@pairdraw/scene-graph 0.19.2 → 0.20.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.
Files changed (166) hide show
  1. package/dist/components/index.d.ts +2 -2
  2. package/dist/components/index.js +2 -2
  3. package/dist/components/variants.d.ts +12 -1
  4. package/dist/components/variants.d.ts.map +1 -1
  5. package/dist/components/variants.js +30 -1
  6. package/dist/components/variants.js.map +1 -1
  7. package/dist/constants.d.ts +25 -1
  8. package/dist/constants.d.ts.map +1 -1
  9. package/dist/constants.js +94 -1
  10. package/dist/constants.js.map +1 -1
  11. package/dist/copy.d.ts.map +1 -1
  12. package/dist/copy.js +17 -1
  13. package/dist/copy.js.map +1 -1
  14. package/dist/css/index.d.ts +2 -2
  15. package/dist/css/index.js +2 -2
  16. package/dist/css/text.d.ts +17 -1
  17. package/dist/css/text.d.ts.map +1 -1
  18. package/dist/css/text.js +62 -1
  19. package/dist/css/text.js.map +1 -1
  20. package/dist/design-memory/index.d.ts +3 -0
  21. package/dist/design-memory/index.js +3 -0
  22. package/dist/design-memory/model.d.ts +33 -0
  23. package/dist/design-memory/model.d.ts.map +1 -0
  24. package/dist/design-memory/model.js +142 -0
  25. package/dist/design-memory/model.js.map +1 -0
  26. package/dist/design-memory/schema.d.ts +76 -0
  27. package/dist/design-memory/schema.d.ts.map +1 -0
  28. package/dist/design-memory/schema.js +72 -0
  29. package/dist/design-memory/schema.js.map +1 -0
  30. package/dist/effects.d.ts +7 -4
  31. package/dist/effects.d.ts.map +1 -1
  32. package/dist/effects.js +9 -4
  33. package/dist/effects.js.map +1 -1
  34. package/dist/empty-values.js +93 -0
  35. package/dist/empty-values.js.map +1 -0
  36. package/dist/fields/components.d.ts +9 -0
  37. package/dist/fields/components.d.ts.map +1 -0
  38. package/dist/fields/components.js +24 -0
  39. package/dist/fields/components.js.map +1 -0
  40. package/dist/fields/index.d.ts +3 -2
  41. package/dist/fields/index.js +3 -2
  42. package/dist/fields/layout.d.ts +3 -1
  43. package/dist/fields/layout.d.ts.map +1 -1
  44. package/dist/fields/layout.js +10 -1
  45. package/dist/fields/layout.js.map +1 -1
  46. package/dist/graph.d.ts +8 -1
  47. package/dist/graph.d.ts.map +1 -1
  48. package/dist/graph.js +28 -5
  49. package/dist/graph.js.map +1 -1
  50. package/dist/grid-values.d.ts +10 -0
  51. package/dist/grid-values.d.ts.map +1 -0
  52. package/dist/grid-values.js +53 -0
  53. package/dist/grid-values.js.map +1 -0
  54. package/dist/hit-test/drop.d.ts +20 -0
  55. package/dist/hit-test/drop.d.ts.map +1 -0
  56. package/dist/hit-test/drop.js +54 -0
  57. package/dist/hit-test/drop.js.map +1 -0
  58. package/dist/hit-test/geometry.js +86 -0
  59. package/dist/hit-test/geometry.js.map +1 -0
  60. package/dist/hit-test/masks.d.ts +14 -0
  61. package/dist/hit-test/masks.d.ts.map +1 -0
  62. package/dist/hit-test/masks.js +41 -0
  63. package/dist/hit-test/masks.js.map +1 -0
  64. package/dist/hit-test/paint.d.ts +6 -0
  65. package/dist/hit-test/paint.d.ts.map +1 -0
  66. package/dist/hit-test/paint.js +19 -0
  67. package/dist/hit-test/paint.js.map +1 -0
  68. package/dist/hit-test.d.ts +4 -15
  69. package/dist/hit-test.d.ts.map +1 -1
  70. package/dist/hit-test.js +5 -173
  71. package/dist/hit-test.js.map +1 -1
  72. package/dist/index.d.ts +2 -2
  73. package/dist/instances/fields.d.ts.map +1 -1
  74. package/dist/instances/fields.js +2 -0
  75. package/dist/instances/fields.js.map +1 -1
  76. package/dist/instances/index.d.ts +2 -1
  77. package/dist/instances/index.d.ts.map +1 -1
  78. package/dist/instances/index.js +1 -1
  79. package/dist/instances/index.js.map +1 -1
  80. package/dist/instances/source-walk.d.ts +12 -0
  81. package/dist/instances/source-walk.d.ts.map +1 -0
  82. package/dist/node-defaults.d.ts.map +1 -1
  83. package/dist/node-defaults.js +41 -36
  84. package/dist/node-defaults.js.map +1 -1
  85. package/dist/plugin-data/fields.d.ts +75 -0
  86. package/dist/plugin-data/fields.d.ts.map +1 -1
  87. package/dist/plugin-data/fields.js +18 -1
  88. package/dist/plugin-data/fields.js.map +1 -1
  89. package/dist/preview.d.ts.map +1 -1
  90. package/dist/preview.js +2 -0
  91. package/dist/preview.js.map +1 -1
  92. package/dist/scaling/node.d.ts.map +1 -1
  93. package/dist/scaling/node.js +5 -1
  94. package/dist/scaling/node.js.map +1 -1
  95. package/dist/token-sources/document.d.ts +26 -0
  96. package/dist/token-sources/document.d.ts.map +1 -0
  97. package/dist/token-sources/document.js +80 -0
  98. package/dist/token-sources/document.js.map +1 -0
  99. package/dist/token-sources/index.d.ts +3 -0
  100. package/dist/token-sources/index.js +3 -0
  101. package/dist/token-sources/schema.d.ts +43 -0
  102. package/dist/token-sources/schema.d.ts.map +1 -0
  103. package/dist/token-sources/schema.js +50 -0
  104. package/dist/token-sources/schema.js.map +1 -0
  105. package/dist/types.d.ts +102 -14
  106. package/dist/types.d.ts.map +1 -1
  107. package/dist/types.js.map +1 -1
  108. package/dist/variations/copy.d.ts +16 -0
  109. package/dist/variations/copy.d.ts.map +1 -0
  110. package/dist/variations/copy.js +78 -0
  111. package/dist/variations/copy.js.map +1 -0
  112. package/dist/variations/index.d.ts +6 -0
  113. package/dist/variations/index.js +6 -0
  114. package/dist/variations/match.d.ts +23 -0
  115. package/dist/variations/match.d.ts.map +1 -0
  116. package/dist/variations/match.js +80 -0
  117. package/dist/variations/match.js.map +1 -0
  118. package/dist/variations/model.d.ts +39 -0
  119. package/dist/variations/model.d.ts.map +1 -0
  120. package/dist/variations/model.js +90 -0
  121. package/dist/variations/model.js.map +1 -0
  122. package/dist/variations/pick.d.ts +43 -0
  123. package/dist/variations/pick.d.ts.map +1 -0
  124. package/dist/variations/pick.js +211 -0
  125. package/dist/variations/pick.js.map +1 -0
  126. package/dist/variations/schema.d.ts +27 -0
  127. package/dist/variations/schema.d.ts.map +1 -0
  128. package/dist/variations/schema.js +27 -0
  129. package/dist/variations/schema.js.map +1 -0
  130. package/package.json +21 -1
  131. package/src/components/variants.ts +39 -0
  132. package/src/constants.ts +75 -0
  133. package/src/copy.ts +20 -1
  134. package/src/css/index.ts +7 -1
  135. package/src/css/text.ts +62 -0
  136. package/src/design-memory/index.ts +2 -0
  137. package/src/design-memory/model.ts +143 -0
  138. package/src/design-memory/schema.ts +84 -0
  139. package/src/effects.ts +16 -7
  140. package/src/empty-values.ts +101 -0
  141. package/src/fields/components.ts +21 -0
  142. package/src/fields/index.ts +1 -0
  143. package/src/fields/layout.ts +10 -0
  144. package/src/graph.ts +37 -5
  145. package/src/grid-values.ts +47 -0
  146. package/src/hit-test/drop.ts +90 -0
  147. package/src/hit-test/geometry.ts +131 -0
  148. package/src/hit-test/masks.ts +57 -0
  149. package/src/hit-test/paint.ts +24 -0
  150. package/src/hit-test.ts +8 -277
  151. package/src/instances/fields.ts +2 -0
  152. package/src/instances/index.ts +1 -0
  153. package/src/node-defaults.ts +49 -39
  154. package/src/plugin-data/fields.ts +18 -1
  155. package/src/preview.ts +2 -0
  156. package/src/scaling/node.ts +7 -2
  157. package/src/token-sources/document.ts +104 -0
  158. package/src/token-sources/index.ts +2 -0
  159. package/src/token-sources/schema.ts +59 -0
  160. package/src/types.ts +115 -13
  161. package/src/variations/copy.ts +89 -0
  162. package/src/variations/index.ts +5 -0
  163. package/src/variations/match.ts +100 -0
  164. package/src/variations/model.ts +132 -0
  165. package/src/variations/pick.ts +293 -0
  166. package/src/variations/schema.ts +29 -0
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/* eslint-disable max-lines -- scene node contracts are kept together as the public graph type surface */\n\nimport type { ExportFormatId } from './export-format'\nimport type { CanvasGuide } from './guides'\nimport type { InstanceOverrideState } from './instances/overrides'\nimport type { Color, Matrix, Rect, Vector } from './primitives'\nimport type { ShaderUniformValue } from './shaders/schema'\nimport type { ShapeWithTextType } from './shape-with-text/kinds'\n\nexport interface SceneGraphEvents {\n 'node:created': (node: SceneNode) => void\n 'node:updated': (id: string, changes: Partial<SceneNode>) => void\n 'node:previewUpdated': (id: string, changes: Partial<SceneNode>) => void\n 'node:deleted': (id: string, parentId: string | null) => void\n 'node:reparented': (nodeId: string, oldParentId: string | null, newParentId: string) => void\n 'node:reordered': (\n nodeId: string,\n parentId: string,\n index: number,\n previousParentId: string | null\n ) => void\n}\n\nexport type SceneGraphEventHandlers = Partial<{\n created: (node: SceneNode) => void\n updated: (id: string, changes: Partial<SceneNode>) => void\n previewUpdated: (id: string, changes: Partial<SceneNode>) => void\n deleted: (id: string, parentId: string | null) => void\n reparented: (nodeId: string, oldParentId: string | null, newParentId: string) => void\n reordered: (\n nodeId: string,\n parentId: string,\n index: number,\n previousParentId: string | null\n ) => void\n}>\n\n/** Hears about nodes as an edit adds and changes them, synchronously and before each change. */\nexport interface NodeChangeObserver {\n /** A node is about to change and is still as it was. */\n before: (node: SceneNode) => void\n /** A node was just added. */\n created: (node: SceneNode) => void\n /** What changes from now until `resume` is someone else's; `waitOutsideEdit` calls this. */\n pause?: () => void\n /** The wait ended, and what changed meanwhile belongs outside the edit. */\n resume?: () => void\n}\n\nexport type DocumentColorSpace = 'srgb' | 'display-p3'\n\n/** What a document is for, as Figma keeps design files and FigJam boards apart. */\nexport type DocumentKind = 'design' | 'board'\n\nexport interface FigmaSourcePayload {\n rawSize: Vector | null\n rawTransform: Matrix | null\n rawNodeFields: Record<string, unknown>\n layout: FigmaLayoutMetadata | null\n symbolOverrides: unknown[]\n componentPropAssignments: unknown[]\n derivedSymbolData: unknown[]\n derivedSymbolDataLayoutVersion: number | null\n uniformScaleFactor: number | null\n}\n\nexport interface SourceMetadata {\n format: 'fig' | null\n id: string | null\n orderKey: string | null\n editedFields: string[]\n fig: FigmaSourcePayload\n}\n\nexport type HandleMirroring = 'NONE' | 'ANGLE' | 'ANGLE_AND_LENGTH'\nexport type WindingRule = 'NONZERO' | 'EVENODD'\n\nexport interface VectorVertex {\n x: number\n y: number\n strokeCap?: string\n strokeJoin?: string\n cornerRadius?: number\n handleMirroring?: HandleMirroring\n}\n\nexport interface VectorSegment {\n start: number\n end: number\n tangentStart: Vector\n tangentEnd: Vector\n}\n\nexport interface VectorRegion {\n windingRule: WindingRule\n loops: number[][]\n}\n\nexport interface VectorNetwork {\n vertices: VectorVertex[]\n segments: VectorSegment[]\n regions: VectorRegion[]\n}\n\nexport interface GeometryPath {\n windingRule: WindingRule\n commandsBlob: Uint8Array\n /** Resolved paints for geometry using a format-specific style override. */\n fills?: Fill[]\n /** Shared fill style attached to this geometry region, when available. */\n fillStyleId?: string\n}\n\nexport type NodeType =\n | 'CANVAS'\n | 'FRAME'\n | 'RECTANGLE'\n | 'ROUNDED_RECTANGLE'\n | 'ELLIPSE'\n | 'TEXT'\n | 'LINE'\n | 'STAR'\n | 'POLYGON'\n | 'VECTOR'\n | 'BOOLEAN_OPERATION'\n | 'GROUP'\n | 'SECTION'\n | 'COMPONENT'\n | 'COMPONENT_SET'\n | 'INSTANCE'\n | 'CONNECTOR'\n | 'SHAPE_WITH_TEXT'\n | 'STICKY'\n | 'SCRIPT'\n\nexport type FillType =\n | 'SOLID'\n | 'GRADIENT_LINEAR'\n | 'GRADIENT_RADIAL'\n | 'GRADIENT_ANGULAR'\n | 'GRADIENT_DIAMOND'\n | 'MESH'\n | 'IMAGE'\n | 'VIDEO'\n | 'PATTERN'\n | 'NOISE'\n | 'CUSTOM'\nexport type BlendMode =\n | 'NORMAL'\n | 'DARKEN'\n | 'MULTIPLY'\n | 'LINEAR_BURN'\n | 'COLOR_BURN'\n | 'LIGHTEN'\n | 'SCREEN'\n | 'LINEAR_DODGE'\n | 'COLOR_DODGE'\n | 'OVERLAY'\n | 'SOFT_LIGHT'\n | 'HARD_LIGHT'\n | 'DIFFERENCE'\n | 'EXCLUSION'\n | 'HUE'\n | 'SATURATION'\n | 'COLOR'\n | 'LUMINOSITY'\n | 'PASS_THROUGH'\nexport type ImageScaleMode = 'FILL' | 'FIT' | 'CROP' | 'TILE'\nexport type NoiseType = 'MULTITONE' | 'MONOTONE' | 'DUOTONE'\nexport type PatternTileType = 'RECTANGULAR' | 'HORIZONTAL_HEXAGONAL' | 'VERTICAL_HEXAGONAL'\nexport type PatternAlignment = 'START' | 'CENTER' | 'END'\n\nexport interface GradientStop {\n color: Color\n position: number\n}\n\n/**\n * One control point of a `MESH` fill: its color, and where it sits in the layer's unit square.\n * A mesh holds `(rows + 1) * (columns + 1)` points in row-major order: corners and edge points\n * first, so a 1x1 mesh is the four corners. Positions outside 0..1 are allowed; the renderer\n * clamps them to the layer.\n */\nexport interface MeshGradientPoint {\n position: Vector\n color: Color\n}\n\nexport type GradientTransform = Matrix\n\n/** Figma's adjustments of an image paint, each from -1 to 1; 0 leaves the image as it is. */\nexport interface ImageFilters {\n exposure?: number\n contrast?: number\n saturation?: number\n temperature?: number\n tint?: number\n highlights?: number\n shadows?: number\n}\n\nexport interface Fill {\n type: FillType\n color: Color\n opacity: number\n visible: boolean\n blendMode?: BlendMode\n gradientStops?: GradientStop[]\n gradientTransform?: GradientTransform\n /** A `MESH` fill's grid: columns and rows of cells, with one more point than cells each way. */\n meshColumns?: number\n meshRows?: number\n meshPoints?: MeshGradientPoint[]\n imageHash?: string\n imageScaleMode?: ImageScaleMode\n /** A crop's image-space window; Fill, Fit and Tile ignore it. */\n imageTransform?: GradientTransform\n /** Clockwise turn of a Fill, Fit or Tile image, in multiples of 90°; a crop holds its own. */\n imageRotation?: number\n /** An image's adjustments, kept and saved; the canvas does not draw them. */\n filters?: ImageFilters\n sourceNodeId?: string\n scale?: number\n spacing?: number\n patternSpacing?: Vector\n patternTileType?: PatternTileType\n verticalAlignment?: PatternAlignment\n horizontalAlignment?: PatternAlignment\n noiseType?: NoiseType\n density?: number\n noiseSize?: Vector\n customEffectId?: string\n}\n\nexport type StrokeCap =\n | 'NONE'\n | 'ROUND'\n | 'SQUARE'\n | 'ARROW_LINES'\n | 'ARROW_EQUILATERAL'\n | 'TRIANGLE_FILLED'\n | 'DIAMOND_FILLED'\n | 'CIRCLE_FILLED'\nexport type StrokeJoin = 'MITER' | 'BEVEL' | 'ROUND'\nexport type SharedStyleType = 'FILL' | 'TEXT' | 'EFFECT' | 'GRID'\nexport type SharedStyleKind = 'fill' | 'stroke' | 'text' | 'effect' | 'grid'\nexport type MaskType = 'ALPHA' | 'VECTOR' | 'LUMINANCE'\nexport type BooleanOperation = 'UNION' | 'SUBTRACT' | 'INTERSECT' | 'EXCLUDE'\n\nexport interface LayoutGrid {\n visible?: boolean\n color?: Color\n /** `STRIPES` is the archive's name for columns or rows, along `axis`. */\n pattern?: 'COLUMNS' | 'ROWS' | 'GRID' | 'STRIPES'\n axis?: 'X' | 'Y'\n type?: 'MIN' | 'CENTER' | 'MAX' | 'STRETCH'\n alignment?: 'MIN' | 'CENTER' | 'MAX' | 'STRETCH'\n numSections?: number\n /** Figma's plugin API reports an Auto count as `null` and accepts `Infinity` for it. */\n count?: number | null\n offset?: number\n sectionSize?: number\n gutterSize?: number\n}\n\nexport interface SharedStyle {\n id: string\n nodeId: string\n name: string\n type: SharedStyleType\n}\n\n/** A stroke is a paint with the geometry that decides where it is drawn. */\nexport interface Stroke extends Fill {\n weight: number\n align: 'INSIDE' | 'CENTER' | 'OUTSIDE'\n cap?: StrokeCap\n join?: StrokeJoin\n dashPattern?: number[]\n}\n\nexport type Effect = ShadowEffect | ShaderEffect\n\nexport interface ShadowEffect {\n type: 'DROP_SHADOW' | 'INNER_SHADOW' | 'LAYER_BLUR' | 'BACKGROUND_BLUR' | 'FOREGROUND_BLUR'\n color: Color\n offset: Vector\n radius: number\n spread: number\n visible: boolean\n blendMode?: BlendMode\n showShadowBehindNode?: boolean\n}\n\n/** A layer post-processed by shader code the user wrote; the layer is the `pencil:object` sample. */\nexport interface ShaderEffect {\n type: 'SHADER'\n source: string\n uniforms?: Record<string, ShaderUniformValue>\n uniformBindings?: Record<string, string>\n visible: boolean\n blendMode?: BlendMode\n}\n\nexport type ConstraintType = 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'SCALE'\nexport type TextAutoResize = 'NONE' | 'HEIGHT' | 'WIDTH_AND_HEIGHT' | 'TRUNCATE'\n\n/** Where a connector end attaches to a layer: a side, the side Figma picks, or a fixed point. */\nexport type ConnectorMagnet =\n | 'NONE'\n | 'AUTO'\n | 'AUTO_HORIZONTAL'\n | 'TOP'\n | 'RIGHT'\n | 'BOTTOM'\n | 'LEFT'\n | 'CENTER'\n | 'EDGE'\n | 'ABSOLUTE'\n\n/**\n * One end of a connector. Bound to a layer, it follows the layer by `magnet`, or by `position`\n * in the layer's own axes when the magnet is `NONE`. Free, `nodeId` is null and `position` is in\n * the connector's parent's axes.\n */\nexport interface ConnectorEndpoint {\n nodeId: string | null\n magnet: ConnectorMagnet\n position: Vector\n}\n\nexport type ConnectorLineType = 'ELBOWED' | 'STRAIGHT' | 'CURVED'\n\n/**\n * A segment of an elbow connector that was dragged into place: the line it runs along, through\n * `position`, in the connector's own axes. `position` lies midway along the segment as last drawn.\n */\nexport interface ConnectorControlPoint {\n position: Vector\n direction: 'HORIZONTAL' | 'VERTICAL'\n}\n\n/**\n * Where a connector's label was dragged along its line: `offset` of the way from the middle of\n * the line towards one end, by length, on the line or to one side of it. `ABOVE` is the side to\n * the left of the line's direction.\n */\nexport interface ConnectorLabelPosition {\n section: 'MIDDLE_TO_START' | 'MIDDLE_TO_END'\n offset: number\n offAxis: 'NONE' | 'ABOVE' | 'BELOW'\n}\nexport type TextAlignVertical = 'TOP' | 'CENTER' | 'BOTTOM'\nexport type TextCase = 'ORIGINAL' | 'UPPER' | 'LOWER' | 'TITLE'\nexport type TextDecoration = 'NONE' | 'UNDERLINE' | 'STRIKETHROUGH'\nexport type TextDecorationStyle = 'SOLID' | 'DOTTED' | 'WAVY'\nexport type LeadingTrim = 'NONE' | 'CAP_HEIGHT'\nexport type TextDirection = 'AUTO' | 'LTR' | 'RTL'\nexport type LayoutDirection = 'AUTO' | 'LTR' | 'RTL'\n/** Whether a paragraph is an item of a numbered list, a bulleted list, or no list. */\nexport type TextListType = 'NONE' | 'ORDERED' | 'UNORDERED'\n\n/** How one paragraph of a text node (a line ending at a newline) sits in a list. */\n/** Spacing a text sets for all its paragraphs and a paragraph can set for itself. */\nexport type TextParagraphSpacingField = 'listSpacing' | 'paragraphSpacing' | 'paragraphIndent'\n\nexport interface TextParagraphStyle {\n listType: TextListType\n /** Nesting level: 1–5 for list items; kept but not drawn for plain paragraphs. */\n indentation: number\n /** This paragraph's own spacing, in place of the text's; absent ones follow the text. */\n listSpacing?: number\n paragraphSpacing?: number\n paragraphIndent?: number\n}\n\nexport interface FontVariation {\n axis: string\n value: number\n}\n\nexport interface FontFeature {\n tag: string\n enabled: boolean\n}\n\n/** Where a stretch of text links to, as Figma's `HyperlinkTarget`: a URL, or a node by its ID. */\nexport interface HyperlinkTarget {\n type: 'URL' | 'NODE'\n value: string\n}\n\n/** The text fields a range of characters can bind to a variable, as Figma lists them. */\nexport const TEXT_BINDABLE_FIELDS = [\n 'fontFamily',\n 'fontSize',\n 'fontStyle',\n 'fontWeight',\n 'letterSpacing',\n 'lineHeight',\n 'paragraphSpacing',\n 'paragraphIndent'\n] as const\n\nexport type TextBindableField = (typeof TEXT_BINDABLE_FIELDS)[number]\n\n/** Variable IDs bound to text fields, by field. */\nexport type TextBoundVariables = Partial<Record<TextBindableField, string>>\n\n/**\n * A line height or letter spacing as Figma keeps it: pixels, or a percent of the font size that\n * follows the size when it changes.\n */\nexport interface TextLength {\n value: number\n unit: 'PIXELS' | 'PERCENT'\n}\n\nexport interface CharacterStyleOverride {\n fontWeight?: number\n italic?: boolean\n /** The characters' face by its font's own name for it; `null` is the face their weight picks. */\n fontStyle?: string | null\n textDecoration?: TextDecoration\n textDecorationStyle?: TextDecorationStyle\n textDecorationThickness?: number | null\n textDecorationFills?: Fill[]\n textDecorationSkipInk?: boolean\n textUnderlineOffset?: number | null\n fontSize?: number\n fontFamily?: string\n letterSpacing?: TextLength\n /** `null` is automatic, from the font. */\n lineHeight?: TextLength | null\n fills?: Fill[]\n fontVariations?: FontVariation[]\n /** Whether the characters' optical size follows their font size, in place of the text's own. */\n opticalSizeFromFontSize?: boolean\n fontFeatures?: FontFeature[]\n textLanguage?: string | null\n textCase?: TextCase\n /** A link over the characters; `null`, like leaving it out, links nowhere. */\n hyperlink?: HyperlinkTarget | null\n /** The text style the characters use in place of the text's own; `null` uses none. */\n textStyleId?: string | null\n /** The fill style the characters use in place of the text's own; `null` uses none. */\n fillStyleId?: string | null\n /** The characters' text field bindings, in place of the text's own. */\n boundVariables?: TextBoundVariables\n /**\n * The scale each number the characters bind resolves with, as a rescale left it; a field without\n * one uses the layer's `variableBindingScales`, as runs did before they kept their own.\n */\n variableBindingScales?: Partial<Record<TextBindableField, number>>\n}\n\nexport interface StyleRun {\n start: number\n length: number\n style: CharacterStyleOverride\n}\n\nexport interface ArcData {\n startingAngle: number\n endingAngle: number\n innerRadius: number\n}\n\nexport type LayoutMode = 'NONE' | 'HORIZONTAL' | 'VERTICAL' | 'GRID'\n/** A node's sizing along one axis; fill is stored on the child, see `layoutSizing`. */\nexport type LayoutSizing = 'FIXED' | 'HUG' | 'FILL'\n/** Whether an auto-layout frame keeps its size or hugs its children along one of its axes. */\nexport type AxisSizingMode = 'FIXED' | 'HUG'\n\nexport type GridTrackSizing = 'FIXED' | 'FR' | 'AUTO'\n\nexport interface GridTrack {\n sizing: GridTrackSizing\n value: number\n}\n\nexport interface GridPosition {\n column: number\n row: number\n columnSpan: number\n rowSpan: number\n}\n/**\n * Primary axis alignment of an auto layout's children. `SPACE_AROUND` is Pairdraw's own:\n * Figma has no such mode, so `.fig` files keep it as plugin data over Figma's space between.\n */\nexport type LayoutAlign = 'MIN' | 'CENTER' | 'MAX' | 'SPACE_BETWEEN' | 'SPACE_AROUND'\nexport type LayoutCounterAlign = 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'BASELINE'\nexport type LayoutAlignSelf = 'AUTO' | 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'BASELINE'\nexport type LayoutWrap = 'NO_WRAP' | 'WRAP'\n\nexport interface PluginDataEntry {\n pluginId: string\n key: string\n value: string\n}\n\nexport interface ExportSetting {\n scale: number\n format: ExportFormatId\n /** JPG and WEBP quality from 1 to 100; absent means the encoder's default. */\n quality?: number\n}\n\nexport interface PluginRelaunchDataEntry {\n pluginId: string\n command: string\n message: string\n isDeleted: boolean\n}\n\n/**\n * One derived glyph outline for display (path text / missing-font fidelity).\n * Figma import is one producer; Pairdraw editing and reflow can regenerate it.\n * commandsBlob is in font units; paint multiplies by fontSize (and scaleX/Y).\n */\nexport interface TextPathData {\n network: VectorNetwork\n normalizedSize: Vector\n /** Where on the start segment the text starts, from 0 at its start to 1 at its end. */\n tValue: number\n forward: boolean\n /** The segment the text starts on, which Figma marks in the network blob; 0 when unmarked. */\n startSegment?: number\n}\n\nexport interface DerivedTextGlyph {\n /** UTF-16 source-text cluster start, when supplied by the shaping source. */\n firstCharacter?: number\n commandsBlob: Uint8Array\n x: number\n y: number\n fontSize: number\n /** Figma Glyph.rotation — radians, not degrees. Zero for axis-aligned text. */\n rotation?: number\n /**\n * Horizontal advance in pixels at `fontSize`, before `scaleX`, when the shaping source gave\n * one; where the glyph ends, so decorations stop at the text rather than the layer's edge.\n */\n advance?: number\n /**\n * Accumulated non-uniform resize scale (default 1). Paint order is\n * translate → scale(scaleX,Y) → rotate → scale(fontSize,-fontSize) so\n * anisotropic stretch matches scaleGeometryPaths(strokeGeometry).\n * Do not fold this into fontSize or rotated letters desync from outlines.\n */\n scaleX?: number\n scaleY?: number\n /**\n * The code points of the emoji this glyph stands for, sequence and all. Its outline is only a\n * placeholder square a 1 em wide; the emoji's image is drawn there instead, as Figma does.\n */\n emojiCodePoints?: number[]\n /** The image set Figma draws the emoji from, when the file names one other than Apple's. */\n emojiImageSet?: 'NOTO'\n}\n\nexport interface SymbolLink {\n uri: string\n displayName?: string\n displayText?: string\n}\n\nexport interface VariantPropSpec {\n propDefId: string\n value: string\n}\n\nexport type FigmaLayoutMetadata = Partial<\n Record<\n | 'stackMode'\n | 'stackCounterAlign'\n | 'stackJustify'\n | 'stackCounterAlignItems'\n | 'stackPrimaryAlignItems'\n | 'stackPrimarySizing'\n | 'stackCounterSizing'\n | 'stackWrap'\n | 'stackPositioning'\n | 'stackChildAlignSelf',\n string\n > &\n Record<\n | 'stackSpacing'\n | 'stackPadding'\n | 'stackPaddingRight'\n | 'stackPaddingBottom'\n | 'stackVerticalPadding'\n | 'stackHorizontalPadding'\n | 'stackChildPrimaryGrow'\n | 'stackCounterSpacing',\n number\n > &\n Record<'bordersTakeSpace' | 'stackReverseZIndex', boolean>\n>\n\nexport interface LibraryAssetIdentity {\n libraryId: string\n assetKey: string\n revisionId: string\n}\n\nexport interface LibraryAssetSource {\n identity: LibraryAssetIdentity\n sourceNodeId: string | null\n readOnly: boolean\n}\n\nexport interface EnabledLibraryBinding {\n libraryId: string\n revisionId: string\n enabled: boolean\n}\n\n/** The library a document publishes as. */\nexport interface SourceLibraryPublication {\n libraryId: string\n revisionId: string\n name: string\n catalogSource?: string\n}\n\n/** A reply in a canvas comment thread. */\nexport interface CommentReply {\n id: string\n author: string\n /** The author's collaboration color when they wrote it, for their avatar. */\n authorColor?: Color\n /** Markdown: bold, italic, strikethrough, links and lists. */\n text: string\n createdAt: string\n deleted?: boolean\n}\n\n/** A canvas comment thread, kept in the document's root plugin data. */\nexport interface CommentThread {\n id: string\n pageId: string\n /** Page name when the pin was placed, for readers of the raw data. */\n pageName?: string\n /** Top-level layer under the pin; the pin follows it when it moves. */\n nodeId?: string | null\n nodeName?: string | null\n /** Offset from the layer's top-left corner, in canvas units. */\n offsetX?: number\n offsetY?: number\n /** Canvas position when the pin was last saved; used when the layer is gone. */\n x: number\n y: number\n author: string\n /** The author's collaboration color when they wrote it, for their avatar. */\n authorColor?: Color\n /** Markdown: bold, italic, strikethrough, links and lists. */\n text: string\n createdAt: string\n /** Bumped on every change. */\n updatedAt: string\n resolved: boolean\n resolvedAt?: string | null\n /** Deleted threads stay as tombstones so a stale copy cannot bring them back. */\n deleted?: boolean\n replies: CommentReply[]\n}\n\n/** How a prototype reaction starts, as `.fig` keeps `PrototypeEvent.interactionType`. */\nexport type PrototypeTriggerType = 'ON_CLICK' | 'AFTER_TIMEOUT'\n\n/** What a reaction does, as `.fig` keeps `ConnectionType` on `PrototypeAction`. */\nexport type PrototypeActionType = 'NODE' | 'BACK' | 'CLOSE'\n\n/** Whether an action moves to a frame or opens it over the screen, as `NavigationType`. */\nexport type PrototypeNavigationType = 'NAVIGATE' | 'OVERLAY'\n\n/** How a reaction animates between frames, as `TransitionType` keeps them. */\nexport type PrototypeTransitionType = 'INSTANT' | 'DISSOLVE'\n\n/** Where an overlay sits over the screen, as `OverlayPositionType`. */\nexport type PrototypeOverlayPositionType =\n | 'CENTER'\n | 'TOP_LEFT'\n | 'TOP_CENTER'\n | 'TOP_RIGHT'\n | 'BOTTOM_LEFT'\n | 'BOTTOM_CENTER'\n | 'BOTTOM_RIGHT'\n\n/** How a reaction animates, and how long it takes in seconds. */\nexport interface PrototypeTransition {\n type: PrototypeTransitionType\n duration: number\n}\n\n/** A reaction's move to another frame, or the overlay it opens. */\nexport interface PrototypeNodeAction {\n type: 'NODE'\n /** The frame the action shows; `null` keeps the connection when its target is gone. */\n nodeId: string | null\n navigation: PrototypeNavigationType\n transition: PrototypeTransition\n /** Where an OVERLAY sits over the screen; NAVIGATE keeps CENTER. */\n overlayPosition: PrototypeOverlayPositionType\n}\n\n/** Goes back to the frame the play came from. */\nexport interface PrototypeBackAction {\n type: 'BACK'\n}\n\n/** Closes the overlay the play is showing. */\nexport interface PrototypeCloseAction {\n type: 'CLOSE'\n}\n\nexport type PrototypeAction = PrototypeNodeAction | PrototypeBackAction | PrototypeCloseAction\n\n/** What starts a reaction, and after how long an AFTER_TIMEOUT does. */\nexport interface PrototypeTrigger {\n type: PrototypeTriggerType\n /** AFTER_TIMEOUT only: the seconds before the reaction runs. */\n delay: number\n}\n\n/**\n * One prototype connection on a layer: what starts it and what it does, as `.fig` keeps a\n * `PrototypeInteraction` on the layer's `prototypeInteractions`.\n */\nexport interface PrototypeReaction {\n id: string\n trigger: PrototypeTrigger\n actions: PrototypeAction[]\n}\n\nexport interface SceneNode {\n id: string\n type: NodeType\n name: string\n parentId: string | null\n childIds: string[]\n\n x: number\n y: number\n width: number\n height: number\n rotation: number\n source: SourceMetadata\n /** Materialized layout hint imported or generated outside the live Yoga layout pass. */\n derivedLayout: Partial<Rect> | null\n\n fills: Fill[]\n strokes: Stroke[]\n effects: Effect[]\n layoutGrids: LayoutGrid[]\n guides: CanvasGuide[]\n fillStyleId: string | null\n strokeStyleId: string | null\n textStyleId: string | null\n effectStyleId: string | null\n gridStyleId: string | null\n sharedStyleType: SharedStyleType | null\n opacity: number\n\n cornerRadius: number\n topLeftRadius: number\n topRightRadius: number\n bottomRightRadius: number\n bottomLeftRadius: number\n independentCorners: boolean\n cornerSmoothing: number\n\n visible: boolean\n locked: boolean\n clipsContent: boolean\n\n blendMode: BlendMode\n\n text: string\n fontSize: number\n fontFamily: string\n fontWeight: number\n italic: boolean\n /**\n * The face by the name its font gives it (\"Semi Bold\", \"Book\", \"Condensed Bold\"), which Figma\n * finds a font's face by; `null` is the face the weight and slant pick in the family.\n */\n fontStyle: string | null\n textAlignHorizontal: 'LEFT' | 'CENTER' | 'RIGHT' | 'JUSTIFIED'\n textDirection: TextDirection\n textLanguage: string | null\n textAlignVertical: TextAlignVertical\n textAutoResize: TextAutoResize\n textCase: TextCase\n textDecoration: TextDecoration\n textDecorationStyle: TextDecorationStyle\n textDecorationThickness: number | null\n textDecorationFills: Fill[]\n textDecorationSkipInk: boolean\n textUnderlineOffset: number | null\n leadingTrim: LeadingTrim\n /** `null` is automatic, from the font. */\n lineHeight: TextLength | null\n letterSpacing: TextLength\n maxLines: number | null\n /**\n * One entry per paragraph of `text`, in order. Missing entries are plain paragraphs, so text\n * without lists keeps this empty.\n */\n textParagraphs: TextParagraphStyle[]\n /** Space after a list item followed by another; a paragraph's own value comes first. */\n listSpacing: number\n /** Space after a paragraph other than between two list items. */\n paragraphSpacing: number\n /** Indent of the first line of each plain paragraph. */\n paragraphIndent: number\n /** Whether list markers hang outside the text box instead of indenting the items. */\n hangingList: boolean\n\n styleRuns: StyleRun[]\n fontVariations: FontVariation[]\n /**\n * Whether a variable font's optical size follows the font size, as Figma's \"Set optical size\n * automatically\" does by default; when it does not, the `opsz` in `fontVariations` applies.\n */\n opticalSizeFromFontSize: boolean\n fontFeatures: FontFeature[]\n\n horizontalConstraint: ConstraintType\n verticalConstraint: ConstraintType\n\n layoutMode: LayoutMode\n layoutDirection: LayoutDirection\n layoutWrap: LayoutWrap\n primaryAxisAlign: LayoutAlign\n counterAxisAlign: LayoutCounterAlign\n primaryAxisSizing: AxisSizingMode\n counterAxisSizing: AxisSizingMode\n itemSpacing: number\n counterAxisSpacing: number\n paddingTop: number\n paddingRight: number\n paddingBottom: number\n paddingLeft: number\n\n layoutPositioning: 'AUTO' | 'ABSOLUTE'\n layoutGrow: number\n layoutAlignSelf: LayoutAlignSelf\n\n vectorNetwork: VectorNetwork | null\n handleMirroring: HandleMirroring\n booleanOperation: BooleanOperation | undefined\n fillGeometry: GeometryPath[]\n strokeGeometry: GeometryPath[]\n\n arcData: ArcData | null\n\n strokeCap: StrokeCap\n strokeJoin: StrokeJoin\n dashPattern: number[]\n\n borderTopWeight: number\n borderRightWeight: number\n borderBottomWeight: number\n borderLeftWeight: number\n independentStrokeWeights: boolean\n\n /**\n * The weight and alignment a node keeps for its strokes, as Figma keeps them on the node: they\n * last while it has no strokes, and a stroke added to it takes them. Each stroke still carries\n * its own `weight` and `align`, which win while the node has strokes.\n */\n strokeWeight: number\n strokeAlign: Stroke['align']\n\n strokeMiterLimit: number\n\n minWidth: number | null\n maxWidth: number | null\n minHeight: number | null\n maxHeight: number | null\n /**\n * The size whose proportions the layer keeps, as Figma stores it: the width and height it had\n * when the ratio was locked, not a reduced ratio. Null leaves the proportions free.\n */\n targetAspectRatio: Vector | null\n\n /** A connector's ends and the line between them; null on other layers. */\n connectorStart: ConnectorEndpoint | null\n connectorEnd: ConnectorEndpoint | null\n connectorLineType: ConnectorLineType\n connectorStartCap: StrokeCap\n connectorEndCap: StrokeCap\n /**\n * An elbow connector's segments between its first and last, in order, once one was dragged;\n * empty while it routes itself. Kept, unused, while the line is straight or curved.\n */\n connectorControlPoints: ConnectorControlPoint[]\n /**\n * A curved connector's two cubic control points, in the connector's own axes, once its curve\n * was dragged; null while it curves by itself. Kept, unused, while the line is not curved.\n */\n connectorCurveHandles: [Vector, Vector] | null\n /** Where a connector's label was dragged to; null while it sits midway along the line. */\n connectorLabelPosition: ConnectorLabelPosition | null\n\n isMask: boolean\n maskType: MaskType\n maskIsOutline: boolean\n\n gridTemplateColumns: GridTrack[]\n gridTemplateRows: GridTrack[]\n gridColumnGap: number\n gridRowGap: number\n gridPosition: GridPosition | null\n\n counterAxisAlignContent: 'AUTO' | 'SPACE_BETWEEN'\n itemReverseZIndex: boolean\n strokesIncludedInLayout: boolean\n\n expanded: boolean\n textTruncation: 'DISABLED' | 'ENDING'\n autoRename: boolean\n\n pointCount: number\n starInnerRadius: number\n /** The FigJam kind a SHAPE_WITH_TEXT draws; its label is the node's own text. */\n shapeWithTextType: ShapeWithTextType\n /** The height a shape with text was given; it grows past it to fit its label. 0 is unset. */\n shapeUserHeight: number\n /**\n * Whether a shape with text keeps its height and cuts its label off with \"…\" instead of growing,\n * as FigJam does once the shape's height was set.\n */\n shapeTruncates: boolean\n\n componentId: string | null\n instanceOverrides: InstanceOverrideState\n componentPropertyDefinitions: ComponentPropertyDefinition[]\n componentPropertyReferences: ComponentPropertyReference[]\n componentPropertyAssignments: Record<string, string>\n componentPropertyValues: Record<string, string>\n componentKey: string | null\n sourceLibraryKey: string | null\n publishId: string | null\n overrideKey: string | null\n sharedSymbolVersion: string | null\n publishedVersion: string | null\n librarySource: LibraryAssetSource | null\n isPublishable: boolean\n isSymbolPublishable: boolean\n /**\n * On an instance inside a component: its properties show on instances of that component,\n * as Figma's `isExposedInstance`.\n */\n isExposedInstance: boolean\n symbolDescription: string\n symbolLinks: SymbolLink[]\n variantPropSpecs: VariantPropSpec[]\n\n boundVariables: Record<string, string>\n /** Multipliers from bound numeric values to this occurrence's scene units. */\n variableBindingScales: Partial<Record<string, number>>\n /** Numeric units for new declarations owned by this node's occurrence scope. */\n variableAssignmentScales: Partial<Record<string, number>>\n /** Explicit coordinate scale relative to the containing component definition. */\n componentScale: number\n variableModes: VariableModeMap\n exportSettings: ExportSetting[]\n /**\n * The id of the status a team gave the layer, a state of the document's workflow such as Ready\n * for dev. It stays while the layer sits where it cannot show one; `effectiveStatus` tells\n * whether it shows.\n */\n status: string | null\n\n pluginData: PluginDataEntry[]\n pluginRelaunchData: PluginRelaunchDataEntry[]\n\n /** The prototype reactions this layer starts, as Figma's prototype keeps them. */\n prototypeReactions: PrototypeReaction[]\n\n internalOnly: boolean\n\n flipX: boolean\n flipY: boolean\n\n textPicture: Uint8Array | null\n derivedTextGlyphs: DerivedTextGlyph[] | null\n /**\n * How far a text's lines reach down from its top: measured at its width when its text or width\n * changes, or read from the lines a file saved, and never saved itself. A fixed-size box does not\n * clip them, as in Figma, so its visual bounds reach this far. Null when not known.\n */\n derivedTextHeight: number | null\n /** Format-neutral layout path for text-on-path nodes. */\n textPathData: TextPathData | null\n /** Node-local box that maps textPathData into the node coordinate space. */\n textPathBox: Rect | null\n}\n\nexport type ComponentPropertyType = 'VARIANT' | 'TEXT' | 'BOOLEAN' | 'INSTANCE_SWAP' | 'SLOT'\n\n/** `SLOT_CONTENT` marks a frame whose children are the slot's content. */\nexport type ComponentPropertyReferenceField = 'VISIBLE' | 'TEXT' | 'INSTANCE_SWAP' | 'SLOT_CONTENT'\n\nexport interface ComponentPropertyReference {\n propertyId: string\n field: ComponentPropertyReferenceField\n}\n\n/** Guidance for a slot property; Figma reports a breach but still accepts the content. */\nexport interface SlotSettings {\n minChildren?: number\n maxChildren?: number\n allowPreferredValuesOnly: boolean\n displayEmptyByDefault: boolean\n /** Content added to the slot fills its counter axis. */\n stretchChildOnInsert: boolean\n}\n\n/**\n * For a `SLOT` property, an instance assignment (whatever its value) means the instance owns\n * that slot's content: the slot frame's children in the instance, which component sync keeps.\n */\nexport interface ComponentPropertyDefinition {\n id: string\n name: string\n type: ComponentPropertyType\n defaultValue: string\n variantOptions?: string[]\n preferredValues?: string[]\n description?: string\n slotSettings?: SlotSettings\n}\n\nexport type VariableType = 'COLOR' | 'FLOAT' | 'STRING' | 'BOOLEAN'\nexport interface VariableAlias {\n aliasId: string\n}\n\n/** Figma's two-argument color expression; opacity is a percentage, not an alpha multiplier. */\nexport interface VariableColorExpression {\n expression: 'COMPOSE_COLOR'\n color: Color | VariableAlias\n opacity: number | VariableAlias\n}\n\nexport type VariableLiteral = Color | number | string | boolean\n/** The arithmetic, comparison, logic and conversions a formula combines values with. */\nexport const VARIABLE_FORMULA_OPERATORS = [\n 'add',\n 'subtract',\n 'multiply',\n 'divide',\n 'negate',\n 'equal',\n 'notEqual',\n 'less',\n 'lessOrEqual',\n 'greater',\n 'greaterOrEqual',\n 'and',\n 'or',\n 'not',\n 'text',\n 'truthy',\n 'if'\n] as const\nexport type VariableFormulaOperator = (typeof VARIABLE_FORMULA_OPERATORS)[number]\nexport interface VariableFormulaOperation {\n operator: VariableFormulaOperator\n operands: VariableFormulaNode[]\n}\nexport type VariableFormulaNode = VariableLiteral | VariableAlias | VariableFormulaOperation\nexport interface VariableFormula {\n expression: 'FORMULA'\n type: VariableType\n value: VariableFormulaNode\n}\n/**\n * An imported expression Pairdraw cannot evaluate, kept as the file wrote it so saving writes it\n * back. `references` holds one entry per alias in `value`, in the order the format walks them, and\n * `null` where the alias names a variable this document does not have. `modes` holds the mode id of\n * each mode key in `value`, in the same walk order.\n */\nexport interface VariableUnsupportedExpression {\n expression: 'UNSUPPORTED'\n /** The function name the file gives, such as `VAR_MODE_LOOKUP`. */\n function: string\n value: Record<string, unknown>\n references: (string | null)[]\n modes: string[]\n}\nexport type VariableValue =\n | VariableLiteral\n | VariableAlias\n | VariableColorExpression\n | VariableFormula\n | VariableUnsupportedExpression\nexport type VariableModeMap = Record<string, string>\n\n/** Property pickers a variable is offered in, as Figma names them. */\nexport const VARIABLE_SCOPES = [\n 'ALL_SCOPES',\n 'TEXT_CONTENT',\n 'CORNER_RADIUS',\n 'WIDTH_HEIGHT',\n 'GAP',\n 'ALL_FILLS',\n 'FRAME_FILL',\n 'SHAPE_FILL',\n 'TEXT_FILL',\n 'STROKE',\n 'STROKE_FLOAT',\n 'EFFECT_FLOAT',\n 'EFFECT_COLOR',\n 'OPACITY',\n 'FONT_STYLE',\n 'FONT_FAMILY',\n 'FONT_SIZE',\n 'LINE_HEIGHT',\n 'LETTER_SPACING',\n 'PARAGRAPH_SPACING',\n 'PARAGRAPH_INDENT',\n 'FONT_VARIATIONS',\n 'TRANSFORM'\n] as const\nexport type VariableScope = (typeof VARIABLE_SCOPES)[number]\n\nexport const CODE_SYNTAX_PLATFORMS = ['WEB', 'ANDROID', 'iOS'] as const\nexport type CodeSyntaxPlatform = (typeof CODE_SYNTAX_PLATFORMS)[number]\n\n/**\n * The CSS unit a numeric token is written in. Lengths (`px`, `rem`) stay in canvas pixels in\n * the document and convert only when written as CSS; the other units store the number as written.\n */\nexport const TOKEN_UNITS = ['none', 'px', 'rem', '%', 'ms', 's', 'deg'] as const\nexport type TokenUnit = (typeof TOKEN_UNITS)[number]\n\n/**\n * CSS written in place of a number mode's value, such as `clamp(1rem, 4vw, 1.5rem)`. While the\n * mode holds a plain number, `resolved` records it, so a number later edited elsewhere, Figma\n * included, shows the CSS no longer describes it.\n */\nexport interface TokenExpression {\n css: string\n resolved?: number\n}\n\nexport interface Variable {\n id: string\n name: string\n type: VariableType\n collectionId: string\n valuesByMode: Record<string, VariableValue>\n description: string\n hiddenFromPublishing: boolean\n /** Absent means every scope. */\n scopes?: VariableScope[]\n /**\n * Per-platform code snippets, as Figma's Dev Mode shows them. A `WEB` snippet of `--x` or\n * `var(--x)` names the token's CSS custom property; otherwise the name is derived.\n */\n codeSyntax?: Partial<Record<CodeSyntaxPlatform, string>>\n /** FLOAT only. Absent means inferred when written as CSS. */\n unit?: TokenUnit\n /** Raw CSS by mode id, for values a number cannot express (`clamp()`, `calc()`). */\n expressions?: Record<string, TokenExpression>\n pluginData?: PluginDataEntry[]\n /** Published library key (from NodeChange.key). Used for assetRef resolution in colorVar. */\n key?: string\n /** Published library version (from NodeChange.version). Used for assetRef resolution in colorVar. */\n version?: string\n}\n\n/** Scalar numeric node fields accepted by numeric property controls. */\nexport type NumericNodeProperty = {\n [K in keyof SceneNode]-?: SceneNode[K] extends number ? K : never\n}[keyof SceneNode]\n\nexport interface VariableCollectionMode {\n modeId: string\n name: string\n /**\n * Where the mode applies in CSS: a selector (`[data-theme=\"dark\"]`, `.compact`) or an\n * at-rule prelude (`@media (max-width: 640px)`). Absent means the default for its axis.\n */\n condition?: string\n /** Where Figma lists the mode, as the file saved it; Figma orders a collection's modes by it. */\n sortPosition?: string\n}\n\nexport interface VariableCollection {\n id: string\n name: string\n /** The default mode comes first, as in Figma. */\n modes: VariableCollectionMode[]\n defaultModeId: string\n variableIds: string[]\n /**\n * The attribute that switches a mode with no condition of its own, `data-theme` for\n * `[data-theme=\"dark\"]`. Absent means one named after the collection.\n */\n modeAttribute?: string\n pluginData?: PluginDataEntry[]\n /**\n * Published library key, for a collection the file copies from a library. Such a collection\n * belongs to the library: Figma lists it with the library's, not the file's own.\n */\n key?: string\n /** Published library version, which references by key carry with it. */\n version?: string\n}\n\n/** Whether a collection is a library's copy, which takes no variables or modes of the file's. */\nexport function isLibraryCollection(collection: Pick<VariableCollection, 'key'>): boolean {\n return !!collection.key\n}\n\n/** An HTML attribute name a stylesheet can select on unescaped: `data-theme`, `theme`. */\nexport const MODE_ATTRIBUTE_PATTERN = /^[A-Za-z_][\\w-]*$/\n\nexport function isModeAttributeName(name: string): boolean {\n return name.length <= 100 && MODE_ATTRIBUTE_PATTERN.test(name)\n}\n"],"mappings":";;AAyYA,MAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AA0oBA,MAAa,6BAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAmCA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAGA,MAAa,wBAAwB;CAAC;CAAO;CAAW;AAAK;;;;;AAO7D,MAAa,cAAc;CAAC;CAAQ;CAAM;CAAO;CAAK;CAAM;CAAK;AAAK;;AA+EtE,SAAgB,oBAAoB,YAAsD;CACxF,OAAO,CAAC,CAAC,WAAW;AACtB;;AAGA,MAAa,yBAAyB;AAEtC,SAAgB,oBAAoB,MAAuB;CACzD,OAAO,KAAK,UAAU,OAAO,uBAAuB,KAAK,IAAI;AAC/D"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/* eslint-disable max-lines -- scene node contracts are kept together as the public graph type surface */\n\nimport type { ExportFormatId } from './export-format'\nimport type { CanvasGuide } from './guides'\nimport type { InstanceOverrideState } from './instances/overrides'\nimport type { Color, Matrix, Rect, Vector } from './primitives'\nimport type { ShaderUniformValue } from './shaders/schema'\nimport type { ShapeWithTextType } from './shape-with-text/kinds'\n\nexport interface SceneGraphEvents {\n 'node:created': (node: SceneNode) => void\n 'node:updated': (id: string, changes: Partial<SceneNode>) => void\n 'node:previewUpdated': (id: string, changes: Partial<SceneNode>) => void\n 'node:deleted': (id: string, parentId: string | null) => void\n 'node:reparented': (nodeId: string, oldParentId: string | null, newParentId: string) => void\n 'node:reordered': (\n nodeId: string,\n parentId: string,\n index: number,\n previousParentId: string | null\n ) => void\n}\n\nexport type SceneGraphEventHandlers = Partial<{\n created: (node: SceneNode) => void\n updated: (id: string, changes: Partial<SceneNode>) => void\n previewUpdated: (id: string, changes: Partial<SceneNode>) => void\n deleted: (id: string, parentId: string | null) => void\n reparented: (nodeId: string, oldParentId: string | null, newParentId: string) => void\n reordered: (\n nodeId: string,\n parentId: string,\n index: number,\n previousParentId: string | null\n ) => void\n}>\n\n/** Hears about nodes as an edit adds and changes them, synchronously and before each change. */\nexport interface NodeChangeObserver {\n /** A node is about to change and is still as it was. */\n before: (node: SceneNode) => void\n /** A node was just added. */\n created: (node: SceneNode) => void\n /** What changes from now until `resume` is someone else's; `waitOutsideEdit` calls this. */\n pause?: () => void\n /** The wait ended, and what changed meanwhile belongs outside the edit. */\n resume?: () => void\n}\n\nexport type DocumentColorSpace = 'srgb' | 'display-p3'\n\n/** What a document is for, as Figma keeps design files and FigJam boards apart. */\nexport type DocumentKind = 'design' | 'board'\n\nexport interface FigmaSourcePayload {\n rawSize: Vector | null\n rawTransform: Matrix | null\n rawNodeFields: Record<string, unknown>\n layout: FigmaLayoutMetadata | null\n symbolOverrides: unknown[]\n componentPropAssignments: unknown[]\n derivedSymbolData: unknown[]\n derivedSymbolDataLayoutVersion: number | null\n uniformScaleFactor: number | null\n}\n\n/**\n * An edge as its draw.io file wrote it: the style pairs and geometry the author set. A connector\n * read from a file keeps them so saving an unedited edge writes back what draw.io had, instead of\n * re-routing it.\n */\nexport interface DrawIOEdgeSource {\n /** The style's names and its pairs, in the order the file wrote them. */\n styleNames: string[]\n styleValues: Partial<Record<string, string>>\n /** The label's place along the edge, as the geometry's `x`. */\n labelX: number\n /** Bend points and free ends, in the edge's parent's axes. */\n points: Vector[]\n sourcePoint: Vector | null\n targetPoint: Vector | null\n}\n\nexport interface SourceMetadata {\n format: 'fig' | null\n id: string | null\n orderKey: string | null\n editedFields: string[]\n fig: FigmaSourcePayload\n /** The edge cell a connector was read from, kept until the connector is edited. */\n drawio?: DrawIOEdgeSource | null\n}\n\nexport type HandleMirroring = 'NONE' | 'ANGLE' | 'ANGLE_AND_LENGTH'\nexport type WindingRule = 'NONZERO' | 'EVENODD'\n\nexport interface VectorVertex {\n x: number\n y: number\n strokeCap?: string\n strokeJoin?: string\n cornerRadius?: number\n handleMirroring?: HandleMirroring\n}\n\nexport interface VectorSegment {\n start: number\n end: number\n tangentStart: Vector\n tangentEnd: Vector\n}\n\nexport interface VectorRegion {\n windingRule: WindingRule\n loops: number[][]\n}\n\nexport interface VectorNetwork {\n vertices: VectorVertex[]\n segments: VectorSegment[]\n regions: VectorRegion[]\n}\n\nexport interface GeometryPath {\n windingRule: WindingRule\n commandsBlob: Uint8Array\n /** Resolved paints for geometry using a format-specific style override. */\n fills?: Fill[]\n /** Shared fill style attached to this geometry region, when available. */\n fillStyleId?: string\n}\n\nexport type NodeType =\n | 'CANVAS'\n | 'FRAME'\n | 'RECTANGLE'\n | 'ROUNDED_RECTANGLE'\n | 'ELLIPSE'\n | 'TEXT'\n | 'LINE'\n | 'STAR'\n | 'POLYGON'\n | 'VECTOR'\n | 'BOOLEAN_OPERATION'\n | 'GROUP'\n | 'SECTION'\n | 'COMPONENT'\n | 'COMPONENT_SET'\n | 'INSTANCE'\n | 'CONNECTOR'\n | 'SHAPE_WITH_TEXT'\n | 'STICKY'\n | 'SCRIPT'\n\nexport type FillType =\n | 'SOLID'\n | 'GRADIENT_LINEAR'\n | 'GRADIENT_RADIAL'\n | 'GRADIENT_ANGULAR'\n | 'GRADIENT_DIAMOND'\n | 'MESH'\n | 'IMAGE'\n | 'VIDEO'\n | 'PATTERN'\n | 'NOISE'\n | 'CUSTOM'\nexport type BlendMode =\n | 'NORMAL'\n | 'DARKEN'\n | 'MULTIPLY'\n | 'LINEAR_BURN'\n | 'COLOR_BURN'\n | 'LIGHTEN'\n | 'SCREEN'\n | 'LINEAR_DODGE'\n | 'COLOR_DODGE'\n | 'OVERLAY'\n | 'SOFT_LIGHT'\n | 'HARD_LIGHT'\n | 'DIFFERENCE'\n | 'EXCLUSION'\n | 'HUE'\n | 'SATURATION'\n | 'COLOR'\n | 'LUMINOSITY'\n | 'PASS_THROUGH'\nexport type ImageScaleMode = 'FILL' | 'FIT' | 'CROP' | 'TILE'\nexport type NoiseType = 'MULTITONE' | 'MONOTONE' | 'DUOTONE'\nexport type PatternTileType = 'RECTANGULAR' | 'HORIZONTAL_HEXAGONAL' | 'VERTICAL_HEXAGONAL'\nexport type PatternAlignment = 'START' | 'CENTER' | 'END'\n\nexport interface GradientStop {\n color: Color\n position: number\n}\n\n/**\n * One control point of a `MESH` fill: its color, and where it sits in the layer's unit square.\n * A mesh holds `(rows + 1) * (columns + 1)` points in row-major order: corners and edge points\n * first, so a 1x1 mesh is the four corners. Positions outside 0..1 are allowed; the renderer\n * clamps them to the layer.\n */\nexport interface MeshGradientPoint {\n position: Vector\n color: Color\n}\n\nexport type GradientTransform = Matrix\n\n/** Figma's adjustments of an image paint, each from -1 to 1; 0 leaves the image as it is. */\nexport interface ImageFilters {\n exposure?: number\n contrast?: number\n saturation?: number\n temperature?: number\n tint?: number\n highlights?: number\n shadows?: number\n}\n\nexport interface Fill {\n type: FillType\n color: Color\n opacity: number\n visible: boolean\n blendMode?: BlendMode\n gradientStops?: GradientStop[]\n gradientTransform?: GradientTransform\n /** A `MESH` fill's grid: columns and rows of cells, with one more point than cells each way. */\n meshColumns?: number\n meshRows?: number\n meshPoints?: MeshGradientPoint[]\n imageHash?: string\n imageScaleMode?: ImageScaleMode\n /** A crop's image-space window; Fill, Fit and Tile ignore it. */\n imageTransform?: GradientTransform\n /** Clockwise turn of a Fill, Fit or Tile image, in multiples of 90°; a crop holds its own. */\n imageRotation?: number\n /** An image's adjustments, in Figma's plugin API units. */\n filters?: ImageFilters\n sourceNodeId?: string\n scale?: number\n spacing?: number\n patternSpacing?: Vector\n patternTileType?: PatternTileType\n verticalAlignment?: PatternAlignment\n horizontalAlignment?: PatternAlignment\n noiseType?: NoiseType\n density?: number\n noiseSize?: Vector\n customEffectId?: string\n}\n\nexport type StrokeCap =\n | 'NONE'\n | 'ROUND'\n | 'SQUARE'\n | 'ARROW_LINES'\n | 'ARROW_EQUILATERAL'\n | 'TRIANGLE_FILLED'\n | 'DIAMOND_FILLED'\n | 'CIRCLE_FILLED'\nexport type StrokeJoin = 'MITER' | 'BEVEL' | 'ROUND'\nexport type SharedStyleType = 'FILL' | 'TEXT' | 'EFFECT' | 'GRID'\nexport type SharedStyleKind = 'fill' | 'stroke' | 'text' | 'effect' | 'grid'\nexport type MaskType = 'ALPHA' | 'VECTOR' | 'LUMINANCE'\nexport type BooleanOperation = 'UNION' | 'SUBTRACT' | 'INTERSECT' | 'EXCLUDE'\n\nexport interface LayoutGrid {\n visible?: boolean\n color?: Color\n /** `STRIPES` is the archive's name for columns or rows, along `axis`. */\n pattern?: 'COLUMNS' | 'ROWS' | 'GRID' | 'STRIPES'\n axis?: 'X' | 'Y'\n type?: 'MIN' | 'CENTER' | 'MAX' | 'STRETCH'\n alignment?: 'MIN' | 'CENTER' | 'MAX' | 'STRETCH'\n numSections?: number\n /** Figma's plugin API reports an Auto count as `null` and accepts `Infinity` for it. */\n count?: number | null\n offset?: number\n sectionSize?: number\n gutterSize?: number\n}\n\nexport interface SharedStyle {\n id: string\n nodeId: string\n name: string\n type: SharedStyleType\n}\n\n/** A stroke is a paint with the geometry that decides where it is drawn. */\nexport interface Stroke extends Fill {\n weight: number\n align: 'INSIDE' | 'CENTER' | 'OUTSIDE'\n cap?: StrokeCap\n join?: StrokeJoin\n dashPattern?: number[]\n}\n\nexport type Effect = ShadowEffect | ShaderEffect | NoiseEffect | TextureEffect\n\nexport interface ShadowEffect {\n type: 'DROP_SHADOW' | 'INNER_SHADOW' | 'LAYER_BLUR' | 'BACKGROUND_BLUR' | 'FOREGROUND_BLUR'\n color: Color\n offset: Vector\n radius: number\n spread: number\n visible: boolean\n blendMode?: BlendMode\n showShadowBehindNode?: boolean\n}\n\n/**\n * A Noise effect's grain, in Figma's plugin terms: `MONOTONE` grains in the effect's colour,\n * `DUOTONE` in it and `secondaryColor`, `MULTITONE` in many colours at `opacity`. `noiseSize` is a\n * grain's size in px, which Figma keeps within 0 to 100, and `density` how much of the layer the\n * grains cover, 0 to 1. `seed` picks the pattern; Figma's plugin API neither shows nor sets it.\n */\nexport interface NoiseEffectParams {\n noiseType: NoiseType\n noiseSize: Vector\n density: number\n secondaryColor?: Color\n opacity?: number\n seed?: number\n}\n\n/**\n * A Texture effect's grain, which roughens the layer's edges: `noiseSize` is the grain's size in\n * px, within 0 to 100 as Figma keeps it, and `clipToShape` keeps the roughened layer inside its\n * own outline. The effect's `radius` is how far the grain moves the edges. `.fig` files name the\n * effect `GRAIN`.\n */\nexport interface TextureEffectParams {\n noiseSize: Vector\n clipToShape: boolean\n seed?: number\n}\n\nexport interface NoiseEffect {\n type: 'NOISE'\n color: Color\n visible: boolean\n blendMode?: BlendMode\n noise: NoiseEffectParams\n}\n\nexport interface TextureEffect {\n type: 'TEXTURE'\n color: Color\n radius: number\n visible: boolean\n blendMode?: BlendMode\n texture: TextureEffectParams\n}\n\n/** A layer post-processed by shader code the user wrote; the layer is the `pencil:object` sample. */\nexport interface ShaderEffect {\n type: 'SHADER'\n source: string\n uniforms?: Record<string, ShaderUniformValue>\n uniformBindings?: Record<string, string>\n visible: boolean\n blendMode?: BlendMode\n}\n\nexport type ConstraintType = 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'SCALE'\nexport type TextAutoResize = 'NONE' | 'HEIGHT' | 'WIDTH_AND_HEIGHT' | 'TRUNCATE'\n\n/** Where a connector end attaches to a layer: a side, the side Figma picks, or a fixed point. */\nexport type ConnectorMagnet =\n | 'NONE'\n | 'AUTO'\n | 'AUTO_HORIZONTAL'\n | 'TOP'\n | 'RIGHT'\n | 'BOTTOM'\n | 'LEFT'\n | 'CENTER'\n | 'EDGE'\n | 'ABSOLUTE'\n\n/**\n * One end of a connector. Bound to a layer, it follows the layer by `magnet`, or by `position`\n * in the layer's own axes when the magnet is `NONE`. Free, `nodeId` is null and `position` is in\n * the connector's parent's axes.\n */\nexport interface ConnectorEndpoint {\n nodeId: string | null\n magnet: ConnectorMagnet\n position: Vector\n}\n\nexport type ConnectorLineType = 'ELBOWED' | 'STRAIGHT' | 'CURVED'\n\n/**\n * A segment of an elbow connector that was dragged into place: the line it runs along, through\n * `position`, in the connector's own axes. `position` lies midway along the segment as last drawn.\n */\nexport interface ConnectorControlPoint {\n position: Vector\n direction: 'HORIZONTAL' | 'VERTICAL'\n}\n\n/**\n * Where a connector's label was dragged along its line: `offset` of the way from the middle of\n * the line towards one end, by length, on the line or to one side of it. `ABOVE` is the side to\n * the left of the line's direction.\n */\nexport interface ConnectorLabelPosition {\n section: 'MIDDLE_TO_START' | 'MIDDLE_TO_END'\n offset: number\n offAxis: 'NONE' | 'ABOVE' | 'BELOW'\n}\nexport type TextAlignVertical = 'TOP' | 'CENTER' | 'BOTTOM'\nexport type TextCase = 'ORIGINAL' | 'UPPER' | 'LOWER' | 'TITLE'\nexport type TextDecoration = 'NONE' | 'UNDERLINE' | 'STRIKETHROUGH'\nexport type TextDecorationStyle = 'SOLID' | 'DOTTED' | 'WAVY'\nexport type LeadingTrim = 'NONE' | 'CAP_HEIGHT'\nexport type TextDirection = 'AUTO' | 'LTR' | 'RTL'\nexport type LayoutDirection = 'AUTO' | 'LTR' | 'RTL'\n/** Whether a paragraph is an item of a numbered list, a bulleted list, or no list. */\nexport type TextListType = 'NONE' | 'ORDERED' | 'UNORDERED'\n\n/** How one paragraph of a text node (a line ending at a newline) sits in a list. */\n/** Spacing a text sets for all its paragraphs and a paragraph can set for itself. */\nexport type TextParagraphSpacingField = 'listSpacing' | 'paragraphSpacing' | 'paragraphIndent'\n\nexport interface TextParagraphStyle {\n listType: TextListType\n /** Nesting level: 1–5 for list items; kept but not drawn for plain paragraphs. */\n indentation: number\n /** This paragraph's own spacing, in place of the text's; absent ones follow the text. */\n listSpacing?: number\n paragraphSpacing?: number\n paragraphIndent?: number\n}\n\nexport interface FontVariation {\n axis: string\n value: number\n}\n\nexport interface FontFeature {\n tag: string\n enabled: boolean\n}\n\n/** Where a stretch of text links to, as Figma's `HyperlinkTarget`: a URL, or a node by its ID. */\nexport interface HyperlinkTarget {\n type: 'URL' | 'NODE'\n value: string\n}\n\n/** The text fields a range of characters can bind to a variable, as Figma lists them. */\nexport const TEXT_BINDABLE_FIELDS = [\n 'fontFamily',\n 'fontSize',\n 'fontStyle',\n 'fontWeight',\n 'letterSpacing',\n 'lineHeight',\n 'paragraphSpacing',\n 'paragraphIndent'\n] as const\n\nexport type TextBindableField = (typeof TEXT_BINDABLE_FIELDS)[number]\n\n/** Variable IDs bound to text fields, by field. */\nexport type TextBoundVariables = Partial<Record<TextBindableField, string>>\n\n/**\n * A line height or letter spacing as Figma keeps it: pixels, or a percent of the font size that\n * follows the size when it changes.\n */\nexport interface TextLength {\n value: number\n unit: 'PIXELS' | 'PERCENT'\n}\n\nexport interface CharacterStyleOverride {\n fontWeight?: number\n italic?: boolean\n /** The characters' face by its font's own name for it; `null` is the face their weight picks. */\n fontStyle?: string | null\n textDecoration?: TextDecoration\n textDecorationStyle?: TextDecorationStyle\n textDecorationThickness?: number | null\n textDecorationFills?: Fill[]\n textDecorationSkipInk?: boolean\n textUnderlineOffset?: number | null\n fontSize?: number\n fontFamily?: string\n letterSpacing?: TextLength\n /** `null` is automatic, from the font. */\n lineHeight?: TextLength | null\n fills?: Fill[]\n fontVariations?: FontVariation[]\n /** Whether the characters' optical size follows their font size, in place of the text's own. */\n opticalSizeFromFontSize?: boolean\n fontFeatures?: FontFeature[]\n textLanguage?: string | null\n textCase?: TextCase\n /** A link over the characters; `null`, like leaving it out, links nowhere. */\n hyperlink?: HyperlinkTarget | null\n /** The text style the characters use in place of the text's own; `null` uses none. */\n textStyleId?: string | null\n /** The fill style the characters use in place of the text's own; `null` uses none. */\n fillStyleId?: string | null\n /** The characters' text field bindings, in place of the text's own. */\n boundVariables?: TextBoundVariables\n /**\n * The scale each number the characters bind resolves with, as a rescale left it; a field without\n * one uses the layer's `variableBindingScales`, as runs did before they kept their own.\n */\n variableBindingScales?: Partial<Record<TextBindableField, number>>\n}\n\nexport interface StyleRun {\n start: number\n length: number\n style: CharacterStyleOverride\n}\n\nexport interface ArcData {\n startingAngle: number\n endingAngle: number\n innerRadius: number\n}\n\nexport type LayoutMode = 'NONE' | 'HORIZONTAL' | 'VERTICAL' | 'GRID'\n/** A node's sizing along one axis; fill is stored on the child, see `layoutSizing`. */\nexport type LayoutSizing = 'FIXED' | 'HUG' | 'FILL'\n/** Whether an auto-layout frame keeps its size or hugs its children along one of its axes. */\nexport type AxisSizingMode = 'FIXED' | 'HUG'\n\nexport type GridTrackSizing = 'FIXED' | 'FR' | 'AUTO'\n\nexport interface GridTrack {\n sizing: GridTrackSizing\n value: number\n}\n\nexport interface GridPosition {\n column: number\n row: number\n columnSpan: number\n rowSpan: number\n}\n/**\n * Primary axis alignment of an auto layout's children. `SPACE_AROUND` is Pairdraw's own:\n * Figma has no such mode, so `.fig` files keep it as plugin data over Figma's space between.\n */\nexport type LayoutAlign = 'MIN' | 'CENTER' | 'MAX' | 'SPACE_BETWEEN' | 'SPACE_AROUND'\nexport type LayoutCounterAlign = 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'BASELINE'\nexport type LayoutAlignSelf = 'AUTO' | 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'BASELINE'\nexport type LayoutWrap = 'NO_WRAP' | 'WRAP'\n\nexport interface PluginDataEntry {\n pluginId: string\n key: string\n value: string\n}\n\nexport interface ExportSetting {\n scale: number\n format: ExportFormatId\n /** JPG and WEBP quality from 1 to 100; absent means the encoder's default. */\n quality?: number\n}\n\nexport interface PluginRelaunchDataEntry {\n pluginId: string\n command: string\n message: string\n isDeleted: boolean\n}\n\n/**\n * One derived glyph outline for display (path text / missing-font fidelity).\n * Figma import is one producer; Pairdraw editing and reflow can regenerate it.\n * commandsBlob is in font units; paint multiplies by fontSize (and scaleX/Y).\n */\nexport interface TextPathData {\n network: VectorNetwork\n normalizedSize: Vector\n /** Where on the start segment the text starts, from 0 at its start to 1 at its end. */\n tValue: number\n forward: boolean\n /** The segment the text starts on, which Figma marks in the network blob; 0 when unmarked. */\n startSegment?: number\n}\n\nexport interface DerivedTextGlyph {\n /** UTF-16 source-text cluster start, when supplied by the shaping source. */\n firstCharacter?: number\n commandsBlob: Uint8Array\n x: number\n y: number\n fontSize: number\n /** Figma Glyph.rotation — radians, not degrees. Zero for axis-aligned text. */\n rotation?: number\n /**\n * Horizontal advance in pixels at `fontSize`, before `scaleX`, when the shaping source gave\n * one; where the glyph ends, so decorations stop at the text rather than the layer's edge.\n */\n advance?: number\n /**\n * Accumulated non-uniform resize scale (default 1). Paint order is\n * translate → scale(scaleX,Y) → rotate → scale(fontSize,-fontSize) so\n * anisotropic stretch matches scaleGeometryPaths(strokeGeometry).\n * Do not fold this into fontSize or rotated letters desync from outlines.\n */\n scaleX?: number\n scaleY?: number\n /**\n * The code points of the emoji this glyph stands for, sequence and all. Its outline is only a\n * placeholder square a 1 em wide; the emoji's image is drawn there instead, as Figma does.\n */\n emojiCodePoints?: number[]\n /** The image set Figma draws the emoji from, when the file names one other than Apple's. */\n emojiImageSet?: 'NOTO'\n}\n\nexport interface SymbolLink {\n uri: string\n displayName?: string\n displayText?: string\n}\n\nexport interface VariantPropSpec {\n propDefId: string\n value: string\n}\n\nexport type FigmaLayoutMetadata = Partial<\n Record<\n | 'stackMode'\n | 'stackCounterAlign'\n | 'stackJustify'\n | 'stackCounterAlignItems'\n | 'stackPrimaryAlignItems'\n | 'stackPrimarySizing'\n | 'stackCounterSizing'\n | 'stackWrap'\n | 'stackPositioning'\n | 'stackChildAlignSelf',\n string\n > &\n Record<\n | 'stackSpacing'\n | 'stackPadding'\n | 'stackPaddingRight'\n | 'stackPaddingBottom'\n | 'stackVerticalPadding'\n | 'stackHorizontalPadding'\n | 'stackChildPrimaryGrow'\n | 'stackCounterSpacing',\n number\n > &\n Record<'bordersTakeSpace' | 'stackReverseZIndex', boolean>\n>\n\nexport interface LibraryAssetIdentity {\n libraryId: string\n assetKey: string\n revisionId: string\n}\n\nexport interface LibraryAssetSource {\n identity: LibraryAssetIdentity\n sourceNodeId: string | null\n readOnly: boolean\n}\n\nexport interface EnabledLibraryBinding {\n libraryId: string\n revisionId: string\n enabled: boolean\n}\n\n/** The library a document publishes as. */\nexport interface SourceLibraryPublication {\n libraryId: string\n revisionId: string\n name: string\n catalogSource?: string\n}\n\n/** A reply in a canvas comment thread. */\nexport interface CommentReply {\n id: string\n author: string\n /** The author's collaboration color when they wrote it, for their avatar. */\n authorColor?: Color\n /** Markdown: bold, italic, strikethrough, links and lists. */\n text: string\n createdAt: string\n deleted?: boolean\n}\n\n/** A canvas comment thread, kept in the document's root plugin data. */\nexport interface CommentThread {\n id: string\n pageId: string\n /** Page name when the pin was placed, for readers of the raw data. */\n pageName?: string\n /** Top-level layer under the pin; the pin follows it when it moves. */\n nodeId?: string | null\n nodeName?: string | null\n /** Offset from the layer's top-left corner, in canvas units. */\n offsetX?: number\n offsetY?: number\n /** Canvas position when the pin was last saved; used when the layer is gone. */\n x: number\n y: number\n author: string\n /** The author's collaboration color when they wrote it, for their avatar. */\n authorColor?: Color\n /** Markdown: bold, italic, strikethrough, links and lists. */\n text: string\n createdAt: string\n /** Bumped on every change. */\n updatedAt: string\n resolved: boolean\n resolvedAt?: string | null\n /** Deleted threads stay as tombstones so a stale copy cannot bring them back. */\n deleted?: boolean\n replies: CommentReply[]\n}\n\n/**\n * How a prototype reaction starts, as `.fig` keeps `PrototypeEvent.interactionType`: a click, the\n * pointer held over the layer (`ON_HOVER`, While hovering) or pressed on it (`ON_PRESS`, While\n * pressing), which undo themselves when it leaves or lifts, the pointer entering or leaving it,\n * or a delay.\n */\nexport type PrototypeTriggerType =\n | 'ON_CLICK'\n | 'ON_HOVER'\n | 'ON_PRESS'\n | 'MOUSE_ENTER'\n | 'MOUSE_LEAVE'\n | 'AFTER_TIMEOUT'\n\n/** What a reaction does, as `.fig` keeps `ConnectionType` on `PrototypeAction`. */\nexport type PrototypeActionType = 'NODE' | 'BACK' | 'CLOSE'\n\n/**\n * What a node action does with its node, as `NavigationType`: move to a frame, open it over the\n * screen, show another variant of the instance's set (Figma's Change to, `SWAP_STATE` in `.fig`),\n * or scroll the layer into view.\n */\nexport type PrototypeNavigationType = 'NAVIGATE' | 'OVERLAY' | 'CHANGE_TO' | 'SCROLL_TO'\n\n/** Which way a frame's content scrolls in play, as Figma's `overflowDirection`. */\nexport type OverflowDirection = 'NONE' | 'HORIZONTAL' | 'VERTICAL' | 'BOTH'\n\n/**\n * How a layer moves when its parent frame scrolls in play: with the content, fixed in the frame,\n * or scrolled until it reaches the frame's top/left edge and then stuck there.\n */\nexport type ScrollBehavior = 'SCROLLS' | 'FIXED' | 'STICKY_SCROLLS'\n\n/**\n * How a reaction animates between frames, as `TransitionType` keeps them: a cut, a crossfade, or\n * Smart animate, which moves the layers two frames share by name and fades the rest.\n */\nexport type PrototypeTransitionType = 'INSTANT' | 'DISSOLVE' | 'SMART_ANIMATE'\n\n/** How a transition eases, by the names Figma's plugin API gives its presets. */\nexport type PrototypeEasingType = 'LINEAR' | 'EASE_IN' | 'EASE_OUT' | 'EASE_IN_AND_OUT'\n\n/** Where an overlay sits over the screen, as `OverlayPositionType`. */\nexport type PrototypeOverlayPositionType =\n | 'CENTER'\n | 'TOP_LEFT'\n | 'TOP_CENTER'\n | 'TOP_RIGHT'\n | 'BOTTOM_LEFT'\n | 'BOTTOM_CENTER'\n | 'BOTTOM_RIGHT'\n\n/** How a reaction animates, how long it takes in seconds, and how it eases. */\nexport interface PrototypeTransition {\n type: PrototypeTransitionType\n duration: number\n /** Absent eases as Figma's default does, `DEFAULT_PROTOTYPE_EASING`. */\n easing?: PrototypeEasingType\n}\n\n/** A reaction's move to another frame, the overlay it opens, the variant or layer it shows. */\nexport interface PrototypeNodeAction {\n type: 'NODE'\n /**\n * The frame the action shows, the variant a Change to shows, or the layer a Scroll to brings\n * into view; `null` keeps the connection when its target is gone.\n */\n nodeId: string | null\n navigation: PrototypeNavigationType\n transition: PrototypeTransition\n /** Where an OVERLAY sits over the screen; NAVIGATE keeps CENTER. */\n overlayPosition: PrototypeOverlayPositionType\n}\n\n/** Goes back to the frame the play came from. */\nexport interface PrototypeBackAction {\n type: 'BACK'\n}\n\n/** Closes the overlay the play is showing. */\nexport interface PrototypeCloseAction {\n type: 'CLOSE'\n}\n\nexport type PrototypeAction = PrototypeNodeAction | PrototypeBackAction | PrototypeCloseAction\n\n/** What starts a reaction, and after how long an AFTER_TIMEOUT or mouse enter or leave does. */\nexport interface PrototypeTrigger {\n type: PrototypeTriggerType\n /** AFTER_TIMEOUT, MOUSE_ENTER and MOUSE_LEAVE: the seconds before the reaction runs. */\n delay: number\n}\n\n/**\n * One prototype connection on a layer: what starts it and what it does, as `.fig` keeps a\n * `PrototypeInteraction` on the layer's `prototypeInteractions`.\n */\nexport interface PrototypeReaction {\n id: string\n trigger: PrototypeTrigger\n actions: PrototypeAction[]\n}\n\nexport interface SceneNode {\n id: string\n type: NodeType\n name: string\n parentId: string | null\n childIds: string[]\n\n x: number\n y: number\n width: number\n height: number\n rotation: number\n source: SourceMetadata\n /** Materialized layout hint imported or generated outside the live Yoga layout pass. */\n derivedLayout: Partial<Rect> | null\n\n fills: Fill[]\n strokes: Stroke[]\n effects: Effect[]\n layoutGrids: LayoutGrid[]\n guides: CanvasGuide[]\n fillStyleId: string | null\n strokeStyleId: string | null\n textStyleId: string | null\n effectStyleId: string | null\n gridStyleId: string | null\n sharedStyleType: SharedStyleType | null\n opacity: number\n\n cornerRadius: number\n topLeftRadius: number\n topRightRadius: number\n bottomRightRadius: number\n bottomLeftRadius: number\n independentCorners: boolean\n cornerSmoothing: number\n\n visible: boolean\n locked: boolean\n clipsContent: boolean\n /** Which way the frame's content scrolls in play; a nested frame scrolls only while it clips. */\n overflowDirection: OverflowDirection\n /** How this layer moves while its parent frame scrolls in play. */\n scrollBehavior: ScrollBehavior\n\n blendMode: BlendMode\n\n text: string\n fontSize: number\n fontFamily: string\n fontWeight: number\n italic: boolean\n /**\n * The face by the name its font gives it (\"Semi Bold\", \"Book\", \"Condensed Bold\"), which Figma\n * finds a font's face by; `null` is the face the weight and slant pick in the family.\n */\n fontStyle: string | null\n textAlignHorizontal: 'LEFT' | 'CENTER' | 'RIGHT' | 'JUSTIFIED'\n textDirection: TextDirection\n textLanguage: string | null\n textAlignVertical: TextAlignVertical\n textAutoResize: TextAutoResize\n textCase: TextCase\n textDecoration: TextDecoration\n textDecorationStyle: TextDecorationStyle\n textDecorationThickness: number | null\n textDecorationFills: Fill[]\n textDecorationSkipInk: boolean\n textUnderlineOffset: number | null\n leadingTrim: LeadingTrim\n /** `null` is automatic, from the font. */\n lineHeight: TextLength | null\n letterSpacing: TextLength\n maxLines: number | null\n /**\n * One entry per paragraph of `text`, in order. Missing entries are plain paragraphs, so text\n * without lists keeps this empty.\n */\n textParagraphs: TextParagraphStyle[]\n /** Space after a list item followed by another; a paragraph's own value comes first. */\n listSpacing: number\n /** Space after a paragraph other than between two list items. */\n paragraphSpacing: number\n /** Indent of the first line of each plain paragraph. */\n paragraphIndent: number\n /** Whether list markers hang outside the text box instead of indenting the items. */\n hangingList: boolean\n\n styleRuns: StyleRun[]\n fontVariations: FontVariation[]\n /**\n * Whether a variable font's optical size follows the font size, as Figma's \"Set optical size\n * automatically\" does by default; when it does not, the `opsz` in `fontVariations` applies.\n */\n opticalSizeFromFontSize: boolean\n fontFeatures: FontFeature[]\n\n horizontalConstraint: ConstraintType\n verticalConstraint: ConstraintType\n\n layoutMode: LayoutMode\n layoutDirection: LayoutDirection\n layoutWrap: LayoutWrap\n primaryAxisAlign: LayoutAlign\n counterAxisAlign: LayoutCounterAlign\n primaryAxisSizing: AxisSizingMode\n counterAxisSizing: AxisSizingMode\n itemSpacing: number\n counterAxisSpacing: number\n paddingTop: number\n paddingRight: number\n paddingBottom: number\n paddingLeft: number\n\n layoutPositioning: 'AUTO' | 'ABSOLUTE'\n layoutGrow: number\n layoutAlignSelf: LayoutAlignSelf\n\n vectorNetwork: VectorNetwork | null\n handleMirroring: HandleMirroring\n booleanOperation: BooleanOperation | undefined\n fillGeometry: GeometryPath[]\n strokeGeometry: GeometryPath[]\n\n arcData: ArcData | null\n\n strokeCap: StrokeCap\n strokeJoin: StrokeJoin\n dashPattern: number[]\n\n borderTopWeight: number\n borderRightWeight: number\n borderBottomWeight: number\n borderLeftWeight: number\n independentStrokeWeights: boolean\n\n /**\n * The weight and alignment a node keeps for its strokes, as Figma keeps them on the node: they\n * last while it has no strokes, and a stroke added to it takes them. Each stroke still carries\n * its own `weight` and `align`, which win while the node has strokes.\n */\n strokeWeight: number\n strokeAlign: Stroke['align']\n\n strokeMiterLimit: number\n\n minWidth: number | null\n maxWidth: number | null\n minHeight: number | null\n maxHeight: number | null\n /**\n * The size whose proportions the layer keeps, as Figma stores it: the width and height it had\n * when the ratio was locked, not a reduced ratio. Null leaves the proportions free.\n */\n targetAspectRatio: Vector | null\n\n /** A connector's ends and the line between them; null on other layers. */\n connectorStart: ConnectorEndpoint | null\n connectorEnd: ConnectorEndpoint | null\n connectorLineType: ConnectorLineType\n connectorStartCap: StrokeCap\n connectorEndCap: StrokeCap\n /**\n * An elbow connector's segments between its first and last, in order, once one was dragged;\n * empty while it routes itself. Kept, unused, while the line is straight or curved.\n */\n connectorControlPoints: ConnectorControlPoint[]\n /**\n * A curved connector's two cubic control points, in the connector's own axes, once its curve\n * was dragged; null while it curves by itself. Kept, unused, while the line is not curved.\n */\n connectorCurveHandles: [Vector, Vector] | null\n /** Where a connector's label was dragged to; null while it sits midway along the line. */\n connectorLabelPosition: ConnectorLabelPosition | null\n\n isMask: boolean\n maskType: MaskType\n maskIsOutline: boolean\n\n gridTemplateColumns: GridTrack[]\n gridTemplateRows: GridTrack[]\n gridColumnGap: number\n gridRowGap: number\n gridPosition: GridPosition | null\n\n counterAxisAlignContent: 'AUTO' | 'SPACE_BETWEEN'\n itemReverseZIndex: boolean\n strokesIncludedInLayout: boolean\n\n expanded: boolean\n textTruncation: 'DISABLED' | 'ENDING'\n autoRename: boolean\n\n pointCount: number\n starInnerRadius: number\n /** The FigJam kind a SHAPE_WITH_TEXT draws; its label is the node's own text. */\n shapeWithTextType: ShapeWithTextType\n /** The height a shape with text was given; it grows past it to fit its label. 0 is unset. */\n shapeUserHeight: number\n /**\n * Whether a shape with text keeps its height and cuts its label off with \"…\" instead of growing,\n * as FigJam does once the shape's height was set.\n */\n shapeTruncates: boolean\n\n componentId: string | null\n instanceOverrides: InstanceOverrideState\n componentPropertyDefinitions: ComponentPropertyDefinition[]\n componentPropertyReferences: ComponentPropertyReference[]\n componentPropertyAssignments: Record<string, string>\n componentPropertyValues: Record<string, string>\n componentKey: string | null\n sourceLibraryKey: string | null\n publishId: string | null\n overrideKey: string | null\n sharedSymbolVersion: string | null\n publishedVersion: string | null\n librarySource: LibraryAssetSource | null\n isPublishable: boolean\n isSymbolPublishable: boolean\n /**\n * On an instance inside a component: its properties show on instances of that component,\n * as Figma's `isExposedInstance`.\n */\n isExposedInstance: boolean\n symbolDescription: string\n symbolLinks: SymbolLink[]\n variantPropSpecs: VariantPropSpec[]\n\n boundVariables: Record<string, string>\n /** Multipliers from bound numeric values to this occurrence's scene units. */\n variableBindingScales: Partial<Record<string, number>>\n /** Numeric units for new declarations owned by this node's occurrence scope. */\n variableAssignmentScales: Partial<Record<string, number>>\n /** Explicit coordinate scale relative to the containing component definition. */\n componentScale: number\n variableModes: VariableModeMap\n exportSettings: ExportSetting[]\n /**\n * The id of the status a team gave the layer, a state of the document's workflow such as Ready\n * for dev. It stays while the layer sits where it cannot show one; `effectiveStatus` tells\n * whether it shows.\n */\n status: string | null\n\n pluginData: PluginDataEntry[]\n pluginRelaunchData: PluginRelaunchDataEntry[]\n\n /** The prototype reactions this layer starts, as Figma's prototype keeps them. */\n prototypeReactions: PrototypeReaction[]\n\n internalOnly: boolean\n\n flipX: boolean\n flipY: boolean\n\n textPicture: Uint8Array | null\n derivedTextGlyphs: DerivedTextGlyph[] | null\n /**\n * How far a text's lines reach down from its top: measured at its width when its text or width\n * changes, or read from the lines a file saved, and never saved itself. A fixed-size box does not\n * clip them, as in Figma, so its visual bounds reach this far. Null when not known.\n */\n derivedTextHeight: number | null\n /** Format-neutral layout path for text-on-path nodes. */\n textPathData: TextPathData | null\n /** Node-local box that maps textPathData into the node coordinate space. */\n textPathBox: Rect | null\n}\n\nexport type ComponentPropertyType = 'VARIANT' | 'TEXT' | 'BOOLEAN' | 'INSTANCE_SWAP' | 'SLOT'\n\n/** `SLOT_CONTENT` marks a frame whose children are the slot's content. */\nexport type ComponentPropertyReferenceField = 'VISIBLE' | 'TEXT' | 'INSTANCE_SWAP' | 'SLOT_CONTENT'\n\nexport interface ComponentPropertyReference {\n propertyId: string\n field: ComponentPropertyReferenceField\n}\n\n/** Guidance for a slot property; Figma reports a breach but still accepts the content. */\nexport interface SlotSettings {\n minChildren?: number\n maxChildren?: number\n allowPreferredValuesOnly: boolean\n displayEmptyByDefault: boolean\n /** Content added to the slot fills its counter axis. */\n stretchChildOnInsert: boolean\n}\n\n/**\n * For a `SLOT` property, an instance assignment (whatever its value) means the instance owns\n * that slot's content: the slot frame's children in the instance, which component sync keeps.\n */\nexport interface ComponentPropertyDefinition {\n id: string\n name: string\n type: ComponentPropertyType\n defaultValue: string\n variantOptions?: string[]\n preferredValues?: string[]\n description?: string\n slotSettings?: SlotSettings\n}\n\nexport type VariableType = 'COLOR' | 'FLOAT' | 'STRING' | 'BOOLEAN'\nexport interface VariableAlias {\n aliasId: string\n}\n\n/** Figma's two-argument color expression; opacity is a percentage, not an alpha multiplier. */\nexport interface VariableColorExpression {\n expression: 'COMPOSE_COLOR'\n color: Color | VariableAlias\n opacity: number | VariableAlias\n}\n\nexport type VariableLiteral = Color | number | string | boolean\n/** The arithmetic, comparison, logic and conversions a formula combines values with. */\nexport const VARIABLE_FORMULA_OPERATORS = [\n 'add',\n 'subtract',\n 'multiply',\n 'divide',\n 'negate',\n 'equal',\n 'notEqual',\n 'less',\n 'lessOrEqual',\n 'greater',\n 'greaterOrEqual',\n 'and',\n 'or',\n 'not',\n 'text',\n 'truthy',\n 'if'\n] as const\nexport type VariableFormulaOperator = (typeof VARIABLE_FORMULA_OPERATORS)[number]\nexport interface VariableFormulaOperation {\n operator: VariableFormulaOperator\n operands: VariableFormulaNode[]\n}\nexport type VariableFormulaNode = VariableLiteral | VariableAlias | VariableFormulaOperation\nexport interface VariableFormula {\n expression: 'FORMULA'\n type: VariableType\n value: VariableFormulaNode\n}\n/**\n * An imported expression Pairdraw cannot evaluate, kept as the file wrote it so saving writes it\n * back. `references` holds one entry per alias in `value`, in the order the format walks them, and\n * `null` where the alias names a variable this document does not have. `modes` holds the mode id of\n * each mode key in `value`, in the same walk order.\n */\nexport interface VariableUnsupportedExpression {\n expression: 'UNSUPPORTED'\n /** The function name the file gives, such as `VAR_MODE_LOOKUP`. */\n function: string\n value: Record<string, unknown>\n references: (string | null)[]\n modes: string[]\n}\nexport type VariableValue =\n | VariableLiteral\n | VariableAlias\n | VariableColorExpression\n | VariableFormula\n | VariableUnsupportedExpression\nexport type VariableModeMap = Record<string, string>\n\n/** Property pickers a variable is offered in, as Figma names them. */\nexport const VARIABLE_SCOPES = [\n 'ALL_SCOPES',\n 'TEXT_CONTENT',\n 'CORNER_RADIUS',\n 'WIDTH_HEIGHT',\n 'GAP',\n 'ALL_FILLS',\n 'FRAME_FILL',\n 'SHAPE_FILL',\n 'TEXT_FILL',\n 'STROKE',\n 'STROKE_FLOAT',\n 'EFFECT_FLOAT',\n 'EFFECT_COLOR',\n 'OPACITY',\n 'FONT_STYLE',\n 'FONT_FAMILY',\n 'FONT_SIZE',\n 'LINE_HEIGHT',\n 'LETTER_SPACING',\n 'PARAGRAPH_SPACING',\n 'PARAGRAPH_INDENT',\n 'FONT_VARIATIONS',\n 'TRANSFORM'\n] as const\nexport type VariableScope = (typeof VARIABLE_SCOPES)[number]\n\nexport const CODE_SYNTAX_PLATFORMS = ['WEB', 'ANDROID', 'iOS'] as const\nexport type CodeSyntaxPlatform = (typeof CODE_SYNTAX_PLATFORMS)[number]\n\n/**\n * The CSS unit a numeric token is written in. Lengths (`px`, `rem`) stay in canvas pixels in\n * the document and convert only when written as CSS; the other units store the number as written.\n */\nexport const TOKEN_UNITS = ['none', 'px', 'rem', '%', 'ms', 's', 'deg'] as const\nexport type TokenUnit = (typeof TOKEN_UNITS)[number]\n\n/**\n * CSS written in place of a number mode's value, such as `clamp(1rem, 4vw, 1.5rem)`. While the\n * mode holds a plain number, `resolved` records it, so a number later edited elsewhere, Figma\n * included, shows the CSS no longer describes it.\n */\nexport interface TokenExpression {\n css: string\n resolved?: number\n}\n\nexport interface Variable {\n id: string\n name: string\n type: VariableType\n collectionId: string\n valuesByMode: Record<string, VariableValue>\n description: string\n hiddenFromPublishing: boolean\n /** Absent means every scope. */\n scopes?: VariableScope[]\n /**\n * Per-platform code snippets, as Figma's Dev Mode shows them. A `WEB` snippet of `--x` or\n * `var(--x)` names the token's CSS custom property; otherwise the name is derived.\n */\n codeSyntax?: Partial<Record<CodeSyntaxPlatform, string>>\n /** FLOAT only. Absent means inferred when written as CSS. */\n unit?: TokenUnit\n /** Raw CSS by mode id, for values a number cannot express (`clamp()`, `calc()`). */\n expressions?: Record<string, TokenExpression>\n pluginData?: PluginDataEntry[]\n /** Published library key (from NodeChange.key). Used for assetRef resolution in colorVar. */\n key?: string\n /** Published library version (from NodeChange.version). Used for assetRef resolution in colorVar. */\n version?: string\n}\n\n/** Scalar numeric node fields accepted by numeric property controls. */\nexport type NumericNodeProperty = {\n [K in keyof SceneNode]-?: SceneNode[K] extends number ? K : never\n}[keyof SceneNode]\n\nexport interface VariableCollectionMode {\n modeId: string\n name: string\n /**\n * Where the mode applies in CSS: a selector (`[data-theme=\"dark\"]`, `.compact`) or an\n * at-rule prelude (`@media (max-width: 640px)`). Absent means the default for its axis.\n */\n condition?: string\n /** Where Figma lists the mode, as the file saved it; Figma orders a collection's modes by it. */\n sortPosition?: string\n}\n\nexport interface VariableCollection {\n id: string\n name: string\n /** The default mode comes first, as in Figma. */\n modes: VariableCollectionMode[]\n defaultModeId: string\n variableIds: string[]\n /**\n * The attribute that switches a mode with no condition of its own, `data-theme` for\n * `[data-theme=\"dark\"]`. Absent means one named after the collection.\n */\n modeAttribute?: string\n pluginData?: PluginDataEntry[]\n /**\n * Published library key, for a collection the file copies from a library. Such a collection\n * belongs to the library: Figma lists it with the library's, not the file's own.\n */\n key?: string\n /** Published library version, which references by key carry with it. */\n version?: string\n}\n\n/** Whether a collection is a library's copy, which takes no variables or modes of the file's. */\nexport function isLibraryCollection(collection: Pick<VariableCollection, 'key'>): boolean {\n return !!collection.key\n}\n\n/** An HTML attribute name a stylesheet can select on unescaped: `data-theme`, `theme`. */\nexport const MODE_ATTRIBUTE_PATTERN = /^[A-Za-z_][\\w-]*$/\n\nexport function isModeAttributeName(name: string): boolean {\n return name.length <= 100 && MODE_ATTRIBUTE_PATTERN.test(name)\n}\n"],"mappings":";;AAwcA,MAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAirBA,MAAa,6BAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAmCA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAGA,MAAa,wBAAwB;CAAC;CAAO;CAAW;AAAK;;;;;AAO7D,MAAa,cAAc;CAAC;CAAQ;CAAM;CAAO;CAAK;CAAM;CAAK;AAAK;;AA+EtE,SAAgB,oBAAoB,YAAsD;CACxF,OAAO,CAAC,CAAC,WAAW;AACtB;;AAGA,MAAa,yBAAyB;AAEtC,SAAgB,oBAAoB,MAAuB;CACzD,OAAO,KAAK,UAAU,OAAO,uBAAuB,KAAK,IAAI;AAC/D"}
@@ -0,0 +1,16 @@
1
+ import { SceneGraph } from "../graph.js";
2
+ import { PluginDataEntry, SceneNode } from "../types.js";
3
+ //#region src/variations/copy.d.ts
4
+ /** `node`'s plugin data marking it as the stand-in for `mainId`, or unmarked for null. */
5
+ declare function withStandIn(node: Pick<SceneNode, 'pluginData'>, mainId: string | null): PluginDataEntry[];
6
+ /**
7
+ * Copies `source` under `parentId` as a version: its root is never a main component or a
8
+ * component set (it becomes a plain frame), and the main components inside it are instances of
9
+ * the components they copy. Instances stay instances. Each layer standing in for a main
10
+ * component or set is marked with its id (`variationStandIn`), which is how a pick knows it. Right after a copy the two trees have the
11
+ * same shape, so each copied layer is found at its source's place.
12
+ */
13
+ declare function copyVersion(graph: SceneGraph, sourceId: string, parentId: string, overrides: Partial<SceneNode>): SceneNode | null;
14
+ //#endregion
15
+ export { copyVersion, withStandIn };
16
+ //# sourceMappingURL=copy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy.d.ts","names":[],"sources":["../../src/variations/copy.ts"],"mappings":";;;;iBAUgB,YAAY,MAAM,KAAK,0BAA0B,wBAA/B;;;;;;;;iBAoClB,YACd,OAAO,YACP,kBACA,kBACA,WAAW,QAAQ,aAClB"}
@@ -0,0 +1,78 @@
1
+ import { createDefaultNode } from "../node-defaults.js";
2
+ import { readPluginData, withPluginData } from "../plugin-data/field.js";
3
+ import { PAIRDRAW_PLUGIN_DATA } from "../plugin-data/fields.js";
4
+ import { MAIN_COMPONENT_FIELDS } from "../fields/components.js";
5
+ import { pick } from "es-toolkit";
6
+ //#region src/variations/copy.ts
7
+ /** `node`'s plugin data marking it as the stand-in for `mainId`, or unmarked for null. */
8
+ function withStandIn(node, mainId) {
9
+ return withPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.variationStandIn, mainId ?? void 0);
10
+ }
11
+ /** What a copied main component or component set clears to become a plain frame. */
12
+ function plainFrameFields() {
13
+ const frame = createDefaultNode(() => "", "FRAME");
14
+ return {
15
+ type: "FRAME",
16
+ ...pick(frame, MAIN_COMPONENT_FIELDS)
17
+ };
18
+ }
19
+ /**
20
+ * A copied main component inside the copy shows the component it copied, as an instance in its
21
+ * place, so copies never add main components; one that cannot become an instance, such as one
22
+ * that would hold itself, stays a plain frame.
23
+ */
24
+ function instanceInPlace(graph, component, copy, index) {
25
+ const parentId = copy.parentId;
26
+ const instance = parentId ? graph.createInstance(component.id, parentId, {
27
+ name: copy.name,
28
+ x: copy.x,
29
+ y: copy.y
30
+ }) : null;
31
+ if (!instance || !parentId) {
32
+ graph.updateNode(copy.id, plainFrameFields());
33
+ return;
34
+ }
35
+ graph.updateNode(instance.id, { pluginData: withStandIn(instance, component.id) });
36
+ graph.insertChildAt(instance.id, parentId, index);
37
+ graph.deleteNode(copy.id);
38
+ }
39
+ /**
40
+ * Copies `source` under `parentId` as a version: its root is never a main component or a
41
+ * component set (it becomes a plain frame), and the main components inside it are instances of
42
+ * the components they copy. Instances stay instances. Each layer standing in for a main
43
+ * component or set is marked with its id (`variationStandIn`), which is how a pick knows it. Right after a copy the two trees have the
44
+ * same shape, so each copied layer is found at its source's place.
45
+ */
46
+ function copyVersion(graph, sourceId, parentId, overrides) {
47
+ const copy = graph.cloneTree(sourceId, parentId, overrides);
48
+ if (!copy) return null;
49
+ if (copy.type === "COMPONENT" || copy.type === "COMPONENT_SET") graph.updateNode(copy.id, plainFrameFields());
50
+ const pending = [[sourceId, copy.id]];
51
+ for (const [fromId, toId] of pending) {
52
+ const from = graph.getNode(fromId);
53
+ const to = graph.getNode(toId);
54
+ if (!from || !to || from.type === "INSTANCE") continue;
55
+ const copied = [...to.childIds];
56
+ from.childIds.forEach((childId, index) => {
57
+ const child = graph.getNode(childId);
58
+ const childCopy = graph.getNode(copied[index] ?? "");
59
+ if (!child || !childCopy) return;
60
+ const mark = readPluginData(child.pluginData, PAIRDRAW_PLUGIN_DATA.variationStandIn);
61
+ if (mark !== void 0) graph.updateNode(childCopy.id, { pluginData: withStandIn(childCopy, mark) });
62
+ if (child.type === "COMPONENT") {
63
+ instanceInPlace(graph, child, childCopy, index);
64
+ return;
65
+ }
66
+ if (child.type === "COMPONENT_SET") graph.updateNode(childCopy.id, {
67
+ ...plainFrameFields(),
68
+ pluginData: withStandIn(childCopy, child.id)
69
+ });
70
+ pending.push([childId, childCopy.id]);
71
+ });
72
+ }
73
+ return graph.getNode(copy.id) ?? null;
74
+ }
75
+ //#endregion
76
+ export { copyVersion, withStandIn };
77
+
78
+ //# sourceMappingURL=copy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy.js","names":[],"sources":["../../src/variations/copy.ts"],"sourcesContent":["import { pick } from 'es-toolkit'\n\nimport { MAIN_COMPONENT_FIELDS } from '../fields'\nimport type { SceneGraph } from '../graph'\nimport { createDefaultNode } from '../node-defaults'\nimport { readPluginData, withPluginData } from '../plugin-data/field'\nimport { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { SceneNode } from '../types'\n\n/** `node`'s plugin data marking it as the stand-in for `mainId`, or unmarked for null. */\nexport function withStandIn(node: Pick<SceneNode, 'pluginData'>, mainId: string | null) {\n return withPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.variationStandIn, mainId ?? undefined)\n}\n\n/** What a copied main component or component set clears to become a plain frame. */\nfunction plainFrameFields(): Partial<SceneNode> {\n const frame = createDefaultNode(() => '', 'FRAME')\n return { type: 'FRAME', ...pick(frame, MAIN_COMPONENT_FIELDS) }\n}\n\n/**\n * A copied main component inside the copy shows the component it copied, as an instance in its\n * place, so copies never add main components; one that cannot become an instance, such as one\n * that would hold itself, stays a plain frame.\n */\nfunction instanceInPlace(graph: SceneGraph, component: SceneNode, copy: SceneNode, index: number) {\n const parentId = copy.parentId\n const instance = parentId\n ? graph.createInstance(component.id, parentId, { name: copy.name, x: copy.x, y: copy.y })\n : null\n if (!instance || !parentId) {\n graph.updateNode(copy.id, plainFrameFields())\n return\n }\n graph.updateNode(instance.id, { pluginData: withStandIn(instance, component.id) })\n graph.insertChildAt(instance.id, parentId, index)\n graph.deleteNode(copy.id)\n}\n\n/**\n * Copies `source` under `parentId` as a version: its root is never a main component or a\n * component set (it becomes a plain frame), and the main components inside it are instances of\n * the components they copy. Instances stay instances. Each layer standing in for a main\n * component or set is marked with its id (`variationStandIn`), which is how a pick knows it. Right after a copy the two trees have the\n * same shape, so each copied layer is found at its source's place.\n */\nexport function copyVersion(\n graph: SceneGraph,\n sourceId: string,\n parentId: string,\n overrides: Partial<SceneNode>\n): SceneNode | null {\n const copy = graph.cloneTree(sourceId, parentId, overrides)\n if (!copy) return null\n if (copy.type === 'COMPONENT' || copy.type === 'COMPONENT_SET') {\n graph.updateNode(copy.id, plainFrameFields())\n }\n const pending: Array<[string, string]> = [[sourceId, copy.id]]\n // Pairs are appended while the list is walked, parents before their children.\n for (const [fromId, toId] of pending) {\n const from = graph.getNode(fromId)\n const to = graph.getNode(toId)\n // An instance's layers are its component's copies, kept by sync.\n if (!from || !to || from.type === 'INSTANCE') continue\n const copied = [...to.childIds]\n from.childIds.forEach((childId, index) => {\n const child = graph.getNode(childId)\n const childCopy = graph.getNode(copied[index] ?? '')\n if (!child || !childCopy) return\n // Copying a version copies its stand-ins as stand-ins, which a plain copy drops.\n const mark = readPluginData(child.pluginData, PAIRDRAW_PLUGIN_DATA.variationStandIn)\n if (mark !== undefined) {\n graph.updateNode(childCopy.id, { pluginData: withStandIn(childCopy, mark) })\n }\n if (child.type === 'COMPONENT') {\n instanceInPlace(graph, child, childCopy, index)\n return\n }\n if (child.type === 'COMPONENT_SET') {\n graph.updateNode(childCopy.id, {\n ...plainFrameFields(),\n pluginData: withStandIn(childCopy, child.id)\n })\n }\n pending.push([childId, childCopy.id])\n })\n }\n return graph.getNode(copy.id) ?? null\n}\n"],"mappings":";;;;;;;AAUA,SAAgB,YAAY,MAAqC,QAAuB;CACtF,OAAO,eAAe,KAAK,YAAY,qBAAqB,kBAAkB,UAAU,KAAA,CAAS;AACnG;;AAGA,SAAS,mBAAuC;CAC9C,MAAM,QAAQ,wBAAwB,IAAI,OAAO;CACjD,OAAO;EAAE,MAAM;EAAS,GAAG,KAAK,OAAO,qBAAqB;CAAE;AAChE;;;;;;AAOA,SAAS,gBAAgB,OAAmB,WAAsB,MAAiB,OAAe;CAChG,MAAM,WAAW,KAAK;CACtB,MAAM,WAAW,WACb,MAAM,eAAe,UAAU,IAAI,UAAU;EAAE,MAAM,KAAK;EAAM,GAAG,KAAK;EAAG,GAAG,KAAK;CAAE,CAAC,IACtF;CACJ,IAAI,CAAC,YAAY,CAAC,UAAU;EAC1B,MAAM,WAAW,KAAK,IAAI,iBAAiB,CAAC;EAC5C;CACF;CACA,MAAM,WAAW,SAAS,IAAI,EAAE,YAAY,YAAY,UAAU,UAAU,EAAE,EAAE,CAAC;CACjF,MAAM,cAAc,SAAS,IAAI,UAAU,KAAK;CAChD,MAAM,WAAW,KAAK,EAAE;AAC1B;;;;;;;;AASA,SAAgB,YACd,OACA,UACA,UACA,WACkB;CAClB,MAAM,OAAO,MAAM,UAAU,UAAU,UAAU,SAAS;CAC1D,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,KAAK,SAAS,eAAe,KAAK,SAAS,iBAC7C,MAAM,WAAW,KAAK,IAAI,iBAAiB,CAAC;CAE9C,MAAM,UAAmC,CAAC,CAAC,UAAU,KAAK,EAAE,CAAC;CAE7D,KAAK,MAAM,CAAC,QAAQ,SAAS,SAAS;EACpC,MAAM,OAAO,MAAM,QAAQ,MAAM;EACjC,MAAM,KAAK,MAAM,QAAQ,IAAI;EAE7B,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,SAAS,YAAY;EAC9C,MAAM,SAAS,CAAC,GAAG,GAAG,QAAQ;EAC9B,KAAK,SAAS,SAAS,SAAS,UAAU;GACxC,MAAM,QAAQ,MAAM,QAAQ,OAAO;GACnC,MAAM,YAAY,MAAM,QAAQ,OAAO,UAAU,EAAE;GACnD,IAAI,CAAC,SAAS,CAAC,WAAW;GAE1B,MAAM,OAAO,eAAe,MAAM,YAAY,qBAAqB,gBAAgB;GACnF,IAAI,SAAS,KAAA,GACX,MAAM,WAAW,UAAU,IAAI,EAAE,YAAY,YAAY,WAAW,IAAI,EAAE,CAAC;GAE7E,IAAI,MAAM,SAAS,aAAa;IAC9B,gBAAgB,OAAO,OAAO,WAAW,KAAK;IAC9C;GACF;GACA,IAAI,MAAM,SAAS,iBACjB,MAAM,WAAW,UAAU,IAAI;IAC7B,GAAG,iBAAiB;IACpB,YAAY,YAAY,WAAW,MAAM,EAAE;GAC7C,CAAC;GAEH,QAAQ,KAAK,CAAC,SAAS,UAAU,EAAE,CAAC;EACtC,CAAC;CACH;CACA,OAAO,MAAM,QAAQ,KAAK,EAAE,KAAK;AACnC"}
@@ -0,0 +1,6 @@
1
+ import { copyVersion, withStandIn } from "./copy.js";
2
+ import { matchLayers, standsIn } from "./match.js";
3
+ import { VARIATION_LABEL_MAX_LENGTH, VARIATION_MAX_COUNT, VARIATION_MAX_LAYERS, VariationSet, variationSetSchema, variationStandInSchema } from "./schema.js";
4
+ import { VariationSetView, originalChangedSince, readVariationSet, variationFingerprint, variationSetForOriginal, variationSetOf, variationSetsOnPage, versionOf, withVariationSet } from "./model.js";
5
+ import { VariationError, VariationPickProblem, applyVariation, discardVariations, variationPickProblem, variationToPick } from "./pick.js";
6
+ export { VARIATION_LABEL_MAX_LENGTH, VARIATION_MAX_COUNT, VARIATION_MAX_LAYERS, VariationError, VariationPickProblem, VariationSet, VariationSetView, applyVariation, copyVersion, discardVariations, matchLayers, originalChangedSince, readVariationSet, standsIn, variationFingerprint, variationPickProblem, variationSetForOriginal, variationSetOf, variationSetSchema, variationSetsOnPage, variationStandInSchema, variationToPick, versionOf, withStandIn, withVariationSet };
@@ -0,0 +1,6 @@
1
+ import { VARIATION_LABEL_MAX_LENGTH, VARIATION_MAX_COUNT, VARIATION_MAX_LAYERS, variationSetSchema, variationStandInSchema } from "./schema.js";
2
+ import { copyVersion, withStandIn } from "./copy.js";
3
+ import { matchLayers, standsIn } from "./match.js";
4
+ import { originalChangedSince, readVariationSet, variationFingerprint, variationSetForOriginal, variationSetOf, variationSetsOnPage, versionOf, withVariationSet } from "./model.js";
5
+ import { VariationError, applyVariation, discardVariations, variationPickProblem, variationToPick } from "./pick.js";
6
+ export { VARIATION_LABEL_MAX_LENGTH, VARIATION_MAX_COUNT, VARIATION_MAX_LAYERS, VariationError, applyVariation, copyVersion, discardVariations, matchLayers, originalChangedSince, readVariationSet, standsIn, variationFingerprint, variationPickProblem, variationSetForOriginal, variationSetOf, variationSetSchema, variationSetsOnPage, variationStandInSchema, variationToPick, versionOf, withStandIn, withVariationSet };
@@ -0,0 +1,23 @@
1
+ import { SceneGraph } from "../graph.js";
2
+ import { SceneNode } from "../types.js";
3
+ //#region src/variations/match.d.ts
4
+ /**
5
+ * Which layer of the original each layer of a version stands for, as version id → original id.
6
+ * The roots always pair. Under each paired parent, children pair first by type and name in
7
+ * order, then the ones left by type in order, so a renamed or moved layer still finds its
8
+ * counterpart; layers of different types never pair, except a main component's or component
9
+ * set's stand-in, marked as such (`standsIn`), which pairs with it; a marked layer that does
10
+ * not find its component here pairs as any other layer. Only layers paired with their own type are
11
+ * searched further. Nothing is stored: a version is a copy of the original, so its layers mostly
12
+ * keep the names and types they were copied with.
13
+ */
14
+ declare function matchLayers(graph: SceneGraph, originalId: string, versionId: string): Map<string, string>;
15
+ /**
16
+ * Whether `version` is what a copy holds in place of the main component or component set
17
+ * `original`, as its mark says (`copyVersion`): an instance of the component, or a frame of
18
+ * instances of the set's variants. A name proves nothing, since an instance may share it.
19
+ */
20
+ declare function standsIn(version: SceneNode, original: SceneNode): boolean;
21
+ //#endregion
22
+ export { matchLayers, standsIn };
23
+ //# sourceMappingURL=match.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match.d.ts","names":[],"sources":["../../src/variations/match.ts"],"mappings":";;;;;;;;;;;;;iBAiBgB,YACd,OAAO,YACP,oBACA,oBACC;;;;;;iBAqBa,SAAS,SAAS,WAAW,UAAU"}
@@ -0,0 +1,80 @@
1
+ import { readPluginData } from "../plugin-data/field.js";
2
+ import { PAIRDRAW_PLUGIN_DATA } from "../plugin-data/fields.js";
3
+ import { groupBy } from "es-toolkit";
4
+ //#region src/variations/match.ts
5
+ /**
6
+ * Which layer of the original each layer of a version stands for, as version id → original id.
7
+ * The roots always pair. Under each paired parent, children pair first by type and name in
8
+ * order, then the ones left by type in order, so a renamed or moved layer still finds its
9
+ * counterpart; layers of different types never pair, except a main component's or component
10
+ * set's stand-in, marked as such (`standsIn`), which pairs with it; a marked layer that does
11
+ * not find its component here pairs as any other layer. Only layers paired with their own type are
12
+ * searched further. Nothing is stored: a version is a copy of the original, so its layers mostly
13
+ * keep the names and types they were copied with.
14
+ */
15
+ function matchLayers(graph, originalId, versionId) {
16
+ const pairs = /* @__PURE__ */ new Map([[versionId, originalId]]);
17
+ const pending = [[versionId, originalId]];
18
+ for (let next = pending.pop(); next; next = pending.pop()) {
19
+ const [versionParent, originalParent] = next;
20
+ for (const [version, original] of matchChildren(graph.getChildren(versionParent), graph.getChildren(originalParent))) {
21
+ pairs.set(version.id, original.id);
22
+ if (version.type === original.type) pending.push([version.id, original.id]);
23
+ }
24
+ }
25
+ return pairs;
26
+ }
27
+ /**
28
+ * Whether `version` is what a copy holds in place of the main component or component set
29
+ * `original`, as its mark says (`copyVersion`): an instance of the component, or a frame of
30
+ * instances of the set's variants. A name proves nothing, since an instance may share it.
31
+ */
32
+ function standsIn(version, original) {
33
+ if (original.type !== "COMPONENT" && original.type !== "COMPONENT_SET") return false;
34
+ return readPluginData(version.pluginData, PAIRDRAW_PLUGIN_DATA.variationStandIn) === original.id;
35
+ }
36
+ /** Takes the next free layer of a bucket, skipping ones another bucket already gave away. */
37
+ function takeNext(bucket, cursors, taken) {
38
+ if (!bucket) return void 0;
39
+ let index = cursors.get(bucket) ?? 0;
40
+ while (index < bucket.length && taken.has(bucket[index].id)) index++;
41
+ cursors.set(bucket, Math.min(index + 1, bucket.length));
42
+ if (index === bucket.length) return void 0;
43
+ const found = bucket[index];
44
+ taken.add(found.id);
45
+ return found;
46
+ }
47
+ /**
48
+ * Pairs in one pass over each list: stand-ins for main components and sets first, then through
49
+ * buckets by type and name and by type alone.
50
+ */
51
+ function matchChildren(versions, originals) {
52
+ const mains = new Map(originals.filter((node) => node.type === "COMPONENT" || node.type === "COMPONENT_SET").map((node) => [node.id, node]));
53
+ const byName = groupBy(originals, (node) => `${node.type}\u0000${node.name}`);
54
+ const byType = groupBy(originals, (node) => node.type);
55
+ const cursors = /* @__PURE__ */ new Map();
56
+ const taken = /* @__PURE__ */ new Set();
57
+ const pairs = [];
58
+ const left = [];
59
+ for (const version of versions) {
60
+ const mainId = readPluginData(version.pluginData, PAIRDRAW_PLUGIN_DATA.variationStandIn);
61
+ const main = mainId === void 0 ? void 0 : mains.get(mainId);
62
+ if (main && !taken.has(main.id) && standsIn(version, main)) {
63
+ taken.add(main.id);
64
+ pairs.push([version, main]);
65
+ continue;
66
+ }
67
+ const named = takeNext(byName[`${version.type}\u0000${version.name}`], cursors, taken);
68
+ if (named) pairs.push([version, named]);
69
+ else left.push(version);
70
+ }
71
+ for (const version of left) {
72
+ const typed = takeNext(byType[version.type], cursors, taken);
73
+ if (typed) pairs.push([version, typed]);
74
+ }
75
+ return pairs;
76
+ }
77
+ //#endregion
78
+ export { matchLayers, standsIn };
79
+
80
+ //# sourceMappingURL=match.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match.js","names":[],"sources":["../../src/variations/match.ts"],"sourcesContent":["import { groupBy } from 'es-toolkit'\n\nimport type { SceneGraph } from '../graph'\nimport { readPluginData } from '../plugin-data/field'\nimport { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { SceneNode } from '../types'\n\n/**\n * Which layer of the original each layer of a version stands for, as version id → original id.\n * The roots always pair. Under each paired parent, children pair first by type and name in\n * order, then the ones left by type in order, so a renamed or moved layer still finds its\n * counterpart; layers of different types never pair, except a main component's or component\n * set's stand-in, marked as such (`standsIn`), which pairs with it; a marked layer that does\n * not find its component here pairs as any other layer. Only layers paired with their own type are\n * searched further. Nothing is stored: a version is a copy of the original, so its layers mostly\n * keep the names and types they were copied with.\n */\nexport function matchLayers(\n graph: SceneGraph,\n originalId: string,\n versionId: string\n): Map<string, string> {\n const pairs = new Map<string, string>([[versionId, originalId]])\n const pending: Array<[string, string]> = [[versionId, originalId]]\n for (let next = pending.pop(); next; next = pending.pop()) {\n const [versionParent, originalParent] = next\n for (const [version, original] of matchChildren(\n graph.getChildren(versionParent),\n graph.getChildren(originalParent)\n )) {\n pairs.set(version.id, original.id)\n if (version.type === original.type) pending.push([version.id, original.id])\n }\n }\n return pairs\n}\n\n/**\n * Whether `version` is what a copy holds in place of the main component or component set\n * `original`, as its mark says (`copyVersion`): an instance of the component, or a frame of\n * instances of the set's variants. A name proves nothing, since an instance may share it.\n */\nexport function standsIn(version: SceneNode, original: SceneNode): boolean {\n if (original.type !== 'COMPONENT' && original.type !== 'COMPONENT_SET') return false\n return readPluginData(version.pluginData, PAIRDRAW_PLUGIN_DATA.variationStandIn) === original.id\n}\n\n/** Takes the next free layer of a bucket, skipping ones another bucket already gave away. */\nfunction takeNext(\n bucket: readonly SceneNode[] | undefined,\n cursors: Map<readonly SceneNode[], number>,\n taken: Set<string>\n): SceneNode | undefined {\n if (!bucket) return undefined\n let index = cursors.get(bucket) ?? 0\n while (index < bucket.length && taken.has(bucket[index].id)) index++\n cursors.set(bucket, Math.min(index + 1, bucket.length))\n if (index === bucket.length) return undefined\n const found = bucket[index]\n taken.add(found.id)\n return found\n}\n\n/**\n * Pairs in one pass over each list: stand-ins for main components and sets first, then through\n * buckets by type and name and by type alone.\n */\nfunction matchChildren(\n versions: SceneNode[],\n originals: SceneNode[]\n): Array<[SceneNode, SceneNode]> {\n const mains = new Map(\n originals\n .filter((node) => node.type === 'COMPONENT' || node.type === 'COMPONENT_SET')\n .map((node) => [node.id, node])\n )\n const byName = groupBy(originals, (node) => `${node.type}\\u0000${node.name}`)\n const byType = groupBy(originals, (node) => node.type)\n const cursors = new Map<readonly SceneNode[], number>()\n const taken = new Set<string>()\n const pairs: Array<[SceneNode, SceneNode]> = []\n const left: SceneNode[] = []\n for (const version of versions) {\n const mainId = readPluginData(version.pluginData, PAIRDRAW_PLUGIN_DATA.variationStandIn)\n const main = mainId === undefined ? undefined : mains.get(mainId)\n if (main && !taken.has(main.id) && standsIn(version, main)) {\n taken.add(main.id)\n pairs.push([version, main])\n continue\n }\n const named = takeNext(byName[`${version.type}\\u0000${version.name}`], cursors, taken)\n if (named) pairs.push([version, named])\n else left.push(version)\n }\n for (const version of left) {\n const typed = takeNext(byType[version.type], cursors, taken)\n if (typed) pairs.push([version, typed])\n }\n return pairs\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,SAAgB,YACd,OACA,YACA,WACqB;CACrB,MAAM,wBAAQ,IAAI,IAAoB,CAAC,CAAC,WAAW,UAAU,CAAC,CAAC;CAC/D,MAAM,UAAmC,CAAC,CAAC,WAAW,UAAU,CAAC;CACjE,KAAK,IAAI,OAAO,QAAQ,IAAI,GAAG,MAAM,OAAO,QAAQ,IAAI,GAAG;EACzD,MAAM,CAAC,eAAe,kBAAkB;EACxC,KAAK,MAAM,CAAC,SAAS,aAAa,cAChC,MAAM,YAAY,aAAa,GAC/B,MAAM,YAAY,cAAc,CAClC,GAAG;GACD,MAAM,IAAI,QAAQ,IAAI,SAAS,EAAE;GACjC,IAAI,QAAQ,SAAS,SAAS,MAAM,QAAQ,KAAK,CAAC,QAAQ,IAAI,SAAS,EAAE,CAAC;EAC5E;CACF;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,SAAS,SAAoB,UAA8B;CACzE,IAAI,SAAS,SAAS,eAAe,SAAS,SAAS,iBAAiB,OAAO;CAC/E,OAAO,eAAe,QAAQ,YAAY,qBAAqB,gBAAgB,MAAM,SAAS;AAChG;;AAGA,SAAS,SACP,QACA,SACA,OACuB;CACvB,IAAI,CAAC,QAAQ,OAAO,KAAA;CACpB,IAAI,QAAQ,QAAQ,IAAI,MAAM,KAAK;CACnC,OAAO,QAAQ,OAAO,UAAU,MAAM,IAAI,OAAO,MAAM,CAAC,EAAE,GAAG;CAC7D,QAAQ,IAAI,QAAQ,KAAK,IAAI,QAAQ,GAAG,OAAO,MAAM,CAAC;CACtD,IAAI,UAAU,OAAO,QAAQ,OAAO,KAAA;CACpC,MAAM,QAAQ,OAAO;CACrB,MAAM,IAAI,MAAM,EAAE;CAClB,OAAO;AACT;;;;;AAMA,SAAS,cACP,UACA,WAC+B;CAC/B,MAAM,QAAQ,IAAI,IAChB,UACG,QAAQ,SAAS,KAAK,SAAS,eAAe,KAAK,SAAS,eAAe,CAAC,CAC5E,KAAK,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,CAClC;CACA,MAAM,SAAS,QAAQ,YAAY,SAAS,GAAG,KAAK,KAAK,QAAQ,KAAK,MAAM;CAC5E,MAAM,SAAS,QAAQ,YAAY,SAAS,KAAK,IAAI;CACrD,MAAM,0BAAU,IAAI,IAAkC;CACtD,MAAM,wBAAQ,IAAI,IAAY;CAC9B,MAAM,QAAuC,CAAC;CAC9C,MAAM,OAAoB,CAAC;CAC3B,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,SAAS,eAAe,QAAQ,YAAY,qBAAqB,gBAAgB;EACvF,MAAM,OAAO,WAAW,KAAA,IAAY,KAAA,IAAY,MAAM,IAAI,MAAM;EAChE,IAAI,QAAQ,CAAC,MAAM,IAAI,KAAK,EAAE,KAAK,SAAS,SAAS,IAAI,GAAG;GAC1D,MAAM,IAAI,KAAK,EAAE;GACjB,MAAM,KAAK,CAAC,SAAS,IAAI,CAAC;GAC1B;EACF;EACA,MAAM,QAAQ,SAAS,OAAO,GAAG,QAAQ,KAAK,QAAQ,QAAQ,SAAS,SAAS,KAAK;EACrF,IAAI,OAAO,MAAM,KAAK,CAAC,SAAS,KAAK,CAAC;OACjC,KAAK,KAAK,OAAO;CACxB;CACA,KAAK,MAAM,WAAW,MAAM;EAC1B,MAAM,QAAQ,SAAS,OAAO,QAAQ,OAAO,SAAS,KAAK;EAC3D,IAAI,OAAO,MAAM,KAAK,CAAC,SAAS,KAAK,CAAC;CACxC;CACA,OAAO;AACT"}
@@ -0,0 +1,39 @@
1
+ import { SceneGraph } from "../graph.js";
2
+ import { SceneNode } from "../types.js";
3
+ import { VariationSet } from "./schema.js";
4
+ //#region src/variations/model.d.ts
5
+ /** A set of variations as the document holds it now. */
6
+ interface VariationSetView {
7
+ /** The section holding the versions, which carries the set's mark. */
8
+ section: SceneNode;
9
+ set: VariationSet;
10
+ /** The layer the versions are variations of, or null when it is gone. */
11
+ original: SceneNode | null;
12
+ /** The section's children, in their order. */
13
+ versions: SceneNode[];
14
+ }
15
+ /** The set a section marks, or null when the layer is not a section or carries none. */
16
+ declare function readVariationSet(node: Pick<SceneNode, 'type' | 'pluginData'>): VariationSet | null;
17
+ /** The section's plugin data with its mark replaced by `set`, or removed when it is null. */
18
+ declare function withVariationSet(node: Pick<SceneNode, 'pluginData'>, set: VariationSet | null): SceneNode['pluginData'];
19
+ /** The set a layer belongs to: the marked section itself, one of its versions, or a layer inside one. */
20
+ declare function variationSetOf(graph: SceneGraph, nodeId: string): VariationSetView | null;
21
+ /** The version of `view` that holds `nodeId`, or the version itself; null outside its versions. */
22
+ declare function versionOf(graph: SceneGraph, view: VariationSetView, nodeId: string): SceneNode | null;
23
+ /** The sets on a page; they sit on the page itself, beside the layers they vary. */
24
+ declare function variationSetsOnPage(graph: SceneGraph, pageId: string): VariationSetView[];
25
+ /** The set whose versions vary `originalId`, if there is one on its page. */
26
+ declare function variationSetForOriginal(graph: SceneGraph, originalId: string): VariationSetView | null;
27
+ /**
28
+ * A short hash of what a layer and its layers look like at a glance: their types, names, boxes,
29
+ * visibility, opacity, text, and how many fills and children they have. The layer's own position
30
+ * is left out, so moving it, or its auto layout parent placing it, is no change. It walks the
31
+ * whole subtree, so callers compute it when they show it rather than on every edit; it changes
32
+ * with most edits, which is all a "changed since" notice needs, and is not a full comparison.
33
+ */
34
+ declare function variationFingerprint(graph: SceneGraph, nodeId: string): string;
35
+ /** Whether the set's original looks different from when its versions were made. */
36
+ declare function originalChangedSince(graph: SceneGraph, view: VariationSetView): boolean;
37
+ //#endregion
38
+ export { VariationSetView, originalChangedSince, readVariationSet, variationFingerprint, variationSetForOriginal, variationSetOf, variationSetsOnPage, versionOf, withVariationSet };
39
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","names":[],"sources":["../../src/variations/model.ts"],"mappings":";;;;;UAOiB;;EAEf,SAAS;EACT,KAAK;;EAEL,UAAU;;EAEV,UAAU;;;iBAII,iBACd,MAAM,KAAK,oCACV;;iBAMa,iBACd,MAAM,KAAK,0BACX,KAAK,sBACJ;;iBAsBa,eAAe,OAAO,YAAY,iBAAiB;;iBAMnD,UACd,OAAO,YACP,MAAM,kBACN,iBACC;;iBAKa,oBAAoB,OAAO,YAAY,iBAAiB;;iBAKxD,wBACd,OAAO,YACP,qBACC;;;;;;;;iBAwBa,qBAAqB,OAAO,YAAY;;iBA6BxC,qBAAqB,OAAO,YAAY,MAAM"}
@@ -0,0 +1,90 @@
1
+ import { readPluginData, withPluginData } from "../plugin-data/field.js";
2
+ import { PAIRDRAW_PLUGIN_DATA } from "../plugin-data/fields.js";
3
+ //#region src/variations/model.ts
4
+ /** The set a section marks, or null when the layer is not a section or carries none. */
5
+ function readVariationSet(node) {
6
+ if (node.type !== "SECTION") return null;
7
+ return readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.variationSet) ?? null;
8
+ }
9
+ /** The section's plugin data with its mark replaced by `set`, or removed when it is null. */
10
+ function withVariationSet(node, set) {
11
+ return withPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.variationSet, set ?? void 0);
12
+ }
13
+ function viewOf(graph, section) {
14
+ const set = readVariationSet(section);
15
+ if (!set) return null;
16
+ const original = graph.getNode(set.originalId) ?? null;
17
+ return {
18
+ section,
19
+ set,
20
+ original: original !== null && original.type !== "CANVAS" && graph.pageOf(original.id) !== null && !graph.isDescendant(original.id, section.id) ? original : null,
21
+ versions: graph.getChildren(section.id)
22
+ };
23
+ }
24
+ /** The set a layer belongs to: the marked section itself, one of its versions, or a layer inside one. */
25
+ function variationSetOf(graph, nodeId) {
26
+ const section = graph.closest(nodeId, (node) => readVariationSet(node) !== null);
27
+ return section ? viewOf(graph, section) : null;
28
+ }
29
+ /** The version of `view` that holds `nodeId`, or the version itself; null outside its versions. */
30
+ function versionOf(graph, view, nodeId) {
31
+ return graph.closest(nodeId, (node) => node.parentId === view.section.id) ?? null;
32
+ }
33
+ /** The sets on a page; they sit on the page itself, beside the layers they vary. */
34
+ function variationSetsOnPage(graph, pageId) {
35
+ return graph.getChildren(pageId).flatMap((node) => viewOf(graph, node) ?? []);
36
+ }
37
+ /** The set whose versions vary `originalId`, if there is one on its page. */
38
+ function variationSetForOriginal(graph, originalId) {
39
+ const pageId = graph.pageOf(originalId);
40
+ if (!pageId) return null;
41
+ return variationSetsOnPage(graph, pageId).find((view) => view.original?.id === originalId) ?? null;
42
+ }
43
+ const FNV_OFFSET = 2166136261;
44
+ const FNV_PRIME = 16777619;
45
+ function hashText(hash, text) {
46
+ let next = hash;
47
+ for (let index = 0; index < text.length; index++) next = Math.imul(next ^ text.charCodeAt(index), FNV_PRIME) >>> 0;
48
+ return next;
49
+ }
50
+ /**
51
+ * A short hash of what a layer and its layers look like at a glance: their types, names, boxes,
52
+ * visibility, opacity, text, and how many fills and children they have. The layer's own position
53
+ * is left out, so moving it, or its auto layout parent placing it, is no change. It walks the
54
+ * whole subtree, so callers compute it when they show it rather than on every edit; it changes
55
+ * with most edits, which is all a "changed since" notice needs, and is not a full comparison.
56
+ */
57
+ function variationFingerprint(graph, nodeId) {
58
+ let hash = FNV_OFFSET;
59
+ const pending = [nodeId];
60
+ for (let id = pending.pop(); id !== void 0; id = pending.pop()) {
61
+ const node = graph.getNode(id);
62
+ if (!node) continue;
63
+ hash = hashText(hash, [
64
+ node.type,
65
+ node.name,
66
+ id === nodeId ? "" : node.x,
67
+ id === nodeId ? "" : node.y,
68
+ node.width,
69
+ node.height,
70
+ node.rotation,
71
+ node.visible,
72
+ node.opacity,
73
+ node.text,
74
+ node.fills.length,
75
+ node.childIds.length
76
+ ].join("\0"));
77
+ pending.push(...node.childIds);
78
+ }
79
+ return hash.toString(16).padStart(8, "0");
80
+ }
81
+ /** Whether the set's original looks different from when its versions were made. */
82
+ function originalChangedSince(graph, view) {
83
+ const { original, set } = view;
84
+ if (!original || set.originalFingerprint === void 0) return false;
85
+ return variationFingerprint(graph, original.id) !== set.originalFingerprint;
86
+ }
87
+ //#endregion
88
+ export { originalChangedSince, readVariationSet, variationFingerprint, variationSetForOriginal, variationSetOf, variationSetsOnPage, versionOf, withVariationSet };
89
+
90
+ //# sourceMappingURL=model.js.map