@algorisys/tinyfly 0.82.0 → 0.87.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 +13 -4
- package/bin/tinyfly.mjs +44 -6
- package/lib/addons/adapters.js +411 -248
- package/lib/addons/characters.js +1652 -1470
- package/lib/addons/dom-adapter-Cphr2HZn.js +372 -0
- package/lib/addons/gsap-compat.js +197 -187
- package/lib/addons/load-scene-vp14_Jj-.js +324 -0
- package/lib/addons/maps.js +1 -1
- package/lib/addons/scene-3d-webgl.js +240 -0
- package/lib/addons/scene-3d.js +306 -0
- 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 +116 -0
- package/lib/browser/tinyfly-scene-3d.iife.js +3 -0
- package/lib/browser/tinyfly.iife.js +4 -4
- package/lib/browser/tinyfly.js +4333 -3726
- package/lib/browser/tinyfly.umd.js +4 -4
- package/lib/cli/tools.js +137 -22
- package/lib/embed/tinyfly-embed.iife.js +4 -4
- package/lib/embed/tinyfly-embed.js +921 -833
- package/lib/engine/tinyfly-engine.js +1022 -776
- package/lib/engine/tinyfly-engine.umd.cjs +2 -2
- package/lib/headless/headless.js +410 -8
- package/lib/player/tinyfly-player.es.js +459 -371
- package/lib/player/tinyfly-player.iife.js +2 -2
- package/lib/player/tinyfly-player.umd.js +2 -2
- package/lib/types/adapters/canvas/bloom.d.ts +33 -0
- package/lib/types/adapters/canvas/canvas-adapter.d.ts +36 -0
- package/lib/types/adapters/canvas/index.d.ts +2 -0
- package/lib/types/adapters/canvas/offscreen.d.ts +13 -0
- package/lib/types/adapters/transform-3d.d.ts +99 -0
- package/lib/types/adapters/webgl/webgl-adapter.d.ts +17 -0
- package/lib/types/browser/index.d.ts +2 -0
- package/lib/types/characters/character.d.ts +20 -1
- package/lib/types/characters/index.d.ts +2 -0
- package/lib/types/characters/rig/body-plan.d.ts +3 -1
- package/lib/types/characters/rig/skeleton.d.ts +57 -0
- package/lib/types/characters/scene-objects.d.ts +2 -0
- package/lib/types/compat/gsap/vars.d.ts +8 -0
- package/lib/types/engine/core/bake.d.ts +3 -1
- package/lib/types/engine/index.d.ts +1 -0
- package/lib/types/engine/interpolation/interpolators.d.ts +10 -3
- package/lib/types/engine/math/index.d.ts +11 -0
- package/lib/types/engine/math/mat4.d.ts +37 -0
- package/lib/types/engine/math/quat.d.ts +39 -0
- package/lib/types/engine/math/vec3.d.ts +16 -0
- package/lib/types/engine/types.d.ts +23 -2
- 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 +7 -1
- package/lib/types/scene-3d/camera.d.ts +27 -0
- package/lib/types/scene-3d/canvas-2d-renderer.d.ts +21 -0
- package/lib/types/scene-3d/geometry/extrude.d.ts +17 -0
- package/lib/types/scene-3d/geometry/mesh.d.ts +36 -0
- package/lib/types/scene-3d/geometry/primitives.d.ts +16 -0
- package/lib/types/scene-3d/geometry/triangulate.d.ts +24 -0
- package/lib/types/scene-3d/index.d.ts +20 -0
- package/lib/types/scene-3d/load-scene.d.ts +31 -0
- package/lib/types/scene-3d/object-kind.d.ts +54 -0
- package/lib/types/scene-3d/resolve-scene.d.ts +122 -0
- package/lib/types/scene-3d/scene-3d-adapter.d.ts +46 -0
- package/lib/types/scene-3d/scene-types.d.ts +192 -0
- package/lib/types/scene-3d/shading.d.ts +20 -0
- package/lib/types/scene-3d/validate-scene.d.ts +11 -0
- package/lib/types/scene-3d/webgl/gl-data.d.ts +29 -0
- package/lib/types/scene-3d/webgl/index.d.ts +16 -0
- package/lib/types/scene-3d/webgl/shaders.d.ts +29 -0
- package/lib/types/scene-3d/webgl/webgl2-renderer.d.ts +33 -0
- package/package.json +10 -2
- package/lib/addons/dom-adapter-CrNwoomd.js +0 -243
package/lib/addons/adapters.js
CHANGED
|
@@ -1,113 +1,126 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { D as
|
|
3
|
-
import { createTrack as
|
|
4
|
-
import { p as
|
|
5
|
-
import {
|
|
6
|
-
function
|
|
1
|
+
import { h as D, e as C, i as I, a as U, b as W, p as N, t as H, g as V, c as O, q, F as z, s as j, d as Z } from "./dom-adapter-Cphr2HZn.js";
|
|
2
|
+
import { D as xe } from "./dom-adapter-Cphr2HZn.js";
|
|
3
|
+
import { createTrack as J, parsePath as B, mat4 as T } from "@algorisys/tinyfly";
|
|
4
|
+
import { p as K, s as Q } from "./sketch-CYPUbk3Q.js";
|
|
5
|
+
import { c as Ae, a as ke, b as Ee } from "./sketch-CYPUbk3Q.js";
|
|
6
|
+
function ee(r) {
|
|
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 r)
|
|
9
|
+
e.set(t, g(i));
|
|
10
10
|
return { measurements: e };
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
const i = t.duration ?? 600,
|
|
14
|
-
for (const { name:
|
|
15
|
-
const h =
|
|
12
|
+
function te(r, e, t = {}) {
|
|
13
|
+
const i = t.duration ?? 600, s = t.easing ?? "ease-out", o = t.scale !== !1, a = t.idPrefix ?? "flip", n = [];
|
|
14
|
+
for (const { name: c, element: l } of e) {
|
|
15
|
+
const h = r.measurements.get(c);
|
|
16
16
|
if (!h) continue;
|
|
17
|
-
const f =
|
|
17
|
+
const f = g(l), p = h.left + h.width / 2 - (f.left + f.width / 2), u = h.top + h.height / 2 - (f.top + f.height / 2);
|
|
18
18
|
if ((p !== 0 || u !== 0) && n.push(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
),
|
|
19
|
+
v(`${a}-${c}-x`, c, "x", p, 0, i, s),
|
|
20
|
+
v(`${a}-${c}-y`, c, "y", u, 0, i, s)
|
|
21
|
+
), o && f.width > 0 && f.height > 0) {
|
|
22
22
|
const d = h.width / f.width, m = h.height / f.height;
|
|
23
|
-
d !== 1 && n.push(
|
|
23
|
+
d !== 1 && n.push(v(`${a}-${c}-sx`, c, "scaleX", d, 1, i, s)), m !== 1 && n.push(v(`${a}-${c}-sy`, c, "scaleY", m, 1, i, s));
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
return n;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
const i =
|
|
30
|
-
return e(),
|
|
28
|
+
function ye(r, e, t = {}) {
|
|
29
|
+
const i = ee(r);
|
|
30
|
+
return e(), te(i, r, t);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
return
|
|
34
|
-
id:
|
|
32
|
+
function v(r, e, t, i, s, o, a) {
|
|
33
|
+
return J({
|
|
34
|
+
id: r,
|
|
35
35
|
target: e,
|
|
36
36
|
property: t,
|
|
37
37
|
keyframes: [
|
|
38
38
|
{ time: 0, value: i },
|
|
39
|
-
{ time:
|
|
39
|
+
{ time: o, value: s, easing: a }
|
|
40
40
|
]
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
const e =
|
|
43
|
+
function g(r) {
|
|
44
|
+
const e = r;
|
|
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 L(r, e, t = {}) {
|
|
51
|
+
const i = t.highlight ?? "#ffffff", s = t.halfWidth ?? 0.12, o = -0.2 + r * 1.4, a = [{ offset: 0, color: e }], n = [
|
|
52
|
+
{ offset: o - s, color: e },
|
|
53
|
+
{ offset: o, color: i },
|
|
54
|
+
{ offset: o + s, color: e }
|
|
55
55
|
];
|
|
56
|
-
for (const
|
|
57
|
-
|
|
58
|
-
return a.push({ offset: 1, color: e }), a.sort((
|
|
56
|
+
for (const c of n)
|
|
57
|
+
c.offset > 0 && c.offset < 1 && a.push(c);
|
|
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 A = 12;
|
|
61
|
+
function x(r) {
|
|
62
62
|
const e = [];
|
|
63
63
|
let t, i = -1;
|
|
64
|
-
for (const
|
|
65
|
-
if (
|
|
66
|
-
(!t || i !==
|
|
64
|
+
for (const s of B(r).segments) {
|
|
65
|
+
if (s.type === "L") {
|
|
66
|
+
(!t || i !== s.subpath) && (t = { kind: "line", points: [{ x: s.startX, y: s.startY }], length: 0 }, i = s.subpath, e.push(t)), t.points.push({ x: s.endX, y: s.endY }), t.length += s.length;
|
|
67
67
|
continue;
|
|
68
68
|
}
|
|
69
69
|
t = void 0;
|
|
70
|
-
const [
|
|
71
|
-
for (let p = 0; p <=
|
|
72
|
-
const u = p /
|
|
70
|
+
const [o, a, n, c, l, h] = s.points, f = [];
|
|
71
|
+
for (let p = 0; p <= A; p++) {
|
|
72
|
+
const u = p / A, d = 1 - u;
|
|
73
73
|
f.push({
|
|
74
|
-
x: d * d * d *
|
|
75
|
-
y: d * d * d *
|
|
74
|
+
x: d * d * d * s.startX + 3 * d * d * u * o + 3 * d * u * u * n + u * u * u * l,
|
|
75
|
+
y: d * d * d * s.startY + 3 * d * d * u * a + 3 * d * 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: s.length });
|
|
79
79
|
}
|
|
80
80
|
return e;
|
|
81
81
|
}
|
|
82
|
-
function
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
85
|
-
const a =
|
|
86
|
-
return
|
|
87
|
-
`M${
|
|
82
|
+
function ie(r, e, t, i, s = 0) {
|
|
83
|
+
const o = Math.max(0, Math.min(s, t / 2, i / 2));
|
|
84
|
+
if (o === 0) return x(`M${r},${e} H${r + t} V${e + i} H${r} Z`);
|
|
85
|
+
const a = r + t, n = e + i;
|
|
86
|
+
return x(
|
|
87
|
+
`M${r + o},${e} H${a - o} A${o},${o} 0 0 1 ${a},${e + o} V${n - o} A${o},${o} 0 0 1 ${a - o},${n} H${r + o} A${o},${o} 0 0 1 ${r},${n - o} V${e + o} A${o},${o} 0 0 1 ${r + o},${e} Z`
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
|
-
function S(
|
|
91
|
-
const
|
|
90
|
+
function S(r, e, t, i) {
|
|
91
|
+
const o = e.reduce((n, c) => n + c.length, 0) * Math.min(1, Math.max(0, t));
|
|
92
92
|
let a = 0;
|
|
93
|
-
i ||
|
|
93
|
+
i || r.beginPath();
|
|
94
94
|
for (const n of e) {
|
|
95
|
-
const
|
|
95
|
+
const c = n.length === 0 ? o >= a ? 1 : 0 : Math.min(1, Math.max(0, (o - a) / n.length));
|
|
96
96
|
if (a += n.length, i) {
|
|
97
|
-
n.kind === "curve" ? i.curve(n.points,
|
|
97
|
+
n.kind === "curve" ? i.curve(n.points, c) : i.line(n.points, c);
|
|
98
98
|
continue;
|
|
99
99
|
}
|
|
100
|
-
if (
|
|
101
|
-
const l =
|
|
102
|
-
|
|
103
|
-
for (const h of l.slice(1))
|
|
100
|
+
if (c <= 0) continue;
|
|
101
|
+
const l = K(n.points, c);
|
|
102
|
+
r.moveTo(l[0].x, l[0].y);
|
|
103
|
+
for (const h of l.slice(1)) r.lineTo(h.x, h.y);
|
|
104
104
|
}
|
|
105
|
-
i ||
|
|
105
|
+
i || r.stroke();
|
|
106
106
|
}
|
|
107
|
-
function
|
|
108
|
-
|
|
107
|
+
function F(r, e, t) {
|
|
108
|
+
if (typeof OffscreenCanvas < "u") return new OffscreenCanvas(e, t);
|
|
109
|
+
const i = r.canvas;
|
|
110
|
+
if (i?.ownerDocument) {
|
|
111
|
+
const s = i.ownerDocument.createElement("canvas");
|
|
112
|
+
return s.width = e, s.height = t, s;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
return i?.constructor ? new i.constructor(e, t) : null;
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function we(r) {
|
|
121
|
+
return typeof r == "object" && r !== null && "type" in r;
|
|
109
122
|
}
|
|
110
|
-
class
|
|
123
|
+
class R {
|
|
111
124
|
targets = /* @__PURE__ */ new Map();
|
|
112
125
|
targetOrder = [];
|
|
113
126
|
// Store animation offsets separately - these are applied via ctx.translate() during rendering
|
|
@@ -117,6 +130,8 @@ class v {
|
|
|
117
130
|
aliases = /* @__PURE__ */ new Map();
|
|
118
131
|
// Time of the last applied state, passed to custom draw functions
|
|
119
132
|
time = 0;
|
|
133
|
+
/** Offscreen layer for see-through targets in perspective (see `drawInPerspective`) */
|
|
134
|
+
layer = null;
|
|
120
135
|
/**
|
|
121
136
|
* Register a canvas drawing target.
|
|
122
137
|
* @param id - The ID to register the target under
|
|
@@ -153,7 +168,8 @@ class v {
|
|
|
153
168
|
fill: "fillStyle",
|
|
154
169
|
stroke: "strokeStyle",
|
|
155
170
|
strokeWidth: "lineWidth",
|
|
156
|
-
motionPathRotate: "rotate"
|
|
171
|
+
motionPathRotate: "rotate",
|
|
172
|
+
rotateZ: "rotate"
|
|
157
173
|
};
|
|
158
174
|
// Properties that are position offsets (applied via ctx.translate)
|
|
159
175
|
static OFFSET_PROPERTIES = /* @__PURE__ */ new Set(["x", "y", "motionPathX", "motionPathY"]);
|
|
@@ -165,19 +181,19 @@ class v {
|
|
|
165
181
|
applyState(e) {
|
|
166
182
|
this.time = e.currentTime;
|
|
167
183
|
for (const [t, i] of e.values) {
|
|
168
|
-
const
|
|
169
|
-
if (!
|
|
170
|
-
const
|
|
171
|
-
for (const [n,
|
|
172
|
-
if (
|
|
173
|
-
n === "x" || n === "motionPathX" ? a.x =
|
|
174
|
-
else if (
|
|
175
|
-
|
|
184
|
+
const s = this.targets.get(t);
|
|
185
|
+
if (!s) continue;
|
|
186
|
+
const o = this.aliases.get(t) ?? t, a = this.animationOffsets.get(o) ?? { x: 0, y: 0 };
|
|
187
|
+
for (const [n, c] of i)
|
|
188
|
+
if (R.OFFSET_PROPERTIES.has(n) && typeof c == "number")
|
|
189
|
+
n === "x" || n === "motionPathX" ? a.x = c : (n === "y" || n === "motionPathY") && (a.y = c);
|
|
190
|
+
else if (s.type === "custom" && s.props && (n in s.props || s.acceptsProp?.(n)))
|
|
191
|
+
s.props[n] = c;
|
|
176
192
|
else {
|
|
177
|
-
const l =
|
|
178
|
-
|
|
193
|
+
const l = R.PROPERTY_MAP[n] ?? n;
|
|
194
|
+
s[l] = c;
|
|
179
195
|
}
|
|
180
|
-
this.animationOffsets.set(
|
|
196
|
+
this.animationOffsets.set(o, a);
|
|
181
197
|
}
|
|
182
198
|
}
|
|
183
199
|
/**
|
|
@@ -194,29 +210,107 @@ class v {
|
|
|
194
210
|
for (const t of this.targetOrder) {
|
|
195
211
|
const i = this.targets.get(t);
|
|
196
212
|
if (!i) continue;
|
|
197
|
-
const
|
|
198
|
-
this.renderTarget(e, i,
|
|
213
|
+
const s = this.animationOffsets.get(t) ?? { x: 0, y: 0 };
|
|
214
|
+
this.renderTarget(e, i, s);
|
|
199
215
|
}
|
|
200
216
|
}
|
|
201
217
|
/**
|
|
202
218
|
* Render a single target.
|
|
203
219
|
*/
|
|
204
220
|
renderTarget(e, t, i) {
|
|
205
|
-
if (e.save(),
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const h = (t.skewX ?? 0) * Math.PI / 180, f = (t.skewY ?? 0) * Math.PI / 180;
|
|
211
|
-
e.transform(1, Math.tan(f), Math.tan(h), 1, 0, 0);
|
|
221
|
+
if (e.save(), t.opacity !== void 0 && (e.globalAlpha = t.opacity), D(t)) {
|
|
222
|
+
const o = C(t, i, { x: this.getPivotX(t), y: this.getPivotY(t) });
|
|
223
|
+
if (t.backfaceVisibility === "hidden" && I(o)) {
|
|
224
|
+
e.restore();
|
|
225
|
+
return;
|
|
212
226
|
}
|
|
213
|
-
e.
|
|
227
|
+
U(o) ? (e.transform(...W(o)), this.drawContent(e, t)) : this.drawInPerspective(e, t, o), e.restore();
|
|
228
|
+
return;
|
|
214
229
|
}
|
|
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 o = this.getPivotX(t), a = this.getPivotY(t);
|
|
232
|
+
e.translate(o, a), t.rotate !== void 0 && e.rotate(t.rotate * Math.PI / 180);
|
|
233
|
+
let n = 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 && (n *= Math.cos(t.rotateY * Math.PI / 180)), t.scale !== void 0 ? e.scale(t.scale, t.scale) : (n !== 1 || c !== 1) && e.scale(n, c), t.skewX !== void 0 || t.skewY !== void 0) {
|
|
235
|
+
const l = (t.skewX ?? 0) * Math.PI / 180, h = (t.skewY ?? 0) * Math.PI / 180;
|
|
236
|
+
e.transform(1, Math.tan(h), Math.tan(l), 1, 0, 0);
|
|
237
|
+
}
|
|
238
|
+
e.translate(-o, -a);
|
|
239
|
+
}
|
|
240
|
+
this.drawContent(e, t), e.restore();
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Draw a target in perspective: each triangle of a mesh over its bounds is
|
|
244
|
+
* clipped on the canvas and drawn with the 2D transform that carries it
|
|
245
|
+
* there. The triangles overlap by a pixel so no anti-aliased seam shows.
|
|
246
|
+
*/
|
|
247
|
+
drawInPerspective(e, t, i) {
|
|
248
|
+
const o = e.globalAlpha < 1 ? this.perspectiveLayer(e) : null;
|
|
249
|
+
if (o) {
|
|
250
|
+
o.ctx.setTransform(e.getTransform()), this.drawMesh(o.ctx, t, i), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(o.canvas, 0, 0), e.restore();
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
this.drawMesh(e, t, i);
|
|
254
|
+
}
|
|
255
|
+
drawMesh(e, t, i) {
|
|
256
|
+
const s = this.contentBounds(e, t);
|
|
257
|
+
for (const o of N(i, s)) {
|
|
258
|
+
const a = H(o.source, o.target);
|
|
259
|
+
if (!a) continue;
|
|
260
|
+
const [n, c, l] = V(o.target, 1);
|
|
261
|
+
e.save(), e.beginPath(), e.moveTo(n.x, n.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
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/** A cleared offscreen canvas the size of `ctx`'s, reused frame to frame; null where none can be made. */
|
|
265
|
+
perspectiveLayer(e) {
|
|
266
|
+
const t = e.canvas?.width ?? 0, i = e.canvas?.height ?? 0;
|
|
267
|
+
if (!(t > 0 && i > 0)) return null;
|
|
268
|
+
if (!this.layer || this.layer.width !== t || this.layer.height !== i) {
|
|
269
|
+
const o = F(e, t, i), a = o?.getContext("2d");
|
|
270
|
+
if (this.layer = o && a ? { canvas: o, ctx: a, width: t, height: i } : null, !this.layer) return null;
|
|
271
|
+
}
|
|
272
|
+
const s = this.layer.ctx;
|
|
273
|
+
return s.setTransform(1, 0, 0, 1, 0, 0), s.globalAlpha = 1, s.clearRect(0, 0, t, i), this.layer;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Everything a target paints, generously: its box, measured text, a path's
|
|
277
|
+
* control points, plus room for its stroke, blur and glow. The perspective
|
|
278
|
+
* mesh covers this, so nothing it draws falls outside.
|
|
279
|
+
*/
|
|
280
|
+
contentBounds(e, t) {
|
|
281
|
+
let i = this.getTargetBounds(t);
|
|
282
|
+
if (t.type === "text") {
|
|
283
|
+
const o = t.fontSize ?? 16;
|
|
284
|
+
e.save(), e.font = `${t.fontWeight ?? 400} ${o}px ${t.fontFamily ?? "sans-serif"}`;
|
|
285
|
+
const a = e.measureText(t.text).width;
|
|
286
|
+
e.restore();
|
|
287
|
+
const n = t.textAlign ?? "left", c = n === "center" ? t.x - a / 2 : n === "right" ? t.x - a : t.x, l = (t.textBaseline ?? "top") === "top" ? t.y : t.y - o;
|
|
288
|
+
i = { x: c, y: l, width: a, height: o * 1.4 };
|
|
289
|
+
} else if (t.type === "path") {
|
|
290
|
+
const o = [], a = [];
|
|
291
|
+
for (const n of B(t.d).segments) {
|
|
292
|
+
o.push(n.startX, n.endX), a.push(n.startY, n.endY);
|
|
293
|
+
for (let c = 0; c + 1 < n.points.length; c += 2)
|
|
294
|
+
o.push(n.points[c]), a.push(n.points[c + 1]);
|
|
295
|
+
}
|
|
296
|
+
if (o.length > 0) {
|
|
297
|
+
const n = Math.min(...o), c = Math.min(...a);
|
|
298
|
+
i = { x: t.x + n, y: t.y + c, width: Math.max(...o) - n, height: Math.max(...a) - c };
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const s = (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 - s, y: i.y - s, width: i.width + 2 * s, height: i.height + 2 * s };
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Paint a target in the current transform: its fill and stroke styles,
|
|
306
|
+
* filter and clip, then its shape.
|
|
307
|
+
*/
|
|
308
|
+
drawContent(e, t) {
|
|
215
309
|
t.fillStyle && (e.fillStyle = this.resolveFillStyle(e, t)), t.strokeStyle && (e.strokeStyle = t.strokeStyle), t.lineWidth !== void 0 && (e.lineWidth = t.lineWidth);
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
218
|
-
const
|
|
219
|
-
e.beginPath(), e.rect(
|
|
310
|
+
const i = O(t);
|
|
311
|
+
if (i && (e.filter = i), t.clipTop !== void 0 || t.clipRight !== void 0 || t.clipBottom !== void 0 || t.clipLeft !== void 0) {
|
|
312
|
+
const s = this.getTargetBounds(t), o = s.x + (t.clipLeft ?? 0) / 100 * s.width, a = s.x + s.width - (t.clipRight ?? 0) / 100 * s.width, n = s.y + (t.clipTop ?? 0) / 100 * s.height, c = s.y + s.height - (t.clipBottom ?? 0) / 100 * s.height;
|
|
313
|
+
e.beginPath(), e.rect(o, n, Math.max(0, a - o), Math.max(0, c - n)), e.clip();
|
|
220
314
|
}
|
|
221
315
|
switch (t.type) {
|
|
222
316
|
case "rect":
|
|
@@ -241,7 +335,6 @@ class v {
|
|
|
241
335
|
this.renderCustom(e, t);
|
|
242
336
|
break;
|
|
243
337
|
}
|
|
244
|
-
e.restore();
|
|
245
338
|
}
|
|
246
339
|
/**
|
|
247
340
|
* Resolve a fill style to a canvas-compatible value.
|
|
@@ -250,14 +343,14 @@ class v {
|
|
|
250
343
|
const i = t.fillStyle;
|
|
251
344
|
if (!i) return "transparent";
|
|
252
345
|
if (typeof i == "string") return i;
|
|
253
|
-
const
|
|
254
|
-
return i.type === "linear" ? this.createLinearGradient(e, i,
|
|
346
|
+
const s = this.getTargetBounds(t);
|
|
347
|
+
return i.type === "linear" ? this.createLinearGradient(e, i, s) : this.createRadialGradient(e, i, s);
|
|
255
348
|
}
|
|
256
349
|
/**
|
|
257
350
|
* Create a canvas linear gradient from a LinearGradient definition.
|
|
258
351
|
*/
|
|
259
352
|
createLinearGradient(e, t, i) {
|
|
260
|
-
const
|
|
353
|
+
const s = (t.angle - 90) * (Math.PI / 180), o = i.x + i.width / 2, a = i.y + i.height / 2, n = Math.max(i.width, i.height), c = o - Math.cos(s) * n / 2, l = a - Math.sin(s) * n / 2, h = o + Math.cos(s) * n / 2, f = a + Math.sin(s) * n / 2, p = e.createLinearGradient(c, l, h, f);
|
|
261
354
|
for (const u of t.stops)
|
|
262
355
|
p.addColorStop(u.offset, u.color);
|
|
263
356
|
return p;
|
|
@@ -266,9 +359,9 @@ class v {
|
|
|
266
359
|
* Create a canvas radial gradient from a RadialGradient definition.
|
|
267
360
|
*/
|
|
268
361
|
createRadialGradient(e, t, i) {
|
|
269
|
-
const
|
|
270
|
-
for (const
|
|
271
|
-
n.addColorStop(
|
|
362
|
+
const s = i.x + i.width * t.centerX, o = i.y + i.height * t.centerY, a = Math.max(i.width, i.height) * t.radius, n = e.createRadialGradient(s, o, 0, s, o, a);
|
|
363
|
+
for (const c of t.stops)
|
|
364
|
+
n.addColorStop(c.offset, c.color);
|
|
272
365
|
return n;
|
|
273
366
|
}
|
|
274
367
|
/**
|
|
@@ -308,25 +401,25 @@ class v {
|
|
|
308
401
|
* Draw a shape outline-first: the fill (clean) once the outline is complete,
|
|
309
402
|
* then the outline up to `drawOn`, in pencil strokes when sketched.
|
|
310
403
|
*/
|
|
311
|
-
renderOutlined(e, t, i,
|
|
312
|
-
const
|
|
313
|
-
if (i && t.fillStyle &&
|
|
314
|
-
const a = t.sketch ?
|
|
315
|
-
a && (e.lineCap = t.lineCap ?? "round", e.lineJoin = t.lineJoin ?? "round"), o
|
|
404
|
+
renderOutlined(e, t, i, s) {
|
|
405
|
+
const o = Math.min(1, Math.max(0, t.drawOn ?? 1));
|
|
406
|
+
if (i && t.fillStyle && o >= 1 && i(), !t.strokeStyle || o <= 0) return;
|
|
407
|
+
const a = t.sketch ? Q(e, t.sketch, this.time) : void 0;
|
|
408
|
+
a && (e.lineCap = t.lineCap ?? "round", e.lineJoin = t.lineJoin ?? "round"), s(o, a);
|
|
316
409
|
}
|
|
317
410
|
/**
|
|
318
411
|
* Render a rectangle.
|
|
319
412
|
*/
|
|
320
413
|
renderRect(e, t) {
|
|
321
414
|
if (this.drawsOutline(t)) {
|
|
322
|
-
const { x: i, y:
|
|
415
|
+
const { x: i, y: s, width: o, height: a } = t;
|
|
323
416
|
return this.renderOutlined(
|
|
324
417
|
e,
|
|
325
418
|
t,
|
|
326
419
|
() => {
|
|
327
|
-
e.beginPath(), t.borderRadius && t.borderRadius > 0 ? this.roundRect(e, i,
|
|
420
|
+
e.beginPath(), t.borderRadius && t.borderRadius > 0 ? this.roundRect(e, i, s, o, a, t.borderRadius) : e.rect(i, s, o, a), e.fill();
|
|
328
421
|
},
|
|
329
|
-
(n,
|
|
422
|
+
(n, c) => S(e, ie(i, s, o, a, t.borderRadius), n, c)
|
|
330
423
|
);
|
|
331
424
|
}
|
|
332
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();
|
|
@@ -334,25 +427,25 @@ class v {
|
|
|
334
427
|
/**
|
|
335
428
|
* Draw a rounded rectangle path.
|
|
336
429
|
*/
|
|
337
|
-
roundRect(e, t, i,
|
|
338
|
-
const n = Math.min(a,
|
|
339
|
-
e.moveTo(t + n, i), e.lineTo(t +
|
|
430
|
+
roundRect(e, t, i, s, o, a) {
|
|
431
|
+
const n = Math.min(a, s / 2, o / 2);
|
|
432
|
+
e.moveTo(t + n, i), e.lineTo(t + s - n, i), e.arcTo(t + s, i, t + s, i + n, n), e.lineTo(t + s, i + o - n), e.arcTo(t + s, i + o, t + s - n, i + o, n), e.lineTo(t + n, i + o), e.arcTo(t, i + o, t, i + o - n, n), e.lineTo(t, i + n), e.arcTo(t, i, t + n, i, n);
|
|
340
433
|
}
|
|
341
434
|
/**
|
|
342
435
|
* Render a circle.
|
|
343
436
|
*/
|
|
344
437
|
renderCircle(e, t) {
|
|
345
438
|
if (this.drawsOutline(t)) {
|
|
346
|
-
const { x: i, y:
|
|
439
|
+
const { x: i, y: s, radius: o } = t;
|
|
347
440
|
return this.renderOutlined(
|
|
348
441
|
e,
|
|
349
442
|
t,
|
|
350
443
|
() => {
|
|
351
|
-
e.beginPath(), e.arc(i,
|
|
444
|
+
e.beginPath(), e.arc(i, s, o, 0, Math.PI * 2), e.fill();
|
|
352
445
|
},
|
|
353
446
|
(a, n) => {
|
|
354
|
-
if (n) return n.circle(i,
|
|
355
|
-
e.beginPath(), e.arc(i,
|
|
447
|
+
if (n) return n.circle(i, s, o, a);
|
|
448
|
+
e.beginPath(), e.arc(i, s, o, -Math.PI / 2, -Math.PI / 2 + Math.PI * 2 * a), e.stroke();
|
|
356
449
|
}
|
|
357
450
|
);
|
|
358
451
|
}
|
|
@@ -362,11 +455,11 @@ class v {
|
|
|
362
455
|
* Render text.
|
|
363
456
|
*/
|
|
364
457
|
renderText(e, t) {
|
|
365
|
-
const i = t.fontSize ?? 16,
|
|
366
|
-
if (e.font = `${
|
|
458
|
+
const i = t.fontSize ?? 16, s = t.fontFamily ?? "sans-serif", o = t.fontWeight ?? 400;
|
|
459
|
+
if (e.font = `${o} ${i}px ${s}`, e.textAlign = t.textAlign ?? "left", e.textBaseline = t.textBaseline ?? "top", t.fillStyle) {
|
|
367
460
|
if (t.shine !== void 0 && typeof t.fillStyle == "string") {
|
|
368
|
-
const a = e.measureText(t.text).width, n = t.textAlign ?? "left",
|
|
369
|
-
for (const h of
|
|
461
|
+
const a = e.measureText(t.text).width, n = t.textAlign ?? "left", c = n === "center" ? t.x - a / 2 : n === "right" ? t.x - a : t.x, l = e.createLinearGradient(c, t.y, c + a, t.y);
|
|
462
|
+
for (const h of L(t.shine, t.fillStyle))
|
|
370
463
|
l.addColorStop(h.offset, h.color);
|
|
371
464
|
e.fillStyle = l;
|
|
372
465
|
}
|
|
@@ -382,12 +475,12 @@ class v {
|
|
|
382
475
|
const i = [
|
|
383
476
|
{ x: t.x, y: t.y },
|
|
384
477
|
{ x: t.x2, y: t.y2 }
|
|
385
|
-
],
|
|
478
|
+
], s = Math.hypot(t.x2 - t.x, t.y2 - t.y);
|
|
386
479
|
return this.renderOutlined(
|
|
387
480
|
e,
|
|
388
481
|
t,
|
|
389
482
|
void 0,
|
|
390
|
-
(
|
|
483
|
+
(o, a) => S(e, [{ kind: "line", points: i, length: s }], o, a)
|
|
391
484
|
);
|
|
392
485
|
}
|
|
393
486
|
e.beginPath(), e.moveTo(t.x, t.y), e.lineTo(t.x2, t.y2), t.strokeStyle && e.stroke(), e.closePath();
|
|
@@ -403,7 +496,7 @@ class v {
|
|
|
403
496
|
e,
|
|
404
497
|
t,
|
|
405
498
|
() => e.fill(i),
|
|
406
|
-
(
|
|
499
|
+
(s, o) => S(e, x(t.d), s, o)
|
|
407
500
|
);
|
|
408
501
|
t.fillStyle && e.fill(i), t.strokeStyle && e.stroke(i);
|
|
409
502
|
}
|
|
@@ -413,13 +506,13 @@ class v {
|
|
|
413
506
|
renderImage(e, t) {
|
|
414
507
|
if (!t.image) return;
|
|
415
508
|
t.opacity !== void 0 && (e.globalAlpha = t.opacity);
|
|
416
|
-
const { x: i, y:
|
|
417
|
-
let p = i, u =
|
|
509
|
+
const { x: i, y: s, width: o, height: a } = t, n = t.objectFit ?? "fill", c = t.borderRadius ?? 0, l = t.image, h = l.naturalWidth || l.videoWidth || l.width || o, f = l.naturalHeight || l.videoHeight || l.height || a;
|
|
510
|
+
let p = i, u = s, d = o, m = a;
|
|
418
511
|
if (n !== "fill" && h > 0 && f > 0) {
|
|
419
|
-
const y = n === "cover" ? Math.max(
|
|
420
|
-
d = h * y, m = f * y, p = i + (
|
|
512
|
+
const y = n === "cover" ? Math.max(o / h, a / f) : Math.min(o / h, a / f);
|
|
513
|
+
d = h * y, m = f * y, p = i + (o - d) / 2, u = s + (a - m) / 2;
|
|
421
514
|
}
|
|
422
|
-
e.save(), e.beginPath(),
|
|
515
|
+
e.save(), e.beginPath(), c > 0 && typeof e.roundRect == "function" ? e.roundRect(i, s, o, a, c) : e.rect(i, s, o, a), e.clip(), e.drawImage(t.image, p, u, d, m), e.restore();
|
|
423
516
|
}
|
|
424
517
|
/**
|
|
425
518
|
* Render a custom target by calling its draw function in local coordinates.
|
|
@@ -522,12 +615,56 @@ class v {
|
|
|
522
615
|
*/
|
|
523
616
|
static loadImage(e) {
|
|
524
617
|
return new Promise((t, i) => {
|
|
525
|
-
const
|
|
526
|
-
|
|
618
|
+
const s = new Image();
|
|
619
|
+
s.onload = () => t(s), s.onerror = i, s.src = e;
|
|
527
620
|
});
|
|
528
621
|
}
|
|
529
622
|
}
|
|
530
|
-
|
|
623
|
+
function se(r, e) {
|
|
624
|
+
const t = r.length / 4, i = new Float32Array(t * 3), s = Math.min(0.999, Math.max(0, e));
|
|
625
|
+
for (let o = 0; o < t; o++) {
|
|
626
|
+
const a = r[o * 4] / 255, n = r[o * 4 + 1] / 255, c = r[o * 4 + 2] / 255, l = r[o * 4 + 3] / 255, h = Math.max(a, n, c);
|
|
627
|
+
if (h <= s) continue;
|
|
628
|
+
const f = (h - s) / (1 - s) * l / h;
|
|
629
|
+
i[o * 3] = a * f, i[o * 3 + 1] = n * f, i[o * 3 + 2] = c * f;
|
|
630
|
+
}
|
|
631
|
+
return i;
|
|
632
|
+
}
|
|
633
|
+
function k(r, e, t, i, s) {
|
|
634
|
+
const o = new Float32Array(r.length), a = s ? t : e, n = s ? e : t, c = (h, f) => (s ? 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 p = 0;
|
|
638
|
+
for (let u = -i; u <= i; u++) p += r[c(h, Math.min(n - 1, Math.max(0, u))) + f];
|
|
639
|
+
for (let u = 0; u < n; u++) {
|
|
640
|
+
o[c(h, u) + f] = p / l;
|
|
641
|
+
const d = r[c(h, Math.max(0, u - i)) + f], m = r[c(h, Math.min(n - 1, u + i + 1)) + f];
|
|
642
|
+
p += m - d;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return o;
|
|
646
|
+
}
|
|
647
|
+
function E(r, e, t, i) {
|
|
648
|
+
const s = Math.max(1, Math.round(i / Math.sqrt(3)));
|
|
649
|
+
let o = r;
|
|
650
|
+
for (let a = 0; a < 3; a++)
|
|
651
|
+
o = k(o, e, t, s, !0), o = k(o, e, t, s, !1);
|
|
652
|
+
return o;
|
|
653
|
+
}
|
|
654
|
+
function Te(r, e = {}) {
|
|
655
|
+
const t = r.canvas, i = t.width, s = t.height;
|
|
656
|
+
if (!(i > 0 && s > 0)) return;
|
|
657
|
+
const o = Math.max(1, Math.round(e.downsample ?? 4)), a = Math.max(1, Math.ceil(i / o)), n = Math.max(1, Math.ceil(s / o)), c = F(r, a, n), l = c?.getContext("2d");
|
|
658
|
+
if (!c || !l) return;
|
|
659
|
+
l.imageSmoothingEnabled = !0, l.drawImage(r.canvas, 0, 0, a, n);
|
|
660
|
+
const h = se(l.getImageData(0, 0, a, n).data, e.threshold ?? 0.55), f = (e.radius ?? Math.max(i, s) * 0.02) / o, p = E(h, a, n, f), u = E(h, a, n, f * 3), d = e.halo ?? 0.6, m = l.createImageData(a, n);
|
|
661
|
+
for (let y = 0; y < a * n; y++) {
|
|
662
|
+
for (let w = 0; w < 3; w++) m.data[y * 4 + w] = Math.round(Math.min(1, p[y * 3 + w] + u[y * 3 + w] * d) * 255);
|
|
663
|
+
m.data[y * 4 + 3] = 255;
|
|
664
|
+
}
|
|
665
|
+
l.putImageData(m, 0, 0), r.save(), r.setTransform(1, 0, 0, 1, 0, 0), r.globalCompositeOperation = "lighter", r.globalAlpha = Math.max(0, e.strength ?? 0.9), r.imageSmoothingEnabled = !0, r.drawImage(c, 0, 0, i, s), r.restore();
|
|
666
|
+
}
|
|
667
|
+
const M = "http://www.w3.org/2000/svg", oe = /* @__PURE__ */ new Set([
|
|
531
668
|
"fill",
|
|
532
669
|
"stroke",
|
|
533
670
|
"d",
|
|
@@ -547,7 +684,7 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
|
|
|
547
684
|
"height",
|
|
548
685
|
"viewBox",
|
|
549
686
|
"preserveAspectRatio"
|
|
550
|
-
]),
|
|
687
|
+
]), X = {
|
|
551
688
|
strokeWidth: "stroke-width",
|
|
552
689
|
strokeLinecap: "stroke-linecap",
|
|
553
690
|
strokeLinejoin: "stroke-linejoin",
|
|
@@ -558,7 +695,7 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
|
|
|
558
695
|
strokeOpacity: "stroke-opacity",
|
|
559
696
|
borderRadius: "rx"
|
|
560
697
|
// Map CSS borderRadius to SVG rx
|
|
561
|
-
},
|
|
698
|
+
}, ne = /* @__PURE__ */ new Set([
|
|
562
699
|
"x",
|
|
563
700
|
// Position x treated as translateX
|
|
564
701
|
"y",
|
|
@@ -566,8 +703,10 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
|
|
|
566
703
|
"translateX",
|
|
567
704
|
"translateY",
|
|
568
705
|
"rotate",
|
|
706
|
+
"rotateZ",
|
|
569
707
|
"rotateX",
|
|
570
708
|
"rotateY",
|
|
709
|
+
"z",
|
|
571
710
|
"scale",
|
|
572
711
|
"scaleX",
|
|
573
712
|
"scaleY",
|
|
@@ -577,8 +716,8 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
|
|
|
577
716
|
"motionPathX",
|
|
578
717
|
"motionPathY",
|
|
579
718
|
"motionPathRotate"
|
|
580
|
-
]),
|
|
581
|
-
class
|
|
719
|
+
]), re = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]);
|
|
720
|
+
class ve {
|
|
582
721
|
targets = /* @__PURE__ */ new Map();
|
|
583
722
|
/**
|
|
584
723
|
* Register an SVG element as an animation target.
|
|
@@ -609,51 +748,53 @@ class oe {
|
|
|
609
748
|
*/
|
|
610
749
|
applyState(e) {
|
|
611
750
|
for (const [t, i] of e.values) {
|
|
612
|
-
const
|
|
613
|
-
|
|
751
|
+
const s = this.targets.get(t);
|
|
752
|
+
s && this.applyProperties(s, i);
|
|
614
753
|
}
|
|
615
754
|
}
|
|
616
755
|
/**
|
|
617
756
|
* Apply properties to a single SVG element.
|
|
618
757
|
*/
|
|
619
758
|
applyProperties(e, t) {
|
|
620
|
-
const i = {}
|
|
621
|
-
let
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
759
|
+
const i = {};
|
|
760
|
+
let s = null;
|
|
761
|
+
const o = {}, a = {}, n = {};
|
|
762
|
+
let c = !1;
|
|
763
|
+
for (const [l, h] of t)
|
|
764
|
+
l !== "drawOn" && (ne.has(l) ? i[l] = h : l === "quaternion" ? s = q(h) : l === "originX" || l === "originY" ? typeof h == "number" && (o[l] = h) : l === "perspective" ? typeof h == "number" && (i.perspective = h) : re.has(l) ? typeof h == "number" && (a[l] = h) : z.has(l) ? (n[l] = h, c = !0) : l === "text" ? typeof h == "string" && j(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));
|
|
765
|
+
if (Object.keys(i).length > 0 || s) {
|
|
766
|
+
const l = this.buildCssTransformString(i, s);
|
|
767
|
+
e.style.transform = l, Z(e);
|
|
627
768
|
}
|
|
628
769
|
if (Object.keys(o).length > 0) {
|
|
629
|
-
const
|
|
630
|
-
|
|
770
|
+
const l = e.style;
|
|
771
|
+
l.transformBox = "fill-box", l.transformOrigin = `${o.originX ?? 50}% ${o.originY ?? 50}%`;
|
|
631
772
|
}
|
|
632
|
-
if (Object.keys(
|
|
633
|
-
const
|
|
634
|
-
e.style.clipPath = `inset(${
|
|
773
|
+
if (Object.keys(a).length > 0) {
|
|
774
|
+
const l = a.clipTop ?? 0, h = a.clipRight ?? 0, f = a.clipBottom ?? 0, p = a.clipLeft ?? 0;
|
|
775
|
+
e.style.clipPath = `inset(${l}% ${h}% ${f}% ${p}%)`;
|
|
635
776
|
}
|
|
636
|
-
if (
|
|
637
|
-
const
|
|
638
|
-
|
|
777
|
+
if (c) {
|
|
778
|
+
const l = O(n);
|
|
779
|
+
l && (e.style.filter = l);
|
|
639
780
|
}
|
|
640
781
|
}
|
|
641
782
|
/**
|
|
642
783
|
* Build a CSS transform string (for use with transform-origin).
|
|
643
784
|
*/
|
|
644
|
-
buildCssTransformString(e) {
|
|
645
|
-
const
|
|
646
|
-
e.perspective !== void 0 &&
|
|
647
|
-
const
|
|
648
|
-
(
|
|
649
|
-
const
|
|
650
|
-
if (
|
|
651
|
-
|
|
785
|
+
buildCssTransformString(e, t = null) {
|
|
786
|
+
const i = [];
|
|
787
|
+
e.perspective !== void 0 && e.perspective > 0 && i.push(`perspective(${e.perspective}px)`);
|
|
788
|
+
const s = e.motionPathX ?? e.x ?? e.translateX, o = e.motionPathY ?? e.y ?? e.translateY;
|
|
789
|
+
e.z !== void 0 ? i.push(`translate3d(${s ?? 0}px, ${o ?? 0}px, ${e.z}px)`) : (s !== void 0 || o !== void 0) && i.push(`translate(${s ?? 0}px, ${o ?? 0}px)`);
|
|
790
|
+
const a = e.motionPathRotate ?? e.rotate ?? e.rotateZ;
|
|
791
|
+
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)
|
|
792
|
+
i.push(`scale(${e.scale})`);
|
|
652
793
|
else if (e.scaleX !== void 0 || e.scaleY !== void 0) {
|
|
653
|
-
const
|
|
654
|
-
|
|
794
|
+
const n = e.scaleX ?? 1, c = e.scaleY ?? 1;
|
|
795
|
+
i.push(`scale(${n}, ${c})`);
|
|
655
796
|
}
|
|
656
|
-
return e.skewX !== void 0 &&
|
|
797
|
+
return e.skewX !== void 0 && i.push(`skewX(${e.skewX}deg)`), e.skewY !== void 0 && i.push(`skewY(${e.skewY}deg)`), i.join(" ");
|
|
657
798
|
}
|
|
658
799
|
/**
|
|
659
800
|
* Apply a single attribute to an SVG element.
|
|
@@ -664,39 +805,39 @@ class oe {
|
|
|
664
805
|
* gradient lives in the owner SVG's <defs> and is reused across frames.
|
|
665
806
|
*/
|
|
666
807
|
applyShine(e, t) {
|
|
667
|
-
const i = e.ownerSVGElement,
|
|
668
|
-
if (!i || !
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
const a =
|
|
808
|
+
const i = e.ownerSVGElement, s = e.ownerDocument;
|
|
809
|
+
if (!i || !s) return;
|
|
810
|
+
const o = e;
|
|
811
|
+
o.dataset.shineBase || (o.dataset.shineBase = e.getAttribute("fill") || "#000000");
|
|
812
|
+
const a = o.dataset.shineBase;
|
|
672
813
|
let n = i.querySelector("defs");
|
|
673
|
-
n || (n =
|
|
674
|
-
let
|
|
675
|
-
for (l || (
|
|
676
|
-
for (const h of
|
|
677
|
-
const f =
|
|
814
|
+
n || (n = s.createElementNS(M, "defs"), i.insertBefore(n, i.firstChild));
|
|
815
|
+
let c = o.dataset.shineGrad, l = c ? n.querySelector(`#${c}`) : null;
|
|
816
|
+
for (l || (c = `tinyfly-shine-${Math.random().toString(36).slice(2, 9)}`, o.dataset.shineGrad = c, l = s.createElementNS(M, "linearGradient"), l.setAttribute("id", c), n.appendChild(l)); l.firstChild; ) l.removeChild(l.firstChild);
|
|
817
|
+
for (const h of L(t, a)) {
|
|
818
|
+
const f = s.createElementNS(M, "stop");
|
|
678
819
|
f.setAttribute("offset", String(h.offset)), f.setAttribute("stop-color", h.color), l.appendChild(f);
|
|
679
820
|
}
|
|
680
|
-
e.setAttribute("fill", `url(#${
|
|
821
|
+
e.setAttribute("fill", `url(#${c})`);
|
|
681
822
|
}
|
|
682
823
|
applyAttribute(e, t, i) {
|
|
683
|
-
let
|
|
684
|
-
|
|
685
|
-
const
|
|
686
|
-
e.setAttribute(
|
|
824
|
+
let s = t;
|
|
825
|
+
X[t] ? s = X[t] : oe.has(t) && (s = t);
|
|
826
|
+
const o = Array.isArray(i) ? i.join(" ") : String(i);
|
|
827
|
+
e.setAttribute(s, o);
|
|
687
828
|
}
|
|
688
829
|
}
|
|
689
|
-
const
|
|
830
|
+
const ae = `
|
|
690
831
|
attribute vec2 a_position;
|
|
691
832
|
attribute vec2 a_texCoord;
|
|
692
|
-
uniform
|
|
833
|
+
uniform mat4 u_matrix;
|
|
693
834
|
varying vec2 v_texCoord;
|
|
694
835
|
void main() {
|
|
695
|
-
|
|
696
|
-
gl_Position = vec4(
|
|
836
|
+
// w carries the perspective, so textures are interpolated perspective-correct.
|
|
837
|
+
gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);
|
|
697
838
|
v_texCoord = a_texCoord;
|
|
698
839
|
}
|
|
699
|
-
`,
|
|
840
|
+
`, ce = `
|
|
700
841
|
precision mediump float;
|
|
701
842
|
uniform vec4 u_color;
|
|
702
843
|
uniform sampler2D u_texture;
|
|
@@ -707,7 +848,7 @@ void main() {
|
|
|
707
848
|
vec4 color = u_useTexture ? texture2D(u_texture, v_texCoord) : u_color;
|
|
708
849
|
gl_FragColor = vec4(color.rgb, color.a * u_opacity);
|
|
709
850
|
}
|
|
710
|
-
`,
|
|
851
|
+
`, le = /* @__PURE__ */ new Set([
|
|
711
852
|
"x",
|
|
712
853
|
"y",
|
|
713
854
|
"width",
|
|
@@ -715,6 +856,10 @@ void main() {
|
|
|
715
856
|
"opacity",
|
|
716
857
|
"rotate",
|
|
717
858
|
"rotateZ",
|
|
859
|
+
"rotateX",
|
|
860
|
+
"rotateY",
|
|
861
|
+
"z",
|
|
862
|
+
"perspective",
|
|
718
863
|
"scale",
|
|
719
864
|
"scaleX",
|
|
720
865
|
"scaleY",
|
|
@@ -724,7 +869,7 @@ void main() {
|
|
|
724
869
|
"motionPathY",
|
|
725
870
|
"motionPathRotate"
|
|
726
871
|
]);
|
|
727
|
-
class
|
|
872
|
+
class be {
|
|
728
873
|
gl;
|
|
729
874
|
program;
|
|
730
875
|
positionBuffer;
|
|
@@ -735,7 +880,7 @@ class se {
|
|
|
735
880
|
basePositions = /* @__PURE__ */ new Map();
|
|
736
881
|
locations;
|
|
737
882
|
constructor(e) {
|
|
738
|
-
this.gl = e, this.program =
|
|
883
|
+
this.gl = e, this.program = ue(e, ae, ce), this.locations = {
|
|
739
884
|
position: e.getAttribLocation(this.program, "a_position"),
|
|
740
885
|
texCoord: e.getAttribLocation(this.program, "a_texCoord"),
|
|
741
886
|
matrix: e.getUniformLocation(this.program, "u_matrix"),
|
|
@@ -743,7 +888,7 @@ class se {
|
|
|
743
888
|
texture: e.getUniformLocation(this.program, "u_texture"),
|
|
744
889
|
useTexture: e.getUniformLocation(this.program, "u_useTexture"),
|
|
745
890
|
opacity: e.getUniformLocation(this.program, "u_opacity")
|
|
746
|
-
}, this.positionBuffer =
|
|
891
|
+
}, this.positionBuffer = Y(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]), this.texCoordBuffer = Y(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]);
|
|
747
892
|
}
|
|
748
893
|
registerTarget(e, t) {
|
|
749
894
|
this.targets.set(e, t), this.basePositions.set(e, { x: t.x, y: t.y });
|
|
@@ -762,79 +907,92 @@ class se {
|
|
|
762
907
|
/** Apply engine state to the registered targets. */
|
|
763
908
|
applyState(e) {
|
|
764
909
|
for (const [t, i] of e.values) {
|
|
765
|
-
const
|
|
766
|
-
if (!
|
|
767
|
-
const
|
|
910
|
+
const s = this.targets.get(t);
|
|
911
|
+
if (!s) continue;
|
|
912
|
+
const o = this.basePositions.get(t) ?? { x: 0, y: 0 };
|
|
768
913
|
for (const [a, n] of i)
|
|
769
|
-
this.applyProperty(
|
|
914
|
+
this.applyProperty(s, o, a, n);
|
|
770
915
|
}
|
|
771
916
|
}
|
|
772
|
-
applyProperty(e, t, i,
|
|
773
|
-
if (typeof
|
|
917
|
+
applyProperty(e, t, i, s) {
|
|
918
|
+
if (typeof s == "number") {
|
|
774
919
|
if (i === "x" || i === "motionPathX") {
|
|
775
|
-
e.x = t.x +
|
|
920
|
+
e.x = t.x + s;
|
|
776
921
|
return;
|
|
777
922
|
}
|
|
778
923
|
if (i === "y" || i === "motionPathY") {
|
|
779
|
-
e.y = t.y +
|
|
924
|
+
e.y = t.y + s;
|
|
780
925
|
return;
|
|
781
926
|
}
|
|
782
927
|
if (i === "rotateZ" || i === "motionPathRotate") {
|
|
783
|
-
e.rotate =
|
|
928
|
+
e.rotate = s;
|
|
784
929
|
return;
|
|
785
930
|
}
|
|
786
|
-
if (
|
|
787
|
-
e[i] =
|
|
931
|
+
if (le.has(i)) {
|
|
932
|
+
e[i] = s;
|
|
788
933
|
return;
|
|
789
934
|
}
|
|
790
935
|
}
|
|
791
|
-
typeof
|
|
936
|
+
typeof s == "string" && i === "fill" && (e.fill = s), i === "quaternion" && Array.isArray(s) && (e.quaternion = s);
|
|
792
937
|
}
|
|
793
938
|
/** Draw every registered target. */
|
|
794
939
|
render() {
|
|
795
940
|
const e = this.gl, { width: t, height: i } = e.canvas;
|
|
796
|
-
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),
|
|
797
|
-
for (const [
|
|
798
|
-
this.drawTarget(
|
|
799
|
-
}
|
|
800
|
-
drawTarget(e, t, i,
|
|
801
|
-
const
|
|
802
|
-
if (
|
|
803
|
-
|
|
941
|
+
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), $(e, this.positionBuffer, this.locations.position), $(e, this.texCoordBuffer, this.locations.texCoord);
|
|
942
|
+
for (const [s, o] of this.targets)
|
|
943
|
+
this.drawTarget(s, o, t, i);
|
|
944
|
+
}
|
|
945
|
+
drawTarget(e, t, i, s) {
|
|
946
|
+
const o = this.gl;
|
|
947
|
+
if (t.backfaceVisibility === "hidden" && I(G(t))) return;
|
|
948
|
+
const a = he(t, i, s);
|
|
949
|
+
if (o.uniformMatrix4fv(this.locations.matrix, !1, a), o.uniform1f(this.locations.opacity, t.opacity ?? 1), t.texture)
|
|
950
|
+
o.bindTexture(o.TEXTURE_2D, this.textureFor(e, t.texture)), o.uniform1i(this.locations.useTexture, 1), o.uniform1i(this.locations.texture, 0);
|
|
804
951
|
else {
|
|
805
|
-
|
|
806
|
-
const [n,
|
|
807
|
-
|
|
952
|
+
o.uniform1i(this.locations.useTexture, 0);
|
|
953
|
+
const [n, c, l] = fe(t.fill ?? "#ffffff");
|
|
954
|
+
o.uniform4f(this.locations.color, n, c, l, 1);
|
|
808
955
|
}
|
|
809
|
-
|
|
956
|
+
o.drawArrays(o.TRIANGLES, 0, 6);
|
|
810
957
|
}
|
|
811
958
|
textureFor(e, t) {
|
|
812
959
|
const i = this.textures.get(e);
|
|
813
960
|
if (i) return i;
|
|
814
|
-
const
|
|
815
|
-
return
|
|
961
|
+
const s = this.gl, o = s.createTexture();
|
|
962
|
+
return s.bindTexture(s.TEXTURE_2D, o), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_S, s.CLAMP_TO_EDGE), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_T, s.CLAMP_TO_EDGE), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MIN_FILTER, s.LINEAR), s.texImage2D(s.TEXTURE_2D, 0, s.RGBA, s.RGBA, s.UNSIGNED_BYTE, t), this.textures.set(e, o), o;
|
|
816
963
|
}
|
|
817
964
|
/** Release GL resources. */
|
|
818
965
|
destroy() {
|
|
819
966
|
this.clearTargets(), this.gl.deleteProgram(this.program), this.gl.deleteBuffer(this.positionBuffer), this.gl.deleteBuffer(this.texCoordBuffer);
|
|
820
967
|
}
|
|
821
968
|
}
|
|
822
|
-
function
|
|
823
|
-
const i = (
|
|
969
|
+
function Pe(r, e, t) {
|
|
970
|
+
const i = (r.scale ?? r.scaleX ?? 1) * r.width, s = (r.scale ?? r.scaleY ?? 1) * r.height, o = (r.originX ?? 50) / 100, a = (r.originY ?? 50) / 100, n = (r.rotate ?? 0) * Math.PI / 180, c = Math.cos(n), l = Math.sin(n), h = -o, f = -a, p = c * i, u = l * i, d = -l * s, m = c * s, y = r.x + p * h + d * f, w = r.y + u * h + m * f, b = 2 / e, P = -2 / t;
|
|
824
971
|
return new Float32Array([
|
|
825
|
-
p *
|
|
972
|
+
p * b,
|
|
826
973
|
u * P,
|
|
827
974
|
0,
|
|
828
|
-
d *
|
|
975
|
+
d * b,
|
|
829
976
|
m * P,
|
|
830
977
|
0,
|
|
831
|
-
y *
|
|
832
|
-
|
|
978
|
+
y * b - 1,
|
|
979
|
+
w * P + 1,
|
|
833
980
|
1
|
|
834
981
|
]);
|
|
835
982
|
}
|
|
836
|
-
function
|
|
837
|
-
const e =
|
|
983
|
+
function G(r) {
|
|
984
|
+
const e = (r.originX ?? 50) / 100, t = (r.originY ?? 50) / 100, i = { x: r.x, y: r.y }, s = T.multiply(
|
|
985
|
+
T.translation([r.x, r.y, 0]),
|
|
986
|
+
T.multiply(T.scaling([r.width, r.height, 1]), T.translation([-e, -t, 0]))
|
|
987
|
+
);
|
|
988
|
+
return T.multiply(C(r, { x: 0, y: 0 }, i), s);
|
|
989
|
+
}
|
|
990
|
+
function he(r, e, t) {
|
|
991
|
+
const i = [2 / e, 0, 0, 0, 0, -2 / t, 0, 0, 0, 0, 0, 0, -1, 1, 0, 1];
|
|
992
|
+
return new Float32Array(T.multiply(i, G(r)));
|
|
993
|
+
}
|
|
994
|
+
function fe(r) {
|
|
995
|
+
const e = r.trim().replace("#", "");
|
|
838
996
|
return e.length === 3 ? [
|
|
839
997
|
Number.parseInt(e[0] + e[0], 16) / 255,
|
|
840
998
|
Number.parseInt(e[1] + e[1], 16) / 255,
|
|
@@ -845,46 +1003,51 @@ function Z(c) {
|
|
|
845
1003
|
Number.parseInt(e.slice(4, 6), 16) / 255
|
|
846
1004
|
] : [1, 1, 1];
|
|
847
1005
|
}
|
|
848
|
-
function
|
|
849
|
-
const i =
|
|
1006
|
+
function ue(r, e, t) {
|
|
1007
|
+
const i = r.createProgram();
|
|
850
1008
|
if (!i) throw new Error("WebGLAdapter: could not create a program");
|
|
851
|
-
if (
|
|
852
|
-
throw new Error(`WebGLAdapter: program link failed — ${
|
|
1009
|
+
if (r.attachShader(i, _(r, r.VERTEX_SHADER, e)), r.attachShader(i, _(r, r.FRAGMENT_SHADER, t)), r.linkProgram(i), !r.getProgramParameter(i, r.LINK_STATUS))
|
|
1010
|
+
throw new Error(`WebGLAdapter: program link failed — ${r.getProgramInfoLog(i)}`);
|
|
853
1011
|
return i;
|
|
854
1012
|
}
|
|
855
|
-
function
|
|
856
|
-
const i =
|
|
1013
|
+
function _(r, e, t) {
|
|
1014
|
+
const i = r.createShader(e);
|
|
857
1015
|
if (!i) throw new Error("WebGLAdapter: could not create a shader");
|
|
858
|
-
if (
|
|
859
|
-
throw new Error(`WebGLAdapter: shader compile failed — ${
|
|
1016
|
+
if (r.shaderSource(i, t), r.compileShader(i), !r.getShaderParameter(i, r.COMPILE_STATUS))
|
|
1017
|
+
throw new Error(`WebGLAdapter: shader compile failed — ${r.getShaderInfoLog(i)}`);
|
|
860
1018
|
return i;
|
|
861
1019
|
}
|
|
862
|
-
function
|
|
863
|
-
const t =
|
|
1020
|
+
function Y(r, e) {
|
|
1021
|
+
const t = r.createBuffer();
|
|
864
1022
|
if (!t) throw new Error("WebGLAdapter: could not create a buffer");
|
|
865
|
-
return
|
|
1023
|
+
return r.bindBuffer(r.ARRAY_BUFFER, t), r.bufferData(r.ARRAY_BUFFER, new Float32Array(e), r.STATIC_DRAW), t;
|
|
866
1024
|
}
|
|
867
|
-
function
|
|
868
|
-
t < 0 || (
|
|
1025
|
+
function $(r, e, t) {
|
|
1026
|
+
t < 0 || (r.bindBuffer(r.ARRAY_BUFFER, e), r.enableVertexAttribArray(t), r.vertexAttribPointer(t, 2, r.FLOAT, !1, 0, 0));
|
|
869
1027
|
}
|
|
870
1028
|
export {
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
1029
|
+
R as CanvasAdapter,
|
|
1030
|
+
xe as DOMAdapter,
|
|
1031
|
+
ve as SVGAdapter,
|
|
1032
|
+
be as WebGLAdapter,
|
|
1033
|
+
Te as applyBloom,
|
|
1034
|
+
Ae as boilFrame,
|
|
1035
|
+
E as boxBlur,
|
|
1036
|
+
se as brightPass,
|
|
1037
|
+
te as buildFlipTracks,
|
|
1038
|
+
F as canvasLike,
|
|
877
1039
|
S as drawOutline,
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
1040
|
+
ye as flip,
|
|
1041
|
+
we as isGradient,
|
|
1042
|
+
fe as parseColor,
|
|
1043
|
+
K as partialPath,
|
|
1044
|
+
ke as pathLength,
|
|
1045
|
+
x as pathOutline,
|
|
1046
|
+
Ee as pointAlong,
|
|
1047
|
+
Pe as quadMatrix,
|
|
1048
|
+
he as quadMatrix3d,
|
|
1049
|
+
ee as recordFlipState,
|
|
1050
|
+
ie as rectOutline,
|
|
1051
|
+
j as setTextContent,
|
|
1052
|
+
Q as sketchPen
|
|
890
1053
|
};
|