@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
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import * as v from 'valibot'
|
|
2
|
+
|
|
3
|
+
import type { ColorProfile, SceneGraph, SceneNode, ShadowEffect } from '@pairdraw/scene-graph'
|
|
4
|
+
import { colorToDocumentCSS } from '@pairdraw/scene-graph/color'
|
|
5
|
+
import type { Color } from '@pairdraw/scene-graph/primitives'
|
|
6
|
+
|
|
7
|
+
import { defineTool, nodeIdsField, toolNumber } from '#core/tools/schema'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A subtree as CSS-shaped lines: one line per node, lengths in px, colours in the document's
|
|
11
|
+
* profile with the token that binds them in `var(--name, …)` form: hex in an sRGB document,
|
|
12
|
+
* `color(display-p3 …)` in a Display P3 one. This is the read side of the CSS shorthand the
|
|
13
|
+
* setters accept, so a value read here can be written back unchanged.
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_MAX_BYTES = 6000
|
|
16
|
+
export const HARD_MAX_BYTES = 20_000
|
|
17
|
+
|
|
18
|
+
const AXIS_JUSTIFY: Record<string, string> = {
|
|
19
|
+
CENTER: 'center',
|
|
20
|
+
MAX: 'end',
|
|
21
|
+
SPACE_BETWEEN: 'space-between',
|
|
22
|
+
SPACE_AROUND: 'space-around'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const AXIS_ITEMS: Record<string, string> = {
|
|
26
|
+
CENTER: 'center',
|
|
27
|
+
MAX: 'end',
|
|
28
|
+
STRETCH: 'stretch',
|
|
29
|
+
BASELINE: 'baseline'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A length as CSS writes it: whole px where it is whole, up to two decimals otherwise. */
|
|
33
|
+
function px(value: number): string {
|
|
34
|
+
return `${Math.round(value * 100) / 100}px`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The radius line, read the way `shape-details` reads corners: the per-corner fields while
|
|
39
|
+
* `independentCorners` is set (the uniform field is stale then), four values in CSS order when
|
|
40
|
+
* they differ, one otherwise. The four values write back through `set_radius`'s shorthand.
|
|
41
|
+
*/
|
|
42
|
+
function radiusOf(node: SceneNode): string | null {
|
|
43
|
+
if (node.independentCorners) {
|
|
44
|
+
const corners = [
|
|
45
|
+
node.topLeftRadius,
|
|
46
|
+
node.topRightRadius,
|
|
47
|
+
node.bottomRightRadius,
|
|
48
|
+
node.bottomLeftRadius
|
|
49
|
+
]
|
|
50
|
+
if (corners.every((value) => value === corners[0])) {
|
|
51
|
+
return corners[0] > 0 ? px(corners[0]) : null
|
|
52
|
+
}
|
|
53
|
+
return corners.map((value) => (value === 0 ? '0' : px(value))).join(' ')
|
|
54
|
+
}
|
|
55
|
+
return node.cornerRadius > 0 ? px(node.cornerRadius) : null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function box(value: number): string {
|
|
59
|
+
return String(Math.round(value))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** UTF-8 bytes without a Node Buffer, so the tool runs in the app as well as headless. */
|
|
63
|
+
function utf8Length(text: string): number {
|
|
64
|
+
let bytes = 0
|
|
65
|
+
for (let index = 0; index < text.length; index++) {
|
|
66
|
+
const code = text.charCodeAt(index)
|
|
67
|
+
if (code < 0x80) bytes += 1
|
|
68
|
+
else if (code < 0x800) bytes += 2
|
|
69
|
+
else if (code < 0xd800 || code >= 0xe000) bytes += 3
|
|
70
|
+
else bytes += 4
|
|
71
|
+
}
|
|
72
|
+
return bytes
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function boundName(graph: SceneGraph, node: SceneNode, field: string): string | null {
|
|
76
|
+
const variableId = node.boundVariables[field]
|
|
77
|
+
if (!variableId) return null
|
|
78
|
+
return graph.variables.get(variableId)?.name ?? null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A stored colour as the shorthand writes it: `#RRGGBB` in an sRGB document, `color(display-p3 …)`
|
|
83
|
+
* in a Display P3 one, where hex would name a different colour. The shorthand carries no alpha, as
|
|
84
|
+
* it never has, so the paint's opacity is left to `opacity`.
|
|
85
|
+
*/
|
|
86
|
+
function cssColor(color: Color, profile: ColorProfile): string {
|
|
87
|
+
return colorToDocumentCSS({ ...color, a: 1 }, profile)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A colour in the document's profile, or `var(--token, …)` when a variable paints it. */
|
|
91
|
+
function paintOf(node: SceneNode, graph: SceneGraph, field: string, paint: string): string {
|
|
92
|
+
const name = boundName(graph, node, field)
|
|
93
|
+
return name ? `var(--${name}, ${paint})` : paint
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function background(node: SceneNode, graph: SceneGraph): string | null {
|
|
97
|
+
const index = node.fills.findIndex((candidate) => candidate.type === 'SOLID' && candidate.visible)
|
|
98
|
+
const solid = index === -1 ? undefined : node.fills[index]
|
|
99
|
+
if (solid) {
|
|
100
|
+
const paint = cssColor(solid.color, graph.documentColorSpace)
|
|
101
|
+
return paintOf(node, graph, `fills/${index}/color`, paint)
|
|
102
|
+
}
|
|
103
|
+
const otherIndex = node.fills.findIndex((candidate) => candidate.visible)
|
|
104
|
+
const other = otherIndex === -1 ? undefined : node.fills[otherIndex]
|
|
105
|
+
if (!other) return null
|
|
106
|
+
return other.type.startsWith('GRADIENT') ? 'gradient' : 'image'
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function border(node: SceneNode, graph: SceneGraph): string | null {
|
|
110
|
+
const index = node.strokes.findIndex((candidate) => candidate.visible)
|
|
111
|
+
const stroke = index === -1 ? undefined : node.strokes[index]
|
|
112
|
+
if (!stroke) return null
|
|
113
|
+
const paint = cssColor(stroke.color, graph.documentColorSpace)
|
|
114
|
+
return `${px(stroke.weight)} ${paintOf(node, graph, `strokes/${index}/color`, paint)}`
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Padding in CSS order, compressed to the fewest values that say the same thing. */
|
|
118
|
+
function padding(node: SceneNode): string | null {
|
|
119
|
+
const top = node.paddingTop
|
|
120
|
+
const right = node.paddingRight
|
|
121
|
+
const bottom = node.paddingBottom
|
|
122
|
+
const left = node.paddingLeft
|
|
123
|
+
if (top === 0 && right === 0 && bottom === 0 && left === 0) return null
|
|
124
|
+
if (top === right && right === bottom && bottom === left) return px(top)
|
|
125
|
+
if (top === bottom && right === left) return `${px(top)} ${px(right)}`
|
|
126
|
+
return `${px(top)} ${px(right)} ${px(bottom)} ${px(left)}`
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function shadowOf(prefix: string, effect: ShadowEffect, profile: ColorProfile): string {
|
|
130
|
+
return `${prefix}:${px(effect.offset.x)} ${px(effect.offset.y)} ${px(effect.radius)} ${cssColor(effect.color, profile)}`
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function effects(node: SceneNode, profile: ColorProfile): string[] {
|
|
134
|
+
const out: string[] = []
|
|
135
|
+
for (const effect of node.effects) {
|
|
136
|
+
if (!effect.visible) continue
|
|
137
|
+
if (effect.type === 'DROP_SHADOW') out.push(shadowOf('shadow', effect, profile))
|
|
138
|
+
else if (effect.type === 'INNER_SHADOW') out.push(shadowOf('inner-shadow', effect, profile))
|
|
139
|
+
else if (effect.type === 'LAYER_BLUR' || effect.type === 'FOREGROUND_BLUR')
|
|
140
|
+
out.push(`blur:${px(effect.radius)}`)
|
|
141
|
+
else out.push('backdrop-blur')
|
|
142
|
+
}
|
|
143
|
+
return out
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function layoutDecls(node: SceneNode): string[] {
|
|
147
|
+
if (node.layoutMode === 'NONE') return []
|
|
148
|
+
const out = [node.layoutMode === 'HORIZONTAL' ? 'flex:row' : 'flex:column']
|
|
149
|
+
if (node.itemSpacing > 0) {
|
|
150
|
+
out.push(
|
|
151
|
+
node.layoutWrap === 'WRAP' && node.counterAxisSpacing > 0
|
|
152
|
+
? `gap:${px(node.itemSpacing)} ${px(node.counterAxisSpacing)}`
|
|
153
|
+
: `gap:${px(node.itemSpacing)}`
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
const paddingValue = padding(node)
|
|
157
|
+
if (paddingValue) out.push(`padding:${paddingValue}`)
|
|
158
|
+
const justify = AXIS_JUSTIFY[node.primaryAxisAlign]
|
|
159
|
+
if (justify) out.push(`justify:${justify}`)
|
|
160
|
+
const items = AXIS_ITEMS[node.counterAxisAlign]
|
|
161
|
+
if (items) out.push(`items:${items}`)
|
|
162
|
+
if (node.layoutWrap === 'WRAP') out.push('wrap')
|
|
163
|
+
if (node.primaryAxisSizing === 'HUG') out.push('hug:main')
|
|
164
|
+
if (node.counterAxisSizing === 'HUG') out.push('hug:cross')
|
|
165
|
+
return out
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function boxDecls(node: SceneNode, graph: SceneGraph): string[] {
|
|
169
|
+
const out: string[] = []
|
|
170
|
+
if (node.layoutAlignSelf === 'STRETCH') out.push('stretch')
|
|
171
|
+
if (node.layoutGrow > 0) out.push(`grow:${Math.round(node.layoutGrow * 100) / 100}`)
|
|
172
|
+
const bg = background(node, graph)
|
|
173
|
+
if (bg) out.push(`bg:${bg}`)
|
|
174
|
+
const stroke = border(node, graph)
|
|
175
|
+
if (stroke) out.push(`border:${stroke}`)
|
|
176
|
+
const radius = radiusOf(node)
|
|
177
|
+
if (radius) out.push(`radius:${radius}`)
|
|
178
|
+
if (node.minWidth !== null) out.push(`min-w:${px(node.minWidth)}`)
|
|
179
|
+
if (node.maxWidth !== null) out.push(`max-w:${px(node.maxWidth)}`)
|
|
180
|
+
if (node.minHeight !== null) out.push(`min-h:${px(node.minHeight)}`)
|
|
181
|
+
if (node.maxHeight !== null) out.push(`max-h:${px(node.maxHeight)}`)
|
|
182
|
+
out.push(...effects(node, graph.documentColorSpace))
|
|
183
|
+
if (node.opacity !== 1) out.push(`opacity:${Math.round(node.opacity * 100) / 100}`)
|
|
184
|
+
if (node.clipsContent) out.push('clip')
|
|
185
|
+
return out
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function lineHeightOf(node: SceneNode): string {
|
|
189
|
+
const lineHeight = node.lineHeight
|
|
190
|
+
if (!lineHeight) return 'auto'
|
|
191
|
+
return lineHeight.unit === 'PERCENT'
|
|
192
|
+
? `${Math.round(lineHeight.value * 100) / 100}%`
|
|
193
|
+
: px(lineHeight.value)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function textDecls(node: SceneNode, graph: SceneGraph): string[] {
|
|
197
|
+
const out = [
|
|
198
|
+
`font:${node.fontWeight} ${px(node.fontSize)}/${lineHeightOf(node)} ${node.fontFamily}`
|
|
199
|
+
]
|
|
200
|
+
const bg = background(node, graph)
|
|
201
|
+
if (bg) out.push(`color:${bg}`)
|
|
202
|
+
if (node.textAlignHorizontal !== 'LEFT') {
|
|
203
|
+
out.push(`text-align:${node.textAlignHorizontal.toLowerCase()}`)
|
|
204
|
+
}
|
|
205
|
+
if (node.maxLines !== null && node.maxLines > 0) out.push(`max-lines:${node.maxLines}`)
|
|
206
|
+
if (node.textAutoResize === 'NONE') out.push('fixed')
|
|
207
|
+
return out
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function lineOf(node: SceneNode, graph: SceneGraph): string {
|
|
211
|
+
const decls =
|
|
212
|
+
node.type === 'TEXT' ? textDecls(node, graph) : [...layoutDecls(node), ...boxDecls(node, graph)]
|
|
213
|
+
const label =
|
|
214
|
+
node.type === 'TEXT'
|
|
215
|
+
? `"${node.text.slice(0, 40).replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('\n', '\\n')}"`
|
|
216
|
+
: node.name
|
|
217
|
+
const body = decls.length > 0 ? ` {${decls.join(';')}}` : ''
|
|
218
|
+
return `${label}#${node.id} ${box(node.width)}×${box(node.height)}${body}`
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
interface Budget {
|
|
222
|
+
bytes: number
|
|
223
|
+
limit: number
|
|
224
|
+
truncated: boolean
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** What a cut-off walk left out, counted through the same visible-node rule as the lines. */
|
|
228
|
+
function countVisible(graph: SceneGraph, nodeId: string): number {
|
|
229
|
+
const node = graph.getNode(nodeId)
|
|
230
|
+
if (!node || !node.visible) return 0
|
|
231
|
+
let count = 1
|
|
232
|
+
for (const childId of node.childIds) count += countVisible(graph, childId)
|
|
233
|
+
return count
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function truncationTail(omitted: number): string {
|
|
237
|
+
return `… +${omitted} node${omitted === 1 ? '' : 's'} (raise max_bytes or narrow with depth)`
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Depth-first lines until the budget is spent. A line that does not fit ends the walk; the kept
|
|
242
|
+
* lines never exceed the limit on their own, so the reply can always stay within `max_bytes`.
|
|
243
|
+
*/
|
|
244
|
+
function collect(
|
|
245
|
+
graph: SceneGraph,
|
|
246
|
+
nodeId: string,
|
|
247
|
+
depth: number,
|
|
248
|
+
indent: string,
|
|
249
|
+
lines: string[],
|
|
250
|
+
budget: Budget
|
|
251
|
+
): void {
|
|
252
|
+
const node = graph.getNode(nodeId)
|
|
253
|
+
if (!node || !node.visible) return
|
|
254
|
+
if (budget.truncated) return
|
|
255
|
+
const line = `${indent}${lineOf(node, graph)}`
|
|
256
|
+
const fits = budget.bytes + utf8Length(line) + 1 <= budget.limit
|
|
257
|
+
if (!fits) {
|
|
258
|
+
budget.truncated = true
|
|
259
|
+
return
|
|
260
|
+
}
|
|
261
|
+
budget.bytes += utf8Length(line) + 1
|
|
262
|
+
lines.push(line)
|
|
263
|
+
if (depth > 0) {
|
|
264
|
+
for (const childId of node.childIds) {
|
|
265
|
+
collect(graph, childId, depth - 1, `${indent} `, lines, budget)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* A subtree within `maxBytes`. The truncation tail is charged to the same budget: trailing lines
|
|
272
|
+
* give way first, then the tail is left out when only the kept lines fit. A block whose first line
|
|
273
|
+
* does not fit returns no CSS at all; the reply's `truncated`/`omitted` fields report the cut.
|
|
274
|
+
*/
|
|
275
|
+
function blockFor(
|
|
276
|
+
graph: SceneGraph,
|
|
277
|
+
nodeId: string,
|
|
278
|
+
depth: number,
|
|
279
|
+
maxBytes: number
|
|
280
|
+
): { css: string; truncated?: true; omitted?: number } {
|
|
281
|
+
const lines: string[] = []
|
|
282
|
+
const budget: Budget = { bytes: 0, limit: maxBytes, truncated: false }
|
|
283
|
+
collect(graph, nodeId, depth, '', lines, budget)
|
|
284
|
+
if (!budget.truncated) return { css: lines.join('\n') }
|
|
285
|
+
// Every visible node either has a line or is left out, so the omitted count follows from the
|
|
286
|
+
// node total. Each dropped line's byte count includes the newline collect charged for it.
|
|
287
|
+
let omitted = countVisible(graph, nodeId) - lines.length
|
|
288
|
+
while (
|
|
289
|
+
lines.length > 1 &&
|
|
290
|
+
budget.bytes + 1 + utf8Length(truncationTail(omitted)) > budget.limit
|
|
291
|
+
) {
|
|
292
|
+
const last = lines.pop()
|
|
293
|
+
if (last === undefined) break
|
|
294
|
+
budget.bytes -= utf8Length(last) + 1
|
|
295
|
+
omitted = countVisible(graph, nodeId) - lines.length
|
|
296
|
+
}
|
|
297
|
+
if (lines.length === 0) {
|
|
298
|
+
return { css: '', truncated: true, omitted: countVisible(graph, nodeId) }
|
|
299
|
+
}
|
|
300
|
+
const head = lines.join('\n')
|
|
301
|
+
if (budget.bytes + 1 + utf8Length(truncationTail(omitted)) > budget.limit) {
|
|
302
|
+
return { css: head, truncated: true, omitted }
|
|
303
|
+
}
|
|
304
|
+
return { css: `${head}\n${truncationTail(omitted)}`, truncated: true, omitted }
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export const getCSS = defineTool({
|
|
308
|
+
name: 'get_css',
|
|
309
|
+
description:
|
|
310
|
+
'Read a node subtree as compact CSS-like lines: `Name#id W×H {flex:row;gap:12px;padding:16px 24px;bg:var(--color/brand, #4F46E5);radius:8px}`. ' +
|
|
311
|
+
'Lengths are px; short names: flex (implies display:flex), gap, padding, justify, items, wrap, hug, stretch, grow, bg, border, radius, min/max-w/h, shadow, blur, opacity, clip; text: `font:600 14px/20px Inter`, color, text-align, max-lines. ' +
|
|
312
|
+
"Colours follow the document's profile, as get_jsx writes them: `#RRGGBB` in an sRGB document, `color(display-p3 r g b)` in a Display P3 one, and either inside the `var()` fallback. " +
|
|
313
|
+
'Use it for geometry and style; describe gives roles and design issues. The setters accept the same shorthand (padding/gap/radius strings, `var(--token)` colours).',
|
|
314
|
+
execution: { kind: 'sync', mutation: 'none' },
|
|
315
|
+
input: v.strictObject({
|
|
316
|
+
id: v.optional(v.pipe(v.string(), v.description('Node ID (single node)'))),
|
|
317
|
+
ids: nodeIdsField('Node IDs (several nodes in one call)'),
|
|
318
|
+
depth: v.optional(
|
|
319
|
+
toolNumber(
|
|
320
|
+
v.pipe(
|
|
321
|
+
v.number(),
|
|
322
|
+
v.description('Child levels to include (default: as many as the budget holds)')
|
|
323
|
+
)
|
|
324
|
+
)
|
|
325
|
+
),
|
|
326
|
+
max_bytes: v.optional(
|
|
327
|
+
toolNumber(
|
|
328
|
+
v.pipe(v.number(), v.description('Byte budget for the reply (default 6000, max 20000)'))
|
|
329
|
+
)
|
|
330
|
+
)
|
|
331
|
+
}),
|
|
332
|
+
execute: (figma, args) => {
|
|
333
|
+
const maxBytes = Math.min(args.max_bytes ?? DEFAULT_MAX_BYTES, HARD_MAX_BYTES)
|
|
334
|
+
const depth = args.depth ?? 100
|
|
335
|
+
|
|
336
|
+
if (args.ids && Array.isArray(args.ids)) {
|
|
337
|
+
const blocks: string[] = []
|
|
338
|
+
let omitted = 0
|
|
339
|
+
let truncated = false
|
|
340
|
+
let used = 0
|
|
341
|
+
for (const nodeId of args.ids) {
|
|
342
|
+
if (!figma.graph.getNode(nodeId)) return { error: `Node "${nodeId}" not found` }
|
|
343
|
+
const separator = blocks.length === 0 ? 0 : 1
|
|
344
|
+
const block = blockFor(figma.graph, nodeId, depth, maxBytes - used - separator)
|
|
345
|
+
if (block.css === '') {
|
|
346
|
+
omitted += block.omitted ?? 0
|
|
347
|
+
truncated = truncated || block.truncated === true
|
|
348
|
+
continue
|
|
349
|
+
}
|
|
350
|
+
blocks.push(block.css)
|
|
351
|
+
used += utf8Length(block.css) + separator
|
|
352
|
+
omitted += block.omitted ?? 0
|
|
353
|
+
truncated = truncated || block.truncated === true
|
|
354
|
+
}
|
|
355
|
+
const css = blocks.join('\n')
|
|
356
|
+
if (!truncated) return { ids: args.ids, css }
|
|
357
|
+
return { ids: args.ids, css, truncated: true, omitted }
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (!args.id) return { error: 'Provide id (string) or ids (string[])' }
|
|
361
|
+
if (!figma.graph.getNode(args.id)) return { error: `Node "${args.id}" not found` }
|
|
362
|
+
const block = blockFor(figma.graph, args.id, depth, maxBytes)
|
|
363
|
+
return { id: args.id, ...block }
|
|
364
|
+
}
|
|
365
|
+
})
|
|
@@ -7,8 +7,9 @@ export const getReactions = defineTool({
|
|
|
7
7
|
|
|
8
8
|
description:
|
|
9
9
|
"Get the prototype connections on a layer, in Figma's plugin shape: each trigger and its " +
|
|
10
|
-
'actions, with a NODE action naming the destination frame.
|
|
11
|
-
'
|
|
10
|
+
'actions, with a NODE action naming the destination frame or variant. A Change to authored ' +
|
|
11
|
+
'by variant properties reads back as the destination variant id. Empty when the layer ' +
|
|
12
|
+
'connects to nothing.',
|
|
12
13
|
execution: { kind: 'sync', mutation: 'none' },
|
|
13
14
|
input: v.strictObject({
|
|
14
15
|
id: nodeIdInputSchema
|
package/src/tools/read/space.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { getAxisAlignedBoundsInParent } from '@pairdraw/scene-graph/coordinate'
|
|
|
5
5
|
import { computeBounds } from '@pairdraw/scene-graph/geometry'
|
|
6
6
|
import type { Rect } from '@pairdraw/scene-graph/primitives'
|
|
7
7
|
|
|
8
|
-
import { flushPendingLayout } from '#core/figma-api'
|
|
9
8
|
import { findPageId } from '#core/io/subgraph'
|
|
10
9
|
import { defineTool, toolNumber } from '#core/tools/schema'
|
|
11
10
|
|
|
@@ -176,7 +175,6 @@ export const findEmptySpaceTool = defineTool({
|
|
|
176
175
|
if (args.near_id && nearParentId !== parentId) {
|
|
177
176
|
return { error: `Node "${args.near_id}" is not a child of "${parentId}"` }
|
|
178
177
|
}
|
|
179
|
-
flushPendingLayout(graph)
|
|
180
178
|
const obstacles = childBoxes(graph, parentId)
|
|
181
179
|
const near = args.near_id ? graph.getNode(args.near_id) : undefined
|
|
182
180
|
let anchor = obstacles.length > 0 ? computeBounds(obstacles) : null
|
package/src/tools/read.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getComponents } from './read/components'
|
|
2
|
+
export { getCSS } from './read/css'
|
|
2
3
|
export { insertLibraryComponent, listLibraries } from './read/libraries'
|
|
3
4
|
export { getFontStatus, listAvailableFonts, listFonts } from './read/fonts'
|
|
4
5
|
export { diffJSX, getJSX } from './read/jsx'
|
|
@@ -13,14 +13,14 @@ import {
|
|
|
13
13
|
setTextProperties,
|
|
14
14
|
updateNode
|
|
15
15
|
} from '#core/tools/modify'
|
|
16
|
-
import { diffJSX, findNodes, getJSX, getNode, getSelection } from '#core/tools/read'
|
|
16
|
+
import { diffJSX, findNodes, getCSS, getJSX, getNode, getSelection } from '#core/tools/read'
|
|
17
17
|
import type { ToolDef } from '#core/tools/schema'
|
|
18
18
|
import { stockPhoto } from '#core/tools/stock-photo'
|
|
19
19
|
import { batchUpdate, deleteNode, nodeResize, reparentNode } from '#core/tools/structure'
|
|
20
20
|
import { viewportZoomToFit } from '#core/tools/vector'
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Core tools registered by default in AI chat (
|
|
23
|
+
* Core tools registered by default in AI chat (28 tools, ~5K schema tokens).
|
|
24
24
|
* Covers 90%+ of design sessions: render, describe, modify, structure, and diff checks.
|
|
25
25
|
*/
|
|
26
26
|
export const CORE_TOOLS: ToolDef[] = [
|
|
@@ -29,6 +29,7 @@ export const CORE_TOOLS: ToolDef[] = [
|
|
|
29
29
|
getNode,
|
|
30
30
|
findNodes,
|
|
31
31
|
getJSX,
|
|
32
|
+
getCSS,
|
|
32
33
|
// Create
|
|
33
34
|
render,
|
|
34
35
|
// Modify
|
package/src/tools/schema.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import * as v from 'valibot'
|
|
9
9
|
|
|
10
|
-
import type { SceneNode } from '@pairdraw/scene-graph'
|
|
10
|
+
import type { DocumentColorSpace, SceneNode } from '@pairdraw/scene-graph'
|
|
11
11
|
import { tryParseColor } from '@pairdraw/scene-graph/color'
|
|
12
12
|
import type { Color } from '@pairdraw/scene-graph/primitives'
|
|
13
13
|
|
|
@@ -328,9 +328,12 @@ export function nodeSummary(node: FigmaNodeProxy): { id: string; name: string; t
|
|
|
328
328
|
* used to paint black and report success. Read through `tryParseColor`, since a published schema
|
|
329
329
|
* cannot express what the parser accepts.
|
|
330
330
|
*/
|
|
331
|
-
export function parseToolColor(
|
|
331
|
+
export function parseToolColor(
|
|
332
|
+
value: string,
|
|
333
|
+
profile: DocumentColorSpace = 'srgb'
|
|
334
|
+
): Color | { error: string } {
|
|
332
335
|
return (
|
|
333
|
-
tryParseColor(value) ?? {
|
|
336
|
+
tryParseColor(value, profile) ?? {
|
|
334
337
|
error: `"${value}" is not a color; use a hex value, a color name, or a color function`
|
|
335
338
|
}
|
|
336
339
|
)
|
|
@@ -341,10 +344,11 @@ export function parseToolColor(value: string): Color | { error: string } {
|
|
|
341
344
|
* same refusal `parseToolColor` gives, so each tool does not repeat that check.
|
|
342
345
|
*/
|
|
343
346
|
export function parseOptionalToolColor(
|
|
344
|
-
value: string | undefined
|
|
347
|
+
value: string | undefined,
|
|
348
|
+
profile: DocumentColorSpace = 'srgb'
|
|
345
349
|
): { color: Color | undefined } | { error: string } {
|
|
346
350
|
if (value === undefined) return { color: undefined }
|
|
347
|
-
const parsed = parseToolColor(value)
|
|
351
|
+
const parsed = parseToolColor(value, profile)
|
|
348
352
|
if ('error' in parsed) return parsed
|
|
349
353
|
return { color: parsed }
|
|
350
354
|
}
|
|
@@ -382,3 +386,8 @@ export function toolNumber(schema: v.GenericSchema<number, number> = v.number())
|
|
|
382
386
|
)
|
|
383
387
|
])
|
|
384
388
|
}
|
|
389
|
+
|
|
390
|
+
/** `ids`: several node IDs in one call; the description names what they point at. */
|
|
391
|
+
export function nodeIdsField(description: string) {
|
|
392
|
+
return v.optional(v.pipe(v.array(v.string()), v.minLength(1), v.description(description)))
|
|
393
|
+
}
|
package/src/tools/script/host.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { underlyingGraph } from '#core/figma-api/graph-ref'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* What the `script` tool needs from the host: the sandbox and the node that carries its program
|
|
3
5
|
* live in the app, so the app registers the runner for the documents it shows. A headless host
|
|
@@ -21,12 +23,13 @@ const hosts = new WeakMap<object, ScriptToolHost>()
|
|
|
21
23
|
|
|
22
24
|
/** Lets the `script` tool run for the documents of `owner`, a document's graph. */
|
|
23
25
|
export function registerScriptToolHost(owner: object, host: ScriptToolHost): () => void {
|
|
24
|
-
|
|
26
|
+
const target = underlyingGraph(owner)
|
|
27
|
+
hosts.set(target, host)
|
|
25
28
|
return () => {
|
|
26
|
-
if (hosts.get(
|
|
29
|
+
if (hosts.get(target) === host) hosts.delete(target)
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
export function getScriptToolHost(owner: object): ScriptToolHost | undefined {
|
|
31
|
-
return hosts.get(owner)
|
|
34
|
+
return hosts.get(underlyingGraph(owner))
|
|
32
35
|
}
|
|
@@ -8,7 +8,7 @@ export const listCollections = defineTool({
|
|
|
8
8
|
execution: { kind: 'sync', mutation: 'none' },
|
|
9
9
|
input: v.strictObject({}),
|
|
10
10
|
execute: (figma) => {
|
|
11
|
-
const collections =
|
|
11
|
+
const collections = figma.graph.getLiveCollections()
|
|
12
12
|
return { count: collections.length, collections }
|
|
13
13
|
}
|
|
14
14
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as v from 'valibot'
|
|
2
2
|
|
|
3
|
-
import type { VariableType } from '@pairdraw/scene-graph'
|
|
3
|
+
import type { DocumentColorSpace, VariableType } from '@pairdraw/scene-graph'
|
|
4
4
|
import { tryParseColor } from '@pairdraw/scene-graph/color'
|
|
5
5
|
import type { Color } from '@pairdraw/scene-graph/primitives'
|
|
6
6
|
|
|
@@ -14,8 +14,12 @@ function figmaValue(value: ToolValue): FigmaVariableValue {
|
|
|
14
14
|
|
|
15
15
|
type ToolValue = Color | number | string | boolean
|
|
16
16
|
|
|
17
|
-
function parseVariableValue(
|
|
18
|
-
|
|
17
|
+
function parseVariableValue(
|
|
18
|
+
type: VariableType,
|
|
19
|
+
value: string,
|
|
20
|
+
profile: DocumentColorSpace
|
|
21
|
+
): ToolValue | null {
|
|
22
|
+
if (type === 'COLOR') return tryParseColor(value, profile)
|
|
19
23
|
if (type === 'FLOAT') return Number(value)
|
|
20
24
|
if (type === 'BOOLEAN') return value === 'true'
|
|
21
25
|
return value
|
|
@@ -40,7 +44,10 @@ export const createVariable = defineTool({
|
|
|
40
44
|
execute: (figma, args) => {
|
|
41
45
|
const type = args.type
|
|
42
46
|
// The value is checked first, so a value the variable cannot hold creates nothing.
|
|
43
|
-
const value =
|
|
47
|
+
const value =
|
|
48
|
+
args.value === undefined
|
|
49
|
+
? undefined
|
|
50
|
+
: parseVariableValue(type, args.value, figma.graph.documentColorSpace)
|
|
44
51
|
if (value === null) return { error: `"${args.value}" is not a ${type} value` }
|
|
45
52
|
if (typeof value === 'number' && !Number.isFinite(value))
|
|
46
53
|
return { error: `"${args.value}" is not a number` }
|
|
@@ -66,7 +73,11 @@ export const setVariable = defineTool({
|
|
|
66
73
|
execute: (figma, args) => {
|
|
67
74
|
const variable = figma.variables.getVariableById(args.id)
|
|
68
75
|
if (!variable) return { error: `Variable "${args.id}" not found` }
|
|
69
|
-
const parsedValue = parseVariableValue(
|
|
76
|
+
const parsedValue = parseVariableValue(
|
|
77
|
+
variable.resolvedType,
|
|
78
|
+
args.value,
|
|
79
|
+
figma.graph.documentColorSpace
|
|
80
|
+
)
|
|
70
81
|
if (parsedValue === null)
|
|
71
82
|
return { error: `"${args.value}" is not a ${variable.resolvedType} value` }
|
|
72
83
|
variable.setValueForMode(args.mode, figmaValue(parsedValue))
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as v from 'valibot'
|
|
2
2
|
|
|
3
|
+
import { underlyingGraph } from '#core/figma-api/graph-ref'
|
|
3
4
|
import { defineTool, nodeIdInputSchema, nodeNotFound, toolFailure } from '#core/tools/schema'
|
|
4
5
|
import {
|
|
5
6
|
createVectorFrameBeside,
|
|
@@ -25,14 +26,15 @@ const vectorizers = new WeakMap<object, ImageVectorizer>()
|
|
|
25
26
|
|
|
26
27
|
/** Lets `vectorize_image` run for the documents of `owner`, a document's graph. */
|
|
27
28
|
export function registerImageVectorizer(owner: object, vectorizer: ImageVectorizer): () => void {
|
|
28
|
-
|
|
29
|
+
const target = underlyingGraph(owner)
|
|
30
|
+
vectorizers.set(target, vectorizer)
|
|
29
31
|
return () => {
|
|
30
|
-
if (vectorizers.get(
|
|
32
|
+
if (vectorizers.get(target) === vectorizer) vectorizers.delete(target)
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
export function getImageVectorizer(owner: object): ImageVectorizer | undefined {
|
|
35
|
-
return vectorizers.get(owner)
|
|
37
|
+
return vectorizers.get(underlyingGraph(owner))
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export const vectorizeImage = defineTool({
|
|
@@ -73,7 +75,11 @@ export const vectorizeImage = defineTool({
|
|
|
73
75
|
if (!current || vectorizableImageFill(current)?.imageHash !== fill.imageHash) {
|
|
74
76
|
return { error: `The image of "${node.name}" changed before vectorizing finished` }
|
|
75
77
|
}
|
|
76
|
-
const vectorized = svgToVectorPaths(
|
|
78
|
+
const vectorized = svgToVectorPaths(
|
|
79
|
+
svg,
|
|
80
|
+
{ width: current.width, height: current.height },
|
|
81
|
+
{ profile: graph.documentColorSpace }
|
|
82
|
+
)
|
|
77
83
|
if (!vectorized?.paths.length) return { error: 'The vectorize service returned no paths' }
|
|
78
84
|
const frameId = createVectorFrameBeside(graph, id, vectorized)
|
|
79
85
|
const frame = frameId ? graph.getNode(frameId) : undefined
|
package/src/tools/video-host.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { underlyingGraph } from '#core/figma-api/graph-ref'
|
|
1
2
|
import type { VideoHostEncoder } from '#core/io/formats/video'
|
|
2
3
|
|
|
3
4
|
const encoders = new WeakMap<object, VideoHostEncoder>()
|
|
@@ -7,12 +8,13 @@ const encoders = new WeakMap<object, VideoHostEncoder>()
|
|
|
7
8
|
* WebCodecs cannot encode in that host, as the CLI does with ffmpeg. The app needs none.
|
|
8
9
|
*/
|
|
9
10
|
export function registerVideoEncoder(owner: object, encoder: VideoHostEncoder): () => void {
|
|
10
|
-
|
|
11
|
+
const target = underlyingGraph(owner)
|
|
12
|
+
encoders.set(target, encoder)
|
|
11
13
|
return () => {
|
|
12
|
-
if (encoders.get(
|
|
14
|
+
if (encoders.get(target) === encoder) encoders.delete(target)
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export function getVideoEncoder(owner: object): VideoHostEncoder | undefined {
|
|
17
|
-
return encoders.get(owner)
|
|
19
|
+
return encoders.get(underlyingGraph(owner))
|
|
18
20
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* normalize into each node's bounding box and build the transform in Figma's convention
|
|
10
10
|
* (see geometry/gradient).
|
|
11
11
|
*/
|
|
12
|
-
import type { Fill, GradientStop } from '@pairdraw/scene-graph'
|
|
12
|
+
import type { DocumentColorSpace, Fill, GradientStop } from '@pairdraw/scene-graph'
|
|
13
13
|
import { parseColor } from '@pairdraw/scene-graph/color'
|
|
14
14
|
import {
|
|
15
15
|
ellipticalGradientTransform,
|
|
@@ -59,12 +59,12 @@ function coord(value: string | null, fallback: number): number {
|
|
|
59
59
|
return Number.isFinite(n) ? n : fallback
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
function readStops(gradient: SVGElementLike): RawStop[] {
|
|
62
|
+
function readStops(gradient: SVGElementLike, profile: DocumentColorSpace): RawStop[] {
|
|
63
63
|
const stops: RawStop[] = []
|
|
64
64
|
const stopEls = Array.from(gradient.getElementsByTagName('stop'))
|
|
65
65
|
for (const [i, stop] of stopEls.entries()) {
|
|
66
66
|
const offset = coord(stop.getAttribute('offset'), i === 0 ? 0 : 1)
|
|
67
|
-
const color = parseColor(stop.getAttribute('stop-color') ?? '#000000')
|
|
67
|
+
const color = parseColor(stop.getAttribute('stop-color') ?? '#000000', profile)
|
|
68
68
|
const opacity = stop.getAttribute('stop-opacity')
|
|
69
69
|
if (opacity != null) {
|
|
70
70
|
const a = Number.parseFloat(opacity)
|
|
@@ -80,7 +80,10 @@ function readStops(gradient: SVGElementLike): RawStop[] {
|
|
|
80
80
|
* (no hand-rolled markup parsing). Returns an empty map on parse failure so a
|
|
81
81
|
* malformed SVG simply falls back to solid fills.
|
|
82
82
|
*/
|
|
83
|
-
export function parseSVGGradients(
|
|
83
|
+
export function parseSVGGradients(
|
|
84
|
+
svg: string,
|
|
85
|
+
profile: DocumentColorSpace = 'srgb'
|
|
86
|
+
): Map<string, ParsedGradient> {
|
|
84
87
|
const map = new Map<string, ParsedGradient>()
|
|
85
88
|
const doc: SVGQueryable | null = parseSVGDocument(svg)
|
|
86
89
|
if (!doc) return map
|
|
@@ -100,7 +103,7 @@ export function parseSVGGradients(svg: string): Map<string, ParsedGradient> {
|
|
|
100
103
|
kind,
|
|
101
104
|
units,
|
|
102
105
|
transform: el.getAttribute('gradientTransform'),
|
|
103
|
-
stops: readStops(el),
|
|
106
|
+
stops: readStops(el, profile),
|
|
104
107
|
x1: coord(el.getAttribute('x1'), 0),
|
|
105
108
|
y1: coord(el.getAttribute('y1'), 0),
|
|
106
109
|
x2: coord(el.getAttribute('x2'), units === 'objectBoundingBox' ? 1 : 0),
|