@pairdraw/kiwi 0.0.0-stage → 0.16.0
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/LICENSE +21 -0
- package/NOTICE +28 -0
- package/README.md +112 -2
- package/dist/chunks/fig/codec.js +1371 -0
- package/dist/chunks/fig/codec.js.map +1 -0
- package/dist/fig/codec.d.ts +477 -0
- package/dist/fig/codec.js +2 -0
- package/dist/fig/container.d.ts +48 -0
- package/dist/fig/container.js +2 -0
- package/dist/fig/guid.d.ts +13 -0
- package/dist/fig/guid.js +31 -0
- package/dist/fig/guid.js.map +1 -0
- package/dist/fig/parse.d.ts +33 -0
- package/dist/fig/parse.js +83 -0
- package/dist/fig/parse.js.map +1 -0
- package/dist/fig.d.ts +185 -0
- package/dist/fig.js +117 -0
- package/dist/fig.js.map +1 -0
- package/dist/index.d.ts +182 -0
- package/dist/page-manifest.d.ts +16 -0
- package/dist/schema-runtime.d.ts +2 -0
- package/dist/schema-runtime.js +2 -0
- package/dist/types.d.ts +26 -0
- package/package.json +52 -4
- package/src/fig/codec.ts +536 -0
- package/src/fig/container.ts +180 -0
- package/src/fig/guid.ts +24 -0
- package/src/fig/index.ts +5 -0
- package/src/fig/page-manifest.ts +149 -0
- package/src/fig/parse.ts +136 -0
- package/src/fig/protocol.ts +237 -0
- package/src/fig/schema/fig.kiwi +5628 -0
- package/src/fig/schema.ts +7 -0
- package/src/fig/types.ts +25 -0
- package/src/fig/variable-bindings.ts +11 -0
- package/src/global.d.ts +4 -0
- package/src/schema-runtime/bb.ts +284 -0
- package/src/schema-runtime/binary.ts +102 -0
- package/src/schema-runtime/index.ts +25 -0
- package/src/schema-runtime/interpreter.ts +465 -0
- package/src/schema-runtime/parser.ts +287 -0
- package/src/schema-runtime/schema.ts +24 -0
- package/src/schema-runtime/util.ts +10 -0
- package/src/schema-runtime/validate.ts +88 -0
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
import { Color, GUID, Matrix, Vector } from "../types.js";
|
|
2
|
+
//#region src/fig/codec.d.ts
|
|
3
|
+
interface CompiledSchema {
|
|
4
|
+
encodeMessage(message: unknown): Uint8Array;
|
|
5
|
+
decodeMessage(data: Uint8Array): unknown;
|
|
6
|
+
encodePaint(paint: unknown): Uint8Array;
|
|
7
|
+
encodeNodeChange(nodeChange: unknown): Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Initialize the codec (compiles Kiwi schema)
|
|
11
|
+
*/
|
|
12
|
+
declare function initCodec(): Promise<void>;
|
|
13
|
+
declare function getCompiledSchema(): CompiledSchema;
|
|
14
|
+
declare function getSchemaBytes(): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Check if codec is initialized
|
|
17
|
+
*/
|
|
18
|
+
declare function isCodecReady(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Compress data using Zstd (Bun native)
|
|
21
|
+
*/
|
|
22
|
+
declare function compress(data: Uint8Array): Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* Decompress Zstd data (Bun native)
|
|
25
|
+
*/
|
|
26
|
+
declare function decompress(data: Uint8Array): Uint8Array;
|
|
27
|
+
/**
|
|
28
|
+
* Encode a message for sending to Figma
|
|
29
|
+
* Handles variable bindings in fillPaints which require custom encoding
|
|
30
|
+
*/
|
|
31
|
+
declare function encodeMessage(message: FigmaMessage): Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Decode a message received from Figma
|
|
34
|
+
*/
|
|
35
|
+
declare function decodeMessage(data: Uint8Array): FigmaMessage;
|
|
36
|
+
/**
|
|
37
|
+
* Quick peek at message type without full decoding
|
|
38
|
+
*/
|
|
39
|
+
declare function peekMessageType(data: Uint8Array): number | null;
|
|
40
|
+
interface ParentIndex {
|
|
41
|
+
guid: GUID;
|
|
42
|
+
position: string;
|
|
43
|
+
}
|
|
44
|
+
interface ImageSource {
|
|
45
|
+
hash: string | Uint8Array;
|
|
46
|
+
name?: string;
|
|
47
|
+
dataBlob?: number;
|
|
48
|
+
}
|
|
49
|
+
interface Paint {
|
|
50
|
+
type: 'SOLID' | 'GRADIENT_LINEAR' | 'GRADIENT_RADIAL' | 'GRADIENT_ANGULAR' | 'GRADIENT_DIAMOND' | 'IMAGE' | 'VIDEO' | 'PATTERN' | 'NOISE' | 'CUSTOM';
|
|
51
|
+
color?: Color;
|
|
52
|
+
opacity?: number;
|
|
53
|
+
visible?: boolean;
|
|
54
|
+
blendMode?: string;
|
|
55
|
+
stops?: {
|
|
56
|
+
color: Color;
|
|
57
|
+
position: number;
|
|
58
|
+
}[];
|
|
59
|
+
transform?: Matrix;
|
|
60
|
+
image?: ImageSource;
|
|
61
|
+
imageThumbnail?: ImageSource;
|
|
62
|
+
animatedImage?: ImageSource;
|
|
63
|
+
imageScaleMode?: string;
|
|
64
|
+
/** Degrees an image turns in Fill, Fit, and Tile; a crop's transform holds its own turn. */
|
|
65
|
+
rotation?: number;
|
|
66
|
+
sourceNodeId?: GUID;
|
|
67
|
+
scale?: number;
|
|
68
|
+
spacing?: number;
|
|
69
|
+
patternSpacing?: Vector;
|
|
70
|
+
patternTileType?: string;
|
|
71
|
+
verticalAlignment?: string;
|
|
72
|
+
horizontalAlignment?: string;
|
|
73
|
+
id?: GUID;
|
|
74
|
+
altText?: string;
|
|
75
|
+
noiseType?: string;
|
|
76
|
+
density?: number;
|
|
77
|
+
noiseSize?: Vector;
|
|
78
|
+
customEffectId?: {
|
|
79
|
+
guid?: GUID;
|
|
80
|
+
};
|
|
81
|
+
colorVar?: {
|
|
82
|
+
value?: {
|
|
83
|
+
alias?: {
|
|
84
|
+
guid?: GUID;
|
|
85
|
+
assetRef?: {
|
|
86
|
+
key: string;
|
|
87
|
+
version?: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
dataType?: string;
|
|
92
|
+
resolvedDataType?: string;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
interface Effect {
|
|
96
|
+
type: 'DROP_SHADOW' | 'INNER_SHADOW' | 'LAYER_BLUR' | 'BACKGROUND_BLUR' | 'FOREGROUND_BLUR';
|
|
97
|
+
color?: Color;
|
|
98
|
+
offset?: Vector;
|
|
99
|
+
radius?: number;
|
|
100
|
+
visible?: boolean;
|
|
101
|
+
spread?: number;
|
|
102
|
+
blendMode?: string;
|
|
103
|
+
showShadowBehindNode?: boolean;
|
|
104
|
+
}
|
|
105
|
+
interface VariableAnyValue {
|
|
106
|
+
boolValue?: boolean;
|
|
107
|
+
textValue?: string;
|
|
108
|
+
floatValue?: number;
|
|
109
|
+
colorValue?: Color;
|
|
110
|
+
alias?: {
|
|
111
|
+
guid?: GUID;
|
|
112
|
+
assetRef?: {
|
|
113
|
+
key: string;
|
|
114
|
+
version?: string;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
symbolIdValue?: {
|
|
118
|
+
guid?: GUID;
|
|
119
|
+
};
|
|
120
|
+
propRefValue?: {
|
|
121
|
+
defId?: GUID;
|
|
122
|
+
};
|
|
123
|
+
mapValue?: {
|
|
124
|
+
values?: {
|
|
125
|
+
key?: string;
|
|
126
|
+
guidKey?: GUID;
|
|
127
|
+
value?: VariableDataEntry;
|
|
128
|
+
}[];
|
|
129
|
+
};
|
|
130
|
+
colorArrayValue?: {
|
|
131
|
+
colors?: VariableDataEntry[];
|
|
132
|
+
};
|
|
133
|
+
fontStyleValue?: {
|
|
134
|
+
asString?: VariableDataEntry;
|
|
135
|
+
asFloat?: VariableDataEntry;
|
|
136
|
+
asVariations?: VariableDataEntry;
|
|
137
|
+
};
|
|
138
|
+
expressionValue?: {
|
|
139
|
+
expressionFunction?: string;
|
|
140
|
+
expressionArguments?: VariableDataEntry[];
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
interface VariableDataEntry {
|
|
144
|
+
value?: VariableAnyValue;
|
|
145
|
+
dataType?: string;
|
|
146
|
+
resolvedDataType?: string;
|
|
147
|
+
}
|
|
148
|
+
interface VariableConsumptionEntry {
|
|
149
|
+
nodeField?: number;
|
|
150
|
+
variableData?: VariableDataEntry;
|
|
151
|
+
variableField?: string;
|
|
152
|
+
}
|
|
153
|
+
interface VariableDataValuesEntry {
|
|
154
|
+
modeID: GUID;
|
|
155
|
+
variableData: VariableDataEntry;
|
|
156
|
+
}
|
|
157
|
+
interface PluginData {
|
|
158
|
+
pluginID: string;
|
|
159
|
+
value: string;
|
|
160
|
+
key: string;
|
|
161
|
+
}
|
|
162
|
+
interface PluginRelaunchData {
|
|
163
|
+
pluginID: string;
|
|
164
|
+
message: string;
|
|
165
|
+
command: string;
|
|
166
|
+
isDeleted: boolean;
|
|
167
|
+
}
|
|
168
|
+
interface AssetRef {
|
|
169
|
+
key: string;
|
|
170
|
+
version?: string;
|
|
171
|
+
}
|
|
172
|
+
type StyleReference = {
|
|
173
|
+
guid: GUID;
|
|
174
|
+
assetRef?: never;
|
|
175
|
+
} | {
|
|
176
|
+
guid?: never;
|
|
177
|
+
assetRef: AssetRef;
|
|
178
|
+
};
|
|
179
|
+
/** One paragraph of a text: whether it is a list item, and how deeply it nests. */
|
|
180
|
+
interface TextLineData {
|
|
181
|
+
lineType?: 'PLAIN' | 'ORDERED_LIST' | 'UNORDERED_LIST' | 'BLOCKQUOTE' | 'HEADER';
|
|
182
|
+
styleId?: number;
|
|
183
|
+
indentationLevel?: number;
|
|
184
|
+
sourceDirectionality?: string;
|
|
185
|
+
listStartOffset?: number;
|
|
186
|
+
isFirstLineOfList?: boolean;
|
|
187
|
+
}
|
|
188
|
+
interface NodeChange {
|
|
189
|
+
[key: string]: unknown;
|
|
190
|
+
guid?: GUID;
|
|
191
|
+
phase?: 'CREATED' | 'REMOVED';
|
|
192
|
+
parentIndex?: ParentIndex;
|
|
193
|
+
type?: string;
|
|
194
|
+
name?: string;
|
|
195
|
+
visible?: boolean;
|
|
196
|
+
locked?: boolean;
|
|
197
|
+
opacity?: number;
|
|
198
|
+
blendMode?: string;
|
|
199
|
+
size?: Vector;
|
|
200
|
+
transform?: Matrix;
|
|
201
|
+
cornerRadius?: number;
|
|
202
|
+
fillPaints?: Paint[];
|
|
203
|
+
strokePaints?: Paint[];
|
|
204
|
+
backgroundPaints?: Paint[];
|
|
205
|
+
strokeWeight?: number;
|
|
206
|
+
strokeAlign?: string;
|
|
207
|
+
strokeCap?: string;
|
|
208
|
+
strokeJoin?: string;
|
|
209
|
+
dashPattern?: number[];
|
|
210
|
+
effects?: Effect[];
|
|
211
|
+
mask?: boolean;
|
|
212
|
+
maskType?: string;
|
|
213
|
+
maskIsOutline?: boolean;
|
|
214
|
+
exportSettings?: unknown[];
|
|
215
|
+
layoutGrids?: unknown[];
|
|
216
|
+
stackMode?: 'NONE' | 'HORIZONTAL' | 'VERTICAL';
|
|
217
|
+
stackSpacing?: number;
|
|
218
|
+
stackPadding?: number;
|
|
219
|
+
stackPaddingRight?: number;
|
|
220
|
+
stackPaddingBottom?: number;
|
|
221
|
+
stackCounterAlign?: string;
|
|
222
|
+
stackJustify?: string;
|
|
223
|
+
stackCounterAlignItems?: string;
|
|
224
|
+
stackPrimaryAlignItems?: string;
|
|
225
|
+
stackPrimarySizing?: 'FIXED' | 'RESIZE_TO_FIT' | 'RESIZE_TO_FIT_WITH_IMPLICIT_SIZE';
|
|
226
|
+
stackCounterSizing?: 'FIXED' | 'RESIZE_TO_FIT' | 'RESIZE_TO_FIT_WITH_IMPLICIT_SIZE';
|
|
227
|
+
stackVerticalPadding?: number;
|
|
228
|
+
stackHorizontalPadding?: number;
|
|
229
|
+
stackWrap?: string;
|
|
230
|
+
stackPositioning?: string;
|
|
231
|
+
stackChildPrimaryGrow?: number;
|
|
232
|
+
stackChildAlignSelf?: string;
|
|
233
|
+
stackCounterSpacing?: number;
|
|
234
|
+
minSize?: {
|
|
235
|
+
value?: Vector;
|
|
236
|
+
};
|
|
237
|
+
maxSize?: {
|
|
238
|
+
value?: Vector;
|
|
239
|
+
};
|
|
240
|
+
targetAspectRatio?: {
|
|
241
|
+
value?: Vector;
|
|
242
|
+
};
|
|
243
|
+
clipsContent?: boolean;
|
|
244
|
+
frameMaskDisabled?: boolean;
|
|
245
|
+
resizeToFit?: boolean;
|
|
246
|
+
booleanOperation?: 'UNION' | 'SUBTRACT' | 'INTERSECT' | 'XOR';
|
|
247
|
+
vectorData?: unknown;
|
|
248
|
+
fillGeometry?: Array<{
|
|
249
|
+
windingRule?: string;
|
|
250
|
+
commandsBlob?: number;
|
|
251
|
+
styleID?: number;
|
|
252
|
+
}>;
|
|
253
|
+
strokeGeometry?: Array<{
|
|
254
|
+
windingRule?: string;
|
|
255
|
+
commandsBlob?: number;
|
|
256
|
+
}>;
|
|
257
|
+
fontSize?: number;
|
|
258
|
+
fontWeight?: number;
|
|
259
|
+
fontName?: {
|
|
260
|
+
family: string;
|
|
261
|
+
style: string;
|
|
262
|
+
postscript?: string;
|
|
263
|
+
};
|
|
264
|
+
textAlignHorizontal?: string;
|
|
265
|
+
textAlignVertical?: string;
|
|
266
|
+
textAutoResize?: string;
|
|
267
|
+
textData?: {
|
|
268
|
+
characters: string;
|
|
269
|
+
lines?: TextLineData[];
|
|
270
|
+
characterStyleIDs?: number[];
|
|
271
|
+
styleOverrideTable?: NodeChange[];
|
|
272
|
+
};
|
|
273
|
+
derivedTextData?: {
|
|
274
|
+
layoutSize?: Vector;
|
|
275
|
+
baselines?: Array<{
|
|
276
|
+
firstCharacter: number;
|
|
277
|
+
endCharacter: number;
|
|
278
|
+
position: Vector;
|
|
279
|
+
width: number;
|
|
280
|
+
lineY?: number;
|
|
281
|
+
lineHeight: number;
|
|
282
|
+
lineAscent: number;
|
|
283
|
+
}>;
|
|
284
|
+
glyphs?: Array<{
|
|
285
|
+
commandsBlob?: number;
|
|
286
|
+
position: Vector;
|
|
287
|
+
fontSize: number;
|
|
288
|
+
/** The character the glyph draws; Figma leaves it out for list markers. */
|
|
289
|
+
firstCharacter?: number;
|
|
290
|
+
advance: number;
|
|
291
|
+
/** Radians along the text path; kiwi omits the field for axis-aligned text. */
|
|
292
|
+
rotation?: number;
|
|
293
|
+
/** An emoji's code points; Figma draws its image in place of the glyph's placeholder. */
|
|
294
|
+
emojiCodePoints?: number[];
|
|
295
|
+
/** The image set the emoji is drawn from; left out for the default, APPLE. */
|
|
296
|
+
emojiImageSet?: 'APPLE' | 'NOTO';
|
|
297
|
+
}>;
|
|
298
|
+
/** Underlines and strikethroughs, which Figma draws saved text's decorations from. */
|
|
299
|
+
decorations?: Array<{
|
|
300
|
+
rects: Array<{
|
|
301
|
+
x: number;
|
|
302
|
+
y: number;
|
|
303
|
+
w: number;
|
|
304
|
+
h: number;
|
|
305
|
+
}>;
|
|
306
|
+
/** The override table entry of the characters decorated, or 0 for the text's own style. */
|
|
307
|
+
styleID: number;
|
|
308
|
+
}>;
|
|
309
|
+
fontMetaData?: Array<{
|
|
310
|
+
key: {
|
|
311
|
+
family: string;
|
|
312
|
+
style: string;
|
|
313
|
+
postscript?: string;
|
|
314
|
+
};
|
|
315
|
+
fontLineHeight: number;
|
|
316
|
+
fontDigest?: Uint8Array | Record<string, number>;
|
|
317
|
+
fontStyle?: string;
|
|
318
|
+
fontWeight?: number;
|
|
319
|
+
}>;
|
|
320
|
+
logicalIndexToCharacterOffsetMap?: number[];
|
|
321
|
+
derivedLines?: Array<{
|
|
322
|
+
directionality: 'LTR' | 'RTL';
|
|
323
|
+
}>;
|
|
324
|
+
truncationStartIndex?: number;
|
|
325
|
+
truncatedHeight?: number;
|
|
326
|
+
};
|
|
327
|
+
styleType?: string;
|
|
328
|
+
styleIdForText?: StyleReference;
|
|
329
|
+
styleIdForFill?: StyleReference;
|
|
330
|
+
styleIdForStrokeFill?: StyleReference;
|
|
331
|
+
styleIdForEffect?: StyleReference;
|
|
332
|
+
styleIdForGrid?: StyleReference;
|
|
333
|
+
textUserLayoutVersion?: number;
|
|
334
|
+
textExplicitLayoutVersion?: number;
|
|
335
|
+
textBidiVersion?: number;
|
|
336
|
+
textDecoration?: string;
|
|
337
|
+
textDecorationSkipInk?: boolean;
|
|
338
|
+
textDecorationFillPaints?: Paint[];
|
|
339
|
+
textUnderlineOffset?: {
|
|
340
|
+
value?: number;
|
|
341
|
+
units?: string;
|
|
342
|
+
};
|
|
343
|
+
textDecorationThickness?: {
|
|
344
|
+
value?: number;
|
|
345
|
+
units?: string;
|
|
346
|
+
};
|
|
347
|
+
textDecorationStyle?: string;
|
|
348
|
+
toggledOnOTFeatures?: string[];
|
|
349
|
+
toggledOffOTFeatures?: string[];
|
|
350
|
+
fontVariations?: Array<{
|
|
351
|
+
axisTag?: number;
|
|
352
|
+
axisName?: string;
|
|
353
|
+
value?: number;
|
|
354
|
+
}>;
|
|
355
|
+
fontVariantCommonLigatures?: boolean;
|
|
356
|
+
fontVariantContextualLigatures?: boolean;
|
|
357
|
+
fontVariantDiscretionaryLigatures?: boolean;
|
|
358
|
+
fontVariantHistoricalLigatures?: boolean;
|
|
359
|
+
fontVariantOrdinal?: boolean;
|
|
360
|
+
fontVariantSlashedZero?: boolean;
|
|
361
|
+
fontVariantNumericFigure?: string;
|
|
362
|
+
fontVariantNumericSpacing?: string;
|
|
363
|
+
fontVariantNumericFraction?: string;
|
|
364
|
+
fontVariantCaps?: string;
|
|
365
|
+
fontVersion?: string;
|
|
366
|
+
emojiImageSet?: string;
|
|
367
|
+
lineHeight?: {
|
|
368
|
+
value: number;
|
|
369
|
+
units: string;
|
|
370
|
+
};
|
|
371
|
+
letterSpacing?: {
|
|
372
|
+
value: number;
|
|
373
|
+
units: string;
|
|
374
|
+
};
|
|
375
|
+
paragraphSpacing?: number;
|
|
376
|
+
paragraphIndent?: number;
|
|
377
|
+
listSpacing?: number;
|
|
378
|
+
hangingList?: boolean;
|
|
379
|
+
symbolData?: {
|
|
380
|
+
symbolID: GUID;
|
|
381
|
+
};
|
|
382
|
+
isStateGroup?: boolean;
|
|
383
|
+
stateGroupPropertyValueOrders?: Array<{
|
|
384
|
+
property: string;
|
|
385
|
+
values: string[];
|
|
386
|
+
}>;
|
|
387
|
+
internalOnly?: boolean;
|
|
388
|
+
rectangleTopLeftCornerRadius?: number;
|
|
389
|
+
rectangleTopRightCornerRadius?: number;
|
|
390
|
+
rectangleBottomLeftCornerRadius?: number;
|
|
391
|
+
rectangleBottomRightCornerRadius?: number;
|
|
392
|
+
rectangleCornerRadiiIndependent?: boolean;
|
|
393
|
+
cornerSmoothing?: number;
|
|
394
|
+
/** A polygon's sides or a star's points. */
|
|
395
|
+
count?: number;
|
|
396
|
+
/** A star's inner radius as a share of its outer one. */
|
|
397
|
+
starInnerScale?: number;
|
|
398
|
+
horizontalConstraint?: string;
|
|
399
|
+
verticalConstraint?: string;
|
|
400
|
+
prototypeStartNodeID?: GUID;
|
|
401
|
+
prototypeInteractions?: unknown[];
|
|
402
|
+
transitionInfo?: unknown;
|
|
403
|
+
variableData?: VariableDataEntry;
|
|
404
|
+
variableConsumptionMap?: {
|
|
405
|
+
entries?: VariableConsumptionEntry[];
|
|
406
|
+
};
|
|
407
|
+
parameterConsumptionMap?: {
|
|
408
|
+
entries?: VariableConsumptionEntry[];
|
|
409
|
+
};
|
|
410
|
+
variableSetModes?: Array<{
|
|
411
|
+
id: GUID;
|
|
412
|
+
name: string;
|
|
413
|
+
sortPosition?: string;
|
|
414
|
+
}>;
|
|
415
|
+
variableSetID?: {
|
|
416
|
+
guid?: GUID;
|
|
417
|
+
assetRef?: {
|
|
418
|
+
key: string;
|
|
419
|
+
version?: string;
|
|
420
|
+
};
|
|
421
|
+
};
|
|
422
|
+
variableResolvedType?: string;
|
|
423
|
+
variableDataValues?: {
|
|
424
|
+
entries?: VariableDataValuesEntry[];
|
|
425
|
+
};
|
|
426
|
+
variableScopes?: string[];
|
|
427
|
+
codeSyntax?: {
|
|
428
|
+
entries?: Array<{
|
|
429
|
+
platform: string;
|
|
430
|
+
value: string;
|
|
431
|
+
}>;
|
|
432
|
+
};
|
|
433
|
+
description?: string;
|
|
434
|
+
symbolDescription?: string;
|
|
435
|
+
isPublishable?: boolean;
|
|
436
|
+
documentColorProfile?: 'SRGB' | 'DISPLAY_P3';
|
|
437
|
+
pluginData?: PluginData[];
|
|
438
|
+
pluginRelaunchData?: PluginRelaunchData[];
|
|
439
|
+
}
|
|
440
|
+
interface FigmaMessage {
|
|
441
|
+
type: string;
|
|
442
|
+
sessionID?: number;
|
|
443
|
+
ackID?: number;
|
|
444
|
+
reconnectSequenceNumber?: number;
|
|
445
|
+
nodeChanges?: NodeChange[];
|
|
446
|
+
blobs?: Array<{
|
|
447
|
+
bytes: Uint8Array;
|
|
448
|
+
}>;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Create a NODE_CHANGES message
|
|
452
|
+
*/
|
|
453
|
+
declare function createNodeChangesMessage(sessionID: number, reconnectSequenceNumber: number, nodeChanges: NodeChange[], ackID?: number): FigmaMessage;
|
|
454
|
+
/**
|
|
455
|
+
* Create a node change for a new shape
|
|
456
|
+
*/
|
|
457
|
+
declare function createNodeChange(opts: {
|
|
458
|
+
sessionID: number;
|
|
459
|
+
localID: number;
|
|
460
|
+
parentSessionID: number;
|
|
461
|
+
parentLocalID: number;
|
|
462
|
+
position?: string;
|
|
463
|
+
type: string;
|
|
464
|
+
name: string;
|
|
465
|
+
x: number;
|
|
466
|
+
y: number;
|
|
467
|
+
width: number;
|
|
468
|
+
height: number;
|
|
469
|
+
fill?: Color;
|
|
470
|
+
stroke?: Color;
|
|
471
|
+
strokeWeight?: number;
|
|
472
|
+
cornerRadius?: number;
|
|
473
|
+
opacity?: number;
|
|
474
|
+
}): NodeChange;
|
|
475
|
+
//#endregion
|
|
476
|
+
export { AssetRef, Effect, FigmaMessage, ImageSource, NodeChange, Paint, ParentIndex, PluginData, PluginRelaunchData, StyleReference, TextLineData, VariableAnyValue, VariableConsumptionEntry, VariableDataEntry, VariableDataValuesEntry, compress, createNodeChange, createNodeChangesMessage, decodeMessage, decompress, encodeMessage, getCompiledSchema, getSchemaBytes, initCodec, isCodecReady, peekMessageType };
|
|
477
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { compress, createNodeChange, createNodeChangesMessage, decodeMessage, decompress, encodeMessage, getCompiledSchema, getSchemaBytes, initCodec, isCodecReady, peekMessageType } from "../chunks/fig/codec.js";
|
|
2
|
+
export { compress, createNodeChange, createNodeChangesMessage, decodeMessage, decompress, encodeMessage, getCompiledSchema, getSchemaBytes, initCodec, isCodecReady, peekMessageType };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/fig/container.d.ts
|
|
2
|
+
declare const FIG_KIWI_DEFAULT_VERSION = 101;
|
|
3
|
+
/**
|
|
4
|
+
* The header a canvas starts with. Figma's design files and FigJam boards differ only here:
|
|
5
|
+
* a board's `.jam` archive holds the same records under `fig-jam.`.
|
|
6
|
+
*/
|
|
7
|
+
declare const FIG_FILE_HEADERS: {
|
|
8
|
+
readonly design: "fig-kiwi";
|
|
9
|
+
readonly board: "fig-jam.";
|
|
10
|
+
};
|
|
11
|
+
/** What a canvas is for, by its header. */
|
|
12
|
+
type FigFileKind = keyof typeof FIG_FILE_HEADERS;
|
|
13
|
+
/** The kind a canvas's header names, or null when it is no Figma canvas. */
|
|
14
|
+
declare function figFileKind(binary: Uint8Array): FigFileKind | null;
|
|
15
|
+
/** Compresses a fig-kiwi data chunk. */
|
|
16
|
+
type FigDataCompressor = (data: Uint8Array) => Uint8Array;
|
|
17
|
+
/** Decompresses a fig-kiwi data chunk, zstd or deflate. */
|
|
18
|
+
type FigDataDecompressor = (data: Uint8Array) => Uint8Array;
|
|
19
|
+
/** The zstd level Figma itself saves with. */
|
|
20
|
+
declare const FIG_ZSTD_DEFAULT_LEVEL = 3;
|
|
21
|
+
/**
|
|
22
|
+
* Bun's zstd at its default level, or deflate where zstd needs loading first. Figma reads both,
|
|
23
|
+
* so writers that cannot wait, such as the clipboard, use this one.
|
|
24
|
+
*/
|
|
25
|
+
declare const defaultFigDataCompressor: FigDataCompressor;
|
|
26
|
+
/** The WebAssembly zstd encoder at `level`. */
|
|
27
|
+
declare function loadWasmFigDataCompressor(level?: number): Promise<FigDataCompressor>;
|
|
28
|
+
/**
|
|
29
|
+
* A zstd compressor at `level`: Bun's own where it runs, the WebAssembly build elsewhere. Figma
|
|
30
|
+
* opens every level, but only frames that declare their decompressed size, which both write.
|
|
31
|
+
*/
|
|
32
|
+
declare function loadFigDataCompressor(level?: number): Promise<FigDataCompressor>;
|
|
33
|
+
/** The WebAssembly zstd decoder. */
|
|
34
|
+
declare function loadWasmFigDataDecompressor(): Promise<FigDataDecompressor>;
|
|
35
|
+
/**
|
|
36
|
+
* Makes `decompressFigKiwiData` ready for zstd chunks: Bun's own zstd needs nothing, the
|
|
37
|
+
* WebAssembly build elsewhere loads once. Every path that opens a `.fig` synchronously awaits
|
|
38
|
+
* this first, so a document session, its worker, and the patches they write never wait.
|
|
39
|
+
*/
|
|
40
|
+
declare function loadFigDataDecompressor(): Promise<FigDataDecompressor>;
|
|
41
|
+
declare function parseFigKiwiChunks(binary: Uint8Array): Uint8Array[] | null;
|
|
42
|
+
/** A data chunk decompressed at once; a zstd chunk needs `loadFigDataDecompressor` first. */
|
|
43
|
+
declare function decompressFigKiwiData(compressed: Uint8Array): Uint8Array;
|
|
44
|
+
declare function decompressFigKiwiDataAsync(compressed: Uint8Array): Promise<Uint8Array>;
|
|
45
|
+
declare function buildFigKiwi(schemaDeflated: Uint8Array, dataRaw: Uint8Array, version?: number, compress?: FigDataCompressor, kind?: FigFileKind): Uint8Array;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { FIG_FILE_HEADERS, FIG_KIWI_DEFAULT_VERSION, FIG_ZSTD_DEFAULT_LEVEL, FigDataCompressor, FigDataDecompressor, FigFileKind, buildFigKiwi, decompressFigKiwiData, decompressFigKiwiDataAsync, defaultFigDataCompressor, figFileKind, loadFigDataCompressor, loadFigDataDecompressor, loadWasmFigDataCompressor, loadWasmFigDataDecompressor, parseFigKiwiChunks };
|
|
48
|
+
//# sourceMappingURL=container.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { FIG_FILE_HEADERS, FIG_KIWI_DEFAULT_VERSION, FIG_ZSTD_DEFAULT_LEVEL, buildFigKiwi, decompressFigKiwiData, decompressFigKiwiDataAsync, defaultFigDataCompressor, figFileKind, loadFigDataCompressor, loadFigDataDecompressor, loadWasmFigDataCompressor, loadWasmFigDataDecompressor, parseFigKiwiChunks } from "../chunks/fig/codec.js";
|
|
2
|
+
export { FIG_FILE_HEADERS, FIG_KIWI_DEFAULT_VERSION, FIG_ZSTD_DEFAULT_LEVEL, buildFigKiwi, decompressFigKiwiData, decompressFigKiwiDataAsync, defaultFigDataCompressor, figFileKind, loadFigDataCompressor, loadFigDataDecompressor, loadWasmFigDataCompressor, loadWasmFigDataDecompressor, parseFigKiwiChunks };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GUID } from "../types.js";
|
|
2
|
+
//#region src/fig/guid.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Kiwi's all-ones GUID names no node: a cleared style reference, a slot's own content, or a
|
|
5
|
+
* layer without an override key.
|
|
6
|
+
*/
|
|
7
|
+
declare const UNSET_GUID: Readonly<GUID>;
|
|
8
|
+
declare function isUnsetGuid(guid: GUID): boolean;
|
|
9
|
+
declare function guidToString(guid: GUID): string;
|
|
10
|
+
declare function stringToGuid(str: string): GUID;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { UNSET_GUID, guidToString, isUnsetGuid, stringToGuid };
|
|
13
|
+
//# sourceMappingURL=guid.d.ts.map
|
package/dist/fig/guid.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/fig/guid.ts
|
|
2
|
+
/**
|
|
3
|
+
* Kiwi's all-ones GUID names no node: a cleared style reference, a slot's own content, or a
|
|
4
|
+
* layer without an override key.
|
|
5
|
+
*/
|
|
6
|
+
const UNSET_GUID = {
|
|
7
|
+
sessionID: 4294967295,
|
|
8
|
+
localID: 4294967295
|
|
9
|
+
};
|
|
10
|
+
function isUnsetGuid(guid) {
|
|
11
|
+
return guid.sessionID === UNSET_GUID.sessionID && guid.localID === UNSET_GUID.localID;
|
|
12
|
+
}
|
|
13
|
+
function guidToString(guid) {
|
|
14
|
+
return `${guid.sessionID}:${guid.localID}`;
|
|
15
|
+
}
|
|
16
|
+
function stringToGuid(str) {
|
|
17
|
+
const match = str.match(/^(?:VariableID:|VariableCollectionId:)?(\d+):(\d+)$/);
|
|
18
|
+
if (match) return {
|
|
19
|
+
sessionID: Number.parseInt(match[1], 10),
|
|
20
|
+
localID: Number.parseInt(match[2], 10)
|
|
21
|
+
};
|
|
22
|
+
const [session, local] = str.split(":");
|
|
23
|
+
return {
|
|
24
|
+
sessionID: Number.parseInt(session, 10),
|
|
25
|
+
localID: Number.parseInt(local, 10)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { UNSET_GUID, guidToString, isUnsetGuid, stringToGuid };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=guid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guid.js","names":[],"sources":["../../src/fig/guid.ts"],"sourcesContent":["import type { GUID } from './types'\n\n/**\n * Kiwi's all-ones GUID names no node: a cleared style reference, a slot's own content, or a\n * layer without an override key.\n */\nexport const UNSET_GUID: Readonly<GUID> = { sessionID: 0xffffffff, localID: 0xffffffff }\n\nexport function isUnsetGuid(guid: GUID): boolean {\n return guid.sessionID === UNSET_GUID.sessionID && guid.localID === UNSET_GUID.localID\n}\n\nexport function guidToString(guid: GUID): string {\n return `${guid.sessionID}:${guid.localID}`\n}\n\nexport function stringToGuid(str: string): GUID {\n const match = str.match(/^(?:VariableID:|VariableCollectionId:)?(\\d+):(\\d+)$/)\n if (match) {\n return { sessionID: Number.parseInt(match[1], 10), localID: Number.parseInt(match[2], 10) }\n }\n const [session, local] = str.split(':')\n return { sessionID: Number.parseInt(session, 10), localID: Number.parseInt(local, 10) }\n}\n"],"mappings":";;;;;AAMA,MAAa,aAA6B;CAAE,WAAW;CAAY,SAAS;AAAW;AAEvF,SAAgB,YAAY,MAAqB;CAC/C,OAAO,KAAK,cAAc,WAAW,aAAa,KAAK,YAAY,WAAW;AAChF;AAEA,SAAgB,aAAa,MAAoB;CAC/C,OAAO,GAAG,KAAK,UAAU,GAAG,KAAK;AACnC;AAEA,SAAgB,aAAa,KAAmB;CAC9C,MAAM,QAAQ,IAAI,MAAM,qDAAqD;CAC7E,IAAI,OACF,OAAO;EAAE,WAAW,OAAO,SAAS,MAAM,IAAI,EAAE;EAAG,SAAS,OAAO,SAAS,MAAM,IAAI,EAAE;CAAE;CAE5F,MAAM,CAAC,SAAS,SAAS,IAAI,MAAM,GAAG;CACtC,OAAO;EAAE,WAAW,OAAO,SAAS,SAAS,EAAE;EAAG,SAAS,OAAO,SAAS,OAAO,EAAE;CAAE;AACxF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NodeChange } from "./codec.js";
|
|
2
|
+
import { FigFileKind } from "./container.js";
|
|
3
|
+
import { HeaderFields } from "../index.js";
|
|
4
|
+
import { FigPageManifestEntry } from "../page-manifest.js";
|
|
5
|
+
//#region src/fig/parse.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Deduplicates pluginData/pluginRelaunchData entries on raw NodeChange objects.
|
|
8
|
+
* Some .fig files have millions of identical entries where only a small
|
|
9
|
+
* fraction are unique by full triple.
|
|
10
|
+
* Full-triple key (id+key+value) preserves multi-entry subsystems like OkHCL.
|
|
11
|
+
*/
|
|
12
|
+
declare function deduplicateNodeChangePluginData(nodeChanges: NodeChange[]): void;
|
|
13
|
+
interface FigKiwiPayload {
|
|
14
|
+
schemaDeflated: Uint8Array;
|
|
15
|
+
dataRaw: Uint8Array;
|
|
16
|
+
version: number;
|
|
17
|
+
kind: FigFileKind;
|
|
18
|
+
}
|
|
19
|
+
declare function parseFigKiwiContainer(data: Uint8Array): FigKiwiPayload | null;
|
|
20
|
+
interface FigKiwiDecodeResult {
|
|
21
|
+
nodeChanges: NodeChange[];
|
|
22
|
+
blobs: Uint8Array[];
|
|
23
|
+
figKiwiVersion: number;
|
|
24
|
+
/** Deflated kiwi schema bytes from the original file (for roundtrip fidelity). */
|
|
25
|
+
figSchemaDeflated: Uint8Array;
|
|
26
|
+
/** A design file or a FigJam board, by the canvas's header. */
|
|
27
|
+
kind: FigFileKind;
|
|
28
|
+
}
|
|
29
|
+
/** Decode one raw `fig-kiwi` canvas payload. Outer `.fig` archive handling lives in `@pairdraw/fig`. */
|
|
30
|
+
declare function decodeFigKiwiCanvas(data: Uint8Array, onPages?: (pages: FigPageManifestEntry[]) => void, headers?: HeaderFields): FigKiwiDecodeResult;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { FigKiwiDecodeResult, decodeFigKiwiCanvas, deduplicateNodeChangePluginData, parseFigKiwiContainer };
|
|
33
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ByteBuffer, compileSchemaRuntime, decodeBinarySchema, decompressFigKiwiData, figFileKind } from "../chunks/fig/codec.js";
|
|
2
|
+
import { extractFigPageManifest } from "../fig.js";
|
|
3
|
+
import { inflateSync } from "fflate";
|
|
4
|
+
//#region src/fig/parse.ts
|
|
5
|
+
/**
|
|
6
|
+
* Deduplicates pluginData/pluginRelaunchData entries on raw NodeChange objects.
|
|
7
|
+
* Some .fig files have millions of identical entries where only a small
|
|
8
|
+
* fraction are unique by full triple.
|
|
9
|
+
* Full-triple key (id+key+value) preserves multi-entry subsystems like OkHCL.
|
|
10
|
+
*/
|
|
11
|
+
function deduplicateNodeChangePluginData(nodeChanges) {
|
|
12
|
+
for (const nc of nodeChanges) {
|
|
13
|
+
if (nc.pluginData && nc.pluginData.length > 1) {
|
|
14
|
+
const map = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const entry of nc.pluginData) map.set(`${entry.pluginID}\0${entry.key}\0${entry.value}`, entry);
|
|
16
|
+
if (map.size < nc.pluginData.length) nc.pluginData = [...map.values()];
|
|
17
|
+
}
|
|
18
|
+
if (nc.pluginRelaunchData && nc.pluginRelaunchData.length > 1) {
|
|
19
|
+
const map = /* @__PURE__ */ new Map();
|
|
20
|
+
for (const entry of nc.pluginRelaunchData) map.set(`${entry.pluginID}\0${entry.command}\0${entry.message}\0${entry.isDeleted}`, entry);
|
|
21
|
+
if (map.size < nc.pluginRelaunchData.length) nc.pluginRelaunchData = [...map.values()];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function parseFigKiwiContainer(data) {
|
|
26
|
+
const kind = figFileKind(data);
|
|
27
|
+
if (!kind) return null;
|
|
28
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
29
|
+
const version = view.getUint32(8, true);
|
|
30
|
+
let offset = 12;
|
|
31
|
+
const chunks = [];
|
|
32
|
+
while (offset < data.length) {
|
|
33
|
+
if (offset + 4 > data.length) break;
|
|
34
|
+
const len = view.getUint32(offset, true);
|
|
35
|
+
offset += 4;
|
|
36
|
+
if (offset + len > data.length) throw new Error(`Corrupted .fig file: chunk at offset ${offset - 4} declares length ${len} but only ${data.length - offset} bytes remain`);
|
|
37
|
+
chunks.push(data.slice(offset, offset + len));
|
|
38
|
+
offset += len;
|
|
39
|
+
}
|
|
40
|
+
if (chunks.length < 2) return null;
|
|
41
|
+
return {
|
|
42
|
+
schemaDeflated: chunks[0],
|
|
43
|
+
dataRaw: decompressFigKiwiData(chunks[1]),
|
|
44
|
+
version,
|
|
45
|
+
kind
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function isRuntimeMessage(value) {
|
|
49
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Uint8Array);
|
|
50
|
+
}
|
|
51
|
+
/** Decode one raw `fig-kiwi` canvas payload. Outer `.fig` archive handling lives in `@pairdraw/fig`. */
|
|
52
|
+
function decodeFigKiwiCanvas(data, onPages, headers) {
|
|
53
|
+
const payload = parseFigKiwiContainer(data);
|
|
54
|
+
if (!payload) throw new Error("Invalid fig-kiwi container");
|
|
55
|
+
const schemaBytes = inflateSync(payload.schemaDeflated);
|
|
56
|
+
const compiled = compileSchemaRuntime(decodeBinarySchema(new ByteBuffer(schemaBytes)), headers);
|
|
57
|
+
if (onPages) try {
|
|
58
|
+
const pages = extractFigPageManifest(compiled.schema, payload.dataRaw);
|
|
59
|
+
if (pages.length > 0) onPages(pages);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.warn("Failed to scan FIG page manifest; continuing with full decode:", error);
|
|
62
|
+
}
|
|
63
|
+
if (!compiled.decodeMessage) throw new Error("The fig-kiwi schema has no Message");
|
|
64
|
+
const message = compiled.decodeMessage(payload.dataRaw);
|
|
65
|
+
const records = message.nodeChanges;
|
|
66
|
+
if (!Array.isArray(records) || records.length === 0) throw new Error("No nodes found in .fig file");
|
|
67
|
+
const nodeChanges = records;
|
|
68
|
+
deduplicateNodeChangePluginData(nodeChanges);
|
|
69
|
+
return {
|
|
70
|
+
nodeChanges,
|
|
71
|
+
blobs: (Array.isArray(message.blobs) ? message.blobs : []).map((blob) => {
|
|
72
|
+
const bytes = isRuntimeMessage(blob) ? blob.bytes : void 0;
|
|
73
|
+
return bytes instanceof Uint8Array ? bytes : new Uint8Array(Object.values(bytes ?? {}));
|
|
74
|
+
}),
|
|
75
|
+
figKiwiVersion: payload.version,
|
|
76
|
+
figSchemaDeflated: payload.schemaDeflated,
|
|
77
|
+
kind: payload.kind
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
export { decodeFigKiwiCanvas, deduplicateNodeChangePluginData, parseFigKiwiContainer };
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=parse.js.map
|