@open-pencil/scene-graph 0.17.0-beta.1 → 0.17.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow-caps.d.ts.map +1 -1
- package/dist/arrow-caps.js +2 -5
- package/dist/arrow-caps.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 +176 -5
- 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 +13 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +58 -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/copy.d.ts.map +1 -1
- package/dist/copy.js +9 -15
- 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 +2 -1
- package/dist/css/index.js +2 -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 +30 -46
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +63 -131
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +1 -0
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +15 -3
- package/dist/graph.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.map +1 -1
- package/dist/hit-test.js +42 -29
- package/dist/hit-test.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 +36 -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/swap.js +288 -0
- package/dist/instances/swap.js.map +1 -0
- package/dist/instances/sync.js +84 -32
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +1 -1
- package/dist/node-defaults.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 +2 -1
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +19 -4
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/scaling/tree.js +1 -1
- package/dist/shared-styles.d.ts +14 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +63 -2
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +2 -0
- 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/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/index.js +1 -1
- package/dist/transfer/nodes.js +9 -5
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +27 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/bindings.d.ts +28 -5
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +104 -14
- 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/index.d.ts +3 -3
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +23 -8
- package/dist/variables/index.js.map +1 -1
- package/package.json +7 -1
- package/src/arrow-caps.ts +2 -5
- 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 +251 -4
- package/src/components/properties.ts +92 -2
- package/src/components/variants.ts +51 -30
- package/src/connectors/hit.ts +1 -12
- package/src/connectors/pieces.ts +2 -5
- package/src/copy.ts +9 -15
- package/src/css/blend.ts +27 -0
- package/src/css/index.ts +1 -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 +78 -198
- package/src/graph.ts +27 -3
- package/src/guides.ts +5 -0
- package/src/hit-test.ts +67 -54
- package/src/instances/fields.ts +8 -0
- package/src/instances/index.ts +58 -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/swap.ts +451 -0
- package/src/instances/sync.ts +141 -42
- package/src/node-defaults.ts +2 -1
- 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 +15 -2
- package/src/shared-styles.ts +82 -1
- package/src/slots/content.ts +2 -0
- package/src/slots/frames.ts +9 -7
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +2 -2
- package/src/text/picture.ts +0 -4
- package/src/transfer/nodes.ts +7 -5
- package/src/types.ts +28 -0
- package/src/variables/bindings.ts +125 -14
- package/src/variables/fields.ts +46 -1
- package/src/variables/index.ts +35 -2
package/dist/geometry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { cubicPoint } from "./cubic.js";
|
|
1
2
|
import { arrowCapOverflow } from "./arrow-caps.js";
|
|
2
|
-
import { textLinesOverflow } from "./text/overflow.js";
|
|
3
3
|
//#region src/geometry.ts
|
|
4
4
|
function degToRad(degrees) {
|
|
5
5
|
return degrees * Math.PI / 180;
|
|
@@ -172,6 +172,26 @@ function miterRatio(network, join, limit = 4) {
|
|
|
172
172
|
}
|
|
173
173
|
return ratio;
|
|
174
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* The blur radius Figma draws: a negative one, which only a bound variable can give, draws as no
|
|
177
|
+
* blur, though the layer keeps the value.
|
|
178
|
+
*/
|
|
179
|
+
function drawnBlurRadius(radius) {
|
|
180
|
+
return Math.max(0, radius);
|
|
181
|
+
}
|
|
182
|
+
const BLUR_SIGMA_PER_RADIUS = .43;
|
|
183
|
+
/**
|
|
184
|
+
* The Gaussian sigma that draws a Figma blur radius as Figma does. Measured on Figma 126 exports,
|
|
185
|
+
* layer blur, both shadows, and background blur fall off as a Gaussian of 0.43 × radius; Figma's
|
|
186
|
+
* SVG export writes radius / 2, which is wider (`packages/core/tests/canvas/blur.test.ts`).
|
|
187
|
+
*/
|
|
188
|
+
function blurSigma(radius) {
|
|
189
|
+
return drawnBlurRadius(radius) * BLUR_SIGMA_PER_RADIUS;
|
|
190
|
+
}
|
|
191
|
+
/** The Figma blur radius that draws a Gaussian of `sigma`, the inverse of `blurSigma`. */
|
|
192
|
+
function blurRadiusForSigma(sigma) {
|
|
193
|
+
return Math.max(0, sigma) / BLUR_SIGMA_PER_RADIUS;
|
|
194
|
+
}
|
|
175
195
|
function effectOverflow(effects) {
|
|
176
196
|
let left = 0;
|
|
177
197
|
let right = 0;
|
|
@@ -180,7 +200,7 @@ function effectOverflow(effects) {
|
|
|
180
200
|
for (const effect of effects ?? []) {
|
|
181
201
|
if (!effect.visible) continue;
|
|
182
202
|
if (effect.type !== "DROP_SHADOW" && effect.type !== "LAYER_BLUR" && effect.type !== "FOREGROUND_BLUR") continue;
|
|
183
|
-
const blurSpread = effect.radius + effect.spread;
|
|
203
|
+
const blurSpread = drawnBlurRadius(effect.radius) + effect.spread;
|
|
184
204
|
left = Math.max(left, blurSpread + Math.max(0, -effect.offset.x));
|
|
185
205
|
right = Math.max(right, blurSpread + Math.max(0, effect.offset.x));
|
|
186
206
|
top = Math.max(top, blurSpread + Math.max(0, -effect.offset.y));
|
|
@@ -206,18 +226,6 @@ function computeAbsoluteBounds(nodes, getAbsolutePosition) {
|
|
|
206
226
|
}
|
|
207
227
|
return boundsToRect(bounds);
|
|
208
228
|
}
|
|
209
|
-
function computeVisualBounds(nodes, getAbsolutePosition) {
|
|
210
|
-
const bounds = createBoundsAccumulator();
|
|
211
|
-
for (const n of nodes) {
|
|
212
|
-
const abs = getAbsolutePosition(n.id);
|
|
213
|
-
const bbox = rotatedBBox(abs.x, abs.y, n.width, n.height, n.rotation ?? 0);
|
|
214
|
-
const stroke = strokeOverflow(n.strokes, n.strokeCap, n.vectorNetwork, n);
|
|
215
|
-
const effects = effectOverflow(n.effects);
|
|
216
|
-
includePoint(bounds, bbox.left - stroke - effects.left, bbox.top - stroke - effects.top);
|
|
217
|
-
includePoint(bounds, bbox.right + stroke + effects.right, bbox.bottom + stroke + effects.bottom);
|
|
218
|
-
}
|
|
219
|
-
return boundsToRect(bounds);
|
|
220
|
-
}
|
|
221
229
|
function unionVisualBounds(a, b) {
|
|
222
230
|
if (!a) return b;
|
|
223
231
|
if (!b) return a;
|
|
@@ -240,135 +248,59 @@ function intersectVisualBounds(a, b) {
|
|
|
240
248
|
maxY
|
|
241
249
|
} : null;
|
|
242
250
|
}
|
|
251
|
+
/** The path commands of a Figma geometry blob, by their byte code. */
|
|
252
|
+
const GeometryCommand = {
|
|
253
|
+
CLOSE: 0,
|
|
254
|
+
MOVE: 1,
|
|
255
|
+
LINE: 2,
|
|
256
|
+
QUAD: 3,
|
|
257
|
+
CUBIC: 4
|
|
258
|
+
};
|
|
243
259
|
/**
|
|
244
|
-
* Coordinate pairs per
|
|
245
|
-
*
|
|
246
|
-
* walkers stop instead of desyncing into coordinate bytes.
|
|
260
|
+
* Coordinate pairs per command: glyph-derived blobs are quad-heavy, so every code needs its
|
|
261
|
+
* count. Unknown codes are null, so readers stop instead of desyncing into coordinate bytes.
|
|
247
262
|
*/
|
|
248
|
-
function
|
|
249
|
-
if (command ===
|
|
250
|
-
if (command ===
|
|
251
|
-
if (command ===
|
|
252
|
-
if (command ===
|
|
263
|
+
function commandCoordCount(command) {
|
|
264
|
+
if (command === GeometryCommand.CLOSE) return 0;
|
|
265
|
+
if (command === GeometryCommand.MOVE || command === GeometryCommand.LINE) return 1;
|
|
266
|
+
if (command === GeometryCommand.QUAD) return 2;
|
|
267
|
+
if (command === GeometryCommand.CUBIC) return 3;
|
|
253
268
|
return null;
|
|
254
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Walks a Figma geometry blob: `visit` gets each command, its coordinates as x, y pairs in one
|
|
272
|
+
* array reused between calls, and the byte offset of the first coordinate. It stops at an
|
|
273
|
+
* unknown command or one cut short.
|
|
274
|
+
*/
|
|
275
|
+
function readGeometryBlob(blob, visit) {
|
|
276
|
+
const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength);
|
|
277
|
+
const coords = [];
|
|
278
|
+
let offset = 0;
|
|
279
|
+
while (offset < blob.length) {
|
|
280
|
+
const command = blob[offset];
|
|
281
|
+
const count = commandCoordCount(command);
|
|
282
|
+
if (count === null || offset + 1 + count * 8 > blob.length) return;
|
|
283
|
+
offset += 1;
|
|
284
|
+
coords.length = 0;
|
|
285
|
+
for (let i = 0; i < count; i++) coords.push(view.getFloat32(offset + i * 8, true), view.getFloat32(offset + i * 8 + 4, true));
|
|
286
|
+
visit(command, coords, offset);
|
|
287
|
+
offset += count * 8;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
255
290
|
function geometryBlobBounds(paths) {
|
|
256
291
|
const bounds = createBoundsAccumulator();
|
|
257
|
-
for (const path of paths) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
let offset = 0;
|
|
261
|
-
while (offset < blob.length) {
|
|
262
|
-
const command = blob[offset++];
|
|
263
|
-
const coords = geometryCommandCoordCount(command);
|
|
264
|
-
if (coords == null) break;
|
|
265
|
-
for (let i = 0; i < coords; i++) {
|
|
266
|
-
if (offset + 8 > blob.length) break;
|
|
267
|
-
includePoint(bounds, dv.getFloat32(offset, true), dv.getFloat32(offset + 4, true));
|
|
268
|
-
offset += 8;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
292
|
+
for (const path of paths) readGeometryBlob(path.commandsBlob, (_, coords) => {
|
|
293
|
+
for (let i = 0; i < coords.length; i += 2) includePoint(bounds, coords[i], coords[i + 1]);
|
|
294
|
+
});
|
|
272
295
|
return bounds.minX === Infinity ? null : boundsToRect(bounds);
|
|
273
296
|
}
|
|
274
|
-
function transformLocalPoint(node, point) {
|
|
275
|
-
let x = node.flipX ? node.width - point.x : point.x;
|
|
276
|
-
let y = node.flipY ? node.height - point.y : point.y;
|
|
277
|
-
const rotation = node.rotation ?? 0;
|
|
278
|
-
if (rotation !== 0) {
|
|
279
|
-
const rotated = rotatePoint(x, y, node.width / 2, node.height / 2, degToRad(rotation));
|
|
280
|
-
x = rotated.x;
|
|
281
|
-
y = rotated.y;
|
|
282
|
-
}
|
|
283
|
-
return {
|
|
284
|
-
x,
|
|
285
|
-
y
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
function transformedLocalBounds(node, local, abs) {
|
|
289
|
-
const points = [
|
|
290
|
-
{
|
|
291
|
-
x: local.x,
|
|
292
|
-
y: local.y
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
x: local.x + local.width,
|
|
296
|
-
y: local.y
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
x: local.x + local.width,
|
|
300
|
-
y: local.y + local.height
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
x: local.x,
|
|
304
|
-
y: local.y + local.height
|
|
305
|
-
}
|
|
306
|
-
].map((point) => transformLocalPoint(node, point));
|
|
307
|
-
return {
|
|
308
|
-
minX: abs.x + Math.min(...points.map((point) => point.x)),
|
|
309
|
-
minY: abs.y + Math.min(...points.map((point) => point.y)),
|
|
310
|
-
maxX: abs.x + Math.max(...points.map((point) => point.x)),
|
|
311
|
-
maxY: abs.y + Math.max(...points.map((point) => point.y))
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
function nodeVisualBounds(node, getAbsolutePosition) {
|
|
315
|
-
const abs = getAbsolutePosition(node.id);
|
|
316
|
-
const base = computeVisualBounds([node], getAbsolutePosition);
|
|
317
|
-
let bounds = {
|
|
318
|
-
minX: base.x,
|
|
319
|
-
minY: base.y,
|
|
320
|
-
maxX: base.x + base.width,
|
|
321
|
-
maxY: base.y + base.height
|
|
322
|
-
};
|
|
323
|
-
const hasNonInsideStroke = node.strokes?.some((stroke) => stroke.visible && stroke.align !== "INSIDE");
|
|
324
|
-
const localGeometry = geometryBlobBounds([...node.fillGeometry ?? [], ...hasNonInsideStroke ? node.strokeGeometry ?? [] : []]);
|
|
325
|
-
if (localGeometry) bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds;
|
|
326
|
-
const linesOverflow = textLinesOverflow(node);
|
|
327
|
-
if (linesOverflow > 0) {
|
|
328
|
-
const lines = {
|
|
329
|
-
x: 0,
|
|
330
|
-
y: 0,
|
|
331
|
-
width: node.width,
|
|
332
|
-
height: node.height + linesOverflow
|
|
333
|
-
};
|
|
334
|
-
bounds = unionVisualBounds(bounds, transformedLocalBounds(node, lines, abs)) ?? bounds;
|
|
335
|
-
}
|
|
336
|
-
bounds.maxY += textDecorationOverflow(node);
|
|
337
|
-
return bounds;
|
|
338
|
-
}
|
|
339
297
|
/** How far a text node's underline or strikethrough reaches below its box. */
|
|
340
298
|
function textDecorationOverflow(node) {
|
|
341
|
-
if (node.type !== "TEXT" ||
|
|
342
|
-
const fontSize = node
|
|
299
|
+
if (node.type !== "TEXT" || node.textDecoration === "NONE") return 0;
|
|
300
|
+
const { fontSize } = node;
|
|
343
301
|
return (node.textUnderlineOffset ?? fontSize * .18) + (node.textDecorationThickness ?? Math.max(1, fontSize / 16)) + fontSize * .35;
|
|
344
302
|
}
|
|
345
|
-
function collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition, clip = null) {
|
|
346
|
-
const node = getNode(nodeId);
|
|
347
|
-
if (!node?.visible) return null;
|
|
348
|
-
const own = nodeVisualBounds(node, getAbsolutePosition);
|
|
349
|
-
let bounds = clip ? intersectVisualBounds(own, clip) : own;
|
|
350
|
-
const isClippableContainer = node.type === "FRAME" || node.type === "COMPONENT" || node.type === "INSTANCE";
|
|
351
|
-
let childClip = clip;
|
|
352
|
-
if (isClippableContainer && node.clipsContent) {
|
|
353
|
-
const abs = getAbsolutePosition(node.id);
|
|
354
|
-
const nodeClip = {
|
|
355
|
-
minX: abs.x,
|
|
356
|
-
minY: abs.y,
|
|
357
|
-
maxX: abs.x + node.width,
|
|
358
|
-
maxY: abs.y + node.height
|
|
359
|
-
};
|
|
360
|
-
childClip = childClip ? intersectVisualBounds(childClip, nodeClip) : nodeClip;
|
|
361
|
-
if (!childClip) return bounds;
|
|
362
|
-
}
|
|
363
|
-
for (const childId of node.childIds ?? []) bounds = unionVisualBounds(bounds, collectDescendantVisualBounds(childId, getNode, getAbsolutePosition, childClip));
|
|
364
|
-
return bounds;
|
|
365
|
-
}
|
|
366
|
-
function computeDescendantVisualBounds(nodeIds, getNode, getAbsolutePosition) {
|
|
367
|
-
let bounds = null;
|
|
368
|
-
for (const nodeId of nodeIds) bounds = unionVisualBounds(bounds, collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition));
|
|
369
|
-
return bounds;
|
|
370
|
-
}
|
|
371
303
|
//#endregion
|
|
372
|
-
export { computeAbsoluteBounds, computeBounds,
|
|
304
|
+
export { GeometryCommand, blurRadiusForSigma, blurSigma, computeAbsoluteBounds, computeBounds, cubicPoint, degToRad, drawnBlurRadius, effectOverflow, geometryBlobBounds, intersectVisualBounds, polygonVertices, radToDeg, readGeometryBlob, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds };
|
|
373
305
|
|
|
374
306
|
//# sourceMappingURL=geometry.js.map
|
package/dist/geometry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.js","names":[],"sources":["../src/geometry.ts"],"sourcesContent":["import { arrowCapOverflow } from './arrow-caps'\nimport type { Rect, Vector } from './primitives'\nimport { textLinesOverflow } from './text/overflow'\nimport type { Effect, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from './types'\n\nexport function degToRad(degrees: number): number {\n return (degrees * Math.PI) / 180\n}\n\nexport function radToDeg(radians: number): number {\n return (radians * 180) / Math.PI\n}\n\nexport function rotatePoint(px: number, py: number, cx: number, cy: number, rad: number): Vector {\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return {\n x: cx + (px - cx) * cos - (py - cy) * sin,\n y: cy + (px - cx) * sin + (py - cy) * cos\n }\n}\n\nexport function rotatedCorners(\n cx: number,\n cy: number,\n hw: number,\n hh: number,\n rotationDeg: number\n): [Vector, Vector, Vector, Vector] {\n const rad = degToRad(rotationDeg)\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return [\n { x: cx + -hw * cos - -hh * sin, y: cy + -hw * sin + -hh * cos },\n { x: cx + hw * cos - -hh * sin, y: cy + hw * sin + -hh * cos },\n { x: cx + hw * cos - hh * sin, y: cy + hw * sin + hh * cos },\n { x: cx + -hw * cos - hh * sin, y: cy + -hw * sin + hh * cos }\n ]\n}\n\nexport function rotatedBBox(\n x: number,\n y: number,\n w: number,\n h: number,\n rotationDeg: number\n): { left: number; right: number; top: number; bottom: number; centerX: number; centerY: number } {\n if (rotationDeg === 0) {\n return {\n left: x,\n right: x + w,\n top: y,\n bottom: y + h,\n centerX: x + w / 2,\n centerY: y + h / 2\n }\n }\n const corners = rotatedCorners(x + w / 2, y + h / 2, w / 2, h / 2, rotationDeg)\n let left = Infinity,\n right = -Infinity,\n top = Infinity,\n bottom = -Infinity\n for (const c of corners) {\n left = Math.min(left, c.x)\n right = Math.max(right, c.x)\n top = Math.min(top, c.y)\n bottom = Math.max(bottom, c.y)\n }\n return { left, right, top, bottom, centerX: (left + right) / 2, centerY: (top + bottom) / 2 }\n}\n\nexport interface VisualBounds {\n minX: number\n minY: number\n maxX: number\n maxY: number\n}\n\ntype BoundsAccumulator = VisualBounds\n\nfunction createBoundsAccumulator(): BoundsAccumulator {\n return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity }\n}\n\nfunction includePoint(bounds: BoundsAccumulator, x: number, y: number): void {\n bounds.minX = Math.min(bounds.minX, x)\n bounds.minY = Math.min(bounds.minY, y)\n bounds.maxX = Math.max(bounds.maxX, x)\n bounds.maxY = Math.max(bounds.maxY, y)\n}\n\nfunction includeRect(bounds: BoundsAccumulator, rect: Rect): void {\n includePoint(bounds, rect.x, rect.y)\n includePoint(bounds, rect.x + rect.width, rect.y + rect.height)\n}\n\nfunction boundsToRect(bounds: BoundsAccumulator): Rect {\n return bounds.minX === Infinity\n ? { x: 0, y: 0, width: 0, height: 0 }\n : {\n x: bounds.minX,\n y: bounds.minY,\n width: bounds.maxX - bounds.minX,\n height: bounds.maxY - bounds.minY\n }\n}\n\nexport function computeBounds(items: Iterable<Rect>): Rect {\n const bounds = createBoundsAccumulator()\n for (const item of items) includeRect(bounds, item)\n return boundsToRect(bounds)\n}\n\nexport function polygonVertices(node: {\n width: number\n height: number\n pointCount: number\n type: string\n starInnerRadius: number\n}): Vector[] {\n const cx = node.width / 2\n const cy = node.height / 2\n const rx = node.width / 2\n const ry = node.height / 2\n const pointCount = Math.max(3, node.pointCount)\n const isStar = node.type === 'STAR'\n const innerRatio = isStar ? node.starInnerRadius : 1\n const totalPoints = isStar ? pointCount * 2 : pointCount\n const angleOffset = -Math.PI / 2\n\n return Array.from({ length: totalPoints }, (_, index) => {\n const angle = angleOffset + (2 * Math.PI * index) / totalPoints\n const isInner = isStar && index % 2 === 1\n const radius = isInner ? innerRatio : 1\n return {\n x: cx + rx * radius * Math.cos(angle),\n y: cy + ry * radius * Math.sin(angle)\n }\n })\n}\n\n/**\n * What shapes how far a layer's stroke reaches past its box: its type, since a line is stroked to\n * one side, and its join and miter limit, for the tips mitered path corners reach.\n */\nexport interface StrokeShape {\n type?: string\n strokeJoin?: StrokeJoin\n strokeMiterLimit?: number\n}\n\nexport function strokeOverflow(\n strokes?: Stroke[],\n fallbackCap?: StrokeCap,\n network?: VectorNetwork | null,\n shape?: StrokeShape\n): number {\n const line = shape?.type === 'LINE'\n // Open segments enclose nothing to take a side of, so their strokes draw centred; a network\n // with closed regions still strokes those on their side.\n const enclosed = new Set(network?.regions.flatMap((region) => region.loops.flat()))\n const open = network?.segments.some((_, index) => !enclosed.has(index)) ?? false\n const sided = !network || network.regions.length > 0\n let overflow = 0\n for (const stroke of strokes ?? []) {\n if (!stroke.visible) continue\n const align = sided ? stroke.align : 'CENTER'\n let extra = open ? stroke.weight / 2 : 0\n if (line || align === 'OUTSIDE') extra = stroke.weight\n else if (align === 'CENTER') extra = stroke.weight / 2\n const miter = network\n ? miterRatio(network, stroke.join ?? shape?.strokeJoin, shape?.strokeMiterLimit)\n : 1\n overflow = Math.max(overflow, extra * miter)\n }\n // A line's heads sit on its stroke's middle, half a weight off the line.\n const heads = arrowCapOverflow(strokes, fallbackCap, network)\n return Math.max(overflow, heads > 0 && line ? heads + overflow / 2 : heads)\n}\n\n/** The direction a segment leaves `vertex` in, along its handle when it has one. */\nfunction leaving(network: VectorNetwork, index: number, vertex: number): Vector {\n const segment = network.segments[index]\n const atStart = segment.start === vertex\n const handle = atStart ? segment.tangentStart : segment.tangentEnd\n if (handle.x !== 0 || handle.y !== 0) return handle\n const from = network.vertices[vertex]\n const to = network.vertices[atStart ? segment.end : segment.start]\n return { x: to.x - from.x, y: to.y - from.y }\n}\n\n/**\n * How far past half the stroke the sharpest mitered corner reaches, as a multiple: a corner of\n * angle θ mitres out to 1/sin(θ/2), unless that passes the miter limit and it bevels instead.\n * Corners are the vertices exactly two segments meet at, as the stroke joins them.\n */\nfunction miterRatio(network: VectorNetwork, join: StrokeJoin | undefined, limit = 4): number {\n const meeting = new Map<number, number[]>()\n for (const [index, segment] of network.segments.entries()) {\n for (const vertex of new Set([segment.start, segment.end])) {\n meeting.set(vertex, [...(meeting.get(vertex) ?? []), index])\n }\n }\n let ratio = 1\n for (const [vertex, indices] of meeting) {\n if (indices.length !== 2) continue\n if ((network.vertices[vertex].strokeJoin ?? join ?? 'MITER') !== 'MITER') continue\n const a = leaving(network, indices[0], vertex)\n const b = leaving(network, indices[1], vertex)\n const lengths = Math.hypot(a.x, a.y) * Math.hypot(b.x, b.y)\n if (lengths === 0) continue\n const angle = Math.acos(Math.max(-1, Math.min(1, (a.x * b.x + a.y * b.y) / lengths)))\n const miter = 1 / Math.sin(angle / 2)\n if (miter <= limit) ratio = Math.max(ratio, miter)\n }\n return ratio\n}\n\nexport function effectOverflow(effects?: Effect[]) {\n let left = 0\n let right = 0\n let top = 0\n let bottom = 0\n\n for (const effect of effects ?? []) {\n if (!effect.visible) continue\n if (\n effect.type !== 'DROP_SHADOW' &&\n effect.type !== 'LAYER_BLUR' &&\n effect.type !== 'FOREGROUND_BLUR'\n ) {\n continue\n }\n const blurSpread = effect.radius + effect.spread\n left = Math.max(left, blurSpread + Math.max(0, -effect.offset.x))\n right = Math.max(right, blurSpread + Math.max(0, effect.offset.x))\n top = Math.max(top, blurSpread + Math.max(0, -effect.offset.y))\n bottom = Math.max(bottom, blurSpread + Math.max(0, effect.offset.y))\n }\n\n return { left, right, top, bottom }\n}\n\nexport function computeAbsoluteBounds(\n nodes: Iterable<{ id: string; width: number; height: number }>,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n for (const n of nodes) {\n const abs = getAbsolutePosition(n.id)\n includeRect(bounds, { x: abs.x, y: abs.y, width: n.width, height: n.height })\n }\n return boundsToRect(bounds)\n}\n\nexport function computeVisualBounds(\n nodes: Iterable<\n {\n id: string\n width: number\n height: number\n rotation?: number\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n } & StrokeShape\n >,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n\n for (const n of nodes) {\n const abs = getAbsolutePosition(n.id)\n const bbox = rotatedBBox(abs.x, abs.y, n.width, n.height, n.rotation ?? 0)\n const stroke = strokeOverflow(n.strokes, n.strokeCap, n.vectorNetwork, n)\n const effects = effectOverflow(n.effects)\n includePoint(bounds, bbox.left - stroke - effects.left, bbox.top - stroke - effects.top)\n includePoint(bounds, bbox.right + stroke + effects.right, bbox.bottom + stroke + effects.bottom)\n }\n\n return boundsToRect(bounds)\n}\n\nexport interface VisualBoundsNode {\n id: string\n width: number\n height: number\n rotation?: number\n flipX?: boolean\n flipY?: boolean\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n fillGeometry?: Array<{ commandsBlob: Uint8Array }>\n strokeGeometry?: Array<{ commandsBlob: Uint8Array }>\n childIds?: string[]\n visible?: boolean\n type?: string\n clipsContent?: boolean\n fontSize?: number\n textDecoration?: string\n textUnderlineOffset?: number | null\n textDecorationThickness?: number | null\n derivedTextHeight?: number | null\n}\n\nexport function unionVisualBounds(\n a: VisualBounds | null,\n b: VisualBounds | null\n): VisualBounds | null {\n if (!a) return b\n if (!b) return a\n return {\n minX: Math.min(a.minX, b.minX),\n minY: Math.min(a.minY, b.minY),\n maxX: Math.max(a.maxX, b.maxX),\n maxY: Math.max(a.maxY, b.maxY)\n }\n}\n\nexport function intersectVisualBounds(a: VisualBounds, b: VisualBounds): VisualBounds | null {\n const minX = Math.max(a.minX, b.minX)\n const minY = Math.max(a.minY, b.minY)\n const maxX = Math.min(a.maxX, b.maxX)\n const maxY = Math.min(a.maxY, b.maxY)\n return minX < maxX && minY < maxY ? { minX, minY, maxX, maxY } : null\n}\n\n/**\n * Coordinate pairs per path blob command: 0=close, 1=move, 2=line,\n * 3=quad (glyph-derived blobs are quad-heavy), 4=cubic. Unknown → null so\n * walkers stop instead of desyncing into coordinate bytes.\n */\nexport function geometryCommandCoordCount(command: number): number | null {\n if (command === 0) return 0\n if (command === 1 || command === 2) return 1\n if (command === 3) return 2\n if (command === 4) return 3\n return null\n}\n\nexport function geometryBlobBounds(paths: Array<{ commandsBlob: Uint8Array }>): Rect | null {\n const bounds = createBoundsAccumulator()\n\n for (const path of paths) {\n const blob = path.commandsBlob\n const dv = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n let offset = 0\n while (offset < blob.length) {\n const command = blob[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords == null) break\n for (let i = 0; i < coords; i++) {\n if (offset + 8 > blob.length) break\n const x = dv.getFloat32(offset, true)\n const y = dv.getFloat32(offset + 4, true)\n includePoint(bounds, x, y)\n offset += 8\n }\n }\n }\n\n return bounds.minX === Infinity ? null : boundsToRect(bounds)\n}\n\nfunction transformLocalPoint(node: VisualBoundsNode, point: Vector): Vector {\n let x = node.flipX ? node.width - point.x : point.x\n let y = node.flipY ? node.height - point.y : point.y\n const rotation = node.rotation ?? 0\n if (rotation !== 0) {\n const rotated = rotatePoint(x, y, node.width / 2, node.height / 2, degToRad(rotation))\n x = rotated.x\n y = rotated.y\n }\n return { x, y }\n}\n\nfunction transformedLocalBounds(node: VisualBoundsNode, local: Rect, abs: Vector): VisualBounds {\n const points = [\n { x: local.x, y: local.y },\n { x: local.x + local.width, y: local.y },\n { x: local.x + local.width, y: local.y + local.height },\n { x: local.x, y: local.y + local.height }\n ].map((point) => transformLocalPoint(node, point))\n\n return {\n minX: abs.x + Math.min(...points.map((point) => point.x)),\n minY: abs.y + Math.min(...points.map((point) => point.y)),\n maxX: abs.x + Math.max(...points.map((point) => point.x)),\n maxY: abs.y + Math.max(...points.map((point) => point.y))\n }\n}\n\nexport function nodeVisualBounds(\n node: VisualBoundsNode,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds {\n const abs = getAbsolutePosition(node.id)\n const base = computeVisualBounds([node], getAbsolutePosition)\n let bounds: VisualBounds = {\n minX: base.x,\n minY: base.y,\n maxX: base.x + base.width,\n maxY: base.y + base.height\n }\n\n const hasNonInsideStroke = node.strokes?.some(\n (stroke) => stroke.visible && stroke.align !== 'INSIDE'\n )\n const localGeometry = geometryBlobBounds([\n ...(node.fillGeometry ?? []),\n ...(hasNonInsideStroke ? (node.strokeGeometry ?? []) : [])\n ])\n if (localGeometry) {\n bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds\n }\n\n const linesOverflow = textLinesOverflow(node)\n if (linesOverflow > 0) {\n const lines = { x: 0, y: 0, width: node.width, height: node.height + linesOverflow }\n bounds = unionVisualBounds(bounds, transformedLocalBounds(node, lines, abs)) ?? bounds\n }\n\n bounds.maxY += textDecorationOverflow(node)\n\n return bounds\n}\n\n/** How far a text node's underline or strikethrough reaches below its box. */\nexport function textDecorationOverflow(node: VisualBoundsNode): number {\n if (node.type !== 'TEXT' || !node.textDecoration || node.textDecoration === 'NONE') return 0\n const fontSize = node.fontSize ?? 14\n const underlineOffset = node.textUnderlineOffset ?? fontSize * 0.18\n const thickness = node.textDecorationThickness ?? Math.max(1, fontSize / 16)\n return underlineOffset + thickness + fontSize * 0.35\n}\n\nfunction collectDescendantVisualBounds(\n nodeId: string,\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector,\n clip: VisualBounds | null = null\n): VisualBounds | null {\n const node = getNode(nodeId)\n if (!node?.visible) return null\n\n const own = nodeVisualBounds(node, getAbsolutePosition)\n let bounds = clip ? intersectVisualBounds(own, clip) : own\n\n const isClippableContainer =\n node.type === 'FRAME' || node.type === 'COMPONENT' || node.type === 'INSTANCE'\n let childClip = clip\n if (isClippableContainer && node.clipsContent) {\n const abs = getAbsolutePosition(node.id)\n const nodeClip = {\n minX: abs.x,\n minY: abs.y,\n maxX: abs.x + node.width,\n maxY: abs.y + node.height\n }\n childClip = childClip ? intersectVisualBounds(childClip, nodeClip) : nodeClip\n if (!childClip) return bounds\n }\n\n for (const childId of node.childIds ?? []) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(childId, getNode, getAbsolutePosition, childClip)\n )\n }\n\n return bounds\n}\n\nexport function computeDescendantVisualBounds(\n nodeIds: string[],\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds | null {\n let bounds: VisualBounds | null = null\n for (const nodeId of nodeIds) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition)\n )\n }\n return bounds\n}\n"],"mappings":";;;AAKA,SAAgB,SAAS,SAAyB;CAChD,OAAQ,UAAU,KAAK,KAAM;AAC/B;AAEA,SAAgB,SAAS,SAAyB;CAChD,OAAQ,UAAU,MAAO,KAAK;AAChC;AAEA,SAAgB,YAAY,IAAY,IAAY,IAAY,IAAY,KAAqB;CAC/F,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,OAAO;EACL,GAAG,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM;EACtC,GAAG,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM;CACxC;AACF;AAEA,SAAgB,eACd,IACA,IACA,IACA,IACA,aACkC;CAClC,MAAM,MAAM,SAAS,WAAW;CAChC,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,OAAO;EACL;GAAE,GAAG,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK;GAAK,GAAG,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK;EAAI;EAC/D;GAAE,GAAG,KAAK,KAAK,MAAM,CAAC,KAAK;GAAK,GAAG,KAAK,KAAK,MAAM,CAAC,KAAK;EAAI;EAC7D;GAAE,GAAG,KAAK,KAAK,MAAM,KAAK;GAAK,GAAG,KAA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,sBAAsB,WAAW,QAAQ,IAAI;EACrE,IAAI,CAAC,WAAW,OAAO;CACzB;CAEA,KAAK,MAAM,WAAW,KAAK,YAAY,CAAC,GACtC,SAAS,kBACP,QACA,8BAA8B,SAAS,SAAS,qBAAqB,SAAS,CAChF;CAGF,OAAO;AACT;AAEA,SAAgB,8BACd,SACA,SACA,qBACqB;CACrB,IAAI,SAA8B;CAClC,KAAK,MAAM,UAAU,SACnB,SAAS,kBACP,QACA,8BAA8B,QAAQ,SAAS,mBAAmB,CACpE;CAEF,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"geometry.js","names":[],"sources":["../src/geometry.ts"],"sourcesContent":["import { arrowCapOverflow } from './arrow-caps'\nimport type { Rect, Vector } from './primitives'\nimport type { Effect, SceneNode, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from './types'\n\nexport { cubicPoint } from './cubic'\n\nexport function degToRad(degrees: number): number {\n return (degrees * Math.PI) / 180\n}\n\nexport function radToDeg(radians: number): number {\n return (radians * 180) / Math.PI\n}\n\nexport function rotatePoint(px: number, py: number, cx: number, cy: number, rad: number): Vector {\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return {\n x: cx + (px - cx) * cos - (py - cy) * sin,\n y: cy + (px - cx) * sin + (py - cy) * cos\n }\n}\n\nexport function rotatedCorners(\n cx: number,\n cy: number,\n hw: number,\n hh: number,\n rotationDeg: number\n): [Vector, Vector, Vector, Vector] {\n const rad = degToRad(rotationDeg)\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return [\n { x: cx + -hw * cos - -hh * sin, y: cy + -hw * sin + -hh * cos },\n { x: cx + hw * cos - -hh * sin, y: cy + hw * sin + -hh * cos },\n { x: cx + hw * cos - hh * sin, y: cy + hw * sin + hh * cos },\n { x: cx + -hw * cos - hh * sin, y: cy + -hw * sin + hh * cos }\n ]\n}\n\nexport function rotatedBBox(\n x: number,\n y: number,\n w: number,\n h: number,\n rotationDeg: number\n): { left: number; right: number; top: number; bottom: number; centerX: number; centerY: number } {\n if (rotationDeg === 0) {\n return {\n left: x,\n right: x + w,\n top: y,\n bottom: y + h,\n centerX: x + w / 2,\n centerY: y + h / 2\n }\n }\n const corners = rotatedCorners(x + w / 2, y + h / 2, w / 2, h / 2, rotationDeg)\n let left = Infinity,\n right = -Infinity,\n top = Infinity,\n bottom = -Infinity\n for (const c of corners) {\n left = Math.min(left, c.x)\n right = Math.max(right, c.x)\n top = Math.min(top, c.y)\n bottom = Math.max(bottom, c.y)\n }\n return { left, right, top, bottom, centerX: (left + right) / 2, centerY: (top + bottom) / 2 }\n}\n\nexport interface VisualBounds {\n minX: number\n minY: number\n maxX: number\n maxY: number\n}\n\ntype BoundsAccumulator = VisualBounds\n\nfunction createBoundsAccumulator(): BoundsAccumulator {\n return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity }\n}\n\nfunction includePoint(bounds: BoundsAccumulator, x: number, y: number): void {\n bounds.minX = Math.min(bounds.minX, x)\n bounds.minY = Math.min(bounds.minY, y)\n bounds.maxX = Math.max(bounds.maxX, x)\n bounds.maxY = Math.max(bounds.maxY, y)\n}\n\nfunction includeRect(bounds: BoundsAccumulator, rect: Rect): void {\n includePoint(bounds, rect.x, rect.y)\n includePoint(bounds, rect.x + rect.width, rect.y + rect.height)\n}\n\nfunction boundsToRect(bounds: BoundsAccumulator): Rect {\n return bounds.minX === Infinity\n ? { x: 0, y: 0, width: 0, height: 0 }\n : {\n x: bounds.minX,\n y: bounds.minY,\n width: bounds.maxX - bounds.minX,\n height: bounds.maxY - bounds.minY\n }\n}\n\nexport function computeBounds(items: Iterable<Rect>): Rect {\n const bounds = createBoundsAccumulator()\n for (const item of items) includeRect(bounds, item)\n return boundsToRect(bounds)\n}\n\nexport function polygonVertices(node: {\n width: number\n height: number\n pointCount: number\n type: string\n starInnerRadius: number\n}): Vector[] {\n const cx = node.width / 2\n const cy = node.height / 2\n const rx = node.width / 2\n const ry = node.height / 2\n const pointCount = Math.max(3, node.pointCount)\n const isStar = node.type === 'STAR'\n const innerRatio = isStar ? node.starInnerRadius : 1\n const totalPoints = isStar ? pointCount * 2 : pointCount\n const angleOffset = -Math.PI / 2\n\n return Array.from({ length: totalPoints }, (_, index) => {\n const angle = angleOffset + (2 * Math.PI * index) / totalPoints\n const isInner = isStar && index % 2 === 1\n const radius = isInner ? innerRatio : 1\n return {\n x: cx + rx * radius * Math.cos(angle),\n y: cy + ry * radius * Math.sin(angle)\n }\n })\n}\n\n/**\n * What shapes how far a layer's stroke reaches past its box: its type, since a line is stroked to\n * one side, and its join and miter limit, for the tips mitered path corners reach.\n */\nexport interface StrokeShape {\n type?: string\n strokeJoin?: StrokeJoin\n strokeMiterLimit?: number\n}\n\nexport function strokeOverflow(\n strokes?: Stroke[],\n fallbackCap?: StrokeCap,\n network?: VectorNetwork | null,\n shape?: StrokeShape\n): number {\n const line = shape?.type === 'LINE'\n // Open segments enclose nothing to take a side of, so their strokes draw centred; a network\n // with closed regions still strokes those on their side.\n const enclosed = new Set(network?.regions.flatMap((region) => region.loops.flat()))\n const open = network?.segments.some((_, index) => !enclosed.has(index)) ?? false\n const sided = !network || network.regions.length > 0\n let overflow = 0\n for (const stroke of strokes ?? []) {\n if (!stroke.visible) continue\n const align = sided ? stroke.align : 'CENTER'\n let extra = open ? stroke.weight / 2 : 0\n if (line || align === 'OUTSIDE') extra = stroke.weight\n else if (align === 'CENTER') extra = stroke.weight / 2\n const miter = network\n ? miterRatio(network, stroke.join ?? shape?.strokeJoin, shape?.strokeMiterLimit)\n : 1\n overflow = Math.max(overflow, extra * miter)\n }\n // A line's heads sit on its stroke's middle, half a weight off the line.\n const heads = arrowCapOverflow(strokes, fallbackCap, network)\n return Math.max(overflow, heads > 0 && line ? heads + overflow / 2 : heads)\n}\n\n/** The direction a segment leaves `vertex` in, along its handle when it has one. */\nfunction leaving(network: VectorNetwork, index: number, vertex: number): Vector {\n const segment = network.segments[index]\n const atStart = segment.start === vertex\n const handle = atStart ? segment.tangentStart : segment.tangentEnd\n if (handle.x !== 0 || handle.y !== 0) return handle\n const from = network.vertices[vertex]\n const to = network.vertices[atStart ? segment.end : segment.start]\n return { x: to.x - from.x, y: to.y - from.y }\n}\n\n/**\n * How far past half the stroke the sharpest mitered corner reaches, as a multiple: a corner of\n * angle θ mitres out to 1/sin(θ/2), unless that passes the miter limit and it bevels instead.\n * Corners are the vertices exactly two segments meet at, as the stroke joins them.\n */\nfunction miterRatio(network: VectorNetwork, join: StrokeJoin | undefined, limit = 4): number {\n const meeting = new Map<number, number[]>()\n for (const [index, segment] of network.segments.entries()) {\n for (const vertex of new Set([segment.start, segment.end])) {\n meeting.set(vertex, [...(meeting.get(vertex) ?? []), index])\n }\n }\n let ratio = 1\n for (const [vertex, indices] of meeting) {\n if (indices.length !== 2) continue\n if ((network.vertices[vertex].strokeJoin ?? join ?? 'MITER') !== 'MITER') continue\n const a = leaving(network, indices[0], vertex)\n const b = leaving(network, indices[1], vertex)\n const lengths = Math.hypot(a.x, a.y) * Math.hypot(b.x, b.y)\n if (lengths === 0) continue\n const angle = Math.acos(Math.max(-1, Math.min(1, (a.x * b.x + a.y * b.y) / lengths)))\n const miter = 1 / Math.sin(angle / 2)\n if (miter <= limit) ratio = Math.max(ratio, miter)\n }\n return ratio\n}\n\n/**\n * The blur radius Figma draws: a negative one, which only a bound variable can give, draws as no\n * blur, though the layer keeps the value.\n */\nexport function drawnBlurRadius(radius: number): number {\n return Math.max(0, radius)\n}\n\nconst BLUR_SIGMA_PER_RADIUS = 0.43\n\n/**\n * The Gaussian sigma that draws a Figma blur radius as Figma does. Measured on Figma 126 exports,\n * layer blur, both shadows, and background blur fall off as a Gaussian of 0.43 × radius; Figma's\n * SVG export writes radius / 2, which is wider (`packages/core/tests/canvas/blur.test.ts`).\n */\nexport function blurSigma(radius: number): number {\n return drawnBlurRadius(radius) * BLUR_SIGMA_PER_RADIUS\n}\n\n/** The Figma blur radius that draws a Gaussian of `sigma`, the inverse of `blurSigma`. */\nexport function blurRadiusForSigma(sigma: number): number {\n return Math.max(0, sigma) / BLUR_SIGMA_PER_RADIUS\n}\n\nexport function effectOverflow(effects?: Effect[]) {\n let left = 0\n let right = 0\n let top = 0\n let bottom = 0\n\n for (const effect of effects ?? []) {\n if (!effect.visible) continue\n if (\n effect.type !== 'DROP_SHADOW' &&\n effect.type !== 'LAYER_BLUR' &&\n effect.type !== 'FOREGROUND_BLUR'\n ) {\n continue\n }\n const blurSpread = drawnBlurRadius(effect.radius) + effect.spread\n left = Math.max(left, blurSpread + Math.max(0, -effect.offset.x))\n right = Math.max(right, blurSpread + Math.max(0, effect.offset.x))\n top = Math.max(top, blurSpread + Math.max(0, -effect.offset.y))\n bottom = Math.max(bottom, blurSpread + Math.max(0, effect.offset.y))\n }\n\n return { left, right, top, bottom }\n}\n\nexport function computeAbsoluteBounds(\n nodes: Iterable<{ id: string; width: number; height: number }>,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n for (const n of nodes) {\n const abs = getAbsolutePosition(n.id)\n includeRect(bounds, { x: abs.x, y: abs.y, width: n.width, height: n.height })\n }\n return boundsToRect(bounds)\n}\n\nexport function unionVisualBounds(\n a: VisualBounds | null,\n b: VisualBounds | null\n): VisualBounds | null {\n if (!a) return b\n if (!b) return a\n return {\n minX: Math.min(a.minX, b.minX),\n minY: Math.min(a.minY, b.minY),\n maxX: Math.max(a.maxX, b.maxX),\n maxY: Math.max(a.maxY, b.maxY)\n }\n}\n\nexport function intersectVisualBounds(a: VisualBounds, b: VisualBounds): VisualBounds | null {\n const minX = Math.max(a.minX, b.minX)\n const minY = Math.max(a.minY, b.minY)\n const maxX = Math.min(a.maxX, b.maxX)\n const maxY = Math.min(a.maxY, b.maxY)\n return minX < maxX && minY < maxY ? { minX, minY, maxX, maxY } : null\n}\n\n/** The path commands of a Figma geometry blob, by their byte code. */\nexport const GeometryCommand = { CLOSE: 0, MOVE: 1, LINE: 2, QUAD: 3, CUBIC: 4 } as const\nexport type GeometryCommand = (typeof GeometryCommand)[keyof typeof GeometryCommand]\n\n/**\n * Coordinate pairs per command: glyph-derived blobs are quad-heavy, so every code needs its\n * count. Unknown codes are null, so readers stop instead of desyncing into coordinate bytes.\n */\nfunction commandCoordCount(command: number): number | null {\n if (command === GeometryCommand.CLOSE) return 0\n if (command === GeometryCommand.MOVE || command === GeometryCommand.LINE) return 1\n if (command === GeometryCommand.QUAD) return 2\n if (command === GeometryCommand.CUBIC) return 3\n return null\n}\n\n/**\n * Walks a Figma geometry blob: `visit` gets each command, its coordinates as x, y pairs in one\n * array reused between calls, and the byte offset of the first coordinate. It stops at an\n * unknown command or one cut short.\n */\nexport function readGeometryBlob(\n blob: Uint8Array,\n visit: (command: GeometryCommand, coords: readonly number[], offset: number) => void\n): void {\n const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n const coords: number[] = []\n let offset = 0\n while (offset < blob.length) {\n const command = blob[offset]\n const count = commandCoordCount(command)\n if (count === null || offset + 1 + count * 8 > blob.length) return\n offset += 1\n coords.length = 0\n for (let i = 0; i < count; i++) {\n coords.push(view.getFloat32(offset + i * 8, true), view.getFloat32(offset + i * 8 + 4, true))\n }\n visit(command as GeometryCommand, coords, offset)\n offset += count * 8\n }\n}\n\nexport function geometryBlobBounds(paths: Array<{ commandsBlob: Uint8Array }>): Rect | null {\n const bounds = createBoundsAccumulator()\n for (const path of paths) {\n readGeometryBlob(path.commandsBlob, (_, coords) => {\n for (let i = 0; i < coords.length; i += 2) includePoint(bounds, coords[i], coords[i + 1])\n })\n }\n\n return bounds.minX === Infinity ? null : boundsToRect(bounds)\n}\n\n/** How far a text node's underline or strikethrough reaches below its box. */\nexport function textDecorationOverflow(\n node: Pick<\n SceneNode,\n 'type' | 'fontSize' | 'textDecoration' | 'textUnderlineOffset' | 'textDecorationThickness'\n >\n): number {\n if (node.type !== 'TEXT' || node.textDecoration === 'NONE') {\n return 0\n }\n const { fontSize } = node\n const underlineOffset = node.textUnderlineOffset ?? fontSize * 0.18\n const thickness = node.text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C,OAAO;AACT;;;;;;AAOA,SAAgB,iBACd,MACA,OACM;CACN,MAAM,OAAO,IAAI,SAAS,KAAK,QAAQ,KAAK,YAAY,KAAK,UAAU;CACvE,MAAM,SAAmB,CAAC;CAC1B,IAAI,SAAS;CACb,OAAO,SAAS,KAAK,QAAQ;EAC3B,MAAM,UAAU,KAAK;EACrB,MAAM,QAAQ,kBAAkB,OAAO;EACvC,IAAI,UAAU,QAAQ,SAAS,IAAI,QAAQ,IAAI,KAAK,QAAQ;EAC5D,UAAU;EACV,OAAO,SAAS;EAChB,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KACzB,OAAO,KAAK,KAAK,WAAW,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,WAAW,SAAS,IAAI,IAAI,GAAG,IAAI,CAAC;EAE9F,MAAM,SAA4B,QAAQ,MAAM;EAChD,UAAU,QAAQ;CACpB;AACF;AAEA,SAAgB,mBAAmB,OAAyD;CAC1F,MAAM,SAAS,wBAAwB;CACvC,KAAK,MAAM,QAAQ,OACjB,iBAAiB,KAAK,eAAe,GAAG,WAAW;EACjD,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG,aAAa,QAAQ,OAAO,IAAI,OAAO,IAAI,EAAE;CAC1F,CAAC;CAGH,OAAO,OAAO,SAAS,WAAW,OAAO,aAAa,MAAM;AAC9D;;AAGA,SAAgB,uBACd,MAIQ;CACR,IAAI,KAAK,SAAS,UAAU,KAAK,mBAAmB,QAClD,OAAO;CAET,MAAM,EAAE,aAAa;CAGrB,QAFwB,KAAK,uBAAuB,WAAW,QAC7C,KAAK,2BAA2B,KAAK,IAAI,GAAG,WAAW,EAAE,KACtC,WAAW;AAClD"}
|
package/dist/graph.d.ts
CHANGED
|
@@ -158,6 +158,7 @@ declare class SceneGraph {
|
|
|
158
158
|
isPointInNode(nodeId: string, px: number, py: number): boolean;
|
|
159
159
|
hitTestDropTarget(px: number, py: number, excludeIds: ReadonlySet<string>, scopeId?: string, options?: DropTargetOptions): SceneNode | null;
|
|
160
160
|
cloneTree(sourceId: string, parentId: string, overrides?: Partial<SceneNode>): SceneNode | null;
|
|
161
|
+
private cloneSubtree;
|
|
161
162
|
createInstance(componentId: string, parentId: string, overrides?: Partial<SceneNode>): SceneNode | null;
|
|
162
163
|
populateInstanceChildren(instanceId: string, componentId: string, mode?: NodeCloneMode): void;
|
|
163
164
|
swapInstanceComponent(instanceId: string, componentId: string, options?: SwapInstanceOptions): void;
|
package/dist/graph.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","names":[],"sources":["../src/graph.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"graph.d.ts","names":[],"sources":["../src/graph.ts"],"mappings":";;;;;;;;;cAkDa;mBA+BkB;EA9B7B,OAAK,YAAA;EACL,QAAM,YAAA,WAAA;EACN,WAAS,YAAA;EACT,qBAAmB,YAAA;EACnB,YAAU;EACV;EACA;;EAEA,mBAAmB;EACnB,oBAAoB;EACpB,cAAc;EACd,kBAAgB,YAAA;WACP,SAAO;UACR;mBACS;UAOT;mBACS;UACT;UACA;EACR;EACA,eAAa,YAAA;;EAEb,cAAY;EAEiB,YAAA;EAW7B,QAAQ,eAAe;EAIvB,SAAS,4BAA0B;EAKnC,eAAe,SAAS;EAGxB,QAAQ,aAAa;EAGrB,aAAa,UAAU;;;;;;;EAUvB,mBAAmB,UAAU;;EAM7B,eAAe,MAAM;EAKrB,iBAAiB;EAkBjB,YAAY,UAAU;EAGtB,eAAe;EAGf,cAAc,YAAY;EAG1B,eACE,cACA,MAAM,cACN,sBACA,QAAQ,gBACP;EAWH,iBAAiB,eAAe;EAMhC,WAAW,sBAAsB,cAAc;EAU/C,iBAAiB;EAIjB,gBAAgB;EAIhB,sBAAsB,gBAAgB;EAItC,cAAc,sBAAsB;EAIpC,QAAQ,sBAAsB,gBAAgB,cAAc;EAI5D,WAAW,sBAAsB;EAIjC,WAAW,sBAAsB,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iBACA,aAAa,qBACb,UAAU,uBACT;EAIH,qBAAqB,YAAY,YAAY,kBAAkB;EAI/D,gBAAgB,gBAAgB;EAIhC,cAAc,gBAAgB,YAAY;EAI1C,kBACE,YACA,YACA,YAAY,qBACZ,kBACA,UAAU,oBACT;EAIH,UACE,kBACA,kBACA,YAAW,QAAQ,aAClB;UASK;EAyBR,eACE,qBACA,kBACA,YAAW,QAAQ,aAClB;EAIH,yBACE,oBACA,qBACA,OAAM;EAKR,sBACE,oBACA,qBACA,UAAU;EAKZ,cAAc;EAId,sBAAsB,cAAc;EAIpC,aAAa;EAIb,eAAe;EAIf,iBAAiB,qBAAqB;EAItC,aAAa,sBAAsB;EAInC,YAAY,mBAAmB,iBAAY;IAAQ,MAAM;IAAW"}
|
package/dist/graph.js
CHANGED
|
@@ -13,9 +13,10 @@ import { generateId } from "./ids.js";
|
|
|
13
13
|
import { normalizeVectorNetwork } from "./vector-network.js";
|
|
14
14
|
import { createInstance, detachInstance, getInstances, getMainComponent, populateInstanceChildren, swapInstanceComponent, syncInstance, syncInstances, syncInstancesTogether } from "./instances/index.js";
|
|
15
15
|
import { LayoutWrites } from "./layout/writes.js";
|
|
16
|
-
import {
|
|
16
|
+
import { textCacheInvalidationChanges } from "./text/picture.js";
|
|
17
17
|
import { updateNodePreview } from "./preview.js";
|
|
18
18
|
import { markSourceFieldsEdited } from "./source-metadata.js";
|
|
19
|
+
import { remapCopiedReferences } from "./transfer/copied.js";
|
|
19
20
|
import { getActiveModeId, getNodeVariableModeId, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode } from "./variables/resolution.js";
|
|
20
21
|
import { addCollection, addMode, addVariable, bindVariable, createCollection, createMode, createVariable, getVariablesByType, getVariablesForCollection, removeCollection, removeMode, removeVariable, renameMode, setActiveMode, setDefaultMode, unbindVariable } from "./variables/index.js";
|
|
21
22
|
import { omitBy, pick } from "es-toolkit/object";
|
|
@@ -435,8 +436,11 @@ var SceneGraph = class {
|
|
|
435
436
|
if (node.componentId) this.unindexInstance(node.componentId, id);
|
|
436
437
|
if (changes.componentId) this.indexInstance(changes.componentId, id);
|
|
437
438
|
}
|
|
438
|
-
if (node.type === "TEXT") invalidateTextCaches(node, changes);
|
|
439
439
|
this.markEdited(node, Object.keys(changes));
|
|
440
|
+
if (node.type === "TEXT") changes = {
|
|
441
|
+
...omitBy(textCacheInvalidationChanges(node, changes), (value, key) => Object.is(node[key], value)),
|
|
442
|
+
...changes
|
|
443
|
+
};
|
|
440
444
|
if (changes.vectorNetwork) changes = {
|
|
441
445
|
...changes,
|
|
442
446
|
vectorNetwork: normalizeVectorNetwork(changes.vectorNetwork)
|
|
@@ -445,6 +449,7 @@ var SceneGraph = class {
|
|
|
445
449
|
Object.assign(node, changes);
|
|
446
450
|
if (changes.fills) removeStaleBindings(node, "fills", changes);
|
|
447
451
|
if (changes.strokes) removeStaleBindings(node, "strokes", changes);
|
|
452
|
+
if (changes.effects) removeStaleBindings(node, "effects", changes);
|
|
448
453
|
for (const key of absent) Reflect.deleteProperty(node, key);
|
|
449
454
|
this.publishNodeUpdate(id, changes);
|
|
450
455
|
}
|
|
@@ -546,6 +551,12 @@ var SceneGraph = class {
|
|
|
546
551
|
return hitTestDropTarget(this, px, py, excludeIds, scopeId, options);
|
|
547
552
|
}
|
|
548
553
|
cloneTree(sourceId, parentId, overrides = {}) {
|
|
554
|
+
const ids = /* @__PURE__ */ new Map();
|
|
555
|
+
const clone = this.cloneSubtree(sourceId, parentId, overrides, ids);
|
|
556
|
+
remapCopiedReferences(this, ids);
|
|
557
|
+
return clone;
|
|
558
|
+
}
|
|
559
|
+
cloneSubtree(sourceId, parentId, overrides, ids) {
|
|
549
560
|
const src = this.nodes.get(sourceId);
|
|
550
561
|
if (!src) return null;
|
|
551
562
|
const props = cloneNodeProps(src, null);
|
|
@@ -560,7 +571,8 @@ var SceneGraph = class {
|
|
|
560
571
|
...overrides
|
|
561
572
|
});
|
|
562
573
|
if (src.status) markSourceFieldsEdited(clone, ["status"]);
|
|
563
|
-
|
|
574
|
+
ids.set(src.id, clone.id);
|
|
575
|
+
for (const childId of src.childIds) this.cloneSubtree(childId, clone.id, {}, ids);
|
|
564
576
|
return clone;
|
|
565
577
|
}
|
|
566
578
|
createInstance(componentId, parentId, overrides = {}) {
|