@pairdraw/core 0.21.1 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/boolean.d.ts +6 -1
- package/dist/canvas/boolean.d.ts.map +1 -1
- package/dist/canvas/boolean.js +10 -2
- package/dist/canvas/boolean.js.map +1 -1
- package/dist/canvas/color-space.d.ts +45 -0
- package/dist/canvas/color-space.d.ts.map +1 -0
- package/dist/canvas/color-space.js +39 -0
- package/dist/canvas/color-space.js.map +1 -0
- package/dist/canvas/fills.d.ts +10 -10
- package/dist/canvas/fills.d.ts.map +1 -1
- package/dist/canvas/fills.js +116 -62
- package/dist/canvas/fills.js.map +1 -1
- package/dist/canvas/flatten.d.ts +11 -3
- package/dist/canvas/flatten.d.ts.map +1 -1
- package/dist/canvas/flatten.js +62 -4
- package/dist/canvas/flatten.js.map +1 -1
- package/dist/canvas/index.d.ts +2 -1
- package/dist/canvas/index.js +2 -1
- package/dist/canvas/layout-grids.d.ts +5 -2
- package/dist/canvas/layout-grids.d.ts.map +1 -1
- package/dist/canvas/layout-grids.js +7 -2
- package/dist/canvas/layout-grids.js.map +1 -1
- package/dist/canvas/noise/render.d.ts +17 -4
- package/dist/canvas/noise/render.d.ts.map +1 -1
- package/dist/canvas/noise/render.js +21 -6
- package/dist/canvas/noise/render.js.map +1 -1
- package/dist/canvas/noise/shader.d.ts +4 -4
- package/dist/canvas/noise/shader.d.ts.map +1 -1
- package/dist/canvas/noise/shader.js +5 -6
- package/dist/canvas/noise/shader.js.map +1 -1
- package/dist/canvas/overlays/annotations.d.ts +19 -0
- package/dist/canvas/overlays/annotations.d.ts.map +1 -0
- package/dist/canvas/overlays/annotations.js +110 -0
- package/dist/canvas/overlays/annotations.js.map +1 -0
- package/dist/canvas/overlays/auto-layout-hover.d.ts +11 -1
- package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
- package/dist/canvas/overlays/auto-layout-hover.js +25 -1
- package/dist/canvas/overlays/auto-layout-hover.js.map +1 -1
- package/dist/canvas/overlays/feedback.js +1 -1
- package/dist/canvas/overlays/feedback.js.map +1 -1
- package/dist/canvas/overlays/index.d.ts +2 -2
- package/dist/canvas/overlays/index.js +2 -2
- package/dist/canvas/overlays/measurement.d.ts +7 -1
- package/dist/canvas/overlays/measurement.d.ts.map +1 -1
- package/dist/canvas/overlays/measurement.js +42 -4
- package/dist/canvas/overlays/measurement.js.map +1 -1
- package/dist/canvas/overlays/presence.d.ts.map +1 -1
- package/dist/canvas/overlays/presence.js +21 -24
- package/dist/canvas/overlays/presence.js.map +1 -1
- package/dist/canvas/renderer/colors.d.ts +7 -1
- package/dist/canvas/renderer/colors.d.ts.map +1 -1
- package/dist/canvas/renderer/colors.js +9 -1
- package/dist/canvas/renderer/colors.js.map +1 -1
- package/dist/canvas/renderer/document-surface.d.ts +15 -6
- package/dist/canvas/renderer/document-surface.d.ts.map +1 -1
- package/dist/canvas/renderer/document-surface.js +1 -0
- package/dist/canvas/renderer/document-surface.js.map +1 -1
- package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +2 -2
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts +1 -0
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +4 -1
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
- package/dist/canvas/renderer/overlay-pass.js +6 -1
- package/dist/canvas/renderer/overlay-pass.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +7 -0
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/types.d.ts +10 -0
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer.d.ts +10 -2
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +15 -3
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +9 -9
- package/dist/canvas/scene.js.map +1 -1
- package/dist/clipboard/pairdraw.d.ts.map +1 -1
- package/dist/clipboard/pairdraw.js +1 -0
- package/dist/clipboard/pairdraw.js.map +1 -1
- package/dist/editor/bridges/clipboard.d.ts +2 -0
- package/dist/editor/bridges/clipboard.d.ts.map +1 -1
- package/dist/editor/bridges/clipboard.js +1 -0
- package/dist/editor/bridges/clipboard.js.map +1 -1
- package/dist/editor/bridges/components.d.ts +14 -7
- package/dist/editor/bridges/components.d.ts.map +1 -1
- package/dist/editor/bridges/components.js +6 -0
- package/dist/editor/bridges/components.js.map +1 -1
- package/dist/editor/bridges/structure.d.ts +1 -1
- package/dist/editor/bridges/structure.d.ts.map +1 -1
- package/dist/editor/clipboard/code.d.ts +32 -0
- package/dist/editor/clipboard/code.d.ts.map +1 -0
- package/dist/editor/clipboard/code.js +30 -0
- package/dist/editor/clipboard/code.js.map +1 -0
- package/dist/editor/clipboard/paste/dependencies.d.ts +14 -0
- package/dist/editor/clipboard/paste/dependencies.d.ts.map +1 -0
- package/dist/editor/clipboard/paste/dependencies.js +0 -0
- package/dist/editor/clipboard/paste/run.d.ts +14 -0
- package/dist/editor/clipboard/paste/run.d.ts.map +1 -0
- package/dist/editor/clipboard/paste/run.js +47 -0
- package/dist/editor/clipboard/paste/run.js.map +1 -0
- package/dist/editor/clipboard/styled.d.ts +2 -8
- package/dist/editor/clipboard/styled.d.ts.map +1 -1
- package/dist/editor/clipboard/styled.js +2 -32
- package/dist/editor/clipboard/styled.js.map +1 -1
- package/dist/editor/clipboard.d.ts +2 -0
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +34 -0
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/components/instances.d.ts +5 -0
- package/dist/editor/components/instances.d.ts.map +1 -1
- package/dist/editor/components/instances.js +69 -4
- package/dist/editor/components/instances.js.map +1 -1
- package/dist/editor/components/slots/index.d.ts.map +1 -1
- package/dist/editor/components/slots/index.js +7 -0
- package/dist/editor/components/slots/index.js.map +1 -1
- package/dist/editor/components.d.ts +6 -0
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor/components.js +14 -2
- package/dist/editor/components.js.map +1 -1
- package/dist/editor/create.d.ts +29 -2
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +11 -2
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/design-tokens.d.ts +1 -1
- package/dist/editor/design-tokens.d.ts.map +1 -1
- package/dist/editor/design-tokens.js +4 -18
- package/dist/editor/design-tokens.js.map +1 -1
- package/dist/editor/image-edit.d.ts.map +1 -1
- package/dist/editor/image-edit.js +1 -2
- package/dist/editor/image-edit.js.map +1 -1
- package/dist/editor/index.d.ts +4 -4
- package/dist/editor/index.js +1 -1
- package/dist/editor/layout-mode.d.ts +3 -1
- package/dist/editor/layout-mode.d.ts.map +1 -1
- package/dist/editor/layout-mode.js +97 -2
- package/dist/editor/layout-mode.js.map +1 -1
- package/dist/editor/nodes.d.ts +2 -0
- package/dist/editor/nodes.d.ts.map +1 -1
- package/dist/editor/nodes.js +22 -7
- package/dist/editor/nodes.js.map +1 -1
- package/dist/editor/read-only/actions.js +6 -0
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/selection/overlays.d.ts +1 -0
- package/dist/editor/selection/overlays.d.ts.map +1 -1
- package/dist/editor/selection/overlays.js +7 -0
- package/dist/editor/selection/overlays.js.map +1 -1
- package/dist/editor/selection/read.d.ts +8 -0
- package/dist/editor/selection.d.ts +9 -0
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/state/shared.js +1 -0
- package/dist/editor/state/shared.js.map +1 -1
- package/dist/editor/state/view.d.ts.map +1 -1
- package/dist/editor/state/view.js +2 -0
- package/dist/editor/state/view.js.map +1 -1
- package/dist/editor/structure/boolean.d.ts +1 -1
- package/dist/editor/structure/boolean.d.ts.map +1 -1
- package/dist/editor/structure/boolean.js +20 -1
- package/dist/editor/structure/boolean.js.map +1 -1
- package/dist/editor/structure/container-wrap.d.ts +8 -2
- package/dist/editor/structure/container-wrap.d.ts.map +1 -1
- package/dist/editor/structure/container-wrap.js +17 -5
- package/dist/editor/structure/container-wrap.js.map +1 -1
- package/dist/editor/structure/flatten.d.ts.map +1 -1
- package/dist/editor/structure/flatten.js +8 -7
- package/dist/editor/structure/flatten.js.map +1 -1
- package/dist/editor/structure/group/ungroup.d.ts.map +1 -1
- package/dist/editor/structure/group/ungroup.js +2 -0
- package/dist/editor/structure/group/ungroup.js.map +1 -1
- package/dist/editor/structure/outline-stroke.d.ts.map +1 -1
- package/dist/editor/structure/outline-stroke.js +5 -0
- package/dist/editor/structure/outline-stroke.js.map +1 -1
- package/dist/editor/structure.d.ts +1 -1
- package/dist/editor/structure.d.ts.map +1 -1
- package/dist/editor/styles.d.ts +26 -0
- package/dist/editor/styles.d.ts.map +1 -0
- package/dist/editor/styles.js +127 -0
- package/dist/editor/styles.js.map +1 -0
- package/dist/editor/text/selection-style.d.ts +1 -0
- package/dist/editor/text/selection-style.d.ts.map +1 -1
- package/dist/editor/text/selection-style.js +10 -2
- package/dist/editor/text/selection-style.js.map +1 -1
- package/dist/editor/tool-registry.d.ts.map +1 -1
- package/dist/editor/tool-registry.js +6 -0
- package/dist/editor/tool-registry.js.map +1 -1
- package/dist/editor/types.d.ts +14 -2
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/variable-bindings.d.ts.map +1 -1
- package/dist/editor/variable-bindings.js +6 -1
- package/dist/editor/variable-bindings.js.map +1 -1
- package/dist/figma-api/accessors/basic.d.ts.map +1 -1
- package/dist/figma-api/accessors/basic.js +22 -1
- package/dist/figma-api/accessors/basic.js.map +1 -1
- package/dist/figma-api/accessors/shape.js +1 -1
- package/dist/figma-api/accessors/text/index.js +1 -1
- package/dist/figma-api/accessors/text/ranges.js +1 -1
- package/dist/figma-api/accessors/text/references.js +1 -1
- package/dist/figma-api/accessors/variables.js +1 -1
- package/dist/figma-api/accessors/vector.d.ts.map +1 -1
- package/dist/figma-api/accessors/vector.js +8 -22
- package/dist/figma-api/accessors/vector.js.map +1 -1
- package/dist/figma-api/accessors/visual.js +1 -1
- package/dist/figma-api/compatibility.d.ts +1 -1
- package/dist/figma-api/compatibility.d.ts.map +1 -1
- package/dist/figma-api/component-scope.d.ts +14 -0
- package/dist/figma-api/component-scope.d.ts.map +1 -0
- package/dist/figma-api/component-scope.js +28 -0
- package/dist/figma-api/component-scope.js.map +1 -0
- package/dist/figma-api/components.d.ts.map +1 -1
- package/dist/figma-api/components.js +26 -2
- package/dist/figma-api/components.js.map +1 -1
- package/dist/figma-api/flatten.js +3 -3
- package/dist/figma-api/flatten.js.map +1 -1
- package/dist/figma-api/index.d.ts +77 -6
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +188 -2
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/node-types.d.ts +2 -1
- package/dist/figma-api/node-types.d.ts.map +1 -1
- package/dist/figma-api/overrides.d.ts +26 -1
- package/dist/figma-api/overrides.d.ts.map +1 -1
- package/dist/figma-api/overrides.js +157 -10
- package/dist/figma-api/overrides.js.map +1 -1
- package/dist/figma-api/proxy.d.ts +2 -0
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +10 -2
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +61 -5
- package/dist/figma-api/reactions.d.ts.map +1 -1
- package/dist/figma-api/reactions.js +144 -11
- package/dist/figma-api/reactions.js.map +1 -1
- package/dist/figma-api/shape-with-text.js +1 -1
- package/dist/figma-api/slots.d.ts +3 -1
- package/dist/figma-api/slots.d.ts.map +1 -1
- package/dist/figma-api/slots.js +9 -8
- package/dist/figma-api/slots.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/io/formats/code/detect.d.ts +23 -0
- package/dist/io/formats/code/detect.d.ts.map +1 -0
- package/dist/io/formats/code/detect.js +46 -0
- package/dist/io/formats/code/detect.js.map +1 -0
- package/dist/io/formats/code/index.d.ts +5 -0
- package/dist/io/formats/code/index.js +5 -0
- package/dist/io/formats/code/read.d.ts +45 -0
- package/dist/io/formats/code/read.d.ts.map +1 -0
- package/dist/io/formats/code/read.js +86 -0
- package/dist/io/formats/code/read.js.map +1 -0
- package/dist/io/formats/code/stylesheet.d.ts +13 -0
- package/dist/io/formats/code/stylesheet.d.ts.map +1 -0
- package/dist/io/formats/code/stylesheet.js +21 -0
- package/dist/io/formats/code/stylesheet.js.map +1 -0
- package/dist/io/formats/code/tokens.d.ts +18 -0
- package/dist/io/formats/code/tokens.d.ts.map +1 -0
- package/dist/io/formats/code/tokens.js +135 -0
- package/dist/io/formats/code/tokens.js.map +1 -0
- package/dist/io/formats/design-tokens/apply.d.ts +7 -3
- package/dist/io/formats/design-tokens/apply.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/apply.js.map +1 -1
- package/dist/io/formats/fig/export/patch/fields.js +5 -0
- package/dist/io/formats/fig/export/patch/fields.js.map +1 -1
- package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/patch/index.js +20 -20
- package/dist/io/formats/fig/export/patch/index.js.map +1 -1
- package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
- package/dist/io/formats/fig/export/setup.js +5 -1
- package/dist/io/formats/fig/export/setup.js.map +1 -1
- package/dist/io/formats/fig/index.d.ts +3 -2
- package/dist/io/formats/fig/index.js +2 -2
- package/dist/io/formats/fig/read.d.ts.map +1 -1
- package/dist/io/formats/fig/read.js +5 -2
- package/dist/io/formats/fig/read.js.map +1 -1
- package/dist/io/formats/html/layers.d.ts +3 -1
- package/dist/io/formats/html/layers.d.ts.map +1 -1
- package/dist/io/formats/html/layers.js +6 -1
- package/dist/io/formats/html/layers.js.map +1 -1
- package/dist/io/formats/pdf/export.d.ts.map +1 -1
- package/dist/io/formats/pdf/export.js +7 -3
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/pdf/plan.d.ts +3 -0
- package/dist/io/formats/pdf/plan.d.ts.map +1 -1
- package/dist/io/formats/pdf/plan.js +60 -36
- package/dist/io/formats/pdf/plan.js.map +1 -1
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +3 -2
- package/dist/io/formats/raster/headless.js.map +1 -1
- package/dist/io/formats/raster/index.d.ts +2 -2
- package/dist/io/formats/raster/index.js +2 -2
- package/dist/io/formats/raster/render.d.ts +10 -2
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +35 -9
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +19 -1
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts +5 -2
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +59 -10
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/index.d.ts +2 -2
- package/dist/io/formats/svg/index.js +2 -2
- package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
- package/dist/io/formats/svg/text/layout.js +4 -2
- package/dist/io/formats/svg/text/layout.js.map +1 -1
- package/dist/io/formats/video/record.d.ts.map +1 -1
- package/dist/io/formats/video/record.js +24 -9
- package/dist/io/formats/video/record.js.map +1 -1
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +20 -13
- package/dist/io/formats.js.map +1 -1
- package/dist/kiwi/fig/population/client.d.ts.map +1 -1
- package/dist/kiwi/fig/population/client.js +2 -1
- package/dist/kiwi/fig/population/client.js.map +1 -1
- package/dist/kiwi/fig/session/document-state.d.ts +46 -2
- package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
- package/dist/kiwi/fig/session/document-state.js +113 -5
- package/dist/kiwi/fig/session/document-state.js.map +1 -1
- package/dist/kiwi/fig/session/options.d.ts +4 -0
- package/dist/kiwi/fig/session/options.d.ts.map +1 -1
- package/dist/kiwi/fig/session/options.js.map +1 -1
- package/dist/layout/apply.d.ts.map +1 -1
- package/dist/layout/apply.js +8 -4
- package/dist/layout/apply.js.map +1 -1
- package/dist/layout/auto-layout-handles.js +1 -1
- package/dist/layout/auto-layout-handles.js.map +1 -1
- package/dist/layout/axis-sizing.d.ts.map +1 -1
- package/dist/layout/axis-sizing.js +1 -1
- package/dist/layout/axis-sizing.js.map +1 -1
- package/dist/layout/derived.d.ts.map +1 -1
- package/dist/layout/derived.js +1 -1
- package/dist/layout/derived.js.map +1 -1
- package/dist/layout/effective-generated-text.js +1 -1
- package/dist/layout/effective-generated-text.js.map +1 -1
- package/dist/layout/grid.d.ts +3 -1
- package/dist/layout/grid.d.ts.map +1 -1
- package/dist/layout/grid.js +57 -16
- package/dist/layout/grid.js.map +1 -1
- package/dist/layout.d.ts +1 -1
- package/dist/layout.js +6 -5
- package/dist/layout.js.map +1 -1
- package/dist/node/fs.d.ts.map +1 -1
- package/dist/node/fs.js +28 -7
- package/dist/node/fs.js.map +1 -1
- package/dist/prototype/easing.d.ts +13 -5
- package/dist/prototype/easing.d.ts.map +1 -1
- package/dist/prototype/easing.js +46 -6
- package/dist/prototype/easing.js.map +1 -1
- package/dist/prototype/scenes.d.ts +31 -0
- package/dist/prototype/scenes.d.ts.map +1 -1
- package/dist/prototype/scenes.js +220 -31
- package/dist/prototype/scenes.js.map +1 -1
- package/dist/prototype/session.d.ts.map +1 -1
- package/dist/prototype/session.js +1 -0
- package/dist/prototype/session.js.map +1 -1
- package/dist/prototype/smart-animate/animation.d.ts +2 -1
- package/dist/prototype/smart-animate/animation.d.ts.map +1 -1
- package/dist/prototype/smart-animate/animation.js +2 -2
- package/dist/prototype/smart-animate/animation.js.map +1 -1
- package/dist/prototype/timeline.d.ts +10 -1
- package/dist/prototype/timeline.d.ts.map +1 -1
- package/dist/prototype/timeline.js +69 -23
- package/dist/prototype/timeline.js.map +1 -1
- package/dist/prototype/variables.d.ts +23 -0
- package/dist/prototype/variables.d.ts.map +1 -0
- package/dist/prototype/variables.js +237 -0
- package/dist/prototype/variables.js.map +1 -0
- package/dist/rpc/read-commands.d.ts +5 -0
- package/dist/rpc/read-commands.d.ts.map +1 -1
- package/dist/rpc/read-commands.js +4 -1
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/text/character-style.d.ts +8 -1
- package/dist/text/character-style.d.ts.map +1 -1
- package/dist/text/character-style.js +39 -1
- package/dist/text/character-style.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +2 -2
- package/dist/tools/create/basic.js +3 -4
- package/dist/tools/create/basic.js.map +1 -1
- package/dist/tools/create/behaviours.js +1 -1
- package/dist/tools/create/code.d.ts +6 -0
- package/dist/tools/create/code.d.ts.map +1 -0
- package/dist/tools/create/code.js +68 -0
- package/dist/tools/create/code.js.map +1 -0
- package/dist/tools/create/html.d.ts.map +1 -1
- package/dist/tools/create/html.js +9 -57
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.js +1 -1
- package/dist/tools/create/inputs.d.ts +11 -0
- package/dist/tools/create/inputs.d.ts.map +1 -0
- package/dist/tools/create/inputs.js +15 -0
- package/dist/tools/create/inputs.js.map +1 -0
- package/dist/tools/create/mermaid.d.ts.map +1 -1
- package/dist/tools/create/mermaid.js +5 -6
- package/dist/tools/create/mermaid.js.map +1 -1
- package/dist/tools/create/place.d.ts +30 -0
- package/dist/tools/create/place.d.ts.map +1 -0
- package/dist/tools/create/place.js +70 -0
- package/dist/tools/create/place.js.map +1 -0
- package/dist/tools/create/render.js +1 -1
- package/dist/tools/create/svg.js +1 -1
- package/dist/tools/create/vector.js +1 -1
- package/dist/tools/create.d.ts +2 -1
- package/dist/tools/create.js +2 -1
- package/dist/tools/css/gradient.d.ts +28 -0
- package/dist/tools/css/gradient.d.ts.map +1 -0
- package/dist/tools/css/gradient.js +118 -0
- package/dist/tools/css/gradient.js.map +1 -0
- package/dist/tools/image-ai/generate.js +1 -1
- package/dist/tools/modify/geometry.js +5 -5
- package/dist/tools/modify/geometry.js.map +1 -1
- package/dist/tools/modify/layout.d.ts.map +1 -1
- package/dist/tools/modify/layout.js +7 -1
- package/dist/tools/modify/layout.js.map +1 -1
- package/dist/tools/modify/matching.js +1 -1
- package/dist/tools/modify/overrides.d.ts +6 -0
- package/dist/tools/modify/overrides.d.ts.map +1 -0
- package/dist/tools/modify/overrides.js +27 -0
- package/dist/tools/modify/overrides.js.map +1 -0
- package/dist/tools/modify/paint.d.ts.map +1 -1
- package/dist/tools/modify/paint.js +84 -39
- package/dist/tools/modify/paint.js.map +1 -1
- package/dist/tools/modify/text.d.ts +2 -1
- package/dist/tools/modify/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +79 -8
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/modify/update.d.ts.map +1 -1
- package/dist/tools/modify/update.js +18 -2
- package/dist/tools/modify/update.js.map +1 -1
- package/dist/tools/modify.d.ts +3 -2
- package/dist/tools/modify.js +3 -2
- package/dist/tools/read/css.d.ts.map +1 -1
- package/dist/tools/read/css.js +29 -12
- package/dist/tools/read/css.js.map +1 -1
- package/dist/tools/read/libraries.js +1 -1
- package/dist/tools/read/nodes.d.ts.map +1 -1
- package/dist/tools/read/nodes.js +19 -5
- package/dist/tools/read/nodes.js.map +1 -1
- package/dist/tools/registry/extended.d.ts.map +1 -1
- package/dist/tools/registry/extended.js +6 -1
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/text-range.d.ts +11 -0
- package/dist/tools/text-range.d.ts.map +1 -0
- package/dist/tools/text-range.js +26 -0
- package/dist/tools/text-range.js.map +1 -0
- package/dist/tools/variables/bindings.js +1 -1
- package/dist/tools/variables/bindings.js.map +1 -1
- package/dist/tools/variables/unbind.js +1 -1
- package/dist/tools/variables/unbind.js.map +1 -1
- package/dist/tools/vector/path.d.ts.map +1 -1
- package/dist/tools/vector/path.js +7 -21
- package/dist/tools/vector/path.js.map +1 -1
- package/dist/vector/rebase.d.ts +17 -0
- package/dist/vector/rebase.d.ts.map +1 -0
- package/dist/vector/rebase.js +32 -0
- package/dist/vector/rebase.js.map +1 -0
- package/package.json +14 -9
- package/src/canvas/boolean.ts +12 -1
- package/src/canvas/color-space.ts +73 -0
- package/src/canvas/fills.ts +130 -83
- package/src/canvas/flatten.ts +92 -7
- package/src/canvas/index.ts +9 -0
- package/src/canvas/layout-grids.ts +15 -2
- package/src/canvas/noise/render.ts +35 -7
- package/src/canvas/noise/shader.ts +8 -10
- package/src/canvas/overlays/annotations.ts +117 -0
- package/src/canvas/overlays/auto-layout-hover.ts +41 -1
- package/src/canvas/overlays/feedback.ts +7 -2
- package/src/canvas/overlays/index.ts +1 -1
- package/src/canvas/overlays/measurement.ts +49 -3
- package/src/canvas/overlays/presence.ts +35 -32
- package/src/canvas/renderer/colors.ts +14 -0
- package/src/canvas/renderer/document-surface.ts +16 -6
- package/src/canvas/renderer/lifecycle.ts +2 -2
- package/src/canvas/renderer/methods.ts +4 -0
- package/src/canvas/renderer/overlay-pass.ts +4 -0
- package/src/canvas/renderer/pipeline.ts +8 -0
- package/src/canvas/renderer/types.ts +8 -0
- package/src/canvas/renderer.ts +21 -2
- package/src/canvas/scene.ts +15 -7
- package/src/clipboard/pairdraw.ts +1 -0
- package/src/editor/bridges/clipboard.ts +1 -0
- package/src/editor/bridges/components.ts +10 -0
- package/src/editor/clipboard/code.ts +50 -0
- package/src/editor/clipboard/paste/dependencies.ts +18 -0
- package/src/editor/clipboard/paste/run.ts +64 -0
- package/src/editor/clipboard/styled.ts +4 -52
- package/src/editor/clipboard.ts +40 -0
- package/src/editor/components/instances.ts +92 -4
- package/src/editor/components/slots/index.ts +7 -0
- package/src/editor/components.ts +16 -2
- package/src/editor/create.ts +15 -1
- package/src/editor/design-tokens.ts +3 -23
- package/src/editor/image-edit.ts +5 -2
- package/src/editor/index.ts +1 -0
- package/src/editor/layout-mode.ts +131 -3
- package/src/editor/nodes.ts +30 -5
- package/src/editor/read-only/actions.ts +6 -0
- package/src/editor/selection/overlays.ts +8 -0
- package/src/editor/state/shared.ts +1 -0
- package/src/editor/state/view.ts +2 -0
- package/src/editor/structure/boolean.ts +29 -1
- package/src/editor/structure/container-wrap.ts +20 -4
- package/src/editor/structure/flatten.ts +15 -8
- package/src/editor/structure/group/ungroup.ts +2 -0
- package/src/editor/structure/outline-stroke.ts +5 -0
- package/src/editor/styles.ts +203 -0
- package/src/editor/text/selection-style.ts +18 -1
- package/src/editor/tool-registry.ts +2 -0
- package/src/editor/types.ts +14 -0
- package/src/editor/variable-bindings.ts +11 -0
- package/src/figma-api/accessors/basic.ts +33 -1
- package/src/figma-api/accessors/vector.ts +6 -13
- package/src/figma-api/compatibility.ts +1 -0
- package/src/figma-api/component-scope.ts +36 -0
- package/src/figma-api/components.ts +24 -0
- package/src/figma-api/flatten.ts +7 -3
- package/src/figma-api/index.ts +302 -6
- package/src/figma-api/node-types.ts +1 -0
- package/src/figma-api/overrides.ts +192 -5
- package/src/figma-api/proxy.ts +16 -1
- package/src/figma-api/reactions.ts +163 -12
- package/src/figma-api/slots.ts +10 -9
- package/src/io/formats/code/detect.ts +67 -0
- package/src/io/formats/code/index.ts +17 -0
- package/src/io/formats/code/read.ts +143 -0
- package/src/io/formats/code/stylesheet.ts +24 -0
- package/src/io/formats/code/tokens.ts +159 -0
- package/src/io/formats/design-tokens/apply.ts +3 -2
- package/src/io/formats/fig/export/patch/fields.ts +11 -0
- package/src/io/formats/fig/export/patch/index.ts +23 -19
- package/src/io/formats/fig/export/setup.ts +8 -1
- package/src/io/formats/fig/index.ts +6 -0
- package/src/io/formats/fig/read.ts +11 -2
- package/src/io/formats/html/layers.ts +7 -0
- package/src/io/formats/pdf/export.ts +19 -7
- package/src/io/formats/pdf/plan.ts +71 -32
- package/src/io/formats/raster/headless.ts +3 -1
- package/src/io/formats/raster/index.ts +2 -0
- package/src/io/formats/raster/render.ts +49 -9
- package/src/io/formats/svg/defs.ts +27 -1
- package/src/io/formats/svg/export.ts +75 -13
- package/src/io/formats/svg/index.ts +1 -0
- package/src/io/formats/svg/text/layout.ts +5 -3
- package/src/io/formats/video/record.ts +33 -9
- package/src/io/formats.ts +35 -15
- package/src/kiwi/fig/population/client.ts +6 -1
- package/src/kiwi/fig/session/document-state.ts +195 -5
- package/src/kiwi/fig/session/options.ts +2 -0
- package/src/layout/apply.ts +12 -4
- package/src/layout/auto-layout-handles.ts +1 -1
- package/src/layout/axis-sizing.ts +3 -1
- package/src/layout/derived.ts +3 -1
- package/src/layout/effective-generated-text.ts +1 -1
- package/src/layout/grid.ts +91 -21
- package/src/layout.ts +16 -3
- package/src/node/fs.ts +32 -7
- package/src/prototype/easing.ts +79 -7
- package/src/prototype/scenes.ts +244 -15
- package/src/prototype/session.ts +1 -0
- package/src/prototype/smart-animate/animation.ts +4 -3
- package/src/prototype/timeline.ts +118 -26
- package/src/prototype/variables.ts +189 -0
- package/src/rpc/read-commands.ts +19 -1
- package/src/text/character-style.ts +47 -0
- package/src/text/index.ts +1 -1
- package/src/tools/create/basic.ts +2 -3
- package/src/tools/create/code.ts +85 -0
- package/src/tools/create/html.ts +9 -46
- package/src/tools/create/inputs.ts +12 -0
- package/src/tools/create/mermaid.ts +6 -6
- package/src/tools/create/place.ts +80 -0
- package/src/tools/create.ts +1 -0
- package/src/tools/css/gradient.ts +147 -0
- package/src/tools/modify/geometry.ts +5 -5
- package/src/tools/modify/layout.ts +19 -0
- package/src/tools/modify/overrides.ts +35 -0
- package/src/tools/modify/paint.ts +124 -54
- package/src/tools/modify/text.ts +91 -7
- package/src/tools/modify/update.ts +23 -2
- package/src/tools/modify.ts +9 -1
- package/src/tools/read/css.ts +46 -12
- package/src/tools/read/nodes.ts +26 -4
- package/src/tools/registry/extended.ts +6 -0
- package/src/tools/text-range.ts +29 -0
- package/src/tools/variables/bindings.ts +4 -1
- package/src/tools/variables/unbind.ts +4 -1
- package/src/tools/vector/path.ts +11 -13
- package/src/vector/rebase.ts +33 -0
package/dist/index.js
CHANGED
|
@@ -15,12 +15,12 @@ import { replaceSelectionColor, selectionColors, selectionColorsShown } from "./
|
|
|
15
15
|
import { DOCUMENT_COLOR_LIMIT, documentColors } from "./editor/document-colors.js";
|
|
16
16
|
import { copyEditorViewState, createDefaultEditorViewState, pickEditorViewState } from "./editor/state/view.js";
|
|
17
17
|
import { applyDocumentChange, isEmptyDocumentChange, recordDocumentChange, touchedTopLevelIds } from "./editor/history/document-change.js";
|
|
18
|
+
import { syncEditedComponents } from "./editor/component-sync.js";
|
|
18
19
|
import { resolvePasteTarget } from "./editor/clipboard/paste/target.js";
|
|
19
20
|
import { clipboardImportHasConflicts, clipboardImportHasDependencies, planClipboardImport } from "./editor/clipboard/conflicts.js";
|
|
20
21
|
import { reapplyInstanceComponentProperties } from "./editor/components/properties.js";
|
|
21
22
|
import { newLayerDefaults } from "./editor/shapes/defaults.js";
|
|
22
23
|
import { pastedPropertyChanges } from "./editor/clipboard/paste/properties.js";
|
|
23
|
-
import { syncEditedComponents } from "./editor/component-sync.js";
|
|
24
24
|
import { resizedPathTextGlyphs } from "./editor/text/path-edit.js";
|
|
25
25
|
import { createGuideActions } from "./editor/guides.js";
|
|
26
26
|
import { opacityFromBuffer } from "./editor/nodes.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/io/formats/code/detect.d.ts
|
|
2
|
+
/** The most source a paste reads: 200 000 characters of JSX or HTML. */
|
|
3
|
+
declare const MAX_CODE_LENGTH = 200000;
|
|
4
|
+
/** What a pasted source is written in, which decides how its layers are built. */
|
|
5
|
+
type PasteCodeKind = 'jsx' | 'html';
|
|
6
|
+
/** Detection's answer for source longer than a paste reads. */
|
|
7
|
+
declare const CODE_TOO_LARGE = "too-large";
|
|
8
|
+
/** What detection says about a text: the code it holds, or that it is past the size a paste reads. */
|
|
9
|
+
type CodeDetection = PasteCodeKind | typeof CODE_TOO_LARGE;
|
|
10
|
+
/**
|
|
11
|
+
* What a pasted text is: JSX or TSX when it names components or inline props, HTML when it is
|
|
12
|
+
* markup alone, `too-large` when it is either but longer than a paste reads, and nothing when it
|
|
13
|
+
* draws no element, so ordinary text keeps pasting as text.
|
|
14
|
+
*/
|
|
15
|
+
declare function detectCode(text: string): CodeDetection | null;
|
|
16
|
+
/**
|
|
17
|
+
* The code a pasted text holds, or null when it is not code or is past the size a paste reads;
|
|
18
|
+
* `detectCode` says which of the two refused it.
|
|
19
|
+
*/
|
|
20
|
+
declare function detectCodeText(text: string): PasteCodeKind | null;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { CODE_TOO_LARGE, CodeDetection, MAX_CODE_LENGTH, PasteCodeKind, detectCode, detectCodeText };
|
|
23
|
+
//# sourceMappingURL=detect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.d.ts","names":[],"sources":["../../../../src/io/formats/code/detect.ts"],"mappings":";;cACa;;KAGD;;cAGC;;KAGD,gBAAgB,uBAAuB;;;;;;iBAqCnC,WAAW,eAAe;;;;;iBAgB1B,eAAe,eAAe"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//#region src/io/formats/code/detect.ts
|
|
2
|
+
/** The most source a paste reads: 200 000 characters of JSX or HTML. */
|
|
3
|
+
const MAX_CODE_LENGTH = 2e5;
|
|
4
|
+
/** Detection's answer for source longer than a paste reads. */
|
|
5
|
+
const CODE_TOO_LARGE = "too-large";
|
|
6
|
+
const ELEMENT = /<([A-Za-z][\w.:-]*)(?:\s[^<>]*)?\/?>/;
|
|
7
|
+
const CLOSING = /<\/([A-Za-z][\w.:-]*)\s*>/;
|
|
8
|
+
const SELF_CLOSING = /<([A-Za-z][\w.:-]*)(?:\s[^<>]*)?\/>/;
|
|
9
|
+
const FRAGMENT = /<>[\s\S]*<\/>/;
|
|
10
|
+
/** A source that names a component, an export, or an arrow body, rather than plain markup. */
|
|
11
|
+
const JSX_SOURCE = /\b(?:className\s*=|export\s+(?:default|function|const)\b|=>|function\s+[A-Z_a-z]\w*\s*\()/;
|
|
12
|
+
/** The kind of code a trimmed text draws, or null when it draws no element. */
|
|
13
|
+
function looksLikeCode(trimmed, tail) {
|
|
14
|
+
if (!ELEMENT.test(trimmed)) return null;
|
|
15
|
+
if (!CLOSING.test(trimmed) && !SELF_CLOSING.test(trimmed) && !FRAGMENT.test(trimmed) && !CLOSING.test(tail)) return null;
|
|
16
|
+
if (!trimmed.startsWith("<")) {
|
|
17
|
+
if (!/\breturn\b|\bimport\b|\bexport\b/.test(trimmed)) return null;
|
|
18
|
+
return "jsx";
|
|
19
|
+
}
|
|
20
|
+
return JSX_SOURCE.test(trimmed) ? "jsx" : "html";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* What a pasted text is: JSX or TSX when it names components or inline props, HTML when it is
|
|
24
|
+
* markup alone, `too-large` when it is either but longer than a paste reads, and nothing when it
|
|
25
|
+
* draws no element, so ordinary text keeps pasting as text.
|
|
26
|
+
*/
|
|
27
|
+
function detectCode(text) {
|
|
28
|
+
const tooLarge = text.length > MAX_CODE_LENGTH;
|
|
29
|
+
const trimmed = (tooLarge ? text.slice(0, MAX_CODE_LENGTH) : text).trim();
|
|
30
|
+
const tail = tooLarge ? text.slice(-4096) : "";
|
|
31
|
+
const kind = trimmed.length > 0 ? looksLikeCode(trimmed, tail) : null;
|
|
32
|
+
if (!kind) return null;
|
|
33
|
+
return tooLarge ? CODE_TOO_LARGE : kind;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The code a pasted text holds, or null when it is not code or is past the size a paste reads;
|
|
37
|
+
* `detectCode` says which of the two refused it.
|
|
38
|
+
*/
|
|
39
|
+
function detectCodeText(text) {
|
|
40
|
+
const detection = detectCode(text);
|
|
41
|
+
return detection === "too-large" ? null : detection;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { CODE_TOO_LARGE, MAX_CODE_LENGTH, detectCode, detectCodeText };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=detect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.js","names":[],"sources":["../../../../src/io/formats/code/detect.ts"],"sourcesContent":["/** The most source a paste reads: 200 000 characters of JSX or HTML. */\nexport const MAX_CODE_LENGTH = 200_000\n\n/** What a pasted source is written in, which decides how its layers are built. */\nexport type PasteCodeKind = 'jsx' | 'html'\n\n/** Detection's answer for source longer than a paste reads. */\nexport const CODE_TOO_LARGE = 'too-large'\n\n/** What detection says about a text: the code it holds, or that it is past the size a paste reads. */\nexport type CodeDetection = PasteCodeKind | typeof CODE_TOO_LARGE\n\nconst ELEMENT = /<([A-Za-z][\\w.:-]*)(?:\\s[^<>]*)?\\/?>/\nconst CLOSING = /<\\/([A-Za-z][\\w.:-]*)\\s*>/\nconst SELF_CLOSING = /<([A-Za-z][\\w.:-]*)(?:\\s[^<>]*)?\\/>/\nconst FRAGMENT = /<>[\\s\\S]*<\\/>/\n/** A source that names a component, an export, or an arrow body, rather than plain markup. */\nconst JSX_SOURCE =\n /\\b(?:className\\s*=|export\\s+(?:default|function|const)\\b|=>|function\\s+[A-Z_a-z]\\w*\\s*\\()/\n\n/** The end of a paste too long to read whole, where its closing markup still is. */\nconst STRUCTURE_TAIL = 4096\n\n/** The kind of code a trimmed text draws, or null when it draws no element. */\nfunction looksLikeCode(trimmed: string, tail: string): PasteCodeKind | null {\n if (!ELEMENT.test(trimmed)) return null\n if (\n !CLOSING.test(trimmed) &&\n !SELF_CLOSING.test(trimmed) &&\n !FRAGMENT.test(trimmed) &&\n !CLOSING.test(tail)\n ) {\n return null\n }\n if (!trimmed.startsWith('<')) {\n // Markup with code around it is a component; anything else without a return is markup.\n if (!/\\breturn\\b|\\bimport\\b|\\bexport\\b/.test(trimmed)) return null\n return 'jsx'\n }\n return JSX_SOURCE.test(trimmed) ? 'jsx' : 'html'\n}\n\n/**\n * What a pasted text is: JSX or TSX when it names components or inline props, HTML when it is\n * markup alone, `too-large` when it is either but longer than a paste reads, and nothing when it\n * draws no element, so ordinary text keeps pasting as text.\n */\nexport function detectCode(text: string): CodeDetection | null {\n // A paste past the size a paste reads is only scanned up to that size, so its length bounds work;\n // the tail still decides whether markup is closed, since the cut can land inside an element.\n const tooLarge = text.length > MAX_CODE_LENGTH\n const limited = tooLarge ? text.slice(0, MAX_CODE_LENGTH) : text\n const trimmed = limited.trim()\n const tail = tooLarge ? text.slice(-STRUCTURE_TAIL) : ''\n const kind = trimmed.length > 0 ? looksLikeCode(trimmed, tail) : null\n if (!kind) return null\n return tooLarge ? CODE_TOO_LARGE : kind\n}\n\n/**\n * The code a pasted text holds, or null when it is not code or is past the size a paste reads;\n * `detectCode` says which of the two refused it.\n */\nexport function detectCodeText(text: string): PasteCodeKind | null {\n const detection = detectCode(text)\n return detection === CODE_TOO_LARGE ? null : detection\n}\n"],"mappings":";;AACA,MAAa,kBAAkB;;AAM/B,MAAa,iBAAiB;AAK9B,MAAM,UAAU;AAChB,MAAM,UAAU;AAChB,MAAM,eAAe;AACrB,MAAM,WAAW;;AAEjB,MAAM,aACJ;;AAMF,SAAS,cAAc,SAAiB,MAAoC;CAC1E,IAAI,CAAC,QAAQ,KAAK,OAAO,GAAG,OAAO;CACnC,IACE,CAAC,QAAQ,KAAK,OAAO,KACrB,CAAC,aAAa,KAAK,OAAO,KAC1B,CAAC,SAAS,KAAK,OAAO,KACtB,CAAC,QAAQ,KAAK,IAAI,GAElB,OAAO;CAET,IAAI,CAAC,QAAQ,WAAW,GAAG,GAAG;EAE5B,IAAI,CAAC,mCAAmC,KAAK,OAAO,GAAG,OAAO;EAC9D,OAAO;CACT;CACA,OAAO,WAAW,KAAK,OAAO,IAAI,QAAQ;AAC5C;;;;;;AAOA,SAAgB,WAAW,MAAoC;CAG7D,MAAM,WAAW,KAAK,SAAS;CAE/B,MAAM,WADU,WAAW,KAAK,MAAM,GAAG,eAAe,IAAI,KAAA,CACpC,KAAK;CAC7B,MAAM,OAAO,WAAW,KAAK,MAAM,KAAe,IAAI;CACtD,MAAM,OAAO,QAAQ,SAAS,IAAI,cAAc,SAAS,IAAI,IAAI;CACjE,IAAI,CAAC,MAAM,OAAO;CAClB,OAAO,WAAW,iBAAiB;AACrC;;;;;AAMA,SAAgB,eAAe,MAAoC;CACjE,MAAM,YAAY,WAAW,IAAI;CACjC,OAAO,cAAA,cAA+B,OAAO;AAC/C"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CODE_TOO_LARGE, CodeDetection, MAX_CODE_LENGTH, PasteCodeKind, detectCode, detectCodeText } from "./detect.js";
|
|
2
|
+
import { CodeStylesheet, codeStylesheet } from "./stylesheet.js";
|
|
3
|
+
import { ReadCodeOptions, ReadCodeReport, ReadCodeResult, codeLayerCount, readCodeDocument } from "./read.js";
|
|
4
|
+
import { TokenBindingReport, bindCodeTokens, codeLayerNodes } from "./tokens.js";
|
|
5
|
+
export { CODE_TOO_LARGE, type CodeDetection, type CodeStylesheet, MAX_CODE_LENGTH, type PasteCodeKind, type ReadCodeOptions, type ReadCodeReport, type ReadCodeResult, type TokenBindingReport, bindCodeTokens, codeLayerCount, codeLayerNodes, codeStylesheet, detectCode, detectCodeText, readCodeDocument };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CODE_TOO_LARGE, MAX_CODE_LENGTH, detectCode, detectCodeText } from "./detect.js";
|
|
2
|
+
import { codeStylesheet } from "./stylesheet.js";
|
|
3
|
+
import { codeLayerCount, readCodeDocument } from "./read.js";
|
|
4
|
+
import { bindCodeTokens, codeLayerNodes } from "./tokens.js";
|
|
5
|
+
export { CODE_TOO_LARGE, MAX_CODE_LENGTH, bindCodeTokens, codeLayerCount, codeLayerNodes, codeStylesheet, detectCode, detectCodeText, readCodeDocument };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PasteCodeKind } from "./detect.js";
|
|
2
|
+
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
3
|
+
import { CSSRuntime, CodeReport } from "@pairdraw/dom-css";
|
|
4
|
+
//#region src/io/formats/code/read.d.ts
|
|
5
|
+
/** What a paste could not keep, counted for the toast, plus what only the paste knows. */
|
|
6
|
+
interface ReadCodeReport extends CodeReport {
|
|
7
|
+
/** Top-level layers the paste drew. */
|
|
8
|
+
layers: number;
|
|
9
|
+
/** Variant-prefixed utilities left out, such as `md:flex-row`'s `md:`. */
|
|
10
|
+
variantsStripped: number;
|
|
11
|
+
/** Colour and number properties bound to the target document's variables. */
|
|
12
|
+
tokensBound: number;
|
|
13
|
+
/** Values two variables share, which a paste binds nothing to. */
|
|
14
|
+
tokensAmbiguous: number;
|
|
15
|
+
}
|
|
16
|
+
interface ReadCodeOptions {
|
|
17
|
+
/** The paste's own CSS: a `globals.css` or a `<style>` block it came with. */
|
|
18
|
+
css?: string;
|
|
19
|
+
/** The target document's tokens as a stylesheet, so `bg-primary` resolves before binding. */
|
|
20
|
+
tokensCSS?: string;
|
|
21
|
+
/** The CSS runtime a host supplies; the headless one by default. */
|
|
22
|
+
runtime?: CSSRuntime;
|
|
23
|
+
pageName?: string;
|
|
24
|
+
/** The language the caller names, instead of what detection reads. */
|
|
25
|
+
kind?: PasteCodeKind;
|
|
26
|
+
/** Whether Tailwind utilities compile; false reads only inline styles and the paste's CSS. */
|
|
27
|
+
tailwind?: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface ReadCodeResult {
|
|
30
|
+
graph: SceneGraph;
|
|
31
|
+
report: ReadCodeReport;
|
|
32
|
+
kind: PasteCodeKind;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The layers a pasted JSX, TSX, or HTML source draws, styled as a browser would style it with its
|
|
36
|
+
* own CSS and the Tailwind classes it names. Nothing in the source runs. Token binding needs the
|
|
37
|
+
* target document and happens in `bindCodeTokens`. Source past the size a paste reads is refused
|
|
38
|
+
* before it is parsed.
|
|
39
|
+
*/
|
|
40
|
+
declare function readCodeDocument(code: string, options?: ReadCodeOptions): Promise<ReadCodeResult>;
|
|
41
|
+
/** Every layer the paste drew, without the document node or its pages. */
|
|
42
|
+
declare function codeLayerCount(graph: SceneGraph): number;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { ReadCodeOptions, ReadCodeReport, ReadCodeResult, codeLayerCount, readCodeDocument };
|
|
45
|
+
//# sourceMappingURL=read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.d.ts","names":[],"sources":["../../../../src/io/formats/code/read.ts"],"mappings":";;;;;UAoBiB,uBAAuB;;EAEtC;;EAEA;;EAEA;;EAEA;;UAGe;;EAEf;;EAEA;;EAEA,UAAU;EACV;;EAEA,OAAO;;EAEP;;UAGe;EACf,OAAO;EACP,QAAQ;EACR,MAAM;;;;;;;;iBASc,iBACpB,cACA,UAAS,kBACR,QAAQ;;iBA0EK,eAAe,OAAO"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { MAX_CODE_LENGTH, detectCode } from "./detect.js";
|
|
2
|
+
import { codeStylesheet } from "./stylesheet.js";
|
|
3
|
+
import { htmlClassNames, htmlElementCount } from "../html/layers.js";
|
|
4
|
+
import { CodeTooLargeError, MAX_CODE_ELEMENTS, createHeadlessCSSRuntime, jsxSourceToTree, tailwindCandidates, tailwindHTMLToSceneGraph, tailwindJSXToSceneGraph, tailwindUtilities } from "@pairdraw/dom-css";
|
|
5
|
+
//#region src/io/formats/code/read.ts
|
|
6
|
+
/**
|
|
7
|
+
* The layers a pasted JSX, TSX, or HTML source draws, styled as a browser would style it with its
|
|
8
|
+
* own CSS and the Tailwind classes it names. Nothing in the source runs. Token binding needs the
|
|
9
|
+
* target document and happens in `bindCodeTokens`. Source past the size a paste reads is refused
|
|
10
|
+
* before it is parsed.
|
|
11
|
+
*/
|
|
12
|
+
async function readCodeDocument(code, options = {}) {
|
|
13
|
+
const detection = detectCode(code);
|
|
14
|
+
if (detection === "too-large") throw new CodeTooLargeError(`The paste is longer than ${MAX_CODE_LENGTH} characters; paste a smaller part of it.`);
|
|
15
|
+
const kind = options.kind ?? detection;
|
|
16
|
+
if (!kind) throw new Error("This text does not draw a layout: paste JSX, TSX, or HTML markup.");
|
|
17
|
+
if (kind === "html" && htmlElementCount(code) > MAX_CODE_ELEMENTS) throw new CodeTooLargeError(`The paste draws more than ${MAX_CODE_ELEMENTS} layers; paste a smaller part of it.`);
|
|
18
|
+
const stylesheet = codeStylesheet([options.tokensCSS, options.css]);
|
|
19
|
+
const runtime = options.runtime ?? createHeadlessCSSRuntime();
|
|
20
|
+
const { graph, report } = await (kind === "jsx" ? jsxLayers : htmlLayers)(code, {
|
|
21
|
+
...options,
|
|
22
|
+
runtime,
|
|
23
|
+
css: stylesheet.css,
|
|
24
|
+
tailwind: options.tailwind !== false
|
|
25
|
+
});
|
|
26
|
+
report.layers = codeLayerCount(graph);
|
|
27
|
+
report.approximations += stylesheet.importsDropped;
|
|
28
|
+
return {
|
|
29
|
+
graph,
|
|
30
|
+
report,
|
|
31
|
+
kind
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async function jsxLayers(code, source) {
|
|
35
|
+
const { children, report } = jsxSourceToTree(code);
|
|
36
|
+
const { candidates, variantsStripped } = source.tailwind ? tailwindCandidates(children) : {
|
|
37
|
+
candidates: [],
|
|
38
|
+
variantsStripped: 0
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
graph: await tailwindJSXToSceneGraph(children, candidates, {
|
|
42
|
+
runtime: source.runtime,
|
|
43
|
+
css: source.css,
|
|
44
|
+
pageName: source.pageName
|
|
45
|
+
}),
|
|
46
|
+
report: withCounts(report, variantsStripped)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function htmlLayers(code, source) {
|
|
50
|
+
const { candidates, variantsStripped } = source.tailwind ? tailwindUtilities(htmlClassNames(code)) : {
|
|
51
|
+
candidates: [],
|
|
52
|
+
variantsStripped: 0
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
graph: await tailwindHTMLToSceneGraph(code, candidates, {
|
|
56
|
+
runtime: source.runtime,
|
|
57
|
+
css: source.css,
|
|
58
|
+
pageName: source.pageName
|
|
59
|
+
}),
|
|
60
|
+
report: withCounts({
|
|
61
|
+
placeholders: 0,
|
|
62
|
+
componentsAsFrames: 0,
|
|
63
|
+
droppedProps: 0,
|
|
64
|
+
approximations: 0,
|
|
65
|
+
imagesAsPlaceholders: 0
|
|
66
|
+
}, variantsStripped)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Every layer the paste drew, without the document node or its pages. */
|
|
70
|
+
function codeLayerCount(graph) {
|
|
71
|
+
const pages = new Set(graph.getPages().map((page) => page.id));
|
|
72
|
+
return [...graph.getAllNodes()].filter((node) => node.id !== graph.rootId && !pages.has(node.id)).length;
|
|
73
|
+
}
|
|
74
|
+
function withCounts(report, variantsStripped) {
|
|
75
|
+
return {
|
|
76
|
+
...report,
|
|
77
|
+
layers: 0,
|
|
78
|
+
variantsStripped,
|
|
79
|
+
tokensBound: 0,
|
|
80
|
+
tokensAmbiguous: 0
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { codeLayerCount, readCodeDocument };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.js","names":[],"sources":["../../../../src/io/formats/code/read.ts"],"sourcesContent":["import {\n CodeTooLargeError,\n MAX_CODE_ELEMENTS,\n createHeadlessCSSRuntime,\n jsxSourceToTree,\n tailwindCandidates,\n tailwindHTMLToSceneGraph,\n tailwindJSXToSceneGraph,\n tailwindUtilities,\n type CodeReport,\n type CSSRuntime\n} from '@pairdraw/dom-css'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { htmlClassNames, htmlElementCount } from '#core/io/formats/html/layers'\n\nimport { CODE_TOO_LARGE, MAX_CODE_LENGTH, detectCode, type PasteCodeKind } from './detect'\nimport { codeStylesheet } from './stylesheet'\n\n/** What a paste could not keep, counted for the toast, plus what only the paste knows. */\nexport interface ReadCodeReport extends CodeReport {\n /** Top-level layers the paste drew. */\n layers: number\n /** Variant-prefixed utilities left out, such as `md:flex-row`'s `md:`. */\n variantsStripped: number\n /** Colour and number properties bound to the target document's variables. */\n tokensBound: number\n /** Values two variables share, which a paste binds nothing to. */\n tokensAmbiguous: number\n}\n\nexport interface ReadCodeOptions {\n /** The paste's own CSS: a `globals.css` or a `<style>` block it came with. */\n css?: string\n /** The target document's tokens as a stylesheet, so `bg-primary` resolves before binding. */\n tokensCSS?: string\n /** The CSS runtime a host supplies; the headless one by default. */\n runtime?: CSSRuntime\n pageName?: string\n /** The language the caller names, instead of what detection reads. */\n kind?: PasteCodeKind\n /** Whether Tailwind utilities compile; false reads only inline styles and the paste's CSS. */\n tailwind?: boolean\n}\n\nexport interface ReadCodeResult {\n graph: SceneGraph\n report: ReadCodeReport\n kind: PasteCodeKind\n}\n\n/**\n * The layers a pasted JSX, TSX, or HTML source draws, styled as a browser would style it with its\n * own CSS and the Tailwind classes it names. Nothing in the source runs. Token binding needs the\n * target document and happens in `bindCodeTokens`. Source past the size a paste reads is refused\n * before it is parsed.\n */\nexport async function readCodeDocument(\n code: string,\n options: ReadCodeOptions = {}\n): Promise<ReadCodeResult> {\n const detection = detectCode(code)\n if (detection === CODE_TOO_LARGE) {\n throw new CodeTooLargeError(\n `The paste is longer than ${MAX_CODE_LENGTH} characters; paste a smaller part of it.`\n )\n }\n const kind = options.kind ?? detection\n if (!kind) throw new Error('This text does not draw a layout: paste JSX, TSX, or HTML markup.')\n if (kind === 'html' && htmlElementCount(code) > MAX_CODE_ELEMENTS) {\n throw new CodeTooLargeError(\n `The paste draws more than ${MAX_CODE_ELEMENTS} layers; paste a smaller part of it.`\n )\n }\n const stylesheet = codeStylesheet([options.tokensCSS, options.css])\n const runtime = options.runtime ?? createHeadlessCSSRuntime()\n const build = kind === 'jsx' ? jsxLayers : htmlLayers\n const { graph, report } = await build(code, {\n ...options,\n runtime,\n css: stylesheet.css,\n tailwind: options.tailwind !== false\n })\n report.layers = codeLayerCount(graph)\n report.approximations += stylesheet.importsDropped\n return { graph, report, kind }\n}\n\ninterface StyleSource {\n runtime: CSSRuntime\n css: string\n pageName?: string\n tailwind: boolean\n}\n\nasync function jsxLayers(\n code: string,\n source: StyleSource\n): Promise<{ graph: SceneGraph; report: ReadCodeReport }> {\n const { children, report } = jsxSourceToTree(code)\n const { candidates, variantsStripped } = source.tailwind\n ? tailwindCandidates(children)\n : { candidates: [], variantsStripped: 0 }\n const graph = await tailwindJSXToSceneGraph(children, candidates, {\n runtime: source.runtime,\n css: source.css,\n pageName: source.pageName\n })\n return { graph, report: withCounts(report, variantsStripped) }\n}\n\nasync function htmlLayers(\n code: string,\n source: StyleSource\n): Promise<{ graph: SceneGraph; report: ReadCodeReport }> {\n const { candidates, variantsStripped } = source.tailwind\n ? tailwindUtilities(htmlClassNames(code))\n : { candidates: [], variantsStripped: 0 }\n const graph = await tailwindHTMLToSceneGraph(code, candidates, {\n runtime: source.runtime,\n css: source.css,\n pageName: source.pageName\n })\n const report: CodeReport = {\n placeholders: 0,\n componentsAsFrames: 0,\n droppedProps: 0,\n approximations: 0,\n imagesAsPlaceholders: 0\n }\n return { graph, report: withCounts(report, variantsStripped) }\n}\n\n/** Every layer the paste drew, without the document node or its pages. */\nexport function codeLayerCount(graph: SceneGraph): number {\n const pages = new Set(graph.getPages().map((page) => page.id))\n return [...graph.getAllNodes()].filter((node) => node.id !== graph.rootId && !pages.has(node.id))\n .length\n}\n\nfunction withCounts(report: CodeReport, variantsStripped: number): ReadCodeReport {\n return { ...report, layers: 0, variantsStripped, tokensBound: 0, tokensAmbiguous: 0 }\n}\n"],"mappings":";;;;;;;;;;;AAyDA,eAAsB,iBACpB,MACA,UAA2B,CAAC,GACH;CACzB,MAAM,YAAY,WAAW,IAAI;CACjC,IAAI,cAAA,aACF,MAAM,IAAI,kBACR,4BAA4B,gBAAgB,yCAC9C;CAEF,MAAM,OAAO,QAA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AAGA,SAAgB,eAAe,OAA2B;CACxD,MAAM,QAAQ,IAAI,IAAI,MAAM,SAAS,CAAC,CAAC,KAAK,SAAS,KAAK,EAAE,CAAC;CAC7D,OAAO,CAAC,GAAG,MAAM,YAAY,CAAC,CAAC,CAAC,QAAQ,SAAS,KAAK,OAAO,MAAM,UAAU,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC,CAAC,CAC9F;AACL;AAEA,SAAS,WAAW,QAAoB,kBAA0C;CAChF,OAAO;EAAE,GAAG;EAAQ,QAAQ;EAAG;EAAkB,aAAa;EAAG,iBAAiB;CAAE;AACtF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/io/formats/code/stylesheet.d.ts
|
|
2
|
+
interface CodeStylesheet {
|
|
3
|
+
css: string;
|
|
4
|
+
importsDropped: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The stylesheet a paste styles with: the document's tokens first, then the paste's own CSS, with
|
|
8
|
+
* `@import` rules left out because they name files the paste does not bring with it.
|
|
9
|
+
*/
|
|
10
|
+
declare function codeStylesheet(parts: Array<string | undefined>): CodeStylesheet;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { CodeStylesheet, codeStylesheet };
|
|
13
|
+
//# sourceMappingURL=stylesheet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stylesheet.d.ts","names":[],"sources":["../../../../src/io/formats/code/stylesheet.ts"],"mappings":";UAGiB;EACf;EACA;;;;;;iBAOc,eAAe,OAAO,4BAA4B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/io/formats/code/stylesheet.ts
|
|
2
|
+
/** The declarations a stylesheet keeps: one import names a file the paste does not carry. */
|
|
3
|
+
const IMPORT = /^\s*@import\b.*$/gm;
|
|
4
|
+
/**
|
|
5
|
+
* The stylesheet a paste styles with: the document's tokens first, then the paste's own CSS, with
|
|
6
|
+
* `@import` rules left out because they name files the paste does not bring with it.
|
|
7
|
+
*/
|
|
8
|
+
function codeStylesheet(parts) {
|
|
9
|
+
let importsDropped = 0;
|
|
10
|
+
return {
|
|
11
|
+
css: parts.filter((part) => Boolean(part?.trim())).map((part) => part.replace(IMPORT, () => {
|
|
12
|
+
importsDropped += 1;
|
|
13
|
+
return "";
|
|
14
|
+
})).join("\n"),
|
|
15
|
+
importsDropped
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { codeStylesheet };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=stylesheet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stylesheet.js","names":[],"sources":["../../../../src/io/formats/code/stylesheet.ts"],"sourcesContent":["/** The declarations a stylesheet keeps: one import names a file the paste does not carry. */\nconst IMPORT = /^\\s*@import\\b.*$/gm\n\nexport interface CodeStylesheet {\n css: string\n importsDropped: number\n}\n\n/**\n * The stylesheet a paste styles with: the document's tokens first, then the paste's own CSS, with\n * `@import` rules left out because they name files the paste does not bring with it.\n */\nexport function codeStylesheet(parts: Array<string | undefined>): CodeStylesheet {\n let importsDropped = 0\n const kept = parts\n .filter((part): part is string => Boolean(part?.trim()))\n .map((part) =>\n part.replace(IMPORT, () => {\n importsDropped += 1\n return ''\n })\n )\n return { css: kept.join('\\n'), importsDropped }\n}\n"],"mappings":";;AACA,MAAM,SAAS;;;;;AAWf,SAAgB,eAAe,OAAkD;CAC/E,IAAI,iBAAiB;CASrB,OAAO;EAAE,KARI,MACV,QAAQ,SAAyB,QAAQ,MAAM,KAAK,CAAC,CAAC,CAAC,CACvD,KAAK,SACJ,KAAK,QAAQ,cAAc;GACzB,kBAAkB;GAClB,OAAO;EACT,CAAC,CAEY,CAAC,CAAC,KAAK,IAAI;EAAG;CAAe;AAChD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
|
|
2
|
+
//#region src/io/formats/code/tokens.d.ts
|
|
3
|
+
interface TokenBindingReport {
|
|
4
|
+
tokensBound: number;
|
|
5
|
+
tokensAmbiguous: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Binds a pasted layer's colours and numbers to the target document's variables, one property at
|
|
9
|
+
* a time, only when exactly one variable of the matching namespace holds that exact value. A value
|
|
10
|
+
* two variables share binds nothing: guessing would change the design. The layers are the inserted
|
|
11
|
+
* ones, so a binding names a variable the document already has.
|
|
12
|
+
*/
|
|
13
|
+
declare function bindCodeTokens(nodes: Iterable<SceneNode>, target: SceneGraph, report: TokenBindingReport): void;
|
|
14
|
+
/** Every layer a paste created, from its roots down, as a transfer inserted them. */
|
|
15
|
+
declare function codeLayerNodes(graph: SceneGraph, rootIds: readonly string[]): SceneNode[];
|
|
16
|
+
//#endregion
|
|
17
|
+
export { TokenBindingReport, bindCodeTokens, codeLayerNodes };
|
|
18
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","names":[],"sources":["../../../../src/io/formats/code/tokens.ts"],"mappings":";;UA8BiB;EACf;EACA;;;;;;;;iBASc,eACd,OAAO,SAAS,YAChB,QAAQ,YACR,QAAQ;;iBAQM,eAAe,OAAO,YAAY,6BAA6B"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { variableValueInMode } from "@pairdraw/scene-graph/variables";
|
|
2
|
+
//#region src/io/formats/code/tokens.ts
|
|
3
|
+
/** The namespaces a layer property can take, in the vocabulary its tokens are named in. */
|
|
4
|
+
const PROPERTY_NAMESPACES = {
|
|
5
|
+
cornerRadius: "radius",
|
|
6
|
+
topLeftRadius: "radius",
|
|
7
|
+
topRightRadius: "radius",
|
|
8
|
+
bottomLeftRadius: "radius",
|
|
9
|
+
bottomRightRadius: "radius",
|
|
10
|
+
fontSize: "text",
|
|
11
|
+
lineHeight: "leading",
|
|
12
|
+
letterSpacing: "tracking",
|
|
13
|
+
itemSpacing: "spacing",
|
|
14
|
+
counterAxisSpacing: "spacing",
|
|
15
|
+
gridColumnGap: "spacing",
|
|
16
|
+
gridRowGap: "spacing",
|
|
17
|
+
paddingLeft: "spacing",
|
|
18
|
+
paddingRight: "spacing",
|
|
19
|
+
paddingTop: "spacing",
|
|
20
|
+
paddingBottom: "spacing"
|
|
21
|
+
};
|
|
22
|
+
/** The numeric properties a pasted layer binds to a matching variable. */
|
|
23
|
+
const BOUND_NUMERIC_FIELDS = Object.keys(PROPERTY_NAMESPACES);
|
|
24
|
+
/**
|
|
25
|
+
* Binds a pasted layer's colours and numbers to the target document's variables, one property at
|
|
26
|
+
* a time, only when exactly one variable of the matching namespace holds that exact value. A value
|
|
27
|
+
* two variables share binds nothing: guessing would change the design. The layers are the inserted
|
|
28
|
+
* ones, so a binding names a variable the document already has.
|
|
29
|
+
*/
|
|
30
|
+
function bindCodeTokens(nodes, target, report) {
|
|
31
|
+
const index = variableIndex(target);
|
|
32
|
+
if (index.size === 0) return;
|
|
33
|
+
for (const node of nodes) bindNode(node, index, report);
|
|
34
|
+
}
|
|
35
|
+
/** Every layer a paste created, from its roots down, as a transfer inserted them. */
|
|
36
|
+
function codeLayerNodes(graph, rootIds) {
|
|
37
|
+
const nodes = [];
|
|
38
|
+
const visit = (id) => {
|
|
39
|
+
const node = graph.getNode(id);
|
|
40
|
+
if (!node) return;
|
|
41
|
+
nodes.push(node);
|
|
42
|
+
for (const child of node.childIds) visit(child);
|
|
43
|
+
};
|
|
44
|
+
for (const id of rootIds) visit(id);
|
|
45
|
+
return nodes;
|
|
46
|
+
}
|
|
47
|
+
function variableIndex(target) {
|
|
48
|
+
const index = /* @__PURE__ */ new Map();
|
|
49
|
+
for (const variable of target.variables.values()) {
|
|
50
|
+
if (variable.deleted) continue;
|
|
51
|
+
const namespace = namespaceOf(variable);
|
|
52
|
+
if (!namespace) continue;
|
|
53
|
+
const key = indexKey(namespace, variableValueInMode(target, variable, defaultModeOf(target, variable)));
|
|
54
|
+
if (!key) continue;
|
|
55
|
+
const found = index.get(key);
|
|
56
|
+
if (found) found.push(variable);
|
|
57
|
+
else index.set(key, [variable]);
|
|
58
|
+
}
|
|
59
|
+
return index;
|
|
60
|
+
}
|
|
61
|
+
function defaultModeOf(target, variable) {
|
|
62
|
+
return target.variableCollections.get(variable.collectionId)?.defaultModeId ?? "";
|
|
63
|
+
}
|
|
64
|
+
/** The namespace a variable's scopes name, or none when it names something a layer cannot take. */
|
|
65
|
+
function namespaceOf(variable) {
|
|
66
|
+
if (variable.type === "COLOR") return "color";
|
|
67
|
+
if (variable.type !== "FLOAT") return null;
|
|
68
|
+
for (const scope of variable.scopes ?? []) {
|
|
69
|
+
if (scope === "CORNER_RADIUS") return "radius";
|
|
70
|
+
if (scope === "GAP" || scope === "WIDTH_HEIGHT") return "spacing";
|
|
71
|
+
if (scope === "FONT_SIZE") return "text";
|
|
72
|
+
if (scope === "LINE_HEIGHT") return "leading";
|
|
73
|
+
if (scope === "LETTER_SPACING") return "tracking";
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
function indexKey(namespace, value) {
|
|
78
|
+
if (typeof value === "number") return `${namespace}:${value.toFixed(3)}`;
|
|
79
|
+
if (!isColor(value)) return null;
|
|
80
|
+
return `${namespace}:${colorKey(value)}`;
|
|
81
|
+
}
|
|
82
|
+
function isColor(value) {
|
|
83
|
+
return typeof value === "object" && value !== null && "r" in value && "g" in value && "b" in value;
|
|
84
|
+
}
|
|
85
|
+
function colorKey(color) {
|
|
86
|
+
return [
|
|
87
|
+
color.r,
|
|
88
|
+
color.g,
|
|
89
|
+
color.b,
|
|
90
|
+
color.a
|
|
91
|
+
].map((channel) => channel.toFixed(4)).join(",");
|
|
92
|
+
}
|
|
93
|
+
function bindNode(node, index, report) {
|
|
94
|
+
bindPaints(node, "fills", index, report);
|
|
95
|
+
bindPaints(node, "strokes", index, report);
|
|
96
|
+
for (const field of BOUND_NUMERIC_FIELDS) {
|
|
97
|
+
const value = node[field];
|
|
98
|
+
if (typeof value !== "number" || value === 0) continue;
|
|
99
|
+
const namespace = PROPERTY_NAMESPACES[field];
|
|
100
|
+
if (!namespace) continue;
|
|
101
|
+
bindField(node, field, indexKey(namespace, value), index, report);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function bindPaints(node, list, index, report) {
|
|
105
|
+
node[list].forEach((paint, paintIndex) => {
|
|
106
|
+
if (paint.type !== "SOLID") return;
|
|
107
|
+
const { r, g, b, a } = paint.color;
|
|
108
|
+
bindField(node, `${list}/${paintIndex}/color`, indexKey("color", {
|
|
109
|
+
r,
|
|
110
|
+
g,
|
|
111
|
+
b,
|
|
112
|
+
a
|
|
113
|
+
}), index, report);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function bindField(node, field, key, index, report) {
|
|
117
|
+
if (!key || node.boundVariables[field]) return;
|
|
118
|
+
const candidates = index.get(key);
|
|
119
|
+
if (!candidates || candidates.length === 0) return;
|
|
120
|
+
if (candidates.length > 1) {
|
|
121
|
+
report.tokensAmbiguous += 1;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const variable = candidates.at(0);
|
|
125
|
+
if (!variable) return;
|
|
126
|
+
node.boundVariables = {
|
|
127
|
+
...node.boundVariables,
|
|
128
|
+
[field]: variable.id
|
|
129
|
+
};
|
|
130
|
+
report.tokensBound += 1;
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
export { bindCodeTokens, codeLayerNodes };
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","names":[],"sources":["../../../../src/io/formats/code/tokens.ts"],"sourcesContent":["import type { SceneGraph, SceneNode, Variable, VariableValue } from '@pairdraw/scene-graph'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\nimport { variableValueInMode } from '@pairdraw/scene-graph/variables'\n\n/** Tailwind namespace a document variable belongs to, which decides what it may bind. */\ntype TokenNamespace = 'color' | 'radius' | 'spacing' | 'text' | 'leading' | 'tracking'\n\n/** The namespaces a layer property can take, in the vocabulary its tokens are named in. */\nconst PROPERTY_NAMESPACES: Partial<Record<string, TokenNamespace>> = {\n cornerRadius: 'radius',\n topLeftRadius: 'radius',\n topRightRadius: 'radius',\n bottomLeftRadius: 'radius',\n bottomRightRadius: 'radius',\n fontSize: 'text',\n lineHeight: 'leading',\n letterSpacing: 'tracking',\n itemSpacing: 'spacing',\n counterAxisSpacing: 'spacing',\n gridColumnGap: 'spacing',\n gridRowGap: 'spacing',\n paddingLeft: 'spacing',\n paddingRight: 'spacing',\n paddingTop: 'spacing',\n paddingBottom: 'spacing'\n}\n\n/** The numeric properties a pasted layer binds to a matching variable. */\nconst BOUND_NUMERIC_FIELDS = Object.keys(PROPERTY_NAMESPACES)\n\nexport interface TokenBindingReport {\n tokensBound: number\n tokensAmbiguous: number\n}\n\n/**\n * Binds a pasted layer's colours and numbers to the target document's variables, one property at\n * a time, only when exactly one variable of the matching namespace holds that exact value. A value\n * two variables share binds nothing: guessing would change the design. The layers are the inserted\n * ones, so a binding names a variable the document already has.\n */\nexport function bindCodeTokens(\n nodes: Iterable<SceneNode>,\n target: SceneGraph,\n report: TokenBindingReport\n): void {\n const index = variableIndex(target)\n if (index.size === 0) return\n for (const node of nodes) bindNode(node, index, report)\n}\n\n/** Every layer a paste created, from its roots down, as a transfer inserted them. */\nexport function codeLayerNodes(graph: SceneGraph, rootIds: readonly string[]): SceneNode[] {\n const nodes: SceneNode[] = []\n const visit = (id: string): void => {\n const node = graph.getNode(id)\n if (!node) return\n nodes.push(node)\n for (const child of node.childIds) visit(child)\n }\n for (const id of rootIds) visit(id)\n return nodes\n}\n\ntype ValueIndex = Map<string, Variable[]>\n\nfunction variableIndex(target: SceneGraph): ValueIndex {\n const index: ValueIndex = new Map()\n for (const variable of target.variables.values()) {\n if (variable.deleted) continue\n const namespace = namespaceOf(variable)\n if (!namespace) continue\n const value = variableValueInMode(target, variable, defaultModeOf(target, variable))\n const key = indexKey(namespace, value)\n if (!key) continue\n const found = index.get(key)\n if (found) found.push(variable)\n else index.set(key, [variable])\n }\n return index\n}\n\nfunction defaultModeOf(target: SceneGraph, variable: Variable): string {\n return target.variableCollections.get(variable.collectionId)?.defaultModeId ?? ''\n}\n\n/** The namespace a variable's scopes name, or none when it names something a layer cannot take. */\nfunction namespaceOf(variable: Variable): TokenNamespace | null {\n if (variable.type === 'COLOR') return 'color'\n if (variable.type !== 'FLOAT') return null\n for (const scope of variable.scopes ?? []) {\n if (scope === 'CORNER_RADIUS') return 'radius'\n if (scope === 'GAP' || scope === 'WIDTH_HEIGHT') return 'spacing'\n if (scope === 'FONT_SIZE') return 'text'\n if (scope === 'LINE_HEIGHT') return 'leading'\n if (scope === 'LETTER_SPACING') return 'tracking'\n }\n return null\n}\n\nfunction indexKey(namespace: TokenNamespace, value: VariableValue | undefined): string | null {\n if (typeof value === 'number') return `${namespace}:${value.toFixed(3)}`\n if (!isColor(value)) return null\n return `${namespace}:${colorKey(value)}`\n}\n\nfunction isColor(value: unknown): value is Color {\n return typeof value === 'object' && value !== null && 'r' in value && 'g' in value && 'b' in value\n}\n\nfunction colorKey(color: Color): string {\n return [color.r, color.g, color.b, color.a].map((channel) => channel.toFixed(4)).join(',')\n}\n\nfunction bindNode(node: SceneNode, index: ValueIndex, report: TokenBindingReport): void {\n bindPaints(node, 'fills', index, report)\n bindPaints(node, 'strokes', index, report)\n for (const field of BOUND_NUMERIC_FIELDS) {\n const value = node[field as keyof SceneNode]\n if (typeof value !== 'number' || value === 0) continue\n const namespace = PROPERTY_NAMESPACES[field]\n if (!namespace) continue\n bindField(node, field, indexKey(namespace, value), index, report)\n }\n}\n\nfunction bindPaints(\n node: SceneNode,\n list: 'fills' | 'strokes',\n index: ValueIndex,\n report: TokenBindingReport\n): void {\n const paints = node[list]\n paints.forEach((paint, paintIndex) => {\n if (paint.type !== 'SOLID') return\n const { r, g, b, a } = paint.color\n bindField(node, `${list}/${paintIndex}/color`, indexKey('color', { r, g, b, a }), index, report)\n })\n}\n\nfunction bindField(\n node: SceneNode,\n field: string,\n key: string | null,\n index: ValueIndex,\n report: TokenBindingReport\n): void {\n if (!key || node.boundVariables[field]) return\n const candidates = index.get(key)\n if (!candidates || candidates.length === 0) return\n if (candidates.length > 1) {\n report.tokensAmbiguous += 1\n return\n }\n const variable = candidates.at(0)\n if (!variable) return\n node.boundVariables = { ...node.boundVariables, [field]: variable.id }\n report.tokensBound += 1\n}\n"],"mappings":";;;AAQA,MAAM,sBAA+D;CACnE,cAAc;CACd,eAAe;CACf,gBAAgB;CAChB,kBAAkB;CAClB,mBAAmB;CACnB,UAAU;CACV,YAAY;CACZ,eAAe;CACf,aAAa;CACb,oBAAoB;CACpB,eAAe;CACf,YAAY;CACZ,aAAa;CACb,cAAc;CACd,YAAY;CACZ,eAAe;AACjB;;AAGA,MAAM,uBAAuB,OAAO,KAAK,mBAAmB;;;;;;;AAa5D,SAAgB,eACd,OACA,QACA,QACM;CACN,MAAM,QAAQ,cAAc,MAAM;CAClC,IAAI,MAAM,SAAS,GAAG;CACtB,KAAK,MAAM,QAAQ,OAAO,SAAS,MAAM,OAAO,MAAM;AACxD;;AAGA,SAAgB,eAAe,OAAmB,SAAyC;CACzF,MAAM,QAAqB,CAAC;CAC5B,MAAM,SAAS,OAAqB;EAClC,MAAM,OAAO,MAAM,QAAQ,EAAE;EAC7B,IAAI,CAAC,MAAM;EACX,MAAM,KAAK,IAAI;EACf,KAAK,MAAM,SAAS,KAAK,UAAU,MAAM,KAAK;CAChD;CACA,KAAK,MAAM,MAAM,SAAS,MAAM,EAAE;CAClC,OAAO;AACT;AAIA,SAAS,cAAc,QAAgC;CACrD,MAAM,wBAAoB,IAAI,IAAI;CAClC,KAAK,MAAM,YAAY,OAAO,UAAU,OAAO,GAAG;EAChD,IAAI,SAAS,SAAS;EACtB,MAAM,YAAY,YAAY,QAAQ;EACtC,IAAI,CAAC,WAAW;EAEhB,MAAM,MAAM,SAAS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AAW,MAAM,WAAW,OAAO,MAAM;CACzC,KAAK,MAAM,SAAS,sBAAsB;EACxC,MAAM,QAAQ,KAAK;EACnB,IAAI,OAAO,UAAU,YAAY,UAAU,GAAG;EAC9C,MAAM,YAAY,oBAAoB;EACtC,IAAI,CAAC,WAAW;EAChB,UAAU,MAAM,OAAO,SAAS,WAAW,KAAK,GAAG,OAAO,MAAM;CAClE;AACF;AAEA,SAAS,WACP,MACA,MACA,OACA,QACM;CAEN,KADoB,KACd,CAAC,SAAS,OAAO,eAAe;EACpC,IAAI,MAAM,SAAS,SAAS;EAC5B,MAAM,EAAE,GAAG,GAAG,GAAG,MAAM,MAAM;EAC7B,UAAU,MAAM,GAAG,KAAK,GAAG,WAAW,SAAS,SAAS,SAAS;GAAE;GAAG;GAAG;GAAG;EAAE,CAAC,GAAG,OAAO,MAAM;CACjG,CAAC;AACH;AAEA,SAAS,UACP,MACA,OACA,KACA,OACA,QACM;CACN,IAAI,CAAC,OAAO,KAAK,eAAe,QAAQ;CACxC,MAAM,aAAa,MAAM,IAAI,GAAG;CAChC,IAAI,CAAC,cAAc,WAAW,WAAW,GAAG;CAC5C,IAAI,WAAW,SAAS,GAAG;EACzB,OAAO,mBAAmB;EAC1B;CACF;CACA,MAAM,WAAW,WAAW,GAAG,CAAC;CAChC,IAAI,CAAC,UAAU;CACf,KAAK,iBAAiB;EAAE,GAAG,KAAK;GAAiB,QAAQ,SAAS;CAAG;CACrE,OAAO,eAAe;AACxB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PlannedStyle } from "./plan/styles.js";
|
|
2
2
|
import { PlannedVariable, TokenImportPlan } from "./plan/index.js";
|
|
3
|
-
import { CodeSyntaxPlatform, SceneGraph, SceneNode, TokenExpression, TokenUnit, Variable, VariableCollection, VariableScope, VariableValue } from "@pairdraw/scene-graph";
|
|
3
|
+
import { CodeSyntaxPlatform, SceneGraph, SceneNode, SharedStyleType, TokenExpression, TokenUnit, Variable, VariableCollection, VariableScope, VariableValue } from "@pairdraw/scene-graph";
|
|
4
4
|
//#region src/io/formats/design-tokens/apply.d.ts
|
|
5
5
|
/** Token fields an import sets; `undefined` clears one. */
|
|
6
6
|
interface ImportedTokenFields {
|
|
@@ -42,8 +42,12 @@ interface TokenImportResult {
|
|
|
42
42
|
*/
|
|
43
43
|
declare function applyTokenImport(target: TokenImportTarget, plan: TokenImportPlan): TokenImportResult;
|
|
44
44
|
/** A style node: hidden from the layer list, found by its style id, as `.fig` styles are. */
|
|
45
|
-
declare function styleNodeProps(style: PlannedStyle,
|
|
46
|
-
|
|
45
|
+
declare function styleNodeProps(style: Pick<PlannedStyle, 'kind'> | {
|
|
46
|
+
kind: SharedStyleType;
|
|
47
|
+
}, fields: Partial<SceneNode>): Partial<SceneNode>;
|
|
48
|
+
declare function styleNodeType(style: Pick<PlannedStyle, 'kind'> | {
|
|
49
|
+
kind: SharedStyleType;
|
|
50
|
+
}): "RECTANGLE" | "TEXT";
|
|
47
51
|
/**
|
|
48
52
|
* Imports straight into a graph, for scripts, tools, and the CLI working on a document without
|
|
49
53
|
* an editor; the layers bound to variables whose values changed are resolved and laid out
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/apply.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/apply.ts"],"mappings":";;;;;UA0BiB;EACf,OAAO;EACP,SAAS;EACT,aAAa,QAAQ,OAAO;EAC5B;EACA;EACA,cAAc,eAAe;;;;;;UAOd;EACf,OAAO;EACP,cAAc,eAAe;EAC7B,QAAQ,sBAAsB;EAC9B,WAAW,sBAAsB,gBAAgB;EACjD,eAAe,sBAAsB;EACrC,iBAAiB,sBAAsB,gBAAgB;EACvD,iBAAiB,sBAAsB;EACvC,YAAY,SAAS,iBAAiB,uBAAuB;EAC7D,SAAS,oBAAoB,gBAAgB,OAAO;EACpD,eAAe,oBAAoB,QAAQ;EAC3C,SAAS,OAAO,cAAc,QAAQ,QAAQ,aAAa;EAC3D,WAAW,gBAAgB,SAAS,QAAQ;EAC5C,aAAa,gBAAgB,eAAe;;UAG7B;EACf;EACA;EACA;;;;;;;iBA+Kc,iBACd,QAAQ,mBACR,MAAM,kBACL;;iBAWa,eACd,OAAO,KAAK;EAA0B,MAAM;GAC5C,QAAQ,QAAQ,aACf,QAAQ;iBAIK,cAAc,OAAO,KAAK;EAA0B,MAAM;;;;;;;iBAuD1D,sBACd,OAAO,YACP,gBACA,MAAM,kBACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","names":[],"sources":["../../../../src/io/formats/design-tokens/apply.ts"],"sourcesContent":["import { compact } from 'es-toolkit/array'\nimport { pick } from 'es-toolkit/object'\nimport { isEmptyObject, isEqual } from 'es-toolkit/predicate'\n\nimport type {\n CodeSyntaxPlatform,\n SceneGraph,\n SceneNode,\n TokenExpression,\n TokenUnit,\n Variable,\n VariableCollection,\n VariableScope,\n VariableValue\n} from '@pairdraw/scene-graph'\nimport { copyEffects } from '@pairdraw/scene-graph/copy'\nimport { findInstanceAncestor } from '@pairdraw/scene-graph/instances'\nimport { randomHex } from '@pairdraw/scene-graph/random'\n\nimport { reconcileVariableLayouts } from '#core/layout/variables'\n\nimport type { AliasTarget, PlannedCollection, PlannedVariable, TokenImportPlan } from './plan'\nimport type { PlannedStyle } from './plan/styles'\n\n/** Token fields an import sets; `undefined` clears one. */\nexport interface ImportedTokenFields {\n unit?: TokenUnit\n scopes?: VariableScope[]\n codeSyntax?: Partial<Record<CodeSyntaxPlatform, string>>\n hiddenFromPublishing?: boolean\n description?: string\n expressions?: Record<string, TokenExpression>\n}\n\n/**\n * The changes an import makes, so the editor can make them undoable and a headless document can\n * make them directly. Each adds to or changes the document; none deletes.\n */\nexport interface TokenImportTarget {\n graph: SceneGraph\n addCollection(name: string): VariableCollection\n addMode(collectionId: string, name: string): string | undefined\n renameMode(collectionId: string, modeId: string, name: string): void\n setDefaultMode(collectionId: string, modeId: string): void\n setModeCondition(collectionId: string, modeId: string, condition: string): void\n setModeAttribute(collectionId: string, name: string): void\n addVariable(planned: PlannedVariable, collectionId: string): Variable\n setValue(variableId: string, modeId: string, value: VariableValue): void\n setTokenFields(variableId: string, fields: ImportedTokenFields): void\n addStyle(style: PlannedStyle, fields: Partial<SceneNode>): SceneNode\n updateNode(nodeId: string, changes: Partial<SceneNode>): void\n bindVariable(nodeId: string, field: string, variableId: string): void\n}\n\nexport interface TokenImportResult {\n collectionIds: string[]\n variableIds: string[]\n styleNodeIds: string[]\n}\n\n/** Text fields a text style gives the layers that use it. */\nconst TEXT_STYLE_FIELDS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textCase'\n] as const satisfies ReadonlyArray<keyof SceneNode>\n\nfunction targetCollection(target: TokenImportTarget, planned: PlannedCollection): string {\n if (planned.target.kind === 'existing') return planned.target.collectionId\n return target.addCollection(planned.target.name).id\n}\n\n/** Mode ids by planned mode: matched ones, a new collection's first renamed, or new ones. */\nfunction targetModes(\n target: TokenImportTarget,\n planned: PlannedCollection,\n collectionId: string\n): string[] {\n const collection = target.graph.variableCollections.get(collectionId)\n let unclaimed = planned.target.kind === 'new' ? (collection?.defaultModeId ?? null) : null\n const modeIds = planned.modes.map((mode) => {\n if (mode.target.kind === 'existing') return mode.target.modeId\n if (unclaimed) {\n const modeId = unclaimed\n unclaimed = null\n target.renameMode(collectionId, modeId, mode.target.name)\n return modeId\n }\n return target.addMode(collectionId, mode.target.name) ?? ''\n })\n planned.modes.forEach((mode, index) => {\n if (mode.condition) target.setModeCondition(collectionId, modeIds[index], mode.condition)\n })\n if (planned.target.kind === 'new') {\n const defaultIndex = planned.modes.findIndex((mode) => mode.isDefault)\n if (defaultIndex > 0) target.setDefaultMode(collectionId, modeIds[defaultIndex])\n if (planned.modeAttribute) target.setModeAttribute(collectionId, planned.modeAttribute)\n }\n return modeIds\n}\n\nfunction aliasId(target: AliasTarget, created: ReadonlyArray<ReadonlyArray<Variable>>) {\n if (target.kind === 'variable') return target.variableId\n return created.at(target.collection)?.at(target.variable)?.id\n}\n\nfunction plannedValue(\n value: NonNullable<PlannedVariable['values'][number]>,\n created: ReadonlyArray<ReadonlyArray<Variable>>\n): VariableValue | undefined {\n if (value.kind === 'literal') return value.value\n const id = aliasId(value.target, created)\n return id ? { aliasId: id } : undefined\n}\n\nfunction applyVariables(target: TokenImportTarget, plan: TokenImportPlan) {\n const collectionIds = plan.collections.map((planned) => targetCollection(target, planned))\n const modeIds = plan.collections.map((planned, index) =>\n targetModes(target, planned, collectionIds[index])\n )\n // Every variable exists before any value is set, so aliases can point at later ones.\n const created = plan.collections.map((planned, index) =>\n planned.variables.map((variable) =>\n variable.existingId\n ? (target.graph.variables.get(variable.existingId) ??\n target.addVariable(variable, collectionIds[index]))\n : target.addVariable(variable, collectionIds[index])\n )\n )\n plan.collections.forEach((planned, collectionIndex) => {\n planned.variables.forEach((variable, variableIndex) => {\n const made = created[collectionIndex][variableIndex]\n const modes = modeIds[collectionIndex]\n variable.values.forEach((value, modeIndex) => {\n const next = value && plannedValue(value, created)\n const modeId = modes[modeIndex]\n if (next !== undefined && modeId && !isEqual(made.valuesByMode[modeId], next))\n target.setValue(made.id, modeId, next)\n })\n const expressions = Object.fromEntries(\n variable.expressions.flatMap((css, modeIndex) => {\n const resolved = made.valuesByMode[modes[modeIndex]]\n return css && typeof resolved === 'number' ? [[modes[modeIndex], { css, resolved }]] : []\n })\n )\n const fields: ImportedTokenFields = {\n unit: variable.unit,\n scopes: variable.scopes,\n codeSyntax: variable.codeSyntax,\n hiddenFromPublishing: variable.hiddenFromPublishing ?? false,\n description: variable.description ?? made.description\n }\n if (!isEmptyObject(expressions)) fields.expressions = expressions\n target.setTokenFields(made.id, fields)\n })\n })\n return { collectionIds, created }\n}\n\n/** The fields a style gives each layer that uses it, with the reference that keeps it attached. */\nfunction consumerPatch(style: SceneNode, kind: PlannedStyle['kind']): Partial<SceneNode> {\n if (kind === 'EFFECT')\n return { effects: copyEffects(style.effects), effectStyleId: style.source.id }\n const fields: Partial<SceneNode> = { textStyleId: style.source.id }\n for (const field of TEXT_STYLE_FIELDS) Object.assign(fields, { [field]: style[field] })\n return fields\n}\n\n/** The fields of `changes` that differ from what `node` holds, or null when none do. */\nfunction changedFields(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> | null {\n const changed = Object.fromEntries(\n Object.entries(changes).filter(([key, value]) => !isEqual(node[key as keyof SceneNode], value))\n )\n return isEmptyObject(changed) ? null : changed\n}\n\n/**\n * Layers that use a style and hold its values themselves. Layers inside an instance follow their\n * component instead, and changing them would make overrides of what should stay inherited.\n */\nfunction refKeyOf(kind: PlannedStyle['kind']) {\n return kind === 'TEXT' ? ('textStyleId' as const) : ('effectStyleId' as const)\n}\n\nfunction styleConsumers(graph: SceneGraph, style: SceneNode, kind: PlannedStyle['kind']) {\n const refKey = refKeyOf(kind)\n return [...graph.getAllNodes()].filter(\n (node) =>\n node[refKey] === style.source.id &&\n node.id !== style.id &&\n !findInstanceAncestor(graph, node.id)\n )\n}\n\nfunction applyStyles(\n target: TokenImportTarget,\n plan: TokenImportPlan,\n created: ReadonlyArray<ReadonlyArray<Variable>>\n): string[] {\n return plan.styles.map((style) => {\n const existing = style.existingNodeId ? target.graph.getNode(style.existingNodeId) : undefined\n const node = existing ?? target.addStyle(style, { ...style.fields, name: style.name })\n const own = existing && changedFields(existing, style.fields)\n if (own) target.updateNode(node.id, own)\n for (const [field, alias] of Object.entries(style.bindings)) {\n const variableId = aliasId(alias, created)\n if (variableId && node.boundVariables[field] !== variableId)\n target.bindVariable(node.id, field, variableId)\n }\n if (own && node.source.id) {\n const patch = consumerPatch(node, style.kind)\n for (const consumer of styleConsumers(target.graph, node, style.kind)) {\n const changes = changedFields(consumer, patch)\n // The style reference always goes along, or changing styled fields would detach it.\n if (changes)\n target.updateNode(consumer.id, { ...changes, ...pick(patch, [refKeyOf(style.kind)]) })\n }\n }\n return node.id\n })\n}\n\n/**\n * Applies an import plan: collections and modes first, then every variable, then their values,\n * so an alias can point at a variable the same import adds, and last the styles, whose bindings\n * and the layers that use them follow. Nothing is deleted.\n */\nexport function applyTokenImport(\n target: TokenImportTarget,\n plan: TokenImportPlan\n): TokenImportResult {\n const { collectionIds, created } = applyVariables(target, plan)\n const styleNodeIds = applyStyles(target, plan, created)\n return {\n collectionIds,\n variableIds: compact(created.flat().map((variable) => variable.id)),\n styleNodeIds\n }\n}\n\n/** A style node: hidden from the layer list, found by its style id, as `.fig` styles are. */\nexport function styleNodeProps(\n style: PlannedStyle,\n fields: Partial<SceneNode>\n): Partial<SceneNode> {\n return { ...fields, sharedStyleType: style.kind, internalOnly: true }\n}\n\nexport function styleNodeType(style: PlannedStyle) {\n return style.kind === 'TEXT' ? ('TEXT' as const) : ('RECTANGLE' as const)\n}\n\n/** The changes made directly on a graph, without history. */\nfunction graphTokenImportTarget(\n graph: SceneGraph,\n pageId: string,\n changed: Set<string>\n): TokenImportTarget {\n const collection = (id: string) => graph.variableCollections.get(id)\n return {\n graph,\n addCollection: (name) => graph.createCollection(name),\n addMode: (collectionId, name) => graph.createMode(collectionId, name),\n renameMode: (collectionId, modeId, name) => graph.renameMode(collectionId, modeId, name),\n setDefaultMode: (collectionId, modeId) => graph.setDefaultMode(collectionId, modeId),\n setModeCondition: (collectionId, modeId, condition) => {\n const mode = collection(collectionId)?.modes.find((entry) => entry.modeId === modeId)\n if (mode) mode.condition = condition\n },\n setModeAttribute: (collectionId, name) => {\n const found = collection(collectionId)\n if (found) found.modeAttribute = name\n },\n addVariable: (planned, collectionId) =>\n graph.createVariable(planned.name, planned.type, collectionId),\n setValue: (variableId, modeId, value) => {\n const variable = graph.variables.get(variableId)\n if (!variable) return\n variable.valuesByMode[modeId] = structuredClone(value)\n changed.add(variableId)\n },\n setTokenFields: (variableId, fields) => {\n const variable = graph.variables.get(variableId)\n if (!variable) return\n for (const [key, value] of Object.entries(fields))\n if (value === undefined) Reflect.deleteProperty(variable, key)\n else Object.assign(variable, { [key]: structuredClone(value) })\n },\n addStyle: (style, fields) => {\n const node = graph.createNode(styleNodeType(style), pageId, styleNodeProps(style, fields))\n node.source.id = `style:${randomHex(12)}`\n return node\n },\n updateNode: (nodeId, changes) => graph.updateNode(nodeId, changes),\n bindVariable: (nodeId, field, variableId) => graph.bindVariable(nodeId, field, variableId)\n }\n}\n\n/**\n * Imports straight into a graph, for scripts, tools, and the CLI working on a document without\n * an editor; the layers bound to variables whose values changed are resolved and laid out\n * afterwards.\n */\nexport function importTokensIntoGraph(\n graph: SceneGraph,\n pageId: string,\n plan: TokenImportPlan\n): TokenImportResult {\n const changed = new Set<string>()\n const result = applyTokenImport(graphTokenImportTarget(graph, pageId, changed), plan)\n if (changed.size > 0) reconcileVariableLayouts(graph, { variables: changed })\n return result\n}\n"],"mappings":";;;;;;;;;AA6DA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,iBAAiB,QAA2B,SAAoC;CACvF,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,QAAQ,OAAO;CAC9D,OAAO,OAAO,cAAc,QAAQ,OAAO,IAAI,CAAC,CAAC;AACnD;;AAGA,SAAS,YACP,QACA,SACA,cACU;CACV,MAAM,aAAa,OAAO,MAAM,oBAAoB,IAAI,YAAY;CACpE,IAAI,YAAY,QAAQ,OAAO,SAAS,QAAS,YAAY,iBAAiB,OAAQ;CACtF,MAAM,UAAU,QAAQ,MAAM,KAAK,SAAS;EAC1C,IAAI,KAAK,OAAO,SAAS,YAAY,OAAO,KAAK,OAAO;EACxD,IAAI,WAAW;GACb,MAAM,SAAS;GACf,YAAY;GACZ,OAAO,WAAW,cAAc,QAAQ,KAAK,OAAO,IAAI;GACxD,OAAO;EACT;EACA,OAAO,OAAO,QAAQ,cAAc,KAAK,OAAO,IAAI,KAAK;CAC3D,CAAC;C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UAAU,OAAO,QAAQ,MAAM,GAC9C,IAAI,UAAU,KAAA,GAAW,QAAQ,eAAe,UAAU,GAAG;QACxD,OAAO,OAAO,UAAU,GAAG,MAAM,gBAAgB,KAAK,EAAE,CAAC;EAClE;EACA,WAAW,OAAO,WAAW;GAC3B,MAAM,OAAO,MAAM,WAAW,cAAc,KAAK,GAAG,QAAQ,eAAe,OAAO,MAAM,CAAC;GACzF,KAAK,OAAO,KAAK,SAAS,UAAU,EAAE;GACtC,OAAO;EACT;EACA,aAAa,QAAQ,YAAY,MAAM,WAAW,QAAQ,OAAO;EACjE,eAAe,QAAQ,OAAO,eAAe,MAAM,aAAa,QAAQ,OAAO,UAAU;CAC3F;AACF;;;;;;AAOA,SAAgB,sBACd,OACA,QACA,MACmB;CACnB,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,SAAS,iBAAiB,uBAAuB,OAAO,QAAQ,OAAO,GAAG,IAAI;CACpF,IAAI,QAAQ,OAAO,GAAG,yBAAyB,OAAO,EAAE,WAAW,QAAQ,CAAC;CAC5E,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"apply.js","names":[],"sources":["../../../../src/io/formats/design-tokens/apply.ts"],"sourcesContent":["import { compact } from 'es-toolkit/array'\nimport { pick } from 'es-toolkit/object'\nimport { isEmptyObject, isEqual } from 'es-toolkit/predicate'\n\nimport type {\n CodeSyntaxPlatform,\n SceneGraph,\n SceneNode,\n SharedStyleType,\n TokenExpression,\n TokenUnit,\n Variable,\n VariableCollection,\n VariableScope,\n VariableValue\n} from '@pairdraw/scene-graph'\nimport { copyEffects } from '@pairdraw/scene-graph/copy'\nimport { findInstanceAncestor } from '@pairdraw/scene-graph/instances'\nimport { randomHex } from '@pairdraw/scene-graph/random'\n\nimport { reconcileVariableLayouts } from '#core/layout/variables'\n\nimport type { AliasTarget, PlannedCollection, PlannedVariable, TokenImportPlan } from './plan'\nimport type { PlannedStyle } from './plan/styles'\n\n/** Token fields an import sets; `undefined` clears one. */\nexport interface ImportedTokenFields {\n unit?: TokenUnit\n scopes?: VariableScope[]\n codeSyntax?: Partial<Record<CodeSyntaxPlatform, string>>\n hiddenFromPublishing?: boolean\n description?: string\n expressions?: Record<string, TokenExpression>\n}\n\n/**\n * The changes an import makes, so the editor can make them undoable and a headless document can\n * make them directly. Each adds to or changes the document; none deletes.\n */\nexport interface TokenImportTarget {\n graph: SceneGraph\n addCollection(name: string): VariableCollection\n addMode(collectionId: string, name: string): string | undefined\n renameMode(collectionId: string, modeId: string, name: string): void\n setDefaultMode(collectionId: string, modeId: string): void\n setModeCondition(collectionId: string, modeId: string, condition: string): void\n setModeAttribute(collectionId: string, name: string): void\n addVariable(planned: PlannedVariable, collectionId: string): Variable\n setValue(variableId: string, modeId: string, value: VariableValue): void\n setTokenFields(variableId: string, fields: ImportedTokenFields): void\n addStyle(style: PlannedStyle, fields: Partial<SceneNode>): SceneNode\n updateNode(nodeId: string, changes: Partial<SceneNode>): void\n bindVariable(nodeId: string, field: string, variableId: string): void\n}\n\nexport interface TokenImportResult {\n collectionIds: string[]\n variableIds: string[]\n styleNodeIds: string[]\n}\n\n/** Text fields a text style gives the layers that use it. */\nconst TEXT_STYLE_FIELDS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textCase'\n] as const satisfies ReadonlyArray<keyof SceneNode>\n\nfunction targetCollection(target: TokenImportTarget, planned: PlannedCollection): string {\n if (planned.target.kind === 'existing') return planned.target.collectionId\n return target.addCollection(planned.target.name).id\n}\n\n/** Mode ids by planned mode: matched ones, a new collection's first renamed, or new ones. */\nfunction targetModes(\n target: TokenImportTarget,\n planned: PlannedCollection,\n collectionId: string\n): string[] {\n const collection = target.graph.variableCollections.get(collectionId)\n let unclaimed = planned.target.kind === 'new' ? (collection?.defaultModeId ?? null) : null\n const modeIds = planned.modes.map((mode) => {\n if (mode.target.kind === 'existing') return mode.target.modeId\n if (unclaimed) {\n const modeId = unclaimed\n unclaimed = null\n target.renameMode(collectionId, modeId, mode.target.name)\n return modeId\n }\n return target.addMode(collectionId, mode.target.name) ?? ''\n })\n planned.modes.forEach((mode, index) => {\n if (mode.condition) target.setModeCondition(collectionId, modeIds[index], mode.condition)\n })\n if (planned.target.kind === 'new') {\n const defaultIndex = planned.modes.findIndex((mode) => mode.isDefault)\n if (defaultIndex > 0) target.setDefaultMode(collectionId, modeIds[defaultIndex])\n if (planned.modeAttribute) target.setModeAttribute(collectionId, planned.modeAttribute)\n }\n return modeIds\n}\n\nfunction aliasId(target: AliasTarget, created: ReadonlyArray<ReadonlyArray<Variable>>) {\n if (target.kind === 'variable') return target.variableId\n return created.at(target.collection)?.at(target.variable)?.id\n}\n\nfunction plannedValue(\n value: NonNullable<PlannedVariable['values'][number]>,\n created: ReadonlyArray<ReadonlyArray<Variable>>\n): VariableValue | undefined {\n if (value.kind === 'literal') return value.value\n const id = aliasId(value.target, created)\n return id ? { aliasId: id } : undefined\n}\n\nfunction applyVariables(target: TokenImportTarget, plan: TokenImportPlan) {\n const collectionIds = plan.collections.map((planned) => targetCollection(target, planned))\n const modeIds = plan.collections.map((planned, index) =>\n targetModes(target, planned, collectionIds[index])\n )\n // Every variable exists before any value is set, so aliases can point at later ones.\n const created = plan.collections.map((planned, index) =>\n planned.variables.map((variable) =>\n variable.existingId\n ? (target.graph.variables.get(variable.existingId) ??\n target.addVariable(variable, collectionIds[index]))\n : target.addVariable(variable, collectionIds[index])\n )\n )\n plan.collections.forEach((planned, collectionIndex) => {\n planned.variables.forEach((variable, variableIndex) => {\n const made = created[collectionIndex][variableIndex]\n const modes = modeIds[collectionIndex]\n variable.values.forEach((value, modeIndex) => {\n const next = value && plannedValue(value, created)\n const modeId = modes[modeIndex]\n if (next !== undefined && modeId && !isEqual(made.valuesByMode[modeId], next))\n target.setValue(made.id, modeId, next)\n })\n const expressions = Object.fromEntries(\n variable.expressions.flatMap((css, modeIndex) => {\n const resolved = made.valuesByMode[modes[modeIndex]]\n return css && typeof resolved === 'number' ? [[modes[modeIndex], { css, resolved }]] : []\n })\n )\n const fields: ImportedTokenFields = {\n unit: variable.unit,\n scopes: variable.scopes,\n codeSyntax: variable.codeSyntax,\n hiddenFromPublishing: variable.hiddenFromPublishing ?? false,\n description: variable.description ?? made.description\n }\n if (!isEmptyObject(expressions)) fields.expressions = expressions\n target.setTokenFields(made.id, fields)\n })\n })\n return { collectionIds, created }\n}\n\n/** The fields a style gives each layer that uses it, with the reference that keeps it attached. */\nfunction consumerPatch(style: SceneNode, kind: PlannedStyle['kind']): Partial<SceneNode> {\n if (kind === 'EFFECT')\n return { effects: copyEffects(style.effects), effectStyleId: style.source.id }\n const fields: Partial<SceneNode> = { textStyleId: style.source.id }\n for (const field of TEXT_STYLE_FIELDS) Object.assign(fields, { [field]: style[field] })\n return fields\n}\n\n/** The fields of `changes` that differ from what `node` holds, or null when none do. */\nfunction changedFields(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> | null {\n const changed = Object.fromEntries(\n Object.entries(changes).filter(([key, value]) => !isEqual(node[key as keyof SceneNode], value))\n )\n return isEmptyObject(changed) ? null : changed\n}\n\n/**\n * Layers that use a style and hold its values themselves. Layers inside an instance follow their\n * component instead, and changing them would make overrides of what should stay inherited.\n */\nfunction refKeyOf(kind: PlannedStyle['kind']) {\n return kind === 'TEXT' ? ('textStyleId' as const) : ('effectStyleId' as const)\n}\n\nfunction styleConsumers(graph: SceneGraph, style: SceneNode, kind: PlannedStyle['kind']) {\n const refKey = refKeyOf(kind)\n return [...graph.getAllNodes()].filter(\n (node) =>\n node[refKey] === style.source.id &&\n node.id !== style.id &&\n !findInstanceAncestor(graph, node.id)\n )\n}\n\nfunction applyStyles(\n target: TokenImportTarget,\n plan: TokenImportPlan,\n created: ReadonlyArray<ReadonlyArray<Variable>>\n): string[] {\n return plan.styles.map((style) => {\n const existing = style.existingNodeId ? target.graph.getNode(style.existingNodeId) : undefined\n const node = existing ?? target.addStyle(style, { ...style.fields, name: style.name })\n const own = existing && changedFields(existing, style.fields)\n if (own) target.updateNode(node.id, own)\n for (const [field, alias] of Object.entries(style.bindings)) {\n const variableId = aliasId(alias, created)\n if (variableId && node.boundVariables[field] !== variableId)\n target.bindVariable(node.id, field, variableId)\n }\n if (own && node.source.id) {\n const patch = consumerPatch(node, style.kind)\n for (const consumer of styleConsumers(target.graph, node, style.kind)) {\n const changes = changedFields(consumer, patch)\n // The style reference always goes along, or changing styled fields would detach it.\n if (changes)\n target.updateNode(consumer.id, { ...changes, ...pick(patch, [refKeyOf(style.kind)]) })\n }\n }\n return node.id\n })\n}\n\n/**\n * Applies an import plan: collections and modes first, then every variable, then their values,\n * so an alias can point at a variable the same import adds, and last the styles, whose bindings\n * and the layers that use them follow. Nothing is deleted.\n */\nexport function applyTokenImport(\n target: TokenImportTarget,\n plan: TokenImportPlan\n): TokenImportResult {\n const { collectionIds, created } = applyVariables(target, plan)\n const styleNodeIds = applyStyles(target, plan, created)\n return {\n collectionIds,\n variableIds: compact(created.flat().map((variable) => variable.id)),\n styleNodeIds\n }\n}\n\n/** A style node: hidden from the layer list, found by its style id, as `.fig` styles are. */\nexport function styleNodeProps(\n style: Pick<PlannedStyle, 'kind'> | { kind: SharedStyleType },\n fields: Partial<SceneNode>\n): Partial<SceneNode> {\n return { ...fields, sharedStyleType: style.kind, internalOnly: true }\n}\n\nexport function styleNodeType(style: Pick<PlannedStyle, 'kind'> | { kind: SharedStyleType }) {\n return style.kind === 'TEXT' ? ('TEXT' as const) : ('RECTANGLE' as const)\n}\n\n/** The changes made directly on a graph, without history. */\nfunction graphTokenImportTarget(\n graph: SceneGraph,\n pageId: string,\n changed: Set<string>\n): TokenImportTarget {\n const collection = (id: string) => graph.variableCollections.get(id)\n return {\n graph,\n addCollection: (name) => graph.createCollection(name),\n addMode: (collectionId, name) => graph.createMode(collectionId, name),\n renameMode: (collectionId, modeId, name) => graph.renameMode(collectionId, modeId, name),\n setDefaultMode: (collectionId, modeId) => graph.setDefaultMode(collectionId, modeId),\n setModeCondition: (collectionId, modeId, condition) => {\n const mode = collection(collectionId)?.modes.find((entry) => entry.modeId === modeId)\n if (mode) mode.condition = condition\n },\n setModeAttribute: (collectionId, name) => {\n const found = collection(collectionId)\n if (found) found.modeAttribute = name\n },\n addVariable: (planned, collectionId) =>\n graph.createVariable(planned.name, planned.type, collectionId),\n setValue: (variableId, modeId, value) => {\n const variable = graph.variables.get(variableId)\n if (!variable) return\n variable.valuesByMode[modeId] = structuredClone(value)\n changed.add(variableId)\n },\n setTokenFields: (variableId, fields) => {\n const variable = graph.variables.get(variableId)\n if (!variable) return\n for (const [key, value] of Object.entries(fields))\n if (value === undefined) Reflect.deleteProperty(variable, key)\n else Object.assign(variable, { [key]: structuredClone(value) })\n },\n addStyle: (style, fields) => {\n const node = graph.createNode(styleNodeType(style), pageId, styleNodeProps(style, fields))\n node.source.id = `style:${randomHex(12)}`\n return node\n },\n updateNode: (nodeId, changes) => graph.updateNode(nodeId, changes),\n bindVariable: (nodeId, field, variableId) => graph.bindVariable(nodeId, field, variableId)\n }\n}\n\n/**\n * Imports straight into a graph, for scripts, tools, and the CLI working on a document without\n * an editor; the layers bound to variables whose values changed are resolved and laid out\n * afterwards.\n */\nexport function importTokensIntoGraph(\n graph: SceneGraph,\n pageId: string,\n plan: TokenImportPlan\n): TokenImportResult {\n const changed = new Set<string>()\n const result = applyTokenImport(graphTokenImportTarget(graph, pageId, changed), plan)\n if (changed.size > 0) reconcileVariableLayouts(graph, { variables: changed })\n return result\n}\n"],"mappings":";;;;;;;;;AA8DA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,iBAAiB,QAA2B,SAAoC;CACvF,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,QAAQ,OAAO;CAC9D,OAAO,OAAO,cAAc,QAAQ,OAAO,IAAI,CAAC,CAAC;AACnD;;AAGA,SAAS,YACP,QACA,SACA,cACU;CACV,MAAM,aAAa,OAAO,MAAM,oBAA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C;EACA,cAAc,SAAS,iBACrB,MAAM,eAAe,QAAQ,MAAM,QAAQ,MAAM,YAAY;EAC/D,WAAW,YAAY,QAAQ,UAAU;GACvC,MAAM,WAAW,MAAM,UAAU,IAAI,UAAU;GAC/C,IAAI,CAAC,UAAU;GACf,SAAS,aAAa,UAAU,gBAAgB,KAAK;GACrD,QAAQ,IAAI,UAAU;EACxB;EACA,iBAAiB,YAAY,WAAW;GACtC,MAAM,WAAW,MAAM,UAAU,IAAI,UAAU;GAC/C,IAAI,CAAC,UAAU;GACf,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAC9C,IAAI,UAAU,KAAA,GAAW,QAAQ,eAAe,UAAU,GAAG;QACxD,OAAO,OAAO,UAAU,GAAG,MAAM,gBAAgB,KAAK,EAAE,CAAC;EAClE;EACA,WAAW,OAAO,WAAW;GAC3B,MAAM,OAAO,MAAM,WAAW,cAAc,KAAK,GAAG,QAAQ,eAAe,OAAO,MAAM,CAAC;GACzF,KAAK,OAAO,KAAK,SAAS,UAAU,EAAE;GACtC,OAAO;EACT;EACA,aAAa,QAAQ,YAAY,MAAM,WAAW,QAAQ,OAAO;EACjE,eAAe,QAAQ,OAAO,eAAe,MAAM,aAAa,QAAQ,OAAO,UAAU;CAC3F;AACF;;;;;;AAOA,SAAgB,sBACd,OACA,QACA,MACmB;CACnB,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,SAAS,iBAAiB,uBAAuB,OAAO,QAAQ,OAAO,GAAG,IAAI;CACpF,IAAI,QAAQ,OAAO,GAAG,yBAAyB,OAAO,EAAE,WAAW,QAAQ,CAAC;CAC5E,OAAO;AACT"}
|
|
@@ -136,6 +136,11 @@ async function narrowToChangedFields(source, runtime, info, recordOwners, writte
|
|
|
136
136
|
const fields = [];
|
|
137
137
|
for (const record of written) {
|
|
138
138
|
const id = record.guid ? guidToString(record.guid) : null;
|
|
139
|
+
const owner = id ? recordOwners.get(id) : void 0;
|
|
140
|
+
if (owner && source.getNode(owner)?.source.editedFields.includes("componentPropertyAssignments")) {
|
|
141
|
+
records.push(record);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
139
144
|
const saved = id ? baseline?.get(id) : void 0;
|
|
140
145
|
if (!saved || !record.guid) {
|
|
141
146
|
records.push(record);
|