@open-pencil/scene-graph 0.17.0-beta.4 → 0.17.0-beta.6
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/buffered-events.js +1 -1
- package/dist/buffered-events.js.map +1 -1
- package/dist/clipping.d.ts +7 -1
- package/dist/clipping.d.ts.map +1 -1
- package/dist/clipping.js +23 -19
- package/dist/clipping.js.map +1 -1
- package/dist/comments/schema.d.ts.map +1 -1
- package/dist/comments/schema.js +1 -0
- package/dist/comments/schema.js.map +1 -1
- package/dist/comments/threads.d.ts +2 -0
- package/dist/comments/threads.d.ts.map +1 -1
- package/dist/comments/threads.js +11 -5
- package/dist/comments/threads.js.map +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/properties.d.ts +1 -3
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +3 -10
- package/dist/components/properties.js.map +1 -1
- package/dist/constants.d.ts +12 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +42 -1
- package/dist/constants.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +2 -0
- package/dist/copy.js.map +1 -1
- package/dist/corners.d.ts +22 -0
- package/dist/corners.d.ts.map +1 -0
- package/dist/corners.js +52 -0
- package/dist/corners.js.map +1 -0
- package/dist/css/grid.d.ts +4 -1
- package/dist/css/grid.d.ts.map +1 -1
- package/dist/css/grid.js +40 -7
- package/dist/css/grid.js.map +1 -1
- package/dist/css/index.d.ts +3 -3
- package/dist/css/index.js +3 -3
- package/dist/css/layout.d.ts +13 -1
- package/dist/css/layout.d.ts.map +1 -1
- package/dist/css/layout.js +26 -1
- package/dist/css/layout.js.map +1 -1
- package/dist/css/values.d.ts +23 -1
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +39 -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 +68 -3
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +159 -25
- package/dist/geometry.js.map +1 -1
- package/dist/gradient.d.ts +9 -2
- package/dist/gradient.d.ts.map +1 -1
- package/dist/gradient.js +29 -1
- package/dist/gradient.js.map +1 -1
- package/dist/graph.d.ts +9 -2
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +46 -10
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +4 -3
- package/dist/group-bounds.js.map +1 -1
- package/dist/guides.d.ts +11 -2
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +30 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +57 -5
- package/dist/hit-test.js.map +1 -1
- package/dist/icons/fit.d.ts +17 -0
- package/dist/icons/fit.d.ts.map +1 -0
- package/dist/icons/fit.js +21 -0
- package/dist/icons/fit.js.map +1 -0
- package/dist/icons/glyph.d.ts.map +1 -1
- package/dist/icons/glyph.js +5 -4
- package/dist/icons/glyph.js.map +1 -1
- package/dist/icons/index.d.ts +2 -1
- package/dist/icons/index.js +2 -1
- package/dist/ids.js +1 -1
- package/dist/ids.js.map +1 -1
- package/dist/images.d.ts +14 -4
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +45 -5
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/assignments.js +39 -6
- package/dist/instances/assignments.js.map +1 -1
- package/dist/instances/index.d.ts +6 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +58 -9
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +2 -2
- package/dist/instances/kept-overrides.js.map +1 -1
- package/dist/instances/matching.js +68 -0
- package/dist/instances/matching.js.map +1 -0
- package/dist/instances/overrides.d.ts +4 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +13 -1
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/protection.js +67 -0
- package/dist/instances/protection.js.map +1 -0
- package/dist/instances/swap.js +7 -5
- package/dist/instances/swap.js.map +1 -1
- package/dist/instances/sync.js +34 -116
- package/dist/instances/sync.js.map +1 -1
- package/dist/layout/guides.d.ts +17 -1
- package/dist/layout/guides.d.ts.map +1 -1
- package/dist/layout/guides.js +31 -11
- package/dist/layout/guides.js.map +1 -1
- package/dist/layout/index.d.ts +5 -2
- package/dist/layout/index.js +5 -2
- package/dist/layout/limits.d.ts +40 -0
- package/dist/layout/limits.d.ts.map +1 -0
- package/dist/layout/limits.js +54 -0
- package/dist/layout/limits.js.map +1 -0
- package/dist/layout/sizing.d.ts.map +1 -1
- package/dist/layout/sizing.js +0 -1
- package/dist/layout/sizing.js.map +1 -1
- package/dist/layout/spacing.d.ts +10 -0
- package/dist/layout/spacing.d.ts.map +1 -0
- package/dist/layout/spacing.js +12 -0
- package/dist/layout/spacing.js.map +1 -0
- package/dist/layout/strokes.d.ts +10 -0
- package/dist/layout/strokes.d.ts.map +1 -0
- package/dist/layout/strokes.js +30 -0
- package/dist/layout/strokes.js.map +1 -0
- package/dist/masks.d.ts +28 -0
- package/dist/masks.d.ts.map +1 -0
- package/dist/masks.js +53 -0
- package/dist/masks.js.map +1 -0
- package/dist/matrix.d.ts +2 -1
- package/dist/matrix.d.ts.map +1 -1
- package/dist/matrix.js +14 -1
- package/dist/matrix.js.map +1 -1
- package/dist/node-defaults.d.ts +9 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +65 -38
- package/dist/node-defaults.js.map +1 -1
- package/dist/outline/flatten.d.ts.map +1 -1
- package/dist/outline/flatten.js +24 -17
- package/dist/outline/flatten.js.map +1 -1
- package/dist/outline/hit.d.ts +2 -8
- package/dist/outline/hit.d.ts.map +1 -1
- package/dist/outline/hit.js +16 -25
- package/dist/outline/hit.js.map +1 -1
- package/dist/outline/index.d.ts +3 -3
- package/dist/outline/index.js +3 -3
- package/dist/outline/shapes.d.ts +3 -1
- package/dist/outline/shapes.d.ts.map +1 -1
- package/dist/outline/shapes.js +18 -39
- package/dist/outline/shapes.js.map +1 -1
- package/dist/paints/index.d.ts +3 -1
- package/dist/paints/index.js +3 -1
- package/dist/paints/pattern.d.ts +13 -0
- package/dist/paints/pattern.d.ts.map +1 -0
- package/dist/paints/pattern.js +47 -0
- package/dist/paints/pattern.js.map +1 -0
- package/dist/paints/shows.d.ts +11 -0
- package/dist/paints/shows.d.ts.map +1 -0
- package/dist/paints/shows.js +16 -0
- package/dist/paints/shows.js.map +1 -0
- package/dist/parse-path.d.ts +4 -1
- package/dist/parse-path.d.ts.map +1 -1
- package/dist/parse-path.js +15 -1
- package/dist/parse-path.js.map +1 -1
- package/dist/paths/arc.d.ts +32 -0
- package/dist/paths/arc.d.ts.map +1 -0
- package/dist/paths/arc.js +49 -0
- package/dist/paths/arc.js.map +1 -0
- package/dist/paths/index.d.ts +5 -0
- package/dist/paths/index.js +5 -0
- package/dist/paths/network.d.ts +63 -0
- package/dist/paths/network.d.ts.map +1 -0
- package/dist/paths/network.js +315 -0
- package/dist/paths/network.js.map +1 -0
- package/dist/paths/sink.d.ts +20 -0
- package/dist/paths/sink.d.ts.map +1 -0
- package/dist/paths/sink.js +32 -0
- package/dist/paths/sink.js.map +1 -0
- package/dist/paths/smooth-corners.d.ts +25 -0
- package/dist/paths/smooth-corners.d.ts.map +1 -0
- package/dist/paths/smooth-corners.js +196 -0
- package/dist/paths/smooth-corners.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +4 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +2 -0
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/polygon.d.ts +1 -3
- package/dist/polygon.d.ts.map +1 -1
- package/dist/polygon.js +1 -16
- package/dist/polygon.js.map +1 -1
- package/dist/primitives/index.d.ts +1 -7
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +5 -5
- package/dist/resize.js.map +1 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +25 -3
- package/dist/scaling/node.js.map +1 -1
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +1 -1
- package/dist/shaders/model.js.map +1 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +2 -9
- package/dist/shared-styles.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/auto-resize.d.ts +15 -0
- package/dist/text/auto-resize.d.ts.map +1 -0
- package/dist/text/auto-resize.js +23 -0
- package/dist/text/auto-resize.js.map +1 -0
- package/dist/text/index.d.ts +5 -3
- package/dist/text/index.js +5 -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 +14 -5
- 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/text/path.js +10 -0
- package/dist/text/path.js.map +1 -0
- package/dist/text/picture.js +5 -5
- package/dist/text/picture.js.map +1 -1
- package/dist/text/runs.d.ts +29 -0
- package/dist/text/runs.d.ts.map +1 -0
- package/dist/text/runs.js +72 -0
- package/dist/text/runs.js.map +1 -0
- package/dist/transfer/dependencies.d.ts.map +1 -1
- package/dist/transfer/dependencies.js +3 -2
- package/dist/transfer/dependencies.js.map +1 -1
- package/dist/transfer/nodes.js +2 -1
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +56 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/index.d.ts +4 -3
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +4 -3
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/lookup.d.ts +20 -0
- package/dist/variables/lookup.d.ts.map +1 -0
- package/dist/variables/lookup.js +34 -0
- package/dist/variables/lookup.js.map +1 -0
- package/dist/variables/paints.d.ts +35 -4
- package/dist/variables/paints.d.ts.map +1 -1
- package/dist/variables/paints.js +67 -16
- package/dist/variables/paints.js.map +1 -1
- package/dist/variables/resolution.d.ts +3 -1
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +8 -3
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +1 -1
- package/dist/variables/subtree.js.map +1 -1
- package/dist/vector-network.d.ts.map +1 -1
- package/dist/vector-network.js +13 -79
- package/dist/vector-network.js.map +1 -1
- package/package.json +28 -7
- package/src/buffered-events.ts +2 -1
- package/src/clipping.ts +11 -8
- package/src/comments/schema.ts +1 -0
- package/src/comments/threads.ts +13 -5
- package/src/components/properties.ts +3 -14
- package/src/constants.ts +25 -1
- package/src/copy.ts +2 -0
- package/src/corners.ts +93 -0
- package/src/css/grid.ts +49 -7
- package/src/css/index.ts +13 -2
- package/src/css/layout.ts +36 -0
- package/src/css/values.ts +49 -0
- package/src/font-style.ts +38 -4
- package/src/geometry.ts +223 -28
- package/src/gradient.ts +23 -1
- package/src/graph.ts +35 -10
- package/src/group-bounds.ts +7 -3
- package/src/guides.ts +26 -1
- package/src/hit-test.ts +68 -10
- package/src/icons/fit.ts +24 -0
- package/src/icons/glyph.ts +6 -4
- package/src/icons/index.ts +1 -0
- package/src/ids.ts +1 -1
- package/src/images.ts +67 -7
- package/src/instances/assignments.ts +65 -7
- package/src/instances/index.ts +77 -13
- package/src/instances/kept-overrides.ts +2 -5
- package/src/instances/matching.ts +101 -0
- package/src/instances/overrides.ts +18 -0
- package/src/instances/protection.ts +103 -0
- package/src/instances/swap.ts +12 -9
- package/src/instances/sync.ts +52 -184
- package/src/layout/guides.ts +42 -9
- package/src/layout/index.ts +3 -0
- package/src/layout/limits.ts +64 -0
- package/src/layout/sizing.ts +0 -2
- package/src/layout/spacing.ts +11 -0
- package/src/layout/strokes.ts +23 -0
- package/src/masks.ts +51 -0
- package/src/matrix.ts +15 -2
- package/src/node-defaults.ts +71 -36
- package/src/outline/flatten.ts +31 -18
- package/src/outline/hit.ts +16 -33
- package/src/outline/index.ts +2 -2
- package/src/outline/shapes.ts +19 -36
- package/src/paints/index.ts +2 -0
- package/src/paints/pattern.ts +45 -0
- package/src/paints/shows.ts +13 -0
- package/src/parse-path.ts +14 -0
- package/src/paths/arc.ts +59 -0
- package/src/paths/index.ts +4 -0
- package/src/paths/network.ts +411 -0
- package/src/paths/sink.ts +50 -0
- package/src/paths/smooth-corners.ts +357 -0
- package/src/plugin-data/fields.ts +2 -0
- package/src/polygon.ts +0 -17
- package/src/primitives/index.ts +0 -5
- package/src/resize.ts +6 -7
- package/src/scaling/node.ts +29 -3
- package/src/shaders/model.ts +2 -1
- package/src/shared-styles.ts +3 -4
- package/src/strokes.ts +121 -0
- package/src/text/auto-resize.ts +25 -0
- package/src/text/index.ts +2 -0
- package/src/text/lengths.ts +11 -0
- package/src/text/overflow.ts +32 -6
- package/src/text/path.ts +13 -0
- package/src/text/picture.ts +5 -5
- package/src/text/runs.ts +80 -0
- package/src/transfer/dependencies.ts +4 -2
- package/src/transfer/nodes.ts +2 -1
- package/src/types.ts +62 -8
- package/src/variables/index.ts +1 -0
- package/src/variables/lookup.ts +31 -0
- package/src/variables/paints.ts +101 -20
- package/src/variables/resolution.ts +15 -2
- package/src/variables/subtree.ts +1 -1
- package/src/vector-network.ts +19 -142
- package/dist/random.d.ts +0 -7
- package/dist/random.d.ts.map +0 -1
- package/dist/random.js +0 -25
- package/dist/random.js.map +0 -1
- package/src/random.ts +0 -28
|
@@ -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 { uniq } from 'es-toolkit/array'\nimport { pick } from 'es-toolkit/object'\nimport { isEmptyObject, 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 { resolvedNumericBindings } from '../variables/bindings'\nimport {\n effectBindingTarget,\n isNumericVariableBindingField,\n paintBindingTarget\n} 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 {\n bindingOverrideField,\n copiedComponentLayerId,\n hasInstanceOverride as hasNodeInstanceOverride,\n overriddenBindingField,\n setInstanceOverride,\n type InstanceOverrideState\n} from './overrides'\nimport { fitCopiedGroup, PLACEMENT_FIELDS, placedByConstraints } from './placement'\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 if (key === 'booleanOperation') {\n setSceneProp(target, key, source.booleanOperation ?? 'UNION')\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 and effects 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 if (paint) return fields.has(paint.list)\n return fields.has('effects') && effectBindingTarget(binding) !== null\n }\n}\n\nfunction isUnbound(node: SceneNode): boolean {\n return isEmptyObject(node.boundVariables) && isEmptyObject(node.variableBindingScales)\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') || (isUnbound(source) && isUnbound(target))) {\n return\n }\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\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 return {\n ...source,\n ...scaleNodeChanges(source, factor, true),\n ...scaleVariableBindingUnits(source, factor)\n }\n}\n\nconst SYNCED_FIELDS = INSTANCE_SYNC_FIELDS.filter((key) => key !== 'boundVariables').map((key) => ({\n key,\n owner: INSTANCE_SYNC_FIELD_OWNERS[key],\n placement: PLACEMENT_FIELDS.has(key),\n position: key === 'x' || key === 'y'\n}))\n\nexport const NOTHING_PROTECTED = (_field: string): boolean => false\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 graph: SceneGraph,\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(graph, source, compParent, instParent, factor)\n for (const { key, owner, placement, position } of SYNCED_FIELDS) {\n if ((placedByLayout && position) || skip(key) || (owner && skip(owner))) {\n continue\n }\n const from = placement ? placed : source\n // Most fields already match: comparing first spares cloning them for nothing.\n if (copy[key] === from[key] || isEqual(copy[key], from[key])) {\n continue\n }\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 let changed: Partial<SceneNode> | undefined\n for (const key of Object.keys(updates)) {\n const current = target[key as keyof SceneNode]\n const value = updates[key as keyof SceneNode]\n if (current !== value && !isEqual(current, value)) {\n changed ??= {}\n Reflect.set(changed, key, value)\n }\n }\n if (!changed) {\n return\n }\n if (changed.fills && updates.fillStyleId !== undefined) {\n changed.fillStyleId = updates.fillStyleId\n }\n 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\nexport function 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 if (child.instanceOverrides.self.size === 0 && fields.every((scope) => scope.size === 0)) {\n return NOTHING_PROTECTED\n }\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): void {\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 = 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\nexport interface MatchedCopy {\n compParent: SceneNode\n instParent: SceneNode\n compChild: SceneNode\n instChild: SceneNode\n}\n\nexport function syncCopy(\n graph: SceneGraph,\n { compParent, instParent, compChild, instChild }: MatchedCopy,\n protectedField: (field: string) => boolean,\n linkedLayerId?: string\n): boolean {\n const driven = propertyDrivenFields(graph, instChild, compChild)\n const kept =\n driven.size === 0 && protectedField === NOTHING_PROTECTED\n ? NOTHING_PROTECTED\n : (key: string) => 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 if (instChild.componentScale !== componentScale) {\n updates.componentScale = componentScale\n }\n if (!isEqual(instChild.componentPropertyReferences, compChild.componentPropertyReferences)) {\n updates.componentPropertyReferences = structuredClone(compChild.componentPropertyReferences)\n }\n if (linkedLayerId !== undefined) {\n updates.componentId = linkedLayerId\n }\n syncBindingFields(instChild, source, updates, protectedField)\n const placement = copySyncedFields(graph, 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 return placement.placed !== source\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/** Children already linked to a component child by sourceComponentId or componentId. */\nfunction matchLinkedChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n overrides: InstanceOverrideState,\n compChildIdSet: ReadonlySet<string>,\n instChildMap: Map<string, SceneNode>,\n usedInstChildIds: Set<string>\n): void {\n for (const childId of instParent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n const mappedComponentId = copiedComponentLayerId(overrides, instParentId, child)\n if (mappedComponentId && compChildIdSet.has(mappedComponentId)) {\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): boolean {\n // An instance inside its own component would clone the component into itself without end.\n if (isCyclicSync(graph, compParentId, instParentId)) return false\n\n const compParent = graph.nodes.get(compParentId)\n const instParent = graph.nodes.get(instParentId)\n if (!compParent || !instParent) return false\n\n const instChildMap = new Map<string, SceneNode>()\n const usedInstChildIds = new Set<string>()\n const compChildIdSet = new Set(compParent.childIds)\n\n // Pass 1: Direct matching via sourceComponentId or componentId\n matchLinkedChildren(\n graph,\n instParent,\n instParentId,\n overrides,\n compChildIdSet,\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 let constrained = false\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\n const match = { compParent, instParent, compChild, instChild }\n const protection = childBindingProtection(graph, instChild, overrides)\n // True when its constraints placed the copy elsewhere than the component's layer.\n if (syncCopy(graph, match, protection)) constrained = true\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 if (syncChildren(graph, compChildId, instChild.id, overrides, context)) constrained = true\n }\n }\n\n // Pass 5: Sort instance children to match component child order\n sortInstanceChildren(graph, instParent, instParentId, compParent.childIds, overrides)\n // A group fits layers its constraints moved; else it keeps the component's box, as a boolean must.\n if (constrained) fitCopiedGroup(graph, instParentId)\n return constrained\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6CA,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,QAA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Ac,kBAAkB,OAAO;CAG3F,IAAI,cAAc;CAClB,KAAK,MAAM,eAAe,WAAW,UAAU;EAC7C,MAAM,YAAY,MAAM,MAAM,IAAI,WAAW;EAC7C,MAAM,YAAY,aAAa,IAAI,WAAW;EAC9C,IAAI,CAAC,aAAa,CAAC,WAAW;EAK9B,IAAI,SAAS,OAAO;GAHJ;GAAY;GAAY;GAAW;EAG3B,GAFL,uBAAuB,OAAO,WAAW,SAExB,CAAC,GAAG,cAAc;EACtD,IACE,UAAU,SAAS,SAAS,KAC5B,CAACA,oBAAwB,WAAW,cAAc,UAAU,IAAI,aAAa,KAG7E,CAAC,gBAAgB,OAAO,WAAW,eAAe,SAAS,CAAC,GAExD;OAAA,aAAa,OAAO,aAAa,UAAU,IAAI,WAAW,OAAO,GAAG,cAAc;EAAA;CAE1F;CAGA,qBAAqB,OAAO,YAAY,cAAc,WAAW,UAAU,SAAS;CAEpF,IAAI,aAAa,eAAe,OAAO,YAAY;CACnD,OAAO;AACT"}
|
|
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 { uniq } from 'es-toolkit/array'\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 } 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 { sourceWithEffectiveFill } from './main-component'\nimport { matchFallbackChildren, matchLinkedChildren } from './matching'\nimport {\n copiedComponentLayerId,\n hasInstanceOverride as hasNodeInstanceOverride,\n type InstanceOverrideState\n} from './overrides'\nimport { fitCopiedGroup, PLACEMENT_FIELDS, placedByConstraints } from './placement'\nimport {\n childBindingProtection,\n isProtectedSyncField,\n NOTHING_PROTECTED,\n syncBindingFields\n} from './protection'\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 if (key === 'booleanOperation') {\n setSceneProp(target, key, source.booleanOperation ?? 'UNION')\n } else {\n const value = source[key]\n setSceneProp(target, key, Array.isArray(value) ? structuredClone(value) : value)\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 return {\n ...source,\n ...scaleNodeChanges(source, factor, true),\n ...scaleVariableBindingUnits(source, factor)\n }\n}\n\nconst SYNCED_FIELDS = INSTANCE_SYNC_FIELDS.filter((key) => key !== 'boundVariables').map((key) => ({\n key,\n owner: INSTANCE_SYNC_FIELD_OWNERS[key],\n placement: PLACEMENT_FIELDS.has(key),\n position: key === 'x' || key === 'y'\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 graph: SceneGraph,\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(graph, source, compParent, instParent, factor)\n for (const { key, owner, placement, position } of SYNCED_FIELDS) {\n if ((placedByLayout && position) || skip(key) || (owner && skip(owner))) {\n continue\n }\n const from = placement ? placed : source\n // Most fields already match: comparing first spares cloning them for nothing.\n if (copy[key] === from[key] || isEqual(copy[key], from[key])) {\n continue\n }\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(target, updates, kept)\n let changed: Partial<SceneNode> | undefined\n for (const key of Object.keys(updates)) {\n const current = target[key as keyof SceneNode]\n const value = updates[key as keyof SceneNode]\n if (current !== value && !isEqual(current, value)) {\n changed ??= {}\n Reflect.set(changed, key, value)\n }\n }\n if (!changed) {\n return\n }\n if (changed.fills && updates.fillStyleId !== undefined) {\n changed.fillStyleId = updates.fillStyleId\n }\n graph.updateNode(target.id, changed)\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 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 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 const value = own ? target[field] : updates[field]\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\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\nexport function 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\nfunction sortInstanceChildren(\n graph: SceneGraph,\n instParent: SceneNode,\n instParentId: string,\n compChildOrder: string[],\n overrides: InstanceOverrideState\n): void {\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 = 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\nexport interface MatchedCopy {\n compParent: SceneNode\n instParent: SceneNode\n compChild: SceneNode\n instChild: SceneNode\n}\n\nexport function syncCopy(\n graph: SceneGraph,\n { compParent, instParent, compChild, instChild }: MatchedCopy,\n protectedField: (field: string) => boolean,\n linkedLayerId?: string\n): boolean {\n const driven = propertyDrivenFields(graph, instChild, compChild)\n const kept =\n driven.size === 0 && protectedField === NOTHING_PROTECTED\n ? NOTHING_PROTECTED\n : (key: string) => 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 if (instChild.componentScale !== componentScale) {\n updates.componentScale = componentScale\n }\n if (!isEqual(instChild.componentPropertyReferences, compChild.componentPropertyReferences)) {\n updates.componentPropertyReferences = structuredClone(compChild.componentPropertyReferences)\n }\n if (linkedLayerId !== undefined) {\n updates.componentId = linkedLayerId\n }\n syncBindingFields(instChild, source, updates, protectedField)\n const placement = copySyncedFields(graph, 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 return placement.placed !== source\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 * 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): boolean {\n // An instance inside its own component would clone the component into itself without end.\n if (isCyclicSync(graph, compParentId, instParentId)) return false\n\n const compParent = graph.nodes.get(compParentId)\n const instParent = graph.nodes.get(instParentId)\n if (!compParent || !instParent) return false\n\n const instChildMap = new Map<string, SceneNode>()\n const usedInstChildIds = new Set<string>()\n const compChildIdSet = new Set(compParent.childIds)\n\n // Pass 1: Direct matching via sourceComponentId or componentId\n matchLinkedChildren(\n graph,\n instParent,\n instParentId,\n overrides,\n compChildIdSet,\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 let constrained = false\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\n const match = { compParent, instParent, compChild, instChild }\n const protection = childBindingProtection(graph, instChild, overrides)\n // True when its constraints placed the copy elsewhere than the component's layer.\n if (syncCopy(graph, match, protection)) constrained = true\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 if (syncChildren(graph, compChildId, instChild.id, overrides, context)) constrained = true\n }\n }\n\n // Pass 5: Sort instance children to match component child order\n sortInstanceChildren(graph, instParent, instParentId, compParent.childIds, overrides)\n // A group fits layers its constraints moved; else it keeps the component's box, as a boolean must.\n if (constrained) fitCopiedGroup(graph, instParentId)\n return constrained\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoDA,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,qBACjB,aAAa,QAAQ,KAAK,OAAO,oBAAoB,EAAE,GAAG,OAAO,kBAAkB,IAAI,IAAI;MACtF,IAAI,QAAQ,oBACjB,aAAa,QAAQ,KAAK,OAAO,oBAAoB,OAAO;MACvD;EACL,MAAM,QAAQ,OAAO;E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;GAHJ;GAAY;GAAY;GAAW;EAG3B,GAFL,uBAAuB,OAAO,WAAW,SAExB,CAAC,GAAG,cAAc;EACtD,IACE,UAAU,SAAS,SAAS,KAC5B,CAACA,oBAAwB,WAAW,cAAc,UAAU,IAAI,aAAa,KAG7E,CAAC,gBAAgB,OAAO,WAAW,eAAe,SAAS,CAAC,GAExD;OAAA,aAAa,OAAO,aAAa,UAAU,IAAI,WAAW,OAAO,GAAG,cAAc;EAAA;CAE1F;CAGA,qBAAqB,OAAO,YAAY,cAAc,WAAW,UAAU,SAAS;CAEpF,IAAI,aAAa,eAAe,OAAO,YAAY;CACnD,OAAO;AACT"}
|
package/dist/layout/guides.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { Color } from "../primitives/index.js";
|
|
1
2
|
import { LayoutGrid, SceneNode } from "../types.js";
|
|
2
3
|
//#region src/layout/guides.d.ts
|
|
3
4
|
interface LayoutGuideLine {
|
|
4
5
|
axis: 'x' | 'y';
|
|
5
6
|
position: number;
|
|
6
7
|
}
|
|
8
|
+
/** The most lines one guide draws or snaps to on an axis. */
|
|
9
|
+
declare const MAX_LAYOUT_GUIDE_LINES = 10000;
|
|
7
10
|
/** Figma's Auto count, as its archive stores it: as many sections as fit. */
|
|
8
11
|
declare const AUTO_LAYOUT_GRID_COUNT = 2147483647;
|
|
9
12
|
/** Whether a guide's count is Auto: the archive's value, or the plugin API's `Infinity` or `null`. */
|
|
@@ -13,6 +16,19 @@ declare function isAutoGridCount(count: number | null | undefined): boolean;
|
|
|
13
16
|
* edit's `count` wins over the count the file had. Auto is {@link AUTO_LAYOUT_GRID_COUNT}.
|
|
14
17
|
*/
|
|
15
18
|
declare function layoutGridCount(grid: LayoutGrid): number;
|
|
19
|
+
/** Figma's color for a new guide: red at 10%. */
|
|
20
|
+
declare const DEFAULT_LAYOUT_GRID_COLOR: Readonly<Color>;
|
|
21
|
+
/** A guide's pattern in Figma's plugin names, from either shape: the archive's `STRIPES` along an `axis`. */
|
|
22
|
+
declare function layoutGridPattern(grid: Pick<LayoutGrid, 'pattern' | 'axis'>): 'COLUMNS' | 'ROWS' | 'GRID';
|
|
23
|
+
/**
|
|
24
|
+
* A guide's alignment, from either shape. One set without any stretches, as the plugin API and
|
|
25
|
+
* export have read it; a file's guide always has one, as Figma drops a guide without it.
|
|
26
|
+
*/
|
|
27
|
+
declare function layoutGridAlignment(grid: Pick<LayoutGrid, 'alignment' | 'type'>): 'MIN' | 'CENTER' | 'MAX' | 'STRETCH';
|
|
28
|
+
/** Whether a file's guide record names an alignment; Figma drops one that does not (live). */
|
|
29
|
+
declare function hasLayoutGridAlignment(grid: Partial<Pick<LayoutGrid, 'alignment' | 'type'>>): boolean;
|
|
30
|
+
/** A guide's color, Figma's new-guide red for one set without any. */
|
|
31
|
+
declare function layoutGridColor(grid: Pick<LayoutGrid, 'color'>): Color;
|
|
16
32
|
interface LayoutGuideSection {
|
|
17
33
|
axis: 'x' | 'y';
|
|
18
34
|
start: number;
|
|
@@ -21,5 +37,5 @@ interface LayoutGuideSection {
|
|
|
21
37
|
declare function layoutGuideSections(node: Pick<SceneNode, 'width' | 'height'>, grid: LayoutGrid): LayoutGuideSection[];
|
|
22
38
|
declare function layoutGuideLines(node: Pick<SceneNode, 'width' | 'height'>, grid: LayoutGrid): LayoutGuideLine[];
|
|
23
39
|
//#endregion
|
|
24
|
-
export { AUTO_LAYOUT_GRID_COUNT, LayoutGuideLine, LayoutGuideSection, isAutoGridCount, layoutGridCount, layoutGuideLines, layoutGuideSections };
|
|
40
|
+
export { AUTO_LAYOUT_GRID_COUNT, DEFAULT_LAYOUT_GRID_COLOR, LayoutGuideLine, LayoutGuideSection, MAX_LAYOUT_GUIDE_LINES, hasLayoutGridAlignment, isAutoGridCount, layoutGridAlignment, layoutGridColor, layoutGridCount, layoutGridPattern, layoutGuideLines, layoutGuideSections };
|
|
25
41
|
//# sourceMappingURL=guides.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guides.d.ts","names":[],"sources":["../../src/layout/guides.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"guides.d.ts","names":[],"sources":["../../src/layout/guides.ts"],"mappings":";;;UAGiB;EACf;EACA;;;cAIW;;cAGA;;iBAGG,gBAAgB;;;;;iBAQhB,gBAAgB,MAAM;;cAMzB,2BAA2B,SAAS;;iBAQjC,kBACd,MAAM,KAAK;;;;;iBAYG,oBACd,MAAM,KAAK;;iBAMG,uBACd,MAAM,QAAQ,KAAK;;iBAML,gBAAgB,MAAM,KAAK,uBAAuB;UA4CjD;EACf;EACA;EACA;;iBAGc,oBACd,MAAM,KAAK,gCACX,MAAM,aACL;iBAea,iBAAiB,MAAM,KAAK,gCAAgC,MAAM,aAAU"}
|
package/dist/layout/guides.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//#region src/layout/guides.ts
|
|
2
|
+
/** The most lines one guide draws or snaps to on an axis. */
|
|
2
3
|
const MAX_LAYOUT_GUIDE_LINES = 1e4;
|
|
3
4
|
/** Figma's Auto count, as its archive stores it: as many sections as fit. */
|
|
4
5
|
const AUTO_LAYOUT_GRID_COUNT = 2147483647;
|
|
@@ -14,16 +15,35 @@ function layoutGridCount(grid) {
|
|
|
14
15
|
const count = grid.count === void 0 ? grid.numSections : grid.count;
|
|
15
16
|
return isAutoGridCount(count) ? AUTO_LAYOUT_GRID_COUNT : count ?? 1;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/** Figma's color for a new guide: red at 10%. */
|
|
19
|
+
const DEFAULT_LAYOUT_GRID_COLOR = Object.freeze({
|
|
20
|
+
r: 1,
|
|
21
|
+
g: 0,
|
|
22
|
+
b: 0,
|
|
23
|
+
a: .1
|
|
24
|
+
});
|
|
25
|
+
/** A guide's pattern in Figma's plugin names, from either shape: the archive's `STRIPES` along an `axis`. */
|
|
26
|
+
function layoutGridPattern(grid) {
|
|
27
|
+
if (grid.pattern === "GRID" || grid.pattern === "ROWS" || grid.pattern === "COLUMNS") return grid.pattern;
|
|
28
|
+
return grid.axis === "Y" ? "ROWS" : "COLUMNS";
|
|
21
29
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
/**
|
|
31
|
+
* A guide's alignment, from either shape. One set without any stretches, as the plugin API and
|
|
32
|
+
* export have read it; a file's guide always has one, as Figma drops a guide without it.
|
|
33
|
+
*/
|
|
34
|
+
function layoutGridAlignment(grid) {
|
|
35
|
+
return grid.alignment ?? grid.type ?? "STRETCH";
|
|
36
|
+
}
|
|
37
|
+
/** Whether a file's guide record names an alignment; Figma drops one that does not (live). */
|
|
38
|
+
function hasLayoutGridAlignment(grid) {
|
|
39
|
+
return grid.type !== void 0 || grid.alignment !== void 0;
|
|
40
|
+
}
|
|
41
|
+
/** A guide's color, Figma's new-guide red for one set without any. */
|
|
42
|
+
function layoutGridColor(grid) {
|
|
43
|
+
return { ...grid.color ?? DEFAULT_LAYOUT_GRID_COLOR };
|
|
26
44
|
}
|
|
45
|
+
const pattern = layoutGridPattern;
|
|
46
|
+
const alignment = layoutGridAlignment;
|
|
27
47
|
/**
|
|
28
48
|
* How many sections a guide draws. Auto fits as many fixed sections as the frame holds, counting
|
|
29
49
|
* the offset once from the aligned edge, as Figma desktop 126 draws them.
|
|
@@ -79,11 +99,11 @@ function layoutGuideLines(node, grid) {
|
|
|
79
99
|
if (gridPattern === "GRID") {
|
|
80
100
|
const size = grid.sectionSize ?? 0;
|
|
81
101
|
if (size <= 0) return lines;
|
|
82
|
-
for (let index = 0, x = grid.offset ?? 0; x <= node.width && index <
|
|
102
|
+
for (let index = 0, x = grid.offset ?? 0; x <= node.width && index < 1e4; index++, x += size) lines.push({
|
|
83
103
|
axis: "x",
|
|
84
104
|
position: x
|
|
85
105
|
});
|
|
86
|
-
for (let index = 0, y = grid.offset ?? 0; y <= node.height && index <
|
|
106
|
+
for (let index = 0, y = grid.offset ?? 0; y <= node.height && index < 1e4; index++, y += size) lines.push({
|
|
87
107
|
axis: "y",
|
|
88
108
|
position: y
|
|
89
109
|
});
|
|
@@ -100,6 +120,6 @@ function layoutGuideLines(node, grid) {
|
|
|
100
120
|
return lines;
|
|
101
121
|
}
|
|
102
122
|
//#endregion
|
|
103
|
-
export { AUTO_LAYOUT_GRID_COUNT, isAutoGridCount, layoutGridCount, layoutGuideLines, layoutGuideSections };
|
|
123
|
+
export { AUTO_LAYOUT_GRID_COUNT, DEFAULT_LAYOUT_GRID_COLOR, MAX_LAYOUT_GUIDE_LINES, hasLayoutGridAlignment, isAutoGridCount, layoutGridAlignment, layoutGridColor, layoutGridCount, layoutGridPattern, layoutGuideLines, layoutGuideSections };
|
|
104
124
|
|
|
105
125
|
//# sourceMappingURL=guides.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guides.js","names":[],"sources":["../../src/layout/guides.ts"],"sourcesContent":["import type { LayoutGrid, SceneNode } from '../types'\n\nexport interface LayoutGuideLine {\n axis: 'x' | 'y'\n position: number\n}\n\
|
|
1
|
+
{"version":3,"file":"guides.js","names":[],"sources":["../../src/layout/guides.ts"],"sourcesContent":["import type { Color } from '../primitives'\nimport type { LayoutGrid, SceneNode } from '../types'\n\nexport interface LayoutGuideLine {\n axis: 'x' | 'y'\n position: number\n}\n\n/** The most lines one guide draws or snaps to on an axis. */\nexport const MAX_LAYOUT_GUIDE_LINES = 10_000\n\n/** Figma's Auto count, as its archive stores it: as many sections as fit. */\nexport const AUTO_LAYOUT_GRID_COUNT = 2_147_483_647\n\n/** Whether a guide's count is Auto: the archive's value, or the plugin API's `Infinity` or `null`. */\nexport function isAutoGridCount(count: number | null | undefined): boolean {\n return count === null || count === Infinity || (count ?? 0) >= AUTO_LAYOUT_GRID_COUNT\n}\n\n/**\n * A guide's count, set in Figma's plugin shape (`count`) or read from a file (`numSections`); an\n * edit's `count` wins over the count the file had. Auto is {@link AUTO_LAYOUT_GRID_COUNT}.\n */\nexport function layoutGridCount(grid: LayoutGrid): number {\n const count = grid.count === undefined ? grid.numSections : grid.count\n return isAutoGridCount(count) ? AUTO_LAYOUT_GRID_COUNT : (count ?? 1)\n}\n\n/** Figma's color for a new guide: red at 10%. */\nexport const DEFAULT_LAYOUT_GRID_COLOR: Readonly<Color> = Object.freeze({\n r: 1,\n g: 0,\n b: 0,\n a: 0.1\n})\n\n/** A guide's pattern in Figma's plugin names, from either shape: the archive's `STRIPES` along an `axis`. */\nexport function layoutGridPattern(\n grid: Pick<LayoutGrid, 'pattern' | 'axis'>\n): 'COLUMNS' | 'ROWS' | 'GRID' {\n if (grid.pattern === 'GRID' || grid.pattern === 'ROWS' || grid.pattern === 'COLUMNS') {\n return grid.pattern\n }\n return grid.axis === 'Y' ? 'ROWS' : 'COLUMNS'\n}\n\n/**\n * A guide's alignment, from either shape. One set without any stretches, as the plugin API and\n * export have read it; a file's guide always has one, as Figma drops a guide without it.\n */\nexport function layoutGridAlignment(\n grid: Pick<LayoutGrid, 'alignment' | 'type'>\n): 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' {\n return grid.alignment ?? grid.type ?? 'STRETCH'\n}\n\n/** Whether a file's guide record names an alignment; Figma drops one that does not (live). */\nexport function hasLayoutGridAlignment(\n grid: Partial<Pick<LayoutGrid, 'alignment' | 'type'>>\n): boolean {\n return grid.type !== undefined || grid.alignment !== undefined\n}\n\n/** A guide's color, Figma's new-guide red for one set without any. */\nexport function layoutGridColor(grid: Pick<LayoutGrid, 'color'>): Color {\n return { ...(grid.color ?? DEFAULT_LAYOUT_GRID_COLOR) }\n}\n\nconst pattern = layoutGridPattern\nconst alignment = layoutGridAlignment\n\n/**\n * How many sections a guide draws. Auto fits as many fixed sections as the frame holds, counting\n * the offset once from the aligned edge, as Figma desktop 126 draws them.\n */\nfunction sectionCount(nodeSize: number, grid: LayoutGrid): number {\n const value = layoutGridCount(grid)\n if (value === AUTO_LAYOUT_GRID_COUNT) {\n const size = grid.sectionSize ?? 0\n if (alignment(grid) === 'STRETCH' || size <= 0) return 0\n const gutter = grid.gutterSize ?? 0\n const offset = alignment(grid) === 'CENTER' ? 0 : (grid.offset ?? 0)\n return Math.min(\n MAX_LAYOUT_GUIDE_LINES,\n Math.max(0, Math.floor((nodeSize - offset + gutter) / (size + gutter)))\n )\n }\n if (!Number.isFinite(value)) return 0\n return Math.min(MAX_LAYOUT_GUIDE_LINES, Math.max(0, Math.floor(value)))\n}\n\nfunction sectionSize(nodeSize: number, grid: LayoutGrid, count: number): number {\n const fixed = grid.sectionSize ?? 0\n if (alignment(grid) !== 'STRETCH') return fixed\n const gutter = grid.gutterSize ?? 0\n const offset = grid.offset ?? 0\n return (nodeSize - offset * 2 - Math.max(0, count - 1) * gutter) / count\n}\n\nfunction start(nodeSize: number, grid: LayoutGrid, size: number, count: number): number {\n const gutter = grid.gutterSize ?? 0\n const offset = grid.offset ?? 0\n const span = count * size + Math.max(0, count - 1) * gutter\n if (alignment(grid) === 'CENTER') return (nodeSize - span) / 2 + offset\n if (alignment(grid) === 'MAX') return nodeSize - span - offset\n return offset\n}\n\nexport interface LayoutGuideSection {\n axis: 'x' | 'y'\n start: number\n end: number\n}\n\nexport function layoutGuideSections(\n node: Pick<SceneNode, 'width' | 'height'>,\n grid: LayoutGrid\n): LayoutGuideSection[] {\n if (grid.visible === false || pattern(grid) === 'GRID') return []\n const axis = pattern(grid) === 'ROWS' ? 'y' : 'x'\n const nodeSize = axis === 'x' ? node.width : node.height\n const count = sectionCount(nodeSize, grid)\n const size = sectionSize(nodeSize, grid, count)\n if (count <= 0 || size <= 0) return []\n const first = start(nodeSize, grid, size, count)\n const step = size + (grid.gutterSize ?? 0)\n return Array.from({ length: count }, (_, index) => {\n const sectionStart = first + index * step\n return { axis, start: sectionStart, end: sectionStart + size }\n })\n}\n\nexport function layoutGuideLines(node: Pick<SceneNode, 'width' | 'height'>, grid: LayoutGrid) {\n if (grid.visible === false) return []\n const gridPattern = pattern(grid)\n const lines: LayoutGuideLine[] = []\n if (gridPattern === 'GRID') {\n const size = grid.sectionSize ?? 0\n if (size <= 0) return lines\n for (\n let index = 0, x = grid.offset ?? 0;\n x <= node.width && index < MAX_LAYOUT_GUIDE_LINES;\n index++, x += size\n ) {\n lines.push({ axis: 'x', position: x })\n }\n for (\n let index = 0, y = grid.offset ?? 0;\n y <= node.height && index < MAX_LAYOUT_GUIDE_LINES;\n index++, y += size\n ) {\n lines.push({ axis: 'y', position: y })\n }\n return lines\n }\n\n const sections = layoutGuideSections(node, grid)\n for (const section of sections) {\n lines.push(\n { axis: section.axis, position: section.start },\n { axis: section.axis, position: section.end }\n )\n }\n return lines\n}\n"],"mappings":";;AASA,MAAa,yBAAyB;;AAGtC,MAAa,yBAAyB;;AAGtC,SAAgB,gBAAgB,OAA2C;CACzE,OAAO,UAAU,QAAQ,UAAU,aAAa,SAAS,MAAA;AAC3D;;;;;AAMA,SAAgB,gBAAgB,MAA0B;CACxD,MAAM,QAAQ,KAAK,UAAU,KAAA,IAAY,KAAK,cAAc,KAAK;CACjE,OAAO,gBAAgB,KAAK,IAAI,yBAA0B,SAAS;AACrE;;AAGA,MAAa,4BAA6C,OAAO,OAAO;CACtE,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL,CAAC;;AAGD,SAAgB,kBACd,MAC6B;CAC7B,IAAI,KAAK,YAAY,UAAU,KAAK,YAAY,UAAU,KAAK,YAAY,WACzE,OAAO,KAAK;CAEd,OAAO,KAAK,SAAS,MAAM,SAAS;AACtC;;;;;AAMA,SAAgB,oBACd,MACsC;CACtC,OAAO,KAAK,aAAa,KAAK,QAAQ;AACxC;;AAGA,SAAgB,uBACd,MACS;CACT,OAAO,KAAK,SAAS,KAAA,KAAa,KAAK,cAAc,KAAA;AACvD;;AAGA,SAAgB,gBAAgB,MAAwC;CACtE,OAAO,EAAE,GAAI,KAAK,SAAS,0BAA2B;AACxD;AAEA,MAAM,UAAU;AAChB,MAAM,YAAY;;;;;AAMlB,SAAS,aAAa,UAAkB,MAA0B;C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AxisAlign, parseLayoutAlignSelf, parsePrimaryAxisAlign } from "./keywords.js";
|
|
2
2
|
import { aspectRatioLockEditable, enforcedAspectRatio, lockedAspectRatioTarget, recapturedAspectRatio, sizeKeepingAspectRatio } from "./aspect-ratio.js";
|
|
3
|
-
import { AUTO_LAYOUT_GRID_COUNT, LayoutGuideLine, LayoutGuideSection, isAutoGridCount, layoutGridCount, layoutGuideLines, layoutGuideSections } from "./guides.js";
|
|
3
|
+
import { AUTO_LAYOUT_GRID_COUNT, DEFAULT_LAYOUT_GRID_COLOR, LayoutGuideLine, LayoutGuideSection, MAX_LAYOUT_GUIDE_LINES, hasLayoutGridAlignment, isAutoGridCount, layoutGridAlignment, layoutGridColor, layoutGridCount, layoutGridPattern, layoutGuideLines, layoutGuideSections } from "./guides.js";
|
|
4
|
+
import { MAX_FONT_SIZE, MAX_GRID_LINE, MAX_GRID_SPAN, MAX_GRID_TRACKS, MAX_LAYOUT_ANGLE, MAX_LAYOUT_FACTOR, MAX_LAYOUT_LENGTH, MAX_LAYOUT_SPACING, MAX_TEXT_LENGTH, clampFontSize, clampGridTracks, clampLayoutLength, clampLayoutPosition } from "./limits.js";
|
|
4
5
|
import { LayoutSizingAxis, autoLayoutSizingFields, fillSizingFields, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, textAutoResizeFor } from "./sizing.js";
|
|
5
|
-
|
|
6
|
+
import { counterAxisSpacingOf } from "./spacing.js";
|
|
7
|
+
import { includedStrokeWeights } from "./strokes.js";
|
|
8
|
+
export { AUTO_LAYOUT_GRID_COUNT, AutoLayoutDirection, DEFAULT_LAYOUT_GRID_COLOR, LayoutGuideLine, LayoutGuideSection, LayoutSizingAxis, MAX_FONT_SIZE, MAX_GRID_LINE, MAX_GRID_SPAN, MAX_GRID_TRACKS, MAX_LAYOUT_ANGLE, MAX_LAYOUT_FACTOR, MAX_LAYOUT_GUIDE_LINES, MAX_LAYOUT_LENGTH, MAX_LAYOUT_SPACING, MAX_TEXT_LENGTH, aspectRatioLockEditable, autoLayoutSizingFields, clampFontSize, clampGridTracks, clampLayoutLength, clampLayoutPosition, counterAxisSpacingOf, enforcedAspectRatio, fillSizingFields, hasLayoutGridAlignment, includedStrokeWeights, isAutoGridCount, layoutGridAlignment, layoutGridColor, layoutGridCount, layoutGridPattern, layoutGuideLines, layoutGuideSections, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, lockedAspectRatioTarget, paddingFromShorthand, parseAutoLayoutDirection, parseCounterAxisAlign, parseLayoutAlignSelf, parsePrimaryAxisAlign, recapturedAspectRatio, sizeKeepingAspectRatio, textAutoResizeFor };
|
package/dist/layout/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { autoLayoutSizingFields, fillSizingFields, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, textAutoResizeFor } from "./sizing.js";
|
|
2
2
|
import { aspectRatioLockEditable, enforcedAspectRatio, lockedAspectRatioTarget, recapturedAspectRatio, sizeKeepingAspectRatio } from "./aspect-ratio.js";
|
|
3
|
+
import { MAX_FONT_SIZE, MAX_GRID_LINE, MAX_GRID_SPAN, MAX_GRID_TRACKS, MAX_LAYOUT_ANGLE, MAX_LAYOUT_FACTOR, MAX_LAYOUT_LENGTH, MAX_LAYOUT_SPACING, MAX_TEXT_LENGTH, clampFontSize, clampGridTracks, clampLayoutLength, clampLayoutPosition } from "./limits.js";
|
|
3
4
|
import { paddingFromShorthand, parseAutoLayoutDirection, parseCounterAxisAlign, parseLayoutAlignSelf, parsePrimaryAxisAlign } from "./keywords.js";
|
|
4
|
-
import { AUTO_LAYOUT_GRID_COUNT, isAutoGridCount, layoutGridCount, layoutGuideLines, layoutGuideSections } from "./guides.js";
|
|
5
|
-
|
|
5
|
+
import { AUTO_LAYOUT_GRID_COUNT, DEFAULT_LAYOUT_GRID_COLOR, MAX_LAYOUT_GUIDE_LINES, hasLayoutGridAlignment, isAutoGridCount, layoutGridAlignment, layoutGridColor, layoutGridCount, layoutGridPattern, layoutGuideLines, layoutGuideSections } from "./guides.js";
|
|
6
|
+
import { counterAxisSpacingOf } from "./spacing.js";
|
|
7
|
+
import { includedStrokeWeights } from "./strokes.js";
|
|
8
|
+
export { AUTO_LAYOUT_GRID_COUNT, DEFAULT_LAYOUT_GRID_COLOR, MAX_FONT_SIZE, MAX_GRID_LINE, MAX_GRID_SPAN, MAX_GRID_TRACKS, MAX_LAYOUT_ANGLE, MAX_LAYOUT_FACTOR, MAX_LAYOUT_GUIDE_LINES, MAX_LAYOUT_LENGTH, MAX_LAYOUT_SPACING, MAX_TEXT_LENGTH, aspectRatioLockEditable, autoLayoutSizingFields, clampFontSize, clampGridTracks, clampLayoutLength, clampLayoutPosition, counterAxisSpacingOf, enforcedAspectRatio, fillSizingFields, hasLayoutGridAlignment, includedStrokeWeights, isAutoGridCount, layoutGridAlignment, layoutGridColor, layoutGridCount, layoutGridPattern, layoutGuideLines, layoutGuideSections, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, lockedAspectRatioTarget, paddingFromShorthand, parseAutoLayoutDirection, parseCounterAxisAlign, parseLayoutAlignSelf, parsePrimaryAxisAlign, recapturedAspectRatio, sizeKeepingAspectRatio, textAutoResizeFor };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { GridTrack } from "../types.js";
|
|
2
|
+
//#region src/layout/limits.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Bounds for the numbers layout computes with and for the values it writes back.
|
|
5
|
+
*
|
|
6
|
+
* Layout tolerates a span of zero or a track list a tool wrote by mistake, but not every
|
|
7
|
+
* consumer does: a document carrying absurd geometry cannot be rasterized, a grid template
|
|
8
|
+
* naming a billion tracks allocates one entry per track, and a text layer set at 1e9 px makes
|
|
9
|
+
* font shaping build a run of glyphs no memory holds. Every path that writes a layout value
|
|
10
|
+
* clamps to these bounds, and tool schemas reject values outside them.
|
|
11
|
+
*/
|
|
12
|
+
/** The largest size or position, in pixels, that a layout value may carry. */
|
|
13
|
+
declare const MAX_LAYOUT_LENGTH = 1000000;
|
|
14
|
+
/** The largest gap, padding, or stroke a layout value may carry, in pixels. */
|
|
15
|
+
declare const MAX_LAYOUT_SPACING = 100000;
|
|
16
|
+
/** The largest number of tracks one grid template may name. */
|
|
17
|
+
declare const MAX_GRID_TRACKS = 1000;
|
|
18
|
+
/** The last grid line a placement may name; line 0 leaves placement to auto-flow. */
|
|
19
|
+
declare const MAX_GRID_LINE = 1000;
|
|
20
|
+
/** The most tracks one grid item may span. */
|
|
21
|
+
declare const MAX_GRID_SPAN = 1000;
|
|
22
|
+
/** The largest rotation, in degrees, a layout or transform may carry. */
|
|
23
|
+
declare const MAX_LAYOUT_ANGLE = 360000;
|
|
24
|
+
/** The largest font size, in pixels, text may be set in. */
|
|
25
|
+
declare const MAX_FONT_SIZE = 10000;
|
|
26
|
+
/** The largest ratio a layout factor, such as a flex grow share, may carry. */
|
|
27
|
+
declare const MAX_LAYOUT_FACTOR = 1000;
|
|
28
|
+
/** The largest line height or letter spacing, in pixels or percent, a text may carry. */
|
|
29
|
+
declare const MAX_TEXT_LENGTH = 10000;
|
|
30
|
+
/** A length that cannot be negative, such as a size, padding, gap, or radius. */
|
|
31
|
+
declare function clampLayoutLength(value: number, max?: number): number;
|
|
32
|
+
/** A coordinate that may be negative, such as a position. */
|
|
33
|
+
declare function clampLayoutPosition(value: number, max?: number): number;
|
|
34
|
+
/** A font size in pixels, at least one and at most `MAX_FONT_SIZE`; fractions are kept. */
|
|
35
|
+
declare function clampFontSize(value: number): number;
|
|
36
|
+
/** A grid template's tracks, with at most `MAX_GRID_TRACKS` of them and no negative sizes. */
|
|
37
|
+
declare function clampGridTracks(tracks: readonly GridTrack[]): GridTrack[];
|
|
38
|
+
//#endregion
|
|
39
|
+
export { MAX_FONT_SIZE, MAX_GRID_LINE, MAX_GRID_SPAN, MAX_GRID_TRACKS, MAX_LAYOUT_ANGLE, MAX_LAYOUT_FACTOR, MAX_LAYOUT_LENGTH, MAX_LAYOUT_SPACING, MAX_TEXT_LENGTH, clampFontSize, clampGridTracks, clampLayoutLength, clampLayoutPosition };
|
|
40
|
+
//# sourceMappingURL=limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.d.ts","names":[],"sources":["../../src/layout/limits.ts"],"mappings":";;;;;;;;;;;;cAaa;;cAGA;;cAGA;;cAGA;;cAGA;;cAGA;;cAGA;;cAGA;;cAGA;;iBAGG,kBAAkB,eAAe;;iBAMjC,oBAAoB,eAAe;;iBAMnC,cAAc;;iBAMd,gBAAgB,iBAAiB,cAAc"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region src/layout/limits.ts
|
|
2
|
+
/**
|
|
3
|
+
* Bounds for the numbers layout computes with and for the values it writes back.
|
|
4
|
+
*
|
|
5
|
+
* Layout tolerates a span of zero or a track list a tool wrote by mistake, but not every
|
|
6
|
+
* consumer does: a document carrying absurd geometry cannot be rasterized, a grid template
|
|
7
|
+
* naming a billion tracks allocates one entry per track, and a text layer set at 1e9 px makes
|
|
8
|
+
* font shaping build a run of glyphs no memory holds. Every path that writes a layout value
|
|
9
|
+
* clamps to these bounds, and tool schemas reject values outside them.
|
|
10
|
+
*/
|
|
11
|
+
/** The largest size or position, in pixels, that a layout value may carry. */
|
|
12
|
+
const MAX_LAYOUT_LENGTH = 1e6;
|
|
13
|
+
/** The largest gap, padding, or stroke a layout value may carry, in pixels. */
|
|
14
|
+
const MAX_LAYOUT_SPACING = 1e5;
|
|
15
|
+
/** The largest number of tracks one grid template may name. */
|
|
16
|
+
const MAX_GRID_TRACKS = 1e3;
|
|
17
|
+
/** The last grid line a placement may name; line 0 leaves placement to auto-flow. */
|
|
18
|
+
const MAX_GRID_LINE = 1e3;
|
|
19
|
+
/** The most tracks one grid item may span. */
|
|
20
|
+
const MAX_GRID_SPAN = 1e3;
|
|
21
|
+
/** The largest rotation, in degrees, a layout or transform may carry. */
|
|
22
|
+
const MAX_LAYOUT_ANGLE = 36e4;
|
|
23
|
+
/** The largest font size, in pixels, text may be set in. */
|
|
24
|
+
const MAX_FONT_SIZE = 1e4;
|
|
25
|
+
/** The largest ratio a layout factor, such as a flex grow share, may carry. */
|
|
26
|
+
const MAX_LAYOUT_FACTOR = 1e3;
|
|
27
|
+
/** The largest line height or letter spacing, in pixels or percent, a text may carry. */
|
|
28
|
+
const MAX_TEXT_LENGTH = 1e4;
|
|
29
|
+
/** A length that cannot be negative, such as a size, padding, gap, or radius. */
|
|
30
|
+
function clampLayoutLength(value, max = MAX_LAYOUT_LENGTH) {
|
|
31
|
+
if (!Number.isFinite(value)) return 0;
|
|
32
|
+
return Math.min(max, Math.max(0, value));
|
|
33
|
+
}
|
|
34
|
+
/** A coordinate that may be negative, such as a position. */
|
|
35
|
+
function clampLayoutPosition(value, max = MAX_LAYOUT_LENGTH) {
|
|
36
|
+
if (!Number.isFinite(value)) return 0;
|
|
37
|
+
return Math.min(max, Math.max(-max, value));
|
|
38
|
+
}
|
|
39
|
+
/** A font size in pixels, at least one and at most `MAX_FONT_SIZE`; fractions are kept. */
|
|
40
|
+
function clampFontSize(value) {
|
|
41
|
+
if (!Number.isFinite(value)) return 1;
|
|
42
|
+
return Math.min(MAX_FONT_SIZE, Math.max(1, value));
|
|
43
|
+
}
|
|
44
|
+
/** A grid template's tracks, with at most `MAX_GRID_TRACKS` of them and no negative sizes. */
|
|
45
|
+
function clampGridTracks(tracks) {
|
|
46
|
+
return tracks.slice(0, MAX_GRID_TRACKS).map((track) => ({
|
|
47
|
+
...track,
|
|
48
|
+
value: clampLayoutLength(track.value)
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { MAX_FONT_SIZE, MAX_GRID_LINE, MAX_GRID_SPAN, MAX_GRID_TRACKS, MAX_LAYOUT_ANGLE, MAX_LAYOUT_FACTOR, MAX_LAYOUT_LENGTH, MAX_LAYOUT_SPACING, MAX_TEXT_LENGTH, clampFontSize, clampGridTracks, clampLayoutLength, clampLayoutPosition };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.js","names":[],"sources":["../../src/layout/limits.ts"],"sourcesContent":["import type { GridTrack } from '../types'\n\n/**\n * Bounds for the numbers layout computes with and for the values it writes back.\n *\n * Layout tolerates a span of zero or a track list a tool wrote by mistake, but not every\n * consumer does: a document carrying absurd geometry cannot be rasterized, a grid template\n * naming a billion tracks allocates one entry per track, and a text layer set at 1e9 px makes\n * font shaping build a run of glyphs no memory holds. Every path that writes a layout value\n * clamps to these bounds, and tool schemas reject values outside them.\n */\n\n/** The largest size or position, in pixels, that a layout value may carry. */\nexport const MAX_LAYOUT_LENGTH = 1_000_000\n\n/** The largest gap, padding, or stroke a layout value may carry, in pixels. */\nexport const MAX_LAYOUT_SPACING = 100_000\n\n/** The largest number of tracks one grid template may name. */\nexport const MAX_GRID_TRACKS = 1_000\n\n/** The last grid line a placement may name; line 0 leaves placement to auto-flow. */\nexport const MAX_GRID_LINE = 1_000\n\n/** The most tracks one grid item may span. */\nexport const MAX_GRID_SPAN = 1_000\n\n/** The largest rotation, in degrees, a layout or transform may carry. */\nexport const MAX_LAYOUT_ANGLE = 360_000\n\n/** The largest font size, in pixels, text may be set in. */\nexport const MAX_FONT_SIZE = 10_000\n\n/** The largest ratio a layout factor, such as a flex grow share, may carry. */\nexport const MAX_LAYOUT_FACTOR = 1_000\n\n/** The largest line height or letter spacing, in pixels or percent, a text may carry. */\nexport const MAX_TEXT_LENGTH = 10_000\n\n/** A length that cannot be negative, such as a size, padding, gap, or radius. */\nexport function clampLayoutLength(value: number, max = MAX_LAYOUT_LENGTH): number {\n if (!Number.isFinite(value)) return 0\n return Math.min(max, Math.max(0, value))\n}\n\n/** A coordinate that may be negative, such as a position. */\nexport function clampLayoutPosition(value: number, max = MAX_LAYOUT_LENGTH): number {\n if (!Number.isFinite(value)) return 0\n return Math.min(max, Math.max(-max, value))\n}\n\n/** A font size in pixels, at least one and at most `MAX_FONT_SIZE`; fractions are kept. */\nexport function clampFontSize(value: number): number {\n if (!Number.isFinite(value)) return 1\n return Math.min(MAX_FONT_SIZE, Math.max(1, value))\n}\n\n/** A grid template's tracks, with at most `MAX_GRID_TRACKS` of them and no negative sizes. */\nexport function clampGridTracks(tracks: readonly GridTrack[]): GridTrack[] {\n return tracks.slice(0, MAX_GRID_TRACKS).map((track) => ({\n ...track,\n value: clampLayoutLength(track.value)\n }))\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAa,oBAAoB;;AAGjC,MAAa,qBAAqB;;AAGlC,MAAa,kBAAkB;;AAG/B,MAAa,gBAAgB;;AAG7B,MAAa,gBAAgB;;AAG7B,MAAa,mBAAmB;;AAGhC,MAAa,gBAAgB;;AAG7B,MAAa,oBAAoB;;AAGjC,MAAa,kBAAkB;;AAG/B,SAAgB,kBAAkB,OAAe,MAAM,mBAA2B;CAChF,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,OAAO;CACpC,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,KAAK,CAAC;AACzC;;AAGA,SAAgB,oBAAoB,OAAe,MAAM,mBAA2B;CAClF,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,OAAO;CACpC,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,KAAK,CAAC;AAC5C;;AAGA,SAAgB,cAAc,OAAuB;CACnD,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,OAAO;CACpC,OAAO,KAAK,IAAI,eAAe,KAAK,IAAI,GAAG,KAAK,CAAC;AACnD;;AAGA,SAAgB,gBAAgB,QAA2C;CACzE,OAAO,OAAO,MAAM,GAAG,eAAe,CAAC,CAAC,KAAK,WAAW;EACtD,GAAG;EACH,OAAO,kBAAkB,MAAM,KAAK;CACtC,EAAE;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sizing.d.ts","names":[],"sources":["../../src/layout/sizing.ts"],"mappings":";;;;;;;;;;;KAWY;KAEP,iBAAiB,QAAQ;;iBAgDd,aACd,OAAO,YACP,MAAM,WACN,MAAM,mBACL;;iBAKa,qBACd,YAAY,uBACZ,MAAM,WACN,MAAM,mBACL;;iBASa,oBAAoB,OAAO,YAAY,MAAM,YAAY;;iBAOzD,kBACd,OAAO,YACP,MAAM,WACN,OAAO;;iBAoBO,kBAAkB,oBAAoB,sBAAsB;;;;;
|
|
1
|
+
{"version":3,"file":"sizing.d.ts","names":[],"sources":["../../src/layout/sizing.ts"],"mappings":";;;;;;;;;;;KAWY;KAEP,iBAAiB,QAAQ;;iBAgDd,aACd,OAAO,YACP,MAAM,WACN,MAAM,mBACL;;iBAKa,qBACd,YAAY,uBACZ,MAAM,WACN,MAAM,mBACL;;iBASa,oBAAoB,OAAO,YAAY,MAAM,YAAY;;iBAOzD,kBACd,OAAO,YACP,MAAM,WACN,OAAO;;iBAoBO,kBAAkB,oBAAoB,sBAAsB;;;;;iBAyB5D,oBACd,OAAO,YACP,MAAM,WACN,MAAM,kBACN,OAAO,eACN,QAAQ;;;;;;;iBA+BK,iBACd,cAAc,yBACd,MAAM,mBACL,QAAQ,KAAK;;iBAMA,uBACd,WAAW,gBACX,wBACA,0BACC,KAAK"}
|
package/dist/layout/sizing.js
CHANGED
|
@@ -69,7 +69,6 @@ function textSizingUpdates(graph, node, axis, value) {
|
|
|
69
69
|
const hugsAxis = value === "HUG";
|
|
70
70
|
const hugsOther = layoutSizing(graph, node, other) === "HUG";
|
|
71
71
|
const autoResize = axis === "HORIZONTAL" ? textAutoResizeFor(hugsAxis, hugsOther) : textAutoResizeFor(hugsOther, hugsAxis);
|
|
72
|
-
if (autoResize === "NONE" && node.textAutoResize === "TRUNCATE") return {};
|
|
73
72
|
return autoResize === node.textAutoResize ? {} : { textAutoResize: autoResize };
|
|
74
73
|
}
|
|
75
74
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sizing.js","names":[],"sources":["../../src/layout/sizing.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { LayoutSizing, SceneNode, TextAutoResize } from '../types'\n\n/**\n * How a node sizes along one screen axis, as Figma's `layoutSizingHorizontal` and\n * `layoutSizingVertical` report it. Fill is stored on the child, the way Figma stores it:\n * along the parent's primary axis as `layoutGrow`, across it as `layoutAlignSelf: 'STRETCH'`.\n * A grid lays its children out like a horizontal stack. Hug is stored on the node itself:\n * `primaryAxisSizing` and `counterAxisSizing` for an auto-layout frame, `textAutoResize`\n * for text.\n */\nexport type LayoutSizingAxis = 'HORIZONTAL' | 'VERTICAL'\n\ntype AutoLayoutMode = Exclude<SceneNode['layoutMode'], 'NONE'>\n\nfunction primaryAxis(mode: AutoLayoutMode): LayoutSizingAxis {\n return mode === 'VERTICAL' ? 'VERTICAL' : 'HORIZONTAL'\n}\n\n/** The auto-layout parent that sizes a node's fill, or `undefined` when nothing does. */\nfunction fillingParent(parent: SceneNode | undefined, node: SceneNode): SceneNode | undefined {\n if (!parent || parent.layoutMode === 'NONE' || node.layoutPositioning === 'ABSOLUTE')\n return undefined\n return parent\n}\n\nfunction graphParent(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n return node.parentId ? graph.getNode(node.parentId) : undefined\n}\n\nfunction fills(parent: SceneNode, node: SceneNode, axis: LayoutSizingAxis): boolean {\n if (parent.layoutMode === 'NONE') return false\n if (axis === primaryAxis(parent.layoutMode)) return node.layoutGrow > 0\n if (node.layoutAlignSelf === 'STRETCH') return true\n return (\n node.layoutAlignSelf === 'AUTO' &&\n parent.layoutMode !== 'GRID' &&\n parent.counterAxisAlign === 'STRETCH'\n )\n}\n\nfunction ownSizingField(\n node: SceneNode,\n axis: LayoutSizingAxis\n): 'primaryAxisSizing' | 'counterAxisSizing' | undefined {\n if (node.layoutMode === 'NONE') return undefined\n return axis === primaryAxis(node.layoutMode) ? 'primaryAxisSizing' : 'counterAxisSizing'\n}\n\nfunction textHugs(autoResize: TextAutoResize, axis: LayoutSizingAxis): boolean {\n if (autoResize === 'WIDTH_AND_HEIGHT') return true\n return axis === 'VERTICAL' && autoResize === 'HEIGHT'\n}\n\nfunction hugs(node: SceneNode, axis: LayoutSizingAxis): boolean {\n if (node.type === 'TEXT') return textHugs(node.textAutoResize, axis)\n const field = ownSizingField(node, axis)\n return field !== undefined && node[field] === 'HUG'\n}\n\n/** The node's sizing along `axis`: fill from its parent, else its own hug, else fixed. */\nexport function layoutSizing(\n graph: SceneGraph,\n node: SceneNode,\n axis: LayoutSizingAxis\n): LayoutSizing {\n return layoutSizingInParent(graphParent(graph, node), node, axis)\n}\n\n/** `layoutSizing` for code that holds the parent rather than the graph. */\nexport function layoutSizingInParent(\n parentNode: SceneNode | undefined,\n node: SceneNode,\n axis: LayoutSizingAxis\n): LayoutSizing {\n const parent = fillingParent(parentNode, node)\n if (parent && fills(parent, node, axis)) return 'FILL'\n // Figma reports text outside auto-layout as fixed, though it still resizes to its content.\n if (hugs(node, axis) && (parent || node.layoutMode !== 'NONE')) return 'HUG'\n return 'FIXED'\n}\n\n/** The sizings this node accepts on either axis, in Figma's order. */\nexport function layoutSizingOptions(graph: SceneGraph, node: SceneNode): LayoutSizing[] {\n return (['FIXED', 'HUG', 'FILL'] as const).filter(\n (value) => layoutSizingError(graph, node, value) === undefined\n )\n}\n\n/** Figma's reason for refusing `value` on this node, or `undefined` when it applies. */\nexport function layoutSizingError(\n graph: SceneGraph,\n node: SceneNode,\n value: LayoutSizing\n): string | undefined {\n const parent = graphParent(graph, node)\n const inAutoLayout = parent !== undefined && parent.layoutMode !== 'NONE'\n if (!inAutoLayout && node.layoutMode === 'NONE') {\n return 'node must be an auto-layout frame or a child of an auto-layout frame'\n }\n if (value === 'FILL') {\n if (!inAutoLayout) return 'FILL can only be set on children of auto-layout frames'\n if (node.layoutPositioning === 'ABSOLUTE') {\n return 'FILL cannot be set on absolute positioned auto-layout children'\n }\n }\n if (value === 'HUG' && node.layoutMode === 'NONE' && node.type !== 'TEXT') {\n return 'HUG can only be set on auto-layout frames or text children of auto-layout frames'\n }\n return undefined\n}\n\n/** The text auto-resize that hugs the content along the axes given. */\nexport function textAutoResizeFor(hugsWidth: boolean, hugsHeight: boolean): TextAutoResize {\n if (hugsWidth && hugsHeight) return 'WIDTH_AND_HEIGHT'\n return hugsHeight ? 'HEIGHT' : 'NONE'\n}\n\nfunction textSizingUpdates(\n graph: SceneGraph,\n node: SceneNode,\n axis: LayoutSizingAxis,\n value: LayoutSizing\n): Partial<SceneNode> {\n const other: LayoutSizingAxis = axis === 'HORIZONTAL' ? 'VERTICAL' : 'HORIZONTAL'\n const hugsAxis = value === 'HUG'\n const hugsOther = layoutSizing(graph, node, other) === 'HUG'\n const autoResize =\n axis === 'HORIZONTAL'\n ? textAutoResizeFor(hugsAxis, hugsOther)\n : textAutoResizeFor(hugsOther, hugsAxis)\n // Truncated text keeps truncating when it stops hugging.\n if (autoResize === 'NONE' && node.textAutoResize === 'TRUNCATE') return {}\n return autoResize === node.textAutoResize ? {} : { textAutoResize: autoResize }\n}\n\n/**\n * The fields that set the node's sizing along `axis` to `value`, as Figma's setter writes\n * them. A value Figma refuses yields no updates; `layoutSizingError` says why.\n */\nexport function layoutSizingUpdates(\n graph: SceneGraph,\n node: SceneNode,\n axis: LayoutSizingAxis,\n value: LayoutSizing\n): Partial<SceneNode> {\n if (layoutSizingError(graph, node, value) !== undefined) return {}\n const updates: Partial<SceneNode> = {}\n const parent = fillingParent(graphParent(graph, node), node)\n if (parent && parent.layoutMode !== 'NONE') {\n const fill = value === 'FILL'\n if (axis === primaryAxis(parent.layoutMode)) {\n if (fill !== node.layoutGrow > 0) updates.layoutGrow = fill ? 1 : 0\n } else if (fill && node.layoutAlignSelf !== 'STRETCH') {\n updates.layoutAlignSelf = 'STRETCH'\n } else if (!fill && fills(parent, node, axis)) {\n // A flex parent set to stretch its children stretches this one too unless it opts out.\n const inheritsStretch = parent.layoutMode !== 'GRID' && parent.counterAxisAlign === 'STRETCH'\n updates.layoutAlignSelf = inheritsStretch ? 'MIN' : 'AUTO'\n }\n }\n const field = ownSizingField(node, axis)\n if (field) {\n const own = value === 'HUG' ? 'HUG' : 'FIXED'\n if (node[field] !== own) updates[field] = own\n }\n if (node.type === 'TEXT') Object.assign(updates, textSizingUpdates(graph, node, axis, value))\n return updates\n}\n\n/**\n * The fields that make a child fill `axis` of a parent laid out as `parentLayout`, for a node\n * an importer builds before it joins the graph. Under a parent without auto layout, such as a\n * staging parent the node leaves when placed, both are set, so it fills whichever axis its\n * eventual parent stacks along.\n */\nexport function fillSizingFields(\n parentLayout: SceneNode['layoutMode'],\n axis: LayoutSizingAxis\n): Partial<Pick<SceneNode, 'layoutGrow' | 'layoutAlignSelf'>> {\n if (parentLayout === 'NONE') return { layoutGrow: 1, layoutAlignSelf: 'STRETCH' }\n return axis === primaryAxis(parentLayout) ? { layoutGrow: 1 } : { layoutAlignSelf: 'STRETCH' }\n}\n\n/** An auto-layout frame's own sizing when it hugs or fixes its width and height. */\nexport function autoLayoutSizingFields(\n direction: AutoLayoutMode,\n width: 'FIXED' | 'HUG',\n height: 'FIXED' | 'HUG'\n): Pick<SceneNode, 'primaryAxisSizing' | 'counterAxisSizing'> {\n const horizontal = primaryAxis(direction) === 'HORIZONTAL'\n return {\n primaryAxisSizing: horizontal ? width : height,\n counterAxisSizing: horizontal ? height : width\n }\n}\n"],"mappings":";AAeA,SAAS,YAAY,MAAwC;CAC3D,OAAO,SAAS,aAAa,aAAa;AAC5C;;AAGA,SAAS,cAAc,QAA+B,MAAwC;CAC5F,IAAI,CAAC,UAAU,OAAO,eAAe,UAAU,KAAK,sBAAsB,YACxE,OAAO,KAAA;CACT,OAAO;AACT;AAEA,SAAS,YAAY,OAAmB,MAAwC;CAC9E,OAAO,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;AACxD;AAEA,SAAS,MAAM,QAAmB,MAAiB,MAAiC;CAClF,IAAI,OAA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AAM,UAAU,QAAQ,QAAQ;EACtC,IAAI,KAAK,WAAW,KAAK,QAAQ,SAAS;CAC5C;CACA,IAAI,KAAK,SAAS,QAAQ,OAAO,OAAO,SAAS,kBAAkB,OAAO,MAAM,MAAM,KAAK,CAAC;CAC5F,OAAO;AACT;;;;;;;AAQA,SAAgB,iBACd,cACA,MAC4D;CAC5D,IAAI,iBAAiB,QAAQ,OAAO;EAAE,YAAY;EAAG,iBAAiB;CAAU;CAChF,OAAO,SAAS,YAAY,YAAY,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,UAAU;AAC/F;;AAGA,SAAgB,uBACd,WACA,OACA,QAC4D;CAC5D,MAAM,aAAa,YAAY,SAAS,MAAM;CAC9C,OAAO;EACL,mBAAmB,aAAa,QAAQ;EACxC,mBAAmB,aAAa,SAAS;CAC3C;AACF"}
|
|
1
|
+
{"version":3,"file":"sizing.js","names":[],"sources":["../../src/layout/sizing.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { LayoutSizing, SceneNode, TextAutoResize } from '../types'\n\n/**\n * How a node sizes along one screen axis, as Figma's `layoutSizingHorizontal` and\n * `layoutSizingVertical` report it. Fill is stored on the child, the way Figma stores it:\n * along the parent's primary axis as `layoutGrow`, across it as `layoutAlignSelf: 'STRETCH'`.\n * A grid lays its children out like a horizontal stack. Hug is stored on the node itself:\n * `primaryAxisSizing` and `counterAxisSizing` for an auto-layout frame, `textAutoResize`\n * for text.\n */\nexport type LayoutSizingAxis = 'HORIZONTAL' | 'VERTICAL'\n\ntype AutoLayoutMode = Exclude<SceneNode['layoutMode'], 'NONE'>\n\nfunction primaryAxis(mode: AutoLayoutMode): LayoutSizingAxis {\n return mode === 'VERTICAL' ? 'VERTICAL' : 'HORIZONTAL'\n}\n\n/** The auto-layout parent that sizes a node's fill, or `undefined` when nothing does. */\nfunction fillingParent(parent: SceneNode | undefined, node: SceneNode): SceneNode | undefined {\n if (!parent || parent.layoutMode === 'NONE' || node.layoutPositioning === 'ABSOLUTE')\n return undefined\n return parent\n}\n\nfunction graphParent(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n return node.parentId ? graph.getNode(node.parentId) : undefined\n}\n\nfunction fills(parent: SceneNode, node: SceneNode, axis: LayoutSizingAxis): boolean {\n if (parent.layoutMode === 'NONE') return false\n if (axis === primaryAxis(parent.layoutMode)) return node.layoutGrow > 0\n if (node.layoutAlignSelf === 'STRETCH') return true\n return (\n node.layoutAlignSelf === 'AUTO' &&\n parent.layoutMode !== 'GRID' &&\n parent.counterAxisAlign === 'STRETCH'\n )\n}\n\nfunction ownSizingField(\n node: SceneNode,\n axis: LayoutSizingAxis\n): 'primaryAxisSizing' | 'counterAxisSizing' | undefined {\n if (node.layoutMode === 'NONE') return undefined\n return axis === primaryAxis(node.layoutMode) ? 'primaryAxisSizing' : 'counterAxisSizing'\n}\n\nfunction textHugs(autoResize: TextAutoResize, axis: LayoutSizingAxis): boolean {\n if (autoResize === 'WIDTH_AND_HEIGHT') return true\n return axis === 'VERTICAL' && autoResize === 'HEIGHT'\n}\n\nfunction hugs(node: SceneNode, axis: LayoutSizingAxis): boolean {\n if (node.type === 'TEXT') return textHugs(node.textAutoResize, axis)\n const field = ownSizingField(node, axis)\n return field !== undefined && node[field] === 'HUG'\n}\n\n/** The node's sizing along `axis`: fill from its parent, else its own hug, else fixed. */\nexport function layoutSizing(\n graph: SceneGraph,\n node: SceneNode,\n axis: LayoutSizingAxis\n): LayoutSizing {\n return layoutSizingInParent(graphParent(graph, node), node, axis)\n}\n\n/** `layoutSizing` for code that holds the parent rather than the graph. */\nexport function layoutSizingInParent(\n parentNode: SceneNode | undefined,\n node: SceneNode,\n axis: LayoutSizingAxis\n): LayoutSizing {\n const parent = fillingParent(parentNode, node)\n if (parent && fills(parent, node, axis)) return 'FILL'\n // Figma reports text outside auto-layout as fixed, though it still resizes to its content.\n if (hugs(node, axis) && (parent || node.layoutMode !== 'NONE')) return 'HUG'\n return 'FIXED'\n}\n\n/** The sizings this node accepts on either axis, in Figma's order. */\nexport function layoutSizingOptions(graph: SceneGraph, node: SceneNode): LayoutSizing[] {\n return (['FIXED', 'HUG', 'FILL'] as const).filter(\n (value) => layoutSizingError(graph, node, value) === undefined\n )\n}\n\n/** Figma's reason for refusing `value` on this node, or `undefined` when it applies. */\nexport function layoutSizingError(\n graph: SceneGraph,\n node: SceneNode,\n value: LayoutSizing\n): string | undefined {\n const parent = graphParent(graph, node)\n const inAutoLayout = parent !== undefined && parent.layoutMode !== 'NONE'\n if (!inAutoLayout && node.layoutMode === 'NONE') {\n return 'node must be an auto-layout frame or a child of an auto-layout frame'\n }\n if (value === 'FILL') {\n if (!inAutoLayout) return 'FILL can only be set on children of auto-layout frames'\n if (node.layoutPositioning === 'ABSOLUTE') {\n return 'FILL cannot be set on absolute positioned auto-layout children'\n }\n }\n if (value === 'HUG' && node.layoutMode === 'NONE' && node.type !== 'TEXT') {\n return 'HUG can only be set on auto-layout frames or text children of auto-layout frames'\n }\n return undefined\n}\n\n/** The text auto-resize that hugs the content along the axes given. */\nexport function textAutoResizeFor(hugsWidth: boolean, hugsHeight: boolean): TextAutoResize {\n if (hugsWidth && hugsHeight) return 'WIDTH_AND_HEIGHT'\n return hugsHeight ? 'HEIGHT' : 'NONE'\n}\n\nfunction textSizingUpdates(\n graph: SceneGraph,\n node: SceneNode,\n axis: LayoutSizingAxis,\n value: LayoutSizing\n): Partial<SceneNode> {\n const other: LayoutSizingAxis = axis === 'HORIZONTAL' ? 'VERTICAL' : 'HORIZONTAL'\n const hugsAxis = value === 'HUG'\n const hugsOther = layoutSizing(graph, node, other) === 'HUG'\n const autoResize =\n axis === 'HORIZONTAL'\n ? textAutoResizeFor(hugsAxis, hugsOther)\n : textAutoResizeFor(hugsOther, hugsAxis)\n return autoResize === node.textAutoResize ? {} : { textAutoResize: autoResize }\n}\n\n/**\n * The fields that set the node's sizing along `axis` to `value`, as Figma's setter writes\n * them. A value Figma refuses yields no updates; `layoutSizingError` says why.\n */\nexport function layoutSizingUpdates(\n graph: SceneGraph,\n node: SceneNode,\n axis: LayoutSizingAxis,\n value: LayoutSizing\n): Partial<SceneNode> {\n if (layoutSizingError(graph, node, value) !== undefined) return {}\n const updates: Partial<SceneNode> = {}\n const parent = fillingParent(graphParent(graph, node), node)\n if (parent && parent.layoutMode !== 'NONE') {\n const fill = value === 'FILL'\n if (axis === primaryAxis(parent.layoutMode)) {\n if (fill !== node.layoutGrow > 0) updates.layoutGrow = fill ? 1 : 0\n } else if (fill && node.layoutAlignSelf !== 'STRETCH') {\n updates.layoutAlignSelf = 'STRETCH'\n } else if (!fill && fills(parent, node, axis)) {\n // A flex parent set to stretch its children stretches this one too unless it opts out.\n const inheritsStretch = parent.layoutMode !== 'GRID' && parent.counterAxisAlign === 'STRETCH'\n updates.layoutAlignSelf = inheritsStretch ? 'MIN' : 'AUTO'\n }\n }\n const field = ownSizingField(node, axis)\n if (field) {\n const own = value === 'HUG' ? 'HUG' : 'FIXED'\n if (node[field] !== own) updates[field] = own\n }\n if (node.type === 'TEXT') Object.assign(updates, textSizingUpdates(graph, node, axis, value))\n return updates\n}\n\n/**\n * The fields that make a child fill `axis` of a parent laid out as `parentLayout`, for a node\n * an importer builds before it joins the graph. Under a parent without auto layout, such as a\n * staging parent the node leaves when placed, both are set, so it fills whichever axis its\n * eventual parent stacks along.\n */\nexport function fillSizingFields(\n parentLayout: SceneNode['layoutMode'],\n axis: LayoutSizingAxis\n): Partial<Pick<SceneNode, 'layoutGrow' | 'layoutAlignSelf'>> {\n if (parentLayout === 'NONE') return { layoutGrow: 1, layoutAlignSelf: 'STRETCH' }\n return axis === primaryAxis(parentLayout) ? { layoutGrow: 1 } : { layoutAlignSelf: 'STRETCH' }\n}\n\n/** An auto-layout frame's own sizing when it hugs or fixes its width and height. */\nexport function autoLayoutSizingFields(\n direction: AutoLayoutMode,\n width: 'FIXED' | 'HUG',\n height: 'FIXED' | 'HUG'\n): Pick<SceneNode, 'primaryAxisSizing' | 'counterAxisSizing'> {\n const horizontal = primaryAxis(direction) === 'HORIZONTAL'\n return {\n primaryAxisSizing: horizontal ? width : height,\n counterAxisSizing: horizontal ? height : width\n }\n}\n"],"mappings":";AAeA,SAAS,YAAY,MAAwC;CAC3D,OAAO,SAAS,aAAa,aAAa;AAC5C;;AAGA,SAAS,cAAc,QAA+B,MAAwC;CAC5F,IAAI,CAAC,UAAU,OAAO,eAAe,UAAU,KAAK,sBAAsB,YACxE,OAAO,KAAA;CACT,OAAO;AACT;AAEA,SAAS,YAAY,OAAmB,MAAwC;CAC9E,OAAO,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;AACxD;AAEA,SAAS,MAAM,QAAmB,MAAiB,MAAiC;CAClF,IAAI,OAAO,eAAe,QAAQ,OAAO;CACzC,IAAI,SAAS,YAAY,OAAO,UAAU,GAAG,OAAO,KAAK,aAAa;CACtE,IAAI,KAAK,oBAAoB,WAAW,OAAO;CAC/C,OACE,KAAK,oBAAoB,UACzB,OAAO,eAAe,UACtB,OAAO,qBAAqB;AAEhC;AAEA,SAAS,eACP,MACA,MACuD;CACvD,IAAI,KAAK,eAAe,QAAQ,OAAO,KAAA;CACvC,OAAO,SAAS,YAAY,KAAK,UAAU,IAAI,sBAAsB;AACvE;AAEA,SAAS,SAAS,YAA4B,MAAiC;CAC7E,IAAI,eAAe,oBAAoB,OAAO;CAC9C,OAAO,SAAS,cAAc,eAAe;AAC/C;AAEA,SAAS,KAAK,MAAiB,MAAiC;CAC9D,IAAI,KAAK,SAAS,QAAQ,OAAO,SAAS,KAAK,gBAAgB,IAAI;CACnE,MAAM,QAAQ,eAAe,MAAM,IAAI;CACvC,OAAO,UAAU,KAAA,KAAa,KAAK,WAAW;AAChD;;AAGA,SAAgB,aACd,OACA,MACA,MACc;CACd,OAAO,qBAAqB,YAAY,OAAO,IAAI,GAAG,MAAM,IAAI;AAClE;;AAGA,SAAgB,qBACd,YACA,MACA,MACc;CACd,MAAM,SAAS,cAAc,YAAY,IAAI;CAC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AU,OAAO,eAAe,QAAQ;EAC1C,MAAM,OAAO,UAAU;EACvB,IAAI,SAAS,YAAY,OAAO,UAAU,GACpC;OAAA,SAAS,KAAK,aAAa,GAAG,QAAQ,aAAa,OAAO,IAAI;EAAA,OAC7D,IAAI,QAAQ,KAAK,oBAAoB,WAC1C,QAAQ,kBAAkB;OACrB,IAAI,CAAC,QAAQ,MAAM,QAAQ,MAAM,IAAI,GAG1C,QAAQ,kBADgB,OAAO,eAAe,UAAU,OAAO,qBAAqB,YACxC,QAAQ;CAExD;CACA,MAAM,QAAQ,eAAe,MAAM,IAAI;CACvC,IAAI,OAAO;EACT,MAAM,MAAM,UAAU,QAAQ,QAAQ;EACtC,IAAI,KAAK,WAAW,KAAK,QAAQ,SAAS;CAC5C;CACA,IAAI,KAAK,SAAS,QAAQ,OAAO,OAAO,SAAS,kBAAkB,OAAO,MAAM,MAAM,KAAK,CAAC;CAC5F,OAAO;AACT;;;;;;;AAQA,SAAgB,iBACd,cACA,MAC4D;CAC5D,IAAI,iBAAiB,QAAQ,OAAO;EAAE,YAAY;EAAG,iBAAiB;CAAU;CAChF,OAAO,SAAS,YAAY,YAAY,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,UAAU;AAC/F;;AAGA,SAAgB,uBACd,WACA,OACA,QAC4D;CAC5D,MAAM,aAAa,YAAY,SAAS,MAAM;CAC9C,OAAO;EACL,mBAAmB,aAAa,QAAQ;EACxC,mBAAmB,aAAa,SAAS;CAC3C;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SceneNode } from "../types.js";
|
|
2
|
+
//#region src/layout/spacing.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The space between wrapped lines of an auto layout. A frame without its own follows the item
|
|
5
|
+
* spacing, as Figma's `counterAxisSpacing: null` does.
|
|
6
|
+
*/
|
|
7
|
+
declare function counterAxisSpacingOf(node: Pick<SceneNode, 'counterAxisSpacing' | 'itemSpacing'>): number;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { counterAxisSpacingOf };
|
|
10
|
+
//# sourceMappingURL=spacing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spacing.d.ts","names":[],"sources":["../../src/layout/spacing.ts"],"mappings":";;;;;;iBAMgB,qBACd,MAAM,KAAK"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/layout/spacing.ts
|
|
2
|
+
/**
|
|
3
|
+
* The space between wrapped lines of an auto layout. A frame without its own follows the item
|
|
4
|
+
* spacing, as Figma's `counterAxisSpacing: null` does.
|
|
5
|
+
*/
|
|
6
|
+
function counterAxisSpacingOf(node) {
|
|
7
|
+
return node.counterAxisSpacing ?? node.itemSpacing;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { counterAxisSpacingOf };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=spacing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spacing.js","names":[],"sources":["../../src/layout/spacing.ts"],"sourcesContent":["import type { SceneNode } from '../types'\n\n/**\n * The space between wrapped lines of an auto layout. A frame without its own follows the item\n * spacing, as Figma's `counterAxisSpacing: null` does.\n */\nexport function counterAxisSpacingOf(\n node: Pick<SceneNode, 'counterAxisSpacing' | 'itemSpacing'>\n): number {\n return node.counterAxisSpacing ?? node.itemSpacing\n}\n"],"mappings":";;;;;AAMA,SAAgB,qBACd,MACQ;CACR,OAAO,KAAK,sBAAsB,KAAK;AACzC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SceneNode } from "../types.js";
|
|
2
|
+
//#region src/layout/strokes.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The stroke a frame counts inside its padding, per side: its visible INSIDE strokes when its
|
|
5
|
+
* strokes are included in layout, as Figma lays it out and as a CSS border takes room.
|
|
6
|
+
*/
|
|
7
|
+
declare function includedStrokeWeights(node: SceneNode): Record<'top' | 'right' | 'bottom' | 'left', number>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { includedStrokeWeights };
|
|
10
|
+
//# sourceMappingURL=strokes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strokes.d.ts","names":[],"sources":["../../src/layout/strokes.ts"],"mappings":";;;;;;iBAMgB,sBACd,MAAM,YACL"}
|