@open-pencil/scene-graph 0.14.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow-caps.d.ts +44 -0
- package/dist/arrow-caps.d.ts.map +1 -0
- package/dist/arrow-caps.js +131 -0
- package/dist/arrow-caps.js.map +1 -0
- package/dist/chunks/checkpoint.js +78 -0
- package/dist/chunks/checkpoint.js.map +1 -0
- package/dist/chunks/components/properties.js +1571 -0
- package/dist/chunks/components/properties.js.map +1 -0
- package/dist/chunks/coordinate.js +87 -33
- package/dist/chunks/coordinate.js.map +1 -1
- package/dist/chunks/font-style.js +2 -1
- package/dist/chunks/font-style.js.map +1 -1
- package/dist/chunks/index.js +1283 -0
- package/dist/chunks/index.js.map +1 -0
- package/dist/constants.js +1 -18
- package/dist/constants2.d.ts +0 -1
- package/dist/constants2.d.ts.map +1 -1
- package/dist/coordinate.d.ts +107 -11
- package/dist/coordinate.d.ts.map +1 -1
- package/dist/coordinate.js +2 -2
- package/dist/coordinate2.d.ts +2 -2
- package/dist/copy.d.ts +2 -2
- package/dist/copy.js +2 -2
- package/dist/geometry.d.ts +2 -2
- package/dist/geometry.js +2 -431
- package/dist/guides.d.ts +2 -0
- package/dist/guides.js +0 -0
- package/dist/guides2.d.ts +11 -0
- package/dist/guides2.d.ts.map +1 -0
- package/dist/hit-test.d.ts +1 -2
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +26 -14
- package/dist/hit-test.js.map +1 -1
- package/dist/images.js +0 -1
- package/dist/images.js.map +1 -1
- package/dist/images2.d.ts.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -6
- package/dist/instances.d.ts +2 -2
- package/dist/instances.js +2 -2
- package/dist/layout-guides.d.ts +2 -0
- package/dist/layout-guides.js +2 -0
- package/dist/layout-guides2.d.ts +16 -0
- package/dist/layout-guides2.d.ts.map +1 -0
- package/dist/matrix2.d.ts +0 -1
- package/dist/matrix2.d.ts.map +1 -1
- package/dist/node-defaults.d.ts +1 -2
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +1 -1
- package/dist/parse-path.d.ts +1 -2
- package/dist/parse-path.d.ts.map +1 -1
- package/dist/parse-path.js.map +1 -1
- package/dist/preview.d.ts +2 -12
- package/dist/preview.js +1 -1
- package/dist/preview2.d.ts +12 -0
- package/dist/preview2.d.ts.map +1 -0
- package/dist/primitives2.d.ts.map +1 -1
- package/dist/resize.d.ts +18 -4
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +70 -22
- package/dist/resize.js.map +1 -1
- package/dist/snap.js +1 -1
- package/dist/source-metadata.d.ts +1 -2
- package/dist/source-metadata.d.ts.map +1 -1
- package/dist/source-metadata.js +1 -1
- package/dist/text-picture.d.ts +13 -2
- package/dist/text-picture.d.ts.map +1 -1
- package/dist/text-picture.js +2 -2
- package/dist/types.d.ts +499 -2
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -1296
- package/dist/types2.d.ts +2 -430
- package/dist/undo.js +1 -1
- package/dist/undo2.d.ts +5 -0
- package/dist/undo2.d.ts.map +1 -1
- package/dist/variables.d.ts +1 -2
- package/dist/variables.d.ts.map +1 -1
- package/dist/variables.js +1 -1
- package/dist/variant-name.d.ts.map +1 -1
- package/dist/variant-properties.d.ts +10 -0
- package/dist/variant-properties.d.ts.map +1 -0
- package/dist/variant-properties.js +39 -0
- package/dist/variant-properties.js.map +1 -0
- package/dist/vector-network.js +1 -1
- package/dist/vector-network2.d.ts +1 -2
- package/dist/vector-network2.d.ts.map +1 -1
- package/package.json +40 -15
- package/src/arrow-caps.ts +146 -0
- package/src/bindings.ts +20 -0
- package/src/checkpoint.ts +123 -0
- package/src/components/properties.ts +238 -0
- package/src/constants.ts +6 -0
- package/src/coordinate.ts +226 -0
- package/src/copy.ts +294 -0
- package/src/events.ts +21 -0
- package/src/export-scale.ts +16 -0
- package/src/font-style.ts +77 -0
- package/src/geometry.ts +530 -0
- package/src/guides.ts +8 -0
- package/src/hit-test.ts +205 -0
- package/src/images.ts +34 -0
- package/src/index.ts +686 -0
- package/src/instance-overrides.test.ts +67 -0
- package/src/instance-overrides.ts +152 -0
- package/src/instances.ts +480 -0
- package/src/layout-guides.ts +103 -0
- package/src/matrix.ts +116 -0
- package/src/mutation-impact.ts +70 -0
- package/src/node-defaults.ts +186 -0
- package/src/parse-path.ts +191 -0
- package/src/preview.ts +80 -0
- package/src/primitives.ts +42 -0
- package/src/resize.ts +302 -0
- package/src/shared-styles.ts +73 -0
- package/src/snap.ts +129 -0
- package/src/source-metadata.ts +8 -0
- package/src/text-picture.ts +65 -0
- package/src/types.ts +635 -0
- package/src/undo.ts +171 -0
- package/src/variables.ts +399 -0
- package/src/variant-name.ts +15 -0
- package/src/variant-properties.ts +48 -0
- package/src/vector-network.ts +293 -0
- package/dist/chunks/copy.js +0 -576
- package/dist/chunks/copy.js.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/geometry.js.map +0 -1
- package/dist/preview.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/types2.d.ts.map +0 -1
package/dist/geometry.js
CHANGED
|
@@ -1,431 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return degrees * Math.PI / 180;
|
|
4
|
-
}
|
|
5
|
-
function radToDeg(radians) {
|
|
6
|
-
return radians * 180 / Math.PI;
|
|
7
|
-
}
|
|
8
|
-
function rotatePoint(px, py, cx, cy, rad) {
|
|
9
|
-
const cos = Math.cos(rad);
|
|
10
|
-
const sin = Math.sin(rad);
|
|
11
|
-
return {
|
|
12
|
-
x: cx + (px - cx) * cos - (py - cy) * sin,
|
|
13
|
-
y: cy + (px - cx) * sin + (py - cy) * cos
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
function rotatedCorners(cx, cy, hw, hh, rotationDeg) {
|
|
17
|
-
const rad = degToRad(rotationDeg);
|
|
18
|
-
const cos = Math.cos(rad);
|
|
19
|
-
const sin = Math.sin(rad);
|
|
20
|
-
return [
|
|
21
|
-
{
|
|
22
|
-
x: cx + -hw * cos - -hh * sin,
|
|
23
|
-
y: cy + -hw * sin + -hh * cos
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
x: cx + hw * cos - -hh * sin,
|
|
27
|
-
y: cy + hw * sin + -hh * cos
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
x: cx + hw * cos - hh * sin,
|
|
31
|
-
y: cy + hw * sin + hh * cos
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
x: cx + -hw * cos - hh * sin,
|
|
35
|
-
y: cy + -hw * sin + hh * cos
|
|
36
|
-
}
|
|
37
|
-
];
|
|
38
|
-
}
|
|
39
|
-
function rotatedBBox(x, y, w, h, rotationDeg) {
|
|
40
|
-
if (rotationDeg === 0) return {
|
|
41
|
-
left: x,
|
|
42
|
-
right: x + w,
|
|
43
|
-
top: y,
|
|
44
|
-
bottom: y + h,
|
|
45
|
-
centerX: x + w / 2,
|
|
46
|
-
centerY: y + h / 2
|
|
47
|
-
};
|
|
48
|
-
const corners = rotatedCorners(x + w / 2, y + h / 2, w / 2, h / 2, rotationDeg);
|
|
49
|
-
let left = Infinity, right = -Infinity, top = Infinity, bottom = -Infinity;
|
|
50
|
-
for (const c of corners) {
|
|
51
|
-
left = Math.min(left, c.x);
|
|
52
|
-
right = Math.max(right, c.x);
|
|
53
|
-
top = Math.min(top, c.y);
|
|
54
|
-
bottom = Math.max(bottom, c.y);
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
left,
|
|
58
|
-
right,
|
|
59
|
-
top,
|
|
60
|
-
bottom,
|
|
61
|
-
centerX: (left + right) / 2,
|
|
62
|
-
centerY: (top + bottom) / 2
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function createBoundsAccumulator() {
|
|
66
|
-
return {
|
|
67
|
-
minX: Infinity,
|
|
68
|
-
minY: Infinity,
|
|
69
|
-
maxX: -Infinity,
|
|
70
|
-
maxY: -Infinity
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
function includePoint(bounds, x, y) {
|
|
74
|
-
bounds.minX = Math.min(bounds.minX, x);
|
|
75
|
-
bounds.minY = Math.min(bounds.minY, y);
|
|
76
|
-
bounds.maxX = Math.max(bounds.maxX, x);
|
|
77
|
-
bounds.maxY = Math.max(bounds.maxY, y);
|
|
78
|
-
}
|
|
79
|
-
function includeRect(bounds, rect) {
|
|
80
|
-
includePoint(bounds, rect.x, rect.y);
|
|
81
|
-
includePoint(bounds, rect.x + rect.width, rect.y + rect.height);
|
|
82
|
-
}
|
|
83
|
-
function boundsToRect(bounds) {
|
|
84
|
-
return bounds.minX === Infinity ? {
|
|
85
|
-
x: 0,
|
|
86
|
-
y: 0,
|
|
87
|
-
width: 0,
|
|
88
|
-
height: 0
|
|
89
|
-
} : {
|
|
90
|
-
x: bounds.minX,
|
|
91
|
-
y: bounds.minY,
|
|
92
|
-
width: bounds.maxX - bounds.minX,
|
|
93
|
-
height: bounds.maxY - bounds.minY
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function computeBounds(items) {
|
|
97
|
-
const bounds = createBoundsAccumulator();
|
|
98
|
-
for (const item of items) includeRect(bounds, item);
|
|
99
|
-
return boundsToRect(bounds);
|
|
100
|
-
}
|
|
101
|
-
function polygonVertices(node) {
|
|
102
|
-
const cx = node.width / 2;
|
|
103
|
-
const cy = node.height / 2;
|
|
104
|
-
const rx = node.width / 2;
|
|
105
|
-
const ry = node.height / 2;
|
|
106
|
-
const pointCount = Math.max(3, node.pointCount);
|
|
107
|
-
const isStar = node.type === "STAR";
|
|
108
|
-
const innerRatio = isStar ? node.starInnerRadius : 1;
|
|
109
|
-
const totalPoints = isStar ? pointCount * 2 : pointCount;
|
|
110
|
-
const angleOffset = -Math.PI / 2;
|
|
111
|
-
return Array.from({ length: totalPoints }, (_, index) => {
|
|
112
|
-
const angle = angleOffset + 2 * Math.PI * index / totalPoints;
|
|
113
|
-
const radius = isStar && index % 2 === 1 ? innerRatio : 1;
|
|
114
|
-
return {
|
|
115
|
-
x: cx + rx * radius * Math.cos(angle),
|
|
116
|
-
y: cy + ry * radius * Math.sin(angle)
|
|
117
|
-
};
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
function strokeOverflow(strokes) {
|
|
121
|
-
let overflow = 0;
|
|
122
|
-
for (const stroke of strokes ?? []) {
|
|
123
|
-
if (!stroke.visible) continue;
|
|
124
|
-
let extra = 0;
|
|
125
|
-
if (stroke.align === "OUTSIDE") extra = stroke.weight;
|
|
126
|
-
else if (stroke.align === "CENTER") extra = stroke.weight / 2;
|
|
127
|
-
overflow = Math.max(overflow, extra);
|
|
128
|
-
}
|
|
129
|
-
return overflow;
|
|
130
|
-
}
|
|
131
|
-
function effectOverflow(effects) {
|
|
132
|
-
let left = 0;
|
|
133
|
-
let right = 0;
|
|
134
|
-
let top = 0;
|
|
135
|
-
let bottom = 0;
|
|
136
|
-
for (const effect of effects ?? []) {
|
|
137
|
-
if (!effect.visible) continue;
|
|
138
|
-
if (effect.type !== "DROP_SHADOW" && effect.type !== "LAYER_BLUR" && effect.type !== "FOREGROUND_BLUR") continue;
|
|
139
|
-
const blurSpread = effect.radius + effect.spread;
|
|
140
|
-
left = Math.max(left, blurSpread + Math.max(0, -effect.offset.x));
|
|
141
|
-
right = Math.max(right, blurSpread + Math.max(0, effect.offset.x));
|
|
142
|
-
top = Math.max(top, blurSpread + Math.max(0, -effect.offset.y));
|
|
143
|
-
bottom = Math.max(bottom, blurSpread + Math.max(0, effect.offset.y));
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
left,
|
|
147
|
-
right,
|
|
148
|
-
top,
|
|
149
|
-
bottom
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function computeAbsoluteBounds(nodes, getAbsolutePosition) {
|
|
153
|
-
const bounds = createBoundsAccumulator();
|
|
154
|
-
for (const n of nodes) {
|
|
155
|
-
const abs = getAbsolutePosition(n.id);
|
|
156
|
-
includeRect(bounds, {
|
|
157
|
-
x: abs.x,
|
|
158
|
-
y: abs.y,
|
|
159
|
-
width: n.width,
|
|
160
|
-
height: n.height
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
return boundsToRect(bounds);
|
|
164
|
-
}
|
|
165
|
-
function computeVisualBounds(nodes, getAbsolutePosition) {
|
|
166
|
-
const bounds = createBoundsAccumulator();
|
|
167
|
-
for (const n of nodes) {
|
|
168
|
-
const abs = getAbsolutePosition(n.id);
|
|
169
|
-
const bbox = rotatedBBox(abs.x, abs.y, n.width, n.height, n.rotation ?? 0);
|
|
170
|
-
const stroke = strokeOverflow(n.strokes);
|
|
171
|
-
const effects = effectOverflow(n.effects);
|
|
172
|
-
includePoint(bounds, bbox.left - stroke - effects.left, bbox.top - stroke - effects.top);
|
|
173
|
-
includePoint(bounds, bbox.right + stroke + effects.right, bbox.bottom + stroke + effects.bottom);
|
|
174
|
-
}
|
|
175
|
-
return boundsToRect(bounds);
|
|
176
|
-
}
|
|
177
|
-
function unionVisualBounds(a, b) {
|
|
178
|
-
if (!a) return b;
|
|
179
|
-
if (!b) return a;
|
|
180
|
-
return {
|
|
181
|
-
minX: Math.min(a.minX, b.minX),
|
|
182
|
-
minY: Math.min(a.minY, b.minY),
|
|
183
|
-
maxX: Math.max(a.maxX, b.maxX),
|
|
184
|
-
maxY: Math.max(a.maxY, b.maxY)
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
function intersectVisualBounds(a, b) {
|
|
188
|
-
const minX = Math.max(a.minX, b.minX);
|
|
189
|
-
const minY = Math.max(a.minY, b.minY);
|
|
190
|
-
const maxX = Math.min(a.maxX, b.maxX);
|
|
191
|
-
const maxY = Math.min(a.maxY, b.maxY);
|
|
192
|
-
return minX < maxX && minY < maxY ? {
|
|
193
|
-
minX,
|
|
194
|
-
minY,
|
|
195
|
-
maxX,
|
|
196
|
-
maxY
|
|
197
|
-
} : null;
|
|
198
|
-
}
|
|
199
|
-
function geometryCommandCoordCount(command) {
|
|
200
|
-
if (command === 0) return 0;
|
|
201
|
-
if (command === 1 || command === 2) return 1;
|
|
202
|
-
if (command === 4) return 3;
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
function geometryBlobBounds(paths) {
|
|
206
|
-
const bounds = createBoundsAccumulator();
|
|
207
|
-
for (const path of paths) {
|
|
208
|
-
const blob = path.commandsBlob;
|
|
209
|
-
const dv = new DataView(blob.buffer, blob.byteOffset, blob.byteLength);
|
|
210
|
-
let offset = 0;
|
|
211
|
-
while (offset < blob.length) {
|
|
212
|
-
const command = blob[offset++];
|
|
213
|
-
const coords = geometryCommandCoordCount(command);
|
|
214
|
-
if (coords == null) break;
|
|
215
|
-
for (let i = 0; i < coords; i++) {
|
|
216
|
-
if (offset + 8 > blob.length) break;
|
|
217
|
-
includePoint(bounds, dv.getFloat32(offset, true), dv.getFloat32(offset + 4, true));
|
|
218
|
-
offset += 8;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return bounds.minX === Infinity ? null : boundsToRect(bounds);
|
|
223
|
-
}
|
|
224
|
-
function transformLocalPoint(node, point) {
|
|
225
|
-
let x = node.flipX ? node.width - point.x : point.x;
|
|
226
|
-
let y = node.flipY ? node.height - point.y : point.y;
|
|
227
|
-
const rotation = node.rotation ?? 0;
|
|
228
|
-
if (rotation !== 0) {
|
|
229
|
-
const rotated = rotatePoint(x, y, node.width / 2, node.height / 2, degToRad(rotation));
|
|
230
|
-
x = rotated.x;
|
|
231
|
-
y = rotated.y;
|
|
232
|
-
}
|
|
233
|
-
return {
|
|
234
|
-
x,
|
|
235
|
-
y
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
function transformedLocalBounds(node, local, abs) {
|
|
239
|
-
const points = [
|
|
240
|
-
{
|
|
241
|
-
x: local.x,
|
|
242
|
-
y: local.y
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
x: local.x + local.width,
|
|
246
|
-
y: local.y
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
x: local.x + local.width,
|
|
250
|
-
y: local.y + local.height
|
|
251
|
-
},
|
|
252
|
-
{
|
|
253
|
-
x: local.x,
|
|
254
|
-
y: local.y + local.height
|
|
255
|
-
}
|
|
256
|
-
].map((point) => transformLocalPoint(node, point));
|
|
257
|
-
return {
|
|
258
|
-
minX: abs.x + Math.min(...points.map((point) => point.x)),
|
|
259
|
-
minY: abs.y + Math.min(...points.map((point) => point.y)),
|
|
260
|
-
maxX: abs.x + Math.max(...points.map((point) => point.x)),
|
|
261
|
-
maxY: abs.y + Math.max(...points.map((point) => point.y))
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
function nodeVisualBounds(node, getAbsolutePosition) {
|
|
265
|
-
const abs = getAbsolutePosition(node.id);
|
|
266
|
-
const base = computeVisualBounds([node], getAbsolutePosition);
|
|
267
|
-
let bounds = {
|
|
268
|
-
minX: base.x,
|
|
269
|
-
minY: base.y,
|
|
270
|
-
maxX: base.x + base.width,
|
|
271
|
-
maxY: base.y + base.height
|
|
272
|
-
};
|
|
273
|
-
const hasNonInsideStroke = node.strokes?.some((stroke) => stroke.visible && stroke.align !== "INSIDE");
|
|
274
|
-
const localGeometry = geometryBlobBounds([...node.fillGeometry ?? [], ...hasNonInsideStroke ? node.strokeGeometry ?? [] : []]);
|
|
275
|
-
if (localGeometry) bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds;
|
|
276
|
-
if (node.type === "TEXT" && node.textDecoration && node.textDecoration !== "NONE") {
|
|
277
|
-
const fontSize = node.fontSize ?? 14;
|
|
278
|
-
const underlineOffset = node.textUnderlineOffset ?? fontSize * .18;
|
|
279
|
-
const thickness = node.textDecorationThickness ?? Math.max(1, fontSize / 16);
|
|
280
|
-
bounds.maxY += underlineOffset + thickness + fontSize * .35;
|
|
281
|
-
}
|
|
282
|
-
return bounds;
|
|
283
|
-
}
|
|
284
|
-
function collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition, clip = null) {
|
|
285
|
-
const node = getNode(nodeId);
|
|
286
|
-
if (!node?.visible) return null;
|
|
287
|
-
const own = nodeVisualBounds(node, getAbsolutePosition);
|
|
288
|
-
let bounds = clip ? intersectVisualBounds(own, clip) : own;
|
|
289
|
-
const isClippableContainer = node.type === "FRAME" || node.type === "COMPONENT" || node.type === "INSTANCE";
|
|
290
|
-
let childClip = clip;
|
|
291
|
-
if (isClippableContainer && node.clipsContent) {
|
|
292
|
-
const abs = getAbsolutePosition(node.id);
|
|
293
|
-
const nodeClip = {
|
|
294
|
-
minX: abs.x,
|
|
295
|
-
minY: abs.y,
|
|
296
|
-
maxX: abs.x + node.width,
|
|
297
|
-
maxY: abs.y + node.height
|
|
298
|
-
};
|
|
299
|
-
childClip = childClip ? intersectVisualBounds(childClip, nodeClip) : nodeClip;
|
|
300
|
-
if (!childClip) return bounds;
|
|
301
|
-
}
|
|
302
|
-
for (const childId of node.childIds ?? []) bounds = unionVisualBounds(bounds, collectDescendantVisualBounds(childId, getNode, getAbsolutePosition, childClip));
|
|
303
|
-
return bounds;
|
|
304
|
-
}
|
|
305
|
-
function computeDescendantVisualBounds(nodeIds, getNode, getAbsolutePosition) {
|
|
306
|
-
let bounds = null;
|
|
307
|
-
for (const nodeId of nodeIds) bounds = unionVisualBounds(bounds, collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition));
|
|
308
|
-
return bounds;
|
|
309
|
-
}
|
|
310
|
-
function crossProduct(a, b, p) {
|
|
311
|
-
return (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x);
|
|
312
|
-
}
|
|
313
|
-
function lineSegmentIntersect(p1, p2, p3, p4) {
|
|
314
|
-
const dx1 = p2.x - p1.x;
|
|
315
|
-
const dy1 = p2.y - p1.y;
|
|
316
|
-
const dx2 = p4.x - p3.x;
|
|
317
|
-
const dy2 = p4.y - p3.y;
|
|
318
|
-
const denom = dx1 * dy2 - dy1 * dx2;
|
|
319
|
-
if (denom === 0) return p1;
|
|
320
|
-
const t = ((p3.x - p1.x) * dy2 - (p3.y - p1.y) * dx2) / denom;
|
|
321
|
-
return {
|
|
322
|
-
x: p1.x + t * dx1,
|
|
323
|
-
y: p1.y + t * dy1
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
function clipHalfPlane(polygon, a, b, wantPositive) {
|
|
327
|
-
const output = [];
|
|
328
|
-
const isInside = (p) => {
|
|
329
|
-
const cross = crossProduct(a, b, p);
|
|
330
|
-
return wantPositive ? cross >= 0 : cross <= 0;
|
|
331
|
-
};
|
|
332
|
-
for (let i = 0; i < polygon.length; i++) {
|
|
333
|
-
const curr = polygon[i];
|
|
334
|
-
const prev = polygon[i === 0 ? polygon.length - 1 : i - 1];
|
|
335
|
-
const currInside = isInside(curr);
|
|
336
|
-
const prevInside = isInside(prev);
|
|
337
|
-
if (currInside) {
|
|
338
|
-
if (!prevInside) output.push(lineSegmentIntersect(prev, curr, a, b));
|
|
339
|
-
output.push(curr);
|
|
340
|
-
} else if (prevInside) output.push(lineSegmentIntersect(prev, curr, a, b));
|
|
341
|
-
}
|
|
342
|
-
return output;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Clip a subject polygon against a convex polygon (e.g. the 4 canvas-space
|
|
346
|
-
* corners of a rotated clipping ancestor).
|
|
347
|
-
*
|
|
348
|
-
* Uses Sutherland–Hodgman polygon clipping with centroid-based interior
|
|
349
|
-
* detection, making it robust to either winding order of the clip polygon.
|
|
350
|
-
* Returns the clipped polygon, or null if the subject is fully outside the
|
|
351
|
-
* clip polygon. When `clipCorners` has fewer than 3 points the subject is
|
|
352
|
-
* returned unchanged (no clipping).
|
|
353
|
-
*
|
|
354
|
-
* Preserving the polygon (rather than collapsing to an AABB) lets callers
|
|
355
|
-
* chain multiple clips without reintroducing corners removed by an inner clip.
|
|
356
|
-
*/
|
|
357
|
-
function clipPolygon(subject, clipCorners) {
|
|
358
|
-
if (clipCorners.length < 3) return subject;
|
|
359
|
-
let cx = 0;
|
|
360
|
-
let cy = 0;
|
|
361
|
-
for (const c of clipCorners) {
|
|
362
|
-
cx += c.x;
|
|
363
|
-
cy += c.y;
|
|
364
|
-
}
|
|
365
|
-
cx /= clipCorners.length;
|
|
366
|
-
cy /= clipCorners.length;
|
|
367
|
-
let polygon = subject;
|
|
368
|
-
for (let i = 0; i < clipCorners.length; i++) {
|
|
369
|
-
if (polygon.length === 0) return null;
|
|
370
|
-
const a = clipCorners[i];
|
|
371
|
-
const b = clipCorners[(i + 1) % clipCorners.length];
|
|
372
|
-
const centroidCross = crossProduct(a, b, {
|
|
373
|
-
x: cx,
|
|
374
|
-
y: cy
|
|
375
|
-
});
|
|
376
|
-
polygon = clipHalfPlane(polygon, a, b, centroidCross >= 0);
|
|
377
|
-
}
|
|
378
|
-
return polygon.length === 0 ? null : polygon;
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Clip an axis-aligned VisualBounds rectangle against a convex polygon
|
|
382
|
-
* (e.g. the 4 canvas-space corners of a rotated clipping ancestor).
|
|
383
|
-
*
|
|
384
|
-
* Returns the AABB of the intersection, or null if the bounds are fully
|
|
385
|
-
* outside the clip polygon. Delegates to {@link clipPolygon}.
|
|
386
|
-
*
|
|
387
|
-
* For a non-rotated clip (axis-aligned corners) the result is identical
|
|
388
|
-
* to `intersectVisualBounds`.
|
|
389
|
-
*/
|
|
390
|
-
function clipBoundsToPolygon(bounds, clipCorners) {
|
|
391
|
-
if (clipCorners.length < 3) return bounds;
|
|
392
|
-
const polygon = clipPolygon([
|
|
393
|
-
{
|
|
394
|
-
x: bounds.minX,
|
|
395
|
-
y: bounds.minY
|
|
396
|
-
},
|
|
397
|
-
{
|
|
398
|
-
x: bounds.maxX,
|
|
399
|
-
y: bounds.minY
|
|
400
|
-
},
|
|
401
|
-
{
|
|
402
|
-
x: bounds.maxX,
|
|
403
|
-
y: bounds.maxY
|
|
404
|
-
},
|
|
405
|
-
{
|
|
406
|
-
x: bounds.minX,
|
|
407
|
-
y: bounds.maxY
|
|
408
|
-
}
|
|
409
|
-
], clipCorners);
|
|
410
|
-
if (!polygon) return null;
|
|
411
|
-
let minX = Infinity;
|
|
412
|
-
let minY = Infinity;
|
|
413
|
-
let maxX = -Infinity;
|
|
414
|
-
let maxY = -Infinity;
|
|
415
|
-
for (const p of polygon) {
|
|
416
|
-
if (p.x < minX) minX = p.x;
|
|
417
|
-
if (p.y < minY) minY = p.y;
|
|
418
|
-
if (p.x > maxX) maxX = p.x;
|
|
419
|
-
if (p.y > maxY) maxY = p.y;
|
|
420
|
-
}
|
|
421
|
-
return minX < maxX && minY < maxY ? {
|
|
422
|
-
minX,
|
|
423
|
-
minY,
|
|
424
|
-
maxX,
|
|
425
|
-
maxY
|
|
426
|
-
} : null;
|
|
427
|
-
}
|
|
428
|
-
//#endregion
|
|
429
|
-
export { clipBoundsToPolygon, clipPolygon, computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, degToRad, effectOverflow, geometryBlobBounds, intersectVisualBounds, nodeVisualBounds, polygonVertices, radToDeg, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, unionVisualBounds };
|
|
430
|
-
|
|
431
|
-
//# sourceMappingURL=geometry.js.map
|
|
1
|
+
import { clipBoundsToPolygon, clipPolygon, computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, degToRad, effectOverflow, geometryBlobBounds, geometryCommandCoordCount, intersectVisualBounds, nodeVisualBounds, polygonVertices, radToDeg, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, unionVisualBounds } from "./chunks/components/properties.js";
|
|
2
|
+
export { clipBoundsToPolygon, clipPolygon, computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, degToRad, effectOverflow, geometryBlobBounds, geometryCommandCoordCount, intersectVisualBounds, nodeVisualBounds, polygonVertices, radToDeg, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, unionVisualBounds };
|
package/dist/guides.d.ts
ADDED
package/dist/guides.js
ADDED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guides2.d.ts","names":[],"sources":["../src/guides.ts"],"mappings":";;UAEiB;EACf;EACA;EACA;EACA,UAAU"}
|
package/dist/hit-test.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import { SceneNode } from "./types.js";
|
|
1
2
|
import { SceneGraph } from "./coordinate.js";
|
|
2
|
-
import { SceneNode } from "./types2.js";
|
|
3
|
-
|
|
4
3
|
//#region src/hit-test.d.ts
|
|
5
4
|
declare function hitTest(graph: SceneGraph, px: number, py: number, scopeId?: string): SceneNode | null;
|
|
6
5
|
declare function hitTestDeep(graph: SceneGraph, px: number, py: number, scopeId?: string): SceneNode | null;
|
package/dist/hit-test.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hit-test.d.ts","names":[],"sources":["../src/hit-test.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"hit-test.d.ts","names":[],"sources":["../src/hit-test.ts"],"mappings":";;;iBA8IgB,QACd,OAAO,YACP,YACA,YACA,mBACC;iBAKa,YACd,OAAO,YACP,YACA,YACA,mBACC;iBAuCa,aACd,OAAO,YACP,YACA,YACA,YAAY,aACZ,mBACC"}
|
package/dist/hit-test.js
CHANGED
|
@@ -13,38 +13,50 @@ const OPAQUE_CONTAINER_TYPES = /* @__PURE__ */ new Set(["COMPONENT", "INSTANCE"]
|
|
|
13
13
|
function hasVisibleFillOrStroke(node) {
|
|
14
14
|
return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible);
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function hasTransformedAncestor(node, graph, cache) {
|
|
17
|
+
const cached = cache.get(node.id);
|
|
18
|
+
if (cached !== void 0) return cached;
|
|
19
|
+
const parent = node.parentId ? graph.getNode(node.parentId) : void 0;
|
|
20
|
+
const transformed = node.rotation !== 0 || node.flipX || node.flipY || (parent ? hasTransformedAncestor(parent, graph, cache) : false);
|
|
21
|
+
cache.set(node.id, transformed);
|
|
22
|
+
return transformed;
|
|
23
|
+
}
|
|
24
|
+
function containsPoint(px, py, node, graph, transformCache) {
|
|
25
|
+
if (!hasTransformedAncestor(node, graph, transformCache)) {
|
|
26
|
+
const absolute = graph.getAbsolutePosition(node.id);
|
|
27
|
+
return px >= absolute.x && px <= absolute.x + node.width && py >= absolute.y && py <= absolute.y + node.height;
|
|
28
|
+
}
|
|
17
29
|
const m = getWorldMatrix(node, graph);
|
|
18
30
|
const inv = Matrix.invert(m);
|
|
19
31
|
if (!inv) return false;
|
|
20
32
|
const [localX, localY] = Matrix.mapPoints(inv, [px, py]);
|
|
21
33
|
return localX >= 0 && localX <= node.width && localY >= 0 && localY <= node.height;
|
|
22
34
|
}
|
|
23
|
-
function hitTestOpaqueContainer(graph, px, py, child, childId, deep) {
|
|
24
|
-
if (!containsPoint(px, py, child, graph)) return null;
|
|
25
|
-
if (hitTestChildren(graph, px, py, childId, deep)) return child;
|
|
35
|
+
function hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache) {
|
|
36
|
+
if (!containsPoint(px, py, child, graph, transformCache)) return null;
|
|
37
|
+
if (hitTestChildren(graph, px, py, childId, deep, transformCache)) return child;
|
|
26
38
|
if (hasVisibleFillOrStroke(child)) return child;
|
|
27
39
|
return null;
|
|
28
40
|
}
|
|
29
|
-
function hitTestTransparentContainer(graph, px, py, child, childId, deep) {
|
|
41
|
+
function hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache) {
|
|
30
42
|
if (child.type === "GROUP") {
|
|
31
|
-
if (!containsPoint(px, py, child, graph)) return null;
|
|
32
|
-
if (deep) return hitTestChildren(graph, px, py, childId, deep) ?? child;
|
|
43
|
+
if (!containsPoint(px, py, child, graph, transformCache)) return null;
|
|
44
|
+
if (deep) return hitTestChildren(graph, px, py, childId, deep, transformCache) ?? child;
|
|
33
45
|
return child;
|
|
34
46
|
}
|
|
35
|
-
const childHit = hitTestChildren(graph, px, py, childId, deep);
|
|
47
|
+
const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache);
|
|
36
48
|
if (childHit) {
|
|
37
49
|
if (child.locked) return child;
|
|
38
50
|
return childHit;
|
|
39
51
|
}
|
|
40
|
-
if (containsPoint(px, py, child, graph) && hasVisibleFillOrStroke(child)) return child;
|
|
52
|
+
if (containsPoint(px, py, child, graph, transformCache) && hasVisibleFillOrStroke(child)) return child;
|
|
41
53
|
return null;
|
|
42
54
|
}
|
|
43
|
-
function hitTestChildren(graph, px, py, parentId, deep = false) {
|
|
55
|
+
function hitTestChildren(graph, px, py, parentId, deep = false, transformCache = /* @__PURE__ */ new Map()) {
|
|
44
56
|
const parent = graph.nodes.get(parentId);
|
|
45
57
|
if (!parent) return null;
|
|
46
58
|
if (parent.clipsContent) {
|
|
47
|
-
if (!containsPoint(px, py, parent, graph)) return null;
|
|
59
|
+
if (!containsPoint(px, py, parent, graph, transformCache)) return null;
|
|
48
60
|
}
|
|
49
61
|
for (let i = parent.childIds.length - 1; i >= 0; i--) {
|
|
50
62
|
const childId = parent.childIds[i];
|
|
@@ -52,15 +64,15 @@ function hitTestChildren(graph, px, py, parentId, deep = false) {
|
|
|
52
64
|
if (!child || child.internalOnly || !child.visible) continue;
|
|
53
65
|
if (CONTAINER_TYPES.has(child.type)) {
|
|
54
66
|
if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {
|
|
55
|
-
const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep);
|
|
67
|
+
const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache);
|
|
56
68
|
if (hit) return hit;
|
|
57
69
|
continue;
|
|
58
70
|
}
|
|
59
|
-
const hit = hitTestTransparentContainer(graph, px, py, child, childId, deep);
|
|
71
|
+
const hit = hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache);
|
|
60
72
|
if (hit) return hit;
|
|
61
73
|
continue;
|
|
62
74
|
}
|
|
63
|
-
if (containsPoint(px, py, child, graph)) return child;
|
|
75
|
+
if (containsPoint(px, py, child, graph, transformCache)) return child;
|
|
64
76
|
}
|
|
65
77
|
return null;
|
|
66
78
|
}
|
package/dist/hit-test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import type { SceneGraph, SceneNode, NodeType } from './'\nimport { getWorldMatrix } from './coordinate'\nimport Matrix from './matrix'\n\nconst CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\nconst OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])\n\nfunction hasVisibleFillOrStroke(node: SceneNode): boolean {\n return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible)\n}\n\nfunction containsPoint(px: number
|
|
1
|
+
{"version":3,"file":"hit-test.js","names":[],"sources":["../src/hit-test.ts"],"sourcesContent":["import type { SceneGraph, SceneNode, NodeType } from './'\nimport { getWorldMatrix } from './coordinate'\nimport Matrix from './matrix'\n\nconst CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\nconst OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])\n\nfunction hasVisibleFillOrStroke(node: SceneNode): boolean {\n return node.fills.some((f) => f.visible) || node.strokes.some((s) => s.visible)\n}\n\nfunction hasTransformedAncestor(\n node: SceneNode,\n graph: SceneGraph,\n cache: Map<string, boolean>\n): boolean {\n const cached = cache.get(node.id)\n if (cached !== undefined) return cached\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const transformed =\n node.rotation !== 0 ||\n node.flipX ||\n node.flipY ||\n (parent ? hasTransformedAncestor(parent, graph, cache) : false)\n cache.set(node.id, transformed)\n return transformed\n}\n\nfunction containsPoint(\n px: number,\n py: number,\n node: SceneNode,\n graph: SceneGraph,\n transformCache: Map<string, boolean>\n): boolean {\n if (!hasTransformedAncestor(node, graph, transformCache)) {\n const absolute = graph.getAbsolutePosition(node.id)\n return (\n px >= absolute.x &&\n px <= absolute.x + node.width &&\n py >= absolute.y &&\n py <= absolute.y + node.height\n )\n }\n\n const m = getWorldMatrix(node, graph)\n\n const inv = Matrix.invert(m)\n if (!inv) return false\n\n const [localX, localY] = Matrix.mapPoints(inv, [px, py])\n return localX >= 0 && localX <= node.width && localY >= 0 && localY <= node.height\n}\n\nfunction hitTestOpaqueContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>\n): SceneNode | null {\n if (!containsPoint(px, py, child, graph, transformCache)) return null\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache)\n if (childHit) return child\n if (hasVisibleFillOrStroke(child)) return child\n return null\n}\nfunction hitTestTransparentContainer(\n graph: SceneGraph,\n px: number,\n py: number,\n child: SceneNode,\n childId: string,\n deep: boolean,\n transformCache: Map<string, boolean>\n): SceneNode | null {\n if (child.type === 'GROUP') {\n if (!containsPoint(px, py, child, graph, transformCache)) return null\n\n if (deep) return hitTestChildren(graph, px, py, childId, deep, transformCache) ?? child\n\n return child\n }\n\n const childHit = hitTestChildren(graph, px, py, childId, deep, transformCache)\n if (childHit) {\n if (child.locked) return child\n return childHit\n }\n\n if (containsPoint(px, py, child, graph, transformCache) && hasVisibleFillOrStroke(child))\n return child\n return null\n}\n\nfunction hitTestChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n deep = false,\n transformCache = new Map<string, boolean>()\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n\n if (parent.clipsContent) {\n if (!containsPoint(px, py, parent, graph, transformCache)) return null\n }\n\n for (let i = parent.childIds.length - 1; i >= 0; i--) {\n const childId = parent.childIds[i]\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible) continue\n if (CONTAINER_TYPES.has(child.type)) {\n if (OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {\n const hit = hitTestOpaqueContainer(graph, px, py, child, childId, deep, transformCache)\n if (hit) return hit\n continue\n }\n\n const hit = hitTestTransparentContainer(graph, px, py, child, childId, deep, transformCache)\n if (hit) return hit\n continue\n }\n\n if (containsPoint(px, py, child, graph, transformCache)) return child\n }\n\n return null\n}\n\nexport function hitTest(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, false)\n}\n\nexport function hitTestDeep(\n graph: SceneGraph,\n px: number,\n py: number,\n scopeId?: string\n): SceneNode | null {\n const scope = scopeId ?? graph.rootId\n return hitTestChildren(graph, px, py, scope, true)\n}\n\nfunction hitTestFrameChildren(\n graph: SceneGraph,\n px: number,\n py: number,\n parentId: string,\n offsetX: number,\n offsetY: number,\n excludeIds: Set<string>\n): SceneNode | null {\n const parent = graph.nodes.get(parentId)\n if (!parent) return null\n\n let best: SceneNode | null = null\n\n for (const childId of parent.childIds) {\n if (excludeIds.has(childId)) continue\n const child = graph.nodes.get(childId)\n if (!child || child.internalOnly || !child.visible) continue\n\n const ax = offsetX + child.x\n const ay = offsetY + child.y\n\n if (!CONTAINER_TYPES.has(child.type)) continue\n if (px < ax || px > ax + child.width || py < ay || py > ay + child.height) continue\n\n best = child\n\n const deeper = hitTestFrameChildren(graph, px, py, childId, ax, ay, excludeIds)\n if (deeper) best = deeper\n }\n\n return best\n}\n\nexport function hitTestFrame(\n graph: SceneGraph,\n px: number,\n py: number,\n excludeIds: Set<string>,\n scopeId?: string\n): SceneNode | null {\n return hitTestFrameChildren(graph, px, py, scopeId ?? graph.rootId, 0, 0, excludeIds)\n}\n"],"mappings":"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"}
|
package/dist/images.js
CHANGED
package/dist/images.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"images.js","names":[],"sources":["../src/images.ts"],"sourcesContent":["export function computeImageHash(data: Uint8Array): string {\n let h1 = 0x811c9dc5 >>> 0\n let h2 = 0x811c9dc5 >>> 0\n let h3 = 0x811c9dc5 >>> 0\n let h4 = 0x811c9dc5 >>> 0\n let h5 = 0x811c9dc5 >>> 0\n for (let i = 0; i < data.length; i++) {\n const b = data[i]\n switch (i % 5) {\n case 0:\n h1 ^= b\n h1 = Math.imul(h1, 0x01000193) >>> 0\n break\n case 1:\n h2 ^= b\n h2 = Math.imul(h2, 0x01000193) >>> 0\n break\n case 2:\n h3 ^= b\n h3 = Math.imul(h3, 0x01000193) >>> 0\n break\n case 3:\n h4 ^= b\n h4 = Math.imul(h4, 0x01000193) >>> 0\n break\n default:\n h5 ^= b\n h5 = Math.imul(h5, 0x01000193) >>> 0\n break\n }\n }\n h5 = Math.imul(h5 ^ data.length, 0x01000193) >>> 0\n return [h1, h2, h3, h4, h5].map((hash) => hash.toString(16).padStart(8, '0')).join('')\n}\n"],"mappings":";AAAA,SAAgB,iBAAiB,MAA0B;CACzD,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,IAAI,KAAK;EACf,QAAQ,IAAI,GAAZ;GACE,KAAK;IACH,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;GACF,KAAK;IACH,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;GACF,KAAK;IACH,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;GACF,KAAK;IACH,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;GACF;IACE,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;
|
|
1
|
+
{"version":3,"file":"images.js","names":[],"sources":["../src/images.ts"],"sourcesContent":["export function computeImageHash(data: Uint8Array): string {\n let h1 = 0x811c9dc5 >>> 0\n let h2 = 0x811c9dc5 >>> 0\n let h3 = 0x811c9dc5 >>> 0\n let h4 = 0x811c9dc5 >>> 0\n let h5 = 0x811c9dc5 >>> 0\n for (let i = 0; i < data.length; i++) {\n const b = data[i]\n switch (i % 5) {\n case 0:\n h1 ^= b\n h1 = Math.imul(h1, 0x01000193) >>> 0\n break\n case 1:\n h2 ^= b\n h2 = Math.imul(h2, 0x01000193) >>> 0\n break\n case 2:\n h3 ^= b\n h3 = Math.imul(h3, 0x01000193) >>> 0\n break\n case 3:\n h4 ^= b\n h4 = Math.imul(h4, 0x01000193) >>> 0\n break\n default:\n h5 ^= b\n h5 = Math.imul(h5, 0x01000193) >>> 0\n break\n }\n }\n h5 = Math.imul(h5 ^ data.length, 0x01000193) >>> 0\n return [h1, h2, h3, h4, h5].map((hash) => hash.toString(16).padStart(8, '0')).join('')\n}\n"],"mappings":";AAAA,SAAgB,iBAAiB,MAA0B;CACzD,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,IAAI,KAAK;EACf,QAAQ,IAAI,GAAZ;GACE,KAAK;IACH,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;GACF,KAAK;IACH,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;GACF,KAAK;IACH,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;GACF,KAAK;IACH,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;IACnC;GACF;IACE,MAAM;IACN,KAAK,KAAK,KAAK,IAAI,QAAU,MAAM;EAEvC;CACF;CACA,KAAK,KAAK,KAAK,KAAK,KAAK,QAAQ,QAAU,MAAM;CACjD,OAAO;EAAC;EAAI;EAAI;EAAI;EAAI;CAAE,CAAC,CAAC,KAAK,SAAS,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE;AACvF"}
|
package/dist/images2.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"images2.d.ts","names":[],"sources":["../src/images.ts"],"mappings":";iBAAgB,
|
|
1
|
+
{"version":3,"file":"images2.d.ts","names":[],"sources":["../src/images.ts"],"mappings":";iBAAgB,iBAAiB,MAAM"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Color, GUID, Size, Vector } from "./primitives2.js";
|
|
2
|
+
import { CanvasGuide } from "./guides2.js";
|
|
3
|
+
import { ArcData, BlendMode, CharacterStyleOverride, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConstraintType, DerivedTextGlyph, DocumentColorSpace, Effect, EnabledLibraryBinding, ExportFormatId, ExportSetting, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, ImageScaleMode, InstanceOverrideField, InstanceOverrideState, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MaskType, NodeType, NoiseType, NumericNodeProperty, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, SerializedInstanceOverrideState, SerializedOverrideValue, SharedStyle, SharedStyleKind, SharedStyleType, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TextAlignVertical, TextAutoResize, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextPathData, Variable, VariableCollection, VariableCollectionMode, VariableModeMap, VariableType, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule, clearInstanceOverrides, cloneInstanceOverrideState, createInstanceOverrideState, deleteInstanceOverride, deserializeInstanceOverrideState, forEachInstanceOverride, getInstanceOverride, serializeInstanceOverrideState, setInstanceOverride } from "./types.js";
|
|
2
4
|
import { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_STROKE_MITER_LIMIT, TRANSPARENT } from "./constants2.js";
|
|
5
|
+
import { CollectedSceneMutation, ComponentPropertyTarget, FONT_WEIGHT_NAMES, FontFamilyStyle, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS, MAX_EXPORT_SCALE, MIN_EXPORT_SCALE, MutationImpactListener, NodeCloneMode, ParsedFontStyle, SceneGraph, SceneMutationImpact, SnapGuide, SnapResult, VisualBounds, VisualBoundsNode, applyComponentPropertyValue, captureGraphCheckpoint, clampExportScale, clipBoundsToPolygon, clipPolygon, cloneNodeProps, collectSceneMutation, componentPropertyDefinitions, componentPropertyOwners, computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeSelectionBounds, computeSnap, computeVisualBounds, copyDerivedGlyphs, copyEffect, copyEffects, copyFill, copyFills, copyGeometryPaths, copyInstanceComponentProps, copyLayoutGrids, copyStroke, copyStrokes, copyStyleRun, copyStyleRuns, createSceneMutationImpact, degToRad, effectOverflow, findComponentPropertyTarget, findComponentPropertyTargets, generateId, geometryBlobBounds, geometryCommandCoordCount, getAbsolutePosition, getAbsolutePositionFull, getAbsoluteRotation, getAxisAlignedWorldBounds, getNodeLocalMatrix, getNodeRotationOrigin, getNodeWorldBounds, getSharedStyles, getWorldHandles, getWorldMatrix, hasInstanceOverride, hasSameCopySource, intersectVisualBounds, isValidExportScale, markCopySource, mutationLayoutScopeIds, nodeVisualBounds, normalizeFontFamily, normalizeFontStyleName, parseFontStyle, polygonVertices, radToDeg, recordInstanceOverride, removeComponentProperty, resolveComponentPropertyValue, rotatePoint, rotatedBBox, rotatedCorners, scaleGeometryPaths, sharedStyleRefKey, sharedStyleTypeForKind, strokeOverflow, styleDetachmentChanges, styleToVariant, styleToWeight, transformGeometryBlob, transformGeometryPaths, unionVisualBounds, weightToStyle } from "./coordinate.js";
|
|
3
6
|
import { computeImageHash } from "./images2.js";
|
|
4
|
-
import {
|
|
7
|
+
import { LayoutGuideLine, LayoutGuideSection, layoutGuideLines, layoutGuideSections } from "./layout-guides2.js";
|
|
5
8
|
import { Mat3, Matrix } from "./matrix2.js";
|
|
6
9
|
import { UndoEntry, UndoManager, UndoManagerOptions } from "./undo2.js";
|
|
7
|
-
import { ArcData, BlendMode, CharacterStyleOverride, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConstraintType, DocumentColorSpace, Effect, ExportFormatId, ExportSetting, FigmaDerivedTextGlyph, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFeature, FontVariation, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, ImageScaleMode, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, MaskType, NodeType, NoiseType, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, SceneGraphEventHandlers, SceneGraphEvents, SceneNode, SharedStyle, SharedStyleKind, SharedStyleType, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TextAlignVertical, TextAutoResize, TextCase, TextDecoration, TextDecorationStyle, TextDirection, Variable, VariableCollection, VariableCollectionMode, VariableModeMap, VariableType, VariableValue, VariantPropSpec, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, WindingRule } from "./types2.js";
|
|
8
10
|
import { cloneVectorNetwork, mergeVectorNetworks, normalizeVectorNetwork, transformVectorNetwork, validateVectorNetwork, vectorNetworksEqual } from "./vector-network2.js";
|
|
9
|
-
export { ArcData, BLACK, BlendMode, CharacterStyleOverride, type Color, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyType, ConstraintType, DEFAULT_FONT_FAMILY, DEFAULT_STROKE_MITER_LIMIT, DocumentColorSpace, Effect, ExportFormatId, ExportSetting, FONT_WEIGHT_NAMES,
|
|
11
|
+
export { ArcData, BLACK, BlendMode, CanvasGuide, CharacterStyleOverride, CollectedSceneMutation, type Color, ComponentPropertyDefinition, ComponentPropertyReference, ComponentPropertyReferenceField, ComponentPropertyTarget, ComponentPropertyType, ConstraintType, DEFAULT_FONT_FAMILY, DEFAULT_STROKE_MITER_LIMIT, DerivedTextGlyph, DocumentColorSpace, Effect, EnabledLibraryBinding, ExportFormatId, ExportSetting, FONT_WEIGHT_NAMES, FigmaLayoutMetadata, FigmaSourcePayload, Fill, FillType, FontFamilyStyle, FontFeature, FontVariation, type GUID, GeometryPath, GradientStop, GradientTransform, GridPosition, GridTrack, GridTrackSizing, HandleMirroring, INSTANCE_SYNC_FIELDS, INSTANCE_SYNC_PROPS, INSTANCE_SYNC_TEXT_PROPS, ImageScaleMode, InstanceOverrideField, InstanceOverrideState, LayoutAlign, LayoutAlignSelf, LayoutCounterAlign, LayoutDirection, LayoutGrid, LayoutGuideLine, LayoutGuideSection, LayoutMode, LayoutSizing, LayoutWrap, LeadingTrim, LibraryAssetIdentity, LibraryAssetSource, MAX_EXPORT_SCALE, MIN_EXPORT_SCALE, MaskType, type Mat3, MutationImpactListener, NodeCloneMode, NodeType, NoiseType, NumericNodeProperty, ParsedFontStyle, PatternAlignment, PatternTileType, PluginDataEntry, PluginRelaunchDataEntry, SceneGraph, SceneGraphEventHandlers, SceneGraphEvents, SceneMutationImpact, SceneNode, SerializedInstanceOverrideState, SerializedOverrideValue, SharedStyle, SharedStyleKind, SharedStyleType, type Size, SnapGuide, SnapResult, SourceMetadata, Stroke, StrokeCap, StrokeJoin, StyleRun, SymbolLink, TRANSPARENT, TextAlignVertical, TextAutoResize, TextCase, TextDecoration, TextDecorationStyle, TextDirection, TextPathData, Matrix as TransformMatrix, type UndoEntry, UndoManager, type UndoManagerOptions, Variable, VariableCollection, VariableCollectionMode, VariableModeMap, VariableType, VariableValue, VariantPropSpec, type Vector, VectorNetwork, VectorRegion, VectorSegment, VectorVertex, VisualBounds, VisualBoundsNode, WindingRule, applyComponentPropertyValue, captureGraphCheckpoint, clampExportScale, clearInstanceOverrides, clipBoundsToPolygon, clipPolygon, cloneInstanceOverrideState, cloneNodeProps, cloneVectorNetwork, collectSceneMutation, componentPropertyDefinitions, componentPropertyOwners, computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeImageHash, computeSelectionBounds, computeSnap, computeVisualBounds, copyDerivedGlyphs, copyEffect, copyEffects, copyFill, copyFills, copyGeometryPaths, copyInstanceComponentProps, copyLayoutGrids, copyStroke, copyStrokes, copyStyleRun, copyStyleRuns, createInstanceOverrideState, createSceneMutationImpact, degToRad, deleteInstanceOverride, deserializeInstanceOverrideState, effectOverflow, findComponentPropertyTarget, findComponentPropertyTargets, forEachInstanceOverride, generateId, geometryBlobBounds, geometryCommandCoordCount, getAbsolutePosition, getAbsolutePositionFull, getAbsoluteRotation, getAxisAlignedWorldBounds, getInstanceOverride, getNodeLocalMatrix, getNodeRotationOrigin, getNodeWorldBounds, getSharedStyles, getWorldHandles, getWorldMatrix, hasInstanceOverride, hasSameCopySource, intersectVisualBounds, isValidExportScale, layoutGuideLines, layoutGuideSections, markCopySource, mergeVectorNetworks, mutationLayoutScopeIds, nodeVisualBounds, normalizeFontFamily, normalizeFontStyleName, normalizeVectorNetwork, parseFontStyle, polygonVertices, radToDeg, recordInstanceOverride, removeComponentProperty, resolveComponentPropertyValue, rotatePoint, rotatedBBox, rotatedCorners, scaleGeometryPaths, serializeInstanceOverrideState, setInstanceOverride, sharedStyleRefKey, sharedStyleTypeForKind, strokeOverflow, styleDetachmentChanges, styleToVariant, styleToWeight, transformGeometryBlob, transformGeometryPaths, transformVectorNetwork, unionVisualBounds, validateVectorNetwork, vectorNetworksEqual, weightToStyle };
|