@pairdraw/scene-graph 0.16.1 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +8 -3
- package/dist/checkpoint.js.map +1 -1
- package/dist/color/index.d.ts.map +1 -1
- package/dist/color/index.js +3 -3
- package/dist/color/index.js.map +1 -1
- package/dist/color/management.d.ts.map +1 -1
- package/dist/color/management.js +4 -2
- package/dist/color/management.js.map +1 -1
- package/dist/coordinate.d.ts.map +1 -1
- package/dist/coordinate.js +3 -1
- package/dist/coordinate.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +1 -0
- package/dist/copy.js.map +1 -1
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +2 -2
- package/dist/css/values.js.map +1 -1
- package/dist/geometry.d.ts +14 -7
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +130 -26
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +7 -3
- package/dist/graph.js.map +1 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +100 -8
- package/dist/hit-test.js.map +1 -1
- package/dist/instances/content-size.js +1 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +4 -1
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/sync.js +4 -3
- package/dist/instances/sync.js.map +1 -1
- package/dist/layout/index.js +1 -1
- package/dist/resize.d.ts +4 -1
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +18 -12
- package/dist/resize.js.map +1 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +3 -1
- package/dist/scaling/node.js.map +1 -1
- package/dist/scaling/tree.d.ts.map +1 -1
- package/dist/scaling/tree.js +8 -5
- package/dist/scaling/tree.js.map +1 -1
- package/dist/slots/authoring.js +3 -6
- package/dist/slots/authoring.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +15 -25
- package/dist/slots/content.js.map +1 -1
- package/dist/slots/frames.js +1 -2
- package/dist/slots/frames.js.map +1 -1
- package/dist/snap.d.ts.map +1 -1
- package/dist/snap.js +12 -4
- package/dist/snap.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +2 -1
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +3 -2
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +2 -1
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +6 -2
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/index.d.ts +2 -1
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +23 -5
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/units.d.ts +31 -0
- package/dist/variables/units.d.ts.map +1 -0
- package/dist/variables/units.js +79 -4
- package/dist/variables/units.js.map +1 -1
- package/package.json +1 -1
- package/src/checkpoint.ts +8 -2
- package/src/color/index.ts +3 -6
- package/src/color/management.ts +8 -2
- package/src/coordinate.ts +4 -1
- package/src/copy.ts +2 -0
- package/src/css/values.ts +3 -2
- package/src/geometry.ts +147 -24
- package/src/graph.ts +9 -3
- package/src/hit-test.ts +138 -16
- package/src/instances/index.ts +5 -1
- package/src/instances/sync.ts +5 -3
- package/src/resize.ts +40 -20
- package/src/scaling/node.ts +3 -1
- package/src/scaling/tree.ts +3 -2
- package/src/slots/authoring.ts +7 -7
- package/src/slots/content.ts +13 -19
- package/src/slots/frames.ts +3 -3
- package/src/snap.ts +14 -4
- package/src/types.ts +5 -0
- package/src/undo.ts +3 -2
- package/src/variables/bindings.ts +6 -2
- package/src/variables/index.ts +29 -6
- package/src/variables/units.ts +97 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","names":[],"sources":["../../src/slots/content.ts"],"sourcesContent":["import { isGeneratedFrame } from '../generated'\nimport type { SceneGraph } from '../graph'\nimport { getInstanceOverride, setInstanceOverride } from '../instances/overrides'\nimport { cloneChildrenWithMapping } from '../instances/sync'\nimport type { SceneNode } from '../types'\nimport { ownsSlotContent, slotPropertyId } from './frames'\n\n/**\n * Where layers may be added, moved, or removed under a parent:\n * - `free`: outside any instance, or inside a component definition;\n * - `slot`: inside a slot of an instance, whose content the instance owns or can claim;\n * - `locked`: anywhere else inside an instance, whose layers come from its component, or inside a\n * generated frame such as a sticky note, whose layers come from its template.\n */\nexport type SlotScope =\n | { kind: 'free' }\n | { kind: 'slot'; frame: SceneNode; instance: SceneNode; propertyId: string }\n | { kind: 'locked'; owner: SceneNode }\n\nfunction
|
|
1
|
+
{"version":3,"file":"content.js","names":[],"sources":["../../src/slots/content.ts"],"sourcesContent":["import { isGeneratedFrame } from '../generated'\nimport type { SceneGraph } from '../graph'\nimport { getInstanceOverride, setInstanceOverride } from '../instances/overrides'\nimport { cloneChildrenWithMapping } from '../instances/sync'\nimport type { SceneNode } from '../types'\nimport { ownsSlotContent, slotPropertyId } from './frames'\n\n/**\n * Where layers may be added, moved, or removed under a parent:\n * - `free`: outside any instance, or inside a component definition;\n * - `slot`: inside a slot of an instance, whose content the instance owns or can claim;\n * - `locked`: anywhere else inside an instance, whose layers come from its component, or inside a\n * generated frame such as a sticky note, whose layers come from its template.\n */\nexport type SlotScope =\n | { kind: 'free' }\n | { kind: 'slot'; frame: SceneNode; instance: SceneNode; propertyId: string }\n | { kind: 'locked'; owner: SceneNode }\n\nfunction nearestInstance(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n return node.parentId\n ? graph.closest(node.parentId, (current) => current.type === 'INSTANCE')\n : undefined\n}\n\nexport function slotScope(graph: SceneGraph, parentId: string): SlotScope {\n const owner = graph.closest(\n parentId,\n (current) =>\n !!slotPropertyId(current) || current.type === 'INSTANCE' || isGeneratedFrame(current)\n )\n if (!owner) return { kind: 'free' }\n const propertyId = slotPropertyId(owner)\n if (!propertyId) return { kind: 'locked', owner }\n const instance = nearestInstance(graph, owner)\n return instance ? { kind: 'slot', frame: owner, instance, propertyId } : { kind: 'free' }\n}\n\n/** Every layer below `node`; `enterInstances` also walks the layers of nested instances. */\nfunction descendants(graph: SceneGraph, node: SceneNode, enterInstances: boolean): SceneNode[] {\n const result: SceneNode[] = []\n const visit = (parent: SceneNode): void => {\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n result.push(child)\n if (enterInstances || child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(node)\n return result\n}\n\n/**\n * Make the instance own its slot's content, as Figma does on the first edit: the layers\n * stay where they are, but stop following the component. Overrides the instance held for\n * them become their own values, or move to the nested instance they belong to.\n */\nexport function claimSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n if (ownsSlotContent(graph, frame, propertyId)) return\n const overrides = instance.instanceOverrides\n for (const node of descendants(graph, frame, false)) {\n overrides.descendants.delete(node.id)\n if (node.type !== 'INSTANCE') {\n graph.updateNode(node.id, { componentId: null })\n continue\n }\n // A nested instance keeps the overrides its former owner applied inside it.\n for (const inner of descendants(graph, node, true)) {\n const fields = overrides.descendants.get(inner.id)\n if (!fields) continue\n for (const [field, value] of fields)\n if (field !== 'sourceComponentId')\n setInstanceOverride(node.instanceOverrides, node.id, inner.id, field, value)\n overrides.descendants.delete(inner.id)\n }\n graph.updateNode(node.id, { instanceOverrides: node.instanceOverrides })\n }\n graph.updateNode(instance.id, {\n instanceOverrides: overrides,\n componentPropertyAssignments: { ...instance.componentPropertyAssignments, [propertyId]: '' }\n })\n}\n\n/** The component layer an instance layer was cloned from. */\nfunction componentSource(instance: SceneNode, node: SceneNode): string | null {\n const mapped = getInstanceOverride(\n instance.instanceOverrides,\n instance.id,\n node.id,\n 'sourceComponentId'\n )\n return typeof mapped === 'string' ? mapped : node.componentId\n}\n\n/** Return the slot to its component's content: the instance stops owning it. */\nexport function resetSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n for (const childId of Array.from(frame.childIds)) graph.deleteNode(childId)\n const assignments = { ...instance.componentPropertyAssignments }\n Reflect.deleteProperty(assignments, propertyId)\n graph.updateNode(instance.id, { componentPropertyAssignments: assignments })\n const source = componentSource(instance, frame)\n if (source && graph.nodes.has(source)) cloneChildrenWithMapping(graph, source, frame.id)\n}\n\n/** Remove everything from the slot; the instance keeps owning it, now empty. */\nexport function clearSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n claimSlotContent(graph, scope)\n for (const childId of Array.from(scope.frame.childIds)) graph.deleteNode(childId)\n}\n"],"mappings":";;;;;AAmBA,SAAS,gBAAgB,OAAmB,MAAwC;CAClF,OAAO,KAAK,WACR,MAAM,QAAQ,KAAK,WAAW,YAAY,QAAQ,SAAS,UAAU,IACrE,KAAA;AACN;AAEA,SAAgB,UAAU,OAAmB,UAA6B;CACxE,MAAM,QAAQ,MAAM,QAClB,WACC,YACC,CAAC,CAAC,eAAe,OAAO,KAAK,QAAQ,SAAS,cAAc,iBAAiB,OAAO,CACxF;CACA,IAAI,CAAC,OAAO,OAAO,EAAE,MAAM,OAAO;CAClC,MAAM,aAAa,eAAe,KAAK;CACvC,IAAI,CAAC,YAAY,OAAO;EAAE,MAAM;EAAU;CAAM;CAChD,MAAM,WAAW,gBAAgB,OAAO,KAAK;CAC7C,OAAO,WAAW;EAAE,MAAM;EAAQ,OAAO;EAAO;EAAU;CAAW,IAAI,EAAE,MAAM,OAAO;AAC1F;;AAGA,SAAS,YAAY,OAAmB,MAAiB,gBAAsC;CAC7F,MAAM,SAAsB,CAAC;CAC7B,MAAM,SAAS,WAA4B;EACzC,KAAK,MAAM,WAAW,OAAO,UAAU;GACrC,MAAM,QAAQ,MAAM,MAAM,IAAI,OAAO;GACrC,IAAI,CAAC,OAAO;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AE,GAAG,SAAS,6BAA6B;CAC/D,QAAQ,eAAe,aAAa,UAAU;CAC9C,MAAM,WAAW,SAAS,IAAI,EAAE,8BAA8B,YAAY,CAAC;CAC3E,MAAM,SAAS,gBAAgB,UAAU,KAAK;CAC9C,IAAI,UAAU,MAAM,MAAM,IAAI,MAAM,GAAG,yBAAyB,OAAO,QAAQ,MAAM,EAAE;AACzF;;AAGA,SAAgB,iBACd,OACA,OACM;CACN,iBAAiB,OAAO,KAAK;CAC7B,KAAK,MAAM,WAAW,MAAM,KAAK,MAAM,MAAM,QAAQ,GAAG,MAAM,WAAW,OAAO;AAClF"}
|
package/dist/slots/frames.js
CHANGED
|
@@ -10,8 +10,7 @@ function slotPropertyId(node) {
|
|
|
10
10
|
*/
|
|
11
11
|
function ownsSlotContent(graph, node, propertyId = slotPropertyId(node)) {
|
|
12
12
|
if (!propertyId) return false;
|
|
13
|
-
|
|
14
|
-
while (owner && owner.type !== "INSTANCE") owner = owner.parentId ? graph.nodes.get(owner.parentId) : void 0;
|
|
13
|
+
const owner = node.parentId ? graph.closest(node.parentId, (current) => current.type === "INSTANCE") : void 0;
|
|
15
14
|
return !!owner && Object.hasOwn(owner.componentPropertyAssignments, propertyId);
|
|
16
15
|
}
|
|
17
16
|
/** The name of a slot property as the instance's component (or the component's set) defines it. */
|
package/dist/slots/frames.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frames.js","names":[],"sources":["../../src/slots/frames.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { instanceMainComponent } from '../instances/main-component'\nimport type { SceneNode } from '../types'\n\n/** The slot property a frame holds the content of, if it is a slot. */\nexport function slotPropertyId(node: SceneNode): string | undefined {\n return node.componentPropertyReferences.find((reference) => reference.field === 'SLOT_CONTENT')\n ?.propertyId\n}\n\n/**\n * Whether this slot frame's children belong to its instance rather than its component: the\n * nearest enclosing instance assigns the slot. Such content is never synced from the component.\n */\nexport function ownsSlotContent(\n graph: SceneGraph,\n node: SceneNode,\n propertyId = slotPropertyId(node)\n): boolean {\n if (!propertyId) return false\n
|
|
1
|
+
{"version":3,"file":"frames.js","names":[],"sources":["../../src/slots/frames.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { instanceMainComponent } from '../instances/main-component'\nimport type { SceneNode } from '../types'\n\n/** The slot property a frame holds the content of, if it is a slot. */\nexport function slotPropertyId(node: SceneNode): string | undefined {\n return node.componentPropertyReferences.find((reference) => reference.field === 'SLOT_CONTENT')\n ?.propertyId\n}\n\n/**\n * Whether this slot frame's children belong to its instance rather than its component: the\n * nearest enclosing instance assigns the slot. Such content is never synced from the component.\n */\nexport function ownsSlotContent(\n graph: SceneGraph,\n node: SceneNode,\n propertyId = slotPropertyId(node)\n): boolean {\n if (!propertyId) return false\n const owner = node.parentId\n ? graph.closest(node.parentId, (current) => current.type === 'INSTANCE')\n : undefined\n return !!owner && Object.hasOwn(owner.componentPropertyAssignments, propertyId)\n}\n\n/** The name of a slot property as the instance's component (or the component's set) defines it. */\nfunction slotName(graph: SceneGraph, instance: SceneNode, propertyId: string) {\n const component = instanceMainComponent(graph, instance)\n const set = component?.parentId ? graph.nodes.get(component.parentId) : undefined\n return [component, set]\n .flatMap((node) => node?.componentPropertyDefinitions ?? [])\n .find((definition) => definition.id === propertyId && definition.type === 'SLOT')?.name\n}\n\n/** An instance's slot frames, without entering nested instances, whose slots are their own. */\nexport function instanceSlotFrames(graph: SceneGraph, instance: SceneNode): SceneNode[] {\n const frames: SceneNode[] = []\n const visit = (node: SceneNode): void => {\n for (const childId of node.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n if (slotPropertyId(child)) frames.push(child)\n else if (child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(instance)\n return frames\n}\n\n/** One slot's owned content, parked while the instance it belongs to is rebuilt. */\ninterface ParkedSlot {\n /** Names of the nested instances leading to the slot's owner; empty for the instance itself. */\n path: string[]\n /** The slot property's name, which the replacement must share. */\n name: string\n /** Content layer ids, in layer order. */\n content: string[]\n}\n\n/** Owned slot content parked under an instance while its component changes. */\nexport interface ParkedSlotContent {\n slots: ParkedSlot[]\n /** The instance's own slot assignments the content was parked from. */\n propertyIds: string[]\n}\n\n/** Instances directly inside this one: not inside another nested instance or a slot. */\nfunction nestedInstances(graph: SceneGraph, owner: SceneNode): SceneNode[] {\n const found: SceneNode[] = []\n const visit = (node: SceneNode): void => {\n for (const childId of node.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || slotPropertyId(child)) continue\n if (child.type === 'INSTANCE') found.push(child)\n else visit(child)\n }\n }\n visit(owner)\n return found\n}\n\n/** The nested instance a name path leads to from `root`, matched by layer name as Figma does. */\nfunction instanceAtPath(\n graph: SceneGraph,\n root: SceneNode,\n path: readonly string[]\n): SceneNode | undefined {\n let current: SceneNode | undefined = root\n for (const name of path) {\n current = current && nestedInstances(graph, current).find((node) => node.name === name)\n }\n return current\n}\n\n/**\n * Park the slot content an instance and the instances nested in it own, by slot name and the\n * nested instance's name path, directly under the instance, so its component can be replaced.\n * Figma keeps that content when a variant switch or swap leads to slots of the same names.\n */\nexport function detachOwnedSlotContent(graph: SceneGraph, instance: SceneNode): ParkedSlotContent {\n const parked: ParkedSlotContent = { slots: [], propertyIds: [] }\n const visit = (owner: SceneNode, path: string[]): void => {\n for (const nested of nestedInstances(graph, owner)) visit(nested, [...path, nested.name])\n for (const frame of instanceSlotFrames(graph, owner)) {\n const propertyId = slotPropertyId(frame)\n if (!propertyId || !Object.hasOwn(owner.componentPropertyAssignments, propertyId)) continue\n if (owner.id === instance.id) parked.propertyIds.push(propertyId)\n const name = slotName(graph, owner, propertyId)\n const key = [...path, name].join('\\u0000')\n if (!name || parked.slots.some((slot) => [...slot.path, slot.name].join('\\u0000') === key))\n continue\n const content = [...frame.childIds]\n for (const id of content) graph.insertChildAt(id, instance.id, instance.childIds.length)\n parked.slots.push({ path, name, content })\n }\n }\n visit(instance, [])\n return parked\n}\n\n/** Move parked content into the slots of the same names and paths, and reassign them. */\nexport function restoreOwnedSlotContent(\n graph: SceneGraph,\n instance: SceneNode,\n parked: ParkedSlotContent\n): void {\n if (parked.slots.length === 0 && parked.propertyIds.length === 0) return\n graph.updateNode(instance.id, {\n componentPropertyAssignments: Object.fromEntries(\n Object.entries(instance.componentPropertyAssignments).filter(\n ([id]) => !parked.propertyIds.includes(id)\n )\n )\n })\n for (const slot of parked.slots) {\n const owner = instanceAtPath(graph, instance, slot.path)\n const frame =\n owner &&\n instanceSlotFrames(graph, owner).find((candidate) => {\n const propertyId = slotPropertyId(candidate)\n return !!propertyId && slotName(graph, owner, propertyId) === slot.name\n })\n const propertyId = frame && slotPropertyId(frame)\n if (\n !owner ||\n !frame ||\n !propertyId ||\n Object.hasOwn(owner.componentPropertyAssignments, propertyId)\n ) {\n for (const id of slot.content) graph.deleteNode(id)\n continue\n }\n for (const id of Array.from(frame.childIds)) graph.deleteNode(id)\n for (const [index, id] of slot.content.entries()) graph.insertChildAt(id, frame.id, index)\n graph.updateNode(owner.id, {\n componentPropertyAssignments: { ...owner.componentPropertyAssignments, [propertyId]: '' }\n })\n }\n}\n"],"mappings":";;;AAKA,SAAgB,eAAe,MAAqC;CAClE,OAAO,KAAK,4BAA4B,MAAM,cAAc,UAAU,UAAU,cAAc,CAAC,EAC3F;AACN;;;;;AAMA,SAAgB,gBACd,OACA,MACA,aAAa,eAAe,IAAI,GACvB;CACT,IAAI,CAAC,YAAY,OAAO;CACxB,MAAM,QAAQ,KAAK,WACf,MAAM,QAAQ,KAAK,WAAW,YAAY,QAAQ,SAAS,UAAU,IACrE,KAAA;CACJ,OAAO,CAAC,CAAC,SAAS,OAAO,OAAO,MAAM,8BAA8B,UAAU;AAChF;;AAGA,SAAS,SAAS,OAAmB,UAAqB,YAAoB;CAC5E,MAAM,YAAY,sBAAsB,OAAO,QAAQ;CAEvD,OAAO,CAAC,WADI,WAAW,WAAW,MAAM,MAAM,IAAI,UAAU,QAAQ,IAAI,KAAA,CAClD,CAAC,CACpB,SAAS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AO,OAAO,MAAM,8BAA8B,UAAU,GAC5D;GACA,KAAK,MAAM,MAAM,KAAK,SAAS,MAAM,WAAW,EAAE;GAClD;EACF;EACA,KAAK,MAAM,MAAM,MAAM,KAAK,MAAM,QAAQ,GAAG,MAAM,WAAW,EAAE;EAChE,KAAK,MAAM,CAAC,OAAO,OAAO,KAAK,QAAQ,QAAQ,GAAG,MAAM,cAAc,IAAI,MAAM,IAAI,KAAK;EACzF,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B;GAAE,GAAG,MAAM;IAA+B,aAAa;EAAG,EAC1F,CAAC;CACH;AACF"}
|
package/dist/snap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snap.d.ts","names":[],"sources":["../src/snap.ts"],"mappings":";;;UAMiB;EACf;EACA;EACA;EACA;;EAEA;;;;;;EAMA;;UAGe;EACf;EACA;EACA,QAAQ;;
|
|
1
|
+
{"version":3,"file":"snap.d.ts","names":[],"sources":["../src/snap.ts"],"mappings":";;;UAMiB;EACf;EACA;EACA;EACA;;EAEA;;;;;;EAMA;;UAGe;EACf;EACA;EACA,QAAQ;;iBAkBM,YACd,WAAW,aACX,cAAc,MACd,UAAU,aACV,qBACC;iBAqFa,uBAAuB,OAAO,cAAc;;UAoB3C;EACf;EACA;EACA;EACA;;;;;;;UAQe;WACN,YAAY;WACZ,YAAY;;UASN;;EAEf;EACA;;;iBA2Bc,eACd,WAAW,aACX,mBAAmB,cAClB;;;;;;iBA4Fa,mBACd,SAAS,gBACT,cAAc,MACd,qBACC;;;;;iBAiDa,qBAAqB,SAAS,gBAAgB,cAAc,OAAO"}
|
package/dist/snap.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getNodeWorldBounds } from "./coordinate.js";
|
|
2
2
|
//#region src/snap.ts
|
|
3
3
|
const DEFAULT_SNAP_THRESHOLD = 5;
|
|
4
4
|
function getEdges(node) {
|
|
5
|
-
|
|
5
|
+
const box = getNodeWorldBounds(node);
|
|
6
|
+
return {
|
|
7
|
+
left: box.x,
|
|
8
|
+
right: box.x + box.width,
|
|
9
|
+
top: box.y,
|
|
10
|
+
bottom: box.y + box.height,
|
|
11
|
+
centerX: box.x + box.width / 2,
|
|
12
|
+
centerY: box.y + box.height / 2
|
|
13
|
+
};
|
|
6
14
|
}
|
|
7
15
|
function computeSnap(movingIds, movingBounds, allNodes, threshold = DEFAULT_SNAP_THRESHOLD) {
|
|
8
16
|
const targets = allNodes.filter((n) => !movingIds.has(n.id));
|
|
@@ -39,7 +47,7 @@ function computeSnap(movingIds, movingBounds, allNodes, threshold = DEFAULT_SNAP
|
|
|
39
47
|
guides.length = guides.filter((g) => g.axis === "y").length ? guides.length : guides.length;
|
|
40
48
|
for (let i = guides.length - 1; i >= 0; i--) if (guides[i].axis === "x") guides.splice(i, 1);
|
|
41
49
|
}
|
|
42
|
-
if (
|
|
50
|
+
if (d === bestDx) {
|
|
43
51
|
const minY = Math.min(m.top, t.top);
|
|
44
52
|
const maxY = Math.max(m.bottom, t.bottom);
|
|
45
53
|
guides.push({
|
|
@@ -65,7 +73,7 @@ function computeSnap(movingIds, movingBounds, allNodes, threshold = DEFAULT_SNAP
|
|
|
65
73
|
for (let i = guides.length - 1; i >= 0; i--) if (guides[i].axis === "y") guides.splice(i, 1);
|
|
66
74
|
bestDy = d;
|
|
67
75
|
}
|
|
68
|
-
if (
|
|
76
|
+
if (d === bestDy) {
|
|
69
77
|
const minX = Math.min(m.left, t.left);
|
|
70
78
|
const maxX = Math.max(m.right, t.right);
|
|
71
79
|
guides.push({
|
package/dist/snap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snap.js","names":[],"sources":["../src/snap.ts"],"sourcesContent":["import { rotatedBBox } from './geometry'\nimport type { Rect } from './primitives'\nimport type { SceneNode } from './types'\n\nconst DEFAULT_SNAP_THRESHOLD = 5\n\nexport interface SnapGuide {\n axis: 'x' | 'y'\n position: number\n from: number\n to: number\n /** Points along the guide that lined up, marked with a cross: a guide through path vertices. */\n marks?: number[]\n /**\n * An equal-spacing indicator instead of an alignment line: the gap between two neighbours, from\n * `from` to `to` on the line at `position`. A gap along x is a horizontal line, so its `axis` is\n * `'y'`, as for any horizontal guide; the renderer caps both ends and labels the gap's size.\n */\n spacing?: boolean\n}\n\nexport interface SnapResult {\n dx: number\n dy: number\n guides: SnapGuide[]\n}\n\nfunction getEdges(node: SceneNode) {\n return rotatedBBox(node.x, node.y, node.width, node.height, node.rotation)\n}\n\n// Pairwise edge/center matching intentionally keeps both axes in one pass.\n// eslint-disable-next-line complexity\nexport function computeSnap(\n movingIds: Set<string>,\n movingBounds: Rect,\n allNodes: SceneNode[],\n threshold = DEFAULT_SNAP_THRESHOLD\n): SnapResult {\n const targets = allNodes.filter((n) => !movingIds.has(n.id))\n if (targets.length === 0) return { dx: 0, dy: 0, guides: [] }\n\n const m = {\n left: movingBounds.x,\n right: movingBounds.x + movingBounds.width,\n centerX: movingBounds.x + movingBounds.width / 2,\n top: movingBounds.y,\n bottom: movingBounds.y + movingBounds.height,\n centerY: movingBounds.y + movingBounds.height / 2\n }\n\n let bestDx = Infinity\n let bestDy = Infinity\n const guides: SnapGuide[] = []\n\n for (const target of targets) {\n const t = getEdges(target)\n\n // X-axis snapping: left-to-left, left-to-right, right-to-left, right-to-right, center-to-center\n const xPairs: [number, number][] = [\n [m.left, t.left],\n [m.left, t.right],\n [m.right, t.left],\n [m.right, t.right],\n [m.centerX, t.centerX]\n ]\n\n for (const [mVal, tVal] of xPairs) {\n const d = tVal - mVal\n if (Math.abs(d) < threshold && Math.abs(d) <= Math.abs(bestDx)) {\n if (Math.abs(d) < Math.abs(bestDx)) {\n bestDx = d\n guides.length = guides.filter((g) => g.axis === 'y').length\n ? guides.length\n : guides.length\n // Remove old x guides if we found a closer snap\n for (let i = guides.length - 1; i >= 0; i--) {\n if (guides[i].axis === 'x') guides.splice(i, 1)\n }\n }\n if (Math.abs(d) === Math.abs(bestDx)) {\n const minY = Math.min(m.top, t.top)\n const maxY = Math.max(m.bottom, t.bottom)\n guides.push({ axis: 'x', position: tVal, from: minY, to: maxY })\n }\n }\n }\n\n // Y-axis snapping\n const yPairs: [number, number][] = [\n [m.top, t.top],\n [m.top, t.bottom],\n [m.bottom, t.top],\n [m.bottom, t.bottom],\n [m.centerY, t.centerY]\n ]\n\n for (const [mVal, tVal] of yPairs) {\n const d = tVal - mVal\n if (Math.abs(d) < threshold && Math.abs(d) <= Math.abs(bestDy)) {\n if (Math.abs(d) < Math.abs(bestDy)) {\n for (let i = guides.length - 1; i >= 0; i--) {\n if (guides[i].axis === 'y') guides.splice(i, 1)\n }\n bestDy = d\n }\n if (Math.abs(d) === Math.abs(bestDy)) {\n const minX = Math.min(m.left, t.left)\n const maxX = Math.max(m.right, t.right)\n guides.push({ axis: 'y', position: tVal, from: minX, to: maxX })\n }\n }\n }\n }\n\n return {\n dx: Math.abs(bestDx) <= threshold ? bestDx : 0,\n dy: Math.abs(bestDy) <= threshold ? bestDy : 0,\n guides\n }\n}\n\nexport function computeSelectionBounds(nodes: SceneNode[]): Rect | null {\n if (nodes.length === 0) return null\n let minX = Infinity\n let minY = Infinity\n let maxX = -Infinity\n let maxY = -Infinity\n for (const n of nodes) {\n const edges = getEdges(n)\n minX = Math.min(minX, edges.left)\n minY = Math.min(minY, edges.top)\n maxX = Math.max(maxX, edges.right)\n maxY = Math.max(maxY, edges.bottom)\n }\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY }\n}\n\n/** Gaps this close count as equal, so float noise from world transforms does not hide a match. */\nconst SPACING_MATCH_TOLERANCE = 0.01\n\n/** A layer's extent along one axis (`start`..`end`) and across it (`crossStart`..`crossEnd`). */\nexport interface SpacingSpan {\n start: number\n end: number\n crossStart: number\n crossEnd: number\n}\n\n/**\n * The layers equal spacing measures against, along each axis and sorted by start. Build them once\n * with {@link spacingTargets} and share them between {@link computeSpacingSnap} and\n * {@link computeSpacingGuides}, so one pointer move sorts the layers once.\n */\nexport interface SpacingTargets {\n readonly x: readonly SpacingSpan[]\n readonly y: readonly SpacingSpan[]\n}\n\ninterface SpacingPair {\n before: SpacingSpan\n after: SpacingSpan\n gap: number\n}\n\nexport interface SpacingSnapResult {\n /** The move that makes a gap along x equal to its neighbours', or `null` when none is near. */\n dx: number | null\n dy: number | null\n}\n\ntype Edges = Pick<ReturnType<typeof getEdges>, 'left' | 'right' | 'top' | 'bottom'>\ntype Axis = 'x' | 'y'\n\nfunction spanOf(edges: Edges, axis: Axis): SpacingSpan {\n return axis === 'x'\n ? { start: edges.left, end: edges.right, crossStart: edges.top, crossEnd: edges.bottom }\n : { start: edges.top, end: edges.bottom, crossStart: edges.left, crossEnd: edges.right }\n}\n\nfunction boundsSpan(bounds: Rect, axis: Axis): SpacingSpan {\n const edges = {\n left: bounds.x,\n right: bounds.x + bounds.width,\n top: bounds.y,\n bottom: bounds.y + bounds.height\n }\n return spanOf(edges, axis)\n}\n\nfunction crossOverlaps(a: SpacingSpan, b: SpacingSpan): boolean {\n return a.crossStart < b.crossEnd && a.crossEnd > b.crossStart\n}\n\n/** Every layer except the moving ones, as spans along each axis sorted by start. */\nexport function spacingTargets(\n movingIds: Set<string>,\n allNodes: readonly SceneNode[]\n): SpacingTargets {\n const x: SpacingSpan[] = []\n const y: SpacingSpan[] = []\n for (const node of allNodes) {\n if (movingIds.has(node.id)) continue\n const edges = getEdges(node)\n x.push(spanOf(edges, 'x'))\n y.push(spanOf(edges, 'y'))\n }\n const byStart = (a: SpacingSpan, b: SpacingSpan) => a.start - b.start\n return { x: x.sort(byStart), y: y.sort(byStart) }\n}\n\n/** The layers beside the moving one along an axis: those sharing some of its extent across it. */\nfunction rowOf(moving: SpacingSpan, sorted: readonly SpacingSpan[]): SpacingSpan[] {\n return sorted.filter((span) => crossOverlaps(span, moving))\n}\n\n/**\n * The gaps between neighbours in a row: stretches along the axis that no layer of the row covers,\n * each between the layer reaching furthest into it and the next layer, when the two share some\n * extent across the axis. A layer over another, such as a label on its button, therefore never\n * makes a gap across the button. A gap the moving layer sits in is not a gap between neighbours, so\n * it is left out. The row is sorted by start, so one sweep finds them all.\n */\nfunction neighbourPairs(row: readonly SpacingSpan[], moving: SpacingSpan): SpacingPair[] {\n const pairs: SpacingPair[] = []\n let frontier: SpacingSpan | null = null\n for (const span of row) {\n if (\n frontier &&\n span.start >= frontier.end &&\n crossOverlaps(span, frontier) &&\n !(moving.start < span.start && moving.end > frontier.end)\n ) {\n pairs.push({ before: frontier, after: span, gap: span.start - frontier.end })\n }\n if (!frontier || span.end > frontier.end) frontier = span\n }\n return pairs\n}\n\n/** The nearest layer before the moving one (ending at most `slack` into it), and after it. */\nfunction neighboursOf(\n row: readonly SpacingSpan[],\n moving: SpacingSpan,\n slack: number\n): { before: SpacingSpan | null; after: SpacingSpan | null } {\n let before: SpacingSpan | null = null\n let after: SpacingSpan | null = null\n for (const span of row) {\n if (span.start < moving.start && span.end <= moving.start + slack) {\n if (!before || span.end > before.end) before = span\n }\n if (span.end > moving.end && span.start >= moving.end - slack) {\n if (!after || span.start < after.start) after = span\n }\n }\n return { before, after }\n}\n\nfunction spacingDelta(\n moving: SpacingSpan,\n sorted: readonly SpacingSpan[],\n threshold: number\n): number | null {\n const row = rowOf(moving, sorted)\n const { before, after } = neighboursOf(row, moving, threshold)\n if (!before && !after) return null\n const size = moving.end - moving.start\n const starts: number[] = []\n if (before && after && after.start - before.end - size >= 0) {\n starts.push((before.end + after.start - size) / 2)\n }\n for (const pair of neighbourPairs(row, moving)) {\n if (before) starts.push(before.end + pair.gap)\n if (after) starts.push(after.start - pair.gap - size)\n }\n let best: number | null = null\n for (const start of starts) {\n const delta = start - moving.start\n if (Math.abs(delta) >= threshold) continue\n if (best === null || Math.abs(delta) < Math.abs(best)) best = delta\n }\n return best\n}\n\n/**\n * Figma's equal-spacing snap: on each axis, the move within `threshold` that centres the moving\n * bounds between their two neighbours, or leaves them as far from a neighbour as two other\n * neighbours in the same row are apart. Only layers sharing some extent across the axis count.\n */\nexport function computeSpacingSnap(\n targets: SpacingTargets,\n movingBounds: Rect,\n threshold = DEFAULT_SNAP_THRESHOLD\n): SpacingSnapResult {\n const delta = (axis: Axis) =>\n spacingDelta(boundsSpan(movingBounds, axis), targets[axis], threshold)\n return { dx: delta('x'), dy: delta('y') }\n}\n\nfunction gapGuide(before: SpacingSpan, after: SpacingSpan, axis: Axis): SnapGuide {\n const position =\n (Math.max(before.crossStart, after.crossStart) + Math.min(before.crossEnd, after.crossEnd)) / 2\n return {\n axis: axis === 'x' ? 'y' : 'x',\n position,\n from: before.end,\n to: after.start,\n spacing: true\n }\n}\n\nfunction sameGap(a: number, b: number): boolean {\n return Math.abs(a - b) < SPACING_MATCH_TOLERANCE\n}\n\nfunction axisSpacingGuides(\n movingBounds: Rect,\n sorted: readonly SpacingSpan[],\n axis: Axis\n): SnapGuide[] {\n const moving = boundsSpan(movingBounds, axis)\n const row = rowOf(moving, sorted)\n const { before, after } = neighboursOf(row, moving, SPACING_MATCH_TOLERANCE)\n const pairs = neighbourPairs(row, moving)\n const sides: SpacingPair[] = []\n if (before) sides.push({ before, after: moving, gap: moving.start - before.end })\n if (after) sides.push({ before: moving, after, gap: after.start - moving.end })\n const matched = sides.filter(\n (side) =>\n side.gap > SPACING_MATCH_TOLERANCE &&\n (sides.some((other) => other !== side && sameGap(other.gap, side.gap)) ||\n pairs.some((pair) => sameGap(pair.gap, side.gap)))\n )\n const gaps = matched.map((side) => side.gap)\n const shown = [...matched, ...pairs.filter((pair) => gaps.some((gap) => sameGap(pair.gap, gap)))]\n return shown.map((pair) => gapGuide(pair.before, pair.after, axis))\n}\n\n/**\n * The equal-spacing indicators for bounds where they are: every gap beside them that equals the gap\n * on their other side or a gap between two neighbours in the same row, and those neighbours' gaps.\n */\nexport function computeSpacingGuides(targets: SpacingTargets, movingBounds: Rect): SnapGuide[] {\n return [\n ...axisSpacingGuides(movingBounds, targets.x, 'x'),\n ...axisSpacingGuides(movingBounds, targets.y, 'y')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;CAC5C,MAAM,MAAM,MAAM,QAAQ,MAAM;CAChC,MAAM,EAAE,QAAQ,UAAU,aAAa,KAAK,QAAQ,uBAAuB;CAC3E,MAAM,QAAQ,eAAe,KAAK,MAAM;CACxC,MAAM,QAAuB,CAAC;CAC9B,IAAI,QAAQ,MAAM,KAAK;EAAE;EAAQ,OAAO;EAAQ,KAAK,OAAO,QAAQ,OAAO;CAAI,CAAC;CAChF,IAAI,OAAO,MAAM,KAAK;EAAE,QAAQ;EAAQ;EAAO,KAAK,MAAM,QAAQ,OAAO;CAAI,CAAC;CAC9E,MAAM,UAAU,MAAM,QACnB,SACC,KAAK,MAAM,4BACV,MAAM,MAAM,UAAU,UAAU,QAAQ,QAAQ,MAAM,KAAK,KAAK,GAAG,CAAC,KACnE,MAAM,MAAM,SAAS,QAAQ,KAAK,KAAK,KAAK,GAAG,CAAC,EACtD;CACA,MAAM,OAAO,QAAQ,KAAK,SAAS,KAAK,GAAG;CAE3C,OAAO,CADQ,GAAG,SAAS,GAAG,MAAM,QAAQ,SAAS,KAAK,MAAM,QAAQ,QAAQ,KAAK,KAAK,GAAG,CAAC,CAAC,CACpF,CAAC,CAAC,KAAK,SAAS,SAAS,KAAK,QAAQ,KAAK,OAAO,IAAI,CAAC;AACpE;;;;;AAMA,SAAgB,qBAAqB,SAAyB,cAAiC;CAC7F,OAAO,CACL,GAAG,kBAAkB,cAAc,QAAQ,GAAG,GAAG,GACjD,GAAG,kBAAkB,cAAc,QAAQ,GAAG,GAAG,CACnD;AACF"}
|
|
1
|
+
{"version":3,"file":"snap.js","names":[],"sources":["../src/snap.ts"],"sourcesContent":["import { getNodeWorldBounds } from './coordinate'\nimport type { Rect } from './primitives'\nimport type { SceneNode } from './types'\n\nconst DEFAULT_SNAP_THRESHOLD = 5\n\nexport interface SnapGuide {\n axis: 'x' | 'y'\n position: number\n from: number\n to: number\n /** Points along the guide that lined up, marked with a cross: a guide through path vertices. */\n marks?: number[]\n /**\n * An equal-spacing indicator instead of an alignment line: the gap between two neighbours, from\n * `from` to `to` on the line at `position`. A gap along x is a horizontal line, so its `axis` is\n * `'y'`, as for any horizontal guide; the renderer caps both ends and labels the gap's size.\n */\n spacing?: boolean\n}\n\nexport interface SnapResult {\n dx: number\n dy: number\n guides: SnapGuide[]\n}\n\n// A line turns around its start point and other layers around their centre, as they are drawn.\nfunction getEdges(node: SceneNode) {\n const box = getNodeWorldBounds(node)\n return {\n left: box.x,\n right: box.x + box.width,\n top: box.y,\n bottom: box.y + box.height,\n centerX: box.x + box.width / 2,\n centerY: box.y + box.height / 2\n }\n}\n\n// Pairwise edge/center matching intentionally keeps both axes in one pass.\n// eslint-disable-next-line complexity\nexport function computeSnap(\n movingIds: Set<string>,\n movingBounds: Rect,\n allNodes: SceneNode[],\n threshold = DEFAULT_SNAP_THRESHOLD\n): SnapResult {\n const targets = allNodes.filter((n) => !movingIds.has(n.id))\n if (targets.length === 0) return { dx: 0, dy: 0, guides: [] }\n\n const m = {\n left: movingBounds.x,\n right: movingBounds.x + movingBounds.width,\n centerX: movingBounds.x + movingBounds.width / 2,\n top: movingBounds.y,\n bottom: movingBounds.y + movingBounds.height,\n centerY: movingBounds.y + movingBounds.height / 2\n }\n\n let bestDx = Infinity\n let bestDy = Infinity\n const guides: SnapGuide[] = []\n\n for (const target of targets) {\n const t = getEdges(target)\n\n // X-axis snapping: left-to-left, left-to-right, right-to-left, right-to-right, center-to-center\n const xPairs: [number, number][] = [\n [m.left, t.left],\n [m.left, t.right],\n [m.right, t.left],\n [m.right, t.right],\n [m.centerX, t.centerX]\n ]\n\n for (const [mVal, tVal] of xPairs) {\n const d = tVal - mVal\n if (Math.abs(d) < threshold && Math.abs(d) <= Math.abs(bestDx)) {\n if (Math.abs(d) < Math.abs(bestDx)) {\n bestDx = d\n guides.length = guides.filter((g) => g.axis === 'y').length\n ? guides.length\n : guides.length\n // Remove old x guides if we found a closer snap\n for (let i = guides.length - 1; i >= 0; i--) {\n if (guides[i].axis === 'x') guides.splice(i, 1)\n }\n }\n // A tie in the other direction is not applied, so it draws no guide.\n if (d === bestDx) {\n const minY = Math.min(m.top, t.top)\n const maxY = Math.max(m.bottom, t.bottom)\n guides.push({ axis: 'x', position: tVal, from: minY, to: maxY })\n }\n }\n }\n\n // Y-axis snapping\n const yPairs: [number, number][] = [\n [m.top, t.top],\n [m.top, t.bottom],\n [m.bottom, t.top],\n [m.bottom, t.bottom],\n [m.centerY, t.centerY]\n ]\n\n for (const [mVal, tVal] of yPairs) {\n const d = tVal - mVal\n if (Math.abs(d) < threshold && Math.abs(d) <= Math.abs(bestDy)) {\n if (Math.abs(d) < Math.abs(bestDy)) {\n for (let i = guides.length - 1; i >= 0; i--) {\n if (guides[i].axis === 'y') guides.splice(i, 1)\n }\n bestDy = d\n }\n if (d === bestDy) {\n const minX = Math.min(m.left, t.left)\n const maxX = Math.max(m.right, t.right)\n guides.push({ axis: 'y', position: tVal, from: minX, to: maxX })\n }\n }\n }\n }\n\n return {\n dx: Math.abs(bestDx) <= threshold ? bestDx : 0,\n dy: Math.abs(bestDy) <= threshold ? bestDy : 0,\n guides\n }\n}\n\nexport function computeSelectionBounds(nodes: SceneNode[]): Rect | null {\n if (nodes.length === 0) return null\n let minX = Infinity\n let minY = Infinity\n let maxX = -Infinity\n let maxY = -Infinity\n for (const n of nodes) {\n const edges = getEdges(n)\n minX = Math.min(minX, edges.left)\n minY = Math.min(minY, edges.top)\n maxX = Math.max(maxX, edges.right)\n maxY = Math.max(maxY, edges.bottom)\n }\n return { x: minX, y: minY, width: maxX - minX, height: maxY - minY }\n}\n\n/** Gaps this close count as equal, so float noise from world transforms does not hide a match. */\nconst SPACING_MATCH_TOLERANCE = 0.01\n\n/** A layer's extent along one axis (`start`..`end`) and across it (`crossStart`..`crossEnd`). */\nexport interface SpacingSpan {\n start: number\n end: number\n crossStart: number\n crossEnd: number\n}\n\n/**\n * The layers equal spacing measures against, along each axis and sorted by start. Build them once\n * with {@link spacingTargets} and share them between {@link computeSpacingSnap} and\n * {@link computeSpacingGuides}, so one pointer move sorts the layers once.\n */\nexport interface SpacingTargets {\n readonly x: readonly SpacingSpan[]\n readonly y: readonly SpacingSpan[]\n}\n\ninterface SpacingPair {\n before: SpacingSpan\n after: SpacingSpan\n gap: number\n}\n\nexport interface SpacingSnapResult {\n /** The move that makes a gap along x equal to its neighbours', or `null` when none is near. */\n dx: number | null\n dy: number | null\n}\n\ntype Edges = Pick<ReturnType<typeof getEdges>, 'left' | 'right' | 'top' | 'bottom'>\ntype Axis = 'x' | 'y'\n\nfunction spanOf(edges: Edges, axis: Axis): SpacingSpan {\n return axis === 'x'\n ? { start: edges.left, end: edges.right, crossStart: edges.top, crossEnd: edges.bottom }\n : { start: edges.top, end: edges.bottom, crossStart: edges.left, crossEnd: edges.right }\n}\n\nfunction boundsSpan(bounds: Rect, axis: Axis): SpacingSpan {\n const edges = {\n left: bounds.x,\n right: bounds.x + bounds.width,\n top: bounds.y,\n bottom: bounds.y + bounds.height\n }\n return spanOf(edges, axis)\n}\n\nfunction crossOverlaps(a: SpacingSpan, b: SpacingSpan): boolean {\n return a.crossStart < b.crossEnd && a.crossEnd > b.crossStart\n}\n\n/** Every layer except the moving ones, as spans along each axis sorted by start. */\nexport function spacingTargets(\n movingIds: Set<string>,\n allNodes: readonly SceneNode[]\n): SpacingTargets {\n const x: SpacingSpan[] = []\n const y: SpacingSpan[] = []\n for (const node of allNodes) {\n if (movingIds.has(node.id)) continue\n const edges = getEdges(node)\n x.push(spanOf(edges, 'x'))\n y.push(spanOf(edges, 'y'))\n }\n const byStart = (a: SpacingSpan, b: SpacingSpan) => a.start - b.start\n return { x: x.sort(byStart), y: y.sort(byStart) }\n}\n\n/** The layers beside the moving one along an axis: those sharing some of its extent across it. */\nfunction rowOf(moving: SpacingSpan, sorted: readonly SpacingSpan[]): SpacingSpan[] {\n return sorted.filter((span) => crossOverlaps(span, moving))\n}\n\n/**\n * The gaps between neighbours in a row: stretches along the axis that no layer of the row covers,\n * each between the layer reaching furthest into it and the next layer, when the two share some\n * extent across the axis. A layer over another, such as a label on its button, therefore never\n * makes a gap across the button. A gap the moving layer sits in is not a gap between neighbours, so\n * it is left out. The row is sorted by start, so one sweep finds them all.\n */\nfunction neighbourPairs(row: readonly SpacingSpan[], moving: SpacingSpan): SpacingPair[] {\n const pairs: SpacingPair[] = []\n let frontier: SpacingSpan | null = null\n for (const span of row) {\n if (\n frontier &&\n span.start >= frontier.end &&\n crossOverlaps(span, frontier) &&\n !(moving.start < span.start && moving.end > frontier.end)\n ) {\n pairs.push({ before: frontier, after: span, gap: span.start - frontier.end })\n }\n if (!frontier || span.end > frontier.end) frontier = span\n }\n return pairs\n}\n\n/** The nearest layer before the moving one (ending at most `slack` into it), and after it. */\nfunction neighboursOf(\n row: readonly SpacingSpan[],\n moving: SpacingSpan,\n slack: number\n): { before: SpacingSpan | null; after: SpacingSpan | null } {\n let before: SpacingSpan | null = null\n let after: SpacingSpan | null = null\n for (const span of row) {\n if (span.start < moving.start && span.end <= moving.start + slack) {\n if (!before || span.end > before.end) before = span\n }\n if (span.end > moving.end && span.start >= moving.end - slack) {\n if (!after || span.start < after.start) after = span\n }\n }\n return { before, after }\n}\n\nfunction spacingDelta(\n moving: SpacingSpan,\n sorted: readonly SpacingSpan[],\n threshold: number\n): number | null {\n const row = rowOf(moving, sorted)\n const { before, after } = neighboursOf(row, moving, threshold)\n if (!before && !after) return null\n const size = moving.end - moving.start\n const starts: number[] = []\n if (before && after && after.start - before.end - size >= 0) {\n starts.push((before.end + after.start - size) / 2)\n }\n for (const pair of neighbourPairs(row, moving)) {\n if (before) starts.push(before.end + pair.gap)\n if (after) starts.push(after.start - pair.gap - size)\n }\n let best: number | null = null\n for (const start of starts) {\n const delta = start - moving.start\n if (Math.abs(delta) >= threshold) continue\n if (best === null || Math.abs(delta) < Math.abs(best)) best = delta\n }\n return best\n}\n\n/**\n * Figma's equal-spacing snap: on each axis, the move within `threshold` that centres the moving\n * bounds between their two neighbours, or leaves them as far from a neighbour as two other\n * neighbours in the same row are apart. Only layers sharing some extent across the axis count.\n */\nexport function computeSpacingSnap(\n targets: SpacingTargets,\n movingBounds: Rect,\n threshold = DEFAULT_SNAP_THRESHOLD\n): SpacingSnapResult {\n const delta = (axis: Axis) =>\n spacingDelta(boundsSpan(movingBounds, axis), targets[axis], threshold)\n return { dx: delta('x'), dy: delta('y') }\n}\n\nfunction gapGuide(before: SpacingSpan, after: SpacingSpan, axis: Axis): SnapGuide {\n const position =\n (Math.max(before.crossStart, after.crossStart) + Math.min(before.crossEnd, after.crossEnd)) / 2\n return {\n axis: axis === 'x' ? 'y' : 'x',\n position,\n from: before.end,\n to: after.start,\n spacing: true\n }\n}\n\nfunction sameGap(a: number, b: number): boolean {\n return Math.abs(a - b) < SPACING_MATCH_TOLERANCE\n}\n\nfunction axisSpacingGuides(\n movingBounds: Rect,\n sorted: readonly SpacingSpan[],\n axis: Axis\n): SnapGuide[] {\n const moving = boundsSpan(movingBounds, axis)\n const row = rowOf(moving, sorted)\n const { before, after } = neighboursOf(row, moving, SPACING_MATCH_TOLERANCE)\n const pairs = neighbourPairs(row, moving)\n const sides: SpacingPair[] = []\n if (before) sides.push({ before, after: moving, gap: moving.start - before.end })\n if (after) sides.push({ before: moving, after, gap: after.start - moving.end })\n const matched = sides.filter(\n (side) =>\n side.gap > SPACING_MATCH_TOLERANCE &&\n (sides.some((other) => other !== side && sameGap(other.gap, side.gap)) ||\n pairs.some((pair) => sameGap(pair.gap, side.gap)))\n )\n const gaps = matched.map((side) => side.gap)\n const shown = [...matched, ...pairs.filter((pair) => gaps.some((gap) => sameGap(pair.gap, gap)))]\n return shown.map((pair) => gapGuide(pair.before, pair.after, axis))\n}\n\n/**\n * The equal-spacing indicators for bounds where they are: every gap beside them that equals the gap\n * on their other side or a gap between two neighbours in the same row, and those neighbours' gaps.\n */\nexport function computeSpacingGuides(targets: SpacingTargets, movingBounds: Rect): SnapGuide[] {\n return [\n ...axisSpacingGuides(movingBounds, targets.x, 'x'),\n ...axisSpacingGuides(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CAAC,IAAI;AAC3B;AAEA,SAAS,kBACP,cACA,QACA,MACa;CACb,MAAM,SAAS,WAAW,cAAc,IAAI;CAC5C,MAAM,MAAM,MAAM,QAAQ,MAAM;CAChC,MAAM,EAAE,QAAQ,UAAU,aAAa,KAAK,QAAQ,uBAAuB;CAC3E,MAAM,QAAQ,eAAe,KAAK,MAAM;CACxC,MAAM,QAAuB,CAAC;CAC9B,IAAI,QAAQ,MAAM,KAAK;EAAE;EAAQ,OAAO;EAAQ,KAAK,OAAO,QAAQ,OAAO;CAAI,CAAC;CAChF,IAAI,OAAO,MAAM,KAAK;EAAE,QAAQ;EAAQ;EAAO,KAAK,MAAM,QAAQ,OAAO;CAAI,CAAC;CAC9E,MAAM,UAAU,MAAM,QACnB,SACC,KAAK,MAAM,4BACV,MAAM,MAAM,UAAU,UAAU,QAAQ,QAAQ,MAAM,KAAK,KAAK,GAAG,CAAC,KACnE,MAAM,MAAM,SAAS,QAAQ,KAAK,KAAK,KAAK,GAAG,CAAC,EACtD;CACA,MAAM,OAAO,QAAQ,KAAK,SAAS,KAAK,GAAG;CAE3C,OAAO,CADQ,GAAG,SAAS,GAAG,MAAM,QAAQ,SAAS,KAAK,MAAM,QAAQ,QAAQ,KAAK,KAAK,GAAG,CAAC,CAAC,CACpF,CAAC,CAAC,KAAK,SAAS,SAAS,KAAK,QAAQ,KAAK,OAAO,IAAI,CAAC;AACpE;;;;;AAMA,SAAgB,qBAAqB,SAAyB,cAAiC;CAC7F,OAAO,CACL,GAAG,kBAAkB,cAAc,QAAQ,GAAG,GAAG,GACjD,GAAG,kBAAkB,cAAc,QAAQ,GAAG,GAAG,CACnD;AACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -299,6 +299,11 @@ interface CharacterStyleOverride {
|
|
|
299
299
|
fillStyleId?: string | null;
|
|
300
300
|
/** The characters' text field bindings, in place of the text's own. */
|
|
301
301
|
boundVariables?: TextBoundVariables;
|
|
302
|
+
/**
|
|
303
|
+
* The scale each number the characters bind resolves with, as a rescale left it; a field without
|
|
304
|
+
* one uses the layer's `variableBindingScales`, as runs did before they kept their own.
|
|
305
|
+
*/
|
|
306
|
+
variableBindingScales?: Partial<Record<TextBindableField, number>>;
|
|
302
307
|
}
|
|
303
308
|
interface StyleRun {
|
|
304
309
|
start: number;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;UASiB;EACf,iBAAiB,MAAM;EACvB,iBAAiB,YAAY,SAAS,QAAQ;EAC9C,wBAAwB,YAAY,SAAS,QAAQ;EACrD,iBAAiB,YAAY;EAC7B,oBAAoB,gBAAgB,4BAA4B;EAChE,mBACE,gBACA,kBACA,eACA;;KAIQ,0BAA0B;EACpC,UAAU,MAAM;EAChB,UAAU,YAAY,SAAS,QAAQ;EACvC,iBAAiB,YAAY,SAAS,QAAQ;EAC9C,UAAU,YAAY;EACtB,aAAa,gBAAgB,4BAA4B;EACzD,YACE,gBACA,kBACA,eACA;;;UAKa;;EAEf,SAAS,MAAM;;EAEf,UAAU,MAAM;;KAGN;;KAGA;UAEK;EACf,SAAS;EACT,cAAc;EACd,eAAe;EACf,QAAQ;EACR;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA,KAAK;;KAGK;KACA;UAEK;EACf;EACA;EACA;EACA;EACA;EACA,kBAAkB;;UAGH;EACf;EACA;EACA,cAAc;EACd,YAAY;;UAGG;EACf,aAAa;EACb;;UAGe;EACf,UAAU;EACV,UAAU;EACV,SAAS;;UAGM;EACf,aAAa;EACb,cAAc;;EAEd,QAAQ;;EAER;;KAGU;KAsBA;KAYA;KAoBA;KACA;KACA;KACA;UAEK;EACf,OAAO;EACP;;;;;;;;UASe;EACf,UAAU;EACV,OAAO;;KAGG,oBAAoB;UAEf;EACf,MAAM;EACN,OAAO;EACP;EACA;EACA,YAAY;EACZ,gBAAgB;EAChB,oBAAoB;;EAEpB;EACA;EACA,aAAa;EACb;EACA,iBAAiB;;EAEjB,iBAAiB;;EAEjB;EACA;EACA;EACA;EACA,iBAAiB;EACjB,kBAAkB;EAClB,oBAAoB;EACpB,sBAAsB;EACtB,YAAY;EACZ;EACA,YAAY;EACZ;;KAGU;KASA;KACA;KACA;KACA;UAEK;EACf;EACA,QAAQ;;EAER;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA,MAAM;;;UAIS,eAAe;EAC9B;EACA;EACA,MAAM;EACN,OAAO;EACP;;KAGU,SAAS,eAAe;UAEnB;EACf;EACA,OAAO;EACP,QAAQ;EACR;EACA;EACA;EACA,YAAY;EACZ;;;UAIe;EACf;EACA;EACA,WAAW,eAAe;EAC1B,kBAAkB;EAClB;EACA,YAAY;;KAGF;KACA;;KAGA;;;;;;UAiBK;EACf;EACA,QAAQ;EACR,UAAU;;KAGA;;;;;UAMK;EACf,UAAU;EACV;;;;;;;UAQe;EACf;EACA;EACA;;KAEU;KACA;KACA;KACA;KACA;KACA;KACA;;KAEA;;;KAIA;UAEK;EACf,UAAU;;EAEV;;EAEA;EACA;EACA;;UAGe;EACf;EACA;;UAGe;EACf;EACA;;;UAIe;EACf;EACA;;;cAIW;KAWD,4BAA4B;;KAG5B,qBAAqB,QAAQ,OAAO;;;;;UAM/B;EACf;EACA;;UAGe;EACf;EACA;;EAEA;EACA,iBAAiB;EACjB,sBAAsB;EACtB;EACA,sBAAsB;EACtB;EACA;EACA;EACA;EACA,gBAAgB;;EAEhB,aAAa;EACb,QAAQ;EACR,iBAAiB;;EAEjB;EACA,eAAe;EACf;EACA,WAAW;;EAEX,YAAY;;EAEZ;;EAEA;;EAEA,iBAAiB;;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;UASiB;EACf,iBAAiB,MAAM;EACvB,iBAAiB,YAAY,SAAS,QAAQ;EAC9C,wBAAwB,YAAY,SAAS,QAAQ;EACrD,i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ACQ,kBAAkB;;cAGjB;KAyBD,wBAAwB;cAEvB;KACD,6BAA6B;;;;;cAM5B;KACD,oBAAoB;;;;;;UAOf;EACf;EACA;;UAGe;EACf;EACA;EACA,MAAM;EACN;EACA,cAAc,eAAe;EAC7B;EACA;;EAEA,SAAS;;;;;EAKT,aAAa,QAAQ,OAAO;;EAE5B,OAAO;;EAEP,cAAc,eAAe;EAC7B,aAAa;;EAEb;;EAEA;;;KAIU,yBACT,WAAW,cAAc,UAAU,oBAAoB,mBAClD;UAES;EACf;EACA;;;;;EAKA;;EAEA;;UAGe;EACf;EACA;;EAEA,OAAO;EACP;EACA;;;;;EAKA;EACA,aAAa;;;;;EAKb;;EAEA;;;iBAIc,oBAAoB,YAAY,KAAK;;cAKxC,wBAAsB;iBAEnB,oBAAoB"}
|
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}\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\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 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'\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\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: 'UNION' | 'SUBTRACT' | 'INTERSECT' | 'EXCLUDE' | 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":";;AAuXA,MAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAqoBA,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}\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\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 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'\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: 'UNION' | 'SUBTRACT' | 'INTERSECT' | 'EXCLUDE' | 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":";;AAuXA,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"}
|
package/dist/undo.d.ts
CHANGED
|
@@ -51,7 +51,8 @@ declare class UndoManager {
|
|
|
51
51
|
get isReplaying(): boolean;
|
|
52
52
|
/**
|
|
53
53
|
* Adds a change that the newest step caused, as one an editor makes in response to it, so undo
|
|
54
|
-
* and redo apply them together. Inside a batch it joins the batch. False with no step to join
|
|
54
|
+
* and redo apply them together. Inside a batch it joins the batch. False with no step to join,
|
|
55
|
+
* including after an undo, when the newest step is on the redo stack and not applied.
|
|
55
56
|
*/
|
|
56
57
|
extendLastStep(entry: UndoEntry): boolean;
|
|
57
58
|
private replay;
|
package/dist/undo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undo.d.ts","names":[],"sources":["../src/undo.ts"],"mappings":";UAAiB;EACf;EACA;EACA;EACA;;UAGe;EACf;;EAEA;;;cAUW;cAEA;UACH;UACA;UACA;UACA;UACA;mBACS;mBACA;mBACA;EAEL,YAAA,UAAS;EAKrB,MAAM,OAAO;EAIb,QAAQ,OAAO;EAKf,KAAK,OAAO;EAIZ,OAAO,OAAO;;;;;;EAcd,SAAS,OAAO;;;;;EAShB,gBAAgB;UAKR;EAIR;EAUA;EAUA,WAAW,eAAe;EAI1B;EAUA,SAAS,GAAG,eAAe,UAAU,GAAG,uBAAuB;EAY/D;;EAOA;EAIA;;MAQI
|
|
1
|
+
{"version":3,"file":"undo.d.ts","names":[],"sources":["../src/undo.ts"],"mappings":";UAAiB;EACf;EACA;EACA;EACA;;UAGe;EACf;;EAEA;;;cAUW;cAEA;UACH;UACA;UACA;UACA;UACA;mBACS;mBACA;mBACA;EAEL,YAAA,UAAS;EAKrB,MAAM,OAAO;EAIb,QAAQ,OAAO;EAKf,KAAK,OAAO;EAIZ,OAAO,OAAO;;;;;;EAcd,SAAS,OAAO;;;;;EAShB,gBAAgB;UAKR;EAIR;EAUA;EAUA,WAAW,eAAe;EAI1B;EAUA,SAAS,GAAG,eAAe,UAAU,GAAG,uBAAuB;EAY/D;;EAOA;EAIA;;MAQI;;;;;;EASJ,eAAe,OAAO;UAoBd;MASJ;;;;;EAQJ;;;;;MAcI;;MAKA;MAKA;;;;;EAQJ,SAAS,iBAAY;;EAKrB,SAAS,iBAAY;;;;;EAQrB,QAAQ,OAAO;MAMX;MAIA;cAIQ;UAIJ;UASA;UAeA"}
|
package/dist/undo.js
CHANGED
|
@@ -117,7 +117,8 @@ var UndoManager = class {
|
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
119
119
|
* Adds a change that the newest step caused, as one an editor makes in response to it, so undo
|
|
120
|
-
* and redo apply them together. Inside a batch it joins the batch. False with no step to join
|
|
120
|
+
* and redo apply them together. Inside a batch it joins the batch. False with no step to join,
|
|
121
|
+
* including after an undo, when the newest step is on the redo stack and not applied.
|
|
121
122
|
*/
|
|
122
123
|
extendLastStep(entry) {
|
|
123
124
|
if (this.currentBatch) {
|
|
@@ -125,7 +126,7 @@ var UndoManager = class {
|
|
|
125
126
|
return true;
|
|
126
127
|
}
|
|
127
128
|
const last = this.undoStack.at(-1);
|
|
128
|
-
if (!last) return false;
|
|
129
|
+
if (!last || this.redoStack.length > 0) return false;
|
|
129
130
|
const { forward, inverse } = last;
|
|
130
131
|
last.forward = () => {
|
|
131
132
|
forward();
|
package/dist/undo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undo.js","names":[],"sources":["../src/undo.ts"],"sourcesContent":["export interface UndoEntry {\n label: string\n forward: () => void\n inverse: () => void\n coalesceKey?: string\n}\n\nexport interface UndoManagerOptions {\n limit?: number\n /** Called after recording, undoing, redoing, or clearing committed history. */\n onChange?: () => void\n}\n\ninterface UndoBatch {\n label: string\n entries: UndoEntry[]\n coalesceKey?: string\n}\n\n/** How many edits undo keeps by default. */\nexport const DEFAULT_HISTORY_LIMIT = 200\n\nexport class UndoManager {\n private undoStack: UndoEntry[] = []\n private redoStack: UndoEntry[] = []\n private batches: UndoBatch[] = []\n private replaying = 0\n private openEdits = 0\n private readonly settlers = new Set<() => void>()\n private readonly limit: number\n private readonly onChange: (() => void) | undefined\n\n constructor(options: UndoManagerOptions = {}) {\n this.limit = options.limit ?? DEFAULT_HISTORY_LIMIT\n this.onChange = options.onChange\n }\n\n apply(entry: UndoEntry): void {\n this.execute(entry)\n }\n\n execute(entry: UndoEntry): void {\n entry.forward()\n this.record(entry)\n }\n\n push(entry: UndoEntry): void {\n this.record(entry)\n }\n\n record(entry: UndoEntry): void {\n const batch = this.currentBatch\n if (batch) {\n batch.entries.push(entry)\n return\n }\n this.pushUndoEntry(entry)\n }\n\n /**\n * Records an entry as a step of its own, outside the batches being built, such as an agent's\n * edit made while a colour picker is open. Batches settle first, so the step follows the\n * changes they hold so far.\n */\n pushStep(entry: UndoEntry): void {\n this.settle()\n this.pushUndoEntry(entry)\n }\n\n /**\n * Registers a hook that commits an edit still being coalesced, such as a run of picker changes.\n * Undo and redo run every hook first, so they act on the newest change.\n */\n onBeforeHistory(settle: () => void): () => void {\n this.settlers.add(settle)\n return () => this.settlers.delete(settle)\n }\n\n private settle() {\n for (const settle of this.settlers) settle()\n }\n\n undo(): string | null {\n this.settle()\n const entry = this.undoStack.pop()\n if (!entry) return null\n this.replay(() => entry.inverse())\n this.redoStack.push(entry)\n this.onChange?.()\n return entry.label\n }\n\n redo(): string | null {\n this.settle()\n const entry = this.redoStack.pop()\n if (!entry) return null\n this.replay(() => entry.forward())\n this.undoStack.push(entry)\n this.onChange?.()\n return entry.label\n }\n\n beginBatch(label: string, coalesceKey?: string): void {\n this.batches.push({ label, entries: [], coalesceKey })\n }\n\n commitBatch(): void {\n const batch = this.batches.pop()\n if (!batch || batch.entries.length === 0) return\n\n const entry = this.createBatchEntry(batch)\n const parentBatch = this.currentBatch\n if (parentBatch) parentBatch.entries.push(entry)\n else this.pushUndoEntry(entry)\n }\n\n runBatch<T>(label: string, fn: () => T, coalesceKey?: string): T {\n this.beginBatch(label, coalesceKey)\n try {\n const result = fn()\n this.commitBatch()\n return result\n } catch (error) {\n this.rollbackBatch()\n throw error\n }\n }\n\n rollbackBatch(): void {\n const batch = this.batches.pop()\n if (!batch) return\n for (const entry of batch.entries.toReversed()) entry.inverse()\n }\n\n /** Abandon provisional history without replaying it or changing committed undo/redo entries. */\n discardBatches(): void {\n this.batches = []\n }\n\n clear(): void {\n this.undoStack = []\n this.redoStack = []\n this.discardBatches()\n this.onChange?.()\n }\n\n /** Whether undo or redo is replaying a step, whose changes are history rather than new edits. */\n get isReplaying(): boolean {\n return this.replaying > 0\n }\n\n /**\n * Adds a change that the newest step caused, as one an editor makes in response to it, so undo\n * and redo apply them together. Inside a batch it joins the batch. False with no step to join.\n */\n extendLastStep(entry: UndoEntry): boolean {\n if (this.currentBatch) {\n this.currentBatch.entries.push(entry)\n return true\n }\n const last = this.undoStack.at(-1)\n if (!last) return false\n // The step keeps its identity, so callers that hold it still find it in the history.\n const { forward, inverse } = last\n last.forward = () => {\n forward()\n entry.forward()\n }\n last.inverse = () => {\n entry.inverse()\n inverse()\n }\n return true\n }\n\n private replay(step: () => void) {\n this.replaying++\n try {\n step()\n } finally {\n this.replaying--\n }\n }\n\n get isBatching(): boolean {\n return this.batches.length > 0\n }\n\n /**\n * Marks an edit whose step is recorded when it ends, such as an agent's call that awaits fonts\n * or a layout before it finishes. Returns the function that ends it; ending it twice is a no-op.\n */\n openEdit(): () => void {\n this.openEdits++\n let open = true\n return () => {\n if (!open) return\n open = false\n this.openEdits--\n }\n }\n\n /**\n * Whether a batch or an edit opened with `openEdit` will record a step for the changes made now,\n * so they are not edits outside the history.\n */\n get isRecording(): boolean {\n return this.isBatching || this.openEdits > 0\n }\n\n /** Committed history, or changes in an open batch that a settling hook commits first. */\n get canUndo(): boolean {\n if (this.undoStack.length > 0) return true\n return this.settlers.size > 0 && this.batches.some((batch) => batch.entries.length > 0)\n }\n\n get canRedo(): boolean {\n return this.redoStack.length > 0\n }\n\n /**\n * The entry `depth` steps below the top of the undo stack, so a caller that pushed entries\n * can tell whether they are still the most recent ones.\n */\n peekUndo(depth = 0): UndoEntry | undefined {\n return this.undoStack.at(-1 - depth)\n }\n\n /** The entry `depth` steps below the top of the redo stack, the next one Redo applies at 0. */\n peekRedo(depth = 0): UndoEntry | undefined {\n return this.redoStack.at(-1 - depth)\n }\n\n /**\n * Whether `entry` is applied (on the undo stack) or undone (on the redo stack); null once it\n * left the history, trimmed or dropped when an edit cleared Redo.\n */\n stateOf(entry: UndoEntry): 'applied' | 'undone' | null {\n if (this.undoStack.includes(entry)) return 'applied'\n if (this.redoStack.includes(entry)) return 'undone'\n return null\n }\n\n get undoLabel(): string | null {\n return this.undoStack.at(-1)?.label ?? null\n }\n\n get redoLabel(): string | null {\n return this.redoStack.at(-1)?.label ?? null\n }\n\n private get currentBatch(): UndoBatch | null {\n return this.batches.at(-1) ?? null\n }\n\n private createBatchEntry(batch: UndoBatch): UndoEntry {\n return {\n label: batch.label,\n forward: () => batch.entries.forEach((entry) => entry.forward()),\n inverse: () => batch.entries.toReversed().forEach((entry) => entry.inverse()),\n coalesceKey: batch.coalesceKey\n }\n }\n\n private pushUndoEntry(entry: UndoEntry): void {\n const previous = this.undoStack.at(-1)\n if (entry.coalesceKey && previous?.coalesceKey === entry.coalesceKey) {\n this.undoStack[this.undoStack.length - 1] = {\n ...entry,\n inverse: previous.inverse\n }\n } else {\n this.undoStack.push(entry)\n }\n this.redoStack = []\n this.trimUndoStack()\n this.onChange?.()\n }\n\n private trimUndoStack(): void {\n if (!Number.isFinite(this.limit) || this.limit <= 0) return\n const overflow = this.undoStack.length - this.limit\n if (overflow > 0) this.undoStack.splice(0, overflow)\n }\n}\n"],"mappings":";;AAoBA,MAAa,wBAAwB;AAErC,IAAa,cAAb,MAAyB;CACvB,YAAiC,CAAC;CAClC,YAAiC,CAAC;CAClC,UAA+B,CAAC;CAChC,YAAoB;CACpB,YAAoB;CACpB,2BAA4B,IAAI,IAAgB;CAChD;CACA;CAEA,YAAY,UAA8B,CAAC,GAAG;EAC5C,KAAK,QAAQ,QAAQ,SAAA;EACrB,KAAK,WAAW,QAAQ;CAC1B;CAEA,MAAM,OAAwB;EAC5B,KAAK,QAAQ,KAAK;CACpB;CAEA,QAAQ,OAAwB;EAC9B,MAAM,QAAQ;EACd,KAAK,OAAO,KAAK;CACnB;CAEA,KAAK,OAAwB;EAC3B,KAAK,OAAO,KAAK;CACnB;CAEA,OAAO,OAAwB;EAC7B,MAAM,QAAQ,KAAK;EACnB,IAAI,OAAO;GACT,MAAM,QAAQ,KAAK,KAAK;GACxB;EACF;EACA,KAAK,cAAc,KAAK;CAC1B;;;;;;CAOA,SAAS,OAAwB;EAC/B,KAAK,OAAO;EACZ,KAAK,cAAc,KAAK;CAC1B;;;;;CAMA,gBAAgB,QAAgC;EAC9C,KAAK,SAAS,IAAI,MAAM;EACxB,aAAa,KAAK,SAAS,OAAO,MAAM;CAC1C;CAEA,SAAiB;EACf,KAAK,MAAM,UAAU,KAAK,UAAU,OAAO;CAC7C;CAEA,OAAsB;EACpB,KAAK,OAAO;EACZ,MAAM,QAAQ,KAAK,UAAU,IAAI;EACjC,IAAI,CAAC,OAAO,OAAO;EACnB,KAAK,aAAa,MAAM,QAAQ,CAAC;E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;CACzC;CAEA,IAAY,eAAiC;EAC3C,OAAO,KAAK,QAAQ,GAAG,EAAE,KAAK;CAChC;CAEA,iBAAyB,OAA6B;EACpD,OAAO;GACL,OAAO,MAAM;GACb,eAAe,MAAM,QAAQ,SAAS,UAAU,MAAM,QAAQ,CAAC;GAC/D,eAAe,MAAM,QAAQ,WAAW,CAAC,CAAC,SAAS,UAAU,MAAM,QAAQ,CAAC;GAC5E,aAAa,MAAM;EACrB;CACF;CAEA,cAAsB,OAAwB;EAC5C,MAAM,WAAW,KAAK,UAAU,GAAG,EAAE;EACrC,IAAI,MAAM,eAAe,UAAU,gBAAgB,MAAM,aACvD,KAAK,UAAU,KAAK,UAAU,SAAS,KAAK;GAC1C,GAAG;GACH,SAAS,SAAS;EACpB;OAEA,KAAK,UAAU,KAAK,KAAK;EAE3B,KAAK,YAAY,CAAC;EAClB,KAAK,cAAc;EACnB,KAAK,WAAW;CAClB;CAEA,gBAA8B;EAC5B,IAAI,CAAC,OAAO,SAAS,KAAK,KAAK,KAAK,KAAK,SAAS,GAAG;EACrD,MAAM,WAAW,KAAK,UAAU,SAAS,KAAK;EAC9C,IAAI,WAAW,GAAG,KAAK,UAAU,OAAO,GAAG,QAAQ;CACrD;AACF"}
|
|
1
|
+
{"version":3,"file":"undo.js","names":[],"sources":["../src/undo.ts"],"sourcesContent":["export interface UndoEntry {\n label: string\n forward: () => void\n inverse: () => void\n coalesceKey?: string\n}\n\nexport interface UndoManagerOptions {\n limit?: number\n /** Called after recording, undoing, redoing, or clearing committed history. */\n onChange?: () => void\n}\n\ninterface UndoBatch {\n label: string\n entries: UndoEntry[]\n coalesceKey?: string\n}\n\n/** How many edits undo keeps by default. */\nexport const DEFAULT_HISTORY_LIMIT = 200\n\nexport class UndoManager {\n private undoStack: UndoEntry[] = []\n private redoStack: UndoEntry[] = []\n private batches: UndoBatch[] = []\n private replaying = 0\n private openEdits = 0\n private readonly settlers = new Set<() => void>()\n private readonly limit: number\n private readonly onChange: (() => void) | undefined\n\n constructor(options: UndoManagerOptions = {}) {\n this.limit = options.limit ?? DEFAULT_HISTORY_LIMIT\n this.onChange = options.onChange\n }\n\n apply(entry: UndoEntry): void {\n this.execute(entry)\n }\n\n execute(entry: UndoEntry): void {\n entry.forward()\n this.record(entry)\n }\n\n push(entry: UndoEntry): void {\n this.record(entry)\n }\n\n record(entry: UndoEntry): void {\n const batch = this.currentBatch\n if (batch) {\n batch.entries.push(entry)\n return\n }\n this.pushUndoEntry(entry)\n }\n\n /**\n * Records an entry as a step of its own, outside the batches being built, such as an agent's\n * edit made while a colour picker is open. Batches settle first, so the step follows the\n * changes they hold so far.\n */\n pushStep(entry: UndoEntry): void {\n this.settle()\n this.pushUndoEntry(entry)\n }\n\n /**\n * Registers a hook that commits an edit still being coalesced, such as a run of picker changes.\n * Undo and redo run every hook first, so they act on the newest change.\n */\n onBeforeHistory(settle: () => void): () => void {\n this.settlers.add(settle)\n return () => this.settlers.delete(settle)\n }\n\n private settle() {\n for (const settle of this.settlers) settle()\n }\n\n undo(): string | null {\n this.settle()\n const entry = this.undoStack.pop()\n if (!entry) return null\n this.replay(() => entry.inverse())\n this.redoStack.push(entry)\n this.onChange?.()\n return entry.label\n }\n\n redo(): string | null {\n this.settle()\n const entry = this.redoStack.pop()\n if (!entry) return null\n this.replay(() => entry.forward())\n this.undoStack.push(entry)\n this.onChange?.()\n return entry.label\n }\n\n beginBatch(label: string, coalesceKey?: string): void {\n this.batches.push({ label, entries: [], coalesceKey })\n }\n\n commitBatch(): void {\n const batch = this.batches.pop()\n if (!batch || batch.entries.length === 0) return\n\n const entry = this.createBatchEntry(batch)\n const parentBatch = this.currentBatch\n if (parentBatch) parentBatch.entries.push(entry)\n else this.pushUndoEntry(entry)\n }\n\n runBatch<T>(label: string, fn: () => T, coalesceKey?: string): T {\n this.beginBatch(label, coalesceKey)\n try {\n const result = fn()\n this.commitBatch()\n return result\n } catch (error) {\n this.rollbackBatch()\n throw error\n }\n }\n\n rollbackBatch(): void {\n const batch = this.batches.pop()\n if (!batch) return\n for (const entry of batch.entries.toReversed()) entry.inverse()\n }\n\n /** Abandon provisional history without replaying it or changing committed undo/redo entries. */\n discardBatches(): void {\n this.batches = []\n }\n\n clear(): void {\n this.undoStack = []\n this.redoStack = []\n this.discardBatches()\n this.onChange?.()\n }\n\n /** Whether undo or redo is replaying a step, whose changes are history rather than new edits. */\n get isReplaying(): boolean {\n return this.replaying > 0\n }\n\n /**\n * Adds a change that the newest step caused, as one an editor makes in response to it, so undo\n * and redo apply them together. Inside a batch it joins the batch. False with no step to join,\n * including after an undo, when the newest step is on the redo stack and not applied.\n */\n extendLastStep(entry: UndoEntry): boolean {\n if (this.currentBatch) {\n this.currentBatch.entries.push(entry)\n return true\n }\n const last = this.undoStack.at(-1)\n if (!last || this.redoStack.length > 0) return false\n // The step keeps its identity, so callers that hold it still find it in the history.\n const { forward, inverse } = last\n last.forward = () => {\n forward()\n entry.forward()\n }\n last.inverse = () => {\n entry.inverse()\n inverse()\n }\n return true\n }\n\n private replay(step: () => void) {\n this.replaying++\n try {\n step()\n } finally {\n this.replaying--\n }\n }\n\n get isBatching(): boolean {\n return this.batches.length > 0\n }\n\n /**\n * Marks an edit whose step is recorded when it ends, such as an agent's call that awaits fonts\n * or a layout before it finishes. Returns the function that ends it; ending it twice is a no-op.\n */\n openEdit(): () => void {\n this.openEdits++\n let open = true\n return () => {\n if (!open) return\n open = false\n this.openEdits--\n }\n }\n\n /**\n * Whether a batch or an edit opened with `openEdit` will record a step for the changes made now,\n * so they are not edits outside the history.\n */\n get isRecording(): boolean {\n return this.isBatching || this.openEdits > 0\n }\n\n /** Committed history, or changes in an open batch that a settling hook commits first. */\n get canUndo(): boolean {\n if (this.undoStack.length > 0) return true\n return this.settlers.size > 0 && this.batches.some((batch) => batch.entries.length > 0)\n }\n\n get canRedo(): boolean {\n return this.redoStack.length > 0\n }\n\n /**\n * The entry `depth` steps below the top of the undo stack, so a caller that pushed entries\n * can tell whether they are still the most recent ones.\n */\n peekUndo(depth = 0): UndoEntry | undefined {\n return this.undoStack.at(-1 - depth)\n }\n\n /** The entry `depth` steps below the top of the redo stack, the next one Redo applies at 0. */\n peekRedo(depth = 0): UndoEntry | undefined {\n return this.redoStack.at(-1 - depth)\n }\n\n /**\n * Whether `entry` is applied (on the undo stack) or undone (on the redo stack); null once it\n * left the history, trimmed or dropped when an edit cleared Redo.\n */\n stateOf(entry: UndoEntry): 'applied' | 'undone' | null {\n if (this.undoStack.includes(entry)) return 'applied'\n if (this.redoStack.includes(entry)) return 'undone'\n return null\n }\n\n get undoLabel(): string | null {\n return this.undoStack.at(-1)?.label ?? null\n }\n\n get redoLabel(): string | null {\n return this.redoStack.at(-1)?.label ?? null\n }\n\n private get currentBatch(): UndoBatch | null {\n return this.batches.at(-1) ?? null\n }\n\n private createBatchEntry(batch: UndoBatch): UndoEntry {\n return {\n label: batch.label,\n forward: () => batch.entries.forEach((entry) => entry.forward()),\n inverse: () => batch.entries.toReversed().forEach((entry) => entry.inverse()),\n coalesceKey: batch.coalesceKey\n }\n }\n\n private pushUndoEntry(entry: UndoEntry): void {\n const previous = this.undoStack.at(-1)\n if (entry.coalesceKey && previous?.coalesceKey === entry.coalesceKey) {\n this.undoStack[this.undoStack.length - 1] = {\n ...entry,\n inverse: previous.inverse\n }\n } else {\n this.undoStack.push(entry)\n }\n this.redoStack = []\n this.trimUndoStack()\n this.onChange?.()\n }\n\n private trimUndoStack(): void {\n if (!Number.isFinite(this.limit) || this.limit <= 0) return\n const overflow = this.undoStack.length - this.limit\n if (overflow > 0) this.undoStack.splice(0, overflow)\n }\n}\n"],"mappings":";;AAoBA,MAAa,wBAAwB;AAErC,IAAa,cAAb,MAAyB;CACvB,YAAiC,CAAC;CAClC,YAAiC,CAAC;CAClC,UAA+B,CAAC;CAChC,YAAoB;CACpB,YAAoB;CACpB,2BAA4B,IAAI,IAAgB;CAChD;CACA;CAEA,YAAY,UAA8B,CAAC,GAAG;EAC5C,KAAK,QAAQ,QAAQ,SAAA;EAC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,KAAK,KAAK;EAE3B,KAAK,YAAY,CAAC;EAClB,KAAK,cAAc;EACnB,KAAK,WAAW;CAClB;CAEA,gBAA8B;EAC5B,IAAI,CAAC,OAAO,SAAS,KAAK,KAAK,KAAK,KAAK,SAAS,GAAG;EACrD,MAAM,WAAW,KAAK,UAAU,SAAS,KAAK;EAC9C,IAAI,WAAW,GAAG,KAAK,UAAU,OAAO,GAAG,QAAQ;CACrD;AACF"}
|
|
@@ -29,7 +29,8 @@ declare function resolvedValueBindings(graph: SceneGraph, node: SceneNode, fallb
|
|
|
29
29
|
declare function resolvedIconBinding(graph: SceneGraph, node: SceneNode, fallback?: VariableModeFallback): string | undefined;
|
|
30
30
|
/**
|
|
31
31
|
* The runs a text's character bindings resolve to in its mode, when a bound number or font family
|
|
32
|
-
* differs from what its characters hold
|
|
32
|
+
* differs from what its characters hold, a size or spacing in the run's binding scale for the
|
|
33
|
+
* field, as a rescale left it (`runBindingScale`). Bound font styles are left as stored.
|
|
33
34
|
*/
|
|
34
35
|
declare function resolvedRunBindings(graph: SceneGraph, node: SceneNode, fallback?: VariableModeFallback): Pick<Partial<SceneNode>, 'styleRuns'>;
|
|
35
36
|
/** The fills and strokes a node's color bindings resolve to in its mode, when it has any. */
|