@willwade/aac-processors 0.2.20 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -65,6 +65,7 @@ const tree = await processor.loadIntoTree(gridsetUint8Array);
65
65
  - DOT (Graphviz)
66
66
  - Apple Panels (macOS plist)
67
67
  - Asterics Grid
68
+ - GoTalk NOW (.gtbz)
68
69
  - Excel export
69
70
 
70
71
  ## Wrangle strings workflow
@@ -28,6 +28,7 @@ export { SnapProcessor } from './processors/snapProcessor';
28
28
  export { TouchChatProcessor } from './processors/touchchatProcessor';
29
29
  export { ApplePanelsProcessor } from './processors/applePanelsProcessor';
30
30
  export { AstericsGridProcessor } from './processors/astericsGridProcessor';
31
+ export { GotalkNowProcessor } from './processors/gotalkNowProcessor';
31
32
  // ===================================================================
32
33
  // UTILITY FUNCTIONS
33
34
  // ===================================================================
@@ -41,6 +42,7 @@ import { SnapProcessor } from './processors/snapProcessor';
41
42
  import { TouchChatProcessor } from './processors/touchchatProcessor';
42
43
  import { ApplePanelsProcessor } from './processors/applePanelsProcessor';
43
44
  import { AstericsGridProcessor } from './processors/astericsGridProcessor';
45
+ import { GotalkNowProcessor } from './processors/gotalkNowProcessor';
44
46
  export { configureSqlJs } from './utils/sqlite';
45
47
  /**
46
48
  * Factory function to get the appropriate processor for a file extension
@@ -71,6 +73,8 @@ export function getProcessor(filePathOrExtension, options) {
71
73
  return new ApplePanelsProcessor(options);
72
74
  case '.grd':
73
75
  return new AstericsGridProcessor(options);
76
+ case '.gtbz':
77
+ return new GotalkNowProcessor(options);
74
78
  default:
75
79
  throw new Error(`Unsupported file extension: ${extension}`);
76
80
  }
@@ -80,7 +84,19 @@ export function getProcessor(filePathOrExtension, options) {
80
84
  * @returns Array of supported file extensions
81
85
  */
82
86
  export function getSupportedExtensions() {
83
- return ['.dot', '.opml', '.obf', '.obz', '.gridset', '.spb', '.sps', '.ce', '.plist', '.grd'];
87
+ return [
88
+ '.dot',
89
+ '.opml',
90
+ '.obf',
91
+ '.obz',
92
+ '.gridset',
93
+ '.spb',
94
+ '.sps',
95
+ '.ce',
96
+ '.plist',
97
+ '.grd',
98
+ '.gtbz',
99
+ ];
84
100
  }
