@pairdraw/core 0.21.0 → 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/canvas/shaders/compile.d.ts +3 -1
- package/dist/canvas/shaders/compile.d.ts.map +1 -1
- package/dist/canvas/shaders/compile.js +12 -3
- package/dist/canvas/shaders/compile.js.map +1 -1
- package/dist/canvas/shaders/draw.d.ts.map +1 -1
- package/dist/canvas/shaders/draw.js +10 -3
- package/dist/canvas/shaders/draw.js.map +1 -1
- package/dist/canvas/shaders/effect.d.ts.map +1 -1
- package/dist/canvas/shaders/effect.js +6 -16
- package/dist/canvas/shaders/effect.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/bridges/undo.d.ts +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/export.js +2 -2
- package/dist/editor/clipboard/export.js.map +1 -1
- 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 +30 -3
- 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/drawio/warnings.d.ts +17 -2
- package/dist/io/formats/drawio/warnings.d.ts.map +1 -1
- package/dist/io/formats/drawio/warnings.js +14 -7
- package/dist/io/formats/drawio/warnings.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/index.d.ts +1 -0
- package/dist/io/formats/html/index.d.ts.map +1 -1
- package/dist/io/formats/html/index.js +5 -3
- package/dist/io/formats/html/index.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/pen/index.d.ts.map +1 -1
- package/dist/io/formats/pen/index.js +13 -4
- package/dist/io/formats/pen/index.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 +30 -17
- package/dist/io/formats.js.map +1 -1
- package/dist/io/index.d.ts +2 -2
- package/dist/io/types.d.ts +11 -2
- package/dist/io/types.d.ts.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/canvas/shaders/compile.ts +14 -3
- package/src/canvas/shaders/draw.ts +11 -4
- package/src/canvas/shaders/effect.ts +6 -18
- 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/export.ts +2 -2
- 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/drawio/warnings.ts +27 -8
- 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/index.ts +9 -3
- 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/pen/index.ts +14 -6
- 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 +45 -19
- package/src/io/index.ts +1 -0
- package/src/io/types.ts +10 -0
- 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/src/layout/grid.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Align,
|
|
3
|
+
Direction,
|
|
4
|
+
Display,
|
|
5
|
+
FlexDirection,
|
|
6
|
+
Gutter,
|
|
7
|
+
Justify,
|
|
8
|
+
type Node as YogaNode
|
|
9
|
+
} from 'yoga-layout'
|
|
2
10
|
|
|
3
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
GridChildAlign,
|
|
13
|
+
GridPosition,
|
|
14
|
+
GridTrack,
|
|
15
|
+
SceneGraph,
|
|
16
|
+
SceneNode
|
|
17
|
+
} from '@pairdraw/scene-graph'
|
|
4
18
|
import { layoutSizing } from '@pairdraw/scene-graph/layout'
|
|
5
19
|
import { resolveNodeLayoutDirection } from '@pairdraw/scene-graph/text/direction'
|
|
6
20
|
|
|
@@ -56,28 +70,29 @@ function configureAsGrid(
|
|
|
56
70
|
applyMinMaxConstraints(yogaNode, node)
|
|
57
71
|
}
|
|
58
72
|
|
|
73
|
+
function applyGridPlacement(yogaNode: YogaNode, pos: GridPosition): void {
|
|
74
|
+
// A span from an explicit line ends N lines on; from an auto line it is CSS
|
|
75
|
+
// `grid-column: span N`, which Yoga places by itself.
|
|
76
|
+
if (pos.column > 0) {
|
|
77
|
+
yogaNode.setGridColumnStart(pos.column)
|
|
78
|
+
yogaNode.setGridColumnEndSpan(pos.columnSpan)
|
|
79
|
+
} else if (pos.columnSpan > 1) {
|
|
80
|
+
yogaNode.setGridColumnStartSpan(pos.columnSpan)
|
|
81
|
+
}
|
|
82
|
+
if (pos.row > 0) {
|
|
83
|
+
yogaNode.setGridRowStart(pos.row)
|
|
84
|
+
yogaNode.setGridRowEndSpan(pos.rowSpan)
|
|
85
|
+
} else if (pos.rowSpan > 1) {
|
|
86
|
+
yogaNode.setGridRowStartSpan(pos.rowSpan)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
59
90
|
export function createGridChildNode(graph: SceneGraph, child: SceneNode): YogaNode {
|
|
60
91
|
const yogaChild = createYogaNode()
|
|
61
92
|
if (!child.visible) {
|
|
62
93
|
yogaChild.setDisplay(Display.None)
|
|
63
94
|
} else {
|
|
64
|
-
|
|
65
|
-
if (pos) {
|
|
66
|
-
// A span from an explicit line ends N lines on; from an auto line it is CSS
|
|
67
|
-
// `grid-column: span N`, which Yoga places by itself.
|
|
68
|
-
if (pos.column > 0) {
|
|
69
|
-
yogaChild.setGridColumnStart(pos.column)
|
|
70
|
-
yogaChild.setGridColumnEndSpan(pos.columnSpan)
|
|
71
|
-
} else if (pos.columnSpan > 1) {
|
|
72
|
-
yogaChild.setGridColumnStartSpan(pos.columnSpan)
|
|
73
|
-
}
|
|
74
|
-
if (pos.row > 0) {
|
|
75
|
-
yogaChild.setGridRowStart(pos.row)
|
|
76
|
-
yogaChild.setGridRowEndSpan(pos.rowSpan)
|
|
77
|
-
} else if (pos.rowSpan > 1) {
|
|
78
|
-
yogaChild.setGridRowStartSpan(pos.rowSpan)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
95
|
+
if (child.gridPosition) applyGridPlacement(yogaChild, child.gridPosition)
|
|
81
96
|
// Each axis fills its cell on its own, as in Figma: grow for width, stretch for height.
|
|
82
97
|
if (layoutSizing(graph, child, 'HORIZONTAL') === 'FILL') yogaChild.setWidthStretch()
|
|
83
98
|
else yogaChild.setWidth(child.width)
|
|
@@ -87,6 +102,60 @@ export function createGridChildNode(graph: SceneGraph, child: SceneNode): YogaNo
|
|
|
87
102
|
return yogaChild
|
|
88
103
|
}
|
|
89
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Yoga's grid ignores `justifySelf`/`alignSelf`, so an aligned child gets a wrapper that fills its
|
|
107
|
+
* cell and lays the child out inside it. The wrapper's box is the cell, and this map reaches the
|
|
108
|
+
* child's own box inside.
|
|
109
|
+
*/
|
|
110
|
+
const gridChildBoxes = new WeakMap<YogaNode, YogaNode>()
|
|
111
|
+
|
|
112
|
+
/** The box of the layer inside an aligned child's cell wrapper, if it has one. */
|
|
113
|
+
export function gridChildBox(wrapper: YogaNode): YogaNode | undefined {
|
|
114
|
+
return gridChildBoxes.get(wrapper)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function alignOrAuto(value: GridChildAlign | undefined): GridChildAlign {
|
|
118
|
+
return value ?? 'AUTO'
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function needsCellWrapper(child: SceneNode): boolean {
|
|
122
|
+
// A node built before the field existed has no value: that is AUTO, and it keeps no wrapper.
|
|
123
|
+
return (
|
|
124
|
+
child.visible &&
|
|
125
|
+
child.layoutPositioning !== 'ABSOLUTE' &&
|
|
126
|
+
(alignOrAuto(child.gridChildHorizontalAlign) !== 'AUTO' ||
|
|
127
|
+
alignOrAuto(child.gridChildVerticalAlign) !== 'AUTO')
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function justifyContent(value: GridChildAlign): Justify {
|
|
132
|
+
if (value === 'CENTER') return Justify.Center
|
|
133
|
+
if (value === 'MAX') return Justify.FlexEnd
|
|
134
|
+
return Justify.FlexStart
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function alignItems(value: GridChildAlign): Align {
|
|
138
|
+
if (value === 'CENTER') return Align.Center
|
|
139
|
+
if (value === 'MAX') return Align.FlexEnd
|
|
140
|
+
return Align.FlexStart
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The child inside a wrapper that fills its cell and aligns the child in it. */
|
|
144
|
+
function wrapGridChild(child: SceneNode, yogaChild: YogaNode): YogaNode {
|
|
145
|
+
const wrapper = createYogaNode()
|
|
146
|
+
wrapper.setDisplay(Display.Flex)
|
|
147
|
+
wrapper.setFlexDirection(FlexDirection.Row)
|
|
148
|
+
wrapper.setWidthStretch()
|
|
149
|
+
wrapper.setHeightStretch()
|
|
150
|
+
wrapper.setJustifyContent(justifyContent(child.gridChildHorizontalAlign))
|
|
151
|
+
wrapper.setAlignItems(alignItems(child.gridChildVerticalAlign))
|
|
152
|
+
// The wrapper is the grid item, so the cell placement belongs on it, not on the layer inside.
|
|
153
|
+
if (child.gridPosition) applyGridPlacement(wrapper, child.gridPosition)
|
|
154
|
+
wrapper.insertChild(yogaChild, 0)
|
|
155
|
+
gridChildBoxes.set(wrapper, yogaChild)
|
|
156
|
+
return wrapper
|
|
157
|
+
}
|
|
158
|
+
|
|
90
159
|
export function buildGridTree(
|
|
91
160
|
graph: SceneGraph,
|
|
92
161
|
frame: SceneNode,
|
|
@@ -96,14 +165,15 @@ export function buildGridTree(
|
|
|
96
165
|
const direction = resolveNodeLayoutDirection(frame, inheritedDirection)
|
|
97
166
|
configureAsGrid(graph, root, frame, direction)
|
|
98
167
|
|
|
99
|
-
const children = graph.getChildren(frame.id)
|
|
168
|
+
const children = graph.getChildren(frame.id).filter((child) => child.type !== 'SLICE')
|
|
100
169
|
for (const child of children) {
|
|
101
170
|
if (child.layoutPositioning === 'ABSOLUTE') {
|
|
102
171
|
const yogaChild = createYogaNode()
|
|
103
172
|
configureAbsoluteChild(yogaChild, child)
|
|
104
173
|
root.insertChild(yogaChild, root.getChildCount())
|
|
105
174
|
} else {
|
|
106
|
-
|
|
175
|
+
let yogaChild = createGridChildNode(graph, child)
|
|
176
|
+
if (needsCellWrapper(child)) yogaChild = wrapGridChild(child, yogaChild)
|
|
107
177
|
applyStrokeMargins(yogaChild, child, frame)
|
|
108
178
|
if (
|
|
109
179
|
child.layoutMode === 'GRID' ||
|
package/src/layout.ts
CHANGED
|
@@ -299,7 +299,7 @@ function configureChildAsGrid(
|
|
|
299
299
|
applyLockedAspectRatio(yogaChild, child, parent)
|
|
300
300
|
applyMinMaxConstraints(yogaChild, child)
|
|
301
301
|
|
|
302
|
-
const grandchildren = graph.getChildren(child.id)
|
|
302
|
+
const grandchildren = graph.getChildren(child.id).filter((gc) => gc.type !== 'SLICE')
|
|
303
303
|
for (const gc of grandchildren) {
|
|
304
304
|
if (gc.layoutPositioning === 'ABSOLUTE') {
|
|
305
305
|
const yogaGC = createYogaNode()
|
|
@@ -342,7 +342,12 @@ function derivedMainAxisFitsParent(
|
|
|
342
342
|
if (!keepsSavedLayout(graph, parent)) return false
|
|
343
343
|
const children = graph
|
|
344
344
|
.getChildren(parent.id)
|
|
345
|
-
.filter(
|
|
345
|
+
.filter(
|
|
346
|
+
(candidate) =>
|
|
347
|
+
candidate.visible &&
|
|
348
|
+
candidate.type !== 'SLICE' &&
|
|
349
|
+
candidate.layoutPositioning !== 'ABSOLUTE'
|
|
350
|
+
)
|
|
346
351
|
if (children.length === 0) return false
|
|
347
352
|
|
|
348
353
|
const sizes = children.map((candidate) => candidate.derivedLayout?.[axis])
|
|
@@ -477,6 +482,9 @@ function insertFlexChildren(
|
|
|
477
482
|
for (const child of graph
|
|
478
483
|
.getChildren(parent.id)
|
|
479
484
|
.map((node) => asLaidOutIn(graph, node, parent))) {
|
|
485
|
+
// A slice is an export region, not an auto-layout child: SliceNode does not extend
|
|
486
|
+
// AutoLayoutChildrenMixin, so it takes no gap, order, or stretch.
|
|
487
|
+
if (child.type === 'SLICE') continue
|
|
480
488
|
const yogaChild = createYogaNode()
|
|
481
489
|
// Attached before it is configured, so a child the depth check refuses still hangs from the
|
|
482
490
|
// root and is freed with it rather than left in WebAssembly memory.
|
|
@@ -512,7 +520,12 @@ function derivedGrowingLeafFitsParent(
|
|
|
512
520
|
}
|
|
513
521
|
const children = graph
|
|
514
522
|
.getChildren(parent.id)
|
|
515
|
-
.filter(
|
|
523
|
+
.filter(
|
|
524
|
+
(candidate) =>
|
|
525
|
+
candidate.visible &&
|
|
526
|
+
candidate.type !== 'SLICE' &&
|
|
527
|
+
candidate.layoutPositioning !== 'ABSOLUTE'
|
|
528
|
+
)
|
|
516
529
|
const sizes = children.map((candidate) => {
|
|
517
530
|
if (candidate.layoutGrow > 0) return candidate.derivedLayout?.[axis]
|
|
518
531
|
return axis === 'width' ? candidate.width : candidate.height
|
package/src/node/fs.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { chmod, lstat, open, realpath, rename, unlink, writeFile } from 'node:fs/promises'
|
|
2
|
-
import { basename, dirname, join } from 'node:path'
|
|
1
|
+
import { chmod, lstat, open, readlink, realpath, rename, unlink, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { basename, dirname, isAbsolute, join } from 'node:path'
|
|
3
3
|
|
|
4
4
|
import { randomHex } from '@pairdraw/scene-graph/random'
|
|
5
5
|
|
|
@@ -18,13 +18,36 @@ function hasCode(error: unknown, ...codes: string[]): boolean {
|
|
|
18
18
|
return error instanceof Error && 'code' in error && codes.includes(String(error.code))
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/** How many links one path may cross; the system limit is 40 on Linux. */
|
|
22
|
+
const MAX_LINK_HOPS = 40
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The file `follow` writes: the link's final target. `realpath` resolves a chain that exists; a
|
|
26
|
+
* dangling link is followed by its own text so writing it creates the target, as `writeFile` does,
|
|
27
|
+
* instead of replacing the link with a regular file.
|
|
28
|
+
*/
|
|
21
29
|
async function resolveTarget(path: string): Promise<string> {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
let current = path
|
|
31
|
+
for (let hops = 0; hops < MAX_LINK_HOPS; hops += 1) {
|
|
32
|
+
try {
|
|
33
|
+
return await realpath(current)
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (!hasCode(error, 'ENOENT')) throw error
|
|
36
|
+
}
|
|
37
|
+
let link: string
|
|
38
|
+
try {
|
|
39
|
+
const stats = await lstat(current)
|
|
40
|
+
if (!stats.isSymbolicLink()) return current
|
|
41
|
+
link = await readlink(current)
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (hasCode(error, 'ENOENT')) return current
|
|
44
|
+
throw error
|
|
45
|
+
}
|
|
46
|
+
current = isAbsolute(link) ? link : join(dirname(current), link)
|
|
27
47
|
}
|
|
48
|
+
const error = new Error(`Too many symbolic links at ${path}`) as NodeJS.ErrnoException
|
|
49
|
+
error.code = 'ELOOP'
|
|
50
|
+
throw error
|
|
28
51
|
}
|
|
29
52
|
|
|
30
53
|
/** The mode of the regular file at `path`, which a symlink or a missing file does not have. */
|
|
@@ -57,6 +80,8 @@ export async function writeFileAtomic(
|
|
|
57
80
|
handle = await open(temporary, 'wx', mode ?? 0o666)
|
|
58
81
|
} catch (error) {
|
|
59
82
|
if (existing === undefined || !hasCode(error, 'EACCES', 'EPERM')) throw error
|
|
83
|
+
// As `writeFile` would: this branch keeps its old behaviour for a directory that takes no new
|
|
84
|
+
// files, so unlike the rename above it follows a link swapped in since the resolve.
|
|
60
85
|
await writeFile(target, data)
|
|
61
86
|
return
|
|
62
87
|
}
|
package/src/prototype/easing.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
PrototypeCubicBezier,
|
|
3
|
+
PrototypeEasingType,
|
|
4
|
+
PrototypeSpring
|
|
5
|
+
} from '@pairdraw/scene-graph'
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_PROTOTYPE_EASING,
|
|
8
|
+
PROTOTYPE_EASING_CURVES,
|
|
9
|
+
PROTOTYPE_SPRING_PRESETS
|
|
10
|
+
} from '@pairdraw/scene-graph/constants'
|
|
3
11
|
|
|
4
12
|
/** Bisection steps that solve a curve's x for its t; 32 halvings are far below a pixel. */
|
|
5
13
|
const BISECTION_STEPS = 32
|
|
@@ -8,15 +16,66 @@ function bezier(t: number, p1: number, p2: number): number {
|
|
|
8
16
|
return 3 * (1 - t) * (1 - t) * t * p1 + 3 * (1 - t) * t * t * p2 + t * t * t
|
|
9
17
|
}
|
|
10
18
|
|
|
19
|
+
/** How a transition's easing plays: its type and the data a custom type needs. */
|
|
20
|
+
export interface EasingPlayback {
|
|
21
|
+
curve?: PrototypeCubicBezier
|
|
22
|
+
spring?: PrototypeSpring
|
|
23
|
+
/** The transition's length in seconds; a spring settles over it. */
|
|
24
|
+
duration?: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function springAt(spring: PrototypeSpring, progress: number, duration: number): number {
|
|
28
|
+
const time = progress * duration
|
|
29
|
+
const { mass, stiffness, damping, initialVelocity } = spring
|
|
30
|
+
if (mass <= 0 || stiffness <= 0) return progress
|
|
31
|
+
const omega = Math.sqrt(stiffness / mass)
|
|
32
|
+
const zeta = damping / (2 * Math.sqrt(stiffness * mass))
|
|
33
|
+
if (zeta < 1) {
|
|
34
|
+
const damped = omega * Math.sqrt(1 - zeta * zeta)
|
|
35
|
+
return (
|
|
36
|
+
1 -
|
|
37
|
+
Math.exp(-zeta * omega * time) *
|
|
38
|
+
(Math.cos(damped * time) +
|
|
39
|
+
((zeta * omega + initialVelocity) / damped) * Math.sin(damped * time))
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
if (zeta === 1) return 1 - Math.exp(-omega * time) * (1 + (omega + initialVelocity) * time)
|
|
43
|
+
// Overdamped: two real roots, not the critical-damping approximation.
|
|
44
|
+
const root = omega * Math.sqrt(zeta * zeta - 1)
|
|
45
|
+
const r1 = -zeta * omega + root
|
|
46
|
+
const r2 = -zeta * omega - root
|
|
47
|
+
const e1 = Math.exp(r1 * time)
|
|
48
|
+
const e2 = Math.exp(r2 * time)
|
|
49
|
+
return 1 + (r2 * e1 - r1 * e2) / (r1 - r2) + (initialVelocity * (e1 - e2)) / (r1 - r2)
|
|
50
|
+
}
|
|
51
|
+
|
|
11
52
|
/**
|
|
12
53
|
* How far along a transition eased by `easing` is at `progress` of its time, from 0 to 1; no
|
|
13
54
|
* easing eases as Figma's default does. The player and a recording both read it, so they move
|
|
14
|
-
* alike.
|
|
55
|
+
* alike. A spring plays its damped-oscillator solution over the transition's own duration, which
|
|
56
|
+
* Figma exposes beside the spring in the transition panel.
|
|
15
57
|
*/
|
|
16
|
-
export function easingAt(
|
|
58
|
+
export function easingAt(
|
|
59
|
+
easing: PrototypeEasingType | undefined,
|
|
60
|
+
progress: number,
|
|
61
|
+
playback: EasingPlayback = {}
|
|
62
|
+
): number {
|
|
17
63
|
if (progress <= 0) return 0
|
|
18
64
|
if (progress >= 1) return 1
|
|
19
|
-
const
|
|
65
|
+
const type = easing ?? DEFAULT_PROTOTYPE_EASING
|
|
66
|
+
if (type === 'CUSTOM_SPRING' || type in PROTOTYPE_SPRING_PRESETS) {
|
|
67
|
+
const spring =
|
|
68
|
+
type === 'CUSTOM_SPRING'
|
|
69
|
+
? (playback.spring ?? PROTOTYPE_SPRING_PRESETS.GENTLE)
|
|
70
|
+
: PROTOTYPE_SPRING_PRESETS[type as keyof typeof PROTOTYPE_SPRING_PRESETS]
|
|
71
|
+
return springAt(spring, progress, playback.duration ?? 0.45)
|
|
72
|
+
}
|
|
73
|
+
const curve = type === 'CUSTOM_CUBIC_BEZIER' && playback.curve ? playback.curve : undefined
|
|
74
|
+
const DEFAULT_CURVE =
|
|
75
|
+
PROTOTYPE_EASING_CURVES[DEFAULT_PROTOTYPE_EASING] ?? ([0, 0, 0.58, 1] as const)
|
|
76
|
+
const [x1, y1, x2, y2] = curve
|
|
77
|
+
? [curve.x1, curve.y1, curve.x2, curve.y2]
|
|
78
|
+
: (PROTOTYPE_EASING_CURVES[type] ?? DEFAULT_CURVE)
|
|
20
79
|
if (x1 === y1 && x2 === y2) return progress
|
|
21
80
|
// x(t) rises monotonically, so bisection finds the t whose x is `progress`.
|
|
22
81
|
let low = 0
|
|
@@ -30,8 +89,21 @@ export function easingAt(easing: PrototypeEasingType | undefined, progress: numb
|
|
|
30
89
|
}
|
|
31
90
|
|
|
32
91
|
/** `easing` as a CSS timing function, for a transition the browser animates. */
|
|
33
|
-
export function easingCSS(
|
|
34
|
-
|
|
92
|
+
export function easingCSS(
|
|
93
|
+
easing: PrototypeEasingType | undefined,
|
|
94
|
+
curve?: PrototypeCubicBezier
|
|
95
|
+
): string {
|
|
96
|
+
if (easing === 'CUSTOM_CUBIC_BEZIER' && curve)
|
|
97
|
+
return `cubic-bezier(${curve.x1}, ${curve.y1}, ${curve.x2}, ${curve.y2})`
|
|
98
|
+
// The app baseline predates CSS `linear()` (Chrome 111, Safari 16.4), so a spring dissolve
|
|
99
|
+
// snapshot eases out instead of sampling the physical curve; documented on the roadmap.
|
|
100
|
+
if (easing === 'CUSTOM_SPRING' || (easing !== undefined && easing in PROTOTYPE_SPRING_PRESETS))
|
|
101
|
+
return 'ease-out'
|
|
102
|
+
const points =
|
|
103
|
+
PROTOTYPE_EASING_CURVES[easing ?? DEFAULT_PROTOTYPE_EASING] ??
|
|
104
|
+
PROTOTYPE_EASING_CURVES[DEFAULT_PROTOTYPE_EASING] ??
|
|
105
|
+
([0, 0, 0.58, 1] as const)
|
|
106
|
+
const [x1, y1, x2, y2] = points
|
|
35
107
|
if (x1 === y1 && x2 === y2) return 'linear'
|
|
36
108
|
return `cubic-bezier(${x1}, ${y1}, ${x2}, ${y2})`
|
|
37
109
|
}
|
package/src/prototype/scenes.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
PrototypeAction,
|
|
3
|
+
PrototypeConditionalAction,
|
|
3
4
|
PrototypeReaction,
|
|
5
|
+
PrototypeSetVariableAction,
|
|
6
|
+
PrototypeSetVariableModeAction,
|
|
4
7
|
PrototypeTransition,
|
|
5
8
|
SceneGraph,
|
|
6
|
-
SceneNode
|
|
9
|
+
SceneNode,
|
|
10
|
+
VariableValue
|
|
7
11
|
} from '@pairdraw/scene-graph'
|
|
8
12
|
import { instanceMainComponent } from '@pairdraw/scene-graph/instances'
|
|
9
13
|
import type { Vector } from '@pairdraw/scene-graph/primitives'
|
|
@@ -26,6 +30,7 @@ import {
|
|
|
26
30
|
type PlayFrame,
|
|
27
31
|
type SmartAnimation
|
|
28
32
|
} from './smart-animate/animation'
|
|
33
|
+
import { evaluateVariable, type PrototypeResolvedValue } from './variables'
|
|
29
34
|
|
|
30
35
|
/** How many changed frames play keeps; a frame dropped beyond them starts again as designed. */
|
|
31
36
|
export const PLAY_SCENE_LIMIT = 4
|
|
@@ -59,6 +64,12 @@ export interface PlayStep {
|
|
|
59
64
|
* the player to run over the transition's duration; the copy shows the change at once.
|
|
60
65
|
*/
|
|
61
66
|
animation?: SmartAnimation
|
|
67
|
+
/** Why a variable action could not run; the player shows it instead of guessing a value. */
|
|
68
|
+
variablesRefused?: string
|
|
69
|
+
/** The action actually run, after a Conditional picked a branch. */
|
|
70
|
+
action?: PrototypeAction
|
|
71
|
+
/** Whether play's variable values changed, so a frame showing them must be drawn again. */
|
|
72
|
+
repaint?: boolean
|
|
62
73
|
}
|
|
63
74
|
|
|
64
75
|
/**
|
|
@@ -69,6 +80,29 @@ export interface PlayStep {
|
|
|
69
80
|
export interface PlayScenes {
|
|
70
81
|
/** The graph play reads a top-level frame from: its copy once changed, else the document. */
|
|
71
82
|
graphFor(rootId: string): SceneGraph
|
|
83
|
+
/**
|
|
84
|
+
* A fresh copy of `rootId` with the session's variable values and modes applied, for a caller
|
|
85
|
+
* that must keep the state it sees after play moves on (a video's earlier frames).
|
|
86
|
+
*/
|
|
87
|
+
cloneGraphFor(rootId: string): SceneGraph
|
|
88
|
+
/**
|
|
89
|
+
* The action a Conditional would run now, resolving nested conditionals; a condition this build
|
|
90
|
+
* cannot evaluate is refused with its reason.
|
|
91
|
+
*/
|
|
92
|
+
resolve(
|
|
93
|
+
action: PrototypeAction,
|
|
94
|
+
rootId?: string
|
|
95
|
+
): { action: PrototypeAction } | { refused: string }
|
|
96
|
+
/**
|
|
97
|
+
* The actions of the first matching Conditional branch, or `[action]` for any other action; a
|
|
98
|
+
* condition this build cannot evaluate is refused with its reason.
|
|
99
|
+
*/
|
|
100
|
+
resolveBranch(
|
|
101
|
+
action: PrototypeAction,
|
|
102
|
+
rootId?: string
|
|
103
|
+
): { actions: readonly PrototypeAction[] } | { refused: string }
|
|
104
|
+
/** Whether this session has changed a variable's value or a collection's mode. */
|
|
105
|
+
hasVariables(): boolean
|
|
72
106
|
/** The changed frames the canvas draws from their copies, by frame id. */
|
|
73
107
|
readonly views: ReadonlyMap<string, PlaySceneView>
|
|
74
108
|
/** How far play scrolled each frame that scrolls, by frame id. */
|
|
@@ -107,9 +141,66 @@ export function createPlayScenes(
|
|
|
107
141
|
// Insertion order is use order: a frame changed again moves to the end, and the first goes.
|
|
108
142
|
const scenes = new Map<string, PlayScene>()
|
|
109
143
|
const scroll = new Map<string, Vector>()
|
|
144
|
+
// The play session's variable values and mode overrides, applied only to frame copies.
|
|
145
|
+
const values = new Map<string, PrototypeResolvedValue>()
|
|
146
|
+
const modes = new Map<string, string>()
|
|
147
|
+
|
|
148
|
+
function literalOf(value: VariableValue | undefined): PrototypeResolvedValue | undefined {
|
|
149
|
+
if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string')
|
|
150
|
+
return value
|
|
151
|
+
if (value && typeof value === 'object' && 'r' in value) return value
|
|
152
|
+
return undefined
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function valueOf(variableId: string, rootId?: string): PrototypeResolvedValue | undefined {
|
|
156
|
+
const overlay = values.get(variableId)
|
|
157
|
+
if (overlay !== undefined) return overlay
|
|
158
|
+
const frame = rootId ? graphFor(rootId).getNode(rootId) : undefined
|
|
159
|
+
const variable = (rootId ? graphFor(rootId).variables : getDocument().variables).get(variableId)
|
|
160
|
+
if (!variable) return undefined
|
|
161
|
+
const frameMode = frame ? frame.variableModes[variable.collectionId] : undefined
|
|
162
|
+
const defaultMode = getDocument().variableCollections.get(variable.collectionId)?.modes[0]
|
|
163
|
+
?.modeId
|
|
164
|
+
const mode = modes.get(variable.collectionId) ?? frameMode ?? defaultMode
|
|
165
|
+
return mode ? literalOf(variable.valuesByMode[mode]) : undefined
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function applyVariables(graph: SceneGraph): void {
|
|
169
|
+
// A play scene shares the document's variable table; copy it before an override touches it.
|
|
170
|
+
if (graph.variables === getDocument().variables) graph.variables = new Map(graph.variables)
|
|
171
|
+
const root = [...graph.getAllNodes()].find((node) => node.parentId === null)
|
|
172
|
+
for (const [variableId, value] of values) {
|
|
173
|
+
const variable = graph.variables.get(variableId)
|
|
174
|
+
if (!variable) continue
|
|
175
|
+
const rootMode = root ? root.variableModes[variable.collectionId] : undefined
|
|
176
|
+
const defaultMode = graph.variableCollections.get(variable.collectionId)?.modes[0]?.modeId
|
|
177
|
+
const mode = modes.get(variable.collectionId) ?? rootMode ?? defaultMode
|
|
178
|
+
if (mode)
|
|
179
|
+
graph.variables.set(variableId, {
|
|
180
|
+
...variable,
|
|
181
|
+
valuesByMode: { ...variable.valuesByMode, [mode]: value }
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
if (modes.size === 0) return
|
|
185
|
+
for (const node of graph.getAllNodes()) {
|
|
186
|
+
const overrides = { ...node.variableModes }
|
|
187
|
+
for (const [collectionId, modeId] of modes) overrides[collectionId] = modeId
|
|
188
|
+
graph.updateNode(node.id, { variableModes: overrides })
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function sceneFor(rootId: string): PlayScene {
|
|
193
|
+
const existing = scenes.get(rootId)
|
|
194
|
+
if (existing) return existing
|
|
195
|
+
const scene = createPlayScene(getDocument(), rootId)
|
|
196
|
+
applyVariables(scene.graph)
|
|
197
|
+
scenes.set(rootId, scene)
|
|
198
|
+
return scene
|
|
199
|
+
}
|
|
110
200
|
|
|
111
201
|
function graphFor(rootId: string): SceneGraph {
|
|
112
|
-
return scenes.get(rootId)?.graph ?? getDocument()
|
|
202
|
+
if (values.size === 0 && modes.size === 0) return scenes.get(rootId)?.graph ?? getDocument()
|
|
203
|
+
return sceneFor(rootId).graph
|
|
113
204
|
}
|
|
114
205
|
|
|
115
206
|
/**
|
|
@@ -142,13 +233,20 @@ export function createPlayScenes(
|
|
|
142
233
|
const changed = changeIn(rootId, sourceId, variantId)
|
|
143
234
|
if (!changed || !from) return { changed }
|
|
144
235
|
const to = { graph: graphFor(rootId), rootId }
|
|
145
|
-
return {
|
|
236
|
+
return {
|
|
237
|
+
changed,
|
|
238
|
+
animation: createSmartAnimation(from, to, transition?.easing, {
|
|
239
|
+
curve: transition?.easingCurve,
|
|
240
|
+
spring: transition?.easingSpring,
|
|
241
|
+
duration: transition?.duration
|
|
242
|
+
})
|
|
243
|
+
}
|
|
146
244
|
}
|
|
147
245
|
|
|
148
246
|
function changeIn(rootId: string, sourceId: string, variantId: string): PlayChange | null {
|
|
149
247
|
// Checked on what play shows now, so a Change to that cannot run copies nothing.
|
|
150
248
|
if (!changeTarget(graphFor(rootId), rootId, sourceId, variantId)) return null
|
|
151
|
-
const scene =
|
|
249
|
+
const scene = sceneFor(rootId)
|
|
152
250
|
const change = scene.changeTo(sourceId, variantId)
|
|
153
251
|
scenes.delete(rootId)
|
|
154
252
|
scenes.set(rootId, scene)
|
|
@@ -161,8 +259,148 @@ export function createPlayScenes(
|
|
|
161
259
|
return change
|
|
162
260
|
}
|
|
163
261
|
|
|
262
|
+
function setVariableStep(
|
|
263
|
+
session: PlaySession,
|
|
264
|
+
action: PrototypeSetVariableAction,
|
|
265
|
+
rootId: string
|
|
266
|
+
): PlayStep {
|
|
267
|
+
if (!action.variableId) return { session, changed: null, action }
|
|
268
|
+
const result = evaluateVariable(action.value, (id) => valueOf(id, rootId))
|
|
269
|
+
if (!result.ok) return { session, changed: null, variablesRefused: result.reason, action }
|
|
270
|
+
values.set(action.variableId, result.value)
|
|
271
|
+
applyVariables(graphFor(rootId))
|
|
272
|
+
return { session, changed: null, repaint: true, action }
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function setModeStep(
|
|
276
|
+
session: PlaySession,
|
|
277
|
+
action: PrototypeSetVariableModeAction,
|
|
278
|
+
rootId: string
|
|
279
|
+
): PlayStep {
|
|
280
|
+
if (!action.collectionId || !action.modeId) return { session, changed: null, action }
|
|
281
|
+
modes.set(action.collectionId, action.modeId)
|
|
282
|
+
applyVariables(graphFor(rootId))
|
|
283
|
+
return { session, changed: null, repaint: true, action }
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** Whether an evaluated variable counts as true for a Conditional. */
|
|
287
|
+
function truthy(value: PrototypeResolvedValue): boolean {
|
|
288
|
+
return (
|
|
289
|
+
value === true ||
|
|
290
|
+
(typeof value === 'number' && value !== 0) ||
|
|
291
|
+
(typeof value === 'string' && value.length > 0)
|
|
292
|
+
)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function takenBranch(
|
|
296
|
+
action: PrototypeConditionalAction,
|
|
297
|
+
rootId?: string
|
|
298
|
+
): { actions: readonly PrototypeAction[] } | { refused: string } {
|
|
299
|
+
for (const block of action.blocks) {
|
|
300
|
+
if (block.condition) {
|
|
301
|
+
const result = evaluateVariable(block.condition, (id) => valueOf(id, rootId))
|
|
302
|
+
if (!result.ok) return { refused: result.reason }
|
|
303
|
+
if (!truthy(result.value)) continue
|
|
304
|
+
}
|
|
305
|
+
return { actions: block.actions }
|
|
306
|
+
}
|
|
307
|
+
return { actions: [] }
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function resolveBranch(
|
|
311
|
+
action: PrototypeAction,
|
|
312
|
+
rootId?: string
|
|
313
|
+
): { actions: readonly PrototypeAction[] } | { refused: string } {
|
|
314
|
+
if (action.type !== 'CONDITIONAL') return { actions: [action] }
|
|
315
|
+
return takenBranch(action, rootId)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** The first branch's action whose condition holds, resolving nested conditionals. */
|
|
319
|
+
function resolveAction(
|
|
320
|
+
action: PrototypeAction,
|
|
321
|
+
rootId?: string
|
|
322
|
+
): { action: PrototypeAction } | { refused: string } {
|
|
323
|
+
if (action.type !== 'CONDITIONAL') return { action }
|
|
324
|
+
const branch = takenBranch(action, rootId)
|
|
325
|
+
if ('refused' in branch) return branch
|
|
326
|
+
if (branch.actions.length === 0) return { action }
|
|
327
|
+
return resolveAction(branch.actions[0], rootId)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function mergeStep(target: PlayStep, next: PlayStep): void {
|
|
331
|
+
target.session = next.session
|
|
332
|
+
if (next.changed) target.changed = next.changed
|
|
333
|
+
if (next.repaint) target.repaint = true
|
|
334
|
+
if (next.scrolled?.length) target.scrolled = [...(target.scrolled ?? []), ...next.scrolled]
|
|
335
|
+
if (next.reveal !== undefined) target.reveal = next.reveal
|
|
336
|
+
if (next.animation) target.animation = next.animation
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function conditionalStep(
|
|
340
|
+
session: PlaySession,
|
|
341
|
+
action: PrototypeConditionalAction,
|
|
342
|
+
sourceId: string,
|
|
343
|
+
rootId: string
|
|
344
|
+
): PlayStep {
|
|
345
|
+
const branch = takenBranch(action, rootId)
|
|
346
|
+
if ('refused' in branch) {
|
|
347
|
+
return { session, changed: null, variablesRefused: branch.refused, action }
|
|
348
|
+
}
|
|
349
|
+
if (branch.actions.length === 0) return { session, changed: null, action }
|
|
350
|
+
const merged: PlayStep = { session, changed: null, action }
|
|
351
|
+
let currentRoot = rootId
|
|
352
|
+
let primary: PrototypeAction | undefined
|
|
353
|
+
for (const item of branch.actions) {
|
|
354
|
+
const prevSession = merged.session
|
|
355
|
+
const transition = item.type === 'NODE' ? item.transition : null
|
|
356
|
+
const next = runAction(prevSession, { sourceId, action: item, transition }, currentRoot)
|
|
357
|
+
mergeStep(merged, next)
|
|
358
|
+
if (next.session !== prevSession) currentRoot = shownFrame(next.session)
|
|
359
|
+
const transitioned =
|
|
360
|
+
next.session !== prevSession ||
|
|
361
|
+
next.changed !== null ||
|
|
362
|
+
Boolean(next.animation) ||
|
|
363
|
+
Boolean(next.scrolled?.length)
|
|
364
|
+
if (next.action) {
|
|
365
|
+
merged.action = next.action
|
|
366
|
+
if (transitioned) primary = next.action
|
|
367
|
+
}
|
|
368
|
+
if (next.variablesRefused) {
|
|
369
|
+
merged.variablesRefused = next.variablesRefused
|
|
370
|
+
return merged
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (primary) merged.action = primary
|
|
374
|
+
return merged
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function runAction(session: PlaySession, click: PlayClick, rootId: string): PlayStep {
|
|
378
|
+
const { sourceId, action } = click
|
|
379
|
+
if (action.type === 'SET_VARIABLE') return setVariableStep(session, action, rootId)
|
|
380
|
+
if (action.type === 'SET_VARIABLE_MODE') return setModeStep(session, action, rootId)
|
|
381
|
+
if (action.type === 'CONDITIONAL') return conditionalStep(session, action, sourceId, rootId)
|
|
382
|
+
if (action.type === 'NODE' && action.navigation === 'CHANGE_TO') {
|
|
383
|
+
if (!action.nodeId) return { session, changed: null, action }
|
|
384
|
+
return { session, action, ...changeWith(rootId, sourceId, action.nodeId, action.transition) }
|
|
385
|
+
}
|
|
386
|
+
if (action.type === 'NODE' && action.navigation === 'SCROLL_TO') {
|
|
387
|
+
if (!action.nodeId) return { session, changed: null, scrolled: [], reveal: null, action }
|
|
388
|
+
const moved = scrollIntoView(graphFor(rootId), scroll, rootId, action.nodeId)
|
|
389
|
+
return { session, changed: null, action, ...moved }
|
|
390
|
+
}
|
|
391
|
+
return { session: step(getDocument(), session, action), changed: null, action }
|
|
392
|
+
}
|
|
393
|
+
|
|
164
394
|
return {
|
|
165
395
|
graphFor,
|
|
396
|
+
cloneGraphFor(rootId) {
|
|
397
|
+
const copy = createPlayScene(getDocument(), rootId)
|
|
398
|
+
applyVariables(copy.graph)
|
|
399
|
+
return copy.graph
|
|
400
|
+
},
|
|
401
|
+
resolve: resolveAction,
|
|
402
|
+
resolveBranch,
|
|
403
|
+
hasVariables: () => values.size > 0 || modes.size > 0,
|
|
166
404
|
views: scenes,
|
|
167
405
|
scroll,
|
|
168
406
|
scrollBy(rootId, path, dx, dy) {
|
|
@@ -171,17 +409,8 @@ export function createPlayScenes(
|
|
|
171
409
|
setScroll(id, offset) {
|
|
172
410
|
scroll.set(id, offset)
|
|
173
411
|
},
|
|
174
|
-
run(session,
|
|
175
|
-
|
|
176
|
-
if (!action.nodeId) return { session, changed: null }
|
|
177
|
-
return { session, ...changeWith(rootId, sourceId, action.nodeId, action.transition) }
|
|
178
|
-
}
|
|
179
|
-
if (action.type === 'NODE' && action.navigation === 'SCROLL_TO') {
|
|
180
|
-
if (!action.nodeId) return { session, changed: null, scrolled: [], reveal: null }
|
|
181
|
-
const moved = scrollIntoView(graphFor(rootId), scroll, rootId, action.nodeId)
|
|
182
|
-
return { session, changed: null, ...moved }
|
|
183
|
-
}
|
|
184
|
-
return { session: step(getDocument(), session, action), changed: null }
|
|
412
|
+
run(session, click, rootId = shownFrame(session)) {
|
|
413
|
+
return runAction(session, click, rootId)
|
|
185
414
|
},
|
|
186
415
|
revert(session, revert) {
|
|
187
416
|
if (revert.kind === 'change') {
|