@pairdraw/core 0.18.0 → 0.19.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/effects.d.ts +5 -11
- package/dist/canvas/effects.d.ts.map +1 -1
- package/dist/canvas/effects.js +25 -30
- package/dist/canvas/effects.js.map +1 -1
- package/dist/canvas/labels/hit-test.d.ts +5 -0
- package/dist/canvas/labels/hit-test.d.ts.map +1 -1
- package/dist/canvas/labels/hit-test.js +1 -1
- package/dist/canvas/labels/hit-test.js.map +1 -1
- package/dist/canvas/labels/paragraph-cache.d.ts.map +1 -1
- package/dist/canvas/labels/paragraph-cache.js +3 -2
- package/dist/canvas/labels/paragraph-cache.js.map +1 -1
- package/dist/canvas/labels/selection.js +3 -2
- package/dist/canvas/labels/selection.js.map +1 -1
- package/dist/canvas/labels/style.d.ts +1 -1
- package/dist/canvas/node-edit-overlay.js +2 -2
- package/dist/canvas/node-edit-overlay.js.map +1 -1
- package/dist/canvas/overlays/index.d.ts +2 -2
- package/dist/canvas/overlays/index.js +2 -2
- package/dist/canvas/overlays/selection.d.ts +1 -2
- package/dist/canvas/overlays/selection.d.ts.map +1 -1
- package/dist/canvas/overlays/selection.js +4 -37
- package/dist/canvas/overlays/selection.js.map +1 -1
- package/dist/canvas/region-hatch.js +3 -2
- package/dist/canvas/region-hatch.js.map +1 -1
- package/dist/canvas/renderer/colors.d.ts.map +1 -1
- package/dist/canvas/renderer/colors.js +36 -18
- package/dist/canvas/renderer/colors.js.map +1 -1
- package/dist/canvas/renderer/font-waiters.d.ts +9 -0
- package/dist/canvas/renderer/font-waiters.d.ts.map +1 -0
- package/dist/canvas/renderer/font-waiters.js +26 -0
- package/dist/canvas/renderer/font-waiters.js.map +1 -0
- package/dist/canvas/renderer/fonts.d.ts +4 -2
- package/dist/canvas/renderer/fonts.d.ts.map +1 -1
- package/dist/canvas/renderer/fonts.js +23 -9
- package/dist/canvas/renderer/fonts.js.map +1 -1
- package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +6 -9
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts +4 -5
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +1 -4
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/paints.d.ts.map +1 -1
- package/dist/canvas/renderer/paints.js +0 -6
- package/dist/canvas/renderer/paints.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +20 -2
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/retained-backing.js +4 -4
- package/dist/canvas/renderer/retained-backing.js.map +1 -1
- package/dist/canvas/renderer/state.js +1 -1
- package/dist/canvas/renderer/state.js.map +1 -1
- package/dist/canvas/renderer/tiles/controller.d.ts +2 -0
- package/dist/canvas/renderer/tiles/controller.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/controller.js +8 -0
- package/dist/canvas/renderer/tiles/controller.js.map +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.js +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.js.map +1 -1
- package/dist/canvas/renderer/visual-bounds.d.ts.map +1 -1
- package/dist/canvas/renderer/visual-bounds.js +7 -5
- package/dist/canvas/renderer/visual-bounds.js.map +1 -1
- package/dist/canvas/renderer.d.ts +22 -7
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +46 -11
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/rulers.d.ts +8 -1
- package/dist/canvas/rulers.d.ts.map +1 -1
- package/dist/canvas/rulers.js +30 -5
- package/dist/canvas/rulers.js.map +1 -1
- package/dist/canvas/scene.d.ts +2 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +30 -18
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/shadows/shape.js +1 -1
- package/dist/canvas/shadows/shape.js.map +1 -1
- package/dist/canvas/shadows/silhouette.d.ts.map +1 -1
- package/dist/canvas/shadows/silhouette.js +4 -2
- package/dist/canvas/shadows/silhouette.js.map +1 -1
- package/dist/canvas/shadows.d.ts.map +1 -1
- package/dist/canvas/shadows.js +3 -2
- package/dist/canvas/shadows.js.map +1 -1
- package/dist/canvas/text/derived.d.ts +1 -2
- package/dist/canvas/text/derived.d.ts.map +1 -1
- package/dist/canvas/text/derived.js +1 -7
- package/dist/canvas/text/derived.js.map +1 -1
- package/dist/canvas/text/emoji/index.js +1 -1
- package/dist/canvas/text/emoji/raster.d.ts.map +1 -1
- package/dist/canvas/text/emoji/raster.js +14 -10
- package/dist/canvas/text/emoji/raster.js.map +1 -1
- package/dist/canvas/text/font-families.d.ts.map +1 -1
- package/dist/canvas/text/font-families.js +5 -2
- package/dist/canvas/text/font-families.js.map +1 -1
- package/dist/canvas/text/index.d.ts +1 -3
- package/dist/canvas/text/index.d.ts.map +1 -1
- package/dist/canvas/text/index.js +1 -8
- package/dist/canvas/text/index.js.map +1 -1
- package/dist/canvas/text/layout/build.d.ts.map +1 -1
- package/dist/canvas/text/layout/build.js +25 -9
- package/dist/canvas/text/layout/build.js.map +1 -1
- package/dist/canvas/text/layout/index.d.ts.map +1 -1
- package/dist/canvas/text/layout/index.js +8 -4
- package/dist/canvas/text/layout/index.js.map +1 -1
- package/dist/canvas/text/layout/lines.js +5 -3
- package/dist/canvas/text/layout/lines.js.map +1 -1
- package/dist/canvas/text/paragraph/index.d.ts +5 -0
- package/dist/canvas/text/paragraph/index.d.ts.map +1 -1
- package/dist/canvas/text/paragraph/index.js +16 -7
- package/dist/canvas/text/paragraph/index.js.map +1 -1
- package/dist/canvas/text/paragraph/inputs.d.ts +1 -1
- package/dist/canvas/text/paragraph/inputs.d.ts.map +1 -1
- package/dist/canvas/text/paragraph/inputs.js +9 -2
- package/dist/canvas/text/paragraph/inputs.js.map +1 -1
- package/dist/canvas/text/placed.js +1 -1
- package/dist/canvas/text/shape.d.ts +4 -3
- package/dist/canvas/text/shape.d.ts.map +1 -1
- package/dist/canvas/text/shape.js +9 -22
- package/dist/canvas/text/shape.js.map +1 -1
- package/dist/constants.d.ts +6 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +6 -2
- package/dist/constants.js.map +1 -1
- package/dist/editor/bridges/clipboard.d.ts +1 -0
- package/dist/editor/bridges/clipboard.js +1 -0
- package/dist/editor/bridges/clipboard.js.map +1 -1
- package/dist/editor/bridges/components.d.ts +2 -0
- package/dist/editor/bridges/components.d.ts.map +1 -1
- package/dist/editor/bridges/components.js +2 -0
- package/dist/editor/bridges/components.js.map +1 -1
- package/dist/editor/bridges/frames.d.ts +4 -3
- package/dist/editor/bridges/frames.d.ts.map +1 -1
- package/dist/editor/bridges/frames.js +6 -4
- package/dist/editor/bridges/frames.js.map +1 -1
- package/dist/editor/bridges/structure.d.ts +1 -0
- package/dist/editor/bridges/structure.d.ts.map +1 -1
- package/dist/editor/bridges/structure.js +1 -0
- package/dist/editor/bridges/structure.js.map +1 -1
- package/dist/editor/clipboard/detach.js +2 -2
- package/dist/editor/clipboard/detach.js.map +1 -1
- package/dist/editor/clipboard/paste/properties.js +1 -1
- package/dist/editor/clipboard/paste/target.js +2 -2
- package/dist/editor/clipboard/paste/target.js.map +1 -1
- package/dist/editor/clipboard/snapshot.d.ts +3 -0
- package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
- package/dist/editor/clipboard/snapshot.js +2 -0
- package/dist/editor/clipboard/snapshot.js.map +1 -1
- package/dist/editor/clipboard/variables.d.ts.map +1 -1
- package/dist/editor/clipboard/variables.js +14 -1
- package/dist/editor/clipboard/variables.js.map +1 -1
- package/dist/editor/clipboard.d.ts +1 -0
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +122 -16
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/component-sync.d.ts +10 -1
- package/dist/editor/component-sync.d.ts.map +1 -1
- package/dist/editor/component-sync.js +25 -8
- package/dist/editor/component-sync.js.map +1 -1
- package/dist/editor/components/authoring/text-edit.d.ts.map +1 -1
- package/dist/editor/components/authoring/text-edit.js +11 -2
- package/dist/editor/components/authoring/text-edit.js.map +1 -1
- package/dist/editor/components/authoring/visibility-edit.d.ts.map +1 -1
- package/dist/editor/components/authoring/visibility-edit.js +7 -3
- package/dist/editor/components/authoring/visibility-edit.js.map +1 -1
- package/dist/editor/components/instances.d.ts +2 -0
- package/dist/editor/components/instances.d.ts.map +1 -1
- package/dist/editor/components/instances.js +37 -7
- package/dist/editor/components/instances.js.map +1 -1
- package/dist/editor/components/properties.d.ts.map +1 -1
- package/dist/editor/components/properties.js +3 -0
- package/dist/editor/components/properties.js.map +1 -1
- package/dist/editor/components/slots/authoring.js +2 -1
- package/dist/editor/components/slots/authoring.js.map +1 -1
- package/dist/editor/components.d.ts +2 -0
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor/create.d.ts +17 -3
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +43 -6
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/guides.d.ts.map +1 -1
- package/dist/editor/guides.js +20 -13
- package/dist/editor/guides.js.map +1 -1
- package/dist/editor/history/document-change.d.ts +19 -3
- package/dist/editor/history/document-change.d.ts.map +1 -1
- package/dist/editor/history/document-change.js +94 -8
- package/dist/editor/history/document-change.js.map +1 -1
- package/dist/editor/history/edit.d.ts.map +1 -1
- package/dist/editor/history/edit.js +56 -12
- package/dist/editor/history/edit.js.map +1 -1
- package/dist/editor/history/position.js +1 -4
- package/dist/editor/history/position.js.map +1 -1
- package/dist/editor/history/sources.d.ts +14 -0
- package/dist/editor/history/sources.d.ts.map +1 -0
- package/dist/editor/history/sources.js +24 -0
- package/dist/editor/history/sources.js.map +1 -0
- package/dist/editor/index.d.ts +2 -2
- package/dist/editor/index.js +1 -1
- package/dist/editor/layout-mode.d.ts.map +1 -1
- package/dist/editor/layout-mode.js +16 -1
- package/dist/editor/layout-mode.js.map +1 -1
- package/dist/editor/node-preview.d.ts.map +1 -1
- package/dist/editor/node-preview.js +26 -7
- package/dist/editor/node-preview.js.map +1 -1
- package/dist/editor/nodes.d.ts.map +1 -1
- package/dist/editor/nodes.js +33 -10
- package/dist/editor/nodes.js.map +1 -1
- package/dist/editor/nudge.d.ts.map +1 -1
- package/dist/editor/nudge.js +12 -2
- package/dist/editor/nudge.js.map +1 -1
- package/dist/editor/pages.d.ts +2 -1
- package/dist/editor/pages.d.ts.map +1 -1
- package/dist/editor/pages.js +94 -15
- package/dist/editor/pages.js.map +1 -1
- package/dist/editor/play/states.d.ts.map +1 -1
- package/dist/editor/play/states.js +0 -5
- package/dist/editor/play/states.js.map +1 -1
- package/dist/editor/read-only/actions.js +3 -0
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/selection/hit-test.d.ts +2 -1
- package/dist/editor/selection/hit-test.d.ts.map +1 -1
- package/dist/editor/selection/hit-test.js +29 -4
- package/dist/editor/selection/hit-test.js.map +1 -1
- package/dist/editor/selection.d.ts +2 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/shapes/pen.js +6 -2
- package/dist/editor/shapes/pen.js.map +1 -1
- package/dist/editor/shapes.d.ts.map +1 -1
- package/dist/editor/shapes.js +2 -1
- package/dist/editor/shapes.js.map +1 -1
- package/dist/editor/structure/auto-layout-wrap.d.ts.map +1 -1
- package/dist/editor/structure/auto-layout-wrap.js +12 -0
- package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
- package/dist/editor/structure/boolean.js +1 -1
- package/dist/editor/structure/group/bounds.d.ts +4 -2
- package/dist/editor/structure/group/bounds.d.ts.map +1 -1
- package/dist/editor/structure/group/bounds.js +17 -4
- package/dist/editor/structure/group/bounds.js.map +1 -1
- package/dist/editor/structure/rename.d.ts +2 -3
- package/dist/editor/structure/rename.d.ts.map +1 -1
- package/dist/editor/structure/rename.js +2 -5
- package/dist/editor/structure/rename.js.map +1 -1
- package/dist/editor/structure/reorder.d.ts.map +1 -1
- package/dist/editor/structure/reorder.js +20 -9
- package/dist/editor/structure/reorder.js.map +1 -1
- package/dist/editor/structure/state.js +1 -1
- package/dist/editor/structure.d.ts +1 -0
- package/dist/editor/structure.d.ts.map +1 -1
- package/dist/editor/structure.js +76 -20
- package/dist/editor/structure.js.map +1 -1
- package/dist/editor/text/hyperlink.d.ts.map +1 -1
- package/dist/editor/text/hyperlink.js +1 -1
- package/dist/editor/text/hyperlink.js.map +1 -1
- package/dist/editor/text/name.d.ts +13 -5
- package/dist/editor/text/name.d.ts.map +1 -1
- package/dist/editor/text/name.js +47 -17
- package/dist/editor/text/name.js.map +1 -1
- package/dist/editor/text/pending-layout.d.ts +2 -1
- package/dist/editor/text/pending-layout.d.ts.map +1 -1
- package/dist/editor/text/pending-layout.js +33 -6
- package/dist/editor/text/pending-layout.js.map +1 -1
- package/dist/editor/text/selection-style.d.ts +1 -0
- package/dist/editor/text/selection-style.d.ts.map +1 -1
- package/dist/editor/text/selection-style.js +16 -4
- package/dist/editor/text/selection-style.js.map +1 -1
- package/dist/editor/text.d.ts +5 -0
- package/dist/editor/text.d.ts.map +1 -1
- package/dist/editor/text.js +70 -3
- package/dist/editor/text.js.map +1 -1
- package/dist/editor/types.d.ts +18 -1
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/undo.d.ts.map +1 -1
- package/dist/editor/undo.js +14 -2
- package/dist/editor/undo.js.map +1 -1
- package/dist/editor/variable-bindings.d.ts.map +1 -1
- package/dist/editor/variable-bindings.js +21 -2
- package/dist/editor/variable-bindings.js.map +1 -1
- package/dist/editor/variables.d.ts +1 -1
- package/dist/editor/variables.d.ts.map +1 -1
- package/dist/editor/variables.js +7 -8
- package/dist/editor/variables.js.map +1 -1
- package/dist/editor/viewport.d.ts +11 -2
- package/dist/editor/viewport.d.ts.map +1 -1
- package/dist/editor/viewport.js +61 -21
- package/dist/editor/viewport.js.map +1 -1
- package/dist/editor/views/actions.d.ts.map +1 -1
- package/dist/editor/views/actions.js +13 -5
- package/dist/editor/views/actions.js.map +1 -1
- package/dist/editor/views/present.d.ts +6 -4
- package/dist/editor/views/present.d.ts.map +1 -1
- package/dist/editor/views/present.js +12 -10
- package/dist/editor/views/present.js.map +1 -1
- package/dist/editor/views/types.d.ts +11 -5
- package/dist/editor/views/types.d.ts.map +1 -1
- package/dist/figma-api/accessor-utils.d.ts.map +1 -1
- package/dist/figma-api/accessor-utils.js +4 -1
- package/dist/figma-api/accessor-utils.js.map +1 -1
- package/dist/figma-api/accessors/basic.d.ts.map +1 -1
- package/dist/figma-api/accessors/basic.js +41 -21
- package/dist/figma-api/accessors/basic.js.map +1 -1
- package/dist/figma-api/accessors/layout.d.ts.map +1 -1
- package/dist/figma-api/accessors/layout.js +37 -7
- package/dist/figma-api/accessors/layout.js.map +1 -1
- package/dist/figma-api/accessors/reactions.d.ts +11 -0
- package/dist/figma-api/accessors/reactions.d.ts.map +1 -0
- package/dist/figma-api/accessors/reactions.js +30 -0
- package/dist/figma-api/accessors/reactions.js.map +1 -0
- package/dist/figma-api/accessors/strokes.d.ts.map +1 -1
- package/dist/figma-api/accessors/strokes.js +12 -4
- package/dist/figma-api/accessors/strokes.js.map +1 -1
- package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
- package/dist/figma-api/accessors/text/index.js +3 -1
- package/dist/figma-api/accessors/text/index.js.map +1 -1
- package/dist/figma-api/accessors/vector.d.ts.map +1 -1
- package/dist/figma-api/accessors/vector.js +1 -1
- package/dist/figma-api/accessors/vector.js.map +1 -1
- package/dist/figma-api/accessors/visual.d.ts +6 -5
- package/dist/figma-api/accessors/visual.d.ts.map +1 -1
- package/dist/figma-api/accessors/visual.js +20 -17
- package/dist/figma-api/accessors/visual.js.map +1 -1
- package/dist/figma-api/components.d.ts.map +1 -1
- package/dist/figma-api/components.js +2 -1
- package/dist/figma-api/components.js.map +1 -1
- package/dist/figma-api/finite.d.ts +27 -0
- package/dist/figma-api/finite.d.ts.map +1 -0
- package/dist/figma-api/finite.js +69 -0
- package/dist/figma-api/finite.js.map +1 -0
- package/dist/figma-api/fonts/list.d.ts +13 -0
- package/dist/figma-api/fonts/list.d.ts.map +1 -0
- package/dist/figma-api/fonts/list.js +25 -0
- package/dist/figma-api/fonts/list.js.map +1 -0
- package/dist/figma-api/index.d.ts +21 -3
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +58 -13
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/overrides.d.ts +6 -1
- package/dist/figma-api/overrides.d.ts.map +1 -1
- package/dist/figma-api/overrides.js +2 -2
- package/dist/figma-api/overrides.js.map +1 -1
- package/dist/figma-api/pending-layout.d.ts +12 -2
- package/dist/figma-api/pending-layout.d.ts.map +1 -1
- package/dist/figma-api/pending-layout.js +41 -1
- package/dist/figma-api/pending-layout.js.map +1 -1
- package/dist/figma-api/pending-sync.d.ts +19 -0
- package/dist/figma-api/pending-sync.d.ts.map +1 -0
- package/dist/figma-api/pending-sync.js +52 -0
- package/dist/figma-api/pending-sync.js.map +1 -0
- package/dist/figma-api/proxy.d.ts +15 -2
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +23 -3
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +104 -0
- package/dist/figma-api/reactions.d.ts.map +1 -0
- package/dist/figma-api/reactions.js +157 -0
- package/dist/figma-api/reactions.js.map +1 -0
- package/dist/figma-api/render-bounds.d.ts.map +1 -1
- package/dist/figma-api/render-bounds.js +4 -4
- package/dist/figma-api/render-bounds.js.map +1 -1
- package/dist/figma-api/serialization.js +2 -2
- package/dist/figma-api/serialization.js.map +1 -1
- package/dist/figma-api/slots.d.ts +7 -1
- package/dist/figma-api/slots.d.ts.map +1 -1
- package/dist/figma-api/slots.js +12 -4
- package/dist/figma-api/slots.js.map +1 -1
- package/dist/figma-api/strokes.d.ts +5 -2
- package/dist/figma-api/strokes.d.ts.map +1 -1
- package/dist/figma-api/strokes.js +12 -19
- package/dist/figma-api/strokes.js.map +1 -1
- package/dist/figma-api/text/bindings.js +1 -1
- package/dist/figma-api/text/index.d.ts +2 -3
- package/dist/figma-api/text/index.d.ts.map +1 -1
- package/dist/figma-api/text/index.js +2 -12
- package/dist/figma-api/text/index.js.map +1 -1
- package/dist/figma-api/variables/bindings.js +1 -1
- package/dist/figma-api/variables/variable.d.ts.map +1 -1
- package/dist/figma-api/variables/variable.js +2 -2
- package/dist/figma-api/variables/variable.js.map +1 -1
- package/dist/geometry/figma.d.ts +6 -1
- package/dist/geometry/figma.d.ts.map +1 -1
- package/dist/geometry/figma.js +8 -1
- package/dist/geometry/figma.js.map +1 -1
- package/dist/geometry/index.d.ts +2 -2
- package/dist/geometry/index.js +2 -2
- package/dist/icons/api.d.ts +3 -2
- package/dist/icons/api.d.ts.map +1 -1
- package/dist/icons/api.js +12 -12
- package/dist/icons/api.js.map +1 -1
- package/dist/icons/provider.d.ts +4 -3
- package/dist/icons/provider.d.ts.map +1 -1
- package/dist/icons/provider.js +6 -13
- package/dist/icons/provider.js.map +1 -1
- package/dist/icons/schema.d.ts +33 -1
- package/dist/icons/schema.d.ts.map +1 -1
- package/dist/icons/schema.js +30 -1
- package/dist/icons/schema.js.map +1 -1
- package/dist/icons/svg/presentation.d.ts +8 -1
- package/dist/icons/svg/presentation.d.ts.map +1 -1
- package/dist/icons/svg/presentation.js +21 -3
- package/dist/icons/svg/presentation.js.map +1 -1
- package/dist/icons/svg/text.js +1 -1
- package/dist/icons/svg/text.js.map +1 -1
- package/dist/icons/svg.d.ts +8 -3
- package/dist/icons/svg.d.ts.map +1 -1
- package/dist/icons/svg.js +15 -13
- package/dist/icons/svg.js.map +1 -1
- package/dist/icons/types.d.ts +1 -19
- package/dist/icons/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/io/formats/design-tokens/css/read.js +1 -1
- package/dist/io/formats/design-tokens/decode.js +1 -1
- package/dist/io/formats/design-tokens/plan/index.js +4 -2
- package/dist/io/formats/design-tokens/plan/index.js.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.d.ts +9 -1
- package/dist/io/formats/design-tokens/plan/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.js +23 -3
- package/dist/io/formats/design-tokens/plan/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/styles.d.ts +9 -1
- package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/styles.js +41 -4
- package/dist/io/formats/design-tokens/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/types.d.ts +5 -0
- package/dist/io/formats/design-tokens/types.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/types.js +1 -0
- package/dist/io/formats/design-tokens/types.js.map +1 -1
- package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
- package/dist/io/formats/fig/export/setup.js +8 -4
- package/dist/io/formats/fig/export/setup.js.map +1 -1
- package/dist/io/formats/fig/export/variables.d.ts.map +1 -1
- package/dist/io/formats/fig/export/variables.js +2 -2
- package/dist/io/formats/fig/export/variables.js.map +1 -1
- package/dist/io/formats/fig/index.d.ts +2 -2
- package/dist/io/formats/fig/index.js +2 -2
- package/dist/io/formats/fig/read.d.ts +9 -2
- package/dist/io/formats/fig/read.d.ts.map +1 -1
- package/dist/io/formats/fig/read.js +44 -20
- package/dist/io/formats/fig/read.js.map +1 -1
- package/dist/io/formats/html/index.d.ts.map +1 -1
- package/dist/io/formats/html/index.js +2 -6
- package/dist/io/formats/html/index.js.map +1 -1
- package/dist/io/formats/pdf/dom.d.ts.map +1 -1
- package/dist/io/formats/pdf/dom.js +65 -1
- package/dist/io/formats/pdf/dom.js.map +1 -1
- package/dist/io/formats/pdf/prepare.js +1 -1
- package/dist/io/formats/pen/fonts.d.ts +14 -0
- package/dist/io/formats/pen/fonts.d.ts.map +1 -0
- package/dist/io/formats/pen/fonts.js +39 -0
- package/dist/io/formats/pen/fonts.js.map +1 -0
- package/dist/io/formats/pen/index.d.ts.map +1 -1
- package/dist/io/formats/pen/index.js +25 -6
- package/dist/io/formats/pen/index.js.map +1 -1
- package/dist/io/formats/raster/headless.d.ts +2 -2
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +24 -13
- 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 +7 -1
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +40 -6
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +28 -24
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/paths.d.ts +8 -2
- package/dist/io/formats/svg/paths.d.ts.map +1 -1
- package/dist/io/formats/svg/paths.js +11 -3
- package/dist/io/formats/svg/paths.js.map +1 -1
- package/dist/io/formats/svg/strokes.d.ts.map +1 -1
- package/dist/io/formats/svg/strokes.js +2 -5
- package/dist/io/formats/svg/strokes.js.map +1 -1
- package/dist/io/formats/svg/text/export.d.ts.map +1 -1
- package/dist/io/formats/svg/text/export.js +19 -1
- package/dist/io/formats/svg/text/export.js.map +1 -1
- package/dist/io/formats/svg/text/import.d.ts.map +1 -1
- package/dist/io/formats/svg/text/import.js +2 -1
- package/dist/io/formats/svg/text/import.js.map +1 -1
- package/dist/io/subgraph.d.ts.map +1 -1
- package/dist/io/subgraph.js +5 -2
- package/dist/io/subgraph.js.map +1 -1
- package/dist/kiwi/fig/population/client.d.ts.map +1 -1
- package/dist/kiwi/fig/population/client.js +63 -45
- package/dist/kiwi/fig/population/client.js.map +1 -1
- package/dist/kiwi/fig/population/delta.d.ts +34 -3
- package/dist/kiwi/fig/population/delta.d.ts.map +1 -1
- package/dist/kiwi/fig/population/delta.js +99 -16
- package/dist/kiwi/fig/population/delta.js.map +1 -1
- package/dist/kiwi/fig/population/edits.d.ts +51 -0
- package/dist/kiwi/fig/population/edits.d.ts.map +1 -0
- package/dist/kiwi/fig/population/edits.js +169 -0
- package/dist/kiwi/fig/population/edits.js.map +1 -0
- package/dist/kiwi/fig/session/archive/access.d.ts +3 -0
- package/dist/kiwi/fig/session/archive/access.d.ts.map +1 -1
- package/dist/kiwi/fig/session/archive/access.js +8 -1
- package/dist/kiwi/fig/session/archive/access.js.map +1 -1
- package/dist/kiwi/fig/session/archive/changes.d.ts +2 -1
- package/dist/kiwi/fig/session/archive/changes.d.ts.map +1 -1
- package/dist/kiwi/fig/session/archive/changes.js +12 -5
- package/dist/kiwi/fig/session/archive/changes.js.map +1 -1
- package/dist/kiwi/fig/session/document-state.d.ts +7 -1
- package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
- package/dist/kiwi/fig/session/document-state.js +16 -2
- package/dist/kiwi/fig/session/document-state.js.map +1 -1
- package/dist/kiwi/fig/session/protocol.d.ts +31 -3
- package/dist/kiwi/fig/session/protocol.d.ts.map +1 -1
- package/dist/kiwi/fig/session/worker.js +33 -8
- package/dist/kiwi/fig/session/worker.js.map +1 -1
- package/dist/layout/apply.d.ts +6 -1
- package/dist/layout/apply.d.ts.map +1 -1
- package/dist/layout/apply.js +39 -14
- package/dist/layout/apply.js.map +1 -1
- package/dist/layout/arrange/boxes.d.ts.map +1 -1
- package/dist/layout/arrange/boxes.js +31 -0
- package/dist/layout/arrange/boxes.js.map +1 -1
- package/dist/layout/flow-edges.d.ts +26 -0
- package/dist/layout/flow-edges.d.ts.map +1 -0
- package/dist/layout/flow-edges.js +105 -0
- package/dist/layout/flow-edges.js.map +1 -0
- package/dist/layout/grid.d.ts.map +1 -1
- package/dist/layout/grid.js +9 -5
- package/dist/layout/grid.js.map +1 -1
- package/dist/layout/text-auto-resize.d.ts.map +1 -1
- package/dist/layout/text-auto-resize.js +9 -4
- package/dist/layout/text-auto-resize.js.map +1 -1
- package/dist/layout/text-measurement.d.ts +15 -1
- package/dist/layout/text-measurement.d.ts.map +1 -1
- package/dist/layout/text-measurement.js +40 -4
- package/dist/layout/text-measurement.js.map +1 -1
- package/dist/layout/variables.d.ts +1 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +35 -35
- package/dist/layout.js.map +1 -1
- package/dist/library/asset-keys.d.ts +3 -2
- package/dist/library/asset-keys.d.ts.map +1 -1
- package/dist/library/asset-keys.js +4 -3
- package/dist/library/asset-keys.js.map +1 -1
- package/dist/library/copied-references.d.ts +8 -3
- package/dist/library/copied-references.d.ts.map +1 -1
- package/dist/library/copied-references.js +15 -5
- package/dist/library/copied-references.js.map +1 -1
- package/dist/library/materialize.js +1 -1
- package/dist/library/materialize.js.map +1 -1
- package/dist/library/schema.js.map +1 -1
- package/dist/library/snapshot.d.ts.map +1 -1
- package/dist/library/snapshot.js +10 -2
- package/dist/library/snapshot.js.map +1 -1
- package/dist/pairdraw-api/variables.d.ts.map +1 -1
- package/dist/pairdraw-api/variables.js +0 -2
- package/dist/pairdraw-api/variables.js.map +1 -1
- package/dist/profiler/hud-controller.d.ts +4 -3
- package/dist/profiler/hud-controller.d.ts.map +1 -1
- package/dist/profiler/hud-controller.js +7 -5
- package/dist/profiler/hud-controller.js.map +1 -1
- package/dist/profiler/hud-renderer.d.ts +5 -2
- package/dist/profiler/hud-renderer.d.ts.map +1 -1
- package/dist/profiler/hud-renderer.js +8 -5
- package/dist/profiler/hud-renderer.js.map +1 -1
- package/dist/profiler/render-profiler.d.ts +3 -2
- package/dist/profiler/render-profiler.d.ts.map +1 -1
- package/dist/profiler/render-profiler.js +3 -2
- package/dist/profiler/render-profiler.js.map +1 -1
- package/dist/text/character-style.d.ts +11 -1
- package/dist/text/character-style.d.ts.map +1 -1
- package/dist/text/character-style.js +27 -5
- package/dist/text/character-style.js.map +1 -1
- package/dist/text/coverage.d.ts.map +1 -1
- package/dist/text/coverage.js +15 -16
- package/dist/text/coverage.js.map +1 -1
- package/dist/text/editor.d.ts.map +1 -1
- package/dist/text/editor.js +3 -8
- package/dist/text/editor.js.map +1 -1
- package/dist/text/fallbacks.d.ts +19 -2
- package/dist/text/fallbacks.d.ts.map +1 -1
- package/dist/text/fallbacks.js +63 -12
- package/dist/text/fallbacks.js.map +1 -1
- package/dist/text/font/catalog.d.ts +4 -0
- package/dist/text/font/catalog.d.ts.map +1 -1
- package/dist/text/font/catalog.js +8 -0
- package/dist/text/font/catalog.js.map +1 -1
- package/dist/text/font/collection.d.ts +13 -0
- package/dist/text/font/collection.d.ts.map +1 -0
- package/dist/text/font/collection.js +51 -0
- package/dist/text/font/collection.js.map +1 -0
- package/dist/text/font/faces.d.ts +2 -1
- package/dist/text/font/faces.d.ts.map +1 -1
- package/dist/text/font/faces.js +9 -5
- package/dist/text/font/faces.js.map +1 -1
- package/dist/text/font/glyphs.d.ts +14 -3
- package/dist/text/font/glyphs.d.ts.map +1 -1
- package/dist/text/font/glyphs.js +22 -5
- package/dist/text/font/glyphs.js.map +1 -1
- package/dist/text/font/local.js +2 -2
- package/dist/text/font/local.js.map +1 -1
- package/dist/text/font/manager.d.ts +36 -0
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +139 -19
- package/dist/text/font/manager.js.map +1 -1
- package/dist/text/font/style.d.ts +7 -2
- package/dist/text/font/style.d.ts.map +1 -1
- package/dist/text/font/style.js +31 -3
- package/dist/text/font/style.js.map +1 -1
- package/dist/text/index.d.ts +5 -4
- package/dist/text/index.js +5 -4
- package/dist/text/outlines.d.ts.map +1 -1
- package/dist/text/outlines.js +70 -70
- package/dist/text/outlines.js.map +1 -1
- package/dist/text/prepare.d.ts.map +1 -1
- package/dist/text/prepare.js +7 -1
- package/dist/text/prepare.js.map +1 -1
- package/dist/text/style-runs.d.ts +14 -2
- package/dist/text/style-runs.d.ts.map +1 -1
- package/dist/text/style-runs.js +22 -14
- package/dist/text/style-runs.js.map +1 -1
- package/dist/tools/analyze/overlaps/helpers.d.ts.map +1 -1
- package/dist/tools/analyze/overlaps/helpers.js +9 -1
- package/dist/tools/analyze/overlaps/helpers.js.map +1 -1
- package/dist/tools/analyze/overlaps/index.d.ts.map +1 -1
- package/dist/tools/analyze/overlaps/index.js +27 -5
- package/dist/tools/analyze/overlaps/index.js.map +1 -1
- package/dist/tools/codegen/component-map.js +3 -3
- package/dist/tools/codegen/component-map.js.map +1 -1
- package/dist/tools/create/basic.d.ts.map +1 -1
- package/dist/tools/create/basic.js +5 -4
- package/dist/tools/create/basic.js.map +1 -1
- package/dist/tools/create/html.d.ts.map +1 -1
- package/dist/tools/create/html.js +4 -2
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.d.ts.map +1 -1
- package/dist/tools/create/icons.js +3 -1
- package/dist/tools/create/icons.js.map +1 -1
- package/dist/tools/create/mermaid.d.ts.map +1 -1
- package/dist/tools/create/mermaid.js +2 -0
- package/dist/tools/create/mermaid.js.map +1 -1
- package/dist/tools/create/render.d.ts.map +1 -1
- package/dist/tools/create/render.js +2 -0
- package/dist/tools/create/render.js.map +1 -1
- package/dist/tools/create/script.js +3 -1
- package/dist/tools/create/script.js.map +1 -1
- package/dist/tools/create/svg.d.ts.map +1 -1
- package/dist/tools/create/svg.js +4 -1
- package/dist/tools/create/svg.js.map +1 -1
- package/dist/tools/create/vector.d.ts.map +1 -1
- package/dist/tools/create/vector.js +4 -4
- package/dist/tools/create/vector.js.map +1 -1
- package/dist/tools/image-ai/apply.js +1 -1
- package/dist/tools/image-ai/generate.d.ts.map +1 -1
- package/dist/tools/image-ai/generate.js +3 -0
- package/dist/tools/image-ai/generate.js.map +1 -1
- package/dist/tools/modify/matching.js +1 -1
- package/dist/tools/modify/reactions.d.ts +6 -0
- package/dist/tools/modify/reactions.d.ts.map +1 -0
- package/dist/tools/modify/reactions.js +35 -0
- package/dist/tools/modify/reactions.js.map +1 -0
- package/dist/tools/modify.d.ts +2 -1
- package/dist/tools/modify.js +2 -1
- package/dist/tools/read/components.js +20 -22
- package/dist/tools/read/components.js.map +1 -1
- package/dist/tools/read/fonts.js +1 -1
- package/dist/tools/read/fonts.js.map +1 -1
- package/dist/tools/read/libraries.d.ts.map +1 -1
- package/dist/tools/read/libraries.js +2 -0
- package/dist/tools/read/libraries.js.map +1 -1
- package/dist/tools/read/nodes.d.ts.map +1 -1
- package/dist/tools/read/nodes.js +38 -16
- package/dist/tools/read/nodes.js.map +1 -1
- package/dist/tools/read/pages.d.ts.map +1 -1
- package/dist/tools/read/pages.js +4 -3
- package/dist/tools/read/pages.js.map +1 -1
- package/dist/tools/read/query.js +1 -0
- package/dist/tools/read/query.js.map +1 -1
- package/dist/tools/read/reactions.d.ts +6 -0
- package/dist/tools/read/reactions.d.ts.map +1 -0
- package/dist/tools/read/reactions.js +24 -0
- package/dist/tools/read/reactions.js.map +1 -0
- package/dist/tools/read/space.js +1 -1
- package/dist/tools/read.d.ts +2 -1
- package/dist/tools/read.js +2 -1
- package/dist/tools/registry/extended.d.ts.map +1 -1
- package/dist/tools/registry/extended.js +4 -0
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/schema.d.ts +6 -0
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +53 -9
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/stock-photo/apply.js +8 -9
- package/dist/tools/stock-photo/apply.js.map +1 -1
- package/dist/tools/structure/batch.d.ts.map +1 -1
- package/dist/tools/structure/batch.js +85 -90
- package/dist/tools/structure/batch.js.map +1 -1
- package/dist/vector/fill-geometry.d.ts +4 -1
- package/dist/vector/fill-geometry.d.ts.map +1 -1
- package/dist/vector/fill-geometry.js +8 -5
- package/dist/vector/fill-geometry.js.map +1 -1
- package/dist/vector/index.js +1 -1
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/path-helpers.d.ts +1 -1
- package/dist/vector/path-helpers.d.ts.map +1 -1
- package/dist/vector/path-helpers.js +24 -7
- package/dist/vector/path-helpers.js.map +1 -1
- package/dist/vector/placement.js +1 -1
- package/dist/vector/placement.js.map +1 -1
- package/dist/vector/vectorize/preprocess.js +1 -1
- package/dist/vector/vectorize/preprocess.js.map +1 -1
- package/package.json +10 -10
- package/src/canvas/effects.ts +29 -33
- package/src/canvas/labels/hit-test.ts +6 -2
- package/src/canvas/labels/paragraph-cache.ts +2 -1
- package/src/canvas/labels/selection.ts +3 -3
- package/src/canvas/node-edit-overlay.ts +3 -2
- package/src/canvas/overlays/index.ts +0 -1
- package/src/canvas/overlays/selection.ts +4 -52
- package/src/canvas/region-hatch.ts +7 -2
- package/src/canvas/renderer/colors.ts +41 -26
- package/src/canvas/renderer/font-waiters.ts +25 -0
- package/src/canvas/renderer/fonts.ts +40 -17
- package/src/canvas/renderer/lifecycle.ts +8 -10
- package/src/canvas/renderer/methods.ts +9 -13
- package/src/canvas/renderer/paints.ts +0 -10
- package/src/canvas/renderer/pipeline.ts +29 -3
- package/src/canvas/renderer/retained-backing.ts +4 -4
- package/src/canvas/renderer/state.ts +1 -1
- package/src/canvas/renderer/tiles/controller.ts +8 -0
- package/src/canvas/renderer/tiles/surface-pool.ts +1 -1
- package/src/canvas/renderer/visual-bounds.ts +7 -6
- package/src/canvas/renderer.ts +39 -11
- package/src/canvas/rulers.ts +55 -26
- package/src/canvas/scene.ts +37 -16
- package/src/canvas/shadows/shape.ts +1 -1
- package/src/canvas/shadows/silhouette.ts +4 -2
- package/src/canvas/shadows.ts +4 -2
- package/src/canvas/text/derived.ts +0 -9
- package/src/canvas/text/emoji/raster.ts +14 -10
- package/src/canvas/text/font-families.ts +6 -0
- package/src/canvas/text/index.ts +0 -8
- package/src/canvas/text/layout/build.ts +35 -18
- package/src/canvas/text/layout/index.ts +15 -6
- package/src/canvas/text/layout/lines.ts +10 -4
- package/src/canvas/text/paragraph/index.ts +17 -8
- package/src/canvas/text/paragraph/inputs.ts +4 -2
- package/src/canvas/text/shape.ts +20 -31
- package/src/constants.ts +6 -1
- package/src/editor/bridges/clipboard.ts +1 -0
- package/src/editor/bridges/components.ts +2 -0
- package/src/editor/bridges/frames.ts +6 -4
- package/src/editor/bridges/structure.ts +1 -0
- package/src/editor/clipboard/detach.ts +3 -3
- package/src/editor/clipboard/paste/target.ts +2 -2
- package/src/editor/clipboard/snapshot.ts +7 -0
- package/src/editor/clipboard/variables.ts +20 -0
- package/src/editor/clipboard.ts +133 -14
- package/src/editor/component-sync.ts +28 -7
- package/src/editor/components/authoring/text-edit.ts +15 -2
- package/src/editor/components/authoring/visibility-edit.ts +11 -3
- package/src/editor/components/instances.ts +61 -11
- package/src/editor/components/properties.ts +10 -0
- package/src/editor/components/slots/authoring.ts +4 -1
- package/src/editor/create.ts +58 -8
- package/src/editor/guides.ts +27 -12
- package/src/editor/history/document-change.ts +115 -7
- package/src/editor/history/edit.ts +62 -14
- package/src/editor/history/position.ts +1 -4
- package/src/editor/history/sources.ts +25 -0
- package/src/editor/index.ts +3 -1
- package/src/editor/layout-mode.ts +20 -1
- package/src/editor/node-preview.ts +44 -8
- package/src/editor/nodes.ts +52 -12
- package/src/editor/nudge.ts +16 -2
- package/src/editor/pages.ts +100 -17
- package/src/editor/play/states.ts +0 -7
- package/src/editor/read-only/actions.ts +4 -0
- package/src/editor/selection/hit-test.ts +37 -4
- package/src/editor/shapes/pen.ts +6 -3
- package/src/editor/shapes.ts +2 -1
- package/src/editor/structure/auto-layout-wrap.ts +26 -0
- package/src/editor/structure/group/bounds.ts +22 -4
- package/src/editor/structure/rename.ts +2 -6
- package/src/editor/structure/reorder.ts +26 -8
- package/src/editor/structure.ts +88 -24
- package/src/editor/text/hyperlink.ts +2 -1
- package/src/editor/text/name.ts +51 -15
- package/src/editor/text/pending-layout.ts +42 -4
- package/src/editor/text/selection-style.ts +17 -3
- package/src/editor/text.ts +86 -4
- package/src/editor/types.ts +19 -0
- package/src/editor/undo.ts +21 -2
- package/src/editor/variable-bindings.ts +22 -2
- package/src/editor/variables.ts +10 -6
- package/src/editor/viewport.ts +55 -21
- package/src/editor/views/actions.ts +17 -7
- package/src/editor/views/present.ts +20 -11
- package/src/editor/views/types.ts +11 -5
- package/src/figma-api/accessor-utils.ts +4 -1
- package/src/figma-api/accessors/basic.ts +54 -18
- package/src/figma-api/accessors/layout.ts +46 -7
- package/src/figma-api/accessors/reactions.ts +29 -0
- package/src/figma-api/accessors/strokes.ts +28 -8
- package/src/figma-api/accessors/text/index.ts +4 -0
- package/src/figma-api/accessors/vector.ts +3 -1
- package/src/figma-api/accessors/visual.ts +25 -28
- package/src/figma-api/components.ts +9 -7
- package/src/figma-api/finite.ts +102 -0
- package/src/figma-api/fonts/list.ts +24 -0
- package/src/figma-api/index.ts +82 -12
- package/src/figma-api/overrides.ts +1 -1
- package/src/figma-api/pending-layout.ts +50 -1
- package/src/figma-api/pending-sync.ts +61 -0
- package/src/figma-api/proxy.ts +35 -2
- package/src/figma-api/reactions.ts +212 -0
- package/src/figma-api/render-bounds.ts +13 -4
- package/src/figma-api/serialization.ts +2 -2
- package/src/figma-api/slots.ts +12 -3
- package/src/figma-api/strokes.ts +16 -12
- package/src/figma-api/text/index.ts +9 -15
- package/src/figma-api/variables/variable.ts +3 -2
- package/src/geometry/figma.ts +9 -0
- package/src/geometry/index.ts +1 -0
- package/src/global.d.ts +6 -0
- package/src/icons/api.ts +27 -16
- package/src/icons/provider.ts +9 -20
- package/src/icons/schema.ts +31 -0
- package/src/icons/svg/presentation.ts +27 -3
- package/src/icons/svg/text.ts +1 -1
- package/src/icons/svg.ts +21 -19
- package/src/icons/types.ts +0 -14
- package/src/io/formats/design-tokens/plan/index.ts +7 -1
- package/src/io/formats/design-tokens/plan/styles.ts +40 -4
- package/src/io/formats/design-tokens/styles.ts +60 -3
- package/src/io/formats/design-tokens/types.ts +3 -0
- package/src/io/formats/fig/export/setup.ts +16 -14
- package/src/io/formats/fig/export/variables.ts +7 -8
- package/src/io/formats/fig/index.ts +1 -0
- package/src/io/formats/fig/read.ts +66 -23
- package/src/io/formats/html/index.ts +2 -6
- package/src/io/formats/pdf/dom.ts +96 -3
- package/src/io/formats/pen/fonts.ts +45 -0
- package/src/io/formats/pen/index.ts +30 -6
- package/src/io/formats/raster/headless.ts +31 -12
- package/src/io/formats/raster/index.ts +3 -0
- package/src/io/formats/raster/render.ts +62 -6
- package/src/io/formats/svg/export.ts +24 -25
- package/src/io/formats/svg/paths.ts +11 -2
- package/src/io/formats/svg/strokes.ts +8 -2
- package/src/io/formats/svg/text/export.ts +23 -0
- package/src/io/formats/svg/text/import.ts +2 -1
- package/src/io/subgraph.ts +3 -1
- package/src/kiwi/fig/population/client.ts +77 -43
- package/src/kiwi/fig/population/delta.ts +141 -18
- package/src/kiwi/fig/population/edits.ts +235 -0
- package/src/kiwi/fig/session/archive/access.ts +15 -0
- package/src/kiwi/fig/session/archive/changes.ts +27 -6
- package/src/kiwi/fig/session/document-state.ts +23 -1
- package/src/kiwi/fig/session/protocol.ts +26 -1
- package/src/kiwi/fig/session/worker.ts +38 -11
- package/src/layout/apply.ts +52 -10
- package/src/layout/arrange/boxes.ts +36 -0
- package/src/layout/flow-edges.ts +139 -0
- package/src/layout/grid.ts +14 -4
- package/src/layout/text-auto-resize.ts +13 -4
- package/src/layout/text-measurement.ts +46 -3
- package/src/layout.ts +60 -66
- package/src/library/asset-keys.ts +4 -3
- package/src/library/copied-references.ts +29 -5
- package/src/library/materialize.ts +1 -1
- package/src/library/schema.ts +1 -1
- package/src/library/snapshot.ts +11 -2
- package/src/pairdraw-api/variables.ts +1 -3
- package/src/profiler/hud-controller.ts +8 -6
- package/src/profiler/hud-renderer.ts +9 -6
- package/src/profiler/render-profiler.ts +4 -3
- package/src/text/character-style.ts +29 -9
- package/src/text/coverage.ts +17 -18
- package/src/text/editor.ts +3 -8
- package/src/text/fallbacks.ts +82 -15
- package/src/text/font/catalog.ts +10 -0
- package/src/text/font/collection.ts +60 -0
- package/src/text/font/faces.ts +9 -5
- package/src/text/font/glyphs.ts +29 -4
- package/src/text/font/local.ts +2 -2
- package/src/text/font/manager.ts +170 -32
- package/src/text/font/style.ts +52 -3
- package/src/text/index.ts +1 -0
- package/src/text/outlines.ts +105 -89
- package/src/text/prepare.ts +17 -0
- package/src/text/style-runs.ts +43 -16
- package/src/tools/analyze/overlaps/helpers.ts +18 -1
- package/src/tools/analyze/overlaps/index.ts +37 -6
- package/src/tools/codegen/component-map.ts +3 -3
- package/src/tools/create/basic.ts +6 -4
- package/src/tools/create/html.ts +3 -1
- package/src/tools/create/icons.ts +3 -1
- package/src/tools/create/mermaid.ts +2 -0
- package/src/tools/create/render.ts +2 -0
- package/src/tools/create/script.ts +5 -1
- package/src/tools/create/svg.ts +4 -1
- package/src/tools/create/vector.ts +4 -4
- package/src/tools/image-ai/generate.ts +3 -0
- package/src/tools/modify/reactions.ts +40 -0
- package/src/tools/modify.ts +1 -0
- package/src/tools/read/components.ts +28 -25
- package/src/tools/read/fonts.ts +1 -1
- package/src/tools/read/libraries.ts +3 -0
- package/src/tools/read/nodes.ts +47 -17
- package/src/tools/read/pages.ts +7 -4
- package/src/tools/read/query.ts +2 -0
- package/src/tools/read/reactions.ts +21 -0
- package/src/tools/read.ts +1 -0
- package/src/tools/registry/extended.ts +4 -0
- package/src/tools/schema.ts +68 -12
- package/src/tools/stock-photo/apply.ts +17 -5
- package/src/tools/structure/batch.ts +82 -101
- package/src/vector/fill-geometry.ts +11 -5
- package/src/vector/index.ts +1 -1
- package/src/vector/path-helpers.ts +34 -8
- package/src/vector/placement.ts +1 -1
- package/src/vector/vectorize/preprocess.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variables.js","names":[],"sources":["../../src/editor/variables.ts"],"sourcesContent":["import { omit, omitBy } from 'es-toolkit/object'\nimport { isEmptyObject } from 'es-toolkit/predicate'\n\nimport {\n isModeAttributeName,\n type TokenExpression,\n type Variable,\n type VariableCollection,\n type VariableType,\n type VariableValue\n} from '@pairdraw/scene-graph'\nimport { tokenExpressionForValue, type BindingScope } from '@pairdraw/scene-graph/variables'\n\nimport { reconcileVariableLayouts } from '#core/layout/variables'\n\nimport { loadBoundIcons } from './icons'\nimport { loadBoundFonts } from './text/bound-fonts'\nimport type { EditorContext } from './types'\n\n/** What a variable means as a design token beyond its values: how CSS and code read it. */\nexport type VariableTokenFields = Pick<\n Variable,\n 'unit' | 'expressions' | 'scopes' | 'codeSyntax' | 'description' | 'hiddenFromPublishing'\n>\n\n/** Every token field, unset ones included, so restoring it also clears what was added. */\nfunction tokenFields(variable: Variable): VariableTokenFields {\n const { unit, expressions, scopes, codeSyntax, description, hiddenFromPublishing } = variable\n return structuredClone({\n unit,\n expressions,\n scopes,\n codeSyntax,\n description,\n hiddenFromPublishing\n })\n}\n\n/** A mode's value with the CSS expression written for it, which the value must keep matching. */\ninterface ModeEntry {\n value: VariableValue | undefined\n expression: TokenExpression | undefined\n}\n\nfunction modeEntry(variable: Variable, modeId: string): ModeEntry {\n return structuredClone({\n value: variable.valuesByMode[modeId],\n expression: variable.expressions?.[modeId]\n })\n}\n\nfunction setModeEntry(variable: Variable, modeId: string, entry: ModeEntry) {\n const { value, expression } = structuredClone(entry)\n const values = omit(variable.valuesByMode, [modeId])\n variable.valuesByMode = value === undefined ? values : { ...values, [modeId]: value }\n const others = omit(variable.expressions ?? {}, [modeId])\n const expressions: Record<string, TokenExpression> = expression\n ? { ...others, [modeId]: expression }\n : others\n if (isEmptyObject(expressions)) delete variable.expressions\n else variable.expressions = expressions\n}\n\nexport function createVariableActions(ctx: EditorContext) {\n /**\n * Re-resolves the layers a change to what variables resolve to can reach: those bound to the\n * changed variables or to variables aliasing them. Every other variable change, such as adding,\n * renaming, reordering, or a token field, changes nothing the canvas draws, so it only refreshes\n * the views and leaves the canvas's recorded pictures in place. Records written into the graph\n * without an editor action, such as a collaborator's, take effect through it.\n */\n function refreshVariables(scope: BindingScope) {\n const changed = reconcileVariableLayouts(ctx.graph, scope)\n loadBoundFonts(ctx, changed)\n void loadBoundIcons(ctx, scope).catch((error: unknown) => {\n console.warn(\n 'Loading a bound icon failed:',\n error instanceof Error ? error.message : String(error)\n )\n })\n ctx.requestRender()\n }\n\n /** Every variable in a collection, the ones a change to its modes can reach. */\n function collectionScope(collectionId: string): BindingScope {\n return { variables: [...(ctx.graph.variableCollections.get(collectionId)?.variableIds ?? [])] }\n }\n\n function getVariablesByType(type: VariableType) {\n return ctx.graph.getVariablesByType(type)\n }\n\n function getVariable(id: string) {\n return ctx.graph.variables.get(id)\n }\n\n function resolveColorVariable(id: string) {\n return ctx.graph.resolveColorVariable(id)\n }\n\n function resolveNumberVariable(id: string) {\n return ctx.graph.resolveNumberVariable(id)\n }\n\n function getVariablesForCollection(collectionId: string) {\n return ctx.graph.getVariablesForCollection(collectionId)\n }\n\n function getCollection(id: string) {\n return ctx.graph.variableCollections.get(id)\n }\n\n function getCollections() {\n return [...ctx.graph.variableCollections.values()]\n }\n\n function getCollectionCount() {\n return ctx.graph.variableCollections.size\n }\n\n function getVariableCount() {\n return ctx.graph.variables.size\n }\n\n function renameCollection(id: string, newName: string) {\n const collection = ctx.graph.variableCollections.get(id)\n if (!collection) return\n const prevName = collection.name\n collection.name = newName\n ctx.undo.push({\n label: 'Rename collection',\n forward: () => {\n const c = ctx.graph.variableCollections.get(id)\n if (c) c.name = newName\n ctx.requestRefresh()\n },\n inverse: () => {\n const c = ctx.graph.variableCollections.get(id)\n if (c) c.name = prevName\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n }\n\n function addCollection(collection: VariableCollection) {\n ctx.graph.addCollection(collection)\n ctx.undo.push({\n label: 'Add collection',\n forward: () => {\n ctx.graph.addCollection(collection)\n ctx.requestRefresh()\n },\n inverse: () => {\n ctx.graph.removeCollection(collection.id)\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n }\n\n function removeCollection(id: string) {\n const collection = ctx.graph.variableCollections.get(id)\n if (!collection) return\n const snapshot = structuredClone(collection)\n const scope: BindingScope = { variables: snapshot.variableIds }\n const variables = snapshot.variableIds\n .map((vid) => ctx.graph.variables.get(vid))\n .filter((v): v is Variable => v != null)\n .map((v) => structuredClone(v))\n ctx.graph.removeCollection(id)\n ctx.undo.push({\n label: 'Remove collection',\n forward: () => {\n ctx.graph.removeCollection(id)\n refreshVariables(scope)\n },\n inverse: () => {\n ctx.graph.addCollection(snapshot)\n for (const v of variables) ctx.graph.addVariable(v)\n refreshVariables(scope)\n }\n })\n refreshVariables(scope)\n }\n\n function addVariable(variable: Variable) {\n ctx.graph.addVariable(variable)\n ctx.undo.push({\n label: 'Add variable',\n forward: () => {\n ctx.graph.addVariable(variable)\n ctx.requestRefresh()\n },\n inverse: () => {\n ctx.graph.removeVariable(variable.id)\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n }\n\n function removeVariable(id: string) {\n const variable = ctx.graph.variables.get(id)\n if (!variable) return\n const snapshot = structuredClone(variable)\n const order = [...(ctx.graph.variableCollections.get(variable.collectionId)?.variableIds ?? [])]\n ctx.graph.removeVariable(id)\n ctx.undo.push({\n label: 'Remove variable',\n forward: () => {\n ctx.graph.removeVariable(id)\n refreshVariables({ variables: [id] })\n },\n // Undo puts the variable back where it was, not at the end of its collection.\n inverse: () => {\n ctx.graph.addVariable(structuredClone(snapshot))\n placeVariables(snapshot.collectionId, order)\n refreshVariables({ variables: [id] })\n }\n })\n refreshVariables({ variables: [id] })\n }\n\n /** Puts a collection's variables in `order`; ids it does not hold are ignored. */\n function placeVariables(collectionId: string, order: readonly string[]) {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return\n const held = new Set(collection.variableIds)\n const placed = order.filter((id) => held.has(id))\n const rest = collection.variableIds.filter((id) => !placed.includes(id))\n collection.variableIds = [...placed, ...rest]\n }\n\n /** Reorders a collection's variables in one undo step; the order is what files and lists show. */\n function setVariableOrder(collectionId: string, order: readonly string[]) {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return\n const previous = [...collection.variableIds]\n const next = [...order]\n placeVariables(collectionId, next)\n if (previous.join('\\n') === collection.variableIds.join('\\n')) return\n ctx.undo.push({\n label: 'Reorder variables',\n forward: () => {\n placeVariables(collectionId, next)\n ctx.requestRefresh()\n },\n inverse: () => {\n placeVariables(collectionId, previous)\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n }\n\n /** Copies a variable, values and token fields included, right after the original. */\n function duplicateVariable(id: string, name: string): string | undefined {\n const source = ctx.graph.variables.get(id)\n const collection = source && ctx.graph.variableCollections.get(source.collectionId)\n if (!source || !collection) return undefined\n const created = ctx.graph.createVariable(name, source.type, source.collectionId)\n const copy: Variable = { ...structuredClone(source), id: created.id, name }\n ctx.graph.addVariable(copy)\n const before = [...collection.variableIds]\n const order = before.filter((candidate) => candidate !== copy.id)\n order.splice(order.indexOf(id) + 1, 0, copy.id)\n placeVariables(collection.id, order)\n ctx.undo.push({\n label: 'Duplicate variable',\n forward: () => {\n ctx.graph.addVariable(structuredClone(copy))\n placeVariables(collection.id, order)\n ctx.requestRefresh()\n },\n inverse: () => {\n ctx.graph.removeVariable(copy.id)\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n return copy.id\n }\n\n function renameVariable(id: string, newName: string) {\n const variable = ctx.graph.variables.get(id)\n if (!variable) return\n const prevName = variable.name\n variable.name = newName\n ctx.undo.push({\n label: 'Rename variable',\n forward: () => {\n const v = ctx.graph.variables.get(id)\n if (v) v.name = newName\n ctx.requestRefresh()\n },\n inverse: () => {\n const v = ctx.graph.variables.get(id)\n if (v) v.name = prevName\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n }\n\n function addMode(collectionId: string, name?: string): string | undefined {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return undefined\n const modeName = name ?? `Mode ${collection.modes.length + 1}`\n const modeId = ctx.graph.createMode(collectionId, modeName)\n if (!modeId) return undefined\n ctx.undo.push({\n label: 'Add mode',\n forward: () => {\n ctx.graph.addMode(collectionId, modeId, modeName)\n refreshVariables(collectionScope(collectionId))\n },\n inverse: () => {\n ctx.graph.removeMode(collectionId, modeId)\n refreshVariables(collectionScope(collectionId))\n }\n })\n refreshVariables(collectionScope(collectionId))\n return modeId\n }\n\n function removeMode(collectionId: string, modeId: string) {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection || collection.modes.length <= 1) return\n const modeIndex = collection.modes.findIndex((m) => m.modeId === modeId)\n const modeName = collection.modes[modeIndex]?.name ?? ''\n const wasDefault = collection.defaultModeId === modeId\n const valueSnapshots = new Map<string, VariableValue>()\n for (const varId of collection.variableIds) {\n const v = ctx.graph.variables.get(varId)\n if (v?.valuesByMode[modeId] !== undefined) {\n valueSnapshots.set(varId, structuredClone(v.valuesByMode[modeId]))\n }\n }\n ctx.graph.removeMode(collectionId, modeId)\n ctx.undo.push({\n label: 'Remove mode',\n forward: () => {\n ctx.graph.removeMode(collectionId, modeId)\n refreshVariables(collectionScope(collectionId))\n },\n inverse: () => {\n ctx.graph.addMode(collectionId, modeId, modeName)\n const col = ctx.graph.variableCollections.get(collectionId)\n if (col && modeIndex !== -1) {\n const mode = col.modes.pop()\n if (mode) col.modes.splice(modeIndex, 0, mode)\n }\n for (const [varId, value] of valueSnapshots) {\n const v = ctx.graph.variables.get(varId)\n if (v) v.valuesByMode[modeId] = structuredClone(value)\n }\n if (wasDefault) ctx.graph.setDefaultMode(collectionId, modeId)\n refreshVariables(collectionScope(collectionId))\n }\n })\n refreshVariables(collectionScope(collectionId))\n }\n\n function renameMode(collectionId: string, modeId: string, newName: string) {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return\n const mode = collection.modes.find((m) => m.modeId === modeId)\n if (!mode) return\n const prevName = mode.name\n ctx.graph.renameMode(collectionId, modeId, newName)\n ctx.undo.push({\n label: 'Rename mode',\n forward: () => {\n ctx.graph.renameMode(collectionId, modeId, newName)\n ctx.requestRefresh()\n },\n inverse: () => {\n ctx.graph.renameMode(collectionId, modeId, prevName)\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n }\n\n function setDefaultMode(collectionId: string, modeId: string) {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return\n const prevDefault = collection.defaultModeId\n const prevModes = structuredClone(collection.modes)\n ctx.graph.setDefaultMode(collectionId, modeId)\n ctx.undo.push({\n label: 'Set default mode',\n forward: () => {\n ctx.graph.setDefaultMode(collectionId, modeId)\n refreshVariables(collectionScope(collectionId))\n },\n inverse: () => {\n // Setting a default moves it first; undo restores the column order too. Look the\n // collection up again: undoing its removal in between restores a copy.\n const current = ctx.graph.variableCollections.get(collectionId)\n if (current) {\n current.modes = structuredClone(prevModes)\n current.defaultModeId = prevDefault\n }\n refreshVariables(collectionScope(collectionId))\n }\n })\n refreshVariables(collectionScope(collectionId))\n }\n\n function duplicateMode(collectionId: string, sourceModeId: string): string | undefined {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return undefined\n const sourceMode = collection.modes.find((m) => m.modeId === sourceModeId)\n if (!sourceMode) return undefined\n const modeName = `${sourceMode.name} copy`\n const modeId = ctx.graph.createMode(collectionId, modeName, sourceModeId)\n if (!modeId) return undefined\n ctx.undo.push({\n label: 'Duplicate mode',\n forward: () => {\n ctx.graph.addMode(collectionId, modeId, modeName, sourceModeId)\n refreshVariables(collectionScope(collectionId))\n },\n inverse: () => {\n ctx.graph.removeMode(collectionId, modeId)\n refreshVariables(collectionScope(collectionId))\n }\n })\n refreshVariables(collectionScope(collectionId))\n return modeId\n }\n\n function setActiveMode(collectionId: string, modeId: string) {\n ctx.graph.setActiveMode(collectionId, modeId)\n refreshVariables(collectionScope(collectionId))\n }\n\n /**\n * Sets one mode's value. Calls that share a `coalesceKey`, such as the steps of one color picker\n * drag, undo together.\n */\n function updateVariableValue(\n id: string,\n modeId: string,\n value: VariableValue,\n coalesceKey?: string\n ) {\n const variable = ctx.graph.variables.get(id)\n if (!variable) return\n const previous = modeEntry(variable, modeId)\n const next: ModeEntry = {\n value: structuredClone(value),\n expression: tokenExpressionForValue(previous.expression, value)\n }\n const apply = (entry: ModeEntry) => {\n const target = ctx.graph.variables.get(id)\n if (target) setModeEntry(target, modeId, entry)\n refreshVariables({ variables: [id] })\n }\n apply(next)\n ctx.undo.push({\n label: 'Update variable value',\n forward: () => apply(next),\n inverse: () => apply(previous),\n coalesceKey\n })\n }\n\n /** Change token fields in one undo step; a field set to `undefined` is cleared. */\n function updateVariableToken(id: string, patch: Partial<VariableTokenFields>) {\n const variable = ctx.graph.variables.get(id)\n if (!variable) return\n const previous = tokenFields(variable)\n const next = structuredClone(patch)\n const apply = (values: Partial<VariableTokenFields>) => {\n const target = ctx.graph.variables.get(id)\n if (!target) return\n const { description, ...fields } = structuredClone(values)\n // A cleared field is removed, not kept as a key set to `undefined`.\n for (const key of Object.keys(fields) as Array<keyof typeof fields>) {\n if (fields[key] === undefined) Reflect.deleteProperty(target, key)\n }\n Object.assign(\n target,\n omitBy(fields, (value) => value === undefined)\n )\n // Every variable has a description; clearing it leaves an empty one.\n if ('description' in values) target.description = description ?? ''\n ctx.requestRefresh()\n }\n apply(next)\n ctx.undo.push({\n label: 'Update variable token',\n forward: () => apply(next),\n inverse: () => apply(previous)\n })\n }\n\n /** The selector or query a mode applies under; an empty condition restores the default. */\n function setModeCondition(collectionId: string, modeId: string, condition: string | undefined) {\n const mode = ctx.graph.variableCollections\n .get(collectionId)\n ?.modes.find((candidate) => candidate.modeId === modeId)\n if (!mode) return\n const previous = mode.condition\n const next = condition?.trim() || undefined\n if (next === previous) return\n const apply = (value: string | undefined) => {\n const target = ctx.graph.variableCollections\n .get(collectionId)\n ?.modes.find((candidate) => candidate.modeId === modeId)\n if (target) target.condition = value\n ctx.requestRefresh()\n }\n apply(next)\n ctx.undo.push({\n label: 'Set mode condition',\n forward: () => apply(next),\n inverse: () => apply(previous)\n })\n }\n\n /**\n * Name the attribute manual modes are switched by; an empty name restores the default, and a\n * name no stylesheet can select on leaves the current one.\n */\n function setModeAttribute(collectionId: string, name: string | undefined) {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return\n const previous = collection.modeAttribute\n const next = name?.trim() || undefined\n if (next === previous || (next !== undefined && !isModeAttributeName(next))) return\n const apply = (value: string | undefined) => {\n const target = ctx.graph.variableCollections.get(collectionId)\n if (target) target.modeAttribute = value\n ctx.requestRefresh()\n }\n apply(next)\n ctx.undo.push({\n label: 'Set mode attribute',\n forward: () => apply(next),\n inverse: () => apply(previous)\n })\n }\n\n return {\n refreshVariables,\n updateVariableToken,\n setModeCondition,\n duplicateVariable,\n setVariableOrder,\n setModeAttribute,\n getVariablesByType,\n getVariable,\n resolveColorVariable,\n resolveNumberVariable,\n getVariablesForCollection,\n getCollection,\n getCollections,\n getCollectionCount,\n getVariableCount,\n renameCollection,\n addCollection,\n removeCollection,\n addVariable,\n removeVariable,\n renameVariable,\n updateVariableValue,\n addMode,\n removeMode,\n renameMode,\n setDefaultMode,\n duplicateMode,\n setActiveMode\n }\n}\n"],"mappings":";;;;;;;;;AA0BA,SAAS,YAAY,UAAyC;CAC5D,MAAM,EAAE,MAAM,aAAa,QAAQ,YAAY,aAAa,yBAAyB;CACrF,OAAO,gBAAgB;EACrB;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;AACH;AAQA,SAAS,UAAU,UAAoB,QAA2B;CAChE,OAAO,gBAAgB;EACrB,OAAO,SAAS,aAAa;EAC7B,YAAY,SAAS,cAAc;CACrC,CAAC;AACH;AAEA,SAAS,aAAa,UAAoB,QAAgB,OAAkB;CAC1E,MAAM,EAAE,OAAO,eAAe,gBAAgB,KAAK;CACnD,MAAM,SAAS,KAAK,SAAS,cAAc,CAAC,MAAM,CAAC;CACnD,SAAS,eAAe,UAAU,KAAA,IAAY,SAAS;EAAE,GAAG;GAAS,SAAS;CAAM;CACpF,MAAM,SAAS,KAAK,SAAS,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC;CACxD,MAAM,cAA+C,aACjD;EAAE,GAAG;GAAS,SAAS;CAAW,IAClC;CACJ,IAAI,cAAc,WAAW,GAAG,OAAO,SAAS;MAC3C,SAAS,cAAc;AAC9B;AAEA,SAAgB,sBAAsB,KAAoB;;;;;;;;CAQ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eAAe,MAAM,QAAQ;EAC/B,CAAC;CACH;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"variables.js","names":[],"sources":["../../src/editor/variables.ts"],"sourcesContent":["import { omit, omitBy } from 'es-toolkit/object'\nimport { isEmptyObject } from 'es-toolkit/predicate'\n\nimport {\n isModeAttributeName,\n type TokenExpression,\n type Variable,\n type VariableCollection,\n type VariableType,\n type VariableValue\n} from '@pairdraw/scene-graph'\nimport { tokenExpressionForValue, type BindingScope } from '@pairdraw/scene-graph/variables'\n\nimport { reconcileVariableLayouts } from '#core/layout/variables'\n\nimport { loadBoundIcons } from './icons'\nimport { loadBoundFonts } from './text/bound-fonts'\nimport type { EditorContext } from './types'\n\n/** What a variable means as a design token beyond its values: how CSS and code read it. */\nexport type VariableTokenFields = Pick<\n Variable,\n 'unit' | 'expressions' | 'scopes' | 'codeSyntax' | 'description' | 'hiddenFromPublishing'\n>\n\n/** Every token field, unset ones included, so restoring it also clears what was added. */\nfunction tokenFields(variable: Variable): VariableTokenFields {\n const { unit, expressions, scopes, codeSyntax, description, hiddenFromPublishing } = variable\n return structuredClone({\n unit,\n expressions,\n scopes,\n codeSyntax,\n description,\n hiddenFromPublishing\n })\n}\n\n/** A mode's value with the CSS expression written for it, which the value must keep matching. */\ninterface ModeEntry {\n value: VariableValue | undefined\n expression: TokenExpression | undefined\n}\n\nfunction modeEntry(variable: Variable, modeId: string): ModeEntry {\n return structuredClone({\n value: variable.valuesByMode[modeId],\n expression: variable.expressions?.[modeId]\n })\n}\n\nfunction setModeEntry(variable: Variable, modeId: string, entry: ModeEntry) {\n const { value, expression } = structuredClone(entry)\n const values = omit(variable.valuesByMode, [modeId])\n variable.valuesByMode = value === undefined ? values : { ...values, [modeId]: value }\n const others = omit(variable.expressions ?? {}, [modeId])\n const expressions: Record<string, TokenExpression> = expression\n ? { ...others, [modeId]: expression }\n : others\n if (isEmptyObject(expressions)) delete variable.expressions\n else variable.expressions = expressions\n}\n\nexport function createVariableActions(ctx: EditorContext) {\n /**\n * Re-resolves the layers a change to what variables resolve to can reach: those bound to the\n * changed variables or to variables aliasing them. Every other variable change, such as adding,\n * renaming, reordering, or a token field, changes nothing the canvas draws, so it only refreshes\n * the views and leaves the canvas's recorded pictures in place. Records written into the graph\n * without an editor action, such as a collaborator's, take effect through it.\n */\n function refreshVariables(scope: BindingScope) {\n const changed = reconcileVariableLayouts(ctx.graph, scope)\n loadBoundFonts(ctx, changed)\n void loadBoundIcons(ctx, scope).catch((error: unknown) => {\n console.warn(\n 'Loading a bound icon failed:',\n error instanceof Error ? error.message : String(error)\n )\n })\n ctx.requestRender()\n }\n\n /** Every variable in a collection, the ones a change to its modes can reach. */\n function collectionScope(collectionId: string): BindingScope {\n return { variables: [...(ctx.graph.variableCollections.get(collectionId)?.variableIds ?? [])] }\n }\n\n function getVariablesByType(type: VariableType) {\n return ctx.graph.getVariablesByType(type)\n }\n\n function getVariable(id: string) {\n return ctx.graph.variables.get(id)\n }\n\n function resolveColorVariable(id: string) {\n return ctx.graph.resolveColorVariable(id)\n }\n\n function resolveNumberVariable(id: string) {\n return ctx.graph.resolveNumberVariable(id)\n }\n\n function getVariablesForCollection(collectionId: string) {\n return ctx.graph.getVariablesForCollection(collectionId)\n }\n\n function getCollection(id: string) {\n return ctx.graph.variableCollections.get(id)\n }\n\n function getCollections() {\n return [...ctx.graph.variableCollections.values()]\n }\n\n function getCollectionCount() {\n return ctx.graph.variableCollections.size\n }\n\n function getVariableCount() {\n return ctx.graph.variables.size\n }\n\n function renameCollection(id: string, newName: string) {\n const collection = ctx.graph.variableCollections.get(id)\n if (!collection) return\n const prevName = collection.name\n collection.name = newName\n ctx.undo.push({\n label: 'Rename collection',\n forward: () => {\n const c = ctx.graph.variableCollections.get(id)\n if (c) c.name = newName\n ctx.requestRefresh()\n },\n inverse: () => {\n const c = ctx.graph.variableCollections.get(id)\n if (c) c.name = prevName\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n }\n\n function addCollection(collection: VariableCollection) {\n ctx.graph.addCollection(collection)\n ctx.undo.push({\n label: 'Add collection',\n forward: () => {\n ctx.graph.addCollection(collection)\n ctx.requestRefresh()\n },\n inverse: () => {\n ctx.graph.removeCollection(collection.id)\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n }\n\n function removeCollection(id: string) {\n const collection = ctx.graph.variableCollections.get(id)\n if (!collection) return\n const snapshot = structuredClone(collection)\n const scope: BindingScope = { variables: snapshot.variableIds }\n const variables = snapshot.variableIds\n .map((vid) => ctx.graph.variables.get(vid))\n .filter((v): v is Variable => v != null)\n .map((v) => structuredClone(v))\n ctx.graph.removeCollection(id)\n ctx.undo.push({\n label: 'Remove collection',\n forward: () => {\n ctx.graph.removeCollection(id)\n refreshVariables(scope)\n },\n inverse: () => {\n ctx.graph.addCollection(snapshot)\n for (const v of variables) ctx.graph.addVariable(v)\n refreshVariables(scope)\n }\n })\n refreshVariables(scope)\n }\n\n function addVariable(variable: Variable) {\n ctx.graph.addVariable(variable)\n ctx.undo.push({\n label: 'Add variable',\n forward: () => {\n ctx.graph.addVariable(variable)\n ctx.requestRefresh()\n },\n inverse: () => {\n ctx.graph.removeVariable(variable.id)\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n }\n\n function removeVariable(id: string) {\n const variable = ctx.graph.variables.get(id)\n if (!variable) return\n const snapshot = structuredClone(variable)\n const order = [...(ctx.graph.variableCollections.get(variable.collectionId)?.variableIds ?? [])]\n ctx.graph.removeVariable(id)\n ctx.undo.push({\n label: 'Remove variable',\n forward: () => {\n ctx.graph.removeVariable(id)\n refreshVariables({ variables: [id] })\n },\n // Undo puts the variable back where it was, not at the end of its collection.\n inverse: () => {\n ctx.graph.addVariable(structuredClone(snapshot))\n placeVariables(snapshot.collectionId, order)\n refreshVariables({ variables: [id] })\n }\n })\n refreshVariables({ variables: [id] })\n }\n\n /** Puts a collection's variables in `order`; ids it does not hold are ignored. */\n function placeVariables(collectionId: string, order: readonly string[]) {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return\n const held = new Set(collection.variableIds)\n const placed = order.filter((id) => held.has(id))\n const rest = collection.variableIds.filter((id) => !placed.includes(id))\n collection.variableIds = [...placed, ...rest]\n }\n\n /** Reorders a collection's variables in one undo step; the order is what files and lists show. */\n function setVariableOrder(collectionId: string, order: readonly string[]) {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return\n const previous = [...collection.variableIds]\n const next = [...order]\n placeVariables(collectionId, next)\n if (previous.join('\\n') === collection.variableIds.join('\\n')) return\n ctx.undo.push({\n label: 'Reorder variables',\n forward: () => {\n placeVariables(collectionId, next)\n ctx.requestRefresh()\n },\n inverse: () => {\n placeVariables(collectionId, previous)\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n }\n\n /** Copies a variable, values and token fields included, right after the original. */\n function duplicateVariable(id: string, name: string): string | undefined {\n const source = ctx.graph.variables.get(id)\n const collection = source && ctx.graph.variableCollections.get(source.collectionId)\n if (!source || !collection) return undefined\n const created = ctx.graph.createVariable(name, source.type, source.collectionId)\n const copy: Variable = { ...structuredClone(source), id: created.id, name }\n ctx.graph.addVariable(copy)\n const before = [...collection.variableIds]\n const order = before.filter((candidate) => candidate !== copy.id)\n order.splice(order.indexOf(id) + 1, 0, copy.id)\n placeVariables(collection.id, order)\n ctx.undo.push({\n label: 'Duplicate variable',\n forward: () => {\n ctx.graph.addVariable(structuredClone(copy))\n placeVariables(collection.id, order)\n ctx.requestRefresh()\n },\n inverse: () => {\n ctx.graph.removeVariable(copy.id)\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n return copy.id\n }\n\n function renameVariable(id: string, newName: string) {\n const variable = ctx.graph.variables.get(id)\n if (!variable) return\n const prevName = variable.name\n variable.name = newName\n ctx.undo.push({\n label: 'Rename variable',\n forward: () => {\n const v = ctx.graph.variables.get(id)\n if (v) v.name = newName\n ctx.requestRefresh()\n },\n inverse: () => {\n const v = ctx.graph.variables.get(id)\n if (v) v.name = prevName\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n }\n\n function addMode(collectionId: string, name?: string): string | undefined {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return undefined\n const modeName = name ?? `Mode ${collection.modes.length + 1}`\n const modeId = ctx.graph.createMode(collectionId, modeName)\n if (!modeId) return undefined\n ctx.undo.push({\n label: 'Add mode',\n forward: () => {\n ctx.graph.addMode(collectionId, modeId, modeName)\n refreshVariables(collectionScope(collectionId))\n },\n inverse: () => {\n ctx.graph.removeMode(collectionId, modeId)\n refreshVariables(collectionScope(collectionId))\n }\n })\n refreshVariables(collectionScope(collectionId))\n return modeId\n }\n\n function removeMode(collectionId: string, modeId: string) {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection || collection.modes.length <= 1) return\n const removedMode = collection.modes.find((m) => m.modeId === modeId)\n if (!removedMode) return\n const modeIndex = collection.modes.indexOf(removedMode)\n const savedMode = structuredClone(removedMode)\n const wasDefault = collection.defaultModeId === modeId\n const valueSnapshots = new Map<string, VariableValue>()\n for (const varId of collection.variableIds) {\n const v = ctx.graph.variables.get(varId)\n if (v?.valuesByMode[modeId] !== undefined) {\n valueSnapshots.set(varId, structuredClone(v.valuesByMode[modeId]))\n }\n }\n ctx.graph.removeMode(collectionId, modeId)\n ctx.undo.push({\n label: 'Remove mode',\n forward: () => {\n ctx.graph.removeMode(collectionId, modeId)\n refreshVariables(collectionScope(collectionId))\n },\n inverse: () => {\n ctx.graph.addMode(collectionId, modeId, savedMode.name)\n const col = ctx.graph.variableCollections.get(collectionId)\n if (col) {\n // The mode comes back as it was, its sort position included, so it keeps its place.\n col.modes = col.modes\n .filter((m) => m.modeId !== modeId)\n .toSpliced(modeIndex, 0, structuredClone(savedMode))\n }\n for (const [varId, value] of valueSnapshots) {\n const v = ctx.graph.variables.get(varId)\n if (v) v.valuesByMode[modeId] = structuredClone(value)\n }\n if (wasDefault) ctx.graph.setDefaultMode(collectionId, modeId)\n refreshVariables(collectionScope(collectionId))\n }\n })\n refreshVariables(collectionScope(collectionId))\n }\n\n function renameMode(collectionId: string, modeId: string, newName: string) {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return\n const mode = collection.modes.find((m) => m.modeId === modeId)\n if (!mode) return\n const prevName = mode.name\n ctx.graph.renameMode(collectionId, modeId, newName)\n ctx.undo.push({\n label: 'Rename mode',\n forward: () => {\n ctx.graph.renameMode(collectionId, modeId, newName)\n ctx.requestRefresh()\n },\n inverse: () => {\n ctx.graph.renameMode(collectionId, modeId, prevName)\n ctx.requestRefresh()\n }\n })\n ctx.requestRefresh()\n }\n\n function setDefaultMode(collectionId: string, modeId: string) {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return\n const prevDefault = collection.defaultModeId\n const prevModes = structuredClone(collection.modes)\n ctx.graph.setDefaultMode(collectionId, modeId)\n ctx.undo.push({\n label: 'Set default mode',\n forward: () => {\n ctx.graph.setDefaultMode(collectionId, modeId)\n refreshVariables(collectionScope(collectionId))\n },\n inverse: () => {\n // Setting a default moves it first; undo restores the column order too. Look the\n // collection up again: undoing its removal in between restores a copy.\n const current = ctx.graph.variableCollections.get(collectionId)\n if (current) {\n current.modes = structuredClone(prevModes)\n current.defaultModeId = prevDefault\n }\n refreshVariables(collectionScope(collectionId))\n }\n })\n refreshVariables(collectionScope(collectionId))\n }\n\n function duplicateMode(collectionId: string, sourceModeId: string): string | undefined {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return undefined\n const sourceMode = collection.modes.find((m) => m.modeId === sourceModeId)\n if (!sourceMode) return undefined\n const modeName = `${sourceMode.name} copy`\n const modeId = ctx.graph.createMode(collectionId, modeName, sourceModeId)\n if (!modeId) return undefined\n ctx.undo.push({\n label: 'Duplicate mode',\n forward: () => {\n ctx.graph.addMode(collectionId, modeId, modeName, sourceModeId)\n refreshVariables(collectionScope(collectionId))\n },\n inverse: () => {\n ctx.graph.removeMode(collectionId, modeId)\n refreshVariables(collectionScope(collectionId))\n }\n })\n refreshVariables(collectionScope(collectionId))\n return modeId\n }\n\n function setActiveMode(collectionId: string, modeId: string) {\n ctx.graph.setActiveMode(collectionId, modeId)\n refreshVariables(collectionScope(collectionId))\n }\n\n /**\n * Sets one mode's value. Calls that share a `coalesceKey`, such as the steps of one color picker\n * drag, undo together.\n */\n function updateVariableValue(\n id: string,\n modeId: string,\n value: VariableValue,\n coalesceKey?: string\n ) {\n const variable = ctx.graph.variables.get(id)\n if (!variable) return\n const previous = modeEntry(variable, modeId)\n const next: ModeEntry = {\n value: structuredClone(value),\n expression: tokenExpressionForValue(previous.expression, value)\n }\n const apply = (entry: ModeEntry) => {\n const target = ctx.graph.variables.get(id)\n if (target) setModeEntry(target, modeId, entry)\n refreshVariables({ variables: [id] })\n }\n apply(next)\n ctx.undo.push({\n label: 'Update variable value',\n forward: () => apply(next),\n inverse: () => apply(previous),\n coalesceKey\n })\n }\n\n /** Change token fields in one undo step; a field set to `undefined` is cleared. */\n function updateVariableToken(id: string, patch: Partial<VariableTokenFields>) {\n const variable = ctx.graph.variables.get(id)\n if (!variable) return\n const previous = tokenFields(variable)\n const next = structuredClone(patch)\n const apply = (values: Partial<VariableTokenFields>) => {\n const target = ctx.graph.variables.get(id)\n if (!target) return\n const { description, ...fields } = structuredClone(values)\n // A cleared field is removed, not kept as a key set to `undefined`.\n for (const key of Object.keys(fields) as Array<keyof typeof fields>) {\n if (fields[key] === undefined) Reflect.deleteProperty(target, key)\n }\n Object.assign(\n target,\n omitBy(fields, (value) => value === undefined)\n )\n // Every variable has a description; clearing it leaves an empty one.\n if ('description' in values) target.description = description ?? ''\n ctx.requestRefresh()\n }\n apply(next)\n ctx.undo.push({\n label: 'Update variable token',\n forward: () => apply(next),\n inverse: () => apply(previous)\n })\n }\n\n /** The selector or query a mode applies under; an empty condition restores the default. */\n function setModeCondition(collectionId: string, modeId: string, condition: string | undefined) {\n const mode = ctx.graph.variableCollections\n .get(collectionId)\n ?.modes.find((candidate) => candidate.modeId === modeId)\n if (!mode) return\n const previous = mode.condition\n const next = condition?.trim() || undefined\n if (next === previous) return\n const apply = (value: string | undefined) => {\n const target = ctx.graph.variableCollections\n .get(collectionId)\n ?.modes.find((candidate) => candidate.modeId === modeId)\n if (target) target.condition = value\n ctx.requestRefresh()\n }\n apply(next)\n ctx.undo.push({\n label: 'Set mode condition',\n forward: () => apply(next),\n inverse: () => apply(previous)\n })\n }\n\n /**\n * Name the attribute manual modes are switched by; an empty name restores the default, and a\n * name no stylesheet can select on leaves the current one.\n */\n function setModeAttribute(collectionId: string, name: string | undefined) {\n const collection = ctx.graph.variableCollections.get(collectionId)\n if (!collection) return\n const previous = collection.modeAttribute\n const next = name?.trim() || undefined\n if (next === previous || (next !== undefined && !isModeAttributeName(next))) return\n const apply = (value: string | undefined) => {\n const target = ctx.graph.variableCollections.get(collectionId)\n if (target) target.modeAttribute = value\n ctx.requestRefresh()\n }\n apply(next)\n ctx.undo.push({\n label: 'Set mode attribute',\n forward: () => apply(next),\n inverse: () => apply(previous)\n })\n }\n\n return {\n refreshVariables,\n updateVariableToken,\n setModeCondition,\n duplicateVariable,\n setVariableOrder,\n setModeAttribute,\n getVariablesByType,\n getVariable,\n resolveColorVariable,\n resolveNumberVariable,\n getVariablesForCollection,\n getCollection,\n getCollections,\n getCollectionCount,\n getVariableCount,\n renameCollection,\n addCollection,\n removeCollection,\n addVariable,\n removeVariable,\n renameVariable,\n updateVariableValue,\n addMode,\n removeMode,\n renameMode,\n setDefaultMode,\n duplicateMode,\n setActiveMode\n }\n}\n"],"mappings":";;;;;;;;;AA0BA,SAAS,YAAY,UAAyC;CAC5D,MAAM,EAAE,MAAM,aAAa,QAAQ,YAAY,aAAa,yBAAyB;CACrF,OAAO,gBAAgB;EACrB;EACA;EACA;EACA;EACA;EACA;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AAI,QAAQ,OAAO,YAAY;GAC/B,IAAI,eAAe;EACrB;EACA,MAAM,IAAI;EACV,IAAI,KAAK,KAAK;GACZ,OAAO;GACP,eAAe,MAAM,IAAI;GACzB,eAAe,MAAM,QAAQ;EAC/B,CAAC;CACH;;;;;CAMA,SAAS,iBAAiB,cAAsB,MAA0B;EACxE,MAAM,aAAa,IAAI,MAAM,oBAAoB,IAAI,YAAY;EACjE,IAAI,CAAC,YAAY;EACjB,MAAM,WAAW,WAAW;EAC5B,MAAM,OAAO,MAAM,KAAK,KAAK,KAAA;EAC7B,IAAI,SAAS,YAAa,SAAS,KAAA,KAAa,CAAC,oBAAoB,IAAI,GAAI;EAC7E,MAAM,SAAS,UAA8B;GAC3C,MAAM,SAAS,IAAI,MAAM,oBAAoB,IAAI,YAAY;GAC7D,IAAI,QAAQ,OAAO,gBAAgB;GACnC,IAAI,eAAe;EACrB;EACA,MAAM,IAAI;EACV,IAAI,KAAK,KAAK;GACZ,OAAO;GACP,eAAe,MAAM,IAAI;GACzB,eAAe,MAAM,QAAQ;EAC/B,CAAC;CACH;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import { EditorContext } from "./types.js";
|
|
1
|
+
import { EditorContext, ViewportInsets, VisibleCanvas } from "./types.js";
|
|
2
|
+
import { Vector } from "@pairdraw/scene-graph/primitives";
|
|
2
3
|
//#region src/editor/viewport.d.ts
|
|
4
|
+
/** No floating chrome, for an editor whose canvas is bare. */
|
|
5
|
+
declare const NO_VIEWPORT_INSETS: ViewportInsets;
|
|
6
|
+
/**
|
|
7
|
+
* The part of the canvas no floating chrome covers. A rail on the left or a pill at the bottom sits
|
|
8
|
+
* above the canvas element, so fitting to the whole element hides content under it.
|
|
9
|
+
*/
|
|
10
|
+
declare function visibleCanvas(ctx: EditorContext): VisibleCanvas;
|
|
3
11
|
declare function createViewportActions(ctx: EditorContext): {
|
|
12
|
+
viewportCanvasCenter: () => Vector;
|
|
4
13
|
revealNodes: (nodeIds: readonly string[], margin?: number) => void;
|
|
5
14
|
screenToCanvas: (sx: number, sy: number) => {
|
|
6
15
|
x: number;
|
|
@@ -18,5 +27,5 @@ declare function createViewportActions(ctx: EditorContext): {
|
|
|
18
27
|
zoomToSelection: () => void;
|
|
19
28
|
};
|
|
20
29
|
//#endregion
|
|
21
|
-
export { createViewportActions };
|
|
30
|
+
export { NO_VIEWPORT_INSETS, createViewportActions, visibleCanvas };
|
|
22
31
|
//# sourceMappingURL=viewport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewport.d.ts","names":[],"sources":["../../src/editor/viewport.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"viewport.d.ts","names":[],"sources":["../../src/editor/viewport.ts"],"mappings":";;;;cAaa,oBAAoB;;;;;iBAMjB,cAAc,KAAK,gBAAgB;iBAYnC,sBAAsB,KAAK;EAgLR,4BAAA;EA9BH,cAAA,4BAAiB;EA9HnB,iBAAA,YAAM;;;;EAOC,qBAAA,eAAM,iBAAiB;EAUhC,YAAA,eAAM,iBAAiB;EAQhC,MAAA,YAAM;EAQK,eAAA,cAAM,cAAc,cAAc;EAqBpC,aAAA,cAAM,cAAc,cAAc;EAevC,WAAA,WAAM,WAAW;;;EAuBV,cAAA"}
|
package/dist/editor/viewport.js
CHANGED
|
@@ -5,6 +5,37 @@ import { computeAbsoluteBounds, computeBounds } from "@pairdraw/scene-graph/geom
|
|
|
5
5
|
//#region src/editor/viewport.ts
|
|
6
6
|
/** Space kept between revealed layers and the viewport edge. */
|
|
7
7
|
const REVEAL_MARGIN = 48;
|
|
8
|
+
/** No floating chrome, for an editor whose canvas is bare. */
|
|
9
|
+
const NO_VIEWPORT_INSETS = {
|
|
10
|
+
top: 0,
|
|
11
|
+
right: 0,
|
|
12
|
+
bottom: 0,
|
|
13
|
+
left: 0
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The part of the canvas no floating chrome covers. A rail on the left or a pill at the bottom sits
|
|
17
|
+
* above the canvas element, so fitting to the whole element hides content under it.
|
|
18
|
+
*/
|
|
19
|
+
function visibleCanvas(ctx) {
|
|
20
|
+
const { width, height } = ctx.getViewportSize();
|
|
21
|
+
const insets = ctx.getViewportInsets();
|
|
22
|
+
const left = Math.min(Math.max(insets.left, 0), width);
|
|
23
|
+
const top = Math.min(Math.max(insets.top, 0), height);
|
|
24
|
+
const right = Math.min(Math.max(insets.right, 0), width - left);
|
|
25
|
+
const bottom = Math.min(Math.max(insets.bottom, 0), height - top);
|
|
26
|
+
const area = {
|
|
27
|
+
left,
|
|
28
|
+
top,
|
|
29
|
+
width: width - left - right,
|
|
30
|
+
height: height - top - bottom
|
|
31
|
+
};
|
|
32
|
+
return area.width > 0 && area.height > 0 ? area : {
|
|
33
|
+
left: 0,
|
|
34
|
+
top: 0,
|
|
35
|
+
width,
|
|
36
|
+
height
|
|
37
|
+
};
|
|
38
|
+
}
|
|
8
39
|
function createViewportActions(ctx) {
|
|
9
40
|
function currentViewport() {
|
|
10
41
|
return {
|
|
@@ -58,11 +89,11 @@ function createViewportActions(ctx) {
|
|
|
58
89
|
const padding = 80;
|
|
59
90
|
const w = maxX - minX + 160;
|
|
60
91
|
const h = maxY - minY + 160;
|
|
61
|
-
const
|
|
62
|
-
const zoom = Math.max(.02, Math.min(
|
|
92
|
+
const area = visibleCanvas(ctx);
|
|
93
|
+
const zoom = Math.max(.02, Math.min(area.width / w, area.height / h, 1));
|
|
63
94
|
ctx.state.zoom = zoom;
|
|
64
|
-
ctx.state.panX = (
|
|
65
|
-
ctx.state.panY = (
|
|
95
|
+
ctx.state.panX = area.left + (area.width - w * zoom) / 2 - minX * zoom + padding * zoom;
|
|
96
|
+
ctx.state.panY = area.top + (area.height - h * zoom) / 2 - minY * zoom + padding * zoom;
|
|
66
97
|
ctx.requestRepaint();
|
|
67
98
|
emitViewportChanged(previous);
|
|
68
99
|
}
|
|
@@ -76,21 +107,21 @@ function createViewportActions(ctx) {
|
|
|
76
107
|
const height = maxY - minY;
|
|
77
108
|
if (!(width > 0) || !(height > 0)) return;
|
|
78
109
|
const previous = currentViewport();
|
|
79
|
-
const
|
|
80
|
-
const zoom = Math.max(.02, Math.min(256, Math.min(
|
|
110
|
+
const area = visibleCanvas(ctx);
|
|
111
|
+
const zoom = Math.max(.02, Math.min(256, Math.min(area.width / width, area.height / height)));
|
|
81
112
|
ctx.state.zoom = zoom;
|
|
82
|
-
ctx.state.panX =
|
|
83
|
-
ctx.state.panY =
|
|
113
|
+
ctx.state.panX = area.left + area.width / 2 - (minX + width / 2) * zoom;
|
|
114
|
+
ctx.state.panY = area.top + area.height / 2 - (minY + height / 2) * zoom;
|
|
84
115
|
ctx.requestRepaint();
|
|
85
116
|
emitViewportChanged(previous);
|
|
86
117
|
}
|
|
87
118
|
/** Put the world point (x, y) at the center of the viewport, at `zoom` (the current one by default). */
|
|
88
119
|
function centerOn(x, y, zoom = ctx.state.zoom) {
|
|
89
120
|
const previous = currentViewport();
|
|
90
|
-
const
|
|
121
|
+
const area = visibleCanvas(ctx);
|
|
91
122
|
const nextZoom = Math.max(.02, Math.min(256, zoom));
|
|
92
|
-
const panX = width / 2 - x * nextZoom;
|
|
93
|
-
const panY = height / 2 - y * nextZoom;
|
|
123
|
+
const panX = area.left + area.width / 2 - x * nextZoom;
|
|
124
|
+
const panY = area.top + area.height / 2 - y * nextZoom;
|
|
94
125
|
if (!Number.isFinite(panX) || !Number.isFinite(panY)) return;
|
|
95
126
|
ctx.state.zoom = nextZoom;
|
|
96
127
|
ctx.state.panX = panX;
|
|
@@ -105,13 +136,13 @@ function createViewportActions(ctx) {
|
|
|
105
136
|
zoomToBounds(b.x, b.y, b.x + b.width, b.y + b.height);
|
|
106
137
|
}
|
|
107
138
|
function zoomToLevel(level) {
|
|
108
|
-
const
|
|
109
|
-
const centerX = (-ctx.state.panX +
|
|
110
|
-
const centerY = (-ctx.state.panY +
|
|
139
|
+
const area = visibleCanvas(ctx);
|
|
140
|
+
const centerX = (-ctx.state.panX + area.left + area.width / 2) / ctx.state.zoom;
|
|
141
|
+
const centerY = (-ctx.state.panY + area.top + area.height / 2) / ctx.state.zoom;
|
|
111
142
|
const previous = currentViewport();
|
|
112
143
|
ctx.state.zoom = Math.max(.02, Math.min(256, level));
|
|
113
|
-
ctx.state.panX =
|
|
114
|
-
ctx.state.panY =
|
|
144
|
+
ctx.state.panX = area.left + area.width / 2 - centerX * ctx.state.zoom;
|
|
145
|
+
ctx.state.panY = area.top + area.height / 2 - centerY * ctx.state.zoom;
|
|
115
146
|
ctx.requestRepaint();
|
|
116
147
|
emitViewportChanged(previous);
|
|
117
148
|
}
|
|
@@ -133,9 +164,9 @@ function createViewportActions(ctx) {
|
|
|
133
164
|
const nodes = nodeIds.map((id) => ctx.graph.getNode(id)).filter((node) => node !== void 0);
|
|
134
165
|
if (nodes.length === 0) return;
|
|
135
166
|
const bounds = computeBounds(nodes.map((node) => getAxisAlignedWorldBounds(node, ctx.graph)));
|
|
136
|
-
const
|
|
167
|
+
const area = visibleCanvas(ctx);
|
|
137
168
|
const { zoom, panX, panY } = ctx.state;
|
|
138
|
-
if (!(bounds.width * zoom <= width - margin * 2 && bounds.height * zoom <= height - margin * 2)) {
|
|
169
|
+
if (!(bounds.width * zoom <= area.width - margin * 2 && bounds.height * zoom <= area.height - margin * 2)) {
|
|
139
170
|
zoomToBounds(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height);
|
|
140
171
|
return;
|
|
141
172
|
}
|
|
@@ -143,10 +174,19 @@ function createViewportActions(ctx) {
|
|
|
143
174
|
const top = bounds.y * zoom + panY;
|
|
144
175
|
const right = left + bounds.width * zoom;
|
|
145
176
|
const bottom = top + bounds.height * zoom;
|
|
146
|
-
if (left >= margin && top >= margin && right <= width - margin && bottom <= height - margin) return;
|
|
147
|
-
pan(width / 2 - (left + right) / 2, height / 2 - (top + bottom) / 2);
|
|
177
|
+
if (left >= area.left + margin && top >= area.top + margin && right <= area.left + area.width - margin && bottom <= area.top + area.height - margin) return;
|
|
178
|
+
pan(area.left + area.width / 2 - (left + right) / 2, area.top + area.height / 2 - (top + bottom) / 2);
|
|
179
|
+
}
|
|
180
|
+
/** The middle of the canvas the floating chrome leaves, in canvas pixels from its top-left. */
|
|
181
|
+
function viewportCanvasCenter() {
|
|
182
|
+
const area = visibleCanvas(ctx);
|
|
183
|
+
return {
|
|
184
|
+
x: area.left + area.width / 2,
|
|
185
|
+
y: area.top + area.height / 2
|
|
186
|
+
};
|
|
148
187
|
}
|
|
149
188
|
return {
|
|
189
|
+
viewportCanvasCenter,
|
|
150
190
|
revealNodes,
|
|
151
191
|
screenToCanvas,
|
|
152
192
|
setZoomAroundPoint,
|
|
@@ -162,6 +202,6 @@ function createViewportActions(ctx) {
|
|
|
162
202
|
};
|
|
163
203
|
}
|
|
164
204
|
//#endregion
|
|
165
|
-
export { createViewportActions };
|
|
205
|
+
export { NO_VIEWPORT_INSETS, createViewportActions, visibleCanvas };
|
|
166
206
|
|
|
167
207
|
//# sourceMappingURL=viewport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewport.js","names":[],"sources":["../../src/editor/viewport.ts"],"sourcesContent":["import { getAxisAlignedWorldBounds } from '@pairdraw/scene-graph/coordinate'\nimport { computeBounds, computeAbsoluteBounds } from '@pairdraw/scene-graph/geometry'\n\nimport { ZOOM_DIVISOR, ZOOM_SCALE_MAX, ZOOM_SCALE_MIN } from '#core/constants'\nimport { emitNavigationTrace } from '#core/profiler'\n\nimport type { EditorContext } from './types'\n\n/** Space kept between revealed layers and the viewport edge. */\nconst REVEAL_MARGIN = 48\n\nexport function createViewportActions(ctx: EditorContext) {\n function currentViewport() {\n return { panX: ctx.state.panX, panY: ctx.state.panY, zoom: ctx.state.zoom }\n }\n\n function emitViewportChanged(previous: ReturnType<typeof currentViewport>) {\n const next = currentViewport()\n if (next.panX !== previous.panX || next.panY !== previous.panY || next.zoom !== previous.zoom) {\n emitNavigationTrace('viewport:changed', {\n panX: next.panX,\n panY: next.panY,\n zoom: next.zoom,\n previousPanX: previous.panX,\n previousPanY: previous.panY,\n previousZoom: previous.zoom\n })\n ctx.emitEditorEvent('viewport:changed', next, previous)\n }\n }\n\n function screenToCanvas(sx: number, sy: number) {\n return {\n x: (sx - ctx.state.panX) / ctx.state.zoom,\n y: (sy - ctx.state.panY) / ctx.state.zoom\n }\n }\n\n function setZoomAroundPoint(level: number, centerX: number, centerY: number) {\n const previous = currentViewport()\n const newZoom = Math.max(0.02, Math.min(256, level))\n ctx.state.panX = centerX - (centerX - ctx.state.panX) * (newZoom / ctx.state.zoom)\n ctx.state.panY = centerY - (centerY - ctx.state.panY) * (newZoom / ctx.state.zoom)\n ctx.state.zoom = newZoom\n ctx.requestRepaint()\n emitViewportChanged(previous)\n }\n\n function applyZoom(delta: number, centerX: number, centerY: number) {\n const factor = Math.min(\n ZOOM_SCALE_MAX,\n Math.max(ZOOM_SCALE_MIN, Math.exp(-delta / ZOOM_DIVISOR))\n )\n setZoomAroundPoint(ctx.state.zoom * factor, centerX, centerY)\n }\n\n function pan(dx: number, dy: number) {\n const previous = currentViewport()\n ctx.state.panX += dx\n ctx.state.panY += dy\n ctx.requestRepaint()\n emitViewportChanged(previous)\n }\n\n function zoomToBounds(minX: number, minY: number, maxX: number, maxY: number) {\n const previous = currentViewport()\n const padding = 80\n const w = maxX - minX + padding * 2\n const h = maxY - minY + padding * 2\n\n const { width: viewW, height: viewH } = ctx.getViewportSize()\n const zoom = Math.max(0.02, Math.min(viewW / w, viewH / h, 1))\n\n ctx.state.zoom = zoom\n ctx.state.panX = (viewW - w * zoom) / 2 - minX * zoom + padding * zoom\n ctx.state.panY = (viewH - h * zoom) / 2 - minY * zoom + padding * zoom\n ctx.requestRepaint()\n emitViewportChanged(previous)\n }\n\n /**\n * Fits the world area to the viewport, edge to edge and at any zoom, as a drag of Figma's zoom\n * tool does; `zoomToBounds` instead leaves a margin and never zooms past 100%. An area with no\n * width or height leaves the view alone.\n */\n function zoomToArea(minX: number, minY: number, maxX: number, maxY: number) {\n const width = maxX - minX\n const height = maxY - minY\n if (!(width > 0) || !(height > 0)) return\n const previous = currentViewport()\n const { width: viewW, height: viewH } = ctx.getViewportSize()\n const zoom = Math.max(0.02, Math.min(256, Math.min(viewW / width, viewH / height)))\n ctx.state.zoom = zoom\n ctx.state.panX = viewW / 2 - (minX + width / 2) * zoom\n ctx.state.panY = viewH / 2 - (minY + height / 2) * zoom\n ctx.requestRepaint()\n emitViewportChanged(previous)\n }\n\n /** Put the world point (x, y) at the center of the viewport, at `zoom` (the current one by default). */\n function centerOn(x: number, y: number, zoom = ctx.state.zoom) {\n const previous = currentViewport()\n const { width, height } = ctx.getViewportSize()\n const nextZoom = Math.max(0.02, Math.min(256, zoom))\n const panX = width / 2 - x * nextZoom\n const panY = height / 2 - y * nextZoom\n // Remote cursors are finite but unbounded; a point that overflows leaves the view alone.\n if (!Number.isFinite(panX) || !Number.isFinite(panY)) return\n ctx.state.zoom = nextZoom\n ctx.state.panX = panX\n ctx.state.panY = panY\n ctx.requestRepaint()\n emitViewportChanged(previous)\n }\n\n function zoomToFit() {\n const nodes = ctx.graph.getChildren(ctx.state.currentPageId)\n if (nodes.length === 0) return\n\n const b = computeBounds(nodes)\n zoomToBounds(b.x, b.y, b.x + b.width, b.y + b.height)\n }\n\n function zoomToLevel(level: number) {\n const { width: viewW, height: viewH } = ctx.getViewportSize()\n const centerX = (-ctx.state.panX + viewW / 2) / ctx.state.zoom\n const centerY = (-ctx.state.panY + viewH / 2) / ctx.state.zoom\n\n const previous = currentViewport()\n ctx.state.zoom = Math.max(0.02, Math.min(256, level))\n // Keep the world point at the center of the viewport where it was.\n ctx.state.panX = viewW / 2 - centerX * ctx.state.zoom\n ctx.state.panY = viewH / 2 - centerY * ctx.state.zoom\n ctx.requestRepaint()\n emitViewportChanged(previous)\n }\n\n function zoomTo100() {\n zoomToLevel(1)\n }\n\n function zoomToSelection() {\n if (ctx.state.selectedIds.size === 0) return\n\n const nodes = [...ctx.state.selectedIds]\n .map((id) => ctx.graph.getNode(id))\n .filter((n): n is NonNullable<typeof n> => n != null)\n if (nodes.length === 0) return\n\n const b = computeAbsoluteBounds(nodes, ctx.graph)\n zoomToBounds(b.x, b.y, b.x + b.width, b.y + b.height)\n }\n\n /**\n * Brings layers into view: pans to center them when they fit at the current zoom and are not\n * already visible, and zooms out to fit them only when they do not fit.\n */\n function revealNodes(nodeIds: readonly string[], margin = REVEAL_MARGIN) {\n const nodes = nodeIds.map((id) => ctx.graph.getNode(id)).filter((node) => node !== undefined)\n if (nodes.length === 0) return\n const bounds = computeBounds(nodes.map((node) => getAxisAlignedWorldBounds(node, ctx.graph)))\n const { width, height } = ctx.getViewportSize()\n const { zoom, panX, panY } = ctx.state\n const fits =\n bounds.width * zoom <= width - margin * 2 && bounds.height * zoom <= height - margin * 2\n if (!fits) {\n zoomToBounds(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height)\n return\n }\n const left = bounds.x * zoom + panX\n const top = bounds.y * zoom + panY\n const right = left + bounds.width * zoom\n const bottom = top + bounds.height * zoom\n const visible =\n left >= margin && top >= margin && right <= width - margin && bottom <= height - margin\n if (visible) return\n pan(width / 2 - (left + right) / 2, height / 2 - (top + bottom) / 2)\n }\n\n return {\n revealNodes,\n screenToCanvas,\n setZoomAroundPoint,\n applyZoom,\n pan,\n zoomToBounds,\n zoomToArea,\n centerOn,\n zoomToFit,\n zoomTo100,\n zoomToLevel,\n zoomToSelection\n }\n}\n"],"mappings":";;;;;;AASA,MAAM,gBAAgB;AAEtB,SAAgB,sBAAsB,KAAoB;CACxD,SAAS,kBAAkB;EACzB,OAAO;GAAE,MAAM,IAAI,MAAM;GAAM,MAAM,IAAI,MAAM;GAAM,MAAM,IAAI,MAAM;EAAK;C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O,IAAI,KAAK;EAChD,aAAa,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM;CACtD;;;;;CAMA,SAAS,YAAY,SAA4B,SAAS,eAAe;EACvE,MAAM,QAAQ,QAAQ,KAAK,OAAO,IAAI,MAAM,QAAQ,EAAE,CAAC,CAAC,CAAC,QAAQ,SAAS,SAAS,KAAA,CAAS;EAC5F,IAAI,MAAM,WAAW,GAAG;EACxB,MAAM,SAAS,cAAc,MAAM,KAAK,SAAS,0BAA0B,MAAM,IAAI,KAAK,CAAC,CAAC;EAC5F,MAAM,EAAE,OAAO,WAAW,IAAI,gBAAgB;EAC9C,MAAM,EAAE,MAAM,MAAM,SAAS,IAAI;EAGjC,IAAI,EADF,OAAO,QAAQ,QAAQ,QAAQ,SAAS,KAAK,OAAO,SAAS,QAAQ,SAAS,SAAS,IAC9E;GACT,aAAa,OAAO,GAAG,OAAO,GAAG,OAAO,IAAI,OAAO,OAAO,OAAO,IAAI,OAAO,MAAM;GAClF;EACF;EACA,MAAM,OAAO,OAAO,IAAI,OAAO;EAC/B,MAAM,MAAM,OAAO,IAAI,OAAO;EAC9B,MAAM,QAAQ,OAAO,OAAO,QAAQ;EACpC,MAAM,SAAS,MAAM,OAAO,SAAS;EAGrC,IADE,QAAQ,UAAU,OAAO,UAAU,SAAS,QAAQ,UAAU,UAAU,SAAS,QACtE;EACb,IAAI,QAAQ,KAAK,OAAO,SAAS,GAAG,SAAS,KAAK,MAAM,UAAU,CAAC;CACrE;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"viewport.js","names":[],"sources":["../../src/editor/viewport.ts"],"sourcesContent":["import { getAxisAlignedWorldBounds } from '@pairdraw/scene-graph/coordinate'\nimport { computeBounds, computeAbsoluteBounds } from '@pairdraw/scene-graph/geometry'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { ZOOM_DIVISOR, ZOOM_SCALE_MAX, ZOOM_SCALE_MIN } from '#core/constants'\nimport { emitNavigationTrace } from '#core/profiler'\n\nimport type { EditorContext, ViewportInsets, VisibleCanvas } from './types'\n\n/** Space kept between revealed layers and the viewport edge. */\nconst REVEAL_MARGIN = 48\n\n/** No floating chrome, for an editor whose canvas is bare. */\nexport const NO_VIEWPORT_INSETS: ViewportInsets = { top: 0, right: 0, bottom: 0, left: 0 }\n\n/**\n * The part of the canvas no floating chrome covers. A rail on the left or a pill at the bottom sits\n * above the canvas element, so fitting to the whole element hides content under it.\n */\nexport function visibleCanvas(ctx: EditorContext): VisibleCanvas {\n const { width, height } = ctx.getViewportSize()\n const insets = ctx.getViewportInsets()\n const left = Math.min(Math.max(insets.left, 0), width)\n const top = Math.min(Math.max(insets.top, 0), height)\n const right = Math.min(Math.max(insets.right, 0), width - left)\n const bottom = Math.min(Math.max(insets.bottom, 0), height - top)\n const area = { left, top, width: width - left - right, height: height - top - bottom }\n // Chrome that covers everything is no guide at all; the whole canvas is then the best guess.\n return area.width > 0 && area.height > 0 ? area : { left: 0, top: 0, width, height }\n}\n\nexport function createViewportActions(ctx: EditorContext) {\n function currentViewport() {\n return { panX: ctx.state.panX, panY: ctx.state.panY, zoom: ctx.state.zoom }\n }\n\n function emitViewportChanged(previous: ReturnType<typeof currentViewport>) {\n const next = currentViewport()\n if (next.panX !== previous.panX || next.panY !== previous.panY || next.zoom !== previous.zoom) {\n emitNavigationTrace('viewport:changed', {\n panX: next.panX,\n panY: next.panY,\n zoom: next.zoom,\n previousPanX: previous.panX,\n previousPanY: previous.panY,\n previousZoom: previous.zoom\n })\n ctx.emitEditorEvent('viewport:changed', next, previous)\n }\n }\n\n function screenToCanvas(sx: number, sy: number) {\n return {\n x: (sx - ctx.state.panX) / ctx.state.zoom,\n y: (sy - ctx.state.panY) / ctx.state.zoom\n }\n }\n\n function setZoomAroundPoint(level: number, centerX: number, centerY: number) {\n const previous = currentViewport()\n const newZoom = Math.max(0.02, Math.min(256, level))\n ctx.state.panX = centerX - (centerX - ctx.state.panX) * (newZoom / ctx.state.zoom)\n ctx.state.panY = centerY - (centerY - ctx.state.panY) * (newZoom / ctx.state.zoom)\n ctx.state.zoom = newZoom\n ctx.requestRepaint()\n emitViewportChanged(previous)\n }\n\n function applyZoom(delta: number, centerX: number, centerY: number) {\n const factor = Math.min(\n ZOOM_SCALE_MAX,\n Math.max(ZOOM_SCALE_MIN, Math.exp(-delta / ZOOM_DIVISOR))\n )\n setZoomAroundPoint(ctx.state.zoom * factor, centerX, centerY)\n }\n\n function pan(dx: number, dy: number) {\n const previous = currentViewport()\n ctx.state.panX += dx\n ctx.state.panY += dy\n ctx.requestRepaint()\n emitViewportChanged(previous)\n }\n\n function zoomToBounds(minX: number, minY: number, maxX: number, maxY: number) {\n const previous = currentViewport()\n const padding = 80\n const w = maxX - minX + padding * 2\n const h = maxY - minY + padding * 2\n\n const area = visibleCanvas(ctx)\n const zoom = Math.max(0.02, Math.min(area.width / w, area.height / h, 1))\n\n ctx.state.zoom = zoom\n ctx.state.panX = area.left + (area.width - w * zoom) / 2 - minX * zoom + padding * zoom\n ctx.state.panY = area.top + (area.height - h * zoom) / 2 - minY * zoom + padding * zoom\n ctx.requestRepaint()\n emitViewportChanged(previous)\n }\n\n /**\n * Fits the world area to the viewport, edge to edge and at any zoom, as a drag of Figma's zoom\n * tool does; `zoomToBounds` instead leaves a margin and never zooms past 100%. An area with no\n * width or height leaves the view alone.\n */\n function zoomToArea(minX: number, minY: number, maxX: number, maxY: number) {\n const width = maxX - minX\n const height = maxY - minY\n if (!(width > 0) || !(height > 0)) return\n const previous = currentViewport()\n const area = visibleCanvas(ctx)\n const zoom = Math.max(0.02, Math.min(256, Math.min(area.width / width, area.height / height)))\n ctx.state.zoom = zoom\n ctx.state.panX = area.left + area.width / 2 - (minX + width / 2) * zoom\n ctx.state.panY = area.top + area.height / 2 - (minY + height / 2) * zoom\n ctx.requestRepaint()\n emitViewportChanged(previous)\n }\n\n /** Put the world point (x, y) at the center of the viewport, at `zoom` (the current one by default). */\n function centerOn(x: number, y: number, zoom = ctx.state.zoom) {\n const previous = currentViewport()\n const area = visibleCanvas(ctx)\n const nextZoom = Math.max(0.02, Math.min(256, zoom))\n const panX = area.left + area.width / 2 - x * nextZoom\n const panY = area.top + area.height / 2 - y * nextZoom\n // Remote cursors are finite but unbounded; a point that overflows leaves the view alone.\n if (!Number.isFinite(panX) || !Number.isFinite(panY)) return\n ctx.state.zoom = nextZoom\n ctx.state.panX = panX\n ctx.state.panY = panY\n ctx.requestRepaint()\n emitViewportChanged(previous)\n }\n\n function zoomToFit() {\n const nodes = ctx.graph.getChildren(ctx.state.currentPageId)\n if (nodes.length === 0) return\n\n const b = computeBounds(nodes)\n zoomToBounds(b.x, b.y, b.x + b.width, b.y + b.height)\n }\n\n function zoomToLevel(level: number) {\n const area = visibleCanvas(ctx)\n const centerX = (-ctx.state.panX + area.left + area.width / 2) / ctx.state.zoom\n const centerY = (-ctx.state.panY + area.top + area.height / 2) / ctx.state.zoom\n\n const previous = currentViewport()\n ctx.state.zoom = Math.max(0.02, Math.min(256, level))\n // Keep the world point at the center of the viewport where it was.\n ctx.state.panX = area.left + area.width / 2 - centerX * ctx.state.zoom\n ctx.state.panY = area.top + area.height / 2 - centerY * ctx.state.zoom\n ctx.requestRepaint()\n emitViewportChanged(previous)\n }\n\n function zoomTo100() {\n zoomToLevel(1)\n }\n\n function zoomToSelection() {\n if (ctx.state.selectedIds.size === 0) return\n\n const nodes = [...ctx.state.selectedIds]\n .map((id) => ctx.graph.getNode(id))\n .filter((n): n is NonNullable<typeof n> => n != null)\n if (nodes.length === 0) return\n\n const b = computeAbsoluteBounds(nodes, ctx.graph)\n zoomToBounds(b.x, b.y, b.x + b.width, b.y + b.height)\n }\n\n /**\n * Brings layers into view: pans to center them when they fit at the current zoom and are not\n * already visible, and zooms out to fit them only when they do not fit.\n */\n function revealNodes(nodeIds: readonly string[], margin = REVEAL_MARGIN) {\n const nodes = nodeIds.map((id) => ctx.graph.getNode(id)).filter((node) => node !== undefined)\n if (nodes.length === 0) return\n const bounds = computeBounds(nodes.map((node) => getAxisAlignedWorldBounds(node, ctx.graph)))\n const area = visibleCanvas(ctx)\n const { zoom, panX, panY } = ctx.state\n const fits =\n bounds.width * zoom <= area.width - margin * 2 &&\n bounds.height * zoom <= area.height - margin * 2\n if (!fits) {\n zoomToBounds(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height)\n return\n }\n const left = bounds.x * zoom + panX\n const top = bounds.y * zoom + panY\n const right = left + bounds.width * zoom\n const bottom = top + bounds.height * zoom\n const visible =\n left >= area.left + margin &&\n top >= area.top + margin &&\n right <= area.left + area.width - margin &&\n bottom <= area.top + area.height - margin\n if (visible) return\n pan(\n area.left + area.width / 2 - (left + right) / 2,\n area.top + area.height / 2 - (top + bottom) / 2\n )\n }\n\n /** The middle of the canvas the floating chrome leaves, in canvas pixels from its top-left. */\n function viewportCanvasCenter(): Vector {\n const area = visibleCanvas(ctx)\n return { x: area.left + area.width / 2, y: area.top + area.height / 2 }\n }\n\n return {\n viewportCanvasCenter,\n revealNodes,\n screenToCanvas,\n setZoomAroundPoint,\n applyZoom,\n pan,\n zoomToBounds,\n zoomToArea,\n centerOn,\n zoomToFit,\n zoomTo100,\n zoomToLevel,\n zoomToSelection\n }\n}\n"],"mappings":";;;;;;AAUA,MAAM,gBAAgB;;AAGtB,MAAa,qBAAqC;CAAE,KAAK;CAAG,OAAO;CAAG,QAAQ;CAAG,MAAM;AAAE;;;;;AAMzF,SAAgB,cAAc,KAAmC;CAC/D,MAAM,EAAE,OAAO,WAAW,IAAI,gBAAgB;CAC9C,MAAM,SAAS,IAAI,kBAAkB;CACrC,MAAM,OAAO,KAAK,IAAI,KAAK,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK;CACrD,MAAM,MAAM,KAAK,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,GAAG,MAAM;CACpD,MAAM,Q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MAAM,OAAO,OAAO,IAAI,OAAO;EAC/B,MAAM,MAAM,OAAO,IAAI,OAAO;EAC9B,MAAM,QAAQ,OAAO,OAAO,QAAQ;EACpC,MAAM,SAAS,MAAM,OAAO,SAAS;EAMrC,IAJE,QAAQ,KAAK,OAAO,UACpB,OAAO,KAAK,MAAM,UAClB,SAAS,KAAK,OAAO,KAAK,QAAQ,UAClC,UAAU,KAAK,MAAM,KAAK,SAAS,QACxB;EACb,IACE,KAAK,OAAO,KAAK,QAAQ,KAAK,OAAO,SAAS,GAC9C,KAAK,MAAM,KAAK,SAAS,KAAK,MAAM,UAAU,CAChD;CACF;;CAGA,SAAS,uBAA+B;EACtC,MAAM,OAAO,cAAc,GAAG;EAC9B,OAAO;GAAE,GAAG,KAAK,OAAO,KAAK,QAAQ;GAAG,GAAG,KAAK,MAAM,KAAK,SAAS;EAAE;CACxE;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","names":[],"sources":["../../../src/editor/views/actions.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"actions.d.ts","names":[],"sources":["../../../src/editor/views/actions.ts"],"mappings":";;;;;iBAkBgB,wBAAwB,KAAK,eAAe,UAAU;uBAAA;;;;;;;;;;;;;;;;EAWxC;EAQN;EAOD;EAIE;EAMD"}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { EDIT_VIEW, resolveEditorProfile } from "./profile.js";
|
|
2
|
-
import { createPresentationActions,
|
|
2
|
+
import { createPresentationActions, currentPlace, returnToPlace } from "./present.js";
|
|
3
3
|
import { createShaderModeActions } from "./shader.js";
|
|
4
4
|
//#region src/editor/views/actions.ts
|
|
5
|
+
/** The place a view put the canvas aside from, for a view that fits or scrolls it. */
|
|
6
|
+
function returnPlace(view) {
|
|
7
|
+
if (view.id === "present") return view.returnTo;
|
|
8
|
+
return view.id === "play" ? view.returnTo : null;
|
|
9
|
+
}
|
|
5
10
|
function createCanvasViewActions(ctx, viewport) {
|
|
6
11
|
function setCanvasView(view) {
|
|
7
12
|
const left = ctx.state.canvasView;
|
|
8
13
|
ctx.state.canvasView = view;
|
|
9
|
-
|
|
14
|
+
const back = left.id === view.id ? null : returnPlace(left);
|
|
15
|
+
if (back) returnToPlace(ctx, back, viewport);
|
|
10
16
|
ctx.requestRepaint();
|
|
11
17
|
}
|
|
12
18
|
/** Leaves the canvas's view for the one it returns to; false when there is none to leave. */
|
|
@@ -22,10 +28,11 @@ function createCanvasViewActions(ctx, viewport) {
|
|
|
22
28
|
ctx.state.hoveredNodeId = null;
|
|
23
29
|
setCanvasView({
|
|
24
30
|
id: "play",
|
|
25
|
-
revision: 0
|
|
31
|
+
revision: 0,
|
|
32
|
+
returnTo: currentPlace(ctx)
|
|
26
33
|
});
|
|
27
34
|
}
|
|
28
|
-
/** Go back to editing; the canvas draws every layer again. */
|
|
35
|
+
/** Go back to editing; the canvas draws every layer again where it looked before. */
|
|
29
36
|
function stopPlay() {
|
|
30
37
|
if (ctx.state.canvasView.id === "play") setCanvasView(EDIT_VIEW);
|
|
31
38
|
}
|
|
@@ -38,7 +45,8 @@ function createCanvasViewActions(ctx, viewport) {
|
|
|
38
45
|
const view = ctx.state.canvasView;
|
|
39
46
|
if (view.id === "play") ctx.state.canvasView = {
|
|
40
47
|
id: "play",
|
|
41
|
-
revision: view.revision + 1
|
|
48
|
+
revision: view.revision + 1,
|
|
49
|
+
returnTo: view.returnTo
|
|
42
50
|
};
|
|
43
51
|
}
|
|
44
52
|
ctx.onEditorEvent("graph:replaced", resetPlay);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","names":[],"sources":["../../../src/editor/views/actions.ts"],"sourcesContent":["import type { EditorContext } from '#core/editor/types'\n\nimport {\n createPresentationActions,\n
|
|
1
|
+
{"version":3,"file":"actions.js","names":[],"sources":["../../../src/editor/views/actions.ts"],"sourcesContent":["import type { EditorContext } from '#core/editor/types'\n\nimport {\n createPresentationActions,\n currentPlace,\n returnToPlace,\n type PresentationViewport\n} from './present'\nimport { EDIT_VIEW, resolveEditorProfile } from './profile'\nimport { createShaderModeActions } from './shader'\nimport type { CanvasView, ViewportPlace } from './types'\n\n/** The place a view put the canvas aside from, for a view that fits or scrolls it. */\nfunction returnPlace(view: CanvasView): ViewportPlace | null {\n if (view.id === 'present') return view.returnTo\n return view.id === 'play' ? view.returnTo : null\n}\n\nexport function createCanvasViewActions(ctx: EditorContext, viewport: PresentationViewport) {\n function setCanvasView(view: CanvasView): void {\n const left = ctx.state.canvasView\n ctx.state.canvasView = view\n // However a preview or presentation is left, the canvas returns to where it looked before it.\n const back = left.id === view.id ? null : returnPlace(left)\n if (back) returnToPlace(ctx, back, viewport)\n ctx.requestRepaint()\n }\n\n /** Leaves the canvas's view for the one it returns to; false when there is none to leave. */\n function leaveCanvasView(): boolean {\n const target = resolveEditorProfile(ctx.state).leaveTo\n if (!target) return false\n setCanvasView(target)\n return true\n }\n\n /** Preview this canvas: layers holding controls run as live components. */\n function startPlay(): void {\n if (ctx.state.canvasView.id === 'play') return\n ctx.state.hoveredNodeId = null\n setCanvasView({ id: 'play', revision: 0, returnTo: currentPlace(ctx) })\n }\n\n /** Go back to editing; the canvas draws every layer again where it looked before. */\n function stopPlay(): void {\n if (ctx.state.canvasView.id === 'play') setCanvasView(EDIT_VIEW)\n }\n\n function togglePlay(): void {\n if (ctx.state.canvasView.id === 'play') stopPlay()\n else startPlay()\n }\n\n /** Put every control back as designed by running the islands afresh. */\n function resetPlay(): void {\n const view = ctx.state.canvasView\n if (view.id === 'play') {\n ctx.state.canvasView = { id: 'play', revision: view.revision + 1, returnTo: view.returnTo }\n }\n }\n\n // Another document's layers start from their designed state, not from the old islands'.\n ctx.onEditorEvent('graph:replaced', resetPlay)\n\n const presentation = createPresentationActions(ctx, viewport, setCanvasView)\n const shaderMode = createShaderModeActions(ctx, setC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K,aAAa;CAE7D,OAAO;EACL;EACA;EACA;EACA;EACA;EACA,GAAG;EACH,GAAG;CACL;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CanvasView,
|
|
1
|
+
import { CanvasView, PresentationScale, ViewportCenter, ViewportPlace } from "./types.js";
|
|
2
2
|
import { EditorContext } from "../types.js";
|
|
3
3
|
import { createViewportActions } from "../viewport.js";
|
|
4
4
|
import { Rect, Size } from "@pairdraw/scene-graph/primitives";
|
|
@@ -20,11 +20,13 @@ interface PresentationState {
|
|
|
20
20
|
* that axis.
|
|
21
21
|
*/
|
|
22
22
|
declare function presentationViewport(slide: Rect, screen: Size, scale: PresentationScale, scrolledTo?: Pick<ViewportCenter, 'x' | 'y'>): ViewportCenter;
|
|
23
|
+
/** Where the canvas looked before a view replaces it, as the place to return to. */
|
|
24
|
+
declare function currentPlace(ctx: EditorContext): ViewportPlace;
|
|
23
25
|
/**
|
|
24
|
-
* Puts the canvas back where it looked before
|
|
26
|
+
* Puts the canvas back where it looked before a view took it elsewhere: its pan and zoom, so the
|
|
25
27
|
* editor's canvas, back at its own size, shows what it showed.
|
|
26
28
|
*/
|
|
27
|
-
declare function
|
|
29
|
+
declare function returnToPlace(ctx: EditorContext, place: ViewportPlace, viewport: PresentationViewport): void;
|
|
28
30
|
/**
|
|
29
31
|
* Presenting the page's slides, a slide at a time: the canvas runs as a preview and shows one
|
|
30
32
|
* slide, fitted or at 100%, and steps through the slides in the page's layer order. Leaving the
|
|
@@ -44,5 +46,5 @@ declare function createPresentationActions(ctx: EditorContext, viewport: Present
|
|
|
44
46
|
scrollPresentation: (dx: number, dy: number) => boolean;
|
|
45
47
|
};
|
|
46
48
|
//#endregion
|
|
47
|
-
export { PresentationState, PresentationViewport, createPresentationActions, presentationViewport,
|
|
49
|
+
export { PresentationState, PresentationViewport, createPresentationActions, currentPlace, presentationViewport, returnToPlace };
|
|
48
50
|
//# sourceMappingURL=present.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"present.d.ts","names":[],"sources":["../../../src/editor/views/present.ts"],"mappings":";;;;;;KAgBY,uBAAuB,KAAK,kBAAkB;;UAGzC;EACf;;EAEA;EACA;EACA,OAAO;;;;;;;;iBAmBO,qBACd,OAAO,MACP,QAAQ,MACR,OAAO,mBACP,aAAa,KAAK,6BACjB;;;;;
|
|
1
|
+
{"version":3,"file":"present.d.ts","names":[],"sources":["../../../src/editor/views/present.ts"],"mappings":";;;;;;KAgBY,uBAAuB,KAAK,kBAAkB;;UAGzC;EACf;;EAEA;EACA;EACA,OAAO;;;;;;;;iBAmBO,qBACd,OAAO,MACP,QAAQ,MACR,OAAO,mBACP,aAAa,KAAK,6BACjB;;iBA8Ba,aAAa,KAAK,gBAAgB;;;;;iBASlC,cACd,KAAK,eACL,OAAO,eACP,UAAU;;;;;;iBAgBI,0BACd,KAAK,eACL,UAAU,sBACV,gBAAgB,MAAM;;EAyBM,uBAAA;EAaS,oBAAA;EAsBR;EAIE;EAMA,eAAA;EA0BF;EAII;EAKI,uBAAA,OAAA;EAST;EAUI,qBAAA,YAAM"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { pageSlides } from "../bridges/frames.js";
|
|
2
|
+
import { visibleCanvas } from "../viewport.js";
|
|
2
3
|
import { getAxisAlignedWorldBounds } from "@pairdraw/scene-graph/coordinate";
|
|
3
4
|
//#region src/editor/views/present.ts
|
|
4
5
|
/**
|
|
@@ -36,16 +37,17 @@ function presentationViewport(slide, screen, scale, scrolledTo) {
|
|
|
36
37
|
zoom
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
|
-
/** The world point at the
|
|
40
|
+
/** The world point at the middle of the canvas the chrome leaves, as `centerOn` takes it back. */
|
|
40
41
|
function currentCenter(ctx) {
|
|
41
|
-
const
|
|
42
|
+
const area = visibleCanvas(ctx);
|
|
42
43
|
const { panX, panY, zoom } = ctx.state;
|
|
43
44
|
return {
|
|
44
|
-
x: (width / 2 - panX) / zoom,
|
|
45
|
-
y: (height / 2 - panY) / zoom,
|
|
45
|
+
x: (area.left + area.width / 2 - panX) / zoom,
|
|
46
|
+
y: (area.top + area.height / 2 - panY) / zoom,
|
|
46
47
|
zoom
|
|
47
48
|
};
|
|
48
49
|
}
|
|
50
|
+
/** Where the canvas looked before a view replaces it, as the place to return to. */
|
|
49
51
|
function currentPlace(ctx) {
|
|
50
52
|
const { panX, panY, zoom } = ctx.state;
|
|
51
53
|
return {
|
|
@@ -55,13 +57,13 @@ function currentPlace(ctx) {
|
|
|
55
57
|
};
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
58
|
-
* Puts the canvas back where it looked before
|
|
60
|
+
* Puts the canvas back where it looked before a view took it elsewhere: its pan and zoom, so the
|
|
59
61
|
* editor's canvas, back at its own size, shows what it showed.
|
|
60
62
|
*/
|
|
61
|
-
function
|
|
62
|
-
const
|
|
63
|
-
const { panX, panY, zoom } =
|
|
64
|
-
viewport.centerOn((width / 2 - panX) / zoom, (height / 2 - panY) / zoom, zoom);
|
|
63
|
+
function returnToPlace(ctx, place, viewport) {
|
|
64
|
+
const area = visibleCanvas(ctx);
|
|
65
|
+
const { panX, panY, zoom } = place;
|
|
66
|
+
viewport.centerOn((area.left + area.width / 2 - panX) / zoom, (area.top + area.height / 2 - panY) / zoom, zoom);
|
|
65
67
|
}
|
|
66
68
|
/**
|
|
67
69
|
* Presenting the page's slides, a slide at a time: the canvas runs as a preview and shows one
|
|
@@ -222,6 +224,6 @@ function createPresentationActions(ctx, viewport, setCanvasView) {
|
|
|
222
224
|
};
|
|
223
225
|
}
|
|
224
226
|
//#endregion
|
|
225
|
-
export { createPresentationActions, presentationViewport,
|
|
227
|
+
export { createPresentationActions, currentPlace, presentationViewport, returnToPlace };
|
|
226
228
|
|
|
227
229
|
//# sourceMappingURL=present.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"present.js","names":[],"sources":["../../../src/editor/views/present.ts"],"sourcesContent":["import { getAxisAlignedWorldBounds } from '@pairdraw/scene-graph/coordinate'\nimport type { Rect, Size } from '@pairdraw/scene-graph/primitives'\n\nimport { pageSlides } from '#core/editor/bridges/frames'\nimport type { EditorContext } from '#core/editor/types'\nimport type { createViewportActions } from '#core/editor/viewport'\n\nimport type {\n CanvasView,\n PresentationScale,\n PresentView,\n ViewportCenter,\n ViewportPlace\n} from './types'\n\n/** The viewport action a presentation moves the canvas with. */\nexport type PresentationViewport = Pick<ReturnType<typeof createViewportActions>, 'centerOn'>\n\n/** What a front end shows of a presentation: the slide on screen, its place, and its scale. */\nexport interface PresentationState {\n slideId: string\n /** The slide's place in the page's slide order, from 0. */\n index: number\n count: number\n scale: PresentationScale\n}\n\n/**\n * Where on one axis the screen's center goes: the slide's middle when the slide fits the screen,\n * otherwise as near `center` as keeps the screen inside the slide.\n */\nfunction clampAxis(start: number, extent: number, screen: number, zoom: number, center: number) {\n const visible = screen / zoom\n if (extent <= visible) return start + extent / 2\n return Math.min(Math.max(center, start + visible / 2), start + extent - visible / 2)\n}\n\n/**\n * Where a presentation puts the canvas for a slide: fitted, the whole slide centered as large as\n * the screen holds; at 100%, the screen kept inside the slide, from its top-left corner unless\n * `scrolledTo` says where it scrolled. A slide narrower or shorter than the screen centers on\n * that axis.\n */\nexport function presentationViewport(\n slide: Rect,\n screen: Size,\n scale: PresentationScale,\n scrolledTo?: Pick<ViewportCenter, 'x' | 'y'>\n): ViewportCenter {\n if (scale === 'fit') {\n const fitted = Math.min(screen.width / slide.width, screen.height / slide.height)\n return {\n x: slide.x + slide.width / 2,\n y: slide.y + slide.height / 2,\n zoom: Number.isFinite(fitted) && fitted > 0 ? fitted : 1\n }\n }\n const zoom = 1\n const center = scrolledTo ?? { x: -Infinity, y: -Infinity }\n return {\n x: clampAxis(slide.x, slide.width, screen.width, zoom, center.x),\n y: clampAxis(slide.y, slide.height, screen.height, zoom, center.y),\n zoom\n }\n}\n\n/** The world point at the screen's center and the zoom, as `centerOn` takes them back. */\nfunction currentCenter(ctx: EditorContext): ViewportCenter {\n const { width, height } = ctx.getViewportSize()\n const { panX, panY, zoom } = ctx.state\n return { x: (width / 2 - panX) / zoom, y: (height / 2 - panY) / zoom, zoom }\n}\n\nfunction currentPlace(ctx: EditorContext): ViewportPlace {\n const { panX, panY, zoom } = ctx.state\n return { panX, panY, zoom }\n}\n\n/**\n * Puts the canvas back where it looked before the presentation started: its pan and zoom, so the\n * editor's canvas, back at its own size, shows what it showed.\n */\nexport function returnFromPresentation(\n ctx: EditorContext,\n view: PresentView,\n viewport: PresentationViewport\n): void {\n const { width, height } = ctx.getViewportSize()\n const { panX, panY, zoom } = view.returnTo\n viewport.centerOn((width / 2 - panX) / zoom, (height / 2 - panY) / zoom, zoom)\n}\n\n/**\n * Presenting the page's slides, a slide at a time: the canvas runs as a preview and shows one\n * slide, fitted or at 100%, and steps through the slides in the page's layer order. Leaving the\n * presentation, by any way out of the view, returns the canvas to where it looked.\n */\nexport function createPresentationActions(\n ctx: EditorContext,\n viewport: PresentationViewport,\n setCanvasView: (view: CanvasView) => void\n) {\n function presented(): PresentView | null {\n const view = ctx.state.canvasView\n return view.id === 'present' ? view : null\n }\n\n /** The page's slides, in the order they are presented and exported. */\n function getSlides() {\n return pageSlides(ctx.graph, ctx.state.currentPageId)\n }\n\n function slideBounds(slideId: string): Rect | null {\n const node = ctx.graph.getNode(slideId)\n return node ? getAxisAlignedWorldBounds(node, ctx.graph) : null\n }\n\n function show(view: PresentView, scrolledTo?: Pick<ViewportCenter, 'x' | 'y'>) {\n const bounds = slideBounds(view.slideId)\n if (!bounds) return\n const target = presentationViewport(bounds, ctx.getViewportSize(), view.scale, scrolledTo)\n viewport.centerOn(target.x, target.y, target.zoom)\n }\n\n /** The presentation on this canvas, or null while it shows something else. */\n function getPresentation(): PresentationState | null {\n const view = presented()\n if (!view) return null\n const order = getSlides()\n const index = order.findIndex((slide) => slide.id === view.slideId)\n if (index === -1) return null\n return { slideId: view.slideId, index, count: order.length, scale: view.scale }\n }\n\n /**\n * Presents the page's slides from `slideId`, or from the slide holding the selection, or from\n * the first; false when the page has no slides.\n */\n function startPresentation(slideId?: string): boolean {\n const order = getSlides()\n if (order.length === 0) return false\n const ids = new Set(order.map((slide) => slide.id))\n const [selectedId] = ctx.state.selectedIds\n const holding = selectedId ? ctx.graph.closest(selectedId, (node) => ids.has(node.id)) : null\n const start = (slideId && ids.has(slideId) ? slideId : null) ?? holding?.id ?? order[0].id\n const current = presented()\n const view: PresentView = {\n id: 'present',\n revision: current?.revision ?? 0,\n slideId: start,\n scale: current?.scale ?? 'fit',\n returnTo: current?.returnTo ?? currentPlace(ctx)\n }\n ctx.state.hoveredNodeId = null\n setCanvasView(view)\n show(view)\n return true\n }\n\n /** Leaves the presentation for editing, back where the canvas looked before it. */\n function stopPresentation(): void {\n if (presented()) setCanvasView({ id: 'edit' })\n }\n\n function togglePresentation(): void {\n if (presented()) stopPresentation()\n else startPresentation()\n }\n\n /** Shows another slide of the presentation; false when there is none to show. */\n function presentSlide(slideId: string): boolean {\n const view = presented()\n if (!view || !getSlides().some((slide) => slide.id === slideId)) return false\n const next: PresentView = { ...view, slideId }\n setCanvasView(next)\n show(next)\n return true\n }\n\n /**\n * Steps to the next or previous slide; false at either end, where the presentation stays. A\n * slide removed while it was shown ends the presentation.\n */\n function presentAdjacentSlide(step: 1 | -1): boolean {\n const view = presented()\n if (!view) return false\n const order = getSlides()\n const index = order.findIndex((slide) => slide.id === view.slideId)\n if (index === -1) {\n stopPresentation()\n return false\n }\n const target = order.at(index + step)\n return index + step >= 0 && target ? presentSlide(target.id) : false\n }\n\n function presentNextSlide(): boolean {\n return presentAdjacentSlide(1)\n }\n\n function presentPreviousSlide(): boolean {\n return presentAdjacentSlide(-1)\n }\n\n /** Shows the slide fitted to the screen or at 100%. */\n function setPresentationScale(scale: PresentationScale): void {\n const view = presented()\n if (!view || view.scale === scale) return\n const next: PresentView = { ...view, scale }\n setCanvasView(next)\n show(next)\n }\n\n /** Puts the slide back in place, as after the screen changed size. */\n function fitPresentation(): void {\n const view = presented()\n if (!view) return\n show(view, view.scale === 'actual' ? currentCenter(ctx) : undefined)\n }\n\n /**\n * Scrolls a slide shown at 100% by screen pixels, within the slide; false when it is already\n * at that edge or fits the screen, so a front end can step to the next slide instead.\n */\n function scrollPresentation(dx: number, dy: number): boolean {\n const view = presented()\n if (view?.scale !== 'actual') return false\n const bounds = slideBounds(view.slideId)\n if (!bounds) return false\n const from = currentCenter(ctx)\n const target = presentationViewport(bounds, ctx.getViewportSize(), 'actual', {\n x: from.x + dx / from.zoom,\n y: from.y + dy / from.zoom\n })\n if (Math.abs(target.x - from.x) < 0.5 && Math.abs(target.y - from.y) < 0.5) return false\n viewport.centerOn(target.x, target.y, target.zoom)\n return true\n }\n\n // Another document has other slides, so its arrival ends the presentation; the canvas stays\n // where the new document puts it rather than returning to a place in the old one.\n ctx.onEditorEvent('graph:replaced', () => {\n if (!presented()) return\n ctx.state.canvasView = { id: 'edit' }\n ctx.requestRepaint()\n })\n\n return {\n getSlides,\n getPresentation,\n startPresentation,\n stopPresentation,\n togglePresentation,\n presentSlide,\n presentNextSlide,\n presentPreviousSlide,\n setPresentationScale,\n fitPresentation,\n scrollPresentation\n }\n}\n"],"mappings":";;;;;;;AA+BA,SAAS,UAAU,OAAe,QAAgB,QAAgB,MAAc,QAAgB;CAC9F,MAAM,UAAU,SAAS;CACzB,IAAI,UAAU,SAAS,OAAO,QAAQ,SAAS;CAC/C,OAAO,KAAK,IAAI,KAAK,IAAI,QAAQ,QAAQ,UAAU,CAAC,GAAG,QAAQ,SAAS,UAAU,CAAC;AACrF;;;;;;;AAQA,SAAgB,qBACd,OACA,QACA,OACA,YACgB;CAChB,IAAI,UAAU,OAAO;EACnB,MAAM,SAAS,KAAK,IAAI,OAAO,QAAQ,MAAM,OAAO,OAAO,SAAS,MAAM,MAAM;EAChF,OAAO;GACL,GAAG,MAAM,IAAI,MAAM,QAAQ;GAC3B,GAAG,MAAM,IAAI,MAAM,SAAS;GAC5B,MAAM,OAAO,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AU;GAC3E,GAAG,KAAK,IAAI,KAAK,KAAK;GACtB,GAAG,KAAK,IAAI,KAAK,KAAK;EACxB,CAAC;EACD,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,CAAC,IAAI,MAAO,KAAK,IAAI,OAAO,IAAI,KAAK,CAAC,IAAI,IAAK,OAAO;EACnF,SAAS,SAAS,OAAO,GAAG,OAAO,GAAG,OAAO,IAAI;EACjD,OAAO;CACT;CAIA,IAAI,cAAc,wBAAwB;EACxC,IAAI,CAAC,UAAU,GAAG;EAClB,IAAI,MAAM,aAAa,EAAE,IAAI,OAAO;EACpC,IAAI,eAAe;CACrB,CAAC;CAED,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"present.js","names":[],"sources":["../../../src/editor/views/present.ts"],"sourcesContent":["import { getAxisAlignedWorldBounds } from '@pairdraw/scene-graph/coordinate'\nimport type { Rect, Size } from '@pairdraw/scene-graph/primitives'\n\nimport { pageSlides } from '#core/editor/bridges/frames'\nimport type { EditorContext } from '#core/editor/types'\nimport { visibleCanvas, type createViewportActions } from '#core/editor/viewport'\n\nimport type {\n CanvasView,\n PresentationScale,\n PresentView,\n ViewportCenter,\n ViewportPlace\n} from './types'\n\n/** The viewport action a presentation moves the canvas with. */\nexport type PresentationViewport = Pick<ReturnType<typeof createViewportActions>, 'centerOn'>\n\n/** What a front end shows of a presentation: the slide on screen, its place, and its scale. */\nexport interface PresentationState {\n slideId: string\n /** The slide's place in the page's slide order, from 0. */\n index: number\n count: number\n scale: PresentationScale\n}\n\n/**\n * Where on one axis the screen's center goes: the slide's middle when the slide fits the screen,\n * otherwise as near `center` as keeps the screen inside the slide.\n */\nfunction clampAxis(start: number, extent: number, screen: number, zoom: number, center: number) {\n const visible = screen / zoom\n if (extent <= visible) return start + extent / 2\n return Math.min(Math.max(center, start + visible / 2), start + extent - visible / 2)\n}\n\n/**\n * Where a presentation puts the canvas for a slide: fitted, the whole slide centered as large as\n * the screen holds; at 100%, the screen kept inside the slide, from its top-left corner unless\n * `scrolledTo` says where it scrolled. A slide narrower or shorter than the screen centers on\n * that axis.\n */\nexport function presentationViewport(\n slide: Rect,\n screen: Size,\n scale: PresentationScale,\n scrolledTo?: Pick<ViewportCenter, 'x' | 'y'>\n): ViewportCenter {\n if (scale === 'fit') {\n const fitted = Math.min(screen.width / slide.width, screen.height / slide.height)\n return {\n x: slide.x + slide.width / 2,\n y: slide.y + slide.height / 2,\n zoom: Number.isFinite(fitted) && fitted > 0 ? fitted : 1\n }\n }\n const zoom = 1\n const center = scrolledTo ?? { x: -Infinity, y: -Infinity }\n return {\n x: clampAxis(slide.x, slide.width, screen.width, zoom, center.x),\n y: clampAxis(slide.y, slide.height, screen.height, zoom, center.y),\n zoom\n }\n}\n\n/** The world point at the middle of the canvas the chrome leaves, as `centerOn` takes it back. */\nfunction currentCenter(ctx: EditorContext): ViewportCenter {\n const area = visibleCanvas(ctx)\n const { panX, panY, zoom } = ctx.state\n return {\n x: (area.left + area.width / 2 - panX) / zoom,\n y: (area.top + area.height / 2 - panY) / zoom,\n zoom\n }\n}\n\n/** Where the canvas looked before a view replaces it, as the place to return to. */\nexport function currentPlace(ctx: EditorContext): ViewportPlace {\n const { panX, panY, zoom } = ctx.state\n return { panX, panY, zoom }\n}\n\n/**\n * Puts the canvas back where it looked before a view took it elsewhere: its pan and zoom, so the\n * editor's canvas, back at its own size, shows what it showed.\n */\nexport function returnToPlace(\n ctx: EditorContext,\n place: ViewportPlace,\n viewport: PresentationViewport\n): void {\n const area = visibleCanvas(ctx)\n const { panX, panY, zoom } = place\n viewport.centerOn(\n (area.left + area.width / 2 - panX) / zoom,\n (area.top + area.height / 2 - panY) / zoom,\n zoom\n )\n}\n\n/**\n * Presenting the page's slides, a slide at a time: the canvas runs as a preview and shows one\n * slide, fitted or at 100%, and steps through the slides in the page's layer order. Leaving the\n * presentation, by any way out of the view, returns the canvas to where it looked.\n */\nexport function createPresentationActions(\n ctx: EditorContext,\n viewport: PresentationViewport,\n setCanvasView: (view: CanvasView) => void\n) {\n function presented(): PresentView | null {\n const view = ctx.state.canvasView\n return view.id === 'present' ? view : null\n }\n\n /** The page's slides, in the order they are presented and exported. */\n function getSlides() {\n return pageSlides(ctx.graph, ctx.state.currentPageId)\n }\n\n function slideBounds(slideId: string): Rect | null {\n const node = ctx.graph.getNode(slideId)\n return node ? getAxisAlignedWorldBounds(node, ctx.graph) : null\n }\n\n function show(view: PresentView, scrolledTo?: Pick<ViewportCenter, 'x' | 'y'>) {\n const bounds = slideBounds(view.slideId)\n if (!bounds) return\n const target = presentationViewport(bounds, ctx.getViewportSize(), view.scale, scrolledTo)\n viewport.centerOn(target.x, target.y, target.zoom)\n }\n\n /** The presentation on this canvas, or null while it shows something else. */\n function getPresentation(): PresentationState | null {\n const view = presented()\n if (!view) return null\n const order = getSlides()\n const index = order.findIndex((slide) => slide.id === view.slideId)\n if (index === -1) return null\n return { slideId: view.slideId, index, count: order.length, scale: view.scale }\n }\n\n /**\n * Presents the page's slides from `slideId`, or from the slide holding the selection, or from\n * the first; false when the page has no slides.\n */\n function startPresentation(slideId?: string): boolean {\n const order = getSlides()\n if (order.length === 0) return false\n const ids = new Set(order.map((slide) => slide.id))\n const [selectedId] = ctx.state.selectedIds\n const holding = selectedId ? ctx.graph.closest(selectedId, (node) => ids.has(node.id)) : null\n const start = (slideId && ids.has(slideId) ? slideId : null) ?? holding?.id ?? order[0].id\n const current = presented()\n const view: PresentView = {\n id: 'present',\n revision: current?.revision ?? 0,\n slideId: start,\n scale: current?.scale ?? 'fit',\n returnTo: current?.returnTo ?? currentPlace(ctx)\n }\n ctx.state.hoveredNodeId = null\n setCanvasView(view)\n show(view)\n return true\n }\n\n /** Leaves the presentation for editing, back where the canvas looked before it. */\n function stopPresentation(): void {\n if (presented()) setCanvasView({ id: 'edit' })\n }\n\n function togglePresentation(): void {\n if (presented()) stopPresentation()\n else startPresentation()\n }\n\n /** Shows another slide of the presentation; false when there is none to show. */\n function presentSlide(slideId: string): boolean {\n const view = presented()\n if (!view || !getSlides().some((slide) => slide.id === slideId)) return false\n const next: PresentView = { ...view, slideId }\n setCanvasView(next)\n show(next)\n return true\n }\n\n /**\n * Steps to the next or previous slide; false at either end, where the presentation stays. A\n * slide removed while it was shown ends the presentation.\n */\n function presentAdjacentSlide(step: 1 | -1): boolean {\n const view = presented()\n if (!view) return false\n const order = getSlides()\n const index = order.findIndex((slide) => slide.id === view.slideId)\n if (index === -1) {\n stopPresentation()\n return false\n }\n const target = order.at(index + step)\n return index + step >= 0 && target ? presentSlide(target.id) : false\n }\n\n function presentNextSlide(): boolean {\n return presentAdjacentSlide(1)\n }\n\n function presentPreviousSlide(): boolean {\n return presentAdjacentSlide(-1)\n }\n\n /** Shows the slide fitted to the screen or at 100%. */\n function setPresentationScale(scale: PresentationScale): void {\n const view = presented()\n if (!view || view.scale === scale) return\n const next: PresentView = { ...view, scale }\n setCanvasView(next)\n show(next)\n }\n\n /** Puts the slide back in place, as after the screen changed size. */\n function fitPresentation(): void {\n const view = presented()\n if (!view) return\n show(view, view.scale === 'actual' ? currentCenter(ctx) : undefined)\n }\n\n /**\n * Scrolls a slide shown at 100% by screen pixels, within the slide; false when it is already\n * at that edge or fits the screen, so a front end can step to the next slide instead.\n */\n function scrollPresentation(dx: number, dy: number): boolean {\n const view = presented()\n if (view?.scale !== 'actual') return false\n const bounds = slideBounds(view.slideId)\n if (!bounds) return false\n const from = currentCenter(ctx)\n const target = presentationViewport(bounds, ctx.getViewportSize(), 'actual', {\n x: from.x + dx / from.zoom,\n y: from.y + dy / from.zoom\n })\n if (Math.abs(target.x - from.x) < 0.5 && Math.abs(target.y - from.y) < 0.5) return false\n viewport.centerOn(target.x, target.y, target.zoom)\n return true\n }\n\n // Another document has other slides, so its arrival ends the presentation; the canvas stays\n // where the new document puts it rather than returning to a place in the old one.\n ctx.onEditorEvent('graph:replaced', () => {\n if (!presented()) return\n ctx.state.canvasView = { id: 'edit' }\n ctx.requestRepaint()\n })\n\n return {\n getSlides,\n getPresentation,\n startPresentation,\n stopPresentation,\n togglePresentation,\n presentSlide,\n presentNextSlide,\n presentPreviousSlide,\n setPresentationScale,\n fitPresentation,\n scrollPresentation\n }\n}\n"],"mappings":";;;;;;;;AA+BA,SAAS,UAAU,OAAe,QAAgB,QAAgB,MAAc,QAAgB;CAC9F,MAAM,UAAU,SAAS;CACzB,IAAI,UAAU,SAAS,OAAO,QAAQ,SAAS;CAC/C,OAAO,KAAK,IAAI,KAAK,IAAI,QAAQ,QAAQ,UAAU,CAAC,GAAG,QAAQ,SAAS,UAAU,CAAC;AACrF;;;;;;;AAQA,SAAgB,qBACd,OACA,QACA,OACA,YACgB;CAChB,IAAI,UAAU,OAAO;EACnB,MAAM,SAAS,KAAK,IAAI,OAAO,QAAQ,MAAM,OAAO,OAAO,SAAS,MAAM,MAAM;EAChF,OAAO;GACL,GAAG,MAAM,IAAI,MAAM,QAAQ;GAC3B,GAAG,MAAM,IAAI,MAAM,SAAS;GAC5B,MAAM,OAAO,SAAS,MAAM,KAAK,SAAS,IAAI,SAAS;EACzD;CACF;CACA,MAAM,OAAO;CACb,MAAM,SAAS,cAAc;EAAE,GAAG;EAAW,GAAG;CAAU;CAC1D,OAAO;EACL,GAAG,UAAU,MAAM,GAAG,MAAM,OAAO,OAAO,OAAO,MAAM,OAAO,CAAC;EAC/D,GAAG,UAAU,MAAM,GAAG,MAAM,QAAQ,OAAO,QAAQ,MAAM,OAAO,CAAC;EACjE;CACF;AACF;;AAGA,SAAS,cAAc,KAAoC;CACzD,MAAM,OAAO,cAAc,GAAG;CAC9B,MAAM,EAAE,MAAM,MAAM,SAAS,IAAI;CACjC,OAAO;EACL,IAAI,KAAK,OAAO,KAAK,QAAQ,IAAI,QAAQ;EACzC,IAAI,KAAK,MAAM,KAAK,SAAS,IAAI,QAAQ;EACzC;CACF;AACF;;AAGA,SAAgB,aAAa,KAAmC;CAC9D,MAAM,EAAE,MAAM,MA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