@pairdraw/scene-graph 0.18.0 → 0.19.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/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/properties.d.ts +6 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +14 -3
- package/dist/components/properties.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/gradient.d.ts +23 -0
- package/dist/css/gradient.d.ts.map +1 -0
- package/dist/css/gradient.js +404 -0
- package/dist/css/gradient.js.map +1 -0
- package/dist/css/index.d.ts +2 -1
- package/dist/css/index.js +2 -1
- package/dist/css/shadows.d.ts.map +1 -1
- package/dist/css/shadows.js +2 -13
- package/dist/css/shadows.js.map +1 -1
- package/dist/css/values.js +24 -1
- package/dist/css/values.js.map +1 -1
- package/dist/font-style.d.ts +2 -1
- package/dist/font-style.d.ts.map +1 -1
- package/dist/font-style.js +31 -6
- package/dist/font-style.js.map +1 -1
- package/dist/geometry.d.ts +10 -1
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +21 -6
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +49 -3
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +179 -17
- package/dist/graph.js.map +1 -1
- package/dist/hit-test.d.ts +3 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +38 -23
- package/dist/hit-test.js.map +1 -1
- package/dist/icons/index.d.ts +2 -2
- package/dist/icons/index.js +2 -2
- package/dist/icons/model.d.ts +8 -2
- package/dist/icons/model.d.ts.map +1 -1
- package/dist/icons/model.js +10 -1
- package/dist/icons/model.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/assignments.js +40 -6
- package/dist/instances/assignments.js.map +1 -1
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +18 -1
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +38 -2
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +134 -15
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/overrides.d.ts +10 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +28 -2
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/placement.js +1 -1
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap-overrides.js +94 -0
- package/dist/instances/swap-overrides.js.map +1 -0
- package/dist/instances/sync.js +90 -12
- package/dist/instances/sync.js.map +1 -1
- package/dist/layout/draw-order.d.ts +11 -0
- package/dist/layout/draw-order.d.ts.map +1 -0
- package/dist/layout/draw-order.js +14 -0
- package/dist/layout/draw-order.js.map +1 -0
- package/dist/layout/index.d.ts +2 -1
- package/dist/layout/index.js +2 -1
- package/dist/node-defaults.d.ts +11 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +16 -1
- package/dist/node-defaults.js.map +1 -1
- package/dist/order-keys.d.ts +3 -1
- package/dist/order-keys.d.ts.map +1 -1
- package/dist/order-keys.js +6 -1
- package/dist/order-keys.js.map +1 -1
- package/dist/resize.d.ts +29 -9
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +95 -62
- package/dist/resize.js.map +1 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +1 -8
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/authoring.d.ts +3 -2
- package/dist/slots/authoring.d.ts.map +1 -1
- package/dist/slots/authoring.js +5 -3
- package/dist/slots/authoring.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +4 -1
- package/dist/slots/content.js.map +1 -1
- package/dist/source-metadata.d.ts +4 -2
- package/dist/source-metadata.d.ts.map +1 -1
- package/dist/source-metadata.js +10 -3
- package/dist/source-metadata.js.map +1 -1
- package/dist/strokes.d.ts +39 -0
- package/dist/strokes.d.ts.map +1 -0
- package/dist/strokes.js +104 -0
- package/dist/strokes.js.map +1 -0
- package/dist/text/direction.d.ts +6 -2
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +2 -1
- package/dist/text/direction.js.map +1 -1
- package/dist/text/index.d.ts +3 -3
- package/dist/text/index.js +3 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +22 -6
- package/dist/text/overflow.d.ts.map +1 -1
- package/dist/text/overflow.js +24 -6
- package/dist/text/overflow.js.map +1 -1
- package/dist/transfer/nodes.js +9 -5
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +18 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +36 -1
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +52 -2
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +14 -6
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +42 -67
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/formula/signatures.js +1 -1
- package/dist/variables/index.d.ts +10 -4
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +58 -15
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +101 -0
- package/dist/variables/paints.d.ts.map +1 -0
- package/dist/variables/paints.js +313 -0
- package/dist/variables/paints.js.map +1 -0
- package/dist/variables/resolution.d.ts +14 -1
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +44 -4
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +17 -0
- package/dist/variables/subtree.js.map +1 -0
- package/package.json +6 -1
- package/src/components/properties.ts +17 -2
- package/src/copy.ts +1 -0
- package/src/css/gradient.ts +438 -0
- package/src/css/index.ts +1 -0
- package/src/css/shadows.ts +2 -18
- package/src/css/values.ts +27 -1
- package/src/font-style.ts +38 -4
- package/src/geometry.ts +25 -6
- package/src/graph.ts +207 -17
- package/src/hit-test.ts +67 -24
- package/src/icons/model.ts +11 -1
- package/src/instances/assignments.ts +65 -7
- package/src/instances/fields.ts +21 -0
- package/src/instances/index.ts +237 -14
- package/src/instances/overrides.ts +36 -1
- package/src/instances/placement.ts +5 -1
- package/src/instances/swap-overrides.ts +123 -0
- package/src/instances/sync.ts +139 -12
- package/src/layout/draw-order.ts +13 -0
- package/src/layout/index.ts +1 -0
- package/src/node-defaults.ts +21 -0
- package/src/order-keys.ts +6 -0
- package/src/resize.ts +133 -69
- package/src/shared-styles.ts +1 -3
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +4 -1
- package/src/source-metadata.ts +18 -3
- package/src/strokes.ts +121 -0
- package/src/text/direction.ts +7 -5
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +30 -7
- package/src/transfer/nodes.ts +7 -5
- package/src/types.ts +17 -0
- package/src/undo.ts +79 -2
- package/src/variables/bindings.ts +52 -74
- package/src/variables/index.ts +80 -14
- package/src/variables/paints.ts +413 -0
- package/src/variables/resolution.ts +56 -5
- package/src/variables/subtree.ts +15 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overrides.js","names":[],"sources":["../../src/instances/overrides.ts"],"sourcesContent":["export type InstanceOverrideField = string\n\nexport interface InstanceOverrideState {\n self: Map<InstanceOverrideField, unknown>\n descendants: Map<string, Map<InstanceOverrideField, unknown>>\n}\n\nconst BINDING_OVERRIDE_PREFIX = 'boundVariables/'\n\n/**\n * The override field that claims a layer's binding of `field`, which keeps that binding, or its\n * absence, through a sync. `boundVariables` alone claims every binding of the layer.\n */\nexport function bindingOverrideField(field: string): InstanceOverrideField {\n return `${BINDING_OVERRIDE_PREFIX}${field}`\n}\n\n/** The binding field an override field claims, or null for an override of anything else. */\nexport function overriddenBindingField(field: InstanceOverrideField): string | null {\n return field.startsWith(BINDING_OVERRIDE_PREFIX)\n ? field.slice(BINDING_OVERRIDE_PREFIX.length)\n : null\n}\n\nconst VARIABLE_MODE_OVERRIDE_PREFIX = 'variableModes/'\n\n/**\n * The override field that keeps a layer's mode for one collection through a sync, so the\n * component's modes for other collections still reach it. `variableModes` alone keeps them all.\n */\nexport function variableModeOverrideField(collectionId: string): InstanceOverrideField {\n return `${VARIABLE_MODE_OVERRIDE_PREFIX}${collectionId}`\n}\n\n/** The collection a mode override field claims, or null for an override of anything else. */\nexport function overriddenVariableModeCollection(field: InstanceOverrideField): string | null {\n return field.startsWith(VARIABLE_MODE_OVERRIDE_PREFIX)\n ? field.slice(VARIABLE_MODE_OVERRIDE_PREFIX.length)\n : null\n}\n\n/**\n * The override field that marks a layer of an instance as one put in place of a component's\n * layer, recorded by the nearest instance above it. Its value is the layer it replaces, which\n * sync matches it to instead of copying that layer in again.\n */\nexport const REPLACED_LAYER_OVERRIDE = 'replacedLayer'\n\n/** Override fields whose value names another layer of the document. */\nexport function isLayerReferenceOverride(field: InstanceOverrideField): boolean {\n return (\n field === 'componentId' || field === 'sourceComponentId' || field === REPLACED_LAYER_OVERRIDE\n )\n}\n\nexport function createInstanceOverrideState(): InstanceOverrideState {\n return { self: new Map(), descendants: new Map() }\n}\n\nexport interface SerializedOverrideValue {\n defined: boolean\n value?: unknown\n}\n\nexport interface SerializedInstanceOverrideState {\n self: Array<[InstanceOverrideField, SerializedOverrideValue]>\n descendants: Array<[string, Array<[InstanceOverrideField, SerializedOverrideValue]>]>\n}\n\nfunction serializeOverrideValue(value: unknown): SerializedOverrideValue {\n return value === undefined ? { defined: false } : { defined: true, value }\n}\n\nfunction deserializeOverrideValue(value: unknown): { valid: boolean; value: unknown } {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return { valid: false, value: undefined }\n }\n if (!('defined' in value) || typeof value.defined !== 'boolean') {\n return { valid: false, value: undefined }\n }\n if (value.defined) {\n return 'value' in value\n ? { valid: true, value: value['value'] }\n : { valid: false, value: undefined }\n }\n return { valid: true, value: undefined }\n}\n\nfunction deserializeEntries(value: unknown): Map<InstanceOverrideField, unknown> {\n const result = new Map<InstanceOverrideField, unknown>()\n if (!Array.isArray(value)) return result\n for (const entry of value) {\n if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== 'string') continue\n const decoded = deserializeOverrideValue(entry[1])\n if (decoded.valid) result.set(entry[0], decoded.value)\n }\n return result\n}\n\nexport function serializeInstanceOverrideState(\n state: InstanceOverrideState\n): SerializedInstanceOverrideState {\n return {\n self: [...state.self].map(([field, value]) => [field, serializeOverrideValue(value)]),\n descendants: [...state.descendants].map(([nodeId, fields]) => [\n nodeId,\n [...fields].map(([field, value]) => [field, serializeOverrideValue(value)])\n ])\n }\n}\n\nexport function deserializeInstanceOverrideState(state: unknown): InstanceOverrideState {\n if (!state || typeof state !== 'object' || Array.isArray(state)) {\n return createInstanceOverrideState()\n }\n const self =\n 'self' in state ? deserializeEntries(state.self) : new Map<InstanceOverrideField, unknown>()\n const descendants = new Map<string, Map<InstanceOverrideField, unknown>>()\n if ('descendants' in state && Array.isArray(state.descendants)) {\n for (const entry of state.descendants) {\n if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== 'string') continue\n descendants.set(entry[0], deserializeEntries(entry[1]))\n }\n }\n return { self, descendants }\n}\n\nexport function cloneInstanceOverrideState(state: InstanceOverrideState): InstanceOverrideState {\n return {\n self: new Map([...state.self].map(([field, value]) => [field, structuredClone(value)])),\n descendants: new Map(\n [...state.descendants].map(([id, fields]) => [\n id,\n new Map([...fields].map(([field, value]) => [field, structuredClone(value)]))\n ])\n )\n }\n}\n\nexport interface InstanceOverrideReferenceMapper {\n node: (id: string) => string\n variable: (id: string) => string\n}\n\n/** Remap runtime identities only; ordinary strings and source-format payloads stay opaque. */\nexport function remapInstanceOverrideState(\n state: InstanceOverrideState,\n references: InstanceOverrideReferenceMapper\n): InstanceOverrideState {\n const remapValue = (field: string, value: unknown): unknown => {\n if (typeof value !== 'string') return structuredClone(value)\n if (isLayerReferenceOverride(field)) return references.node(value)\n if (overriddenBindingField(field) !== null) return references.variable(value)\n return value\n }\n const fields = (entries: ReadonlyMap<string, unknown>) =>\n new Map([...entries].map(([field, value]) => [field, remapValue(field, value)]))\n const descendants = new Map<string, Map<string, unknown>>()\n for (const [id, entries] of state.descendants) {\n const mapped = references.node(id)\n if (descendants.has(mapped)) throw new Error(`Duplicate remapped override target ${mapped}`)\n descendants.set(mapped, fields(entries))\n }\n return { self: fields(state.self), descendants }\n}\n\nexport function getInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField\n): unknown {\n return nodeId === instanceId ? state.self.get(field) : state.descendants.get(nodeId)?.get(field)\n}\n\n/**\n * The component layer a layer of an instance copies: the one its instance recorded for it, as\n * a swapped nested instance keeps, or else the one it was cloned from.\n */\nexport function copiedComponentLayerId(\n state: InstanceOverrideState,\n instanceId: string,\n node: { id: string; componentId: string | null }\n): string | undefined {\n const recorded = getInstanceOverride(state, instanceId, node.id, 'sourceComponentId')\n return typeof recorded === 'string' ? recorded : (node.componentId ?? undefined)\n}\n\nexport function hasInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField\n): boolean {\n const fields = nodeId === instanceId ? state.self : state.descendants.get(nodeId)\n return fields?.has(field) ?? false\n}\n\nexport function setInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField,\n value: unknown = true\n): void {\n if (nodeId === instanceId) {\n state.self.set(field, value)\n return\n }\n const fields = state.descendants.get(nodeId) ?? new Map<string, unknown>()\n fields.set(field, value)\n state.descendants.set(nodeId, fields)\n}\n\nexport function deleteInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField\n): boolean {\n const fields = nodeId === instanceId ? state.self : state.descendants.get(nodeId)\n if (!fields?.delete(field)) return false\n if (nodeId !== instanceId && fields.size === 0) state.descendants.delete(nodeId)\n return true\n}\n\nexport function clearInstanceOverrides(state: InstanceOverrideState): void {\n state.self.clear()\n state.descendants.clear()\n}\n\nexport function forEachInstanceOverride(\n state: InstanceOverrideState,\n callback: (nodeId: string, field: InstanceOverrideField, value: unknown) => void\n): void {\n for (const [field, value] of state.self) callback('', field, value)\n for (const [nodeId, fields] of state.descendants) {\n for (const [field, value] of fields) callback(nodeId, field, value)\n }\n}\n"],"mappings":";AAOA,MAAM,0BAA0B;;;;;AAMhC,SAAgB,qBAAqB,OAAsC;CACzE,OAAO,GAAG,0BAA0B;AACtC;;AAGA,SAAgB,uBAAuB,OAA6C;CAClF,OAAO,MAAM,WAAW,uBAAuB,IAC3C,MAAM,MAAM,EAA8B,IAC1C;AACN;AAEA,MAAM,gCAAgC;;;;;AAMtC,SAAgB,0BAA0B,cAA6C;CACrF,OAAO,GAAG,gCAAgC;AAC5C;;AAGA,SAAgB,iCAAiC,OAA6C;CAC5F,OAAO,MAAM,WAAW,6BAA6B,IACjD,MAAM,MAAM,EAAoC,IAChD;AACN;;;;;;AAOA,MAAa,0BAA0B;;AAGvC,SAAgB,yBAAyB,OAAuC;CAC9E,OACE,UAAU,iBAAiB,UAAU,uBAAuB,UAAA;AAEhE;AAEA,SAAgB,8BAAqD;CACnE,OAAO;EAAE,sBAAM,IAAI,IAAI;EAAG,6BAAa,IAAI,IAAI;CAAE;AACnD;AAYA,SAAS,uBAAuB,OAAyC;CACvE,OAAO,UAAU,KAAA,IAAY,EAAE,SAAS,MAAM,IAAI;EAAE,SAAS;EAAM;CAAM;AAC3E;AAEA,SAAS,yBAAyB,OAAoD;CACpF,IAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAC5D,OAAO;EAAE,OAAO;EAAO,OAAO,KAAA;CAAU;CAE1C,IAAI,EAAE,aAAa,UAAU,OAAO,MAAM,YAAY,WACpD,OAAO;EAAE,OAAO;EAAO,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K;AAEtE"}
|
|
1
|
+
{"version":3,"file":"overrides.js","names":[],"sources":["../../src/instances/overrides.ts"],"sourcesContent":["export type InstanceOverrideField = string\n\nexport interface InstanceOverrideState {\n self: Map<InstanceOverrideField, unknown>\n descendants: Map<string, Map<InstanceOverrideField, unknown>>\n}\n\nconst BINDING_OVERRIDE_PREFIX = 'boundVariables/'\n\n/**\n * The override field that claims a layer's binding of `field`, which keeps that binding, or its\n * absence, through a sync. `boundVariables` alone claims every binding of the layer.\n */\nexport function bindingOverrideField(field: string): InstanceOverrideField {\n return `${BINDING_OVERRIDE_PREFIX}${field}`\n}\n\n/** The binding field an override field claims, or null for an override of anything else. */\nexport function overriddenBindingField(field: InstanceOverrideField): string | null {\n return field.startsWith(BINDING_OVERRIDE_PREFIX)\n ? field.slice(BINDING_OVERRIDE_PREFIX.length)\n : null\n}\n\nconst VARIABLE_MODE_OVERRIDE_PREFIX = 'variableModes/'\n\n/**\n * The override field that keeps a layer's mode for one collection through a sync, so the\n * component's modes for other collections still reach it. `variableModes` alone keeps them all.\n */\nexport function variableModeOverrideField(collectionId: string): InstanceOverrideField {\n return `${VARIABLE_MODE_OVERRIDE_PREFIX}${collectionId}`\n}\n\n/** The collection a mode override field claims, or null for an override of anything else. */\nexport function overriddenVariableModeCollection(field: InstanceOverrideField): string | null {\n return field.startsWith(VARIABLE_MODE_OVERRIDE_PREFIX)\n ? field.slice(VARIABLE_MODE_OVERRIDE_PREFIX.length)\n : null\n}\n\nconst ASSIGNMENT_OVERRIDE_PREFIX = 'componentPropertyAssignments/'\n\n/**\n * The override field that claims a nested instance's assignment of `propertyId`, which keeps\n * that assignment through a sync of the instance that makes it.\n */\nexport function assignmentOverrideField(propertyId: string): InstanceOverrideField {\n return `${ASSIGNMENT_OVERRIDE_PREFIX}${propertyId}`\n}\n\n/** The property an assignment override field claims, or null for an override of anything else. */\nexport function overriddenAssignmentId(field: InstanceOverrideField): string | null {\n return field.startsWith(ASSIGNMENT_OVERRIDE_PREFIX)\n ? field.slice(ASSIGNMENT_OVERRIDE_PREFIX.length)\n : null\n}\n\n/**\n * The override field that marks a layer of an instance as one put in place of a component's\n * layer, recorded by the nearest instance above it. Its value is the layer it replaces, which\n * sync matches it to instead of copying that layer in again.\n */\nexport const REPLACED_LAYER_OVERRIDE = 'replacedLayer'\n\n/** Override fields whose value names another layer of the document. */\nexport function isLayerReferenceOverride(field: InstanceOverrideField): boolean {\n return (\n field === 'componentId' || field === 'sourceComponentId' || field === REPLACED_LAYER_OVERRIDE\n )\n}\n\nexport function createInstanceOverrideState(): InstanceOverrideState {\n return { self: new Map(), descendants: new Map() }\n}\n\nexport interface SerializedOverrideValue {\n defined: boolean\n value?: unknown\n}\n\nexport interface SerializedInstanceOverrideState {\n self: Array<[InstanceOverrideField, SerializedOverrideValue]>\n descendants: Array<[string, Array<[InstanceOverrideField, SerializedOverrideValue]>]>\n}\n\nfunction serializeOverrideValue(value: unknown): SerializedOverrideValue {\n return value === undefined ? { defined: false } : { defined: true, value }\n}\n\nfunction deserializeOverrideValue(value: unknown): { valid: boolean; value: unknown } {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return { valid: false, value: undefined }\n }\n if (!('defined' in value) || typeof value.defined !== 'boolean') {\n return { valid: false, value: undefined }\n }\n if (value.defined) {\n return 'value' in value\n ? { valid: true, value: value['value'] }\n : { valid: false, value: undefined }\n }\n return { valid: true, value: undefined }\n}\n\nfunction deserializeEntries(value: unknown): Map<InstanceOverrideField, unknown> {\n const result = new Map<InstanceOverrideField, unknown>()\n if (!Array.isArray(value)) return result\n for (const entry of value) {\n if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== 'string') continue\n const decoded = deserializeOverrideValue(entry[1])\n if (decoded.valid) result.set(entry[0], decoded.value)\n }\n return result\n}\n\nexport function serializeInstanceOverrideState(\n state: InstanceOverrideState\n): SerializedInstanceOverrideState {\n return {\n self: [...state.self].map(([field, value]) => [field, serializeOverrideValue(value)]),\n descendants: [...state.descendants].map(([nodeId, fields]) => [\n nodeId,\n [...fields].map(([field, value]) => [field, serializeOverrideValue(value)])\n ])\n }\n}\n\nexport function deserializeInstanceOverrideState(state: unknown): InstanceOverrideState {\n if (!state || typeof state !== 'object' || Array.isArray(state)) {\n return createInstanceOverrideState()\n }\n const self =\n 'self' in state ? deserializeEntries(state.self) : new Map<InstanceOverrideField, unknown>()\n const descendants = new Map<string, Map<InstanceOverrideField, unknown>>()\n if ('descendants' in state && Array.isArray(state.descendants)) {\n for (const entry of state.descendants) {\n if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== 'string') continue\n descendants.set(entry[0], deserializeEntries(entry[1]))\n }\n }\n return { self, descendants }\n}\n\nexport function cloneInstanceOverrideState(state: InstanceOverrideState): InstanceOverrideState {\n return {\n self: new Map([...state.self].map(([field, value]) => [field, structuredClone(value)])),\n descendants: new Map(\n [...state.descendants].map(([id, fields]) => [\n id,\n new Map([...fields].map(([field, value]) => [field, structuredClone(value)]))\n ])\n )\n }\n}\n\nexport interface InstanceOverrideReferenceMapper {\n node: (id: string) => string\n variable: (id: string) => string\n collection?: (id: string) => string | undefined\n property?: (id: string) => string | undefined\n}\n\n/** Remap runtime identities only; ordinary strings and source-format payloads stay opaque. */\nexport function remapInstanceOverrideState(\n state: InstanceOverrideState,\n references: InstanceOverrideReferenceMapper\n): InstanceOverrideState {\n const remapValue = (field: string, value: unknown): unknown => {\n if (typeof value !== 'string') return structuredClone(value)\n if (isLayerReferenceOverride(field)) return references.node(value)\n if (overriddenBindingField(field) !== null) return references.variable(value)\n return value\n }\n const remapField = (field: string): string | undefined => {\n const property = overriddenAssignmentId(field)\n if (property !== null && references.property) {\n const mapped = references.property(property)\n return mapped === undefined ? undefined : assignmentOverrideField(mapped)\n }\n const collection = overriddenVariableModeCollection(field)\n if (collection === null || !references.collection) return field\n const mapped = references.collection(collection)\n return mapped === undefined ? undefined : variableModeOverrideField(mapped)\n }\n const fields = (entries: ReadonlyMap<string, unknown>) =>\n new Map(\n [...entries].flatMap(([field, value]) => {\n const mapped = remapField(field)\n return mapped === undefined ? [] : [[mapped, remapValue(field, value)] as const]\n })\n )\n const descendants = new Map<string, Map<string, unknown>>()\n for (const [id, entries] of state.descendants) {\n const mapped = references.node(id)\n if (descendants.has(mapped)) throw new Error(`Duplicate remapped override target ${mapped}`)\n descendants.set(mapped, fields(entries))\n }\n return { self: fields(state.self), descendants }\n}\n\nexport function getInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField\n): unknown {\n return nodeId === instanceId ? state.self.get(field) : state.descendants.get(nodeId)?.get(field)\n}\n\n/**\n * The component layer a layer of an instance copies: the one its instance recorded for it, as\n * a swapped nested instance keeps, or else the one it was cloned from.\n */\nexport function copiedComponentLayerId(\n state: InstanceOverrideState,\n instanceId: string,\n node: { id: string; componentId: string | null }\n): string | undefined {\n const recorded = getInstanceOverride(state, instanceId, node.id, 'sourceComponentId')\n return typeof recorded === 'string' ? recorded : (node.componentId ?? undefined)\n}\n\nexport function hasInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField\n): boolean {\n const fields = nodeId === instanceId ? state.self : state.descendants.get(nodeId)\n return fields?.has(field) ?? false\n}\n\nexport function setInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField,\n value: unknown = true\n): void {\n if (nodeId === instanceId) {\n state.self.set(field, value)\n return\n }\n const fields = state.descendants.get(nodeId) ?? new Map<string, unknown>()\n fields.set(field, value)\n state.descendants.set(nodeId, fields)\n}\n\nexport function deleteInstanceOverride(\n state: InstanceOverrideState,\n instanceId: string,\n nodeId: string,\n field: InstanceOverrideField\n): boolean {\n const fields = nodeId === instanceId ? state.self : state.descendants.get(nodeId)\n if (!fields?.delete(field)) return false\n if (nodeId !== instanceId && fields.size === 0) state.descendants.delete(nodeId)\n return true\n}\n\nexport function clearInstanceOverrides(state: InstanceOverrideState): void {\n state.self.clear()\n state.descendants.clear()\n}\n\nexport function forEachInstanceOverride(\n state: InstanceOverrideState,\n callback: (nodeId: string, field: InstanceOverrideField, value: unknown) => void\n): void {\n for (const [field, value] of state.self) callback('', field, value)\n for (const [nodeId, fields] of state.descendants) {\n for (const [field, value] of fields) callback(nodeId, field, value)\n }\n}\n"],"mappings":";AAOA,MAAM,0BAA0B;;;;;AAMhC,SAAgB,qBAAqB,OAAsC;CACzE,OAAO,GAAG,0BAA0B;AACtC;;AAGA,SAAgB,uBAAuB,OAA6C;CAClF,OAAO,MAAM,WAAW,uBAAuB,IAC3C,MAAM,MAAM,EAA8B,IAC1C;AACN;AAEA,MAAM,gCAAgC;;;;;AAMtC,SAAgB,0BAA0B,cAA6C;CACrF,OAAO,GAAG,gCAAgC;AAC5C;;AAGA,SAAgB,iCAAiC,OAA6C;CAC5F,OAAO,MAAM,WAAW,6BAA6B,IACjD,MAAM,MAAM,EAAoC,IAChD;AACN;AAEA,MAAM,6BAA6B;;;;;AAMnC,SAAgB,wBAAwB,YAA2C;CACjF,OAAO,GAAG,6BAA6B;AACzC;;AAGA,SAAgB,uBAAuB,OAA6C;CAClF,OAAO,MAAM,WAAW,0BAA0B,IAC9C,MAAM,MAAM,EAAiC,IAC7C;AACN;;;;;;AAOA,MAAa,0BAA0B;;AAGvC,SAAgB,yBAAyB,OAAuC;CAC9E,OACE,UAAU,iBAAiB,UAAU,uBAAuB,UAAA;AAEhE;AAEA,SAAgB,8BAAqD;CACnE,OAAO;EAAE,sBAAM,IAAI,IAAI;EAAG,6BAAa,IAAI,IAAI;CAAE;AACnD;AAYA,SAAS,uBAAuB,OAAyC;CACvE,OAAO,UAAU,KAAA,IAAY,EAAE,SAAS,MAAM,IAAI;EAAE,SAAS;EAAM;CAAM;AAC3E;AAEA,SAAS,yBAAyB,OAAoD;CACpF,IAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAC5D,OAAO;EAAE,OAAO;EAAO,OAAO,KAAA;CAAU;CAE1C,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MAAM;AACtC;AAEA,SAAgB,uBACd,OACA,YACA,QACA,OACS;CACT,MAAM,SAAS,WAAW,aAAa,MAAM,OAAO,MAAM,YAAY,IAAI,MAAM;CAChF,IAAI,CAAC,QAAQ,OAAO,KAAK,GAAG,OAAO;CACnC,IAAI,WAAW,cAAc,OAAO,SAAS,GAAG,MAAM,YAAY,OAAO,MAAM;CAC/E,OAAO;AACT;AAEA,SAAgB,uBAAuB,OAAoC;CACzE,MAAM,KAAK,MAAM;CACjB,MAAM,YAAY,MAAM;AAC1B;AAEA,SAAgB,wBACd,OACA,UACM;CACN,KAAK,MAAM,CAAC,OAAO,UAAU,MAAM,MAAM,SAAS,IAAI,OAAO,KAAK;CAClE,KAAK,MAAM,CAAC,QAAQ,WAAW,MAAM,aACnC,KAAK,MAAM,CAAC,OAAO,UAAU,QAAQ,SAAS,QAAQ,OAAO,KAAK;AAEtE"}
|
|
@@ -18,7 +18,7 @@ function placedByConstraints(source, compParent, instParent, factor) {
|
|
|
18
18
|
height: compParent.height * factor
|
|
19
19
|
};
|
|
20
20
|
if (before.width === instParent.width && before.height === instParent.height) return source;
|
|
21
|
-
const rect = layoutConstrainedChildRect(source, before, instParent, source.horizontalConstraint, source.verticalConstraint, enforcedAspectRatio(source));
|
|
21
|
+
const { flipsX: _flipsX, flipsY: _flipsY, ...rect } = layoutConstrainedChildRect(source, before, instParent, source.horizontalConstraint, source.verticalConstraint, enforcedAspectRatio(source));
|
|
22
22
|
return {
|
|
23
23
|
...source,
|
|
24
24
|
...rect
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placement.js","names":[],"sources":["../../src/instances/placement.ts"],"sourcesContent":["import { enforcedAspectRatio } from '../layout/aspect-ratio'\nimport { layoutConstrainedChildRect } from '../resize'\nimport type { SceneNode } from '../types'\n\n/** The fields that say where a copy sits in its parent. */\nexport const PLACEMENT_FIELDS: ReadonlySet<string> = new Set(['x', 'y', 'width', 'height'])\n\n/**\n * The component's layer placed in the copy's parent: where its constraints put it when the\n * instance's frame has another size than the component's, as Figma resizes an instance.\n */\nexport function placedByConstraints(\n source: SceneNode,\n compParent: SceneNode,\n instParent: SceneNode,\n factor: number\n): SceneNode {\n const before = { width: compParent.width * factor, height: compParent.height * factor }\n if (before.width === instParent.width && before.height === instParent.height) return source\n const rect = layoutConstrainedChildRect(\n source,\n before,\n instParent,\n source.horizontalConstraint,\n source.verticalConstraint,\n enforcedAspectRatio(source)\n )\n return { ...source, ...rect }\n}\n"],"mappings":";;;;AAKA,MAAa,mCAAwC,IAAI,IAAI;CAAC;CAAK;CAAK;CAAS;AAAQ,CAAC;;;;;AAM1F,SAAgB,oBACd,QACA,YACA,YACA,QACW;CACX,MAAM,SAAS;EAAE,OAAO,WAAW,QAAQ;EAAQ,QAAQ,WAAW,SAAS;CAAO;CACtF,IAAI,OAAO,UAAU,WAAW,SAAS,OAAO,WAAW,WAAW,QAAQ,OAAO;CACrF,MAAM,
|
|
1
|
+
{"version":3,"file":"placement.js","names":[],"sources":["../../src/instances/placement.ts"],"sourcesContent":["import { enforcedAspectRatio } from '../layout/aspect-ratio'\nimport { layoutConstrainedChildRect } from '../resize'\nimport type { SceneNode } from '../types'\n\n/** The fields that say where a copy sits in its parent. */\nexport const PLACEMENT_FIELDS: ReadonlySet<string> = new Set(['x', 'y', 'width', 'height'])\n\n/**\n * The component's layer placed in the copy's parent: where its constraints put it when the\n * instance's frame has another size than the component's, as Figma resizes an instance.\n */\nexport function placedByConstraints(\n source: SceneNode,\n compParent: SceneNode,\n instParent: SceneNode,\n factor: number\n): SceneNode {\n const before = { width: compParent.width * factor, height: compParent.height * factor }\n if (before.width === instParent.width && before.height === instParent.height) return source\n const {\n flipsX: _flipsX,\n flipsY: _flipsY,\n ...rect\n } = layoutConstrainedChildRect(\n source,\n before,\n instParent,\n source.horizontalConstraint,\n source.verticalConstraint,\n enforcedAspectRatio(source)\n )\n return { ...source, ...rect }\n}\n"],"mappings":";;;;AAKA,MAAa,mCAAwC,IAAI,IAAI;CAAC;CAAK;CAAK;CAAS;AAAQ,CAAC;;;;;AAM1F,SAAgB,oBACd,QACA,YACA,YACA,QACW;CACX,MAAM,SAAS;EAAE,OAAO,WAAW,QAAQ;EAAQ,QAAQ,WAAW,SAAS;CAAO;CACtF,IAAI,OAAO,UAAU,WAAW,SAAS,OAAO,WAAW,WAAW,QAAQ,OAAO;CACrF,MAAM,EACJ,QAAQ,SACR,QAAQ,SACR,GAAG,SACD,2BACF,QACA,QACA,YACA,OAAO,sBACP,OAAO,oBACP,oBAAoB,MAAM,CAC5B;CACA,OAAO;EAAE,GAAG;EAAQ,GAAG;CAAK;AAC9B"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { isLayerReferenceOverride, overriddenBindingField, overriddenVariableModeCollection, setInstanceOverride } from "./overrides.js";
|
|
2
|
+
import { INSTANCE_OVERRIDE_FIELDS } from "./fields.js";
|
|
3
|
+
import { copyProp } from "./sync.js";
|
|
4
|
+
//#region src/instances/swap-overrides.ts
|
|
5
|
+
const OVERRIDE_FIELD_KEYS = new Set(INSTANCE_OVERRIDE_FIELDS);
|
|
6
|
+
function isInstanceOverrideField(field) {
|
|
7
|
+
return OVERRIDE_FIELD_KEYS.has(field);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A layer's place inside its instance: the names from the instance down, with the position among
|
|
11
|
+
* siblings of the same name appended, so two layers called the same stay apart.
|
|
12
|
+
*/
|
|
13
|
+
function childPath(parentPath, name, index) {
|
|
14
|
+
return `${parentPath}/${name}#${index}`;
|
|
15
|
+
}
|
|
16
|
+
function forEachChildPath(graph, parentId, parentPath, visit) {
|
|
17
|
+
const seen = /* @__PURE__ */ new Map();
|
|
18
|
+
for (const child of graph.getChildren(parentId)) {
|
|
19
|
+
const index = seen.get(child.name) ?? 0;
|
|
20
|
+
seen.set(child.name, index + 1);
|
|
21
|
+
const path = childPath(parentPath, child.name, index);
|
|
22
|
+
visit(child, path);
|
|
23
|
+
forEachChildPath(graph, child.id, path, visit);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Every override an instance's layers record, keyed by path, so a swap of the component can give
|
|
28
|
+
* them back to the layers of the variant that replace them, as Figma keeps overrides where the
|
|
29
|
+
* two variants share a layer.
|
|
30
|
+
*/
|
|
31
|
+
function captureInstanceOverrides(graph, instance) {
|
|
32
|
+
const captured = /* @__PURE__ */ new Map();
|
|
33
|
+
forEachChildPath(graph, instance.id, "", (child, path) => {
|
|
34
|
+
const fields = instance.instanceOverrides.descendants.get(child.id);
|
|
35
|
+
if (!fields?.size) return;
|
|
36
|
+
const kept = [...fields.keys()].filter((field) => isInstanceOverrideField(field) || !isLayerReferenceOverride(field));
|
|
37
|
+
if (kept.length) captured.set(path, {
|
|
38
|
+
snapshot: structuredClone(child),
|
|
39
|
+
fields: kept
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
return captured;
|
|
43
|
+
}
|
|
44
|
+
function changesFor(layer) {
|
|
45
|
+
const changes = {};
|
|
46
|
+
const bindings = {};
|
|
47
|
+
const modes = {};
|
|
48
|
+
let bindingsTouched = false;
|
|
49
|
+
let modesTouched = false;
|
|
50
|
+
for (const field of layer.fields) {
|
|
51
|
+
const binding = overriddenBindingField(field);
|
|
52
|
+
if (binding) {
|
|
53
|
+
bindingsTouched = true;
|
|
54
|
+
if (binding in layer.snapshot.boundVariables) bindings[binding] = layer.snapshot.boundVariables[binding];
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const collection = overriddenVariableModeCollection(field);
|
|
58
|
+
if (collection) {
|
|
59
|
+
modesTouched = true;
|
|
60
|
+
if (collection in layer.snapshot.variableModes) modes[collection] = layer.snapshot.variableModes[collection];
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (isInstanceOverrideField(field)) copyProp(changes, layer.snapshot, field);
|
|
64
|
+
}
|
|
65
|
+
if (bindingsTouched) changes.boundVariables = bindings;
|
|
66
|
+
if (modesTouched) changes.variableModes = modes;
|
|
67
|
+
return changes;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Gives the captured overrides back to the layers of the instance's new component, matching each
|
|
71
|
+
* layer by path, and records them again for the layers that take the old ones' places.
|
|
72
|
+
*/
|
|
73
|
+
function restoreInstanceOverrides(graph, instance, captured) {
|
|
74
|
+
if (!captured.size) return;
|
|
75
|
+
const paths = [];
|
|
76
|
+
forEachChildPath(graph, instance.id, "", (child, path) => {
|
|
77
|
+
const layer = captured.get(path);
|
|
78
|
+
if (layer) paths.push({
|
|
79
|
+
child,
|
|
80
|
+
layer
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
if (!paths.length) return;
|
|
84
|
+
for (const { child, layer } of paths) {
|
|
85
|
+
const changes = changesFor(layer);
|
|
86
|
+
if (Object.keys(changes).length) graph.updateNode(child.id, changes);
|
|
87
|
+
for (const field of layer.fields) setInstanceOverride(instance.instanceOverrides, instance.id, child.id, field);
|
|
88
|
+
}
|
|
89
|
+
graph.updateNode(instance.id, { instanceOverrides: instance.instanceOverrides });
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { captureInstanceOverrides, restoreInstanceOverrides };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=swap-overrides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap-overrides.js","names":[],"sources":["../../src/instances/swap-overrides.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { SceneNode } from '../types'\nimport { INSTANCE_OVERRIDE_FIELDS } from './fields'\nimport {\n isLayerReferenceOverride,\n overriddenBindingField,\n overriddenVariableModeCollection,\n setInstanceOverride\n} from './overrides'\nimport { copyProp } from './sync'\n\n/** What a swap keeps for one layer, so the layer that replaces it can take the values over. */\ninterface CapturedLayer {\n snapshot: SceneNode\n fields: string[]\n}\n\n/** Overrides kept across a swap, keyed by each layer's name path inside the instance. */\nexport type CapturedInstanceOverrides = Map<string, CapturedLayer>\n\nconst OVERRIDE_FIELD_KEYS = new Set<string>(INSTANCE_OVERRIDE_FIELDS)\n\nfunction isInstanceOverrideField(field: string): field is keyof SceneNode {\n return OVERRIDE_FIELD_KEYS.has(field)\n}\n\n/**\n * A layer's place inside its instance: the names from the instance down, with the position among\n * siblings of the same name appended, so two layers called the same stay apart.\n */\nfunction childPath(parentPath: string, name: string, index: number): string {\n return `${parentPath}/${name}#${index}`\n}\n\nfunction forEachChildPath(\n graph: SceneGraph,\n parentId: string,\n parentPath: string,\n visit: (child: SceneNode, path: string) => void\n): void {\n const seen = new Map<string, number>()\n for (const child of graph.getChildren(parentId)) {\n const index = seen.get(child.name) ?? 0\n seen.set(child.name, index + 1)\n const path = childPath(parentPath, child.name, index)\n visit(child, path)\n forEachChildPath(graph, child.id, path, visit)\n }\n}\n\n/**\n * Every override an instance's layers record, keyed by path, so a swap of the component can give\n * them back to the layers of the variant that replace them, as Figma keeps overrides where the\n * two variants share a layer.\n */\nexport function captureInstanceOverrides(\n graph: SceneGraph,\n instance: SceneNode\n): CapturedInstanceOverrides {\n const captured: CapturedInstanceOverrides = new Map()\n forEachChildPath(graph, instance.id, '', (child, path) => {\n const fields = instance.instanceOverrides.descendants.get(child.id)\n if (!fields?.size) return\n const kept = [...fields.keys()].filter(\n (field) => isInstanceOverrideField(field) || !isLayerReferenceOverride(field)\n )\n if (kept.length) captured.set(path, { snapshot: structuredClone(child), fields: kept })\n })\n return captured\n}\n\nfunction changesFor(layer: CapturedLayer): Partial<SceneNode> {\n const changes: Partial<SceneNode> = {}\n const bindings: Record<string, string> = {}\n const modes: Record<string, string> = {}\n let bindingsTouched = false\n let modesTouched = false\n for (const field of layer.fields) {\n const binding = overriddenBindingField(field)\n if (binding) {\n bindingsTouched = true\n if (binding in layer.snapshot.boundVariables)\n bindings[binding] = layer.snapshot.boundVariables[binding]\n continue\n }\n const collection = overriddenVariableModeCollection(field)\n if (collection) {\n modesTouched = true\n if (collection in layer.snapshot.variableModes)\n modes[collection] = layer.snapshot.variableModes[collection]\n continue\n }\n if (isInstanceOverrideField(field)) copyProp(changes, layer.snapshot, field)\n }\n if (bindingsTouched) changes.boundVariables = bindings\n if (modesTouched) changes.variableModes = modes\n return changes\n}\n\n/**\n * Gives the captured overrides back to the layers of the instance's new component, matching each\n * layer by path, and records them again for the layers that take the old ones' places.\n */\nexport function restoreInstanceOverrides(\n graph: SceneGraph,\n instance: SceneNode,\n captured: CapturedInstanceOverrides\n): void {\n if (!captured.size) return\n const paths: Array<{ child: SceneNode; layer: CapturedLayer }> = []\n forEachChildPath(graph, instance.id, '', (child, path) => {\n const layer = captured.get(path)\n if (layer) paths.push({ child, layer })\n })\n if (!paths.length) return\n for (const { child, layer } of paths) {\n const changes = changesFor(layer)\n if (Object.keys(changes).length) graph.updateNode(child.id, changes)\n for (const field of layer.fields)\n setInstanceOverride(instance.instanceOverrides, instance.id, child.id, field)\n }\n graph.updateNode(instance.id, { instanceOverrides: instance.instanceOverrides })\n}\n"],"mappings":";;;;AAoBA,MAAM,sBAAsB,IAAI,IAAY,wBAAwB;AAEpE,SAAS,wBAAwB,OAAyC;CACxE,OAAO,oBAAoB,IAAI,KAAK;AACtC;;;;;AAMA,SAAS,UAAU,YAAoB,MAAc,OAAuB;CAC1E,OAAO,GAAG,WAAW,GAAG,KAAK,GAAG;AAClC;AAEA,SAAS,iBACP,OACA,UACA,YACA,OACM;CACN,MAAM,uBAAO,IAAI,IAAoB;CACrC,KAAK,MAAM,SAAS,MAAM,YAAY,QAAQ,GAAG;EAC/C,MAAM,QAAQ,KAAK,IAAI,MAAM,IAAI,KAAK;EACtC,KAAK,IAAI,MAAM,MAAM,QAAQ,CAAC;EAC9B,MAAM,OAAO,UAAU,YAAY,MAAM,MAAM,KAAK;EACpD,MAAM,OAAO,IAAI;EACjB,iBAAiB,OAAO,MAAM,IAAI,MAAM,KAAK;CAC/C;AACF;;;;;;AAOA,SAAgB,yBACd,OACA,UAC2B;CAC3B,MAAM,2BAAsC,IAAI,IAAI;CACpD,i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,CAAC;CACD,IAAI,CAAC,MAAM,QAAQ;CACnB,KAAK,MAAM,EAAE,OAAO,WAAW,OAAO;EACpC,MAAM,UAAU,WAAW,KAAK;EAChC,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,QAAQ,MAAM,WAAW,MAAM,IAAI,OAAO;EACnE,KAAK,MAAM,SAAS,MAAM,QACxB,oBAAoB,SAAS,mBAAmB,SAAS,IAAI,MAAM,IAAI,KAAK;CAChF;CACA,MAAM,WAAW,SAAS,IAAI,EAAE,mBAAmB,SAAS,kBAAkB,CAAC;AACjF"}
|
package/dist/instances/sync.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { bindingOverrideField, copiedComponentLayerId, hasInstanceOverride, overriddenBindingField, setInstanceOverride } from "./overrides.js";
|
|
2
2
|
import { cloneNodeProps, copyEffects, copyFills, copyStrokes, copyStyleRuns } from "../copy.js";
|
|
3
3
|
import { scaleNodeChanges } from "../scaling/node.js";
|
|
4
|
+
import { isNumericVariableBindingField, paintBindingTarget } from "../variables/fields.js";
|
|
4
5
|
import { ownsSelfFillField, sourceWithEffectiveFill } from "./main-component.js";
|
|
5
6
|
import { ownsSlotContent, slotPropertyId } from "../slots/frames.js";
|
|
7
|
+
import { STROKE_LINE_FIELDS, STROKE_LINE_KEYS, strokeLine, withStrokeLines } from "../strokes.js";
|
|
8
|
+
import { applyBoundPaintColorsIn, copyAppliedBoundPaints, keepCopyBoundPaints } from "../variables/paints.js";
|
|
6
9
|
import { scaleVariableBindingUnits } from "../variables/units.js";
|
|
10
|
+
import { resolvedNumericBindings } from "../variables/bindings.js";
|
|
7
11
|
import { applyEnclosingAssignments, assignedFieldValues, propertyDrivenFields } from "./assignments.js";
|
|
8
12
|
import { keepOwnContentSize, remeasureChangedText } from "./content-size.js";
|
|
9
13
|
import { replacedLayerIn, replacedLayerMatch } from "./replacements.js";
|
|
@@ -12,7 +16,9 @@ import { INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_FIELD_OWNERS } from "./fields.js";
|
|
|
12
16
|
import { syncedVariableModes } from "./modes.js";
|
|
13
17
|
import { PLACEMENT_FIELDS, placedByConstraints } from "./placement.js";
|
|
14
18
|
import { followVectorGeometry } from "./vector-geometry.js";
|
|
19
|
+
import { pick } from "es-toolkit/object";
|
|
15
20
|
import { isEqual } from "es-toolkit/predicate";
|
|
21
|
+
import { uniq } from "es-toolkit/array";
|
|
16
22
|
//#region src/instances/sync.ts
|
|
17
23
|
function setSceneProp(target, key, value) {
|
|
18
24
|
target[key] = value;
|
|
@@ -39,7 +45,13 @@ function bindingProtection(scopes) {
|
|
|
39
45
|
const perField = [...scope].some((field) => overriddenBindingField(field) !== null);
|
|
40
46
|
for (const field of scope) if (field !== "boundVariables" || !perField) fields.add(field);
|
|
41
47
|
}
|
|
42
|
-
return (field) =>
|
|
48
|
+
return (field) => {
|
|
49
|
+
if (fields.has(field)) return true;
|
|
50
|
+
const binding = overriddenBindingField(field);
|
|
51
|
+
if (binding === null) return false;
|
|
52
|
+
const paint = paintBindingTarget(binding);
|
|
53
|
+
return paint !== null && fields.has(paint.list);
|
|
54
|
+
};
|
|
43
55
|
}
|
|
44
56
|
function syncBindingFields(target, source, updates, protectedField) {
|
|
45
57
|
if (protectedField("boundVariables")) return;
|
|
@@ -105,17 +117,73 @@ function copySyncedFields(updates, copy, source, { compParent, instParent, facto
|
|
|
105
117
|
y: !placedByLayout && !skip("y")
|
|
106
118
|
};
|
|
107
119
|
}
|
|
108
|
-
function updateSyncedProps(graph, target, updates) {
|
|
120
|
+
function updateSyncedProps(graph, target, updates, kept = () => false) {
|
|
121
|
+
resolveBoundNumbersInPlace(graph, target, updates, kept);
|
|
122
|
+
if (updates.fills || updates.strokes || updates.boundVariables) {
|
|
123
|
+
applySyncedModes(graph, target, updates);
|
|
124
|
+
keepCopyBoundPaints(graph, target, updates);
|
|
125
|
+
}
|
|
126
|
+
applySyncedStrokeLines(graph, target, updates, kept);
|
|
109
127
|
const changed = Object.fromEntries(Object.entries(updates).filter(([key, value]) => !isEqual(target[key], value)));
|
|
110
128
|
if (changed.fills && updates.fillStyleId !== void 0) changed.fillStyleId = updates.fillStyleId;
|
|
111
129
|
if (Object.keys(changed).length) graph.updateNode(target.id, changed);
|
|
112
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* A bound number the sync writes takes the value it resolves to where the copy sits, not the
|
|
133
|
+
* one its component holds: an instance that sets another mode, or sits in one that does, shows
|
|
134
|
+
* that mode's value, as Figma draws it. A field the sync leaves alone, such as one an instance
|
|
135
|
+
* overrides, keeps its own value.
|
|
136
|
+
*/
|
|
137
|
+
function resolveBoundNumbersInPlace(graph, target, updates, kept) {
|
|
138
|
+
const bound = updates.boundVariables ?? target.boundVariables;
|
|
139
|
+
const rebound = updates.boundVariables ? Object.keys(bound).filter((field) => bound[field] !== target.boundVariables[field]) : [];
|
|
140
|
+
const synced = uniq([...Object.keys(updates), ...rebound]).filter((field) => isNumericVariableBindingField(field) && bound[field] && !kept(field));
|
|
141
|
+
if (synced.length === 0) return;
|
|
142
|
+
applySyncedModes(graph, target, updates);
|
|
143
|
+
const resolved = resolvedNumericBindings(graph, {
|
|
144
|
+
...target,
|
|
145
|
+
...updates
|
|
146
|
+
});
|
|
147
|
+
Object.assign(updates, pick(resolved, synced));
|
|
148
|
+
}
|
|
149
|
+
/** The modes the copy takes in this sync decide what its bindings resolve to. */
|
|
150
|
+
function applySyncedModes(graph, target, updates) {
|
|
151
|
+
if (updates.variableModes && !isEqual(updates.variableModes, target.variableModes)) graph.updateNode(target.id, { variableModes: updates.variableModes });
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Strokes a sync or swap gives a copy draw with the copy's own line fields: the weight,
|
|
155
|
+
* alignment, cap, join, or dash it overrides, and a bound weight resolved in its modes. Figma
|
|
156
|
+
* keeps a stroke weight override when the component's color changes (live).
|
|
157
|
+
*/
|
|
158
|
+
function applySyncedStrokeLines(graph, target, updates, kept) {
|
|
159
|
+
const strokes = updates.strokes;
|
|
160
|
+
const first = strokes?.at(0);
|
|
161
|
+
if (!strokes || !first) return;
|
|
162
|
+
const boundWeight = kept("strokeWeight") ? void 0 : (updates.boundVariables ?? target.boundVariables).strokeWeight;
|
|
163
|
+
const weightScale = (updates.variableBindingScales ?? target.variableBindingScales).strokeWeight ?? 1;
|
|
164
|
+
const resolvedWeight = boundWeight ? graph.resolveNumberVariableForNode(target.id, boundWeight, "active") : void 0;
|
|
165
|
+
const lines = {};
|
|
166
|
+
let set = false;
|
|
167
|
+
for (const key of STROKE_LINE_KEYS) {
|
|
168
|
+
const field = STROKE_LINE_FIELDS[key];
|
|
169
|
+
const own = kept(field);
|
|
170
|
+
const synced = own ? target[field] : updates[field];
|
|
171
|
+
const value = field === "strokeWeight" && resolvedWeight !== void 0 ? resolvedWeight * weightScale : synced;
|
|
172
|
+
if (value === void 0) continue;
|
|
173
|
+
if (!(own ? strokes.some((stroke) => !isEqual(value, strokeLine(stroke, key))) : !isEqual(value, strokeLine(first, key)))) continue;
|
|
174
|
+
Reflect.set(lines, key, value);
|
|
175
|
+
set = true;
|
|
176
|
+
}
|
|
177
|
+
if (set) updates.strokes = withStrokeLines(strokes, lines);
|
|
178
|
+
}
|
|
113
179
|
function cloneChildInCoordinates(graph, src, sourceParent, targetParent, mode = "deep") {
|
|
114
180
|
const componentScale = src.componentScale * targetParent.componentScale / sourceParent.componentScale;
|
|
115
|
-
|
|
181
|
+
const clone = graph.createNode(src.type, targetParent.id, {
|
|
116
182
|
...cloneNodeProps(sourceInTargetCoordinates(src, componentScale), src.id, mode),
|
|
117
183
|
componentScale
|
|
118
184
|
});
|
|
185
|
+
copyAppliedBoundPaints(src, clone);
|
|
186
|
+
return clone;
|
|
119
187
|
}
|
|
120
188
|
function cloneChildrenWithMapping(graph, sourceParentId, destParentId, mode = "deep") {
|
|
121
189
|
if (sourceParentId === destParentId || graph.isDescendant(destParentId, sourceParentId)) return;
|
|
@@ -144,11 +212,19 @@ function childBindingProtection(graph, child, overrides) {
|
|
|
144
212
|
const protectedField = bindingProtection(fields);
|
|
145
213
|
return (field) => protectedField(field) || ownsSelfFillField(child, field);
|
|
146
214
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
215
|
+
/** Links a copy to the component layer it matched, reporting each changed node and its owner. */
|
|
216
|
+
function linkMatchedChild(graph, context, instParentId, instChild, compChildId) {
|
|
217
|
+
const { overrides } = context;
|
|
218
|
+
const recorded = hasInstanceOverride(overrides, instParentId, instChild.id, "sourceComponentId");
|
|
219
|
+
if (instChild.type === "INSTANCE" || recorded) {
|
|
220
|
+
const owner = graph.nodes.get(context.instanceId);
|
|
221
|
+
graph.willChangeNode(owner);
|
|
222
|
+
setInstanceOverride(overrides, instParentId, instChild.id, "sourceComponentId", compChildId);
|
|
223
|
+
if (owner) graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides });
|
|
224
|
+
}
|
|
225
|
+
if (instChild.type !== "INSTANCE") graph.updateNode(instChild.id, { componentId: compChildId });
|
|
150
226
|
}
|
|
151
|
-
function matchFallbackChildren(graph, compParent, instParent, instParentId,
|
|
227
|
+
function matchFallbackChildren(graph, compParent, instParent, instParentId, context, instChildMap, usedInstChildIds) {
|
|
152
228
|
const fallbackByType = /* @__PURE__ */ new Map();
|
|
153
229
|
const remainingCandidateCount = /* @__PURE__ */ new Map();
|
|
154
230
|
const unmatchedComponentCount = /* @__PURE__ */ new Map();
|
|
@@ -182,7 +258,7 @@ function matchFallbackChildren(graph, compParent, instParent, instParentId, over
|
|
|
182
258
|
remainingCandidateCount.set(compChild.type, candidateCount - 1);
|
|
183
259
|
instChildMap.set(compChildId, match);
|
|
184
260
|
usedInstChildIds.add(match.id);
|
|
185
|
-
linkMatchedChild(
|
|
261
|
+
linkMatchedChild(graph, context, instParentId, match, compChildId);
|
|
186
262
|
}
|
|
187
263
|
}
|
|
188
264
|
function sortInstanceChildren(graph, instParent, instParentId, compChildOrder, overrides, matched) {
|
|
@@ -255,6 +331,7 @@ function placeMissingChildren(graph, compParent, instParent, instChildMap, usedI
|
|
|
255
331
|
const clone = cloneChildInCoordinates(graph, src, compParent, instParent);
|
|
256
332
|
if (src.childIds.length > 0 && !hasUnplacedCopiesBelow(graph, context, compChildId)) cloneChildrenWithMapping(graph, compChildId, clone.id);
|
|
257
333
|
applyEnclosingAssignments(graph, clone);
|
|
334
|
+
applyBoundPaintColorsIn(graph, clone.id);
|
|
258
335
|
instChildMap.set(compChildId, clone);
|
|
259
336
|
usedInstChildIds.add(clone.id);
|
|
260
337
|
context.matched.add(clone.id);
|
|
@@ -270,7 +347,7 @@ function syncChildren(graph, compParentId, instParentId, overrides, context = cr
|
|
|
270
347
|
const usedInstChildIds = /* @__PURE__ */ new Set();
|
|
271
348
|
const owner = instParent.type === "INSTANCE" ? instParent : graph.closest(instParent.id, (node) => node.type === "INSTANCE");
|
|
272
349
|
matchLinkedChildren(graph, instParent, instParentId, overrides, owner, compParent, instChildMap, usedInstChildIds);
|
|
273
|
-
matchFallbackChildren(graph, compParent, instParent, instParentId,
|
|
350
|
+
matchFallbackChildren(graph, compParent, instParent, instParentId, context, instChildMap, usedInstChildIds);
|
|
274
351
|
placeMissingChildren(graph, compParent, instParent, instChildMap, usedInstChildIds, context);
|
|
275
352
|
for (const compChildId of compParent.childIds) {
|
|
276
353
|
const compChild = graph.nodes.get(compChildId);
|
|
@@ -279,6 +356,7 @@ function syncChildren(graph, compParentId, instParentId, overrides, context = cr
|
|
|
279
356
|
if (replacedLayerIn(owner, instChild.id) !== void 0) continue;
|
|
280
357
|
const protectedField = childBindingProtection(graph, instChild, overrides);
|
|
281
358
|
const driven = propertyDrivenFields(graph, instChild, compChild);
|
|
359
|
+
const kept = (key) => driven.has(key) || isProtectedSyncField(instChild, key, protectedField);
|
|
282
360
|
const componentScale = compChild.componentScale * instParent.componentScale / compParent.componentScale;
|
|
283
361
|
const source = sourceInTargetCoordinates(sourceWithEffectiveFill(graph, compChild, instChild), componentScale);
|
|
284
362
|
const updates = {
|
|
@@ -291,16 +369,16 @@ function syncChildren(graph, compParentId, instParentId, overrides, context = cr
|
|
|
291
369
|
compParent,
|
|
292
370
|
instParent,
|
|
293
371
|
factor: componentScale / compChild.componentScale,
|
|
294
|
-
skip:
|
|
372
|
+
skip: kept
|
|
295
373
|
});
|
|
296
374
|
Object.assign(updates, assignedFieldValues(graph, instChild, compChild));
|
|
297
375
|
keepOwnContentSize(graph, updates, instChild, source, placement);
|
|
298
|
-
updateSyncedProps(graph, instChild, updates);
|
|
376
|
+
updateSyncedProps(graph, instChild, updates, kept);
|
|
299
377
|
if (compChild.childIds.length > 0 && !hasInstanceOverride(overrides, instParentId, instChild.id, "componentId") && !ownsSlotContent(graph, instChild, slotPropertyId(compChild))) syncChildren(graph, compChildId, instChild.id, overrides, context);
|
|
300
378
|
}
|
|
301
379
|
sortInstanceChildren(graph, instParent, instParentId, compParent.childIds, overrides, instChildMap);
|
|
302
380
|
}
|
|
303
381
|
//#endregion
|
|
304
|
-
export { bindingProtection, cloneChildrenWithMapping, copyProp, enclosingInstanceOverrideFields, isProtectedSyncField, sourceInTargetCoordinates, syncBindingFields, syncChildren, syncVariableModeFields, updateSyncedProps };
|
|
382
|
+
export { applySyncedStrokeLines, bindingProtection, cloneChildrenWithMapping, copyProp, enclosingInstanceOverrideFields, isProtectedSyncField, sourceInTargetCoordinates, syncBindingFields, syncChildren, syncVariableModeFields, updateSyncedProps };
|
|
305
383
|
|
|
306
384
|
//# sourceMappingURL=sync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","names":["hasNodeInstanceOverride"],"sources":["../../src/instances/sync.ts"],"sourcesContent":["// Child cloning and property synchronization shared by instance creation, swap, and sync.\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport { cloneNodeProps, copyEffects, copyFills, copyStrokes, copyStyleRuns } from '../copy'\nimport type { NodeCloneMode } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport { scaleNodeChanges } from '../scaling/node'\nimport { ownsSlotContent, slotPropertyId } from '../slots/frames'\nimport type { SceneNode } from '../types'\nimport { scaleVariableBindingUnits } from '../variables/units'\nimport { applyEnclosingAssignments, assignedFieldValues, propertyDrivenFields } from './assignments'\nimport { keepOwnContentSize, remeasureChangedText, type SyncedPlacement } from './content-size'\nimport {\n createInstanceSyncContext,\n hasUnplacedCopiesBelow,\n restoreRemovedCopy,\n unplacedCopy,\n type InstanceSyncContext\n} from './copies'\nimport { INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_FIELDS } from './fields'\nimport { ownsSelfFillField, sourceWithEffectiveFill } from './main-component'\nimport { syncedVariableModes } from './modes'\nimport {\n bindingOverrideField,\n copiedComponentLayerId,\n hasInstanceOverride as hasNodeInstanceOverride,\n overriddenBindingField,\n setInstanceOverride,\n type InstanceOverrideState\n} from './overrides'\nimport { PLACEMENT_FIELDS, placedByConstraints } from './placement'\nimport { replacedLayerIn, replacedLayerMatch } from './replacements'\nimport { followVectorGeometry } from './vector-geometry'\n\nfunction setSceneProp<K extends keyof SceneNode>(\n target: Partial<SceneNode>,\n key: K,\n value: SceneNode[K]\n): void {\n target[key] = value\n}\n\nexport function copyProp(\n target: Partial<SceneNode> | SceneNode,\n source: SceneNode,\n key: keyof SceneNode\n): void {\n if (key === 'fills') {\n setSceneProp(target, key, copyFills(source.fills))\n } else if (key === 'strokes') {\n setSceneProp(target, key, copyStrokes(source.strokes))\n } else if (key === 'effects') {\n setSceneProp(target, key, copyEffects(source.effects))\n } else if (key === 'styleRuns') {\n setSceneProp(target, key, copyStyleRuns(source.styleRuns))\n } else if (key === 'boundVariables') {\n // Shallow copy the binding map — values are variable IDs (strings), not objects\n setSceneProp(target, key, { ...source.boundVariables })\n setSceneProp(target, 'variableBindingScales', { ...source.variableBindingScales })\n } else if (key === 'variableModes') {\n setSceneProp(target, key, { ...source.variableModes })\n } else if (key === 'gridPosition') {\n // Shallow copy the grid position object — all fields are primitives\n setSceneProp(target, key, source.gridPosition ? { ...source.gridPosition } : null)\n } else if (key === 'targetAspectRatio') {\n setSceneProp(target, key, source.targetAspectRatio ? { ...source.targetAspectRatio } : null)\n } else {\n const value = source[key]\n setSceneProp(target, key, Array.isArray(value) ? structuredClone(value) : value)\n }\n}\n\nexport function bindingProtection(scopes: ReadonlySet<string>[]): (field: string) => boolean {\n const fields = new Set<string>()\n for (const scope of scopes) {\n const perField = [...scope].some((field) => overriddenBindingField(field) !== null)\n for (const field of scope) {\n if (field !== 'boundVariables' || !perField) fields.add(field)\n }\n }\n return (field) => fields.has(field)\n}\n\nexport function syncBindingFields(\n target: SceneNode,\n source: SceneNode,\n updates: Partial<SceneNode>,\n protectedField: (field: string) => boolean\n): void {\n if (protectedField('boundVariables')) return\n const bindings = { ...source.boundVariables }\n const scales = { ...source.variableBindingScales }\n for (const field of new Set([\n ...Object.keys(source.boundVariables),\n ...Object.keys(target.boundVariables),\n ...Object.keys(target.variableBindingScales)\n ])) {\n if (!protectedField(bindingOverrideField(field))) continue\n if (!Object.hasOwn(target.boundVariables, field)) Reflect.deleteProperty(bindings, field)\n else bindings[field] = target.boundVariables[field]\n if (target.variableBindingScales[field] === undefined) Reflect.deleteProperty(scales, field)\n else scales[field] = target.variableBindingScales[field]\n }\n updates.boundVariables = bindings\n updates.variableBindingScales = scales\n}\n\n/**\n * Takes the component layer's variable modes, but those the copy overrides, collection by\n * collection. A nested instance's own claims count too, as its enclosing component syncs it.\n */\nexport function syncVariableModeFields(\n target: SceneNode,\n source: SceneNode,\n updates: Partial<SceneNode>,\n protectedField: (field: string) => boolean\n): void {\n const ownClaim = (field: string) =>\n target.type === 'INSTANCE' && target.instanceOverrides.self.has(field)\n const modes = syncedVariableModes(\n target,\n source,\n (field) => protectedField(field) || ownClaim(field)\n )\n if (modes) updates.variableModes = modes\n}\n\nexport function isProtectedSyncField(\n node: SceneNode,\n key: string,\n protectedField: (field: string) => boolean\n): boolean {\n return (\n protectedField(key) ||\n (key in node.boundVariables &&\n (protectedField('boundVariables') || protectedField(bindingOverrideField(key))))\n )\n}\n\nexport function sourceInTargetCoordinates(source: SceneNode, targetScale: number): SceneNode {\n const factor = targetScale / source.componentScale\n if (!Number.isFinite(factor) || factor <= 0) throw new Error('Invalid component coordinate scale')\n if (factor === 1) return source\n const scaled = scaleNodeChanges(source, factor, true)\n return {\n ...source,\n ...scaled,\n ...scaleVariableBindingUnits(source, factor, scaled.styleRuns)\n }\n}\n\ninterface SyncedFieldsInput {\n compParent: SceneNode\n instParent: SceneNode\n /** The component's coordinates in the copy's. */\n factor: number\n /** Fields the copy keeps: overridden, bound, or driven by a property. */\n skip: (key: string) => boolean\n}\n\n/** The fields a copy takes from its component's layer, placed in the copy's parent. */\nfunction copySyncedFields(\n updates: Partial<SceneNode>,\n copy: SceneNode,\n source: SceneNode,\n { compParent, instParent, factor, skip }: SyncedFieldsInput\n): SyncedPlacement {\n // In an auto layout flow the layout places the copy, as it placed the component's layer.\n const placedByLayout = instParent.layoutMode !== 'NONE' && source.layoutPositioning !== 'ABSOLUTE'\n const placed = placedByLayout\n ? source\n : placedByConstraints(source, compParent, instParent, factor)\n for (const key of INSTANCE_SYNC_FIELDS) {\n // Bindings and modes merge entry by entry, apart from this loop.\n if (key === 'boundVariables' || key === 'variableModes') continue\n if (placedByLayout && (key === 'x' || key === 'y')) continue\n if (skip(key)) continue\n const owner = INSTANCE_SYNC_FIELD_OWNERS[key]\n if (owner && skip(owner)) continue\n const from = PLACEMENT_FIELDS.has(key) ? placed : source\n // Most fields already match: comparing first spares cloning them for nothing.\n if (isEqual(copy[key], from[key])) continue\n copyProp(updates, from, key)\n }\n // New paints bring their style link, unless the copy keeps a style of its own.\n if (updates.fills)\n updates.fillStyleId = skip('fillStyleId') ? copy.fillStyleId : source.fillStyleId\n followVectorGeometry(updates, copy, source)\n remeasureChangedText(updates, copy)\n return { placed, x: !placedByLayout && !skip('x'), y: !placedByLayout && !skip('y') }\n}\n\nexport function updateSyncedProps(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>\n): void {\n const changed = Object.fromEntries(\n Object.entries(updates).filter(\n ([key, value]) => !isEqual(target[key as keyof SceneNode], value)\n )\n ) as Partial<SceneNode>\n if (changed.fills && updates.fillStyleId !== undefined) changed.fillStyleId = updates.fillStyleId\n if (Object.keys(changed).length) graph.updateNode(target.id, changed)\n}\n\nfunction cloneChildInCoordinates(\n graph: SceneGraph,\n src: SceneNode,\n sourceParent: SceneNode,\n targetParent: SceneNode,\n mode: NodeCloneMode = 'deep'\n): SceneNode {\n const componentScale =\n (src.componentScale * targetParent.componentScale) / sourceParent.componentScale\n return graph.createNode(src.type, targetParent.id, {\n ...cloneNodeProps(sourceInTargetCoordinates(src, componentScale), src.id, mode),\n componentScale\n })\n}\n\nexport function cloneChildrenWithMapping(\n graph: SceneGraph,\n sourceParentId: string,\n destParentId: string,\n mode: NodeCloneMode = 'deep'\n): void {\n // A cyclic component, such as an instance of an ancestor, would clone itself without end.\n if (sourceParentId === destParentId || graph.isDescendant(destParentId, sourceParentId)) return\n\n const sourceParent = graph.nodes.get(sourceParentId)\n const targetParent = graph.nodes.get(destParentId)\n if (!sourceParent || !targetParent) return\n\n for (const childId of sourceParent.childIds) {\n const src = graph.nodes.get(childId)\n if (!src) continue\n\n const clone = cloneChildInCoordinates(graph, src, sourceParent, targetParent, mode)\n\n if (src.childIds.length > 0) {\n cloneChildrenWithMapping(graph, childId, clone.id, mode)\n }\n }\n}\n\nexport function enclosingInstanceOverrideFields(graph: SceneGraph, node: SceneNode): Set<string>[] {\n const fields: Set<string>[] = []\n let parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n while (parent) {\n if (parent.type === 'INSTANCE') {\n fields.push(new Set(parent.instanceOverrides.descendants.get(node.id)?.keys()))\n }\n parent = parent.parentId ? graph.nodes.get(parent.parentId) : undefined\n }\n return fields\n}\n\nfunction childBindingProtection(\n graph: SceneGraph,\n child: SceneNode,\n overrides: InstanceOverrideState\n) {\n const fields = enclosingInstanceOverrideFields(graph, child)\n fields.push(new Set(overrides.descendants.get(child.id)?.keys()))\n const protectedField = bindingProtection(fields)\n return (field: string) => protectedField(field) || ownsSelfFillField(child, field)\n}\n\nfunction linkMatchedChild(\n overrides: InstanceOverrideState,\n instParentId: string,\n instChild: SceneNode,\n compChildId: string\n): void {\n if (instChild.type === 'INSTANCE') {\n setInstanceOverride(overrides, instParentId, instChild.id, 'sourceComponentId', compChildId)\n } else {\n instChild.componentId = compChildId\n }\n}\n\nfunction matchFallbackChildren(\n graph: SceneGraph,\n compParent: SceneNode,\n instParent: SceneNode,\n instParentId: string,\n overrides: InstanceOverrideState,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n const fallbackByType = new Map<SceneNode['type'], Map<string, SceneNode[]>>()\n const remainingCandidateCount = new Map<SceneNode['type'], number>()\n const unmatchedComponentCount = new Map<SceneNode['type'], number>()\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const child = graph.nodes.get(compChildId)\n if (child) {\n unmatchedComponentCount.set(child.type, (unmatchedComponentCount.get(child.type) ?? 0) + 1)\n }\n }\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || usedInstChildIds.has(child.id)) continue\n remainingCandidateCount.set(child.type, (remainingCandidateCount.get(child.type) ?? 0) + 1)\n let byName = fallbackByType.get(child.type)\n if (!byName) {\n byName = new Map()\n fallbackByType.set(child.type, byName)\n }\n const queue = byName.get(child.name)\n if (queue) queue.push(child)\n else byName.set(child.name, [child])\n }\n\n // Match by name and type with FIFO queues to preserve sibling order in linear time.\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const compChild = graph.nodes.get(compChildId)\n if (!compChild) continue\n const candidatesByName = fallbackByType.get(compChild.type)\n const candidateCount = remainingCandidateCount.get(compChild.type) ?? 0\n if (candidateCount > (unmatchedComponentCount.get(compChild.type) ?? 0)) continue\n const match = candidatesByName?.get(compChild.name)?.shift()\n if (!match) continue\n remainingCandidateCount.set(compChild.type, candidateCount - 1)\n instChildMap.set(compChildId, match)\n usedInstChildIds.add(match.id)\n linkMatchedChild(overrides, instParentId, match, compChildId)\n }\n}\n\nfunction sortInstanceChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n compChildOrder: string[],\n overrides: InstanceOverrideState,\n matched: ReadonlyMap<string, SceneNode>\n): void {\n // A replaced layer copies nothing, so its place comes from the layer it was matched to.\n const matchedLayer = new Map([...matched].map(([layerId, child]) => [child.id, layerId]))\n const orderMap = new Map<string, number>()\n for (let i = 0; i < compChildOrder.length; i++) orderMap.set(compChildOrder[i], i)\n\n const ranks = new Map<string, number>()\n for (let index = 0; index < instParent.childIds.length; index++) {\n const childId = instParent.childIds[index]\n const node = graph.nodes.get(childId)\n const mapped =\n matchedLayer.get(childId) ?? (node && copiedComponentLayerId(overrides, instParentId, node))\n const componentIndex = mapped ? orderMap.get(mapped) : undefined\n ranks.set(childId, componentIndex ?? compChildOrder.length + index)\n }\n const sorted = instParent.childIds.toSorted(\n (left, right) => (ranks.get(left) ?? 0) - (ranks.get(right) ?? 0)\n )\n // Move through the graph so the reorder is reported, as collaboration syncs it.\n sorted.forEach((childId, index) => {\n if (instParent.childIds[index] !== childId) graph.insertChildAt(childId, instParentId, index)\n })\n}\n\n/** True when syncing `compParentId` into `instParentId` would form a cycle. */\nfunction isCyclicSync(graph: SceneGraph, compParentId: string, instParentId: string): boolean {\n return compParentId === instParentId || graph.isDescendant(instParentId, compParentId)\n}\n\n/**\n * Children already linked to a component child: a layer an instance put in place of one, or a\n * copy by sourceComponentId or componentId.\n */\nfunction matchLinkedChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n overrides: InstanceOverrideState,\n owner: SceneNode | undefined,\n compParent: SceneNode,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n const compChildIdSet = new Set(compParent.childIds)\n const replacements = new Set<string>()\n // Replaced layers first: each keeps the place it took, whatever else claims it.\n for (const childId of instParent.childIds) {\n const replaced = replacedLayerIn(owner, childId)\n const layerId = replaced && replacedLayerMatch(graph, replaced, compParent.childIds)\n const child = graph.nodes.get(childId)\n if (!layerId || !child || instChildMap.has(layerId)) continue\n instChildMap.set(layerId, child)\n usedInstChildIds.add(child.id)\n replacements.add(child.id)\n }\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || replacements.has(child.id)) continue\n const mappedComponentId = copiedComponentLayerId(overrides, instParentId, child)\n if (mappedComponentId && compChildIdSet.has(mappedComponentId)) {\n // The first copy of a layer keeps it; a duplicate stays unmatched for the sync to remove.\n if (instChildMap.has(mappedComponentId)) continue\n instChildMap.set(mappedComponentId, child)\n usedInstChildIds.add(child.id)\n }\n }\n}\n\n/**\n * Pass 3 of a sync: bring along the copy of a layer moved here inside the component, bring back\n * one the sync removed when its layer returns, or clone a layer the instance has no copy of. A\n * clone takes its own subtree unless copies the instance has belong in it, which the recursion\n * moves in instead. Children left unmatched are the sync's to remove once it finishes.\n */\nfunction placeMissingChildren(\n graph: SceneGraph,\n compParent: SceneNode,\n instParent: SceneNode,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>,\n context: InstanceSyncContext\n): void {\n for (const child of instChildMap.values()) context.matched.add(child.id)\n\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const moved =\n unplacedCopy(graph, context, compChildId, instParent.id) ??\n restoreRemovedCopy(graph, context, compChildId, instParent.id)\n if (moved) {\n graph.insertChildAt(moved.id, instParent.id, instParent.childIds.length)\n instChildMap.set(compChildId, moved)\n usedInstChildIds.add(moved.id)\n context.matched.add(moved.id)\n continue\n }\n const src = graph.nodes.get(compChildId)\n if (!src) continue\n const clone = cloneChildInCoordinates(graph, src, compParent, instParent)\n if (src.childIds.length > 0 && !hasUnplacedCopiesBelow(graph, context, compChildId)) {\n cloneChildrenWithMapping(graph, compChildId, clone.id)\n }\n applyEnclosingAssignments(graph, clone)\n instChildMap.set(compChildId, clone)\n usedInstChildIds.add(clone.id)\n context.matched.add(clone.id)\n }\n for (const childId of instParent.childIds) {\n if (!usedInstChildIds.has(childId)) context.leftovers.add(childId)\n }\n}\n\nexport function syncChildren(\n graph: SceneGraph,\n compParentId: string,\n instParentId: string,\n overrides: InstanceOverrideState,\n context: InstanceSyncContext = createInstanceSyncContext(instParentId, overrides)\n): void {\n // An instance inside its own component would clone the component into itself without end.\n if (isCyclicSync(graph, compParentId, instParentId)) return\n\n const compParent = graph.nodes.get(compParentId)\n const instParent = graph.nodes.get(instParentId)\n if (!compParent || !instParent) return\n\n const instChildMap = new Map<string, SceneNode>()\n const usedInstChildIds = new Set<string>()\n\n // The instance that records overrides of these children is the same for all of them.\n const owner =\n instParent.type === 'INSTANCE'\n ? instParent\n : graph.closest(instParent.id, (node) => node.type === 'INSTANCE')\n\n // Pass 1: Direct matching via a replacement, sourceComponentId, or componentId\n matchLinkedChildren(\n graph,\n instParent,\n instParentId,\n overrides,\n owner,\n compParent,\n instChildMap,\n usedInstChildIds\n )\n\n // Pass 2: Fallback matching for unmatched children (e.g. from Figma imports)\n matchFallbackChildren(\n graph,\n compParent,\n instParent,\n instParentId,\n overrides,\n instChildMap,\n usedInstChildIds\n )\n\n placeMissingChildren(graph, compParent, instParent, instChildMap, usedInstChildIds, context)\n\n // Pass 4: Synchronize properties and recurse\n for (const compChildId of compParent.childIds) {\n const compChild = graph.nodes.get(compChildId)\n const instChild = instChildMap.get(compChildId)\n if (!compChild || !instChild) continue\n // A replaced layer is the instance's own: nothing of the layer it replaced reaches it, also\n // when it followed that layer here from elsewhere in the component.\n if (replacedLayerIn(owner, instChild.id) !== undefined) continue\n\n const protectedField = childBindingProtection(graph, instChild, overrides)\n const driven = propertyDrivenFields(graph, instChild, compChild)\n const componentScale =\n (compChild.componentScale * instParent.componentScale) / compParent.componentScale\n const effectiveSource = sourceWithEffectiveFill(graph, compChild, instChild)\n const source = sourceInTargetCoordinates(effectiveSource, componentScale)\n // Which properties a layer serves is the component's to say; a slot or exposed layer\n // created on the component becomes one in every instance.\n const updates: Partial<SceneNode> = {\n componentScale,\n componentPropertyReferences: structuredClone(compChild.componentPropertyReferences)\n }\n syncBindingFields(instChild, source, updates, protectedField)\n syncVariableModeFields(\n instChild,\n source,\n updates,\n (field) => driven.has(field) || protectedField(field)\n )\n const placement = copySyncedFields(updates, instChild, source, {\n compParent,\n instParent,\n factor: componentScale / compChild.componentScale,\n skip: (key) => driven.has(key) || isProtectedSyncField(instChild, key, protectedField)\n })\n Object.assign(updates, assignedFieldValues(graph, instChild, compChild))\n keepOwnContentSize(graph, updates, instChild, source, placement)\n updateSyncedProps(graph, instChild, updates)\n\n if (\n compChild.childIds.length > 0 &&\n !hasNodeInstanceOverride(overrides, instParentId, instChild.id, 'componentId') &&\n // The component's frame is the authority on which slot this is; instance copies of\n // its bindings are not synced.\n !ownsSlotContent(graph, instChild, slotPropertyId(compChild))\n ) {\n syncChildren(graph, compChildId, instChild.id, overrides, context)\n }\n }\n\n // Pass 5: Sort instance children to match component child order\n sortInstanceChildren(\n graph,\n instParent,\n instParentId,\n compParent.childIds,\n overrides,\n instChildMap\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAS,aACP,QACA,KACA,OACM;CACN,OAAO,OAAO;AAChB;AAEA,SAAgB,SACd,QACA,QACA,KACM;CACN,IAAI,QAAQ,SACV,aAAa,QAAQ,KAAK,UAAU,OAAO,KAAK,CAAC;MAC5C,IAAI,QAAQ,WACjB,aAAa,QAAQ,KAAK,YAAY,OAAO,OAAO,CAAC;MAChD,IAAI,QAAQ,WACjB,aAAa,QAAQ,KAAK,YAAY,OAAO,OAAO,CAAC;MAChD,IAAI,QAAQ,aACjB,aAAa,QAAQ,KAAK,cAAc,OAAO,SAAS,CAAC;MACpD,IAAI,QAAQ,kBAAkB;EAEnC,aAAa,QAAQ,KAAK,EAAE,GAAG,OAAO,eAAe,CAAC;EACtD,aAAa,QAAQ,yBAAyB,EAAE,GAAG,OAAO,sBAAsB,CAAC;CACnF,OAAO,IAAI,QAAQ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,UACC,UAAU,OAAO,IAAI,KAAK,KAAK,eAAe,KAAK,CACtD;EACA,MAAM,YAAY,iBAAiB,SAAS,WAAW,QAAQ;GAC7D;GACA;GACA,QAAQ,iBAAiB,UAAU;GACnC,OAAO,QAAQ,OAAO,IAAI,GAAG,KAAK,qBAAqB,WAAW,KAAK,cAAc;EACvF,CAAC;EACD,OAAO,OAAO,SAAS,oBAAoB,OAAO,WAAW,SAAS,CAAC;EACvE,mBAAmB,OAAO,SAAS,WAAW,QAAQ,SAAS;EAC/D,kBAAkB,OAAO,WAAW,OAAO;EAE3C,IACE,UAAU,SAAS,SAAS,KAC5B,CAACA,oBAAwB,WAAW,cAAc,UAAU,IAAI,aAAa,KAG7E,CAAC,gBAAgB,OAAO,WAAW,eAAe,SAAS,CAAC,GAE5D,aAAa,OAAO,aAAa,UAAU,IAAI,WAAW,OAAO;CAErE;CAGA,qBACE,OACA,YACA,cACA,WAAW,UACX,WACA,YACF;AACF"}
|
|
1
|
+
{"version":3,"file":"sync.js","names":["hasNodeInstanceOverride"],"sources":["../../src/instances/sync.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\n// Child cloning and property synchronization shared by instance creation, swap, and sync.\nimport { pick } from 'es-toolkit/object'\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport { cloneNodeProps, copyEffects, copyFills, copyStrokes, copyStyleRuns } from '../copy'\nimport type { NodeCloneMode } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport { scaleNodeChanges } from '../scaling/node'\nimport { ownsSlotContent, slotPropertyId } from '../slots/frames'\nimport {\n STROKE_LINE_FIELDS,\n STROKE_LINE_KEYS,\n strokeLine,\n type StrokeLines,\n withStrokeLines\n} from '../strokes'\nimport type { SceneNode } from '../types'\nimport { resolvedNumericBindings } from '../variables/bindings'\nimport { isNumericVariableBindingField, paintBindingTarget } from '../variables/fields'\nimport {\n applyBoundPaintColorsIn,\n copyAppliedBoundPaints,\n keepCopyBoundPaints\n} from '../variables/paints'\nimport { scaleVariableBindingUnits } from '../variables/units'\nimport { applyEnclosingAssignments, assignedFieldValues, propertyDrivenFields } from './assignments'\nimport { keepOwnContentSize, remeasureChangedText, type SyncedPlacement } from './content-size'\nimport {\n createInstanceSyncContext,\n hasUnplacedCopiesBelow,\n restoreRemovedCopy,\n unplacedCopy,\n type InstanceSyncContext\n} from './copies'\nimport { INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_FIELDS } from './fields'\nimport { ownsSelfFillField, sourceWithEffectiveFill } from './main-component'\nimport { syncedVariableModes } from './modes'\nimport {\n bindingOverrideField,\n copiedComponentLayerId,\n hasInstanceOverride as hasNodeInstanceOverride,\n overriddenBindingField,\n setInstanceOverride,\n type InstanceOverrideState\n} from './overrides'\nimport { PLACEMENT_FIELDS, placedByConstraints } from './placement'\nimport { replacedLayerIn, replacedLayerMatch } from './replacements'\nimport { followVectorGeometry } from './vector-geometry'\n\nfunction setSceneProp<K extends keyof SceneNode>(\n target: Partial<SceneNode>,\n key: K,\n value: SceneNode[K]\n): void {\n target[key] = value\n}\n\nexport function copyProp(\n target: Partial<SceneNode> | SceneNode,\n source: SceneNode,\n key: keyof SceneNode\n): void {\n if (key === 'fills') {\n setSceneProp(target, key, copyFills(source.fills))\n } else if (key === 'strokes') {\n setSceneProp(target, key, copyStrokes(source.strokes))\n } else if (key === 'effects') {\n setSceneProp(target, key, copyEffects(source.effects))\n } else if (key === 'styleRuns') {\n setSceneProp(target, key, copyStyleRuns(source.styleRuns))\n } else if (key === 'boundVariables') {\n // Shallow copy the binding map — values are variable IDs (strings), not objects\n setSceneProp(target, key, { ...source.boundVariables })\n setSceneProp(target, 'variableBindingScales', { ...source.variableBindingScales })\n } else if (key === 'variableModes') {\n setSceneProp(target, key, { ...source.variableModes })\n } else if (key === 'gridPosition') {\n // Shallow copy the grid position object — all fields are primitives\n setSceneProp(target, key, source.gridPosition ? { ...source.gridPosition } : null)\n } else if (key === 'targetAspectRatio') {\n setSceneProp(target, key, source.targetAspectRatio ? { ...source.targetAspectRatio } : null)\n } else {\n const value = source[key]\n setSceneProp(target, key, Array.isArray(value) ? structuredClone(value) : value)\n }\n}\n\nexport function bindingProtection(scopes: ReadonlySet<string>[]): (field: string) => boolean {\n const fields = new Set<string>()\n for (const scope of scopes) {\n const perField = [...scope].some((field) => overriddenBindingField(field) !== null)\n for (const field of scope) {\n if (field !== 'boundVariables' || !perField) fields.add(field)\n }\n }\n return (field) => {\n if (fields.has(field)) return true\n // Paints an instance set itself own their bindings too, bound or not.\n const binding = overriddenBindingField(field)\n if (binding === null) return false\n const paint = paintBindingTarget(binding)\n return paint !== null && fields.has(paint.list)\n }\n}\n\nexport function syncBindingFields(\n target: SceneNode,\n source: SceneNode,\n updates: Partial<SceneNode>,\n protectedField: (field: string) => boolean\n): void {\n if (protectedField('boundVariables')) return\n const bindings = { ...source.boundVariables }\n const scales = { ...source.variableBindingScales }\n for (const field of new Set([\n ...Object.keys(source.boundVariables),\n ...Object.keys(target.boundVariables),\n ...Object.keys(target.variableBindingScales)\n ])) {\n if (!protectedField(bindingOverrideField(field))) continue\n if (!Object.hasOwn(target.boundVariables, field)) Reflect.deleteProperty(bindings, field)\n else bindings[field] = target.boundVariables[field]\n if (target.variableBindingScales[field] === undefined) Reflect.deleteProperty(scales, field)\n else scales[field] = target.variableBindingScales[field]\n }\n updates.boundVariables = bindings\n updates.variableBindingScales = scales\n}\n\n/**\n * Takes the component layer's variable modes, but those the copy overrides, collection by\n * collection. A nested instance's own claims count too, as its enclosing component syncs it.\n */\nexport function syncVariableModeFields(\n target: SceneNode,\n source: SceneNode,\n updates: Partial<SceneNode>,\n protectedField: (field: string) => boolean\n): void {\n const ownClaim = (field: string) =>\n target.type === 'INSTANCE' && target.instanceOverrides.self.has(field)\n const modes = syncedVariableModes(\n target,\n source,\n (field) => protectedField(field) || ownClaim(field)\n )\n if (modes) updates.variableModes = modes\n}\n\nexport function isProtectedSyncField(\n node: SceneNode,\n key: string,\n protectedField: (field: string) => boolean\n): boolean {\n return (\n protectedField(key) ||\n (key in node.boundVariables &&\n (protectedField('boundVariables') || protectedField(bindingOverrideField(key))))\n )\n}\n\nexport function sourceInTargetCoordinates(source: SceneNode, targetScale: number): SceneNode {\n const factor = targetScale / source.componentScale\n if (!Number.isFinite(factor) || factor <= 0) throw new Error('Invalid component coordinate scale')\n if (factor === 1) return source\n const scaled = scaleNodeChanges(source, factor, true)\n return {\n ...source,\n ...scaled,\n ...scaleVariableBindingUnits(source, factor, scaled.styleRuns)\n }\n}\n\ninterface SyncedFieldsInput {\n compParent: SceneNode\n instParent: SceneNode\n /** The component's coordinates in the copy's. */\n factor: number\n /** Fields the copy keeps: overridden, bound, or driven by a property. */\n skip: (key: string) => boolean\n}\n\n/** The fields a copy takes from its component's layer, placed in the copy's parent. */\nfunction copySyncedFields(\n updates: Partial<SceneNode>,\n copy: SceneNode,\n source: SceneNode,\n { compParent, instParent, factor, skip }: SyncedFieldsInput\n): SyncedPlacement {\n // In an auto layout flow the layout places the copy, as it placed the component's layer.\n const placedByLayout = instParent.layoutMode !== 'NONE' && source.layoutPositioning !== 'ABSOLUTE'\n const placed = placedByLayout\n ? source\n : placedByConstraints(source, compParent, instParent, factor)\n for (const key of INSTANCE_SYNC_FIELDS) {\n // Bindings and modes merge entry by entry, apart from this loop.\n if (key === 'boundVariables' || key === 'variableModes') continue\n if (placedByLayout && (key === 'x' || key === 'y')) continue\n if (skip(key)) continue\n const owner = INSTANCE_SYNC_FIELD_OWNERS[key]\n if (owner && skip(owner)) continue\n const from = PLACEMENT_FIELDS.has(key) ? placed : source\n // Most fields already match: comparing first spares cloning them for nothing.\n if (isEqual(copy[key], from[key])) continue\n copyProp(updates, from, key)\n }\n // New paints bring their style link, unless the copy keeps a style of its own.\n if (updates.fills)\n updates.fillStyleId = skip('fillStyleId') ? copy.fillStyleId : source.fillStyleId\n followVectorGeometry(updates, copy, source)\n remeasureChangedText(updates, copy)\n return { placed, x: !placedByLayout && !skip('x'), y: !placedByLayout && !skip('y') }\n}\n\nexport function updateSyncedProps(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>,\n /** A field the copy keeps as its own, which the sync leaves as it is. */\n kept: (field: string) => boolean = () => false\n): void {\n resolveBoundNumbersInPlace(graph, target, updates, kept)\n if (updates.fills || updates.strokes || updates.boundVariables) {\n applySyncedModes(graph, target, updates)\n keepCopyBoundPaints(graph, target, updates)\n }\n // After the copy's own bound paints, which can bring its strokes into the write.\n applySyncedStrokeLines(graph, target, updates, kept)\n const changed = Object.fromEntries(\n Object.entries(updates).filter(\n ([key, value]) => !isEqual(target[key as keyof SceneNode], value)\n )\n ) as Partial<SceneNode>\n if (changed.fills && updates.fillStyleId !== undefined) changed.fillStyleId = updates.fillStyleId\n if (Object.keys(changed).length) graph.updateNode(target.id, changed)\n}\n\n/**\n * A bound number the sync writes takes the value it resolves to where the copy sits, not the\n * one its component holds: an instance that sets another mode, or sits in one that does, shows\n * that mode's value, as Figma draws it. A field the sync leaves alone, such as one an instance\n * overrides, keeps its own value.\n */\nfunction resolveBoundNumbersInPlace(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>,\n kept: (field: string) => boolean\n): void {\n const bound = updates.boundVariables ?? target.boundVariables\n // The fields the sync writes, and the ones it binds anew, which keep an equal value only in\n // the component's mode.\n const rebound = updates.boundVariables\n ? Object.keys(bound).filter((field) => bound[field] !== target.boundVariables[field])\n : []\n const synced = uniq([...Object.keys(updates), ...rebound]).filter(\n (field) => isNumericVariableBindingField(field) && bound[field] && !kept(field)\n )\n if (synced.length === 0) return\n applySyncedModes(graph, target, updates)\n const resolved = resolvedNumericBindings(graph, { ...target, ...updates })\n Object.assign(updates, pick(resolved, synced as (keyof SceneNode)[]))\n}\n\n/** The modes the copy takes in this sync decide what its bindings resolve to. */\nfunction applySyncedModes(graph: SceneGraph, target: SceneNode, updates: Partial<SceneNode>): void {\n if (updates.variableModes && !isEqual(updates.variableModes, target.variableModes))\n graph.updateNode(target.id, { variableModes: updates.variableModes })\n}\n\n/**\n * Strokes a sync or swap gives a copy draw with the copy's own line fields: the weight,\n * alignment, cap, join, or dash it overrides, and a bound weight resolved in its modes. Figma\n * keeps a stroke weight override when the component's color changes (live).\n */\nexport function applySyncedStrokeLines(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>,\n kept: (field: string) => boolean\n): void {\n const strokes = updates.strokes\n const first = strokes?.at(0)\n if (!strokes || !first) return\n const boundWeight = kept('strokeWeight')\n ? undefined\n : (updates.boundVariables ?? target.boundVariables).strokeWeight\n const weightScale =\n (updates.variableBindingScales ?? target.variableBindingScales).strokeWeight ?? 1\n const resolvedWeight = boundWeight\n ? graph.resolveNumberVariableForNode(target.id, boundWeight, 'active')\n : undefined\n const lines: StrokeLines = {}\n let set = false\n for (const key of STROKE_LINE_KEYS) {\n const field = STROKE_LINE_FIELDS[key]\n const own = kept(field)\n // A bound weight takes the value it resolves to where the copy sits, not its component's.\n const synced = own ? target[field] : updates[field]\n const value =\n field === 'strokeWeight' && resolvedWeight !== undefined\n ? resolvedWeight * weightScale\n : synced\n if (value === undefined) continue\n // A field the copy overrides holds for every stroke; the component's own values keep its\n // strokes' differences unless a binding resolved the first one apart.\n const differs = own\n ? strokes.some((stroke) => !isEqual(value, strokeLine(stroke, key)))\n : !isEqual(value, strokeLine(first, key))\n if (!differs) continue\n Reflect.set(lines, key, value)\n set = true\n }\n if (set) updates.strokes = withStrokeLines(strokes, lines)\n}\n\nfunction cloneChildInCoordinates(\n graph: SceneGraph,\n src: SceneNode,\n sourceParent: SceneNode,\n targetParent: SceneNode,\n mode: NodeCloneMode = 'deep'\n): SceneNode {\n const componentScale =\n (src.componentScale * targetParent.componentScale) / sourceParent.componentScale\n const clone = graph.createNode(src.type, targetParent.id, {\n ...cloneNodeProps(sourceInTargetCoordinates(src, componentScale), src.id, mode),\n componentScale\n })\n copyAppliedBoundPaints(src, clone)\n return clone\n}\n\nexport function cloneChildrenWithMapping(\n graph: SceneGraph,\n sourceParentId: string,\n destParentId: string,\n mode: NodeCloneMode = 'deep'\n): void {\n // A cyclic component, such as an instance of an ancestor, would clone itself without end.\n if (sourceParentId === destParentId || graph.isDescendant(destParentId, sourceParentId)) return\n\n const sourceParent = graph.nodes.get(sourceParentId)\n const targetParent = graph.nodes.get(destParentId)\n if (!sourceParent || !targetParent) return\n\n for (const childId of sourceParent.childIds) {\n const src = graph.nodes.get(childId)\n if (!src) continue\n\n const clone = cloneChildInCoordinates(graph, src, sourceParent, targetParent, mode)\n\n if (src.childIds.length > 0) {\n cloneChildrenWithMapping(graph, childId, clone.id, mode)\n }\n }\n}\n\nexport function enclosingInstanceOverrideFields(graph: SceneGraph, node: SceneNode): Set<string>[] {\n const fields: Set<string>[] = []\n let parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n while (parent) {\n if (parent.type === 'INSTANCE') {\n fields.push(new Set(parent.instanceOverrides.descendants.get(node.id)?.keys()))\n }\n parent = parent.parentId ? graph.nodes.get(parent.parentId) : undefined\n }\n return fields\n}\n\nfunction childBindingProtection(\n graph: SceneGraph,\n child: SceneNode,\n overrides: InstanceOverrideState\n) {\n const fields = enclosingInstanceOverrideFields(graph, child)\n fields.push(new Set(overrides.descendants.get(child.id)?.keys()))\n const protectedField = bindingProtection(fields)\n return (field: string) => protectedField(field) || ownsSelfFillField(child, field)\n}\n\n/** Links a copy to the component layer it matched, reporting each changed node and its owner. */\nfunction linkMatchedChild(\n graph: SceneGraph,\n context: InstanceSyncContext,\n instParentId: string,\n instChild: SceneNode,\n compChildId: string\n): void {\n const { overrides } = context\n const recorded = hasNodeInstanceOverride(\n overrides,\n instParentId,\n instChild.id,\n 'sourceComponentId'\n )\n if (instChild.type === 'INSTANCE' || recorded) {\n const owner = graph.nodes.get(context.instanceId)\n graph.willChangeNode(owner)\n setInstanceOverride(overrides, instParentId, instChild.id, 'sourceComponentId', compChildId)\n if (owner) graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides })\n }\n if (instChild.type !== 'INSTANCE') graph.updateNode(instChild.id, { componentId: compChildId })\n}\n\nfunction matchFallbackChildren(\n graph: SceneGraph,\n compParent: SceneNode,\n instParent: SceneNode,\n instParentId: string,\n context: InstanceSyncContext,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n const fallbackByType = new Map<SceneNode['type'], Map<string, SceneNode[]>>()\n const remainingCandidateCount = new Map<SceneNode['type'], number>()\n const unmatchedComponentCount = new Map<SceneNode['type'], number>()\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const child = graph.nodes.get(compChildId)\n if (child) {\n unmatchedComponentCount.set(child.type, (unmatchedComponentCount.get(child.type) ?? 0) + 1)\n }\n }\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || usedInstChildIds.has(child.id)) continue\n remainingCandidateCount.set(child.type, (remainingCandidateCount.get(child.type) ?? 0) + 1)\n let byName = fallbackByType.get(child.type)\n if (!byName) {\n byName = new Map()\n fallbackByType.set(child.type, byName)\n }\n const queue = byName.get(child.name)\n if (queue) queue.push(child)\n else byName.set(child.name, [child])\n }\n\n // Match by name and type with FIFO queues to preserve sibling order in linear time.\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const compChild = graph.nodes.get(compChildId)\n if (!compChild) continue\n const candidatesByName = fallbackByType.get(compChild.type)\n const candidateCount = remainingCandidateCount.get(compChild.type) ?? 0\n if (candidateCount > (unmatchedComponentCount.get(compChild.type) ?? 0)) continue\n const match = candidatesByName?.get(compChild.name)?.shift()\n if (!match) continue\n remainingCandidateCount.set(compChild.type, candidateCount - 1)\n instChildMap.set(compChildId, match)\n usedInstChildIds.add(match.id)\n linkMatchedChild(graph, context, instParentId, match, compChildId)\n }\n}\n\nfunction sortInstanceChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n compChildOrder: string[],\n overrides: InstanceOverrideState,\n matched: ReadonlyMap<string, SceneNode>\n): void {\n // A replaced layer copies nothing, so its place comes from the layer it was matched to.\n const matchedLayer = new Map([...matched].map(([layerId, child]) => [child.id, layerId]))\n const orderMap = new Map<string, number>()\n for (let i = 0; i < compChildOrder.length; i++) orderMap.set(compChildOrder[i], i)\n\n const ranks = new Map<string, number>()\n for (let index = 0; index < instParent.childIds.length; index++) {\n const childId = instParent.childIds[index]\n const node = graph.nodes.get(childId)\n const mapped =\n matchedLayer.get(childId) ?? (node && copiedComponentLayerId(overrides, instParentId, node))\n const componentIndex = mapped ? orderMap.get(mapped) : undefined\n ranks.set(childId, componentIndex ?? compChildOrder.length + index)\n }\n const sorted = instParent.childIds.toSorted(\n (left, right) => (ranks.get(left) ?? 0) - (ranks.get(right) ?? 0)\n )\n // Move through the graph so the reorder is reported, as collaboration syncs it.\n sorted.forEach((childId, index) => {\n if (instParent.childIds[index] !== childId) graph.insertChildAt(childId, instParentId, index)\n })\n}\n\n/** True when syncing `compParentId` into `instParentId` would form a cycle. */\nfunction isCyclicSync(graph: SceneGraph, compParentId: string, instParentId: string): boolean {\n return compParentId === instParentId || graph.isDescendant(instParentId, compParentId)\n}\n\n/**\n * Children already linked to a component child: a layer an instance put in place of one, or a\n * copy by sourceComponentId or componentId.\n */\nfunction matchLinkedChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n overrides: InstanceOverrideState,\n owner: SceneNode | undefined,\n compParent: SceneNode,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n const compChildIdSet = new Set(compParent.childIds)\n const replacements = new Set<string>()\n // Replaced layers first: each keeps the place it took, whatever else claims it.\n for (const childId of instParent.childIds) {\n const replaced = replacedLayerIn(owner, childId)\n const layerId = replaced && replacedLayerMatch(graph, replaced, compParent.childIds)\n const child = graph.nodes.get(childId)\n if (!layerId || !child || instChildMap.has(layerId)) continue\n instChildMap.set(layerId, child)\n usedInstChildIds.add(child.id)\n replacements.add(child.id)\n }\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || replacements.has(child.id)) continue\n const mappedComponentId = copiedComponentLayerId(overrides, instParentId, child)\n if (mappedComponentId && compChildIdSet.has(mappedComponentId)) {\n // The first copy of a layer keeps it; a duplicate stays unmatched for the sync to remove.\n if (instChildMap.has(mappedComponentId)) continue\n instChildMap.set(mappedComponentId, child)\n usedInstChildIds.add(child.id)\n }\n }\n}\n\n/**\n * Pass 3 of a sync: bring along the copy of a layer moved here inside the component, bring back\n * one the sync removed when its layer returns, or clone a layer the instance has no copy of. A\n * clone takes its own subtree unless copies the instance has belong in it, which the recursion\n * moves in instead. Children left unmatched are the sync's to remove once it finishes.\n */\nfunction placeMissingChildren(\n graph: SceneGraph,\n compParent: SceneNode,\n instParent: SceneNode,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>,\n context: InstanceSyncContext\n): void {\n for (const child of instChildMap.values()) context.matched.add(child.id)\n\n for (const compChildId of compParent.childIds) {\n if (instChildMap.has(compChildId)) continue\n const moved =\n unplacedCopy(graph, context, compChildId, instParent.id) ??\n restoreRemovedCopy(graph, context, compChildId, instParent.id)\n if (moved) {\n graph.insertChildAt(moved.id, instParent.id, instParent.childIds.length)\n instChildMap.set(compChildId, moved)\n usedInstChildIds.add(moved.id)\n context.matched.add(moved.id)\n continue\n }\n const src = graph.nodes.get(compChildId)\n if (!src) continue\n const clone = cloneChildInCoordinates(graph, src, compParent, instParent)\n if (src.childIds.length > 0 && !hasUnplacedCopiesBelow(graph, context, compChildId)) {\n cloneChildrenWithMapping(graph, compChildId, clone.id)\n }\n applyEnclosingAssignments(graph, clone)\n applyBoundPaintColorsIn(graph, clone.id)\n instChildMap.set(compChildId, clone)\n usedInstChildIds.add(clone.id)\n context.matched.add(clone.id)\n }\n for (const childId of instParent.childIds) {\n if (!usedInstChildIds.has(childId)) context.leftovers.add(childId)\n }\n}\n\nexport function syncChildren(\n graph: SceneGraph,\n compParentId: string,\n instParentId: string,\n overrides: InstanceOverrideState,\n context: InstanceSyncContext = createInstanceSyncContext(instParentId, overrides)\n): void {\n // An instance inside its own component would clone the component into itself without end.\n if (isCyclicSync(graph, compParentId, instParentId)) return\n\n const compParent = graph.nodes.get(compParentId)\n const instParent = graph.nodes.get(instParentId)\n if (!compParent || !instParent) return\n\n const instChildMap = new Map<string, SceneNode>()\n const usedInstChildIds = new Set<string>()\n\n // The instance that records overrides of these children is the same for all of them.\n const owner =\n instParent.type === 'INSTANCE'\n ? instParent\n : graph.closest(instParent.id, (node) => node.type === 'INSTANCE')\n\n // Pass 1: Direct matching via a replacement, sourceComponentId, or componentId\n matchLinkedChildren(\n graph,\n instParent,\n instParentId,\n overrides,\n owner,\n compParent,\n instChildMap,\n usedInstChildIds\n )\n\n // Pass 2: Fallback matching for unmatched children (e.g. from Figma imports)\n matchFallbackChildren(\n graph,\n compParent,\n instParent,\n instParentId,\n context,\n instChildMap,\n usedInstChildIds\n )\n\n placeMissingChildren(graph, compParent, instParent, instChildMap, usedInstChildIds, context)\n\n // Pass 4: Synchronize properties and recurse\n for (const compChildId of compParent.childIds) {\n const compChild = graph.nodes.get(compChildId)\n const instChild = instChildMap.get(compChildId)\n if (!compChild || !instChild) continue\n // A replaced layer is the instance's own: nothing of the layer it replaced reaches it, also\n // when it followed that layer here from elsewhere in the component.\n if (replacedLayerIn(owner, instChild.id) !== undefined) continue\n\n const protectedField = childBindingProtection(graph, instChild, overrides)\n const driven = propertyDrivenFields(graph, instChild, compChild)\n const kept = (key: string) =>\n driven.has(key) || isProtectedSyncField(instChild, key, protectedField)\n const componentScale =\n (compChild.componentScale * instParent.componentScale) / compParent.componentScale\n const effectiveSource = sourceWithEffectiveFill(graph, compChild, instChild)\n const source = sourceInTargetCoordinates(effectiveSource, componentScale)\n // Which properties a layer serves is the component's to say; a slot or exposed layer\n // created on the component becomes one in every instance.\n const updates: Partial<SceneNode> = {\n componentScale,\n componentPropertyReferences: structuredClone(compChild.componentPropertyReferences)\n }\n syncBindingFields(instChild, source, updates, protectedField)\n syncVariableModeFields(\n instChild,\n source,\n updates,\n (field) => driven.has(field) || protectedField(field)\n )\n const placement = copySyncedFields(updates, instChild, source, {\n compParent,\n instParent,\n factor: componentScale / compChild.componentScale,\n skip: kept\n })\n Object.assign(updates, assignedFieldValues(graph, instChild, compChild))\n keepOwnContentSize(graph, updates, instChild, source, placement)\n updateSyncedProps(graph, instChild, updates, kept)\n\n if (\n compChild.childIds.length > 0 &&\n !hasNodeInstanceOverride(overrides, instParentId, instChild.id, 'componentId') &&\n // The component's frame is the authority on which slot this is; instance copies of\n // its bindings are not synced.\n !ownsSlotContent(graph, instChild, slotPropertyId(compChild))\n ) {\n syncChildren(graph, compChildId, instChild.id, overrides, context)\n }\n }\n\n // Pass 5: Sort instance children to match component child order\n sortInstanceChildren(\n graph,\n instParent,\n instParentId,\n compParent.childIds,\n overrides,\n instChildMap\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAS,aACP,QACA,KACA,OACM;CACN,OAAO,OAAO;AAChB;AAEA,SAAgB,SACd,QACA,QACA,KACM;CACN,IAAI,QAAQ,SACV,aAAa,QAAQ,KAAK,UAAU,OAAO,KAAK,CAAC;MAC5C,IAAI,QAAQ,WACjB,aAAa,QAAQ,KAAK,YAAY,OAAO,OAAO,CAAC;MAChD,IAAI,QAAQ,WACjB,aAAa,QAAQ,KAAK,YAAY,OAAO,OAAO,CAAC;MAChD,IAAI,QAAQ,aACjB,aAAa,QAAQ,KAAK,cAAc,OAAO,SAAS,CAAC;MACpD,IAAI,QAAQ,kBAAkB;EAEnC,aAAa,QAAQ,KAAK,EAAE,GAAG,OAAO,eAAe,CAAC;EACtD,aAAa,QAAQ,yBAAyB,EAAE,GAAG,OAAO,sBAAsB,CAAC;CACnF,OAAO,IAAI,QAAQ,iBACjB,aAAa,QAAQ,KAAK,EAAE,GAAG,OAAO,cAAc,CAAC;MAChD,IAAI,QAAQ,gBAEjB,aAAa,QAAQ,KAAK,OAAO,eAAe,EAAE,GAAG,OAAO,aAAa,IAAI,IAAI;MAC5E,IAAI,QAAQ,qB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GACnC,MAAM;EACR,CAAC;EACD,OAAO,OAAO,SAAS,oBAAoB,OAAO,WAAW,SAAS,CAAC;EACvE,mBAAmB,OAAO,SAAS,WAAW,QAAQ,SAAS;EAC/D,kBAAkB,OAAO,WAAW,SAAS,IAAI;EAEjD,IACE,UAAU,SAAS,SAAS,KAC5B,CAACA,oBAAwB,WAAW,cAAc,UAAU,IAAI,aAAa,KAG7E,CAAC,gBAAgB,OAAO,WAAW,eAAe,SAAS,CAAC,GAE5D,aAAa,OAAO,aAAa,UAAU,IAAI,WAAW,OAAO;CAErE;CAGA,qBACE,OACA,YACA,cACA,WAAW,UACX,WACA,YACF;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SceneNode } from "../types.js";
|
|
2
|
+
//#region src/layout/draw-order.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* A frame's children in the order they are drawn, back to front. An auto layout frame asked for
|
|
5
|
+
* Figma's "Reverse Z-index" paints them in reverse: the first layer sits on top, so the last one
|
|
6
|
+
* is drawn first. Everywhere else, and in a frame without auto layout, layer order draws.
|
|
7
|
+
*/
|
|
8
|
+
declare function drawnChildIds(parent: Pick<SceneNode, 'childIds' | 'layoutMode' | 'itemReverseZIndex'>): string[];
|
|
9
|
+
//#endregion
|
|
10
|
+
export { drawnChildIds };
|
|
11
|
+
//# sourceMappingURL=draw-order.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw-order.d.ts","names":[],"sources":["../../src/layout/draw-order.ts"],"mappings":";;;;;;;iBAOgB,cACd,QAAQ,KAAK"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/layout/draw-order.ts
|
|
2
|
+
/**
|
|
3
|
+
* A frame's children in the order they are drawn, back to front. An auto layout frame asked for
|
|
4
|
+
* Figma's "Reverse Z-index" paints them in reverse: the first layer sits on top, so the last one
|
|
5
|
+
* is drawn first. Everywhere else, and in a frame without auto layout, layer order draws.
|
|
6
|
+
*/
|
|
7
|
+
function drawnChildIds(parent) {
|
|
8
|
+
if (parent.layoutMode === "NONE" || !parent.itemReverseZIndex) return parent.childIds;
|
|
9
|
+
return [...parent.childIds].reverse();
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { drawnChildIds };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=draw-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw-order.js","names":[],"sources":["../../src/layout/draw-order.ts"],"sourcesContent":["import type { SceneNode } from '../types'\n\n/**\n * A frame's children in the order they are drawn, back to front. An auto layout frame asked for\n * Figma's \"Reverse Z-index\" paints them in reverse: the first layer sits on top, so the last one\n * is drawn first. Everywhere else, and in a frame without auto layout, layer order draws.\n */\nexport function drawnChildIds(\n parent: Pick<SceneNode, 'childIds' | 'layoutMode' | 'itemReverseZIndex'>\n): string[] {\n if (parent.layoutMode === 'NONE' || !parent.itemReverseZIndex) return parent.childIds\n return [...parent.childIds].reverse()\n}\n"],"mappings":";;;;;;AAOA,SAAgB,cACd,QACU;CACV,IAAI,OAAO,eAAe,UAAU,CAAC,OAAO,mBAAmB,OAAO,OAAO;CAC7E,OAAO,CAAC,GAAG,OAAO,QAAQ,CAAC,CAAC,QAAQ;AACtC"}
|
package/dist/layout/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AutoLayoutDirection, paddingFromShorthand, parseAutoLayoutDirection, parseCounterAxisAlign, parseLayoutAlignSelf, parsePrimaryAxisAlign } from "./keywords.js";
|
|
2
2
|
import { aspectRatioLockEditable, enforcedAspectRatio, lockedAspectRatioTarget, recapturedAspectRatio, sizeKeepingAspectRatio } from "./aspect-ratio.js";
|
|
3
|
+
import { drawnChildIds } from "./draw-order.js";
|
|
3
4
|
import { AUTO_LAYOUT_GRID_COUNT, LayoutGuideLine, LayoutGuideSection, isAutoGridCount, layoutGridCount, layoutGuideLines, layoutGuideSections } from "./guides.js";
|
|
4
5
|
import { LayoutSizingAxis, autoLayoutSizingFields, fillSizingFields, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, textAutoResizeFor } from "./sizing.js";
|
|
5
|
-
export { AUTO_LAYOUT_GRID_COUNT, AutoLayoutDirection, LayoutGuideLine, LayoutGuideSection, LayoutSizingAxis, aspectRatioLockEditable, autoLayoutSizingFields, enforcedAspectRatio, fillSizingFields, isAutoGridCount, layoutGridCount, layoutGuideLines, layoutGuideSections, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, lockedAspectRatioTarget, paddingFromShorthand, parseAutoLayoutDirection, parseCounterAxisAlign, parseLayoutAlignSelf, parsePrimaryAxisAlign, recapturedAspectRatio, sizeKeepingAspectRatio, textAutoResizeFor };
|
|
6
|
+
export { AUTO_LAYOUT_GRID_COUNT, AutoLayoutDirection, LayoutGuideLine, LayoutGuideSection, LayoutSizingAxis, aspectRatioLockEditable, autoLayoutSizingFields, drawnChildIds, enforcedAspectRatio, fillSizingFields, isAutoGridCount, layoutGridCount, layoutGuideLines, layoutGuideSections, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, lockedAspectRatioTarget, paddingFromShorthand, parseAutoLayoutDirection, parseCounterAxisAlign, parseLayoutAlignSelf, parsePrimaryAxisAlign, recapturedAspectRatio, sizeKeepingAspectRatio, textAutoResizeFor };
|