@pairdraw/core 0.21.1 → 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/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/clipboard/code.d.ts +32 -0
- package/dist/editor/clipboard/code.d.ts.map +1 -0
- package/dist/editor/clipboard/code.js +30 -0
- package/dist/editor/clipboard/code.js.map +1 -0
- package/dist/editor/clipboard/paste/dependencies.d.ts +14 -0
- package/dist/editor/clipboard/paste/dependencies.d.ts.map +1 -0
- package/dist/editor/clipboard/paste/dependencies.js +0 -0
- package/dist/editor/clipboard/paste/run.d.ts +14 -0
- package/dist/editor/clipboard/paste/run.d.ts.map +1 -0
- package/dist/editor/clipboard/paste/run.js +47 -0
- package/dist/editor/clipboard/paste/run.js.map +1 -0
- package/dist/editor/clipboard/styled.d.ts +2 -8
- package/dist/editor/clipboard/styled.d.ts.map +1 -1
- package/dist/editor/clipboard/styled.js +2 -32
- package/dist/editor/clipboard/styled.js.map +1 -1
- package/dist/editor/clipboard.d.ts +2 -0
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +34 -0
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/components/instances.d.ts +5 -0
- package/dist/editor/components/instances.d.ts.map +1 -1
- package/dist/editor/components/instances.js +69 -4
- package/dist/editor/components/instances.js.map +1 -1
- package/dist/editor/components/slots/index.d.ts.map +1 -1
- package/dist/editor/components/slots/index.js +7 -0
- package/dist/editor/components/slots/index.js.map +1 -1
- package/dist/editor/components.d.ts +6 -0
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor/components.js +14 -2
- package/dist/editor/components.js.map +1 -1
- package/dist/editor/create.d.ts +29 -2
- 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/fig/export/patch/fields.js +5 -0
- package/dist/io/formats/fig/export/patch/fields.js.map +1 -1
- package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/patch/index.js +20 -20
- package/dist/io/formats/fig/export/patch/index.js.map +1 -1
- package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
- package/dist/io/formats/fig/export/setup.js +5 -1
- package/dist/io/formats/fig/export/setup.js.map +1 -1
- package/dist/io/formats/fig/index.d.ts +3 -2
- package/dist/io/formats/fig/index.js +2 -2
- package/dist/io/formats/fig/read.d.ts.map +1 -1
- package/dist/io/formats/fig/read.js +5 -2
- package/dist/io/formats/fig/read.js.map +1 -1
- package/dist/io/formats/html/layers.d.ts +3 -1
- package/dist/io/formats/html/layers.d.ts.map +1 -1
- package/dist/io/formats/html/layers.js +6 -1
- package/dist/io/formats/html/layers.js.map +1 -1
- package/dist/io/formats/pdf/export.d.ts.map +1 -1
- package/dist/io/formats/pdf/export.js +7 -3
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/pdf/plan.d.ts +3 -0
- package/dist/io/formats/pdf/plan.d.ts.map +1 -1
- package/dist/io/formats/pdf/plan.js +60 -36
- package/dist/io/formats/pdf/plan.js.map +1 -1
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +3 -2
- package/dist/io/formats/raster/headless.js.map +1 -1
- package/dist/io/formats/raster/index.d.ts +2 -2
- package/dist/io/formats/raster/index.js +2 -2
- package/dist/io/formats/raster/render.d.ts +10 -2
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +35 -9
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +19 -1
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts +5 -2
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +59 -10
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/index.d.ts +2 -2
- package/dist/io/formats/svg/index.js +2 -2
- package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
- package/dist/io/formats/svg/text/layout.js +4 -2
- package/dist/io/formats/svg/text/layout.js.map +1 -1
- package/dist/io/formats/video/record.d.ts.map +1 -1
- package/dist/io/formats/video/record.js +24 -9
- package/dist/io/formats/video/record.js.map +1 -1
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +20 -13
- package/dist/io/formats.js.map +1 -1
- package/dist/kiwi/fig/population/client.d.ts.map +1 -1
- package/dist/kiwi/fig/population/client.js +2 -1
- package/dist/kiwi/fig/population/client.js.map +1 -1
- package/dist/kiwi/fig/session/document-state.d.ts +46 -2
- package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
- package/dist/kiwi/fig/session/document-state.js +113 -5
- package/dist/kiwi/fig/session/document-state.js.map +1 -1
- package/dist/kiwi/fig/session/options.d.ts +4 -0
- package/dist/kiwi/fig/session/options.d.ts.map +1 -1
- package/dist/kiwi/fig/session/options.js.map +1 -1
- package/dist/layout/apply.d.ts.map +1 -1
- package/dist/layout/apply.js +8 -4
- package/dist/layout/apply.js.map +1 -1
- package/dist/layout/auto-layout-handles.js +1 -1
- package/dist/layout/auto-layout-handles.js.map +1 -1
- package/dist/layout/axis-sizing.d.ts.map +1 -1
- package/dist/layout/axis-sizing.js +1 -1
- package/dist/layout/axis-sizing.js.map +1 -1
- package/dist/layout/derived.d.ts.map +1 -1
- package/dist/layout/derived.js +1 -1
- package/dist/layout/derived.js.map +1 -1
- package/dist/layout/effective-generated-text.js +1 -1
- package/dist/layout/effective-generated-text.js.map +1 -1
- package/dist/layout/grid.d.ts +3 -1
- package/dist/layout/grid.d.ts.map +1 -1
- package/dist/layout/grid.js +57 -16
- package/dist/layout/grid.js.map +1 -1
- package/dist/layout.d.ts +1 -1
- package/dist/layout.js +6 -5
- package/dist/layout.js.map +1 -1
- package/dist/node/fs.d.ts.map +1 -1
- package/dist/node/fs.js +28 -7
- package/dist/node/fs.js.map +1 -1
- package/dist/prototype/easing.d.ts +13 -5
- package/dist/prototype/easing.d.ts.map +1 -1
- package/dist/prototype/easing.js +46 -6
- package/dist/prototype/easing.js.map +1 -1
- package/dist/prototype/scenes.d.ts +31 -0
- package/dist/prototype/scenes.d.ts.map +1 -1
- package/dist/prototype/scenes.js +220 -31
- package/dist/prototype/scenes.js.map +1 -1
- package/dist/prototype/session.d.ts.map +1 -1
- package/dist/prototype/session.js +1 -0
- package/dist/prototype/session.js.map +1 -1
- package/dist/prototype/smart-animate/animation.d.ts +2 -1
- package/dist/prototype/smart-animate/animation.d.ts.map +1 -1
- package/dist/prototype/smart-animate/animation.js +2 -2
- package/dist/prototype/smart-animate/animation.js.map +1 -1
- package/dist/prototype/timeline.d.ts +10 -1
- package/dist/prototype/timeline.d.ts.map +1 -1
- package/dist/prototype/timeline.js +69 -23
- package/dist/prototype/timeline.js.map +1 -1
- package/dist/prototype/variables.d.ts +23 -0
- package/dist/prototype/variables.d.ts.map +1 -0
- package/dist/prototype/variables.js +237 -0
- package/dist/prototype/variables.js.map +1 -0
- package/dist/rpc/read-commands.d.ts +5 -0
- package/dist/rpc/read-commands.d.ts.map +1 -1
- package/dist/rpc/read-commands.js +4 -1
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/text/character-style.d.ts +8 -1
- package/dist/text/character-style.d.ts.map +1 -1
- package/dist/text/character-style.js +39 -1
- package/dist/text/character-style.js.map +1 -1
- package/dist/text/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/clipboard/pairdraw.ts +1 -0
- package/src/editor/bridges/clipboard.ts +1 -0
- package/src/editor/bridges/components.ts +10 -0
- package/src/editor/clipboard/code.ts +50 -0
- package/src/editor/clipboard/paste/dependencies.ts +18 -0
- package/src/editor/clipboard/paste/run.ts +64 -0
- package/src/editor/clipboard/styled.ts +4 -52
- package/src/editor/clipboard.ts +40 -0
- package/src/editor/components/instances.ts +92 -4
- package/src/editor/components/slots/index.ts +7 -0
- package/src/editor/components.ts +16 -2
- package/src/editor/create.ts +15 -1
- package/src/editor/design-tokens.ts +3 -23
- package/src/editor/image-edit.ts +5 -2
- package/src/editor/index.ts +1 -0
- package/src/editor/layout-mode.ts +131 -3
- package/src/editor/nodes.ts +30 -5
- package/src/editor/read-only/actions.ts +6 -0
- package/src/editor/selection/overlays.ts +8 -0
- package/src/editor/state/shared.ts +1 -0
- package/src/editor/state/view.ts +2 -0
- package/src/editor/structure/boolean.ts +29 -1
- package/src/editor/structure/container-wrap.ts +20 -4
- package/src/editor/structure/flatten.ts +15 -8
- package/src/editor/structure/group/ungroup.ts +2 -0
- package/src/editor/structure/outline-stroke.ts +5 -0
- package/src/editor/styles.ts +203 -0
- package/src/editor/text/selection-style.ts +18 -1
- package/src/editor/tool-registry.ts +2 -0
- package/src/editor/types.ts +14 -0
- package/src/editor/variable-bindings.ts +11 -0
- package/src/figma-api/accessors/basic.ts +33 -1
- package/src/figma-api/accessors/vector.ts +6 -13
- package/src/figma-api/compatibility.ts +1 -0
- package/src/figma-api/component-scope.ts +36 -0
- package/src/figma-api/components.ts +24 -0
- package/src/figma-api/flatten.ts +7 -3
- package/src/figma-api/index.ts +302 -6
- package/src/figma-api/node-types.ts +1 -0
- package/src/figma-api/overrides.ts +192 -5
- package/src/figma-api/proxy.ts +16 -1
- package/src/figma-api/reactions.ts +163 -12
- package/src/figma-api/slots.ts +10 -9
- package/src/io/formats/code/detect.ts +67 -0
- package/src/io/formats/code/index.ts +17 -0
- package/src/io/formats/code/read.ts +143 -0
- package/src/io/formats/code/stylesheet.ts +24 -0
- package/src/io/formats/code/tokens.ts +159 -0
- package/src/io/formats/design-tokens/apply.ts +3 -2
- package/src/io/formats/fig/export/patch/fields.ts +11 -0
- package/src/io/formats/fig/export/patch/index.ts +23 -19
- package/src/io/formats/fig/export/setup.ts +8 -1
- package/src/io/formats/fig/index.ts +6 -0
- package/src/io/formats/fig/read.ts +11 -2
- package/src/io/formats/html/layers.ts +7 -0
- package/src/io/formats/pdf/export.ts +19 -7
- package/src/io/formats/pdf/plan.ts +71 -32
- package/src/io/formats/raster/headless.ts +3 -1
- package/src/io/formats/raster/index.ts +2 -0
- package/src/io/formats/raster/render.ts +49 -9
- package/src/io/formats/svg/defs.ts +27 -1
- package/src/io/formats/svg/export.ts +75 -13
- package/src/io/formats/svg/index.ts +1 -0
- package/src/io/formats/svg/text/layout.ts +5 -3
- package/src/io/formats/video/record.ts +33 -9
- package/src/io/formats.ts +35 -15
- package/src/kiwi/fig/population/client.ts +6 -1
- package/src/kiwi/fig/session/document-state.ts +195 -5
- package/src/kiwi/fig/session/options.ts +2 -0
- package/src/layout/apply.ts +12 -4
- package/src/layout/auto-layout-handles.ts +1 -1
- package/src/layout/axis-sizing.ts +3 -1
- package/src/layout/derived.ts +3 -1
- package/src/layout/effective-generated-text.ts +1 -1
- package/src/layout/grid.ts +91 -21
- package/src/layout.ts +16 -3
- package/src/node/fs.ts +32 -7
- package/src/prototype/easing.ts +79 -7
- package/src/prototype/scenes.ts +244 -15
- package/src/prototype/session.ts +1 -0
- package/src/prototype/smart-animate/animation.ts +4 -3
- package/src/prototype/timeline.ts +118 -26
- package/src/prototype/variables.ts +189 -0
- package/src/rpc/read-commands.ts +19 -1
- package/src/text/character-style.ts +47 -0
- package/src/text/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":"render.js","names":[],"sources":["../../../../src/io/formats/raster/render.ts"],"sourcesContent":["import type { CanvasKit, Canvas, Image as CanvasImage } from 'canvaskit-wasm'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport type { RenderColorSpace } from '@pairdraw/scene-graph/color'\nimport { getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport { computeDescendantVisualBounds, type VisualBounds } from '@pairdraw/scene-graph/geometry'\nimport Matrix, { type Mat3 } from '@pairdraw/scene-graph/matrix'\nimport { resolvedVariableModes } from '@pairdraw/scene-graph/variables'\n\nimport type { SkiaRenderer } from '#core/canvas'\nimport { skColorSpace } from '#core/canvas/renderer/colors'\nimport { getPageColor } from '#core/figma-api/page-backgrounds'\nimport { extractExportGraph, findPageId } from '#core/io/subgraph'\n\nexport type RasterExportFormat = 'PNG' | 'JPG' | 'WEBP'\nexport type ExportFormat = RasterExportFormat | 'SVG'\n\ninterface RenderOptions {\n scale: number\n format: ExportFormat\n quality?: number\n colorSpace?: RenderColorSpace\n trimTransparent?: boolean\n}\n\n/** Pixels an export may hold before it is refused, keeping a large scale from aborting CanvasKit. */\nexport const MAX_EXPORT_PIXELS = 150_000_000\n/** Intermediate pixels above which the 2× supersampling that sharpens small exports is dropped. */\nconst SUPERSAMPLE_PIXELS = 150_000_000\n\n/** Throws when an export of `width`×`height` pixels is larger than the renderer may allocate. */\nexport function assertExportSize(width: number, height: number): void {\n if (width * height > MAX_EXPORT_PIXELS) {\n throw new Error(\n `Export is too large: ${width}×${height} pixels (limit ${MAX_EXPORT_PIXELS}). Reduce the scale.`\n )\n }\n}\n\n/** The scale an export renders at before downsampling: 2× while it stays within the budget. */\nexport function exportRenderScale(width: number, height: number): number {\n return width * height * 4 <= SUPERSAMPLE_PIXELS ? 2 : 1\n}\n\nfunction ensureSinglePageSelection(graph: SceneGraph, pageId: string, nodeIds: string[]): boolean {\n return nodeIds.every((nodeId) => findPageId(graph, nodeId) === pageId)\n}\n\nexport function computeContentBounds(graph: SceneGraph, nodeIds: string[]) {\n return computeDescendantVisualBounds(\n nodeIds,\n (id) => graph.getNode(id),\n (id) => graph.getAbsolutePosition(id)\n )\n}\n\nfunction ckImageFormat(ck: CanvasKit, format: ExportFormat) {\n switch (format) {\n case 'JPG':\n return ck.ImageFormat.JPEG\n case 'WEBP':\n return ck.ImageFormat.WEBP\n default:\n return ck.ImageFormat.PNG\n }\n}\n\nfunction findAlphaBounds(ck: CanvasKit, canvas: Canvas, width: number, height: number) {\n const pixels = canvas.readPixels(0, 0, {\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width,\n height\n })\n if (!pixels) return null\n\n let minX = width\n let minY = height\n let maxX = -1\n let maxY = -1\n\n for (let y = 0; y < height; y++) {\n const row = y * width * 4\n for (let x = 0; x < width; x++) {\n if (pixels[row + x * 4 + 3] === 0) continue\n minX = Math.min(minX, x)\n minY = Math.min(minY, y)\n maxX = Math.max(maxX, x + 1)\n maxY = Math.max(maxY, y + 1)\n }\n }\n\n if (maxX < minX || maxY < minY) return null\n return { minX, minY, maxX, maxY }\n}\n\nconst MIN_TRANSPARENT_TRIM_INSET = 2\n\nfunction shouldTrimAlphaBounds(\n alphaBounds: NonNullable<ReturnType<typeof findAlphaBounds>>,\n width: number,\n height: number\n): boolean {\n return (\n Math.max(\n alphaBounds.minX,\n alphaBounds.minY,\n width - alphaBounds.maxX,\n height - alphaBounds.maxY\n ) >= MIN_TRANSPARENT_TRIM_INSET\n )\n}\n\n/** Encodes `image`, whose pixels are `width`×`height`, falling back to the host's encoder. */\nfunction encodeImage(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n image: CanvasImage,\n width: number,\n height: number,\n format: ExportFormat,\n quality: number\n): Uint8Array<ArrayBuffer> | null {\n const encoded = image.encodeToBytes(ckImageFormat(ck, format), quality)\n if (encoded) return new Uint8Array(encoded)\n if (format !== 'JPG' && format !== 'WEBP') return null\n const raw = image.readPixels(0, 0, {\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width,\n height\n })\n return raw instanceof Uint8Array\n ? renderer.encodeRasterFallback(raw, width, height, format, quality)\n : null\n}\n\nfunction renderToSurface(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n renderGraph: SceneGraph,\n pageId: string,\n width: number,\n height: number,\n format: ExportFormat,\n quality: number,\n setup: (canvas: Canvas) => void,\n trimTransparent = false\n): Uint8Array<ArrayBuffer> | null {\n renderer.useDocumentColorSpace(renderGraph.documentColorSpace)\n const documentSpace = skColorSpace(ck, renderGraph.documentColorSpace)\n const renderScale = exportRenderScale(width, height)\n const renderWidth = width * renderScale\n const renderHeight = height * renderScale\n const pixels = ck.Malloc(Uint8Array, renderWidth * renderHeight * 4)\n const surface = ck.MakeRasterDirectSurface(\n {\n alphaType: ck.AlphaType.Premul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: documentSpace,\n width: renderWidth,\n height: renderHeight\n },\n pixels,\n renderWidth * 4\n )\n if (!surface) {\n ck.Free(pixels)\n throw new Error(`Could not allocate a ${renderWidth}×${renderHeight} export surface.`)\n }\n\n const drawnFor = renderer.supersampledOutput\n try {\n const canvas = surface.getCanvas()\n canvas.scale(renderScale, renderScale)\n setup(canvas)\n renderer.supersampledOutput =\n renderScale > 1\n ? {\n outputFromWorld: Matrix.multiply(\n Matrix.scaled(1 / renderScale, 1 / renderScale),\n canvas.getTotalMatrix()\n )\n }\n : null\n renderer.renderSceneToCanvas(canvas, renderGraph, pageId)\n surface.flush()\n\n const highResImage = surface.makeImageSnapshot()\n // At the export's own scale the snapshot is already the output: encode it without a second\n // full-size surface, which a large export would not have room for.\n if (renderScale === 1 && !trimTransparent) {\n const directBytes = encodeImage(ck, renderer, highResImage, width, height, format, quality)\n highResImage.delete()\n return directBytes\n }\n const downsamplePixels = ck.Malloc(Uint8Array, width * height * 4)\n const downsampleSurface = ck.MakeRasterDirectSurface(\n {\n alphaType: ck.AlphaType.Premul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: documentSpace,\n width,\n height\n },\n downsamplePixels,\n width * 4\n )\n if (!downsampleSurface) {\n ck.Free(downsamplePixels)\n highResImage.delete()\n throw new Error(`Could not allocate a ${width}×${height} export surface.`)\n }\n const downsampleCanvas = downsampleSurface.getCanvas()\n downsampleCanvas.clear(ck.TRANSPARENT)\n downsampleCanvas.drawImageRectOptions(\n highResImage,\n ck.LTRBRect(0, 0, renderWidth, renderHeight),\n ck.LTRBRect(0, 0, width, height),\n ck.FilterMode.Linear,\n ck.MipmapMode.None,\n null\n )\n downsampleSurface.flush()\n highResImage.delete()\n\n const foundAlphaBounds = trimTransparent\n ? findAlphaBounds(ck, downsampleCanvas, width, height)\n : null\n const alphaBounds =\n foundAlphaBounds && shouldTrimAlphaBounds(foundAlphaBounds, width, height)\n ? foundAlphaBounds\n : null\n const image = alphaBounds\n ? downsampleSurface.makeImageSnapshot([\n alphaBounds.minX,\n alphaBounds.minY,\n alphaBounds.maxX,\n alphaBounds.maxY\n ])\n : downsampleSurface.makeImageSnapshot()\n const encoded = image.encodeToBytes(ckImageFormat(ck, format), quality)\n let resultBytes: Uint8Array<ArrayBuffer> | null = encoded ? new Uint8Array(encoded) : null\n\n // CanvasKit's `encodeToBytes` returns null for JPEG/WEBP in this build, so\n // fall back to encoding the raw pixels through the browser canvas.\n if (!resultBytes && (format === 'JPG' || format === 'WEBP')) {\n const exportWidth = alphaBounds ? alphaBounds.maxX - alphaBounds.minX : width\n const exportHeight = alphaBounds ? alphaBounds.maxY - alphaBounds.minY : height\n const exportMinX = alphaBounds ? alphaBounds.minX : 0\n const exportMinY = alphaBounds ? alphaBounds.minY : 0\n\n const rawPixels = downsampleCanvas.readPixels(exportMinX, exportMinY, {\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width: exportWidth,\n height: exportHeight\n })\n\n if (rawPixels instanceof Uint8Array) {\n resultBytes = renderer.encodeRasterFallback(\n rawPixels,\n exportWidth,\n exportHeight,\n format,\n quality\n )\n }\n }\n\n image.delete()\n downsampleSurface.delete()\n ck.Free(downsamplePixels)\n return resultBytes\n } finally {\n renderer.supersampledOutput = drawnFor\n surface.dispose()\n ck.Free(pixels)\n }\n}\n\n/**\n * `nodeIds` in the order the source page paints them, bottom to top, whatever order they came in,\n * without those a selected ancestor already paints.\n */\nfunction inPaintOrder(source: SceneGraph, pageId: string, nodeIds: readonly string[]): string[] {\n const selected = new Set(nodeIds)\n const ordered: string[] = []\n const visit = (id: string): void => {\n if (selected.has(id)) {\n ordered.push(id)\n return\n }\n for (const childId of source.getNode(id)?.childIds ?? []) visit(childId)\n }\n visit(pageId)\n return ordered\n}\n\nexport function prepareSelectionRenderGraph(\n source: SceneGraph,\n renderGraph: SceneGraph,\n pageId: string,\n nodeIds: string[]\n): void {\n const page = renderGraph.getNode(pageId)\n if (!page) return\n\n page.childIds = inPaintOrder(source, pageId, nodeIds).filter(\n (nodeId) => renderGraph.getNode(nodeId) !== undefined\n )\n for (const nodeId of page.childIds) {\n const node = renderGraph.getNode(nodeId)\n const sourceNode = source.getNode(nodeId)\n if (!node || !sourceNode) continue\n if (sourceNode.parentId === pageId) continue\n const world = getWorldMatrix(sourceNode, source)\n node.parentId = pageId\n // The page is now the parent, so the modes the ancestors set must stay on the node.\n node.variableModes = resolvedVariableModes(source, nodeId)\n applyWorldTransform(node, world)\n }\n renderGraph.clearAbsPosCache()\n}\n\nfunction applyWorldTransform(node: SceneNode, matrix: Mat3): void {\n const determinant = matrix[0] * matrix[4] - matrix[1] * matrix[3]\n const flipX = determinant < 0\n const rotation = Math.atan2(matrix[3], flipX ? matrix[4] : matrix[0])\n const cos = Math.cos(rotation)\n const sin = Math.sin(rotation)\n const centerX = node.width / 2\n const centerY = node.height / 2\n const m00 = flipX ? -cos : cos\n const m01 = flipX ? sin : -sin\n const m10 = sin\n const m11 = cos\n\n node.x = matrix[2] - centerX + m00 * centerX + m01 * centerY\n node.y = matrix[5] - centerY + m10 * centerX + m11 * centerY\n node.rotation = rotation * (180 / Math.PI)\n node.flipX = flipX\n node.flipY = false\n}\n\nexport function renderNodesToImage(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n graph: SceneGraph,\n pageId: string,\n nodeIds: string[],\n options: RenderOptions\n): Uint8Array<ArrayBuffer> | null {\n if (!ensureSinglePageSelection(graph, pageId, nodeIds)) {\n throw new Error('Raster export selection must stay on a single page')\n }\n\n const bounds = computeContentBounds(graph, nodeIds)\n if (!bounds) return null\n\n const contentW = bounds.maxX - bounds.minX\n const contentH = bounds.maxY - bounds.minY\n if (contentW <= 0 || contentH <= 0) return null\n\n const pixelW = Math.ceil(contentW * options.scale)\n const pixelH = Math.ceil(contentH * options.scale)\n if (pixelW <= 0 || pixelH <= 0) return null\n assertExportSize(pixelW, pixelH)\n\n // Figma exports a layer by itself, without the page behind it, even when it blends.\n const extracted = extractExportGraph(graph, { scope: 'selection', nodeIds })\n if (!extracted.pageId) return null\n prepareSelectionRenderGraph(graph, extracted.graph, extracted.pageId, nodeIds)\n\n const quality = options.quality ?? (options.format === 'PNG' ? 100 : 90)\n return renderToSurface(\n ck,\n renderer,\n extracted.graph,\n extracted.pageId,\n pixelW,\n pixelH,\n options.format,\n quality,\n (canvas) => {\n // JPEG has no transparency; Figma fills whatever the layer leaves clear with white.\n canvas.clear(options.format === 'JPG' ? ck.WHITE : ck.TRANSPARENT)\n canvas.scale(options.scale, options.scale)\n canvas.translate(-bounds.minX, -bounds.minY)\n },\n options.trimTransparent\n )\n}\n\nexport interface ThumbnailFrame {\n /** The page content the thumbnail shows. */\n bounds: VisualBounds\n scale: number\n /** The thumbnail's size in pixels. */\n width: number\n height: number\n}\n\n/** The page region a thumbnail fitted into `width` by `height` pixels shows, and its size. */\nexport function thumbnailFrame(\n graph: SceneGraph,\n pageId: string,\n width: number,\n height: number\n): ThumbnailFrame | null {\n const page = graph.getNode(pageId)\n if (!page || page.childIds.length === 0) return null\n\n const bounds = computeContentBounds(graph, page.childIds)\n if (!bounds) return null\n\n const contentW = bounds.maxX - bounds.minX\n const contentH = bounds.maxY - bounds.minY\n if (contentW <= 0 || contentH <= 0) return null\n\n const scale = Math.min(width / contentW, height / contentH)\n return {\n bounds,\n scale,\n width: Math.max(1, Math.round(contentW * scale)),\n height: Math.max(1, Math.round(contentH * scale))\n }\n}\n\nexport function renderThumbnail(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n graph: SceneGraph,\n pageId: string,\n width: number,\n height: number,\n format: RasterExportFormat = 'PNG',\n quality = 100\n): Uint8Array<ArrayBuffer> | null {\n const frame = thumbnailFrame(graph, pageId, width, height)\n if (!frame) return null\n const { bounds, scale, width: pixelW, height: pixelH } = frame\n // The page's own background, which the editor's page colour matches only while it is open.\n const stored = getPageColor(graph.getNode(pageId))\n\n return renderToSurface(ck, renderer, graph, pageId, pixelW, pixelH, format, quality, (canvas) => {\n // The page's color is stored in the document's profile, and `renderToSurface` has just told\n // the renderer which that is; converting before that call would use the previous document's.\n const background = renderer.renderColor(stored)\n canvas.clear(ck.Color4f(background.r, background.g, background.b, 1))\n canvas.translate(-bounds.minX * scale, -bounds.minY * scale)\n canvas.scale(scale, scale)\n })\n}\n\n/** Draws a page region with `renderer`; `region.ts` gives it a renderer of its own. */\nexport function drawRegionToImage(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n graph: SceneGraph,\n pageId: string,\n bounds: VisualBounds,\n scale: number\n): Uint8Array<ArrayBuffer> | null {\n const pixelW = Math.max(1, Math.round((bounds.maxX - bounds.minX) * scale))\n const pixelH = Math.max(1, Math.round((bounds.maxY - bounds.minY) * scale))\n if (!graph.getNode(pageId) || !Number.isFinite(pixelW * pixelH)) return null\n return renderToSurface(ck, renderer, graph, pageId, pixelW, pixelH, 'PNG', 100, (canvas) => {\n // `renderToSurface` has just set the renderer's profile, so the page color converts in it.\n const pageBackground = renderer.renderColor(renderer.pageColor)\n canvas.clear(ck.Color4f(pageBackground.r, pageBackground.g, pageBackground.b, 1))\n canvas.scale(scale, scale)\n canvas.translate(-bounds.minX, -bounds.minY)\n })\n}\n"],"mappings":";;;;;;;;;AA0BA,MAAa,oBAAoB;;AAEjC,MAAM,qBAAqB;;AAG3B,SAAgB,iBAAiB,OAAe,QAAsB;CACpE,IAAI,QAAQ,SAAA,MACV,MAAM,IAAI,MACR,wBAAwB,MAAM,GAAG,OAAO,iBAAiB,kBAAkB,qBAC7E;AAEJ;;AAGA,SAAgB,kBAAkB,OAAe,QAAwB;CACvE,OAAO,QAAQ,SAAS,KAAK,qBAAqB,IAAI;AACxD;AAEA,SAAS,0BAA0B,OAAmB,QAAgB,SAA4B;CAChG,OAAO,QAAQ,OAAO,WAAW,WAAW,OAAO,MAAM,MAAM,MAAM;AACvE;AAEA,SAAgB,qBAAqB,OAAmB,SAAmB;CACzE,OAAO,8BACL,UACC,OAAO,MAAM,QAAQ,EAAE,IACvB,OAAO,MAAM,oBAAoB,EAAE,CACtC;AACF;AAEA,SAAS,cAAc,IAAe,QAAsB;CAC1D,QAAQ,QAAR;EACE,KAAK,OACH,OAAO,GAAG,YAAY;EACxB,KAAK,QACH,OAAO,GAAG,YAAY;EACxB,SACE,OAAO,GAAG,YAAY;CAC1B;AACF;AAEA,SAAS,gBAAgB,IAAe,QAAgB,OAAe,QAAgB;CACrF,MAAM,SAAS,OAAO,WAAW,GAAG,GAAG;EACrC,WAAW,GAAG,UAAU;EACxB,WAAW,GAAG,UAAU;EACxB,YAAY,GAAG,WAAW;EAC1B;EACA;CACF,CAAC;CACD,IAAI,CAAC,QAAQ,OAAO;CAEpB,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,OAAO;CAEX,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK;EAC/B,MAA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,SAAS,SAAS,MAAM,GAAG,OAAO;CACxE,OAAO,gBAAgB,IAAI,UAAU,OAAO,QAAQ,QAAQ,QAAQ,OAAO,MAAM,WAAW;EAE1F,MAAM,iBAAiB,SAAS,YAAY,SAAS,SAAS;EAC9D,OAAO,MAAM,GAAG,QAAQ,eAAe,GAAG,eAAe,GAAG,eAAe,GAAG,CAAC,CAAC;EAChF,OAAO,MAAM,OAAO,KAAK;EACzB,OAAO,UAAU,CAAC,OAAO,MAAM,CAAC,OAAO,IAAI;CAC7C,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"render.js","names":[],"sources":["../../../../src/io/formats/raster/render.ts"],"sourcesContent":["import type { CanvasKit, Canvas, Image as CanvasImage } from 'canvaskit-wasm'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport type { RenderColorSpace } from '@pairdraw/scene-graph/color'\nimport { getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport { computeDescendantVisualBounds, type VisualBounds } from '@pairdraw/scene-graph/geometry'\nimport Matrix, { type Mat3 } from '@pairdraw/scene-graph/matrix'\nimport { resolvedVariableModes } from '@pairdraw/scene-graph/variables'\n\nimport type { SkiaRenderer } from '#core/canvas'\nimport { skColorSpace } from '#core/canvas/renderer/colors'\nimport { getPageColor } from '#core/figma-api/page-backgrounds'\nimport { extractExportGraph, findPageId } from '#core/io/subgraph'\n\nexport type RasterExportFormat = 'PNG' | 'JPG' | 'WEBP'\nexport type ExportFormat = RasterExportFormat | 'SVG'\n\ninterface RenderOptions {\n scale: number\n format: ExportFormat\n quality?: number\n colorSpace?: RenderColorSpace\n trimTransparent?: boolean\n}\n\n/** Pixels an export may hold before it is refused, keeping a large scale from aborting CanvasKit. */\nexport const MAX_EXPORT_PIXELS = 150_000_000\n/** Intermediate pixels above which the 2× supersampling that sharpens small exports is dropped. */\nconst SUPERSAMPLE_PIXELS = 150_000_000\n\n/** Throws when an export of `width`×`height` pixels is larger than the renderer may allocate. */\nexport function assertExportSize(width: number, height: number): void {\n if (width * height > MAX_EXPORT_PIXELS) {\n throw new Error(\n `Export is too large: ${width}×${height} pixels (limit ${MAX_EXPORT_PIXELS}). Reduce the scale.`\n )\n }\n}\n\n/** The scale an export renders at before downsampling: 2× while it stays within the budget. */\nexport function exportRenderScale(width: number, height: number): number {\n return width * height * 4 <= SUPERSAMPLE_PIXELS ? 2 : 1\n}\n\nfunction ensureSinglePageSelection(graph: SceneGraph, pageId: string, nodeIds: string[]): boolean {\n return nodeIds.every((nodeId) => findPageId(graph, nodeId) === pageId)\n}\n\nexport function computeContentBounds(graph: SceneGraph, nodeIds: string[]) {\n return computeDescendantVisualBounds(\n nodeIds,\n (id) => graph.getNode(id),\n (id) => graph.getAbsolutePosition(id)\n )\n}\n\nfunction ckImageFormat(ck: CanvasKit, format: ExportFormat) {\n switch (format) {\n case 'JPG':\n return ck.ImageFormat.JPEG\n case 'WEBP':\n return ck.ImageFormat.WEBP\n default:\n return ck.ImageFormat.PNG\n }\n}\n\nfunction findAlphaBounds(ck: CanvasKit, canvas: Canvas, width: number, height: number) {\n const pixels = canvas.readPixels(0, 0, {\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width,\n height\n })\n if (!pixels) return null\n\n let minX = width\n let minY = height\n let maxX = -1\n let maxY = -1\n\n for (let y = 0; y < height; y++) {\n const row = y * width * 4\n for (let x = 0; x < width; x++) {\n if (pixels[row + x * 4 + 3] === 0) continue\n minX = Math.min(minX, x)\n minY = Math.min(minY, y)\n maxX = Math.max(maxX, x + 1)\n maxY = Math.max(maxY, y + 1)\n }\n }\n\n if (maxX < minX || maxY < minY) return null\n return { minX, minY, maxX, maxY }\n}\n\nconst MIN_TRANSPARENT_TRIM_INSET = 2\n\nfunction shouldTrimAlphaBounds(\n alphaBounds: NonNullable<ReturnType<typeof findAlphaBounds>>,\n width: number,\n height: number\n): boolean {\n return (\n Math.max(\n alphaBounds.minX,\n alphaBounds.minY,\n width - alphaBounds.maxX,\n height - alphaBounds.maxY\n ) >= MIN_TRANSPARENT_TRIM_INSET\n )\n}\n\n/** Encodes `image`, whose pixels are `width`×`height`, falling back to the host's encoder. */\nfunction encodeImage(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n image: CanvasImage,\n width: number,\n height: number,\n format: ExportFormat,\n quality: number\n): Uint8Array<ArrayBuffer> | null {\n const encoded = image.encodeToBytes(ckImageFormat(ck, format), quality)\n if (encoded) return new Uint8Array(encoded)\n if (format !== 'JPG' && format !== 'WEBP') return null\n const raw = image.readPixels(0, 0, {\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width,\n height\n })\n return raw instanceof Uint8Array\n ? renderer.encodeRasterFallback(raw, width, height, format, quality)\n : null\n}\n\nfunction renderToSurface(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n renderGraph: SceneGraph,\n pageId: string,\n width: number,\n height: number,\n format: ExportFormat,\n quality: number,\n setup: (canvas: Canvas) => void,\n trimTransparent = false\n): Uint8Array<ArrayBuffer> | null {\n renderer.useDocumentColorSpace(renderGraph.documentColorSpace)\n const documentSpace = skColorSpace(ck, renderGraph.documentColorSpace)\n const renderScale = exportRenderScale(width, height)\n const renderWidth = width * renderScale\n const renderHeight = height * renderScale\n const pixels = ck.Malloc(Uint8Array, renderWidth * renderHeight * 4)\n const surface = ck.MakeRasterDirectSurface(\n {\n alphaType: ck.AlphaType.Premul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: documentSpace,\n width: renderWidth,\n height: renderHeight\n },\n pixels,\n renderWidth * 4\n )\n if (!surface) {\n ck.Free(pixels)\n throw new Error(`Could not allocate a ${renderWidth}×${renderHeight} export surface.`)\n }\n\n const drawnFor = renderer.supersampledOutput\n try {\n const canvas = surface.getCanvas()\n canvas.scale(renderScale, renderScale)\n setup(canvas)\n renderer.supersampledOutput =\n renderScale > 1\n ? {\n outputFromWorld: Matrix.multiply(\n Matrix.scaled(1 / renderScale, 1 / renderScale),\n canvas.getTotalMatrix()\n )\n }\n : null\n renderer.renderSceneToCanvas(canvas, renderGraph, pageId)\n surface.flush()\n\n const highResImage = surface.makeImageSnapshot()\n // At the export's own scale the snapshot is already the output: encode it without a second\n // full-size surface, which a large export would not have room for.\n if (renderScale === 1 && !trimTransparent) {\n const directBytes = encodeImage(ck, renderer, highResImage, width, height, format, quality)\n highResImage.delete()\n return directBytes\n }\n const downsamplePixels = ck.Malloc(Uint8Array, width * height * 4)\n const downsampleSurface = ck.MakeRasterDirectSurface(\n {\n alphaType: ck.AlphaType.Premul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: documentSpace,\n width,\n height\n },\n downsamplePixels,\n width * 4\n )\n if (!downsampleSurface) {\n ck.Free(downsamplePixels)\n highResImage.delete()\n throw new Error(`Could not allocate a ${width}×${height} export surface.`)\n }\n const downsampleCanvas = downsampleSurface.getCanvas()\n downsampleCanvas.clear(ck.TRANSPARENT)\n downsampleCanvas.drawImageRectOptions(\n highResImage,\n ck.LTRBRect(0, 0, renderWidth, renderHeight),\n ck.LTRBRect(0, 0, width, height),\n ck.FilterMode.Linear,\n ck.MipmapMode.None,\n null\n )\n downsampleSurface.flush()\n highResImage.delete()\n\n const foundAlphaBounds = trimTransparent\n ? findAlphaBounds(ck, downsampleCanvas, width, height)\n : null\n const alphaBounds =\n foundAlphaBounds && shouldTrimAlphaBounds(foundAlphaBounds, width, height)\n ? foundAlphaBounds\n : null\n const image = alphaBounds\n ? downsampleSurface.makeImageSnapshot([\n alphaBounds.minX,\n alphaBounds.minY,\n alphaBounds.maxX,\n alphaBounds.maxY\n ])\n : downsampleSurface.makeImageSnapshot()\n const encoded = image.encodeToBytes(ckImageFormat(ck, format), quality)\n let resultBytes: Uint8Array<ArrayBuffer> | null = encoded ? new Uint8Array(encoded) : null\n\n // CanvasKit's `encodeToBytes` returns null for JPEG/WEBP in this build, so\n // fall back to encoding the raw pixels through the browser canvas.\n if (!resultBytes && (format === 'JPG' || format === 'WEBP')) {\n const exportWidth = alphaBounds ? alphaBounds.maxX - alphaBounds.minX : width\n const exportHeight = alphaBounds ? alphaBounds.maxY - alphaBounds.minY : height\n const exportMinX = alphaBounds ? alphaBounds.minX : 0\n const exportMinY = alphaBounds ? alphaBounds.minY : 0\n\n const rawPixels = downsampleCanvas.readPixels(exportMinX, exportMinY, {\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width: exportWidth,\n height: exportHeight\n })\n\n if (rawPixels instanceof Uint8Array) {\n resultBytes = renderer.encodeRasterFallback(\n rawPixels,\n exportWidth,\n exportHeight,\n format,\n quality\n )\n }\n }\n\n image.delete()\n downsampleSurface.delete()\n ck.Free(downsamplePixels)\n return resultBytes\n } finally {\n renderer.supersampledOutput = drawnFor\n surface.dispose()\n ck.Free(pixels)\n }\n}\n\n/**\n * `nodeIds` in the order the source page paints them, bottom to top, whatever order they came in,\n * without those a selected ancestor already paints.\n */\nfunction inPaintOrder(source: SceneGraph, pageId: string, nodeIds: readonly string[]): string[] {\n const selected = new Set(nodeIds)\n const ordered: string[] = []\n const visit = (id: string): void => {\n if (selected.has(id)) {\n ordered.push(id)\n return\n }\n for (const childId of source.getNode(id)?.childIds ?? []) visit(childId)\n }\n visit(pageId)\n return ordered\n}\n\nexport function prepareSelectionRenderGraph(\n source: SceneGraph,\n renderGraph: SceneGraph,\n pageId: string,\n nodeIds: string[]\n): void {\n const page = renderGraph.getNode(pageId)\n if (!page) return\n\n page.childIds = inPaintOrder(source, pageId, nodeIds).filter(\n (nodeId) => renderGraph.getNode(nodeId) !== undefined\n )\n for (const nodeId of page.childIds) {\n const node = renderGraph.getNode(nodeId)\n const sourceNode = source.getNode(nodeId)\n if (!node || !sourceNode) continue\n if (sourceNode.parentId === pageId) continue\n const world = getWorldMatrix(sourceNode, source)\n node.parentId = pageId\n // The page is now the parent, so the modes the ancestors set must stay on the node.\n node.variableModes = resolvedVariableModes(source, nodeId)\n applyWorldTransform(node, world)\n }\n renderGraph.clearAbsPosCache()\n}\n\nfunction applyWorldTransform(node: SceneNode, matrix: Mat3): void {\n const determinant = matrix[0] * matrix[4] - matrix[1] * matrix[3]\n const flipX = determinant < 0\n const rotation = Math.atan2(matrix[3], flipX ? matrix[4] : matrix[0])\n const cos = Math.cos(rotation)\n const sin = Math.sin(rotation)\n const centerX = node.width / 2\n const centerY = node.height / 2\n const m00 = flipX ? -cos : cos\n const m01 = flipX ? sin : -sin\n const m10 = sin\n const m11 = cos\n\n node.x = matrix[2] - centerX + m00 * centerX + m01 * centerY\n node.y = matrix[5] - centerY + m10 * centerX + m11 * centerY\n node.rotation = rotation * (180 / Math.PI)\n node.flipX = flipX\n node.flipY = false\n}\n\nexport function renderNodesToImage(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n graph: SceneGraph,\n pageId: string,\n nodeIds: string[],\n options: RenderOptions\n): Uint8Array<ArrayBuffer> | null {\n if (!ensureSinglePageSelection(graph, pageId, nodeIds)) {\n throw new Error('Raster export selection must stay on a single page')\n }\n\n const region = sliceRegion(graph, nodeIds)\n if (region) {\n return drawRegionToImage(ck, renderer, graph, pageId, region, options.scale, {\n format: options.format,\n quality: options.quality,\n background: options.format === 'JPG' ? 'white' : 'transparent'\n })\n }\n\n const bounds = computeContentBounds(graph, nodeIds)\n if (!bounds) return null\n\n const contentW = bounds.maxX - bounds.minX\n const contentH = bounds.maxY - bounds.minY\n if (contentW <= 0 || contentH <= 0) return null\n\n const pixelW = Math.ceil(contentW * options.scale)\n const pixelH = Math.ceil(contentH * options.scale)\n if (pixelW <= 0 || pixelH <= 0) return null\n assertExportSize(pixelW, pixelH)\n\n // Figma exports a layer by itself, without the page behind it, even when it blends.\n const extracted = extractExportGraph(graph, { scope: 'selection', nodeIds })\n if (!extracted.pageId) return null\n prepareSelectionRenderGraph(graph, extracted.graph, extracted.pageId, nodeIds)\n\n const quality = options.quality ?? (options.format === 'PNG' ? 100 : 90)\n return renderToSurface(\n ck,\n renderer,\n extracted.graph,\n extracted.pageId,\n pixelW,\n pixelH,\n options.format,\n quality,\n (canvas) => {\n // JPEG has no transparency; Figma fills whatever the layer leaves clear with white.\n canvas.clear(options.format === 'JPG' ? ck.WHITE : ck.TRANSPARENT)\n canvas.scale(options.scale, options.scale)\n canvas.translate(-bounds.minX, -bounds.minY)\n },\n options.trimTransparent\n )\n}\n\nexport interface ThumbnailFrame {\n /** The page content the thumbnail shows. */\n bounds: VisualBounds\n scale: number\n /** The thumbnail's size in pixels. */\n width: number\n height: number\n}\n\n/** The page region a thumbnail fitted into `width` by `height` pixels shows, and its size. */\nexport function thumbnailFrame(\n graph: SceneGraph,\n pageId: string,\n width: number,\n height: number\n): ThumbnailFrame | null {\n const page = graph.getNode(pageId)\n if (!page) return null\n const contentIds = page.childIds.filter((id) => graph.getNode(id)?.type !== 'SLICE')\n if (contentIds.length === 0) return null\n\n const bounds = computeContentBounds(graph, contentIds)\n if (!bounds) return null\n\n const contentW = bounds.maxX - bounds.minX\n const contentH = bounds.maxY - bounds.minY\n if (contentW <= 0 || contentH <= 0) return null\n\n const scale = Math.min(width / contentW, height / contentH)\n return {\n bounds,\n scale,\n width: Math.max(1, Math.round(contentW * scale)),\n height: Math.max(1, Math.round(contentH * scale))\n }\n}\n\nexport function renderThumbnail(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n graph: SceneGraph,\n pageId: string,\n width: number,\n height: number,\n format: RasterExportFormat = 'PNG',\n quality = 100\n): Uint8Array<ArrayBuffer> | null {\n const frame = thumbnailFrame(graph, pageId, width, height)\n if (!frame) return null\n const { bounds, scale, width: pixelW, height: pixelH } = frame\n // The page's own background, which the editor's page colour matches only while it is open.\n const stored = getPageColor(graph.getNode(pageId))\n\n return renderToSurface(ck, renderer, graph, pageId, pixelW, pixelH, format, quality, (canvas) => {\n // The page's color is stored in the document's profile, and `renderToSurface` has just told\n // the renderer which that is; converting before that call would use the previous document's.\n const background = renderer.renderColor(stored)\n canvas.clear(ck.Color4f(background.r, background.g, background.b, 1))\n canvas.translate(-bounds.minX * scale, -bounds.minY * scale)\n canvas.scale(scale, scale)\n })\n}\n\nexport interface RegionImageOptions {\n format?: ExportFormat\n quality?: number\n /** Page colour for canvas snapshots (`'page'`), or `'white'` / `'transparent'` for layer exports. */\n background?: 'page' | 'white' | 'transparent'\n}\n\n/** If `nodeIds` names one slice, returns that slice's page-space bounds; otherwise `null`. */\nexport function sliceRegion(graph: SceneGraph, nodeIds: string[]): VisualBounds | null {\n if (nodeIds.length !== 1) return null\n const node = graph.getNode(nodeIds[0] ?? '')\n if (node?.type !== 'SLICE') return null\n return computeContentBounds(graph, [node.id])\n}\n\n/** Draws a page region with `renderer`; `region.ts` gives it a renderer of its own. */\nexport function drawRegionToImage(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n graph: SceneGraph,\n pageId: string,\n bounds: VisualBounds,\n scale: number,\n options: RegionImageOptions = {}\n): Uint8Array<ArrayBuffer> | null {\n const contentW = bounds.maxX - bounds.minX\n const contentH = bounds.maxY - bounds.minY\n if (contentW <= 0 || contentH <= 0) return null\n const pixelW = Math.max(1, Math.round(contentW * scale))\n const pixelH = Math.max(1, Math.round(contentH * scale))\n if (!graph.getNode(pageId) || !Number.isFinite(pixelW * pixelH)) return null\n assertExportSize(pixelW, pixelH)\n const format = options.format ?? 'PNG'\n const quality = options.quality ?? (format === 'PNG' ? 100 : 90)\n const background = options.background ?? 'page'\n return renderToSurface(ck, renderer, graph, pageId, pixelW, pixelH, format, quality, (canvas) => {\n if (background === 'transparent') {\n canvas.clear(ck.TRANSPARENT)\n } else if (background === 'white') {\n canvas.clear(ck.WHITE)\n } else {\n // `renderToSurface` has just set the renderer's profile, so the page color converts in it.\n const pageBackground = renderer.renderColor(renderer.pageColor)\n canvas.clear(ck.Color4f(pageBackground.r, pageBackground.g, pageBackground.b, 1))\n }\n canvas.scale(scale, scale)\n canvas.translate(-bounds.minX, -bounds.minY)\n })\n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AY;;EAEZ,oBAAoB;;EAEpB;;EAEA,QAAQ,MAAM;;EAEd,aAAa;EACb,YAAY;;EAEZ,cAAc;;iBAGA,UAAU,KAAK,kBAAkB;iBAIjC,YACd,OAAO,OACP,kBACA,aAAY,kBACZ,gBAAe;;;;;;iBAeD,iBACd,OAAO,OACP,iBACA,YAAY,kBACZ,gBAAe;;;;;;iBAaD,iBACd,MAAM,MACN,YAAY,kBACZ;
|
|
1
|
+
{"version":3,"file":"defs.d.ts","names":[],"sources":["../../../../src/io/formats/svg/defs.ts"],"mappings":";;;;;;;;;;;;UAmCiB,uBAAuB;;EAEtC;EACA;EACA,qBAAqB;EACrB;;;KAIU,gBAAgB,MAAM;UAEjB;EACf,MAAM;EACN;EACA,OAAO;;EAEP,YAAY;;EAEZ,oBAAoB;;EAEpB;;EAEA,QAAQ,MAAM;;EAEd,aAAa;EACb,YAAY;;EAEZ,cAAc;;iBAGA,UAAU,KAAK,kBAAkB;iBAIjC,YACd,OAAO,OACP,kBACA,aAAY,kBACZ,gBAAe;;;;;;iBAeD,iBACd,OAAO,OACP,iBACA,YAAY,kBACZ,gBAAe;;;;;;iBAaD,iBACd,MAAM,MACN,YAAY,kBACZ;iBAmJc,YAAY,MAAM,MAAM,MAAM,WAAW,KAAK;cAqCjD,gBAAgB;cAMhB,iBAAiB;cAMjB,gBAAgB"}
|
|
@@ -3,7 +3,7 @@ import { round } from "./paths.js";
|
|
|
3
3
|
import { fromUint8Array } from "js-base64";
|
|
4
4
|
import { colorToHex, colorToProfileCSS, convertColor, getDefaultRenderColorSpace } from "@pairdraw/scene-graph/color";
|
|
5
5
|
import { gradientPoint, invertGradientTransform, isIdentityGradientTransform } from "@pairdraw/scene-graph/gradient";
|
|
6
|
-
import { imageMimeType } from "@pairdraw/scene-graph/images";
|
|
6
|
+
import { imageMimeType, makeImageFillLocalMatrix } from "@pairdraw/scene-graph/images";
|
|
7
7
|
//#region src/io/formats/svg/defs.ts
|
|
8
8
|
function nextDefId(ctx, prefix) {
|
|
9
9
|
return `${ctx.idPrefix ?? ""}${prefix}${ctx.defIdCounter++}`;
|
|
@@ -109,6 +109,24 @@ function createImagePattern(fill, node, ctx) {
|
|
|
109
109
|
const id = nextDefId(ctx, "img");
|
|
110
110
|
const base64 = fromUint8Array(data);
|
|
111
111
|
const mime = imageMimeType(data);
|
|
112
|
+
if (fill.imageScaleMode === "CROP") {
|
|
113
|
+
const matrix = makeImageFillLocalMatrix(fill, node, 1, 1);
|
|
114
|
+
return {
|
|
115
|
+
id,
|
|
116
|
+
node: svg("pattern", {
|
|
117
|
+
id,
|
|
118
|
+
patternUnits: "userSpaceOnUse",
|
|
119
|
+
width: node.width,
|
|
120
|
+
height: node.height
|
|
121
|
+
}, svg("image", {
|
|
122
|
+
href: `data:${mime};base64,${base64}`,
|
|
123
|
+
width: 1,
|
|
124
|
+
height: 1,
|
|
125
|
+
preserveAspectRatio: "none",
|
|
126
|
+
transform: `matrix(${round(matrix[0])} ${round(matrix[3])} ${round(matrix[1])} ${round(matrix[4])} ${round(matrix[2])} ${round(matrix[5])})`
|
|
127
|
+
}))
|
|
128
|
+
};
|
|
129
|
+
}
|
|
112
130
|
return {
|
|
113
131
|
id,
|
|
114
132
|
node: svg("pattern", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defs.js","names":[],"sources":["../../../../src/io/formats/svg/defs.ts"],"sourcesContent":["import { fromUint8Array } from 'js-base64'\n\nimport type {\n ColorProfile,\n Fill,\n FontVariation,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\nimport {\n colorToHex,\n colorToProfileCSS,\n convertColor,\n getDefaultRenderColorSpace,\n type RenderColorSpace\n} from '@pairdraw/scene-graph/color'\nimport {\n gradientPoint,\n invertGradientTransform,\n isIdentityGradientTransform\n} from '@pairdraw/scene-graph/gradient'\nimport { imageMimeType } from '@pairdraw/scene-graph/images'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport type { BooleanPathResolver } from '#core/io/formats/boolean-path'\nimport type { FontFaceRef } from '#core/text/font/faces'\n\nimport { svg, type SVGNode } from './node'\nimport { round } from './paths'\nimport type { SVGTextLayout } from './text/lines'\n\n/**\n * A face text is drawn in, with what sets its axes: the font size the optical size follows unless\n * `opticalSizeFromFontSize` is off, and the axes the text sets.\n */\nexport interface SVGFontRequest extends FontFaceRef {\n /** Which of the style's files draws the text, 0 for its own then its shards; 0 when left out. */\n file?: number\n fontSize: number\n variations: readonly FontVariation[]\n opticalSizeFromFontSize: boolean\n}\n\n/** The family to name a font face by instead of its own, or null to keep the face. */\nexport type SVGFontAlias = (font: SVGFontRequest) => string | null\n\nexport interface SVGExportContext {\n defs: SVGNode[]\n defIdCounter: number\n graph: SceneGraph\n /** The space the export writes colors in. */\n colorSpace: RenderColorSpace\n /** The document's profile: the space its stored color components are in. */\n documentColorSpace: ColorProfile\n /** Starts every def id, so SVGs inlined on one page cannot reference each other's defs. */\n idPrefix?: string\n /** Paints drawn in `currentColor`, such as an icon's tinted paths, so CSS `color` sets them. */\n tint?: (node: SceneNode) => readonly ('fill' | 'stroke')[]\n /** Measured line breaks. Without them, only explicit newlines start a new baseline. */\n textLayout?: SVGTextLayout\n fontAlias?: SVGFontAlias\n /** The live result path of a boolean made in Pairdraw, which stores none. */\n booleanPath?: BooleanPathResolver\n}\n\nexport function nextDefId(ctx: SVGExportContext, prefix: string): string {\n return `${ctx.idPrefix ?? ''}${prefix}${ctx.defIdCounter++}`\n}\n\nexport function formatColor(\n color: Color,\n opacity = 1,\n colorSpace: RenderColorSpace = getDefaultRenderColorSpace(),\n documentSpace: ColorProfile = 'srgb'\n): string {\n const painted = { ...color, a: color.a * opacity }\n // Stored components sit in the document's profile; write the color in the profile it is shown in.\n if (colorSpace === 'display-p3') return colorToProfileCSS(painted, documentSpace, 'display-p3')\n const alphaColor = convertColor(painted, documentSpace, 'srgb')\n // Hex has no alpha. Stops and shadows already emit theirs; solid fills use `solidFillOpacity`.\n return colorToHex(alphaColor)\n}\n\n/**\n * A solid paint's SVG color. The canvas paints `opacity` and drops color alpha: `setAlphaf`\n * replaces it, and `.pen` stores a hex alpha in both fields. Display P3 carries that painted\n * alpha in the color. sRGB hex cannot, so `solidFillOpacity` emits it beside the color.\n */\nexport function formatSolidColor(\n color: Color,\n opacity: number,\n colorSpace: RenderColorSpace,\n documentSpace: ColorProfile = 'srgb'\n): string {\n if (colorSpace === 'display-p3') {\n return formatColor({ ...color, a: 1 }, round(opacity), colorSpace, documentSpace)\n }\n return formatColor(color, 1, colorSpace, documentSpace)\n}\n\n/**\n * `fill-opacity` for a solid paint. Omitted at full opacity so an opaque export stays unchanged.\n * Display P3 already carries the same alpha in the color `formatSolidColor` returns, unless\n * `separate` is set because that color was replaced and can no longer carry it.\n */\nexport function solidFillOpacity(\n fill: Fill,\n colorSpace: RenderColorSpace,\n separate = false\n): number | undefined {\n if (fill.type !== 'SOLID' || (colorSpace === 'display-p3' && !separate)) return undefined\n const alpha = round(fill.opacity)\n return alpha < 1 ? alpha : undefined\n}\n\nfunction createGradientDef(\n fill: Fill,\n node: SceneNode,\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n const stops = fill.gradientStops\n const t = fill.gradientTransform\n if (!stops || !t) return null\n\n const stopNodes = stops.map((s) =>\n svg('stop', {\n offset: `${round(s.position * 100)}%`,\n 'stop-color': formatColor(s.color, 1, ctx.colorSpace, ctx.documentColorSpace),\n 'stop-opacity': s.color.a < 1 ? round(s.color.a) : undefined\n })\n )\n\n const id = nextDefId(ctx, 'grad')\n\n // Gradient space in bounding-box units, mapped onto the layer as the canvas draws it.\n const toLayer = invertGradientTransform(t)\n const transform = isIdentityGradientTransform(toLayer)\n ? undefined\n : `matrix(${[toLayer.m00, toLayer.m10, toLayer.m01, toLayer.m11, toLayer.m02, toLayer.m12].map((v) => round(v, 6)).join(' ')})`\n\n if (fill.type === 'GRADIENT_LINEAR') {\n return {\n id,\n node: svg(\n 'linearGradient',\n {\n id,\n x1: 0,\n y1: 0.5,\n x2: 1,\n y2: 0.5,\n gradientUnits: 'objectBoundingBox',\n gradientTransform: transform\n },\n ...stopNodes\n )\n }\n }\n\n // SVG has no diamond gradient, so a diamond exports as the radial one it is closest to.\n if (fill.type === 'GRADIENT_RADIAL' || fill.type === 'GRADIENT_DIAMOND') {\n return {\n id,\n node: svg(\n 'radialGradient',\n {\n id,\n cx: 0.5,\n cy: 0.5,\n r: 0.5,\n gradientUnits: 'objectBoundingBox',\n gradientTransform: transform\n },\n ...stopNodes\n )\n }\n }\n\n // Nor an angular one: it exports as a radial gradient around its centre.\n if (fill.type === 'GRADIENT_ANGULAR') {\n const center = gradientPoint(t, { x: 0.5, y: 0.5 })\n const cx = round(center.x * node.width)\n const cy = round(center.y * node.height)\n const r = Math.max(node.width, node.height)\n return {\n id,\n node: svg('radialGradient', { id, cx, cy, r, gradientUnits: 'userSpaceOnUse' }, ...stopNodes)\n }\n }\n\n return null\n}\n\nfunction createImagePattern(\n fill: Fill,\n node: SceneNode,\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n if (!fill.imageHash) return null\n const data = ctx.graph.images.get(fill.imageHash)\n if (!data) return null\n\n const id = nextDefId(ctx, 'img')\n const base64 = fromUint8Array(data)\n const mime = imageMimeType(data)\n\n return {\n id,\n node: svg(\n 'pattern',\n {\n id,\n patternUnits: 'objectBoundingBox',\n width: 1,\n height: 1,\n patternTransform: fill.imageRotation\n ? `rotate(${round(fill.imageRotation)} 0.5 0.5)`\n : undefined\n },\n svg('image', {\n href: `data:${mime};base64,${base64}`,\n width: node.width,\n height: node.height,\n preserveAspectRatio: fill.imageScaleMode === 'FIT' ? 'xMidYMid meet' : 'xMidYMid slice'\n })\n )\n }\n}\n\nexport function resolveFill(fill: Fill, node: SceneNode, ctx: SVGExportContext): string | null {\n if (!fill.visible) return null\n\n if (fill.type === 'SOLID') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace, ctx.documentColorSpace)\n }\n\n // SVG has no mesh element: a mesh exports its own color, as `.fig` records carry it.\n if (fill.type === 'MESH') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace, ctx.documentColorSpace)\n }\n\n // The canvas draws a pattern, noise or custom paint as its own colour when the format has no\n // element for it, so the export must not drop the layer.\n if (fill.type === 'PATTERN' || fill.type === 'NOISE' || fill.type === 'CUSTOM') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace, ctx.documentColorSpace)\n }\n\n if (fill.type.startsWith('GRADIENT')) {\n const grad = createGradientDef(fill, node, ctx)\n if (grad) {\n ctx.defs.push(grad.node)\n return `url(#${grad.id})`\n }\n }\n\n if (fill.type === 'IMAGE') {\n const pattern = createImagePattern(fill, node, ctx)\n if (pattern) {\n ctx.defs.push(pattern.node)\n return `url(#${pattern.id})`\n }\n }\n\n return null\n}\n\nexport const SVG_STROKE_CAP: Record<string, string> = {\n NONE: 'butt',\n ROUND: 'round',\n SQUARE: 'square'\n}\n\nexport const SVG_STROKE_JOIN: Record<string, string> = {\n MITER: 'miter',\n ROUND: 'round',\n BEVEL: 'bevel'\n}\n\nexport const SVG_BLEND_MODE: Record<string, string> = {\n NORMAL: 'normal',\n DARKEN: 'darken',\n MULTIPLY: 'multiply',\n COLOR_BURN: 'color-burn',\n LIGHTEN: 'lighten',\n LINEAR_BURN: 'plus-darker',\n SCREEN: 'screen',\n LINEAR_DODGE: 'plus-lighter',\n COLOR_DODGE: 'color-dodge',\n OVERLAY: 'overlay',\n SOFT_LIGHT: 'soft-light',\n HARD_LIGHT: 'hard-light',\n DIFFERENCE: 'difference',\n EXCLUSION: 'exclusion',\n HUE: 'hue',\n SATURATION: 'saturation',\n COLOR: 'color',\n LUMINOSITY: 'luminosity'\n}\n"],"mappings":";;;;;;;AAiEA,SAAgB,UAAU,KAAuB,QAAwB;CACvE,OAAO,GAAG,IAAI,YAAY,KAAK,SAAS,IAAI;AAC9C;AAEA,SAAgB,YACd,OACA,UAAU,GACV,aAA+B,2BAA2B,GAC1D,gBAA8B,QACtB;CACR,MAAM,UAAU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[],"sources":["../../../../src/io/formats/svg/defs.ts"],"sourcesContent":["import { fromUint8Array } from 'js-base64'\n\nimport type {\n ColorProfile,\n Fill,\n FontVariation,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\nimport {\n colorToHex,\n colorToProfileCSS,\n convertColor,\n getDefaultRenderColorSpace,\n type RenderColorSpace\n} from '@pairdraw/scene-graph/color'\nimport {\n gradientPoint,\n invertGradientTransform,\n isIdentityGradientTransform\n} from '@pairdraw/scene-graph/gradient'\nimport { imageMimeType, makeImageFillLocalMatrix } from '@pairdraw/scene-graph/images'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport type { BooleanPathResolver } from '#core/io/formats/boolean-path'\nimport type { FontFaceRef } from '#core/text/font/faces'\n\nimport { svg, type SVGNode } from './node'\nimport { round } from './paths'\nimport type { SVGTextLayout } from './text/lines'\n\n/**\n * A face text is drawn in, with what sets its axes: the font size the optical size follows unless\n * `opticalSizeFromFontSize` is off, and the axes the text sets.\n */\nexport interface SVGFontRequest extends FontFaceRef {\n /** Which of the style's files draws the text, 0 for its own then its shards; 0 when left out. */\n file?: number\n fontSize: number\n variations: readonly FontVariation[]\n opticalSizeFromFontSize: boolean\n}\n\n/** The family to name a font face by instead of its own, or null to keep the face. */\nexport type SVGFontAlias = (font: SVGFontRequest) => string | null\n\nexport interface SVGExportContext {\n defs: SVGNode[]\n defIdCounter: number\n graph: SceneGraph\n /** The space the export writes colors in. */\n colorSpace: RenderColorSpace\n /** The document's profile: the space its stored color components are in. */\n documentColorSpace: ColorProfile\n /** Starts every def id, so SVGs inlined on one page cannot reference each other's defs. */\n idPrefix?: string\n /** Paints drawn in `currentColor`, such as an icon's tinted paths, so CSS `color` sets them. */\n tint?: (node: SceneNode) => readonly ('fill' | 'stroke')[]\n /** Measured line breaks. Without them, only explicit newlines start a new baseline. */\n textLayout?: SVGTextLayout\n fontAlias?: SVGFontAlias\n /** The live result path of a boolean made in Pairdraw, which stores none. */\n booleanPath?: BooleanPathResolver\n}\n\nexport function nextDefId(ctx: SVGExportContext, prefix: string): string {\n return `${ctx.idPrefix ?? ''}${prefix}${ctx.defIdCounter++}`\n}\n\nexport function formatColor(\n color: Color,\n opacity = 1,\n colorSpace: RenderColorSpace = getDefaultRenderColorSpace(),\n documentSpace: ColorProfile = 'srgb'\n): string {\n const painted = { ...color, a: color.a * opacity }\n // Stored components sit in the document's profile; write the color in the profile it is shown in.\n if (colorSpace === 'display-p3') return colorToProfileCSS(painted, documentSpace, 'display-p3')\n const alphaColor = convertColor(painted, documentSpace, 'srgb')\n // Hex has no alpha. Stops and shadows already emit theirs; solid fills use `solidFillOpacity`.\n return colorToHex(alphaColor)\n}\n\n/**\n * A solid paint's SVG color. The canvas paints `opacity` and drops color alpha: `setAlphaf`\n * replaces it, and `.pen` stores a hex alpha in both fields. Display P3 carries that painted\n * alpha in the color. sRGB hex cannot, so `solidFillOpacity` emits it beside the color.\n */\nexport function formatSolidColor(\n color: Color,\n opacity: number,\n colorSpace: RenderColorSpace,\n documentSpace: ColorProfile = 'srgb'\n): string {\n if (colorSpace === 'display-p3') {\n return formatColor({ ...color, a: 1 }, round(opacity), colorSpace, documentSpace)\n }\n return formatColor(color, 1, colorSpace, documentSpace)\n}\n\n/**\n * `fill-opacity` for a solid paint. Omitted at full opacity so an opaque export stays unchanged.\n * Display P3 already carries the same alpha in the color `formatSolidColor` returns, unless\n * `separate` is set because that color was replaced and can no longer carry it.\n */\nexport function solidFillOpacity(\n fill: Fill,\n colorSpace: RenderColorSpace,\n separate = false\n): number | undefined {\n if (fill.type !== 'SOLID' || (colorSpace === 'display-p3' && !separate)) return undefined\n const alpha = round(fill.opacity)\n return alpha < 1 ? alpha : undefined\n}\n\nfunction createGradientDef(\n fill: Fill,\n node: SceneNode,\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n const stops = fill.gradientStops\n const t = fill.gradientTransform\n if (!stops || !t) return null\n\n const stopNodes = stops.map((s) =>\n svg('stop', {\n offset: `${round(s.position * 100)}%`,\n 'stop-color': formatColor(s.color, 1, ctx.colorSpace, ctx.documentColorSpace),\n 'stop-opacity': s.color.a < 1 ? round(s.color.a) : undefined\n })\n )\n\n const id = nextDefId(ctx, 'grad')\n\n // Gradient space in bounding-box units, mapped onto the layer as the canvas draws it.\n const toLayer = invertGradientTransform(t)\n const transform = isIdentityGradientTransform(toLayer)\n ? undefined\n : `matrix(${[toLayer.m00, toLayer.m10, toLayer.m01, toLayer.m11, toLayer.m02, toLayer.m12].map((v) => round(v, 6)).join(' ')})`\n\n if (fill.type === 'GRADIENT_LINEAR') {\n return {\n id,\n node: svg(\n 'linearGradient',\n {\n id,\n x1: 0,\n y1: 0.5,\n x2: 1,\n y2: 0.5,\n gradientUnits: 'objectBoundingBox',\n gradientTransform: transform\n },\n ...stopNodes\n )\n }\n }\n\n // SVG has no diamond gradient, so a diamond exports as the radial one it is closest to.\n if (fill.type === 'GRADIENT_RADIAL' || fill.type === 'GRADIENT_DIAMOND') {\n return {\n id,\n node: svg(\n 'radialGradient',\n {\n id,\n cx: 0.5,\n cy: 0.5,\n r: 0.5,\n gradientUnits: 'objectBoundingBox',\n gradientTransform: transform\n },\n ...stopNodes\n )\n }\n }\n\n // Nor an angular one: it exports as a radial gradient around its centre.\n if (fill.type === 'GRADIENT_ANGULAR') {\n const center = gradientPoint(t, { x: 0.5, y: 0.5 })\n const cx = round(center.x * node.width)\n const cy = round(center.y * node.height)\n const r = Math.max(node.width, node.height)\n return {\n id,\n node: svg('radialGradient', { id, cx, cy, r, gradientUnits: 'userSpaceOnUse' }, ...stopNodes)\n }\n }\n\n return null\n}\n\nfunction createImagePattern(\n fill: Fill,\n node: SceneNode,\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n if (!fill.imageHash) return null\n const data = ctx.graph.images.get(fill.imageHash)\n if (!data) return null\n\n const id = nextDefId(ctx, 'img')\n const base64 = fromUint8Array(data)\n const mime = imageMimeType(data)\n\n if (fill.imageScaleMode === 'CROP') {\n // A crop places the image by its transform alone, in layer coordinates; `rotation` is\n // automatic for a crop, as it is on the canvas. The pattern tile is the layer, and the unit\n // image inside it is laid out by the same matrix the canvas draws with.\n const matrix = makeImageFillLocalMatrix(fill, node, 1, 1)\n return {\n id,\n node: svg(\n 'pattern',\n {\n id,\n patternUnits: 'userSpaceOnUse',\n width: node.width,\n height: node.height\n },\n svg('image', {\n href: `data:${mime};base64,${base64}`,\n width: 1,\n height: 1,\n preserveAspectRatio: 'none',\n transform: `matrix(${round(matrix[0])} ${round(matrix[3])} ${round(matrix[1])} ${round(matrix[4])} ${round(matrix[2])} ${round(matrix[5])})`\n })\n )\n }\n }\n\n return {\n id,\n node: svg(\n 'pattern',\n {\n id,\n patternUnits: 'objectBoundingBox',\n width: 1,\n height: 1,\n patternTransform: fill.imageRotation\n ? `rotate(${round(fill.imageRotation)} 0.5 0.5)`\n : undefined\n },\n svg('image', {\n href: `data:${mime};base64,${base64}`,\n width: node.width,\n height: node.height,\n preserveAspectRatio: fill.imageScaleMode === 'FIT' ? 'xMidYMid meet' : 'xMidYMid slice'\n })\n )\n }\n}\n\nexport function resolveFill(fill: Fill, node: SceneNode, ctx: SVGExportContext): string | null {\n if (!fill.visible) return null\n\n if (fill.type === 'SOLID') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace, ctx.documentColorSpace)\n }\n\n // SVG has no mesh element: a mesh exports its own color, as `.fig` records carry it.\n if (fill.type === 'MESH') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace, ctx.documentColorSpace)\n }\n\n // The canvas draws a pattern, noise or custom paint as its own colour when the format has no\n // element for it, so the export must not drop the layer.\n if (fill.type === 'PATTERN' || fill.type === 'NOISE' || fill.type === 'CUSTOM') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace, ctx.documentColorSpace)\n }\n\n if (fill.type.startsWith('GRADIENT')) {\n const grad = createGradientDef(fill, node, ctx)\n if (grad) {\n ctx.defs.push(grad.node)\n return `url(#${grad.id})`\n }\n }\n\n if (fill.type === 'IMAGE') {\n const pattern = createImagePattern(fill, node, ctx)\n if (pattern) {\n ctx.defs.push(pattern.node)\n return `url(#${pattern.id})`\n }\n }\n\n return null\n}\n\nexport const SVG_STROKE_CAP: Record<string, string> = {\n NONE: 'butt',\n ROUND: 'round',\n SQUARE: 'square'\n}\n\nexport const SVG_STROKE_JOIN: Record<string, string> = {\n MITER: 'miter',\n ROUND: 'round',\n BEVEL: 'bevel'\n}\n\nexport const SVG_BLEND_MODE: Record<string, string> = {\n NORMAL: 'normal',\n DARKEN: 'darken',\n MULTIPLY: 'multiply',\n COLOR_BURN: 'color-burn',\n LIGHTEN: 'lighten',\n LINEAR_BURN: 'plus-darker',\n SCREEN: 'screen',\n LINEAR_DODGE: 'plus-lighter',\n COLOR_DODGE: 'color-dodge',\n OVERLAY: 'overlay',\n SOFT_LIGHT: 'soft-light',\n HARD_LIGHT: 'hard-light',\n DIFFERENCE: 'difference',\n EXCLUSION: 'exclusion',\n HUE: 'hue',\n SATURATION: 'saturation',\n COLOR: 'color',\n LUMINOSITY: 'luminosity'\n}\n"],"mappings":";;;;;;;AAiEA,SAAgB,UAAU,KAAuB,QAAwB;CACvE,OAAO,GAAG,IAAI,YAAY,KAAK,SAAS,IAAI;AAC9C;AAEA,SAAgB,YACd,OACA,UAAU,GACV,aAA+B,2BAA2B,GAC1D,gBAA8B,QACtB;CACR,MAAM,UAAU;EAAE,GAAG;EAAO,GAAG,MAAM,IAAI;CAAQ;CAEjD,IAAI,eAAe,cAAc,OAAO,kBAAkB,SAAS,eAAe,YAAY;CAC9F,MAAM,aAAa,aAAa,SAAS,eAAe,MAAM;CAE9D,OAAO,WAAW,UAAU;AAC9B;;;;;;AAOA,SAAgB,iBACd,OACA,SACA,YACA,gBAA8B,QACtB;CACR,IAAI,eAAe,cACjB,OAAO,YAAY;EAAE,GAAG;EAAO,GAAG;CAAE,GAAG,MAAM,OAAO,GAAG,YAAY,aAAa;CAElF,OAAO,YAAY,OAAO,GAAG,YAAY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Z,YAAY;CACZ,YAAY;CACZ,WAAW;CACX,KAAK;CACL,YAAY;CACZ,OAAO;CACP,YAAY;AACd"}
|
|
@@ -3,6 +3,7 @@ import { OutlineNode, geometryBlobToSVGPath, nodeOutlinePath } from "./paths.js"
|
|
|
3
3
|
import { SVGNode } from "./node.js";
|
|
4
4
|
import { SVGTextLayout } from "./text/lines.js";
|
|
5
5
|
import { SVGExportContext, SVGFontAlias } from "./defs.js";
|
|
6
|
+
import { VisualBounds } from "@pairdraw/scene-graph/geometry";
|
|
6
7
|
import { RenderColorSpace } from "@pairdraw/scene-graph/color";
|
|
7
8
|
import { ColorProfile, SceneGraph, SceneNode } from "@pairdraw/scene-graph";
|
|
8
9
|
//#region src/io/formats/svg/export.d.ts
|
|
@@ -29,7 +30,9 @@ interface SVGExportOptions {
|
|
|
29
30
|
*/
|
|
30
31
|
booleanPath?: BooleanPathResolver;
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
/** The slice's box, and the page content under it, clipped: a slice has no vector geometry of its own. */
|
|
34
|
+
declare function renderRegionSVG(graph: SceneGraph, pageId: string, bounds: VisualBounds, options?: SVGExportOptions): string | null;
|
|
35
|
+
declare function renderNodesToSVG(graph: SceneGraph, pageId: string, nodeIds: string[], options?: SVGExportOptions): string | null;
|
|
33
36
|
/**
|
|
34
37
|
* One layer as an `<svg>` element sized to its box, for inlining in HTML where the box already
|
|
35
38
|
* places, rotates, and fades it: the drawing starts at the layer's origin without its rotation
|
|
@@ -41,5 +44,5 @@ declare function renderNodeSVGElement(graph: SceneGraph, node: SceneNode, { idPr
|
|
|
41
44
|
documentColorSpace?: ColorProfile;
|
|
42
45
|
}): SVGNode | null;
|
|
43
46
|
//#endregion
|
|
44
|
-
export { type OutlineNode, SVGExportOptions, geometryBlobToSVGPath, nodeOutlinePath, renderNodeSVGElement, renderNodesToSVG };
|
|
47
|
+
export { type OutlineNode, SVGExportOptions, geometryBlobToSVGPath, nodeOutlinePath, renderNodeSVGElement, renderNodesToSVG, renderRegionSVG };
|
|
45
48
|
//# sourceMappingURL=export.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.d.ts","names":[],"sources":["../../../../src/io/formats/svg/export.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"export.d.ts","names":[],"sources":["../../../../src/io/formats/svg/export.ts"],"mappings":";;;;;;;;;UAwwBiB;;EAEf;;EAEA;;EAEA,qBAAqB;;;;;EAKrB,aAAa;;;;;EAKb,YAAY;;;;;EAKZ,cAAc;;;iBAiBA,gBACd,OAAO,YACP,gBACA,QAAQ,cACR,UAAS;iBAkDK,iBACd,OAAO,YACP,gBACA,mBACA,UAAS;;;;;;iBA4DK,qBACd,OAAO,YACP,MAAM,aAEJ,UACA,YACA,oBACA,MACA,eACC,KAAK;EACN;EACA,aAAa;EACb,qBAAqB;IAEtB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computeContentBounds } from "../raster/render.js";
|
|
1
|
+
import { computeContentBounds, sliceRegion } from "../raster/render.js";
|
|
2
2
|
import { normalizeDashPattern } from "../../../canvas/strokes.js";
|
|
3
3
|
import { fittedDashPattern } from "../../../canvas/strokes/sides.js";
|
|
4
4
|
import { lineStrokePath } from "../../../canvas/strokes/line.js";
|
|
@@ -419,7 +419,7 @@ function renderBooleanNode(node, ctx, paint) {
|
|
|
419
419
|
return svg("g", paint.groupAttrs, ...booleanPathElements(node, d, paint.visibleFills, paint.fillAttr, paint.fillOpacity, paint.strokeAttrs, paint.visibleStrokes, ctx));
|
|
420
420
|
}
|
|
421
421
|
function renderNode(node, ctx) {
|
|
422
|
-
if (!node.visible) return null;
|
|
422
|
+
if (!node.visible || node.type === "SLICE") return null;
|
|
423
423
|
const { attrs: groupAttrs, clipId } = buildGroupAttrs(node, ctx);
|
|
424
424
|
if (node.type === "TEXT") {
|
|
425
425
|
const fill = exportedFill(node.fills.find((f) => f.visible), node, ctx);
|
|
@@ -461,13 +461,8 @@ function renderNode(node, ctx) {
|
|
|
461
461
|
function isGroupLike(node) {
|
|
462
462
|
return node.type === "GROUP";
|
|
463
463
|
}
|
|
464
|
-
function
|
|
465
|
-
|
|
466
|
-
if (!bounds) return null;
|
|
467
|
-
const { minX, minY, maxX, maxY } = bounds;
|
|
468
|
-
const width = round(maxX - minX);
|
|
469
|
-
const height = round(maxY - minY);
|
|
470
|
-
const ctx = {
|
|
464
|
+
function svgExportContext(graph, options) {
|
|
465
|
+
return {
|
|
471
466
|
defs: [],
|
|
472
467
|
defIdCounter: 0,
|
|
473
468
|
graph,
|
|
@@ -477,6 +472,60 @@ function renderNodesToSVG(graph, _pageId, nodeIds, options = {}) {
|
|
|
477
472
|
fontAlias: options.fontAlias,
|
|
478
473
|
booleanPath: options.booleanPath
|
|
479
474
|
};
|
|
475
|
+
}
|
|
476
|
+
/** The slice's box, and the page content under it, clipped: a slice has no vector geometry of its own. */
|
|
477
|
+
function renderRegionSVG(graph, pageId, bounds, options = {}) {
|
|
478
|
+
const page = graph.getNode(pageId);
|
|
479
|
+
if (!page) return null;
|
|
480
|
+
const { minX, minY, maxX, maxY } = bounds;
|
|
481
|
+
const width = round(maxX - minX);
|
|
482
|
+
const height = round(maxY - minY);
|
|
483
|
+
if (width <= 0 || height <= 0) return null;
|
|
484
|
+
const ctx = svgExportContext(graph, options);
|
|
485
|
+
const contentNodes = [];
|
|
486
|
+
for (const id of page.childIds) {
|
|
487
|
+
const node = graph.getNode(id);
|
|
488
|
+
if (!node?.visible || node.type === "SLICE") continue;
|
|
489
|
+
const abs = graph.getAbsolutePosition(id);
|
|
490
|
+
const offsetX = abs.x - minX;
|
|
491
|
+
const offsetY = abs.y - minY;
|
|
492
|
+
const rendered = renderNode(offsetX !== node.x || offsetY !== node.y ? {
|
|
493
|
+
...node,
|
|
494
|
+
x: round(offsetX),
|
|
495
|
+
y: round(offsetY)
|
|
496
|
+
} : node, ctx);
|
|
497
|
+
if (rendered) contentNodes.push(rendered);
|
|
498
|
+
}
|
|
499
|
+
if (contentNodes.length === 0) return null;
|
|
500
|
+
const clipId = nextDefId(ctx, "slice");
|
|
501
|
+
ctx.defs.push(svg("clipPath", {
|
|
502
|
+
id: clipId,
|
|
503
|
+
clipPathUnits: "userSpaceOnUse"
|
|
504
|
+
}, svg("rect", {
|
|
505
|
+
x: 0,
|
|
506
|
+
y: 0,
|
|
507
|
+
width,
|
|
508
|
+
height
|
|
509
|
+
})));
|
|
510
|
+
const root = svg("svg", {
|
|
511
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
512
|
+
"xmlns:xlink": "http://www.w3.org/1999/xlink",
|
|
513
|
+
width,
|
|
514
|
+
height,
|
|
515
|
+
viewBox: `0 0 ${width} ${height}`
|
|
516
|
+
}, svg("defs", {}, ...ctx.defs), svg("g", { "clip-path": `url(#${clipId})` }, ...contentNodes));
|
|
517
|
+
const svgStr = renderSVGNode(root);
|
|
518
|
+
return (options.xmlDeclaration !== false ? "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" : "") + svgStr;
|
|
519
|
+
}
|
|
520
|
+
function renderNodesToSVG(graph, pageId, nodeIds, options = {}) {
|
|
521
|
+
const box = sliceRegion(graph, nodeIds);
|
|
522
|
+
if (box) return renderRegionSVG(graph, pageId, box, options);
|
|
523
|
+
const bounds = computeContentBounds(graph, nodeIds);
|
|
524
|
+
if (!bounds) return null;
|
|
525
|
+
const { minX, minY, maxX, maxY } = bounds;
|
|
526
|
+
const width = round(maxX - minX);
|
|
527
|
+
const height = round(maxY - minY);
|
|
528
|
+
const ctx = svgExportContext(graph, options);
|
|
480
529
|
const contentNodes = [];
|
|
481
530
|
for (const id of nodeIds) {
|
|
482
531
|
const node = graph.getNode(id);
|
|
@@ -538,6 +587,6 @@ function renderNodeSVGElement(graph, node, { idPrefix, colorSpace = "srgb", docu
|
|
|
538
587
|
}, ctx.defs.length > 0 ? svg("defs", {}, ...ctx.defs) : null, drawn);
|
|
539
588
|
}
|
|
540
589
|
//#endregion
|
|
541
|
-
export { geometryBlobToSVGPath, nodeOutlinePath, renderNodeSVGElement, renderNodesToSVG };
|
|
590
|
+
export { geometryBlobToSVGPath, nodeOutlinePath, renderNodeSVGElement, renderNodesToSVG, renderRegionSVG };
|
|
542
591
|
|
|
543
592
|
//# sourceMappingURL=export.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.js","names":[],"sources":["../../../../src/io/formats/svg/export.ts"],"sourcesContent":["import type {\n ColorProfile,\n Fill,\n SceneGraph,\n SceneNode,\n Stroke,\n VectorNetwork\n} from '@pairdraw/scene-graph'\nimport type { RenderColorSpace } from '@pairdraw/scene-graph/color'\n\nimport { normalizeDashPattern } from '#core/canvas/strokes'\nimport { lineStrokePath } from '#core/canvas/strokes/line'\nimport { fittedDashPattern } from '#core/canvas/strokes/sides'\nimport { computeContentBounds } from '#core/io/formats/raster'\n\nimport {\n nextDefId,\n formatSolidColor,\n resolveFill,\n solidFillOpacity,\n SVG_STROKE_CAP,\n SVG_STROKE_JOIN,\n SVG_BLEND_MODE\n} from './defs'\nimport { createFilterDef } from './effects'\nimport {\n round,\n geometryBlobToSVGPath,\n makePolygonPoints,\n roundedPolygonPath,\n hasRadius,\n hasSmoothCorners,\n boxOutlinePath,\n arcPath,\n shapeWithTextOutlinePath\n} from './paths'\n\nexport { geometryBlobToSVGPath, nodeOutlinePath, type OutlineNode } from './paths'\n\nimport { looseSegments, regionSVGPaths } from '@pairdraw/scene-graph/vector-network'\n\nimport type { BooleanPathResolver } from '#core/io/formats/boolean-path'\n\nimport { arrowHeadElements, openPathElements, vectorArrowHeads } from './arrows'\nimport type { SVGExportContext, SVGFontAlias } from './defs'\nimport { svg, renderSVGNode } from './node'\nimport type { SVGNode } from './node'\nimport { alignedStroke, alignedStrokeElement, shapeWithTextDetailElements } from './strokes'\nimport { renderTextNode } from './text/export'\nimport type { SVGTextLayout } from './text/lines'\n\n// --- Node rendering ---\n\n/**\n * A vector network's paths: its regions as they are traced, and its open segments as the canvas\n * strokes them, rounded and pulled back under their heads.\n */\nfunction networkElements(\n node: SceneNode,\n network: VectorNetwork,\n common: Record<string, string | number | undefined>\n): SVGNode[] {\n const regions = regionSVGPaths(network).map((d) => svg('path', { d, ...common }))\n if (looseSegments(network).length === 0) return regions\n return [...regions, ...openPathElements(node, network, common, looseSegments)]\n}\n\n/** Paints one path's fill stack; a blended fill draws its stroke as a separate path. */\nfunction vectorFillElements(\n attrs: Record<string, string | number | undefined>,\n visibleFills: Fill[],\n strokeAttrs: Record<string, string | number | undefined>,\n common: Record<string, string | number | undefined>,\n node: SceneNode,\n ctx: SVGExportContext\n): SVGNode[] {\n const elements: SVGNode[] = []\n for (const [index, fill] of visibleFills.entries()) {\n const fillAttr = resolveFill(fill, node, ctx)\n if (!fillAttr) continue\n const style = paintBlendStyle(fill)\n const last = index === visibleFills.length - 1\n const splitStroke = style !== undefined && last && common.stroke !== 'none'\n const stroke = last && !splitStroke ? common.stroke : 'none'\n elements.push(\n svg('path', {\n ...attrs,\n fill: fillAttr,\n 'fill-opacity': solidFillOpacity(fill, ctx.colorSpace),\n style,\n stroke\n })\n )\n if (splitStroke) {\n elements.push(\n svg('path', {\n d: attrs.d,\n 'fill-rule': attrs['fill-rule'],\n fill: 'none',\n ...strokeAttrs\n })\n )\n }\n }\n return elements\n}\n\nfunction vectorShapeElements(\n node: SceneNode,\n common: Record<string, string | number | undefined>,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext,\n fallbackFills?: Fill[]\n): SVGNode[] {\n const elements: SVGNode[] = []\n if (node.fillGeometry.length > 0) {\n for (const geo of node.fillGeometry) {\n const d = geometryBlobToSVGPath(geo.commandsBlob)\n if (!d) continue\n const attrs = {\n d,\n 'fill-rule': geo.windingRule === 'EVENODD' ? 'evenodd' : undefined,\n ...common\n }\n const pathFills = geo.fills?.length ? geo.fills : fallbackFills\n if (!pathFills) {\n elements.push(svg('path', attrs))\n continue\n }\n const visibleFills = pathFills.filter((fill) => fill.visible)\n if (visibleFills.length === 0) {\n elements.push(svg('path', { ...attrs, fill: 'none' }))\n continue\n }\n elements.push(...vectorFillElements(attrs, visibleFills, strokeAttrs, common, node, ctx))\n }\n } else if (node.vectorNetwork) {\n elements.push(...networkElements(node, node.vectorNetwork, common))\n }\n elements.push(...vectorStrokeTail(node, strokeAttrs))\n return withVectorFallback(elements, node, common)\n}\n\n/** The empty vector's fallback shape, after both paints have contributed their elements. */\nfunction withVectorFallback(\n elements: SVGNode[],\n node: SceneNode,\n common: Record<string, string | number | undefined>\n): SVGNode[] {\n return elements.length > 0\n ? elements\n : [svg('rect', { width: round(node.width), height: round(node.height), ...common })]\n}\n\n/** The stored stroke geometry and arrowheads both vector paints share after their outlines. */\nfunction vectorStrokeTail(\n node: SceneNode,\n strokeAttrs: Record<string, string | number | undefined>\n): SVGNode[] {\n const elements: SVGNode[] = []\n if (node.strokeGeometry.length > 0 && strokeAttrs.stroke && strokeAttrs.stroke !== 'none') {\n for (const geo of node.strokeGeometry) {\n const d = geometryBlobToSVGPath(geo.commandsBlob)\n if (d) {\n elements.push(\n svg('path', {\n d,\n fill: strokeAttrs.stroke,\n 'fill-opacity': strokeAttrs['stroke-opacity'],\n stroke: 'none'\n })\n )\n }\n }\n }\n if (node.vectorNetwork) elements.push(...vectorArrowHeads(node, node.vectorNetwork, strokeAttrs))\n return elements\n}\n\n/** A vector layer's outlines as strokes alone, for a second stroke over the painted fills. */\nfunction vectorStrokeElements(\n node: SceneNode,\n strokeAttrs: Record<string, string | number | undefined>\n): SVGNode[] {\n const elements: SVGNode[] = []\n const common: Record<string, string | number | undefined> = { fill: 'none', ...strokeAttrs }\n if (node.fillGeometry.length > 0) {\n for (const geo of node.fillGeometry) {\n const d = geometryBlobToSVGPath(geo.commandsBlob)\n if (d) {\n elements.push(\n svg('path', {\n d,\n 'fill-rule': geo.windingRule === 'EVENODD' ? 'evenodd' : undefined,\n ...common\n })\n )\n }\n }\n } else if (node.vectorNetwork) {\n elements.push(...networkElements(node, node.vectorNetwork, common))\n }\n elements.push(...vectorStrokeTail(node, strokeAttrs))\n return withVectorFallback(elements, node, common)\n}\n\n/** A line's dashes stretched along it as the canvas lays them, half a dash at each end. */\nfunction lineDashAttrs(stroke: Stroke | undefined, length: number) {\n const fitted = fittedDashPattern(length, normalizeDashPattern(stroke?.dashPattern))\n if (!fitted) return {}\n return {\n 'stroke-dasharray': fitted.intervals.map((size) => round(size)).join(' '),\n 'stroke-dashoffset': round(fitted.offset)\n }\n}\n\nfunction nodeShapeElements(\n node: SceneNode,\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext,\n stroke?: Stroke\n): SVGNode[] {\n const common: Record<string, string | number | undefined> = {\n fill: fillAttr ?? 'none',\n 'fill-opacity': fillOpacity,\n ...strokeAttrs\n }\n\n switch (node.type) {\n case 'ELLIPSE': {\n if (node.arcData) {\n return [svg('path', { d: arcPath(node), ...common })]\n }\n return [\n svg('ellipse', {\n cx: round(node.width / 2),\n cy: round(node.height / 2),\n rx: round(node.width / 2),\n ry: round(node.height / 2),\n ...common\n })\n ]\n }\n\n case 'LINE': {\n // Where the canvas strokes it: to one side of the line, with its caps inside its length.\n const lineStroke = stroke ?? node.strokes.find((item) => item.visible)\n const {\n network,\n from: start,\n to: end\n } = lineStrokePath(node, lineStroke?.weight ?? 0, lineStroke?.cap ?? node.strokeCap)\n return [\n svg('line', {\n x1: round(start.x),\n y1: round(start.y),\n x2: round(end.x),\n y2: round(end.y),\n fill: 'none',\n ...strokeAttrs,\n ...lineDashAttrs(lineStroke, Math.hypot(end.x - start.x, end.y - start.y))\n }),\n ...arrowHeadElements(node, network, lineStroke, strokeAttrs)\n ]\n }\n\n case 'STAR':\n case 'POLYGON':\n return node.cornerRadius > 0\n ? [svg('path', { d: roundedPolygonPath(node), ...common })]\n : [svg('polygon', { points: makePolygonPoints(node), ...common })]\n\n case 'VECTOR':\n return vectorShapeElements(node, common, strokeAttrs, ctx)\n\n case 'SHAPE_WITH_TEXT':\n return shapeWithTextElements(node, common, strokeAttrs, ctx)\n\n default:\n return [boxOutlineElement(node, common)]\n }\n}\n\n/**\n * A box layer's outline as one element: a rect, a rect with `rx`/`ry` for one radius, or the\n * shared box path for independent or smoothed corners, so fills and clips follow the same edge.\n */\nfunction boxOutlineElement(\n node: SceneNode,\n attrs: Record<string, string | number | undefined>\n): SVGNode {\n const width = round(node.width)\n const height = round(node.height)\n if (!hasRadius(node)) return svg('rect', { width, height, ...attrs })\n if (node.independentCorners || hasSmoothCorners(node)) {\n return svg('path', { d: boxOutlinePath(node), ...attrs })\n }\n // SVG clamps rx and ry to their own sides; the canvas keeps a too-large radius circular.\n const radius = round(Math.min(node.cornerRadius, node.width / 2, node.height / 2))\n return svg('rect', { width, height, rx: radius, ry: radius, ...attrs })\n}\n\n/**\n * A FigJam shape's outline, and its inner lines, such as a database's front rim, stroked as the\n * canvas strokes them: at the stroke's own weight, ending where the outline does.\n */\nfunction shapeWithTextElements(\n node: SceneNode,\n common: Record<string, string | number | undefined>,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext\n): SVGNode[] {\n return [\n svg('path', { d: shapeWithTextOutlinePath(node), ...common }),\n ...shapeWithTextDetailElements(node, strokeAttrs, ctx)\n ]\n}\n\n// --- Main recursive renderer ---\n\nfunction buildTransformAttr(node: SceneNode): string | undefined {\n const transforms: string[] = []\n if (node.x !== 0 || node.y !== 0) transforms.push(`translate(${round(node.x)}, ${round(node.y)})`)\n if (node.rotation !== 0) {\n transforms.push(\n `rotate(${round(node.rotation)}, ${round(node.width / 2)}, ${round(node.height / 2)})`\n )\n }\n if (node.flipX || node.flipY) {\n const tx = node.flipX ? node.width : 0\n const ty = node.flipY ? node.height : 0\n const sx = node.flipX ? -1 : 1\n const sy = node.flipY ? -1 : 1\n transforms.push(`translate(${round(tx)}, ${round(ty)}) scale(${sx}, ${sy})`)\n }\n return transforms.length > 0 ? transforms.join(' ') : undefined\n}\n\nfunction buildGroupAttrs(\n node: SceneNode,\n ctx: SVGExportContext\n): { attrs: Record<string, string | number | undefined>; clipId?: string } {\n const attrs: Record<string, string | number | undefined> = {}\n\n const transform = buildTransformAttr(node)\n if (transform) attrs.transform = transform\n\n if (node.opacity < 1) attrs.opacity = round(node.opacity)\n\n const blend = SVG_BLEND_MODE[node.blendMode]\n if (blend && blend !== 'normal' && node.blendMode !== 'PASS_THROUGH') {\n attrs.style = `mix-blend-mode: ${blend}`\n }\n\n const filterDef = createFilterDef(node, ctx)\n if (filterDef) {\n ctx.defs.push(filterDef.node)\n attrs.filter = `url(#${filterDef.id})`\n }\n\n let clipId: string | undefined\n if (node.clipsContent && node.childIds.length > 0) {\n clipId = nextDefId(ctx, 'clip')\n ctx.defs.push(svg('clipPath', { id: clipId }, boxOutlineElement(node, {})))\n }\n\n return { attrs, clipId }\n}\n\nfunction buildSVGStrokeAttrs(\n stroke: Stroke,\n node: SceneNode,\n ctx: SVGExportContext\n): Record<string, string | number | undefined> {\n const cap = stroke.cap ?? node.strokeCap\n const attrs: Record<string, string | number | undefined> = {\n // Opacity 1 keeps the color opaque. Display P3 must not also keep color alpha here, or a\n // viewer multiplies it by stroke-opacity; the canvas paints stroke.opacity alone.\n stroke:\n stroke.type === 'SOLID'\n ? formatSolidColor(stroke.color, 1, ctx.colorSpace, ctx.documentColorSpace)\n : (resolveFill(stroke, node, ctx) ??\n formatSolidColor(stroke.color, 1, ctx.colorSpace, ctx.documentColorSpace)),\n 'stroke-width': round(stroke.weight)\n }\n if (stroke.opacity < 1) attrs['stroke-opacity'] = round(stroke.opacity)\n if (cap !== 'NONE') attrs['stroke-linecap'] = SVG_STROKE_CAP[cap] ?? 'butt'\n if (stroke.join && stroke.join !== 'MITER') {\n attrs['stroke-linejoin'] = SVG_STROKE_JOIN[stroke.join] ?? 'miter'\n }\n if (stroke.dashPattern && stroke.dashPattern.length > 0) {\n attrs['stroke-dasharray'] = stroke.dashPattern.map((n) => round(n)).join(' ')\n }\n return attrs\n}\n\n/** The blend CSS a paint adds, when the canvas would not composite it source-over. */\nfunction paintBlendStyle(fill: Fill | undefined): string | undefined {\n const blend = fill?.blendMode ? SVG_BLEND_MODE[fill.blendMode] : undefined\n return blend && blend !== 'normal' ? `mix-blend-mode: ${blend}` : undefined\n}\n\n/** Adds a paint's blend mode to the elements that draw it. */\nfunction withPaintBlend(elements: SVGNode[], fill: Fill | undefined): SVGNode[] {\n const style = paintBlendStyle(fill)\n if (style) for (const element of elements) element.attrs.style = style\n return elements\n}\n\n/**\n * Draws the fill and the stroke as separate elements when the fill blends, so the stroke keeps the\n * source-over canvas gives it instead of inheriting the fill's blend mode.\n */\nfunction shapeWithPaint(\n node: SceneNode,\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n fill: Fill | undefined,\n ctx: SVGExportContext\n): SVGNode[] {\n const blends = paintBlendStyle(fill) !== undefined\n if (!blends || !strokeAttrs.stroke) {\n return withPaintBlend(nodeShapeElements(node, fillAttr, fillOpacity, strokeAttrs, ctx), fill)\n }\n return [\n ...withPaintBlend(nodeShapeElements(node, fillAttr, fillOpacity, {}, ctx), fill),\n ...nodeShapeElements(node, null, undefined, strokeAttrs, ctx)\n ]\n}\n\nfunction hasPathLevelFills(node: SceneNode): boolean {\n return node.type === 'VECTOR' && node.fillGeometry.some((geometry) => geometry.fills?.length)\n}\n\n/** One stroke at its own weight over the fills: a centred one on the outline, an aligned one around it. */\nfunction strokeElements(\n node: SceneNode,\n stroke: Stroke,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext\n): SVGNode[] {\n const aligned = hasPathLevelFills(node) ? null : alignedStroke(node, stroke)\n if (aligned) {\n return [\n ...alignedStrokeElement(node, aligned, strokeAttrs, ctx),\n ...(node.type === 'SHAPE_WITH_TEXT'\n ? shapeWithTextDetailElements(node, strokeAttrs, ctx)\n : [])\n ]\n }\n if (node.type === 'VECTOR') return vectorStrokeElements(node, strokeAttrs)\n return nodeShapeElements(node, null, undefined, strokeAttrs, ctx, stroke)\n}\n\n/**\n * The fills and the strokes over them. The first stroke joins the fill's own element as before;\n * every later visible stroke is drawn in layer order, without painting the fill again.\n */\nfunction buildShapeChildren(\n node: SceneNode,\n visibleFills: Fill[],\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>[],\n visibleStrokes: Stroke[],\n ctx: SVGExportContext\n): SVGNode[] {\n if (visibleStrokes.length === 0) {\n return fillAndStrokeElements(node, visibleFills, fillAttr, fillOpacity, {}, 0, ctx)\n }\n const first = visibleStrokes[0]\n const firstAttrs = strokeAttrs[0]\n const elements = alignedStroke(node, first)\n ? // The fill goes as it is, and the stroke over it inside or outside the outline.\n [\n ...fillAndStrokeElements(node, visibleFills, fillAttr, fillOpacity, {}, 0, ctx),\n ...strokeElements(node, first, firstAttrs, ctx)\n ]\n : fillAndStrokeElements(\n node,\n visibleFills,\n fillAttr,\n fillOpacity,\n firstAttrs,\n visibleStrokes.length,\n ctx\n )\n for (let index = 1; index < visibleStrokes.length; index++) {\n elements.push(...strokeElements(node, visibleStrokes[index], strokeAttrs[index], ctx))\n }\n return elements\n}\n\nfunction fillAndStrokeElements(\n node: SceneNode,\n visibleFills: Fill[],\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n visibleStrokeCount: number,\n ctx: SVGExportContext\n): SVGNode[] {\n if (hasPathLevelFills(node)) {\n return vectorShapeElements(\n node,\n { fill: fillAttr ?? 'none', 'fill-opacity': fillOpacity, ...strokeAttrs },\n strokeAttrs,\n ctx,\n visibleFills\n )\n }\n\n if (visibleFills.length > 1) {\n const elements: SVGNode[] = []\n for (const fill of visibleFills) {\n const ref = resolveFill(fill, node, ctx)\n if (ref) {\n elements.push(\n ...shapeWithPaint(\n node,\n ref,\n solidFillOpacity(fill, ctx.colorSpace),\n fill === visibleFills[visibleFills.length - 1] ? strokeAttrs : {},\n fill,\n ctx\n )\n )\n }\n }\n return elements\n }\n\n const hasFillOrStroke = fillAttr || visibleStrokeCount > 0\n if (hasFillOrStroke && !isGroupLike(node)) {\n return shapeWithPaint(\n node,\n fillAttr,\n fillOpacity,\n strokeAttrs,\n visibleFills.length === 1 ? visibleFills[0] : undefined,\n ctx\n )\n }\n\n return []\n}\n\n/** The paint CSS `color` sets, for a tinted icon path. */\nconst CURRENT_COLOR = 'currentColor'\n\n/** A paint's SVG color and, for an sRGB solid, the `fill-opacity` beside it. */\nfunction exportedFill(\n fill: Fill | undefined,\n node: SceneNode,\n ctx: SVGExportContext\n): { color: string | null; opacity: number | undefined } {\n if (!fill) return { color: null, opacity: undefined }\n return {\n color: resolveFill(fill, node, ctx),\n opacity: solidFillOpacity(fill, ctx.colorSpace)\n }\n}\n\n/**\n * A mask layer's definition: an alpha or luminance `<mask>`, or a `<clipPath>` for an outline\n * mask. The rendered layer carries its own position, opacity, and filters into the mask.\n */\nfunction maskWire(\n mask: SceneNode,\n ctx: SVGExportContext\n): { attribute: 'mask' | 'clip-path'; id: string } {\n const content = renderNode(mask, ctx)\n if (mask.maskType === 'VECTOR') {\n const id = nextDefId(ctx, 'clip')\n ctx.defs.push(svg('clipPath', { id, clipPathUnits: 'userSpaceOnUse' }, content ?? undefined))\n return { attribute: 'clip-path', id }\n }\n const id = nextDefId(ctx, 'mask')\n const attrs: Record<string, string | number | undefined> = {\n id,\n maskContentUnits: 'userSpaceOnUse'\n }\n if (mask.maskType === 'ALPHA') attrs['mask-type'] = 'alpha'\n ctx.defs.push(svg('mask', attrs, content ?? undefined))\n return { attribute: 'mask', id }\n}\n\n/**\n * The children as the canvas draws them: a run of visible masks masks the siblings that follow\n * it, until the next mask, and the mask layers themselves never draw on their own.\n */\nfunction maskedChildNodes(childNodes: SceneNode[], ctx: SVGExportContext): SVGNode[] {\n const content: SVGNode[] = []\n let masks: Array<{ attribute: 'mask' | 'clip-path'; id: string }> = []\n let afterMask = false\n for (const child of childNodes) {\n if (child.visible && child.isMask) {\n const wire = maskWire(child, ctx)\n masks = afterMask ? [...masks, wire] : [wire]\n afterMask = true\n continue\n }\n const rendered = renderNode(child, ctx)\n afterMask = false\n if (!rendered) continue\n let wrapped = rendered\n for (const wire of masks) wrapped = svg('g', { [wire.attribute]: `url(#${wire.id})` }, wrapped)\n content.push(wrapped)\n }\n return content\n}\n\n/** A boolean's live result path in the paints its fills and strokes give it. */\nfunction booleanPathElements(\n node: SceneNode,\n d: string,\n visibleFills: Fill[],\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Array<Record<string, string | number | undefined>>,\n visibleStrokes: Stroke[],\n ctx: SVGExportContext\n): SVGNode[] {\n const common = { d, 'fill-rule': 'evenodd' as const }\n // A centred first stroke joins the fill element, as a shape's does; every later stroke, and\n // every inside or outside stroke, is drawn over the result outline on its own. An unset\n // alignment strokes the centred way, as `alignedStroke` treats it.\n const centered = (stroke: Stroke): boolean =>\n stroke.align !== 'INSIDE' && stroke.align !== 'OUTSIDE'\n const firstJoins = visibleStrokes.length > 0 && centered(visibleStrokes[0])\n const joined = firstJoins ? strokeAttrs[0] : {}\n const elements =\n visibleFills.length <= 1\n ? [\n svg('path', {\n ...common,\n fill: fillAttr ?? 'none',\n 'fill-opacity': fillOpacity,\n ...joined\n })\n ]\n : visibleFills.map((fill, index) =>\n svg('path', {\n ...common,\n fill: resolveFill(fill, node, ctx) ?? 'none',\n 'fill-opacity': solidFillOpacity(fill, ctx.colorSpace),\n ...(index === visibleFills.length - 1 ? joined : {})\n })\n )\n\n for (let index = firstJoins ? 1 : 0; index < visibleStrokes.length; index++) {\n const stroke = visibleStrokes[index]\n const attrs = strokeAttrs[index]\n elements.push(\n ...(centered(stroke)\n ? [svg('path', { d, fill: 'none', ...attrs })]\n : alignedStrokeElement(node, stroke, attrs, ctx, d))\n )\n }\n return elements\n}\n\n/** A boolean made in Pairdraw draws its computed result path instead of its operands. */\nfunction renderBooleanNode(\n node: SceneNode,\n ctx: SVGExportContext,\n paint: {\n groupAttrs: Record<string, string | number | undefined>\n visibleFills: Fill[]\n fillAttr: string | null\n fillOpacity: number | undefined\n strokeAttrs: Array<Record<string, string | number | undefined>>\n visibleStrokes: Stroke[]\n }\n): SVGNode | null {\n if (node.type !== 'BOOLEAN_OPERATION' || node.fillGeometry.length > 0 || !ctx.booleanPath) {\n return null\n }\n const d = ctx.booleanPath(ctx.graph, node)\n if (!d) return null\n return svg(\n 'g',\n paint.groupAttrs,\n ...booleanPathElements(\n node,\n d,\n paint.visibleFills,\n paint.fillAttr,\n paint.fillOpacity,\n paint.strokeAttrs,\n paint.visibleStrokes,\n ctx\n )\n )\n}\n\nfunction renderNode(node: SceneNode, ctx: SVGExportContext): SVGNode | null {\n if (!node.visible) return null\n\n const { attrs: groupAttrs, clipId } = buildGroupAttrs(node, ctx)\n\n if (node.type === 'TEXT') {\n const fill = exportedFill(\n node.fills.find((f) => f.visible),\n node,\n ctx\n )\n return svg('g', groupAttrs, renderTextNode(node, fill.color, ctx, fill.opacity))\n }\n\n const visibleFills = node.fills.filter((f) => f.visible)\n const visibleStrokes = node.strokes.filter((s) => s.visible)\n const tint = ctx.tint?.(node) ?? []\n const ownFill = visibleFills.length > 0 && !hasPathLevelFills(node) ? visibleFills[0] : undefined\n const fill = exportedFill(ownFill, node, ctx)\n const tintedFill = fill.color !== null && tint.includes('fill')\n const fillAttr = tintedFill ? CURRENT_COLOR : fill.color\n // `currentColor` has no alpha. Display P3 normally bakes solid opacity into the color, which a\n // tint throws away, so a tinted solid keeps `fill-opacity` in every color space.\n const fillOpacity = ownFill ? solidFillOpacity(ownFill, ctx.colorSpace, tintedFill) : fill.opacity\n const strokeAttrs = visibleStrokes.map((stroke) => {\n const attrs = buildSVGStrokeAttrs(stroke, node, ctx)\n return tint.includes('stroke') ? { ...attrs, stroke: CURRENT_COLOR } : attrs\n })\n\n const booleanDrawn = renderBooleanNode(node, ctx, {\n groupAttrs,\n visibleFills,\n fillAttr,\n fillOpacity,\n strokeAttrs,\n visibleStrokes\n })\n if (booleanDrawn) return booleanDrawn\n\n const children: (SVGNode | null)[] = buildShapeChildren(\n node,\n visibleFills,\n fillAttr,\n fillOpacity,\n strokeAttrs,\n visibleStrokes,\n ctx\n )\n\n const childContent = maskedChildNodes(ctx.graph.getChildren(node.id), ctx)\n\n if (clipId && childContent.length > 0) {\n children.push(svg('g', { 'clip-path': `url(#${clipId})` }, ...childContent))\n } else {\n children.push(...childContent)\n }\n\n const validChildren = children.filter((c): c is SVGNode => c !== null)\n\n if (validChildren.length === 0 && Object.keys(groupAttrs).length === 0) {\n return null\n }\n\n if (validChildren.length === 1 && Object.keys(groupAttrs).length === 0) {\n return validChildren[0]\n }\n\n return svg('g', groupAttrs, ...validChildren)\n}\n\nfunction isGroupLike(node: SceneNode): boolean {\n return node.type === 'GROUP'\n}\n\n// --- Public API ---\n\nexport interface SVGExportOptions {\n /** Include XML declaration (default: true) */\n xmlDeclaration?: boolean\n /** Target export color space (default: srgb) */\n colorSpace?: 'srgb' | 'display-p3'\n /** The document's color profile; colors stored in it convert into `colorSpace`. */\n documentColorSpace?: ColorProfile\n /**\n * Line breaks of text nodes as the editor laid them out, wraps included. Without them, only\n * explicit newlines start a new baseline, which renderers that do not wrap SVG text keep.\n */\n textLayout?: SVGTextLayout\n /**\n * A family to name a font face by instead of its own, such as the one a PDF embeds the face's\n * file under. Text in an aliased face is written in that family at normal weight and style.\n */\n fontAlias?: SVGFontAlias\n /**\n * The live result path of a boolean operation made in Pairdraw, which stores none. Left out,\n * such a boolean draws its box and its operands, as an archive-less reader sees it.\n */\n booleanPath?: BooleanPathResolver\n}\n\nexport function renderNodesToSVG(\n graph: SceneGraph,\n _pageId: string,\n nodeIds: string[],\n options: SVGExportOptions = {}\n): string | null {\n const bounds = computeContentBounds(graph, nodeIds)\n if (!bounds) return null\n\n const { minX, minY, maxX, maxY } = bounds\n const width = round(maxX - minX)\n const height = round(maxY - minY)\n\n const ctx: SVGExportContext = {\n defs: [],\n defIdCounter: 0,\n graph,\n colorSpace: options.colorSpace ?? 'srgb',\n documentColorSpace: options.documentColorSpace ?? graph.documentColorSpace,\n textLayout: options.textLayout,\n fontAlias: options.fontAlias,\n booleanPath: options.booleanPath\n }\n\n const contentNodes: SVGNode[] = []\n\n for (const id of nodeIds) {\n const node = graph.getNode(id)\n if (!node?.visible) continue\n\n const abs = graph.getAbsolutePosition(id)\n const offsetX = abs.x - minX\n const offsetY = abs.y - minY\n\n const needsOffset = offsetX !== node.x || offsetY !== node.y\n const clone = needsOffset ? { ...node, x: round(offsetX), y: round(offsetY) } : node\n\n const rendered = renderNode(clone, ctx)\n if (rendered) contentNodes.push(rendered)\n }\n\n if (contentNodes.length === 0) return null\n\n const rootChildren: (SVGNode | string)[] = []\n if (ctx.defs.length > 0) {\n rootChildren.push(svg('defs', {}, ...ctx.defs))\n }\n rootChildren.push(...contentNodes)\n\n const root = svg(\n 'svg',\n {\n xmlns: 'http://www.w3.org/2000/svg',\n 'xmlns:xlink': 'http://www.w3.org/1999/xlink',\n width,\n height,\n viewBox: `0 0 ${width} ${height}`\n },\n ...(rootChildren as SVGNode[])\n )\n\n const svgStr = renderSVGNode(root)\n const xmlDecl = options.xmlDeclaration !== false ? '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n' : ''\n return xmlDecl + svgStr\n}\n\n/**\n * One layer as an `<svg>` element sized to its box, for inlining in HTML where the box already\n * places, rotates, and fades it: the drawing starts at the layer's origin without its rotation\n * or opacity, and keeps its flips.\n */\nexport function renderNodeSVGElement(\n graph: SceneGraph,\n node: SceneNode,\n {\n idPrefix,\n colorSpace = 'srgb',\n documentColorSpace,\n tint,\n booleanPath\n }: Pick<SVGExportContext, 'tint' | 'booleanPath'> & {\n idPrefix: string\n colorSpace?: RenderColorSpace\n documentColorSpace?: ColorProfile\n }\n): SVGNode | null {\n const ctx: SVGExportContext = {\n defs: [],\n defIdCounter: 0,\n graph,\n colorSpace,\n documentColorSpace: documentColorSpace ?? graph.documentColorSpace,\n idPrefix,\n tint,\n booleanPath\n }\n const drawn = renderNode({ ...node, x: 0, y: 0, rotation: 0, opacity: 1 }, ctx)\n if (!drawn) return null\n // A straight line has no height or width, but its stroke still needs a viewport to draw in.\n const width = Math.max(1, round(node.width))\n const height = Math.max(1, round(node.height))\n return svg(\n 'svg',\n { width, height, viewBox: `0 0 ${width} ${height}` },\n ctx.defs.length > 0 ? svg('defs', {}, ...ctx.defs) : null,\n drawn\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyDA,SAAS,gBACP,MACA,SACA,QACW;CACX,MAAM,UAAU,eAAe,OAAO,CAAC,CAAC,KAAK,MAAM,IAAI,QAAQ;EAAE;EAAG,GAAG;CAAO,CAAC,CAAC;CAChF,IAAI,cAAc,OAAO,CAAC,CAAC,WAAW,GAAG,OAAO;CAChD,OAAO,CAAC,GAAG,SAAS,GAAG,iBAAiB,MAAM,SAAS,QAAQ,aAAa,CAAC;AAC/E;;AAGA,SAAS,mBACP,OACA,cACA,aACA,QACA,MACA,KACW;CACX,MAAM,WAAsB,CAAC;CAC7B,KAAK,MAAM,CAAC,OAAO,SAAS,aAAa,QAAQ,GAAG;EAClD,MAAM,WAAW,YAAY,MAAM,MAAM,GAAG;EAC5C,IAAI,CAAC,UAAU;EACf,MAAM,QAAQ,gBAAgB,IAAI;EAClC,MAAM,OAAO,UAAU,aAAa,SAAS;EAC7C,MAAM,cAAc,UAAU,KAAA,KAAa,QAAQ,OAAO,WAAW;EACrE,MAAM,SAAS,QAAQ,CAAC,cAAc,OAAO,SAAS;EACtD,SAAS,KACP,IAAI,QAAQ;GACV,GAAG;GACH,MAAM;GACN,gBAAgB,iBAAiB,MAAM,IAAI,UAAU;GACrD;GACA;EACF,CAAC,CACH;EACA,IAAI,aACF,SAAS,KACP,IAAI,QAAQ;GACV,GAAG,MAAM;GACT,aAAa,MAAM;GACnB,MAAM;GACN,GAAG;EACL,CAAC,CACH;CAEJ;CACA,OAAO;AACT;AAEA,SAAS,oBACP,MACA,QACA,aACA,KACA,eACW;CACX,MAAM,WAAsB,CAAC;CAC7B,IAAI,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Aa,KAAK,GAAG,YAAY;CAEjC,MAAM,OAAO,IACX,OACA;EACE,OAAO;EACP,eAAe;EACf;EACA;EACA,SAAS,OAAO,MAAM,GAAG;CAC3B,GACA,GAAI,YACN;CAEA,MAAM,SAAS,cAAc,IAAI;CAEjC,QADgB,QAAQ,mBAAmB,QAAQ,iDAA6C,MAC/E;AACnB;;;;;;AAOA,SAAgB,qBACd,OACA,MACA,EACE,UACA,aAAa,QACb,oBACA,MACA,eAMc;CAChB,MAAM,MAAwB;EAC5B,MAAM,CAAC;EACP,cAAc;EACd;EACA;EACA,oBAAoB,sBAAsB,MAAM;EAChD;EACA;EACA;CACF;CACA,MAAM,QAAQ,WAAW;EAAE,GAAG;EAAM,GAAG;EAAG,GAAG;EAAG,UAAU;EAAG,SAAS;CAAE,GAAG,GAAG;CAC9E,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,QAAQ,KAAK,IAAI,GAAG,MAAM,KAAK,KAAK,CAAC;CAC3C,MAAM,SAAS,KAAK,IAAI,GAAG,MAAM,KAAK,MAAM,CAAC;CAC7C,OAAO,IACL,OACA;EAAE;EAAO;EAAQ,SAAS,OAAO,MAAM,GAAG;CAAS,GACnD,IAAI,KAAK,SAAS,IAAI,IAAI,QAAQ,CAAC,GAAG,GAAG,IAAI,IAAI,IAAI,MACrD,KACF;AACF"}
|
|
1
|
+
{"version":3,"file":"export.js","names":[],"sources":["../../../../src/io/formats/svg/export.ts"],"sourcesContent":["import type {\n ColorProfile,\n Fill,\n SceneGraph,\n SceneNode,\n Stroke,\n VectorNetwork\n} from '@pairdraw/scene-graph'\nimport type { RenderColorSpace } from '@pairdraw/scene-graph/color'\nimport type { VisualBounds } from '@pairdraw/scene-graph/geometry'\n\nimport { normalizeDashPattern } from '#core/canvas/strokes'\nimport { lineStrokePath } from '#core/canvas/strokes/line'\nimport { fittedDashPattern } from '#core/canvas/strokes/sides'\nimport { computeContentBounds, sliceRegion } from '#core/io/formats/raster'\n\nimport {\n nextDefId,\n formatSolidColor,\n resolveFill,\n solidFillOpacity,\n SVG_STROKE_CAP,\n SVG_STROKE_JOIN,\n SVG_BLEND_MODE\n} from './defs'\nimport { createFilterDef } from './effects'\nimport {\n round,\n geometryBlobToSVGPath,\n makePolygonPoints,\n roundedPolygonPath,\n hasRadius,\n hasSmoothCorners,\n boxOutlinePath,\n arcPath,\n shapeWithTextOutlinePath\n} from './paths'\n\nexport { geometryBlobToSVGPath, nodeOutlinePath, type OutlineNode } from './paths'\n\nimport { looseSegments, regionSVGPaths } from '@pairdraw/scene-graph/vector-network'\n\nimport type { BooleanPathResolver } from '#core/io/formats/boolean-path'\n\nimport { arrowHeadElements, openPathElements, vectorArrowHeads } from './arrows'\nimport type { SVGExportContext, SVGFontAlias } from './defs'\nimport { svg, renderSVGNode } from './node'\nimport type { SVGNode } from './node'\nimport { alignedStroke, alignedStrokeElement, shapeWithTextDetailElements } from './strokes'\nimport { renderTextNode } from './text/export'\nimport type { SVGTextLayout } from './text/lines'\n\n// --- Node rendering ---\n\n/**\n * A vector network's paths: its regions as they are traced, and its open segments as the canvas\n * strokes them, rounded and pulled back under their heads.\n */\nfunction networkElements(\n node: SceneNode,\n network: VectorNetwork,\n common: Record<string, string | number | undefined>\n): SVGNode[] {\n const regions = regionSVGPaths(network).map((d) => svg('path', { d, ...common }))\n if (looseSegments(network).length === 0) return regions\n return [...regions, ...openPathElements(node, network, common, looseSegments)]\n}\n\n/** Paints one path's fill stack; a blended fill draws its stroke as a separate path. */\nfunction vectorFillElements(\n attrs: Record<string, string | number | undefined>,\n visibleFills: Fill[],\n strokeAttrs: Record<string, string | number | undefined>,\n common: Record<string, string | number | undefined>,\n node: SceneNode,\n ctx: SVGExportContext\n): SVGNode[] {\n const elements: SVGNode[] = []\n for (const [index, fill] of visibleFills.entries()) {\n const fillAttr = resolveFill(fill, node, ctx)\n if (!fillAttr) continue\n const style = paintBlendStyle(fill)\n const last = index === visibleFills.length - 1\n const splitStroke = style !== undefined && last && common.stroke !== 'none'\n const stroke = last && !splitStroke ? common.stroke : 'none'\n elements.push(\n svg('path', {\n ...attrs,\n fill: fillAttr,\n 'fill-opacity': solidFillOpacity(fill, ctx.colorSpace),\n style,\n stroke\n })\n )\n if (splitStroke) {\n elements.push(\n svg('path', {\n d: attrs.d,\n 'fill-rule': attrs['fill-rule'],\n fill: 'none',\n ...strokeAttrs\n })\n )\n }\n }\n return elements\n}\n\nfunction vectorShapeElements(\n node: SceneNode,\n common: Record<string, string | number | undefined>,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext,\n fallbackFills?: Fill[]\n): SVGNode[] {\n const elements: SVGNode[] = []\n if (node.fillGeometry.length > 0) {\n for (const geo of node.fillGeometry) {\n const d = geometryBlobToSVGPath(geo.commandsBlob)\n if (!d) continue\n const attrs = {\n d,\n 'fill-rule': geo.windingRule === 'EVENODD' ? 'evenodd' : undefined,\n ...common\n }\n const pathFills = geo.fills?.length ? geo.fills : fallbackFills\n if (!pathFills) {\n elements.push(svg('path', attrs))\n continue\n }\n const visibleFills = pathFills.filter((fill) => fill.visible)\n if (visibleFills.length === 0) {\n elements.push(svg('path', { ...attrs, fill: 'none' }))\n continue\n }\n elements.push(...vectorFillElements(attrs, visibleFills, strokeAttrs, common, node, ctx))\n }\n } else if (node.vectorNetwork) {\n elements.push(...networkElements(node, node.vectorNetwork, common))\n }\n elements.push(...vectorStrokeTail(node, strokeAttrs))\n return withVectorFallback(elements, node, common)\n}\n\n/** The empty vector's fallback shape, after both paints have contributed their elements. */\nfunction withVectorFallback(\n elements: SVGNode[],\n node: SceneNode,\n common: Record<string, string | number | undefined>\n): SVGNode[] {\n return elements.length > 0\n ? elements\n : [svg('rect', { width: round(node.width), height: round(node.height), ...common })]\n}\n\n/** The stored stroke geometry and arrowheads both vector paints share after their outlines. */\nfunction vectorStrokeTail(\n node: SceneNode,\n strokeAttrs: Record<string, string | number | undefined>\n): SVGNode[] {\n const elements: SVGNode[] = []\n if (node.strokeGeometry.length > 0 && strokeAttrs.stroke && strokeAttrs.stroke !== 'none') {\n for (const geo of node.strokeGeometry) {\n const d = geometryBlobToSVGPath(geo.commandsBlob)\n if (d) {\n elements.push(\n svg('path', {\n d,\n fill: strokeAttrs.stroke,\n 'fill-opacity': strokeAttrs['stroke-opacity'],\n stroke: 'none'\n })\n )\n }\n }\n }\n if (node.vectorNetwork) elements.push(...vectorArrowHeads(node, node.vectorNetwork, strokeAttrs))\n return elements\n}\n\n/** A vector layer's outlines as strokes alone, for a second stroke over the painted fills. */\nfunction vectorStrokeElements(\n node: SceneNode,\n strokeAttrs: Record<string, string | number | undefined>\n): SVGNode[] {\n const elements: SVGNode[] = []\n const common: Record<string, string | number | undefined> = { fill: 'none', ...strokeAttrs }\n if (node.fillGeometry.length > 0) {\n for (const geo of node.fillGeometry) {\n const d = geometryBlobToSVGPath(geo.commandsBlob)\n if (d) {\n elements.push(\n svg('path', {\n d,\n 'fill-rule': geo.windingRule === 'EVENODD' ? 'evenodd' : undefined,\n ...common\n })\n )\n }\n }\n } else if (node.vectorNetwork) {\n elements.push(...networkElements(node, node.vectorNetwork, common))\n }\n elements.push(...vectorStrokeTail(node, strokeAttrs))\n return withVectorFallback(elements, node, common)\n}\n\n/** A line's dashes stretched along it as the canvas lays them, half a dash at each end. */\nfunction lineDashAttrs(stroke: Stroke | undefined, length: number) {\n const fitted = fittedDashPattern(length, normalizeDashPattern(stroke?.dashPattern))\n if (!fitted) return {}\n return {\n 'stroke-dasharray': fitted.intervals.map((size) => round(size)).join(' '),\n 'stroke-dashoffset': round(fitted.offset)\n }\n}\n\nfunction nodeShapeElements(\n node: SceneNode,\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext,\n stroke?: Stroke\n): SVGNode[] {\n const common: Record<string, string | number | undefined> = {\n fill: fillAttr ?? 'none',\n 'fill-opacity': fillOpacity,\n ...strokeAttrs\n }\n\n switch (node.type) {\n case 'ELLIPSE': {\n if (node.arcData) {\n return [svg('path', { d: arcPath(node), ...common })]\n }\n return [\n svg('ellipse', {\n cx: round(node.width / 2),\n cy: round(node.height / 2),\n rx: round(node.width / 2),\n ry: round(node.height / 2),\n ...common\n })\n ]\n }\n\n case 'LINE': {\n // Where the canvas strokes it: to one side of the line, with its caps inside its length.\n const lineStroke = stroke ?? node.strokes.find((item) => item.visible)\n const {\n network,\n from: start,\n to: end\n } = lineStrokePath(node, lineStroke?.weight ?? 0, lineStroke?.cap ?? node.strokeCap)\n return [\n svg('line', {\n x1: round(start.x),\n y1: round(start.y),\n x2: round(end.x),\n y2: round(end.y),\n fill: 'none',\n ...strokeAttrs,\n ...lineDashAttrs(lineStroke, Math.hypot(end.x - start.x, end.y - start.y))\n }),\n ...arrowHeadElements(node, network, lineStroke, strokeAttrs)\n ]\n }\n\n case 'STAR':\n case 'POLYGON':\n return node.cornerRadius > 0\n ? [svg('path', { d: roundedPolygonPath(node), ...common })]\n : [svg('polygon', { points: makePolygonPoints(node), ...common })]\n\n case 'VECTOR':\n return vectorShapeElements(node, common, strokeAttrs, ctx)\n\n case 'SHAPE_WITH_TEXT':\n return shapeWithTextElements(node, common, strokeAttrs, ctx)\n\n default:\n return [boxOutlineElement(node, common)]\n }\n}\n\n/**\n * A box layer's outline as one element: a rect, a rect with `rx`/`ry` for one radius, or the\n * shared box path for independent or smoothed corners, so fills and clips follow the same edge.\n */\nfunction boxOutlineElement(\n node: SceneNode,\n attrs: Record<string, string | number | undefined>\n): SVGNode {\n const width = round(node.width)\n const height = round(node.height)\n if (!hasRadius(node)) return svg('rect', { width, height, ...attrs })\n if (node.independentCorners || hasSmoothCorners(node)) {\n return svg('path', { d: boxOutlinePath(node), ...attrs })\n }\n // SVG clamps rx and ry to their own sides; the canvas keeps a too-large radius circular.\n const radius = round(Math.min(node.cornerRadius, node.width / 2, node.height / 2))\n return svg('rect', { width, height, rx: radius, ry: radius, ...attrs })\n}\n\n/**\n * A FigJam shape's outline, and its inner lines, such as a database's front rim, stroked as the\n * canvas strokes them: at the stroke's own weight, ending where the outline does.\n */\nfunction shapeWithTextElements(\n node: SceneNode,\n common: Record<string, string | number | undefined>,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext\n): SVGNode[] {\n return [\n svg('path', { d: shapeWithTextOutlinePath(node), ...common }),\n ...shapeWithTextDetailElements(node, strokeAttrs, ctx)\n ]\n}\n\n// --- Main recursive renderer ---\n\nfunction buildTransformAttr(node: SceneNode): string | undefined {\n const transforms: string[] = []\n if (node.x !== 0 || node.y !== 0) transforms.push(`translate(${round(node.x)}, ${round(node.y)})`)\n if (node.rotation !== 0) {\n transforms.push(\n `rotate(${round(node.rotation)}, ${round(node.width / 2)}, ${round(node.height / 2)})`\n )\n }\n if (node.flipX || node.flipY) {\n const tx = node.flipX ? node.width : 0\n const ty = node.flipY ? node.height : 0\n const sx = node.flipX ? -1 : 1\n const sy = node.flipY ? -1 : 1\n transforms.push(`translate(${round(tx)}, ${round(ty)}) scale(${sx}, ${sy})`)\n }\n return transforms.length > 0 ? transforms.join(' ') : undefined\n}\n\nfunction buildGroupAttrs(\n node: SceneNode,\n ctx: SVGExportContext\n): { attrs: Record<string, string | number | undefined>; clipId?: string } {\n const attrs: Record<string, string | number | undefined> = {}\n\n const transform = buildTransformAttr(node)\n if (transform) attrs.transform = transform\n\n if (node.opacity < 1) attrs.opacity = round(node.opacity)\n\n const blend = SVG_BLEND_MODE[node.blendMode]\n if (blend && blend !== 'normal' && node.blendMode !== 'PASS_THROUGH') {\n attrs.style = `mix-blend-mode: ${blend}`\n }\n\n const filterDef = createFilterDef(node, ctx)\n if (filterDef) {\n ctx.defs.push(filterDef.node)\n attrs.filter = `url(#${filterDef.id})`\n }\n\n let clipId: string | undefined\n if (node.clipsContent && node.childIds.length > 0) {\n clipId = nextDefId(ctx, 'clip')\n ctx.defs.push(svg('clipPath', { id: clipId }, boxOutlineElement(node, {})))\n }\n\n return { attrs, clipId }\n}\n\nfunction buildSVGStrokeAttrs(\n stroke: Stroke,\n node: SceneNode,\n ctx: SVGExportContext\n): Record<string, string | number | undefined> {\n const cap = stroke.cap ?? node.strokeCap\n const attrs: Record<string, string | number | undefined> = {\n // Opacity 1 keeps the color opaque. Display P3 must not also keep color alpha here, or a\n // viewer multiplies it by stroke-opacity; the canvas paints stroke.opacity alone.\n stroke:\n stroke.type === 'SOLID'\n ? formatSolidColor(stroke.color, 1, ctx.colorSpace, ctx.documentColorSpace)\n : (resolveFill(stroke, node, ctx) ??\n formatSolidColor(stroke.color, 1, ctx.colorSpace, ctx.documentColorSpace)),\n 'stroke-width': round(stroke.weight)\n }\n if (stroke.opacity < 1) attrs['stroke-opacity'] = round(stroke.opacity)\n if (cap !== 'NONE') attrs['stroke-linecap'] = SVG_STROKE_CAP[cap] ?? 'butt'\n if (stroke.join && stroke.join !== 'MITER') {\n attrs['stroke-linejoin'] = SVG_STROKE_JOIN[stroke.join] ?? 'miter'\n }\n if (stroke.dashPattern && stroke.dashPattern.length > 0) {\n attrs['stroke-dasharray'] = stroke.dashPattern.map((n) => round(n)).join(' ')\n }\n return attrs\n}\n\n/** The blend CSS a paint adds, when the canvas would not composite it source-over. */\nfunction paintBlendStyle(fill: Fill | undefined): string | undefined {\n const blend = fill?.blendMode ? SVG_BLEND_MODE[fill.blendMode] : undefined\n return blend && blend !== 'normal' ? `mix-blend-mode: ${blend}` : undefined\n}\n\n/** Adds a paint's blend mode to the elements that draw it. */\nfunction withPaintBlend(elements: SVGNode[], fill: Fill | undefined): SVGNode[] {\n const style = paintBlendStyle(fill)\n if (style) for (const element of elements) element.attrs.style = style\n return elements\n}\n\n/**\n * Draws the fill and the stroke as separate elements when the fill blends, so the stroke keeps the\n * source-over canvas gives it instead of inheriting the fill's blend mode.\n */\nfunction shapeWithPaint(\n node: SceneNode,\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n fill: Fill | undefined,\n ctx: SVGExportContext\n): SVGNode[] {\n const blends = paintBlendStyle(fill) !== undefined\n if (!blends || !strokeAttrs.stroke) {\n return withPaintBlend(nodeShapeElements(node, fillAttr, fillOpacity, strokeAttrs, ctx), fill)\n }\n return [\n ...withPaintBlend(nodeShapeElements(node, fillAttr, fillOpacity, {}, ctx), fill),\n ...nodeShapeElements(node, null, undefined, strokeAttrs, ctx)\n ]\n}\n\nfunction hasPathLevelFills(node: SceneNode): boolean {\n return node.type === 'VECTOR' && node.fillGeometry.some((geometry) => geometry.fills?.length)\n}\n\n/** One stroke at its own weight over the fills: a centred one on the outline, an aligned one around it. */\nfunction strokeElements(\n node: SceneNode,\n stroke: Stroke,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext\n): SVGNode[] {\n const aligned = hasPathLevelFills(node) ? null : alignedStroke(node, stroke)\n if (aligned) {\n return [\n ...alignedStrokeElement(node, aligned, strokeAttrs, ctx),\n ...(node.type === 'SHAPE_WITH_TEXT'\n ? shapeWithTextDetailElements(node, strokeAttrs, ctx)\n : [])\n ]\n }\n if (node.type === 'VECTOR') return vectorStrokeElements(node, strokeAttrs)\n return nodeShapeElements(node, null, undefined, strokeAttrs, ctx, stroke)\n}\n\n/**\n * The fills and the strokes over them. The first stroke joins the fill's own element as before;\n * every later visible stroke is drawn in layer order, without painting the fill again.\n */\nfunction buildShapeChildren(\n node: SceneNode,\n visibleFills: Fill[],\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>[],\n visibleStrokes: Stroke[],\n ctx: SVGExportContext\n): SVGNode[] {\n if (visibleStrokes.length === 0) {\n return fillAndStrokeElements(node, visibleFills, fillAttr, fillOpacity, {}, 0, ctx)\n }\n const first = visibleStrokes[0]\n const firstAttrs = strokeAttrs[0]\n const elements = alignedStroke(node, first)\n ? // The fill goes as it is, and the stroke over it inside or outside the outline.\n [\n ...fillAndStrokeElements(node, visibleFills, fillAttr, fillOpacity, {}, 0, ctx),\n ...strokeElements(node, first, firstAttrs, ctx)\n ]\n : fillAndStrokeElements(\n node,\n visibleFills,\n fillAttr,\n fillOpacity,\n firstAttrs,\n visibleStrokes.length,\n ctx\n )\n for (let index = 1; index < visibleStrokes.length; index++) {\n elements.push(...strokeElements(node, visibleStrokes[index], strokeAttrs[index], ctx))\n }\n return elements\n}\n\nfunction fillAndStrokeElements(\n node: SceneNode,\n visibleFills: Fill[],\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n visibleStrokeCount: number,\n ctx: SVGExportContext\n): SVGNode[] {\n if (hasPathLevelFills(node)) {\n return vectorShapeElements(\n node,\n { fill: fillAttr ?? 'none', 'fill-opacity': fillOpacity, ...strokeAttrs },\n strokeAttrs,\n ctx,\n visibleFills\n )\n }\n\n if (visibleFills.length > 1) {\n const elements: SVGNode[] = []\n for (const fill of visibleFills) {\n const ref = resolveFill(fill, node, ctx)\n if (ref) {\n elements.push(\n ...shapeWithPaint(\n node,\n ref,\n solidFillOpacity(fill, ctx.colorSpace),\n fill === visibleFills[visibleFills.length - 1] ? strokeAttrs : {},\n fill,\n ctx\n )\n )\n }\n }\n return elements\n }\n\n const hasFillOrStroke = fillAttr || visibleStrokeCount > 0\n if (hasFillOrStroke && !isGroupLike(node)) {\n return shapeWithPaint(\n node,\n fillAttr,\n fillOpacity,\n strokeAttrs,\n visibleFills.length === 1 ? visibleFills[0] : undefined,\n ctx\n )\n }\n\n return []\n}\n\n/** The paint CSS `color` sets, for a tinted icon path. */\nconst CURRENT_COLOR = 'currentColor'\n\n/** A paint's SVG color and, for an sRGB solid, the `fill-opacity` beside it. */\nfunction exportedFill(\n fill: Fill | undefined,\n node: SceneNode,\n ctx: SVGExportContext\n): { color: string | null; opacity: number | undefined } {\n if (!fill) return { color: null, opacity: undefined }\n return {\n color: resolveFill(fill, node, ctx),\n opacity: solidFillOpacity(fill, ctx.colorSpace)\n }\n}\n\n/**\n * A mask layer's definition: an alpha or luminance `<mask>`, or a `<clipPath>` for an outline\n * mask. The rendered layer carries its own position, opacity, and filters into the mask.\n */\nfunction maskWire(\n mask: SceneNode,\n ctx: SVGExportContext\n): { attribute: 'mask' | 'clip-path'; id: string } {\n const content = renderNode(mask, ctx)\n if (mask.maskType === 'VECTOR') {\n const id = nextDefId(ctx, 'clip')\n ctx.defs.push(svg('clipPath', { id, clipPathUnits: 'userSpaceOnUse' }, content ?? undefined))\n return { attribute: 'clip-path', id }\n }\n const id = nextDefId(ctx, 'mask')\n const attrs: Record<string, string | number | undefined> = {\n id,\n maskContentUnits: 'userSpaceOnUse'\n }\n if (mask.maskType === 'ALPHA') attrs['mask-type'] = 'alpha'\n ctx.defs.push(svg('mask', attrs, content ?? undefined))\n return { attribute: 'mask', id }\n}\n\n/**\n * The children as the canvas draws them: a run of visible masks masks the siblings that follow\n * it, until the next mask, and the mask layers themselves never draw on their own.\n */\nfunction maskedChildNodes(childNodes: SceneNode[], ctx: SVGExportContext): SVGNode[] {\n const content: SVGNode[] = []\n let masks: Array<{ attribute: 'mask' | 'clip-path'; id: string }> = []\n let afterMask = false\n for (const child of childNodes) {\n if (child.visible && child.isMask) {\n const wire = maskWire(child, ctx)\n masks = afterMask ? [...masks, wire] : [wire]\n afterMask = true\n continue\n }\n const rendered = renderNode(child, ctx)\n afterMask = false\n if (!rendered) continue\n let wrapped = rendered\n for (const wire of masks) wrapped = svg('g', { [wire.attribute]: `url(#${wire.id})` }, wrapped)\n content.push(wrapped)\n }\n return content\n}\n\n/** A boolean's live result path in the paints its fills and strokes give it. */\nfunction booleanPathElements(\n node: SceneNode,\n d: string,\n visibleFills: Fill[],\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Array<Record<string, string | number | undefined>>,\n visibleStrokes: Stroke[],\n ctx: SVGExportContext\n): SVGNode[] {\n const common = { d, 'fill-rule': 'evenodd' as const }\n // A centred first stroke joins the fill element, as a shape's does; every later stroke, and\n // every inside or outside stroke, is drawn over the result outline on its own. An unset\n // alignment strokes the centred way, as `alignedStroke` treats it.\n const centered = (stroke: Stroke): boolean =>\n stroke.align !== 'INSIDE' && stroke.align !== 'OUTSIDE'\n const firstJoins = visibleStrokes.length > 0 && centered(visibleStrokes[0])\n const joined = firstJoins ? strokeAttrs[0] : {}\n const elements =\n visibleFills.length <= 1\n ? [\n svg('path', {\n ...common,\n fill: fillAttr ?? 'none',\n 'fill-opacity': fillOpacity,\n ...joined\n })\n ]\n : visibleFills.map((fill, index) =>\n svg('path', {\n ...common,\n fill: resolveFill(fill, node, ctx) ?? 'none',\n 'fill-opacity': solidFillOpacity(fill, ctx.colorSpace),\n ...(index === visibleFills.length - 1 ? joined : {})\n })\n )\n\n for (let index = firstJoins ? 1 : 0; index < visibleStrokes.length; index++) {\n const stroke = visibleStrokes[index]\n const attrs = strokeAttrs[index]\n elements.push(\n ...(centered(stroke)\n ? [svg('path', { d, fill: 'none', ...attrs })]\n : alignedStrokeElement(node, stroke, attrs, ctx, d))\n )\n }\n return elements\n}\n\n/** A boolean made in Pairdraw draws its computed result path instead of its operands. */\nfunction renderBooleanNode(\n node: SceneNode,\n ctx: SVGExportContext,\n paint: {\n groupAttrs: Record<string, string | number | undefined>\n visibleFills: Fill[]\n fillAttr: string | null\n fillOpacity: number | undefined\n strokeAttrs: Array<Record<string, string | number | undefined>>\n visibleStrokes: Stroke[]\n }\n): SVGNode | null {\n if (node.type !== 'BOOLEAN_OPERATION' || node.fillGeometry.length > 0 || !ctx.booleanPath) {\n return null\n }\n const d = ctx.booleanPath(ctx.graph, node)\n if (!d) return null\n return svg(\n 'g',\n paint.groupAttrs,\n ...booleanPathElements(\n node,\n d,\n paint.visibleFills,\n paint.fillAttr,\n paint.fillOpacity,\n paint.strokeAttrs,\n paint.visibleStrokes,\n ctx\n )\n )\n}\n\nfunction renderNode(node: SceneNode, ctx: SVGExportContext): SVGNode | null {\n if (!node.visible || node.type === 'SLICE') return null\n\n const { attrs: groupAttrs, clipId } = buildGroupAttrs(node, ctx)\n\n if (node.type === 'TEXT') {\n const fill = exportedFill(\n node.fills.find((f) => f.visible),\n node,\n ctx\n )\n return svg('g', groupAttrs, renderTextNode(node, fill.color, ctx, fill.opacity))\n }\n\n const visibleFills = node.fills.filter((f) => f.visible)\n const visibleStrokes = node.strokes.filter((s) => s.visible)\n const tint = ctx.tint?.(node) ?? []\n const ownFill = visibleFills.length > 0 && !hasPathLevelFills(node) ? visibleFills[0] : undefined\n const fill = exportedFill(ownFill, node, ctx)\n const tintedFill = fill.color !== null && tint.includes('fill')\n const fillAttr = tintedFill ? CURRENT_COLOR : fill.color\n // `currentColor` has no alpha. Display P3 normally bakes solid opacity into the color, which a\n // tint throws away, so a tinted solid keeps `fill-opacity` in every color space.\n const fillOpacity = ownFill ? solidFillOpacity(ownFill, ctx.colorSpace, tintedFill) : fill.opacity\n const strokeAttrs = visibleStrokes.map((stroke) => {\n const attrs = buildSVGStrokeAttrs(stroke, node, ctx)\n return tint.includes('stroke') ? { ...attrs, stroke: CURRENT_COLOR } : attrs\n })\n\n const booleanDrawn = renderBooleanNode(node, ctx, {\n groupAttrs,\n visibleFills,\n fillAttr,\n fillOpacity,\n strokeAttrs,\n visibleStrokes\n })\n if (booleanDrawn) return booleanDrawn\n\n const children: (SVGNode | null)[] = buildShapeChildren(\n node,\n visibleFills,\n fillAttr,\n fillOpacity,\n strokeAttrs,\n visibleStrokes,\n ctx\n )\n\n const childContent = maskedChildNodes(ctx.graph.getChildren(node.id), ctx)\n\n if (clipId && childContent.length > 0) {\n children.push(svg('g', { 'clip-path': `url(#${clipId})` }, ...childContent))\n } else {\n children.push(...childContent)\n }\n\n const validChildren = children.filter((c): c is SVGNode => c !== null)\n\n if (validChildren.length === 0 && Object.keys(groupAttrs).length === 0) {\n return null\n }\n\n if (validChildren.length === 1 && Object.keys(groupAttrs).length === 0) {\n return validChildren[0]\n }\n\n return svg('g', groupAttrs, ...validChildren)\n}\n\nfunction isGroupLike(node: SceneNode): boolean {\n return node.type === 'GROUP'\n}\n\n// --- Public API ---\n\nexport interface SVGExportOptions {\n /** Include XML declaration (default: true) */\n xmlDeclaration?: boolean\n /** Target export color space (default: srgb) */\n colorSpace?: 'srgb' | 'display-p3'\n /** The document's color profile; colors stored in it convert into `colorSpace`. */\n documentColorSpace?: ColorProfile\n /**\n * Line breaks of text nodes as the editor laid them out, wraps included. Without them, only\n * explicit newlines start a new baseline, which renderers that do not wrap SVG text keep.\n */\n textLayout?: SVGTextLayout\n /**\n * A family to name a font face by instead of its own, such as the one a PDF embeds the face's\n * file under. Text in an aliased face is written in that family at normal weight and style.\n */\n fontAlias?: SVGFontAlias\n /**\n * The live result path of a boolean operation made in Pairdraw, which stores none. Left out,\n * such a boolean draws its box and its operands, as an archive-less reader sees it.\n */\n booleanPath?: BooleanPathResolver\n}\n\nfunction svgExportContext(graph: SceneGraph, options: SVGExportOptions): SVGExportContext {\n return {\n defs: [],\n defIdCounter: 0,\n graph,\n colorSpace: options.colorSpace ?? 'srgb',\n documentColorSpace: options.documentColorSpace ?? graph.documentColorSpace,\n textLayout: options.textLayout,\n fontAlias: options.fontAlias,\n booleanPath: options.booleanPath\n }\n}\n\n/** The slice's box, and the page content under it, clipped: a slice has no vector geometry of its own. */\nexport function renderRegionSVG(\n graph: SceneGraph,\n pageId: string,\n bounds: VisualBounds,\n options: SVGExportOptions = {}\n): string | null {\n const page = graph.getNode(pageId)\n if (!page) return null\n const { minX, minY, maxX, maxY } = bounds\n const width = round(maxX - minX)\n const height = round(maxY - minY)\n if (width <= 0 || height <= 0) return null\n const ctx = svgExportContext(graph, options)\n const contentNodes: SVGNode[] = []\n for (const id of page.childIds) {\n const node = graph.getNode(id)\n if (!node?.visible || node.type === 'SLICE') continue\n const abs = graph.getAbsolutePosition(id)\n const offsetX = abs.x - minX\n const offsetY = abs.y - minY\n const rendered = renderNode(\n offsetX !== node.x || offsetY !== node.y\n ? { ...node, x: round(offsetX), y: round(offsetY) }\n : node,\n ctx\n )\n if (rendered) contentNodes.push(rendered)\n }\n if (contentNodes.length === 0) return null\n const clipId = nextDefId(ctx, 'slice')\n ctx.defs.push(\n svg(\n 'clipPath',\n { id: clipId, clipPathUnits: 'userSpaceOnUse' },\n svg('rect', { x: 0, y: 0, width, height })\n )\n )\n const root = svg(\n 'svg',\n {\n xmlns: 'http://www.w3.org/2000/svg',\n 'xmlns:xlink': 'http://www.w3.org/1999/xlink',\n width,\n height,\n viewBox: `0 0 ${width} ${height}`\n },\n svg('defs', {}, ...ctx.defs),\n svg('g', { 'clip-path': `url(#${clipId})` }, ...contentNodes)\n )\n const svgStr = renderSVGNode(root)\n const xmlDecl = options.xmlDeclaration !== false ? '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n' : ''\n return xmlDecl + svgStr\n}\n\nexport function renderNodesToSVG(\n graph: SceneGraph,\n pageId: string,\n nodeIds: string[],\n options: SVGExportOptions = {}\n): string | null {\n const box = sliceRegion(graph, nodeIds)\n if (box) return renderRegionSVG(graph, pageId, box, options)\n const bounds = computeContentBounds(graph, nodeIds)\n if (!bounds) return null\n\n const { minX, minY, maxX, maxY } = bounds\n const width = round(maxX - minX)\n const height = round(maxY - minY)\n\n const ctx = svgExportContext(graph, options)\n\n const contentNodes: SVGNode[] = []\n\n for (const id of nodeIds) {\n const node = graph.getNode(id)\n if (!node?.visible) continue\n\n const abs = graph.getAbsolutePosition(id)\n const offsetX = abs.x - minX\n const offsetY = abs.y - minY\n\n const needsOffset = offsetX !== node.x || offsetY !== node.y\n const clone = needsOffset ? { ...node, x: round(offsetX), y: round(offsetY) } : node\n\n const rendered = renderNode(clone, ctx)\n if (rendered) contentNodes.push(rendered)\n }\n\n if (contentNodes.length === 0) return null\n\n const rootChildren: (SVGNode | string)[] = []\n if (ctx.defs.length > 0) {\n rootChildren.push(svg('defs', {}, ...ctx.defs))\n }\n rootChildren.push(...contentNodes)\n\n const root = svg(\n 'svg',\n {\n xmlns: 'http://www.w3.org/2000/svg',\n 'xmlns:xlink': 'http://www.w3.org/1999/xlink',\n width,\n height,\n viewBox: `0 0 ${width} ${height}`\n },\n ...(rootChildren as SVGNode[])\n )\n\n const svgStr = renderSVGNode(root)\n const xmlDecl = options.xmlDeclaration !== false ? '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n' : ''\n return xmlDecl + svgStr\n}\n\n/**\n * One layer as an `<svg>` element sized to its box, for inlining in HTML where the box already\n * places, rotates, and fades it: the drawing starts at the layer's origin without its rotation\n * or opacity, and keeps its flips.\n */\nexport function renderNodeSVGElement(\n graph: SceneGraph,\n node: SceneNode,\n {\n idPrefix,\n colorSpace = 'srgb',\n documentColorSpace,\n tint,\n booleanPath\n }: Pick<SVGExportContext, 'tint' | 'booleanPath'> & {\n idPrefix: string\n colorSpace?: RenderColorSpace\n documentColorSpace?: ColorProfile\n }\n): SVGNode | null {\n const ctx: SVGExportContext = {\n defs: [],\n defIdCounter: 0,\n graph,\n colorSpace,\n documentColorSpace: documentColorSpace ?? graph.documentColorSpace,\n idPrefix,\n tint,\n booleanPath\n }\n const drawn = renderNode({ ...node, x: 0, y: 0, rotation: 0, opacity: 1 }, ctx)\n if (!drawn) return null\n // A straight line has no height or width, but its stroke still needs a viewport to draw in.\n const width = Math.max(1, round(node.width))\n const height = Math.max(1, round(node.height))\n return svg(\n 'svg',\n { width, height, viewBox: `0 0 ${width} ${height}` },\n ctx.defs.length > 0 ? svg('defs', {}, ...ctx.defs) : null,\n drawn\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0DA,SAAS,gBACP,MACA,SACA,QACW;CACX,MAAM,UAAU,eAAe,OAAO,CAAC,CAAC,KAAK,MAAM,IAAI,QAAQ;EAAE;EAAG,GAAG;CAAO,CAAC,CAAC;CAChF,IAAI,cAAc,OAAO,CAAC,CAAC,WAAW,GAAG,OAAO;CAChD,OAAO,CAAC,GAAG,SAAS,GAAG,iBAAiB,MAAM,SAAS,QAAQ,aAAa,CAAC;AAC/E;;AAGA,SAAS,mBACP,OACA,cACA,aACA,QACA,MACA,KACW;CACX,MAAM,WAAsB,CAAC;CAC7B,KAAK,MAAM,CAAC,OAAO,SAAS,aAAa,QAAQ,G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,GAAG;EAAM,GAAG;EAAG,GAAG;EAAG,UAAU;EAAG,SAAS;CAAE,GAAG,GAAG;CAC9E,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,QAAQ,KAAK,IAAI,GAAG,MAAM,KAAK,KAAK,CAAC;CAC3C,MAAM,SAAS,KAAK,IAAI,GAAG,MAAM,KAAK,MAAM,CAAC;CAC7C,OAAO,IACL,OACA;EAAE;EAAO;EAAQ,SAAS,OAAO,MAAM,GAAG;CAAS,GACnD,IAAI,KAAK,SAAS,IAAI,IAAI,QAAQ,CAAC,GAAG,GAAG,IAAI,IAAI,IAAI,MACrD,KACF;AACF"}
|
|
@@ -2,8 +2,8 @@ import { OutlineNode, geometryBlobToSVGPath, nodeOutlinePath } from "./paths.js"
|
|
|
2
2
|
import { SVGNode, renderSVGNode, svg } from "./node.js";
|
|
3
3
|
import { SVGCharacterEdges, SVGFallbackFace, SVGTextLayout, SVGTextLine } from "./text/lines.js";
|
|
4
4
|
import { SVGFontAlias, SVGFontRequest } from "./defs.js";
|
|
5
|
-
import { SVGExportOptions, renderNodesToSVG } from "./export.js";
|
|
5
|
+
import { SVGExportOptions, renderNodesToSVG, renderRegionSVG } from "./export.js";
|
|
6
6
|
import { SVGImportData, SVGImportOptions, createSVGNodes, createSVGNodesFromImport, prepareSVGImport } from "./import.js";
|
|
7
7
|
import { isSVGMarkup } from "./metadata.js";
|
|
8
8
|
import { svgImportFonts } from "./text/import.js";
|
|
9
|
-
export { type OutlineNode, type SVGCharacterEdges, type SVGExportOptions, type SVGFallbackFace, type SVGFontAlias, type SVGFontRequest, type SVGImportData, type SVGImportOptions, type SVGNode, type SVGTextLayout, type SVGTextLine, createSVGNodes, createSVGNodesFromImport, geometryBlobToSVGPath, isSVGMarkup, nodeOutlinePath, prepareSVGImport, renderNodesToSVG, renderSVGNode, svg, svgImportFonts };
|
|
9
|
+
export { type OutlineNode, type SVGCharacterEdges, type SVGExportOptions, type SVGFallbackFace, type SVGFontAlias, type SVGFontRequest, type SVGImportData, type SVGImportOptions, type SVGNode, type SVGTextLayout, type SVGTextLine, createSVGNodes, createSVGNodesFromImport, geometryBlobToSVGPath, isSVGMarkup, nodeOutlinePath, prepareSVGImport, renderNodesToSVG, renderRegionSVG, renderSVGNode, svg, svgImportFonts };
|