@open-pencil/scene-graph 0.16.0 → 0.17.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow-caps.d.ts +35 -14
- package/dist/arrow-caps.d.ts.map +1 -1
- package/dist/arrow-caps.js +286 -55
- package/dist/arrow-caps.js.map +1 -1
- package/dist/asset-keys.d.ts +17 -0
- package/dist/asset-keys.d.ts.map +1 -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 +62 -0
- package/dist/behaviours/kinds.d.ts.map +1 -0
- package/dist/{chunks/behaviours → behaviours}/kinds.js +76 -75
- 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 +43 -0
- package/dist/behaviours/layers.js.map +1 -0
- package/dist/behaviours/model.d.ts +48 -0
- package/dist/behaviours/model.d.ts.map +1 -0
- package/dist/behaviours/model.js +156 -0
- package/dist/behaviours/model.js.map +1 -0
- package/dist/behaviours/schema.d.ts +228 -0
- package/dist/behaviours/schema.d.ts.map +1 -0
- package/dist/behaviours/schema.js +86 -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/{chunks/behaviours → behaviours}/spec.js +6 -29
- package/dist/behaviours/spec.js.map +1 -0
- package/dist/bindings.js +26 -0
- package/dist/bindings.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.map +1 -0
- package/dist/checkpoint.d.ts +42 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +249 -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 +17 -0
- package/dist/color/contrast.d.ts.map +1 -0
- package/dist/{chunks/color → color}/contrast.js +2 -24
- 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/{chunks/comments → comments}/document.js +2 -1
- 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/{chunks/comments → comments}/merge.js +1 -1
- 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/{chunks/comments/list.js → comments/threads.js} +3 -53
- 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 +4 -0
- package/dist/components/index.js +4 -0
- package/dist/components/properties.d.ts +32 -0
- package/dist/components/properties.d.ts.map +1 -0
- package/dist/components/properties.js +180 -0
- package/dist/components/properties.js.map +1 -0
- package/dist/components/variants.d.ts +33 -0
- package/dist/components/variants.d.ts.map +1 -0
- package/dist/components/variants.js +58 -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 +47 -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 +156 -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 +208 -0
- package/dist/connectors/sublayers.js.map +1 -0
- package/dist/constants.d.ts +11 -2
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +25 -1
- package/dist/constants.js.map +1 -0
- package/dist/coordinate.d.ts +94 -2
- package/dist/coordinate.d.ts.map +1 -0
- package/dist/coordinate.js +268 -1
- package/dist/coordinate.js.map +1 -0
- package/dist/copy.d.ts +49 -2
- package/dist/copy.d.ts.map +1 -0
- package/dist/copy.js +264 -2
- package/dist/copy.js.map +1 -0
- package/dist/css/blend.d.ts +11 -0
- package/dist/css/blend.d.ts.map +1 -0
- package/dist/css/blend.js +30 -0
- package/dist/css/blend.js.map +1 -0
- package/dist/css/grid.d.ts +7 -0
- package/dist/css/grid.d.ts.map +1 -0
- package/dist/{chunks/css → css}/grid.js +2 -33
- package/dist/css/grid.js.map +1 -0
- package/dist/css/index.d.ts +7 -0
- package/dist/css/index.js +7 -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/cubic.d.ts +7 -0
- package/dist/cubic.d.ts.map +1 -0
- package/dist/cubic.js +17 -0
- package/dist/cubic.js.map +1 -0
- package/dist/events.js.map +1 -0
- package/dist/export-format.d.ts +25 -0
- package/dist/export-format.d.ts.map +1 -0
- package/dist/export-format.js +47 -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.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 +64 -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 +270 -0
- package/dist/figjam/palette.d.ts.map +1 -0
- package/dist/figjam/palette.js +439 -0
- package/dist/figjam/palette.js.map +1 -0
- package/dist/figjam/text.d.ts +70 -0
- package/dist/figjam/text.d.ts.map +1 -0
- package/dist/figjam/text.js +95 -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 +44 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +58 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/kind.d.ts +27 -0
- package/dist/generated/kind.d.ts.map +1 -0
- package/dist/generated/shape-with-text.d.ts +43 -0
- package/dist/generated/shape-with-text.d.ts.map +1 -0
- package/dist/generated/shape-with-text.js +135 -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 +233 -0
- package/dist/generated/sticky.js.map +1 -0
- package/dist/geometry.d.ts +89 -2
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +306 -2
- package/dist/geometry.js.map +1 -0
- package/dist/gradient.d.ts +9 -2
- package/dist/gradient.d.ts.map +1 -1
- package/dist/gradient.js +13 -1
- package/dist/gradient.js.map +1 -1
- package/dist/graph.d.ts +178 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +625 -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/{chunks/group-bounds.js → group-bounds.js} +56 -14
- package/dist/group-bounds.js.map +1 -0
- package/dist/guides.d.ts +21 -2
- package/dist/guides.d.ts.map +1 -0
- package/dist/guides.js +5 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts +48 -2
- package/dist/hit-test.d.ts.map +1 -0
- package/dist/hit-test.js +75 -57
- package/dist/hit-test.js.map +1 -1
- package/dist/icons/glyph.d.ts +22 -0
- package/dist/icons/glyph.d.ts.map +1 -0
- package/dist/{chunks/icons → icons}/glyph.js +2 -40
- 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 -2
- package/dist/images.d.ts.map +1 -0
- package/dist/images.js +67 -9
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +5 -7
- package/dist/index.js +5 -23
- 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 +161 -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 +90 -0
- package/dist/instances/fields.js.map +1 -0
- package/dist/instances/index.d.ts +38 -0
- package/dist/instances/index.d.ts.map +1 -0
- package/dist/instances/index.js +180 -0
- package/dist/instances/index.js.map +1 -0
- package/dist/instances/kept-overrides.js +204 -0
- package/dist/instances/kept-overrides.js.map +1 -0
- package/dist/instances/main-component.d.ts +13 -0
- package/dist/instances/main-component.d.ts.map +1 -0
- package/dist/instances/main-component.js +50 -0
- package/dist/instances/main-component.js.map +1 -0
- package/dist/instances/overrides.d.ts +51 -0
- package/dist/instances/overrides.d.ts.map +1 -0
- package/dist/instances/overrides.js +158 -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/source-walk.js +31 -0
- package/dist/instances/source-walk.js.map +1 -0
- package/dist/instances/swap.js +288 -0
- package/dist/instances/swap.js.map +1 -0
- package/dist/instances/sync.js +327 -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.js → layout/index.js} +4 -3
- package/dist/layout/keywords.d.ts +26 -0
- package/dist/layout/keywords.d.ts.map +1 -0
- package/dist/layout/keywords.js +59 -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 -2
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +119 -1
- 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/node-defaults.d.ts +22 -2
- package/dist/node-defaults.d.ts.map +1 -0
- package/dist/node-defaults.js +254 -2
- package/dist/node-defaults.js.map +1 -0
- package/dist/outline/flatten.d.ts +15 -0
- package/dist/outline/flatten.d.ts.map +1 -0
- package/dist/outline/flatten.js +189 -0
- package/dist/outline/flatten.js.map +1 -0
- package/dist/outline/heads.js +34 -0
- package/dist/outline/heads.js.map +1 -0
- package/dist/outline/hit.d.ts +21 -0
- package/dist/outline/hit.d.ts.map +1 -0
- package/dist/outline/hit.js +276 -0
- package/dist/outline/hit.js.map +1 -0
- package/dist/outline/index.d.ts +5 -0
- package/dist/outline/index.js +5 -0
- package/dist/outline/point.d.ts +16 -0
- package/dist/outline/point.d.ts.map +1 -0
- package/dist/outline/point.js +42 -0
- package/dist/outline/point.js.map +1 -0
- package/dist/outline/shapes.d.ts +35 -0
- package/dist/outline/shapes.d.ts.map +1 -0
- package/dist/outline/shapes.js +181 -0
- package/dist/outline/shapes.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 +77 -0
- package/dist/paints/schema.d.ts.map +1 -0
- package/dist/paints/schema.js +56 -0
- package/dist/paints/schema.js.map +1 -0
- package/dist/parse-path.d.ts +9 -1
- package/dist/parse-path.d.ts.map +1 -1
- package/dist/parse-path.js +39 -2
- package/dist/parse-path.js.map +1 -1
- 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 +73 -0
- package/dist/plugin-data/field.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +143 -0
- package/dist/plugin-data/fields.d.ts.map +1 -0
- package/dist/plugin-data/fields.js +168 -0
- package/dist/plugin-data/fields.js.map +1 -0
- package/dist/plugin-data/index.d.ts +3 -0
- package/dist/plugin-data/index.js +3 -0
- package/dist/polygon.d.ts +4 -2
- package/dist/polygon.d.ts.map +1 -1
- package/dist/polygon.js +17 -2
- package/dist/polygon.js.map +1 -1
- package/dist/preview.d.ts +12 -2
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +62 -1
- package/dist/preview.js.map +1 -0
- package/dist/{primitives2.d.ts → primitives/index.d.ts} +4 -3
- 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.js +24 -1
- package/dist/random.js.map +1 -0
- package/dist/resize.d.ts +6 -4
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +287 -2
- 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 +148 -0
- package/dist/scaling/node.js.map +1 -0
- package/dist/scaling/tree.d.ts +7 -0
- package/dist/scaling/tree.d.ts.map +1 -0
- package/dist/scaling/tree.js +47 -0
- package/dist/scaling/tree.js.map +1 -0
- package/dist/shaders/index.d.ts +4 -0
- package/dist/shaders/index.js +4 -0
- package/dist/shaders/model.d.ts +41 -0
- package/dist/shaders/model.d.ts.map +1 -0
- package/dist/shaders/model.js +71 -0
- package/dist/shaders/model.js.map +1 -0
- package/dist/shaders/schema.d.ts +41 -0
- package/dist/shaders/schema.d.ts.map +1 -0
- package/dist/shaders/schema.js +36 -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 +51 -0
- package/dist/shared-styles.d.ts.map +1 -0
- package/dist/shared-styles.js +186 -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 +77 -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 +105 -0
- package/dist/slots/content.js.map +1 -0
- package/dist/slots/frames.d.ts +40 -0
- package/dist/slots/frames.d.ts.map +1 -0
- package/dist/slots/frames.js +118 -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 +21 -2
- package/dist/snap.d.ts.map +1 -0
- package/dist/snap.js +109 -1
- package/dist/snap.js.map +1 -0
- package/dist/source-metadata.js +10 -1
- 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 → text/direction.d.ts} +2 -2
- package/dist/text/direction.d.ts.map +1 -0
- package/dist/{text-direction.js → text/direction.js} +1 -1
- 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 +24 -0
- package/dist/text/lengths.d.ts.map +1 -0
- package/dist/text/lengths.js +49 -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 → text/picture.d.ts} +3 -4
- package/dist/text/picture.d.ts.map +1 -0
- package/dist/text/picture.js +38 -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/copied.d.ts +14 -0
- package/dist/transfer/copied.d.ts.map +1 -0
- package/dist/transfer/copied.js +52 -0
- package/dist/transfer/copied.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 +8 -0
- package/dist/transfer/index.js +8 -0
- package/dist/transfer/nodes.d.ts +14 -0
- package/dist/transfer/nodes.d.ts.map +1 -0
- package/dist/transfer/nodes.js +78 -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 +195 -2007
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +89 -2
- package/dist/types.js.map +1 -0
- package/dist/undo.d.ts +93 -2
- package/dist/undo.d.ts.map +1 -0
- package/dist/undo.js +235 -1
- package/dist/undo.js.map +1 -0
- package/dist/variables/bindings.d.ts +83 -0
- package/dist/variables/bindings.d.ts.map +1 -0
- package/dist/variables/bindings.js +314 -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 +43 -0
- package/dist/variables/fields.d.ts.map +1 -0
- package/dist/variables/fields.js +104 -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 +238 -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 +16 -0
- package/dist/variables/text.d.ts.map +1 -0
- package/dist/variables/text.js +49 -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/vector-network.d.ts +65 -2
- package/dist/vector-network.d.ts.map +1 -0
- package/dist/vector-network.js +375 -2
- package/dist/vector-network.js.map +1 -0
- package/package.json +303 -137
- package/src/arrow-caps.ts +279 -62
- package/src/behaviours/index.ts +5 -0
- package/src/behaviours/kinds.ts +51 -34
- package/src/behaviours/layers.ts +5 -3
- package/src/behaviours/model.ts +25 -22
- package/src/behaviours/schema.ts +64 -13
- package/src/behaviours/spec.ts +11 -50
- package/src/bindings.ts +11 -2
- package/src/checkpoint.ts +252 -5
- package/src/clipping.ts +112 -0
- package/src/color/index.ts +1 -0
- package/src/color/schema.ts +10 -0
- package/src/comments/document.ts +1 -1
- package/src/comments/index.ts +5 -0
- package/src/comments/schema.ts +51 -0
- package/src/comments/threads.ts +1 -1
- package/src/components/exposure.ts +1 -1
- package/src/components/index.ts +8 -0
- package/src/components/properties.ts +94 -4
- package/src/components/variants.ts +52 -31
- 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 +49 -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 +141 -0
- package/src/connectors/route.ts +148 -0
- package/src/connectors/sides.ts +94 -0
- package/src/connectors/sublayers.ts +203 -0
- package/src/coordinate.ts +10 -3
- package/src/copy.ts +71 -31
- package/src/css/blend.ts +27 -0
- package/src/css/index.ts +2 -0
- package/src/css/text.ts +84 -0
- package/src/cubic.ts +14 -0
- package/src/export-format.ts +30 -1
- package/src/fields/appearance.ts +35 -0
- package/src/fields/index.ts +4 -0
- package/src/fields/layout.ts +48 -0
- package/src/fields/text.ts +32 -1
- package/src/fig-compression.ts +9 -0
- package/src/figjam/index.ts +2 -0
- package/src/figjam/palette.ts +473 -0
- package/src/figjam/text.ts +83 -0
- package/src/font-style.ts +58 -14
- package/src/generated/index.ts +76 -0
- package/src/generated/kind.ts +24 -0
- package/src/generated/shape-with-text.ts +157 -0
- package/src/generated/sticky.ts +213 -0
- package/src/geometry.ts +102 -312
- package/src/gradient.ts +14 -0
- package/src/graph.ts +849 -0
- package/src/group-bounds.ts +59 -12
- package/src/guides.ts +6 -1
- package/src/hit-test.ts +118 -74
- package/src/icons/index.ts +3 -0
- package/src/icons/model.ts +9 -0
- package/src/icons/schema.ts +19 -3
- package/src/ids.ts +34 -0
- package/src/images.ts +71 -8
- package/src/index.ts +2 -976
- package/src/instances/assignments.ts +116 -0
- package/src/instances/content-size.ts +23 -2
- package/src/instances/copies.ts +7 -10
- package/src/instances/cycles.ts +1 -1
- package/src/instances/fields.ts +47 -92
- package/src/{instances.ts → instances/index.ts} +69 -44
- package/src/instances/kept-overrides.ts +280 -0
- package/src/instances/main-component.ts +55 -1
- package/src/{instance-overrides.ts → instances/overrides.ts} +58 -2
- package/src/instances/placement.ts +1 -1
- package/src/instances/source-walk.ts +3 -9
- package/src/instances/swap.ts +451 -0
- package/src/instances/sync.ts +166 -177
- package/src/instances/vector-geometry.ts +3 -3
- package/src/layout/aspect-ratio.ts +1 -1
- package/src/layout/sizing.ts +1 -1
- package/src/layout/writes.ts +59 -0
- package/src/matrix.ts +1 -1
- package/src/mutation-impact.ts +1 -1
- package/src/node-defaults.ts +43 -3
- package/src/outline/flatten.ts +190 -0
- package/src/outline/heads.ts +52 -0
- package/src/outline/hit.ts +369 -0
- package/src/outline/index.ts +4 -0
- package/src/outline/point.ts +59 -0
- package/src/outline/shapes.ts +207 -0
- package/src/paints/index.ts +1 -0
- package/src/paints/schema.ts +67 -0
- package/src/parse-path.ts +49 -4
- package/src/plugin-data/fields.ts +69 -77
- package/src/plugin-data/index.ts +2 -0
- package/src/polygon.ts +17 -0
- package/src/preview.ts +1 -1
- package/src/{primitives.ts → primitives/index.ts} +2 -0
- package/src/primitives/schema.ts +14 -0
- package/src/resize.ts +32 -6
- package/src/scaling/node.ts +10 -6
- package/src/scaling/tree.ts +2 -1
- package/src/shaders/index.ts +3 -0
- package/src/shaders/schema.ts +3 -3
- 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 +169 -17
- package/src/slots/authoring.ts +1 -1
- package/src/slots/content.ts +10 -5
- package/src/slots/frames.ts +12 -10
- package/src/slots/index.ts +4 -0
- package/src/slots/limits.ts +1 -1
- package/src/snap.ts +3 -1
- 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/index.ts +3 -0
- package/src/text/lengths.ts +44 -0
- package/src/text/overflow.ts +12 -0
- package/src/text/picture.ts +0 -4
- package/src/text/schema.ts +7 -0
- package/src/transfer/apply.ts +1 -1
- package/src/transfer/copied.ts +72 -0
- package/src/transfer/history.ts +1 -1
- package/src/transfer/index.ts +1 -0
- package/src/transfer/nodes.ts +18 -19
- package/src/transfer/plan.ts +1 -1
- package/src/transfer/remove.ts +1 -1
- package/src/transfer/validation.ts +1 -1
- package/src/transfer/variables.ts +7 -6
- package/src/types.ts +246 -13
- package/src/undo.ts +64 -2
- package/src/variables/bindings.ts +166 -66
- package/src/variables/corners.ts +39 -0
- package/src/variables/fields.ts +83 -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.ts → variables/index.ts} +86 -146
- package/src/variables/resolution.ts +293 -0
- package/src/variables/schema.ts +31 -0
- package/src/variables/text.ts +51 -0
- package/src/variables/token.ts +27 -1
- package/src/variables/value.ts +92 -0
- package/src/vector-network.ts +263 -22
- package/dist/chunks/asset-keys.js.map +0 -1
- package/dist/chunks/behaviours/kinds.js.map +0 -1
- package/dist/chunks/behaviours/layers.js +0 -611
- package/dist/chunks/behaviours/layers.js.map +0 -1
- package/dist/chunks/behaviours/spec.js.map +0 -1
- package/dist/chunks/bindings.js +0 -18
- package/dist/chunks/bindings.js.map +0 -1
- package/dist/chunks/buffered-events.js.map +0 -1
- package/dist/chunks/checkpoint.js +0 -78
- package/dist/chunks/checkpoint.js.map +0 -1
- package/dist/chunks/color/contrast.js.map +0 -1
- package/dist/chunks/color/index.js +0 -1662
- package/dist/chunks/color/index.js.map +0 -1
- package/dist/chunks/comments/document.js.map +0 -1
- package/dist/chunks/comments/list.js.map +0 -1
- package/dist/chunks/comments/merge.js.map +0 -1
- package/dist/chunks/components/exposure.js +0 -2291
- package/dist/chunks/components/exposure.js.map +0 -1
- package/dist/chunks/components/variants.js +0 -32
- package/dist/chunks/components/variants.js.map +0 -1
- package/dist/chunks/coordinate.js +0 -385
- package/dist/chunks/coordinate.js.map +0 -1
- package/dist/chunks/css/grid.js.map +0 -1
- package/dist/chunks/css/index.js +0 -160
- package/dist/chunks/css/index.js.map +0 -1
- package/dist/chunks/events.js.map +0 -1
- package/dist/chunks/fields/geometry.js.map +0 -1
- package/dist/chunks/font-style.js +0 -96
- package/dist/chunks/font-style.js.map +0 -1
- package/dist/chunks/group-bounds.js.map +0 -1
- package/dist/chunks/icons/glyph.js.map +0 -1
- package/dist/chunks/index.js +0 -2430
- package/dist/chunks/index.js.map +0 -1
- package/dist/color.d.ts +0 -78
- package/dist/color.d.ts.map +0 -1
- package/dist/color.js +0 -3
- package/dist/constants2.d.ts +0 -11
- package/dist/constants2.d.ts.map +0 -1
- package/dist/css.d.ts +0 -39
- package/dist/css.d.ts.map +0 -1
- package/dist/css.js +0 -3
- package/dist/images2.d.ts +0 -16
- package/dist/images2.d.ts.map +0 -1
- package/dist/instances.d.ts +0 -2
- package/dist/instances.js +0 -2
- package/dist/layout.d.ts +0 -2
- package/dist/matrix2.d.ts +0 -16
- package/dist/matrix2.d.ts.map +0 -1
- package/dist/primitives.d.ts +0 -2
- package/dist/primitives.js +0 -0
- package/dist/primitives2.d.ts.map +0 -1
- package/dist/text-direction.d.ts.map +0 -1
- package/dist/text-direction.js.map +0 -1
- package/dist/text-picture.d.ts.map +0 -1
- package/dist/text-picture.js +0 -2
- package/dist/text.d.ts +0 -2
- package/dist/text.js +0 -3
- package/dist/types2.d.ts +0 -2
- package/dist/undo2.d.ts +0 -73
- package/dist/undo2.d.ts.map +0 -1
- package/dist/variables.d.ts +0 -2
- package/dist/variables.js +0 -2
- /package/dist/{chunks/asset-keys.js → asset-keys.js} +0 -0
- /package/dist/{chunks/buffered-events.js → buffered-events.js} +0 -0
- /package/dist/{chunks/events.js → events.js} +0 -0
- /package/dist/{chunks/fields → fields}/geometry.js +0 -0
package/dist/hit-test.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Matrix from "./matrix.js";
|
|
2
|
+
import { getWorldMatrix } from "./coordinate.js";
|
|
3
|
+
import { hitsConnectorLine } from "./connectors/hit.js";
|
|
4
|
+
import { hitsShape, isHitPaint, strokeReach } from "./outline/hit.js";
|
|
2
5
|
//#region src/hit-test.ts
|
|
3
6
|
const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
4
7
|
"CANVAS",
|
|
@@ -10,8 +13,9 @@ const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
|
10
13
|
"INSTANCE"
|
|
11
14
|
]);
|
|
12
15
|
const OPAQUE_CONTAINER_TYPES = /* @__PURE__ */ new Set(["COMPONENT", "INSTANCE"]);
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
/** Whether a container's own paints show, so its empty area is drawn (see `isHitPaint`). */
|
|
17
|
+
function showsPaint(node) {
|
|
18
|
+
return node.fills.some(isHitPaint) || node.strokes.some(isHitPaint);
|
|
15
19
|
}
|
|
16
20
|
function isTopLevel(graph, node) {
|
|
17
21
|
const parent = node.parentId ? graph.nodes.get(node.parentId) : void 0;
|
|
@@ -46,96 +50,117 @@ function containsPoint(px, py, node, graph, transformCache, pad = 0) {
|
|
|
46
50
|
const [localX, localY] = Matrix.mapPoints(inv, [px, py]);
|
|
47
51
|
return localX >= -pad && localX <= node.width + pad && localY >= -pad && localY <= node.height + pad;
|
|
48
52
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
function walkOf(deep, pad = 0, instanceBodies = false) {
|
|
54
|
+
return {
|
|
55
|
+
deep,
|
|
56
|
+
pad,
|
|
57
|
+
instanceBodies,
|
|
58
|
+
transformCache: /* @__PURE__ */ new Map()
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** Whether a container's empty area under the point takes a click reaching past containers. */
|
|
62
|
+
function takesEmptyArea(graph, node, walk) {
|
|
63
|
+
if (node.type === "COMPONENT" || showsPaint(node) || ownsItsEmptyArea(graph, node)) return true;
|
|
64
|
+
return walk.instanceBodies && node.type === "INSTANCE";
|
|
54
65
|
}
|
|
55
|
-
function hitTestTransparentContainer(graph, px, py, child,
|
|
66
|
+
function hitTestTransparentContainer(graph, px, py, child, walk) {
|
|
56
67
|
if (child.type === "GROUP") {
|
|
57
|
-
if (!containsPoint(px, py, child, graph, transformCache, pad)) return null;
|
|
58
|
-
const childHit = hitTestChildren(graph, px, py,
|
|
59
|
-
|
|
60
|
-
return containsPoint(px, py, child, graph, transformCache) ? child : null;
|
|
68
|
+
if (!containsPoint(px, py, child, graph, walk.transformCache, walk.pad)) return null;
|
|
69
|
+
const childHit = hitTestChildren(graph, px, py, child.id, walk);
|
|
70
|
+
return childHit ? walk.deep ? childHit : child : null;
|
|
61
71
|
}
|
|
62
|
-
const childHit = hitTestChildren(graph, px, py,
|
|
72
|
+
const childHit = hitTestChildren(graph, px, py, child.id, walk);
|
|
63
73
|
if (childHit) {
|
|
64
74
|
if (child.locked) return child;
|
|
65
75
|
return childHit;
|
|
66
76
|
}
|
|
67
|
-
if (containsPoint(px, py, child, graph, transformCache) && (
|
|
77
|
+
if (containsPoint(px, py, child, graph, walk.transformCache) && takesEmptyArea(graph, child, walk)) return child;
|
|
68
78
|
return null;
|
|
69
79
|
}
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
* each leaf layer's box, as Figma takes a click a few screen pixels outside a shape.
|
|
73
|
-
*/
|
|
74
|
-
function hitTestChildren(graph, px, py, parentId, deep = false, transformCache = /* @__PURE__ */ new Map(), pad = 0) {
|
|
80
|
+
/** The topmost layer under the point among a container's children. */
|
|
81
|
+
function hitTestChildren(graph, px, py, parentId, walk) {
|
|
75
82
|
const parent = graph.nodes.get(parentId);
|
|
76
83
|
if (!parent) return null;
|
|
84
|
+
const { transformCache, pad } = walk;
|
|
77
85
|
if (parent.clipsContent) {
|
|
78
86
|
if (!containsPoint(px, py, parent, graph, transformCache)) return null;
|
|
79
87
|
}
|
|
80
88
|
for (let i = parent.childIds.length - 1; i >= 0; i--) {
|
|
81
|
-
const
|
|
82
|
-
const child = graph.nodes.get(childId);
|
|
89
|
+
const child = graph.nodes.get(parent.childIds[i]);
|
|
83
90
|
if (!child || child.internalOnly || !child.visible) continue;
|
|
84
91
|
if (CONTAINER_TYPES.has(child.type)) {
|
|
85
|
-
if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {
|
|
86
|
-
|
|
87
|
-
if (hit) return hit;
|
|
92
|
+
if (OPAQUE_CONTAINER_TYPES.has(child.type) && !walk.deep) {
|
|
93
|
+
if (containsPoint(px, py, child, graph, transformCache)) return child;
|
|
88
94
|
continue;
|
|
89
95
|
}
|
|
90
|
-
const hit = hitTestTransparentContainer(graph, px, py, child,
|
|
96
|
+
const hit = hitTestTransparentContainer(graph, px, py, child, walk);
|
|
91
97
|
if (hit) return hit;
|
|
92
98
|
continue;
|
|
93
99
|
}
|
|
94
|
-
if (
|
|
100
|
+
if (child.type === "CONNECTOR") {
|
|
101
|
+
if (hitsConnectorLine(graph, child, px, py, pad)) return child;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (hitsLeaf(graph, px, py, child, transformCache, pad)) return child;
|
|
95
105
|
}
|
|
96
106
|
return null;
|
|
97
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Whether a click lands on a leaf layer: on what its paints draw, as Figma tests shapes (see
|
|
110
|
+
* `hitsShape`), or on its box for layers without an outline to test, such as text.
|
|
111
|
+
*/
|
|
112
|
+
function hitsLeaf(graph, px, py, node, transformCache, pad) {
|
|
113
|
+
if (!containsPoint(px, py, node, graph, transformCache, pad + strokeReach(node))) return false;
|
|
114
|
+
return hitsShape(graph, node, px, py, pad) ?? containsPoint(px, py, node, graph, transformCache, pad);
|
|
115
|
+
}
|
|
98
116
|
function hitTest(graph, px, py, scopeId) {
|
|
99
|
-
return hitTestChildren(graph, px, py, scopeId ?? graph.rootId, false);
|
|
117
|
+
return hitTestChildren(graph, px, py, scopeId ?? graph.rootId, walkOf(false));
|
|
100
118
|
}
|
|
101
119
|
function hitTestDeep(graph, px, py, scopeId, pad = 0) {
|
|
102
|
-
return hitTestChildren(graph, px, py, scopeId ?? graph.rootId, true,
|
|
120
|
+
return hitTestChildren(graph, px, py, scopeId ?? graph.rootId, walkOf(true, pad));
|
|
103
121
|
}
|
|
104
122
|
/**
|
|
105
123
|
* A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a
|
|
106
|
-
* section) or a section that holds layers, and a component set.
|
|
124
|
+
* section) or a section that holds layers, and a component set. On a FigJam board frames stay
|
|
125
|
+
* closed (`framesOpen` false): a click inside one selects the frame.
|
|
107
126
|
*/
|
|
108
|
-
function opensByItself(graph, node) {
|
|
127
|
+
function opensByItself(graph, node, framesOpen = true) {
|
|
109
128
|
if (node.type === "COMPONENT_SET") return true;
|
|
110
129
|
if (node.childIds.length === 0) return false;
|
|
111
130
|
if (node.type === "SECTION") return true;
|
|
112
|
-
return node.type === "FRAME" && isTopLevel(graph, node);
|
|
131
|
+
return framesOpen && node.type === "FRAME" && isTopLevel(graph, node);
|
|
113
132
|
}
|
|
114
133
|
/**
|
|
115
134
|
* The topmost frame among a container's children whose bounds hold the point, filled or not: in
|
|
116
135
|
* Figma a click on the empty area of a frame inside an open container, or of an empty frame on the
|
|
117
136
|
* page or in a section, selects that frame, while a deep (⌘) click looks through it.
|
|
118
137
|
*/
|
|
119
|
-
function frameChildAt(graph, container, px, py) {
|
|
138
|
+
function frameChildAt(graph, container, px, py, framesOpen = true) {
|
|
120
139
|
const transformCache = /* @__PURE__ */ new Map();
|
|
121
140
|
for (let i = container.childIds.length - 1; i >= 0; i--) {
|
|
122
141
|
const child = graph.nodes.get(container.childIds[i]);
|
|
123
142
|
if (!child || child.internalOnly || !child.visible || child.type !== "FRAME") continue;
|
|
124
|
-
if (opensByItself(graph, child) && !ownsItsEmptyArea(graph, child)) continue;
|
|
143
|
+
if (opensByItself(graph, child, framesOpen) && !ownsItsEmptyArea(graph, child)) continue;
|
|
125
144
|
if (containsPoint(px, py, child, graph, transformCache)) return child;
|
|
126
145
|
}
|
|
127
146
|
return null;
|
|
128
147
|
}
|
|
129
148
|
/**
|
|
130
|
-
* The containers the selection opens: every ancestor of a selected layer inside the scope,
|
|
131
|
-
*
|
|
132
|
-
*
|
|
149
|
+
* The containers the selection opens: every ancestor of a selected layer inside the scope, so a
|
|
150
|
+
* click reaches the siblings of selected layers, and a selected container itself, so hover and a
|
|
151
|
+
* read-only click reach the layer under the point. A plain press inside a selected frame still
|
|
152
|
+
* drags the frame, as in Figma, which `pressesSelection` in the Vue input decides. A selected group
|
|
153
|
+
* or boolean stays closed: clicking inside it keeps it selected.
|
|
133
154
|
*/
|
|
134
|
-
function openedBySelection(graph, selectedIds, scopeId) {
|
|
155
|
+
function openedBySelection(graph, selectedIds, scopeId, framesOpen, enteredId) {
|
|
135
156
|
const ancestors = /* @__PURE__ */ new Set();
|
|
157
|
+
for (let id = enteredId; id && id !== scopeId && !ancestors.has(id);) {
|
|
158
|
+
ancestors.add(id);
|
|
159
|
+
id = graph.nodes.get(id)?.parentId ?? null;
|
|
160
|
+
}
|
|
136
161
|
for (const id of selectedIds) {
|
|
137
162
|
const node = graph.nodes.get(id);
|
|
138
|
-
if (node && node.childIds.length > 0 && node.type !== "GROUP" && node.type !== "BOOLEAN_OPERATION") ancestors.add(id);
|
|
163
|
+
if (node && node.childIds.length > 0 && node.type !== "GROUP" && node.type !== "BOOLEAN_OPERATION" && (framesOpen || node.type !== "FRAME" || !isTopLevel(graph, node))) ancestors.add(id);
|
|
139
164
|
let parentId = node?.parentId;
|
|
140
165
|
while (parentId && parentId !== scopeId && !ancestors.has(parentId)) {
|
|
141
166
|
ancestors.add(parentId);
|
|
@@ -144,48 +169,41 @@ function openedBySelection(graph, selectedIds, scopeId) {
|
|
|
144
169
|
}
|
|
145
170
|
return ancestors;
|
|
146
171
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
* layers and component sets are open, and so is every ancestor of the selection, so clicks reach
|
|
151
|
-
* the siblings of selected layers. Where every layer under the point is open, a container opened
|
|
152
|
-
* by the selection is selected, so is a top-level frame with auto layout, and a plain top-level
|
|
153
|
-
* frame or a section is not.
|
|
154
|
-
*/
|
|
155
|
-
function hitTestSelectable(graph, px, py, scopeId, selectedIds, pad = 0) {
|
|
156
|
-
const deepest = hitTestChildren(graph, px, py, scopeId, true, /* @__PURE__ */ new Map(), pad);
|
|
172
|
+
function hitTestSelectable(graph, px, py, scopeId, selectedIds, options = {}) {
|
|
173
|
+
const { pad = 0, framesOpen = true, enteredId = null } = options;
|
|
174
|
+
const deepest = hitTestChildren(graph, px, py, scopeId, walkOf(true, pad, true));
|
|
157
175
|
if (!deepest) {
|
|
158
176
|
const scope = graph.nodes.get(scopeId);
|
|
159
|
-
return scope ? frameChildAt(graph, scope, px, py) : null;
|
|
177
|
+
return scope ? frameChildAt(graph, scope, px, py, framesOpen) : null;
|
|
160
178
|
}
|
|
161
179
|
const chain = [];
|
|
162
180
|
for (let node = deepest; node && node.id !== scopeId;) {
|
|
163
181
|
chain.unshift(node);
|
|
164
182
|
node = node.parentId ? graph.nodes.get(node.parentId) : void 0;
|
|
165
183
|
}
|
|
166
|
-
const opened = openedBySelection(graph, selectedIds, scopeId);
|
|
184
|
+
const opened = openedBySelection(graph, selectedIds, scopeId, framesOpen, enteredId);
|
|
167
185
|
for (const node of chain) {
|
|
168
186
|
if (node.locked) return node;
|
|
169
|
-
if (!opened.has(node.id) && !opensByItself(graph, node)) return node;
|
|
187
|
+
if (!opened.has(node.id) && !opensByItself(graph, node, framesOpen)) return node;
|
|
170
188
|
}
|
|
171
189
|
const last = chain.at(-1);
|
|
172
190
|
if (!last) return null;
|
|
173
|
-
const frame = frameChildAt(graph, last, px, py);
|
|
191
|
+
const frame = frameChildAt(graph, last, px, py, framesOpen);
|
|
174
192
|
if (frame) return frame;
|
|
175
193
|
if (ownsItsEmptyArea(graph, last)) return last;
|
|
176
|
-
return opened.has(last.id) && !opensByItself(graph, last) ? last : null;
|
|
194
|
+
return opened.has(last.id) && !opensByItself(graph, last, framesOpen) ? last : null;
|
|
177
195
|
}
|
|
178
196
|
/** Whether a click looks into this container rather than selecting it; see `hitTestSelectable`. */
|
|
179
|
-
function isOpenContainer(graph, nodeId) {
|
|
197
|
+
function isOpenContainer(graph, nodeId, framesOpen = true) {
|
|
180
198
|
const node = graph.nodes.get(nodeId);
|
|
181
|
-
return node !== void 0 && opensByItself(graph, node);
|
|
199
|
+
return node !== void 0 && opensByItself(graph, node, framesOpen);
|
|
182
200
|
}
|
|
183
201
|
/**
|
|
184
202
|
* The innermost open container under the point when every layer there is open: a marquee starting
|
|
185
203
|
* here selects that container's layers, as in Figma.
|
|
186
204
|
*/
|
|
187
205
|
function hitTestOpenContainer(graph, px, py, scopeId) {
|
|
188
|
-
const deepest = hitTestChildren(graph, px, py, scopeId, true);
|
|
206
|
+
const deepest = hitTestChildren(graph, px, py, scopeId, walkOf(true));
|
|
189
207
|
for (let node = deepest ?? void 0; node && node.id !== scopeId;) {
|
|
190
208
|
if (!opensByItself(graph, node) || ownsItsEmptyArea(graph, node)) return null;
|
|
191
209
|
node = node.parentId ? graph.nodes.get(node.parentId) : void 0;
|
package/dist/hit-test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import type { SceneGraph, SceneNode, NodeType } from './'\nimport { getWorldMatrix } from './coordinate'\nimport Matrix from './matrix'\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 (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\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":";;AAIA,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,OAAO,IAAI;AACtF;AAEA,SAAS,uBACP,MACA,OACA,OACS;CACT,MAAM,SAAS,MAAM,IAAI,KAAK,EAAE;CAChC,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,MAAM,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;CAC9D,MAAM,cACJ,KAAK,aAAa,KAClB,KAAK,SACL,KAAK,UACJ,SAAS,uBAAuB,QAAQ,OAAO,KAAK,IAAI;CAC3D,MAAM,IAAI,KAAK,IAAI,WAAW;CAC9B,OAAO;AACT;;AAGA,SAAS,cACP,IACA,IACA,MACA,OACA,gBACA,MAAM,GACG;CACT,IAAI,CAAC,uBAAuB,MAAM,OAAO,cAAc,GAAG;EACxD,MAAM,WAAW,MAAM,oBAAoB,KAAK,EAAE;EAClD,OACE,MAAM,SAAS,IAAI,OACnB,MAAM,SAAS,IAAI,KAAK,QAAQ,OAChC,MAAM,SAAS,IAAI,OACnB,MAAM,SAAS,IAAI,K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AW,MAAM,MAAM;CACrD,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,aAAa,OAAO,IAAI,IAAI,OAAO,YAAY,UAAU,OAAO,mBAAG,IAAI,IAAI,CAAC;AACrF"}
|
|
1
|
+
{"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import { hitsConnectorLine } from './connectors/hit'\nimport { getWorldMatrix } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport Matrix from './matrix'\nimport { hitsShape, isHitPaint, strokeReach } from './outline/hit'\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\n/** Whether a container's own paints show, so its empty area is drawn (see `isHitPaint`). */\nfunction showsPaint(node: SceneNode): boolean {\n return node.fills.some(isHitPaint) || node.strokes.some(isHitPaint)\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\n/**\n * How a walk down the layers takes a click. `deep` reaches past containers to the deepest layer;\n * `pad`, in canvas units, grows each leaf layer's box, as Figma takes a click a few screen pixels\n * outside a shape; `instanceBodies` lets a deep walk take an instance's empty area whatever its\n * fill, as a plain click does, where a ⌘-click counts only a fill that shows.\n */\ninterface HitWalk {\n deep: boolean\n pad: number\n instanceBodies: boolean\n transformCache: Map<string, boolean>\n}\n\nfunction walkOf(deep: boolean, pad = 0, instanceBodies = false): HitWalk {\n return { deep, pad, instanceBodies, transformCache: new Map() }\n}\n\n/** Whether a container's empty area under the point takes a click reaching past containers. */\nfunction takesEmptyArea(graph: SceneGraph, node: SceneNode, walk: HitWalk): boolean {\n // Figma counts an empty area only where a paint shows, except a main component's, which always\n // counts, and an instance's when the click is a plain one.\n if (node.type === 'COMPONENT' || showsPaint(node) || ownsItsEmptyArea(graph, node)) return true\n return walk.instanceBodies && node.type === 'INSTANCE'\n}\n\nfunction hitTestTransparentContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n walk: HitWalk\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, walk.transformCache, walk.pad)) return null\n // A group has no area of its own, as in Figma: between its layers the click falls through to\n // whatever lies under the group.\n const childHit = hitTestChildren(graph, px, py, child.id, walk)\n return childHit ? (walk.deep ? childHit : child) : null\n }\n\n const childHit = hitTestChildren(graph, px, py, child.id, walk)\n if (childHit) {\n if (child.locked) return child\n return childHit\n }\n\n if (\n containsPoint(px, py, child, graph, walk.transformCache) &&\n takesEmptyArea(graph, child, walk)\n )\n return child\n return null\n}\n\n/** The topmost layer under the point among a container's children. */\nfunction hitTestChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n walk: HitWalk\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n const { transformCache, pad } = walk\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 child = graph.nodes.get(parent.childIds[i])\n if (!child || child.internalOnly || !child.visible) continue\n if (CONTAINER_TYPES.has(child.type)) {\n if (OPAQUE_CONTAINER_TYPES.has(child.type) && !walk.deep) {\n // A plain click takes an instance or component anywhere in its box, with a fill or\n // without, as in Figma.\n if (containsPoint(px, py, child, graph, transformCache)) return child\n continue\n }\n const hit = hitTestTransparentContainer(graph, px, py, child, walk)\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 (hitsLeaf(graph, px, py, child, transformCache, pad)) return child\n }\n\n return null\n}\n\n/**\n * Whether a click lands on a leaf layer: on what its paints draw, as Figma tests shapes (see\n * `hitsShape`), or on its box for layers without an outline to test, such as text.\n */\nfunction hitsLeaf(\n graph: SceneGraph,\n px: number,\n py: number,\n node: SceneNode,\n transformCache: Map<string, boolean>,\n pad: number\n): boolean {\n if (!containsPoint(px, py, node, graph, transformCache, pad + strokeReach(node))) return false\n return (\n hitsShape(graph, node, px, py, pad) ?? containsPoint(px, py, node, graph, transformCache, pad)\n )\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, walkOf(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, walkOf(true, 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. On a FigJam board frames stay\n * closed (`framesOpen` false): a click inside one selects the frame.\n */\nfunction opensByItself(graph: SceneGraph, node: SceneNode, framesOpen = true): 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 framesOpen && 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 framesOpen = true\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, framesOpen) && !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, so a\n * click reaches the siblings of selected layers, and a selected container itself, so hover and a\n * read-only click reach the layer under the point. A plain press inside a selected frame still\n * drags the frame, as in Figma, which `pressesSelection` in the Vue input decides. A selected group\n * or boolean stays closed: clicking inside it keeps it selected.\n */\nfunction openedBySelection(\n graph: SceneGraph,\n selectedIds: ReadonlySet<string>,\n scopeId: string,\n framesOpen: boolean,\n enteredId: string | null\n): Set<string> {\n const ancestors = new Set<string>()\n // An entered container is open whatever its kind, so a double-click into a board's frame\n // reaches its layers; its ancestors open with it.\n for (let id = enteredId; id && id !== scopeId && !ancestors.has(id);) {\n ancestors.add(id)\n id = graph.nodes.get(id)?.parentId ?? null\n }\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 // A board's frame stays closed when selected: a click inside keeps it selected.\n (framesOpen || node.type !== 'FRAME' || !isTopLevel(graph, node))\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 interface SelectableHitOptions {\n /** Canvas units a leaf layer's box grows by, as Figma takes a click a few pixels outside. */\n pad?: number\n /** Whether top-level frames are looked into (a design) or selected whole (a board). */\n framesOpen?: boolean\n /** The container a double-click entered, open along with its ancestors. */\n enteredId?: string | null\n}\n\nexport function hitTestSelectable(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId: string,\n selectedIds: ReadonlySet<string>,\n options: SelectableHitOptions = {}\n): SceneNode | null {\n const { pad = 0, framesOpen = true, enteredId = null } = options\n // A plain click: the walk takes an instance's empty area whatever its fill.\n const deepest = hitTestChildren(graph, px, py, scopeId, walkOf(true, pad, true))\n if (!deepest) {\n const scope = graph.nodes.get(scopeId)\n return scope ? frameChildAt(graph, scope, px, py, framesOpen) : 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, framesOpen, enteredId)\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, framesOpen)) return node\n }\n const last = chain.at(-1)\n if (!last) return null\n const frame = frameChildAt(graph, last, px, py, framesOpen)\n if (frame) return frame\n if (ownsItsEmptyArea(graph, last)) return last\n return opened.has(last.id) && !opensByItself(graph, last, framesOpen) ? 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, framesOpen = true): boolean {\n const node = graph.nodes.get(nodeId)\n return node !== undefined && opensByItself(graph, node, framesOpen)\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, walkOf(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\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;;AAG1E,SAAS,WAAW,MAA0B;CAC5C,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,KAAK,QAAQ,KAAK,UAAU;AACpE;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,OAAO,IAAI;AACtF;AAEA,SAAS,uBACP,MACA,OACA,OACS;CACT,MAAM,SAAS,MAAM,IAAI,KAAK,EAAE;CAChC,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,MAAM,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;CAC9D,MAAM,cACJ,KAAK,aAAa,KAClB,KAAK,SACL,KAAK,UACJ,SAAS,uBAAuB,QAAQ,OAAO,KAAK,IAAI;CAC3D,MAAM,IAAI,KAAK,IAAI,WAAW;CAC9B,OAAO;AACT;;AAGA,SAAS,cACP,IACA,IACA,MACA,OACA,gBACA,MAAM,GACG;CACT,IAAI,CAAC,uBAAuB,MAAM,OAAO,cAAc,GAAG;EACxD,MAAM,WAAW,MAAM,oBAAoB,KAAK,EAAE;EAClD,OACE,MAAM,SAAS,IAAI,OACnB,MAAM,SAAS,IAAI,KAAK,QAAQ,OAChC,MAAM,SAAS,IAAI,OACnB,MAAM,SAAS,IAAI,KAAK,SAAS;CAErC;CAEA,MAAM,IAAI,e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K;EACpD,MAAM,UAAU,OAAO,SAAS;EAChC,IAAI,WAAW,IAAI,OAAO,GAAG;EAC7B,MAAM,QAAQ,MAAM,MAAM,IAAI,OAAO;EACrC,IAAI,CAAC,SAAS,MAAM,gBAAgB,CAAC,MAAM,WAAW,MAAM,QAAQ;EACpE,MAAM,SAAS,MAAM,MAAM,KAAK;EAChC,IAAI,CAAC,UAAU,CAAC,MAAM,YAAY,IAAI,MAAM,IAAI,GAAG;EAEnD,MAAM,SAAS,aAAa,OAAO,IAAI,IAAI,OAAO,YAAY,OAAO,cAAc;EACnF,IAAI,QAAQ,OAAO;EACnB,IAAI,UAAU,cAAc,IAAI,IAAI,OAAO,OAAO,cAAc,GAAG,OAAO;CAC5E;CAEA,OAAO;AACT;;;;;;;AAgBA,SAAgB,kBACd,OACA,IACA,IACA,YACA,SACA,UAA6B,CAAC,GACZ;CAClB,MAAM,QAAQ,MAAM,MAAM,IAAI,WAAW,MAAM,MAAM;CACrD,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,aAAa,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"}
|
|
@@ -1,43 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readIcon, readIconTint } from "./model.js";
|
|
2
2
|
import { omit } from "es-toolkit";
|
|
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, OPEN_PENCIL_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, OPEN_PENCIL_PLUGIN_DATA.icon, icon ?? void 0);
|
|
11
|
-
}
|
|
12
|
-
/** The layer name an icon is placed with: its name in the set, such as `cat` for `mdi:cat`. */
|
|
13
|
-
function iconLayerName(name) {
|
|
14
|
-
return name.slice(name.indexOf(":") + 1);
|
|
15
|
-
}
|
|
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
|
-
function isPlacedIconName(layerName, name) {
|
|
21
|
-
return layerName === iconLayerName(name) || layerName === `Icon / ${name}`;
|
|
22
|
-
}
|
|
23
|
-
/** The names of the icons among `nodes`, each once, in the order they are first met. */
|
|
24
|
-
function iconNames(nodes) {
|
|
25
|
-
const names = /* @__PURE__ */ new Set();
|
|
26
|
-
for (const node of nodes) {
|
|
27
|
-
const icon = readIcon(node);
|
|
28
|
-
if (icon) names.add(icon.name);
|
|
29
|
-
}
|
|
30
|
-
return [...names];
|
|
31
|
-
}
|
|
32
|
-
/** The paints of an icon path that its icon's color sets; none when it keeps its own colors. */
|
|
33
|
-
function readIconTint(node) {
|
|
34
|
-
return readPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.iconTint) ?? [];
|
|
35
|
-
}
|
|
36
|
-
/** The path's plugin data with its tinted paints, or removed when there are none. */
|
|
37
|
-
function withIconTint(node, paints) {
|
|
38
|
-
return withPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.iconTint, paints.length > 0 ? [...paints] : void 0);
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
3
|
//#region src/icons/glyph.ts
|
|
42
4
|
/** Digits kept of each proportion, so float noise does not read as an edit. */
|
|
43
5
|
const PRECISION = 1e3;
|
|
@@ -142,6 +104,6 @@ function isIconModified(graph, frame) {
|
|
|
142
104
|
return glyph !== void 0 && iconGlyph(graph, frame) !== glyph;
|
|
143
105
|
}
|
|
144
106
|
//#endregion
|
|
145
|
-
export { iconGlyph,
|
|
107
|
+
export { iconGlyph, isIconModified };
|
|
146
108
|
|
|
147
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;;;;;;AAOj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K,UAAU,WAAW,CAAC;AACzC;;;;;AAMA,SAAgB,eAAe,OAAkB,OAA2B;CAC1E,MAAM,QAAQ,SAAS,KAAK,CAAC,EAAE;CAC/B,OAAO,UAAU,KAAA,KAAa,UAAU,OAAO,KAAK,MAAM;AAC5D"}
|
|
@@ -0,0 +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 { OPEN_PENCIL_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, OPEN_PENCIL_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, OPEN_PENCIL_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, OPEN_PENCIL_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, OPEN_PENCIL_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 { OPEN_PENCIL_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, OPEN_PENCIL_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, OPEN_PENCIL_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, OPEN_PENCIL_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 OPEN_PENCIL_PLUGIN_DATA.iconTint,\n paints.length > 0 ? [...paints] : undefined\n )\n}\n"],"mappings":";;;;AAMA,SAAgB,SAAS,MAA8B;CACrD,OAAO,eAAe,KAAK,YAAY,wBAAwB,IAAI,KAAK;AAC1E;;AAGA,SAAgB,SAAS,MAAiB,MAA4C;CACpF,OAAO,eAAe,KAAK,YAAY,wBAAwB,MAAM,QAAQ,KAAA,CAAS;AACxF;;;;;;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,wBAAwB,QAAQ,KAAK,CAAC;AAC/E;;AAGA,SAAgB,aACd,MACA,QACyB;CACzB,OAAO,eACL,KAAK,YACL,wBAAwB,UACxB,OAAO,SAAS,IAAI,CAAC,GAAG,MAAM,IAAI,KAAA,CACpC;AACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/icons/schema.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* An icon's name in its set, `prefix:name`, as Iconify names icons. Names may hold dots, as SF
|
|
5
|
+
* Symbols' do (`house.fill`).
|
|
6
|
+
*/
|
|
7
|
+
declare const ICON_NAME: RegExp;
|
|
8
|
+
/**
|
|
9
|
+
* How an icon from a set we draw ourselves is drawn: a font's axes, such as Material Symbols'
|
|
10
|
+
* `wght` and `FILL`, or SF Symbols' weight and scale. Icons from Iconify have none.
|
|
11
|
+
*/
|
|
12
|
+
declare const iconOptionsSchema: v.RecordSchema<v.StringSchema<undefined>, v.UnionSchema<[v.NumberSchema<undefined>, v.StringSchema<undefined>], undefined>, undefined>;
|
|
13
|
+
type IconOptions = v.InferOutput<typeof iconOptionsSchema>;
|
|
14
|
+
declare const iconSchema: v.ObjectSchema<{
|
|
15
|
+
readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
16
|
+
/** A fingerprint of the glyph as placed, to tell when its paths were edited; see `iconGlyph`. */
|
|
17
|
+
readonly glyph: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Set for an icon drawn from one of our own sets rather than Iconify, so it is drawn again and
|
|
20
|
+
* exported as the paths it draws rather than by its name alone.
|
|
21
|
+
*/
|
|
22
|
+
readonly options: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnionSchema<[v.NumberSchema<undefined>, v.StringSchema<undefined>], undefined>, undefined>, undefined>;
|
|
23
|
+
}, undefined>;
|
|
24
|
+
/** An icon a frame draws. */
|
|
25
|
+
type Icon = v.InferOutput<typeof iconSchema>;
|
|
26
|
+
declare const ICON_PAINTS: readonly ["fill", "stroke"];
|
|
27
|
+
type IconPaint = (typeof ICON_PAINTS)[number];
|
|
28
|
+
declare const iconTintSchema: v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["fill", "stroke"], undefined>, undefined>, v.MinLengthAction<("fill" | "stroke")[], 1, undefined>]>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { ICON_NAME, ICON_PAINTS, Icon, IconOptions, IconPaint, iconOptionsSchema, iconSchema, iconTintSchema };
|
|
31
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/icons/schema.ts"],"mappings":";;;;;;cAMa,WAAS;;;;;cAMT,mBAAiB,EAAA,aAAA,EAAA,yBAAA,EAAA,aAAA,EAAA,yBAAA,EAAA;KAElB,cAAc,EAAE,mBAAmB;cAElC,YAAU,EAAA;;;;;;;;;;;KAYX,OAAO,EAAE,mBAAmB;cAE3B;KACD,oBAAoB;cAEnB,gBAAc,EAAA,yBAAA,EAAA,YAAA,EAAA,oEAAA,EAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/icons/schema.ts
|
|
3
|
+
/**
|
|
4
|
+
* An icon's name in its set, `prefix:name`, as Iconify names icons. Names may hold dots, as SF
|
|
5
|
+
* Symbols' do (`house.fill`).
|
|
6
|
+
*/
|
|
7
|
+
const ICON_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*:[a-z0-9]+(?:[-_.][a-z0-9]+)*$/;
|
|
8
|
+
/**
|
|
9
|
+
* How an icon from a set we draw ourselves is drawn: a font's axes, such as Material Symbols'
|
|
10
|
+
* `wght` and `FILL`, or SF Symbols' weight and scale. Icons from Iconify have none.
|
|
11
|
+
*/
|
|
12
|
+
const iconOptionsSchema = v.record(v.string(), v.union([v.number(), v.string()]));
|
|
13
|
+
const iconSchema = v.object({
|
|
14
|
+
name: v.pipe(v.string(), v.regex(ICON_NAME)),
|
|
15
|
+
/** A fingerprint of the glyph as placed, to tell when its paths were edited; see `iconGlyph`. */
|
|
16
|
+
glyph: v.optional(v.string()),
|
|
17
|
+
/**
|
|
18
|
+
* Set for an icon drawn from one of our own sets rather than Iconify, so it is drawn again and
|
|
19
|
+
* exported as the paths it draws rather than by its name alone.
|
|
20
|
+
*/
|
|
21
|
+
options: v.optional(iconOptionsSchema)
|
|
22
|
+
});
|
|
23
|
+
const ICON_PAINTS = ["fill", "stroke"];
|
|
24
|
+
const iconTintSchema = v.pipe(v.array(v.picklist(ICON_PAINTS)), v.minLength(1));
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ICON_NAME, ICON_PAINTS, iconOptionsSchema, iconSchema, iconTintSchema };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=schema.js.map
|