|
| 1 | +// AACProcessors Demo: Showcase all engines and features |
| 2 | +const path = require('path'); |
| 3 | + |
| 4 | +// Import processors |
| 5 | +const { DotProcessor, OpmlProcessor, SnapProcessor, GridsetProcessor, TouchChatProcessor, ApplePanelsProcessor, ObfProcessor } = require('../dist/processors'); |
| 6 | + |
| 7 | +// Optional: pretty printer |
| 8 | +let prettyPrint; |
| 9 | +try { |
| 10 | + prettyPrint = require('../dist/viewer/prettyPrint'); |
| 11 | +} catch {} |
| 12 | + |
| 13 | +// Optional: symbol tools |
| 14 | +let symbolTools; |
| 15 | +try { |
| 16 | + symbolTools = require('../dist/optional/symbolTools'); |
| 17 | +} catch {} |
| 18 | + |
| 19 | +// --- DotProcessor --- |
| 20 | +console.log('\n=== DOT Example ==='); |
| 21 | +try { |
| 22 | + const dotFile = path.join(__dirname, 'example.dot'); |
| 23 | + const dotProcessor = new DotProcessor(); |
| 24 | + const dotTree = dotProcessor.loadIntoTree(dotFile); |
| 25 | + console.log('DOT tree:', dotTree); |
| 26 | + console.log('DOT texts:', dotProcessor.extractTexts ? dotProcessor.extractTexts(dotFile) : '(no extractTexts)'); |
| 27 | + if (prettyPrint) prettyPrint.printTree(dotTree, { showNavigation: true }); |
| 28 | +} catch (e) { |
| 29 | + console.warn('DOT demo error:', e.message); |
| 30 | +} |
| 31 | + |
| 32 | +// --- OPMLProcessor --- |
| 33 | +console.log('\n=== OPML Example ==='); |
| 34 | +try { |
| 35 | + const opmlFile = path.join(__dirname, 'example.opml'); |
| 36 | + const opmlProcessor = new OpmlProcessor(); |
| 37 | + const opmlTree = opmlProcessor.loadIntoTree(opmlFile); |
| 38 | + console.log('OPML tree:', opmlTree); |
| 39 | + console.log('OPML texts:', opmlProcessor.extractTexts ? opmlProcessor.extractTexts(opmlFile) : '(no extractTexts)'); |
| 40 | + if (prettyPrint) prettyPrint.printTree(opmlTree, { showNavigation: true }); |
| 41 | +} catch (e) { |
| 42 | + console.warn('OPML demo error:', e.message); |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +// --- SnapProcessor (SPB) --- |
| 48 | +console.log('\n=== Snap Example (.spb) ==='); |
| 49 | +try { |
| 50 | + const spbFile = path.join(__dirname, 'example.spb'); |
| 51 | + const snapProcessor = new SnapProcessor(); |
| 52 | + const snapTree = snapProcessor.loadIntoTree(spbFile); |
| 53 | + console.log('Snap tree (.spb):', snapTree); |
| 54 | + console.log('Snap texts (.spb):', snapProcessor.extractTexts(spbFile)); |
| 55 | + if (prettyPrint) prettyPrint.printTree(snapTree, { showNavigation: true }); |
| 56 | +} catch (e) { |
| 57 | + console.warn('Snap demo error (.spb):', e.message); |
| 58 | +} |
| 59 | + |
| 60 | +// // --- SnapProcessor (SPS) --- |
| 61 | +// console.log('\n=== Snap Example (.sps) ==='); |
| 62 | +// try { |
| 63 | +// const spsFile = path.join(__dirname, 'example.sps'); |
| 64 | +// const snapProcessor = new SnapProcessor(); |
| 65 | +// const snapTree = snapProcessor.loadIntoTree(spsFile); |
| 66 | +// console.log('Snap tree (.sps):', snapTree); |
| 67 | +// console.log('Snap texts (.sps):', snapProcessor.extractTexts(spsFile)); |
| 68 | +// if (prettyPrint) prettyPrint.printTree(snapTree, { showNavigation: true }); |
| 69 | +// } catch (e) { |
| 70 | +// console.warn('Snap demo error (.sps):', e.message); |
| 71 | +// } |
| 72 | + |
| 73 | +// --- GridsetProcessor --- |
| 74 | +console.log('\n=== Gridset Example ==='); |
| 75 | +try { |
| 76 | + const gridsetFile = path.join(__dirname, 'example.gridset'); |
| 77 | + const gridsetProcessor = new GridsetProcessor(); |
| 78 | + const gridTree = gridsetProcessor.loadIntoTree(gridsetFile); |
| 79 | + console.log('Gridset tree:', gridTree); |
| 80 | + console.log('Gridset texts:', gridsetProcessor.extractTexts(gridsetFile)); |
| 81 | + if (prettyPrint) prettyPrint.printTree(gridTree, { showNavigation: true }); |
| 82 | +} catch (e) { |
| 83 | + console.warn('Gridset demo error:', e.message); |
| 84 | +} |
| 85 | + |
| 86 | +// --- TouchChatProcessor --- |
| 87 | +console.log('\n=== TouchChat Example ==='); |
| 88 | +try { |
| 89 | + const touchchatFile = path.join(__dirname, 'example.ce'); |
| 90 | + const touchchatProcessor = new TouchChatProcessor(); |
| 91 | + const tcTree = touchchatProcessor.loadIntoTree(touchchatFile); |
| 92 | + console.log('TouchChat tree:', tcTree); |
| 93 | + console.log('TouchChat texts:', touchchatProcessor.extractTexts(touchchatFile)); |
| 94 | + if (prettyPrint) prettyPrint.printTree(tcTree, { showNavigation: true }); |
| 95 | +} catch (e) { |
| 96 | + console.warn('TouchChat demo error:', e.message); |
| 97 | +} |
| 98 | + |
| 99 | +// --- OBF/OBZ Processor --- |
| 100 | +console.log('\n=== OBF/OBZ Example ==='); |
| 101 | +try { |
| 102 | + // Use ObfProcessor from dist, matching others |
| 103 | +const obfProcessor = new ObfProcessor(); |
| 104 | + const obzFile = path.join(__dirname, 'example.obz'); |
| 105 | + // If loadIntoTree is async, use then/catch. If not, call directly. |
| 106 | + let obTree; |
| 107 | + try { |
| 108 | + obTree = obfProcessor.loadIntoTree(obzFile); |
| 109 | + console.log('OBZ tree:', obTree); |
| 110 | + // Try extractTexts if available |
| 111 | + if (obfProcessor.extractTexts) { |
| 112 | + try { |
| 113 | + const texts = obfProcessor.extractTexts(obzFile); |
| 114 | + console.log('OBZ texts:', texts); |
| 115 | + } catch (e) { |
| 116 | + console.warn('OBZ extractTexts error:', e.message); |
| 117 | + } |
| 118 | + } |
| 119 | + if (prettyPrint) prettyPrint.printTree(obTree, { showNavigation: true }); |
| 120 | + console.log('\nDemo complete.'); |
| 121 | + } catch (e) { |
| 122 | + console.warn('OBZ demo error:', e.message); |
| 123 | + console.log('\nDemo complete.'); |
| 124 | + } |
| 125 | + // Return here so the rest of the demo waits for async |
| 126 | + return; |
| 127 | +} catch (e) { |
| 128 | + console.warn('OBZ demo error:', e.message); |
| 129 | +} |
| 130 | + |
| 131 | +// --- ApplePanelsProcessor (if implemented) --- |
| 132 | +// console.log('\n=== Apple Panels Example ==='); |
| 133 | +// try { |
| 134 | +// const applePanelsFile = path.join(__dirname, 'example.ascconfig'); |
| 135 | +// const applePanelsProcessor = new ApplePanelsProcessor(); |
| 136 | +// const apTree = applePanelsProcessor.loadIntoTree(applePanelsFile); |
| 137 | +// console.log('Apple Panels tree:', apTree); |
| 138 | +// if (prettyPrint) prettyPrint.printTree(apTree, { showNavigation: true }); |
| 139 | +// } catch (e) { |
| 140 | +// console.warn('Apple Panels demo error:', e.message); |
| 141 | +// } |
| 142 | + |
| 143 | +console.log('\nDemo complete.'); |
0 commit comments