@pairdraw/core 0.21.1 → 0.22.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/boolean.d.ts +6 -1
- package/dist/canvas/boolean.d.ts.map +1 -1
- package/dist/canvas/boolean.js +10 -2
- package/dist/canvas/boolean.js.map +1 -1
- package/dist/canvas/color-space.d.ts +45 -0
- package/dist/canvas/color-space.d.ts.map +1 -0
- package/dist/canvas/color-space.js +39 -0
- package/dist/canvas/color-space.js.map +1 -0
- package/dist/canvas/fills.d.ts +10 -10
- package/dist/canvas/fills.d.ts.map +1 -1
- package/dist/canvas/fills.js +116 -62
- package/dist/canvas/fills.js.map +1 -1
- package/dist/canvas/flatten.d.ts +11 -3
- package/dist/canvas/flatten.d.ts.map +1 -1
- package/dist/canvas/flatten.js +62 -4
- package/dist/canvas/flatten.js.map +1 -1
- package/dist/canvas/images/previews.d.ts +1 -1
- package/dist/canvas/index.d.ts +2 -1
- package/dist/canvas/index.js +2 -1
- package/dist/canvas/layout-grids.d.ts +5 -2
- package/dist/canvas/layout-grids.d.ts.map +1 -1
- package/dist/canvas/layout-grids.js +7 -2
- package/dist/canvas/layout-grids.js.map +1 -1
- package/dist/canvas/noise/render.d.ts +17 -4
- package/dist/canvas/noise/render.d.ts.map +1 -1
- package/dist/canvas/noise/render.js +21 -6
- package/dist/canvas/noise/render.js.map +1 -1
- package/dist/canvas/noise/shader.d.ts +4 -4
- package/dist/canvas/noise/shader.d.ts.map +1 -1
- package/dist/canvas/noise/shader.js +5 -6
- package/dist/canvas/noise/shader.js.map +1 -1
- package/dist/canvas/overlays/annotations.d.ts +19 -0
- package/dist/canvas/overlays/annotations.d.ts.map +1 -0
- package/dist/canvas/overlays/annotations.js +110 -0
- package/dist/canvas/overlays/annotations.js.map +1 -0
- package/dist/canvas/overlays/auto-layout-hover.d.ts +11 -1
- package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
- package/dist/canvas/overlays/auto-layout-hover.js +25 -1
- package/dist/canvas/overlays/auto-layout-hover.js.map +1 -1
- package/dist/canvas/overlays/feedback.js +1 -1
- package/dist/canvas/overlays/feedback.js.map +1 -1
- package/dist/canvas/overlays/index.d.ts +2 -2
- package/dist/canvas/overlays/index.js +2 -2
- package/dist/canvas/overlays/measurement.d.ts +7 -1
- package/dist/canvas/overlays/measurement.d.ts.map +1 -1
- package/dist/canvas/overlays/measurement.js +42 -4
- package/dist/canvas/overlays/measurement.js.map +1 -1
- package/dist/canvas/overlays/presence.d.ts.map +1 -1
- package/dist/canvas/overlays/presence.js +21 -24
- package/dist/canvas/overlays/presence.js.map +1 -1
- package/dist/canvas/renderer/colors.d.ts +7 -1
- package/dist/canvas/renderer/colors.d.ts.map +1 -1
- package/dist/canvas/renderer/colors.js +9 -1
- package/dist/canvas/renderer/colors.js.map +1 -1
- package/dist/canvas/renderer/document-surface.d.ts +15 -6
- package/dist/canvas/renderer/document-surface.d.ts.map +1 -1
- package/dist/canvas/renderer/document-surface.js +1 -0
- package/dist/canvas/renderer/document-surface.js.map +1 -1
- package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +2 -2
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts +1 -0
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +4 -1
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
- package/dist/canvas/renderer/overlay-pass.js +6 -1
- package/dist/canvas/renderer/overlay-pass.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +7 -0
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/types.d.ts +10 -0
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer.d.ts +10 -2
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +15 -3
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +9 -9
- package/dist/canvas/scene.js.map +1 -1
- package/dist/clipboard/pairdraw.d.ts.map +1 -1
- package/dist/clipboard/pairdraw.js +1 -0
- package/dist/clipboard/pairdraw.js.map +1 -1
- package/dist/editor/bridges/clipboard.d.ts +2 -0
- package/dist/editor/bridges/clipboard.d.ts.map +1 -1
- package/dist/editor/bridges/clipboard.js +1 -0
- package/dist/editor/bridges/clipboard.js.map +1 -1
- package/dist/editor/bridges/components.d.ts +14 -7
- package/dist/editor/bridges/components.d.ts.map +1 -1
- package/dist/editor/bridges/components.js +6 -0
- package/dist/editor/bridges/components.js.map +1 -1
- package/dist/editor/bridges/structure.d.ts +1 -1
- package/dist/editor/bridges/structure.d.ts.map +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/clipboard/code.d.ts +32 -0
- package/dist/editor/clipboard/code.d.ts.map +1 -0
- package/dist/editor/clipboard/code.js +30 -0
- package/dist/editor/clipboard/code.js.map +1 -0
- package/dist/editor/clipboard/paste/dependencies.d.ts +14 -0
- package/dist/editor/clipboard/paste/dependencies.d.ts.map +1 -0
- package/dist/editor/clipboard/paste/dependencies.js +0 -0
- package/dist/editor/clipboard/paste/run.d.ts +14 -0
- package/dist/editor/clipboard/paste/run.d.ts.map +1 -0
- package/dist/editor/clipboard/paste/run.js +47 -0
- package/dist/editor/clipboard/paste/run.js.map +1 -0
- package/dist/editor/clipboard/styled.d.ts +2 -8
- package/dist/editor/clipboard/styled.d.ts.map +1 -1
- package/dist/editor/clipboard/styled.js +2 -32
- package/dist/editor/clipboard/styled.js.map +1 -1
- package/dist/editor/clipboard.d.ts +2 -0
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +34 -0
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/components/instances.d.ts +5 -0
- package/dist/editor/components/instances.d.ts.map +1 -1
- package/dist/editor/components/instances.js +69 -4
- package/dist/editor/components/instances.js.map +1 -1
- package/dist/editor/components/slots/index.d.ts.map +1 -1
- package/dist/editor/components/slots/index.js +7 -0
- package/dist/editor/components/slots/index.js.map +1 -1
- package/dist/editor/components.d.ts +6 -0
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor/components.js +14 -2
- package/dist/editor/components.js.map +1 -1
- package/dist/editor/create.d.ts +30 -3
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +11 -2
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/design-tokens.d.ts +1 -1
- package/dist/editor/design-tokens.d.ts.map +1 -1
- package/dist/editor/design-tokens.js +4 -18
- package/dist/editor/design-tokens.js.map +1 -1
- package/dist/editor/image-edit.d.ts.map +1 -1
- package/dist/editor/image-edit.js +1 -2
- package/dist/editor/image-edit.js.map +1 -1
- package/dist/editor/index.d.ts +4 -4
- package/dist/editor/index.js +1 -1
- package/dist/editor/layout-mode.d.ts +3 -1
- package/dist/editor/layout-mode.d.ts.map +1 -1
- package/dist/editor/layout-mode.js +97 -2
- package/dist/editor/layout-mode.js.map +1 -1
- package/dist/editor/nodes.d.ts +2 -0
- package/dist/editor/nodes.d.ts.map +1 -1
- package/dist/editor/nodes.js +22 -7
- package/dist/editor/nodes.js.map +1 -1
- package/dist/editor/read-only/actions.js +6 -0
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/selection/overlays.d.ts +1 -0
- package/dist/editor/selection/overlays.d.ts.map +1 -1
- package/dist/editor/selection/overlays.js +7 -0
- package/dist/editor/selection/overlays.js.map +1 -1
- package/dist/editor/selection/read.d.ts +8 -0
- package/dist/editor/selection.d.ts +9 -0
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/state/shared.js +1 -0
- package/dist/editor/state/shared.js.map +1 -1
- package/dist/editor/state/view.d.ts.map +1 -1
- package/dist/editor/state/view.js +2 -0
- package/dist/editor/state/view.js.map +1 -1
- package/dist/editor/structure/boolean.d.ts +1 -1
- package/dist/editor/structure/boolean.d.ts.map +1 -1
- package/dist/editor/structure/boolean.js +20 -1
- package/dist/editor/structure/boolean.js.map +1 -1
- package/dist/editor/structure/container-wrap.d.ts +8 -2
- package/dist/editor/structure/container-wrap.d.ts.map +1 -1
- package/dist/editor/structure/container-wrap.js +17 -5
- package/dist/editor/structure/container-wrap.js.map +1 -1
- package/dist/editor/structure/flatten.d.ts.map +1 -1
- package/dist/editor/structure/flatten.js +8 -7
- package/dist/editor/structure/flatten.js.map +1 -1
- package/dist/editor/structure/group/ungroup.d.ts.map +1 -1
- package/dist/editor/structure/group/ungroup.js +2 -0
- package/dist/editor/structure/group/ungroup.js.map +1 -1
- package/dist/editor/structure/outline-stroke.d.ts.map +1 -1
- package/dist/editor/structure/outline-stroke.js +5 -0
- package/dist/editor/structure/outline-stroke.js.map +1 -1
- package/dist/editor/structure.d.ts +1 -1
- package/dist/editor/structure.d.ts.map +1 -1
- package/dist/editor/styles.d.ts +26 -0
- package/dist/editor/styles.d.ts.map +1 -0
- package/dist/editor/styles.js +127 -0
- package/dist/editor/styles.js.map +1 -0
- package/dist/editor/text/selection-style.d.ts +1 -0
- package/dist/editor/text/selection-style.d.ts.map +1 -1
- package/dist/editor/text/selection-style.js +10 -2
- package/dist/editor/text/selection-style.js.map +1 -1
- package/dist/editor/tool-registry.d.ts.map +1 -1
- package/dist/editor/tool-registry.js +6 -0
- package/dist/editor/tool-registry.js.map +1 -1
- package/dist/editor/types.d.ts +14 -2
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/variable-bindings.d.ts.map +1 -1
- package/dist/editor/variable-bindings.js +6 -1
- package/dist/editor/variable-bindings.js.map +1 -1
- package/dist/figma-api/accessors/basic.d.ts.map +1 -1
- package/dist/figma-api/accessors/basic.js +22 -1
- package/dist/figma-api/accessors/basic.js.map +1 -1
- package/dist/figma-api/accessors/shape.js +1 -1
- package/dist/figma-api/accessors/text/index.js +1 -1
- package/dist/figma-api/accessors/text/ranges.js +1 -1
- package/dist/figma-api/accessors/text/references.js +1 -1
- package/dist/figma-api/accessors/variables.js +1 -1
- package/dist/figma-api/accessors/vector.d.ts.map +1 -1
- package/dist/figma-api/accessors/vector.js +8 -22
- package/dist/figma-api/accessors/vector.js.map +1 -1
- package/dist/figma-api/accessors/visual.js +1 -1
- package/dist/figma-api/compatibility.d.ts +1 -1
- package/dist/figma-api/compatibility.d.ts.map +1 -1
- package/dist/figma-api/component-scope.d.ts +14 -0
- package/dist/figma-api/component-scope.d.ts.map +1 -0
- package/dist/figma-api/component-scope.js +28 -0
- package/dist/figma-api/component-scope.js.map +1 -0
- package/dist/figma-api/components.d.ts.map +1 -1
- package/dist/figma-api/components.js +26 -2
- package/dist/figma-api/components.js.map +1 -1
- package/dist/figma-api/flatten.js +3 -3
- package/dist/figma-api/flatten.js.map +1 -1
- package/dist/figma-api/index.d.ts +77 -6
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +188 -2
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/node-types.d.ts +2 -1
- package/dist/figma-api/node-types.d.ts.map +1 -1
- package/dist/figma-api/overrides.d.ts +26 -1
- package/dist/figma-api/overrides.d.ts.map +1 -1
- package/dist/figma-api/overrides.js +157 -10
- package/dist/figma-api/overrides.js.map +1 -1
- package/dist/figma-api/proxy.d.ts +2 -0
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +10 -2
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +65 -9
- package/dist/figma-api/reactions.d.ts.map +1 -1
- package/dist/figma-api/reactions.js +144 -11
- package/dist/figma-api/reactions.js.map +1 -1
- package/dist/figma-api/shape-with-text.js +1 -1
- package/dist/figma-api/slots.d.ts +3 -1
- package/dist/figma-api/slots.d.ts.map +1 -1
- package/dist/figma-api/slots.js +9 -8
- package/dist/figma-api/slots.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/io/formats/code/detect.d.ts +23 -0
- package/dist/io/formats/code/detect.d.ts.map +1 -0
- package/dist/io/formats/code/detect.js +46 -0
- package/dist/io/formats/code/detect.js.map +1 -0
- package/dist/io/formats/code/index.d.ts +5 -0
- package/dist/io/formats/code/index.js +5 -0
- package/dist/io/formats/code/read.d.ts +45 -0
- package/dist/io/formats/code/read.d.ts.map +1 -0
- package/dist/io/formats/code/read.js +86 -0
- package/dist/io/formats/code/read.js.map +1 -0
- package/dist/io/formats/code/stylesheet.d.ts +13 -0
- package/dist/io/formats/code/stylesheet.d.ts.map +1 -0
- package/dist/io/formats/code/stylesheet.js +21 -0
- package/dist/io/formats/code/stylesheet.js.map +1 -0
- package/dist/io/formats/code/tokens.d.ts +18 -0
- package/dist/io/formats/code/tokens.d.ts.map +1 -0
- package/dist/io/formats/code/tokens.js +135 -0
- package/dist/io/formats/code/tokens.js.map +1 -0
- package/dist/io/formats/design-tokens/apply.d.ts +7 -3
- package/dist/io/formats/design-tokens/apply.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/apply.js.map +1 -1
- package/dist/io/formats/fig/export/patch/fields.js +5 -0
- package/dist/io/formats/fig/export/patch/fields.js.map +1 -1
- package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/patch/index.js +20 -20
- package/dist/io/formats/fig/export/patch/index.js.map +1 -1
- package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
- package/dist/io/formats/fig/export/setup.js +5 -1
- package/dist/io/formats/fig/export/setup.js.map +1 -1
- package/dist/io/formats/fig/index.d.ts +3 -2
- package/dist/io/formats/fig/index.js +2 -2
- package/dist/io/formats/fig/read.d.ts.map +1 -1
- package/dist/io/formats/fig/read.js +5 -2
- package/dist/io/formats/fig/read.js.map +1 -1
- package/dist/io/formats/html/layers.d.ts +3 -1
- package/dist/io/formats/html/layers.d.ts.map +1 -1
- package/dist/io/formats/html/layers.js +6 -1
- package/dist/io/formats/html/layers.js.map +1 -1
- package/dist/io/formats/pdf/export.d.ts.map +1 -1
- package/dist/io/formats/pdf/export.js +7 -3
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/pdf/plan.d.ts +3 -0
- package/dist/io/formats/pdf/plan.d.ts.map +1 -1
- package/dist/io/formats/pdf/plan.js +60 -36
- package/dist/io/formats/pdf/plan.js.map +1 -1
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +3 -2
- package/dist/io/formats/raster/headless.js.map +1 -1
- package/dist/io/formats/raster/index.d.ts +2 -2
- package/dist/io/formats/raster/index.js +2 -2
- package/dist/io/formats/raster/render.d.ts +10 -2
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +35 -9
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +19 -1
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts +5 -2
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +59 -10
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/index.d.ts +2 -2
- package/dist/io/formats/svg/index.js +2 -2
- package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
- package/dist/io/formats/svg/text/layout.js +4 -2
- package/dist/io/formats/svg/text/layout.js.map +1 -1
- package/dist/io/formats/video/record.d.ts.map +1 -1
- package/dist/io/formats/video/record.js +24 -9
- package/dist/io/formats/video/record.js.map +1 -1
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +20 -13
- package/dist/io/formats.js.map +1 -1
- package/dist/kiwi/fig/population/client.d.ts.map +1 -1
- package/dist/kiwi/fig/population/client.js +2 -1
- package/dist/kiwi/fig/population/client.js.map +1 -1
- package/dist/kiwi/fig/session/document-state.d.ts +46 -2
- package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
- package/dist/kiwi/fig/session/document-state.js +113 -5
- package/dist/kiwi/fig/session/document-state.js.map +1 -1
- package/dist/kiwi/fig/session/options.d.ts +4 -0
- package/dist/kiwi/fig/session/options.d.ts.map +1 -1
- package/dist/kiwi/fig/session/options.js.map +1 -1
- package/dist/layout/apply.d.ts.map +1 -1
- package/dist/layout/apply.js +8 -4
- package/dist/layout/apply.js.map +1 -1
- package/dist/layout/auto-layout-handles.js +1 -1
- package/dist/layout/auto-layout-handles.js.map +1 -1
- package/dist/layout/axis-sizing.d.ts.map +1 -1
- package/dist/layout/axis-sizing.js +1 -1
- package/dist/layout/axis-sizing.js.map +1 -1
- package/dist/layout/derived.d.ts.map +1 -1
- package/dist/layout/derived.js +1 -1
- package/dist/layout/derived.js.map +1 -1
- package/dist/layout/effective-generated-text.js +1 -1
- package/dist/layout/effective-generated-text.js.map +1 -1
- package/dist/layout/grid.d.ts +3 -1
- package/dist/layout/grid.d.ts.map +1 -1
- package/dist/layout/grid.js +57 -16
- package/dist/layout/grid.js.map +1 -1
- package/dist/layout.d.ts +1 -1
- package/dist/layout.js +6 -5
- package/dist/layout.js.map +1 -1
- package/dist/node/fs.d.ts.map +1 -1
- package/dist/node/fs.js +28 -7
- package/dist/node/fs.js.map +1 -1
- package/dist/prototype/easing.d.ts +13 -5
- package/dist/prototype/easing.d.ts.map +1 -1
- package/dist/prototype/easing.js +46 -6
- package/dist/prototype/easing.js.map +1 -1
- package/dist/prototype/scenes.d.ts +31 -0
- package/dist/prototype/scenes.d.ts.map +1 -1
- package/dist/prototype/scenes.js +220 -31
- package/dist/prototype/scenes.js.map +1 -1
- package/dist/prototype/session.d.ts.map +1 -1
- package/dist/prototype/session.js +1 -0
- package/dist/prototype/session.js.map +1 -1
- package/dist/prototype/smart-animate/animation.d.ts +2 -1
- package/dist/prototype/smart-animate/animation.d.ts.map +1 -1
- package/dist/prototype/smart-animate/animation.js +2 -2
- package/dist/prototype/smart-animate/animation.js.map +1 -1
- package/dist/prototype/timeline.d.ts +10 -1
- package/dist/prototype/timeline.d.ts.map +1 -1
- package/dist/prototype/timeline.js +69 -23
- package/dist/prototype/timeline.js.map +1 -1
- package/dist/prototype/variables.d.ts +23 -0
- package/dist/prototype/variables.d.ts.map +1 -0
- package/dist/prototype/variables.js +237 -0
- package/dist/prototype/variables.js.map +1 -0
- package/dist/rpc/read-commands.d.ts +5 -0
- package/dist/rpc/read-commands.d.ts.map +1 -1
- package/dist/rpc/read-commands.js +4 -1
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/text/character-style.d.ts +8 -1
- package/dist/text/character-style.d.ts.map +1 -1
- package/dist/text/character-style.js +39 -1
- package/dist/text/character-style.js.map +1 -1
- package/dist/text/font/batch.d.ts +26 -0
- package/dist/text/font/batch.d.ts.map +1 -0
- package/dist/text/font/batch.js +31 -0
- package/dist/text/font/batch.js.map +1 -0
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +14 -1
- package/dist/text/font/manager.js.map +1 -1
- package/dist/text/index.d.ts +3 -2
- package/dist/text/index.js +3 -2
- package/dist/tools/create/basic.js +3 -4
- package/dist/tools/create/basic.js.map +1 -1
- package/dist/tools/create/behaviours.js +1 -1
- package/dist/tools/create/code.d.ts +6 -0
- package/dist/tools/create/code.d.ts.map +1 -0
- package/dist/tools/create/code.js +68 -0
- package/dist/tools/create/code.js.map +1 -0
- package/dist/tools/create/html.d.ts.map +1 -1
- package/dist/tools/create/html.js +9 -57
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.js +1 -1
- package/dist/tools/create/inputs.d.ts +11 -0
- package/dist/tools/create/inputs.d.ts.map +1 -0
- package/dist/tools/create/inputs.js +15 -0
- package/dist/tools/create/inputs.js.map +1 -0
- package/dist/tools/create/mermaid.d.ts.map +1 -1
- package/dist/tools/create/mermaid.js +5 -6
- package/dist/tools/create/mermaid.js.map +1 -1
- package/dist/tools/create/place.d.ts +30 -0
- package/dist/tools/create/place.d.ts.map +1 -0
- package/dist/tools/create/place.js +70 -0
- package/dist/tools/create/place.js.map +1 -0
- package/dist/tools/create/render.js +1 -1
- package/dist/tools/create/svg.js +1 -1
- package/dist/tools/create/vector.js +1 -1
- package/dist/tools/create.d.ts +2 -1
- package/dist/tools/create.js +2 -1
- package/dist/tools/css/gradient.d.ts +28 -0
- package/dist/tools/css/gradient.d.ts.map +1 -0
- package/dist/tools/css/gradient.js +118 -0
- package/dist/tools/css/gradient.js.map +1 -0
- package/dist/tools/image-ai/generate.js +1 -1
- package/dist/tools/modify/geometry.js +5 -5
- package/dist/tools/modify/geometry.js.map +1 -1
- package/dist/tools/modify/layout.d.ts.map +1 -1
- package/dist/tools/modify/layout.js +7 -1
- package/dist/tools/modify/layout.js.map +1 -1
- package/dist/tools/modify/matching.js +1 -1
- package/dist/tools/modify/overrides.d.ts +6 -0
- package/dist/tools/modify/overrides.d.ts.map +1 -0
- package/dist/tools/modify/overrides.js +27 -0
- package/dist/tools/modify/overrides.js.map +1 -0
- package/dist/tools/modify/paint.d.ts.map +1 -1
- package/dist/tools/modify/paint.js +84 -39
- package/dist/tools/modify/paint.js.map +1 -1
- package/dist/tools/modify/text.d.ts +2 -1
- package/dist/tools/modify/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +79 -8
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/modify/update.d.ts.map +1 -1
- package/dist/tools/modify/update.js +18 -2
- package/dist/tools/modify/update.js.map +1 -1
- package/dist/tools/modify.d.ts +3 -2
- package/dist/tools/modify.js +3 -2
- package/dist/tools/read/css.d.ts.map +1 -1
- package/dist/tools/read/css.js +29 -12
- package/dist/tools/read/css.js.map +1 -1
- package/dist/tools/read/libraries.js +1 -1
- package/dist/tools/read/nodes.d.ts.map +1 -1
- package/dist/tools/read/nodes.js +19 -5
- package/dist/tools/read/nodes.js.map +1 -1
- package/dist/tools/registry/extended.d.ts.map +1 -1
- package/dist/tools/registry/extended.js +6 -1
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/text-range.d.ts +11 -0
- package/dist/tools/text-range.d.ts.map +1 -0
- package/dist/tools/text-range.js +26 -0
- package/dist/tools/text-range.js.map +1 -0
- package/dist/tools/variables/bindings.js +1 -1
- package/dist/tools/variables/bindings.js.map +1 -1
- package/dist/tools/variables/unbind.js +1 -1
- package/dist/tools/variables/unbind.js.map +1 -1
- package/dist/tools/vector/path.d.ts.map +1 -1
- package/dist/tools/vector/path.js +7 -21
- package/dist/tools/vector/path.js.map +1 -1
- package/dist/vector/rebase.d.ts +17 -0
- package/dist/vector/rebase.d.ts.map +1 -0
- package/dist/vector/rebase.js +32 -0
- package/dist/vector/rebase.js.map +1 -0
- package/package.json +14 -9
- package/src/canvas/boolean.ts +12 -1
- package/src/canvas/color-space.ts +73 -0
- package/src/canvas/fills.ts +130 -83
- package/src/canvas/flatten.ts +92 -7
- package/src/canvas/index.ts +9 -0
- package/src/canvas/layout-grids.ts +15 -2
- package/src/canvas/noise/render.ts +35 -7
- package/src/canvas/noise/shader.ts +8 -10
- package/src/canvas/overlays/annotations.ts +117 -0
- package/src/canvas/overlays/auto-layout-hover.ts +41 -1
- package/src/canvas/overlays/feedback.ts +7 -2
- package/src/canvas/overlays/index.ts +1 -1
- package/src/canvas/overlays/measurement.ts +49 -3
- package/src/canvas/overlays/presence.ts +35 -32
- package/src/canvas/renderer/colors.ts +14 -0
- package/src/canvas/renderer/document-surface.ts +16 -6
- package/src/canvas/renderer/lifecycle.ts +2 -2
- package/src/canvas/renderer/methods.ts +4 -0
- package/src/canvas/renderer/overlay-pass.ts +4 -0
- package/src/canvas/renderer/pipeline.ts +8 -0
- package/src/canvas/renderer/types.ts +8 -0
- package/src/canvas/renderer.ts +21 -2
- package/src/canvas/scene.ts +15 -7
- package/src/clipboard/pairdraw.ts +1 -0
- package/src/editor/bridges/clipboard.ts +1 -0
- package/src/editor/bridges/components.ts +10 -0
- package/src/editor/clipboard/code.ts +50 -0
- package/src/editor/clipboard/paste/dependencies.ts +18 -0
- package/src/editor/clipboard/paste/run.ts +64 -0
- package/src/editor/clipboard/styled.ts +4 -52
- package/src/editor/clipboard.ts +40 -0
- package/src/editor/components/instances.ts +92 -4
- package/src/editor/components/slots/index.ts +7 -0
- package/src/editor/components.ts +16 -2
- package/src/editor/create.ts +15 -1
- package/src/editor/design-tokens.ts +3 -23
- package/src/editor/image-edit.ts +5 -2
- package/src/editor/index.ts +1 -0
- package/src/editor/layout-mode.ts +131 -3
- package/src/editor/nodes.ts +30 -5
- package/src/editor/read-only/actions.ts +6 -0
- package/src/editor/selection/overlays.ts +8 -0
- package/src/editor/state/shared.ts +1 -0
- package/src/editor/state/view.ts +2 -0
- package/src/editor/structure/boolean.ts +29 -1
- package/src/editor/structure/container-wrap.ts +20 -4
- package/src/editor/structure/flatten.ts +15 -8
- package/src/editor/structure/group/ungroup.ts +2 -0
- package/src/editor/structure/outline-stroke.ts +5 -0
- package/src/editor/styles.ts +203 -0
- package/src/editor/text/selection-style.ts +18 -1
- package/src/editor/tool-registry.ts +2 -0
- package/src/editor/types.ts +14 -0
- package/src/editor/variable-bindings.ts +11 -0
- package/src/figma-api/accessors/basic.ts +33 -1
- package/src/figma-api/accessors/vector.ts +6 -13
- package/src/figma-api/compatibility.ts +1 -0
- package/src/figma-api/component-scope.ts +36 -0
- package/src/figma-api/components.ts +24 -0
- package/src/figma-api/flatten.ts +7 -3
- package/src/figma-api/index.ts +302 -6
- package/src/figma-api/node-types.ts +1 -0
- package/src/figma-api/overrides.ts +192 -5
- package/src/figma-api/proxy.ts +16 -1
- package/src/figma-api/reactions.ts +163 -12
- package/src/figma-api/slots.ts +10 -9
- package/src/io/formats/code/detect.ts +67 -0
- package/src/io/formats/code/index.ts +17 -0
- package/src/io/formats/code/read.ts +143 -0
- package/src/io/formats/code/stylesheet.ts +24 -0
- package/src/io/formats/code/tokens.ts +159 -0
- package/src/io/formats/design-tokens/apply.ts +3 -2
- package/src/io/formats/fig/export/patch/fields.ts +11 -0
- package/src/io/formats/fig/export/patch/index.ts +23 -19
- package/src/io/formats/fig/export/setup.ts +8 -1
- package/src/io/formats/fig/index.ts +6 -0
- package/src/io/formats/fig/read.ts +11 -2
- package/src/io/formats/html/layers.ts +7 -0
- package/src/io/formats/pdf/export.ts +19 -7
- package/src/io/formats/pdf/plan.ts +71 -32
- package/src/io/formats/raster/headless.ts +3 -1
- package/src/io/formats/raster/index.ts +2 -0
- package/src/io/formats/raster/render.ts +49 -9
- package/src/io/formats/svg/defs.ts +27 -1
- package/src/io/formats/svg/export.ts +75 -13
- package/src/io/formats/svg/index.ts +1 -0
- package/src/io/formats/svg/text/layout.ts +5 -3
- package/src/io/formats/video/record.ts +33 -9
- package/src/io/formats.ts +35 -15
- package/src/kiwi/fig/population/client.ts +6 -1
- package/src/kiwi/fig/session/document-state.ts +195 -5
- package/src/kiwi/fig/session/options.ts +2 -0
- package/src/layout/apply.ts +12 -4
- package/src/layout/auto-layout-handles.ts +1 -1
- package/src/layout/axis-sizing.ts +3 -1
- package/src/layout/derived.ts +3 -1
- package/src/layout/effective-generated-text.ts +1 -1
- package/src/layout/grid.ts +91 -21
- package/src/layout.ts +16 -3
- package/src/node/fs.ts +32 -7
- package/src/prototype/easing.ts +79 -7
- package/src/prototype/scenes.ts +244 -15
- package/src/prototype/session.ts +1 -0
- package/src/prototype/smart-animate/animation.ts +4 -3
- package/src/prototype/timeline.ts +118 -26
- package/src/prototype/variables.ts +189 -0
- package/src/rpc/read-commands.ts +19 -1
- package/src/text/character-style.ts +47 -0
- package/src/text/font/batch.ts +58 -0
- package/src/text/font/manager.ts +17 -1
- package/src/text/index.ts +2 -1
- package/src/tools/create/basic.ts +2 -3
- package/src/tools/create/code.ts +85 -0
- package/src/tools/create/html.ts +9 -46
- package/src/tools/create/inputs.ts +12 -0
- package/src/tools/create/mermaid.ts +6 -6
- package/src/tools/create/place.ts +80 -0
- package/src/tools/create.ts +1 -0
- package/src/tools/css/gradient.ts +147 -0
- package/src/tools/modify/geometry.ts +5 -5
- package/src/tools/modify/layout.ts +19 -0
- package/src/tools/modify/overrides.ts +35 -0
- package/src/tools/modify/paint.ts +124 -54
- package/src/tools/modify/text.ts +91 -7
- package/src/tools/modify/update.ts +23 -2
- package/src/tools/modify.ts +9 -1
- package/src/tools/read/css.ts +46 -12
- package/src/tools/read/nodes.ts +26 -4
- package/src/tools/registry/extended.ts +6 -0
- package/src/tools/text-range.ts +29 -0
- package/src/tools/variables/bindings.ts +4 -1
- package/src/tools/variables/unbind.ts +4 -1
- package/src/tools/vector/path.ts +11 -13
- package/src/vector/rebase.ts +33 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { prepareSlotEdits } from "../components/slots/index.js";
|
|
2
2
|
import { nextNumberedName } from "./rename.js";
|
|
3
|
+
import { slotScope } from "@pairdraw/scene-graph/slots";
|
|
3
4
|
import { getAxisAlignedBoundsInParent } from "@pairdraw/scene-graph/coordinate";
|
|
4
5
|
import { groupBounds } from "@pairdraw/scene-graph/group-bounds";
|
|
5
6
|
//#region src/editor/structure/container-wrap.ts
|
|
@@ -17,14 +18,25 @@ const NUMBERED_WHEN_WRAPPED = /* @__PURE__ */ new Set([
|
|
|
17
18
|
]);
|
|
18
19
|
/**
|
|
19
20
|
* The parent these layers share when a new container may go there, or null when they are not
|
|
20
|
-
* siblings or sit in the locked part of an instance.
|
|
21
|
+
* siblings or sit in the locked part of an instance. Reads only: callers that need a slot
|
|
22
|
+
* claimed for the edit do it through `wrapParentId`.
|
|
21
23
|
*/
|
|
22
|
-
function
|
|
24
|
+
function wrappableParentId(ctx, nodes) {
|
|
23
25
|
const first = nodes.at(0);
|
|
24
26
|
if (!first) return null;
|
|
25
27
|
const parentId = first.parentId ?? ctx.state.currentPageId;
|
|
26
28
|
if (nodes.some((node) => (node.parentId ?? ctx.state.currentPageId) !== parentId)) return null;
|
|
27
|
-
|
|
29
|
+
if (ctx.graph.getNode(parentId)?.type === "SLICE") return null;
|
|
30
|
+
if (slotScope(ctx.graph, parentId).kind === "locked") return null;
|
|
31
|
+
return parentId;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The parent that may take a new container, claiming an untouched slot first so the edit lands
|
|
35
|
+
* in content the instance owns. This mutates; capability checks use `wrappableParentId`.
|
|
36
|
+
*/
|
|
37
|
+
function wrapParentId(ctx, nodes) {
|
|
38
|
+
const parentId = wrappableParentId(ctx, nodes);
|
|
39
|
+
return parentId && prepareSlotEdits(ctx, [parentId]) ? parentId : null;
|
|
28
40
|
}
|
|
29
41
|
/**
|
|
30
42
|
* Wraps sibling layers in a new container that spans them, keeping them where they are on the
|
|
@@ -79,7 +91,7 @@ function wrapSelectionInContainer(ctx, containerType, selectedNodes, extraProps)
|
|
|
79
91
|
const containerId = containerNode.id;
|
|
80
92
|
ctx.setSelectedIds(/* @__PURE__ */ new Set([containerId]));
|
|
81
93
|
ctx.undo.push({
|
|
82
|
-
label: `Create ${containerType.toLowerCase().replace("_", " ")}`,
|
|
94
|
+
label: containerType === "COMPONENT_SET" ? "Combine as variants" : `Create ${containerType.toLowerCase().replace("_", " ")}`,
|
|
83
95
|
forward: () => {
|
|
84
96
|
const nodes = origPositions.flatMap((n) => ctx.graph.getNode(n.id) ?? []);
|
|
85
97
|
wrapNodes(ctx.graph, containerType, nodes, parentId, index, {
|
|
@@ -105,6 +117,6 @@ function wrapSelectionInContainer(ctx, containerType, selectedNodes, extraProps)
|
|
|
105
117
|
return containerId;
|
|
106
118
|
}
|
|
107
119
|
//#endregion
|
|
108
|
-
export { canvasWrapIndex, inStackOrder, wrapNodes, wrapParentId, wrapSelectionInContainer };
|
|
120
|
+
export { canvasWrapIndex, inStackOrder, wrapNodes, wrapParentId, wrapSelectionInContainer, wrappableParentId };
|
|
109
121
|
|
|
110
122
|
//# sourceMappingURL=container-wrap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container-wrap.js","names":[],"sources":["../../../src/editor/structure/container-wrap.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { getAxisAlignedBoundsInParent } from '@pairdraw/scene-graph/coordinate'\nimport { groupBounds } from '@pairdraw/scene-graph/group-bounds'\n\nimport { prepareSlotEdits } from '#core/editor/components/slots'\nimport { nextNumberedName } from '#core/editor/structure/rename'\nimport type { EditorContext } from '#core/editor/types'\n\nexport type WrapContainerType =\n | 'GROUP'\n | 'FRAME'\n | 'COMPONENT'\n | 'COMPONENT_SET'\n | 'BOOLEAN_OPERATION'\n\nconst CONTAINER_NAMES: Record<WrapContainerType, string> = {\n BOOLEAN_OPERATION: 'Boolean',\n COMPONENT_SET: 'Component Set',\n COMPONENT: 'Component',\n GROUP: 'Group',\n FRAME: 'Frame'\n}\n\nconst NUMBERED_WHEN_WRAPPED: ReadonlySet<WrapContainerType> = new Set([\n 'GROUP',\n 'FRAME',\n 'COMPONENT'\n])\n\n/**\n * The parent these layers share when a new container may go there, or null when they are not\n * siblings or sit in the locked part of an instance
|
|
1
|
+
{"version":3,"file":"container-wrap.js","names":[],"sources":["../../../src/editor/structure/container-wrap.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { getAxisAlignedBoundsInParent } from '@pairdraw/scene-graph/coordinate'\nimport { groupBounds } from '@pairdraw/scene-graph/group-bounds'\nimport { slotScope } from '@pairdraw/scene-graph/slots'\n\nimport { prepareSlotEdits } from '#core/editor/components/slots'\nimport { nextNumberedName } from '#core/editor/structure/rename'\nimport type { EditorContext } from '#core/editor/types'\n\nexport type WrapContainerType =\n | 'GROUP'\n | 'FRAME'\n | 'COMPONENT'\n | 'COMPONENT_SET'\n | 'BOOLEAN_OPERATION'\n\nconst CONTAINER_NAMES: Record<WrapContainerType, string> = {\n BOOLEAN_OPERATION: 'Boolean',\n COMPONENT_SET: 'Component Set',\n COMPONENT: 'Component',\n GROUP: 'Group',\n FRAME: 'Frame'\n}\n\nconst NUMBERED_WHEN_WRAPPED: ReadonlySet<WrapContainerType> = new Set([\n 'GROUP',\n 'FRAME',\n 'COMPONENT'\n])\n\n/**\n * The parent these layers share when a new container may go there, or null when they are not\n * siblings or sit in the locked part of an instance. Reads only: callers that need a slot\n * claimed for the edit do it through `wrapParentId`.\n */\nexport function wrappableParentId(ctx: EditorContext, nodes: readonly SceneNode[]): string | null {\n const first = nodes.at(0)\n if (!first) return null\n const parentId = first.parentId ?? ctx.state.currentPageId\n if (nodes.some((node) => (node.parentId ?? ctx.state.currentPageId) !== parentId)) return null\n if (ctx.graph.getNode(parentId)?.type === 'SLICE') return null\n if (slotScope(ctx.graph, parentId).kind === 'locked') return null\n return parentId\n}\n\n/**\n * The parent that may take a new container, claiming an untouched slot first so the edit lands\n * in content the instance owns. This mutates; capability checks use `wrappableParentId`.\n */\nexport function wrapParentId(ctx: EditorContext, nodes: readonly SceneNode[]): string | null {\n const parentId = wrappableParentId(ctx, nodes)\n return parentId && prepareSlotEdits(ctx, [parentId]) ? parentId : null\n}\n\n/**\n * Wraps sibling layers in a new container that spans them, keeping them where they are on the\n * canvas. The container goes to `index` among the parent's remaining children, or on top when\n * `index` is omitted. The editor's wrap commands and the plugin API's `group`, boolean\n * operations, and `createComponentFromNode` all wrap through here; `props` gives the look.\n */\nexport function wrapNodes(\n graph: SceneGraph,\n type: WrapContainerType,\n nodes: readonly SceneNode[],\n parentId: string,\n index: number | undefined,\n props: Partial<SceneNode> = {}\n): SceneNode {\n // A group spans only the layers it shows, as Figma's does; other containers span them all.\n const bounds =\n type === 'GROUP'\n ? groupBounds(graph, inStackOrder(graph, nodes, parentId), parentId, { x: 0, y: 0 })\n : getAxisAlignedBoundsInParent(nodes, parentId, graph)\n const container = graph.createNode(type, parentId, {\n name: CONTAINER_NAMES[type],\n ...bounds,\n fills: [],\n ...props\n })\n for (const node of inStackOrder(graph, nodes, parentId)) {\n graph.reparentNode(node.id, container.id)\n }\n if (index !== undefined) graph.insertChildAt(container.id, parentId, index)\n return container\n}\n\n/** Sibling layers bottom to top, whatever order they were selected in. */\nexport function inStackOrder(\n graph: SceneGraph,\n nodes: readonly SceneNode[],\n parentId: string\n): SceneNode[] {\n const order = graph.getNode(parentId)?.childIds ?? []\n return nodes.toSorted((a, b) => order.indexOf(a.id) - order.indexOf(b.id))\n}\n\n/**\n * Where Figma's canvas commands put a container made from `nodes`: in the topmost one's place,\n * counted among the children left once they move into it.\n */\nexport function canvasWrapIndex(parent: SceneNode, nodes: readonly SceneNode[]): number {\n return Math.max(...nodes.map((node) => parent.childIds.indexOf(node.id))) - (nodes.length - 1)\n}\n\nexport function wrapSelectionInContainer(\n ctx: EditorContext,\n containerType: WrapContainerType,\n selectedNodes: SceneNode[],\n extraProps?: Partial<SceneNode>\n) {\n const parentId = wrapParentId(ctx, selectedNodes)\n const parent = parentId ? ctx.graph.getNode(parentId) : undefined\n if (!parentId || !parent) return null\n\n const prevSelection = new Set(ctx.state.selectedIds)\n const origPositions = selectedNodes\n .map((n) => ({ id: n.id, x: n.x, y: n.y, index: parent.childIds.indexOf(n.id) }))\n .toSorted((a, b) => a.index - b.index)\n const index = canvasWrapIndex(parent, selectedNodes)\n\n // Figma numbers a group, frame, or component the canvas wraps layers in, as \"Group 1\".\n const name = NUMBERED_WHEN_WRAPPED.has(containerType)\n ? nextNumberedName(ctx.graph, parentId, CONTAINER_NAMES[containerType])\n : undefined\n const containerNode = wrapNodes(ctx.graph, containerType, selectedNodes, parentId, index, {\n ...(name ? { name } : {}),\n ...extraProps\n })\n const containerId = containerNode.id\n ctx.setSelectedIds(new Set([containerId]))\n\n ctx.undo.push({\n label:\n containerType === 'COMPONENT_SET'\n ? 'Combine as variants'\n : `Create ${containerType.toLowerCase().replace('_', ' ')}`,\n forward: () => {\n const nodes = origPositions.flatMap((n) => ctx.graph.getNode(n.id) ?? [])\n wrapNodes(ctx.graph, containerType, nodes, parentId, index, {\n ...containerNode,\n childIds: [],\n id: containerId\n })\n ctx.setSelectedIds(new Set([containerId]))\n },\n inverse: () => {\n for (const orig of origPositions) {\n ctx.graph.reparentNode(orig.id, parentId)\n ctx.graph.updateNode(orig.id, { x: orig.x, y: orig.y })\n }\n ctx.graph.deleteNode(containerId)\n // Back to their own places in the stack, lowest first so each index is still free.\n for (const orig of origPositions) ctx.graph.insertChildAt(orig.id, parentId, orig.index)\n ctx.setSelectedIds(prevSelection)\n }\n })\n\n return containerId\n}\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten.d.ts","names":[],"sources":["../../../src/editor/structure/flatten.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"flatten.d.ts","names":[],"sources":["../../../src/editor/structure/flatten.ts"],"mappings":";;;;KAUK,4BAA4B;KAE5B;EACH;EACA,kBAAkB,MAAM;EACxB,qBAAqB;;iBAGP,gBACd,KAAK,eACL,eAAe,aACf,UAAS"}
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import { canMakeBooleanSourceNode } from "../../canvas/boolean.js";
|
|
2
|
-
import { flattenNodesToVectorProps } from "../../canvas/flatten.js";
|
|
1
|
+
import { canContainFlattenableChildren, canMakeBooleanSourceNode } from "../../canvas/boolean.js";
|
|
2
|
+
import { flattenLayerToVectorProps, flattenNodesToVectorProps } from "../../canvas/flatten.js";
|
|
3
3
|
import { restoreSubtree, snapshotSubtree } from "../history/subtree.js";
|
|
4
4
|
import { selectedNodesInSharedParent } from "./selection.js";
|
|
5
|
+
import { assertGroupPlacement } from "@pairdraw/scene-graph/slots";
|
|
5
6
|
//#region src/editor/structure/flatten.ts
|
|
6
7
|
function flattenSelected(ctx, selectedNodes, options = {}) {
|
|
7
8
|
const label = options.label ?? "Flatten";
|
|
8
9
|
const canFlattenNode = options.canFlattenNode ?? ((node) => canMakeBooleanSourceNode(node, ctx.graph));
|
|
9
10
|
const vectorPropsFactory = options.vectorPropsFactory ?? flattenNodesToVectorProps;
|
|
10
|
-
const renderer = ctx.getRenderer();
|
|
11
|
-
if (!renderer) return null;
|
|
12
11
|
const selection = selectedNodesInSharedParent(ctx, selectedNodes);
|
|
13
12
|
if (!selection) return null;
|
|
14
13
|
const { topLevel, parentId, parent } = selection;
|
|
15
14
|
if (topLevel.some((node) => !canFlattenNode(node))) return null;
|
|
16
15
|
const childIds = topLevel.map((node) => node.id);
|
|
16
|
+
assertGroupPlacement(ctx.graph, parentId, childIds, "flatten");
|
|
17
|
+
const renderer = ctx.getRenderer();
|
|
18
|
+
if (!renderer) return null;
|
|
17
19
|
const childSnapshots = childIds.map((id) => ({
|
|
18
20
|
id,
|
|
19
21
|
subtree: snapshotSubtree(ctx.graph, id)
|
|
20
22
|
}));
|
|
21
23
|
const prevSelection = new Set(ctx.state.selectedIds);
|
|
22
24
|
const firstIndex = Math.min(...childIds.map((id) => parent.childIds.indexOf(id)));
|
|
23
|
-
const vectorProps = vectorPropsFactory(renderer, ctx.graph, topLevel);
|
|
25
|
+
const vectorProps = !options.vectorPropsFactory && topLevel.length === 1 && !canContainFlattenableChildren(topLevel[0]) ? flattenLayerToVectorProps(renderer, ctx.graph, topLevel[0]) : vectorPropsFactory(renderer, ctx.graph, topLevel);
|
|
24
26
|
if (!vectorProps) return null;
|
|
25
27
|
const vector = ctx.graph.createNode("VECTOR", parentId, {
|
|
26
28
|
...vectorProps,
|
|
27
|
-
name: label
|
|
28
|
-
strokes: []
|
|
29
|
+
name: label
|
|
29
30
|
});
|
|
30
31
|
const vectorSnapshot = structuredClone(vector);
|
|
31
32
|
ctx.graph.insertChildAt(vector.id, parentId, firstIndex);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten.js","names":[],"sources":["../../../src/editor/structure/flatten.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\n\nimport { canMakeBooleanSourceNode } from '#core/canvas/boolean'\nimport { flattenNodesToVectorProps } from '#core/canvas/flatten'\nimport { restoreSubtree, snapshotSubtree } from '#core/editor/history/subtree'\nimport type { EditorContext } from '#core/editor/types'\n\nimport { selectedNodesInSharedParent } from './selection'\n\ntype VectorPropsFactory = typeof flattenNodesToVectorProps\n\ntype FlattenOptions = {\n label?: string\n canFlattenNode?: (node: SceneNode) => boolean\n vectorPropsFactory?: VectorPropsFactory\n}\n\nexport function flattenSelected(\n ctx: EditorContext,\n selectedNodes: SceneNode[],\n options: FlattenOptions = {}\n) {\n const label = options.label ?? 'Flatten'\n const canFlattenNode =\n options.canFlattenNode ?? ((node: SceneNode) => canMakeBooleanSourceNode(node, ctx.graph))\n const vectorPropsFactory = options.vectorPropsFactory ?? flattenNodesToVectorProps\n
|
|
1
|
+
{"version":3,"file":"flatten.js","names":[],"sources":["../../../src/editor/structure/flatten.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\nimport { assertGroupPlacement } from '@pairdraw/scene-graph/slots'\n\nimport { canContainFlattenableChildren, canMakeBooleanSourceNode } from '#core/canvas/boolean'\nimport { flattenLayerToVectorProps, flattenNodesToVectorProps } from '#core/canvas/flatten'\nimport { restoreSubtree, snapshotSubtree } from '#core/editor/history/subtree'\nimport type { EditorContext } from '#core/editor/types'\n\nimport { selectedNodesInSharedParent } from './selection'\n\ntype VectorPropsFactory = typeof flattenNodesToVectorProps\n\ntype FlattenOptions = {\n label?: string\n canFlattenNode?: (node: SceneNode) => boolean\n vectorPropsFactory?: VectorPropsFactory\n}\n\nexport function flattenSelected(\n ctx: EditorContext,\n selectedNodes: SceneNode[],\n options: FlattenOptions = {}\n) {\n const label = options.label ?? 'Flatten'\n const canFlattenNode =\n options.canFlattenNode ?? ((node: SceneNode) => canMakeBooleanSourceNode(node, ctx.graph))\n const vectorPropsFactory = options.vectorPropsFactory ?? flattenNodesToVectorProps\n\n const selection = selectedNodesInSharedParent(ctx, selectedNodes)\n if (!selection) return null\n const { topLevel, parentId, parent } = selection\n if (topLevel.some((node) => !canFlattenNode(node))) return null\n const childIds = topLevel.map((node) => node.id)\n assertGroupPlacement(ctx.graph, parentId, childIds, 'flatten')\n const renderer = ctx.getRenderer()\n if (!renderer) return null\n const childSnapshots = childIds.map((id) => ({ id, subtree: snapshotSubtree(ctx.graph, id) }))\n const prevSelection = new Set(ctx.state.selectedIds)\n const firstIndex = Math.min(...childIds.map((id) => parent.childIds.indexOf(id)))\n // One layer keeps its own appearance, as Figma's Flatten does; several become one silhouette\n // painted with the topmost layer's fills, and a container keeps giving its children's shapes.\n const vectorProps =\n !options.vectorPropsFactory &&\n topLevel.length === 1 &&\n !canContainFlattenableChildren(topLevel[0])\n ? flattenLayerToVectorProps(renderer, ctx.graph, topLevel[0])\n : vectorPropsFactory(renderer, ctx.graph, topLevel)\n if (!vectorProps) return null\n\n const vector = ctx.graph.createNode('VECTOR', parentId, {\n ...vectorProps,\n name: label\n })\n const vectorSnapshot = structuredClone(vector)\n ctx.graph.insertChildAt(vector.id, parentId, firstIndex)\n for (const id of childIds) ctx.graph.deleteNode(id)\n ctx.setSelectedIds(new Set([vector.id]))\n\n ctx.undo.push({\n label,\n forward: () => {\n const restored = ctx.graph.createNode('VECTOR', parentId, vectorSnapshot)\n ctx.graph.insertChildAt(restored.id, parentId, firstIndex)\n for (const id of childIds) ctx.graph.deleteNode(id)\n ctx.setSelectedIds(new Set([restored.id]))\n },\n inverse: () => {\n ctx.graph.deleteNode(vector.id)\n for (let i = 0; i < childSnapshots.length; i++) {\n const { id, subtree } = childSnapshots[i]\n const root = subtree.get(id)\n if (!root) continue\n restoreSubtree(ctx.graph, root, parentId, subtree)\n ctx.graph.insertChildAt(id, parentId, firstIndex + i)\n }\n ctx.setSelectedIds(prevSelection)\n }\n })\n\n return vector.id\n}\n"],"mappings":";;;;;;AAkBA,SAAgB,gBACd,KACA,eACA,UAA0B,CAAC,GAC3B;CACA,MAAM,QAAQ,QAAQ,SAAS;CAC/B,MAAM,iBACJ,QAAQ,oBAAoB,SAAoB,yBAAyB,MAAM,IAAI,KAAK;CAC1F,MAAM,qBAAqB,QAAQ,sBAAsB;CAEzD,MAAM,YAAY,4BAA4B,KAAK,aAAa;CAChE,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,EAAE,UAAU,UAAU,WAAW;CACvC,IAAI,SAAS,MAAM,SAAS,CAAC,eAAe,IAAI,CAAC,GAAG,OAAO;CAC3D,MAAM,WAAW,SAAS,KAAK,SAAS,KAAK,EAAE;CAC/C,qBAAqB,IAAI,OAAO,UAAU,UAAU,SAAS;CAC7D,MAAM,WAAW,IAAI,YAAY;CACjC,IAAI,CAAC,UAAU,OAAO;CACtB,MAAM,iBAAiB,SAAS,KAAK,QAAQ;EAAE;EAAI,SAAS,gBAAgB,IAAI,OAAO,EAAE;CAAE,EAAE;CAC7F,MAAM,gBAAgB,IAAI,IAAI,IAAI,MAAM,WAAW;CACnD,MAAM,aAAa,KAAK,IAAI,GAAG,SAAS,KAAK,OAAO,OAAO,SAAS,QAAQ,EAAE,CAAC,CAAC;CAGhF,MAAM,cACJ,CAAC,QAAQ,sBACT,SAAS,WAAW,KACpB,CAAC,8BAA8B,SAAS,EAAE,IACtC,0BAA0B,UAAU,IAAI,OAAO,SAAS,EAAE,IAC1D,mBAAmB,UAAU,IAAI,OAAO,QAAQ;CACtD,IAAI,CAAC,aAAa,OAAO;CAEzB,MAAM,SAAS,IAAI,MAAM,WAAW,UAAU,UAAU;EACtD,GAAG;EACH,MAAM;CACR,CAAC;CACD,MAAM,iBAAiB,gBAAgB,MAAM;CAC7C,IAAI,MAAM,cAAc,OAAO,IAAI,UAAU,UAAU;CACvD,KAAK,MAAM,MAAM,UAAU,IAAI,MAAM,WAAW,EAAE;CAClD,IAAI,+BAAe,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;CAEvC,IAAI,KAAK,KAAK;EACZ;EACA,eAAe;GACb,MAAM,WAAW,IAAI,MAAM,WAAW,UAAU,UAAU,cAAc;GACxE,IAAI,MAAM,cAAc,SAAS,IAAI,UAAU,UAAU;GACzD,KAAK,MAAM,MAAM,UAAU,IAAI,MAAM,WAAW,EAAE;GAClD,IAAI,+BAAe,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;EAC3C;EACA,eAAe;GACb,IAAI,MAAM,WAAW,OAAO,EAAE;GAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,eAAe,QAAQ,KAAK;IAC9C,MAAM,EAAE,IAAI,YAAY,eAAe;IACvC,MAAM,OAAO,QAAQ,IAAI,EAAE;IAC3B,IAAI,CAAC,MAAM;IACX,eAAe,IAAI,OAAO,MAAM,UAAU,OAAO;IACjD,IAAI,MAAM,cAAc,IAAI,UAAU,aAAa,CAAC;GACtD;GACA,IAAI,eAAe,aAAa;EAClC;CACF,CAAC;CAED,OAAO,OAAO;AAChB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ungroup.d.ts","names":[],"sources":["../../../../src/editor/structure/group/ungroup.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"ungroup.d.ts","names":[],"sources":["../../../../src/editor/structure/group/ungroup.ts"],"mappings":";;;;;;;;iBAUgB,YAAY,OAAO,YAAY;iBAe/B,gBAAgB,KAAK,eAAe,cAAc"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertChildPlacement } from "@pairdraw/scene-graph/slots";
|
|
1
2
|
//#region src/editor/structure/group/ungroup.ts
|
|
2
3
|
/**
|
|
3
4
|
* Moves a container's children into its parent, in the container's place in the stack, and
|
|
@@ -8,6 +9,7 @@ function ungroupNode(graph, nodeId) {
|
|
|
8
9
|
const node = graph.getNode(nodeId);
|
|
9
10
|
const parent = node?.parentId ? graph.getNode(node.parentId) : void 0;
|
|
10
11
|
if (!node || !parent) return null;
|
|
12
|
+
assertChildPlacement(graph, parent.id, "ungroup");
|
|
11
13
|
const index = parent.childIds.indexOf(node.id);
|
|
12
14
|
const childIds = [...node.childIds];
|
|
13
15
|
childIds.forEach((id, i) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ungroup.js","names":[],"sources":["../../../../src/editor/structure/group/ungroup.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport type { EditorContext } from '#core/editor/types'\n\n/**\n * Moves a container's children into its parent, in the container's place in the stack, and\n * deletes the container. Returns the children, or null when the container has no parent. Shared\n * by the editor's Ungroup command and the plugin API's `ungroup`.\n */\nexport function ungroupNode(graph: SceneGraph, nodeId: string): string[] | null {\n const node = graph.getNode(nodeId)\n const parent = node?.parentId ? graph.getNode(node.parentId) : undefined\n if (!node || !parent) return null\n const index = parent.childIds.indexOf(node.id)\n const childIds = [...node.childIds]\n childIds.forEach((id, i) => {\n graph.reparentNode(id, parent.id)\n graph.insertChildAt(id, parent.id, index + i)\n })\n graph.deleteNode(node.id)\n return childIds\n}\n\nexport function ungroupSelected(ctx: EditorContext, selectedNode: SceneNode | undefined) {\n if (selectedNode?.type !== 'GROUP') return\n\n const node = selectedNode\n const parentId = node.parentId ?? ctx.state.currentPageId\n const parent = ctx.graph.getNode(parentId)\n if (!parent) return\n\n const groupIndex = parent.childIds.indexOf(node.id)\n const prevSelection = new Set(ctx.state.selectedIds)\n const origPositions = node.childIds.map((id) => {\n const child = ctx.graph.getNode(id)\n if (!child) return { id, x: 0, y: 0 }\n return { id, x: child.x, y: child.y }\n })\n const groupId = node.id\n const groupSnapshot = { ...node, childIds: [...node.childIds] }\n\n const ungroup = () => {\n const childIds = ungroupNode(ctx.graph, groupId)\n if (childIds) ctx.setSelectedIds(new Set(childIds))\n }\n ungroup()\n\n ctx.undo.push({\n label: 'Ungroup',\n forward: ungroup,\n inverse: () => {\n const g = ctx.graph.createNode('GROUP', parentId, {\n ...groupSnapshot,\n childIds: [],\n id: groupId\n })\n ctx.graph.insertChildAt(g.id, parentId, groupIndex)\n for (const orig of origPositions) {\n ctx.graph.reparentNode(orig.id, g.id)\n ctx.graph.updateNode(orig.id, { x: orig.x, y: orig.y })\n }\n ctx.setSelectedIds(prevSelection)\n }\n })\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ungroup.js","names":[],"sources":["../../../../src/editor/structure/group/ungroup.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { assertChildPlacement } from '@pairdraw/scene-graph/slots'\n\nimport type { EditorContext } from '#core/editor/types'\n\n/**\n * Moves a container's children into its parent, in the container's place in the stack, and\n * deletes the container. Returns the children, or null when the container has no parent. Shared\n * by the editor's Ungroup command and the plugin API's `ungroup`.\n */\nexport function ungroupNode(graph: SceneGraph, nodeId: string): string[] | null {\n const node = graph.getNode(nodeId)\n const parent = node?.parentId ? graph.getNode(node.parentId) : undefined\n if (!node || !parent) return null\n assertChildPlacement(graph, parent.id, 'ungroup')\n const index = parent.childIds.indexOf(node.id)\n const childIds = [...node.childIds]\n childIds.forEach((id, i) => {\n graph.reparentNode(id, parent.id)\n graph.insertChildAt(id, parent.id, index + i)\n })\n graph.deleteNode(node.id)\n return childIds\n}\n\nexport function ungroupSelected(ctx: EditorContext, selectedNode: SceneNode | undefined) {\n if (selectedNode?.type !== 'GROUP') return\n\n const node = selectedNode\n const parentId = node.parentId ?? ctx.state.currentPageId\n const parent = ctx.graph.getNode(parentId)\n if (!parent) return\n\n const groupIndex = parent.childIds.indexOf(node.id)\n const prevSelection = new Set(ctx.state.selectedIds)\n const origPositions = node.childIds.map((id) => {\n const child = ctx.graph.getNode(id)\n if (!child) return { id, x: 0, y: 0 }\n return { id, x: child.x, y: child.y }\n })\n const groupId = node.id\n const groupSnapshot = { ...node, childIds: [...node.childIds] }\n\n const ungroup = () => {\n const childIds = ungroupNode(ctx.graph, groupId)\n if (childIds) ctx.setSelectedIds(new Set(childIds))\n }\n ungroup()\n\n ctx.undo.push({\n label: 'Ungroup',\n forward: ungroup,\n inverse: () => {\n const g = ctx.graph.createNode('GROUP', parentId, {\n ...groupSnapshot,\n childIds: [],\n id: groupId\n })\n ctx.graph.insertChildAt(g.id, parentId, groupIndex)\n for (const orig of origPositions) {\n ctx.graph.reparentNode(orig.id, g.id)\n ctx.graph.updateNode(orig.id, { x: orig.x, y: orig.y })\n }\n ctx.setSelectedIds(prevSelection)\n }\n })\n}\n"],"mappings":";;;;;;;AAUA,SAAgB,YAAY,OAAmB,QAAiC;CAC9E,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,MAAM,SAAS,MAAM,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;CAC/D,IAAI,CAAC,QAAQ,CAAC,QAAQ,OAAO;CAC7B,qBAAqB,OAAO,OAAO,IAAI,SAAS;CAChD,MAAM,QAAQ,OAAO,SAAS,QAAQ,KAAK,EAAE;CAC7C,MAAM,WAAW,CAAC,GAAG,KAAK,QAAQ;CAClC,SAAS,SAAS,IAAI,MAAM;EAC1B,MAAM,aAAa,IAAI,OAAO,EAAE;EAChC,MAAM,cAAc,IAAI,OAAO,IAAI,QAAQ,CAAC;CAC9C,CAAC;CACD,MAAM,WAAW,KAAK,EAAE;CACxB,OAAO;AACT;AAEA,SAAgB,gBAAgB,KAAoB,cAAqC;CACvF,IAAI,cAAc,SAAS,SAAS;CAEpC,MAAM,OAAO;CACb,MAAM,WAAW,KAAK,YAAY,IAAI,MAAM;CAC5C,MAAM,SAAS,IAAI,MAAM,QAAQ,QAAQ;CACzC,IAAI,CAAC,QAAQ;CAEb,MAAM,aAAa,OAAO,SAAS,QAAQ,KAAK,EAAE;CAClD,MAAM,gBAAgB,IAAI,IAAI,IAAI,MAAM,WAAW;CACnD,MAAM,gBAAgB,KAAK,SAAS,KAAK,OAAO;EAC9C,MAAM,QAAQ,IAAI,MAAM,QAAQ,EAAE;EAClC,IAAI,CAAC,OAAO,OAAO;GAAE;GAAI,GAAG;GAAG,GAAG;EAAE;EACpC,OAAO;GAAE;GAAI,GAAG,MAAM;GAAG,GAAG,MAAM;EAAE;CACtC,CAAC;CACD,MAAM,UAAU,KAAK;CACrB,MAAM,gBAAgB;EAAE,GAAG;EAAM,UAAU,CAAC,GAAG,KAAK,QAAQ;CAAE;CAE9D,MAAM,gBAAgB;EACpB,MAAM,WAAW,YAAY,IAAI,OAAO,OAAO;EAC/C,IAAI,UAAU,IAAI,eAAe,IAAI,IAAI,QAAQ,CAAC;CACpD;CACA,QAAQ;CAER,IAAI,KAAK,KAAK;EACZ,OAAO;EACP,SAAS;EACT,eAAe;GACb,MAAM,IAAI,IAAI,MAAM,WAAW,SAAS,UAAU;IAChD,GAAG;IACH,UAAU,CAAC;IACX,IAAI;GACN,CAAC;GACD,IAAI,MAAM,cAAc,EAAE,IAAI,UAAU,UAAU;GAClD,KAAK,MAAM,QAAQ,eAAe;IAChC,IAAI,MAAM,aAAa,KAAK,IAAI,EAAE,EAAE;IACpC,IAAI,MAAM,WAAW,KAAK,IAAI;KAAE,GAAG,KAAK;KAAG,GAAG,KAAK;IAAE,CAAC;GACxD;GACA,IAAI,eAAe,aAAa;EAClC;CACF,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outline-stroke.d.ts","names":[],"sources":["../../../src/editor/structure/outline-stroke.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"outline-stroke.d.ts","names":[],"sources":["../../../src/editor/structure/outline-stroke.ts"],"mappings":";;;;;;;iBAoDgB,sBACd,KAAK,eACL,eAAe"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { layersToOutline, outlineStrokeLayer } from "../../canvas/outline-stroke.js";
|
|
2
2
|
import { restoreSubtree, snapshotSubtree } from "../history/subtree.js";
|
|
3
3
|
import { fitEnclosingGroupsWithUndo } from "./group/bounds.js";
|
|
4
|
+
import { assertChildPlacement, assertNodeMovable } from "@pairdraw/scene-graph/slots";
|
|
4
5
|
//#region src/editor/structure/outline-stroke.ts
|
|
5
6
|
/** Creates a piece in `parentId` at `index`, with a group's glyph vectors inside it. */
|
|
6
7
|
function createPiece(ctx, piece, parentId, index) {
|
|
@@ -28,6 +29,10 @@ function outlineStrokeSelected(ctx, selectedNodes) {
|
|
|
28
29
|
const plan = [];
|
|
29
30
|
for (const node of layersToOutline(selectedNodes, ctx.graph)) {
|
|
30
31
|
const parent = node.parentId ? ctx.graph.getNode(node.parentId) : void 0;
|
|
32
|
+
if (parent) {
|
|
33
|
+
assertChildPlacement(ctx.graph, parent.id, "Outline stroke");
|
|
34
|
+
assertNodeMovable(ctx.graph, node.id, "Outline stroke");
|
|
35
|
+
}
|
|
31
36
|
const outlined = parent ? outlineStrokeLayer(renderer, node, ctx.graph) : null;
|
|
32
37
|
if (!parent || !outlined) continue;
|
|
33
38
|
plan.push({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outline-stroke.js","names":[],"sources":["../../../src/editor/structure/outline-stroke.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\n\nimport {\n layersToOutline,\n outlineStrokeLayer,\n type OutlinePiece,\n type OutlinedLayer\n} from '#core/canvas/outline-stroke'\nimport { restoreSubtree, snapshotSubtree } from '#core/editor/history/subtree'\nimport { fitEnclosingGroupsWithUndo } from '#core/editor/structure/group/bounds'\nimport type { EditorContext } from '#core/editor/types'\n\n/** A layer to outline, where it sits, and what it becomes. */\ninterface Outlining {\n node: SceneNode\n parentId: string\n index: number\n snapshot: Map<string, SceneNode>\n outlined: OutlinedLayer\n}\n\n/** Where a layer Outline stroke made sits, to put it back on redo. */\ninterface Made {\n id: string\n parentId: string\n index: number\n snapshot: Map<string, SceneNode>\n}\n\n/** Creates a piece in `parentId` at `index`, with a group's glyph vectors inside it. */\nfunction createPiece(ctx: EditorContext, piece: OutlinePiece, parentId: string, index: number) {\n const node = ctx.graph.createNode(piece.type, parentId, piece.props)\n for (const child of piece.children) ctx.graph.createNode('VECTOR', node.id, child)\n ctx.graph.insertChildAt(node.id, parentId, index)\n return node.id\n}\n\n/** Restores snapshots taken in one parent, lowest index first so each lands where it was. */\nfunction restoreAt(ctx: EditorContext, entries: readonly Made[]) {\n for (const { id, parentId, index, snapshot } of entries.toSorted((a, b) => a.index - b.index)) {\n const root = snapshot.get(id)\n if (!root) continue\n restoreSubtree(ctx.graph, root, parentId, snapshot)\n ctx.graph.insertChildAt(id, parentId, index)\n }\n}\n\n/**\n * Figma's Outline stroke: every stroked layer is replaced, where it was, by its fill as a shape\n * of its own under its stroke as one, both selected. Undo puts the layers back.\n */\nexport function outlineStrokeSelected(\n ctx: EditorContext,\n selectedNodes: SceneNode[]\n): string[] | null {\n const renderer = ctx.getRenderer()\n if (!renderer) return null\n const plan: Outlining[] = []\n for (const node of layersToOutline(selectedNodes, ctx.graph)) {\n const parent = node.parentId ? ctx.graph.getNode(node.parentId) : undefined\n const outlined = parent ? outlineStrokeLayer(renderer, node, ctx.graph) : null\n if (!parent || !outlined) continue\n plan.push({\n node,\n parentId: parent.id,\n index: parent.childIds.indexOf(node.id),\n snapshot: snapshotSubtree(ctx.graph, node.id),\n outlined\n })\n }\n if (plan.length === 0) return null\n\n const madeIds: string[] = []\n for (const { node, parentId, outlined } of plan) {\n const index = ctx.graph.getNode(parentId)?.childIds.indexOf(node.id) ?? 0\n const fill = outlined.fill ? createPiece(ctx, outlined.fill, parentId, index) : null\n const stroke = createPiece(ctx, outlined.stroke, parentId, index + (fill ? 1 : 0))\n ctx.graph.deleteNode(node.id)\n if (fill) madeIds.push(fill)\n madeIds.push(stroke)\n }\n const made: Made[] = madeIds.flatMap((id) => {\n const parentId = ctx.graph.getNode(id)?.parentId\n if (!parentId) return []\n const index = ctx.graph.getNode(parentId)?.childIds.indexOf(id) ?? 0\n return [{ id, parentId, index, snapshot: snapshotSubtree(ctx.graph, id) }]\n })\n const parentIds = new Set(plan.map((entry) => entry.parentId))\n const prevSelection = new Set(ctx.state.selectedIds)\n ctx.runLayoutForParents(parentIds)\n ctx.setSelectedIds(new Set(madeIds))\n\n // Groups around the outlines fit them, which can reach past the layers they replace, in the\n // same undo step.\n ctx.undo.runBatch('Outline stroke', () => {\n pushOutlineUndo(ctx, { plan, made, madeIds, parentIds, prevSelection })\n fitEnclosingGroupsWithUndo(ctx, parentIds)\n })\n return madeIds\n}\n\n/** The undo step that puts the outlined layers back, and redo that outlines them again. */\nfunction pushOutlineUndo(\n ctx: EditorContext,\n {\n plan,\n made,\n madeIds,\n parentIds,\n prevSelection\n }: {\n plan: readonly Outlining[]\n made: readonly Made[]\n madeIds: readonly string[]\n parentIds: ReadonlySet<string>\n prevSelection: ReadonlySet<string>\n }\n) {\n ctx.undo.push({\n label: 'Outline stroke',\n forward: () => {\n for (const { node } of plan) ctx.graph.deleteNode(node.id)\n restoreAt(ctx, made)\n ctx.runLayoutForParents(parentIds)\n ctx.setSelectedIds(new Set(madeIds))\n },\n inverse: () => {\n for (const { id } of made) ctx.graph.deleteNode(id)\n restoreAt(\n ctx,\n plan.map(({ node, parentId, index, snapshot }) => ({\n id: node.id,\n parentId,\n index,\n snapshot\n }))\n )\n ctx.runLayoutForParents(parentIds)\n ctx.setSelectedIds(new Set(prevSelection))\n }\n })\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"outline-stroke.js","names":[],"sources":["../../../src/editor/structure/outline-stroke.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\nimport { assertChildPlacement, assertNodeMovable } from '@pairdraw/scene-graph/slots'\n\nimport {\n layersToOutline,\n outlineStrokeLayer,\n type OutlinePiece,\n type OutlinedLayer\n} from '#core/canvas/outline-stroke'\nimport { restoreSubtree, snapshotSubtree } from '#core/editor/history/subtree'\nimport { fitEnclosingGroupsWithUndo } from '#core/editor/structure/group/bounds'\nimport type { EditorContext } from '#core/editor/types'\n\n/** A layer to outline, where it sits, and what it becomes. */\ninterface Outlining {\n node: SceneNode\n parentId: string\n index: number\n snapshot: Map<string, SceneNode>\n outlined: OutlinedLayer\n}\n\n/** Where a layer Outline stroke made sits, to put it back on redo. */\ninterface Made {\n id: string\n parentId: string\n index: number\n snapshot: Map<string, SceneNode>\n}\n\n/** Creates a piece in `parentId` at `index`, with a group's glyph vectors inside it. */\nfunction createPiece(ctx: EditorContext, piece: OutlinePiece, parentId: string, index: number) {\n const node = ctx.graph.createNode(piece.type, parentId, piece.props)\n for (const child of piece.children) ctx.graph.createNode('VECTOR', node.id, child)\n ctx.graph.insertChildAt(node.id, parentId, index)\n return node.id\n}\n\n/** Restores snapshots taken in one parent, lowest index first so each lands where it was. */\nfunction restoreAt(ctx: EditorContext, entries: readonly Made[]) {\n for (const { id, parentId, index, snapshot } of entries.toSorted((a, b) => a.index - b.index)) {\n const root = snapshot.get(id)\n if (!root) continue\n restoreSubtree(ctx.graph, root, parentId, snapshot)\n ctx.graph.insertChildAt(id, parentId, index)\n }\n}\n\n/**\n * Figma's Outline stroke: every stroked layer is replaced, where it was, by its fill as a shape\n * of its own under its stroke as one, both selected. Undo puts the layers back.\n */\nexport function outlineStrokeSelected(\n ctx: EditorContext,\n selectedNodes: SceneNode[]\n): string[] | null {\n const renderer = ctx.getRenderer()\n if (!renderer) return null\n const plan: Outlining[] = []\n for (const node of layersToOutline(selectedNodes, ctx.graph)) {\n const parent = node.parentId ? ctx.graph.getNode(node.parentId) : undefined\n if (parent) {\n assertChildPlacement(ctx.graph, parent.id, 'Outline stroke')\n assertNodeMovable(ctx.graph, node.id, 'Outline stroke')\n }\n const outlined = parent ? outlineStrokeLayer(renderer, node, ctx.graph) : null\n if (!parent || !outlined) continue\n plan.push({\n node,\n parentId: parent.id,\n index: parent.childIds.indexOf(node.id),\n snapshot: snapshotSubtree(ctx.graph, node.id),\n outlined\n })\n }\n if (plan.length === 0) return null\n\n const madeIds: string[] = []\n for (const { node, parentId, outlined } of plan) {\n const index = ctx.graph.getNode(parentId)?.childIds.indexOf(node.id) ?? 0\n const fill = outlined.fill ? createPiece(ctx, outlined.fill, parentId, index) : null\n const stroke = createPiece(ctx, outlined.stroke, parentId, index + (fill ? 1 : 0))\n ctx.graph.deleteNode(node.id)\n if (fill) madeIds.push(fill)\n madeIds.push(stroke)\n }\n const made: Made[] = madeIds.flatMap((id) => {\n const parentId = ctx.graph.getNode(id)?.parentId\n if (!parentId) return []\n const index = ctx.graph.getNode(parentId)?.childIds.indexOf(id) ?? 0\n return [{ id, parentId, index, snapshot: snapshotSubtree(ctx.graph, id) }]\n })\n const parentIds = new Set(plan.map((entry) => entry.parentId))\n const prevSelection = new Set(ctx.state.selectedIds)\n ctx.runLayoutForParents(parentIds)\n ctx.setSelectedIds(new Set(madeIds))\n\n // Groups around the outlines fit them, which can reach past the layers they replace, in the\n // same undo step.\n ctx.undo.runBatch('Outline stroke', () => {\n pushOutlineUndo(ctx, { plan, made, madeIds, parentIds, prevSelection })\n fitEnclosingGroupsWithUndo(ctx, parentIds)\n })\n return madeIds\n}\n\n/** The undo step that puts the outlined layers back, and redo that outlines them again. */\nfunction pushOutlineUndo(\n ctx: EditorContext,\n {\n plan,\n made,\n madeIds,\n parentIds,\n prevSelection\n }: {\n plan: readonly Outlining[]\n made: readonly Made[]\n madeIds: readonly string[]\n parentIds: ReadonlySet<string>\n prevSelection: ReadonlySet<string>\n }\n) {\n ctx.undo.push({\n label: 'Outline stroke',\n forward: () => {\n for (const { node } of plan) ctx.graph.deleteNode(node.id)\n restoreAt(ctx, made)\n ctx.runLayoutForParents(parentIds)\n ctx.setSelectedIds(new Set(madeIds))\n },\n inverse: () => {\n for (const { id } of made) ctx.graph.deleteNode(id)\n restoreAt(\n ctx,\n plan.map(({ node, parentId, index, snapshot }) => ({\n id: node.id,\n parentId,\n index,\n snapshot\n }))\n )\n ctx.runLayoutForParents(parentIds)\n ctx.setSelectedIds(new Set(prevSelection))\n }\n })\n}\n"],"mappings":"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"}
|
|
@@ -14,7 +14,7 @@ declare function createStructureActions(ctx: EditorContext): {
|
|
|
14
14
|
toggleNodeLock: (id: string) => void;
|
|
15
15
|
toggleVisibility: () => void;
|
|
16
16
|
toggleLock: () => void;
|
|
17
|
-
booleanOperationSelected: (selectedNodes: SceneNode[], operation: BooleanOperation) =>
|
|
17
|
+
booleanOperationSelected: (selectedNodes: SceneNode[], operation: BooleanOperation) => SceneNode | null;
|
|
18
18
|
ungroupSelected: (selectedNode: SceneNode | undefined) => void;
|
|
19
19
|
flattenSelected: (selectedNodes: SceneNode[]) => string | null;
|
|
20
20
|
outlineTextSelected: (selectedNodes: SceneNode[]) => string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structure.d.ts","names":[],"sources":["../../src/editor/structure.ts"],"mappings":";;;;;;iBAuBgB,uBAAuB,KAAK;EAgId,aAAA;EA+CY,wBAAA,SAAA,2BAAA;EAIP,iBAAA,SAAA;EA8BT,aAAA,YAAM;;;;;;EAvGmB,2BAAA,eAAA,aAAW,WAAa;
|
|
1
|
+
{"version":3,"file":"structure.d.ts","names":[],"sources":["../../src/editor/structure.ts"],"mappings":";;;;;;iBAuBgB,uBAAuB,KAAK;EAgId,aAAA;EA+CY,wBAAA,SAAA,2BAAA;EAIP,iBAAA,SAAA;EA8BT,aAAA,YAAM;;;;;;EAvGmB,2BAAA,eAAA,aAAW,WAAa,qBAAgB;EAIlD,kBAAA,cAAA;EAIC,kBAAA,eAAA;EAII,sBAAA,eAAA;EAME,wBAAA,eAAA;2CAAA;EA/Gd,gBAAA,mBAAQ;EAuBvB,2BAAA,kEAAiD,eACjD,aAAW,aACb,QAAQ;EAKkB,mBAAA,eAAA;EAIH,gBAAA,eAAA;EAoBD,eAAA,eAAA;EAmCE,iBAAA,eAAA;;;;;;;;EAjGT,aAAA;EA+NA,kBAAA;EACA,kBAAA;EACI,qBAAA,WAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EditorContext } from "./types.js";
|
|
2
|
+
import { NodeActions } from "./nodes.js";
|
|
3
|
+
import { SceneNode, SharedStyleKind, SharedStyleType } from "@pairdraw/scene-graph";
|
|
4
|
+
//#region src/editor/styles.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A new style node, which redo makes again with the same ids so layers stay attached. The one
|
|
7
|
+
* creator the token import and the style picker share.
|
|
8
|
+
*/
|
|
9
|
+
declare function createStyleNode(ctx: EditorContext, type: SharedStyleType, fields: Partial<SceneNode>): SceneNode;
|
|
10
|
+
/** Whether a layer can carry this kind of style at all, as the picker's own fields say. */
|
|
11
|
+
declare function supportsStyleKind(node: SceneNode, kind: SharedStyleKind): boolean;
|
|
12
|
+
/** Makes shared styles from what a layer shows, as the style picker asks. */
|
|
13
|
+
declare function createStyleActions(ctx: EditorContext, nodes: NodeActions): {
|
|
14
|
+
createStyleFromSelection: (kind: SharedStyleKind, name: string) => SceneNode | null;
|
|
15
|
+
/** Whether the selection holds something to save for this kind, so the picker can offer it. */
|
|
16
|
+
updateSharedStyle: (styleId: string, kind: SharedStyleKind, changes: SharedStyleDefinitionChanges) => {
|
|
17
|
+
styleId: string;
|
|
18
|
+
layerIds: string[];
|
|
19
|
+
} | null;
|
|
20
|
+
canCreateStyle: (kind: SharedStyleKind) => boolean;
|
|
21
|
+
};
|
|
22
|
+
/** The fields an edit of a shared definition writes for its kind. */
|
|
23
|
+
type SharedStyleDefinitionChanges = Partial<Pick<SceneNode, 'name' | 'symbolDescription' | 'fills' | 'strokes' | 'effects' | 'layoutGrids' | 'fontFamily' | 'fontWeight' | 'italic' | 'fontStyle' | 'fontSize' | 'lineHeight' | 'letterSpacing' | 'textDecoration' | 'textCase' | 'fontFeatures' | 'paragraphSpacing' | 'paragraphIndent' | 'listSpacing'>>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { SharedStyleDefinitionChanges, createStyleActions, createStyleNode, supportsStyleKind };
|
|
26
|
+
//# sourceMappingURL=styles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.d.ts","names":[],"sources":["../../src/editor/styles.ts"],"mappings":";;;;;;;;iBAoBgB,gBACd,KAAK,eACL,MAAM,iBACN,QAAQ,QAAQ,aACf;;iBA0Ba,kBAAkB,MAAM,WAAW,MAAM;;iBA4DzC,mBAAmB,KAAK,eAAe,OAAO;EAEzB,2BAAA,MAAA,iBAAe,iBAAc;;EAInD,oBAAA,iBAAM,MACT,iBAAe,SACZ;IAiDD;IAAkB;;EA/CL,iBAAA,MAAA;;;KAUf,+BAA+B,QACzC,KACE"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { styleNodeProps, styleNodeType } from "../io/formats/design-tokens/apply.js";
|
|
2
|
+
import { SHARED_STYLE_FIELDS, sharedStyleLayers, sharedStyleRefKey, sharedStyleTypeForKind } from "@pairdraw/scene-graph/shared-styles";
|
|
3
|
+
import { isNil } from "es-toolkit";
|
|
4
|
+
import { hasInstanceOverride } from "@pairdraw/scene-graph/instances";
|
|
5
|
+
//#region src/editor/styles.ts
|
|
6
|
+
/**
|
|
7
|
+
* A new style node, which redo makes again with the same ids so layers stay attached. The one
|
|
8
|
+
* creator the token import and the style picker share.
|
|
9
|
+
*/
|
|
10
|
+
function createStyleNode(ctx, type, fields) {
|
|
11
|
+
const node = ctx.graph.createNode(styleNodeType({ kind: type }), ctx.state.currentPageId, styleNodeProps({ kind: type }, fields));
|
|
12
|
+
node.source.id = crypto.randomUUID();
|
|
13
|
+
const snapshot = structuredClone(node);
|
|
14
|
+
const parentId = node.parentId;
|
|
15
|
+
ctx.undo.push({
|
|
16
|
+
label: "Add style",
|
|
17
|
+
forward: () => {
|
|
18
|
+
ctx.graph.createNodeWithId(snapshot.id, snapshot.type, parentId, structuredClone(snapshot));
|
|
19
|
+
ctx.requestRender();
|
|
20
|
+
},
|
|
21
|
+
inverse: () => {
|
|
22
|
+
ctx.graph.deleteNode(snapshot.id);
|
|
23
|
+
ctx.requestRender();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return node;
|
|
27
|
+
}
|
|
28
|
+
const GRID_KINDS = /* @__PURE__ */ new Set([
|
|
29
|
+
"FRAME",
|
|
30
|
+
"COMPONENT",
|
|
31
|
+
"COMPONENT_SET",
|
|
32
|
+
"INSTANCE"
|
|
33
|
+
]);
|
|
34
|
+
/** Whether a layer can carry this kind of style at all, as the picker's own fields say. */
|
|
35
|
+
function supportsStyleKind(node, kind) {
|
|
36
|
+
if (node.type === "CANVAS") return false;
|
|
37
|
+
if (kind === "text") return node.type === "TEXT";
|
|
38
|
+
if (kind === "grid") return GRID_KINDS.has(node.type);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
/** Whether the layer shows something of this kind, such as a fill or an effect to save. */
|
|
42
|
+
function carriesStyleKind(node, kind) {
|
|
43
|
+
return SHARED_STYLE_FIELDS[kind].some((field) => {
|
|
44
|
+
const value = node[field];
|
|
45
|
+
return Array.isArray(value) ? value.length > 0 : !isNil(value);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** The layer a created style takes its fields from: the first selected one that shows the kind. */
|
|
49
|
+
function styleSource(layers, kind) {
|
|
50
|
+
return layers.find((layer) => supportsStyleKind(layer, kind) && carriesStyleKind(layer, kind));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Turns what the selected layers show into one shared style and binds every layer that supports
|
|
54
|
+
* it, as one undo step. The style takes the first layer that shows the kind, so binding changes
|
|
55
|
+
* nothing the person can see; a name may carry `/` groups. Without such a layer nothing is made,
|
|
56
|
+
* as Figma hides creation without paints.
|
|
57
|
+
*/
|
|
58
|
+
function createStyleFromSelection(ctx, nodes, kind, name) {
|
|
59
|
+
const layers = [...ctx.state.selectedIds].map((id) => ctx.graph.getNode(id)).filter((node) => node !== void 0);
|
|
60
|
+
const first = styleSource(layers, kind);
|
|
61
|
+
if (!first) return null;
|
|
62
|
+
const fields = {};
|
|
63
|
+
for (const key of SHARED_STYLE_FIELDS[kind]) Object.assign(fields, { [key]: structuredClone(first[key]) });
|
|
64
|
+
return ctx.undo.runBatch("Create style", () => {
|
|
65
|
+
const style = createStyleNode(ctx, sharedStyleTypeForKind(kind), {
|
|
66
|
+
...fields,
|
|
67
|
+
name: name.trim() || first.name
|
|
68
|
+
});
|
|
69
|
+
const styleId = style.source.id;
|
|
70
|
+
const refKey = sharedStyleRefKey(kind);
|
|
71
|
+
for (const layer of layers) {
|
|
72
|
+
if (!supportsStyleKind(layer, kind)) continue;
|
|
73
|
+
nodes.updateNodeWithUndo(layer.id, { [refKey]: styleId }, `Apply ${kind} style`);
|
|
74
|
+
}
|
|
75
|
+
ctx.requestRender();
|
|
76
|
+
return style;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** Makes shared styles from what a layer shows, as the style picker asks. */
|
|
80
|
+
function createStyleActions(ctx, nodes) {
|
|
81
|
+
return {
|
|
82
|
+
createStyleFromSelection: (kind, name) => createStyleFromSelection(ctx, nodes, kind, name),
|
|
83
|
+
/** Whether the selection holds something to save for this kind, so the picker can offer it. */
|
|
84
|
+
updateSharedStyle: (styleId, kind, changes) => updateSharedStyle(ctx, nodes, styleId, kind, changes),
|
|
85
|
+
canCreateStyle: (kind) => {
|
|
86
|
+
return styleSource([...ctx.state.selectedIds].map((id) => ctx.graph.getNode(id)).filter((node) => node !== void 0), kind) !== void 0;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Writes a shared style's definition and re-applies its fields to every layer linked to that style,
|
|
92
|
+
* as one undo step. A layer's own name and description never follow the style. A layer that detached
|
|
93
|
+
* (its reference cleared) is not touched. An instance field the person overrode keeps its value, as
|
|
94
|
+
* in Figma; the other fields still follow.
|
|
95
|
+
*/
|
|
96
|
+
function updateSharedStyle(ctx, nodes, styleId, kind, changes) {
|
|
97
|
+
const style = [...sharedStyleLayers(ctx.graph).values()].find((node) => node.source.id === styleId && node.sharedStyleType === sharedStyleTypeForKind(kind));
|
|
98
|
+
if (!style) return null;
|
|
99
|
+
const fields = SHARED_STYLE_FIELDS[kind];
|
|
100
|
+
const patch = {};
|
|
101
|
+
for (const field of fields) if (field in changes) Object.assign(patch, { [field]: structuredClone(changes[field]) });
|
|
102
|
+
if (changes.name !== void 0) patch.name = changes.name.trim() || style.name;
|
|
103
|
+
if (changes.symbolDescription !== void 0) patch.symbolDescription = changes.symbolDescription;
|
|
104
|
+
const reference = sharedStyleRefKey(kind);
|
|
105
|
+
const linked = [...ctx.graph.getAllNodes()].filter((node) => node.id !== style.id && node[reference] === styleId);
|
|
106
|
+
ctx.undo.runBatch("Edit style", () => {
|
|
107
|
+
for (const layer of linked) {
|
|
108
|
+
const layerPatch = { [reference]: styleId };
|
|
109
|
+
for (const field of fields) {
|
|
110
|
+
if (!(field in patch) || hasInstanceOverride(ctx.graph, layer.id, field)) continue;
|
|
111
|
+
Object.assign(layerPatch, { [field]: structuredClone(patch[field]) });
|
|
112
|
+
}
|
|
113
|
+
if (Object.keys(layerPatch).length === 1) continue;
|
|
114
|
+
nodes.updateNodeWithUndo(layer.id, layerPatch, "Update style layer");
|
|
115
|
+
}
|
|
116
|
+
nodes.updateNodeWithUndo(style.id, patch, "Edit style");
|
|
117
|
+
});
|
|
118
|
+
ctx.requestRender();
|
|
119
|
+
return {
|
|
120
|
+
styleId,
|
|
121
|
+
layerIds: linked.map((node) => node.id)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export { createStyleActions, createStyleNode, supportsStyleKind };
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","names":[],"sources":["../../src/editor/styles.ts"],"sourcesContent":["import { isNil } from 'es-toolkit'\n\nimport type { SceneNode, SharedStyleKind, SharedStyleType } from '@pairdraw/scene-graph'\nimport { hasInstanceOverride } from '@pairdraw/scene-graph/instances'\nimport {\n SHARED_STYLE_FIELDS,\n sharedStyleLayers,\n sharedStyleRefKey,\n sharedStyleTypeForKind\n} from '@pairdraw/scene-graph/shared-styles'\n\nimport { styleNodeProps, styleNodeType } from '#core/io/formats/design-tokens/apply'\n\nimport type { NodeActions } from './nodes'\nimport type { EditorContext } from './types'\n\n/**\n * A new style node, which redo makes again with the same ids so layers stay attached. The one\n * creator the token import and the style picker share.\n */\nexport function createStyleNode(\n ctx: EditorContext,\n type: SharedStyleType,\n fields: Partial<SceneNode>\n): SceneNode {\n const node = ctx.graph.createNode(\n styleNodeType({ kind: type }),\n ctx.state.currentPageId,\n styleNodeProps({ kind: type }, fields)\n )\n node.source.id = crypto.randomUUID()\n const snapshot = structuredClone(node)\n const parentId = node.parentId\n ctx.undo.push({\n label: 'Add style',\n forward: () => {\n ctx.graph.createNodeWithId(snapshot.id, snapshot.type, parentId, structuredClone(snapshot))\n ctx.requestRender()\n },\n inverse: () => {\n ctx.graph.deleteNode(snapshot.id)\n ctx.requestRender()\n }\n })\n return node\n}\n\nconst GRID_KINDS = new Set(['FRAME', 'COMPONENT', 'COMPONENT_SET', 'INSTANCE'])\n\n/** Whether a layer can carry this kind of style at all, as the picker's own fields say. */\nexport function supportsStyleKind(node: SceneNode, kind: SharedStyleKind): boolean {\n if (node.type === 'CANVAS') return false\n if (kind === 'text') return node.type === 'TEXT'\n if (kind === 'grid') return GRID_KINDS.has(node.type)\n return true\n}\n\n/** Whether the layer shows something of this kind, such as a fill or an effect to save. */\nfunction carriesStyleKind(node: SceneNode, kind: SharedStyleKind): boolean {\n return SHARED_STYLE_FIELDS[kind].some((field) => {\n const value = node[field]\n return Array.isArray(value) ? value.length > 0 : !isNil(value)\n })\n}\n\n/** The layer a created style takes its fields from: the first selected one that shows the kind. */\nfunction styleSource(layers: readonly SceneNode[], kind: SharedStyleKind): SceneNode | undefined {\n return layers.find((layer) => supportsStyleKind(layer, kind) && carriesStyleKind(layer, kind))\n}\n\n/**\n * Turns what the selected layers show into one shared style and binds every layer that supports\n * it, as one undo step. The style takes the first layer that shows the kind, so binding changes\n * nothing the person can see; a name may carry `/` groups. Without such a layer nothing is made,\n * as Figma hides creation without paints.\n */\nfunction createStyleFromSelection(\n ctx: EditorContext,\n nodes: NodeActions,\n kind: SharedStyleKind,\n name: string\n): SceneNode | null {\n const layers = [...ctx.state.selectedIds]\n .map((id) => ctx.graph.getNode(id))\n .filter((node): node is SceneNode => node !== undefined)\n const first = styleSource(layers, kind)\n if (!first) return null\n\n const fields: Partial<SceneNode> = {}\n for (const key of SHARED_STYLE_FIELDS[kind]) {\n Object.assign(fields, { [key]: structuredClone(first[key]) })\n }\n\n return ctx.undo.runBatch('Create style', () => {\n const style = createStyleNode(ctx, sharedStyleTypeForKind(kind), {\n ...fields,\n name: name.trim() || first.name\n })\n const styleId = style.source.id\n const refKey = sharedStyleRefKey(kind)\n for (const layer of layers) {\n if (!supportsStyleKind(layer, kind)) continue\n nodes.updateNodeWithUndo(layer.id, { [refKey]: styleId }, `Apply ${kind} style`)\n }\n ctx.requestRender()\n return style\n })\n}\n\n/** Makes shared styles from what a layer shows, as the style picker asks. */\nexport function createStyleActions(ctx: EditorContext, nodes: NodeActions) {\n return {\n createStyleFromSelection: (kind: SharedStyleKind, name: string) =>\n createStyleFromSelection(ctx, nodes, kind, name),\n /** Whether the selection holds something to save for this kind, so the picker can offer it. */\n updateSharedStyle: (\n styleId: string,\n kind: SharedStyleKind,\n changes: SharedStyleDefinitionChanges\n ) => updateSharedStyle(ctx, nodes, styleId, kind, changes),\n canCreateStyle: (kind: SharedStyleKind) => {\n const layers = [...ctx.state.selectedIds]\n .map((id) => ctx.graph.getNode(id))\n .filter((node): node is SceneNode => node !== undefined)\n return styleSource(layers, kind) !== undefined\n }\n }\n}\n\n/** The fields an edit of a shared definition writes for its kind. */\nexport type SharedStyleDefinitionChanges = Partial<\n Pick<\n SceneNode,\n | 'name'\n | 'symbolDescription'\n | 'fills'\n | 'strokes'\n | 'effects'\n | 'layoutGrids'\n | 'fontFamily'\n | 'fontWeight'\n | 'italic'\n | 'fontStyle'\n | 'fontSize'\n | 'lineHeight'\n | 'letterSpacing'\n | 'textDecoration'\n | 'textCase'\n | 'fontFeatures'\n | 'paragraphSpacing'\n | 'paragraphIndent'\n | 'listSpacing'\n >\n>\n\n/**\n * Writes a shared style's definition and re-applies its fields to every layer linked to that style,\n * as one undo step. A layer's own name and description never follow the style. A layer that detached\n * (its reference cleared) is not touched. An instance field the person overrode keeps its value, as\n * in Figma; the other fields still follow.\n */\nfunction updateSharedStyle(\n ctx: EditorContext,\n nodes: NodeActions,\n styleId: string,\n kind: SharedStyleKind,\n changes: SharedStyleDefinitionChanges\n): { styleId: string; layerIds: string[] } | null {\n const style = [...sharedStyleLayers(ctx.graph).values()].find(\n (node) => node.source.id === styleId && node.sharedStyleType === sharedStyleTypeForKind(kind)\n )\n if (!style) return null\n\n const fields = SHARED_STYLE_FIELDS[kind]\n const patch: Partial<SceneNode> = {}\n for (const field of fields) {\n if (field in changes) Object.assign(patch, { [field]: structuredClone(changes[field]) })\n }\n if (changes.name !== undefined) patch.name = changes.name.trim() || style.name\n if (changes.symbolDescription !== undefined) patch.symbolDescription = changes.symbolDescription\n\n const reference = sharedStyleRefKey(kind)\n const linked = [...ctx.graph.getAllNodes()].filter(\n (node) => node.id !== style.id && node[reference] === styleId\n )\n ctx.undo.runBatch('Edit style', () => {\n for (const layer of linked) {\n // Naming the same reference keeps the node action from treating a definition reapply as a\n // local paint edit.\n const layerPatch: Partial<SceneNode> = { [reference]: styleId }\n for (const field of fields) {\n if (!(field in patch) || hasInstanceOverride(ctx.graph, layer.id, field)) continue\n Object.assign(layerPatch, { [field]: structuredClone(patch[field]) })\n }\n // A rename or description edit changes no linked layer.\n if (Object.keys(layerPatch).length === 1) continue\n nodes.updateNodeWithUndo(layer.id, layerPatch, 'Update style layer')\n }\n nodes.updateNodeWithUndo(style.id, patch, 'Edit style')\n })\n ctx.requestRender()\n return { styleId, layerIds: linked.map((node) => node.id) }\n}\n"],"mappings":"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"}
|
|
@@ -13,6 +13,7 @@ declare function createTextSelectionStyle(ctx: EditorContext, runTextEditStep: (
|
|
|
13
13
|
commitNodeUpdate: (id: string, previous: Partial<SceneNode>, commit: NodeUpdate, updateWithUndo: NodeUpdate) => void;
|
|
14
14
|
selectionStyle: (node: SceneNode) => Partial<SceneNode> | null;
|
|
15
15
|
layerChanges: (id: string, changes: Partial<SceneNode>) => Partial<SceneNode>;
|
|
16
|
+
isTextStyleMixed: (id: string, key: string) => boolean;
|
|
16
17
|
};
|
|
17
18
|
//#endregion
|
|
18
19
|
export { createTextSelectionStyle };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection-style.d.ts","names":[],"sources":["../../../src/editor/text/selection-style.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"selection-style.d.ts","names":[],"sources":["../../../src/editor/text/selection-style.ts"],"mappings":";;;KAgBK,cAAc,YAAY,SAAS,QAAQ;;;;;;iBAWhC,yBACd,KAAK,eACL,kBAAkB;EA6BM,aAAA,YAAM,SAAW,QAAQ,YAAU,QAAU;EAkBrC,qBAAA,YAAM,SAAW,QAAQ,YAAU,QAAU;EAevE,mBAAA,YAAM,UACA,QAAQ,YAAU,QACpB,YAAU,gBACF;EAuBY,iBAAA,MAAA,cAAY,QAAQ;EAaxB,eAAA,YAAM,SAAW,QAAQ,eAAa,QAAQ;EAO1C,mBAAA,YAAM"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TEXT_STYLE_KEYS, characterStyles, layerTextStyleChanges, shownTextStyle, styleRunsWithPatch } from "../../text/character-style.js";
|
|
1
|
+
import { TEXT_STYLE_KEYS, characterStyles, layerTextStyleChanges, mixedTextStyleKeys, shownTextStyle, styleRunsWithPatch } from "../../text/character-style.js";
|
|
2
2
|
import { isEqual } from "es-toolkit/predicate";
|
|
3
3
|
import { omit, pick } from "es-toolkit/object";
|
|
4
4
|
//#region src/editor/text/selection-style.ts
|
|
@@ -103,12 +103,20 @@ function createTextSelectionStyle(ctx, runTextEditStep) {
|
|
|
103
103
|
if (!node || ctx.state.editingTextId === id) return changes;
|
|
104
104
|
return layerTextStyleChanges(node, changes);
|
|
105
105
|
}
|
|
106
|
+
/** Whether the characters the panel would edit differ in this style, so the row shows Mixed. */
|
|
107
|
+
function isTextStyleMixed(id, key) {
|
|
108
|
+
const node = ctx.graph.getNode(id);
|
|
109
|
+
if (!node) return false;
|
|
110
|
+
const range = selectedRange(id);
|
|
111
|
+
return (range ? mixedTextStyleKeys(node, range[0], range[1]) : mixedTextStyleKeys(node)).includes(key);
|
|
112
|
+
}
|
|
106
113
|
return {
|
|
107
114
|
updateNode,
|
|
108
115
|
updateNodeWithUndo,
|
|
109
116
|
commitNodeUpdate,
|
|
110
117
|
selectionStyle,
|
|
111
|
-
layerChanges
|
|
118
|
+
layerChanges,
|
|
119
|
+
isTextStyleMixed
|
|
112
120
|
};
|
|
113
121
|
}
|
|
114
122
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection-style.js","names":[],"sources":["../../../src/editor/text/selection-style.ts"],"sourcesContent":["import { omit, pick } from 'es-toolkit/object'\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport type { CharacterStyleOverride, SceneNode, StyleRun } from '@pairdraw/scene-graph'\n\nimport type { EditorContext } from '#core/editor/types'\nimport {\n characterStyles,\n layerTextStyleChanges,\n shownTextStyle,\n styleRunsWithPatch,\n TEXT_STYLE_KEYS,\n type TextStyleKey\n} from '#core/text/character-style'\n\ntype NodeUpdate = (id: string, changes: Partial<SceneNode>) => void\n\nfunction styleKeys(changes: Partial<SceneNode>): TextStyleKey[] {\n return TEXT_STYLE_KEYS.filter((key) => Object.hasOwn(changes, key))\n}\n\n/**\n * While text is edited with characters selected, a property its characters can each have, such\n * as a fill or font size, styles the selected characters instead of the layer, as in Figma. A\n * change that applies a text style still applies to the layer.\n */\nexport function createTextSelectionStyle(\n ctx: EditorContext,\n runTextEditStep: (change: () => void) => void\n) {\n /**\n * The style runs a previewed change started from, which its commit records as undone to, and\n * the runs it last left; anything else changing them since ends the preview.\n */\n let preview: { nodeId: string; start: StyleRun[]; shown: StyleRun[] } | null = null\n\n function previewOf(id: string) {\n const node = ctx.graph.getNode(id)\n // Graph values are replaced rather than written into, so the runs it left are still its own.\n return preview?.nodeId === id && node?.styleRuns === preview.shown ? preview : null\n }\n\n function selectedRange(id: string): [number, number] | null {\n if (ctx.state.editingTextId !== id) return null\n return ctx.getTextEditor()?.getSelectionRange() ?? null\n }\n\n function rangeChanges(id: string, changes: Partial<SceneNode>): Partial<SceneNode> | null {\n const range = selectedRange(id)\n const node = ctx.graph.getNode(id)\n const keys = styleKeys(changes)\n if (!range || !node || keys.length === 0 || Object.hasOwn(changes, 'textStyleId')) return null\n const patch = pick(changes, keys) as CharacterStyleOverride\n return { ...omit(changes, keys), styleRuns: styleRunsWithPatch(node, ...range, patch) }\n }\n\n /** A change shown before it is committed, such as a dragged field. */\n function updateNode(id: string, changes: Partial<SceneNode>, update: NodeUpdate) {\n const ranged = rangeChanges(id, changes)\n if (!ranged) {\n update(id, changes)\n return\n }\n const current = previewOf(id)\n let start = current?.start ?? []\n // What was typed becomes a step of its own before the preview starts.\n if (!current) {\n runTextEditStep(() => {\n start = structuredClone(ctx.graph.getNode(id)?.styleRuns ?? [])\n })\n }\n update(id, ranged)\n preview = { nodeId: id, start, shown: ctx.graph.getNode(id)?.styleRuns ?? [] }\n }\n\n function updateNodeWithUndo(id: string, changes: Partial<SceneNode>, update: NodeUpdate) {\n const ranged = rangeChanges(id, changes)\n if (!ranged) {\n update(id, changes)\n return\n }\n preview = null\n runTextEditStep(() => update(id, ranged))\n }\n\n /**\n * Records a previewed change, given the values it replaced. The selected characters had\n * styles of their own, so the step undoes to the runs the preview started from.\n */\n function commitNodeUpdate(\n id: string,\n previous: Partial<SceneNode>,\n commit: NodeUpdate,\n updateWithUndo: NodeUpdate\n ) {\n const current = previewOf(id)\n const keys = styleKeys(previous)\n preview = null\n if (!current || keys.length === 0) {\n commit(id, previous)\n return\n }\n const previewed = current.shown\n // Back to where the preview started, so the edit session records nothing of its own.\n ctx.graph.updateNode(id, { styleRuns: current.start })\n runTextEditStep(() => {\n if (!isEqual(previewed, current.start)) updateWithUndo(id, { styleRuns: previewed })\n commit(id, omit(previous, keys))\n })\n }\n\n /**\n * The style of the selected characters as the layer's own properties, for the panel to show;\n * characters styled differently show the first one's. A text not being edited shows its first\n * character's, so a style its ranges set shows instead of one they hide.\n */\n function selectionStyle(node: SceneNode): Partial<SceneNode> | null {\n const range = selectedRange(node.id)\n if (!range) return shownTextStyle(node)\n const [style] = characterStyles(node, range[0], range[0] + 1)\n // Links, styles, and bindings of characters are not the layer's own properties.\n return pick(style, TEXT_STYLE_KEYS)\n }\n\n /**\n * A change the panel makes to a layer: on a text not being edited, a style it sets applies to\n * every character, so a range styled on its own no longer hides it. While text is edited the\n * change goes to the selected characters, as `updateNode` sends it.\n */\n function layerChanges(id: string, changes: Partial<SceneNode>): Partial<SceneNode> {\n const node = ctx.graph.getNode(id)\n if (!node || ctx.state.editingTextId === id) return changes\n return layerTextStyleChanges(node, changes)\n }\n\n
|
|
1
|
+
{"version":3,"file":"selection-style.js","names":[],"sources":["../../../src/editor/text/selection-style.ts"],"sourcesContent":["import { omit, pick } from 'es-toolkit/object'\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport type { CharacterStyleOverride, SceneNode, StyleRun } from '@pairdraw/scene-graph'\n\nimport type { EditorContext } from '#core/editor/types'\nimport {\n characterStyles,\n layerTextStyleChanges,\n mixedTextStyleKeys,\n shownTextStyle,\n styleRunsWithPatch,\n TEXT_STYLE_KEYS,\n type TextStyleKey\n} from '#core/text/character-style'\n\ntype NodeUpdate = (id: string, changes: Partial<SceneNode>) => void\n\nfunction styleKeys(changes: Partial<SceneNode>): TextStyleKey[] {\n return TEXT_STYLE_KEYS.filter((key) => Object.hasOwn(changes, key))\n}\n\n/**\n * While text is edited with characters selected, a property its characters can each have, such\n * as a fill or font size, styles the selected characters instead of the layer, as in Figma. A\n * change that applies a text style still applies to the layer.\n */\nexport function createTextSelectionStyle(\n ctx: EditorContext,\n runTextEditStep: (change: () => void) => void\n) {\n /**\n * The style runs a previewed change started from, which its commit records as undone to, and\n * the runs it last left; anything else changing them since ends the preview.\n */\n let preview: { nodeId: string; start: StyleRun[]; shown: StyleRun[] } | null = null\n\n function previewOf(id: string) {\n const node = ctx.graph.getNode(id)\n // Graph values are replaced rather than written into, so the runs it left are still its own.\n return preview?.nodeId === id && node?.styleRuns === preview.shown ? preview : null\n }\n\n function selectedRange(id: string): [number, number] | null {\n if (ctx.state.editingTextId !== id) return null\n return ctx.getTextEditor()?.getSelectionRange() ?? null\n }\n\n function rangeChanges(id: string, changes: Partial<SceneNode>): Partial<SceneNode> | null {\n const range = selectedRange(id)\n const node = ctx.graph.getNode(id)\n const keys = styleKeys(changes)\n if (!range || !node || keys.length === 0 || Object.hasOwn(changes, 'textStyleId')) return null\n const patch = pick(changes, keys) as CharacterStyleOverride\n return { ...omit(changes, keys), styleRuns: styleRunsWithPatch(node, ...range, patch) }\n }\n\n /** A change shown before it is committed, such as a dragged field. */\n function updateNode(id: string, changes: Partial<SceneNode>, update: NodeUpdate) {\n const ranged = rangeChanges(id, changes)\n if (!ranged) {\n update(id, changes)\n return\n }\n const current = previewOf(id)\n let start = current?.start ?? []\n // What was typed becomes a step of its own before the preview starts.\n if (!current) {\n runTextEditStep(() => {\n start = structuredClone(ctx.graph.getNode(id)?.styleRuns ?? [])\n })\n }\n update(id, ranged)\n preview = { nodeId: id, start, shown: ctx.graph.getNode(id)?.styleRuns ?? [] }\n }\n\n function updateNodeWithUndo(id: string, changes: Partial<SceneNode>, update: NodeUpdate) {\n const ranged = rangeChanges(id, changes)\n if (!ranged) {\n update(id, changes)\n return\n }\n preview = null\n runTextEditStep(() => update(id, ranged))\n }\n\n /**\n * Records a previewed change, given the values it replaced. The selected characters had\n * styles of their own, so the step undoes to the runs the preview started from.\n */\n function commitNodeUpdate(\n id: string,\n previous: Partial<SceneNode>,\n commit: NodeUpdate,\n updateWithUndo: NodeUpdate\n ) {\n const current = previewOf(id)\n const keys = styleKeys(previous)\n preview = null\n if (!current || keys.length === 0) {\n commit(id, previous)\n return\n }\n const previewed = current.shown\n // Back to where the preview started, so the edit session records nothing of its own.\n ctx.graph.updateNode(id, { styleRuns: current.start })\n runTextEditStep(() => {\n if (!isEqual(previewed, current.start)) updateWithUndo(id, { styleRuns: previewed })\n commit(id, omit(previous, keys))\n })\n }\n\n /**\n * The style of the selected characters as the layer's own properties, for the panel to show;\n * characters styled differently show the first one's. A text not being edited shows its first\n * character's, so a style its ranges set shows instead of one they hide.\n */\n function selectionStyle(node: SceneNode): Partial<SceneNode> | null {\n const range = selectedRange(node.id)\n if (!range) return shownTextStyle(node)\n const [style] = characterStyles(node, range[0], range[0] + 1)\n // Links, styles, and bindings of characters are not the layer's own properties.\n return pick(style, TEXT_STYLE_KEYS)\n }\n\n /**\n * A change the panel makes to a layer: on a text not being edited, a style it sets applies to\n * every character, so a range styled on its own no longer hides it. While text is edited the\n * change goes to the selected characters, as `updateNode` sends it.\n */\n function layerChanges(id: string, changes: Partial<SceneNode>): Partial<SceneNode> {\n const node = ctx.graph.getNode(id)\n if (!node || ctx.state.editingTextId === id) return changes\n return layerTextStyleChanges(node, changes)\n }\n\n /** Whether the characters the panel would edit differ in this style, so the row shows Mixed. */\n function isTextStyleMixed(id: string, key: string): boolean {\n const node = ctx.graph.getNode(id)\n if (!node) return false\n const range = selectedRange(id)\n const keys = range ? mixedTextStyleKeys(node, range[0], range[1]) : mixedTextStyleKeys(node)\n return (keys as readonly string[]).includes(key)\n }\n\n return {\n updateNode,\n updateNodeWithUndo,\n commitNodeUpdate,\n selectionStyle,\n layerChanges,\n isTextStyleMixed\n }\n}\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-registry.d.ts","names":[],"sources":["../../src/editor/tool-registry.ts"],"mappings":";;UAEiB;EACf,KAAK;EACL;EACA;EACA,SAAS;;cAGE,cAAc;
|
|
1
|
+
{"version":3,"file":"tool-registry.d.ts","names":[],"sources":["../../src/editor/tool-registry.ts"],"mappings":";;UAEiB;EACf,KAAK;EACL;EACA;EACA,SAAS;;cAGE,cAAc;cAwBd,gBAAgB,QAAQ,eAAe;;;;;cAuBvC,aAAa,YAAY;;cAazB,sBAAsB,QAAQ,eAAe"}
|
|
@@ -30,6 +30,11 @@ const EDITOR_TOOLS = [
|
|
|
30
30
|
shortcut: "P",
|
|
31
31
|
flyout: ["PEN", "PENCIL"]
|
|
32
32
|
},
|
|
33
|
+
{
|
|
34
|
+
key: "SLICE",
|
|
35
|
+
label: "Slice",
|
|
36
|
+
shortcut: "S"
|
|
37
|
+
},
|
|
33
38
|
{
|
|
34
39
|
key: "TEXT",
|
|
35
40
|
label: "Text",
|
|
@@ -68,6 +73,7 @@ const TOOL_SHORTCUTS = {
|
|
|
68
73
|
KeyA: "FRAME",
|
|
69
74
|
"Shift+KeyS": "SECTION",
|
|
70
75
|
KeyR: "RECTANGLE",
|
|
76
|
+
KeyS: "SLICE",
|
|
71
77
|
KeyO: "ELLIPSE",
|
|
72
78
|
KeyL: "LINE",
|
|
73
79
|
KeyT: "TEXT",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-registry.js","names":[],"sources":["../../src/editor/tool-registry.ts"],"sourcesContent":["import type { Tool } from './types'\n\nexport interface EditorToolDef {\n key: Tool\n label: string\n shortcut: string\n flyout?: Tool[]\n}\n\nexport const EDITOR_TOOLS: EditorToolDef[] = [\n // Figma keeps Scale (K) in the Move flyout.\n { key: 'SELECT', label: 'Move', shortcut: 'V', flyout: ['SELECT', 'SCALE'] },\n { key: 'FRAME', label: 'Frame', shortcut: 'F', flyout: ['FRAME', 'SECTION'] },\n {\n key: 'RECTANGLE',\n label: 'Rectangle',\n shortcut: 'R',\n flyout: ['RECTANGLE', 'LINE', 'ELLIPSE', 'POLYGON', 'STAR']\n },\n { key: 'PEN', label: 'Pen', shortcut: 'P', flyout: ['PEN', 'PENCIL'] },\n { key: 'TEXT', label: 'Text', shortcut: 'T' },\n // Figma's S is Slice, and FigJam's sticky tool has no key in Figma Design.\n { key: 'STICKY', label: 'Sticky note', shortcut: '' },\n // FigJam's R; here R is the rectangle, as in Figma Design.\n { key: 'SHAPE_WITH_TEXT', label: 'Shape', shortcut: '' },\n // FigJam's X; Figma Design has no connector tool to take a key from.\n { key: 'CONNECTOR', label: 'Connector', shortcut: '' },\n // Zoom is held on Z, as in Figma, or picked here to stay on.\n { key: 'HAND', label: 'Hand', shortcut: 'H', flyout: ['HAND', 'ZOOM'] },\n { key: 'COMMENT', label: 'Comment', shortcut: 'C' }\n]\n\nexport const TOOL_SHORTCUTS: Partial<Record<string, Tool>> = {\n KeyV: 'SELECT',\n KeyF: 'FRAME',\n KeyA: 'FRAME',\n 'Shift+KeyS': 'SECTION',\n KeyR: 'RECTANGLE',\n KeyO: 'ELLIPSE',\n KeyL: 'LINE',\n KeyT: 'TEXT',\n KeyP: 'PEN',\n 'Shift+KeyP': 'PENCIL',\n KeyH: 'HAND',\n KeyC: 'COMMENT',\n KeyK: 'SCALE',\n KeyZ: 'ZOOM',\n KeyI: 'EYEDROPPER'\n}\n\n/**\n * The tools a board offers, as FigJam's toolbar does: moving and panning, sticky notes, shapes,\n * connectors, sections, text, and comments, without Figma Design's drawing tools.\n */\nexport const BOARD_TOOLS: ReadonlySet<Tool> = new Set<Tool>([\n 'SELECT',\n 'HAND',\n 'STICKY',\n 'SHAPE_WITH_TEXT',\n 'CONNECTOR',\n 'SECTION',\n 'TEXT',\n 'COMMENT',\n 'ZOOM'\n])\n\n/** A board's tool keys, as in FigJam: S places a sticky note, R a shape, and X a connector. */\nexport const BOARD_TOOL_SHORTCUTS: Partial<Record<string, Tool>> = {\n KeyV: 'SELECT',\n KeyH: 'HAND',\n KeyS: 'STICKY',\n 'Shift+KeyS': 'SECTION',\n KeyR: 'SHAPE_WITH_TEXT',\n KeyX: 'CONNECTOR',\n KeyT: 'TEXT',\n KeyC: 'COMMENT',\n KeyZ: 'ZOOM'\n}\n"],"mappings":";AASA,MAAa,eAAgC;CAE3C;EAAE,KAAK;EAAU,OAAO;EAAQ,UAAU;EAAK,QAAQ,CAAC,UAAU,OAAO;CAAE;CAC3E;EAAE,KAAK;EAAS,OAAO;EAAS,UAAU;EAAK,QAAQ,CAAC,SAAS,SAAS;CAAE;CAC5E;EACE,KAAK;EACL,OAAO;EACP,UAAU;EACV,QAAQ;GAAC;GAAa;GAAQ;GAAW;GAAW;EAAM;CAC5D;CACA;EAAE,KAAK;EAAO,OAAO;EAAO,UAAU;EAAK,QAAQ,CAAC,OAAO,QAAQ;CAAE;CACrE;EAAE,KAAK;EAAQ,OAAO;EAAQ,UAAU;CAAI;CAE5C;EAAE,KAAK;EAAU,OAAO;EAAe,UAAU;CAAG;CAEpD;EAAE,KAAK;EAAmB,OAAO;EAAS,UAAU;CAAG;CAEvD;EAAE,KAAK;EAAa,OAAO;EAAa,UAAU;CAAG;CAErD;EAAE,KAAK;EAAQ,OAAO;EAAQ,UAAU;EAAK,QAAQ,CAAC,QAAQ,MAAM;CAAE;CACtE;EAAE,KAAK;EAAW,OAAO;EAAW,UAAU;CAAI;AACpD;AAEA,MAAa,iBAAgD;CAC3D,MAAM;CACN,MAAM;CACN,MAAM;CACN,cAAc;CACd,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,cAAc;CACd,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;AACR;;;;;AAMA,MAAa,8BAAiC,IAAI,IAAU;CAC1D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAa,uBAAsD;CACjE,MAAM;CACN,MAAM;CACN,MAAM;CACN,cAAc;CACd,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;AACR"}
|
|
1
|
+
{"version":3,"file":"tool-registry.js","names":[],"sources":["../../src/editor/tool-registry.ts"],"sourcesContent":["import type { Tool } from './types'\n\nexport interface EditorToolDef {\n key: Tool\n label: string\n shortcut: string\n flyout?: Tool[]\n}\n\nexport const EDITOR_TOOLS: EditorToolDef[] = [\n // Figma keeps Scale (K) in the Move flyout.\n { key: 'SELECT', label: 'Move', shortcut: 'V', flyout: ['SELECT', 'SCALE'] },\n { key: 'FRAME', label: 'Frame', shortcut: 'F', flyout: ['FRAME', 'SECTION'] },\n {\n key: 'RECTANGLE',\n label: 'Rectangle',\n shortcut: 'R',\n flyout: ['RECTANGLE', 'LINE', 'ELLIPSE', 'POLYGON', 'STAR']\n },\n { key: 'PEN', label: 'Pen', shortcut: 'P', flyout: ['PEN', 'PENCIL'] },\n { key: 'SLICE', label: 'Slice', shortcut: 'S' },\n { key: 'TEXT', label: 'Text', shortcut: 'T' },\n // Figma's S is Slice, and FigJam's sticky tool has no key in Figma Design.\n { key: 'STICKY', label: 'Sticky note', shortcut: '' },\n // FigJam's R; here R is the rectangle, as in Figma Design.\n { key: 'SHAPE_WITH_TEXT', label: 'Shape', shortcut: '' },\n // FigJam's X; Figma Design has no connector tool to take a key from.\n { key: 'CONNECTOR', label: 'Connector', shortcut: '' },\n // Zoom is held on Z, as in Figma, or picked here to stay on.\n { key: 'HAND', label: 'Hand', shortcut: 'H', flyout: ['HAND', 'ZOOM'] },\n { key: 'COMMENT', label: 'Comment', shortcut: 'C' }\n]\n\nexport const TOOL_SHORTCUTS: Partial<Record<string, Tool>> = {\n KeyV: 'SELECT',\n KeyF: 'FRAME',\n KeyA: 'FRAME',\n 'Shift+KeyS': 'SECTION',\n KeyR: 'RECTANGLE',\n KeyS: 'SLICE',\n KeyO: 'ELLIPSE',\n KeyL: 'LINE',\n KeyT: 'TEXT',\n KeyP: 'PEN',\n 'Shift+KeyP': 'PENCIL',\n KeyH: 'HAND',\n KeyC: 'COMMENT',\n KeyK: 'SCALE',\n KeyZ: 'ZOOM',\n KeyI: 'EYEDROPPER'\n}\n\n/**\n * The tools a board offers, as FigJam's toolbar does: moving and panning, sticky notes, shapes,\n * connectors, sections, text, and comments, without Figma Design's drawing tools.\n */\nexport const BOARD_TOOLS: ReadonlySet<Tool> = new Set<Tool>([\n 'SELECT',\n 'HAND',\n 'STICKY',\n 'SHAPE_WITH_TEXT',\n 'CONNECTOR',\n 'SECTION',\n 'TEXT',\n 'COMMENT',\n 'ZOOM'\n])\n\n/** A board's tool keys, as in FigJam: S places a sticky note, R a shape, and X a connector. */\nexport const BOARD_TOOL_SHORTCUTS: Partial<Record<string, Tool>> = {\n KeyV: 'SELECT',\n KeyH: 'HAND',\n KeyS: 'STICKY',\n 'Shift+KeyS': 'SECTION',\n KeyR: 'SHAPE_WITH_TEXT',\n KeyX: 'CONNECTOR',\n KeyT: 'TEXT',\n KeyC: 'COMMENT',\n KeyZ: 'ZOOM'\n}\n"],"mappings":";AASA,MAAa,eAAgC;CAE3C;EAAE,KAAK;EAAU,OAAO;EAAQ,UAAU;EAAK,QAAQ,CAAC,UAAU,OAAO;CAAE;CAC3E;EAAE,KAAK;EAAS,OAAO;EAAS,UAAU;EAAK,QAAQ,CAAC,SAAS,SAAS;CAAE;CAC5E;EACE,KAAK;EACL,OAAO;EACP,UAAU;EACV,QAAQ;GAAC;GAAa;GAAQ;GAAW;GAAW;EAAM;CAC5D;CACA;EAAE,KAAK;EAAO,OAAO;EAAO,UAAU;EAAK,QAAQ,CAAC,OAAO,QAAQ;CAAE;CACrE;EAAE,KAAK;EAAS,OAAO;EAAS,UAAU;CAAI;CAC9C;EAAE,KAAK;EAAQ,OAAO;EAAQ,UAAU;CAAI;CAE5C;EAAE,KAAK;EAAU,OAAO;EAAe,UAAU;CAAG;CAEpD;EAAE,KAAK;EAAmB,OAAO;EAAS,UAAU;CAAG;CAEvD;EAAE,KAAK;EAAa,OAAO;EAAa,UAAU;CAAG;CAErD;EAAE,KAAK;EAAQ,OAAO;EAAQ,UAAU;EAAK,QAAQ,CAAC,QAAQ,MAAM;CAAE;CACtE;EAAE,KAAK;EAAW,OAAO;EAAW,UAAU;CAAI;AACpD;AAEA,MAAa,iBAAgD;CAC3D,MAAM;CACN,MAAM;CACN,MAAM;CACN,cAAc;CACd,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,cAAc;CACd,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;AACR;;;;;AAMA,MAAa,8BAAiC,IAAI,IAAU;CAC1D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAa,uBAAsD;CACjE,MAAM;CACN,MAAM;CACN,MAAM;CACN,cAAc;CACd,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;AACR"}
|