@pairdraw/core 0.17.0 → 0.19.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/effects.d.ts +5 -11
- package/dist/canvas/effects.d.ts.map +1 -1
- package/dist/canvas/effects.js +25 -30
- package/dist/canvas/effects.js.map +1 -1
- package/dist/canvas/labels/hit-test.d.ts +5 -0
- package/dist/canvas/labels/hit-test.d.ts.map +1 -1
- package/dist/canvas/labels/hit-test.js +1 -1
- package/dist/canvas/labels/hit-test.js.map +1 -1
- package/dist/canvas/labels/paragraph-cache.d.ts.map +1 -1
- package/dist/canvas/labels/paragraph-cache.js +3 -2
- package/dist/canvas/labels/paragraph-cache.js.map +1 -1
- package/dist/canvas/labels/selection.js +3 -2
- package/dist/canvas/labels/selection.js.map +1 -1
- package/dist/canvas/labels/style.d.ts +1 -1
- package/dist/canvas/node-edit-overlay.js +2 -2
- package/dist/canvas/node-edit-overlay.js.map +1 -1
- package/dist/canvas/outline-stroke.d.ts.map +1 -1
- package/dist/canvas/outline-stroke.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/prototype.d.ts +2 -5
- package/dist/canvas/overlays/prototype.d.ts.map +1 -1
- package/dist/canvas/overlays/prototype.js +3 -19
- package/dist/canvas/overlays/prototype.js.map +1 -1
- 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 +4 -37
- package/dist/canvas/overlays/selection.js.map +1 -1
- package/dist/canvas/region-hatch.js +3 -2
- package/dist/canvas/region-hatch.js.map +1 -1
- package/dist/canvas/renderer/colors.d.ts.map +1 -1
- package/dist/canvas/renderer/colors.js +36 -18
- package/dist/canvas/renderer/colors.js.map +1 -1
- package/dist/canvas/renderer/font-waiters.d.ts +9 -0
- package/dist/canvas/renderer/font-waiters.d.ts.map +1 -0
- package/dist/canvas/renderer/font-waiters.js +26 -0
- package/dist/canvas/renderer/font-waiters.js.map +1 -0
- package/dist/canvas/renderer/fonts.d.ts +4 -2
- package/dist/canvas/renderer/fonts.d.ts.map +1 -1
- package/dist/canvas/renderer/fonts.js +25 -10
- 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 -9
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts +4 -5
- 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/paints.d.ts.map +1 -1
- package/dist/canvas/renderer/paints.js +0 -6
- package/dist/canvas/renderer/paints.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +20 -2
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/retained-backing.js +4 -4
- package/dist/canvas/renderer/retained-backing.js.map +1 -1
- package/dist/canvas/renderer/state.js +1 -1
- package/dist/canvas/renderer/state.js.map +1 -1
- package/dist/canvas/renderer/tiles/controller.d.ts +2 -0
- package/dist/canvas/renderer/tiles/controller.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/controller.js +8 -0
- package/dist/canvas/renderer/tiles/controller.js.map +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.js +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.js.map +1 -1
- package/dist/canvas/renderer/visual-bounds.d.ts.map +1 -1
- package/dist/canvas/renderer/visual-bounds.js +7 -5
- package/dist/canvas/renderer/visual-bounds.js.map +1 -1
- package/dist/canvas/renderer.d.ts +26 -7
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +50 -11
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/rulers.d.ts +8 -1
- package/dist/canvas/rulers.d.ts.map +1 -1
- package/dist/canvas/rulers.js +30 -5
- package/dist/canvas/rulers.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 +90 -54
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/shadows/shape.js +1 -1
- package/dist/canvas/shadows/shape.js.map +1 -1
- package/dist/canvas/shadows/silhouette.d.ts.map +1 -1
- package/dist/canvas/shadows/silhouette.js +4 -2
- package/dist/canvas/shadows/silhouette.js.map +1 -1
- package/dist/canvas/shadows.d.ts.map +1 -1
- package/dist/canvas/shadows.js +3 -2
- package/dist/canvas/shadows.js.map +1 -1
- package/dist/canvas/text/derived.d.ts +1 -2
- package/dist/canvas/text/derived.d.ts.map +1 -1
- package/dist/canvas/text/derived.js +1 -7
- package/dist/canvas/text/derived.js.map +1 -1
- package/dist/canvas/text/emoji/index.js +1 -1
- package/dist/canvas/text/emoji/raster.d.ts.map +1 -1
- package/dist/canvas/text/emoji/raster.js +14 -10
- package/dist/canvas/text/emoji/raster.js.map +1 -1
- package/dist/canvas/text/font-families.d.ts +4 -3
- package/dist/canvas/text/font-families.d.ts.map +1 -1
- package/dist/canvas/text/font-families.js +13 -9
- package/dist/canvas/text/font-families.js.map +1 -1
- package/dist/canvas/text/index.d.ts +1 -3
- package/dist/canvas/text/index.d.ts.map +1 -1
- package/dist/canvas/text/index.js +2 -9
- package/dist/canvas/text/index.js.map +1 -1
- package/dist/canvas/text/layout/build.d.ts.map +1 -1
- package/dist/canvas/text/layout/build.js +25 -9
- package/dist/canvas/text/layout/build.js.map +1 -1
- package/dist/canvas/text/layout/index.d.ts.map +1 -1
- package/dist/canvas/text/layout/index.js +8 -4
- package/dist/canvas/text/layout/index.js.map +1 -1
- package/dist/canvas/text/layout/lines.js +5 -3
- package/dist/canvas/text/layout/lines.js.map +1 -1
- package/dist/canvas/text/paragraph/index.d.ts +5 -0
- package/dist/canvas/text/paragraph/index.d.ts.map +1 -1
- package/dist/canvas/text/paragraph/index.js +18 -9
- package/dist/canvas/text/paragraph/index.js.map +1 -1
- package/dist/canvas/text/paragraph/inputs.d.ts +1 -1
- package/dist/canvas/text/paragraph/inputs.d.ts.map +1 -1
- package/dist/canvas/text/paragraph/inputs.js +9 -2
- package/dist/canvas/text/paragraph/inputs.js.map +1 -1
- package/dist/canvas/text/placed.js +3 -3
- package/dist/canvas/text/placed.js.map +1 -1
- package/dist/canvas/text/renderer.d.ts +2 -0
- package/dist/canvas/text/renderer.d.ts.map +1 -1
- package/dist/canvas/text/shape.d.ts +4 -3
- package/dist/canvas/text/shape.d.ts.map +1 -1
- package/dist/canvas/text/shape.js +9 -22
- package/dist/canvas/text/shape.js.map +1 -1
- package/dist/constants.d.ts +6 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +6 -2
- package/dist/constants.js.map +1 -1
- package/dist/design-jsx/renderer.d.ts.map +1 -1
- package/dist/editor/bridges/clipboard.d.ts +1 -0
- package/dist/editor/bridges/clipboard.js +1 -0
- package/dist/editor/bridges/clipboard.js.map +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/frames.d.ts +4 -3
- package/dist/editor/bridges/frames.d.ts.map +1 -1
- package/dist/editor/bridges/frames.js +6 -4
- package/dist/editor/bridges/frames.js.map +1 -1
- package/dist/editor/bridges/structure.d.ts +1 -0
- package/dist/editor/bridges/structure.d.ts.map +1 -1
- package/dist/editor/bridges/structure.js +1 -0
- package/dist/editor/bridges/structure.js.map +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/clipboard/detach.js +2 -2
- package/dist/editor/clipboard/detach.js.map +1 -1
- package/dist/editor/clipboard/paste/properties.js +1 -1
- package/dist/editor/clipboard/paste/target.js +2 -2
- package/dist/editor/clipboard/paste/target.js.map +1 -1
- package/dist/editor/clipboard/snapshot.d.ts +3 -0
- package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
- package/dist/editor/clipboard/snapshot.js +2 -0
- package/dist/editor/clipboard/snapshot.js.map +1 -1
- package/dist/editor/clipboard/variables.d.ts.map +1 -1
- package/dist/editor/clipboard/variables.js +14 -1
- package/dist/editor/clipboard/variables.js.map +1 -1
- package/dist/editor/clipboard.d.ts +1 -0
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +122 -16
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/component-sync.d.ts +10 -1
- package/dist/editor/component-sync.d.ts.map +1 -1
- package/dist/editor/component-sync.js +25 -8
- package/dist/editor/component-sync.js.map +1 -1
- package/dist/editor/components/authoring/text-edit.d.ts.map +1 -1
- package/dist/editor/components/authoring/text-edit.js +11 -2
- package/dist/editor/components/authoring/text-edit.js.map +1 -1
- package/dist/editor/components/authoring/visibility-edit.d.ts.map +1 -1
- package/dist/editor/components/authoring/visibility-edit.js +7 -3
- package/dist/editor/components/authoring/visibility-edit.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 +37 -7
- package/dist/editor/components/instances.js.map +1 -1
- package/dist/editor/components/properties.d.ts.map +1 -1
- package/dist/editor/components/properties.js +3 -0
- package/dist/editor/components/properties.js.map +1 -1
- package/dist/editor/components/slots/authoring.js +2 -1
- package/dist/editor/components/slots/authoring.js.map +1 -1
- package/dist/editor/components.d.ts +2 -0
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor/create.d.ts +18 -4
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +43 -6
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/guides.d.ts.map +1 -1
- package/dist/editor/guides.js +20 -13
- package/dist/editor/guides.js.map +1 -1
- package/dist/editor/history/document-change.d.ts +19 -3
- package/dist/editor/history/document-change.d.ts.map +1 -1
- package/dist/editor/history/document-change.js +94 -8
- package/dist/editor/history/document-change.js.map +1 -1
- package/dist/editor/history/edit.d.ts.map +1 -1
- package/dist/editor/history/edit.js +56 -12
- package/dist/editor/history/edit.js.map +1 -1
- package/dist/editor/history/position.js +1 -4
- package/dist/editor/history/position.js.map +1 -1
- package/dist/editor/history/sources.d.ts +14 -0
- package/dist/editor/history/sources.d.ts.map +1 -0
- package/dist/editor/history/sources.js +24 -0
- package/dist/editor/history/sources.js.map +1 -0
- package/dist/editor/index.d.ts +2 -2
- package/dist/editor/index.js +1 -1
- package/dist/editor/layout-mode.d.ts.map +1 -1
- package/dist/editor/layout-mode.js +16 -1
- package/dist/editor/layout-mode.js.map +1 -1
- package/dist/editor/node-preview.d.ts.map +1 -1
- package/dist/editor/node-preview.js +26 -7
- package/dist/editor/node-preview.js.map +1 -1
- package/dist/editor/nodes.d.ts.map +1 -1
- package/dist/editor/nodes.js +33 -10
- package/dist/editor/nodes.js.map +1 -1
- package/dist/editor/nudge.d.ts.map +1 -1
- package/dist/editor/nudge.js +12 -2
- package/dist/editor/nudge.js.map +1 -1
- package/dist/editor/pages.d.ts +2 -1
- package/dist/editor/pages.d.ts.map +1 -1
- package/dist/editor/pages.js +94 -15
- package/dist/editor/pages.js.map +1 -1
- package/dist/editor/play/states.d.ts.map +1 -1
- package/dist/editor/play/states.js +0 -5
- package/dist/editor/play/states.js.map +1 -1
- package/dist/editor/read-only/actions.js +3 -0
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/selection/hit-test.d.ts +2 -1
- package/dist/editor/selection/hit-test.d.ts.map +1 -1
- package/dist/editor/selection/hit-test.js +29 -4
- package/dist/editor/selection/hit-test.js.map +1 -1
- package/dist/editor/selection.d.ts +2 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/shapes/pen.js +6 -2
- package/dist/editor/shapes/pen.js.map +1 -1
- package/dist/editor/shapes.d.ts.map +1 -1
- package/dist/editor/shapes.js +2 -1
- package/dist/editor/shapes.js.map +1 -1
- package/dist/editor/structure/auto-layout-wrap.d.ts.map +1 -1
- package/dist/editor/structure/auto-layout-wrap.js +12 -0
- package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
- package/dist/editor/structure/boolean.js +1 -1
- package/dist/editor/structure/group/bounds.d.ts +4 -2
- package/dist/editor/structure/group/bounds.d.ts.map +1 -1
- package/dist/editor/structure/group/bounds.js +17 -4
- package/dist/editor/structure/group/bounds.js.map +1 -1
- package/dist/editor/structure/rename.d.ts +2 -3
- package/dist/editor/structure/rename.d.ts.map +1 -1
- package/dist/editor/structure/rename.js +2 -5
- package/dist/editor/structure/rename.js.map +1 -1
- package/dist/editor/structure/reorder.d.ts.map +1 -1
- package/dist/editor/structure/reorder.js +20 -9
- package/dist/editor/structure/reorder.js.map +1 -1
- package/dist/editor/structure/state.js +1 -1
- package/dist/editor/structure.d.ts +1 -0
- package/dist/editor/structure.d.ts.map +1 -1
- package/dist/editor/structure.js +76 -20
- package/dist/editor/structure.js.map +1 -1
- package/dist/editor/text/hyperlink.d.ts.map +1 -1
- package/dist/editor/text/hyperlink.js +1 -1
- package/dist/editor/text/hyperlink.js.map +1 -1
- package/dist/editor/text/name.d.ts +13 -5
- package/dist/editor/text/name.d.ts.map +1 -1
- package/dist/editor/text/name.js +47 -17
- package/dist/editor/text/name.js.map +1 -1
- package/dist/editor/text/pending-layout.d.ts +2 -1
- package/dist/editor/text/pending-layout.d.ts.map +1 -1
- package/dist/editor/text/pending-layout.js +33 -6
- package/dist/editor/text/pending-layout.js.map +1 -1
- package/dist/editor/text/selection-style.d.ts +1 -0
- package/dist/editor/text/selection-style.d.ts.map +1 -1
- package/dist/editor/text/selection-style.js +16 -4
- package/dist/editor/text/selection-style.js.map +1 -1
- package/dist/editor/text.d.ts +5 -0
- package/dist/editor/text.d.ts.map +1 -1
- package/dist/editor/text.js +70 -3
- package/dist/editor/text.js.map +1 -1
- package/dist/editor/types.d.ts +18 -1
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/undo.d.ts.map +1 -1
- package/dist/editor/undo.js +14 -2
- package/dist/editor/undo.js.map +1 -1
- package/dist/editor/variable-bindings.d.ts.map +1 -1
- package/dist/editor/variable-bindings.js +21 -2
- package/dist/editor/variable-bindings.js.map +1 -1
- package/dist/editor/variables.d.ts +1 -1
- package/dist/editor/variables.d.ts.map +1 -1
- package/dist/editor/variables.js +7 -8
- package/dist/editor/variables.js.map +1 -1
- package/dist/editor/viewport.d.ts +11 -2
- package/dist/editor/viewport.d.ts.map +1 -1
- package/dist/editor/viewport.js +61 -21
- package/dist/editor/viewport.js.map +1 -1
- package/dist/editor/views/actions.d.ts.map +1 -1
- package/dist/editor/views/actions.js +13 -5
- package/dist/editor/views/actions.js.map +1 -1
- package/dist/editor/views/present.d.ts +6 -4
- package/dist/editor/views/present.d.ts.map +1 -1
- package/dist/editor/views/present.js +12 -10
- package/dist/editor/views/present.js.map +1 -1
- package/dist/editor/views/types.d.ts +11 -5
- package/dist/editor/views/types.d.ts.map +1 -1
- package/dist/figma-api/accessor-utils.d.ts.map +1 -1
- package/dist/figma-api/accessor-utils.js +4 -1
- package/dist/figma-api/accessor-utils.js.map +1 -1
- package/dist/figma-api/accessors/basic.d.ts.map +1 -1
- package/dist/figma-api/accessors/basic.js +41 -21
- package/dist/figma-api/accessors/basic.js.map +1 -1
- package/dist/figma-api/accessors/layout.d.ts.map +1 -1
- package/dist/figma-api/accessors/layout.js +37 -7
- package/dist/figma-api/accessors/layout.js.map +1 -1
- package/dist/figma-api/accessors/reactions.d.ts +11 -0
- package/dist/figma-api/accessors/reactions.d.ts.map +1 -0
- package/dist/figma-api/accessors/reactions.js +30 -0
- package/dist/figma-api/accessors/reactions.js.map +1 -0
- package/dist/figma-api/accessors/strokes.d.ts.map +1 -1
- package/dist/figma-api/accessors/strokes.js +12 -4
- package/dist/figma-api/accessors/strokes.js.map +1 -1
- package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
- package/dist/figma-api/accessors/text/index.js +3 -1
- package/dist/figma-api/accessors/text/index.js.map +1 -1
- package/dist/figma-api/accessors/vector.d.ts.map +1 -1
- package/dist/figma-api/accessors/vector.js +1 -1
- package/dist/figma-api/accessors/vector.js.map +1 -1
- package/dist/figma-api/accessors/visual.d.ts +6 -5
- package/dist/figma-api/accessors/visual.d.ts.map +1 -1
- package/dist/figma-api/accessors/visual.js +20 -17
- package/dist/figma-api/accessors/visual.js.map +1 -1
- package/dist/figma-api/components.d.ts.map +1 -1
- package/dist/figma-api/components.js +2 -1
- package/dist/figma-api/components.js.map +1 -1
- package/dist/figma-api/finite.d.ts +27 -0
- package/dist/figma-api/finite.d.ts.map +1 -0
- package/dist/figma-api/finite.js +69 -0
- package/dist/figma-api/finite.js.map +1 -0
- package/dist/figma-api/fonts/list.d.ts +13 -0
- package/dist/figma-api/fonts/list.d.ts.map +1 -0
- package/dist/figma-api/fonts/list.js +25 -0
- package/dist/figma-api/fonts/list.js.map +1 -0
- package/dist/figma-api/index.d.ts +63 -10
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +104 -17
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/overrides.d.ts +6 -1
- package/dist/figma-api/overrides.d.ts.map +1 -1
- package/dist/figma-api/overrides.js +2 -2
- package/dist/figma-api/overrides.js.map +1 -1
- package/dist/figma-api/pending-layout.d.ts +12 -2
- package/dist/figma-api/pending-layout.d.ts.map +1 -1
- package/dist/figma-api/pending-layout.js +41 -1
- package/dist/figma-api/pending-layout.js.map +1 -1
- package/dist/figma-api/pending-sync.d.ts +19 -0
- package/dist/figma-api/pending-sync.d.ts.map +1 -0
- package/dist/figma-api/pending-sync.js +52 -0
- package/dist/figma-api/pending-sync.js.map +1 -0
- package/dist/figma-api/proxy.d.ts +15 -2
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +23 -3
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +104 -0
- package/dist/figma-api/reactions.d.ts.map +1 -0
- package/dist/figma-api/reactions.js +157 -0
- package/dist/figma-api/reactions.js.map +1 -0
- package/dist/figma-api/render-bounds.d.ts.map +1 -1
- package/dist/figma-api/render-bounds.js +4 -4
- package/dist/figma-api/render-bounds.js.map +1 -1
- package/dist/figma-api/serialization.js +12 -2
- package/dist/figma-api/serialization.js.map +1 -1
- package/dist/figma-api/slots.d.ts +7 -1
- package/dist/figma-api/slots.d.ts.map +1 -1
- package/dist/figma-api/slots.js +12 -4
- package/dist/figma-api/slots.js.map +1 -1
- package/dist/figma-api/strokes.d.ts +5 -2
- package/dist/figma-api/strokes.d.ts.map +1 -1
- package/dist/figma-api/strokes.js +12 -19
- package/dist/figma-api/strokes.js.map +1 -1
- package/dist/figma-api/text/bindings.js +1 -1
- package/dist/figma-api/text/index.d.ts +2 -3
- package/dist/figma-api/text/index.d.ts.map +1 -1
- package/dist/figma-api/text/index.js +2 -12
- package/dist/figma-api/text/index.js.map +1 -1
- package/dist/figma-api/variables/bindings.js +1 -1
- package/dist/figma-api/variables/variable.d.ts.map +1 -1
- package/dist/figma-api/variables/variable.js +2 -2
- package/dist/figma-api/variables/variable.js.map +1 -1
- package/dist/geometry/connectors.js +2 -14
- package/dist/geometry/connectors.js.map +1 -1
- package/dist/geometry/figma.d.ts +6 -1
- package/dist/geometry/figma.d.ts.map +1 -1
- package/dist/geometry/figma.js +8 -1
- package/dist/geometry/figma.js.map +1 -1
- package/dist/geometry/index.d.ts +3 -3
- package/dist/geometry/index.js +2 -2
- package/dist/geometry/scene.d.ts +3 -1
- package/dist/geometry/scene.d.ts.map +1 -1
- package/dist/geometry/scene.js +16 -1
- package/dist/geometry/scene.js.map +1 -1
- package/dist/geometry/types.d.ts +7 -1
- package/dist/geometry/types.d.ts.map +1 -1
- package/dist/icons/api.d.ts +3 -2
- package/dist/icons/api.d.ts.map +1 -1
- package/dist/icons/api.js +12 -12
- package/dist/icons/api.js.map +1 -1
- package/dist/icons/provider.d.ts +4 -3
- package/dist/icons/provider.d.ts.map +1 -1
- package/dist/icons/provider.js +6 -13
- package/dist/icons/provider.js.map +1 -1
- package/dist/icons/schema.d.ts +33 -1
- package/dist/icons/schema.d.ts.map +1 -1
- package/dist/icons/schema.js +30 -1
- package/dist/icons/schema.js.map +1 -1
- package/dist/icons/svg/presentation.d.ts +8 -1
- package/dist/icons/svg/presentation.d.ts.map +1 -1
- package/dist/icons/svg/presentation.js +21 -3
- package/dist/icons/svg/presentation.js.map +1 -1
- package/dist/icons/svg/text.js +1 -1
- package/dist/icons/svg/text.js.map +1 -1
- package/dist/icons/svg.d.ts +8 -3
- package/dist/icons/svg.d.ts.map +1 -1
- package/dist/icons/svg.js +15 -13
- package/dist/icons/svg.js.map +1 -1
- package/dist/icons/types.d.ts +1 -19
- package/dist/icons/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/io/formats/design-tokens/css/read.js +1 -1
- package/dist/io/formats/design-tokens/decode.js +1 -1
- package/dist/io/formats/design-tokens/plan/index.js +4 -2
- package/dist/io/formats/design-tokens/plan/index.js.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.d.ts +9 -1
- package/dist/io/formats/design-tokens/plan/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.js +23 -3
- package/dist/io/formats/design-tokens/plan/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/styles.d.ts +9 -1
- package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/styles.js +41 -4
- package/dist/io/formats/design-tokens/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/types.d.ts +5 -0
- package/dist/io/formats/design-tokens/types.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/types.js +1 -0
- package/dist/io/formats/design-tokens/types.js.map +1 -1
- package/dist/io/formats/drawio/export.d.ts.map +1 -1
- package/dist/io/formats/drawio/export.js +10 -0
- 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 +32 -1
- package/dist/io/formats/drawio/index.js.map +1 -1
- package/dist/io/formats/drawio/shapes.d.ts +10 -5
- package/dist/io/formats/drawio/shapes.d.ts.map +1 -1
- package/dist/io/formats/drawio/shapes.js +10 -6
- package/dist/io/formats/drawio/shapes.js.map +1 -1
- package/dist/io/formats/drawio/warnings.d.ts +11 -0
- package/dist/io/formats/drawio/warnings.d.ts.map +1 -0
- package/dist/io/formats/drawio/warnings.js +23 -0
- package/dist/io/formats/drawio/warnings.js.map +1 -0
- package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
- package/dist/io/formats/fig/export/setup.js +8 -4
- package/dist/io/formats/fig/export/setup.js.map +1 -1
- package/dist/io/formats/fig/export/variables.d.ts.map +1 -1
- package/dist/io/formats/fig/export/variables.js +2 -2
- package/dist/io/formats/fig/export/variables.js.map +1 -1
- package/dist/io/formats/fig/index.d.ts +2 -2
- package/dist/io/formats/fig/index.js +2 -2
- package/dist/io/formats/fig/read.d.ts +9 -2
- package/dist/io/formats/fig/read.d.ts.map +1 -1
- package/dist/io/formats/fig/read.js +44 -20
- package/dist/io/formats/fig/read.js.map +1 -1
- package/dist/io/formats/html/index.d.ts.map +1 -1
- package/dist/io/formats/html/index.js +2 -6
- package/dist/io/formats/html/index.js.map +1 -1
- package/dist/io/formats/pdf/dom.d.ts +10 -1
- package/dist/io/formats/pdf/dom.d.ts.map +1 -1
- package/dist/io/formats/pdf/dom.js +96 -2
- package/dist/io/formats/pdf/dom.js.map +1 -1
- package/dist/io/formats/pdf/export.js +3 -2
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/pdf/prepare.js +1 -1
- package/dist/io/formats/pen/fonts.d.ts +14 -0
- package/dist/io/formats/pen/fonts.d.ts.map +1 -0
- package/dist/io/formats/pen/fonts.js +39 -0
- package/dist/io/formats/pen/fonts.js.map +1 -0
- package/dist/io/formats/pen/index.d.ts.map +1 -1
- package/dist/io/formats/pen/index.js +25 -6
- package/dist/io/formats/pen/index.js.map +1 -1
- package/dist/io/formats/raster/headless.d.ts +3 -3
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +25 -14
- package/dist/io/formats/raster/headless.js.map +1 -1
- package/dist/io/formats/raster/index.d.ts +2 -2
- package/dist/io/formats/raster/index.js +2 -2
- package/dist/io/formats/raster/render.d.ts +8 -2
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +42 -8
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +28 -24
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/paths.d.ts +8 -2
- package/dist/io/formats/svg/paths.d.ts.map +1 -1
- package/dist/io/formats/svg/paths.js +11 -3
- package/dist/io/formats/svg/paths.js.map +1 -1
- package/dist/io/formats/svg/strokes.d.ts.map +1 -1
- package/dist/io/formats/svg/strokes.js +2 -5
- package/dist/io/formats/svg/strokes.js.map +1 -1
- package/dist/io/formats/svg/text/export.d.ts.map +1 -1
- package/dist/io/formats/svg/text/export.js +19 -1
- package/dist/io/formats/svg/text/export.js.map +1 -1
- package/dist/io/formats/svg/text/import.d.ts.map +1 -1
- package/dist/io/formats/svg/text/import.js +2 -1
- package/dist/io/formats/svg/text/import.js.map +1 -1
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +3 -1
- package/dist/io/formats.js.map +1 -1
- package/dist/io/registry.d.ts +2 -0
- package/dist/io/registry.d.ts.map +1 -1
- package/dist/io/registry.js +5 -0
- package/dist/io/registry.js.map +1 -1
- package/dist/io/subgraph.d.ts.map +1 -1
- package/dist/io/subgraph.js +5 -2
- package/dist/io/subgraph.js.map +1 -1
- package/dist/io/types.d.ts +2 -0
- package/dist/io/types.d.ts.map +1 -1
- package/dist/kiwi/fig/population/client.d.ts.map +1 -1
- package/dist/kiwi/fig/population/client.js +63 -45
- package/dist/kiwi/fig/population/client.js.map +1 -1
- package/dist/kiwi/fig/population/delta.d.ts +34 -3
- package/dist/kiwi/fig/population/delta.d.ts.map +1 -1
- package/dist/kiwi/fig/population/delta.js +99 -16
- package/dist/kiwi/fig/population/delta.js.map +1 -1
- package/dist/kiwi/fig/population/edits.d.ts +51 -0
- package/dist/kiwi/fig/population/edits.d.ts.map +1 -0
- package/dist/kiwi/fig/population/edits.js +169 -0
- package/dist/kiwi/fig/population/edits.js.map +1 -0
- package/dist/kiwi/fig/session/archive/access.d.ts +3 -0
- package/dist/kiwi/fig/session/archive/access.d.ts.map +1 -1
- package/dist/kiwi/fig/session/archive/access.js +8 -1
- package/dist/kiwi/fig/session/archive/access.js.map +1 -1
- package/dist/kiwi/fig/session/archive/changes.d.ts +2 -1
- package/dist/kiwi/fig/session/archive/changes.d.ts.map +1 -1
- package/dist/kiwi/fig/session/archive/changes.js +12 -5
- package/dist/kiwi/fig/session/archive/changes.js.map +1 -1
- package/dist/kiwi/fig/session/document-state.d.ts +7 -1
- package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
- package/dist/kiwi/fig/session/document-state.js +16 -2
- package/dist/kiwi/fig/session/document-state.js.map +1 -1
- package/dist/kiwi/fig/session/protocol.d.ts +31 -3
- package/dist/kiwi/fig/session/protocol.d.ts.map +1 -1
- package/dist/kiwi/fig/session/worker.js +33 -8
- package/dist/kiwi/fig/session/worker.js.map +1 -1
- package/dist/layout/apply.d.ts +6 -1
- package/dist/layout/apply.d.ts.map +1 -1
- package/dist/layout/apply.js +39 -14
- package/dist/layout/apply.js.map +1 -1
- package/dist/layout/arrange/boxes.d.ts.map +1 -1
- package/dist/layout/arrange/boxes.js +31 -0
- package/dist/layout/arrange/boxes.js.map +1 -1
- package/dist/layout/flow-edges.d.ts +26 -0
- package/dist/layout/flow-edges.d.ts.map +1 -0
- package/dist/layout/flow-edges.js +105 -0
- package/dist/layout/flow-edges.js.map +1 -0
- package/dist/layout/grid.d.ts.map +1 -1
- package/dist/layout/grid.js +9 -5
- package/dist/layout/grid.js.map +1 -1
- package/dist/layout/text-auto-resize.d.ts.map +1 -1
- package/dist/layout/text-auto-resize.js +9 -4
- package/dist/layout/text-auto-resize.js.map +1 -1
- package/dist/layout/text-measurement.d.ts +15 -1
- package/dist/layout/text-measurement.d.ts.map +1 -1
- package/dist/layout/text-measurement.js +40 -4
- package/dist/layout/text-measurement.js.map +1 -1
- package/dist/layout/variables.d.ts +1 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +35 -35
- package/dist/layout.js.map +1 -1
- package/dist/library/asset-keys.d.ts +3 -2
- package/dist/library/asset-keys.d.ts.map +1 -1
- package/dist/library/asset-keys.js +4 -3
- package/dist/library/asset-keys.js.map +1 -1
- package/dist/library/copied-references.d.ts +8 -3
- package/dist/library/copied-references.d.ts.map +1 -1
- package/dist/library/copied-references.js +15 -5
- package/dist/library/copied-references.js.map +1 -1
- package/dist/library/materialize.js +1 -1
- package/dist/library/materialize.js.map +1 -1
- package/dist/library/schema.js.map +1 -1
- package/dist/library/snapshot.d.ts.map +1 -1
- package/dist/library/snapshot.js +11 -2
- package/dist/library/snapshot.js.map +1 -1
- package/dist/lint/linter.d.ts.map +1 -1
- package/dist/lint/linter.js +11 -2
- package/dist/lint/linter.js.map +1 -1
- package/dist/pairdraw-api/variables.d.ts.map +1 -1
- package/dist/pairdraw-api/variables.js +0 -2
- package/dist/pairdraw-api/variables.js.map +1 -1
- package/dist/profiler/hud-controller.d.ts +4 -3
- package/dist/profiler/hud-controller.d.ts.map +1 -1
- package/dist/profiler/hud-controller.js +7 -5
- package/dist/profiler/hud-controller.js.map +1 -1
- package/dist/profiler/hud-renderer.d.ts +5 -2
- package/dist/profiler/hud-renderer.d.ts.map +1 -1
- package/dist/profiler/hud-renderer.js +8 -5
- package/dist/profiler/hud-renderer.js.map +1 -1
- package/dist/profiler/render-profiler.d.ts +3 -2
- package/dist/profiler/render-profiler.d.ts.map +1 -1
- package/dist/profiler/render-profiler.js +3 -2
- package/dist/profiler/render-profiler.js.map +1 -1
- package/dist/rpc/variables-command.d.ts.map +1 -1
- package/dist/rpc/variables-command.js +4 -2
- package/dist/rpc/variables-command.js.map +1 -1
- package/dist/text/character-style.d.ts +11 -1
- package/dist/text/character-style.d.ts.map +1 -1
- package/dist/text/character-style.js +27 -5
- package/dist/text/character-style.js.map +1 -1
- package/dist/text/coverage.d.ts.map +1 -1
- package/dist/text/coverage.js +16 -14
- package/dist/text/coverage.js.map +1 -1
- package/dist/text/editor.d.ts.map +1 -1
- package/dist/text/editor.js +3 -8
- package/dist/text/editor.js.map +1 -1
- package/dist/text/fallbacks.d.ts +26 -3
- package/dist/text/fallbacks.d.ts.map +1 -1
- package/dist/text/fallbacks.js +135 -18
- package/dist/text/fallbacks.js.map +1 -1
- package/dist/text/font/catalog.d.ts +4 -0
- package/dist/text/font/catalog.d.ts.map +1 -1
- package/dist/text/font/catalog.js +8 -0
- package/dist/text/font/catalog.js.map +1 -1
- package/dist/text/font/collection.d.ts +13 -0
- package/dist/text/font/collection.d.ts.map +1 -0
- package/dist/text/font/collection.js +51 -0
- package/dist/text/font/collection.js.map +1 -0
- package/dist/text/font/faces.d.ts +2 -1
- package/dist/text/font/faces.d.ts.map +1 -1
- package/dist/text/font/faces.js +9 -5
- package/dist/text/font/faces.js.map +1 -1
- package/dist/text/font/glyphs.d.ts +14 -3
- package/dist/text/font/glyphs.d.ts.map +1 -1
- package/dist/text/font/glyphs.js +22 -5
- package/dist/text/font/glyphs.js.map +1 -1
- package/dist/text/font/local.js +2 -2
- package/dist/text/font/local.js.map +1 -1
- package/dist/text/font/manager.d.ts +50 -6
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +178 -32
- package/dist/text/font/manager.js.map +1 -1
- package/dist/text/font/style.d.ts +7 -2
- package/dist/text/font/style.d.ts.map +1 -1
- package/dist/text/font/style.js +31 -3
- package/dist/text/font/style.js.map +1 -1
- package/dist/text/index.d.ts +5 -4
- package/dist/text/index.js +5 -4
- package/dist/text/outlines.d.ts.map +1 -1
- package/dist/text/outlines.js +71 -71
- package/dist/text/outlines.js.map +1 -1
- package/dist/text/path/caret.d.ts +2 -4
- package/dist/text/path/caret.d.ts.map +1 -1
- package/dist/text/path/caret.js.map +1 -1
- package/dist/text/prepare.d.ts +5 -1
- package/dist/text/prepare.d.ts.map +1 -1
- package/dist/text/prepare.js +26 -3
- package/dist/text/prepare.js.map +1 -1
- package/dist/text/style-runs.d.ts +14 -2
- package/dist/text/style-runs.d.ts.map +1 -1
- package/dist/text/style-runs.js +22 -14
- package/dist/text/style-runs.js.map +1 -1
- package/dist/text/web-font/assets.d.ts.map +1 -1
- package/dist/text/web-font/assets.js +13 -21
- package/dist/text/web-font/assets.js.map +1 -1
- package/dist/text/web-font/resolver.d.ts.map +1 -1
- package/dist/text/web-font/resolver.js +4 -1
- package/dist/text/web-font/resolver.js.map +1 -1
- package/dist/tools/analyze/overlaps/helpers.d.ts.map +1 -1
- package/dist/tools/analyze/overlaps/helpers.js +9 -1
- package/dist/tools/analyze/overlaps/helpers.js.map +1 -1
- package/dist/tools/analyze/overlaps/index.d.ts.map +1 -1
- package/dist/tools/analyze/overlaps/index.js +27 -5
- package/dist/tools/analyze/overlaps/index.js.map +1 -1
- package/dist/tools/codegen/component-map.js +3 -3
- package/dist/tools/codegen/component-map.js.map +1 -1
- package/dist/tools/create/basic.d.ts.map +1 -1
- package/dist/tools/create/basic.js +5 -4
- package/dist/tools/create/basic.js.map +1 -1
- package/dist/tools/create/components.d.ts +2 -1
- package/dist/tools/create/components.d.ts.map +1 -1
- package/dist/tools/create/components.js +27 -1
- package/dist/tools/create/components.js.map +1 -1
- package/dist/tools/create/html.d.ts.map +1 -1
- package/dist/tools/create/html.js +4 -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 +14 -6
- package/dist/tools/create/icons.js.map +1 -1
- package/dist/tools/create/mermaid.d.ts.map +1 -1
- package/dist/tools/create/mermaid.js +2 -0
- package/dist/tools/create/mermaid.js.map +1 -1
- package/dist/tools/create/render.d.ts.map +1 -1
- package/dist/tools/create/render.js +2 -0
- package/dist/tools/create/render.js.map +1 -1
- package/dist/tools/create/script.js +3 -1
- package/dist/tools/create/script.js.map +1 -1
- package/dist/tools/create/svg.d.ts.map +1 -1
- package/dist/tools/create/svg.js +4 -1
- package/dist/tools/create/svg.js.map +1 -1
- package/dist/tools/create/vector.d.ts.map +1 -1
- package/dist/tools/create/vector.js +13 -10
- package/dist/tools/create/vector.js.map +1 -1
- package/dist/tools/create.d.ts +2 -2
- package/dist/tools/create.js +2 -2
- package/dist/tools/image-ai/apply.js +1 -1
- package/dist/tools/image-ai/generate.d.ts.map +1 -1
- package/dist/tools/image-ai/generate.js +3 -0
- package/dist/tools/image-ai/generate.js.map +1 -1
- package/dist/tools/modify/effects.d.ts.map +1 -1
- package/dist/tools/modify/effects.js +5 -3
- package/dist/tools/modify/effects.js.map +1 -1
- package/dist/tools/modify/matching.d.ts.map +1 -1
- package/dist/tools/modify/matching.js +9 -6
- package/dist/tools/modify/matching.js.map +1 -1
- package/dist/tools/modify/paint.d.ts.map +1 -1
- package/dist/tools/modify/paint.js +7 -5
- package/dist/tools/modify/paint.js.map +1 -1
- package/dist/tools/modify/reactions.d.ts +6 -0
- package/dist/tools/modify/reactions.d.ts.map +1 -0
- package/dist/tools/modify/reactions.js +35 -0
- package/dist/tools/modify/reactions.js.map +1 -0
- package/dist/tools/modify/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +28 -8
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/modify.d.ts +2 -1
- package/dist/tools/modify.js +2 -1
- package/dist/tools/read/components.js +20 -22
- package/dist/tools/read/components.js.map +1 -1
- package/dist/tools/read/fonts.js +1 -1
- package/dist/tools/read/fonts.js.map +1 -1
- package/dist/tools/read/libraries.d.ts.map +1 -1
- package/dist/tools/read/libraries.js +18 -4
- 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 +38 -16
- package/dist/tools/read/nodes.js.map +1 -1
- package/dist/tools/read/pages.d.ts.map +1 -1
- package/dist/tools/read/pages.js +4 -3
- package/dist/tools/read/pages.js.map +1 -1
- package/dist/tools/read/query.js +1 -0
- package/dist/tools/read/query.js.map +1 -1
- package/dist/tools/read/reactions.d.ts +6 -0
- package/dist/tools/read/reactions.d.ts.map +1 -0
- package/dist/tools/read/reactions.js +24 -0
- package/dist/tools/read/reactions.js.map +1 -0
- package/dist/tools/read/space.js +1 -1
- package/dist/tools/read.d.ts +2 -1
- package/dist/tools/read.js +2 -1
- package/dist/tools/registry/extended.d.ts.map +1 -1
- package/dist/tools/registry/extended.js +6 -1
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/schema.d.ts +30 -5
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +125 -7
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/stock-photo/apply.js +8 -9
- package/dist/tools/stock-photo/apply.js.map +1 -1
- package/dist/tools/structure/batch.d.ts.map +1 -1
- package/dist/tools/structure/batch.js +86 -90
- package/dist/tools/structure/batch.js.map +1 -1
- package/dist/tools/variables/values.d.ts.map +1 -1
- package/dist/tools/variables/values.js +4 -2
- package/dist/tools/variables/values.js.map +1 -1
- package/dist/tools/vector/export.d.ts.map +1 -1
- package/dist/tools/vector/export.js +5 -2
- package/dist/tools/vector/export.js.map +1 -1
- package/dist/vector/fill-geometry.d.ts +4 -1
- package/dist/vector/fill-geometry.d.ts.map +1 -1
- package/dist/vector/fill-geometry.js +8 -5
- package/dist/vector/fill-geometry.js.map +1 -1
- package/dist/vector/index.js +1 -1
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/path-helpers.d.ts +1 -1
- package/dist/vector/path-helpers.d.ts.map +1 -1
- package/dist/vector/path-helpers.js +24 -7
- package/dist/vector/path-helpers.js.map +1 -1
- package/dist/vector/placement.js +1 -1
- package/dist/vector/placement.js.map +1 -1
- package/dist/vector/vectorize/preprocess.js +1 -1
- package/dist/vector/vectorize/preprocess.js.map +1 -1
- package/package.json +10 -10
- package/src/canvas/effects.ts +29 -33
- package/src/canvas/labels/hit-test.ts +6 -2
- package/src/canvas/labels/paragraph-cache.ts +2 -1
- package/src/canvas/labels/selection.ts +3 -3
- package/src/canvas/node-edit-overlay.ts +3 -2
- package/src/canvas/outline-stroke.ts +2 -6
- package/src/canvas/overlays/index.ts +0 -1
- package/src/canvas/overlays/prototype.ts +5 -27
- package/src/canvas/overlays/selection.ts +4 -52
- package/src/canvas/region-hatch.ts +7 -2
- package/src/canvas/renderer/colors.ts +41 -26
- package/src/canvas/renderer/font-waiters.ts +25 -0
- package/src/canvas/renderer/fonts.ts +42 -18
- package/src/canvas/renderer/lifecycle.ts +8 -10
- package/src/canvas/renderer/methods.ts +9 -13
- package/src/canvas/renderer/paints.ts +0 -10
- package/src/canvas/renderer/pipeline.ts +29 -3
- package/src/canvas/renderer/retained-backing.ts +4 -4
- package/src/canvas/renderer/state.ts +1 -1
- package/src/canvas/renderer/tiles/controller.ts +8 -0
- package/src/canvas/renderer/tiles/surface-pool.ts +1 -1
- package/src/canvas/renderer/visual-bounds.ts +7 -6
- package/src/canvas/renderer.ts +43 -11
- package/src/canvas/rulers.ts +55 -26
- package/src/canvas/scene.ts +127 -77
- package/src/canvas/shadows/shape.ts +1 -1
- package/src/canvas/shadows/silhouette.ts +4 -2
- package/src/canvas/shadows.ts +4 -2
- package/src/canvas/text/derived.ts +0 -9
- package/src/canvas/text/emoji/raster.ts +14 -10
- package/src/canvas/text/font-families.ts +14 -7
- package/src/canvas/text/index.ts +3 -9
- package/src/canvas/text/layout/build.ts +35 -18
- package/src/canvas/text/layout/index.ts +15 -6
- package/src/canvas/text/layout/lines.ts +10 -4
- package/src/canvas/text/paragraph/index.ts +19 -10
- package/src/canvas/text/paragraph/inputs.ts +4 -2
- package/src/canvas/text/placed.ts +2 -2
- package/src/canvas/text/renderer.ts +2 -0
- package/src/canvas/text/shape.ts +20 -31
- package/src/constants.ts +6 -1
- package/src/editor/bridges/clipboard.ts +1 -0
- package/src/editor/bridges/components.ts +2 -0
- package/src/editor/bridges/frames.ts +6 -4
- package/src/editor/bridges/structure.ts +1 -0
- package/src/editor/clipboard/detach.ts +3 -3
- package/src/editor/clipboard/paste/target.ts +2 -2
- package/src/editor/clipboard/snapshot.ts +7 -0
- package/src/editor/clipboard/variables.ts +20 -0
- package/src/editor/clipboard.ts +133 -14
- package/src/editor/component-sync.ts +28 -7
- package/src/editor/components/authoring/text-edit.ts +15 -2
- package/src/editor/components/authoring/visibility-edit.ts +11 -3
- package/src/editor/components/instances.ts +61 -11
- package/src/editor/components/properties.ts +10 -0
- package/src/editor/components/slots/authoring.ts +4 -1
- package/src/editor/create.ts +58 -8
- package/src/editor/guides.ts +27 -12
- package/src/editor/history/document-change.ts +115 -7
- package/src/editor/history/edit.ts +62 -14
- package/src/editor/history/position.ts +1 -4
- package/src/editor/history/sources.ts +25 -0
- package/src/editor/index.ts +3 -1
- package/src/editor/layout-mode.ts +20 -1
- package/src/editor/node-preview.ts +44 -8
- package/src/editor/nodes.ts +52 -12
- package/src/editor/nudge.ts +16 -2
- package/src/editor/pages.ts +100 -17
- package/src/editor/play/states.ts +0 -7
- package/src/editor/read-only/actions.ts +4 -0
- package/src/editor/selection/hit-test.ts +37 -4
- package/src/editor/shapes/pen.ts +6 -3
- package/src/editor/shapes.ts +2 -1
- package/src/editor/structure/auto-layout-wrap.ts +26 -0
- package/src/editor/structure/group/bounds.ts +22 -4
- package/src/editor/structure/rename.ts +2 -6
- package/src/editor/structure/reorder.ts +26 -8
- package/src/editor/structure.ts +88 -24
- package/src/editor/text/hyperlink.ts +2 -1
- package/src/editor/text/name.ts +51 -15
- package/src/editor/text/pending-layout.ts +42 -4
- package/src/editor/text/selection-style.ts +17 -3
- package/src/editor/text.ts +86 -4
- package/src/editor/types.ts +19 -0
- package/src/editor/undo.ts +21 -2
- package/src/editor/variable-bindings.ts +22 -2
- package/src/editor/variables.ts +10 -6
- package/src/editor/viewport.ts +55 -21
- package/src/editor/views/actions.ts +17 -7
- package/src/editor/views/present.ts +20 -11
- package/src/editor/views/types.ts +11 -5
- package/src/figma-api/accessor-utils.ts +4 -1
- package/src/figma-api/accessors/basic.ts +54 -18
- package/src/figma-api/accessors/layout.ts +46 -7
- package/src/figma-api/accessors/reactions.ts +29 -0
- package/src/figma-api/accessors/strokes.ts +28 -8
- package/src/figma-api/accessors/text/index.ts +4 -0
- package/src/figma-api/accessors/vector.ts +3 -1
- package/src/figma-api/accessors/visual.ts +25 -28
- package/src/figma-api/components.ts +9 -7
- package/src/figma-api/finite.ts +102 -0
- package/src/figma-api/fonts/list.ts +24 -0
- package/src/figma-api/index.ts +170 -19
- package/src/figma-api/overrides.ts +1 -1
- package/src/figma-api/pending-layout.ts +50 -1
- package/src/figma-api/pending-sync.ts +61 -0
- package/src/figma-api/proxy.ts +35 -2
- package/src/figma-api/reactions.ts +212 -0
- package/src/figma-api/render-bounds.ts +13 -4
- package/src/figma-api/serialization.ts +16 -2
- package/src/figma-api/slots.ts +12 -3
- package/src/figma-api/strokes.ts +16 -12
- package/src/figma-api/text/index.ts +9 -15
- package/src/figma-api/variables/variable.ts +3 -2
- package/src/geometry/connectors.ts +2 -12
- package/src/geometry/figma.ts +9 -0
- package/src/geometry/index.ts +2 -1
- package/src/geometry/scene.ts +19 -0
- package/src/geometry/types.ts +8 -0
- package/src/global.d.ts +6 -0
- package/src/icons/api.ts +27 -16
- package/src/icons/provider.ts +9 -20
- package/src/icons/schema.ts +31 -0
- package/src/icons/svg/presentation.ts +27 -3
- package/src/icons/svg/text.ts +1 -1
- package/src/icons/svg.ts +21 -19
- package/src/icons/types.ts +0 -14
- package/src/io/formats/design-tokens/plan/index.ts +7 -1
- package/src/io/formats/design-tokens/plan/styles.ts +40 -4
- package/src/io/formats/design-tokens/styles.ts +60 -3
- package/src/io/formats/design-tokens/types.ts +3 -0
- package/src/io/formats/drawio/export.ts +11 -0
- package/src/io/formats/drawio/index.ts +36 -1
- package/src/io/formats/drawio/shapes.ts +13 -9
- package/src/io/formats/drawio/warnings.ts +27 -0
- package/src/io/formats/fig/export/setup.ts +16 -14
- package/src/io/formats/fig/export/variables.ts +7 -8
- package/src/io/formats/fig/index.ts +1 -0
- package/src/io/formats/fig/read.ts +66 -23
- package/src/io/formats/html/index.ts +2 -6
- package/src/io/formats/pdf/dom.ts +125 -3
- package/src/io/formats/pdf/export.ts +3 -2
- package/src/io/formats/pen/fonts.ts +45 -0
- package/src/io/formats/pen/index.ts +30 -6
- package/src/io/formats/raster/headless.ts +40 -14
- package/src/io/formats/raster/index.ts +3 -0
- package/src/io/formats/raster/render.ts +66 -8
- package/src/io/formats/svg/export.ts +24 -25
- package/src/io/formats/svg/paths.ts +11 -2
- package/src/io/formats/svg/strokes.ts +8 -2
- package/src/io/formats/svg/text/export.ts +23 -0
- package/src/io/formats/svg/text/import.ts +2 -1
- package/src/io/formats.ts +3 -1
- package/src/io/registry.ts +12 -0
- package/src/io/subgraph.ts +3 -1
- package/src/io/types.ts +2 -0
- package/src/kiwi/fig/population/client.ts +77 -43
- package/src/kiwi/fig/population/delta.ts +141 -18
- package/src/kiwi/fig/population/edits.ts +235 -0
- package/src/kiwi/fig/session/archive/access.ts +15 -0
- package/src/kiwi/fig/session/archive/changes.ts +27 -6
- package/src/kiwi/fig/session/document-state.ts +23 -1
- package/src/kiwi/fig/session/protocol.ts +26 -1
- package/src/kiwi/fig/session/worker.ts +38 -11
- package/src/layout/apply.ts +52 -10
- package/src/layout/arrange/boxes.ts +36 -0
- package/src/layout/flow-edges.ts +139 -0
- package/src/layout/grid.ts +14 -4
- package/src/layout/text-auto-resize.ts +13 -4
- package/src/layout/text-measurement.ts +46 -3
- package/src/layout.ts +60 -66
- package/src/library/asset-keys.ts +4 -3
- package/src/library/copied-references.ts +29 -5
- package/src/library/materialize.ts +1 -1
- package/src/library/schema.ts +1 -1
- package/src/library/snapshot.ts +12 -2
- package/src/lint/linter.ts +12 -2
- package/src/pairdraw-api/variables.ts +1 -3
- package/src/profiler/hud-controller.ts +8 -6
- package/src/profiler/hud-renderer.ts +9 -6
- package/src/profiler/render-profiler.ts +4 -3
- package/src/rpc/variables-command.ts +6 -5
- package/src/text/character-style.ts +29 -9
- package/src/text/coverage.ts +29 -15
- package/src/text/editor.ts +3 -8
- package/src/text/fallbacks.ts +163 -22
- package/src/text/font/catalog.ts +10 -0
- package/src/text/font/collection.ts +60 -0
- package/src/text/font/faces.ts +9 -5
- package/src/text/font/glyphs.ts +29 -4
- package/src/text/font/local.ts +2 -2
- package/src/text/font/manager.ts +220 -49
- package/src/text/font/style.ts +52 -3
- package/src/text/index.ts +1 -0
- package/src/text/outlines.ts +106 -90
- package/src/text/path/caret.ts +3 -4
- package/src/text/prepare.ts +51 -2
- package/src/text/style-runs.ts +43 -16
- package/src/text/web-font/assets.ts +11 -15
- package/src/text/web-font/resolver.ts +7 -1
- package/src/tools/analyze/overlaps/helpers.ts +18 -1
- package/src/tools/analyze/overlaps/index.ts +37 -6
- package/src/tools/codegen/component-map.ts +3 -3
- package/src/tools/create/basic.ts +6 -4
- package/src/tools/create/components.ts +33 -0
- package/src/tools/create/html.ts +3 -1
- package/src/tools/create/icons.ts +16 -6
- package/src/tools/create/mermaid.ts +2 -0
- package/src/tools/create/render.ts +2 -0
- package/src/tools/create/script.ts +5 -1
- package/src/tools/create/svg.ts +4 -1
- package/src/tools/create/vector.ts +20 -10
- package/src/tools/create.ts +1 -0
- package/src/tools/image-ai/generate.ts +3 -0
- package/src/tools/modify/effects.ts +11 -4
- package/src/tools/modify/matching.ts +10 -6
- package/src/tools/modify/paint.ts +13 -5
- package/src/tools/modify/reactions.ts +40 -0
- package/src/tools/modify/text.ts +53 -20
- package/src/tools/modify.ts +1 -0
- package/src/tools/read/components.ts +28 -25
- package/src/tools/read/fonts.ts +1 -1
- package/src/tools/read/libraries.ts +24 -4
- package/src/tools/read/nodes.ts +47 -17
- package/src/tools/read/pages.ts +7 -3
- package/src/tools/read/query.ts +2 -0
- package/src/tools/read/reactions.ts +21 -0
- package/src/tools/read.ts +1 -0
- package/src/tools/registry/extended.ts +6 -0
- package/src/tools/schema.ts +166 -6
- package/src/tools/stock-photo/apply.ts +17 -5
- package/src/tools/structure/batch.ts +84 -98
- package/src/tools/variables/values.ts +6 -3
- package/src/tools/vector/export.ts +5 -1
- package/src/vector/fill-geometry.ts +11 -5
- package/src/vector/index.ts +1 -1
- package/src/vector/path-helpers.ts +34 -8
- package/src/vector/placement.ts +1 -1
- package/src/vector/vectorize/preprocess.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-change.js","names":[],"sources":["../../../src/editor/history/document-change.ts"],"sourcesContent":["import { compact, isEqual, 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 * Starts recording an edit made from `pageId`. Call the returned function once the edit is\n * done, also when it 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 */\nexport function captureDocumentChange(graph: SceneGraph, pageId: string): () => DocumentChange {\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 const unobserve = graph.observeNodeChanges({\n created: (node) => created.add(node.id),\n before: (node) => {\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 })\n\n return () => {\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\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,YAAY;AAC3D;;AAGA,SAAS,eAAe,MAAiB,MAA4B;CACnE,OAAO;EAC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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"}
|
|
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,YAAY;AAC3D;;AAGA,SAAS,eAAe,MAAiB,MAA4B;CACnE,OAAO;EACL,GAAG;EACH,YAAY,iBAAiB,KAAK,YAAY,KAAK,UAAU;EAC7D,QAAQ;GAAE,GAAG,KAAK;GAAQ,cAAc,WAAW,KAAK,OAAO,cAAc,IAAI;EAAE;CACrF;AACF;A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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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","names":[],"sources":["../../../src/editor/history/edit.ts"],"mappings":";;;
|
|
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;;;;;;;;iBAqJR,WAAW,GAAG,KAAK,eAAe,SAAS,mBAAmB,WAAW,IAAI;;;;;;;;;;;iBAuBvE,gBAAgB,GACpC,KAAK,eACL,SAAS,mBACT,WAAW,QAAQ,KAClB,QAAQ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyDocumentChange,
|
|
1
|
+
import { applyDocumentChange, isEmptyDocumentChange, recordDocumentChange, restoreDocumentChange } from "./document-change.js";
|
|
2
2
|
//#region src/editor/history/edit.ts
|
|
3
3
|
function unchanged(pageId) {
|
|
4
4
|
return {
|
|
@@ -15,8 +15,50 @@ function unchanged(pageId) {
|
|
|
15
15
|
collections: []
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The undo step of a recorded change. Built outside the edit's own scope, so the step keeps only
|
|
20
|
+
* the change: not the edit's recording state, nor its options, whose `onRecorded` can hold the
|
|
21
|
+
* step before it and so every step back to the first, past the history limit.
|
|
22
|
+
*/
|
|
23
|
+
function changeStep(ctx, label, change) {
|
|
24
|
+
return {
|
|
25
|
+
label,
|
|
26
|
+
forward: () => restoreDocumentChange(ctx, change, "after"),
|
|
27
|
+
inverse: () => restoreDocumentChange(ctx, change, "before")
|
|
28
|
+
};
|
|
29
|
+
}
|
|
18
30
|
/** How many edits that await are running in each history. */
|
|
19
31
|
const runningEdits = /* @__PURE__ */ new WeakMap();
|
|
32
|
+
/** The recorders of edits still open in each editor, which anyone else's edit waits outside. */
|
|
33
|
+
const openRecorders = /* @__PURE__ */ new WeakMap();
|
|
34
|
+
function keepOpenRecorder(ctx, recorder) {
|
|
35
|
+
let recorders = openRecorders.get(ctx);
|
|
36
|
+
if (!recorders) {
|
|
37
|
+
recorders = /* @__PURE__ */ new Set();
|
|
38
|
+
openRecorders.set(ctx, recorders);
|
|
39
|
+
}
|
|
40
|
+
recorders.add(recorder);
|
|
41
|
+
}
|
|
42
|
+
function releaseOpenRecorder(ctx, recorder) {
|
|
43
|
+
const recorders = openRecorders.get(ctx);
|
|
44
|
+
if (!recorders) return;
|
|
45
|
+
recorders.delete(recorder);
|
|
46
|
+
if (recorders.size === 0) openRecorders.delete(ctx);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Runs a separate edit, or an undo or redo, while the edits that are still open treat what it
|
|
50
|
+
* changes as someone else's: their steps leave it alone. The edit is synchronous, so nothing it
|
|
51
|
+
* runs interleaves with their awaits.
|
|
52
|
+
*/
|
|
53
|
+
function withOpenEditsPaused(ctx, run, own) {
|
|
54
|
+
const recorders = [...openRecorders.get(ctx) ?? []].filter((recorder) => recorder !== own);
|
|
55
|
+
for (const recorder of recorders) recorder.pause();
|
|
56
|
+
try {
|
|
57
|
+
return run();
|
|
58
|
+
} finally {
|
|
59
|
+
for (const recorder of recorders) recorder.resume();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
20
62
|
/**
|
|
21
63
|
* Watches, while an edit awaits, for writes it does not own: a step recorded, undone, or redone,
|
|
22
64
|
* another edit or a batch open, or text being edited. They land in the edit's change, so rolling
|
|
@@ -58,27 +100,29 @@ function rollBack(ctx, graph, change) {
|
|
|
58
100
|
function begin(ctx, options, awaits = false) {
|
|
59
101
|
const graph = ctx.graph;
|
|
60
102
|
const pageId = options.pageId ?? ctx.state.currentPageId;
|
|
61
|
-
const
|
|
103
|
+
const recorder = recordDocumentChange(graph, pageId);
|
|
104
|
+
if (awaits) keepOpenRecorder(ctx, recorder);
|
|
62
105
|
const othersWrote = awaits ? watchOtherWrites(ctx) : () => false;
|
|
63
|
-
|
|
106
|
+
const finish = (failed) => {
|
|
107
|
+
if (awaits) releaseOpenRecorder(ctx, recorder);
|
|
64
108
|
const others = othersWrote();
|
|
65
|
-
const change = finish();
|
|
109
|
+
const change = recorder.finish();
|
|
66
110
|
const empty = isEmptyDocumentChange(change);
|
|
67
111
|
if (failed && options.rollbackOnThrow && !empty && !others && options.canRollBack?.() !== false && rollBack(ctx, graph, change)) {
|
|
68
112
|
options.onRecorded?.(unchanged(pageId));
|
|
69
113
|
return;
|
|
70
114
|
}
|
|
71
115
|
if (options.push !== false && !empty) {
|
|
72
|
-
const entry =
|
|
73
|
-
label: options.label,
|
|
74
|
-
forward: () => restoreDocumentChange(ctx, change, "after"),
|
|
75
|
-
inverse: () => restoreDocumentChange(ctx, change, "before")
|
|
76
|
-
};
|
|
116
|
+
const entry = changeStep(ctx, options.label, change);
|
|
77
117
|
if (options.ownStep) ctx.undo.pushStep(entry);
|
|
78
118
|
else ctx.undo.push(entry);
|
|
79
119
|
}
|
|
80
120
|
options.onRecorded?.(change);
|
|
81
121
|
};
|
|
122
|
+
return {
|
|
123
|
+
finish,
|
|
124
|
+
recorder
|
|
125
|
+
};
|
|
82
126
|
}
|
|
83
127
|
/**
|
|
84
128
|
* Runs a synchronous edit as one undo step of everything it changed in the document, also when
|
|
@@ -87,10 +131,10 @@ function begin(ctx, options, awaits = false) {
|
|
|
87
131
|
* edit, and joins a batch open around it.
|
|
88
132
|
*/
|
|
89
133
|
function recordEdit(ctx, options, run) {
|
|
90
|
-
const finish = begin(ctx, options);
|
|
134
|
+
const { finish, recorder } = begin(ctx, options);
|
|
91
135
|
let failed = true;
|
|
92
136
|
try {
|
|
93
|
-
const result = run
|
|
137
|
+
const result = withOpenEditsPaused(ctx, run, recorder);
|
|
94
138
|
failed = false;
|
|
95
139
|
return result;
|
|
96
140
|
} finally {
|
|
@@ -108,7 +152,7 @@ function recordEdit(ctx, options, run) {
|
|
|
108
152
|
* instead.
|
|
109
153
|
*/
|
|
110
154
|
async function recordEditAsync(ctx, options, run) {
|
|
111
|
-
const finish = begin(ctx, {
|
|
155
|
+
const { finish } = begin(ctx, {
|
|
112
156
|
...options,
|
|
113
157
|
ownStep: true
|
|
114
158
|
}, true);
|
|
@@ -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 { UndoManager } from '@pairdraw/scene-graph/undo'\n\nimport {\n applyDocumentChange,\n captureDocumentChange,\n isEmptyDocumentChange,\n restoreDocumentChange,\n type DocumentChange\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/** How many edits that await are running in each history. */\nconst runningEdits = new WeakMap<UndoManager, number>()\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 finish = captureDocumentChange(graph, pageId)\n // A synchronous edit runs alone; one that awaits shares the document while it waits.\n const othersWrote = awaits ? watchOtherWrites(ctx) : () => false\n return (failed: boolean) => {\n const others = othersWrote()\n const change = 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 = {\n label: options.label,\n forward: () => restoreDocumentChange(ctx, change, 'after'),\n inverse: () => restoreDocumentChange(ctx, change, 'before')\n }\n if (options.ownStep) ctx.undo.pushStep(entry)\n else ctx.undo.push(entry)\n }\n options.onRecorded?.(change)\n }\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 = begin(ctx, options)\n let failed = true\n try {\n const result = run()\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":";;AA6CA,SAAS,UAAU,QAAgC;CACjD,OAAO;EACL;EAC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A,QAAQ,mBACR,CAAC,SACD,CAAC,UACD,QAAQ,cAAc,MAAM,SAC5B,SAAS,KAAK,OAAO,MAAM,GAC3B;GACA,QAAQ,aAAa,UAAU,MAAM,CAAC;GACtC;EACF;EAEA,IAAI,QAAQ,SAAS,SAAS,CAAC,OAAO;GACpC,MAAM,QAAQ;IACZ,OAAO,QAAQ;IACf,eAAe,sBAAsB,KAAK,QAAQ,OAAO;IACzD,eAAe,sBAAsB,KAAK,QAAQ,QAAQ;GAC5D;GACA,IAAI,QAAQ,SAAS,IAAI,KAAK,SAAS,KAAK;QACvC,IAAI,KAAK,KAAK,KAAK;EAC1B;EACA,QAAQ,aAAa,MAAM;CAC7B;AACF;;;;;;;AAQA,SAAgB,WAAc,KAAoB,SAA4B,KAAiB;CAC7F,MAAM,SAAS,MAAM,KAAK,OAAO;CACjC,IAAI,SAAS;CACb,IAAI;EACF,MAAM,SAAS,IAAI;EACnB,SAAS;EACT,OAAO;CACT,UAAU;EACR,OAAO,MAAM;CACf;AACF;;;;;;;;;;;AAYA,eAAsB,gBACpB,KACA,SACA,KACY;CAEZ,MAAM,SAAS,MAAM,KAAK;EAAE,GAAG;EAAS,SAAS;CAAK,GAAG,IAAI;CAC7D,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\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,MAAM,+BAAe,IAAI,QAA6B;;AAGtD,MAAM,gCAAgB,IAAI,QAAoD;AAE9E,SAAS,iBAAiB,KAAoB,UAAwC;CACpF,IAAI,YAAY,cAAc,IAAI,GAAG;CACrC,IAAI,CAAC,WAAW;EACd,4BAAY,IAAI,IAAI;EACpB,cAAc,IAAI,KAAK,SAAS;CAClC;CACA,UAAU,IAAI,QAAQ;AACxB;AAEA,SAAS,oBAAoB,KAAoB,UAAwC;CACvF,MAAM,YAAY,cAAc,IAAI,GAAG;CACvC,IAAI,CAAC,WAAW;CAChB,UAAU,OAAO,QAAQ;CACzB,IAAI,UAAU,SAAS,GAAG,cAAc,OAAO,GAAG;AACpD;;;;;;AAOA,SAAS,oBAAuB,KAAoB,KAAc,KAAiC;CACjG,MAAM,YAAY,CAAC,GAAI,cAAc,IAAI,GAAG,KAAK,CAAC,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AAM,SAAS,SAAS,OAAO;EAC/B,MAAM,QAAQ,sBAAsB,MAAM;EAC1C,IACE,UACA,QAAQ,mBACR,CAAC,SACD,CAAC,UACD,QAAQ,cAAc,MAAM,SAC5B,SAAS,KAAK,OAAO,MAAM,GAC3B;GACA,QAAQ,aAAa,UAAU,MAAM,CAAC;GACtC;EACF;EAEA,IAAI,QAAQ,SAAS,SAAS,CAAC,OAAO;GACpC,MAAM,QAAQ,WAAW,KAAK,QAAQ,OAAO,MAAM;GACnD,IAAI,QAAQ,SAAS,IAAI,KAAK,SAAS,KAAK;QACvC,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"}
|
|
@@ -30,10 +30,7 @@ function commitPositionChange(ctx, label, originals) {
|
|
|
30
30
|
})) pushPositionUndo(ctx, label, originals, finals);
|
|
31
31
|
}
|
|
32
32
|
function applyPositions(ctx, positions) {
|
|
33
|
-
for (const [id, pos] of positions)
|
|
34
|
-
ctx.graph.updateNode(id, pos);
|
|
35
|
-
ctx.runLayoutForNode(id);
|
|
36
|
-
}
|
|
33
|
+
for (const [id, pos] of positions) ctx.graph.updateNode(id, pos);
|
|
37
34
|
}
|
|
38
35
|
//#endregion
|
|
39
36
|
export { collectNodePositions, commitPositionChange, pushPositionUndo };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"position.js","names":[],"sources":["../../../src/editor/history/position.ts"],"sourcesContent":["import type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport type { EditorContext } from '#core/editor/types'\n\nexport function collectNodePositions(\n ctx: EditorContext,\n ids: Iterable<string>\n): Map<string, Vector> {\n const positions = new Map<string, Vector>()\n for (const id of ids) {\n const node = ctx.graph.getNode(id)\n if (node) positions.set(id, { x: node.x, y: node.y })\n }\n return positions\n}\n\nexport function pushPositionUndo(\n ctx: EditorContext,\n label: string,\n originals: Map<string, Vector>,\n finals: Map<string, Vector>\n): void {\n ctx.undo.push({\n label,\n forward: () => applyPositions(ctx, finals),\n inverse: () => applyPositions(ctx, originals)\n })\n}\n\n/**\n * Lays the moved layers out, then records one undo step from `originals` to where they ended up.\n * Layers an auto layout holds in place snap back, so an edit that moves nothing records nothing.\n */\nexport function commitPositionChange(\n ctx: EditorContext,\n label: string,\n originals: Map<string, Vector>\n): void {\n for (const id of originals.keys()) ctx.runLayoutForNode(id)\n const finals = collectNodePositions(ctx, originals.keys())\n const moved = [...finals].some(([id, place]) => {\n const before = originals.get(id)\n return !before || before.x !== place.x || before.y !== place.y\n })\n if (moved) pushPositionUndo(ctx, label, originals, finals)\n}\n\nfunction applyPositions(ctx: EditorContext, positions: Map<string, Vector>): void {\n for (const [id, pos] of positions)
|
|
1
|
+
{"version":3,"file":"position.js","names":[],"sources":["../../../src/editor/history/position.ts"],"sourcesContent":["import type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport type { EditorContext } from '#core/editor/types'\n\nexport function collectNodePositions(\n ctx: EditorContext,\n ids: Iterable<string>\n): Map<string, Vector> {\n const positions = new Map<string, Vector>()\n for (const id of ids) {\n const node = ctx.graph.getNode(id)\n if (node) positions.set(id, { x: node.x, y: node.y })\n }\n return positions\n}\n\nexport function pushPositionUndo(\n ctx: EditorContext,\n label: string,\n originals: Map<string, Vector>,\n finals: Map<string, Vector>\n): void {\n ctx.undo.push({\n label,\n forward: () => applyPositions(ctx, finals),\n inverse: () => applyPositions(ctx, originals)\n })\n}\n\n/**\n * Lays the moved layers out, then records one undo step from `originals` to where they ended up.\n * Layers an auto layout holds in place snap back, so an edit that moves nothing records nothing.\n */\nexport function commitPositionChange(\n ctx: EditorContext,\n label: string,\n originals: Map<string, Vector>\n): void {\n for (const id of originals.keys()) ctx.runLayoutForNode(id)\n const finals = collectNodePositions(ctx, originals.keys())\n const moved = [...finals].some(([id, place]) => {\n const before = originals.get(id)\n return !before || before.x !== place.x || before.y !== place.y\n })\n if (moved) pushPositionUndo(ctx, label, originals, finals)\n}\n\nfunction applyPositions(ctx: EditorContext, positions: Map<string, Vector>): void {\n for (const [id, pos] of positions) ctx.graph.updateNode(id, pos)\n}\n"],"mappings":";AAIA,SAAgB,qBACd,KACA,KACqB;CACrB,MAAM,4BAAY,IAAI,IAAoB;CAC1C,KAAK,MAAM,MAAM,KAAK;EACpB,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;EACjC,IAAI,MAAM,UAAU,IAAI,IAAI;GAAE,GAAG,KAAK;GAAG,GAAG,KAAK;EAAE,CAAC;CACtD;CACA,OAAO;AACT;AAEA,SAAgB,iBACd,KACA,OACA,WACA,QACM;CACN,IAAI,KAAK,KAAK;EACZ;EACA,eAAe,eAAe,KAAK,MAAM;EACzC,eAAe,eAAe,KAAK,SAAS;CAC9C,CAAC;AACH;;;;;AAMA,SAAgB,qBACd,KACA,OACA,WACM;CACN,KAAK,MAAM,MAAM,UAAU,KAAK,GAAG,IAAI,iBAAiB,EAAE;CAC1D,MAAM,SAAS,qBAAqB,KAAK,UAAU,KAAK,CAAC;CAKzD,IAJc,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,WAAW;EAC9C,MAAM,SAAS,UAAU,IAAI,EAAE;EAC/B,OAAO,CAAC,UAAU,OAAO,MAAM,MAAM,KAAK,OAAO,MAAM,MAAM;CAC/D,CACQ,GAAG,iBAAiB,KAAK,OAAO,WAAW,MAAM;AAC3D;AAEA,SAAS,eAAe,KAAoB,WAAsC;CAChF,KAAK,MAAM,CAAC,IAAI,QAAQ,WAAW,IAAI,MAAM,WAAW,IAAI,GAAG;AACjE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
|
|
2
|
+
//#region src/editor/history/sources.d.ts
|
|
3
|
+
/** A node's source metadata as it stood at one point, by node id. */
|
|
4
|
+
type SourceSnapshots = Map<string, SceneNode['source']>;
|
|
5
|
+
/**
|
|
6
|
+
* The source marks of these layers. A recorded edit restores them with the values it restores,
|
|
7
|
+
* so undoing the last edit leaves a layer as it was, its edited-field marks included.
|
|
8
|
+
*/
|
|
9
|
+
declare function captureSources(graph: SceneGraph, ids: Iterable<string>): SourceSnapshots;
|
|
10
|
+
/** Puts the marks back without touching values, so the graph does not mark them again. */
|
|
11
|
+
declare function restoreSources(graph: SceneGraph, sources: SourceSnapshots | undefined): void;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { SourceSnapshots, captureSources, restoreSources };
|
|
14
|
+
//# sourceMappingURL=sources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources.d.ts","names":[],"sources":["../../../src/editor/history/sources.ts"],"mappings":";;;KAGY,kBAAkB,YAAY;;;;;iBAM1B,eAAe,OAAO,YAAY,KAAK,mBAAmB;;iBAU1D,eAAe,OAAO,YAAY,SAAS"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/editor/history/sources.ts
|
|
2
|
+
/**
|
|
3
|
+
* The source marks of these layers. A recorded edit restores them with the values it restores,
|
|
4
|
+
* so undoing the last edit leaves a layer as it was, its edited-field marks included.
|
|
5
|
+
*/
|
|
6
|
+
function captureSources(graph, ids) {
|
|
7
|
+
const sources = /* @__PURE__ */ new Map();
|
|
8
|
+
for (const id of ids) {
|
|
9
|
+
const node = graph.getNode(id);
|
|
10
|
+
if (node) sources.set(id, structuredClone(node.source));
|
|
11
|
+
}
|
|
12
|
+
return sources;
|
|
13
|
+
}
|
|
14
|
+
/** Puts the marks back without touching values, so the graph does not mark them again. */
|
|
15
|
+
function restoreSources(graph, sources) {
|
|
16
|
+
if (!sources) return;
|
|
17
|
+
graph.preserveSourceMetadataDuring(() => {
|
|
18
|
+
for (const [id, source] of sources) graph.restoreNodeProperties(id, { source }, []);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { captureSources, restoreSources };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=sources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources.js","names":[],"sources":["../../../src/editor/history/sources.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\n/** A node's source metadata as it stood at one point, by node id. */\nexport type SourceSnapshots = Map<string, SceneNode['source']>\n\n/**\n * The source marks of these layers. A recorded edit restores them with the values it restores,\n * so undoing the last edit leaves a layer as it was, its edited-field marks included.\n */\nexport function captureSources(graph: SceneGraph, ids: Iterable<string>): SourceSnapshots {\n const sources: SourceSnapshots = new Map()\n for (const id of ids) {\n const node = graph.getNode(id)\n if (node) sources.set(id, structuredClone(node.source))\n }\n return sources\n}\n\n/** Puts the marks back without touching values, so the graph does not mark them again. */\nexport function restoreSources(graph: SceneGraph, sources: SourceSnapshots | undefined): void {\n if (!sources) return\n graph.preserveSourceMetadataDuring(() => {\n for (const [id, source] of sources) graph.restoreNodeProperties(id, { source }, [])\n })\n}\n"],"mappings":";;;;;AASA,SAAgB,eAAe,OAAmB,KAAwC;CACxF,MAAM,0BAA2B,IAAI,IAAI;CACzC,KAAK,MAAM,MAAM,KAAK;EACpB,MAAM,OAAO,MAAM,QAAQ,EAAE;EAC7B,IAAI,MAAM,QAAQ,IAAI,IAAI,gBAAgB,KAAK,MAAM,CAAC;CACxD;CACA,OAAO;AACT;;AAGA,SAAgB,eAAe,OAAmB,SAA4C;CAC5F,IAAI,CAAC,SAAS;CACd,MAAM,mCAAmC;EACvC,KAAK,MAAM,CAAC,IAAI,WAAW,SAAS,MAAM,sBAAsB,IAAI,EAAE,OAAO,GAAG,CAAC,CAAC;CACpF,CAAC;AACH"}
|
package/dist/editor/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AttachModifiers } from "./connectors/attach.js";
|
|
|
2
2
|
import { DEFAULT_SNAPPING_PREFERENCES, SnappingPreferences } from "./preferences.js";
|
|
3
3
|
import { ShaderRasterizer } from "./shaders/types.js";
|
|
4
4
|
import { CanvasView, EditorProfile, EditorProfileInputs, EditorRestrictions, PresentationScale, ShaderView } from "./views/types.js";
|
|
5
|
-
import { ClipboardImageResolution, EditorContext, EditorEventName, EditorEvents, EditorOptions, EditorSharedState, EditorState, EditorViewState, FigmaClipboardImageResolver, GradientEdit, ImageEdit, ResumedPath, ShapeHandleHover, Tool } from "./types.js";
|
|
5
|
+
import { ClipboardImageResolution, EditorContext, EditorEventName, EditorEvents, EditorOptions, EditorSharedState, EditorState, EditorViewState, FigmaClipboardImageResolver, GradientEdit, ImageEdit, ResumedPath, ShapeHandleHover, Tool, ViewportInsets, VisibleCanvas } from "./types.js";
|
|
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";
|
|
@@ -54,4 +54,4 @@ import { LayerType, layerTypeOptions } from "./structure/layer-type.js";
|
|
|
54
54
|
import { BOARD_TOOLS, BOARD_TOOL_SHORTCUTS, EDITOR_TOOLS, EditorToolDef, TOOL_SHORTCUTS } from "./tool-registry.js";
|
|
55
55
|
import { newLayerDefaults } from "./shapes/defaults.js";
|
|
56
56
|
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, 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 };
|
|
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 };
|
package/dist/editor/index.js
CHANGED
|
@@ -17,10 +17,10 @@ import { isEmptyDocumentChange, touchedTopLevelIds } from "./history/document-ch
|
|
|
17
17
|
import { resolvePasteTarget } from "./clipboard/paste/target.js";
|
|
18
18
|
import { clipboardImportHasConflicts, clipboardImportHasDependencies, planClipboardImport } from "./clipboard/conflicts.js";
|
|
19
19
|
import { reapplyInstanceComponentProperties } from "./components/properties.js";
|
|
20
|
+
import { newLayerDefaults } from "./shapes/defaults.js";
|
|
20
21
|
import { pastedPropertyChanges } from "./clipboard/paste/properties.js";
|
|
21
22
|
import { syncEditedComponents } from "./component-sync.js";
|
|
22
23
|
import { resizedPathTextGlyphs } from "./text/path-edit.js";
|
|
23
|
-
import { newLayerDefaults } from "./shapes/defaults.js";
|
|
24
24
|
import { createGuideActions } from "./guides.js";
|
|
25
25
|
import { opacityFromBuffer } from "./nodes.js";
|
|
26
26
|
import { DEFAULT_SCALE_ANCHOR, SCALE_ANCHORS, isScaleAnchor, parseScaleFactor, scaleAnchorFraction, scaleAnchorPoint, scaleFactorForSize, scaledBounds } from "./scale/anchor.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout-mode.d.ts","names":[],"sources":["../../src/editor/layout-mode.ts"],"mappings":";;;;iBAKgB,wBACd,KAAK,eACL,mBAAmB,kBAAkB;EAOV,gBAAA,YAAM,MAAQ;
|
|
1
|
+
{"version":3,"file":"layout-mode.d.ts","names":[],"sources":["../../src/editor/layout-mode.ts"],"mappings":";;;;iBAKgB,wBACd,KAAK,eACL,mBAAmB,kBAAkB;EAOV,gBAAA,YAAM,MAAQ;EAeN,uBAAA,eAAQ,aAAe"}
|
|
@@ -9,6 +9,7 @@ function createLayoutModeActions(ctx, beginNodePreview) {
|
|
|
9
9
|
const node = ctx.graph.getNode(id);
|
|
10
10
|
if (!node || node.layoutMode === mode) return;
|
|
11
11
|
const preview = beginNodePreview(mode === "NONE" ? "Remove auto layout" : "Add auto layout");
|
|
12
|
+
if (node.type === "GROUP" && mode !== "NONE") preview.update(id, { type: "FRAME" });
|
|
12
13
|
preview.update(id, layoutModeUpdates(ctx, node, id, mode));
|
|
13
14
|
preview.commit();
|
|
14
15
|
}
|
|
@@ -46,7 +47,21 @@ function createLayoutModeActions(ctx, beginNodePreview) {
|
|
|
46
47
|
function layoutModeUpdates(ctx, node, id, mode) {
|
|
47
48
|
const updates = { layoutMode: mode };
|
|
48
49
|
if (mode === "GRID" && node.layoutMode !== "GRID") applyGridDefaults(ctx, node, id, updates);
|
|
49
|
-
else if (mode
|
|
50
|
+
else if (mode === "NONE") Object.assign(updates, {
|
|
51
|
+
itemSpacing: 0,
|
|
52
|
+
paddingTop: 0,
|
|
53
|
+
paddingRight: 0,
|
|
54
|
+
paddingBottom: 0,
|
|
55
|
+
paddingLeft: 0,
|
|
56
|
+
primaryAxisSizing: "FIXED",
|
|
57
|
+
counterAxisSizing: "FIXED",
|
|
58
|
+
layoutWrap: "NO_WRAP",
|
|
59
|
+
primaryAxisAlign: "MIN",
|
|
60
|
+
counterAxisAlign: "MIN",
|
|
61
|
+
counterAxisSpacing: 0,
|
|
62
|
+
layoutDirection: "AUTO"
|
|
63
|
+
});
|
|
64
|
+
else if (node.layoutMode === "NONE") Object.assign(updates, autoLayoutDefaults());
|
|
50
65
|
return updates;
|
|
51
66
|
}
|
|
52
67
|
function applyGridDefaults(ctx, node, id, updates) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout-mode.js","names":[],"sources":["../../src/editor/layout-mode.ts"],"sourcesContent":["import type { LayoutMode, SceneNode } from '@pairdraw/scene-graph'\n\nimport type { NodePreview } from './node-preview'\nimport type { EditorContext } from './types'\n\nexport function createLayoutModeActions(\n ctx: EditorContext,\n beginNodePreview: (label: string) => NodePreview\n) {\n /**\n * Adding, switching, or removing auto layout moves and resizes children, nested layouts, and\n * Hug ancestors. A node preview records every layer it changes, so one undo puts them all back\n * where they were; setting the mode a frame already has records nothing.\n */\n function setLayoutMode(id: string, mode: LayoutMode) {\n const node = ctx.graph.getNode(id)\n if (!node || node.layoutMode === mode) return\n const preview = beginNodePreview(mode === 'NONE' ? 'Remove auto layout' : 'Add auto layout')\n preview.update(id, layoutModeUpdates(ctx, node, id, mode))\n preview.commit()\n }\n\n /**\n * Takes layers out of their parent's auto layout or puts them back, as Figma's Ignore auto\n * layout toggle does. A layer taken out stays where it is and keeps its sizing, which applies\n * again when it returns; its siblings close the gap in the same undo step.\n */\n function setLayoutPositioning(ids: string[], positioning: SceneNode['layoutPositioning']) {\n // Read every place first: taking one layer out moves the siblings after it.\n const targets = ids.flatMap((id) => {\n const node = ctx.graph.getNode(id)\n const parent = node?.parentId ? ctx.graph.getNode(node.parentId) : undefined\n if (!node || !parent || parent.layoutMode === 'NONE') return []\n if (node.layoutPositioning === positioning) return []\n return [{ id, x: node.x, y: node.y }]\n })\n if (targets.length === 0) return\n const preview = beginNodePreview(\n positioning === 'ABSOLUTE' ? 'Ignore auto layout' : 'Use auto layout'\n )\n for (const { id, x, y } of targets) {\n preview.update(\n id,\n positioning === 'ABSOLUTE'\n ? { layoutPositioning: positioning, x, y }\n : { layoutPositioning: positioning }\n )\n }\n preview.commit()\n }\n\n return { setLayoutMode, setLayoutPositioning }\n}\n\nfunction layoutModeUpdates(\n ctx: EditorContext,\n node: SceneNode,\n id: string,\n mode: LayoutMode\n): Partial<SceneNode> {\n const updates: Partial<SceneNode> = { layoutMode: mode }\n if (mode === 'GRID' && node.layoutMode !== 'GRID') {\n applyGridDefaults(ctx, node, id, updates)\n } else if (mode
|
|
1
|
+
{"version":3,"file":"layout-mode.js","names":[],"sources":["../../src/editor/layout-mode.ts"],"sourcesContent":["import type { LayoutMode, SceneNode } from '@pairdraw/scene-graph'\n\nimport type { NodePreview } from './node-preview'\nimport type { EditorContext } from './types'\n\nexport function createLayoutModeActions(\n ctx: EditorContext,\n beginNodePreview: (label: string) => NodePreview\n) {\n /**\n * Adding, switching, or removing auto layout moves and resizes children, nested layouts, and\n * Hug ancestors. A node preview records every layer it changes, so one undo puts them all back\n * where they were; setting the mode a frame already has records nothing.\n */\n function setLayoutMode(id: string, mode: LayoutMode) {\n const node = ctx.graph.getNode(id)\n if (!node || node.layoutMode === mode) return\n const preview = beginNodePreview(mode === 'NONE' ? 'Remove auto layout' : 'Add auto layout')\n // A group is only its children's bounds; a flow needs a frame to own it, as Figma converts.\n if (node.type === 'GROUP' && mode !== 'NONE') preview.update(id, { type: 'FRAME' })\n preview.update(id, layoutModeUpdates(ctx, node, id, mode))\n preview.commit()\n }\n\n /**\n * Takes layers out of their parent's auto layout or puts them back, as Figma's Ignore auto\n * layout toggle does. A layer taken out stays where it is and keeps its sizing, which applies\n * again when it returns; its siblings close the gap in the same undo step.\n */\n function setLayoutPositioning(ids: string[], positioning: SceneNode['layoutPositioning']) {\n // Read every place first: taking one layer out moves the siblings after it.\n const targets = ids.flatMap((id) => {\n const node = ctx.graph.getNode(id)\n const parent = node?.parentId ? ctx.graph.getNode(node.parentId) : undefined\n if (!node || !parent || parent.layoutMode === 'NONE') return []\n if (node.layoutPositioning === positioning) return []\n return [{ id, x: node.x, y: node.y }]\n })\n if (targets.length === 0) return\n const preview = beginNodePreview(\n positioning === 'ABSOLUTE' ? 'Ignore auto layout' : 'Use auto layout'\n )\n for (const { id, x, y } of targets) {\n preview.update(\n id,\n positioning === 'ABSOLUTE'\n ? { layoutPositioning: positioning, x, y }\n : { layoutPositioning: positioning }\n )\n }\n preview.commit()\n }\n\n return { setLayoutMode, setLayoutPositioning }\n}\n\nfunction layoutModeUpdates(\n ctx: EditorContext,\n node: SceneNode,\n id: string,\n mode: LayoutMode\n): Partial<SceneNode> {\n const updates: Partial<SceneNode> = { layoutMode: mode }\n if (mode === 'GRID' && node.layoutMode !== 'GRID') {\n applyGridDefaults(ctx, node, id, updates)\n } else if (mode === 'NONE') {\n // A frame with no flow cannot wrap, align or space one, and the format stores none of it, so\n // the frame gives them all up rather than reopening with them dropped.\n Object.assign(updates, {\n itemSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n counterAxisSpacing: 0,\n layoutDirection: 'AUTO'\n })\n } else if (node.layoutMode === 'NONE') {\n Object.assign(updates, autoLayoutDefaults())\n }\n return updates\n}\n\nfunction applyGridDefaults(\n ctx: EditorContext,\n node: SceneNode,\n id: string,\n updates: Partial<SceneNode>\n) {\n const children = ctx.graph.getChildren(id)\n const cols = Math.max(2, Math.ceil(Math.sqrt(children.length)))\n const rows = Math.max(1, Math.ceil(children.length / cols))\n updates.gridTemplateColumns = Array.from({ length: cols }, () => ({\n sizing: 'FR' as const,\n value: 1\n }))\n updates.gridTemplateRows = Array.from({ length: rows }, () => ({\n sizing: 'FR' as const,\n value: 1\n }))\n updates.gridColumnGap = 0\n updates.gridRowGap = 0\n updates.primaryAxisSizing = 'FIXED'\n updates.counterAxisSizing = 'FIXED'\n if (node.primaryAxisSizing === 'HUG' || node.counterAxisSizing === 'HUG') {\n const maxChildW = Math.max(...children.map((child) => child.width), 100)\n const maxChildH = Math.max(...children.map((child) => child.height), 100)\n updates.width = maxChildW * cols\n updates.height = maxChildH * rows\n }\n updates.paddingTop = 0\n updates.paddingRight = 0\n updates.paddingBottom = 0\n updates.paddingLeft = 0\n}\n\nfunction autoLayoutDefaults(): Partial<SceneNode> {\n return {\n itemSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n primaryAxisSizing: 'HUG',\n counterAxisSizing: 'HUG',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN'\n }\n}\n"],"mappings":";AAKA,SAAgB,wBACd,KACA,kBACA;;;;;;CAMA,SAAS,cAAc,IAAY,MAAkB;EACnD,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;EACjC,IAAI,CAAC,QAAQ,KAAK,eAAe,MAAM;EACvC,MAAM,UAAU,iBAAiB,SAAS,SAAS,uBAAuB,iBAAiB;EAE3F,IAAI,KAAK,SAAS,WAAW,SAAS,QAAQ,QAAQ,OAAO,IAAI,EAAE,MAAM,QAAQ,CAAC;EAClF,QAAQ,OAAO,IAAI,kBAAkB,KAAK,MAAM,IAAI,IAAI,CAAC;EACzD,QAAQ,OAAO;CACjB;;;;;;CAOA,SAAS,qBAAqB,KAAe,aAA6C;EAExF,MAAM,UAAU,IAAI,SAAS,OAAO;GAClC,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;GACjC,MAAM,SAAS,MAAM,WAAW,IAAI,MAAM,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K,EAAE,QAAQ,KAAK,UAAU;EAChE,QAAQ;EACR,OAAO;CACT,EAAE;CACF,QAAQ,mBAAmB,MAAM,KAAK,EAAE,QAAQ,KAAK,UAAU;EAC7D,QAAQ;EACR,OAAO;CACT,EAAE;CACF,QAAQ,gBAAgB;CACxB,QAAQ,aAAa;CACrB,QAAQ,oBAAoB;CAC5B,QAAQ,oBAAoB;CAC5B,IAAI,KAAK,sBAAsB,SAAS,KAAK,sBAAsB,OAAO;EACxE,MAAM,YAAY,KAAK,IAAI,GAAG,SAAS,KAAK,UAAU,MAAM,KAAK,GAAG,GAAG;EACvE,MAAM,YAAY,KAAK,IAAI,GAAG,SAAS,KAAK,UAAU,MAAM,MAAM,GAAG,GAAG;EACxE,QAAQ,QAAQ,YAAY;EAC5B,QAAQ,SAAS,YAAY;CAC/B;CACA,QAAQ,aAAa;CACrB,QAAQ,eAAe;CACvB,QAAQ,gBAAgB;CACxB,QAAQ,cAAc;AACxB;AAEA,SAAS,qBAAyC;CAChD,OAAO;EACL,aAAa;EACb,YAAY;EACZ,cAAc;EACd,eAAe;EACf,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,kBAAkB;EAClB,kBAAkB;CACpB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-preview.d.ts","names":[],"sources":["../../src/editor/node-preview.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"node-preview.d.ts","names":[],"sources":["../../src/editor/node-preview.ts"],"mappings":";;;UAWiB;WACN;EACT,SAAS,YAAY,SAAS,QAAQ;EACtC;EACA;;;iBAUc,yBACd,KAAK,eACL,aAAa,YAAY,SAAS,QAAQ;EAQG,mBAAA,mBAAA"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
import { groupFitOptions } from "../canvas/boolean.js";
|
|
1
2
|
import { assertNodeEditable } from "./capabilities.js";
|
|
3
|
+
import { restoreSources } from "./history/sources.js";
|
|
2
4
|
import { isEqual, pick, uniq } from "es-toolkit";
|
|
5
|
+
import { fitEnclosingGroups, redoGroupFit, undoGroupFit } from "@pairdraw/scene-graph/group-bounds";
|
|
3
6
|
//#region src/editor/node-preview.ts
|
|
7
|
+
/** Whether an auto layout frame places this layer, so the boxes of the groups above it are theirs. */
|
|
8
|
+
function placedByParent(graph, id) {
|
|
9
|
+
const parent = graph.getNode(graph.getNode(id)?.parentId ?? "");
|
|
10
|
+
return parent !== void 0 && parent.layoutMode !== "NONE";
|
|
11
|
+
}
|
|
4
12
|
/** One owned numeric/property edit, including every node changed by its layout. */
|
|
5
13
|
function createNodePreviewActions(ctx, updateNode) {
|
|
6
14
|
let current = null;
|
|
@@ -13,7 +21,7 @@ function createNodePreviewActions(ctx, updateNode) {
|
|
|
13
21
|
const originals = /* @__PURE__ */ new Map();
|
|
14
22
|
const targets = /* @__PURE__ */ new Set();
|
|
15
23
|
const layoutOnly = /* @__PURE__ */ new Set();
|
|
16
|
-
const
|
|
24
|
+
const sourcesBefore = /* @__PURE__ */ new Map();
|
|
17
25
|
let closed = false;
|
|
18
26
|
let endInteraction;
|
|
19
27
|
const subscriptions = [];
|
|
@@ -30,7 +38,7 @@ function createNodePreviewActions(ctx, updateNode) {
|
|
|
30
38
|
}
|
|
31
39
|
function markEdited(node, changes) {
|
|
32
40
|
if (graph.isPreservingSourceMetadata) return;
|
|
33
|
-
if (!
|
|
41
|
+
if (!sourcesBefore.has(node.id)) sourcesBefore.set(node.id, structuredClone(node.source));
|
|
34
42
|
node.source.editedFields = uniq([...node.source.editedFields, ...Object.keys(changes)]);
|
|
35
43
|
}
|
|
36
44
|
function close() {
|
|
@@ -87,22 +95,33 @@ function createNodePreviewActions(ctx, updateNode) {
|
|
|
87
95
|
if (layoutOnly.has(edit.id)) graph.withLayoutMutations(update);
|
|
88
96
|
else update();
|
|
89
97
|
}
|
|
98
|
+
if (direction === "before") restoreSources(graph, sourcesBefore);
|
|
90
99
|
ctx.requestRender();
|
|
91
100
|
}
|
|
101
|
+
apply("after");
|
|
102
|
+
const parents = uniq(edits.filter((edit) => !placedByParent(graph, edit.id)).map((edit) => graph.getNode(edit.id)?.parentId ?? "")).filter((parentId) => parentId !== "");
|
|
103
|
+
const options = groupFitOptions(ctx.getRenderer(), graph);
|
|
104
|
+
const fits = parents.map((parentId) => fitEnclosingGroups(graph, [parentId], options)).filter((fit) => fit !== null);
|
|
105
|
+
for (const fit of fits) redoGroupFit(graph, fit);
|
|
92
106
|
ctx.undo.push({
|
|
93
107
|
label,
|
|
94
|
-
forward: () =>
|
|
95
|
-
|
|
108
|
+
forward: () => {
|
|
109
|
+
apply("after");
|
|
110
|
+
for (const fit of fits) redoGroupFit(graph, fit);
|
|
111
|
+
},
|
|
112
|
+
inverse: () => {
|
|
113
|
+
for (const fit of fits) undoGroupFit(graph, fit);
|
|
114
|
+
apply("before");
|
|
115
|
+
}
|
|
96
116
|
});
|
|
97
|
-
apply("after");
|
|
98
117
|
},
|
|
99
118
|
cancel() {
|
|
100
119
|
if (closed) return;
|
|
101
120
|
close();
|
|
102
121
|
for (const [id, previous] of originals) graph.updateNodePreview(id, structuredClone(previous));
|
|
103
|
-
for (const [id,
|
|
122
|
+
for (const [id, source] of sourcesBefore) {
|
|
104
123
|
const node = graph.getNode(id);
|
|
105
|
-
if (node) node.source
|
|
124
|
+
if (node) node.source = structuredClone(source);
|
|
106
125
|
}
|
|
107
126
|
if (originals.size) ctx.requestRender();
|
|
108
127
|
}
|