@open-pencil/scene-graph 0.17.0-beta.1 → 0.17.0-beta.3
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/arrow-caps.d.ts.map +1 -1
- package/dist/arrow-caps.js +2 -5
- package/dist/arrow-caps.js.map +1 -1
- package/dist/asset-keys.d.ts +11 -1
- package/dist/asset-keys.d.ts.map +1 -1
- package/dist/asset-keys.js +16 -1
- package/dist/asset-keys.js.map +1 -1
- package/dist/behaviours/index.d.ts +2 -2
- package/dist/behaviours/index.js +2 -2
- package/dist/behaviours/kinds.d.ts +11 -5
- package/dist/behaviours/kinds.d.ts.map +1 -1
- package/dist/behaviours/kinds.js +76 -75
- package/dist/behaviours/kinds.js.map +1 -1
- package/dist/behaviours/layers.d.ts.map +1 -1
- package/dist/behaviours/layers.js +3 -2
- package/dist/behaviours/layers.js.map +1 -1
- package/dist/behaviours/model.d.ts +7 -4
- package/dist/behaviours/model.d.ts.map +1 -1
- package/dist/behaviours/model.js +16 -9
- package/dist/behaviours/model.js.map +1 -1
- package/dist/behaviours/schema.d.ts +118 -4
- package/dist/behaviours/schema.d.ts.map +1 -1
- package/dist/behaviours/schema.js +18 -3
- package/dist/behaviours/schema.js.map +1 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +3 -2
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/bindings.js +9 -1
- package/dist/bindings.js.map +1 -1
- package/dist/checkpoint.d.ts +31 -2
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +211 -10
- package/dist/checkpoint.js.map +1 -1
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +3 -3
- package/dist/components/properties.d.ts +18 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +66 -3
- package/dist/components/properties.js.map +1 -1
- package/dist/components/variants.d.ts +16 -10
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +39 -13
- package/dist/components/variants.js.map +1 -1
- package/dist/connectors/hit.d.ts.map +1 -1
- package/dist/connectors/hit.js +1 -7
- package/dist/connectors/hit.js.map +1 -1
- package/dist/connectors/pieces.d.ts.map +1 -1
- package/dist/connectors/pieces.js +2 -5
- package/dist/connectors/pieces.js.map +1 -1
- package/dist/constants.d.ts +6 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +17 -1
- package/dist/constants.js.map +1 -1
- package/dist/constraints.d.ts +25 -0
- package/dist/constraints.d.ts.map +1 -0
- package/dist/constraints.js +51 -0
- package/dist/constraints.js.map +1 -0
- package/dist/coordinate.d.ts +64 -1
- package/dist/coordinate.d.ts.map +1 -1
- package/dist/coordinate.js +217 -1
- package/dist/coordinate.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +17 -16
- package/dist/copy.js.map +1 -1
- package/dist/css/blend.d.ts +11 -0
- package/dist/css/blend.d.ts.map +1 -0
- package/dist/css/blend.js +30 -0
- package/dist/css/blend.js.map +1 -0
- package/dist/css/index.d.ts +4 -2
- package/dist/css/index.js +4 -2
- package/dist/css/text.d.ts +28 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +84 -17
- package/dist/css/text.js.map +1 -1
- package/dist/css/transform.d.ts +34 -0
- package/dist/css/transform.d.ts.map +1 -0
- package/dist/css/transform.js +320 -0
- package/dist/css/transform.js.map +1 -0
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +11 -1
- package/dist/css/values.js.map +1 -1
- package/dist/cubic.d.ts +7 -0
- package/dist/cubic.d.ts.map +1 -0
- package/dist/cubic.js +17 -0
- package/dist/cubic.js.map +1 -0
- package/dist/export-format.d.ts +14 -1
- package/dist/export-format.d.ts.map +1 -1
- package/dist/export-format.js +26 -1
- package/dist/export-format.js.map +1 -1
- package/dist/fields/text.d.ts +2 -2
- package/dist/fields/text.d.ts.map +1 -1
- package/dist/fields/text.js +2 -1
- package/dist/fields/text.js.map +1 -1
- package/dist/figjam/index.d.ts +2 -2
- package/dist/figjam/index.js +2 -2
- package/dist/figjam/palette.d.ts +13 -2
- package/dist/figjam/palette.d.ts.map +1 -1
- package/dist/figjam/palette.js +30 -2
- package/dist/figjam/palette.js.map +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.js +2 -2
- package/dist/generated/shape-with-text.d.ts +7 -2
- package/dist/generated/shape-with-text.d.ts.map +1 -1
- package/dist/generated/shape-with-text.js +20 -3
- package/dist/generated/shape-with-text.js.map +1 -1
- package/dist/geometry.d.ts +37 -46
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +80 -137
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +49 -12
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +125 -27
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts +14 -4
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +76 -11
- package/dist/group-bounds.js.map +1 -1
- package/dist/guides.d.ts +3 -1
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +5 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts +5 -0
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +57 -38
- package/dist/hit-test.js.map +1 -1
- package/dist/images.d.ts +27 -3
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +57 -3
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +8 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +1 -3
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +39 -30
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +204 -0
- package/dist/instances/kept-overrides.js.map +1 -0
- package/dist/instances/main-component.d.ts +3 -1
- package/dist/instances/main-component.d.ts.map +1 -1
- package/dist/instances/main-component.js +10 -2
- package/dist/instances/main-component.js.map +1 -1
- package/dist/instances/overrides.d.ts +4 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +18 -2
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/placement.js +55 -12
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap.js +291 -0
- package/dist/instances/swap.js.map +1 -0
- package/dist/instances/sync.js +112 -39
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +2 -1
- package/dist/node-defaults.js.map +1 -1
- package/dist/order-keys.d.ts +3 -1
- package/dist/order-keys.d.ts.map +1 -1
- package/dist/order-keys.js +6 -1
- package/dist/order-keys.js.map +1 -1
- package/dist/outline/flatten.d.ts +15 -0
- package/dist/outline/flatten.d.ts.map +1 -0
- package/dist/outline/flatten.js +189 -0
- package/dist/outline/flatten.js.map +1 -0
- package/dist/outline/heads.js +34 -0
- package/dist/outline/heads.js.map +1 -0
- package/dist/outline/hit.d.ts +21 -0
- package/dist/outline/hit.d.ts.map +1 -0
- package/dist/outline/hit.js +276 -0
- package/dist/outline/hit.js.map +1 -0
- package/dist/outline/index.d.ts +5 -0
- package/dist/outline/index.js +5 -0
- package/dist/outline/point.d.ts +16 -0
- package/dist/outline/point.d.ts.map +1 -0
- package/dist/outline/point.js +42 -0
- package/dist/outline/point.js.map +1 -0
- package/dist/outline/shapes.d.ts +35 -0
- package/dist/outline/shapes.d.ts.map +1 -0
- package/dist/outline/shapes.js +181 -0
- package/dist/outline/shapes.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +4 -1
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +21 -4
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/resize.d.ts +22 -11
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +227 -93
- package/dist/resize.js.map +1 -1
- package/dist/scaling/index.d.ts +3 -2
- package/dist/scaling/index.js +3 -2
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +5 -1
- package/dist/scaling/node.js.map +1 -1
- package/dist/scaling/snapshot.d.ts +25 -0
- package/dist/scaling/snapshot.d.ts.map +1 -0
- package/dist/scaling/snapshot.js +39 -0
- package/dist/scaling/snapshot.js.map +1 -0
- package/dist/scaling/tree.d.ts +24 -2
- package/dist/scaling/tree.d.ts.map +1 -1
- package/dist/scaling/tree.js +38 -15
- package/dist/scaling/tree.js.map +1 -1
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +2 -1
- package/dist/shaders/model.js.map +1 -1
- package/dist/shared-styles.d.ts +16 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +69 -2
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/authoring.d.ts +3 -2
- package/dist/slots/authoring.d.ts.map +1 -1
- package/dist/slots/authoring.js +5 -3
- package/dist/slots/authoring.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +6 -1
- package/dist/slots/content.js.map +1 -1
- package/dist/slots/frames.d.ts +2 -0
- package/dist/slots/frames.d.ts.map +1 -1
- package/dist/slots/frames.js +7 -2
- package/dist/slots/frames.js.map +1 -1
- package/dist/text/direction.d.ts +3 -1
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +5 -1
- package/dist/text/direction.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +3 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +2 -2
- package/dist/text/overflow.js.map +1 -1
- package/dist/text/picture.d.ts +1 -2
- package/dist/text/picture.d.ts.map +1 -1
- package/dist/text/picture.js +1 -4
- package/dist/text/picture.js.map +1 -1
- package/dist/transfer/apply.d.ts.map +1 -1
- package/dist/transfer/apply.js +1 -6
- package/dist/transfer/apply.js.map +1 -1
- package/dist/transfer/copied.d.ts +35 -3
- package/dist/transfer/copied.d.ts.map +1 -1
- package/dist/transfer/copied.js +44 -13
- package/dist/transfer/copied.js.map +1 -1
- package/dist/transfer/dependencies.d.ts +38 -0
- package/dist/transfer/dependencies.d.ts.map +1 -0
- package/dist/transfer/dependencies.js +100 -0
- package/dist/transfer/dependencies.js.map +1 -0
- package/dist/transfer/history.js +0 -1
- package/dist/transfer/history.js.map +1 -1
- package/dist/transfer/index.d.ts +5 -3
- package/dist/transfer/index.js +5 -3
- package/dist/transfer/nodes.d.ts.map +1 -1
- package/dist/transfer/nodes.js +16 -19
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/transfer/plan.d.ts +0 -1
- package/dist/transfer/plan.js +3 -5
- package/dist/transfer/plan.js.map +1 -1
- package/dist/transfer/remove.js +5 -2
- package/dist/transfer/remove.js.map +1 -1
- package/dist/transfer/resources.d.ts +21 -0
- package/dist/transfer/resources.d.ts.map +1 -0
- package/dist/transfer/resources.js +38 -0
- package/dist/transfer/resources.js.map +1 -0
- package/dist/transfer/variables.d.ts +8 -1
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +24 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +73 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +28 -3
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +24 -7
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +37 -11
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +122 -74
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/fields.d.ts +19 -1
- package/dist/variables/fields.d.ts.map +1 -1
- package/dist/variables/fields.js +36 -1
- package/dist/variables/fields.js.map +1 -1
- package/dist/variables/formula/check.d.ts +1 -1
- package/dist/variables/formula/index.d.ts +2 -2
- package/dist/variables/formula/index.js +1 -1
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/formula/print.d.ts +1 -1
- package/dist/variables/formula/signatures.js +1 -1
- package/dist/variables/index.d.ts +7 -7
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +57 -26
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +57 -0
- package/dist/variables/paints.d.ts.map +1 -0
- package/dist/variables/paints.js +231 -0
- package/dist/variables/paints.js.map +1 -0
- package/dist/variables/resolution.d.ts +14 -11
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +36 -17
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +17 -0
- package/dist/variables/subtree.js.map +1 -0
- package/dist/vector-network.d.ts.map +1 -1
- package/dist/vector-network.js +2 -8
- package/dist/vector-network.js.map +1 -1
- package/package.json +14 -1
- package/src/arrow-caps.ts +2 -5
- package/src/asset-keys.ts +20 -0
- package/src/behaviours/kinds.ts +51 -34
- package/src/behaviours/layers.ts +4 -2
- package/src/behaviours/model.ts +22 -11
- package/src/behaviours/schema.ts +20 -4
- package/src/behaviours/spec.ts +8 -2
- package/src/bindings.ts +11 -2
- package/src/checkpoint.ts +319 -17
- package/src/components/properties.ts +101 -2
- package/src/components/variants.ts +51 -30
- package/src/connectors/hit.ts +1 -12
- package/src/connectors/pieces.ts +2 -5
- package/src/constants.ts +17 -0
- package/src/constraints.ts +60 -0
- package/src/coordinate.ts +220 -0
- package/src/copy.ts +18 -19
- package/src/css/blend.ts +27 -0
- package/src/css/index.ts +18 -1
- package/src/css/text.ts +85 -17
- package/src/css/transform.ts +266 -0
- package/src/css/values.ts +8 -0
- package/src/cubic.ts +14 -0
- package/src/export-format.ts +29 -0
- package/src/fields/text.ts +3 -1
- package/src/figjam/palette.ts +29 -1
- package/src/generated/shape-with-text.ts +28 -2
- package/src/geometry.ts +97 -206
- package/src/graph.ts +155 -45
- package/src/group-bounds.ts +84 -17
- package/src/guides.ts +5 -0
- package/src/hit-test.ts +93 -64
- package/src/images.ts +71 -3
- package/src/instances/fields.ts +8 -0
- package/src/instances/index.ts +62 -31
- package/src/instances/kept-overrides.ts +280 -0
- package/src/instances/main-component.ts +12 -0
- package/src/instances/overrides.ts +27 -1
- package/src/instances/placement.ts +63 -10
- package/src/instances/swap.ts +456 -0
- package/src/instances/sync.ts +176 -50
- package/src/node-defaults.ts +3 -1
- package/src/order-keys.ts +6 -0
- package/src/outline/flatten.ts +190 -0
- package/src/outline/heads.ts +52 -0
- package/src/outline/hit.ts +369 -0
- package/src/outline/index.ts +4 -0
- package/src/outline/point.ts +59 -0
- package/src/outline/shapes.ts +207 -0
- package/src/plugin-data/fields.ts +21 -2
- package/src/resize.ts +267 -119
- package/src/scaling/index.ts +9 -1
- package/src/scaling/node.ts +9 -1
- package/src/scaling/snapshot.ts +51 -0
- package/src/scaling/tree.ts +63 -19
- package/src/shaders/model.ts +2 -3
- package/src/shared-styles.ts +90 -1
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +6 -1
- package/src/slots/frames.ts +9 -7
- package/src/text/direction.ts +5 -0
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +2 -2
- package/src/text/picture.ts +0 -4
- package/src/transfer/apply.ts +1 -13
- package/src/transfer/copied.ts +83 -15
- package/src/transfer/dependencies.ts +126 -0
- package/src/transfer/history.ts +0 -6
- package/src/transfer/index.ts +20 -2
- package/src/transfer/nodes.ts +17 -31
- package/src/transfer/plan.ts +3 -11
- package/src/transfer/remove.ts +5 -2
- package/src/transfer/resources.ts +54 -0
- package/src/transfer/variables.ts +34 -0
- package/src/types.ts +83 -1
- package/src/undo.ts +48 -10
- package/src/variables/bindings.ts +152 -88
- package/src/variables/fields.ts +46 -1
- package/src/variables/formula/index.ts +3 -1
- package/src/variables/index.ts +90 -39
- package/src/variables/paints.ts +296 -0
- package/src/variables/resolution.ts +39 -28
- package/src/variables/subtree.ts +15 -0
- package/src/vector-network.ts +4 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-styles.js","names":[],"sources":["../src/shared-styles.ts"],"sourcesContent":["import { compact, isEqual, omit } from 'es-toolkit'\n\nimport type { SceneGraph } from './graph'\nimport { styleRunReferences } from './text/references'\nimport type {\n CharacterStyleOverride,\n SceneNode,\n SharedStyle,\n SharedStyleKind,\n SharedStyleType,\n Stroke\n} from './types'\n\nconst STYLE_REF_KEYS = {\n fill: 'fillStyleId',\n stroke: 'strokeStyleId',\n text: 'textStyleId',\n effect: 'effectStyleId',\n grid: 'gridStyleId'\n} as const satisfies Record<SharedStyleKind, keyof SceneNode>\n\n/** The fields that link a layer to its shared styles. */\nexport const STYLE_LINK_FIELDS = Object.values(STYLE_REF_KEYS)\n\n/** The shared styles a layer uses: its own, its text ranges', and its vector regions'. */\nexport function referencedStyleIds(node: SceneNode): string[] {\n return compact([\n ...STYLE_LINK_FIELDS.map((field) => node[field]),\n ...styleRunReferences(node.styleRuns).styles,\n ...(node.vectorNetwork?.regions ?? []).map((region) => region.fillStyleId)\n ])\n}\n\nconst STYLE_TYPES = {\n fill: 'FILL',\n stroke: 'FILL',\n text: 'TEXT',\n effect: 'EFFECT',\n grid: 'GRID'\n} as const satisfies Record<SharedStyleKind, SharedStyleType>\n\n/** The fields a text style gives what uses it; changing one leaves the style. */\nexport const SHARED_TEXT_STYLE_FIELDS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontStyle',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textCase',\n 'fontFeatures'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The paragraph fields a text style also gives the whole text; a range takes only the character\n * ones. Changing one leaves the style, and a cleared style resets them (live-verified).\n */\nconst TEXT_STYLE_PARAGRAPH_FIELDS = [\n 'paragraphSpacing',\n 'paragraphIndent',\n 'listSpacing'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/** The fields each kind of shared style gives what uses it; changing one leaves the style. */\nexport const SHARED_STYLE_FIELDS = {\n fill: ['fills'],\n stroke: ['strokes'],\n text: [...SHARED_TEXT_STYLE_FIELDS, ...TEXT_STYLE_PARAGRAPH_FIELDS],\n effect: ['effects'],\n grid: ['layoutGrids']\n} as const satisfies Record<SharedStyleKind, readonly (keyof SceneNode)[]>\n\n/** The fields that pick a text's face, which its style name names. */\nexport const FACE_KEYS = [\n 'fontFamily',\n 'fontWeight',\n 'italic'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The face name of characters with `style` over the text: their own, none where they set another\n * face without one (as ranges from HTML or `.pen` do), else the text's.\n */\nexport function rangeFontStyle(\n node: Pick<SceneNode, 'fontStyle'>,\n style: CharacterStyleOverride\n): string | null {\n if (style.fontStyle !== undefined) return style.fontStyle\n return FACE_KEYS.some((key) => style[key] !== undefined) ? null : node.fontStyle\n}\n\nexport function sharedStyleRefKey(kind: SharedStyleKind): (typeof STYLE_REF_KEYS)[SharedStyleKind] {\n return STYLE_REF_KEYS[kind]\n}\n\nexport function sharedStyleTypeForKind(kind: SharedStyleKind): SharedStyleType {\n return STYLE_TYPES[kind]\n}\n\nexport function getSharedStyles(graph: SceneGraph, kind: SharedStyleKind): SharedStyle[] {\n const type = sharedStyleTypeForKind(kind)\n const styles: SharedStyle[] = []\n for (const node of graph.getAllNodes()) {\n if (node.sharedStyleType !== type || !node.source.id) continue\n styles.push({ id: node.source.id, nodeId: node.id, name: node.name, type })\n }\n return styles.sort((left, right) => left.name.localeCompare(right.name))\n}\n\n/** What a stroke draws along beside its paint: the layer's, not its stroke style's. */\nconst STROKE_LINE_KEYS = ['weight', 'align', 'cap', 'join', 'dashPattern'] as const\n\n/**\n * Whether new strokes only change how their lines run, keeping every paint. A stroke style gives\n * paints only, so such a write keeps it; any other strokes write leaves it, as setting even the\n * same paints does in Figma (live-verified).\n */\nfunction restylesStrokeLines(current: readonly Stroke[], next: readonly Stroke[]): boolean {\n const paints = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => omit(stroke, STROKE_LINE_KEYS))\n const lines = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => STROKE_LINE_KEYS.map((key) => stroke[key]))\n return isEqual(paints(current), paints(next)) && !isEqual(lines(current), lines(next))\n}\n\nexport function styleDetachmentChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const next = { ...changes }\n for (const [kind, fields] of Object.entries(SHARED_STYLE_FIELDS)) {\n const reference = STYLE_REF_KEYS[kind as SharedStyleKind]\n if (reference in changes || !node[reference]) continue\n if (!fields.some((field) => field in changes)) continue\n if (kind === 'stroke' && changes.strokes && restylesStrokeLines(node.strokes, changes.strokes))\n continue\n next[reference] = null\n }\n // A face named for another family, weight, or slant names none; the new one takes its own name.\n const changesFace = FACE_KEYS.some((key) => key in changes && changes[key] !== node[key])\n if (changesFace && !('fontStyle' in changes) && node.fontStyle) {\n next.fontStyle = null\n }\n return next\n}\n"],"mappings":";;;AAaA,MAAM,iBAAiB;CACrB,MAAM;CACN,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;AACR;;AAGA,MAAa,oBAAoB,OAAO,OAAO,cAAc;;AAG7D,SAAgB,mBAAmB,MAA2B;CAC5D,OAAO,QAAQ;EACb,GAAG,kBAAkB,KAAK,UAAU,KAAK,MAAM;EAC/C,GAAG,mBAAmB,KAAK,SAAS,CAAC,CAAC;EACtC,IAAI,KAAK,eAAe,WAAW,CAAC,EAAA,CAAG,KAAK,WAAW,OAAO,WAAW;CAC3E,CAAC;AACH;AAEA,MAAM,cAAc;CAClB,MAAM;CACN,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;AACR;;AAGA,MAAa,2BAA2B;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;AAMA,MAAM,8BAA8B;CAClC;CACA;CACA;AACF;;AAGA,MAAa,sBAAsB;CACjC,MAAM,CAAC,OAAO;CACd,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,GAAG,0BAA0B,GAAG,2BAA2B;CACl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AAG;EAChE,MAAM,YAAY,eAAe;EACjC,IAAI,aAAa,WAAW,CAAC,KAAK,YAAY;EAC9C,IAAI,CAAC,OAAO,MAAM,UAAU,SAAS,OAAO,GAAG;EAC/C,IAAI,SAAS,YAAY,QAAQ,WAAW,oBAAoB,KAAK,SAAS,QAAQ,OAAO,GAC3F;EACF,KAAK,aAAa;CACpB;CAGA,IADoB,UAAU,MAAM,QAAQ,OAAO,WAAW,QAAQ,SAAS,KAAK,IACtE,KAAK,EAAE,eAAe,YAAY,KAAK,WACnD,KAAK,YAAY;CAEnB,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"shared-styles.js","names":[],"sources":["../src/shared-styles.ts"],"sourcesContent":["import { compact, isEqual, omit, pick } from 'es-toolkit'\n\nimport { BLACK } from './constants'\nimport { copyEffects, copyFills, copyLayoutGrids } from './copy'\nimport type { SceneGraph } from './graph'\nimport { newStrokeGeometry } from './node-defaults'\nimport { randomHex } from './random'\nimport { styleRunReferences } from './text/references'\nimport type {\n CharacterStyleOverride,\n SceneNode,\n SharedStyle,\n SharedStyleKind,\n SharedStyleType,\n Stroke\n} from './types'\n\nconst STYLE_REF_KEYS = {\n fill: 'fillStyleId',\n stroke: 'strokeStyleId',\n text: 'textStyleId',\n effect: 'effectStyleId',\n grid: 'gridStyleId'\n} as const satisfies Record<SharedStyleKind, keyof SceneNode>\n\n/** The fields that link a layer to its shared styles. */\nexport const STYLE_LINK_FIELDS = Object.values(STYLE_REF_KEYS)\n\n/** The shared styles a layer uses: its own, its text ranges', and its vector regions'. */\nexport function referencedStyleIds(node: SceneNode): string[] {\n return compact([\n ...STYLE_LINK_FIELDS.map((field) => node[field]),\n ...styleRunReferences(node.styleRuns).styles,\n ...(node.vectorNetwork?.regions ?? []).map((region) => region.fillStyleId)\n ])\n}\n\nconst STYLE_TYPES = {\n fill: 'FILL',\n stroke: 'FILL',\n text: 'TEXT',\n effect: 'EFFECT',\n grid: 'GRID'\n} as const satisfies Record<SharedStyleKind, SharedStyleType>\n\n/** The fields a text style gives what uses it; changing one leaves the style. */\nexport const SHARED_TEXT_STYLE_FIELDS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontStyle',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textCase',\n 'fontFeatures'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The paragraph fields a text style also gives the whole text; a range takes only the character\n * ones. Changing one leaves the style, and a cleared style resets them (live-verified).\n */\nconst TEXT_STYLE_PARAGRAPH_FIELDS = [\n 'paragraphSpacing',\n 'paragraphIndent',\n 'listSpacing'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/** The fields each kind of shared style gives what uses it; changing one leaves the style. */\nexport const SHARED_STYLE_FIELDS = {\n fill: ['fills'],\n stroke: ['strokes'],\n text: [...SHARED_TEXT_STYLE_FIELDS, ...TEXT_STYLE_PARAGRAPH_FIELDS],\n effect: ['effects'],\n grid: ['layoutGrids']\n} as const satisfies Record<SharedStyleKind, readonly (keyof SceneNode)[]>\n\n/** The fields that pick a text's face, which its style name names. */\nexport const FACE_KEYS = [\n 'fontFamily',\n 'fontWeight',\n 'italic'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The face name of characters with `style` over the text: their own, none where they set another\n * face without one (as ranges from HTML or `.pen` do), else the text's.\n */\nexport function rangeFontStyle(\n node: Pick<SceneNode, 'fontStyle'>,\n style: CharacterStyleOverride\n): string | null {\n if (style.fontStyle !== undefined) return style.fontStyle\n return FACE_KEYS.some((key) => style[key] !== undefined) ? null : node.fontStyle\n}\n\nexport function sharedStyleRefKey(kind: SharedStyleKind): (typeof STYLE_REF_KEYS)[SharedStyleKind] {\n return STYLE_REF_KEYS[kind]\n}\n\nexport function sharedStyleTypeForKind(kind: SharedStyleKind): SharedStyleType {\n return STYLE_TYPES[kind]\n}\n\n/** The document's shared style layers, by the source ID layers link them by. */\nexport function sharedStyleLayers(graph: SceneGraph): Map<string, SceneNode> {\n const styles = new Map<string, SceneNode>()\n for (const node of graph.getAllNodes())\n if (node.sharedStyleType !== null && node.source.id) styles.set(node.source.id, node)\n return styles\n}\n\nexport function getSharedStyles(graph: SceneGraph, kind: SharedStyleKind): SharedStyle[] {\n const type = sharedStyleTypeForKind(kind)\n const styles: SharedStyle[] = []\n for (const node of graph.getAllNodes()) {\n if (node.sharedStyleType !== type || !node.source.id) continue\n styles.push({ id: node.source.id, nodeId: node.id, name: node.name, type })\n }\n return styles.sort((left, right) => left.name.localeCompare(right.name))\n}\n\n/** What a stroke draws along beside its paint: the layer's, not its stroke style's. */\nconst STROKE_LINE_KEYS = ['weight', 'align', 'cap', 'join', 'dashPattern'] as const\n\n/**\n * Whether new strokes only change how their lines run, keeping every paint. A stroke style gives\n * paints only, so such a write keeps it; any other strokes write leaves it, as setting even the\n * same paints does in Figma (live-verified).\n */\nfunction restylesStrokeLines(current: readonly Stroke[], next: readonly Stroke[]): boolean {\n const paints = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => omit(stroke, STROKE_LINE_KEYS))\n const lines = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => STROKE_LINE_KEYS.map((key) => stroke[key]))\n return isEqual(paints(current), paints(next)) && !isEqual(lines(current), lines(next))\n}\n\nexport function styleDetachmentChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const next = { ...changes }\n for (const [kind, fields] of Object.entries(SHARED_STYLE_FIELDS)) {\n const reference = STYLE_REF_KEYS[kind as SharedStyleKind]\n if (reference in changes || !node[reference]) continue\n if (!fields.some((field) => field in changes)) continue\n if (kind === 'stroke' && changes.strokes && restylesStrokeLines(node.strokes, changes.strokes))\n continue\n next[reference] = null\n }\n // A face named for another family, weight, or slant names none; the new one takes its own name.\n const changesFace = FACE_KEYS.some((key) => key in changes && changes[key] !== node[key])\n if (changesFace && !('fontStyle' in changes) && node.fontStyle) {\n next.fontStyle = null\n }\n return next\n}\n\n/** The node of the shared style with `id`, when the document holds one of `type`. */\nexport function findSharedStyle(\n graph: SceneGraph,\n id: string,\n type: SharedStyleType\n): SceneNode | undefined {\n if (!id) return undefined\n for (const node of graph.getAllNodes()) {\n if (node.sharedStyleType === type && node.source.id === id) return node\n }\n return undefined\n}\n\n/** A new local style's ID, in the shape Figma gives one: `S:` and a 40-digit hex key. */\nexport function newSharedStyleId(): string {\n return `S:${randomHex(20)},`\n}\n\nconst INTERNAL_CANVAS_NAME = 'Internal Only Canvas'\n\n/** The page that holds the document's styles out of view, as a `.fig` file keeps them; made once. */\nexport function internalCanvas(graph: SceneGraph): SceneNode {\n const existing = graph.getPages(true).find((page) => page.internalOnly)\n if (existing) return existing\n return graph.createNode('CANVAS', graph.rootId, {\n name: INTERNAL_CANVAS_NAME,\n width: 0,\n height: 0,\n internalOnly: true\n })\n}\n\n/**\n * A paint style's paints as a layer's strokes: every paint, each keeping the weight, alignment,\n * and line style of the stroke it replaces, or of the layer's first; no paints clear the strokes\n * (Figma desktop 126).\n */\nfunction strokesFromStyle(target: SceneNode, style: SceneNode): SceneNode['strokes'] {\n // Without strokes, the layer keeps the weight and alignment a new stroke takes.\n const fallback: Stroke = target.strokes[0] ?? {\n type: 'SOLID',\n color: BLACK,\n opacity: 1,\n visible: true,\n ...newStrokeGeometry(target)\n }\n return copyFills(style.fills).map((paint, index) => ({\n ...paint,\n ...pick(target.strokes[index] ?? fallback, STROKE_LINE_KEYS)\n }))\n}\n\n/**\n * What a layer takes from a shared style it starts using: the style's fields and the reference\n * that keeps it attached. Without the style's node, the reference alone.\n */\nexport function sharedStylePatch(\n kind: SharedStyleKind,\n target: SceneNode,\n styleId: string,\n style: SceneNode | null\n): Partial<SceneNode> {\n const patch: Partial<SceneNode> = { [STYLE_REF_KEYS[kind]]: styleId }\n if (!style) return patch\n if (kind === 'fill') patch.fills = copyFills(style.fills)\n else if (kind === 'stroke') patch.strokes = strokesFromStyle(target, style)\n else if (kind === 'effect') patch.effects = copyEffects(style.effects)\n else if (kind === 'grid') patch.layoutGrids = copyLayoutGrids(style.layoutGrids)\n else Object.assign(patch, structuredClone(pick(style, SHARED_STYLE_FIELDS.text)))\n return patch\n}\n\n/** A layer leaving a shared style: it keeps the style's values, without the reference. */\nexport function sharedStyleDetachPatch(kind: SharedStyleKind): Partial<SceneNode> {\n return { [STYLE_REF_KEYS[kind]]: null }\n}\n"],"mappings":";;;;;;;AAiBA,MAAM,iBAAiB;CACrB,MAAM;CACN,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;AACR;;AAGA,MAAa,oBAAoB,OAAO,OAAO,cAAc;;AAG7D,SAAgB,mBAAmB,MAA2B;CAC5D,OAAO,QAAQ;EACb,GAAG,kBAAkB,KAAK,UAAU,KAAK,MAAM;EAC/C,GAAG,mBAAmB,KAAK,SAAS,CAAC,CAAC;EACtC,IAAI,KAAK,eAAe,WAAW,CAAC,EAAA,CAAG,KAAK,WAAW,OAAO,WAAW;CAC3E,CAAC;AACH;AAEA,MAAM,cAAc;CAClB,MAAM;CACN,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;AACR;;AAGA,MAAa,2BAA2B;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;AAMA,MAAM,8BAA8B;CAClC;CACA;CACA;AACF;;AAGA,MAAa,sBAAsB;CACjC,MAAM,CAAC,OAAO;CACd,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,GAAG,0BAA0B,GAAG,2BAA2B;CAClE,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,aAAa;AACtB;;AAGA,MAAa,YAAY;CACvB;CACA;CACA;AACF;;;;;AAMA,SAAgB,eACd,MACA,OACe;CACf,IAAI,MAAM,cAAc,KAAA,GAAW,OAAO,MAAM;CAChD,OAAO,UAAU,MAAM,QAAQ,MAAM,SAAS,KAAA,CAAS,IAAI,OAAO,KAAK;AACzE;AAEA,SAAgB,kBAAkB,MAAiE;CACjG,OAAO,eAAe;AACxB;AAEA,SAAgB,uBAAuB,MAAwC;CAC7E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,MAAM,UAAU,iBAAiB,QAAQ,KAAK;MACrE,IAAI,SAAS,UAAU,MAAM,UAAU,YAAY,MAAM,OAAO;MAChE,IAAI,SAAS,QAAQ,MAAM,cAAc,gBAAgB,MAAM,WAAW;MAC1E,OAAO,OAAO,OAAO,gBAAgB,KAAK,OAAO,oBAAoB,IAAI,CAAC,CAAC;CAChF,OAAO;AACT;;AAGA,SAAgB,uBAAuB,MAA2C;CAChF,OAAO,GAAG,eAAe,QAAQ,KAAK;AACxC"}
|
|
@@ -4,8 +4,9 @@ import { ComponentPropertyDefinition, SceneNode, SlotSettings } from "../types.j
|
|
|
4
4
|
/** The settings a new slot starts with: no limits, any layer allowed. */
|
|
5
5
|
declare const DEFAULT_SLOT_SETTINGS: SlotSettings;
|
|
6
6
|
/**
|
|
7
|
-
* The main component
|
|
8
|
-
* instance are not authored there, so a
|
|
7
|
+
* The main component or set that defines the slots inside a layer: the component the layer
|
|
8
|
+
* belongs to, or that component's set. Layers of an instance are not authored there, so a
|
|
9
|
+
* layer under an instance has none.
|
|
9
10
|
*/
|
|
10
11
|
declare function slotOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined;
|
|
11
12
|
/** Whether a frame inside a main component can become a slot. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authoring.d.ts","names":[],"sources":["../../src/slots/authoring.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"authoring.d.ts","names":[],"sources":["../../src/slots/authoring.ts"],"mappings":";;;;cAMa,uBAAuB;;;;;;iBAWpB,UAAU,OAAO,YAAY,MAAM,YAAY;;iBAW/C,cAAc,OAAO,YAAY,MAAM;;;;;;iBAiBvC,mBACd,OAAO,YACP,iBACA,aACC;;KAyBS,oBAAoB,QAC9B,KAAK;EACD,eAAe,QAAQ;;;iBAGb,mBACd,OAAO,YACP,iBACA,oBACA,OAAO"}
|
package/dist/slots/authoring.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { slotPropertyId } from "./frames.js";
|
|
2
|
+
import { propertyOwner } from "../components/properties.js";
|
|
2
3
|
//#region src/slots/authoring.ts
|
|
3
4
|
/** The settings a new slot starts with: no limits, any layer allowed. */
|
|
4
5
|
const DEFAULT_SLOT_SETTINGS = {
|
|
@@ -7,13 +8,14 @@ const DEFAULT_SLOT_SETTINGS = {
|
|
|
7
8
|
stretchChildOnInsert: false
|
|
8
9
|
};
|
|
9
10
|
/**
|
|
10
|
-
* The main component
|
|
11
|
-
* instance are not authored there, so a
|
|
11
|
+
* The main component or set that defines the slots inside a layer: the component the layer
|
|
12
|
+
* belongs to, or that component's set. Layers of an instance are not authored there, so a
|
|
13
|
+
* layer under an instance has none.
|
|
12
14
|
*/
|
|
13
15
|
function slotOwner(graph, node) {
|
|
14
16
|
let current = node.parentId ? graph.getNode(node.parentId) : void 0;
|
|
15
17
|
while (current && current.type !== "CANVAS") {
|
|
16
|
-
if (current.type === "COMPONENT") return current;
|
|
18
|
+
if (current.type === "COMPONENT") return propertyOwner(graph, current);
|
|
17
19
|
if (current.type === "INSTANCE") return void 0;
|
|
18
20
|
current = current.parentId ? graph.getNode(current.parentId) : void 0;
|
|
19
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authoring.js","names":[],"sources":["../../src/slots/authoring.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { ComponentPropertyDefinition, SceneNode, SlotSettings } from '../types'\nimport { slotPropertyId } from './frames'\n\n/** The settings a new slot starts with: no limits, any layer allowed. */\nexport const DEFAULT_SLOT_SETTINGS: SlotSettings = {\n allowPreferredValuesOnly: false,\n displayEmptyByDefault: false,\n stretchChildOnInsert: false\n}\n\n/**\n * The main component a layer belongs to,
|
|
1
|
+
{"version":3,"file":"authoring.js","names":[],"sources":["../../src/slots/authoring.ts"],"sourcesContent":["import { propertyOwner } from '../components/properties'\nimport type { SceneGraph } from '../graph'\nimport type { ComponentPropertyDefinition, SceneNode, SlotSettings } from '../types'\nimport { slotPropertyId } from './frames'\n\n/** The settings a new slot starts with: no limits, any layer allowed. */\nexport const DEFAULT_SLOT_SETTINGS: SlotSettings = {\n allowPreferredValuesOnly: false,\n displayEmptyByDefault: false,\n stretchChildOnInsert: false\n}\n\n/**\n * The main component or set that defines the slots inside a layer: the component the layer\n * belongs to, or that component's set. Layers of an instance are not authored there, so a\n * layer under an instance has none.\n */\nexport function slotOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n let current = node.parentId ? graph.getNode(node.parentId) : undefined\n while (current && current.type !== 'CANVAS') {\n if (current.type === 'COMPONENT') return propertyOwner(graph, current)\n if (current.type === 'INSTANCE') return undefined\n current = current.parentId ? graph.getNode(current.parentId) : undefined\n }\n return undefined\n}\n\n/** Whether a frame inside a main component can become a slot. */\nexport function canCreateSlot(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && !slotPropertyId(node) && !!slotOwner(graph, node)\n}\n\nfunction uniqueSlotName(owner: SceneNode, base: string): string {\n const taken = new Set(owner.componentPropertyDefinitions.map((definition) => definition.name))\n if (!taken.has(base)) return base\n let index = 2\n while (taken.has(`${base} ${index}`)) index++\n return `${base} ${index}`\n}\n\n/**\n * Make a frame of a main component a slot: define a SLOT property, named after the frame, on\n * the component and bind the frame's children to it. Instances pick up the slot on their next\n * sync.\n */\nexport function createSlotProperty(\n graph: SceneGraph,\n frameId: string,\n id: string\n): ComponentPropertyDefinition | null {\n const frame = graph.getNode(frameId)\n const owner = frame && canCreateSlot(graph, frame) ? slotOwner(graph, frame) : undefined\n if (!frame || !owner) return null\n const definition: ComponentPropertyDefinition = {\n id,\n name: uniqueSlotName(owner, frame.name.trim() || 'Slot'),\n type: 'SLOT',\n defaultValue: '',\n preferredValues: [],\n slotSettings: { ...DEFAULT_SLOT_SETTINGS }\n }\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: [...owner.componentPropertyDefinitions, definition]\n })\n graph.updateNode(frame.id, {\n componentPropertyReferences: [\n ...frame.componentPropertyReferences,\n { propertyId: id, field: 'SLOT_CONTENT' }\n ]\n })\n return definition\n}\n\n/** What a slot's settings panel can change. */\nexport type SlotPropertyPatch = Partial<\n Pick<ComponentPropertyDefinition, 'name' | 'description' | 'preferredValues'>\n> & { slotSettings?: Partial<SlotSettings> }\n\n/** Change a slot property's name, description, preferred components, or limits. */\nexport function updateSlotProperty(\n graph: SceneGraph,\n ownerId: string,\n propertyId: string,\n patch: SlotPropertyPatch\n): boolean {\n const owner = graph.getNode(ownerId)\n const current = owner?.componentPropertyDefinitions.find(\n (definition) => definition.id === propertyId && definition.type === 'SLOT'\n )\n if (!owner || !current) return false\n const { slotSettings, ...fields } = patch\n const next: ComponentPropertyDefinition = {\n ...current,\n ...fields,\n slotSettings: { ...DEFAULT_SLOT_SETTINGS, ...current.slotSettings, ...slotSettings }\n }\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: owner.componentPropertyDefinitions.map((definition) =>\n definition.id === propertyId ? next : definition\n )\n })\n return true\n}\n"],"mappings":";;;;AAMA,MAAa,wBAAsC;CACjD,0BAA0B;CAC1B,uBAAuB;CACvB,sBAAsB;AACxB;;;;;;AAOA,SAAgB,UAAU,OAAmB,MAAwC;CACnF,IAAI,UAAU,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;CAC7D,OAAO,WAAW,QAAQ,SAAS,UAAU;EAC3C,IAAI,QAAQ,SAAS,aAAa,OAAO,cAAc,OAAO,OAAO;EACrE,IAAI,QAAQ,SAAS,YAAY,OAAO,KAAA;EACxC,UAAU,QAAQ,WAAW,MAAM,QAAQ,QAAQ,QAAQ,IAAI,KAAA;CACjE;AAEF;;AAGA,SAAgB,cAAc,OAAmB,MAA0B;CACzE,OAAO,KAAK,SAAS,WAAW,CAAC,eAAe,IAAI,KAAK,CAAC,CAAC,UAAU,OAAO,IAAI;AAClF;AAEA,SAAS,eAAe,OAAkB,MAAsB;CAC9D,MAAM,QAAQ,IAAI,IAAI,MAAM,6BAA6B,KAAK,eAAe,W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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.d.ts","names":[],"sources":["../../src/slots/content.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"content.d.ts","names":[],"sources":["../../src/slots/content.ts"],"mappings":";;;;;;;;;;KAeY;EACN;;EACA;EAAc,OAAO;EAAW,UAAU;EAAW;;EACrD;EAAgB,OAAO;;iBAYb,UAAU,OAAO,YAAY,mBAAmB;;;;;;iBAmChD,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBA0Cd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAcd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa"}
|
package/dist/slots/content.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getInstanceOverride, setInstanceOverride } from "../instances/overrides.js";
|
|
2
2
|
import { isGeneratedFrame } from "../generated/index.js";
|
|
3
3
|
import { ownsSlotContent, slotPropertyId } from "./frames.js";
|
|
4
|
+
import { applyBoundPaintColorsIn } from "../variables/paints.js";
|
|
4
5
|
import { cloneChildrenWithMapping } from "../instances/sync.js";
|
|
5
6
|
//#region src/slots/content.ts
|
|
6
7
|
function parentOf(graph, node) {
|
|
@@ -54,6 +55,7 @@ function descendants(graph, node, enterInstances) {
|
|
|
54
55
|
function claimSlotContent(graph, scope) {
|
|
55
56
|
const { frame, instance, propertyId } = scope;
|
|
56
57
|
if (ownsSlotContent(graph, frame, propertyId)) return;
|
|
58
|
+
graph.willChangeNode(instance);
|
|
57
59
|
const overrides = instance.instanceOverrides;
|
|
58
60
|
for (const node of descendants(graph, frame, false)) {
|
|
59
61
|
overrides.descendants.delete(node.id);
|
|
@@ -61,6 +63,7 @@ function claimSlotContent(graph, scope) {
|
|
|
61
63
|
graph.updateNode(node.id, { componentId: null });
|
|
62
64
|
continue;
|
|
63
65
|
}
|
|
66
|
+
graph.willChangeNode(node);
|
|
64
67
|
for (const inner of descendants(graph, node, true)) {
|
|
65
68
|
const fields = overrides.descendants.get(inner.id);
|
|
66
69
|
if (!fields) continue;
|
|
@@ -90,7 +93,9 @@ function resetSlotContent(graph, scope) {
|
|
|
90
93
|
Reflect.deleteProperty(assignments, propertyId);
|
|
91
94
|
graph.updateNode(instance.id, { componentPropertyAssignments: assignments });
|
|
92
95
|
const source = componentSource(instance, frame);
|
|
93
|
-
if (source
|
|
96
|
+
if (!source || !graph.nodes.has(source)) return;
|
|
97
|
+
cloneChildrenWithMapping(graph, source, frame.id);
|
|
98
|
+
for (const childId of frame.childIds) applyBoundPaintColorsIn(graph, childId);
|
|
94
99
|
}
|
|
95
100
|
/** Remove everything from the slot; the instance keeps owning it, now empty. */
|
|
96
101
|
function clearSlotContent(graph, scope) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","names":[],"sources":["../../src/slots/content.ts"],"sourcesContent":["import { isGeneratedFrame } from '../generated'\nimport type { SceneGraph } from '../graph'\nimport { getInstanceOverride, setInstanceOverride } from '../instances/overrides'\nimport { cloneChildrenWithMapping } from '../instances/sync'\nimport type { SceneNode } from '../types'\nimport { ownsSlotContent, slotPropertyId } from './frames'\n\n/**\n * Where layers may be added, moved, or removed under a parent:\n * - `free`: outside any instance, or inside a component definition;\n * - `slot`: inside a slot of an instance, whose content the instance owns or can claim;\n * - `locked`: anywhere else inside an instance, whose layers come from its component, or inside a\n * generated frame such as a sticky note, whose layers come from its template.\n */\nexport type SlotScope =\n | { kind: 'free' }\n | { kind: 'slot'; frame: SceneNode; instance: SceneNode; propertyId: string }\n | { kind: 'locked'; owner: SceneNode }\n\nfunction parentOf(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n return node.parentId ? graph.nodes.get(node.parentId) : undefined\n}\n\nfunction nearestInstance(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n let current = parentOf(graph, node)\n while (current && current.type !== 'INSTANCE') current = parentOf(graph, current)\n return current\n}\n\nexport function slotScope(graph: SceneGraph, parentId: string): SlotScope {\n let current = graph.nodes.get(parentId)\n while (current) {\n const propertyId = slotPropertyId(current)\n if (propertyId) {\n const instance = nearestInstance(graph, current)\n return instance ? { kind: 'slot', frame: current, instance, propertyId } : { kind: 'free' }\n }\n if (current.type === 'INSTANCE' || isGeneratedFrame(current))\n return { kind: 'locked', owner: current }\n current = parentOf(graph, current)\n }\n return { kind: 'free' }\n}\n\n/** Every layer below `node`; `enterInstances` also walks the layers of nested instances. */\nfunction descendants(graph: SceneGraph, node: SceneNode, enterInstances: boolean): SceneNode[] {\n const result: SceneNode[] = []\n const visit = (parent: SceneNode): void => {\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n result.push(child)\n if (enterInstances || child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(node)\n return result\n}\n\n/**\n * Make the instance own its slot's content, as Figma does on the first edit: the layers\n * stay where they are, but stop following the component. Overrides the instance held for\n * them become their own values, or move to the nested instance they belong to.\n */\nexport function claimSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n if (ownsSlotContent(graph, frame, propertyId)) return\n const overrides = instance.instanceOverrides\n for (const node of descendants(graph, frame, false)) {\n overrides.descendants.delete(node.id)\n if (node.type !== 'INSTANCE') {\n graph.updateNode(node.id, { componentId: null })\n continue\n }\n // A nested instance keeps the overrides its former owner applied inside it.\n for (const inner of descendants(graph, node, true)) {\n const fields = overrides.descendants.get(inner.id)\n if (!fields) continue\n for (const [field, value] of fields)\n if (field !== 'sourceComponentId')\n setInstanceOverride(node.instanceOverrides, node.id, inner.id, field, value)\n overrides.descendants.delete(inner.id)\n }\n graph.updateNode(node.id, { instanceOverrides: node.instanceOverrides })\n }\n graph.updateNode(instance.id, {\n instanceOverrides: overrides,\n componentPropertyAssignments: { ...instance.componentPropertyAssignments, [propertyId]: '' }\n })\n}\n\n/** The component layer an instance layer was cloned from. */\nfunction componentSource(instance: SceneNode, node: SceneNode): string | null {\n const mapped = getInstanceOverride(\n instance.instanceOverrides,\n instance.id,\n node.id,\n 'sourceComponentId'\n )\n return typeof mapped === 'string' ? mapped : node.componentId\n}\n\n/** Return the slot to its component's content: the instance stops owning it. */\nexport function resetSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n for (const childId of Array.from(frame.childIds)) graph.deleteNode(childId)\n const assignments = { ...instance.componentPropertyAssignments }\n Reflect.deleteProperty(assignments, propertyId)\n graph.updateNode(instance.id, { componentPropertyAssignments: assignments })\n const source = componentSource(instance, frame)\n if (source
|
|
1
|
+
{"version":3,"file":"content.js","names":[],"sources":["../../src/slots/content.ts"],"sourcesContent":["import { isGeneratedFrame } from '../generated'\nimport type { SceneGraph } from '../graph'\nimport { getInstanceOverride, setInstanceOverride } from '../instances/overrides'\nimport { cloneChildrenWithMapping } from '../instances/sync'\nimport type { SceneNode } from '../types'\nimport { applyBoundPaintColorsIn } from '../variables/paints'\nimport { ownsSlotContent, slotPropertyId } from './frames'\n\n/**\n * Where layers may be added, moved, or removed under a parent:\n * - `free`: outside any instance, or inside a component definition;\n * - `slot`: inside a slot of an instance, whose content the instance owns or can claim;\n * - `locked`: anywhere else inside an instance, whose layers come from its component, or inside a\n * generated frame such as a sticky note, whose layers come from its template.\n */\nexport type SlotScope =\n | { kind: 'free' }\n | { kind: 'slot'; frame: SceneNode; instance: SceneNode; propertyId: string }\n | { kind: 'locked'; owner: SceneNode }\n\nfunction parentOf(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n return node.parentId ? graph.nodes.get(node.parentId) : undefined\n}\n\nfunction nearestInstance(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n let current = parentOf(graph, node)\n while (current && current.type !== 'INSTANCE') current = parentOf(graph, current)\n return current\n}\n\nexport function slotScope(graph: SceneGraph, parentId: string): SlotScope {\n let current = graph.nodes.get(parentId)\n while (current) {\n const propertyId = slotPropertyId(current)\n if (propertyId) {\n const instance = nearestInstance(graph, current)\n return instance ? { kind: 'slot', frame: current, instance, propertyId } : { kind: 'free' }\n }\n if (current.type === 'INSTANCE' || isGeneratedFrame(current))\n return { kind: 'locked', owner: current }\n current = parentOf(graph, current)\n }\n return { kind: 'free' }\n}\n\n/** Every layer below `node`; `enterInstances` also walks the layers of nested instances. */\nfunction descendants(graph: SceneGraph, node: SceneNode, enterInstances: boolean): SceneNode[] {\n const result: SceneNode[] = []\n const visit = (parent: SceneNode): void => {\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n result.push(child)\n if (enterInstances || child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(node)\n return result\n}\n\n/**\n * Make the instance own its slot's content, as Figma does on the first edit: the layers\n * stay where they are, but stop following the component. Overrides the instance held for\n * them become their own values, or move to the nested instance they belong to.\n */\nexport function claimSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n if (ownsSlotContent(graph, frame, propertyId)) return\n graph.willChangeNode(instance)\n const overrides = instance.instanceOverrides\n for (const node of descendants(graph, frame, false)) {\n overrides.descendants.delete(node.id)\n if (node.type !== 'INSTANCE') {\n graph.updateNode(node.id, { componentId: null })\n continue\n }\n // A nested instance keeps the overrides its former owner applied inside it.\n graph.willChangeNode(node)\n for (const inner of descendants(graph, node, true)) {\n const fields = overrides.descendants.get(inner.id)\n if (!fields) continue\n for (const [field, value] of fields)\n if (field !== 'sourceComponentId')\n setInstanceOverride(node.instanceOverrides, node.id, inner.id, field, value)\n overrides.descendants.delete(inner.id)\n }\n graph.updateNode(node.id, { instanceOverrides: node.instanceOverrides })\n }\n graph.updateNode(instance.id, {\n instanceOverrides: overrides,\n componentPropertyAssignments: { ...instance.componentPropertyAssignments, [propertyId]: '' }\n })\n}\n\n/** The component layer an instance layer was cloned from. */\nfunction componentSource(instance: SceneNode, node: SceneNode): string | null {\n const mapped = getInstanceOverride(\n instance.instanceOverrides,\n instance.id,\n node.id,\n 'sourceComponentId'\n )\n return typeof mapped === 'string' ? mapped : node.componentId\n}\n\n/** Return the slot to its component's content: the instance stops owning it. */\nexport function resetSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n for (const childId of Array.from(frame.childIds)) graph.deleteNode(childId)\n const assignments = { ...instance.componentPropertyAssignments }\n Reflect.deleteProperty(assignments, propertyId)\n graph.updateNode(instance.id, { componentPropertyAssignments: assignments })\n const source = componentSource(instance, frame)\n if (!source || !graph.nodes.has(source)) return\n cloneChildrenWithMapping(graph, source, frame.id)\n for (const childId of frame.childIds) applyBoundPaintColorsIn(graph, childId)\n}\n\n/** Remove everything from the slot; the instance keeps owning it, now empty. */\nexport function clearSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n claimSlotContent(graph, scope)\n for (const childId of Array.from(scope.frame.childIds)) graph.deleteNode(childId)\n}\n"],"mappings":";;;;;;AAoBA,SAAS,SAAS,OAAmB,MAAwC;CAC3E,OAAO,KAAK,WAAW,MAAM,MAAM,IAAI,KAAK,QAAQ,IAAI,KAAA;AAC1D;AAEA,SAAS,gBAAgB,OAAmB,MAAwC;CAClF,IAAI,UAAU,SAAS,OAAO,IAAI;CAClC,OAAO,WAAW,QAAQ,SAAS,YAAY,UAAU,SAAS,OAAO,OAAO;CAChF,OAAO;AACT;AAEA,SAAgB,UAAU,OAAmB,UAA6B;CACxE,IAAI,UAAU,MAAM,MAAM,IAAI,QAAQ;CACtC,OAAO,SAAS;EACd,MAAM,aAAa,eAAe,OAAO;EACzC,IAAI,YAAY;GACd,MAAM,WAAW,gBAAgB,OAAO,OAAO;GAC/C,OAAO,WAAW;IAAE,MAAM;IAAQ,OAAO;IAAS;IAAU;GAAW,IAAI,EAAE,MAAM,OAAO;EAC5F;EACA,IAAI,QAAQ,SAAS,cAAc,iBAAiB,OAAO,GACzD,OAAO;GAAE,MAAM;GAAU,OAAO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AG;CAC7F,CAAC;AACH;;AAGA,SAAS,gBAAgB,UAAqB,MAAgC;CAC5E,MAAM,SAAS,oBACb,SAAS,mBACT,SAAS,IACT,KAAK,IACL,mBACF;CACA,OAAO,OAAO,WAAW,WAAW,SAAS,KAAK;AACpD;;AAGA,SAAgB,iBACd,OACA,OACM;CACN,MAAM,EAAE,OAAO,UAAU,eAAe;CACxC,KAAK,MAAM,WAAW,MAAM,KAAK,MAAM,QAAQ,GAAG,MAAM,WAAW,OAAO;CAC1E,MAAM,cAAc,EAAE,GAAG,SAAS,6BAA6B;CAC/D,QAAQ,eAAe,aAAa,UAAU;CAC9C,MAAM,WAAW,SAAS,IAAI,EAAE,8BAA8B,YAAY,CAAC;CAC3E,MAAM,SAAS,gBAAgB,UAAU,KAAK;CAC9C,IAAI,CAAC,UAAU,CAAC,MAAM,MAAM,IAAI,MAAM,GAAG;CACzC,yBAAyB,OAAO,QAAQ,MAAM,EAAE;CAChD,KAAK,MAAM,WAAW,MAAM,UAAU,wBAAwB,OAAO,OAAO;AAC9E;;AAGA,SAAgB,iBACd,OACA,OACM;CACN,iBAAiB,OAAO,KAAK;CAC7B,KAAK,MAAM,WAAW,MAAM,KAAK,MAAM,MAAM,QAAQ,GAAG,MAAM,WAAW,OAAO;AAClF"}
|
package/dist/slots/frames.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ interface ParkedSlot {
|
|
|
18
18
|
name: string;
|
|
19
19
|
/** Content layer ids, in layer order. */
|
|
20
20
|
content: string[];
|
|
21
|
+
ownerId: string;
|
|
22
|
+
propertyId: string;
|
|
21
23
|
}
|
|
22
24
|
/** Owned slot content parked under an instance while its component changes. */
|
|
23
25
|
interface ParkedSlotContent {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frames.d.ts","names":[],"sources":["../../src/slots/frames.ts"],"mappings":";;;;iBAKgB,eAAe,MAAM;;;;;iBASrB,gBACd,OAAO,YACP,MAAM,WACN;;iBAmBc,mBAAmB,OAAO,YAAY,UAAU,YAAY;;UAelE;;EAER;;EAEA;;EAEA;;;UAIe;EACf,OAAO;;EAEP;;;;;;;iBAoCc,uBAAuB,OAAO,YAAY,UAAU,YAAY;;
|
|
1
|
+
{"version":3,"file":"frames.d.ts","names":[],"sources":["../../src/slots/frames.ts"],"mappings":";;;;iBAKgB,eAAe,MAAM;;;;;iBASrB,gBACd,OAAO,YACP,MAAM,WACN;;iBAmBc,mBAAmB,OAAO,YAAY,UAAU,YAAY;;UAelE;;EAER;;EAEA;;EAEA;EACA;EACA;;;UAIe;EACf,OAAO;;EAEP;;;;;;;iBAoCc,uBAAuB,OAAO,YAAY,UAAU,YAAY;;iBA2BhE,wBACd,OAAO,YACP,UAAU,WACV,QAAQ"}
|
package/dist/slots/frames.js
CHANGED
|
@@ -77,13 +77,18 @@ function detachOwnedSlotContent(graph, instance) {
|
|
|
77
77
|
parked.slots.push({
|
|
78
78
|
path,
|
|
79
79
|
name,
|
|
80
|
-
content
|
|
80
|
+
content,
|
|
81
|
+
ownerId: owner.id,
|
|
82
|
+
propertyId
|
|
81
83
|
});
|
|
82
84
|
}
|
|
83
85
|
};
|
|
84
86
|
visit(instance, []);
|
|
85
87
|
return parked;
|
|
86
88
|
}
|
|
89
|
+
function assignsOtherContent(owner, propertyId, slot) {
|
|
90
|
+
return !(owner.id === slot.ownerId && propertyId === slot.propertyId) && Object.hasOwn(owner.componentPropertyAssignments, propertyId);
|
|
91
|
+
}
|
|
87
92
|
/** Move parked content into the slots of the same names and paths, and reassign them. */
|
|
88
93
|
function restoreOwnedSlotContent(graph, instance, parked) {
|
|
89
94
|
if (parked.slots.length === 0 && parked.propertyIds.length === 0) return;
|
|
@@ -95,7 +100,7 @@ function restoreOwnedSlotContent(graph, instance, parked) {
|
|
|
95
100
|
return !!propertyId && slotName(graph, owner, propertyId) === slot.name;
|
|
96
101
|
});
|
|
97
102
|
const propertyId = frame && slotPropertyId(frame);
|
|
98
|
-
if (!owner || !frame || !propertyId ||
|
|
103
|
+
if (!owner || !frame || !propertyId || assignsOtherContent(owner, propertyId, slot)) {
|
|
99
104
|
for (const id of slot.content) graph.deleteNode(id);
|
|
100
105
|
continue;
|
|
101
106
|
}
|
package/dist/slots/frames.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frames.js","names":[],"sources":["../../src/slots/frames.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { instanceMainComponent } from '../instances/main-component'\nimport type { SceneNode } from '../types'\n\n/** The slot property a frame holds the content of, if it is a slot. */\nexport function slotPropertyId(node: SceneNode): string | undefined {\n return node.componentPropertyReferences.find((reference) => reference.field === 'SLOT_CONTENT')\n ?.propertyId\n}\n\n/**\n * Whether this slot frame's children belong to its instance rather than its component: the\n * nearest enclosing instance assigns the slot. Such content is never synced from the component.\n */\nexport function ownsSlotContent(\n graph: SceneGraph,\n node: SceneNode,\n propertyId = slotPropertyId(node)\n): boolean {\n if (!propertyId) return false\n let owner = node.parentId ? graph.nodes.get(node.parentId) : undefined\n while (owner && owner.type !== 'INSTANCE')\n owner = owner.parentId ? graph.nodes.get(owner.parentId) : undefined\n return !!owner && Object.hasOwn(owner.componentPropertyAssignments, propertyId)\n}\n\n/** The name of a slot property as the instance's component (or the component's set) defines it. */\nfunction slotName(graph: SceneGraph, instance: SceneNode, propertyId: string) {\n const component = instanceMainComponent(graph, instance)\n const set = component?.parentId ? graph.nodes.get(component.parentId) : undefined\n return [component, set]\n .flatMap((node) => node?.componentPropertyDefinitions ?? [])\n .find((definition) => definition.id === propertyId && definition.type === 'SLOT')?.name\n}\n\n/** An instance's slot frames, without entering nested instances, whose slots are their own. */\nexport function instanceSlotFrames(graph: SceneGraph, instance: SceneNode): SceneNode[] {\n const frames: SceneNode[] = []\n const visit = (node: SceneNode): void => {\n for (const childId of node.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n if (slotPropertyId(child)) frames.push(child)\n else if (child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(instance)\n return frames\n}\n\n/** One slot's owned content, parked while the instance it belongs to is rebuilt. */\ninterface ParkedSlot {\n /** Names of the nested instances leading to the slot's owner; empty for the instance itself. */\n path: string[]\n /** The slot property's name, which the replacement must share. */\n name: string\n /** Content layer ids, in layer order. */\n content: string[]\n}\n\n/** Owned slot content parked under an instance while its component changes. */\nexport interface ParkedSlotContent {\n slots: ParkedSlot[]\n /** The instance's own slot assignments the content was parked from. */\n propertyIds: string[]\n}\n\n/** Instances directly inside this one: not inside another nested instance or a slot. */\nfunction nestedInstances(graph: SceneGraph, owner: SceneNode): SceneNode[] {\n const found: SceneNode[] = []\n const visit = (node: SceneNode): void => {\n for (const childId of node.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || slotPropertyId(child)) continue\n if (child.type === 'INSTANCE') found.push(child)\n else visit(child)\n }\n }\n visit(owner)\n return found\n}\n\n/** The nested instance a name path leads to from `root`, matched by layer name as Figma does. */\nfunction instanceAtPath(\n graph: SceneGraph,\n root: SceneNode,\n path: readonly string[]\n): SceneNode | undefined {\n let current: SceneNode | undefined = root\n for (const name of path) {\n current = current && nestedInstances(graph, current).find((node) => node.name === name)\n }\n return current\n}\n\n/**\n * Park the slot content an instance and the instances nested in it own, by slot name and the\n * nested instance's name path, directly under the instance, so its component can be replaced.\n * Figma keeps that content when a variant switch or swap leads to slots of the same names.\n */\nexport function detachOwnedSlotContent(graph: SceneGraph, instance: SceneNode): ParkedSlotContent {\n const parked: ParkedSlotContent = { slots: [], propertyIds: [] }\n const visit = (owner: SceneNode, path: string[]): void => {\n for (const nested of nestedInstances(graph, owner)) visit(nested, [...path, nested.name])\n for (const frame of instanceSlotFrames(graph, owner)) {\n const propertyId = slotPropertyId(frame)\n if (!propertyId || !Object.hasOwn(owner.componentPropertyAssignments, propertyId)) continue\n if (owner.id === instance.id) parked.propertyIds.push(propertyId)\n const name = slotName(graph, owner, propertyId)\n const key = [...path, name].join('\\u0000')\n if (!name || parked.slots.some((slot) => [...slot.path, slot.name].join('\\u0000') === key))\n continue\n const content = [...frame.childIds]\n for (const id of content) graph.insertChildAt(id, instance.id, instance.childIds.length)\n parked.slots.push({ path, name, content })\n }\n }\n visit(instance, [])\n return parked\n}\n\n/** Move parked content into the slots of the same names and paths, and reassign them. */\nexport function restoreOwnedSlotContent(\n graph: SceneGraph,\n instance: SceneNode,\n parked: ParkedSlotContent\n): void {\n if (parked.slots.length === 0 && parked.propertyIds.length === 0) return\n graph.updateNode(instance.id, {\n componentPropertyAssignments: Object.fromEntries(\n Object.entries(instance.componentPropertyAssignments).filter(\n ([id]) => !parked.propertyIds.includes(id)\n )\n )\n })\n for (const slot of parked.slots) {\n const owner = instanceAtPath(graph, instance, slot.path)\n const frame =\n owner &&\n instanceSlotFrames(graph, owner).find((candidate) => {\n const propertyId = slotPropertyId(candidate)\n return !!propertyId && slotName(graph, owner, propertyId) === slot.name\n })\n const propertyId = frame && slotPropertyId(frame)\n if (\n !owner ||\n !frame ||\n !propertyId ||\n Object.hasOwn(owner.componentPropertyAssignments, propertyId)\n ) {\n for (const id of slot.content) graph.deleteNode(id)\n continue\n }\n for (const id of Array.from(frame.childIds)) graph.deleteNode(id)\n for (const [index, id] of slot.content.entries()) graph.insertChildAt(id, frame.id, index)\n graph.updateNode(owner.id, {\n componentPropertyAssignments: { ...owner.componentPropertyAssignments, [propertyId]: '' }\n })\n }\n}\n"],"mappings":";;;AAKA,SAAgB,eAAe,MAAqC;CAClE,OAAO,KAAK,4BAA4B,MAAM,cAAc,UAAU,UAAU,cAAc,CAAC,EAC3F;AACN;;;;;AAMA,SAAgB,gBACd,OACA,MACA,aAAa,eAAe,IAAI,GACvB;CACT,IAAI,CAAC,YAAY,OAAO;CACxB,IAAI,QAAQ,KAAK,WAAW,MAAM,MAAM,IAAI,KAAK,QAAQ,IAAI,KAAA;CAC7D,OAAO,SAAS,MAAM,SAAS,YAC7B,QAAQ,MAAM,WAAW,MAAM,MAAM,IAAI,MAAM,QAAQ,IAAI,KAAA;CAC7D,OAAO,CAAC,CAA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AmB,OAAO,KAAK,CAAC,CAAC,MAAM,cAAc;GACnD,MAAM,aAAa,eAAe,SAAS;GAC3C,OAAO,CAAC,CAAC,cAAc,SAAS,OAAO,OAAO,UAAU,MAAM,KAAK;EACrE,CAAC;EACH,MAAM,aAAa,SAAS,eAAe,KAAK;EAChD,IACE,CAAC,SACD,CAAC,SACD,CAAC,cACD,OAAO,OAAO,MAAM,8BAA8B,UAAU,GAC5D;GACA,KAAK,MAAM,MAAM,KAAK,SAAS,MAAM,WAAW,EAAE;GAClD;EACF;EACA,KAAK,MAAM,MAAM,MAAM,KAAK,MAAM,QAAQ,GAAG,MAAM,WAAW,EAAE;EAChE,KAAK,MAAM,CAAC,OAAO,OAAO,KAAK,QAAQ,QAAQ,GAAG,MAAM,cAAc,IAAI,MAAM,IAAI,KAAK;EACzF,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B;GAAE,GAAG,MAAM;IAA+B,aAAa;EAAG,EAC1F,CAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"frames.js","names":[],"sources":["../../src/slots/frames.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { instanceMainComponent } from '../instances/main-component'\nimport type { SceneNode } from '../types'\n\n/** The slot property a frame holds the content of, if it is a slot. */\nexport function slotPropertyId(node: SceneNode): string | undefined {\n return node.componentPropertyReferences.find((reference) => reference.field === 'SLOT_CONTENT')\n ?.propertyId\n}\n\n/**\n * Whether this slot frame's children belong to its instance rather than its component: the\n * nearest enclosing instance assigns the slot. Such content is never synced from the component.\n */\nexport function ownsSlotContent(\n graph: SceneGraph,\n node: SceneNode,\n propertyId = slotPropertyId(node)\n): boolean {\n if (!propertyId) return false\n let owner = node.parentId ? graph.nodes.get(node.parentId) : undefined\n while (owner && owner.type !== 'INSTANCE')\n owner = owner.parentId ? graph.nodes.get(owner.parentId) : undefined\n return !!owner && Object.hasOwn(owner.componentPropertyAssignments, propertyId)\n}\n\n/** The name of a slot property as the instance's component (or the component's set) defines it. */\nfunction slotName(graph: SceneGraph, instance: SceneNode, propertyId: string) {\n const component = instanceMainComponent(graph, instance)\n const set = component?.parentId ? graph.nodes.get(component.parentId) : undefined\n return [component, set]\n .flatMap((node) => node?.componentPropertyDefinitions ?? [])\n .find((definition) => definition.id === propertyId && definition.type === 'SLOT')?.name\n}\n\n/** An instance's slot frames, without entering nested instances, whose slots are their own. */\nexport function instanceSlotFrames(graph: SceneGraph, instance: SceneNode): SceneNode[] {\n const frames: SceneNode[] = []\n const visit = (node: SceneNode): void => {\n for (const childId of node.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n if (slotPropertyId(child)) frames.push(child)\n else if (child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(instance)\n return frames\n}\n\n/** One slot's owned content, parked while the instance it belongs to is rebuilt. */\ninterface ParkedSlot {\n /** Names of the nested instances leading to the slot's owner; empty for the instance itself. */\n path: string[]\n /** The slot property's name, which the replacement must share. */\n name: string\n /** Content layer ids, in layer order. */\n content: string[]\n ownerId: string\n propertyId: string\n}\n\n/** Owned slot content parked under an instance while its component changes. */\nexport interface ParkedSlotContent {\n slots: ParkedSlot[]\n /** The instance's own slot assignments the content was parked from. */\n propertyIds: string[]\n}\n\n/** Instances directly inside this one: not inside another nested instance or a slot. */\nfunction nestedInstances(graph: SceneGraph, owner: SceneNode): SceneNode[] {\n const found: SceneNode[] = []\n const visit = (node: SceneNode): void => {\n for (const childId of node.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || slotPropertyId(child)) continue\n if (child.type === 'INSTANCE') found.push(child)\n else visit(child)\n }\n }\n visit(owner)\n return found\n}\n\n/** The nested instance a name path leads to from `root`, matched by layer name as Figma does. */\nfunction instanceAtPath(\n graph: SceneGraph,\n root: SceneNode,\n path: readonly string[]\n): SceneNode | undefined {\n let current: SceneNode | undefined = root\n for (const name of path) {\n current = current && nestedInstances(graph, current).find((node) => node.name === name)\n }\n return current\n}\n\n/**\n * Park the slot content an instance and the instances nested in it own, by slot name and the\n * nested instance's name path, directly under the instance, so its component can be replaced.\n * Figma keeps that content when a variant switch or swap leads to slots of the same names.\n */\nexport function detachOwnedSlotContent(graph: SceneGraph, instance: SceneNode): ParkedSlotContent {\n const parked: ParkedSlotContent = { slots: [], propertyIds: [] }\n const visit = (owner: SceneNode, path: string[]): void => {\n for (const nested of nestedInstances(graph, owner)) visit(nested, [...path, nested.name])\n for (const frame of instanceSlotFrames(graph, owner)) {\n const propertyId = slotPropertyId(frame)\n if (!propertyId || !Object.hasOwn(owner.componentPropertyAssignments, propertyId)) continue\n if (owner.id === instance.id) parked.propertyIds.push(propertyId)\n const name = slotName(graph, owner, propertyId)\n const key = [...path, name].join('\\u0000')\n if (!name || parked.slots.some((slot) => [...slot.path, slot.name].join('\\u0000') === key))\n continue\n const content = [...frame.childIds]\n for (const id of content) graph.insertChildAt(id, instance.id, instance.childIds.length)\n parked.slots.push({ path, name, content, ownerId: owner.id, propertyId })\n }\n }\n visit(instance, [])\n return parked\n}\n\nfunction assignsOtherContent(owner: SceneNode, propertyId: string, slot: ParkedSlot): boolean {\n const parkedFromHere = owner.id === slot.ownerId && propertyId === slot.propertyId\n return !parkedFromHere && Object.hasOwn(owner.componentPropertyAssignments, propertyId)\n}\n\n/** Move parked content into the slots of the same names and paths, and reassign them. */\nexport function restoreOwnedSlotContent(\n graph: SceneGraph,\n instance: SceneNode,\n parked: ParkedSlotContent\n): void {\n if (parked.slots.length === 0 && parked.propertyIds.length === 0) return\n graph.updateNode(instance.id, {\n componentPropertyAssignments: Object.fromEntries(\n Object.entries(instance.componentPropertyAssignments).filter(\n ([id]) => !parked.propertyIds.includes(id)\n )\n )\n })\n for (const slot of parked.slots) {\n const owner = instanceAtPath(graph, instance, slot.path)\n const frame =\n owner &&\n instanceSlotFrames(graph, owner).find((candidate) => {\n const propertyId = slotPropertyId(candidate)\n return !!propertyId && slotName(graph, owner, propertyId) === slot.name\n })\n const propertyId = frame && slotPropertyId(frame)\n if (!owner || !frame || !propertyId || assignsOtherContent(owner, propertyId, slot)) {\n for (const id of slot.content) graph.deleteNode(id)\n continue\n }\n for (const id of Array.from(frame.childIds)) graph.deleteNode(id)\n for (const [index, id] of slot.content.entries()) graph.insertChildAt(id, frame.id, index)\n graph.updateNode(owner.id, {\n componentPropertyAssignments: { ...owner.componentPropertyAssignments, [propertyId]: '' }\n })\n }\n}\n"],"mappings":";;;AAKA,SAAgB,eAAe,MAAqC;CAClE,OAAO,KAAK,4BAA4B,MAAM,cAAc,UAAU,UAAU,cAAc,CAAC,EAC3F;AACN;;;;;AAMA,SAAgB,gBACd,OACA,MACA,aAAa,eAAe,IAAI,GACvB;CACT,IAAI,CAAC,YAAY,OAAO;CACxB,IAAI,QAAQ,KAAK,WAAW,MAAM,MAAM,IAAI,KAAK,QAAQ,IAAI,KAAA;CAC7D,OAAO,SAAS,MAAM,SAAS,YAC7B,QAAQ,MAAM,WAAW,MAAM,MAAM,IAAI,MAAM,QAAQ,IAAI,KAAA;CAC7D,OAAO,CAAC,CAAC,SAAS,OAAO,OAAO,MAAM,8BAA8B,UAAU;AAChF;;AAGA,SAAS,SAAS,OAAmB,UAAqB,YAAoB;CAC5E,MAAM,YAAY,sBAAsB,OAAO,QAAQ;CAEvD,OAAO,CAAC,WADI,WAAW,WAAW,MAAM,MAAM,IAAI,UAAU,QAAQ,IAAI,KAAA,CAClD,CAAC,CACpB,SAAS,SAAS,MAAM,gCAAgC,CAAC,CAAC,CAAC,CAC3D,MAAM,eAAe,WAAW,OAAO,cAAc,WAAW,SAAS,MAAM,CAAC,EAAE;AACvF;;AAGA,SAAgB,mBAAmB,OAAmB,UAAkC;CACtF,MAAM,SAAsB,CAAC;CAC7B,MAAM,SAAS,SAA0B;EACvC,KAAK,MAAM,WAAW,KAAK,UAAU;GACnC,MAAM,QAAQ,MAAM,MAAM,IAAI,OAAO;GACrC,IAAI,CAAC,OAAO;GACZ,IAAI,eAAe,KAAK,GAAG,OAAO,KAAK,KAAK;QACvC,IAAI,MAAM,SAAS,YAAY,MAAM,K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Q,GAAG,MAAM,cAAc,IAAI,MAAM,IAAI,KAAK;EACzF,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B;GAAE,GAAG,MAAM;IAA+B,aAAa;EAAG,EAC1F,CAAC;CACH;AACF"}
|
package/dist/text/direction.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { LayoutDirection, SceneNode, TextDirection } from "../types.js";
|
|
2
2
|
//#region src/text/direction.d.ts
|
|
3
|
+
/** Whether the text has a letter of a right-to-left script, such as Arabic or Hebrew. */
|
|
4
|
+
declare function containsRTLText(text: string): boolean;
|
|
3
5
|
declare function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'>;
|
|
4
6
|
declare function resolveTextDirection(direction: TextDirection, text: string): Exclude<TextDirection, 'AUTO'>;
|
|
5
7
|
declare function resolveNodeTextDirection(node: Pick<SceneNode, 'textDirection' | 'text'>): 'LTR' | 'RTL';
|
|
@@ -9,5 +11,5 @@ declare function resolveNodeLayoutDirection(node: {
|
|
|
9
11
|
declare function isLogicalTextAlignStart(node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>): boolean;
|
|
10
12
|
declare function isLogicalTextAlignEnd(node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>): boolean;
|
|
11
13
|
//#endregion
|
|
12
|
-
export { detectTextDirection, isLogicalTextAlignEnd, isLogicalTextAlignStart, resolveNodeLayoutDirection, resolveNodeTextDirection, resolveTextDirection };
|
|
14
|
+
export { containsRTLText, detectTextDirection, isLogicalTextAlignEnd, isLogicalTextAlignStart, resolveNodeLayoutDirection, resolveNodeTextDirection, resolveTextDirection };
|
|
13
15
|
//# sourceMappingURL=direction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direction.d.ts","names":[],"sources":["../../src/text/direction.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"direction.d.ts","names":[],"sources":["../../src/text/direction.ts"],"mappings":";;;iBAOgB,gBAAgB;iBAIhB,oBAAoB,eAAe,QAAQ;iBAQ3C,qBACd,WAAW,eACX,eACC,QAAQ;iBAIK,yBACd,MAAM,KAAK;iBAKG,2BACd;EAAQ,kBAAkB;GAC1B,qBAAoB,QAAQ,2BAC3B,QAAQ;iBAMK,wBACd,MAAM,KAAK;iBASG,sBACd,MAAM,KAAK"}
|
package/dist/text/direction.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
//#region src/text/direction.ts
|
|
2
2
|
const RTL_CHAR_RE = /\p{Script=Arabic}|\p{Script=Hebrew}|\p{Script=Syriac}|\p{Script=Thaana}|\p{Script=Nko}|\p{Script=Adlam}/u;
|
|
3
3
|
const LTR_CHAR_RE = /\p{Script=Latin}|\p{Script=Cyrillic}|\p{Script=Greek}/u;
|
|
4
|
+
/** Whether the text has a letter of a right-to-left script, such as Arabic or Hebrew. */
|
|
5
|
+
function containsRTLText(text) {
|
|
6
|
+
return RTL_CHAR_RE.test(text);
|
|
7
|
+
}
|
|
4
8
|
function detectTextDirection(text) {
|
|
5
9
|
for (const char of text) {
|
|
6
10
|
if (RTL_CHAR_RE.test(char)) return "RTL";
|
|
@@ -26,6 +30,6 @@ function isLogicalTextAlignEnd(node) {
|
|
|
26
30
|
return direction === "LTR" && node.textAlignHorizontal === "RIGHT" || direction === "RTL" && node.textAlignHorizontal === "LEFT";
|
|
27
31
|
}
|
|
28
32
|
//#endregion
|
|
29
|
-
export { detectTextDirection, isLogicalTextAlignEnd, isLogicalTextAlignStart, resolveNodeLayoutDirection, resolveNodeTextDirection, resolveTextDirection };
|
|
33
|
+
export { containsRTLText, detectTextDirection, isLogicalTextAlignEnd, isLogicalTextAlignStart, resolveNodeLayoutDirection, resolveNodeTextDirection, resolveTextDirection };
|
|
30
34
|
|
|
31
35
|
//# sourceMappingURL=direction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direction.js","names":[],"sources":["../../src/text/direction.ts"],"sourcesContent":["import type { LayoutDirection, SceneNode, TextDirection } from '../types'\n\nconst RTL_CHAR_RE =\n /\\p{Script=Arabic}|\\p{Script=Hebrew}|\\p{Script=Syriac}|\\p{Script=Thaana}|\\p{Script=Nko}|\\p{Script=Adlam}/u\nconst LTR_CHAR_RE = /\\p{Script=Latin}|\\p{Script=Cyrillic}|\\p{Script=Greek}/u\n\nexport function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'> {\n for (const char of text) {\n if (RTL_CHAR_RE.test(char)) return 'RTL'\n if (LTR_CHAR_RE.test(char)) return 'LTR'\n }\n return 'LTR'\n}\n\nexport function resolveTextDirection(\n direction: TextDirection,\n text: string\n): Exclude<TextDirection, 'AUTO'> {\n return direction === 'AUTO' ? detectTextDirection(text) : direction\n}\n\nexport function resolveNodeTextDirection(\n node: Pick<SceneNode, 'textDirection' | 'text'>\n): 'LTR' | 'RTL' {\n return resolveTextDirection(node.textDirection, node.text)\n}\n\nexport function resolveNodeLayoutDirection(\n node: { layoutDirection?: LayoutDirection },\n inheritedDirection: Exclude<LayoutDirection, 'AUTO'> = 'LTR'\n): Exclude<LayoutDirection, 'AUTO'> {\n return !node.layoutDirection || node.layoutDirection === 'AUTO'\n ? inheritedDirection\n : node.layoutDirection\n}\n\nexport function isLogicalTextAlignStart(\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n): boolean {\n const direction = resolveNodeTextDirection(node)\n return (\n (direction === 'LTR' && node.textAlignHorizontal === 'LEFT') ||\n (direction === 'RTL' && node.textAlignHorizontal === 'RIGHT')\n )\n}\n\nexport function isLogicalTextAlignEnd(\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n): boolean {\n const direction = resolveNodeTextDirection(node)\n return (\n (direction === 'LTR' && node.textAlignHorizontal === 'RIGHT') ||\n (direction === 'RTL' && node.textAlignHorizontal === 'LEFT')\n )\n}\n"],"mappings":";AAEA,MAAM,cACJ;AACF,MAAM,cAAc;
|
|
1
|
+
{"version":3,"file":"direction.js","names":[],"sources":["../../src/text/direction.ts"],"sourcesContent":["import type { LayoutDirection, SceneNode, TextDirection } from '../types'\n\nconst RTL_CHAR_RE =\n /\\p{Script=Arabic}|\\p{Script=Hebrew}|\\p{Script=Syriac}|\\p{Script=Thaana}|\\p{Script=Nko}|\\p{Script=Adlam}/u\nconst LTR_CHAR_RE = /\\p{Script=Latin}|\\p{Script=Cyrillic}|\\p{Script=Greek}/u\n\n/** Whether the text has a letter of a right-to-left script, such as Arabic or Hebrew. */\nexport function containsRTLText(text: string): boolean {\n return RTL_CHAR_RE.test(text)\n}\n\nexport function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'> {\n for (const char of text) {\n if (RTL_CHAR_RE.test(char)) return 'RTL'\n if (LTR_CHAR_RE.test(char)) return 'LTR'\n }\n return 'LTR'\n}\n\nexport function resolveTextDirection(\n direction: TextDirection,\n text: string\n): Exclude<TextDirection, 'AUTO'> {\n return direction === 'AUTO' ? detectTextDirection(text) : direction\n}\n\nexport function resolveNodeTextDirection(\n node: Pick<SceneNode, 'textDirection' | 'text'>\n): 'LTR' | 'RTL' {\n return resolveTextDirection(node.textDirection, node.text)\n}\n\nexport function resolveNodeLayoutDirection(\n node: { layoutDirection?: LayoutDirection },\n inheritedDirection: Exclude<LayoutDirection, 'AUTO'> = 'LTR'\n): Exclude<LayoutDirection, 'AUTO'> {\n return !node.layoutDirection || node.layoutDirection === 'AUTO'\n ? inheritedDirection\n : node.layoutDirection\n}\n\nexport function isLogicalTextAlignStart(\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n): boolean {\n const direction = resolveNodeTextDirection(node)\n return (\n (direction === 'LTR' && node.textAlignHorizontal === 'LEFT') ||\n (direction === 'RTL' && node.textAlignHorizontal === 'RIGHT')\n )\n}\n\nexport function isLogicalTextAlignEnd(\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n): boolean {\n const direction = resolveNodeTextDirection(node)\n return (\n (direction === 'LTR' && node.textAlignHorizontal === 'RIGHT') ||\n (direction === 'RTL' && node.textAlignHorizontal === 'LEFT')\n )\n}\n"],"mappings":";AAEA,MAAM,cACJ;AACF,MAAM,cAAc;;AAGpB,SAAgB,gBAAgB,MAAuB;CACrD,OAAO,YAAY,KAAK,IAAI;AAC9B;AAEA,SAAgB,oBAAoB,MAA8C;CAChF,KAAK,MAAM,QAAQ,MAAM;EACvB,IAAI,YAAY,KAAK,IAAI,GAAG,OAAO;EACnC,IAAI,YAAY,KAAK,IAAI,GAAG,OAAO;CACrC;CACA,OAAO;AACT;AAEA,SAAgB,qBACd,WACA,MACgC;CAChC,OAAO,cAAc,SAAS,oBAAoB,IAAI,IAAI;AAC5D;AAEA,SAAgB,yBACd,MACe;CACf,OAAO,qBAAqB,KAAK,eAAe,KAAK,IAAI;AAC3D;AAEA,SAAgB,2BACd,MACA,qBAAuD,OACrB;CAClC,OAAO,CAAC,KAAK,mBAAmB,KAAK,oBAAoB,SACrD,qBACA,KAAK;AACX;AAEA,SAAgB,wBACd,MACS;CACT,MAAM,YAAY,yBAAyB,IAAI;CAC/C,OACG,cAAc,SAAS,KAAK,wBAAwB,UACpD,cAAc,SAAS,KAAK,wBAAwB;AAEzD;AAEA,SAAgB,sBACd,MACS;CACT,MAAM,YAAY,yBAAyB,IAAI;CAC/C,OACG,cAAc,SAAS,KAAK,wBAAwB,WACpD,cAAc,SAAS,KAAK,wBAAwB;AAEzD"}
|
package/dist/text/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MAX_LIST_INDENTATION, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, TextParagraphRange, hasParagraphSpacing, hasTextList, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, sharedParagraphSpacing, textParagraphRanges, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing } from "./paragraphs.js";
|
|
2
2
|
import { LIST_BULLET, ListNumberFormat, TextListItem, formatListNumber, listNumberFormat, textListItems, topLevelNumberDigits } from "./lists.js";
|
|
3
3
|
import { StyleRunReferences, remapStyleRunReferences, styleRunReferences } from "./references.js";
|
|
4
|
-
import { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
|
|
4
|
+
import { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
|
|
5
5
|
import { textLinesOverflow } from "./overflow.js";
|
|
6
6
|
import { textLengthSchema } from "./schema.js";
|
|
7
|
-
export { LIST_BULLET, ListNumberFormat, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, StyleRunReferences, TEXT_PARAGRAPH_SPACING_FIELDS, TextListItem, TextParagraphRange, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunReferences, textLengthPixels, textLengthSchema, textLinesOverflow, textListItems, textParagraphRanges, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
|
|
7
|
+
export { LIST_BULLET, ListNumberFormat, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, StyleRunReferences, TEXT_PARAGRAPH_SPACING_FIELDS, TextListItem, TextParagraphRange, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunReferences, textLengthPixels, textLengthSchema, textLinesOverflow, textListItems, textParagraphRanges, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
|
package/dist/text/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
|
|
2
|
-
import { textLinesOverflow } from "./overflow.js";
|
|
1
|
+
import { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
|
|
3
2
|
import { remapStyleRunReferences, styleRunReferences } from "./references.js";
|
|
4
3
|
import { MAX_LIST_INDENTATION, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, hasParagraphSpacing, hasTextList, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, sharedParagraphSpacing, textParagraphRanges, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing } from "./paragraphs.js";
|
|
5
4
|
import { LIST_BULLET, formatListNumber, listNumberFormat, textListItems, topLevelNumberDigits } from "./lists.js";
|
|
5
|
+
import { textLinesOverflow } from "./overflow.js";
|
|
6
6
|
import { textLengthSchema } from "./schema.js";
|
|
7
|
-
export { LIST_BULLET, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunReferences, textLengthPixels, textLengthSchema, textLinesOverflow, textListItems, textParagraphRanges, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
|
|
7
|
+
export { LIST_BULLET, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunReferences, textLengthPixels, textLengthSchema, textLinesOverflow, textListItems, textParagraphRanges, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
|
package/dist/text/lengths.d.ts
CHANGED
|
@@ -6,6 +6,11 @@ declare const NO_LETTER_SPACING: TextLength;
|
|
|
6
6
|
declare function textLengthPixels(length: TextLength, fontSize: number): number;
|
|
7
7
|
/** A line height in pixels at `fontSize`, or null when it is automatic. */
|
|
8
8
|
declare function lineHeightPixels(lineHeight: TextLength | null, fontSize: number): number | null;
|
|
9
|
+
/**
|
|
10
|
+
* How far apart a line height sets lines at `fontSize`, as Figma steps them: a height in pixels
|
|
11
|
+
* as it is, a percent one to whole pixels (Figma desktop 126); null when it is automatic.
|
|
12
|
+
*/
|
|
13
|
+
declare function lineStepPixels(lineHeight: TextLength | null, fontSize: number): number | null;
|
|
9
14
|
/** A length in pixels, as a bound number variable and most authored formats give one. */
|
|
10
15
|
declare function pixelLength(value: number): TextLength;
|
|
11
16
|
/** A length as a percent of the font size. */
|
|
@@ -15,5 +20,5 @@ declare function scaledTextLength(length: TextLength, factor: number): TextLengt
|
|
|
15
20
|
/** `length` as people read it: `24px` or `150%`. */
|
|
16
21
|
declare function formatTextLength(length: TextLength): string;
|
|
17
22
|
//#endregion
|
|
18
|
-
export { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels };
|
|
23
|
+
export { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels };
|
|
19
24
|
//# sourceMappingURL=lengths.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lengths.d.ts","names":[],"sources":["../../src/text/lengths.ts"],"mappings":";;;cAGa,mBAAmB;;iBAGhB,iBAAiB,QAAQ,YAAY;;iBAKrC,iBAAiB,YAAY,mBAAmB;;
|
|
1
|
+
{"version":3,"file":"lengths.d.ts","names":[],"sources":["../../src/text/lengths.ts"],"mappings":";;;cAGa,mBAAmB;;iBAGhB,iBAAiB,QAAQ,YAAY;;iBAKrC,iBAAiB,YAAY,mBAAmB;;;;;iBAQhD,eAAe,YAAY,mBAAmB;;iBAO9C,YAAY,gBAAgB;;iBAK5B,cAAc,gBAAgB;;iBAK9B,iBAAiB,QAAQ,YAAY,iBAAiB;;iBAKtD,iBAAiB,QAAQ"}
|
package/dist/text/lengths.js
CHANGED
|
@@ -12,6 +12,15 @@ function textLengthPixels(length, fontSize) {
|
|
|
12
12
|
function lineHeightPixels(lineHeight, fontSize) {
|
|
13
13
|
return lineHeight ? textLengthPixels(lineHeight, fontSize) : null;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* How far apart a line height sets lines at `fontSize`, as Figma steps them: a height in pixels
|
|
17
|
+
* as it is, a percent one to whole pixels (Figma desktop 126); null when it is automatic.
|
|
18
|
+
*/
|
|
19
|
+
function lineStepPixels(lineHeight, fontSize) {
|
|
20
|
+
if (!lineHeight) return null;
|
|
21
|
+
const pixels = textLengthPixels(lineHeight, fontSize);
|
|
22
|
+
return lineHeight.unit === "PIXELS" ? pixels : Math.round(pixels);
|
|
23
|
+
}
|
|
15
24
|
/** A length in pixels, as a bound number variable and most authored formats give one. */
|
|
16
25
|
function pixelLength(value) {
|
|
17
26
|
return {
|
|
@@ -35,6 +44,6 @@ function formatTextLength(length) {
|
|
|
35
44
|
return length.unit === "PIXELS" ? `${length.value}px` : `${length.value}%`;
|
|
36
45
|
}
|
|
37
46
|
//#endregion
|
|
38
|
-
export { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels };
|
|
47
|
+
export { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels };
|
|
39
48
|
|
|
40
49
|
//# sourceMappingURL=lengths.js.map
|
package/dist/text/lengths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lengths.js","names":[],"sources":["../../src/text/lengths.ts"],"sourcesContent":["import type { TextLength } from '../types'\n\n/** No letter spacing, as a new text has it and as Figma writes it. */\nexport const NO_LETTER_SPACING: TextLength = { value: 0, unit: 'PERCENT' }\n\n/** `length` in pixels at `fontSize`. */\nexport function textLengthPixels(length: TextLength, fontSize: number): number {\n return length.unit === 'PIXELS' ? length.value : (length.value / 100) * fontSize\n}\n\n/** A line height in pixels at `fontSize`, or null when it is automatic. */\nexport function lineHeightPixels(lineHeight: TextLength | null, fontSize: number): number | null {\n return lineHeight ? textLengthPixels(lineHeight, fontSize) : null\n}\n\n/** A length in pixels, as a bound number variable and most authored formats give one. */\nexport function pixelLength(value: number): TextLength {\n return { value, unit: 'PIXELS' }\n}\n\n/** A length as a percent of the font size. */\nexport function percentLength(value: number): TextLength {\n return { value, unit: 'PERCENT' }\n}\n\n/** `length` scaled by `factor`: pixels scale, a percent already follows the font size. */\nexport function scaledTextLength(length: TextLength, factor: number): TextLength {\n return length.unit === 'PIXELS' ? pixelLength(length.value * factor) : length\n}\n\n/** `length` as people read it: `24px` or `150%`. */\nexport function formatTextLength(length: TextLength): string {\n return length.unit === 'PIXELS' ? `${length.value}px` : `${length.value}%`\n}\n"],"mappings":";;AAGA,MAAa,oBAAgC;CAAE,OAAO;CAAG,MAAM;AAAU;;AAGzE,SAAgB,iBAAiB,QAAoB,UAA0B;CAC7E,OAAO,OAAO,SAAS,WAAW,OAAO,QAAS,OAAO,QAAQ,MAAO;AAC1E;;AAGA,SAAgB,iBAAiB,YAA+B,UAAiC;CAC/F,OAAO,aAAa,iBAAiB,YAAY,QAAQ,IAAI;AAC/D;;AAGA,SAAgB,YAAY,OAA2B;CACrD,OAAO;EAAE;EAAO,MAAM;CAAS;AACjC;;AAGA,SAAgB,cAAc,OAA2B;CACvD,OAAO;EAAE;EAAO,MAAM;CAAU;AAClC;;AAGA,SAAgB,iBAAiB,QAAoB,QAA4B;CAC/E,OAAO,OAAO,SAAS,WAAW,YAAY,OAAO,QAAQ,MAAM,IAAI;AACzE;;AAGA,SAAgB,iBAAiB,QAA4B;CAC3D,OAAO,OAAO,SAAS,WAAW,GAAG,OAAO,MAAM,MAAM,GAAG,OAAO,MAAM;AAC1E"}
|
|
1
|
+
{"version":3,"file":"lengths.js","names":[],"sources":["../../src/text/lengths.ts"],"sourcesContent":["import type { TextLength } from '../types'\n\n/** No letter spacing, as a new text has it and as Figma writes it. */\nexport const NO_LETTER_SPACING: TextLength = { value: 0, unit: 'PERCENT' }\n\n/** `length` in pixels at `fontSize`. */\nexport function textLengthPixels(length: TextLength, fontSize: number): number {\n return length.unit === 'PIXELS' ? length.value : (length.value / 100) * fontSize\n}\n\n/** A line height in pixels at `fontSize`, or null when it is automatic. */\nexport function lineHeightPixels(lineHeight: TextLength | null, fontSize: number): number | null {\n return lineHeight ? textLengthPixels(lineHeight, fontSize) : null\n}\n\n/**\n * How far apart a line height sets lines at `fontSize`, as Figma steps them: a height in pixels\n * as it is, a percent one to whole pixels (Figma desktop 126); null when it is automatic.\n */\nexport function lineStepPixels(lineHeight: TextLength | null, fontSize: number): number | null {\n if (!lineHeight) return null\n const pixels = textLengthPixels(lineHeight, fontSize)\n return lineHeight.unit === 'PIXELS' ? pixels : Math.round(pixels)\n}\n\n/** A length in pixels, as a bound number variable and most authored formats give one. */\nexport function pixelLength(value: number): TextLength {\n return { value, unit: 'PIXELS' }\n}\n\n/** A length as a percent of the font size. */\nexport function percentLength(value: number): TextLength {\n return { value, unit: 'PERCENT' }\n}\n\n/** `length` scaled by `factor`: pixels scale, a percent already follows the font size. */\nexport function scaledTextLength(length: TextLength, factor: number): TextLength {\n return length.unit === 'PIXELS' ? pixelLength(length.value * factor) : length\n}\n\n/** `length` as people read it: `24px` or `150%`. */\nexport function formatTextLength(length: TextLength): string {\n return length.unit === 'PIXELS' ? `${length.value}px` : `${length.value}%`\n}\n"],"mappings":";;AAGA,MAAa,oBAAgC;CAAE,OAAO;CAAG,MAAM;AAAU;;AAGzE,SAAgB,iBAAiB,QAAoB,UAA0B;CAC7E,OAAO,OAAO,SAAS,WAAW,OAAO,QAAS,OAAO,QAAQ,MAAO;AAC1E;;AAGA,SAAgB,iBAAiB,YAA+B,UAAiC;CAC/F,OAAO,aAAa,iBAAiB,YAAY,QAAQ,IAAI;AAC/D;;;;;AAMA,SAAgB,eAAe,YAA+B,UAAiC;CAC7F,IAAI,CAAC,YAAY,OAAO;CACxB,MAAM,SAAS,iBAAiB,YAAY,QAAQ;CACpD,OAAO,WAAW,SAAS,WAAW,SAAS,KAAK,MAAM,MAAM;AAClE;;AAGA,SAAgB,YAAY,OAA2B;CACrD,OAAO;EAAE;EAAO,MAAM;CAAS;AACjC;;AAGA,SAAgB,cAAc,OAA2B;CACvD,OAAO;EAAE;EAAO,MAAM;CAAU;AAClC;;AAGA,SAAgB,iBAAiB,QAAoB,QAA4B;CAC/E,OAAO,OAAO,SAAS,WAAW,YAAY,OAAO,QAAQ,MAAM,IAAI;AACzE;;AAGA,SAAgB,iBAAiB,QAA4B;CAC3D,OAAO,OAAO,SAAS,WAAW,GAAG,OAAO,MAAM,MAAM,GAAG,OAAO,MAAM;AAC1E"}
|
package/dist/text/overflow.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SceneNode } from "../types.js";
|
|
2
2
|
//#region src/text/overflow.d.ts
|
|
3
|
-
type TextBoundsNode = Pick<
|
|
3
|
+
type TextBoundsNode = Pick<SceneNode, 'type' | 'height' | 'derivedTextHeight'>;
|
|
4
4
|
/**
|
|
5
5
|
* How far a text's lines reach below its box: a fixed-size box does not clip them, as in Figma,
|
|
6
6
|
* and the renderer starts them at its top.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overflow.js","names":[],"sources":["../../src/text/overflow.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"overflow.js","names":[],"sources":["../../src/text/overflow.ts"],"sourcesContent":["import type { SceneNode } from '../types'\n\ntype TextBoundsNode = Pick<SceneNode, 'type' | 'height' | 'derivedTextHeight'>\n\n/**\n * How far a text's lines reach below its box: a fixed-size box does not clip them, as in Figma,\n * and the renderer starts them at its top.\n */\nexport function textLinesOverflow(node: TextBoundsNode): number {\n if (node.type !== 'TEXT' || !node.derivedTextHeight) return 0\n return Math.max(0, node.derivedTextHeight - node.height)\n}\n"],"mappings":";;;;;AAQA,SAAgB,kBAAkB,MAA8B;CAC9D,IAAI,KAAK,SAAS,UAAU,CAAC,KAAK,mBAAmB,OAAO;CAC5D,OAAO,KAAK,IAAI,GAAG,KAAK,oBAAoB,KAAK,MAAM;AACzD"}
|
package/dist/text/picture.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ declare const GLYPH_AFFECTING_KEYS: ReadonlySet<string>;
|
|
|
12
12
|
* replaces them in the same update (resize supplies scaled copies).
|
|
13
13
|
*/
|
|
14
14
|
declare function textCacheInvalidationChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode>;
|
|
15
|
-
declare function invalidateTextCaches(node: SceneNode, changes: Partial<SceneNode>): void;
|
|
16
15
|
//#endregion
|
|
17
|
-
export { GLYPH_AFFECTING_KEYS, TEXT_PICTURE_KEYS,
|
|
16
|
+
export { GLYPH_AFFECTING_KEYS, TEXT_PICTURE_KEYS, textCacheInvalidationChanges };
|
|
18
17
|
//# sourceMappingURL=picture.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picture.d.ts","names":[],"sources":["../../src/text/picture.ts"],"mappings":";;;;;;cASa,mBAAmB;cAQnB,sBAAsB;;;;;;iBAOnB,6BACd,MAAM,WACN,SAAS,QAAQ,aAChB,QAAQ
|
|
1
|
+
{"version":3,"file":"picture.d.ts","names":[],"sources":["../../src/text/picture.ts"],"mappings":";;;;;;cASa,mBAAmB;cAQnB,sBAAsB;;;;;;iBAOnB,6BACd,MAAM,WACN,SAAS,QAAQ,aAChB,QAAQ"}
|
package/dist/text/picture.js
CHANGED
|
@@ -32,10 +32,7 @@ function textCacheInvalidationChanges(node, changes) {
|
|
|
32
32
|
}
|
|
33
33
|
return invalidated;
|
|
34
34
|
}
|
|
35
|
-
function invalidateTextCaches(node, changes) {
|
|
36
|
-
Object.assign(node, textCacheInvalidationChanges(node, changes));
|
|
37
|
-
}
|
|
38
35
|
//#endregion
|
|
39
|
-
export { GLYPH_AFFECTING_KEYS, TEXT_PICTURE_KEYS,
|
|
36
|
+
export { GLYPH_AFFECTING_KEYS, TEXT_PICTURE_KEYS, textCacheInvalidationChanges };
|
|
40
37
|
|
|
41
38
|
//# sourceMappingURL=picture.js.map
|
package/dist/text/picture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picture.js","names":[],"sources":["../../src/text/picture.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport { TEXT_SHAPING_FIELDS, TEXT_LAYOUT_FIELDS } from '../fields/text'\nimport type { SceneNode } from '../types'\n\n/**\n * Invalidate cached Skia textPicture (Paragraph snapshot). Includes width/height\n * because wrapping/layout depends on the box.\n */\nexport const TEXT_PICTURE_KEYS: ReadonlySet<string> = new Set([\n ...TEXT_SHAPING_FIELDS,\n 'textDecoration',\n 'fills',\n 'width',\n 'height'\n])\n\nexport const GLYPH_AFFECTING_KEYS: ReadonlySet<string> = new Set(TEXT_SHAPING_FIELDS)\n\n/**\n * Shared by SceneGraph.updateNode and updateNodePreview (drag hot path) so the\n * two invalidation rules cannot drift. Glyphs are kept when the caller\n * replaces them in the same update (resize supplies scaled copies).\n */\nexport function textCacheInvalidationChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const invalidated: Partial<SceneNode> = {}\n const keys = Object.keys(changes).filter(\n (key) => !isEqual(node[key as keyof SceneNode], changes[key as keyof SceneNode])\n )\n if (node.textPicture && keys.some((key) => TEXT_PICTURE_KEYS.has(key)))\n invalidated.textPicture = null\n const glyphsInvalidated =\n keys.some((key) => GLYPH_AFFECTING_KEYS.has(key)) ||\n TEXT_LAYOUT_FIELDS.some((key) => keys.includes(key))\n if (glyphsInvalidated && !('derivedLayout' in changes)) invalidated.derivedLayout = null\n // A successful path-text edit supplies reflowed glyphs in `changes`. Every\n // other mutation path must drop stale baked glyphs and path identity rather\n // than pair new text/style with old visible outlines.\n if (node.derivedTextGlyphs && glyphsInvalidated && !changes.derivedTextGlyphs) {\n // Path-text resize supplies transformed glyphs through the resize workflow. A raw box\n // preview keeps them until that workflow commits or an actual shaping edit occurs.\n const onlyPathBoxResize =\n !!node.textPathData && keys.every((key) => key === 'width' || key === 'height')\n if (!onlyPathBoxResize) {\n invalidated.derivedTextGlyphs = null\n invalidated.textPathData = null\n }\n }\n return invalidated\n}\n
|
|
1
|
+
{"version":3,"file":"picture.js","names":[],"sources":["../../src/text/picture.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport { TEXT_SHAPING_FIELDS, TEXT_LAYOUT_FIELDS } from '../fields/text'\nimport type { SceneNode } from '../types'\n\n/**\n * Invalidate cached Skia textPicture (Paragraph snapshot). Includes width/height\n * because wrapping/layout depends on the box.\n */\nexport const TEXT_PICTURE_KEYS: ReadonlySet<string> = new Set([\n ...TEXT_SHAPING_FIELDS,\n 'textDecoration',\n 'fills',\n 'width',\n 'height'\n])\n\nexport const GLYPH_AFFECTING_KEYS: ReadonlySet<string> = new Set(TEXT_SHAPING_FIELDS)\n\n/**\n * Shared by SceneGraph.updateNode and updateNodePreview (drag hot path) so the\n * two invalidation rules cannot drift. Glyphs are kept when the caller\n * replaces them in the same update (resize supplies scaled copies).\n */\nexport function textCacheInvalidationChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const invalidated: Partial<SceneNode> = {}\n const keys = Object.keys(changes).filter(\n (key) => !isEqual(node[key as keyof SceneNode], changes[key as keyof SceneNode])\n )\n if (node.textPicture && keys.some((key) => TEXT_PICTURE_KEYS.has(key)))\n invalidated.textPicture = null\n const glyphsInvalidated =\n keys.some((key) => GLYPH_AFFECTING_KEYS.has(key)) ||\n TEXT_LAYOUT_FIELDS.some((key) => keys.includes(key))\n if (glyphsInvalidated && !('derivedLayout' in changes)) invalidated.derivedLayout = null\n // A successful path-text edit supplies reflowed glyphs in `changes`. Every\n // other mutation path must drop stale baked glyphs and path identity rather\n // than pair new text/style with old visible outlines.\n if (node.derivedTextGlyphs && glyphsInvalidated && !changes.derivedTextGlyphs) {\n // Path-text resize supplies transformed glyphs through the resize workflow. A raw box\n // preview keeps them until that workflow commits or an actual shaping edit occurs.\n const onlyPathBoxResize =\n !!node.textPathData && keys.every((key) => key === 'width' || key === 'height')\n if (!onlyPathBoxResize) {\n invalidated.derivedTextGlyphs = null\n invalidated.textPathData = null\n }\n }\n return invalidated\n}\n"],"mappings":";;;;;;;AASA,MAAa,oCAAyC,IAAI,IAAI;CAC5D,GAAG;CACH;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,uBAA4C,IAAI,IAAI,mBAAmB;;;;;;AAOpF,SAAgB,6BACd,MACA,SACoB;CACpB,MAAM,cAAkC,CAAC;CACzC,MAAM,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,QAC/B,QAAQ,CAAC,QAAQ,KAAK,MAAyB,QAAQ,IAAuB,CACjF;CACA,IAAI,KAAK,eAAe,KAAK,MAAM,QAAQ,kBAAkB,IAAI,GAAG,CAAC,GACnE,YAAY,cAAc;CAC5B,MAAM,oBACJ,KAAK,MAAM,QAAQ,qBAAqB,IAAI,GAAG,CAAC,KAChD,mBAAmB,MAAM,QAAQ,KAAK,SAAS,GAAG,CAAC;CACrD,IAAI,qBAAqB,EAAE,mBAAmB,UAAU,YAAY,gBAAgB;CAIpF,IAAI,KAAK,qBAAqB,qBAAqB,CAAC,QAAQ,mBAKtD;MAAA,EADF,CAAC,CAAC,KAAK,gBAAgB,KAAK,OAAO,QAAQ,QAAQ,WAAW,QAAQ,QAAQ,IACxD;GACtB,YAAY,oBAAoB;GAChC,YAAY,eAAe;EAC7B;;CAEF,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../src/transfer/apply.ts"],"mappings":";;;KAQY,oBAAoB,kBAAkB;;
|
|
1
|
+
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../src/transfer/apply.ts"],"mappings":";;;KAQY,oBAAoB,kBAAkB;;iBA0ClC,mBAAmB,QAAQ,YAAY,OAAO"}
|
package/dist/transfer/apply.js
CHANGED
|
@@ -15,7 +15,6 @@ function validate(target, plan) {
|
|
|
15
15
|
reserved.add(id);
|
|
16
16
|
};
|
|
17
17
|
prepareVariableTransfer(plan.variables, plan.collections, variableIdentityReferences(plan.variables, plan.collections));
|
|
18
|
-
for (const [id, mode] of plan.activeModes) if (!plan.collections.find((collection) => collection.id === id)?.modes.some((entry) => entry.modeId === mode)) throw new Error(`Invalid transferred active mode ${id}:${mode}`);
|
|
19
18
|
for (const collection of plan.collections) claim(collection.id);
|
|
20
19
|
for (const variable of plan.variables) claim(variable.id);
|
|
21
20
|
const parents = new Set(target.nodes.keys());
|
|
@@ -41,7 +40,6 @@ function applyGraphTransfer(target, input) {
|
|
|
41
40
|
try {
|
|
42
41
|
for (const collection of plan.collections) target.addCollection(collection);
|
|
43
42
|
for (const variable of plan.variables) target.addVariable(variable);
|
|
44
|
-
for (const [id, mode] of plan.activeModes) target.activeMode.set(id, mode);
|
|
45
43
|
for (const [hash, bytes] of plan.images) if (!target.images.has(hash)) target.images.set(hash, bytes);
|
|
46
44
|
for (const node of plan.nodes) target.createNodeWithId(node.id, node.type, node.parentId, {
|
|
47
45
|
...node.props,
|
|
@@ -50,10 +48,7 @@ function applyGraphTransfer(target, input) {
|
|
|
50
48
|
} catch (error) {
|
|
51
49
|
for (const node of plan.nodes.toReversed()) if (target.getNode(node.id)) target.deleteNode(node.id);
|
|
52
50
|
for (const variable of plan.variables) target.variables.delete(variable.id);
|
|
53
|
-
for (const collection of plan.collections)
|
|
54
|
-
target.variableCollections.delete(collection.id);
|
|
55
|
-
target.activeMode.delete(collection.id);
|
|
56
|
-
}
|
|
51
|
+
for (const collection of plan.collections) target.variableCollections.delete(collection.id);
|
|
57
52
|
for (const hash of imageIds) target.images.delete(hash);
|
|
58
53
|
throw error;
|
|
59
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","names":[],"sources":["../../src/transfer/apply.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { SceneGraph } from '../graph'\nimport { variableIdentityReferences } from './identity'\nimport type { prepareGraphTransfer } from './plan'\nimport { validateTransferReferences } from './validation'\nimport { prepareVariableTransfer } from './variables'\n\nexport type GraphTransferPlan = ReturnType<typeof prepareGraphTransfer>\n\nfunction validate(target: SceneGraph, plan: GraphTransferPlan): void {\n validateTransferReferences(target, plan)\n const reserved = new Set([\n ...target.nodes.keys(),\n ...target.variables.keys(),\n ...target.variableCollections.keys()\n ])\n const claim = (id: string): void => {\n if (reserved.has(id)) throw new Error(`Transfer identity collision ${id}`)\n reserved.add(id)\n }\n prepareVariableTransfer(\n plan.variables,\n plan.collections,\n variableIdentityReferences(plan.variables, plan.collections)\n )\n for (const
|
|
1
|
+
{"version":3,"file":"apply.js","names":[],"sources":["../../src/transfer/apply.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { SceneGraph } from '../graph'\nimport { variableIdentityReferences } from './identity'\nimport type { prepareGraphTransfer } from './plan'\nimport { validateTransferReferences } from './validation'\nimport { prepareVariableTransfer } from './variables'\n\nexport type GraphTransferPlan = ReturnType<typeof prepareGraphTransfer>\n\nfunction validate(target: SceneGraph, plan: GraphTransferPlan): void {\n validateTransferReferences(target, plan)\n const reserved = new Set([\n ...target.nodes.keys(),\n ...target.variables.keys(),\n ...target.variableCollections.keys()\n ])\n const claim = (id: string): void => {\n if (reserved.has(id)) throw new Error(`Transfer identity collision ${id}`)\n reserved.add(id)\n }\n prepareVariableTransfer(\n plan.variables,\n plan.collections,\n variableIdentityReferences(plan.variables, plan.collections)\n )\n for (const collection of plan.collections) claim(collection.id)\n for (const variable of plan.variables) claim(variable.id)\n const parents = new Set(target.nodes.keys())\n for (const node of plan.nodes) {\n claim(node.id)\n if ('id' in node.props || 'parentId' in node.props || 'childIds' in node.props)\n throw new Error('Transfer props cannot override hierarchy identity')\n if (!parents.has(node.parentId)) throw new Error(`Missing transfer parent ${node.parentId}`)\n parents.add(node.id)\n }\n for (const id of [...plan.rootIds, ...plan.dependencyPageIds]) {\n if (!plan.nodes.some((node) => node.id === id)) throw new Error(`Missing transfer root ${id}`)\n }\n for (const node of plan.nodes) {\n if (node.props.componentId && !parents.has(node.props.componentId))\n throw new Error(`Missing transfer component ${node.props.componentId}`)\n }\n for (const [hash, bytes] of plan.images) {\n const existing = target.images.get(hash)\n if (existing && !isEqual(existing, bytes)) throw new Error(`Transfer image collision ${hash}`)\n }\n}\n\n/** Revalidate at insertion time. Event-delivery failures after commit are not rollback failures. */\nexport function applyGraphTransfer(target: SceneGraph, input: GraphTransferPlan): void {\n const plan = structuredClone(input)\n validate(target, plan)\n const imageIds = [...plan.images.keys()].filter((hash) => !target.images.has(hash))\n target.withBufferedEvents(() => {\n try {\n for (const collection of plan.collections) target.addCollection(collection)\n for (const variable of plan.variables) target.addVariable(variable)\n for (const [hash, bytes] of plan.images)\n if (!target.images.has(hash)) target.images.set(hash, bytes)\n for (const node of plan.nodes)\n target.createNodeWithId(node.id, node.type, node.parentId, { ...node.props, childIds: [] })\n } catch (error) {\n for (const node of plan.nodes.toReversed())\n if (target.getNode(node.id)) target.deleteNode(node.id)\n for (const variable of plan.variables) target.variables.delete(variable.id)\n for (const collection of plan.collections) target.variableCollections.delete(collection.id)\n for (const hash of imageIds) target.images.delete(hash)\n throw error\n }\n })\n}\n"],"mappings":";;;;;AAUA,SAAS,SAAS,QAAoB,MAA+B;CACnE,2BAA2B,QAAQ,IAAI;CACvC,MAAM,2BAAW,IAAI,IAAI;EACvB,GAAG,OAAO,MAAM,KAAK;EACrB,GAAG,OAAO,UAAU,KAAK;EACzB,GAAG,OAAO,oBAAoB,KAAK;CACrC,CAAC;CACD,MAAM,SAAS,OAAqB;EAClC,IAAI,SAAS,IAAI,EAAE,GAAG,MAAM,IAAI,MAAM,+BAA+B,IAAI;EACzE,SAAS,IAAI,EAAE;CACjB;CACA,wBACE,KAAK,WACL,KAAK,aACL,2BAA2B,KAAK,WAAW,KAAK,WAAW,CAC7D;CACA,KAAK,MAAM,cAAc,KAAK,aAAa,MAAM,WAAW,EAAE;CAC9D,KAAK,MAAM,YAAY,KAAK,WAAW,MAAM,SAAS,EAAE;CACxD,MAAM,UAAU,IAAI,IAAI,OAAO,MAAM,KAAK,CAAC;CAC3C,KAAK,MAAM,QAAQ,KAAK,OAAO;EAC7B,MAAM,KAAK,EAAE;EACb,IAAI,QAAQ,KAAK,SAAS,cAAc,KAAK,SAAS,cAAc,KAAK,OACvE,MAAM,IAAI,MAAM,mDAAmD;EACrE,IAAI,CAAC,QAAQ,IAAI,KAAK,QAAQ,GAAG,MAAM,IAAI,MAAM,2BAA2B,KAAK,UAAU;EAC3F,QAAQ,IAAI,KAAK,EAAE;CACrB;CACA,KAAK,MAAM,MAAM,CAAC,GAAG,K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