@pairdraw/core 0.21.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/boolean.d.ts +6 -1
- package/dist/canvas/boolean.d.ts.map +1 -1
- package/dist/canvas/boolean.js +10 -2
- package/dist/canvas/boolean.js.map +1 -1
- package/dist/canvas/color-space.d.ts +45 -0
- package/dist/canvas/color-space.d.ts.map +1 -0
- package/dist/canvas/color-space.js +39 -0
- package/dist/canvas/color-space.js.map +1 -0
- package/dist/canvas/fills.d.ts +10 -10
- package/dist/canvas/fills.d.ts.map +1 -1
- package/dist/canvas/fills.js +116 -62
- package/dist/canvas/fills.js.map +1 -1
- package/dist/canvas/flatten.d.ts +11 -3
- package/dist/canvas/flatten.d.ts.map +1 -1
- package/dist/canvas/flatten.js +62 -4
- package/dist/canvas/flatten.js.map +1 -1
- package/dist/canvas/index.d.ts +2 -1
- package/dist/canvas/index.js +2 -1
- package/dist/canvas/layout-grids.d.ts +5 -2
- package/dist/canvas/layout-grids.d.ts.map +1 -1
- package/dist/canvas/layout-grids.js +7 -2
- package/dist/canvas/layout-grids.js.map +1 -1
- package/dist/canvas/noise/render.d.ts +17 -4
- package/dist/canvas/noise/render.d.ts.map +1 -1
- package/dist/canvas/noise/render.js +21 -6
- package/dist/canvas/noise/render.js.map +1 -1
- package/dist/canvas/noise/shader.d.ts +4 -4
- package/dist/canvas/noise/shader.d.ts.map +1 -1
- package/dist/canvas/noise/shader.js +5 -6
- package/dist/canvas/noise/shader.js.map +1 -1
- package/dist/canvas/overlays/annotations.d.ts +19 -0
- package/dist/canvas/overlays/annotations.d.ts.map +1 -0
- package/dist/canvas/overlays/annotations.js +110 -0
- package/dist/canvas/overlays/annotations.js.map +1 -0
- package/dist/canvas/overlays/auto-layout-hover.d.ts +11 -1
- package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
- package/dist/canvas/overlays/auto-layout-hover.js +25 -1
- package/dist/canvas/overlays/auto-layout-hover.js.map +1 -1
- package/dist/canvas/overlays/feedback.js +1 -1
- package/dist/canvas/overlays/feedback.js.map +1 -1
- package/dist/canvas/overlays/index.d.ts +2 -2
- package/dist/canvas/overlays/index.js +2 -2
- package/dist/canvas/overlays/measurement.d.ts +7 -1
- package/dist/canvas/overlays/measurement.d.ts.map +1 -1
- package/dist/canvas/overlays/measurement.js +42 -4
- package/dist/canvas/overlays/measurement.js.map +1 -1
- package/dist/canvas/overlays/presence.d.ts.map +1 -1
- package/dist/canvas/overlays/presence.js +21 -24
- package/dist/canvas/overlays/presence.js.map +1 -1
- package/dist/canvas/renderer/colors.d.ts +7 -1
- package/dist/canvas/renderer/colors.d.ts.map +1 -1
- package/dist/canvas/renderer/colors.js +9 -1
- package/dist/canvas/renderer/colors.js.map +1 -1
- package/dist/canvas/renderer/document-surface.d.ts +15 -6
- package/dist/canvas/renderer/document-surface.d.ts.map +1 -1
- package/dist/canvas/renderer/document-surface.js +1 -0
- package/dist/canvas/renderer/document-surface.js.map +1 -1
- package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +2 -2
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts +1 -0
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +4 -1
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
- package/dist/canvas/renderer/overlay-pass.js +6 -1
- package/dist/canvas/renderer/overlay-pass.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +7 -0
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/types.d.ts +10 -0
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer.d.ts +10 -2
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +15 -3
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +9 -9
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/shaders/compile.d.ts +3 -1
- package/dist/canvas/shaders/compile.d.ts.map +1 -1
- package/dist/canvas/shaders/compile.js +12 -3
- package/dist/canvas/shaders/compile.js.map +1 -1
- package/dist/canvas/shaders/draw.d.ts.map +1 -1
- package/dist/canvas/shaders/draw.js +10 -3
- package/dist/canvas/shaders/draw.js.map +1 -1
- package/dist/canvas/shaders/effect.d.ts.map +1 -1
- package/dist/canvas/shaders/effect.js +6 -16
- package/dist/canvas/shaders/effect.js.map +1 -1
- package/dist/clipboard/pairdraw.d.ts.map +1 -1
- package/dist/clipboard/pairdraw.js +1 -0
- package/dist/clipboard/pairdraw.js.map +1 -1
- package/dist/editor/bridges/clipboard.d.ts +2 -0
- package/dist/editor/bridges/clipboard.d.ts.map +1 -1
- package/dist/editor/bridges/clipboard.js +1 -0
- package/dist/editor/bridges/clipboard.js.map +1 -1
- package/dist/editor/bridges/components.d.ts +14 -7
- package/dist/editor/bridges/components.d.ts.map +1 -1
- package/dist/editor/bridges/components.js +6 -0
- package/dist/editor/bridges/components.js.map +1 -1
- package/dist/editor/bridges/structure.d.ts +1 -1
- package/dist/editor/bridges/structure.d.ts.map +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/clipboard/code.d.ts +32 -0
- package/dist/editor/clipboard/code.d.ts.map +1 -0
- package/dist/editor/clipboard/code.js +30 -0
- package/dist/editor/clipboard/code.js.map +1 -0
- package/dist/editor/clipboard/export.js +2 -2
- package/dist/editor/clipboard/export.js.map +1 -1
- package/dist/editor/clipboard/paste/dependencies.d.ts +14 -0
- package/dist/editor/clipboard/paste/dependencies.d.ts.map +1 -0
- package/dist/editor/clipboard/paste/dependencies.js +0 -0
- package/dist/editor/clipboard/paste/run.d.ts +14 -0
- package/dist/editor/clipboard/paste/run.d.ts.map +1 -0
- package/dist/editor/clipboard/paste/run.js +47 -0
- package/dist/editor/clipboard/paste/run.js.map +1 -0
- package/dist/editor/clipboard/styled.d.ts +2 -8
- package/dist/editor/clipboard/styled.d.ts.map +1 -1
- package/dist/editor/clipboard/styled.js +2 -32
- package/dist/editor/clipboard/styled.js.map +1 -1
- package/dist/editor/clipboard.d.ts +2 -0
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +34 -0
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/components/instances.d.ts +5 -0
- package/dist/editor/components/instances.d.ts.map +1 -1
- package/dist/editor/components/instances.js +69 -4
- package/dist/editor/components/instances.js.map +1 -1
- package/dist/editor/components/slots/index.d.ts.map +1 -1
- package/dist/editor/components/slots/index.js +7 -0
- package/dist/editor/components/slots/index.js.map +1 -1
- package/dist/editor/components.d.ts +6 -0
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor/components.js +14 -2
- package/dist/editor/components.js.map +1 -1
- package/dist/editor/create.d.ts +30 -3
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +11 -2
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/design-tokens.d.ts +1 -1
- package/dist/editor/design-tokens.d.ts.map +1 -1
- package/dist/editor/design-tokens.js +4 -18
- package/dist/editor/design-tokens.js.map +1 -1
- package/dist/editor/image-edit.d.ts.map +1 -1
- package/dist/editor/image-edit.js +1 -2
- package/dist/editor/image-edit.js.map +1 -1
- package/dist/editor/index.d.ts +4 -4
- package/dist/editor/index.js +1 -1
- package/dist/editor/layout-mode.d.ts +3 -1
- package/dist/editor/layout-mode.d.ts.map +1 -1
- package/dist/editor/layout-mode.js +97 -2
- package/dist/editor/layout-mode.js.map +1 -1
- package/dist/editor/nodes.d.ts +2 -0
- package/dist/editor/nodes.d.ts.map +1 -1
- package/dist/editor/nodes.js +22 -7
- package/dist/editor/nodes.js.map +1 -1
- package/dist/editor/read-only/actions.js +6 -0
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/selection/overlays.d.ts +1 -0
- package/dist/editor/selection/overlays.d.ts.map +1 -1
- package/dist/editor/selection/overlays.js +7 -0
- package/dist/editor/selection/overlays.js.map +1 -1
- package/dist/editor/selection/read.d.ts +8 -0
- package/dist/editor/selection.d.ts +9 -0
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/state/shared.js +1 -0
- package/dist/editor/state/shared.js.map +1 -1
- package/dist/editor/state/view.d.ts.map +1 -1
- package/dist/editor/state/view.js +2 -0
- package/dist/editor/state/view.js.map +1 -1
- package/dist/editor/structure/boolean.d.ts +1 -1
- package/dist/editor/structure/boolean.d.ts.map +1 -1
- package/dist/editor/structure/boolean.js +20 -1
- package/dist/editor/structure/boolean.js.map +1 -1
- package/dist/editor/structure/container-wrap.d.ts +8 -2
- package/dist/editor/structure/container-wrap.d.ts.map +1 -1
- package/dist/editor/structure/container-wrap.js +17 -5
- package/dist/editor/structure/container-wrap.js.map +1 -1
- package/dist/editor/structure/flatten.d.ts.map +1 -1
- package/dist/editor/structure/flatten.js +8 -7
- package/dist/editor/structure/flatten.js.map +1 -1
- package/dist/editor/structure/group/ungroup.d.ts.map +1 -1
- package/dist/editor/structure/group/ungroup.js +2 -0
- package/dist/editor/structure/group/ungroup.js.map +1 -1
- package/dist/editor/structure/outline-stroke.d.ts.map +1 -1
- package/dist/editor/structure/outline-stroke.js +5 -0
- package/dist/editor/structure/outline-stroke.js.map +1 -1
- package/dist/editor/structure.d.ts +1 -1
- package/dist/editor/structure.d.ts.map +1 -1
- package/dist/editor/styles.d.ts +26 -0
- package/dist/editor/styles.d.ts.map +1 -0
- package/dist/editor/styles.js +127 -0
- package/dist/editor/styles.js.map +1 -0
- package/dist/editor/text/selection-style.d.ts +1 -0
- package/dist/editor/text/selection-style.d.ts.map +1 -1
- package/dist/editor/text/selection-style.js +10 -2
- package/dist/editor/text/selection-style.js.map +1 -1
- package/dist/editor/tool-registry.d.ts.map +1 -1
- package/dist/editor/tool-registry.js +6 -0
- package/dist/editor/tool-registry.js.map +1 -1
- package/dist/editor/types.d.ts +14 -2
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/variable-bindings.d.ts.map +1 -1
- package/dist/editor/variable-bindings.js +6 -1
- package/dist/editor/variable-bindings.js.map +1 -1
- package/dist/figma-api/accessors/basic.d.ts.map +1 -1
- package/dist/figma-api/accessors/basic.js +22 -1
- package/dist/figma-api/accessors/basic.js.map +1 -1
- package/dist/figma-api/accessors/shape.js +1 -1
- package/dist/figma-api/accessors/text/index.js +1 -1
- package/dist/figma-api/accessors/text/ranges.js +1 -1
- package/dist/figma-api/accessors/text/references.js +1 -1
- package/dist/figma-api/accessors/variables.js +1 -1
- package/dist/figma-api/accessors/vector.d.ts.map +1 -1
- package/dist/figma-api/accessors/vector.js +8 -22
- package/dist/figma-api/accessors/vector.js.map +1 -1
- package/dist/figma-api/accessors/visual.js +1 -1
- package/dist/figma-api/compatibility.d.ts +1 -1
- package/dist/figma-api/compatibility.d.ts.map +1 -1
- package/dist/figma-api/component-scope.d.ts +14 -0
- package/dist/figma-api/component-scope.d.ts.map +1 -0
- package/dist/figma-api/component-scope.js +28 -0
- package/dist/figma-api/component-scope.js.map +1 -0
- package/dist/figma-api/components.d.ts.map +1 -1
- package/dist/figma-api/components.js +26 -2
- package/dist/figma-api/components.js.map +1 -1
- package/dist/figma-api/flatten.js +3 -3
- package/dist/figma-api/flatten.js.map +1 -1
- package/dist/figma-api/index.d.ts +77 -6
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +188 -2
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/node-types.d.ts +2 -1
- package/dist/figma-api/node-types.d.ts.map +1 -1
- package/dist/figma-api/overrides.d.ts +26 -1
- package/dist/figma-api/overrides.d.ts.map +1 -1
- package/dist/figma-api/overrides.js +157 -10
- package/dist/figma-api/overrides.js.map +1 -1
- package/dist/figma-api/proxy.d.ts +2 -0
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +10 -2
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +61 -5
- package/dist/figma-api/reactions.d.ts.map +1 -1
- package/dist/figma-api/reactions.js +144 -11
- package/dist/figma-api/reactions.js.map +1 -1
- package/dist/figma-api/shape-with-text.js +1 -1
- package/dist/figma-api/slots.d.ts +3 -1
- package/dist/figma-api/slots.d.ts.map +1 -1
- package/dist/figma-api/slots.js +9 -8
- package/dist/figma-api/slots.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/io/formats/code/detect.d.ts +23 -0
- package/dist/io/formats/code/detect.d.ts.map +1 -0
- package/dist/io/formats/code/detect.js +46 -0
- package/dist/io/formats/code/detect.js.map +1 -0
- package/dist/io/formats/code/index.d.ts +5 -0
- package/dist/io/formats/code/index.js +5 -0
- package/dist/io/formats/code/read.d.ts +45 -0
- package/dist/io/formats/code/read.d.ts.map +1 -0
- package/dist/io/formats/code/read.js +86 -0
- package/dist/io/formats/code/read.js.map +1 -0
- package/dist/io/formats/code/stylesheet.d.ts +13 -0
- package/dist/io/formats/code/stylesheet.d.ts.map +1 -0
- package/dist/io/formats/code/stylesheet.js +21 -0
- package/dist/io/formats/code/stylesheet.js.map +1 -0
- package/dist/io/formats/code/tokens.d.ts +18 -0
- package/dist/io/formats/code/tokens.d.ts.map +1 -0
- package/dist/io/formats/code/tokens.js +135 -0
- package/dist/io/formats/code/tokens.js.map +1 -0
- package/dist/io/formats/design-tokens/apply.d.ts +7 -3
- package/dist/io/formats/design-tokens/apply.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/apply.js.map +1 -1
- package/dist/io/formats/drawio/warnings.d.ts +17 -2
- package/dist/io/formats/drawio/warnings.d.ts.map +1 -1
- package/dist/io/formats/drawio/warnings.js +14 -7
- package/dist/io/formats/drawio/warnings.js.map +1 -1
- package/dist/io/formats/fig/export/patch/fields.js +5 -0
- package/dist/io/formats/fig/export/patch/fields.js.map +1 -1
- package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/patch/index.js +20 -20
- package/dist/io/formats/fig/export/patch/index.js.map +1 -1
- package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
- package/dist/io/formats/fig/export/setup.js +5 -1
- package/dist/io/formats/fig/export/setup.js.map +1 -1
- package/dist/io/formats/fig/index.d.ts +3 -2
- package/dist/io/formats/fig/index.js +2 -2
- package/dist/io/formats/fig/read.d.ts.map +1 -1
- package/dist/io/formats/fig/read.js +5 -2
- package/dist/io/formats/fig/read.js.map +1 -1
- package/dist/io/formats/html/index.d.ts +1 -0
- package/dist/io/formats/html/index.d.ts.map +1 -1
- package/dist/io/formats/html/index.js +5 -3
- package/dist/io/formats/html/index.js.map +1 -1
- package/dist/io/formats/html/layers.d.ts +3 -1
- package/dist/io/formats/html/layers.d.ts.map +1 -1
- package/dist/io/formats/html/layers.js +6 -1
- package/dist/io/formats/html/layers.js.map +1 -1
- package/dist/io/formats/pdf/export.d.ts.map +1 -1
- package/dist/io/formats/pdf/export.js +7 -3
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/pdf/plan.d.ts +3 -0
- package/dist/io/formats/pdf/plan.d.ts.map +1 -1
- package/dist/io/formats/pdf/plan.js +60 -36
- package/dist/io/formats/pdf/plan.js.map +1 -1
- package/dist/io/formats/pen/index.d.ts.map +1 -1
- package/dist/io/formats/pen/index.js +13 -4
- package/dist/io/formats/pen/index.js.map +1 -1
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +3 -2
- package/dist/io/formats/raster/headless.js.map +1 -1
- package/dist/io/formats/raster/index.d.ts +2 -2
- package/dist/io/formats/raster/index.js +2 -2
- package/dist/io/formats/raster/render.d.ts +10 -2
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +35 -9
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +19 -1
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts +5 -2
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +59 -10
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/index.d.ts +2 -2
- package/dist/io/formats/svg/index.js +2 -2
- package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
- package/dist/io/formats/svg/text/layout.js +4 -2
- package/dist/io/formats/svg/text/layout.js.map +1 -1
- package/dist/io/formats/video/record.d.ts.map +1 -1
- package/dist/io/formats/video/record.js +24 -9
- package/dist/io/formats/video/record.js.map +1 -1
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +30 -17
- package/dist/io/formats.js.map +1 -1
- package/dist/io/index.d.ts +2 -2
- package/dist/io/types.d.ts +11 -2
- package/dist/io/types.d.ts.map +1 -1
- package/dist/kiwi/fig/population/client.d.ts.map +1 -1
- package/dist/kiwi/fig/population/client.js +2 -1
- package/dist/kiwi/fig/population/client.js.map +1 -1
- package/dist/kiwi/fig/session/document-state.d.ts +46 -2
- package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
- package/dist/kiwi/fig/session/document-state.js +113 -5
- package/dist/kiwi/fig/session/document-state.js.map +1 -1
- package/dist/kiwi/fig/session/options.d.ts +4 -0
- package/dist/kiwi/fig/session/options.d.ts.map +1 -1
- package/dist/kiwi/fig/session/options.js.map +1 -1
- package/dist/layout/apply.d.ts.map +1 -1
- package/dist/layout/apply.js +8 -4
- package/dist/layout/apply.js.map +1 -1
- package/dist/layout/auto-layout-handles.js +1 -1
- package/dist/layout/auto-layout-handles.js.map +1 -1
- package/dist/layout/axis-sizing.d.ts.map +1 -1
- package/dist/layout/axis-sizing.js +1 -1
- package/dist/layout/axis-sizing.js.map +1 -1
- package/dist/layout/derived.d.ts.map +1 -1
- package/dist/layout/derived.js +1 -1
- package/dist/layout/derived.js.map +1 -1
- package/dist/layout/effective-generated-text.js +1 -1
- package/dist/layout/effective-generated-text.js.map +1 -1
- package/dist/layout/grid.d.ts +3 -1
- package/dist/layout/grid.d.ts.map +1 -1
- package/dist/layout/grid.js +57 -16
- package/dist/layout/grid.js.map +1 -1
- package/dist/layout.d.ts +1 -1
- package/dist/layout.js +6 -5
- package/dist/layout.js.map +1 -1
- package/dist/node/fs.d.ts.map +1 -1
- package/dist/node/fs.js +28 -7
- package/dist/node/fs.js.map +1 -1
- package/dist/prototype/easing.d.ts +13 -5
- package/dist/prototype/easing.d.ts.map +1 -1
- package/dist/prototype/easing.js +46 -6
- package/dist/prototype/easing.js.map +1 -1
- package/dist/prototype/scenes.d.ts +31 -0
- package/dist/prototype/scenes.d.ts.map +1 -1
- package/dist/prototype/scenes.js +220 -31
- package/dist/prototype/scenes.js.map +1 -1
- package/dist/prototype/session.d.ts.map +1 -1
- package/dist/prototype/session.js +1 -0
- package/dist/prototype/session.js.map +1 -1
- package/dist/prototype/smart-animate/animation.d.ts +2 -1
- package/dist/prototype/smart-animate/animation.d.ts.map +1 -1
- package/dist/prototype/smart-animate/animation.js +2 -2
- package/dist/prototype/smart-animate/animation.js.map +1 -1
- package/dist/prototype/timeline.d.ts +10 -1
- package/dist/prototype/timeline.d.ts.map +1 -1
- package/dist/prototype/timeline.js +69 -23
- package/dist/prototype/timeline.js.map +1 -1
- package/dist/prototype/variables.d.ts +23 -0
- package/dist/prototype/variables.d.ts.map +1 -0
- package/dist/prototype/variables.js +237 -0
- package/dist/prototype/variables.js.map +1 -0
- package/dist/rpc/read-commands.d.ts +5 -0
- package/dist/rpc/read-commands.d.ts.map +1 -1
- package/dist/rpc/read-commands.js +4 -1
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/text/character-style.d.ts +8 -1
- package/dist/text/character-style.d.ts.map +1 -1
- package/dist/text/character-style.js +39 -1
- package/dist/text/character-style.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +2 -2
- package/dist/tools/create/basic.js +3 -4
- package/dist/tools/create/basic.js.map +1 -1
- package/dist/tools/create/behaviours.js +1 -1
- package/dist/tools/create/code.d.ts +6 -0
- package/dist/tools/create/code.d.ts.map +1 -0
- package/dist/tools/create/code.js +68 -0
- package/dist/tools/create/code.js.map +1 -0
- package/dist/tools/create/html.d.ts.map +1 -1
- package/dist/tools/create/html.js +9 -57
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.js +1 -1
- package/dist/tools/create/inputs.d.ts +11 -0
- package/dist/tools/create/inputs.d.ts.map +1 -0
- package/dist/tools/create/inputs.js +15 -0
- package/dist/tools/create/inputs.js.map +1 -0
- package/dist/tools/create/mermaid.d.ts.map +1 -1
- package/dist/tools/create/mermaid.js +5 -6
- package/dist/tools/create/mermaid.js.map +1 -1
- package/dist/tools/create/place.d.ts +30 -0
- package/dist/tools/create/place.d.ts.map +1 -0
- package/dist/tools/create/place.js +70 -0
- package/dist/tools/create/place.js.map +1 -0
- package/dist/tools/create/render.js +1 -1
- package/dist/tools/create/svg.js +1 -1
- package/dist/tools/create/vector.js +1 -1
- package/dist/tools/create.d.ts +2 -1
- package/dist/tools/create.js +2 -1
- package/dist/tools/css/gradient.d.ts +28 -0
- package/dist/tools/css/gradient.d.ts.map +1 -0
- package/dist/tools/css/gradient.js +118 -0
- package/dist/tools/css/gradient.js.map +1 -0
- package/dist/tools/image-ai/generate.js +1 -1
- package/dist/tools/modify/geometry.js +5 -5
- package/dist/tools/modify/geometry.js.map +1 -1
- package/dist/tools/modify/layout.d.ts.map +1 -1
- package/dist/tools/modify/layout.js +7 -1
- package/dist/tools/modify/layout.js.map +1 -1
- package/dist/tools/modify/matching.js +1 -1
- package/dist/tools/modify/overrides.d.ts +6 -0
- package/dist/tools/modify/overrides.d.ts.map +1 -0
- package/dist/tools/modify/overrides.js +27 -0
- package/dist/tools/modify/overrides.js.map +1 -0
- package/dist/tools/modify/paint.d.ts.map +1 -1
- package/dist/tools/modify/paint.js +84 -39
- package/dist/tools/modify/paint.js.map +1 -1
- package/dist/tools/modify/text.d.ts +2 -1
- package/dist/tools/modify/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +79 -8
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/modify/update.d.ts.map +1 -1
- package/dist/tools/modify/update.js +18 -2
- package/dist/tools/modify/update.js.map +1 -1
- package/dist/tools/modify.d.ts +3 -2
- package/dist/tools/modify.js +3 -2
- package/dist/tools/read/css.d.ts.map +1 -1
- package/dist/tools/read/css.js +29 -12
- package/dist/tools/read/css.js.map +1 -1
- package/dist/tools/read/libraries.js +1 -1
- package/dist/tools/read/nodes.d.ts.map +1 -1
- package/dist/tools/read/nodes.js +19 -5
- package/dist/tools/read/nodes.js.map +1 -1
- package/dist/tools/registry/extended.d.ts.map +1 -1
- package/dist/tools/registry/extended.js +6 -1
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/text-range.d.ts +11 -0
- package/dist/tools/text-range.d.ts.map +1 -0
- package/dist/tools/text-range.js +26 -0
- package/dist/tools/text-range.js.map +1 -0
- package/dist/tools/variables/bindings.js +1 -1
- package/dist/tools/variables/bindings.js.map +1 -1
- package/dist/tools/variables/unbind.js +1 -1
- package/dist/tools/variables/unbind.js.map +1 -1
- package/dist/tools/vector/path.d.ts.map +1 -1
- package/dist/tools/vector/path.js +7 -21
- package/dist/tools/vector/path.js.map +1 -1
- package/dist/vector/rebase.d.ts +17 -0
- package/dist/vector/rebase.d.ts.map +1 -0
- package/dist/vector/rebase.js +32 -0
- package/dist/vector/rebase.js.map +1 -0
- package/package.json +14 -9
- package/src/canvas/boolean.ts +12 -1
- package/src/canvas/color-space.ts +73 -0
- package/src/canvas/fills.ts +130 -83
- package/src/canvas/flatten.ts +92 -7
- package/src/canvas/index.ts +9 -0
- package/src/canvas/layout-grids.ts +15 -2
- package/src/canvas/noise/render.ts +35 -7
- package/src/canvas/noise/shader.ts +8 -10
- package/src/canvas/overlays/annotations.ts +117 -0
- package/src/canvas/overlays/auto-layout-hover.ts +41 -1
- package/src/canvas/overlays/feedback.ts +7 -2
- package/src/canvas/overlays/index.ts +1 -1
- package/src/canvas/overlays/measurement.ts +49 -3
- package/src/canvas/overlays/presence.ts +35 -32
- package/src/canvas/renderer/colors.ts +14 -0
- package/src/canvas/renderer/document-surface.ts +16 -6
- package/src/canvas/renderer/lifecycle.ts +2 -2
- package/src/canvas/renderer/methods.ts +4 -0
- package/src/canvas/renderer/overlay-pass.ts +4 -0
- package/src/canvas/renderer/pipeline.ts +8 -0
- package/src/canvas/renderer/types.ts +8 -0
- package/src/canvas/renderer.ts +21 -2
- package/src/canvas/scene.ts +15 -7
- package/src/canvas/shaders/compile.ts +14 -3
- package/src/canvas/shaders/draw.ts +11 -4
- package/src/canvas/shaders/effect.ts +6 -18
- package/src/clipboard/pairdraw.ts +1 -0
- package/src/editor/bridges/clipboard.ts +1 -0
- package/src/editor/bridges/components.ts +10 -0
- package/src/editor/clipboard/code.ts +50 -0
- package/src/editor/clipboard/export.ts +2 -2
- package/src/editor/clipboard/paste/dependencies.ts +18 -0
- package/src/editor/clipboard/paste/run.ts +64 -0
- package/src/editor/clipboard/styled.ts +4 -52
- package/src/editor/clipboard.ts +40 -0
- package/src/editor/components/instances.ts +92 -4
- package/src/editor/components/slots/index.ts +7 -0
- package/src/editor/components.ts +16 -2
- package/src/editor/create.ts +15 -1
- package/src/editor/design-tokens.ts +3 -23
- package/src/editor/image-edit.ts +5 -2
- package/src/editor/index.ts +1 -0
- package/src/editor/layout-mode.ts +131 -3
- package/src/editor/nodes.ts +30 -5
- package/src/editor/read-only/actions.ts +6 -0
- package/src/editor/selection/overlays.ts +8 -0
- package/src/editor/state/shared.ts +1 -0
- package/src/editor/state/view.ts +2 -0
- package/src/editor/structure/boolean.ts +29 -1
- package/src/editor/structure/container-wrap.ts +20 -4
- package/src/editor/structure/flatten.ts +15 -8
- package/src/editor/structure/group/ungroup.ts +2 -0
- package/src/editor/structure/outline-stroke.ts +5 -0
- package/src/editor/styles.ts +203 -0
- package/src/editor/text/selection-style.ts +18 -1
- package/src/editor/tool-registry.ts +2 -0
- package/src/editor/types.ts +14 -0
- package/src/editor/variable-bindings.ts +11 -0
- package/src/figma-api/accessors/basic.ts +33 -1
- package/src/figma-api/accessors/vector.ts +6 -13
- package/src/figma-api/compatibility.ts +1 -0
- package/src/figma-api/component-scope.ts +36 -0
- package/src/figma-api/components.ts +24 -0
- package/src/figma-api/flatten.ts +7 -3
- package/src/figma-api/index.ts +302 -6
- package/src/figma-api/node-types.ts +1 -0
- package/src/figma-api/overrides.ts +192 -5
- package/src/figma-api/proxy.ts +16 -1
- package/src/figma-api/reactions.ts +163 -12
- package/src/figma-api/slots.ts +10 -9
- package/src/io/formats/code/detect.ts +67 -0
- package/src/io/formats/code/index.ts +17 -0
- package/src/io/formats/code/read.ts +143 -0
- package/src/io/formats/code/stylesheet.ts +24 -0
- package/src/io/formats/code/tokens.ts +159 -0
- package/src/io/formats/design-tokens/apply.ts +3 -2
- package/src/io/formats/drawio/warnings.ts +27 -8
- package/src/io/formats/fig/export/patch/fields.ts +11 -0
- package/src/io/formats/fig/export/patch/index.ts +23 -19
- package/src/io/formats/fig/export/setup.ts +8 -1
- package/src/io/formats/fig/index.ts +6 -0
- package/src/io/formats/fig/read.ts +11 -2
- package/src/io/formats/html/index.ts +9 -3
- package/src/io/formats/html/layers.ts +7 -0
- package/src/io/formats/pdf/export.ts +19 -7
- package/src/io/formats/pdf/plan.ts +71 -32
- package/src/io/formats/pen/index.ts +14 -6
- package/src/io/formats/raster/headless.ts +3 -1
- package/src/io/formats/raster/index.ts +2 -0
- package/src/io/formats/raster/render.ts +49 -9
- package/src/io/formats/svg/defs.ts +27 -1
- package/src/io/formats/svg/export.ts +75 -13
- package/src/io/formats/svg/index.ts +1 -0
- package/src/io/formats/svg/text/layout.ts +5 -3
- package/src/io/formats/video/record.ts +33 -9
- package/src/io/formats.ts +45 -19
- package/src/io/index.ts +1 -0
- package/src/io/types.ts +10 -0
- package/src/kiwi/fig/population/client.ts +6 -1
- package/src/kiwi/fig/session/document-state.ts +195 -5
- package/src/kiwi/fig/session/options.ts +2 -0
- package/src/layout/apply.ts +12 -4
- package/src/layout/auto-layout-handles.ts +1 -1
- package/src/layout/axis-sizing.ts +3 -1
- package/src/layout/derived.ts +3 -1
- package/src/layout/effective-generated-text.ts +1 -1
- package/src/layout/grid.ts +91 -21
- package/src/layout.ts +16 -3
- package/src/node/fs.ts +32 -7
- package/src/prototype/easing.ts +79 -7
- package/src/prototype/scenes.ts +244 -15
- package/src/prototype/session.ts +1 -0
- package/src/prototype/smart-animate/animation.ts +4 -3
- package/src/prototype/timeline.ts +118 -26
- package/src/prototype/variables.ts +189 -0
- package/src/rpc/read-commands.ts +19 -1
- package/src/text/character-style.ts +47 -0
- package/src/text/index.ts +1 -1
- package/src/tools/create/basic.ts +2 -3
- package/src/tools/create/code.ts +85 -0
- package/src/tools/create/html.ts +9 -46
- package/src/tools/create/inputs.ts +12 -0
- package/src/tools/create/mermaid.ts +6 -6
- package/src/tools/create/place.ts +80 -0
- package/src/tools/create.ts +1 -0
- package/src/tools/css/gradient.ts +147 -0
- package/src/tools/modify/geometry.ts +5 -5
- package/src/tools/modify/layout.ts +19 -0
- package/src/tools/modify/overrides.ts +35 -0
- package/src/tools/modify/paint.ts +124 -54
- package/src/tools/modify/text.ts +91 -7
- package/src/tools/modify/update.ts +23 -2
- package/src/tools/modify.ts +9 -1
- package/src/tools/read/css.ts +46 -12
- package/src/tools/read/nodes.ts +26 -4
- package/src/tools/registry/extended.ts +6 -0
- package/src/tools/text-range.ts +29 -0
- package/src/tools/variables/bindings.ts +4 -1
- package/src/tools/variables/unbind.ts +4 -1
- package/src/tools/vector/path.ts +11 -13
- package/src/vector/rebase.ts +33 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-state.js","names":[],"sources":["../../../../src/kiwi/fig/session/document-state.ts"],"sourcesContent":["import {\n createFigDocumentSession,\n figCheckpointRecords,\n type FigSessionCheckpoint\n} from '@pairdraw/fig'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { figArchive } from '#core/kiwi/fig/session/archive/access'\nimport { readerSessionOptions, type FigReaderDiagnostic } from '#core/kiwi/fig/session/options'\n\n/**\n * Per-graph reader state: the archive bytes, the live session or its checkpoint, and the\n * records that session skipped. Page population, diagnostics and recovery all read it.\n */\ninterface ReaderState {\n /** The archive, until every page is in the graph and nothing is left to read from it. */\n bytes?: ArrayBuffer\n checkpoint?: FigSessionCheckpoint\n session?: ReturnType<typeof createFigDocumentSession>\n /** Records skipped by sessions this recovery state has opened. */\n diagnostics: FigReaderDiagnostic[]\n /** Every page is loaded and the reader released; only the diagnostics remain. */\n complete?: true\n}\nconst states = new WeakMap<SceneGraph, ReaderState>()\n\nexport function registerReaderRecovery(\n graph: SceneGraph,\n bytes: ArrayBuffer,\n checkpoint: FigSessionCheckpoint\n): void {\n states.set(graph, { bytes, checkpoint, diagnostics: [] })\n}\n\nexport function registerReaderSession(\n bytes: ArrayBuffer,\n session: ReturnType<typeof createFigDocumentSession>,\n diagnostics: FigReaderDiagnostic[] = []\n): void {\n states.set(session.graph, { bytes, session, diagnostics })\n}\n\n/** Records skipped while opening, recovering, or exporting this graph's document. */\nexport function readerDiagnostics(graph: SceneGraph): readonly FigReaderDiagnostic[] {\n return states.get(graph)?.diagnostics ?? []\n}\n\nexport function isReaderPagePending(graph: SceneGraph, pageId: string): boolean {\n const state = states.get(graph)\n if (!state || state.complete) return false\n const checkpoint = state.session?.checkpoint() ?? state.checkpoint\n const sourceId = checkpoint?.sources.find(([, graphId]) => graphId === pageId)?.[0]\n if (!sourceId) return false\n const session = state.session\n return session\n ? session.pages.some((page) => page.id === sourceId) && !session.loadedPageIds.has(sourceId)\n : !checkpoint.loadedPageIds.includes(sourceId)\n}\n\n/**\n * The page holding a layer of the file while that page has not loaded, so a layer named by its\n * ID, as a link to it names it, is found by loading its page. A layer's ID is its record's GUID;\n * the archive answers which page holds it, in the reader's worker when there is one.\n */\nexport async function pendingReaderPageOfNode(\n graph: SceneGraph,\n nodeId: string\n): Promise<string | null> {\n const archive = figArchive(graph)\n const checkpoint = readerCheckpoint(graph)\n if (!archive || !checkpoint || states.get(graph)?.complete) return null\n const [pageGuid] = await archive.recordPages([nodeId])\n const pageId = pageGuid ? figCheckpointRecords(checkpoint).get(pageGuid) : undefined\n return pageId && isReaderPagePending(graph, pageId) ? pageId : null\n}\n\n/** Where the reader stands: which records became which layers, and which pages it loaded. */\nexport function readerCheckpoint(graph: SceneGraph): FigSessionCheckpoint | undefined {\n const state = states.get(graph)\n return state?.session?.checkpoint() ?? state?.checkpoint\n}\n\nexport function hasReaderSession(graph: SceneGraph): boolean {\n return states.has(graph)\n}\n\nexport function populateFigPage(graph: SceneGraph, pageId: string): boolean {\n return isReaderPagePending(graph, pageId) ? recoverReaderPage(graph, pageId) : false\n}\n\nexport function populateAllFigPages(graph: SceneGraph): boolean {\n let changed = false\n for (const page of graph.getPages()) {\n if (populateFigPage(graph, page.id)) changed = true\n }\n return changed\n}\n\n/**\n * Drop the session and the archive once every page is in the graph, internal ones included, which\n * the first full save loads. The session keeps every record of the file decoded, which for a\n * large design kit is gigabytes, and no page is pending. The checkpoint stays: it says which\n * record each layer came from, which saving only the changed records still reads.\n */\nfunction releaseLoadedReader(state: ReaderState): void {\n const session = state.session\n if (!session?.pages.every((page) => session.loadedPageIds.has(page.id))) return\n state.checkpoint = session.checkpoint()\n state.session = undefined\n state.bytes = undefined\n state.complete = true\n}\n\n/**\n * Load the pages the editor never shows, such as Figma's internal canvas, into the document's own\n * graph, so a save no longer opens a second session to read them into its copy. Their layers\n * never draw and loading them is not an edit. Only a live session loads them: while a population\n * worker still fills the graph, a second session must not, and the export reads them as before.\n */\nexport function populateFigInternalPages(graph: SceneGraph): boolean {\n const state = states.get(graph)\n const session = state?.session\n if (!state || !session) return false\n let changed = false\n for (const page of session.pages) {\n if (!page.internalOnly || session.loadedPageIds.has(page.id)) continue\n graph.applyImportedStateDuring(() => session.loadPage(page.id))\n changed = true\n }\n releaseLoadedReader(state)\n return changed\n}\n\n/**\n * Whether a save still has pages to read from the archive, which it reads into a copy of the\n * document: a population worker still fills the graph, or a page is not loaded yet.\n */\nexport function hasPendingReaderPages(graph: SceneGraph): boolean {\n const state = states.get(graph)\n if (!state || state.complete) return false\n const session = state.session\n return !session || !session.pages.every((page) => session.loadedPageIds.has(page.id))\n}\n\nexport function populateReaderExport(source: SceneGraph, target: SceneGraph): boolean {\n const state = states.get(source)\n if (!state || state.complete) return false\n const live = state.session\n // Every page is already in the graph the target was copied from.\n if (live?.pages.every((page) => live.loadedPageIds.has(page.id))) return false\n const checkpoint = live?.checkpoint() ?? state.checkpoint\n if (!checkpoint || !state.bytes) throw new Error('Missing reader checkpoint')\n const session = createFigDocumentSession(state.bytes, readerSessionOptions(state.diagnostics), {\n graph: target,\n checkpoint\n })\n // Export must include internal content too, not just the dependency closure needed\n // for visible pages. Loading happens on the isolated target, never the live graph.\n for (const page of session.pages) session.loadPage(page.id)\n return true\n}\n\nexport function updateReaderRecovery(graph: SceneGraph, checkpoint: FigSessionCheckpoint): void {\n const state = states.get(graph)\n if (state && !state.session) state.checkpoint = checkpoint\n}\n\nexport function releaseReaderRecovery(graph: SceneGraph): void {\n states.delete(graph)\n}\n\nexport function recoverReaderPage(graph: SceneGraph, pageId: string): boolean {\n const state = states.get(graph)\n if (!state) throw new Error('No reader recovery state')\n if (state.complete) return false\n if (!state.session) {\n if (!state.checkpoint || !state.bytes) throw new Error('Missing reader checkpoint')\n state.session = createFigDocumentSession(state.bytes, readerSessionOptions(state.diagnostics), {\n graph,\n checkpoint: state.checkpoint\n })\n }\n const page = state.session.pages.find((page) => state.session?.graphPageId(page.id) === pageId)\n if (!page) throw new Error(`Unknown graph page ${pageId}`)\n const session = state.session\n const populated = !session.loadedPageIds.has(page.id)\n // The layers come from the opened file, as they do through the population worker's delta.\n graph.applyImportedStateDuring(() => session.loadPage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M,MAAM,IAAI,MAAM,sBAAsB,QAAQ;CACzD,MAAM,UAAU,MAAM;CACtB,MAAM,YAAY,CAAC,QAAQ,cAAc,IAAI,KAAK,EAAE;CAEpD,MAAM,+BAA+B,QAAQ,SAAS,KAAK,EAAE,CAAC;CAC9D,oBAAoB,KAAK;CACzB,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"document-state.js","names":[],"sources":["../../../../src/kiwi/fig/session/document-state.ts"],"sourcesContent":["import {\n createFigDocumentSession,\n figCheckpointRecords,\n type FigSessionCheckpoint\n} from '@pairdraw/fig'\nimport type { GUID } from '@pairdraw/kiwi/fig'\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { dropDuplicateSlotContentAssignments } from '@pairdraw/scene-graph/slots'\n\nimport { figArchive } from '#core/kiwi/fig/session/archive/access'\nimport { readerSessionOptions, type FigReaderDiagnostic } from '#core/kiwi/fig/session/options'\n\n/**\n * Per-graph reader state: the archive bytes, the live session or its checkpoint, and the\n * records that session skipped. Page population, diagnostics and recovery all read it.\n */\ninterface ReaderState {\n /** The archive, until every page is in the graph and nothing is left to read from it. */\n bytes?: ArrayBuffer\n checkpoint?: FigSessionCheckpoint\n session?: ReturnType<typeof createFigDocumentSession>\n /** Records skipped by sessions this recovery state has opened. */\n diagnostics: FigReaderDiagnostic[]\n /** Every page is loaded and the reader released; only the diagnostics remain. */\n complete?: true\n}\nconst states = new WeakMap<SceneGraph, ReaderState>()\n\nexport function registerReaderRecovery(\n graph: SceneGraph,\n bytes: ArrayBuffer,\n checkpoint: FigSessionCheckpoint\n): void {\n states.set(graph, { bytes, checkpoint, diagnostics: [] })\n}\n\nconst outsideDiagnostics = new WeakMap<SceneGraph, FigReaderDiagnostic[]>()\n\n/** Records a diagnostic on a graph whose reader state is gone or was never kept. */\nexport function recordReaderDiagnostic(graph: SceneGraph, diagnostic: FigReaderDiagnostic): void {\n const log = outsideDiagnostics.get(graph)\n if (log) log.push(diagnostic)\n else outsideDiagnostics.set(graph, [diagnostic])\n}\n\n/** Keeps one owner per slot-content frame on a graph read from outside Pairdraw. */\nexport function normalizeSlotContentOwners(graph: SceneGraph): void {\n for (const conflict of dropDuplicateSlotContentAssignments(graph)) {\n recordReaderDiagnostic(graph, { kind: 'duplicate-slot-content', diagnostic: conflict })\n }\n}\n\nexport function registerReaderSession(\n bytes: ArrayBuffer,\n session: ReturnType<typeof createFigDocumentSession>,\n diagnostics: FigReaderDiagnostic[] = []\n): void {\n states.set(session.graph, { bytes, session, diagnostics })\n}\n\n/** Whether this graph still holds a live reader session (its decoded records). */\nexport function readerSessionHeld(graph: SceneGraph): boolean {\n return states.get(graph)?.session !== undefined\n}\n\n/**\n * Drop the decoded records of a graph whose pages are in it, keeping the archive bytes and the\n * checkpoint so a save or an explicit page population can open a fresh session from them. The\n * session holds every record of the file decoded, which is the largest part of an open document.\n */\nexport function releaseReaderRecords(graph: SceneGraph): void {\n const state = states.get(graph)\n if (!state?.session) return\n const session = state.session\n const everyPageLoaded = session.pages.every((page) => session.loadedPageIds.has(page.id))\n state.checkpoint = session.checkpoint()\n state.session = undefined\n // With every page already in the graph there is nothing left to read; without this a fallback\n // write sees the missing session as pending pages and clones the whole document.\n if (everyPageLoaded) state.complete = true\n}\n\n/** Records skipped while opening, recovering, or exporting this graph's document. */\n/** One kind of reader diagnostic and how many records it affected. */\nexport interface ReaderDiagnosticCount {\n kind: FigReaderDiagnostic['kind']\n count: number\n}\n\n/** The reader diagnostics of `graph`, counted by kind and sorted, for reports. */\nexport function readerDiagnosticCounts(graph: SceneGraph): ReaderDiagnosticCount[] {\n const counts = new Map<FigReaderDiagnostic['kind'], number>()\n for (const entry of readerDiagnostics(graph))\n counts.set(entry.kind, (counts.get(entry.kind) ?? 0) + 1)\n return [...counts]\n .map(([kind, count]) => ({ kind, count }))\n .sort((left, right) => left.kind.localeCompare(right.kind))\n}\n\nexport type ReaderDiagnosticReason =\n | 'missing-target'\n | 'ambiguous-target'\n | 'library-not-loaded'\n | 'stale-target'\n\n/** A reader record as reported: a skipped part, or a saved path that names other content. */\nexport type ReaderDiagnostic =\n | Exclude<FigReaderDiagnostic, { kind: 'property' }>\n | {\n kind: 'property'\n diagnostic: Omit<\n Extract<FigReaderDiagnostic, { kind: 'property' }>['diagnostic'],\n 'reason'\n > & { reason: ReaderDiagnosticReason }\n }\n\n/** What the reader could not use, gathered under the component the records belong to. */\nexport interface ReaderDiagnosticComponent {\n id: string | null\n name: string\n count: number\n reasons: ReaderDiagnosticReason[]\n}\n\n/** The main component a diagnostic belongs to, where the record names one. */\nfunction diagnosticComponentId(entry: ReaderDiagnostic): string | null {\n const diagnostic = entry.diagnostic as {\n mainComponentId?: string | null\n componentId?: string\n }\n return diagnostic.mainComponentId ?? diagnostic.componentId ?? null\n}\n\n/**\n * Reader diagnostics grouped by the component whose records were skipped, largest first, for a\n * notice that names components instead of counting parts. `kinds` narrows the report to what a\n * person can act on; the library reason needs a missing target on a layer carrying a library key.\n */\nexport function readerDiagnosticComponents(\n graph: SceneGraph,\n kinds?: ReadonlySet<FigReaderDiagnostic['kind']>\n): readonly ReaderDiagnosticComponent[] {\n const components = new Map<string, ReaderDiagnosticComponent>()\n for (const entry of readerDiagnostics(graph)) {\n if (kinds && !kinds.has(entry.kind)) continue\n if ((entry.diagnostic as { reason?: ReaderDiagnosticReason }).reason === 'stale-target')\n continue\n const owner = componentOwnerOf(graph, diagnosticComponentId(entry))\n const diagnostic = entry.diagnostic as {\n path?: readonly GUID[]\n reason?: ReaderDiagnosticReason | 'missing-target' | 'ambiguous-target'\n targetAbsent?: boolean\n }\n const reason = diagnosticReason(graph, diagnostic, owner)\n const key = owner.id ?? owner.name\n const current = components.get(key) ?? { id: owner.id, name: owner.name, count: 0, reasons: [] }\n current.count++\n if (!current.reasons.includes(reason)) current.reasons.push(reason)\n components.set(key, current)\n }\n return [...components.values()].sort(\n (left, right) => right.count - left.count || left.name.localeCompare(right.name)\n )\n}\n\ninterface DiagnosticOwner {\n id: string | null\n name: string\n node: SceneNode | undefined\n component: SceneNode | undefined\n}\n\n/** The component set a variant belongs to, or the component itself, with a name to show. */\nfunction componentOwnerOf(graph: SceneGraph, componentId: string | null): DiagnosticOwner {\n const component = componentId === null ? undefined : graph.getNode(componentId)\n const parent = component?.parentId ? graph.getNode(component.parentId) : undefined\n const node =\n component?.type === 'COMPONENT' && parent?.type === 'COMPONENT_SET' ? parent : component\n return {\n id: node?.id ?? componentId,\n name: node?.name ?? componentId ?? 'Unknown component',\n node,\n component\n }\n}\n\nfunction diagnosticReason(\n graph: SceneGraph,\n diagnostic: {\n path?: readonly GUID[]\n reason?: ReaderDiagnosticReason | 'missing-target' | 'ambiguous-target'\n targetAbsent?: boolean\n },\n owner: DiagnosticOwner\n): ReaderDiagnosticReason {\n const absent =\n diagnostic.targetAbsent === true ||\n (diagnostic.path?.some(\n (guid) => graph.getNode(`${guid.sessionID}:${guid.localID}`) === undefined\n ) ??\n false)\n if (absent && (owner.node?.sourceLibraryKey ?? owner.component?.sourceLibraryKey))\n return 'library-not-loaded'\n return diagnostic.reason === 'ambiguous-target' ? 'ambiguous-target' : 'missing-target'\n}\n\nexport function readerDiagnostics(graph: SceneGraph): readonly ReaderDiagnostic[] {\n return [...(states.get(graph)?.diagnostics ?? []), ...(outsideDiagnostics.get(graph) ?? [])].map(\n (entry) => {\n if (entry.kind !== 'property') return entry\n const diagnostic = entry.diagnostic\n if (\n diagnostic.reason !== 'missing-target' ||\n diagnostic.path.length === 0 ||\n !diagnostic.path.every(\n (guid) => graph.getNode(`${guid.sessionID}:${guid.localID}`) !== undefined\n )\n )\n return entry\n // The path names layers the file holds, just not under the instance that saved it: stale\n // saved state, not a part the reader lost. It stays in the raw report and out of the notice.\n return { ...entry, diagnostic: { ...diagnostic, reason: 'stale-target' as const } }\n }\n )\n}\n\nexport function isReaderPagePending(graph: SceneGraph, pageId: string): boolean {\n const state = states.get(graph)\n if (!state || state.complete) return false\n const checkpoint = state.session?.checkpoint() ?? state.checkpoint\n const sourceId = checkpoint?.sources.find(([, graphId]) => graphId === pageId)?.[0]\n if (!sourceId) return false\n const session = state.session\n return session\n ? session.pages.some((page) => page.id === sourceId) && !session.loadedPageIds.has(sourceId)\n : !checkpoint.loadedPageIds.includes(sourceId)\n}\n\n/**\n * The page holding a layer of the file while that page has not loaded, so a layer named by its\n * ID, as a link to it names it, is found by loading its page. A layer's ID is its record's GUID;\n * the archive answers which page holds it, in the reader's worker when there is one.\n */\nexport async function pendingReaderPageOfNode(\n graph: SceneGraph,\n nodeId: string\n): Promise<string | null> {\n const archive = figArchive(graph)\n const checkpoint = readerCheckpoint(graph)\n if (!archive || !checkpoint || states.get(graph)?.complete) return null\n const [pageGuid] = await archive.recordPages([nodeId])\n const pageId = pageGuid ? figCheckpointRecords(checkpoint).get(pageGuid) : undefined\n return pageId && isReaderPagePending(graph, pageId) ? pageId : null\n}\n\n/** Where the reader stands: which records became which layers, and which pages it loaded. */\nexport function readerCheckpoint(graph: SceneGraph): FigSessionCheckpoint | undefined {\n const state = states.get(graph)\n return state?.session?.checkpoint() ?? state?.checkpoint\n}\n\nexport function hasReaderSession(graph: SceneGraph): boolean {\n return states.has(graph)\n}\n\nexport function populateFigPage(graph: SceneGraph, pageId: string): boolean {\n return isReaderPagePending(graph, pageId) ? recoverReaderPage(graph, pageId) : false\n}\n\nexport function populateAllFigPages(graph: SceneGraph): boolean {\n let changed = false\n for (const page of graph.getPages()) {\n if (populateFigPage(graph, page.id)) changed = true\n }\n return changed\n}\n\n/**\n * Drop the session and the archive once every page is in the graph, internal ones included, which\n * the first full save loads. The session keeps every record of the file decoded, which for a\n * large design kit is gigabytes, and no page is pending. The checkpoint stays: it says which\n * record each layer came from, which saving only the changed records still reads.\n */\nfunction releaseLoadedReader(state: ReaderState): void {\n const session = state.session\n if (!session?.pages.every((page) => session.loadedPageIds.has(page.id))) return\n state.checkpoint = session.checkpoint()\n state.session = undefined\n state.bytes = undefined\n state.complete = true\n}\n\n/**\n * Load the pages the editor never shows, such as Figma's internal canvas, into the document's own\n * graph, so a save no longer opens a second session to read them into its copy. Their layers\n * never draw and loading them is not an edit. Only a live session loads them: while a population\n * worker still fills the graph, a second session must not, and the export reads them as before.\n */\nexport function populateFigInternalPages(graph: SceneGraph): boolean {\n const state = states.get(graph)\n if (!state || state.complete) return false\n let session = state.session\n if (!session) {\n // The records are released; read them back for the internal pages a full write needs, on this\n // graph, so a released document does not turn every fallback write into a full clone.\n if (!state.checkpoint || !state.bytes) return false\n session = createFigDocumentSession(state.bytes, readerSessionOptions(state.diagnostics), {\n graph,\n checkpoint: state.checkpoint\n })\n state.session = session\n }\n let changed = false\n for (const page of session.pages) {\n if (!page.internalOnly || session.loadedPageIds.has(page.id)) continue\n graph.applyImportedStateDuring(() => session.loadPage(page.id))\n changed = true\n }\n releaseLoadedReader(state)\n return changed\n}\n\n/**\n * Whether a save still has pages to read from the archive, which it reads into a copy of the\n * document: a population worker still fills the graph, or a page is not loaded yet.\n */\nexport function hasPendingReaderPages(graph: SceneGraph): boolean {\n const state = states.get(graph)\n if (!state || state.complete) return false\n const session = state.session\n return !session || !session.pages.every((page) => session.loadedPageIds.has(page.id))\n}\n\nexport function populateReaderExport(source: SceneGraph, target: SceneGraph): boolean {\n const state = states.get(source)\n if (!state || state.complete) return false\n const live = state.session\n // Every page is already in the graph the target was copied from.\n if (live?.pages.every((page) => live.loadedPageIds.has(page.id))) return false\n const checkpoint = live?.checkpoint() ?? state.checkpoint\n if (!checkpoint || !state.bytes) throw new Error('Missing reader checkpoint')\n const session = createFigDocumentSession(state.bytes, readerSessionOptions(state.diagnostics), {\n graph: target,\n checkpoint\n })\n // Export must include internal content too, not just the dependency closure needed\n // for visible pages. Loading happens on the isolated target, never the live graph.\n for (const page of session.pages) session.loadPage(page.id)\n return true\n}\n\nexport function updateReaderRecovery(graph: SceneGraph, checkpoint: FigSessionCheckpoint): void {\n const state = states.get(graph)\n if (state && !state.session) state.checkpoint = checkpoint\n}\n\nexport function releaseReaderRecovery(graph: SceneGraph): void {\n states.delete(graph)\n}\n\nexport function recoverReaderPage(graph: SceneGraph, pageId: string): boolean {\n const state = states.get(graph)\n if (!state) throw new Error('No reader recovery state')\n if (state.complete) return false\n if (!state.session) {\n if (!state.checkpoint || !state.bytes) throw new Error('Missing reader checkpoint')\n state.session = createFigDocumentSession(state.bytes, readerSessionOptions(state.diagnostics), {\n graph,\n checkpoint: state.checkpoint\n })\n }\n const page = state.session.pages.find((page) => state.session?.graphPageId(page.id) === pageId)\n if (!page) throw new Error(`Unknown graph page ${pageId}`)\n const session = state.session\n const populated = !session.loadedPageIds.has(page.id)\n // The layers come from the opened file, as they do through the population worker's delta.\n graph.applyImportedStateDuring(() => session.loadPage(page.id))\n normalizeSlotContentOwners(graph)\n releaseLoadedReader(state)\n return populated\n}\n"],"mappings":";;;;;AA0BA,MAAM,yBAAS,IAAI,QAAiC;AAEpD,SAAgB,uBACd,OACA,OACA,YACM;CACN,OAAO,IAAI,OAAO;EAAE;EAAO;EAAY,aAAa,CAAC;CAAE,CAAC;AAC1D;AAEA,MAAM,qCAAqB,IAAI,QAA2C;;AAG1E,SAAgB,uBAAuB,OAAmB,YAAuC;CAC/F,MAAM,MAAM,mBAAmB,IAAI,KAAK;CACxC,IAAI,KAAK,IAAI,KAAK,UAAU;MACvB,mBAAmB,IAAI,OAAO,CAAC,UAAU,CAAC;AACjD;;AAGA,SAAgB,2BAA2B,OAAyB;CAClE,KAAK,MAAM,YAAY,oCAAoC,KAAK,GAC9D,uBAAuB,OAAO;EAAE,MAAM;EAA0B,YAAY;CAAS,CAAC;AAE1F;AAEA,SAAgB,sBACd,OACA,SACA,cAAqC,CAAC,GAChC;CACN,OAAO,IAAI,QAAQ,OAAO;EAAE;EAAO;EAAS;CAAY,CAAC;AAC3D;;AAGA,SAAgB,kBAAkB,OAA4B;CAC5D,OAAO,OAAO,IAAI,KAAK,CAAC,EAAE,YAAY,KAAA;AACxC;;;;;;AAOA,SAAgB,qBAAqB,OAAyB;CAC5D,MAAM,QAAQ,OAAO,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CAC9D,2BAA2B,KAAK;CAChC,oBAAoB,KAAK;CACzB,OAAO;AACT"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DuplicateSlotContentAssignment } from "@pairdraw/scene-graph/slots";
|
|
1
2
|
import { DocumentAssemblyOptions } from "@pairdraw/fig";
|
|
2
3
|
//#region src/kiwi/fig/session/options.d.ts
|
|
3
4
|
type Handler<K extends keyof DocumentAssemblyOptions> = NonNullable<DocumentAssemblyOptions[K]>;
|
|
@@ -20,6 +21,9 @@ type FigReaderDiagnostic = {
|
|
|
20
21
|
} | {
|
|
21
22
|
kind: 'slot-content';
|
|
22
23
|
diagnostic: Parameters<Handler<'onMissingSlotContent'>>[0];
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'duplicate-slot-content';
|
|
26
|
+
diagnostic: DuplicateSlotContentAssignment;
|
|
23
27
|
} | {
|
|
24
28
|
kind: 'variable-type';
|
|
25
29
|
diagnostic: Parameters<Handler<'onUnsupportedVariableType'>>[0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","names":[],"sources":["../../../../src/kiwi/fig/session/options.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"options.d.ts","names":[],"sources":["../../../../src/kiwi/fig/session/options.ts"],"mappings":";;;KAGK,QAAQ,gBAAgB,2BAA2B,YAAY,wBAAwB;;KAGhF;EACN;EAAkB,YAAY,WAAW;;EACzC;EAAoB,YAAY,WAAW;;EAC3C;EAAiB,YAAY,WAAW;;EAExC;EACA,YAAY,WAAW;;EAEvB;EAAmB,YAAY,WAAW;;EAC1C;EAAsB,YAAY,WAAW;;EAC7C;EAAgC,YAAY;;EAC5C;EAAuB,YAAY,WAAW;;;;;;;;;;iBA6BpC,qBAAqB,MAAM,wBAAwB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","names":[],"sources":["../../../../src/kiwi/fig/session/options.ts"],"sourcesContent":["import type { DocumentAssemblyOptions } from '@pairdraw/fig'\n\ntype Handler<K extends keyof DocumentAssemblyOptions> = NonNullable<DocumentAssemblyOptions[K]>\n\n/** A saved record the reader could not apply and skipped instead of refusing the file. */\nexport type FigReaderDiagnostic =\n | { kind: 'property'; diagnostic: Parameters<Handler<'onUnresolvedProperty'>>[0] }\n | { kind: 'assignment'; diagnostic: Parameters<Handler<'onUnresolvedAssignment'>>[0] }\n | { kind: 'binding'; diagnostic: Parameters<Handler<'onUnresolvedBinding'>>[0] }\n | {\n kind: 'variable-expression'\n diagnostic: Parameters<Handler<'onUnsupportedVariableExpression'>>[0]\n }\n | { kind: 'component'; diagnostic: Parameters<Handler<'onMissingComponent'>>[0] }\n | { kind: 'slot-content'; diagnostic: Parameters<Handler<'onMissingSlotContent'>>[0] }\n | { kind: 'variable-type'; diagnostic: Parameters<Handler<'onUnsupportedVariableType'>>[0] }\n\n/** Each sink's entries, so a record reported again is not listed twice. */\nconst reported = new WeakMap<FigReaderDiagnostic[], Set<string>>()\n\n/**\n * Opening a file, recovering a page, and every save read records through sessions that share\n * one sink, so the same skipped record can reach it more than once.\n */\nfunction report(sink: FigReaderDiagnostic[], entry: FigReaderDiagnostic): void {\n let keys = reported.get(sink)\n if (!keys) {\n keys = new Set(sink.map((existing) => JSON.stringify(existing)))\n reported.set(sink, keys)\n }\n const key = JSON.stringify(entry)\n if (keys.has(key)) return\n keys.add(key)\n sink.push(entry)\n}\n\n/**\n * Figma retains override and binding records that address nodes it later deleted, and\n * instances of deleted components, and the reader has no replacement to guess at. Opening\n * a file skips those records, keeps such instances childless, and reports both, including a\n * swap whose target layer is gone. A slot whose assigned content frame is gone keeps its\n * component's content. An ambiguous address means the path is wrong, not stale,\n * and still fails.\n */\nexport function readerSessionOptions(sink: FigReaderDiagnostic[]): DocumentAssemblyOptions {\n return {\n derivedBounds: true,\n onUnresolvedProperty: (diagnostic) => report(sink, { kind: 'property', diagnostic }),\n onUnresolvedAssignment: (diagnostic) => report(sink, { kind: 'assignment', diagnostic }),\n onUnresolvedBinding: (diagnostic) => report(sink, { kind: 'binding', diagnostic }),\n onUnsupportedVariableExpression: (diagnostic) =>\n report(sink, { kind: 'variable-expression', diagnostic }),\n onMissingComponent: (diagnostic) => report(sink, { kind: 'component', diagnostic }),\n onMissingSlotContent: (diagnostic) => report(sink, { kind: 'slot-content', diagnostic }),\n onUnsupportedVariableType: (resource) =>\n report(sink, { kind: 'variable-type', diagnostic: resource })\n }\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"options.js","names":[],"sources":["../../../../src/kiwi/fig/session/options.ts"],"sourcesContent":["import type { DocumentAssemblyOptions } from '@pairdraw/fig'\nimport type { DuplicateSlotContentAssignment } from '@pairdraw/scene-graph/slots'\n\ntype Handler<K extends keyof DocumentAssemblyOptions> = NonNullable<DocumentAssemblyOptions[K]>\n\n/** A saved record the reader could not apply and skipped instead of refusing the file. */\nexport type FigReaderDiagnostic =\n | { kind: 'property'; diagnostic: Parameters<Handler<'onUnresolvedProperty'>>[0] }\n | { kind: 'assignment'; diagnostic: Parameters<Handler<'onUnresolvedAssignment'>>[0] }\n | { kind: 'binding'; diagnostic: Parameters<Handler<'onUnresolvedBinding'>>[0] }\n | {\n kind: 'variable-expression'\n diagnostic: Parameters<Handler<'onUnsupportedVariableExpression'>>[0]\n }\n | { kind: 'component'; diagnostic: Parameters<Handler<'onMissingComponent'>>[0] }\n | { kind: 'slot-content'; diagnostic: Parameters<Handler<'onMissingSlotContent'>>[0] }\n | { kind: 'duplicate-slot-content'; diagnostic: DuplicateSlotContentAssignment }\n | { kind: 'variable-type'; diagnostic: Parameters<Handler<'onUnsupportedVariableType'>>[0] }\n\n/** Each sink's entries, so a record reported again is not listed twice. */\nconst reported = new WeakMap<FigReaderDiagnostic[], Set<string>>()\n\n/**\n * Opening a file, recovering a page, and every save read records through sessions that share\n * one sink, so the same skipped record can reach it more than once.\n */\nfunction report(sink: FigReaderDiagnostic[], entry: FigReaderDiagnostic): void {\n let keys = reported.get(sink)\n if (!keys) {\n keys = new Set(sink.map((existing) => JSON.stringify(existing)))\n reported.set(sink, keys)\n }\n const key = JSON.stringify(entry)\n if (keys.has(key)) return\n keys.add(key)\n sink.push(entry)\n}\n\n/**\n * Figma retains override and binding records that address nodes it later deleted, and\n * instances of deleted components, and the reader has no replacement to guess at. Opening\n * a file skips those records, keeps such instances childless, and reports both, including a\n * swap whose target layer is gone. A slot whose assigned content frame is gone keeps its\n * component's content. An ambiguous address means the path is wrong, not stale,\n * and still fails.\n */\nexport function readerSessionOptions(sink: FigReaderDiagnostic[]): DocumentAssemblyOptions {\n return {\n derivedBounds: true,\n onUnresolvedProperty: (diagnostic) => report(sink, { kind: 'property', diagnostic }),\n onUnresolvedAssignment: (diagnostic) => report(sink, { kind: 'assignment', diagnostic }),\n onUnresolvedBinding: (diagnostic) => report(sink, { kind: 'binding', diagnostic }),\n onUnsupportedVariableExpression: (diagnostic) =>\n report(sink, { kind: 'variable-expression', diagnostic }),\n onMissingComponent: (diagnostic) => report(sink, { kind: 'component', diagnostic }),\n onMissingSlotContent: (diagnostic) => report(sink, { kind: 'slot-content', diagnostic }),\n onUnsupportedVariableType: (resource) =>\n report(sink, { kind: 'variable-type', diagnostic: resource })\n }\n}\n"],"mappings":";;AAoBA,MAAM,2BAAW,IAAI,QAA4C;;;;;AAMjE,SAAS,OAAO,MAA6B,OAAkC;CAC7E,IAAI,OAAO,SAAS,IAAI,IAAI;CAC5B,IAAI,CAAC,MAAM;EACT,OAAO,IAAI,IAAI,KAAK,KAAK,aAAa,KAAK,UAAU,QAAQ,CAAC,CAAC;EAC/D,SAAS,IAAI,MAAM,IAAI;CACzB;CACA,MAAM,MAAM,KAAK,UAAU,KAAK;CAChC,IAAI,KAAK,IAAI,GAAG,GAAG;CACnB,KAAK,IAAI,GAAG;CACZ,KAAK,KAAK,KAAK;AACjB;;;;;;;;;AAUA,SAAgB,qBAAqB,MAAsD;CACzF,OAAO;EACL,eAAe;EACf,uBAAuB,eAAe,OAAO,MAAM;GAAE,MAAM;GAAY;EAAW,CAAC;EACnF,yBAAyB,eAAe,OAAO,MAAM;GAAE,MAAM;GAAc;EAAW,CAAC;EACvF,sBAAsB,eAAe,OAAO,MAAM;GAAE,MAAM;GAAW;EAAW,CAAC;EACjF,kCAAkC,eAChC,OAAO,MAAM;GAAE,MAAM;GAAuB;EAAW,CAAC;EAC1D,qBAAqB,eAAe,OAAO,MAAM;GAAE,MAAM;GAAa;EAAW,CAAC;EAClF,uBAAuB,eAAe,OAAO,MAAM;GAAE,MAAM;GAAgB;EAAW,CAAC;EACvF,4BAA4B,aAC1B,OAAO,MAAM;GAAE,MAAM;GAAiB,YAAY;EAAS,CAAC;CAChE;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../src/layout/apply.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../src/layout/apply.ts"],"mappings":";;;KAYY,mBAAmB,OAAO,YAAY;;;;;iBAuElC,mBAAmB,OAAO;iBAmT1B,gBACd,OAAO,YACP,OAAO,WACP,UAAU,MACV,eAAe"}
|
package/dist/layout/apply.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { keepsSavedFrameSize, keepsSavedLayout, usesDetachedDerivedLayout } from "./derived.js";
|
|
2
2
|
import { laidOutFlowBox } from "./flow-edges.js";
|
|
3
3
|
import { contentInsetsSize } from "./strokes.js";
|
|
4
|
+
import { gridChildBox } from "./grid.js";
|
|
4
5
|
import { layoutConstrainedChildRect, shapeGeometryChanges } from "@pairdraw/scene-graph/resize";
|
|
5
6
|
import { enforcedAspectRatio } from "@pairdraw/scene-graph/layout";
|
|
6
7
|
//#region src/layout/apply.ts
|
|
@@ -81,12 +82,13 @@ const CONSTRAINT_PARENT_TYPES = /* @__PURE__ */ new Set([
|
|
|
81
82
|
*/
|
|
82
83
|
function constrainChildren(graph, frame, before, computeLayout) {
|
|
83
84
|
for (const child of graph.getChildren(frame.id)) {
|
|
85
|
+
if (child.type === "SLICE") continue;
|
|
84
86
|
if (frame.layoutMode !== "NONE" && child.layoutPositioning !== "ABSOLUTE") continue;
|
|
85
87
|
const size = {
|
|
86
88
|
width: child.width,
|
|
87
89
|
height: child.height
|
|
88
90
|
};
|
|
89
|
-
writeLayoutGeometry(graph, child.id, layoutConstrainedChildRect(child, before, frame, child.horizontalConstraint, child.verticalConstraint, enforcedAspectRatio(child)), computeLayout, void 0, true);
|
|
91
|
+
writeLayoutGeometry(graph, child.id, layoutConstrainedChildRect(child, before, frame, child.horizontalConstraint, child.verticalConstraint, enforcedAspectRatio(child), child), computeLayout, void 0, true);
|
|
90
92
|
if ((child.width !== size.width || child.height !== size.height) && child.layoutMode !== "NONE") computeLayout(graph, child.id);
|
|
91
93
|
}
|
|
92
94
|
}
|
|
@@ -168,7 +170,8 @@ function applyFrameSize(graph, frame, yogaNode, keepsSaved, computeLayout) {
|
|
|
168
170
|
}
|
|
169
171
|
function computedChildPosition(child, yogaChild, axis, origin, preservesImportedGeometry, keepsSaved) {
|
|
170
172
|
if (preservesImportedGeometry) return child[axis];
|
|
171
|
-
const
|
|
173
|
+
const layer = gridChildBox(yogaChild) ?? yogaChild;
|
|
174
|
+
const computed = origin + (axis === "x" ? yogaChild.getComputedLeft() + (layer === yogaChild ? 0 : layer.getComputedLeft()) : yogaChild.getComputedTop() + (layer === yogaChild ? 0 : layer.getComputedTop()));
|
|
172
175
|
if (child.type === "INSTANCE" || !keepsSaved) return computed;
|
|
173
176
|
return child.derivedLayout?.[axis] ?? computed;
|
|
174
177
|
}
|
|
@@ -178,7 +181,8 @@ function preservesStaleImportedTextSize(child, axis) {
|
|
|
178
181
|
}
|
|
179
182
|
function computedChildSize(child, yogaChild, axis, preservesImportedFrameGeometry, keepsSaved) {
|
|
180
183
|
if (preservesImportedFrameGeometry || keepsSaved && preservesStaleImportedTextSize(child, axis)) return child[axis];
|
|
181
|
-
const
|
|
184
|
+
const layer = gridChildBox(yogaChild) ?? yogaChild;
|
|
185
|
+
const computed = axis === "width" ? layer.getComputedWidth() : layer.getComputedHeight();
|
|
182
186
|
if (child.type === "TEXT" && child.source.format === "fig") return computed > 0 ? computed : child[axis];
|
|
183
187
|
if (!keepsSaved) return computed;
|
|
184
188
|
return child.derivedLayout?.[axis] ?? computed;
|
|
@@ -216,7 +220,7 @@ function recomputeGridChild(graph, child, computeLayout) {
|
|
|
216
220
|
function applyYogaLayout(graph, frame, yogaNode, computeLayout) {
|
|
217
221
|
const keepsSaved = keepsSavedLayout(graph, frame);
|
|
218
222
|
applyFrameSize(graph, frame, yogaNode, keepsSaved, computeLayout);
|
|
219
|
-
const children = graph.getChildren(frame.id);
|
|
223
|
+
const children = graph.getChildren(frame.id).filter((child) => child.type !== "SLICE");
|
|
220
224
|
const box = laidOutFlowBox(yogaNode, frame);
|
|
221
225
|
let yogaIndex = 0;
|
|
222
226
|
for (const child of children) {
|
package/dist/layout/apply.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","names":[],"sources":["../../src/layout/apply.ts"],"sourcesContent":["import type { Node as YogaNode } from 'yoga-layout'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { enforcedAspectRatio } from '@pairdraw/scene-graph/layout'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\nimport { layoutConstrainedChildRect, shapeGeometryChanges } from '@pairdraw/scene-graph/resize'\n\nimport { keepsSavedFrameSize, keepsSavedLayout, usesDetachedDerivedLayout } from './derived'\nimport { laidOutFlowBox } from './flow-edges'\nimport { contentInsetsSize } from './strokes'\n\nexport type ComputeLayoutFn = (graph: SceneGraph, frameId: string) => void\n\nfunction preservesImportedHugCrossSize(\n graph: SceneGraph,\n frame: SceneNode,\n axis: 'width' | 'height'\n): boolean {\n if (frame.source.format !== 'fig' || frame.counterAxisSizing !== 'HUG') return false\n const expectedMode = axis === 'width' ? 'VERTICAL' : 'HORIZONTAL'\n if (frame.layoutMode !== expectedMode) return false\n return graph\n .getChildren(frame.id)\n .some(\n (child) => child.layoutAlignSelf === 'STRETCH' && child.derivedLayout?.[axis] !== undefined\n )\n}\n\ntype LayoutGeometry = Partial<Pick<SceneNode, 'x' | 'y' | 'width' | 'height'>>\n\n/**\n * Writes only the geometry layout changed. Laying out a large page leaves most layers where they\n * were, and each write would notify every graph listener for nothing. A frame it resizes from\n * `before`, by default the size it has, places the layers its constraints govern; `constrained`\n * marks a write those constraints made, which places its own children in turn.\n */\nfunction writeLayoutGeometry(\n graph: SceneGraph,\n id: string,\n geometry: LayoutGeometry,\n computeLayout: ComputeLayoutFn,\n before?: { width: number; height: number },\n constrained = false\n): void {\n const node = graph.getNode(id)\n if (!node) return\n const from = before ?? { width: node.width, height: node.height }\n const changes: LayoutGeometry = {}\n for (const key of ['x', 'y', 'width', 'height'] as const) {\n const value = geometry[key]\n // A container whose size no arithmetic can use makes Yoga answer NaN for a child's place\n // (BASELINE alignment in a wrap is one); the layer stays where it was.\n if (value === undefined || !Number.isFinite(value) || value === node[key]) continue\n changes[key] = value\n }\n const resized = changes.width !== undefined || changes.height !== undefined\n const outlines = resized\n ? shapeGeometryChanges(node, changes.width ?? node.width, changes.height ?? node.height)\n : {}\n if (Object.keys(changes).length + Object.keys(outlines).length > 0) {\n graph.updateNode(id, { ...changes, ...outlines })\n }\n if (!CONSTRAINT_PARENT_TYPES.has(node.type)) return\n // Laying out what a file holds, as a page opens or its fonts arrive, resizes a frame only where\n // our layout differs from the one the file saved; its children keep the places it saved.\n if (graph.isApplyingDerivedLayout && !constrained) return\n if (from.width !== node.width || from.height !== node.height) {\n constrainChildren(graph, node, from, computeLayout)\n rememberPlacedSize(node)\n }\n}\n\n/**\n * The size each Hug frame's constrained children were last placed for by layout. Keyed by the\n * node, so a deleted frame's entry goes with it and a restored one starts afresh.\n */\nconst huggedSizes = new WeakMap<SceneNode, { width: number; height: number }>()\n\n/**\n * Records a frame's size as the one its constrained children were placed for, after a rescale\n * scaled them with it: the next hug moves them from the scaled size, not twice from the old one.\n */\nexport function restoredHuggedSize(frame: SceneNode): void {\n if (huggedSizes.has(frame)) huggedSizes.set(frame, { width: frame.width, height: frame.height })\n}\n\nfunction rememberPlacedSize(frame: SceneNode): void {\n const placed = huggedSizes.get(frame)\n if (!placed) return\n placed.width = frame.width\n placed.height = frame.height\n}\n\nconst CONSTRAINT_PARENT_TYPES: ReadonlySet<SceneNode['type']> = new Set([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\n/**\n * Places the children of a frame layout resized by their constraints: every child of a frame\n * without auto layout, and those that ignore an auto layout, as Figma keeps a badge pinned to the\n * right of a Hug button while its label grows. A child it resizes places its own children, and\n * lays out again when it has auto layout.\n */\nfunction constrainChildren(\n graph: SceneGraph,\n frame: SceneNode,\n before: { width: number; height: number },\n computeLayout: ComputeLayoutFn\n): void {\n for (const child of graph.getChildren(frame.id)) {\n if (frame.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE') continue\n const size = { width: child.width, height: child.height }\n writeLayoutGeometry(\n graph,\n child.id,\n layoutConstrainedChildRect(\n child,\n before,\n frame,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n ),\n computeLayout,\n undefined,\n true\n )\n const resized = child.width !== size.width || child.height !== size.height\n if (resized && child.layoutMode !== 'NONE') computeLayout(graph, child.id)\n }\n}\n\n/**\n * The size a frame's constrained children move from as it hugs, or null when it hugs no axis.\n * An editor that resizes a Hug frame places its children for the size it sets, which layout then\n * hugs back, as when a parent stretches it; its children move only from the size it last hugged\n * to. An axis it does not hug keeps the size it has.\n */\nfunction hugStart(frame: SceneNode): { width: number; height: number } | null {\n const row = frame.layoutMode === 'HORIZONTAL'\n const hugsWidth = (row ? frame.primaryAxisSizing : frame.counterAxisSizing) === 'HUG'\n const hugsHeight = (row ? frame.counterAxisSizing : frame.primaryAxisSizing) === 'HUG'\n if (!hugsWidth && !hugsHeight) {\n huggedSizes.delete(frame)\n return null\n }\n const hugged = huggedSizes.get(frame)\n return {\n width: hugsWidth && hugged ? hugged.width : frame.width,\n height: hugsHeight && hugged ? hugged.height : frame.height\n }\n}\n\n/**\n * The smallest size a layout frame holds: what Yoga computed for it, or the room its padding and\n * included inside strokes take, which Yoga's fixed size does not count. A saved frame nobody\n * edited holds exactly what Yoga computed, so opening a file never grows it.\n */\nfunction heldFrameSize(\n frame: SceneNode,\n yogaNode: YogaNode,\n holdsSavedSize: boolean\n): { width: number; height: number } {\n const insets = holdsSavedSize ? null : contentInsetsSize(frame)\n return {\n width: Math.max(yogaNode.getComputedWidth(), insets?.width ?? 0),\n height: Math.max(yogaNode.getComputedHeight(), insets?.height ?? 0)\n }\n}\n\n/** A grid's size: automatic rows take their height, and a hugged axis takes what Yoga computed. */\nfunction applyGridFrameSize(\n graph: SceneGraph,\n frame: SceneNode,\n yogaNode: YogaNode,\n computeLayout: ComputeLayoutFn\n): void {\n const updates: LayoutGeometry = {}\n const holds = keepsSavedFrameSize(graph, frame)\n const held = heldFrameSize(frame, yogaNode, holds)\n if (frame.primaryAxisSizing === 'HUG') updates.width = held.width\n else if (!holds && held.width > frame.width) updates.width = held.width\n const automaticRows = frame.gridTemplateRows.length === 0\n if (automaticRows || frame.counterAxisSizing === 'HUG') updates.height = held.height\n else if (!holds && held.height > frame.height) updates.height = held.height\n writeLayoutGeometry(graph, frame.id, updates, computeLayout)\n}\n\n/** The sizes a flex frame takes: a fixed one grows to its padding, and a hugged one hugs. */\nfunction flexFrameSizeUpdates(\n frame: SceneNode,\n held: { width: number; height: number },\n computed: (axis: 'width' | 'height') => number,\n derived: Partial<Record<'width' | 'height', number>> | null,\n keepsSavedSize: (axis: 'width' | 'height') => boolean,\n holdsSavedSize: boolean\n): LayoutGeometry {\n const primary = frame.layoutMode === 'HORIZONTAL' ? 'width' : 'height'\n const counter = primary === 'width' ? 'height' : 'width'\n const updates: LayoutGeometry = {}\n // The padding floor is an edit: a saved frame nobody touched keeps the size it has.\n if (frame.primaryAxisSizing === 'FIXED' && !holdsSavedSize && held[primary] > frame[primary]) {\n updates[primary] = held[primary]\n }\n if (frame.counterAxisSizing === 'FIXED' && !holdsSavedSize && held[counter] > frame[counter]) {\n updates[counter] = held[counter]\n }\n if (frame.primaryAxisSizing === 'HUG') {\n const floor = holdsSavedSize ? 0 : held[primary]\n updates[primary] = Math.max(derived?.[primary] ?? computed(primary), floor)\n }\n if (frame.counterAxisSizing === 'HUG') {\n const floor = holdsSavedSize ? 0 : held[counter]\n updates[counter] = Math.max(\n keepsSavedSize(counter) ? frame[counter] : (derived?.[counter] ?? computed(counter)),\n floor\n )\n }\n return updates\n}\n\nfunction applyFrameSize(\n graph: SceneGraph,\n frame: SceneNode,\n yogaNode: YogaNode,\n keepsSaved: boolean,\n computeLayout: ComputeLayoutFn\n): void {\n if (frame.layoutMode === 'GRID') {\n applyGridFrameSize(graph, frame, yogaNode, computeLayout)\n return\n }\n\n const before = hugStart(frame)\n const computed = (axis: 'width' | 'height') =>\n axis === 'width' ? yogaNode.getComputedWidth() : yogaNode.getComputedHeight()\n const holds = keepsSavedFrameSize(graph, frame)\n const updates = flexFrameSizeUpdates(\n frame,\n heldFrameSize(frame, yogaNode, holds),\n computed,\n keepsSaved ? frame.derivedLayout : null,\n (axis) => keepsSaved && preservesImportedHugCrossSize(graph, frame, axis),\n holds\n )\n if (Object.keys(updates).length === 0) return\n writeLayoutGeometry(graph, frame.id, updates, computeLayout, before ?? undefined)\n if (before) huggedSizes.set(frame, { width: frame.width, height: frame.height })\n}\n\nfunction computedChildPosition(\n child: SceneNode,\n yogaChild: YogaNode,\n axis: 'x' | 'y',\n origin: number,\n preservesImportedGeometry: boolean,\n keepsSaved: boolean\n): number {\n if (preservesImportedGeometry) return child[axis]\n const computed =\n origin + (axis === 'x' ? yogaChild.getComputedLeft() : yogaChild.getComputedTop())\n if (child.type === 'INSTANCE' || !keepsSaved) return computed\n return child.derivedLayout?.[axis] ?? computed\n}\n\nfunction preservesStaleImportedTextSize(child: SceneNode, axis: 'width' | 'height'): boolean {\n const derivedSize = child.derivedLayout?.[axis]\n return (\n child.type === 'TEXT' &&\n child.source.format === 'fig' &&\n derivedSize !== undefined &&\n Math.abs(child[axis] - derivedSize) > 0.001\n )\n}\n\nfunction computedChildSize(\n child: SceneNode,\n yogaChild: YogaNode,\n axis: 'width' | 'height',\n preservesImportedFrameGeometry: boolean,\n keepsSaved: boolean\n): number {\n if (\n preservesImportedFrameGeometry ||\n (keepsSaved && preservesStaleImportedTextSize(child, axis))\n ) {\n return child[axis]\n }\n const computed = axis === 'width' ? yogaChild.getComputedWidth() : yogaChild.getComputedHeight()\n if (child.type === 'TEXT' && child.source.format === 'fig') {\n return computed > 0 ? computed : child[axis]\n }\n if (!keepsSaved) return computed\n return child.derivedLayout?.[axis] ?? computed\n}\n\nfunction updateChildFromYoga(\n graph: SceneGraph,\n frame: SceneNode,\n child: SceneNode,\n yogaChild: YogaNode,\n origin: Vector,\n keepsSaved: boolean,\n computeLayout: ComputeLayoutFn\n): void {\n if (!child.visible || child.layoutPositioning === 'ABSOLUTE') return\n\n const savedFig = keepsSaved && child.source.format === 'fig'\n const preservesImportedFrameGeometry =\n savedFig && frame.source.format === 'fig' && (child.type === 'FRAME' || child.type === 'LINE')\n const preservesImportedPosition =\n preservesImportedFrameGeometry || (savedFig && Math.abs(child.rotation) > 0.001)\n writeLayoutGeometry(\n graph,\n child.id,\n {\n x: computedChildPosition(\n child,\n yogaChild,\n 'x',\n origin.x,\n preservesImportedPosition,\n keepsSaved\n ),\n y: computedChildPosition(\n child,\n yogaChild,\n 'y',\n origin.y,\n preservesImportedPosition,\n keepsSaved\n ),\n width: computedChildSize(\n child,\n yogaChild,\n 'width',\n preservesImportedFrameGeometry,\n keepsSaved\n ),\n height: computedChildSize(\n child,\n yogaChild,\n 'height',\n preservesImportedFrameGeometry,\n keepsSaved\n )\n },\n computeLayout\n )\n}\n\nfunction preservesImportedInstanceInternals(child: SceneNode): boolean {\n return child.type === 'INSTANCE' && child.source.format === 'fig'\n}\n\nfunction recomputeGridChild(\n graph: SceneGraph,\n child: SceneNode,\n computeLayout: ComputeLayoutFn\n): void {\n const updated = graph.getNode(child.id)\n if (!updated || updated.layoutMode === 'NONE') return\n\n const savedPrimary = updated.primaryAxisSizing\n const savedCounter = updated.counterAxisSizing\n const updates: Partial<SceneNode> = {}\n\n if (savedPrimary === 'HUG') updates.primaryAxisSizing = 'FIXED'\n if (savedCounter === 'HUG') updates.counterAxisSizing = 'FIXED'\n if (Object.keys(updates).length > 0) graph.updateNode(child.id, updates)\n\n computeLayout(graph, child.id)\n\n const restore: Partial<SceneNode> = {}\n if (updates.primaryAxisSizing) restore.primaryAxisSizing = savedPrimary\n if (updates.counterAxisSizing) restore.counterAxisSizing = savedCounter\n if (Object.keys(restore).length > 0) graph.updateNode(child.id, restore)\n}\n\nexport function applyYogaLayout(\n graph: SceneGraph,\n frame: SceneNode,\n yogaNode: YogaNode,\n computeLayout: ComputeLayoutFn\n): void {\n const keepsSaved = keepsSavedLayout(graph, frame)\n applyFrameSize(graph, frame, yogaNode, keepsSaved, computeLayout)\n\n const children = graph.getChildren(frame.id)\n const box = laidOutFlowBox(yogaNode, frame)\n let yogaIndex = 0\n for (const child of children) {\n if (yogaIndex >= box.node.getChildCount()) continue\n const yogaChild = box.node.getChild(yogaIndex)\n yogaIndex++\n\n updateChildFromYoga(graph, frame, child, yogaChild, box.origin, keepsSaved, computeLayout)\n\n if (!child.visible) continue\n if (preservesImportedInstanceInternals(child)) continue\n\n if (usesDetachedDerivedLayout(graph, child)) {\n computeLayout(graph, child.id)\n continue\n }\n\n if (child.layoutMode !== 'NONE') {\n if (child.layoutMode === 'GRID' && child.layoutPositioning !== 'ABSOLUTE') {\n computeLayout(graph, child.id)\n } else if (frame.layoutMode === 'GRID' && child.layoutPositioning !== 'ABSOLUTE') {\n recomputeGridChild(graph, child, computeLayout)\n } else {\n applyYogaLayout(graph, child, yogaChild, computeLayout)\n }\n }\n }\n}\n"],"mappings":";;;;;;AA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AAc,OAAO,MAAM,EAAE;CAE7B,MAAM,UAA8B,CAAC;CACrC,IAAI,QAAQ,mBAAmB,QAAQ,oBAAoB;CAC3D,IAAI,QAAQ,mBAAmB,QAAQ,oBAAoB;CAC3D,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,GAAG,MAAM,WAAW,MAAM,IAAI,OAAO;AACzE;AAEA,SAAgB,gBACd,OACA,OACA,UACA,eACM;CACN,MAAM,aAAa,iBAAiB,OAAO,KAAK;CAChD,eAAe,OAAO,OAAO,UAAU,YAAY,aAAa;CAEhE,MAAM,WAAW,MAAM,YAAY,MAAM,EAAE;CAC3C,MAAM,MAAM,eAAe,UAAU,KAAK;CAC1C,IAAI,YAAY;CAChB,KAAK,MAAM,SAAS,UAAU;EAC5B,IAAI,aAAa,IAAI,KAAK,cAAc,GAAG;EAC3C,MAAM,YAAY,IAAI,KAAK,SAAS,SAAS;EAC7C;EAEA,oBAAoB,OAAO,OAAO,OAAO,WAAW,IAAI,QAAQ,YAAY,aAAa;EAEzF,IAAI,CAAC,MAAM,SAAS;EACpB,IAAI,mCAAmC,KAAK,GAAG;EAE/C,IAAI,0BAA0B,OAAO,KAAK,GAAG;GAC3C,cAAc,OAAO,MAAM,EAAE;GAC7B;EACF;EAEA,IAAI,MAAM,eAAe,QAAQ;GAC/B,IAAI,MAAM,eAAe,UAAU,MAAM,sBAAsB,YAC7D,cAAc,OAAO,MAAM,EAAE;QACxB,IAAI,MAAM,eAAe,UAAU,MAAM,sBAAsB,YACpE,mBAAmB,OAAO,OAAO,aAAa;QAE9C,gBAAgB,OAAO,OAAO,WAAW,aAAa;EAE1D;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"apply.js","names":[],"sources":["../../src/layout/apply.ts"],"sourcesContent":["import type { Node as YogaNode } from 'yoga-layout'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { enforcedAspectRatio } from '@pairdraw/scene-graph/layout'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\nimport { layoutConstrainedChildRect, shapeGeometryChanges } from '@pairdraw/scene-graph/resize'\n\nimport { keepsSavedFrameSize, keepsSavedLayout, usesDetachedDerivedLayout } from './derived'\nimport { laidOutFlowBox } from './flow-edges'\nimport { gridChildBox } from './grid'\nimport { contentInsetsSize } from './strokes'\n\nexport type ComputeLayoutFn = (graph: SceneGraph, frameId: string) => void\n\nfunction preservesImportedHugCrossSize(\n graph: SceneGraph,\n frame: SceneNode,\n axis: 'width' | 'height'\n): boolean {\n if (frame.source.format !== 'fig' || frame.counterAxisSizing !== 'HUG') return false\n const expectedMode = axis === 'width' ? 'VERTICAL' : 'HORIZONTAL'\n if (frame.layoutMode !== expectedMode) return false\n return graph\n .getChildren(frame.id)\n .some(\n (child) => child.layoutAlignSelf === 'STRETCH' && child.derivedLayout?.[axis] !== undefined\n )\n}\n\ntype LayoutGeometry = Partial<Pick<SceneNode, 'x' | 'y' | 'width' | 'height'>>\n\n/**\n * Writes only the geometry layout changed. Laying out a large page leaves most layers where they\n * were, and each write would notify every graph listener for nothing. A frame it resizes from\n * `before`, by default the size it has, places the layers its constraints govern; `constrained`\n * marks a write those constraints made, which places its own children in turn.\n */\nfunction writeLayoutGeometry(\n graph: SceneGraph,\n id: string,\n geometry: LayoutGeometry,\n computeLayout: ComputeLayoutFn,\n before?: { width: number; height: number },\n constrained = false\n): void {\n const node = graph.getNode(id)\n if (!node) return\n const from = before ?? { width: node.width, height: node.height }\n const changes: LayoutGeometry = {}\n for (const key of ['x', 'y', 'width', 'height'] as const) {\n const value = geometry[key]\n // A container whose size no arithmetic can use makes Yoga answer NaN for a child's place\n // (BASELINE alignment in a wrap is one); the layer stays where it was.\n if (value === undefined || !Number.isFinite(value) || value === node[key]) continue\n changes[key] = value\n }\n const resized = changes.width !== undefined || changes.height !== undefined\n const outlines = resized\n ? shapeGeometryChanges(node, changes.width ?? node.width, changes.height ?? node.height)\n : {}\n if (Object.keys(changes).length + Object.keys(outlines).length > 0) {\n graph.updateNode(id, { ...changes, ...outlines })\n }\n if (!CONSTRAINT_PARENT_TYPES.has(node.type)) return\n // Laying out what a file holds, as a page opens or its fonts arrive, resizes a frame only where\n // our layout differs from the one the file saved; its children keep the places it saved.\n if (graph.isApplyingDerivedLayout && !constrained) return\n if (from.width !== node.width || from.height !== node.height) {\n constrainChildren(graph, node, from, computeLayout)\n rememberPlacedSize(node)\n }\n}\n\n/**\n * The size each Hug frame's constrained children were last placed for by layout. Keyed by the\n * node, so a deleted frame's entry goes with it and a restored one starts afresh.\n */\nconst huggedSizes = new WeakMap<SceneNode, { width: number; height: number }>()\n\n/**\n * Records a frame's size as the one its constrained children were placed for, after a rescale\n * scaled them with it: the next hug moves them from the scaled size, not twice from the old one.\n */\nexport function restoredHuggedSize(frame: SceneNode): void {\n if (huggedSizes.has(frame)) huggedSizes.set(frame, { width: frame.width, height: frame.height })\n}\n\nfunction rememberPlacedSize(frame: SceneNode): void {\n const placed = huggedSizes.get(frame)\n if (!placed) return\n placed.width = frame.width\n placed.height = frame.height\n}\n\nconst CONSTRAINT_PARENT_TYPES: ReadonlySet<SceneNode['type']> = new Set([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\n/**\n * Places the children of a frame layout resized by their constraints: every child of a frame\n * without auto layout, and those that ignore an auto layout, as Figma keeps a badge pinned to the\n * right of a Hug button while its label grows. A child it resizes places its own children, and\n * lays out again when it has auto layout.\n */\nfunction constrainChildren(\n graph: SceneGraph,\n frame: SceneNode,\n before: { width: number; height: number },\n computeLayout: ComputeLayoutFn\n): void {\n for (const child of graph.getChildren(frame.id)) {\n if (child.type === 'SLICE') continue\n if (frame.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE') continue\n const size = { width: child.width, height: child.height }\n writeLayoutGeometry(\n graph,\n child.id,\n layoutConstrainedChildRect(\n child,\n before,\n frame,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child),\n child\n ),\n computeLayout,\n undefined,\n true\n )\n const resized = child.width !== size.width || child.height !== size.height\n if (resized && child.layoutMode !== 'NONE') computeLayout(graph, child.id)\n }\n}\n\n/**\n * The size a frame's constrained children move from as it hugs, or null when it hugs no axis.\n * An editor that resizes a Hug frame places its children for the size it sets, which layout then\n * hugs back, as when a parent stretches it; its children move only from the size it last hugged\n * to. An axis it does not hug keeps the size it has.\n */\nfunction hugStart(frame: SceneNode): { width: number; height: number } | null {\n const row = frame.layoutMode === 'HORIZONTAL'\n const hugsWidth = (row ? frame.primaryAxisSizing : frame.counterAxisSizing) === 'HUG'\n const hugsHeight = (row ? frame.counterAxisSizing : frame.primaryAxisSizing) === 'HUG'\n if (!hugsWidth && !hugsHeight) {\n huggedSizes.delete(frame)\n return null\n }\n const hugged = huggedSizes.get(frame)\n return {\n width: hugsWidth && hugged ? hugged.width : frame.width,\n height: hugsHeight && hugged ? hugged.height : frame.height\n }\n}\n\n/**\n * The smallest size a layout frame holds: what Yoga computed for it, or the room its padding and\n * included inside strokes take, which Yoga's fixed size does not count. A saved frame nobody\n * edited holds exactly what Yoga computed, so opening a file never grows it.\n */\nfunction heldFrameSize(\n frame: SceneNode,\n yogaNode: YogaNode,\n holdsSavedSize: boolean\n): { width: number; height: number } {\n const insets = holdsSavedSize ? null : contentInsetsSize(frame)\n return {\n width: Math.max(yogaNode.getComputedWidth(), insets?.width ?? 0),\n height: Math.max(yogaNode.getComputedHeight(), insets?.height ?? 0)\n }\n}\n\n/** A grid's size: automatic rows take their height, and a hugged axis takes what Yoga computed. */\nfunction applyGridFrameSize(\n graph: SceneGraph,\n frame: SceneNode,\n yogaNode: YogaNode,\n computeLayout: ComputeLayoutFn\n): void {\n const updates: LayoutGeometry = {}\n const holds = keepsSavedFrameSize(graph, frame)\n const held = heldFrameSize(frame, yogaNode, holds)\n if (frame.primaryAxisSizing === 'HUG') updates.width = held.width\n else if (!holds && held.width > frame.width) updates.width = held.width\n const automaticRows = frame.gridTemplateRows.length === 0\n if (automaticRows || frame.counterAxisSizing === 'HUG') updates.height = held.height\n else if (!holds && held.height > frame.height) updates.height = held.height\n writeLayoutGeometry(graph, frame.id, updates, computeLayout)\n}\n\n/** The sizes a flex frame takes: a fixed one grows to its padding, and a hugged one hugs. */\nfunction flexFrameSizeUpdates(\n frame: SceneNode,\n held: { width: number; height: number },\n computed: (axis: 'width' | 'height') => number,\n derived: Partial<Record<'width' | 'height', number>> | null,\n keepsSavedSize: (axis: 'width' | 'height') => boolean,\n holdsSavedSize: boolean\n): LayoutGeometry {\n const primary = frame.layoutMode === 'HORIZONTAL' ? 'width' : 'height'\n const counter = primary === 'width' ? 'height' : 'width'\n const updates: LayoutGeometry = {}\n // The padding floor is an edit: a saved frame nobody touched keeps the size it has.\n if (frame.primaryAxisSizing === 'FIXED' && !holdsSavedSize && held[primary] > frame[primary]) {\n updates[primary] = held[primary]\n }\n if (frame.counterAxisSizing === 'FIXED' && !holdsSavedSize && held[counter] > frame[counter]) {\n updates[counter] = held[counter]\n }\n if (frame.primaryAxisSizing === 'HUG') {\n const floor = holdsSavedSize ? 0 : held[primary]\n updates[primary] = Math.max(derived?.[primary] ?? computed(primary), floor)\n }\n if (frame.counterAxisSizing === 'HUG') {\n const floor = holdsSavedSize ? 0 : held[counter]\n updates[counter] = Math.max(\n keepsSavedSize(counter) ? frame[counter] : (derived?.[counter] ?? computed(counter)),\n floor\n )\n }\n return updates\n}\n\nfunction applyFrameSize(\n graph: SceneGraph,\n frame: SceneNode,\n yogaNode: YogaNode,\n keepsSaved: boolean,\n computeLayout: ComputeLayoutFn\n): void {\n if (frame.layoutMode === 'GRID') {\n applyGridFrameSize(graph, frame, yogaNode, computeLayout)\n return\n }\n\n const before = hugStart(frame)\n const computed = (axis: 'width' | 'height') =>\n axis === 'width' ? yogaNode.getComputedWidth() : yogaNode.getComputedHeight()\n const holds = keepsSavedFrameSize(graph, frame)\n const updates = flexFrameSizeUpdates(\n frame,\n heldFrameSize(frame, yogaNode, holds),\n computed,\n keepsSaved ? frame.derivedLayout : null,\n (axis) => keepsSaved && preservesImportedHugCrossSize(graph, frame, axis),\n holds\n )\n if (Object.keys(updates).length === 0) return\n writeLayoutGeometry(graph, frame.id, updates, computeLayout, before ?? undefined)\n if (before) huggedSizes.set(frame, { width: frame.width, height: frame.height })\n}\n\nfunction computedChildPosition(\n child: SceneNode,\n yogaChild: YogaNode,\n axis: 'x' | 'y',\n origin: number,\n preservesImportedGeometry: boolean,\n keepsSaved: boolean\n): number {\n if (preservesImportedGeometry) return child[axis]\n const layer = gridChildBox(yogaChild) ?? yogaChild\n const computed =\n origin +\n (axis === 'x'\n ? yogaChild.getComputedLeft() + (layer === yogaChild ? 0 : layer.getComputedLeft())\n : yogaChild.getComputedTop() + (layer === yogaChild ? 0 : layer.getComputedTop()))\n if (child.type === 'INSTANCE' || !keepsSaved) return computed\n return child.derivedLayout?.[axis] ?? computed\n}\n\nfunction preservesStaleImportedTextSize(child: SceneNode, axis: 'width' | 'height'): boolean {\n const derivedSize = child.derivedLayout?.[axis]\n return (\n child.type === 'TEXT' &&\n child.source.format === 'fig' &&\n derivedSize !== undefined &&\n Math.abs(child[axis] - derivedSize) > 0.001\n )\n}\n\nfunction computedChildSize(\n child: SceneNode,\n yogaChild: YogaNode,\n axis: 'width' | 'height',\n preservesImportedFrameGeometry: boolean,\n keepsSaved: boolean\n): number {\n if (\n preservesImportedFrameGeometry ||\n (keepsSaved && preservesStaleImportedTextSize(child, axis))\n ) {\n return child[axis]\n }\n const layer = gridChildBox(yogaChild) ?? yogaChild\n const computed = axis === 'width' ? layer.getComputedWidth() : layer.getComputedHeight()\n if (child.type === 'TEXT' && child.source.format === 'fig') {\n return computed > 0 ? computed : child[axis]\n }\n if (!keepsSaved) return computed\n return child.derivedLayout?.[axis] ?? computed\n}\n\nfunction updateChildFromYoga(\n graph: SceneGraph,\n frame: SceneNode,\n child: SceneNode,\n yogaChild: YogaNode,\n origin: Vector,\n keepsSaved: boolean,\n computeLayout: ComputeLayoutFn\n): void {\n if (!child.visible || child.layoutPositioning === 'ABSOLUTE') return\n\n const savedFig = keepsSaved && child.source.format === 'fig'\n const preservesImportedFrameGeometry =\n savedFig && frame.source.format === 'fig' && (child.type === 'FRAME' || child.type === 'LINE')\n const preservesImportedPosition =\n preservesImportedFrameGeometry || (savedFig && Math.abs(child.rotation) > 0.001)\n writeLayoutGeometry(\n graph,\n child.id,\n {\n x: computedChildPosition(\n child,\n yogaChild,\n 'x',\n origin.x,\n preservesImportedPosition,\n keepsSaved\n ),\n y: computedChildPosition(\n child,\n yogaChild,\n 'y',\n origin.y,\n preservesImportedPosition,\n keepsSaved\n ),\n width: computedChildSize(\n child,\n yogaChild,\n 'width',\n preservesImportedFrameGeometry,\n keepsSaved\n ),\n height: computedChildSize(\n child,\n yogaChild,\n 'height',\n preservesImportedFrameGeometry,\n keepsSaved\n )\n },\n computeLayout\n )\n}\n\nfunction preservesImportedInstanceInternals(child: SceneNode): boolean {\n return child.type === 'INSTANCE' && child.source.format === 'fig'\n}\n\nfunction recomputeGridChild(\n graph: SceneGraph,\n child: SceneNode,\n computeLayout: ComputeLayoutFn\n): void {\n const updated = graph.getNode(child.id)\n if (!updated || updated.layoutMode === 'NONE') return\n\n const savedPrimary = updated.primaryAxisSizing\n const savedCounter = updated.counterAxisSizing\n const updates: Partial<SceneNode> = {}\n\n if (savedPrimary === 'HUG') updates.primaryAxisSizing = 'FIXED'\n if (savedCounter === 'HUG') updates.counterAxisSizing = 'FIXED'\n if (Object.keys(updates).length > 0) graph.updateNode(child.id, updates)\n\n computeLayout(graph, child.id)\n\n const restore: Partial<SceneNode> = {}\n if (updates.primaryAxisSizing) restore.primaryAxisSizing = savedPrimary\n if (updates.counterAxisSizing) restore.counterAxisSizing = savedCounter\n if (Object.keys(restore).length > 0) graph.updateNode(child.id, restore)\n}\n\nexport function applyYogaLayout(\n graph: SceneGraph,\n frame: SceneNode,\n yogaNode: YogaNode,\n computeLayout: ComputeLayoutFn\n): void {\n const keepsSaved = keepsSavedLayout(graph, frame)\n applyFrameSize(graph, frame, yogaNode, keepsSaved, computeLayout)\n\n const children = graph.getChildren(frame.id).filter((child) => child.type !== 'SLICE')\n const box = laidOutFlowBox(yogaNode, frame)\n let yogaIndex = 0\n for (const child of children) {\n if (yogaIndex >= box.node.getChildCount()) continue\n const yogaChild = box.node.getChild(yogaIndex)\n yogaIndex++\n\n updateChildFromYoga(graph, frame, child, yogaChild, box.origin, keepsSaved, computeLayout)\n\n if (!child.visible) continue\n if (preservesImportedInstanceInternals(child)) continue\n\n if (usesDetachedDerivedLayout(graph, child)) {\n computeLayout(graph, child.id)\n continue\n }\n\n if (child.layoutMode !== 'NONE') {\n if (child.layoutMode === 'GRID' && child.layoutPositioning !== 'ABSOLUTE') {\n computeLayout(graph, child.id)\n } else if (frame.layoutMode === 'GRID' && child.layoutPositioning !== 'ABSOLUTE') {\n recomputeGridChild(graph, child, computeLayout)\n } else {\n applyYogaLayout(graph, child, yogaChild, computeLayout)\n }\n }\n }\n}\n"],"mappings":";;;;;;;AAcA,SAAS,8BACP,OACA,OACA,MACS;CACT,IAAI,MAAM,OAAO,WAAW,SAAS,MAAM,sBAAsB,OAAO,OAAO;CAC/E,MAAM,eAAe,SAAS,UAAU,aAAa;CACrD,IAAI,MAAM,eAAe,cAAc,OAAO;CAC9C,OAAO,MACJ,YAAY,MAAM,EAAE,CAAC,CACrB,MACE,UAAU,MAAM,oBAAoB,aAAa,MAAM,gBAAgB,UAAU,KAAA,CACpF;AACJ;;;;;;;AAUA,SAAS,oBACP,OACA,IACA,UACA,eACA,QACA,cAAc,OACR;CACN,MAAM,OAAO,MAAM,QAAQ,EAAE;CAC7B,IAAI,CAAC,MAAM;CACX,MAAM,OAAO,UAAU;EAAE,OAAO,KAAK;EAAO,QAAQ,KAAK;CAAO;CAChE,MAAM,UAA0B,CAAC;CACjC,KAAK,MAAM,OAAO;EAAC;EAAK;EAAK;EAAS;CAAQ,GAAY;EACxD,MAAM,QAAQ,SAAS;EAGvB,IAAI,UAAU,KAAA,KAA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O;CACrF,MAAM,MAAM,eAAe,UAAU,KAAK;CAC1C,IAAI,YAAY;CAChB,KAAK,MAAM,SAAS,UAAU;EAC5B,IAAI,aAAa,IAAI,KAAK,cAAc,GAAG;EAC3C,MAAM,YAAY,IAAI,KAAK,SAAS,SAAS;EAC7C;EAEA,oBAAoB,OAAO,OAAO,OAAO,WAAW,IAAI,QAAQ,YAAY,aAAa;EAEzF,IAAI,CAAC,MAAM,SAAS;EACpB,IAAI,mCAAmC,KAAK,GAAG;EAE/C,IAAI,0BAA0B,OAAO,KAAK,GAAG;GAC3C,cAAc,OAAO,MAAM,EAAE;GAC7B;EACF;EAEA,IAAI,MAAM,eAAe,QAAQ;GAC/B,IAAI,MAAM,eAAe,UAAU,MAAM,sBAAsB,YAC7D,cAAc,OAAO,MAAM,EAAE;QACxB,IAAI,MAAM,eAAe,UAAU,MAAM,sBAAsB,YACpE,mBAAmB,OAAO,OAAO,aAAa;QAE9C,gBAAgB,OAAO,OAAO,WAAW,aAAa;EAE1D;CACF;AACF"}
|
|
@@ -133,7 +133,7 @@ function edgeDistance(handle, x, y) {
|
|
|
133
133
|
}
|
|
134
134
|
function measureAutoLayoutHandles(node, children) {
|
|
135
135
|
if (!node || node.layoutMode !== "HORIZONTAL" && node.layoutMode !== "VERTICAL") return null;
|
|
136
|
-
const laidOut = children.filter((child) => child.visible && child.layoutPositioning !== "ABSOLUTE");
|
|
136
|
+
const laidOut = children.filter((child) => child.visible && child.type !== "SLICE" && child.layoutPositioning !== "ABSOLUTE");
|
|
137
137
|
const padding = [];
|
|
138
138
|
for (const side of [
|
|
139
139
|
"top",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-layout-handles.js","names":[],"sources":["../../src/layout/auto-layout-handles.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\nimport { isGeneratedFrame } from '@pairdraw/scene-graph/generated'\n\n/** The side of a frame a padding handle edits. */\nexport type AutoLayoutPaddingSide = 'top' | 'right' | 'bottom' | 'left'\n\n/** A rectangle in the frame's own coordinates, the space a handle occupies. */\nexport interface AutoLayoutHandleRect {\n x: number\n y: number\n width: number\n height: number\n}\n\nexport interface AutoLayoutPaddingHandle {\n kind: 'padding'\n side: AutoLayoutPaddingSide\n rect: AutoLayoutHandleRect\n value: number\n}\n\nexport interface AutoLayoutGapHandle {\n kind: 'gap'\n /** The gap the flow lays out, or the gap between wrapped lines. */\n axis: 'primary' | 'counter'\n /** The child the gap starts after, on the primary axis. */\n index: number\n rect: AutoLayoutHandleRect\n value: number\n}\n\nexport type AutoLayoutHandle = AutoLayoutPaddingHandle | AutoLayoutGapHandle\nexport type AutoLayoutHandleHit =\n | Pick<AutoLayoutPaddingHandle, 'kind' | 'side'>\n | Pick<AutoLayoutGapHandle, 'kind' | 'axis' | 'index'>\n\nexport interface AutoLayoutHandleLayout {\n nodeId: string\n layoutMode: 'HORIZONTAL' | 'VERTICAL'\n /** False where no edit can land, such as a generated frame's own layout. */\n editable: boolean\n padding: AutoLayoutPaddingHandle[]\n gaps: AutoLayoutGapHandle[]\n}\n\nexport interface AutoLayoutDragInput {\n /** Pointer movement on screen, in pixels. */\n dx: number\n dy: number\n zoom: number\n /** Alt edits the opposite side on the dragged axis; with Shift, every side. */\n alt: boolean\n /** Shift moves padding or spacing by the large nudge. */\n shift: boolean\n /** The large nudge distance, as Settings → Editor sets it. */\n bigNudge?: number\n}\n\nexport interface AutoLayoutDragChanges {\n /** The new value of the dragged property, clamped to zero. */\n value: number\n changes: Partial<\n Pick<\n SceneNode,\n | 'paddingTop'\n | 'paddingRight'\n | 'paddingBottom'\n | 'paddingLeft'\n | 'itemSpacing'\n | 'counterAxisSpacing'\n >\n >\n}\n\n/** The gap between two neighbouring children, in the frame's coordinates. */\nfunction primaryGapRects(\n node: SceneNode,\n children: readonly SceneNode[]\n): Array<{ index: number; rect: AutoLayoutHandleRect }> {\n if (children.length < 2 || node.itemSpacing <= 0 || node.primaryAxisAlign === 'SPACE_BETWEEN')\n return []\n const isRow = node.layoutMode === 'HORIZONTAL'\n const rects: Array<{ index: number; rect: AutoLayoutHandleRect }> = []\n for (let index = 0; index < children.length - 1; index++) {\n const prev = children[index]\n const next = children[index + 1]\n const prevStart = isRow ? prev.x : prev.y\n const prevEnd = isRow ? prev.x + prev.width : prev.y + prev.height\n const nextStart = isRow ? next.x : next.y\n const nextEnd = isRow ? next.x + next.width : next.y + next.height\n // A reversed flow (RTL rows, for one) lays the next child before the previous one.\n const start = nextStart >= prevStart ? prevEnd : nextEnd\n const end = nextStart >= prevStart ? nextStart : prevStart\n if (end <= start) continue\n rects.push(\n isRow\n ? {\n index,\n rect: {\n x: start,\n y: node.paddingTop,\n width: end - start,\n height: node.height - node.paddingTop - node.paddingBottom\n }\n }\n : {\n index,\n rect: {\n x: node.paddingLeft,\n y: start,\n width: node.width - node.paddingLeft - node.paddingRight,\n height: end - start\n }\n }\n )\n }\n return rects\n}\n\n/**\n * The gap between wrapped lines, which a wrapping flow lays out with counterAxisSpacing. Lines are\n * grouped by their position so a line with different item sizes still yields one gap.\n */\nfunction counterGapRects(\n node: SceneNode,\n children: readonly SceneNode[]\n): Array<{ index: number; rect: AutoLayoutHandleRect }> {\n if (node.layoutWrap !== 'WRAP' || node.counterAxisSpacing <= 0 || children.length < 2) return []\n const isRow = node.layoutMode === 'HORIZONTAL'\n const lines: Array<{ start: number; end: number }> = []\n for (const child of children) {\n const start = isRow ? child.y : child.x\n const end = isRow ? child.y + child.height : child.x + child.width\n // A centered or baseline line aligns children with different sizes at different starts.\n const line = lines.find((candidate) => start <= candidate.end && end >= candidate.start)\n if (line) {\n line.start = Math.min(line.start, start)\n line.end = Math.max(line.end, end)\n } else {\n lines.push({ start, end })\n }\n }\n const sorted = lines.sort((left, right) => left.start - right.start)\n const rects: Array<{ index: number; rect: AutoLayoutHandleRect }> = []\n for (let index = 0; index < sorted.length - 1; index++) {\n const previous = sorted[index]\n const next = sorted[index + 1]\n if (next.start <= previous.end) continue\n rects.push(\n isRow\n ? {\n index,\n rect: {\n x: node.paddingLeft,\n y: previous.end,\n width: node.width - node.paddingLeft - node.paddingRight,\n height: next.start - previous.end\n }\n }\n : {\n index,\n rect: {\n x: previous.end,\n y: node.paddingTop,\n width: next.start - previous.end,\n height: node.height - node.paddingTop - node.paddingBottom\n }\n }\n )\n }\n return rects\n}\n\n/** The padding and gap zones of an auto-layout frame, in its own coordinates. */\nconst PADDING_FIELD = {\n top: 'paddingTop',\n right: 'paddingRight',\n bottom: 'paddingBottom',\n left: 'paddingLeft'\n} as const\n\nfunction paddingValue(node: SceneNode, side: AutoLayoutPaddingSide): number {\n return node[PADDING_FIELD[side]]\n}\n\n/** The band a padding side occupies, in the frame's coordinates. */\nfunction paddingBand(\n node: SceneNode,\n side: AutoLayoutPaddingSide,\n value: number\n): AutoLayoutHandleRect {\n switch (side) {\n case 'top':\n return { x: 0, y: 0, width: node.width, height: value }\n case 'right':\n return { x: node.width - value, y: 0, width: value, height: node.height }\n case 'bottom':\n return { x: 0, y: node.height - value, width: node.width, height: value }\n case 'left':\n return { x: 0, y: 0, width: value, height: node.height }\n default:\n throw new Error('Unknown padding side')\n }\n}\n\n/** The frame edge a padding handle hugs, so the nearest of two meeting bands wins. */\nfunction edgeDistance(handle: AutoLayoutPaddingHandle, x: number, y: number): number {\n switch (handle.side) {\n case 'top':\n return y\n case 'bottom':\n return handle.rect.y + handle.rect.height - y\n case 'left':\n return x\n case 'right':\n return handle.rect.x + handle.rect.width - x\n default:\n throw new Error('Unknown padding side')\n }\n}\n\nexport function measureAutoLayoutHandles(\n node: SceneNode | undefined,\n children: readonly SceneNode[]\n): AutoLayoutHandleLayout | null {\n if (!node || (node.layoutMode !== 'HORIZONTAL' && node.layoutMode !== 'VERTICAL')) return null\n const laidOut = children.filter(\n (child) => child.visible && child.layoutPositioning !== 'ABSOLUTE'\n )\n const padding: AutoLayoutPaddingHandle[] = []\n const sides: AutoLayoutPaddingSide[] = ['top', 'right', 'bottom', 'left']\n for (const side of sides) {\n const value = paddingValue(node, side)\n if (value <= 0) continue\n padding.push({ kind: 'padding', side, rect: paddingBand(node, side, value), value })\n }\n const gaps: AutoLayoutGapHandle[] = [\n ...primaryGapRects(node, laidOut).map(({ index, rect }) => ({\n kind: 'gap' as const,\n axis: 'primary' as const,\n index,\n rect,\n value: node.itemSpacing\n })),\n ...counterGapRects(node, laidOut).map(({ index, rect }) => ({\n kind: 'gap' as const,\n axis: 'counter' as const,\n index,\n rect,\n value: node.counterAxisSpacing\n }))\n ]\n return {\n nodeId: node.id,\n layoutMode: node.layoutMode,\n editable: !isGeneratedFrame(node),\n padding,\n gaps\n }\n}\n\nfunction contains(rect: AutoLayoutHandleRect, x: number, y: number, grow = 0): boolean {\n return (\n x >= rect.x - grow &&\n x <= rect.x + rect.width + grow &&\n y >= rect.y - grow &&\n y <= rect.y + rect.height + grow\n )\n}\n\n/**\n * The padding or gap handle under a point in the frame's coordinates. Padding wins where it meets a\n * gap, and the nearest frame edge wins in a corner where two padding bands meet.\n */\nexport function hitAutoLayoutHandle(\n layout: AutoLayoutHandleLayout | null,\n x: number,\n y: number\n): AutoLayoutHandleHit | null {\n if (!layout) return null\n let nearest: AutoLayoutPaddingHandle | null = null\n for (const handle of layout.padding) {\n if (!contains(handle.rect, x, y)) continue\n if (!nearest || edgeDistance(handle, x, y) <= edgeDistance(nearest, x, y)) nearest = handle\n }\n if (nearest) return { kind: 'padding', side: nearest.side }\n for (const handle of layout.gaps) {\n if (contains(handle.rect, x, y)) {\n return { kind: 'gap', axis: handle.axis, index: handle.index }\n }\n }\n return null\n}\n\nfunction handleFor(\n layout: AutoLayoutHandleLayout,\n hit: AutoLayoutHandleHit\n): AutoLayoutHandle | null {\n if (hit.kind === 'padding') {\n return layout.padding.find((handle) => handle.side === hit.side) ?? null\n }\n return (\n layout.gaps.find((handle) => handle.axis === hit.axis && handle.index === hit.index) ?? null\n )\n}\n\n/** Movement along the axis a padding side grows in. */\nfunction paddingDelta(side: AutoLayoutPaddingSide, dx: number, dy: number): number {\n switch (side) {\n case 'top':\n return dy\n case 'bottom':\n return -dy\n case 'left':\n return dx\n case 'right':\n return -dx\n default:\n throw new Error('Unknown padding side')\n }\n}\n\n/** Movement across the gaps of a flow: primary along it, counter across it. */\nfunction gapDelta(\n layoutMode: 'HORIZONTAL' | 'VERTICAL',\n axis: AutoLayoutGapHandle['axis'],\n dx: number,\n dy: number\n): number {\n const horizontal = layoutMode === 'HORIZONTAL'\n if (axis === 'counter') return horizontal ? dy : dx\n return horizontal ? dx : dy\n}\n\n/** The rounded, non-negative value a drag would set for the grabbed handle. */\nexport function autoLayoutDragValue(\n layout: AutoLayoutHandleLayout,\n hit: AutoLayoutHandleHit,\n input: AutoLayoutDragInput\n): number {\n const handle = handleFor(layout, hit)\n if (!handle) return 0\n const zoom = input.zoom > 0 ? input.zoom : 1\n const delta =\n handle.kind === 'padding'\n ? paddingDelta(handle.side, input.dx, input.dy)\n : gapDelta(layout.layoutMode, handle.axis, input.dx, input.dy)\n const raw = handle.value + delta / zoom\n // Shift moves padding and spacing by the large nudge, as Settings → Editor sets it.\n const step = input.bigNudge && input.bigNudge > 0 ? input.bigNudge : 10\n return Math.max(0, input.shift ? Math.round(raw / step) * step : Math.round(raw))\n}\n\n/** The properties a drag writes for the grabbed handle, with Alt and Shift expanding padding. */\nexport function autoLayoutDragChanges(\n layout: AutoLayoutHandleLayout,\n hit: AutoLayoutHandleHit,\n input: AutoLayoutDragInput\n): AutoLayoutDragChanges {\n const value = autoLayoutDragValue(layout, hit, input)\n if (hit.kind === 'padding') {\n if (input.alt && input.shift) {\n return {\n value,\n changes: {\n paddingTop: value,\n paddingRight: value,\n paddingBottom: value,\n paddingLeft: value\n }\n }\n }\n if (input.alt) {\n switch (hit.side) {\n case 'top':\n case 'bottom':\n return { value, changes: { paddingTop: value, paddingBottom: value } }\n case 'left':\n case 'right':\n return { value, changes: { paddingLeft: value, paddingRight: value } }\n }\n }\n switch (hit.side) {\n case 'top':\n return { value, changes: { paddingTop: value } }\n case 'right':\n return { value, changes: { paddingRight: value } }\n case 'bottom':\n return { value, changes: { paddingBottom: value } }\n case 'left':\n return { value, changes: { paddingLeft: value } }\n }\n }\n if (hit.axis === 'counter') return { value, changes: { counterAxisSpacing: value } }\n return { value, changes: { itemSpacing: value } }\n}\n"],"mappings":";;;AA2EA,SAAS,gBACP,MACA,UACsD;CACtD,IAAI,SAAS,SAAS,KAAK,KAAK,eAAe,KAAK,KAAK,qBAAqB,iBAC5E,OAAO,CAAC;CACV,MAAM,QAAQ,KAAK,eAAe;CAClC,MAAM,QAA8D,CAAC;CACrE,KAAK,IAAI,QAAQ,GAAG,QAAQ,SAAS,SAAS,GAAG,SAAS;EACxD,MAAM,OAAO,SAAS;EACtB,MAAM,OAAO,SAAS,QAAQ;EAC9B,MAAM,YAAY,QAAQ,KAAK,IAAI,KAAK;EACxC,MAAM,UAAU,QAAQ,KAAK,IAAI,KAAK,QAAQ,KAAK,IAAI,KAAK;EAC5D,MAAM,YAAY,QAAQ,KAAK,IAAI,KAAK;EACxC,MAAM,UAAU,QAAQ,KAAK,IAAI,KAAK,QAAQ,KAAK,IAAI,KAAK;EAE5D,MAAM,QAAQ,aAAa,YAAY,UAAU;EACjD,MAAM,MAAM,aAAa,YAAY,YAAY;EACjD,IAAI,OAAO,OAAO;EAClB,MAAM,KACJ,QACI;GACE;GACA,MAAM;IACJ,GAAG;IACH,GAAG,KAAK;IACR,OAAO,MAAM;IACb,QAAQ,KAAK,SAAS,KAAK,aAAa,KAAK;GAC/C;EACF,IACA;GACE;GACA,MAAM;IACJ,GAAG,KAAK;IACR,GAAG;IACH,OAAO,KAAK,QAAQ,KAAK,cAAc,KAAK;IAC5C,QAAQ,MAAM;GAChB;EACF,CACN;CACF;CACA,OAAO;AACT;;;;;AAMA,SAAS,gBACP,MACA,UACsD;CACtD,IAAI,KAAK,eAAe,UAAU,KAAK,sBAAsB,KAAK,SAAS,SAAS,GAAG,OAAO,CAAC;CAC/F,MAAM,QAAQ,KAAK,eAAe;C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E,YAAY,MAAM;GAAE;GACjD,KAAK,SACH,OAAO;IAAE;IAAO,SAAS,EAAE,cAAc,MAAM;GAAE;GACnD,KAAK,UACH,OAAO;IAAE;IAAO,SAAS,EAAE,eAAe,MAAM;GAAE;GACpD,KAAK,QACH,OAAO;IAAE;IAAO,SAAS,EAAE,aAAa,MAAM;GAAE;EACpD;CACF;CACA,IAAI,IAAI,SAAS,WAAW,OAAO;EAAE;EAAO,SAAS,EAAE,oBAAoB,MAAM;CAAE;CACnF,OAAO;EAAE;EAAO,SAAS,EAAE,aAAa,MAAM;CAAE;AAClD"}
|
|
1
|
+
{"version":3,"file":"auto-layout-handles.js","names":[],"sources":["../../src/layout/auto-layout-handles.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\nimport { isGeneratedFrame } from '@pairdraw/scene-graph/generated'\n\n/** The side of a frame a padding handle edits. */\nexport type AutoLayoutPaddingSide = 'top' | 'right' | 'bottom' | 'left'\n\n/** A rectangle in the frame's own coordinates, the space a handle occupies. */\nexport interface AutoLayoutHandleRect {\n x: number\n y: number\n width: number\n height: number\n}\n\nexport interface AutoLayoutPaddingHandle {\n kind: 'padding'\n side: AutoLayoutPaddingSide\n rect: AutoLayoutHandleRect\n value: number\n}\n\nexport interface AutoLayoutGapHandle {\n kind: 'gap'\n /** The gap the flow lays out, or the gap between wrapped lines. */\n axis: 'primary' | 'counter'\n /** The child the gap starts after, on the primary axis. */\n index: number\n rect: AutoLayoutHandleRect\n value: number\n}\n\nexport type AutoLayoutHandle = AutoLayoutPaddingHandle | AutoLayoutGapHandle\nexport type AutoLayoutHandleHit =\n | Pick<AutoLayoutPaddingHandle, 'kind' | 'side'>\n | Pick<AutoLayoutGapHandle, 'kind' | 'axis' | 'index'>\n\nexport interface AutoLayoutHandleLayout {\n nodeId: string\n layoutMode: 'HORIZONTAL' | 'VERTICAL'\n /** False where no edit can land, such as a generated frame's own layout. */\n editable: boolean\n padding: AutoLayoutPaddingHandle[]\n gaps: AutoLayoutGapHandle[]\n}\n\nexport interface AutoLayoutDragInput {\n /** Pointer movement on screen, in pixels. */\n dx: number\n dy: number\n zoom: number\n /** Alt edits the opposite side on the dragged axis; with Shift, every side. */\n alt: boolean\n /** Shift moves padding or spacing by the large nudge. */\n shift: boolean\n /** The large nudge distance, as Settings → Editor sets it. */\n bigNudge?: number\n}\n\nexport interface AutoLayoutDragChanges {\n /** The new value of the dragged property, clamped to zero. */\n value: number\n changes: Partial<\n Pick<\n SceneNode,\n | 'paddingTop'\n | 'paddingRight'\n | 'paddingBottom'\n | 'paddingLeft'\n | 'itemSpacing'\n | 'counterAxisSpacing'\n >\n >\n}\n\n/** The gap between two neighbouring children, in the frame's coordinates. */\nfunction primaryGapRects(\n node: SceneNode,\n children: readonly SceneNode[]\n): Array<{ index: number; rect: AutoLayoutHandleRect }> {\n if (children.length < 2 || node.itemSpacing <= 0 || node.primaryAxisAlign === 'SPACE_BETWEEN')\n return []\n const isRow = node.layoutMode === 'HORIZONTAL'\n const rects: Array<{ index: number; rect: AutoLayoutHandleRect }> = []\n for (let index = 0; index < children.length - 1; index++) {\n const prev = children[index]\n const next = children[index + 1]\n const prevStart = isRow ? prev.x : prev.y\n const prevEnd = isRow ? prev.x + prev.width : prev.y + prev.height\n const nextStart = isRow ? next.x : next.y\n const nextEnd = isRow ? next.x + next.width : next.y + next.height\n // A reversed flow (RTL rows, for one) lays the next child before the previous one.\n const start = nextStart >= prevStart ? prevEnd : nextEnd\n const end = nextStart >= prevStart ? nextStart : prevStart\n if (end <= start) continue\n rects.push(\n isRow\n ? {\n index,\n rect: {\n x: start,\n y: node.paddingTop,\n width: end - start,\n height: node.height - node.paddingTop - node.paddingBottom\n }\n }\n : {\n index,\n rect: {\n x: node.paddingLeft,\n y: start,\n width: node.width - node.paddingLeft - node.paddingRight,\n height: end - start\n }\n }\n )\n }\n return rects\n}\n\n/**\n * The gap between wrapped lines, which a wrapping flow lays out with counterAxisSpacing. Lines are\n * grouped by their position so a line with different item sizes still yields one gap.\n */\nfunction counterGapRects(\n node: SceneNode,\n children: readonly SceneNode[]\n): Array<{ index: number; rect: AutoLayoutHandleRect }> {\n if (node.layoutWrap !== 'WRAP' || node.counterAxisSpacing <= 0 || children.length < 2) return []\n const isRow = node.layoutMode === 'HORIZONTAL'\n const lines: Array<{ start: number; end: number }> = []\n for (const child of children) {\n const start = isRow ? child.y : child.x\n const end = isRow ? child.y + child.height : child.x + child.width\n // A centered or baseline line aligns children with different sizes at different starts.\n const line = lines.find((candidate) => start <= candidate.end && end >= candidate.start)\n if (line) {\n line.start = Math.min(line.start, start)\n line.end = Math.max(line.end, end)\n } else {\n lines.push({ start, end })\n }\n }\n const sorted = lines.sort((left, right) => left.start - right.start)\n const rects: Array<{ index: number; rect: AutoLayoutHandleRect }> = []\n for (let index = 0; index < sorted.length - 1; index++) {\n const previous = sorted[index]\n const next = sorted[index + 1]\n if (next.start <= previous.end) continue\n rects.push(\n isRow\n ? {\n index,\n rect: {\n x: node.paddingLeft,\n y: previous.end,\n width: node.width - node.paddingLeft - node.paddingRight,\n height: next.start - previous.end\n }\n }\n : {\n index,\n rect: {\n x: previous.end,\n y: node.paddingTop,\n width: next.start - previous.end,\n height: node.height - node.paddingTop - node.paddingBottom\n }\n }\n )\n }\n return rects\n}\n\n/** The padding and gap zones of an auto-layout frame, in its own coordinates. */\nconst PADDING_FIELD = {\n top: 'paddingTop',\n right: 'paddingRight',\n bottom: 'paddingBottom',\n left: 'paddingLeft'\n} as const\n\nfunction paddingValue(node: SceneNode, side: AutoLayoutPaddingSide): number {\n return node[PADDING_FIELD[side]]\n}\n\n/** The band a padding side occupies, in the frame's coordinates. */\nfunction paddingBand(\n node: SceneNode,\n side: AutoLayoutPaddingSide,\n value: number\n): AutoLayoutHandleRect {\n switch (side) {\n case 'top':\n return { x: 0, y: 0, width: node.width, height: value }\n case 'right':\n return { x: node.width - value, y: 0, width: value, height: node.height }\n case 'bottom':\n return { x: 0, y: node.height - value, width: node.width, height: value }\n case 'left':\n return { x: 0, y: 0, width: value, height: node.height }\n default:\n throw new Error('Unknown padding side')\n }\n}\n\n/** The frame edge a padding handle hugs, so the nearest of two meeting bands wins. */\nfunction edgeDistance(handle: AutoLayoutPaddingHandle, x: number, y: number): number {\n switch (handle.side) {\n case 'top':\n return y\n case 'bottom':\n return handle.rect.y + handle.rect.height - y\n case 'left':\n return x\n case 'right':\n return handle.rect.x + handle.rect.width - x\n default:\n throw new Error('Unknown padding side')\n }\n}\n\nexport function measureAutoLayoutHandles(\n node: SceneNode | undefined,\n children: readonly SceneNode[]\n): AutoLayoutHandleLayout | null {\n if (!node || (node.layoutMode !== 'HORIZONTAL' && node.layoutMode !== 'VERTICAL')) return null\n const laidOut = children.filter(\n (child) => child.visible && child.type !== 'SLICE' && child.layoutPositioning !== 'ABSOLUTE'\n )\n const padding: AutoLayoutPaddingHandle[] = []\n const sides: AutoLayoutPaddingSide[] = ['top', 'right', 'bottom', 'left']\n for (const side of sides) {\n const value = paddingValue(node, side)\n if (value <= 0) continue\n padding.push({ kind: 'padding', side, rect: paddingBand(node, side, value), value })\n }\n const gaps: AutoLayoutGapHandle[] = [\n ...primaryGapRects(node, laidOut).map(({ index, rect }) => ({\n kind: 'gap' as const,\n axis: 'primary' as const,\n index,\n rect,\n value: node.itemSpacing\n })),\n ...counterGapRects(node, laidOut).map(({ index, rect }) => ({\n kind: 'gap' as const,\n axis: 'counter' as const,\n index,\n rect,\n value: node.counterAxisSpacing\n }))\n ]\n return {\n nodeId: node.id,\n layoutMode: node.layoutMode,\n editable: !isGeneratedFrame(node),\n padding,\n gaps\n }\n}\n\nfunction contains(rect: AutoLayoutHandleRect, x: number, y: number, grow = 0): boolean {\n return (\n x >= rect.x - grow &&\n x <= rect.x + rect.width + grow &&\n y >= rect.y - grow &&\n y <= rect.y + rect.height + grow\n )\n}\n\n/**\n * The padding or gap handle under a point in the frame's coordinates. Padding wins where it meets a\n * gap, and the nearest frame edge wins in a corner where two padding bands meet.\n */\nexport function hitAutoLayoutHandle(\n layout: AutoLayoutHandleLayout | null,\n x: number,\n y: number\n): AutoLayoutHandleHit | null {\n if (!layout) return null\n let nearest: AutoLayoutPaddingHandle | null = null\n for (const handle of layout.padding) {\n if (!contains(handle.rect, x, y)) continue\n if (!nearest || edgeDistance(handle, x, y) <= edgeDistance(nearest, x, y)) nearest = handle\n }\n if (nearest) return { kind: 'padding', side: nearest.side }\n for (const handle of layout.gaps) {\n if (contains(handle.rect, x, y)) {\n return { kind: 'gap', axis: handle.axis, index: handle.index }\n }\n }\n return null\n}\n\nfunction handleFor(\n layout: AutoLayoutHandleLayout,\n hit: AutoLayoutHandleHit\n): AutoLayoutHandle | null {\n if (hit.kind === 'padding') {\n return layout.padding.find((handle) => handle.side === hit.side) ?? null\n }\n return (\n layout.gaps.find((handle) => handle.axis === hit.axis && handle.index === hit.index) ?? null\n )\n}\n\n/** Movement along the axis a padding side grows in. */\nfunction paddingDelta(side: AutoLayoutPaddingSide, dx: number, dy: number): number {\n switch (side) {\n case 'top':\n return dy\n case 'bottom':\n return -dy\n case 'left':\n return dx\n case 'right':\n return -dx\n default:\n throw new Error('Unknown padding side')\n }\n}\n\n/** Movement across the gaps of a flow: primary along it, counter across it. */\nfunction gapDelta(\n layoutMode: 'HORIZONTAL' | 'VERTICAL',\n axis: AutoLayoutGapHandle['axis'],\n dx: number,\n dy: number\n): number {\n const horizontal = layoutMode === 'HORIZONTAL'\n if (axis === 'counter') return horizontal ? dy : dx\n return horizontal ? dx : dy\n}\n\n/** The rounded, non-negative value a drag would set for the grabbed handle. */\nexport function autoLayoutDragValue(\n layout: AutoLayoutHandleLayout,\n hit: AutoLayoutHandleHit,\n input: AutoLayoutDragInput\n): number {\n const handle = handleFor(layout, hit)\n if (!handle) return 0\n const zoom = input.zoom > 0 ? input.zoom : 1\n const delta =\n handle.kind === 'padding'\n ? paddingDelta(handle.side, input.dx, input.dy)\n : gapDelta(layout.layoutMode, handle.axis, input.dx, input.dy)\n const raw = handle.value + delta / zoom\n // Shift moves padding and spacing by the large nudge, as Settings → Editor sets it.\n const step = input.bigNudge && input.bigNudge > 0 ? input.bigNudge : 10\n return Math.max(0, input.shift ? Math.round(raw / step) * step : Math.round(raw))\n}\n\n/** The properties a drag writes for the grabbed handle, with Alt and Shift expanding padding. */\nexport function autoLayoutDragChanges(\n layout: AutoLayoutHandleLayout,\n hit: AutoLayoutHandleHit,\n input: AutoLayoutDragInput\n): AutoLayoutDragChanges {\n const value = autoLayoutDragValue(layout, hit, input)\n if (hit.kind === 'padding') {\n if (input.alt && input.shift) {\n return {\n value,\n changes: {\n paddingTop: value,\n paddingRight: value,\n paddingBottom: value,\n paddingLeft: value\n }\n }\n }\n if (input.alt) {\n switch (hit.side) {\n case 'top':\n case 'bottom':\n return { value, changes: { paddingTop: value, paddingBottom: value } }\n case 'left':\n case 'right':\n return { value, changes: { paddingLeft: value, paddingRight: value } }\n }\n }\n switch (hit.side) {\n case 'top':\n return { value, changes: { paddingTop: value } }\n case 'right':\n return { value, changes: { paddingRight: value } }\n case 'bottom':\n return { value, changes: { paddingBottom: value } }\n case 'left':\n return { value, changes: { paddingLeft: value } }\n }\n }\n if (hit.axis === 'counter') return { value, changes: { counterAxisSpacing: value } }\n return { value, changes: { itemSpacing: value } }\n}\n"],"mappings":";;;AA2EA,SAAS,gBACP,MACA,UACsD;CACtD,IAAI,SAAS,SAAS,KAAK,KAAK,eAAe,KAAK,KAAK,qBAAqB,iBAC5E,OAAO,CAAC;CACV,MAAM,QAAQ,KAAK,eAAe;CAClC,MAAM,QAA8D,CAAC;CACrE,KAAK,IAAI,QAAQ,GAAG,QAAQ,SAAS,SAAS,GAAG,SAAS;EACxD,MAAM,OAAO,SAAS;EACtB,MAAM,OAAO,SAAS,QAAQ;EAC9B,MAAM,YAAY,QAAQ,KAAK,IAAI,KAAK;EACxC,MAAM,UAAU,QAAQ,KAAK,IAAI,KAAK,QAAQ,KAAK,IAAI,KAAK;EAC5D,MAAM,YAAY,QAAQ,KAAK,IAAI,KAAK;EACx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;;;
|
|
1
|
+
{"version":3,"file":"axis-sizing.d.ts","names":[],"sources":["../../src/layout/axis-sizing.ts"],"mappings":";;;KAKK;;;;;iBAMW,YAAY,OAAO,YAAY,OAAO,WAAW,QAAQ,YAAY;;;;;;iBAarE,WAAW,OAAO,WAAW,QAAQ,YAAY;;;;;iBAoBjD,YAAY,OAAO,YAAY,OAAO;;;;;;iBAkCtC,6BACd,OAAO,WACP,QAAQ,WACR,MAAM;;iBAUQ,cAAc,OAAO,WAAW,MAAM,OAAO;iBAK7C,kBACd,UAAU,MACV,MAAM,MACN,QAAQ,cACR,oBACA;iBAwBc,mBACd,UAAU,MACV,MAAM,MACN,QAAQ,cACR,oBACA"}
|
|
@@ -39,7 +39,7 @@ function asFlatLeaf(child, parent) {
|
|
|
39
39
|
function heldHugAxis(graph, frame) {
|
|
40
40
|
if (frame.counterAxisSizing !== "HUG") return null;
|
|
41
41
|
if (frame.layoutMode !== "HORIZONTAL" && frame.layoutMode !== "VERTICAL") return null;
|
|
42
|
-
const flow = graph.getChildren(frame.id).filter((child) => child.visible && child.layoutPositioning !== "ABSOLUTE");
|
|
42
|
+
const flow = graph.getChildren(frame.id).filter((child) => child.visible && child.type !== "SLICE" && child.layoutPositioning !== "ABSOLUTE");
|
|
43
43
|
if (!(flow.length > 0 && flow.every((child) => child.layoutMode === "NONE" && child.type !== "TEXT" && (child.layoutAlignSelf === "STRETCH" || child.layoutAlignSelf === "AUTO" && frame.counterAxisAlign === "STRETCH")))) return null;
|
|
44
44
|
return frame.layoutMode === "HORIZONTAL" ? "height" : "width";
|
|
45
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axis-sizing.js","names":[],"sources":["../../src/layout/axis-sizing.ts"],"sourcesContent":["import { Align, type Node as YogaNode } from 'yoga-layout'\n\nimport type { LayoutSizing, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { layoutSizing } from '@pairdraw/scene-graph/layout'\n\ntype Axis = 'width' | 'height'\n\n/**\n * A Fill child along the axis its parent hugs keeps its own size there, as Figma lays it out: the\n * parent hugs the child as it is, and neither collapses to nothing.\n */\nexport function asLaidOutIn(graph: SceneGraph, child: SceneNode, parent: SceneNode): SceneNode {\n if (child.layoutGrow <= 0) return child\n if (parent.layoutMode !== 'HORIZONTAL' && parent.layoutMode !== 'VERTICAL') return child\n return layoutSizing(graph, parent, parent.layoutMode) === 'HUG'\n ? { ...child, layoutGrow: 0 }\n : child\n}\n\n/**\n * Figma resizes a line or vector by scaling its geometry, so one with no extent along an axis\n * keeps none there: it neither fills that axis nor stretches across it, and sits where its\n * parent aligns the other children.\n */\nexport function asFlatLeaf(child: SceneNode, parent: SceneNode): SceneNode {\n if (child.type !== 'LINE' && child.type !== 'VECTOR') return child\n // A turned layer's own width and height do not run along the layout's axes.\n if (child.rotation !== 0) return child\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const main = isRow ? child.width : child.height\n const cross = isRow ? child.height : child.width\n if (main !== 0 && cross !== 0) return child\n const align = parent.counterAxisAlign === 'STRETCH' ? 'MIN' : parent.counterAxisAlign\n return {\n ...child,\n layoutGrow: main === 0 ? 0 : child.layoutGrow,\n layoutAlignSelf: cross === 0 ? align : child.layoutAlignSelf\n }\n}\n\n/**\n * The counter axis a frame hugs but keeps its size on, because every child in its flow fills\n * that axis and none has content of its own to hug, as Figma keeps it.\n */\nexport function heldHugAxis(graph: SceneGraph, frame: SceneNode): 'width' | 'height' | null {\n if (frame.counterAxisSizing !== 'HUG') return null\n if (frame.layoutMode !== 'HORIZONTAL' && frame.layoutMode !== 'VERTICAL') return null\n const flow = graph\n .getChildren(frame.id)\n .filter((child) => child.visible && child.layoutPositioning !== 'ABSOLUTE')\n const holds =\n flow.length > 0 &&\n flow.every(\n (child) =>\n child.layoutMode === 'NONE' &&\n child.type !== 'TEXT' &&\n (child.layoutAlignSelf === 'STRETCH' ||\n (child.layoutAlignSelf === 'AUTO' && frame.counterAxisAlign === 'STRETCH'))\n )\n if (!holds) return null\n return frame.layoutMode === 'HORIZONTAL' ? 'height' : 'width'\n}\n\n/** The fields that set how a layer sizes in its parent's layout. */\nconst SIZING_FIELDS: ReadonlySet<string> = new Set([\n 'layoutGrow',\n 'layoutAlignSelf',\n 'primaryAxisSizing',\n 'counterAxisSizing'\n])\n\n/**\n * A fixed-size child that fills across a hugging parent counts toward the hug with the size it\n * has, as files Figma saved were laid out: the parent is at least as wide as the child was. Once\n * Fill is set by an edit, the child counts only with its content, as Figma lays it out then.\n */\nexport function fillKeepsSizeInHuggingParent(\n child: SceneNode,\n parent: SceneNode,\n axis: Axis\n): boolean {\n return (\n parent.counterAxisSizing === 'HUG' &&\n ownAxisSizing(child, axis) === 'FIXED' &&\n !child.source.editedFields.some((field) => SIZING_FIELDS.has(field))\n )\n}\n\n/** An auto-layout frame's own sizing along a screen axis, before any fill from its parent. */\nexport function ownAxisSizing(child: SceneNode, axis: Axis): SceneNode['primaryAxisSizing'] {\n const childPrimary = child.layoutMode === 'VERTICAL' ? 'height' : 'width'\n return axis === childPrimary ? child.primaryAxisSizing : child.counterAxisSizing\n}\n\nexport function setMainAxisSizing(\n yogaNode: YogaNode,\n axis: Axis,\n sizing: LayoutSizing,\n fixedValue: number,\n grow: number\n): void {\n if (grow > 0) {\n yogaNode.setFlexGrow(grow)\n yogaNode.setFlexShrink(1)\n yogaNode.setFlexBasis(0)\n return\n }\n\n switch (sizing) {\n case 'FIXED':\n if (axis === 'width') yogaNode.setWidth(fixedValue)\n else yogaNode.setHeight(fixedValue)\n break\n case 'HUG':\n break\n case 'FILL':\n yogaNode.setFlexGrow(1)\n yogaNode.setFlexShrink(1)\n yogaNode.setFlexBasis(0)\n break\n }\n}\n\nexport function setCrossAxisSizing(\n yogaNode: YogaNode,\n axis: Axis,\n sizing: LayoutSizing,\n fixedValue: number,\n fillKeepsSize = false\n): void {\n switch (sizing) {\n case 'FIXED':\n if (axis === 'width') yogaNode.setWidth(fixedValue)\n else yogaNode.setHeight(fixedValue)\n break\n case 'HUG':\n break\n case 'FILL':\n yogaNode.setAlignSelf(Align.Stretch)\n if (fillKeepsSize) {\n if (axis === 'width') yogaNode.setMinWidth(fixedValue)\n else yogaNode.setMinHeight(fixedValue)\n }\n break\n }\n}\n"],"mappings":";;;;;;;AAWA,SAAgB,YAAY,OAAmB,OAAkB,QAA8B;CAC7F,IAAI,MAAM,cAAc,GAAG,OAAO;CAClC,IAAI,OAAO,eAAe,gBAAgB,OAAO,eAAe,YAAY,OAAO;CACnF,OAAO,aAAa,OAAO,QAAQ,OAAO,UAAU,MAAM,QACtD;EAAE,GAAG;EAAO,YAAY;CAAE,IAC1B;AACN;;;;;;AAOA,SAAgB,WAAW,OAAkB,QAA8B;CACzE,IAAI,MAAM,SAAS,UAAU,MAAM,SAAS,UAAU,OAAO;CAE7D,IAAI,MAAM,aAAa,GAAG,OAAO;CACjC,MAAM,QAAQ,OAAO,eAAe;CACpC,MAAM,OAAO,QAAQ,MAAM,QAAQ,MAAM;CACzC,MAAM,QAAQ,QAAQ,MAAM,SAAS,MAAM;CAC3C,IAAI,SAAS,KAAK,UAAU,GAAG,OAAO;CACtC,MAAM,QAAQ,OAAO,qBAAqB,YAAY,QAAQ,OAAO;CACrE,OAAO;EACL,GAAG;EACH,YAAY,SAAS,IAAI,IAAI,MAAM;EACnC,iBAAiB,UAAU,IAAI,QAAQ,MAAM;CAC/C;AACF;;;;;AAMA,SAAgB,YAAY,OAAmB,OAA6C;CAC1F,IAAI,MAAM,sBAAsB,OAAO,OAAO;CAC9C,IAAI,MAAM,eAAe,gBAAgB,MAAM,eAAe,YAAY,OAAO;CACjF,MAAM,OAAO,MACV,YAAY,MAAM,EAAE,CAAC,CACrB,
|
|
1
|
+
{"version":3,"file":"axis-sizing.js","names":[],"sources":["../../src/layout/axis-sizing.ts"],"sourcesContent":["import { Align, type Node as YogaNode } from 'yoga-layout'\n\nimport type { LayoutSizing, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { layoutSizing } from '@pairdraw/scene-graph/layout'\n\ntype Axis = 'width' | 'height'\n\n/**\n * A Fill child along the axis its parent hugs keeps its own size there, as Figma lays it out: the\n * parent hugs the child as it is, and neither collapses to nothing.\n */\nexport function asLaidOutIn(graph: SceneGraph, child: SceneNode, parent: SceneNode): SceneNode {\n if (child.layoutGrow <= 0) return child\n if (parent.layoutMode !== 'HORIZONTAL' && parent.layoutMode !== 'VERTICAL') return child\n return layoutSizing(graph, parent, parent.layoutMode) === 'HUG'\n ? { ...child, layoutGrow: 0 }\n : child\n}\n\n/**\n * Figma resizes a line or vector by scaling its geometry, so one with no extent along an axis\n * keeps none there: it neither fills that axis nor stretches across it, and sits where its\n * parent aligns the other children.\n */\nexport function asFlatLeaf(child: SceneNode, parent: SceneNode): SceneNode {\n if (child.type !== 'LINE' && child.type !== 'VECTOR') return child\n // A turned layer's own width and height do not run along the layout's axes.\n if (child.rotation !== 0) return child\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const main = isRow ? child.width : child.height\n const cross = isRow ? child.height : child.width\n if (main !== 0 && cross !== 0) return child\n const align = parent.counterAxisAlign === 'STRETCH' ? 'MIN' : parent.counterAxisAlign\n return {\n ...child,\n layoutGrow: main === 0 ? 0 : child.layoutGrow,\n layoutAlignSelf: cross === 0 ? align : child.layoutAlignSelf\n }\n}\n\n/**\n * The counter axis a frame hugs but keeps its size on, because every child in its flow fills\n * that axis and none has content of its own to hug, as Figma keeps it.\n */\nexport function heldHugAxis(graph: SceneGraph, frame: SceneNode): 'width' | 'height' | null {\n if (frame.counterAxisSizing !== 'HUG') return null\n if (frame.layoutMode !== 'HORIZONTAL' && frame.layoutMode !== 'VERTICAL') return null\n const flow = graph\n .getChildren(frame.id)\n .filter(\n (child) => child.visible && child.type !== 'SLICE' && child.layoutPositioning !== 'ABSOLUTE'\n )\n const holds =\n flow.length > 0 &&\n flow.every(\n (child) =>\n child.layoutMode === 'NONE' &&\n child.type !== 'TEXT' &&\n (child.layoutAlignSelf === 'STRETCH' ||\n (child.layoutAlignSelf === 'AUTO' && frame.counterAxisAlign === 'STRETCH'))\n )\n if (!holds) return null\n return frame.layoutMode === 'HORIZONTAL' ? 'height' : 'width'\n}\n\n/** The fields that set how a layer sizes in its parent's layout. */\nconst SIZING_FIELDS: ReadonlySet<string> = new Set([\n 'layoutGrow',\n 'layoutAlignSelf',\n 'primaryAxisSizing',\n 'counterAxisSizing'\n])\n\n/**\n * A fixed-size child that fills across a hugging parent counts toward the hug with the size it\n * has, as files Figma saved were laid out: the parent is at least as wide as the child was. Once\n * Fill is set by an edit, the child counts only with its content, as Figma lays it out then.\n */\nexport function fillKeepsSizeInHuggingParent(\n child: SceneNode,\n parent: SceneNode,\n axis: Axis\n): boolean {\n return (\n parent.counterAxisSizing === 'HUG' &&\n ownAxisSizing(child, axis) === 'FIXED' &&\n !child.source.editedFields.some((field) => SIZING_FIELDS.has(field))\n )\n}\n\n/** An auto-layout frame's own sizing along a screen axis, before any fill from its parent. */\nexport function ownAxisSizing(child: SceneNode, axis: Axis): SceneNode['primaryAxisSizing'] {\n const childPrimary = child.layoutMode === 'VERTICAL' ? 'height' : 'width'\n return axis === childPrimary ? child.primaryAxisSizing : child.counterAxisSizing\n}\n\nexport function setMainAxisSizing(\n yogaNode: YogaNode,\n axis: Axis,\n sizing: LayoutSizing,\n fixedValue: number,\n grow: number\n): void {\n if (grow > 0) {\n yogaNode.setFlexGrow(grow)\n yogaNode.setFlexShrink(1)\n yogaNode.setFlexBasis(0)\n return\n }\n\n switch (sizing) {\n case 'FIXED':\n if (axis === 'width') yogaNode.setWidth(fixedValue)\n else yogaNode.setHeight(fixedValue)\n break\n case 'HUG':\n break\n case 'FILL':\n yogaNode.setFlexGrow(1)\n yogaNode.setFlexShrink(1)\n yogaNode.setFlexBasis(0)\n break\n }\n}\n\nexport function setCrossAxisSizing(\n yogaNode: YogaNode,\n axis: Axis,\n sizing: LayoutSizing,\n fixedValue: number,\n fillKeepsSize = false\n): void {\n switch (sizing) {\n case 'FIXED':\n if (axis === 'width') yogaNode.setWidth(fixedValue)\n else yogaNode.setHeight(fixedValue)\n break\n case 'HUG':\n break\n case 'FILL':\n yogaNode.setAlignSelf(Align.Stretch)\n if (fillKeepsSize) {\n if (axis === 'width') yogaNode.setMinWidth(fixedValue)\n else yogaNode.setMinHeight(fixedValue)\n }\n break\n }\n}\n"],"mappings":";;;;;;;AAWA,SAAgB,YAAY,OAAmB,OAAkB,QAA8B;CAC7F,IAAI,MAAM,cAAc,GAAG,OAAO;CAClC,IAAI,OAAO,eAAe,gBAAgB,OAAO,eAAe,YAAY,OAAO;CACnF,OAAO,aAAa,OAAO,QAAQ,OAAO,UAAU,MAAM,QACtD;EAAE,GAAG;EAAO,YAAY;CAAE,IAC1B;AACN;;;;;;AAOA,SAAgB,WAAW,OAAkB,QAA8B;CACzE,IAAI,MAAM,SAAS,UAAU,MAAM,SAAS,UAAU,OAAO;CAE7D,IAAI,MAAM,aAAa,GAAG,OAAO;CACjC,MAAM,QAAQ,OAAO,eAAe;CACpC,MAAM,OAAO,QAAQ,MAAM,QAAQ,MAAM;CACzC,MAAM,QAAQ,QAAQ,MAAM,SAAS,MAAM;CAC3C,IAAI,SAAS,KAAK,UAAU,GAAG,OAAO;CACtC,MAAM,QAAQ,OAAO,qBAAqB,YAAY,QAAQ,OAAO;CACrE,OAAO;EACL,GAAG;EACH,YAAY,SAAS,IAAI,IAAI,MAAM;EACnC,iBAAiB,UAAU,IAAI,QAAQ,MAAM;CAC/C;AACF;;;;;AAMA,SAAgB,YAAY,OAAmB,OAA6C;CAC1F,IAAI,MAAM,sBAAsB,OAAO,OAAO;CAC9C,IAAI,MAAM,eAAe,gBAAgB,MAAM,eAAe,YAAY,OAAO;CACjF,MAAM,OAAO,MACV,YAAY,MAAM,EAAE,CAAC,CACrB,QACE,UAAU,MAAM,WAAW,MAAM,SAAS,WAAW,MAAM,sBAAsB,UACpF;CAUF,IAAI,EARF,KAAK,SAAS,KACd,KAAK,OACF,UACC,MAAM,eAAe,UACrB,MAAM,SAAS,WACd,MAAM,oBAAoB,aACxB,MAAM,oBAAoB,UAAU,MAAM,qBAAqB,UACtE,IACU,OAAO;CACnB,OAAO,MAAM,eAAe,eAAe,WAAW;AACxD;;AAGA,MAAM,gCAAqC,IAAI,IAAI;CACjD;CACA;CACA;CACA;AACF,CAAC;;;;;;AAOD,SAAgB,6BACd,OACA,QACA,MACS;CACT,OACE,OAAO,sBAAsB,SAC7B,cAAc,OAAO,IAAI,MAAM,WAC/B,CAAC,MAAM,OAAO,aAAa,MAAM,UAAU,cAAc,IAAI,KAAK,CAAC;AAEvE;;AAGA,SAAgB,cAAc,OAAkB,MAA4C;CAE1F,OAAO,UADc,MAAM,eAAe,aAAa,WAAW,WACnC,MAAM,oBAAoB,MAAM;AACjE;AAEA,SAAgB,kBACd,UACA,MACA,QACA,YACA,MACM;CACN,IAAI,OAAO,GAAG;EACZ,SAAS,YAAY,IAAI;EACzB,SAAS,cAAc,CAAC;EACxB,SAAS,aAAa,CAAC;EACvB;CACF;CAEA,QAAQ,QAAR;EACE,KAAK;GACH,IAAI,SAAS,SAAS,SAAS,SAAS,UAAU;QAC7C,SAAS,UAAU,UAAU;GAClC;EACF,KAAK,OACH;EACF,KAAK;GACH,SAAS,YAAY,CAAC;GACtB,SAAS,cAAc,CAAC;GACxB,SAAS,aAAa,CAAC;CAE3B;AACF;AAEA,SAAgB,mBACd,UACA,MACA,QACA,YACA,gBAAgB,OACV;CACN,QAAQ,QAAR;EACE,KAAK;GACH,IAAI,SAAS,SAAS,SAAS,SAAS,UAAU;QAC7C,SAAS,UAAU,UAAU;GAClC;EACF,KAAK,OACH;EACF,KAAK;GACH,SAAS,aAAa,MAAM,OAAO;GACnC,IAAI,eAAe;IACjB,IAAI,SAAS,SAAS,SAAS,YAAY,UAAU;SAChD,SAAS,aAAa,UAAU;GACvC;CAEJ;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derived.d.ts","names":[],"sources":["../../src/layout/derived.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"derived.d.ts","names":[],"sources":["../../src/layout/derived.ts"],"mappings":";;;;;;iBAsDgB,gBAAgB,OAAO,YAAY;;;;;;;iBAUnC,iBAAiB,OAAO,YAAY,OAAO;iBAwB3C,0BAA0B,OAAO,YAAY,OAAO;;;;;;iBAkBpD,oBAAoB,OAAO,YAAY,OAAO"}
|
package/dist/layout/derived.js
CHANGED
|
@@ -25,7 +25,7 @@ function graphState(states, graph, create) {
|
|
|
25
25
|
return state;
|
|
26
26
|
}
|
|
27
27
|
function flowOf(graph, node) {
|
|
28
|
-
return graph.getChildren(node.id).filter((child) => child.layoutPositioning !== "ABSOLUTE");
|
|
28
|
+
return graph.getChildren(node.id).filter((child) => child.type !== "SLICE" && child.layoutPositioning !== "ABSOLUTE");
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Loading a file adds, moves, and removes layers too, so structure edits are told from it by
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derived.js","names":[],"sources":["../../src/layout/derived.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { LAYOUT_AFFECTING_KEYS } from '@pairdraw/scene-graph/fields'\nimport { takesOwnSize } from '@pairdraw/scene-graph/instances'\n\n/** Edits that make saved geometry stale: layout fields, visibility, and text laid out again. */\nconst LAYOUT_EDIT_FIELDS: ReadonlySet<string> = new Set([\n ...LAYOUT_AFFECTING_KEYS,\n 'visible',\n 'derivedLayout'\n])\n\nfunction hasEditedLayout(node: SceneNode): boolean {\n return node.source.editedFields.some((field) => LAYOUT_EDIT_FIELDS.has(field))\n}\n\n/** The layers in each .fig frame's flow when layout first saw them, as its page opened. */\nconst savedFlows = new WeakMap<SceneGraph, Map<string, string>>()\n/** Frames whose flow, or a flow inside it, lost or gained a layer since; kept until reload. */\nconst restructured = new WeakMap<SceneGraph, Set<string>>()\n/** Frames that last laid out without their saved geometry, for the frames around them. */\nconst reflowed = new WeakMap<SceneGraph, Set<string>>()\n\nfunction graphState<T>(states: WeakMap<SceneGraph, T>, graph: SceneGraph, create: () => T): T {\n let state = states.get(graph)\n if (!state) {\n state = create()\n states.set(graph, state)\n }\n return state\n}\n\nfunction flowOf(graph: SceneGraph, node: SceneNode): SceneNode[] {\n return graph.getChildren(node.id).filter((child) => child.layoutPositioning !== 'ABSOLUTE')\n}\n\n/**\n * Loading a file adds, moves, and removes layers too, so structure edits are told from it by\n * comparing the layers in a frame's flow, in order, with those layout first saw. A layer that\n * ignores auto layout, or stops ignoring it, leaves or joins the flow.\n */\nfunction flowChanged(graph: SceneGraph, node: SceneNode, flow = flowOf(graph, node)): boolean {\n const seen = graphState(savedFlows, graph, () => new Map<string, string>())\n const ids = flow.map((child) => child.id).join(',')\n const saved = seen.get(node.id)\n if (saved === undefined) seen.set(node.id, ids)\n return saved !== undefined && saved !== ids\n}\n\n/**\n * Records that a layer joined, left, or moved in `parentId`'s children, as an editor sees an edit\n * happen, so the frame stops keeping saved geometry even if layout never ran on it before.\n */\nexport function markFlowChanged(graph: SceneGraph, parentId: string): void {\n graphState(restructured, graph, () => new Set<string>()).add(parentId)\n}\n\n/**\n * Whether layout still keeps the geometry saved for `frame` and its flow. A frame stops once a\n * layer joins, leaves, or moves in its flow or a flow inside it, or once it or a layer in its flow\n * has its layout edited, such as by adding auto layout or a gap or restyling text. That holds for\n * layers read without a source format too, as a .fig file's components and instances are.\n */\nexport function keepsSavedLayout(graph: SceneGraph, frame: SceneNode): boolean {\n const fromFig = frame.source.format === 'fig'\n const flow = flowOf(graph, frame)\n // Nothing saved to keep: the usual case outside documents read from files.\n if (!fromFig && !frame.derivedLayout && !flow.some((child) => child.derivedLayout)) return true\n const stale = graphState(restructured, graph, () => new Set<string>())\n if (stale.has(frame.id)) return false\n // Layout runs inner frames first, so a changed flow deep inside is already marked.\n if (\n flowChanged(graph, frame, flow) ||\n flow.some((child) => stale.has(child.id) || flowChanged(graph, child))\n ) {\n stale.add(frame.id)\n return false\n }\n // A flow inside edited by now resizes this one, but a cancelled preview gives it back.\n const last = graphState(reflowed, graph, () => new Set<string>())\n const keeps =\n !hasEditedLayout(frame) && !flow.some((child) => hasEditedLayout(child) || last.has(child.id))\n if (keeps) last.delete(frame.id)\n else last.add(frame.id)\n return keeps\n}\n\nexport function usesDetachedDerivedLayout(graph: SceneGraph, child: SceneNode): boolean {\n const derived = child.derivedLayout\n if (!derived || child.layoutMode === 'NONE' || child.layoutGrow > 0) return false\n const isRow = child.layoutMode === 'HORIZONTAL'\n const widthSizing = isRow ? child.primaryAxisSizing : child.counterAxisSizing\n const heightSizing = isRow ? child.counterAxisSizing : child.primaryAxisSizing\n return (\n ((widthSizing === 'HUG' && derived.width !== undefined) ||\n (heightSizing === 'HUG' && derived.height !== undefined)) &&\n keepsSavedLayout(graph, child)\n )\n}\n\n/**\n * Whether layout holds a frame's saved size exactly: a frame read from a file whose flow and\n * layout are still untouched by the user or a tool. Growing it to its padding belongs to an\n * edit, so opening or re-laying out a file leaves the saved size alone.\n */\nexport function keepsSavedFrameSize(graph: SceneGraph, frame: SceneNode): boolean {\n // An instance shows the size its main or an override gives it, as do the layers inside it; their\n // own padding is not an edit this layout may grow them from.\n if (frame.type === 'INSTANCE' || !takesOwnSize(graph, frame)) return true\n const readFromFile = frame.source.format === 'fig' || frame.derivedLayout != null\n return readFromFile && keepsSavedLayout(graph, frame)\n}\n"],"mappings":";;;;AAKA,MAAM,qCAA0C,IAAI,IAAI;CACtD,GAAG;CACH;CACA;AACF,CAAC;AAED,SAAS,gBAAgB,MAA0B;CACjD,OAAO,KAAK,OAAO,aAAa,MAAM,UAAU,mBAAmB,IAAI,KAAK,CAAC;AAC/E;;AAGA,MAAM,6BAAa,IAAI,QAAyC;;AAEhE,MAAM,+BAAe,IAAI,QAAiC;;AAE1D,MAAM,2BAAW,IAAI,QAAiC;AAEtD,SAAS,WAAc,QAAgC,OAAmB,QAAoB;CAC5F,IAAI,QAAQ,OAAO,IAAI,KAAK;CAC5B,IAAI,CAAC,OAAO;EACV,QAAQ,OAAO;EACf,OAAO,IAAI,OAAO,KAAK;CACzB;CACA,OAAO;AACT;AAEA,SAAS,OAAO,OAAmB,MAA8B;CAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"derived.js","names":[],"sources":["../../src/layout/derived.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { LAYOUT_AFFECTING_KEYS } from '@pairdraw/scene-graph/fields'\nimport { takesOwnSize } from '@pairdraw/scene-graph/instances'\n\n/** Edits that make saved geometry stale: layout fields, visibility, and text laid out again. */\nconst LAYOUT_EDIT_FIELDS: ReadonlySet<string> = new Set([\n ...LAYOUT_AFFECTING_KEYS,\n 'visible',\n 'derivedLayout'\n])\n\nfunction hasEditedLayout(node: SceneNode): boolean {\n return node.source.editedFields.some((field) => LAYOUT_EDIT_FIELDS.has(field))\n}\n\n/** The layers in each .fig frame's flow when layout first saw them, as its page opened. */\nconst savedFlows = new WeakMap<SceneGraph, Map<string, string>>()\n/** Frames whose flow, or a flow inside it, lost or gained a layer since; kept until reload. */\nconst restructured = new WeakMap<SceneGraph, Set<string>>()\n/** Frames that last laid out without their saved geometry, for the frames around them. */\nconst reflowed = new WeakMap<SceneGraph, Set<string>>()\n\nfunction graphState<T>(states: WeakMap<SceneGraph, T>, graph: SceneGraph, create: () => T): T {\n let state = states.get(graph)\n if (!state) {\n state = create()\n states.set(graph, state)\n }\n return state\n}\n\nfunction flowOf(graph: SceneGraph, node: SceneNode): SceneNode[] {\n return graph\n .getChildren(node.id)\n .filter((child) => child.type !== 'SLICE' && child.layoutPositioning !== 'ABSOLUTE')\n}\n\n/**\n * Loading a file adds, moves, and removes layers too, so structure edits are told from it by\n * comparing the layers in a frame's flow, in order, with those layout first saw. A layer that\n * ignores auto layout, or stops ignoring it, leaves or joins the flow.\n */\nfunction flowChanged(graph: SceneGraph, node: SceneNode, flow = flowOf(graph, node)): boolean {\n const seen = graphState(savedFlows, graph, () => new Map<string, string>())\n const ids = flow.map((child) => child.id).join(',')\n const saved = seen.get(node.id)\n if (saved === undefined) seen.set(node.id, ids)\n return saved !== undefined && saved !== ids\n}\n\n/**\n * Records that a layer joined, left, or moved in `parentId`'s children, as an editor sees an edit\n * happen, so the frame stops keeping saved geometry even if layout never ran on it before.\n */\nexport function markFlowChanged(graph: SceneGraph, parentId: string): void {\n graphState(restructured, graph, () => new Set<string>()).add(parentId)\n}\n\n/**\n * Whether layout still keeps the geometry saved for `frame` and its flow. A frame stops once a\n * layer joins, leaves, or moves in its flow or a flow inside it, or once it or a layer in its flow\n * has its layout edited, such as by adding auto layout or a gap or restyling text. That holds for\n * layers read without a source format too, as a .fig file's components and instances are.\n */\nexport function keepsSavedLayout(graph: SceneGraph, frame: SceneNode): boolean {\n const fromFig = frame.source.format === 'fig'\n const flow = flowOf(graph, frame)\n // Nothing saved to keep: the usual case outside documents read from files.\n if (!fromFig && !frame.derivedLayout && !flow.some((child) => child.derivedLayout)) return true\n const stale = graphState(restructured, graph, () => new Set<string>())\n if (stale.has(frame.id)) return false\n // Layout runs inner frames first, so a changed flow deep inside is already marked.\n if (\n flowChanged(graph, frame, flow) ||\n flow.some((child) => stale.has(child.id) || flowChanged(graph, child))\n ) {\n stale.add(frame.id)\n return false\n }\n // A flow inside edited by now resizes this one, but a cancelled preview gives it back.\n const last = graphState(reflowed, graph, () => new Set<string>())\n const keeps =\n !hasEditedLayout(frame) && !flow.some((child) => hasEditedLayout(child) || last.has(child.id))\n if (keeps) last.delete(frame.id)\n else last.add(frame.id)\n return keeps\n}\n\nexport function usesDetachedDerivedLayout(graph: SceneGraph, child: SceneNode): boolean {\n const derived = child.derivedLayout\n if (!derived || child.layoutMode === 'NONE' || child.layoutGrow > 0) return false\n const isRow = child.layoutMode === 'HORIZONTAL'\n const widthSizing = isRow ? child.primaryAxisSizing : child.counterAxisSizing\n const heightSizing = isRow ? child.counterAxisSizing : child.primaryAxisSizing\n return (\n ((widthSizing === 'HUG' && derived.width !== undefined) ||\n (heightSizing === 'HUG' && derived.height !== undefined)) &&\n keepsSavedLayout(graph, child)\n )\n}\n\n/**\n * Whether layout holds a frame's saved size exactly: a frame read from a file whose flow and\n * layout are still untouched by the user or a tool. Growing it to its padding belongs to an\n * edit, so opening or re-laying out a file leaves the saved size alone.\n */\nexport function keepsSavedFrameSize(graph: SceneGraph, frame: SceneNode): boolean {\n // An instance shows the size its main or an override gives it, as do the layers inside it; their\n // own padding is not an edit this layout may grow them from.\n if (frame.type === 'INSTANCE' || !takesOwnSize(graph, frame)) return true\n const readFromFile = frame.source.format === 'fig' || frame.derivedLayout != null\n return readFromFile && keepsSavedLayout(graph, frame)\n}\n"],"mappings":";;;;AAKA,MAAM,qCAA0C,IAAI,IAAI;CACtD,GAAG;CACH;CACA;AACF,CAAC;AAED,SAAS,gBAAgB,MAA0B;CACjD,OAAO,KAAK,OAAO,aAAa,MAAM,UAAU,mBAAmB,IAAI,KAAK,CAAC;AAC/E;;AAGA,MAAM,6BAAa,IAAI,QAAyC;;AAEhE,MAAM,+BAAe,IAAI,QAAiC;;AAE1D,MAAM,2BAAW,IAAI,QAAiC;AAEtD,SAAS,WAAc,QAAgC,OAAmB,QAAoB;CAC5F,IAAI,QAAQ,OAAO,IAAI,KAAK;CAC5B,IAAI,CAAC,OAAO;EACV,QAAQ,OAAO;EACf,OAAO,IAAI,OAAO,KAAK;CACzB;CACA,OAAO;AACT;AAEA,SAAS,OAAO,OAAmB,MAA8B;CAC/D,OAAO,MACJ,YAAY,KAAK,EAAE,CAAC,CACpB,QAAQ,UAAU,MAAM,SAAS,WAAW,MAAM,sBAAsB,UAAU;AACvF;;;;;;AAOA,SAAS,YAAY,OAAmB,MAAiB,OAAO,OAAO,OAAO,IAAI,GAAY;CAC5F,MAAM,OAAO,WAAW,YAAY,6BAAa,IAAI,IAAoB,CAAC;CAC1E,MAAM,MAAM,KAAK,KAAK,UAAU,MAAM,EAAE,CAAC,CAAC,KAAK,GAAG;CAClD,MAAM,QAAQ,KAAK,IAAI,KAA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AC7D,QACI,gBAAgB,SAAS,QAAQ,UAAU,KAAA,KAC1C,iBAAiB,SAAS,QAAQ,WAAW,KAAA,MAChD,iBAAiB,OAAO,KAAK;AAEjC;;;;;;AAOA,SAAgB,oBAAoB,OAAmB,OAA2B;CAGhF,IAAI,MAAM,SAAS,cAAc,CAAC,aAAa,OAAO,KAAK,GAAG,OAAO;CAErE,QADqB,MAAM,OAAO,WAAW,SAAS,MAAM,iBAAiB,SACtD,iBAAiB,OAAO,KAAK;AACtD"}
|
|
@@ -43,7 +43,7 @@ function stretchesCrossAxis(child, parent) {
|
|
|
43
43
|
return child.layoutAlignSelf === "STRETCH" || child.layoutAlignSelf === "AUTO" && parent.counterAxisAlign === "STRETCH";
|
|
44
44
|
}
|
|
45
45
|
function participatesInIntrinsicSize(node) {
|
|
46
|
-
return node.visible && node.layoutPositioning !== "ABSOLUTE";
|
|
46
|
+
return node.visible && node.type !== "SLICE" && node.layoutPositioning !== "ABSOLUTE";
|
|
47
47
|
}
|
|
48
48
|
function intrinsicSize(graph, node, sizes) {
|
|
49
49
|
if (node.layoutMode !== "HORIZONTAL" && node.layoutMode !== "VERTICAL") return null;
|