@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"animation.js","names":[],"sources":["../../../src/prototype/smart-animate/animation.ts"],"sourcesContent":["import type { Fill, PrototypeEasingType, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport { extractPageContext, findPageId } from '#core/io/subgraph'\nimport { easingAt } from '#core/prototype/easing'\nimport type { PlaySceneView } from '#core/prototype/scene'\n\nimport { matchLayers } from './match'\n\n/** A top-level frame and the graph play reads it from: the document, or play's copy of it. */\nexport interface PlayFrame {\n graph: SceneGraph\n rootId: string\n}\n\n/**\n * A Smart animate from one frame to another, drawn as a view of the destination frame: a private\n * copy of it, which `seek` poses at a moment of the transition. The canvas draws `graph` in place\n * of `rootId` and redraws `touched` whenever `revision` grows; a recording draws it the same way.\n */\nexport interface SmartAnimation extends PlaySceneView {\n /** The destination frame, which the copy draws in its place. */\n readonly rootId: string\n /**\n * Poses the copy `progress` of the way through the transition's time, from 0 to 1, eased as the\n * transition asks. Writes only the layers that change.\n */\n seek(progress: number): void\n}\n\n/** The numbers Smart animate moves from one layer's value to its match's. */\nconst ANIMATED_FIELDS = [\n 'x',\n 'y',\n 'width',\n 'height',\n 'rotation',\n 'opacity',\n 'cornerRadius',\n 'topLeftRadius',\n 'topRightRadius',\n 'bottomRightRadius',\n 'bottomLeftRadius'\n] as const satisfies readonly (keyof SceneNode)[]\n\ntype AnimatedField = (typeof ANIMATED_FIELDS)[number]\n\n/** One field moving from `from` to `to`. */\ninterface NumberTrack {\n field: AnimatedField\n from: number\n to: number\n}\n\n/** A layer of the copy and what moves on it: numbers, and solid fills whose colours blend. */\ninterface LayerTrack {\n id: string\n numbers: NumberTrack[]\n fills: { from: readonly Fill[]; to: readonly Fill[] } | null\n}\n\n/** A copy's own id for a layer of the start frame that fades out, which never names a real one. */\nfunction leavingId(id: string): string {\n return `smart-animate:${id}`\n}\n\nfunction lerp(from: number, to: number, amount: number): number {\n return from + (to - from) * amount\n}\n\n/** Wraps an angle into (-180, 180], the range a layer's rotation keeps. */\nfunction wrapAngle(degrees: number): number {\n const wrapped = ((degrees % 360) + 360) % 360\n return wrapped > 180 ? wrapped - 360 : wrapped\n}\n\nfunction blend(from: Color, to: Color, amount: number): Color {\n return {\n r: lerp(from.r, to.r, amount),\n g: lerp(from.g, to.g, amount),\n b: lerp(from.b, to.b, amount),\n a: lerp(from.a, to.a, amount)\n }\n}\n\n/**\n * The fills to blend between two layers: lists of the same length whose fills are solid at the\n * same places. Others, and fills that do not differ, take the destination's at once.\n */\nfunction fillTrack(from: readonly Fill[], to: readonly Fill[]): LayerTrack['fills'] {\n if (from.length !== to.length || from.length === 0) return null\n let differs = false\n for (const [index, fill] of to.entries()) {\n const start = from.at(index)\n if (start?.type !== 'SOLID' || fill.type !== 'SOLID') return null\n const { r, g, b, a } = start.color\n const end = fill.color\n if (\n r !== end.r ||\n g !== end.g ||\n b !== end.b ||\n a !== end.a ||\n start.opacity !== fill.opacity\n ) {\n differs = true\n }\n }\n return differs ? { from, to } : null\n}\n\nfunction blendFills(track: NonNullable<LayerTrack['fills']>, amount: number): Fill[] {\n return track.to.map((fill, index) => {\n const start = track.from.at(index)\n if (!start) return fill\n return {\n ...fill,\n color: blend(start.color, fill.color, amount),\n opacity: lerp(start.opacity, fill.opacity, amount)\n }\n })\n}\n\n/** What moves on a matched layer, or null when nothing does. Rotation turns the short way. */\nfunction pairTrack(from: SceneNode, to: SceneNode, fields: readonly AnimatedField[]) {\n const numbers = fields.flatMap((field) => {\n const start = from[field]\n const end = to[field]\n if (start === end) return []\n // Rotation lives in (-180, 180]; across ±180 the short way is under half a turn.\n const delta = field === 'rotation' ? ((((end - start) % 360) + 540) % 360) - 180 : end - start\n return [{ field, from: start, to: start + delta }]\n })\n const fills = fillTrack(from.fills, to.fills)\n return numbers.length > 0 || fills ? { id: to.id, numbers, fills } : null\n}\n\n/**\n * Copies a start-frame layer that fades out, with all it holds, under `parentId` in the copy at\n * `index`, under ids of its own so it never shares a cached drawing with a real layer.\n */\nfunction carryLeaving(\n from: SceneGraph,\n graph: SceneGraph,\n id: string,\n parentId: string,\n index: number\n): string | null {\n const parent = graph.getNode(parentId)\n const source = from.getNode(id)\n if (!parent || !source) return null\n const copy = (node: SceneNode, copyParentId: string): string => {\n const cloned = structuredClone(node)\n cloned.id = leavingId(node.id)\n cloned.parentId = copyParentId\n cloned.childIds = node.childIds.flatMap((childId) => {\n const child = from.getNode(childId)\n return child ? [copy(child, cloned.id)] : []\n })\n graph.nodes.set(cloned.id, cloned)\n return cloned.id\n }\n const copied = copy(source, parent.id)\n const at = Math.min(index, parent.childIds.length)\n parent.childIds = [...parent.childIds.slice(0, at), copied, ...parent.childIds.slice(at)]\n return copied\n}\n\n/** A fade of one layer's opacity, or null for a layer already invisible. */\nfunction fadeTrack(id: string, from: number, to: number): LayerTrack | null {\n return from === to ? null : { id, numbers: [{ field: 'opacity', from, to }], fills: null }\n}\n\n/**\n * What moves in `graph`, the copy of the destination frame `rootId`: its fill, the layers that\n * match the start frame's, the destination's layers that fade in, and the start frame's that fade\n * out, which this carries into the copy under the match of their parent.\n */\nfunction animationTracks(from: PlayFrame, graph: SceneGraph, rootId: string): LayerTrack[] {\n const match = matchLayers(from.graph, from.rootId, graph, rootId)\n const tracks: LayerTrack[] = []\n const add = (track: LayerTrack | null) => {\n if (track) tracks.push(track)\n }\n const fromRoot = from.graph.getNode(from.rootId)\n const toRoot = graph.getNode(rootId)\n if (fromRoot && toRoot) add(pairTrack(fromRoot, toRoot, []))\n const matchOf = new Map<string, string>([[from.rootId, rootId]])\n for (const pair of match.pairs) {\n matchOf.set(pair.from, pair.to)\n const start = from.graph.getNode(pair.from)\n const end = graph.getNode(pair.to)\n if (start && end) add(pairTrack(start, end, ANIMATED_FIELDS))\n }\n // A layer hidden at an end draws nothing there, so it needs no fade: one hidden in both frames\n // costs nothing at all, and one hidden at the far end only fades at the end that shows it.\n for (const id of match.entering) {\n const node = graph.getNode(id)\n if (node?.visible) add(fadeTrack(id, 0, node.opacity))\n }\n for (const id of match.leaving) {\n const node = from.graph.getNode(id)\n if (!node?.visible) continue\n const parentId = node.parentId ? matchOf.get(node.parentId) : undefined\n if (!node.parentId || !parentId) continue\n const index = from.graph.getNode(node.parentId)?.childIds.indexOf(id) ?? 0\n const copied = carryLeaving(from.graph, graph, id, parentId, index)\n if (copied) add(fadeTrack(copied, node.opacity, 0))\n }\n graph.clearAbsPosCache()\n return tracks\n}\n\n/**\n * A Smart animate from `from` to `to`: a copy of the destination frame in which each layer that\n * matches one of the start frame (`matchLayers`) moves from the start layer's position, size,\n * rotation, opacity, corner radius and solid fill colours to its own, the start frame's layers\n * with no match fade out where they were, and the destination's fade in. The destination frame\n * keeps its place and size and blends its fill. Neither frame changes. Matching and the copy cost\n * one pass when it is made; a step writes only the layers that change.\n */\nexport function createSmartAnimation(\n from: PlayFrame,\n to: PlayFrame,\n easing?: PrototypeEasingType\n): SmartAnimation {\n const pageId = findPageId(to.graph, to.rootId) ?? to.graph.rootId\n const graph = extractPageContext(to.graph, pageId, [to.rootId], { shareTables: true })\n const tracks = animationTracks(from, graph, to.rootId)\n\n // A layer's cached drawing holds what it contains, so its frame and the layers between redraw.\n const touched = new Set<string>()\n for (const track of tracks) {\n graph.closest(track.id, (node) => {\n touched.add(node.id)\n return node.id === to.rootId\n })\n }\n\n function pose(progress: number): void {\n const amount = easingAt(easing, progress)\n for (const track of tracks) {\n const changes: Partial<SceneNode> = {}\n for (const { field, from: start, to: end } of track.numbers) {\n const value = lerp(start, end, amount)\n changes[field] = field === 'rotation' ? wrapAngle(value) : value\n }\n if (track.fills) changes.fills = blendFills(track.fills, amount)\n graph.updateNode(track.id, changes)\n }\n }\n\n // Made at its start, so the first drawing shows the start frame's layout.\n pose(0)\n let revision = 0\n return {\n graph,\n rootId: to.rootId,\n touched,\n get revision() {\n return revision\n },\n seek(progress) {\n pose(progress)\n revision += 1\n }\n }\n}\n"],"mappings":";;;;;AA+BA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAmBA,SAAS,UAAU,IAAoB;CACrC,OAAO,iBAAiB;AAC1B;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esContent":["import type { Fill, PrototypeEasingType, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport { extractPageContext, findPageId } from '#core/io/subgraph'\nimport { easingAt, type EasingPlayback } from '#core/prototype/easing'\nimport type { PlaySceneView } from '#core/prototype/scene'\n\nimport { matchLayers } from './match'\n\n/** A top-level frame and the graph play reads it from: the document, or play's copy of it. */\nexport interface PlayFrame {\n graph: SceneGraph\n rootId: string\n}\n\n/**\n * A Smart animate from one frame to another, drawn as a view of the destination frame: a private\n * copy of it, which `seek` poses at a moment of the transition. The canvas draws `graph` in place\n * of `rootId` and redraws `touched` whenever `revision` grows; a recording draws it the same way.\n */\nexport interface SmartAnimation extends PlaySceneView {\n /** The destination frame, which the copy draws in its place. */\n readonly rootId: string\n /**\n * Poses the copy `progress` of the way through the transition's time, from 0 to 1, eased as the\n * transition asks. Writes only the layers that change.\n */\n seek(progress: number): void\n}\n\n/** The numbers Smart animate moves from one layer's value to its match's. */\nconst ANIMATED_FIELDS = [\n 'x',\n 'y',\n 'width',\n 'height',\n 'rotation',\n 'opacity',\n 'cornerRadius',\n 'topLeftRadius',\n 'topRightRadius',\n 'bottomRightRadius',\n 'bottomLeftRadius'\n] as const satisfies readonly (keyof SceneNode)[]\n\ntype AnimatedField = (typeof ANIMATED_FIELDS)[number]\n\n/** One field moving from `from` to `to`. */\ninterface NumberTrack {\n field: AnimatedField\n from: number\n to: number\n}\n\n/** A layer of the copy and what moves on it: numbers, and solid fills whose colours blend. */\ninterface LayerTrack {\n id: string\n numbers: NumberTrack[]\n fills: { from: readonly Fill[]; to: readonly Fill[] } | null\n}\n\n/** A copy's own id for a layer of the start frame that fades out, which never names a real one. */\nfunction leavingId(id: string): string {\n return `smart-animate:${id}`\n}\n\nfunction lerp(from: number, to: number, amount: number): number {\n return from + (to - from) * amount\n}\n\n/** Wraps an angle into (-180, 180], the range a layer's rotation keeps. */\nfunction wrapAngle(degrees: number): number {\n const wrapped = ((degrees % 360) + 360) % 360\n return wrapped > 180 ? wrapped - 360 : wrapped\n}\n\nfunction blend(from: Color, to: Color, amount: number): Color {\n return {\n r: lerp(from.r, to.r, amount),\n g: lerp(from.g, to.g, amount),\n b: lerp(from.b, to.b, amount),\n a: lerp(from.a, to.a, amount)\n }\n}\n\n/**\n * The fills to blend between two layers: lists of the same length whose fills are solid at the\n * same places. Others, and fills that do not differ, take the destination's at once.\n */\nfunction fillTrack(from: readonly Fill[], to: readonly Fill[]): LayerTrack['fills'] {\n if (from.length !== to.length || from.length === 0) return null\n let differs = false\n for (const [index, fill] of to.entries()) {\n const start = from.at(index)\n if (start?.type !== 'SOLID' || fill.type !== 'SOLID') return null\n const { r, g, b, a } = start.color\n const end = fill.color\n if (\n r !== end.r ||\n g !== end.g ||\n b !== end.b ||\n a !== end.a ||\n start.opacity !== fill.opacity\n ) {\n differs = true\n }\n }\n return differs ? { from, to } : null\n}\n\nfunction blendFills(track: NonNullable<LayerTrack['fills']>, amount: number): Fill[] {\n return track.to.map((fill, index) => {\n const start = track.from.at(index)\n if (!start) return fill\n return {\n ...fill,\n color: blend(start.color, fill.color, amount),\n opacity: lerp(start.opacity, fill.opacity, amount)\n }\n })\n}\n\n/** What moves on a matched layer, or null when nothing does. Rotation turns the short way. */\nfunction pairTrack(from: SceneNode, to: SceneNode, fields: readonly AnimatedField[]) {\n const numbers = fields.flatMap((field) => {\n const start = from[field]\n const end = to[field]\n if (start === end) return []\n // Rotation lives in (-180, 180]; across ±180 the short way is under half a turn.\n const delta = field === 'rotation' ? ((((end - start) % 360) + 540) % 360) - 180 : end - start\n return [{ field, from: start, to: start + delta }]\n })\n const fills = fillTrack(from.fills, to.fills)\n return numbers.length > 0 || fills ? { id: to.id, numbers, fills } : null\n}\n\n/**\n * Copies a start-frame layer that fades out, with all it holds, under `parentId` in the copy at\n * `index`, under ids of its own so it never shares a cached drawing with a real layer.\n */\nfunction carryLeaving(\n from: SceneGraph,\n graph: SceneGraph,\n id: string,\n parentId: string,\n index: number\n): string | null {\n const parent = graph.getNode(parentId)\n const source = from.getNode(id)\n if (!parent || !source) return null\n const copy = (node: SceneNode, copyParentId: string): string => {\n const cloned = structuredClone(node)\n cloned.id = leavingId(node.id)\n cloned.parentId = copyParentId\n cloned.childIds = node.childIds.flatMap((childId) => {\n const child = from.getNode(childId)\n return child ? [copy(child, cloned.id)] : []\n })\n graph.nodes.set(cloned.id, cloned)\n return cloned.id\n }\n const copied = copy(source, parent.id)\n const at = Math.min(index, parent.childIds.length)\n parent.childIds = [...parent.childIds.slice(0, at), copied, ...parent.childIds.slice(at)]\n return copied\n}\n\n/** A fade of one layer's opacity, or null for a layer already invisible. */\nfunction fadeTrack(id: string, from: number, to: number): LayerTrack | null {\n return from === to ? null : { id, numbers: [{ field: 'opacity', from, to }], fills: null }\n}\n\n/**\n * What moves in `graph`, the copy of the destination frame `rootId`: its fill, the layers that\n * match the start frame's, the destination's layers that fade in, and the start frame's that fade\n * out, which this carries into the copy under the match of their parent.\n */\nfunction animationTracks(from: PlayFrame, graph: SceneGraph, rootId: string): LayerTrack[] {\n const match = matchLayers(from.graph, from.rootId, graph, rootId)\n const tracks: LayerTrack[] = []\n const add = (track: LayerTrack | null) => {\n if (track) tracks.push(track)\n }\n const fromRoot = from.graph.getNode(from.rootId)\n const toRoot = graph.getNode(rootId)\n if (fromRoot && toRoot) add(pairTrack(fromRoot, toRoot, []))\n const matchOf = new Map<string, string>([[from.rootId, rootId]])\n for (const pair of match.pairs) {\n matchOf.set(pair.from, pair.to)\n const start = from.graph.getNode(pair.from)\n const end = graph.getNode(pair.to)\n if (start && end) add(pairTrack(start, end, ANIMATED_FIELDS))\n }\n // A layer hidden at an end draws nothing there, so it needs no fade: one hidden in both frames\n // costs nothing at all, and one hidden at the far end only fades at the end that shows it.\n for (const id of match.entering) {\n const node = graph.getNode(id)\n if (node?.visible) add(fadeTrack(id, 0, node.opacity))\n }\n for (const id of match.leaving) {\n const node = from.graph.getNode(id)\n if (!node?.visible) continue\n const parentId = node.parentId ? matchOf.get(node.parentId) : undefined\n if (!node.parentId || !parentId) continue\n const index = from.graph.getNode(node.parentId)?.childIds.indexOf(id) ?? 0\n const copied = carryLeaving(from.graph, graph, id, parentId, index)\n if (copied) add(fadeTrack(copied, node.opacity, 0))\n }\n graph.clearAbsPosCache()\n return tracks\n}\n\n/**\n * A Smart animate from `from` to `to`: a copy of the destination frame in which each layer that\n * matches one of the start frame (`matchLayers`) moves from the start layer's position, size,\n * rotation, opacity, corner radius and solid fill colours to its own, the start frame's layers\n * with no match fade out where they were, and the destination's fade in. The destination frame\n * keeps its place and size and blends its fill. Neither frame changes. Matching and the copy cost\n * one pass when it is made; a step writes only the layers that change.\n */\nexport function createSmartAnimation(\n from: PlayFrame,\n to: PlayFrame,\n easing?: PrototypeEasingType,\n playback?: EasingPlayback\n): SmartAnimation {\n const pageId = findPageId(to.graph, to.rootId) ?? to.graph.rootId\n const graph = extractPageContext(to.graph, pageId, [to.rootId], { shareTables: true })\n const tracks = animationTracks(from, graph, to.rootId)\n\n // A layer's cached drawing holds what it contains, so its frame and the layers between redraw.\n const touched = new Set<string>()\n for (const track of tracks) {\n graph.closest(track.id, (node) => {\n touched.add(node.id)\n return node.id === to.rootId\n })\n }\n\n function pose(progress: number): void {\n const amount = easingAt(easing, progress, playback)\n for (const track of tracks) {\n const changes: Partial<SceneNode> = {}\n for (const { field, from: start, to: end } of track.numbers) {\n const value = lerp(start, end, amount)\n changes[field] = field === 'rotation' ? wrapAngle(value) : value\n }\n if (track.fills) changes.fills = blendFills(track.fills, amount)\n graph.updateNode(track.id, changes)\n }\n }\n\n // Made at its start, so the first drawing shows the start frame's layout.\n pose(0)\n let revision = 0\n return {\n graph,\n rootId: to.rootId,\n touched,\n get revision() {\n return revision\n },\n seek(progress) {\n pose(progress)\n revision += 1\n }\n }\n}\n"],"mappings":";;;;;AA+BA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAC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
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PlaySession } from "./session.js";
|
|
2
|
-
import { PrototypeAction, PrototypeEasingType, PrototypeOverlayPositionType, PrototypeTransitionType, SceneGraph } from "@pairdraw/scene-graph";
|
|
2
|
+
import { PrototypeAction, PrototypeCubicBezier, PrototypeEasingType, PrototypeOverlayPositionType, PrototypeSpring, PrototypeTransitionType, SceneGraph } from "@pairdraw/scene-graph";
|
|
3
3
|
//#region src/prototype/timeline.d.ts
|
|
4
4
|
/** A scripted click: the layer clicked, and when, in milliseconds from the start of play. */
|
|
5
5
|
interface TimelineClick {
|
|
@@ -25,6 +25,11 @@ interface TimelineTransition {
|
|
|
25
25
|
/** The transition's own length, which keeps its pace when a later step cuts it short. */
|
|
26
26
|
fadeMs: number;
|
|
27
27
|
easing?: PrototypeEasingType;
|
|
28
|
+
easingCurve?: PrototypeCubicBezier;
|
|
29
|
+
easingSpring?: PrototypeSpring;
|
|
30
|
+
/** The screens as play showed them, with its variable values and modes applied. */
|
|
31
|
+
fromGraph?: SceneGraph;
|
|
32
|
+
toGraph?: SceneGraph;
|
|
28
33
|
}
|
|
29
34
|
/**
|
|
30
35
|
* A stretch of play: one screen held still, a crossfade from one screen to the next, or a Smart
|
|
@@ -35,6 +40,7 @@ type TimelineSegment = {
|
|
|
35
40
|
session: PlaySession;
|
|
36
41
|
startMs: number;
|
|
37
42
|
endMs: number;
|
|
43
|
+
graph?: SceneGraph;
|
|
38
44
|
} | ({
|
|
39
45
|
kind: 'dissolve';
|
|
40
46
|
} & TimelineTransition) | ({
|
|
@@ -70,10 +76,13 @@ interface Timeline {
|
|
|
70
76
|
*/
|
|
71
77
|
type TimelineFrame = {
|
|
72
78
|
session: PlaySession;
|
|
79
|
+
graph?: SceneGraph;
|
|
73
80
|
} | {
|
|
74
81
|
from: PlaySession;
|
|
75
82
|
to: PlaySession;
|
|
76
83
|
mix: number;
|
|
84
|
+
fromGraph?: SceneGraph;
|
|
85
|
+
toGraph?: SceneGraph;
|
|
77
86
|
} | {
|
|
78
87
|
smart: TimelineSmartSegment;
|
|
79
88
|
progress: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.d.ts","names":[],"sources":["../../src/prototype/timeline.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"timeline.d.ts","names":[],"sources":["../../src/prototype/timeline.ts"],"mappings":";;;;UAuBiB;EACf;EACA;;UAGe;;EAEf;;EAEA,kBAAkB;;EAElB;;EAEA;;;UAIQ;EACR,MAAM;EACN,IAAI;EACJ;EACA;;EAEA;EACA,SAAS;EACT,cAAc;EACd,eAAe;;EAEf,YAAY;EACZ,UAAU;;;;;;KAOA;EACN;EAAc,SAAS;EAAa;EAAiB;EAAe,QAAQ;;EAC3E;IAAqB;EACrB;IAAkB;;KAGb,uBAAuB,QAAQ;EAAmB;;;UAG7C;EACf;EACA;EACA;EACA,YAAY;;UAGG;EACf,UAAU;EACV;;EAEA,eAAe;;EAEf;;EAEA;EACA,OAAO;;EAEP,kBAAkB,eAAe;;;;;;KAOvB;EACN,SAAS;EAAa,QAAQ;;EAE9B,MAAM;EACN,IAAI;EACJ;EACA,YAAY;EACZ,UAAU;;EAEV,OAAO;EAAsB;;;KAGvB;;cAGC,sBAAsB;WAItB,QAAQ;EAHV;EAEP,YAAA,iBACS,SAAQ;;;iBAUL,aAAa,QAAQ;;KAMzB;;;;;;iBAOI,aAAa,SAAS,aAAa,QAAQ,kBAAkB;;;;;;cAYhE;;;;;;;cAGA;;iBAGG,eAAe;;;;;;iBASf,eAAe,SAAS;;;;;;;;iBA8OxB,aAAa,OAAO,YAAY,SAAS,kBAAkB;;iBAkE3D,QAAQ,UAAU,UAAU,eAAe"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { easingAt } from "./easing.js";
|
|
2
|
-
import { primaryAction, shownFrame, startSession,
|
|
2
|
+
import { primaryAction, shownFrame, startSession, timeoutReactions, topFrameOf } from "./session.js";
|
|
3
|
+
import { createPlayScenes } from "./scenes.js";
|
|
3
4
|
//#region src/prototype/timeline.ts
|
|
4
5
|
/** A flow that cannot be played as asked, with a message naming the frame or click at fault. */
|
|
5
6
|
var TimelineError = class extends Error {
|
|
@@ -89,19 +90,23 @@ function clickAction(graph, session, click, index) {
|
|
|
89
90
|
}
|
|
90
91
|
/** The shown frame's After delay reactions, each due `delay` after the frame finished entering. */
|
|
91
92
|
function armTimers(graph, session, readyMs) {
|
|
93
|
+
const sourceId = shownFrame(session);
|
|
92
94
|
return timeoutReactions(graph, session).map(({ action, delayMs }) => ({
|
|
93
95
|
atMs: readyMs + delayMs,
|
|
96
|
+
sourceId,
|
|
94
97
|
action
|
|
95
98
|
})).toSorted((a, b) => a.atMs - b.atMs);
|
|
96
99
|
}
|
|
97
100
|
/** Play at its start frame, which must be a top-level frame with something to follow. */
|
|
98
|
-
function startWalk(graph, options) {
|
|
101
|
+
function startWalk(graph, play, options) {
|
|
99
102
|
const start = graph.getNode(options.startFrameId);
|
|
100
103
|
if (!start || topFrameOf(graph, start)?.id !== start.id) throw new TimelineError(`'${start?.name ?? options.startFrameId}' is not a top-level frame`);
|
|
101
104
|
const session = startSession(start.id);
|
|
102
105
|
const walk = {
|
|
103
106
|
graph,
|
|
107
|
+
play,
|
|
104
108
|
session,
|
|
109
|
+
stateGraph: play.hasVariables() ? play.cloneGraphFor(start.id) : graph,
|
|
105
110
|
readyMs: 0,
|
|
106
111
|
timers: armTimers(graph, session, 0),
|
|
107
112
|
clicks: (options.clicks ?? []).toSorted((a, b) => a.atMs - b.atMs),
|
|
@@ -118,13 +123,16 @@ function startWalk(graph, options) {
|
|
|
118
123
|
};
|
|
119
124
|
}
|
|
120
125
|
/** Holds the shown screen from when it finished entering until `endMs`. */
|
|
121
|
-
function hold(walk, endMs) {
|
|
122
|
-
if (endMs
|
|
126
|
+
function hold(walk, endMs, graph = walk.stateGraph) {
|
|
127
|
+
if (endMs <= walk.readyMs) return;
|
|
128
|
+
const segment = {
|
|
123
129
|
kind: "hold",
|
|
124
130
|
session: walk.session,
|
|
125
131
|
startMs: walk.readyMs,
|
|
126
132
|
endMs
|
|
127
|
-
}
|
|
133
|
+
};
|
|
134
|
+
if (graph !== walk.graph) segment.graph = graph;
|
|
135
|
+
walk.segments.push(segment);
|
|
128
136
|
}
|
|
129
137
|
/** The earliest due timer or click, taken off its queue; null when nothing else will happen. */
|
|
130
138
|
function takeNextEvent(walk) {
|
|
@@ -134,6 +142,7 @@ function takeNextEvent(walk) {
|
|
|
134
142
|
walk.timers = walk.timers.slice(1);
|
|
135
143
|
return {
|
|
136
144
|
atMs: timer.atMs,
|
|
145
|
+
sourceId: timer.sourceId,
|
|
137
146
|
action: timer.action,
|
|
138
147
|
trigger: "AFTER_TIMEOUT"
|
|
139
148
|
};
|
|
@@ -144,6 +153,7 @@ function takeNextEvent(walk) {
|
|
|
144
153
|
if (!action) walk.skippedClicks.push(click);
|
|
145
154
|
return {
|
|
146
155
|
atMs: click.atMs,
|
|
156
|
+
sourceId: click.nodeId,
|
|
147
157
|
action,
|
|
148
158
|
trigger: "ON_CLICK"
|
|
149
159
|
};
|
|
@@ -157,20 +167,32 @@ function nextEventAt(walk) {
|
|
|
157
167
|
/** Runs `action` at `atMs`, recording the hold before it, its crossfade, and the step. */
|
|
158
168
|
function advance(walk, event, next) {
|
|
159
169
|
const { atMs, action } = event;
|
|
170
|
+
const fromGraph = walk.stateGraph;
|
|
171
|
+
const toGraph = walk.play.hasVariables() ? walk.play.cloneGraphFor(shownFrame(next)) : walk.graph;
|
|
160
172
|
const running = walk.segments.at(-1);
|
|
161
173
|
if (running && running.kind !== "hold" && running.endMs > atMs) running.endMs = atMs;
|
|
162
174
|
hold(walk, atMs);
|
|
163
175
|
const durationMs = transitionMs(action);
|
|
164
176
|
const animation = animationFor(walk.session, action);
|
|
165
|
-
if (animation !== "cut")
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
177
|
+
if (animation !== "cut") {
|
|
178
|
+
const easing = action.type === "NODE" && action.transition.easing ? {
|
|
179
|
+
easing: action.transition.easing,
|
|
180
|
+
easingCurve: action.transition.easingCurve,
|
|
181
|
+
easingSpring: action.transition.easingSpring
|
|
182
|
+
} : void 0;
|
|
183
|
+
const segment = {
|
|
184
|
+
kind: animation === "smart" ? "smart" : "dissolve",
|
|
185
|
+
from: walk.session,
|
|
186
|
+
to: next,
|
|
187
|
+
startMs: atMs,
|
|
188
|
+
endMs: atMs + durationMs,
|
|
189
|
+
fadeMs: durationMs
|
|
190
|
+
};
|
|
191
|
+
if (fromGraph !== walk.graph) segment.fromGraph = fromGraph;
|
|
192
|
+
if (toGraph !== walk.graph) segment.toGraph = toGraph;
|
|
193
|
+
if (easing) Object.assign(segment, easing);
|
|
194
|
+
walk.segments.push(segment);
|
|
195
|
+
}
|
|
174
196
|
walk.steps.push({
|
|
175
197
|
atMs,
|
|
176
198
|
frameId: shownFrame(next),
|
|
@@ -179,6 +201,7 @@ function advance(walk, event, next) {
|
|
|
179
201
|
});
|
|
180
202
|
if (action.type === "NODE" && action.navigation === "OVERLAY" && action.nodeId) walk.overlayPositions[action.nodeId] = action.overlayPosition;
|
|
181
203
|
walk.session = next;
|
|
204
|
+
walk.stateGraph = toGraph;
|
|
182
205
|
walk.readyMs = atMs + durationMs;
|
|
183
206
|
walk.timers = armTimers(walk.graph, next, walk.readyMs);
|
|
184
207
|
}
|
|
@@ -201,7 +224,7 @@ function finish(walk, durationMs, end) {
|
|
|
201
224
|
* held `tailMs`), or at `maxMs` (`truncated`).
|
|
202
225
|
*/
|
|
203
226
|
function planTimeline(graph, options) {
|
|
204
|
-
const { walk, start } = startWalk(graph, options);
|
|
227
|
+
const { walk, start } = startWalk(graph, createPlayScenes(() => graph), options);
|
|
205
228
|
const startKey = sessionDrawKey(walk.session);
|
|
206
229
|
for (let taken = 0; taken <= MAX_TIMELINE_STEPS; taken++) {
|
|
207
230
|
const dueAt = nextEventAt(walk);
|
|
@@ -218,13 +241,26 @@ function planTimeline(graph, options) {
|
|
|
218
241
|
return truncated ? finish(walk, options.maxMs, "truncated") : finish(walk, endMs, "ends");
|
|
219
242
|
}
|
|
220
243
|
const event = takeNextEvent(walk);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
244
|
+
if (!event?.action) continue;
|
|
245
|
+
const result = walk.play.run(walk.session, {
|
|
246
|
+
sourceId: event.sourceId,
|
|
247
|
+
action: event.action,
|
|
248
|
+
transition: event.action.type === "NODE" ? event.action.transition : null
|
|
249
|
+
}, shownFrame(walk.session));
|
|
250
|
+
if (result.variablesRefused) throw new TimelineError(`Could not run a variable action at ${seconds(event.atMs)}: ${result.variablesRefused}`);
|
|
251
|
+
const resolved = result.action ?? event.action;
|
|
252
|
+
const next = result.session;
|
|
253
|
+
if (next === walk.session) {
|
|
254
|
+
if (result.repaint) {
|
|
255
|
+
hold(walk, event.atMs);
|
|
256
|
+
walk.readyMs = event.atMs;
|
|
257
|
+
walk.stateGraph = walk.play.hasVariables() ? walk.play.cloneGraphFor(shownFrame(walk.session)) : walk.graph;
|
|
258
|
+
}
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
225
261
|
advance(walk, {
|
|
226
262
|
...event,
|
|
227
|
-
action
|
|
263
|
+
action: resolved
|
|
228
264
|
}, next);
|
|
229
265
|
if (sessionDrawKey(next) === startKey && walk.clickIndex >= walk.clicks.length) {
|
|
230
266
|
if (walk.readyMs === 0) throw new TimelineError(`The flow loops back to '${start.name}' at once`);
|
|
@@ -238,17 +274,27 @@ function planTimeline(graph, options) {
|
|
|
238
274
|
function frameAt(timeline, atMs) {
|
|
239
275
|
for (const segment of timeline.segments) {
|
|
240
276
|
if (atMs >= segment.endMs) continue;
|
|
241
|
-
if (segment.kind === "hold") return
|
|
277
|
+
if (segment.kind === "hold") return segment.graph ? {
|
|
278
|
+
session: segment.session,
|
|
279
|
+
graph: segment.graph
|
|
280
|
+
} : { session: segment.session };
|
|
242
281
|
const progress = (atMs - segment.startMs) / segment.fadeMs;
|
|
243
282
|
if (segment.kind === "smart") return {
|
|
244
283
|
smart: segment,
|
|
245
284
|
progress
|
|
246
285
|
};
|
|
247
|
-
|
|
286
|
+
const frame = {
|
|
248
287
|
from: segment.from,
|
|
249
288
|
to: segment.to,
|
|
250
|
-
mix: easingAt(segment.easing, progress
|
|
289
|
+
mix: easingAt(segment.easing, progress, {
|
|
290
|
+
curve: segment.easingCurve,
|
|
291
|
+
spring: segment.easingSpring,
|
|
292
|
+
duration: segment.fadeMs / 1e3
|
|
293
|
+
})
|
|
251
294
|
};
|
|
295
|
+
if (segment.fromGraph) frame.fromGraph = segment.fromGraph;
|
|
296
|
+
if (segment.toGraph) frame.toGraph = segment.toGraph;
|
|
297
|
+
return frame;
|
|
252
298
|
}
|
|
253
299
|
const last = timeline.segments.at(-1);
|
|
254
300
|
if (!last) throw new TimelineError("The timeline is empty");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.js","names":[],"sources":["../../src/prototype/timeline.ts"],"sourcesContent":["import type {\n PrototypeAction,\n PrototypeEasingType,\n PrototypeOverlayPositionType,\n PrototypeTransitionType,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\n\nimport { easingAt } from './easing'\nimport {\n primaryAction,\n shownFrame,\n startSession,\n step,\n timeoutReactions,\n topFrameOf,\n type PlaySession\n} from './session'\n\n/** A scripted click: the layer clicked, and when, in milliseconds from the start of play. */\nexport interface TimelineClick {\n atMs: number\n nodeId: string\n}\n\nexport interface TimelineOptions {\n /** The top-level frame play starts from. */\n startFrameId: string\n /** Clicks to run as play goes, in time order. */\n clicks?: readonly TimelineClick[]\n /** Where the timeline stops when the flow goes on longer. */\n maxMs: number\n /** How long the last frame stays once nothing else happens. */\n tailMs: number\n}\n\n/** A stretch of play that moves from one screen to the next over a transition's own length. */\ninterface TimelineTransition {\n from: PlaySession\n to: PlaySession\n startMs: number\n endMs: number\n /** The transition's own length, which keeps its pace when a later step cuts it short. */\n fadeMs: number\n easing?: PrototypeEasingType\n}\n\n/**\n * A stretch of play: one screen held still, a crossfade from one screen to the next, or a Smart\n * animate between them.\n */\nexport type TimelineSegment =\n | { kind: 'hold'; session: PlaySession; startMs: number; endMs: number }\n | ({ kind: 'dissolve' } & TimelineTransition)\n | ({ kind: 'smart' } & TimelineTransition)\n\n/** A Smart animate stretch of a timeline. */\nexport type TimelineSmartSegment = Extract<TimelineSegment, { kind: 'smart' }>\n\n/** One step play took: when, the frame it shows afterwards, what started it, and how it moved. */\nexport interface TimelineStep {\n atMs: number\n frameId: string\n trigger: 'AFTER_TIMEOUT' | 'ON_CLICK'\n transition: PrototypeTransitionType\n}\n\nexport interface Timeline {\n segments: TimelineSegment[]\n durationMs: number\n /** Clicks the walk never ran: past the cap, or on a layer whose hit runs no reaction. */\n skippedClicks: TimelineClick[]\n /** Play came back to the screen it started on, so the clip repeats seamlessly. */\n loops: boolean\n /** The flow went on past `maxMs`, where the timeline stops. */\n truncated: boolean\n steps: TimelineStep[]\n /** Where each overlay frame play opened sits over the screen, from the action that opened it. */\n overlayPositions: Record<string, PrototypeOverlayPositionType>\n}\n\n/**\n * What a timeline shows at a moment: one screen, two mid-crossfade with `mix` of the second, or a\n * Smart animate `progress` of the way through its time, which its animation eases.\n */\nexport type TimelineFrame =\n | { session: PlaySession }\n | { from: PlaySession; to: PlaySession; mix: number }\n | { smart: TimelineSmartSegment; progress: number }\n\n/** Why a flow cannot be played: the start frame has nothing to follow, or anything else. */\nexport type TimelineErrorReason = 'nothing-to-follow' | 'invalid'\n\n/** A flow that cannot be played as asked, with a message naming the frame or click at fault. */\nexport class TimelineError extends Error {\n override name = 'TimelineError'\n constructor(\n message: string,\n readonly reason: TimelineErrorReason = 'invalid'\n ) {\n super(message)\n }\n}\n\n/** Steps a timeline may take before it is refused, which stops cycles that take no time. */\nconst MAX_TIMELINE_STEPS = 10_000\n\n/** How long an action's transition runs, in milliseconds; a cut takes none. */\nexport function transitionMs(action: PrototypeAction): number {\n if (action.type !== 'NODE' || action.transition.type === 'INSTANT') return 0\n return Math.max(0, action.transition.duration * 1000)\n}\n\n/** How play shows a step: a cut, a crossfade, or Smart animate. */\nexport type PlayAnimation = 'cut' | 'dissolve' | 'smart'\n\n/**\n * How play animates `action` from `session`: a cut when it takes no time; Smart animate for a\n * Smart animate Change to, or a navigation between screens while no overlay is open, as Figma\n * has no Smart animate for overlays; a crossfade otherwise.\n */\nexport function animationFor(session: PlaySession, action: PrototypeAction): PlayAnimation {\n if (transitionMs(action) === 0 || action.type !== 'NODE') return 'cut'\n if (action.transition.type !== 'SMART_ANIMATE') return 'dissolve'\n if (action.navigation === 'CHANGE_TO') return 'smart'\n return action.navigation === 'NAVIGATE' && session.overlays.length === 0 ? 'smart' : 'dissolve'\n}\n\n/**\n * The curve a dissolve fades along, CSS `ease-out`, which Figma's dissolve uses by default: the\n * x and y of its two cubic Bézier control points. The player draws its crossfade with\n * `DISSOLVE_EASING_CSS` and a recording samples `dissolveEasing`, so both fade alike.\n */\nexport const DISSOLVE_EASING = { x1: 0, y1: 0, x2: 0.58, y2: 1 } as const\n\n/** `DISSOLVE_EASING` as a CSS timing function. */\nexport const DISSOLVE_EASING_CSS = `cubic-bezier(${DISSOLVE_EASING.x1}, ${DISSOLVE_EASING.y1}, ${DISSOLVE_EASING.x2}, ${DISSOLVE_EASING.y2})`\n\n/** The share of the new screen a dissolve shows at `progress` of the way, along `DISSOLVE_EASING`. */\nexport function dissolveEasing(progress: number): number {\n return easingAt('EASE_OUT', progress)\n}\n\n/**\n * What play draws, as a key two sessions share when they look alike: the base frame and its\n * overlays. History only matters to Back. State that changes what a frame shows extends it here,\n * and the recorder's screen cache follows.\n */\nexport function sessionDrawKey(session: PlaySession): string {\n return [session.frameId, ...session.overlays].join(' ')\n}\n\nfunction nameOf(graph: SceneGraph, id: string): string {\n return graph.getNode(id)?.name ?? id\n}\n\nfunction seconds(ms: number): string {\n return `${(ms / 1000).toFixed(2)} s`\n}\n\n/** Whether `node` sits in `frameId`, or is that frame. */\nfunction isInside(graph: SceneGraph, node: SceneNode, frameId: string): boolean {\n let current: SceneNode | undefined = node\n while (current) {\n if (current.id === frameId) return true\n current = current.parentId ? graph.getNode(current.parentId) : undefined\n }\n return false\n}\n\n/**\n * The action a click on `nodeId` runs, as a click on the canvas resolves one: the layer or its\n * nearest ancestor inside the shown frame with an `ON_CLICK` reaction. Throws when the layer is not\n * on the shown frame; null when nothing there reacts to a click.\n */\nfunction clickAction(\n graph: SceneGraph,\n session: PlaySession,\n click: TimelineClick,\n index: number\n): PrototypeAction | null {\n const shown = shownFrame(session)\n const node = graph.getNode(click.nodeId)\n if (!node || !isInside(graph, node, shown)) {\n throw new TimelineError(\n `click ${index + 1}: '${node?.name ?? click.nodeId}' is not on the shown frame '${nameOf(graph, shown)}' at ${seconds(click.atMs)}`\n )\n }\n let current: SceneNode | undefined = node\n while (current) {\n const reaction = current.prototypeReactions.find(\n (candidate) => candidate.trigger.type === 'ON_CLICK'\n )\n const action = reaction ? primaryAction(reaction) : null\n if (action) return action\n if (current.id === shown) return null\n current = current.parentId ? graph.getNode(current.parentId) : undefined\n }\n return null\n}\n\ninterface ArmedTimer {\n atMs: number\n action: PrototypeAction\n}\n\n/** The shown frame's After delay reactions, each due `delay` after the frame finished entering. */\nfunction armTimers(graph: SceneGraph, session: PlaySession, readyMs: number): ArmedTimer[] {\n return timeoutReactions(graph, session)\n .map(({ action, delayMs }) => ({ atMs: readyMs + delayMs, action }))\n .toSorted((a, b) => a.atMs - b.atMs)\n}\n\n/** Play at its start frame, which must be a top-level frame with something to follow. */\nfunction startWalk(graph: SceneGraph, options: TimelineOptions): { walk: Walk; start: SceneNode } {\n const start = graph.getNode(options.startFrameId)\n if (!start || topFrameOf(graph, start)?.id !== start.id) {\n throw new TimelineError(`'${start?.name ?? options.startFrameId}' is not a top-level frame`)\n }\n const session = startSession(start.id)\n const walk: Walk = {\n graph,\n session,\n readyMs: 0,\n timers: armTimers(graph, session, 0),\n clicks: (options.clicks ?? []).toSorted((a, b) => a.atMs - b.atMs),\n clickIndex: 0,\n skippedClicks: [],\n segments: [],\n steps: [],\n overlayPositions: {}\n }\n if (walk.timers.length === 0 && walk.clicks.length === 0) {\n throw new TimelineError(\n `'${start.name}' has no After delay interaction to follow`,\n 'nothing-to-follow'\n )\n }\n return { walk, start }\n}\n\n/** Play in progress on the virtual clock: what is shown, since when, and what is due next. */\ninterface Walk {\n graph: SceneGraph\n session: PlaySession\n /** When the shown screen finished entering; its After delays count from here. */\n readyMs: number\n timers: ArmedTimer[]\n clicks: TimelineClick[]\n clickIndex: number\n skippedClicks: TimelineClick[]\n segments: TimelineSegment[]\n steps: TimelineStep[]\n overlayPositions: Record<string, PrototypeOverlayPositionType>\n}\n\ninterface WalkEvent {\n atMs: number\n action: PrototypeAction | null\n trigger: TimelineStep['trigger']\n}\n\n/** Holds the shown screen from when it finished entering until `endMs`. */\nfunction hold(walk: Walk, endMs: number): void {\n if (endMs > walk.readyMs) {\n walk.segments.push({ kind: 'hold', session: walk.session, startMs: walk.readyMs, endMs })\n }\n}\n\n/** The earliest due timer or click, taken off its queue; null when nothing else will happen. */\nfunction takeNextEvent(walk: Walk): WalkEvent | null {\n const timer = walk.timers.at(0)\n const click = walk.clicks.at(walk.clickIndex)\n if (timer && (!click || timer.atMs <= click.atMs)) {\n walk.timers = walk.timers.slice(1)\n return { atMs: timer.atMs, action: timer.action, trigger: 'AFTER_TIMEOUT' }\n }\n if (!click) return null\n const action = clickAction(walk.graph, walk.session, click, walk.clickIndex)\n walk.clickIndex += 1\n if (!action) walk.skippedClicks.push(click)\n return { atMs: click.atMs, action, trigger: 'ON_CLICK' }\n}\n\n/** The earliest event's time without taking it, or infinity when nothing else will happen. */\nfunction nextEventAt(walk: Walk): number {\n const timerAt = walk.timers.at(0)?.atMs ?? Number.POSITIVE_INFINITY\n const clickAt = walk.clicks.at(walk.clickIndex)?.atMs ?? Number.POSITIVE_INFINITY\n return Math.min(timerAt, clickAt)\n}\n\n/** Runs `action` at `atMs`, recording the hold before it, its crossfade, and the step. */\nfunction advance(walk: Walk, event: WalkEvent & { action: PrototypeAction }, next: PlaySession) {\n const { atMs, action } = event\n // A step while a transition still runs cuts it short where it is.\n const running = walk.segments.at(-1)\n if (running && running.kind !== 'hold' && running.endMs > atMs) running.endMs = atMs\n hold(walk, atMs)\n const durationMs = transitionMs(action)\n const animation = animationFor(walk.session, action)\n if (animation !== 'cut') {\n walk.segments.push({\n kind: animation === 'smart' ? 'smart' : 'dissolve',\n from: walk.session,\n to: next,\n startMs: atMs,\n endMs: atMs + durationMs,\n fadeMs: durationMs,\n ...(action.type === 'NODE' && action.transition.easing\n ? { easing: action.transition.easing }\n : {})\n })\n }\n walk.steps.push({\n atMs,\n frameId: shownFrame(next),\n trigger: event.trigger,\n transition: durationMs > 0 && action.type === 'NODE' ? action.transition.type : 'INSTANT'\n })\n if (action.type === 'NODE' && action.navigation === 'OVERLAY' && action.nodeId) {\n walk.overlayPositions[action.nodeId] = action.overlayPosition\n }\n walk.session = next\n walk.readyMs = atMs + durationMs\n walk.timers = armTimers(walk.graph, next, walk.readyMs)\n}\n\nfunction finish(walk: Walk, durationMs: number, end: 'ends' | 'loops' | 'truncated'): Timeline {\n return {\n segments: walk.segments,\n durationMs,\n loops: end === 'loops',\n truncated: end === 'truncated',\n steps: walk.steps,\n overlayPositions: walk.overlayPositions,\n skippedClicks: [...walk.skippedClicks, ...walk.clicks.slice(walk.clickIndex)]\n }\n}\n\n/**\n * Plays a prototype on a virtual clock, from `startFrameId`, following its After delay\n * reactions and the scripted clicks as the player would, without waiting for real time. Each delay\n * counts from when the transition into its frame ends, as in Figma. The walk stops when play\n * returns to the screen it started on (`loops`), when nothing else will happen (the last screen is\n * held `tailMs`), or at `maxMs` (`truncated`).\n */\nexport function planTimeline(graph: SceneGraph, options: TimelineOptions): Timeline {\n const { walk, start } = startWalk(graph, options)\n const startKey = sessionDrawKey(walk.session)\n\n for (let taken = 0; taken <= MAX_TIMELINE_STEPS; taken++) {\n const dueAt = nextEventAt(walk)\n if (dueAt >= options.maxMs) {\n const endMs = Math.min(walk.readyMs + options.tailMs, options.maxMs)\n // More is due past the cap, or the cap falls before the last transition has ended.\n const truncated = dueAt !== Number.POSITIVE_INFINITY || walk.readyMs > options.maxMs\n hold(walk, truncated ? options.maxMs : endMs)\n // With no time left to hold it, the last screen still ends the timeline.\n if (!truncated && endMs <= walk.readyMs) {\n walk.segments.push({\n kind: 'hold',\n session: walk.session,\n startMs: walk.readyMs,\n endMs: walk.readyMs\n })\n }\n return truncated ? finish(walk, options.maxMs, 'truncated') : finish(walk, endMs, 'ends')\n }\n const event = takeNextEvent(walk)\n const action = event?.action\n if (!event || !action) continue\n const next = step(graph, walk.session, action)\n if (next === walk.session) continue\n advance(walk, { ...event, action }, next)\n\n if (sessionDrawKey(next) === startKey && walk.clickIndex >= walk.clicks.length) {\n if (walk.readyMs === 0) {\n throw new TimelineError(`The flow loops back to '${start.name}' at once`)\n }\n if (walk.readyMs > options.maxMs) return finish(walk, options.maxMs, 'truncated')\n return finish(walk, walk.readyMs, 'loops')\n }\n }\n throw new TimelineError(`The flow takes more than ${MAX_TIMELINE_STEPS} steps`)\n}\n\n/** What the timeline shows at `atMs`; past its end, the last screen it shows. */\nexport function frameAt(timeline: Timeline, atMs: number): TimelineFrame {\n for (const segment of timeline.segments) {\n if (atMs >= segment.endMs) continue\n if (segment.kind === 'hold') return { session: segment.session }\n const progress = (atMs - segment.startMs) / segment.fadeMs\n if (segment.kind === 'smart') return { smart: segment, progress }\n return { from: segment.from, to: segment.to, mix: easingAt(segment.easing, progress) }\n }\n const last = timeline.segments.at(-1)\n if (!last) throw new TimelineError('The timeline is empty')\n return { session: last.kind === 'hold' ? last.session : last.to }\n}\n"],"mappings":";;;;AA+FA,IAAa,gBAAb,cAAmC,MAAM;CAI5B;CAHX,OAAgB;CAChB,YACE,SACA,SAAuC,WACvC;EACA,MAAM,OAAO;EAFJ,K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;GAAI,KAAK,SAAS,QAAQ,QAAQ,QAAQ;EAAE;CACvF;CACA,MAAM,OAAO,SAAS,SAAS,GAAG,EAAE;CACpC,IAAI,CAAC,MAAM,MAAM,IAAI,cAAc,uBAAuB;CAC1D,OAAO,EAAE,SAAS,KAAK,SAAS,SAAS,KAAK,UAAU,KAAK,GAAG;AAClE"}
|
|
1
|
+
{"version":3,"file":"timeline.js","names":[],"sources":["../../src/prototype/timeline.ts"],"sourcesContent":["import type {\n PrototypeAction,\n PrototypeCubicBezier,\n PrototypeEasingType,\n PrototypeOverlayPositionType,\n PrototypeSpring,\n PrototypeTransitionType,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\n\nimport { easingAt } from './easing'\nimport { createPlayScenes, type PlayScenes } from './scenes'\nimport {\n primaryAction,\n shownFrame,\n startSession,\n timeoutReactions,\n topFrameOf,\n type PlaySession\n} from './session'\n\n/** A scripted click: the layer clicked, and when, in milliseconds from the start of play. */\nexport interface TimelineClick {\n atMs: number\n nodeId: string\n}\n\nexport interface TimelineOptions {\n /** The top-level frame play starts from. */\n startFrameId: string\n /** Clicks to run as play goes, in time order. */\n clicks?: readonly TimelineClick[]\n /** Where the timeline stops when the flow goes on longer. */\n maxMs: number\n /** How long the last frame stays once nothing else happens. */\n tailMs: number\n}\n\n/** A stretch of play that moves from one screen to the next over a transition's own length. */\ninterface TimelineTransition {\n from: PlaySession\n to: PlaySession\n startMs: number\n endMs: number\n /** The transition's own length, which keeps its pace when a later step cuts it short. */\n fadeMs: number\n easing?: PrototypeEasingType\n easingCurve?: PrototypeCubicBezier\n easingSpring?: PrototypeSpring\n /** The screens as play showed them, with its variable values and modes applied. */\n fromGraph?: SceneGraph\n toGraph?: SceneGraph\n}\n\n/**\n * A stretch of play: one screen held still, a crossfade from one screen to the next, or a Smart\n * animate between them.\n */\nexport type TimelineSegment =\n | { kind: 'hold'; session: PlaySession; startMs: number; endMs: number; graph?: SceneGraph }\n | ({ kind: 'dissolve' } & TimelineTransition)\n | ({ kind: 'smart' } & TimelineTransition)\n\n/** A Smart animate stretch of a timeline. */\nexport type TimelineSmartSegment = Extract<TimelineSegment, { kind: 'smart' }>\n\n/** One step play took: when, the frame it shows afterwards, what started it, and how it moved. */\nexport interface TimelineStep {\n atMs: number\n frameId: string\n trigger: 'AFTER_TIMEOUT' | 'ON_CLICK'\n transition: PrototypeTransitionType\n}\n\nexport interface Timeline {\n segments: TimelineSegment[]\n durationMs: number\n /** Clicks the walk never ran: past the cap, or on a layer whose hit runs no reaction. */\n skippedClicks: TimelineClick[]\n /** Play came back to the screen it started on, so the clip repeats seamlessly. */\n loops: boolean\n /** The flow went on past `maxMs`, where the timeline stops. */\n truncated: boolean\n steps: TimelineStep[]\n /** Where each overlay frame play opened sits over the screen, from the action that opened it. */\n overlayPositions: Record<string, PrototypeOverlayPositionType>\n}\n\n/**\n * What a timeline shows at a moment: one screen, two mid-crossfade with `mix` of the second, or a\n * Smart animate `progress` of the way through its time, which its animation eases.\n */\nexport type TimelineFrame =\n | { session: PlaySession; graph?: SceneGraph }\n | {\n from: PlaySession\n to: PlaySession\n mix: number\n fromGraph?: SceneGraph\n toGraph?: SceneGraph\n }\n | { smart: TimelineSmartSegment; progress: number }\n\n/** Why a flow cannot be played: the start frame has nothing to follow, or anything else. */\nexport type TimelineErrorReason = 'nothing-to-follow' | 'invalid'\n\n/** A flow that cannot be played as asked, with a message naming the frame or click at fault. */\nexport class TimelineError extends Error {\n override name = 'TimelineError'\n constructor(\n message: string,\n readonly reason: TimelineErrorReason = 'invalid'\n ) {\n super(message)\n }\n}\n\n/** Steps a timeline may take before it is refused, which stops cycles that take no time. */\nconst MAX_TIMELINE_STEPS = 10_000\n\n/** How long an action's transition runs, in milliseconds; a cut takes none. */\nexport function transitionMs(action: PrototypeAction): number {\n if (action.type !== 'NODE' || action.transition.type === 'INSTANT') return 0\n return Math.max(0, action.transition.duration * 1000)\n}\n\n/** How play shows a step: a cut, a crossfade, or Smart animate. */\nexport type PlayAnimation = 'cut' | 'dissolve' | 'smart'\n\n/**\n * How play animates `action` from `session`: a cut when it takes no time; Smart animate for a\n * Smart animate Change to, or a navigation between screens while no overlay is open, as Figma\n * has no Smart animate for overlays; a crossfade otherwise.\n */\nexport function animationFor(session: PlaySession, action: PrototypeAction): PlayAnimation {\n if (transitionMs(action) === 0 || action.type !== 'NODE') return 'cut'\n if (action.transition.type !== 'SMART_ANIMATE') return 'dissolve'\n if (action.navigation === 'CHANGE_TO') return 'smart'\n return action.navigation === 'NAVIGATE' && session.overlays.length === 0 ? 'smart' : 'dissolve'\n}\n\n/**\n * The curve a dissolve fades along, CSS `ease-out`, which Figma's dissolve uses by default: the\n * x and y of its two cubic Bézier control points. The player draws its crossfade with\n * `DISSOLVE_EASING_CSS` and a recording samples `dissolveEasing`, so both fade alike.\n */\nexport const DISSOLVE_EASING = { x1: 0, y1: 0, x2: 0.58, y2: 1 } as const\n\n/** `DISSOLVE_EASING` as a CSS timing function. */\nexport const DISSOLVE_EASING_CSS = `cubic-bezier(${DISSOLVE_EASING.x1}, ${DISSOLVE_EASING.y1}, ${DISSOLVE_EASING.x2}, ${DISSOLVE_EASING.y2})`\n\n/** The share of the new screen a dissolve shows at `progress` of the way, along `DISSOLVE_EASING`. */\nexport function dissolveEasing(progress: number): number {\n return easingAt('EASE_OUT', progress)\n}\n\n/**\n * What play draws, as a key two sessions share when they look alike: the base frame and its\n * overlays. History only matters to Back. State that changes what a frame shows extends it here,\n * and the recorder's screen cache follows.\n */\nexport function sessionDrawKey(session: PlaySession): string {\n return [session.frameId, ...session.overlays].join(' ')\n}\n\nfunction nameOf(graph: SceneGraph, id: string): string {\n return graph.getNode(id)?.name ?? id\n}\n\nfunction seconds(ms: number): string {\n return `${(ms / 1000).toFixed(2)} s`\n}\n\n/** Whether `node` sits in `frameId`, or is that frame. */\nfunction isInside(graph: SceneGraph, node: SceneNode, frameId: string): boolean {\n let current: SceneNode | undefined = node\n while (current) {\n if (current.id === frameId) return true\n current = current.parentId ? graph.getNode(current.parentId) : undefined\n }\n return false\n}\n\n/**\n * The action a click on `nodeId` runs, as a click on the canvas resolves one: the layer or its\n * nearest ancestor inside the shown frame with an `ON_CLICK` reaction. Throws when the layer is not\n * on the shown frame; null when nothing there reacts to a click.\n */\nfunction clickAction(\n graph: SceneGraph,\n session: PlaySession,\n click: TimelineClick,\n index: number\n): PrototypeAction | null {\n const shown = shownFrame(session)\n const node = graph.getNode(click.nodeId)\n if (!node || !isInside(graph, node, shown)) {\n throw new TimelineError(\n `click ${index + 1}: '${node?.name ?? click.nodeId}' is not on the shown frame '${nameOf(graph, shown)}' at ${seconds(click.atMs)}`\n )\n }\n let current: SceneNode | undefined = node\n while (current) {\n const reaction = current.prototypeReactions.find(\n (candidate) => candidate.trigger.type === 'ON_CLICK'\n )\n const action = reaction ? primaryAction(reaction) : null\n if (action) return action\n if (current.id === shown) return null\n current = current.parentId ? graph.getNode(current.parentId) : undefined\n }\n return null\n}\n\ninterface ArmedTimer {\n atMs: number\n sourceId: string\n action: PrototypeAction\n}\n\n/** The shown frame's After delay reactions, each due `delay` after the frame finished entering. */\nfunction armTimers(graph: SceneGraph, session: PlaySession, readyMs: number): ArmedTimer[] {\n const sourceId = shownFrame(session)\n return timeoutReactions(graph, session)\n .map(({ action, delayMs }) => ({ atMs: readyMs + delayMs, sourceId, action }))\n .toSorted((a, b) => a.atMs - b.atMs)\n}\n\n/** Play at its start frame, which must be a top-level frame with something to follow. */\nfunction startWalk(\n graph: SceneGraph,\n play: PlayScenes,\n options: TimelineOptions\n): { walk: Walk; start: SceneNode } {\n const start = graph.getNode(options.startFrameId)\n if (!start || topFrameOf(graph, start)?.id !== start.id) {\n throw new TimelineError(`'${start?.name ?? options.startFrameId}' is not a top-level frame`)\n }\n const session = startSession(start.id)\n const walk: Walk = {\n graph,\n play,\n session,\n stateGraph: play.hasVariables() ? play.cloneGraphFor(start.id) : graph,\n readyMs: 0,\n timers: armTimers(graph, session, 0),\n clicks: (options.clicks ?? []).toSorted((a, b) => a.atMs - b.atMs),\n clickIndex: 0,\n skippedClicks: [],\n segments: [],\n steps: [],\n overlayPositions: {}\n }\n if (walk.timers.length === 0 && walk.clicks.length === 0) {\n throw new TimelineError(\n `'${start.name}' has no After delay interaction to follow`,\n 'nothing-to-follow'\n )\n }\n return { walk, start }\n}\n\n/** Play in progress on the virtual clock: what is shown, since when, and what is due next. */\ninterface Walk {\n graph: SceneGraph\n play: PlayScenes\n session: PlaySession\n /** The shown screen as play draws it now, variables and modes applied. */\n stateGraph: SceneGraph\n /** When the shown screen finished entering; its After delays count from here. */\n readyMs: number\n timers: ArmedTimer[]\n clicks: TimelineClick[]\n clickIndex: number\n skippedClicks: TimelineClick[]\n segments: TimelineSegment[]\n steps: TimelineStep[]\n overlayPositions: Record<string, PrototypeOverlayPositionType>\n}\n\ninterface WalkEvent {\n atMs: number\n sourceId: string\n action: PrototypeAction | null\n trigger: TimelineStep['trigger']\n}\n\n/** Holds the shown screen from when it finished entering until `endMs`. */\nfunction hold(walk: Walk, endMs: number, graph = walk.stateGraph): void {\n if (endMs <= walk.readyMs) return\n const segment: TimelineSegment = {\n kind: 'hold',\n session: walk.session,\n startMs: walk.readyMs,\n endMs\n }\n // The document itself when play changed no variable, so the recorder draws as it always has.\n if (graph !== walk.graph) segment.graph = graph\n walk.segments.push(segment)\n}\n\n/** The earliest due timer or click, taken off its queue; null when nothing else will happen. */\nfunction takeNextEvent(walk: Walk): WalkEvent | null {\n const timer = walk.timers.at(0)\n const click = walk.clicks.at(walk.clickIndex)\n if (timer && (!click || timer.atMs <= click.atMs)) {\n walk.timers = walk.timers.slice(1)\n return {\n atMs: timer.atMs,\n sourceId: timer.sourceId,\n action: timer.action,\n trigger: 'AFTER_TIMEOUT'\n }\n }\n if (!click) return null\n const action = clickAction(walk.graph, walk.session, click, walk.clickIndex)\n walk.clickIndex += 1\n if (!action) walk.skippedClicks.push(click)\n return { atMs: click.atMs, sourceId: click.nodeId, action, trigger: 'ON_CLICK' }\n}\n\n/** The earliest event's time without taking it, or infinity when nothing else will happen. */\nfunction nextEventAt(walk: Walk): number {\n const timerAt = walk.timers.at(0)?.atMs ?? Number.POSITIVE_INFINITY\n const clickAt = walk.clicks.at(walk.clickIndex)?.atMs ?? Number.POSITIVE_INFINITY\n return Math.min(timerAt, clickAt)\n}\n\n/** Runs `action` at `atMs`, recording the hold before it, its crossfade, and the step. */\nfunction advance(\n walk: Walk,\n event: WalkEvent & { action: PrototypeAction },\n next: PlaySession\n): void {\n const { atMs, action } = event\n const fromGraph = walk.stateGraph\n const toGraph = walk.play.hasVariables() ? walk.play.cloneGraphFor(shownFrame(next)) : walk.graph\n // A step while a transition still runs cuts it short where it is.\n const running = walk.segments.at(-1)\n if (running && running.kind !== 'hold' && running.endMs > atMs) running.endMs = atMs\n hold(walk, atMs)\n const durationMs = transitionMs(action)\n const animation = animationFor(walk.session, action)\n if (animation !== 'cut') {\n const easing =\n action.type === 'NODE' && action.transition.easing\n ? {\n easing: action.transition.easing,\n easingCurve: action.transition.easingCurve,\n easingSpring: action.transition.easingSpring\n }\n : undefined\n const segment: TimelineTransition & { kind: 'smart' | 'dissolve' } = {\n kind: animation === 'smart' ? 'smart' : 'dissolve',\n from: walk.session,\n to: next,\n startMs: atMs,\n endMs: atMs + durationMs,\n fadeMs: durationMs\n }\n if (fromGraph !== walk.graph) segment.fromGraph = fromGraph\n if (toGraph !== walk.graph) segment.toGraph = toGraph\n if (easing) Object.assign(segment, easing)\n walk.segments.push(segment)\n }\n walk.steps.push({\n atMs,\n frameId: shownFrame(next),\n trigger: event.trigger,\n transition: durationMs > 0 && action.type === 'NODE' ? action.transition.type : 'INSTANT'\n })\n if (action.type === 'NODE' && action.navigation === 'OVERLAY' && action.nodeId) {\n walk.overlayPositions[action.nodeId] = action.overlayPosition\n }\n walk.session = next\n walk.stateGraph = toGraph\n walk.readyMs = atMs + durationMs\n walk.timers = armTimers(walk.graph, next, walk.readyMs)\n}\n\nfunction finish(walk: Walk, durationMs: number, end: 'ends' | 'loops' | 'truncated'): Timeline {\n return {\n segments: walk.segments,\n durationMs,\n loops: end === 'loops',\n truncated: end === 'truncated',\n steps: walk.steps,\n overlayPositions: walk.overlayPositions,\n skippedClicks: [...walk.skippedClicks, ...walk.clicks.slice(walk.clickIndex)]\n }\n}\n\n/**\n * Plays a prototype on a virtual clock, from `startFrameId`, following its After delay\n * reactions and the scripted clicks as the player would, without waiting for real time. Each delay\n * counts from when the transition into its frame ends, as in Figma. The walk stops when play\n * returns to the screen it started on (`loops`), when nothing else will happen (the last screen is\n * held `tailMs`), or at `maxMs` (`truncated`).\n */\nexport function planTimeline(graph: SceneGraph, options: TimelineOptions): Timeline {\n const play = createPlayScenes(() => graph)\n const { walk, start } = startWalk(graph, play, options)\n const startKey = sessionDrawKey(walk.session)\n\n for (let taken = 0; taken <= MAX_TIMELINE_STEPS; taken++) {\n const dueAt = nextEventAt(walk)\n if (dueAt >= options.maxMs) {\n const endMs = Math.min(walk.readyMs + options.tailMs, options.maxMs)\n // More is due past the cap, or the cap falls before the last transition has ended.\n const truncated = dueAt !== Number.POSITIVE_INFINITY || walk.readyMs > options.maxMs\n hold(walk, truncated ? options.maxMs : endMs)\n // With no time left to hold it, the last screen still ends the timeline.\n if (!truncated && endMs <= walk.readyMs) {\n walk.segments.push({\n kind: 'hold',\n session: walk.session,\n startMs: walk.readyMs,\n endMs: walk.readyMs\n })\n }\n return truncated ? finish(walk, options.maxMs, 'truncated') : finish(walk, endMs, 'ends')\n }\n const event = takeNextEvent(walk)\n if (!event?.action) continue\n const result = walk.play.run(\n walk.session,\n {\n sourceId: event.sourceId,\n action: event.action,\n transition: event.action.type === 'NODE' ? event.action.transition : null\n },\n shownFrame(walk.session)\n )\n if (result.variablesRefused) {\n throw new TimelineError(\n `Could not run a variable action at ${seconds(event.atMs)}: ${result.variablesRefused}`\n )\n }\n const resolved = result.action ?? event.action\n const next = result.session\n if (next === walk.session) {\n // A variable or mode change shows at once, without a transition or a step.\n if (result.repaint) {\n hold(walk, event.atMs)\n walk.readyMs = event.atMs\n walk.stateGraph = walk.play.hasVariables()\n ? walk.play.cloneGraphFor(shownFrame(walk.session))\n : walk.graph\n }\n continue\n }\n advance(walk, { ...event, action: resolved }, next)\n\n if (sessionDrawKey(next) === startKey && walk.clickIndex >= walk.clicks.length) {\n if (walk.readyMs === 0) {\n throw new TimelineError(`The flow loops back to '${start.name}' at once`)\n }\n if (walk.readyMs > options.maxMs) return finish(walk, options.maxMs, 'truncated')\n return finish(walk, walk.readyMs, 'loops')\n }\n }\n throw new TimelineError(`The flow takes more than ${MAX_TIMELINE_STEPS} steps`)\n}\n\n/** What the timeline shows at `atMs`; past its end, the last screen it shows. */\nexport function frameAt(timeline: Timeline, atMs: number): TimelineFrame {\n for (const segment of timeline.segments) {\n if (atMs >= segment.endMs) continue\n if (segment.kind === 'hold')\n return segment.graph\n ? { session: segment.session, graph: segment.graph }\n : { session: segment.session }\n const progress = (atMs - segment.startMs) / segment.fadeMs\n if (segment.kind === 'smart') return { smart: segment, progress }\n const frame: TimelineFrame = {\n from: segment.from,\n to: segment.to,\n mix: easingAt(segment.easing, progress, {\n curve: segment.easingCurve,\n spring: segment.easingSpring,\n duration: segment.fadeMs / 1000\n })\n }\n if (segment.fromGraph) frame.fromGraph = segment.fromGraph\n if (segment.toGraph) frame.toGraph = segment.toGraph\n return frame\n }\n const last = timeline.segments.at(-1)\n if (!last) throw new TimelineError('The timeline is empty')\n return { session: last.kind === 'hold' ? last.session : last.to }\n}\n"],"mappings":";;;;;AA4GA,IAAa,gBAAb,cAAmC,MAAM;CAI5B;CAHX,OAAgB;CAChB,YACE,SACA,SAAuC,WACvC;EACA,MAAM,OAAO;EAFJ,KAAA,SAAA;CAGX;AACF;;AAGA,MAAM,qBAAqB;;AAG3B,SAAgB,aAAa,QAAiC;CAC5D,IAAI,OAAO,SAAS,UAAU,OAAO,WAAW,SAAS,WAAW,OAAO;CAC3E,OAAO,KAAK,IAAI,GAAG,OAAO,WAAW,WAAW,GAAI;AACt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AAK,SAAS,SAAS,KAAK,UAAU,KAAK,GAAG;AAClE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PrototypeVariableValue } from "@pairdraw/scene-graph";
|
|
2
|
+
import { Color } from "@pairdraw/scene-graph/primitives";
|
|
3
|
+
//#region src/prototype/variables.d.ts
|
|
4
|
+
/** What a variable or expression resolves to at play time. */
|
|
5
|
+
type PrototypeResolvedValue = boolean | number | string | Color;
|
|
6
|
+
type PrototypeEvaluation = {
|
|
7
|
+
ok: true;
|
|
8
|
+
value: PrototypeResolvedValue;
|
|
9
|
+
} | {
|
|
10
|
+
ok: false;
|
|
11
|
+
reason: string;
|
|
12
|
+
};
|
|
13
|
+
/** Resolves an alias to the value its variable holds in this session. */
|
|
14
|
+
type PrototypeAliasResolver = (variableId: string) => PrototypeResolvedValue | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The value of a variable expression at play time, with aliases read from the session overlay.
|
|
17
|
+
* A function this build cannot compute, or a type a function does not take, is refused with a
|
|
18
|
+
* reason rather than guessed.
|
|
19
|
+
*/
|
|
20
|
+
declare function evaluateVariable(value: PrototypeVariableValue, resolveAlias?: PrototypeAliasResolver): PrototypeEvaluation;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { PrototypeAliasResolver, PrototypeEvaluation, PrototypeResolvedValue, evaluateVariable };
|
|
23
|
+
//# sourceMappingURL=variables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variables.d.ts","names":[],"sources":["../../src/prototype/variables.ts"],"mappings":";;;;KAIY,qDAAqD;KAErD;EACN;EAAU,OAAO;;EACjB;EAAW;;;KAGL,0BAA0B,uBAAuB;;;;;;iBA8J7C,iBACd,OAAO,wBACP,eAAc,yBACb"}
|