@pairdraw/core 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/noise/render.js +1 -1
- package/dist/canvas/noise/render.js.map +1 -1
- package/dist/canvas/noise/shader.d.ts +6 -3
- package/dist/canvas/noise/shader.d.ts.map +1 -1
- package/dist/canvas/noise/shader.js +12 -7
- package/dist/canvas/noise/shader.js.map +1 -1
- package/dist/canvas/noise/tile.d.ts.map +1 -1
- package/dist/canvas/noise/tile.js +2 -1
- package/dist/canvas/noise/tile.js.map +1 -1
- package/dist/canvas/renderer/colors.d.ts +20 -5
- package/dist/canvas/renderer/colors.d.ts.map +1 -1
- package/dist/canvas/renderer/colors.js +48 -42
- package/dist/canvas/renderer/colors.js.map +1 -1
- package/dist/canvas/renderer/document-surface.d.ts +25 -0
- package/dist/canvas/renderer/document-surface.d.ts.map +1 -0
- package/dist/canvas/renderer/document-surface.js +46 -0
- package/dist/canvas/renderer/document-surface.js.map +1 -0
- package/dist/canvas/renderer/fonts.d.ts.map +1 -1
- package/dist/canvas/renderer/fonts.js +6 -4
- package/dist/canvas/renderer/fonts.js.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +4 -3
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +1 -0
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +23 -2
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/retained-backing.d.ts.map +1 -1
- package/dist/canvas/renderer/retained-backing.js +2 -1
- package/dist/canvas/renderer/retained-backing.js.map +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.js +2 -7
- package/dist/canvas/renderer/tiles/surface-pool.js.map +1 -1
- package/dist/canvas/renderer.d.ts +20 -2
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +28 -4
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +4 -3
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/shaders/effect.d.ts.map +1 -1
- package/dist/canvas/shaders/effect.js +2 -1
- package/dist/canvas/shaders/effect.js.map +1 -1
- package/dist/canvas/shadows/shape.d.ts.map +1 -1
- package/dist/canvas/shadows/shape.js +4 -2
- package/dist/canvas/shadows/shape.js.map +1 -1
- package/dist/canvas/shadows.d.ts.map +1 -1
- package/dist/canvas/shadows.js +4 -2
- package/dist/canvas/shadows.js.map +1 -1
- package/dist/canvas/text/decorations.d.ts +2 -2
- package/dist/canvas/text/decorations.d.ts.map +1 -1
- package/dist/canvas/text/decorations.js +5 -5
- package/dist/canvas/text/decorations.js.map +1 -1
- package/dist/canvas/text/index.js +1 -1
- package/dist/canvas/text/index.js.map +1 -1
- package/dist/canvas/text/paragraph/index.d.ts +2 -2
- package/dist/canvas/text/paragraph/index.d.ts.map +1 -1
- package/dist/canvas/text/paragraph/index.js +16 -5
- package/dist/canvas/text/paragraph/index.js.map +1 -1
- package/dist/canvas/text/renderer.d.ts +2 -1
- package/dist/canvas/text/renderer.d.ts.map +1 -1
- package/dist/canvas/text/shape.js +4 -4
- package/dist/canvas/text/shape.js.map +1 -1
- package/dist/canvas/texture.d.ts.map +1 -1
- package/dist/canvas/texture.js +2 -1
- package/dist/canvas/texture.js.map +1 -1
- package/dist/design-memory/rules.js +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/clipboard/assets.d.ts.map +1 -1
- package/dist/editor/clipboard/assets.js +2 -2
- package/dist/editor/clipboard/assets.js.map +1 -1
- package/dist/editor/clipboard/component-matches.d.ts +13 -0
- package/dist/editor/clipboard/component-matches.d.ts.map +1 -0
- package/dist/editor/clipboard/component-matches.js +50 -0
- package/dist/editor/clipboard/component-matches.js.map +1 -0
- package/dist/editor/clipboard/dependencies.d.ts +7 -0
- package/dist/editor/clipboard/dependencies.d.ts.map +1 -1
- package/dist/editor/clipboard/dependencies.js +5 -0
- package/dist/editor/clipboard/dependencies.js.map +1 -1
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +48 -19
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/components/properties.d.ts.map +1 -1
- package/dist/editor/components/properties.js +3 -3
- package/dist/editor/components/properties.js.map +1 -1
- package/dist/editor/create.d.ts +1 -1
- package/dist/editor/eyedropper.d.ts +1 -1
- package/dist/editor/eyedropper.d.ts.map +1 -1
- package/dist/editor/eyedropper.js +6 -3
- package/dist/editor/eyedropper.js.map +1 -1
- package/dist/editor/history/atomic-tool.d.ts.map +1 -1
- package/dist/editor/history/atomic-tool.js +3 -2
- package/dist/editor/history/atomic-tool.js.map +1 -1
- package/dist/editor/shapes/pencil.js +1 -1
- package/dist/editor/structure/state.d.ts.map +1 -1
- package/dist/editor/structure/state.js +2 -2
- package/dist/editor/structure/state.js.map +1 -1
- package/dist/editor/text.d.ts.map +1 -1
- package/dist/editor/text.js +2 -2
- package/dist/editor/text.js.map +1 -1
- package/dist/editor/variables.js +3 -3
- package/dist/editor/variables.js.map +1 -1
- package/dist/figma-api/fresh-read.d.ts +15 -0
- package/dist/figma-api/fresh-read.d.ts.map +1 -0
- package/dist/figma-api/fresh-read.js +54 -0
- package/dist/figma-api/fresh-read.js.map +1 -0
- package/dist/figma-api/graph-ref.d.ts +9 -0
- package/dist/figma-api/graph-ref.d.ts.map +1 -0
- package/dist/figma-api/graph-ref.js +14 -0
- package/dist/figma-api/graph-ref.js.map +1 -0
- package/dist/figma-api/index.d.ts +6 -1
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +12 -5
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/pending-layout.d.ts +3 -3
- package/dist/figma-api/pending-layout.d.ts.map +1 -1
- package/dist/figma-api/pending-layout.js +7 -3
- package/dist/figma-api/pending-layout.js.map +1 -1
- package/dist/figma-api/pending-sync.d.ts +1 -1
- package/dist/figma-api/pending-sync.d.ts.map +1 -1
- package/dist/figma-api/pending-sync.js +3 -1
- package/dist/figma-api/pending-sync.js.map +1 -1
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +3 -2
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +20 -4
- package/dist/figma-api/reactions.d.ts.map +1 -1
- package/dist/figma-api/reactions.js +49 -3
- package/dist/figma-api/reactions.js.map +1 -1
- package/dist/figma-api/variables/index.d.ts.map +1 -1
- package/dist/figma-api/variables/index.js +2 -2
- package/dist/figma-api/variables/index.js.map +1 -1
- package/dist/io/formats/design-tokens/css/known.js +1 -1
- package/dist/io/formats/design-tokens/css/known.js.map +1 -1
- package/dist/io/formats/design-tokens/css/read.d.ts +3 -1
- package/dist/io/formats/design-tokens/css/read.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/css/read.js +11 -5
- package/dist/io/formats/design-tokens/css/read.js.map +1 -1
- package/dist/io/formats/design-tokens/css/sync.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/css/sync.js +17 -4
- package/dist/io/formats/design-tokens/css/sync.js.map +1 -1
- package/dist/io/formats/design-tokens/css/values.d.ts +6 -5
- package/dist/io/formats/design-tokens/css/values.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/css/values.js +24 -8
- package/dist/io/formats/design-tokens/css/values.js.map +1 -1
- package/dist/io/formats/design-tokens/decode.d.ts +7 -6
- package/dist/io/formats/design-tokens/decode.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/decode.js +13 -12
- package/dist/io/formats/design-tokens/decode.js.map +1 -1
- package/dist/io/formats/design-tokens/export.js +3 -3
- package/dist/io/formats/design-tokens/export.js.map +1 -1
- package/dist/io/formats/design-tokens/plan/index.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/index.js +4 -3
- package/dist/io/formats/design-tokens/plan/index.js.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.js +9 -9
- package/dist/io/formats/design-tokens/plan/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/styles.d.ts +4 -4
- package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/styles.js +7 -7
- package/dist/io/formats/design-tokens/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/sync/drift.js +2 -2
- package/dist/io/formats/design-tokens/sync/drift.js.map +1 -1
- package/dist/io/formats/design-tokens/values.d.ts +10 -5
- package/dist/io/formats/design-tokens/values.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/values.js +13 -7
- package/dist/io/formats/design-tokens/values.js.map +1 -1
- package/dist/io/formats/drawio/label.js +1 -1
- package/dist/io/formats/drawio/paint.js +1 -1
- package/dist/io/formats/drawio/warnings.js +2 -2
- package/dist/io/formats/drawio/warnings.js.map +1 -1
- package/dist/io/formats/fig/export/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/index.js +15 -3
- package/dist/io/formats/fig/export/index.js.map +1 -1
- package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/patch/index.js +2 -1
- package/dist/io/formats/fig/export/patch/index.js.map +1 -1
- package/dist/io/formats/fig/export/setup.d.ts +7 -2
- package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
- package/dist/io/formats/fig/export/setup.js +12 -13
- package/dist/io/formats/fig/export/setup.js.map +1 -1
- package/dist/io/formats/fig/export/variables.d.ts.map +1 -1
- package/dist/io/formats/fig/export/variables.js +9 -7
- package/dist/io/formats/fig/export/variables.js.map +1 -1
- package/dist/io/formats/html/vectors.js +1 -0
- package/dist/io/formats/html/vectors.js.map +1 -1
- package/dist/io/formats/mermaid/layers.js +2 -2
- package/dist/io/formats/mermaid/layers.js.map +1 -1
- package/dist/io/formats/mermaid/styles.js +1 -1
- package/dist/io/formats/pdf/export.d.ts.map +1 -1
- package/dist/io/formats/pdf/export.js +1 -0
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/pdf/prepare.d.ts +4 -4
- package/dist/io/formats/pdf/prepare.d.ts.map +1 -1
- package/dist/io/formats/pdf/prepare.js +2 -2
- package/dist/io/formats/pdf/prepare.js.map +1 -1
- package/dist/io/formats/pen/index.js +4 -2
- package/dist/io/formats/pen/index.js.map +1 -1
- package/dist/io/formats/pptx/style.js +1 -1
- package/dist/io/formats/raster/render.d.ts +1 -1
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +9 -4
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts +6 -3
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +12 -11
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/effects.js +2 -2
- package/dist/io/formats/svg/effects.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts +5 -2
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +4 -2
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/filter.d.ts +4 -1
- package/dist/io/formats/svg/filter.d.ts.map +1 -1
- package/dist/io/formats/svg/filter.js +6 -2
- package/dist/io/formats/svg/filter.js.map +1 -1
- package/dist/io/formats/svg/grain.js +1 -1
- package/dist/io/formats/svg/grain.js.map +1 -1
- package/dist/io/formats/svg/import.d.ts +4 -2
- package/dist/io/formats/svg/import.d.ts.map +1 -1
- package/dist/io/formats/svg/import.js +2 -1
- package/dist/io/formats/svg/import.js.map +1 -1
- package/dist/io/formats/svg/text/export.d.ts.map +1 -1
- package/dist/io/formats/svg/text/export.js +8 -8
- package/dist/io/formats/svg/text/export.js.map +1 -1
- package/dist/io/formats/svg/text/layout.js +2 -2
- package/dist/io/formats/svg/text/layout.js.map +1 -1
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +1 -0
- package/dist/io/formats.js.map +1 -1
- package/dist/io/subgraph.d.ts.map +1 -1
- package/dist/io/subgraph.js +1 -1
- package/dist/io/subgraph.js.map +1 -1
- package/dist/io/types.d.ts +1 -1
- package/dist/kiwi/fig/session/options.d.ts +3 -0
- package/dist/kiwi/fig/session/options.d.ts.map +1 -1
- package/dist/kiwi/fig/session/options.js +4 -0
- package/dist/kiwi/fig/session/options.js.map +1 -1
- package/dist/layout/yoga-helpers.d.ts +2 -1
- package/dist/layout/yoga-helpers.d.ts.map +1 -1
- package/dist/layout/yoga-helpers.js +7 -1
- package/dist/layout/yoga-helpers.js.map +1 -1
- package/dist/layout.js +24 -1
- package/dist/layout.js.map +1 -1
- package/dist/lint/fixes.js +1 -1
- package/dist/lint/linter.js +2 -2
- package/dist/lint/linter.js.map +1 -1
- package/dist/pairdraw-api/comments.d.ts +4 -1
- package/dist/pairdraw-api/comments.d.ts.map +1 -1
- package/dist/pairdraw-api/comments.js +5 -0
- package/dist/pairdraw-api/comments.js.map +1 -1
- package/dist/pairdraw-api/index.d.ts +3 -3
- package/dist/pairdraw-api/index.d.ts.map +1 -1
- package/dist/pairdraw-api/index.js +5 -5
- package/dist/pairdraw-api/index.js.map +1 -1
- package/dist/pairdraw-api/nodes.d.ts +1 -1
- package/dist/prototype/scene.js +1 -1
- package/dist/rpc/analyze-commands.js +1 -1
- package/dist/rpc/read-commands.d.ts +2 -2
- package/dist/rpc/read-commands.js +3 -3
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/rpc/variables-command.js +2 -2
- package/dist/rpc/variables-command.js.map +1 -1
- package/dist/text/font/provider.d.ts +15 -0
- package/dist/text/font/provider.d.ts.map +1 -0
- package/dist/text/font/provider.js +18 -0
- package/dist/text/font/provider.js.map +1 -0
- package/dist/text/font/readiness.d.ts +32 -0
- package/dist/text/font/readiness.d.ts.map +1 -0
- package/dist/text/font/{status.js → readiness.js} +8 -4
- package/dist/text/font/readiness.js.map +1 -0
- package/dist/text/index.d.ts +4 -3
- package/dist/text/index.js +4 -3
- package/dist/text/prepare.d.ts +9 -4
- package/dist/text/prepare.d.ts.map +1 -1
- package/dist/text/prepare.js +9 -4
- package/dist/text/prepare.js.map +1 -1
- package/dist/tools/analyze/colors.js +1 -1
- package/dist/tools/analyze/responsive/index.js +7 -18
- package/dist/tools/analyze/responsive/index.js.map +1 -1
- package/dist/tools/analyze/responsive/widths.d.ts +27 -0
- package/dist/tools/analyze/responsive/widths.d.ts.map +1 -0
- package/dist/tools/analyze/responsive/widths.js +49 -0
- package/dist/tools/analyze/responsive/widths.js.map +1 -0
- package/dist/tools/analyze.d.ts +2 -1
- package/dist/tools/analyze.js +2 -1
- package/dist/tools/codegen/tokens.d.ts.map +1 -1
- package/dist/tools/codegen/tokens.js +2 -2
- package/dist/tools/codegen/tokens.js.map +1 -1
- package/dist/tools/comments.d.ts.map +1 -1
- package/dist/tools/comments.js +2 -2
- package/dist/tools/comments.js.map +1 -1
- package/dist/tools/component-catalog.d.ts.map +1 -1
- package/dist/tools/component-catalog.js +5 -3
- package/dist/tools/component-catalog.js.map +1 -1
- package/dist/tools/create/basic.js +1 -1
- package/dist/tools/create/behaviours.js +1 -1
- package/dist/tools/create/html.d.ts.map +1 -1
- package/dist/tools/create/html.js +1 -3
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.js +2 -2
- package/dist/tools/create/icons.js.map +1 -1
- package/dist/tools/create/mermaid.js +1 -1
- package/dist/tools/create/render.js +1 -1
- package/dist/tools/create/svg.js +5 -2
- package/dist/tools/create/svg.js.map +1 -1
- package/dist/tools/create/vector.js +3 -3
- package/dist/tools/create/vector.js.map +1 -1
- package/dist/tools/css/shorthand.d.ts +20 -0
- package/dist/tools/css/shorthand.d.ts.map +1 -0
- package/dist/tools/css/shorthand.js +54 -0
- package/dist/tools/css/shorthand.js.map +1 -0
- package/dist/tools/describe/index.js +2 -2
- package/dist/tools/describe/index.js.map +1 -1
- package/dist/tools/describe/issues.js +1 -1
- package/dist/tools/html-host.d.ts.map +1 -1
- package/dist/tools/html-host.js +5 -3
- package/dist/tools/html-host.js.map +1 -1
- package/dist/tools/image-ai/apply.d.ts.map +1 -1
- package/dist/tools/image-ai/apply.js +1 -3
- package/dist/tools/image-ai/apply.js.map +1 -1
- package/dist/tools/image-ai/generate.js +1 -1
- package/dist/tools/image-ai/service.d.ts.map +1 -1
- package/dist/tools/image-ai/service.js +5 -3
- package/dist/tools/image-ai/service.js.map +1 -1
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.js +2 -1
- package/dist/tools/modify/effects.js +1 -1
- package/dist/tools/modify/effects.js.map +1 -1
- package/dist/tools/modify/geometry.d.ts.map +1 -1
- package/dist/tools/modify/geometry.js +14 -3
- package/dist/tools/modify/geometry.js.map +1 -1
- package/dist/tools/modify/layout.d.ts.map +1 -1
- package/dist/tools/modify/layout.js +35 -8
- package/dist/tools/modify/layout.js.map +1 -1
- package/dist/tools/modify/matching.d.ts.map +1 -1
- package/dist/tools/modify/matching.js +10 -10
- package/dist/tools/modify/matching.js.map +1 -1
- package/dist/tools/modify/paint.d.ts.map +1 -1
- package/dist/tools/modify/paint.js +57 -5
- package/dist/tools/modify/paint.js.map +1 -1
- package/dist/tools/modify/reactions.d.ts.map +1 -1
- package/dist/tools/modify/reactions.js +2 -2
- package/dist/tools/modify/reactions.js.map +1 -1
- package/dist/tools/modify/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +3 -3
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/prompts/codegen.js +1 -1
- package/dist/tools/prompts/codegen.js.map +1 -1
- package/dist/tools/read/css.d.ts +14 -0
- package/dist/tools/read/css.d.ts.map +1 -0
- package/dist/tools/read/css.js +306 -0
- package/dist/tools/read/css.js.map +1 -0
- package/dist/tools/read/libraries.js +1 -1
- package/dist/tools/read/reactions.js +1 -1
- package/dist/tools/read/reactions.js.map +1 -1
- package/dist/tools/read/space.d.ts.map +1 -1
- package/dist/tools/read/space.js +0 -2
- package/dist/tools/read/space.js.map +1 -1
- package/dist/tools/read.d.ts +2 -1
- package/dist/tools/read.js +2 -1
- package/dist/tools/registry/core.d.ts +1 -1
- package/dist/tools/registry/core.js +3 -1
- package/dist/tools/registry/core.js.map +1 -1
- package/dist/tools/schema.d.ts +6 -4
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +9 -5
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/script/host.d.ts.map +1 -1
- package/dist/tools/script/host.js +5 -3
- package/dist/tools/script/host.js.map +1 -1
- package/dist/tools/variables/collections.js +1 -1
- package/dist/tools/variables/collections.js.map +1 -1
- package/dist/tools/variables/values.d.ts.map +1 -1
- package/dist/tools/variables/values.js +4 -4
- package/dist/tools/variables/values.js.map +1 -1
- package/dist/tools/vector/vectorize.d.ts.map +1 -1
- package/dist/tools/vector/vectorize.js +6 -4
- package/dist/tools/vector/vectorize.js.map +1 -1
- package/dist/tools/video-host.d.ts.map +1 -1
- package/dist/tools/video-host.js +5 -3
- package/dist/tools/video-host.js.map +1 -1
- package/dist/vector/vectorize/svg/gradients.d.ts +2 -2
- package/dist/vector/vectorize/svg/gradients.d.ts.map +1 -1
- package/dist/vector/vectorize/svg/gradients.js +5 -5
- package/dist/vector/vectorize/svg/gradients.js.map +1 -1
- package/dist/vector/vectorize/svg/to-vectors.d.ts +3 -1
- package/dist/vector/vectorize/svg/to-vectors.d.ts.map +1 -1
- package/dist/vector/vectorize/svg/to-vectors.js +13 -12
- package/dist/vector/vectorize/svg/to-vectors.js.map +1 -1
- package/package.json +9 -9
- package/src/canvas/noise/render.ts +1 -1
- package/src/canvas/noise/shader.ts +13 -5
- package/src/canvas/noise/tile.ts +2 -1
- package/src/canvas/renderer/colors.ts +76 -50
- package/src/canvas/renderer/document-surface.ts +53 -0
- package/src/canvas/renderer/fonts.ts +6 -4
- package/src/canvas/renderer/lifecycle.ts +4 -4
- package/src/canvas/renderer/methods.ts +1 -0
- package/src/canvas/renderer/pipeline.ts +21 -3
- package/src/canvas/renderer/retained-backing.ts +2 -1
- package/src/canvas/renderer/tiles/surface-pool.ts +9 -7
- package/src/canvas/renderer.ts +36 -11
- package/src/canvas/scene.ts +4 -3
- package/src/canvas/shaders/effect.ts +2 -1
- package/src/canvas/shadows/shape.ts +4 -2
- package/src/canvas/shadows.ts +5 -2
- package/src/canvas/text/decorations.ts +15 -5
- package/src/canvas/text/index.ts +9 -1
- package/src/canvas/text/paragraph/index.ts +16 -6
- package/src/canvas/text/renderer.ts +2 -1
- package/src/canvas/text/shape.ts +4 -4
- package/src/canvas/texture.ts +2 -1
- package/src/editor/clipboard/assets.ts +6 -2
- package/src/editor/clipboard/component-matches.ts +65 -0
- package/src/editor/clipboard/dependencies.ts +22 -1
- package/src/editor/clipboard.ts +74 -20
- package/src/editor/components/properties.ts +3 -2
- package/src/editor/eyedropper.ts +14 -4
- package/src/editor/history/atomic-tool.ts +3 -2
- package/src/editor/structure/state.ts +2 -1
- package/src/editor/text.ts +2 -1
- package/src/editor/variables.ts +3 -3
- package/src/figma-api/fresh-read.ts +57 -0
- package/src/figma-api/graph-ref.ts +13 -0
- package/src/figma-api/index.ts +12 -4
- package/src/figma-api/pending-layout.ts +7 -3
- package/src/figma-api/pending-sync.ts +4 -1
- package/src/figma-api/proxy.ts +2 -1
- package/src/figma-api/reactions.ts +91 -10
- package/src/figma-api/variables/index.ts +5 -4
- package/src/io/formats/design-tokens/css/known.ts +1 -1
- package/src/io/formats/design-tokens/css/read.ts +20 -7
- package/src/io/formats/design-tokens/css/sync.ts +9 -4
- package/src/io/formats/design-tokens/css/values.ts +37 -9
- package/src/io/formats/design-tokens/decode.ts +17 -12
- package/src/io/formats/design-tokens/export.ts +3 -3
- package/src/io/formats/design-tokens/plan/index.ts +6 -5
- package/src/io/formats/design-tokens/plan/styles.ts +37 -10
- package/src/io/formats/design-tokens/styles.ts +10 -7
- package/src/io/formats/design-tokens/sync/drift.ts +6 -4
- package/src/io/formats/design-tokens/values.ts +15 -8
- package/src/io/formats/drawio/warnings.ts +2 -2
- package/src/io/formats/fig/export/index.ts +36 -3
- package/src/io/formats/fig/export/patch/index.ts +4 -1
- package/src/io/formats/fig/export/setup.ts +25 -15
- package/src/io/formats/fig/export/variables.ts +17 -6
- package/src/io/formats/html/vectors.ts +1 -0
- package/src/io/formats/mermaid/layers.ts +2 -2
- package/src/io/formats/pdf/export.ts +1 -0
- package/src/io/formats/pdf/prepare.ts +6 -6
- package/src/io/formats/pen/index.ts +5 -2
- package/src/io/formats/raster/render.ts +12 -4
- package/src/io/formats/svg/defs.ts +26 -14
- package/src/io/formats/svg/effects.ts +2 -2
- package/src/io/formats/svg/export.ts +17 -3
- package/src/io/formats/svg/filter.ts +12 -2
- package/src/io/formats/svg/grain.ts +1 -1
- package/src/io/formats/svg/import.ts +6 -3
- package/src/io/formats/svg/text/export.ts +10 -8
- package/src/io/formats/svg/text/layout.ts +2 -2
- package/src/io/formats.ts +8 -1
- package/src/io/subgraph.ts +4 -1
- package/src/kiwi/fig/session/options.ts +4 -1
- package/src/layout/yoga-helpers.ts +8 -0
- package/src/layout.ts +47 -1
- package/src/lint/linter.ts +1 -1
- package/src/pairdraw-api/comments.ts +6 -0
- package/src/pairdraw-api/index.ts +7 -9
- package/src/rpc/read-commands.ts +4 -4
- package/src/rpc/variables-command.ts +2 -2
- package/src/text/font/provider.ts +26 -0
- package/src/text/font/{status.ts → readiness.ts} +13 -9
- package/src/text/index.ts +2 -1
- package/src/text/prepare.ts +9 -4
- package/src/tools/analyze/responsive/index.ts +8 -15
- package/src/tools/analyze/responsive/widths.ts +63 -0
- package/src/tools/analyze.ts +2 -0
- package/src/tools/codegen/tokens.ts +4 -2
- package/src/tools/comments.ts +6 -4
- package/src/tools/component-catalog.ts +5 -3
- package/src/tools/create/html.ts +0 -3
- package/src/tools/create/icons.ts +1 -1
- package/src/tools/create/svg.ts +4 -1
- package/src/tools/create/vector.ts +2 -2
- package/src/tools/css/shorthand.ts +64 -0
- package/src/tools/describe/index.ts +2 -8
- package/src/tools/html-host.ts +5 -3
- package/src/tools/image-ai/apply.ts +0 -2
- package/src/tools/image-ai/service.ts +5 -3
- package/src/tools/index.ts +2 -0
- package/src/tools/modify/effects.ts +1 -1
- package/src/tools/modify/geometry.ts +16 -3
- package/src/tools/modify/layout.ts +47 -13
- package/src/tools/modify/matching.ts +14 -11
- package/src/tools/modify/paint.ts +85 -5
- package/src/tools/modify/reactions.ts +3 -2
- package/src/tools/modify/text.ts +15 -11
- package/src/tools/prompts/codegen.md +2 -1
- package/src/tools/read/css.ts +365 -0
- package/src/tools/read/reactions.ts +3 -2
- package/src/tools/read/space.ts +0 -2
- package/src/tools/read.ts +1 -0
- package/src/tools/registry/core.ts +3 -2
- package/src/tools/schema.ts +14 -5
- package/src/tools/script/host.ts +6 -3
- package/src/tools/variables/collections.ts +1 -1
- package/src/tools/variables/values.ts +16 -5
- package/src/tools/vector/vectorize.ts +10 -4
- package/src/tools/video-host.ts +5 -3
- package/src/vector/vectorize/svg/gradients.ts +8 -5
- package/src/vector/vectorize/svg/to-vectors.ts +48 -14
- package/dist/text/font/status.d.ts +0 -28
- package/dist/text/font/status.d.ts.map +0 -1
- package/dist/text/font/status.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape.js","names":[],"sources":["../../../src/canvas/text/shape.ts"],"sourcesContent":["import type { CanvasKit, TypefaceFontProvider } from 'canvaskit-wasm'\n\nimport {\n EMPTY_EXPORT_RUNTIME,\n type FigNodeChangeExportRuntime,\n type PlacedTextGlyph,\n type ShapedText,\n type ShapedTextGlyph,\n type TextDecorationRecord\n} from '@pairdraw/fig/node-change'\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { textVerticalOffset } from '@pairdraw/scene-graph/text'\n\nimport { buildParagraph } from '#core/canvas/text'\nimport { textDecorationRects, type DecoratedGlyph } from '#core/canvas/text/decorations'\nimport { outlineInk, savedGlyphInk } from '#core/canvas/text/ink'\nimport { COMBINING_KEYCAP, keycapFrame } from '#core/canvas/text/keycap'\nimport { characterFamily, laidOutGlyphs, type LaidOutGlyph } from '#core/canvas/text/placed'\nimport { getCanvasKit } from '#core/canvaskit'\nimport { shownText } from '#core/text/case'\nimport { EMOJI_METRICS_FAMILY } from '#core/text/emoji'\nimport type { OutlineCommand } from '#core/text/font/glyphs'\nimport { fontManager } from '#core/text/font/manager'\nimport { faceStyleName } from '#core/text/font/names'\nimport { nextGraphemeBoundary } from '#core/text/graphemes'\n\n/**\n * Whether saved glyphs could stand for this text: case changes that alter its length move\n * glyphs off the characters they came from, and path text is placed along its path. Truncated\n * text saves the characters it shows and the ellipsis after them.\n */\nfunction canShape(node: SceneNode, text: string): boolean {\n return node.text.length > 0 && text.length === node.text.length && !node.textPathData\n}\n\n/** Characters inside a glyph cluster or without a glyph take the offset of the one before. */\nfunction completeCharacterOffsets(offsets: Array<number | undefined>): number[] {\n let previous = 0\n return offsets.map((offset) => {\n previous = offset ?? previous\n return previous\n })\n}\n\n/**\n * The square Figma saves for an emoji, in pixels at `size` with y down: 1 em wide, from 0.07 em\n * below the baseline, closed with a line back to its start as Figma writes it.\n */\nfunction emojiPlaceholder(size: number): OutlineCommand[] {\n const bottom = 0.07 * size\n const top = -0.93 * size\n return [\n { type: 'M', x: 0, y: bottom },\n { type: 'L', x: size, y: bottom },\n { type: 'L', x: size, y: top },\n { type: 'L', x: 0, y: top },\n { type: 'L', x: 0, y: bottom },\n { type: 'Z' }\n ]\n}\n\ninterface SavedEmoji {\n codePoints: number[]\n /** Where the emoji's characters end in the text. */\n end: number\n}\n\n/**\n * The emoji a glyph starts, as Figma saves it, when the layout gave it to the emoji metrics font:\n * its code points, an emoji that shows as text by default with the selector that asks for its\n * emoji form, as Figma saves ☺ as ☺️.\n */\nfunction savedEmoji(node: SceneNode, text: string, glyph: LaidOutGlyph): SavedEmoji | undefined {\n const start = glyph.firstCharacter\n if (start === undefined || characterFamily(node, text, start) !== EMOJI_METRICS_FAMILY)\n return undefined\n const end = nextGraphemeBoundary(text, start)\n const emoji = text.slice(start, end)\n const codePoints = Array.from(emoji, (character) => character.codePointAt(0) ?? 0)\n if (codePoints.length === 1 && !/\\p{Emoji_Presentation}/u.test(emoji)) codePoints.push(0xfe0f)\n return { codePoints, end }\n}\n\n/**\n * A glyph's saved outline: an emoji's placeholder, nothing inside one, a keycap's frame, or its\n * font's outline.\n */\nfunction savedOutline(\n glyph: LaidOutGlyph,\n text: string,\n emoji: SavedEmoji | undefined,\n insideEmoji: boolean\n): OutlineCommand[] | null {\n if (insideEmoji) return []\n if (emoji) return emojiPlaceholder(glyph.fontSize)\n const character = glyph.firstCharacter\n if (character !== undefined && text[character] === COMBINING_KEYCAP)\n return keycapFrame(glyph.fontSize)\n return glyph.source?.outline(glyph.id, glyph.fontSize) ?? null\n}\n\n/**\n * Lay a text node out as the renderer draws it and pair each shaped glyph with the outline of\n * the glyph ID CanvasKit chose, so ligatures and contextual forms keep their shapes. An emoji the\n * layout gives the emoji metrics font is saved as Figma saves one: a placeholder square with its\n * code points. When a run's font cannot be told, no glyph gets an outline: the layout still\n * stands and Pairdraw lays the text out again on reading, but Figma draws it blank.\n * Returns `null` for text saved glyphs cannot represent at all.\n */\nexport function shapeText(\n ck: CanvasKit,\n fontProvider: TypefaceFontProvider,\n node: SceneNode\n): ShapedText | null {\n const text = shownText(node)\n if (!canShape(node, text)) return null\n\n const paragraph = buildParagraph({ ck, fontProvider, fontsLoaded: true }, node, undefined, {\n halfLeading: true\n })\n try {\n const offsetY = textVerticalOffset(node, paragraph.getHeight())\n const placed = laidOutGlyphs(node, paragraph, text, offsetY)\n if (!placed) return null\n const metrics = paragraph.getLineMetrics()\n const characterOffsets: Array<number | undefined> = Array.from({ length: text.length })\n // A sequence the font does not join is several glyphs: the first stands for the emoji, and\n // the rest keep their place and draw nothing. Glyphs come in visual order, so in\n // right-to-left text a character before the emoji can follow it: the whole range counts.\n let emojiRange = { start: 0, end: 0 }\n const glyphs: ShapedTextGlyph[] = placed.map((glyph) => {\n const start = glyph.firstCharacter\n if (start !== undefined) characterOffsets[start] ??= glyph.x - glyph.lineLeft\n const insideEmoji = start !== undefined && start > emojiRange.start && start < emojiRange.end\n const emoji = insideEmoji ? undefined : savedEmoji(node, text, glyph)\n if (emoji && start !== undefined) emojiRange = { start, end: emoji.end }\n return {\n commands: savedOutline(glyph, text, emoji, insideEmoji),\n x: glyph.x,\n y: glyph.y,\n fontSize: glyph.fontSize,\n firstCharacter: start,\n advance: glyph.advance,\n emojiCodePoints: emoji?.codePoints\n }\n })\n // Outlines from some runs only would draw the text with characters missing.\n const outlined = glyphs.every((glyph) => glyph.commands)\n return {\n glyphs: outlined ? glyphs : glyphs.map((glyph) => ({ ...glyph, commands: null })),\n // Figma saves no baseline for the empty line after a closing line break.\n baselines: metrics\n .filter((line, index) => index === 0 || line.startIndex < text.length)\n .map((line) => ({\n firstCharacter: line.startIndex,\n endCharacter: Math.min(line.endIncludingNewline, text.length),\n position: { x: line.left, y: line.baseline + offsetY },\n width: line.width,\n lineY: line.baseline - line.ascent + offsetY,\n lineHeight: line.height,\n lineAscent: line.ascent\n })),\n logicalIndexToCharacterOffsetMap: completeCharacterOffsets(characterOffsets)\n }\n } finally {\n paragraph.delete()\n }\n}\n\nfunction decoratedGlyph(glyph: PlacedTextGlyph): DecoratedGlyph {\n const { commandsBlob, commands } = glyph\n return {\n ...glyph,\n ink: (top, bottom) => {\n if (commandsBlob) return savedGlyphInk(commandsBlob, glyph, top, bottom)\n return commands ? outlineInk(commands, glyph.x, glyph.y, top, bottom) : null\n }\n }\n}\n\n/** Decorations as Figma saves them, over glyphs saved or just shaped. */\nfunction textDecorations(\n node: SceneNode,\n glyphs: readonly PlacedTextGlyph[]\n): TextDecorationRecord[] {\n return textDecorationRects(node, glyphs.map(decoratedGlyph)).map(\n ({ firstCharacter, x, y, width, height }) => ({ firstCharacter, x, y, width, height })\n )\n}\n\nfunction needsShaping(graph: SceneGraph): boolean {\n for (const node of graph.nodes.values()) {\n if (node.type === 'TEXT' && node.text && !node.derivedTextGlyphs?.length) return true\n }\n return false\n}\n\n/**\n * Run `use` with text shaped as the canvas lays it out, from the font provider the canvas of\n * `canvasKit` draws from, or one a caller attached and registered faces on for layout alone.\n * Each call holds a share of that provider, so overlapping calls shape from the same one and the\n * last to finish releases it; a provider with no share left is deleted.\n */\nexport async function withTextShaper<T>(\n canvasKit: CanvasKit,\n use: (shape: (node: SceneNode) => ShapedText | null) => Promise<T>\n): Promise<T> {\n const provider = fontManager.acquireProvider(canvasKit)\n try {\n return await use((node) => shapeText(canvasKit, provider, node))\n } finally {\n fontManager.releaseProvider(provider)\n }\n}\n\n/** Run a `.fig` or Figma clipboard write with text shaping. */\nexport async function withFigExportRuntime<T>(\n graph: SceneGraph,\n ck: CanvasKit | undefined,\n write: (runtime: FigNodeChangeExportRuntime) => Promise<T>\n): Promise<T> {\n const named = { textDecorations, fontStyleName: faceStyleName }\n if (!needsShaping(graph)) return write({ ...EMPTY_EXPORT_RUNTIME, ...named })\n return withTextShaper(ck ?? (await getCanvasKit()), (shapeText) => write({ shapeText, ...named }))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA+BA,SAAS,SAAS,MAAiB,MAAuB;CACxD,OAAO,KAAK,KAAK,SAAS,KAAK,KAAK,WAAW,KAAK,KAAK,UAAU,CAAC,KAAK;AAC3E;;AAGA,SAAS,yBAAyB,SAA8C;CAC9E,IAAI,WAAW;CACf,OAAO,QAAQ,KAAK,WAAW;EAC7B,WAAW,UAAU;EACrB,OAAO;CACT,CAAC;AACH;;;;;AAMA,SAAS,iBAAiB,MAAgC;CACxD,MAAM,SAAS,MAAO;CACtB,MAAM,MAAM,OAAQ;CACpB,OAAO;EACL;GAAE,MAAM;GAAK,GAAG;GAAG,GAAG;EAAO;EAC7B;GAAE,MAAM;GAAK,GAAG;GAAM,GAAG;EAAO;EAChC;GAAE,MAAM;GAAK,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AAa;CACnC,OAAO;EACL,GAAG;EACH,MAAM,KAAK,WAAW;GACpB,IAAI,cAAc,OAAO,cAAc,cAAc,OAAO,KAAK,MAAM;GACvE,OAAO,WAAW,WAAW,UAAU,MAAM,GAAG,MAAM,GAAG,KAAK,MAAM,IAAI;EAC1E;CACF;AACF;;AAGA,SAAS,gBACP,MACA,QACwB;CACxB,OAAO,oBAAoB,MAAM,OAAO,IAAI,cAAc,CAAC,CAAC,CAAC,KAC1D,EAAE,gBAAgB,GAAG,GAAG,OAAO,cAAc;EAAE;EAAgB;EAAG;EAAG;EAAO;CAAO,EACtF;AACF;AAEA,SAAS,aAAa,OAA4B;CAChD,KAAK,MAAM,QAAQ,MAAM,MAAM,OAAO,GACpC,IAAI,KAAK,SAAS,UAAU,KAAK,QAAQ,CAAC,KAAK,mBAAmB,QAAQ,OAAO;CAEnF,OAAO;AACT;;;;;;;AAQA,eAAsB,eACpB,WACA,KACY;CACZ,MAAM,WAAW,YAAY,gBAAgB,SAAS;CACtD,IAAI;EACF,OAAO,MAAM,KAAK,SAAS,UAAU,WAAW,UAAU,IAAI,CAAC;CACjE,UAAU;EACR,YAAY,gBAAgB,QAAQ;CACtC;AACF;;AAGA,eAAsB,qBACpB,OACA,IACA,OACY;CACZ,MAAM,QAAQ;EAAE;EAAiB,eAAe;CAAc;CAC9D,IAAI,CAAC,aAAa,KAAK,GAAG,OAAO,MAAM;EAAE,GAAG;EAAsB,GAAG;CAAM,CAAC;CAC5E,OAAO,eAAe,MAAO,MAAM,aAAa,IAAK,cAAc,MAAM;EAAE;EAAW,GAAG;CAAM,CAAC,CAAC;AACnG"}
|
|
1
|
+
{"version":3,"file":"shape.js","names":[],"sources":["../../../src/canvas/text/shape.ts"],"sourcesContent":["import type { CanvasKit, TypefaceFontProvider } from 'canvaskit-wasm'\n\nimport {\n EMPTY_EXPORT_RUNTIME,\n type FigNodeChangeExportRuntime,\n type PlacedTextGlyph,\n type ShapedText,\n type ShapedTextGlyph,\n type TextDecorationRecord\n} from '@pairdraw/fig/node-change'\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { textVerticalOffset } from '@pairdraw/scene-graph/text'\n\nimport { buildParagraph } from '#core/canvas/text'\nimport { textDecorationRects, type DecoratedGlyph } from '#core/canvas/text/decorations'\nimport { outlineInk, savedGlyphInk } from '#core/canvas/text/ink'\nimport { COMBINING_KEYCAP, keycapFrame } from '#core/canvas/text/keycap'\nimport { characterFamily, laidOutGlyphs, type LaidOutGlyph } from '#core/canvas/text/placed'\nimport { getCanvasKit } from '#core/canvaskit'\nimport { shownText } from '#core/text/case'\nimport { EMOJI_METRICS_FAMILY } from '#core/text/emoji'\nimport type { OutlineCommand } from '#core/text/font/glyphs'\nimport { faceStyleName } from '#core/text/font/names'\nimport { leaseFontProvider } from '#core/text/font/provider'\nimport { nextGraphemeBoundary } from '#core/text/graphemes'\n\n/**\n * Whether saved glyphs could stand for this text: case changes that alter its length move\n * glyphs off the characters they came from, and path text is placed along its path. Truncated\n * text saves the characters it shows and the ellipsis after them.\n */\nfunction canShape(node: SceneNode, text: string): boolean {\n return node.text.length > 0 && text.length === node.text.length && !node.textPathData\n}\n\n/** Characters inside a glyph cluster or without a glyph take the offset of the one before. */\nfunction completeCharacterOffsets(offsets: Array<number | undefined>): number[] {\n let previous = 0\n return offsets.map((offset) => {\n previous = offset ?? previous\n return previous\n })\n}\n\n/**\n * The square Figma saves for an emoji, in pixels at `size` with y down: 1 em wide, from 0.07 em\n * below the baseline, closed with a line back to its start as Figma writes it.\n */\nfunction emojiPlaceholder(size: number): OutlineCommand[] {\n const bottom = 0.07 * size\n const top = -0.93 * size\n return [\n { type: 'M', x: 0, y: bottom },\n { type: 'L', x: size, y: bottom },\n { type: 'L', x: size, y: top },\n { type: 'L', x: 0, y: top },\n { type: 'L', x: 0, y: bottom },\n { type: 'Z' }\n ]\n}\n\ninterface SavedEmoji {\n codePoints: number[]\n /** Where the emoji's characters end in the text. */\n end: number\n}\n\n/**\n * The emoji a glyph starts, as Figma saves it, when the layout gave it to the emoji metrics font:\n * its code points, an emoji that shows as text by default with the selector that asks for its\n * emoji form, as Figma saves ☺ as ☺️.\n */\nfunction savedEmoji(node: SceneNode, text: string, glyph: LaidOutGlyph): SavedEmoji | undefined {\n const start = glyph.firstCharacter\n if (start === undefined || characterFamily(node, text, start) !== EMOJI_METRICS_FAMILY)\n return undefined\n const end = nextGraphemeBoundary(text, start)\n const emoji = text.slice(start, end)\n const codePoints = Array.from(emoji, (character) => character.codePointAt(0) ?? 0)\n if (codePoints.length === 1 && !/\\p{Emoji_Presentation}/u.test(emoji)) codePoints.push(0xfe0f)\n return { codePoints, end }\n}\n\n/**\n * A glyph's saved outline: an emoji's placeholder, nothing inside one, a keycap's frame, or its\n * font's outline.\n */\nfunction savedOutline(\n glyph: LaidOutGlyph,\n text: string,\n emoji: SavedEmoji | undefined,\n insideEmoji: boolean\n): OutlineCommand[] | null {\n if (insideEmoji) return []\n if (emoji) return emojiPlaceholder(glyph.fontSize)\n const character = glyph.firstCharacter\n if (character !== undefined && text[character] === COMBINING_KEYCAP)\n return keycapFrame(glyph.fontSize)\n return glyph.source?.outline(glyph.id, glyph.fontSize) ?? null\n}\n\n/**\n * Lay a text node out as the renderer draws it and pair each shaped glyph with the outline of\n * the glyph ID CanvasKit chose, so ligatures and contextual forms keep their shapes. An emoji the\n * layout gives the emoji metrics font is saved as Figma saves one: a placeholder square with its\n * code points. When a run's font cannot be told, no glyph gets an outline: the layout still\n * stands and Pairdraw lays the text out again on reading, but Figma draws it blank.\n * Returns `null` for text saved glyphs cannot represent at all.\n */\nexport function shapeText(\n ck: CanvasKit,\n fontProvider: TypefaceFontProvider,\n node: SceneNode\n): ShapedText | null {\n const text = shownText(node)\n if (!canShape(node, text)) return null\n\n const paragraph = buildParagraph({ ck, fontProvider, fontsLoaded: true }, node, undefined, {\n halfLeading: true\n })\n try {\n const offsetY = textVerticalOffset(node, paragraph.getHeight())\n const placed = laidOutGlyphs(node, paragraph, text, offsetY)\n if (!placed) return null\n const metrics = paragraph.getLineMetrics()\n const characterOffsets: Array<number | undefined> = Array.from({ length: text.length })\n // A sequence the font does not join is several glyphs: the first stands for the emoji, and\n // the rest keep their place and draw nothing. Glyphs come in visual order, so in\n // right-to-left text a character before the emoji can follow it: the whole range counts.\n let emojiRange = { start: 0, end: 0 }\n const glyphs: ShapedTextGlyph[] = placed.map((glyph) => {\n const start = glyph.firstCharacter\n if (start !== undefined) characterOffsets[start] ??= glyph.x - glyph.lineLeft\n const insideEmoji = start !== undefined && start > emojiRange.start && start < emojiRange.end\n const emoji = insideEmoji ? undefined : savedEmoji(node, text, glyph)\n if (emoji && start !== undefined) emojiRange = { start, end: emoji.end }\n return {\n commands: savedOutline(glyph, text, emoji, insideEmoji),\n x: glyph.x,\n y: glyph.y,\n fontSize: glyph.fontSize,\n firstCharacter: start,\n advance: glyph.advance,\n emojiCodePoints: emoji?.codePoints\n }\n })\n // Outlines from some runs only would draw the text with characters missing.\n const outlined = glyphs.every((glyph) => glyph.commands)\n return {\n glyphs: outlined ? glyphs : glyphs.map((glyph) => ({ ...glyph, commands: null })),\n // Figma saves no baseline for the empty line after a closing line break.\n baselines: metrics\n .filter((line, index) => index === 0 || line.startIndex < text.length)\n .map((line) => ({\n firstCharacter: line.startIndex,\n endCharacter: Math.min(line.endIncludingNewline, text.length),\n position: { x: line.left, y: line.baseline + offsetY },\n width: line.width,\n lineY: line.baseline - line.ascent + offsetY,\n lineHeight: line.height,\n lineAscent: line.ascent\n })),\n logicalIndexToCharacterOffsetMap: completeCharacterOffsets(characterOffsets)\n }\n } finally {\n paragraph.delete()\n }\n}\n\nfunction decoratedGlyph(glyph: PlacedTextGlyph): DecoratedGlyph {\n const { commandsBlob, commands } = glyph\n return {\n ...glyph,\n ink: (top, bottom) => {\n if (commandsBlob) return savedGlyphInk(commandsBlob, glyph, top, bottom)\n return commands ? outlineInk(commands, glyph.x, glyph.y, top, bottom) : null\n }\n }\n}\n\n/** Decorations as Figma saves them, over glyphs saved or just shaped. */\nfunction textDecorations(\n node: SceneNode,\n glyphs: readonly PlacedTextGlyph[]\n): TextDecorationRecord[] {\n return textDecorationRects(node, glyphs.map(decoratedGlyph)).map(\n ({ firstCharacter, x, y, width, height }) => ({ firstCharacter, x, y, width, height })\n )\n}\n\nfunction needsShaping(graph: SceneGraph): boolean {\n for (const node of graph.nodes.values()) {\n if (node.type === 'TEXT' && node.text && !node.derivedTextGlyphs?.length) return true\n }\n return false\n}\n\n/**\n * Run `use` with text shaped as the canvas lays it out, from the font provider the canvas of\n * `canvasKit` draws from, or one a caller attached and registered faces on for layout alone.\n * Each call holds a share of that provider, so overlapping calls shape from the same one and the\n * last to finish releases it; a provider with no share left is deleted.\n */\nexport async function withTextShaper<T>(\n canvasKit: CanvasKit,\n use: (shape: (node: SceneNode) => ShapedText | null) => Promise<T>\n): Promise<T> {\n const lease = leaseFontProvider(canvasKit)\n try {\n return await use((node) => shapeText(canvasKit, lease.provider, node))\n } finally {\n lease.release()\n }\n}\n\n/** Run a `.fig` or Figma clipboard write with text shaping. */\nexport async function withFigExportRuntime<T>(\n graph: SceneGraph,\n ck: CanvasKit | undefined,\n write: (runtime: FigNodeChangeExportRuntime) => Promise<T>\n): Promise<T> {\n const named = { textDecorations, fontStyleName: faceStyleName }\n if (!needsShaping(graph)) return write({ ...EMPTY_EXPORT_RUNTIME, ...named })\n return withTextShaper(ck ?? (await getCanvasKit()), (shapeText) => write({ shapeText, ...named }))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA+BA,SAAS,SAAS,MAAiB,MAAuB;CACxD,OAAO,KAAK,KAAK,SAAS,KAAK,KAAK,WAAW,KAAK,KAAK,UAAU,CAAC,KAAK;AAC3E;;AAGA,SAAS,yBAAyB,SAA8C;CAC9E,IAAI,WAAW;CACf,OAAO,QAAQ,KAAK,WAAW;EAC7B,WAAW,UAAU;EACrB,OAAO;CACT,CAAC;AACH;;;;;AAMA,SAAS,iBAAiB,MAAgC;CACxD,MAAM,SA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../../src/canvas/texture.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"texture.d.ts","names":[],"sources":["../../src/canvas/texture.ts"],"mappings":";;;;;;;;iBA2CgB,wBACd,GAAG,cACH,SAAS,eACT,eACC;;iBAkCa,gBAAgB,MAAM,YAAY;;;;;;iBAYlC,kBACd,GAAG,cACH,QAAQ,QACR,MAAM,WACN"}
|
package/dist/canvas/texture.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { skColorSpace } from "./renderer/colors.js";
|
|
1
2
|
import { cellValue } from "./noise/tile.js";
|
|
2
3
|
//#region src/canvas/texture.ts
|
|
3
4
|
/** Cells on each side of a texture's displacement tile; it repeats beyond them. */
|
|
@@ -50,7 +51,7 @@ function textureDisplacementTile(r, texture, seed) {
|
|
|
50
51
|
height: TEXTURE_TILE_CELLS,
|
|
51
52
|
alphaType: r.ck.AlphaType.Unpremul,
|
|
52
53
|
colorType: r.ck.ColorType.RGBA_8888,
|
|
53
|
-
colorSpace: r.ck.
|
|
54
|
+
colorSpace: skColorSpace(r.ck, r.documentColorSpace)
|
|
54
55
|
}, pixels, TEXTURE_TILE_CELLS * 4);
|
|
55
56
|
if (!image) return null;
|
|
56
57
|
r.textureNoiseCache.set(key, image);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"texture.js","names":[],"sources":["../../src/canvas/texture.ts"],"sourcesContent":["import type { Canvas, Image, ImageFilter, Shader } from 'canvaskit-wasm'\n\nimport type { SceneNode, TextureEffect } from '@pairdraw/scene-graph'\n\nimport { cellValue } from './noise/tile'\nimport type { SkiaRenderer } from './renderer'\n\n/** Cells on each side of a texture's displacement tile; it repeats beyond them. */\nconst TEXTURE_TILE_CELLS = 256\n\nfunction smooth(t: number): number {\n return t * t * (3 - 2 * t)\n}\n\n/**\n * A cell's red or green displacement as smooth noise over `frequency` cells, sampled where the\n * layer's pixels are: one cycle per grain, and tileable because the corners wrap.\n */\nfunction displacement(x: number, y: number, frequency: number, seed: number, salt: number): number {\n const gx = x * frequency\n const gy = y * frequency\n const x0 = Math.floor(gx)\n const y0 = Math.floor(gy)\n const x1 = (x0 + 1) % TEXTURE_TILE_CELLS\n const y1 = (y0 + 1) % TEXTURE_TILE_CELLS\n const tx = smooth(gx - x0)\n const ty = smooth(gy - y0)\n const wrap = (value: number) =>\n ((value % TEXTURE_TILE_CELLS) + TEXTURE_TILE_CELLS) % TEXTURE_TILE_CELLS\n const v00 = cellValue(wrap(x0), wrap(y0), seed, salt)\n const v10 = cellValue(x1, wrap(y0), seed, salt)\n const v01 = cellValue(wrap(x0), y1, seed, salt)\n const v11 = cellValue(x1, y1, seed, salt)\n const top = v00 + (v10 - v00) * tx\n const bottom = v01 + (v11 - v01) * tx\n return top + (bottom - top) * ty\n}\n\n/**\n * The displacement tile for a texture: red and green as independent smooth noise one grain to a\n * cycle, as `feTurbulence` writes them, cached by grain size and seed.\n */\nexport function textureDisplacementTile(\n r: SkiaRenderer,\n texture: TextureEffect,\n seed: number\n): Image | null {\n const frequency = (size: number) => (size > 0 ? 1 / size : 0)\n const fx = frequency(texture.texture.noiseSize.x)\n const fy = frequency(texture.texture.noiseSize.y)\n const key = `texture:${fx}:${fy}:${seed}`\n const kept = r.textureNoiseCache.get(key)\n if (kept) return kept\n const pixels = new Uint8Array(TEXTURE_TILE_CELLS * TEXTURE_TILE_CELLS * 4)\n for (let y = 0; y < TEXTURE_TILE_CELLS; y++) {\n for (let x = 0; x < TEXTURE_TILE_CELLS; x++) {\n const at = (y * TEXTURE_TILE_CELLS + x) * 4\n pixels[at] = Math.floor(displacement(x, y, fx, seed, 1) * 256)\n pixels[at + 1] = Math.floor(displacement(x, y, fy, seed, 2) * 256)\n pixels[at + 2] = 0\n pixels[at + 3] = 255\n }\n }\n const image = r.ck.MakeImage(\n {\n width: TEXTURE_TILE_CELLS,\n height: TEXTURE_TILE_CELLS,\n alphaType: r.ck.AlphaType.Unpremul,\n colorType: r.ck.ColorType.RGBA_8888,\n colorSpace: r.ck.
|
|
1
|
+
{"version":3,"file":"texture.js","names":[],"sources":["../../src/canvas/texture.ts"],"sourcesContent":["import type { Canvas, Image, ImageFilter, Shader } from 'canvaskit-wasm'\n\nimport type { SceneNode, TextureEffect } from '@pairdraw/scene-graph'\n\nimport { cellValue } from './noise/tile'\nimport type { SkiaRenderer } from './renderer'\nimport { skColorSpace } from './renderer/colors'\n\n/** Cells on each side of a texture's displacement tile; it repeats beyond them. */\nconst TEXTURE_TILE_CELLS = 256\n\nfunction smooth(t: number): number {\n return t * t * (3 - 2 * t)\n}\n\n/**\n * A cell's red or green displacement as smooth noise over `frequency` cells, sampled where the\n * layer's pixels are: one cycle per grain, and tileable because the corners wrap.\n */\nfunction displacement(x: number, y: number, frequency: number, seed: number, salt: number): number {\n const gx = x * frequency\n const gy = y * frequency\n const x0 = Math.floor(gx)\n const y0 = Math.floor(gy)\n const x1 = (x0 + 1) % TEXTURE_TILE_CELLS\n const y1 = (y0 + 1) % TEXTURE_TILE_CELLS\n const tx = smooth(gx - x0)\n const ty = smooth(gy - y0)\n const wrap = (value: number) =>\n ((value % TEXTURE_TILE_CELLS) + TEXTURE_TILE_CELLS) % TEXTURE_TILE_CELLS\n const v00 = cellValue(wrap(x0), wrap(y0), seed, salt)\n const v10 = cellValue(x1, wrap(y0), seed, salt)\n const v01 = cellValue(wrap(x0), y1, seed, salt)\n const v11 = cellValue(x1, y1, seed, salt)\n const top = v00 + (v10 - v00) * tx\n const bottom = v01 + (v11 - v01) * tx\n return top + (bottom - top) * ty\n}\n\n/**\n * The displacement tile for a texture: red and green as independent smooth noise one grain to a\n * cycle, as `feTurbulence` writes them, cached by grain size and seed.\n */\nexport function textureDisplacementTile(\n r: SkiaRenderer,\n texture: TextureEffect,\n seed: number\n): Image | null {\n const frequency = (size: number) => (size > 0 ? 1 / size : 0)\n const fx = frequency(texture.texture.noiseSize.x)\n const fy = frequency(texture.texture.noiseSize.y)\n const key = `texture:${fx}:${fy}:${seed}`\n const kept = r.textureNoiseCache.get(key)\n if (kept) return kept\n const pixels = new Uint8Array(TEXTURE_TILE_CELLS * TEXTURE_TILE_CELLS * 4)\n for (let y = 0; y < TEXTURE_TILE_CELLS; y++) {\n for (let x = 0; x < TEXTURE_TILE_CELLS; x++) {\n const at = (y * TEXTURE_TILE_CELLS + x) * 4\n pixels[at] = Math.floor(displacement(x, y, fx, seed, 1) * 256)\n pixels[at + 1] = Math.floor(displacement(x, y, fy, seed, 2) * 256)\n pixels[at + 2] = 0\n pixels[at + 3] = 255\n }\n }\n const image = r.ck.MakeImage(\n {\n width: TEXTURE_TILE_CELLS,\n height: TEXTURE_TILE_CELLS,\n alphaType: r.ck.AlphaType.Unpremul,\n colorType: r.ck.ColorType.RGBA_8888,\n colorSpace: skColorSpace(r.ck, r.documentColorSpace)\n },\n pixels,\n TEXTURE_TILE_CELLS * 4\n )\n if (!image) return null\n r.textureNoiseCache.set(key, image)\n return image\n}\n\n/** The first visible texture effect on a layer, which roughens its edges. */\nexport function textureEffectOf(node: SceneNode): TextureEffect | null {\n for (const effect of node.effects) {\n if (effect.visible && effect.type === 'TEXTURE' && effect.radius > 0) return effect\n }\n return null\n}\n\n/**\n * Draws a layer's content through the displacement of its texture effect: the noise moves each\n * pixel by up to `radius`, as Figma's filter does, and `clipToShape` keeps the moved pixels inside\n * the layer's box. Returns false when there is no texture to draw, so a caller draws as usual.\n */\nexport function withTextureEffect(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n draw: () => void\n): boolean {\n const texture = textureEffectOf(node)\n if (!texture) return false\n const tile = textureDisplacementTile(r, texture, texture.texture.seed ?? 0)\n if (!tile) return false\n const repeat = r.ck.TileMode.Repeat\n const shader: Shader = tile.makeShaderOptions(\n repeat,\n repeat,\n r.ck.FilterMode.Linear,\n r.ck.MipmapMode.None\n )\n const displacement: ImageFilter = r.ck.ImageFilter.MakeShader(shader)\n const filter: ImageFilter = r.ck.ImageFilter.MakeDisplacementMap(\n r.ck.ColorChannel.Red,\n r.ck.ColorChannel.Green,\n texture.radius * 2,\n displacement,\n null\n )\n const paint = new r.ck.Paint()\n try {\n paint.setImageFilter(filter)\n const rect = r.ck.LTRBRect(0, 0, node.width, node.height)\n if (texture.texture.clipToShape) r.clipNodeShape(canvas, node)\n canvas.saveLayer(paint, rect)\n try {\n draw()\n } finally {\n canvas.restore()\n }\n } finally {\n paint.delete()\n filter.delete()\n displacement.delete()\n shader.delete()\n }\n return true\n}\n"],"mappings":";;;;AASA,MAAM,qBAAqB;AAE3B,SAAS,OAAO,GAAmB;CACjC,OAAO,IAAI,KAAK,IAAI,IAAI;AAC1B;;;;;AAMA,SAAS,aAAa,GAAW,GAAW,WAAmB,MAAc,MAAsB;CACjG,MAAM,KAAK,IAAI;CACf,MAAM,KAAK,IAAI;CACf,MAAM,KAAK,KAAK,MAAM,EAAE;CACxB,MAAM,KAAK,KAAK,MAAM,EAAE;CACxB,MAAM,MAAM,KAAK,KAAK;CACtB,MAAM,MAAM,KAAK,KAAK;CACtB,MAAM,KAAK,OAAO,KAAK,EAAE;CACzB,MAAM,KAAK,OAAO,KAAK,EAAE;CACzB,MAAM,QAAQ,WACV,QAAQ,qBAAsB,sBAAsB;CACxD,MAAM,MAAM,UAAU,KAAK,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,IAAI;CACpD,MAAM,MAAM,UAAU,IAAI,KAAK,EAAE,GAAG,MAAM,IAAI;CAC9C,MAAM,MAAM,UAAU,KAAK,EAAE,GAAG,IAAI,MAAM,IAAI;CAC9C,MAAM,MAAM,UAAU,IAAI,IAAI,MAAM,IAAI;CACxC,MAAM,MAAM,OAAO,MAAM,OAAO;CAEhC,OAAO,OADQ,OAAO,MAAM,OAAO,KACZ,OAAO;AAChC;;;;;AAMA,SAAgB,wBACd,GACA,SACA,MACc;CACd,MAAM,aAAa,SAAkB,OAAO,IAAI,IAAI,OAAO;CAC3D,MAAM,KAAK,UAAU,QAAQ,QAAQ,UAAU,CAAC;CAChD,MAAM,KAAK,UAAU,QA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KAAK,kBAC1B,QACA,QACA,EAAE,GAAG,WAAW,QAChB,EAAE,GAAG,WAAW,IAClB;CACA,MAAM,eAA4B,EAAE,GAAG,YAAY,WAAW,MAAM;CACpE,MAAM,SAAsB,EAAE,GAAG,YAAY,oBAC3C,EAAE,GAAG,aAAa,KAClB,EAAE,GAAG,aAAa,OAClB,QAAQ,SAAS,GACjB,cACA,IACF;CACA,MAAM,QAAQ,IAAI,EAAE,GAAG,MAAM;CAC7B,IAAI;EACF,MAAM,eAAe,MAAM;EAC3B,MAAM,OAAO,EAAE,GAAG,SAAS,GAAG,GAAG,KAAK,OAAO,KAAK,MAAM;EACxD,IAAI,QAAQ,QAAQ,aAAa,EAAE,cAAc,QAAQ,IAAI;EAC7D,OAAO,UAAU,OAAO,IAAI;EAC5B,IAAI;GACF,KAAK;EACP,UAAU;GACR,OAAO,QAAQ;EACjB;CACF,UAAU;EACR,MAAM,OAAO;EACb,OAAO,OAAO;EACd,aAAa,OAAO;EACpB,OAAO,OAAO;CAChB;CACA,OAAO;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveVariable } from "@pairdraw/scene-graph/variables";
|
|
2
|
-
import { uniqBy } from "es-toolkit/array";
|
|
3
2
|
import { colorToHex } from "@pairdraw/scene-graph/color";
|
|
3
|
+
import { uniqBy } from "es-toolkit/array";
|
|
4
4
|
import { DESIGN_MEMORY_GROUPS } from "@pairdraw/scene-graph/design-memory";
|
|
5
5
|
import { converter } from "culori";
|
|
6
6
|
//#region src/design-memory/rules.ts
|
|
@@ -15,7 +15,7 @@ declare function createUndoBridge(undoActions: UndoActions, selection: Selection
|
|
|
15
15
|
commitMove: (originals: Map<string, import("@pairdraw/scene-graph/primitives").Vector>) => void;
|
|
16
16
|
commitMoveWithReparent: (originals: Map<string, MovePlace>) => void;
|
|
17
17
|
commitDuplicateMove: (rootIds: string[], previousSelection: Set<string>) => void;
|
|
18
|
-
commitResize: (nodeId: string, original: import("@pairdraw/scene-graph/primitives").Rect & Partial<Pick<import("@pairdraw/scene-graph").SceneNode, "
|
|
18
|
+
commitResize: (nodeId: string, original: import("@pairdraw/scene-graph/primitives").Rect & Partial<Pick<import("@pairdraw/scene-graph").SceneNode, "vectorNetwork" | "fillGeometry" | "strokeGeometry" | "derivedTextGlyphs" | "strokes" | "textPathData" | "textPathBox">>) => void;
|
|
19
19
|
commitGroupResize: (nodeId: string, origRect: import("@pairdraw/scene-graph/primitives").Rect, origChildren: Map<string, import("@pairdraw/scene-graph/resize").ResizeSnapshot>) => void;
|
|
20
20
|
commitRotation: (nodeId: string, origRotation: number) => void;
|
|
21
21
|
commitNodeUpdate: (nodeId: string, previous: Partial<import("@pairdraw/scene-graph").SceneNode>, label?: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.d.ts","names":[],"sources":["../../../src/editor/clipboard/assets.ts"],"mappings":";;KA0CK,wBACH,mBACA,mBAAmB,aACnB;iBAGc,4BACd,KAAK,eACL,sBAAsB;EAEK,aAAA,OAAA;
|
|
1
|
+
{"version":3,"file":"assets.d.ts","names":[],"sources":["../../../src/editor/clipboard/assets.ts"],"mappings":";;KA0CK,wBACH,mBACA,mBAAmB,aACnB;iBAGc,4BACd,KAAK,eACL,sBAAsB;EAEK,aAAA,OAAA;EA2HM,aAAA,OAAA,QAAM,YAAY,eAAY;EAwC/B,kBAAA,OAAA,QAAM,YAAY,eAAY;EA/B9B,WAAA,gBAAM,YAAY,eAAe;EAc/B,eAAA,cAAM,YAAY,eAAe"}
|
|
@@ -38,7 +38,7 @@ function createClipboardAssetActions(ctx, pushCreatedNodesUndo) {
|
|
|
38
38
|
}
|
|
39
39
|
async function prepareAsset(file) {
|
|
40
40
|
if (isSVGFile(file)) {
|
|
41
|
-
const data = prepareSVGImport(await file.text());
|
|
41
|
+
const data = prepareSVGImport(await file.text(), { profile: ctx.graph.documentColorSpace });
|
|
42
42
|
return data ? {
|
|
43
43
|
kind: "svg",
|
|
44
44
|
data,
|
|
@@ -133,7 +133,7 @@ function createClipboardAssetActions(ctx, pushCreatedNodesUndo) {
|
|
|
133
133
|
}
|
|
134
134
|
/** Paste SVG markup as layers, as Figma does; false when the text is not SVG. */
|
|
135
135
|
async function pasteSVG(markup, cx, cy) {
|
|
136
|
-
const data = isSVGMarkup(markup) ? prepareSVGImport(markup) : null;
|
|
136
|
+
const data = isSVGMarkup(markup) ? prepareSVGImport(markup, { profile: ctx.graph.documentColorSpace }) : null;
|
|
137
137
|
if (!data) return false;
|
|
138
138
|
const asset = {
|
|
139
139
|
kind: "svg",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.js","names":[],"sources":["../../../src/editor/clipboard/assets.ts"],"sourcesContent":["import { sumBy } from 'es-toolkit'\nimport { filename } from 'pathe/utils'\n\nimport type { Fill } from '@pairdraw/scene-graph'\nimport { getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport { computeImageHash, IMPORTABLE_RASTER_TYPES, isSVGFile } from '@pairdraw/scene-graph/images'\nimport Matrix from '@pairdraw/scene-graph/matrix'\n\nimport { TRANSPARENT } from '#core/constants'\nimport { resolvePasteTarget } from '#core/editor/clipboard/paste/target'\nimport type { EditorContext } from '#core/editor/types'\nimport {\n createSVGNodesFromImport,\n isSVGMarkup,\n prepareSVGImport,\n svgImportFonts,\n type SVGImportData\n} from '#core/io/formats/svg'\nimport { computeAllLayouts } from '#core/layout'\n\nconst IMAGE_MAX_DIMENSION = 4096\nconst ASSET_GAP = 20\n\ninterface PreparedRasterAsset {\n kind: 'raster'\n bytes: Uint8Array\n name: string\n width: number\n height: number\n}\n\ninterface PreparedSVGAsset {\n kind: 'svg'\n data: SVGImportData\n /** A dropped file's name; pasted markup is named as Figma names it. */\n name?: string\n width: number\n height: number\n}\n\ntype PreparedAsset = PreparedRasterAsset | PreparedSVGAsset\n\ntype PushCreatedNodesUndo = (\n created: string[],\n previousSelection: Set<string>,\n label?: string\n) => void\n\nexport function createClipboardAssetActions(\n ctx: EditorContext,\n pushCreatedNodesUndo: PushCreatedNodesUndo\n) {\n function storeImage(bytes: Uint8Array): string {\n const hash = computeImageHash(bytes)\n ctx.graph.images.set(hash, bytes)\n return hash\n }\n\n function decodeImageDimensions(bytes: Uint8Array): { width: number; height: number } | null {\n const ck = ctx.getCk()\n if (!ck) return null\n const skImg = ck.MakeImageFromEncoded(bytes)\n if (!skImg) return null\n let width = skImg.width()\n let height = skImg.height()\n skImg.delete()\n if (width > IMAGE_MAX_DIMENSION || height > IMAGE_MAX_DIMENSION) {\n const ratio = Math.min(IMAGE_MAX_DIMENSION / width, IMAGE_MAX_DIMENSION / height)\n width = Math.round(width * ratio)\n height = Math.round(height * ratio)\n }\n return { width, height }\n }\n\n async function prepareAsset(file: File): Promise<PreparedAsset | null> {\n if (isSVGFile(file)) {\n const data = prepareSVGImport(await file.text())\n return data\n ? {\n kind: 'svg',\n data,\n name: filename(file.name) || undefined,\n width: data.width,\n height: data.height\n }\n : null\n }\n if (!IMPORTABLE_RASTER_TYPES.has(file.type)) return null\n const bytes = new Uint8Array(await file.arrayBuffer())\n const dimensions = decodeImageDimensions(bytes)\n return dimensions ? { kind: 'raster', bytes, name: file.name, ...dimensions } : null\n }\n\n function parentLocalPoint(parentId: string, x: number, y: number) {\n const parent = ctx.graph.getNode(parentId)\n if (!parent) return { x, y }\n const inverse = Matrix.invert(getWorldMatrix(parent, ctx.graph))\n return inverse ? Matrix.mapPoint(inverse, { x, y }) : { x, y }\n }\n\n function createRasterNode(\n asset: PreparedRasterAsset,\n parentId: string,\n x: number,\n y: number\n ): string {\n const hash = storeImage(asset.bytes)\n const fill: Fill = {\n type: 'IMAGE',\n imageHash: hash,\n imageScaleMode: 'FILL',\n color: TRANSPARENT,\n opacity: 1,\n visible: true\n }\n return ctx.graph.createNode('RECTANGLE', parentId, {\n name: filename(asset.name) ?? asset.name,\n x,\n y,\n width: asset.width,\n height: asset.height,\n fills: [fill]\n }).id\n }\n\n function placeAssets(prepared: PreparedAsset[], cx: number, cy: number, label: string): boolean {\n if (prepared.length === 0) return false\n\n const previousSelection = new Set(ctx.state.selectedIds)\n const parentId = resolvePasteTarget(ctx)\n const center = parentLocalPoint(parentId, cx, cy)\n const totalWidth = sumBy(prepared, (asset) => asset.width) + ASSET_GAP * (prepared.length - 1)\n const maxHeight = Math.max(...prepared.map((asset) => asset.height))\n let x = center.x - totalWidth / 2\n const y = center.y - maxHeight / 2\n const created: string[] = []\n\n try {\n for (const asset of prepared) {\n const id =\n asset.kind === 'raster'\n ? createRasterNode(asset, parentId, x, y)\n : createSVGNodesFromImport(ctx.graph, parentId, asset.data, {\n name: asset.name,\n x,\n y\n })?.id\n if (id) created.push(id)\n x += asset.width + ASSET_GAP\n }\n } catch (error) {\n for (const id of created.reverse()) ctx.graph.deleteNode(id)\n throw error\n }\n\n if (created.length === 0) return false\n computeAllLayouts(ctx.graph, ctx.state.currentPageId)\n ctx.setSelectedIds(new Set(created))\n pushCreatedNodesUndo(created, previousSelection, label)\n ctx.requestRender()\n return true\n }\n\n /** Load the fonts of imported SVG text, so it is measured and placed with them. */\n async function loadSVGFonts(assets: PreparedAsset[]) {\n const fonts = assets.flatMap((asset) =>\n asset.kind === 'svg' ? svgImportFonts(asset.data) : []\n )\n await Promise.all(\n fonts.map((font) => ctx.loadFont(font.family, font.style, font.characters).catch(() => null))\n )\n }\n\n async function placeFiles(files: File[], cx: number, cy: number) {\n const prepared = (await Promise.all(files.map(prepareAsset))).filter(\n (asset): asset is PreparedAsset => asset !== null\n )\n await loadSVGFonts(prepared)\n placeAssets(prepared, cx, cy, 'Place files')\n }\n\n /** Paste SVG markup as layers, as Figma does; false when the text is not SVG. */\n async function pasteSVG(markup: string, cx: number, cy: number): Promise<boolean> {\n const data = isSVGMarkup(markup) ? prepareSVGImport(markup) : null\n if (!data) return false\n const asset: PreparedAsset = { kind: 'svg', data, width: data.width, height: data.height }\n await loadSVGFonts([asset])\n return placeAssets([asset], cx, cy, 'Paste SVG')\n }\n\n /**\n * Paste a Mermaid flowchart as FigJam shapes, sections, and connectors, laid out and centred on\n * the point; false when the text is not one.\n */\n async function pasteMermaid(text: string, cx: number, cy: number): Promise<boolean> {\n const { detectMermaidDiagram, parseFlowchart } = await import('@pairdraw/mermaid')\n if (!detectMermaidDiagram(text)) return false\n const chart = parseFlowchart(text)\n const { addFlowchart } = await import('#core/io/formats/mermaid')\n const previousSelection = new Set(ctx.state.selectedIds)\n const parentId = resolvePasteTarget(ctx)\n const { ids: created } = await addFlowchart(ctx.graph, parentId, chart, {\n center: parentLocalPoint(parentId, cx, cy)\n })\n if (created.length === 0) return false\n ctx.setSelectedIds(new Set(created))\n pushCreatedNodesUndo(created, previousSelection, 'Paste Mermaid')\n ctx.requestRender()\n return true\n }\n\n function placeImageFiles(files: File[], cx: number, cy: number) {\n return placeFiles(\n files.filter((file) => IMPORTABLE_RASTER_TYPES.has(file.type)),\n cx,\n cy\n )\n }\n\n return { storeImage, placeFiles, placeImageFiles, pasteSVG, pasteMermaid }\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,MAAM,sBAAsB;AAC5B,MAAM,YAAY;AA2BlB,SAAgB,4BACd,KACA,sBACA;CACA,SAAS,WAAW,OAA2B;EAC7C,MAAM,OAAO,iBAAiB,KAAK;EACnC,IAAI,MAAM,OAAO,IAAI,MAAM,KAAK;EAChC,OAAO;CACT;CAEA,SAAS,sBAAsB,OAA6D;EAC1F,MAAM,KAAK,IAAI,MAAM;EACrB,IAAI,CAAC,IAAI,OAAO;EAChB,MAAM,QAAQ,GAAG,qBAAqB,KAAK;EAC3C,IAAI,CAAC,OAAO,OAAO;EACnB,IAAI,QAAQ,MAAM,MAAM;EACxB,IAAI,SAAS,MAAM,OAAO;EAC1B,MAAM,OAAO;EACb,IAAI,QAAQ,uBAAuB,SAAS,qBAAqB;GAC/D,MAAM,QAAQ,KAAK,IAAI,sBAAsB,OAAO,sBAAsB,MAAM;GAChF,QAAQ,KAAK,MAAM,QAAQ,KAAK;GAChC,SAAS,KAAK,MAAM,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[],"sources":["../../../src/editor/clipboard/assets.ts"],"sourcesContent":["import { sumBy } from 'es-toolkit'\nimport { filename } from 'pathe/utils'\n\nimport type { Fill } from '@pairdraw/scene-graph'\nimport { getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport { computeImageHash, IMPORTABLE_RASTER_TYPES, isSVGFile } from '@pairdraw/scene-graph/images'\nimport Matrix from '@pairdraw/scene-graph/matrix'\n\nimport { TRANSPARENT } from '#core/constants'\nimport { resolvePasteTarget } from '#core/editor/clipboard/paste/target'\nimport type { EditorContext } from '#core/editor/types'\nimport {\n createSVGNodesFromImport,\n isSVGMarkup,\n prepareSVGImport,\n svgImportFonts,\n type SVGImportData\n} from '#core/io/formats/svg'\nimport { computeAllLayouts } from '#core/layout'\n\nconst IMAGE_MAX_DIMENSION = 4096\nconst ASSET_GAP = 20\n\ninterface PreparedRasterAsset {\n kind: 'raster'\n bytes: Uint8Array\n name: string\n width: number\n height: number\n}\n\ninterface PreparedSVGAsset {\n kind: 'svg'\n data: SVGImportData\n /** A dropped file's name; pasted markup is named as Figma names it. */\n name?: string\n width: number\n height: number\n}\n\ntype PreparedAsset = PreparedRasterAsset | PreparedSVGAsset\n\ntype PushCreatedNodesUndo = (\n created: string[],\n previousSelection: Set<string>,\n label?: string\n) => void\n\nexport function createClipboardAssetActions(\n ctx: EditorContext,\n pushCreatedNodesUndo: PushCreatedNodesUndo\n) {\n function storeImage(bytes: Uint8Array): string {\n const hash = computeImageHash(bytes)\n ctx.graph.images.set(hash, bytes)\n return hash\n }\n\n function decodeImageDimensions(bytes: Uint8Array): { width: number; height: number } | null {\n const ck = ctx.getCk()\n if (!ck) return null\n const skImg = ck.MakeImageFromEncoded(bytes)\n if (!skImg) return null\n let width = skImg.width()\n let height = skImg.height()\n skImg.delete()\n if (width > IMAGE_MAX_DIMENSION || height > IMAGE_MAX_DIMENSION) {\n const ratio = Math.min(IMAGE_MAX_DIMENSION / width, IMAGE_MAX_DIMENSION / height)\n width = Math.round(width * ratio)\n height = Math.round(height * ratio)\n }\n return { width, height }\n }\n\n async function prepareAsset(file: File): Promise<PreparedAsset | null> {\n if (isSVGFile(file)) {\n const data = prepareSVGImport(await file.text(), {\n profile: ctx.graph.documentColorSpace\n })\n return data\n ? {\n kind: 'svg',\n data,\n name: filename(file.name) || undefined,\n width: data.width,\n height: data.height\n }\n : null\n }\n if (!IMPORTABLE_RASTER_TYPES.has(file.type)) return null\n const bytes = new Uint8Array(await file.arrayBuffer())\n const dimensions = decodeImageDimensions(bytes)\n return dimensions ? { kind: 'raster', bytes, name: file.name, ...dimensions } : null\n }\n\n function parentLocalPoint(parentId: string, x: number, y: number) {\n const parent = ctx.graph.getNode(parentId)\n if (!parent) return { x, y }\n const inverse = Matrix.invert(getWorldMatrix(parent, ctx.graph))\n return inverse ? Matrix.mapPoint(inverse, { x, y }) : { x, y }\n }\n\n function createRasterNode(\n asset: PreparedRasterAsset,\n parentId: string,\n x: number,\n y: number\n ): string {\n const hash = storeImage(asset.bytes)\n const fill: Fill = {\n type: 'IMAGE',\n imageHash: hash,\n imageScaleMode: 'FILL',\n color: TRANSPARENT,\n opacity: 1,\n visible: true\n }\n return ctx.graph.createNode('RECTANGLE', parentId, {\n name: filename(asset.name) ?? asset.name,\n x,\n y,\n width: asset.width,\n height: asset.height,\n fills: [fill]\n }).id\n }\n\n function placeAssets(prepared: PreparedAsset[], cx: number, cy: number, label: string): boolean {\n if (prepared.length === 0) return false\n\n const previousSelection = new Set(ctx.state.selectedIds)\n const parentId = resolvePasteTarget(ctx)\n const center = parentLocalPoint(parentId, cx, cy)\n const totalWidth = sumBy(prepared, (asset) => asset.width) + ASSET_GAP * (prepared.length - 1)\n const maxHeight = Math.max(...prepared.map((asset) => asset.height))\n let x = center.x - totalWidth / 2\n const y = center.y - maxHeight / 2\n const created: string[] = []\n\n try {\n for (const asset of prepared) {\n const id =\n asset.kind === 'raster'\n ? createRasterNode(asset, parentId, x, y)\n : createSVGNodesFromImport(ctx.graph, parentId, asset.data, {\n name: asset.name,\n x,\n y\n })?.id\n if (id) created.push(id)\n x += asset.width + ASSET_GAP\n }\n } catch (error) {\n for (const id of created.reverse()) ctx.graph.deleteNode(id)\n throw error\n }\n\n if (created.length === 0) return false\n computeAllLayouts(ctx.graph, ctx.state.currentPageId)\n ctx.setSelectedIds(new Set(created))\n pushCreatedNodesUndo(created, previousSelection, label)\n ctx.requestRender()\n return true\n }\n\n /** Load the fonts of imported SVG text, so it is measured and placed with them. */\n async function loadSVGFonts(assets: PreparedAsset[]) {\n const fonts = assets.flatMap((asset) =>\n asset.kind === 'svg' ? svgImportFonts(asset.data) : []\n )\n await Promise.all(\n fonts.map((font) => ctx.loadFont(font.family, font.style, font.characters).catch(() => null))\n )\n }\n\n async function placeFiles(files: File[], cx: number, cy: number) {\n const prepared = (await Promise.all(files.map(prepareAsset))).filter(\n (asset): asset is PreparedAsset => asset !== null\n )\n await loadSVGFonts(prepared)\n placeAssets(prepared, cx, cy, 'Place files')\n }\n\n /** Paste SVG markup as layers, as Figma does; false when the text is not SVG. */\n async function pasteSVG(markup: string, cx: number, cy: number): Promise<boolean> {\n const data = isSVGMarkup(markup)\n ? prepareSVGImport(markup, { profile: ctx.graph.documentColorSpace })\n : null\n if (!data) return false\n const asset: PreparedAsset = { kind: 'svg', data, width: data.width, height: data.height }\n await loadSVGFonts([asset])\n return placeAssets([asset], cx, cy, 'Paste SVG')\n }\n\n /**\n * Paste a Mermaid flowchart as FigJam shapes, sections, and connectors, laid out and centred on\n * the point; false when the text is not one.\n */\n async function pasteMermaid(text: string, cx: number, cy: number): Promise<boolean> {\n const { detectMermaidDiagram, parseFlowchart } = await import('@pairdraw/mermaid')\n if (!detectMermaidDiagram(text)) return false\n const chart = parseFlowchart(text)\n const { addFlowchart } = await import('#core/io/formats/mermaid')\n const previousSelection = new Set(ctx.state.selectedIds)\n const parentId = resolvePasteTarget(ctx)\n const { ids: created } = await addFlowchart(ctx.graph, parentId, chart, {\n center: parentLocalPoint(parentId, cx, cy)\n })\n if (created.length === 0) return false\n ctx.setSelectedIds(new Set(created))\n pushCreatedNodesUndo(created, previousSelection, 'Paste Mermaid')\n ctx.requestRender()\n return true\n }\n\n function placeImageFiles(files: File[], cx: number, cy: number) {\n return placeFiles(\n files.filter((file) => IMPORTABLE_RASTER_TYPES.has(file.type)),\n cx,\n cy\n )\n }\n\n return { storeImage, placeFiles, placeImageFiles, pasteSVG, pasteMermaid }\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,MAAM,sBAAsB;AAC5B,MAAM,YAAY;AA2BlB,SAAgB,4BACd,KACA,sBACA;CACA,SAAS,WAAW,OAA2B;EAC7C,MAAM,OAAO,iBAAiB,KAAK;EACnC,IAAI,MAAM,OAAO,IAAI,MAAM,KAAK;EAChC,OAAO;CACT;CAEA,SAAS,sBAAsB,OAA6D;EAC1F,MAAM,KAAK,IAAI,MAAM;EACrB,IAAI,CAAC,IAAI,OAAO;EAChB,MAAM,QAAQ,GAAG,qBAAqB,KAAK;EAC3C,IAAI,CAAC,OAAO,OAAO;EACnB,IAAI,QAAQ,MAAM,MAAM;EACxB,IAAI,SAAS,MAAM,OAAO;EAC1B,MAAM,OAAO;EACb,IAAI,QAAQ,uBAAuB,SAAS,qBAAqB;GAC/D,MAAM,QAAQ,KAAK,IAAI,sBAAsB,OAAO,sBAAsB,MAAM;GAChF,QAAQ,KAAK,MAAM,QAAQ,KAAK;GAChC,SAAS,KAAK,MAAM,SAAS,KAAK;EACpC;EACA,OAAO;GAAE;GAAO;EAAO;CACzB;CAEA,eAAe,aAAa,MAA2C;EACrE,IAAI,UAAU,IAAI,GAAG;GACnB,MAAM,OAAO,iBAAiB,MAAM,KAAK,KAAK,GAAG,EAC/C,SAAS,IAAI,MAAM,mBACrB,CAAC;GACD,OAAO,OACH;IACE,MAAM;IACN;IACA,MAAM,SAAS,KAAK,IAAI,KAAK,KAAA;IAC7B,OAAO,KAAK;IACZ,QAAQ,KAAK;GACf,IACA;EACN;EACA,IAAI,CAAC,wBAAwB,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OAAO;EAClB,MAAM,QAAuB;GAAE,MAAM;GAAO;GAAM,OAAO,KAAK;GAAO,QAAQ,KAAK;EAAO;EACzF,MAAM,aAAa,CAAC,KAAK,CAAC;EAC1B,OAAO,YAAY,CAAC,KAAK,GAAG,IAAI,IAAI,WAAW;CACjD;;;;;CAMA,eAAe,aAAa,MAAc,IAAY,IAA8B;EAClF,MAAM,EAAE,sBAAsB,mBAAmB,MAAM,OAAO;EAC9D,IAAI,CAAC,qBAAqB,IAAI,GAAG,OAAO;EACxC,MAAM,QAAQ,eAAe,IAAI;EACjC,MAAM,EAAE,iBAAiB,MAAM,OAAO;EACtC,MAAM,oBAAoB,IAAI,IAAI,IAAI,MAAM,WAAW;EACvD,MAAM,WAAW,mBAAmB,GAAG;EACvC,MAAM,EAAE,KAAK,YAAY,MAAM,aAAa,IAAI,OAAO,UAAU,OAAO,EACtE,QAAQ,iBAAiB,UAAU,IAAI,EAAE,EAC3C,CAAC;EACD,IAAI,QAAQ,WAAW,GAAG,OAAO;EACjC,IAAI,eAAe,IAAI,IAAI,OAAO,CAAC;EACnC,qBAAqB,SAAS,mBAAmB,eAAe;EAChE,IAAI,cAAc;EAClB,OAAO;CACT;CAEA,SAAS,gBAAgB,OAAe,IAAY,IAAY;EAC9D,OAAO,WACL,MAAM,QAAQ,SAAS,wBAAwB,IAAI,KAAK,IAAI,CAAC,GAC7D,IACA,EACF;CACF;CAEA,OAAO;EAAE;EAAY;EAAY;EAAiB;EAAU;CAAa;AAC3E"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ClipboardNodeTree } from "./snapshot.js";
|
|
2
|
+
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
3
|
+
//#region src/editor/clipboard/component-matches.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The component or set already in this document that a snapshot's dependency becomes, when the
|
|
6
|
+
* dependency came from here before. A node a paste created carries its clipboard origin, and a
|
|
7
|
+
* component read from a `.fig` carries the source identity Figma stores; names are never compared,
|
|
8
|
+
* so an unrelated same-named component is never reused.
|
|
9
|
+
*/
|
|
10
|
+
declare function matchClipboardComponents(graph: SceneGraph, sourceRootId: string, dependencies: ClipboardNodeTree[]): Map<string, string>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { matchClipboardComponents };
|
|
13
|
+
//# sourceMappingURL=component-matches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-matches.d.ts","names":[],"sources":["../../../src/editor/clipboard/component-matches.ts"],"mappings":";;;;;;;;;iBAagB,yBACd,OAAO,YACP,sBACA,cAAc,sBACb"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { collectSubtrees } from "../history/subtree.js";
|
|
2
|
+
import { PAIRDRAW_PLUGIN_DATA, readPluginData } from "@pairdraw/scene-graph/plugin-data";
|
|
3
|
+
//#region src/editor/clipboard/component-matches.ts
|
|
4
|
+
/**
|
|
5
|
+
* The component or set already in this document that a snapshot's dependency becomes, when the
|
|
6
|
+
* dependency came from here before. A node a paste created carries its clipboard origin, and a
|
|
7
|
+
* component read from a `.fig` carries the source identity Figma stores; names are never compared,
|
|
8
|
+
* so an unrelated same-named component is never reused.
|
|
9
|
+
*/
|
|
10
|
+
function matchClipboardComponents(graph, sourceRootId, dependencies) {
|
|
11
|
+
const roots = [...graph.getAllNodes()].filter((node) => node.type === "COMPONENT" || node.type === "COMPONENT_SET");
|
|
12
|
+
const byOrigin = /* @__PURE__ */ new Map();
|
|
13
|
+
const bySource = /* @__PURE__ */ new Map();
|
|
14
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const root of roots) {
|
|
16
|
+
const origin = readPluginData(root.pluginData, PAIRDRAW_PLUGIN_DATA.clipboardOrigin);
|
|
17
|
+
if (origin?.documentId === sourceRootId) byOrigin.set(origin.nodeId, root.id);
|
|
18
|
+
if (root.source.id) bySource.set(root.source.id, root.id);
|
|
19
|
+
for (const key of [root.sourceLibraryKey, root.componentKey]) if (key && !byKey.has(key)) byKey.set(key, root.id);
|
|
20
|
+
}
|
|
21
|
+
const matches = /* @__PURE__ */ new Map();
|
|
22
|
+
const matchedRoots = /* @__PURE__ */ new Set();
|
|
23
|
+
const mapExistingChildren = (dependency, existingRootId) => {
|
|
24
|
+
const byChildOrigin = /* @__PURE__ */ new Map();
|
|
25
|
+
const byChildSource = /* @__PURE__ */ new Map();
|
|
26
|
+
for (const node of collectSubtrees(graph, [existingRootId])) {
|
|
27
|
+
const origin = readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.clipboardOrigin);
|
|
28
|
+
if (origin?.documentId === sourceRootId) byChildOrigin.set(origin.nodeId, node.id);
|
|
29
|
+
if (node.source.id) byChildSource.set(node.source.id, node.id);
|
|
30
|
+
}
|
|
31
|
+
const visit = (node) => {
|
|
32
|
+
const existing = byChildOrigin.get(node.id) ?? (node.source.id ? byChildSource.get(node.source.id) : void 0);
|
|
33
|
+
if (existing) matches.set(node.id, existing);
|
|
34
|
+
for (const child of node.children ?? []) visit(child);
|
|
35
|
+
};
|
|
36
|
+
for (const child of dependency.children ?? []) visit(child);
|
|
37
|
+
};
|
|
38
|
+
for (const dependency of dependencies) {
|
|
39
|
+
const existing = byOrigin.get(dependency.id) ?? (dependency.sourceLibraryKey ? byKey.get(dependency.sourceLibraryKey) : void 0) ?? (dependency.componentKey ? byKey.get(dependency.componentKey) : void 0) ?? (dependency.source.id ? bySource.get(dependency.source.id) : void 0);
|
|
40
|
+
if (!existing || matchedRoots.has(existing)) continue;
|
|
41
|
+
matchedRoots.add(existing);
|
|
42
|
+
matches.set(dependency.id, existing);
|
|
43
|
+
mapExistingChildren(dependency, existing);
|
|
44
|
+
}
|
|
45
|
+
return matches;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { matchClipboardComponents };
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=component-matches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-matches.js","names":[],"sources":["../../../src/editor/clipboard/component-matches.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\nimport { PAIRDRAW_PLUGIN_DATA, readPluginData } from '@pairdraw/scene-graph/plugin-data'\n\nimport { collectSubtrees } from '#core/editor/history/subtree'\n\nimport type { ClipboardNodeTree } from './snapshot'\n\n/**\n * The component or set already in this document that a snapshot's dependency becomes, when the\n * dependency came from here before. A node a paste created carries its clipboard origin, and a\n * component read from a `.fig` carries the source identity Figma stores; names are never compared,\n * so an unrelated same-named component is never reused.\n */\nexport function matchClipboardComponents(\n graph: SceneGraph,\n sourceRootId: string,\n dependencies: ClipboardNodeTree[]\n): Map<string, string> {\n const roots = [...graph.getAllNodes()].filter(\n (node) => node.type === 'COMPONENT' || node.type === 'COMPONENT_SET'\n )\n const byOrigin = new Map<string, string>()\n const bySource = new Map<string, string>()\n const byKey = new Map<string, string>()\n for (const root of roots) {\n const origin = readPluginData(root.pluginData, PAIRDRAW_PLUGIN_DATA.clipboardOrigin)\n if (origin?.documentId === sourceRootId) byOrigin.set(origin.nodeId, root.id)\n if (root.source.id) bySource.set(root.source.id, root.id)\n for (const key of [root.sourceLibraryKey, root.componentKey])\n if (key && !byKey.has(key)) byKey.set(key, root.id)\n }\n const matches = new Map<string, string>()\n const matchedRoots = new Set<string>()\n\n const mapExistingChildren = (dependency: ClipboardNodeTree, existingRootId: string) => {\n const byChildOrigin = new Map<string, string>()\n const byChildSource = new Map<string, string>()\n for (const node of collectSubtrees(graph, [existingRootId])) {\n const origin = readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.clipboardOrigin)\n if (origin?.documentId === sourceRootId) byChildOrigin.set(origin.nodeId, node.id)\n if (node.source.id) byChildSource.set(node.source.id, node.id)\n }\n const visit = (node: ClipboardNodeTree) => {\n const existing =\n byChildOrigin.get(node.id) ??\n (node.source.id ? byChildSource.get(node.source.id) : undefined)\n if (existing) matches.set(node.id, existing)\n for (const child of node.children ?? []) visit(child)\n }\n for (const child of dependency.children ?? []) visit(child)\n }\n\n for (const dependency of dependencies) {\n const existing =\n byOrigin.get(dependency.id) ??\n (dependency.sourceLibraryKey ? byKey.get(dependency.sourceLibraryKey) : undefined) ??\n (dependency.componentKey ? byKey.get(dependency.componentKey) : undefined) ??\n (dependency.source.id ? bySource.get(dependency.source.id) : undefined)\n if (!existing || matchedRoots.has(existing)) continue\n matchedRoots.add(existing)\n matches.set(dependency.id, existing)\n mapExistingChildren(dependency, existing)\n }\n return matches\n}\n"],"mappings":";;;;;;;;;AAaA,SAAgB,yBACd,OACA,cACA,cACqB;CACrB,MAAM,QAAQ,CAAC,GAAG,MAAM,YAAY,CAAC,CAAC,CAAC,QACpC,SAAS,KAAK,SAAS,eAAe,KAAK,SAAS,eACvD;CACA,MAAM,2BAAW,IAAI,IAAoB;CACzC,MAAM,2BAAW,IAAI,IAAoB;CACzC,MAAM,wBAAQ,IAAI,IAAoB;CACtC,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,SAAS,eAAe,KAAK,YAAY,qBAAqB,eAAe;EACnF,IAAI,QAAQ,eAAe,cAAc,SAAS,IAAI,OAAO,QAAQ,KAAK,EAAE;EAC5E,IAAI,KAAK,OAAO,IAAI,SAAS,IAAI,KAAK,OAAO,IAAI,KAAK,EAAE;EACxD,KAAK,MAAM,OAAO,CAAC,KAAK,kBAAkB,KAAK,YAAY,GACzD,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,GAAG,MAAM,IAAI,KAAK,KAAK,EAAE;CACtD;CACA,MAAM,0BAAU,IAAI,IAAoB;CACxC,MAAM,+BAAe,IAAI,IAAY;CAErC,MAAM,uBAAuB,YAA+B,mBAA2B;EACrF,MAAM,gCAAgB,IAAI,IAAoB;EAC9C,MAAM,gCAAgB,IAAI,IAAoB;EAC9C,KAAK,MAAM,QAAQ,gBAAgB,OAAO,CAAC,cAAc,CAAC,GAAG;GAC3D,MAAM,SAAS,eAAe,KAAK,YAAY,qBAAqB,eAAe;GACnF,IAAI,QAAQ,eAAe,cAAc,cAAc,IAAI,OAAO,QAAQ,KAAK,EAAE;GACjF,IAAI,KAAK,OAAO,IAAI,cAAc,IAAI,KAAK,OAAO,IAAI,KAAK,EAAE;EAC/D;EACA,MAAM,SAAS,SAA4B;GACzC,MAAM,WACJ,cAAc,IAAI,KAAK,EAAE,MACxB,KAAK,OAAO,KAAK,cAAc,IAAI,KAAK,OAAO,EAAE,IAAI,KAAA;GACxD,IAAI,UAAU,QAAQ,IAAI,KAAK,IAAI,QAAQ;GAC3C,KAAK,MAAM,SAAS,KAAK,YAAY,CAAC,GAAG,MAAM,KAAK;EACtD;EACA,KAAK,MAAM,SAAS,WAAW,YAAY,CAAC,GAAG,MAAM,KAAK;CAC5D;CAEA,KAAK,MAAM,cAAc,cAAc;EACrC,MAAM,WACJ,SAAS,IAAI,WAAW,EAAE,MACzB,WAAW,mBAAmB,MAAM,IAAI,WAAW,gBAAgB,IAAI,KAAA,OACvE,WAAW,eAAe,MAAM,IAAI,WAAW,YAAY,IAAI,KAAA,OAC/D,WAAW,OAAO,KAAK,SAAS,IAAI,WAAW,OAAO,EAAE,IAAI,KAAA;EAC/D,IAAI,CAAC,YAAY,aAAa,IAAI,QAAQ,GAAG;EAC7C,aAAa,IAAI,QAAQ;EACzB,QAAQ,IAAI,WAAW,IAAI,QAAQ;EACnC,oBAAoB,YAAY,QAAQ;CAC1C;CACA,OAAO;AACT"}
|
|
@@ -6,6 +6,13 @@ import { SceneNode } from "@pairdraw/scene-graph";
|
|
|
6
6
|
interface ClipboardDependencyImport {
|
|
7
7
|
nodes: ClipboardSnapshot['nodes'];
|
|
8
8
|
componentDependencies: ClipboardSnapshot['componentDependencies'];
|
|
9
|
+
/**
|
|
10
|
+
* By a dependency's id here, the component or set already in this document it becomes, when the
|
|
11
|
+
* same snapshot was pasted before. A reuse keeps the local main, as in Figma.
|
|
12
|
+
*/
|
|
13
|
+
componentMatches: Map<string, string>;
|
|
14
|
+
/** The copying document's root id, for a foreign paste that creates dependencies here. */
|
|
15
|
+
clipboardOrigin?: string;
|
|
9
16
|
styleSnapshots: SceneNode[];
|
|
10
17
|
/**
|
|
11
18
|
* Whether the layers bind variables of this document now, whose values may differ from the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencies.d.ts","names":[],"sources":["../../../src/editor/clipboard/dependencies.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"dependencies.d.ts","names":[],"sources":["../../../src/editor/clipboard/dependencies.ts"],"mappings":";;;;;UAkBiB;EACf,OAAO;EACP,uBAAuB;;;;;EAKvB,kBAAkB;;EAElB;EACA,gBAAgB;;;;;EAKhB;EACA;EACA;;;iBAIc,oCACd,KAAK,eACL,UAAU,mBACV,SAAS,wBACR;;;;;;;iBAiCa,4BACd,KAAK,eACL,UAAU,mBACV,SAAS,wBACR"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { detachClipboardNode } from "./detach.js";
|
|
2
2
|
import { importClipboardVariables, remapClipboardVariableBindings } from "./variables.js";
|
|
3
|
+
import { matchClipboardComponents } from "./component-matches.js";
|
|
3
4
|
import { addsRenamed, matchClipboardCollections, matchClipboardStyles } from "./conflicts.js";
|
|
4
5
|
import { applyExistingStyles } from "./existing-styles.js";
|
|
5
6
|
import { numberedName } from "@pairdraw/scene-graph/naming";
|
|
@@ -35,6 +36,7 @@ function importClipboardDependencies(ctx, snapshot, choice) {
|
|
|
35
36
|
if (snapshot.sourceRootId === ctx.graph.rootId) return {
|
|
36
37
|
nodes,
|
|
37
38
|
componentDependencies: componentDependencies.filter((node) => !ctx.graph.getNode(node.id)),
|
|
39
|
+
componentMatches: /* @__PURE__ */ new Map(),
|
|
38
40
|
styleSnapshots: [],
|
|
39
41
|
resolveBindings: false
|
|
40
42
|
};
|
|
@@ -47,6 +49,7 @@ function importClipboardDependencies(ctx, snapshot, choice) {
|
|
|
47
49
|
return {
|
|
48
50
|
nodes,
|
|
49
51
|
componentDependencies,
|
|
52
|
+
componentMatches: /* @__PURE__ */ new Map(),
|
|
50
53
|
styleSnapshots: [],
|
|
51
54
|
resolveBindings: false
|
|
52
55
|
};
|
|
@@ -102,6 +105,8 @@ function importClipboardDependencies(ctx, snapshot, choice) {
|
|
|
102
105
|
return {
|
|
103
106
|
nodes,
|
|
104
107
|
componentDependencies,
|
|
108
|
+
componentMatches: matchClipboardComponents(ctx.graph, snapshot.sourceRootId, componentDependencies),
|
|
109
|
+
clipboardOrigin: snapshot.sourceRootId,
|
|
105
110
|
styleSnapshots,
|
|
106
111
|
resolveBindings: snapshot.variableDependencies.variables.length > 0,
|
|
107
112
|
applyVariables: variables.apply,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencies.js","names":[],"sources":["../../../src/editor/clipboard/dependencies.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\nimport { numberedName } from '@pairdraw/scene-graph/naming'\n\nimport type { EditorContext } from '#core/editor/types'\n\nimport {\n addsRenamed,\n matchClipboardCollections,\n matchClipboardStyles,\n type ClipboardCollectionMerge,\n type ClipboardImportChoice\n} from './conflicts'\nimport { detachClipboardNode } from './detach'\nimport { applyExistingStyles } from './existing-styles'\nimport type { ClipboardNodeTree, ClipboardSnapshot } from './snapshot'\nimport { importClipboardVariables, remapClipboardVariableBindings } from './variables'\n\nexport interface ClipboardDependencyImport {\n nodes: ClipboardSnapshot['nodes']\n componentDependencies: ClipboardSnapshot['componentDependencies']\n styleSnapshots: SceneNode[]\n /**\n * Whether the layers bind variables of this document now, whose values may differ from the\n * copied ones, so the paste resolves their bindings once they are placed.\n */\n resolveBindings: boolean\n applyVariables?: () => void\n revertVariables?: () => void\n}\n\n/** Imports a snapshot's styles and variables as undo steps of the running batch. */\nexport function importClipboardDependenciesWithUndo(\n ctx: EditorContext,\n snapshot: ClipboardSnapshot,\n choice?: ClipboardImportChoice\n): ClipboardDependencyImport {\n const dependencies = importClipboardDependencies(ctx, snapshot, choice)\n if (dependencies.styleSnapshots.length > 0) {\n ctx.undo.push({\n label: 'Import clipboard styles',\n forward: () => {\n for (const style of dependencies.styleSnapshots) {\n ctx.graph.preserveSourceMetadataDuring(() =>\n ctx.graph.createNode(style.type, ctx.state.currentPageId, style)\n )\n }\n },\n inverse: () => {\n for (const style of dependencies.styleSnapshots) ctx.graph.deleteNode(style.id)\n }\n })\n }\n if (dependencies.applyVariables && dependencies.revertVariables) {\n ctx.undo.push({\n label: 'Import clipboard variables',\n forward: dependencies.applyVariables,\n inverse: dependencies.revertVariables\n })\n }\n return dependencies\n}\n\n/**\n * The snapshot's layers ready to paste here. A copy from another document brings its styles and\n * variables, or with an `as-is` choice keeps only the values its layers showed. Without a choice\n * every collection and style is added; with one, a same-named collection or style is used\n * unless the choice adds it renamed.\n */\nexport function importClipboardDependencies(\n ctx: EditorContext,\n snapshot: ClipboardSnapshot,\n choice?: ClipboardImportChoice\n): ClipboardDependencyImport {\n const nodes = structuredClone(snapshot.nodes)\n const componentDependencies = structuredClone(snapshot.componentDependencies)\n if (snapshot.sourceRootId === ctx.graph.rootId) {\n return {\n nodes,\n componentDependencies: componentDependencies.filter((node) => !ctx.graph.getNode(node.id)),\n styleSnapshots: [],\n resolveBindings: false\n }\n }\n if (choice?.mode === 'as-is') {\n const detach = (node: ClipboardNodeTree) => {\n detachClipboardNode(node, snapshot.resolvedBindings?.get(node.id))\n for (const child of node.children ?? []) detach(child)\n }\n for (const node of [...nodes, ...componentDependencies]) detach(node)\n return {
|
|
1
|
+
{"version":3,"file":"dependencies.js","names":[],"sources":["../../../src/editor/clipboard/dependencies.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\nimport { numberedName } from '@pairdraw/scene-graph/naming'\n\nimport type { EditorContext } from '#core/editor/types'\n\nimport { matchClipboardComponents } from './component-matches'\nimport {\n addsRenamed,\n matchClipboardCollections,\n matchClipboardStyles,\n type ClipboardCollectionMerge,\n type ClipboardImportChoice\n} from './conflicts'\nimport { detachClipboardNode } from './detach'\nimport { applyExistingStyles } from './existing-styles'\nimport type { ClipboardNodeTree, ClipboardSnapshot } from './snapshot'\nimport { importClipboardVariables, remapClipboardVariableBindings } from './variables'\n\nexport interface ClipboardDependencyImport {\n nodes: ClipboardSnapshot['nodes']\n componentDependencies: ClipboardSnapshot['componentDependencies']\n /**\n * By a dependency's id here, the component or set already in this document it becomes, when the\n * same snapshot was pasted before. A reuse keeps the local main, as in Figma.\n */\n componentMatches: Map<string, string>\n /** The copying document's root id, for a foreign paste that creates dependencies here. */\n clipboardOrigin?: string\n styleSnapshots: SceneNode[]\n /**\n * Whether the layers bind variables of this document now, whose values may differ from the\n * copied ones, so the paste resolves their bindings once they are placed.\n */\n resolveBindings: boolean\n applyVariables?: () => void\n revertVariables?: () => void\n}\n\n/** Imports a snapshot's styles and variables as undo steps of the running batch. */\nexport function importClipboardDependenciesWithUndo(\n ctx: EditorContext,\n snapshot: ClipboardSnapshot,\n choice?: ClipboardImportChoice\n): ClipboardDependencyImport {\n const dependencies = importClipboardDependencies(ctx, snapshot, choice)\n if (dependencies.styleSnapshots.length > 0) {\n ctx.undo.push({\n label: 'Import clipboard styles',\n forward: () => {\n for (const style of dependencies.styleSnapshots) {\n ctx.graph.preserveSourceMetadataDuring(() =>\n ctx.graph.createNode(style.type, ctx.state.currentPageId, style)\n )\n }\n },\n inverse: () => {\n for (const style of dependencies.styleSnapshots) ctx.graph.deleteNode(style.id)\n }\n })\n }\n if (dependencies.applyVariables && dependencies.revertVariables) {\n ctx.undo.push({\n label: 'Import clipboard variables',\n forward: dependencies.applyVariables,\n inverse: dependencies.revertVariables\n })\n }\n return dependencies\n}\n\n/**\n * The snapshot's layers ready to paste here. A copy from another document brings its styles and\n * variables, or with an `as-is` choice keeps only the values its layers showed. Without a choice\n * every collection and style is added; with one, a same-named collection or style is used\n * unless the choice adds it renamed.\n */\nexport function importClipboardDependencies(\n ctx: EditorContext,\n snapshot: ClipboardSnapshot,\n choice?: ClipboardImportChoice\n): ClipboardDependencyImport {\n const nodes = structuredClone(snapshot.nodes)\n const componentDependencies = structuredClone(snapshot.componentDependencies)\n if (snapshot.sourceRootId === ctx.graph.rootId) {\n return {\n nodes,\n componentDependencies: componentDependencies.filter((node) => !ctx.graph.getNode(node.id)),\n componentMatches: new Map(),\n styleSnapshots: [],\n resolveBindings: false\n }\n }\n if (choice?.mode === 'as-is') {\n const detach = (node: ClipboardNodeTree) => {\n detachClipboardNode(node, snapshot.resolvedBindings?.get(node.id))\n for (const child of node.children ?? []) detach(child)\n }\n for (const node of [...nodes, ...componentDependencies]) detach(node)\n return {\n nodes,\n componentDependencies,\n componentMatches: new Map(),\n styleSnapshots: [],\n resolveBindings: false\n }\n }\n const styleIds = new Map<string, string>()\n /** This document's styles the layers use in place of copied ones, by id. */\n const existingStyles = new Map<string, SceneNode>()\n const styleSnapshots: SceneNode[] = []\n const styleMatches = choice ? matchClipboardStyles(ctx.graph, snapshot.styleDefinitions) : null\n const takenStyleNames = [...ctx.graph.getAllNodes()].flatMap((node) =>\n node.sharedStyleType ? [node.name] : []\n )\n for (const definition of snapshot.styleDefinitions) {\n const sourceStyleId = definition.source.id\n if (!sourceStyleId) continue\n const match = styleMatches?.get(sourceStyleId)\n const renamed = addsRenamed(choice, sourceStyleId)\n if (match?.source.id && !renamed) {\n styleIds.set(sourceStyleId, match.source.id)\n existingStyles.set(match.source.id, match)\n continue\n }\n const pastedStyleId = crypto.randomUUID()\n const name = renamed ? numberedName(definition.name, takenStyleNames) : definition.name\n takenStyleNames.push(name)\n let pasted: SceneNode | undefined\n ctx.graph.preserveSourceMetadataDuring(() => {\n pasted = ctx.graph.createNode(definition.type, ctx.state.currentPageId, {\n ...structuredClone(definition),\n id: undefined,\n name,\n parentId: ctx.state.currentPageId,\n childIds: [],\n source: { ...definition.source, id: pastedStyleId }\n })\n })\n if (!pasted) continue\n styleIds.set(sourceStyleId, pastedStyleId)\n styleSnapshots.push(structuredClone(pasted))\n }\n const collections = snapshot.variableDependencies.collections\n const merges = choice\n ? matchClipboardCollections(ctx.graph, collections)\n : new Map<string, ClipboardCollectionMerge>()\n for (const collection of collections)\n if (addsRenamed(choice, collection.id)) merges.delete(collection.id)\n const variables = importClipboardVariables(\n ctx.graph,\n snapshot.variableDependencies,\n merges,\n new Set(collections.flatMap(({ id }) => (addsRenamed(choice, id) ? [id] : [])))\n )\n function remap(node: ClipboardSnapshot['nodes'][number]) {\n remapClipboardVariableBindings(\n node,\n variables.variableIds,\n variables.collectionIds,\n variables.modeIds,\n styleIds,\n variables.droppedModes\n )\n applyExistingStyles(ctx.graph, node, existingStyles)\n for (const child of node.children ?? []) remap(child)\n }\n for (const node of [...nodes, ...componentDependencies]) remap(node)\n variables.apply()\n return {\n nodes,\n componentDependencies,\n componentMatches: matchClipboardComponents(\n ctx.graph,\n snapshot.sourceRootId,\n componentDependencies\n ),\n clipboardOrigin: snapshot.sourceRootId,\n styleSnapshots,\n resolveBindings: snapshot.variableDependencies.variables.length > 0,\n applyVariables: variables.apply,\n revertVariables: variables.revert\n }\n}\n"],"mappings":";;;;;;;;AAuCA,SAAgB,oCACd,KACA,UACA,QAC2B;CAC3B,MAAM,eAAe,4BAA4B,KAAK,UAAU,MAAM;CACtE,IAAI,aAAa,eAAe,SAAS,GACvC,IAAI,KAAK,KAAK;EACZ,OAAO;EACP,eAAe;GACb,KAAK,MAAM,SAAS,aAAa,gBAC/B,IAAI,MAAM,mCACR,IAAI,MAAM,WAAW,MAAM,MAAM,IAAI,MAAM,eAAe,KAAK,CACjE;EAEJ;EACA,eAAe;GACb,KAAK,MAAM,SAAS,aAAa,gBAAgB,IAAI,MAAM,WAAW,MAAM,EAAE;EAChF;CACF,CAAC;CAEH,IAAI,aAAa,kBAAkB,aAAa,iBAC9C,IAAI,KAAK,KAAK;EACZ,OAAO;EACP,SAAS,aAAa;EACtB,SAAS,aAAa;CACxB,CAAC;CAEH,OAAO;AACT;;;;;;;AAQA,SAAgB,4BACd,KACA,UACA,QAC2B;CAC3B,MAAM,QAAQ,gBAAgB,SAAS,KAAK;CAC5C,MAAM,wBAA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B,iBAAiB,UAAU;CAC7B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clipboard.d.ts","names":[],"sources":["../../src/editor/clipboard.ts"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","names":[],"sources":["../../src/editor/clipboard.ts"],"mappings":";;;;;;;;;;;KA+CK;EACH;;;;;EAKA;;EAEA,eAAe;;;;;;iBAgBD,cACd,KAAK,KAAK,yBACV,MAAM,WACN,kBACA,UAAU,SACT;iBAQa,uBAAuB,KAAK;;;;;;;;;;;EAoH9B,gBAAA,UAAA,mBAAiB,YACf,QAAM,UACT,iBAAY;EA0BY,gBAAA,cAAM,YAAc,QAAM,UAAW,iBAAY;EAgFhD,iBAAA,cAAM,aAAa,gBAAgB;EA4MnC,oBAAA;EASN,cAAA,SAAA,kBAAgB,gBAAkB;;;EApbtB,oBAAA,eAAA;EAijBlB,gBAAA,MAAA,WAAS,kBAAkB,UAAY,WAAM"}
|
package/dist/editor/clipboard.js
CHANGED
|
@@ -20,12 +20,14 @@ import { fitEnclosingGroupsWithUndo } from "./structure/group/bounds.js";
|
|
|
20
20
|
import { loadBoundFonts } from "./text/bound-fonts.js";
|
|
21
21
|
import { parseFigmaClipboard } from "@pairdraw/fig/clipboard";
|
|
22
22
|
import { slotPropertyId } from "@pairdraw/scene-graph/slots";
|
|
23
|
+
import { PAIRDRAW_PLUGIN_DATA, withPluginData } from "@pairdraw/scene-graph/plugin-data";
|
|
23
24
|
import { getAxisAlignedBoundsInParent, getNodeLocalMatrix } from "@pairdraw/scene-graph/coordinate";
|
|
24
25
|
import { keepPastedBoundPaints } from "@pairdraw/scene-graph/variables";
|
|
25
26
|
import { CommittedGraphEventError } from "@pairdraw/scene-graph";
|
|
26
27
|
import { uniq } from "es-toolkit";
|
|
27
28
|
import { attachedConnectors } from "@pairdraw/scene-graph/connectors";
|
|
28
29
|
import { cycleSafeParent, recordInstanceOverride } from "@pairdraw/scene-graph/instances";
|
|
30
|
+
import { ownInstanceOverrides } from "@pairdraw/scene-graph/instances/overrides";
|
|
29
31
|
//#region src/editor/clipboard.ts
|
|
30
32
|
/**
|
|
31
33
|
* A copy of the layer under the same parent, keeping its name as Figma does. A main component
|
|
@@ -145,7 +147,9 @@ function createClipboardActions(ctx) {
|
|
|
145
147
|
const dependencies = importClipboardDependenciesWithUndo(ctx, snapshot, options.dependencies);
|
|
146
148
|
created = pastePairdrawNodes(dependencies.nodes, snapshot.placement, snapshot.images, snapshot.sourceRootId === ctx.graph.rootId ? snapshot.appliedBoundPaints : /* @__PURE__ */ new Map(), dependencies.componentDependencies, cursorPos, {
|
|
147
149
|
...options,
|
|
148
|
-
resolveBindings: dependencies.resolveBindings
|
|
150
|
+
resolveBindings: dependencies.resolveBindings,
|
|
151
|
+
componentMatches: dependencies.componentMatches,
|
|
152
|
+
clipboardOrigin: dependencies.clipboardOrigin
|
|
149
153
|
});
|
|
150
154
|
});
|
|
151
155
|
await fontActions.loadFontsForNodes(created);
|
|
@@ -250,37 +254,62 @@ function createClipboardActions(ctx) {
|
|
|
250
254
|
const replacementTargets = options.replaceSelection ? selectedReplacementTargets(ctx) : [];
|
|
251
255
|
const instanceTargets = instanceReplacementTargets(options);
|
|
252
256
|
for (const [hash, bytes] of images) ctx.graph.images.set(hash, bytes);
|
|
257
|
+
const matches = options.componentMatches ?? /* @__PURE__ */ new Map();
|
|
253
258
|
const created = [];
|
|
254
259
|
const copiedIds = /* @__PURE__ */ new Map();
|
|
255
|
-
const
|
|
256
|
-
|
|
260
|
+
const pastedIds = /* @__PURE__ */ new Set();
|
|
261
|
+
const seedMatches = () => {
|
|
262
|
+
for (const [sourceId, existingId] of matches) if (ctx.graph.getNode(existingId)) copiedIds.set(sourceId, existingId);
|
|
263
|
+
};
|
|
264
|
+
seedMatches();
|
|
265
|
+
const createNodeTree = (source, parentId, originDocumentId) => {
|
|
266
|
+
const existing = copiedIds.get(source.id);
|
|
267
|
+
if (existing && ctx.graph.getNode(existing)) return existing;
|
|
268
|
+
const { id: _id, childIds: _childIds, children = [], parentId: _parentId, pluginData, ...rest } = source;
|
|
269
|
+
const record = originDocumentId ? withPluginData(pluginData, PAIRDRAW_PLUGIN_DATA.clipboardOrigin, {
|
|
270
|
+
documentId: originDocumentId,
|
|
271
|
+
nodeId: source.id
|
|
272
|
+
}) : pluginData;
|
|
257
273
|
const node = ctx.graph.createNode(source.type, parentId, {
|
|
258
274
|
...structuredClone(rest),
|
|
275
|
+
pluginData: structuredClone(record),
|
|
259
276
|
childIds: []
|
|
260
277
|
});
|
|
261
278
|
copiedIds.set(source.id, node.id);
|
|
262
|
-
|
|
279
|
+
pastedIds.add(node.id);
|
|
280
|
+
for (const child of children) createNodeTree(child, node.id, originDocumentId);
|
|
263
281
|
return node.id;
|
|
264
282
|
};
|
|
265
283
|
const { requestedTarget, returningTo } = requestedPasteTarget(ctx, placement.sources.map((source) => source?.id ?? null), replacementTargets[0]?.parentId ?? null, !!cursorPos);
|
|
266
284
|
const pasteTarget = cycleSafeParent(ctx.graph, requestedTarget, pastedComponentIds(ctx.graph, [...nodes, ...dependencies]));
|
|
267
285
|
if (!prepareSlotEdits(ctx, [pasteTarget])) return created;
|
|
268
|
-
const
|
|
269
|
-
|
|
286
|
+
const pasteDependencies = () => {
|
|
287
|
+
const roots = [];
|
|
288
|
+
for (const dependency of dependencies) {
|
|
289
|
+
if (copiedIds.has(dependency.id)) continue;
|
|
290
|
+
roots.push(createNodeTree(dependency, ctx.state.currentPageId, options.clipboardOrigin));
|
|
291
|
+
}
|
|
292
|
+
return roots;
|
|
293
|
+
};
|
|
294
|
+
const dependencyRootIds = pasteDependencies();
|
|
270
295
|
for (const node of nodes) created.push(createNodeTree(node, pasteTarget));
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
296
|
+
const remapPasted = () => {
|
|
297
|
+
for (const id of pastedIds) {
|
|
298
|
+
const node = ctx.graph.getNode(id);
|
|
299
|
+
if (!node) continue;
|
|
300
|
+
const componentId = node.componentId ? copiedIds.get(node.componentId) : void 0;
|
|
301
|
+
const owned = ownInstanceOverrides(node);
|
|
302
|
+
const instanceOverrides = {
|
|
303
|
+
self: owned.self,
|
|
304
|
+
descendants: new Map([...owned.descendants].map(([target, fields]) => [copiedIds.get(target) ?? target, fields]))
|
|
305
|
+
};
|
|
306
|
+
ctx.graph.updateNode(id, {
|
|
307
|
+
componentId: componentId ?? node.componentId,
|
|
308
|
+
instanceOverrides
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
remapPasted();
|
|
284
313
|
keepPastedBoundPaints(ctx.graph, copiedIds, applied);
|
|
285
314
|
if (options.resolveBindings) {
|
|
286
315
|
const subtrees = [...dependencyRootIds, ...created];
|