@pairdraw/core 0.20.0 → 0.21.1
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/compile.d.ts +3 -1
- package/dist/canvas/shaders/compile.d.ts.map +1 -1
- package/dist/canvas/shaders/compile.js +12 -3
- package/dist/canvas/shaders/compile.js.map +1 -1
- package/dist/canvas/shaders/draw.d.ts.map +1 -1
- package/dist/canvas/shaders/draw.js +10 -3
- package/dist/canvas/shaders/draw.js.map +1 -1
- package/dist/canvas/shaders/effect.d.ts.map +1 -1
- package/dist/canvas/shaders/effect.js +8 -17
- 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/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/export.js +2 -2
- package/dist/editor/clipboard/export.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/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.d.ts +17 -2
- package/dist/io/formats/drawio/warnings.d.ts.map +1 -1
- package/dist/io/formats/drawio/warnings.js +15 -8
- 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/index.d.ts +1 -0
- package/dist/io/formats/html/index.d.ts.map +1 -1
- package/dist/io/formats/html/index.js +5 -3
- package/dist/io/formats/html/index.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.d.ts.map +1 -1
- package/dist/io/formats/pen/index.js +13 -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 +11 -4
- package/dist/io/formats.js.map +1 -1
- package/dist/io/index.d.ts +2 -2
- 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 +12 -3
- package/dist/io/types.d.ts.map +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/compile.ts +14 -3
- package/src/canvas/shaders/draw.ts +11 -4
- package/src/canvas/shaders/effect.ts +8 -19
- 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/export.ts +2 -2
- 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 +28 -9
- 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/index.ts +9 -3
- 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 +15 -4
- 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 +18 -5
- package/src/io/index.ts +1 -0
- package/src/io/subgraph.ts +4 -1
- package/src/io/types.ts +10 -0
- 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,306 @@
|
|
|
1
|
+
import { defineTool, nodeIdsField, toolNumber } from "../schema.js";
|
|
2
|
+
import { colorToDocumentCSS } from "@pairdraw/scene-graph/color";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
//#region src/tools/read/css.ts
|
|
5
|
+
/**
|
|
6
|
+
* A subtree as CSS-shaped lines: one line per node, lengths in px, colours in the document's
|
|
7
|
+
* profile with the token that binds them in `var(--name, …)` form: hex in an sRGB document,
|
|
8
|
+
* `color(display-p3 …)` in a Display P3 one. This is the read side of the CSS shorthand the
|
|
9
|
+
* setters accept, so a value read here can be written back unchanged.
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_MAX_BYTES = 6e3;
|
|
12
|
+
const HARD_MAX_BYTES = 2e4;
|
|
13
|
+
const AXIS_JUSTIFY = {
|
|
14
|
+
CENTER: "center",
|
|
15
|
+
MAX: "end",
|
|
16
|
+
SPACE_BETWEEN: "space-between",
|
|
17
|
+
SPACE_AROUND: "space-around"
|
|
18
|
+
};
|
|
19
|
+
const AXIS_ITEMS = {
|
|
20
|
+
CENTER: "center",
|
|
21
|
+
MAX: "end",
|
|
22
|
+
STRETCH: "stretch",
|
|
23
|
+
BASELINE: "baseline"
|
|
24
|
+
};
|
|
25
|
+
/** A length as CSS writes it: whole px where it is whole, up to two decimals otherwise. */
|
|
26
|
+
function px(value) {
|
|
27
|
+
return `${Math.round(value * 100) / 100}px`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The radius line, read the way `shape-details` reads corners: the per-corner fields while
|
|
31
|
+
* `independentCorners` is set (the uniform field is stale then), four values in CSS order when
|
|
32
|
+
* they differ, one otherwise. The four values write back through `set_radius`'s shorthand.
|
|
33
|
+
*/
|
|
34
|
+
function radiusOf(node) {
|
|
35
|
+
if (node.independentCorners) {
|
|
36
|
+
const corners = [
|
|
37
|
+
node.topLeftRadius,
|
|
38
|
+
node.topRightRadius,
|
|
39
|
+
node.bottomRightRadius,
|
|
40
|
+
node.bottomLeftRadius
|
|
41
|
+
];
|
|
42
|
+
if (corners.every((value) => value === corners[0])) return corners[0] > 0 ? px(corners[0]) : null;
|
|
43
|
+
return corners.map((value) => value === 0 ? "0" : px(value)).join(" ");
|
|
44
|
+
}
|
|
45
|
+
return node.cornerRadius > 0 ? px(node.cornerRadius) : null;
|
|
46
|
+
}
|
|
47
|
+
function box(value) {
|
|
48
|
+
return String(Math.round(value));
|
|
49
|
+
}
|
|
50
|
+
/** UTF-8 bytes without a Node Buffer, so the tool runs in the app as well as headless. */
|
|
51
|
+
function utf8Length(text) {
|
|
52
|
+
let bytes = 0;
|
|
53
|
+
for (let index = 0; index < text.length; index++) {
|
|
54
|
+
const code = text.charCodeAt(index);
|
|
55
|
+
if (code < 128) bytes += 1;
|
|
56
|
+
else if (code < 2048) bytes += 2;
|
|
57
|
+
else if (code < 55296 || code >= 57344) bytes += 3;
|
|
58
|
+
else bytes += 4;
|
|
59
|
+
}
|
|
60
|
+
return bytes;
|
|
61
|
+
}
|
|
62
|
+
function boundName(graph, node, field) {
|
|
63
|
+
const variableId = node.boundVariables[field];
|
|
64
|
+
if (!variableId) return null;
|
|
65
|
+
return graph.variables.get(variableId)?.name ?? null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A stored colour as the shorthand writes it: `#RRGGBB` in an sRGB document, `color(display-p3 …)`
|
|
69
|
+
* in a Display P3 one, where hex would name a different colour. The shorthand carries no alpha, as
|
|
70
|
+
* it never has, so the paint's opacity is left to `opacity`.
|
|
71
|
+
*/
|
|
72
|
+
function cssColor(color, profile) {
|
|
73
|
+
return colorToDocumentCSS({
|
|
74
|
+
...color,
|
|
75
|
+
a: 1
|
|
76
|
+
}, profile);
|
|
77
|
+
}
|
|
78
|
+
/** A colour in the document's profile, or `var(--token, …)` when a variable paints it. */
|
|
79
|
+
function paintOf(node, graph, field, paint) {
|
|
80
|
+
const name = boundName(graph, node, field);
|
|
81
|
+
return name ? `var(--${name}, ${paint})` : paint;
|
|
82
|
+
}
|
|
83
|
+
function background(node, graph) {
|
|
84
|
+
const index = node.fills.findIndex((candidate) => candidate.type === "SOLID" && candidate.visible);
|
|
85
|
+
const solid = index === -1 ? void 0 : node.fills[index];
|
|
86
|
+
if (solid) {
|
|
87
|
+
const paint = cssColor(solid.color, graph.documentColorSpace);
|
|
88
|
+
return paintOf(node, graph, `fills/${index}/color`, paint);
|
|
89
|
+
}
|
|
90
|
+
const otherIndex = node.fills.findIndex((candidate) => candidate.visible);
|
|
91
|
+
const other = otherIndex === -1 ? void 0 : node.fills[otherIndex];
|
|
92
|
+
if (!other) return null;
|
|
93
|
+
return other.type.startsWith("GRADIENT") ? "gradient" : "image";
|
|
94
|
+
}
|
|
95
|
+
function border(node, graph) {
|
|
96
|
+
const index = node.strokes.findIndex((candidate) => candidate.visible);
|
|
97
|
+
const stroke = index === -1 ? void 0 : node.strokes[index];
|
|
98
|
+
if (!stroke) return null;
|
|
99
|
+
const paint = cssColor(stroke.color, graph.documentColorSpace);
|
|
100
|
+
return `${px(stroke.weight)} ${paintOf(node, graph, `strokes/${index}/color`, paint)}`;
|
|
101
|
+
}
|
|
102
|
+
/** Padding in CSS order, compressed to the fewest values that say the same thing. */
|
|
103
|
+
function padding(node) {
|
|
104
|
+
const top = node.paddingTop;
|
|
105
|
+
const right = node.paddingRight;
|
|
106
|
+
const bottom = node.paddingBottom;
|
|
107
|
+
const left = node.paddingLeft;
|
|
108
|
+
if (top === 0 && right === 0 && bottom === 0 && left === 0) return null;
|
|
109
|
+
if (top === right && right === bottom && bottom === left) return px(top);
|
|
110
|
+
if (top === bottom && right === left) return `${px(top)} ${px(right)}`;
|
|
111
|
+
return `${px(top)} ${px(right)} ${px(bottom)} ${px(left)}`;
|
|
112
|
+
}
|
|
113
|
+
function shadowOf(prefix, effect, profile) {
|
|
114
|
+
return `${prefix}:${px(effect.offset.x)} ${px(effect.offset.y)} ${px(effect.radius)} ${cssColor(effect.color, profile)}`;
|
|
115
|
+
}
|
|
116
|
+
function effects(node, profile) {
|
|
117
|
+
const out = [];
|
|
118
|
+
for (const effect of node.effects) {
|
|
119
|
+
if (!effect.visible) continue;
|
|
120
|
+
if (effect.type === "DROP_SHADOW") out.push(shadowOf("shadow", effect, profile));
|
|
121
|
+
else if (effect.type === "INNER_SHADOW") out.push(shadowOf("inner-shadow", effect, profile));
|
|
122
|
+
else if (effect.type === "LAYER_BLUR" || effect.type === "FOREGROUND_BLUR") out.push(`blur:${px(effect.radius)}`);
|
|
123
|
+
else out.push("backdrop-blur");
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
function layoutDecls(node) {
|
|
128
|
+
if (node.layoutMode === "NONE") return [];
|
|
129
|
+
const out = [node.layoutMode === "HORIZONTAL" ? "flex:row" : "flex:column"];
|
|
130
|
+
if (node.itemSpacing > 0) out.push(node.layoutWrap === "WRAP" && node.counterAxisSpacing > 0 ? `gap:${px(node.itemSpacing)} ${px(node.counterAxisSpacing)}` : `gap:${px(node.itemSpacing)}`);
|
|
131
|
+
const paddingValue = padding(node);
|
|
132
|
+
if (paddingValue) out.push(`padding:${paddingValue}`);
|
|
133
|
+
const justify = AXIS_JUSTIFY[node.primaryAxisAlign];
|
|
134
|
+
if (justify) out.push(`justify:${justify}`);
|
|
135
|
+
const items = AXIS_ITEMS[node.counterAxisAlign];
|
|
136
|
+
if (items) out.push(`items:${items}`);
|
|
137
|
+
if (node.layoutWrap === "WRAP") out.push("wrap");
|
|
138
|
+
if (node.primaryAxisSizing === "HUG") out.push("hug:main");
|
|
139
|
+
if (node.counterAxisSizing === "HUG") out.push("hug:cross");
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
function boxDecls(node, graph) {
|
|
143
|
+
const out = [];
|
|
144
|
+
if (node.layoutAlignSelf === "STRETCH") out.push("stretch");
|
|
145
|
+
if (node.layoutGrow > 0) out.push(`grow:${Math.round(node.layoutGrow * 100) / 100}`);
|
|
146
|
+
const bg = background(node, graph);
|
|
147
|
+
if (bg) out.push(`bg:${bg}`);
|
|
148
|
+
const stroke = border(node, graph);
|
|
149
|
+
if (stroke) out.push(`border:${stroke}`);
|
|
150
|
+
const radius = radiusOf(node);
|
|
151
|
+
if (radius) out.push(`radius:${radius}`);
|
|
152
|
+
if (node.minWidth !== null) out.push(`min-w:${px(node.minWidth)}`);
|
|
153
|
+
if (node.maxWidth !== null) out.push(`max-w:${px(node.maxWidth)}`);
|
|
154
|
+
if (node.minHeight !== null) out.push(`min-h:${px(node.minHeight)}`);
|
|
155
|
+
if (node.maxHeight !== null) out.push(`max-h:${px(node.maxHeight)}`);
|
|
156
|
+
out.push(...effects(node, graph.documentColorSpace));
|
|
157
|
+
if (node.opacity !== 1) out.push(`opacity:${Math.round(node.opacity * 100) / 100}`);
|
|
158
|
+
if (node.clipsContent) out.push("clip");
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
function lineHeightOf(node) {
|
|
162
|
+
const lineHeight = node.lineHeight;
|
|
163
|
+
if (!lineHeight) return "auto";
|
|
164
|
+
return lineHeight.unit === "PERCENT" ? `${Math.round(lineHeight.value * 100) / 100}%` : px(lineHeight.value);
|
|
165
|
+
}
|
|
166
|
+
function textDecls(node, graph) {
|
|
167
|
+
const out = [`font:${node.fontWeight} ${px(node.fontSize)}/${lineHeightOf(node)} ${node.fontFamily}`];
|
|
168
|
+
const bg = background(node, graph);
|
|
169
|
+
if (bg) out.push(`color:${bg}`);
|
|
170
|
+
if (node.textAlignHorizontal !== "LEFT") out.push(`text-align:${node.textAlignHorizontal.toLowerCase()}`);
|
|
171
|
+
if (node.maxLines !== null && node.maxLines > 0) out.push(`max-lines:${node.maxLines}`);
|
|
172
|
+
if (node.textAutoResize === "NONE") out.push("fixed");
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
function lineOf(node, graph) {
|
|
176
|
+
const decls = node.type === "TEXT" ? textDecls(node, graph) : [...layoutDecls(node), ...boxDecls(node, graph)];
|
|
177
|
+
const label = node.type === "TEXT" ? `"${node.text.slice(0, 40).replaceAll("\\", "\\\\").replaceAll("\"", "\\\"").replaceAll("\n", "\\n")}"` : node.name;
|
|
178
|
+
const body = decls.length > 0 ? ` {${decls.join(";")}}` : "";
|
|
179
|
+
return `${label}#${node.id} ${box(node.width)}×${box(node.height)}${body}`;
|
|
180
|
+
}
|
|
181
|
+
/** What a cut-off walk left out, counted through the same visible-node rule as the lines. */
|
|
182
|
+
function countVisible(graph, nodeId) {
|
|
183
|
+
const node = graph.getNode(nodeId);
|
|
184
|
+
if (!node || !node.visible) return 0;
|
|
185
|
+
let count = 1;
|
|
186
|
+
for (const childId of node.childIds) count += countVisible(graph, childId);
|
|
187
|
+
return count;
|
|
188
|
+
}
|
|
189
|
+
function truncationTail(omitted) {
|
|
190
|
+
return `… +${omitted} node${omitted === 1 ? "" : "s"} (raise max_bytes or narrow with depth)`;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Depth-first lines until the budget is spent. A line that does not fit ends the walk; the kept
|
|
194
|
+
* lines never exceed the limit on their own, so the reply can always stay within `max_bytes`.
|
|
195
|
+
*/
|
|
196
|
+
function collect(graph, nodeId, depth, indent, lines, budget) {
|
|
197
|
+
const node = graph.getNode(nodeId);
|
|
198
|
+
if (!node || !node.visible) return;
|
|
199
|
+
if (budget.truncated) return;
|
|
200
|
+
const line = `${indent}${lineOf(node, graph)}`;
|
|
201
|
+
if (!(budget.bytes + utf8Length(line) + 1 <= budget.limit)) {
|
|
202
|
+
budget.truncated = true;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
budget.bytes += utf8Length(line) + 1;
|
|
206
|
+
lines.push(line);
|
|
207
|
+
if (depth > 0) for (const childId of node.childIds) collect(graph, childId, depth - 1, `${indent} `, lines, budget);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* A subtree within `maxBytes`. The truncation tail is charged to the same budget: trailing lines
|
|
211
|
+
* give way first, then the tail is left out when only the kept lines fit. A block whose first line
|
|
212
|
+
* does not fit returns no CSS at all; the reply's `truncated`/`omitted` fields report the cut.
|
|
213
|
+
*/
|
|
214
|
+
function blockFor(graph, nodeId, depth, maxBytes) {
|
|
215
|
+
const lines = [];
|
|
216
|
+
const budget = {
|
|
217
|
+
bytes: 0,
|
|
218
|
+
limit: maxBytes,
|
|
219
|
+
truncated: false
|
|
220
|
+
};
|
|
221
|
+
collect(graph, nodeId, depth, "", lines, budget);
|
|
222
|
+
if (!budget.truncated) return { css: lines.join("\n") };
|
|
223
|
+
let omitted = countVisible(graph, nodeId) - lines.length;
|
|
224
|
+
while (lines.length > 1 && budget.bytes + 1 + utf8Length(truncationTail(omitted)) > budget.limit) {
|
|
225
|
+
const last = lines.pop();
|
|
226
|
+
if (last === void 0) break;
|
|
227
|
+
budget.bytes -= utf8Length(last) + 1;
|
|
228
|
+
omitted = countVisible(graph, nodeId) - lines.length;
|
|
229
|
+
}
|
|
230
|
+
if (lines.length === 0) return {
|
|
231
|
+
css: "",
|
|
232
|
+
truncated: true,
|
|
233
|
+
omitted: countVisible(graph, nodeId)
|
|
234
|
+
};
|
|
235
|
+
const head = lines.join("\n");
|
|
236
|
+
if (budget.bytes + 1 + utf8Length(truncationTail(omitted)) > budget.limit) return {
|
|
237
|
+
css: head,
|
|
238
|
+
truncated: true,
|
|
239
|
+
omitted
|
|
240
|
+
};
|
|
241
|
+
return {
|
|
242
|
+
css: `${head}\n${truncationTail(omitted)}`,
|
|
243
|
+
truncated: true,
|
|
244
|
+
omitted
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
const getCSS = defineTool({
|
|
248
|
+
name: "get_css",
|
|
249
|
+
description: "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}`. 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. 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. 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).",
|
|
250
|
+
execution: {
|
|
251
|
+
kind: "sync",
|
|
252
|
+
mutation: "none"
|
|
253
|
+
},
|
|
254
|
+
input: v.strictObject({
|
|
255
|
+
id: v.optional(v.pipe(v.string(), v.description("Node ID (single node)"))),
|
|
256
|
+
ids: nodeIdsField("Node IDs (several nodes in one call)"),
|
|
257
|
+
depth: v.optional(toolNumber(v.pipe(v.number(), v.description("Child levels to include (default: as many as the budget holds)")))),
|
|
258
|
+
max_bytes: v.optional(toolNumber(v.pipe(v.number(), v.description("Byte budget for the reply (default 6000, max 20000)"))))
|
|
259
|
+
}),
|
|
260
|
+
execute: (figma, args) => {
|
|
261
|
+
const maxBytes = Math.min(args.max_bytes ?? 6e3, HARD_MAX_BYTES);
|
|
262
|
+
const depth = args.depth ?? 100;
|
|
263
|
+
if (args.ids && Array.isArray(args.ids)) {
|
|
264
|
+
const blocks = [];
|
|
265
|
+
let omitted = 0;
|
|
266
|
+
let truncated = false;
|
|
267
|
+
let used = 0;
|
|
268
|
+
for (const nodeId of args.ids) {
|
|
269
|
+
if (!figma.graph.getNode(nodeId)) return { error: `Node "${nodeId}" not found` };
|
|
270
|
+
const separator = blocks.length === 0 ? 0 : 1;
|
|
271
|
+
const block = blockFor(figma.graph, nodeId, depth, maxBytes - used - separator);
|
|
272
|
+
if (block.css === "") {
|
|
273
|
+
omitted += block.omitted ?? 0;
|
|
274
|
+
truncated = truncated || block.truncated === true;
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
blocks.push(block.css);
|
|
278
|
+
used += utf8Length(block.css) + separator;
|
|
279
|
+
omitted += block.omitted ?? 0;
|
|
280
|
+
truncated = truncated || block.truncated === true;
|
|
281
|
+
}
|
|
282
|
+
const css = blocks.join("\n");
|
|
283
|
+
if (!truncated) return {
|
|
284
|
+
ids: args.ids,
|
|
285
|
+
css
|
|
286
|
+
};
|
|
287
|
+
return {
|
|
288
|
+
ids: args.ids,
|
|
289
|
+
css,
|
|
290
|
+
truncated: true,
|
|
291
|
+
omitted
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
if (!args.id) return { error: "Provide id (string) or ids (string[])" };
|
|
295
|
+
if (!figma.graph.getNode(args.id)) return { error: `Node "${args.id}" not found` };
|
|
296
|
+
const block = blockFor(figma.graph, args.id, depth, maxBytes);
|
|
297
|
+
return {
|
|
298
|
+
id: args.id,
|
|
299
|
+
...block
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
//#endregion
|
|
304
|
+
export { DEFAULT_MAX_BYTES, HARD_MAX_BYTES, getCSS };
|
|
305
|
+
|
|
306
|
+
//# sourceMappingURL=css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.js","names":[],"sources":["../../../src/tools/read/css.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { ColorProfile, SceneGraph, SceneNode, ShadowEffect } from '@pairdraw/scene-graph'\nimport { colorToDocumentCSS } from '@pairdraw/scene-graph/color'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport { defineTool, nodeIdsField, toolNumber } from '#core/tools/schema'\n\n/**\n * A subtree as CSS-shaped lines: one line per node, lengths in px, colours in the document's\n * profile with the token that binds them in `var(--name, …)` form: hex in an sRGB document,\n * `color(display-p3 …)` in a Display P3 one. This is the read side of the CSS shorthand the\n * setters accept, so a value read here can be written back unchanged.\n */\nexport const DEFAULT_MAX_BYTES = 6000\nexport const HARD_MAX_BYTES = 20_000\n\nconst AXIS_JUSTIFY: Record<string, string> = {\n CENTER: 'center',\n MAX: 'end',\n SPACE_BETWEEN: 'space-between',\n SPACE_AROUND: 'space-around'\n}\n\nconst AXIS_ITEMS: Record<string, string> = {\n CENTER: 'center',\n MAX: 'end',\n STRETCH: 'stretch',\n BASELINE: 'baseline'\n}\n\n/** A length as CSS writes it: whole px where it is whole, up to two decimals otherwise. */\nfunction px(value: number): string {\n return `${Math.round(value * 100) / 100}px`\n}\n\n/**\n * The radius line, read the way `shape-details` reads corners: the per-corner fields while\n * `independentCorners` is set (the uniform field is stale then), four values in CSS order when\n * they differ, one otherwise. The four values write back through `set_radius`'s shorthand.\n */\nfunction radiusOf(node: SceneNode): string | null {\n if (node.independentCorners) {\n const corners = [\n node.topLeftRadius,\n node.topRightRadius,\n node.bottomRightRadius,\n node.bottomLeftRadius\n ]\n if (corners.every((value) => value === corners[0])) {\n return corners[0] > 0 ? px(corners[0]) : null\n }\n return corners.map((value) => (value === 0 ? '0' : px(value))).join(' ')\n }\n return node.cornerRadius > 0 ? px(node.cornerRadius) : null\n}\n\nfunction box(value: number): string {\n return String(Math.round(value))\n}\n\n/** UTF-8 bytes without a Node Buffer, so the tool runs in the app as well as headless. */\nfunction utf8Length(text: string): number {\n let bytes = 0\n for (let index = 0; index < text.length; index++) {\n const code = text.charCodeAt(index)\n if (code < 0x80) bytes += 1\n else if (code < 0x800) bytes += 2\n else if (code < 0xd800 || code >= 0xe000) bytes += 3\n else bytes += 4\n }\n return bytes\n}\n\nfunction boundName(graph: SceneGraph, node: SceneNode, field: string): string | null {\n const variableId = node.boundVariables[field]\n if (!variableId) return null\n return graph.variables.get(variableId)?.name ?? null\n}\n\n/**\n * A stored colour as the shorthand writes it: `#RRGGBB` in an sRGB document, `color(display-p3 …)`\n * in a Display P3 one, where hex would name a different colour. The shorthand carries no alpha, as\n * it never has, so the paint's opacity is left to `opacity`.\n */\nfunction cssColor(color: Color, profile: ColorProfile): string {\n return colorToDocumentCSS({ ...color, a: 1 }, profile)\n}\n\n/** A colour in the document's profile, or `var(--token, …)` when a variable paints it. */\nfunction paintOf(node: SceneNode, graph: SceneGraph, field: string, paint: string): string {\n const name = boundName(graph, node, field)\n return name ? `var(--${name}, ${paint})` : paint\n}\n\nfunction background(node: SceneNode, graph: SceneGraph): string | null {\n const index = node.fills.findIndex((candidate) => candidate.type === 'SOLID' && candidate.visible)\n const solid = index === -1 ? undefined : node.fills[index]\n if (solid) {\n const paint = cssColor(solid.color, graph.documentColorSpace)\n return paintOf(node, graph, `fills/${index}/color`, paint)\n }\n const otherIndex = node.fills.findIndex((candidate) => candidate.visible)\n const other = otherIndex === -1 ? undefined : node.fills[otherIndex]\n if (!other) return null\n return other.type.startsWith('GRADIENT') ? 'gradient' : 'image'\n}\n\nfunction border(node: SceneNode, graph: SceneGraph): string | null {\n const index = node.strokes.findIndex((candidate) => candidate.visible)\n const stroke = index === -1 ? undefined : node.strokes[index]\n if (!stroke) return null\n const paint = cssColor(stroke.color, graph.documentColorSpace)\n return `${px(stroke.weight)} ${paintOf(node, graph, `strokes/${index}/color`, paint)}`\n}\n\n/** Padding in CSS order, compressed to the fewest values that say the same thing. */\nfunction padding(node: SceneNode): string | null {\n const top = node.paddingTop\n const right = node.paddingRight\n const bottom = node.paddingBottom\n const left = node.paddingLeft\n if (top === 0 && right === 0 && bottom === 0 && left === 0) return null\n if (top === right && right === bottom && bottom === left) return px(top)\n if (top === bottom && right === left) return `${px(top)} ${px(right)}`\n return `${px(top)} ${px(right)} ${px(bottom)} ${px(left)}`\n}\n\nfunction shadowOf(prefix: string, effect: ShadowEffect, profile: ColorProfile): string {\n return `${prefix}:${px(effect.offset.x)} ${px(effect.offset.y)} ${px(effect.radius)} ${cssColor(effect.color, profile)}`\n}\n\nfunction effects(node: SceneNode, profile: ColorProfile): string[] {\n const out: string[] = []\n for (const effect of node.effects) {\n if (!effect.visible) continue\n if (effect.type === 'DROP_SHADOW') out.push(shadowOf('shadow', effect, profile))\n else if (effect.type === 'INNER_SHADOW') out.push(shadowOf('inner-shadow', effect, profile))\n else if (effect.type === 'LAYER_BLUR' || effect.type === 'FOREGROUND_BLUR')\n out.push(`blur:${px(effect.radius)}`)\n else out.push('backdrop-blur')\n }\n return out\n}\n\nfunction layoutDecls(node: SceneNode): string[] {\n if (node.layoutMode === 'NONE') return []\n const out = [node.layoutMode === 'HORIZONTAL' ? 'flex:row' : 'flex:column']\n if (node.itemSpacing > 0) {\n out.push(\n node.layoutWrap === 'WRAP' && node.counterAxisSpacing > 0\n ? `gap:${px(node.itemSpacing)} ${px(node.counterAxisSpacing)}`\n : `gap:${px(node.itemSpacing)}`\n )\n }\n const paddingValue = padding(node)\n if (paddingValue) out.push(`padding:${paddingValue}`)\n const justify = AXIS_JUSTIFY[node.primaryAxisAlign]\n if (justify) out.push(`justify:${justify}`)\n const items = AXIS_ITEMS[node.counterAxisAlign]\n if (items) out.push(`items:${items}`)\n if (node.layoutWrap === 'WRAP') out.push('wrap')\n if (node.primaryAxisSizing === 'HUG') out.push('hug:main')\n if (node.counterAxisSizing === 'HUG') out.push('hug:cross')\n return out\n}\n\nfunction boxDecls(node: SceneNode, graph: SceneGraph): string[] {\n const out: string[] = []\n if (node.layoutAlignSelf === 'STRETCH') out.push('stretch')\n if (node.layoutGrow > 0) out.push(`grow:${Math.round(node.layoutGrow * 100) / 100}`)\n const bg = background(node, graph)\n if (bg) out.push(`bg:${bg}`)\n const stroke = border(node, graph)\n if (stroke) out.push(`border:${stroke}`)\n const radius = radiusOf(node)\n if (radius) out.push(`radius:${radius}`)\n if (node.minWidth !== null) out.push(`min-w:${px(node.minWidth)}`)\n if (node.maxWidth !== null) out.push(`max-w:${px(node.maxWidth)}`)\n if (node.minHeight !== null) out.push(`min-h:${px(node.minHeight)}`)\n if (node.maxHeight !== null) out.push(`max-h:${px(node.maxHeight)}`)\n out.push(...effects(node, graph.documentColorSpace))\n if (node.opacity !== 1) out.push(`opacity:${Math.round(node.opacity * 100) / 100}`)\n if (node.clipsContent) out.push('clip')\n return out\n}\n\nfunction lineHeightOf(node: SceneNode): string {\n const lineHeight = node.lineHeight\n if (!lineHeight) return 'auto'\n return lineHeight.unit === 'PERCENT'\n ? `${Math.round(lineHeight.value * 100) / 100}%`\n : px(lineHeight.value)\n}\n\nfunction textDecls(node: SceneNode, graph: SceneGraph): string[] {\n const out = [\n `font:${node.fontWeight} ${px(node.fontSize)}/${lineHeightOf(node)} ${node.fontFamily}`\n ]\n const bg = background(node, graph)\n if (bg) out.push(`color:${bg}`)\n if (node.textAlignHorizontal !== 'LEFT') {\n out.push(`text-align:${node.textAlignHorizontal.toLowerCase()}`)\n }\n if (node.maxLines !== null && node.maxLines > 0) out.push(`max-lines:${node.maxLines}`)\n if (node.textAutoResize === 'NONE') out.push('fixed')\n return out\n}\n\nfunction lineOf(node: SceneNode, graph: SceneGraph): string {\n const decls =\n node.type === 'TEXT' ? textDecls(node, graph) : [...layoutDecls(node), ...boxDecls(node, graph)]\n const label =\n node.type === 'TEXT'\n ? `\"${node.text.slice(0, 40).replaceAll('\\\\', '\\\\\\\\').replaceAll('\"', '\\\\\"').replaceAll('\\n', '\\\\n')}\"`\n : node.name\n const body = decls.length > 0 ? ` {${decls.join(';')}}` : ''\n return `${label}#${node.id} ${box(node.width)}×${box(node.height)}${body}`\n}\n\ninterface Budget {\n bytes: number\n limit: number\n truncated: boolean\n}\n\n/** What a cut-off walk left out, counted through the same visible-node rule as the lines. */\nfunction countVisible(graph: SceneGraph, nodeId: string): number {\n const node = graph.getNode(nodeId)\n if (!node || !node.visible) return 0\n let count = 1\n for (const childId of node.childIds) count += countVisible(graph, childId)\n return count\n}\n\nfunction truncationTail(omitted: number): string {\n return `… +${omitted} node${omitted === 1 ? '' : 's'} (raise max_bytes or narrow with depth)`\n}\n\n/**\n * Depth-first lines until the budget is spent. A line that does not fit ends the walk; the kept\n * lines never exceed the limit on their own, so the reply can always stay within `max_bytes`.\n */\nfunction collect(\n graph: SceneGraph,\n nodeId: string,\n depth: number,\n indent: string,\n lines: string[],\n budget: Budget\n): void {\n const node = graph.getNode(nodeId)\n if (!node || !node.visible) return\n if (budget.truncated) return\n const line = `${indent}${lineOf(node, graph)}`\n const fits = budget.bytes + utf8Length(line) + 1 <= budget.limit\n if (!fits) {\n budget.truncated = true\n return\n }\n budget.bytes += utf8Length(line) + 1\n lines.push(line)\n if (depth > 0) {\n for (const childId of node.childIds) {\n collect(graph, childId, depth - 1, `${indent} `, lines, budget)\n }\n }\n}\n\n/**\n * A subtree within `maxBytes`. The truncation tail is charged to the same budget: trailing lines\n * give way first, then the tail is left out when only the kept lines fit. A block whose first line\n * does not fit returns no CSS at all; the reply's `truncated`/`omitted` fields report the cut.\n */\nfunction blockFor(\n graph: SceneGraph,\n nodeId: string,\n depth: number,\n maxBytes: number\n): { css: string; truncated?: true; omitted?: number } {\n const lines: string[] = []\n const budget: Budget = { bytes: 0, limit: maxBytes, truncated: false }\n collect(graph, nodeId, depth, '', lines, budget)\n if (!budget.truncated) return { css: lines.join('\\n') }\n // Every visible node either has a line or is left out, so the omitted count follows from the\n // node total. Each dropped line's byte count includes the newline collect charged for it.\n let omitted = countVisible(graph, nodeId) - lines.length\n while (\n lines.length > 1 &&\n budget.bytes + 1 + utf8Length(truncationTail(omitted)) > budget.limit\n ) {\n const last = lines.pop()\n if (last === undefined) break\n budget.bytes -= utf8Length(last) + 1\n omitted = countVisible(graph, nodeId) - lines.length\n }\n if (lines.length === 0) {\n return { css: '', truncated: true, omitted: countVisible(graph, nodeId) }\n }\n const head = lines.join('\\n')\n if (budget.bytes + 1 + utf8Length(truncationTail(omitted)) > budget.limit) {\n return { css: head, truncated: true, omitted }\n }\n return { css: `${head}\\n${truncationTail(omitted)}`, truncated: true, omitted }\n}\n\nexport const getCSS = defineTool({\n name: 'get_css',\n description:\n '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}`. ' +\n '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. ' +\n \"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. \" +\n '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).',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({\n id: v.optional(v.pipe(v.string(), v.description('Node ID (single node)'))),\n ids: nodeIdsField('Node IDs (several nodes in one call)'),\n depth: v.optional(\n toolNumber(\n v.pipe(\n v.number(),\n v.description('Child levels to include (default: as many as the budget holds)')\n )\n )\n ),\n max_bytes: v.optional(\n toolNumber(\n v.pipe(v.number(), v.description('Byte budget for the reply (default 6000, max 20000)'))\n )\n )\n }),\n execute: (figma, args) => {\n const maxBytes = Math.min(args.max_bytes ?? DEFAULT_MAX_BYTES, HARD_MAX_BYTES)\n const depth = args.depth ?? 100\n\n if (args.ids && Array.isArray(args.ids)) {\n const blocks: string[] = []\n let omitted = 0\n let truncated = false\n let used = 0\n for (const nodeId of args.ids) {\n if (!figma.graph.getNode(nodeId)) return { error: `Node \"${nodeId}\" not found` }\n const separator = blocks.length === 0 ? 0 : 1\n const block = blockFor(figma.graph, nodeId, depth, maxBytes - used - separator)\n if (block.css === '') {\n omitted += block.omitted ?? 0\n truncated = truncated || block.truncated === true\n continue\n }\n blocks.push(block.css)\n used += utf8Length(block.css) + separator\n omitted += block.omitted ?? 0\n truncated = truncated || block.truncated === true\n }\n const css = blocks.join('\\n')\n if (!truncated) return { ids: args.ids, css }\n return { ids: args.ids, css, truncated: true, omitted }\n }\n\n if (!args.id) return { error: 'Provide id (string) or ids (string[])' }\n if (!figma.graph.getNode(args.id)) return { error: `Node \"${args.id}\"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,SAAS,OAAO,aAAa;IAC/E,MAAM,YAAY,OAAO,WAAW,IAAI,IAAI;IAC5C,MAAM,QAAQ,SAAS,MAAM,OAAO,QAAQ,OAAO,WAAW,OAAO,SAAS;IAC9E,IAAI,MAAM,QAAQ,IAAI;KACpB,WAAW,MAAM,WAAW;KAC5B,YAAY,aAAa,MAAM,cAAc;KAC7C;IACF;IACA,OAAO,KAAK,MAAM,GAAG;IACrB,QAAQ,WAAW,MAAM,GAAG,IAAI;IAChC,WAAW,MAAM,WAAW;IAC5B,YAAY,aAAa,MAAM,cAAc;GAC/C;GACA,MAAM,MAAM,OAAO,KAAK,IAAI;GAC5B,IAAI,CAAC,WAAW,OAAO;IAAE,KAAK,KAAK;IAAK;GAAI;GAC5C,OAAO;IAAE,KAAK,KAAK;IAAK;IAAK,WAAW;IAAM;GAAQ;EACxD;EAEA,IAAI,CAAC,KAAK,IAAI,OAAO,EAAE,OAAO,wCAAwC;EACtE,IAAI,CAAC,MAAM,MAAM,QAAQ,KAAK,EAAE,GAAG,OAAO,EAAE,OAAO,SAAS,KAAK,GAAG,aAAa;EACjF,MAAM,QAAQ,SAAS,MAAM,OAAO,KAAK,IAAI,OAAO,QAAQ;EAC5D,OAAO;GAAE,IAAI,KAAK;GAAI,GAAG;EAAM;CACjC;AACF,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { prepareSlotInsertion } from "../../figma-api/slots.js";
|
|
2
1
|
import { defineTool, toolNumber } from "../schema.js";
|
|
2
|
+
import { prepareSlotInsertion } from "../../figma-api/slots.js";
|
|
3
3
|
import { getComponentCatalog } from "../component-catalog.js";
|
|
4
4
|
import { groupBy, isPlainObject } from "es-toolkit";
|
|
5
5
|
import * as v from "valibot";
|
|
@@ -3,7 +3,7 @@ import * as v from "valibot";
|
|
|
3
3
|
//#region src/tools/read/reactions.ts
|
|
4
4
|
const getReactions = defineTool({
|
|
5
5
|
name: "get_reactions",
|
|
6
|
-
description: "Get the prototype connections on a layer, in Figma's plugin shape: each trigger and its actions, with a NODE action naming the destination frame. Empty when the layer connects to nothing.",
|
|
6
|
+
description: "Get the prototype connections on a layer, in Figma's plugin shape: each trigger and its actions, with a NODE action naming the destination frame or variant. A Change to authored by variant properties reads back as the destination variant id. Empty when the layer connects to nothing.",
|
|
7
7
|
execution: {
|
|
8
8
|
kind: "sync",
|
|
9
9
|
mutation: "none"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactions.js","names":[],"sources":["../../../src/tools/read/reactions.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { defineTool, nodeIdInputSchema, nodeNotFound } from '#core/tools/schema'\n\nexport const getReactions = defineTool({\n name: 'get_reactions',\n\n description:\n \"Get the prototype connections on a layer, in Figma's plugin shape: each trigger and its \" +\n 'actions, with a NODE action naming the destination frame. Empty when the layer
|
|
1
|
+
{"version":3,"file":"reactions.js","names":[],"sources":["../../../src/tools/read/reactions.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { defineTool, nodeIdInputSchema, nodeNotFound } from '#core/tools/schema'\n\nexport const getReactions = defineTool({\n name: 'get_reactions',\n\n description:\n \"Get the prototype connections on a layer, in Figma's plugin shape: each trigger and its \" +\n 'actions, with a NODE action naming the destination frame or variant. A Change to authored ' +\n 'by variant properties reads back as the destination variant id. Empty when the layer ' +\n 'connects to nothing.',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({\n id: nodeIdInputSchema\n }),\n execute: (figma, { id }) => {\n const node = figma.getNodeById(id)\n if (!node) return nodeNotFound(id)\n return { id, reactions: node.reactions }\n }\n})\n"],"mappings":";;;AAIA,MAAa,eAAe,WAAW;CACrC,MAAM;CAEN,aACE;CAIF,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,OAAO,EAAE,aAAa,EACpB,IAAI,kBACN,CAAC;CACD,UAAU,OAAO,EAAE,SAAS;EAC1B,MAAM,OAAO,MAAM,YAAY,EAAE;EACjC,IAAI,CAAC,MAAM,OAAO,aAAa,EAAE;EACjC,OAAO;GAAE;GAAI,WAAW,KAAK;EAAU;CACzC;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"space.d.ts","names":[],"sources":["../../../src/tools/read/space.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"space.d.ts","names":[],"sources":["../../../src/tools/read/space.ts"],"mappings":";;;;cAUM;KACD,yBAAyB;;cAGjB;UAEI;;EAEf,oBAAoB;EACpB;EACA;;EAEA,QAAQ;EACR;EACA,qBAAqB;;UAGN,mBAAmB;EAClC,WAAW;;;iBAIG,aAAa,MAAM,MAAM,UAAU,MAAM;;;;;iBAsDzC,eAAe,SAAS,oBAAoB;;iBAe5C,WAAW,OAAO,YAAY,mBAAmB;;iBAUjD,mBACd,OAAO,YACP,kBACA;EAAQ;EAAe;GACvB,eACC;cAcU,oBAAA"}
|
package/dist/tools/read/space.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { findPageId } from "../../io/subgraph.js";
|
|
2
|
-
import { flushPendingLayout } from "../../figma-api/pending-layout.js";
|
|
3
2
|
import { defineTool, toolNumber } from "../schema.js";
|
|
4
3
|
import { getAxisAlignedBoundsInParent } from "@pairdraw/scene-graph/coordinate";
|
|
5
4
|
import { computeBounds } from "@pairdraw/scene-graph/geometry";
|
|
@@ -137,7 +136,6 @@ const findEmptySpaceTool = defineTool({
|
|
|
137
136
|
if (!parent || parent.type !== "CANVAS" && !findPageId(graph, parentId)) return { error: `Parent "${parentId}" not found` };
|
|
138
137
|
if (parent.layoutMode !== "NONE" && parent.type !== "CANVAS") return { error: `${parent.name} places its children with auto layout; append to it instead` };
|
|
139
138
|
if (args.near_id && nearParentId !== parentId) return { error: `Node "${args.near_id}" is not a child of "${parentId}"` };
|
|
140
|
-
flushPendingLayout(graph);
|
|
141
139
|
const obstacles = childBoxes(graph, parentId);
|
|
142
140
|
const near = args.near_id ? graph.getNode(args.near_id) : void 0;
|
|
143
141
|
let anchor = obstacles.length > 0 ? computeBounds(obstacles) : null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"space.js","names":[],"sources":["../../../src/tools/read/space.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport { getAxisAlignedBoundsInParent } from '@pairdraw/scene-graph/coordinate'\nimport { computeBounds } from '@pairdraw/scene-graph/geometry'\nimport type { Rect } from '@pairdraw/scene-graph/primitives'\n\nimport { flushPendingLayout } from '#core/figma-api'\nimport { findPageId } from '#core/io/subgraph'\nimport { defineTool, toolNumber } from '#core/tools/schema'\n\nconst SPACE_DIRECTIONS = ['right', 'below', 'left', 'above'] as const\ntype SpaceDirection = (typeof SPACE_DIRECTIONS)[number]\n\n/** Room kept between a found space and the layers around it, as `import_mermaid` keeps. */\nexport const DEFAULT_SPACE_GAP = 100\n\nexport interface EmptySpaceRequest {\n /** What is already there, in the parent's coordinates. */\n obstacles: readonly Rect[]\n width: number\n height: number\n /** The region to stay close to; null when the parent is empty. */\n anchor: Rect | null\n gap: number\n directions: readonly SpaceDirection[]\n}\n\nexport interface EmptySpace extends Rect {\n direction: SpaceDirection | null\n}\n\n/** Whether `rect` comes within `gap` of `obstacle`, or covers part of it when `gap` is 0. */\nexport function rectsOverlap(rect: Rect, obstacle: Rect, gap: number): boolean {\n return (\n rect.x < obstacle.x + obstacle.width + gap &&\n rect.x + rect.width + gap > obstacle.x &&\n rect.y < obstacle.y + obstacle.height + gap &&\n rect.y + rect.height + gap > obstacle.y\n )\n}\n\n/**\n * The first free position going one way from the anchor, keeping the anchor's row or column.\n * Each candidate sits just past an obstacle's far edge, so the last one clears them all.\n */\nfunction spaceToward(request: EmptySpaceRequest, anchor: Rect, direction: SpaceDirection): Rect {\n const { obstacles, width, height, gap } = request\n const horizontal = direction === 'right' || direction === 'left'\n const forward = direction === 'right' || direction === 'below'\n const start = {\n right: anchor.x + anchor.width + gap,\n left: anchor.x - gap - width,\n below: anchor.y + anchor.height + gap,\n above: anchor.y - gap - height\n }[direction]\n const edges = obstacles.map((obstacle) => {\n if (direction === 'right') return obstacle.x + obstacle.width + gap\n if (direction === 'left') return obstacle.x - gap - width\n if (direction === 'below') return obstacle.y + obstacle.height + gap\n return obstacle.y - gap - height\n })\n const candidates = [start, ...edges.filter((edge) => (forward ? edge > start : edge < start))]\n candidates.sort((a, b) => (forward ? a - b : b - a))\n const place = (offset: number): Rect =>\n horizontal\n ? { x: offset, y: anchor.y, width, height }\n : { x: anchor.x, y: offset, width, height }\n for (const offset of candidates) {\n const rect = place(offset)\n if (!obstacles.some((obstacle) => rectsOverlap(rect, obstacle, gap))) return rect\n }\n // Unreachable: the farthest candidate clears every obstacle along this axis.\n return place(candidates[candidates.length - 1] ?? start)\n}\n\nfunction distance(anchor: Rect, rect: Rect, direction: SpaceDirection, gap: number): number {\n if (direction === 'right') return rect.x - (anchor.x + anchor.width + gap)\n if (direction === 'left') return anchor.x - gap - (rect.x + rect.width)\n if (direction === 'below') return rect.y - (anchor.y + anchor.height + gap)\n return anchor.y - gap - (rect.y + rect.height)\n}\n\n/**\n * A free region of `width` × `height` that keeps `gap` from every obstacle, as close to the\n * anchor as the directions allow; the first direction wins a tie.\n */\nexport function findEmptySpace(request: EmptySpaceRequest): EmptySpace {\n const { anchor, width, height, gap } = request\n if (!anchor) return { x: 0, y: 0, width, height, direction: null }\n let best: { rect: Rect; direction: SpaceDirection; distance: number } | null = null\n for (const direction of request.directions) {\n const rect = spaceToward(request, anchor, direction)\n const away = distance(anchor, rect, direction, gap)\n if (!best || away < best.distance) best = { rect, direction, distance: away }\n }\n return best\n ? { ...best.rect, direction: best.direction }\n : { ...spaceToward(request, anchor, 'right'), direction: 'right' }\n}\n\n/** Each child of `parentId` as an axis-aligned box in the parent's coordinates. */\nexport function childBoxes(graph: SceneGraph, parentId: string): Rect[] {\n const parent = graph.getNode(parentId)\n if (!parent) return []\n return parent.childIds.flatMap((id) => {\n const node = graph.getNode(id)\n return node ? [getAxisAlignedBoundsInParent([node], parentId, graph)] : []\n })\n}\n\n/** Where content of a size goes beside what `parentId` already holds. */\nexport function spaceBesideContent(\n graph: SceneGraph,\n parentId: string,\n size: { width: number; height: number },\n gap = DEFAULT_SPACE_GAP\n): EmptySpace {\n const obstacles = childBoxes(graph, parentId)\n return findEmptySpace({\n obstacles,\n ...size,\n anchor: obstacles.length > 0 ? computeBounds(obstacles) : null,\n gap,\n directions: ['right']\n })\n}\n\nconst sizeInput = (description: string) =>\n toolNumber(v.pipe(v.number(), v.minValue(0), v.description(description)))\n\nexport const findEmptySpaceTool = defineTool({\n name: 'find_empty_space',\n description:\n 'Find a free region of the canvas for new content of a given size, so it overlaps nothing. Without near_id it looks beside everything the parent holds; with near_id it looks next to that layer. direction \"any\" (default) takes the nearest free spot to the right, below, left, or above. Returns x and y in the parent’s coordinates, ready for render or create tools.',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({\n width: sizeInput('Width of the content to place'),\n height: sizeInput('Height of the content to place'),\n near_id: v.optional(\n v.pipe(v.string(), v.description('Layer to place the content next to (default: all content)'))\n ),\n parent_id: v.optional(\n v.pipe(v.string(), v.description('Parent to search (default: the current page)'))\n ),\n direction: v.optional(\n v.pipe(\n v.picklist(['any', ...SPACE_DIRECTIONS]),\n v.description('Which side of the anchor to search (default: any)')\n ),\n 'any'\n ),\n gap: v.optional(\n toolNumber(\n v.pipe(\n v.number(),\n v.minValue(0),\n v.description(`Room to keep around other layers (default: ${DEFAULT_SPACE_GAP})`)\n )\n ),\n DEFAULT_SPACE_GAP\n )\n }),\n execute: (figma, args) => {\n const graph = figma.graph\n const nearParentId = args.near_id ? graph.getNode(args.near_id)?.parentId : undefined\n if (args.near_id && !nearParentId) return { error: `Node \"${args.near_id}\" not found` }\n const parentId = args.parent_id ?? nearParentId ?? figma.currentPage.id\n const parent = graph.getNode(parentId)\n if (!parent || (parent.type !== 'CANVAS' && !findPageId(graph, parentId))) {\n return { error: `Parent \"${parentId}\" not found` }\n }\n if (parent.layoutMode !== 'NONE' && parent.type !== 'CANVAS') {\n return { error: `${parent.name} places its children with auto layout; append to it instead` }\n }\n if (args.near_id && nearParentId !== parentId) {\n return { error: `Node \"${args.near_id}\" is not a child of \"${parentId}\"` }\n }\n flushPendingLayout(graph)\n const obstacles = childBoxes(graph, parentId)\n const near = args.near_id ? graph.getNode(args.near_id) : undefined\n let anchor = obstacles.length > 0 ? computeBounds(obstacles) : null\n if (near) anchor = getAxisAlignedBoundsInParent([near], parentId, graph)\n const space = findEmptySpace({\n obstacles,\n width: args.width,\n height: args.height,\n anchor,\n gap: args.gap,\n directions: args.direction === 'any' ? SPACE_DIRECTIONS : [args.direction]\n })\n // Whole pixels, rounded away from what the space was found beside.\n const round = (value: number, away: SpaceDirection) =>\n space.direction === away ? Math.floor(value) : Math.ceil(value)\n return {\n parent_id: parentId,\n x: round(space.x, 'left'),\n y: round(space.y, 'above'),\n width: args.width,\n height: args.height,\n ...(space.direction ? { direction: space.direction } : {})\n }\n }\n})\n"],"mappings":";;;;;;;AAWA,MAAM,mBAAmB;CAAC;CAAS;CAAS;CAAQ;AAAO;;AAI3D,MAAa,oBAAoB;;AAkBjC,SAAgB,aAAa,MAAY,UAAgB,KAAsB;CAC7E,OACE,KAAK,IAAI,SAAS,IAAI,SAAS,QAAQ,OACvC,KAAK,IAAI,KAAK,QAAQ,MAAM,SAAS,KACrC,KAAK,IAAI,SAAS,IAAI,SAAS,SAAS,OACxC,KAAK,IAAI,KAAK,SAAS,MAAM,SAAS;AAE1C;;;;;AAMA,SAAS,YAAY,SAA4B,QAAc,WAAiC;CAC9F,MAAM,EAAE,WAAW,OAAO,QAAQ,QAAQ;CAC1C,MAAM,aAAa,cAAc,WAAW,cAAc;CAC1D,MAAM,UAAU,cAAc,WAAW,cAAc;CACvD,MAAM,QAAQ;EACZ,OAAO,OAAO,IAAI,OAAO,QAAQ;EACjC,MAAM,OAAO,IAAI,MAAM;EACvB,OAAO,OAAO,IAAI,OAAO,SAAS;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AAQ,KAAK;GACb;GACA,KAAK,KAAK;GACV,YAAY,KAAK,cAAc,QAAQ,mBAAmB,CAAC,KAAK,SAAS;EAC3E,CAAC;EAED,MAAM,SAAS,OAAe,SAC5B,MAAM,cAAc,OAAO,KAAK,MAAM,KAAK,IAAI,KAAK,KAAK,KAAK;EAChE,OAAO;GACL,WAAW;GACX,GAAG,MAAM,MAAM,GAAG,MAAM;GACxB,GAAG,MAAM,MAAM,GAAG,OAAO;GACzB,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,GAAI,MAAM,YAAY,EAAE,WAAW,MAAM,UAAU,IAAI,CAAC;EAC1D;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"space.js","names":[],"sources":["../../../src/tools/read/space.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport { getAxisAlignedBoundsInParent } from '@pairdraw/scene-graph/coordinate'\nimport { computeBounds } from '@pairdraw/scene-graph/geometry'\nimport type { Rect } from '@pairdraw/scene-graph/primitives'\n\nimport { findPageId } from '#core/io/subgraph'\nimport { defineTool, toolNumber } from '#core/tools/schema'\n\nconst SPACE_DIRECTIONS = ['right', 'below', 'left', 'above'] as const\ntype SpaceDirection = (typeof SPACE_DIRECTIONS)[number]\n\n/** Room kept between a found space and the layers around it, as `import_mermaid` keeps. */\nexport const DEFAULT_SPACE_GAP = 100\n\nexport interface EmptySpaceRequest {\n /** What is already there, in the parent's coordinates. */\n obstacles: readonly Rect[]\n width: number\n height: number\n /** The region to stay close to; null when the parent is empty. */\n anchor: Rect | null\n gap: number\n directions: readonly SpaceDirection[]\n}\n\nexport interface EmptySpace extends Rect {\n direction: SpaceDirection | null\n}\n\n/** Whether `rect` comes within `gap` of `obstacle`, or covers part of it when `gap` is 0. */\nexport function rectsOverlap(rect: Rect, obstacle: Rect, gap: number): boolean {\n return (\n rect.x < obstacle.x + obstacle.width + gap &&\n rect.x + rect.width + gap > obstacle.x &&\n rect.y < obstacle.y + obstacle.height + gap &&\n rect.y + rect.height + gap > obstacle.y\n )\n}\n\n/**\n * The first free position going one way from the anchor, keeping the anchor's row or column.\n * Each candidate sits just past an obstacle's far edge, so the last one clears them all.\n */\nfunction spaceToward(request: EmptySpaceRequest, anchor: Rect, direction: SpaceDirection): Rect {\n const { obstacles, width, height, gap } = request\n const horizontal = direction === 'right' || direction === 'left'\n const forward = direction === 'right' || direction === 'below'\n const start = {\n right: anchor.x + anchor.width + gap,\n left: anchor.x - gap - width,\n below: anchor.y + anchor.height + gap,\n above: anchor.y - gap - height\n }[direction]\n const edges = obstacles.map((obstacle) => {\n if (direction === 'right') return obstacle.x + obstacle.width + gap\n if (direction === 'left') return obstacle.x - gap - width\n if (direction === 'below') return obstacle.y + obstacle.height + gap\n return obstacle.y - gap - height\n })\n const candidates = [start, ...edges.filter((edge) => (forward ? edge > start : edge < start))]\n candidates.sort((a, b) => (forward ? a - b : b - a))\n const place = (offset: number): Rect =>\n horizontal\n ? { x: offset, y: anchor.y, width, height }\n : { x: anchor.x, y: offset, width, height }\n for (const offset of candidates) {\n const rect = place(offset)\n if (!obstacles.some((obstacle) => rectsOverlap(rect, obstacle, gap))) return rect\n }\n // Unreachable: the farthest candidate clears every obstacle along this axis.\n return place(candidates[candidates.length - 1] ?? start)\n}\n\nfunction distance(anchor: Rect, rect: Rect, direction: SpaceDirection, gap: number): number {\n if (direction === 'right') return rect.x - (anchor.x + anchor.width + gap)\n if (direction === 'left') return anchor.x - gap - (rect.x + rect.width)\n if (direction === 'below') return rect.y - (anchor.y + anchor.height + gap)\n return anchor.y - gap - (rect.y + rect.height)\n}\n\n/**\n * A free region of `width` × `height` that keeps `gap` from every obstacle, as close to the\n * anchor as the directions allow; the first direction wins a tie.\n */\nexport function findEmptySpace(request: EmptySpaceRequest): EmptySpace {\n const { anchor, width, height, gap } = request\n if (!anchor) return { x: 0, y: 0, width, height, direction: null }\n let best: { rect: Rect; direction: SpaceDirection; distance: number } | null = null\n for (const direction of request.directions) {\n const rect = spaceToward(request, anchor, direction)\n const away = distance(anchor, rect, direction, gap)\n if (!best || away < best.distance) best = { rect, direction, distance: away }\n }\n return best\n ? { ...best.rect, direction: best.direction }\n : { ...spaceToward(request, anchor, 'right'), direction: 'right' }\n}\n\n/** Each child of `parentId` as an axis-aligned box in the parent's coordinates. */\nexport function childBoxes(graph: SceneGraph, parentId: string): Rect[] {\n const parent = graph.getNode(parentId)\n if (!parent) return []\n return parent.childIds.flatMap((id) => {\n const node = graph.getNode(id)\n return node ? [getAxisAlignedBoundsInParent([node], parentId, graph)] : []\n })\n}\n\n/** Where content of a size goes beside what `parentId` already holds. */\nexport function spaceBesideContent(\n graph: SceneGraph,\n parentId: string,\n size: { width: number; height: number },\n gap = DEFAULT_SPACE_GAP\n): EmptySpace {\n const obstacles = childBoxes(graph, parentId)\n return findEmptySpace({\n obstacles,\n ...size,\n anchor: obstacles.length > 0 ? computeBounds(obstacles) : null,\n gap,\n directions: ['right']\n })\n}\n\nconst sizeInput = (description: string) =>\n toolNumber(v.pipe(v.number(), v.minValue(0), v.description(description)))\n\nexport const findEmptySpaceTool = defineTool({\n name: 'find_empty_space',\n description:\n 'Find a free region of the canvas for new content of a given size, so it overlaps nothing. Without near_id it looks beside everything the parent holds; with near_id it looks next to that layer. direction \"any\" (default) takes the nearest free spot to the right, below, left, or above. Returns x and y in the parent’s coordinates, ready for render or create tools.',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({\n width: sizeInput('Width of the content to place'),\n height: sizeInput('Height of the content to place'),\n near_id: v.optional(\n v.pipe(v.string(), v.description('Layer to place the content next to (default: all content)'))\n ),\n parent_id: v.optional(\n v.pipe(v.string(), v.description('Parent to search (default: the current page)'))\n ),\n direction: v.optional(\n v.pipe(\n v.picklist(['any', ...SPACE_DIRECTIONS]),\n v.description('Which side of the anchor to search (default: any)')\n ),\n 'any'\n ),\n gap: v.optional(\n toolNumber(\n v.pipe(\n v.number(),\n v.minValue(0),\n v.description(`Room to keep around other layers (default: ${DEFAULT_SPACE_GAP})`)\n )\n ),\n DEFAULT_SPACE_GAP\n )\n }),\n execute: (figma, args) => {\n const graph = figma.graph\n const nearParentId = args.near_id ? graph.getNode(args.near_id)?.parentId : undefined\n if (args.near_id && !nearParentId) return { error: `Node \"${args.near_id}\" not found` }\n const parentId = args.parent_id ?? nearParentId ?? figma.currentPage.id\n const parent = graph.getNode(parentId)\n if (!parent || (parent.type !== 'CANVAS' && !findPageId(graph, parentId))) {\n return { error: `Parent \"${parentId}\" not found` }\n }\n if (parent.layoutMode !== 'NONE' && parent.type !== 'CANVAS') {\n return { error: `${parent.name} places its children with auto layout; append to it instead` }\n }\n if (args.near_id && nearParentId !== parentId) {\n return { error: `Node \"${args.near_id}\" is not a child of \"${parentId}\"` }\n }\n const obstacles = childBoxes(graph, parentId)\n const near = args.near_id ? graph.getNode(args.near_id) : undefined\n let anchor = obstacles.length > 0 ? computeBounds(obstacles) : null\n if (near) anchor = getAxisAlignedBoundsInParent([near], parentId, graph)\n const space = findEmptySpace({\n obstacles,\n width: args.width,\n height: args.height,\n anchor,\n gap: args.gap,\n directions: args.direction === 'any' ? SPACE_DIRECTIONS : [args.direction]\n })\n // Whole pixels, rounded away from what the space was found beside.\n const round = (value: number, away: SpaceDirection) =>\n space.direction === away ? Math.floor(value) : Math.ceil(value)\n return {\n parent_id: parentId,\n x: round(space.x, 'left'),\n y: round(space.y, 'above'),\n width: args.width,\n height: args.height,\n ...(space.direction ? { direction: space.direction } : {})\n }\n }\n})\n"],"mappings":";;;;;;AAUA,MAAM,mBAAmB;CAAC;CAAS;CAAS;CAAQ;AAAO;;AAI3D,MAAa,oBAAoB;;AAkBjC,SAAgB,aAAa,MAAY,UAAgB,KAAsB;CAC7E,OACE,KAAK,IAAI,SAAS,IAAI,SAAS,QAAQ,OACvC,KAAK,IAAI,KAAK,QAAQ,MAAM,SAAS,KACrC,KAAK,IAAI,SAAS,IAAI,SAAS,SAAS,OACxC,KAAK,IAAI,KAAK,SAAS,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G;EAE3E,MAAM,YAAY,WAAW,OAAO,QAAQ;EAC5C,MAAM,OAAO,KAAK,UAAU,MAAM,QAAQ,KAAK,OAAO,IAAI,KAAA;EAC1D,IAAI,SAAS,UAAU,SAAS,IAAI,cAAc,SAAS,IAAI;EAC/D,IAAI,MAAM,SAAS,6BAA6B,CAAC,IAAI,GAAG,UAAU,KAAK;EACvE,MAAM,QAAQ,eAAe;GAC3B;GACA,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb;GACA,KAAK,KAAK;GACV,YAAY,KAAK,cAAc,QAAQ,mBAAmB,CAAC,KAAK,SAAS;EAC3E,CAAC;EAED,MAAM,SAAS,OAAe,SAC5B,MAAM,cAAc,OAAO,KAAK,MAAM,KAAK,IAAI,KAAK,KAAK,KAAK;EAChE,OAAO;GACL,WAAW;GACX,GAAG,MAAM,MAAM,GAAG,MAAM;GACxB,GAAG,MAAM,MAAM,GAAG,OAAO;GACzB,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,GAAI,MAAM,YAAY,EAAE,WAAW,MAAM,UAAU,IAAI,CAAC;EAC1D;CACF;AACF,CAAC"}
|
package/dist/tools/read.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getComponents } from "./read/components.js";
|
|
2
|
+
import { getCSS } from "./read/css.js";
|
|
2
3
|
import { insertLibraryComponent, listLibraries } from "./read/libraries.js";
|
|
3
4
|
import { getFontStatus, listAvailableFonts, listFonts } from "./read/fonts.js";
|
|
4
5
|
import { diffJSX, getJSX } from "./read/jsx.js";
|
|
@@ -8,4 +9,4 @@ import { queryNodes } from "./read/query.js";
|
|
|
8
9
|
import { getReactions } from "./read/reactions.js";
|
|
9
10
|
import { getSelection, selectNodes } from "./read/selection.js";
|
|
10
11
|
import { findEmptySpaceTool } from "./read/space.js";
|
|
11
|
-
export { diffJSX, findEmptySpaceTool, findNodes, getComponents, getCurrentPage, getFontStatus, getJSX, getNode, getPageTree, getReactions, getSelection, insertLibraryComponent, listAvailableFonts, listFonts, listLibraries, listPages, pageBounds, queryNodes, selectNodes, switchPage };
|
|
12
|
+
export { diffJSX, findEmptySpaceTool, findNodes, getCSS, getComponents, getCurrentPage, getFontStatus, getJSX, getNode, getPageTree, getReactions, getSelection, insertLibraryComponent, listAvailableFonts, listFonts, listLibraries, listPages, pageBounds, queryNodes, selectNodes, switchPage };
|
package/dist/tools/read.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { findEmptySpaceTool } from "./read/space.js";
|
|
2
2
|
import { getComponents } from "./read/components.js";
|
|
3
|
+
import { getCSS } from "./read/css.js";
|
|
3
4
|
import { insertLibraryComponent, listLibraries } from "./read/libraries.js";
|
|
4
5
|
import { getFontStatus, listAvailableFonts, listFonts } from "./read/fonts.js";
|
|
5
6
|
import { diffJSX, getJSX } from "./read/jsx.js";
|
|
@@ -8,4 +9,4 @@ import { getCurrentPage, listPages, pageBounds, switchPage } from "./read/pages.
|
|
|
8
9
|
import { queryNodes } from "./read/query.js";
|
|
9
10
|
import { getReactions } from "./read/reactions.js";
|
|
10
11
|
import { getSelection, selectNodes } from "./read/selection.js";
|
|
11
|
-
export { diffJSX, findEmptySpaceTool, findNodes, getComponents, getCurrentPage, getFontStatus, getJSX, getNode, getPageTree, getReactions, getSelection, insertLibraryComponent, listAvailableFonts, listFonts, listLibraries, listPages, pageBounds, queryNodes, selectNodes, switchPage };
|
|
12
|
+
export { diffJSX, findEmptySpaceTool, findNodes, getCSS, getComponents, getCurrentPage, getFontStatus, getJSX, getNode, getPageTree, getReactions, getSelection, insertLibraryComponent, listAvailableFonts, listFonts, listLibraries, listPages, pageBounds, queryNodes, selectNodes, switchPage };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ToolDef } from "../schema.js";
|
|
2
2
|
//#region src/tools/registry/core.d.ts
|
|
3
3
|
/**
|
|
4
|
-
* Core tools registered by default in AI chat (
|
|
4
|
+
* Core tools registered by default in AI chat (28 tools, ~5K schema tokens).
|
|
5
5
|
* Covers 90%+ of design sessions: render, describe, modify, structure, and diff checks.
|
|
6
6
|
*/
|
|
7
7
|
declare const CORE_TOOLS: ToolDef[];
|
|
@@ -11,6 +11,7 @@ import { setLayout, setLayoutChild } from "../modify/layout.js";
|
|
|
11
11
|
import { setText, setTextProperties } from "../modify/text.js";
|
|
12
12
|
import { setFill, setStroke } from "../modify/paint.js";
|
|
13
13
|
import { updateNode } from "../modify/update.js";
|
|
14
|
+
import { getCSS } from "../read/css.js";
|
|
14
15
|
import { diffJSX, getJSX } from "../read/jsx.js";
|
|
15
16
|
import { findNodes, getNode } from "../read/nodes.js";
|
|
16
17
|
import { getSelection } from "../read/selection.js";
|
|
@@ -21,7 +22,7 @@ import { batchUpdate } from "../structure/batch.js";
|
|
|
21
22
|
import { viewportZoomToFit } from "../vector/viewport.js";
|
|
22
23
|
//#region src/tools/registry/core.ts
|
|
23
24
|
/**
|
|
24
|
-
* Core tools registered by default in AI chat (
|
|
25
|
+
* Core tools registered by default in AI chat (28 tools, ~5K schema tokens).
|
|
25
26
|
* Covers 90%+ of design sessions: render, describe, modify, structure, and diff checks.
|
|
26
27
|
*/
|
|
27
28
|
const CORE_TOOLS = [
|
|
@@ -29,6 +30,7 @@ const CORE_TOOLS = [
|
|
|
29
30
|
getNode,
|
|
30
31
|
findNodes,
|
|
31
32
|
getJSX,
|
|
33
|
+
getCSS,
|
|
32
34
|
render,
|
|
33
35
|
updateNode,
|
|
34
36
|
setLayout,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","names":[],"sources":["../../../src/tools/registry/core.ts"],"sourcesContent":["import { diffChanges, diffCreate, diffVisual, evalCode } from '#core/tools/analyze'\nimport { checkResponsive } from '#core/tools/analyze/responsive'\nimport { calc } from '#core/tools/calc'\nimport { render } from '#core/tools/create'\nimport { describe } from '#core/tools/describe'\nimport {\n setFill,\n setLayout,\n setLayoutChild,\n setRadius,\n setStroke,\n setText,\n setTextProperties,\n updateNode\n} from '#core/tools/modify'\nimport { diffJSX, findNodes, getJSX, getNode, getSelection } from '#core/tools/read'\nimport type { ToolDef } from '#core/tools/schema'\nimport { stockPhoto } from '#core/tools/stock-photo'\nimport { batchUpdate, deleteNode, nodeResize, reparentNode } from '#core/tools/structure'\nimport { viewportZoomToFit } from '#core/tools/vector'\n\n/**\n * Core tools registered by default in AI chat (
|
|
1
|
+
{"version":3,"file":"core.js","names":[],"sources":["../../../src/tools/registry/core.ts"],"sourcesContent":["import { diffChanges, diffCreate, diffVisual, evalCode } from '#core/tools/analyze'\nimport { checkResponsive } from '#core/tools/analyze/responsive'\nimport { calc } from '#core/tools/calc'\nimport { render } from '#core/tools/create'\nimport { describe } from '#core/tools/describe'\nimport {\n setFill,\n setLayout,\n setLayoutChild,\n setRadius,\n setStroke,\n setText,\n setTextProperties,\n updateNode\n} from '#core/tools/modify'\nimport { diffJSX, findNodes, getCSS, getJSX, getNode, getSelection } from '#core/tools/read'\nimport type { ToolDef } from '#core/tools/schema'\nimport { stockPhoto } from '#core/tools/stock-photo'\nimport { batchUpdate, deleteNode, nodeResize, reparentNode } from '#core/tools/structure'\nimport { viewportZoomToFit } from '#core/tools/vector'\n\n/**\n * Core tools registered by default in AI chat (28 tools, ~5K schema tokens).\n * Covers 90%+ of design sessions: render, describe, modify, structure, and diff checks.\n */\nexport const CORE_TOOLS: ToolDef[] = [\n // Read\n getSelection,\n getNode,\n findNodes,\n getJSX,\n getCSS,\n // Create\n render,\n // Modify\n updateNode,\n setLayout,\n setLayoutChild,\n setRadius,\n setFill,\n setStroke,\n setText,\n setTextProperties,\n // Structure\n deleteNode,\n reparentNode,\n nodeResize,\n batchUpdate,\n // Stock photos\n stockPhoto,\n // Inspect & utility\n describe,\n diffChanges,\n diffCreate,\n diffJSX,\n diffVisual,\n checkResponsive,\n calc,\n evalCode,\n viewportZoomToFit\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,aAAwB;CAEnC;CACA;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
package/dist/tools/schema.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FigmaFontNameInput } from "../figma-api/fonts/names.js";
|
|
2
2
|
import { FigmaNodeProxy } from "../figma-api/proxy.js";
|
|
3
3
|
import { FigmaAPI } from "../figma-api/index.js";
|
|
4
|
-
import { SceneNode } from "@pairdraw/scene-graph";
|
|
4
|
+
import { DocumentColorSpace, SceneNode } from "@pairdraw/scene-graph";
|
|
5
5
|
import * as v from "valibot";
|
|
6
6
|
import { Color } from "@pairdraw/scene-graph/primitives";
|
|
7
7
|
//#region src/tools/schema.d.ts
|
|
@@ -107,14 +107,14 @@ declare function nodeSummary(node: FigmaNodeProxy): {
|
|
|
107
107
|
* used to paint black and report success. Read through `tryParseColor`, since a published schema
|
|
108
108
|
* cannot express what the parser accepts.
|
|
109
109
|
*/
|
|
110
|
-
declare function parseToolColor(value: string): Color | {
|
|
110
|
+
declare function parseToolColor(value: string, profile?: DocumentColorSpace): Color | {
|
|
111
111
|
error: string;
|
|
112
112
|
};
|
|
113
113
|
/**
|
|
114
114
|
* A colour the caller may leave out. Missing stays missing; text that is not a colour is the
|
|
115
115
|
* same refusal `parseToolColor` gives, so each tool does not repeat that check.
|
|
116
116
|
*/
|
|
117
|
-
declare function parseOptionalToolColor(value: string | undefined): {
|
|
117
|
+
declare function parseOptionalToolColor(value: string | undefined, profile?: DocumentColorSpace): {
|
|
118
118
|
color: Color | undefined;
|
|
119
119
|
} | {
|
|
120
120
|
error: string;
|
|
@@ -137,6 +137,8 @@ declare const positionInputs: {
|
|
|
137
137
|
};
|
|
138
138
|
/** Reuse a native number schema for both numeric and numeric-string agent inputs. */
|
|
139
139
|
declare function toolNumber(schema?: v.GenericSchema<number, number>): v.UnionSchema<[v.SchemaWithPipe<readonly [v.GenericSchema<number, number>, v.MinValueAction<number, number, undefined>, v.MaxValueAction<number, number, undefined>]>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "Expected a nonblank numeric string">, v.DescriptionAction<string, string>, v.TransformAction<any, number>, v.SchemaWithPipe<readonly [v.GenericSchema<number, number>, v.MinValueAction<number, number, undefined>, v.MaxValueAction<number, number, undefined>]>]>], undefined>;
|
|
140
|
+
/** `ids`: several node IDs in one call; the description names what they point at. */
|
|
141
|
+
declare function nodeIdsField(description: string): v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.StringSchema<undefined>, undefined>, v.MinLengthAction<string[], 1, undefined>, v.DescriptionAction<string[], string>]>, undefined>;
|
|
140
142
|
//#endregion
|
|
141
|
-
export { NodeNotFoundError, ToolCapability, ToolDef, ToolExecution, ToolExposure, ToolInterface, defineTool, getRawNodeOrError, isAtomicTool, isToolExposed, nodeComparisonInputSchema, nodeIdInputSchema, nodeInputSchema, nodeNotFound, nodeSummary, nodeToResult, nodeTraversalInput, parseOptionalToolColor, parseToolArgs, parseToolColor, positionInputs, requireNode, requireNodes, toolChangesDocument, toolFailure, toolNumber };
|
|
143
|
+
export { NodeNotFoundError, ToolCapability, ToolDef, ToolExecution, ToolExposure, ToolInterface, defineTool, getRawNodeOrError, isAtomicTool, isToolExposed, nodeComparisonInputSchema, nodeIdInputSchema, nodeIdsField, nodeInputSchema, nodeNotFound, nodeSummary, nodeToResult, nodeTraversalInput, parseOptionalToolColor, parseToolArgs, parseToolColor, positionInputs, requireNode, requireNodes, toolChangesDocument, toolFailure, toolNumber };
|
|
142
144
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/tools/schema.ts"],"mappings":";;;;;;;KAgBY;KAUA;EACN;EAAc;;EAEd;EACA;;;;;EAKA;;KAGM;KACA,eAAe,QAAQ,OAAO;UAEhC;EACR;EACA;EACA,WAAW;;EA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BAMG,WAAW,SAAQ,EAAE,gCAA0C,EAAA,aAAA,EAAA,yBAAA,EAAA,+BAAA,EAAA,2CAAA,EAAA,6CAAA,EAAA,yBAAA,EAAA,yBAAA,EAAA,2DAAA,EAAA,mCAAA,EAAA,8BAAA,EAAA,yBAAA,EAAA,+BAAA,EAAA,2CAAA,EAAA;;iBAgB/D,aAAa,sBAAmB,EAAA,eAAA,EAAA,yBAAA,EAAA,YAAA,EAAA,qCAAA,EAAA,yCAAA,EAAA"}
|
package/dist/tools/schema.js
CHANGED
|
@@ -191,16 +191,16 @@ function nodeSummary(node) {
|
|
|
191
191
|
* used to paint black and report success. Read through `tryParseColor`, since a published schema
|
|
192
192
|
* cannot express what the parser accepts.
|
|
193
193
|
*/
|
|
194
|
-
function parseToolColor(value) {
|
|
195
|
-
return tryParseColor(value) ?? { error: `"${value}" is not a color; use a hex value, a color name, or a color function` };
|
|
194
|
+
function parseToolColor(value, profile = "srgb") {
|
|
195
|
+
return tryParseColor(value, profile) ?? { error: `"${value}" is not a color; use a hex value, a color name, or a color function` };
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
198
198
|
* A colour the caller may leave out. Missing stays missing; text that is not a colour is the
|
|
199
199
|
* same refusal `parseToolColor` gives, so each tool does not repeat that check.
|
|
200
200
|
*/
|
|
201
|
-
function parseOptionalToolColor(value) {
|
|
201
|
+
function parseOptionalToolColor(value, profile = "srgb") {
|
|
202
202
|
if (value === void 0) return { color: void 0 };
|
|
203
|
-
const parsed = parseToolColor(value);
|
|
203
|
+
const parsed = parseToolColor(value, profile);
|
|
204
204
|
if ("error" in parsed) return parsed;
|
|
205
205
|
return { color: parsed };
|
|
206
206
|
}
|
|
@@ -225,7 +225,11 @@ function toolNumber(schema = v.number()) {
|
|
|
225
225
|
const finite = v.pipe(schema, v.minValue(-Number.MAX_VALUE), v.maxValue(Number.MAX_VALUE));
|
|
226
226
|
return v.union([finite, v.pipe(v.string(), v.regex(/\S/, "Expected a nonblank numeric string"), v.description(v.getDescription(schema) ?? "Numeric value"), v.transform(Number), finite)]);
|
|
227
227
|
}
|
|
228
|
+
/** `ids`: several node IDs in one call; the description names what they point at. */
|
|
229
|
+
function nodeIdsField(description) {
|
|
230
|
+
return v.optional(v.pipe(v.array(v.string()), v.minLength(1), v.description(description)));
|
|
231
|
+
}
|
|
228
232
|
//#endregion
|
|
229
|
-
export { NodeNotFoundError, defineTool, getRawNodeOrError, isAtomicTool, isToolExposed, nodeComparisonInputSchema, nodeIdInputSchema, nodeInputSchema, nodeNotFound, nodeSummary, nodeToResult, nodeTraversalInput, parseOptionalToolColor, parseToolArgs, parseToolColor, positionInputs, requireNode, requireNodes, toolChangesDocument, toolFailure, toolNumber };
|
|
233
|
+
export { NodeNotFoundError, defineTool, getRawNodeOrError, isAtomicTool, isToolExposed, nodeComparisonInputSchema, nodeIdInputSchema, nodeIdsField, nodeInputSchema, nodeNotFound, nodeSummary, nodeToResult, nodeTraversalInput, parseOptionalToolColor, parseToolArgs, parseToolColor, positionInputs, requireNode, requireNodes, toolChangesDocument, toolFailure, toolNumber };
|
|
230
234
|
|
|
231
235
|
//# sourceMappingURL=schema.js.map
|