@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
package/dist/layout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.js","names":[],"sources":["../src/layout.ts"],"sourcesContent":["import {\n Direction,\n Display,\n Gutter,\n MeasureMode,\n Overflow,\n type Node as YogaNode\n} from 'yoga-layout'\n\nimport { resolveNodeLayoutDirection } from '@pairdraw/scene-graph/text/direction'\n\nimport { applyYogaLayout } from './layout/apply'\nimport {\n asFlatLeaf,\n asLaidOutIn,\n fillKeepsSizeInHuggingParent,\n heldHugAxis,\n ownAxisSizing,\n setCrossAxisSizing,\n setMainAxisSizing\n} from './layout/axis-sizing'\nimport { keepsSavedFrameSize, keepsSavedLayout, usesDetachedDerivedLayout } from './layout/derived'\nimport { applyEffectiveGeneratedTextLayout } from './layout/effective-generated-text'\nimport { insertFlowBox, setFlexFlow, setFlowEdges } from './layout/flow-edges'\nimport { buildGridTree, createGridChildNode, gridTracksForAxis } from './layout/grid'\nimport { sizeAutoResizingText } from './layout/text-auto-resize'\nexport { sizeAutoResizingText } from './layout/text-auto-resize'\nexport * from './layout/auto-layout-handles'\nexport {\n estimateTextSize,\n getTextMeasurer,\n installTextMeasurer,\n measureTextForLayout,\n setTextMeasurer,\n type TextMeasurer\n} from './layout/text-measurement'\nimport type { LayoutSizing, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { connectorSublayers, layoutConnector } from '@pairdraw/scene-graph/connectors'\nimport { layoutSizing } from '@pairdraw/scene-graph/layout'\n\nimport { fitShapeWithTextFrame } from './layout/shape-with-text'\nimport {\n applyContentInsets,\n applyStrokeMargins,\n contentInsetsSize,\n strokeRoom\n} from './layout/strokes'\nimport {\n autoWidthWrapWidth,\n estimateTextSize,\n getTextMeasurer,\n measureAutoWidthText,\n measureTextForLayout\n} from './layout/text-measurement'\nimport {\n applyMinMaxConstraints,\n applyLockedAspectRatio,\n configureAbsoluteChild,\n configureNonTextLeaf,\n createYogaNode,\n freeYogaTree,\n mapAlignSelf,\n mapGridTrack,\n parentStretchedAxis\n} from './layout/yoga-helpers'\n\nexport function computeLayout(graph: SceneGraph, frameId: string): void {\n graph.withLayoutMutations(() => computeLayoutInternal(graph, frameId))\n}\n\n/**\n * The deepest chain of auto-layout frames one layout pass may build. Yoga lays a tree out by\n * recursing in its WebAssembly stack, which overruns at about 150 nested frames here; that throws\n * an out-of-bounds memory error and leaves the shared Yoga instance unusable for every later\n * layout. Refusing the pass before the call keeps the editor working.\n */\nconst MAX_LAYOUT_DEPTH = 128\n\nfunction computeLayoutInternal(graph: SceneGraph, frameId: string): void {\n const frame = graph.getNode(frameId)\n if (!frame || frame.layoutMode === 'NONE') return\n // A shape with text takes its size from its label before laying the label out in it.\n fitShapeWithTextFrame(graph, frame)\n\n const rootDirection = resolveComputedLayoutDirection(graph, frame)\n const yogaDirection = rootDirection === 'RTL' ? Direction.RTL : Direction.LTR\n // The tree is freed on every path, a refused pass included: Yoga's nodes are WebAssembly memory\n // the caller owns, so a throw must not leave them behind.\n let yogaRoot: YogaNode | null = null\n try {\n yogaRoot =\n frame.layoutMode === 'GRID'\n ? buildGridTree(graph, frame, rootDirection)\n : buildYogaTree(graph, frame, rootDirection)\n yogaRoot.calculateLayout(undefined, undefined, yogaDirection)\n applyYogaLayout(graph, frame, yogaRoot, computeLayoutInternal)\n } finally {\n if (yogaRoot) freeYogaTree(yogaRoot)\n }\n}\nfunction resolveComputedLayoutDirection(\n graph: SceneGraph,\n node: Pick<SceneNode, 'layoutDirection' | 'parentId'>\n): 'LTR' | 'RTL' {\n const parent = node.parentId ? graph.getNode(node.parentId) : null\n const inheritedDirection = parent ? resolveComputedLayoutDirection(graph, parent) : 'LTR'\n return resolveNodeLayoutDirection(node, inheritedDirection)\n}\n\nexport function computeAllLayouts(graph: SceneGraph, scopeId?: string): void {\n graph.withLayoutMutations(() => {\n const rootId = scopeId ?? graph.rootId\n const visited = new Set<string>()\n computeLayoutsBottomUp(graph, rootId, visited)\n if (applyEffectiveGeneratedTextLayout(graph, rootId)) {\n computeLayoutsBottomUp(graph, rootId, new Set())\n }\n routeUnroutedConnectors(graph, rootId)\n })\n}\n\n/**\n * Routes each connector that has no route yet, as one read from a file that saved none, once its\n * label is measured, as FigJam routes such a connector when it opens. A saved route is kept.\n */\nexport function routeUnroutedConnectors(graph: SceneGraph, rootId: string): void {\n for (const { node } of graph.flattenTree(rootId)) {\n if (node.type !== 'CONNECTOR') continue\n const line = connectorSublayers(graph, node)?.line\n if (!line || (line.vectorNetwork?.vertices.length ?? 0) > 0) continue\n sizeAutoResizingText(graph, node.id)\n layoutConnector(graph, node)\n }\n}\n\n/**\n * Gives content an author wrote, such as design JSX, HTML, or a `.pen` file, the sizes and\n * positions its layout implies, which the source does not store, measuring its text first.\n * Documents that store their geometry, such as `.fig` files, keep theirs and do not come here.\n */\nexport function layoutAuthoredNodes(graph: SceneGraph, rootIds: Iterable<string>): void {\n const roots = [...rootIds]\n const pageIds = new Set<string>()\n let outsidePages = false\n for (const id of roots) {\n sizeAutoResizingText(graph, id)\n const page = graph.pageOf(id)\n if (page !== null) pageIds.add(page)\n else outsidePages = true\n }\n const layout = () => {\n if (outsidePages) computeAllLayouts(graph)\n else for (const pageId of pageIds) computeAllLayouts(graph, pageId)\n }\n layout()\n // Layout gives wrapping text its width, which its height follows.\n if (roots.map((id) => sizeAutoResizingText(graph, id, true)).some(Boolean)) layout()\n // Connectors authored with the layers they join route once those layers are in place.\n for (const id of roots) {\n for (const { node } of graph.flattenTree(id)) {\n if (node.type === 'CONNECTOR') layoutConnector(graph, node)\n }\n }\n}\n\nfunction computeLayoutsBottomUp(graph: SceneGraph, nodeId: string, visited: Set<string>): void {\n const node = graph.getNode(nodeId)\n if (!node || visited.has(nodeId)) return\n visited.add(nodeId)\n\n for (const childId of node.childIds) {\n computeLayoutsBottomUp(graph, childId, visited)\n }\n\n if (node.layoutMode !== 'NONE' && !preservesImportedInstanceLayout(node)) {\n computeLayout(graph, nodeId)\n }\n}\n\nfunction preservesImportedInstanceLayout(node: SceneNode): boolean {\n return node.type === 'INSTANCE' && node.source.format === 'fig'\n}\n\nfunction buildYogaTree(\n graph: SceneGraph,\n frame: SceneNode,\n inheritedDirection: 'LTR' | 'RTL'\n): YogaNode {\n const root = createYogaNode()\n const direction = resolveNodeLayoutDirection(frame, inheritedDirection)\n const insets = keepsSavedFrameSize(graph, frame) ? null : contentInsetsSize(frame)\n const width = insets ? Math.max(frame.width, insets.width) : frame.width\n const height = insets ? Math.max(frame.height, insets.height) : frame.height\n\n if (frame.primaryAxisSizing === 'FIXED') {\n if (frame.layoutMode === 'HORIZONTAL') root.setWidth(width)\n else root.setHeight(height)\n }\n if (frame.counterAxisSizing === 'FIXED') {\n if (frame.layoutMode === 'HORIZONTAL') root.setHeight(height)\n else root.setWidth(width)\n }\n // Laid out on its own, a frame its parent stretches keeps the size the parent gave it on\n // that axis, so its content aligns within that size rather than within a hug.\n const stretchedAxis = parentStretchedAxis(graph, frame)\n if (stretchedAxis === 'width') root.setWidth(width)\n if (stretchedAxis === 'height') root.setHeight(height)\n const heldAxis = heldHugAxis(graph, frame)\n if (heldAxis === 'width') root.setWidth(width)\n if (heldAxis === 'height') root.setHeight(height)\n\n configureFlexContainer(root, frame, direction)\n\n try {\n insertFlexChildren(root, frame, graph, direction, 1)\n } catch (error) {\n // The depth check refuses a chain while the tree is half built; every node made so far hangs\n // from the root, which has no other holder.\n freeYogaTree(root)\n throw error\n }\n\n return root\n}\n\nfunction configureFlexContainer(\n yogaNode: YogaNode,\n node: SceneNode,\n direction: Exclude<SceneNode['layoutDirection'], 'AUTO'>\n): void {\n yogaNode.setDirection(direction === 'RTL' ? Direction.RTL : Direction.LTR)\n setFlexFlow(yogaNode, node)\n if (node.clipsContent) yogaNode.setOverflow(Overflow.Hidden)\n applyContentInsets(yogaNode, node)\n\n applyMinMaxConstraints(yogaNode, node)\n}\n\n/**\n * A grid child's box in its flex parent: grow takes the free space, a fixed size is stored, and\n * an axis the grid hugs takes its tracks' size there, as configureAsGrid lays it out.\n */\nfunction applyGridChildBox(yogaChild: YogaNode, child: SceneNode, parent: SceneNode): void {\n const isParentRow = parent.layoutMode === 'HORIZONTAL'\n const selfOverride = child.layoutAlignSelf !== 'AUTO'\n const stretchCross = selfOverride\n ? child.layoutAlignSelf === 'STRETCH'\n : parent.counterAxisAlign === 'STRETCH'\n const hugWidth = ownAxisSizing(child, 'width') === 'HUG'\n const hugHeight = ownAxisSizing(child, 'height') === 'HUG'\n if (child.layoutGrow > 0) {\n yogaChild.setFlexGrow(child.layoutGrow)\n yogaChild.setFlexShrink(1)\n yogaChild.setFlexBasis(0)\n if (stretchCross) return\n if (isParentRow) {\n if (!hugHeight) yogaChild.setHeight(child.height)\n } else if (!hugWidth) {\n yogaChild.setWidth(child.width)\n }\n return\n }\n if (isParentRow) {\n if (!hugWidth) yogaChild.setWidth(child.width)\n if (!stretchCross && !hugHeight) yogaChild.setHeight(child.height)\n return\n }\n if (child.gridTemplateRows.length > 0 && !hugHeight) yogaChild.setHeight(child.height)\n if (!stretchCross && !hugWidth) yogaChild.setWidth(child.width)\n}\n\nfunction configureChildAsGrid(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n graph: SceneGraph,\n inheritedDirection: 'LTR' | 'RTL'\n): void {\n const direction = resolveNodeLayoutDirection(child, inheritedDirection)\n yogaChild.setDisplay(Display.Grid)\n yogaChild.setDirection(direction === 'RTL' ? Direction.RTL : Direction.LTR)\n\n if (child.gridTemplateColumns.length > 0) {\n yogaChild.setGridTemplateColumns(gridTracksForAxis(child, 'width').map(mapGridTrack))\n }\n if (child.gridTemplateRows.length > 0) {\n yogaChild.setGridTemplateRows(gridTracksForAxis(child, 'height').map(mapGridTrack))\n }\n\n yogaChild.setGap(Gutter.Column, child.gridColumnGap)\n yogaChild.setGap(Gutter.Row, child.gridRowGap)\n\n applyContentInsets(yogaChild, child)\n applyGridChildBox(yogaChild, child, parent)\n\n const selfAlign = mapAlignSelf(child.layoutAlignSelf)\n if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)\n\n applyLockedAspectRatio(yogaChild, child, parent)\n applyMinMaxConstraints(yogaChild, child)\n\n const grandchildren = graph.getChildren(child.id)\n for (const gc of grandchildren) {\n if (gc.layoutPositioning === 'ABSOLUTE') {\n const yogaGC = createYogaNode()\n configureAbsoluteChild(yogaGC, gc)\n yogaChild.insertChild(yogaGC, yogaChild.getChildCount())\n } else {\n const yogaGC = createGridChildNode(graph, gc)\n applyStrokeMargins(yogaGC, gc, child)\n yogaChild.insertChild(yogaGC, yogaChild.getChildCount())\n }\n }\n}\n\nfunction sizesFitParent(\n parent: SceneNode,\n children: readonly SceneNode[],\n sizes: Array<number | undefined>,\n axis: 'width' | 'height'\n): boolean {\n if (sizes.some((size) => size === undefined)) return false\n const padding =\n (axis === 'width'\n ? parent.paddingLeft + parent.paddingRight\n : parent.paddingTop + parent.paddingBottom) + strokeRoom(parent, children, axis)\n const gap =\n parent.primaryAxisAlign === 'SPACE_BETWEEN'\n ? 0\n : parent.itemSpacing * Math.max(0, children.length - 1)\n const available = axis === 'width' ? parent.width : parent.height\n const total = sizes.reduce<number>((sum, size) => sum + (size ?? 0), padding + gap)\n return Math.abs(total - available) < 0.001\n}\n\nfunction derivedMainAxisFitsParent(\n graph: SceneGraph,\n parent: SceneNode,\n child: SceneNode,\n axis: 'width' | 'height'\n): boolean {\n if (!keepsSavedLayout(graph, parent)) return false\n const children = graph\n .getChildren(parent.id)\n .filter((candidate) => candidate.visible && candidate.layoutPositioning !== 'ABSOLUTE')\n if (children.length === 0) return false\n\n const sizes = children.map((candidate) => candidate.derivedLayout?.[axis])\n return sizesFitParent(parent, children, sizes, axis) && child.derivedLayout?.[axis] !== undefined\n}\n\nfunction configureAutoLayoutChildSizing(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n graph: SceneGraph,\n widthSizing: LayoutSizing,\n heightSizing: LayoutSizing\n): void {\n const isParentRow = parent.layoutMode === 'HORIZONTAL'\n const fixedDerivedMainAxis = isParentRow\n ? derivedMainAxisFitsParent(graph, parent, child, 'width')\n : derivedMainAxisFitsParent(graph, parent, child, 'height')\n\n if (isParentRow) {\n if (fixedDerivedMainAxis) yogaChild.setWidth(child.derivedLayout?.width ?? child.width)\n else setMainAxisSizing(yogaChild, 'width', widthSizing, child.width, child.layoutGrow)\n const keepsSize = fillKeepsSizeInHuggingParent(child, parent, 'height')\n setCrossAxisSizing(yogaChild, 'height', heightSizing, child.height, keepsSize)\n return\n }\n\n const keepsSize = fillKeepsSizeInHuggingParent(child, parent, 'width')\n setCrossAxisSizing(yogaChild, 'width', widthSizing, child.width, keepsSize)\n if (fixedDerivedMainAxis) yogaChild.setHeight(child.derivedLayout?.height ?? child.height)\n else setMainAxisSizing(yogaChild, 'height', heightSizing, child.height, child.layoutGrow)\n}\n\nfunction configureChildAsAutoLayout(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n graph: SceneGraph,\n inheritedDirection: 'LTR' | 'RTL',\n depth: number\n): void {\n if (depth > MAX_LAYOUT_DEPTH) {\n throw new RangeError(\n `Layers nest more than ${MAX_LAYOUT_DEPTH} auto-layout frames deep, which the layout engine cannot lay out.`\n )\n }\n const direction = resolveNodeLayoutDirection(child, inheritedDirection)\n const widthSizing = layoutSizing(graph, child, 'HORIZONTAL')\n const heightSizing = layoutSizing(graph, child, 'VERTICAL')\n\n configureAutoLayoutChildSizing(yogaChild, child, parent, graph, widthSizing, heightSizing)\n\n const selfAlign = mapAlignSelf(child.layoutAlignSelf)\n if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)\n applyLockedAspectRatio(yogaChild, child, parent)\n\n if (usesDetachedDerivedLayout(graph, child)) {\n // The imported size is what the child's own hug produced, whether or not it also fills.\n const derived = child.derivedLayout\n if (ownAxisSizing(child, 'width') === 'HUG') yogaChild.setWidth(derived?.width ?? child.width)\n if (ownAxisSizing(child, 'height') === 'HUG') {\n yogaChild.setHeight(derived?.height ?? child.height)\n }\n applyMinMaxConstraints(yogaChild, child)\n return\n }\n\n configureFlexContainer(yogaChild, child, direction)\n const heldAxis = heldHugAxis(graph, child)\n if (heldAxis === 'width' && widthSizing === 'HUG') yogaChild.setWidth(child.width)\n if (heldAxis === 'height' && heightSizing === 'HUG') yogaChild.setHeight(child.height)\n\n insertFlexChildren(yogaChild, child, graph, direction, depth + 1)\n}\n\n/** Puts a frame's children into its Yoga node, through the flow box a negative edge needs. */\nfunction insertFlexChildren(\n yogaParent: YogaNode,\n parent: SceneNode,\n graph: SceneGraph,\n direction: 'LTR' | 'RTL',\n depth: number\n): void {\n const box = insertFlowBox(yogaParent, parent)\n const flow: YogaNode[] = []\n for (const child of graph\n .getChildren(parent.id)\n .map((node) => asLaidOutIn(graph, node, parent))) {\n const yogaChild = createYogaNode()\n // Attached before it is configured, so a child the depth check refuses still hangs from the\n // root and is freed with it rather than left in WebAssembly memory.\n box.insertChild(yogaChild, box.getChildCount())\n\n if (child.layoutPositioning === 'ABSOLUTE') {\n configureAbsoluteChild(yogaChild, child)\n } else if (!child.visible) {\n yogaChild.setDisplay(Display.None)\n } else {\n if (child.layoutMode === 'GRID') {\n configureChildAsGrid(yogaChild, child, parent, graph, direction)\n } else if (child.layoutMode !== 'NONE') {\n configureChildAsAutoLayout(yogaChild, child, parent, graph, direction, depth)\n } else {\n configureChildAsLeaf(yogaChild, child, parent, graph)\n }\n flow.push(yogaChild)\n }\n applyStrokeMargins(yogaChild, child, parent)\n }\n setFlowEdges(yogaParent, box, parent, flow, direction)\n}\n\nfunction derivedGrowingLeafFitsParent(\n graph: SceneGraph,\n parent: SceneNode,\n child: SceneNode,\n axis: 'width' | 'height'\n): boolean {\n if (child.type !== 'TEXT' || child.layoutGrow <= 0 || child.derivedLayout?.[axis] === undefined) {\n return false\n }\n const children = graph\n .getChildren(parent.id)\n .filter((candidate) => candidate.visible && candidate.layoutPositioning !== 'ABSOLUTE')\n const sizes = children.map((candidate) => {\n if (candidate.layoutGrow > 0) return candidate.derivedLayout?.[axis]\n return axis === 'width' ? candidate.width : candidate.height\n })\n return sizesFitParent(parent, children, sizes, axis)\n}\n\n/**\n * Fill text shares its parent's main axis like a fill frame: it grows and shrinks from a zero\n * basis, so its stored width (100px for new text) never decides its share. Returns whether\n * it fills the row's width, where its stored width must not constrain it either.\n */\nfunction configureGrowingText(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n fixedDerivedMainAxis: boolean\n): boolean {\n if (child.layoutGrow <= 0 || fixedDerivedMainAxis) return false\n yogaChild.setFlexGrow(child.layoutGrow)\n yogaChild.setFlexShrink(1)\n yogaChild.setFlexBasis(0)\n return parent.layoutMode === 'HORIZONTAL'\n}\n\nfunction configureTextLeafWithoutMeasurer(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n fixedDerivedMainAxis: boolean\n): void {\n const hasStoredSize =\n child.width > 0 && child.height > 0 && !(child.width === 100 && child.height === 100)\n\n if (child.textAutoResize === 'WIDTH_AND_HEIGHT') {\n if (hasStoredSize) {\n yogaChild.setWidth(child.width)\n yogaChild.setHeight(child.height)\n } else {\n const estimated = estimateTextSize(child)\n yogaChild.setWidth(estimated.width)\n yogaChild.setHeight(estimated.height)\n }\n return\n }\n if (child.textAutoResize !== 'HEIGHT') {\n // A truncating text keeps the box it has, as Figma clips it to that box.\n if (child.width > 0 && child.height > 0) {\n yogaChild.setWidth(child.width)\n yogaChild.setHeight(child.height)\n }\n return\n }\n\n const growsWidth = configureGrowingText(yogaChild, child, parent, fixedDerivedMainAxis)\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const measurementWidth = fixedDerivedMainAxis\n ? (child.derivedLayout?.width ?? child.width)\n : child.width\n const stretches =\n child.layoutAlignSelf === 'STRETCH' ||\n (child.layoutAlignSelf === 'AUTO' && parent.counterAxisAlign === 'STRETCH')\n if (!(!isRow && stretches) && !fixedDerivedMainAxis && !growsWidth) {\n yogaChild.setWidth(child.width)\n }\n if (hasStoredSize) yogaChild.setHeight(child.height)\n else yogaChild.setHeight(estimateTextSize(child, measurementWidth).height)\n}\n\nfunction configureChildAsLeaf(\n yogaChild: YogaNode,\n node: SceneNode,\n parent: SceneNode,\n graph: SceneGraph\n): void {\n const child = asFlatLeaf(node, parent)\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const selfOverride = child.layoutAlignSelf !== 'AUTO'\n const stretchCross = selfOverride\n ? child.layoutAlignSelf === 'STRETCH'\n : parent.counterAxisAlign === 'STRETCH'\n\n const isText = child.type === 'TEXT'\n const textMeasurer = getTextMeasurer()\n // A truncating or fixed text keeps its box, so Yoga measures only text that grows.\n const needsMeasureFunc = isText && textMeasurer && growsText(child)\n\n const fixedDerivedMainAxis = isRow\n ? derivedGrowingLeafFitsParent(graph, parent, child, 'width')\n : derivedGrowingLeafFitsParent(graph, parent, child, 'height')\n\n if (fixedDerivedMainAxis) {\n if (isRow) yogaChild.setWidth(child.derivedLayout?.width ?? child.width)\n else yogaChild.setHeight(child.derivedLayout?.height ?? child.height)\n }\n\n if (needsMeasureFunc) {\n configureTextLeaf(yogaChild, child, parent, fixedDerivedMainAxis)\n } else if (isText && !textMeasurer && child.textAutoResize !== 'NONE') {\n configureTextLeafWithoutMeasurer(yogaChild, child, parent, fixedDerivedMainAxis)\n } else {\n configureNonTextLeaf(yogaChild, child, isRow, stretchCross)\n // Fixed text still contributes its box to a HUG cross axis. Without\n // an intrinsic minimum, stretch collapses the text to its siblings.\n if (isText && stretchCross && parent.counterAxisSizing === 'HUG') {\n if (isRow) yogaChild.setMinHeight(child.height)\n else yogaChild.setMinWidth(child.width)\n }\n }\n\n const selfAlign = mapAlignSelf(child.layoutAlignSelf)\n if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)\n\n applyLockedAspectRatio(yogaChild, child, parent)\n applyMinMaxConstraints(yogaChild, child)\n}\n\n/** Whether layout measures a text to size it, which only the two growing modes need. */\nfunction growsText(node: SceneNode): boolean {\n return node.textAutoResize === 'WIDTH_AND_HEIGHT' || node.textAutoResize === 'HEIGHT'\n}\n\nfunction configureTextLeaf(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n fixedDerivedMainAxis = false\n): void {\n const autoResize = child.textAutoResize\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const growsWidth = configureGrowingText(yogaChild, child, parent, fixedDerivedMainAxis)\n const stretchesCross =\n child.layoutAlignSelf === 'STRETCH' ||\n (child.layoutAlignSelf === 'AUTO' && parent.counterAxisAlign === 'STRETCH')\n // Layout sets the width of text that grows along a row or stretches across a column.\n const fillsWidth = (!isRow && stretchesCross) || growsWidth\n\n const cache = new Map<number, { width: number; height: number }>()\n const UNCONSTRAINED_KEY = -1\n\n if (autoResize === 'WIDTH_AND_HEIGHT') {\n const importedSize = child.derivedLayout\n if (importedSize?.width !== undefined && importedSize.height !== undefined) {\n yogaChild.setWidth(child.width)\n yogaChild.setHeight(child.height)\n return\n }\n\n // Auto-width text keeps each line whole, as Figma's does, in a parent narrower than the text;\n // only a width that layout or a max width sets wraps it.\n const wraps = fillsWidth || child.maxWidth != null\n yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {\n const maxW = wraps && widthMode !== MeasureMode.Undefined ? width : undefined\n const cacheKey = maxW === undefined ? UNCONSTRAINED_KEY : Math.round(maxW)\n const cached = cache.get(cacheKey)\n if (cached) return cached\n\n const result = measureAutoWidthText(child, maxW ?? autoWidthWrapWidth(child))\n cache.set(cacheKey, result)\n return result\n })\n } else if (autoResize === 'HEIGHT') {\n const fixedWidth = fixedDerivedMainAxis\n ? (child.derivedLayout?.width ?? child.width)\n : child.width\n // Let Yoga stretch or grow fill-width text instead of fixing its stored width.\n if (child.layoutGrow <= 0 && !fillsWidth) {\n yogaChild.setWidth(fixedWidth)\n }\n yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {\n let constraintW = fixedWidth\n if (fillsWidth) {\n if (widthMode !== MeasureMode.Undefined) constraintW = width\n } else if (widthMode !== MeasureMode.Undefined) {\n constraintW = Math.min(width, fixedWidth || width)\n }\n const cacheKey = Math.round(constraintW)\n const cached = cache.get(cacheKey)\n if (cached) return cached\n\n if (constraintW === child.width && (child.derivedTextGlyphs?.length ?? 0) > 0) {\n return { width: constraintW, height: child.height }\n }\n const result = { width: constraintW, height: measureTextForLayout(child, constraintW).height }\n cache.set(cacheKey, result)\n return result\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkEA,SAAgB,cAAc,OAAmB,SAAuB;CACtE,MAAM,0BAA0B,sBAAsB,OAAO,OAAO,CAAC;AACvE;;;;;;;AAQA,MAAM,mBAAmB;AAEzB,SAAS,sBAAsB,OAAmB,SAAuB;CACvE,MAAM,QAAQ,MAAM,QAAQ,OAAO;CACnC,IAAI,CAAC,SAAS,MAAM,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W,CAAC,CAAC;GAAO;GAC7F,MAAM,IAAI,UAAU,MAAM;GAC1B,OAAO;EACT,CAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"layout.js","names":[],"sources":["../src/layout.ts"],"sourcesContent":["import {\n Direction,\n Display,\n Gutter,\n MeasureMode,\n Overflow,\n type Node as YogaNode\n} from 'yoga-layout'\n\nimport { resolveNodeLayoutDirection } from '@pairdraw/scene-graph/text/direction'\n\nimport { applyYogaLayout } from './layout/apply'\nimport {\n asFlatLeaf,\n asLaidOutIn,\n fillKeepsSizeInHuggingParent,\n heldHugAxis,\n ownAxisSizing,\n setCrossAxisSizing,\n setMainAxisSizing\n} from './layout/axis-sizing'\nimport { keepsSavedFrameSize, keepsSavedLayout, usesDetachedDerivedLayout } from './layout/derived'\nimport { applyEffectiveGeneratedTextLayout } from './layout/effective-generated-text'\nimport { insertFlowBox, setFlexFlow, setFlowEdges } from './layout/flow-edges'\nimport { buildGridTree, createGridChildNode, gridTracksForAxis } from './layout/grid'\nimport { sizeAutoResizingText } from './layout/text-auto-resize'\nexport { sizeAutoResizingText } from './layout/text-auto-resize'\nexport * from './layout/auto-layout-handles'\nexport {\n estimateTextSize,\n getTextMeasurer,\n installTextMeasurer,\n measureTextForLayout,\n setTextMeasurer,\n type TextMeasurer\n} from './layout/text-measurement'\nimport type { LayoutSizing, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { connectorSublayers, layoutConnector } from '@pairdraw/scene-graph/connectors'\nimport { enforcedAspectRatio, layoutSizing } from '@pairdraw/scene-graph/layout'\n\nimport { fitShapeWithTextFrame } from './layout/shape-with-text'\nimport {\n applyContentInsets,\n applyStrokeMargins,\n contentInsetsSize,\n strokeRoom\n} from './layout/strokes'\nimport {\n autoWidthWrapWidth,\n estimateTextSize,\n getTextMeasurer,\n measureAutoWidthText,\n measureTextForLayout\n} from './layout/text-measurement'\nimport {\n applyMinMaxConstraints,\n applyLockedAspectRatio,\n configureAbsoluteChild,\n configureNonTextLeaf,\n createYogaNode,\n freeYogaTree,\n mapAlignSelf,\n mapGridTrack,\n parentStretchedAxis\n} from './layout/yoga-helpers'\n\nexport function computeLayout(graph: SceneGraph, frameId: string): void {\n graph.withLayoutMutations(() => computeLayoutInternal(graph, frameId))\n}\n\n/**\n * The deepest chain of auto-layout frames one layout pass may build. Yoga lays a tree out by\n * recursing in its WebAssembly stack, which overruns at about 150 nested frames here; that throws\n * an out-of-bounds memory error and leaves the shared Yoga instance unusable for every later\n * layout. Refusing the pass before the call keeps the editor working.\n */\nconst MAX_LAYOUT_DEPTH = 128\n\nfunction computeLayoutInternal(graph: SceneGraph, frameId: string): void {\n const frame = graph.getNode(frameId)\n if (!frame || frame.layoutMode === 'NONE') return\n // A shape with text takes its size from its label before laying the label out in it.\n fitShapeWithTextFrame(graph, frame)\n\n const rootDirection = resolveComputedLayoutDirection(graph, frame)\n const yogaDirection = rootDirection === 'RTL' ? Direction.RTL : Direction.LTR\n // The tree is freed on every path, a refused pass included: Yoga's nodes are WebAssembly memory\n // the caller owns, so a throw must not leave them behind.\n let yogaRoot: YogaNode | null = null\n try {\n yogaRoot =\n frame.layoutMode === 'GRID'\n ? buildGridTree(graph, frame, rootDirection)\n : buildYogaTree(graph, frame, rootDirection)\n yogaRoot.calculateLayout(undefined, undefined, yogaDirection)\n applyYogaLayout(graph, frame, yogaRoot, computeLayoutInternal)\n } finally {\n if (yogaRoot) freeYogaTree(yogaRoot)\n }\n}\nfunction resolveComputedLayoutDirection(\n graph: SceneGraph,\n node: Pick<SceneNode, 'layoutDirection' | 'parentId'>\n): 'LTR' | 'RTL' {\n const parent = node.parentId ? graph.getNode(node.parentId) : null\n const inheritedDirection = parent ? resolveComputedLayoutDirection(graph, parent) : 'LTR'\n return resolveNodeLayoutDirection(node, inheritedDirection)\n}\n\nexport function computeAllLayouts(graph: SceneGraph, scopeId?: string): void {\n graph.withLayoutMutations(() => {\n const rootId = scopeId ?? graph.rootId\n const visited = new Set<string>()\n computeLayoutsBottomUp(graph, rootId, visited)\n if (applyEffectiveGeneratedTextLayout(graph, rootId)) {\n computeLayoutsBottomUp(graph, rootId, new Set())\n }\n routeUnroutedConnectors(graph, rootId)\n })\n}\n\n/**\n * Routes each connector that has no route yet, as one read from a file that saved none, once its\n * label is measured, as FigJam routes such a connector when it opens. A saved route is kept.\n */\nexport function routeUnroutedConnectors(graph: SceneGraph, rootId: string): void {\n for (const { node } of graph.flattenTree(rootId)) {\n if (node.type !== 'CONNECTOR') continue\n const line = connectorSublayers(graph, node)?.line\n if (!line || (line.vectorNetwork?.vertices.length ?? 0) > 0) continue\n sizeAutoResizingText(graph, node.id)\n layoutConnector(graph, node)\n }\n}\n\n/**\n * Gives content an author wrote, such as design JSX, HTML, or a `.pen` file, the sizes and\n * positions its layout implies, which the source does not store, measuring its text first.\n * Documents that store their geometry, such as `.fig` files, keep theirs and do not come here.\n */\nexport function layoutAuthoredNodes(graph: SceneGraph, rootIds: Iterable<string>): void {\n const roots = [...rootIds]\n const pageIds = new Set<string>()\n let outsidePages = false\n for (const id of roots) {\n sizeAutoResizingText(graph, id)\n const page = graph.pageOf(id)\n if (page !== null) pageIds.add(page)\n else outsidePages = true\n }\n const layout = () => {\n if (outsidePages) computeAllLayouts(graph)\n else for (const pageId of pageIds) computeAllLayouts(graph, pageId)\n }\n layout()\n // Layout gives wrapping text its width, which its height follows.\n if (roots.map((id) => sizeAutoResizingText(graph, id, true)).some(Boolean)) layout()\n // Connectors authored with the layers they join route once those layers are in place.\n for (const id of roots) {\n for (const { node } of graph.flattenTree(id)) {\n if (node.type === 'CONNECTOR') layoutConnector(graph, node)\n }\n }\n}\n\nfunction computeLayoutsBottomUp(graph: SceneGraph, nodeId: string, visited: Set<string>): void {\n const node = graph.getNode(nodeId)\n if (!node || visited.has(nodeId)) return\n visited.add(nodeId)\n\n for (const childId of node.childIds) {\n computeLayoutsBottomUp(graph, childId, visited)\n }\n\n if (node.layoutMode !== 'NONE' && !preservesImportedInstanceLayout(node)) {\n computeLayout(graph, nodeId)\n }\n}\n\nfunction preservesImportedInstanceLayout(node: SceneNode): boolean {\n return node.type === 'INSTANCE' && node.source.format === 'fig'\n}\n\nfunction buildYogaTree(\n graph: SceneGraph,\n frame: SceneNode,\n inheritedDirection: 'LTR' | 'RTL'\n): YogaNode {\n const root = createYogaNode()\n const direction = resolveNodeLayoutDirection(frame, inheritedDirection)\n const insets = keepsSavedFrameSize(graph, frame) ? null : contentInsetsSize(frame)\n const width = insets ? Math.max(frame.width, insets.width) : frame.width\n const height = insets ? Math.max(frame.height, insets.height) : frame.height\n\n if (frame.primaryAxisSizing === 'FIXED') {\n if (frame.layoutMode === 'HORIZONTAL') root.setWidth(width)\n else root.setHeight(height)\n }\n if (frame.counterAxisSizing === 'FIXED') {\n if (frame.layoutMode === 'HORIZONTAL') root.setHeight(height)\n else root.setWidth(width)\n }\n // Laid out on its own, a frame its parent stretches keeps the size the parent gave it on\n // that axis, so its content aligns within that size rather than within a hug.\n const stretchedAxis = parentStretchedAxis(graph, frame)\n if (stretchedAxis === 'width') root.setWidth(width)\n if (stretchedAxis === 'height') root.setHeight(height)\n const heldAxis = heldHugAxis(graph, frame)\n if (heldAxis === 'width') root.setWidth(width)\n if (heldAxis === 'height') root.setHeight(height)\n\n configureFlexContainer(root, frame, direction)\n\n try {\n insertFlexChildren(root, frame, graph, direction, 1)\n } catch (error) {\n // The depth check refuses a chain while the tree is half built; every node made so far hangs\n // from the root, which has no other holder.\n freeYogaTree(root)\n throw error\n }\n\n return root\n}\n\nfunction configureFlexContainer(\n yogaNode: YogaNode,\n node: SceneNode,\n direction: Exclude<SceneNode['layoutDirection'], 'AUTO'>\n): void {\n yogaNode.setDirection(direction === 'RTL' ? Direction.RTL : Direction.LTR)\n setFlexFlow(yogaNode, node)\n if (node.clipsContent) yogaNode.setOverflow(Overflow.Hidden)\n applyContentInsets(yogaNode, node)\n\n applyMinMaxConstraints(yogaNode, node)\n}\n\n/**\n * A grid child's box in its flex parent: grow takes the free space, a fixed size is stored, and\n * an axis the grid hugs takes its tracks' size there, as configureAsGrid lays it out.\n */\nfunction applyGridChildBox(yogaChild: YogaNode, child: SceneNode, parent: SceneNode): void {\n const isParentRow = parent.layoutMode === 'HORIZONTAL'\n const selfOverride = child.layoutAlignSelf !== 'AUTO'\n const stretchCross = selfOverride\n ? child.layoutAlignSelf === 'STRETCH'\n : parent.counterAxisAlign === 'STRETCH'\n const hugWidth = ownAxisSizing(child, 'width') === 'HUG'\n const hugHeight = ownAxisSizing(child, 'height') === 'HUG'\n if (child.layoutGrow > 0) {\n yogaChild.setFlexGrow(child.layoutGrow)\n yogaChild.setFlexShrink(1)\n yogaChild.setFlexBasis(0)\n if (stretchCross) return\n if (isParentRow) {\n if (!hugHeight) yogaChild.setHeight(child.height)\n } else if (!hugWidth) {\n yogaChild.setWidth(child.width)\n }\n return\n }\n if (isParentRow) {\n if (!hugWidth) yogaChild.setWidth(child.width)\n if (!stretchCross && !hugHeight) yogaChild.setHeight(child.height)\n return\n }\n if (child.gridTemplateRows.length > 0 && !hugHeight) yogaChild.setHeight(child.height)\n if (!stretchCross && !hugWidth) yogaChild.setWidth(child.width)\n}\n\nfunction configureChildAsGrid(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n graph: SceneGraph,\n inheritedDirection: 'LTR' | 'RTL'\n): void {\n const direction = resolveNodeLayoutDirection(child, inheritedDirection)\n yogaChild.setDisplay(Display.Grid)\n yogaChild.setDirection(direction === 'RTL' ? Direction.RTL : Direction.LTR)\n\n if (child.gridTemplateColumns.length > 0) {\n yogaChild.setGridTemplateColumns(gridTracksForAxis(child, 'width').map(mapGridTrack))\n }\n if (child.gridTemplateRows.length > 0) {\n yogaChild.setGridTemplateRows(gridTracksForAxis(child, 'height').map(mapGridTrack))\n }\n\n yogaChild.setGap(Gutter.Column, child.gridColumnGap)\n yogaChild.setGap(Gutter.Row, child.gridRowGap)\n\n applyContentInsets(yogaChild, child)\n applyGridChildBox(yogaChild, child, parent)\n\n const selfAlign = mapAlignSelf(child.layoutAlignSelf)\n if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)\n\n applyLockedAspectRatio(yogaChild, child, parent)\n applyMinMaxConstraints(yogaChild, child)\n\n const grandchildren = graph.getChildren(child.id)\n for (const gc of grandchildren) {\n if (gc.layoutPositioning === 'ABSOLUTE') {\n const yogaGC = createYogaNode()\n configureAbsoluteChild(yogaGC, gc)\n yogaChild.insertChild(yogaGC, yogaChild.getChildCount())\n } else {\n const yogaGC = createGridChildNode(graph, gc)\n applyStrokeMargins(yogaGC, gc, child)\n yogaChild.insertChild(yogaGC, yogaChild.getChildCount())\n }\n }\n}\n\nfunction sizesFitParent(\n parent: SceneNode,\n children: readonly SceneNode[],\n sizes: Array<number | undefined>,\n axis: 'width' | 'height'\n): boolean {\n if (sizes.some((size) => size === undefined)) return false\n const padding =\n (axis === 'width'\n ? parent.paddingLeft + parent.paddingRight\n : parent.paddingTop + parent.paddingBottom) + strokeRoom(parent, children, axis)\n const gap =\n parent.primaryAxisAlign === 'SPACE_BETWEEN'\n ? 0\n : parent.itemSpacing * Math.max(0, children.length - 1)\n const available = axis === 'width' ? parent.width : parent.height\n const total = sizes.reduce<number>((sum, size) => sum + (size ?? 0), padding + gap)\n return Math.abs(total - available) < 0.001\n}\n\nfunction derivedMainAxisFitsParent(\n graph: SceneGraph,\n parent: SceneNode,\n child: SceneNode,\n axis: 'width' | 'height'\n): boolean {\n if (!keepsSavedLayout(graph, parent)) return false\n const children = graph\n .getChildren(parent.id)\n .filter((candidate) => candidate.visible && candidate.layoutPositioning !== 'ABSOLUTE')\n if (children.length === 0) return false\n\n const sizes = children.map((candidate) => candidate.derivedLayout?.[axis])\n return sizesFitParent(parent, children, sizes, axis) && child.derivedLayout?.[axis] !== undefined\n}\n\nfunction configureAutoLayoutChildSizing(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n graph: SceneGraph,\n widthSizing: LayoutSizing,\n heightSizing: LayoutSizing\n): void {\n const isParentRow = parent.layoutMode === 'HORIZONTAL'\n const fixedDerivedMainAxis = isParentRow\n ? derivedMainAxisFitsParent(graph, parent, child, 'width')\n : derivedMainAxisFitsParent(graph, parent, child, 'height')\n\n if (isParentRow) {\n if (fixedDerivedMainAxis) yogaChild.setWidth(child.derivedLayout?.width ?? child.width)\n else setMainAxisSizing(yogaChild, 'width', widthSizing, child.width, child.layoutGrow)\n const keepsSize = fillKeepsSizeInHuggingParent(child, parent, 'height')\n setCrossAxisSizing(yogaChild, 'height', heightSizing, child.height, keepsSize)\n return\n }\n\n const keepsSize = fillKeepsSizeInHuggingParent(child, parent, 'width')\n setCrossAxisSizing(yogaChild, 'width', widthSizing, child.width, keepsSize)\n if (fixedDerivedMainAxis) yogaChild.setHeight(child.derivedLayout?.height ?? child.height)\n else setMainAxisSizing(yogaChild, 'height', heightSizing, child.height, child.layoutGrow)\n}\n\n/**\n * Whether the parent's pass places this child from the size it holds: neither its content nor the\n * parent decides its size, so its own cells keep their places while the parent moves it.\n */\nfunction placesFromSize(\n child: SceneNode,\n parent: SceneNode,\n widthSizing: LayoutSizing,\n heightSizing: LayoutSizing\n): boolean {\n return (\n widthSizing === 'FIXED' &&\n heightSizing === 'FIXED' &&\n child.layoutGrow === 0 &&\n parent.counterAxisAlign !== 'BASELINE' &&\n child.layoutAlignSelf !== 'BASELINE' &&\n enforcedAspectRatio(child) === null &&\n child.minWidth === null &&\n child.maxWidth === null &&\n child.minHeight === null &&\n child.maxHeight === null\n )\n}\n\n/**\n * Refuses a chain deeper than Yoga can lay out, for the subtrees a pass places from their size and\n * does not build: the same refusal, without the Yoga nodes.\n */\nfunction assertLayoutDepth(graph: SceneGraph, frame: SceneNode, depth: number): void {\n if (depth > MAX_LAYOUT_DEPTH) {\n throw new RangeError(\n `Layers nest more than ${MAX_LAYOUT_DEPTH} auto-layout frames deep, which the layout engine cannot lay out.`\n )\n }\n for (const child of graph.getChildren(frame.id)) {\n if (child.layoutMode === 'NONE' || !child.visible) continue\n if (child.layoutPositioning === 'ABSOLUTE') continue\n assertLayoutDepth(graph, child, depth + 1)\n }\n}\n\nfunction configureChildAsAutoLayout(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n graph: SceneGraph,\n inheritedDirection: 'LTR' | 'RTL',\n depth: number\n): void {\n if (depth > MAX_LAYOUT_DEPTH) {\n throw new RangeError(\n `Layers nest more than ${MAX_LAYOUT_DEPTH} auto-layout frames deep, which the layout engine cannot lay out.`\n )\n }\n const direction = resolveNodeLayoutDirection(child, inheritedDirection)\n const widthSizing = layoutSizing(graph, child, 'HORIZONTAL')\n const heightSizing = layoutSizing(graph, child, 'VERTICAL')\n\n configureAutoLayoutChildSizing(yogaChild, child, parent, graph, widthSizing, heightSizing)\n\n const selfAlign = mapAlignSelf(child.layoutAlignSelf)\n if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)\n applyLockedAspectRatio(yogaChild, child, parent)\n\n if (usesDetachedDerivedLayout(graph, child)) {\n // The imported size is what the child's own hug produced, whether or not it also fills.\n const derived = child.derivedLayout\n if (ownAxisSizing(child, 'width') === 'HUG') yogaChild.setWidth(derived?.width ?? child.width)\n if (ownAxisSizing(child, 'height') === 'HUG') {\n yogaChild.setHeight(derived?.height ?? child.height)\n }\n applyMinMaxConstraints(yogaChild, child)\n return\n }\n\n if (placesFromSize(child, parent, widthSizing, heightSizing)) {\n assertLayoutDepth(graph, child, depth + 1)\n return\n }\n\n configureFlexContainer(yogaChild, child, direction)\n const heldAxis = heldHugAxis(graph, child)\n if (heldAxis === 'width' && widthSizing === 'HUG') yogaChild.setWidth(child.width)\n if (heldAxis === 'height' && heightSizing === 'HUG') yogaChild.setHeight(child.height)\n\n insertFlexChildren(yogaChild, child, graph, direction, depth + 1)\n}\n\n/** Puts a frame's children into its Yoga node, through the flow box a negative edge needs. */\nfunction insertFlexChildren(\n yogaParent: YogaNode,\n parent: SceneNode,\n graph: SceneGraph,\n direction: 'LTR' | 'RTL',\n depth: number\n): void {\n const box = insertFlowBox(yogaParent, parent)\n const flow: YogaNode[] = []\n for (const child of graph\n .getChildren(parent.id)\n .map((node) => asLaidOutIn(graph, node, parent))) {\n const yogaChild = createYogaNode()\n // Attached before it is configured, so a child the depth check refuses still hangs from the\n // root and is freed with it rather than left in WebAssembly memory.\n box.insertChild(yogaChild, box.getChildCount())\n\n if (child.layoutPositioning === 'ABSOLUTE') {\n configureAbsoluteChild(yogaChild, child)\n } else if (!child.visible) {\n yogaChild.setDisplay(Display.None)\n } else {\n if (child.layoutMode === 'GRID') {\n configureChildAsGrid(yogaChild, child, parent, graph, direction)\n } else if (child.layoutMode !== 'NONE') {\n configureChildAsAutoLayout(yogaChild, child, parent, graph, direction, depth)\n } else {\n configureChildAsLeaf(yogaChild, child, parent, graph)\n }\n flow.push(yogaChild)\n }\n applyStrokeMargins(yogaChild, child, parent)\n }\n setFlowEdges(yogaParent, box, parent, flow, direction)\n}\n\nfunction derivedGrowingLeafFitsParent(\n graph: SceneGraph,\n parent: SceneNode,\n child: SceneNode,\n axis: 'width' | 'height'\n): boolean {\n if (child.type !== 'TEXT' || child.layoutGrow <= 0 || child.derivedLayout?.[axis] === undefined) {\n return false\n }\n const children = graph\n .getChildren(parent.id)\n .filter((candidate) => candidate.visible && candidate.layoutPositioning !== 'ABSOLUTE')\n const sizes = children.map((candidate) => {\n if (candidate.layoutGrow > 0) return candidate.derivedLayout?.[axis]\n return axis === 'width' ? candidate.width : candidate.height\n })\n return sizesFitParent(parent, children, sizes, axis)\n}\n\n/**\n * Fill text shares its parent's main axis like a fill frame: it grows and shrinks from a zero\n * basis, so its stored width (100px for new text) never decides its share. Returns whether\n * it fills the row's width, where its stored width must not constrain it either.\n */\nfunction configureGrowingText(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n fixedDerivedMainAxis: boolean\n): boolean {\n if (child.layoutGrow <= 0 || fixedDerivedMainAxis) return false\n yogaChild.setFlexGrow(child.layoutGrow)\n yogaChild.setFlexShrink(1)\n yogaChild.setFlexBasis(0)\n return parent.layoutMode === 'HORIZONTAL'\n}\n\nfunction configureTextLeafWithoutMeasurer(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n fixedDerivedMainAxis: boolean\n): void {\n const hasStoredSize =\n child.width > 0 && child.height > 0 && !(child.width === 100 && child.height === 100)\n\n if (child.textAutoResize === 'WIDTH_AND_HEIGHT') {\n if (hasStoredSize) {\n yogaChild.setWidth(child.width)\n yogaChild.setHeight(child.height)\n } else {\n const estimated = estimateTextSize(child)\n yogaChild.setWidth(estimated.width)\n yogaChild.setHeight(estimated.height)\n }\n return\n }\n if (child.textAutoResize !== 'HEIGHT') {\n // A truncating text keeps the box it has, as Figma clips it to that box.\n if (child.width > 0 && child.height > 0) {\n yogaChild.setWidth(child.width)\n yogaChild.setHeight(child.height)\n }\n return\n }\n\n const growsWidth = configureGrowingText(yogaChild, child, parent, fixedDerivedMainAxis)\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const measurementWidth = fixedDerivedMainAxis\n ? (child.derivedLayout?.width ?? child.width)\n : child.width\n const stretches =\n child.layoutAlignSelf === 'STRETCH' ||\n (child.layoutAlignSelf === 'AUTO' && parent.counterAxisAlign === 'STRETCH')\n if (!(!isRow && stretches) && !fixedDerivedMainAxis && !growsWidth) {\n yogaChild.setWidth(child.width)\n }\n if (hasStoredSize) yogaChild.setHeight(child.height)\n else yogaChild.setHeight(estimateTextSize(child, measurementWidth).height)\n}\n\nfunction configureChildAsLeaf(\n yogaChild: YogaNode,\n node: SceneNode,\n parent: SceneNode,\n graph: SceneGraph\n): void {\n const child = asFlatLeaf(node, parent)\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const selfOverride = child.layoutAlignSelf !== 'AUTO'\n const stretchCross = selfOverride\n ? child.layoutAlignSelf === 'STRETCH'\n : parent.counterAxisAlign === 'STRETCH'\n\n const isText = child.type === 'TEXT'\n const textMeasurer = getTextMeasurer()\n // A truncating or fixed text keeps its box, so Yoga measures only text that grows.\n const needsMeasureFunc = isText && textMeasurer && growsText(child)\n\n const fixedDerivedMainAxis = isRow\n ? derivedGrowingLeafFitsParent(graph, parent, child, 'width')\n : derivedGrowingLeafFitsParent(graph, parent, child, 'height')\n\n if (fixedDerivedMainAxis) {\n if (isRow) yogaChild.setWidth(child.derivedLayout?.width ?? child.width)\n else yogaChild.setHeight(child.derivedLayout?.height ?? child.height)\n }\n\n if (needsMeasureFunc) {\n configureTextLeaf(yogaChild, child, parent, fixedDerivedMainAxis)\n } else if (isText && !textMeasurer && child.textAutoResize !== 'NONE') {\n configureTextLeafWithoutMeasurer(yogaChild, child, parent, fixedDerivedMainAxis)\n } else {\n configureNonTextLeaf(yogaChild, child, isRow, stretchCross)\n // Fixed text still contributes its box to a HUG cross axis. Without\n // an intrinsic minimum, stretch collapses the text to its siblings.\n if (isText && stretchCross && parent.counterAxisSizing === 'HUG') {\n if (isRow) yogaChild.setMinHeight(child.height)\n else yogaChild.setMinWidth(child.width)\n }\n }\n\n const selfAlign = mapAlignSelf(child.layoutAlignSelf)\n if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)\n\n applyLockedAspectRatio(yogaChild, child, parent)\n applyMinMaxConstraints(yogaChild, child)\n}\n\n/** Whether layout measures a text to size it, which only the two growing modes need. */\nfunction growsText(node: SceneNode): boolean {\n return node.textAutoResize === 'WIDTH_AND_HEIGHT' || node.textAutoResize === 'HEIGHT'\n}\n\nfunction configureTextLeaf(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n fixedDerivedMainAxis = false\n): void {\n const autoResize = child.textAutoResize\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const growsWidth = configureGrowingText(yogaChild, child, parent, fixedDerivedMainAxis)\n const stretchesCross =\n child.layoutAlignSelf === 'STRETCH' ||\n (child.layoutAlignSelf === 'AUTO' && parent.counterAxisAlign === 'STRETCH')\n // Layout sets the width of text that grows along a row or stretches across a column.\n const fillsWidth = (!isRow && stretchesCross) || growsWidth\n\n const cache = new Map<number, { width: number; height: number }>()\n const UNCONSTRAINED_KEY = -1\n\n if (autoResize === 'WIDTH_AND_HEIGHT') {\n const importedSize = child.derivedLayout\n if (importedSize?.width !== undefined && importedSize.height !== undefined) {\n yogaChild.setWidth(child.width)\n yogaChild.setHeight(child.height)\n return\n }\n\n // Auto-width text keeps each line whole, as Figma's does, in a parent narrower than the text;\n // only a width that layout or a max width sets wraps it.\n const wraps = fillsWidth || child.maxWidth != null\n yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {\n const maxW = wraps && widthMode !== MeasureMode.Undefined ? width : undefined\n const cacheKey = maxW === undefined ? UNCONSTRAINED_KEY : Math.round(maxW)\n const cached = cache.get(cacheKey)\n if (cached) return cached\n\n const result = measureAutoWidthText(child, maxW ?? autoWidthWrapWidth(child))\n cache.set(cacheKey, result)\n return result\n })\n } else if (autoResize === 'HEIGHT') {\n const fixedWidth = fixedDerivedMainAxis\n ? (child.derivedLayout?.width ?? child.width)\n : child.width\n // Let Yoga stretch or grow fill-width text instead of fixing its stored width.\n if (child.layoutGrow <= 0 && !fillsWidth) {\n yogaChild.setWidth(fixedWidth)\n }\n yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {\n let constraintW = fixedWidth\n if (fillsWidth) {\n if (widthMode !== MeasureMode.Undefined) constraintW = width\n } else if (widthMode !== MeasureMode.Undefined) {\n constraintW = Math.min(width, fixedWidth || width)\n }\n const cacheKey = Math.round(constraintW)\n const cached = cache.get(cacheKey)\n if (cached) return cached\n\n if (constraintW === child.width && (child.derivedTextGlyphs?.length ?? 0) > 0) {\n return { width: constraintW, height: child.height }\n }\n const result = { width: constraintW, height: measureTextForLayout(child, constraintW).height }\n cache.set(cacheKey, result)\n return result\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkEA,SAAgB,cAAc,OAAmB,SAAuB;CACtE,MAAM,0BAA0B,sBAAsB,OAAO,OAAO,CAAC;AACvE;;;;;;;AAQA,MAAM,mBAAmB;AAEzB,SAAS,sBAAsB,OAAmB,SAAuB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M,SAAS,qBAAqB,OAAO,QAAQ,mBAAmB,KAAK,CAAC;GAC5E,MAAM,IAAI,UAAU,MAAM;GAC1B,OAAO;EACT,CAAC;CACH,OAAO,IAAI,eAAe,UAAU;EAClC,MAAM,aAAa,uBACd,MAAM,eAAe,SAAS,MAAM,QACrC,MAAM;EAEV,IAAI,MAAM,cAAc,KAAK,CAAC,YAC5B,UAAU,SAAS,UAAU;EAE/B,UAAU,gBAAgB,OAAO,WAAW,SAAS,gBAAgB;GACnE,IAAI,cAAc;GAClB,IAAI,YACE;QAAA,cAAc,YAAY,WAAW,cAAc;GAAA,OAClD,IAAI,cAAc,YAAY,WACnC,cAAc,KAAK,IAAI,OAAO,cAAc,KAAK;GAEnD,MAAM,WAAW,KAAK,MAAM,WAAW;GACvC,MAAM,SAAS,MAAM,IAAI,QAAQ;GACjC,IAAI,QAAQ,OAAO;GAEnB,IAAI,gBAAgB,MAAM,UAAU,MAAM,mBAAmB,UAAU,KAAK,GAC1E,OAAO;IAAE,OAAO;IAAa,QAAQ,MAAM;GAAO;GAEpD,MAAM,SAAS;IAAE,OAAO;IAAa,QAAQ,qBAAqB,OAAO,WAAW,CAAC,CAAC;GAAO;GAC7F,MAAM,IAAI,UAAU,MAAM;GAC1B,OAAO;EACT,CAAC;CACH;AACF"}
|
package/dist/lint/fixes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ownsComponentTree } from "./utils.js";
|
|
2
2
|
import { isNumericVariableBindingField, paintBindingTarget } from "@pairdraw/scene-graph/variables";
|
|
3
|
-
import { isEmptyObject } from "es-toolkit";
|
|
4
3
|
import { colorToHex } from "@pairdraw/scene-graph/color";
|
|
4
|
+
import { isEmptyObject } from "es-toolkit";
|
|
5
5
|
//#region src/lint/fixes.ts
|
|
6
6
|
function graphFixTarget(graph) {
|
|
7
7
|
return {
|
package/dist/lint/linter.js
CHANGED
|
@@ -4,9 +4,9 @@ import { designViolations } from "../design-memory/check.js";
|
|
|
4
4
|
import { presets } from "./presets.js";
|
|
5
5
|
import { DESIGN_MEMORY_RULE_IDS, designMemoryRules } from "./rules/design-memory.js";
|
|
6
6
|
import { allRules } from "./rules/index.js";
|
|
7
|
+
import { colorToHex } from "@pairdraw/scene-graph/color";
|
|
7
8
|
import { sharedStyleLayers, sharedStyleTypeForKind } from "@pairdraw/scene-graph/shared-styles";
|
|
8
9
|
import { uniq } from "es-toolkit";
|
|
9
|
-
import { colorToHex } from "@pairdraw/scene-graph/color";
|
|
10
10
|
import { variableNamespace } from "@pairdraw/dom-css/export";
|
|
11
11
|
import { DESIGN_MEMORY_GROUPS, cachedDesignMemory } from "@pairdraw/scene-graph/design-memory";
|
|
12
12
|
//#region src/lint/linter.ts
|
|
@@ -316,7 +316,7 @@ function describeVariables(graph) {
|
|
|
316
316
|
};
|
|
317
317
|
const colorsByHex = /* @__PURE__ */ new Map();
|
|
318
318
|
const numbersByField = /* @__PURE__ */ new Map();
|
|
319
|
-
for (const variable of graph.
|
|
319
|
+
for (const variable of graph.getLiveVariables()) {
|
|
320
320
|
counts[variable.type]++;
|
|
321
321
|
if (variable.type === "FLOAT") {
|
|
322
322
|
const namespace = variableNamespace(variable);
|
package/dist/lint/linter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linter.js","names":[],"sources":["../../src/lint/linter.ts"],"sourcesContent":["import { uniq } from 'es-toolkit'\n\nimport { variableNamespace } from '@pairdraw/dom-css/export'\nimport type { SceneGraph, SceneNode, SharedStyleType } from '@pairdraw/scene-graph'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport { cachedDesignMemory, DESIGN_MEMORY_GROUPS } from '@pairdraw/scene-graph/design-memory'\nimport { sharedStyleLayers, sharedStyleTypeForKind } from '@pairdraw/scene-graph/shared-styles'\n\nimport { currentDesignRules, designViolations, type DesignViolation } from '#core/design-memory'\n\nimport { presets } from './presets'\nimport { allRules } from './rules'\nimport { DESIGN_MEMORY_RULE_IDS, designMemoryRules } from './rules/design-memory'\nimport type {\n LintConfig,\n LintDesignMemory,\n LintVariables,\n LintMessage,\n LintNode,\n LintResult,\n Rule,\n RuleContext,\n Severity,\n TokenNumberField\n} from './types'\nimport { getNodePath } from './utils'\n\n/** The size and weight of each stretch of a text layer's characters, as the canvas draws them. */\nfunction effectiveTextStyles(node: SceneNode): { fontSize: number; fontWeight: number }[] {\n const base = { fontSize: node.fontSize, fontWeight: node.fontWeight }\n const runs = node.styleRuns.map((run) => ({\n fontSize: run.style.fontSize ?? base.fontSize,\n fontWeight: run.style.fontWeight ?? base.fontWeight\n }))\n const covered = node.styleRuns.reduce((total, run) => total + run.length, 0)\n return covered < node.text.length || runs.length === 0 ? [base, ...runs] : runs\n}\n\ntype RuleSettings = { severity: Severity; options?: Record<string, unknown> }\n\n/** How mild each reported severity is, so a finding can only soften its rule's. */\nconst SEVERITY_RANK: Record<Exclude<Severity, 'off'>, number> = { error: 0, warning: 1, info: 2 }\n\n/** A preset's rules, refusing a name no preset has so a typo cannot silently disable linting. */\nfunction presetRules(id: string) {\n if (!Object.hasOwn(presets, id)) {\n const known = Object.keys(presets).sort().join(', ')\n throw new Error(`Unknown lint preset \"${id}\". Known presets: ${known}`)\n }\n return presets[id].rules\n}\n\nexport class Linter {\n private rules = new Map<string, Rule>()\n private ruleConfigs = new Map<string, RuleSettings | undefined>()\n private messages: LintMessage[] = []\n private graph: SceneGraph | null = null\n /** The enabled rules with their contexts, made once per run rather than once per layer. */\n private checks: { rule: Rule; context: RuleContext }[] = []\n private nodes = new Map<string, LintNode>()\n private variables: LintVariables = {\n counts: { COLOR: 0, FLOAT: 0, STRING: 0, BOOLEAN: 0 },\n colorsByHex: new Map(),\n numbersByField: new Map()\n }\n private sharedStyleTypes: ReadonlyMap<string, SharedStyleType> = new Map()\n private design: LintDesignMemory | null = null\n /** Rules the configuration names, which a document's design memory does not override. */\n private configured = new Set<string>()\n /** The only rules to run, when the caller named them. */\n private only: ReadonlySet<string> | null = null\n\n constructor(options: { config?: LintConfig; preset?: string; rules?: string[] } = {}) {\n let baseConfig: Record<\n string,\n Severity | { severity: Severity; options?: Record<string, unknown> }\n > = {}\n if (options.preset) baseConfig = { ...presetRules(options.preset) }\n if (options.config?.extends) {\n const ids = Array.isArray(options.config.extends)\n ? options.config.extends\n : [options.config.extends]\n for (const id of ids) baseConfig = { ...baseConfig, ...presetRules(id) }\n }\n if (options.config?.rules) baseConfig = { ...baseConfig, ...options.config.rules }\n this.configured = new Set(Object.keys(options.config?.rules ?? {}))\n this.only = options.rules ? new Set(options.rules) : null\n const rulesToLoad = options.rules ?? Object.keys(baseConfig)\n for (const ruleId of rulesToLoad) {\n if (!Object.hasOwn(allRules, ruleId)) throw new Error(`Unknown lint rule \"${ruleId}\"`)\n const rule = allRules[ruleId]\n const config = baseConfig[ruleId]\n if (config === 'off') continue\n this.rules.set(ruleId, rule)\n if (typeof config === 'string') this.ruleConfigs.set(ruleId, { severity: config })\n else this.ruleConfigs.set(ruleId, config)\n }\n }\n\n lintGraph(graph: SceneGraph, rootIds?: string[]): LintResult {\n this.messages = []\n this.nodes.clear()\n this.graph = graph\n this.variables = describeVariables(graph)\n this.sharedStyleTypes = sharedStyleTypes(graph)\n this.design = this.describeDesign(graph)\n this.checks = this.ruleChecks()\n const roots = rootIds && rootIds.length > 0 ? rootIds : graph.getPages().map((p) => p.id)\n for (const id of outermostRoots(graph, roots)) this.lintNode(id, undefined)\n this.graph = null\n this.checks = []\n this.design = null\n return {\n messages: this.messages,\n errorCount: this.messages.filter((m) => m.severity === 'error').length,\n warningCount: this.messages.filter((m) => m.severity === 'warning').length,\n infoCount: this.messages.filter((m) => m.severity === 'info').length\n }\n }\n\n /**\n * The rules' view of `id`, made the first time the walk or a rule reaches it. Instance sublayers\n * are never linted, so on a page made of instances most layers are never converted at all.\n */\n private nodeFor(id: string, parent: LintNode | undefined): LintNode | undefined {\n const cached = this.nodes.get(id)\n if (cached) return cached\n const raw = this.graph?.getNode(id)\n if (!this.graph || !raw) return undefined\n const node = this.toLintNode(this.graph, raw)\n node.parent = parent\n this.nodes.set(id, node)\n return node\n }\n\n private toLintNode(graph: SceneGraph, raw: SceneNode): LintNode {\n // Rules see the color a paint renders with, including a bound variable in this node's mode.\n const paintColor = (\n field: 'fills' | 'strokes',\n index: number,\n color: SceneNode['fills'][number]['color']\n ) => {\n const variableId = raw.boundVariables[`${field}/${index}/color`]\n return (variableId && graph.resolveColorVariableForNode(raw.id, variableId)) || color\n }\n return {\n id: raw.id,\n name: raw.name,\n type: raw.type,\n width: raw.width,\n height: raw.height,\n x: raw.x,\n y: raw.y,\n rotation: raw.rotation,\n visible: raw.visible,\n locked: raw.locked,\n opacity: raw.opacity,\n layoutMode: raw.layoutMode,\n layoutPositioning: raw.layoutPositioning,\n layoutGrow: raw.layoutGrow,\n layoutAlignSelf: raw.layoutAlignSelf,\n primaryAxisSizing: raw.primaryAxisSizing,\n counterAxisSizing: raw.counterAxisSizing,\n textAutoResize: raw.textAutoResize,\n itemSpacing: raw.itemSpacing,\n paddingTop: raw.paddingTop,\n paddingRight: raw.paddingRight,\n paddingBottom: raw.paddingBottom,\n paddingLeft: raw.paddingLeft,\n cornerRadius: raw.cornerRadius,\n childIds: raw.childIds.slice(),\n componentId: raw.componentId || undefined,\n text: raw.text,\n fontSize: raw.fontSize,\n textStyles: raw.type === 'TEXT' ? effectiveTextStyles(raw) : undefined,\n styleRunCount: raw.styleRuns.length,\n boundVariables: raw.boundVariables,\n fills: raw.fills.map((f, index) => ({\n type: f.type,\n visible: f.visible,\n opacity: f.opacity,\n color: f.type === 'SOLID' ? paintColor('fills', index, f.color) : undefined\n })),\n strokes: raw.strokes.map((stroke, index) => ({\n visible: stroke.visible,\n opacity: stroke.opacity,\n color: paintColor('strokes', index, stroke.color)\n })),\n effects: raw.effects.map((effect) => ({\n type: effect.type,\n visible: effect.visible,\n radius: effect.type === 'SHADER' || effect.type === 'NOISE' ? 0 : effect.radius\n })),\n textStyleId: raw.textStyleId,\n effectStyleId: raw.effectStyleId\n }\n }\n\n /**\n * The document's design memory, which its own rules check layers against. A memory's group\n * replaces the generic scale rule for the same values.\n */\n private describeDesign(graph: SceneGraph): LintDesignMemory | null {\n const memory = cachedDesignMemory(graph)\n if (!memory) return null\n const rules = currentDesignRules(graph, memory)\n const found = new Map<string, readonly DesignViolation[]>()\n return {\n rules,\n violations: (node) => {\n const cached = found.get(node.id)\n if (cached) return cached\n const raw = graph.getNode(node.id)\n const violations = raw ? designViolations(rules, raw) : []\n found.set(node.id, violations)\n return violations\n }\n }\n }\n\n /** The rules this run checks with their settings: the configured ones and the memory's. */\n private activeRules(): [string, Rule, RuleSettings][] {\n const active: [string, Rule, RuleSettings][] = []\n const rules = this.design?.rules\n const superseded = new Set<string>()\n if (rules && rules.spacing.enforce !== 'off') superseded.add('consistent-spacing')\n if (rules && rules.radius.enforce !== 'off') superseded.add('consistent-radius')\n for (const [ruleId, rule] of this.rules) {\n if (ruleId in designMemoryRules && !rules) continue\n if (superseded.has(ruleId) && !this.configured.has(ruleId)) continue\n const config = this.ruleConfigs.get(ruleId)\n if (config) active.push([ruleId, rule, config])\n }\n if (!rules) return active\n for (const group of DESIGN_MEMORY_GROUPS) {\n const ruleId = DESIGN_MEMORY_RULE_IDS[group]\n if (this.ruleConfigs.get(ruleId) || this.configured.has(ruleId)) continue\n if (this.only && !this.only.has(ruleId)) continue\n const enforce = rules[group].enforce\n if (enforce === 'off') continue\n active.push([\n ruleId,\n designMemoryRules[ruleId],\n { severity: enforce === 'refuse' ? 'error' : 'warning' }\n ])\n }\n return active\n }\n\n private ruleChecks(): { rule: Rule; context: RuleContext }[] {\n const checks: { rule: Rule; context: RuleContext }[] = []\n for (const [ruleId, rule, config] of this.activeRules()) {\n if (config.severity === 'off') continue\n const severity = config.severity\n checks.push({\n rule,\n context: {\n variables: this.variables,\n isSharedStyle: (kind, id) =>\n id !== null && this.sharedStyleTypes.get(id) === sharedStyleTypeForKind(kind),\n design: this.design,\n report: ({ node, message, suggest, data, fix, suggestions, severity: milder }) => {\n this.messages.push({\n ruleId,\n severity:\n milder && SEVERITY_RANK[milder] > SEVERITY_RANK[severity] ? milder : severity,\n message,\n nodeId: node.id,\n nodeName: node.name,\n nodePath: getNodePath(this.nodes.get(node.id) ?? node),\n suggest,\n data,\n fix,\n suggestions\n })\n },\n getConfig: () => config.options,\n getParent: (node) => this.nodes.get(node.id)?.parent ?? null,\n getChildren: (node) =>\n node.childIds\n .map((childId) => this.nodeFor(childId, this.nodes.get(node.id)))\n .filter((child): child is LintNode => !!child)\n }\n })\n }\n return checks\n }\n\n private lintNode(id: string, parent: LintNode | undefined) {\n const node = this.nodeFor(id, parent)\n if (!node) return\n for (const { rule, context } of this.checks) {\n if (rule.match && !rule.match.includes(node.type)) continue\n rule.check(node, context)\n }\n // Instance sublayers mirror their main component: issues there are fixed once in the\n // component, so reporting every placed copy only multiplies the same finding.\n if (node.type === 'INSTANCE') return\n for (const childId of node.childIds) this.lintNode(childId, node)\n }\n}\n\n/**\n * The roots no other root contains, each once. A layer inside another root is linted with it,\n * so it has its real parents and reports once.\n */\nfunction outermostRoots(graph: SceneGraph, ids: readonly string[]): string[] {\n const requested = new Set(ids)\n return uniq(ids).filter((id) => {\n for (let parentId = graph.getNode(id)?.parentId; parentId;) {\n if (requested.has(parentId)) return false\n parentId = graph.getNode(parentId)?.parentId\n }\n return true\n })\n}\n\n/** The type of each shared style in the document, by the source id layers link it by. */\nfunction sharedStyleTypes(graph: SceneGraph): ReadonlyMap<string, SharedStyleType> {\n const types = new Map<string, SharedStyleType>()\n for (const [id, style] of sharedStyleLayers(graph))\n if (style.sharedStyleType) types.set(id, style.sharedStyleType)\n return types\n}\n\n/** The layer fields each Tailwind namespace of number tokens sets. */\nconst NAMESPACE_FIELDS: Readonly<Record<string, readonly TokenNumberField[]>> = {\n radius: ['cornerRadius'],\n spacing: ['itemSpacing', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'],\n text: ['fontSize']\n}\n\nfunction describeVariables(graph: SceneGraph): LintVariables {\n const counts = { COLOR: 0, FLOAT: 0, STRING: 0, BOOLEAN: 0 }\n const colorsByHex = new Map<string, { id: string; name: string }>()\n const numbersByField = new Map<TokenNumberField, Map<number, { id: string; name: string }[]>>()\n for (const variable of graph.variables.values()) {\n counts[variable.type]++\n if (variable.type === 'FLOAT') {\n const namespace = variableNamespace(variable)\n const value = graph.resolveNumberVariable(variable.id)\n if (!namespace || value === undefined) continue\n for (const field of NAMESPACE_FIELDS[namespace] ?? []) {\n const byValue =\n numbersByField.get(field) ?? new Map<number, { id: string; name: string }[]>()\n byValue.set(value, [\n ...(byValue.get(value) ?? []),\n { id: variable.id, name: variable.name }\n ])\n numbersByField.set(field, byValue)\n }\n continue\n }\n if (variable.type !== 'COLOR') continue\n const color = graph.resolveColorVariable(variable.id)\n if (!color || color.a < 1) continue\n const hex = colorToHex(color)\n if (!colorsByHex.has(hex)) colorsByHex.set(hex, { id: variable.id, name: variable.name })\n }\n return { counts, colorsByHex, numbersByField }\n}\n\nexport function createLinter(options?: { config?: LintConfig; preset?: string; rules?: string[] }) {\n return new Linter(options)\n}\n"],"mappings":";;;;;;;;;;;;;AA4BA,SAAS,oBAAoB,MAA6D;CACxF,MAAM,OAAO;EAAE,UAAU,KAAK;EAAU,YAAY,KAAK;CAAW;CACpE,MAAM,OAAO,KAAK,UAAU,KAAK,SAAS;EACxC,UAAU,IAAI,MAAM,YAAY,KAAK;EACrC,YAAY,IAAI,MAAM,cAAc,KAAK;CAC3C,EAAE;CAEF,OADgB,KAAK,UAAU,QAAQ,OAAO,QAAQ,QAAQ,IAAI,QAAQ,CAC7D,IAAI,KAAK,KAAK,UAAU,KAAK,WAAW,IAAI,CAAC,MAAM,GAAG,IAAI,IAAI;AAC7E;;AAKA,MAAM,gBAA0D;CAAE,OAAO;CAAG,SAAS;CAAG,MAAM;AAAE;;AAGhG,SAAS,YAAY,IAAY;CAC/B,IAAI,CAAC,OAAO,OAAO,SAAS,EAAE,GAAG;EAC/B,MAAM,QAAQ,OAAO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;GACrD,IAAI,CAAC,aAAa,UAAU,KAAA,GAAW;GACvC,KAAK,MAAM,SAAS,iBAAiB,cAAc,CAAC,GAAG;IACrD,MAAM,UACJ,eAAe,IAAI,KAAK,qBAAK,IAAI,IAA4C;IAC/E,QAAQ,IAAI,OAAO,CACjB,GAAI,QAAQ,IAAI,KAAK,KAAK,CAAC,GAC3B;KAAE,IAAI,SAAS;KAAI,MAAM,SAAS;IAAK,CACzC,CAAC;IACD,eAAe,IAAI,OAAO,OAAO;GACnC;GACA;EACF;EACA,IAAI,SAAS,SAAS,SAAS;EAC/B,MAAM,QAAQ,MAAM,qBAAqB,SAAS,EAAE;EACpD,IAAI,CAAC,SAAS,MAAM,IAAI,GAAG;EAC3B,MAAM,MAAM,WAAW,KAAK;EAC5B,IAAI,CAAC,YAAY,IAAI,GAAG,GAAG,YAAY,IAAI,KAAK;GAAE,IAAI,SAAS;GAAI,MAAM,SAAS;EAAK,CAAC;CAC1F;CACA,OAAO;EAAE;EAAQ;EAAa;CAAe;AAC/C;AAEA,SAAgB,aAAa,SAAsE;CACjG,OAAO,IAAI,OAAO,OAAO;AAC3B"}
|
|
1
|
+
{"version":3,"file":"linter.js","names":[],"sources":["../../src/lint/linter.ts"],"sourcesContent":["import { uniq } from 'es-toolkit'\n\nimport { variableNamespace } from '@pairdraw/dom-css/export'\nimport type { SceneGraph, SceneNode, SharedStyleType } from '@pairdraw/scene-graph'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport { cachedDesignMemory, DESIGN_MEMORY_GROUPS } from '@pairdraw/scene-graph/design-memory'\nimport { sharedStyleLayers, sharedStyleTypeForKind } from '@pairdraw/scene-graph/shared-styles'\n\nimport { currentDesignRules, designViolations, type DesignViolation } from '#core/design-memory'\n\nimport { presets } from './presets'\nimport { allRules } from './rules'\nimport { DESIGN_MEMORY_RULE_IDS, designMemoryRules } from './rules/design-memory'\nimport type {\n LintConfig,\n LintDesignMemory,\n LintVariables,\n LintMessage,\n LintNode,\n LintResult,\n Rule,\n RuleContext,\n Severity,\n TokenNumberField\n} from './types'\nimport { getNodePath } from './utils'\n\n/** The size and weight of each stretch of a text layer's characters, as the canvas draws them. */\nfunction effectiveTextStyles(node: SceneNode): { fontSize: number; fontWeight: number }[] {\n const base = { fontSize: node.fontSize, fontWeight: node.fontWeight }\n const runs = node.styleRuns.map((run) => ({\n fontSize: run.style.fontSize ?? base.fontSize,\n fontWeight: run.style.fontWeight ?? base.fontWeight\n }))\n const covered = node.styleRuns.reduce((total, run) => total + run.length, 0)\n return covered < node.text.length || runs.length === 0 ? [base, ...runs] : runs\n}\n\ntype RuleSettings = { severity: Severity; options?: Record<string, unknown> }\n\n/** How mild each reported severity is, so a finding can only soften its rule's. */\nconst SEVERITY_RANK: Record<Exclude<Severity, 'off'>, number> = { error: 0, warning: 1, info: 2 }\n\n/** A preset's rules, refusing a name no preset has so a typo cannot silently disable linting. */\nfunction presetRules(id: string) {\n if (!Object.hasOwn(presets, id)) {\n const known = Object.keys(presets).sort().join(', ')\n throw new Error(`Unknown lint preset \"${id}\". Known presets: ${known}`)\n }\n return presets[id].rules\n}\n\nexport class Linter {\n private rules = new Map<string, Rule>()\n private ruleConfigs = new Map<string, RuleSettings | undefined>()\n private messages: LintMessage[] = []\n private graph: SceneGraph | null = null\n /** The enabled rules with their contexts, made once per run rather than once per layer. */\n private checks: { rule: Rule; context: RuleContext }[] = []\n private nodes = new Map<string, LintNode>()\n private variables: LintVariables = {\n counts: { COLOR: 0, FLOAT: 0, STRING: 0, BOOLEAN: 0 },\n colorsByHex: new Map(),\n numbersByField: new Map()\n }\n private sharedStyleTypes: ReadonlyMap<string, SharedStyleType> = new Map()\n private design: LintDesignMemory | null = null\n /** Rules the configuration names, which a document's design memory does not override. */\n private configured = new Set<string>()\n /** The only rules to run, when the caller named them. */\n private only: ReadonlySet<string> | null = null\n\n constructor(options: { config?: LintConfig; preset?: string; rules?: string[] } = {}) {\n let baseConfig: Record<\n string,\n Severity | { severity: Severity; options?: Record<string, unknown> }\n > = {}\n if (options.preset) baseConfig = { ...presetRules(options.preset) }\n if (options.config?.extends) {\n const ids = Array.isArray(options.config.extends)\n ? options.config.extends\n : [options.config.extends]\n for (const id of ids) baseConfig = { ...baseConfig, ...presetRules(id) }\n }\n if (options.config?.rules) baseConfig = { ...baseConfig, ...options.config.rules }\n this.configured = new Set(Object.keys(options.config?.rules ?? {}))\n this.only = options.rules ? new Set(options.rules) : null\n const rulesToLoad = options.rules ?? Object.keys(baseConfig)\n for (const ruleId of rulesToLoad) {\n if (!Object.hasOwn(allRules, ruleId)) throw new Error(`Unknown lint rule \"${ruleId}\"`)\n const rule = allRules[ruleId]\n const config = baseConfig[ruleId]\n if (config === 'off') continue\n this.rules.set(ruleId, rule)\n if (typeof config === 'string') this.ruleConfigs.set(ruleId, { severity: config })\n else this.ruleConfigs.set(ruleId, config)\n }\n }\n\n lintGraph(graph: SceneGraph, rootIds?: string[]): LintResult {\n this.messages = []\n this.nodes.clear()\n this.graph = graph\n this.variables = describeVariables(graph)\n this.sharedStyleTypes = sharedStyleTypes(graph)\n this.design = this.describeDesign(graph)\n this.checks = this.ruleChecks()\n const roots = rootIds && rootIds.length > 0 ? rootIds : graph.getPages().map((p) => p.id)\n for (const id of outermostRoots(graph, roots)) this.lintNode(id, undefined)\n this.graph = null\n this.checks = []\n this.design = null\n return {\n messages: this.messages,\n errorCount: this.messages.filter((m) => m.severity === 'error').length,\n warningCount: this.messages.filter((m) => m.severity === 'warning').length,\n infoCount: this.messages.filter((m) => m.severity === 'info').length\n }\n }\n\n /**\n * The rules' view of `id`, made the first time the walk or a rule reaches it. Instance sublayers\n * are never linted, so on a page made of instances most layers are never converted at all.\n */\n private nodeFor(id: string, parent: LintNode | undefined): LintNode | undefined {\n const cached = this.nodes.get(id)\n if (cached) return cached\n const raw = this.graph?.getNode(id)\n if (!this.graph || !raw) return undefined\n const node = this.toLintNode(this.graph, raw)\n node.parent = parent\n this.nodes.set(id, node)\n return node\n }\n\n private toLintNode(graph: SceneGraph, raw: SceneNode): LintNode {\n // Rules see the color a paint renders with, including a bound variable in this node's mode.\n const paintColor = (\n field: 'fills' | 'strokes',\n index: number,\n color: SceneNode['fills'][number]['color']\n ) => {\n const variableId = raw.boundVariables[`${field}/${index}/color`]\n return (variableId && graph.resolveColorVariableForNode(raw.id, variableId)) || color\n }\n return {\n id: raw.id,\n name: raw.name,\n type: raw.type,\n width: raw.width,\n height: raw.height,\n x: raw.x,\n y: raw.y,\n rotation: raw.rotation,\n visible: raw.visible,\n locked: raw.locked,\n opacity: raw.opacity,\n layoutMode: raw.layoutMode,\n layoutPositioning: raw.layoutPositioning,\n layoutGrow: raw.layoutGrow,\n layoutAlignSelf: raw.layoutAlignSelf,\n primaryAxisSizing: raw.primaryAxisSizing,\n counterAxisSizing: raw.counterAxisSizing,\n textAutoResize: raw.textAutoResize,\n itemSpacing: raw.itemSpacing,\n paddingTop: raw.paddingTop,\n paddingRight: raw.paddingRight,\n paddingBottom: raw.paddingBottom,\n paddingLeft: raw.paddingLeft,\n cornerRadius: raw.cornerRadius,\n childIds: raw.childIds.slice(),\n componentId: raw.componentId || undefined,\n text: raw.text,\n fontSize: raw.fontSize,\n textStyles: raw.type === 'TEXT' ? effectiveTextStyles(raw) : undefined,\n styleRunCount: raw.styleRuns.length,\n boundVariables: raw.boundVariables,\n fills: raw.fills.map((f, index) => ({\n type: f.type,\n visible: f.visible,\n opacity: f.opacity,\n color: f.type === 'SOLID' ? paintColor('fills', index, f.color) : undefined\n })),\n strokes: raw.strokes.map((stroke, index) => ({\n visible: stroke.visible,\n opacity: stroke.opacity,\n color: paintColor('strokes', index, stroke.color)\n })),\n effects: raw.effects.map((effect) => ({\n type: effect.type,\n visible: effect.visible,\n radius: effect.type === 'SHADER' || effect.type === 'NOISE' ? 0 : effect.radius\n })),\n textStyleId: raw.textStyleId,\n effectStyleId: raw.effectStyleId\n }\n }\n\n /**\n * The document's design memory, which its own rules check layers against. A memory's group\n * replaces the generic scale rule for the same values.\n */\n private describeDesign(graph: SceneGraph): LintDesignMemory | null {\n const memory = cachedDesignMemory(graph)\n if (!memory) return null\n const rules = currentDesignRules(graph, memory)\n const found = new Map<string, readonly DesignViolation[]>()\n return {\n rules,\n violations: (node) => {\n const cached = found.get(node.id)\n if (cached) return cached\n const raw = graph.getNode(node.id)\n const violations = raw ? designViolations(rules, raw) : []\n found.set(node.id, violations)\n return violations\n }\n }\n }\n\n /** The rules this run checks with their settings: the configured ones and the memory's. */\n private activeRules(): [string, Rule, RuleSettings][] {\n const active: [string, Rule, RuleSettings][] = []\n const rules = this.design?.rules\n const superseded = new Set<string>()\n if (rules && rules.spacing.enforce !== 'off') superseded.add('consistent-spacing')\n if (rules && rules.radius.enforce !== 'off') superseded.add('consistent-radius')\n for (const [ruleId, rule] of this.rules) {\n if (ruleId in designMemoryRules && !rules) continue\n if (superseded.has(ruleId) && !this.configured.has(ruleId)) continue\n const config = this.ruleConfigs.get(ruleId)\n if (config) active.push([ruleId, rule, config])\n }\n if (!rules) return active\n for (const group of DESIGN_MEMORY_GROUPS) {\n const ruleId = DESIGN_MEMORY_RULE_IDS[group]\n if (this.ruleConfigs.get(ruleId) || this.configured.has(ruleId)) continue\n if (this.only && !this.only.has(ruleId)) continue\n const enforce = rules[group].enforce\n if (enforce === 'off') continue\n active.push([\n ruleId,\n designMemoryRules[ruleId],\n { severity: enforce === 'refuse' ? 'error' : 'warning' }\n ])\n }\n return active\n }\n\n private ruleChecks(): { rule: Rule; context: RuleContext }[] {\n const checks: { rule: Rule; context: RuleContext }[] = []\n for (const [ruleId, rule, config] of this.activeRules()) {\n if (config.severity === 'off') continue\n const severity = config.severity\n checks.push({\n rule,\n context: {\n variables: this.variables,\n isSharedStyle: (kind, id) =>\n id !== null && this.sharedStyleTypes.get(id) === sharedStyleTypeForKind(kind),\n design: this.design,\n report: ({ node, message, suggest, data, fix, suggestions, severity: milder }) => {\n this.messages.push({\n ruleId,\n severity:\n milder && SEVERITY_RANK[milder] > SEVERITY_RANK[severity] ? milder : severity,\n message,\n nodeId: node.id,\n nodeName: node.name,\n nodePath: getNodePath(this.nodes.get(node.id) ?? node),\n suggest,\n data,\n fix,\n suggestions\n })\n },\n getConfig: () => config.options,\n getParent: (node) => this.nodes.get(node.id)?.parent ?? null,\n getChildren: (node) =>\n node.childIds\n .map((childId) => this.nodeFor(childId, this.nodes.get(node.id)))\n .filter((child): child is LintNode => !!child)\n }\n })\n }\n return checks\n }\n\n private lintNode(id: string, parent: LintNode | undefined) {\n const node = this.nodeFor(id, parent)\n if (!node) return\n for (const { rule, context } of this.checks) {\n if (rule.match && !rule.match.includes(node.type)) continue\n rule.check(node, context)\n }\n // Instance sublayers mirror their main component: issues there are fixed once in the\n // component, so reporting every placed copy only multiplies the same finding.\n if (node.type === 'INSTANCE') return\n for (const childId of node.childIds) this.lintNode(childId, node)\n }\n}\n\n/**\n * The roots no other root contains, each once. A layer inside another root is linted with it,\n * so it has its real parents and reports once.\n */\nfunction outermostRoots(graph: SceneGraph, ids: readonly string[]): string[] {\n const requested = new Set(ids)\n return uniq(ids).filter((id) => {\n for (let parentId = graph.getNode(id)?.parentId; parentId;) {\n if (requested.has(parentId)) return false\n parentId = graph.getNode(parentId)?.parentId\n }\n return true\n })\n}\n\n/** The type of each shared style in the document, by the source id layers link it by. */\nfunction sharedStyleTypes(graph: SceneGraph): ReadonlyMap<string, SharedStyleType> {\n const types = new Map<string, SharedStyleType>()\n for (const [id, style] of sharedStyleLayers(graph))\n if (style.sharedStyleType) types.set(id, style.sharedStyleType)\n return types\n}\n\n/** The layer fields each Tailwind namespace of number tokens sets. */\nconst NAMESPACE_FIELDS: Readonly<Record<string, readonly TokenNumberField[]>> = {\n radius: ['cornerRadius'],\n spacing: ['itemSpacing', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'],\n text: ['fontSize']\n}\n\nfunction describeVariables(graph: SceneGraph): LintVariables {\n const counts = { COLOR: 0, FLOAT: 0, STRING: 0, BOOLEAN: 0 }\n const colorsByHex = new Map<string, { id: string; name: string }>()\n const numbersByField = new Map<TokenNumberField, Map<number, { id: string; name: string }[]>>()\n for (const variable of graph.getLiveVariables()) {\n counts[variable.type]++\n if (variable.type === 'FLOAT') {\n const namespace = variableNamespace(variable)\n const value = graph.resolveNumberVariable(variable.id)\n if (!namespace || value === undefined) continue\n for (const field of NAMESPACE_FIELDS[namespace] ?? []) {\n const byValue =\n numbersByField.get(field) ?? new Map<number, { id: string; name: string }[]>()\n byValue.set(value, [\n ...(byValue.get(value) ?? []),\n { id: variable.id, name: variable.name }\n ])\n numbersByField.set(field, byValue)\n }\n continue\n }\n if (variable.type !== 'COLOR') continue\n const color = graph.resolveColorVariable(variable.id)\n if (!color || color.a < 1) continue\n const hex = colorToHex(color)\n if (!colorsByHex.has(hex)) colorsByHex.set(hex, { id: variable.id, name: variable.name })\n }\n return { counts, colorsByHex, numbersByField }\n}\n\nexport function createLinter(options?: { config?: LintConfig; preset?: string; rules?: string[] }) {\n return new Linter(options)\n}\n"],"mappings":";;;;;;;;;;;;;AA4BA,SAAS,oBAAoB,MAA6D;CACxF,MAAM,OAAO;EAAE,UAAU,KAAK;EAAU,YAAY,KAAK;CAAW;CACpE,MAAM,OAAO,KAAK,UAAU,KAAK,SAAS;EACxC,UAAU,IAAI,MAAM,YAAY,KAAK;EACrC,YAAY,IAAI,MAAM,cAAc,KAAK;CAC3C,EAAE;CAEF,OADgB,KAAK,UAAU,QAAQ,OAAO,QAAQ,QAAQ,IAAI,QAAQ,CAC7D,IAAI,KAAK,KAAK,UAAU,KAAK,WAAW,IAAI,CAAC,MAAM,GAAG,IAAI,IAAI;AAC7E;;AAKA,MAAM,gBAA0D;CAAE,OAAO;CAAG,SAAS;CAAG,MAAM;AAAE;;AAGhG,SAAS,YAAY,IAAY;CAC/B,IAAI,CAAC,OAAO,OAAO,SAAS,EAAE,GAAG;EAC/B,MAAM,QAAQ,OAAO,KAAK,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI;EACnD,MAAM,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AiB,cAAc,CAAC,GAAG;IACrD,MAAM,UACJ,eAAe,IAAI,KAAK,qBAAK,IAAI,IAA4C;IAC/E,QAAQ,IAAI,OAAO,CACjB,GAAI,QAAQ,IAAI,KAAK,KAAK,CAAC,GAC3B;KAAE,IAAI,SAAS;KAAI,MAAM,SAAS;IAAK,CACzC,CAAC;IACD,eAAe,IAAI,OAAO,OAAO;GACnC;GACA;EACF;EACA,IAAI,SAAS,SAAS,SAAS;EAC/B,MAAM,QAAQ,MAAM,qBAAqB,SAAS,EAAE;EACpD,IAAI,CAAC,SAAS,MAAM,IAAI,GAAG;EAC3B,MAAM,MAAM,WAAW,KAAK;EAC5B,IAAI,CAAC,YAAY,IAAI,GAAG,GAAG,YAAY,IAAI,KAAK;GAAE,IAAI,SAAS;GAAI,MAAM,SAAS;EAAK,CAAC;CAC1F;CACA,OAAO;EAAE;EAAQ;EAAa;CAAe;AAC/C;AAEA,SAAgB,aAAa,SAAsE;CACjG,OAAO,IAAI,OAAO,OAAO;AAC3B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NodeRef } from "./behaviours.js";
|
|
2
|
-
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
2
|
+
import { CommentThread, SceneGraph } from "@pairdraw/scene-graph";
|
|
3
3
|
import { Vector } from "@pairdraw/scene-graph/primitives";
|
|
4
4
|
//#region src/pairdraw-api/comments.d.ts
|
|
5
5
|
/** Who scripts and agents comment as when they give no name. */
|
|
@@ -49,6 +49,8 @@ declare class CommentHandle {
|
|
|
49
49
|
} | null;
|
|
50
50
|
/** Where the pin is on the page's canvas. */
|
|
51
51
|
get position(): Vector;
|
|
52
|
+
/** The area the person circled, in canvas units relative to the pin; null for a clicked pin. */
|
|
53
|
+
get region(): CommentThread['region'];
|
|
52
54
|
get replies(): {
|
|
53
55
|
id: string;
|
|
54
56
|
author: string;
|
|
@@ -78,6 +80,7 @@ declare class CommentHandle {
|
|
|
78
80
|
name: string;
|
|
79
81
|
} | null;
|
|
80
82
|
position: Vector;
|
|
83
|
+
region: import("@pairdraw/scene-graph").CommentRegion | null | undefined;
|
|
81
84
|
replies: {
|
|
82
85
|
id: string;
|
|
83
86
|
author: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comments.d.ts","names":[],"sources":["../../src/pairdraw-api/comments.ts"],"mappings":";;;;;cAuBa;UAEI;;EAEf;;EAEA,OAAO;;EAEP;;UAGe;;EAEf,OAAO;;EAEP,OAAO;;EAEP;EACA;EACA;;;;;;;cAkBW;mBAEQ;WACR;EADQ,YAAA,OAAO,YACf;cAGC;UAMJ;MAOJ;MAIA;MAIA;MAIA;;MAKA;IAAU;IAAY;;;MAMtB;IAAU;IAAY;;;MAOtB,YAAY;
|
|
1
|
+
{"version":3,"file":"comments.d.ts","names":[],"sources":["../../src/pairdraw-api/comments.ts"],"mappings":";;;;;cAuBa;UAEI;;EAEf;;EAEA,OAAO;;EAEP;;UAGe;;EAEf,OAAO;;EAEP,OAAO;;EAEP;EACA;EACA;;;;;;;cAkBW;mBAEQ;WACR;EADQ,YAAA,OAAO,YACf;cAGC;UAMJ;MAOJ;MAIA;MAIA;MAIA;;MAKA;IAAU;IAAY;;;MAMtB;IAAU;IAAY;;;MAOtB,YAAY;;MAKZ,UAAU;MAIV;IAAa;IAAY;IAAgB;IAAc;;;EAU3D,MAAM,cAAc;IAAW;;EAO/B;EAIA;;EAKA;EAIA;;;;;;;MApDkB;MAAc;;;MAMd;MAAc;;;;;MAgBX;MAAgB;MAAc;MAAmB;;;;;iBA+CxD,YAAY,OAAO,YAAY,SAAQ,gBAAqB;iBAc5D,WAAW,OAAO,YAAY,aAAa;;iBAK3C,WACd,OAAO,YACP,uBACA,cACA,UAAS,aACR"}
|
|
@@ -67,6 +67,10 @@ var CommentHandle = class {
|
|
|
67
67
|
get position() {
|
|
68
68
|
return commentPosition(this.graph, this.thread);
|
|
69
69
|
}
|
|
70
|
+
/** The area the person circled, in canvas units relative to the pin; null for a clicked pin. */
|
|
71
|
+
get region() {
|
|
72
|
+
return this.thread.region ?? null;
|
|
73
|
+
}
|
|
70
74
|
get replies() {
|
|
71
75
|
return liveReplies(this.thread).map(({ id, author, text, createdAt }) => ({
|
|
72
76
|
id,
|
|
@@ -102,6 +106,7 @@ var CommentHandle = class {
|
|
|
102
106
|
page: this.page,
|
|
103
107
|
node: this.node,
|
|
104
108
|
position: this.position,
|
|
109
|
+
region: this.region,
|
|
105
110
|
replies: this.replies
|
|
106
111
|
};
|
|
107
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comments.js","names":["now"],"sources":["../../src/pairdraw-api/comments.ts"],"sourcesContent":["import type { CommentThread, SceneGraph } from '@pairdraw/scene-graph'\nimport {\n byCreatedAt,\n commentPosition,\n commentTimestamp as now,\n createCommentReply,\n createCommentThread,\n deleteCommentThread,\n editCommentThread,\n findLiveCommentThread,\n liveReplies,\n readComments,\n replyToCommentThread,\n resolveCommentThread,\n takesPartInThread,\n writeComments,\n type CommentAuthor\n} from '@pairdraw/scene-graph/comments'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { nodeOf, type NodeRef } from './behaviours'\n\n/** Who scripts and agents comment as when they give no name. */\nexport const DEFAULT_COMMENT_AUTHOR = 'Agent'\n\nexport interface CommentFilter {\n /** true for resolved threads only, false for open ones; both when left out. */\n resolved?: boolean\n /** Only threads on this page. */\n page?: NodeRef\n /** Only threads this person started or replied to. */\n author?: string\n}\n\nexport interface NewComment {\n /** Pin the comment on this layer; it follows the top-level layer it lands on. */\n node?: NodeRef\n /** The page to comment on without a layer; the current page by default. */\n page?: NodeRef\n /** Canvas position on the page, or offset from the layer's top-left corner. */\n x?: number\n y?: number\n author?: string\n}\n\nfunction author(name: string | undefined): CommentAuthor {\n return { name: name?.trim() || DEFAULT_COMMENT_AUTHOR }\n}\n\nfunction pageOf(graph: SceneGraph, nodeId: string): string {\n const page = graph.pageOf(nodeId)\n if (page === null) throw new Error(`${graph.getNode(nodeId)?.name ?? nodeId} is not on a page`)\n return page\n}\n\n/**\n * A comment thread as scripts read and answer it, in the style of the Figma API: properties\n * read the thread as the document holds it now, and every change is written at once, where\n * the editor and collaborators see it.\n */\nexport class CommentHandle {\n constructor(\n private readonly graph: SceneGraph,\n readonly id: string\n ) {}\n\n private get thread(): CommentThread {\n const thread = findLiveCommentThread(readComments(this.graph), this.id)\n if (!thread) throw new Error(`Comment ${this.id} was deleted`)\n return thread\n }\n\n private edit(change: (thread: CommentThread) => CommentThread): this {\n const threads = readComments(this.graph)\n if (!findLiveCommentThread(threads, this.id)) throw new Error(`Comment ${this.id} was deleted`)\n writeComments(this.graph, editCommentThread(threads, this.id, now(), change))\n return this\n }\n\n get text(): string {\n return this.thread.text\n }\n\n get author(): string {\n return this.thread.author\n }\n\n get createdAt(): string {\n return this.thread.createdAt\n }\n\n get resolved(): boolean {\n return this.thread.resolved\n }\n\n /** The page the comment is on. */\n get page(): { id: string; name: string } {\n const { pageId, pageName } = this.thread\n return { id: pageId, name: this.graph.getNode(pageId)?.name ?? pageName ?? '' }\n }\n\n /** The top-level layer the comment is pinned to, while it exists. */\n get node(): { id: string; name: string } | null {\n const { nodeId } = this.thread\n const node = nodeId ? this.graph.getNode(nodeId) : undefined\n return node ? { id: node.id, name: node.name } : null\n }\n\n /** Where the pin is on the page's canvas. */\n get position(): Vector {\n return commentPosition(this.graph, this.thread)\n }\n\n get replies(): { id: string; author: string; text: string; createdAt: string }[] {\n return liveReplies(this.thread).map(({ id, author, text, createdAt }) => ({\n id,\n author,\n text,\n createdAt\n }))\n }\n\n /** Answer the thread, which reopens it if it was resolved. */\n reply(text: string, options: { author?: string } = {}): this {\n const body = text.trim()\n if (!body) throw new Error('A reply needs text')\n const entry = createCommentReply(author(options.author), body, now())\n return this.edit((thread) => replyToCommentThread(thread, entry))\n }\n\n resolve(): this {\n return this.edit((thread) => resolveCommentThread(thread, true, now()))\n }\n\n reopen(): this {\n return this.edit((thread) => resolveCommentThread(thread, false, now()))\n }\n\n /** Delete the thread and its replies for everyone. */\n remove(): void {\n this.edit(deleteCommentThread)\n }\n\n toJSON() {\n return {\n id: this.id,\n text: this.text,\n author: this.author,\n createdAt: this.createdAt,\n resolved: this.resolved,\n page: this.page,\n node: this.node,\n position: this.position,\n replies: this.replies\n }\n }\n}\n\n/** The document's live threads, oldest first, narrowed by `filter`. */\nexport function getComments(graph: SceneGraph, filter: CommentFilter = {}): CommentHandle[] {\n const pageId = filter.page === undefined ? undefined : nodeOf(graph, filter.page).id\n return readComments(graph)\n .filter(\n (thread) =>\n !thread.deleted &&\n (filter.resolved === undefined || thread.resolved === filter.resolved) &&\n (pageId === undefined || thread.pageId === pageId) &&\n (filter.author === undefined || takesPartInThread(thread, filter.author))\n )\n .sort(byCreatedAt)\n .map((thread) => new CommentHandle(graph, thread.id))\n}\n\nexport function getComment(graph: SceneGraph, id: string): CommentHandle | null {\n return findLiveCommentThread(readComments(graph), id) ? new CommentHandle(graph, id) : null\n}\n\n/** Leave a comment on a layer, or at a point of a page. */\nexport function addComment(\n graph: SceneGraph,\n currentPageId: string,\n text: string,\n options: NewComment = {}\n): CommentHandle {\n const body = text.trim()\n if (!body) throw new Error('A comment needs text')\n const dx = options.x ?? 0\n const dy = options.y ?? 0\n let pageId: string\n let at: Vector\n const node = options.node === undefined ? undefined : nodeOf(graph, options.node)\n if (node) {\n pageId = pageOf(graph, node.id)\n const abs = graph.getAbsolutePosition(node.id)\n at = { x: abs.x + dx, y: abs.y + dy }\n } else {\n pageId = options.page === undefined ? currentPageId : nodeOf(graph, options.page).id\n if (graph.getNode(pageId)?.type !== 'CANVAS') throw new Error(`${pageId} is not a page`)\n at = { x: dx, y: dy }\n }\n const thread = createCommentThread(graph, {\n pageId,\n at,\n node,\n author: author(options.author),\n text: body,\n now: now()\n })\n writeComments(graph, [...readComments(graph), thread])\n return new CommentHandle(graph, thread.id)\n}\n"],"mappings":";;;;AAuBA,MAAa,yBAAyB;AAsBtC,SAAS,OAAO,MAAyC;CACv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.js","names":["now"],"sources":["../../src/pairdraw-api/comments.ts"],"sourcesContent":["import type { CommentThread, SceneGraph } from '@pairdraw/scene-graph'\nimport {\n byCreatedAt,\n commentPosition,\n commentTimestamp as now,\n createCommentReply,\n createCommentThread,\n deleteCommentThread,\n editCommentThread,\n findLiveCommentThread,\n liveReplies,\n readComments,\n replyToCommentThread,\n resolveCommentThread,\n takesPartInThread,\n writeComments,\n type CommentAuthor\n} from '@pairdraw/scene-graph/comments'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { nodeOf, type NodeRef } from './behaviours'\n\n/** Who scripts and agents comment as when they give no name. */\nexport const DEFAULT_COMMENT_AUTHOR = 'Agent'\n\nexport interface CommentFilter {\n /** true for resolved threads only, false for open ones; both when left out. */\n resolved?: boolean\n /** Only threads on this page. */\n page?: NodeRef\n /** Only threads this person started or replied to. */\n author?: string\n}\n\nexport interface NewComment {\n /** Pin the comment on this layer; it follows the top-level layer it lands on. */\n node?: NodeRef\n /** The page to comment on without a layer; the current page by default. */\n page?: NodeRef\n /** Canvas position on the page, or offset from the layer's top-left corner. */\n x?: number\n y?: number\n author?: string\n}\n\nfunction author(name: string | undefined): CommentAuthor {\n return { name: name?.trim() || DEFAULT_COMMENT_AUTHOR }\n}\n\nfunction pageOf(graph: SceneGraph, nodeId: string): string {\n const page = graph.pageOf(nodeId)\n if (page === null) throw new Error(`${graph.getNode(nodeId)?.name ?? nodeId} is not on a page`)\n return page\n}\n\n/**\n * A comment thread as scripts read and answer it, in the style of the Figma API: properties\n * read the thread as the document holds it now, and every change is written at once, where\n * the editor and collaborators see it.\n */\nexport class CommentHandle {\n constructor(\n private readonly graph: SceneGraph,\n readonly id: string\n ) {}\n\n private get thread(): CommentThread {\n const thread = findLiveCommentThread(readComments(this.graph), this.id)\n if (!thread) throw new Error(`Comment ${this.id} was deleted`)\n return thread\n }\n\n private edit(change: (thread: CommentThread) => CommentThread): this {\n const threads = readComments(this.graph)\n if (!findLiveCommentThread(threads, this.id)) throw new Error(`Comment ${this.id} was deleted`)\n writeComments(this.graph, editCommentThread(threads, this.id, now(), change))\n return this\n }\n\n get text(): string {\n return this.thread.text\n }\n\n get author(): string {\n return this.thread.author\n }\n\n get createdAt(): string {\n return this.thread.createdAt\n }\n\n get resolved(): boolean {\n return this.thread.resolved\n }\n\n /** The page the comment is on. */\n get page(): { id: string; name: string } {\n const { pageId, pageName } = this.thread\n return { id: pageId, name: this.graph.getNode(pageId)?.name ?? pageName ?? '' }\n }\n\n /** The top-level layer the comment is pinned to, while it exists. */\n get node(): { id: string; name: string } | null {\n const { nodeId } = this.thread\n const node = nodeId ? this.graph.getNode(nodeId) : undefined\n return node ? { id: node.id, name: node.name } : null\n }\n\n /** Where the pin is on the page's canvas. */\n get position(): Vector {\n return commentPosition(this.graph, this.thread)\n }\n\n /** The area the person circled, in canvas units relative to the pin; null for a clicked pin. */\n get region(): CommentThread['region'] {\n return this.thread.region ?? null\n }\n\n get replies(): { id: string; author: string; text: string; createdAt: string }[] {\n return liveReplies(this.thread).map(({ id, author, text, createdAt }) => ({\n id,\n author,\n text,\n createdAt\n }))\n }\n\n /** Answer the thread, which reopens it if it was resolved. */\n reply(text: string, options: { author?: string } = {}): this {\n const body = text.trim()\n if (!body) throw new Error('A reply needs text')\n const entry = createCommentReply(author(options.author), body, now())\n return this.edit((thread) => replyToCommentThread(thread, entry))\n }\n\n resolve(): this {\n return this.edit((thread) => resolveCommentThread(thread, true, now()))\n }\n\n reopen(): this {\n return this.edit((thread) => resolveCommentThread(thread, false, now()))\n }\n\n /** Delete the thread and its replies for everyone. */\n remove(): void {\n this.edit(deleteCommentThread)\n }\n\n toJSON() {\n return {\n id: this.id,\n text: this.text,\n author: this.author,\n createdAt: this.createdAt,\n resolved: this.resolved,\n page: this.page,\n node: this.node,\n position: this.position,\n region: this.region,\n replies: this.replies\n }\n }\n}\n\n/** The document's live threads, oldest first, narrowed by `filter`. */\nexport function getComments(graph: SceneGraph, filter: CommentFilter = {}): CommentHandle[] {\n const pageId = filter.page === undefined ? undefined : nodeOf(graph, filter.page).id\n return readComments(graph)\n .filter(\n (thread) =>\n !thread.deleted &&\n (filter.resolved === undefined || thread.resolved === filter.resolved) &&\n (pageId === undefined || thread.pageId === pageId) &&\n (filter.author === undefined || takesPartInThread(thread, filter.author))\n )\n .sort(byCreatedAt)\n .map((thread) => new CommentHandle(graph, thread.id))\n}\n\nexport function getComment(graph: SceneGraph, id: string): CommentHandle | null {\n return findLiveCommentThread(readComments(graph), id) ? new CommentHandle(graph, id) : null\n}\n\n/** Leave a comment on a layer, or at a point of a page. */\nexport function addComment(\n graph: SceneGraph,\n currentPageId: string,\n text: string,\n options: NewComment = {}\n): CommentHandle {\n const body = text.trim()\n if (!body) throw new Error('A comment needs text')\n const dx = options.x ?? 0\n const dy = options.y ?? 0\n let pageId: string\n let at: Vector\n const node = options.node === undefined ? undefined : nodeOf(graph, options.node)\n if (node) {\n pageId = pageOf(graph, node.id)\n const abs = graph.getAbsolutePosition(node.id)\n at = { x: abs.x + dx, y: abs.y + dy }\n } else {\n pageId = options.page === undefined ? currentPageId : nodeOf(graph, options.page).id\n if (graph.getNode(pageId)?.type !== 'CANVAS') throw new Error(`${pageId} is not a page`)\n at = { x: dx, y: dy }\n }\n const thread = createCommentThread(graph, {\n pageId,\n at,\n node,\n author: author(options.author),\n text: body,\n now: now()\n })\n writeComments(graph, [...readComments(graph), thread])\n return new CommentHandle(graph, thread.id)\n}\n"],"mappings":";;;;AAuBA,MAAa,yBAAyB;AAsBtC,SAAS,OAAO,MAAyC;CACvD,OAAO,EAAE,MAAM,MAAM,KAAK,KAAA,QAA4B;AACxD;AAEA,SAAS,OAAO,OAAmB,QAAwB;CACzD,MAAM,OAAO,MAAM,OAAO,MAAM;CAChC,IAAI,SAAS,MAAM,MAAM,IAAI,MAAM,GAAG,MAAM,QAAQ,MAAM,CAAC,EAAE,QAAQ,OAAO,kBAAkB;CAC9F,OAAO;AACT;;;;;;AAOA,IAAa,gBAAb,MAA2B;C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AO,sBAAsB,aAAa,KAAK,GAAG,EAAE,IAAI,IAAI,cAAc,OAAO,EAAE,IAAI;AACzF;;AAGA,SAAgB,WACd,OACA,eACA,MACA,UAAsB,CAAC,GACR;CACf,MAAM,OAAO,KAAK,KAAK;CACvB,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,sBAAsB;CACjD,MAAM,KAAK,QAAQ,KAAK;CACxB,MAAM,KAAK,QAAQ,KAAK;CACxB,IAAI;CACJ,IAAI;CACJ,MAAM,OAAO,QAAQ,SAAS,KAAA,IAAY,KAAA,IAAY,OAAO,OAAO,QAAQ,IAAI;CAChF,IAAI,MAAM;EACR,SAAS,OAAO,OAAO,KAAK,EAAE;EAC9B,MAAM,MAAM,MAAM,oBAAoB,KAAK,EAAE;EAC7C,KAAK;GAAE,GAAG,IAAI,IAAI;GAAI,GAAG,IAAI,IAAI;EAAG;CACtC,OAAO;EACL,SAAS,QAAQ,SAAS,KAAA,IAAY,gBAAgB,OAAO,OAAO,QAAQ,IAAI,CAAC,CAAC;EAClF,IAAI,MAAM,QAAQ,MAAM,CAAC,EAAE,SAAS,UAAU,MAAM,IAAI,MAAM,GAAG,OAAO,eAAe;EACvF,KAAK;GAAE,GAAG;GAAI,GAAG;EAAG;CACtB;CACA,MAAM,SAAS,oBAAoB,OAAO;EACxC;EACA;EACA;EACA,QAAQ,OAAO,QAAQ,MAAM;EAC7B,MAAM;EACN,KAAKA,iBAAI;CACX,CAAC;CACD,cAAc,OAAO,CAAC,GAAG,aAAa,KAAK,GAAG,MAAM,CAAC;CACrD,OAAO,IAAI,cAAc,OAAO,OAAO,EAAE;AAC3C"}
|
|
@@ -3,15 +3,15 @@ import { DesignMemoryReport } from "../design-memory/describe.js";
|
|
|
3
3
|
import { FigmaNodeProxy } from "../figma-api/proxy.js";
|
|
4
4
|
import { FigmaAPI } from "../figma-api/index.js";
|
|
5
5
|
import "../design-memory/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { FontReadiness } from "../text/font/readiness.js";
|
|
7
7
|
import { BehaviourHandle, NodeRef } from "./behaviours.js";
|
|
8
8
|
import { CommentFilter, CommentHandle, DEFAULT_COMMENT_AUTHOR, NewComment } from "./comments.js";
|
|
9
9
|
import { StatusInfo } from "./statuses.js";
|
|
10
10
|
import { VariableRef } from "./variables.js";
|
|
11
11
|
import { VariationSetHandle, VariationSetInfo } from "./variations.js";
|
|
12
12
|
import { BehaviourKind, BehaviourSpec } from "@pairdraw/scene-graph/behaviours";
|
|
13
|
-
import { VariableLiteral } from "@pairdraw/scene-graph";
|
|
14
13
|
import { OkHCLColor, OkHCLPayload } from "@pairdraw/scene-graph/color";
|
|
14
|
+
import { VariableLiteral } from "@pairdraw/scene-graph";
|
|
15
15
|
import { DesignMemoryGroup } from "@pairdraw/scene-graph/design-memory";
|
|
16
16
|
//#region src/pairdraw-api/index.d.ts
|
|
17
17
|
/**
|
|
@@ -122,7 +122,7 @@ declare class PairdrawAPI {
|
|
|
122
122
|
* Whether the current page's fonts are faithfully available: requested faces, where each
|
|
123
123
|
* loaded from, substitutions, why an installed face could not load, and the layers affected.
|
|
124
124
|
*/
|
|
125
|
-
getFontStatus():
|
|
125
|
+
getFontStatus(): FontReadiness;
|
|
126
126
|
/** A fill's OkHCL color, which the color picker keeps beside its RGB, or null. */
|
|
127
127
|
getFillOkHCL(node: NodeRef, index?: number): OkHCLPayload | null;
|
|
128
128
|
/** Set a fill's color in OkHCL; its RGB follows in the document's color space. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/pairdraw-api/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;cA2Ea;mBACkB;EAAA,YAAA,OAAO;;;;;;;;EASpC,mBACE,wBACA,sBACA,gBACA,oBACC;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/pairdraw-api/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;cA2Ea;mBACkB;EAAA,YAAA,OAAO;;;;;;;;EASpC,mBACE,wBACA,sBACA,gBACA,oBACC;;;;;;;EA4BH,aAAa,MAAM,SAAS,eAAe,UAAU;;EAKrD,eAAe,MAAM,SAAS;;MAK1B;;;;;;EAKJ,aAAa,MAAM,UAAU;;;;;;EAS7B,aAAa,MAAM,SAAS,MAAM,gBAAgB,gBAAgB;;EAKlE,WAAW,OAAO;;;;;EAQlB,YAAY,SAAS,gBAAgB;EAIrC,WAAW,aAAa;;;;;EAQxB,WAAW,cAAc,UAAU,aAAa;;;;;MAQ5C,YAAY;;EAKhB,UAAU,MAAM;;;;;EAQhB,UAAU,MAAM,SAAS;;;;;;MASrB,gBAAgB;;;;;EAQpB,kBACE,UAAU,QAAQ,OAAO,oDACxB;;;;;EAQH,qBAAqB,cAAc,UAAU;IAAY;IAAmB;;;;;;;EAS5E,iBACE,MAAM,SACN;IAAW;IAAe;;IACvB,KAAK;IAAoB,UAAU;;;EAMxC,cAAc,MAAM,UAAU;;MAK1B,cAAc;;;;;EAQlB,mBACE,oBAAoB,WACpB,qBAAqB,WACrB,wBACC;;;;;EAgBH,iBAAiB;;EAKjB,aAAa,MAAM,SAAS,iBAAY;;EAKxC,aAAa,MAAM,SAAS,OAAO,YAAY;EAI/C,eAAe,MAAM,SAAS,iBAAY;EAI1C,eAAe,MAAM,SAAS,OAAO,YAAY;;EAKjD,mBAAmB,MAAM;EAIzB,mBAAmB,MAAM,SAAS;;EAKlC,iBAAiB,MAAM;EAIvB,iBAAiB,MAAM,SAAS;;EAKhC,gBAAgB,MAAM,SAAS,UAAU;;EAKzC,qBACE,MAAM,SACN,eACA,aACA,UAAU"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFontReadiness } from "../text/font/readiness.js";
|
|
2
|
+
import { describeDesignMemory } from "../design-memory/describe.js";
|
|
2
3
|
import { exposeInstanceSwap } from "../figma-api/components.js";
|
|
3
4
|
import { writeVariableValue } from "../figma-api/variables/variable.js";
|
|
4
|
-
import { describeDesignMemory } from "../design-memory/describe.js";
|
|
5
5
|
import { BehaviourHandle, getBehaviour, makeSlot, nodeOf, setBehaviour } from "./behaviours.js";
|
|
6
6
|
import { CommentHandle, DEFAULT_COMMENT_AUTHOR, addComment, getComment, getComments } from "./comments.js";
|
|
7
7
|
import { checkProposedDesignValues, recordDesignDecision } from "./design-memory.js";
|
|
@@ -31,10 +31,10 @@ var PairdrawAPI = class {
|
|
|
31
31
|
*/
|
|
32
32
|
setVariableFormula(collectionName, variableName, source, modeName) {
|
|
33
33
|
const graph = this.figma.graph;
|
|
34
|
-
const collections =
|
|
34
|
+
const collections = graph.getLiveCollections().filter((item) => item.name === collectionName);
|
|
35
35
|
const collection = collections.at(0);
|
|
36
36
|
if (!collection || collections.length !== 1) throw new Error(`Unknown or ambiguous collection: ${collectionName}`);
|
|
37
|
-
const variables =
|
|
37
|
+
const variables = graph.getLiveVariables().filter((item) => item.collectionId === collection.id && item.name === variableName);
|
|
38
38
|
const variable = variables.at(0);
|
|
39
39
|
if (!variable || variables.length !== 1) throw new Error(`Unknown or ambiguous variable: ${variableName}`);
|
|
40
40
|
const modes = collection.modes.filter((mode) => modeName ? mode.name === modeName : mode.modeId === collection.defaultModeId);
|
|
@@ -171,7 +171,7 @@ var PairdrawAPI = class {
|
|
|
171
171
|
* loaded from, substitutions, why an installed face could not load, and the layers affected.
|
|
172
172
|
*/
|
|
173
173
|
getFontStatus() {
|
|
174
|
-
return
|
|
174
|
+
return readFontReadiness(this.figma.graph, this.figma.currentPageId);
|
|
175
175
|
}
|
|
176
176
|
/** A fill's OkHCL color, which the color picker keeps beside its RGB, or null. */
|
|
177
177
|
getFillOkHCL(node, index = 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/pairdraw-api/index.ts"],"sourcesContent":["import type { VariableLiteral } from '@pairdraw/scene-graph'\nimport {\n BEHAVIOUR_CONTRACTS,\n BEHAVIOUR_KINDS,\n type BehaviourKind,\n type BehaviourSpec\n} from '@pairdraw/scene-graph/behaviours'\nimport type { OkHCLColor, OkHCLPayload } from '@pairdraw/scene-graph/color'\nimport type { DesignMemoryGroup } from '@pairdraw/scene-graph/design-memory'\nimport { parseVariableFormula } from '@pairdraw/scene-graph/variables'\n\nimport {\n describeDesignMemory,\n type DesignMemoryReport,\n type DesignValueVerdict\n} from '#core/design-memory'\nimport { exposeInstanceSwap } from '#core/figma-api/components'\nimport type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api/index'\nimport { writeVariableValue } from '#core/figma-api/variables'\nimport { documentFontStatus, type DocumentFontStatus } from '#core/text/font/status'\n\nimport {\n getBehaviour,\n makeSlot,\n nodeOf,\n setBehaviour,\n type BehaviourHandle,\n type NodeRef\n} from './behaviours'\nimport {\n addComment,\n getComment,\n getComments,\n type CommentFilter,\n type CommentHandle,\n type NewComment\n} from './comments'\nimport { checkProposedDesignValues, recordDesignDecision } from './design-memory'\nimport {\n readFillOkHCL,\n readLayoutDirection,\n readStrokeOkHCL,\n readTextDirection,\n writeFillOkHCL,\n writeFontFeatures,\n writeLayoutDirection,\n writeRangeFontFeatures,\n writeStrokeOkHCL,\n writeTextDirection\n} from './nodes'\nimport { getStatus, listStatuses, setStatus, type StatusInfo } from './statuses'\nimport { bindVariable, unbindVariable, type VariableRef } from './variables'\nimport {\n createVariationSet,\n getVariationSet,\n listVariationSets,\n type VariationSetHandle\n} from './variations'\n\nexport { BehaviourHandle, type NodeRef } from './behaviours'\nexport type { StatusInfo } from './statuses'\nexport type { VariableRef } from './variables'\nexport { VariationSetHandle, type VariationSetInfo } from './variations'\nexport {\n CommentHandle,\n DEFAULT_COMMENT_AUTHOR,\n type CommentFilter,\n type NewComment\n} from './comments'\n\n/**\n * What Pairdraw adds to the Figma Plugin API for scripts, as the `pairdraw` global next to\n * `figma`: features Figma has no API for, in the same style. It edits the same document as the\n * `figma` it is made for.\n */\nexport class PairdrawAPI {\n constructor(private readonly figma: FigmaAPI) {}\n\n /**\n * Set a token formula by collection, variable and optional mode names. References use\n * `{variable/name}` or `{Collection::variable/name}` and persist by ID; a true/false formula\n * can compare numbers, as in `{width} > 600 and not {loading}`, and `if()`, `text()` and\n * `truthy()` pick values, write text, and test text or numbers, as in\n * `if({compact}, \"Hi\", \"Hello, \" + {name})`.\n */\n setVariableFormula(\n collectionName: string,\n variableName: string,\n source: string,\n modeName?: string\n ): VariableLiteral {\n const graph = this.figma.graph\n const collections = [...graph.variableCollections.values()].filter(\n (item) => item.name === collectionName\n )\n const collection = collections.at(0)\n if (!collection || collections.length !== 1)\n throw new Error(`Unknown or ambiguous collection: ${collectionName}`)\n const variables = [...graph.variables.values()].filter(\n (item) => item.collectionId === collection.id && item.name === variableName\n )\n const variable = variables.at(0)\n if (!variable || variables.length !== 1)\n throw new Error(`Unknown or ambiguous variable: ${variableName}`)\n const modes = collection.modes.filter((mode) =>\n modeName ? mode.name === modeName : mode.modeId === collection.defaultModeId\n )\n const mode = modes.at(0)\n if (!mode || modes.length !== 1) throw new Error(`Unknown or ambiguous mode: ${modeName}`)\n const { value, resolved } = parseVariableFormula(graph, variable.id, mode.modeId, source)\n writeVariableValue(graph, variable, mode.modeId, value)\n return resolved\n }\n\n /**\n * Bind a layer field to a variable from `figma.variables`, as the layer panel does:\n * fields by Pairdraw's names, such as `'text'`, `'visible'`, `'opacity'` or `'fills/0/color'`.\n * Text content takes a text or number variable, a number shown as text; visibility takes a\n * boolean, or text that shows the layer unless it is empty or reads false, no or off.\n */\n bindVariable(node: NodeRef, field: string, variable: VariableRef): void {\n bindVariable(this.figma.graph, node, field, variable)\n }\n\n /** Let a layer field go of its variable, keeping the value the variable last gave it. */\n unbindVariable(node: NodeRef, field: string): void {\n unbindVariable(this.figma.graph, node, field)\n }\n\n /** The behaviour kinds, after Reka UI's primitives, with the values and parts each binds. */\n get behaviourKinds() {\n return BEHAVIOUR_KINDS.map((kind) => ({ kind, ...structuredClone(BEHAVIOUR_CONTRACTS[kind]) }))\n }\n\n /** The behaviour a node's main component keeps, or null; a variant reads its set's. */\n getBehaviour(node: NodeRef): BehaviourHandle | null {\n return getBehaviour(this.figma.graph, node)\n }\n\n /**\n * Give a main component or component set a behaviour, replacing any it has: a kind alone, or\n * a spec naming its properties and slots, such as\n * `{ kind: 'switch', values: { value: 'State' }, parts: { thumb: 'Thumb' }, states: 'Interaction' }`.\n */\n setBehaviour(node: NodeRef, spec: BehaviourKind | BehaviourSpec): BehaviourHandle {\n return setBehaviour(this.figma.graph, node, spec)\n }\n\n /** Make a frame of a main component a slot, as Create slot does; returns the slot's name. */\n createSlot(frame: NodeRef): string {\n return makeSlot(this.figma.graph, frame)\n }\n\n /**\n * The document's comment threads, oldest first: all of them, or only resolved or open ones,\n * one page's, or those a person started or replied to, such as `{ resolved: false }`.\n */\n getComments(filter?: CommentFilter): CommentHandle[] {\n return getComments(this.figma.graph, filter)\n }\n\n getComment(id: string): CommentHandle | null {\n return getComment(this.figma.graph, id)\n }\n\n /**\n * Leave a comment pinned on a layer, `{ node }`, which it then follows, or at a point of a\n * page, `{ page, x, y }`; the current page by default. `author` names who wrote it.\n */\n addComment(text: string, options?: NewComment): CommentHandle {\n return addComment(this.figma.graph, this.figma.currentPageId, text, options)\n }\n\n /**\n * The document's statuses, such as Ready for dev or the team's own Approved, with each one's\n * color and the status Figma shows for it, if any.\n */\n get statuses(): StatusInfo[] {\n return listStatuses(this.figma.graph)\n }\n\n /** The name of the status a section, frame, component, set or instance shows, or null. */\n getStatus(node: NodeRef): string | null {\n return getStatus(this.figma.graph, node)\n }\n\n /**\n * Give a layer one of the document's statuses by name, or clear it with null. Only sections,\n * frames, components, sets and instances directly on a page or in a section take one.\n */\n setStatus(node: NodeRef, status: string | null): void {\n setStatus(this.figma.graph, node, status)\n }\n\n /**\n * The document's design memory: the colors, fonts, sizes, spacing and radii agents may use,\n * whether an off-system value is refused or warned about, the decisions written down, and the\n * layers pinned as examples. Null when the document has none.\n */\n get designMemory(): DesignMemoryReport | null {\n return describeDesignMemory(this.figma.graph)\n }\n\n /**\n * Judge values before using them, such as `{ colors: ['#FF00AA'], spacing: [13] }`: each comes\n * back `ok`, `warn`, `refuse` or `invalid`, with the nearest allowed value.\n */\n checkDesignValues(\n proposal: Partial<Record<DesignMemoryGroup, readonly (string | number)[]>>\n ): DesignValueVerdict[] {\n return checkProposedDesignValues(this.figma.graph, proposal)\n }\n\n /**\n * Write a decision down in the design memory, optionally pinning a layer that shows it as an\n * example. The memory's allowed values stay as the person set them.\n */\n recordDesignDecision(text: string, example?: NodeRef): { decisions: number; examples: number } {\n return recordDesignDecision(this.figma.graph, text, example)\n }\n\n /**\n * Copy a layer `count` times (1 to 8) into a section of variations beside it, made the first\n * time; `labels` name what each version tries, as in `V2 · Calmer palette`. On a version, it\n * copies that version into its set. The original does not change.\n */\n createVariations(\n node: NodeRef,\n options: { count: number; labels?: readonly string[] }\n ): { set: VariationSetHandle; versions: FigmaNodeProxy[] } {\n const { set, created } = createVariationSet(this.figma, node, options)\n return { set, versions: created }\n }\n\n /** The set of variations a layer belongs to, from its section, a version or a layer inside one. */\n getVariations(node: NodeRef): VariationSetHandle | null {\n return getVariationSet(this.figma, node)\n }\n\n /** The sets of variations on the current page. */\n get variations(): VariationSetHandle[] {\n return listVariationSets(this.figma, this.figma.currentPageId)\n }\n\n /**\n * Expose a swap on instances as one INSTANCE_SWAP property, offering the candidate components;\n * returns the layer that holds the property.\n */\n exposeInstanceSwap(\n instances: readonly NodeRef[],\n candidates: readonly NodeRef[],\n propertyName = 'Instance'\n ): FigmaNodeProxy {\n const proxies = (refs: readonly NodeRef[]) =>\n refs.map((ref) => this.figma.wrapNode(nodeOf(this.figma.graph, ref).id))\n const host = exposeInstanceSwap(\n this.figma.graph,\n proxies(instances),\n proxies(candidates),\n propertyName\n )\n return this.figma.wrapNode(host.id)\n }\n\n /**\n * Whether the current page's fonts are faithfully available: requested faces, where each\n * loaded from, substitutions, why an installed face could not load, and the layers affected.\n */\n getFontStatus(): DocumentFontStatus {\n return documentFontStatus(this.figma.graph, this.figma.currentPageId)\n }\n\n /** A fill's OkHCL color, which the color picker keeps beside its RGB, or null. */\n getFillOkHCL(node: NodeRef, index = 0): OkHCLPayload | null {\n return readFillOkHCL(this.figma.graph, node, index)\n }\n\n /** Set a fill's color in OkHCL; its RGB follows in the document's color space. */\n setFillOkHCL(node: NodeRef, color: OkHCLColor, index = 0): void {\n writeFillOkHCL(this.figma.graph, node, color, index)\n }\n\n getStrokeOkHCL(node: NodeRef, index = 0): OkHCLPayload | null {\n return readStrokeOkHCL(this.figma.graph, node, index)\n }\n\n setStrokeOkHCL(node: NodeRef, color: OkHCLColor, index = 0): void {\n writeStrokeOkHCL(this.figma.graph, node, color, index)\n }\n\n /** Which way a frame's auto layout runs: `AUTO`, `LTR` or `RTL`. */\n getLayoutDirection(node: NodeRef): string {\n return readLayoutDirection(this.figma.graph, node)\n }\n\n setLayoutDirection(node: NodeRef, direction: string): void {\n writeLayoutDirection(this.figma.graph, node, direction)\n }\n\n /** Which way a text runs: `AUTO`, `LTR` or `RTL`. */\n getTextDirection(node: NodeRef): string {\n return readTextDirection(this.figma.graph, node)\n }\n\n setTextDirection(node: NodeRef, direction: string): void {\n writeTextDirection(this.figma.graph, node, direction)\n }\n\n /** Merges OpenType feature toggles into the text's own, keeping the tags it does not name. */\n setFontFeatures(node: NodeRef, features: Record<string, boolean>): void {\n writeFontFeatures(this.figma.graph, node, features)\n }\n\n /** Merges OpenType feature toggles into a text range's own, keeping its other features. */\n setRangeFontFeatures(\n node: NodeRef,\n start: number,\n end: number,\n features: Record<string, boolean>\n ): void {\n writeRangeFontFeatures(this.figma.graph, node, start, end, features)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2EA,IAAa,cAAb,MAAyB;CACM;CAA7B,YAAY,OAAkC;EAAjB,KAAA,QAAA;CAAkB;;;;;;;;CAS/C,mBACE,gBACA,cACA,QACA,UACiB;EACjB,MAAM,QAAQ,KAAK,MAAM;EACzB,MAAM,cAAc,CAAC,GAAG,MAA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,GAClB,YACF;EACA,OAAO,KAAK,MAAM,SAAS,KAAK,EAAE;CACpC;;;;;CAMA,gBAAoC;EAClC,OAAO,mBAAmB,KAAK,MAAM,OAAO,KAAK,MAAM,aAAa;CACtE;;CAGA,aAAa,MAAe,QAAQ,GAAwB;EAC1D,OAAO,cAAc,KAAK,MAAM,OAAO,MAAM,KAAK;CACpD;;CAGA,aAAa,MAAe,OAAmB,QAAQ,GAAS;EAC9D,eAAe,KAAK,MAAM,OAAO,MAAM,OAAO,KAAK;CACrD;CAEA,eAAe,MAAe,QAAQ,GAAwB;EAC5D,OAAO,gBAAgB,KAAK,MAAM,OAAO,MAAM,KAAK;CACtD;CAEA,eAAe,MAAe,OAAmB,QAAQ,GAAS;EAChE,iBAAiB,KAAK,MAAM,OAAO,MAAM,OAAO,KAAK;CACvD;;CAGA,mBAAmB,MAAuB;EACxC,OAAO,oBAAoB,KAAK,MAAM,OAAO,IAAI;CACnD;CAEA,mBAAmB,MAAe,WAAyB;EACzD,qBAAqB,KAAK,MAAM,OAAO,MAAM,SAAS;CACxD;;CAGA,iBAAiB,MAAuB;EACtC,OAAO,kBAAkB,KAAK,MAAM,OAAO,IAAI;CACjD;CAEA,iBAAiB,MAAe,WAAyB;EACvD,mBAAmB,KAAK,MAAM,OAAO,MAAM,SAAS;CACtD;;CAGA,gBAAgB,MAAe,UAAyC;EACtE,kBAAkB,KAAK,MAAM,OAAO,MAAM,QAAQ;CACpD;;CAGA,qBACE,MACA,OACA,KACA,UACM;EACN,uBAAuB,KAAK,MAAM,OAAO,MAAM,OAAO,KAAK,QAAQ;CACrE;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/pairdraw-api/index.ts"],"sourcesContent":["import type { VariableLiteral } from '@pairdraw/scene-graph'\nimport {\n BEHAVIOUR_CONTRACTS,\n BEHAVIOUR_KINDS,\n type BehaviourKind,\n type BehaviourSpec\n} from '@pairdraw/scene-graph/behaviours'\nimport type { OkHCLColor, OkHCLPayload } from '@pairdraw/scene-graph/color'\nimport type { DesignMemoryGroup } from '@pairdraw/scene-graph/design-memory'\nimport { parseVariableFormula } from '@pairdraw/scene-graph/variables'\n\nimport {\n describeDesignMemory,\n type DesignMemoryReport,\n type DesignValueVerdict\n} from '#core/design-memory'\nimport { exposeInstanceSwap } from '#core/figma-api/components'\nimport type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api/index'\nimport { writeVariableValue } from '#core/figma-api/variables'\nimport { readFontReadiness, type FontReadiness } from '#core/text/font/readiness'\n\nimport {\n getBehaviour,\n makeSlot,\n nodeOf,\n setBehaviour,\n type BehaviourHandle,\n type NodeRef\n} from './behaviours'\nimport {\n addComment,\n getComment,\n getComments,\n type CommentFilter,\n type CommentHandle,\n type NewComment\n} from './comments'\nimport { checkProposedDesignValues, recordDesignDecision } from './design-memory'\nimport {\n readFillOkHCL,\n readLayoutDirection,\n readStrokeOkHCL,\n readTextDirection,\n writeFillOkHCL,\n writeFontFeatures,\n writeLayoutDirection,\n writeRangeFontFeatures,\n writeStrokeOkHCL,\n writeTextDirection\n} from './nodes'\nimport { getStatus, listStatuses, setStatus, type StatusInfo } from './statuses'\nimport { bindVariable, unbindVariable, type VariableRef } from './variables'\nimport {\n createVariationSet,\n getVariationSet,\n listVariationSets,\n type VariationSetHandle\n} from './variations'\n\nexport { BehaviourHandle, type NodeRef } from './behaviours'\nexport type { StatusInfo } from './statuses'\nexport type { VariableRef } from './variables'\nexport { VariationSetHandle, type VariationSetInfo } from './variations'\nexport {\n CommentHandle,\n DEFAULT_COMMENT_AUTHOR,\n type CommentFilter,\n type NewComment\n} from './comments'\n\n/**\n * What Pairdraw adds to the Figma Plugin API for scripts, as the `pairdraw` global next to\n * `figma`: features Figma has no API for, in the same style. It edits the same document as the\n * `figma` it is made for.\n */\nexport class PairdrawAPI {\n constructor(private readonly figma: FigmaAPI) {}\n\n /**\n * Set a token formula by collection, variable and optional mode names. References use\n * `{variable/name}` or `{Collection::variable/name}` and persist by ID; a true/false formula\n * can compare numbers, as in `{width} > 600 and not {loading}`, and `if()`, `text()` and\n * `truthy()` pick values, write text, and test text or numbers, as in\n * `if({compact}, \"Hi\", \"Hello, \" + {name})`.\n */\n setVariableFormula(\n collectionName: string,\n variableName: string,\n source: string,\n modeName?: string\n ): VariableLiteral {\n const graph = this.figma.graph\n const collections = graph.getLiveCollections().filter((item) => item.name === collectionName)\n const collection = collections.at(0)\n if (!collection || collections.length !== 1)\n throw new Error(`Unknown or ambiguous collection: ${collectionName}`)\n const variables = graph\n .getLiveVariables()\n .filter((item) => item.collectionId === collection.id && item.name === variableName)\n const variable = variables.at(0)\n if (!variable || variables.length !== 1)\n throw new Error(`Unknown or ambiguous variable: ${variableName}`)\n const modes = collection.modes.filter((mode) =>\n modeName ? mode.name === modeName : mode.modeId === collection.defaultModeId\n )\n const mode = modes.at(0)\n if (!mode || modes.length !== 1) throw new Error(`Unknown or ambiguous mode: ${modeName}`)\n const { value, resolved } = parseVariableFormula(graph, variable.id, mode.modeId, source)\n writeVariableValue(graph, variable, mode.modeId, value)\n return resolved\n }\n\n /**\n * Bind a layer field to a variable from `figma.variables`, as the layer panel does:\n * fields by Pairdraw's names, such as `'text'`, `'visible'`, `'opacity'` or `'fills/0/color'`.\n * Text content takes a text or number variable, a number shown as text; visibility takes a\n * boolean, or text that shows the layer unless it is empty or reads false, no or off.\n */\n bindVariable(node: NodeRef, field: string, variable: VariableRef): void {\n bindVariable(this.figma.graph, node, field, variable)\n }\n\n /** Let a layer field go of its variable, keeping the value the variable last gave it. */\n unbindVariable(node: NodeRef, field: string): void {\n unbindVariable(this.figma.graph, node, field)\n }\n\n /** The behaviour kinds, after Reka UI's primitives, with the values and parts each binds. */\n get behaviourKinds() {\n return BEHAVIOUR_KINDS.map((kind) => ({ kind, ...structuredClone(BEHAVIOUR_CONTRACTS[kind]) }))\n }\n\n /** The behaviour a node's main component keeps, or null; a variant reads its set's. */\n getBehaviour(node: NodeRef): BehaviourHandle | null {\n return getBehaviour(this.figma.graph, node)\n }\n\n /**\n * Give a main component or component set a behaviour, replacing any it has: a kind alone, or\n * a spec naming its properties and slots, such as\n * `{ kind: 'switch', values: { value: 'State' }, parts: { thumb: 'Thumb' }, states: 'Interaction' }`.\n */\n setBehaviour(node: NodeRef, spec: BehaviourKind | BehaviourSpec): BehaviourHandle {\n return setBehaviour(this.figma.graph, node, spec)\n }\n\n /** Make a frame of a main component a slot, as Create slot does; returns the slot's name. */\n createSlot(frame: NodeRef): string {\n return makeSlot(this.figma.graph, frame)\n }\n\n /**\n * The document's comment threads, oldest first: all of them, or only resolved or open ones,\n * one page's, or those a person started or replied to, such as `{ resolved: false }`.\n */\n getComments(filter?: CommentFilter): CommentHandle[] {\n return getComments(this.figma.graph, filter)\n }\n\n getComment(id: string): CommentHandle | null {\n return getComment(this.figma.graph, id)\n }\n\n /**\n * Leave a comment pinned on a layer, `{ node }`, which it then follows, or at a point of a\n * page, `{ page, x, y }`; the current page by default. `author` names who wrote it.\n */\n addComment(text: string, options?: NewComment): CommentHandle {\n return addComment(this.figma.graph, this.figma.currentPageId, text, options)\n }\n\n /**\n * The document's statuses, such as Ready for dev or the team's own Approved, with each one's\n * color and the status Figma shows for it, if any.\n */\n get statuses(): StatusInfo[] {\n return listStatuses(this.figma.graph)\n }\n\n /** The name of the status a section, frame, component, set or instance shows, or null. */\n getStatus(node: NodeRef): string | null {\n return getStatus(this.figma.graph, node)\n }\n\n /**\n * Give a layer one of the document's statuses by name, or clear it with null. Only sections,\n * frames, components, sets and instances directly on a page or in a section take one.\n */\n setStatus(node: NodeRef, status: string | null): void {\n setStatus(this.figma.graph, node, status)\n }\n\n /**\n * The document's design memory: the colors, fonts, sizes, spacing and radii agents may use,\n * whether an off-system value is refused or warned about, the decisions written down, and the\n * layers pinned as examples. Null when the document has none.\n */\n get designMemory(): DesignMemoryReport | null {\n return describeDesignMemory(this.figma.graph)\n }\n\n /**\n * Judge values before using them, such as `{ colors: ['#FF00AA'], spacing: [13] }`: each comes\n * back `ok`, `warn`, `refuse` or `invalid`, with the nearest allowed value.\n */\n checkDesignValues(\n proposal: Partial<Record<DesignMemoryGroup, readonly (string | number)[]>>\n ): DesignValueVerdict[] {\n return checkProposedDesignValues(this.figma.graph, proposal)\n }\n\n /**\n * Write a decision down in the design memory, optionally pinning a layer that shows it as an\n * example. The memory's allowed values stay as the person set them.\n */\n recordDesignDecision(text: string, example?: NodeRef): { decisions: number; examples: number } {\n return recordDesignDecision(this.figma.graph, text, example)\n }\n\n /**\n * Copy a layer `count` times (1 to 8) into a section of variations beside it, made the first\n * time; `labels` name what each version tries, as in `V2 · Calmer palette`. On a version, it\n * copies that version into its set. The original does not change.\n */\n createVariations(\n node: NodeRef,\n options: { count: number; labels?: readonly string[] }\n ): { set: VariationSetHandle; versions: FigmaNodeProxy[] } {\n const { set, created } = createVariationSet(this.figma, node, options)\n return { set, versions: created }\n }\n\n /** The set of variations a layer belongs to, from its section, a version or a layer inside one. */\n getVariations(node: NodeRef): VariationSetHandle | null {\n return getVariationSet(this.figma, node)\n }\n\n /** The sets of variations on the current page. */\n get variations(): VariationSetHandle[] {\n return listVariationSets(this.figma, this.figma.currentPageId)\n }\n\n /**\n * Expose a swap on instances as one INSTANCE_SWAP property, offering the candidate components;\n * returns the layer that holds the property.\n */\n exposeInstanceSwap(\n instances: readonly NodeRef[],\n candidates: readonly NodeRef[],\n propertyName = 'Instance'\n ): FigmaNodeProxy {\n const proxies = (refs: readonly NodeRef[]) =>\n refs.map((ref) => this.figma.wrapNode(nodeOf(this.figma.graph, ref).id))\n const host = exposeInstanceSwap(\n this.figma.graph,\n proxies(instances),\n proxies(candidates),\n propertyName\n )\n return this.figma.wrapNode(host.id)\n }\n\n /**\n * Whether the current page's fonts are faithfully available: requested faces, where each\n * loaded from, substitutions, why an installed face could not load, and the layers affected.\n */\n getFontStatus(): FontReadiness {\n return readFontReadiness(this.figma.graph, this.figma.currentPageId)\n }\n\n /** A fill's OkHCL color, which the color picker keeps beside its RGB, or null. */\n getFillOkHCL(node: NodeRef, index = 0): OkHCLPayload | null {\n return readFillOkHCL(this.figma.graph, node, index)\n }\n\n /** Set a fill's color in OkHCL; its RGB follows in the document's color space. */\n setFillOkHCL(node: NodeRef, color: OkHCLColor, index = 0): void {\n writeFillOkHCL(this.figma.graph, node, color, index)\n }\n\n getStrokeOkHCL(node: NodeRef, index = 0): OkHCLPayload | null {\n return readStrokeOkHCL(this.figma.graph, node, index)\n }\n\n setStrokeOkHCL(node: NodeRef, color: OkHCLColor, index = 0): void {\n writeStrokeOkHCL(this.figma.graph, node, color, index)\n }\n\n /** Which way a frame's auto layout runs: `AUTO`, `LTR` or `RTL`. */\n getLayoutDirection(node: NodeRef): string {\n return readLayoutDirection(this.figma.graph, node)\n }\n\n setLayoutDirection(node: NodeRef, direction: string): void {\n writeLayoutDirection(this.figma.graph, node, direction)\n }\n\n /** Which way a text runs: `AUTO`, `LTR` or `RTL`. */\n getTextDirection(node: NodeRef): string {\n return readTextDirection(this.figma.graph, node)\n }\n\n setTextDirection(node: NodeRef, direction: string): void {\n writeTextDirection(this.figma.graph, node, direction)\n }\n\n /** Merges OpenType feature toggles into the text's own, keeping the tags it does not name. */\n setFontFeatures(node: NodeRef, features: Record<string, boolean>): void {\n writeFontFeatures(this.figma.graph, node, features)\n }\n\n /** Merges OpenType feature toggles into a text range's own, keeping its other features. */\n setRangeFontFeatures(\n node: NodeRef,\n start: number,\n end: number,\n features: Record<string, boolean>\n ): void {\n writeRangeFontFeatures(this.figma.graph, node, start, end, features)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2EA,IAAa,cAAb,MAAyB;CACM;CAA7B,YAAY,OAAkC;EAAjB,KAAA,QAAA;CAAkB;;;;;;;;CAS/C,mBACE,gBACA,cACA,QACA,UACiB;EACjB,MAAM,QAAQ,KAAK,MAAM;EACzB,MAAM,cAAc,MAAM,mBAAmB,CAAC,CAAC,QAAQ,SAAS,KAAK,SAAS,cAAc;EAC5F,MAAM,aAAa,YAAY,GAAG,CAA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AK,MAAM,aAAa;CACrE;;CAGA,aAAa,MAAe,QAAQ,GAAwB;EAC1D,OAAO,cAAc,KAAK,MAAM,OAAO,MAAM,KAAK;CACpD;;CAGA,aAAa,MAAe,OAAmB,QAAQ,GAAS;EAC9D,eAAe,KAAK,MAAM,OAAO,MAAM,OAAO,KAAK;CACrD;CAEA,eAAe,MAAe,QAAQ,GAAwB;EAC5D,OAAO,gBAAgB,KAAK,MAAM,OAAO,MAAM,KAAK;CACtD;CAEA,eAAe,MAAe,OAAmB,QAAQ,GAAS;EAChE,iBAAiB,KAAK,MAAM,OAAO,MAAM,OAAO,KAAK;CACvD;;CAGA,mBAAmB,MAAuB;EACxC,OAAO,oBAAoB,KAAK,MAAM,OAAO,IAAI;CACnD;CAEA,mBAAmB,MAAe,WAAyB;EACzD,qBAAqB,KAAK,MAAM,OAAO,MAAM,SAAS;CACxD;;CAGA,iBAAiB,MAAuB;EACtC,OAAO,kBAAkB,KAAK,MAAM,OAAO,IAAI;CACjD;CAEA,iBAAiB,MAAe,WAAyB;EACvD,mBAAmB,KAAK,MAAM,OAAO,MAAM,SAAS;CACtD;;CAGA,gBAAgB,MAAe,UAAyC;EACtE,kBAAkB,KAAK,MAAM,OAAO,MAAM,QAAQ;CACpD;;CAGA,qBACE,MACA,OACA,KACA,UACM;EACN,uBAAuB,KAAK,MAAM,OAAO,MAAM,OAAO,KAAK,QAAQ;CACrE;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeRef } from "./behaviours.js";
|
|
2
|
-
import { LayoutDirection, SceneGraph, TextDirection } from "@pairdraw/scene-graph";
|
|
3
2
|
import { OkHCLColor, OkHCLPayload } from "@pairdraw/scene-graph/color";
|
|
3
|
+
import { LayoutDirection, SceneGraph, TextDirection } from "@pairdraw/scene-graph";
|
|
4
4
|
//#region src/pairdraw-api/nodes.d.ts
|
|
5
5
|
declare function readFillOkHCL(graph: SceneGraph, ref: NodeRef, index: number): OkHCLPayload | null;
|
|
6
6
|
declare function writeFillOkHCL(graph: SceneGraph, ref: NodeRef, color: OkHCLColor, index: number): void;
|
package/dist/prototype/scene.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { extractPageContext, findPageId } from "../io/subgraph.js";
|
|
2
2
|
import { computeAllLayouts, computeLayout } from "../layout.js";
|
|
3
|
-
import { withoutInheritedCopies } from "./reactions.js";
|
|
4
3
|
import { reflow } from "../editor/play/states.js";
|
|
4
|
+
import { withoutInheritedCopies } from "./reactions.js";
|
|
5
5
|
import { instanceMainComponent } from "@pairdraw/scene-graph/instances";
|
|
6
6
|
import { variantInstanceFor } from "@pairdraw/scene-graph/components";
|
|
7
7
|
//#region src/prototype/scene.ts
|