@pixerate/editor 0.107.0 → 0.109.0

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.
Files changed (78) hide show
  1. package/THIRD_PARTY_NOTICES.md +4 -0
  2. package/dist/animation/index.cjs +5 -5
  3. package/dist/animation/index.cjs.map +1 -1
  4. package/dist/animation/index.js +9 -9
  5. package/dist/animation-editor/index.cjs +59 -59
  6. package/dist/animation-editor/index.cjs.map +1 -1
  7. package/dist/animation-editor/index.d.cts +2 -1
  8. package/dist/animation-editor/index.d.ts +2 -1
  9. package/dist/animation-editor/index.js +29 -29
  10. package/dist/canvas/index.cjs +27 -27
  11. package/dist/canvas/index.cjs.map +1 -1
  12. package/dist/canvas/index.js +11 -11
  13. package/dist/{chunk-2FGRTYJN.cjs → chunk-477UVMNR.cjs} +3 -3
  14. package/dist/{chunk-2FGRTYJN.cjs.map → chunk-477UVMNR.cjs.map} +1 -1
  15. package/dist/{chunk-T3QZ6S47.cjs → chunk-AZTZRLDI.cjs} +40 -2
  16. package/dist/chunk-AZTZRLDI.cjs.map +1 -0
  17. package/dist/{chunk-63EFQCT5.js → chunk-BLWCAQCW.js} +2879 -3362
  18. package/dist/chunk-BLWCAQCW.js.map +1 -0
  19. package/dist/{chunk-G4BIYE6R.js → chunk-CFMWALBM.js} +39 -1
  20. package/dist/chunk-CFMWALBM.js.map +1 -0
  21. package/dist/{chunk-FRD3FUXI.cjs → chunk-D37BX2ZA.cjs} +2081 -460
  22. package/dist/chunk-D37BX2ZA.cjs.map +1 -0
  23. package/dist/chunk-JLYX4V57.cjs +2001 -0
  24. package/dist/chunk-JLYX4V57.cjs.map +1 -0
  25. package/dist/chunk-KB2YBCVS.js +2001 -0
  26. package/dist/chunk-KB2YBCVS.js.map +1 -0
  27. package/dist/{chunk-SOROZ2BF.js → chunk-RE77QYUF.js} +1938 -317
  28. package/dist/chunk-RE77QYUF.js.map +1 -0
  29. package/dist/{chunk-KANRAHTL.cjs → chunk-W3GXSUSQ.cjs} +2830 -3313
  30. package/dist/chunk-W3GXSUSQ.cjs.map +1 -0
  31. package/dist/{chunk-JK6M6V7G.js → chunk-Z3YWVUWT.js} +4 -4
  32. package/dist/{export-a9bnF7Cl.d.ts → export-BLPLaE6Z.d.ts} +417 -16
  33. package/dist/{export-JGWQEPJn.d.cts → export-DSUc4fQD.d.cts} +417 -16
  34. package/dist/image-editor/index.cjs +1527 -1001
  35. package/dist/image-editor/index.cjs.map +1 -1
  36. package/dist/image-editor/index.d.cts +73 -9
  37. package/dist/image-editor/index.d.ts +73 -9
  38. package/dist/image-editor/index.js +814 -288
  39. package/dist/image-editor/index.js.map +1 -1
  40. package/dist/paint-editor/index.cjs +252 -64
  41. package/dist/paint-editor/index.cjs.map +1 -1
  42. package/dist/paint-editor/index.d.cts +101 -4
  43. package/dist/paint-editor/index.d.ts +101 -4
  44. package/dist/paint-editor/index.js +196 -8
  45. package/dist/paint-editor/index.js.map +1 -1
  46. package/dist/raster/index.cjs +4 -2
  47. package/dist/raster/index.cjs.map +1 -1
  48. package/dist/raster/index.d.cts +3 -129
  49. package/dist/raster/index.d.ts +3 -129
  50. package/dist/raster/index.js +3 -1
  51. package/dist/{compositor-D92URMlm.d.cts → render-C-fO_mes.d.cts} +135 -1
  52. package/dist/{compositor-Kt_M4ruo.d.ts → render-OLIMk_v0.d.ts} +135 -1
  53. package/dist/{svg-vme0PLNo.d.ts → svg-D_cfkhlB.d.cts} +6 -608
  54. package/dist/{svg-Bj1MQFh6.d.cts → svg-wIaKLrU0.d.ts} +6 -608
  55. package/dist/types-DtL_qLFz.d.ts +630 -0
  56. package/dist/types-DyQq-WPY.d.cts +630 -0
  57. package/dist/vector/index.cjs +1080 -1051
  58. package/dist/vector/index.cjs.map +1 -1
  59. package/dist/vector/index.d.cts +268 -7
  60. package/dist/vector/index.d.ts +268 -7
  61. package/dist/vector/index.js +495 -466
  62. package/dist/vector/index.js.map +1 -1
  63. package/dist/video-editor/index.cjs +3 -3
  64. package/dist/video-editor/index.js +2 -2
  65. package/package.json +1 -1
  66. package/skills/pixerate-image-editor/SKILL.md +50 -7
  67. package/skills/pixerate-vector/SKILL.md +35 -5
  68. package/dist/chunk-63EFQCT5.js.map +0 -1
  69. package/dist/chunk-DWGZUSES.cjs +0 -694
  70. package/dist/chunk-DWGZUSES.cjs.map +0 -1
  71. package/dist/chunk-FRD3FUXI.cjs.map +0 -1
  72. package/dist/chunk-G4BIYE6R.js.map +0 -1
  73. package/dist/chunk-KANRAHTL.cjs.map +0 -1
  74. package/dist/chunk-KKREERP2.js +0 -694
  75. package/dist/chunk-KKREERP2.js.map +0 -1
  76. package/dist/chunk-SOROZ2BF.js.map +0 -1
  77. package/dist/chunk-T3QZ6S47.cjs.map +0 -1
  78. /package/dist/{chunk-JK6M6V7G.js.map → chunk-Z3YWVUWT.js.map} +0 -0
