@pairdraw/scene-graph 0.0.0-stage → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +4 -2
- package/dist/agent-notes/index.d.ts +3 -0
- package/dist/agent-notes/index.js +3 -0
- package/dist/agent-notes/model.d.ts +23 -0
- package/dist/agent-notes/model.d.ts.map +1 -0
- package/dist/agent-notes/model.js +36 -0
- package/dist/agent-notes/model.js.map +1 -0
- package/dist/agent-notes/schema.d.ts +19 -0
- package/dist/agent-notes/schema.d.ts.map +1 -0
- package/dist/agent-notes/schema.js +17 -0
- package/dist/agent-notes/schema.js.map +1 -0
- package/dist/arrow-caps.d.ts +65 -0
- package/dist/arrow-caps.d.ts.map +1 -0
- package/dist/arrow-caps.js +365 -0
- package/dist/arrow-caps.js.map +1 -0
- package/dist/asset-keys.d.ts +17 -0
- package/dist/asset-keys.d.ts.map +1 -0
- package/dist/asset-keys.js +27 -0
- package/dist/asset-keys.js.map +1 -0
- package/dist/behaviours/index.d.ts +6 -0
- package/dist/behaviours/index.js +6 -0
- package/dist/behaviours/kinds.d.ts +56 -0
- package/dist/behaviours/kinds.d.ts.map +1 -0
- package/dist/behaviours/kinds.js +273 -0
- package/dist/behaviours/kinds.js.map +1 -0
- package/dist/behaviours/layers.d.ts +16 -0
- package/dist/behaviours/layers.d.ts.map +1 -0
- package/dist/behaviours/layers.js +42 -0
- package/dist/behaviours/layers.js.map +1 -0
- package/dist/behaviours/model.d.ts +45 -0
- package/dist/behaviours/model.d.ts.map +1 -0
- package/dist/behaviours/model.js +149 -0
- package/dist/behaviours/model.js.map +1 -0
- package/dist/behaviours/schema.d.ts +114 -0
- package/dist/behaviours/schema.d.ts.map +1 -0
- package/dist/behaviours/schema.js +71 -0
- package/dist/behaviours/schema.js.map +1 -0
- package/dist/behaviours/spec.d.ts +26 -0
- package/dist/behaviours/spec.d.ts.map +1 -0
- package/dist/behaviours/spec.js +157 -0
- package/dist/behaviours/spec.js.map +1 -0
- package/dist/bindings.js +18 -0
- package/dist/bindings.js.map +1 -0
- package/dist/browser-node/index.d.ts +3 -0
- package/dist/browser-node/index.js +3 -0
- package/dist/browser-node/model.d.ts +18 -0
- package/dist/browser-node/model.d.ts.map +1 -0
- package/dist/browser-node/model.js +31 -0
- package/dist/browser-node/model.js.map +1 -0
- package/dist/browser-node/schema.d.ts +23 -0
- package/dist/browser-node/schema.d.ts.map +1 -0
- package/dist/browser-node/schema.js +44 -0
- package/dist/browser-node/schema.js.map +1 -0
- package/dist/buffered-events.d.ts +21 -0
- package/dist/buffered-events.d.ts.map +1 -0
- package/dist/buffered-events.js +57 -0
- package/dist/buffered-events.js.map +1 -0
- package/dist/checkpoint.d.ts +28 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +246 -0
- package/dist/checkpoint.js.map +1 -0
- package/dist/clipping.d.ts +31 -0
- package/dist/clipping.d.ts.map +1 -0
- package/dist/clipping.js +125 -0
- package/dist/clipping.js.map +1 -0
- package/dist/color/contrast.d.ts +20 -0
- package/dist/color/contrast.d.ts.map +1 -0
- package/dist/color/contrast.js +69 -0
- package/dist/color/contrast.js.map +1 -0
- package/dist/color/index.d.ts +38 -0
- package/dist/color/index.d.ts.map +1 -0
- package/dist/color/index.js +110 -0
- package/dist/color/index.js.map +1 -0
- package/dist/color/management.d.ts +32 -0
- package/dist/color/management.d.ts.map +1 -0
- package/dist/color/management.js +187 -0
- package/dist/color/management.js.map +1 -0
- package/dist/color/normalize.d.ts +6 -0
- package/dist/color/normalize.d.ts.map +1 -0
- package/dist/color/normalize.js +15 -0
- package/dist/color/normalize.js.map +1 -0
- package/dist/color/okhcl.d.ts +33 -0
- package/dist/color/okhcl.d.ts.map +1 -0
- package/dist/color/okhcl.js +146 -0
- package/dist/color/okhcl.js.map +1 -0
- package/dist/color/schema.d.ts +11 -0
- package/dist/color/schema.d.ts.map +1 -0
- package/dist/color/schema.js +13 -0
- package/dist/color/schema.js.map +1 -0
- package/dist/comments/document.d.ts +23 -0
- package/dist/comments/document.d.ts.map +1 -0
- package/dist/comments/document.js +33 -0
- package/dist/comments/document.js.map +1 -0
- package/dist/comments/index.d.ts +6 -0
- package/dist/comments/index.js +6 -0
- package/dist/comments/list.d.ts +25 -0
- package/dist/comments/list.d.ts.map +1 -0
- package/dist/comments/list.js +33 -0
- package/dist/comments/list.js.map +1 -0
- package/dist/comments/merge.d.ts +16 -0
- package/dist/comments/merge.d.ts.map +1 -0
- package/dist/comments/merge.js +58 -0
- package/dist/comments/merge.js.map +1 -0
- package/dist/comments/schema.d.ts +8 -0
- package/dist/comments/schema.d.ts.map +1 -0
- package/dist/comments/schema.js +50 -0
- package/dist/comments/schema.js.map +1 -0
- package/dist/comments/threads.d.ts +59 -0
- package/dist/comments/threads.d.ts.map +1 -0
- package/dist/comments/threads.js +132 -0
- package/dist/comments/threads.js.map +1 -0
- package/dist/components/exposure.d.ts +24 -0
- package/dist/components/exposure.d.ts.map +1 -0
- package/dist/components/exposure.js +51 -0
- package/dist/components/exposure.js.map +1 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +5 -0
- package/dist/components/library-page.d.ts +11 -0
- package/dist/components/library-page.d.ts.map +1 -0
- package/dist/components/library-page.js +21 -0
- package/dist/components/library-page.js.map +1 -0
- package/dist/components/properties.d.ts +20 -0
- package/dist/components/properties.d.ts.map +1 -0
- package/dist/components/properties.js +125 -0
- package/dist/components/properties.js.map +1 -0
- package/dist/components/variants.d.ts +27 -0
- package/dist/components/variants.d.ts.map +1 -0
- package/dist/components/variants.js +32 -0
- package/dist/components/variants.js.map +1 -0
- package/dist/connectors/controls.d.ts +34 -0
- package/dist/connectors/controls.d.ts.map +1 -0
- package/dist/connectors/controls.js +196 -0
- package/dist/connectors/controls.js.map +1 -0
- package/dist/connectors/create.d.ts +23 -0
- package/dist/connectors/create.d.ts.map +1 -0
- package/dist/connectors/create.js +33 -0
- package/dist/connectors/create.js.map +1 -0
- package/dist/connectors/elbow.js +191 -0
- package/dist/connectors/elbow.js.map +1 -0
- package/dist/connectors/gaps.d.ts +10 -0
- package/dist/connectors/gaps.d.ts.map +1 -0
- package/dist/connectors/gaps.js +86 -0
- package/dist/connectors/gaps.js.map +1 -0
- package/dist/connectors/hit.d.ts +11 -0
- package/dist/connectors/hit.d.ts.map +1 -0
- package/dist/connectors/hit.js +53 -0
- package/dist/connectors/hit.js.map +1 -0
- package/dist/connectors/index.d.ts +11 -0
- package/dist/connectors/index.js +11 -0
- package/dist/connectors/label.d.ts +32 -0
- package/dist/connectors/label.d.ts.map +1 -0
- package/dist/connectors/label.js +213 -0
- package/dist/connectors/label.js.map +1 -0
- package/dist/connectors/layout.d.ts +46 -0
- package/dist/connectors/layout.d.ts.map +1 -0
- package/dist/connectors/layout.js +234 -0
- package/dist/connectors/layout.js.map +1 -0
- package/dist/connectors/pieces.d.ts +22 -0
- package/dist/connectors/pieces.d.ts.map +1 -0
- package/dist/connectors/pieces.js +159 -0
- package/dist/connectors/pieces.js.map +1 -0
- package/dist/connectors/route.d.ts +23 -0
- package/dist/connectors/route.d.ts.map +1 -0
- package/dist/connectors/route.js +107 -0
- package/dist/connectors/route.js.map +1 -0
- package/dist/connectors/sides.d.ts +23 -0
- package/dist/connectors/sides.d.ts.map +1 -0
- package/dist/connectors/sides.js +98 -0
- package/dist/connectors/sides.js.map +1 -0
- package/dist/connectors/sublayers.d.ts +76 -0
- package/dist/connectors/sublayers.d.ts.map +1 -0
- package/dist/connectors/sublayers.js +209 -0
- package/dist/connectors/sublayers.js.map +1 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +31 -0
- package/dist/constants.js.map +1 -0
- package/dist/coordinate.d.ts +99 -0
- package/dist/coordinate.d.ts.map +1 -0
- package/dist/coordinate.js +276 -0
- package/dist/coordinate.js.map +1 -0
- package/dist/copy.d.ts +45 -0
- package/dist/copy.d.ts.map +1 -0
- package/dist/copy.js +256 -0
- package/dist/copy.js.map +1 -0
- package/dist/css/grid.d.ts +7 -0
- package/dist/css/grid.d.ts.map +1 -0
- package/dist/css/grid.js +63 -0
- package/dist/css/grid.js.map +1 -0
- package/dist/css/index.d.ts +6 -0
- package/dist/css/index.js +6 -0
- package/dist/css/layout.d.ts +17 -0
- package/dist/css/layout.d.ts.map +1 -0
- package/dist/css/layout.js +45 -0
- package/dist/css/layout.js.map +1 -0
- package/dist/css/shadows.d.ts +10 -0
- package/dist/css/shadows.d.ts.map +1 -0
- package/dist/css/shadows.js +64 -0
- package/dist/css/shadows.js.map +1 -0
- package/dist/css/text.d.ts +22 -0
- package/dist/css/text.d.ts.map +1 -0
- package/dist/css/text.js +76 -0
- package/dist/css/text.js.map +1 -0
- package/dist/css/values.d.ts +14 -0
- package/dist/css/values.d.ts.map +1 -0
- package/dist/css/values.js +36 -0
- package/dist/css/values.js.map +1 -0
- package/dist/events.js +18 -0
- package/dist/events.js.map +1 -0
- package/dist/export-format.d.ts +19 -0
- package/dist/export-format.d.ts.map +1 -0
- package/dist/export-format.js +33 -0
- package/dist/export-format.js.map +1 -0
- package/dist/export-scale.d.ts +14 -0
- package/dist/export-scale.d.ts.map +1 -0
- package/dist/export-scale.js +19 -0
- package/dist/export-scale.js.map +1 -0
- package/dist/fields/appearance.d.ts +9 -0
- package/dist/fields/appearance.d.ts.map +1 -0
- package/dist/fields/appearance.js +36 -0
- package/dist/fields/appearance.js.map +1 -0
- package/dist/fields/geometry.d.ts +7 -0
- package/dist/fields/geometry.d.ts.map +1 -0
- package/dist/fields/geometry.js +14 -0
- package/dist/fields/geometry.js.map +1 -0
- package/dist/fields/index.d.ts +5 -0
- package/dist/fields/index.js +5 -0
- package/dist/fields/layout.d.ts +10 -0
- package/dist/fields/layout.d.ts.map +1 -0
- package/dist/fields/layout.js +49 -0
- package/dist/fields/layout.js.map +1 -0
- package/dist/fields/text.d.ts +11 -0
- package/dist/fields/text.d.ts.map +1 -0
- package/dist/fields/text.js +63 -0
- package/dist/fields/text.js.map +1 -0
- package/dist/fig-compression.d.ts +11 -0
- package/dist/fig-compression.d.ts.map +1 -0
- package/dist/fig-compression.js +15 -0
- package/dist/fig-compression.js.map +1 -0
- package/dist/figjam/index.d.ts +3 -0
- package/dist/figjam/index.js +3 -0
- package/dist/figjam/palette.d.ts +199 -0
- package/dist/figjam/palette.d.ts.map +1 -0
- package/dist/figjam/palette.js +277 -0
- package/dist/figjam/palette.js.map +1 -0
- package/dist/figjam/text.d.ts +68 -0
- package/dist/figjam/text.d.ts.map +1 -0
- package/dist/figjam/text.js +89 -0
- package/dist/figjam/text.js.map +1 -0
- package/dist/font-style.d.ts +46 -0
- package/dist/font-style.d.ts.map +1 -0
- package/dist/font-style.js +127 -0
- package/dist/font-style.js.map +1 -0
- package/dist/generated/index.d.ts +46 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +62 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/kind.d.ts +29 -0
- package/dist/generated/kind.d.ts.map +1 -0
- package/dist/generated/shape-with-text.d.ts +38 -0
- package/dist/generated/shape-with-text.d.ts.map +1 -0
- package/dist/generated/shape-with-text.js +119 -0
- package/dist/generated/shape-with-text.js.map +1 -0
- package/dist/generated/sticky.d.ts +128 -0
- package/dist/generated/sticky.d.ts.map +1 -0
- package/dist/generated/sticky.js +234 -0
- package/dist/generated/sticky.js.map +1 -0
- package/dist/geometry.d.ts +105 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +374 -0
- package/dist/geometry.js.map +1 -0
- package/dist/gradient.d.ts +74 -0
- package/dist/gradient.d.ts.map +1 -0
- package/dist/gradient.js +211 -0
- package/dist/gradient.js.map +1 -0
- package/dist/graph.d.ts +186 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +630 -0
- package/dist/graph.js.map +1 -0
- package/dist/group-bounds.d.ts +42 -0
- package/dist/group-bounds.d.ts.map +1 -0
- package/dist/group-bounds.js +146 -0
- package/dist/group-bounds.js.map +1 -0
- package/dist/guides.d.ts +19 -0
- package/dist/guides.d.ts.map +1 -0
- package/dist/guides.js +39 -0
- package/dist/guides.js.map +1 -0
- package/dist/hit-test.d.ts +49 -0
- package/dist/hit-test.d.ts.map +1 -0
- package/dist/hit-test.js +315 -0
- package/dist/hit-test.js.map +1 -0
- package/dist/icons/glyph.d.ts +22 -0
- package/dist/icons/glyph.d.ts.map +1 -0
- package/dist/icons/glyph.js +109 -0
- package/dist/icons/glyph.js.map +1 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.js +4 -0
- package/dist/icons/model.d.ts +29 -0
- package/dist/icons/model.d.ts.map +1 -0
- package/dist/icons/model.js +51 -0
- package/dist/icons/model.js.map +1 -0
- package/dist/icons/schema.d.ts +31 -0
- package/dist/icons/schema.d.ts.map +1 -0
- package/dist/icons/schema.js +28 -0
- package/dist/icons/schema.js.map +1 -0
- package/dist/ids.d.ts +12 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +31 -0
- package/dist/ids.js.map +1 -0
- package/dist/images.d.ts +39 -0
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +85 -0
- package/dist/images.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/instances/assignments.js +89 -0
- package/dist/instances/assignments.js.map +1 -0
- package/dist/instances/content-size.js +60 -0
- package/dist/instances/content-size.js.map +1 -0
- package/dist/instances/copies.js +162 -0
- package/dist/instances/copies.js.map +1 -0
- package/dist/instances/cycles.d.ts +20 -0
- package/dist/instances/cycles.d.ts.map +1 -0
- package/dist/instances/cycles.js +53 -0
- package/dist/instances/cycles.js.map +1 -0
- package/dist/instances/fields.d.ts +18 -0
- package/dist/instances/fields.d.ts.map +1 -0
- package/dist/instances/fields.js +82 -0
- package/dist/instances/fields.js.map +1 -0
- package/dist/instances/index.d.ts +63 -0
- package/dist/instances/index.d.ts.map +1 -0
- package/dist/instances/index.js +305 -0
- package/dist/instances/index.js.map +1 -0
- package/dist/instances/main-component.d.ts +11 -0
- package/dist/instances/main-component.d.ts.map +1 -0
- package/dist/instances/main-component.js +42 -0
- package/dist/instances/main-component.js.map +1 -0
- package/dist/instances/modes.js +26 -0
- package/dist/instances/modes.js.map +1 -0
- package/dist/instances/overrides.d.ts +63 -0
- package/dist/instances/overrides.d.ts.map +1 -0
- package/dist/instances/overrides.js +164 -0
- package/dist/instances/overrides.js.map +1 -0
- package/dist/instances/placement.js +30 -0
- package/dist/instances/placement.js.map +1 -0
- package/dist/instances/replacements.d.ts +19 -0
- package/dist/instances/replacements.d.ts.map +1 -0
- package/dist/instances/replacements.js +67 -0
- package/dist/instances/replacements.js.map +1 -0
- package/dist/instances/source-walk.js +31 -0
- package/dist/instances/source-walk.js.map +1 -0
- package/dist/instances/sync.js +305 -0
- package/dist/instances/sync.js.map +1 -0
- package/dist/instances/vector-geometry.js +70 -0
- package/dist/instances/vector-geometry.js.map +1 -0
- package/dist/layout/aspect-ratio.d.ts +27 -0
- package/dist/layout/aspect-ratio.d.ts.map +1 -0
- package/dist/layout/aspect-ratio.js +45 -0
- package/dist/layout/aspect-ratio.js.map +1 -0
- package/dist/layout/guides.d.ts +25 -0
- package/dist/layout/guides.d.ts.map +1 -0
- package/dist/layout/guides.js +105 -0
- package/dist/layout/guides.js.map +1 -0
- package/dist/layout/index.d.ts +5 -0
- package/dist/layout/index.js +5 -0
- package/dist/layout/keywords.d.ts +26 -0
- package/dist/layout/keywords.d.ts.map +1 -0
- package/dist/layout/keywords.js +60 -0
- package/dist/layout/keywords.js.map +1 -0
- package/dist/layout/sizing.d.ts +40 -0
- package/dist/layout/sizing.d.ts.map +1 -0
- package/dist/layout/sizing.js +122 -0
- package/dist/layout/sizing.js.map +1 -0
- package/dist/layout/writes.js +55 -0
- package/dist/layout/writes.js.map +1 -0
- package/dist/matrix.d.ts +16 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +120 -0
- package/dist/matrix.js.map +1 -0
- package/dist/mutation-impact.d.ts +23 -0
- package/dist/mutation-impact.d.ts.map +1 -0
- package/dist/mutation-impact.js +67 -0
- package/dist/mutation-impact.js.map +1 -0
- package/dist/naming.d.ts +9 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/naming.js +16 -0
- package/dist/naming.js.map +1 -0
- package/dist/node-defaults.d.ts +19 -0
- package/dist/node-defaults.d.ts.map +1 -0
- package/dist/node-defaults.js +243 -0
- package/dist/node-defaults.js.map +1 -0
- package/dist/order-keys.d.ts +39 -0
- package/dist/order-keys.d.ts.map +1 -0
- package/dist/order-keys.js +136 -0
- package/dist/order-keys.js.map +1 -0
- package/dist/paints/index.d.ts +2 -0
- package/dist/paints/index.js +2 -0
- package/dist/paints/schema.d.ts +103 -0
- package/dist/paints/schema.d.ts.map +1 -0
- package/dist/paints/schema.js +64 -0
- package/dist/paints/schema.js.map +1 -0
- package/dist/parse-path.d.ts +36 -0
- package/dist/parse-path.d.ts.map +1 -0
- package/dist/parse-path.js +200 -0
- package/dist/parse-path.js.map +1 -0
- package/dist/plugin-data/citation.d.ts +13 -0
- package/dist/plugin-data/citation.d.ts.map +1 -0
- package/dist/plugin-data/citation.js +23 -0
- package/dist/plugin-data/citation.js.map +1 -0
- package/dist/plugin-data/field.d.ts +47 -0
- package/dist/plugin-data/field.d.ts.map +1 -0
- package/dist/plugin-data/field.js +79 -0
- package/dist/plugin-data/field.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +220 -0
- package/dist/plugin-data/fields.d.ts.map +1 -0
- package/dist/plugin-data/fields.js +214 -0
- package/dist/plugin-data/fields.js.map +1 -0
- package/dist/plugin-data/index.d.ts +5 -0
- package/dist/plugin-data/index.js +5 -0
- package/dist/plugin-data/schema.d.ts +18 -0
- package/dist/plugin-data/schema.d.ts.map +1 -0
- package/dist/plugin-data/schema.js +29 -0
- package/dist/plugin-data/schema.js.map +1 -0
- package/dist/polygon.d.ts +55 -0
- package/dist/polygon.d.ts.map +1 -0
- package/dist/polygon.js +220 -0
- package/dist/polygon.js.map +1 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +63 -0
- package/dist/preview.js.map +1 -0
- package/dist/primitives/index.d.ts +43 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +2 -0
- package/dist/primitives/schema.d.ts +18 -0
- package/dist/primitives/schema.d.ts.map +1 -0
- package/dist/primitives/schema.js +19 -0
- package/dist/primitives/schema.js.map +1 -0
- package/dist/random.d.ts +7 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +25 -0
- package/dist/random.js.map +1 -0
- package/dist/resize.d.ts +41 -0
- package/dist/resize.d.ts.map +1 -0
- package/dist/resize.js +288 -0
- package/dist/resize.js.map +1 -0
- package/dist/scaling/index.d.ts +3 -0
- package/dist/scaling/index.js +3 -0
- package/dist/scaling/node.d.ts +6 -0
- package/dist/scaling/node.d.ts.map +1 -0
- package/dist/scaling/node.js +150 -0
- package/dist/scaling/node.js.map +1 -0
- package/dist/scaling/tree.d.ts +22 -0
- package/dist/scaling/tree.d.ts.map +1 -0
- package/dist/scaling/tree.js +71 -0
- package/dist/scaling/tree.js.map +1 -0
- package/dist/script/index.d.ts +2 -0
- package/dist/script/index.js +2 -0
- package/dist/script/schema.d.ts +29 -0
- package/dist/script/schema.d.ts.map +1 -0
- package/dist/script/schema.js +51 -0
- package/dist/script/schema.js.map +1 -0
- package/dist/shaders/directives.d.ts +43 -0
- package/dist/shaders/directives.d.ts.map +1 -0
- package/dist/shaders/directives.js +293 -0
- package/dist/shaders/directives.js.map +1 -0
- package/dist/shaders/index.d.ts +5 -0
- package/dist/shaders/index.js +5 -0
- package/dist/shaders/model.d.ts +58 -0
- package/dist/shaders/model.d.ts.map +1 -0
- package/dist/shaders/model.js +109 -0
- package/dist/shaders/model.js.map +1 -0
- package/dist/shaders/schema.d.ts +86 -0
- package/dist/shaders/schema.d.ts.map +1 -0
- package/dist/shaders/schema.js +65 -0
- package/dist/shaders/schema.js.map +1 -0
- package/dist/shaders/still.d.ts +18 -0
- package/dist/shaders/still.d.ts.map +1 -0
- package/dist/shaders/still.js +36 -0
- package/dist/shaders/still.js.map +1 -0
- package/dist/shape-with-text/fit.d.ts +28 -0
- package/dist/shape-with-text/fit.d.ts.map +1 -0
- package/dist/shape-with-text/fit.js +271 -0
- package/dist/shape-with-text/fit.js.map +1 -0
- package/dist/shape-with-text/geometry.d.ts +20 -0
- package/dist/shape-with-text/geometry.d.ts.map +1 -0
- package/dist/shape-with-text/geometry.js +539 -0
- package/dist/shape-with-text/geometry.js.map +1 -0
- package/dist/shape-with-text/index.d.ts +4 -0
- package/dist/shape-with-text/index.js +4 -0
- package/dist/shape-with-text/kinds.d.ts +20 -0
- package/dist/shape-with-text/kinds.d.ts.map +1 -0
- package/dist/shape-with-text/kinds.js +86 -0
- package/dist/shape-with-text/kinds.js.map +1 -0
- package/dist/shared-styles.d.ts +36 -0
- package/dist/shared-styles.d.ts.map +1 -0
- package/dist/shared-styles.js +116 -0
- package/dist/shared-styles.js.map +1 -0
- package/dist/slots/authoring.d.ts +27 -0
- package/dist/slots/authoring.d.ts.map +1 -0
- package/dist/slots/authoring.js +74 -0
- package/dist/slots/authoring.js.map +1 -0
- package/dist/slots/content.d.ts +41 -0
- package/dist/slots/content.d.ts.map +1 -0
- package/dist/slots/content.js +103 -0
- package/dist/slots/content.js.map +1 -0
- package/dist/slots/frames.d.ts +38 -0
- package/dist/slots/frames.d.ts.map +1 -0
- package/dist/slots/frames.js +113 -0
- package/dist/slots/frames.js.map +1 -0
- package/dist/slots/index.d.ts +5 -0
- package/dist/slots/index.js +5 -0
- package/dist/slots/limits.d.ts +14 -0
- package/dist/slots/limits.d.ts.map +1 -0
- package/dist/slots/limits.js +28 -0
- package/dist/slots/limits.js.map +1 -0
- package/dist/snap.d.ts +61 -0
- package/dist/snap.d.ts.map +1 -0
- package/dist/snap.js +264 -0
- package/dist/snap.js.map +1 -0
- package/dist/source-metadata.d.ts +6 -0
- package/dist/source-metadata.d.ts.map +1 -0
- package/dist/source-metadata.js +11 -0
- package/dist/source-metadata.js.map +1 -0
- package/dist/statuses/impact.d.ts +18 -0
- package/dist/statuses/impact.d.ts.map +1 -0
- package/dist/statuses/impact.js +33 -0
- package/dist/statuses/impact.js.map +1 -0
- package/dist/statuses/index.d.ts +5 -0
- package/dist/statuses/index.js +5 -0
- package/dist/statuses/node.d.ts +22 -0
- package/dist/statuses/node.d.ts.map +1 -0
- package/dist/statuses/node.js +47 -0
- package/dist/statuses/node.js.map +1 -0
- package/dist/statuses/schema.d.ts +59 -0
- package/dist/statuses/schema.d.ts.map +1 -0
- package/dist/statuses/schema.js +27 -0
- package/dist/statuses/schema.js.map +1 -0
- package/dist/statuses/workflow.d.ts +120 -0
- package/dist/statuses/workflow.d.ts.map +1 -0
- package/dist/statuses/workflow.js +135 -0
- package/dist/statuses/workflow.js.map +1 -0
- package/dist/text/direction.d.ts +13 -0
- package/dist/text/direction.d.ts.map +1 -0
- package/dist/text/direction.js +31 -0
- package/dist/text/direction.js.map +1 -0
- package/dist/text/index.d.ts +7 -0
- package/dist/text/index.js +7 -0
- package/dist/text/lengths.d.ts +19 -0
- package/dist/text/lengths.d.ts.map +1 -0
- package/dist/text/lengths.js +40 -0
- package/dist/text/lengths.js.map +1 -0
- package/dist/text/lists.d.ts +44 -0
- package/dist/text/lists.d.ts.map +1 -0
- package/dist/text/lists.js +100 -0
- package/dist/text/lists.js.map +1 -0
- package/dist/text/overflow.d.ts +11 -0
- package/dist/text/overflow.d.ts.map +1 -0
- package/dist/text/overflow.js +13 -0
- package/dist/text/overflow.js.map +1 -0
- package/dist/text/paragraphs.d.ts +62 -0
- package/dist/text/paragraphs.d.ts.map +1 -0
- package/dist/text/paragraphs.js +166 -0
- package/dist/text/paragraphs.js.map +1 -0
- package/dist/text/picture.d.ts +18 -0
- package/dist/text/picture.d.ts.map +1 -0
- package/dist/text/picture.js +41 -0
- package/dist/text/picture.js.map +1 -0
- package/dist/text/references.d.ts +21 -0
- package/dist/text/references.d.ts.map +1 -0
- package/dist/text/references.js +43 -0
- package/dist/text/references.js.map +1 -0
- package/dist/text/schema.d.ts +10 -0
- package/dist/text/schema.d.ts.map +1 -0
- package/dist/text/schema.js +11 -0
- package/dist/text/schema.js.map +1 -0
- package/dist/transfer/apply.d.ts +9 -0
- package/dist/transfer/apply.d.ts.map +1 -0
- package/dist/transfer/apply.js +65 -0
- package/dist/transfer/apply.js.map +1 -0
- package/dist/transfer/history.d.ts +8 -0
- package/dist/transfer/history.d.ts.map +1 -0
- package/dist/transfer/history.js +32 -0
- package/dist/transfer/history.js.map +1 -0
- package/dist/transfer/identity.js +12 -0
- package/dist/transfer/identity.js.map +1 -0
- package/dist/transfer/index.d.ts +7 -0
- package/dist/transfer/index.js +7 -0
- package/dist/transfer/nodes.d.ts +14 -0
- package/dist/transfer/nodes.d.ts.map +1 -0
- package/dist/transfer/nodes.js +82 -0
- package/dist/transfer/nodes.js.map +1 -0
- package/dist/transfer/plan.d.ts +29 -0
- package/dist/transfer/plan.d.ts.map +1 -0
- package/dist/transfer/plan.js +106 -0
- package/dist/transfer/plan.js.map +1 -0
- package/dist/transfer/references.js +10 -0
- package/dist/transfer/references.js.map +1 -0
- package/dist/transfer/remove.d.ts +8 -0
- package/dist/transfer/remove.d.ts.map +1 -0
- package/dist/transfer/remove.js +34 -0
- package/dist/transfer/remove.js.map +1 -0
- package/dist/transfer/validation.js +39 -0
- package/dist/transfer/validation.js.map +1 -0
- package/dist/transfer/variables.d.ts +15 -0
- package/dist/transfer/variables.d.ts.map +1 -0
- package/dist/transfer/variables.js +52 -0
- package/dist/transfer/variables.js.map +1 -0
- package/dist/types.d.ts +910 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +89 -0
- package/dist/types.js.map +1 -0
- package/dist/undo.d.ts +93 -0
- package/dist/undo.d.ts.map +1 -0
- package/dist/undo.js +236 -0
- package/dist/undo.js.map +1 -0
- package/dist/variables/bindings.d.ts +66 -0
- package/dist/variables/bindings.d.ts.map +1 -0
- package/dist/variables/bindings.js +251 -0
- package/dist/variables/bindings.js.map +1 -0
- package/dist/variables/corners.d.ts +12 -0
- package/dist/variables/corners.d.ts.map +1 -0
- package/dist/variables/corners.js +38 -0
- package/dist/variables/corners.js.map +1 -0
- package/dist/variables/fields.d.ts +30 -0
- package/dist/variables/fields.d.ts.map +1 -0
- package/dist/variables/fields.js +89 -0
- package/dist/variables/fields.js.map +1 -0
- package/dist/variables/formula/check.d.ts +14 -0
- package/dist/variables/formula/check.d.ts.map +1 -0
- package/dist/variables/formula/check.js +73 -0
- package/dist/variables/formula/check.js.map +1 -0
- package/dist/variables/formula/evaluate.d.ts +7 -0
- package/dist/variables/formula/evaluate.d.ts.map +1 -0
- package/dist/variables/formula/evaluate.js +30 -0
- package/dist/variables/formula/evaluate.js.map +1 -0
- package/dist/variables/formula/index.d.ts +21 -0
- package/dist/variables/formula/index.d.ts.map +1 -0
- package/dist/variables/formula/index.js +77 -0
- package/dist/variables/formula/index.js.map +1 -0
- package/dist/variables/formula/parse.js +141 -0
- package/dist/variables/formula/parse.js.map +1 -0
- package/dist/variables/formula/print.d.ts +25 -0
- package/dist/variables/formula/print.d.ts.map +1 -0
- package/dist/variables/formula/print.js +105 -0
- package/dist/variables/formula/print.js.map +1 -0
- package/dist/variables/formula/schema.d.ts +7 -0
- package/dist/variables/formula/schema.d.ts.map +1 -0
- package/dist/variables/formula/schema.js +62 -0
- package/dist/variables/formula/schema.js.map +1 -0
- package/dist/variables/formula/signatures.d.ts +9 -0
- package/dist/variables/formula/signatures.d.ts.map +1 -0
- package/dist/variables/formula/signatures.js +238 -0
- package/dist/variables/formula/signatures.js.map +1 -0
- package/dist/variables/formula/tokens.d.ts +26 -0
- package/dist/variables/formula/tokens.d.ts.map +1 -0
- package/dist/variables/formula/tokens.js +82 -0
- package/dist/variables/formula/tokens.js.map +1 -0
- package/dist/variables/formula/tree.d.ts +22 -0
- package/dist/variables/formula/tree.d.ts.map +1 -0
- package/dist/variables/formula/tree.js +35 -0
- package/dist/variables/formula/tree.js.map +1 -0
- package/dist/variables/index.d.ts +41 -0
- package/dist/variables/index.d.ts.map +1 -0
- package/dist/variables/index.js +246 -0
- package/dist/variables/index.js.map +1 -0
- package/dist/variables/resolution.d.ts +39 -0
- package/dist/variables/resolution.d.ts.map +1 -0
- package/dist/variables/resolution.js +154 -0
- package/dist/variables/resolution.js.map +1 -0
- package/dist/variables/schema.d.ts +40 -0
- package/dist/variables/schema.d.ts.map +1 -0
- package/dist/variables/schema.js +32 -0
- package/dist/variables/schema.js.map +1 -0
- package/dist/variables/text.d.ts +21 -0
- package/dist/variables/text.d.ts.map +1 -0
- package/dist/variables/text.js +58 -0
- package/dist/variables/text.js.map +1 -0
- package/dist/variables/token.d.ts +18 -0
- package/dist/variables/token.d.ts.map +1 -0
- package/dist/variables/token.js +39 -0
- package/dist/variables/token.js.map +1 -0
- package/dist/variables/units.js +19 -0
- package/dist/variables/units.js.map +1 -0
- package/dist/variables/value.d.ts +12 -0
- package/dist/variables/value.d.ts.map +1 -0
- package/dist/variables/value.js +70 -0
- package/dist/variables/value.js.map +1 -0
- package/dist/variant-name.d.ts +6 -0
- package/dist/variant-name.d.ts.map +1 -0
- package/dist/variant-name.js +17 -0
- package/dist/variant-name.js.map +1 -0
- package/dist/variant-properties.d.ts +18 -0
- package/dist/variant-properties.d.ts.map +1 -0
- package/dist/variant-properties.js +74 -0
- package/dist/variant-properties.js.map +1 -0
- package/dist/vector-network.d.ts +48 -0
- package/dist/vector-network.d.ts.map +1 -0
- package/dist/vector-network.js +352 -0
- package/dist/vector-network.js.map +1 -0
- package/package.json +364 -4
- package/src/agent-notes/index.ts +2 -0
- package/src/agent-notes/model.ts +46 -0
- package/src/agent-notes/schema.ts +28 -0
- package/src/arrow-caps.ts +364 -0
- package/src/asset-keys.ts +25 -0
- package/src/behaviours/index.ts +5 -0
- package/src/behaviours/kinds.ts +185 -0
- package/src/behaviours/layers.ts +51 -0
- package/src/behaviours/model.ts +184 -0
- package/src/behaviours/schema.ts +93 -0
- package/src/behaviours/spec.ts +178 -0
- package/src/bindings.ts +20 -0
- package/src/browser-node/index.ts +2 -0
- package/src/browser-node/model.ts +35 -0
- package/src/browser-node/schema.ts +62 -0
- package/src/buffered-events.ts +64 -0
- package/src/checkpoint.ts +325 -0
- package/src/clipping.ts +112 -0
- package/src/color/contrast.ts +71 -0
- package/src/color/index.ts +89 -0
- package/src/color/management.ts +210 -0
- package/src/color/normalize.ts +7 -0
- package/src/color/okhcl.ts +201 -0
- package/src/color/schema.ts +10 -0
- package/src/comments/document.ts +51 -0
- package/src/comments/index.ts +5 -0
- package/src/comments/list.ts +52 -0
- package/src/comments/merge.ts +63 -0
- package/src/comments/schema.ts +51 -0
- package/src/comments/threads.ts +156 -0
- package/src/components/exposure.ts +61 -0
- package/src/components/index.ts +9 -0
- package/src/components/library-page.ts +17 -0
- package/src/components/properties.ts +241 -0
- package/src/components/variants.ts +53 -0
- package/src/connectors/controls.ts +229 -0
- package/src/connectors/create.ts +48 -0
- package/src/connectors/elbow.ts +235 -0
- package/src/connectors/gaps.ts +72 -0
- package/src/connectors/hit.ts +60 -0
- package/src/connectors/index.ts +28 -0
- package/src/connectors/label.ts +238 -0
- package/src/connectors/layout.ts +280 -0
- package/src/connectors/pieces.ts +144 -0
- package/src/connectors/route.ts +148 -0
- package/src/connectors/sides.ts +94 -0
- package/src/connectors/sublayers.ts +204 -0
- package/src/constants.ts +13 -0
- package/src/coordinate.ts +298 -0
- package/src/copy.ts +341 -0
- package/src/css/grid.ts +70 -0
- package/src/css/index.ts +10 -0
- package/src/css/layout.ts +53 -0
- package/src/css/shadows.ts +68 -0
- package/src/css/text.ts +84 -0
- package/src/css/values.ts +42 -0
- package/src/events.ts +21 -0
- package/src/export-format.ts +33 -0
- package/src/export-scale.ts +16 -0
- package/src/fields/appearance.ts +35 -0
- package/src/fields/geometry.ts +11 -0
- package/src/fields/index.ts +4 -0
- package/src/fields/layout.ts +48 -0
- package/src/fields/text.ts +64 -0
- package/src/fig-compression.ts +9 -0
- package/src/figjam/index.ts +2 -0
- package/src/figjam/palette.ts +308 -0
- package/src/figjam/text.ts +78 -0
- package/src/font-style.ts +121 -0
- package/src/generated/index.ts +81 -0
- package/src/generated/kind.ts +26 -0
- package/src/generated/shape-with-text.ts +132 -0
- package/src/generated/sticky.ts +214 -0
- package/src/geometry.ts +490 -0
- package/src/gradient.ts +275 -0
- package/src/graph.ts +842 -0
- package/src/group-bounds.ts +178 -0
- package/src/guides.ts +47 -0
- package/src/hit-test.ts +501 -0
- package/src/icons/glyph.ts +128 -0
- package/src/icons/index.ts +3 -0
- package/src/icons/model.ts +63 -0
- package/src/icons/schema.ts +34 -0
- package/src/ids.ts +34 -0
- package/src/images.ts +89 -0
- package/src/index.ts +4 -0
- package/src/instances/assignments.ts +116 -0
- package/src/instances/content-size.ts +84 -0
- package/src/instances/copies.ts +244 -0
- package/src/instances/cycles.ts +73 -0
- package/src/instances/fields.ts +90 -0
- package/src/instances/index.ts +467 -0
- package/src/instances/main-component.ts +61 -0
- package/src/instances/modes.ts +39 -0
- package/src/instances/overrides.ts +240 -0
- package/src/instances/placement.ts +29 -0
- package/src/instances/replacements.ts +80 -0
- package/src/instances/source-walk.ts +35 -0
- package/src/instances/sync.ts +556 -0
- package/src/instances/vector-geometry.ts +81 -0
- package/src/layout/aspect-ratio.ts +51 -0
- package/src/layout/guides.ts +132 -0
- package/src/layout/index.ts +4 -0
- package/src/layout/keywords.ts +74 -0
- package/src/layout/sizing.ts +196 -0
- package/src/layout/writes.ts +59 -0
- package/src/matrix.ts +116 -0
- package/src/mutation-impact.ts +85 -0
- package/src/naming.ts +11 -0
- package/src/node-defaults.ts +260 -0
- package/src/order-keys.ts +162 -0
- package/src/paints/index.ts +1 -0
- package/src/paints/schema.ts +72 -0
- package/src/parse-path.ts +244 -0
- package/src/plugin-data/citation.ts +27 -0
- package/src/plugin-data/field.ts +140 -0
- package/src/plugin-data/fields.ts +306 -0
- package/src/plugin-data/index.ts +3 -0
- package/src/plugin-data/schema.ts +35 -0
- package/src/polygon.ts +228 -0
- package/src/preview.ts +80 -0
- package/src/primitives/index.ts +44 -0
- package/src/primitives/schema.ts +14 -0
- package/src/random.ts +28 -0
- package/src/resize.ts +415 -0
- package/src/scaling/index.ts +9 -0
- package/src/scaling/node.ts +168 -0
- package/src/scaling/tree.ts +85 -0
- package/src/script/index.ts +1 -0
- package/src/script/schema.ts +65 -0
- package/src/shaders/directives.ts +366 -0
- package/src/shaders/index.ts +4 -0
- package/src/shaders/model.ts +147 -0
- package/src/shaders/schema.ts +84 -0
- package/src/shaders/still.ts +41 -0
- package/src/shape-with-text/fit.ts +154 -0
- package/src/shape-with-text/geometry.ts +496 -0
- package/src/shape-with-text/index.ts +10 -0
- package/src/shape-with-text/kinds.ts +86 -0
- package/src/shared-styles.ts +137 -0
- package/src/slots/authoring.ts +101 -0
- package/src/slots/content.ts +127 -0
- package/src/slots/frames.ts +160 -0
- package/src/slots/index.ts +4 -0
- package/src/slots/limits.ts +49 -0
- package/src/snap.ts +349 -0
- package/src/source-metadata.ts +8 -0
- package/src/statuses/impact.ts +38 -0
- package/src/statuses/index.ts +4 -0
- package/src/statuses/node.ts +63 -0
- package/src/statuses/schema.ts +39 -0
- package/src/statuses/workflow.ts +121 -0
- package/src/text/direction.ts +55 -0
- package/src/text/index.ts +6 -0
- package/src/text/lengths.ts +34 -0
- package/src/text/lists.ts +138 -0
- package/src/text/overflow.ts +12 -0
- package/src/text/paragraphs.ts +241 -0
- package/src/text/picture.ts +57 -0
- package/src/text/references.ts +50 -0
- package/src/text/schema.ts +7 -0
- package/src/transfer/apply.ts +84 -0
- package/src/transfer/history.ts +49 -0
- package/src/transfer/identity.ts +16 -0
- package/src/transfer/index.ts +6 -0
- package/src/transfer/nodes.ts +128 -0
- package/src/transfer/plan.ts +130 -0
- package/src/transfer/references.ts +9 -0
- package/src/transfer/remove.ts +39 -0
- package/src/transfer/validation.ts +59 -0
- package/src/transfer/variables.ts +83 -0
- package/src/types.ts +1205 -0
- package/src/undo.ts +285 -0
- package/src/variables/bindings.ts +310 -0
- package/src/variables/corners.ts +39 -0
- package/src/variables/fields.ts +109 -0
- package/src/variables/formula/check.ts +99 -0
- package/src/variables/formula/evaluate.ts +33 -0
- package/src/variables/formula/index.ts +129 -0
- package/src/variables/formula/parse.ts +160 -0
- package/src/variables/formula/print.ts +167 -0
- package/src/variables/formula/schema.ts +77 -0
- package/src/variables/formula/signatures.ts +266 -0
- package/src/variables/formula/tokens.ts +114 -0
- package/src/variables/formula/tree.ts +53 -0
- package/src/variables/index.ts +400 -0
- package/src/variables/resolution.ts +293 -0
- package/src/variables/schema.ts +31 -0
- package/src/variables/text.ts +61 -0
- package/src/variables/token.ts +40 -0
- package/src/variables/units.ts +15 -0
- package/src/variables/value.ts +92 -0
- package/src/variant-name.ts +15 -0
- package/src/variant-properties.ts +98 -0
- package/src/vector-network.ts +489 -0
package/dist/hit-test.js
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import Matrix from "./matrix.js";
|
|
2
|
+
import { getAxisAlignedBoundsAt, getNodeLocalMatrix, getWorldMatrix } from "./coordinate.js";
|
|
3
|
+
import { hitsConnectorLine } from "./connectors/hit.js";
|
|
4
|
+
//#region src/hit-test.ts
|
|
5
|
+
const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
6
|
+
"CANVAS",
|
|
7
|
+
"FRAME",
|
|
8
|
+
"GROUP",
|
|
9
|
+
"SECTION",
|
|
10
|
+
"COMPONENT",
|
|
11
|
+
"COMPONENT_SET",
|
|
12
|
+
"INSTANCE"
|
|
13
|
+
]);
|
|
14
|
+
const OPAQUE_CONTAINER_TYPES = /* @__PURE__ */ new Set(["COMPONENT", "INSTANCE"]);
|
|
15
|
+
function hasVisibleFillOrStroke(node) {
|
|
16
|
+
return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible);
|
|
17
|
+
}
|
|
18
|
+
function isTopLevel(graph, node) {
|
|
19
|
+
const parent = node.parentId ? graph.nodes.get(node.parentId) : void 0;
|
|
20
|
+
return parent?.type === "CANVAS" || parent?.type === "SECTION";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* An open container whose empty area still belongs to it, as in Figma: a top-level frame with auto
|
|
24
|
+
* layout is selected, hovered, and dragged by its gaps and padding, while its children stay one
|
|
25
|
+
* click away, with or without a fill. A plain top-level frame's empty area is background, and a
|
|
26
|
+
* nested frame's empty area belongs to it only as a click target (see `frameChildAt`).
|
|
27
|
+
*/
|
|
28
|
+
function ownsItsEmptyArea(graph, node) {
|
|
29
|
+
return node.type === "FRAME" && node.layoutMode !== "NONE" && isTopLevel(graph, node);
|
|
30
|
+
}
|
|
31
|
+
function hasTransformedAncestor(node, graph, cache) {
|
|
32
|
+
const cached = cache.get(node.id);
|
|
33
|
+
if (cached !== void 0) return cached;
|
|
34
|
+
const parent = node.parentId ? graph.getNode(node.parentId) : void 0;
|
|
35
|
+
const transformed = node.rotation !== 0 || node.flipX || node.flipY || (parent ? hasTransformedAncestor(parent, graph, cache) : false);
|
|
36
|
+
cache.set(node.id, transformed);
|
|
37
|
+
return transformed;
|
|
38
|
+
}
|
|
39
|
+
/** Whether the point lies in the node's box, grown by `pad` canvas units on every side. */
|
|
40
|
+
function containsPoint(px, py, node, graph, transformCache, pad = 0) {
|
|
41
|
+
if (!hasTransformedAncestor(node, graph, transformCache)) {
|
|
42
|
+
const absolute = graph.getAbsolutePosition(node.id);
|
|
43
|
+
return px >= absolute.x - pad && px <= absolute.x + node.width + pad && py >= absolute.y - pad && py <= absolute.y + node.height + pad;
|
|
44
|
+
}
|
|
45
|
+
const m = getWorldMatrix(node, graph);
|
|
46
|
+
const inv = Matrix.invert(m);
|
|
47
|
+
if (!inv) return false;
|
|
48
|
+
const [localX, localY] = Matrix.mapPoints(inv, [px, py]);
|
|
49
|
+
return localX >= -pad && localX <= node.width + pad && localY >= -pad && localY <= node.height + pad;
|
|
50
|
+
}
|
|
51
|
+
function hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad) {
|
|
52
|
+
if (!containsPoint(px, py, child, graph, transformCache)) return null;
|
|
53
|
+
if (hitTestChildren(graph, px, py, childId, deep, transformCache, pad)) return child;
|
|
54
|
+
if (hasVisibleFillOrStroke(child)) return child;
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
function hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache, pad) {
|
|
58
|
+
if (child.type === "GROUP") {
|
|
59
|
+
if (!containsPoint(px, py, child, graph, transformCache, pad)) return null;
|
|
60
|
+
const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad);
|
|
61
|
+
if (childHit) return deep ? childHit : child;
|
|
62
|
+
return containsPoint(px, py, child, graph, transformCache) ? child : null;
|
|
63
|
+
}
|
|
64
|
+
const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad);
|
|
65
|
+
if (childHit) {
|
|
66
|
+
if (child.locked) return child;
|
|
67
|
+
return childHit;
|
|
68
|
+
}
|
|
69
|
+
if (containsPoint(px, py, child, graph, transformCache) && (hasVisibleFillOrStroke(child) || ownsItsEmptyArea(graph, child))) return child;
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The topmost layer under the point among a container's children. `pad`, in canvas units, grows
|
|
74
|
+
* each leaf layer's box, as Figma takes a click a few screen pixels outside a shape.
|
|
75
|
+
*/
|
|
76
|
+
function hitTestChildren(graph, px, py, parentId, deep = false, transformCache = /* @__PURE__ */ new Map(), pad = 0) {
|
|
77
|
+
const parent = graph.nodes.get(parentId);
|
|
78
|
+
if (!parent) return null;
|
|
79
|
+
if (parent.clipsContent) {
|
|
80
|
+
if (!containsPoint(px, py, parent, graph, transformCache)) return null;
|
|
81
|
+
}
|
|
82
|
+
for (let i = parent.childIds.length - 1; i >= 0; i--) {
|
|
83
|
+
const childId = parent.childIds[i];
|
|
84
|
+
const child = graph.nodes.get(childId);
|
|
85
|
+
if (!child || child.internalOnly || !child.visible) continue;
|
|
86
|
+
if (CONTAINER_TYPES.has(child.type)) {
|
|
87
|
+
if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {
|
|
88
|
+
const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad);
|
|
89
|
+
if (hit) return hit;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const hit = hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache, pad);
|
|
93
|
+
if (hit) return hit;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (child.type === "CONNECTOR") {
|
|
97
|
+
if (hitsConnectorLine(graph, child, px, py, pad)) return child;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (containsPoint(px, py, child, graph, transformCache, pad)) return child;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
function hitTest(graph, px, py, scopeId) {
|
|
105
|
+
return hitTestChildren(graph, px, py, scopeId ?? graph.rootId, false);
|
|
106
|
+
}
|
|
107
|
+
function hitTestDeep(graph, px, py, scopeId, pad = 0) {
|
|
108
|
+
return hitTestChildren(graph, px, py, scopeId ?? graph.rootId, true, /* @__PURE__ */ new Map(), pad);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a
|
|
112
|
+
* section) or a section that holds layers, and a component set.
|
|
113
|
+
*/
|
|
114
|
+
function opensByItself(graph, node) {
|
|
115
|
+
if (node.type === "COMPONENT_SET") return true;
|
|
116
|
+
if (node.childIds.length === 0) return false;
|
|
117
|
+
if (node.type === "SECTION") return true;
|
|
118
|
+
return node.type === "FRAME" && isTopLevel(graph, node);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The topmost frame among a container's children whose bounds hold the point, filled or not: in
|
|
122
|
+
* Figma a click on the empty area of a frame inside an open container, or of an empty frame on the
|
|
123
|
+
* page or in a section, selects that frame, while a deep (⌘) click looks through it.
|
|
124
|
+
*/
|
|
125
|
+
function frameChildAt(graph, container, px, py) {
|
|
126
|
+
const transformCache = /* @__PURE__ */ new Map();
|
|
127
|
+
for (let i = container.childIds.length - 1; i >= 0; i--) {
|
|
128
|
+
const child = graph.nodes.get(container.childIds[i]);
|
|
129
|
+
if (!child || child.internalOnly || !child.visible || child.type !== "FRAME") continue;
|
|
130
|
+
if (opensByItself(graph, child) && !ownsItsEmptyArea(graph, child)) continue;
|
|
131
|
+
if (containsPoint(px, py, child, graph, transformCache)) return child;
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The containers the selection opens: every ancestor of a selected layer inside the scope, and a
|
|
137
|
+
* selected container itself, so a click inside it selects the layer under the point, as in Figma.
|
|
138
|
+
* A selected group or boolean stays closed: clicking inside it keeps it selected.
|
|
139
|
+
*/
|
|
140
|
+
function openedBySelection(graph, selectedIds, scopeId) {
|
|
141
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
142
|
+
for (const id of selectedIds) {
|
|
143
|
+
const node = graph.nodes.get(id);
|
|
144
|
+
if (node && node.childIds.length > 0 && node.type !== "GROUP" && node.type !== "BOOLEAN_OPERATION") ancestors.add(id);
|
|
145
|
+
let parentId = node?.parentId;
|
|
146
|
+
while (parentId && parentId !== scopeId && !ancestors.has(parentId)) {
|
|
147
|
+
ancestors.add(parentId);
|
|
148
|
+
parentId = graph.nodes.get(parentId)?.parentId;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return ancestors;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The layer a click selects, as in Figma. It walks from the scope down to the deepest layer under
|
|
155
|
+
* the point and stops at the first layer that is not open. Top-level frames and sections with
|
|
156
|
+
* layers and component sets are open, and so is every ancestor of the selection, so clicks reach
|
|
157
|
+
* the siblings of selected layers. Where every layer under the point is open, a container opened
|
|
158
|
+
* by the selection is selected, so is a top-level frame with auto layout, and a plain top-level
|
|
159
|
+
* frame or a section is not.
|
|
160
|
+
*/
|
|
161
|
+
function hitTestSelectable(graph, px, py, scopeId, selectedIds, pad = 0) {
|
|
162
|
+
const deepest = hitTestChildren(graph, px, py, scopeId, true, /* @__PURE__ */ new Map(), pad);
|
|
163
|
+
if (!deepest) {
|
|
164
|
+
const scope = graph.nodes.get(scopeId);
|
|
165
|
+
return scope ? frameChildAt(graph, scope, px, py) : null;
|
|
166
|
+
}
|
|
167
|
+
const chain = [];
|
|
168
|
+
for (let node = deepest; node && node.id !== scopeId;) {
|
|
169
|
+
chain.unshift(node);
|
|
170
|
+
node = node.parentId ? graph.nodes.get(node.parentId) : void 0;
|
|
171
|
+
}
|
|
172
|
+
const opened = openedBySelection(graph, selectedIds, scopeId);
|
|
173
|
+
for (const node of chain) {
|
|
174
|
+
if (node.locked) return node;
|
|
175
|
+
if (!opened.has(node.id) && !opensByItself(graph, node)) return node;
|
|
176
|
+
}
|
|
177
|
+
const last = chain.at(-1);
|
|
178
|
+
if (!last) return null;
|
|
179
|
+
const frame = frameChildAt(graph, last, px, py);
|
|
180
|
+
if (frame) return frame;
|
|
181
|
+
if (ownsItsEmptyArea(graph, last)) return last;
|
|
182
|
+
return opened.has(last.id) && !opensByItself(graph, last) ? last : null;
|
|
183
|
+
}
|
|
184
|
+
/** Whether a click looks into this container rather than selecting it; see `hitTestSelectable`. */
|
|
185
|
+
function isOpenContainer(graph, nodeId) {
|
|
186
|
+
const node = graph.nodes.get(nodeId);
|
|
187
|
+
return node !== void 0 && opensByItself(graph, node);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The innermost open container under the point when every layer there is open: a marquee starting
|
|
191
|
+
* here selects that container's layers, as in Figma.
|
|
192
|
+
*/
|
|
193
|
+
function hitTestOpenContainer(graph, px, py, scopeId) {
|
|
194
|
+
const deepest = hitTestChildren(graph, px, py, scopeId, true);
|
|
195
|
+
for (let node = deepest ?? void 0; node && node.id !== scopeId;) {
|
|
196
|
+
if (!opensByItself(graph, node) || ownsItsEmptyArea(graph, node)) return null;
|
|
197
|
+
node = node.parentId ? graph.nodes.get(node.parentId) : void 0;
|
|
198
|
+
}
|
|
199
|
+
return deepest;
|
|
200
|
+
}
|
|
201
|
+
function rectsTouch(a, b) {
|
|
202
|
+
return a.x + a.width > b.x && a.x < b.x + b.width && a.y + a.height > b.y && a.y < b.y + b.height;
|
|
203
|
+
}
|
|
204
|
+
function rectOverlap(a, b) {
|
|
205
|
+
if (!rectsTouch(a, b)) return null;
|
|
206
|
+
const x = Math.max(a.x, b.x);
|
|
207
|
+
const y = Math.max(a.y, b.y);
|
|
208
|
+
return {
|
|
209
|
+
x,
|
|
210
|
+
y,
|
|
211
|
+
width: Math.min(a.x + a.width, b.x + b.width) - x,
|
|
212
|
+
height: Math.min(a.y + a.height, b.y + b.height) - y
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Whether a deep marquee touching a container, but none of its layers, selects it: where a deep
|
|
217
|
+
* click there would select it (a group's box, a painted container, the empty area a top-level frame
|
|
218
|
+
* with auto layout owns), except a board or section whose empty area a press treats as background.
|
|
219
|
+
*/
|
|
220
|
+
function selectsByOwnArea(graph, node) {
|
|
221
|
+
if (node.type === "GROUP" || ownsItsEmptyArea(graph, node)) return true;
|
|
222
|
+
return hasVisibleFillOrStroke(node) && !opensByItself(graph, node);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Collects the deepest layers among `parent`'s children that touch `rect`. Each child's world
|
|
226
|
+
* matrix is composed from its parent's, so a walk over a large page climbs no ancestor chains.
|
|
227
|
+
*/
|
|
228
|
+
function collectDeepestInRect(graph, parent, parentWorld, rect, hits) {
|
|
229
|
+
const area = parent.clipsContent && parent.type !== "CANVAS" ? rectOverlap(rect, getAxisAlignedBoundsAt(parent, parentWorld)) : rect;
|
|
230
|
+
if (!area) return;
|
|
231
|
+
for (const childId of parent.childIds) {
|
|
232
|
+
const child = graph.nodes.get(childId);
|
|
233
|
+
if (!child || child.internalOnly || !child.visible || child.locked) continue;
|
|
234
|
+
const world = Matrix.multiply(parentWorld, getNodeLocalMatrix(child));
|
|
235
|
+
const touches = rectsTouch(area, getAxisAlignedBoundsAt(child, world));
|
|
236
|
+
if (!CONTAINER_TYPES.has(child.type) || child.childIds.length === 0) {
|
|
237
|
+
if (touches) hits.push(child);
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const before = hits.length;
|
|
241
|
+
collectDeepestInRect(graph, child, world, area, hits);
|
|
242
|
+
if (hits.length === before && touches && selectsByOwnArea(graph, child)) hits.push(child);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* The deepest layers a deep (⌘) marquee over `rect` selects, as in Figma, by the rules a deep click
|
|
247
|
+
* follows: it looks into frames, groups, sections, components, component sets, and instances, keeps
|
|
248
|
+
* a boolean's operands inside it, and skips hidden, locked, and internal layers with their contents.
|
|
249
|
+
* A container is selected itself only where the rect touches its own area and none of its layers.
|
|
250
|
+
* Layers are compared by their axis-aligned canvas bounds, as a plain marquee compares them.
|
|
251
|
+
*/
|
|
252
|
+
function hitTestDeepInRect(graph, rect, scopeId) {
|
|
253
|
+
const scope = graph.nodes.get(scopeId);
|
|
254
|
+
if (!scope) return [];
|
|
255
|
+
const hits = [];
|
|
256
|
+
collectDeepestInRect(graph, scope, getWorldMatrix(scope, graph), rect, hits);
|
|
257
|
+
return hits;
|
|
258
|
+
}
|
|
259
|
+
/** Whether the point lies inside the node's rotated and flipped bounds. */
|
|
260
|
+
function isPointInNode(graph, nodeId, px, py) {
|
|
261
|
+
const node = graph.nodes.get(nodeId);
|
|
262
|
+
return node !== void 0 && containsPoint(px, py, node, graph, /* @__PURE__ */ new Map());
|
|
263
|
+
}
|
|
264
|
+
const LAYER_TARGETS = /* @__PURE__ */ new Set([
|
|
265
|
+
"FRAME",
|
|
266
|
+
"SECTION",
|
|
267
|
+
"COMPONENT",
|
|
268
|
+
"INSTANCE"
|
|
269
|
+
]);
|
|
270
|
+
const COMPONENT_TARGETS = /* @__PURE__ */ new Set([
|
|
271
|
+
"FRAME",
|
|
272
|
+
"SECTION",
|
|
273
|
+
"INSTANCE"
|
|
274
|
+
]);
|
|
275
|
+
function dropRules(options) {
|
|
276
|
+
const { componentSetIds } = options;
|
|
277
|
+
if (!componentSetIds) return {
|
|
278
|
+
takes: (node) => LAYER_TARGETS.has(node.type),
|
|
279
|
+
passThrough: /* @__PURE__ */ new Set(["GROUP", "COMPONENT_SET"])
|
|
280
|
+
};
|
|
281
|
+
return {
|
|
282
|
+
takes: (node) => COMPONENT_TARGETS.has(node.type) || node.type === "COMPONENT_SET" && componentSetIds.has(node.id),
|
|
283
|
+
passThrough: /* @__PURE__ */ new Set(["GROUP"])
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function dropTargetIn(graph, px, py, parent, excludeIds, rules, transformCache) {
|
|
287
|
+
if (parent.type !== "CANVAS" && parent.clipsContent && !containsPoint(px, py, parent, graph, transformCache)) return null;
|
|
288
|
+
for (let i = parent.childIds.length - 1; i >= 0; i--) {
|
|
289
|
+
const childId = parent.childIds[i];
|
|
290
|
+
if (excludeIds.has(childId)) continue;
|
|
291
|
+
const child = graph.nodes.get(childId);
|
|
292
|
+
if (!child || child.internalOnly || !child.visible || child.locked) continue;
|
|
293
|
+
const target = rules.takes(child);
|
|
294
|
+
if (!target && !rules.passThrough.has(child.type)) continue;
|
|
295
|
+
const deeper = dropTargetIn(graph, px, py, child, excludeIds, rules, transformCache);
|
|
296
|
+
if (deeper) return deeper;
|
|
297
|
+
if (target && containsPoint(px, py, child, graph, transformCache)) return child;
|
|
298
|
+
}
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* The topmost unlocked frame, section, component, or instance under the point, in its rotated
|
|
303
|
+
* shape and inside its clipping ancestors. Groups and component sets are looked through but never
|
|
304
|
+
* returned, except that a set takes dropped components; locked layers and their contents are
|
|
305
|
+
* skipped.
|
|
306
|
+
*/
|
|
307
|
+
function hitTestDropTarget(graph, px, py, excludeIds, scopeId, options = {}) {
|
|
308
|
+
const scope = graph.nodes.get(scopeId ?? graph.rootId);
|
|
309
|
+
if (!scope) return null;
|
|
310
|
+
return dropTargetIn(graph, px, py, scope, excludeIds, dropRules(options), /* @__PURE__ */ new Map());
|
|
311
|
+
}
|
|
312
|
+
//#endregion
|
|
313
|
+
export { hitTest, hitTestDeep, hitTestDeepInRect, hitTestDropTarget, hitTestOpenContainer, hitTestSelectable, isOpenContainer, isPointInNode };
|
|
314
|
+
|
|
315
|
+
//# sourceMappingURL=hit-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import { hitsConnectorLine } from './connectors/hit'\nimport { getAxisAlignedBoundsAt, getNodeLocalMatrix, getWorldMatrix } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport Matrix, { type Mat3 } from './matrix'\nimport type { Rect } from './primitives'\nimport type { SceneNode, NodeType } from './types'\n\nconst CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\nconst OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])\n\nfunction hasVisibleFillOrStroke(node: SceneNode): boolean {\n return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible)\n}\n\nfunction isTopLevel(graph: SceneGraph, node: SceneNode): boolean {\n const parent = node.parentId ? graph.nodes.get(node.parentId) : undefined\n return parent?.type === 'CANVAS' || parent?.type === 'SECTION'\n}\n\n/**\n * An open container whose empty area still belongs to it, as in Figma: a top-level frame with auto\n * layout is selected, hovered, and dragged by its gaps and padding, while its children stay one\n * click away, with or without a fill. A plain top-level frame's empty area is background, and a\n * nested frame's empty area belongs to it only as a click target (see `frameChildAt`).\n */\nfunction ownsItsEmptyArea(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && node.layoutMode !== 'NONE' && isTopLevel(graph, node)\n}\n\nfunction hasTransformedAncestor(\n node: SceneNode,\n graph: SceneGraph,\n cache: Map<string, boolean>\n): boolean {\n const cached = cache.get(node.id)\n if (cached !== undefined) return cached\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const transformed =\n node.rotation !== 0 ||\n node.flipX ||\n node.flipY ||\n (parent ? hasTransformedAncestor(parent, graph, cache) : false)\n cache.set(node.id, transformed)\n return transformed\n}\n\n/** Whether the point lies in the node's box, grown by `pad` canvas units on every side. */\nfunction containsPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>,\n pad = 0\n): boolean {\n if (!hasTransformedAncestor(node, graph, transformCache)) {\n const absolute = graph.getAbsolutePosition(node.id)\n return (\n px >= absolute.x - pad &&\n px <= absolute.x + node.width + pad &&\n py >= absolute.y - pad &&\n py <= absolute.y + node.height + pad\n )\n }\n\n const m = getWorldMatrix(node, graph)\n\n const inv = Matrix.invert(m)\n if (!inv) return false\n\n const [localX, localY] = Matrix.mapPoints(inv, [px, py])\n return (\n localX >= -pad && localX <= node.width + pad && localY >= -pad && localY <= node.height + pad\n )\n}\n\nfunction hitTestOpaqueContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>,\n pad: number\n): SceneNode | null {\n if (!containsPoint(px, py, child, graph, transformCache)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad)\n if (childHit) return child\n if (hasVisibleFillOrStroke(child)) return child\n return null\n}\nfunction hitTestTransparentContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>,\n pad: number\n): SceneNode | null {\n if (child.type === 'GROUP') {\n // A group fits its layers, so a padded click on one at its edge falls just outside it.\n if (!containsPoint(px, py, child, graph, transformCache, pad)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad)\n if (childHit) return deep ? childHit : child\n return containsPoint(px, py, child, graph, transformCache) ? child : null\n }\n\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache, pad)\n if (childHit) {\n if (child.locked) return child\n return childHit\n }\n\n if (\n containsPoint(px, py, child, graph, transformCache) &&\n (hasVisibleFillOrStroke(child) || ownsItsEmptyArea(graph, child))\n )\n return child\n return null\n}\n\n/**\n * The topmost layer under the point among a container's children. `pad`, in canvas units, grows\n * each leaf layer's box, as Figma takes a click a few screen pixels outside a shape.\n */\nfunction hitTestChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n deep = false,\n transformCache = new Map<string, boolean>(),\n pad = 0\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n\n if (parent.clipsContent) {\n if (!containsPoint(px, py, parent, graph, transformCache)) return null\n }\n\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible) continue\n if (CONTAINER_TYPES.has(child.type)) {\n if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {\n const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache, pad)\n if (hit) return hit\n continue\n }\n\n const hit = hitTestTransparentContainer(\n graph,\n px,\n py,\n child,\n childId,\n deep,\n transformCache,\n pad\n )\n if (hit) return hit\n continue\n }\n\n if (child.type === 'CONNECTOR') {\n if (hitsConnectorLine(graph, child, px, py, pad)) return child\n continue\n }\n if (containsPoint(px, py, child, graph, transformCache, pad)) return child\n }\n\n return null\n}\n\nexport function hitTest(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, false)\n}\n\nexport function hitTestDeep(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string,\n pad = 0\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, true, new Map(), pad)\n}\n\n/**\n * A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a\n * section) or a section that holds layers, and a component set.\n */\nfunction opensByItself(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'COMPONENT_SET') return true\n if (node.childIds.length === 0) return false\n if (node.type === 'SECTION') return true\n return node.type === 'FRAME' && isTopLevel(graph, node)\n}\n\n/**\n * The topmost frame among a container's children whose bounds hold the point, filled or not: in\n * Figma a click on the empty area of a frame inside an open container, or of an empty frame on the\n * page or in a section, selects that frame, while a deep (⌘) click looks through it.\n */\nfunction frameChildAt(\n graph: SceneGraph,\n container: SceneNode,\n px: number,\n py: number\n): SceneNode | null {\n const transformCache = new Map<string, boolean>()\n for (let i = container.childIds.length - 1; i >= 0; i--) {\n const child = graph.nodes.get(container.childIds[i])\n if (!child || child.internalOnly || !child.visible || child.type !== 'FRAME') continue\n // A board, such as a top-level frame in a section, keeps its empty area as background.\n if (opensByItself(graph, child) && !ownsItsEmptyArea(graph, child)) continue\n if (containsPoint(px, py, child, graph, transformCache)) return child\n }\n return null\n}\n\n/**\n * The containers the selection opens: every ancestor of a selected layer inside the scope, and a\n * selected container itself, so a click inside it selects the layer under the point, as in Figma.\n * A selected group or boolean stays closed: clicking inside it keeps it selected.\n */\nfunction openedBySelection(\n graph: SceneGraph,\n selectedIds: ReadonlySet<string>,\n scopeId: string\n): Set<string> {\n const ancestors = new Set<string>()\n for (const id of selectedIds) {\n const node = graph.nodes.get(id)\n if (\n node &&\n node.childIds.length > 0 &&\n node.type !== 'GROUP' &&\n node.type !== 'BOOLEAN_OPERATION'\n )\n ancestors.add(id)\n let parentId = node?.parentId\n while (parentId && parentId !== scopeId && !ancestors.has(parentId)) {\n ancestors.add(parentId)\n parentId = graph.nodes.get(parentId)?.parentId\n }\n }\n return ancestors\n}\n\n/**\n * The layer a click selects, as in Figma. It walks from the scope down to the deepest layer under\n * the point and stops at the first layer that is not open. Top-level frames and sections with\n * layers and component sets are open, and so is every ancestor of the selection, so clicks reach\n * the siblings of selected layers. Where every layer under the point is open, a container opened\n * by the selection is selected, so is a top-level frame with auto layout, and a plain top-level\n * frame or a section is not.\n */\nexport function hitTestSelectable(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n pad = 0\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true, new Map(), pad)\n if (!deepest) {\n const scope = graph.nodes.get(scopeId)\n return scope ? frameChildAt(graph, scope, px, py) : null\n }\n\n const chain: SceneNode[] = []\n for (let node: SceneNode | undefined = deepest; node && node.id !== scopeId;) {\n chain.unshift(node)\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n\n const opened = openedBySelection(graph, selectedIds, scopeId)\n\n for (const node of chain) {\n // A locked layer stands in for everything inside it.\n if (node.locked) return node\n if (!opened.has(node.id) && !opensByItself(graph, node)) return node\n }\n const last = chain.at(-1)\n if (!last) return null\n const frame = frameChildAt(graph, last, px, py)\n if (frame) return frame\n if (ownsItsEmptyArea(graph, last)) return last\n return opened.has(last.id) && !opensByItself(graph, last) ? last : null\n}\n\n/** Whether a click looks into this container rather than selecting it; see `hitTestSelectable`. */\nexport function isOpenContainer(graph: SceneGraph, nodeId: string): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && opensByItself(graph, node)\n}\n\n/**\n * The innermost open container under the point when every layer there is open: a marquee starting\n * here selects that container's layers, as in Figma.\n */\nexport function hitTestOpenContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string\n): SceneNode | null {\n const deepest = hitTestChildren(graph, px, py, scopeId, true)\n for (let node: SceneNode | undefined = deepest ?? undefined; node && node.id !== scopeId;) {\n if (!opensByItself(graph, node) || ownsItsEmptyArea(graph, node)) return null\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n return deepest\n}\n\nfunction rectsTouch(a: Rect, b: Rect): boolean {\n return a.x + a.width > b.x && a.x < b.x + b.width && a.y + a.height > b.y && a.y < b.y + b.height\n}\n\nfunction rectOverlap(a: Rect, b: Rect): Rect | null {\n if (!rectsTouch(a, b)) return null\n const x = Math.max(a.x, b.x)\n const y = Math.max(a.y, b.y)\n return {\n x,\n y,\n width: Math.min(a.x + a.width, b.x + b.width) - x,\n height: Math.min(a.y + a.height, b.y + b.height) - y\n }\n}\n\n/**\n * Whether a deep marquee touching a container, but none of its layers, selects it: where a deep\n * click there would select it (a group's box, a painted container, the empty area a top-level frame\n * with auto layout owns), except a board or section whose empty area a press treats as background.\n */\nfunction selectsByOwnArea(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type === 'GROUP' || ownsItsEmptyArea(graph, node)) return true\n return hasVisibleFillOrStroke(node) && !opensByItself(graph, node)\n}\n\n/**\n * Collects the deepest layers among `parent`'s children that touch `rect`. Each child's world\n * matrix is composed from its parent's, so a walk over a large page climbs no ancestor chains.\n */\nfunction collectDeepestInRect(\n graph: SceneGraph,\n parent: SceneNode,\n parentWorld: Mat3,\n rect: Rect,\n hits: SceneNode[]\n) {\n // A clipping container draws nothing outside itself, so its layers meet only that part of the rect.\n const area =\n parent.clipsContent && parent.type !== 'CANVAS'\n ? rectOverlap(rect, getAxisAlignedBoundsAt(parent, parentWorld))\n : rect\n if (!area) return\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const world = Matrix.multiply(parentWorld, getNodeLocalMatrix(child))\n const touches = rectsTouch(area, getAxisAlignedBoundsAt(child, world))\n if (!CONTAINER_TYPES.has(child.type) || child.childIds.length === 0) {\n if (touches) hits.push(child)\n continue\n }\n const before = hits.length\n collectDeepestInRect(graph, child, world, area, hits)\n if (hits.length === before && touches && selectsByOwnArea(graph, child)) hits.push(child)\n }\n}\n\n/**\n * The deepest layers a deep (⌘) marquee over `rect` selects, as in Figma, by the rules a deep click\n * follows: it looks into frames, groups, sections, components, component sets, and instances, keeps\n * a boolean's operands inside it, and skips hidden, locked, and internal layers with their contents.\n * A container is selected itself only where the rect touches its own area and none of its layers.\n * Layers are compared by their axis-aligned canvas bounds, as a plain marquee compares them.\n */\nexport function hitTestDeepInRect(graph: SceneGraph, rect: Rect, scopeId: string): SceneNode[] {\n const scope = graph.nodes.get(scopeId)\n if (!scope) return []\n const hits: SceneNode[] = []\n collectDeepestInRect(graph, scope, getWorldMatrix(scope, graph), rect, hits)\n return hits\n}\n\n/** Whether the point lies inside the node's rotated and flipped bounds. */\nexport function isPointInNode(graph: SceneGraph, nodeId: string, px: number, py: number): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && containsPoint(px, py, node, graph, new Map())\n}\n\n/** Which layers take a drop, and which are only looked through, as in Figma. */\ninterface DropRules {\n takes: (node: SceneNode) => boolean\n passThrough: ReadonlySet<NodeType>\n}\n\nconst LAYER_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'COMPONENT', 'INSTANCE'])\nconst COMPONENT_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'INSTANCE'])\n\nfunction dropRules(options: DropTargetOptions): DropRules {\n const { componentSetIds } = options\n if (!componentSetIds) {\n return {\n takes: (node) => LAYER_TARGETS.has(node.type),\n passThrough: new Set(['GROUP', 'COMPONENT_SET'])\n }\n }\n // Components never go into other components, and a set only takes back its own variants.\n return {\n takes: (node) =>\n COMPONENT_TARGETS.has(node.type) ||\n (node.type === 'COMPONENT_SET' && componentSetIds.has(node.id)),\n passThrough: new Set(['GROUP'])\n }\n}\n\nfunction dropTargetIn(\n graph: SceneGraph,\n px: number,\n py: number,\n parent: SceneNode,\n excludeIds: ReadonlySet<string>,\n rules: DropRules,\n transformCache: Map<string, boolean>\n): SceneNode | null {\n // A clipped-away part of a child is not under the cursor.\n if (\n parent.type !== 'CANVAS' &&\n parent.clipsContent &&\n !containsPoint(px, py, parent, graph, transformCache)\n )\n return null\n\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n if (excludeIds.has(childId)) continue\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible || child.locked) continue\n const target = rules.takes(child)\n if (!target && !rules.passThrough.has(child.type)) continue\n\n const deeper = dropTargetIn(graph, px, py, child, excludeIds, rules, transformCache)\n if (deeper) return deeper\n if (target && containsPoint(px, py, child, graph, transformCache)) return child\n }\n\n return null\n}\n\nexport interface DropTargetOptions {\n /**\n * Set when the dropped layers are all main components: the component sets they come from.\n * Components then go only into frames, sections, instances, and those sets.\n */\n componentSetIds?: ReadonlySet<string>\n}\n\n/**\n * The topmost unlocked frame, section, component, or instance under the point, in its rotated\n * shape and inside its clipping ancestors. Groups and component sets are looked through but never\n * returned, except that a set takes dropped components; locked layers and their contents are\n * skipped.\n */\nexport function hitTestDropTarget(\n graph: SceneGraph,\n px: number,\n py: number,\n excludeIds: ReadonlySet<string>,\n scopeId?: string,\n options: DropTargetOptions = {}\n): SceneNode | null {\n const scope = graph.nodes.get(scopeId ?? graph.rootId)\n if (!scope) return null\n return dropTargetIn(graph, px, py, scope, excludeIds, dropRules(options), new Map())\n}\n"],"mappings":";;;;AAOA,MAAM,kCAAkB,IAAI,IAAc;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,yCAAyB,IAAI,IAAc,CAAC,aAAa,UAAU,CAAC;AAE1E,SAAS,uBAAuB,MAA0B;CACxD,OAAO,KAAK,MAAM,MAAM,MAAM,EAAE,OAAO,KAAK,KAAK,QAAQ,MAAM,MAAM,EAAE,OAAO;AAChF;AAEA,SAAS,WAAW,OAAmB,MAA0B;CAC/D,MAAM,SAAS,KAAK,WAAW,MAAM,MAAM,IAAI,KAAK,QAAQ,IAAI,KAAA;CAChE,OAAO,QAAQ,SAAS,YAAY,QAAQ,SAAS;AACvD;;;;;;;AAQA,SAAS,iBAAiB,OAAmB,MAA0B;CACrE,OAAO,KAAK,SAAS,WAAW,KAAK,eAAe,UAAU,WAAW,O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AAa,OAAO,IAAI,IAAI,OAAO,YAAY,UAAU,OAAO,mBAAG,IAAI,IAAI,CAAC;AACrF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SceneNode } from "../types.js";
|
|
2
|
+
//#region src/icons/glyph.d.ts
|
|
3
|
+
/** What reading an icon's paths needs of a graph. */
|
|
4
|
+
interface IconGraph {
|
|
5
|
+
getChildren(id: string): SceneNode[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A fingerprint of what an icon frame draws: which paths it holds and their shapes, stroke ends,
|
|
9
|
+
* and paints. Resizing the icon, however unevenly, or changing its color leaves it unchanged;
|
|
10
|
+
* editing points, rotating or fading a path, adding or removing one, or changing a color of the
|
|
11
|
+
* icon's own changes it. Moving a whole path or changing its stroke weight does not count, since
|
|
12
|
+
* resizing changes those by rounded amounts too.
|
|
13
|
+
*/
|
|
14
|
+
declare function iconGlyph(graph: IconGraph, frame: SceneNode): string;
|
|
15
|
+
/**
|
|
16
|
+
* Whether an icon frame no longer draws the glyph it was placed with: its paths were edited,
|
|
17
|
+
* added, or removed. An icon placed before glyphs were recorded counts as unedited.
|
|
18
|
+
*/
|
|
19
|
+
declare function isIconModified(graph: IconGraph, frame: SceneNode): boolean;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { iconGlyph, isIconModified };
|
|
22
|
+
//# sourceMappingURL=glyph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glyph.d.ts","names":[],"sources":["../../src/icons/glyph.ts"],"mappings":";;;UAMU;EACR,YAAY,aAAa;;;;;;;;;iBA+FX,UAAU,OAAO,WAAW,OAAO;;;;;iBAsBnC,eAAe,OAAO,WAAW,OAAO"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { readIcon, readIconTint } from "./model.js";
|
|
2
|
+
import { omit } from "es-toolkit";
|
|
3
|
+
//#region src/icons/glyph.ts
|
|
4
|
+
/** Digits kept of each proportion, so float noise does not read as an edit. */
|
|
5
|
+
const PRECISION = 1e3;
|
|
6
|
+
const round = (value) => Math.round(value * PRECISION) / PRECISION;
|
|
7
|
+
/**
|
|
8
|
+
* A path's points in proportion to their own bounds on each axis. Resizing scales vertices by
|
|
9
|
+
* exact factors, so these proportions survive any resize, while the path boxes around them are
|
|
10
|
+
* rounded to pixels and are left out.
|
|
11
|
+
*/
|
|
12
|
+
function shape(network) {
|
|
13
|
+
if (!network) return null;
|
|
14
|
+
const f = Math.fround;
|
|
15
|
+
const xs = network.vertices.map((vertex) => f(vertex.x));
|
|
16
|
+
const ys = network.vertices.map((vertex) => f(vertex.y));
|
|
17
|
+
const minX = Math.min(...xs);
|
|
18
|
+
const minY = Math.min(...ys);
|
|
19
|
+
const sx = 1 / (Math.max(...xs) - minX || 1);
|
|
20
|
+
const sy = 1 / (Math.max(...ys) - minY || 1);
|
|
21
|
+
return {
|
|
22
|
+
vertices: network.vertices.map((vertex) => [
|
|
23
|
+
round((f(vertex.x) - minX) * sx),
|
|
24
|
+
round((f(vertex.y) - minY) * sy),
|
|
25
|
+
vertex.strokeCap ?? null,
|
|
26
|
+
vertex.strokeJoin ?? null
|
|
27
|
+
]),
|
|
28
|
+
segments: network.segments.map((segment) => [
|
|
29
|
+
segment.start,
|
|
30
|
+
segment.end,
|
|
31
|
+
round(f(segment.tangentStart.x) * sx),
|
|
32
|
+
round(f(segment.tangentStart.y) * sy),
|
|
33
|
+
round(f(segment.tangentEnd.x) * sx),
|
|
34
|
+
round(f(segment.tangentEnd.y) * sy)
|
|
35
|
+
]),
|
|
36
|
+
regions: network.regions
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Paint fields that read the same as when they are absent, which saving and loading a document
|
|
41
|
+
* fills in: a normal blend and no dashes.
|
|
42
|
+
*/
|
|
43
|
+
const PAINT_DEFAULTS = { blendMode: "NORMAL" };
|
|
44
|
+
/**
|
|
45
|
+
* A value described the same however it was stored: keys sorted, defaults and empty lists left
|
|
46
|
+
* out, and numbers rounded, since a saved document keeps them at lower precision.
|
|
47
|
+
*/
|
|
48
|
+
function canonical(value) {
|
|
49
|
+
if (typeof value === "number") return round(Math.fround(value));
|
|
50
|
+
if (Array.isArray(value)) return value.map(canonical);
|
|
51
|
+
if (typeof value !== "object" || value === null) return value;
|
|
52
|
+
const entries = Object.entries(value).filter(([key, item]) => item !== void 0 && PAINT_DEFAULTS[key] !== item && !(Array.isArray(item) && item.length === 0)).sort(([a], [b]) => a.localeCompare(b));
|
|
53
|
+
return Object.fromEntries(entries.map(([key, item]) => [key, canonical(item)]));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A paint as it looks, leaving out the color when the icon's color sets it, and a stroke's
|
|
57
|
+
* weight, which resizing scales.
|
|
58
|
+
*/
|
|
59
|
+
function paint(fill, tinted) {
|
|
60
|
+
const { color, ...rest } = "weight" in fill ? omit(fill, ["weight"]) : fill;
|
|
61
|
+
return canonical(tinted ? rest : {
|
|
62
|
+
...rest,
|
|
63
|
+
color
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** FNV-1a, enough to tell one glyph from another without keeping the whole description. */
|
|
67
|
+
function hash(text) {
|
|
68
|
+
let value = 2166136261;
|
|
69
|
+
for (let index = 0; index < text.length; index++) {
|
|
70
|
+
value ^= text.charCodeAt(index);
|
|
71
|
+
value = Math.imul(value, 16777619);
|
|
72
|
+
}
|
|
73
|
+
return (value >>> 0).toString(16).padStart(8, "0");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A fingerprint of what an icon frame draws: which paths it holds and their shapes, stroke ends,
|
|
77
|
+
* and paints. Resizing the icon, however unevenly, or changing its color leaves it unchanged;
|
|
78
|
+
* editing points, rotating or fading a path, adding or removing one, or changing a color of the
|
|
79
|
+
* icon's own changes it. Moving a whole path or changing its stroke weight does not count, since
|
|
80
|
+
* resizing changes those by rounded amounts too.
|
|
81
|
+
*/
|
|
82
|
+
function iconGlyph(graph, frame) {
|
|
83
|
+
const description = graph.getChildren(frame.id).map((path) => {
|
|
84
|
+
const tint = readIconTint(path);
|
|
85
|
+
return {
|
|
86
|
+
type: path.type,
|
|
87
|
+
shape: shape(path.vectorNetwork),
|
|
88
|
+
fills: path.fills.map((fill) => paint(fill, tint.includes("fill"))),
|
|
89
|
+
strokes: path.strokes.map((stroke) => paint(stroke, tint.includes("stroke"))),
|
|
90
|
+
ends: [path.strokeCap, path.strokeJoin],
|
|
91
|
+
rotation: round(path.rotation),
|
|
92
|
+
opacity: round(path.opacity),
|
|
93
|
+
visible: path.visible
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
return hash(JSON.stringify(description));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Whether an icon frame no longer draws the glyph it was placed with: its paths were edited,
|
|
100
|
+
* added, or removed. An icon placed before glyphs were recorded counts as unedited.
|
|
101
|
+
*/
|
|
102
|
+
function isIconModified(graph, frame) {
|
|
103
|
+
const glyph = readIcon(frame)?.glyph;
|
|
104
|
+
return glyph !== void 0 && iconGlyph(graph, frame) !== glyph;
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { iconGlyph, isIconModified };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=glyph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glyph.js","names":[],"sources":["../../src/icons/glyph.ts"],"sourcesContent":["import { omit } from 'es-toolkit'\n\nimport type { Fill, SceneNode, Stroke, VectorNetwork } from '../types'\nimport { readIcon, readIconTint } from './model'\n\n/** What reading an icon's paths needs of a graph. */\ninterface IconGraph {\n getChildren(id: string): SceneNode[]\n}\n\n/** Digits kept of each proportion, so float noise does not read as an edit. */\nconst PRECISION = 1000\n\nconst round = (value: number) => Math.round(value * PRECISION) / PRECISION\n\n/**\n * A path's points in proportion to their own bounds on each axis. Resizing scales vertices by\n * exact factors, so these proportions survive any resize, while the path boxes around them are\n * rounded to pixels and are left out.\n */\nfunction shape(network: VectorNetwork | null | undefined) {\n if (!network) return null\n // A saved document keeps coordinates as 32-bit floats, so they are read at that precision\n // either way; rounding alone would still split a value that lands on a rounding boundary.\n const f = Math.fround\n const xs = network.vertices.map((vertex) => f(vertex.x))\n const ys = network.vertices.map((vertex) => f(vertex.y))\n const minX = Math.min(...xs)\n const minY = Math.min(...ys)\n const sx = 1 / (Math.max(...xs) - minX || 1)\n const sy = 1 / (Math.max(...ys) - minY || 1)\n return {\n vertices: network.vertices.map((vertex) => [\n round((f(vertex.x) - minX) * sx),\n round((f(vertex.y) - minY) * sy),\n vertex.strokeCap ?? null,\n vertex.strokeJoin ?? null\n ]),\n segments: network.segments.map((segment) => [\n segment.start,\n segment.end,\n round(f(segment.tangentStart.x) * sx),\n round(f(segment.tangentStart.y) * sy),\n round(f(segment.tangentEnd.x) * sx),\n round(f(segment.tangentEnd.y) * sy)\n ]),\n regions: network.regions\n }\n}\n\n/**\n * Paint fields that read the same as when they are absent, which saving and loading a document\n * fills in: a normal blend and no dashes.\n */\nconst PAINT_DEFAULTS: Readonly<Record<string, unknown>> = { blendMode: 'NORMAL' }\n\n/**\n * A value described the same however it was stored: keys sorted, defaults and empty lists left\n * out, and numbers rounded, since a saved document keeps them at lower precision.\n */\nfunction canonical(value: unknown): unknown {\n // Stored as 32-bit floats too, so read at that precision before rounding, as coordinates are.\n if (typeof value === 'number') return round(Math.fround(value))\n if (Array.isArray(value)) return value.map(canonical)\n if (typeof value !== 'object' || value === null) return value\n const entries = Object.entries(value)\n .filter(\n ([key, item]) =>\n item !== undefined &&\n PAINT_DEFAULTS[key] !== item &&\n !(Array.isArray(item) && item.length === 0)\n )\n .sort(([a], [b]) => a.localeCompare(b))\n return Object.fromEntries(entries.map(([key, item]) => [key, canonical(item)]))\n}\n\n/**\n * A paint as it looks, leaving out the color when the icon's color sets it, and a stroke's\n * weight, which resizing scales.\n */\nfunction paint(fill: Fill | Stroke, tinted: boolean) {\n const { color, ...rest } = 'weight' in fill ? omit(fill, ['weight']) : fill\n return canonical(tinted ? rest : { ...rest, color })\n}\n\n/** FNV-1a, enough to tell one glyph from another without keeping the whole description. */\nfunction hash(text: string): string {\n let value = 0x811c9dc5\n for (let index = 0; index < text.length; index++) {\n value ^= text.charCodeAt(index)\n value = Math.imul(value, 0x01000193)\n }\n return (value >>> 0).toString(16).padStart(8, '0')\n}\n\n/**\n * A fingerprint of what an icon frame draws: which paths it holds and their shapes, stroke ends,\n * and paints. Resizing the icon, however unevenly, or changing its color leaves it unchanged;\n * editing points, rotating or fading a path, adding or removing one, or changing a color of the\n * icon's own changes it. Moving a whole path or changing its stroke weight does not count, since\n * resizing changes those by rounded amounts too.\n */\nexport function iconGlyph(graph: IconGraph, frame: SceneNode): string {\n const description = graph.getChildren(frame.id).map((path) => {\n const tint = readIconTint(path)\n return {\n type: path.type,\n shape: shape(path.vectorNetwork),\n fills: path.fills.map((fill) => paint(fill, tint.includes('fill'))),\n strokes: path.strokes.map((stroke) => paint(stroke, tint.includes('stroke'))),\n ends: [path.strokeCap, path.strokeJoin],\n // Resizing leaves these alone, so they count, unlike a path's place and stroke weight.\n rotation: round(path.rotation),\n opacity: round(path.opacity),\n visible: path.visible\n }\n })\n return hash(JSON.stringify(description))\n}\n\n/**\n * Whether an icon frame no longer draws the glyph it was placed with: its paths were edited,\n * added, or removed. An icon placed before glyphs were recorded counts as unedited.\n */\nexport function isIconModified(graph: IconGraph, frame: SceneNode): boolean {\n const glyph = readIcon(frame)?.glyph\n return glyph !== undefined && iconGlyph(graph, frame) !== glyph\n}\n"],"mappings":";;;;AAWA,MAAM,YAAY;AAElB,MAAM,SAAS,UAAkB,KAAK,MAAM,QAAQ,SAAS,IAAI;;;;;;AAOjE,SAAS,MAAM,SAA2C;CACxD,IAAI,CAAC,SAAS,OAAO;CAGrB,MAAM,IAAI,KAAK;CACf,MAAM,KAAK,QAAQ,SAAS,KAAK,WAAW,EAAE,OAAO,CAAC,CAAC;CACvD,MAAM,KAAK,QAAQ,SAAS,KAAK,WAAW,E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 +1,4 @@
|
|
|
1
|
+
import { iconGlyph, isIconModified } from "./glyph.js";
|
|
2
|
+
import { ICON_NAME, ICON_PAINTS, Icon, IconOptions, IconPaint, iconOptionsSchema, iconSchema, iconTintSchema } from "./schema.js";
|
|
3
|
+
import { iconLayerName, iconNames, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint } from "./model.js";
|
|
4
|
+
export { ICON_NAME, ICON_PAINTS, Icon, IconOptions, IconPaint, iconGlyph, iconLayerName, iconNames, iconOptionsSchema, iconSchema, iconTintSchema, isIconModified, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ICON_NAME, ICON_PAINTS, iconOptionsSchema, iconSchema, iconTintSchema } from "./schema.js";
|
|
2
|
+
import { iconLayerName, iconNames, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint } from "./model.js";
|
|
3
|
+
import { iconGlyph, isIconModified } from "./glyph.js";
|
|
4
|
+
export { ICON_NAME, ICON_PAINTS, iconGlyph, iconLayerName, iconNames, iconOptionsSchema, iconSchema, iconTintSchema, isIconModified, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SceneNode } from "../types.js";
|
|
2
|
+
import { Icon, IconPaint } from "./schema.js";
|
|
3
|
+
//#region src/icons/model.d.ts
|
|
4
|
+
/** The icon a frame draws, or null when it is not an icon or its data is unreadable. */
|
|
5
|
+
declare function readIcon(node: SceneNode): Icon | null;
|
|
6
|
+
/** The node's plugin data with the icon set, or removed when null. */
|
|
7
|
+
declare function withIcon(node: SceneNode, icon: Icon | null): SceneNode['pluginData'];
|
|
8
|
+
/**
|
|
9
|
+
* Whether code can draw the icon from its name alone, as Iconify's components do. An icon with
|
|
10
|
+
* options was drawn from a set of our own, such as a font at its axes, so it exports as the paths
|
|
11
|
+
* it draws.
|
|
12
|
+
*/
|
|
13
|
+
declare function isNamedIcon(icon: Icon): boolean;
|
|
14
|
+
/** The layer name an icon is placed with: its name in the set, such as `cat` for `mdi:cat`. */
|
|
15
|
+
declare function iconLayerName(name: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Whether `layerName` is the name an icon `name` was placed with, rather than one someone gave
|
|
18
|
+
* it: `cat`, or `Icon / mdi:cat` as icons were named before.
|
|
19
|
+
*/
|
|
20
|
+
declare function isPlacedIconName(layerName: string, name: string): boolean;
|
|
21
|
+
/** The names of the icons among `nodes`, each once, in the order they are first met. */
|
|
22
|
+
declare function iconNames(nodes: Iterable<SceneNode>): string[];
|
|
23
|
+
/** The paints of an icon path that its icon's color sets; none when it keeps its own colors. */
|
|
24
|
+
declare function readIconTint(node: SceneNode): readonly IconPaint[];
|
|
25
|
+
/** The path's plugin data with its tinted paints, or removed when there are none. */
|
|
26
|
+
declare function withIconTint(node: SceneNode, paints: readonly IconPaint[]): SceneNode['pluginData'];
|
|
27
|
+
//#endregion
|
|
28
|
+
export { iconLayerName, iconNames, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint };
|
|
29
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","names":[],"sources":["../../src/icons/model.ts"],"mappings":";;;;iBAMgB,SAAS,MAAM,YAAY;;iBAK3B,SAAS,MAAM,WAAW,MAAM,cAAc;;;;;;iBAS9C,YAAY,MAAM;;iBAKlB,cAAc;;;;;iBAQd,iBAAiB,mBAAmB;;iBAKpC,UAAU,OAAO,SAAS;;iBAU1B,aAAa,MAAM,qBAAqB;;iBAKxC,aACd,MAAM,WACN,iBAAiB,cAChB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { readPluginData, withPluginData } from "../plugin-data/field.js";
|
|
2
|
+
import { PAIRDRAW_PLUGIN_DATA } from "../plugin-data/fields.js";
|
|
3
|
+
//#region src/icons/model.ts
|
|
4
|
+
/** The icon a frame draws, or null when it is not an icon or its data is unreadable. */
|
|
5
|
+
function readIcon(node) {
|
|
6
|
+
return readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.icon) ?? null;
|
|
7
|
+
}
|
|
8
|
+
/** The node's plugin data with the icon set, or removed when null. */
|
|
9
|
+
function withIcon(node, icon) {
|
|
10
|
+
return withPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.icon, icon ?? void 0);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Whether code can draw the icon from its name alone, as Iconify's components do. An icon with
|
|
14
|
+
* options was drawn from a set of our own, such as a font at its axes, so it exports as the paths
|
|
15
|
+
* it draws.
|
|
16
|
+
*/
|
|
17
|
+
function isNamedIcon(icon) {
|
|
18
|
+
return icon.options === void 0;
|
|
19
|
+
}
|
|
20
|
+
/** The layer name an icon is placed with: its name in the set, such as `cat` for `mdi:cat`. */
|
|
21
|
+
function iconLayerName(name) {
|
|
22
|
+
return name.slice(name.indexOf(":") + 1);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether `layerName` is the name an icon `name` was placed with, rather than one someone gave
|
|
26
|
+
* it: `cat`, or `Icon / mdi:cat` as icons were named before.
|
|
27
|
+
*/
|
|
28
|
+
function isPlacedIconName(layerName, name) {
|
|
29
|
+
return layerName === iconLayerName(name) || layerName === `Icon / ${name}`;
|
|
30
|
+
}
|
|
31
|
+
/** The names of the icons among `nodes`, each once, in the order they are first met. */
|
|
32
|
+
function iconNames(nodes) {
|
|
33
|
+
const names = /* @__PURE__ */ new Set();
|
|
34
|
+
for (const node of nodes) {
|
|
35
|
+
const icon = readIcon(node);
|
|
36
|
+
if (icon) names.add(icon.name);
|
|
37
|
+
}
|
|
38
|
+
return [...names];
|
|
39
|
+
}
|
|
40
|
+
/** The paints of an icon path that its icon's color sets; none when it keeps its own colors. */
|
|
41
|
+
function readIconTint(node) {
|
|
42
|
+
return readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.iconTint) ?? [];
|
|
43
|
+
}
|
|
44
|
+
/** The path's plugin data with its tinted paints, or removed when there are none. */
|
|
45
|
+
function withIconTint(node, paints) {
|
|
46
|
+
return withPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.iconTint, paints.length > 0 ? [...paints] : void 0);
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { iconLayerName, iconNames, isNamedIcon, isPlacedIconName, readIcon, readIconTint, withIcon, withIconTint };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/icons/model.ts"],"sourcesContent":["import { readPluginData, withPluginData } from '../plugin-data/field'\nimport { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { SceneNode } from '../types'\nimport type { Icon, IconPaint } from './schema'\n\n/** The icon a frame draws, or null when it is not an icon or its data is unreadable. */\nexport function readIcon(node: SceneNode): Icon | null {\n return readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.icon) ?? null\n}\n\n/** The node's plugin data with the icon set, or removed when null. */\nexport function withIcon(node: SceneNode, icon: Icon | null): SceneNode['pluginData'] {\n return withPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.icon, icon ?? undefined)\n}\n\n/**\n * Whether code can draw the icon from its name alone, as Iconify's components do. An icon with\n * options was drawn from a set of our own, such as a font at its axes, so it exports as the paths\n * it draws.\n */\nexport function isNamedIcon(icon: Icon): boolean {\n return icon.options === undefined\n}\n\n/** The layer name an icon is placed with: its name in the set, such as `cat` for `mdi:cat`. */\nexport function iconLayerName(name: string): string {\n return name.slice(name.indexOf(':') + 1)\n}\n\n/**\n * Whether `layerName` is the name an icon `name` was placed with, rather than one someone gave\n * it: `cat`, or `Icon / mdi:cat` as icons were named before.\n */\nexport function isPlacedIconName(layerName: string, name: string): boolean {\n return layerName === iconLayerName(name) || layerName === `Icon / ${name}`\n}\n\n/** The names of the icons among `nodes`, each once, in the order they are first met. */\nexport function iconNames(nodes: Iterable<SceneNode>): string[] {\n const names = new Set<string>()\n for (const node of nodes) {\n const icon = readIcon(node)\n if (icon) names.add(icon.name)\n }\n return [...names]\n}\n\n/** The paints of an icon path that its icon's color sets; none when it keeps its own colors. */\nexport function readIconTint(node: SceneNode): readonly IconPaint[] {\n return readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.iconTint) ?? []\n}\n\n/** The path's plugin data with its tinted paints, or removed when there are none. */\nexport function withIconTint(\n node: SceneNode,\n paints: readonly IconPaint[]\n): SceneNode['pluginData'] {\n return withPluginData(\n node.pluginData,\n PAIRDRAW_PLUGIN_DATA.iconTint,\n paints.length > 0 ? [...paints] : undefined\n )\n}\n"],"mappings":";;;;AAMA,SAAgB,SAAS,MAA8B;CACrD,OAAO,eAAe,KAAK,YAAY,qBAAqB,IAAI,KAAK;AACvE;;AAGA,SAAgB,SAAS,MAAiB,MAA4C;CACpF,OAAO,eAAe,KAAK,YAAY,qBAAqB,MAAM,QAAQ,KAAA,CAAS;AACrF;;;;;;AAOA,SAAgB,YAAY,MAAqB;CAC/C,OAAO,KAAK,YAAY,KAAA;AAC1B;;AAGA,SAAgB,cAAc,MAAsB;CAClD,OAAO,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI,CAAC;AACzC;;;;;AAMA,SAAgB,iBAAiB,WAAmB,MAAuB;CACzE,OAAO,cAAc,cAAc,IAAI,KAAK,cAAc,UAAU;AACtE;;AAGA,SAAgB,UAAU,OAAsC;CAC9D,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,OAAO,SAAS,IAAI;EAC1B,IAAI,MAAM,MAAM,IAAI,KAAK,IAAI;CAC/B;CACA,OAAO,CAAC,GAAG,KAAK;AAClB;;AAGA,SAAgB,aAAa,MAAuC;CAClE,OAAO,eAAe,KAAK,YAAY,qBAAqB,QAAQ,KAAK,CAAC;AAC5E;;AAGA,SAAgB,aACd,MACA,QACyB;CACzB,OAAO,eACL,KAAK,YACL,qBAAqB,UACrB,OAAO,SAAS,IAAI,CAAC,GAAG,MAAM,IAAI,KAAA,CACpC;AACF"}
|