@open-pencil/scene-graph 0.16.0 → 0.17.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow-caps.d.ts +35 -14
- package/dist/arrow-caps.d.ts.map +1 -1
- package/dist/arrow-caps.js +289 -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 +56 -0
- package/dist/behaviours/kinds.d.ts.map +1 -0
- package/dist/behaviours/kinds.js.map +1 -0
- package/dist/behaviours/layers.d.ts +16 -0
- package/dist/behaviours/layers.d.ts.map +1 -0
- package/dist/behaviours/layers.js +42 -0
- package/dist/behaviours/layers.js.map +1 -0
- package/dist/behaviours/model.d.ts +45 -0
- package/dist/behaviours/model.d.ts.map +1 -0
- package/dist/behaviours/model.js +149 -0
- package/dist/behaviours/model.js.map +1 -0
- package/dist/behaviours/schema.d.ts +114 -0
- package/dist/behaviours/schema.d.ts.map +1 -0
- package/dist/behaviours/schema.js +71 -0
- package/dist/behaviours/schema.js.map +1 -0
- package/dist/behaviours/spec.d.ts +26 -0
- package/dist/behaviours/spec.d.ts.map +1 -0
- package/dist/{chunks/behaviours → behaviours}/spec.js +4 -28
- package/dist/behaviours/spec.js.map +1 -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 +13 -0
- package/dist/checkpoint.d.ts.map +1 -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 +20 -0
- package/dist/components/properties.d.ts.map +1 -0
- package/dist/components/properties.js +125 -0
- package/dist/components/properties.js.map +1 -0
- package/dist/components/variants.d.ts +27 -0
- package/dist/components/variants.d.ts.map +1 -0
- package/dist/components/variants.js.map +1 -0
- package/dist/connectors/controls.d.ts +34 -0
- package/dist/connectors/controls.d.ts.map +1 -0
- package/dist/connectors/controls.js +196 -0
- package/dist/connectors/controls.js.map +1 -0
- package/dist/connectors/create.d.ts +23 -0
- package/dist/connectors/create.d.ts.map +1 -0
- package/dist/connectors/create.js +33 -0
- package/dist/connectors/create.js.map +1 -0
- package/dist/connectors/elbow.js +191 -0
- package/dist/connectors/elbow.js.map +1 -0
- package/dist/connectors/gaps.d.ts +10 -0
- package/dist/connectors/gaps.d.ts.map +1 -0
- package/dist/connectors/gaps.js +86 -0
- package/dist/connectors/gaps.js.map +1 -0
- package/dist/connectors/hit.d.ts +11 -0
- package/dist/connectors/hit.d.ts.map +1 -0
- package/dist/connectors/hit.js +53 -0
- package/dist/connectors/hit.js.map +1 -0
- package/dist/connectors/index.d.ts +11 -0
- package/dist/connectors/index.js +11 -0
- package/dist/connectors/label.d.ts +32 -0
- package/dist/connectors/label.d.ts.map +1 -0
- package/dist/connectors/label.js +213 -0
- package/dist/connectors/label.js.map +1 -0
- package/dist/connectors/layout.d.ts +46 -0
- package/dist/connectors/layout.d.ts.map +1 -0
- package/dist/connectors/layout.js +234 -0
- package/dist/connectors/layout.js.map +1 -0
- package/dist/connectors/pieces.d.ts +22 -0
- package/dist/connectors/pieces.d.ts.map +1 -0
- package/dist/connectors/pieces.js +159 -0
- package/dist/connectors/pieces.js.map +1 -0
- package/dist/connectors/route.d.ts +23 -0
- package/dist/connectors/route.d.ts.map +1 -0
- package/dist/connectors/route.js +107 -0
- package/dist/connectors/route.js.map +1 -0
- package/dist/connectors/sides.d.ts +23 -0
- package/dist/connectors/sides.d.ts.map +1 -0
- package/dist/connectors/sides.js +98 -0
- package/dist/connectors/sides.js.map +1 -0
- package/dist/connectors/sublayers.d.ts +76 -0
- package/dist/connectors/sublayers.d.ts.map +1 -0
- package/dist/connectors/sublayers.js +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 +270 -2
- package/dist/copy.js.map +1 -0
- package/dist/css/grid.d.ts +7 -0
- package/dist/css/grid.d.ts.map +1 -0
- package/dist/{chunks/css → css}/grid.js +2 -33
- package/dist/css/grid.js.map +1 -0
- package/dist/css/index.d.ts +6 -0
- package/dist/css/index.js +6 -0
- package/dist/css/layout.d.ts +17 -0
- package/dist/css/layout.d.ts.map +1 -0
- package/dist/css/layout.js +45 -0
- package/dist/css/layout.js.map +1 -0
- package/dist/css/shadows.d.ts +10 -0
- package/dist/css/shadows.d.ts.map +1 -0
- package/dist/css/shadows.js +64 -0
- package/dist/css/shadows.js.map +1 -0
- package/dist/css/text.d.ts +22 -0
- package/dist/css/text.d.ts.map +1 -0
- package/dist/css/text.js +76 -0
- package/dist/css/text.js.map +1 -0
- package/dist/css/values.d.ts +14 -0
- package/dist/css/values.d.ts.map +1 -0
- package/dist/css/values.js +36 -0
- package/dist/css/values.js.map +1 -0
- package/dist/events.js.map +1 -0
- package/dist/export-format.d.ts +12 -0
- package/dist/export-format.d.ts.map +1 -0
- package/dist/export-format.js +22 -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 +63 -0
- package/dist/fields/text.js.map +1 -0
- package/dist/fig-compression.d.ts +11 -0
- package/dist/fig-compression.d.ts.map +1 -0
- package/dist/fig-compression.js +15 -0
- package/dist/fig-compression.js.map +1 -0
- package/dist/figjam/index.d.ts +3 -0
- package/dist/figjam/index.js +3 -0
- package/dist/figjam/palette.d.ts +259 -0
- package/dist/figjam/palette.d.ts.map +1 -0
- package/dist/figjam/palette.js +411 -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 +38 -0
- package/dist/generated/shape-with-text.d.ts.map +1 -0
- package/dist/generated/shape-with-text.js +118 -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 +105 -2
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +374 -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 +177 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +613 -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 +19 -2
- package/dist/guides.d.ts.map +1 -0
- 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 +34 -29
- 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 +82 -0
- package/dist/instances/fields.js.map +1 -0
- package/dist/instances/index.d.ts +40 -0
- package/dist/instances/index.d.ts.map +1 -0
- package/dist/instances/index.js +174 -0
- package/dist/instances/index.js.map +1 -0
- package/dist/instances/main-component.d.ts +11 -0
- package/dist/instances/main-component.d.ts.map +1 -0
- package/dist/instances/main-component.js +42 -0
- package/dist/instances/main-component.js.map +1 -0
- package/dist/instances/overrides.d.ts +48 -0
- package/dist/instances/overrides.d.ts.map +1 -0
- package/dist/instances/overrides.js +142 -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/sync.js +275 -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/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 +142 -0
- package/dist/plugin-data/fields.d.ts.map +1 -0
- package/dist/plugin-data/fields.js +153 -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 +38 -0
- package/dist/shared-styles.d.ts.map +1 -0
- package/dist/shared-styles.js +125 -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 +103 -0
- package/dist/slots/content.js.map +1 -0
- package/dist/slots/frames.d.ts +38 -0
- package/dist/slots/frames.d.ts.map +1 -0
- package/dist/slots/frames.js +113 -0
- package/dist/slots/frames.js.map +1 -0
- package/dist/slots/index.d.ts +5 -0
- package/dist/slots/index.js +5 -0
- package/dist/slots/limits.d.ts +14 -0
- package/dist/slots/limits.d.ts.map +1 -0
- package/dist/slots/limits.js +28 -0
- package/dist/slots/limits.js.map +1 -0
- package/dist/snap.d.ts +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 +19 -0
- package/dist/text/lengths.d.ts.map +1 -0
- package/dist/text/lengths.js +40 -0
- package/dist/text/lengths.js.map +1 -0
- package/dist/text/lists.d.ts +44 -0
- package/dist/text/lists.d.ts.map +1 -0
- package/dist/text/lists.js +100 -0
- package/dist/text/lists.js.map +1 -0
- package/dist/text/overflow.d.ts +11 -0
- package/dist/text/overflow.d.ts.map +1 -0
- package/dist/text/overflow.js +13 -0
- package/dist/text/overflow.js.map +1 -0
- package/dist/text/paragraphs.d.ts +62 -0
- package/dist/text/paragraphs.d.ts.map +1 -0
- package/dist/text/paragraphs.js +166 -0
- package/dist/text/paragraphs.js.map +1 -0
- package/dist/{text-picture.d.ts → text/picture.d.ts} +2 -2
- package/dist/text/picture.d.ts.map +1 -0
- package/dist/text/picture.js +41 -0
- package/dist/text/picture.js.map +1 -0
- package/dist/text/references.d.ts +21 -0
- package/dist/text/references.d.ts.map +1 -0
- package/dist/text/references.js +43 -0
- package/dist/text/references.js.map +1 -0
- package/dist/text/schema.d.ts +10 -0
- package/dist/text/schema.d.ts.map +1 -0
- package/dist/text/schema.js +11 -0
- package/dist/text/schema.js.map +1 -0
- package/dist/transfer/apply.d.ts +9 -0
- package/dist/transfer/apply.d.ts.map +1 -0
- package/dist/transfer/apply.js +65 -0
- package/dist/transfer/apply.js.map +1 -0
- package/dist/transfer/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 +74 -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 +169 -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 +60 -0
- package/dist/variables/bindings.d.ts.map +1 -0
- package/dist/variables/bindings.js +224 -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 +25 -0
- package/dist/variables/fields.d.ts.map +1 -0
- package/dist/variables/fields.js +69 -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 +223 -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 +297 -137
- package/src/arrow-caps.ts +282 -62
- package/src/behaviours/index.ts +5 -0
- package/src/behaviours/layers.ts +1 -1
- package/src/behaviours/model.ts +3 -11
- package/src/behaviours/schema.ts +44 -9
- package/src/behaviours/spec.ts +4 -49
- package/src/checkpoint.ts +1 -1
- 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 +2 -2
- package/src/components/variants.ts +1 -1
- package/src/connectors/controls.ts +229 -0
- package/src/connectors/create.ts +48 -0
- package/src/connectors/elbow.ts +235 -0
- package/src/connectors/gaps.ts +72 -0
- package/src/connectors/hit.ts +60 -0
- package/src/connectors/index.ts +28 -0
- package/src/connectors/label.ts +238 -0
- package/src/connectors/layout.ts +280 -0
- package/src/connectors/pieces.ts +144 -0
- package/src/connectors/route.ts +148 -0
- package/src/connectors/sides.ts +94 -0
- package/src/connectors/sublayers.ts +203 -0
- package/src/coordinate.ts +10 -3
- package/src/copy.ts +63 -17
- package/src/css/index.ts +1 -0
- package/src/css/text.ts +84 -0
- package/src/export-format.ts +1 -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 +29 -0
- package/src/fig-compression.ts +9 -0
- package/src/figjam/index.ts +2 -0
- package/src/figjam/palette.ts +445 -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 +131 -0
- package/src/generated/sticky.ts +213 -0
- package/src/geometry.ts +40 -130
- package/src/gradient.ts +14 -0
- package/src/graph.ts +825 -0
- package/src/group-bounds.ts +59 -12
- package/src/guides.ts +1 -1
- package/src/hit-test.ts +52 -21
- 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 +39 -92
- package/src/{instances.ts → instances/index.ts} +13 -15
- package/src/instances/main-component.ts +43 -1
- package/src/{instance-overrides.ts → instances/overrides.ts} +31 -1
- package/src/instances/placement.ts +1 -1
- package/src/instances/source-walk.ts +3 -9
- package/src/instances/sync.ts +30 -140
- 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 +41 -2
- 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 +54 -75
- 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 +89 -18
- package/src/slots/authoring.ts +1 -1
- package/src/slots/content.ts +8 -5
- package/src/slots/frames.ts +3 -3
- 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 +34 -0
- package/src/text/overflow.ts +12 -0
- 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 +11 -14
- 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 +218 -13
- package/src/undo.ts +64 -2
- package/src/variables/bindings.ts +44 -55
- package/src/variables/corners.ts +39 -0
- package/src/variables/fields.ts +38 -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} +52 -145
- 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.map +0 -1
- package/dist/chunks/buffered-events.js.map +0 -1
- 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.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/behaviours → behaviours}/kinds.js +0 -0
- /package/dist/{chunks/bindings.js → bindings.js} +0 -0
- /package/dist/{chunks/buffered-events.js → buffered-events.js} +0 -0
- /package/dist/{chunks/checkpoint.js → checkpoint.js} +0 -0
- /package/dist/{chunks/components → components}/variants.js +0 -0
- /package/dist/{chunks/events.js → events.js} +0 -0
- /package/dist/{chunks/fields → fields}/geometry.js +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import Matrix from "../matrix.js";
|
|
2
|
+
import { getWorldMatrix } from "../coordinate.js";
|
|
3
|
+
import { connectorSublayers } from "./sublayers.js";
|
|
4
|
+
import { isStraight, pointAt } from "./pieces.js";
|
|
5
|
+
//#region src/connectors/hit.ts
|
|
6
|
+
/** How far from a line, beyond half its stroke, a point still lands on it, in canvas units. */
|
|
7
|
+
const CONNECTOR_HIT_SLOP = 4;
|
|
8
|
+
/** Points sampled along a curved segment to measure distance to it. */
|
|
9
|
+
const CURVE_SAMPLES = 24;
|
|
10
|
+
function distanceToSegment(p, a, b) {
|
|
11
|
+
const dx = b.x - a.x;
|
|
12
|
+
const dy = b.y - a.y;
|
|
13
|
+
const lengthSquared = dx * dx + dy * dy;
|
|
14
|
+
const t = lengthSquared === 0 ? 0 : Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / lengthSquared));
|
|
15
|
+
return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Whether a canvas point lands on a connector's line: within half its stroke and a few units of
|
|
19
|
+
* slop, plus `pad`. A connector is picked by its line, not by the box around its route.
|
|
20
|
+
*/
|
|
21
|
+
function hitsConnectorLine(graph, connector, px, py, pad = 0) {
|
|
22
|
+
const line = connectorSublayers(graph, connector)?.line;
|
|
23
|
+
const network = line?.vectorNetwork;
|
|
24
|
+
if (!line || !network) return false;
|
|
25
|
+
const inverse = Matrix.invert(getWorldMatrix(line, graph));
|
|
26
|
+
if (!inverse) return false;
|
|
27
|
+
const [x, y] = Matrix.mapPoints(inverse, [px, py]);
|
|
28
|
+
const point = {
|
|
29
|
+
x,
|
|
30
|
+
y
|
|
31
|
+
};
|
|
32
|
+
const reach = (line.strokes[0]?.weight ?? line.strokeWeight) / 2 + CONNECTOR_HIT_SLOP + pad;
|
|
33
|
+
return network.segments.some((segment) => {
|
|
34
|
+
const piece = {
|
|
35
|
+
from: network.vertices[segment.start],
|
|
36
|
+
to: network.vertices[segment.end],
|
|
37
|
+
handleFrom: segment.tangentStart,
|
|
38
|
+
handleTo: segment.tangentEnd
|
|
39
|
+
};
|
|
40
|
+
if (isStraight(piece)) return distanceToSegment(point, piece.from, piece.to) <= reach;
|
|
41
|
+
let previous = piece.from;
|
|
42
|
+
for (let step = 1; step <= CURVE_SAMPLES; step++) {
|
|
43
|
+
const current = pointAt(piece, step / CURVE_SAMPLES);
|
|
44
|
+
if (distanceToSegment(point, previous, current) <= reach) return true;
|
|
45
|
+
previous = current;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { hitsConnectorLine };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=hit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hit.js","names":[],"sources":["../../src/connectors/hit.ts"],"sourcesContent":["import { getWorldMatrix } from '../coordinate'\nimport type { SceneGraph } from '../graph'\nimport Matrix from '../matrix'\nimport type { Vector } from '../primitives'\nimport type { SceneNode } from '../types'\nimport { isStraight, pointAt, type ConnectorPiece } from './pieces'\nimport { connectorSublayers } from './sublayers'\n\n/** How far from a line, beyond half its stroke, a point still lands on it, in canvas units. */\nconst CONNECTOR_HIT_SLOP = 4\n/** Points sampled along a curved segment to measure distance to it. */\nconst CURVE_SAMPLES = 24\n\nfunction distanceToSegment(p: Vector, a: Vector, b: Vector): number {\n const dx = b.x - a.x\n const dy = b.y - a.y\n const lengthSquared = dx * dx + dy * dy\n const t =\n lengthSquared === 0\n ? 0\n : Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / lengthSquared))\n return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy))\n}\n\n/**\n * Whether a canvas point lands on a connector's line: within half its stroke and a few units of\n * slop, plus `pad`. A connector is picked by its line, not by the box around its route.\n */\nexport function hitsConnectorLine(\n graph: SceneGraph,\n connector: SceneNode,\n px: number,\n py: number,\n pad = 0\n): boolean {\n const line = connectorSublayers(graph, connector)?.line\n const network = line?.vectorNetwork\n if (!line || !network) return false\n const inverse = Matrix.invert(getWorldMatrix(line, graph))\n if (!inverse) return false\n const [x, y] = Matrix.mapPoints(inverse, [px, py])\n const point = { x, y }\n const reach = (line.strokes[0]?.weight ?? line.strokeWeight) / 2 + CONNECTOR_HIT_SLOP + pad\n return network.segments.some((segment) => {\n const piece: ConnectorPiece = {\n from: network.vertices[segment.start],\n to: network.vertices[segment.end],\n handleFrom: segment.tangentStart,\n handleTo: segment.tangentEnd\n }\n if (isStraight(piece)) return distanceToSegment(point, piece.from, piece.to) <= reach\n let previous = piece.from\n for (let step = 1; step <= CURVE_SAMPLES; step++) {\n const current = pointAt(piece, step / CURVE_SAMPLES)\n if (distanceToSegment(point, previous, current) <= reach) return true\n previous = current\n }\n return false\n })\n}\n"],"mappings":";;;;;;AASA,MAAM,qBAAqB;;AAE3B,MAAM,gBAAgB;AAEtB,SAAS,kBAAkB,GAAW,GAAW,GAAmB;CAClE,MAAM,KAAK,EAAE,IAAI,EAAE;CACnB,MAAM,KAAK,EAAE,IAAI,EAAE;CACnB,MAAM,gBAAgB,KAAK,KAAK,KAAK;CACrC,MAAM,IACJ,kBAAkB,IACd,IACA,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,EAAE,IAAI,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,MAAM,aAAa,CAAC;CACpF,OAAO,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE,KAAK,EAAE,IAAI,IAAI,GAAG;AAC9D;;;;;AAMA,SAAgB,kBACd,OACA,WACA,IACA,IACA,MAAM,GACG;CACT,MAAM,OAAO,mBAAmB,OAAO,SAAS,CAAC,EAAE;CACnD,MAAM,UAAU,MAAM;CACtB,IAAI,CAAC,QAAQ,CAAC,SAAS,OAAO;CAC9B,MAAM,UAAU,OAAO,OAAO,eAAe,MAAM,KAAK,CAAC;CACzD,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,CAAC,GAAG,KAAK,OAAO,UAAU,SAAS,CAAC,IAAI,EAAE,CAAC;CACjD,MAAM,QAAQ;EAAE;EAAG;CAAE;CACrB,MAAM,SAAS,KAAK,QAAQ,EAAE,EAAE,UAAU,KAAK,gBAAgB,IAAI,qBAAqB;CACxF,OAAO,QAAQ,SAAS,MAAM,YAAY;EACxC,MAAM,QAAwB;GAC5B,MAAM,QAAQ,SAAS,QAAQ;GAC/B,IAAI,QAAQ,SAAS,QAAQ;GAC7B,YAAY,QAAQ;GACpB,UAAU,QAAQ;EACpB;EACA,IAAI,WAAW,KAAK,GAAG,OAAO,kBAAkB,OAAO,MAAM,MAAM,MAAM,EAAE,KAAK;EAChF,IAAI,WAAW,MAAM;EACrB,KAAK,IAAI,OAAO,GAAG,QAAQ,eAAe,QAAQ;GAChD,MAAM,UAAU,QAAQ,OAAO,OAAO,aAAa;GACnD,IAAI,kBAAkB,OAAO,UAAU,OAAO,KAAK,OAAO,OAAO;GACjE,WAAW;EACb;EACA,OAAO;CACT,CAAC;AACH"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CONNECTOR_NAME, ConnectorContent, createConnector } from "./create.js";
|
|
2
|
+
import { hitsConnectorLine } from "./hit.js";
|
|
3
|
+
import { ConnectorPiece, connectorNetwork } from "./pieces.js";
|
|
4
|
+
import { CONNECTOR_LABEL_PADDING, ConnectorLabelLayout, connectorLabelPositionAt, placeConnectorLabel } from "./label.js";
|
|
5
|
+
import { ConnectorRouteEnd, ConnectorSide, connectorSides } from "./sides.js";
|
|
6
|
+
import { curveControlPoints, curveMidpoint, dragCurve, dragElbowSegment, elbowControlPoints, elbowJoints } from "./controls.js";
|
|
7
|
+
import { ConnectorRouteControls, routeConnector } from "./route.js";
|
|
8
|
+
import { ConnectorRoute, attachedConnectors, connectorRoute, connectorsAffectedBy, layoutConnector } from "./layout.js";
|
|
9
|
+
import { connectorEndGap } from "./gaps.js";
|
|
10
|
+
import { CONNECTOR_COLOR, CONNECTOR_CORNER_RADIUS, CONNECTOR_KIND, CONNECTOR_LABEL_FONT, CONNECTOR_STROKE_WEIGHT, CONNECTOR_THICK_STROKE_WEIGHT, ConnectorLineStyle, ConnectorSublayers, boundEndpoint, buildConnectorSublayers, connectorDash, connectorLineEnds, connectorLineStyle, connectorLineStyleFields, connectorRouteEnds, connectorStroke, connectorSublayers, freeEndpoint, labelledConnector } from "./sublayers.js";
|
|
11
|
+
export { CONNECTOR_COLOR, CONNECTOR_CORNER_RADIUS, CONNECTOR_KIND, CONNECTOR_LABEL_FONT, CONNECTOR_LABEL_PADDING, CONNECTOR_NAME, CONNECTOR_STROKE_WEIGHT, CONNECTOR_THICK_STROKE_WEIGHT, type ConnectorContent, type ConnectorLabelLayout, ConnectorLineStyle, type ConnectorPiece, type ConnectorRoute, type ConnectorRouteControls, type ConnectorRouteEnd, type ConnectorSide, ConnectorSublayers, attachedConnectors, boundEndpoint, buildConnectorSublayers, connectorDash, connectorEndGap, connectorLabelPositionAt, connectorLineEnds, connectorLineStyle, connectorLineStyleFields, connectorNetwork, connectorRoute, connectorRouteEnds, connectorSides, connectorStroke, connectorSublayers, connectorsAffectedBy, createConnector, curveControlPoints, curveMidpoint, dragCurve, dragElbowSegment, elbowControlPoints, elbowJoints, freeEndpoint, hitsConnectorLine, labelledConnector, layoutConnector, placeConnectorLabel, routeConnector };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CONNECTOR_COLOR, CONNECTOR_CORNER_RADIUS, CONNECTOR_KIND, CONNECTOR_LABEL_FONT, CONNECTOR_STROKE_WEIGHT, CONNECTOR_THICK_STROKE_WEIGHT, boundEndpoint, buildConnectorSublayers, connectorDash, connectorLineEnds, connectorLineStyle, connectorLineStyleFields, connectorRouteEnds, connectorStroke, connectorSublayers, freeEndpoint, labelledConnector } from "./sublayers.js";
|
|
2
|
+
import { connectorNetwork } from "./pieces.js";
|
|
3
|
+
import { hitsConnectorLine } from "./hit.js";
|
|
4
|
+
import { connectorSides } from "./sides.js";
|
|
5
|
+
import { curveControlPoints, curveMidpoint, dragCurve, dragElbowSegment, elbowControlPoints, elbowJoints } from "./controls.js";
|
|
6
|
+
import { CONNECTOR_LABEL_PADDING, connectorLabelPositionAt, placeConnectorLabel } from "./label.js";
|
|
7
|
+
import { connectorEndGap } from "./gaps.js";
|
|
8
|
+
import { routeConnector } from "./route.js";
|
|
9
|
+
import { attachedConnectors, connectorRoute, connectorsAffectedBy, layoutConnector } from "./layout.js";
|
|
10
|
+
import { CONNECTOR_NAME, createConnector } from "./create.js";
|
|
11
|
+
export { CONNECTOR_COLOR, CONNECTOR_CORNER_RADIUS, CONNECTOR_KIND, CONNECTOR_LABEL_FONT, CONNECTOR_LABEL_PADDING, CONNECTOR_NAME, CONNECTOR_STROKE_WEIGHT, CONNECTOR_THICK_STROKE_WEIGHT, attachedConnectors, boundEndpoint, buildConnectorSublayers, connectorDash, connectorEndGap, connectorLabelPositionAt, connectorLineEnds, connectorLineStyle, connectorLineStyleFields, connectorNetwork, connectorRoute, connectorRouteEnds, connectorSides, connectorStroke, connectorSublayers, connectorsAffectedBy, createConnector, curveControlPoints, curveMidpoint, dragCurve, dragElbowSegment, elbowControlPoints, elbowJoints, freeEndpoint, hitsConnectorLine, labelledConnector, layoutConnector, placeConnectorLabel, routeConnector };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Rect, Vector } from "../primitives/index.js";
|
|
2
|
+
import { ConnectorLabelPosition } from "../types.js";
|
|
3
|
+
import { ConnectorPiece } from "./pieces.js";
|
|
4
|
+
//#region src/connectors/label.d.ts
|
|
5
|
+
/** How far a label's plate reaches past its text. */
|
|
6
|
+
declare const CONNECTOR_LABEL_PADDING = 8.5;
|
|
7
|
+
/** A connector's label plate and the line with the plate's span cut out. */
|
|
8
|
+
interface ConnectorLabelLayout {
|
|
9
|
+
pieces: ConnectorPiece[];
|
|
10
|
+
plate: Rect;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Where a label dragged to `point` goes, as FigJam places it: at the nearest point of the line,
|
|
14
|
+
* as a share of the way from the middle towards an end, and beside the line once the point is
|
|
15
|
+
* farther from it than half the plate across plus a little.
|
|
16
|
+
*/
|
|
17
|
+
declare function connectorLabelPositionAt(pieces: ConnectorPiece[], size: {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
}, point: Vector): ConnectorLabelPosition | null;
|
|
21
|
+
/**
|
|
22
|
+
* Places a label's plate on a route and cuts the line where it sits: midway along a straight or
|
|
23
|
+
* curved line, and midway along an elbow's longest run, the first of equal runs, unless it was
|
|
24
|
+
* dragged to a `position` of its own.
|
|
25
|
+
*/
|
|
26
|
+
declare function placeConnectorLabel(pieces: ConnectorPiece[], plateSize: {
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
}, position?: ConnectorLabelPosition | null): ConnectorLabelLayout | null;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { CONNECTOR_LABEL_PADDING, ConnectorLabelLayout, connectorLabelPositionAt, placeConnectorLabel };
|
|
32
|
+
//# sourceMappingURL=label.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"label.d.ts","names":[],"sources":["../../src/connectors/label.ts"],"mappings":";;;;;cAaa;;UAgCI;EACf,QAAQ;EACR,OAAO;;;;;;;iBAqHO,yBACd,QAAQ,kBACR;EAAQ;EAAe;GACvB,OAAO,SACN;;;;;;iBAiDa,oBACd,QAAQ,kBACR;EAAa;EAAe;GAC5B,WAAU,gCACT"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { exitPoint, isStraight, pieceLength, pointAt, subPiece } from "./pieces.js";
|
|
2
|
+
//#region src/connectors/label.ts
|
|
3
|
+
/** How far a label's plate reaches past its text. */
|
|
4
|
+
const CONNECTOR_LABEL_PADDING = 8.5;
|
|
5
|
+
function insideRect(point, rect) {
|
|
6
|
+
return point.x > rect.x + 1e-6 && point.x < rect.x + rect.width - 1e-6 && point.y > rect.y + 1e-6 && point.y < rect.y + rect.height - 1e-6;
|
|
7
|
+
}
|
|
8
|
+
/** Where a piece running from inside `rect` at `inside` towards `outside` leaves it. */
|
|
9
|
+
function crossing(piece, rect, inside, outside) {
|
|
10
|
+
const end = pointAt(piece, outside);
|
|
11
|
+
if (insideRect(end, rect)) return outside;
|
|
12
|
+
if (isStraight(piece)) {
|
|
13
|
+
const start = pointAt(piece, inside);
|
|
14
|
+
const exit = exitPoint(rect, start, end);
|
|
15
|
+
const share = Math.hypot(exit.x - start.x, exit.y - start.y) / pieceLength(piece);
|
|
16
|
+
return inside + Math.sign(outside - inside) * share;
|
|
17
|
+
}
|
|
18
|
+
let low = inside;
|
|
19
|
+
let high = outside;
|
|
20
|
+
for (let step = 0; step < 40; step++) {
|
|
21
|
+
const t = (low + high) / 2;
|
|
22
|
+
if (insideRect(pointAt(piece, t), rect)) low = t;
|
|
23
|
+
else high = t;
|
|
24
|
+
}
|
|
25
|
+
return high;
|
|
26
|
+
}
|
|
27
|
+
/** Points sampled along a curved piece to measure and search it. */
|
|
28
|
+
const CURVE_SAMPLES = 32;
|
|
29
|
+
/**
|
|
30
|
+
* How far a label dragged off its line sits from it, centre to line: 0.7 of the plate's extent
|
|
31
|
+
* across the line plus 12.3, fitted to the distances FigJam keeps for plates 31 to 118 across.
|
|
32
|
+
*/
|
|
33
|
+
const OFF_AXIS_SCALE = .7;
|
|
34
|
+
const OFF_AXIS_OFFSET = 12.3;
|
|
35
|
+
/**
|
|
36
|
+
* How far past half the plate's extent across the line a dragged label may be from it and stay
|
|
37
|
+
* on it, as FigJam lets it.
|
|
38
|
+
*/
|
|
39
|
+
const OFF_AXIS_SLACK = 12;
|
|
40
|
+
/** A piece's length along its curve. */
|
|
41
|
+
function lengthOf(piece) {
|
|
42
|
+
if (isStraight(piece)) return pieceLength(piece);
|
|
43
|
+
let length = 0;
|
|
44
|
+
let last = piece.from;
|
|
45
|
+
for (let step = 1; step <= CURVE_SAMPLES; step++) {
|
|
46
|
+
const point = pointAt(piece, step / CURVE_SAMPLES);
|
|
47
|
+
length += Math.hypot(point.x - last.x, point.y - last.y);
|
|
48
|
+
last = point;
|
|
49
|
+
}
|
|
50
|
+
return length;
|
|
51
|
+
}
|
|
52
|
+
/** Where a route is `distance` along it: which piece, how far into it, and which way it runs. */
|
|
53
|
+
function alongRoute(pieces, distance) {
|
|
54
|
+
let left = Math.max(0, distance);
|
|
55
|
+
for (const [index, piece] of pieces.entries()) {
|
|
56
|
+
const length = lengthOf(piece);
|
|
57
|
+
if (left <= length || index === pieces.length - 1) {
|
|
58
|
+
const t = length > 0 ? Math.min(1, left / length) : 0;
|
|
59
|
+
return {
|
|
60
|
+
index,
|
|
61
|
+
t,
|
|
62
|
+
point: pointAt(piece, t),
|
|
63
|
+
direction: directionAt(piece, t)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
left -= length;
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
function directionAt(piece, t) {
|
|
71
|
+
const a = pointAt(piece, Math.max(0, t - .001));
|
|
72
|
+
const b = pointAt(piece, Math.min(1, t + .001));
|
|
73
|
+
const length = Math.hypot(b.x - a.x, b.y - a.y);
|
|
74
|
+
return length > 0 ? {
|
|
75
|
+
x: (b.x - a.x) / length,
|
|
76
|
+
y: (b.y - a.y) / length
|
|
77
|
+
} : {
|
|
78
|
+
x: 1,
|
|
79
|
+
y: 0
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** The side to the left of a run along `direction`, which FigJam calls above. */
|
|
83
|
+
function above(direction) {
|
|
84
|
+
return {
|
|
85
|
+
x: direction.y,
|
|
86
|
+
y: -direction.x
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** A plate's extent across a line running along `direction`. */
|
|
90
|
+
function extentAcross(size, direction) {
|
|
91
|
+
return Math.abs(direction.y) * size.width + Math.abs(direction.x) * size.height;
|
|
92
|
+
}
|
|
93
|
+
function plateAt(centre, size) {
|
|
94
|
+
return {
|
|
95
|
+
x: centre.x - size.width / 2,
|
|
96
|
+
y: centre.y - size.height / 2,
|
|
97
|
+
...size
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** Cuts the plate's span out of piece `index`, around the point `t` along it. */
|
|
101
|
+
function cutAround(pieces, index, t, plate) {
|
|
102
|
+
const piece = pieces[index];
|
|
103
|
+
if (pieceLength(piece) <= 1e-6) return pieces;
|
|
104
|
+
const t0 = crossing(piece, plate, t, 0);
|
|
105
|
+
const t1 = crossing(piece, plate, t, 1);
|
|
106
|
+
const cut = [...t0 > 1e-6 ? [subPiece(piece, 0, t0)] : [], ...t1 < 1 - 1e-6 ? [subPiece(piece, t1, 1)] : []];
|
|
107
|
+
return [
|
|
108
|
+
...pieces.slice(0, index),
|
|
109
|
+
...cut,
|
|
110
|
+
...pieces.slice(index + 1)
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A label dragged along its line: its centre `offset` of the way from the middle to an end, by
|
|
115
|
+
* length, cutting the line there, or beside the line, which then runs on uncut.
|
|
116
|
+
*/
|
|
117
|
+
function placeDragged(pieces, size, { section, offset, offAxis }) {
|
|
118
|
+
const half = pieces.reduce((sum, piece) => sum + lengthOf(piece), 0) / 2;
|
|
119
|
+
const at = alongRoute(pieces, half + (section === "MIDDLE_TO_END" ? offset : -offset) * half);
|
|
120
|
+
if (!at) return null;
|
|
121
|
+
if (offAxis === "NONE") {
|
|
122
|
+
const plate = plateAt(at.point, size);
|
|
123
|
+
return {
|
|
124
|
+
pieces: cutAround(pieces, at.index, at.t, plate),
|
|
125
|
+
plate
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const side = above(at.direction);
|
|
129
|
+
const sign = offAxis === "ABOVE" ? 1 : -1;
|
|
130
|
+
const distance = OFF_AXIS_SCALE * extentAcross(size, at.direction) + OFF_AXIS_OFFSET;
|
|
131
|
+
return {
|
|
132
|
+
pieces,
|
|
133
|
+
plate: plateAt({
|
|
134
|
+
x: at.point.x + side.x * sign * distance,
|
|
135
|
+
y: at.point.y + side.y * sign * distance
|
|
136
|
+
}, size)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Where a label dragged to `point` goes, as FigJam places it: at the nearest point of the line,
|
|
141
|
+
* as a share of the way from the middle towards an end, and beside the line once the point is
|
|
142
|
+
* farther from it than half the plate across plus a little.
|
|
143
|
+
*/
|
|
144
|
+
function connectorLabelPositionAt(pieces, size, point) {
|
|
145
|
+
let best = null;
|
|
146
|
+
let before = 0;
|
|
147
|
+
for (const piece of pieces) {
|
|
148
|
+
const length = lengthOf(piece);
|
|
149
|
+
const samples = isStraight(piece) ? 1 : CURVE_SAMPLES;
|
|
150
|
+
for (let step = 0; step < samples; step++) {
|
|
151
|
+
const a = pointAt(piece, step / samples);
|
|
152
|
+
const b = pointAt(piece, (step + 1) / samples);
|
|
153
|
+
const dx = b.x - a.x;
|
|
154
|
+
const dy = b.y - a.y;
|
|
155
|
+
const span = Math.hypot(dx, dy);
|
|
156
|
+
const u = span > 0 ? Math.max(0, Math.min(1, ((point.x - a.x) * dx + (point.y - a.y) * dy) / (span * span))) : 0;
|
|
157
|
+
const near = {
|
|
158
|
+
x: a.x + dx * u,
|
|
159
|
+
y: a.y + dy * u
|
|
160
|
+
};
|
|
161
|
+
const distance = Math.hypot(point.x - near.x, point.y - near.y);
|
|
162
|
+
if (best && distance >= best.distance - 1e-6) continue;
|
|
163
|
+
const direction = span > 0 ? {
|
|
164
|
+
x: dx / span,
|
|
165
|
+
y: dy / span
|
|
166
|
+
} : directionAt(piece, step / samples);
|
|
167
|
+
const side = above(direction);
|
|
168
|
+
best = {
|
|
169
|
+
distance,
|
|
170
|
+
along: before + length * (step + u) / samples,
|
|
171
|
+
direction,
|
|
172
|
+
across: (point.x - near.x) * side.x + (point.y - near.y) * side.y
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
before += length;
|
|
176
|
+
}
|
|
177
|
+
if (!best || before <= 0) return null;
|
|
178
|
+
const half = before / 2;
|
|
179
|
+
const beside = best.distance > extentAcross(size, best.direction) / 2 + OFF_AXIS_SLACK;
|
|
180
|
+
const side = best.across > 0 ? "ABOVE" : "BELOW";
|
|
181
|
+
return {
|
|
182
|
+
section: best.along > half + 1e-6 ? "MIDDLE_TO_END" : "MIDDLE_TO_START",
|
|
183
|
+
offset: Math.min(1, Math.abs(best.along - half) / half),
|
|
184
|
+
offAxis: beside ? side : "NONE"
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Places a label's plate on a route and cuts the line where it sits: midway along a straight or
|
|
189
|
+
* curved line, and midway along an elbow's longest run, the first of equal runs, unless it was
|
|
190
|
+
* dragged to a `position` of its own.
|
|
191
|
+
*/
|
|
192
|
+
function placeConnectorLabel(pieces, plateSize, position = null) {
|
|
193
|
+
if (pieces.length === 0) return null;
|
|
194
|
+
if (position) return placeDragged(pieces, plateSize, position);
|
|
195
|
+
let index = 0;
|
|
196
|
+
for (let n = 1; n < pieces.length; n++) if (pieceLength(pieces[n]) > pieceLength(pieces[index]) + 1e-6) index = n;
|
|
197
|
+
const piece = pieces[index];
|
|
198
|
+
const middle = pointAt(piece, .5);
|
|
199
|
+
const plate = {
|
|
200
|
+
x: middle.x - plateSize.width / 2,
|
|
201
|
+
y: middle.y - plateSize.height / 2,
|
|
202
|
+
width: plateSize.width,
|
|
203
|
+
height: plateSize.height
|
|
204
|
+
};
|
|
205
|
+
return {
|
|
206
|
+
pieces: cutAround(pieces, index, .5, plate),
|
|
207
|
+
plate
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
export { CONNECTOR_LABEL_PADDING, connectorLabelPositionAt, placeConnectorLabel };
|
|
212
|
+
|
|
213
|
+
//# sourceMappingURL=label.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"label.js","names":[],"sources":["../../src/connectors/label.ts"],"sourcesContent":["import type { Rect, Vector } from '../primitives'\nimport type { ConnectorLabelPosition } from '../types'\nimport {\n EPSILON,\n exitPoint,\n isStraight,\n pieceLength,\n pointAt,\n subPiece,\n type ConnectorPiece\n} from './pieces'\n\n/** How far a label's plate reaches past its text. */\nexport const CONNECTOR_LABEL_PADDING = 8.5\n\nfunction insideRect(point: Vector, rect: Rect): boolean {\n return (\n point.x > rect.x + EPSILON &&\n point.x < rect.x + rect.width - EPSILON &&\n point.y > rect.y + EPSILON &&\n point.y < rect.y + rect.height - EPSILON\n )\n}\n\n/** Where a piece running from inside `rect` at `inside` towards `outside` leaves it. */\nfunction crossing(piece: ConnectorPiece, rect: Rect, inside: number, outside: number): number {\n const end = pointAt(piece, outside)\n if (insideRect(end, rect)) return outside\n if (isStraight(piece)) {\n const start = pointAt(piece, inside)\n const exit = exitPoint(rect, start, end)\n const share = Math.hypot(exit.x - start.x, exit.y - start.y) / pieceLength(piece)\n return inside + Math.sign(outside - inside) * share\n }\n let low = inside\n let high = outside\n for (let step = 0; step < 40; step++) {\n const t = (low + high) / 2\n if (insideRect(pointAt(piece, t), rect)) low = t\n else high = t\n }\n return high\n}\n\n/** A connector's label plate and the line with the plate's span cut out. */\nexport interface ConnectorLabelLayout {\n pieces: ConnectorPiece[]\n plate: Rect\n}\n\n/** Points sampled along a curved piece to measure and search it. */\nconst CURVE_SAMPLES = 32\n\n/**\n * How far a label dragged off its line sits from it, centre to line: 0.7 of the plate's extent\n * across the line plus 12.3, fitted to the distances FigJam keeps for plates 31 to 118 across.\n */\nconst OFF_AXIS_SCALE = 0.7\nconst OFF_AXIS_OFFSET = 12.3\n/**\n * How far past half the plate's extent across the line a dragged label may be from it and stay\n * on it, as FigJam lets it.\n */\nconst OFF_AXIS_SLACK = 12\n\n/** A piece's length along its curve. */\nfunction lengthOf(piece: ConnectorPiece): number {\n if (isStraight(piece)) return pieceLength(piece)\n let length = 0\n let last = piece.from\n for (let step = 1; step <= CURVE_SAMPLES; step++) {\n const point = pointAt(piece, step / CURVE_SAMPLES)\n length += Math.hypot(point.x - last.x, point.y - last.y)\n last = point\n }\n return length\n}\n\n/** Where a route is `distance` along it: which piece, how far into it, and which way it runs. */\nfunction alongRoute(pieces: ConnectorPiece[], distance: number) {\n let left = Math.max(0, distance)\n for (const [index, piece] of pieces.entries()) {\n const length = lengthOf(piece)\n if (left <= length || index === pieces.length - 1) {\n const t = length > 0 ? Math.min(1, left / length) : 0\n return { index, t, point: pointAt(piece, t), direction: directionAt(piece, t) }\n }\n left -= length\n }\n return null\n}\n\nfunction directionAt(piece: ConnectorPiece, t: number): Vector {\n const a = pointAt(piece, Math.max(0, t - 0.001))\n const b = pointAt(piece, Math.min(1, t + 0.001))\n const length = Math.hypot(b.x - a.x, b.y - a.y)\n return length > 0 ? { x: (b.x - a.x) / length, y: (b.y - a.y) / length } : { x: 1, y: 0 }\n}\n\n/** The side to the left of a run along `direction`, which FigJam calls above. */\nfunction above(direction: Vector): Vector {\n return { x: direction.y, y: -direction.x }\n}\n\n/** A plate's extent across a line running along `direction`. */\nfunction extentAcross(size: { width: number; height: number }, direction: Vector): number {\n return Math.abs(direction.y) * size.width + Math.abs(direction.x) * size.height\n}\n\nfunction plateAt(centre: Vector, size: { width: number; height: number }): Rect {\n return { x: centre.x - size.width / 2, y: centre.y - size.height / 2, ...size }\n}\n\n/** Cuts the plate's span out of piece `index`, around the point `t` along it. */\nfunction cutAround(\n pieces: ConnectorPiece[],\n index: number,\n t: number,\n plate: Rect\n): ConnectorPiece[] {\n const piece = pieces[index]\n // A line between touching layers has no length to cut; it keeps its one point.\n if (pieceLength(piece) <= EPSILON) return pieces\n const t0 = crossing(piece, plate, t, 0)\n const t1 = crossing(piece, plate, t, 1)\n const cut = [\n ...(t0 > EPSILON ? [subPiece(piece, 0, t0)] : []),\n ...(t1 < 1 - EPSILON ? [subPiece(piece, t1, 1)] : [])\n ]\n return [...pieces.slice(0, index), ...cut, ...pieces.slice(index + 1)]\n}\n\n/**\n * A label dragged along its line: its centre `offset` of the way from the middle to an end, by\n * length, cutting the line there, or beside the line, which then runs on uncut.\n */\nfunction placeDragged(\n pieces: ConnectorPiece[],\n size: { width: number; height: number },\n { section, offset, offAxis }: ConnectorLabelPosition\n): ConnectorLabelLayout | null {\n const total = pieces.reduce((sum, piece) => sum + lengthOf(piece), 0)\n const half = total / 2\n const at = alongRoute(pieces, half + (section === 'MIDDLE_TO_END' ? offset : -offset) * half)\n if (!at) return null\n if (offAxis === 'NONE') {\n const plate = plateAt(at.point, size)\n return { pieces: cutAround(pieces, at.index, at.t, plate), plate }\n }\n const side = above(at.direction)\n const sign = offAxis === 'ABOVE' ? 1 : -1\n const distance = OFF_AXIS_SCALE * extentAcross(size, at.direction) + OFF_AXIS_OFFSET\n const centre = {\n x: at.point.x + side.x * sign * distance,\n y: at.point.y + side.y * sign * distance\n }\n return { pieces, plate: plateAt(centre, size) }\n}\n\n/**\n * Where a label dragged to `point` goes, as FigJam places it: at the nearest point of the line,\n * as a share of the way from the middle towards an end, and beside the line once the point is\n * farther from it than half the plate across plus a little.\n */\nexport function connectorLabelPositionAt(\n pieces: ConnectorPiece[],\n size: { width: number; height: number },\n point: Vector\n): ConnectorLabelPosition | null {\n let best: { distance: number; along: number; direction: Vector; across: number } | null = null\n let before = 0\n for (const piece of pieces) {\n const length = lengthOf(piece)\n const samples = isStraight(piece) ? 1 : CURVE_SAMPLES\n for (let step = 0; step < samples; step++) {\n // The nearest point of each straight stretch, curves taken a stretch at a time.\n const a = pointAt(piece, step / samples)\n const b = pointAt(piece, (step + 1) / samples)\n const dx = b.x - a.x\n const dy = b.y - a.y\n const span = Math.hypot(dx, dy)\n const u =\n span > 0\n ? Math.max(0, Math.min(1, ((point.x - a.x) * dx + (point.y - a.y) * dy) / (span * span)))\n : 0\n const near = { x: a.x + dx * u, y: a.y + dy * u }\n const distance = Math.hypot(point.x - near.x, point.y - near.y)\n if (best && distance >= best.distance - EPSILON) continue\n const direction =\n span > 0 ? { x: dx / span, y: dy / span } : directionAt(piece, step / samples)\n const side = above(direction)\n best = {\n distance,\n along: before + (length * (step + u)) / samples,\n direction,\n across: (point.x - near.x) * side.x + (point.y - near.y) * side.y\n }\n }\n before += length\n }\n if (!best || before <= 0) return null\n const half = before / 2\n const beside = best.distance > extentAcross(size, best.direction) / 2 + OFF_AXIS_SLACK\n const side = best.across > 0 ? 'ABOVE' : 'BELOW'\n return {\n // The middle itself counts towards the start, as FigJam records it.\n section: best.along > half + EPSILON ? 'MIDDLE_TO_END' : 'MIDDLE_TO_START',\n offset: Math.min(1, Math.abs(best.along - half) / half),\n offAxis: beside ? side : 'NONE'\n }\n}\n\n/**\n * Places a label's plate on a route and cuts the line where it sits: midway along a straight or\n * curved line, and midway along an elbow's longest run, the first of equal runs, unless it was\n * dragged to a `position` of its own.\n */\nexport function placeConnectorLabel(\n pieces: ConnectorPiece[],\n plateSize: { width: number; height: number },\n position: ConnectorLabelPosition | null = null\n): ConnectorLabelLayout | null {\n if (pieces.length === 0) return null\n if (position) return placeDragged(pieces, plateSize, position)\n let index = 0\n for (let n = 1; n < pieces.length; n++) {\n if (pieceLength(pieces[n]) > pieceLength(pieces[index]) + EPSILON) index = n\n }\n const piece = pieces[index]\n const middle = pointAt(piece, 0.5)\n const plate = {\n x: middle.x - plateSize.width / 2,\n y: middle.y - plateSize.height / 2,\n width: plateSize.width,\n height: plateSize.height\n }\n return { pieces: cutAround(pieces, index, 0.5, plate), plate }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { SceneNode } from "../types.js";
|
|
3
|
+
import { ConnectorPiece } from "./pieces.js";
|
|
4
|
+
import { ConnectorRouteEnd, ConnectorSide } from "./sides.js";
|
|
5
|
+
import { ConnectorRouteControls } from "./route.js";
|
|
6
|
+
//#region src/connectors/layout.d.ts
|
|
7
|
+
/** A connector's route as its ends and control points give it, in its parent's axes. */
|
|
8
|
+
interface ConnectorRoute {
|
|
9
|
+
start: ConnectorRouteEnd;
|
|
10
|
+
end: ConnectorRouteEnd;
|
|
11
|
+
sides: [ConnectorSide, ConnectorSide];
|
|
12
|
+
/** The line before its label cuts it. */
|
|
13
|
+
pieces: ConnectorPiece[];
|
|
14
|
+
/** Its control points in its parent's axes. */
|
|
15
|
+
controls: ConnectorRouteControls;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Routes a connector from the layers its ends follow and the control points it was dragged to,
|
|
19
|
+
* without laying anything out. Null when an end cannot be placed.
|
|
20
|
+
*/
|
|
21
|
+
declare function connectorRoute(graph: SceneGraph, connector: SceneNode): ConnectorRoute | null;
|
|
22
|
+
/**
|
|
23
|
+
* Routes a connector again from the layers its ends follow and lays out its line, label plate,
|
|
24
|
+
* and label to match, through `update` so the caller decides whether that is an edit or a
|
|
25
|
+
* preview. Returns whether anything moved. A connector with an end that cannot be placed keeps
|
|
26
|
+
* its route. With `keepBox`, the connector keeps its own position and size, as while a move
|
|
27
|
+
* previews. With `capture`, an elbow that was dragged keeps its new route's segments as its
|
|
28
|
+
* control points, as FigJam does after an edit reroutes one.
|
|
29
|
+
*/
|
|
30
|
+
declare function layoutConnector(graph: SceneGraph, connector: SceneNode, update?: (id: string, changes: Partial<SceneNode>) => void, { keepBox, capture }?: {
|
|
31
|
+
keepBox?: boolean;
|
|
32
|
+
capture?: boolean;
|
|
33
|
+
}): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The connectors with an end on one of `ids` or a layer inside them, which go when those layers
|
|
36
|
+
* are deleted, as in FigJam. Connectors inside `ids` themselves are left out.
|
|
37
|
+
*/
|
|
38
|
+
declare function attachedConnectors(graph: SceneGraph, ids: Iterable<string>): SceneNode[];
|
|
39
|
+
/**
|
|
40
|
+
* The connectors an edit to `ids` moves: those with an end on one of them or on a layer inside
|
|
41
|
+
* them, those inside them, and those whose line or label is among them.
|
|
42
|
+
*/
|
|
43
|
+
declare function connectorsAffectedBy(graph: SceneGraph, ids: ReadonlySet<string>): SceneNode[];
|
|
44
|
+
//#endregion
|
|
45
|
+
export { ConnectorRoute, attachedConnectors, connectorRoute, connectorsAffectedBy, layoutConnector };
|
|
46
|
+
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.d.ts","names":[],"sources":["../../src/connectors/layout.ts"],"mappings":";;;;;;;UAuFiB;EACf,OAAO;EACP,KAAK;EACL,QAAQ,eAAe;;EAEvB,QAAQ;;EAER,UAAU;;;;;;iBAOI,eAAe,OAAO,YAAY,WAAW,YAAY;;;;;;;;;iBA8FzD,gBACd,OAAO,YACP,WAAW,WACX,UAAS,YAAY,SAAS,QAAQ,uBAEpC,SAAiB;EAAqB;EAAmB;;;;;;iBAqD7C,mBAAmB,OAAO,YAAY,KAAK,mBAAmB;;;;;iBAe9D,qBAAqB,OAAO,YAAY,KAAK,sBAAsB"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import Matrix from "../matrix.js";
|
|
2
|
+
import { getAxisAlignedBoundsInParent, getParentWorldMatrix, getWorldMatrix } from "../coordinate.js";
|
|
3
|
+
import { computeBounds } from "../geometry.js";
|
|
4
|
+
import { connectorRouteEnds, connectorSublayers } from "./sublayers.js";
|
|
5
|
+
import { connectorNetwork, piecesBounds } from "./pieces.js";
|
|
6
|
+
import { connectorSides } from "./sides.js";
|
|
7
|
+
import { elbowControlPoints } from "./controls.js";
|
|
8
|
+
import { CONNECTOR_LABEL_PADDING, placeConnectorLabel } from "./label.js";
|
|
9
|
+
import { routeConnector } from "./route.js";
|
|
10
|
+
import { compact, isEqual, pick } from "es-toolkit";
|
|
11
|
+
//#region src/connectors/layout.ts
|
|
12
|
+
/**
|
|
13
|
+
* An end as the router sees it, in the connector's parent's axes: the box of the layer it follows
|
|
14
|
+
* by a magnet, or a point, which an end pinned to a point of its layer follows as the layer moves.
|
|
15
|
+
* An end whose layer is gone stays where its route last ended.
|
|
16
|
+
*/
|
|
17
|
+
function routeEnd(graph, connector, endpoint, cap, fallback) {
|
|
18
|
+
const parentId = connector.parentId;
|
|
19
|
+
if (!parentId) return null;
|
|
20
|
+
const node = endpoint.nodeId ? graph.getNode(endpoint.nodeId) : void 0;
|
|
21
|
+
if (!node) {
|
|
22
|
+
if (endpoint.nodeId && !fallback) return null;
|
|
23
|
+
return {
|
|
24
|
+
box: null,
|
|
25
|
+
point: endpoint.nodeId && fallback ? fallback : endpoint.position,
|
|
26
|
+
magnet: "NONE",
|
|
27
|
+
cap,
|
|
28
|
+
outline: 0
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const centred = endpoint.magnet === "CENTER" && connector.connectorLineType !== "STRAIGHT";
|
|
32
|
+
if (endpoint.magnet === "NONE" || endpoint.magnet === "ABSOLUTE" || centred) {
|
|
33
|
+
const toParent = Matrix.invert(getParentWorldMatrix(graph.getNode(parentId), graph)) ?? Matrix.identity();
|
|
34
|
+
const local = centred ? {
|
|
35
|
+
x: node.width / 2,
|
|
36
|
+
y: node.height / 2
|
|
37
|
+
} : endpoint.position;
|
|
38
|
+
const [x, y] = Matrix.mapPoints(Matrix.multiply(toParent, getWorldMatrix(node, graph)), [local.x, local.y]);
|
|
39
|
+
return {
|
|
40
|
+
box: null,
|
|
41
|
+
point: {
|
|
42
|
+
x,
|
|
43
|
+
y
|
|
44
|
+
},
|
|
45
|
+
magnet: endpoint.magnet,
|
|
46
|
+
cap,
|
|
47
|
+
outline: 0
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
box: getAxisAlignedBoundsInParent([node], parentId, graph),
|
|
52
|
+
point: {
|
|
53
|
+
x: 0,
|
|
54
|
+
y: 0
|
|
55
|
+
},
|
|
56
|
+
magnet: endpoint.magnet,
|
|
57
|
+
cap,
|
|
58
|
+
outline: node.type === "SHAPE_WITH_TEXT" && node.strokes.length > 0 ? node.strokeWeight / 2 : 0
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** Writes only the fields that differ, so a route that did not move changes nothing. */
|
|
62
|
+
function changesFor(node, changes) {
|
|
63
|
+
const differing = Object.fromEntries(Object.entries(changes).filter(([key, value]) => !isEqual(node[key], value)));
|
|
64
|
+
return Object.keys(differing).length > 0 ? differing : null;
|
|
65
|
+
}
|
|
66
|
+
function shifted(point, by) {
|
|
67
|
+
return {
|
|
68
|
+
x: point.x + by.x,
|
|
69
|
+
y: point.y + by.y
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Control points carried between the connector's own axes and its parent's, by `by`. */
|
|
73
|
+
function shiftControls(points, curve, by) {
|
|
74
|
+
return {
|
|
75
|
+
points: points.map((point) => ({
|
|
76
|
+
...point,
|
|
77
|
+
position: shifted(point.position, by)
|
|
78
|
+
})),
|
|
79
|
+
curve: curve && [shifted(curve[0], by), shifted(curve[1], by)]
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Routes a connector from the layers its ends follow and the control points it was dragged to,
|
|
84
|
+
* without laying anything out. Null when an end cannot be placed.
|
|
85
|
+
*/
|
|
86
|
+
function connectorRoute(graph, connector) {
|
|
87
|
+
const parts = connectorSublayers(graph, connector);
|
|
88
|
+
const { connectorStart, connectorEnd } = connector;
|
|
89
|
+
if (!parts || !connectorStart || !connectorEnd) return null;
|
|
90
|
+
const drawn = connectorRouteEnds(graph, connector);
|
|
91
|
+
const start = routeEnd(graph, connector, connectorStart, connector.connectorStartCap, drawn?.start);
|
|
92
|
+
const end = routeEnd(graph, connector, connectorEnd, connector.connectorEndCap, drawn?.end);
|
|
93
|
+
if (!start || !end) return null;
|
|
94
|
+
const weight = parts.line.strokes[0]?.weight ?? parts.line.strokeWeight;
|
|
95
|
+
const controls = shiftControls(connector.connectorControlPoints, connector.connectorCurveHandles, connector);
|
|
96
|
+
return {
|
|
97
|
+
start,
|
|
98
|
+
end,
|
|
99
|
+
sides: connectorSides(start, end),
|
|
100
|
+
pieces: routeConnector(connector.connectorLineType, start, end, weight, controls),
|
|
101
|
+
controls
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Where the connector, its line, and its label go for a route with the label placed on it. A
|
|
106
|
+
* connector that keeps its box places its line and label inside the box it has.
|
|
107
|
+
*/
|
|
108
|
+
function routeWrites(connector, { line, label, labelBackground }, pieces, placed, labelled, keepBox, controls) {
|
|
109
|
+
const lineBox = pieces.length > 0 ? piecesBounds(pieces) : null;
|
|
110
|
+
const boxes = compact([lineBox, labelled ? placed?.plate : null]);
|
|
111
|
+
if (boxes.length === 0) return null;
|
|
112
|
+
const bounds = computeBounds(boxes);
|
|
113
|
+
const frame = keepBox ? connector : bounds;
|
|
114
|
+
const lineOrigin = lineBox ?? bounds;
|
|
115
|
+
const local = shiftControls(controls.points, controls.curve, {
|
|
116
|
+
x: -frame.x,
|
|
117
|
+
y: -frame.y
|
|
118
|
+
});
|
|
119
|
+
const writes = [[connector, {
|
|
120
|
+
...keepBox ? {} : pick(frame, [
|
|
121
|
+
"x",
|
|
122
|
+
"y",
|
|
123
|
+
"width",
|
|
124
|
+
"height"
|
|
125
|
+
]),
|
|
126
|
+
connectorControlPoints: local.points,
|
|
127
|
+
connectorCurveHandles: local.curve
|
|
128
|
+
}], [line, {
|
|
129
|
+
x: lineOrigin.x - frame.x,
|
|
130
|
+
y: lineOrigin.y - frame.y,
|
|
131
|
+
width: lineOrigin.width,
|
|
132
|
+
height: lineOrigin.height,
|
|
133
|
+
vectorNetwork: connectorNetwork(pieces, lineOrigin, {
|
|
134
|
+
start: connector.connectorStartCap,
|
|
135
|
+
end: connector.connectorEndCap
|
|
136
|
+
})
|
|
137
|
+
}]];
|
|
138
|
+
if (!placed) return [...writes, [labelBackground, { visible: false }]];
|
|
139
|
+
const x = placed.plate.x - frame.x;
|
|
140
|
+
const y = placed.plate.y - frame.y;
|
|
141
|
+
const { width, height } = placed.plate;
|
|
142
|
+
return [
|
|
143
|
+
...writes,
|
|
144
|
+
[labelBackground, {
|
|
145
|
+
x,
|
|
146
|
+
y,
|
|
147
|
+
width,
|
|
148
|
+
height,
|
|
149
|
+
visible: labelled
|
|
150
|
+
}],
|
|
151
|
+
[label, {
|
|
152
|
+
x: x + CONNECTOR_LABEL_PADDING,
|
|
153
|
+
y: y + CONNECTOR_LABEL_PADDING,
|
|
154
|
+
visible: true
|
|
155
|
+
}]
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Routes a connector again from the layers its ends follow and lays out its line, label plate,
|
|
160
|
+
* and label to match, through `update` so the caller decides whether that is an edit or a
|
|
161
|
+
* preview. Returns whether anything moved. A connector with an end that cannot be placed keeps
|
|
162
|
+
* its route. With `keepBox`, the connector keeps its own position and size, as while a move
|
|
163
|
+
* previews. With `capture`, an elbow that was dragged keeps its new route's segments as its
|
|
164
|
+
* control points, as FigJam does after an edit reroutes one.
|
|
165
|
+
*/
|
|
166
|
+
function layoutConnector(graph, connector, update = (id, changes) => graph.updateNode(id, changes), { keepBox = false, capture = false } = {}) {
|
|
167
|
+
const parts = connectorSublayers(graph, connector);
|
|
168
|
+
const route = connectorRoute(graph, connector);
|
|
169
|
+
if (!parts || !route) return false;
|
|
170
|
+
const { label } = parts;
|
|
171
|
+
const { pieces } = route;
|
|
172
|
+
const controls = capture && connector.connectorLineType === "ELBOWED" && route.controls.points.length > 0 ? {
|
|
173
|
+
...route.controls,
|
|
174
|
+
points: elbowControlPoints(pieces)
|
|
175
|
+
} : route.controls;
|
|
176
|
+
const labelled = label.text !== "";
|
|
177
|
+
const placed = placeConnectorLabel(pieces, {
|
|
178
|
+
width: label.width + CONNECTOR_LABEL_PADDING * 2,
|
|
179
|
+
height: label.height + CONNECTOR_LABEL_PADDING * 2
|
|
180
|
+
}, connector.connectorLabelPosition);
|
|
181
|
+
const writes = routeWrites(connector, parts, labelled && placed ? placed.pieces : pieces, placed, labelled, keepBox, controls);
|
|
182
|
+
let moved = false;
|
|
183
|
+
graph.withLayoutMutations(() => {
|
|
184
|
+
for (const [node, changes] of writes ?? []) {
|
|
185
|
+
const differing = changesFor(node, changes);
|
|
186
|
+
if (!differing) continue;
|
|
187
|
+
update(node.id, differing);
|
|
188
|
+
moved = true;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
return moved;
|
|
192
|
+
}
|
|
193
|
+
/** Whether `id` is one of `ids` or lies inside one of them. */
|
|
194
|
+
function withinAny(graph, id, ids) {
|
|
195
|
+
return graph.closest(id, (node) => ids.has(node.id)) !== void 0;
|
|
196
|
+
}
|
|
197
|
+
/** The graph's connectors, from its index rather than a scan of every layer. */
|
|
198
|
+
function* connectorsIn(graph) {
|
|
199
|
+
for (const id of graph.connectorIds) {
|
|
200
|
+
const node = graph.getNode(id);
|
|
201
|
+
if (node?.type === "CONNECTOR") yield node;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The connectors with an end on one of `ids` or a layer inside them, which go when those layers
|
|
206
|
+
* are deleted, as in FigJam. Connectors inside `ids` themselves are left out.
|
|
207
|
+
*/
|
|
208
|
+
function attachedConnectors(graph, ids) {
|
|
209
|
+
const roots = new Set(ids);
|
|
210
|
+
const attached = [];
|
|
211
|
+
for (const node of connectorsIn(graph)) {
|
|
212
|
+
if (withinAny(graph, node.id, roots)) continue;
|
|
213
|
+
if ([node.connectorStart?.nodeId, node.connectorEnd?.nodeId].some((id) => id && withinAny(graph, id, roots))) attached.push(node);
|
|
214
|
+
}
|
|
215
|
+
return attached;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The connectors an edit to `ids` moves: those with an end on one of them or on a layer inside
|
|
219
|
+
* them, those inside them, and those whose line or label is among them.
|
|
220
|
+
*/
|
|
221
|
+
function connectorsAffectedBy(graph, ids) {
|
|
222
|
+
if (ids.size === 0) return [];
|
|
223
|
+
const affected = [];
|
|
224
|
+
for (const node of connectorsIn(graph)) if ([
|
|
225
|
+
node.id,
|
|
226
|
+
node.connectorStart?.nodeId,
|
|
227
|
+
node.connectorEnd?.nodeId
|
|
228
|
+
].some((id) => id && withinAny(graph, id, ids)) || node.childIds.some((id) => ids.has(id))) affected.push(node);
|
|
229
|
+
return affected;
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
export { attachedConnectors, connectorRoute, connectorsAffectedBy, layoutConnector };
|
|
233
|
+
|
|
234
|
+
//# sourceMappingURL=layout.js.map
|