-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-debug.mts
More file actions
42 lines (39 loc) · 1.68 KB
/
Copy pathtest-debug.mts
File metadata and controls
42 lines (39 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import JSZip from 'jszip';
import { readFileSync } from 'fs';
import { inflateRawSync } from 'zlib';
import { decodeBinarySchema, compileSchema } from 'kiwi-schema';
const buf = readFileSync('/Users/deepaksingh/Downloads/fig-mcp/test.fig');
const zip = await JSZip.loadAsync(buf);
console.log('ZIP files:', Object.keys(zip.files).slice(0, 5));
const canvasFig = zip.file('canvas.fig');
console.log('canvas.fig found:', !!canvasFig);
if (canvasFig) {
const data = await canvasFig.async('uint8array');
console.log('canvas.fig size:', data.length);
console.log('canvas.fig magic:', String.fromCharCode(...data.slice(0, 8)));
// Test archive parsing
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
let offset = 8 + 4; // skip "fig-kiwi" + version uint32
const chunks: Uint8Array[] = [];
while (offset + 4 <= data.length) {
const size = view.getUint32(offset, true);
offset += 4;
chunks.push(data.slice(offset, offset + size));
offset += size;
}
console.log('Chunks:', chunks.length, chunks.map(c => c.length));
if (chunks.length >= 2) {
const rawSchema = inflateRawSync(chunks[0]);
const rawData = inflateRawSync(chunks[1]);
console.log('Schema size:', rawSchema.length, 'Data size:', rawData.length);
const schema = decodeBinarySchema(rawSchema);
console.log('Schema decoded OK');
const compiled = compileSchema(schema) as any;
const msg = compiled.decodeMessage(rawData) as any;
console.log('Message keys:', Object.keys(msg));
const nc = msg.nodeChanges ?? [];
console.log('NodeChanges count:', nc.length);
const types = [...new Set(nc.map((n: any) => n.type))];
console.log('Node types:', types);
}
}