@pairdraw/core 0.19.1 → 0.20.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/ai/providers.d.ts +6 -0
- package/dist/ai/providers.d.ts.map +1 -1
- package/dist/ai/providers.js.map +1 -1
- package/dist/cache/resource.d.ts +8 -1
- package/dist/cache/resource.d.ts.map +1 -1
- package/dist/cache/resource.js +18 -0
- package/dist/cache/resource.js.map +1 -1
- package/dist/canvas/effects.d.ts +6 -4
- package/dist/canvas/effects.d.ts.map +1 -1
- package/dist/canvas/effects.js +37 -34
- package/dist/canvas/effects.js.map +1 -1
- package/dist/canvas/fills.d.ts.map +1 -1
- package/dist/canvas/fills.js +12 -8
- package/dist/canvas/fills.js.map +1 -1
- package/dist/canvas/images/adjustments.d.ts +18 -0
- package/dist/canvas/images/adjustments.d.ts.map +1 -0
- package/dist/canvas/images/adjustments.js +184 -0
- package/dist/canvas/images/adjustments.js.map +1 -0
- package/dist/canvas/images/previews.d.ts +1 -1
- package/dist/canvas/images/sampling.d.ts +13 -0
- package/dist/canvas/images/sampling.d.ts.map +1 -0
- package/dist/canvas/images/sampling.js +49 -0
- package/dist/canvas/images/sampling.js.map +1 -0
- package/dist/canvas/index.d.ts +2 -2
- package/dist/canvas/masks.d.ts +1 -1
- package/dist/canvas/masks.d.ts.map +1 -1
- package/dist/canvas/masks.js.map +1 -1
- package/dist/canvas/noise/render.d.ts +15 -0
- package/dist/canvas/noise/render.d.ts.map +1 -0
- package/dist/canvas/noise/render.js +56 -0
- package/dist/canvas/noise/render.js.map +1 -0
- package/dist/canvas/noise/shader.d.ts +43 -0
- package/dist/canvas/noise/shader.d.ts.map +1 -0
- package/dist/canvas/noise/shader.js +161 -0
- package/dist/canvas/noise/shader.js.map +1 -0
- package/dist/canvas/noise/table.d.ts +13 -0
- package/dist/canvas/noise/table.d.ts.map +1 -0
- package/dist/canvas/noise/table.js +408 -0
- package/dist/canvas/noise/table.js.map +1 -0
- package/dist/canvas/noise/tile.d.ts +22 -0
- package/dist/canvas/noise/tile.d.ts.map +1 -0
- package/dist/canvas/noise/tile.js +73 -0
- package/dist/canvas/noise/tile.js.map +1 -0
- package/dist/canvas/outline-stroke.js +1 -1
- package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
- package/dist/canvas/overlays/auto-layout-hover.js +31 -71
- package/dist/canvas/overlays/auto-layout-hover.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/selection.d.ts +1 -2
- package/dist/canvas/overlays/selection.d.ts.map +1 -1
- package/dist/canvas/overlays/selection.js +2 -9
- package/dist/canvas/overlays/selection.js.map +1 -1
- package/dist/canvas/renderer/chunks/index.d.ts +1 -1
- package/dist/canvas/renderer/fonts.d.ts.map +1 -1
- package/dist/canvas/renderer/fonts.js +2 -0
- package/dist/canvas/renderer/fonts.js.map +1 -1
- package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +6 -0
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts +0 -1
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +1 -4
- 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 +0 -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 +13 -2
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/play-scenes.d.ts +13 -0
- package/dist/canvas/renderer/play-scenes.d.ts.map +1 -0
- package/dist/canvas/renderer/play-scenes.js +40 -0
- package/dist/canvas/renderer/play-scenes.js.map +1 -0
- package/dist/canvas/renderer/tiles/cache.d.ts +19 -1
- package/dist/canvas/renderer/tiles/cache.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/cache.js +32 -1
- package/dist/canvas/renderer/tiles/cache.js.map +1 -1
- package/dist/canvas/renderer/tiles/controller.d.ts +11 -0
- package/dist/canvas/renderer/tiles/controller.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/controller.js +18 -1
- package/dist/canvas/renderer/tiles/controller.js.map +1 -1
- package/dist/canvas/renderer/tiles/index.d.ts +2 -2
- package/dist/canvas/renderer/tiles/planner.d.ts +1 -1
- package/dist/canvas/renderer/types.d.ts +18 -4
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer/visual-bounds.d.ts +1 -1
- package/dist/canvas/renderer/visual-bounds.js +1 -1
- package/dist/canvas/renderer.d.ts +22 -3
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +29 -1
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/scene.d.ts +2 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +41 -9
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/shadows/silhouette.js +1 -1
- package/dist/canvas/texture.d.ts +20 -0
- package/dist/canvas/texture.d.ts.map +1 -0
- package/dist/canvas/texture.js +100 -0
- package/dist/canvas/texture.js.map +1 -0
- package/dist/clipboard.js +16 -5
- package/dist/clipboard.js.map +1 -1
- package/dist/constants.d.ts +5 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +5 -1
- package/dist/constants.js.map +1 -1
- package/dist/design-jsx/index.d.ts +2 -2
- package/dist/design-jsx/index.js +2 -2
- package/dist/design-jsx/renderer.d.ts +3 -2
- package/dist/design-jsx/renderer.d.ts.map +1 -1
- package/dist/design-jsx/renderer.js +2 -2
- package/dist/design-jsx/renderer.js.map +1 -1
- package/dist/design-memory/check.d.ts +90 -0
- package/dist/design-memory/check.d.ts.map +1 -0
- package/dist/design-memory/check.js +281 -0
- package/dist/design-memory/check.js.map +1 -0
- package/dist/design-memory/describe.d.ts +37 -0
- package/dist/design-memory/describe.d.ts.map +1 -0
- package/dist/design-memory/describe.js +52 -0
- package/dist/design-memory/describe.js.map +1 -0
- package/dist/design-memory/distil.d.ts +22 -0
- package/dist/design-memory/distil.d.ts.map +1 -0
- package/dist/design-memory/distil.js +54 -0
- package/dist/design-memory/distil.js.map +1 -0
- package/dist/design-memory/document.d.ts +12 -0
- package/dist/design-memory/document.d.ts.map +1 -0
- package/dist/design-memory/document.js +64 -0
- package/dist/design-memory/document.js.map +1 -0
- package/dist/design-memory/guard.d.ts +48 -0
- package/dist/design-memory/guard.d.ts.map +1 -0
- package/dist/design-memory/guard.js +105 -0
- package/dist/design-memory/guard.js.map +1 -0
- package/dist/design-memory/index.d.ts +9 -0
- package/dist/design-memory/index.js +9 -0
- package/dist/design-memory/refusal.d.ts +32 -0
- package/dist/design-memory/refusal.d.ts.map +1 -0
- package/dist/design-memory/refusal.js +68 -0
- package/dist/design-memory/refusal.js.map +1 -0
- package/dist/design-memory/rules.d.ts +63 -0
- package/dist/design-memory/rules.d.ts.map +1 -0
- package/dist/design-memory/rules.js +224 -0
- package/dist/design-memory/rules.js.map +1 -0
- package/dist/design-memory/values.d.ts +28 -0
- package/dist/design-memory/values.d.ts.map +1 -0
- package/dist/design-memory/values.js +160 -0
- package/dist/design-memory/values.js.map +1 -0
- package/dist/editor/alignment.js +1 -1
- package/dist/editor/bridges/components.d.ts +2 -0
- package/dist/editor/bridges/components.d.ts.map +1 -1
- package/dist/editor/bridges/components.js +2 -0
- package/dist/editor/bridges/components.js.map +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/clipboard/assets.js +1 -1
- package/dist/editor/clipboard/export.d.ts.map +1 -1
- package/dist/editor/clipboard/export.js +16 -2
- package/dist/editor/clipboard/export.js.map +1 -1
- package/dist/editor/clipboard/placement.d.ts +1 -1
- package/dist/editor/clipboard/placement.js +1 -1
- package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
- package/dist/editor/clipboard/snapshot.js +12 -4
- package/dist/editor/clipboard/snapshot.js.map +1 -1
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +2 -7
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/color-space.d.ts.map +1 -1
- package/dist/editor/color-space.js +33 -38
- package/dist/editor/color-space.js.map +1 -1
- package/dist/editor/components/instances.d.ts +2 -0
- package/dist/editor/components/instances.d.ts.map +1 -1
- package/dist/editor/components/instances.js +22 -1
- package/dist/editor/components/instances.js.map +1 -1
- package/dist/editor/components.d.ts +2 -0
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor/connectors/attach.js +1 -1
- package/dist/editor/create.d.ts +36 -8
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +26 -61
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/design-memory.d.ts +11 -0
- package/dist/editor/design-memory.d.ts.map +1 -0
- package/dist/editor/design-memory.js +40 -0
- package/dist/editor/design-memory.js.map +1 -0
- package/dist/editor/design-tokens.d.ts +4 -0
- package/dist/editor/design-tokens.d.ts.map +1 -1
- package/dist/editor/design-tokens.js +30 -1
- package/dist/editor/design-tokens.js.map +1 -1
- package/dist/editor/document-colors.d.ts +23 -0
- package/dist/editor/document-colors.d.ts.map +1 -0
- package/dist/editor/document-colors.js +53 -0
- package/dist/editor/document-colors.js.map +1 -0
- package/dist/editor/eyedropper.d.ts +47 -0
- package/dist/editor/eyedropper.d.ts.map +1 -0
- package/dist/editor/eyedropper.js +168 -0
- package/dist/editor/eyedropper.js.map +1 -0
- package/dist/editor/fonts.d.ts +9 -0
- package/dist/editor/fonts.d.ts.map +1 -0
- package/dist/editor/fonts.js +14 -0
- package/dist/editor/fonts.js.map +1 -0
- package/dist/editor/history/atomic-tool.d.ts +9 -2
- package/dist/editor/history/atomic-tool.d.ts.map +1 -1
- package/dist/editor/history/atomic-tool.js +6 -0
- package/dist/editor/history/atomic-tool.js.map +1 -1
- package/dist/editor/history/capture.d.ts +13 -0
- package/dist/editor/history/capture.d.ts.map +1 -0
- package/dist/editor/history/capture.js +28 -0
- package/dist/editor/history/capture.js.map +1 -0
- package/dist/editor/history/document-change.d.ts.map +1 -1
- package/dist/editor/history/document-change.js +2 -22
- package/dist/editor/history/document-change.js.map +1 -1
- package/dist/editor/history/edit.d.ts +7 -0
- package/dist/editor/history/edit.d.ts.map +1 -1
- package/dist/editor/history/edit.js +6 -3
- package/dist/editor/history/edit.js.map +1 -1
- package/dist/editor/history/subtree.d.ts +9 -0
- package/dist/editor/history/subtree.d.ts.map +1 -1
- package/dist/editor/history/subtree.js +12 -2
- package/dist/editor/history/subtree.js.map +1 -1
- package/dist/editor/index.d.ts +4 -2
- package/dist/editor/index.js +4 -2
- package/dist/editor/nudge.js +1 -1
- package/dist/editor/nudge.js.map +1 -1
- package/dist/editor/pages.d.ts +7 -5
- package/dist/editor/pages.d.ts.map +1 -1
- package/dist/editor/pages.js +35 -25
- package/dist/editor/pages.js.map +1 -1
- package/dist/editor/play/states.d.ts +3 -1
- package/dist/editor/play/states.d.ts.map +1 -1
- package/dist/editor/play/states.js +1 -1
- package/dist/editor/play/states.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/render-requests.d.ts +18 -0
- package/dist/editor/render-requests.d.ts.map +1 -0
- package/dist/editor/render-requests.js +76 -0
- package/dist/editor/render-requests.js.map +1 -0
- package/dist/editor/scale/rescale.d.ts +1 -1
- package/dist/editor/selection/container.d.ts +2 -0
- package/dist/editor/selection/container.d.ts.map +1 -1
- package/dist/editor/selection/container.js +17 -1
- package/dist/editor/selection/container.js.map +1 -1
- package/dist/editor/selection/navigation.js +7 -4
- package/dist/editor/selection/navigation.js.map +1 -1
- package/dist/editor/selection/overlays.d.ts.map +1 -1
- package/dist/editor/selection/overlays.js +1 -1
- package/dist/editor/selection/overlays.js.map +1 -1
- package/dist/editor/selection/read.d.ts +6 -2
- package/dist/editor/selection.d.ts +9 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/shapes/with-text.d.ts.map +1 -1
- package/dist/editor/shapes/with-text.js +2 -5
- package/dist/editor/shapes/with-text.js.map +1 -1
- package/dist/editor/structure/auto-layout-wrap.js +1 -1
- package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
- package/dist/editor/structure/boolean.d.ts +2 -3
- package/dist/editor/structure/boolean.d.ts.map +1 -1
- package/dist/editor/structure/boolean.js.map +1 -1
- package/dist/editor/structure/group/bounds.d.ts.map +1 -1
- package/dist/editor/structure/group/bounds.js +1 -3
- package/dist/editor/structure/group/bounds.js.map +1 -1
- package/dist/editor/structure/outline-stroke.js +3 -3
- package/dist/editor/structure/outline-stroke.js.map +1 -1
- package/dist/editor/structure/reorder.d.ts.map +1 -1
- package/dist/editor/structure/reorder.js +7 -14
- package/dist/editor/structure/reorder.js.map +1 -1
- package/dist/editor/structure/state.js +1 -1
- package/dist/editor/structure/state.js.map +1 -1
- package/dist/editor/structure.d.ts +1 -2
- package/dist/editor/structure.d.ts.map +1 -1
- package/dist/editor/structure.js +3 -3
- package/dist/editor/structure.js.map +1 -1
- package/dist/editor/tool-registry.d.ts.map +1 -1
- package/dist/editor/tool-registry.js +2 -1
- package/dist/editor/tool-registry.js.map +1 -1
- package/dist/editor/types.d.ts +9 -2
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/variables.d.ts.map +1 -1
- package/dist/editor/variables.js +57 -1
- package/dist/editor/variables.js.map +1 -1
- package/dist/editor/variations/create.d.ts +28 -0
- package/dist/editor/variations/create.d.ts.map +1 -0
- package/dist/editor/variations/create.js +176 -0
- package/dist/editor/variations/create.js.map +1 -0
- package/dist/editor/variations/pick.d.ts +16 -0
- package/dist/editor/variations/pick.d.ts.map +1 -0
- package/dist/editor/variations/pick.js +23 -0
- package/dist/editor/variations/pick.js.map +1 -0
- package/dist/editor/variations.d.ts +28 -0
- package/dist/editor/variations.d.ts.map +1 -0
- package/dist/editor/variations.js +88 -0
- package/dist/editor/variations.js.map +1 -0
- package/dist/figma-api/accessors/reactions.d.ts.map +1 -1
- package/dist/figma-api/accessors/reactions.js +4 -1
- package/dist/figma-api/accessors/reactions.js.map +1 -1
- package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
- package/dist/figma-api/accessors/text/index.js +7 -1
- package/dist/figma-api/accessors/text/index.js.map +1 -1
- package/dist/figma-api/accessors/text/opentype.d.ts +17 -0
- package/dist/figma-api/accessors/text/opentype.d.ts.map +1 -0
- package/dist/figma-api/accessors/text/opentype.js +28 -0
- package/dist/figma-api/accessors/text/opentype.js.map +1 -0
- package/dist/figma-api/accessors/visual.d.ts.map +1 -1
- package/dist/figma-api/accessors/visual.js +33 -0
- package/dist/figma-api/accessors/visual.js.map +1 -1
- package/dist/figma-api/effects.d.ts +79 -3
- package/dist/figma-api/effects.d.ts.map +1 -1
- package/dist/figma-api/effects.js +150 -9
- package/dist/figma-api/effects.js.map +1 -1
- package/dist/figma-api/fonts/loaded.d.ts +3 -1
- package/dist/figma-api/fonts/loaded.d.ts.map +1 -1
- package/dist/figma-api/fonts/loaded.js +8 -1
- package/dist/figma-api/fonts/loaded.js.map +1 -1
- package/dist/figma-api/index.d.ts +18 -0
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +19 -1
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/overrides.d.ts +13 -1
- package/dist/figma-api/overrides.d.ts.map +1 -1
- package/dist/figma-api/overrides.js +196 -4
- package/dist/figma-api/overrides.js.map +1 -1
- package/dist/figma-api/paints.d.ts +3 -3
- package/dist/figma-api/paints.d.ts.map +1 -1
- package/dist/figma-api/paints.js +14 -4
- package/dist/figma-api/paints.js.map +1 -1
- package/dist/figma-api/proxy.d.ts +4 -1
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +1 -1
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +41 -13
- package/dist/figma-api/reactions.d.ts.map +1 -1
- package/dist/figma-api/reactions.js +113 -31
- package/dist/figma-api/reactions.js.map +1 -1
- package/dist/figma-api/render-bounds.js +1 -1
- package/dist/figma-api/serialization.d.ts.map +1 -1
- package/dist/figma-api/serialization.js +2 -1
- package/dist/figma-api/serialization.js.map +1 -1
- package/dist/figma-api/shape-details.d.ts +26 -0
- package/dist/figma-api/shape-details.d.ts.map +1 -0
- package/dist/figma-api/shape-details.js +28 -0
- package/dist/figma-api/shape-details.js.map +1 -0
- package/dist/figma-api/shape-with-text.js +2 -5
- package/dist/figma-api/shape-with-text.js.map +1 -1
- package/dist/figma-api/surface.d.ts +7 -4
- package/dist/figma-api/surface.d.ts.map +1 -1
- package/dist/figma-api/surface.js +7 -2
- package/dist/figma-api/surface.js.map +1 -1
- package/dist/figma-api/transform.d.ts +1 -1
- package/dist/geometry/figma.d.ts +1 -1
- package/dist/geometry/image-crop.d.ts +1 -1
- package/dist/geometry/image-crop.js +1 -1
- package/dist/icons/svg.js +1 -1
- package/dist/icons/svg.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/io/formats/boolean-path.d.ts +19 -0
- package/dist/io/formats/boolean-path.d.ts.map +1 -0
- package/dist/io/formats/boolean-path.js +47 -0
- package/dist/io/formats/boolean-path.js.map +1 -0
- package/dist/io/formats/design-tokens/decode.js +1 -1
- package/dist/io/formats/design-tokens/index.d.ts +4 -1
- package/dist/io/formats/design-tokens/index.js +4 -1
- package/dist/io/formats/design-tokens/plan/changes.d.ts +5 -3
- package/dist/io/formats/design-tokens/plan/changes.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/changes.js +1 -1
- package/dist/io/formats/design-tokens/plan/changes.js.map +1 -1
- package/dist/io/formats/design-tokens/project.d.ts +17 -2
- package/dist/io/formats/design-tokens/project.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/project.js +29 -8
- package/dist/io/formats/design-tokens/project.js.map +1 -1
- package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/sync/apply.d.ts +42 -0
- package/dist/io/formats/design-tokens/sync/apply.d.ts.map +1 -0
- package/dist/io/formats/design-tokens/sync/apply.js +73 -0
- package/dist/io/formats/design-tokens/sync/apply.js.map +1 -0
- package/dist/io/formats/design-tokens/sync/drift.d.ts +77 -0
- package/dist/io/formats/design-tokens/sync/drift.d.ts.map +1 -0
- package/dist/io/formats/design-tokens/sync/drift.js +391 -0
- package/dist/io/formats/design-tokens/sync/drift.js.map +1 -0
- package/dist/io/formats/design-tokens/sync/files.d.ts +15 -0
- package/dist/io/formats/design-tokens/sync/files.d.ts.map +1 -0
- package/dist/io/formats/design-tokens/sync/files.js +35 -0
- package/dist/io/formats/design-tokens/sync/files.js.map +1 -0
- package/dist/io/formats/drawio/edges.d.ts +7 -1
- package/dist/io/formats/drawio/edges.d.ts.map +1 -1
- package/dist/io/formats/drawio/edges.js +54 -1
- package/dist/io/formats/drawio/edges.js.map +1 -1
- package/dist/io/formats/drawio/export.d.ts.map +1 -1
- package/dist/io/formats/drawio/export.js +19 -2
- package/dist/io/formats/drawio/export.js.map +1 -1
- package/dist/io/formats/drawio/index.d.ts.map +1 -1
- package/dist/io/formats/drawio/index.js +2 -1
- package/dist/io/formats/drawio/index.js.map +1 -1
- package/dist/io/formats/drawio/label.js +1 -1
- package/dist/io/formats/drawio/paint.js +1 -1
- package/dist/io/formats/drawio/placement.d.ts +1 -1
- package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/patch/index.js +5 -0
- package/dist/io/formats/fig/export/patch/index.js.map +1 -1
- package/dist/io/formats/fig/thumbnail-page.d.ts +3 -4
- package/dist/io/formats/fig/thumbnail-page.d.ts.map +1 -1
- package/dist/io/formats/fig/thumbnail-page.js.map +1 -1
- package/dist/io/formats/html/import.d.ts.map +1 -1
- package/dist/io/formats/html/import.js +3 -1
- package/dist/io/formats/html/import.js.map +1 -1
- package/dist/io/formats/html/index.d.ts +2 -2
- package/dist/io/formats/html/index.d.ts.map +1 -1
- package/dist/io/formats/html/index.js +6 -4
- package/dist/io/formats/html/index.js.map +1 -1
- package/dist/io/formats/html/layers.d.ts +7 -4
- package/dist/io/formats/html/layers.d.ts.map +1 -1
- package/dist/io/formats/html/layers.js +4 -1
- package/dist/io/formats/html/layers.js.map +1 -1
- package/dist/io/formats/html/vectors.d.ts +2 -1
- package/dist/io/formats/html/vectors.d.ts.map +1 -1
- package/dist/io/formats/html/vectors.js +3 -2
- package/dist/io/formats/html/vectors.js.map +1 -1
- package/dist/io/formats/mermaid/styles.js +1 -1
- package/dist/io/formats/pdf/document.d.ts +3 -1
- package/dist/io/formats/pdf/document.d.ts.map +1 -1
- package/dist/io/formats/pdf/document.js +6 -3
- package/dist/io/formats/pdf/document.js.map +1 -1
- package/dist/io/formats/pdf/dom.d.ts +6 -1
- package/dist/io/formats/pdf/dom.d.ts.map +1 -1
- package/dist/io/formats/pdf/dom.js +9 -22
- package/dist/io/formats/pdf/dom.js.map +1 -1
- package/dist/io/formats/pdf/export.js +1 -1
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/pdf/prepare.d.ts +1 -1
- package/dist/io/formats/pen/imports.d.ts +4 -1
- package/dist/io/formats/pen/imports.d.ts.map +1 -1
- package/dist/io/formats/pen/imports.js.map +1 -1
- package/dist/io/formats/pen/index.d.ts.map +1 -1
- package/dist/io/formats/pen/index.js +31 -3
- package/dist/io/formats/pen/index.js.map +1 -1
- package/dist/io/formats/pptx/export.js +1 -1
- package/dist/io/formats/pptx/geometry.d.ts +1 -1
- package/dist/io/formats/raster/adjusted-images.d.ts +15 -0
- package/dist/io/formats/raster/adjusted-images.d.ts.map +1 -0
- package/dist/io/formats/raster/adjusted-images.js +118 -0
- package/dist/io/formats/raster/adjusted-images.js.map +1 -0
- package/dist/io/formats/raster/headless.d.ts +11 -1
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +4 -4
- 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/pixels.d.ts +7 -1
- package/dist/io/formats/raster/pixels.d.ts.map +1 -1
- package/dist/io/formats/raster/pixels.js.map +1 -1
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +4 -0
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts +5 -6
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +4 -54
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/effects.d.ts +16 -0
- package/dist/io/formats/svg/effects.d.ts.map +1 -0
- package/dist/io/formats/svg/effects.js +126 -0
- package/dist/io/formats/svg/effects.js.map +1 -0
- package/dist/io/formats/svg/export.d.ts +7 -1
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +224 -50
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/filter.d.ts +27 -0
- package/dist/io/formats/svg/filter.d.ts.map +1 -0
- package/dist/io/formats/svg/filter.js +44 -0
- package/dist/io/formats/svg/filter.js.map +1 -0
- package/dist/io/formats/svg/grain.d.ts +26 -0
- package/dist/io/formats/svg/grain.d.ts.map +1 -0
- package/dist/io/formats/svg/grain.js +298 -0
- package/dist/io/formats/svg/grain.js.map +1 -0
- package/dist/io/formats/svg/strokes.d.ts +1 -1
- package/dist/io/formats/svg/strokes.d.ts.map +1 -1
- package/dist/io/formats/svg/strokes.js +1 -2
- package/dist/io/formats/svg/strokes.js.map +1 -1
- package/dist/io/formats/svg/text/import.js +1 -1
- package/dist/io/formats/svg/text/layout.d.ts +5 -2
- package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
- package/dist/io/formats/svg/text/layout.js +6 -3
- package/dist/io/formats/svg/text/layout.js.map +1 -1
- package/dist/io/formats/video/composite.d.ts +18 -0
- package/dist/io/formats/video/composite.d.ts.map +1 -0
- package/dist/io/formats/video/composite.js +79 -0
- package/dist/io/formats/video/composite.js.map +1 -0
- package/dist/io/formats/video/formats.d.ts +29 -0
- package/dist/io/formats/video/formats.d.ts.map +1 -0
- package/dist/io/formats/video/formats.js +43 -0
- package/dist/io/formats/video/formats.js.map +1 -0
- package/dist/io/formats/video/gif.d.ts +13 -0
- package/dist/io/formats/video/gif.d.ts.map +1 -0
- package/dist/io/formats/video/gif.js +56 -0
- package/dist/io/formats/video/gif.js.map +1 -0
- package/dist/io/formats/video/index.d.ts +9 -0
- package/dist/io/formats/video/index.js +9 -0
- package/dist/io/formats/video/plan.d.ts +64 -0
- package/dist/io/formats/video/plan.d.ts.map +1 -0
- package/dist/io/formats/video/plan.js +90 -0
- package/dist/io/formats/video/plan.js.map +1 -0
- package/dist/io/formats/video/record.d.ts +36 -0
- package/dist/io/formats/video/record.d.ts.map +1 -0
- package/dist/io/formats/video/record.js +154 -0
- package/dist/io/formats/video/record.js.map +1 -0
- package/dist/io/formats/video/sink.d.ts +29 -0
- package/dist/io/formats/video/sink.d.ts.map +1 -0
- package/dist/io/formats/video/sink.js +16 -0
- package/dist/io/formats/video/sink.js.map +1 -0
- package/dist/io/formats/video/size.d.ts +19 -0
- package/dist/io/formats/video/size.d.ts.map +1 -0
- package/dist/io/formats/video/size.js +26 -0
- package/dist/io/formats/video/size.js.map +1 -0
- package/dist/io/formats/video/webcodecs.d.ts +18 -0
- package/dist/io/formats/video/webcodecs.d.ts.map +1 -0
- package/dist/io/formats/video/webcodecs.js +74 -0
- package/dist/io/formats/video/webcodecs.js.map +1 -0
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +40 -11
- package/dist/io/formats.js.map +1 -1
- package/dist/io/types.d.ts +19 -4
- package/dist/io/types.d.ts.map +1 -1
- package/dist/kiwi/fig/parse/transfer.d.ts +1 -1
- package/dist/layout/apply.d.ts.map +1 -1
- package/dist/layout/apply.js +50 -12
- package/dist/layout/apply.js.map +1 -1
- package/dist/layout/auto-layout-handles.d.ts +66 -0
- package/dist/layout/auto-layout-handles.d.ts.map +1 -0
- package/dist/layout/auto-layout-handles.js +291 -0
- package/dist/layout/auto-layout-handles.js.map +1 -0
- package/dist/layout/derived.d.ts +7 -1
- package/dist/layout/derived.d.ts.map +1 -1
- package/dist/layout/derived.js +11 -1
- package/dist/layout/derived.js.map +1 -1
- package/dist/layout/grid.d.ts +7 -2
- package/dist/layout/grid.d.ts.map +1 -1
- package/dist/layout/grid.js +27 -9
- package/dist/layout/grid.js.map +1 -1
- package/dist/layout/mutations.d.ts +1 -0
- package/dist/layout/mutations.d.ts.map +1 -1
- package/dist/layout/mutations.js +10 -0
- package/dist/layout/mutations.js.map +1 -1
- package/dist/layout/strokes.d.ts +9 -1
- package/dist/layout/strokes.d.ts.map +1 -1
- package/dist/layout/strokes.js +12 -1
- package/dist/layout/strokes.js.map +1 -1
- package/dist/layout/yoga-helpers.d.ts +3 -1
- package/dist/layout/yoga-helpers.d.ts.map +1 -1
- package/dist/layout/yoga-helpers.js +16 -2
- package/dist/layout/yoga-helpers.js.map +1 -1
- package/dist/layout.d.ts +3 -2
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +73 -39
- package/dist/layout.js.map +1 -1
- package/dist/lint/fixes.d.ts.map +1 -1
- package/dist/lint/fixes.js +9 -3
- package/dist/lint/fixes.js.map +1 -1
- package/dist/lint/index.d.ts +3 -2
- package/dist/lint/index.js +2 -1
- package/dist/lint/linter.d.ts +13 -0
- package/dist/lint/linter.d.ts.map +1 -1
- package/dist/lint/linter.js +123 -9
- package/dist/lint/linter.js.map +1 -1
- package/dist/lint/presets.d.ts.map +1 -1
- package/dist/lint/presets.js +2 -0
- package/dist/lint/presets.js.map +1 -1
- package/dist/lint/rules/design-memory.d.ts +15 -0
- package/dist/lint/rules/design-memory.d.ts.map +1 -0
- package/dist/lint/rules/design-memory.js +90 -0
- package/dist/lint/rules/design-memory.js.map +1 -0
- package/dist/lint/rules/effect-style-required.js +1 -0
- package/dist/lint/rules/effect-style-required.js.map +1 -1
- package/dist/lint/rules/index.d.ts +6 -5
- package/dist/lint/rules/index.d.ts.map +1 -1
- package/dist/lint/rules/index.js +6 -2
- package/dist/lint/rules/index.js.map +1 -1
- package/dist/lint/rules/no-unbound-token-values.d.ts +6 -0
- package/dist/lint/rules/no-unbound-token-values.d.ts.map +1 -0
- package/dist/lint/rules/no-unbound-token-values.js +79 -0
- package/dist/lint/rules/no-unbound-token-values.js.map +1 -0
- package/dist/lint/rules/text-style-required.js +1 -0
- package/dist/lint/rules/text-style-required.js.map +1 -1
- package/dist/lint/types.d.ts +32 -2
- package/dist/lint/types.d.ts.map +1 -1
- package/dist/node/video.d.ts +12 -0
- package/dist/node/video.d.ts.map +1 -0
- package/dist/node/video.js +206 -0
- package/dist/node/video.js.map +1 -0
- package/dist/pairdraw-api/design-memory.d.ts +19 -0
- package/dist/pairdraw-api/design-memory.d.ts.map +1 -0
- package/dist/pairdraw-api/design-memory.js +39 -0
- package/dist/pairdraw-api/design-memory.js.map +1 -0
- package/dist/pairdraw-api/index.d.ts +45 -1
- package/dist/pairdraw-api/index.d.ts.map +1 -1
- package/dist/pairdraw-api/index.js +55 -2
- package/dist/pairdraw-api/index.js.map +1 -1
- package/dist/pairdraw-api/nodes.d.ts +12 -1
- package/dist/pairdraw-api/nodes.d.ts.map +1 -1
- package/dist/pairdraw-api/nodes.js +28 -1
- package/dist/pairdraw-api/nodes.js.map +1 -1
- package/dist/pairdraw-api/variations.d.ts +48 -0
- package/dist/pairdraw-api/variations.d.ts.map +1 -0
- package/dist/pairdraw-api/variations.js +76 -0
- package/dist/pairdraw-api/variations.js.map +1 -0
- package/dist/prototype/easing.d.ts +13 -0
- package/dist/prototype/easing.d.ts.map +1 -0
- package/dist/prototype/easing.js +36 -0
- package/dist/prototype/easing.js.map +1 -0
- package/dist/prototype/frames.d.ts +10 -0
- package/dist/prototype/frames.d.ts.map +1 -0
- package/dist/prototype/frames.js +12 -0
- package/dist/prototype/frames.js.map +1 -0
- package/dist/prototype/hit.d.ts +17 -0
- package/dist/prototype/hit.d.ts.map +1 -0
- package/dist/prototype/hit.js +45 -0
- package/dist/prototype/hit.js.map +1 -0
- package/dist/prototype/index.d.ts +14 -0
- package/dist/prototype/index.js +14 -0
- package/dist/prototype/pointer.d.ts +63 -0
- package/dist/prototype/pointer.d.ts.map +1 -0
- package/dist/prototype/pointer.js +104 -0
- package/dist/prototype/pointer.js.map +1 -0
- package/dist/prototype/reactions.d.ts +45 -0
- package/dist/prototype/reactions.d.ts.map +1 -0
- package/dist/prototype/reactions.js +122 -0
- package/dist/prototype/reactions.js.map +1 -0
- package/dist/prototype/scene.d.ts +35 -0
- package/dist/prototype/scene.d.ts.map +1 -0
- package/dist/prototype/scene.js +86 -0
- package/dist/prototype/scene.js.map +1 -0
- package/dist/prototype/scenes.d.ts +81 -0
- package/dist/prototype/scenes.d.ts.map +1 -0
- package/dist/prototype/scenes.js +175 -0
- package/dist/prototype/scenes.js.map +1 -0
- package/dist/prototype/scroll.d.ts +48 -0
- package/dist/prototype/scroll.d.ts.map +1 -0
- package/dist/prototype/scroll.js +159 -0
- package/dist/prototype/scroll.js.map +1 -0
- package/dist/prototype/session.d.ts +71 -0
- package/dist/prototype/session.d.ts.map +1 -0
- package/dist/prototype/session.js +135 -0
- package/dist/prototype/session.js.map +1 -0
- package/dist/prototype/smart-animate/animation.d.ts +34 -0
- package/dist/prototype/smart-animate/animation.d.ts.map +1 -0
- package/dist/prototype/smart-animate/animation.js +212 -0
- package/dist/prototype/smart-animate/animation.js.map +1 -0
- package/dist/prototype/smart-animate/match.d.ts +24 -0
- package/dist/prototype/smart-animate/match.d.ts.map +1 -0
- package/dist/prototype/smart-animate/match.js +72 -0
- package/dist/prototype/smart-animate/match.js.map +1 -0
- package/dist/prototype/snapshot.d.ts +19 -0
- package/dist/prototype/snapshot.d.ts.map +1 -0
- package/dist/prototype/snapshot.js +56 -0
- package/dist/prototype/snapshot.js.map +1 -0
- package/dist/prototype/timeline.d.ts +132 -0
- package/dist/prototype/timeline.d.ts.map +1 -0
- package/dist/prototype/timeline.js +260 -0
- package/dist/prototype/timeline.js.map +1 -0
- package/dist/rpc/commands.d.ts +2 -2
- package/dist/rpc/index.d.ts +2 -2
- package/dist/rpc/read-commands.d.ts +18 -8
- package/dist/rpc/read-commands.d.ts.map +1 -1
- package/dist/rpc/read-commands.js +18 -9
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/text/font/faces.d.ts +12 -1
- package/dist/text/font/faces.d.ts.map +1 -1
- package/dist/text/font/faces.js +15 -1
- package/dist/text/font/faces.js.map +1 -1
- package/dist/text/font/features.d.ts +9 -0
- package/dist/text/font/features.d.ts.map +1 -0
- package/dist/text/font/features.js +27 -0
- package/dist/text/font/features.js.map +1 -0
- package/dist/text/font/manager.d.ts +12 -0
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +66 -12
- package/dist/text/font/manager.js.map +1 -1
- package/dist/text/index.d.ts +11 -9
- package/dist/text/index.js +4 -2
- package/dist/text/replace-fonts.d.ts +41 -0
- package/dist/text/replace-fonts.d.ts.map +1 -0
- package/dist/text/replace-fonts.js +121 -0
- package/dist/text/replace-fonts.js.map +1 -0
- package/dist/tools/analyze/responsive/index.d.ts +15 -0
- package/dist/tools/analyze/responsive/index.d.ts.map +1 -0
- package/dist/tools/analyze/responsive/index.js +203 -0
- package/dist/tools/analyze/responsive/index.js.map +1 -0
- package/dist/tools/analyze.d.ts +2 -1
- package/dist/tools/analyze.js +2 -1
- package/dist/tools/codegen/token-sync.d.ts +7 -0
- package/dist/tools/codegen/token-sync.d.ts.map +1 -0
- package/dist/tools/codegen/token-sync.js +85 -0
- package/dist/tools/codegen/token-sync.js.map +1 -0
- package/dist/tools/codegen/tokens.d.ts +1 -1
- package/dist/tools/codegen.d.ts +2 -1
- package/dist/tools/codegen.js +2 -1
- package/dist/tools/create/basic.js +1 -1
- package/dist/tools/create/behaviours.js +1 -1
- package/dist/tools/create/components.d.ts.map +1 -1
- package/dist/tools/create/components.js +4 -0
- package/dist/tools/create/components.js.map +1 -1
- package/dist/tools/create/html.js +3 -2
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.d.ts.map +1 -1
- package/dist/tools/create/icons.js +2 -1
- package/dist/tools/create/icons.js.map +1 -1
- package/dist/tools/create/mermaid.js +2 -1
- package/dist/tools/create/mermaid.js.map +1 -1
- package/dist/tools/create/render.js +1 -1
- package/dist/tools/create/svg.js +2 -1
- package/dist/tools/create/svg.js.map +1 -1
- package/dist/tools/create/vector.js +1 -1
- package/dist/tools/design-memory.d.ts +8 -0
- package/dist/tools/design-memory.d.ts.map +1 -0
- package/dist/tools/design-memory.js +68 -0
- package/dist/tools/design-memory.js.map +1 -0
- package/dist/tools/image-ai/generate.d.ts.map +1 -1
- package/dist/tools/image-ai/generate.js +3 -1
- package/dist/tools/image-ai/generate.js.map +1 -1
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.js +2 -1
- package/dist/tools/modify/fonts.d.ts +6 -0
- package/dist/tools/modify/fonts.d.ts.map +1 -0
- package/dist/tools/modify/fonts.js +27 -0
- package/dist/tools/modify/fonts.js.map +1 -0
- package/dist/tools/modify/layout.d.ts.map +1 -1
- package/dist/tools/modify/layout.js +1 -0
- package/dist/tools/modify/layout.js.map +1 -1
- package/dist/tools/modify/paint.js +1 -1
- package/dist/tools/modify/reactions.d.ts.map +1 -1
- package/dist/tools/modify/reactions.js +3 -3
- package/dist/tools/modify/reactions.js.map +1 -1
- package/dist/tools/modify/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +26 -5
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/modify/update.d.ts +10 -1
- package/dist/tools/modify/update.d.ts.map +1 -1
- package/dist/tools/modify/update.js +34 -3
- package/dist/tools/modify/update.js.map +1 -1
- package/dist/tools/modify.d.ts +2 -1
- package/dist/tools/modify.js +2 -1
- package/dist/tools/read/fonts.d.ts.map +1 -1
- package/dist/tools/read/fonts.js +17 -2
- package/dist/tools/read/fonts.js.map +1 -1
- package/dist/tools/read/libraries.js +2 -1
- package/dist/tools/read/libraries.js.map +1 -1
- package/dist/tools/read/nodes.d.ts.map +1 -1
- package/dist/tools/read/nodes.js.map +1 -1
- package/dist/tools/read/space.d.ts +3 -1
- package/dist/tools/read/space.d.ts.map +1 -1
- package/dist/tools/read/space.js +4 -3
- package/dist/tools/read/space.js.map +1 -1
- package/dist/tools/registry/core.d.ts +1 -1
- package/dist/tools/registry/core.d.ts.map +1 -1
- package/dist/tools/registry/core.js +3 -1
- package/dist/tools/registry/core.js.map +1 -1
- package/dist/tools/registry/extended.d.ts.map +1 -1
- package/dist/tools/registry/extended.js +16 -1
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/schema.d.ts +18 -2
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +1 -1
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/stock-photo.js +1 -0
- package/dist/tools/stock-photo.js.map +1 -1
- package/dist/tools/structure/basic.d.ts.map +1 -1
- package/dist/tools/structure/basic.js +1 -0
- package/dist/tools/structure/basic.js.map +1 -1
- package/dist/tools/structure/batch.d.ts.map +1 -1
- package/dist/tools/structure/batch.js +22 -1
- package/dist/tools/structure/batch.js.map +1 -1
- package/dist/tools/structure/hierarchy.d.ts.map +1 -1
- package/dist/tools/structure/hierarchy.js +4 -0
- package/dist/tools/structure/hierarchy.js.map +1 -1
- package/dist/tools/structure/variations.d.ts +8 -0
- package/dist/tools/structure/variations.d.ts.map +1 -0
- package/dist/tools/structure/variations.js +106 -0
- package/dist/tools/structure/variations.js.map +1 -0
- package/dist/tools/structure.d.ts +2 -1
- package/dist/tools/structure.js +2 -1
- package/dist/tools/styles/types.d.ts +2 -4
- package/dist/tools/styles/types.d.ts.map +1 -1
- package/dist/tools/styles/types.js.map +1 -1
- package/dist/tools/vector/boolean.d.ts.map +1 -1
- package/dist/tools/vector/boolean.js +4 -0
- package/dist/tools/vector/boolean.js.map +1 -1
- package/dist/tools/vector/path.d.ts.map +1 -1
- package/dist/tools/vector/path.js +39 -7
- package/dist/tools/vector/path.js.map +1 -1
- package/dist/tools/vector/vectorize.js +1 -0
- package/dist/tools/vector/vectorize.js.map +1 -1
- package/dist/tools/vector/video.d.ts +6 -0
- package/dist/tools/vector/video.d.ts.map +1 -0
- package/dist/tools/vector/video.js +133 -0
- package/dist/tools/vector/video.js.map +1 -0
- package/dist/tools/vector.d.ts +2 -1
- package/dist/tools/vector.js +2 -1
- package/dist/tools/video-host.d.ts +12 -0
- package/dist/tools/video-host.d.ts.map +1 -0
- package/dist/tools/video-host.js +19 -0
- package/dist/tools/video-host.js.map +1 -0
- package/dist/vector/point-transform.d.ts +1 -1
- package/dist/vector/vectorize/svg/to-vectors.d.ts +1 -1
- package/dist/xpath.d.ts +3 -0
- package/dist/xpath.d.ts.map +1 -1
- package/dist/xpath.js +3 -1
- package/dist/xpath.js.map +1 -1
- package/package.json +31 -9
- package/src/ai/providers.ts +2 -0
- package/src/cache/resource.ts +24 -1
- package/src/canvas/effects.ts +47 -50
- package/src/canvas/fills.ts +19 -15
- package/src/canvas/images/adjustments.ts +203 -0
- package/src/canvas/images/sampling.ts +88 -0
- package/src/canvas/index.ts +1 -0
- package/src/canvas/masks.ts +1 -1
- package/src/canvas/noise/render.ts +75 -0
- package/src/canvas/noise/shader.ts +161 -0
- package/src/canvas/noise/table.ts +91 -0
- package/src/canvas/noise/tile.ts +94 -0
- package/src/canvas/overlays/auto-layout-hover.ts +47 -65
- package/src/canvas/overlays/index.ts +0 -1
- package/src/canvas/overlays/selection.ts +1 -12
- package/src/canvas/renderer/fonts.ts +2 -0
- package/src/canvas/renderer/lifecycle.ts +6 -0
- package/src/canvas/renderer/methods.ts +0 -9
- package/src/canvas/renderer/overlay-pass.ts +0 -1
- package/src/canvas/renderer/pipeline.ts +19 -2
- package/src/canvas/renderer/play-scenes.ts +51 -0
- package/src/canvas/renderer/tiles/cache.ts +54 -1
- package/src/canvas/renderer/tiles/controller.ts +30 -1
- package/src/canvas/renderer/types.ts +18 -3
- package/src/canvas/renderer.ts +40 -4
- package/src/canvas/scene.ts +65 -9
- package/src/canvas/texture.ts +136 -0
- package/src/clipboard.ts +23 -10
- package/src/constants.ts +6 -0
- package/src/design-jsx/index.ts +1 -1
- package/src/design-jsx/renderer.ts +1 -1
- package/src/design-memory/check.ts +376 -0
- package/src/design-memory/describe.ts +77 -0
- package/src/design-memory/distil.ts +69 -0
- package/src/design-memory/document.ts +80 -0
- package/src/design-memory/guard.ts +157 -0
- package/src/design-memory/index.ts +8 -0
- package/src/design-memory/refusal.ts +90 -0
- package/src/design-memory/rules.ts +274 -0
- package/src/design-memory/values.ts +179 -0
- package/src/editor/bridges/components.ts +2 -0
- package/src/editor/clipboard/export.ts +24 -7
- package/src/editor/clipboard/snapshot.ts +21 -4
- package/src/editor/clipboard.ts +4 -14
- package/src/editor/color-space.ts +47 -38
- package/src/editor/components/instances.ts +31 -0
- package/src/editor/create.ts +39 -71
- package/src/editor/design-memory.ts +39 -0
- package/src/editor/design-tokens.ts +41 -2
- package/src/editor/document-colors.ts +65 -0
- package/src/editor/eyedropper.ts +198 -0
- package/src/editor/fonts.ts +19 -0
- package/src/editor/history/atomic-tool.ts +29 -1
- package/src/editor/history/capture.ts +19 -0
- package/src/editor/history/document-change.ts +5 -17
- package/src/editor/history/edit.ts +16 -2
- package/src/editor/history/subtree.ts +13 -2
- package/src/editor/index.ts +11 -0
- package/src/editor/nudge.ts +1 -1
- package/src/editor/pages.ts +40 -29
- package/src/editor/play/states.ts +1 -1
- package/src/editor/read-only/actions.ts +6 -0
- package/src/editor/render-requests.ts +83 -0
- package/src/editor/selection/container.ts +24 -1
- package/src/editor/selection/navigation.ts +8 -6
- package/src/editor/selection/overlays.ts +1 -0
- package/src/editor/shapes/with-text.ts +2 -5
- package/src/editor/structure/auto-layout-wrap.ts +1 -1
- package/src/editor/structure/boolean.ts +1 -3
- package/src/editor/structure/group/bounds.ts +1 -5
- package/src/editor/structure/outline-stroke.ts +3 -3
- package/src/editor/structure/reorder.ts +8 -14
- package/src/editor/structure/state.ts +1 -1
- package/src/editor/structure.ts +5 -8
- package/src/editor/tool-registry.ts +2 -1
- package/src/editor/types.ts +8 -1
- package/src/editor/variables.ts +74 -2
- package/src/editor/variations/create.ts +235 -0
- package/src/editor/variations/pick.ts +35 -0
- package/src/editor/variations.ts +110 -0
- package/src/figma-api/accessors/reactions.ts +11 -1
- package/src/figma-api/accessors/text/index.ts +17 -1
- package/src/figma-api/accessors/text/opentype.ts +33 -0
- package/src/figma-api/accessors/visual.ts +55 -2
- package/src/figma-api/compatibility.ts +5 -2
- package/src/figma-api/effects.ts +143 -5
- package/src/figma-api/fonts/loaded.ts +9 -0
- package/src/figma-api/index.ts +35 -0
- package/src/figma-api/overrides.ts +295 -3
- package/src/figma-api/paints.ts +24 -9
- package/src/figma-api/proxy.ts +6 -1
- package/src/figma-api/reactions.ts +130 -32
- package/src/figma-api/serialization.ts +2 -1
- package/src/figma-api/shape-details.ts +50 -0
- package/src/figma-api/shape-with-text.ts +2 -5
- package/src/figma-api/surface.ts +7 -2
- package/src/global.d.ts +31 -0
- package/src/icons/svg.ts +3 -1
- package/src/io/formats/boolean-path.ts +60 -0
- package/src/io/formats/design-tokens/index.ts +21 -0
- package/src/io/formats/design-tokens/plan/changes.ts +4 -1
- package/src/io/formats/design-tokens/project.ts +40 -9
- package/src/io/formats/design-tokens/styles.ts +10 -2
- package/src/io/formats/design-tokens/sync/apply.ts +130 -0
- package/src/io/formats/design-tokens/sync/drift.ts +587 -0
- package/src/io/formats/design-tokens/sync/files.ts +40 -0
- package/src/io/formats/drawio/edges.ts +65 -0
- package/src/io/formats/drawio/export.ts +37 -14
- package/src/io/formats/drawio/index.ts +5 -1
- package/src/io/formats/fig/export/patch/index.ts +8 -0
- package/src/io/formats/fig/thumbnail-page.ts +4 -4
- package/src/io/formats/html/import.ts +9 -1
- package/src/io/formats/html/index.ts +14 -7
- package/src/io/formats/html/layers.ts +11 -2
- package/src/io/formats/html/vectors.ts +8 -2
- package/src/io/formats/pdf/document.ts +14 -4
- package/src/io/formats/pdf/dom.ts +10 -18
- package/src/io/formats/pdf/export.ts +1 -1
- package/src/io/formats/pen/imports.ts +5 -6
- package/src/io/formats/pen/index.ts +36 -5
- package/src/io/formats/raster/adjusted-images.ts +125 -0
- package/src/io/formats/raster/headless.ts +3 -3
- package/src/io/formats/raster/index.ts +6 -1
- package/src/io/formats/raster/pixels.ts +7 -0
- package/src/io/formats/raster/render.ts +12 -1
- package/src/io/formats/svg/defs.ts +14 -73
- package/src/io/formats/svg/effects.ts +131 -0
- package/src/io/formats/svg/export.ts +371 -64
- package/src/io/formats/svg/filter.ts +47 -0
- package/src/io/formats/svg/grain.ts +249 -0
- package/src/io/formats/svg/strokes.ts +2 -2
- package/src/io/formats/svg/text/layout.ts +13 -3
- package/src/io/formats/video/composite.ts +79 -0
- package/src/io/formats/video/formats.ts +77 -0
- package/src/io/formats/video/gif.ts +65 -0
- package/src/io/formats/video/index.ts +30 -0
- package/src/io/formats/video/plan.ts +116 -0
- package/src/io/formats/video/record.ts +227 -0
- package/src/io/formats/video/sink.ts +32 -0
- package/src/io/formats/video/size.ts +25 -0
- package/src/io/formats/video/webcodecs.ts +89 -0
- package/src/io/formats.ts +59 -11
- package/src/io/types.ts +29 -10
- package/src/layout/apply.ts +87 -21
- package/src/layout/auto-layout-handles.ts +396 -0
- package/src/layout/derived.ts +14 -0
- package/src/layout/grid.ts +33 -9
- package/src/layout/mutations.ts +13 -1
- package/src/layout/strokes.ts +12 -0
- package/src/layout/yoga-helpers.ts +18 -1
- package/src/layout.ts +96 -49
- package/src/lint/fixes.ts +12 -3
- package/src/lint/index.ts +3 -1
- package/src/lint/linter.ts +124 -12
- package/src/lint/presets.ts +2 -0
- package/src/lint/rules/design-memory.ts +97 -0
- package/src/lint/rules/effect-style-required.ts +2 -0
- package/src/lint/rules/index.ts +6 -1
- package/src/lint/rules/no-unbound-token-values.ts +73 -0
- package/src/lint/rules/text-style-required.ts +2 -0
- package/src/lint/types.ts +40 -0
- package/src/node/video.ts +196 -0
- package/src/pairdraw-api/design-memory.ts +61 -0
- package/src/pairdraw-api/index.ts +81 -0
- package/src/pairdraw-api/nodes.ts +38 -0
- package/src/pairdraw-api/variations.ts +109 -0
- package/src/prototype/easing.ts +37 -0
- package/src/prototype/frames.ts +9 -0
- package/src/prototype/hit.ts +70 -0
- package/src/prototype/index.ts +69 -0
- package/src/prototype/pointer.ts +146 -0
- package/src/prototype/reactions.ts +178 -0
- package/src/prototype/scene.ts +116 -0
- package/src/prototype/scenes.ts +256 -0
- package/src/prototype/scroll.ts +190 -0
- package/src/prototype/session.ts +188 -0
- package/src/prototype/smart-animate/animation.ts +267 -0
- package/src/prototype/smart-animate/match.ts +85 -0
- package/src/prototype/snapshot.ts +60 -0
- package/src/prototype/timeline.ts +400 -0
- package/src/rpc/index.ts +1 -0
- package/src/rpc/read-commands.ts +40 -23
- package/src/text/font/faces.ts +22 -0
- package/src/text/font/features.ts +27 -0
- package/src/text/font/manager.ts +88 -12
- package/src/text/index.ts +2 -0
- package/src/text/replace-fonts.ts +171 -0
- package/src/tools/analyze/responsive/index.ts +264 -0
- package/src/tools/analyze.ts +2 -0
- package/src/tools/codegen/token-sync.ts +98 -0
- package/src/tools/codegen.ts +1 -0
- package/src/tools/create/components.ts +4 -0
- package/src/tools/create/html.ts +1 -0
- package/src/tools/create/icons.ts +1 -0
- package/src/tools/create/mermaid.ts +1 -0
- package/src/tools/create/svg.ts +1 -0
- package/src/tools/design-memory.ts +72 -0
- package/src/tools/image-ai/generate.ts +2 -0
- package/src/tools/index.ts +1 -0
- package/src/tools/modify/fonts.ts +34 -0
- package/src/tools/modify/layout.ts +5 -0
- package/src/tools/modify/reactions.ts +15 -8
- package/src/tools/modify/text.ts +42 -5
- package/src/tools/modify/update.ts +46 -2
- package/src/tools/modify.ts +1 -0
- package/src/tools/read/fonts.ts +24 -2
- package/src/tools/read/libraries.ts +1 -0
- package/src/tools/read/nodes.ts +0 -1
- package/src/tools/read/space.ts +3 -2
- package/src/tools/registry/core.ts +3 -1
- package/src/tools/registry/extended.ts +28 -1
- package/src/tools/schema.ts +28 -4
- package/src/tools/stock-photo.ts +1 -0
- package/src/tools/structure/basic.ts +1 -0
- package/src/tools/structure/batch.ts +34 -1
- package/src/tools/structure/hierarchy.ts +4 -0
- package/src/tools/structure/variations.ts +118 -0
- package/src/tools/structure.ts +2 -0
- package/src/tools/styles/types.ts +3 -4
- package/src/tools/vector/boolean.ts +4 -0
- package/src/tools/vector/path.ts +30 -6
- package/src/tools/vector/vectorize.ts +1 -0
- package/src/tools/vector/video.ts +228 -0
- package/src/tools/vector.ts +1 -0
- package/src/tools/video-host.ts +18 -0
- package/src/xpath.ts +6 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { computeAllLayouts } from "../../layout.js";
|
|
2
|
+
import { captureNode } from "./capture.js";
|
|
2
3
|
import { diffFields } from "./diff.js";
|
|
3
4
|
import { compact, isEqual, isPlainObject, uniq, xor } from "es-toolkit";
|
|
4
|
-
import { cloneInstanceOverrideState } from "@pairdraw/scene-graph/instances/overrides";
|
|
5
5
|
import { createSceneMutationImpact, recordSceneMutations } from "@pairdraw/scene-graph/mutation-impact";
|
|
6
6
|
import { withLiveComments } from "@pairdraw/scene-graph/comments";
|
|
7
7
|
//#region src/editor/history/document-change.ts
|
|
@@ -63,26 +63,6 @@ function restoreLayer(graph, update, side) {
|
|
|
63
63
|
}
|
|
64
64
|
graph.restoreNodeProperties(update.id, changes, update.fields?.absent[side] ?? []);
|
|
65
65
|
}
|
|
66
|
-
/**
|
|
67
|
-
* A copy that keeps the layer's values as they are now. Values are replaced, never written into
|
|
68
|
-
* (`materialize-instance.ts` in `@pairdraw/fig`), so sharing them is safe; the graph edits
|
|
69
|
-
* child lists, source metadata, and override maps in place, so those are copied.
|
|
70
|
-
*/
|
|
71
|
-
function captureNode(node) {
|
|
72
|
-
const { source, instanceOverrides } = node;
|
|
73
|
-
return {
|
|
74
|
-
...node,
|
|
75
|
-
childIds: [...node.childIds],
|
|
76
|
-
source: {
|
|
77
|
-
...source,
|
|
78
|
-
fig: {
|
|
79
|
-
...source.fig,
|
|
80
|
-
rawNodeFields: { ...source.fig.rawNodeFields }
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
instanceOverrides: cloneInstanceOverrideState(instanceOverrides)
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
66
|
/** Copies a page's layers not copied yet; a layer moved in from another page keeps its copy. */
|
|
87
67
|
function capturePage(graph, pageId, captured) {
|
|
88
68
|
const stack = [pageId];
|
|
@@ -125,7 +105,7 @@ function recordLayer(change, id, previous, current) {
|
|
|
125
105
|
});
|
|
126
106
|
if (!previous) {
|
|
127
107
|
if (current) change.created.push(structuredClone(current));
|
|
128
|
-
} else if (!current) change.deleted.push(
|
|
108
|
+
} else if (!current) change.deleted.push(previous);
|
|
129
109
|
else {
|
|
130
110
|
const update = diffLayer(id, previous, current);
|
|
131
111
|
if (update) change.updated.push(update);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-change.js","names":[],"sources":["../../../src/editor/history/document-change.ts"],"sourcesContent":["import { compact, isEqual, isPlainObject, uniq, xor } from 'es-toolkit'\n\nimport type {\n FigmaSourcePayload,\n SceneGraph,\n SceneNode,\n SourceMetadata,\n Variable,\n VariableCollection\n} from '@pairdraw/scene-graph'\nimport { withLiveComments } from '@pairdraw/scene-graph/comments'\nimport { cloneInstanceOverrideState } from '@pairdraw/scene-graph/instances/overrides'\nimport {\n createSceneMutationImpact,\n recordSceneMutations\n} from '@pairdraw/scene-graph/mutation-impact'\n\nimport type { EditorContext } from '#core/editor/types'\nimport { computeAllLayouts } from '#core/layout'\n\nimport { diffFields, type FieldChanges } from './diff'\n\ntype Side = 'before' | 'after'\n\n/**\n * The fields an edit changed on a layer that exists on both sides. Source metadata is compared\n * a level down and its `.fig` payload a level below that, so marking a field edited keeps that\n * change rather than the layer's whole `.fig` record.\n */\ninterface LayerUpdate {\n id: string\n fields: FieldChanges<SceneNode> | null\n source: FieldChanges<SourceMetadata> | null\n fig: FieldChanges<FigmaSourcePayload> | null\n}\n\n/** A parent's children in one state, listed parents first. */\ninterface ChildList {\n id: string\n childIds: string[]\n}\n\n/** A variable or collection on each side of an edit; `null` on the side it does not exist. */\ninterface RecordChange<T> {\n id: string\n before: T | null\n after: T | null\n}\n\n/**\n * What one edit did to the document: copies of only the layers, variables, and collections it\n * created, deleted, or changed, on any page, so an undo step costs what the edit touched rather\n * than a copy of the document. Comments on the document node are left out, as undo never takes\n * them back.\n */\nexport interface DocumentChange {\n /** The page the edit ran on, which a review of it shows. */\n pageId: string\n /** Pages whose layers the edit changed, laid out again when it is undone or redone. */\n pageIds: string[]\n /** Layers as the edit left them, parents first. */\n created: SceneNode[]\n /** Layers as they were before the edit removed them, parents first. */\n deleted: SceneNode[]\n /** Fields the edit changed on layers that exist in both states, children aside. */\n updated: LayerUpdate[]\n /** Child lists that differ between the states, each side's parents first. */\n children: Record<Side, ChildList[]>\n variables: RecordChange<Variable>[]\n collections: RecordChange<VariableCollection>[]\n}\n\n/** Layers by id: the live graph's, or those captured before the edit. */\ntype Lookup = Pick<ReadonlyMap<string, SceneNode>, 'get' | 'size'>\n\nconst NESTED_FIELDS: ReadonlySet<keyof SceneNode> = new Set(['childIds', 'parentId', 'source'])\nconst SOURCE_PAYLOAD: ReadonlySet<keyof SourceMetadata> = new Set(['fig'])\n\nfunction diffLayer(id: string, previous: SceneNode, current: SceneNode): LayerUpdate | null {\n const update: LayerUpdate = {\n id,\n fields: diffFields(id, previous, current, NESTED_FIELDS),\n source: diffFields(id, previous.source, current.source, SOURCE_PAYLOAD),\n fig: diffFields(id, previous.source.fig, current.source.fig)\n }\n return update.fields || update.source || update.fig ? update : null\n}\n\nfunction withChanges<T extends object>(value: T, changes: FieldChanges<T> | null, side: Side): T {\n if (!changes) return value\n const result = { ...value, ...structuredClone(changes[side]) }\n for (const key of changes.absent[side]) Reflect.deleteProperty(result, key)\n return result\n}\n\n/**\n * `editedFields` marking plugin data edited as `live` does. The mark makes `.fig` export write\n * the document node's comments, so it follows them rather than undo.\n */\nfunction markedLike(editedFields: string[], live: SceneNode): string[] {\n const marked = live.source.editedFields.includes('pluginData')\n if (editedFields.includes('pluginData') === marked) return editedFields\n return marked\n ? [...editedFields, 'pluginData']\n : editedFields.filter((field) => field !== 'pluginData')\n}\n\n/** The document node holding the comments of `live`, as undo never takes them back. */\nfunction withCommentsOf(root: SceneNode, live: SceneNode): SceneNode {\n return {\n ...root,\n pluginData: withLiveComments(root.pluginData, live.pluginData),\n source: { ...root.source, editedFields: markedLike(root.source.editedFields, live) }\n }\n}\n\nfunction restoreLayer(graph: SceneGraph, update: LayerUpdate, side: Side): void {\n const node = graph.getNode(update.id)\n if (!node) return\n const changes: Partial<SceneNode> = update.fields ? structuredClone(update.fields[side]) : {}\n if (update.source || update.fig) {\n changes.source = {\n ...withChanges(node.source, update.source, side),\n fig: withChanges(node.source.fig, update.fig, side)\n }\n }\n if (node.id === graph.rootId) {\n if (changes.pluginData)\n changes.pluginData = withLiveComments(changes.pluginData, node.pluginData)\n if (changes.source) {\n changes.source.editedFields = markedLike(changes.source.editedFields, node)\n }\n }\n graph.restoreNodeProperties(update.id, changes, update.fields?.absent[side] ?? [])\n}\n\n/**\n * A copy that keeps the layer's values as they are now. Values are replaced, never written into\n * (`materialize-instance.ts` in `@pairdraw/fig`), so sharing them is safe; the graph edits\n * child lists, source metadata, and override maps in place, so those are copied.\n */\nfunction captureNode(node: SceneNode): SceneNode {\n const { source, instanceOverrides } = node\n return {\n ...node,\n childIds: [...node.childIds],\n source: { ...source, fig: { ...source.fig, rawNodeFields: { ...source.fig.rawNodeFields } } },\n instanceOverrides: cloneInstanceOverrideState(instanceOverrides)\n }\n}\n\n/** Copies a page's layers not copied yet; a layer moved in from another page keeps its copy. */\nfunction capturePage(graph: SceneGraph, pageId: string, captured: Map<string, SceneNode>): void {\n const stack = [pageId]\n for (let id = stack.pop(); id !== undefined; id = stack.pop()) {\n const node = graph.getNode(id)\n if (!node) continue\n if (!captured.has(id)) captured.set(id, captureNode(node))\n stack.push(...node.childIds)\n }\n}\n\n/**\n * A layer and its ancestors, nearest first. Like `SceneGraph.closest`, the walk visits at most as\n * many layers as there are, so a parent cycle in bad data cannot hang it.\n */\nfunction* lineage(nodes: Lookup, id: string): Generator<SceneNode> {\n let node = nodes.get(id)\n for (let steps = 0; node && steps < nodes.size; steps++) {\n yield node\n node = node.parentId ? nodes.get(node.parentId) : undefined\n }\n}\n\nfunction pageOf(nodes: Lookup, id: string): string | null {\n for (const node of lineage(nodes, id)) if (node.type === 'CANVAS') return node.id\n return null\n}\n\nfunction depthIn(nodes: Lookup, id: string): number {\n let depth = 0\n for (const node of lineage(nodes, id)) if (node.parentId) depth++\n return depth\n}\n\n/** Adds one touched layer to the change, given its state on each side, if it has one. */\nfunction recordLayer(\n change: DocumentChange,\n id: string,\n previous: SceneNode | undefined,\n current: SceneNode | undefined\n): void {\n if (previous && !isEqual(previous.childIds, current?.childIds ?? [])) {\n change.children.before.push({ id, childIds: previous.childIds })\n }\n if (current && !isEqual(current.childIds, previous?.childIds ?? [])) {\n change.children.after.push({ id, childIds: [...current.childIds] })\n }\n if (!previous) {\n if (current) change.created.push(structuredClone(current))\n } else if (!current) {\n change.deleted.push(structuredClone(previous))\n } else {\n const update = diffLayer(id, previous, current)\n if (update) change.updated.push(update)\n }\n}\n\nfunction diffRecords<T>(previous: Map<string, T>, current: Map<string, T>): RecordChange<T>[] {\n const ids = new Set([...previous.keys(), ...current.keys()])\n return [...ids].flatMap((id) => {\n const before = previous.get(id) ?? null\n const after = current.get(id) ?? null\n return isEqual(before, after) ? [] : [{ id, before, after: structuredClone(after) }]\n })\n}\n\n/** Restores records in place where they exist, as views may hold them, as atomic tools do. */\n/** Make `target` hold `value` under `id`, or nothing; an existing record is kept and rewritten. */\nexport function writeRecord<T extends object>(\n target: Map<string, T>,\n id: string,\n value: T | null\n): void {\n const existing = target.get(id)\n if (!value) {\n target.delete(id)\n } else if (existing) {\n for (const key of Object.keys(existing)) {\n if (!Object.hasOwn(value, key)) Reflect.deleteProperty(existing, key)\n }\n Object.assign(existing, structuredClone(value))\n } else {\n target.set(id, structuredClone(value))\n }\n}\n\nfunction restoreRecords<T extends object>(\n target: Map<string, T>,\n changes: RecordChange<T>[],\n side: Side\n): void {\n for (const change of changes) writeRecord(target, change.id, change[side])\n}\n\n/**\n * A layer or record as it was before an edit, with what someone else changed on it while the edit\n * waited, field by field: a field the edit had left alone takes the other writer's value, and one\n * the edit had changed keeps the edit's, so its undo restores what it changed. Fields that map\n * keys to values, such as variable bindings or a variable's values by mode, are adopted one level\n * in, so independent entries of one field both survive.\n */\nfunction adoptChanges<T extends object>(baseline: T, atPause: T, live: T, depth = 1): T {\n const adopted = { ...baseline }\n for (const key of new Set([...Object.keys(atPause), ...Object.keys(live)])) {\n const paused: unknown = Reflect.get(atPause, key)\n const now: unknown = Reflect.get(live, key)\n const base: unknown = Reflect.get(baseline, key)\n const pausedHas = Object.hasOwn(atPause, key)\n const liveHas = Object.hasOwn(live, key)\n if (pausedHas === liveHas && isEqual(paused, now)) continue\n if (Object.hasOwn(baseline, key) === pausedHas && isEqual(base, paused)) {\n if (liveHas) Reflect.set(adopted, key, structuredClone(now))\n else Reflect.deleteProperty(adopted, key)\n } else if (depth > 0 && isPlainObject(base) && isPlainObject(paused) && isPlainObject(now)) {\n Reflect.set(adopted, key, adoptChanges(base, paused, now, depth - 1))\n }\n }\n return adopted\n}\n\n/** As `adoptChanges` for a map of records, dropping a record someone else removed meanwhile. */\nfunction adoptRecords<T extends object>(\n baseline: Map<string, T>,\n atPause: Map<string, T>,\n live: ReadonlyMap<string, T>\n): void {\n for (const [id, paused] of atPause) {\n const before = baseline.get(id)\n if (!before) continue\n const now = live.get(id)\n if (!now) baseline.delete(id)\n else if (isEqual(before, paused)) baseline.set(id, structuredClone(now))\n else baseline.set(id, adoptChanges(before, paused, now))\n }\n}\n\n/** What an edit changed in the document, once it is done; see `recordDocumentChange`. */\nexport interface DocumentChangeRecorder {\n /** Stops recording and returns what the edit changed. */\n finish: () => DocumentChange\n /** Treats what changes until `resume` as someone else's, as when the edit waits. */\n pause: () => void\n /** The wait ended: what changed meanwhile stays out of the edit's step. */\n resume: () => void\n}\n\n/**\n * Starts recording an edit made from `pageId`. Call `finish` once the edit is done, also when it\n * failed, to stop recording and get what the edit changed.\n *\n * The page is copied up front, so values written into its layers in place are kept too. Another\n * page, or the document node, is copied the first time the edit is about to change it.\n *\n * While the edit waits (`pause`/`resume`, or `SceneGraph.waitOutsideEdit`), what changes is\n * someone else's: a layer first touched meanwhile is not recorded, and one the edit had already\n * copied is taken in from its new state field by field on resume, so an undo of the edit leaves\n * the other writer's change alone.\n */\nexport function recordDocumentChange(graph: SceneGraph, pageId: string): DocumentChangeRecorder {\n const captured = new Map<string, SceneNode>()\n const capturedPages = new Set([pageId])\n const created = new Set<string>()\n capturePage(graph, pageId, captured)\n const variables = structuredClone(graph.variables)\n const collections = structuredClone(graph.variableCollections)\n const impact = createSceneMutationImpact()\n const unbindEvents = recordSceneMutations(graph, impact)\n let pausedDepth = 0\n let layersAtPause = new Map<string, SceneNode>()\n let variablesAtPause: Map<string, Variable> | null = null\n let collectionsAtPause: Map<string, VariableCollection> | null = null\n\n function pause(): void {\n pausedDepth += 1\n if (pausedDepth > 1) return\n layersAtPause = new Map()\n variablesAtPause = structuredClone(graph.variables)\n collectionsAtPause = structuredClone(graph.variableCollections)\n }\n\n function resume(): void {\n if (pausedDepth === 0) return\n pausedDepth -= 1\n if (pausedDepth > 0) return\n for (const [id, atPause] of layersAtPause) {\n const before = captured.get(id)\n if (!before) continue\n const live = graph.getNode(id)\n // A layer someone else removed meanwhile is not the edit's to put back.\n if (!live) captured.delete(id)\n else captured.set(id, adoptChanges(before, atPause, live))\n }\n if (variablesAtPause) adoptRecords(variables, variablesAtPause, graph.variables)\n if (collectionsAtPause) adoptRecords(collections, collectionsAtPause, graph.variableCollections)\n layersAtPause = new Map()\n variablesAtPause = null\n collectionsAtPause = null\n }\n\n const unobserve = graph.observeNodeChanges({\n created: (node) => {\n if (pausedDepth === 0) created.add(node.id)\n },\n before: (node) => {\n // While the edit waits, layers belong to whoever else changes them.\n if (pausedDepth > 0) {\n const before = captured.get(node.id)\n if (before && !layersAtPause.has(node.id)) layersAtPause.set(node.id, captureNode(node))\n return\n }\n if (captured.has(node.id) || created.has(node.id)) return\n const page = pageOf(graph.nodes, node.id)\n if (page && !capturedPages.has(page)) {\n capturedPages.add(page)\n capturePage(graph, page, captured)\n }\n if (!captured.has(node.id)) captured.set(node.id, captureNode(node))\n },\n pause,\n resume\n })\n\n const finish = (): DocumentChange => {\n resume()\n pausedDepth = 0\n unobserve()\n unbindEvents()\n const change: DocumentChange = {\n pageId,\n pageIds: [],\n created: [],\n deleted: [],\n updated: [],\n children: { before: [], after: [] },\n variables: diffRecords(variables, graph.variables),\n collections: diffRecords(collections, graph.variableCollections)\n }\n const pageIds = new Set<string>()\n const touched = new Set([\n ...impact.changedNodeIds,\n ...impact.previousParentIds,\n ...impact.currentParentIds\n ])\n for (const id of touched) {\n const previous = captured.get(id)\n // A layer changed without telling observers has no state to go back to.\n if (!previous && !created.has(id)) continue\n const current = graph.getNode(id)\n // Comments are never part of an undo step.\n const kept =\n previous && current && id === graph.rootId ? withCommentsOf(previous, current) : previous\n recordLayer(change, id, kept, current)\n for (const page of [pageOf(captured, id), pageOf(graph.nodes, id)])\n if (page) pageIds.add(page)\n }\n change.pageIds = [...pageIds]\n const byDepth = (nodes: Lookup) => (a: { id: string }, b: { id: string }) =>\n depthIn(nodes, a.id) - depthIn(nodes, b.id)\n change.created.sort(byDepth(graph.nodes))\n change.children.after.sort(byDepth(graph.nodes))\n change.deleted.sort(byDepth(captured))\n change.children.before.sort(byDepth(captured))\n return change\n }\n\n return { finish, pause, resume }\n}\n\n/** The change of one edit; `recordDocumentChange` when the edit can also wait. */\nexport function captureDocumentChange(graph: SceneGraph, pageId: string): () => DocumentChange {\n return recordDocumentChange(graph, pageId).finish\n}\n\n/** Where a layer sits: its page and the page's child holding it, null for a page or the root. */\ninterface Placement {\n pageId: string | null\n layerId: string | null\n}\n\n/** `undefined` when the layer's parents cannot be followed to a page or the root. */\nfunction placement(nodes: Lookup, id: string): Placement | undefined {\n let child: SceneNode | null = null\n for (const node of lineage(nodes, id)) {\n if (node.type === 'CANVAS') return { pageId: node.id, layerId: child?.id ?? null }\n if (!node.parentId) return { pageId: null, layerId: null }\n child = node\n }\n return undefined\n}\n\n/**\n * Layers as they were before the edit, read from the live graph: removed ones from their copies,\n * and moved ones under the parent whose old child list held them.\n */\nfunction layersBefore(graph: SceneGraph, change: DocumentChange): Lookup {\n const created = new Set(change.created.map((node) => node.id))\n const deleted = new Map(change.deleted.map((node) => [node.id, node]))\n const parents = new Map<string, string>()\n for (const { id, childIds } of change.children.before) {\n for (const childId of childIds) parents.set(childId, id)\n }\n return {\n size: graph.nodes.size + deleted.size,\n get(id) {\n if (created.has(id)) return undefined\n const node = deleted.get(id) ?? graph.getNode(id)\n const parentId = parents.get(id)\n return node && parentId !== undefined && parentId !== node.parentId\n ? { ...node, parentId }\n : node\n }\n }\n}\n\n/** Layers the edit created, removed, changed, or moved, and the parents whose children changed. */\nfunction touchedLayerIds(change: DocumentChange): string[] {\n const lists = (side: Side) =>\n new Map(change.children[side].map(({ id, childIds }) => [id, childIds]))\n const before = lists('before')\n const after = lists('after')\n // A reorder changes only its parent; a move also touches the layers that came or went.\n const moved = uniq([...before.keys(), ...after.keys()]).flatMap((id) => [\n id,\n ...xor(before.get(id) ?? [], after.get(id) ?? [])\n ])\n return uniq([\n ...change.created.map((node) => node.id),\n ...change.deleted.map((node) => node.id),\n ...change.updated.map((update) => update.id),\n ...moved\n ])\n}\n\n/** The ends of the connectors in the graph or removed by the edit, on either side of it. */\nfunction connectorEnds(graph: SceneGraph, change: DocumentChange): Map<string, string[]> {\n const ends = new Map<string, string[]>()\n const add = (id: string, nodes: Partial<SceneNode>[]) => {\n const nodeIds = nodes.flatMap((node) => [\n node.connectorStart?.nodeId,\n node.connectorEnd?.nodeId\n ])\n ends.set(id, uniq([...(ends.get(id) ?? []), ...compact(nodeIds)]))\n }\n for (const id of graph.connectorIds) add(id, compact([graph.getNode(id)]))\n for (const node of change.deleted) if (node.type === 'CONNECTOR') add(node.id, [node])\n for (const update of change.updated) {\n if (update.fields && ends.has(update.id)) add(update.id, [update.fields.before])\n }\n return ends\n}\n\n/**\n * The page children holding what an edit touched, on either side of it, for diffing and drawing\n * just those instead of whole pages (`graphsFromDocumentChange`). A layer whose connector draws\n * to a layer elsewhere brings that layer too, as JSX writes the end by it. `null` when part of\n * the page cannot be told apart this way: the edit changed variables, which any layer may show,\n * moved a layer to another page, or left a layer whose parents cannot be followed.\n */\nexport function touchedTopLevelIds(graph: SceneGraph, change: DocumentChange): string[] | null {\n if (change.variables.length > 0 || change.collections.length > 0) return null\n const before = layersBefore(graph, change)\n const sides = [before, graph.nodes]\n const holders = (id: string): (string | null)[] | null => {\n const placements = sides.map((nodes) => (nodes.get(id) ? placement(nodes, id) : null))\n if (placements.includes(undefined)) return null\n const [was, is] = placements\n if (was?.pageId && is?.pageId && was.pageId !== is.pageId) return null\n return placements.map((place) => place?.layerId ?? null)\n }\n const layers = new Set<string>()\n for (const id of touchedLayerIds(change)) {\n const held = holders(id)\n if (!held) return null\n for (const layerId of compact(held)) layers.add(layerId)\n }\n const ends = connectorEnds(graph, change)\n for (let grew = true; grew;) {\n grew = false\n for (const [connectorId, endIds] of ends) {\n if (!holders(connectorId)?.some((layerId) => layerId && layers.has(layerId))) continue\n for (const layerId of compact(endIds.flatMap((id) => holders(id) ?? []))) {\n grew ||= !layers.has(layerId)\n layers.add(layerId)\n }\n }\n }\n return [...layers]\n}\n\nexport function isEmptyDocumentChange(change: DocumentChange): boolean {\n return (\n change.created.length === 0 &&\n change.deleted.length === 0 &&\n change.updated.length === 0 &&\n change.children.before.length === 0 &&\n change.children.after.length === 0 &&\n change.variables.length === 0 &&\n change.collections.length === 0\n )\n}\n\n/**\n * Puts what an edit touched back as it was on one side of it. The graph must be as the other\n * side left it; what the edit did not touch is left alone, and so are comments. A graph that\n * holds only part of the document, such as one page, gets the part of the change it has room\n * for.\n */\nexport function applyDocumentChange(graph: SceneGraph, change: DocumentChange, side: Side): void {\n const restored = side === 'before' ? change.deleted : change.created\n const removed = side === 'before' ? change.created : change.deleted\n restoreRecords(graph.variableCollections, change.collections, side)\n restoreRecords(graph.variables, change.variables, side)\n graph.preserveSourceMetadataDuring(() => {\n for (const node of restored) {\n const { parentId, childIds: _childIds, ...fields } = structuredClone(node)\n if (!parentId || !graph.getNode(parentId)) continue\n graph.createNode(node.type, parentId, { ...fields, childIds: [] })\n }\n // Parents come first, so a layer never moves under one of its own descendants.\n for (const { id, childIds } of change.children[side]) {\n for (const [index, childId] of childIds.entries()) {\n if (graph.getNode(id)?.childIds[index] !== childId) graph.insertChildAt(childId, id, index)\n }\n }\n // Layers that survive have moved out of the removed ones by now.\n for (const node of removed) graph.deleteNode(node.id)\n for (const update of change.updated) restoreLayer(graph, update, side)\n })\n graph.clearAbsPosCache()\n}\n\n/** Drops the selected and hovered layers that no longer exist, and keeps the rest. */\nfunction keepLiveSelection(ctx: EditorContext): void {\n const live = [...ctx.state.selectedIds].filter((id) => ctx.graph.getNode(id))\n if (live.length !== ctx.state.selectedIds.size) ctx.setSelectedIds(new Set(live))\n const hovered = ctx.state.hoveredNodeId\n if (hovered !== null && !ctx.graph.getNode(hovered)) ctx.state.hoveredNodeId = null\n}\n\n/**\n * Undoes or redoes an edit in the editor, whichever page is on screen. Undo and redo clear the\n * selection on that page; `keepSelection`, for an edit put back that the person did not ask to\n * undo, keeps the selected layers that still exist.\n */\nexport function restoreDocumentChange(\n ctx: EditorContext,\n change: DocumentChange,\n side: Side,\n options: { keepSelection?: boolean } = {}\n): void {\n applyDocumentChange(ctx.graph, change, side)\n const pageIds = new Set(change.pageIds)\n // Bound values follow their variables, so the page on screen is laid out again.\n if (change.variables.length > 0) pageIds.add(ctx.state.currentPageId)\n for (const pageId of pageIds) {\n if (ctx.graph.getNode(pageId)) computeAllLayouts(ctx.graph, pageId)\n }\n if (options.keepSelection) {\n keepLiveSelection(ctx)\n } else if (pageIds.has(ctx.state.currentPageId)) {\n ctx.setSelectedIds(new Set())\n ctx.state.hoveredNodeId = null\n }\n ctx.requestRender()\n}\n"],"mappings":";;;;;;;AA2EA,MAAM,gCAA8C,IAAI,IAAI;CAAC;CAAY;CAAY;AAAQ,CAAC;AAC9F,MAAM,iCAAoD,IAAI,IAAI,CAAC,KAAK,CAAC;AAEzE,SAAS,UAAU,IAAY,UAAqB,SAAwC;CAC1F,MAAM,SAAsB;EAC1B;EACA,QAAQ,WAAW,IAAI,UAAU,SAAS,aAAa;EACvD,QAAQ,WAAW,IAAI,SAAS,QAAQ,QAAQ,QAAQ,cAAc;EACtE,KAAK,WAAW,IAAI,SAAS,OAAO,KAAK,QAAQ,OAAO,GAAG;CAC7D;CACA,OAAO,OAAO,UAAU,OAAO,UAAU,OAAO,MAAM,SAAS;AACjE;AAEA,SAAS,YAA8B,OAAU,SAAiC,MAAe;CAC/F,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,SAAS;EAAE,GAAG;EAAO,GAAG,gBAAgB,QAAQ,KAAK;CAAE;CAC7D,KAAK,MAAM,OAAO,QAAQ,OAAO,OAAO,QAAQ,eAAe,QAAQ,GAAG;CAC1E,OAAO;AACT;;;;;AAMA,SAAS,WAAW,cAAwB,MAA2B;CACrE,MAAM,SAAS,KAAK,OAAO,aAAa,SAAS,YAAY;CAC7D,IAAI,aAAa,SAAS,YAAY,MAAM,QAAQ,OAAO;CAC3D,OAAO,SACH,CAAC,GAAG,cAAc,YAAY,IAC9B,aAAa,QAAQ,UAAU,UAAU,Y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,GAClC;CACN,oBAAoB,IAAI,OAAO,QAAQ,IAAI;CAC3C,MAAM,UAAU,IAAI,IAAI,OAAO,OAAO;CAEtC,IAAI,OAAO,UAAU,SAAS,GAAG,QAAQ,IAAI,IAAI,MAAM,aAAa;CACpE,KAAK,MAAM,UAAU,SACnB,IAAI,IAAI,MAAM,QAAQ,MAAM,GAAG,kBAAkB,IAAI,OAAO,MAAM;CAEpE,IAAI,QAAQ,eACV,kBAAkB,GAAG;MAChB,IAAI,QAAQ,IAAI,IAAI,MAAM,aAAa,GAAG;EAC/C,IAAI,+BAAe,IAAI,IAAI,CAAC;EAC5B,IAAI,MAAM,gBAAgB;CAC5B;CACA,IAAI,cAAc;AACpB"}
|
|
1
|
+
{"version":3,"file":"document-change.js","names":[],"sources":["../../../src/editor/history/document-change.ts"],"sourcesContent":["import { compact, isEqual, isPlainObject, uniq, xor } from 'es-toolkit'\n\nimport type {\n FigmaSourcePayload,\n SceneGraph,\n SceneNode,\n SourceMetadata,\n Variable,\n VariableCollection\n} from '@pairdraw/scene-graph'\nimport { withLiveComments } from '@pairdraw/scene-graph/comments'\nimport {\n createSceneMutationImpact,\n recordSceneMutations\n} from '@pairdraw/scene-graph/mutation-impact'\n\nimport type { EditorContext } from '#core/editor/types'\nimport { computeAllLayouts } from '#core/layout'\n\nimport { captureNode } from './capture'\nimport { diffFields, type FieldChanges } from './diff'\n\ntype Side = 'before' | 'after'\n\n/**\n * The fields an edit changed on a layer that exists on both sides. Source metadata is compared\n * a level down and its `.fig` payload a level below that, so marking a field edited keeps that\n * change rather than the layer's whole `.fig` record.\n */\ninterface LayerUpdate {\n id: string\n fields: FieldChanges<SceneNode> | null\n source: FieldChanges<SourceMetadata> | null\n fig: FieldChanges<FigmaSourcePayload> | null\n}\n\n/** A parent's children in one state, listed parents first. */\ninterface ChildList {\n id: string\n childIds: string[]\n}\n\n/** A variable or collection on each side of an edit; `null` on the side it does not exist. */\ninterface RecordChange<T> {\n id: string\n before: T | null\n after: T | null\n}\n\n/**\n * What one edit did to the document: copies of only the layers, variables, and collections it\n * created, deleted, or changed, on any page, so an undo step costs what the edit touched rather\n * than a copy of the document. Comments on the document node are left out, as undo never takes\n * them back.\n */\nexport interface DocumentChange {\n /** The page the edit ran on, which a review of it shows. */\n pageId: string\n /** Pages whose layers the edit changed, laid out again when it is undone or redone. */\n pageIds: string[]\n /** Layers as the edit left them, parents first. */\n created: SceneNode[]\n /** Layers as they were before the edit removed them, parents first. */\n deleted: SceneNode[]\n /** Fields the edit changed on layers that exist in both states, children aside. */\n updated: LayerUpdate[]\n /** Child lists that differ between the states, each side's parents first. */\n children: Record<Side, ChildList[]>\n variables: RecordChange<Variable>[]\n collections: RecordChange<VariableCollection>[]\n}\n\n/** Layers by id: the live graph's, or those captured before the edit. */\ntype Lookup = Pick<ReadonlyMap<string, SceneNode>, 'get' | 'size'>\n\nconst NESTED_FIELDS: ReadonlySet<keyof SceneNode> = new Set(['childIds', 'parentId', 'source'])\nconst SOURCE_PAYLOAD: ReadonlySet<keyof SourceMetadata> = new Set(['fig'])\n\nfunction diffLayer(id: string, previous: SceneNode, current: SceneNode): LayerUpdate | null {\n const update: LayerUpdate = {\n id,\n fields: diffFields(id, previous, current, NESTED_FIELDS),\n source: diffFields(id, previous.source, current.source, SOURCE_PAYLOAD),\n fig: diffFields(id, previous.source.fig, current.source.fig)\n }\n return update.fields || update.source || update.fig ? update : null\n}\n\nfunction withChanges<T extends object>(value: T, changes: FieldChanges<T> | null, side: Side): T {\n if (!changes) return value\n const result = { ...value, ...structuredClone(changes[side]) }\n for (const key of changes.absent[side]) Reflect.deleteProperty(result, key)\n return result\n}\n\n/**\n * `editedFields` marking plugin data edited as `live` does. The mark makes `.fig` export write\n * the document node's comments, so it follows them rather than undo.\n */\nfunction markedLike(editedFields: string[], live: SceneNode): string[] {\n const marked = live.source.editedFields.includes('pluginData')\n if (editedFields.includes('pluginData') === marked) return editedFields\n return marked\n ? [...editedFields, 'pluginData']\n : editedFields.filter((field) => field !== 'pluginData')\n}\n\n/** The document node holding the comments of `live`, as undo never takes them back. */\nfunction withCommentsOf(root: SceneNode, live: SceneNode): SceneNode {\n return {\n ...root,\n pluginData: withLiveComments(root.pluginData, live.pluginData),\n source: { ...root.source, editedFields: markedLike(root.source.editedFields, live) }\n }\n}\n\nfunction restoreLayer(graph: SceneGraph, update: LayerUpdate, side: Side): void {\n const node = graph.getNode(update.id)\n if (!node) return\n const changes: Partial<SceneNode> = update.fields ? structuredClone(update.fields[side]) : {}\n if (update.source || update.fig) {\n changes.source = {\n ...withChanges(node.source, update.source, side),\n fig: withChanges(node.source.fig, update.fig, side)\n }\n }\n if (node.id === graph.rootId) {\n if (changes.pluginData)\n changes.pluginData = withLiveComments(changes.pluginData, node.pluginData)\n if (changes.source) {\n changes.source.editedFields = markedLike(changes.source.editedFields, node)\n }\n }\n graph.restoreNodeProperties(update.id, changes, update.fields?.absent[side] ?? [])\n}\n\n/** Copies a page's layers not copied yet; a layer moved in from another page keeps its copy. */\nfunction capturePage(graph: SceneGraph, pageId: string, captured: Map<string, SceneNode>): void {\n const stack = [pageId]\n for (let id = stack.pop(); id !== undefined; id = stack.pop()) {\n const node = graph.getNode(id)\n if (!node) continue\n if (!captured.has(id)) captured.set(id, captureNode(node))\n stack.push(...node.childIds)\n }\n}\n\n/**\n * A layer and its ancestors, nearest first. Like `SceneGraph.closest`, the walk visits at most as\n * many layers as there are, so a parent cycle in bad data cannot hang it.\n */\nfunction* lineage(nodes: Lookup, id: string): Generator<SceneNode> {\n let node = nodes.get(id)\n for (let steps = 0; node && steps < nodes.size; steps++) {\n yield node\n node = node.parentId ? nodes.get(node.parentId) : undefined\n }\n}\n\nfunction pageOf(nodes: Lookup, id: string): string | null {\n for (const node of lineage(nodes, id)) if (node.type === 'CANVAS') return node.id\n return null\n}\n\nfunction depthIn(nodes: Lookup, id: string): number {\n let depth = 0\n for (const node of lineage(nodes, id)) if (node.parentId) depth++\n return depth\n}\n\n/** Adds one touched layer to the change, given its state on each side, if it has one. */\nfunction recordLayer(\n change: DocumentChange,\n id: string,\n previous: SceneNode | undefined,\n current: SceneNode | undefined\n): void {\n if (previous && !isEqual(previous.childIds, current?.childIds ?? [])) {\n change.children.before.push({ id, childIds: previous.childIds })\n }\n if (current && !isEqual(current.childIds, previous?.childIds ?? [])) {\n change.children.after.push({ id, childIds: [...current.childIds] })\n }\n if (!previous) {\n if (current) change.created.push(structuredClone(current))\n } else if (!current) {\n // `previous` is this edit's own copy, made before the layer changed (`captureNode`), and the\n // layer it copies is gone; restoring it copies it again, so the record stays as it is.\n // Copying it here too cost a deep clone per layer, which made deleting thousands slow.\n change.deleted.push(previous)\n } else {\n const update = diffLayer(id, previous, current)\n if (update) change.updated.push(update)\n }\n}\n\nfunction diffRecords<T>(previous: Map<string, T>, current: Map<string, T>): RecordChange<T>[] {\n const ids = new Set([...previous.keys(), ...current.keys()])\n return [...ids].flatMap((id) => {\n const before = previous.get(id) ?? null\n const after = current.get(id) ?? null\n return isEqual(before, after) ? [] : [{ id, before, after: structuredClone(after) }]\n })\n}\n\n/** Restores records in place where they exist, as views may hold them, as atomic tools do. */\n/** Make `target` hold `value` under `id`, or nothing; an existing record is kept and rewritten. */\nexport function writeRecord<T extends object>(\n target: Map<string, T>,\n id: string,\n value: T | null\n): void {\n const existing = target.get(id)\n if (!value) {\n target.delete(id)\n } else if (existing) {\n for (const key of Object.keys(existing)) {\n if (!Object.hasOwn(value, key)) Reflect.deleteProperty(existing, key)\n }\n Object.assign(existing, structuredClone(value))\n } else {\n target.set(id, structuredClone(value))\n }\n}\n\nfunction restoreRecords<T extends object>(\n target: Map<string, T>,\n changes: RecordChange<T>[],\n side: Side\n): void {\n for (const change of changes) writeRecord(target, change.id, change[side])\n}\n\n/**\n * A layer or record as it was before an edit, with what someone else changed on it while the edit\n * waited, field by field: a field the edit had left alone takes the other writer's value, and one\n * the edit had changed keeps the edit's, so its undo restores what it changed. Fields that map\n * keys to values, such as variable bindings or a variable's values by mode, are adopted one level\n * in, so independent entries of one field both survive.\n */\nfunction adoptChanges<T extends object>(baseline: T, atPause: T, live: T, depth = 1): T {\n const adopted = { ...baseline }\n for (const key of new Set([...Object.keys(atPause), ...Object.keys(live)])) {\n const paused: unknown = Reflect.get(atPause, key)\n const now: unknown = Reflect.get(live, key)\n const base: unknown = Reflect.get(baseline, key)\n const pausedHas = Object.hasOwn(atPause, key)\n const liveHas = Object.hasOwn(live, key)\n if (pausedHas === liveHas && isEqual(paused, now)) continue\n if (Object.hasOwn(baseline, key) === pausedHas && isEqual(base, paused)) {\n if (liveHas) Reflect.set(adopted, key, structuredClone(now))\n else Reflect.deleteProperty(adopted, key)\n } else if (depth > 0 && isPlainObject(base) && isPlainObject(paused) && isPlainObject(now)) {\n Reflect.set(adopted, key, adoptChanges(base, paused, now, depth - 1))\n }\n }\n return adopted\n}\n\n/** As `adoptChanges` for a map of records, dropping a record someone else removed meanwhile. */\nfunction adoptRecords<T extends object>(\n baseline: Map<string, T>,\n atPause: Map<string, T>,\n live: ReadonlyMap<string, T>\n): void {\n for (const [id, paused] of atPause) {\n const before = baseline.get(id)\n if (!before) continue\n const now = live.get(id)\n if (!now) baseline.delete(id)\n else if (isEqual(before, paused)) baseline.set(id, structuredClone(now))\n else baseline.set(id, adoptChanges(before, paused, now))\n }\n}\n\n/** What an edit changed in the document, once it is done; see `recordDocumentChange`. */\nexport interface DocumentChangeRecorder {\n /** Stops recording and returns what the edit changed. */\n finish: () => DocumentChange\n /** Treats what changes until `resume` as someone else's, as when the edit waits. */\n pause: () => void\n /** The wait ended: what changed meanwhile stays out of the edit's step. */\n resume: () => void\n}\n\n/**\n * Starts recording an edit made from `pageId`. Call `finish` once the edit is done, also when it\n * failed, to stop recording and get what the edit changed.\n *\n * The page is copied up front, so values written into its layers in place are kept too. Another\n * page, or the document node, is copied the first time the edit is about to change it.\n *\n * While the edit waits (`pause`/`resume`, or `SceneGraph.waitOutsideEdit`), what changes is\n * someone else's: a layer first touched meanwhile is not recorded, and one the edit had already\n * copied is taken in from its new state field by field on resume, so an undo of the edit leaves\n * the other writer's change alone.\n */\nexport function recordDocumentChange(graph: SceneGraph, pageId: string): DocumentChangeRecorder {\n const captured = new Map<string, SceneNode>()\n const capturedPages = new Set([pageId])\n const created = new Set<string>()\n capturePage(graph, pageId, captured)\n const variables = structuredClone(graph.variables)\n const collections = structuredClone(graph.variableCollections)\n const impact = createSceneMutationImpact()\n const unbindEvents = recordSceneMutations(graph, impact)\n let pausedDepth = 0\n let layersAtPause = new Map<string, SceneNode>()\n let variablesAtPause: Map<string, Variable> | null = null\n let collectionsAtPause: Map<string, VariableCollection> | null = null\n\n function pause(): void {\n pausedDepth += 1\n if (pausedDepth > 1) return\n layersAtPause = new Map()\n variablesAtPause = structuredClone(graph.variables)\n collectionsAtPause = structuredClone(graph.variableCollections)\n }\n\n function resume(): void {\n if (pausedDepth === 0) return\n pausedDepth -= 1\n if (pausedDepth > 0) return\n for (const [id, atPause] of layersAtPause) {\n const before = captured.get(id)\n if (!before) continue\n const live = graph.getNode(id)\n // A layer someone else removed meanwhile is not the edit's to put back.\n if (!live) captured.delete(id)\n else captured.set(id, adoptChanges(before, atPause, live))\n }\n if (variablesAtPause) adoptRecords(variables, variablesAtPause, graph.variables)\n if (collectionsAtPause) adoptRecords(collections, collectionsAtPause, graph.variableCollections)\n layersAtPause = new Map()\n variablesAtPause = null\n collectionsAtPause = null\n }\n\n const unobserve = graph.observeNodeChanges({\n created: (node) => {\n if (pausedDepth === 0) created.add(node.id)\n },\n before: (node) => {\n // While the edit waits, layers belong to whoever else changes them.\n if (pausedDepth > 0) {\n const before = captured.get(node.id)\n if (before && !layersAtPause.has(node.id)) layersAtPause.set(node.id, captureNode(node))\n return\n }\n if (captured.has(node.id) || created.has(node.id)) return\n const page = pageOf(graph.nodes, node.id)\n if (page && !capturedPages.has(page)) {\n capturedPages.add(page)\n capturePage(graph, page, captured)\n }\n if (!captured.has(node.id)) captured.set(node.id, captureNode(node))\n },\n pause,\n resume\n })\n\n const finish = (): DocumentChange => {\n resume()\n pausedDepth = 0\n unobserve()\n unbindEvents()\n const change: DocumentChange = {\n pageId,\n pageIds: [],\n created: [],\n deleted: [],\n updated: [],\n children: { before: [], after: [] },\n variables: diffRecords(variables, graph.variables),\n collections: diffRecords(collections, graph.variableCollections)\n }\n const pageIds = new Set<string>()\n const touched = new Set([\n ...impact.changedNodeIds,\n ...impact.previousParentIds,\n ...impact.currentParentIds\n ])\n for (const id of touched) {\n const previous = captured.get(id)\n // A layer changed without telling observers has no state to go back to.\n if (!previous && !created.has(id)) continue\n const current = graph.getNode(id)\n // Comments are never part of an undo step.\n const kept =\n previous && current && id === graph.rootId ? withCommentsOf(previous, current) : previous\n recordLayer(change, id, kept, current)\n for (const page of [pageOf(captured, id), pageOf(graph.nodes, id)])\n if (page) pageIds.add(page)\n }\n change.pageIds = [...pageIds]\n const byDepth = (nodes: Lookup) => (a: { id: string }, b: { id: string }) =>\n depthIn(nodes, a.id) - depthIn(nodes, b.id)\n change.created.sort(byDepth(graph.nodes))\n change.children.after.sort(byDepth(graph.nodes))\n change.deleted.sort(byDepth(captured))\n change.children.before.sort(byDepth(captured))\n return change\n }\n\n return { finish, pause, resume }\n}\n\n/** The change of one edit; `recordDocumentChange` when the edit can also wait. */\nexport function captureDocumentChange(graph: SceneGraph, pageId: string): () => DocumentChange {\n return recordDocumentChange(graph, pageId).finish\n}\n\n/** Where a layer sits: its page and the page's child holding it, null for a page or the root. */\ninterface Placement {\n pageId: string | null\n layerId: string | null\n}\n\n/** `undefined` when the layer's parents cannot be followed to a page or the root. */\nfunction placement(nodes: Lookup, id: string): Placement | undefined {\n let child: SceneNode | null = null\n for (const node of lineage(nodes, id)) {\n if (node.type === 'CANVAS') return { pageId: node.id, layerId: child?.id ?? null }\n if (!node.parentId) return { pageId: null, layerId: null }\n child = node\n }\n return undefined\n}\n\n/**\n * Layers as they were before the edit, read from the live graph: removed ones from their copies,\n * and moved ones under the parent whose old child list held them.\n */\nfunction layersBefore(graph: SceneGraph, change: DocumentChange): Lookup {\n const created = new Set(change.created.map((node) => node.id))\n const deleted = new Map(change.deleted.map((node) => [node.id, node]))\n const parents = new Map<string, string>()\n for (const { id, childIds } of change.children.before) {\n for (const childId of childIds) parents.set(childId, id)\n }\n return {\n size: graph.nodes.size + deleted.size,\n get(id) {\n if (created.has(id)) return undefined\n const node = deleted.get(id) ?? graph.getNode(id)\n const parentId = parents.get(id)\n return node && parentId !== undefined && parentId !== node.parentId\n ? { ...node, parentId }\n : node\n }\n }\n}\n\n/** Layers the edit created, removed, changed, or moved, and the parents whose children changed. */\nfunction touchedLayerIds(change: DocumentChange): string[] {\n const lists = (side: Side) =>\n new Map(change.children[side].map(({ id, childIds }) => [id, childIds]))\n const before = lists('before')\n const after = lists('after')\n // A reorder changes only its parent; a move also touches the layers that came or went.\n const moved = uniq([...before.keys(), ...after.keys()]).flatMap((id) => [\n id,\n ...xor(before.get(id) ?? [], after.get(id) ?? [])\n ])\n return uniq([\n ...change.created.map((node) => node.id),\n ...change.deleted.map((node) => node.id),\n ...change.updated.map((update) => update.id),\n ...moved\n ])\n}\n\n/** The ends of the connectors in the graph or removed by the edit, on either side of it. */\nfunction connectorEnds(graph: SceneGraph, change: DocumentChange): Map<string, string[]> {\n const ends = new Map<string, string[]>()\n const add = (id: string, nodes: Partial<SceneNode>[]) => {\n const nodeIds = nodes.flatMap((node) => [\n node.connectorStart?.nodeId,\n node.connectorEnd?.nodeId\n ])\n ends.set(id, uniq([...(ends.get(id) ?? []), ...compact(nodeIds)]))\n }\n for (const id of graph.connectorIds) add(id, compact([graph.getNode(id)]))\n for (const node of change.deleted) if (node.type === 'CONNECTOR') add(node.id, [node])\n for (const update of change.updated) {\n if (update.fields && ends.has(update.id)) add(update.id, [update.fields.before])\n }\n return ends\n}\n\n/**\n * The page children holding what an edit touched, on either side of it, for diffing and drawing\n * just those instead of whole pages (`graphsFromDocumentChange`). A layer whose connector draws\n * to a layer elsewhere brings that layer too, as JSX writes the end by it. `null` when part of\n * the page cannot be told apart this way: the edit changed variables, which any layer may show,\n * moved a layer to another page, or left a layer whose parents cannot be followed.\n */\nexport function touchedTopLevelIds(graph: SceneGraph, change: DocumentChange): string[] | null {\n if (change.variables.length > 0 || change.collections.length > 0) return null\n const before = layersBefore(graph, change)\n const sides = [before, graph.nodes]\n const holders = (id: string): (string | null)[] | null => {\n const placements = sides.map((nodes) => (nodes.get(id) ? placement(nodes, id) : null))\n if (placements.includes(undefined)) return null\n const [was, is] = placements\n if (was?.pageId && is?.pageId && was.pageId !== is.pageId) return null\n return placements.map((place) => place?.layerId ?? null)\n }\n const layers = new Set<string>()\n for (const id of touchedLayerIds(change)) {\n const held = holders(id)\n if (!held) return null\n for (const layerId of compact(held)) layers.add(layerId)\n }\n const ends = connectorEnds(graph, change)\n for (let grew = true; grew;) {\n grew = false\n for (const [connectorId, endIds] of ends) {\n if (!holders(connectorId)?.some((layerId) => layerId && layers.has(layerId))) continue\n for (const layerId of compact(endIds.flatMap((id) => holders(id) ?? []))) {\n grew ||= !layers.has(layerId)\n layers.add(layerId)\n }\n }\n }\n return [...layers]\n}\n\nexport function isEmptyDocumentChange(change: DocumentChange): boolean {\n return (\n change.created.length === 0 &&\n change.deleted.length === 0 &&\n change.updated.length === 0 &&\n change.children.before.length === 0 &&\n change.children.after.length === 0 &&\n change.variables.length === 0 &&\n change.collections.length === 0\n )\n}\n\n/**\n * Puts what an edit touched back as it was on one side of it. The graph must be as the other\n * side left it; what the edit did not touch is left alone, and so are comments. A graph that\n * holds only part of the document, such as one page, gets the part of the change it has room\n * for.\n */\nexport function applyDocumentChange(graph: SceneGraph, change: DocumentChange, side: Side): void {\n const restored = side === 'before' ? change.deleted : change.created\n const removed = side === 'before' ? change.created : change.deleted\n restoreRecords(graph.variableCollections, change.collections, side)\n restoreRecords(graph.variables, change.variables, side)\n graph.preserveSourceMetadataDuring(() => {\n for (const node of restored) {\n const { parentId, childIds: _childIds, ...fields } = structuredClone(node)\n if (!parentId || !graph.getNode(parentId)) continue\n graph.createNode(node.type, parentId, { ...fields, childIds: [] })\n }\n // Parents come first, so a layer never moves under one of its own descendants.\n for (const { id, childIds } of change.children[side]) {\n for (const [index, childId] of childIds.entries()) {\n if (graph.getNode(id)?.childIds[index] !== childId) graph.insertChildAt(childId, id, index)\n }\n }\n // Layers that survive have moved out of the removed ones by now.\n for (const node of removed) graph.deleteNode(node.id)\n for (const update of change.updated) restoreLayer(graph, update, side)\n })\n graph.clearAbsPosCache()\n}\n\n/** Drops the selected and hovered layers that no longer exist, and keeps the rest. */\nfunction keepLiveSelection(ctx: EditorContext): void {\n const live = [...ctx.state.selectedIds].filter((id) => ctx.graph.getNode(id))\n if (live.length !== ctx.state.selectedIds.size) ctx.setSelectedIds(new Set(live))\n const hovered = ctx.state.hoveredNodeId\n if (hovered !== null && !ctx.graph.getNode(hovered)) ctx.state.hoveredNodeId = null\n}\n\n/**\n * Undoes or redoes an edit in the editor, whichever page is on screen. Undo and redo clear the\n * selection on that page; `keepSelection`, for an edit put back that the person did not ask to\n * undo, keeps the selected layers that still exist.\n */\nexport function restoreDocumentChange(\n ctx: EditorContext,\n change: DocumentChange,\n side: Side,\n options: { keepSelection?: boolean } = {}\n): void {\n applyDocumentChange(ctx.graph, change, side)\n const pageIds = new Set(change.pageIds)\n // Bound values follow their variables, so the page on screen is laid out again.\n if (change.variables.length > 0) pageIds.add(ctx.state.currentPageId)\n for (const pageId of pageIds) {\n if (ctx.graph.getNode(pageId)) computeAllLayouts(ctx.graph, pageId)\n }\n if (options.keepSelection) {\n keepLiveSelection(ctx)\n } else if (pageIds.has(ctx.state.currentPageId)) {\n ctx.setSelectedIds(new Set())\n ctx.state.hoveredNodeId = null\n }\n ctx.requestRender()\n}\n"],"mappings":";;;;;;;AA2EA,MAAM,gCAA8C,IAAI,IAAI;CAAC;CAAY;CAAY;AAAQ,CAAC;AAC9F,MAAM,iCAAoD,IAAI,IAAI,CAAC,KAAK,CAAC;AAEzE,SAAS,UAAU,IAAY,UAAqB,SAAwC;CA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iB;AACzB;;AAGA,SAAS,kBAAkB,KAA0B;CACnD,MAAM,OAAO,CAAC,GAAG,IAAI,MAAM,WAAW,CAAC,CAAC,QAAQ,OAAO,IAAI,MAAM,QAAQ,EAAE,CAAC;CAC5E,IAAI,KAAK,WAAW,IAAI,MAAM,YAAY,MAAM,IAAI,eAAe,IAAI,IAAI,IAAI,CAAC;CAChF,MAAM,UAAU,IAAI,MAAM;CAC1B,IAAI,YAAY,QAAQ,CAAC,IAAI,MAAM,QAAQ,OAAO,GAAG,IAAI,MAAM,gBAAgB;AACjF;;;;;;AAOA,SAAgB,sBACd,KACA,QACA,MACA,UAAuC,CAAC,GAClC;CACN,oBAAoB,IAAI,OAAO,QAAQ,IAAI;CAC3C,MAAM,UAAU,IAAI,IAAI,OAAO,OAAO;CAEtC,IAAI,OAAO,UAAU,SAAS,GAAG,QAAQ,IAAI,IAAI,MAAM,aAAa;CACpE,KAAK,MAAM,UAAU,SACnB,IAAI,IAAI,MAAM,QAAQ,MAAM,GAAG,kBAAkB,IAAI,OAAO,MAAM;CAEpE,IAAI,QAAQ,eACV,kBAAkB,GAAG;MAChB,IAAI,QAAQ,IAAI,IAAI,MAAM,aAAa,GAAG;EAC/C,IAAI,+BAAe,IAAI,IAAI,CAAC;EAC5B,IAAI,MAAM,gBAAgB;CAC5B;CACA,IAAI,cAAc;AACpB"}
|
|
@@ -32,6 +32,13 @@ interface RecordEditOptions {
|
|
|
32
32
|
* back after it threw changed nothing.
|
|
33
33
|
*/
|
|
34
34
|
onRecorded?: (change: DocumentChange) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Judges what the edit changed once it finished without throwing. An error it returns fails
|
|
37
|
+
* the edit: with `rollbackOnThrow` the edit is put back and the error thrown, as the design
|
|
38
|
+
* memory refuses an agent's off-system values. When the edit cannot be put back, its step is
|
|
39
|
+
* recorded and nothing is thrown, so the caller reports the error some other way.
|
|
40
|
+
*/
|
|
41
|
+
verify?: (change: DocumentChange) => Error | null;
|
|
35
42
|
}
|
|
36
43
|
/**
|
|
37
44
|
* Runs a synchronous edit as one undo step of everything it changed in the document, also when
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","names":[],"sources":["../../../src/editor/history/edit.ts"],"mappings":";;;UAaiB;;EAEf;;EAEA;;EAEA;;;;;;EAMA;;;;;;;EAOA;;;;;;EAMA;;;;;EAKA,cAAc,QAAQ;;;;;;;;
|
|
1
|
+
{"version":3,"file":"edit.d.ts","names":[],"sources":["../../../src/editor/history/edit.ts"],"mappings":";;;UAaiB;;EAEf;;EAEA;;EAEA;;;;;;EAMA;;;;;;;EAOA;;;;;;EAMA;;;;;EAKA,cAAc,QAAQ;;;;;;;EAOtB,UAAU,QAAQ,mBAAmB;;;;;;;;iBA4JvB,WAAW,GAAG,KAAK,eAAe,SAAS,mBAAmB,WAAW,IAAI;;;;;;;;;;;iBAuBvE,gBAAgB,GACpC,KAAK,eACL,SAAS,mBACT,WAAW,QAAQ,KAClB,QAAQ"}
|
|
@@ -103,18 +103,21 @@ function begin(ctx, options, awaits = false) {
|
|
|
103
103
|
const recorder = recordDocumentChange(graph, pageId);
|
|
104
104
|
if (awaits) keepOpenRecorder(ctx, recorder);
|
|
105
105
|
const othersWrote = awaits ? watchOtherWrites(ctx) : () => false;
|
|
106
|
-
const finish = (
|
|
106
|
+
const finish = (threw) => {
|
|
107
107
|
if (awaits) releaseOpenRecorder(ctx, recorder);
|
|
108
108
|
const others = othersWrote();
|
|
109
109
|
const change = recorder.finish();
|
|
110
110
|
const empty = isEmptyDocumentChange(change);
|
|
111
|
-
|
|
111
|
+
const refusal = !threw && !empty && options.verify ? options.verify(change) : null;
|
|
112
|
+
if ((threw || refusal !== null) && options.rollbackOnThrow && !empty && !others && options.canRollBack?.() !== false && rollBack(ctx, graph, change)) {
|
|
112
113
|
options.onRecorded?.(unchanged(pageId));
|
|
114
|
+
if (refusal) throw refusal;
|
|
113
115
|
return;
|
|
114
116
|
}
|
|
115
117
|
if (options.push !== false && !empty) {
|
|
116
118
|
const entry = changeStep(ctx, options.label, change);
|
|
117
|
-
if (
|
|
119
|
+
if (ctx.graph !== graph) ctx.parkStep(graph, entry);
|
|
120
|
+
else if (options.ownStep) ctx.undo.pushStep(entry);
|
|
118
121
|
else ctx.undo.push(entry);
|
|
119
122
|
}
|
|
120
123
|
options.onRecorded?.(change);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.js","names":[],"sources":["../../../src/editor/history/edit.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\nimport type { UndoEntry, UndoManager } from '@pairdraw/scene-graph/undo'\n\nimport {\n applyDocumentChange,\n isEmptyDocumentChange,\n recordDocumentChange,\n restoreDocumentChange,\n type DocumentChange,\n type DocumentChangeRecorder\n} from '#core/editor/history/document-change'\nimport type { EditorContext } from '#core/editor/types'\n\nexport interface RecordEditOptions {\n /** The undo step's label. */\n label: string\n /** The page the edit is made from; it is recorded wherever in the document it lands. */\n pageId?: string\n /** False for an edit that records its own steps, such as an atomic tool's. */\n push?: boolean\n /**\n * Records the step on its own, settling any batch first, rather than as part of an open batch.\n * An edit that finishes after an await needs this: a batch open by then belongs to another\n * edit, such as a picker drag. `recordEditAsync` always does.\n */\n ownStep?: boolean\n /**\n * Puts back everything the edit changed when it throws, so a failed agent call or script leaves\n * the document as it found it and records no step. Undoing it costs what the edit touched, not\n * a copy of the document. Without it, or when something else wrote to the document while the\n * edit ran, what the edit did before it threw stays as one step.\n */\n rollbackOnThrow?: boolean\n /**\n * Whether nothing outside the editor's history wrote to the document since the edit began, such\n * as a collaborator. Asked once the edit has thrown; false records the edit's step instead of a\n * rollback that would revert those writes too. Writes the history sees are checked anyway.\n */\n canRollBack?: () => boolean\n /**\n * Receives what the edit changed, also when it fails, before its step closes. An edit rolled\n * back after it threw changed nothing.\n */\n onRecorded?: (change: DocumentChange) => void\n}\n\nfunction unchanged(pageId: string): DocumentChange {\n return {\n pageId,\n pageIds: [],\n created: [],\n deleted: [],\n updated: [],\n children: { before: [], after: [] },\n variables: [],\n collections: []\n }\n}\n\n/**\n * The undo step of a recorded change. Built outside the edit's own scope, so the step keeps only\n * the change: not the edit's recording state, nor its options, whose `onRecorded` can hold the\n * step before it and so every step back to the first, past the history limit.\n */\nfunction changeStep(ctx: EditorContext, label: string, change: DocumentChange): UndoEntry {\n return {\n label,\n forward: () => restoreDocumentChange(ctx, change, 'after'),\n inverse: () => restoreDocumentChange(ctx, change, 'before')\n }\n}\n\n/** How many edits that await are running in each history. */\nconst runningEdits = new WeakMap<UndoManager, number>()\n\n/** The recorders of edits still open in each editor, which anyone else's edit waits outside. */\nconst openRecorders = new WeakMap<EditorContext, Set<DocumentChangeRecorder>>()\n\nfunction keepOpenRecorder(ctx: EditorContext, recorder: DocumentChangeRecorder): void {\n let recorders = openRecorders.get(ctx)\n if (!recorders) {\n recorders = new Set()\n openRecorders.set(ctx, recorders)\n }\n recorders.add(recorder)\n}\n\nfunction releaseOpenRecorder(ctx: EditorContext, recorder: DocumentChangeRecorder): void {\n const recorders = openRecorders.get(ctx)\n if (!recorders) return\n recorders.delete(recorder)\n if (recorders.size === 0) openRecorders.delete(ctx)\n}\n\n/**\n * Runs a separate edit, or an undo or redo, while the edits that are still open treat what it\n * changes as someone else's: their steps leave it alone. The edit is synchronous, so nothing it\n * runs interleaves with their awaits.\n */\nfunction withOpenEditsPaused<T>(ctx: EditorContext, run: () => T, own?: DocumentChangeRecorder): T {\n const recorders = [...(openRecorders.get(ctx) ?? [])].filter((recorder) => recorder !== own)\n for (const recorder of recorders) recorder.pause()\n try {\n return run()\n } finally {\n for (const recorder of recorders) recorder.resume()\n }\n}\n\n/**\n * Watches, while an edit awaits, for writes it does not own: a step recorded, undone, or redone,\n * another edit or a batch open, or text being edited. They land in the edit's change, so rolling\n * it back would revert them too. Returns the function that stops watching and tells.\n */\nfunction watchOtherWrites(ctx: EditorContext): () => boolean {\n const { undo } = ctx\n const running = runningEdits.get(undo) ?? 0\n let others = running > 0 || undo.isRecording || ctx.state.editingTextId !== null\n runningEdits.set(undo, running + 1)\n const stop = ctx.onEditorEvent('history:changed', () => {\n others = true\n })\n return () => {\n stop()\n const left = (runningEdits.get(undo) ?? 1) - 1\n runningEdits.set(undo, left)\n return others || left > 0 || undo.isBatching || ctx.state.editingTextId !== null\n }\n}\n\n/**\n * Puts the document back as it was before a failed edit, keeping the selection the edit left\n * alone; false when that failed too, and the edit's step is then recorded instead, so what it did\n * stays undoable.\n */\nfunction rollBack(ctx: EditorContext, graph: SceneGraph, change: DocumentChange): boolean {\n try {\n if (ctx.graph !== graph) {\n // The document the edit ran in is no longer shown, so only its graph goes back.\n applyDocumentChange(graph, change, 'before')\n return true\n }\n restoreDocumentChange(ctx, change, 'before', { keepSelection: true })\n } catch {\n return false\n }\n // The document is back where its history left it, so what follows the history, such as its\n // unsaved state, settles as after an undo.\n ctx.emitEditorEvent('history:changed')\n return true\n}\n\nfunction begin(ctx: EditorContext, options: RecordEditOptions, awaits = false) {\n const graph = ctx.graph\n const pageId = options.pageId ?? ctx.state.currentPageId\n const recorder = recordDocumentChange(graph, pageId)\n if (awaits) keepOpenRecorder(ctx, recorder)\n // A synchronous edit runs alone; one that awaits shares the document while it waits.\n const othersWrote = awaits ? watchOtherWrites(ctx) : () => false\n const finish = (failed: boolean) => {\n if (awaits) releaseOpenRecorder(ctx, recorder)\n const others = othersWrote()\n const change = recorder.finish()\n const empty = isEmptyDocumentChange(change)\n if (\n failed &&\n options.rollbackOnThrow &&\n !empty &&\n !others &&\n options.canRollBack?.() !== false &&\n rollBack(ctx, graph, change)\n ) {\n options.onRecorded?.(unchanged(pageId))\n return\n }\n // An edit that changed nothing, such as a read-only script, leaves no empty step behind.\n if (options.push !== false && !empty) {\n const entry = changeStep(ctx, options.label, change)\n if (options.ownStep) ctx.undo.pushStep(entry)\n else ctx.undo.push(entry)\n }\n options.onRecorded?.(change)\n }\n return { finish, recorder }\n}\n\n/**\n * Runs a synchronous edit as one undo step of everything it changed in the document, also when\n * it throws part way, so what it did stays undoable, unless `rollbackOnThrow` puts it back. Its\n * step is recorded in the same task as its changes, as the document's unsaved state expects of an\n * edit, and joins a batch open around it.\n */\nexport function recordEdit<T>(ctx: EditorContext, options: RecordEditOptions, run: () => T): T {\n const { finish, recorder } = begin(ctx, options)\n let failed = true\n try {\n // An edit that awaits meanwhile keeps what this one changes out of its step.\n const result = withOpenEditsPaused(ctx, run, recorder)\n failed = false\n return result\n } finally {\n finish(failed)\n }\n}\n\n/**\n * Runs an edit that awaits before it finishes, such as an agent's tool call that loads fonts or\n * runs a layout, as one undo step. The edit stays open until its step is recorded, so the changes\n * it makes meanwhile count as its own rather than as edits outside the history. An edit made\n * elsewhere while it runs, such as the user's, lands in the same step: nothing tells whose write\n * is whose across an await. So `rollbackOnThrow` rolls back only an edit nothing else wrote\n * beside, as far as the history and `canRollBack` can tell, and otherwise records its step. An\n * edit that can compute first and apply in one go records only the apply with `recordEdit`\n * instead.\n */\nexport async function recordEditAsync<T>(\n ctx: EditorContext,\n options: RecordEditOptions,\n run: () => Promise<T>\n): Promise<T> {\n // Capturing can throw; the edit opens only once it has, so a failure never leaves it open.\n const { finish } = begin(ctx, { ...options, ownStep: true }, true)\n const close = ctx.undo.openEdit()\n let failed = true\n try {\n const result = await run()\n failed = false\n return result\n } finally {\n try {\n finish(failed)\n } finally {\n close()\n }\n }\n}\n"],"mappings":";;AA8CA,SAAS,UAAU,QAAgC;CACjD,OAAO;EACL;EACA,SAAS,CAAC;EACV,SAAS,CAAC;EACV,SAAS,CAAC;EACV,SAAS,CAAC;EACV,UAAU;GAAE,QAAQ,CAAC;GAAG,OAAO,CAAC;EAAE;EAClC,WAAW,CAAC;EACZ,aAAa,CAAC;CAChB;AACF;;;;;;AAOA,SAAS,WAAW,KAAoB,OAAe,QAAmC;CACxF,OAAO;EACL;EACA,eAAe,sBAAsB,KAAK,QAAQ,OAAO;EACzD,eAAe,sBAAsB,KAAK,QAAQ,QAAQ;CAC5D;AACF;;AAGA,M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;;;;;;AAYA,eAAsB,gBACpB,KACA,SACA,KACY;CAEZ,MAAM,EAAE,WAAW,MAAM,KAAK;EAAE,GAAG;EAAS,SAAS;CAAK,GAAG,IAAI;CACjE,MAAM,QAAQ,IAAI,KAAK,SAAS;CAChC,IAAI,SAAS;CACb,IAAI;EACF,MAAM,SAAS,MAAM,IAAI;EACzB,SAAS;EACT,OAAO;CACT,UAAU;EACR,IAAI;GACF,OAAO,MAAM;EACf,UAAU;GACR,MAAM;EACR;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"edit.js","names":[],"sources":["../../../src/editor/history/edit.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\nimport type { UndoEntry, UndoManager } from '@pairdraw/scene-graph/undo'\n\nimport {\n applyDocumentChange,\n isEmptyDocumentChange,\n recordDocumentChange,\n restoreDocumentChange,\n type DocumentChange,\n type DocumentChangeRecorder\n} from '#core/editor/history/document-change'\nimport type { EditorContext } from '#core/editor/types'\n\nexport interface RecordEditOptions {\n /** The undo step's label. */\n label: string\n /** The page the edit is made from; it is recorded wherever in the document it lands. */\n pageId?: string\n /** False for an edit that records its own steps, such as an atomic tool's. */\n push?: boolean\n /**\n * Records the step on its own, settling any batch first, rather than as part of an open batch.\n * An edit that finishes after an await needs this: a batch open by then belongs to another\n * edit, such as a picker drag. `recordEditAsync` always does.\n */\n ownStep?: boolean\n /**\n * Puts back everything the edit changed when it throws, so a failed agent call or script leaves\n * the document as it found it and records no step. Undoing it costs what the edit touched, not\n * a copy of the document. Without it, or when something else wrote to the document while the\n * edit ran, what the edit did before it threw stays as one step.\n */\n rollbackOnThrow?: boolean\n /**\n * Whether nothing outside the editor's history wrote to the document since the edit began, such\n * as a collaborator. Asked once the edit has thrown; false records the edit's step instead of a\n * rollback that would revert those writes too. Writes the history sees are checked anyway.\n */\n canRollBack?: () => boolean\n /**\n * Receives what the edit changed, also when it fails, before its step closes. An edit rolled\n * back after it threw changed nothing.\n */\n onRecorded?: (change: DocumentChange) => void\n /**\n * Judges what the edit changed once it finished without throwing. An error it returns fails\n * the edit: with `rollbackOnThrow` the edit is put back and the error thrown, as the design\n * memory refuses an agent's off-system values. When the edit cannot be put back, its step is\n * recorded and nothing is thrown, so the caller reports the error some other way.\n */\n verify?: (change: DocumentChange) => Error | null\n}\n\nfunction unchanged(pageId: string): DocumentChange {\n return {\n pageId,\n pageIds: [],\n created: [],\n deleted: [],\n updated: [],\n children: { before: [], after: [] },\n variables: [],\n collections: []\n }\n}\n\n/**\n * The undo step of a recorded change. Built outside the edit's own scope, so the step keeps only\n * the change: not the edit's recording state, nor its options, whose `onRecorded` can hold the\n * step before it and so every step back to the first, past the history limit.\n */\nfunction changeStep(ctx: EditorContext, label: string, change: DocumentChange): UndoEntry {\n return {\n label,\n forward: () => restoreDocumentChange(ctx, change, 'after'),\n inverse: () => restoreDocumentChange(ctx, change, 'before')\n }\n}\n\n/** How many edits that await are running in each history. */\nconst runningEdits = new WeakMap<UndoManager, number>()\n\n/** The recorders of edits still open in each editor, which anyone else's edit waits outside. */\nconst openRecorders = new WeakMap<EditorContext, Set<DocumentChangeRecorder>>()\n\nfunction keepOpenRecorder(ctx: EditorContext, recorder: DocumentChangeRecorder): void {\n let recorders = openRecorders.get(ctx)\n if (!recorders) {\n recorders = new Set()\n openRecorders.set(ctx, recorders)\n }\n recorders.add(recorder)\n}\n\nfunction releaseOpenRecorder(ctx: EditorContext, recorder: DocumentChangeRecorder): void {\n const recorders = openRecorders.get(ctx)\n if (!recorders) return\n recorders.delete(recorder)\n if (recorders.size === 0) openRecorders.delete(ctx)\n}\n\n/**\n * Runs a separate edit, or an undo or redo, while the edits that are still open treat what it\n * changes as someone else's: their steps leave it alone. The edit is synchronous, so nothing it\n * runs interleaves with their awaits.\n */\nfunction withOpenEditsPaused<T>(ctx: EditorContext, run: () => T, own?: DocumentChangeRecorder): T {\n const recorders = [...(openRecorders.get(ctx) ?? [])].filter((recorder) => recorder !== own)\n for (const recorder of recorders) recorder.pause()\n try {\n return run()\n } finally {\n for (const recorder of recorders) recorder.resume()\n }\n}\n\n/**\n * Watches, while an edit awaits, for writes it does not own: a step recorded, undone, or redone,\n * another edit or a batch open, or text being edited. They land in the edit's change, so rolling\n * it back would revert them too. Returns the function that stops watching and tells.\n */\nfunction watchOtherWrites(ctx: EditorContext): () => boolean {\n const { undo } = ctx\n const running = runningEdits.get(undo) ?? 0\n let others = running > 0 || undo.isRecording || ctx.state.editingTextId !== null\n runningEdits.set(undo, running + 1)\n const stop = ctx.onEditorEvent('history:changed', () => {\n others = true\n })\n return () => {\n stop()\n const left = (runningEdits.get(undo) ?? 1) - 1\n runningEdits.set(undo, left)\n return others || left > 0 || undo.isBatching || ctx.state.editingTextId !== null\n }\n}\n\n/**\n * Puts the document back as it was before a failed edit, keeping the selection the edit left\n * alone; false when that failed too, and the edit's step is then recorded instead, so what it did\n * stays undoable.\n */\nfunction rollBack(ctx: EditorContext, graph: SceneGraph, change: DocumentChange): boolean {\n try {\n if (ctx.graph !== graph) {\n // The document the edit ran in is no longer shown, so only its graph goes back.\n applyDocumentChange(graph, change, 'before')\n return true\n }\n restoreDocumentChange(ctx, change, 'before', { keepSelection: true })\n } catch {\n return false\n }\n // The document is back where its history left it, so what follows the history, such as its\n // unsaved state, settles as after an undo.\n ctx.emitEditorEvent('history:changed')\n return true\n}\n\nfunction begin(ctx: EditorContext, options: RecordEditOptions, awaits = false) {\n const graph = ctx.graph\n const pageId = options.pageId ?? ctx.state.currentPageId\n const recorder = recordDocumentChange(graph, pageId)\n if (awaits) keepOpenRecorder(ctx, recorder)\n // A synchronous edit runs alone; one that awaits shares the document while it waits.\n const othersWrote = awaits ? watchOtherWrites(ctx) : () => false\n const finish = (threw: boolean) => {\n if (awaits) releaseOpenRecorder(ctx, recorder)\n const others = othersWrote()\n const change = recorder.finish()\n const empty = isEmptyDocumentChange(change)\n const refusal = !threw && !empty && options.verify ? options.verify(change) : null\n const failed = threw || refusal !== null\n if (\n failed &&\n options.rollbackOnThrow &&\n !empty &&\n !others &&\n options.canRollBack?.() !== false &&\n rollBack(ctx, graph, change)\n ) {\n options.onRecorded?.(unchanged(pageId))\n if (refusal) throw refusal\n return\n }\n // An edit that changed nothing, such as a read-only script, leaves no empty step behind.\n if (options.push !== false && !empty) {\n const entry = changeStep(ctx, options.label, change)\n if (ctx.graph !== graph) {\n // The document the edit began on was swapped away while it awaited: its step stays with\n // that document, and the one now open never carries an edit it did not see.\n ctx.parkStep(graph, entry)\n } else if (options.ownStep) ctx.undo.pushStep(entry)\n else ctx.undo.push(entry)\n }\n options.onRecorded?.(change)\n }\n return { finish, recorder }\n}\n\n/**\n * Runs a synchronous edit as one undo step of everything it changed in the document, also when\n * it throws part way, so what it did stays undoable, unless `rollbackOnThrow` puts it back. Its\n * step is recorded in the same task as its changes, as the document's unsaved state expects of an\n * edit, and joins a batch open around it.\n */\nexport function recordEdit<T>(ctx: EditorContext, options: RecordEditOptions, run: () => T): T {\n const { finish, recorder } = begin(ctx, options)\n let failed = true\n try {\n // An edit that awaits meanwhile keeps what this one changes out of its step.\n const result = withOpenEditsPaused(ctx, run, recorder)\n failed = false\n return result\n } finally {\n finish(failed)\n }\n}\n\n/**\n * Runs an edit that awaits before it finishes, such as an agent's tool call that loads fonts or\n * runs a layout, as one undo step. The edit stays open until its step is recorded, so the changes\n * it makes meanwhile count as its own rather than as edits outside the history. An edit made\n * elsewhere while it runs, such as the user's, lands in the same step: nothing tells whose write\n * is whose across an await. So `rollbackOnThrow` rolls back only an edit nothing else wrote\n * beside, as far as the history and `canRollBack` can tell, and otherwise records its step. An\n * edit that can compute first and apply in one go records only the apply with `recordEdit`\n * instead.\n */\nexport async function recordEditAsync<T>(\n ctx: EditorContext,\n options: RecordEditOptions,\n run: () => Promise<T>\n): Promise<T> {\n // Capturing can throw; the edit opens only once it has, so a failure never leaves it open.\n const { finish } = begin(ctx, { ...options, ownStep: true }, true)\n const close = ctx.undo.openEdit()\n let failed = true\n try {\n const result = await run()\n failed = false\n return result\n } finally {\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,UAAU,MAAM,CAAC;GACtC,IAAI,SAAS,MAAM;GACnB;EACF;EAEA,IAAI,QAAQ,SAAS,SAAS,CAAC,OAAO;GACpC,MAAM,QAAQ,WAAW,KAAK,QAAQ,OAAO,MAAM;GACnD,IAAI,IAAI,UAAU,OAGhB,IAAI,SAAS,OAAO,KAAK;QACpB,IAAI,QAAQ,SAAS,IAAI,KAAK,SAAS,KAAK;QAC9C,IAAI,KAAK,KAAK,KAAK;EAC1B;EACA,QAAQ,aAAa,MAAM;CAC7B;CACA,OAAO;EAAE;EAAQ;CAAS;AAC5B;;;;;;;AAQA,SAAgB,WAAc,KAAoB,SAA4B,KAAiB;CAC7F,MAAM,EAAE,QAAQ,aAAa,MAAM,KAAK,OAAO;CAC/C,IAAI,SAAS;CACb,IAAI;EAEF,MAAM,SAAS,oBAAoB,KAAK,KAAK,QAAQ;EACrD,SAAS;EACT,OAAO;CACT,UAAU;EACR,OAAO,MAAM;CACf;AACF;;;;;;;;;;;AAYA,eAAsB,gBACpB,KACA,SACA,KACY;CAEZ,MAAM,EAAE,WAAW,MAAM,KAAK;EAAE,GAAG;EAAS,SAAS;CAAK,GAAG,IAAI;CACjE,MAAM,QAAQ,IAAI,KAAK,SAAS;CAChC,IAAI,SAAS;CACb,IAAI;EACF,MAAM,SAAS,MAAM,IAAI;EACzB,SAAS;EACT,OAAO;CACT,UAAU;EACR,IAAI;GACF,OAAO,MAAM;EACf,UAAU;GACR,MAAM;EACR;CACF;AACF"}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
|
|
2
2
|
//#region src/editor/history/subtree.d.ts
|
|
3
3
|
declare function collectSubtrees(graph: SceneGraph, rootIds: string[]): SceneNode[];
|
|
4
|
+
/**
|
|
5
|
+
* Copies of a layer and its layers by id, for undo to put back. Each is a `captureNode` copy,
|
|
6
|
+
* not a deep clone, so deleting thousands of layers stays quick.
|
|
7
|
+
*/
|
|
4
8
|
declare function snapshotSubtree(graph: SceneGraph, rootId: string): Map<string, SceneNode>;
|
|
9
|
+
/**
|
|
10
|
+
* Puts a snapshot back under `parentId`, its layers in order. The layer it makes gets a copy of
|
|
11
|
+
* the snapshot's child list, source metadata and override maps, which the graph edits in place,
|
|
12
|
+
* so the snapshot stays as it is for the next undo or redo.
|
|
13
|
+
*/
|
|
5
14
|
declare function restoreSubtree(graph: SceneGraph, snapshot: SceneNode, parentId: string, index: Map<string, SceneNode>): void;
|
|
6
15
|
//#endregion
|
|
7
16
|
export { collectSubtrees, restoreSubtree, snapshotSubtree };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subtree.d.ts","names":[],"sources":["../../../src/editor/history/subtree.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"subtree.d.ts","names":[],"sources":["../../../src/editor/history/subtree.ts"],"mappings":";;iBAIgB,gBAAgB,OAAO,YAAY,oBAAoB;;;;;iBAgBvD,gBAAgB,OAAO,YAAY,iBAAiB,YAAY;;;;;;iBAiBhE,eACd,OAAO,YACP,UAAU,WACV,kBACA,OAAO,YAAY"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { captureNode } from "./capture.js";
|
|
1
2
|
//#region src/editor/history/subtree.ts
|
|
2
3
|
function collectSubtrees(graph, rootIds) {
|
|
3
4
|
const result = [];
|
|
@@ -10,19 +11,28 @@ function collectSubtrees(graph, rootIds) {
|
|
|
10
11
|
for (const id of rootIds) walk(id);
|
|
11
12
|
return result;
|
|
12
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Copies of a layer and its layers by id, for undo to put back. Each is a `captureNode` copy,
|
|
16
|
+
* not a deep clone, so deleting thousands of layers stays quick.
|
|
17
|
+
*/
|
|
13
18
|
function snapshotSubtree(graph, rootId) {
|
|
14
19
|
const index = /* @__PURE__ */ new Map();
|
|
15
20
|
const walk = (id) => {
|
|
16
21
|
const node = graph.getNode(id);
|
|
17
22
|
if (!node) return;
|
|
18
|
-
index.set(id,
|
|
23
|
+
index.set(id, captureNode(node));
|
|
19
24
|
for (const childId of node.childIds) walk(childId);
|
|
20
25
|
};
|
|
21
26
|
walk(rootId);
|
|
22
27
|
return index;
|
|
23
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Puts a snapshot back under `parentId`, its layers in order. The layer it makes gets a copy of
|
|
31
|
+
* the snapshot's child list, source metadata and override maps, which the graph edits in place,
|
|
32
|
+
* so the snapshot stays as it is for the next undo or redo.
|
|
33
|
+
*/
|
|
24
34
|
function restoreSubtree(graph, snapshot, parentId, index) {
|
|
25
|
-
const { parentId: _parentId, childIds, ...rest } = snapshot;
|
|
35
|
+
const { parentId: _parentId, childIds, ...rest } = captureNode(snapshot);
|
|
26
36
|
graph.createNode(snapshot.type, parentId, {
|
|
27
37
|
...rest,
|
|
28
38
|
id: snapshot.id
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subtree.js","names":[],"sources":["../../../src/editor/history/subtree.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nexport function collectSubtrees(graph: SceneGraph, rootIds: string[]): SceneNode[] {\n const result: SceneNode[] = []\n function walk(id: string) {\n const node = graph.getNode(id)\n if (!node) return\n result.push(structuredClone(node))\n for (const childId of node.childIds) walk(childId)\n }\n for (const id of rootIds) walk(id)\n return result\n}\n\nexport function snapshotSubtree(graph: SceneGraph, rootId: string): Map<string, SceneNode> {\n const index = new Map<string, SceneNode>()\n const walk = (id: string) => {\n const node = graph.getNode(id)\n if (!node) return\n index.set(id,
|
|
1
|
+
{"version":3,"file":"subtree.js","names":[],"sources":["../../../src/editor/history/subtree.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport { captureNode } from './capture'\n\nexport function collectSubtrees(graph: SceneGraph, rootIds: string[]): SceneNode[] {\n const result: SceneNode[] = []\n function walk(id: string) {\n const node = graph.getNode(id)\n if (!node) return\n result.push(structuredClone(node))\n for (const childId of node.childIds) walk(childId)\n }\n for (const id of rootIds) walk(id)\n return result\n}\n\n/**\n * Copies of a layer and its layers by id, for undo to put back. Each is a `captureNode` copy,\n * not a deep clone, so deleting thousands of layers stays quick.\n */\nexport function snapshotSubtree(graph: SceneGraph, rootId: string): Map<string, SceneNode> {\n const index = new Map<string, SceneNode>()\n const walk = (id: string) => {\n const node = graph.getNode(id)\n if (!node) return\n index.set(id, captureNode(node))\n for (const childId of node.childIds) walk(childId)\n }\n walk(rootId)\n return index\n}\n\n/**\n * Puts a snapshot back under `parentId`, its layers in order. The layer it makes gets a copy of\n * the snapshot's child list, source metadata and override maps, which the graph edits in place,\n * so the snapshot stays as it is for the next undo or redo.\n */\nexport function restoreSubtree(\n graph: SceneGraph,\n snapshot: SceneNode,\n parentId: string,\n index: Map<string, SceneNode>\n): void {\n const { parentId: _parentId, childIds, ...rest } = captureNode(snapshot)\n graph.createNode(snapshot.type, parentId, { ...rest, id: snapshot.id })\n for (const childId of childIds) {\n const child = index.get(childId)\n if (child) restoreSubtree(graph, child, snapshot.id, index)\n }\n}\n"],"mappings":";;AAIA,SAAgB,gBAAgB,OAAmB,SAAgC;CACjF,MAAM,SAAsB,CAAC;CAC7B,SAAS,KAAK,IAAY;EACxB,MAAM,OAAO,MAAM,QAAQ,EAAE;EAC7B,IAAI,CAAC,MAAM;EACX,OAAO,KAAK,gBAAgB,IAAI,CAAC;EACjC,KAAK,MAAM,WAAW,KAAK,UAAU,KAAK,OAAO;CACnD;CACA,KAAK,MAAM,MAAM,SAAS,KAAK,EAAE;CACjC,OAAO;AACT;;;;;AAMA,SAAgB,gBAAgB,OAAmB,QAAwC;CACzF,MAAM,wBAAQ,IAAI,IAAuB;CACzC,MAAM,QAAQ,OAAe;EAC3B,MAAM,OAAO,MAAM,QAAQ,EAAE;EAC7B,IAAI,CAAC,MAAM;EACX,MAAM,IAAI,IAAI,YAAY,IAAI,CAAC;EAC/B,KAAK,MAAM,WAAW,KAAK,UAAU,KAAK,OAAO;CACnD;CACA,KAAK,MAAM;CACX,OAAO;AACT;;;;;;AAOA,SAAgB,eACd,OACA,UACA,UACA,OACM;CACN,MAAM,EAAE,UAAU,WAAW,UAAU,GAAG,SAAS,YAAY,QAAQ;CACvE,MAAM,WAAW,SAAS,MAAM,UAAU;EAAE,GAAG;EAAM,IAAI,SAAS;CAAG,CAAC;CACtE,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,QAAQ,MAAM,IAAI,OAAO;EAC/B,IAAI,OAAO,eAAe,OAAO,OAAO,SAAS,IAAI,KAAK;CAC5D;AACF"}
|
package/dist/editor/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { ClipboardImageResolution, EditorContext, EditorEventName, EditorEvents,
|
|
|
6
6
|
import { ClipboardCollectionDependency, ClipboardConflictResolution, ClipboardImportChoice, ClipboardImportPlan, ClipboardStyleDependency, clipboardImportHasConflicts, clipboardImportHasDependencies, planClipboardImport } from "./clipboard/conflicts.js";
|
|
7
7
|
import { ClipboardSnapshot } from "./clipboard/snapshot.js";
|
|
8
8
|
import { ClipboardPayload, CopyOptions } from "./clipboard/copy.js";
|
|
9
|
+
import { DocumentChange, applyDocumentChange, isEmptyDocumentChange, recordDocumentChange, touchedTopLevelIds } from "./history/document-change.js";
|
|
9
10
|
import { SelectionSpacing } from "./alignment.js";
|
|
10
11
|
import { NodeEditCapability, ReadOnlyLibraryDefinitionError, assertNodeEditable, getNodeEditCapability } from "./capabilities.js";
|
|
11
12
|
import { ReadOnlyDocumentError } from "./read-only/index.js";
|
|
@@ -13,11 +14,11 @@ import { createDocumentGraph } from "./document-settings.js";
|
|
|
13
14
|
import { createDefaultEditorSharedState } from "./state/shared.js";
|
|
14
15
|
import { editedGradient, editedGradientLayout } from "./gradient-edit.js";
|
|
15
16
|
import { EditedImage, ImageEditModifiers, editableImageFillIndex, editedImage, editedImageLayout, imageEditChanges, imageEditCrops } from "./image-edit.js";
|
|
16
|
-
import { DocumentChange, isEmptyDocumentChange, touchedTopLevelIds } from "./history/document-change.js";
|
|
17
17
|
import { RecordEditOptions } from "./history/edit.js";
|
|
18
18
|
import { PageSnapshot } from "./history/snapshot/page.js";
|
|
19
19
|
import { MovePlace } from "./undo.js";
|
|
20
20
|
import { SelectionColor, replaceSelectionColor, selectionColors, selectionColorsShown } from "./selection/colors.js";
|
|
21
|
+
import { DOCUMENT_COLOR_LIMIT, DocumentColor, documentColors } from "./document-colors.js";
|
|
21
22
|
import { copyEditorViewState, createDefaultEditorViewState, pickEditorViewState } from "./state/view.js";
|
|
22
23
|
import { VariantConflict, VariantMutationResult, VariantValidationIssue } from "./components/variants/model.js";
|
|
23
24
|
import "./components/variants/index.js";
|
|
@@ -52,6 +53,7 @@ import { resizedPathTextGlyphs } from "./text/path-edit.js";
|
|
|
52
53
|
import { opacityFromBuffer } from "./nodes.js";
|
|
53
54
|
import { LayerType, layerTypeOptions } from "./structure/layer-type.js";
|
|
54
55
|
import { BOARD_TOOLS, BOARD_TOOL_SHORTCUTS, EDITOR_TOOLS, EditorToolDef, TOOL_SHORTCUTS } from "./tool-registry.js";
|
|
56
|
+
import { EyedropperTarget, ScenePixels, applySampledColor, eyedropperChanges, sampleSceneColor, sampleScenePixels, scenePixelColor } from "./eyedropper.js";
|
|
55
57
|
import { newLayerDefaults } from "./shapes/defaults.js";
|
|
56
58
|
import { RenameSelectionOptions, RenameSelectionPreview } from "./structure/rename.js";
|
|
57
|
-
export { type AttachModifiers, BOARD_TOOLS, BOARD_TOOL_SHORTCUTS, type CanvasView, type ClipboardCollectionDependency, type ClipboardConflictResolution, type ClipboardImageResolution, type ClipboardImportChoice, type ClipboardImportPlan, type ClipboardPayload, type ClipboardSnapshot, type ClipboardStyleDependency, type CopyOptions, DEFAULT_SCALE_ANCHOR, DEFAULT_SNAPPING_PREFERENCES, type DocumentChange, EDITOR_TOOLS, EDIT_VIEW, type EditedImage, type Editor, type EditorContext, type EditorEventName, type EditorEvents, type EditorOptions, type EditorProfile, type EditorProfileInputs, type EditorRestrictions, type EditorSharedState, type EditorState, type EditorToolDef, type EditorViewState, type ExposableComponentField, type FigmaClipboardImageResolver, type GradientEdit, type HyperlinkHit, type ImageEdit, type ImageEditModifiers, type InstanceState, type LayerType, type MovePlace, type NodeEditCapability, type NodePreview, type PageSnapshot, type PageSwitchProgress, type PreparePageOptions, type PreparedPage, type PresentationScale, type PresentationState, ReadOnlyDocumentError, ReadOnlyLibraryDefinitionError, type RecordEditOptions, type RenameSelectionOptions, type RenameSelectionPreview, type RescaleSnapshot, type ResumedPath, SCALE_ANCHORS, type ScaleAnchor, type ScaleSession, type SelectionColor, type SelectionSpacing, type ShaderModeState, type ShaderModeTarget, type ShaderPaintList, type ShaderRasterizer, type ShaderView, type ShapeHandleHover, type SlideMoveTarget, type SnappingPreferences, type SwitchPageOptions, TOOL_SHORTCUTS, type TextHyperlinkState, type Tool, type VariableTokenFields, type VariantConflict, type VariantMutationResult, type VariantValidationIssue, type ViewportInsets, type VisibleCanvas, assertNodeEditable, clipboardImportHasConflicts, clipboardImportHasDependencies, copyEditorViewState, createDefaultEditorSharedState, createDefaultEditorState, createDefaultEditorViewState, createDocumentGraph, createEditor, createGuideActions, createTextActions, editableImageFillIndex, editedGradient, editedGradientLayout, editedImage, editedImageLayout, executeAtomicTool, findShaderModeTarget, getNodeEditCapability, graphFromDocumentChange, graphFromPageSnapshot, graphsFromDocumentChange, imageEditChanges, imageEditCrops, isEmptyDocumentChange, isScaleAnchor, layerTypeOptions, newLayerDefaults, opacityFromBuffer, pageSlides, parseScaleFactor, pastedPropertyChanges, pickEditorViewState, planClipboardImport, playIslandRoots, presentationViewport, reapplyInstanceComponentProperties, replaceSelectionColor, rescaleNodes, resizedPathTextGlyphs, resolveEditorProfile, resolvePasteTarget, resolvePlayState, scaleAnchorFraction, scaleAnchorPoint, scaleFactorForSize, scaledBounds, selectionColors, selectionColorsShown, slideMoveTarget, syncEditedComponents, touchedTopLevelIds };
|
|
59
|
+
export { type AttachModifiers, BOARD_TOOLS, BOARD_TOOL_SHORTCUTS, type CanvasView, type ClipboardCollectionDependency, type ClipboardConflictResolution, type ClipboardImageResolution, type ClipboardImportChoice, type ClipboardImportPlan, type ClipboardPayload, type ClipboardSnapshot, type ClipboardStyleDependency, type CopyOptions, DEFAULT_SCALE_ANCHOR, DEFAULT_SNAPPING_PREFERENCES, DOCUMENT_COLOR_LIMIT, type DocumentChange, type DocumentColor, EDITOR_TOOLS, EDIT_VIEW, type EditedImage, type Editor, type EditorContext, type EditorEventName, type EditorEvents, type EditorOptions, type EditorProfile, type EditorProfileInputs, type EditorRestrictions, type EditorSharedState, type EditorState, type EditorToolDef, type EditorViewState, type ExposableComponentField, type EyedropperTarget, type FigmaClipboardImageResolver, type GradientEdit, type HyperlinkHit, type ImageEdit, type ImageEditModifiers, type InstanceState, type LayerType, type MovePlace, type NodeEditCapability, type NodePreview, type PageSnapshot, type PageSwitchProgress, type PreparePageOptions, type PreparedPage, type PresentationScale, type PresentationState, ReadOnlyDocumentError, ReadOnlyLibraryDefinitionError, type RecordEditOptions, type RenameSelectionOptions, type RenameSelectionPreview, type RescaleSnapshot, type ResumedPath, SCALE_ANCHORS, type ScaleAnchor, type ScaleSession, type ScenePixels, type SelectionColor, type SelectionSpacing, type ShaderModeState, type ShaderModeTarget, type ShaderPaintList, type ShaderRasterizer, type ShaderView, type ShapeHandleHover, type SlideMoveTarget, type SnappingPreferences, type SwitchPageOptions, TOOL_SHORTCUTS, type TextHyperlinkState, type Tool, type VariableTokenFields, type VariantConflict, type VariantMutationResult, type VariantValidationIssue, type ViewportInsets, type VisibleCanvas, applyDocumentChange, applySampledColor, assertNodeEditable, clipboardImportHasConflicts, clipboardImportHasDependencies, copyEditorViewState, createDefaultEditorSharedState, createDefaultEditorState, createDefaultEditorViewState, createDocumentGraph, createEditor, createGuideActions, createTextActions, documentColors, editableImageFillIndex, editedGradient, editedGradientLayout, editedImage, editedImageLayout, executeAtomicTool, eyedropperChanges, findShaderModeTarget, getNodeEditCapability, graphFromDocumentChange, graphFromPageSnapshot, graphsFromDocumentChange, imageEditChanges, imageEditCrops, isEmptyDocumentChange, isScaleAnchor, layerTypeOptions, newLayerDefaults, opacityFromBuffer, pageSlides, parseScaleFactor, pastedPropertyChanges, pickEditorViewState, planClipboardImport, playIslandRoots, presentationViewport, reapplyInstanceComponentProperties, recordDocumentChange, replaceSelectionColor, rescaleNodes, resizedPathTextGlyphs, resolveEditorProfile, resolvePasteTarget, resolvePlayState, sampleSceneColor, sampleScenePixels, scaleAnchorFraction, scaleAnchorPoint, scaleFactorForSize, scaledBounds, scenePixelColor, selectionColors, selectionColorsShown, slideMoveTarget, syncEditedComponents, touchedTopLevelIds };
|
package/dist/editor/index.js
CHANGED
|
@@ -12,8 +12,9 @@ import { DEFAULT_SNAPPING_PREFERENCES } from "./preferences.js";
|
|
|
12
12
|
import { createDocumentGraph } from "./document-settings.js";
|
|
13
13
|
import { createDefaultEditorSharedState } from "./state/shared.js";
|
|
14
14
|
import { replaceSelectionColor, selectionColors, selectionColorsShown } from "./selection/colors.js";
|
|
15
|
+
import { DOCUMENT_COLOR_LIMIT, documentColors } from "./document-colors.js";
|
|
15
16
|
import { copyEditorViewState, createDefaultEditorViewState, pickEditorViewState } from "./state/view.js";
|
|
16
|
-
import { isEmptyDocumentChange, touchedTopLevelIds } from "./history/document-change.js";
|
|
17
|
+
import { applyDocumentChange, isEmptyDocumentChange, recordDocumentChange, touchedTopLevelIds } from "./history/document-change.js";
|
|
17
18
|
import { resolvePasteTarget } from "./clipboard/paste/target.js";
|
|
18
19
|
import { clipboardImportHasConflicts, clipboardImportHasDependencies, planClipboardImport } from "./clipboard/conflicts.js";
|
|
19
20
|
import { reapplyInstanceComponentProperties } from "./components/properties.js";
|
|
@@ -32,4 +33,5 @@ import { createEditor } from "./create.js";
|
|
|
32
33
|
import { executeAtomicTool } from "./history/atomic-tool.js";
|
|
33
34
|
import { graphFromDocumentChange, graphFromPageSnapshot, graphsFromDocumentChange } from "./history/snapshot/graph.js";
|
|
34
35
|
import { resolvePlayState } from "./play/states.js";
|
|
35
|
-
|
|
36
|
+
import { applySampledColor, eyedropperChanges, sampleSceneColor, sampleScenePixels, scenePixelColor } from "./eyedropper.js";
|
|
37
|
+
export { BOARD_TOOLS, BOARD_TOOL_SHORTCUTS, DEFAULT_SCALE_ANCHOR, DEFAULT_SNAPPING_PREFERENCES, DOCUMENT_COLOR_LIMIT, EDITOR_TOOLS, EDIT_VIEW, ReadOnlyDocumentError, ReadOnlyLibraryDefinitionError, SCALE_ANCHORS, TOOL_SHORTCUTS, applyDocumentChange, applySampledColor, assertNodeEditable, clipboardImportHasConflicts, clipboardImportHasDependencies, copyEditorViewState, createDefaultEditorSharedState, createDefaultEditorState, createDefaultEditorViewState, createDocumentGraph, createEditor, createGuideActions, createTextActions, documentColors, editableImageFillIndex, editedGradient, editedGradientLayout, editedImage, editedImageLayout, executeAtomicTool, eyedropperChanges, findShaderModeTarget, getNodeEditCapability, graphFromDocumentChange, graphFromPageSnapshot, graphsFromDocumentChange, imageEditChanges, imageEditCrops, isEmptyDocumentChange, isScaleAnchor, layerTypeOptions, newLayerDefaults, opacityFromBuffer, pageSlides, parseScaleFactor, pastedPropertyChanges, pickEditorViewState, planClipboardImport, playIslandRoots, presentationViewport, reapplyInstanceComponentProperties, recordDocumentChange, replaceSelectionColor, rescaleNodes, resizedPathTextGlyphs, resolveEditorProfile, resolvePasteTarget, resolvePlayState, sampleSceneColor, sampleScenePixels, scaleAnchorFraction, scaleAnchorPoint, scaleFactorForSize, scaledBounds, scenePixelColor, selectionColors, selectionColorsShown, slideMoveTarget, syncEditedComponents, touchedTopLevelIds };
|
package/dist/editor/nudge.js
CHANGED
|
@@ -42,7 +42,7 @@ function createNudgeActions(ctx) {
|
|
|
42
42
|
let closeNudgeEdit = null;
|
|
43
43
|
function applyOrder(parentId, order) {
|
|
44
44
|
order.forEach((id, index) => ctx.graph.insertChildAt(id, parentId, index));
|
|
45
|
-
ctx.
|
|
45
|
+
ctx.runLayoutForParents([parentId]);
|
|
46
46
|
}
|
|
47
47
|
function commitReorder() {
|
|
48
48
|
if (!reorderOriginals) return;
|
package/dist/editor/nudge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nudge.js","names":[],"sources":["../../src/editor/nudge.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { collectNodePositions, pushPositionUndo } from './history/position'\nimport { fitEnclosingGroupsWithUndo } from './structure/group/bounds'\nimport type { EditorContext } from './types'\n\nconst NUDGE_COMMIT_DELAY = 300\n\n/** The flow an arrow key moves a layer along: its row or column, or none. */\nfunction flowParent(ctx: EditorContext, node: SceneNode): SceneNode | null {\n if (node.layoutPositioning === 'ABSOLUTE' || !node.parentId) return null\n const parent = ctx.graph.getNode(node.parentId)\n return parent?.layoutMode === 'HORIZONTAL' || parent?.layoutMode === 'VERTICAL' ? parent : null\n}\n\n/**\n * One slot along the flow for an arrow key, as Figma reorders auto layout children: Right and\n * Left in a row (mirrored when it runs right to left), Down and Up in a column, and nothing for\n * the arrows across it. Shift moves one slot too.\n */\nfunction flowStep(parent: SceneNode, dx: number, dy: number): -1 | 0 | 1 {\n const along = parent.layoutMode === 'HORIZONTAL' ? dx : dy\n const visual =\n parent.layoutMode === 'HORIZONTAL' && parent.layoutDirection === 'RTL' ? -along : along\n if (visual === 0) return 0\n return visual > 0 ? 1 : -1\n}\n\n/**\n * The flow with each selected layer moved one slot by `step`; one already at the end of the\n * flow, or behind another selected layer that is, stays put.\n */\nfunction steppedFlow(\n flow: readonly string[],\n selected: ReadonlySet<string>,\n step: 1 | -1\n): string[] {\n const order = [...flow]\n const indices = step > 0 ? order.map((_, i) => order.length - 1 - i) : order.map((_, i) => i)\n for (const i of indices) {\n const j = i + step\n if (!selected.has(order[i]) || j < 0 || j >= order.length || selected.has(order[j])) continue\n ;[order[i], order[j]] = [order[j], order[i]]\n }\n return order\n}\n\nexport function createNudgeActions(ctx: EditorContext) {\n let nudgeOriginals: Map<string, Vector> | null = null\n let reorderOriginals: Map<string, string[]> | null = null\n let nudgeCommitTimer: ReturnType<typeof setTimeout> | null = null\n /** Open from the first key press until the nudge records its step, which waits for a pause. */\n let closeNudgeEdit: (() => void) | null = null\n\n function applyOrder(parentId: string, order: readonly string[]) {\n order.forEach((id, index) => ctx.graph.insertChildAt(id, parentId, index))\n ctx.runLayoutForNode(parentId)\n }\n\n function commitReorder() {\n if (!reorderOriginals) return\n const originals = reorderOriginals\n reorderOriginals = null\n const finals = new Map(\n [...originals.keys()].map((id) => [id, [...(ctx.graph.getNode(id)?.childIds ?? [])]])\n )\n if ([...originals].every(([id, order]) => isEqual(order, finals.get(id)))) return\n ctx.undo.push({\n label: 'Reorder',\n forward: () => {\n for (const [id, order] of finals) applyOrder(id, order)\n },\n inverse: () => {\n for (const [id, order] of originals) applyOrder(id, order)\n }\n })\n }\n\n function commitNudge() {\n nudgeCommitTimer = null\n try {\n commitReorder()\n commitMove()\n } finally {\n closeNudgeEdit?.()\n closeNudgeEdit = null\n }\n }\n\n function commitMove() {\n if (!nudgeOriginals) return\n const originals = nudgeOriginals\n nudgeOriginals = null\n\n const finals = collectNodePositions(ctx, originals.keys())\n const parentIds = [...originals.keys()].flatMap((id) => ctx.graph.getNode(id)?.parentId ?? [])\n // Groups and booleans fit their nudged children, in the same undo step.\n ctx.undo.runBatch('Nudge', () => {\n pushPositionUndo(ctx, 'Nudge', originals, finals)\n fitEnclosingGroupsWithUndo(ctx, parentIds)\n })\n ctx.requestRender()\n }\n\n /** Moves the selected layers in auto layout flows one slot; returns the layers it handled. */\n function reorderInFlows(movable: readonly string[], dx: number, dy: number): Set<string> {\n const byParent = new Map<string, Set<string>>()\n for (const id of movable) {\n const node = ctx.graph.getNode(id)\n const parent = node && flowParent(ctx, node)\n if (!parent) continue\n const selected = byParent.get(parent.id) ?? new Set<string>()\n selected.add(id)\n byParent.set(parent.id, selected)\n }\n const handled = new Set<string>()\n for (const [parentId, selected] of byParent) {\n for (const id of selected) handled.add(id)\n const parent = ctx.graph.getNode(parentId)\n const step = parent ? flowStep(parent, dx, dy) : 0\n if (!parent || step === 0) continue\n const children = ctx.graph.getChildren(parentId)\n const flowIds = children\n .filter((child) => child.layoutPositioning !== 'ABSOLUTE')\n .map((c) => c.id)\n const moved = steppedFlow(flowIds, selected, step)\n if (isEqual(moved, flowIds)) continue\n reorderOriginals ??= new Map()\n if (!reorderOriginals.has(parentId)) reorderOriginals.set(parentId, [...parent.childIds])\n // Layers that ignore the layout keep their places in the stack.\n let next = 0\n const order = children.map((child) =>\n child.layoutPositioning === 'ABSOLUTE' ? child.id : moved[next++]\n )\n applyOrder(parentId, order)\n }\n return handled\n }\n\n function nudgeSelected(dx: number, dy: number) {\n const ids = [...ctx.state.selectedIds]\n if (ids.length === 0) return\n\n const movable: string[] = []\n for (const id of ids) {\n const node = ctx.graph.getNode(id)\n if (node && !node.locked) movable.push(id)\n }\n if (movable.length === 0) return\n\n // The step waits for the keys to pause: hold the edit open until then, so the unsaved-changes\n // tracker takes the moves for that step's own.\n closeNudgeEdit ??= ctx.undo.openEdit()\n\n const reordered = reorderInFlows(movable, dx, dy)\n const nudged = movable.filter((id) => !reordered.has(id))\n\n // A run can span selection changes; each layer's start is recorded the first time it moves.\n if (nudged.length > 0) {\n nudgeOriginals ??= new Map()\n for (const id of nudged) {\n if (nudgeOriginals.has(id)) continue\n const node = ctx.graph.getNode(id)\n if (node) nudgeOriginals.set(id, { x: node.x, y: node.y })\n }\n }\n\n for (const id of nudged) {\n const node = ctx.graph.getNode(id)\n if (!node) continue\n ctx.graph.updateNode(id, { x: node.x + dx, y: node.y + dy })\n }\n\n if (nudgeCommitTimer) clearTimeout(nudgeCommitTimer)\n nudgeCommitTimer = setTimeout(commitNudge, NUDGE_COMMIT_DELAY)\n\n ctx.requestRender()\n }\n\n function flushNudge() {\n if (nudgeCommitTimer) {\n clearTimeout(nudgeCommitTimer)\n commitNudge()\n }\n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AS;EAErC,MAAM,YAAY,eAAe,SAAS,IAAI,EAAE;EAChD,MAAM,SAAS,QAAQ,QAAQ,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;EAGxD,IAAI,OAAO,SAAS,GAAG;GACrB,mCAAmB,IAAI,IAAI;GAC3B,KAAK,MAAM,MAAM,QAAQ;IACvB,IAAI,eAAe,IAAI,EAAE,GAAG;IAC5B,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;IACjC,IAAI,MAAM,eAAe,IAAI,IAAI;KAAE,GAAG,KAAK;KAAG,GAAG,KAAK;IAAE,CAAC;GAC3D;EACF;EAEA,KAAK,MAAM,MAAM,QAAQ;GACvB,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;GACjC,IAAI,CAAC,MAAM;GACX,IAAI,MAAM,WAAW,IAAI;IAAE,GAAG,KAAK,IAAI;IAAI,GAAG,KAAK,IAAI;GAAG,CAAC;EAC7D;EAEA,IAAI,kBAAkB,aAAa,gBAAgB;EACnD,mBAAmB,WAAW,aAAa,kBAAkB;EAE7D,IAAI,cAAc;CACpB;CAEA,SAAS,aAAa;EACpB,IAAI,kBAAkB;GACpB,aAAa,gBAAgB;GAC7B,YAAY;EACd;CACF;CAEA,OAAO;EAAE;EAAe;CAAW;AACrC"}
|
|
1
|
+
{"version":3,"file":"nudge.js","names":[],"sources":["../../src/editor/nudge.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { collectNodePositions, pushPositionUndo } from './history/position'\nimport { fitEnclosingGroupsWithUndo } from './structure/group/bounds'\nimport type { EditorContext } from './types'\n\nconst NUDGE_COMMIT_DELAY = 300\n\n/** The flow an arrow key moves a layer along: its row or column, or none. */\nfunction flowParent(ctx: EditorContext, node: SceneNode): SceneNode | null {\n if (node.layoutPositioning === 'ABSOLUTE' || !node.parentId) return null\n const parent = ctx.graph.getNode(node.parentId)\n return parent?.layoutMode === 'HORIZONTAL' || parent?.layoutMode === 'VERTICAL' ? parent : null\n}\n\n/**\n * One slot along the flow for an arrow key, as Figma reorders auto layout children: Right and\n * Left in a row (mirrored when it runs right to left), Down and Up in a column, and nothing for\n * the arrows across it. Shift moves one slot too.\n */\nfunction flowStep(parent: SceneNode, dx: number, dy: number): -1 | 0 | 1 {\n const along = parent.layoutMode === 'HORIZONTAL' ? dx : dy\n const visual =\n parent.layoutMode === 'HORIZONTAL' && parent.layoutDirection === 'RTL' ? -along : along\n if (visual === 0) return 0\n return visual > 0 ? 1 : -1\n}\n\n/**\n * The flow with each selected layer moved one slot by `step`; one already at the end of the\n * flow, or behind another selected layer that is, stays put.\n */\nfunction steppedFlow(\n flow: readonly string[],\n selected: ReadonlySet<string>,\n step: 1 | -1\n): string[] {\n const order = [...flow]\n const indices = step > 0 ? order.map((_, i) => order.length - 1 - i) : order.map((_, i) => i)\n for (const i of indices) {\n const j = i + step\n if (!selected.has(order[i]) || j < 0 || j >= order.length || selected.has(order[j])) continue\n ;[order[i], order[j]] = [order[j], order[i]]\n }\n return order\n}\n\nexport function createNudgeActions(ctx: EditorContext) {\n let nudgeOriginals: Map<string, Vector> | null = null\n let reorderOriginals: Map<string, string[]> | null = null\n let nudgeCommitTimer: ReturnType<typeof setTimeout> | null = null\n /** Open from the first key press until the nudge records its step, which waits for a pause. */\n let closeNudgeEdit: (() => void) | null = null\n\n function applyOrder(parentId: string, order: readonly string[]) {\n order.forEach((id, index) => ctx.graph.insertChildAt(id, parentId, index))\n ctx.runLayoutForParents([parentId])\n }\n\n function commitReorder() {\n if (!reorderOriginals) return\n const originals = reorderOriginals\n reorderOriginals = null\n const finals = new Map(\n [...originals.keys()].map((id) => [id, [...(ctx.graph.getNode(id)?.childIds ?? [])]])\n )\n if ([...originals].every(([id, order]) => isEqual(order, finals.get(id)))) return\n ctx.undo.push({\n label: 'Reorder',\n forward: () => {\n for (const [id, order] of finals) applyOrder(id, order)\n },\n inverse: () => {\n for (const [id, order] of originals) applyOrder(id, order)\n }\n })\n }\n\n function commitNudge() {\n nudgeCommitTimer = null\n try {\n commitReorder()\n commitMove()\n } finally {\n closeNudgeEdit?.()\n closeNudgeEdit = null\n }\n }\n\n function commitMove() {\n if (!nudgeOriginals) return\n const originals = nudgeOriginals\n nudgeOriginals = null\n\n const finals = collectNodePositions(ctx, originals.keys())\n const parentIds = [...originals.keys()].flatMap((id) => ctx.graph.getNode(id)?.parentId ?? [])\n // Groups and booleans fit their nudged children, in the same undo step.\n ctx.undo.runBatch('Nudge', () => {\n pushPositionUndo(ctx, 'Nudge', originals, finals)\n fitEnclosingGroupsWithUndo(ctx, parentIds)\n })\n ctx.requestRender()\n }\n\n /** Moves the selected layers in auto layout flows one slot; returns the layers it handled. */\n function reorderInFlows(movable: readonly string[], dx: number, dy: number): Set<string> {\n const byParent = new Map<string, Set<string>>()\n for (const id of movable) {\n const node = ctx.graph.getNode(id)\n const parent = node && flowParent(ctx, node)\n if (!parent) continue\n const selected = byParent.get(parent.id) ?? new Set<string>()\n selected.add(id)\n byParent.set(parent.id, selected)\n }\n const handled = new Set<string>()\n for (const [parentId, selected] of byParent) {\n for (const id of selected) handled.add(id)\n const parent = ctx.graph.getNode(parentId)\n const step = parent ? flowStep(parent, dx, dy) : 0\n if (!parent || step === 0) continue\n const children = ctx.graph.getChildren(parentId)\n const flowIds = children\n .filter((child) => child.layoutPositioning !== 'ABSOLUTE')\n .map((c) => c.id)\n const moved = steppedFlow(flowIds, selected, step)\n if (isEqual(moved, flowIds)) continue\n reorderOriginals ??= new Map()\n if (!reorderOriginals.has(parentId)) reorderOriginals.set(parentId, [...parent.childIds])\n // Layers that ignore the layout keep their places in the stack.\n let next = 0\n const order = children.map((child) =>\n child.layoutPositioning === 'ABSOLUTE' ? child.id : moved[next++]\n )\n applyOrder(parentId, order)\n }\n return handled\n }\n\n function nudgeSelected(dx: number, dy: number) {\n const ids = [...ctx.state.selectedIds]\n if (ids.length === 0) return\n\n const movable: string[] = []\n for (const id of ids) {\n const node = ctx.graph.getNode(id)\n if (node && !node.locked) movable.push(id)\n }\n if (movable.length === 0) return\n\n // The step waits for the keys to pause: hold the edit open until then, so the unsaved-changes\n // tracker takes the moves for that step's own.\n closeNudgeEdit ??= ctx.undo.openEdit()\n\n const reordered = reorderInFlows(movable, dx, dy)\n const nudged = movable.filter((id) => !reordered.has(id))\n\n // A run can span selection changes; each layer's start is recorded the first time it moves.\n if (nudged.length > 0) {\n nudgeOriginals ??= new Map()\n for (const id of nudged) {\n if (nudgeOriginals.has(id)) continue\n const node = ctx.graph.getNode(id)\n if (node) nudgeOriginals.set(id, { x: node.x, y: node.y })\n }\n }\n\n for (const id of nudged) {\n const node = ctx.graph.getNode(id)\n if (!node) continue\n ctx.graph.updateNode(id, { x: node.x + dx, y: node.y + dy })\n }\n\n if (nudgeCommitTimer) clearTimeout(nudgeCommitTimer)\n nudgeCommitTimer = setTimeout(commitNudge, NUDGE_COMMIT_DELAY)\n\n ctx.requestRender()\n }\n\n function flushNudge() {\n if (nudgeCommitTimer) {\n clearTimeout(nudgeCommitTimer)\n commitNudge()\n }\n }\n\n return { nudgeSelected, flushNudge }\n}\n"],"mappings":";;;;AASA,MAAM,qBAAqB;;AAG3B,SAAS,WAAW,KAAoB,MAAmC;CACzE,IAAI,KAAK,sBAAsB,cAAc,CAAC,KAAK,UAAU,OAAO;CACpE,MAAM,SAAS,IAAI,MAAM,QAAQ,KAAK,QAAQ;CAC9C,OAAO,QAAQ,eAAe,gBAAgB,QAAQ,eAAe,aAAa,SAAS;AAC7F;;;;;;AAOA,SAAS,SAAS,QAAmB,IAAY,IAAwB;CACvE,MAAM,QAAQ,OAAO,eAAe,eAAe,KAAK;CACxD,MAAM,SACJ,OAAO,eAAe,gBAAgB,OAAO,oBAAoB,QAAQ,CAAC,QAAQ;CACpF,IAAI,WAAW,GAAG,OAAO;CACzB,OAAO,SAAS,IAAI,IAAI;AAC1B;;;;;AAMA,SAAS,YACP,MACA,UACA,MACU;C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AAI;IAAI,GAAG,KAAK,IAAI;GAAG,CAAC;EAC7D;EAEA,IAAI,kBAAkB,aAAa,gBAAgB;EACnD,mBAAmB,WAAW,aAAa,kBAAkB;EAE7D,IAAI,cAAc;CACpB;CAEA,SAAS,aAAa;EACpB,IAAI,kBAAkB;GACpB,aAAa,gBAAgB;GAC7B,YAAY;EACd;CACF;CAEA,OAAO;EAAE;EAAe;CAAW;AACrC"}
|
package/dist/editor/pages.d.ts
CHANGED
|
@@ -25,11 +25,12 @@ interface PageDrawing {
|
|
|
25
25
|
}): Promise<void>;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* The other pages that
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* The component sets on other pages that instances on `pageId` show a variant of, nested
|
|
29
|
+
* instances included, and the sets those sets' variants use in turn. Reading a page brings in
|
|
30
|
+
* each such set whole, so its variants can be switched to; they get fonts and layout here
|
|
31
|
+
* rather than their pages, whose other layers the page does not use.
|
|
31
32
|
*/
|
|
32
|
-
declare function
|
|
33
|
+
declare function componentSetsUsed(graph: SceneGraph, pageId: string): string[];
|
|
33
34
|
declare function createPageActions(ctx: EditorContext, drawing?: PageDrawing): {
|
|
34
35
|
loadPageNodes: (pageId: string) => Promise<void>;
|
|
35
36
|
pageHoldingNode: (nodeId: string) => Promise<string | null>;
|
|
@@ -38,6 +39,7 @@ declare function createPageActions(ctx: EditorContext, drawing?: PageDrawing): {
|
|
|
38
39
|
preparePage: (pageId: string, options?: PreparePageOptions) => Promise<PreparedPage | null>;
|
|
39
40
|
commitPageSwitch: (prepared: PreparedPage) => boolean;
|
|
40
41
|
switchPage: (pageId: string, options?: SwitchPageOptions) => Promise<void>;
|
|
42
|
+
layOutStaleCurrentPage: () => void;
|
|
41
43
|
switchToNextPage: () => Promise<void>;
|
|
42
44
|
switchToPreviousPage: () => Promise<void>;
|
|
43
45
|
addPage: (name?: string) => string;
|
|
@@ -48,5 +50,5 @@ declare function createPageActions(ctx: EditorContext, drawing?: PageDrawing): {
|
|
|
48
50
|
clearPageViewports: () => void;
|
|
49
51
|
};
|
|
50
52
|
//#endregion
|
|
51
|
-
export { PageSwitchProgress, PreparePageOptions, PreparedPage, SwitchPageOptions,
|
|
53
|
+
export { PageSwitchProgress, PreparePageOptions, PreparedPage, SwitchPageOptions, componentSetsUsed, createPageActions };
|
|
52
54
|
//# sourceMappingURL=pages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pages.d.ts","names":[],"sources":["../../src/editor/pages.ts"],"mappings":";;;;UA+BiB;EACf;EAMA;EACA;EACA;;UAGe;EACf,cAAc,UAAU;EACxB,SAAS;;UAGM;EACf;EACA;;KAGU,oBAAoB;;UAQtB;EACR,qBACE,gBACA;IAAW,SAAS;IAAa,cAAc,UAAU;MACxD
|
|
1
|
+
{"version":3,"file":"pages.d.ts","names":[],"sources":["../../src/editor/pages.ts"],"mappings":";;;;UA+BiB;EACf;EAMA;EACA;EACA;;UAGe;EACf,cAAc,UAAU;EACxB,SAAS;;UAGM;EACf;EACA;;KAGU,oBAAoB;;UAQtB;EACR,qBACE,gBACA;IAAW,SAAS;IAAa,cAAc,UAAU;MACxD;;;;;;;;iBASW,kBAAkB,OAAO,YAAY;iBAoBrC,kBAAkB,KAAK,eAAe,UAAU;EAoMzB,gBAAA,mBAAS;EAKb,kBAAA,mBAAS;EAoBR,mBAAA,mBAAS;EAgKf;EAvQlB,cAAA,gBAAM,UACL,uBACR,QAAQ;EA8CyB,mBAAA,UAAA;EAmFF,aAAA,gBAAM,UAAW,sBAAyB;EA3FzC;;;EAkHX,UAAA;EAuCU,aAAA,mBAAM;EA0Bd,WAAA,gBAAM;EAqBJ,aAAA,gBAAM;EAYL,eAAA,OAAA"}
|