@open-pencil/scene-graph 0.17.0-beta.1 → 0.17.0-beta.3
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.map +1 -1
- package/dist/arrow-caps.js +2 -5
- package/dist/arrow-caps.js.map +1 -1
- package/dist/asset-keys.d.ts +11 -1
- package/dist/asset-keys.d.ts.map +1 -1
- package/dist/asset-keys.js +16 -1
- package/dist/asset-keys.js.map +1 -1
- package/dist/behaviours/index.d.ts +2 -2
- package/dist/behaviours/index.js +2 -2
- package/dist/behaviours/kinds.d.ts +11 -5
- package/dist/behaviours/kinds.d.ts.map +1 -1
- package/dist/behaviours/kinds.js +76 -75
- package/dist/behaviours/kinds.js.map +1 -1
- package/dist/behaviours/layers.d.ts.map +1 -1
- package/dist/behaviours/layers.js +3 -2
- package/dist/behaviours/layers.js.map +1 -1
- package/dist/behaviours/model.d.ts +7 -4
- package/dist/behaviours/model.d.ts.map +1 -1
- package/dist/behaviours/model.js +16 -9
- package/dist/behaviours/model.js.map +1 -1
- package/dist/behaviours/schema.d.ts +118 -4
- package/dist/behaviours/schema.d.ts.map +1 -1
- package/dist/behaviours/schema.js +18 -3
- package/dist/behaviours/schema.js.map +1 -1
- package/dist/behaviours/spec.d.ts.map +1 -1
- package/dist/behaviours/spec.js +3 -2
- package/dist/behaviours/spec.js.map +1 -1
- package/dist/bindings.js +9 -1
- package/dist/bindings.js.map +1 -1
- package/dist/checkpoint.d.ts +31 -2
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +211 -10
- package/dist/checkpoint.js.map +1 -1
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +3 -3
- package/dist/components/properties.d.ts +18 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +66 -3
- package/dist/components/properties.js.map +1 -1
- package/dist/components/variants.d.ts +16 -10
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +39 -13
- package/dist/components/variants.js.map +1 -1
- package/dist/connectors/hit.d.ts.map +1 -1
- package/dist/connectors/hit.js +1 -7
- package/dist/connectors/hit.js.map +1 -1
- package/dist/connectors/pieces.d.ts.map +1 -1
- package/dist/connectors/pieces.js +2 -5
- package/dist/connectors/pieces.js.map +1 -1
- package/dist/constants.d.ts +6 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +17 -1
- package/dist/constants.js.map +1 -1
- package/dist/constraints.d.ts +25 -0
- package/dist/constraints.d.ts.map +1 -0
- package/dist/constraints.js +51 -0
- package/dist/constraints.js.map +1 -0
- package/dist/coordinate.d.ts +64 -1
- package/dist/coordinate.d.ts.map +1 -1
- package/dist/coordinate.js +217 -1
- package/dist/coordinate.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +17 -16
- package/dist/copy.js.map +1 -1
- 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/index.d.ts +4 -2
- package/dist/css/index.js +4 -2
- package/dist/css/text.d.ts +28 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +84 -17
- package/dist/css/text.js.map +1 -1
- package/dist/css/transform.d.ts +34 -0
- package/dist/css/transform.d.ts.map +1 -0
- package/dist/css/transform.js +320 -0
- package/dist/css/transform.js.map +1 -0
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +11 -1
- package/dist/css/values.js.map +1 -1
- 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/export-format.d.ts +14 -1
- package/dist/export-format.d.ts.map +1 -1
- package/dist/export-format.js +26 -1
- package/dist/export-format.js.map +1 -1
- package/dist/fields/text.d.ts +2 -2
- package/dist/fields/text.d.ts.map +1 -1
- package/dist/fields/text.js +2 -1
- package/dist/fields/text.js.map +1 -1
- package/dist/figjam/index.d.ts +2 -2
- package/dist/figjam/index.js +2 -2
- package/dist/figjam/palette.d.ts +13 -2
- package/dist/figjam/palette.d.ts.map +1 -1
- package/dist/figjam/palette.js +30 -2
- package/dist/figjam/palette.js.map +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.js +2 -2
- package/dist/generated/shape-with-text.d.ts +7 -2
- package/dist/generated/shape-with-text.d.ts.map +1 -1
- package/dist/generated/shape-with-text.js +20 -3
- package/dist/generated/shape-with-text.js.map +1 -1
- package/dist/geometry.d.ts +37 -46
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +80 -137
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +49 -12
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +125 -27
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts +14 -4
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +76 -11
- package/dist/group-bounds.js.map +1 -1
- package/dist/guides.d.ts +3 -1
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +5 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts +5 -0
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +57 -38
- package/dist/hit-test.js.map +1 -1
- package/dist/images.d.ts +27 -3
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +57 -3
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +8 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +1 -3
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +39 -30
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +204 -0
- package/dist/instances/kept-overrides.js.map +1 -0
- package/dist/instances/main-component.d.ts +3 -1
- package/dist/instances/main-component.d.ts.map +1 -1
- package/dist/instances/main-component.js +10 -2
- package/dist/instances/main-component.js.map +1 -1
- package/dist/instances/overrides.d.ts +4 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +18 -2
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/placement.js +55 -12
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap.js +291 -0
- package/dist/instances/swap.js.map +1 -0
- package/dist/instances/sync.js +112 -39
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +2 -1
- package/dist/node-defaults.js.map +1 -1
- package/dist/order-keys.d.ts +3 -1
- package/dist/order-keys.d.ts.map +1 -1
- package/dist/order-keys.js +6 -1
- package/dist/order-keys.js.map +1 -1
- 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/plugin-data/fields.d.ts +4 -1
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +21 -4
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/resize.d.ts +22 -11
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +227 -93
- package/dist/resize.js.map +1 -1
- package/dist/scaling/index.d.ts +3 -2
- package/dist/scaling/index.js +3 -2
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +5 -1
- package/dist/scaling/node.js.map +1 -1
- package/dist/scaling/snapshot.d.ts +25 -0
- package/dist/scaling/snapshot.d.ts.map +1 -0
- package/dist/scaling/snapshot.js +39 -0
- package/dist/scaling/snapshot.js.map +1 -0
- package/dist/scaling/tree.d.ts +24 -2
- package/dist/scaling/tree.d.ts.map +1 -1
- package/dist/scaling/tree.js +38 -15
- package/dist/scaling/tree.js.map +1 -1
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +2 -1
- package/dist/shaders/model.js.map +1 -1
- package/dist/shared-styles.d.ts +16 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +69 -2
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/authoring.d.ts +3 -2
- package/dist/slots/authoring.d.ts.map +1 -1
- package/dist/slots/authoring.js +5 -3
- package/dist/slots/authoring.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +6 -1
- package/dist/slots/content.js.map +1 -1
- package/dist/slots/frames.d.ts +2 -0
- package/dist/slots/frames.d.ts.map +1 -1
- package/dist/slots/frames.js +7 -2
- package/dist/slots/frames.js.map +1 -1
- package/dist/text/direction.d.ts +3 -1
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +5 -1
- package/dist/text/direction.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +3 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +2 -2
- package/dist/text/overflow.js.map +1 -1
- package/dist/text/picture.d.ts +1 -2
- package/dist/text/picture.d.ts.map +1 -1
- package/dist/text/picture.js +1 -4
- package/dist/text/picture.js.map +1 -1
- package/dist/transfer/apply.d.ts.map +1 -1
- package/dist/transfer/apply.js +1 -6
- package/dist/transfer/apply.js.map +1 -1
- package/dist/transfer/copied.d.ts +35 -3
- package/dist/transfer/copied.d.ts.map +1 -1
- package/dist/transfer/copied.js +44 -13
- package/dist/transfer/copied.js.map +1 -1
- package/dist/transfer/dependencies.d.ts +38 -0
- package/dist/transfer/dependencies.d.ts.map +1 -0
- package/dist/transfer/dependencies.js +100 -0
- package/dist/transfer/dependencies.js.map +1 -0
- package/dist/transfer/history.js +0 -1
- package/dist/transfer/history.js.map +1 -1
- package/dist/transfer/index.d.ts +5 -3
- package/dist/transfer/index.js +5 -3
- package/dist/transfer/nodes.d.ts.map +1 -1
- package/dist/transfer/nodes.js +16 -19
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/transfer/plan.d.ts +0 -1
- package/dist/transfer/plan.js +3 -5
- package/dist/transfer/plan.js.map +1 -1
- package/dist/transfer/remove.js +5 -2
- package/dist/transfer/remove.js.map +1 -1
- package/dist/transfer/resources.d.ts +21 -0
- package/dist/transfer/resources.d.ts.map +1 -0
- package/dist/transfer/resources.js +38 -0
- package/dist/transfer/resources.js.map +1 -0
- package/dist/transfer/variables.d.ts +8 -1
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +24 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +73 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +28 -3
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +24 -7
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +37 -11
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +122 -74
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/fields.d.ts +19 -1
- package/dist/variables/fields.d.ts.map +1 -1
- package/dist/variables/fields.js +36 -1
- package/dist/variables/fields.js.map +1 -1
- package/dist/variables/formula/check.d.ts +1 -1
- package/dist/variables/formula/index.d.ts +2 -2
- package/dist/variables/formula/index.js +1 -1
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/formula/print.d.ts +1 -1
- package/dist/variables/formula/signatures.js +1 -1
- package/dist/variables/index.d.ts +7 -7
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +57 -26
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +57 -0
- package/dist/variables/paints.d.ts.map +1 -0
- package/dist/variables/paints.js +231 -0
- package/dist/variables/paints.js.map +1 -0
- package/dist/variables/resolution.d.ts +14 -11
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +36 -17
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +17 -0
- package/dist/variables/subtree.js.map +1 -0
- package/dist/vector-network.d.ts.map +1 -1
- package/dist/vector-network.js +2 -8
- package/dist/vector-network.js.map +1 -1
- package/package.json +14 -1
- package/src/arrow-caps.ts +2 -5
- package/src/asset-keys.ts +20 -0
- package/src/behaviours/kinds.ts +51 -34
- package/src/behaviours/layers.ts +4 -2
- package/src/behaviours/model.ts +22 -11
- package/src/behaviours/schema.ts +20 -4
- package/src/behaviours/spec.ts +8 -2
- package/src/bindings.ts +11 -2
- package/src/checkpoint.ts +319 -17
- package/src/components/properties.ts +101 -2
- package/src/components/variants.ts +51 -30
- package/src/connectors/hit.ts +1 -12
- package/src/connectors/pieces.ts +2 -5
- package/src/constants.ts +17 -0
- package/src/constraints.ts +60 -0
- package/src/coordinate.ts +220 -0
- package/src/copy.ts +18 -19
- package/src/css/blend.ts +27 -0
- package/src/css/index.ts +18 -1
- package/src/css/text.ts +85 -17
- package/src/css/transform.ts +266 -0
- package/src/css/values.ts +8 -0
- package/src/cubic.ts +14 -0
- package/src/export-format.ts +29 -0
- package/src/fields/text.ts +3 -1
- package/src/figjam/palette.ts +29 -1
- package/src/generated/shape-with-text.ts +28 -2
- package/src/geometry.ts +97 -206
- package/src/graph.ts +155 -45
- package/src/group-bounds.ts +84 -17
- package/src/guides.ts +5 -0
- package/src/hit-test.ts +93 -64
- package/src/images.ts +71 -3
- package/src/instances/fields.ts +8 -0
- package/src/instances/index.ts +62 -31
- package/src/instances/kept-overrides.ts +280 -0
- package/src/instances/main-component.ts +12 -0
- package/src/instances/overrides.ts +27 -1
- package/src/instances/placement.ts +63 -10
- package/src/instances/swap.ts +456 -0
- package/src/instances/sync.ts +176 -50
- package/src/node-defaults.ts +3 -1
- package/src/order-keys.ts +6 -0
- 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/plugin-data/fields.ts +21 -2
- package/src/resize.ts +267 -119
- package/src/scaling/index.ts +9 -1
- package/src/scaling/node.ts +9 -1
- package/src/scaling/snapshot.ts +51 -0
- package/src/scaling/tree.ts +63 -19
- package/src/shaders/model.ts +2 -3
- package/src/shared-styles.ts +90 -1
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +6 -1
- package/src/slots/frames.ts +9 -7
- package/src/text/direction.ts +5 -0
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +2 -2
- package/src/text/picture.ts +0 -4
- package/src/transfer/apply.ts +1 -13
- package/src/transfer/copied.ts +83 -15
- package/src/transfer/dependencies.ts +126 -0
- package/src/transfer/history.ts +0 -6
- package/src/transfer/index.ts +20 -2
- package/src/transfer/nodes.ts +17 -31
- package/src/transfer/plan.ts +3 -11
- package/src/transfer/remove.ts +5 -2
- package/src/transfer/resources.ts +54 -0
- package/src/transfer/variables.ts +34 -0
- package/src/types.ts +83 -1
- package/src/undo.ts +48 -10
- package/src/variables/bindings.ts +152 -88
- package/src/variables/fields.ts +46 -1
- package/src/variables/formula/index.ts +3 -1
- package/src/variables/index.ts +90 -39
- package/src/variables/paints.ts +296 -0
- package/src/variables/resolution.ts +39 -28
- package/src/variables/subtree.ts +15 -0
- package/src/vector-network.ts +4 -2
|
@@ -1,32 +1,58 @@
|
|
|
1
|
+
import { compact, uniq } from "es-toolkit/array";
|
|
1
2
|
//#region src/components/variants.ts
|
|
2
3
|
/** Variants in reading order on the canvas: top to bottom, then left to right, then by name. */
|
|
3
4
|
function compareCanvasPosition(a, b) {
|
|
4
5
|
return a.y - b.y || a.x - b.x || a.name.localeCompare(b.name);
|
|
5
6
|
}
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
8
|
+
* Whether `a` comes before `b` reading the set as Figma does: variants whose rows overlap, edges
|
|
9
|
+
* touching included, read left to right, and others top to bottom.
|
|
10
|
+
*/
|
|
11
|
+
function readsBefore(a, b) {
|
|
12
|
+
return a.y <= b.y + b.height && b.y <= a.y + a.height ? a.x < b.x || a.x === b.x && a.y < b.y : a.y < b.y;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A component set's default variant, the one an instance starts as: the first in reading order,
|
|
16
|
+
* and the first in layer order of those at the same place (measured in Figma desktop 126).
|
|
9
17
|
*/
|
|
10
18
|
function defaultVariant(graph, set) {
|
|
11
|
-
|
|
19
|
+
let first;
|
|
20
|
+
for (const child of graph.getChildren(set.id)) {
|
|
21
|
+
if (child.type !== "COMPONENT") continue;
|
|
22
|
+
if (!first || readsBefore(child, first)) first = child;
|
|
23
|
+
}
|
|
24
|
+
return first;
|
|
12
25
|
}
|
|
13
26
|
/**
|
|
14
|
-
* The value a variant property starts at:
|
|
15
|
-
*
|
|
27
|
+
* The value a variant property starts at: the default variant's, as Figma reads it whatever
|
|
28
|
+
* default the document records, and follows when another variant moves to the top left. The
|
|
29
|
+
* recorded default stands only while the default variant has no value for the property.
|
|
16
30
|
*/
|
|
17
31
|
function variantDefaultValue(graph, set, property) {
|
|
18
|
-
|
|
19
|
-
return defaultVariant(graph, set)?.componentPropertyValues[property.name] ?? property.defaultValue;
|
|
32
|
+
return defaultVariant(graph, set)?.componentPropertyValues[property.name] || property.defaultValue;
|
|
20
33
|
}
|
|
21
34
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
35
|
+
* A variant property's values: the ones the document records, then any its variants use that it
|
|
36
|
+
* does not, since older documents record none and a set's page may have loaded only some
|
|
37
|
+
* variants.
|
|
24
38
|
*/
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
return
|
|
39
|
+
function variantOptions(graph, set, property) {
|
|
40
|
+
const used = graph.getChildren(set.id).map((child) => child.type === "COMPONENT" ? child.componentPropertyValues[property.name] : "");
|
|
41
|
+
return compact(uniq([...property.variantOptions ?? [], ...used]));
|
|
42
|
+
}
|
|
43
|
+
/** A set's definition with a variant property's values and default filled in from its variants. */
|
|
44
|
+
function resolvedVariantDefinition(graph, set, definition) {
|
|
45
|
+
if (definition.type !== "VARIANT") return definition;
|
|
46
|
+
const options = {
|
|
47
|
+
...definition,
|
|
48
|
+
variantOptions: variantOptions(graph, set, definition)
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
...options,
|
|
52
|
+
defaultValue: variantDefaultValue(graph, set, options)
|
|
53
|
+
};
|
|
28
54
|
}
|
|
29
55
|
//#endregion
|
|
30
|
-
export { compareCanvasPosition, defaultVariant,
|
|
56
|
+
export { compareCanvasPosition, defaultVariant, resolvedVariantDefinition, variantDefaultValue, variantOptions };
|
|
31
57
|
|
|
32
58
|
//# sourceMappingURL=variants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variants.js","names":[],"sources":["../../src/components/variants.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { SceneNode } from '../types'\n\n/** Variants in reading order on the canvas: top to bottom, then left to right, then by name. */\nexport function compareCanvasPosition(a: SceneNode, b: SceneNode): number {\n return a.y - b.y || a.x - b.x || a.name.localeCompare(b.name)\n}\n\n/**\n * A component set's default variant, the one an instance starts as: the
|
|
1
|
+
{"version":3,"file":"variants.js","names":[],"sources":["../../src/components/variants.ts"],"sourcesContent":["import { compact, uniq } from 'es-toolkit/array'\n\nimport type { SceneGraph } from '../graph'\nimport type { ComponentPropertyDefinition, SceneNode } from '../types'\n\n/** Variants in reading order on the canvas: top to bottom, then left to right, then by name. */\nexport function compareCanvasPosition(a: SceneNode, b: SceneNode): number {\n return a.y - b.y || a.x - b.x || a.name.localeCompare(b.name)\n}\n\n/**\n * Whether `a` comes before `b` reading the set as Figma does: variants whose rows overlap, edges\n * touching included, read left to right, and others top to bottom.\n */\nfunction readsBefore(a: SceneNode, b: SceneNode): boolean {\n const sameRow = a.y <= b.y + b.height && b.y <= a.y + a.height\n return sameRow ? a.x < b.x || (a.x === b.x && a.y < b.y) : a.y < b.y\n}\n\n/**\n * A component set's default variant, the one an instance starts as: the first in reading order,\n * and the first in layer order of those at the same place (measured in Figma desktop 126).\n */\nexport function defaultVariant(graph: SceneGraph, set: SceneNode): SceneNode | undefined {\n let first: SceneNode | undefined\n for (const child of graph.getChildren(set.id)) {\n if (child.type !== 'COMPONENT') continue\n if (!first || readsBefore(child, first)) first = child\n }\n return first\n}\n\n/**\n * The value a variant property starts at: the default variant's, as Figma reads it whatever\n * default the document records, and follows when another variant moves to the top left. The\n * recorded default stands only while the default variant has no value for the property.\n */\nexport function variantDefaultValue(\n graph: SceneGraph,\n set: SceneNode,\n property: { name: string; defaultValue: string }\n): string {\n const value = defaultVariant(graph, set)?.componentPropertyValues[property.name]\n return value || property.defaultValue\n}\n\n/**\n * A variant property's values: the ones the document records, then any its variants use that it\n * does not, since older documents record none and a set's page may have loaded only some\n * variants.\n */\nexport function variantOptions(\n graph: SceneGraph,\n set: SceneNode,\n property: { name: string; variantOptions?: string[] }\n): string[] {\n const used = graph\n .getChildren(set.id)\n .map((child) =>\n child.type === 'COMPONENT' ? child.componentPropertyValues[property.name] : ''\n )\n return compact(uniq([...(property.variantOptions ?? []), ...used]))\n}\n\n/** A set's definition with a variant property's values and default filled in from its variants. */\nexport function resolvedVariantDefinition(\n graph: SceneGraph,\n set: SceneNode,\n definition: ComponentPropertyDefinition\n): ComponentPropertyDefinition {\n if (definition.type !== 'VARIANT') return definition\n const options = { ...definition, variantOptions: variantOptions(graph, set, definition) }\n return { ...options, defaultValue: variantDefaultValue(graph, set, options) }\n}\n"],"mappings":";;;AAMA,SAAgB,sBAAsB,GAAc,GAAsB;CACxE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,cAAc,EAAE,IAAI;AAC9D;;;;;AAMA,SAAS,YAAY,GAAc,GAAuB;CAExD,OADgB,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,SACvC,EAAE,IAAI,EAAE,KAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAK,EAAE,IAAI,EAAE;AACrE;;;;;AAMA,SAAgB,eAAe,OAAmB,KAAuC;CACvF,IAAI;CACJ,KAAK,MAAM,SAAS,MAAM,YAAY,IAAI,EAAE,GAAG;EAC7C,IAAI,MAAM,SAAS,aAAa;EAChC,IAAI,CAAC,SAAS,YAAY,OAAO,KAAK,GAAG,QAAQ;CACnD;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,oBACd,OACA,KACA,UACQ;CAER,OADc,eAAe,OAAO,GAAG,CAAC,EAAE,wBAAwB,SAAS,SAC3D,SAAS;AAC3B;;;;;;AAOA,SAAgB,eACd,OACA,KACA,UACU;CACV,MAAM,OAAO,MACV,YAAY,IAAI,EAAE,CAAC,CACnB,KAAK,UACJ,MAAM,SAAS,cAAc,MAAM,wBAAwB,SAAS,QAAQ,EAC9E;CACF,OAAO,QAAQ,KAAK,CAAC,GAAI,SAAS,kBAAkB,CAAC,GAAI,GAAG,IAAI,CAAC,CAAC;AACpE;;AAGA,SAAgB,0BACd,OACA,KACA,YAC6B;CAC7B,IAAI,WAAW,SAAS,WAAW,OAAO;CAC1C,MAAM,UAAU;EAAE,GAAG;EAAY,gBAAgB,eAAe,OAAO,KAAK,UAAU;CAAE;CACxF,OAAO;EAAE,GAAG;EAAS,cAAc,oBAAoB,OAAO,KAAK,OAAO;CAAE;AAC9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hit.d.ts","names":[],"sources":["../../src/connectors/hit.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"hit.d.ts","names":[],"sources":["../../src/connectors/hit.ts"],"mappings":";;;;;;;iBAiBgB,kBACd,OAAO,YACP,WAAW,WACX,YACA,YACA"}
|
package/dist/connectors/hit.js
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import Matrix from "../matrix.js";
|
|
2
2
|
import { getWorldMatrix } from "../coordinate.js";
|
|
3
3
|
import { connectorSublayers } from "./sublayers.js";
|
|
4
|
+
import { distanceToSegment } from "../outline/point.js";
|
|
4
5
|
import { isStraight, pointAt } from "./pieces.js";
|
|
5
6
|
//#region src/connectors/hit.ts
|
|
6
7
|
/** How far from a line, beyond half its stroke, a point still lands on it, in canvas units. */
|
|
7
8
|
const CONNECTOR_HIT_SLOP = 4;
|
|
8
9
|
/** Points sampled along a curved segment to measure distance to it. */
|
|
9
10
|
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
11
|
/**
|
|
18
12
|
* Whether a canvas point lands on a connector's line: within half its stroke and a few units of
|
|
19
13
|
* slop, plus `pad`. A connector is picked by its line, not by the box around its route.
|
|
@@ -1 +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
|
|
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 { distanceToSegment } from '../outline/point'\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\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;;;;;AAMtB,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pieces.d.ts","names":[],"sources":["../../src/connectors/pieces.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"pieces.d.ts","names":[],"sources":["../../src/connectors/pieces.ts"],"mappings":";;;;UAMiB;EACf,MAAM;EACN,IAAI;EACJ,YAAY;EACZ,UAAU;;;;;;;iBAgGI,iBACd,QAAQ,kBACR,QAAQ,QACR;EAAQ,OAAO;EAAW,KAAK;IAC9B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { cubicPoint } from "../cubic.js";
|
|
1
2
|
import { computeBounds } from "../geometry.js";
|
|
2
3
|
//#region src/connectors/pieces.ts
|
|
3
4
|
const ZERO = {
|
|
@@ -46,11 +47,7 @@ function pointAt(piece, t) {
|
|
|
46
47
|
y: a.y + (b.y - a.y) * t
|
|
47
48
|
};
|
|
48
49
|
const [c1, c2] = controls(piece);
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
x: u * u * u * a.x + 3 * u * u * t * c1.x + 3 * u * t * t * c2.x + t * t * t * b.x,
|
|
52
|
-
y: u * u * u * a.y + 3 * u * u * t * c1.y + 3 * u * t * t * c2.y + t * t * t * b.y
|
|
53
|
-
};
|
|
50
|
+
return cubicPoint(a, c1, c2, b, t);
|
|
54
51
|
}
|
|
55
52
|
function derivativeAt(piece, t) {
|
|
56
53
|
const { from: a, to: b } = piece;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pieces.js","names":[],"sources":["../../src/connectors/pieces.ts"],"sourcesContent":["import { computeBounds } from '../geometry'\nimport type { Rect, Vector } from '../primitives'\nimport type { StrokeCap, VectorNetwork } from '../types'\n\n/** One piece of a route: a straight run when both handles are zero, else a cubic. */\nexport interface ConnectorPiece {\n from: Vector\n to: Vector\n handleFrom: Vector\n handleTo: Vector\n}\n\nexport const ZERO: Vector = { x: 0, y: 0 }\nexport const EPSILON = 1e-6\n/** Points sampled along a curved piece to bound it. */\nconst CURVE_BOUND_SAMPLES = 16\n\nexport function along(point: Vector, direction: Vector, distance: number): Vector {\n return { x: point.x + direction.x * distance, y: point.y + direction.y * distance }\n}\n\nexport function isStraight(piece: ConnectorPiece): boolean {\n const { handleFrom: h0, handleTo: h1 } = piece\n return h0.x === 0 && h0.y === 0 && h1.x === 0 && h1.y === 0\n}\n\nexport function straightPieces(points: Vector[]): ConnectorPiece[] {\n return points\n .slice(1)\n .map((to, index) => ({ from: points[index], to, handleFrom: ZERO, handleTo: ZERO }))\n}\n\nexport function pieceLength(piece: ConnectorPiece): number {\n return Math.hypot(piece.to.x - piece.from.x, piece.to.y - piece.from.y)\n}\n\nfunction controls(piece: ConnectorPiece): [Vector, Vector] {\n const { from: a, to: b } = piece\n return [\n { x: a.x + piece.handleFrom.x, y: a.y + piece.handleFrom.y },\n { x: b.x + piece.handleTo.x, y: b.y + piece.handleTo.y }\n ]\n}\n\n/** The point at `t` along a piece; a straight run is parametrised by length. */\nexport function pointAt(piece: ConnectorPiece, t: number): Vector {\n const { from: a, to: b } = piece\n if (isStraight(piece)) return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t }\n const [c1, c2] = controls(piece)\n
|
|
1
|
+
{"version":3,"file":"pieces.js","names":[],"sources":["../../src/connectors/pieces.ts"],"sourcesContent":["import { cubicPoint } from '../cubic'\nimport { computeBounds } from '../geometry'\nimport type { Rect, Vector } from '../primitives'\nimport type { StrokeCap, VectorNetwork } from '../types'\n\n/** One piece of a route: a straight run when both handles are zero, else a cubic. */\nexport interface ConnectorPiece {\n from: Vector\n to: Vector\n handleFrom: Vector\n handleTo: Vector\n}\n\nexport const ZERO: Vector = { x: 0, y: 0 }\nexport const EPSILON = 1e-6\n/** Points sampled along a curved piece to bound it. */\nconst CURVE_BOUND_SAMPLES = 16\n\nexport function along(point: Vector, direction: Vector, distance: number): Vector {\n return { x: point.x + direction.x * distance, y: point.y + direction.y * distance }\n}\n\nexport function isStraight(piece: ConnectorPiece): boolean {\n const { handleFrom: h0, handleTo: h1 } = piece\n return h0.x === 0 && h0.y === 0 && h1.x === 0 && h1.y === 0\n}\n\nexport function straightPieces(points: Vector[]): ConnectorPiece[] {\n return points\n .slice(1)\n .map((to, index) => ({ from: points[index], to, handleFrom: ZERO, handleTo: ZERO }))\n}\n\nexport function pieceLength(piece: ConnectorPiece): number {\n return Math.hypot(piece.to.x - piece.from.x, piece.to.y - piece.from.y)\n}\n\nfunction controls(piece: ConnectorPiece): [Vector, Vector] {\n const { from: a, to: b } = piece\n return [\n { x: a.x + piece.handleFrom.x, y: a.y + piece.handleFrom.y },\n { x: b.x + piece.handleTo.x, y: b.y + piece.handleTo.y }\n ]\n}\n\n/** The point at `t` along a piece; a straight run is parametrised by length. */\nexport function pointAt(piece: ConnectorPiece, t: number): Vector {\n const { from: a, to: b } = piece\n if (isStraight(piece)) return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t }\n const [c1, c2] = controls(piece)\n return cubicPoint(a, c1, c2, b, t)\n}\n\nfunction derivativeAt(piece: ConnectorPiece, t: number): Vector {\n const { from: a, to: b } = piece\n const [c1, c2] = controls(piece)\n const u = 1 - t\n return {\n x: 3 * u * u * (c1.x - a.x) + 6 * u * t * (c2.x - c1.x) + 3 * t * t * (b.x - c2.x),\n y: 3 * u * u * (c1.y - a.y) + 6 * u * t * (c2.y - c1.y) + 3 * t * t * (b.y - c2.y)\n }\n}\n\n/** The part of a piece from `t0` to `t1`, its handles as de Casteljau splits them. */\nexport function subPiece(piece: ConnectorPiece, t0: number, t1: number): ConnectorPiece {\n const from = pointAt(piece, t0)\n const to = pointAt(piece, t1)\n if (isStraight(piece)) return { from, to, handleFrom: ZERO, handleTo: ZERO }\n const span = (t1 - t0) / 3\n const d0 = derivativeAt(piece, t0)\n const d1 = derivativeAt(piece, t1)\n return {\n from,\n to,\n handleFrom: { x: d0.x * span, y: d0.y * span },\n handleTo: { x: -d1.x * span, y: -d1.y * span }\n }\n}\n\n/** Where the ray from `from`, inside `box`, towards `toward` leaves it. */\nexport function exitPoint(box: Rect, from: Vector, toward: Vector): Vector {\n const dx = toward.x - from.x\n const dy = toward.y - from.y\n const tx = dx === 0 ? Infinity : ((dx > 0 ? box.x + box.width : box.x) - from.x) / dx\n const ty = dy === 0 ? Infinity : ((dy > 0 ? box.y + box.height : box.y) - from.y) / dy\n const t = Math.max(0, Math.min(tx, ty, 1))\n return { x: from.x + dx * t, y: from.y + dy * t }\n}\n\n/** The box a route's pieces cover, curves sampled along their length. */\nexport function piecesBounds(pieces: ConnectorPiece[]): Rect {\n const points: Rect[] = []\n for (const piece of pieces) {\n const samples = isStraight(piece) ? 1 : CURVE_BOUND_SAMPLES\n for (let step = 0; step <= samples; step++) {\n points.push({ ...pointAt(piece, step / samples), width: 0, height: 0 })\n }\n }\n return computeBounds(points)\n}\n\n/**\n * A route as a vector network: pieces that meet share a vertex, so elbows round their corners,\n * and a cut leaves two runs. The first and last vertices carry the connector's caps, as Figma\n * stores them.\n */\nexport function connectorNetwork(\n pieces: ConnectorPiece[],\n origin: Vector,\n caps: { start: StrokeCap; end: StrokeCap }\n): VectorNetwork {\n const network: VectorNetwork = { vertices: [], segments: [], regions: [] }\n const vertexAt = (point: Vector) => {\n const last = network.vertices.at(-1)\n const x = point.x - origin.x\n const y = point.y - origin.y\n if (last && Math.abs(last.x - x) < EPSILON && Math.abs(last.y - y) < EPSILON) {\n return network.vertices.length - 1\n }\n network.vertices.push({ x, y })\n return network.vertices.length - 1\n }\n for (const piece of pieces) {\n const start = vertexAt(piece.from)\n const end = vertexAt(piece.to)\n if (start === end) continue\n network.segments.push({\n start,\n end,\n tangentStart: { ...piece.handleFrom },\n tangentEnd: { ...piece.handleTo }\n })\n }\n const first = network.vertices.at(0)\n const last = network.vertices.at(-1)\n if (first && last && first !== last) {\n first.strokeCap = caps.start\n last.strokeCap = caps.end\n }\n return network\n}\n"],"mappings":";;;AAaA,MAAa,OAAe;CAAE,GAAG;CAAG,GAAG;AAAE;AACzC,MAAa,UAAU;;AAEvB,MAAM,sBAAsB;AAE5B,SAAgB,MAAM,OAAe,WAAmB,UAA0B;CAChF,OAAO;EAAE,GAAG,MAAM,IAAI,UAAU,IAAI;EAAU,GAAG,MAAM,IAAI,UAAU,IAAI;CAAS;AACpF;AAEA,SAAgB,WAAW,OAAgC;CACzD,MAAM,EAAE,YAAY,IAAI,UAAU,OAAO;CACzC,OAAO,GAAG,MAAM,KAAK,GAAG,MAAM,KAAK,GAAG,MAAM,KAAK,GAAG,MAAM;AAC5D;AAEA,SAAgB,eAAe,QAAoC;CACjE,OAAO,OACJ,MAAM,CAAC,CAAC,CACR,KAAK,IAAI,WAAW;EAAE,MAAM,OAAO;EAAQ;EAAI,YAAY;EAAM,UAAU;CAAK,EAAE;AACvF;AAEA,SAAgB,YAAY,OAA+B;CACzD,OAAO,KAAK,MAAM,MAAM,GAAG,IAAI,MAAM,KAAK,GAAG,MAAM,GAAG,IAAI,MAAM,KAAK,CAAC;AACxE;AAEA,SAAS,SAAS,OAAyC;CACzD,MAAM,EAAE,MAAM,GAAG,IAAI,MAAM;CAC3B,OAAO,CACL;EAAE,GAAG,EAAE,IAAI,MAAM,WAAW;EAAG,GAAG,EAAE,IAAI,MAAM,WAAW;CAAE,GAC3D;EAAE,GAAG,EAAE,IAAI,MAAM,SAAS;EAAG,GAAG,EAAE,IAAI,MAAM,SAAS;CAAE,CACzD;AACF;;AAGA,SAAgB,QAAQ,OAAuB,GAAmB;CAChE,MAAM,EAAE,MAAM,GAAG,IAAI,MAAM;CAC3B,IAAI,WAAW,KAAK,GAAG,OAAO;EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK;EAAG,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK;CAAE;CACnF,MAAM,CAAC,IAAI,MAAM,SAAS,KAAK;CAC/B,OAAO,WAAW,GAAG,IAAI,IAAI,GAAG,CAAC;AACnC;AAEA,SAAS,aAAa,OAAuB,GAAmB;CAC9D,MAAM,EAAE,MAAM,GAAG,IAAI,MAAM;CAC3B,MAAM,CAAC,IAAI,MAAM,SAAS,KAAK;CAC/B,MAAM,IAAI,IAAI;CACd,OAAO;EACL,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,IAAI,KAAK,GAAG,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,EAAE,IAAI,GAAG;EAChF,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,IAAI,KAAK,GAAG,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,EAAE,IAAI,GAAG;CAClF;AACF;;AAGA,SAAgB,SAAS,OAAuB,IAAY,IAA4B;CACtF,MAAM,OAAO,QAAQ,OAAO,EAAE;CAC9B,MAAM,KAAK,QAAQ,OAAO,EAAE;CAC5B,IAAI,WAAW,KAAK,GAAG,OAAO;EAAE;EAAM;EAAI,YAAY;EAAM,UAAU;CAAK;CAC3E,MAAM,QAAQ,KAAK,MAAM;CACzB,MAAM,KAAK,aAAa,OAAO,EAAE;CACjC,MAAM,KAAK,aAAa,OAAO,EAAE;CACjC,OAAO;EACL;EACA;EACA,YAAY;GAAE,GAAG,GAAG,IAAI;GAAM,GAAG,GAAG,IAAI;EAAK;EAC7C,UAAU;GAAE,GAAG,CAAC,GAAG,IAAI;GAAM,GAAG,CAAC,GAAG,IAAI;EAAK;CAC/C;AACF;;AAGA,SAAgB,UAAU,KAAW,MAAc,QAAwB;CACzE,MAAM,KAAK,OAAO,IAAI,KAAK;CAC3B,MAAM,KAAK,OAAO,IAAI,KAAK;CAC3B,MAAM,KAAK,OAAO,IAAI,aAAa,KAAK,IAAI,IAAI,IAAI,IAAI,QAAQ,IAAI,KAAK,KAAK,KAAK;CACnF,MAAM,KAAK,OAAO,IAAI,aAAa,KAAK,IAAI,IAAI,IAAI,IAAI,SAAS,IAAI,KAAK,KAAK,KAAK;CACpF,MAAM,IAAI,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC;CACzC,OAAO;EAAE,GAAG,KAAK,IAAI,KAAK;EAAG,GAAG,KAAK,IAAI,KAAK;CAAE;AAClD;;AAGA,SAAgB,aAAa,QAAgC;CAC3D,MAAM,SAAiB,CAAC;CACxB,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,UAAU,WAAW,KAAK,IAAI,IAAI;EACxC,KAAK,IAAI,OAAO,GAAG,QAAQ,SAAS,QAClC,OAAO,KAAK;GAAE,GAAG,QAAQ,OAAO,OAAO,OAAO;GAAG,OAAO;GAAG,QAAQ;EAAE,CAAC;CAE1E;CACA,OAAO,cAAc,MAAM;AAC7B;;;;;;AAOA,SAAgB,iBACd,QACA,QACA,MACe;CACf,MAAM,UAAyB;EAAE,UAAU,CAAC;EAAG,UAAU,CAAC;EAAG,SAAS,CAAC;CAAE;CACzE,MAAM,YAAY,UAAkB;EAClC,MAAM,OAAO,QAAQ,SAAS,GAAG,EAAE;EACnC,MAAM,IAAI,MAAM,IAAI,OAAO;EAC3B,MAAM,IAAI,MAAM,IAAI,OAAO;EAC3B,IAAI,QAAQ,KAAK,IAAI,KAAK,IAAI,CAAC,IAAA,QAAe,KAAK,IAAI,KAAK,IAAI,CAAC,IAAA,MAC/D,OAAO,QAAQ,SAAS,SAAS;EAEnC,QAAQ,SAAS,KAAK;GAAE;GAAG;EAAE,CAAC;EAC9B,OAAO,QAAQ,SAAS,SAAS;CACnC;CACA,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,QAAQ,SAAS,MAAM,IAAI;EACjC,MAAM,MAAM,SAAS,MAAM,EAAE;EAC7B,IAAI,UAAU,KAAK;EACnB,QAAQ,SAAS,KAAK;GACpB;GACA;GACA,cAAc,EAAE,GAAG,MAAM,WAAW;GACpC,YAAY,EAAE,GAAG,MAAM,SAAS;EAClC,CAAC;CACH;CACA,MAAM,QAAQ,QAAQ,SAAS,GAAG,CAAC;CACnC,MAAM,OAAO,QAAQ,SAAS,GAAG,EAAE;CACnC,IAAI,SAAS,QAAQ,UAAU,MAAM;EACnC,MAAM,YAAY,KAAK;EACvB,KAAK,YAAY,KAAK;CACxB;CACA,OAAO;AACT"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { Color } from "./primitives/index.js";
|
|
2
|
+
import { GlassEffectParams } from "./types.js";
|
|
2
3
|
//#region src/constants.d.ts
|
|
3
4
|
declare const BLACK: Color;
|
|
4
5
|
declare const WHITE: Color;
|
|
5
6
|
declare const TRANSPARENT: Color;
|
|
7
|
+
/** The lens of a glass effect whose values are missing: the least it can be, so it bends nothing. */
|
|
8
|
+
declare const UNSET_GLASS: Readonly<GlassEffectParams>;
|
|
9
|
+
/** The lens a new glass effect starts with when nothing sets its values. */
|
|
10
|
+
declare const DEFAULT_GLASS: Readonly<GlassEffectParams>;
|
|
6
11
|
declare const DEFAULT_FONT_FAMILY = "Inter";
|
|
7
12
|
declare const DEFAULT_STROKE_MITER_LIMIT = 4;
|
|
8
13
|
declare const DEFAULT_STROKE_WEIGHT = 1;
|
|
9
14
|
//#endregion
|
|
10
|
-
export { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_STROKE_MITER_LIMIT, DEFAULT_STROKE_WEIGHT, TRANSPARENT, WHITE };
|
|
15
|
+
export { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_GLASS, DEFAULT_STROKE_MITER_LIMIT, DEFAULT_STROKE_WEIGHT, TRANSPARENT, UNSET_GLASS, WHITE };
|
|
11
16
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;;cAGa,OAAO;cACP,OAAO;cACP,aAAa;;cAEb,aAAa,SAAS;;cAQtB,eAAe,SAAS;cAOxB;cACA;cACA"}
|
package/dist/constants.js
CHANGED
|
@@ -17,10 +17,26 @@ const TRANSPARENT = {
|
|
|
17
17
|
b: 0,
|
|
18
18
|
a: 0
|
|
19
19
|
};
|
|
20
|
+
/** The lens of a glass effect whose values are missing: the least it can be, so it bends nothing. */
|
|
21
|
+
const UNSET_GLASS = {
|
|
22
|
+
refraction: 0,
|
|
23
|
+
depth: 1,
|
|
24
|
+
lightAngle: 0,
|
|
25
|
+
lightIntensity: 0,
|
|
26
|
+
dispersion: 0
|
|
27
|
+
};
|
|
28
|
+
/** The lens a new glass effect starts with when nothing sets its values. */
|
|
29
|
+
const DEFAULT_GLASS = {
|
|
30
|
+
refraction: .5,
|
|
31
|
+
depth: 20,
|
|
32
|
+
lightAngle: -45,
|
|
33
|
+
lightIntensity: .5,
|
|
34
|
+
dispersion: 0
|
|
35
|
+
};
|
|
20
36
|
const DEFAULT_FONT_FAMILY = "Inter";
|
|
21
37
|
const DEFAULT_STROKE_MITER_LIMIT = 4;
|
|
22
38
|
const DEFAULT_STROKE_WEIGHT = 1;
|
|
23
39
|
//#endregion
|
|
24
|
-
export { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_STROKE_MITER_LIMIT, DEFAULT_STROKE_WEIGHT, TRANSPARENT, WHITE };
|
|
40
|
+
export { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_GLASS, DEFAULT_STROKE_MITER_LIMIT, DEFAULT_STROKE_WEIGHT, TRANSPARENT, UNSET_GLASS, WHITE };
|
|
25
41
|
|
|
26
42
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { Color } from './primitives'\n\nexport const BLACK: Color = { r: 0, g: 0, b: 0, a: 1 }\nexport const WHITE: Color = { r: 1, g: 1, b: 1, a: 1 }\nexport const TRANSPARENT: Color = { r: 0, g: 0, b: 0, a: 0 }\nexport const DEFAULT_FONT_FAMILY = 'Inter'\nexport const DEFAULT_STROKE_MITER_LIMIT = 4\nexport const DEFAULT_STROKE_WEIGHT = 1\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { Color } from './primitives'\nimport type { GlassEffectParams } from './types'\n\nexport const BLACK: Color = { r: 0, g: 0, b: 0, a: 1 }\nexport const WHITE: Color = { r: 1, g: 1, b: 1, a: 1 }\nexport const TRANSPARENT: Color = { r: 0, g: 0, b: 0, a: 0 }\n/** The lens of a glass effect whose values are missing: the least it can be, so it bends nothing. */\nexport const UNSET_GLASS: Readonly<GlassEffectParams> = {\n refraction: 0,\n depth: 1,\n lightAngle: 0,\n lightIntensity: 0,\n dispersion: 0\n}\n/** The lens a new glass effect starts with when nothing sets its values. */\nexport const DEFAULT_GLASS: Readonly<GlassEffectParams> = {\n refraction: 0.5,\n depth: 20,\n lightAngle: -45,\n lightIntensity: 0.5,\n dispersion: 0\n}\nexport const DEFAULT_FONT_FAMILY = 'Inter'\nexport const DEFAULT_STROKE_MITER_LIMIT = 4\nexport const DEFAULT_STROKE_WEIGHT = 1\n"],"mappings":";AAGA,MAAa,QAAe;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;AACrD,MAAa,QAAe;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;AACrD,MAAa,cAAqB;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;;AAE3D,MAAa,cAA2C;CACtD,YAAY;CACZ,OAAO;CACP,YAAY;CACZ,gBAAgB;CAChB,YAAY;AACd;;AAEA,MAAa,gBAA6C;CACxD,YAAY;CACZ,OAAO;CACP,YAAY;CACZ,gBAAgB;CAChB,YAAY;AACd;AACA,MAAa,sBAAsB;AACnC,MAAa,6BAA6B;AAC1C,MAAa,wBAAwB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SceneGraph } from "./graph.js";
|
|
2
|
+
import { ConstraintType, SceneNode } from "./types.js";
|
|
3
|
+
//#region src/constraints.d.ts
|
|
4
|
+
type ConstraintGraph = Pick<SceneGraph, 'getNode' | 'closest'>;
|
|
5
|
+
/** Containers whose children keep their place by their own constraints when they resize. */
|
|
6
|
+
declare const CONSTRAINT_PARENT_TYPES: ReadonlySet<SceneNode['type']>;
|
|
7
|
+
/**
|
|
8
|
+
* The frame, component, or instance whose resize moves `node` by its constraints: its parent, or,
|
|
9
|
+
* for a layer in groups and booleans, the frame around the outermost of them, as in Figma (live,
|
|
10
|
+
* #1835). Null when nothing places it by constraints: on a page or in a section, or in an auto
|
|
11
|
+
* layout flow.
|
|
12
|
+
*/
|
|
13
|
+
declare function constraintFrame(graph: ConstraintGraph, node: SceneNode): SceneNode | null;
|
|
14
|
+
/** Whether `node` has constraints the Design panel offers and the canvas shows. */
|
|
15
|
+
declare function isConstraintEligible(graph: ConstraintGraph, node: SceneNode): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The layers whose constraints `node` stands for. A group or boolean has none of its own: it shows
|
|
18
|
+
* and sets those of the layers in it, through nested groups and booleans, as in Figma.
|
|
19
|
+
*/
|
|
20
|
+
declare function constraintLayers(graph: ConstraintGraph, node: SceneNode): SceneNode[];
|
|
21
|
+
/** The constraint the layers share on one axis, or null when they differ or there are none. */
|
|
22
|
+
declare function sharedConstraint(layers: readonly SceneNode[], key: 'horizontalConstraint' | 'verticalConstraint'): ConstraintType | null;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { CONSTRAINT_PARENT_TYPES, constraintFrame, constraintLayers, isConstraintEligible, sharedConstraint };
|
|
25
|
+
//# sourceMappingURL=constraints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraints.d.ts","names":[],"sources":["../src/constraints.ts"],"mappings":";;;KAIK,kBAAkB,KAAK;;cAGf,yBAAyB,YAAY;;;;;;;iBAalC,gBAAgB,OAAO,iBAAiB,MAAM,YAAY;;iBAe1D,qBAAqB,OAAO,iBAAiB,MAAM;;;;;iBAQnD,iBAAiB,OAAO,iBAAiB,MAAM,YAAY;;iBAS3D,iBACd,iBAAiB,aACjB,qDACC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { FITTED_CONTAINER_TYPES } from "./node-defaults.js";
|
|
2
|
+
//#region src/constraints.ts
|
|
3
|
+
/** Containers whose children keep their place by their own constraints when they resize. */
|
|
4
|
+
const CONSTRAINT_PARENT_TYPES = /* @__PURE__ */ new Set([
|
|
5
|
+
"FRAME",
|
|
6
|
+
"COMPONENT",
|
|
7
|
+
"COMPONENT_SET",
|
|
8
|
+
"INSTANCE"
|
|
9
|
+
]);
|
|
10
|
+
/**
|
|
11
|
+
* The frame, component, or instance whose resize moves `node` by its constraints: its parent, or,
|
|
12
|
+
* for a layer in groups and booleans, the frame around the outermost of them, as in Figma (live,
|
|
13
|
+
* #1835). Null when nothing places it by constraints: on a page or in a section, or in an auto
|
|
14
|
+
* layout flow.
|
|
15
|
+
*/
|
|
16
|
+
function constraintFrame(graph, node) {
|
|
17
|
+
let layer = node;
|
|
18
|
+
const parent = node.parentId ? graph.closest(node.parentId, (ancestor) => {
|
|
19
|
+
if (!FITTED_CONTAINER_TYPES.has(ancestor.type)) return true;
|
|
20
|
+
layer = ancestor;
|
|
21
|
+
return false;
|
|
22
|
+
}) : void 0;
|
|
23
|
+
if (!parent || !CONSTRAINT_PARENT_TYPES.has(parent.type)) return null;
|
|
24
|
+
if (parent.layoutMode !== "NONE" && layer.layoutPositioning !== "ABSOLUTE") return null;
|
|
25
|
+
return parent;
|
|
26
|
+
}
|
|
27
|
+
/** Whether `node` has constraints the Design panel offers and the canvas shows. */
|
|
28
|
+
function isConstraintEligible(graph, node) {
|
|
29
|
+
return constraintFrame(graph, node) !== null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The layers whose constraints `node` stands for. A group or boolean has none of its own: it shows
|
|
33
|
+
* and sets those of the layers in it, through nested groups and booleans, as in Figma.
|
|
34
|
+
*/
|
|
35
|
+
function constraintLayers(graph, node) {
|
|
36
|
+
if (!FITTED_CONTAINER_TYPES.has(node.type)) return [node];
|
|
37
|
+
return node.childIds.flatMap((id) => {
|
|
38
|
+
const child = graph.getNode(id);
|
|
39
|
+
return child ? constraintLayers(graph, child) : [];
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** The constraint the layers share on one axis, or null when they differ or there are none. */
|
|
43
|
+
function sharedConstraint(layers, key) {
|
|
44
|
+
const first = layers.at(0)?.[key];
|
|
45
|
+
if (first === void 0) return null;
|
|
46
|
+
return layers.every((layer) => layer[key] === first) ? first : null;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { CONSTRAINT_PARENT_TYPES, constraintFrame, constraintLayers, isConstraintEligible, sharedConstraint };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=constraints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraints.js","names":[],"sources":["../src/constraints.ts"],"sourcesContent":["import type { SceneGraph } from './graph'\nimport { FITTED_CONTAINER_TYPES } from './node-defaults'\nimport type { ConstraintType, SceneNode } from './types'\n\ntype ConstraintGraph = Pick<SceneGraph, 'getNode' | 'closest'>\n\n/** Containers whose children keep their place by their own constraints when they resize. */\nexport const CONSTRAINT_PARENT_TYPES: ReadonlySet<SceneNode['type']> = new Set<SceneNode['type']>([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\n/**\n * The frame, component, or instance whose resize moves `node` by its constraints: its parent, or,\n * for a layer in groups and booleans, the frame around the outermost of them, as in Figma (live,\n * #1835). Null when nothing places it by constraints: on a page or in a section, or in an auto\n * layout flow.\n */\nexport function constraintFrame(graph: ConstraintGraph, node: SceneNode): SceneNode | null {\n let layer = node\n const parent = node.parentId\n ? graph.closest(node.parentId, (ancestor) => {\n if (!FITTED_CONTAINER_TYPES.has(ancestor.type)) return true\n layer = ancestor\n return false\n })\n : undefined\n if (!parent || !CONSTRAINT_PARENT_TYPES.has(parent.type)) return null\n if (parent.layoutMode !== 'NONE' && layer.layoutPositioning !== 'ABSOLUTE') return null\n return parent\n}\n\n/** Whether `node` has constraints the Design panel offers and the canvas shows. */\nexport function isConstraintEligible(graph: ConstraintGraph, node: SceneNode): boolean {\n return constraintFrame(graph, node) !== null\n}\n\n/**\n * The layers whose constraints `node` stands for. A group or boolean has none of its own: it shows\n * and sets those of the layers in it, through nested groups and booleans, as in Figma.\n */\nexport function constraintLayers(graph: ConstraintGraph, node: SceneNode): SceneNode[] {\n if (!FITTED_CONTAINER_TYPES.has(node.type)) return [node]\n return node.childIds.flatMap((id) => {\n const child = graph.getNode(id)\n return child ? constraintLayers(graph, child) : []\n })\n}\n\n/** The constraint the layers share on one axis, or null when they differ or there are none. */\nexport function sharedConstraint(\n layers: readonly SceneNode[],\n key: 'horizontalConstraint' | 'verticalConstraint'\n): ConstraintType | null {\n const first = layers.at(0)?.[key]\n if (first === undefined) return null\n return layers.every((layer) => layer[key] === first) ? first : null\n}\n"],"mappings":";;;AAOA,MAAa,0CAA0D,IAAI,IAAuB;CAChG;CACA;CACA;CACA;AACF,CAAC;;;;;;;AAQD,SAAgB,gBAAgB,OAAwB,MAAmC;CACzF,IAAI,QAAQ;CACZ,MAAM,SAAS,KAAK,WAChB,MAAM,QAAQ,KAAK,WAAW,aAAa;EACzC,IAAI,CAAC,uBAAuB,IAAI,SAAS,IAAI,GAAG,OAAO;EACvD,QAAQ;EACR,OAAO;CACT,CAAC,IACD,KAAA;CACJ,IAAI,CAAC,UAAU,CAAC,wBAAwB,IAAI,OAAO,IAAI,GAAG,OAAO;CACjE,IAAI,OAAO,eAAe,UAAU,MAAM,sBAAsB,YAAY,OAAO;CACnF,OAAO;AACT;;AAGA,SAAgB,qBAAqB,OAAwB,MAA0B;CACrF,OAAO,gBAAgB,OAAO,IAAI,MAAM;AAC1C;;;;;AAMA,SAAgB,iBAAiB,OAAwB,MAA8B;CACrF,IAAI,CAAC,uBAAuB,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI;CACxD,OAAO,KAAK,SAAS,SAAS,OAAO;EACnC,MAAM,QAAQ,MAAM,QAAQ,EAAE;EAC9B,OAAO,QAAQ,iBAAiB,OAAO,KAAK,IAAI,CAAC;CACnD,CAAC;AACH;;AAGA,SAAgB,iBACd,QACA,KACuB;CACvB,MAAM,QAAQ,OAAO,GAAG,CAAC,CAAC,GAAG;CAC7B,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,OAAO,OAAO,OAAO,UAAU,MAAM,SAAS,KAAK,IAAI,QAAQ;AACjE"}
|
package/dist/coordinate.d.ts
CHANGED
|
@@ -89,6 +89,69 @@ declare function isTranslationOnly(matrix: Mat3): boolean;
|
|
|
89
89
|
* not a group.
|
|
90
90
|
*/
|
|
91
91
|
declare function getParentToContainerMatrix(node: SceneNode, graph: Pick<SceneGraph, 'getNode'>): Mat3;
|
|
92
|
+
/**
|
|
93
|
+
* A selected layer's place in a multi-selection's canvas bounds, taken when a resize starts so
|
|
94
|
+
* every step re-places the layer from where it began rather than from its previewed state.
|
|
95
|
+
*/
|
|
96
|
+
interface SelectionPlacement {
|
|
97
|
+
node: SceneNode;
|
|
98
|
+
center: Vector;
|
|
99
|
+
/** Draws the layer from its own (0,0)…(width,height) on the canvas. */
|
|
100
|
+
world: Mat3;
|
|
101
|
+
/** Draws the layer's parent on the canvas. */
|
|
102
|
+
parentWorld: Mat3;
|
|
103
|
+
/** -1 when the layer is drawn mirrored, so its rotation turns the other way on the canvas. */
|
|
104
|
+
direction: 1 | -1;
|
|
105
|
+
/** Maps canvas points into the layer's parent's space, or null when it cannot be inverted. */
|
|
106
|
+
parentInverse: Mat3 | null;
|
|
107
|
+
}
|
|
108
|
+
declare function selectionPlacement(node: SceneNode, graph: Pick<SceneGraph, 'getNode' | 'rootId'>): SelectionPlacement;
|
|
109
|
+
interface ResizedBoundsOptions {
|
|
110
|
+
/** The layer is locked to its ratio: it scales evenly instead of stretching. */
|
|
111
|
+
keepRatio?: boolean;
|
|
112
|
+
/** Adjusts a locked layer's sizes, such as to whole pixels. */
|
|
113
|
+
round?: (size: number) => number;
|
|
114
|
+
/**
|
|
115
|
+
* Lands an upright layer's edges on whole pixels from the box's top-left corner, as Figma places
|
|
116
|
+
* the layers of a selection a handle resizes while Snap to pixel grid is on.
|
|
117
|
+
*/
|
|
118
|
+
wholeEdges?: boolean;
|
|
119
|
+
}
|
|
120
|
+
/** Where a layer sits in its parent and how large it is, with its angle and flips. */
|
|
121
|
+
type LayerPlacement = Pick<SceneNode, 'x' | 'y' | 'width' | 'height' | 'rotation' | 'flipX' | 'flipY'>;
|
|
122
|
+
/**
|
|
123
|
+
* Where a layer lands, in its parent's space, when a multi-selection's canvas box `from` is
|
|
124
|
+
* resized to `to`. Figma scales the layer's whole transform with the box, which skews a rotated
|
|
125
|
+
* layer under an uneven scale. A layer here cannot skew, so it takes what Figma then reports for
|
|
126
|
+
* it, and what a `.fig` file of that result opens as: its top-left corner and x axis where the
|
|
127
|
+
* scale puts them, its width and height the scaled lengths of its own axes, and its y axis square
|
|
128
|
+
* to its x axis. An even scale, or a layer upright in the box, comes out exactly as in Figma.
|
|
129
|
+
*/
|
|
130
|
+
declare function placeInResizedBounds(placement: SelectionPlacement, from: Rect, to: Rect, { keepRatio, round, wholeEdges }?: ResizedBoundsOptions): LayerPlacement;
|
|
131
|
+
/**
|
|
132
|
+
* Where a layer lands, in its parent's space, when it scales evenly by `scale` about a canvas
|
|
133
|
+
* point, as Figma's Scale tool scales it: its angle and flips stay, and the point stays put.
|
|
134
|
+
*/
|
|
135
|
+
declare function placeScaledAbout(placement: SelectionPlacement, anchor: Vector, scale: number): LayerPlacement;
|
|
136
|
+
/** A canvas pointer movement along the layer's own axes, as its handles measure it. */
|
|
137
|
+
declare function canvasDeltaInLayer(placement: SelectionPlacement, dx: number, dy: number): Vector;
|
|
138
|
+
/**
|
|
139
|
+
* Where a layer lands when one of its handles resizes it in its own frame, from `from` to `to`,
|
|
140
|
+
* both its box in its parent's axes as an upright layer would have it. `to` is signed: a handle
|
|
141
|
+
* dragged past the opposite edge gives a negative size and mirrors the layer, as Figma flips it.
|
|
142
|
+
* The edges the handle leaves stay where they are on the canvas, whatever the layer's angle.
|
|
143
|
+
*/
|
|
144
|
+
declare function placeInResizedFrame(placement: SelectionPlacement, from: Rect, to: Rect): LayerPlacement;
|
|
145
|
+
/**
|
|
146
|
+
* Where a layer lands, in its parent's space, when a multi-selection turns `degrees` about a
|
|
147
|
+
* canvas pivot, as Figma rotates a selection about its bounds' center: the layer's center swings
|
|
148
|
+
* around the pivot and the layer itself turns by the same angle on the canvas.
|
|
149
|
+
*/
|
|
150
|
+
declare function placeRotatedAbout(placement: SelectionPlacement, pivot: Vector, degrees: number): {
|
|
151
|
+
x: number;
|
|
152
|
+
y: number;
|
|
153
|
+
rotation: number;
|
|
154
|
+
};
|
|
92
155
|
//#endregion
|
|
93
|
-
export { NodePlacement, getAbsolutePosition, getAbsolutePositionFull, getAbsoluteRotation, getAxisAlignedBoundsInParent, getAxisAlignedWorldBounds, getNodeLocalMatrix, getNodeRotationOrigin, getNodeWorldBounds, getParentToContainerMatrix, getParentWorldMatrix, getWorldHandles, getWorldMatrix, isTranslationOnly, localTransformFromWorld };
|
|
156
|
+
export { LayerPlacement, NodePlacement, ResizedBoundsOptions, SelectionPlacement, canvasDeltaInLayer, getAbsolutePosition, getAbsolutePositionFull, getAbsoluteRotation, getAxisAlignedBoundsInParent, getAxisAlignedWorldBounds, getNodeLocalMatrix, getNodeRotationOrigin, getNodeWorldBounds, getParentToContainerMatrix, getParentWorldMatrix, getWorldHandles, getWorldMatrix, isTranslationOnly, localTransformFromWorld, placeInResizedBounds, placeInResizedFrame, placeRotatedAbout, placeScaledAbout, selectionPlacement };
|
|
94
157
|
//# sourceMappingURL=coordinate.d.ts.map
|
package/dist/coordinate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinate.d.ts","names":[],"sources":["../src/coordinate.ts"],"mappings":";;;;;iBAMgB,eAAe,MAAM,WAAW,OAAO,KAAK,yBAAyB;iBAwCrE,0BAA0B,MAAM,WAAW,OAAO,KAAK,yBAAsB;;iBAK7E,qBACd,QAAQ,uBACR,OAAO,KAAK,oCACX;;;;;;;iBAWa,6BACd,gBAAgB,aAChB,kBACA,OAAO,KAAK,oCACX;iBASa,oBAAoB,MAAM,WAAW,OAAO,aAAa;iBASzD,oBAAoB,MAAM,WAAW,OAAO;iBAW5C,wBAAwB,MAAM,WAAW,OAAO;;;;;;;;;;;;iBA2DhD,sBAAsB,MAAM,KAAK,0CAA0C;;KAK/E,gBAAgB,KAC1B;;iBAKc,mBAAmB,GAAG,eAAe,WAAU,SAAU;iBAczD,mBAAmB,MAAM,YAAS;;;;;;;;iBAWlC,gBACd,MAAM,WACN,OAAO,KAAK,wBACZ,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8CT,iBAAiB,KAAK;;;;;iBAMX,wBACd,MAAM,WACN,OAAO,MACP,aAAa,OACZ;iBAca,kBAAkB,QAAQ;;;;;;;iBAU1B,2BACd,MAAM,WACN,OAAO,KAAK,yBACX"}
|
|
1
|
+
{"version":3,"file":"coordinate.d.ts","names":[],"sources":["../src/coordinate.ts"],"mappings":";;;;;iBAMgB,eAAe,MAAM,WAAW,OAAO,KAAK,yBAAyB;iBAwCrE,0BAA0B,MAAM,WAAW,OAAO,KAAK,yBAAsB;;iBAK7E,qBACd,QAAQ,uBACR,OAAO,KAAK,oCACX;;;;;;;iBAWa,6BACd,gBAAgB,aAChB,kBACA,OAAO,KAAK,oCACX;iBASa,oBAAoB,MAAM,WAAW,OAAO,aAAa;iBASzD,oBAAoB,MAAM,WAAW,OAAO;iBAW5C,wBAAwB,MAAM,WAAW,OAAO;;;;;;;;;;;;iBA2DhD,sBAAsB,MAAM,KAAK,0CAA0C;;KAK/E,gBAAgB,KAC1B;;iBAKc,mBAAmB,GAAG,eAAe,WAAU,SAAU;iBAczD,mBAAmB,MAAM,YAAS;;;;;;;;iBAWlC,gBACd,MAAM,WACN,OAAO,KAAK,wBACZ,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8CT,iBAAiB,KAAK;;;;;iBAMX,wBACd,MAAM,WACN,OAAO,MACP,aAAa,OACZ;iBAca,kBAAkB,QAAQ;;;;;;;iBAU1B,2BACd,MAAM,WACN,OAAO,KAAK,yBACX;;;;;UAgBc;EACf,MAAM;EACN,QAAQ;;EAER,OAAO;;EAEP,aAAa;;EAEb;;EAEA,eAAe;;iBAGD,mBACd,MAAM,WACN,OAAO,KAAK,oCACX;UA4Bc;;EAEf;;EAEA,SAAS;;;;;EAKT;;;KAwBU,iBAAiB,KAC3B;;;;;;;;;iBAYc,qBACd,WAAW,oBACX,MAAM,MACN,IAAI,QAEF,WACA,OACA,eACC,uBACF;;;;;iBAqCa,iBACd,WAAW,oBACX,QAAQ,QACR,gBACC;;iBAMa,mBAAmB,WAAW,oBAAoB,YAAY,aAAa;;;;;;;iBAa3E,oBACd,WAAW,oBACX,MAAM,MACN,IAAI,OACH;;;;;;iBAoCa,kBACd,WAAW,oBACX,OAAO,QACP;EACG;EAAW;EAAW"}
|