85
101
  /**
86
102
  * Check if a file extension is supported
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Helpers for decoding GoTalk NOW's NSKeyedArchiver-encoded values.
3
+ *
4
+ * GoTalk NOW stores UIColor and UIFont objects inside `<data>` tags as
5
+ * binary property lists (NSKeyedArchiver). Rather than pulling in a full
6
+ * bplist parser, we exploit the fact that the archived objects embed
7
+ * human-readable ASCII representations of the component values, e.g. an
8
+ * NSRGB colour appears as "0.908 0.355 0.522" and a font name appears as
9
+ * "Futura-Medium".
10
+ */
11
+ function bufferToLatinString(buffer) {
12
+ if (typeof Buffer !== 'undefined' && Buffer.isBuffer(buffer)) {
13
+ return buffer.toString('latin1');
14
+ }
15
+ let out = '';
16
+ for (let i = 0; i < buffer.length; i++)
17
+ out += String.fromCharCode(buffer[i]);
18
+ return out;
19
+ }
20
+ function clampUnit(v) {
21
+ if (Number.isNaN(v))
22
+ return 0;
23
+ return Math.max(0, Math.min(1, v));
24
+ }
25
+ function toHexChannel(v) {
26
+ return Math.round(clampUnit(v) * 255)
27
+ .toString(16)
28
+ .padStart(2, '0');
29
+ }
30
+ /** Convert a 0-1 float triple to an #rrggbb hex string. */
31
+ function rgbToHex(r, g, b) {
32
+ return `#${toHexChannel(r)}${toHexChannel(g)}${toHexChannel(b)}`;
33
+ }
34
+ /**
35
+ * Decode an NSKeyedArchiver-encoded UIColor into a #rrggbb hex string.
36
+ *
37
+ * NSRGB / NSCalibratedRGB colours store a human-readable "R G B [A]" string
38
+ * (e.g. "0.908 0.355 0.522") inside the archive — this is the only encoding we
39
+ * can reliably read without a full binary-plist parser. NSWhite and
40
+ * UISystemColor values store their components as raw IEEE-754 floats, so we
41
+ * return undefined for those rather than risk an incorrect colour.
42
+ */
43
+ export function decodeNsColor(buffer) {
44
+ if (!buffer)
45
+ return undefined;
46
+ const s = bufferToLatinString(buffer);
47
+ // Match RGB[A] component strings like "1 0.949 0.561" or "0.5 0.5 0.5 1".
48
+ // Allow integer components (e.g. "1") but require at least one decimal to
49
+ // avoid matching bplist header bytes (e.g. "00 00 00").
50
+ const candidates = s.match(/\d+(?:\.\d+)?\s+\d+(?:\.\d+)?\s+\d+(?:\.\d+)?(?:\s+\d+(?:\.\d+)?)?/g);
51
+ if (candidates) {
52
+ // Find the first candidate that looks like RGB (has at least one decimal point).
53
+ const rgbStr = candidates.find((c) => c.includes('.'));
54
+ if (rgbStr) {
55
+ const parts = rgbStr.split(/\s+/).map(Number);
56
+ return rgbToHex(parts[0], parts[1], parts[2]);
57
+ }
58
+ }
59
+ return undefined;
60
+ }
61
+ const FONT_KEYWORDS = new Set([
62
+ 'bplist',
63
+ 'bplist00',
64
+ 'UIFont',
65
+ 'UIFontName',
66
+ 'UIFontPointSize',
67
+ 'UIFontDescriptor',
68
+ 'UIFontTraits',
69
+ 'UIFontSystemFont',
70
+ 'UIFontDescriptorAttributes',
71
+ 'UIFontSystemFontName',
72
+ 'NSFont',
73
+ 'NSFontNameAttribute',
74
+ 'NSFontSizeAttribute',
75
+ 'NSName',
76
+ 'NSSize',
77
+ 'NSMutableDictionary',
78
+ 'NSDictionary',
79
+ 'NSObject',
80
+ 'NSKeyedArchiver',
81
+ 'NSColor',
82
+ 'NSColorSpace',
83
+ 'VUIFont',
84
+ 'XNSObject',
85
+ 'classname',
86
+ 'classhints',
87
+ 'classes',
88
+ 'objects',
89
+ 'version',
90
+ 'archiver',
91
+ 'root',
92
+ ]);
93
+ /**
94
+ * Decode an NSKeyedArchiver-encoded UIFont into its family name.
95
+ * Font size is encoded as a raw IEEE-754 float and is not extracted.
96
+ */
97
+ export function decodeNsFont(buffer) {
98
+ if (!buffer)
99
+ return {};
100
+ const s = bufferToLatinString(buffer);
101
+ const tokens = s.match(/[A-Za-z][A-Za-z0-9-]{2,}/g) || [];
102
+ const fontFamily = tokens.find((t) => !FONT_KEYWORDS.has(t) &&
103
+ !t.startsWith('UI') &&
104
+ !t.startsWith('NS') &&
105
+ !t.startsWith('CF') &&
106
+ !t.startsWith('GT'));
107
+ return fontFamily ? { fontFamily } : {};
108
+ }