@pairdraw/core 0.19.2 → 0.20.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/ai/providers.d.ts +6 -0
- package/dist/ai/providers.d.ts.map +1 -1
- package/dist/ai/providers.js.map +1 -1
- package/dist/cache/resource.d.ts +8 -1
- package/dist/cache/resource.d.ts.map +1 -1
- package/dist/cache/resource.js +18 -0
- package/dist/cache/resource.js.map +1 -1
- package/dist/canvas/effects.d.ts +6 -4
- package/dist/canvas/effects.d.ts.map +1 -1
- package/dist/canvas/effects.js +37 -34
- package/dist/canvas/effects.js.map +1 -1
- package/dist/canvas/fills.d.ts.map +1 -1
- package/dist/canvas/fills.js +12 -8
- package/dist/canvas/fills.js.map +1 -1
- package/dist/canvas/images/adjustments.d.ts +18 -0
- package/dist/canvas/images/adjustments.d.ts.map +1 -0
- package/dist/canvas/images/adjustments.js +184 -0
- package/dist/canvas/images/adjustments.js.map +1 -0
- package/dist/canvas/images/sampling.d.ts +13 -0
- package/dist/canvas/images/sampling.d.ts.map +1 -0
- package/dist/canvas/images/sampling.js +49 -0
- package/dist/canvas/images/sampling.js.map +1 -0
- package/dist/canvas/index.d.ts +2 -2
- package/dist/canvas/masks.d.ts +1 -1
- package/dist/canvas/masks.d.ts.map +1 -1
- package/dist/canvas/masks.js.map +1 -1
- package/dist/canvas/noise/render.d.ts +15 -0
- package/dist/canvas/noise/render.d.ts.map +1 -0
- package/dist/canvas/noise/render.js +56 -0
- package/dist/canvas/noise/render.js.map +1 -0
- package/dist/canvas/noise/shader.d.ts +43 -0
- package/dist/canvas/noise/shader.d.ts.map +1 -0
- package/dist/canvas/noise/shader.js +161 -0
- package/dist/canvas/noise/shader.js.map +1 -0
- package/dist/canvas/noise/table.d.ts +13 -0
- package/dist/canvas/noise/table.d.ts.map +1 -0
- package/dist/canvas/noise/table.js +408 -0
- package/dist/canvas/noise/table.js.map +1 -0
- package/dist/canvas/noise/tile.d.ts +22 -0
- package/dist/canvas/noise/tile.d.ts.map +1 -0
- package/dist/canvas/noise/tile.js +73 -0
- package/dist/canvas/noise/tile.js.map +1 -0
- package/dist/canvas/outline-stroke.js +1 -1
- package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
- package/dist/canvas/overlays/auto-layout-hover.js +31 -71
- package/dist/canvas/overlays/auto-layout-hover.js.map +1 -1
- package/dist/canvas/renderer/chunks/index.d.ts +1 -1
- package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +6 -0
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +13 -1
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/play-scenes.d.ts +13 -0
- package/dist/canvas/renderer/play-scenes.d.ts.map +1 -0
- package/dist/canvas/renderer/play-scenes.js +40 -0
- package/dist/canvas/renderer/play-scenes.js.map +1 -0
- package/dist/canvas/renderer/tiles/cache.d.ts +19 -1
- package/dist/canvas/renderer/tiles/cache.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/cache.js +32 -1
- package/dist/canvas/renderer/tiles/cache.js.map +1 -1
- package/dist/canvas/renderer/tiles/controller.d.ts +11 -0
- package/dist/canvas/renderer/tiles/controller.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/controller.js +18 -1
- package/dist/canvas/renderer/tiles/controller.js.map +1 -1
- package/dist/canvas/renderer/tiles/index.d.ts +2 -2
- package/dist/canvas/renderer/tiles/planner.d.ts +1 -1
- package/dist/canvas/renderer/types.d.ts +18 -3
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer/visual-bounds.d.ts +1 -1
- package/dist/canvas/renderer/visual-bounds.js +1 -1
- package/dist/canvas/renderer.d.ts +22 -2
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +29 -1
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/scene.d.ts +2 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +41 -9
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/shadows/silhouette.js +1 -1
- package/dist/canvas/texture.d.ts +20 -0
- package/dist/canvas/texture.d.ts.map +1 -0
- package/dist/canvas/texture.js +100 -0
- package/dist/canvas/texture.js.map +1 -0
- package/dist/clipboard.js +16 -5
- package/dist/clipboard.js.map +1 -1
- package/dist/constants.d.ts +5 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +5 -1
- package/dist/constants.js.map +1 -1
- package/dist/design-jsx/renderer.d.ts.map +1 -1
- package/dist/design-memory/check.d.ts +90 -0
- package/dist/design-memory/check.d.ts.map +1 -0
- package/dist/design-memory/check.js +281 -0
- package/dist/design-memory/check.js.map +1 -0
- package/dist/design-memory/describe.d.ts +37 -0
- package/dist/design-memory/describe.d.ts.map +1 -0
- package/dist/design-memory/describe.js +52 -0
- package/dist/design-memory/describe.js.map +1 -0
- package/dist/design-memory/distil.d.ts +22 -0
- package/dist/design-memory/distil.d.ts.map +1 -0
- package/dist/design-memory/distil.js +54 -0
- package/dist/design-memory/distil.js.map +1 -0
- package/dist/design-memory/document.d.ts +12 -0
- package/dist/design-memory/document.d.ts.map +1 -0
- package/dist/design-memory/document.js +64 -0
- package/dist/design-memory/document.js.map +1 -0
- package/dist/design-memory/guard.d.ts +48 -0
- package/dist/design-memory/guard.d.ts.map +1 -0
- package/dist/design-memory/guard.js +105 -0
- package/dist/design-memory/guard.js.map +1 -0
- package/dist/design-memory/index.d.ts +9 -0
- package/dist/design-memory/index.js +9 -0
- package/dist/design-memory/refusal.d.ts +32 -0
- package/dist/design-memory/refusal.d.ts.map +1 -0
- package/dist/design-memory/refusal.js +68 -0
- package/dist/design-memory/refusal.js.map +1 -0
- package/dist/design-memory/rules.d.ts +63 -0
- package/dist/design-memory/rules.d.ts.map +1 -0
- package/dist/design-memory/rules.js +224 -0
- package/dist/design-memory/rules.js.map +1 -0
- package/dist/design-memory/values.d.ts +28 -0
- package/dist/design-memory/values.d.ts.map +1 -0
- package/dist/design-memory/values.js +160 -0
- package/dist/design-memory/values.js.map +1 -0
- package/dist/editor/alignment.js +1 -1
- package/dist/editor/bridges/components.d.ts +2 -0
- package/dist/editor/bridges/components.d.ts.map +1 -1
- package/dist/editor/bridges/components.js +2 -0
- package/dist/editor/bridges/components.js.map +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/clipboard/assets.js +1 -1
- package/dist/editor/clipboard/export.d.ts.map +1 -1
- package/dist/editor/clipboard/export.js +16 -2
- package/dist/editor/clipboard/export.js.map +1 -1
- package/dist/editor/clipboard/placement.d.ts +1 -1
- package/dist/editor/clipboard/placement.js +1 -1
- package/dist/editor/components/instances.d.ts +2 -0
- package/dist/editor/components/instances.d.ts.map +1 -1
- package/dist/editor/components/instances.js +22 -1
- package/dist/editor/components/instances.js.map +1 -1
- package/dist/editor/components.d.ts +2 -0
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor/connectors/attach.js +1 -1
- package/dist/editor/create.d.ts +27 -3
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +16 -60
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/design-memory.d.ts +11 -0
- package/dist/editor/design-memory.d.ts.map +1 -0
- package/dist/editor/design-memory.js +40 -0
- package/dist/editor/design-memory.js.map +1 -0
- package/dist/editor/design-tokens.d.ts +4 -0
- package/dist/editor/design-tokens.d.ts.map +1 -1
- package/dist/editor/design-tokens.js +30 -1
- package/dist/editor/design-tokens.js.map +1 -1
- package/dist/editor/document-colors.d.ts +23 -0
- package/dist/editor/document-colors.d.ts.map +1 -0
- package/dist/editor/document-colors.js +53 -0
- package/dist/editor/document-colors.js.map +1 -0
- package/dist/editor/eyedropper.d.ts +47 -0
- package/dist/editor/eyedropper.d.ts.map +1 -0
- package/dist/editor/eyedropper.js +168 -0
- package/dist/editor/eyedropper.js.map +1 -0
- package/dist/editor/fonts.d.ts +9 -0
- package/dist/editor/fonts.d.ts.map +1 -0
- package/dist/editor/fonts.js +14 -0
- package/dist/editor/fonts.js.map +1 -0
- package/dist/editor/history/atomic-tool.d.ts +9 -2
- package/dist/editor/history/atomic-tool.d.ts.map +1 -1
- package/dist/editor/history/atomic-tool.js +6 -0
- package/dist/editor/history/atomic-tool.js.map +1 -1
- package/dist/editor/history/capture.d.ts +13 -0
- package/dist/editor/history/capture.d.ts.map +1 -0
- package/dist/editor/history/capture.js +28 -0
- package/dist/editor/history/capture.js.map +1 -0
- package/dist/editor/history/document-change.d.ts.map +1 -1
- package/dist/editor/history/document-change.js +2 -22
- package/dist/editor/history/document-change.js.map +1 -1
- package/dist/editor/history/edit.d.ts +7 -0
- package/dist/editor/history/edit.d.ts.map +1 -1
- package/dist/editor/history/edit.js +4 -2
- package/dist/editor/history/edit.js.map +1 -1
- package/dist/editor/history/subtree.d.ts +9 -0
- package/dist/editor/history/subtree.d.ts.map +1 -1
- package/dist/editor/history/subtree.js +12 -2
- package/dist/editor/history/subtree.js.map +1 -1
- package/dist/editor/index.d.ts +4 -2
- package/dist/editor/index.js +4 -2
- package/dist/editor/pages.d.ts +7 -5
- package/dist/editor/pages.d.ts.map +1 -1
- package/dist/editor/pages.js +35 -25
- package/dist/editor/pages.js.map +1 -1
- package/dist/editor/play/states.d.ts +3 -1
- package/dist/editor/play/states.d.ts.map +1 -1
- package/dist/editor/play/states.js +1 -1
- package/dist/editor/play/states.js.map +1 -1
- package/dist/editor/read-only/actions.js +4 -0
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/render-requests.d.ts +18 -0
- package/dist/editor/render-requests.d.ts.map +1 -0
- package/dist/editor/render-requests.js +76 -0
- package/dist/editor/render-requests.js.map +1 -0
- package/dist/editor/scale/rescale.d.ts +1 -1
- package/dist/editor/selection/overlays.d.ts.map +1 -1
- package/dist/editor/selection/overlays.js +1 -1
- package/dist/editor/selection/overlays.js.map +1 -1
- package/dist/editor/selection/read.d.ts +4 -0
- package/dist/editor/selection.d.ts +5 -0
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/tool-registry.d.ts.map +1 -1
- package/dist/editor/tool-registry.js +2 -1
- package/dist/editor/tool-registry.js.map +1 -1
- package/dist/editor/types.d.ts +5 -1
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/variations/create.d.ts +28 -0
- package/dist/editor/variations/create.d.ts.map +1 -0
- package/dist/editor/variations/create.js +176 -0
- package/dist/editor/variations/create.js.map +1 -0
- package/dist/editor/variations/pick.d.ts +16 -0
- package/dist/editor/variations/pick.d.ts.map +1 -0
- package/dist/editor/variations/pick.js +23 -0
- package/dist/editor/variations/pick.js.map +1 -0
- package/dist/editor/variations.d.ts +28 -0
- package/dist/editor/variations.d.ts.map +1 -0
- package/dist/editor/variations.js +88 -0
- package/dist/editor/variations.js.map +1 -0
- package/dist/figma-api/accessors/reactions.d.ts.map +1 -1
- package/dist/figma-api/accessors/reactions.js +4 -1
- package/dist/figma-api/accessors/reactions.js.map +1 -1
- package/dist/figma-api/accessors/text/index.js +3 -0
- package/dist/figma-api/accessors/text/index.js.map +1 -1
- package/dist/figma-api/accessors/text/opentype.d.ts +17 -0
- package/dist/figma-api/accessors/text/opentype.d.ts.map +1 -0
- package/dist/figma-api/accessors/text/opentype.js +28 -0
- package/dist/figma-api/accessors/text/opentype.js.map +1 -0
- package/dist/figma-api/accessors/visual.d.ts.map +1 -1
- package/dist/figma-api/accessors/visual.js +33 -0
- package/dist/figma-api/accessors/visual.js.map +1 -1
- package/dist/figma-api/effects.d.ts +79 -3
- package/dist/figma-api/effects.d.ts.map +1 -1
- package/dist/figma-api/effects.js +150 -9
- package/dist/figma-api/effects.js.map +1 -1
- package/dist/figma-api/index.d.ts +5 -0
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +6 -1
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/overrides.d.ts +13 -1
- package/dist/figma-api/overrides.d.ts.map +1 -1
- package/dist/figma-api/overrides.js +196 -4
- package/dist/figma-api/overrides.js.map +1 -1
- package/dist/figma-api/paints.d.ts +3 -3
- package/dist/figma-api/paints.d.ts.map +1 -1
- package/dist/figma-api/paints.js +14 -4
- package/dist/figma-api/paints.js.map +1 -1
- package/dist/figma-api/proxy.d.ts +4 -1
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +1 -1
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +41 -13
- package/dist/figma-api/reactions.d.ts.map +1 -1
- package/dist/figma-api/reactions.js +113 -31
- package/dist/figma-api/reactions.js.map +1 -1
- package/dist/figma-api/render-bounds.js +1 -1
- package/dist/figma-api/surface.d.ts +6 -3
- package/dist/figma-api/surface.d.ts.map +1 -1
- package/dist/figma-api/surface.js +6 -2
- package/dist/figma-api/surface.js.map +1 -1
- package/dist/figma-api/transform.d.ts +1 -1
- package/dist/geometry/figma.d.ts +1 -1
- package/dist/geometry/image-crop.d.ts +1 -1
- package/dist/geometry/image-crop.js +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/io/formats/boolean-path.d.ts +19 -0
- package/dist/io/formats/boolean-path.d.ts.map +1 -0
- package/dist/io/formats/boolean-path.js +47 -0
- package/dist/io/formats/boolean-path.js.map +1 -0
- package/dist/io/formats/design-tokens/decode.js +1 -1
- package/dist/io/formats/design-tokens/index.d.ts +4 -1
- package/dist/io/formats/design-tokens/index.js +4 -1
- package/dist/io/formats/design-tokens/plan/changes.d.ts +5 -3
- package/dist/io/formats/design-tokens/plan/changes.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/changes.js +1 -1
- package/dist/io/formats/design-tokens/plan/changes.js.map +1 -1
- package/dist/io/formats/design-tokens/project.d.ts +17 -2
- package/dist/io/formats/design-tokens/project.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/project.js +29 -8
- package/dist/io/formats/design-tokens/project.js.map +1 -1
- package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/sync/apply.d.ts +42 -0
- package/dist/io/formats/design-tokens/sync/apply.d.ts.map +1 -0
- package/dist/io/formats/design-tokens/sync/apply.js +73 -0
- package/dist/io/formats/design-tokens/sync/apply.js.map +1 -0
- package/dist/io/formats/design-tokens/sync/drift.d.ts +77 -0
- package/dist/io/formats/design-tokens/sync/drift.d.ts.map +1 -0
- package/dist/io/formats/design-tokens/sync/drift.js +391 -0
- package/dist/io/formats/design-tokens/sync/drift.js.map +1 -0
- package/dist/io/formats/design-tokens/sync/files.d.ts +15 -0
- package/dist/io/formats/design-tokens/sync/files.d.ts.map +1 -0
- package/dist/io/formats/design-tokens/sync/files.js +35 -0
- package/dist/io/formats/design-tokens/sync/files.js.map +1 -0
- package/dist/io/formats/drawio/edges.d.ts +7 -1
- package/dist/io/formats/drawio/edges.d.ts.map +1 -1
- package/dist/io/formats/drawio/edges.js +54 -1
- package/dist/io/formats/drawio/edges.js.map +1 -1
- package/dist/io/formats/drawio/export.d.ts.map +1 -1
- package/dist/io/formats/drawio/export.js +19 -2
- package/dist/io/formats/drawio/export.js.map +1 -1
- package/dist/io/formats/drawio/index.js +1 -0
- package/dist/io/formats/drawio/index.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/placement.d.ts +1 -1
- package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/patch/index.js +5 -0
- package/dist/io/formats/fig/export/patch/index.js.map +1 -1
- package/dist/io/formats/fig/thumbnail-page.d.ts +3 -4
- package/dist/io/formats/fig/thumbnail-page.d.ts.map +1 -1
- package/dist/io/formats/fig/thumbnail-page.js.map +1 -1
- package/dist/io/formats/html/import.d.ts.map +1 -1
- package/dist/io/formats/html/import.js +3 -1
- package/dist/io/formats/html/import.js.map +1 -1
- package/dist/io/formats/html/index.d.ts +2 -2
- package/dist/io/formats/html/index.d.ts.map +1 -1
- package/dist/io/formats/html/index.js +6 -4
- package/dist/io/formats/html/index.js.map +1 -1
- package/dist/io/formats/html/vectors.d.ts +2 -1
- package/dist/io/formats/html/vectors.d.ts.map +1 -1
- package/dist/io/formats/html/vectors.js +3 -2
- package/dist/io/formats/html/vectors.js.map +1 -1
- package/dist/io/formats/mermaid/styles.js +1 -1
- package/dist/io/formats/pdf/document.d.ts +3 -1
- package/dist/io/formats/pdf/document.d.ts.map +1 -1
- package/dist/io/formats/pdf/document.js +6 -3
- package/dist/io/formats/pdf/document.js.map +1 -1
- package/dist/io/formats/pdf/prepare.d.ts +1 -1
- package/dist/io/formats/pen/imports.d.ts +4 -1
- package/dist/io/formats/pen/imports.d.ts.map +1 -1
- package/dist/io/formats/pen/imports.js.map +1 -1
- package/dist/io/formats/pen/index.d.ts.map +1 -1
- package/dist/io/formats/pen/index.js +31 -3
- package/dist/io/formats/pen/index.js.map +1 -1
- package/dist/io/formats/pptx/export.js +1 -1
- package/dist/io/formats/pptx/geometry.d.ts +1 -1
- package/dist/io/formats/raster/adjusted-images.d.ts +15 -0
- package/dist/io/formats/raster/adjusted-images.d.ts.map +1 -0
- package/dist/io/formats/raster/adjusted-images.js +118 -0
- package/dist/io/formats/raster/adjusted-images.js.map +1 -0
- package/dist/io/formats/raster/headless.d.ts +11 -1
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +4 -4
- package/dist/io/formats/raster/headless.js.map +1 -1
- package/dist/io/formats/raster/index.d.ts +2 -2
- package/dist/io/formats/raster/pixels.d.ts +7 -1
- package/dist/io/formats/raster/pixels.d.ts.map +1 -1
- package/dist/io/formats/raster/pixels.js.map +1 -1
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +4 -0
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts +5 -6
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +1 -53
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/effects.d.ts +16 -0
- package/dist/io/formats/svg/effects.d.ts.map +1 -0
- package/dist/io/formats/svg/effects.js +126 -0
- package/dist/io/formats/svg/effects.js.map +1 -0
- package/dist/io/formats/svg/export.d.ts +7 -1
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +174 -36
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/filter.d.ts +27 -0
- package/dist/io/formats/svg/filter.d.ts.map +1 -0
- package/dist/io/formats/svg/filter.js +44 -0
- package/dist/io/formats/svg/filter.js.map +1 -0
- package/dist/io/formats/svg/grain.d.ts +26 -0
- package/dist/io/formats/svg/grain.d.ts.map +1 -0
- package/dist/io/formats/svg/grain.js +298 -0
- package/dist/io/formats/svg/grain.js.map +1 -0
- package/dist/io/formats/svg/strokes.d.ts +1 -1
- package/dist/io/formats/svg/strokes.d.ts.map +1 -1
- package/dist/io/formats/svg/strokes.js +1 -2
- package/dist/io/formats/svg/strokes.js.map +1 -1
- package/dist/io/formats/svg/text/import.js +1 -1
- package/dist/io/formats/svg/text/layout.d.ts +5 -2
- package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
- package/dist/io/formats/svg/text/layout.js +6 -3
- package/dist/io/formats/svg/text/layout.js.map +1 -1
- package/dist/io/formats/video/composite.d.ts +18 -0
- package/dist/io/formats/video/composite.d.ts.map +1 -0
- package/dist/io/formats/video/composite.js +79 -0
- package/dist/io/formats/video/composite.js.map +1 -0
- package/dist/io/formats/video/formats.d.ts +29 -0
- package/dist/io/formats/video/formats.d.ts.map +1 -0
- package/dist/io/formats/video/formats.js +43 -0
- package/dist/io/formats/video/formats.js.map +1 -0
- package/dist/io/formats/video/gif.d.ts +13 -0
- package/dist/io/formats/video/gif.d.ts.map +1 -0
- package/dist/io/formats/video/gif.js +56 -0
- package/dist/io/formats/video/gif.js.map +1 -0
- package/dist/io/formats/video/index.d.ts +9 -0
- package/dist/io/formats/video/index.js +9 -0
- package/dist/io/formats/video/plan.d.ts +64 -0
- package/dist/io/formats/video/plan.d.ts.map +1 -0
- package/dist/io/formats/video/plan.js +90 -0
- package/dist/io/formats/video/plan.js.map +1 -0
- package/dist/io/formats/video/record.d.ts +36 -0
- package/dist/io/formats/video/record.d.ts.map +1 -0
- package/dist/io/formats/video/record.js +154 -0
- package/dist/io/formats/video/record.js.map +1 -0
- package/dist/io/formats/video/sink.d.ts +29 -0
- package/dist/io/formats/video/sink.d.ts.map +1 -0
- package/dist/io/formats/video/sink.js +16 -0
- package/dist/io/formats/video/sink.js.map +1 -0
- package/dist/io/formats/video/size.d.ts +19 -0
- package/dist/io/formats/video/size.d.ts.map +1 -0
- package/dist/io/formats/video/size.js +26 -0
- package/dist/io/formats/video/size.js.map +1 -0
- package/dist/io/formats/video/webcodecs.d.ts +18 -0
- package/dist/io/formats/video/webcodecs.d.ts.map +1 -0
- package/dist/io/formats/video/webcodecs.js +74 -0
- package/dist/io/formats/video/webcodecs.js.map +1 -0
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +40 -11
- package/dist/io/formats.js.map +1 -1
- package/dist/io/types.d.ts +19 -4
- package/dist/io/types.d.ts.map +1 -1
- package/dist/kiwi/fig/parse/transfer.d.ts +1 -1
- package/dist/layout/auto-layout-handles.d.ts +66 -0
- package/dist/layout/auto-layout-handles.d.ts.map +1 -0
- package/dist/layout/auto-layout-handles.js +291 -0
- package/dist/layout/auto-layout-handles.js.map +1 -0
- package/dist/layout.d.ts +3 -2
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +2 -1
- package/dist/layout.js.map +1 -1
- package/dist/lint/fixes.d.ts.map +1 -1
- package/dist/lint/fixes.js +9 -3
- package/dist/lint/fixes.js.map +1 -1
- package/dist/lint/index.d.ts +3 -2
- package/dist/lint/index.js +2 -1
- package/dist/lint/linter.d.ts +12 -0
- package/dist/lint/linter.d.ts.map +1 -1
- package/dist/lint/linter.js +110 -8
- package/dist/lint/linter.js.map +1 -1
- package/dist/lint/presets.d.ts.map +1 -1
- package/dist/lint/presets.js +2 -0
- package/dist/lint/presets.js.map +1 -1
- package/dist/lint/rules/design-memory.d.ts +15 -0
- package/dist/lint/rules/design-memory.d.ts.map +1 -0
- package/dist/lint/rules/design-memory.js +90 -0
- package/dist/lint/rules/design-memory.js.map +1 -0
- package/dist/lint/rules/index.d.ts +6 -5
- package/dist/lint/rules/index.d.ts.map +1 -1
- package/dist/lint/rules/index.js +6 -2
- package/dist/lint/rules/index.js.map +1 -1
- package/dist/lint/rules/no-unbound-token-values.d.ts +6 -0
- package/dist/lint/rules/no-unbound-token-values.d.ts.map +1 -0
- package/dist/lint/rules/no-unbound-token-values.js +79 -0
- package/dist/lint/rules/no-unbound-token-values.js.map +1 -0
- package/dist/lint/types.d.ts +25 -2
- package/dist/lint/types.d.ts.map +1 -1
- package/dist/node/video.d.ts +12 -0
- package/dist/node/video.d.ts.map +1 -0
- package/dist/node/video.js +206 -0
- package/dist/node/video.js.map +1 -0
- package/dist/pairdraw-api/design-memory.d.ts +19 -0
- package/dist/pairdraw-api/design-memory.d.ts.map +1 -0
- package/dist/pairdraw-api/design-memory.js +39 -0
- package/dist/pairdraw-api/design-memory.js.map +1 -0
- package/dist/pairdraw-api/index.d.ts +45 -1
- package/dist/pairdraw-api/index.d.ts.map +1 -1
- package/dist/pairdraw-api/index.js +55 -2
- package/dist/pairdraw-api/index.js.map +1 -1
- package/dist/pairdraw-api/nodes.d.ts +12 -1
- package/dist/pairdraw-api/nodes.d.ts.map +1 -1
- package/dist/pairdraw-api/nodes.js +28 -1
- package/dist/pairdraw-api/nodes.js.map +1 -1
- package/dist/pairdraw-api/variations.d.ts +48 -0
- package/dist/pairdraw-api/variations.d.ts.map +1 -0
- package/dist/pairdraw-api/variations.js +76 -0
- package/dist/pairdraw-api/variations.js.map +1 -0
- package/dist/prototype/easing.d.ts +13 -0
- package/dist/prototype/easing.d.ts.map +1 -0
- package/dist/prototype/easing.js +36 -0
- package/dist/prototype/easing.js.map +1 -0
- package/dist/prototype/frames.d.ts +10 -0
- package/dist/prototype/frames.d.ts.map +1 -0
- package/dist/prototype/frames.js +12 -0
- package/dist/prototype/frames.js.map +1 -0
- package/dist/prototype/hit.d.ts +17 -0
- package/dist/prototype/hit.d.ts.map +1 -0
- package/dist/prototype/hit.js +45 -0
- package/dist/prototype/hit.js.map +1 -0
- package/dist/prototype/index.d.ts +14 -0
- package/dist/prototype/index.js +14 -0
- package/dist/prototype/pointer.d.ts +63 -0
- package/dist/prototype/pointer.d.ts.map +1 -0
- package/dist/prototype/pointer.js +104 -0
- package/dist/prototype/pointer.js.map +1 -0
- package/dist/prototype/reactions.d.ts +45 -0
- package/dist/prototype/reactions.d.ts.map +1 -0
- package/dist/prototype/reactions.js +122 -0
- package/dist/prototype/reactions.js.map +1 -0
- package/dist/prototype/scene.d.ts +35 -0
- package/dist/prototype/scene.d.ts.map +1 -0
- package/dist/prototype/scene.js +86 -0
- package/dist/prototype/scene.js.map +1 -0
- package/dist/prototype/scenes.d.ts +81 -0
- package/dist/prototype/scenes.d.ts.map +1 -0
- package/dist/prototype/scenes.js +175 -0
- package/dist/prototype/scenes.js.map +1 -0
- package/dist/prototype/scroll.d.ts +48 -0
- package/dist/prototype/scroll.d.ts.map +1 -0
- package/dist/prototype/scroll.js +159 -0
- package/dist/prototype/scroll.js.map +1 -0
- package/dist/prototype/session.d.ts +71 -0
- package/dist/prototype/session.d.ts.map +1 -0
- package/dist/prototype/session.js +135 -0
- package/dist/prototype/session.js.map +1 -0
- package/dist/prototype/smart-animate/animation.d.ts +34 -0
- package/dist/prototype/smart-animate/animation.d.ts.map +1 -0
- package/dist/prototype/smart-animate/animation.js +212 -0
- package/dist/prototype/smart-animate/animation.js.map +1 -0
- package/dist/prototype/smart-animate/match.d.ts +24 -0
- package/dist/prototype/smart-animate/match.d.ts.map +1 -0
- package/dist/prototype/smart-animate/match.js +72 -0
- package/dist/prototype/smart-animate/match.js.map +1 -0
- package/dist/prototype/snapshot.d.ts +19 -0
- package/dist/prototype/snapshot.d.ts.map +1 -0
- package/dist/prototype/snapshot.js +56 -0
- package/dist/prototype/snapshot.js.map +1 -0
- package/dist/prototype/timeline.d.ts +132 -0
- package/dist/prototype/timeline.d.ts.map +1 -0
- package/dist/prototype/timeline.js +260 -0
- package/dist/prototype/timeline.js.map +1 -0
- package/dist/rpc/read-commands.js +1 -1
- package/dist/text/font/features.d.ts +9 -0
- package/dist/text/font/features.d.ts.map +1 -0
- package/dist/text/font/features.js +27 -0
- package/dist/text/font/features.js.map +1 -0
- package/dist/text/font/manager.d.ts +12 -0
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +60 -1
- package/dist/text/font/manager.js.map +1 -1
- package/dist/text/index.d.ts +10 -8
- package/dist/text/index.js +3 -1
- package/dist/text/replace-fonts.d.ts +41 -0
- package/dist/text/replace-fonts.d.ts.map +1 -0
- package/dist/text/replace-fonts.js +121 -0
- package/dist/text/replace-fonts.js.map +1 -0
- package/dist/tools/analyze/responsive/index.d.ts +15 -0
- package/dist/tools/analyze/responsive/index.d.ts.map +1 -0
- package/dist/tools/analyze/responsive/index.js +203 -0
- package/dist/tools/analyze/responsive/index.js.map +1 -0
- package/dist/tools/analyze.d.ts +2 -1
- package/dist/tools/analyze.js +2 -1
- package/dist/tools/codegen/token-sync.d.ts +7 -0
- package/dist/tools/codegen/token-sync.d.ts.map +1 -0
- package/dist/tools/codegen/token-sync.js +85 -0
- package/dist/tools/codegen/token-sync.js.map +1 -0
- package/dist/tools/codegen/tokens.d.ts +1 -1
- package/dist/tools/codegen.d.ts +2 -1
- package/dist/tools/codegen.js +2 -1
- package/dist/tools/create/basic.js +1 -1
- package/dist/tools/create/behaviours.js +1 -1
- package/dist/tools/create/components.d.ts.map +1 -1
- package/dist/tools/create/components.js +4 -0
- package/dist/tools/create/components.js.map +1 -1
- package/dist/tools/create/html.js +3 -2
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.d.ts.map +1 -1
- package/dist/tools/create/icons.js +2 -1
- package/dist/tools/create/icons.js.map +1 -1
- package/dist/tools/create/mermaid.js +2 -1
- package/dist/tools/create/mermaid.js.map +1 -1
- package/dist/tools/create/render.js +1 -1
- package/dist/tools/create/svg.js +2 -1
- package/dist/tools/create/svg.js.map +1 -1
- package/dist/tools/create/vector.js +1 -1
- package/dist/tools/design-memory.d.ts +8 -0
- package/dist/tools/design-memory.d.ts.map +1 -0
- package/dist/tools/design-memory.js +68 -0
- package/dist/tools/design-memory.js.map +1 -0
- package/dist/tools/image-ai/generate.d.ts.map +1 -1
- package/dist/tools/image-ai/generate.js +3 -1
- package/dist/tools/image-ai/generate.js.map +1 -1
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.js +2 -1
- package/dist/tools/modify/fonts.d.ts +6 -0
- package/dist/tools/modify/fonts.d.ts.map +1 -0
- package/dist/tools/modify/fonts.js +27 -0
- package/dist/tools/modify/fonts.js.map +1 -0
- package/dist/tools/modify/paint.js +1 -1
- package/dist/tools/modify/reactions.d.ts.map +1 -1
- package/dist/tools/modify/reactions.js +3 -3
- 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 +26 -5
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/modify/update.d.ts +10 -1
- package/dist/tools/modify/update.d.ts.map +1 -1
- package/dist/tools/modify/update.js +34 -3
- package/dist/tools/modify/update.js.map +1 -1
- package/dist/tools/modify.d.ts +2 -1
- package/dist/tools/modify.js +2 -1
- package/dist/tools/read/fonts.d.ts.map +1 -1
- package/dist/tools/read/fonts.js +17 -2
- package/dist/tools/read/fonts.js.map +1 -1
- package/dist/tools/read/libraries.js +2 -1
- package/dist/tools/read/libraries.js.map +1 -1
- package/dist/tools/read/space.d.ts +3 -1
- package/dist/tools/read/space.d.ts.map +1 -1
- package/dist/tools/read/space.js +4 -3
- package/dist/tools/read/space.js.map +1 -1
- package/dist/tools/registry/core.d.ts +1 -1
- package/dist/tools/registry/core.d.ts.map +1 -1
- package/dist/tools/registry/core.js +3 -1
- package/dist/tools/registry/core.js.map +1 -1
- package/dist/tools/registry/extended.d.ts.map +1 -1
- package/dist/tools/registry/extended.js +16 -1
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/schema.d.ts +18 -2
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +1 -1
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/stock-photo.js +1 -0
- package/dist/tools/stock-photo.js.map +1 -1
- package/dist/tools/structure/basic.d.ts.map +1 -1
- package/dist/tools/structure/basic.js +1 -0
- package/dist/tools/structure/basic.js.map +1 -1
- package/dist/tools/structure/batch.d.ts.map +1 -1
- package/dist/tools/structure/batch.js +8 -1
- package/dist/tools/structure/batch.js.map +1 -1
- package/dist/tools/structure/hierarchy.d.ts.map +1 -1
- package/dist/tools/structure/hierarchy.js +4 -0
- package/dist/tools/structure/hierarchy.js.map +1 -1
- package/dist/tools/structure/variations.d.ts +8 -0
- package/dist/tools/structure/variations.d.ts.map +1 -0
- package/dist/tools/structure/variations.js +106 -0
- package/dist/tools/structure/variations.js.map +1 -0
- package/dist/tools/structure.d.ts +2 -1
- package/dist/tools/structure.js +2 -1
- package/dist/tools/styles/types.d.ts +2 -4
- package/dist/tools/styles/types.d.ts.map +1 -1
- package/dist/tools/styles/types.js.map +1 -1
- package/dist/tools/vector/boolean.d.ts.map +1 -1
- package/dist/tools/vector/boolean.js +4 -0
- package/dist/tools/vector/boolean.js.map +1 -1
- package/dist/tools/vector/vectorize.js +1 -0
- package/dist/tools/vector/vectorize.js.map +1 -1
- package/dist/tools/vector/video.d.ts +6 -0
- package/dist/tools/vector/video.d.ts.map +1 -0
- package/dist/tools/vector/video.js +133 -0
- package/dist/tools/vector/video.js.map +1 -0
- package/dist/tools/vector.d.ts +2 -1
- package/dist/tools/vector.js +2 -1
- package/dist/tools/video-host.d.ts +12 -0
- package/dist/tools/video-host.d.ts.map +1 -0
- package/dist/tools/video-host.js +19 -0
- package/dist/tools/video-host.js.map +1 -0
- package/dist/vector/point-transform.d.ts +1 -1
- package/dist/vector/vectorize/svg/to-vectors.d.ts +1 -1
- package/package.json +31 -9
- package/src/ai/providers.ts +2 -0
- package/src/cache/resource.ts +24 -1
- package/src/canvas/effects.ts +47 -50
- package/src/canvas/fills.ts +19 -15
- package/src/canvas/images/adjustments.ts +203 -0
- package/src/canvas/images/sampling.ts +88 -0
- package/src/canvas/index.ts +1 -0
- package/src/canvas/masks.ts +1 -1
- package/src/canvas/noise/render.ts +75 -0
- package/src/canvas/noise/shader.ts +161 -0
- package/src/canvas/noise/table.ts +91 -0
- package/src/canvas/noise/tile.ts +94 -0
- package/src/canvas/overlays/auto-layout-hover.ts +47 -65
- package/src/canvas/renderer/lifecycle.ts +6 -0
- package/src/canvas/renderer/pipeline.ts +19 -1
- package/src/canvas/renderer/play-scenes.ts +51 -0
- package/src/canvas/renderer/tiles/cache.ts +54 -1
- package/src/canvas/renderer/tiles/controller.ts +30 -1
- package/src/canvas/renderer/types.ts +18 -2
- package/src/canvas/renderer.ts +40 -3
- package/src/canvas/scene.ts +65 -9
- package/src/canvas/texture.ts +136 -0
- package/src/clipboard.ts +23 -10
- package/src/constants.ts +6 -0
- package/src/design-memory/check.ts +376 -0
- package/src/design-memory/describe.ts +77 -0
- package/src/design-memory/distil.ts +69 -0
- package/src/design-memory/document.ts +80 -0
- package/src/design-memory/guard.ts +157 -0
- package/src/design-memory/index.ts +8 -0
- package/src/design-memory/refusal.ts +90 -0
- package/src/design-memory/rules.ts +274 -0
- package/src/design-memory/values.ts +179 -0
- package/src/editor/bridges/components.ts +2 -0
- package/src/editor/clipboard/export.ts +24 -7
- package/src/editor/components/instances.ts +31 -0
- package/src/editor/create.ts +25 -69
- package/src/editor/design-memory.ts +39 -0
- package/src/editor/design-tokens.ts +41 -2
- package/src/editor/document-colors.ts +65 -0
- package/src/editor/eyedropper.ts +198 -0
- package/src/editor/fonts.ts +19 -0
- package/src/editor/history/atomic-tool.ts +29 -1
- package/src/editor/history/capture.ts +19 -0
- package/src/editor/history/document-change.ts +5 -17
- package/src/editor/history/edit.ts +11 -1
- package/src/editor/history/subtree.ts +13 -2
- package/src/editor/index.ts +11 -0
- package/src/editor/pages.ts +40 -29
- package/src/editor/play/states.ts +1 -1
- package/src/editor/read-only/actions.ts +4 -0
- package/src/editor/render-requests.ts +83 -0
- package/src/editor/selection/overlays.ts +1 -0
- package/src/editor/tool-registry.ts +2 -1
- package/src/editor/types.ts +4 -0
- package/src/editor/variations/create.ts +235 -0
- package/src/editor/variations/pick.ts +35 -0
- package/src/editor/variations.ts +110 -0
- package/src/figma-api/accessors/reactions.ts +11 -1
- package/src/figma-api/accessors/text/index.ts +7 -0
- package/src/figma-api/accessors/text/opentype.ts +33 -0
- package/src/figma-api/accessors/visual.ts +55 -2
- package/src/figma-api/compatibility.ts +5 -2
- package/src/figma-api/effects.ts +143 -5
- package/src/figma-api/index.ts +10 -0
- package/src/figma-api/overrides.ts +295 -3
- package/src/figma-api/paints.ts +24 -9
- package/src/figma-api/proxy.ts +6 -1
- package/src/figma-api/reactions.ts +130 -32
- package/src/figma-api/surface.ts +6 -2
- package/src/global.d.ts +26 -0
- package/src/io/formats/boolean-path.ts +60 -0
- package/src/io/formats/design-tokens/index.ts +21 -0
- package/src/io/formats/design-tokens/plan/changes.ts +4 -1
- package/src/io/formats/design-tokens/project.ts +40 -9
- package/src/io/formats/design-tokens/styles.ts +10 -2
- package/src/io/formats/design-tokens/sync/apply.ts +130 -0
- package/src/io/formats/design-tokens/sync/drift.ts +587 -0
- package/src/io/formats/design-tokens/sync/files.ts +40 -0
- package/src/io/formats/drawio/edges.ts +65 -0
- package/src/io/formats/drawio/export.ts +37 -14
- package/src/io/formats/drawio/index.ts +2 -0
- package/src/io/formats/fig/export/patch/index.ts +8 -0
- package/src/io/formats/fig/thumbnail-page.ts +4 -4
- package/src/io/formats/html/import.ts +9 -1
- package/src/io/formats/html/index.ts +14 -7
- package/src/io/formats/html/vectors.ts +8 -2
- package/src/io/formats/pdf/document.ts +14 -4
- package/src/io/formats/pen/imports.ts +5 -6
- package/src/io/formats/pen/index.ts +36 -5
- package/src/io/formats/raster/adjusted-images.ts +125 -0
- package/src/io/formats/raster/headless.ts +3 -3
- package/src/io/formats/raster/index.ts +6 -1
- package/src/io/formats/raster/pixels.ts +7 -0
- package/src/io/formats/raster/render.ts +12 -1
- package/src/io/formats/svg/defs.ts +4 -72
- package/src/io/formats/svg/effects.ts +131 -0
- package/src/io/formats/svg/export.ts +278 -46
- package/src/io/formats/svg/filter.ts +47 -0
- package/src/io/formats/svg/grain.ts +249 -0
- package/src/io/formats/svg/strokes.ts +2 -2
- package/src/io/formats/svg/text/layout.ts +13 -3
- package/src/io/formats/video/composite.ts +79 -0
- package/src/io/formats/video/formats.ts +77 -0
- package/src/io/formats/video/gif.ts +65 -0
- package/src/io/formats/video/index.ts +30 -0
- package/src/io/formats/video/plan.ts +116 -0
- package/src/io/formats/video/record.ts +227 -0
- package/src/io/formats/video/sink.ts +32 -0
- package/src/io/formats/video/size.ts +25 -0
- package/src/io/formats/video/webcodecs.ts +89 -0
- package/src/io/formats.ts +59 -11
- package/src/io/types.ts +29 -10
- package/src/layout/auto-layout-handles.ts +396 -0
- package/src/layout.ts +2 -0
- package/src/lint/fixes.ts +12 -3
- package/src/lint/index.ts +3 -1
- package/src/lint/linter.ts +107 -10
- package/src/lint/presets.ts +2 -0
- package/src/lint/rules/design-memory.ts +97 -0
- package/src/lint/rules/index.ts +6 -1
- package/src/lint/rules/no-unbound-token-values.ts +73 -0
- package/src/lint/types.ts +32 -0
- package/src/node/video.ts +196 -0
- package/src/pairdraw-api/design-memory.ts +61 -0
- package/src/pairdraw-api/index.ts +81 -0
- package/src/pairdraw-api/nodes.ts +38 -0
- package/src/pairdraw-api/variations.ts +109 -0
- package/src/prototype/easing.ts +37 -0
- package/src/prototype/frames.ts +9 -0
- package/src/prototype/hit.ts +70 -0
- package/src/prototype/index.ts +69 -0
- package/src/prototype/pointer.ts +146 -0
- package/src/prototype/reactions.ts +178 -0
- package/src/prototype/scene.ts +116 -0
- package/src/prototype/scenes.ts +256 -0
- package/src/prototype/scroll.ts +190 -0
- package/src/prototype/session.ts +188 -0
- package/src/prototype/smart-animate/animation.ts +267 -0
- package/src/prototype/smart-animate/match.ts +85 -0
- package/src/prototype/snapshot.ts +60 -0
- package/src/prototype/timeline.ts +400 -0
- package/src/text/font/features.ts +27 -0
- package/src/text/font/manager.ts +79 -1
- package/src/text/index.ts +2 -0
- package/src/text/replace-fonts.ts +171 -0
- package/src/tools/analyze/responsive/index.ts +264 -0
- package/src/tools/analyze.ts +2 -0
- package/src/tools/codegen/token-sync.ts +98 -0
- package/src/tools/codegen.ts +1 -0
- package/src/tools/create/components.ts +4 -0
- package/src/tools/create/html.ts +1 -0
- package/src/tools/create/icons.ts +1 -0
- package/src/tools/create/mermaid.ts +1 -0
- package/src/tools/create/svg.ts +1 -0
- package/src/tools/design-memory.ts +72 -0
- package/src/tools/image-ai/generate.ts +2 -0
- package/src/tools/index.ts +1 -0
- package/src/tools/modify/fonts.ts +34 -0
- package/src/tools/modify/reactions.ts +15 -8
- package/src/tools/modify/text.ts +42 -5
- package/src/tools/modify/update.ts +46 -2
- package/src/tools/modify.ts +1 -0
- package/src/tools/read/fonts.ts +24 -2
- package/src/tools/read/libraries.ts +1 -0
- package/src/tools/read/space.ts +3 -2
- package/src/tools/registry/core.ts +3 -1
- package/src/tools/registry/extended.ts +28 -1
- package/src/tools/schema.ts +28 -4
- package/src/tools/stock-photo.ts +1 -0
- package/src/tools/structure/basic.ts +1 -0
- package/src/tools/structure/batch.ts +12 -1
- package/src/tools/structure/hierarchy.ts +4 -0
- package/src/tools/structure/variations.ts +118 -0
- package/src/tools/structure.ts +2 -0
- package/src/tools/styles/types.ts +3 -4
- package/src/tools/vector/boolean.ts +4 -0
- package/src/tools/vector/vectorize.ts +1 -0
- package/src/tools/vector/video.ts +228 -0
- package/src/tools/vector.ts +1 -0
- package/src/tools/video-host.ts +18 -0
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
import "../../../canvas/index.js";
|
|
2
|
+
import { SkiaRenderer } from "../../../canvas/renderer.js";
|
|
1
3
|
import { ExportFormat, RasterExportFormat } from "./render.js";
|
|
2
4
|
import { CanvasKit } from "canvaskit-wasm";
|
|
3
5
|
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
4
6
|
//#region src/io/formats/raster/headless.d.ts
|
|
5
7
|
declare function initCanvasKit(): Promise<CanvasKit>;
|
|
8
|
+
/**
|
|
9
|
+
* The offscreen renderer for `canvasKit`, made on first use. A browser host passes the build its
|
|
10
|
+
* canvas already uses; without one the export renderer loads its own.
|
|
11
|
+
*/
|
|
12
|
+
declare function headlessRenderer(canvasKit?: CanvasKit): Promise<{
|
|
13
|
+
ck: CanvasKit;
|
|
14
|
+
renderer: SkiaRenderer;
|
|
15
|
+
}>;
|
|
6
16
|
declare function headlessRenderNodes(graph: SceneGraph, pageId: string, nodeIds: string[], options?: {
|
|
7
17
|
scale?: number;
|
|
8
18
|
format?: ExportFormat;
|
|
@@ -11,5 +21,5 @@ declare function headlessRenderNodes(graph: SceneGraph, pageId: string, nodeIds:
|
|
|
11
21
|
}, canvasKit?: CanvasKit): Promise<Uint8Array<ArrayBuffer> | null>;
|
|
12
22
|
declare function headlessRenderThumbnail(graph: SceneGraph, pageId: string, width: number, height: number, format?: RasterExportFormat, quality?: number, canvasKit?: CanvasKit): Promise<Uint8Array<ArrayBuffer> | null>;
|
|
13
23
|
//#endregion
|
|
14
|
-
export { headlessRenderNodes, headlessRenderThumbnail, initCanvasKit };
|
|
24
|
+
export { headlessRenderNodes, headlessRenderThumbnail, headlessRenderer, initCanvasKit };
|
|
15
25
|
//# sourceMappingURL=headless.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headless.d.ts","names":[],"sources":["../../../../src/io/formats/raster/headless.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"headless.d.ts","names":[],"sources":["../../../../src/io/formats/raster/headless.ts"],"mappings":";;;;;;iBAiBsB,iBAAiB,QAAQ;;;;;iBAyBzB,iBACpB,YAAY,YACX;EAAU,IAAI;EAAW,UAAU;;iBAahB,oBACpB,OAAO,YACP,gBACA,mBACA;EACE;EACA,SAAS;EACT;EACA;GAEF,YAAY,YACX,QAAQ,WAAW;iBAYA,wBACpB,OAAO,YACP,gBACA,eACA,gBACA,SAAQ,oBACR,kBACA,YAAY,YACX,QAAQ,WAAW"}
|
|
@@ -25,7 +25,7 @@ async function createRenderer(ck) {
|
|
|
25
25
|
* The offscreen renderer for `canvasKit`, made on first use. A browser host passes the build its
|
|
26
26
|
* canvas already uses; without one the export renderer loads its own.
|
|
27
27
|
*/
|
|
28
|
-
async function
|
|
28
|
+
async function headlessRenderer(canvasKit) {
|
|
29
29
|
const ck = canvasKit ?? await initCanvasKit();
|
|
30
30
|
let pending = renderers.get(ck);
|
|
31
31
|
if (!pending) {
|
|
@@ -41,7 +41,7 @@ async function getRenderer(canvasKit) {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
async function headlessRenderNodes(graph, pageId, nodeIds, options = {}, canvasKit) {
|
|
44
|
-
const { ck, renderer } = await
|
|
44
|
+
const { ck, renderer } = await headlessRenderer(canvasKit);
|
|
45
45
|
renderer.invalidateAllPictures();
|
|
46
46
|
await renderer.prepareForExport(graph, pageId, nodeIds);
|
|
47
47
|
return renderNodesToImage(ck, renderer, graph, pageId, nodeIds, {
|
|
@@ -52,12 +52,12 @@ async function headlessRenderNodes(graph, pageId, nodeIds, options = {}, canvasK
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
async function headlessRenderThumbnail(graph, pageId, width, height, format = "PNG", quality = 100, canvasKit) {
|
|
55
|
-
const { ck, renderer } = await
|
|
55
|
+
const { ck, renderer } = await headlessRenderer(canvasKit);
|
|
56
56
|
renderer.invalidateAllPictures();
|
|
57
57
|
await renderer.prepareForExport(graph, pageId, graph.getNode(pageId)?.childIds ?? []);
|
|
58
58
|
return renderThumbnail(ck, renderer, graph, pageId, width, height, format, quality);
|
|
59
59
|
}
|
|
60
60
|
//#endregion
|
|
61
|
-
export { headlessRenderNodes, headlessRenderThumbnail, initCanvasKit };
|
|
61
|
+
export { headlessRenderNodes, headlessRenderThumbnail, headlessRenderer, initCanvasKit };
|
|
62
62
|
|
|
63
63
|
//# sourceMappingURL=headless.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headless.js","names":[],"sources":["../../../../src/io/formats/raster/headless.ts"],"sourcesContent":["import type { CanvasKit } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { SkiaRenderer } from '#core/canvas'\n\nimport {\n renderNodesToImage,\n renderThumbnail,\n type ExportFormat,\n type RasterExportFormat\n} from './render'\n\nlet cachedCk: CanvasKit | null = null\n/** One offscreen renderer per CanvasKit: the CLI's own, and the app's build when it passes one. */\nconst renderers = new WeakMap<CanvasKit, Promise<SkiaRenderer>>()\n\nexport async function initCanvasKit(): Promise<CanvasKit> {\n if (cachedCk) return cachedCk\n const CanvasKitInit = (await import('canvaskit-wasm/full')).default\n const ckURL = import.meta.resolve('canvaskit-wasm/full')\n cachedCk = await CanvasKitInit({\n locateFile: (file: string) => new URL(file, ckURL).href\n })\n return cachedCk\n}\n\nasync function createRenderer(ck: CanvasKit): Promise<SkiaRenderer> {\n const surface = ck.MakeSurface(1, 1)\n if (!surface) throw new Error('Failed to create CanvasKit surface')\n const renderer = new SkiaRenderer(ck, surface)\n renderer.viewportWidth = 1\n renderer.viewportHeight = 1\n renderer.dpr = 1\n await renderer.loadFonts()\n return renderer\n}\n\n/**\n * The offscreen renderer for `canvasKit`, made on first use. A browser host passes the build its\n * canvas already uses; without one the export renderer loads its own.\n */\
|
|
1
|
+
{"version":3,"file":"headless.js","names":[],"sources":["../../../../src/io/formats/raster/headless.ts"],"sourcesContent":["import type { CanvasKit } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { SkiaRenderer } from '#core/canvas'\n\nimport {\n renderNodesToImage,\n renderThumbnail,\n type ExportFormat,\n type RasterExportFormat\n} from './render'\n\nlet cachedCk: CanvasKit | null = null\n/** One offscreen renderer per CanvasKit: the CLI's own, and the app's build when it passes one. */\nconst renderers = new WeakMap<CanvasKit, Promise<SkiaRenderer>>()\n\nexport async function initCanvasKit(): Promise<CanvasKit> {\n if (cachedCk) return cachedCk\n const CanvasKitInit = (await import('canvaskit-wasm/full')).default\n const ckURL = import.meta.resolve('canvaskit-wasm/full')\n cachedCk = await CanvasKitInit({\n locateFile: (file: string) => new URL(file, ckURL).href\n })\n return cachedCk\n}\n\nasync function createRenderer(ck: CanvasKit): Promise<SkiaRenderer> {\n const surface = ck.MakeSurface(1, 1)\n if (!surface) throw new Error('Failed to create CanvasKit surface')\n const renderer = new SkiaRenderer(ck, surface)\n renderer.viewportWidth = 1\n renderer.viewportHeight = 1\n renderer.dpr = 1\n await renderer.loadFonts()\n return renderer\n}\n\n/**\n * The offscreen renderer for `canvasKit`, made on first use. A browser host passes the build its\n * canvas already uses; without one the export renderer loads its own.\n */\nexport async function headlessRenderer(\n canvasKit?: CanvasKit\n): Promise<{ ck: CanvasKit; renderer: SkiaRenderer }> {\n const ck = canvasKit ?? (await initCanvasKit())\n let pending = renderers.get(ck)\n if (!pending) {\n pending = createRenderer(ck)\n renderers.set(ck, pending)\n pending.catch(() => {\n if (renderers.get(ck) === pending) renderers.delete(ck)\n })\n }\n return { ck, renderer: await pending }\n}\n\nexport async function headlessRenderNodes(\n graph: SceneGraph,\n pageId: string,\n nodeIds: string[],\n options: {\n scale?: number\n format?: ExportFormat\n quality?: number\n trimTransparent?: boolean\n } = {},\n canvasKit?: CanvasKit\n): Promise<Uint8Array<ArrayBuffer> | null> {\n const { ck, renderer } = await headlessRenderer(canvasKit)\n renderer.invalidateAllPictures()\n await renderer.prepareForExport(graph, pageId, nodeIds)\n return renderNodesToImage(ck, renderer, graph, pageId, nodeIds, {\n scale: options.scale ?? 1,\n format: options.format ?? 'PNG',\n quality: options.quality,\n trimTransparent: options.trimTransparent\n })\n}\n\nexport async function headlessRenderThumbnail(\n graph: SceneGraph,\n pageId: string,\n width: number,\n height: number,\n format: RasterExportFormat = 'PNG',\n quality = 100,\n canvasKit?: CanvasKit\n): Promise<Uint8Array<ArrayBuffer> | null> {\n const { ck, renderer } = await headlessRenderer(canvasKit)\n renderer.invalidateAllPictures()\n await renderer.prepareForExport(graph, pageId, graph.getNode(pageId)?.childIds ?? [])\n return renderThumbnail(ck, renderer, graph, pageId, width, height, format, quality)\n}\n"],"mappings":";;;AAaA,IAAI,WAA6B;;AAEjC,MAAM,4BAAY,IAAI,QAA0C;AAEhE,eAAsB,gBAAoC;CACxD,IAAI,UAAU,OAAO;CACrB,MAAM,iBAAiB,MAAM,OAAO,uBAAA,CAAwB;CAC5D,MAAM,QAAQ,YAAY,QAAQ,qBAAqB;CACvD,WAAW,MAAM,cAAc,EAC7B,aAAa,SAAiB,IAAI,IAAI,MAAM,KAAK,CAAC,CAAC,KACrD,CAAC;CACD,OAAO;AACT;AAEA,eAAe,eAAe,IAAsC;CAClE,MAAM,UAAU,GAAG,YAAY,GAAG,CAAC;CACnC,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,oCAAoC;CAClE,MAAM,WAAW,IAAI,aAAa,IAAI,OAAO;CAC7C,SAAS,gBAAgB;CACzB,SAAS,iBAAiB;CAC1B,SAAS,MAAM;CACf,MAAM,SAAS,UAAU;CACzB,OAAO;AACT;;;;;AAMA,eAAsB,iBACpB,WACoD;CACpD,MAAM,KAAK,aAAc,MAAM,cAAc;CAC7C,IAAI,UAAU,UAAU,IAAI,EAAE;CAC9B,IAAI,CAAC,SAAS;EACZ,UAAU,eAAe,EAAE;EAC3B,UAAU,IAAI,IAAI,OAAO;EACzB,QAAQ,YAAY;GAClB,IAAI,UAAU,IAAI,EAAE,MAAM,SAAS,UAAU,OAAO,EAAE;EACxD,CAAC;CACH;CACA,OAAO;EAAE;EAAI,UAAU,MAAM;CAAQ;AACvC;AAEA,eAAsB,oBACpB,OACA,QACA,SACA,UAKI,CAAC,GACL,WACyC;CACzC,MAAM,EAAE,IAAI,aAAa,MAAM,iBAAiB,SAAS;CACzD,SAAS,sBAAsB;CAC/B,MAAM,SAAS,iBAAiB,OAAO,QAAQ,OAAO;CACtD,OAAO,mBAAmB,IAAI,UAAU,OAAO,QAAQ,SAAS;EAC9D,OAAO,QAAQ,SAAS;EACxB,QAAQ,QAAQ,UAAU;EAC1B,SAAS,QAAQ;EACjB,iBAAiB,QAAQ;CAC3B,CAAC;AACH;AAEA,eAAsB,wBACpB,OACA,QACA,OACA,QACA,SAA6B,OAC7B,UAAU,KACV,WACyC;CACzC,MAAM,EAAE,IAAI,aAAa,MAAM,iBAAiB,SAAS;CACzD,SAAS,sBAAsB;CAC/B,MAAM,SAAS,iBAAiB,OAAO,QAAQ,MAAM,QAAQ,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC;CACpF,OAAO,gBAAgB,IAAI,UAAU,OAAO,QAAQ,OAAO,QAAQ,QAAQ,OAAO;AACpF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExportFormat, MAX_EXPORT_PIXELS, RasterExportFormat, ThumbnailFrame, assertExportSize, computeContentBounds, exportRenderScale, renderNodesToImage, renderThumbnail, thumbnailFrame } from "./render.js";
|
|
2
2
|
import { headlessRenderNodes, headlessRenderThumbnail, initCanvasKit } from "./headless.js";
|
|
3
|
-
import { RGBAImage, RasterCodec, createCanvasKitRasterCodec } from "./pixels.js";
|
|
3
|
+
import { EncodedPNG, RGBAImage, RasterCodec, createCanvasKitRasterCodec } from "./pixels.js";
|
|
4
4
|
import { PixelComparison, PixelComparisonOptions, comparePNGs } from "./compare.js";
|
|
5
5
|
import { RegionRenderOptions, renderRegionToImage } from "./region.js";
|
|
6
|
-
export { type ExportFormat, MAX_EXPORT_PIXELS, type PixelComparison, type PixelComparisonOptions, type RGBAImage, type RasterCodec, type RasterExportFormat, type RegionRenderOptions, type ThumbnailFrame, assertExportSize, comparePNGs, computeContentBounds, createCanvasKitRasterCodec, exportRenderScale, headlessRenderNodes, headlessRenderThumbnail, initCanvasKit, renderNodesToImage, renderRegionToImage, renderThumbnail, thumbnailFrame };
|
|
6
|
+
export { type EncodedPNG, type ExportFormat, MAX_EXPORT_PIXELS, type PixelComparison, type PixelComparisonOptions, type RGBAImage, type RasterCodec, type RasterExportFormat, type RegionRenderOptions, type ThumbnailFrame, assertExportSize, comparePNGs, computeContentBounds, createCanvasKitRasterCodec, exportRenderScale, headlessRenderNodes, headlessRenderThumbnail, initCanvasKit, renderNodesToImage, renderRegionToImage, renderThumbnail, thumbnailFrame };
|
|
@@ -6,6 +6,12 @@ interface RGBAImage {
|
|
|
6
6
|
height: number;
|
|
7
7
|
data: Uint8Array;
|
|
8
8
|
}
|
|
9
|
+
/** A PNG's bytes and the size they were drawn at. */
|
|
10
|
+
interface EncodedPNG {
|
|
11
|
+
png: Uint8Array;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
9
15
|
/** Decode and encode raster images for pixel-level tools; backed by CanvasKit in app and CLI. */
|
|
10
16
|
interface RasterCodec {
|
|
11
17
|
decode(bytes: Uint8Array): RGBAImage | null;
|
|
@@ -13,5 +19,5 @@ interface RasterCodec {
|
|
|
13
19
|
}
|
|
14
20
|
declare function createCanvasKitRasterCodec(ck: CanvasKit): RasterCodec;
|
|
15
21
|
//#endregion
|
|
16
|
-
export { RGBAImage, RasterCodec, createCanvasKitRasterCodec };
|
|
22
|
+
export { EncodedPNG, RGBAImage, RasterCodec, createCanvasKitRasterCodec };
|
|
17
23
|
//# sourceMappingURL=pixels.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pixels.d.ts","names":[],"sources":["../../../../src/io/formats/raster/pixels.ts"],"mappings":";;;UAGiB;EACf;EACA;EACA,MAAM;;;UAIS;EACf,OAAO,OAAO,aAAa;EAC3B,UAAU,OAAO,YAAY;;iBAGf,2BAA2B,IAAI,YAAY"}
|
|
1
|
+
{"version":3,"file":"pixels.d.ts","names":[],"sources":["../../../../src/io/formats/raster/pixels.ts"],"mappings":";;;UAGiB;EACf;EACA;EACA,MAAM;;;UAIS;EACf,KAAK;EACL;EACA;;;UAIe;EACf,OAAO,OAAO,aAAa;EAC3B,UAAU,OAAO,YAAY;;iBAGf,2BAA2B,IAAI,YAAY"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pixels.js","names":[],"sources":["../../../../src/io/formats/raster/pixels.ts"],"sourcesContent":["import type { CanvasKit } from 'canvaskit-wasm'\n\n/** Unpremultiplied sRGB RGBA pixels, row-major with no padding. */\nexport interface RGBAImage {\n width: number\n height: number\n data: Uint8Array\n}\n\n/** Decode and encode raster images for pixel-level tools; backed by CanvasKit in app and CLI. */\nexport interface RasterCodec {\n decode(bytes: Uint8Array): RGBAImage | null\n encodePNG(image: RGBAImage): Uint8Array | null\n}\n\nexport function createCanvasKitRasterCodec(ck: CanvasKit): RasterCodec {\n const info = (width: number, height: number) => ({\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width,\n height\n })\n\n return {\n decode(bytes) {\n const image = ck.MakeImageFromEncoded(bytes)\n if (!image) return null\n try {\n const width = image.width()\n const height = image.height()\n const pixels = image.readPixels(0, 0, info(width, height))\n // RGBA_8888 always reads back as bytes.\n if (!(pixels instanceof Uint8Array)) return null\n return { width, height, data: pixels }\n } finally {\n image.delete()\n }\n },\n encodePNG({ width, height, data }) {\n const image = ck.MakeImage(info(width, height), data, width * 4)\n if (!image) return null\n try {\n const encoded = image.encodeToBytes(ck.ImageFormat.PNG, 100)\n return encoded ? new Uint8Array(encoded) : null\n } finally {\n image.delete()\n }\n }\n }\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"pixels.js","names":[],"sources":["../../../../src/io/formats/raster/pixels.ts"],"sourcesContent":["import type { CanvasKit } from 'canvaskit-wasm'\n\n/** Unpremultiplied sRGB RGBA pixels, row-major with no padding. */\nexport interface RGBAImage {\n width: number\n height: number\n data: Uint8Array\n}\n\n/** A PNG's bytes and the size they were drawn at. */\nexport interface EncodedPNG {\n png: Uint8Array\n width: number\n height: number\n}\n\n/** Decode and encode raster images for pixel-level tools; backed by CanvasKit in app and CLI. */\nexport interface RasterCodec {\n decode(bytes: Uint8Array): RGBAImage | null\n encodePNG(image: RGBAImage): Uint8Array | null\n}\n\nexport function createCanvasKitRasterCodec(ck: CanvasKit): RasterCodec {\n const info = (width: number, height: number) => ({\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width,\n height\n })\n\n return {\n decode(bytes) {\n const image = ck.MakeImageFromEncoded(bytes)\n if (!image) return null\n try {\n const width = image.width()\n const height = image.height()\n const pixels = image.readPixels(0, 0, info(width, height))\n // RGBA_8888 always reads back as bytes.\n if (!(pixels instanceof Uint8Array)) return null\n return { width, height, data: pixels }\n } finally {\n image.delete()\n }\n },\n encodePNG({ width, height, data }) {\n const image = ck.MakeImage(info(width, height), data, width * 4)\n if (!image) return null\n try {\n const encoded = image.encodeToBytes(ck.ImageFormat.PNG, 100)\n return encoded ? new Uint8Array(encoded) : null\n } finally {\n image.delete()\n }\n }\n }\n}\n"],"mappings":";AAsBA,SAAgB,2BAA2B,IAA4B;CACrE,MAAM,QAAQ,OAAe,YAAoB;EAC/C,WAAW,GAAG,UAAU;EACxB,WAAW,GAAG,UAAU;EACxB,YAAY,GAAG,WAAW;EAC1B;EACA;CACF;CAEA,OAAO;EACL,OAAO,OAAO;GACZ,MAAM,QAAQ,GAAG,qBAAqB,KAAK;GAC3C,IAAI,CAAC,OAAO,OAAO;GACnB,IAAI;IACF,MAAM,QAAQ,MAAM,MAAM;IAC1B,MAAM,SAAS,MAAM,OAAO;IAC5B,MAAM,SAAS,MAAM,WAAW,GAAG,GAAG,KAAK,OAAO,MAAM,CAAC;IAEzD,IAAI,EAAE,kBAAkB,aAAa,OAAO;IAC5C,OAAO;KAAE;KAAO;KAAQ,MAAM;IAAO;GACvC,UAAU;IACR,MAAM,OAAO;GACf;EACF;EACA,UAAU,EAAE,OAAO,QAAQ,QAAQ;GACjC,MAAM,QAAQ,GAAG,UAAU,KAAK,OAAO,MAAM,GAAG,MAAM,QAAQ,CAAC;GAC/D,IAAI,CAAC,OAAO,OAAO;GACnB,IAAI;IACF,MAAM,UAAU,MAAM,cAAc,GAAG,YAAY,KAAK,GAAG;IAC3D,OAAO,UAAU,IAAI,WAAW,OAAO,IAAI;GAC7C,UAAU;IACR,MAAM,OAAO;GACf;EACF;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","names":[],"sources":["../../../../src/io/formats/raster/render.ts"],"mappings":";;;;;;;KAaY;KACA,eAAe;UAEjB;EACR;EACA,QAAQ;EACR;EACA,aAAa;EACb;;;cAIW;;iBAKG,iBAAiB,eAAe;;iBAShC,kBAAkB,eAAe;iBAQjC,qBAAqB,OAAO,YAAY,oBAAiB;
|
|
1
|
+
{"version":3,"file":"render.d.ts","names":[],"sources":["../../../../src/io/formats/raster/render.ts"],"mappings":";;;;;;;KAaY;KACA,eAAe;UAEjB;EACR;EACA,QAAQ;EACR;EACA,aAAa;EACb;;;cAIW;;iBAKG,iBAAiB,eAAe;;iBAShC,kBAAkB,eAAe;iBAQjC,qBAAqB,OAAO,YAAY,oBAAiB;iBA4PzD,4BACd,QAAQ,YACR,aAAa,YACb,gBACA;iBA0Cc,mBACd,IAAI,WACJ,UAAU,cACV,OAAO,YACP,gBACA,mBACA,SAAS,gBACR,WAAW;UA0CG;;EAEf,QAAQ;EACR;;EAEA;EACA;;;iBAIc,eACd,OAAO,YACP,gBACA,eACA,iBACC;iBAoBa,gBACd,IAAI,WACJ,UAAU,cACV,OAAO,YACP,gBACA,eACA,gBACA,SAAQ,oBACR,mBACC,WAAW;;iBAeE,kBACd,IAAI,WACJ,UAAU,cACV,OAAO,YACP,gBACA,QAAQ,cACR,gBACC,WAAW"}
|
|
@@ -2,6 +2,7 @@ import { getPageColor } from "../../../figma-api/page-backgrounds.js";
|
|
|
2
2
|
import { extractExportGraph, findPageId } from "../../subgraph.js";
|
|
3
3
|
import { getWorldMatrix } from "@pairdraw/scene-graph/coordinate";
|
|
4
4
|
import { computeDescendantVisualBounds } from "@pairdraw/scene-graph/geometry";
|
|
5
|
+
import Matrix from "@pairdraw/scene-graph/matrix";
|
|
5
6
|
import { resolvedVariableModes } from "@pairdraw/scene-graph/variables";
|
|
6
7
|
//#region src/io/formats/raster/render.ts
|
|
7
8
|
/** Pixels an export may hold before it is refused, keeping a large scale from aborting CanvasKit. */
|
|
@@ -94,10 +95,12 @@ function renderToSurface(ck, renderer, renderGraph, pageId, width, height, forma
|
|
|
94
95
|
ck.Free(pixels);
|
|
95
96
|
throw new Error(`Could not allocate a ${renderWidth}×${renderHeight} export surface.`);
|
|
96
97
|
}
|
|
98
|
+
const drawnFor = renderer.supersampledOutput;
|
|
97
99
|
try {
|
|
98
100
|
const canvas = surface.getCanvas();
|
|
99
101
|
canvas.scale(renderScale, renderScale);
|
|
100
102
|
setup(canvas);
|
|
103
|
+
renderer.supersampledOutput = renderScale > 1 ? { outputFromWorld: Matrix.multiply(Matrix.scaled(1 / renderScale, 1 / renderScale), canvas.getTotalMatrix()) } : null;
|
|
101
104
|
renderer.renderSceneToCanvas(canvas, renderGraph, pageId);
|
|
102
105
|
surface.flush();
|
|
103
106
|
const highResImage = surface.makeImageSnapshot();
|
|
@@ -153,6 +156,7 @@ function renderToSurface(ck, renderer, renderGraph, pageId, width, height, forma
|
|
|
153
156
|
ck.Free(downsamplePixels);
|
|
154
157
|
return resultBytes;
|
|
155
158
|
} finally {
|
|
159
|
+
renderer.supersampledOutput = drawnFor;
|
|
156
160
|
surface.dispose();
|
|
157
161
|
ck.Free(pixels);
|
|
158
162
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","names":[],"sources":["../../../../src/io/formats/raster/render.ts"],"sourcesContent":["import type { CanvasKit, Canvas, Image as CanvasImage } from 'canvaskit-wasm'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport type { RenderColorSpace } from '@pairdraw/scene-graph/color'\nimport { getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport { computeDescendantVisualBounds, type VisualBounds } from '@pairdraw/scene-graph/geometry'\nimport type { Mat3 } from '@pairdraw/scene-graph/matrix'\nimport { resolvedVariableModes } from '@pairdraw/scene-graph/variables'\n\nimport type { SkiaRenderer } from '#core/canvas'\nimport { getPageColor } from '#core/figma-api/page-backgrounds'\nimport { extractExportGraph, findPageId } from '#core/io/subgraph'\n\nexport type RasterExportFormat = 'PNG' | 'JPG' | 'WEBP'\nexport type ExportFormat = RasterExportFormat | 'SVG'\n\ninterface RenderOptions {\n scale: number\n format: ExportFormat\n quality?: number\n colorSpace?: RenderColorSpace\n trimTransparent?: boolean\n}\n\n/** Pixels an export may hold before it is refused, keeping a large scale from aborting CanvasKit. */\nexport const MAX_EXPORT_PIXELS = 150_000_000\n/** Intermediate pixels above which the 2× supersampling that sharpens small exports is dropped. */\nconst SUPERSAMPLE_PIXELS = 150_000_000\n\n/** Throws when an export of `width`×`height` pixels is larger than the renderer may allocate. */\nexport function assertExportSize(width: number, height: number): void {\n if (width * height > MAX_EXPORT_PIXELS) {\n throw new Error(\n `Export is too large: ${width}×${height} pixels (limit ${MAX_EXPORT_PIXELS}). Reduce the scale.`\n )\n }\n}\n\n/** The scale an export renders at before downsampling: 2× while it stays within the budget. */\nexport function exportRenderScale(width: number, height: number): number {\n return width * height * 4 <= SUPERSAMPLE_PIXELS ? 2 : 1\n}\n\nfunction ensureSinglePageSelection(graph: SceneGraph, pageId: string, nodeIds: string[]): boolean {\n return nodeIds.every((nodeId) => findPageId(graph, nodeId) === pageId)\n}\n\nexport function computeContentBounds(graph: SceneGraph, nodeIds: string[]) {\n return computeDescendantVisualBounds(\n nodeIds,\n (id) => graph.getNode(id),\n (id) => graph.getAbsolutePosition(id)\n )\n}\n\nfunction ckImageFormat(ck: CanvasKit, format: ExportFormat) {\n switch (format) {\n case 'JPG':\n return ck.ImageFormat.JPEG\n case 'WEBP':\n return ck.ImageFormat.WEBP\n default:\n return ck.ImageFormat.PNG\n }\n}\n\nfunction findAlphaBounds(ck: CanvasKit, canvas: Canvas, width: number, height: number) {\n const pixels = canvas.readPixels(0, 0, {\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width,\n height\n })\n if (!pixels) return null\n\n let minX = width\n let minY = height\n let maxX = -1\n let maxY = -1\n\n for (let y = 0; y < height; y++) {\n const row = y * width * 4\n for (let x = 0; x < width; x++) {\n if (pixels[row + x * 4 + 3] === 0) continue\n minX = Math.min(minX, x)\n minY = Math.min(minY, y)\n maxX = Math.max(maxX, x + 1)\n maxY = Math.max(maxY, y + 1)\n }\n }\n\n if (maxX < minX || maxY < minY) return null\n return { minX, minY, maxX, maxY }\n}\n\nconst MIN_TRANSPARENT_TRIM_INSET = 2\n\nfunction shouldTrimAlphaBounds(\n alphaBounds: NonNullable<ReturnType<typeof findAlphaBounds>>,\n width: number,\n height: number\n): boolean {\n return (\n Math.max(\n alphaBounds.minX,\n alphaBounds.minY,\n width - alphaBounds.maxX,\n height - alphaBounds.maxY\n ) >= MIN_TRANSPARENT_TRIM_INSET\n )\n}\n\n/** Encodes `image`, whose pixels are `width`×`height`, falling back to the host's encoder. */\nfunction encodeImage(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n image: CanvasImage,\n width: number,\n height: number,\n format: ExportFormat,\n quality: number\n): Uint8Array<ArrayBuffer> | null {\n const encoded = image.encodeToBytes(ckImageFormat(ck, format), quality)\n if (encoded) return new Uint8Array(encoded)\n if (format !== 'JPG' && format !== 'WEBP') return null\n const raw = image.readPixels(0, 0, {\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width,\n height\n })\n return raw instanceof Uint8Array\n ? renderer.encodeRasterFallback(raw, width, height, format, quality)\n : null\n}\n\nfunction renderToSurface(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n renderGraph: SceneGraph,\n pageId: string,\n width: number,\n height: number,\n format: ExportFormat,\n quality: number,\n setup: (canvas: Canvas) => void,\n trimTransparent = false\n): Uint8Array<ArrayBuffer> | null {\n const renderScale = exportRenderScale(width, height)\n const renderWidth = width * renderScale\n const renderHeight = height * renderScale\n const pixels = ck.Malloc(Uint8Array, renderWidth * renderHeight * 4)\n const surface = ck.MakeRasterDirectSurface(\n {\n alphaType: ck.AlphaType.Premul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width: renderWidth,\n height: renderHeight\n },\n pixels,\n renderWidth * 4\n )\n if (!surface) {\n ck.Free(pixels)\n throw new Error(`Could not allocate a ${renderWidth}×${renderHeight} export surface.`)\n }\n\n try {\n const canvas = surface.getCanvas()\n canvas.scale(renderScale, renderScale)\n setup(canvas)\n renderer.renderSceneToCanvas(canvas, renderGraph, pageId)\n surface.flush()\n\n const highResImage = surface.makeImageSnapshot()\n // At the export's own scale the snapshot is already the output: encode it without a second\n // full-size surface, which a large export would not have room for.\n if (renderScale === 1 && !trimTransparent) {\n const directBytes = encodeImage(ck, renderer, highResImage, width, height, format, quality)\n highResImage.delete()\n return directBytes\n }\n const downsamplePixels = ck.Malloc(Uint8Array, width * height * 4)\n const downsampleSurface = ck.MakeRasterDirectSurface(\n {\n alphaType: ck.AlphaType.Premul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width,\n height\n },\n downsamplePixels,\n width * 4\n )\n if (!downsampleSurface) {\n ck.Free(downsamplePixels)\n highResImage.delete()\n throw new Error(`Could not allocate a ${width}×${height} export surface.`)\n }\n const downsampleCanvas = downsampleSurface.getCanvas()\n downsampleCanvas.clear(ck.TRANSPARENT)\n downsampleCanvas.drawImageRectOptions(\n highResImage,\n ck.LTRBRect(0, 0, renderWidth, renderHeight),\n ck.LTRBRect(0, 0, width, height),\n ck.FilterMode.Linear,\n ck.MipmapMode.None,\n null\n )\n downsampleSurface.flush()\n highResImage.delete()\n\n const foundAlphaBounds = trimTransparent\n ? findAlphaBounds(ck, downsampleCanvas, width, height)\n : null\n const alphaBounds =\n foundAlphaBounds && shouldTrimAlphaBounds(foundAlphaBounds, width, height)\n ? foundAlphaBounds\n : null\n const image = alphaBounds\n ? downsampleSurface.makeImageSnapshot([\n alphaBounds.minX,\n alphaBounds.minY,\n alphaBounds.maxX,\n alphaBounds.maxY\n ])\n : downsampleSurface.makeImageSnapshot()\n const encoded = image.encodeToBytes(ckImageFormat(ck, format), quality)\n let resultBytes: Uint8Array<ArrayBuffer> | null = encoded ? new Uint8Array(encoded) : null\n\n // CanvasKit's `encodeToBytes` returns null for JPEG/WEBP in this build, so\n // fall back to encoding the raw pixels through the browser canvas.\n if (!resultBytes && (format === 'JPG' || format === 'WEBP')) {\n const exportWidth = alphaBounds ? alphaBounds.maxX - alphaBounds.minX : width\n const exportHeight = alphaBounds ? alphaBounds.maxY - alphaBounds.minY : height\n const exportMinX = alphaBounds ? alphaBounds.minX : 0\n const exportMinY = alphaBounds ? alphaBounds.minY : 0\n\n const rawPixels = downsampleCanvas.readPixels(exportMinX, exportMinY, {\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width: exportWidth,\n height: exportHeight\n })\n\n if (rawPixels instanceof Uint8Array) {\n resultBytes = renderer.encodeRasterFallback(\n rawPixels,\n exportWidth,\n exportHeight,\n format,\n quality\n )\n }\n }\n\n image.delete()\n downsampleSurface.delete()\n ck.Free(downsamplePixels)\n return resultBytes\n } finally {\n surface.dispose()\n ck.Free(pixels)\n }\n}\n\n/**\n * `nodeIds` in the order the source page paints them, bottom to top, whatever order they came in,\n * without those a selected ancestor already paints.\n */\nfunction inPaintOrder(source: SceneGraph, pageId: string, nodeIds: readonly string[]): string[] {\n const selected = new Set(nodeIds)\n const ordered: string[] = []\n const visit = (id: string): void => {\n if (selected.has(id)) {\n ordered.push(id)\n return\n }\n for (const childId of source.getNode(id)?.childIds ?? []) visit(childId)\n }\n visit(pageId)\n return ordered\n}\n\nexport function prepareSelectionRenderGraph(\n source: SceneGraph,\n renderGraph: SceneGraph,\n pageId: string,\n nodeIds: string[]\n): void {\n const page = renderGraph.getNode(pageId)\n if (!page) return\n\n page.childIds = inPaintOrder(source, pageId, nodeIds).filter(\n (nodeId) => renderGraph.getNode(nodeId) !== undefined\n )\n for (const nodeId of page.childIds) {\n const node = renderGraph.getNode(nodeId)\n const sourceNode = source.getNode(nodeId)\n if (!node || !sourceNode) continue\n if (sourceNode.parentId === pageId) continue\n const world = getWorldMatrix(sourceNode, source)\n node.parentId = pageId\n // The page is now the parent, so the modes the ancestors set must stay on the node.\n node.variableModes = resolvedVariableModes(source, nodeId)\n applyWorldTransform(node, world)\n }\n renderGraph.clearAbsPosCache()\n}\n\nfunction applyWorldTransform(node: SceneNode, matrix: Mat3): void {\n const determinant = matrix[0] * matrix[4] - matrix[1] * matrix[3]\n const flipX = determinant < 0\n const rotation = Math.atan2(matrix[3], flipX ? matrix[4] : matrix[0])\n const cos = Math.cos(rotation)\n const sin = Math.sin(rotation)\n const centerX = node.width / 2\n const centerY = node.height / 2\n const m00 = flipX ? -cos : cos\n const m01 = flipX ? sin : -sin\n const m10 = sin\n const m11 = cos\n\n node.x = matrix[2] - centerX + m00 * centerX + m01 * centerY\n node.y = matrix[5] - centerY + m10 * centerX + m11 * centerY\n node.rotation = rotation * (180 / Math.PI)\n node.flipX = flipX\n node.flipY = false\n}\n\nexport function renderNodesToImage(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n graph: SceneGraph,\n pageId: string,\n nodeIds: string[],\n options: RenderOptions\n): Uint8Array<ArrayBuffer> | null {\n if (!ensureSinglePageSelection(graph, pageId, nodeIds)) {\n throw new Error('Raster export selection must stay on a single page')\n }\n\n const bounds = computeContentBounds(graph, nodeIds)\n if (!bounds) return null\n\n const contentW = bounds.maxX - bounds.minX\n const contentH = bounds.maxY - bounds.minY\n if (contentW <= 0 || contentH <= 0) return null\n\n const pixelW = Math.ceil(contentW * options.scale)\n const pixelH = Math.ceil(contentH * options.scale)\n if (pixelW <= 0 || pixelH <= 0) return null\n assertExportSize(pixelW, pixelH)\n\n // Figma exports a layer by itself, without the page behind it, even when it blends.\n const extracted = extractExportGraph(graph, { scope: 'selection', nodeIds })\n if (!extracted.pageId) return null\n prepareSelectionRenderGraph(graph, extracted.graph, extracted.pageId, nodeIds)\n\n const quality = options.quality ?? (options.format === 'PNG' ? 100 : 90)\n return renderToSurface(\n ck,\n renderer,\n extracted.graph,\n extracted.pageId,\n pixelW,\n pixelH,\n options.format,\n quality,\n (canvas) => {\n // JPEG has no transparency; Figma fills whatever the layer leaves clear with white.\n canvas.clear(options.format === 'JPG' ? ck.WHITE : ck.TRANSPARENT)\n canvas.scale(options.scale, options.scale)\n canvas.translate(-bounds.minX, -bounds.minY)\n },\n options.trimTransparent\n )\n}\n\nexport interface ThumbnailFrame {\n /** The page content the thumbnail shows. */\n bounds: VisualBounds\n scale: number\n /** The thumbnail's size in pixels. */\n width: number\n height: number\n}\n\n/** The page region a thumbnail fitted into `width` by `height` pixels shows, and its size. */\nexport function thumbnailFrame(\n graph: SceneGraph,\n pageId: string,\n width: number,\n height: number\n): ThumbnailFrame | null {\n const page = graph.getNode(pageId)\n if (!page || page.childIds.length === 0) return null\n\n const bounds = computeContentBounds(graph, page.childIds)\n if (!bounds) return null\n\n const contentW = bounds.maxX - bounds.minX\n const contentH = bounds.maxY - bounds.minY\n if (contentW <= 0 || contentH <= 0) return null\n\n const scale = Math.min(width / contentW, height / contentH)\n return {\n bounds,\n scale,\n width: Math.max(1, Math.round(contentW * scale)),\n height: Math.max(1, Math.round(contentH * scale))\n }\n}\n\nexport function renderThumbnail(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n graph: SceneGraph,\n pageId: string,\n width: number,\n height: number,\n format: RasterExportFormat = 'PNG',\n quality = 100\n): Uint8Array<ArrayBuffer> | null {\n const frame = thumbnailFrame(graph, pageId, width, height)\n if (!frame) return null\n const { bounds, scale, width: pixelW, height: pixelH } = frame\n // The page's own background, which the editor's page colour matches only while it is open.\n const background = getPageColor(graph.getNode(pageId))\n\n return renderToSurface(ck, renderer, graph, pageId, pixelW, pixelH, format, quality, (canvas) => {\n canvas.clear(ck.Color4f(background.r, background.g, background.b, 1))\n canvas.translate(-bounds.minX * scale, -bounds.minY * scale)\n canvas.scale(scale, scale)\n })\n}\n\n/** Draws a page region with `renderer`; `region.ts` gives it a renderer of its own. */\nexport function drawRegionToImage(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n graph: SceneGraph,\n pageId: string,\n bounds: VisualBounds,\n scale: number\n): Uint8Array<ArrayBuffer> | null {\n const pixelW = Math.max(1, Math.round((bounds.maxX - bounds.minX) * scale))\n const pixelH = Math.max(1, Math.round((bounds.maxY - bounds.minY) * scale))\n if (!graph.getNode(pageId) || !Number.isFinite(pixelW * pixelH)) return null\n return renderToSurface(ck, renderer, graph, pageId, pixelW, pixelH, 'PNG', 100, (canvas) => {\n canvas.clear(ck.Color4f(renderer.pageColor.r, renderer.pageColor.g, renderer.pageColor.b, 1))\n canvas.scale(scale, scale)\n canvas.translate(-bounds.minX, -bounds.minY)\n })\n}\n"],"mappings":";;;;;;;AAyBA,MAAa,oBAAoB;;AAEjC,MAAM,qBAAqB;;AAG3B,SAAgB,iBAAi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IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,EAAE,QAAQ,OAAO,OAAO,QAAQ,QAAQ,WAAW;CAEzD,MAAM,aAAa,aAAa,MAAM,QAAQ,MAAM,CAAC;CAErD,OAAO,gBAAgB,IAAI,UAAU,OAAO,QAAQ,QAAQ,QAAQ,QAAQ,UAAU,WAAW;EAC/F,OAAO,MAAM,GAAG,QAAQ,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,CAAC,CAAC;EACpE,OAAO,UAAU,CAAC,OAAO,OAAO,OAAO,CAAC,OAAO,OAAO,KAAK;EAC3D,OAAO,MAAM,OAAO,KAAK;CAC3B,CAAC;AACH;;AAGA,SAAgB,kBACd,IACA,UACA,OACA,QACA,QACA,OACgC;CAChC,MAAM,SAAS,KAAK,IAAI,GAAG,KAAK,OAAO,OAAO,OAAO,OAAO,QAAQ,KAAK,CAAC;CAC1E,MAAM,SAAS,KAAK,IAAI,GAAG,KAAK,OAAO,OAAO,OAAO,OAAO,QAAQ,KAAK,CAAC;CAC1E,IAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,CAAC,OAAO,SAAS,SAAS,MAAM,GAAG,OAAO;CACxE,OAAO,gBAAgB,IAAI,UAAU,OAAO,QAAQ,QAAQ,QAAQ,OAAO,MAAM,WAAW;EAC1F,OAAO,MAAM,GAAG,QAAQ,SAAS,UAAU,GAAG,SAAS,UAAU,GAAG,SAAS,UAAU,GAAG,CAAC,CAAC;EAC5F,OAAO,MAAM,OAAO,KAAK;EACzB,OAAO,UAAU,CAAC,OAAO,MAAM,CAAC,OAAO,IAAI;CAC7C,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"render.js","names":[],"sources":["../../../../src/io/formats/raster/render.ts"],"sourcesContent":["import type { CanvasKit, Canvas, Image as CanvasImage } from 'canvaskit-wasm'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport type { RenderColorSpace } from '@pairdraw/scene-graph/color'\nimport { getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport { computeDescendantVisualBounds, type VisualBounds } from '@pairdraw/scene-graph/geometry'\nimport Matrix, { type Mat3 } from '@pairdraw/scene-graph/matrix'\nimport { resolvedVariableModes } from '@pairdraw/scene-graph/variables'\n\nimport type { SkiaRenderer } from '#core/canvas'\nimport { getPageColor } from '#core/figma-api/page-backgrounds'\nimport { extractExportGraph, findPageId } from '#core/io/subgraph'\n\nexport type RasterExportFormat = 'PNG' | 'JPG' | 'WEBP'\nexport type ExportFormat = RasterExportFormat | 'SVG'\n\ninterface RenderOptions {\n scale: number\n format: ExportFormat\n quality?: number\n colorSpace?: RenderColorSpace\n trimTransparent?: boolean\n}\n\n/** Pixels an export may hold before it is refused, keeping a large scale from aborting CanvasKit. */\nexport const MAX_EXPORT_PIXELS = 150_000_000\n/** Intermediate pixels above which the 2× supersampling that sharpens small exports is dropped. */\nconst SUPERSAMPLE_PIXELS = 150_000_000\n\n/** Throws when an export of `width`×`height` pixels is larger than the renderer may allocate. */\nexport function assertExportSize(width: number, height: number): void {\n if (width * height > MAX_EXPORT_PIXELS) {\n throw new Error(\n `Export is too large: ${width}×${height} pixels (limit ${MAX_EXPORT_PIXELS}). Reduce the scale.`\n )\n }\n}\n\n/** The scale an export renders at before downsampling: 2× while it stays within the budget. */\nexport function exportRenderScale(width: number, height: number): number {\n return width * height * 4 <= SUPERSAMPLE_PIXELS ? 2 : 1\n}\n\nfunction ensureSinglePageSelection(graph: SceneGraph, pageId: string, nodeIds: string[]): boolean {\n return nodeIds.every((nodeId) => findPageId(graph, nodeId) === pageId)\n}\n\nexport function computeContentBounds(graph: SceneGraph, nodeIds: string[]) {\n return computeDescendantVisualBounds(\n nodeIds,\n (id) => graph.getNode(id),\n (id) => graph.getAbsolutePosition(id)\n )\n}\n\nfunction ckImageFormat(ck: CanvasKit, format: ExportFormat) {\n switch (format) {\n case 'JPG':\n return ck.ImageFormat.JPEG\n case 'WEBP':\n return ck.ImageFormat.WEBP\n default:\n return ck.ImageFormat.PNG\n }\n}\n\nfunction findAlphaBounds(ck: CanvasKit, canvas: Canvas, width: number, height: number) {\n const pixels = canvas.readPixels(0, 0, {\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width,\n height\n })\n if (!pixels) return null\n\n let minX = width\n let minY = height\n let maxX = -1\n let maxY = -1\n\n for (let y = 0; y < height; y++) {\n const row = y * width * 4\n for (let x = 0; x < width; x++) {\n if (pixels[row + x * 4 + 3] === 0) continue\n minX = Math.min(minX, x)\n minY = Math.min(minY, y)\n maxX = Math.max(maxX, x + 1)\n maxY = Math.max(maxY, y + 1)\n }\n }\n\n if (maxX < minX || maxY < minY) return null\n return { minX, minY, maxX, maxY }\n}\n\nconst MIN_TRANSPARENT_TRIM_INSET = 2\n\nfunction shouldTrimAlphaBounds(\n alphaBounds: NonNullable<ReturnType<typeof findAlphaBounds>>,\n width: number,\n height: number\n): boolean {\n return (\n Math.max(\n alphaBounds.minX,\n alphaBounds.minY,\n width - alphaBounds.maxX,\n height - alphaBounds.maxY\n ) >= MIN_TRANSPARENT_TRIM_INSET\n )\n}\n\n/** Encodes `image`, whose pixels are `width`×`height`, falling back to the host's encoder. */\nfunction encodeImage(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n image: CanvasImage,\n width: number,\n height: number,\n format: ExportFormat,\n quality: number\n): Uint8Array<ArrayBuffer> | null {\n const encoded = image.encodeToBytes(ckImageFormat(ck, format), quality)\n if (encoded) return new Uint8Array(encoded)\n if (format !== 'JPG' && format !== 'WEBP') return null\n const raw = image.readPixels(0, 0, {\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width,\n height\n })\n return raw instanceof Uint8Array\n ? renderer.encodeRasterFallback(raw, width, height, format, quality)\n : null\n}\n\nfunction renderToSurface(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n renderGraph: SceneGraph,\n pageId: string,\n width: number,\n height: number,\n format: ExportFormat,\n quality: number,\n setup: (canvas: Canvas) => void,\n trimTransparent = false\n): Uint8Array<ArrayBuffer> | null {\n const renderScale = exportRenderScale(width, height)\n const renderWidth = width * renderScale\n const renderHeight = height * renderScale\n const pixels = ck.Malloc(Uint8Array, renderWidth * renderHeight * 4)\n const surface = ck.MakeRasterDirectSurface(\n {\n alphaType: ck.AlphaType.Premul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width: renderWidth,\n height: renderHeight\n },\n pixels,\n renderWidth * 4\n )\n if (!surface) {\n ck.Free(pixels)\n throw new Error(`Could not allocate a ${renderWidth}×${renderHeight} export surface.`)\n }\n\n const drawnFor = renderer.supersampledOutput\n try {\n const canvas = surface.getCanvas()\n canvas.scale(renderScale, renderScale)\n setup(canvas)\n renderer.supersampledOutput =\n renderScale > 1\n ? {\n outputFromWorld: Matrix.multiply(\n Matrix.scaled(1 / renderScale, 1 / renderScale),\n canvas.getTotalMatrix()\n )\n }\n : null\n renderer.renderSceneToCanvas(canvas, renderGraph, pageId)\n surface.flush()\n\n const highResImage = surface.makeImageSnapshot()\n // At the export's own scale the snapshot is already the output: encode it without a second\n // full-size surface, which a large export would not have room for.\n if (renderScale === 1 && !trimTransparent) {\n const directBytes = encodeImage(ck, renderer, highResImage, width, height, format, quality)\n highResImage.delete()\n return directBytes\n }\n const downsamplePixels = ck.Malloc(Uint8Array, width * height * 4)\n const downsampleSurface = ck.MakeRasterDirectSurface(\n {\n alphaType: ck.AlphaType.Premul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width,\n height\n },\n downsamplePixels,\n width * 4\n )\n if (!downsampleSurface) {\n ck.Free(downsamplePixels)\n highResImage.delete()\n throw new Error(`Could not allocate a ${width}×${height} export surface.`)\n }\n const downsampleCanvas = downsampleSurface.getCanvas()\n downsampleCanvas.clear(ck.TRANSPARENT)\n downsampleCanvas.drawImageRectOptions(\n highResImage,\n ck.LTRBRect(0, 0, renderWidth, renderHeight),\n ck.LTRBRect(0, 0, width, height),\n ck.FilterMode.Linear,\n ck.MipmapMode.None,\n null\n )\n downsampleSurface.flush()\n highResImage.delete()\n\n const foundAlphaBounds = trimTransparent\n ? findAlphaBounds(ck, downsampleCanvas, width, height)\n : null\n const alphaBounds =\n foundAlphaBounds && shouldTrimAlphaBounds(foundAlphaBounds, width, height)\n ? foundAlphaBounds\n : null\n const image = alphaBounds\n ? downsampleSurface.makeImageSnapshot([\n alphaBounds.minX,\n alphaBounds.minY,\n alphaBounds.maxX,\n alphaBounds.maxY\n ])\n : downsampleSurface.makeImageSnapshot()\n const encoded = image.encodeToBytes(ckImageFormat(ck, format), quality)\n let resultBytes: Uint8Array<ArrayBuffer> | null = encoded ? new Uint8Array(encoded) : null\n\n // CanvasKit's `encodeToBytes` returns null for JPEG/WEBP in this build, so\n // fall back to encoding the raw pixels through the browser canvas.\n if (!resultBytes && (format === 'JPG' || format === 'WEBP')) {\n const exportWidth = alphaBounds ? alphaBounds.maxX - alphaBounds.minX : width\n const exportHeight = alphaBounds ? alphaBounds.maxY - alphaBounds.minY : height\n const exportMinX = alphaBounds ? alphaBounds.minX : 0\n const exportMinY = alphaBounds ? alphaBounds.minY : 0\n\n const rawPixels = downsampleCanvas.readPixels(exportMinX, exportMinY, {\n alphaType: ck.AlphaType.Unpremul,\n colorType: ck.ColorType.RGBA_8888,\n colorSpace: ck.ColorSpace.SRGB,\n width: exportWidth,\n height: exportHeight\n })\n\n if (rawPixels instanceof Uint8Array) {\n resultBytes = renderer.encodeRasterFallback(\n rawPixels,\n exportWidth,\n exportHeight,\n format,\n quality\n )\n }\n }\n\n image.delete()\n downsampleSurface.delete()\n ck.Free(downsamplePixels)\n return resultBytes\n } finally {\n renderer.supersampledOutput = drawnFor\n surface.dispose()\n ck.Free(pixels)\n }\n}\n\n/**\n * `nodeIds` in the order the source page paints them, bottom to top, whatever order they came in,\n * without those a selected ancestor already paints.\n */\nfunction inPaintOrder(source: SceneGraph, pageId: string, nodeIds: readonly string[]): string[] {\n const selected = new Set(nodeIds)\n const ordered: string[] = []\n const visit = (id: string): void => {\n if (selected.has(id)) {\n ordered.push(id)\n return\n }\n for (const childId of source.getNode(id)?.childIds ?? []) visit(childId)\n }\n visit(pageId)\n return ordered\n}\n\nexport function prepareSelectionRenderGraph(\n source: SceneGraph,\n renderGraph: SceneGraph,\n pageId: string,\n nodeIds: string[]\n): void {\n const page = renderGraph.getNode(pageId)\n if (!page) return\n\n page.childIds = inPaintOrder(source, pageId, nodeIds).filter(\n (nodeId) => renderGraph.getNode(nodeId) !== undefined\n )\n for (const nodeId of page.childIds) {\n const node = renderGraph.getNode(nodeId)\n const sourceNode = source.getNode(nodeId)\n if (!node || !sourceNode) continue\n if (sourceNode.parentId === pageId) continue\n const world = getWorldMatrix(sourceNode, source)\n node.parentId = pageId\n // The page is now the parent, so the modes the ancestors set must stay on the node.\n node.variableModes = resolvedVariableModes(source, nodeId)\n applyWorldTransform(node, world)\n }\n renderGraph.clearAbsPosCache()\n}\n\nfunction applyWorldTransform(node: SceneNode, matrix: Mat3): void {\n const determinant = matrix[0] * matrix[4] - matrix[1] * matrix[3]\n const flipX = determinant < 0\n const rotation = Math.atan2(matrix[3], flipX ? matrix[4] : matrix[0])\n const cos = Math.cos(rotation)\n const sin = Math.sin(rotation)\n const centerX = node.width / 2\n const centerY = node.height / 2\n const m00 = flipX ? -cos : cos\n const m01 = flipX ? sin : -sin\n const m10 = sin\n const m11 = cos\n\n node.x = matrix[2] - centerX + m00 * centerX + m01 * centerY\n node.y = matrix[5] - centerY + m10 * centerX + m11 * centerY\n node.rotation = rotation * (180 / Math.PI)\n node.flipX = flipX\n node.flipY = false\n}\n\nexport function renderNodesToImage(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n graph: SceneGraph,\n pageId: string,\n nodeIds: string[],\n options: RenderOptions\n): Uint8Array<ArrayBuffer> | null {\n if (!ensureSinglePageSelection(graph, pageId, nodeIds)) {\n throw new Error('Raster export selection must stay on a single page')\n }\n\n const bounds = computeContentBounds(graph, nodeIds)\n if (!bounds) return null\n\n const contentW = bounds.maxX - bounds.minX\n const contentH = bounds.maxY - bounds.minY\n if (contentW <= 0 || contentH <= 0) return null\n\n const pixelW = Math.ceil(contentW * options.scale)\n const pixelH = Math.ceil(contentH * options.scale)\n if (pixelW <= 0 || pixelH <= 0) return null\n assertExportSize(pixelW, pixelH)\n\n // Figma exports a layer by itself, without the page behind it, even when it blends.\n const extracted = extractExportGraph(graph, { scope: 'selection', nodeIds })\n if (!extracted.pageId) return null\n prepareSelectionRenderGraph(graph, extracted.graph, extracted.pageId, nodeIds)\n\n const quality = options.quality ?? (options.format === 'PNG' ? 100 : 90)\n return renderToSurface(\n ck,\n renderer,\n extracted.graph,\n extracted.pageId,\n pixelW,\n pixelH,\n options.format,\n quality,\n (canvas) => {\n // JPEG has no transparency; Figma fills whatever the layer leaves clear with white.\n canvas.clear(options.format === 'JPG' ? ck.WHITE : ck.TRANSPARENT)\n canvas.scale(options.scale, options.scale)\n canvas.translate(-bounds.minX, -bounds.minY)\n },\n options.trimTransparent\n )\n}\n\nexport interface ThumbnailFrame {\n /** The page content the thumbnail shows. */\n bounds: VisualBounds\n scale: number\n /** The thumbnail's size in pixels. */\n width: number\n height: number\n}\n\n/** The page region a thumbnail fitted into `width` by `height` pixels shows, and its size. */\nexport function thumbnailFrame(\n graph: SceneGraph,\n pageId: string,\n width: number,\n height: number\n): ThumbnailFrame | null {\n const page = graph.getNode(pageId)\n if (!page || page.childIds.length === 0) return null\n\n const bounds = computeContentBounds(graph, page.childIds)\n if (!bounds) return null\n\n const contentW = bounds.maxX - bounds.minX\n const contentH = bounds.maxY - bounds.minY\n if (contentW <= 0 || contentH <= 0) return null\n\n const scale = Math.min(width / contentW, height / contentH)\n return {\n bounds,\n scale,\n width: Math.max(1, Math.round(contentW * scale)),\n height: Math.max(1, Math.round(contentH * scale))\n }\n}\n\nexport function renderThumbnail(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n graph: SceneGraph,\n pageId: string,\n width: number,\n height: number,\n format: RasterExportFormat = 'PNG',\n quality = 100\n): Uint8Array<ArrayBuffer> | null {\n const frame = thumbnailFrame(graph, pageId, width, height)\n if (!frame) return null\n const { bounds, scale, width: pixelW, height: pixelH } = frame\n // The page's own background, which the editor's page colour matches only while it is open.\n const background = getPageColor(graph.getNode(pageId))\n\n return renderToSurface(ck, renderer, graph, pageId, pixelW, pixelH, format, quality, (canvas) => {\n canvas.clear(ck.Color4f(background.r, background.g, background.b, 1))\n canvas.translate(-bounds.minX * scale, -bounds.minY * scale)\n canvas.scale(scale, scale)\n })\n}\n\n/** Draws a page region with `renderer`; `region.ts` gives it a renderer of its own. */\nexport function drawRegionToImage(\n ck: CanvasKit,\n renderer: SkiaRenderer,\n graph: SceneGraph,\n pageId: string,\n bounds: VisualBounds,\n scale: number\n): Uint8Array<ArrayBuffer> | null {\n const pixelW = Math.max(1, Math.round((bounds.maxX - bounds.minX) * scale))\n const pixelH = Math.max(1, Math.round((bounds.maxY - bounds.minY) * scale))\n if (!graph.getNode(pageId) || !Number.isFinite(pixelW * pixelH)) return null\n return renderToSurface(ck, renderer, graph, pageId, pixelW, pixelH, 'PNG', 100, (canvas) => {\n canvas.clear(ck.Color4f(renderer.pageColor.r, renderer.pageColor.g, renderer.pageColor.b, 1))\n canvas.scale(scale, scale)\n canvas.translate(-bounds.minX, -bounds.minY)\n })\n}\n"],"mappings":";;;;;;;;AAyBA,MAAa,oBAAoB;;AAEjC,MAAM,qBAAqB;;AAG3B,SAAgB,iBAAiB,OAAe,QAAsB;CACpE,IAAI,QAAQ,SAAA,MACV,MAAM,IAAI,MACR,wBAAwB,MAAM,GAAG,OAAO,iBAAiB,kBAAkB,qBAC7E;AAEJ;;AAGA,SAAgB,kBAAkB,OAAe,QAAwB;CACvE,OAAO,QAAQ,SAAS,KAAK,qBAAqB,IAAI;AACxD;AAEA,SAAS,0BAA0B,OAAmB,QAAgB,SAA4B;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;CAEzD,MAAM,aAAa,aAAa,MAAM,QAAQ,MAAM,CAAC;CAErD,OAAO,gBAAgB,IAAI,UAAU,OAAO,QAAQ,QAAQ,QAAQ,QAAQ,UAAU,WAAW;EAC/F,OAAO,MAAM,GAAG,QAAQ,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,CAAC,CAAC;EACpE,OAAO,UAAU,CAAC,OAAO,OAAO,OAAO,CAAC,OAAO,OAAO,KAAK;EAC3D,OAAO,MAAM,OAAO,KAAK;CAC3B,CAAC;AACH;;AAGA,SAAgB,kBACd,IACA,UACA,OACA,QACA,QACA,OACgC;CAChC,MAAM,SAAS,KAAK,IAAI,GAAG,KAAK,OAAO,OAAO,OAAO,OAAO,QAAQ,KAAK,CAAC;CAC1E,MAAM,SAAS,KAAK,IAAI,GAAG,KAAK,OAAO,OAAO,OAAO,OAAO,QAAQ,KAAK,CAAC;CAC1E,IAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,CAAC,OAAO,SAAS,SAAS,MAAM,GAAG,OAAO;CACxE,OAAO,gBAAgB,IAAI,UAAU,OAAO,QAAQ,QAAQ,QAAQ,OAAO,MAAM,WAAW;EAC1F,OAAO,MAAM,GAAG,QAAQ,SAAS,UAAU,GAAG,SAAS,UAAU,GAAG,SAAS,UAAU,GAAG,CAAC,CAAC;EAC5F,OAAO,MAAM,OAAO,KAAK;EACzB,OAAO,UAAU,CAAC,OAAO,MAAM,CAAC,OAAO,IAAI;CAC7C,CAAC;AACH"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { FontFaceRef } from "../../../text/font/faces.js";
|
|
2
|
+
import { BooleanPathResolver } from "../boolean-path.js";
|
|
2
3
|
import { SVGNode } from "./node.js";
|
|
3
4
|
import { SVGTextLayout } from "./text/lines.js";
|
|
4
|
-
import {
|
|
5
|
+
import { Fill, FontVariation, SceneGraph, SceneNode } from "@pairdraw/scene-graph";
|
|
5
6
|
import { RenderColorSpace } from "@pairdraw/scene-graph/color";
|
|
6
7
|
import { Color } from "@pairdraw/scene-graph/primitives";
|
|
7
8
|
//#region src/io/formats/svg/defs.d.ts
|
|
@@ -30,6 +31,8 @@ interface SVGExportContext {
|
|
|
30
31
|
/** Measured line breaks. Without them, only explicit newlines start a new baseline. */
|
|
31
32
|
textLayout?: SVGTextLayout;
|
|
32
33
|
fontAlias?: SVGFontAlias;
|
|
34
|
+
/** The live result path of a boolean made in Pairdraw, which stores none. */
|
|
35
|
+
booleanPath?: BooleanPathResolver;
|
|
33
36
|
}
|
|
34
37
|
declare function nextDefId(ctx: SVGExportContext, prefix: string): string;
|
|
35
38
|
declare function formatColor(color: Color, opacity?: number, colorSpace?: RenderColorSpace): string;
|
|
@@ -45,14 +48,10 @@ declare function formatSolidColor(color: Color, opacity: number, colorSpace: Ren
|
|
|
45
48
|
* `separate` is set because that color was replaced and can no longer carry it.
|
|
46
49
|
*/
|
|
47
50
|
declare function solidFillOpacity(fill: Fill, colorSpace: RenderColorSpace, separate?: boolean): number | undefined;
|
|
48
|
-
declare function createFilterDef(effects: Effect[], ctx: SVGExportContext): {
|
|
49
|
-
id: string;
|
|
50
|
-
node: SVGNode;
|
|
51
|
-
} | null;
|
|
52
51
|
declare function resolveFill(fill: Fill, node: SceneNode, ctx: SVGExportContext): string | null;
|
|
53
52
|
declare const SVG_STROKE_CAP: Record<string, string>;
|
|
54
53
|
declare const SVG_STROKE_JOIN: Record<string, string>;
|
|
55
54
|
declare const SVG_BLEND_MODE: Record<string, string>;
|
|
56
55
|
//#endregion
|
|
57
|
-
export { SVGExportContext, SVGFontAlias, SVGFontRequest, SVG_BLEND_MODE, SVG_STROKE_CAP, SVG_STROKE_JOIN,
|
|
56
|
+
export { SVGExportContext, SVGFontAlias, SVGFontRequest, SVG_BLEND_MODE, SVG_STROKE_CAP, SVG_STROKE_JOIN, formatColor, formatSolidColor, nextDefId, resolveFill, solidFillOpacity };
|
|
58
57
|
//# sourceMappingURL=defs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defs.d.ts","names":[],"sources":["../../../../src/io/formats/svg/defs.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"defs.d.ts","names":[],"sources":["../../../../src/io/formats/svg/defs.ts"],"mappings":";;;;;;;;;;;;UA4BiB,uBAAuB;;EAEtC;EACA;EACA,qBAAqB;EACrB;;;KAIU,gBAAgB,MAAM;UAEjB;EACf,MAAM;EACN;EACA,OAAO;EACP,YAAY;;EAEZ;;EAEA,QAAQ,MAAM;;EAEd,aAAa;EACb,YAAY;;EAEZ,cAAc;;iBAGA,UAAU,KAAK,kBAAkB;iBAIjC,YACd,OAAO,OACP,kBACA,aAAY;;;;;;iBAeE,iBACd,OAAO,OACP,iBACA,YAAY;;;;;;iBAaE,iBACd,MAAM,MACN,YAAY,kBACZ;iBAyHc,YAAY,MAAM,MAAM,MAAM,WAAW,KAAK;cAqCjD,gBAAgB;cAMhB,iBAAiB;cAMjB,gBAAgB"}
|
|
@@ -124,58 +124,6 @@ function createImagePattern(fill, node, ctx) {
|
|
|
124
124
|
}))
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
|
-
function createFilterDef(effects, ctx) {
|
|
128
|
-
const visible = effects.filter((e) => e.visible && e.type !== "SHADER");
|
|
129
|
-
if (visible.length === 0) return null;
|
|
130
|
-
const id = nextDefId(ctx, "fx");
|
|
131
|
-
const primitives = [];
|
|
132
|
-
for (const effect of visible) if (effect.type === "DROP_SHADOW") {
|
|
133
|
-
const stdDev = round(effect.radius / 2);
|
|
134
|
-
primitives.push(svg("feDropShadow", {
|
|
135
|
-
dx: round(effect.offset.x),
|
|
136
|
-
dy: round(effect.offset.y),
|
|
137
|
-
stdDeviation: stdDev,
|
|
138
|
-
"flood-color": formatColor(effect.color, 1, ctx.colorSpace),
|
|
139
|
-
"flood-opacity": round(effect.color.a)
|
|
140
|
-
}));
|
|
141
|
-
} else if (effect.type === "INNER_SHADOW") {
|
|
142
|
-
const sid = `${id}_is`;
|
|
143
|
-
const stdDev = round(effect.radius / 2);
|
|
144
|
-
primitives.push(svg("feGaussianBlur", {
|
|
145
|
-
in: "SourceAlpha",
|
|
146
|
-
stdDeviation: stdDev,
|
|
147
|
-
result: `${sid}_blur`
|
|
148
|
-
}), svg("feOffset", {
|
|
149
|
-
dx: round(effect.offset.x),
|
|
150
|
-
dy: round(effect.offset.y),
|
|
151
|
-
result: `${sid}_off`
|
|
152
|
-
}), svg("feComposite", {
|
|
153
|
-
in: "SourceAlpha",
|
|
154
|
-
in2: `${sid}_off`,
|
|
155
|
-
operator: "out",
|
|
156
|
-
result: `${sid}_inv`
|
|
157
|
-
}), svg("feFlood", {
|
|
158
|
-
"flood-color": formatColor(effect.color, 1, ctx.colorSpace),
|
|
159
|
-
"flood-opacity": round(effect.color.a)
|
|
160
|
-
}), svg("feComposite", {
|
|
161
|
-
in2: `${sid}_inv`,
|
|
162
|
-
operator: "in",
|
|
163
|
-
result: `${sid}_shadow`
|
|
164
|
-
}), svg("feComposite", {
|
|
165
|
-
in: `${sid}_shadow`,
|
|
166
|
-
in2: "SourceGraphic",
|
|
167
|
-
operator: "over"
|
|
168
|
-
}));
|
|
169
|
-
} else {
|
|
170
|
-
const stdDev = round(effect.radius / 2);
|
|
171
|
-
primitives.push(svg("feGaussianBlur", { stdDeviation: stdDev }));
|
|
172
|
-
}
|
|
173
|
-
if (primitives.length === 0) return null;
|
|
174
|
-
return {
|
|
175
|
-
id,
|
|
176
|
-
node: svg("filter", { id }, ...primitives)
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
127
|
function resolveFill(fill, node, ctx) {
|
|
180
128
|
if (!fill.visible) return null;
|
|
181
129
|
if (fill.type === "SOLID") return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace);
|
|
@@ -228,6 +176,6 @@ const SVG_BLEND_MODE = {
|
|
|
228
176
|
LUMINOSITY: "luminosity"
|
|
229
177
|
};
|
|
230
178
|
//#endregion
|
|
231
|
-
export { SVG_BLEND_MODE, SVG_STROKE_CAP, SVG_STROKE_JOIN,
|
|
179
|
+
export { SVG_BLEND_MODE, SVG_STROKE_CAP, SVG_STROKE_JOIN, formatColor, formatSolidColor, nextDefId, resolveFill, solidFillOpacity };
|
|
232
180
|
|
|
233
181
|
//# sourceMappingURL=defs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defs.js","names":[],"sources":["../../../../src/io/formats/svg/defs.ts"],"sourcesContent":["import { fromUint8Array } from 'js-base64'\n\nimport type {\n Effect,\n Fill,\n FontVariation,\n SceneGraph,\n SceneNode,\n ShadowEffect\n} from '@pairdraw/scene-graph'\nimport {\n colorToHex,\n colorToDisplayCSS,\n getDefaultRenderColorSpace,\n type RenderColorSpace\n} from '@pairdraw/scene-graph/color'\nimport {\n gradientPoint,\n invertGradientTransform,\n isIdentityGradientTransform\n} from '@pairdraw/scene-graph/gradient'\nimport { imageMimeType } from '@pairdraw/scene-graph/images'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport type { FontFaceRef } from '#core/text/font/faces'\n\nimport { svg, type SVGNode } from './node'\nimport { round } from './paths'\nimport type { SVGTextLayout } from './text/lines'\n\n/**\n * A face text is drawn in, with what sets its axes: the font size the optical size follows unless\n * `opticalSizeFromFontSize` is off, and the axes the text sets.\n */\nexport interface SVGFontRequest extends FontFaceRef {\n /** Which of the style's files draws the text, 0 for its own then its shards; 0 when left out. */\n file?: number\n fontSize: number\n variations: readonly FontVariation[]\n opticalSizeFromFontSize: boolean\n}\n\n/** The family to name a font face by instead of its own, or null to keep the face. */\nexport type SVGFontAlias = (font: SVGFontRequest) => string | null\n\nexport interface SVGExportContext {\n defs: SVGNode[]\n defIdCounter: number\n graph: SceneGraph\n colorSpace: RenderColorSpace\n /** Starts every def id, so SVGs inlined on one page cannot reference each other's defs. */\n idPrefix?: string\n /** Paints drawn in `currentColor`, such as an icon's tinted paths, so CSS `color` sets them. */\n tint?: (node: SceneNode) => readonly ('fill' | 'stroke')[]\n /** Measured line breaks. Without them, only explicit newlines start a new baseline. */\n textLayout?: SVGTextLayout\n fontAlias?: SVGFontAlias\n}\n\nexport function nextDefId(ctx: SVGExportContext, prefix: string): string {\n return `${ctx.idPrefix ?? ''}${prefix}${ctx.defIdCounter++}`\n}\n\nexport function formatColor(\n color: Color,\n opacity = 1,\n colorSpace: RenderColorSpace = getDefaultRenderColorSpace()\n): string {\n const alphaColor = { ...color, a: color.a * opacity }\n if (colorSpace === 'display-p3') {\n return colorToDisplayCSS(alphaColor, { colorSpace })\n }\n // Hex has no alpha. Stops and shadows already emit theirs; solid fills use `solidFillOpacity`.\n return colorToHex(alphaColor)\n}\n\n/**\n * A solid paint's SVG color. The canvas paints `opacity` and drops color alpha: `setAlphaf`\n * replaces it, and `.pen` stores a hex alpha in both fields. Display P3 carries that painted\n * alpha in the color. sRGB hex cannot, so `solidFillOpacity` emits it beside the color.\n */\nexport function formatSolidColor(\n color: Color,\n opacity: number,\n colorSpace: RenderColorSpace\n): string {\n if (colorSpace === 'display-p3') {\n return formatColor({ ...color, a: 1 }, round(opacity), colorSpace)\n }\n return formatColor(color, 1, colorSpace)\n}\n\n/**\n * `fill-opacity` for a solid paint. Omitted at full opacity so an opaque export stays unchanged.\n * Display P3 already carries the same alpha in the color `formatSolidColor` returns, unless\n * `separate` is set because that color was replaced and can no longer carry it.\n */\nexport function solidFillOpacity(\n fill: Fill,\n colorSpace: RenderColorSpace,\n separate = false\n): number | undefined {\n if (fill.type !== 'SOLID' || (colorSpace === 'display-p3' && !separate)) return undefined\n const alpha = round(fill.opacity)\n return alpha < 1 ? alpha : undefined\n}\n\nfunction createGradientDef(\n fill: Fill,\n node: SceneNode,\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n const stops = fill.gradientStops\n const t = fill.gradientTransform\n if (!stops || !t) return null\n\n const stopNodes = stops.map((s) =>\n svg('stop', {\n offset: `${round(s.position * 100)}%`,\n 'stop-color': formatColor(s.color, 1, ctx.colorSpace),\n 'stop-opacity': s.color.a < 1 ? round(s.color.a) : undefined\n })\n )\n\n const id = nextDefId(ctx, 'grad')\n\n // Gradient space in bounding-box units, mapped onto the layer as the canvas draws it.\n const toLayer = invertGradientTransform(t)\n const transform = isIdentityGradientTransform(toLayer)\n ? undefined\n : `matrix(${[toLayer.m00, toLayer.m10, toLayer.m01, toLayer.m11, toLayer.m02, toLayer.m12].map((v) => round(v, 6)).join(' ')})`\n\n if (fill.type === 'GRADIENT_LINEAR') {\n return {\n id,\n node: svg(\n 'linearGradient',\n {\n id,\n x1: 0,\n y1: 0.5,\n x2: 1,\n y2: 0.5,\n gradientUnits: 'objectBoundingBox',\n gradientTransform: transform\n },\n ...stopNodes\n )\n }\n }\n\n // SVG has no diamond gradient, so a diamond exports as the radial one it is closest to.\n if (fill.type === 'GRADIENT_RADIAL' || fill.type === 'GRADIENT_DIAMOND') {\n return {\n id,\n node: svg(\n 'radialGradient',\n {\n id,\n cx: 0.5,\n cy: 0.5,\n r: 0.5,\n gradientUnits: 'objectBoundingBox',\n gradientTransform: transform\n },\n ...stopNodes\n )\n }\n }\n\n // Nor an angular one: it exports as a radial gradient around its centre.\n if (fill.type === 'GRADIENT_ANGULAR') {\n const center = gradientPoint(t, { x: 0.5, y: 0.5 })\n const cx = round(center.x * node.width)\n const cy = round(center.y * node.height)\n const r = Math.max(node.width, node.height)\n return {\n id,\n node: svg('radialGradient', { id, cx, cy, r, gradientUnits: 'userSpaceOnUse' }, ...stopNodes)\n }\n }\n\n return null\n}\n\nfunction createImagePattern(\n fill: Fill,\n node: SceneNode,\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n if (!fill.imageHash) return null\n const data = ctx.graph.images.get(fill.imageHash)\n if (!data) return null\n\n const id = nextDefId(ctx, 'img')\n const base64 = fromUint8Array(data)\n const mime = imageMimeType(data)\n\n return {\n id,\n node: svg(\n 'pattern',\n {\n id,\n patternUnits: 'objectBoundingBox',\n width: 1,\n height: 1,\n patternTransform: fill.imageRotation\n ? `rotate(${round(fill.imageRotation)} 0.5 0.5)`\n : undefined\n },\n svg('image', {\n href: `data:${mime};base64,${base64}`,\n width: node.width,\n height: node.height,\n preserveAspectRatio: fill.imageScaleMode === 'FIT' ? 'xMidYMid meet' : 'xMidYMid slice'\n })\n )\n }\n}\n\nexport function createFilterDef(\n effects: Effect[],\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n // SVG has no shader effect; a shader is a raster the format cannot carry.\n const visible = effects.filter((e): e is ShadowEffect => e.visible && e.type !== 'SHADER')\n if (visible.length === 0) return null\n\n const id = nextDefId(ctx, 'fx')\n const primitives: SVGNode[] = []\n\n for (const effect of visible) {\n if (effect.type === 'DROP_SHADOW') {\n const stdDev = round(effect.radius / 2)\n primitives.push(\n svg('feDropShadow', {\n dx: round(effect.offset.x),\n dy: round(effect.offset.y),\n stdDeviation: stdDev,\n 'flood-color': formatColor(effect.color, 1, ctx.colorSpace),\n 'flood-opacity': round(effect.color.a)\n })\n )\n } else if (effect.type === 'INNER_SHADOW') {\n const sid = `${id}_is`\n const stdDev = round(effect.radius / 2)\n primitives.push(\n svg('feGaussianBlur', { in: 'SourceAlpha', stdDeviation: stdDev, result: `${sid}_blur` }),\n svg('feOffset', {\n dx: round(effect.offset.x),\n dy: round(effect.offset.y),\n result: `${sid}_off`\n }),\n svg('feComposite', {\n in: 'SourceAlpha',\n in2: `${sid}_off`,\n operator: 'out',\n result: `${sid}_inv`\n }),\n svg('feFlood', {\n 'flood-color': formatColor(effect.color, 1, ctx.colorSpace),\n 'flood-opacity': round(effect.color.a)\n }),\n svg('feComposite', { in2: `${sid}_inv`, operator: 'in', result: `${sid}_shadow` }),\n svg('feComposite', {\n in: `${sid}_shadow`,\n in2: 'SourceGraphic',\n operator: 'over'\n })\n )\n } else {\n const stdDev = round(effect.radius / 2)\n primitives.push(svg('feGaussianBlur', { stdDeviation: stdDev }))\n }\n }\n\n if (primitives.length === 0) return null\n\n return {\n id,\n node: svg('filter', { id }, ...primitives)\n }\n}\n\nexport function resolveFill(fill: Fill, node: SceneNode, ctx: SVGExportContext): string | null {\n if (!fill.visible) return null\n\n if (fill.type === 'SOLID') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace)\n }\n\n // SVG has no mesh element: a mesh exports its own color, as `.fig` records carry it.\n if (fill.type === 'MESH') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace)\n }\n\n // The canvas draws a pattern, noise or custom paint as its own colour when the format has no\n // element for it, so the export must not drop the layer.\n if (fill.type === 'PATTERN' || fill.type === 'NOISE' || fill.type === 'CUSTOM') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace)\n }\n\n if (fill.type.startsWith('GRADIENT')) {\n const grad = createGradientDef(fill, node, ctx)\n if (grad) {\n ctx.defs.push(grad.node)\n return `url(#${grad.id})`\n }\n }\n\n if (fill.type === 'IMAGE') {\n const pattern = createImagePattern(fill, node, ctx)\n if (pattern) {\n ctx.defs.push(pattern.node)\n return `url(#${pattern.id})`\n }\n }\n\n return null\n}\n\nexport const SVG_STROKE_CAP: Record<string, string> = {\n NONE: 'butt',\n ROUND: 'round',\n SQUARE: 'square'\n}\n\nexport const SVG_STROKE_JOIN: Record<string, string> = {\n MITER: 'miter',\n ROUND: 'round',\n BEVEL: 'bevel'\n}\n\nexport const SVG_BLEND_MODE: Record<string, string> = {\n NORMAL: 'normal',\n DARKEN: 'darken',\n MULTIPLY: 'multiply',\n COLOR_BURN: 'color-burn',\n LIGHTEN: 'lighten',\n LINEAR_BURN: 'plus-darker',\n SCREEN: 'screen',\n LINEAR_DODGE: 'plus-lighter',\n COLOR_DODGE: 'color-dodge',\n OVERLAY: 'overlay',\n SOFT_LIGHT: 'soft-light',\n HARD_LIGHT: 'hard-light',\n DIFFERENCE: 'difference',\n EXCLUSION: 'exclusion',\n HUE: 'hue',\n SATURATION: 'saturation',\n COLOR: 'color',\n LUMINOSITY: 'luminosity'\n}\n"],"mappings":";;;;;;;AA2DA,SAAgB,UAAU,KAAuB,QAAwB;CACvE,OAAO,GAAG,IAAI,YAAY,KAA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UAAU;CACV,YAAY;CACZ,SAAS;CACT,aAAa;CACb,QAAQ;CACR,cAAc;CACd,aAAa;CACb,SAAS;CACT,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,WAAW;CACX,KAAK;CACL,YAAY;CACZ,OAAO;CACP,YAAY;AACd"}
|
|
1
|
+
{"version":3,"file":"defs.js","names":[],"sources":["../../../../src/io/formats/svg/defs.ts"],"sourcesContent":["import { fromUint8Array } from 'js-base64'\n\nimport type { Fill, FontVariation, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport {\n colorToHex,\n colorToDisplayCSS,\n getDefaultRenderColorSpace,\n type RenderColorSpace\n} from '@pairdraw/scene-graph/color'\nimport {\n gradientPoint,\n invertGradientTransform,\n isIdentityGradientTransform\n} from '@pairdraw/scene-graph/gradient'\nimport { imageMimeType } from '@pairdraw/scene-graph/images'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport type { BooleanPathResolver } from '#core/io/formats/boolean-path'\nimport type { FontFaceRef } from '#core/text/font/faces'\n\nimport { svg, type SVGNode } from './node'\nimport { round } from './paths'\nimport type { SVGTextLayout } from './text/lines'\n\n/**\n * A face text is drawn in, with what sets its axes: the font size the optical size follows unless\n * `opticalSizeFromFontSize` is off, and the axes the text sets.\n */\nexport interface SVGFontRequest extends FontFaceRef {\n /** Which of the style's files draws the text, 0 for its own then its shards; 0 when left out. */\n file?: number\n fontSize: number\n variations: readonly FontVariation[]\n opticalSizeFromFontSize: boolean\n}\n\n/** The family to name a font face by instead of its own, or null to keep the face. */\nexport type SVGFontAlias = (font: SVGFontRequest) => string | null\n\nexport interface SVGExportContext {\n defs: SVGNode[]\n defIdCounter: number\n graph: SceneGraph\n colorSpace: RenderColorSpace\n /** Starts every def id, so SVGs inlined on one page cannot reference each other's defs. */\n idPrefix?: string\n /** Paints drawn in `currentColor`, such as an icon's tinted paths, so CSS `color` sets them. */\n tint?: (node: SceneNode) => readonly ('fill' | 'stroke')[]\n /** Measured line breaks. Without them, only explicit newlines start a new baseline. */\n textLayout?: SVGTextLayout\n fontAlias?: SVGFontAlias\n /** The live result path of a boolean made in Pairdraw, which stores none. */\n booleanPath?: BooleanPathResolver\n}\n\nexport function nextDefId(ctx: SVGExportContext, prefix: string): string {\n return `${ctx.idPrefix ?? ''}${prefix}${ctx.defIdCounter++}`\n}\n\nexport function formatColor(\n color: Color,\n opacity = 1,\n colorSpace: RenderColorSpace = getDefaultRenderColorSpace()\n): string {\n const alphaColor = { ...color, a: color.a * opacity }\n if (colorSpace === 'display-p3') {\n return colorToDisplayCSS(alphaColor, { colorSpace })\n }\n // Hex has no alpha. Stops and shadows already emit theirs; solid fills use `solidFillOpacity`.\n return colorToHex(alphaColor)\n}\n\n/**\n * A solid paint's SVG color. The canvas paints `opacity` and drops color alpha: `setAlphaf`\n * replaces it, and `.pen` stores a hex alpha in both fields. Display P3 carries that painted\n * alpha in the color. sRGB hex cannot, so `solidFillOpacity` emits it beside the color.\n */\nexport function formatSolidColor(\n color: Color,\n opacity: number,\n colorSpace: RenderColorSpace\n): string {\n if (colorSpace === 'display-p3') {\n return formatColor({ ...color, a: 1 }, round(opacity), colorSpace)\n }\n return formatColor(color, 1, colorSpace)\n}\n\n/**\n * `fill-opacity` for a solid paint. Omitted at full opacity so an opaque export stays unchanged.\n * Display P3 already carries the same alpha in the color `formatSolidColor` returns, unless\n * `separate` is set because that color was replaced and can no longer carry it.\n */\nexport function solidFillOpacity(\n fill: Fill,\n colorSpace: RenderColorSpace,\n separate = false\n): number | undefined {\n if (fill.type !== 'SOLID' || (colorSpace === 'display-p3' && !separate)) return undefined\n const alpha = round(fill.opacity)\n return alpha < 1 ? alpha : undefined\n}\n\nfunction createGradientDef(\n fill: Fill,\n node: SceneNode,\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n const stops = fill.gradientStops\n const t = fill.gradientTransform\n if (!stops || !t) return null\n\n const stopNodes = stops.map((s) =>\n svg('stop', {\n offset: `${round(s.position * 100)}%`,\n 'stop-color': formatColor(s.color, 1, ctx.colorSpace),\n 'stop-opacity': s.color.a < 1 ? round(s.color.a) : undefined\n })\n )\n\n const id = nextDefId(ctx, 'grad')\n\n // Gradient space in bounding-box units, mapped onto the layer as the canvas draws it.\n const toLayer = invertGradientTransform(t)\n const transform = isIdentityGradientTransform(toLayer)\n ? undefined\n : `matrix(${[toLayer.m00, toLayer.m10, toLayer.m01, toLayer.m11, toLayer.m02, toLayer.m12].map((v) => round(v, 6)).join(' ')})`\n\n if (fill.type === 'GRADIENT_LINEAR') {\n return {\n id,\n node: svg(\n 'linearGradient',\n {\n id,\n x1: 0,\n y1: 0.5,\n x2: 1,\n y2: 0.5,\n gradientUnits: 'objectBoundingBox',\n gradientTransform: transform\n },\n ...stopNodes\n )\n }\n }\n\n // SVG has no diamond gradient, so a diamond exports as the radial one it is closest to.\n if (fill.type === 'GRADIENT_RADIAL' || fill.type === 'GRADIENT_DIAMOND') {\n return {\n id,\n node: svg(\n 'radialGradient',\n {\n id,\n cx: 0.5,\n cy: 0.5,\n r: 0.5,\n gradientUnits: 'objectBoundingBox',\n gradientTransform: transform\n },\n ...stopNodes\n )\n }\n }\n\n // Nor an angular one: it exports as a radial gradient around its centre.\n if (fill.type === 'GRADIENT_ANGULAR') {\n const center = gradientPoint(t, { x: 0.5, y: 0.5 })\n const cx = round(center.x * node.width)\n const cy = round(center.y * node.height)\n const r = Math.max(node.width, node.height)\n return {\n id,\n node: svg('radialGradient', { id, cx, cy, r, gradientUnits: 'userSpaceOnUse' }, ...stopNodes)\n }\n }\n\n return null\n}\n\nfunction createImagePattern(\n fill: Fill,\n node: SceneNode,\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n if (!fill.imageHash) return null\n const data = ctx.graph.images.get(fill.imageHash)\n if (!data) return null\n\n const id = nextDefId(ctx, 'img')\n const base64 = fromUint8Array(data)\n const mime = imageMimeType(data)\n\n return {\n id,\n node: svg(\n 'pattern',\n {\n id,\n patternUnits: 'objectBoundingBox',\n width: 1,\n height: 1,\n patternTransform: fill.imageRotation\n ? `rotate(${round(fill.imageRotation)} 0.5 0.5)`\n : undefined\n },\n svg('image', {\n href: `data:${mime};base64,${base64}`,\n width: node.width,\n height: node.height,\n preserveAspectRatio: fill.imageScaleMode === 'FIT' ? 'xMidYMid meet' : 'xMidYMid slice'\n })\n )\n }\n}\n\nexport function resolveFill(fill: Fill, node: SceneNode, ctx: SVGExportContext): string | null {\n if (!fill.visible) return null\n\n if (fill.type === 'SOLID') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace)\n }\n\n // SVG has no mesh element: a mesh exports its own color, as `.fig` records carry it.\n if (fill.type === 'MESH') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace)\n }\n\n // The canvas draws a pattern, noise or custom paint as its own colour when the format has no\n // element for it, so the export must not drop the layer.\n if (fill.type === 'PATTERN' || fill.type === 'NOISE' || fill.type === 'CUSTOM') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace)\n }\n\n if (fill.type.startsWith('GRADIENT')) {\n const grad = createGradientDef(fill, node, ctx)\n if (grad) {\n ctx.defs.push(grad.node)\n return `url(#${grad.id})`\n }\n }\n\n if (fill.type === 'IMAGE') {\n const pattern = createImagePattern(fill, node, ctx)\n if (pattern) {\n ctx.defs.push(pattern.node)\n return `url(#${pattern.id})`\n }\n }\n\n return null\n}\n\nexport const SVG_STROKE_CAP: Record<string, string> = {\n NONE: 'butt',\n ROUND: 'round',\n SQUARE: 'square'\n}\n\nexport const SVG_STROKE_JOIN: Record<string, string> = {\n MITER: 'miter',\n ROUND: 'round',\n BEVEL: 'bevel'\n}\n\nexport const SVG_BLEND_MODE: Record<string, string> = {\n NORMAL: 'normal',\n DARKEN: 'darken',\n MULTIPLY: 'multiply',\n COLOR_BURN: 'color-burn',\n LIGHTEN: 'lighten',\n LINEAR_BURN: 'plus-darker',\n SCREEN: 'screen',\n LINEAR_DODGE: 'plus-lighter',\n COLOR_DODGE: 'color-dodge',\n OVERLAY: 'overlay',\n SOFT_LIGHT: 'soft-light',\n HARD_LIGHT: 'hard-light',\n DIFFERENCE: 'difference',\n EXCLUSION: 'exclusion',\n HUE: 'hue',\n SATURATION: 'saturation',\n COLOR: 'color',\n LUMINOSITY: 'luminosity'\n}\n"],"mappings":";;;;;;;AAuDA,SAAgB,UAAU,KAAuB,QAAwB;CACvE,OAAO,GAAG,IAAI,YAAY,KAAK,SAAS,IAAI;AAC9C;AAEA,SAAgB,YACd,OACA,UAAU,GACV,aAA+B,2BAA2B,GAClD;CACR,MAAM,aAAa;EAAE,GAAG;EAAO,GAAG,MAAM,IAAI;CAAQ;CACpD,IAAI,eAAe,cACjB,OAAO,kBAAkB,YAAY,EAAE,WAAW,CAAC;CAGrD,OAAO,WAAW,UAAU;AAC9B;;;;;;AAOA,SAAgB,iBACd,OACA,SACA,YACQ;CACR,IAAI,eAAe,cACjB,OAAO,YAAY;EAAE,GAAG;EAAO,GAAG;CAAE,GAAG,MAAM,OAAO,GAAG,UAAU;CAEnE,OAAO,YAAY,OAAO,GAAG,UAAU;AACzC;;;;;;AAOA,SAAgB,iBACd,MACA,YACA,WAAW,OACS;CACpB,IAAI,KAAK,SAAS,WAAY,eAAe,gBAAgB,CAAC,UAAW,OAAO,KAAA;CAChF,MAAM,QAAQ,MAAM,KAAK,OAAO;CAChC,OAAO,QAAQ,IAAI,QAAQ,KAAA;AAC7B;AAEA,SAAS,kBACP,MACA,MACA,KACsC;CACtC,MAAM,QAAQ,KAAK;CACnB,MAAM,IAAI,KAAK;CACf,IAAI,CAAC,SAAS,CAAC,GAAG,OAAO;CAEzB,MAAM,YAAY,MAAM,KAAK,MAC3B,IAAI,QAAQ;EACV,QAAQ,GAAG,MAAM,EAAE,WAAW,GAAG,EAAE;EACnC,cAAc,YAAY,EAAE,OAAO,GAAG,IAAI,UAAU;EACpD,gBAAgB,EAAE,MAAM,IAAI,IAAI,MAAM,EAAE,MAAM,CAAC,IAAI,KAAA;CACrD,CAAC,CACH;CAEA,MAAM,KAAK,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AU;CACV,YAAY;CACZ,SAAS;CACT,aAAa;CACb,QAAQ;CACR,cAAc;CACd,aAAa;CACb,SAAS;CACT,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,WAAW;CACX,KAAK;CACL,YAAY;CACZ,OAAO;CACP,YAAY;AACd"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SVGNode } from "./node.js";
|
|
2
|
+
import { SVGExportContext } from "./defs.js";
|
|
3
|
+
import { SceneNode } from "@pairdraw/scene-graph";
|
|
4
|
+
//#region src/io/formats/svg/effects.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The filter for a layer's visible effects, `null` when it has none SVG can draw. Shadows and
|
|
7
|
+
* layer blurs come first, then a texture roughens the result and noise grains it, as Figma's SVG
|
|
8
|
+
* export orders them. Shader effects cannot be drawn as filters and are left out.
|
|
9
|
+
*/
|
|
10
|
+
declare function createFilterDef(node: SceneNode, ctx: SVGExportContext): {
|
|
11
|
+
id: string;
|
|
12
|
+
node: SVGNode;
|
|
13
|
+
} | null;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { createFilterDef };
|
|
16
|
+
//# sourceMappingURL=effects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.d.ts","names":[],"sources":["../../../../src/io/formats/svg/effects.ts"],"mappings":";;;;;;;;;iBA0CgB,gBACd,MAAM,WACN,KAAK;EACF;EAAY,MAAM"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { svg } from "./node.js";
|
|
2
|
+
import { round } from "./paths.js";
|
|
3
|
+
import { nextDefId } from "./defs.js";
|
|
4
|
+
import { FilterBuilder, floodColor } from "./filter.js";
|
|
5
|
+
import { noiseFilter, textureFilter } from "./grain.js";
|
|
6
|
+
//#region src/io/formats/svg/effects.ts
|
|
7
|
+
/**
|
|
8
|
+
* A filter region that holds what every visible effect draws, in the layer's own coordinates. A
|
|
9
|
+
* texture moves the layer's edges by its radius, and a shadow reaches by its blur and spread.
|
|
10
|
+
*/
|
|
11
|
+
function filterRegion(node, id, effects) {
|
|
12
|
+
let reach = 0;
|
|
13
|
+
for (const effect of effects) {
|
|
14
|
+
if (effect.type === "NOISE") continue;
|
|
15
|
+
if (effect.type === "TEXTURE") {
|
|
16
|
+
reach = Math.max(reach, effect.radius);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const offset = Math.max(Math.abs(effect.offset.x), Math.abs(effect.offset.y));
|
|
20
|
+
reach = Math.max(reach, effect.radius + effect.spread + offset);
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
id,
|
|
24
|
+
x: round(-reach),
|
|
25
|
+
y: round(-reach),
|
|
26
|
+
width: round(node.width + reach * 2),
|
|
27
|
+
height: round(node.height + reach * 2),
|
|
28
|
+
filterUnits: "userSpaceOnUse",
|
|
29
|
+
"color-interpolation-filters": "sRGB"
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The filter for a layer's visible effects, `null` when it has none SVG can draw. Shadows and
|
|
34
|
+
* layer blurs come first, then a texture roughens the result and noise grains it, as Figma's SVG
|
|
35
|
+
* export orders them. Shader effects cannot be drawn as filters and are left out.
|
|
36
|
+
*/
|
|
37
|
+
function createFilterDef(node, ctx) {
|
|
38
|
+
const visible = node.effects.filter((effect) => effect.visible && effect.type !== "SHADER");
|
|
39
|
+
if (visible.length === 0) return null;
|
|
40
|
+
const id = nextDefId(ctx, "fx");
|
|
41
|
+
const filter = new FilterBuilder(id, ctx);
|
|
42
|
+
let shape = "SourceGraphic";
|
|
43
|
+
for (const effect of visible) {
|
|
44
|
+
if (effect.type === "DROP_SHADOW") {
|
|
45
|
+
const dropped = filter.result("dropShadow");
|
|
46
|
+
filter.push("feDropShadow", {
|
|
47
|
+
in: shape,
|
|
48
|
+
dx: round(effect.offset.x),
|
|
49
|
+
dy: round(effect.offset.y),
|
|
50
|
+
stdDeviation: round(effect.radius / 2),
|
|
51
|
+
"flood-color": floodColor(effect.color, ctx.colorSpace),
|
|
52
|
+
"flood-opacity": round(effect.color.a),
|
|
53
|
+
result: dropped
|
|
54
|
+
});
|
|
55
|
+
shape = dropped;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (effect.type === "INNER_SHADOW") {
|
|
59
|
+
const blur = filter.result("innerBlur");
|
|
60
|
+
const offset = filter.result("innerOffset");
|
|
61
|
+
const inverted = filter.result("innerInverse");
|
|
62
|
+
const shadow = filter.result("innerShadow");
|
|
63
|
+
const composited = filter.result("innerComposited");
|
|
64
|
+
filter.push("feGaussianBlur", {
|
|
65
|
+
in: shape,
|
|
66
|
+
stdDeviation: round(effect.radius / 2),
|
|
67
|
+
result: blur
|
|
68
|
+
});
|
|
69
|
+
filter.push("feOffset", {
|
|
70
|
+
in: blur,
|
|
71
|
+
dx: round(effect.offset.x),
|
|
72
|
+
dy: round(effect.offset.y),
|
|
73
|
+
result: offset
|
|
74
|
+
});
|
|
75
|
+
filter.push("feComposite", {
|
|
76
|
+
in: shape,
|
|
77
|
+
in2: offset,
|
|
78
|
+
operator: "out",
|
|
79
|
+
result: inverted
|
|
80
|
+
});
|
|
81
|
+
filter.push("feFlood", {
|
|
82
|
+
"flood-color": floodColor(effect.color, ctx.colorSpace),
|
|
83
|
+
"flood-opacity": round(effect.color.a),
|
|
84
|
+
result: shadow
|
|
85
|
+
});
|
|
86
|
+
filter.push("feComposite", {
|
|
87
|
+
in: shadow,
|
|
88
|
+
in2: inverted,
|
|
89
|
+
operator: "in",
|
|
90
|
+
result: `${shadow}Masked`
|
|
91
|
+
});
|
|
92
|
+
filter.push("feComposite", {
|
|
93
|
+
in: `${shadow}Masked`,
|
|
94
|
+
in2: shape,
|
|
95
|
+
operator: "over",
|
|
96
|
+
result: composited
|
|
97
|
+
});
|
|
98
|
+
shape = composited;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (effect.type === "TEXTURE") {
|
|
102
|
+
shape = textureFilter(filter, effect, shape);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (effect.type === "NOISE") {
|
|
106
|
+
shape = noiseFilter(filter, effect, shape);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (effect.radius <= 0) continue;
|
|
110
|
+
const blurred = filter.result("layerBlur");
|
|
111
|
+
filter.push("feGaussianBlur", {
|
|
112
|
+
in: shape,
|
|
113
|
+
stdDeviation: round(effect.radius / 2),
|
|
114
|
+
result: blurred
|
|
115
|
+
});
|
|
116
|
+
shape = blurred;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
id,
|
|
120
|
+
node: svg("filter", filterRegion(node, id, visible), ...filter.primitives)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
export { createFilterDef };
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=effects.js.map
|