@pairdraw/core 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/noise/render.js +1 -1
- package/dist/canvas/noise/render.js.map +1 -1
- package/dist/canvas/noise/shader.d.ts +6 -3
- package/dist/canvas/noise/shader.d.ts.map +1 -1
- package/dist/canvas/noise/shader.js +12 -7
- package/dist/canvas/noise/shader.js.map +1 -1
- package/dist/canvas/noise/tile.d.ts.map +1 -1
- package/dist/canvas/noise/tile.js +2 -1
- package/dist/canvas/noise/tile.js.map +1 -1
- package/dist/canvas/renderer/colors.d.ts +20 -5
- package/dist/canvas/renderer/colors.d.ts.map +1 -1
- package/dist/canvas/renderer/colors.js +48 -42
- package/dist/canvas/renderer/colors.js.map +1 -1
- package/dist/canvas/renderer/document-surface.d.ts +25 -0
- package/dist/canvas/renderer/document-surface.d.ts.map +1 -0
- package/dist/canvas/renderer/document-surface.js +46 -0
- package/dist/canvas/renderer/document-surface.js.map +1 -0
- package/dist/canvas/renderer/fonts.d.ts.map +1 -1
- package/dist/canvas/renderer/fonts.js +6 -4
- package/dist/canvas/renderer/fonts.js.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +4 -3
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +1 -0
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +23 -2
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/retained-backing.d.ts.map +1 -1
- package/dist/canvas/renderer/retained-backing.js +2 -1
- package/dist/canvas/renderer/retained-backing.js.map +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.js +2 -7
- package/dist/canvas/renderer/tiles/surface-pool.js.map +1 -1
- package/dist/canvas/renderer.d.ts +20 -2
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +28 -4
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +4 -3
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/shaders/effect.d.ts.map +1 -1
- package/dist/canvas/shaders/effect.js +2 -1
- package/dist/canvas/shaders/effect.js.map +1 -1
- package/dist/canvas/shadows/shape.d.ts.map +1 -1
- package/dist/canvas/shadows/shape.js +4 -2
- package/dist/canvas/shadows/shape.js.map +1 -1
- package/dist/canvas/shadows.d.ts.map +1 -1
- package/dist/canvas/shadows.js +4 -2
- package/dist/canvas/shadows.js.map +1 -1
- package/dist/canvas/text/decorations.d.ts +2 -2
- package/dist/canvas/text/decorations.d.ts.map +1 -1
- package/dist/canvas/text/decorations.js +5 -5
- package/dist/canvas/text/decorations.js.map +1 -1
- package/dist/canvas/text/index.js +1 -1
- package/dist/canvas/text/index.js.map +1 -1
- package/dist/canvas/text/paragraph/index.d.ts +2 -2
- package/dist/canvas/text/paragraph/index.d.ts.map +1 -1
- package/dist/canvas/text/paragraph/index.js +16 -5
- package/dist/canvas/text/paragraph/index.js.map +1 -1
- package/dist/canvas/text/renderer.d.ts +2 -1
- package/dist/canvas/text/renderer.d.ts.map +1 -1
- package/dist/canvas/text/shape.js +4 -4
- package/dist/canvas/text/shape.js.map +1 -1
- package/dist/canvas/texture.d.ts.map +1 -1
- package/dist/canvas/texture.js +2 -1
- package/dist/canvas/texture.js.map +1 -1
- package/dist/design-memory/rules.js +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/clipboard/assets.d.ts.map +1 -1
- package/dist/editor/clipboard/assets.js +2 -2
- package/dist/editor/clipboard/assets.js.map +1 -1
- package/dist/editor/clipboard/component-matches.d.ts +13 -0
- package/dist/editor/clipboard/component-matches.d.ts.map +1 -0
- package/dist/editor/clipboard/component-matches.js +50 -0
- package/dist/editor/clipboard/component-matches.js.map +1 -0
- package/dist/editor/clipboard/dependencies.d.ts +7 -0
- package/dist/editor/clipboard/dependencies.d.ts.map +1 -1
- package/dist/editor/clipboard/dependencies.js +5 -0
- package/dist/editor/clipboard/dependencies.js.map +1 -1
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +48 -19
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/components/properties.d.ts.map +1 -1
- package/dist/editor/components/properties.js +3 -3
- package/dist/editor/components/properties.js.map +1 -1
- package/dist/editor/create.d.ts +1 -1
- package/dist/editor/eyedropper.d.ts +1 -1
- package/dist/editor/eyedropper.d.ts.map +1 -1
- package/dist/editor/eyedropper.js +6 -3
- package/dist/editor/eyedropper.js.map +1 -1
- package/dist/editor/history/atomic-tool.d.ts.map +1 -1
- package/dist/editor/history/atomic-tool.js +3 -2
- package/dist/editor/history/atomic-tool.js.map +1 -1
- package/dist/editor/shapes/pencil.js +1 -1
- package/dist/editor/structure/state.d.ts.map +1 -1
- package/dist/editor/structure/state.js +2 -2
- package/dist/editor/structure/state.js.map +1 -1
- package/dist/editor/text.d.ts.map +1 -1
- package/dist/editor/text.js +2 -2
- package/dist/editor/text.js.map +1 -1
- package/dist/editor/variables.js +3 -3
- package/dist/editor/variables.js.map +1 -1
- package/dist/figma-api/fresh-read.d.ts +15 -0
- package/dist/figma-api/fresh-read.d.ts.map +1 -0
- package/dist/figma-api/fresh-read.js +54 -0
- package/dist/figma-api/fresh-read.js.map +1 -0
- package/dist/figma-api/graph-ref.d.ts +9 -0
- package/dist/figma-api/graph-ref.d.ts.map +1 -0
- package/dist/figma-api/graph-ref.js +14 -0
- package/dist/figma-api/graph-ref.js.map +1 -0
- package/dist/figma-api/index.d.ts +6 -1
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +12 -5
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/pending-layout.d.ts +3 -3
- package/dist/figma-api/pending-layout.d.ts.map +1 -1
- package/dist/figma-api/pending-layout.js +7 -3
- package/dist/figma-api/pending-layout.js.map +1 -1
- package/dist/figma-api/pending-sync.d.ts +1 -1
- package/dist/figma-api/pending-sync.d.ts.map +1 -1
- package/dist/figma-api/pending-sync.js +3 -1
- package/dist/figma-api/pending-sync.js.map +1 -1
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +3 -2
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +20 -4
- package/dist/figma-api/reactions.d.ts.map +1 -1
- package/dist/figma-api/reactions.js +49 -3
- package/dist/figma-api/reactions.js.map +1 -1
- package/dist/figma-api/variables/index.d.ts.map +1 -1
- package/dist/figma-api/variables/index.js +2 -2
- package/dist/figma-api/variables/index.js.map +1 -1
- package/dist/io/formats/design-tokens/css/known.js +1 -1
- package/dist/io/formats/design-tokens/css/known.js.map +1 -1
- package/dist/io/formats/design-tokens/css/read.d.ts +3 -1
- package/dist/io/formats/design-tokens/css/read.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/css/read.js +11 -5
- package/dist/io/formats/design-tokens/css/read.js.map +1 -1
- package/dist/io/formats/design-tokens/css/sync.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/css/sync.js +17 -4
- package/dist/io/formats/design-tokens/css/sync.js.map +1 -1
- package/dist/io/formats/design-tokens/css/values.d.ts +6 -5
- package/dist/io/formats/design-tokens/css/values.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/css/values.js +24 -8
- package/dist/io/formats/design-tokens/css/values.js.map +1 -1
- package/dist/io/formats/design-tokens/decode.d.ts +7 -6
- package/dist/io/formats/design-tokens/decode.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/decode.js +13 -12
- package/dist/io/formats/design-tokens/decode.js.map +1 -1
- package/dist/io/formats/design-tokens/export.js +3 -3
- package/dist/io/formats/design-tokens/export.js.map +1 -1
- package/dist/io/formats/design-tokens/plan/index.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/index.js +4 -3
- package/dist/io/formats/design-tokens/plan/index.js.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.js +9 -9
- package/dist/io/formats/design-tokens/plan/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/styles.d.ts +4 -4
- package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/styles.js +7 -7
- package/dist/io/formats/design-tokens/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/sync/drift.js +2 -2
- package/dist/io/formats/design-tokens/sync/drift.js.map +1 -1
- package/dist/io/formats/design-tokens/values.d.ts +10 -5
- package/dist/io/formats/design-tokens/values.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/values.js +13 -7
- package/dist/io/formats/design-tokens/values.js.map +1 -1
- package/dist/io/formats/drawio/label.js +1 -1
- package/dist/io/formats/drawio/paint.js +1 -1
- package/dist/io/formats/drawio/warnings.js +2 -2
- package/dist/io/formats/drawio/warnings.js.map +1 -1
- package/dist/io/formats/fig/export/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/index.js +15 -3
- package/dist/io/formats/fig/export/index.js.map +1 -1
- package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/patch/index.js +2 -1
- package/dist/io/formats/fig/export/patch/index.js.map +1 -1
- package/dist/io/formats/fig/export/setup.d.ts +7 -2
- package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
- package/dist/io/formats/fig/export/setup.js +12 -13
- package/dist/io/formats/fig/export/setup.js.map +1 -1
- package/dist/io/formats/fig/export/variables.d.ts.map +1 -1
- package/dist/io/formats/fig/export/variables.js +9 -7
- package/dist/io/formats/fig/export/variables.js.map +1 -1
- package/dist/io/formats/html/vectors.js +1 -0
- package/dist/io/formats/html/vectors.js.map +1 -1
- package/dist/io/formats/mermaid/layers.js +2 -2
- package/dist/io/formats/mermaid/layers.js.map +1 -1
- package/dist/io/formats/mermaid/styles.js +1 -1
- package/dist/io/formats/pdf/export.d.ts.map +1 -1
- package/dist/io/formats/pdf/export.js +1 -0
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/pdf/prepare.d.ts +4 -4
- package/dist/io/formats/pdf/prepare.d.ts.map +1 -1
- package/dist/io/formats/pdf/prepare.js +2 -2
- package/dist/io/formats/pdf/prepare.js.map +1 -1
- package/dist/io/formats/pen/index.js +4 -2
- package/dist/io/formats/pen/index.js.map +1 -1
- package/dist/io/formats/pptx/style.js +1 -1
- package/dist/io/formats/raster/render.d.ts +1 -1
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +9 -4
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts +6 -3
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +12 -11
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/effects.js +2 -2
- package/dist/io/formats/svg/effects.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts +5 -2
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +4 -2
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/filter.d.ts +4 -1
- package/dist/io/formats/svg/filter.d.ts.map +1 -1
- package/dist/io/formats/svg/filter.js +6 -2
- package/dist/io/formats/svg/filter.js.map +1 -1
- package/dist/io/formats/svg/grain.js +1 -1
- package/dist/io/formats/svg/grain.js.map +1 -1
- package/dist/io/formats/svg/import.d.ts +4 -2
- package/dist/io/formats/svg/import.d.ts.map +1 -1
- package/dist/io/formats/svg/import.js +2 -1
- package/dist/io/formats/svg/import.js.map +1 -1
- package/dist/io/formats/svg/text/export.d.ts.map +1 -1
- package/dist/io/formats/svg/text/export.js +8 -8
- package/dist/io/formats/svg/text/export.js.map +1 -1
- package/dist/io/formats/svg/text/layout.js +2 -2
- package/dist/io/formats/svg/text/layout.js.map +1 -1
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +1 -0
- package/dist/io/formats.js.map +1 -1
- package/dist/io/subgraph.d.ts.map +1 -1
- package/dist/io/subgraph.js +1 -1
- package/dist/io/subgraph.js.map +1 -1
- package/dist/io/types.d.ts +1 -1
- package/dist/kiwi/fig/session/options.d.ts +3 -0
- package/dist/kiwi/fig/session/options.d.ts.map +1 -1
- package/dist/kiwi/fig/session/options.js +4 -0
- package/dist/kiwi/fig/session/options.js.map +1 -1
- package/dist/layout/yoga-helpers.d.ts +2 -1
- package/dist/layout/yoga-helpers.d.ts.map +1 -1
- package/dist/layout/yoga-helpers.js +7 -1
- package/dist/layout/yoga-helpers.js.map +1 -1
- package/dist/layout.js +24 -1
- package/dist/layout.js.map +1 -1
- package/dist/lint/fixes.js +1 -1
- package/dist/lint/linter.js +2 -2
- package/dist/lint/linter.js.map +1 -1
- package/dist/pairdraw-api/comments.d.ts +4 -1
- package/dist/pairdraw-api/comments.d.ts.map +1 -1
- package/dist/pairdraw-api/comments.js +5 -0
- package/dist/pairdraw-api/comments.js.map +1 -1
- package/dist/pairdraw-api/index.d.ts +3 -3
- package/dist/pairdraw-api/index.d.ts.map +1 -1
- package/dist/pairdraw-api/index.js +5 -5
- package/dist/pairdraw-api/index.js.map +1 -1
- package/dist/pairdraw-api/nodes.d.ts +1 -1
- package/dist/prototype/scene.js +1 -1
- package/dist/rpc/analyze-commands.js +1 -1
- package/dist/rpc/read-commands.d.ts +2 -2
- package/dist/rpc/read-commands.js +3 -3
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/rpc/variables-command.js +2 -2
- package/dist/rpc/variables-command.js.map +1 -1
- package/dist/text/font/provider.d.ts +15 -0
- package/dist/text/font/provider.d.ts.map +1 -0
- package/dist/text/font/provider.js +18 -0
- package/dist/text/font/provider.js.map +1 -0
- package/dist/text/font/readiness.d.ts +32 -0
- package/dist/text/font/readiness.d.ts.map +1 -0
- package/dist/text/font/{status.js → readiness.js} +8 -4
- package/dist/text/font/readiness.js.map +1 -0
- package/dist/text/index.d.ts +4 -3
- package/dist/text/index.js +4 -3
- package/dist/text/prepare.d.ts +9 -4
- package/dist/text/prepare.d.ts.map +1 -1
- package/dist/text/prepare.js +9 -4
- package/dist/text/prepare.js.map +1 -1
- package/dist/tools/analyze/colors.js +1 -1
- package/dist/tools/analyze/responsive/index.js +7 -18
- package/dist/tools/analyze/responsive/index.js.map +1 -1
- package/dist/tools/analyze/responsive/widths.d.ts +27 -0
- package/dist/tools/analyze/responsive/widths.d.ts.map +1 -0
- package/dist/tools/analyze/responsive/widths.js +49 -0
- package/dist/tools/analyze/responsive/widths.js.map +1 -0
- package/dist/tools/analyze.d.ts +2 -1
- package/dist/tools/analyze.js +2 -1
- package/dist/tools/codegen/tokens.d.ts.map +1 -1
- package/dist/tools/codegen/tokens.js +2 -2
- package/dist/tools/codegen/tokens.js.map +1 -1
- package/dist/tools/comments.d.ts.map +1 -1
- package/dist/tools/comments.js +2 -2
- package/dist/tools/comments.js.map +1 -1
- package/dist/tools/component-catalog.d.ts.map +1 -1
- package/dist/tools/component-catalog.js +5 -3
- package/dist/tools/component-catalog.js.map +1 -1
- package/dist/tools/create/basic.js +1 -1
- package/dist/tools/create/behaviours.js +1 -1
- package/dist/tools/create/html.d.ts.map +1 -1
- package/dist/tools/create/html.js +1 -3
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.js +2 -2
- package/dist/tools/create/icons.js.map +1 -1
- package/dist/tools/create/mermaid.js +1 -1
- package/dist/tools/create/render.js +1 -1
- package/dist/tools/create/svg.js +5 -2
- package/dist/tools/create/svg.js.map +1 -1
- package/dist/tools/create/vector.js +3 -3
- package/dist/tools/create/vector.js.map +1 -1
- package/dist/tools/css/shorthand.d.ts +20 -0
- package/dist/tools/css/shorthand.d.ts.map +1 -0
- package/dist/tools/css/shorthand.js +54 -0
- package/dist/tools/css/shorthand.js.map +1 -0
- package/dist/tools/describe/index.js +2 -2
- package/dist/tools/describe/index.js.map +1 -1
- package/dist/tools/describe/issues.js +1 -1
- package/dist/tools/html-host.d.ts.map +1 -1
- package/dist/tools/html-host.js +5 -3
- package/dist/tools/html-host.js.map +1 -1
- package/dist/tools/image-ai/apply.d.ts.map +1 -1
- package/dist/tools/image-ai/apply.js +1 -3
- package/dist/tools/image-ai/apply.js.map +1 -1
- package/dist/tools/image-ai/generate.js +1 -1
- package/dist/tools/image-ai/service.d.ts.map +1 -1
- package/dist/tools/image-ai/service.js +5 -3
- package/dist/tools/image-ai/service.js.map +1 -1
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.js +2 -1
- package/dist/tools/modify/effects.js +1 -1
- package/dist/tools/modify/effects.js.map +1 -1
- package/dist/tools/modify/geometry.d.ts.map +1 -1
- package/dist/tools/modify/geometry.js +14 -3
- package/dist/tools/modify/geometry.js.map +1 -1
- package/dist/tools/modify/layout.d.ts.map +1 -1
- package/dist/tools/modify/layout.js +35 -8
- package/dist/tools/modify/layout.js.map +1 -1
- package/dist/tools/modify/matching.d.ts.map +1 -1
- package/dist/tools/modify/matching.js +10 -10
- package/dist/tools/modify/matching.js.map +1 -1
- package/dist/tools/modify/paint.d.ts.map +1 -1
- package/dist/tools/modify/paint.js +57 -5
- package/dist/tools/modify/paint.js.map +1 -1
- package/dist/tools/modify/reactions.d.ts.map +1 -1
- package/dist/tools/modify/reactions.js +2 -2
- package/dist/tools/modify/reactions.js.map +1 -1
- package/dist/tools/modify/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +3 -3
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/prompts/codegen.js +1 -1
- package/dist/tools/prompts/codegen.js.map +1 -1
- package/dist/tools/read/css.d.ts +14 -0
- package/dist/tools/read/css.d.ts.map +1 -0
- package/dist/tools/read/css.js +306 -0
- package/dist/tools/read/css.js.map +1 -0
- package/dist/tools/read/libraries.js +1 -1
- package/dist/tools/read/reactions.js +1 -1
- package/dist/tools/read/reactions.js.map +1 -1
- package/dist/tools/read/space.d.ts.map +1 -1
- package/dist/tools/read/space.js +0 -2
- package/dist/tools/read/space.js.map +1 -1
- package/dist/tools/read.d.ts +2 -1
- package/dist/tools/read.js +2 -1
- package/dist/tools/registry/core.d.ts +1 -1
- package/dist/tools/registry/core.js +3 -1
- package/dist/tools/registry/core.js.map +1 -1
- package/dist/tools/schema.d.ts +6 -4
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +9 -5
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/script/host.d.ts.map +1 -1
- package/dist/tools/script/host.js +5 -3
- package/dist/tools/script/host.js.map +1 -1
- package/dist/tools/variables/collections.js +1 -1
- package/dist/tools/variables/collections.js.map +1 -1
- package/dist/tools/variables/values.d.ts.map +1 -1
- package/dist/tools/variables/values.js +4 -4
- package/dist/tools/variables/values.js.map +1 -1
- package/dist/tools/vector/vectorize.d.ts.map +1 -1
- package/dist/tools/vector/vectorize.js +6 -4
- package/dist/tools/vector/vectorize.js.map +1 -1
- package/dist/tools/video-host.d.ts.map +1 -1
- package/dist/tools/video-host.js +5 -3
- package/dist/tools/video-host.js.map +1 -1
- package/dist/vector/vectorize/svg/gradients.d.ts +2 -2
- package/dist/vector/vectorize/svg/gradients.d.ts.map +1 -1
- package/dist/vector/vectorize/svg/gradients.js +5 -5
- package/dist/vector/vectorize/svg/gradients.js.map +1 -1
- package/dist/vector/vectorize/svg/to-vectors.d.ts +3 -1
- package/dist/vector/vectorize/svg/to-vectors.d.ts.map +1 -1
- package/dist/vector/vectorize/svg/to-vectors.js +13 -12
- package/dist/vector/vectorize/svg/to-vectors.js.map +1 -1
- package/package.json +9 -9
- package/src/canvas/noise/render.ts +1 -1
- package/src/canvas/noise/shader.ts +13 -5
- package/src/canvas/noise/tile.ts +2 -1
- package/src/canvas/renderer/colors.ts +76 -50
- package/src/canvas/renderer/document-surface.ts +53 -0
- package/src/canvas/renderer/fonts.ts +6 -4
- package/src/canvas/renderer/lifecycle.ts +4 -4
- package/src/canvas/renderer/methods.ts +1 -0
- package/src/canvas/renderer/pipeline.ts +21 -3
- package/src/canvas/renderer/retained-backing.ts +2 -1
- package/src/canvas/renderer/tiles/surface-pool.ts +9 -7
- package/src/canvas/renderer.ts +36 -11
- package/src/canvas/scene.ts +4 -3
- package/src/canvas/shaders/effect.ts +2 -1
- package/src/canvas/shadows/shape.ts +4 -2
- package/src/canvas/shadows.ts +5 -2
- package/src/canvas/text/decorations.ts +15 -5
- package/src/canvas/text/index.ts +9 -1
- package/src/canvas/text/paragraph/index.ts +16 -6
- package/src/canvas/text/renderer.ts +2 -1
- package/src/canvas/text/shape.ts +4 -4
- package/src/canvas/texture.ts +2 -1
- package/src/editor/clipboard/assets.ts +6 -2
- package/src/editor/clipboard/component-matches.ts +65 -0
- package/src/editor/clipboard/dependencies.ts +22 -1
- package/src/editor/clipboard.ts +74 -20
- package/src/editor/components/properties.ts +3 -2
- package/src/editor/eyedropper.ts +14 -4
- package/src/editor/history/atomic-tool.ts +3 -2
- package/src/editor/structure/state.ts +2 -1
- package/src/editor/text.ts +2 -1
- package/src/editor/variables.ts +3 -3
- package/src/figma-api/fresh-read.ts +57 -0
- package/src/figma-api/graph-ref.ts +13 -0
- package/src/figma-api/index.ts +12 -4
- package/src/figma-api/pending-layout.ts +7 -3
- package/src/figma-api/pending-sync.ts +4 -1
- package/src/figma-api/proxy.ts +2 -1
- package/src/figma-api/reactions.ts +91 -10
- package/src/figma-api/variables/index.ts +5 -4
- package/src/io/formats/design-tokens/css/known.ts +1 -1
- package/src/io/formats/design-tokens/css/read.ts +20 -7
- package/src/io/formats/design-tokens/css/sync.ts +9 -4
- package/src/io/formats/design-tokens/css/values.ts +37 -9
- package/src/io/formats/design-tokens/decode.ts +17 -12
- package/src/io/formats/design-tokens/export.ts +3 -3
- package/src/io/formats/design-tokens/plan/index.ts +6 -5
- package/src/io/formats/design-tokens/plan/styles.ts +37 -10
- package/src/io/formats/design-tokens/styles.ts +10 -7
- package/src/io/formats/design-tokens/sync/drift.ts +6 -4
- package/src/io/formats/design-tokens/values.ts +15 -8
- package/src/io/formats/drawio/warnings.ts +2 -2
- package/src/io/formats/fig/export/index.ts +36 -3
- package/src/io/formats/fig/export/patch/index.ts +4 -1
- package/src/io/formats/fig/export/setup.ts +25 -15
- package/src/io/formats/fig/export/variables.ts +17 -6
- package/src/io/formats/html/vectors.ts +1 -0
- package/src/io/formats/mermaid/layers.ts +2 -2
- package/src/io/formats/pdf/export.ts +1 -0
- package/src/io/formats/pdf/prepare.ts +6 -6
- package/src/io/formats/pen/index.ts +5 -2
- package/src/io/formats/raster/render.ts +12 -4
- package/src/io/formats/svg/defs.ts +26 -14
- package/src/io/formats/svg/effects.ts +2 -2
- package/src/io/formats/svg/export.ts +17 -3
- package/src/io/formats/svg/filter.ts +12 -2
- package/src/io/formats/svg/grain.ts +1 -1
- package/src/io/formats/svg/import.ts +6 -3
- package/src/io/formats/svg/text/export.ts +10 -8
- package/src/io/formats/svg/text/layout.ts +2 -2
- package/src/io/formats.ts +8 -1
- package/src/io/subgraph.ts +4 -1
- package/src/kiwi/fig/session/options.ts +4 -1
- package/src/layout/yoga-helpers.ts +8 -0
- package/src/layout.ts +47 -1
- package/src/lint/linter.ts +1 -1
- package/src/pairdraw-api/comments.ts +6 -0
- package/src/pairdraw-api/index.ts +7 -9
- package/src/rpc/read-commands.ts +4 -4
- package/src/rpc/variables-command.ts +2 -2
- package/src/text/font/provider.ts +26 -0
- package/src/text/font/{status.ts → readiness.ts} +13 -9
- package/src/text/index.ts +2 -1
- package/src/text/prepare.ts +9 -4
- package/src/tools/analyze/responsive/index.ts +8 -15
- package/src/tools/analyze/responsive/widths.ts +63 -0
- package/src/tools/analyze.ts +2 -0
- package/src/tools/codegen/tokens.ts +4 -2
- package/src/tools/comments.ts +6 -4
- package/src/tools/component-catalog.ts +5 -3
- package/src/tools/create/html.ts +0 -3
- package/src/tools/create/icons.ts +1 -1
- package/src/tools/create/svg.ts +4 -1
- package/src/tools/create/vector.ts +2 -2
- package/src/tools/css/shorthand.ts +64 -0
- package/src/tools/describe/index.ts +2 -8
- package/src/tools/html-host.ts +5 -3
- package/src/tools/image-ai/apply.ts +0 -2
- package/src/tools/image-ai/service.ts +5 -3
- package/src/tools/index.ts +2 -0
- package/src/tools/modify/effects.ts +1 -1
- package/src/tools/modify/geometry.ts +16 -3
- package/src/tools/modify/layout.ts +47 -13
- package/src/tools/modify/matching.ts +14 -11
- package/src/tools/modify/paint.ts +85 -5
- package/src/tools/modify/reactions.ts +3 -2
- package/src/tools/modify/text.ts +15 -11
- package/src/tools/prompts/codegen.md +2 -1
- package/src/tools/read/css.ts +365 -0
- package/src/tools/read/reactions.ts +3 -2
- package/src/tools/read/space.ts +0 -2
- package/src/tools/read.ts +1 -0
- package/src/tools/registry/core.ts +3 -2
- package/src/tools/schema.ts +14 -5
- package/src/tools/script/host.ts +6 -3
- package/src/tools/variables/collections.ts +1 -1
- package/src/tools/variables/values.ts +16 -5
- package/src/tools/vector/vectorize.ts +10 -4
- package/src/tools/video-host.ts +5 -3
- package/src/vector/vectorize/svg/gradients.ts +8 -5
- package/src/vector/vectorize/svg/to-vectors.ts +48 -14
- package/dist/text/font/status.d.ts +0 -28
- package/dist/text/font/status.d.ts.map +0 -1
- package/dist/text/font/status.js.map +0 -1
|
@@ -14,7 +14,12 @@ declare const reactionSchema: v.StrictObjectSchema<{
|
|
|
14
14
|
}, undefined>], undefined>;
|
|
15
15
|
readonly actions: v.SchemaWithPipe<readonly [v.ArraySchema<v.VariantSchema<"type", [v.StrictObjectSchema<{
|
|
16
16
|
readonly type: v.LiteralSchema<"NODE", undefined>;
|
|
17
|
-
readonly destinationId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.DescriptionAction<string, string>]>;
|
|
17
|
+
readonly destinationId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.DescriptionAction<string, string>]>, undefined>;
|
|
18
|
+
readonly variantProperties: v.OptionalSchema<v.SchemaWithPipe<readonly [v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, v.MinEntriesAction<{
|
|
19
|
+
[x: string]: string;
|
|
20
|
+
}, 1, undefined>, v.DescriptionAction<{
|
|
21
|
+
[x: string]: string;
|
|
22
|
+
}, string>]>, undefined>;
|
|
18
23
|
readonly navigation: v.PicklistSchema<("OVERLAY" | "NAVIGATE" | "CHANGE_TO" | "SCROLL_TO")[], undefined>;
|
|
19
24
|
readonly transition: v.OptionalSchema<v.StrictObjectSchema<{
|
|
20
25
|
readonly type: v.PicklistSchema<("INSTANT" | "DISSOLVE" | "SMART_ANIMATE")[], undefined>;
|
|
@@ -33,7 +38,10 @@ declare const reactionSchema: v.StrictObjectSchema<{
|
|
|
33
38
|
readonly type: v.LiteralSchema<"CLOSE", undefined>;
|
|
34
39
|
}, undefined>], undefined>, undefined>, v.MinLengthAction<({
|
|
35
40
|
type: "NODE";
|
|
36
|
-
destinationId
|
|
41
|
+
destinationId?: string | undefined;
|
|
42
|
+
variantProperties?: {
|
|
43
|
+
[x: string]: string;
|
|
44
|
+
} | undefined;
|
|
37
45
|
navigation: "OVERLAY" | "NAVIGATE" | "CHANGE_TO" | "SCROLL_TO";
|
|
38
46
|
transition: {
|
|
39
47
|
type: "INSTANT" | "DISSOLVE" | "SMART_ANIMATE";
|
|
@@ -63,7 +71,12 @@ declare const figmaReactionsSchema: v.ArraySchema<v.StrictObjectSchema<{
|
|
|
63
71
|
}, undefined>], undefined>;
|
|
64
72
|
readonly actions: v.SchemaWithPipe<readonly [v.ArraySchema<v.VariantSchema<"type", [v.StrictObjectSchema<{
|
|
65
73
|
readonly type: v.LiteralSchema<"NODE", undefined>;
|
|
66
|
-
readonly destinationId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.DescriptionAction<string, string>]>;
|
|
74
|
+
readonly destinationId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.DescriptionAction<string, string>]>, undefined>;
|
|
75
|
+
readonly variantProperties: v.OptionalSchema<v.SchemaWithPipe<readonly [v.RecordSchema<v.StringSchema<undefined>, v.StringSchema<undefined>, undefined>, v.MinEntriesAction<{
|
|
76
|
+
[x: string]: string;
|
|
77
|
+
}, 1, undefined>, v.DescriptionAction<{
|
|
78
|
+
[x: string]: string;
|
|
79
|
+
}, string>]>, undefined>;
|
|
67
80
|
readonly navigation: v.PicklistSchema<("OVERLAY" | "NAVIGATE" | "CHANGE_TO" | "SCROLL_TO")[], undefined>;
|
|
68
81
|
readonly transition: v.OptionalSchema<v.StrictObjectSchema<{
|
|
69
82
|
readonly type: v.PicklistSchema<("INSTANT" | "DISSOLVE" | "SMART_ANIMATE")[], undefined>;
|
|
@@ -82,7 +95,10 @@ declare const figmaReactionsSchema: v.ArraySchema<v.StrictObjectSchema<{
|
|
|
82
95
|
readonly type: v.LiteralSchema<"CLOSE", undefined>;
|
|
83
96
|
}, undefined>], undefined>, undefined>, v.MinLengthAction<({
|
|
84
97
|
type: "NODE";
|
|
85
|
-
destinationId
|
|
98
|
+
destinationId?: string | undefined;
|
|
99
|
+
variantProperties?: {
|
|
100
|
+
[x: string]: string;
|
|
101
|
+
} | undefined;
|
|
86
102
|
navigation: "OVERLAY" | "NAVIGATE" | "CHANGE_TO" | "SCROLL_TO";
|
|
87
103
|
transition: {
|
|
88
104
|
type: "INSTANT" | "DISSOLVE" | "SMART_ANIMATE";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactions.d.ts","names":[],"sources":["../../src/figma-api/reactions.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"reactions.d.ts","names":[],"sources":["../../src/figma-api/reactions.ts"],"mappings":";;;cAoHM,gBAAc,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAQP,sBAAoB,EAAA,YAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAGrB,gBAAgB,EAAE,mBAAmB;KACrC,uBAAuB;KACvB,sBAAsB;;iBAGlB,gBAAgB,UAAU,oBAAoB;;UAsC7C;EACf,OAAO;;EAEP;;EAEA;;EAEA,oBAAoB;;;;;;EAMpB,qBAAqB;;;;;;;;iBASP,oBAAoB,gBAAgB,SAAS,kBAAkB"}
|
|
@@ -4,6 +4,7 @@ import { PROTOTYPE_EASINGS } from "@pairdraw/scene-graph/constants";
|
|
|
4
4
|
import { generateId } from "@pairdraw/scene-graph";
|
|
5
5
|
import * as v from "valibot";
|
|
6
6
|
import { variantSetsAround } from "@pairdraw/scene-graph/components";
|
|
7
|
+
import { parseVariantName } from "@pairdraw/scene-graph/variant-name";
|
|
7
8
|
//#region src/figma-api/reactions.ts
|
|
8
9
|
/**
|
|
9
10
|
* Triggers Figma's plugin API offers that a prototype in Pairdraw cannot start from, and the
|
|
@@ -43,9 +44,12 @@ const transitionSchema = v.strictObject({
|
|
|
43
44
|
duration: secondsSchema,
|
|
44
45
|
easing: v.optional(easingSchema)
|
|
45
46
|
});
|
|
47
|
+
/** A variant's values for its set's properties, as `{ State: 'Hover', Size: 'Large' }`. */
|
|
48
|
+
const variantPropertiesSchema = v.pipe(v.record(v.string(), v.string()), v.minEntries(1), v.description("CHANGE_TO: the values of the variant to change to, in the layer's nearest component set, such as { State: \"Hover\" }. Name every property of a set whose variants share values, as a partial match is refused. Resolved to the variant, so get_reactions reads it back as a destinationId."));
|
|
46
49
|
const nodeActionSchema = v.strictObject({
|
|
47
50
|
type: v.literal("NODE"),
|
|
48
|
-
destinationId: v.pipe(v.string(), v.minLength(1), v.description("NAVIGATE/OVERLAY: a top-level frame on the page; CHANGE_TO: a variant of the set the layer is a variant of, an instance of, or inside; SCROLL_TO: a layer in the layer's top-level frame.")),
|
|
51
|
+
destinationId: v.optional(v.pipe(v.string(), v.minLength(1), v.description("NAVIGATE/OVERLAY: a top-level frame on the page; CHANGE_TO: a variant of the set the layer is a variant of, an instance of, or inside; SCROLL_TO: a layer in the layer's top-level frame. Omit only for CHANGE_TO, and name the variant with variantProperties."))),
|
|
52
|
+
variantProperties: v.optional(variantPropertiesSchema),
|
|
49
53
|
navigation: v.picklist([
|
|
50
54
|
"NAVIGATE",
|
|
51
55
|
"OVERLAY",
|
|
@@ -172,15 +176,57 @@ function toTrigger(trigger) {
|
|
|
172
176
|
}
|
|
173
177
|
function toAction(action, context, reactionIndex) {
|
|
174
178
|
if (action.type !== "NODE") return { type: action.type };
|
|
175
|
-
|
|
179
|
+
const destinationId = resolveDestinationId(action, context, reactionIndex);
|
|
180
|
+
assertDestination({
|
|
181
|
+
...action,
|
|
182
|
+
destinationId
|
|
183
|
+
}, context, reactionIndex);
|
|
176
184
|
return {
|
|
177
185
|
type: "NODE",
|
|
178
|
-
nodeId:
|
|
186
|
+
nodeId: destinationId,
|
|
179
187
|
navigation: action.navigation,
|
|
180
188
|
transition: fromFigmaTransition(action.transition),
|
|
181
189
|
overlayPosition: action.navigation === "OVERLAY" ? action.overlayRelativePosition : "CENTER"
|
|
182
190
|
};
|
|
183
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* The layer a NODE action points at: its `destinationId`, or for a Change to, the variant of the
|
|
194
|
+
* layer's set whose `variantProperties` it names.
|
|
195
|
+
*/
|
|
196
|
+
function resolveDestinationId(action, context, index) {
|
|
197
|
+
const at = `reactions[${index}]`;
|
|
198
|
+
const { destinationId, variantProperties, navigation } = action;
|
|
199
|
+
if (destinationId && variantProperties) throw failure(`${at} names both destinationId and variantProperties; give one`);
|
|
200
|
+
if (variantProperties) {
|
|
201
|
+
if (navigation !== "CHANGE_TO") throw failure(`${at}: variantProperties is for CHANGE_TO only, not ${navigation}`);
|
|
202
|
+
return variantByProperties(variantProperties, context, at);
|
|
203
|
+
}
|
|
204
|
+
if (!destinationId) throw failure(navigation === "CHANGE_TO" ? `${at} must name the variant it Changes to, in destinationId or variantProperties` : `${at} must name the layer it goes to, in destinationId`);
|
|
205
|
+
return destinationId;
|
|
206
|
+
}
|
|
207
|
+
/** The id of the variant of the sets around the layer whose properties are `properties`. */
|
|
208
|
+
function variantByProperties(properties, context, at) {
|
|
209
|
+
const sets = variantSetsAround(context.graph, context.nodeId);
|
|
210
|
+
const nearest = sets.at(0);
|
|
211
|
+
if (!nearest) throw failure(`${at}: only a variant, an instance of one, or a layer inside one can Change to another variant`);
|
|
212
|
+
const wanted = Object.entries(properties).map(([name, value]) => `${name}=${value}`).join(", ");
|
|
213
|
+
for (const set of sets) {
|
|
214
|
+
const matches = context.graph.getChildren(set.id).filter((child) => {
|
|
215
|
+
if (child.type !== "COMPONENT") return false;
|
|
216
|
+
const values = {
|
|
217
|
+
...parseVariantName(child.name),
|
|
218
|
+
...child.componentPropertyValues
|
|
219
|
+
};
|
|
220
|
+
return Object.entries(properties).every(([name, value]) => values[name] === value);
|
|
221
|
+
});
|
|
222
|
+
if (matches.length === 1) return matches[0].id;
|
|
223
|
+
if (matches.length > 1) {
|
|
224
|
+
const names = matches.map((match) => `"${match.name}"`).join(", ");
|
|
225
|
+
throw failure(`${at}: ${wanted} matches ${matches.length} variants of ${set.name} (${names}); name every property of the variant`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
throw failure(`${at}: no variant of ${nearest.name} with ${wanted}`);
|
|
229
|
+
}
|
|
184
230
|
function failure(message) {
|
|
185
231
|
return /* @__PURE__ */ new Error(`Property "reactions" failed validation: ${message}`);
|
|
186
232
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactions.js","names":[],"sources":["../../src/figma-api/reactions.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { generateId } from '@pairdraw/scene-graph'\nimport type {\n PrototypeAction,\n PrototypeNavigationType,\n PrototypeOverlayPositionType,\n PrototypeReaction,\n PrototypeTransition,\n PrototypeTransitionType,\n PrototypeTriggerType,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\nimport { variantSetsAround } from '@pairdraw/scene-graph/components'\nimport { PROTOTYPE_EASINGS } from '@pairdraw/scene-graph/constants'\n\nimport { issuePath } from '#core/figma-api/effects'\nimport { asInstanceEdit, sameReaction } from '#core/prototype/reactions'\n\n/**\n * Triggers Figma's plugin API offers that a prototype in Pairdraw cannot start from, and the\n * message it gets instead.\n */\nconst UNSUPPORTED_TRIGGERS: Record<string, true> = {\n ON_DRAG: true,\n MOUSE_UP: true,\n MOUSE_DOWN: true,\n ON_KEY_DOWN: true\n}\n\n/** Actions Figma's plugin API offers that a prototype in Pairdraw cannot run. */\nconst UNSUPPORTED_ACTIONS: Record<string, true> = {\n URL: true,\n SET_VARIABLE: true,\n CONDITIONAL: true,\n SET_VARIABLE_MODE: true\n}\n\n// No `v.finite()` action: the MCP tool contract turns this schema into JSON Schema, which\n// has no notion of infinities, and JSON numbers are always finite anyway.\nconst secondsSchema = v.pipe(v.number(), v.minValue(0))\n\nconst overlayPositionSchema = v.picklist([\n 'CENTER',\n 'TOP_LEFT',\n 'TOP_CENTER',\n 'TOP_RIGHT',\n 'BOTTOM_LEFT',\n 'BOTTOM_CENTER',\n 'BOTTOM_RIGHT'\n] satisfies PrototypeOverlayPositionType[])\n\n/** Figma's easing presets, which play has; a spring or a custom curve is refused. */\nconst easingSchema = v.strictObject({ type: v.picklist(PROTOTYPE_EASINGS) })\n\nconst transitionSchema = v.strictObject({\n type: v.picklist(['INSTANT', 'DISSOLVE', 'SMART_ANIMATE'] satisfies PrototypeTransitionType[]),\n duration: secondsSchema,\n easing: v.optional(easingSchema)\n})\n\nconst nodeActionSchema = v.strictObject({\n type: v.literal('NODE'),\n destinationId: v.pipe(\n v.string(),\n v.minLength(1),\n v.description(\n 'NAVIGATE/OVERLAY: a top-level frame on the page; CHANGE_TO: a variant of the set the ' +\n \"layer is a variant of, an instance of, or inside; SCROLL_TO: a layer in the layer's \" +\n 'top-level frame.'\n )\n ),\n navigation: v.picklist([\n 'NAVIGATE',\n 'OVERLAY',\n 'CHANGE_TO',\n 'SCROLL_TO'\n ] satisfies PrototypeNavigationType[]),\n transition: v.optional(transitionSchema, { type: 'INSTANT', duration: 0 }),\n overlayRelativePosition: v.optional(overlayPositionSchema, 'CENTER')\n})\n\nconst actionSchema = v.variant('type', [\n nodeActionSchema,\n v.strictObject({ type: v.literal('BACK') }),\n v.strictObject({ type: v.literal('CLOSE') })\n])\n\nconst triggerSchema = v.variant('type', [\n v.strictObject({ type: v.picklist(['ON_CLICK', 'ON_HOVER', 'ON_PRESS']) }),\n v.strictObject({ type: v.literal('AFTER_TIMEOUT'), timeout: secondsSchema }),\n v.strictObject({\n type: v.picklist(['MOUSE_ENTER', 'MOUSE_LEAVE']),\n delay: v.optional(secondsSchema, 0),\n // Figma's plugin API reads it; play treats both versions alike.\n deprecatedVersion: v.optional(v.boolean())\n })\n])\n\nconst reactionSchema = v.strictObject({\n trigger: triggerSchema,\n actions: v.pipe(v.array(actionSchema), v.minLength(1))\n})\n\nconst reactionsSchema = v.array(reactionSchema)\n\n/** The plugin shape as a contract, for a tool that takes connections as arguments. */\nexport const figmaReactionsSchema = reactionsSchema\n\n/** A reaction as Figma's plugin API reads and writes it (`Reaction` in `@figma/plugin-typings`). */\nexport type FigmaReaction = v.InferOutput<typeof reactionSchema>\nexport type FigmaReactionTrigger = FigmaReaction['trigger']\nexport type FigmaReactionAction = FigmaReaction['actions'][number]\n\n/** `reaction` in the plugin shape: the trigger and every action, named as Figma names them. */\nexport function toFigmaReaction(reaction: PrototypeReaction): FigmaReaction {\n return { trigger: toFigmaTrigger(reaction.trigger), actions: reaction.actions.map(toFigmaAction) }\n}\n\nfunction toFigmaTrigger({ type, delay }: PrototypeReaction['trigger']): FigmaReactionTrigger {\n if (type === 'AFTER_TIMEOUT') return { type, timeout: delay }\n if (type === 'MOUSE_ENTER' || type === 'MOUSE_LEAVE') return { type, delay }\n return { type }\n}\n\nfunction toFigmaAction(action: PrototypeAction): FigmaReactionAction {\n if (action.type !== 'NODE') return { type: action.type }\n return {\n type: 'NODE',\n destinationId: action.nodeId ?? '',\n navigation: action.navigation,\n transition: toFigmaTransition(action.transition),\n overlayRelativePosition: action.overlayPosition\n }\n}\n\nfunction toFigmaTransition({\n type,\n duration,\n easing\n}: PrototypeTransition): v.InferOutput<typeof transitionSchema> {\n return easing ? { type, duration, easing: { type: easing } } : { type, duration }\n}\n\nfunction fromFigmaTransition({\n type,\n duration,\n easing\n}: v.InferOutput<typeof transitionSchema>): PrototypeTransition {\n return easing ? { type, duration, easing: easing.type } : { type, duration }\n}\n\n/** The validation context: where the reactions live, and what they may point at. */\nexport interface ReactionContext {\n graph: SceneGraph\n /** The layer the reactions are on, which a Change to or Scroll to destination must suit. */\n nodeId: string\n /** The page the layer is on; a navigation's destination must be a top-level frame on it. */\n pageId: string\n /** The reactions the layer has now, whose ids this keeps by position. */\n previous?: readonly PrototypeReaction[]\n /**\n * An instance's main component's reactions: a reaction kept under one of their ids that an\n * edit changed, from what the layer held at its place and from the main's, becomes the\n * instance's own, with an id of its own.\n */\n inherited?: readonly PrototypeReaction[]\n}\n\n/**\n * `value` as the layer's prototype reactions, or an error naming what Pairdraw cannot play.\n * Accepts Figma's plugin shape only: a trigger Figma offers but playback does not start from,\n * an action, transition, navigation or overlay spot outside the model, and a destination that\n * is not a top-level frame on the layer's page are refused rather than kept unplayable.\n */\nexport function parseFigmaReactions(value: unknown, context: ReactionContext): PrototypeReaction[] {\n const unsupported = unsupportedKind(value)\n if (unsupported) throw new Error(`Property \"reactions\" failed validation: ${unsupported}`)\n const result = v.safeParse(reactionsSchema, value)\n if (!result.success) {\n const [issue] = result.issues\n throw new Error(\n `Property \"reactions\" failed validation: ${issue.message} at ${issuePath(issue.path) || 'reactions'}`\n )\n }\n return result.output.map((reaction, index) => {\n const id = context.previous?.[index]?.id ?? generateId()\n const parsed: PrototypeReaction = {\n id,\n trigger: toTrigger(reaction.trigger),\n actions: reaction.actions.map((action) => toAction(action, context, index))\n }\n // One the layer already held unchanged stays as it was, a copy of the main's included, so\n // writing reactions back as read never re-ids a copy whose main was edited since.\n const held = context.previous?.[index]\n if (held && sameReaction(held, parsed)) return parsed\n return asInstanceEdit(parsed, context.inherited ?? [])\n })\n}\n\nfunction toTrigger(trigger: FigmaReactionTrigger): PrototypeReaction['trigger'] {\n const type: PrototypeTriggerType = trigger.type\n if (trigger.type === 'AFTER_TIMEOUT') return { type, delay: trigger.timeout }\n return { type, delay: 'delay' in trigger ? trigger.delay : 0 }\n}\n\nfunction toAction(\n action: FigmaReactionAction,\n context: ReactionContext,\n reactionIndex: number\n): PrototypeAction {\n if (action.type !== 'NODE') return { type: action.type }\n assertDestination(action, context, reactionIndex)\n return {\n type: 'NODE',\n nodeId: action.destinationId,\n navigation: action.navigation,\n transition: fromFigmaTransition(action.transition),\n // Only an overlay uses the spot; Figma keeps CENTER on a navigation.\n overlayPosition: action.navigation === 'OVERLAY' ? action.overlayRelativePosition : 'CENTER'\n }\n}\n\nfunction failure(message: string): Error {\n return new Error(`Property \"reactions\" failed validation: ${message}`)\n}\n\n/**\n * A destination play can show: a navigation's is a frame at the top of the layer's page, a Change\n * to's a variant of a set the layer belongs to, and a Scroll to's a layer in the layer's\n * top-level frame.\n */\nfunction assertDestination(\n action: v.InferOutput<typeof nodeActionSchema>,\n context: ReactionContext,\n index: number\n): void {\n const { destinationId, navigation } = action\n const destination = context.graph.getNode(destinationId)\n const at = `reactions[${index}]`\n if (!destination) throw failure(`no layer ${destinationId} at ${at}.actions[0].destinationId`)\n if (navigation === 'CHANGE_TO') return assertVariant(destination, context, at)\n if (navigation === 'SCROLL_TO') return assertScrollTarget(destination, context, at)\n if (destination.type !== 'FRAME' || destination.parentId !== context.pageId) {\n throw failure(\n `${at} must navigate to a top-level frame on the same page, not ${destination.type} \"${destination.name}\"`\n )\n }\n}\n\nfunction assertVariant(destination: SceneNode, context: ReactionContext, at: string): void {\n const sets = variantSetsAround(context.graph, context.nodeId)\n const nearest = sets.at(0)\n if (!nearest) {\n throw failure(\n `${at}: only a variant, an instance of one, or a layer inside one can Change to another variant`\n )\n }\n const inSet = sets.some((set) => set.id === destination.parentId)\n if (destination.type !== 'COMPONENT' || !inSet) {\n throw failure(\n `${at} must Change to a variant of ${nearest.name}, not ${destination.type} \"${destination.name}\"`\n )\n }\n}\n\n/** The page's direct child a layer sits in, which play shows as one screen. */\nfunction topLevelOf(graph: SceneGraph, nodeId: string, pageId: string): SceneNode | undefined {\n return graph.closest(nodeId, (node) => node.parentId === pageId)\n}\n\nfunction assertScrollTarget(destination: SceneNode, context: ReactionContext, at: string): void {\n const { graph, nodeId, pageId } = context\n const top = topLevelOf(graph, nodeId, pageId)\n if (!top || destination.id === top.id || !graph.isDescendant(destination.id, top.id)) {\n throw failure(\n `${at} must Scroll to a layer inside the same top-level frame, not ${destination.type} \"${destination.name}\"`\n )\n }\n}\n\n/** Figma's first unsupported trigger or action kind in `value`, if it has one. */\nfunction unsupportedKind(value: unknown): string | null {\n if (!Array.isArray(value)) return null\n const reactions = value.filter(\n (reaction): reaction is Record<string, unknown> =>\n Boolean(reaction) && typeof reaction === 'object'\n )\n for (const reaction of reactions) {\n const trigger = reaction.trigger\n if (trigger && typeof trigger === 'object' && 'type' in trigger) {\n const type = trigger.type\n if (typeof type === 'string' && type in UNSUPPORTED_TRIGGERS) {\n return `a prototype starts from ON_CLICK, ON_HOVER, ON_PRESS, MOUSE_ENTER, MOUSE_LEAVE or AFTER_TIMEOUT, not ${type}`\n }\n }\n const actions = reaction.actions\n if (!Array.isArray(actions)) continue\n for (const action of actions) {\n if (action && typeof action === 'object' && 'type' in action) {\n const type = action.type\n if (typeof type === 'string' && type in UNSUPPORTED_ACTIONS) {\n return `an action is NODE, BACK or CLOSE, not ${type}`\n }\n }\n }\n }\n return null\n}\n"],"mappings":";;;;;;;;;;;AAwBA,MAAM,uBAA6C;CACjD,SAAS;CACT,UAAU;CACV,YAAY;CACZ,aAAa;AACf;;AAGA,MA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a,QAC7C;CACA,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,UAAU,SAAS;EACzB,IAAI,WAAW,OAAO,YAAY,YAAY,UAAU,SAAS;GAC/D,MAAM,OAAO,QAAQ;GACrB,IAAI,OAAO,SAAS,YAAY,QAAQ,sBACtC,OAAO,wGAAwG;EAEnH;EACA,MAAM,UAAU,SAAS;EACzB,IAAI,CAAC,MAAM,QAAQ,OAAO,GAAG;EAC7B,KAAK,MAAM,UAAU,SACnB,IAAI,UAAU,OAAO,WAAW,YAAY,UAAU,QAAQ;GAC5D,MAAM,OAAO,OAAO;GACpB,IAAI,OAAO,SAAS,YAAY,QAAQ,qBACtC,OAAO,yCAAyC;EAEpD;CAEJ;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"reactions.js","names":[],"sources":["../../src/figma-api/reactions.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { generateId } from '@pairdraw/scene-graph'\nimport type {\n PrototypeAction,\n PrototypeNavigationType,\n PrototypeOverlayPositionType,\n PrototypeReaction,\n PrototypeTransition,\n PrototypeTransitionType,\n PrototypeTriggerType,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\nimport { variantSetsAround } from '@pairdraw/scene-graph/components'\nimport { PROTOTYPE_EASINGS } from '@pairdraw/scene-graph/constants'\nimport { parseVariantName } from '@pairdraw/scene-graph/variant-name'\n\nimport { issuePath } from '#core/figma-api/effects'\nimport { asInstanceEdit, sameReaction } from '#core/prototype/reactions'\n\n/**\n * Triggers Figma's plugin API offers that a prototype in Pairdraw cannot start from, and the\n * message it gets instead.\n */\nconst UNSUPPORTED_TRIGGERS: Record<string, true> = {\n ON_DRAG: true,\n MOUSE_UP: true,\n MOUSE_DOWN: true,\n ON_KEY_DOWN: true\n}\n\n/** Actions Figma's plugin API offers that a prototype in Pairdraw cannot run. */\nconst UNSUPPORTED_ACTIONS: Record<string, true> = {\n URL: true,\n SET_VARIABLE: true,\n CONDITIONAL: true,\n SET_VARIABLE_MODE: true\n}\n\n// No `v.finite()` action: the MCP tool contract turns this schema into JSON Schema, which\n// has no notion of infinities, and JSON numbers are always finite anyway.\nconst secondsSchema = v.pipe(v.number(), v.minValue(0))\n\nconst overlayPositionSchema = v.picklist([\n 'CENTER',\n 'TOP_LEFT',\n 'TOP_CENTER',\n 'TOP_RIGHT',\n 'BOTTOM_LEFT',\n 'BOTTOM_CENTER',\n 'BOTTOM_RIGHT'\n] satisfies PrototypeOverlayPositionType[])\n\n/** Figma's easing presets, which play has; a spring or a custom curve is refused. */\nconst easingSchema = v.strictObject({ type: v.picklist(PROTOTYPE_EASINGS) })\n\nconst transitionSchema = v.strictObject({\n type: v.picklist(['INSTANT', 'DISSOLVE', 'SMART_ANIMATE'] satisfies PrototypeTransitionType[]),\n duration: secondsSchema,\n easing: v.optional(easingSchema)\n})\n\n/** A variant's values for its set's properties, as `{ State: 'Hover', Size: 'Large' }`. */\nconst variantPropertiesSchema = v.pipe(\n v.record(v.string(), v.string()),\n v.minEntries(1),\n v.description(\n \"CHANGE_TO: the values of the variant to change to, in the layer's nearest component set, \" +\n 'such as { State: \"Hover\" }. Name every property of a set whose variants share values, as ' +\n 'a partial match is refused. Resolved to the variant, so get_reactions reads it back as ' +\n 'a destinationId.'\n )\n)\n\nconst nodeActionSchema = v.strictObject({\n type: v.literal('NODE'),\n destinationId: v.optional(\n v.pipe(\n v.string(),\n v.minLength(1),\n v.description(\n 'NAVIGATE/OVERLAY: a top-level frame on the page; CHANGE_TO: a variant of the set the ' +\n \"layer is a variant of, an instance of, or inside; SCROLL_TO: a layer in the layer's \" +\n 'top-level frame. Omit only for CHANGE_TO, and name the variant with variantProperties.'\n )\n )\n ),\n variantProperties: v.optional(variantPropertiesSchema),\n navigation: v.picklist([\n 'NAVIGATE',\n 'OVERLAY',\n 'CHANGE_TO',\n 'SCROLL_TO'\n ] satisfies PrototypeNavigationType[]),\n transition: v.optional(transitionSchema, { type: 'INSTANT', duration: 0 }),\n overlayRelativePosition: v.optional(overlayPositionSchema, 'CENTER')\n})\n\nconst actionSchema = v.variant('type', [\n nodeActionSchema,\n v.strictObject({ type: v.literal('BACK') }),\n v.strictObject({ type: v.literal('CLOSE') })\n])\n\nconst triggerSchema = v.variant('type', [\n v.strictObject({ type: v.picklist(['ON_CLICK', 'ON_HOVER', 'ON_PRESS']) }),\n v.strictObject({ type: v.literal('AFTER_TIMEOUT'), timeout: secondsSchema }),\n v.strictObject({\n type: v.picklist(['MOUSE_ENTER', 'MOUSE_LEAVE']),\n delay: v.optional(secondsSchema, 0),\n // Figma's plugin API reads it; play treats both versions alike.\n deprecatedVersion: v.optional(v.boolean())\n })\n])\n\nconst reactionSchema = v.strictObject({\n trigger: triggerSchema,\n actions: v.pipe(v.array(actionSchema), v.minLength(1))\n})\n\nconst reactionsSchema = v.array(reactionSchema)\n\n/** The plugin shape as a contract, for a tool that takes connections as arguments. */\nexport const figmaReactionsSchema = reactionsSchema\n\n/** A reaction as Figma's plugin API reads and writes it (`Reaction` in `@figma/plugin-typings`). */\nexport type FigmaReaction = v.InferOutput<typeof reactionSchema>\nexport type FigmaReactionTrigger = FigmaReaction['trigger']\nexport type FigmaReactionAction = FigmaReaction['actions'][number]\n\n/** `reaction` in the plugin shape: the trigger and every action, named as Figma names them. */\nexport function toFigmaReaction(reaction: PrototypeReaction): FigmaReaction {\n return { trigger: toFigmaTrigger(reaction.trigger), actions: reaction.actions.map(toFigmaAction) }\n}\n\nfunction toFigmaTrigger({ type, delay }: PrototypeReaction['trigger']): FigmaReactionTrigger {\n if (type === 'AFTER_TIMEOUT') return { type, timeout: delay }\n if (type === 'MOUSE_ENTER' || type === 'MOUSE_LEAVE') return { type, delay }\n return { type }\n}\n\nfunction toFigmaAction(action: PrototypeAction): FigmaReactionAction {\n if (action.type !== 'NODE') return { type: action.type }\n return {\n type: 'NODE',\n destinationId: action.nodeId ?? '',\n navigation: action.navigation,\n transition: toFigmaTransition(action.transition),\n overlayRelativePosition: action.overlayPosition\n }\n}\n\nfunction toFigmaTransition({\n type,\n duration,\n easing\n}: PrototypeTransition): v.InferOutput<typeof transitionSchema> {\n return easing ? { type, duration, easing: { type: easing } } : { type, duration }\n}\n\nfunction fromFigmaTransition({\n type,\n duration,\n easing\n}: v.InferOutput<typeof transitionSchema>): PrototypeTransition {\n return easing ? { type, duration, easing: easing.type } : { type, duration }\n}\n\n/** The validation context: where the reactions live, and what they may point at. */\nexport interface ReactionContext {\n graph: SceneGraph\n /** The layer the reactions are on, which a Change to or Scroll to destination must suit. */\n nodeId: string\n /** The page the layer is on; a navigation's destination must be a top-level frame on it. */\n pageId: string\n /** The reactions the layer has now, whose ids this keeps by position. */\n previous?: readonly PrototypeReaction[]\n /**\n * An instance's main component's reactions: a reaction kept under one of their ids that an\n * edit changed, from what the layer held at its place and from the main's, becomes the\n * instance's own, with an id of its own.\n */\n inherited?: readonly PrototypeReaction[]\n}\n\n/**\n * `value` as the layer's prototype reactions, or an error naming what Pairdraw cannot play.\n * Accepts Figma's plugin shape only: a trigger Figma offers but playback does not start from,\n * an action, transition, navigation or overlay spot outside the model, and a destination that\n * is not a top-level frame on the layer's page are refused rather than kept unplayable.\n */\nexport function parseFigmaReactions(value: unknown, context: ReactionContext): PrototypeReaction[] {\n const unsupported = unsupportedKind(value)\n if (unsupported) throw new Error(`Property \"reactions\" failed validation: ${unsupported}`)\n const result = v.safeParse(reactionsSchema, value)\n if (!result.success) {\n const [issue] = result.issues\n throw new Error(\n `Property \"reactions\" failed validation: ${issue.message} at ${issuePath(issue.path) || 'reactions'}`\n )\n }\n return result.output.map((reaction, index) => {\n const id = context.previous?.[index]?.id ?? generateId()\n const parsed: PrototypeReaction = {\n id,\n trigger: toTrigger(reaction.trigger),\n actions: reaction.actions.map((action) => toAction(action, context, index))\n }\n // One the layer already held unchanged stays as it was, a copy of the main's included, so\n // writing reactions back as read never re-ids a copy whose main was edited since.\n const held = context.previous?.[index]\n if (held && sameReaction(held, parsed)) return parsed\n return asInstanceEdit(parsed, context.inherited ?? [])\n })\n}\n\nfunction toTrigger(trigger: FigmaReactionTrigger): PrototypeReaction['trigger'] {\n const type: PrototypeTriggerType = trigger.type\n if (trigger.type === 'AFTER_TIMEOUT') return { type, delay: trigger.timeout }\n return { type, delay: 'delay' in trigger ? trigger.delay : 0 }\n}\n\nfunction toAction(\n action: FigmaReactionAction,\n context: ReactionContext,\n reactionIndex: number\n): PrototypeAction {\n if (action.type !== 'NODE') return { type: action.type }\n const destinationId = resolveDestinationId(action, context, reactionIndex)\n assertDestination({ ...action, destinationId }, context, reactionIndex)\n return {\n type: 'NODE',\n nodeId: destinationId,\n navigation: action.navigation,\n transition: fromFigmaTransition(action.transition),\n // Only an overlay uses the spot; Figma keeps CENTER on a navigation.\n overlayPosition: action.navigation === 'OVERLAY' ? action.overlayRelativePosition : 'CENTER'\n }\n}\n\n/**\n * The layer a NODE action points at: its `destinationId`, or for a Change to, the variant of the\n * layer's set whose `variantProperties` it names.\n */\nfunction resolveDestinationId(\n action: v.InferOutput<typeof nodeActionSchema>,\n context: ReactionContext,\n index: number\n): string {\n const at = `reactions[${index}]`\n const { destinationId, variantProperties, navigation } = action\n if (destinationId && variantProperties) {\n throw failure(`${at} names both destinationId and variantProperties; give one`)\n }\n if (variantProperties) {\n if (navigation !== 'CHANGE_TO') {\n throw failure(`${at}: variantProperties is for CHANGE_TO only, not ${navigation}`)\n }\n return variantByProperties(variantProperties, context, at)\n }\n if (!destinationId) {\n throw failure(\n navigation === 'CHANGE_TO'\n ? `${at} must name the variant it Changes to, in destinationId or variantProperties`\n : `${at} must name the layer it goes to, in destinationId`\n )\n }\n return destinationId\n}\n\n/** The id of the variant of the sets around the layer whose properties are `properties`. */\nfunction variantByProperties(\n properties: Record<string, string>,\n context: ReactionContext,\n at: string\n): string {\n const sets = variantSetsAround(context.graph, context.nodeId)\n const nearest = sets.at(0)\n if (!nearest) {\n throw failure(\n `${at}: only a variant, an instance of one, or a layer inside one can Change to another variant`\n )\n }\n const wanted = Object.entries(properties)\n .map(([name, value]) => `${name}=${value}`)\n .join(', ')\n for (const set of sets) {\n const matches = context.graph.getChildren(set.id).filter((child) => {\n if (child.type !== 'COMPONENT') return false\n const values = { ...parseVariantName(child.name), ...child.componentPropertyValues }\n return Object.entries(properties).every(([name, value]) => values[name] === value)\n })\n if (matches.length === 1) return matches[0].id\n // A set can hold variants a partial map matches equally: refuse rather than pick one.\n if (matches.length > 1) {\n const names = matches.map((match) => `\"${match.name}\"`).join(', ')\n throw failure(\n `${at}: ${wanted} matches ${matches.length} variants of ${set.name} (${names}); name every property of the variant`\n )\n }\n }\n throw failure(`${at}: no variant of ${nearest.name} with ${wanted}`)\n}\n\nfunction failure(message: string): Error {\n return new Error(`Property \"reactions\" failed validation: ${message}`)\n}\n\n/**\n * A destination play can show: a navigation's is a frame at the top of the layer's page, a Change\n * to's a variant of a set the layer belongs to, and a Scroll to's a layer in the layer's\n * top-level frame.\n */\nfunction assertDestination(\n action: Pick<v.InferOutput<typeof nodeActionSchema>, 'navigation'> & { destinationId: string },\n context: ReactionContext,\n index: number\n): void {\n const { destinationId, navigation } = action\n const destination = context.graph.getNode(destinationId)\n const at = `reactions[${index}]`\n if (!destination) throw failure(`no layer ${destinationId} at ${at}.actions[0].destinationId`)\n if (navigation === 'CHANGE_TO') return assertVariant(destination, context, at)\n if (navigation === 'SCROLL_TO') return assertScrollTarget(destination, context, at)\n if (destination.type !== 'FRAME' || destination.parentId !== context.pageId) {\n throw failure(\n `${at} must navigate to a top-level frame on the same page, not ${destination.type} \"${destination.name}\"`\n )\n }\n}\n\nfunction assertVariant(destination: SceneNode, context: ReactionContext, at: string): void {\n const sets = variantSetsAround(context.graph, context.nodeId)\n const nearest = sets.at(0)\n if (!nearest) {\n throw failure(\n `${at}: only a variant, an instance of one, or a layer inside one can Change to another variant`\n )\n }\n const inSet = sets.some((set) => set.id === destination.parentId)\n if (destination.type !== 'COMPONENT' || !inSet) {\n throw failure(\n `${at} must Change to a variant of ${nearest.name}, not ${destination.type} \"${destination.name}\"`\n )\n }\n}\n\n/** The page's direct child a layer sits in, which play shows as one screen. */\nfunction topLevelOf(graph: SceneGraph, nodeId: string, pageId: string): SceneNode | undefined {\n return graph.closest(nodeId, (node) => node.parentId === pageId)\n}\n\nfunction assertScrollTarget(destination: SceneNode, context: ReactionContext, at: string): void {\n const { graph, nodeId, pageId } = context\n const top = topLevelOf(graph, nodeId, pageId)\n if (!top || destination.id === top.id || !graph.isDescendant(destination.id, top.id)) {\n throw failure(\n `${at} must Scroll to a layer inside the same top-level frame, not ${destination.type} \"${destination.name}\"`\n )\n }\n}\n\n/** Figma's first unsupported trigger or action kind in `value`, if it has one. */\nfunction unsupportedKind(value: unknown): string | null {\n if (!Array.isArray(value)) return null\n const reactions = value.filter(\n (reaction): reaction is Record<string, unknown> =>\n Boolean(reaction) && typeof reaction === 'object'\n )\n for (const reaction of reactions) {\n const trigger = reaction.trigger\n if (trigger && typeof trigger === 'object' && 'type' in trigger) {\n const type = trigger.type\n if (typeof type === 'string' && type in UNSUPPORTED_TRIGGERS) {\n return `a prototype starts from ON_CLICK, ON_HOVER, ON_PRESS, MOUSE_ENTER, MOUSE_LEAVE or AFTER_TIMEOUT, not ${type}`\n }\n }\n const actions = reaction.actions\n if (!Array.isArray(actions)) continue\n for (const action of actions) {\n if (action && typeof action === 'object' && 'type' in action) {\n const type = action.type\n if (typeof type === 'string' && type in UNSUPPORTED_ACTIONS) {\n return `an action is NODE, BACK or CLOSE, not ${type}`\n }\n }\n }\n }\n return null\n}\n"],"mappings":";;;;;;;;;;;;AAyBA,MAAM,uBAA6C;CACjD,SAAS;CACT,UAAU;CACV,YAAY;CACZ,aAAa;AACf;;AAGA,MAAM,sBAA4C;CAChD,KAAK;CACL,cAAc;CACd,aAAa;CACb,mBAAmB;AACrB;AAIA,MAAM,gBAAgB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,CAAC;AAEtD,MAAM,wBAAwB,EAAE,SAAS;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;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Y,KAAK,IAAI,YAAY,KAAK,EAC7G;AAEJ;;AAGA,SAAS,gBAAgB,OAA+B;CACtD,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO;CAClC,MAAM,YAAY,MAAM,QACrB,aACC,QAAQ,QAAQ,KAAK,OAAO,aAAa,QAC7C;CACA,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,UAAU,SAAS;EACzB,IAAI,WAAW,OAAO,YAAY,YAAY,UAAU,SAAS;GAC/D,MAAM,OAAO,QAAQ;GACrB,IAAI,OAAO,SAAS,YAAY,QAAQ,sBACtC,OAAO,wGAAwG;EAEnH;EACA,MAAM,UAAU,SAAS;EACzB,IAAI,CAAC,MAAM,QAAQ,OAAO,GAAG;EAC7B,KAAK,MAAM,UAAU,SACnB,IAAI,UAAU,OAAO,WAAW,YAAY,UAAU,QAAQ;GAC5D,MAAM,OAAO,OAAO;GACpB,IAAI,OAAO,SAAS,YAAY,QAAQ,qBACtC,OAAO,yCAAyC;EAEpD;CAEJ;CACA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/figma-api/variables/index.ts"],"mappings":";;;;;;cAgBM;KACM,oCAAoC;;KAiB3C;WACM;WACA;IAAmB,QAAQ;;;;cAIzB;;EAGC,YAAA,OAAO;EAInB,gBAAgB,aAAa;EAIvB,qBAAqB,aAAa,QAAQ;EAIhD,0BAA0B,aAAa;EAMjC,+BAA+B,aAAa,QAAQ;EAI1D,kBAAkB,OAAO,4BAA4B;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/figma-api/variables/index.ts"],"mappings":";;;;;;cAgBM;KACM,oCAAoC;;KAiB3C;WACM;WACA;IAAmB,QAAQ;;;;cAIzB;;EAGC,YAAA,OAAO;EAInB,gBAAgB,aAAa;EAIvB,qBAAqB,aAAa,QAAQ;EAIhD,0BAA0B,aAAa;EAMjC,+BAA+B,aAAa,QAAQ;EAI1D,kBAAkB,OAAO,4BAA4B;EAQ/C,uBAAuB,OAAO,4BAA4B,QAAQ;EAIxE,+BAA+B;EAMzB,oCAAoC,QAAQ;;EAKlD,eACE,cACA;aAAuB;cACvB,cAAc,4BACb;EAkBH,yBAAyB,eAAe;EAIxC,oBAAoB;aAAqB;MAAe;EAIlD,6BAA6B,qBAAqB,QAAQ;;;;;EAWhE,yBAAyB,UAAU,iBACjC,OAAO,GACP,iBACA;aAAqB;aACpB;IAAM;MAAkB,QAAQ"}
|
|
@@ -38,13 +38,13 @@ var FigmaVariablesAPI = class {
|
|
|
38
38
|
}
|
|
39
39
|
getLocalVariables(type) {
|
|
40
40
|
const wanted = type === void 0 ? void 0 : assertType("getLocalVariables", type);
|
|
41
|
-
return
|
|
41
|
+
return this.#graph.getLiveVariables().filter((variable) => wanted === void 0 || variable.type === wanted).map((variable) => new FigmaVariable(this.#graph, variable.id));
|
|
42
42
|
}
|
|
43
43
|
async getLocalVariablesAsync(type) {
|
|
44
44
|
return this.getLocalVariables(type);
|
|
45
45
|
}
|
|
46
46
|
getLocalVariableCollections() {
|
|
47
|
-
return
|
|
47
|
+
return this.#graph.getLiveCollections().map((collection) => new FigmaVariableCollection(this.#graph, collection.id));
|
|
48
48
|
}
|
|
49
49
|
async getLocalVariableCollectionsAsync() {
|
|
50
50
|
return this.getLocalVariableCollections();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["#graph"],"sources":["../../../src/figma-api/variables/index.ts"],"sourcesContent":["import type { SceneGraph, VariableType } from '@pairdraw/scene-graph'\n\nimport { FIGMA_DEFAULT_VALUES, variableAlias, type FigmaVariableAlias } from './values'\nimport { FigmaVariable, FigmaVariableCollection, assertVariableName } from './variable'\n\nexport { FigmaVariable, FigmaVariableCollection, writeVariableValue } from './variable'\nexport type { FigmaComposedColor, FigmaVariableAlias, FigmaVariableValue } from './values'\nexport {\n figmaBoundVariables,\n paintBindings,\n setLayerBinding,\n setPaintBindings,\n type FigmaBindableField\n} from './bindings'\n\n/** Figma's variable types, including the motion types Pairdraw does not model. */\nconst FIGMA_TYPES = ['BOOLEAN', 'COLOR', 'FLOAT', 'STRING', 'EASING', 'TIMING'] as const\nexport type FigmaVariableResolvedType = (typeof FIGMA_TYPES)[number]\n\nfunction assertType(method: string, type: unknown): FigmaVariableResolvedType {\n if (!(FIGMA_TYPES as readonly unknown[]).includes(type)) {\n throw new Error(\n `in ${method}: Property \"resolvedType\" failed validation: Invalid option: expected one of ` +\n FIGMA_TYPES.map((name) => `\"${name}\"`).join('|')\n )\n }\n return type as FigmaVariableResolvedType\n}\n\nfunction isModelledType(type: FigmaVariableResolvedType): type is VariableType {\n return Object.hasOwn(FIGMA_DEFAULT_VALUES, type)\n}\n\n/** A solid paint as `setBoundVariableForPaint` takes and returns it. */\ntype FigmaSolidPaint = {\n readonly type: string\n readonly boundVariables?: { color?: FigmaVariableAlias }\n}\n\n/** `figma.variables`: the document's variables and collections, as Figma's plugin API has them. */\nexport class FigmaVariablesAPI {\n readonly #graph: SceneGraph\n\n constructor(graph: SceneGraph) {\n this.#graph = graph\n }\n\n getVariableById(id: string): FigmaVariable | null {\n return this.#graph.variables.has(id) ? new FigmaVariable(this.#graph, id) : null\n }\n\n async getVariableByIdAsync(id: string): Promise<FigmaVariable | null> {\n return this.getVariableById(id)\n }\n\n getVariableCollectionById(id: string): FigmaVariableCollection | null {\n return this.#graph.variableCollections.has(id)\n ? new FigmaVariableCollection(this.#graph, id)\n : null\n }\n\n async getVariableCollectionByIdAsync(id: string): Promise<FigmaVariableCollection | null> {\n return this.getVariableCollectionById(id)\n }\n\n getLocalVariables(type?: FigmaVariableResolvedType): FigmaVariable[] {\n const wanted = type === undefined ? undefined : assertType('getLocalVariables', type)\n return
|
|
1
|
+
{"version":3,"file":"index.js","names":["#graph"],"sources":["../../../src/figma-api/variables/index.ts"],"sourcesContent":["import type { SceneGraph, VariableType } from '@pairdraw/scene-graph'\n\nimport { FIGMA_DEFAULT_VALUES, variableAlias, type FigmaVariableAlias } from './values'\nimport { FigmaVariable, FigmaVariableCollection, assertVariableName } from './variable'\n\nexport { FigmaVariable, FigmaVariableCollection, writeVariableValue } from './variable'\nexport type { FigmaComposedColor, FigmaVariableAlias, FigmaVariableValue } from './values'\nexport {\n figmaBoundVariables,\n paintBindings,\n setLayerBinding,\n setPaintBindings,\n type FigmaBindableField\n} from './bindings'\n\n/** Figma's variable types, including the motion types Pairdraw does not model. */\nconst FIGMA_TYPES = ['BOOLEAN', 'COLOR', 'FLOAT', 'STRING', 'EASING', 'TIMING'] as const\nexport type FigmaVariableResolvedType = (typeof FIGMA_TYPES)[number]\n\nfunction assertType(method: string, type: unknown): FigmaVariableResolvedType {\n if (!(FIGMA_TYPES as readonly unknown[]).includes(type)) {\n throw new Error(\n `in ${method}: Property \"resolvedType\" failed validation: Invalid option: expected one of ` +\n FIGMA_TYPES.map((name) => `\"${name}\"`).join('|')\n )\n }\n return type as FigmaVariableResolvedType\n}\n\nfunction isModelledType(type: FigmaVariableResolvedType): type is VariableType {\n return Object.hasOwn(FIGMA_DEFAULT_VALUES, type)\n}\n\n/** A solid paint as `setBoundVariableForPaint` takes and returns it. */\ntype FigmaSolidPaint = {\n readonly type: string\n readonly boundVariables?: { color?: FigmaVariableAlias }\n}\n\n/** `figma.variables`: the document's variables and collections, as Figma's plugin API has them. */\nexport class FigmaVariablesAPI {\n readonly #graph: SceneGraph\n\n constructor(graph: SceneGraph) {\n this.#graph = graph\n }\n\n getVariableById(id: string): FigmaVariable | null {\n return this.#graph.variables.has(id) ? new FigmaVariable(this.#graph, id) : null\n }\n\n async getVariableByIdAsync(id: string): Promise<FigmaVariable | null> {\n return this.getVariableById(id)\n }\n\n getVariableCollectionById(id: string): FigmaVariableCollection | null {\n return this.#graph.variableCollections.has(id)\n ? new FigmaVariableCollection(this.#graph, id)\n : null\n }\n\n async getVariableCollectionByIdAsync(id: string): Promise<FigmaVariableCollection | null> {\n return this.getVariableCollectionById(id)\n }\n\n getLocalVariables(type?: FigmaVariableResolvedType): FigmaVariable[] {\n const wanted = type === undefined ? undefined : assertType('getLocalVariables', type)\n return this.#graph\n .getLiveVariables()\n .filter((variable) => wanted === undefined || variable.type === wanted)\n .map((variable) => new FigmaVariable(this.#graph, variable.id))\n }\n\n async getLocalVariablesAsync(type?: FigmaVariableResolvedType): Promise<FigmaVariable[]> {\n return this.getLocalVariables(type)\n }\n\n getLocalVariableCollections(): FigmaVariableCollection[] {\n return this.#graph\n .getLiveCollections()\n .map((collection) => new FigmaVariableCollection(this.#graph, collection.id))\n }\n\n async getLocalVariableCollectionsAsync(): Promise<FigmaVariableCollection[]> {\n return this.getLocalVariableCollections()\n }\n\n /** A variable in `collection` whose every mode starts at Figma's default for its type. */\n createVariable(\n name: string,\n collection: { readonly id: string } | string,\n resolvedType: FigmaVariableResolvedType\n ): FigmaVariable {\n const type = assertType('createVariable', resolvedType)\n if (!isModelledType(type))\n throw new Error(`in createVariable: Pairdraw does not support ${type} variables`)\n const collectionId = typeof collection === 'string' ? collection : collection.id\n if (!this.#graph.variableCollections.has(collectionId)) {\n throw new Error('in createVariable: Could not find variable collection')\n }\n assertVariableName(this.#graph, 'createVariable', name, collectionId)\n const variable = this.#graph.createVariable(\n name,\n type,\n collectionId,\n structuredClone(FIGMA_DEFAULT_VALUES[type])\n )\n return new FigmaVariable(this.#graph, variable.id)\n }\n\n createVariableCollection(name: string): FigmaVariableCollection {\n return new FigmaVariableCollection(this.#graph, this.#graph.createCollection(name).id)\n }\n\n createVariableAlias(variable: { readonly id: string }): FigmaVariableAlias {\n return variableAlias(variable.id)\n }\n\n async createVariableAliasByIdAsync(variableId: string): Promise<FigmaVariableAlias> {\n if (!this.#graph.variables.has(variableId)) {\n throw new Error('in createVariableAliasByIdAsync: Variable not found')\n }\n return variableAlias(variableId)\n }\n\n /**\n * A copy of `paint` whose colour is bound to `variable`, or unbound for `null`; it binds when the\n * paint is set on a layer. Colour is the one paint field Figma binds.\n */\n setBoundVariableForPaint<T extends FigmaSolidPaint>(\n paint: T,\n _field: 'color',\n variable: { readonly id: string } | null\n ): T & { boundVariables: { color?: FigmaVariableAlias } } {\n const { color: _previous, ...others } = paint.boundVariables ?? {}\n if (variable === null) return { ...structuredClone(paint), boundVariables: others }\n if (this.#graph.variables.get(variable.id)?.type !== 'COLOR') {\n throw new Error('in setBoundVariableForPaint: can only bind color variables to color')\n }\n return {\n ...structuredClone(paint),\n boundVariables: { ...others, color: variableAlias(variable.id) }\n }\n }\n}\n"],"mappings":";;;;;AAgBA,MAAM,cAAc;CAAC;CAAW;CAAS;CAAS;CAAU;CAAU;AAAQ;AAG9E,SAAS,WAAW,QAAgB,MAA0C;CAC5E,IAAI,CAAE,YAAmC,SAAS,IAAI,GACpD,MAAM,IAAI,MACR,MAAM,OAAO,iFACX,YAAY,KAAK,SAAS,IAAI,KAAK,EAAE,CAAC,CAAC,KAAK,GAAG,CACnD;CAEF,OAAO;AACT;AAEA,SAAS,eAAe,MAAuD;CAC7E,OAAO,OAAO,OAAO,sBAAsB,IAAI;AACjD;;AASA,IAAa,oBAAb,MAA+B;CAC7B;CAEA,YAAY,OAAmB;EAC7B,KAAKA,SAAS;CAChB;CAEA,gBAAgB,IAAkC;EAChD,OAAO,KAAKA,OAAO,UAAU,IAAI,EAAE,IAAI,IAAI,cAAc,KAAKA,QAAQ,EAAE,IAAI;CAC9E;CAEA,MAAM,qBAAqB,IAA2C;EACpE,OAAO,KAAK,gBAAgB,EAAE;CAChC;CAEA,0BAA0B,IAA4C;EACpE,OAAO,KAAKA,OAAO,oBAAoB,IAAI,EAAE,IACzC,IAAI,wBAAwB,KAAKA,QAAQ,EAAE,IAC3C;CACN;CAEA,MAAM,+BAA+B,IAAqD;EACxF,OAAO,KAAK,0BAA0B,EAAE;CAC1C;CAEA,kBAAkB,MAAmD;EACnE,MAAM,SAAS,SAAS,KAAA,IAAY,KAAA,IAAY,WAAW,qBAAqB,IAAI;EACpF,OAAO,KAAKA,OACT,iBAAiB,CAAC,CAClB,QAAQ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C;EACjE,IAAI,aAAa,MAAM,OAAO;GAAE,GAAG,gBAAgB,KAAK;GAAG,gBAAgB;EAAO;EAClF,IAAI,KAAKA,OAAO,UAAU,IAAI,SAAS,EAAE,CAAC,EAAE,SAAS,SACnD,MAAM,IAAI,MAAM,qEAAqE;EAEvF,OAAO;GACL,GAAG,gBAAgB,KAAK;GACxB,gBAAgB;IAAE,GAAG;IAAQ,OAAO,cAAc,SAAS,EAAE;GAAE;EACjE;CACF;AACF"}
|
|
@@ -21,7 +21,7 @@ function knownTokens(graph) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
const byCondition = /* @__PURE__ */ new Map();
|
|
24
|
-
for (const collection of graph.
|
|
24
|
+
for (const collection of graph.getLiveCollections()) {
|
|
25
25
|
if (isLibraryCollection(collection)) continue;
|
|
26
26
|
for (const mode of collection.modes) {
|
|
27
27
|
if (mode.modeId === collection.defaultModeId) continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"known.js","names":[],"sources":["../../../../../src/io/formats/design-tokens/css/known.ts"],"sourcesContent":["import {\n collectionVariables,\n defaultModeCondition,\n modeConditionKey,\n variableCSSNames\n} from '@pairdraw/dom-css/export'\nimport {\n isLibraryCollection,\n type SceneGraph,\n type Variable,\n type VariableCollection,\n type VariableCollectionMode\n} from '@pairdraw/scene-graph'\n\n/** A variable the stylesheet names, with the collection that holds it. */\nexport interface KnownVariable {\n variable: Variable\n collection: VariableCollection\n /** Whether a library holds it, so an import leaves it alone. */\n library: boolean\n}\n\nexport interface KnownMode {\n collection: VariableCollection\n mode: VariableCollectionMode\n}\n\n/** The document's variables by custom property name, and its modes by the scope they apply in. */\nexport interface KnownTokens {\n byCSSName: Map<string, KnownVariable>\n byCondition: Map<string, KnownMode>\n}\n\n/**\n * What a stylesheet's names and scopes are in this document, as its token stylesheet writes them:\n * each variable by the custom property it is written as, and each mode other than a collection's\n * default by its condition, compared in the form `modeConditionKey` gives.\n */\nexport function knownTokens(graph: SceneGraph): KnownTokens {\n const variables = collectionVariables(graph)\n const names = variableCSSNames(variables)\n const byCSSName = new Map<string, KnownVariable>()\n for (const variable of variables) {\n const collection = graph.variableCollections.get(variable.collectionId)\n const name = names.get(variable.id)\n if (!collection || !name) continue\n byCSSName.set(name, { variable, collection, library: isLibraryCollection(collection) })\n }\n const byCondition = new Map<string, KnownMode>()\n for (const collection of graph.
|
|
1
|
+
{"version":3,"file":"known.js","names":[],"sources":["../../../../../src/io/formats/design-tokens/css/known.ts"],"sourcesContent":["import {\n collectionVariables,\n defaultModeCondition,\n modeConditionKey,\n variableCSSNames\n} from '@pairdraw/dom-css/export'\nimport {\n isLibraryCollection,\n type SceneGraph,\n type Variable,\n type VariableCollection,\n type VariableCollectionMode\n} from '@pairdraw/scene-graph'\n\n/** A variable the stylesheet names, with the collection that holds it. */\nexport interface KnownVariable {\n variable: Variable\n collection: VariableCollection\n /** Whether a library holds it, so an import leaves it alone. */\n library: boolean\n}\n\nexport interface KnownMode {\n collection: VariableCollection\n mode: VariableCollectionMode\n}\n\n/** The document's variables by custom property name, and its modes by the scope they apply in. */\nexport interface KnownTokens {\n byCSSName: Map<string, KnownVariable>\n byCondition: Map<string, KnownMode>\n}\n\n/**\n * What a stylesheet's names and scopes are in this document, as its token stylesheet writes them:\n * each variable by the custom property it is written as, and each mode other than a collection's\n * default by its condition, compared in the form `modeConditionKey` gives.\n */\nexport function knownTokens(graph: SceneGraph): KnownTokens {\n const variables = collectionVariables(graph)\n const names = variableCSSNames(variables)\n const byCSSName = new Map<string, KnownVariable>()\n for (const variable of variables) {\n const collection = graph.variableCollections.get(variable.collectionId)\n const name = names.get(variable.id)\n if (!collection || !name) continue\n byCSSName.set(name, { variable, collection, library: isLibraryCollection(collection) })\n }\n const byCondition = new Map<string, KnownMode>()\n for (const collection of graph.getLiveCollections()) {\n if (isLibraryCollection(collection)) continue\n for (const mode of collection.modes) {\n if (mode.modeId === collection.defaultModeId) continue\n const key = modeConditionKey(mode.condition ?? defaultModeCondition(collection, mode))\n if (!byCondition.has(key)) byCondition.set(key, { collection, mode })\n }\n }\n return { byCSSName, byCondition }\n}\n"],"mappings":";;;;;;;;AAsCA,SAAgB,YAAY,OAAgC;CAC1D,MAAM,YAAY,oBAAoB,KAAK;CAC3C,MAAM,QAAQ,iBAAiB,SAAS;CACxC,MAAM,4BAAY,IAAI,IAA2B;CACjD,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,aAAa,MAAM,oBAAoB,IAAI,SAAS,YAAY;EACtE,MAAM,OAAO,MAAM,IAAI,SAAS,EAAE;EAClC,IAAI,CAAC,cAAc,CAAC,MAAM;EAC1B,UAAU,IAAI,MAAM;GAAE;GAAU;GAAY,SAAS,oBAAoB,UAAU;EAAE,CAAC;CACxF;CACA,MAAM,8BAAc,IAAI,IAAuB;CAC/C,KAAK,MAAM,cAAc,MAAM,mBAAmB,GAAG;EACnD,IAAI,oBAAoB,UAAU,GAAG;EACrC,KAAK,MAAM,QAAQ,WAAW,OAAO;GACnC,IAAI,KAAK,WAAW,WAAW,eAAe;GAC9C,MAAM,MAAM,iBAAiB,KAAK,aAAa,qBAAqB,YAAY,IAAI,CAAC;GACrF,IAAI,CAAC,YAAY,IAAI,GAAG,GAAG,YAAY,IAAI,KAAK;IAAE;IAAY;GAAK,CAAC;EACtE;CACF;CACA,OAAO;EAAE;EAAW;CAAY;AAClC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { DesignTokenBundle } from "../read.js";
|
|
2
|
-
import { SceneGraph, TokenUnit } from "@pairdraw/scene-graph";
|
|
2
|
+
import { ColorProfile, SceneGraph, TokenUnit } from "@pairdraw/scene-graph";
|
|
3
3
|
//#region src/io/formats/design-tokens/css/read.d.ts
|
|
4
4
|
interface CSSTokenReadOptions {
|
|
5
5
|
/** The stylesheet's file name, for issues. */
|
|
6
6
|
file?: string;
|
|
7
|
+
/** The document's profile: a color that names its space converts into it. */
|
|
8
|
+
profile?: ColorProfile;
|
|
7
9
|
/**
|
|
8
10
|
* What a numeric CSS expression such as `clamp(1rem, 4vw, 1.5rem)` comes to in `unit`, with
|
|
9
11
|
* the custom properties in scope by name (`--space`). A browser computes it; without one, an
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","names":[],"sources":["../../../../../src/io/formats/design-tokens/css/read.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"read.d.ts","names":[],"sources":["../../../../../src/io/formats/design-tokens/css/read.ts"],"mappings":";;;UAuCiB;;EAEf;;EAEA,UAAU;;;;;;EAMV,qBACE,aACA,MAAM,WACN,QAAQ;;;;;;;;;;iBAiVI,oBACd,OAAO,YACP,aACA,UAAS,sBACR"}
|
|
@@ -38,7 +38,7 @@ var CSSTokenReader = class {
|
|
|
38
38
|
group(name) {
|
|
39
39
|
const found = this.groups.get(name);
|
|
40
40
|
if (found) return found;
|
|
41
|
-
const existing =
|
|
41
|
+
const existing = this.graph.getLiveCollections().find((collection) => collection.name === name && !isLibraryCollection(collection));
|
|
42
42
|
const defaultName = existing?.modes.find((mode) => mode.modeId === existing.defaultModeId)?.name ?? "Default";
|
|
43
43
|
const group = {
|
|
44
44
|
name,
|
|
@@ -163,7 +163,7 @@ var CSSTokenReader = class {
|
|
|
163
163
|
const property = cssTokenProperty(token);
|
|
164
164
|
const value = property && scope.get(property);
|
|
165
165
|
if (!value) continue;
|
|
166
|
-
const read = readCSSTokenValue(value);
|
|
166
|
+
const read = readCSSTokenValue(value, { profile: this.options.profile });
|
|
167
167
|
if (read.kind === "number") return read.unit;
|
|
168
168
|
if (read.kind === "expression" && read.unit) return read.unit;
|
|
169
169
|
}
|
|
@@ -186,12 +186,15 @@ var CSSTokenReader = class {
|
|
|
186
186
|
token(name, css, group, mode, scope) {
|
|
187
187
|
const existing = this.existingVariable(name, group);
|
|
188
188
|
const tokenName = this.tokenName(name, group);
|
|
189
|
-
const value = readCSSTokenValue(css, {
|
|
189
|
+
const value = readCSSTokenValue(css, {
|
|
190
|
+
font: namesFont(name),
|
|
191
|
+
profile: this.options.profile
|
|
192
|
+
});
|
|
190
193
|
let fields;
|
|
191
194
|
if (value.kind === "reference") fields = this.alias(value.name);
|
|
192
195
|
else if (value.kind === "color") fields = {
|
|
193
196
|
type: "color",
|
|
194
|
-
value: colorTokenValue(value.color)
|
|
197
|
+
value: colorTokenValue(value.color, this.options.profile)
|
|
195
198
|
};
|
|
196
199
|
else if (value.kind === "number") fields = {
|
|
197
200
|
...numberToken(value.value, value.unit),
|
|
@@ -314,7 +317,10 @@ function readCSSDesignTokens(graph, css, options = {}) {
|
|
|
314
317
|
}]
|
|
315
318
|
};
|
|
316
319
|
}
|
|
317
|
-
const reader = new CSSTokenReader(graph, knownTokens(graph), file,
|
|
320
|
+
const reader = new CSSTokenReader(graph, knownTokens(graph), file, {
|
|
321
|
+
...options,
|
|
322
|
+
profile: options.profile ?? graph.documentColorSpace
|
|
323
|
+
});
|
|
318
324
|
reader.read(sheet);
|
|
319
325
|
const issues = [...sheet.skipped.map((rule) => ({
|
|
320
326
|
kind: "unsupported-css",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","names":[],"sources":["../../../../../src/io/formats/design-tokens/css/read.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\nimport { upperFirst } from 'es-toolkit/string'\n\nimport {\n cssNameCodeSyntax,\n cssNameVariableName,\n cssTokenProperty,\n cssValueTokens,\n modeConditionKey,\n modeConditionName,\n readCustomProperties,\n tokenSlug,\n variableUnit,\n type CustomPropertyScope,\n type CustomPropertySheet\n} from '@pairdraw/dom-css/export'\nimport {\n isLibraryCollection,\n type SceneGraph,\n type TokenUnit,\n type Variable,\n type VariableCollection\n} from '@pairdraw/scene-graph'\nimport { tokenNumberInUnit } from '@pairdraw/scene-graph/variables'\n\nimport { tokenPath } from '#core/io/formats/design-tokens/paths'\nimport type {\n DesignTokenBundle,\n DesignTokenReadIssue,\n ReadCollection,\n ReadToken\n} from '#core/io/formats/design-tokens/read'\nimport { PAIRDRAW_EXTENSION } from '#core/io/formats/design-tokens/types'\nimport { colorTokenValue, trimNumber } from '#core/io/formats/design-tokens/values'\n\nimport { knownTokens, type KnownTokens } from './known'\nimport { namesFont, readCSSTokenValue, type CSSTokenValue } from './values'\n\nexport interface CSSTokenReadOptions {\n /** The stylesheet's file name, for issues. */\n file?: string\n /**\n * What a numeric CSS expression such as `clamp(1rem, 4vw, 1.5rem)` comes to in `unit`, with\n * the custom properties in scope by name (`--space`). A browser computes it; without one, an\n * expression keeps the number its variable already has, and a new one is skipped.\n */\n resolveExpression?: (\n css: string,\n unit: TokenUnit,\n tokens: ReadonlyMap<string, string>\n ) => number | undefined\n}\n\ninterface ModeDraft {\n name: string\n /** The scope's condition, or null for the base set. */\n key: string | null\n /** The condition the mode stores; undefined where its collection's attribute implies it. */\n condition: string | undefined\n values: Map<string, string>\n}\n\ninterface Group {\n name: string\n existing: VariableCollection | undefined\n modeAttribute: string | undefined\n /** The default mode first, which holds the base set. */\n modes: ModeDraft[]\n}\n\ninterface TokenFields {\n type: ReadToken['type']\n value: unknown\n unit?: TokenUnit\n expression?: string\n aliasData?: { targetVariableName: string; targetVariableSetName: string }\n}\n\n/** `data-theme` reads as the collection `Theme`. */\nfunction attributeCollectionName(attribute: string): string {\n return upperFirst(attribute.replace(/^data-/i, '')) || attribute\n}\n\n/** `.dark` and `@media (prefers-color-scheme: dark)` are `dark`; other conditions as written. */\nfunction conditionModeName(key: string): string {\n return modeConditionName(key) ?? key.replace(/^@[\\w-]+\\s+/, '')\n}\n\nfunction defaultAttribute(name: string): string {\n return `data-${tokenSlug(name) || 'mode'}`\n}\n\nclass CSSTokenReader {\n readonly groups = new Map<string, Group>()\n readonly base = new Map<string, string>()\n readonly owners = new Map<string, Group>()\n readonly issues: DesignTokenReadIssue[] = []\n\n constructor(\n readonly graph: SceneGraph,\n readonly known: KnownTokens,\n readonly file: string,\n readonly options: CSSTokenReadOptions\n ) {}\n\n group(name: string): Group {\n const found = this.groups.get(name)\n if (found) return found\n const existing = [...this.graph.variableCollections.values()].find(\n (collection) => collection.name === name && !isLibraryCollection(collection)\n )\n const defaultName =\n existing?.modes.find((mode) => mode.modeId === existing.defaultModeId)?.name ?? 'Default'\n const group: Group = {\n name,\n existing,\n modeAttribute: existing?.modeAttribute,\n modes: [{ name: defaultName, key: null, condition: undefined, values: this.base }]\n }\n this.groups.set(name, group)\n return group\n }\n\n addMode(group: Group, name: string, key: string, condition: string | undefined): ModeDraft {\n const same = group.modes.find((mode) => mode.key === key)\n if (same) return same\n let unique = name\n for (let n = 2; group.modes.some((mode) => mode.name === unique); n++) unique = `${name} ${n}`\n const mode: ModeDraft = { name: unique, key, condition, values: new Map() }\n group.modes.push(mode)\n return mode\n }\n\n /** The collection and mode a scope's condition belongs to. */\n placeMode(scope: CustomPropertyScope, key: string): ModeDraft {\n const match = this.known.byCondition.get(key)\n if (match)\n return this.addMode(\n this.group(match.collection.name),\n match.mode.name,\n key,\n match.mode.condition\n )\n const { label, attribute } = scope\n const group = this.group(\n label?.collection ?? (attribute ? attributeCollectionName(attribute.name) : 'Theme')\n )\n const name = label?.mode ?? attribute?.value ?? conditionModeName(key)\n if (attribute && !group.existing && group.modeAttribute === undefined)\n group.modeAttribute = attribute.name\n const implied = `[${group.modeAttribute ?? defaultAttribute(group.name)}=\"${tokenSlug(name)}\"]`\n return this.addMode(group, name, key, modeConditionKey(implied) === key ? undefined : key)\n }\n\n read(sheet: CustomPropertySheet) {\n for (const scope of sheet.scopes) {\n if (scope.condition !== null) continue\n for (const { name, value } of scope.declarations) this.base.set(name, value)\n }\n const names = [...this.base.keys()]\n for (const scope of sheet.scopes) {\n if (scope.condition === null) continue\n const mode = this.placeMode(scope, scope.condition)\n for (const { name, value } of scope.declarations) {\n mode.values.set(name, value)\n names.push(name)\n }\n }\n this.assignOwners(uniq(names))\n this.reportForeignOverrides()\n }\n\n /**\n * Each property's collection: the one whose variable it already is, else the first whose mode\n * changes it, else the only collection with modes, else `Tokens`. A library's variables are\n * the library's, so the import leaves them out.\n */\n assignOwners(names: string[]) {\n const unowned = new Set<string>()\n for (const name of names) {\n const known = this.known.byCSSName.get(name)\n if (known?.library) continue\n if (known) this.owners.set(name, this.group(known.collection.name))\n else unowned.add(name)\n }\n for (const group of this.groups.values())\n for (const mode of group.modes.slice(1))\n for (const name of mode.values.keys())\n if (unowned.has(name) && !this.owners.has(name)) this.owners.set(name, group)\n const rest = [...unowned].filter((name) => !this.owners.has(name))\n if (rest.length === 0) return\n const withModes = [...this.groups.values()].filter((group) => group.modes.length > 1)\n const fallback = withModes.length === 1 ? withModes[0] : this.group('Tokens')\n for (const name of rest) this.owners.set(name, fallback)\n }\n\n /** A mode that changes another collection's variable cannot say so: a variable varies by one. */\n reportForeignOverrides() {\n for (const group of this.groups.values()) {\n for (const mode of group.modes.slice(1)) {\n for (const [name, value] of mode.values) {\n const owner = this.owners.get(name)\n if (!owner || owner === group) continue\n if (value.replaceAll(/\\s+/g, '') === this.base.get(name)?.replaceAll(/\\s+/g, '')) continue\n this.issues.push({\n kind: 'foreign-css-override',\n file: this.file,\n rule: mode.key ?? ':root',\n property: `--${name}`,\n collection: owner.name\n })\n }\n }\n }\n }\n\n existingVariable(name: string, group: Group): Variable | undefined {\n const known = this.known.byCSSName.get(name)\n return known && !known.library && known.collection === group.existing\n ? known.variable\n : undefined\n }\n\n tokenName(name: string, group: Group): string {\n return this.existingVariable(name, group)?.name ?? cssNameVariableName(name)\n }\n\n /** An alias by collection and variable name, as Figma's alias data names one. */\n alias(target: string): TokenFields {\n const group = this.owners.get(target)\n const known = this.known.byCSSName.get(target)\n const targetName = group ? this.tokenName(target, group) : known?.variable.name\n const setName = group?.name ?? known?.collection.name\n if (!targetName || !setName) return { type: undefined, value: `{${target}}` }\n return {\n type: undefined,\n value: `{${tokenPath(targetName).join('.')}}`,\n aliasData: { targetVariableName: targetName, targetVariableSetName: setName }\n }\n }\n\n /** The unit an expression takes from a token it names, `calc(var(--space) * 2)` from `--space`. */\n referencedUnit(css: string, scope: ReadonlyMap<string, string>): TokenUnit | undefined {\n for (const token of cssValueTokens(css)) {\n const property = cssTokenProperty(token)\n const value = property && scope.get(property)\n if (!value) continue\n const read = readCSSTokenValue(value)\n if (read.kind === 'number') return read.unit\n if (read.kind === 'expression' && read.unit) return read.unit\n }\n return undefined\n }\n\n expression(\n value: Extract<CSSTokenValue, { kind: 'expression' }>,\n existing: Variable | undefined,\n group: Group,\n mode: ModeDraft,\n scope: ReadonlyMap<string, string>\n ): TokenFields | undefined {\n const unit =\n value.unit ??\n this.referencedUnit(value.css, scope) ??\n (existing ? variableUnit(existing) : 'none')\n let resolved = this.options.resolveExpression?.(value.css, unit, scope)\n if (resolved === undefined && existing) {\n const modeId = group.existing?.modes.find((candidate) => candidate.name === mode.name)?.modeId\n const current = modeId ? existing.valuesByMode[modeId] : undefined\n if (typeof current === 'number') resolved = current\n }\n if (resolved === undefined) return undefined\n return { ...numberToken(resolved, unit), unit, expression: value.css }\n }\n\n token(\n name: string,\n css: string,\n group: Group,\n mode: ModeDraft,\n scope: ReadonlyMap<string, string>\n ): ReadToken {\n const existing = this.existingVariable(name, group)\n const tokenName = this.tokenName(name, group)\n const value = readCSSTokenValue(css, { font: namesFont(name) })\n let fields: TokenFields\n if (value.kind === 'reference') fields = this.alias(value.name)\n else if (value.kind === 'color') fields = { type: 'color', value: colorTokenValue(value.color) }\n else if (value.kind === 'number')\n fields = { ...numberToken(value.value, value.unit), unit: value.unit }\n else if (value.kind === 'string') fields = { type: 'string', value: value.value }\n else if (value.kind === 'font') fields = { type: 'fontFamily', value: value.family }\n else if (value.kind === 'expression')\n fields = this.expression(value, existing, group, mode, scope) ?? {\n type: 'number',\n value: css\n }\n else fields = { type: undefined, value: css }\n const own = existing\n ? {\n unit: unitFor(existing, fields.unit),\n scopes: existing.scopes,\n codeSyntax: existing.codeSyntax,\n hiddenFromPublishing: existing.hiddenFromPublishing,\n expression: fields.expression\n }\n : {\n unit: fields.unit,\n codeSyntax: { WEB: cssNameCodeSyntax(name) },\n expression: fields.expression\n }\n return {\n path: tokenPath(tokenName),\n name: tokenName,\n type: fields.type,\n value: fields.value,\n description: undefined,\n extensions: {\n [PAIRDRAW_EXTENSION]: own,\n ...(fields.aliasData ? { 'com.figma.aliasData': fields.aliasData } : {})\n }\n }\n }\n\n collections(): ReadCollection[] {\n const collections: ReadCollection[] = []\n for (const group of this.groups.values()) {\n const owned = [...this.owners].flatMap(([name, owner]) => (owner === group ? [name] : []))\n if (owned.length === 0) continue\n const modes = group.modes.flatMap((mode, index) => {\n if (index > 0 && !owned.some((name) => mode.values.has(name))) return []\n const scope = new Map(\n [...this.base, ...mode.values].map(([name, value]) => [`--${name}`, value])\n )\n // A mode's block inherits every base value it leaves out, as it does on a page.\n const tokens = owned.flatMap((name) => {\n const css = mode.values.get(name) ?? this.base.get(name)\n return css === undefined ? [] : [this.token(name, css, group, mode, scope)]\n })\n return [{ name: mode.name, tokens, isDefault: index === 0, condition: mode.condition }]\n })\n const modeAttribute =\n group.modeAttribute === defaultAttribute(group.name) ? undefined : group.modeAttribute\n collections.push({\n name: group.name,\n modes,\n modeAttribute: group.existing ? undefined : modeAttribute\n })\n }\n return collections\n }\n}\n\n/** A number token in the type its unit is written as, which the token decoder reads back. */\nfunction numberToken(stored: number, unit: TokenUnit): TokenFields {\n if (unit === 'px' || unit === 'rem')\n return {\n type: 'dimension',\n value: { value: trimNumber(tokenNumberInUnit(stored, unit)), unit }\n }\n if (unit === 'ms' || unit === 's')\n return { type: 'duration', value: { value: trimNumber(stored), unit } }\n return { type: 'number', value: trimNumber(stored) }\n}\n\n/** An updated variable keeps the unit it has unless the stylesheet writes another. */\nfunction unitFor(existing: Variable, unit: TokenUnit | undefined): TokenUnit | undefined {\n if (existing.type !== 'FLOAT') return undefined\n return unit === undefined || unit === variableUnit(existing) ? existing.unit : unit\n}\n\n/**\n * The custom properties of a stylesheet as collections and modes, ready for `planTokenImport`:\n * the inverse of the token stylesheet. `:root` is each collection's default mode; a selector such\n * as `[data-theme=\"dark\"]` or `.dark`, or a `:root` block in `@media`, `@supports`, or\n * `@container`, is a mode. Properties and conditions the document already writes map back to its\n * variables and modes, so a stylesheet exported from it imports onto the same collections.\n * Elsewhere a `Collection: Mode` comment, the attribute, or the condition names the mode.\n */\nexport function readCSSDesignTokens(\n graph: SceneGraph,\n css: string,\n options: CSSTokenReadOptions = {}\n): DesignTokenBundle {\n const file = options.file ?? 'stylesheet.css'\n let sheet: CustomPropertySheet\n try {\n sheet = readCustomProperties(css)\n } catch {\n return { collections: [], composites: [], issues: [{ kind: 'invalid-file', file }] }\n }\n const reader = new CSSTokenReader(graph, knownTokens(graph), file, options)\n reader.read(sheet)\n const issues: DesignTokenReadIssue[] = [\n ...sheet.skipped.map((rule): DesignTokenReadIssue => ({ kind: 'unsupported-css', file, rule })),\n ...reader.issues\n ]\n return { collections: reader.collections(), composites: [], issues }\n}\n"],"mappings":";;;;;;;;;;;;AA+EA,SAAS,wBAAwB,WAA2B;CAC1D,OAAO,WAAW,UAAU,QAAQ,WAAW,EAAE,CAAC,KAAK;AACzD;;AAGA,SAAS,kBAAkB,KAAqB;CAC9C,OAAO,kBAAkB,GAAG,KAAK,IAAI,QAAQ,eAAe,EAAE;AAChE;AAEA,SAAS,iBAAiB,MAAsB;CAC9C,OAAO,QAAQ,UAAU,IAAI,KAAK;AACpC;AAEA,IAAM,iBAAN,MAAqB;CAOR;CACA;CACA;CACA;CATX,yBAAkB,IAAI,IAAmB;CACzC,uBAAgB,IAAI,IAAoB;CACxC,yBAAkB,IAAI,IAAmB;CACzC,SAA0C,CAAC;CAE3C,YACE,OACA,OACA,MACA,SACA;EAJS,KAAA,QAAA;EACA,KAAA,QAAA;EACA,KAAA,OAAA;EACA,KAAA,UAAA;CACR;CAEH,MAAM,MAAqB;EACzB,MAAM,QAAQ,KAAK,OAAO,IAAI,IAAI;EAClC,IAAI,OAAO,OAAO;EAClB,MAAM,WAAW,CAAC,GAAG,KAAK,MAAM,oBAAoB,OAAO,CAAC,C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SAAS,QAAQ,UAAoB,MAAoD;CACvF,IAAI,SAAS,SAAS,SAAS,OAAO,KAAA;CACtC,OAAO,SAAS,KAAA,KAAa,SAAS,aAAa,QAAQ,IAAI,SAAS,OAAO;AACjF;;;;;;;;;AAUA,SAAgB,oBACd,OACA,KACA,UAA+B,CAAC,GACb;CACnB,MAAM,OAAO,QAAQ,QAAQ;CAC7B,IAAI;CACJ,IAAI;EACF,QAAQ,qBAAqB,GAAG;CAClC,QAAQ;EACN,OAAO;GAAE,aAAa,CAAC;GAAG,YAAY,CAAC;GAAG,QAAQ,CAAC;IAAE,MAAM;IAAgB;GAAK,CAAC;EAAE;CACrF;CACA,MAAM,SAAS,IAAI,eAAe,OAAO,YAAY,KAAK,GAAG,MAAM,OAAO;CAC1E,OAAO,KAAK,KAAK;CACjB,MAAM,SAAiC,CACrC,GAAG,MAAM,QAAQ,KAAK,UAAgC;EAAE,MAAM;EAAmB;EAAM;CAAK,EAAE,GAC9F,GAAG,OAAO,MACZ;CACA,OAAO;EAAE,aAAa,OAAO,YAAY;EAAG,YAAY,CAAC;EAAG;CAAO;AACrE"}
|
|
1
|
+
{"version":3,"file":"read.js","names":[],"sources":["../../../../../src/io/formats/design-tokens/css/read.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\nimport { upperFirst } from 'es-toolkit/string'\n\nimport {\n cssNameCodeSyntax,\n cssNameVariableName,\n cssTokenProperty,\n cssValueTokens,\n modeConditionKey,\n modeConditionName,\n readCustomProperties,\n tokenSlug,\n variableUnit,\n type CustomPropertyScope,\n type CustomPropertySheet\n} from '@pairdraw/dom-css/export'\nimport {\n isLibraryCollection,\n type ColorProfile,\n type SceneGraph,\n type TokenUnit,\n type Variable,\n type VariableCollection\n} from '@pairdraw/scene-graph'\nimport { tokenNumberInUnit } from '@pairdraw/scene-graph/variables'\n\nimport { tokenPath } from '#core/io/formats/design-tokens/paths'\nimport type {\n DesignTokenBundle,\n DesignTokenReadIssue,\n ReadCollection,\n ReadToken\n} from '#core/io/formats/design-tokens/read'\nimport { PAIRDRAW_EXTENSION } from '#core/io/formats/design-tokens/types'\nimport { colorTokenValue, trimNumber } from '#core/io/formats/design-tokens/values'\n\nimport { knownTokens, type KnownTokens } from './known'\nimport { namesFont, readCSSTokenValue, type CSSTokenValue } from './values'\n\nexport interface CSSTokenReadOptions {\n /** The stylesheet's file name, for issues. */\n file?: string\n /** The document's profile: a color that names its space converts into it. */\n profile?: ColorProfile\n /**\n * What a numeric CSS expression such as `clamp(1rem, 4vw, 1.5rem)` comes to in `unit`, with\n * the custom properties in scope by name (`--space`). A browser computes it; without one, an\n * expression keeps the number its variable already has, and a new one is skipped.\n */\n resolveExpression?: (\n css: string,\n unit: TokenUnit,\n tokens: ReadonlyMap<string, string>\n ) => number | undefined\n}\n\ninterface ModeDraft {\n name: string\n /** The scope's condition, or null for the base set. */\n key: string | null\n /** The condition the mode stores; undefined where its collection's attribute implies it. */\n condition: string | undefined\n values: Map<string, string>\n}\n\ninterface Group {\n name: string\n existing: VariableCollection | undefined\n modeAttribute: string | undefined\n /** The default mode first, which holds the base set. */\n modes: ModeDraft[]\n}\n\ninterface TokenFields {\n type: ReadToken['type']\n value: unknown\n unit?: TokenUnit\n expression?: string\n aliasData?: { targetVariableName: string; targetVariableSetName: string }\n}\n\n/** `data-theme` reads as the collection `Theme`. */\nfunction attributeCollectionName(attribute: string): string {\n return upperFirst(attribute.replace(/^data-/i, '')) || attribute\n}\n\n/** `.dark` and `@media (prefers-color-scheme: dark)` are `dark`; other conditions as written. */\nfunction conditionModeName(key: string): string {\n return modeConditionName(key) ?? key.replace(/^@[\\w-]+\\s+/, '')\n}\n\nfunction defaultAttribute(name: string): string {\n return `data-${tokenSlug(name) || 'mode'}`\n}\n\nclass CSSTokenReader {\n readonly groups = new Map<string, Group>()\n readonly base = new Map<string, string>()\n readonly owners = new Map<string, Group>()\n readonly issues: DesignTokenReadIssue[] = []\n\n constructor(\n readonly graph: SceneGraph,\n readonly known: KnownTokens,\n readonly file: string,\n readonly options: CSSTokenReadOptions\n ) {}\n\n group(name: string): Group {\n const found = this.groups.get(name)\n if (found) return found\n const existing = this.graph\n .getLiveCollections()\n .find((collection) => collection.name === name && !isLibraryCollection(collection))\n const defaultName =\n existing?.modes.find((mode) => mode.modeId === existing.defaultModeId)?.name ?? 'Default'\n const group: Group = {\n name,\n existing,\n modeAttribute: existing?.modeAttribute,\n modes: [{ name: defaultName, key: null, condition: undefined, values: this.base }]\n }\n this.groups.set(name, group)\n return group\n }\n\n addMode(group: Group, name: string, key: string, condition: string | undefined): ModeDraft {\n const same = group.modes.find((mode) => mode.key === key)\n if (same) return same\n let unique = name\n for (let n = 2; group.modes.some((mode) => mode.name === unique); n++) unique = `${name} ${n}`\n const mode: ModeDraft = { name: unique, key, condition, values: new Map() }\n group.modes.push(mode)\n return mode\n }\n\n /** The collection and mode a scope's condition belongs to. */\n placeMode(scope: CustomPropertyScope, key: string): ModeDraft {\n const match = this.known.byCondition.get(key)\n if (match)\n return this.addMode(\n this.group(match.collection.name),\n match.mode.name,\n key,\n match.mode.condition\n )\n const { label, attribute } = scope\n const group = this.group(\n label?.collection ?? (attribute ? attributeCollectionName(attribute.name) : 'Theme')\n )\n const name = label?.mode ?? attribute?.value ?? conditionModeName(key)\n if (attribute && !group.existing && group.modeAttribute === undefined)\n group.modeAttribute = attribute.name\n const implied = `[${group.modeAttribute ?? defaultAttribute(group.name)}=\"${tokenSlug(name)}\"]`\n return this.addMode(group, name, key, modeConditionKey(implied) === key ? undefined : key)\n }\n\n read(sheet: CustomPropertySheet) {\n for (const scope of sheet.scopes) {\n if (scope.condition !== null) continue\n for (const { name, value } of scope.declarations) this.base.set(name, value)\n }\n const names = [...this.base.keys()]\n for (const scope of sheet.scopes) {\n if (scope.condition === null) continue\n const mode = this.placeMode(scope, scope.condition)\n for (const { name, value } of scope.declarations) {\n mode.values.set(name, value)\n names.push(name)\n }\n }\n this.assignOwners(uniq(names))\n this.reportForeignOverrides()\n }\n\n /**\n * Each property's collection: the one whose variable it already is, else the first whose mode\n * changes it, else the only collection with modes, else `Tokens`. A library's variables are\n * the library's, so the import leaves them out.\n */\n assignOwners(names: string[]) {\n const unowned = new Set<string>()\n for (const name of names) {\n const known = this.known.byCSSName.get(name)\n if (known?.library) continue\n if (known) this.owners.set(name, this.group(known.collection.name))\n else unowned.add(name)\n }\n for (const group of this.groups.values())\n for (const mode of group.modes.slice(1))\n for (const name of mode.values.keys())\n if (unowned.has(name) && !this.owners.has(name)) this.owners.set(name, group)\n const rest = [...unowned].filter((name) => !this.owners.has(name))\n if (rest.length === 0) return\n const withModes = [...this.groups.values()].filter((group) => group.modes.length > 1)\n const fallback = withModes.length === 1 ? withModes[0] : this.group('Tokens')\n for (const name of rest) this.owners.set(name, fallback)\n }\n\n /** A mode that changes another collection's variable cannot say so: a variable varies by one. */\n reportForeignOverrides() {\n for (const group of this.groups.values()) {\n for (const mode of group.modes.slice(1)) {\n for (const [name, value] of mode.values) {\n const owner = this.owners.get(name)\n if (!owner || owner === group) continue\n if (value.replaceAll(/\\s+/g, '') === this.base.get(name)?.replaceAll(/\\s+/g, '')) continue\n this.issues.push({\n kind: 'foreign-css-override',\n file: this.file,\n rule: mode.key ?? ':root',\n property: `--${name}`,\n collection: owner.name\n })\n }\n }\n }\n }\n\n existingVariable(name: string, group: Group): Variable | undefined {\n const known = this.known.byCSSName.get(name)\n return known && !known.library && known.collection === group.existing\n ? known.variable\n : undefined\n }\n\n tokenName(name: string, group: Group): string {\n return this.existingVariable(name, group)?.name ?? cssNameVariableName(name)\n }\n\n /** An alias by collection and variable name, as Figma's alias data names one. */\n alias(target: string): TokenFields {\n const group = this.owners.get(target)\n const known = this.known.byCSSName.get(target)\n const targetName = group ? this.tokenName(target, group) : known?.variable.name\n const setName = group?.name ?? known?.collection.name\n if (!targetName || !setName) return { type: undefined, value: `{${target}}` }\n return {\n type: undefined,\n value: `{${tokenPath(targetName).join('.')}}`,\n aliasData: { targetVariableName: targetName, targetVariableSetName: setName }\n }\n }\n\n /** The unit an expression takes from a token it names, `calc(var(--space) * 2)` from `--space`. */\n referencedUnit(css: string, scope: ReadonlyMap<string, string>): TokenUnit | undefined {\n for (const token of cssValueTokens(css)) {\n const property = cssTokenProperty(token)\n const value = property && scope.get(property)\n if (!value) continue\n const read = readCSSTokenValue(value, { profile: this.options.profile })\n if (read.kind === 'number') return read.unit\n if (read.kind === 'expression' && read.unit) return read.unit\n }\n return undefined\n }\n\n expression(\n value: Extract<CSSTokenValue, { kind: 'expression' }>,\n existing: Variable | undefined,\n group: Group,\n mode: ModeDraft,\n scope: ReadonlyMap<string, string>\n ): TokenFields | undefined {\n const unit =\n value.unit ??\n this.referencedUnit(value.css, scope) ??\n (existing ? variableUnit(existing) : 'none')\n let resolved = this.options.resolveExpression?.(value.css, unit, scope)\n if (resolved === undefined && existing) {\n const modeId = group.existing?.modes.find((candidate) => candidate.name === mode.name)?.modeId\n const current = modeId ? existing.valuesByMode[modeId] : undefined\n if (typeof current === 'number') resolved = current\n }\n if (resolved === undefined) return undefined\n return { ...numberToken(resolved, unit), unit, expression: value.css }\n }\n\n token(\n name: string,\n css: string,\n group: Group,\n mode: ModeDraft,\n scope: ReadonlyMap<string, string>\n ): ReadToken {\n const existing = this.existingVariable(name, group)\n const tokenName = this.tokenName(name, group)\n const value = readCSSTokenValue(css, {\n font: namesFont(name),\n profile: this.options.profile\n })\n let fields: TokenFields\n if (value.kind === 'reference') fields = this.alias(value.name)\n else if (value.kind === 'color')\n fields = {\n type: 'color',\n value: colorTokenValue(value.color, this.options.profile)\n }\n else if (value.kind === 'number')\n fields = { ...numberToken(value.value, value.unit), unit: value.unit }\n else if (value.kind === 'string') fields = { type: 'string', value: value.value }\n else if (value.kind === 'font') fields = { type: 'fontFamily', value: value.family }\n else if (value.kind === 'expression')\n fields = this.expression(value, existing, group, mode, scope) ?? {\n type: 'number',\n value: css\n }\n else fields = { type: undefined, value: css }\n const own = existing\n ? {\n unit: unitFor(existing, fields.unit),\n scopes: existing.scopes,\n codeSyntax: existing.codeSyntax,\n hiddenFromPublishing: existing.hiddenFromPublishing,\n expression: fields.expression\n }\n : {\n unit: fields.unit,\n codeSyntax: { WEB: cssNameCodeSyntax(name) },\n expression: fields.expression\n }\n return {\n path: tokenPath(tokenName),\n name: tokenName,\n type: fields.type,\n value: fields.value,\n description: undefined,\n extensions: {\n [PAIRDRAW_EXTENSION]: own,\n ...(fields.aliasData ? { 'com.figma.aliasData': fields.aliasData } : {})\n }\n }\n }\n\n collections(): ReadCollection[] {\n const collections: ReadCollection[] = []\n for (const group of this.groups.values()) {\n const owned = [...this.owners].flatMap(([name, owner]) => (owner === group ? [name] : []))\n if (owned.length === 0) continue\n const modes = group.modes.flatMap((mode, index) => {\n if (index > 0 && !owned.some((name) => mode.values.has(name))) return []\n const scope = new Map(\n [...this.base, ...mode.values].map(([name, value]) => [`--${name}`, value])\n )\n // A mode's block inherits every base value it leaves out, as it does on a page.\n const tokens = owned.flatMap((name) => {\n const css = mode.values.get(name) ?? this.base.get(name)\n return css === undefined ? [] : [this.token(name, css, group, mode, scope)]\n })\n return [{ name: mode.name, tokens, isDefault: index === 0, condition: mode.condition }]\n })\n const modeAttribute =\n group.modeAttribute === defaultAttribute(group.name) ? undefined : group.modeAttribute\n collections.push({\n name: group.name,\n modes,\n modeAttribute: group.existing ? undefined : modeAttribute\n })\n }\n return collections\n }\n}\n\n/** A number token in the type its unit is written as, which the token decoder reads back. */\nfunction numberToken(stored: number, unit: TokenUnit): TokenFields {\n if (unit === 'px' || unit === 'rem')\n return {\n type: 'dimension',\n value: { value: trimNumber(tokenNumberInUnit(stored, unit)), unit }\n }\n if (unit === 'ms' || unit === 's')\n return { type: 'duration', value: { value: trimNumber(stored), unit } }\n return { type: 'number', value: trimNumber(stored) }\n}\n\n/** An updated variable keeps the unit it has unless the stylesheet writes another. */\nfunction unitFor(existing: Variable, unit: TokenUnit | undefined): TokenUnit | undefined {\n if (existing.type !== 'FLOAT') return undefined\n return unit === undefined || unit === variableUnit(existing) ? existing.unit : unit\n}\n\n/**\n * The custom properties of a stylesheet as collections and modes, ready for `planTokenImport`:\n * the inverse of the token stylesheet. `:root` is each collection's default mode; a selector such\n * as `[data-theme=\"dark\"]` or `.dark`, or a `:root` block in `@media`, `@supports`, or\n * `@container`, is a mode. Properties and conditions the document already writes map back to its\n * variables and modes, so a stylesheet exported from it imports onto the same collections.\n * Elsewhere a `Collection: Mode` comment, the attribute, or the condition names the mode.\n */\nexport function readCSSDesignTokens(\n graph: SceneGraph,\n css: string,\n options: CSSTokenReadOptions = {}\n): DesignTokenBundle {\n const file = options.file ?? 'stylesheet.css'\n let sheet: CustomPropertySheet\n try {\n sheet = readCustomProperties(css)\n } catch {\n return { collections: [], composites: [], issues: [{ kind: 'invalid-file', file }] }\n }\n const reader = new CSSTokenReader(graph, knownTokens(graph), file, {\n ...options,\n profile: options.profile ?? graph.documentColorSpace\n })\n reader.read(sheet)\n const issues: DesignTokenReadIssue[] = [\n ...sheet.skipped.map((rule): DesignTokenReadIssue => ({ kind: 'unsupported-css', file, rule })),\n ...reader.issues\n ]\n return { collections: reader.collections(), composites: [], issues }\n}\n"],"mappings":";;;;;;;;;;;;AAkFA,SAAS,wBAAwB,WAA2B;CAC1D,OAAO,WAAW,UAAU,QAAQ,WAAW,EAAE,CAAC,KAAK;AACzD;;AAGA,SAAS,kBAAkB,KAAqB;CAC9C,OAAO,kBAAkB,GAAG,KAAK,IAAI,QAAQ,eAAe,EAAE;AAChE;AAEA,SAAS,iBAAiB,MAAsB;CAC9C,OAAO,QAAQ,UAAU,IAAI,KAAK;AACpC;AAEA,IAAM,iBAAN,MAAqB;CAOR;CACA;CACA;CACA;CATX,yBAAkB,IAAI,IAAmB;CACzC,uBAAgB,IAAI,IAAoB;CACxC,yBAAkB,IAAI,IAAmB;CACzC,SAA0C,CAAC;CAE3C,YACE,OACA,OACA,MACA,SACA;EAJS,KAAA,QAAA;EACA,KAAA,QAAA;EACA,KAAA,OAAA;EACA,KAAA,UAAA;CACR;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,CAAC;GAAG;EAAK;CACpE;CACF,IAAI,SAAS,QAAQ,SAAS,KAC5B,OAAO;EAAE,MAAM;EAAY,OAAO;GAAE,OAAO,WAAW,MAAM;GAAG;EAAK;CAAE;CACxE,OAAO;EAAE,MAAM;EAAU,OAAO,WAAW,MAAM;CAAE;AACrD;;AAGA,SAAS,QAAQ,UAAoB,MAAoD;CACvF,IAAI,SAAS,SAAS,SAAS,OAAO,KAAA;CACtC,OAAO,SAAS,KAAA,KAAa,SAAS,aAAa,QAAQ,IAAI,SAAS,OAAO;AACjF;;;;;;;;;AAUA,SAAgB,oBACd,OACA,KACA,UAA+B,CAAC,GACb;CACnB,MAAM,OAAO,QAAQ,QAAQ;CAC7B,IAAI;CACJ,IAAI;EACF,QAAQ,qBAAqB,GAAG;CAClC,QAAQ;EACN,OAAO;GAAE,aAAa,CAAC;GAAG,YAAY,CAAC;GAAG,QAAQ,CAAC;IAAE,MAAM;IAAgB;GAAK,CAAC;EAAE;CACrF;CACA,MAAM,SAAS,IAAI,eAAe,OAAO,YAAY,KAAK,GAAG,MAAM;EACjE,GAAG;EACH,SAAS,QAAQ,WAAW,MAAM;CACpC,CAAC;CACD,OAAO,KAAK,KAAK;CACjB,MAAM,SAAiC,CACrC,GAAG,MAAM,QAAQ,KAAK,UAAgC;EAAE,MAAM;EAAmB;EAAM;CAAK,EAAE,GAC9F,GAAG,OAAO,MACZ;CACA,OAAO;EAAE,aAAa,OAAO,YAAY;EAAG,YAAY,CAAC;EAAG;CAAO;AACrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","names":[],"sources":["../../../../../src/io/formats/design-tokens/css/sync.ts"],"mappings":";;;;UAYiB;EACf;;EAEA;;EAEA;;EAEA,QAAQ;;;;;;;;;;iBAkFM,qBACd,OAAO,YACP,gBACA,oBACC,KAAK;;;;;
|
|
1
|
+
{"version":3,"file":"sync.d.ts","names":[],"sources":["../../../../../src/io/formats/design-tokens/css/sync.ts"],"mappings":";;;;UAYiB;EACf;;EAEA;;EAEA;;EAEA,QAAQ;;;;;;;;;;iBAkFM,qBACd,OAAO,YACP,gBACA,oBACC,KAAK;;;;;iBA4Fc,oBACpB,OAAO,YACP,iBACC,QAAQ"}
|
|
@@ -79,6 +79,7 @@ function patchTokenStylesheet(graph, source, generated) {
|
|
|
79
79
|
const wanted = wantedScopes(generated);
|
|
80
80
|
const base = wanted.get("")?.values ?? /* @__PURE__ */ new Map();
|
|
81
81
|
const known = knownTokens(graph);
|
|
82
|
+
const profile = graph.documentColorSpace;
|
|
82
83
|
/**
|
|
83
84
|
* What a scope should declare for a property. A mode writes only what differs from its default,
|
|
84
85
|
* so a property its own collection's mode leaves out takes the default value there.
|
|
@@ -106,13 +107,19 @@ function patchTokenStylesheet(graph, source, generated) {
|
|
|
106
107
|
const want = expected(key, declaration.name);
|
|
107
108
|
if (want === void 0) continue;
|
|
108
109
|
const font = namesFont(declaration.name);
|
|
109
|
-
const previous = readCSSTokenValue(declaration.value, {
|
|
110
|
-
|
|
110
|
+
const previous = readCSSTokenValue(declaration.value, {
|
|
111
|
+
font,
|
|
112
|
+
profile
|
|
113
|
+
});
|
|
114
|
+
const next = readCSSTokenValue(want, {
|
|
115
|
+
font,
|
|
116
|
+
profile
|
|
117
|
+
});
|
|
111
118
|
if (sameCSSTokenValue(previous, next)) continue;
|
|
112
119
|
edits.push({
|
|
113
120
|
start: declaration.start,
|
|
114
121
|
end: declaration.end,
|
|
115
|
-
text: rewriteCSSTokenValue(previous, next, want)
|
|
122
|
+
text: rewriteCSSTokenValue(previous, next, want, profile)
|
|
116
123
|
});
|
|
117
124
|
updated++;
|
|
118
125
|
}
|
|
@@ -125,7 +132,13 @@ function patchTokenStylesheet(graph, source, generated) {
|
|
|
125
132
|
const from = key === "" ? void 0 : inherited.get(name);
|
|
126
133
|
if (from === void 0) return false;
|
|
127
134
|
const font = namesFont(name);
|
|
128
|
-
return sameCSSTokenValue(readCSSTokenValue(from, {
|
|
135
|
+
return sameCSSTokenValue(readCSSTokenValue(from, {
|
|
136
|
+
font,
|
|
137
|
+
profile
|
|
138
|
+
}), readCSSTokenValue(value, {
|
|
139
|
+
font,
|
|
140
|
+
profile
|
|
141
|
+
}));
|
|
129
142
|
}
|
|
130
143
|
let added = 0;
|
|
131
144
|
const blocks = [];
|