@open-pencil/scene-graph 0.17.0-beta.2 → 0.17.0-beta.4
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/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/checkpoint.d.ts +3 -3
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +53 -23
- package/dist/checkpoint.js.map +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/properties.d.ts +6 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +9 -1
- package/dist/components/properties.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 +8 -1
- package/dist/copy.js.map +1 -1
- package/dist/css/index.d.ts +3 -2
- package/dist/css/index.js +3 -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/figjam/palette.d.ts +1 -1
- package/dist/figjam/palette.js +1 -1
- package/dist/figjam/palette.js.map +1 -1
- package/dist/geometry.d.ts +8 -1
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +19 -8
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +48 -12
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +110 -24
- 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/hit-test.d.ts +5 -0
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +18 -12
- 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/index.d.ts.map +1 -1
- package/dist/instances/index.js +3 -0
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/placement.js +55 -12
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap.js +3 -0
- package/dist/instances/swap.js.map +1 -1
- package/dist/instances/sync.js +34 -13
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +1 -0
- 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/plugin-data/fields.d.ts +2 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +2 -0
- 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 +37 -14
- 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 +3 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +7 -1
- 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 +4 -1
- package/dist/slots/content.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/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 +7 -14
- 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 +47 -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 +17 -14
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +30 -72
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/fields.d.ts +1 -1
- package/dist/variables/fields.js +1 -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 +6 -6
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +40 -24
- 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 +8 -1
- package/src/asset-keys.ts +20 -0
- package/src/checkpoint.ts +87 -32
- package/src/components/properties.ts +9 -0
- package/src/constants.ts +17 -0
- package/src/constraints.ts +60 -0
- package/src/coordinate.ts +220 -0
- package/src/copy.ts +9 -4
- package/src/css/index.ts +17 -1
- package/src/css/text.ts +85 -17
- package/src/css/transform.ts +266 -0
- package/src/css/values.ts +8 -0
- package/src/figjam/palette.ts +1 -1
- package/src/geometry.ts +20 -9
- package/src/graph.ts +128 -42
- package/src/group-bounds.ts +84 -17
- package/src/hit-test.ts +30 -14
- package/src/images.ts +71 -3
- package/src/instances/index.ts +4 -0
- package/src/instances/placement.ts +63 -10
- package/src/instances/swap.ts +5 -0
- package/src/instances/sync.ts +48 -21
- package/src/node-defaults.ts +1 -0
- package/src/order-keys.ts +6 -0
- package/src/plugin-data/fields.ts +6 -0
- 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 +8 -0
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +4 -1
- package/src/text/direction.ts +5 -0
- 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 +10 -26
- 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 +55 -1
- package/src/undo.ts +48 -10
- package/src/variables/bindings.ts +44 -91
- package/src/variables/fields.ts +1 -1
- package/src/variables/formula/index.ts +3 -1
- package/src/variables/index.ts +56 -38
- 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
package/dist/resize.js
CHANGED
|
@@ -1,33 +1,56 @@
|
|
|
1
|
+
import Matrix from "./matrix.js";
|
|
2
|
+
import { FITTED_CONTAINER_TYPES } from "./node-defaults.js";
|
|
3
|
+
import { getNodeLocalMatrix } from "./coordinate.js";
|
|
1
4
|
import { cloneVectorNetwork, copyDerivedGlyphs, copyGeometryPaths, copyStroke, copyStrokes, scaleGeometryPaths } from "./copy.js";
|
|
5
|
+
import { CONSTRAINT_PARENT_TYPES } from "./constraints.js";
|
|
6
|
+
import { groupFitChanges } from "./group-bounds.js";
|
|
2
7
|
import { enforcedAspectRatio } from "./layout/aspect-ratio.js";
|
|
3
8
|
//#region src/resize.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Containers whose resize moves their children: the constraint parents, and groups and booleans,
|
|
11
|
+
* which scale theirs.
|
|
12
|
+
*/
|
|
13
|
+
const CONSTRAINT_CONTAINER_TYPES = /* @__PURE__ */ new Set([...CONSTRAINT_PARENT_TYPES, ...FITTED_CONTAINER_TYPES]);
|
|
14
|
+
/**
|
|
15
|
+
* Where a constraint places a child on one axis when its parent goes from `parentBefore` to
|
|
16
|
+
* `parentAfter`, as Figma does (live-measured, #1060, #1816): Right and Left & right move or grow
|
|
17
|
+
* it by the change in the parent's size rounded to whole pixels, Center by the change in its
|
|
18
|
+
* rounded half, and Scale by the exact ratio. The child's own box is never rounded, so a resize
|
|
19
|
+
* to the same size changes nothing. Left & right that would leave no size keeps the axis as it
|
|
20
|
+
* was; past zero, the child turns over and its box runs back from the edge it was pinned to, as
|
|
21
|
+
* the layer is mirrored in Figma.
|
|
22
|
+
*/
|
|
12
23
|
function constrainedAxis(position, size, parentBefore, parentAfter, constraint) {
|
|
13
|
-
const delta = parentAfter - parentBefore;
|
|
24
|
+
const delta = Math.round(parentAfter) - Math.round(parentBefore);
|
|
14
25
|
if (constraint === "MAX") return {
|
|
15
26
|
position: position + delta,
|
|
16
27
|
size
|
|
17
28
|
};
|
|
18
29
|
if (constraint === "CENTER") return {
|
|
19
|
-
position: position +
|
|
30
|
+
position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2),
|
|
20
31
|
size
|
|
21
32
|
};
|
|
22
|
-
if (constraint === "STRETCH")
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
if (constraint === "STRETCH") {
|
|
34
|
+
const stretched = size + delta;
|
|
35
|
+
if (stretched === 0) return {
|
|
36
|
+
position,
|
|
37
|
+
size
|
|
38
|
+
};
|
|
39
|
+
if (stretched > 0) return {
|
|
40
|
+
position,
|
|
41
|
+
size: stretched
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
position: position + stretched,
|
|
45
|
+
size: -stretched,
|
|
46
|
+
flipped: true
|
|
47
|
+
};
|
|
48
|
+
}
|
|
26
49
|
if (constraint === "SCALE" && parentBefore > 0) {
|
|
27
50
|
const scale = parentAfter / parentBefore;
|
|
28
51
|
return {
|
|
29
52
|
position: position * scale,
|
|
30
|
-
size:
|
|
53
|
+
size: size * scale
|
|
31
54
|
};
|
|
32
55
|
}
|
|
33
56
|
return {
|
|
@@ -86,67 +109,33 @@ function keepLockedRatio(x, y, horizontal, vertical, aspectRatio) {
|
|
|
86
109
|
y
|
|
87
110
|
};
|
|
88
111
|
}
|
|
89
|
-
/** A child's box after its parent resizes, keeping a locked aspect ratio as Figma does. */
|
|
90
|
-
function constrainedChildRect(child, parentBefore, parentAfter, horizontal, vertical, aspectRatio = null) {
|
|
91
|
-
let x = constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal);
|
|
92
|
-
let y = constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical);
|
|
93
|
-
({x, y} = keepLockedRatio(x, y, horizontal, vertical, aspectRatio));
|
|
94
|
-
return {
|
|
95
|
-
x: Math.round(x.position),
|
|
96
|
-
y: Math.round(y.position),
|
|
97
|
-
width: Math.round(x.size),
|
|
98
|
-
height: Math.round(y.size)
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function layoutConstrainedAxis(position, size, parentBefore, parentAfter, constraint) {
|
|
102
|
-
const delta = Math.round(parentAfter) - Math.round(parentBefore);
|
|
103
|
-
if (constraint === "MAX") return {
|
|
104
|
-
position: position + delta,
|
|
105
|
-
size
|
|
106
|
-
};
|
|
107
|
-
if (constraint === "CENTER") return {
|
|
108
|
-
position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2),
|
|
109
|
-
size
|
|
110
|
-
};
|
|
111
|
-
if (constraint === "STRETCH") return {
|
|
112
|
-
position,
|
|
113
|
-
size: Math.abs(size + delta)
|
|
114
|
-
};
|
|
115
|
-
if (constraint === "SCALE" && parentBefore > 0) {
|
|
116
|
-
const scale = parentAfter / parentBefore;
|
|
117
|
-
return {
|
|
118
|
-
position: Math.round(position * scale * 128) / 128,
|
|
119
|
-
size: size * scale
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
return {
|
|
123
|
-
position,
|
|
124
|
-
size
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
112
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* it by the change in the parent's size rounded to whole pixels, Center by the change in its
|
|
131
|
-
* rounded half, and Scale by the exact ratio, its position to 1/128 of a pixel. Sizes are not
|
|
132
|
-
* rounded, so applying a run of changes one at a time lands where applying them at once does.
|
|
113
|
+
* A child's box after its parent resizes, by a handle, `resize()`, layout, or an instance taking
|
|
114
|
+
* another size than its component, keeping a locked aspect ratio as Figma does.
|
|
133
115
|
*/
|
|
134
|
-
function
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
x:
|
|
138
|
-
y:
|
|
139
|
-
width:
|
|
140
|
-
height:
|
|
116
|
+
function constrainedChildRect(child, parentBefore, parentAfter, horizontal, vertical, aspectRatio = null) {
|
|
117
|
+
const { x, y } = keepLockedRatio(constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal), constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical), horizontal, vertical, aspectRatio);
|
|
118
|
+
const rect = {
|
|
119
|
+
x: x.position,
|
|
120
|
+
y: y.position,
|
|
121
|
+
width: x.size,
|
|
122
|
+
height: y.size
|
|
141
123
|
};
|
|
124
|
+
if (x.flipped) rect.flipsX = true;
|
|
125
|
+
if (y.flipped) rect.flipsY = true;
|
|
126
|
+
return rect;
|
|
142
127
|
}
|
|
143
128
|
function scaledChildRect(child, parentBefore, parentAfter) {
|
|
144
129
|
return constrainedChildRect(child, parentBefore, parentAfter, "SCALE", "SCALE");
|
|
145
130
|
}
|
|
131
|
+
/** How much a side grows; a flat side, as a straight line's, has nothing to scale along it. */
|
|
132
|
+
function sideScale(original, size) {
|
|
133
|
+
return original > 0 ? size / original : 1;
|
|
134
|
+
}
|
|
146
135
|
function scaleVectorNetworkForResize(vectorNetwork, originalWidth, originalHeight, width, height) {
|
|
147
136
|
if (!vectorNetwork || originalWidth <= 0 && originalHeight <= 0) return null;
|
|
148
|
-
const scaleX = originalWidth
|
|
149
|
-
const scaleY = originalHeight
|
|
137
|
+
const scaleX = sideScale(originalWidth, width);
|
|
138
|
+
const scaleY = sideScale(originalHeight, height);
|
|
150
139
|
if (scaleX === 1 && scaleY === 1) return null;
|
|
151
140
|
return {
|
|
152
141
|
vertices: vectorNetwork.vertices.map((vertex) => ({
|
|
@@ -176,6 +165,8 @@ function createResizeSnapshot(node) {
|
|
|
176
165
|
y: node.y,
|
|
177
166
|
width: node.width,
|
|
178
167
|
height: node.height,
|
|
168
|
+
flipX: node.flipX,
|
|
169
|
+
flipY: node.flipY,
|
|
179
170
|
vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,
|
|
180
171
|
fillGeometry: copyGeometryPaths(node.fillGeometry),
|
|
181
172
|
strokeGeometry: copyGeometryPaths(node.strokeGeometry),
|
|
@@ -214,9 +205,9 @@ function scaleStrokes(strokes, sx, sy) {
|
|
|
214
205
|
* OUTSIDE outlines look massively thick (DomeSticker resize bug).
|
|
215
206
|
*/
|
|
216
207
|
function scaledGeometryChanges(orig, origWidth, origHeight, width, height) {
|
|
217
|
-
if (origWidth <= 0
|
|
218
|
-
const sx = width
|
|
219
|
-
const sy = height
|
|
208
|
+
if (origWidth <= 0 && origHeight <= 0) return {};
|
|
209
|
+
const sx = sideScale(origWidth, width);
|
|
210
|
+
const sy = sideScale(origHeight, height);
|
|
220
211
|
if (sx === 1 && sy === 1) return {};
|
|
221
212
|
const changes = {};
|
|
222
213
|
const resizedVN = scaleVectorNetworkForResize(orig.vectorNetwork, origWidth, origHeight, width, height);
|
|
@@ -238,6 +229,30 @@ function scaledGeometryChanges(orig, origWidth, origHeight, width, height) {
|
|
|
238
229
|
if (orig.strokes.length > 0 && glyphs.length > 0 && pathText) changes.strokes = scaleStrokes(orig.strokes, sx, sy);
|
|
239
230
|
return changes;
|
|
240
231
|
}
|
|
232
|
+
/** Copies of the geometry a resize may change, as the snapshot held it before the resize. */
|
|
233
|
+
function snapshotGeometry(orig) {
|
|
234
|
+
return {
|
|
235
|
+
vectorNetwork: orig.vectorNetwork ? cloneVectorNetwork(orig.vectorNetwork) : null,
|
|
236
|
+
fillGeometry: copyGeometryPaths(orig.fillGeometry),
|
|
237
|
+
strokeGeometry: copyGeometryPaths(orig.strokeGeometry),
|
|
238
|
+
derivedTextGlyphs: copyDerivedGlyphs(orig.derivedTextGlyphs),
|
|
239
|
+
strokes: copyStrokes(orig.strokes),
|
|
240
|
+
textPathBox: orig.textPathBox ? { ...orig.textPathBox } : null
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/** Whether a box of `size` scales the snapshot's geometry, a flat side left out. */
|
|
244
|
+
function scalesGeometry(orig, size) {
|
|
245
|
+
return sideScale(orig.width, size.width) !== 1 || sideScale(orig.height, size.height) !== 1;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* A child's geometry for its constrained `box`, scaled from the snapshot. At a box that scales
|
|
249
|
+
* nothing, after an earlier frame of the same drag scaled it, the child takes its snapshot
|
|
250
|
+
* geometry again, as nothing else would undo that scaling.
|
|
251
|
+
*/
|
|
252
|
+
function constrainedGeometryChanges(orig, current, box) {
|
|
253
|
+
if (scalesGeometry(orig, box)) return scaledGeometryChanges(orig, orig.width, orig.height, box.width, box.height);
|
|
254
|
+
return scalesGeometry(orig, current) ? snapshotGeometry(orig) : {};
|
|
255
|
+
}
|
|
241
256
|
function collectResizeDescendants(graph, rootId) {
|
|
242
257
|
const root = graph.getNode(rootId);
|
|
243
258
|
if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null;
|
|
@@ -255,33 +270,152 @@ function collectResizeDescendants(graph, rootId) {
|
|
|
255
270
|
collect(rootId);
|
|
256
271
|
return snapshots.size > 0 ? snapshots : null;
|
|
257
272
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
273
|
+
/**
|
|
274
|
+
* The flips a child takes when its constraints place it from `from`, written only where they
|
|
275
|
+
* differ from the ones it has now, so a drag that crosses back undoes its own turn.
|
|
276
|
+
*/
|
|
277
|
+
function flipChanges(from, current, flipsX = false, flipsY = false) {
|
|
278
|
+
const changes = {};
|
|
279
|
+
const flipX = from.flipX !== flipsX;
|
|
280
|
+
const flipY = from.flipY !== flipsY;
|
|
281
|
+
if (flipX !== current.flipX) changes.flipX = flipX;
|
|
282
|
+
if (flipY !== current.flipY) changes.flipY = flipY;
|
|
283
|
+
return changes;
|
|
284
|
+
}
|
|
285
|
+
/** The layer as the resize found it, or as the resize leaves it with its changes so far. */
|
|
286
|
+
function startOf(plan, id) {
|
|
287
|
+
const node = plan.graph.getNode(id);
|
|
288
|
+
const original = plan.originals.get(id);
|
|
289
|
+
return node && original ? {
|
|
290
|
+
...node,
|
|
291
|
+
...original
|
|
292
|
+
} : node;
|
|
293
|
+
}
|
|
294
|
+
function plannedOf(plan, id) {
|
|
295
|
+
const node = startOf(plan, id);
|
|
296
|
+
const changes = plan.changes.get(id);
|
|
297
|
+
return node && changes ? {
|
|
298
|
+
...node,
|
|
299
|
+
...changes
|
|
300
|
+
} : node;
|
|
301
|
+
}
|
|
302
|
+
function mergeChanges(plan, id, changes) {
|
|
303
|
+
plan.changes.set(id, {
|
|
304
|
+
...plan.changes.get(id),
|
|
305
|
+
...changes
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
/** Writes where a layer's constraints put it, then places its own children. */
|
|
309
|
+
function placeConstrained(plan, child, original, rect, toParent) {
|
|
310
|
+
const { flipsX, flipsY, ...box } = rect;
|
|
311
|
+
const position = toParent ? Matrix.mapPoint(toParent, box) : box;
|
|
312
|
+
plan.changes.set(child.id, {
|
|
313
|
+
...box,
|
|
314
|
+
...position,
|
|
315
|
+
...flipChanges(original, child, flipsX, flipsY),
|
|
316
|
+
...constrainedGeometryChanges(original, child, box)
|
|
317
|
+
});
|
|
318
|
+
placeChildren(plan, child.id, original, child.layoutMode === "NONE" ? box : child);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Places the layers in a group or boolean whose frame resized. The group owns no constraints: each
|
|
322
|
+
* layer in it keeps its place in the frame by its own, through nested groups, and the groups then
|
|
323
|
+
* fit around them, as in Figma (live, #1835). A layer is placed in the frame's space and written
|
|
324
|
+
* back in its group's.
|
|
325
|
+
*/
|
|
326
|
+
function placeGroupedLayers(plan, group, toFrame, frameBefore, frameAfter) {
|
|
327
|
+
for (const childId of group.childIds) {
|
|
328
|
+
const child = plan.graph.getNode(childId);
|
|
329
|
+
const original = plan.originals.get(childId);
|
|
330
|
+
const start = startOf(plan, childId);
|
|
331
|
+
if (!child || !original || !start) continue;
|
|
332
|
+
if (FITTED_CONTAINER_TYPES.has(child.type)) {
|
|
333
|
+
placeGroupedLayers(plan, start, Matrix.multiply(toFrame, getNodeLocalMatrix(start)), frameBefore, frameAfter);
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
placeConstrained(plan, child, original, constrainedChildRect({
|
|
337
|
+
...Matrix.mapPoint(toFrame, original),
|
|
338
|
+
width: original.width,
|
|
339
|
+
height: original.height
|
|
340
|
+
}, frameBefore, frameAfter, child.horizontalConstraint, child.verticalConstraint, enforcedAspectRatio(child)), Matrix.invert(toFrame));
|
|
341
|
+
}
|
|
342
|
+
fitPlannedGroup(plan, group.id);
|
|
343
|
+
}
|
|
344
|
+
const PLACEMENT_KEYS = [
|
|
345
|
+
"x",
|
|
346
|
+
"y",
|
|
347
|
+
"width",
|
|
348
|
+
"height"
|
|
349
|
+
];
|
|
350
|
+
/**
|
|
351
|
+
* Fits a group to its layers where the resize put them, when any of them moved: a boolean's box
|
|
352
|
+
* is its result's, which only the renderer measures, so one whose operands stay keeps its box. A
|
|
353
|
+
* drag places from the start each time, so the group's box is always written.
|
|
354
|
+
*/
|
|
355
|
+
function fitPlannedGroup(plan, groupId) {
|
|
356
|
+
const group = plannedOf(plan, groupId);
|
|
357
|
+
if (!group) return;
|
|
358
|
+
const { x, y, width, height } = group;
|
|
359
|
+
mergeChanges(plan, groupId, {
|
|
360
|
+
x,
|
|
361
|
+
y,
|
|
362
|
+
width,
|
|
363
|
+
height
|
|
364
|
+
});
|
|
365
|
+
if (!group.childIds.some((id) => {
|
|
366
|
+
const start = startOf(plan, id);
|
|
367
|
+
const planned = plannedOf(plan, id);
|
|
368
|
+
return start && planned && PLACEMENT_KEYS.some((key) => start[key] !== planned[key]);
|
|
369
|
+
})) return;
|
|
370
|
+
const reader = {
|
|
371
|
+
rootId: plan.graph.rootId,
|
|
372
|
+
getNode: (id) => plannedOf(plan, id)
|
|
373
|
+
};
|
|
374
|
+
const children = group.childIds.flatMap((id) => reader.getNode(id) ?? []);
|
|
375
|
+
const fit = groupFitChanges(reader, group, children);
|
|
376
|
+
for (const [id, changes] of fit ?? []) mergeChanges(plan, id, changes);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Places the children of a layer that went from `parentBefore` to `parentAfter`: a frame's by their
|
|
380
|
+
* constraints, the layers in its groups and booleans by theirs, a group's or boolean's own scaled.
|
|
381
|
+
*/
|
|
382
|
+
function placeChildren(plan, parentId, parentBefore, parentAfter) {
|
|
383
|
+
const parent = plan.graph.getNode(parentId);
|
|
384
|
+
if (!parent) return;
|
|
385
|
+
const scalesChildren = FITTED_CONTAINER_TYPES.has(parent.type);
|
|
386
|
+
for (const childId of parent.childIds) {
|
|
387
|
+
const original = plan.originals.get(childId);
|
|
388
|
+
const child = plan.graph.getNode(childId);
|
|
389
|
+
if (!original || !child) continue;
|
|
390
|
+
if (parent.layoutMode !== "NONE" && child.layoutPositioning !== "ABSOLUTE") {
|
|
391
|
+
placeChildren(plan, childId, original, child);
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (!scalesChildren && FITTED_CONTAINER_TYPES.has(child.type)) {
|
|
395
|
+
const start = {
|
|
396
|
+
...child,
|
|
397
|
+
...original
|
|
276
398
|
};
|
|
277
|
-
|
|
278
|
-
|
|
399
|
+
placeGroupedLayers(plan, start, getNodeLocalMatrix(start), parentBefore, parentAfter);
|
|
400
|
+
continue;
|
|
279
401
|
}
|
|
402
|
+
placeConstrained(plan, child, original, scalesChildren ? scaledChildRect(original, parentBefore, parentAfter) : constrainedChildRect(original, parentBefore, parentAfter, child.horizontalConstraint, child.verticalConstraint, enforcedAspectRatio(child)), null);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Where the descendants of a layer go when it resizes from `rootBefore` to `rootAfter`, from the
|
|
407
|
+
* places `originals` recorded.
|
|
408
|
+
*/
|
|
409
|
+
function computeConstrainedResizeChanges(graph, rootId, rootBefore, rootAfter, originals) {
|
|
410
|
+
const plan = {
|
|
411
|
+
graph,
|
|
412
|
+
originals,
|
|
413
|
+
changes: /* @__PURE__ */ new Map()
|
|
280
414
|
};
|
|
281
|
-
|
|
282
|
-
return changes;
|
|
415
|
+
placeChildren(plan, rootId, rootBefore, rootAfter);
|
|
416
|
+
return plan.changes;
|
|
283
417
|
}
|
|
284
418
|
//#endregion
|
|
285
|
-
export { collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot,
|
|
419
|
+
export { collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, flipChanges, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges };
|
|
286
420
|
|
|
287
421
|
//# sourceMappingURL=resize.js.map
|
package/dist/resize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resize.js","names":[],"sources":["../src/resize.ts"],"sourcesContent":["import {\n cloneVectorNetwork,\n copyDerivedGlyphs,\n copyGeometryPaths,\n copyStroke,\n copyStrokes,\n scaleGeometryPaths\n} from './copy'\nimport { enforcedAspectRatio } from './layout/aspect-ratio'\nimport type { Rect } from './primitives'\nimport type { ConstraintType, DerivedTextGlyph, SceneNode, Stroke, VectorNetwork } from './types'\n\n/**\n * Drag-start state a live resize re-scales from. Path text needs more than the\n * layout rect: its OUTSIDE stroke silhouettes and glyph outlines are baked\n * geometry that must scale with the node, and textPathBox is the layout box the\n * glyphs were reflowed against.\n */\nexport type ResizeSnapshot = Pick<\n SceneNode,\n | 'type'\n | 'x'\n | 'y'\n | 'width'\n | 'height'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n>\n\ninterface ResizeGraph {\n getNode(id: string): SceneNode | undefined\n}\n\nconst CONSTRAINT_CONTAINER_TYPES = new Set([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\nfunction constrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): { position: number; size: number } {\n const delta = parentAfter - parentBefore\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') return { position: position + delta / 2, size }\n if (constraint === 'STRETCH') return { position, size: Math.max(1, size + delta) }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: position * scale, size: Math.max(1, size * scale) }\n }\n return { position, size }\n}\n\ntype AxisPlacement = { position: number; size: number }\n\nconst FLEXIBLE_CONSTRAINTS: ReadonlySet<ConstraintType> = new Set(['STRETCH', 'SCALE'])\n\n/** The axis at `size`, keeping the edge or centre its constraint pins where it was placed. */\nfunction resizedInPlace(\n placed: AxisPlacement,\n size: number,\n constraint: ConstraintType\n): AxisPlacement {\n if (constraint === 'MAX') return { position: placed.position + placed.size - size, size }\n if (constraint === 'CENTER') return { position: placed.position + (placed.size - size) / 2, size }\n return { position: placed.position, size }\n}\n\n/** Keep a placed box's constrained edges or center when its content determines its size. */\nexport function resizedChildRect(\n placed: Rect,\n size: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType\n): Rect {\n const x = resizedInPlace({ position: placed.x, size: placed.width }, size.width, horizontal)\n const y = resizedInPlace({ position: placed.y, size: placed.height }, size.height, vertical)\n return { x: x.position, y: y.position, width: x.size, height: y.size }\n}\n\n/**\n * A locked aspect ratio holds when exactly one axis follows the parent, as in Figma: that axis\n * sizes the other. With both axes following the parent, or neither, the ratio gives way.\n */\nfunction keepLockedRatio(\n x: AxisPlacement,\n y: AxisPlacement,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null\n): { x: AxisPlacement; y: AxisPlacement } {\n const flexibleX = FLEXIBLE_CONSTRAINTS.has(horizontal)\n if (aspectRatio === null || flexibleX === FLEXIBLE_CONSTRAINTS.has(vertical)) return { x, y }\n return flexibleX\n ? { x, y: resizedInPlace(y, x.size / aspectRatio, vertical) }\n : { x: resizedInPlace(x, y.size * aspectRatio, horizontal), y }\n}\n\n/** A child's box after its parent resizes, keeping a locked aspect ratio as Figma does. */\nexport function constrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): Rect {\n let x = constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal)\n let y = constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical)\n ;({ x, y } = keepLockedRatio(x, y, horizontal, vertical, aspectRatio))\n return {\n x: Math.round(x.position),\n y: Math.round(y.position),\n width: Math.round(x.size),\n height: Math.round(y.size)\n }\n}\n\nfunction layoutConstrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): { position: number; size: number } {\n const delta = Math.round(parentAfter) - Math.round(parentBefore)\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') {\n return { position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2), size }\n }\n if (constraint === 'STRETCH') return { position, size: Math.abs(size + delta) }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: Math.round(position * scale * 128) / 128, size: size * scale }\n }\n return { position, size }\n}\n\n/**\n * Where a child goes when layout resizes its parent, as Figma places a layer that ignores auto\n * layout when its Hug frame grows (measured on desktop 126): Right and Left & right move or grow\n * it by the change in the parent's size rounded to whole pixels, Center by the change in its\n * rounded half, and Scale by the exact ratio, its position to 1/128 of a pixel. Sizes are not\n * rounded, so applying a run of changes one at a time lands where applying them at once does.\n */\nexport function layoutConstrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): Rect {\n const placed = keepLockedRatio(\n layoutConstrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal),\n layoutConstrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical),\n horizontal,\n vertical,\n aspectRatio\n )\n return {\n x: placed.x.position,\n y: placed.y.position,\n width: placed.x.size,\n height: placed.y.size\n }\n}\n\nexport function scaledChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n): Rect {\n return constrainedChildRect(child, parentBefore, parentAfter, 'SCALE', 'SCALE')\n}\n\nexport function scaleVectorNetworkForResize(\n vectorNetwork: VectorNetwork | null,\n originalWidth: number,\n originalHeight: number,\n width: number,\n height: number\n): VectorNetwork | null {\n if (!vectorNetwork || (originalWidth <= 0 && originalHeight <= 0)) return null\n\n // A flat side, as a straight line's, has nothing to scale along it.\n const scaleX = originalWidth > 0 ? width / originalWidth : 1\n const scaleY = originalHeight > 0 ? height / originalHeight : 1\n if (scaleX === 1 && scaleY === 1) return null\n\n return {\n vertices: vectorNetwork.vertices.map((vertex) => ({\n ...vertex,\n x: vertex.x * scaleX,\n y: vertex.y * scaleY\n })),\n segments: vectorNetwork.segments.map((segment) => ({\n ...segment,\n tangentStart: {\n x: segment.tangentStart.x * scaleX,\n y: segment.tangentStart.y * scaleY\n },\n tangentEnd: {\n x: segment.tangentEnd.x * scaleX,\n y: segment.tangentEnd.y * scaleY\n }\n })),\n regions: vectorNetwork.regions\n }\n}\n\n/** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */\nexport function createResizeSnapshot(node: SceneNode): ResizeSnapshot {\n return {\n type: node.type,\n x: node.x,\n y: node.y,\n width: node.width,\n height: node.height,\n vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,\n fillGeometry: copyGeometryPaths(node.fillGeometry),\n strokeGeometry: copyGeometryPaths(node.strokeGeometry),\n derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs),\n strokes: copyStrokes(node.strokes),\n textPathData: node.textPathData ? structuredClone(node.textPathData) : null,\n textPathBox: node.textPathBox ? { ...node.textPathBox } : null\n }\n}\n\nfunction scaleDerivedGlyphs(\n glyphs: DerivedTextGlyph[] | null,\n sx: number,\n sy: number\n): DerivedTextGlyph[] | null {\n if (!glyphs?.length) return glyphs\n return glyphs.map((g) => ({\n ...g,\n x: g.x * sx,\n y: g.y * sy,\n scaleX: (g.scaleX ?? 1) * sx,\n scaleY: (g.scaleY ?? 1) * sy,\n commandsBlob: new Uint8Array(g.commandsBlob)\n }))\n}\n\nfunction hasPath(orig: Pick<ResizeSnapshot, 'vectorNetwork'>): boolean {\n return (orig.vectorNetwork?.segments.length ?? 0) > 0\n}\n\nfunction scaleStrokes(strokes: Stroke[], sx: number, sy: number): Stroke[] {\n if (strokes.length === 0) return strokes\n // Weight is a scalar; average scale is the usual 2D → 1D compromise.\n const weightScale = (Math.abs(sx) + Math.abs(sy)) / 2\n return strokes.map((s) => ({ ...copyStroke(s), weight: s.weight * weightScale }))\n}\n\n/**\n * All geometry that must track a width/height change. Historically only\n * vectorNetwork + fillGeometry were updated — path-text strokeGeometry and\n * glyphs stayed at the pre-resize size, so shrinking a sticker made the white\n * OUTSIDE outlines look massively thick (DomeSticker resize bug).\n */\nexport function scaledGeometryChanges(\n orig: Pick<\n ResizeSnapshot,\n | 'type'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n >,\n origWidth: number,\n origHeight: number,\n width: number,\n height: number\n): Partial<SceneNode> {\n if (origWidth <= 0 || origHeight <= 0) return {}\n const sx = width / origWidth\n const sy = height / origHeight\n if (sx === 1 && sy === 1) return {}\n\n const changes: Partial<SceneNode> = {}\n const resizedVN = scaleVectorNetworkForResize(\n orig.vectorNetwork,\n origWidth,\n origHeight,\n width,\n height\n )\n if (resizedVN) changes.vectorNetwork = resizedVN\n\n if (orig.fillGeometry.length > 0) {\n changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy)\n }\n // A stroke keeps its weight through a resize, as in Figma, so a saved stroke outline goes where\n // the stroke can be drawn again at its weight: from a path, or from a shape's own outline.\n // Text and a vector with only its outline keep scaling the outline, which is all they have.\n const outlineOnly = orig.type === 'TEXT' || (orig.type === 'VECTOR' && !hasPath(orig))\n if (orig.strokeGeometry.length > 0) {\n changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : []\n }\n // Path text scales with its path, including baked path text that kept only rotated glyphs;\n // other text reflows in the new box, so its glyphs are dropped.\n const glyphs = orig.derivedTextGlyphs ?? []\n const pathText =\n !!orig.textPathData || !!orig.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0)\n if (glyphs.length > 0 && pathText) {\n changes.derivedTextGlyphs = scaleDerivedGlyphs(glyphs, sx, sy)\n // Keep the layout/selection box in sync with the scaled glyphs. reflow\n // overrides this when it applies; this covers the fallback where reflow\n // returns null (no path data) so the box doesn't carry a stale size.\n if (orig.textPathBox) {\n changes.textPathBox = {\n x: orig.textPathBox.x * sx,\n y: orig.textPathBox.y * sy,\n width: orig.textPathBox.width * sx,\n height: orig.textPathBox.height * sy\n }\n }\n }\n // Glyphs scaled as a picture take their strokes along; any other stroke keeps its weight, as\n // Figma reports it, even where only a scaled outline can draw it.\n if (orig.strokes.length > 0 && glyphs.length > 0 && pathText) {\n changes.strokes = scaleStrokes(orig.strokes, sx, sy)\n }\n return changes\n}\n\nexport function collectResizeDescendants(\n graph: ResizeGraph,\n rootId: string\n): Map<string, ResizeSnapshot> | null {\n const root = graph.getNode(rootId)\n if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null\n const snapshots = new Map<string, ResizeSnapshot>()\n\n const collect = (parentId: string) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n for (const childId of parent.childIds) {\n const child = graph.getNode(childId)\n if (!child) continue\n snapshots.set(childId, createResizeSnapshot(child))\n collect(childId)\n }\n }\n\n collect(rootId)\n return snapshots.size > 0 ? snapshots : null\n}\n\nexport function computeConstrainedResizeChanges(\n graph: ResizeGraph,\n rootId: string,\n rootBefore: Pick<Rect, 'width' | 'height'>,\n rootAfter: Pick<Rect, 'width' | 'height'>,\n originals: ReadonlyMap<string, ResizeSnapshot>\n): Map<string, Partial<SceneNode>> {\n const changes = new Map<string, Partial<SceneNode>>()\n\n const compute = (\n parentId: string,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n ) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n const scalesChildren = parent.type === 'GROUP' || parent.type === 'BOOLEAN_OPERATION'\n for (const childId of parent.childIds) {\n const original = originals.get(childId)\n const child = graph.getNode(childId)\n if (!original || !child) continue\n const isInFlow = parent.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE'\n if (isInFlow) {\n compute(childId, original, child)\n continue\n }\n const rect = scalesChildren\n ? scaledChildRect(original, parentBefore, parentAfter)\n : constrainedChildRect(\n original,\n parentBefore,\n parentAfter,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n )\n const childChanges: Partial<SceneNode> = {\n ...rect,\n ...scaledGeometryChanges(original, original.width, original.height, rect.width, rect.height)\n }\n changes.set(childId, childChanges)\n // The final pass sees layout containers after Yoga has resolved HUG/FILL sizing.\n compute(childId, original, child.layoutMode === 'NONE' ? rect : child)\n }\n }\n\n compute(rootId, rootBefore, rootAfter)\n return changes\n}\n"],"mappings":";;;AAsCA,MAAM,6CAA6B,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,gBACP,UACA,MACA,cACA,aACA,YACoC;CACpC,MAAM,QAAQ,cAAc;CAC5B,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,WAAW;EAAO;CAAK;CACpE,IAAI,eAAe,UAAU,OAAO;EAAE,UAAU,WAAW,QAAQ;EAAG;CAAK;CAC3E,IAAI,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M,WAAW,OAAO,UAAU;GACrC,MAAM,WAAW,UAAU,IAAI,OAAO;GACtC,MAAM,QAAQ,MAAM,QAAQ,OAAO;GACnC,IAAI,CAAC,YAAY,CAAC,OAAO;GAEzB,IADiB,OAAO,eAAe,UAAU,MAAM,sBAAsB,YAC/D;IACZ,QAAQ,SAAS,UAAU,KAAK;IAChC;GACF;GACA,MAAM,OAAO,iBACT,gBAAgB,UAAU,cAAc,WAAW,IACnD,qBACE,UACA,cACA,aACA,MAAM,sBACN,MAAM,oBACN,oBAAoB,KAAK,CAC3B;GACJ,MAAM,eAAmC;IACvC,GAAG;IACH,GAAG,sBAAsB,UAAU,SAAS,OAAO,SAAS,QAAQ,KAAK,OAAO,KAAK,MAAM;GAC7F;GACA,QAAQ,IAAI,SAAS,YAAY;GAEjC,QAAQ,SAAS,UAAU,MAAM,eAAe,SAAS,OAAO,KAAK;EACvE;CACF;CAEA,QAAQ,QAAQ,YAAY,SAAS;CACrC,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"resize.js","names":[],"sources":["../src/resize.ts"],"sourcesContent":["import { CONSTRAINT_PARENT_TYPES } from './constraints'\nimport { getNodeLocalMatrix } from './coordinate'\nimport {\n cloneVectorNetwork,\n copyDerivedGlyphs,\n copyGeometryPaths,\n copyStroke,\n copyStrokes,\n scaleGeometryPaths\n} from './copy'\nimport { groupFitChanges } from './group-bounds'\nimport { enforcedAspectRatio } from './layout/aspect-ratio'\nimport Matrix, { type Mat3 } from './matrix'\nimport { FITTED_CONTAINER_TYPES } from './node-defaults'\nimport type { Rect } from './primitives'\nimport type { ConstraintType, DerivedTextGlyph, SceneNode, Stroke, VectorNetwork } from './types'\n\n/**\n * Drag-start state a live resize re-scales from. Path text needs more than the\n * layout rect: its OUTSIDE stroke silhouettes and glyph outlines are baked\n * geometry that must scale with the node, and textPathBox is the layout box the\n * glyphs were reflowed against.\n */\nexport type ResizeSnapshot = Pick<\n SceneNode,\n | 'type'\n | 'x'\n | 'y'\n | 'width'\n | 'height'\n | 'flipX'\n | 'flipY'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n>\n\ninterface ResizeGraph {\n readonly rootId: string\n getNode(id: string): SceneNode | undefined\n}\n\n/**\n * Containers whose resize moves their children: the constraint parents, and groups and booleans,\n * which scale theirs.\n */\nconst CONSTRAINT_CONTAINER_TYPES = new Set<SceneNode['type']>([\n ...CONSTRAINT_PARENT_TYPES,\n ...FITTED_CONTAINER_TYPES\n])\n\ntype AxisPlacement = { position: number; size: number; flipped?: boolean }\n\n/** A child's box after its parent resizes, and the axes on which it turned over. */\nexport type ConstrainedRect = Rect & { flipsX?: boolean; flipsY?: boolean }\n\n/**\n * Where a constraint places a child on one axis when its parent goes from `parentBefore` to\n * `parentAfter`, as Figma does (live-measured, #1060, #1816): Right and Left & right move or grow\n * it by the change in the parent's size rounded to whole pixels, Center by the change in its\n * rounded half, and Scale by the exact ratio. The child's own box is never rounded, so a resize\n * to the same size changes nothing. Left & right that would leave no size keeps the axis as it\n * was; past zero, the child turns over and its box runs back from the edge it was pinned to, as\n * the layer is mirrored in Figma.\n */\nfunction constrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): AxisPlacement {\n const delta = Math.round(parentAfter) - Math.round(parentBefore)\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') {\n return { position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2), size }\n }\n if (constraint === 'STRETCH') {\n const stretched = size + delta\n if (stretched === 0) return { position, size }\n if (stretched > 0) return { position, size: stretched }\n return { position: position + stretched, size: -stretched, flipped: true }\n }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: position * scale, size: size * scale }\n }\n return { position, size }\n}\n\nconst FLEXIBLE_CONSTRAINTS: ReadonlySet<ConstraintType> = new Set(['STRETCH', 'SCALE'])\n\n/** The axis at `size`, keeping the edge or centre its constraint pins where it was placed. */\nfunction resizedInPlace(\n placed: AxisPlacement,\n size: number,\n constraint: ConstraintType\n): AxisPlacement {\n if (constraint === 'MAX') return { position: placed.position + placed.size - size, size }\n if (constraint === 'CENTER') return { position: placed.position + (placed.size - size) / 2, size }\n return { position: placed.position, size }\n}\n\n/** Keep a placed box's constrained edges or center when its content determines its size. */\nexport function resizedChildRect(\n placed: Rect,\n size: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType\n): Rect {\n const x = resizedInPlace({ position: placed.x, size: placed.width }, size.width, horizontal)\n const y = resizedInPlace({ position: placed.y, size: placed.height }, size.height, vertical)\n return { x: x.position, y: y.position, width: x.size, height: y.size }\n}\n\n/**\n * A locked aspect ratio holds when exactly one axis follows the parent, as in Figma: that axis\n * sizes the other. With both axes following the parent, or neither, the ratio gives way.\n */\nfunction keepLockedRatio(\n x: AxisPlacement,\n y: AxisPlacement,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null\n): { x: AxisPlacement; y: AxisPlacement } {\n const flexibleX = FLEXIBLE_CONSTRAINTS.has(horizontal)\n if (aspectRatio === null || flexibleX === FLEXIBLE_CONSTRAINTS.has(vertical)) return { x, y }\n return flexibleX\n ? { x, y: resizedInPlace(y, x.size / aspectRatio, vertical) }\n : { x: resizedInPlace(x, y.size * aspectRatio, horizontal), y }\n}\n\n/**\n * A child's box after its parent resizes, by a handle, `resize()`, layout, or an instance taking\n * another size than its component, keeping a locked aspect ratio as Figma does.\n */\nexport function constrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): ConstrainedRect {\n const { x, y } = keepLockedRatio(\n constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal),\n constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical),\n horizontal,\n vertical,\n aspectRatio\n )\n const rect: ConstrainedRect = { x: x.position, y: y.position, width: x.size, height: y.size }\n if (x.flipped) rect.flipsX = true\n if (y.flipped) rect.flipsY = true\n return rect\n}\n\nexport function scaledChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n): Rect {\n return constrainedChildRect(child, parentBefore, parentAfter, 'SCALE', 'SCALE')\n}\n\n/** How much a side grows; a flat side, as a straight line's, has nothing to scale along it. */\nfunction sideScale(original: number, size: number): number {\n return original > 0 ? size / original : 1\n}\n\nexport function scaleVectorNetworkForResize(\n vectorNetwork: VectorNetwork | null,\n originalWidth: number,\n originalHeight: number,\n width: number,\n height: number\n): VectorNetwork | null {\n if (!vectorNetwork || (originalWidth <= 0 && originalHeight <= 0)) return null\n\n const scaleX = sideScale(originalWidth, width)\n const scaleY = sideScale(originalHeight, height)\n if (scaleX === 1 && scaleY === 1) return null\n\n return {\n vertices: vectorNetwork.vertices.map((vertex) => ({\n ...vertex,\n x: vertex.x * scaleX,\n y: vertex.y * scaleY\n })),\n segments: vectorNetwork.segments.map((segment) => ({\n ...segment,\n tangentStart: {\n x: segment.tangentStart.x * scaleX,\n y: segment.tangentStart.y * scaleY\n },\n tangentEnd: {\n x: segment.tangentEnd.x * scaleX,\n y: segment.tangentEnd.y * scaleY\n }\n })),\n regions: vectorNetwork.regions\n }\n}\n\n/** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */\nexport function createResizeSnapshot(node: SceneNode): ResizeSnapshot {\n return {\n type: node.type,\n x: node.x,\n y: node.y,\n width: node.width,\n height: node.height,\n flipX: node.flipX,\n flipY: node.flipY,\n vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,\n fillGeometry: copyGeometryPaths(node.fillGeometry),\n strokeGeometry: copyGeometryPaths(node.strokeGeometry),\n derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs),\n strokes: copyStrokes(node.strokes),\n textPathData: node.textPathData ? structuredClone(node.textPathData) : null,\n textPathBox: node.textPathBox ? { ...node.textPathBox } : null\n }\n}\n\nfunction scaleDerivedGlyphs(\n glyphs: DerivedTextGlyph[] | null,\n sx: number,\n sy: number\n): DerivedTextGlyph[] | null {\n if (!glyphs?.length) return glyphs\n return glyphs.map((g) => ({\n ...g,\n x: g.x * sx,\n y: g.y * sy,\n scaleX: (g.scaleX ?? 1) * sx,\n scaleY: (g.scaleY ?? 1) * sy,\n commandsBlob: new Uint8Array(g.commandsBlob)\n }))\n}\n\nfunction hasPath(orig: Pick<ResizeSnapshot, 'vectorNetwork'>): boolean {\n return (orig.vectorNetwork?.segments.length ?? 0) > 0\n}\n\nfunction scaleStrokes(strokes: Stroke[], sx: number, sy: number): Stroke[] {\n if (strokes.length === 0) return strokes\n // Weight is a scalar; average scale is the usual 2D → 1D compromise.\n const weightScale = (Math.abs(sx) + Math.abs(sy)) / 2\n return strokes.map((s) => ({ ...copyStroke(s), weight: s.weight * weightScale }))\n}\n\n/**\n * All geometry that must track a width/height change. Historically only\n * vectorNetwork + fillGeometry were updated — path-text strokeGeometry and\n * glyphs stayed at the pre-resize size, so shrinking a sticker made the white\n * OUTSIDE outlines look massively thick (DomeSticker resize bug).\n */\nexport function scaledGeometryChanges(\n orig: Pick<\n ResizeSnapshot,\n | 'type'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n >,\n origWidth: number,\n origHeight: number,\n width: number,\n height: number\n): Partial<SceneNode> {\n if (origWidth <= 0 && origHeight <= 0) return {}\n // A straight line's other side still scales.\n const sx = sideScale(origWidth, width)\n const sy = sideScale(origHeight, height)\n if (sx === 1 && sy === 1) return {}\n\n const changes: Partial<SceneNode> = {}\n const resizedVN = scaleVectorNetworkForResize(\n orig.vectorNetwork,\n origWidth,\n origHeight,\n width,\n height\n )\n if (resizedVN) changes.vectorNetwork = resizedVN\n\n if (orig.fillGeometry.length > 0) {\n changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy)\n }\n // A stroke keeps its weight through a resize, as in Figma, so a saved stroke outline goes where\n // the stroke can be drawn again at its weight: from a path, or from a shape's own outline.\n // Text and a vector with only its outline keep scaling the outline, which is all they have.\n const outlineOnly = orig.type === 'TEXT' || (orig.type === 'VECTOR' && !hasPath(orig))\n if (orig.strokeGeometry.length > 0) {\n changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : []\n }\n // Path text scales with its path, including baked path text that kept only rotated glyphs;\n // other text reflows in the new box, so its glyphs are dropped.\n const glyphs = orig.derivedTextGlyphs ?? []\n const pathText =\n !!orig.textPathData || !!orig.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0)\n if (glyphs.length > 0 && pathText) {\n changes.derivedTextGlyphs = scaleDerivedGlyphs(glyphs, sx, sy)\n // Keep the layout/selection box in sync with the scaled glyphs. reflow\n // overrides this when it applies; this covers the fallback where reflow\n // returns null (no path data) so the box doesn't carry a stale size.\n if (orig.textPathBox) {\n changes.textPathBox = {\n x: orig.textPathBox.x * sx,\n y: orig.textPathBox.y * sy,\n width: orig.textPathBox.width * sx,\n height: orig.textPathBox.height * sy\n }\n }\n }\n // Glyphs scaled as a picture take their strokes along; any other stroke keeps its weight, as\n // Figma reports it, even where only a scaled outline can draw it.\n if (orig.strokes.length > 0 && glyphs.length > 0 && pathText) {\n changes.strokes = scaleStrokes(orig.strokes, sx, sy)\n }\n return changes\n}\n\n/** Copies of the geometry a resize may change, as the snapshot held it before the resize. */\nfunction snapshotGeometry(orig: ResizeSnapshot): Partial<SceneNode> {\n return {\n vectorNetwork: orig.vectorNetwork ? cloneVectorNetwork(orig.vectorNetwork) : null,\n fillGeometry: copyGeometryPaths(orig.fillGeometry),\n strokeGeometry: copyGeometryPaths(orig.strokeGeometry),\n derivedTextGlyphs: copyDerivedGlyphs(orig.derivedTextGlyphs),\n strokes: copyStrokes(orig.strokes),\n textPathBox: orig.textPathBox ? { ...orig.textPathBox } : null\n }\n}\n\n/** Whether a box of `size` scales the snapshot's geometry, a flat side left out. */\nfunction scalesGeometry(orig: ResizeSnapshot, size: Pick<Rect, 'width' | 'height'>): boolean {\n return sideScale(orig.width, size.width) !== 1 || sideScale(orig.height, size.height) !== 1\n}\n\n/**\n * A child's geometry for its constrained `box`, scaled from the snapshot. At a box that scales\n * nothing, after an earlier frame of the same drag scaled it, the child takes its snapshot\n * geometry again, as nothing else would undo that scaling.\n */\nfunction constrainedGeometryChanges(\n orig: ResizeSnapshot,\n current: Pick<SceneNode, 'width' | 'height'>,\n box: Pick<Rect, 'width' | 'height'>\n): Partial<SceneNode> {\n if (scalesGeometry(orig, box))\n return scaledGeometryChanges(orig, orig.width, orig.height, box.width, box.height)\n return scalesGeometry(orig, current) ? snapshotGeometry(orig) : {}\n}\n\nexport function collectResizeDescendants(\n graph: ResizeGraph,\n rootId: string\n): Map<string, ResizeSnapshot> | null {\n const root = graph.getNode(rootId)\n if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null\n const snapshots = new Map<string, ResizeSnapshot>()\n\n const collect = (parentId: string) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n for (const childId of parent.childIds) {\n const child = graph.getNode(childId)\n if (!child) continue\n snapshots.set(childId, createResizeSnapshot(child))\n collect(childId)\n }\n }\n\n collect(rootId)\n return snapshots.size > 0 ? snapshots : null\n}\n\n/**\n * The flips a child takes when its constraints place it from `from`, written only where they\n * differ from the ones it has now, so a drag that crosses back undoes its own turn.\n */\nexport function flipChanges(\n from: Pick<SceneNode, 'flipX' | 'flipY'>,\n current: Pick<SceneNode, 'flipX' | 'flipY'>,\n flipsX = false,\n flipsY = false\n): Partial<Pick<SceneNode, 'flipX' | 'flipY'>> {\n const changes: Partial<Pick<SceneNode, 'flipX' | 'flipY'>> = {}\n const flipX = from.flipX !== flipsX\n const flipY = from.flipY !== flipsY\n if (flipX !== current.flipX) changes.flipX = flipX\n if (flipY !== current.flipY) changes.flipY = flipY\n return changes\n}\n\ntype Size = Pick<Rect, 'width' | 'height'>\n\n/** One constrained resize: the graph, where each layer was when it began, and what it changes. */\ninterface ResizePlan {\n graph: ResizeGraph\n originals: ReadonlyMap<string, ResizeSnapshot>\n changes: Map<string, Partial<SceneNode>>\n}\n\n/** The layer as the resize found it, or as the resize leaves it with its changes so far. */\nfunction startOf(plan: ResizePlan, id: string): SceneNode | undefined {\n const node = plan.graph.getNode(id)\n const original = plan.originals.get(id)\n return node && original ? { ...node, ...original } : node\n}\n\nfunction plannedOf(plan: ResizePlan, id: string): SceneNode | undefined {\n const node = startOf(plan, id)\n const changes = plan.changes.get(id)\n return node && changes ? { ...node, ...changes } : node\n}\n\nfunction mergeChanges(plan: ResizePlan, id: string, changes: Partial<SceneNode>) {\n plan.changes.set(id, { ...plan.changes.get(id), ...changes })\n}\n\n/** Writes where a layer's constraints put it, then places its own children. */\nfunction placeConstrained(\n plan: ResizePlan,\n child: SceneNode,\n original: ResizeSnapshot,\n rect: ConstrainedRect,\n toParent: Mat3 | null\n) {\n const { flipsX, flipsY, ...box } = rect\n const position = toParent ? Matrix.mapPoint(toParent, box) : box\n plan.changes.set(child.id, {\n ...box,\n ...position,\n ...flipChanges(original, child, flipsX, flipsY),\n ...constrainedGeometryChanges(original, child, box)\n })\n // The final pass sees layout containers after Yoga has resolved HUG/FILL sizing.\n placeChildren(plan, child.id, original, child.layoutMode === 'NONE' ? box : child)\n}\n\n/**\n * Places the layers in a group or boolean whose frame resized. The group owns no constraints: each\n * layer in it keeps its place in the frame by its own, through nested groups, and the groups then\n * fit around them, as in Figma (live, #1835). A layer is placed in the frame's space and written\n * back in its group's.\n */\nfunction placeGroupedLayers(\n plan: ResizePlan,\n group: SceneNode,\n toFrame: Mat3,\n frameBefore: Size,\n frameAfter: Size\n) {\n for (const childId of group.childIds) {\n const child = plan.graph.getNode(childId)\n const original = plan.originals.get(childId)\n const start = startOf(plan, childId)\n if (!child || !original || !start) continue\n if (FITTED_CONTAINER_TYPES.has(child.type)) {\n const inner = Matrix.multiply(toFrame, getNodeLocalMatrix(start))\n placeGroupedLayers(plan, start, inner, frameBefore, frameAfter)\n continue\n }\n const inFrame = Matrix.mapPoint(toFrame, original)\n const rect = constrainedChildRect(\n { ...inFrame, width: original.width, height: original.height },\n frameBefore,\n frameAfter,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n )\n placeConstrained(plan, child, original, rect, Matrix.invert(toFrame))\n }\n fitPlannedGroup(plan, group.id)\n}\n\nconst PLACEMENT_KEYS = ['x', 'y', 'width', 'height'] as const\n\n/**\n * Fits a group to its layers where the resize put them, when any of them moved: a boolean's box\n * is its result's, which only the renderer measures, so one whose operands stay keeps its box. A\n * drag places from the start each time, so the group's box is always written.\n */\nfunction fitPlannedGroup(plan: ResizePlan, groupId: string) {\n const group = plannedOf(plan, groupId)\n if (!group) return\n const { x, y, width, height } = group\n mergeChanges(plan, groupId, { x, y, width, height })\n const moved = group.childIds.some((id) => {\n const start = startOf(plan, id)\n const planned = plannedOf(plan, id)\n return start && planned && PLACEMENT_KEYS.some((key) => start[key] !== planned[key])\n })\n if (!moved) return\n const reader = { rootId: plan.graph.rootId, getNode: (id: string) => plannedOf(plan, id) }\n const children = group.childIds.flatMap((id) => reader.getNode(id) ?? [])\n const fit = groupFitChanges(reader, group, children)\n for (const [id, changes] of fit ?? []) mergeChanges(plan, id, changes)\n}\n\n/**\n * Places the children of a layer that went from `parentBefore` to `parentAfter`: a frame's by their\n * constraints, the layers in its groups and booleans by theirs, a group's or boolean's own scaled.\n */\nfunction placeChildren(plan: ResizePlan, parentId: string, parentBefore: Size, parentAfter: Size) {\n const parent = plan.graph.getNode(parentId)\n if (!parent) return\n const scalesChildren = FITTED_CONTAINER_TYPES.has(parent.type)\n for (const childId of parent.childIds) {\n const original = plan.originals.get(childId)\n const child = plan.graph.getNode(childId)\n if (!original || !child) continue\n const isInFlow = parent.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE'\n if (isInFlow) {\n placeChildren(plan, childId, original, child)\n continue\n }\n if (!scalesChildren && FITTED_CONTAINER_TYPES.has(child.type)) {\n const start = { ...child, ...original }\n placeGroupedLayers(plan, start, getNodeLocalMatrix(start), parentBefore, parentAfter)\n continue\n }\n const rect: ConstrainedRect = scalesChildren\n ? scaledChildRect(original, parentBefore, parentAfter)\n : constrainedChildRect(\n original,\n parentBefore,\n parentAfter,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n )\n placeConstrained(plan, child, original, rect, null)\n }\n}\n\n/**\n * Where the descendants of a layer go when it resizes from `rootBefore` to `rootAfter`, from the\n * places `originals` recorded.\n */\nexport function computeConstrainedResizeChanges(\n graph: ResizeGraph,\n rootId: string,\n rootBefore: Size,\n rootAfter: Size,\n originals: ReadonlyMap<string, ResizeSnapshot>\n): Map<string, Partial<SceneNode>> {\n const plan: ResizePlan = { graph, originals, changes: new Map() }\n placeChildren(plan, rootId, rootBefore, rootAfter)\n return plan.changes\n}\n"],"mappings":";;;;;;;;;;;;AAkDA,MAAM,6CAA6B,IAAI,IAAuB,CAC5D,GAAG,yBACH,GAAG,sBACL,CAAC;;;;;;;;;;AAgBD,SAAS,gBACP,UACA,MACA,cACA,aACA,YACe;CACf,MAAM,QAAQ,KAAK,MAAM,WAAW,IAAI,KAAK,MAAM,YAAY;CAC/D,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,WAAW;EAAO;CAAK;CACpE,IAAI,eAAe,UACjB,OAAO;EAAE,UAAU,WAAW,KAAK,MAAM,cAAc,CAAC,IAAI,KAAK,MAAM,eAAe,CAAC;EAAG;CAAK;CAEjG,IAAI,eAAe,WAAW;EAC5B,MAAM,YAAY,OAAO;EACzB,IAAI,cAAc,GAAG,OAAO;GAAE;GAAU;EAAK;EAC7C,IAAI,YAAY,GAAG,OAAO;GAAE;GAAU,MAAM;EAAU;EACtD,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AAU,MAAM,sBAAsB,YAC/D;GACZ,cAAc,MAAM,SAAS,UAAU,KAAK;GAC5C;EACF;EACA,IAAI,CAAC,kBAAkB,uBAAuB,IAAI,MAAM,IAAI,GAAG;GAC7D,MAAM,QAAQ;IAAE,GAAG;IAAO,GAAG;GAAS;GACtC,mBAAmB,MAAM,OAAO,mBAAmB,KAAK,GAAG,cAAc,WAAW;GACpF;EACF;EAWA,iBAAiB,MAAM,OAAO,UAVA,iBAC1B,gBAAgB,UAAU,cAAc,WAAW,IACnD,qBACE,UACA,cACA,aACA,MAAM,sBACN,MAAM,oBACN,oBAAoB,KAAK,CAC3B,GAC0C,IAAI;CACpD;AACF;;;;;AAMA,SAAgB,gCACd,OACA,QACA,YACA,WACA,WACiC;CACjC,MAAM,OAAmB;EAAE;EAAO;EAAW,yBAAS,IAAI,IAAI;CAAE;CAChE,cAAc,MAAM,QAAQ,YAAY,SAAS;CACjD,OAAO,KAAK;AACd"}
|
package/dist/scaling/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { scaleNodeChanges } from "./node.js";
|
|
2
|
-
import { rescaleNodeTree } from "./tree.js";
|
|
3
|
-
|
|
2
|
+
import { MIN_RESCALE, RescaleOptions, rescaleNodeChanges, rescaleNodeTree, rescaleTargets, scaleRoots } from "./tree.js";
|
|
3
|
+
import { ScaleSnapshot, scaledSnapshotChanges, snapshotScale } from "./snapshot.js";
|
|
4
|
+
export { MIN_RESCALE, type RescaleOptions, type ScaleSnapshot, rescaleNodeChanges, rescaleNodeTree, rescaleTargets, scaleNodeChanges, scaleRoots, scaledSnapshotChanges, snapshotScale };
|
package/dist/scaling/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { scaleNodeChanges } from "./node.js";
|
|
2
|
-
import { rescaleNodeTree } from "./tree.js";
|
|
3
|
-
|
|
2
|
+
import { MIN_RESCALE, rescaleNodeChanges, rescaleNodeTree, rescaleTargets, scaleRoots } from "./tree.js";
|
|
3
|
+
import { scaledSnapshotChanges, snapshotScale } from "./snapshot.js";
|
|
4
|
+
export { MIN_RESCALE, rescaleNodeChanges, rescaleNodeTree, rescaleTargets, scaleNodeChanges, scaleRoots, scaledSnapshotChanges, snapshotScale };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","names":[],"sources":["../../src/scaling/node.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"node.d.ts","names":[],"sources":["../../src/scaling/node.ts"],"mappings":";;iBAyHgB,iBACd,MAAM,WACN,eACA,yBACC,QAAQ"}
|
package/dist/scaling/node.js
CHANGED
|
@@ -20,7 +20,11 @@ function scaledEffects(effects, scale) {
|
|
|
20
20
|
y: effect.offset.y * scale
|
|
21
21
|
},
|
|
22
22
|
radius: effect.radius * scale,
|
|
23
|
-
spread: effect.spread * scale
|
|
23
|
+
spread: effect.spread * scale,
|
|
24
|
+
...effect.progressive ? { progressive: {
|
|
25
|
+
...structuredClone(effect.progressive),
|
|
26
|
+
startRadius: effect.progressive.startRadius * scale
|
|
27
|
+
} } : {}
|
|
24
28
|
}));
|
|
25
29
|
}
|
|
26
30
|
function scaledFills(fills, scale) {
|
package/dist/scaling/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","names":[],"sources":["../../src/scaling/node.ts"],"sourcesContent":["import { cloneVectorNetwork, scaleGeometryPaths } from '../copy'\nimport { scaledTextLength } from '../text/lengths'\nimport { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'\nimport {\n type Effect,\n type Fill,\n type GridTrack,\n type LayoutGrid,\n type SceneNode,\n type Stroke,\n type StyleRun,\n type TextParagraphStyle\n} from '../types'\n\nfunction scaledOptional(value: number | null, scale: number): number | null {\n return value == null ? null : value * scale\n}\n\nfunction scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {\n return strokes.map((stroke) => ({\n ...structuredClone(stroke),\n weight: stroke.weight * scale,\n dashPattern: stroke.dashPattern?.map((value) => value * scale)\n }))\n}\n\nfunction scaledEffects(effects: readonly Effect[], scale: number): Effect[] {\n return effects.map((effect) => ({\n ...structuredClone(effect),\n offset: { x: effect.offset.x * scale, y: effect.offset.y * scale },\n radius: effect.radius * scale,\n spread: effect.spread * scale\n }))\n}\n\nfunction scaledFills(fills: readonly Fill[], scale: number): Fill[] {\n return fills.map((fill) => ({\n ...structuredClone(fill),\n scale: fill.scale == null ? undefined : fill.scale * scale,\n spacing: fill.spacing == null ? undefined : fill.spacing * scale,\n patternSpacing: fill.patternSpacing\n ? { x: fill.patternSpacing.x * scale, y: fill.patternSpacing.y * scale }\n : undefined,\n noiseSize: fill.noiseSize\n ? { x: fill.noiseSize.x * scale, y: fill.noiseSize.y * scale }\n : undefined\n }))\n}\n\nfunction scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {\n return styleRuns.map((run) => ({\n ...structuredClone(run),\n style: {\n ...structuredClone(run.style),\n fontSize: run.style.fontSize == null ? undefined : run.style.fontSize * scale,\n letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),\n lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),\n textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),\n textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)\n }\n }))\n}\n\nfunction scaledParagraphStyles(\n paragraphs: readonly TextParagraphStyle[],\n scale: number\n): TextParagraphStyle[] {\n return paragraphs.map((style) => {\n const scaled = { ...style }\n for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {\n const value = style[field]\n if (value !== undefined) scaled[field] = value * scale\n }\n return scaled\n })\n}\n\nfunction scaledLayoutGrids(grids: readonly LayoutGrid[], scale: number): LayoutGrid[] {\n return grids.map((grid) => ({\n ...structuredClone(grid),\n offset: grid.offset == null ? undefined : grid.offset * scale,\n sectionSize: grid.sectionSize == null ? undefined : grid.sectionSize * scale,\n gutterSize: grid.gutterSize == null ? undefined : grid.gutterSize * scale\n }))\n}\n\nfunction scaledGridTracks(tracks: readonly GridTrack[], scale: number): GridTrack[] {\n return tracks.map((track) => ({\n ...track,\n value: track.sizing === 'FIXED' ? track.value * scale : track.value\n }))\n}\n\nfunction scaledVectorNetwork(node: SceneNode, scale: number): SceneNode['vectorNetwork'] {\n if (!node.vectorNetwork) return null\n const network = cloneVectorNetwork(node.vectorNetwork)\n for (const vertex of network.vertices) {\n vertex.x *= scale\n vertex.y *= scale\n }\n for (const segment of network.segments) {\n segment.tangentStart.x *= scale\n segment.tangentStart.y *= scale\n segment.tangentEnd.x *= scale\n segment.tangentEnd.y *= scale\n }\n // A region's own paints scale as the layer's do.\n for (const region of network.regions) {\n if (region.fills) region.fills = scaledFills(region.fills, scale)\n }\n return network\n}\n\nexport function scaleNodeChanges(\n node: SceneNode,\n scale: number,\n scalePosition: boolean\n): Partial<SceneNode> {\n return {\n x: scalePosition ? node.x * scale : node.x,\n y: scalePosition ? node.y * scale : node.y,\n width: node.width * scale,\n height: node.height * scale,\n minWidth: scaledOptional(node.minWidth, scale),\n maxWidth: scaledOptional(node.maxWidth, scale),\n minHeight: scaledOptional(node.minHeight, scale),\n maxHeight: scaledOptional(node.maxHeight, scale),\n cornerRadius: node.cornerRadius * scale,\n topLeftRadius: node.topLeftRadius * scale,\n topRightRadius: node.topRightRadius * scale,\n bottomRightRadius: node.bottomRightRadius * scale,\n bottomLeftRadius: node.bottomLeftRadius * scale,\n fontSize: node.fontSize * scale,\n letterSpacing: scaledTextLength(node.letterSpacing, scale),\n lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),\n textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),\n textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),\n styleRuns: scaledStyleRuns(node.styleRuns, scale),\n listSpacing: node.listSpacing * scale,\n paragraphSpacing: node.paragraphSpacing * scale,\n paragraphIndent: node.paragraphIndent * scale,\n textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),\n itemSpacing: node.itemSpacing * scale,\n counterAxisSpacing: node.counterAxisSpacing * scale,\n paddingTop: node.paddingTop * scale,\n paddingRight: node.paddingRight * scale,\n paddingBottom: node.paddingBottom * scale,\n paddingLeft: node.paddingLeft * scale,\n gridColumnGap: node.gridColumnGap * scale,\n gridRowGap: node.gridRowGap * scale,\n gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),\n gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),\n strokes: scaledStrokes(node.strokes, scale),\n strokeWeight: node.strokeWeight * scale,\n dashPattern: node.dashPattern.map((value) => value * scale),\n borderTopWeight: node.borderTopWeight * scale,\n borderRightWeight: node.borderRightWeight * scale,\n borderBottomWeight: node.borderBottomWeight * scale,\n borderLeftWeight: node.borderLeftWeight * scale,\n strokeMiterLimit: node.strokeMiterLimit,\n effects: scaledEffects(node.effects, scale),\n fills: scaledFills(node.fills, scale),\n layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),\n vectorNetwork: scaledVectorNetwork(node, scale),\n fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),\n strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale)\n }\n}\n"],"mappings":";;;;AAcA,SAAS,eAAe,OAAsB,OAA8B;CAC1E,OAAO,SAAS,OAAO,OAAO,QAAQ;AACxC;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,YAAY;EAC9B,GAAG,gBAAgB,MAAM;EACzB,QAAQ,OAAO,SAAS;EACxB,aAAa,OAAO,aAAa,KAAK,UAAU,QAAQ,KAAK;CAC/D,EAAE;AACJ;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,YAAY;EAC9B,GAAG,gBAAgB,MAAM;EACzB,QAAQ;GAAE,GAAG,OAAO,OAAO,IAAI;GAAO,GAAG,OAAO,OAAO,IAAI;EAAM;EACjE,QAAQ,OAAO,SAAS;EACxB,QAAQ,OAAO,SAAS;CA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/node.ts"],"sourcesContent":["import { cloneVectorNetwork, scaleGeometryPaths } from '../copy'\nimport { scaledTextLength } from '../text/lengths'\nimport { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'\nimport {\n type Effect,\n type Fill,\n type GridTrack,\n type LayoutGrid,\n type SceneNode,\n type Stroke,\n type StyleRun,\n type TextParagraphStyle\n} from '../types'\n\nfunction scaledOptional(value: number | null, scale: number): number | null {\n return value == null ? null : value * scale\n}\n\nfunction scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {\n return strokes.map((stroke) => ({\n ...structuredClone(stroke),\n weight: stroke.weight * scale,\n dashPattern: stroke.dashPattern?.map((value) => value * scale)\n }))\n}\n\nfunction scaledEffects(effects: readonly Effect[], scale: number): Effect[] {\n return effects.map((effect) => ({\n ...structuredClone(effect),\n offset: { x: effect.offset.x * scale, y: effect.offset.y * scale },\n radius: effect.radius * scale,\n spread: effect.spread * scale,\n ...(effect.progressive\n ? {\n progressive: {\n ...structuredClone(effect.progressive),\n startRadius: effect.progressive.startRadius * scale\n }\n }\n : {})\n }))\n}\n\nfunction scaledFills(fills: readonly Fill[], scale: number): Fill[] {\n return fills.map((fill) => ({\n ...structuredClone(fill),\n scale: fill.scale == null ? undefined : fill.scale * scale,\n spacing: fill.spacing == null ? undefined : fill.spacing * scale,\n patternSpacing: fill.patternSpacing\n ? { x: fill.patternSpacing.x * scale, y: fill.patternSpacing.y * scale }\n : undefined,\n noiseSize: fill.noiseSize\n ? { x: fill.noiseSize.x * scale, y: fill.noiseSize.y * scale }\n : undefined\n }))\n}\n\nfunction scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {\n return styleRuns.map((run) => ({\n ...structuredClone(run),\n style: {\n ...structuredClone(run.style),\n fontSize: run.style.fontSize == null ? undefined : run.style.fontSize * scale,\n letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),\n lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),\n textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),\n textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)\n }\n }))\n}\n\nfunction scaledParagraphStyles(\n paragraphs: readonly TextParagraphStyle[],\n scale: number\n): TextParagraphStyle[] {\n return paragraphs.map((style) => {\n const scaled = { ...style }\n for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {\n const value = style[field]\n if (value !== undefined) scaled[field] = value * scale\n }\n return scaled\n })\n}\n\nfunction scaledLayoutGrids(grids: readonly LayoutGrid[], scale: number): LayoutGrid[] {\n return grids.map((grid) => ({\n ...structuredClone(grid),\n offset: grid.offset == null ? undefined : grid.offset * scale,\n sectionSize: grid.sectionSize == null ? undefined : grid.sectionSize * scale,\n gutterSize: grid.gutterSize == null ? undefined : grid.gutterSize * scale\n }))\n}\n\nfunction scaledGridTracks(tracks: readonly GridTrack[], scale: number): GridTrack[] {\n return tracks.map((track) => ({\n ...track,\n value: track.sizing === 'FIXED' ? track.value * scale : track.value\n }))\n}\n\nfunction scaledVectorNetwork(node: SceneNode, scale: number): SceneNode['vectorNetwork'] {\n if (!node.vectorNetwork) return null\n const network = cloneVectorNetwork(node.vectorNetwork)\n for (const vertex of network.vertices) {\n vertex.x *= scale\n vertex.y *= scale\n }\n for (const segment of network.segments) {\n segment.tangentStart.x *= scale\n segment.tangentStart.y *= scale\n segment.tangentEnd.x *= scale\n segment.tangentEnd.y *= scale\n }\n // A region's own paints scale as the layer's do.\n for (const region of network.regions) {\n if (region.fills) region.fills = scaledFills(region.fills, scale)\n }\n return network\n}\n\nexport function scaleNodeChanges(\n node: SceneNode,\n scale: number,\n scalePosition: boolean\n): Partial<SceneNode> {\n return {\n x: scalePosition ? node.x * scale : node.x,\n y: scalePosition ? node.y * scale : node.y,\n width: node.width * scale,\n height: node.height * scale,\n minWidth: scaledOptional(node.minWidth, scale),\n maxWidth: scaledOptional(node.maxWidth, scale),\n minHeight: scaledOptional(node.minHeight, scale),\n maxHeight: scaledOptional(node.maxHeight, scale),\n cornerRadius: node.cornerRadius * scale,\n topLeftRadius: node.topLeftRadius * scale,\n topRightRadius: node.topRightRadius * scale,\n bottomRightRadius: node.bottomRightRadius * scale,\n bottomLeftRadius: node.bottomLeftRadius * scale,\n fontSize: node.fontSize * scale,\n letterSpacing: scaledTextLength(node.letterSpacing, scale),\n lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),\n textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),\n textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),\n styleRuns: scaledStyleRuns(node.styleRuns, scale),\n listSpacing: node.listSpacing * scale,\n paragraphSpacing: node.paragraphSpacing * scale,\n paragraphIndent: node.paragraphIndent * scale,\n textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),\n itemSpacing: node.itemSpacing * scale,\n counterAxisSpacing: node.counterAxisSpacing * scale,\n paddingTop: node.paddingTop * scale,\n paddingRight: node.paddingRight * scale,\n paddingBottom: node.paddingBottom * scale,\n paddingLeft: node.paddingLeft * scale,\n gridColumnGap: node.gridColumnGap * scale,\n gridRowGap: node.gridRowGap * scale,\n gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),\n gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),\n strokes: scaledStrokes(node.strokes, scale),\n strokeWeight: node.strokeWeight * scale,\n dashPattern: node.dashPattern.map((value) => value * scale),\n borderTopWeight: node.borderTopWeight * scale,\n borderRightWeight: node.borderRightWeight * scale,\n borderBottomWeight: node.borderBottomWeight * scale,\n borderLeftWeight: node.borderLeftWeight * scale,\n strokeMiterLimit: node.strokeMiterLimit,\n effects: scaledEffects(node.effects, scale),\n fills: scaledFills(node.fills, scale),\n layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),\n vectorNetwork: scaledVectorNetwork(node, scale),\n fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),\n strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale)\n }\n}\n"],"m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qBAAqB,KAAK;EACrE,kBAAkB,iBAAiB,KAAK,kBAAkB,KAAK;EAC/D,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,cAAc,KAAK,eAAe;EAClC,aAAa,KAAK,YAAY,KAAK,UAAU,QAAQ,KAAK;EAC1D,iBAAiB,KAAK,kBAAkB;EACxC,mBAAmB,KAAK,oBAAoB;EAC5C,oBAAoB,KAAK,qBAAqB;EAC9C,kBAAkB,KAAK,mBAAmB;EAC1C,kBAAkB,KAAK;EACvB,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,OAAO,YAAY,KAAK,OAAO,KAAK;EACpC,aAAa,kBAAkB,KAAK,aAAa,KAAK;EACtD,eAAe,oBAAoB,MAAM,KAAK;EAC9C,cAAc,mBAAmB,KAAK,cAAc,OAAO,KAAK;EAChE,gBAAgB,mBAAmB,KAAK,gBAAgB,OAAO,KAAK;CACtE;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Vector } from "../primitives/index.js";
|
|
2
|
+
import { SceneGraph } from "../graph.js";
|
|
3
|
+
import { SceneNode } from "../types.js";
|
|
4
|
+
import { SelectionPlacement } from "../coordinate.js";
|
|
5
|
+
//#region src/scaling/snapshot.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The layers a Scale edit changes, as they were when it began, so every step of a drag or a
|
|
8
|
+
* scrubbed field scales from the same start rather than from its own last preview.
|
|
9
|
+
*/
|
|
10
|
+
interface ScaleSnapshot {
|
|
11
|
+
/** Each scaled root's place in its parent and on the canvas, by ID. */
|
|
12
|
+
roots: Map<string, SelectionPlacement>;
|
|
13
|
+
/** Every layer the edit changes, roots first; locked layers inside are left out. */
|
|
14
|
+
nodes: Map<string, SceneNode>;
|
|
15
|
+
}
|
|
16
|
+
/** Records the roots and the layers inside them that Figma's Scale tool changes. */
|
|
17
|
+
declare function snapshotScale(graph: SceneGraph, roots: readonly SceneNode[]): ScaleSnapshot;
|
|
18
|
+
/**
|
|
19
|
+
* What scaling the snapshot evenly by `scale` about a canvas point writes to each layer: its
|
|
20
|
+
* lengths, and for a root its place, so the point stays put and the root keeps its angle.
|
|
21
|
+
*/
|
|
22
|
+
declare function scaledSnapshotChanges(graph: SceneGraph, snapshot: ScaleSnapshot, scale: number, anchor: Vector): Map<string, Partial<SceneNode>>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ScaleSnapshot, scaledSnapshotChanges, snapshotScale };
|
|
25
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","names":[],"sources":["../../src/scaling/snapshot.ts"],"mappings":";;;;;;;;;UAUiB;;EAEf,OAAO,YAAY;;EAEnB,OAAO,YAAY;;;iBAIL,cAAc,OAAO,YAAY,gBAAgB,cAAc;;;;;iBAc/D,sBACd,OAAO,YACP,UAAU,eACV,eACA,QAAQ,SACP,YAAY,QAAQ"}
|