@pairdraw/core 0.20.0 → 0.21.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/noise/render.js +1 -1
- package/dist/canvas/noise/render.js.map +1 -1
- package/dist/canvas/noise/shader.d.ts +6 -3
- package/dist/canvas/noise/shader.d.ts.map +1 -1
- package/dist/canvas/noise/shader.js +12 -7
- package/dist/canvas/noise/shader.js.map +1 -1
- package/dist/canvas/noise/tile.d.ts.map +1 -1
- package/dist/canvas/noise/tile.js +2 -1
- package/dist/canvas/noise/tile.js.map +1 -1
- package/dist/canvas/renderer/colors.d.ts +20 -5
- package/dist/canvas/renderer/colors.d.ts.map +1 -1
- package/dist/canvas/renderer/colors.js +48 -42
- package/dist/canvas/renderer/colors.js.map +1 -1
- package/dist/canvas/renderer/document-surface.d.ts +25 -0
- package/dist/canvas/renderer/document-surface.d.ts.map +1 -0
- package/dist/canvas/renderer/document-surface.js +46 -0
- package/dist/canvas/renderer/document-surface.js.map +1 -0
- package/dist/canvas/renderer/fonts.d.ts.map +1 -1
- package/dist/canvas/renderer/fonts.js +6 -4
- package/dist/canvas/renderer/fonts.js.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +4 -3
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +1 -0
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +23 -2
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/retained-backing.d.ts.map +1 -1
- package/dist/canvas/renderer/retained-backing.js +2 -1
- package/dist/canvas/renderer/retained-backing.js.map +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.js +2 -7
- package/dist/canvas/renderer/tiles/surface-pool.js.map +1 -1
- package/dist/canvas/renderer.d.ts +20 -2
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +28 -4
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +4 -3
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/shaders/effect.d.ts.map +1 -1
- package/dist/canvas/shaders/effect.js +2 -1
- package/dist/canvas/shaders/effect.js.map +1 -1
- package/dist/canvas/shadows/shape.d.ts.map +1 -1
- package/dist/canvas/shadows/shape.js +4 -2
- package/dist/canvas/shadows/shape.js.map +1 -1
- package/dist/canvas/shadows.d.ts.map +1 -1
- package/dist/canvas/shadows.js +4 -2
- package/dist/canvas/shadows.js.map +1 -1
- package/dist/canvas/text/decorations.d.ts +2 -2
- package/dist/canvas/text/decorations.d.ts.map +1 -1
- package/dist/canvas/text/decorations.js +5 -5
- package/dist/canvas/text/decorations.js.map +1 -1
- package/dist/canvas/text/index.js +1 -1
- package/dist/canvas/text/index.js.map +1 -1
- package/dist/canvas/text/paragraph/index.d.ts +2 -2
- package/dist/canvas/text/paragraph/index.d.ts.map +1 -1
- package/dist/canvas/text/paragraph/index.js +16 -5
- package/dist/canvas/text/paragraph/index.js.map +1 -1
- package/dist/canvas/text/renderer.d.ts +2 -1
- package/dist/canvas/text/renderer.d.ts.map +1 -1
- package/dist/canvas/text/shape.js +4 -4
- package/dist/canvas/text/shape.js.map +1 -1
- package/dist/canvas/texture.d.ts.map +1 -1
- package/dist/canvas/texture.js +2 -1
- package/dist/canvas/texture.js.map +1 -1
- package/dist/design-memory/rules.js +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/clipboard/assets.d.ts.map +1 -1
- package/dist/editor/clipboard/assets.js +2 -2
- package/dist/editor/clipboard/assets.js.map +1 -1
- package/dist/editor/clipboard/component-matches.d.ts +13 -0
- package/dist/editor/clipboard/component-matches.d.ts.map +1 -0
- package/dist/editor/clipboard/component-matches.js +50 -0
- package/dist/editor/clipboard/component-matches.js.map +1 -0
- package/dist/editor/clipboard/dependencies.d.ts +7 -0
- package/dist/editor/clipboard/dependencies.d.ts.map +1 -1
- package/dist/editor/clipboard/dependencies.js +5 -0
- package/dist/editor/clipboard/dependencies.js.map +1 -1
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +48 -19
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/components/properties.d.ts.map +1 -1
- package/dist/editor/components/properties.js +3 -3
- package/dist/editor/components/properties.js.map +1 -1
- package/dist/editor/create.d.ts +1 -1
- package/dist/editor/eyedropper.d.ts +1 -1
- package/dist/editor/eyedropper.d.ts.map +1 -1
- package/dist/editor/eyedropper.js +6 -3
- package/dist/editor/eyedropper.js.map +1 -1
- package/dist/editor/history/atomic-tool.d.ts.map +1 -1
- package/dist/editor/history/atomic-tool.js +3 -2
- package/dist/editor/history/atomic-tool.js.map +1 -1
- package/dist/editor/shapes/pencil.js +1 -1
- package/dist/editor/structure/state.d.ts.map +1 -1
- package/dist/editor/structure/state.js +2 -2
- package/dist/editor/structure/state.js.map +1 -1
- package/dist/editor/text.d.ts.map +1 -1
- package/dist/editor/text.js +2 -2
- package/dist/editor/text.js.map +1 -1
- package/dist/editor/variables.js +3 -3
- package/dist/editor/variables.js.map +1 -1
- package/dist/figma-api/fresh-read.d.ts +15 -0
- package/dist/figma-api/fresh-read.d.ts.map +1 -0
- package/dist/figma-api/fresh-read.js +54 -0
- package/dist/figma-api/fresh-read.js.map +1 -0
- package/dist/figma-api/graph-ref.d.ts +9 -0
- package/dist/figma-api/graph-ref.d.ts.map +1 -0
- package/dist/figma-api/graph-ref.js +14 -0
- package/dist/figma-api/graph-ref.js.map +1 -0
- package/dist/figma-api/index.d.ts +6 -1
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +12 -5
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/pending-layout.d.ts +3 -3
- package/dist/figma-api/pending-layout.d.ts.map +1 -1
- package/dist/figma-api/pending-layout.js +7 -3
- package/dist/figma-api/pending-layout.js.map +1 -1
- package/dist/figma-api/pending-sync.d.ts +1 -1
- package/dist/figma-api/pending-sync.d.ts.map +1 -1
- package/dist/figma-api/pending-sync.js +3 -1
- package/dist/figma-api/pending-sync.js.map +1 -1
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +3 -2
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +20 -4
- package/dist/figma-api/reactions.d.ts.map +1 -1
- package/dist/figma-api/reactions.js +49 -3
- package/dist/figma-api/reactions.js.map +1 -1
- package/dist/figma-api/variables/index.d.ts.map +1 -1
- package/dist/figma-api/variables/index.js +2 -2
- package/dist/figma-api/variables/index.js.map +1 -1
- package/dist/io/formats/design-tokens/css/known.js +1 -1
- package/dist/io/formats/design-tokens/css/known.js.map +1 -1
- package/dist/io/formats/design-tokens/css/read.d.ts +3 -1
- package/dist/io/formats/design-tokens/css/read.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/css/read.js +11 -5
- package/dist/io/formats/design-tokens/css/read.js.map +1 -1
- package/dist/io/formats/design-tokens/css/sync.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/css/sync.js +17 -4
- package/dist/io/formats/design-tokens/css/sync.js.map +1 -1
- package/dist/io/formats/design-tokens/css/values.d.ts +6 -5
- package/dist/io/formats/design-tokens/css/values.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/css/values.js +24 -8
- package/dist/io/formats/design-tokens/css/values.js.map +1 -1
- package/dist/io/formats/design-tokens/decode.d.ts +7 -6
- package/dist/io/formats/design-tokens/decode.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/decode.js +13 -12
- package/dist/io/formats/design-tokens/decode.js.map +1 -1
- package/dist/io/formats/design-tokens/export.js +3 -3
- package/dist/io/formats/design-tokens/export.js.map +1 -1
- package/dist/io/formats/design-tokens/plan/index.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/index.js +4 -3
- package/dist/io/formats/design-tokens/plan/index.js.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.js +9 -9
- package/dist/io/formats/design-tokens/plan/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/styles.d.ts +4 -4
- package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/styles.js +7 -7
- package/dist/io/formats/design-tokens/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/sync/drift.js +2 -2
- package/dist/io/formats/design-tokens/sync/drift.js.map +1 -1
- package/dist/io/formats/design-tokens/values.d.ts +10 -5
- package/dist/io/formats/design-tokens/values.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/values.js +13 -7
- package/dist/io/formats/design-tokens/values.js.map +1 -1
- package/dist/io/formats/drawio/label.js +1 -1
- package/dist/io/formats/drawio/paint.js +1 -1
- package/dist/io/formats/drawio/warnings.js +2 -2
- package/dist/io/formats/drawio/warnings.js.map +1 -1
- package/dist/io/formats/fig/export/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/index.js +15 -3
- package/dist/io/formats/fig/export/index.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 +2 -1
- package/dist/io/formats/fig/export/patch/index.js.map +1 -1
- package/dist/io/formats/fig/export/setup.d.ts +7 -2
- package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
- package/dist/io/formats/fig/export/setup.js +12 -13
- package/dist/io/formats/fig/export/setup.js.map +1 -1
- package/dist/io/formats/fig/export/variables.d.ts.map +1 -1
- package/dist/io/formats/fig/export/variables.js +9 -7
- package/dist/io/formats/fig/export/variables.js.map +1 -1
- package/dist/io/formats/html/vectors.js +1 -0
- package/dist/io/formats/html/vectors.js.map +1 -1
- package/dist/io/formats/mermaid/layers.js +2 -2
- package/dist/io/formats/mermaid/layers.js.map +1 -1
- package/dist/io/formats/mermaid/styles.js +1 -1
- package/dist/io/formats/pdf/export.d.ts.map +1 -1
- package/dist/io/formats/pdf/export.js +1 -0
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/pdf/prepare.d.ts +4 -4
- package/dist/io/formats/pdf/prepare.d.ts.map +1 -1
- package/dist/io/formats/pdf/prepare.js +2 -2
- package/dist/io/formats/pdf/prepare.js.map +1 -1
- package/dist/io/formats/pen/index.js +4 -2
- package/dist/io/formats/pen/index.js.map +1 -1
- package/dist/io/formats/pptx/style.js +1 -1
- package/dist/io/formats/raster/render.d.ts +1 -1
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +9 -4
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts +6 -3
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +12 -11
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/effects.js +2 -2
- package/dist/io/formats/svg/effects.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 +4 -2
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/filter.d.ts +4 -1
- package/dist/io/formats/svg/filter.d.ts.map +1 -1
- package/dist/io/formats/svg/filter.js +6 -2
- package/dist/io/formats/svg/filter.js.map +1 -1
- package/dist/io/formats/svg/grain.js +1 -1
- package/dist/io/formats/svg/grain.js.map +1 -1
- package/dist/io/formats/svg/import.d.ts +4 -2
- package/dist/io/formats/svg/import.d.ts.map +1 -1
- package/dist/io/formats/svg/import.js +2 -1
- package/dist/io/formats/svg/import.js.map +1 -1
- package/dist/io/formats/svg/text/export.d.ts.map +1 -1
- package/dist/io/formats/svg/text/export.js +8 -8
- package/dist/io/formats/svg/text/export.js.map +1 -1
- package/dist/io/formats/svg/text/layout.js +2 -2
- package/dist/io/formats/svg/text/layout.js.map +1 -1
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +1 -0
- package/dist/io/formats.js.map +1 -1
- package/dist/io/subgraph.d.ts.map +1 -1
- package/dist/io/subgraph.js +1 -1
- package/dist/io/subgraph.js.map +1 -1
- package/dist/io/types.d.ts +1 -1
- package/dist/kiwi/fig/session/options.d.ts +3 -0
- package/dist/kiwi/fig/session/options.d.ts.map +1 -1
- package/dist/kiwi/fig/session/options.js +4 -0
- package/dist/kiwi/fig/session/options.js.map +1 -1
- package/dist/layout/yoga-helpers.d.ts +2 -1
- package/dist/layout/yoga-helpers.d.ts.map +1 -1
- package/dist/layout/yoga-helpers.js +7 -1
- package/dist/layout/yoga-helpers.js.map +1 -1
- package/dist/layout.js +24 -1
- package/dist/layout.js.map +1 -1
- package/dist/lint/fixes.js +1 -1
- package/dist/lint/linter.js +2 -2
- package/dist/lint/linter.js.map +1 -1
- package/dist/pairdraw-api/comments.d.ts +4 -1
- package/dist/pairdraw-api/comments.d.ts.map +1 -1
- package/dist/pairdraw-api/comments.js +5 -0
- package/dist/pairdraw-api/comments.js.map +1 -1
- package/dist/pairdraw-api/index.d.ts +3 -3
- package/dist/pairdraw-api/index.d.ts.map +1 -1
- package/dist/pairdraw-api/index.js +5 -5
- package/dist/pairdraw-api/index.js.map +1 -1
- package/dist/pairdraw-api/nodes.d.ts +1 -1
- package/dist/prototype/scene.js +1 -1
- package/dist/rpc/analyze-commands.js +1 -1
- package/dist/rpc/read-commands.d.ts +2 -2
- package/dist/rpc/read-commands.js +3 -3
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/rpc/variables-command.js +2 -2
- package/dist/rpc/variables-command.js.map +1 -1
- package/dist/text/font/provider.d.ts +15 -0
- package/dist/text/font/provider.d.ts.map +1 -0
- package/dist/text/font/provider.js +18 -0
- package/dist/text/font/provider.js.map +1 -0
- package/dist/text/font/readiness.d.ts +32 -0
- package/dist/text/font/readiness.d.ts.map +1 -0
- package/dist/text/font/{status.js → readiness.js} +8 -4
- package/dist/text/font/readiness.js.map +1 -0
- package/dist/text/index.d.ts +4 -3
- package/dist/text/index.js +4 -3
- package/dist/text/prepare.d.ts +9 -4
- package/dist/text/prepare.d.ts.map +1 -1
- package/dist/text/prepare.js +9 -4
- package/dist/text/prepare.js.map +1 -1
- package/dist/tools/analyze/colors.js +1 -1
- package/dist/tools/analyze/responsive/index.js +7 -18
- package/dist/tools/analyze/responsive/index.js.map +1 -1
- package/dist/tools/analyze/responsive/widths.d.ts +27 -0
- package/dist/tools/analyze/responsive/widths.d.ts.map +1 -0
- package/dist/tools/analyze/responsive/widths.js +49 -0
- package/dist/tools/analyze/responsive/widths.js.map +1 -0
- package/dist/tools/analyze.d.ts +2 -1
- package/dist/tools/analyze.js +2 -1
- package/dist/tools/codegen/tokens.d.ts.map +1 -1
- package/dist/tools/codegen/tokens.js +2 -2
- package/dist/tools/codegen/tokens.js.map +1 -1
- package/dist/tools/comments.d.ts.map +1 -1
- package/dist/tools/comments.js +2 -2
- package/dist/tools/comments.js.map +1 -1
- package/dist/tools/component-catalog.d.ts.map +1 -1
- package/dist/tools/component-catalog.js +5 -3
- package/dist/tools/component-catalog.js.map +1 -1
- package/dist/tools/create/basic.js +1 -1
- package/dist/tools/create/behaviours.js +1 -1
- package/dist/tools/create/html.d.ts.map +1 -1
- package/dist/tools/create/html.js +1 -3
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.js +2 -2
- package/dist/tools/create/icons.js.map +1 -1
- package/dist/tools/create/mermaid.js +1 -1
- package/dist/tools/create/render.js +1 -1
- package/dist/tools/create/svg.js +5 -2
- package/dist/tools/create/svg.js.map +1 -1
- package/dist/tools/create/vector.js +3 -3
- package/dist/tools/create/vector.js.map +1 -1
- package/dist/tools/css/shorthand.d.ts +20 -0
- package/dist/tools/css/shorthand.d.ts.map +1 -0
- package/dist/tools/css/shorthand.js +54 -0
- package/dist/tools/css/shorthand.js.map +1 -0
- package/dist/tools/describe/index.js +2 -2
- package/dist/tools/describe/index.js.map +1 -1
- package/dist/tools/describe/issues.js +1 -1
- package/dist/tools/html-host.d.ts.map +1 -1
- package/dist/tools/html-host.js +5 -3
- package/dist/tools/html-host.js.map +1 -1
- package/dist/tools/image-ai/apply.d.ts.map +1 -1
- package/dist/tools/image-ai/apply.js +1 -3
- package/dist/tools/image-ai/apply.js.map +1 -1
- package/dist/tools/image-ai/generate.js +1 -1
- package/dist/tools/image-ai/service.d.ts.map +1 -1
- package/dist/tools/image-ai/service.js +5 -3
- package/dist/tools/image-ai/service.js.map +1 -1
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.js +2 -1
- package/dist/tools/modify/effects.js +1 -1
- package/dist/tools/modify/effects.js.map +1 -1
- package/dist/tools/modify/geometry.d.ts.map +1 -1
- package/dist/tools/modify/geometry.js +14 -3
- 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 +35 -8
- package/dist/tools/modify/layout.js.map +1 -1
- package/dist/tools/modify/matching.d.ts.map +1 -1
- package/dist/tools/modify/matching.js +10 -10
- package/dist/tools/modify/matching.js.map +1 -1
- package/dist/tools/modify/paint.d.ts.map +1 -1
- package/dist/tools/modify/paint.js +57 -5
- package/dist/tools/modify/paint.js.map +1 -1
- package/dist/tools/modify/reactions.d.ts.map +1 -1
- package/dist/tools/modify/reactions.js +2 -2
- package/dist/tools/modify/reactions.js.map +1 -1
- package/dist/tools/modify/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +3 -3
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/prompts/codegen.js +1 -1
- package/dist/tools/prompts/codegen.js.map +1 -1
- package/dist/tools/read/css.d.ts +14 -0
- package/dist/tools/read/css.d.ts.map +1 -0
- package/dist/tools/read/css.js +306 -0
- package/dist/tools/read/css.js.map +1 -0
- package/dist/tools/read/libraries.js +1 -1
- package/dist/tools/read/reactions.js +1 -1
- package/dist/tools/read/reactions.js.map +1 -1
- package/dist/tools/read/space.d.ts.map +1 -1
- package/dist/tools/read/space.js +0 -2
- package/dist/tools/read/space.js.map +1 -1
- package/dist/tools/read.d.ts +2 -1
- package/dist/tools/read.js +2 -1
- package/dist/tools/registry/core.d.ts +1 -1
- package/dist/tools/registry/core.js +3 -1
- package/dist/tools/registry/core.js.map +1 -1
- package/dist/tools/schema.d.ts +6 -4
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +9 -5
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/script/host.d.ts.map +1 -1
- package/dist/tools/script/host.js +5 -3
- package/dist/tools/script/host.js.map +1 -1
- package/dist/tools/variables/collections.js +1 -1
- package/dist/tools/variables/collections.js.map +1 -1
- package/dist/tools/variables/values.d.ts.map +1 -1
- package/dist/tools/variables/values.js +4 -4
- package/dist/tools/variables/values.js.map +1 -1
- package/dist/tools/vector/vectorize.d.ts.map +1 -1
- package/dist/tools/vector/vectorize.js +6 -4
- package/dist/tools/vector/vectorize.js.map +1 -1
- package/dist/tools/video-host.d.ts.map +1 -1
- package/dist/tools/video-host.js +5 -3
- package/dist/tools/video-host.js.map +1 -1
- package/dist/vector/vectorize/svg/gradients.d.ts +2 -2
- package/dist/vector/vectorize/svg/gradients.d.ts.map +1 -1
- package/dist/vector/vectorize/svg/gradients.js +5 -5
- package/dist/vector/vectorize/svg/gradients.js.map +1 -1
- package/dist/vector/vectorize/svg/to-vectors.d.ts +3 -1
- package/dist/vector/vectorize/svg/to-vectors.d.ts.map +1 -1
- package/dist/vector/vectorize/svg/to-vectors.js +13 -12
- package/dist/vector/vectorize/svg/to-vectors.js.map +1 -1
- package/package.json +9 -9
- package/src/canvas/noise/render.ts +1 -1
- package/src/canvas/noise/shader.ts +13 -5
- package/src/canvas/noise/tile.ts +2 -1
- package/src/canvas/renderer/colors.ts +76 -50
- package/src/canvas/renderer/document-surface.ts +53 -0
- package/src/canvas/renderer/fonts.ts +6 -4
- package/src/canvas/renderer/lifecycle.ts +4 -4
- package/src/canvas/renderer/methods.ts +1 -0
- package/src/canvas/renderer/pipeline.ts +21 -3
- package/src/canvas/renderer/retained-backing.ts +2 -1
- package/src/canvas/renderer/tiles/surface-pool.ts +9 -7
- package/src/canvas/renderer.ts +36 -11
- package/src/canvas/scene.ts +4 -3
- package/src/canvas/shaders/effect.ts +2 -1
- package/src/canvas/shadows/shape.ts +4 -2
- package/src/canvas/shadows.ts +5 -2
- package/src/canvas/text/decorations.ts +15 -5
- package/src/canvas/text/index.ts +9 -1
- package/src/canvas/text/paragraph/index.ts +16 -6
- package/src/canvas/text/renderer.ts +2 -1
- package/src/canvas/text/shape.ts +4 -4
- package/src/canvas/texture.ts +2 -1
- package/src/editor/clipboard/assets.ts +6 -2
- package/src/editor/clipboard/component-matches.ts +65 -0
- package/src/editor/clipboard/dependencies.ts +22 -1
- package/src/editor/clipboard.ts +74 -20
- package/src/editor/components/properties.ts +3 -2
- package/src/editor/eyedropper.ts +14 -4
- package/src/editor/history/atomic-tool.ts +3 -2
- package/src/editor/structure/state.ts +2 -1
- package/src/editor/text.ts +2 -1
- package/src/editor/variables.ts +3 -3
- package/src/figma-api/fresh-read.ts +57 -0
- package/src/figma-api/graph-ref.ts +13 -0
- package/src/figma-api/index.ts +12 -4
- package/src/figma-api/pending-layout.ts +7 -3
- package/src/figma-api/pending-sync.ts +4 -1
- package/src/figma-api/proxy.ts +2 -1
- package/src/figma-api/reactions.ts +91 -10
- package/src/figma-api/variables/index.ts +5 -4
- package/src/io/formats/design-tokens/css/known.ts +1 -1
- package/src/io/formats/design-tokens/css/read.ts +20 -7
- package/src/io/formats/design-tokens/css/sync.ts +9 -4
- package/src/io/formats/design-tokens/css/values.ts +37 -9
- package/src/io/formats/design-tokens/decode.ts +17 -12
- package/src/io/formats/design-tokens/export.ts +3 -3
- package/src/io/formats/design-tokens/plan/index.ts +6 -5
- package/src/io/formats/design-tokens/plan/styles.ts +37 -10
- package/src/io/formats/design-tokens/styles.ts +10 -7
- package/src/io/formats/design-tokens/sync/drift.ts +6 -4
- package/src/io/formats/design-tokens/values.ts +15 -8
- package/src/io/formats/drawio/warnings.ts +2 -2
- package/src/io/formats/fig/export/index.ts +36 -3
- package/src/io/formats/fig/export/patch/index.ts +4 -1
- package/src/io/formats/fig/export/setup.ts +25 -15
- package/src/io/formats/fig/export/variables.ts +17 -6
- package/src/io/formats/html/vectors.ts +1 -0
- package/src/io/formats/mermaid/layers.ts +2 -2
- package/src/io/formats/pdf/export.ts +1 -0
- package/src/io/formats/pdf/prepare.ts +6 -6
- package/src/io/formats/pen/index.ts +5 -2
- package/src/io/formats/raster/render.ts +12 -4
- package/src/io/formats/svg/defs.ts +26 -14
- package/src/io/formats/svg/effects.ts +2 -2
- package/src/io/formats/svg/export.ts +17 -3
- package/src/io/formats/svg/filter.ts +12 -2
- package/src/io/formats/svg/grain.ts +1 -1
- package/src/io/formats/svg/import.ts +6 -3
- package/src/io/formats/svg/text/export.ts +10 -8
- package/src/io/formats/svg/text/layout.ts +2 -2
- package/src/io/formats.ts +8 -1
- package/src/io/subgraph.ts +4 -1
- package/src/kiwi/fig/session/options.ts +4 -1
- package/src/layout/yoga-helpers.ts +8 -0
- package/src/layout.ts +47 -1
- package/src/lint/linter.ts +1 -1
- package/src/pairdraw-api/comments.ts +6 -0
- package/src/pairdraw-api/index.ts +7 -9
- package/src/rpc/read-commands.ts +4 -4
- package/src/rpc/variables-command.ts +2 -2
- package/src/text/font/provider.ts +26 -0
- package/src/text/font/{status.ts → readiness.ts} +13 -9
- package/src/text/index.ts +2 -1
- package/src/text/prepare.ts +9 -4
- package/src/tools/analyze/responsive/index.ts +8 -15
- package/src/tools/analyze/responsive/widths.ts +63 -0
- package/src/tools/analyze.ts +2 -0
- package/src/tools/codegen/tokens.ts +4 -2
- package/src/tools/comments.ts +6 -4
- package/src/tools/component-catalog.ts +5 -3
- package/src/tools/create/html.ts +0 -3
- package/src/tools/create/icons.ts +1 -1
- package/src/tools/create/svg.ts +4 -1
- package/src/tools/create/vector.ts +2 -2
- package/src/tools/css/shorthand.ts +64 -0
- package/src/tools/describe/index.ts +2 -8
- package/src/tools/html-host.ts +5 -3
- package/src/tools/image-ai/apply.ts +0 -2
- package/src/tools/image-ai/service.ts +5 -3
- package/src/tools/index.ts +2 -0
- package/src/tools/modify/effects.ts +1 -1
- package/src/tools/modify/geometry.ts +16 -3
- package/src/tools/modify/layout.ts +47 -13
- package/src/tools/modify/matching.ts +14 -11
- package/src/tools/modify/paint.ts +85 -5
- package/src/tools/modify/reactions.ts +3 -2
- package/src/tools/modify/text.ts +15 -11
- package/src/tools/prompts/codegen.md +2 -1
- package/src/tools/read/css.ts +365 -0
- package/src/tools/read/reactions.ts +3 -2
- package/src/tools/read/space.ts +0 -2
- package/src/tools/read.ts +1 -0
- package/src/tools/registry/core.ts +3 -2
- package/src/tools/schema.ts +14 -5
- package/src/tools/script/host.ts +6 -3
- package/src/tools/variables/collections.ts +1 -1
- package/src/tools/variables/values.ts +16 -5
- package/src/tools/vector/vectorize.ts +10 -4
- package/src/tools/video-host.ts +5 -3
- package/src/vector/vectorize/svg/gradients.ts +8 -5
- package/src/vector/vectorize/svg/to-vectors.ts +48 -14
- package/dist/text/font/status.d.ts +0 -28
- package/dist/text/font/status.d.ts.map +0 -1
- package/dist/text/font/status.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.js","names":[],"sources":["../../../../src/io/formats/svg/export.ts"],"sourcesContent":["import 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 type { SceneGraph, SceneNode, Fill, Stroke, VectorNetwork } from '@pairdraw/scene-graph'\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)\n : (resolveFill(stroke, node, ctx) ?? formatSolidColor(stroke.color, 1, ctx.colorSpace)),\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 /**\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 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 tint,\n booleanPath\n }: Pick<SVGExportContext, 'tint' | 'booleanPath'> & {\n idPrefix: string\n colorSpace?: RenderColorSpace\n }\n): SVGNode | null {\n const ctx: SVGExportContext = {\n defs: [],\n defIdCounter: 0,\n graph,\n colorSpace,\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":";;;;;;;;;;;;;;;;;AAkDA,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,MAA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\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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ACA,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,12 +1,13 @@
|
|
|
1
1
|
import { SVGNode } from "./node.js";
|
|
2
2
|
import { SVGExportContext } from "./defs.js";
|
|
3
|
+
import { ColorProfile } from "@pairdraw/scene-graph";
|
|
3
4
|
import { Color } from "@pairdraw/scene-graph/primitives";
|
|
4
5
|
//#region src/io/formats/svg/filter.d.ts
|
|
5
6
|
/**
|
|
6
7
|
* A flood's colour, opaque: its alpha goes in `flood-opacity`, which a Display P3 colour would
|
|
7
8
|
* otherwise carry a second time.
|
|
8
9
|
*/
|
|
9
|
-
declare function floodColor(color: Color, colorSpace: SVGExportContext['colorSpace']): string;
|
|
10
|
+
declare function floodColor(color: Color, colorSpace: SVGExportContext['colorSpace'], documentColorSpace?: ColorProfile): string;
|
|
10
11
|
/** An SVG filter's primitives as they are added, each naming its result uniquely. */
|
|
11
12
|
declare class FilterBuilder {
|
|
12
13
|
private readonly id;
|
|
@@ -18,6 +19,8 @@ declare class FilterBuilder {
|
|
|
18
19
|
pushElement(tag: string, attrs: Record<string, string | number | undefined>, children: SVGNode[]): void;
|
|
19
20
|
/** The colour space the export writes colours in. */
|
|
20
21
|
get colorSpace(): SVGExportContext['colorSpace'];
|
|
22
|
+
/** The document's profile, where its stored colors are. */
|
|
23
|
+
get documentColorSpace(): ColorProfile;
|
|
21
24
|
/** A new result name, unique in this filter. */
|
|
22
25
|
result(name: string): string;
|
|
23
26
|
push(tag: string, attrs: Record<string, string | number | undefined>, ...children: SVGNode[]): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.d.ts","names":[],"sources":["../../../../src/io/formats/svg/filter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"filter.d.ts","names":[],"sources":["../../../../src/io/formats/svg/filter.ts"],"mappings":";;;;;;;;;iBAUgB,WACd,OAAO,OACP,YAAY,gCACZ,qBAAoB;;cAMT;mBAKQ;mBACA;WALV,YAAY;UACb;EAGW,YAAA,YACA,KAAK;;EAIxB,YACE,aACA,OAAO,6CACP,UAAU;;MAMR,cAAc;;MAKd,sBAAsB;;EAK1B,OAAO;EAKP,KAAK,aAAa,OAAO,gDAAgD,UAAU"}
|
|
@@ -5,11 +5,11 @@ import { formatColor } from "./defs.js";
|
|
|
5
5
|
* A flood's colour, opaque: its alpha goes in `flood-opacity`, which a Display P3 colour would
|
|
6
6
|
* otherwise carry a second time.
|
|
7
7
|
*/
|
|
8
|
-
function floodColor(color, colorSpace) {
|
|
8
|
+
function floodColor(color, colorSpace, documentColorSpace = "srgb") {
|
|
9
9
|
return formatColor({
|
|
10
10
|
...color,
|
|
11
11
|
a: 1
|
|
12
|
-
}, 1, colorSpace);
|
|
12
|
+
}, 1, colorSpace, documentColorSpace);
|
|
13
13
|
}
|
|
14
14
|
/** An SVG filter's primitives as they are added, each naming its result uniquely. */
|
|
15
15
|
var FilterBuilder = class {
|
|
@@ -29,6 +29,10 @@ var FilterBuilder = class {
|
|
|
29
29
|
get colorSpace() {
|
|
30
30
|
return this.ctx.colorSpace;
|
|
31
31
|
}
|
|
32
|
+
/** The document's profile, where its stored colors are. */
|
|
33
|
+
get documentColorSpace() {
|
|
34
|
+
return this.ctx.documentColorSpace;
|
|
35
|
+
}
|
|
32
36
|
/** A new result name, unique in this filter. */
|
|
33
37
|
result(name) {
|
|
34
38
|
this.count += 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","names":[],"sources":["../../../../src/io/formats/svg/filter.ts"],"sourcesContent":["import type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport { formatColor, type SVGExportContext } from './defs'\nimport { svg, type SVGNode } from './node'\n\n/**\n * A flood's colour, opaque: its alpha goes in `flood-opacity`, which a Display P3 colour would\n * otherwise carry a second time.\n */\nexport function floodColor(color: Color
|
|
1
|
+
{"version":3,"file":"filter.js","names":[],"sources":["../../../../src/io/formats/svg/filter.ts"],"sourcesContent":["import type { ColorProfile } from '@pairdraw/scene-graph'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport { formatColor, type SVGExportContext } from './defs'\nimport { svg, type SVGNode } from './node'\n\n/**\n * A flood's colour, opaque: its alpha goes in `flood-opacity`, which a Display P3 colour would\n * otherwise carry a second time.\n */\nexport function floodColor(\n color: Color,\n colorSpace: SVGExportContext['colorSpace'],\n documentColorSpace: ColorProfile = 'srgb'\n): string {\n return formatColor({ ...color, a: 1 }, 1, colorSpace, documentColorSpace)\n}\n\n/** An SVG filter's primitives as they are added, each naming its result uniquely. */\nexport class FilterBuilder {\n readonly primitives: SVGNode[] = []\n private count = 0\n\n constructor(\n private readonly id: string,\n private readonly ctx: SVGExportContext\n ) {}\n\n /** A primitive with as many children as `children` holds. */\n pushElement(\n tag: string,\n attrs: Record<string, string | number | undefined>,\n children: SVGNode[]\n ) {\n this.primitives.push(svg(tag, attrs, ...children))\n }\n\n /** The colour space the export writes colours in. */\n get colorSpace(): SVGExportContext['colorSpace'] {\n return this.ctx.colorSpace\n }\n\n /** The document's profile, where its stored colors are. */\n get documentColorSpace(): ColorProfile {\n return this.ctx.documentColorSpace\n }\n\n /** A new result name, unique in this filter. */\n result(name: string): string {\n this.count += 1\n return `${this.id}_${name}${this.count}`\n }\n\n push(tag: string, attrs: Record<string, string | number | undefined>, ...children: SVGNode[]) {\n this.primitives.push(svg(tag, attrs, ...children))\n }\n}\n"],"mappings":";;;;;;;AAUA,SAAgB,WACd,OACA,YACA,qBAAmC,QAC3B;CACR,OAAO,YAAY;EAAE,GAAG;EAAO,GAAG;CAAE,GAAG,GAAG,YAAY,kBAAkB;AAC1E;;AAGA,IAAa,gBAAb,MAA2B;CAKN;CACA;CALnB,aAAiC,CAAC;CAClC,QAAgB;CAEhB,YACE,IACA,KACA;EAFiB,KAAA,KAAA;EACA,KAAA,MAAA;CAChB;;CAGH,YACE,KACA,OACA,UACA;EACA,KAAK,WAAW,KAAK,IAAI,KAAK,OAAO,GAAG,QAAQ,CAAC;CACnD;;CAGA,IAAI,aAA6C;EAC/C,OAAO,KAAK,IAAI;CAClB;;CAGA,IAAI,qBAAmC;EACrC,OAAO,KAAK,IAAI;CAClB;;CAGA,OAAO,MAAsB;EAC3B,KAAK,SAAS;EACd,OAAO,GAAG,KAAK,GAAG,GAAG,OAAO,KAAK;CACnC;CAEA,KAAK,KAAa,OAAoD,GAAG,UAAqB;EAC5F,KAAK,WAAW,KAAK,IAAI,KAAK,OAAO,GAAG,QAAQ,CAAC;CACnD;AACF"}
|
|
@@ -110,7 +110,7 @@ function noiseFilter(filter, effect, input) {
|
|
|
110
110
|
});
|
|
111
111
|
const flood = filter.result("noiseFlood");
|
|
112
112
|
filter.push("feFlood", {
|
|
113
|
-
"flood-color": floodColor(color, filter.colorSpace),
|
|
113
|
+
"flood-color": floodColor(color, filter.colorSpace, filter.documentColorSpace),
|
|
114
114
|
"flood-opacity": round(color.a),
|
|
115
115
|
result: flood
|
|
116
116
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grain.js","names":[],"sources":["../../../../src/io/formats/svg/grain.ts"],"sourcesContent":["import type { NoiseEffect, TextureEffect } from '@pairdraw/scene-graph'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { floodColor, type FilterBuilder } from './filter'\nimport { svg } from './node'\nimport { round } from './paths'\n\n/** How many steps the discrete alpha table of a noise has, as Figma writes it. */\nconst NOISE_TABLE_STEPS = 100\n\n/** Keeps a channel's alpha alone, as each of Figma's grain matrices does somewhere. */\nconst ALPHA_ONLY = '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0'\nconst ALPHA_TO_RED = '0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1'\nconst ALPHA_TO_GREEN = '0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1'\nconst OPAQUE = '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 127 0'\nconst ALPHA_TO_RED_OPAQUE = '0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0'\nconst RED_TO_ALPHA = '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0'\n\n/** A grain size as `feTurbulence` frequency, one cycle per grain on each axis. */\nfunction grainFrequency(size: Vector): string {\n const frequency = (length: number) => (length > 0 ? round(1 / length, 4) : 0)\n return `${frequency(size.x)} ${frequency(size.y)}`\n}\n\n/**\n * The discrete alpha table that shows a noise's grains at `density`, as Figma's SVG export writes\n * it: a band of ones over the noise's middle tones, one step wide at no density and half the\n * steps at full. Figma works it out in 32-bit floats, as it stores the density.\n */\nexport function noiseDensityTable(density: number, mirrored = false): string {\n const stored = Math.fround(density)\n const start = Math.floor(25 - 25 * stored)\n const count = Math.floor(50 * stored) + 1\n const steps = Array.from({ length: NOISE_TABLE_STEPS }, (_, step) =>\n step >= start && step < start + count ? 1 : 0\n )\n return (mirrored ? steps.reverse() : steps).join(' ')\n}\n\n/**\n * A noise effect over `input` as Figma's SVG export draws it: fractal noise one grain to a\n * cycle, its middle tones shown in the effect's colour, a duotone's opposite tones in its\n * second colour, and a multitone's own colours at its opacity, all inside the layer. Returns the\n * result's name.\n */\nexport function noiseFilter(filter: FilterBuilder, effect: NoiseEffect, input: string): string {\n const grain = effect.noise\n const noise = filter.result('noise')\n filter.push('feTurbulence', {\n type: 'fractalNoise',\n baseFrequency: grainFrequency(grain.noiseSize),\n stitchTiles: 'stitch',\n numOctaves: 3,\n seed: grain.seed ?? 0,\n result: noise\n })\n const merged = filter.result('noiseMerge')\n if (grain.noiseType === 'MULTITONE') {\n const colored = filter.result('multitone')\n const linear = { type: 'linear', slope: 2, intercept: -0.5 }\n filter.push(\n 'feComponentTransfer',\n { in: noise, result: colored },\n svg('feFuncR', linear),\n svg('feFuncG', linear),\n svg('feFuncB', linear),\n svg('feFuncA', { type: 'discrete', tableValues: noiseDensityTable(grain.density) })\n )\n const clipped = filter.result('noiseClipped')\n filter.push('feComposite', { in: colored, in2: input, operator: 'in', result: clipped })\n const faded = filter.result('noiseColor')\n filter.push(\n 'feComponentTransfer',\n { in: clipped, result: faded },\n svg('feFuncA', { type: 'table', tableValues: `0 ${round(grain.opacity ?? 1)}` })\n )\n filter.pushElement('feMerge', { result: merged }, mergeNodes([input, faded]))\n return merged\n }\n\n const alpha = filter.result('alphaNoise')\n filter.push('feColorMatrix', { in: noise, type: 'luminanceToAlpha', result: alpha })\n const tones = [{ color: effect.color, mirrored: false }]\n if (grain.noiseType === 'DUOTONE') {\n tones.push({ color: grain.secondaryColor ?? effect.color, mirrored: true })\n }\n const colors = tones.map(({ color, mirrored }) => {\n const band = filter.result('noiseBand')\n filter.push(\n 'feComponentTransfer',\n { in: alpha, result: band },\n svg('feFuncA', { type: 'discrete', tableValues: noiseDensityTable(grain.density, mirrored) })\n )\n const clipped = filter.result('noiseClipped')\n filter.push('feComposite', { in: band, in2: input, operator: 'in', result: clipped })\n const flood = filter.result('noiseFlood')\n filter.push('feFlood', {\n 'flood-color': floodColor(color, filter.colorSpace),\n 'flood-opacity': round(color.a),\n result: flood\n })\n const colored = filter.result('noiseColor')\n filter.push('feComposite', { in: flood, in2: clipped, operator: 'in', result: colored })\n return colored\n })\n filter.pushElement('feMerge', { result: merged }, mergeNodes([input, ...colors]))\n return merged\n}\n\nfunction mergeNodes(inputs: readonly string[]) {\n return inputs.map((input) => svg('feMergeNode', { in: input }))\n}\n\n/**\n * A texture effect over `input` as Figma's SVG export draws it: the layer displaced by fractal\n * noise one grain to a cycle, twice the radius at most. Without clipping that is all; clipped to\n * its shape, Figma's chain moves only the layer's inside and keeps it within its own outline.\n * Returns the result's name.\n */\nexport function textureFilter(filter: FilterBuilder, effect: TextureEffect, input: string): string {\n const grain = effect.texture\n const frequency = grainFrequency(grain.noiseSize)\n const scale = round(effect.radius * 2)\n const name = (label: string) => filter.result(label)\n const displace = (into: string, by: string, result: string) =>\n filter.push('feDisplacementMap', {\n in: into,\n in2: by,\n scale,\n xChannelSelector: 'R',\n yChannelSelector: 'G',\n width: '100%',\n height: '100%',\n result\n })\n const turbulence = (seed: number, result: string) =>\n filter.push('feTurbulence', {\n type: 'fractalNoise',\n baseFrequency: frequency,\n numOctaves: 3,\n seed: (grain.seed ?? 0) + seed,\n result\n })\n const matrix = (into: string, values: string, result: string) =>\n filter.push('feColorMatrix', { in: into, type: 'matrix', values, result })\n const arithmetic = (\n into: string,\n by: string,\n k: [number, number, number, number],\n result: string\n ) =>\n filter.push('feComposite', {\n in: into,\n in2: by,\n operator: 'arithmetic',\n k1: k[0],\n k2: k[1],\n k3: k[2],\n k4: k[3],\n result\n })\n const composite = (into: string, by: string, operator: string, result: string) =>\n filter.push('feComposite', { in: into, in2: by, operator, result })\n const gamma = (into: string, result: string) =>\n filter.push(\n 'feComponentTransfer',\n { in: into, result },\n svg('feFuncA', { type: 'gamma', exponent: 0.2 })\n )\n\n if (!grain.clipToShape) {\n const noise = name('textureNoise')\n turbulence(0, noise)\n const displaced = name('texture')\n displace(input, noise, displaced)\n return displaced\n }\n\n const noiseX = name('displacementX')\n const noiseY = name('displacementY')\n turbulence(0, noiseX)\n turbulence(1, noiseY)\n const xRed = name('displacementXRed')\n matrix(noiseX, ALPHA_TO_RED, xRed)\n const yGreen = name('displacementYGreen')\n matrix(noiseY, ALPHA_TO_GREEN, yGreen)\n const xy = name('displacementXY')\n arithmetic(xRed, yGreen, [0, 1, 1, 0], xy)\n const firstPass = name('firstPass')\n displace(input, xy, firstPass)\n const firstAlpha = name('firstPassAlpha')\n matrix(firstPass, ALPHA_ONLY, firstAlpha)\n const displacedAlpha = name('sourceDisplacedAlpha')\n gamma(firstAlpha, displacedAlpha)\n const inputAlphaOnly = name('inputAlphaOnly')\n matrix(input, ALPHA_ONLY, inputAlphaOnly)\n const inputAlpha = name('inputSourceAlpha')\n gamma(inputAlphaOnly, inputAlpha)\n const alphas = name('displacementAlphasMultiplied')\n arithmetic(displacedAlpha, inputAlpha, [1, 0, 0, 0], alphas)\n const centering = name('centeringAdjustment')\n arithmetic(alphas, alphas, [0, 0, -0.5, 0.5], centering)\n\n const finalChannel = (noise: string, values: string, label: string) => {\n const weighted = name(`${label}Weighted`)\n arithmetic(noise, alphas, [1, 0, 0, 0], weighted)\n const centered = name(`${label}Centered`)\n arithmetic(centering, weighted, [0, 1, 1, 0], centered)\n const final = name(`${label}Final`)\n matrix(centered, values, final)\n return final\n }\n const xFinal = finalChannel(noiseX, ALPHA_TO_RED, 'displacementX')\n const yFinal = finalChannel(noiseY, ALPHA_TO_GREEN, 'displacementY')\n const combined = name('displacementCombined')\n arithmetic(xFinal, yFinal, [0, 1, 1, 0], combined)\n const map = name('displacementMap')\n composite(combined, alphas, 'in', map)\n const neutral = name('neutral')\n filter.push('feFlood', {\n 'flood-color': 'rgb(127, 127, 127)',\n 'flood-opacity': 1,\n result: neutral\n })\n const outside = name('neutralOutside')\n composite(neutral, alphas, 'out', outside)\n const mapWithBackground = name('displacementMapWithBg')\n composite(outside, map, 'over', mapWithBackground)\n\n const displaced = name('displacedImage')\n displace(input, mapWithBackground, displaced)\n const opaque = name('imageOpaque')\n matrix(input, OPAQUE, opaque)\n const displacedOpaque = name('displacedImageOpaque')\n displace(opaque, mapWithBackground, displacedOpaque)\n const displacedRed = name('displacedImageRed')\n matrix(displaced, ALPHA_TO_RED_OPAQUE, displacedRed)\n const inputRed = name('inputRed')\n matrix(input, ALPHA_TO_RED_OPAQUE, inputRed)\n const transparencyRed = name('transparencyRedMap')\n composite(displacedRed, inputRed, 'atop', transparencyRed)\n const transparency = name('transparencyAlphaMap')\n matrix(transparencyRed, RED_TO_ALPHA, transparency)\n const layered = name('textureLayered')\n composite(displacedOpaque, opaque, 'over', layered)\n const textured = name('texture')\n composite(layered, transparency, 'in', textured)\n return textured\n}\n"],"mappings":";;;;;AAQA,MAAM,oBAAoB;;AAG1B,MAAM,aAAa;AACnB,MAAM,eAAe;AACrB,MAAM,iBAAiB;AACvB,MAAM,SAAS;AACf,MAAM,sBAAsB;AAC5B,MAAM,eAAe;;AAGrB,SAAS,eAAe,MAAsB;CAC5C,MAAM,aAAa,WAAoB,SAAS,IAAI,MAAM,IAAI,QAAQ,CAAC,IAAI;CAC3E,OAAO,GAAG,UAAU,KAAK,CAAC,EAAE,GAAG,UAAU,KAAK,CAAC;AACjD;;;;;;AAOA,SAAgB,kBAAkB,SAAiB,WAAW,OAAe;CAC3E,MAAM,SAAS,KAAK,OAAO,OAAO;CAClC,MAAM,QAAQ,KAAK,MAAM,KAAK,KAAK,MAAM;CACzC,MAAM,QAAQ,KAAK,MAAM,KAAK,MAAM,IAAI;CACxC,MAAM,QAAQ,MAAM,KAAK,EAAE,QAAQ,kBAAkB,IAAI,GAAG,SAC1D,QAAQ,SAAS,OAAO,QAAQ,QAAQ,IAAI,CAC9C;CACA,QAAQ,WAAW,MAAM,QAAQ,IAAI,MAAA,CAAO,KAAK,GAAG;AACtD;;;;;;;AAQA,SAAgB,YAAY,QAAuB,QAAqB,OAAuB;CAC7F,MAAM,QAAQ,OAAO;CACrB,MAAM,QAAQ,OAAO,OAAO,OAAO;CACnC,OAAO,KAAK,gBAAgB;EAC1B,MAAM;EACN,eAAe,eAAe,MAAM,SAA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,SAAS,OAAO,mBAAmB,SAAS;CAC5C,MAAM,SAAS,KAAK,aAAa;CACjC,OAAO,OAAO,QAAQ,MAAM;CAC5B,MAAM,kBAAkB,KAAK,sBAAsB;CACnD,SAAS,QAAQ,mBAAmB,eAAe;CACnD,MAAM,eAAe,KAAK,mBAAmB;CAC7C,OAAO,WAAW,qBAAqB,YAAY;CACnD,MAAM,WAAW,KAAK,UAAU;CAChC,OAAO,OAAO,qBAAqB,QAAQ;CAC3C,MAAM,kBAAkB,KAAK,oBAAoB;CACjD,UAAU,cAAc,UAAU,QAAQ,eAAe;CACzD,MAAM,eAAe,KAAK,sBAAsB;CAChD,OAAO,iBAAiB,cAAc,YAAY;CAClD,MAAM,UAAU,KAAK,gBAAgB;CACrC,UAAU,iBAAiB,QAAQ,QAAQ,OAAO;CAClD,MAAM,WAAW,KAAK,SAAS;CAC/B,UAAU,SAAS,cAAc,MAAM,QAAQ;CAC/C,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"grain.js","names":[],"sources":["../../../../src/io/formats/svg/grain.ts"],"sourcesContent":["import type { NoiseEffect, TextureEffect } from '@pairdraw/scene-graph'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { floodColor, type FilterBuilder } from './filter'\nimport { svg } from './node'\nimport { round } from './paths'\n\n/** How many steps the discrete alpha table of a noise has, as Figma writes it. */\nconst NOISE_TABLE_STEPS = 100\n\n/** Keeps a channel's alpha alone, as each of Figma's grain matrices does somewhere. */\nconst ALPHA_ONLY = '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0'\nconst ALPHA_TO_RED = '0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1'\nconst ALPHA_TO_GREEN = '0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1'\nconst OPAQUE = '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 127 0'\nconst ALPHA_TO_RED_OPAQUE = '0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0'\nconst RED_TO_ALPHA = '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0'\n\n/** A grain size as `feTurbulence` frequency, one cycle per grain on each axis. */\nfunction grainFrequency(size: Vector): string {\n const frequency = (length: number) => (length > 0 ? round(1 / length, 4) : 0)\n return `${frequency(size.x)} ${frequency(size.y)}`\n}\n\n/**\n * The discrete alpha table that shows a noise's grains at `density`, as Figma's SVG export writes\n * it: a band of ones over the noise's middle tones, one step wide at no density and half the\n * steps at full. Figma works it out in 32-bit floats, as it stores the density.\n */\nexport function noiseDensityTable(density: number, mirrored = false): string {\n const stored = Math.fround(density)\n const start = Math.floor(25 - 25 * stored)\n const count = Math.floor(50 * stored) + 1\n const steps = Array.from({ length: NOISE_TABLE_STEPS }, (_, step) =>\n step >= start && step < start + count ? 1 : 0\n )\n return (mirrored ? steps.reverse() : steps).join(' ')\n}\n\n/**\n * A noise effect over `input` as Figma's SVG export draws it: fractal noise one grain to a\n * cycle, its middle tones shown in the effect's colour, a duotone's opposite tones in its\n * second colour, and a multitone's own colours at its opacity, all inside the layer. Returns the\n * result's name.\n */\nexport function noiseFilter(filter: FilterBuilder, effect: NoiseEffect, input: string): string {\n const grain = effect.noise\n const noise = filter.result('noise')\n filter.push('feTurbulence', {\n type: 'fractalNoise',\n baseFrequency: grainFrequency(grain.noiseSize),\n stitchTiles: 'stitch',\n numOctaves: 3,\n seed: grain.seed ?? 0,\n result: noise\n })\n const merged = filter.result('noiseMerge')\n if (grain.noiseType === 'MULTITONE') {\n const colored = filter.result('multitone')\n const linear = { type: 'linear', slope: 2, intercept: -0.5 }\n filter.push(\n 'feComponentTransfer',\n { in: noise, result: colored },\n svg('feFuncR', linear),\n svg('feFuncG', linear),\n svg('feFuncB', linear),\n svg('feFuncA', { type: 'discrete', tableValues: noiseDensityTable(grain.density) })\n )\n const clipped = filter.result('noiseClipped')\n filter.push('feComposite', { in: colored, in2: input, operator: 'in', result: clipped })\n const faded = filter.result('noiseColor')\n filter.push(\n 'feComponentTransfer',\n { in: clipped, result: faded },\n svg('feFuncA', { type: 'table', tableValues: `0 ${round(grain.opacity ?? 1)}` })\n )\n filter.pushElement('feMerge', { result: merged }, mergeNodes([input, faded]))\n return merged\n }\n\n const alpha = filter.result('alphaNoise')\n filter.push('feColorMatrix', { in: noise, type: 'luminanceToAlpha', result: alpha })\n const tones = [{ color: effect.color, mirrored: false }]\n if (grain.noiseType === 'DUOTONE') {\n tones.push({ color: grain.secondaryColor ?? effect.color, mirrored: true })\n }\n const colors = tones.map(({ color, mirrored }) => {\n const band = filter.result('noiseBand')\n filter.push(\n 'feComponentTransfer',\n { in: alpha, result: band },\n svg('feFuncA', { type: 'discrete', tableValues: noiseDensityTable(grain.density, mirrored) })\n )\n const clipped = filter.result('noiseClipped')\n filter.push('feComposite', { in: band, in2: input, operator: 'in', result: clipped })\n const flood = filter.result('noiseFlood')\n filter.push('feFlood', {\n 'flood-color': floodColor(color, filter.colorSpace, filter.documentColorSpace),\n 'flood-opacity': round(color.a),\n result: flood\n })\n const colored = filter.result('noiseColor')\n filter.push('feComposite', { in: flood, in2: clipped, operator: 'in', result: colored })\n return colored\n })\n filter.pushElement('feMerge', { result: merged }, mergeNodes([input, ...colors]))\n return merged\n}\n\nfunction mergeNodes(inputs: readonly string[]) {\n return inputs.map((input) => svg('feMergeNode', { in: input }))\n}\n\n/**\n * A texture effect over `input` as Figma's SVG export draws it: the layer displaced by fractal\n * noise one grain to a cycle, twice the radius at most. Without clipping that is all; clipped to\n * its shape, Figma's chain moves only the layer's inside and keeps it within its own outline.\n * Returns the result's name.\n */\nexport function textureFilter(filter: FilterBuilder, effect: TextureEffect, input: string): string {\n const grain = effect.texture\n const frequency = grainFrequency(grain.noiseSize)\n const scale = round(effect.radius * 2)\n const name = (label: string) => filter.result(label)\n const displace = (into: string, by: string, result: string) =>\n filter.push('feDisplacementMap', {\n in: into,\n in2: by,\n scale,\n xChannelSelector: 'R',\n yChannelSelector: 'G',\n width: '100%',\n height: '100%',\n result\n })\n const turbulence = (seed: number, result: string) =>\n filter.push('feTurbulence', {\n type: 'fractalNoise',\n baseFrequency: frequency,\n numOctaves: 3,\n seed: (grain.seed ?? 0) + seed,\n result\n })\n const matrix = (into: string, values: string, result: string) =>\n filter.push('feColorMatrix', { in: into, type: 'matrix', values, result })\n const arithmetic = (\n into: string,\n by: string,\n k: [number, number, number, number],\n result: string\n ) =>\n filter.push('feComposite', {\n in: into,\n in2: by,\n operator: 'arithmetic',\n k1: k[0],\n k2: k[1],\n k3: k[2],\n k4: k[3],\n result\n })\n const composite = (into: string, by: string, operator: string, result: string) =>\n filter.push('feComposite', { in: into, in2: by, operator, result })\n const gamma = (into: string, result: string) =>\n filter.push(\n 'feComponentTransfer',\n { in: into, result },\n svg('feFuncA', { type: 'gamma', exponent: 0.2 })\n )\n\n if (!grain.clipToShape) {\n const noise = name('textureNoise')\n turbulence(0, noise)\n const displaced = name('texture')\n displace(input, noise, displaced)\n return displaced\n }\n\n const noiseX = name('displacementX')\n const noiseY = name('displacementY')\n turbulence(0, noiseX)\n turbulence(1, noiseY)\n const xRed = name('displacementXRed')\n matrix(noiseX, ALPHA_TO_RED, xRed)\n const yGreen = name('displacementYGreen')\n matrix(noiseY, ALPHA_TO_GREEN, yGreen)\n const xy = name('displacementXY')\n arithmetic(xRed, yGreen, [0, 1, 1, 0], xy)\n const firstPass = name('firstPass')\n displace(input, xy, firstPass)\n const firstAlpha = name('firstPassAlpha')\n matrix(firstPass, ALPHA_ONLY, firstAlpha)\n const displacedAlpha = name('sourceDisplacedAlpha')\n gamma(firstAlpha, displacedAlpha)\n const inputAlphaOnly = name('inputAlphaOnly')\n matrix(input, ALPHA_ONLY, inputAlphaOnly)\n const inputAlpha = name('inputSourceAlpha')\n gamma(inputAlphaOnly, inputAlpha)\n const alphas = name('displacementAlphasMultiplied')\n arithmetic(displacedAlpha, inputAlpha, [1, 0, 0, 0], alphas)\n const centering = name('centeringAdjustment')\n arithmetic(alphas, alphas, [0, 0, -0.5, 0.5], centering)\n\n const finalChannel = (noise: string, values: string, label: string) => {\n const weighted = name(`${label}Weighted`)\n arithmetic(noise, alphas, [1, 0, 0, 0], weighted)\n const centered = name(`${label}Centered`)\n arithmetic(centering, weighted, [0, 1, 1, 0], centered)\n const final = name(`${label}Final`)\n matrix(centered, values, final)\n return final\n }\n const xFinal = finalChannel(noiseX, ALPHA_TO_RED, 'displacementX')\n const yFinal = finalChannel(noiseY, ALPHA_TO_GREEN, 'displacementY')\n const combined = name('displacementCombined')\n arithmetic(xFinal, yFinal, [0, 1, 1, 0], combined)\n const map = name('displacementMap')\n composite(combined, alphas, 'in', map)\n const neutral = name('neutral')\n filter.push('feFlood', {\n 'flood-color': 'rgb(127, 127, 127)',\n 'flood-opacity': 1,\n result: neutral\n })\n const outside = name('neutralOutside')\n composite(neutral, alphas, 'out', outside)\n const mapWithBackground = name('displacementMapWithBg')\n composite(outside, map, 'over', mapWithBackground)\n\n const displaced = name('displacedImage')\n displace(input, mapWithBackground, displaced)\n const opaque = name('imageOpaque')\n matrix(input, OPAQUE, opaque)\n const displacedOpaque = name('displacedImageOpaque')\n displace(opaque, mapWithBackground, displacedOpaque)\n const displacedRed = name('displacedImageRed')\n matrix(displaced, ALPHA_TO_RED_OPAQUE, displacedRed)\n const inputRed = name('inputRed')\n matrix(input, ALPHA_TO_RED_OPAQUE, inputRed)\n const transparencyRed = name('transparencyRedMap')\n composite(displacedRed, inputRed, 'atop', transparencyRed)\n const transparency = name('transparencyAlphaMap')\n matrix(transparencyRed, RED_TO_ALPHA, transparency)\n const layered = name('textureLayered')\n composite(displacedOpaque, opaque, 'over', layered)\n const textured = name('texture')\n composite(layered, transparency, 'in', textured)\n return textured\n}\n"],"mappings":";;;;;AAQA,MAAM,oBAAoB;;AAG1B,MAAM,aAAa;AACnB,MAAM,eAAe;AACrB,MAAM,iBAAiB;AACvB,MAAM,SAAS;AACf,MAAM,sBAAsB;AAC5B,MAAM,eAAe;;A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;CAClD,MAAM,WAAW,KAAK,SAAS;CAC/B,UAAU,SAAS,cAAc,MAAM,QAAQ;CAC/C,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SVGVectorizeResult } from "../../../vector/vectorize/svg/to-vectors.js";
|
|
2
|
-
import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
|
|
2
|
+
import { DocumentColorSpace, SceneGraph, SceneNode } from "@pairdraw/scene-graph";
|
|
3
3
|
import { Size } from "@pairdraw/scene-graph/primitives";
|
|
4
4
|
//#region src/io/formats/svg/import.d.ts
|
|
5
5
|
type SVGImportData = SVGVectorizeResult & Size & {
|
|
@@ -11,13 +11,15 @@ type SVGImportData = SVGVectorizeResult & Size & {
|
|
|
11
11
|
interface SVGImportOptions {
|
|
12
12
|
name?: string;
|
|
13
13
|
defaultColor?: string;
|
|
14
|
+
/** The profile a color that names its own space is read into. */
|
|
15
|
+
profile?: DocumentColorSpace;
|
|
14
16
|
x?: number;
|
|
15
17
|
y?: number;
|
|
16
18
|
/** Keep the frame of an SVG that draws nothing, as `figma.createNodeFromSvg` does. */
|
|
17
19
|
keepEmpty?: boolean;
|
|
18
20
|
}
|
|
19
21
|
/** The layers SVG markup draws, or null when it does not parse as SVG. */
|
|
20
|
-
declare function prepareSVGImport(source: string, options?: Pick<SVGImportOptions, 'defaultColor'>): SVGImportData | null;
|
|
22
|
+
declare function prepareSVGImport(source: string, options?: Pick<SVGImportOptions, 'defaultColor' | 'profile'>): SVGImportData | null;
|
|
21
23
|
declare function createSVGNodesFromImport(graph: SceneGraph, parentId: string, data: SVGImportData, options?: SVGImportOptions): SceneNode | null;
|
|
22
24
|
declare function createSVGNodes(graph: SceneGraph, parentId: string, source: string, options?: SVGImportOptions): SceneNode | null;
|
|
23
25
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import.d.ts","names":[],"sources":["../../../../src/io/formats/svg/import.ts"],"mappings":";;;;KAsBY,gBAAgB,qBAC1B;;EAEE;;EAEA;;UAGa;EACf;EACA;
|
|
1
|
+
{"version":3,"file":"import.d.ts","names":[],"sources":["../../../../src/io/formats/svg/import.ts"],"mappings":";;;;KAsBY,gBAAgB,qBAC1B;;EAEE;;EAEA;;UAGa;EACf;EACA;;EAEA,UAAU;EACV;EACA;;EAEA;;;iBAIc,iBACd,gBACA,UAAS,KAAK,gDACb;iBAiIa,yBACd,OAAO,YACP,kBACA,MAAM,eACN,UAAS,mBACR;iBA4Ba,eACd,OAAO,YACP,kBACA,gBACA,UAAS,mBACR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import.js","names":["BLACK"],"sources":["../../../../src/io/formats/svg/import.ts"],"sourcesContent":["import { groupBy } from 'es-toolkit/array'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { WHITE } from '@pairdraw/scene-graph/constants'\nimport { fitEnclosingGroups } from '@pairdraw/scene-graph/group-bounds'\nimport type { Size } from '@pairdraw/scene-graph/primitives'\n\nimport { BLACK } from '#core/constants'\nimport type { SVGElementLayer } from '#core/icons/types'\nimport { createPlacedVector, vectorizedPathPaints } from '#core/vector/vectorize/placement'\nimport {\n svgToVectorPaths,\n type SVGVectorizeResult,\n type VectorizedClip,\n type VectorizedPath,\n type VectorizedText\n} from '#core/vector/vectorize/svg/to-vectors'\n\nimport { parseSVGDocument } from './document'\nimport { parseSVGSize, svgRootId } from './metadata'\nimport { createSVGText } from './text/import'\n\nexport type SVGImportData = SVGVectorizeResult &\n Size & {\n /** The root `<svg>` element's `id`, which names the imported layer. */\n name: string | null\n /** Without a width, height, or viewBox the SVG has no frame, only a group of its layers. */\n sized: boolean\n }\n\nexport interface SVGImportOptions {\n name?: string\n defaultColor?: string\n x?: number\n y?: number\n /** Keep the frame of an SVG that draws nothing, as `figma.createNodeFromSvg` does. */\n keepEmpty?: boolean\n}\n\n/** The layers SVG markup draws, or null when it does not parse as SVG. */\nexport function prepareSVGImport(\n source: string,\n options: Pick<SVGImportOptions, 'defaultColor'> = {}\n): SVGImportData | null {\n if (!parseSVGDocument(source)) return null\n const sized = parseSVGSize(source, { width: 0, height: 0 }).width > 0\n const { width, height } = parseSVGSize(source)\n const vectorized = svgToVectorPaths(\n source,\n { width, height },\n {\n defaultColor: options.defaultColor,\n preserveAspectRatio: true\n }\n ) ?? { paths: [], texts: [], contentBounds: { x: 0, y: 0, width: 0, height: 0 } }\n return { width, height, name: svgRootId(source), sized, ...vectorized }\n}\n\nfunction createGroup(graph: SceneGraph, parentId: string, props: Partial<SceneNode>): string {\n return graph.createNode('GROUP', parentId, { x: 0, y: 0, ...props }).id\n}\n\n/** Figma's clip wrapper: a mask group drawn from the clip's shapes, then the clipped content. */\nfunction createClipGroup(\n graph: SceneGraph,\n parentId: string,\n clip: VectorizedClip,\n parentIds: Set<string>\n): string {\n const groupId = createGroup(graph, parentId, { name: 'Clip path group' })\n const maskId = createGroup(graph, groupId, {\n name: clip.id,\n isMask: true,\n maskType: 'VECTOR',\n visible: clip.visible\n })\n for (const shape of clip.shapes) {\n createPlacedVector(graph, maskId, shape.network, {\n name: 'Vector',\n visible: shape.visible,\n fills: [{ type: 'SOLID', color: BLACK, opacity: 1, visible: true }]\n })\n }\n parentIds.add(maskId)\n return groupId\n}\n\nfunction clipFor(\n clips: VectorizedClip[] | undefined,\n element: SVGElementLayer\n): VectorizedClip | null {\n const clip = element.clip === null ? null : clips?.[element.clip]\n return clip && clip.shapes.length > 0 ? clip : null\n}\n\n/** A path or a text, with the elements it was drawn in. */\ninterface Drawable {\n elements: SVGElementLayer[]\n clips?: VectorizedClip[]\n create: (parentId: string, element: SVGElementLayer) => void\n}\n\n/** Paths and texts in drawing order: each text goes before the path it preceded. */\nfunction drawables(graph: SceneGraph, data: SVGImportData, parentIds: Set<string>): Drawable[] {\n const pathDrawable = (path: VectorizedPath): Drawable => ({\n elements: path.elements,\n clips: path.clips,\n create: (parentId, element) => {\n const vector = createPlacedVector(graph, parentId, path.vectorNetwork, {\n name: element.name ?? 'Vector',\n opacity: element.opacity,\n visible: element.visible,\n ...vectorizedPathPaints(path)\n })\n if (vector) parentIds.add(parentId)\n }\n })\n const textDrawable = (text: VectorizedText): Drawable => ({\n elements: text.elements,\n clips: text.clips,\n create: (parentId, element) => {\n createSVGText(graph, parentId, text, element, (groupParentId, props) => {\n const groupId = createGroup(graph, groupParentId, props)\n parentIds.add(groupId)\n return groupId\n })\n parentIds.add(parentId)\n }\n })\n const textsByPath = groupBy(data.texts, (text) => text.pathIndex)\n const textsAt = (index: number) => (textsByPath[index] ?? []).map(textDrawable)\n return [\n ...data.paths.flatMap((path, index) => [...textsAt(index), pathDrawable(path)]),\n ...textsAt(data.paths.length)\n ]\n}\n\n/**\n * Builds the layers Figma makes from SVG: a group per `<g>`, a vector per shape and a text layer\n * per text, each named by its `id`, and a clip group around anything clipped. Groups are fitted\n * to their layers last.\n */\nfunction createSVGLayers(graph: SceneGraph, rootId: string, data: SVGImportData): void {\n const open: Array<{ key: number; parentId: string }> = []\n const parentIds = new Set<string>()\n for (const drawable of drawables(graph, data, parentIds)) {\n const groups = drawable.elements.slice(0, -1)\n const shape = drawable.elements.at(-1)\n if (!shape) continue\n let depth = 0\n while (depth < open.length && depth < groups.length && open[depth].key === groups[depth].key) {\n depth++\n }\n open.length = depth\n let parentId = open.at(-1)?.parentId ?? rootId\n for (const element of groups.slice(depth)) {\n const clip = clipFor(drawable.clips, element)\n if (clip) parentId = createClipGroup(graph, parentId, clip, parentIds)\n parentId = createGroup(graph, parentId, {\n name: element.name ?? 'Group',\n opacity: element.opacity,\n visible: element.visible\n })\n open.push({ key: element.key, parentId })\n }\n const clip = clipFor(drawable.clips, shape)\n drawable.create(clip ? createClipGroup(graph, parentId, clip, parentIds) : parentId, shape)\n }\n fitEnclosingGroups(graph, [...parentIds])\n}\n\nexport function createSVGNodesFromImport(\n graph: SceneGraph,\n parentId: string,\n data: SVGImportData,\n options: SVGImportOptions = {}\n): SceneNode | null {\n const position = { x: options.x ?? 0, y: options.y ?? 0 }\n const root = data.sized\n ? graph.createNode('FRAME', parentId, {\n name: options.name ?? data.name ?? 'Frame',\n ...position,\n width: data.width,\n height: data.height,\n fills: [{ type: 'SOLID', color: WHITE, opacity: 1, visible: true }],\n clipsContent: true\n })\n : graph.createNode('GROUP', parentId, {\n name: options.name ?? data.name ?? 'Group',\n ...position\n })\n\n try {\n createSVGLayers(graph, root.id, data)\n const created = graph.getNode(root.id)\n if (created && (options.keepEmpty || graph.getChildren(root.id).length > 0)) return created\n if (created) graph.deleteNode(root.id)\n return null\n } catch (error) {\n graph.deleteNode(root.id)\n throw error\n }\n}\n\nexport function createSVGNodes(\n graph: SceneGraph,\n parentId: string,\n source: string,\n options: SVGImportOptions = {}\n): SceneNode | null {\n const data = prepareSVGImport(source, options)\n return data ? createSVGNodesFromImport(graph, parentId, data, options) : null\n}\n"],"mappings":";;;;;;;;;;;AAwCA,SAAgB,iBACd,QACA,UAAkD,CAAC,GAC7B;CACtB,IAAI,CAAC,iBAAiB,MAAM,GAAG,OAAO;CACtC,MAAM,QAAQ,aAAa,QAAQ;EAAE,OAAO;EAAG,QAAQ;CAAE,CAAC,CAAC,CAAC,QAAQ;CACpE,MAAM,EAAE,OAAO,WAAW,aAAa,MAAM;CAC7C,MAAM,aAAa,iBACjB,QACA;EAAE;EAAO;CAAO,GAChB;EACE,cAAc,QAAQ;EACtB,qBAAqB;CACvB,CACF,KAAK;EAAE,OAAO,CAAC;EAAG,OAAO,CAAC;EAAG,eAAe;GAAE,GAAG;GAAG,GAAG;GAAG,OAAO;GAAG,QAAQ;EAAE;CAAE;CAChF,OAAO;EAAE;EAAO;EAAQ,MAAM,UAAU,MAAM;EAAG;EAAO,GAAG;CAAW;AACxE;AAEA,SAAS,YAAY,OAAmB,UAAkB,OAAmC;CAC3F,OAAO,MAAM,WAAW,SAAS,UAAU;EAAE,GAAG;EAAG,GAAG;EAAG,GAAG;CAAM,CAAC,CAAC,CAAC;AACvE;;AAGA,SAAS,gBACP,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AK;EAAG,GAAG,QAAQ,KAAK;CAAE;CACxD,MAAM,OAAO,KAAK,QACd,MAAM,WAAW,SAAS,UAAU;EAClC,MAAM,QAAQ,QAAQ,KAAK,QAAQ;EACnC,GAAG;EACH,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,OAAO,CAAC;GAAE,MAAM;GAAS,OAAO;GAAO,SAAS;GAAG,SAAS;EAAK,CAAC;EAClE,cAAc;CAChB,CAAC,IACD,MAAM,WAAW,SAAS,UAAU;EAClC,MAAM,QAAQ,QAAQ,KAAK,QAAQ;EACnC,GAAG;CACL,CAAC;CAEL,IAAI;EACF,gBAAgB,OAAO,KAAK,IAAI,IAAI;EACpC,MAAM,UAAU,MAAM,QAAQ,KAAK,EAAE;EACrC,IAAI,YAAY,QAAQ,aAAa,MAAM,YAAY,KAAK,EAAE,CAAC,CAAC,SAAS,IAAI,OAAO;EACpF,IAAI,SAAS,MAAM,WAAW,KAAK,EAAE;EACrC,OAAO;CACT,SAAS,OAAO;EACd,MAAM,WAAW,KAAK,EAAE;EACxB,MAAM;CACR;AACF;AAEA,SAAgB,eACd,OACA,UACA,QACA,UAA4B,CAAC,GACX;CAClB,MAAM,OAAO,iBAAiB,QAAQ,OAAO;CAC7C,OAAO,OAAO,yBAAyB,OAAO,UAAU,MAAM,OAAO,IAAI;AAC3E"}
|
|
1
|
+
{"version":3,"file":"import.js","names":["BLACK"],"sources":["../../../../src/io/formats/svg/import.ts"],"sourcesContent":["import { groupBy } from 'es-toolkit/array'\n\nimport type { DocumentColorSpace, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { WHITE } from '@pairdraw/scene-graph/constants'\nimport { fitEnclosingGroups } from '@pairdraw/scene-graph/group-bounds'\nimport type { Size } from '@pairdraw/scene-graph/primitives'\n\nimport { BLACK } from '#core/constants'\nimport type { SVGElementLayer } from '#core/icons/types'\nimport { createPlacedVector, vectorizedPathPaints } from '#core/vector/vectorize/placement'\nimport {\n svgToVectorPaths,\n type SVGVectorizeResult,\n type VectorizedClip,\n type VectorizedPath,\n type VectorizedText\n} from '#core/vector/vectorize/svg/to-vectors'\n\nimport { parseSVGDocument } from './document'\nimport { parseSVGSize, svgRootId } from './metadata'\nimport { createSVGText } from './text/import'\n\nexport type SVGImportData = SVGVectorizeResult &\n Size & {\n /** The root `<svg>` element's `id`, which names the imported layer. */\n name: string | null\n /** Without a width, height, or viewBox the SVG has no frame, only a group of its layers. */\n sized: boolean\n }\n\nexport interface SVGImportOptions {\n name?: string\n defaultColor?: string\n /** The profile a color that names its own space is read into. */\n profile?: DocumentColorSpace\n x?: number\n y?: number\n /** Keep the frame of an SVG that draws nothing, as `figma.createNodeFromSvg` does. */\n keepEmpty?: boolean\n}\n\n/** The layers SVG markup draws, or null when it does not parse as SVG. */\nexport function prepareSVGImport(\n source: string,\n options: Pick<SVGImportOptions, 'defaultColor' | 'profile'> = {}\n): SVGImportData | null {\n if (!parseSVGDocument(source)) return null\n const sized = parseSVGSize(source, { width: 0, height: 0 }).width > 0\n const { width, height } = parseSVGSize(source)\n const vectorized = svgToVectorPaths(\n source,\n { width, height },\n {\n defaultColor: options.defaultColor,\n preserveAspectRatio: true,\n profile: options.profile\n }\n ) ?? { paths: [], texts: [], contentBounds: { x: 0, y: 0, width: 0, height: 0 } }\n return { width, height, name: svgRootId(source), sized, ...vectorized }\n}\n\nfunction createGroup(graph: SceneGraph, parentId: string, props: Partial<SceneNode>): string {\n return graph.createNode('GROUP', parentId, { x: 0, y: 0, ...props }).id\n}\n\n/** Figma's clip wrapper: a mask group drawn from the clip's shapes, then the clipped content. */\nfunction createClipGroup(\n graph: SceneGraph,\n parentId: string,\n clip: VectorizedClip,\n parentIds: Set<string>\n): string {\n const groupId = createGroup(graph, parentId, { name: 'Clip path group' })\n const maskId = createGroup(graph, groupId, {\n name: clip.id,\n isMask: true,\n maskType: 'VECTOR',\n visible: clip.visible\n })\n for (const shape of clip.shapes) {\n createPlacedVector(graph, maskId, shape.network, {\n name: 'Vector',\n visible: shape.visible,\n fills: [{ type: 'SOLID', color: BLACK, opacity: 1, visible: true }]\n })\n }\n parentIds.add(maskId)\n return groupId\n}\n\nfunction clipFor(\n clips: VectorizedClip[] | undefined,\n element: SVGElementLayer\n): VectorizedClip | null {\n const clip = element.clip === null ? null : clips?.[element.clip]\n return clip && clip.shapes.length > 0 ? clip : null\n}\n\n/** A path or a text, with the elements it was drawn in. */\ninterface Drawable {\n elements: SVGElementLayer[]\n clips?: VectorizedClip[]\n create: (parentId: string, element: SVGElementLayer) => void\n}\n\n/** Paths and texts in drawing order: each text goes before the path it preceded. */\nfunction drawables(graph: SceneGraph, data: SVGImportData, parentIds: Set<string>): Drawable[] {\n const pathDrawable = (path: VectorizedPath): Drawable => ({\n elements: path.elements,\n clips: path.clips,\n create: (parentId, element) => {\n const vector = createPlacedVector(graph, parentId, path.vectorNetwork, {\n name: element.name ?? 'Vector',\n opacity: element.opacity,\n visible: element.visible,\n ...vectorizedPathPaints(path)\n })\n if (vector) parentIds.add(parentId)\n }\n })\n const textDrawable = (text: VectorizedText): Drawable => ({\n elements: text.elements,\n clips: text.clips,\n create: (parentId, element) => {\n createSVGText(graph, parentId, text, element, (groupParentId, props) => {\n const groupId = createGroup(graph, groupParentId, props)\n parentIds.add(groupId)\n return groupId\n })\n parentIds.add(parentId)\n }\n })\n const textsByPath = groupBy(data.texts, (text) => text.pathIndex)\n const textsAt = (index: number) => (textsByPath[index] ?? []).map(textDrawable)\n return [\n ...data.paths.flatMap((path, index) => [...textsAt(index), pathDrawable(path)]),\n ...textsAt(data.paths.length)\n ]\n}\n\n/**\n * Builds the layers Figma makes from SVG: a group per `<g>`, a vector per shape and a text layer\n * per text, each named by its `id`, and a clip group around anything clipped. Groups are fitted\n * to their layers last.\n */\nfunction createSVGLayers(graph: SceneGraph, rootId: string, data: SVGImportData): void {\n const open: Array<{ key: number; parentId: string }> = []\n const parentIds = new Set<string>()\n for (const drawable of drawables(graph, data, parentIds)) {\n const groups = drawable.elements.slice(0, -1)\n const shape = drawable.elements.at(-1)\n if (!shape) continue\n let depth = 0\n while (depth < open.length && depth < groups.length && open[depth].key === groups[depth].key) {\n depth++\n }\n open.length = depth\n let parentId = open.at(-1)?.parentId ?? rootId\n for (const element of groups.slice(depth)) {\n const clip = clipFor(drawable.clips, element)\n if (clip) parentId = createClipGroup(graph, parentId, clip, parentIds)\n parentId = createGroup(graph, parentId, {\n name: element.name ?? 'Group',\n opacity: element.opacity,\n visible: element.visible\n })\n open.push({ key: element.key, parentId })\n }\n const clip = clipFor(drawable.clips, shape)\n drawable.create(clip ? createClipGroup(graph, parentId, clip, parentIds) : parentId, shape)\n }\n fitEnclosingGroups(graph, [...parentIds])\n}\n\nexport function createSVGNodesFromImport(\n graph: SceneGraph,\n parentId: string,\n data: SVGImportData,\n options: SVGImportOptions = {}\n): SceneNode | null {\n const position = { x: options.x ?? 0, y: options.y ?? 0 }\n const root = data.sized\n ? graph.createNode('FRAME', parentId, {\n name: options.name ?? data.name ?? 'Frame',\n ...position,\n width: data.width,\n height: data.height,\n fills: [{ type: 'SOLID', color: WHITE, opacity: 1, visible: true }],\n clipsContent: true\n })\n : graph.createNode('GROUP', parentId, {\n name: options.name ?? data.name ?? 'Group',\n ...position\n })\n\n try {\n createSVGLayers(graph, root.id, data)\n const created = graph.getNode(root.id)\n if (created && (options.keepEmpty || graph.getChildren(root.id).length > 0)) return created\n if (created) graph.deleteNode(root.id)\n return null\n } catch (error) {\n graph.deleteNode(root.id)\n throw error\n }\n}\n\nexport function createSVGNodes(\n graph: SceneGraph,\n parentId: string,\n source: string,\n options: SVGImportOptions = {}\n): SceneNode | null {\n const data = prepareSVGImport(source, options)\n return data ? createSVGNodesFromImport(graph, parentId, data, options) : null\n}\n"],"mappings":";;;;;;;;;;;AA0CA,SAAgB,iBACd,QACA,UAA8D,CAAC,GACzC;CACtB,IAAI,CAAC,iBAAiB,MAAM,GAAG,OAAO;CACtC,MAAM,QAAQ,aAAa,QAAQ;EAAE,OAAO;EAAG,QAAQ;CA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OACA,UACA,QACA,UAA4B,CAAC,GACX;CAClB,MAAM,OAAO,iBAAiB,QAAQ,OAAO;CAC7C,OAAO,OAAO,yBAAyB,OAAO,UAAU,MAAM,OAAO,IAAI;AAC3E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.d.ts","names":[],"sources":["../../../../../src/io/formats/svg/text/export.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"export.d.ts","names":[],"sources":["../../../../../src/io/formats/svg/text/export.ts"],"mappings":";;;;iBAwMgB,eACd,MAAM,WACN,yBACA,KAAK,kBACL,uBACC"}
|
|
@@ -9,7 +9,7 @@ import { textLengthPixels } from "@pairdraw/scene-graph/text";
|
|
|
9
9
|
import { parseFontStyle } from "@pairdraw/scene-graph/font-style";
|
|
10
10
|
import { resolveNodeTextDirection } from "@pairdraw/scene-graph/text/direction";
|
|
11
11
|
//#region src/io/formats/svg/text/export.ts
|
|
12
|
-
function styleOverrideToTspanAttrs(style, colorSpace, parentFillOpacity, node) {
|
|
12
|
+
function styleOverrideToTspanAttrs(style, colorSpace, documentSpace, parentFillOpacity, node) {
|
|
13
13
|
const attrs = {};
|
|
14
14
|
if (style.fontFamily) attrs["font-family"] = style.fontFamily;
|
|
15
15
|
if (style.fontSize) attrs["font-size"] = style.fontSize;
|
|
@@ -27,9 +27,9 @@ function styleOverrideToTspanAttrs(style, colorSpace, parentFillOpacity, node) {
|
|
|
27
27
|
if (colorSpace === "display-p3") attrs.fill = formatColor({
|
|
28
28
|
...visibleFill.color,
|
|
29
29
|
a: 1
|
|
30
|
-
}, alpha, colorSpace);
|
|
30
|
+
}, alpha, colorSpace, documentSpace);
|
|
31
31
|
else {
|
|
32
|
-
attrs.fill = formatColor(visibleFill.color, 1, colorSpace);
|
|
32
|
+
attrs.fill = formatColor(visibleFill.color, 1, colorSpace, documentSpace);
|
|
33
33
|
if (alpha < 1) attrs["fill-opacity"] = alpha;
|
|
34
34
|
}
|
|
35
35
|
if (alpha >= 1 && parentFillOpacity !== void 0) attrs["fill-opacity"] = 1;
|
|
@@ -68,11 +68,11 @@ function spanFontAttrs(node, style, fallback, fontAlias) {
|
|
|
68
68
|
* so the same band is painted behind the fill at twice the weight, which hides the inner half. An
|
|
69
69
|
* inside or centred stroke keeps its own weight over the fill.
|
|
70
70
|
*/
|
|
71
|
-
function textStrokeAttrs(node, colorSpace) {
|
|
71
|
+
function textStrokeAttrs(node, colorSpace, documentSpace = "srgb") {
|
|
72
72
|
const stroke = node.strokes.find((candidate) => candidate.visible);
|
|
73
73
|
if (!stroke) return {};
|
|
74
74
|
const attrs = {
|
|
75
|
-
stroke: formatSolidColor(stroke.color, 1, colorSpace),
|
|
75
|
+
stroke: formatSolidColor(stroke.color, 1, colorSpace, documentSpace),
|
|
76
76
|
"stroke-width": round(stroke.weight * (stroke.align === "OUTSIDE" ? 2 : 1))
|
|
77
77
|
};
|
|
78
78
|
if (stroke.opacity < 1) attrs["stroke-opacity"] = round(stroke.opacity);
|
|
@@ -134,7 +134,7 @@ function renderUnmeasuredText(node, attrs, spanAttrs, direction) {
|
|
|
134
134
|
}, shownText(node));
|
|
135
135
|
}
|
|
136
136
|
function renderTextNode(node, fillAttr, ctx, fillOpacity) {
|
|
137
|
-
const { colorSpace, textLayout, fontAlias } = ctx;
|
|
137
|
+
const { colorSpace, documentColorSpace: documentSpace, textLayout, fontAlias } = ctx;
|
|
138
138
|
const direction = resolveNodeTextDirection(node);
|
|
139
139
|
const lines = textLayout ? textLayout(node) : null;
|
|
140
140
|
const laidOut = lines && lines.length > 0 ? lines : null;
|
|
@@ -153,11 +153,11 @@ function renderTextNode(node, fillAttr, ctx, fillOpacity) {
|
|
|
153
153
|
"text-anchor": laidOut ? void 0 : textAnchorForNode(node, direction),
|
|
154
154
|
"text-decoration": textDecoration,
|
|
155
155
|
"letter-spacing": letterSpacing ? round(letterSpacing) : void 0,
|
|
156
|
-
...textStrokeAttrs(node, colorSpace),
|
|
156
|
+
...textStrokeAttrs(node, colorSpace, documentSpace),
|
|
157
157
|
...fontAlias ? aliasedFontAttrs(fontRequest(node), fontAlias) : {}
|
|
158
158
|
};
|
|
159
159
|
const spanAttrs = (style, fallback) => ({
|
|
160
|
-
...styleOverrideToTspanAttrs(style, colorSpace, fillOpacity, node),
|
|
160
|
+
...styleOverrideToTspanAttrs(style, colorSpace, documentSpace, fillOpacity, node),
|
|
161
161
|
...spanFontAttrs(node, style, fallback, fontAlias)
|
|
162
162
|
});
|
|
163
163
|
if (laidOut) return svg("text", {
|