@@ -1,694 +0,0 @@
1
- // src/geom/affine.ts
2
- var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
3
- function multiplyMatrices(a, b) {
4
- const [a0, a1, a2, a3, a4, a5] = a;
5
- const [b0, b1, b2, b3, b4, b5] = b;
6
- return [b0 * a0 + b2 * a1, b1 * a0 + b3 * a1, b0 * a2 + b2 * a3, b1 * a2 + b3 * a3, b0 * a4 + b2 * a5 + b4, b1 * a4 + b3 * a5 + b5];
7
- }
8
- var translateMatrix = (dx, dy) => [1, 0, 0, 1, dx, dy];
9
- function scaleMatrix(sx, sy, origin = { x: 0, y: 0 }) {
10
- return [sx, 0, 0, sy, origin.x - sx * origin.x, origin.y - sy * origin.y];
11
- }
12
- function rotateMatrix(degrees, origin = { x: 0, y: 0 }) {
13
- const r = degrees * Math.PI / 180;
14
- const cos = Math.cos(r);
15
- const sin = Math.sin(r);
16
- return [cos, sin, -sin, cos, origin.x - cos * origin.x + sin * origin.y, origin.y - sin * origin.x - cos * origin.y];
17
- }
18
- function matrixAbout(m, origin) {
19
- return multiplyMatrices(multiplyMatrices(translateMatrix(-origin.x, -origin.y), m), translateMatrix(origin.x, origin.y));
20
- }
21
- function skewMatrix(ax, ay, origin = { x: 0, y: 0 }) {
22
- const tx = Math.tan(ax * Math.PI / 180);
23
- const ty = Math.tan(ay * Math.PI / 180);
24
- return matrixAbout([1, ty, tx, 1, 0, 0], origin);
25
- }
26
- function applyMatrix(m, p) {
27
- return { x: m[0] * p.x + m[2] * p.y + m[4], y: m[1] * p.x + m[3] * p.y + m[5] };
28
- }
29
- function isIdentityMatrix(m, eps = 1e-12) {
30
- return Math.abs(m[0] - 1) < eps && Math.abs(m[1]) < eps && Math.abs(m[2]) < eps && Math.abs(m[3] - 1) < eps && Math.abs(m[4]) < eps && Math.abs(m[5]) < eps;
31
- }
32
- function invertMatrix(m) {
33
- const [a, b, c, d, e, f] = m;
34
- const det = a * d - b * c;
35
- if (!det || !Number.isFinite(det)) return IDENTITY_MATRIX;
36
- return [d / det, -b / det, -c / det, a / det, (c * f - d * e) / det, (b * e - a * f) / det];
37
- }
38
- function applyMatrixLinear(m, v) {
39
- return { x: m[0] * v.x + m[2] * v.y, y: m[1] * v.x + m[3] * v.y };
40
- }
41
- function matrixRotation(m) {
42
- const [a, b, c, d] = m;
43
- const mirrored = a * d - b * c < 0;
44
- const deg = (mirrored ? Math.atan2(-b - c, d - a) : Math.atan2(b - c, a + d)) * 180 / Math.PI;
45
- return Math.abs(deg) < 1e-9 ? 0 : deg;
46
- }
47
- function decomposeRigid(m) {
48
- const [a, b, c, d, e, f] = m;
49
- const deg = matrixRotation(m);
50
- if (deg === 0) return { rigid: IDENTITY_MATRIX, residual: m };
51
- const r = deg * Math.PI / 180;
52
- const cos = Math.cos(r);
53
- const sin = Math.sin(r);
54
- return {
55
- rigid: [cos, sin, -sin, cos, e, f],
56
- residual: [cos * a + sin * b, -sin * a + cos * b, cos * c + sin * d, -sin * c + cos * d, 0, 0]
57
- };
58
- }
59
-
60
- // src/geom/warp.ts
61
- var WARP_STYLES = [
62
- "arc",
63
- "arcLower",
64
- "arcUpper",
65
- "arch",
66
- "bulge",
67
- "shellLower",
68
- "shellUpper",
69
- "flag",
70
- "wave",
71
- "fish",
72
- "rise",
73
- "fisheye",
74
- "inflate",
75
- "squeeze",
76
- "twist"
77
- ];
78
- var WARP_STYLE_LABELS = {
79
- arc: "Arc",
80
- arcLower: "Arc Lower",
81
- arcUpper: "Arc Upper",
82
- arch: "Arch",
83
- bulge: "Bulge",
84
- shellLower: "Shell Lower",
85
- shellUpper: "Shell Upper",
86
- flag: "Flag",
87
- wave: "Wave",
88
- fish: "Fish",
89
- rise: "Rise",
90
- fisheye: "Fisheye",
91
- inflate: "Inflate",
92
- squeeze: "Squeeze",
93
- twist: "Twist"
94
- };
95
- function restGrid() {
96
- return [0, 1, 2, 3].map((j) => [0, 1, 2, 3].map((i) => [i / 3, j / 3]));
97
- }
98
- function edgeArc(y, b, up, h) {
99
- if (Math.abs(b) < 1e-9) return [0, 1, 2, 3].map((i) => [i / 3, y]);
100
- const th = Math.abs(b) * Math.PI;
101
- const k = 4 / 3 * Math.tan(th / 4) * 0.5 / Math.sin(th / 2);
102
- const s = b > 0 === up ? -1 : 1;
103
- const c = Math.cos(th / 2);
104
- const n = Math.sin(th / 2);
105
- const dy = s * k * n / h;
106
- return [
107
- [0, y],
108
- [k * c, y + dy],
109
- [1 - k * c, y + dy],
110
- [1, y]
111
- ];
112
- }
113
- function arcGrid(b, h) {
114
- if (Math.abs(b) < 1e-9) return restGrid();
115
- const up = b > 0;
116
- const th = Math.abs(b) * Math.PI;
117
- const r = 0.5 / Math.sin(th / 2);
118
- const k = 4 / 3 * Math.tan(th / 4);
119
- const s = up ? -1 : 1;
120
- const cy = up ? h + r * Math.cos(th / 2) : -r * Math.cos(th / 2);
121
- return [0, 1, 2, 3].map((j) => {
122
- const v = j / 3;
123
- const big = r + h * (up ? 1 - v : v);
124
- const at = (a) => [0.5 + big * Math.sin(a), cy + s * big * Math.cos(a)];
125
- const tangent = (a) => [Math.cos(a), -s * Math.sin(a)];
126
- const p0 = at(-th / 2);
127
- const p3 = at(th / 2);
128
- const t0 = tangent(-th / 2);
129
- const t1 = tangent(th / 2);
130
- const l = k * big;
131
- const pts = [p0, [p0[0] + l * t0[0], p0[1] + l * t0[1]], [p3[0] - l * t1[0], p3[1] - l * t1[1]], p3];
132
- return pts.map((p) => [p[0], p[1] / h]);
133
- });
134
- }
135
- function blendRows(top, bottom) {
136
- return [0, 1, 2, 3].map((j) => {
137
- const t = j / 3;
138
- return [0, 1, 2, 3].map((i) => [top[i][0] + (bottom[i][0] - top[i][0]) * t, top[i][1] + (bottom[i][1] - top[i][1]) * t]);
139
- });
140
- }
141
- var INNER = [
142
- [1, 1, -1, -1],
143
- [1, 2, 1, -1],
144
- [2, 1, -1, 1],
145
- [2, 2, 1, 1]
146
- ];
147
- function warpPresetGrid(style, b, hd, vd, vertical, aspect) {
148
- const h = vertical ? 1 / aspect : aspect;
149
- if (vertical) [hd, vd] = [vd, hd];
150
- let g = restGrid();
151
- switch (style) {
152
- case "arc":
153
- g = arcGrid(b, h);
154
- break;
155
- case "arch":
156
- g = [0, 1, 2, 3].map((j) => edgeArc(j / 3, b, true, h));
157
- break;
158
- case "bulge":
159
- g = blendRows(edgeArc(0, b, true, h), edgeArc(1, b, false, h));
160
- break;
161
- case "arcLower":
162
- g = blendRows(g[0], edgeArc(1, b, false, h));
163
- break;
164
- case "arcUpper":
165
- g = blendRows(edgeArc(0, b, true, h), g[3]);
166
- break;
167
- // The bulging edge and the outer points of the row next to it come from Arc (bent the other
168
- // way for Shell Lower); the rest stays put.
169
- case "shellLower": {
170
- const a = arcGrid(-b, h);
171
- g[3] = a[3];
172
- g[2][0] = a[2][0];
173
- g[2][3] = a[2][3];
174
- break;
175
- }
176
- case "shellUpper": {
177
- const a = arcGrid(b, h);
178
- g[0] = a[0];
179
- g[1][0] = a[1][0];
180
- g[1][3] = a[1][3];
181
- break;
182
- }
183
- case "flag":
184
- for (const row of g) {
185
- row[1][1] -= 2 * b;
186
- row[2][1] += 2 * b;
187
- }
188
- break;
189
- case "wave":
190
- for (const row of g.slice(1, 3)) {
191
- row[1][1] += 4 / 3 * b;
192
- row[2][1] -= 4 / 3 * b;
193
- }
194
- break;
195
- case "fish":
196
- [-2, -2 / 3, 2 / 3, 2].forEach((f, j) => {
197
- g[j][1][1] += f * b;
198
- g[j][2][1] -= f * b;
199
- });
200
- break;
201
- case "rise":
202
- for (const row of g) {
203
- row[0][1] += 2 * b;
204
- row[1][1] += 2 * b;
205
- }
206
- break;
207
- case "fisheye":
208
- for (const [j, i, dx, dy] of INNER) {
209
- g[j][i][0] += dx * 2 * b / 3;
210
- g[j][i][1] += dy * 2 * b / 3;
211
- }
212
- break;
213
- // Edge midpoints move out (Inflate) or the sides in (Squeeze) by b/3, the inner points by b/9.
214
- case "inflate":
215
- case "squeeze": {
216
- const s = style === "inflate" ? 1 : -1;
217
- for (const p of g[0].slice(1, 3)) p[1] -= b / 3;
218
- for (const p of g[3].slice(1, 3)) p[1] += b / 3;
219
- for (const row of g.slice(1, 3)) {
220
- row[0][0] -= s * b / 3;
221
- row[3][0] += s * b / 3;
222
- }
223
- for (const [j, i, dx, dy] of INNER) {
224
- g[j][i][0] += s * dx * b / 9;
225
- g[j][i][1] += dy * b / 9;
226
- }
227
- break;
228
- }
229
- // The inner points turn round the centre (the other way for a negative bend).
230
- case "twist": {
231
- const a = Math.abs(b);
232
- if (b >= 0) {
233
- g[1][1][0] += a;
234
- g[1][2][1] += a;
235
- g[2][1][1] -= a;
236
- g[2][2][0] -= a;
237
- } else {
238
- g[1][1][1] += a;
239
- g[1][2][0] -= a;
240
- g[2][1][0] += a;
241
- g[2][2][1] -= a;
242
- }
243
- break;
244
- }
245
- }
246
- if (vd !== 0) {
247
- const moved = (row, s) => {
248
- const m = [(row[0][0] + row[3][0]) / 2, (row[0][1] + row[3][1]) / 2];
249
- return row.map((p) => [m[0] + (p[0] - m[0]) * s - p[0], m[1] + (p[1] - m[1]) * s - p[1]]);
250
- };
251
- const d0 = moved(g[0], 1 - vd);
252
- const d3 = moved(g[3], 1 + vd);
253
- g.forEach((row, j) => {
254
- const t = j / 3;
255
- row.forEach((p, i) => {
256
- p[0] += d0[i][0] + (d3[i][0] - d0[i][0]) * t;
257
- p[1] += d0[i][1] + (d3[i][1] - d0[i][1]) * t;
258
- });
259
- });
260
- }
261
- if (hd !== 0) {
262
- for (let i = 0; i < 4; i++) {
263
- const s = 1 + hd * (2 * i / 3 - 1);
264
- const m = [(g[0][i][0] + g[3][i][0]) / 2, (g[0][i][1] + g[3][i][1]) / 2];
265
- for (const row of g) row[i] = [m[0] + (row[i][0] - m[0]) * s, m[1] + (row[i][1] - m[1]) * s];
266
- }
267
- }
268
- if (vertical) g = [0, 1, 2, 3].map((j) => [0, 1, 2, 3].map((i) => [g[i][j][1], g[i][j][0]]));
269
- return g;
270
- }
271
- function bernstein(t) {
272
- const s = 1 - t;
273
- return [s * s * s, 3 * s * s * t, 3 * s * t * t, t * t * t];
274
- }
275
- var lerpVec2 = (a, b, t) => ({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t });
276
- function splitCubic(p, t) {
277
- const a = lerpVec2(p[0], p[1], t);
278
- const b = lerpVec2(p[1], p[2], t);
279
- const c = lerpVec2(p[2], p[3], t);
280
- const d = lerpVec2(a, b, t);
281
- const e = lerpVec2(b, c, t);
282
- return [p[0], a, d, lerpVec2(d, e, t), e, c, p[3]];
283
- }
284
- var BERN_INV = [
285
- [1, 0, 0, 0],
286
- [-5 / 6, 3, -1.5, 1 / 3],
287
- [1 / 3, -1.5, 3, -5 / 6],
288
- [0, 0, 0, 1]
289
- ];
290
- var pct = (v) => typeof v === "number" && Number.isFinite(v) ? Math.min(1, Math.max(-1, v / 100)) : 0;
291
- function warpPresetMesh(preset, bounds) {
292
- if (!WARP_STYLES.includes(preset.style)) return null;
293
- const { x, y, width: w, height: h } = bounds;
294
- if (!(w > 0 && h > 0)) return null;
295
- const b = pct(preset.bend);
296
- const hd = pct(preset.horizontal);
297
- const vd = pct(preset.vertical);
298
- if (b === 0 && hd === 0 && vd === 0) return null;
299
- const grid = warpPresetGrid(preset.style, b, hd, vd, preset.orientation === "vertical", h / w);
300
- return { us: [0, 1], vs: [0, 1], points: grid.flat().map((p) => ({ x: x + p[0] * w, y: y + p[1] * h })) };
301
- }
302
- var warpMeshColumns = (m) => 3 * (m.us.length - 1) + 1;
303
- var warpMeshRows = (m) => 3 * (m.vs.length - 1) + 1;
304
- function isValidWarpMesh(m) {
305
- if (!m || typeof m !== "object") return false;
306
- const { us, vs, points } = m;
307
- const knots = (k) => Array.isArray(k) && k.length >= 2 && k.length <= 65 && k[0] === 0 && k[k.length - 1] === 1 && k.every((v, i) => typeof v === "number" && (i === 0 || v > k[i - 1]));
308
- if (!knots(us) || !knots(vs) || !Array.isArray(points)) return false;
309
- return points.length === (3 * (us.length - 1) + 1) * (3 * (vs.length - 1) + 1) && points.every((p) => !!p && Number.isFinite(p.x) && Number.isFinite(p.y));
310
- }
311
- function fitWarpMesh(f, us, vs) {
312
- const pc = us.length - 1;
313
- const pr = vs.length - 1;
314
- const nx = 3 * pc + 1;
315
- const points = new Array((3 * pr + 1) * nx);
316
- for (let pj = 0; pj < pr; pj++) {
317
- for (let pi = 0; pi < pc; pi++) {
318
- const s = [0, 1, 2, 3].map(
319
- (j) => [0, 1, 2, 3].map((i) => f(us[pi] + (us[pi + 1] - us[pi]) * i / 3, vs[pj] + (vs[pj + 1] - vs[pj]) * j / 3))
320
- );
321
- for (let j = 0; j < 4; j++) {
322
- for (let i = 0; i < 4; i++) {
323
- let x = 0;
324
- let y = 0;
325
- for (let a = 0; a < 4; a++) {
326
- for (let b = 0; b < 4; b++) {
327
- const k = BERN_INV[j][a] * BERN_INV[i][b];
328
- x += k * s[a][b].x;
329
- y += k * s[a][b].y;
330
- }
331
- }
332
- points[(3 * pj + j) * nx + 3 * pi + i] = { x, y };
333
- }
334
- }
335
- }
336
- }
337
- return { us: us.slice(), vs: vs.slice(), points };
338
- }
339
- var evenKnots = (n) => Array.from({ length: n + 1 }, (_, i) => i / n);
340
- var clampMeshCount = (n) => Math.min(64, Math.max(1, Math.round(Number.isFinite(n) ? n : 1)));
341
- function identityWarpMesh(bounds, columns = 1, rows = 1) {
342
- return fitWarpMesh((s, t) => ({ x: bounds.x + s * bounds.width, y: bounds.y + t * bounds.height }), evenKnots(clampMeshCount(columns)), evenKnots(clampMeshCount(rows)));
343
- }
344
- function locate(knots, s) {
345
- const n = knots.length - 1;
346
- let i = 0;
347
- while (i + 1 < n && s > knots[i + 1]) i++;
348
- const w = knots[i + 1] - knots[i];
349
- return [i, w > 0 ? (s - knots[i]) / w : 0];
350
- }
351
- function evalWarpMesh(m, s, t) {
352
- const [pi, a] = locate(m.us, s);
353
- const [pj, b] = locate(m.vs, t);
354
- const ba = bernstein(a);
355
- const bb = bernstein(b);
356
- const nx = warpMeshColumns(m);
357
- let x = 0;
358
- let y = 0;
359
- for (let j = 0; j < 4; j++) {
360
- for (let i = 0; i < 4; i++) {
361
- const p = m.points[(3 * pj + j) * nx + 3 * pi + i];
362
- const k = ba[i] * bb[j];
363
- x += p.x * k;
364
- y += p.y * k;
365
- }
366
- }
367
- return { x, y };
368
- }
369
- function transposeMesh(m) {
370
- const nx = warpMeshColumns(m);
371
- const ny = warpMeshRows(m);
372
- const points = new Array(nx * ny);
373
- for (let j = 0; j < ny; j++) for (let i = 0; i < nx; i++) points[i * ny + j] = m.points[j * nx + i];
374
- return { us: m.vs.slice(), vs: m.us.slice(), points };
375
- }
376
- function splitWarpMeshU(m, s) {
377
- const [pi, a] = locate(m.us, s);
378
- if (!(a >= 0.01 && a <= 0.99)) return null;
379
- const nx = warpMeshColumns(m);
380
- const ny = warpMeshRows(m);
381
- const points = [];
382
- for (let j = 0; j < ny; j++) {
383
- const row = m.points.slice(j * nx, (j + 1) * nx);
384
- points.push(...row.slice(0, 3 * pi), ...splitCubic(row.slice(3 * pi, 3 * pi + 4), a), ...row.slice(3 * pi + 4));
385
- }
386
- const us = m.us.slice();
387
- us.splice(pi + 1, 0, Math.min(1, Math.max(0, s)));
388
- return { us, vs: m.vs.slice(), points };
389
- }
390
- function splitWarpMeshV(m, t) {
391
- const out = splitWarpMeshU(transposeMesh(m), t);
392
- return out && transposeMesh(out);
393
- }
394
- function removeWarpMeshSplitU(m, k) {
395
- if (k <= 0 || k + 1 >= m.us.length) return null;
396
- const a = (m.us[k] - m.us[k - 1]) / (m.us[k + 1] - m.us[k - 1]);
397
- const nx = warpMeshColumns(m);
398
- const ny = warpMeshRows(m);
399
- const c0 = 3 * (k - 1);
400
- const points = [];
401
- for (let j = 0; j < ny; j++) {
402
- const row = m.points.slice(j * nx, (j + 1) * nx);
403
- const [p0, q1, r2, p3] = [row[c0], row[c0 + 1], row[c0 + 5], row[c0 + 6]];
404
- const p1 = { x: (q1.x - (1 - a) * p0.x) / a, y: (q1.y - (1 - a) * p0.y) / a };
405
- const p2 = { x: (r2.x - a * p3.x) / (1 - a), y: (r2.y - a * p3.y) / (1 - a) };
406
- points.push(...row.slice(0, c0), p0, p1, p2, p3, ...row.slice(c0 + 7));
407
- }
408
- const us = m.us.slice();
409
- us.splice(k, 1);
410
- return { us, vs: m.vs.slice(), points };
411
- }
412
- function removeWarpMeshSplitV(m, k) {
413
- const out = removeWarpMeshSplitU(transposeMesh(m), k);
414
- return out && transposeMesh(out);
415
- }
416
- function mapWarpMeshPoints(m, f) {
417
- return { us: m.us.slice(), vs: m.vs.slice(), points: m.points.map((p) => f(p)) };
418
- }
419
- function resizeWarpMesh(m, columns, rows) {
420
- const cols = clampMeshCount(columns);
421
- const rws = clampMeshCount(rows);
422
- if (m.us.length - 1 === cols && m.vs.length - 1 === rws) return m;
423
- const us = evenKnots(cols);
424
- const vs = evenKnots(rws);
425
- const has = (list, v) => list.some((k) => Math.abs(k - v) < 1e-12);
426
- if (m.us.every((u) => has(us, u)) && m.vs.every((v) => has(vs, v))) {
427
- let out = m;
428
- for (const u of us) if (!has(out.us, u)) out = splitWarpMeshU(out, u) ?? out;
429
- for (const v of vs) if (!has(out.vs, v)) out = splitWarpMeshV(out, v) ?? out;
430
- return out;
431
- }
432
- return fitWarpMesh((s, t) => evalWarpMesh(m, s, t), us, vs);
433
- }
434
- function warpMeshControlBounds(m) {
435
- let minX = Infinity;
436
- let minY = Infinity;
437
- let maxX = -Infinity;
438
- let maxY = -Infinity;
439
- for (const p of m.points) {
440
- minX = Math.min(minX, p.x);
441
- minY = Math.min(minY, p.y);
442
- maxX = Math.max(maxX, p.x);
443
- maxY = Math.max(maxY, p.y);
444
- }
445
- return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
446
- }
447
- function warpMeshParamAt(m, p) {
448
- const n = 48;
449
- let best = { s: 0.5, t: 0.5, d: Infinity };
450
- for (let j = 0; j <= n; j++) {
451
- for (let i = 0; i <= n; i++) {
452
- const q2 = evalWarpMesh(m, i / n, j / n);
453
- const d = (q2.x - p.x) ** 2 + (q2.y - p.y) ** 2;
454
- if (d < best.d) best = { s: i / n, t: j / n, d };
455
- }
456
- }
457
- let { s, t } = best;
458
- for (let k = 0; k < 12; k++) {
459
- const h = 1e-5;
460
- const q2 = evalWarpMesh(m, s, t);
461
- const qs = evalWarpMesh(m, s + h, t);
462
- const qt = evalWarpMesh(m, s, t + h);
463
- const a = (qs.x - q2.x) / h;
464
- const b = (qt.x - q2.x) / h;
465
- const c = (qs.y - q2.y) / h;
466
- const d = (qt.y - q2.y) / h;
467
- const det = a * d - b * c;
468
- if (Math.abs(det) < 1e-12) break;
469
- const ex = p.x - q2.x;
470
- const ey = p.y - q2.y;
471
- s = Math.min(1, Math.max(0, s + (d * ex - b * ey) / det));
472
- t = Math.min(1, Math.max(0, t + (a * ey - c * ex) / det));
473
- }
474
- const q = evalWarpMesh(m, s, t);
475
- return { s, t, distance: Math.hypot(q.x - p.x, q.y - p.y) };
476
- }
477
- function smoothLines(m, i0, i1, j0, j1) {
478
- const nx = warpMeshColumns(m);
479
- i1 = Math.min(i1, nx);
480
- j1 = Math.min(j1, warpMeshRows(m));
481
- const triples = [];
482
- for (let a = 1; a < m.us.length - 1; a++) {
483
- if (3 * a >= i0 && 3 * a < i1)
484
- for (let j = j0; j < j1; j++) triples.push([j * nx + 3 * a - 1, j * nx + 3 * a, j * nx + 3 * a + 1, m.us[a] - m.us[a - 1], m.us[a + 1] - m.us[a]]);
485
- }
486
- for (let b = 1; b < m.vs.length - 1; b++) {
487
- if (3 * b >= j0 && 3 * b < j1)
488
- for (let i = i0; i < i1; i++) triples.push([(3 * b - 1) * nx + i, 3 * b * nx + i, (3 * b + 1) * nx + i, m.vs[b] - m.vs[b - 1], m.vs[b + 1] - m.vs[b]]);
489
- }
490
- for (const [l, c, r, hl, hr] of triples) {
491
- const pl = m.points[l];
492
- const pc = m.points[c];
493
- const pr = m.points[r];
494
- const tx = ((pc.x - pl.x) / hl + (pr.x - pc.x) / hr) / 2;
495
- const ty = ((pc.y - pl.y) / hl + (pr.y - pc.y) / hr) / 2;
496
- m.points[l] = { x: pc.x - tx * hl, y: pc.y - ty * hl };
497
- m.points[r] = { x: pc.x + tx * hr, y: pc.y + ty * hr };
498
- }
499
- }
500
- function dragWarpMeshPoint(base, index, d) {
501
- if (index < 0 || index >= base.points.length || !Number.isFinite(d.x) || !Number.isFinite(d.y)) return base;
502
- const out = { us: base.us.slice(), vs: base.vs.slice(), points: base.points.slice() };
503
- const nx = warpMeshColumns(base);
504
- const ny = warpMeshRows(base);
505
- const i = index % nx;
506
- const j = Math.floor(index / nx);
507
- const shift = (ii, jj, v) => {
508
- if (ii < 0 || jj < 0 || ii >= nx || jj >= ny) return;
509
- const p = out.points[jj * nx + ii];
510
- out.points[jj * nx + ii] = { x: p.x + v.x, y: p.y + v.y };
511
- };
512
- const span = (knots, k) => k > 0 && k + 1 < knots.length ? [knots[k] - knots[k - 1], knots[k + 1] - knots[k]] : null;
513
- const ri = i % 3;
514
- const rj = j % 3;
515
- if (ri === 0 && rj === 0) {
516
- for (let dj = -1; dj <= 1; dj++) for (let di = -1; di <= 1; di++) shift(i + di, j + dj, d);
517
- } else if (ri === 0) {
518
- for (let di = -1; di <= 1; di++) shift(i + di, j, d);
519
- const sp = span(base.vs, Math.floor(j / 3) + (rj === 2 ? 1 : 0));
520
- if (sp) {
521
- const [other, k] = rj === 1 ? [j - 2, sp[0] / sp[1]] : [j + 2, sp[1] / sp[0]];
522
- for (let di = -1; di <= 1; di++) shift(i + di, other, { x: -d.x * k, y: -d.y * k });
523
- }
524
- } else if (rj === 0) {
525
- for (let dj = -1; dj <= 1; dj++) shift(i, j + dj, d);
526
- const sp = span(base.us, Math.floor(i / 3) + (ri === 2 ? 1 : 0));
527
- if (sp) {
528
- const [other, k] = ri === 1 ? [i - 2, sp[0] / sp[1]] : [i + 2, sp[1] / sp[0]];
529
- for (let dj = -1; dj <= 1; dj++) shift(other, j + dj, { x: -d.x * k, y: -d.y * k });
530
- }
531
- } else shift(i, j, d);
532
- return out;
533
- }
534
- function pullWarpMesh(base, s, t, d) {
535
- const BORDER_ZONE = 0.12;
536
- const REACH = 1.8;
537
- if (!Number.isFinite(d.x) || !Number.isFinite(d.y)) return base;
538
- const m = { us: base.us.slice(), vs: base.vs.slice(), points: base.points.slice() };
539
- const cols = m.us.length - 1;
540
- const rows = m.vs.length - 1;
541
- const [pi, a] = locate(m.us, s);
542
- const [pj, b] = locate(m.vs, t);
543
- const ba = bernstein(a);
544
- const bb = bernstein(b);
545
- const nx = warpMeshColumns(m);
546
- const ny = warpMeshRows(m);
547
- const anchor = (ai, aj) => base.points[3 * aj * nx + 3 * ai] ?? { x: 0, y: 0 };
548
- const at0 = evalWarpMesh(base, s, t);
549
- const target = { x: at0.x + d.x, y: at0.y + d.y };
550
- let size = 1;
551
- for (const k of ["x", "y"]) {
552
- const vals = [anchor(pi, pj)[k], anchor(pi + 1, pj)[k], anchor(pi, pj + 1)[k], anchor(pi + 1, pj + 1)[k]];
553
- size = Math.max(size, Math.max(...vals) - Math.min(...vals));
554
- }
555
- const radius = REACH * size;
556
- const innerW = (ba[1] + ba[2]) * (bb[1] + bb[2]);
557
- const interior = Math.min(1, Math.max(0, innerW / 0.5625));
558
- const toBorder = Math.min(s, 1 - s, t, 1 - t);
559
- const nearBorder = Math.min(1, Math.max(0, 1 - toBorder / BORDER_ZONE));
560
- const meshCorner = (ai, aj) => (ai === 0 || ai === cols) && (aj === 0 || aj === rows);
561
- const onBorder = (ai, aj) => ai === 0 || ai === cols || aj === 0 || aj === rows;
562
- const reach = (ai, aj, wa, wb) => meshCorner(ai, aj) ? 0 : wa * wb * (onBorder(ai, aj) ? nearBorder : 1);
563
- const corner = [
564
- [pi, pj, reach(pi, pj, ba[0] + ba[1], bb[0] + bb[1])],
565
- [pi + 1, pj, reach(pi + 1, pj, ba[2] + ba[3], bb[0] + bb[1])],
566
- [pi, pj + 1, reach(pi, pj + 1, ba[0] + ba[1], bb[2] + bb[3])],
567
- [pi + 1, pj + 1, reach(pi + 1, pj + 1, ba[2] + ba[3], bb[2] + bb[3])]
568
- ];
569
- const share = new Array((cols + 1) * (rows + 1)).fill(0);
570
- for (let aj = 0; aj <= rows; aj++) {
571
- for (let ai = 0; ai <= cols; ai++) {
572
- const p = anchor(ai, aj);
573
- const x = Math.min(1, Math.max(0, Math.hypot(p.x - at0.x, p.y - at0.y) / radius));
574
- const fall = 0.5 * (1 + Math.cos(Math.PI * x));
575
- const edge = meshCorner(ai, aj) ? 0 : onBorder(ai, aj) ? nearBorder : 1;
576
- share[aj * (cols + 1) + ai] = fall * edge;
577
- }
578
- }
579
- for (const [ai, aj, w] of corner) share[aj * (cols + 1) + ai] = Math.max(share[aj * (cols + 1) + ai], (1 - interior) * w);
580
- const move = (idx, k, v) => {
581
- const p = m.points[idx];
582
- m.points[idx] = { x: p.x + v.x * k, y: p.y + v.y * k };
583
- };
584
- for (let j = 0; j < ny; j++) {
585
- for (let i = 0; i < nx; i++) {
586
- const ai = Math.min(cols, Math.floor((i + 1) / 3));
587
- const aj = Math.min(rows, Math.floor((j + 1) / 3));
588
- move(j * nx + i, share[aj * (cols + 1) + ai], d);
589
- }
590
- }
591
- let norm = 0;
592
- for (const j of [1, 2]) for (const i of [1, 2]) norm += (ba[i] * bb[j]) ** 2;
593
- const cornerNorm = corner.reduce((acc, c) => acc + c[2] * c[2], 0);
594
- const innerPart = cornerNorm > 1e-12 ? Math.min(1, innerW / 0.15) : 1;
595
- const edgeHandles = [];
596
- for (const k of [1, 2]) {
597
- if (pi === 0) edgeHandles.push([(3 * pj + k) * nx + 3 * pi, ba[0] * bb[k]]);
598
- if (pi + 1 === cols) edgeHandles.push([(3 * pj + k) * nx + 3 * pi + 3, ba[3] * bb[k]]);
599
- if (pj === 0) edgeHandles.push([3 * pj * nx + 3 * pi + k, ba[k] * bb[0]]);
600
- if (pj + 1 === rows) edgeHandles.push([(3 * pj + 3) * nx + 3 * pi + k, ba[k] * bb[3]]);
601
- }
602
- const edgeNorm = edgeHandles.reduce((acc, e) => acc + e[1] * e[1], 0);
603
- const edgePart = edgeNorm > 1e-12 ? nearBorder : 0;
604
- const innerShare = (1 - edgePart) * innerPart;
605
- const cornerShare = (1 - edgePart) * (1 - innerPart);
606
- for (let iter = 0; iter < 60; iter++) {
607
- const now = evalWarpMesh(m, s, t);
608
- const rem = { x: target.x - now.x, y: target.y - now.y };
609
- if (Math.hypot(rem.x, rem.y) < 1e-9) break;
610
- if (innerShare > 0 && norm > 0) for (const j of [1, 2]) for (const i of [1, 2]) move((3 * pj + j) * nx + 3 * pi + i, ba[i] * bb[j] / norm * innerShare, rem);
611
- if (edgePart > 0) for (const [idx, w] of edgeHandles) move(idx, w / edgeNorm * edgePart, rem);
612
- if (cornerShare > 0 && cornerNorm > 0) {
613
- for (const [ai, aj, w] of corner) {
614
- const k = w / cornerNorm * cornerShare;
615
- for (let dj = -1; dj <= 1; dj++) {
616
- for (let di = -1; di <= 1; di++) {
617
- const i = 3 * ai + di;
618
- const j = 3 * aj + dj;
619
- if (i >= 0 && j >= 0 && i < nx && j < ny) move(j * nx + i, k, rem);
620
- }
621
- }
622
- }
623
- }
624
- for (let k = 0; k < 3; k++) smoothLines(m, Math.max(0, 3 * pi - 3), 3 * pi + 7, Math.max(0, 3 * pj - 3), 3 * pj + 7);
625
- }
626
- return m;
627
- }
628
- function warpMeshEditPoints(m) {
629
- const nx = warpMeshColumns(m);
630
- const ny = warpMeshRows(m);
631
- const anchors = [];
632
- const handles = [];
633
- for (let j = 0; j < ny; j++) {
634
- for (let i = 0; i < nx; i++) {
635
- const ri = i % 3;
636
- const rj = j % 3;
637
- if (ri === 0 && rj === 0) anchors.push(j * nx + i);
638
- else if (ri === 0) handles.push({ index: j * nx + i, anchor: (rj === 1 ? j - 1 : j + 1) * nx + i });
639
- else if (rj === 0) handles.push({ index: j * nx + i, anchor: j * nx + (ri === 1 ? i - 1 : i + 1) });
640
- }
641
- }
642
- return { anchors, handles };
643
- }
644
- function warpMeshGridCurves(m) {
645
- const nx = warpMeshColumns(m);
646
- const ny = warpMeshRows(m);
647
- const pt = (i, j) => m.points[j * nx + i];
648
- const out = [];
649
- for (let j = 0; j < ny; j += 3) for (let i = 0; i + 3 < nx; i += 3) out.push([pt(i, j), pt(i + 1, j), pt(i + 2, j), pt(i + 3, j)]);
650
- for (let i = 0; i < nx; i += 3) for (let j = 0; j + 3 < ny; j += 3) out.push([pt(i, j), pt(i, j + 1), pt(i, j + 2), pt(i, j + 3)]);
651
- return out;
652
- }
653
-
654
- export {
655
- IDENTITY_MATRIX,
656
- multiplyMatrices,
657
- translateMatrix,
658
- scaleMatrix,
659
- rotateMatrix,
660
- matrixAbout,
661
- skewMatrix,
662
- applyMatrix,
663
- isIdentityMatrix,
664
- invertMatrix,
665
- applyMatrixLinear,
666
- matrixRotation,
667
- decomposeRigid,
668
- WARP_STYLES,
669
- WARP_STYLE_LABELS,
670
- warpPresetGrid,
671
- lerpVec2,
672
- warpPresetMesh,
673
- warpMeshColumns,
674
- warpMeshRows,
675
- isValidWarpMesh,
676
- fitWarpMesh,
677
- evenKnots,
678
- clampMeshCount,
679
- identityWarpMesh,
680
- evalWarpMesh,
681
- splitWarpMeshU,
682
- splitWarpMeshV,
683
- removeWarpMeshSplitU,
684
- removeWarpMeshSplitV,
685
- mapWarpMeshPoints,
686
- resizeWarpMesh,
687
- warpMeshControlBounds,
688
- warpMeshParamAt,
689
- dragWarpMeshPoint,
690
- pullWarpMesh,
691
- warpMeshEditPoints,
692
- warpMeshGridCurves
693
- };
694
- //# sourceMappingURL=chunk-KKREERP2.js.map