@algorisys/tinyfly 0.86.2 → 0.88.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.
- package/README.md +7 -4
- package/bin/tinyfly.mjs +44 -6
- package/lib/addons/adapters.js +389 -281
- package/lib/addons/characters.js +3 -3
- package/lib/addons/load-scene-CQvcFWGJ.js +331 -0
- package/lib/addons/maps.js +1 -1
- package/lib/addons/scene-3d-webgl.js +52 -49
- package/lib/addons/scene-3d.js +299 -215
- package/lib/addons/shading-o5T_v9DT.js +89 -0
- package/lib/addons/{sketch-CA8ZXhxI.js → sketch-CYPUbk3Q.js} +2 -2
- package/lib/browser/tinyfly-scene-3d-webgl.iife.js +4 -2
- package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
- package/lib/browser/tinyfly.iife.js +4 -4
- package/lib/browser/tinyfly.js +2204 -2043
- package/lib/browser/tinyfly.umd.js +4 -4
- package/lib/engine/tinyfly-engine.js +149 -106
- package/lib/engine/tinyfly-engine.umd.cjs +2 -2
- package/lib/headless/headless.js +165 -18
- package/lib/types/adapters/canvas/bloom.d.ts +33 -0
- package/lib/types/adapters/canvas/index.d.ts +3 -0
- package/lib/types/adapters/canvas/offscreen.d.ts +13 -0
- package/lib/types/adapters/canvas/trail.d.ts +57 -0
- package/lib/types/browser/index.d.ts +4 -0
- package/lib/types/engine/path/index.d.ts +2 -0
- package/lib/types/engine/path/trail.d.ts +79 -0
- package/lib/types/headless/index.d.ts +1 -0
- package/lib/types/headless/loop-check.d.ts +41 -0
- package/lib/types/headless/node-video.d.ts +8 -0
- package/lib/types/headless/video-scene.d.ts +9 -1
- package/lib/types/scene-3d/resolve-scene.d.ts +6 -0
- package/lib/types/scene-3d/scene-3d-adapter.d.ts +9 -1
- package/lib/types/scene-3d/scene-types.d.ts +42 -2
- package/lib/types/scene-3d/strokes.d.ts +30 -0
- package/lib/types/scene-3d/webgl/gl-data.d.ts +1 -0
- package/lib/types/scene-3d/webgl/shaders.d.ts +1 -1
- package/package.json +1 -1
- package/lib/addons/load-scene-vp14_Jj-.js +0 -324
- package/lib/addons/shading-ByG9UXd0.js +0 -85
package/lib/addons/adapters.js
CHANGED
|
@@ -1,118 +1,115 @@
|
|
|
1
|
-
import { h as
|
|
2
|
-
import { D as
|
|
3
|
-
import { createTrack as
|
|
4
|
-
import { p as
|
|
5
|
-
import {
|
|
6
|
-
function
|
|
1
|
+
import { h as U, e as _, i as O, a as W, b as N, p as H, t as V, g as z, c as B, q, F as j, s as Z, d as J } from "./dom-adapter-Cphr2HZn.js";
|
|
2
|
+
import { D as Ce } from "./dom-adapter-Cphr2HZn.js";
|
|
3
|
+
import { createTrack as Q, parsePath as L, ribbon as K, ribbonHeadCap as ee, mat4 as b } from "@algorisys/tinyfly";
|
|
4
|
+
import { p as te, s as ie } from "./sketch-CYPUbk3Q.js";
|
|
5
|
+
import { c as Ie, a as Ye, b as _e } from "./sketch-CYPUbk3Q.js";
|
|
6
|
+
function oe(n) {
|
|
7
7
|
const e = /* @__PURE__ */ new Map();
|
|
8
|
-
for (const { name: t, element: i } of
|
|
9
|
-
e.set(t,
|
|
8
|
+
for (const { name: t, element: i } of n)
|
|
9
|
+
e.set(t, F(i));
|
|
10
10
|
return { measurements: e };
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
const i = t.duration ?? 600,
|
|
12
|
+
function se(n, e, t = {}) {
|
|
13
|
+
const i = t.duration ?? 600, o = t.easing ?? "ease-out", s = t.scale !== !1, a = t.idPrefix ?? "flip", r = [];
|
|
14
14
|
for (const { name: c, element: l } of e) {
|
|
15
|
-
const h =
|
|
15
|
+
const h = n.measurements.get(c);
|
|
16
16
|
if (!h) continue;
|
|
17
|
-
const f =
|
|
18
|
-
if ((
|
|
19
|
-
T(`${a}-${c}-x`, c, "x",
|
|
20
|
-
T(`${a}-${c}-y`, c, "y", u, 0, i,
|
|
21
|
-
),
|
|
22
|
-
const
|
|
23
|
-
|
|
17
|
+
const f = F(l), m = h.left + h.width / 2 - (f.left + f.width / 2), u = h.top + h.height / 2 - (f.top + f.height / 2);
|
|
18
|
+
if ((m !== 0 || u !== 0) && r.push(
|
|
19
|
+
T(`${a}-${c}-x`, c, "x", m, 0, i, o),
|
|
20
|
+
T(`${a}-${c}-y`, c, "y", u, 0, i, o)
|
|
21
|
+
), s && f.width > 0 && f.height > 0) {
|
|
22
|
+
const p = h.width / f.width, d = h.height / f.height;
|
|
23
|
+
p !== 1 && r.push(T(`${a}-${c}-sx`, c, "scaleX", p, 1, i, o)), d !== 1 && r.push(T(`${a}-${c}-sy`, c, "scaleY", d, 1, i, o));
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
return
|
|
26
|
+
return r;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
const i =
|
|
30
|
-
return e(),
|
|
28
|
+
function Me(n, e, t = {}) {
|
|
29
|
+
const i = oe(n);
|
|
30
|
+
return e(), se(i, n, t);
|
|
31
31
|
}
|
|
32
|
-
function T(
|
|
33
|
-
return
|
|
34
|
-
id:
|
|
32
|
+
function T(n, e, t, i, o, s, a) {
|
|
33
|
+
return Q({
|
|
34
|
+
id: n,
|
|
35
35
|
target: e,
|
|
36
36
|
property: t,
|
|
37
37
|
keyframes: [
|
|
38
38
|
{ time: 0, value: i },
|
|
39
|
-
{ time:
|
|
39
|
+
{ time: s, value: o, easing: a }
|
|
40
40
|
]
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
const e =
|
|
43
|
+
function F(n) {
|
|
44
|
+
const e = n;
|
|
45
45
|
if (typeof e.getBoundingClientRect != "function")
|
|
46
46
|
return { left: 0, top: 0, width: 0, height: 0 };
|
|
47
47
|
const t = e.getBoundingClientRect();
|
|
48
48
|
return { left: t.left, top: t.top, width: t.width, height: t.height };
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
const i = t.highlight ?? "#ffffff",
|
|
52
|
-
{ offset:
|
|
53
|
-
{ offset:
|
|
54
|
-
{ offset:
|
|
50
|
+
function G(n, e, t = {}) {
|
|
51
|
+
const i = t.highlight ?? "#ffffff", o = t.halfWidth ?? 0.12, s = -0.2 + n * 1.4, a = [{ offset: 0, color: e }], r = [
|
|
52
|
+
{ offset: s - o, color: e },
|
|
53
|
+
{ offset: s, color: i },
|
|
54
|
+
{ offset: s + o, color: e }
|
|
55
55
|
];
|
|
56
|
-
for (const c of
|
|
56
|
+
for (const c of r)
|
|
57
57
|
c.offset > 0 && c.offset < 1 && a.push(c);
|
|
58
58
|
return a.push({ offset: 1, color: e }), a.sort((c, l) => c.offset - l.offset), a;
|
|
59
59
|
}
|
|
60
|
-
const
|
|
61
|
-
function
|
|
60
|
+
const k = 12;
|
|
61
|
+
function x(n) {
|
|
62
62
|
const e = [];
|
|
63
63
|
let t, i = -1;
|
|
64
|
-
for (const
|
|
65
|
-
if (
|
|
66
|
-
(!t || i !==
|
|
64
|
+
for (const o of L(n).segments) {
|
|
65
|
+
if (o.type === "L") {
|
|
66
|
+
(!t || i !== o.subpath) && (t = { kind: "line", points: [{ x: o.startX, y: o.startY }], length: 0 }, i = o.subpath, e.push(t)), t.points.push({ x: o.endX, y: o.endY }), t.length += o.length;
|
|
67
67
|
continue;
|
|
68
68
|
}
|
|
69
69
|
t = void 0;
|
|
70
|
-
const [
|
|
71
|
-
for (let
|
|
72
|
-
const u =
|
|
70
|
+
const [s, a, r, c, l, h] = o.points, f = [];
|
|
71
|
+
for (let m = 0; m <= k; m++) {
|
|
72
|
+
const u = m / k, p = 1 - u;
|
|
73
73
|
f.push({
|
|
74
|
-
x:
|
|
75
|
-
y:
|
|
74
|
+
x: p * p * p * o.startX + 3 * p * p * u * s + 3 * p * u * u * r + u * u * u * l,
|
|
75
|
+
y: p * p * p * o.startY + 3 * p * p * u * a + 3 * p * u * u * c + u * u * u * h
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
e.push({ kind: "curve", points: f, length:
|
|
78
|
+
e.push({ kind: "curve", points: f, length: o.length });
|
|
79
79
|
}
|
|
80
80
|
return e;
|
|
81
81
|
}
|
|
82
|
-
function
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
85
|
-
const a =
|
|
86
|
-
return
|
|
87
|
-
`M${
|
|
82
|
+
function ne(n, e, t, i, o = 0) {
|
|
83
|
+
const s = Math.max(0, Math.min(o, t / 2, i / 2));
|
|
84
|
+
if (s === 0) return x(`M${n},${e} H${n + t} V${e + i} H${n} Z`);
|
|
85
|
+
const a = n + t, r = e + i;
|
|
86
|
+
return x(
|
|
87
|
+
`M${n + s},${e} H${a - s} A${s},${s} 0 0 1 ${a},${e + s} V${r - s} A${s},${s} 0 0 1 ${a - s},${r} H${n + s} A${s},${s} 0 0 1 ${n},${r - s} V${e + s} A${s},${s} 0 0 1 ${n + s},${e} Z`
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
|
-
function
|
|
91
|
-
const
|
|
90
|
+
function M(n, e, t, i) {
|
|
91
|
+
const s = e.reduce((r, c) => r + c.length, 0) * Math.min(1, Math.max(0, t));
|
|
92
92
|
let a = 0;
|
|
93
|
-
i ||
|
|
94
|
-
for (const
|
|
95
|
-
const c =
|
|
96
|
-
if (a +=
|
|
97
|
-
|
|
93
|
+
i || n.beginPath();
|
|
94
|
+
for (const r of e) {
|
|
95
|
+
const c = r.length === 0 ? s >= a ? 1 : 0 : Math.min(1, Math.max(0, (s - a) / r.length));
|
|
96
|
+
if (a += r.length, i) {
|
|
97
|
+
r.kind === "curve" ? i.curve(r.points, c) : i.line(r.points, c);
|
|
98
98
|
continue;
|
|
99
99
|
}
|
|
100
100
|
if (c <= 0) continue;
|
|
101
|
-
const l =
|
|
102
|
-
|
|
103
|
-
for (const h of l.slice(1))
|
|
101
|
+
const l = te(r.points, c);
|
|
102
|
+
n.moveTo(l[0].x, l[0].y);
|
|
103
|
+
for (const h of l.slice(1)) n.lineTo(h.x, h.y);
|
|
104
104
|
}
|
|
105
|
-
i ||
|
|
105
|
+
i || n.stroke();
|
|
106
106
|
}
|
|
107
|
-
function
|
|
108
|
-
return typeof r == "object" && r !== null && "type" in r;
|
|
109
|
-
}
|
|
110
|
-
function ee(r, e, t) {
|
|
107
|
+
function g(n, e, t) {
|
|
111
108
|
if (typeof OffscreenCanvas < "u") return new OffscreenCanvas(e, t);
|
|
112
|
-
const i =
|
|
109
|
+
const i = n.canvas;
|
|
113
110
|
if (i?.ownerDocument) {
|
|
114
|
-
const
|
|
115
|
-
return
|
|
111
|
+
const o = i.ownerDocument.createElement("canvas");
|
|
112
|
+
return o.width = e, o.height = t, o;
|
|
116
113
|
}
|
|
117
114
|
try {
|
|
118
115
|
return i?.constructor ? new i.constructor(e, t) : null;
|
|
@@ -120,7 +117,10 @@ function ee(r, e, t) {
|
|
|
120
117
|
return null;
|
|
121
118
|
}
|
|
122
119
|
}
|
|
123
|
-
|
|
120
|
+
function Se(n) {
|
|
121
|
+
return typeof n == "object" && n !== null && "type" in n;
|
|
122
|
+
}
|
|
123
|
+
class R {
|
|
124
124
|
targets = /* @__PURE__ */ new Map();
|
|
125
125
|
targetOrder = [];
|
|
126
126
|
// Store animation offsets separately - these are applied via ctx.translate() during rendering
|
|
@@ -181,19 +181,19 @@ class x {
|
|
|
181
181
|
applyState(e) {
|
|
182
182
|
this.time = e.currentTime;
|
|
183
183
|
for (const [t, i] of e.values) {
|
|
184
|
-
const
|
|
185
|
-
if (!
|
|
186
|
-
const
|
|
187
|
-
for (const [
|
|
188
|
-
if (
|
|
189
|
-
|
|
190
|
-
else if (
|
|
191
|
-
|
|
184
|
+
const o = this.targets.get(t);
|
|
185
|
+
if (!o) continue;
|
|
186
|
+
const s = this.aliases.get(t) ?? t, a = this.animationOffsets.get(s) ?? { x: 0, y: 0 };
|
|
187
|
+
for (const [r, c] of i)
|
|
188
|
+
if (R.OFFSET_PROPERTIES.has(r) && typeof c == "number")
|
|
189
|
+
r === "x" || r === "motionPathX" ? a.x = c : (r === "y" || r === "motionPathY") && (a.y = c);
|
|
190
|
+
else if (o.type === "custom" && o.props && (r in o.props || o.acceptsProp?.(r)))
|
|
191
|
+
o.props[r] = c;
|
|
192
192
|
else {
|
|
193
|
-
const l =
|
|
194
|
-
|
|
193
|
+
const l = R.PROPERTY_MAP[r] ?? r;
|
|
194
|
+
o[l] = c;
|
|
195
195
|
}
|
|
196
|
-
this.animationOffsets.set(
|
|
196
|
+
this.animationOffsets.set(s, a);
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
/**
|
|
@@ -210,32 +210,32 @@ class x {
|
|
|
210
210
|
for (const t of this.targetOrder) {
|
|
211
211
|
const i = this.targets.get(t);
|
|
212
212
|
if (!i) continue;
|
|
213
|
-
const
|
|
214
|
-
this.renderTarget(e, i,
|
|
213
|
+
const o = this.animationOffsets.get(t) ?? { x: 0, y: 0 };
|
|
214
|
+
this.renderTarget(e, i, o);
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
218
|
* Render a single target.
|
|
219
219
|
*/
|
|
220
220
|
renderTarget(e, t, i) {
|
|
221
|
-
if (e.save(), t.opacity !== void 0 && (e.globalAlpha = t.opacity),
|
|
222
|
-
const
|
|
223
|
-
if (t.backfaceVisibility === "hidden" &&
|
|
221
|
+
if (e.save(), t.opacity !== void 0 && (e.globalAlpha = t.opacity), U(t)) {
|
|
222
|
+
const s = _(t, i, { x: this.getPivotX(t), y: this.getPivotY(t) });
|
|
223
|
+
if (t.backfaceVisibility === "hidden" && O(s)) {
|
|
224
224
|
e.restore();
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
227
|
-
|
|
227
|
+
W(s) ? (e.transform(...N(s)), this.drawContent(e, t)) : this.drawInPerspective(e, t, s), e.restore();
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
230
230
|
if ((i.x !== 0 || i.y !== 0) && e.translate(i.x, i.y), t.rotate !== void 0 || t.rotateX !== void 0 || t.rotateY !== void 0 || t.scale !== void 0 || t.scaleX !== void 0 || t.scaleY !== void 0 || t.skewX !== void 0 || t.skewY !== void 0) {
|
|
231
|
-
const
|
|
232
|
-
e.translate(
|
|
233
|
-
let
|
|
234
|
-
if (t.rotateX !== void 0 && (c *= Math.cos(t.rotateX * Math.PI / 180)), t.rotateY !== void 0 && (
|
|
231
|
+
const s = this.getPivotX(t), a = this.getPivotY(t);
|
|
232
|
+
e.translate(s, a), t.rotate !== void 0 && e.rotate(t.rotate * Math.PI / 180);
|
|
233
|
+
let r = t.scaleX ?? 1, c = t.scaleY ?? 1;
|
|
234
|
+
if (t.rotateX !== void 0 && (c *= Math.cos(t.rotateX * Math.PI / 180)), t.rotateY !== void 0 && (r *= Math.cos(t.rotateY * Math.PI / 180)), t.scale !== void 0 ? e.scale(t.scale, t.scale) : (r !== 1 || c !== 1) && e.scale(r, c), t.skewX !== void 0 || t.skewY !== void 0) {
|
|
235
235
|
const l = (t.skewX ?? 0) * Math.PI / 180, h = (t.skewY ?? 0) * Math.PI / 180;
|
|
236
236
|
e.transform(1, Math.tan(h), Math.tan(l), 1, 0, 0);
|
|
237
237
|
}
|
|
238
|
-
e.translate(-
|
|
238
|
+
e.translate(-s, -a);
|
|
239
239
|
}
|
|
240
240
|
this.drawContent(e, t), e.restore();
|
|
241
241
|
}
|
|
@@ -245,20 +245,20 @@ class x {
|
|
|
245
245
|
* there. The triangles overlap by a pixel so no anti-aliased seam shows.
|
|
246
246
|
*/
|
|
247
247
|
drawInPerspective(e, t, i) {
|
|
248
|
-
const
|
|
249
|
-
if (
|
|
250
|
-
|
|
248
|
+
const s = e.globalAlpha < 1 ? this.perspectiveLayer(e) : null;
|
|
249
|
+
if (s) {
|
|
250
|
+
s.ctx.setTransform(e.getTransform()), this.drawMesh(s.ctx, t, i), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(s.canvas, 0, 0), e.restore();
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
253
253
|
this.drawMesh(e, t, i);
|
|
254
254
|
}
|
|
255
255
|
drawMesh(e, t, i) {
|
|
256
|
-
const
|
|
257
|
-
for (const
|
|
258
|
-
const a =
|
|
256
|
+
const o = this.contentBounds(e, t);
|
|
257
|
+
for (const s of H(i, o)) {
|
|
258
|
+
const a = V(s.source, s.target);
|
|
259
259
|
if (!a) continue;
|
|
260
|
-
const [
|
|
261
|
-
e.save(), e.beginPath(), e.moveTo(
|
|
260
|
+
const [r, c, l] = z(s.target, 1);
|
|
261
|
+
e.save(), e.beginPath(), e.moveTo(r.x, r.y), e.lineTo(c.x, c.y), e.lineTo(l.x, l.y), e.closePath(), e.clip(), e.transform(...a), this.drawContent(e, t), e.restore();
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
/** A cleared offscreen canvas the size of `ctx`'s, reused frame to frame; null where none can be made. */
|
|
@@ -266,11 +266,11 @@ class x {
|
|
|
266
266
|
const t = e.canvas?.width ?? 0, i = e.canvas?.height ?? 0;
|
|
267
267
|
if (!(t > 0 && i > 0)) return null;
|
|
268
268
|
if (!this.layer || this.layer.width !== t || this.layer.height !== i) {
|
|
269
|
-
const
|
|
270
|
-
if (this.layer =
|
|
269
|
+
const s = g(e, t, i), a = s?.getContext("2d");
|
|
270
|
+
if (this.layer = s && a ? { canvas: s, ctx: a, width: t, height: i } : null, !this.layer) return null;
|
|
271
271
|
}
|
|
272
|
-
const
|
|
273
|
-
return
|
|
272
|
+
const o = this.layer.ctx;
|
|
273
|
+
return o.setTransform(1, 0, 0, 1, 0, 0), o.globalAlpha = 1, o.clearRect(0, 0, t, i), this.layer;
|
|
274
274
|
}
|
|
275
275
|
/**
|
|
276
276
|
* Everything a target paints, generously: its box, measured text, a path's
|
|
@@ -280,26 +280,26 @@ class x {
|
|
|
280
280
|
contentBounds(e, t) {
|
|
281
281
|
let i = this.getTargetBounds(t);
|
|
282
282
|
if (t.type === "text") {
|
|
283
|
-
const
|
|
284
|
-
e.save(), e.font = `${t.fontWeight ?? 400} ${
|
|
283
|
+
const s = t.fontSize ?? 16;
|
|
284
|
+
e.save(), e.font = `${t.fontWeight ?? 400} ${s}px ${t.fontFamily ?? "sans-serif"}`;
|
|
285
285
|
const a = e.measureText(t.text).width;
|
|
286
286
|
e.restore();
|
|
287
|
-
const
|
|
288
|
-
i = { x: c, y: l, width: a, height:
|
|
287
|
+
const r = t.textAlign ?? "left", c = r === "center" ? t.x - a / 2 : r === "right" ? t.x - a : t.x, l = (t.textBaseline ?? "top") === "top" ? t.y : t.y - s;
|
|
288
|
+
i = { x: c, y: l, width: a, height: s * 1.4 };
|
|
289
289
|
} else if (t.type === "path") {
|
|
290
|
-
const
|
|
291
|
-
for (const
|
|
292
|
-
|
|
293
|
-
for (let c = 0; c + 1 <
|
|
294
|
-
|
|
290
|
+
const s = [], a = [];
|
|
291
|
+
for (const r of L(t.d).segments) {
|
|
292
|
+
s.push(r.startX, r.endX), a.push(r.startY, r.endY);
|
|
293
|
+
for (let c = 0; c + 1 < r.points.length; c += 2)
|
|
294
|
+
s.push(r.points[c]), a.push(r.points[c + 1]);
|
|
295
295
|
}
|
|
296
|
-
if (
|
|
297
|
-
const
|
|
298
|
-
i = { x: t.x +
|
|
296
|
+
if (s.length > 0) {
|
|
297
|
+
const r = Math.min(...s), c = Math.min(...a);
|
|
298
|
+
i = { x: t.x + r, y: t.y + c, width: Math.max(...s) - r, height: Math.max(...a) - c };
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
|
-
const
|
|
302
|
-
return { x: i.x -
|
|
301
|
+
const o = (t.lineWidth ?? 1) + 2 + 3 * Math.max(t.blur ?? 0, t.glow ?? 0, t.shadowBlur ?? 0) + Math.max(Math.abs(t.shadowX ?? 0), Math.abs(t.shadowY ?? 0));
|
|
302
|
+
return { x: i.x - o, y: i.y - o, width: i.width + 2 * o, height: i.height + 2 * o };
|
|
303
303
|
}
|
|
304
304
|
/**
|
|
305
305
|
* Paint a target in the current transform: its fill and stroke styles,
|
|
@@ -307,10 +307,10 @@ class x {
|
|
|
307
307
|
*/
|
|
308
308
|
drawContent(e, t) {
|
|
309
309
|
t.fillStyle && (e.fillStyle = this.resolveFillStyle(e, t)), t.strokeStyle && (e.strokeStyle = t.strokeStyle), t.lineWidth !== void 0 && (e.lineWidth = t.lineWidth);
|
|
310
|
-
const i =
|
|
310
|
+
const i = B(t);
|
|
311
311
|
if (i && (e.filter = i), t.clipTop !== void 0 || t.clipRight !== void 0 || t.clipBottom !== void 0 || t.clipLeft !== void 0) {
|
|
312
|
-
const
|
|
313
|
-
e.beginPath(), e.rect(
|
|
312
|
+
const o = this.getTargetBounds(t), s = o.x + (t.clipLeft ?? 0) / 100 * o.width, a = o.x + o.width - (t.clipRight ?? 0) / 100 * o.width, r = o.y + (t.clipTop ?? 0) / 100 * o.height, c = o.y + o.height - (t.clipBottom ?? 0) / 100 * o.height;
|
|
313
|
+
e.beginPath(), e.rect(s, r, Math.max(0, a - s), Math.max(0, c - r)), e.clip();
|
|
314
314
|
}
|
|
315
315
|
switch (t.type) {
|
|
316
316
|
case "rect":
|
|
@@ -343,26 +343,26 @@ class x {
|
|
|
343
343
|
const i = t.fillStyle;
|
|
344
344
|
if (!i) return "transparent";
|
|
345
345
|
if (typeof i == "string") return i;
|
|
346
|
-
const
|
|
347
|
-
return i.type === "linear" ? this.createLinearGradient(e, i,
|
|
346
|
+
const o = this.getTargetBounds(t);
|
|
347
|
+
return i.type === "linear" ? this.createLinearGradient(e, i, o) : this.createRadialGradient(e, i, o);
|
|
348
348
|
}
|
|
349
349
|
/**
|
|
350
350
|
* Create a canvas linear gradient from a LinearGradient definition.
|
|
351
351
|
*/
|
|
352
352
|
createLinearGradient(e, t, i) {
|
|
353
|
-
const
|
|
353
|
+
const o = (t.angle - 90) * (Math.PI / 180), s = i.x + i.width / 2, a = i.y + i.height / 2, r = Math.max(i.width, i.height), c = s - Math.cos(o) * r / 2, l = a - Math.sin(o) * r / 2, h = s + Math.cos(o) * r / 2, f = a + Math.sin(o) * r / 2, m = e.createLinearGradient(c, l, h, f);
|
|
354
354
|
for (const u of t.stops)
|
|
355
|
-
|
|
356
|
-
return
|
|
355
|
+
m.addColorStop(u.offset, u.color);
|
|
356
|
+
return m;
|
|
357
357
|
}
|
|
358
358
|
/**
|
|
359
359
|
* Create a canvas radial gradient from a RadialGradient definition.
|
|
360
360
|
*/
|
|
361
361
|
createRadialGradient(e, t, i) {
|
|
362
|
-
const
|
|
362
|
+
const o = i.x + i.width * t.centerX, s = i.y + i.height * t.centerY, a = Math.max(i.width, i.height) * t.radius, r = e.createRadialGradient(o, s, 0, o, s, a);
|
|
363
363
|
for (const c of t.stops)
|
|
364
|
-
|
|
365
|
-
return
|
|
364
|
+
r.addColorStop(c.offset, c.color);
|
|
365
|
+
return r;
|
|
366
366
|
}
|
|
367
367
|
/**
|
|
368
368
|
* Get target bounding box for gradient calculations.
|
|
@@ -401,25 +401,25 @@ class x {
|
|
|
401
401
|
* Draw a shape outline-first: the fill (clean) once the outline is complete,
|
|
402
402
|
* then the outline up to `drawOn`, in pencil strokes when sketched.
|
|
403
403
|
*/
|
|
404
|
-
renderOutlined(e, t, i,
|
|
405
|
-
const
|
|
406
|
-
if (i && t.fillStyle &&
|
|
407
|
-
const a = t.sketch ?
|
|
408
|
-
a && (e.lineCap = t.lineCap ?? "round", e.lineJoin = t.lineJoin ?? "round"), s
|
|
404
|
+
renderOutlined(e, t, i, o) {
|
|
405
|
+
const s = Math.min(1, Math.max(0, t.drawOn ?? 1));
|
|
406
|
+
if (i && t.fillStyle && s >= 1 && i(), !t.strokeStyle || s <= 0) return;
|
|
407
|
+
const a = t.sketch ? ie(e, t.sketch, this.time) : void 0;
|
|
408
|
+
a && (e.lineCap = t.lineCap ?? "round", e.lineJoin = t.lineJoin ?? "round"), o(s, a);
|
|
409
409
|
}
|
|
410
410
|
/**
|
|
411
411
|
* Render a rectangle.
|
|
412
412
|
*/
|
|
413
413
|
renderRect(e, t) {
|
|
414
414
|
if (this.drawsOutline(t)) {
|
|
415
|
-
const { x: i, y:
|
|
415
|
+
const { x: i, y: o, width: s, height: a } = t;
|
|
416
416
|
return this.renderOutlined(
|
|
417
417
|
e,
|
|
418
418
|
t,
|
|
419
419
|
() => {
|
|
420
|
-
e.beginPath(), t.borderRadius && t.borderRadius > 0 ? this.roundRect(e, i,
|
|
420
|
+
e.beginPath(), t.borderRadius && t.borderRadius > 0 ? this.roundRect(e, i, o, s, a, t.borderRadius) : e.rect(i, o, s, a), e.fill();
|
|
421
421
|
},
|
|
422
|
-
(
|
|
422
|
+
(r, c) => M(e, ne(i, o, s, a, t.borderRadius), r, c)
|
|
423
423
|
);
|
|
424
424
|
}
|
|
425
425
|
e.beginPath(), t.borderRadius && t.borderRadius > 0 ? this.roundRect(e, t.x, t.y, t.width, t.height, t.borderRadius) : e.rect(t.x, t.y, t.width, t.height), t.fillStyle && e.fill(), t.strokeStyle && e.stroke(), e.closePath();
|
|
@@ -427,25 +427,25 @@ class x {
|
|
|
427
427
|
/**
|
|
428
428
|
* Draw a rounded rectangle path.
|
|
429
429
|
*/
|
|
430
|
-
roundRect(e, t, i,
|
|
431
|
-
const
|
|
432
|
-
e.moveTo(t +
|
|
430
|
+
roundRect(e, t, i, o, s, a) {
|
|
431
|
+
const r = Math.min(a, o / 2, s / 2);
|
|
432
|
+
e.moveTo(t + r, i), e.lineTo(t + o - r, i), e.arcTo(t + o, i, t + o, i + r, r), e.lineTo(t + o, i + s - r), e.arcTo(t + o, i + s, t + o - r, i + s, r), e.lineTo(t + r, i + s), e.arcTo(t, i + s, t, i + s - r, r), e.lineTo(t, i + r), e.arcTo(t, i, t + r, i, r);
|
|
433
433
|
}
|
|
434
434
|
/**
|
|
435
435
|
* Render a circle.
|
|
436
436
|
*/
|
|
437
437
|
renderCircle(e, t) {
|
|
438
438
|
if (this.drawsOutline(t)) {
|
|
439
|
-
const { x: i, y:
|
|
439
|
+
const { x: i, y: o, radius: s } = t;
|
|
440
440
|
return this.renderOutlined(
|
|
441
441
|
e,
|
|
442
442
|
t,
|
|
443
443
|
() => {
|
|
444
|
-
e.beginPath(), e.arc(i,
|
|
444
|
+
e.beginPath(), e.arc(i, o, s, 0, Math.PI * 2), e.fill();
|
|
445
445
|
},
|
|
446
|
-
(a,
|
|
447
|
-
if (
|
|
448
|
-
e.beginPath(), e.arc(i,
|
|
446
|
+
(a, r) => {
|
|
447
|
+
if (r) return r.circle(i, o, s, a);
|
|
448
|
+
e.beginPath(), e.arc(i, o, s, -Math.PI / 2, -Math.PI / 2 + Math.PI * 2 * a), e.stroke();
|
|
449
449
|
}
|
|
450
450
|
);
|
|
451
451
|
}
|
|
@@ -455,11 +455,11 @@ class x {
|
|
|
455
455
|
* Render text.
|
|
456
456
|
*/
|
|
457
457
|
renderText(e, t) {
|
|
458
|
-
const i = t.fontSize ?? 16,
|
|
459
|
-
if (e.font = `${
|
|
458
|
+
const i = t.fontSize ?? 16, o = t.fontFamily ?? "sans-serif", s = t.fontWeight ?? 400;
|
|
459
|
+
if (e.font = `${s} ${i}px ${o}`, e.textAlign = t.textAlign ?? "left", e.textBaseline = t.textBaseline ?? "top", t.fillStyle) {
|
|
460
460
|
if (t.shine !== void 0 && typeof t.fillStyle == "string") {
|
|
461
|
-
const a = e.measureText(t.text).width,
|
|
462
|
-
for (const h of
|
|
461
|
+
const a = e.measureText(t.text).width, r = t.textAlign ?? "left", c = r === "center" ? t.x - a / 2 : r === "right" ? t.x - a : t.x, l = e.createLinearGradient(c, t.y, c + a, t.y);
|
|
462
|
+
for (const h of G(t.shine, t.fillStyle))
|
|
463
463
|
l.addColorStop(h.offset, h.color);
|
|
464
464
|
e.fillStyle = l;
|
|
465
465
|
}
|
|
@@ -475,12 +475,12 @@ class x {
|
|
|
475
475
|
const i = [
|
|
476
476
|
{ x: t.x, y: t.y },
|
|
477
477
|
{ x: t.x2, y: t.y2 }
|
|
478
|
-
],
|
|
478
|
+
], o = Math.hypot(t.x2 - t.x, t.y2 - t.y);
|
|
479
479
|
return this.renderOutlined(
|
|
480
480
|
e,
|
|
481
481
|
t,
|
|
482
482
|
void 0,
|
|
483
|
-
(
|
|
483
|
+
(s, a) => M(e, [{ kind: "line", points: i, length: o }], s, a)
|
|
484
484
|
);
|
|
485
485
|
}
|
|
486
486
|
e.beginPath(), e.moveTo(t.x, t.y), e.lineTo(t.x2, t.y2), t.strokeStyle && e.stroke(), e.closePath();
|
|
@@ -496,7 +496,7 @@ class x {
|
|
|
496
496
|
e,
|
|
497
497
|
t,
|
|
498
498
|
() => e.fill(i),
|
|
499
|
-
(
|
|
499
|
+
(o, s) => M(e, x(t.d), o, s)
|
|
500
500
|
);
|
|
501
501
|
t.fillStyle && e.fill(i), t.strokeStyle && e.stroke(i);
|
|
502
502
|
}
|
|
@@ -506,13 +506,13 @@ class x {
|
|
|
506
506
|
renderImage(e, t) {
|
|
507
507
|
if (!t.image) return;
|
|
508
508
|
t.opacity !== void 0 && (e.globalAlpha = t.opacity);
|
|
509
|
-
const { x: i, y:
|
|
510
|
-
let
|
|
511
|
-
if (
|
|
512
|
-
const
|
|
513
|
-
|
|
509
|
+
const { x: i, y: o, width: s, height: a } = t, r = t.objectFit ?? "fill", c = t.borderRadius ?? 0, l = t.image, h = l.naturalWidth || l.videoWidth || l.width || s, f = l.naturalHeight || l.videoHeight || l.height || a;
|
|
510
|
+
let m = i, u = o, p = s, d = a;
|
|
511
|
+
if (r !== "fill" && h > 0 && f > 0) {
|
|
512
|
+
const y = r === "cover" ? Math.max(s / h, a / f) : Math.min(s / h, a / f);
|
|
513
|
+
p = h * y, d = f * y, m = i + (s - p) / 2, u = o + (a - d) / 2;
|
|
514
514
|
}
|
|
515
|
-
e.save(), e.beginPath(), c > 0 && typeof e.roundRect == "function" ? e.roundRect(i,
|
|
515
|
+
e.save(), e.beginPath(), c > 0 && typeof e.roundRect == "function" ? e.roundRect(i, o, s, a, c) : e.rect(i, o, s, a), e.clip(), e.drawImage(t.image, m, u, p, d), e.restore();
|
|
516
516
|
}
|
|
517
517
|
/**
|
|
518
518
|
* Render a custom target by calling its draw function in local coordinates.
|
|
@@ -615,12 +615,114 @@ class x {
|
|
|
615
615
|
*/
|
|
616
616
|
static loadImage(e) {
|
|
617
617
|
return new Promise((t, i) => {
|
|
618
|
-
const
|
|
619
|
-
|
|
618
|
+
const o = new Image();
|
|
619
|
+
o.onload = () => t(o), o.onerror = i, o.src = e;
|
|
620
620
|
});
|
|
621
621
|
}
|
|
622
622
|
}
|
|
623
|
-
|
|
623
|
+
function re(n, e) {
|
|
624
|
+
const t = n.length / 4, i = new Float32Array(t * 3), o = Math.min(0.999, Math.max(0, e));
|
|
625
|
+
for (let s = 0; s < t; s++) {
|
|
626
|
+
const a = n[s * 4] / 255, r = n[s * 4 + 1] / 255, c = n[s * 4 + 2] / 255, l = n[s * 4 + 3] / 255, h = Math.max(a, r, c);
|
|
627
|
+
if (h <= o) continue;
|
|
628
|
+
const f = (h - o) / (1 - o) * l / h;
|
|
629
|
+
i[s * 3] = a * f, i[s * 3 + 1] = r * f, i[s * 3 + 2] = c * f;
|
|
630
|
+
}
|
|
631
|
+
return i;
|
|
632
|
+
}
|
|
633
|
+
function E(n, e, t, i, o) {
|
|
634
|
+
const s = new Float32Array(n.length), a = o ? t : e, r = o ? e : t, c = (h, f) => (o ? h * e + f : f * e + h) * 3, l = i * 2 + 1;
|
|
635
|
+
for (let h = 0; h < a; h++)
|
|
636
|
+
for (let f = 0; f < 3; f++) {
|
|
637
|
+
let m = 0;
|
|
638
|
+
for (let u = -i; u <= i; u++) m += n[c(h, Math.min(r - 1, Math.max(0, u))) + f];
|
|
639
|
+
for (let u = 0; u < r; u++) {
|
|
640
|
+
s[c(h, u) + f] = m / l;
|
|
641
|
+
const p = n[c(h, Math.max(0, u - i)) + f], d = n[c(h, Math.min(r - 1, u + i + 1)) + f];
|
|
642
|
+
m += d - p;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return s;
|
|
646
|
+
}
|
|
647
|
+
function X(n, e, t, i) {
|
|
648
|
+
const o = Math.max(1, Math.round(i / Math.sqrt(3)));
|
|
649
|
+
let s = n;
|
|
650
|
+
for (let a = 0; a < 3; a++)
|
|
651
|
+
s = E(s, e, t, o, !0), s = E(s, e, t, o, !1);
|
|
652
|
+
return s;
|
|
653
|
+
}
|
|
654
|
+
function xe(n, e = {}) {
|
|
655
|
+
const t = n.canvas, i = t.width, o = t.height;
|
|
656
|
+
if (!(i > 0 && o > 0)) return;
|
|
657
|
+
const s = Math.max(1, Math.round(e.downsample ?? 4)), a = Math.max(1, Math.ceil(i / s)), r = Math.max(1, Math.ceil(o / s)), c = g(n, a, r), l = c?.getContext("2d");
|
|
658
|
+
if (!c || !l) return;
|
|
659
|
+
l.imageSmoothingEnabled = !0, l.drawImage(n.canvas, 0, 0, a, r);
|
|
660
|
+
const h = re(l.getImageData(0, 0, a, r).data, e.threshold ?? 0.55), f = (e.radius ?? Math.max(i, o) * 0.02) / s, m = X(h, a, r, f), u = X(h, a, r, f * 3), p = e.halo ?? 0.6, d = l.createImageData(a, r);
|
|
661
|
+
for (let y = 0; y < a * r; y++) {
|
|
662
|
+
for (let w = 0; w < 3; w++) d.data[y * 4 + w] = Math.round(Math.min(1, m[y * 3 + w] + u[y * 3 + w] * p) * 255);
|
|
663
|
+
d.data[y * 4 + 3] = 255;
|
|
664
|
+
}
|
|
665
|
+
l.putImageData(d, 0, 0), n.save(), n.setTransform(1, 0, 0, 1, 0, 0), n.globalCompositeOperation = "lighter", n.globalAlpha = Math.max(0, e.strength ?? 0.9), n.imageSmoothingEnabled = !0, n.drawImage(c, 0, 0, i, o), n.restore();
|
|
666
|
+
}
|
|
667
|
+
function Re(n, e, t) {
|
|
668
|
+
const i = t.width ?? 6, o = t.taper ?? 1, s = t.fade ?? 1, a = t.opacity ?? 1, r = t.blend === "add";
|
|
669
|
+
if (n.save(), e.length >= 2) {
|
|
670
|
+
const l = le(e, i, o, s, a);
|
|
671
|
+
r ? (n.globalCompositeOperation = "lighter", A(n, l, t.color)) : ce(n, l, t.color);
|
|
672
|
+
}
|
|
673
|
+
const c = e[e.length - 1];
|
|
674
|
+
if (t.head && c && t.head.radius > 0) {
|
|
675
|
+
r && (n.globalCompositeOperation = "lighter");
|
|
676
|
+
const l = t.head.color ?? t.color, h = n.createRadialGradient(c.at.x, c.at.y, 0, c.at.x, c.at.y, t.head.radius);
|
|
677
|
+
h.addColorStop(0, l), h.addColorStop(0.35, l), h.addColorStop(1, ae(n, l)), n.globalAlpha = a, n.fillStyle = h, n.beginPath(), n.arc(c.at.x, c.at.y, t.head.radius, 0, Math.PI * 2), n.fill();
|
|
678
|
+
}
|
|
679
|
+
n.restore();
|
|
680
|
+
}
|
|
681
|
+
function ae(n, e) {
|
|
682
|
+
n.fillStyle = e;
|
|
683
|
+
const t = String(n.fillStyle), i = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i.exec(t);
|
|
684
|
+
if (i) return `rgba(${parseInt(i[1], 16)}, ${parseInt(i[2], 16)}, ${parseInt(i[3], 16)}, 0)`;
|
|
685
|
+
const o = /^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i.exec(t);
|
|
686
|
+
return o ? `rgba(${o[1]}, ${o[2]}, ${o[3]}, 0)` : "rgba(0, 0, 0, 0)";
|
|
687
|
+
}
|
|
688
|
+
function le(n, e, t, i, o) {
|
|
689
|
+
const s = n.map((l) => ({ x: l.at.x, y: l.at.y, width: e * (1 - t * l.age) })), a = K(s), r = ee(s) ?? void 0, c = [];
|
|
690
|
+
for (let l = 0; l + 1 < n.length; l++) {
|
|
691
|
+
const h = (n[l].age + n[l + 1].age) / 2, f = o * (1 - i * h);
|
|
692
|
+
if (f <= 0) continue;
|
|
693
|
+
const m = l + 2 === n.length;
|
|
694
|
+
c.push({ corners: [a.left[l], a.left[l + 1], a.right[l + 1], a.right[l]], alpha: f, ...m && r && { cap: r } });
|
|
695
|
+
}
|
|
696
|
+
return c;
|
|
697
|
+
}
|
|
698
|
+
function A(n, e, t) {
|
|
699
|
+
n.fillStyle = t;
|
|
700
|
+
for (const i of e) {
|
|
701
|
+
const [o, s, a, r] = i.corners;
|
|
702
|
+
n.globalAlpha = Math.min(1, i.alpha), n.beginPath(), n.moveTo(o.x, o.y), n.lineTo(s.x, s.y), i.cap && n.arc(i.cap.x, i.cap.y, i.cap.radius, i.cap.start, i.cap.start - Math.PI, !0), n.lineTo(a.x, a.y), n.lineTo(r.x, r.y), n.closePath(), n.fill();
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
function ce(n, e, t) {
|
|
706
|
+
const i = typeof n.getTransform == "function" ? n.getTransform() : null, o = (d) => i ? { x: i.a * d.x + i.c * d.y + i.e, y: i.b * d.x + i.d * d.y + i.f } : d, s = i ? Math.sqrt(Math.abs(i.a * i.d - i.b * i.c)) : 1, a = e.map((d) => ({
|
|
707
|
+
...d,
|
|
708
|
+
corners: d.corners.map(o),
|
|
709
|
+
...d.cap && { cap: { ...d.cap, ...o(d.cap), radius: d.cap.radius * s, start: d.cap.start + (i ? Math.atan2(i.b, i.a) : 0) } }
|
|
710
|
+
}));
|
|
711
|
+
let r = 1 / 0, c = 1 / 0, l = -1 / 0, h = -1 / 0;
|
|
712
|
+
for (const d of a) {
|
|
713
|
+
const y = d.cap ? [{ x: d.cap.x - d.cap.radius, y: d.cap.y - d.cap.radius }, { x: d.cap.x + d.cap.radius, y: d.cap.y + d.cap.radius }] : [];
|
|
714
|
+
for (const w of [...d.corners, ...y])
|
|
715
|
+
r = Math.min(r, w.x), c = Math.min(c, w.y), l = Math.max(l, w.x), h = Math.max(h, w.y);
|
|
716
|
+
}
|
|
717
|
+
if (!(l > r && h > c)) return;
|
|
718
|
+
const f = Math.floor(r) - 1, m = Math.floor(c) - 1, u = i ? g(n, Math.ceil(l) + 1 - f, Math.ceil(h) + 1 - m) : null, p = u?.getContext("2d");
|
|
719
|
+
if (!u || !p) {
|
|
720
|
+
A(n, e, t);
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
p.translate(-f, -m), p.globalCompositeOperation = "lighter", A(p, a, t), n.save(), n.setTransform(1, 0, 0, 1, 0, 0), n.globalAlpha = 1, n.drawImage(u, f, m), n.restore();
|
|
724
|
+
}
|
|
725
|
+
const S = "http://www.w3.org/2000/svg", he = /* @__PURE__ */ new Set([
|
|
624
726
|
"fill",
|
|
625
727
|
"stroke",
|
|
626
728
|
"d",
|
|
@@ -640,7 +742,7 @@ const S = "http://www.w3.org/2000/svg", te = /* @__PURE__ */ new Set([
|
|
|
640
742
|
"height",
|
|
641
743
|
"viewBox",
|
|
642
744
|
"preserveAspectRatio"
|
|
643
|
-
]),
|
|
745
|
+
]), C = {
|
|
644
746
|
strokeWidth: "stroke-width",
|
|
645
747
|
strokeLinecap: "stroke-linecap",
|
|
646
748
|
strokeLinejoin: "stroke-linejoin",
|
|
@@ -651,7 +753,7 @@ const S = "http://www.w3.org/2000/svg", te = /* @__PURE__ */ new Set([
|
|
|
651
753
|
strokeOpacity: "stroke-opacity",
|
|
652
754
|
borderRadius: "rx"
|
|
653
755
|
// Map CSS borderRadius to SVG rx
|
|
654
|
-
},
|
|
756
|
+
}, fe = /* @__PURE__ */ new Set([
|
|
655
757
|
"x",
|
|
656
758
|
// Position x treated as translateX
|
|
657
759
|
"y",
|
|
@@ -672,8 +774,8 @@ const S = "http://www.w3.org/2000/svg", te = /* @__PURE__ */ new Set([
|
|
|
672
774
|
"motionPathX",
|
|
673
775
|
"motionPathY",
|
|
674
776
|
"motionPathRotate"
|
|
675
|
-
]),
|
|
676
|
-
class
|
|
777
|
+
]), ue = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]);
|
|
778
|
+
class Ae {
|
|
677
779
|
targets = /* @__PURE__ */ new Map();
|
|
678
780
|
/**
|
|
679
781
|
* Register an SVG element as an animation target.
|
|
@@ -704,8 +806,8 @@ class ye {
|
|
|
704
806
|
*/
|
|
705
807
|
applyState(e) {
|
|
706
808
|
for (const [t, i] of e.values) {
|
|
707
|
-
const
|
|
708
|
-
|
|
809
|
+
const o = this.targets.get(t);
|
|
810
|
+
o && this.applyProperties(o, i);
|
|
709
811
|
}
|
|
710
812
|
}
|
|
711
813
|
/**
|
|
@@ -713,25 +815,25 @@ class ye {
|
|
|
713
815
|
*/
|
|
714
816
|
applyProperties(e, t) {
|
|
715
817
|
const i = {};
|
|
716
|
-
let
|
|
717
|
-
const
|
|
818
|
+
let o = null;
|
|
819
|
+
const s = {}, a = {}, r = {};
|
|
718
820
|
let c = !1;
|
|
719
821
|
for (const [l, h] of t)
|
|
720
|
-
l !== "drawOn" && (
|
|
721
|
-
if (Object.keys(i).length > 0 ||
|
|
722
|
-
const l = this.buildCssTransformString(i,
|
|
723
|
-
e.style.transform = l,
|
|
822
|
+
l !== "drawOn" && (fe.has(l) ? i[l] = h : l === "quaternion" ? o = q(h) : l === "originX" || l === "originY" ? typeof h == "number" && (s[l] = h) : l === "perspective" ? typeof h == "number" && (i.perspective = h) : ue.has(l) ? typeof h == "number" && (a[l] = h) : j.has(l) ? (r[l] = h, c = !0) : l === "text" ? typeof h == "string" && Z(e, h) : l === "shine" ? typeof h == "number" && this.applyShine(e, h) : l === "opacity" ? (e.setAttribute("fill-opacity", String(h)), e.setAttribute("stroke-opacity", String(h))) : this.applyAttribute(e, l, h));
|
|
823
|
+
if (Object.keys(i).length > 0 || o) {
|
|
824
|
+
const l = this.buildCssTransformString(i, o);
|
|
825
|
+
e.style.transform = l, J(e);
|
|
724
826
|
}
|
|
725
|
-
if (Object.keys(
|
|
827
|
+
if (Object.keys(s).length > 0) {
|
|
726
828
|
const l = e.style;
|
|
727
|
-
l.transformBox = "fill-box", l.transformOrigin = `${
|
|
829
|
+
l.transformBox = "fill-box", l.transformOrigin = `${s.originX ?? 50}% ${s.originY ?? 50}%`;
|
|
728
830
|
}
|
|
729
831
|
if (Object.keys(a).length > 0) {
|
|
730
|
-
const l = a.clipTop ?? 0, h = a.clipRight ?? 0, f = a.clipBottom ?? 0,
|
|
731
|
-
e.style.clipPath = `inset(${l}% ${h}% ${f}% ${
|
|
832
|
+
const l = a.clipTop ?? 0, h = a.clipRight ?? 0, f = a.clipBottom ?? 0, m = a.clipLeft ?? 0;
|
|
833
|
+
e.style.clipPath = `inset(${l}% ${h}% ${f}% ${m}%)`;
|
|
732
834
|
}
|
|
733
835
|
if (c) {
|
|
734
|
-
const l =
|
|
836
|
+
const l = B(r);
|
|
735
837
|
l && (e.style.filter = l);
|
|
736
838
|
}
|
|
737
839
|
}
|
|
@@ -741,14 +843,14 @@ class ye {
|
|
|
741
843
|
buildCssTransformString(e, t = null) {
|
|
742
844
|
const i = [];
|
|
743
845
|
e.perspective !== void 0 && e.perspective > 0 && i.push(`perspective(${e.perspective}px)`);
|
|
744
|
-
const
|
|
745
|
-
e.z !== void 0 ? i.push(`translate3d(${
|
|
846
|
+
const o = e.motionPathX ?? e.x ?? e.translateX, s = e.motionPathY ?? e.y ?? e.translateY;
|
|
847
|
+
e.z !== void 0 ? i.push(`translate3d(${o ?? 0}px, ${s ?? 0}px, ${e.z}px)`) : (o !== void 0 || s !== void 0) && i.push(`translate(${o ?? 0}px, ${s ?? 0}px)`);
|
|
746
848
|
const a = e.motionPathRotate ?? e.rotate ?? e.rotateZ;
|
|
747
849
|
if (a !== void 0 && i.push(`rotate(${a}deg)`), e.rotateX !== void 0 && i.push(`rotateX(${e.rotateX}deg)`), e.rotateY !== void 0 && i.push(`rotateY(${e.rotateY}deg)`), t && i.push(t), e.scale !== void 0)
|
|
748
850
|
i.push(`scale(${e.scale})`);
|
|
749
851
|
else if (e.scaleX !== void 0 || e.scaleY !== void 0) {
|
|
750
|
-
const
|
|
751
|
-
i.push(`scale(${
|
|
852
|
+
const r = e.scaleX ?? 1, c = e.scaleY ?? 1;
|
|
853
|
+
i.push(`scale(${r}, ${c})`);
|
|
752
854
|
}
|
|
753
855
|
return e.skewX !== void 0 && i.push(`skewX(${e.skewX}deg)`), e.skewY !== void 0 && i.push(`skewY(${e.skewY}deg)`), i.join(" ");
|
|
754
856
|
}
|
|
@@ -761,29 +863,29 @@ class ye {
|
|
|
761
863
|
* gradient lives in the owner SVG's <defs> and is reused across frames.
|
|
762
864
|
*/
|
|
763
865
|
applyShine(e, t) {
|
|
764
|
-
const i = e.ownerSVGElement,
|
|
765
|
-
if (!i || !
|
|
766
|
-
const
|
|
767
|
-
|
|
768
|
-
const a =
|
|
769
|
-
let
|
|
770
|
-
|
|
771
|
-
let c =
|
|
772
|
-
for (l || (c = `tinyfly-shine-${Math.random().toString(36).slice(2, 9)}`,
|
|
773
|
-
for (const h of
|
|
774
|
-
const f =
|
|
866
|
+
const i = e.ownerSVGElement, o = e.ownerDocument;
|
|
867
|
+
if (!i || !o) return;
|
|
868
|
+
const s = e;
|
|
869
|
+
s.dataset.shineBase || (s.dataset.shineBase = e.getAttribute("fill") || "#000000");
|
|
870
|
+
const a = s.dataset.shineBase;
|
|
871
|
+
let r = i.querySelector("defs");
|
|
872
|
+
r || (r = o.createElementNS(S, "defs"), i.insertBefore(r, i.firstChild));
|
|
873
|
+
let c = s.dataset.shineGrad, l = c ? r.querySelector(`#${c}`) : null;
|
|
874
|
+
for (l || (c = `tinyfly-shine-${Math.random().toString(36).slice(2, 9)}`, s.dataset.shineGrad = c, l = o.createElementNS(S, "linearGradient"), l.setAttribute("id", c), r.appendChild(l)); l.firstChild; ) l.removeChild(l.firstChild);
|
|
875
|
+
for (const h of G(t, a)) {
|
|
876
|
+
const f = o.createElementNS(S, "stop");
|
|
775
877
|
f.setAttribute("offset", String(h.offset)), f.setAttribute("stop-color", h.color), l.appendChild(f);
|
|
776
878
|
}
|
|
777
879
|
e.setAttribute("fill", `url(#${c})`);
|
|
778
880
|
}
|
|
779
881
|
applyAttribute(e, t, i) {
|
|
780
|
-
let
|
|
781
|
-
|
|
782
|
-
const
|
|
783
|
-
e.setAttribute(
|
|
882
|
+
let o = t;
|
|
883
|
+
C[t] ? o = C[t] : he.has(t) && (o = t);
|
|
884
|
+
const s = Array.isArray(i) ? i.join(" ") : String(i);
|
|
885
|
+
e.setAttribute(o, s);
|
|
784
886
|
}
|
|
785
887
|
}
|
|
786
|
-
const
|
|
888
|
+
const de = `
|
|
787
889
|
attribute vec2 a_position;
|
|
788
890
|
attribute vec2 a_texCoord;
|
|
789
891
|
uniform mat4 u_matrix;
|
|
@@ -793,7 +895,7 @@ void main() {
|
|
|
793
895
|
gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);
|
|
794
896
|
v_texCoord = a_texCoord;
|
|
795
897
|
}
|
|
796
|
-
`,
|
|
898
|
+
`, pe = `
|
|
797
899
|
precision mediump float;
|
|
798
900
|
uniform vec4 u_color;
|
|
799
901
|
uniform sampler2D u_texture;
|
|
@@ -804,7 +906,7 @@ void main() {
|
|
|
804
906
|
vec4 color = u_useTexture ? texture2D(u_texture, v_texCoord) : u_color;
|
|
805
907
|
gl_FragColor = vec4(color.rgb, color.a * u_opacity);
|
|
806
908
|
}
|
|
807
|
-
`,
|
|
909
|
+
`, me = /* @__PURE__ */ new Set([
|
|
808
910
|
"x",
|
|
809
911
|
"y",
|
|
810
912
|
"width",
|
|
@@ -825,7 +927,7 @@ void main() {
|
|
|
825
927
|
"motionPathY",
|
|
826
928
|
"motionPathRotate"
|
|
827
929
|
]);
|
|
828
|
-
class
|
|
930
|
+
class ge {
|
|
829
931
|
gl;
|
|
830
932
|
program;
|
|
831
933
|
positionBuffer;
|
|
@@ -836,7 +938,7 @@ class me {
|
|
|
836
938
|
basePositions = /* @__PURE__ */ new Map();
|
|
837
939
|
locations;
|
|
838
940
|
constructor(e) {
|
|
839
|
-
this.gl = e, this.program =
|
|
941
|
+
this.gl = e, this.program = be(e, de, pe), this.locations = {
|
|
840
942
|
position: e.getAttribLocation(this.program, "a_position"),
|
|
841
943
|
texCoord: e.getAttribLocation(this.program, "a_texCoord"),
|
|
842
944
|
matrix: e.getUniformLocation(this.program, "u_matrix"),
|
|
@@ -844,7 +946,7 @@ class me {
|
|
|
844
946
|
texture: e.getUniformLocation(this.program, "u_texture"),
|
|
845
947
|
useTexture: e.getUniformLocation(this.program, "u_useTexture"),
|
|
846
948
|
opacity: e.getUniformLocation(this.program, "u_opacity")
|
|
847
|
-
}, this.positionBuffer =
|
|
949
|
+
}, this.positionBuffer = I(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]), this.texCoordBuffer = I(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]);
|
|
848
950
|
}
|
|
849
951
|
registerTarget(e, t) {
|
|
850
952
|
this.targets.set(e, t), this.basePositions.set(e, { x: t.x, y: t.y });
|
|
@@ -863,92 +965,92 @@ class me {
|
|
|
863
965
|
/** Apply engine state to the registered targets. */
|
|
864
966
|
applyState(e) {
|
|
865
967
|
for (const [t, i] of e.values) {
|
|
866
|
-
const
|
|
867
|
-
if (!
|
|
868
|
-
const
|
|
869
|
-
for (const [a,
|
|
870
|
-
this.applyProperty(
|
|
968
|
+
const o = this.targets.get(t);
|
|
969
|
+
if (!o) continue;
|
|
970
|
+
const s = this.basePositions.get(t) ?? { x: 0, y: 0 };
|
|
971
|
+
for (const [a, r] of i)
|
|
972
|
+
this.applyProperty(o, s, a, r);
|
|
871
973
|
}
|
|
872
974
|
}
|
|
873
|
-
applyProperty(e, t, i,
|
|
874
|
-
if (typeof
|
|
975
|
+
applyProperty(e, t, i, o) {
|
|
976
|
+
if (typeof o == "number") {
|
|
875
977
|
if (i === "x" || i === "motionPathX") {
|
|
876
|
-
e.x = t.x +
|
|
978
|
+
e.x = t.x + o;
|
|
877
979
|
return;
|
|
878
980
|
}
|
|
879
981
|
if (i === "y" || i === "motionPathY") {
|
|
880
|
-
e.y = t.y +
|
|
982
|
+
e.y = t.y + o;
|
|
881
983
|
return;
|
|
882
984
|
}
|
|
883
985
|
if (i === "rotateZ" || i === "motionPathRotate") {
|
|
884
|
-
e.rotate =
|
|
986
|
+
e.rotate = o;
|
|
885
987
|
return;
|
|
886
988
|
}
|
|
887
|
-
if (
|
|
888
|
-
e[i] =
|
|
989
|
+
if (me.has(i)) {
|
|
990
|
+
e[i] = o;
|
|
889
991
|
return;
|
|
890
992
|
}
|
|
891
993
|
}
|
|
892
|
-
typeof
|
|
994
|
+
typeof o == "string" && i === "fill" && (e.fill = o), i === "quaternion" && Array.isArray(o) && (e.quaternion = o);
|
|
893
995
|
}
|
|
894
996
|
/** Draw every registered target. */
|
|
895
997
|
render() {
|
|
896
998
|
const e = this.gl, { width: t, height: i } = e.canvas;
|
|
897
|
-
e.viewport(0, 0, t, i), e.clearColor(0, 0, 0, 0), e.clear(e.COLOR_BUFFER_BIT), e.enable(e.BLEND), e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.useProgram(this.program),
|
|
898
|
-
for (const [
|
|
899
|
-
this.drawTarget(
|
|
900
|
-
}
|
|
901
|
-
drawTarget(e, t, i,
|
|
902
|
-
const
|
|
903
|
-
if (t.backfaceVisibility === "hidden" &&
|
|
904
|
-
const a =
|
|
905
|
-
if (
|
|
906
|
-
|
|
999
|
+
e.viewport(0, 0, t, i), e.clearColor(0, 0, 0, 0), e.clear(e.COLOR_BUFFER_BIT), e.enable(e.BLEND), e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.useProgram(this.program), Y(e, this.positionBuffer, this.locations.position), Y(e, this.texCoordBuffer, this.locations.texCoord);
|
|
1000
|
+
for (const [o, s] of this.targets)
|
|
1001
|
+
this.drawTarget(o, s, t, i);
|
|
1002
|
+
}
|
|
1003
|
+
drawTarget(e, t, i, o) {
|
|
1004
|
+
const s = this.gl;
|
|
1005
|
+
if (t.backfaceVisibility === "hidden" && O(D(t))) return;
|
|
1006
|
+
const a = ye(t, i, o);
|
|
1007
|
+
if (s.uniformMatrix4fv(this.locations.matrix, !1, a), s.uniform1f(this.locations.opacity, t.opacity ?? 1), t.texture)
|
|
1008
|
+
s.bindTexture(s.TEXTURE_2D, this.textureFor(e, t.texture)), s.uniform1i(this.locations.useTexture, 1), s.uniform1i(this.locations.texture, 0);
|
|
907
1009
|
else {
|
|
908
|
-
|
|
909
|
-
const [
|
|
910
|
-
|
|
1010
|
+
s.uniform1i(this.locations.useTexture, 0);
|
|
1011
|
+
const [r, c, l] = we(t.fill ?? "#ffffff");
|
|
1012
|
+
s.uniform4f(this.locations.color, r, c, l, 1);
|
|
911
1013
|
}
|
|
912
|
-
|
|
1014
|
+
s.drawArrays(s.TRIANGLES, 0, 6);
|
|
913
1015
|
}
|
|
914
1016
|
textureFor(e, t) {
|
|
915
1017
|
const i = this.textures.get(e);
|
|
916
1018
|
if (i) return i;
|
|
917
|
-
const
|
|
918
|
-
return
|
|
1019
|
+
const o = this.gl, s = o.createTexture();
|
|
1020
|
+
return o.bindTexture(o.TEXTURE_2D, s), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR), o.texImage2D(o.TEXTURE_2D, 0, o.RGBA, o.RGBA, o.UNSIGNED_BYTE, t), this.textures.set(e, s), s;
|
|
919
1021
|
}
|
|
920
1022
|
/** Release GL resources. */
|
|
921
1023
|
destroy() {
|
|
922
1024
|
this.clearTargets(), this.gl.deleteProgram(this.program), this.gl.deleteBuffer(this.positionBuffer), this.gl.deleteBuffer(this.texCoordBuffer);
|
|
923
1025
|
}
|
|
924
1026
|
}
|
|
925
|
-
function
|
|
926
|
-
const i = (
|
|
1027
|
+
function ke(n, e, t) {
|
|
1028
|
+
const i = (n.scale ?? n.scaleX ?? 1) * n.width, o = (n.scale ?? n.scaleY ?? 1) * n.height, s = (n.originX ?? 50) / 100, a = (n.originY ?? 50) / 100, r = (n.rotate ?? 0) * Math.PI / 180, c = Math.cos(r), l = Math.sin(r), h = -s, f = -a, m = c * i, u = l * i, p = -l * o, d = c * o, y = n.x + m * h + p * f, w = n.y + u * h + d * f, v = 2 / e, P = -2 / t;
|
|
927
1029
|
return new Float32Array([
|
|
928
|
-
|
|
1030
|
+
m * v,
|
|
929
1031
|
u * P,
|
|
930
1032
|
0,
|
|
931
|
-
|
|
932
|
-
|
|
1033
|
+
p * v,
|
|
1034
|
+
d * P,
|
|
933
1035
|
0,
|
|
934
|
-
|
|
935
|
-
|
|
1036
|
+
y * v - 1,
|
|
1037
|
+
w * P + 1,
|
|
936
1038
|
1
|
|
937
1039
|
]);
|
|
938
1040
|
}
|
|
939
|
-
function
|
|
940
|
-
const e = (
|
|
941
|
-
|
|
942
|
-
|
|
1041
|
+
function D(n) {
|
|
1042
|
+
const e = (n.originX ?? 50) / 100, t = (n.originY ?? 50) / 100, i = { x: n.x, y: n.y }, o = b.multiply(
|
|
1043
|
+
b.translation([n.x, n.y, 0]),
|
|
1044
|
+
b.multiply(b.scaling([n.width, n.height, 1]), b.translation([-e, -t, 0]))
|
|
943
1045
|
);
|
|
944
|
-
return
|
|
1046
|
+
return b.multiply(_(n, { x: 0, y: 0 }, i), o);
|
|
945
1047
|
}
|
|
946
|
-
function
|
|
1048
|
+
function ye(n, e, t) {
|
|
947
1049
|
const i = [2 / e, 0, 0, 0, 0, -2 / t, 0, 0, 0, 0, 0, 0, -1, 1, 0, 1];
|
|
948
|
-
return new Float32Array(
|
|
1050
|
+
return new Float32Array(b.multiply(i, D(n)));
|
|
949
1051
|
}
|
|
950
|
-
function
|
|
951
|
-
const e =
|
|
1052
|
+
function we(n) {
|
|
1053
|
+
const e = n.trim().replace("#", "");
|
|
952
1054
|
return e.length === 3 ? [
|
|
953
1055
|
Number.parseInt(e[0] + e[0], 16) / 255,
|
|
954
1056
|
Number.parseInt(e[1] + e[1], 16) / 255,
|
|
@@ -959,47 +1061,53 @@ function ce(r) {
|
|
|
959
1061
|
Number.parseInt(e.slice(4, 6), 16) / 255
|
|
960
1062
|
] : [1, 1, 1];
|
|
961
1063
|
}
|
|
962
|
-
function
|
|
963
|
-
const i =
|
|
1064
|
+
function be(n, e, t) {
|
|
1065
|
+
const i = n.createProgram();
|
|
964
1066
|
if (!i) throw new Error("WebGLAdapter: could not create a program");
|
|
965
|
-
if (
|
|
966
|
-
throw new Error(`WebGLAdapter: program link failed — ${
|
|
1067
|
+
if (n.attachShader(i, $(n, n.VERTEX_SHADER, e)), n.attachShader(i, $(n, n.FRAGMENT_SHADER, t)), n.linkProgram(i), !n.getProgramParameter(i, n.LINK_STATUS))
|
|
1068
|
+
throw new Error(`WebGLAdapter: program link failed — ${n.getProgramInfoLog(i)}`);
|
|
967
1069
|
return i;
|
|
968
1070
|
}
|
|
969
|
-
function
|
|
970
|
-
const i =
|
|
1071
|
+
function $(n, e, t) {
|
|
1072
|
+
const i = n.createShader(e);
|
|
971
1073
|
if (!i) throw new Error("WebGLAdapter: could not create a shader");
|
|
972
|
-
if (
|
|
973
|
-
throw new Error(`WebGLAdapter: shader compile failed — ${
|
|
1074
|
+
if (n.shaderSource(i, t), n.compileShader(i), !n.getShaderParameter(i, n.COMPILE_STATUS))
|
|
1075
|
+
throw new Error(`WebGLAdapter: shader compile failed — ${n.getShaderInfoLog(i)}`);
|
|
974
1076
|
return i;
|
|
975
1077
|
}
|
|
976
|
-
function
|
|
977
|
-
const t =
|
|
1078
|
+
function I(n, e) {
|
|
1079
|
+
const t = n.createBuffer();
|
|
978
1080
|
if (!t) throw new Error("WebGLAdapter: could not create a buffer");
|
|
979
|
-
return
|
|
1081
|
+
return n.bindBuffer(n.ARRAY_BUFFER, t), n.bufferData(n.ARRAY_BUFFER, new Float32Array(e), n.STATIC_DRAW), t;
|
|
980
1082
|
}
|
|
981
|
-
function
|
|
982
|
-
t < 0 || (
|
|
1083
|
+
function Y(n, e, t) {
|
|
1084
|
+
t < 0 || (n.bindBuffer(n.ARRAY_BUFFER, e), n.enableVertexAttribArray(t), n.vertexAttribPointer(t, 2, n.FLOAT, !1, 0, 0));
|
|
983
1085
|
}
|
|
984
1086
|
export {
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
Re as
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
we as
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1087
|
+
R as CanvasAdapter,
|
|
1088
|
+
Ce as DOMAdapter,
|
|
1089
|
+
Ae as SVGAdapter,
|
|
1090
|
+
ge as WebGLAdapter,
|
|
1091
|
+
xe as applyBloom,
|
|
1092
|
+
Ie as boilFrame,
|
|
1093
|
+
X as boxBlur,
|
|
1094
|
+
re as brightPass,
|
|
1095
|
+
se as buildFlipTracks,
|
|
1096
|
+
g as canvasLike,
|
|
1097
|
+
M as drawOutline,
|
|
1098
|
+
Re as drawTrail,
|
|
1099
|
+
Me as flip,
|
|
1100
|
+
Se as isGradient,
|
|
1101
|
+
we as parseColor,
|
|
1102
|
+
te as partialPath,
|
|
1103
|
+
Ye as pathLength,
|
|
1104
|
+
x as pathOutline,
|
|
1105
|
+
_e as pointAlong,
|
|
1106
|
+
ke as quadMatrix,
|
|
1107
|
+
ye as quadMatrix3d,
|
|
1108
|
+
oe as recordFlipState,
|
|
1109
|
+
ne as rectOutline,
|
|
1110
|
+
Z as setTextContent,
|
|
1111
|
+
ie as sketchPen,
|
|
1112
|
+
le as trailQuads
|
|
1005
1113
|
};
|