@algorisys/tinyfly 0.81.0 → 0.86.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -5
- package/lib/addons/adapters.js +363 -248
- package/lib/addons/characters.js +1658 -1342
- 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/scene-3d-webgl.js +237 -0
- package/lib/addons/scene-3d.js +306 -0
- package/lib/addons/shading-ByG9UXd0.js +85 -0
- package/lib/browser/tinyfly-scene-3d-webgl.iife.js +114 -0
- package/lib/browser/tinyfly-scene-3d.iife.js +3 -0
- package/lib/browser/tinyfly.iife.js +4 -4
- package/lib/browser/tinyfly.js +3295 -2613
- 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 +264 -7
- 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/canvas-adapter.d.ts +36 -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/characters/character.d.ts +20 -1
- package/lib/types/characters/dance.d.ts +47 -0
- package/lib/types/characters/index.d.ts +3 -1
- 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/characters/species/human.d.ts +8 -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/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 +191 -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 +28 -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 {
|
|
2
|
-
import { D as
|
|
3
|
-
import { createTrack as
|
|
4
|
-
import { p as
|
|
5
|
-
import { b as
|
|
6
|
-
function
|
|
1
|
+
import { h as F, e as _, i as Y, a as G, b as g, p as D, t as U, g as W, c as $, q as N, F as z, s as H, d as V } from "./dom-adapter-Cphr2HZn.js";
|
|
2
|
+
import { D as Pe } from "./dom-adapter-Cphr2HZn.js";
|
|
3
|
+
import { createTrack as q, parsePath as C, mat4 as m } from "@algorisys/tinyfly";
|
|
4
|
+
import { p as j, s as Z } from "./sketch-CA8ZXhxI.js";
|
|
5
|
+
import { b as Se, a as Re, c as xe } from "./sketch-CA8ZXhxI.js";
|
|
6
|
+
function J(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, O(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 K(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 = O(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
|
-
T(`${a}-${
|
|
20
|
-
T(`${a}-${
|
|
21
|
-
),
|
|
22
|
-
const d = h.width / f.width,
|
|
23
|
-
d !== 1 && n.push(T(`${a}-${
|
|
19
|
+
T(`${a}-${c}-x`, c, "x", p, 0, i, s),
|
|
20
|
+
T(`${a}-${c}-y`, c, "y", u, 0, i, s)
|
|
21
|
+
), o && f.width > 0 && f.height > 0) {
|
|
22
|
+
const d = h.width / f.width, y = h.height / f.height;
|
|
23
|
+
d !== 1 && n.push(T(`${a}-${c}-sx`, c, "scaleX", d, 1, i, s)), y !== 1 && n.push(T(`${a}-${c}-sy`, c, "scaleY", y, 1, i, s));
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
return n;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
const i =
|
|
30
|
-
return e(),
|
|
28
|
+
function de(r, e, t = {}) {
|
|
29
|
+
const i = J(r);
|
|
30
|
+
return e(), K(i, r, t);
|
|
31
31
|
}
|
|
32
|
-
function T(
|
|
33
|
-
return
|
|
34
|
-
id:
|
|
32
|
+
function T(r, e, t, i, s, o, a) {
|
|
33
|
+
return q({
|
|
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 O(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 I(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 R(
|
|
60
|
+
const M = 12;
|
|
61
|
+
function R(r) {
|
|
62
62
|
const e = [];
|
|
63
63
|
let t, i = -1;
|
|
64
|
-
for (const
|
|
65
|
-
if (
|
|
66
|
-
(!t || i !==
|
|
64
|
+
for (const s of C(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 <= M; p++) {
|
|
72
|
+
const u = p / M, 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 =
|
|
82
|
+
function Q(r, e, t, i, s = 0) {
|
|
83
|
+
const o = Math.max(0, Math.min(s, t / 2, i / 2));
|
|
84
|
+
if (o === 0) return R(`M${r},${e} H${r + t} V${e + i} H${r} Z`);
|
|
85
|
+
const a = r + t, n = e + i;
|
|
86
86
|
return R(
|
|
87
|
-
`M${
|
|
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
|
|
91
|
-
const
|
|
90
|
+
function b(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 = j(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
|
-
return typeof
|
|
107
|
+
function pe(r) {
|
|
108
|
+
return typeof r == "object" && r !== null && "type" in r;
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
function ee(r, e, t) {
|
|
111
|
+
if (typeof OffscreenCanvas < "u") return new OffscreenCanvas(e, t);
|
|
112
|
+
const i = r.canvas;
|
|
113
|
+
if (i?.ownerDocument) {
|
|
114
|
+
const s = i.ownerDocument.createElement("canvas");
|
|
115
|
+
return s.width = e, s.height = t, s;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
return i?.constructor ? new i.constructor(e, t) : null;
|
|
119
|
+
} catch {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
class x {
|
|
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 (x.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 = x.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
|
-
|
|
211
|
-
|
|
221
|
+
if (e.save(), t.opacity !== void 0 && (e.globalAlpha = t.opacity), F(t)) {
|
|
222
|
+
const o = _(t, i, { x: this.getPivotX(t), y: this.getPivotY(t) });
|
|
223
|
+
if (t.backfaceVisibility === "hidden" && Y(o)) {
|
|
224
|
+
e.restore();
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
G(o) ? (e.transform(...g(o)), this.drawContent(e, t)) : this.drawInPerspective(e, t, o), e.restore();
|
|
228
|
+
return;
|
|
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 D(i, s)) {
|
|
258
|
+
const a = U(o.source, o.target);
|
|
259
|
+
if (!a) continue;
|
|
260
|
+
const [n, c, l] = W(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 = ee(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 C(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 };
|
|
212
299
|
}
|
|
213
|
-
e.translate(-a, -n);
|
|
214
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 = $(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 ? Z(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) => b(e, Q(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 I(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) => b(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) => b(e, R(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, y = a;
|
|
418
511
|
if (n !== "fill" && h > 0 && f > 0) {
|
|
419
|
-
const
|
|
420
|
-
d = h *
|
|
512
|
+
const w = n === "cover" ? Math.max(o / h, a / f) : Math.min(o / h, a / f);
|
|
513
|
+
d = h * w, y = f * w, p = i + (o - d) / 2, u = s + (a - y) / 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, y), e.restore();
|
|
423
516
|
}
|
|
424
517
|
/**
|
|
425
518
|
* Render a custom target by calling its draw function in local coordinates.
|
|
@@ -522,12 +615,12 @@ 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
|
-
const
|
|
623
|
+
const S = "http://www.w3.org/2000/svg", te = /* @__PURE__ */ new Set([
|
|
531
624
|
"fill",
|
|
532
625
|
"stroke",
|
|
533
626
|
"d",
|
|
@@ -547,7 +640,7 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
|
|
|
547
640
|
"height",
|
|
548
641
|
"viewBox",
|
|
549
642
|
"preserveAspectRatio"
|
|
550
|
-
]),
|
|
643
|
+
]), A = {
|
|
551
644
|
strokeWidth: "stroke-width",
|
|
552
645
|
strokeLinecap: "stroke-linecap",
|
|
553
646
|
strokeLinejoin: "stroke-linejoin",
|
|
@@ -558,7 +651,7 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
|
|
|
558
651
|
strokeOpacity: "stroke-opacity",
|
|
559
652
|
borderRadius: "rx"
|
|
560
653
|
// Map CSS borderRadius to SVG rx
|
|
561
|
-
},
|
|
654
|
+
}, ie = /* @__PURE__ */ new Set([
|
|
562
655
|
"x",
|
|
563
656
|
// Position x treated as translateX
|
|
564
657
|
"y",
|
|
@@ -566,8 +659,10 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
|
|
|
566
659
|
"translateX",
|
|
567
660
|
"translateY",
|
|
568
661
|
"rotate",
|
|
662
|
+
"rotateZ",
|
|
569
663
|
"rotateX",
|
|
570
664
|
"rotateY",
|
|
665
|
+
"z",
|
|
571
666
|
"scale",
|
|
572
667
|
"scaleX",
|
|
573
668
|
"scaleY",
|
|
@@ -577,8 +672,8 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
|
|
|
577
672
|
"motionPathX",
|
|
578
673
|
"motionPathY",
|
|
579
674
|
"motionPathRotate"
|
|
580
|
-
]),
|
|
581
|
-
class
|
|
675
|
+
]), se = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]);
|
|
676
|
+
class ye {
|
|
582
677
|
targets = /* @__PURE__ */ new Map();
|
|
583
678
|
/**
|
|
584
679
|
* Register an SVG element as an animation target.
|
|
@@ -609,51 +704,53 @@ class oe {
|
|
|
609
704
|
*/
|
|
610
705
|
applyState(e) {
|
|
611
706
|
for (const [t, i] of e.values) {
|
|
612
|
-
const
|
|
613
|
-
|
|
707
|
+
const s = this.targets.get(t);
|
|
708
|
+
s && this.applyProperties(s, i);
|
|
614
709
|
}
|
|
615
710
|
}
|
|
616
711
|
/**
|
|
617
712
|
* Apply properties to a single SVG element.
|
|
618
713
|
*/
|
|
619
714
|
applyProperties(e, t) {
|
|
620
|
-
const i = {}
|
|
621
|
-
let
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
715
|
+
const i = {};
|
|
716
|
+
let s = null;
|
|
717
|
+
const o = {}, a = {}, n = {};
|
|
718
|
+
let c = !1;
|
|
719
|
+
for (const [l, h] of t)
|
|
720
|
+
l !== "drawOn" && (ie.has(l) ? i[l] = h : l === "quaternion" ? s = N(h) : l === "originX" || l === "originY" ? typeof h == "number" && (o[l] = h) : l === "perspective" ? typeof h == "number" && (i.perspective = h) : se.has(l) ? typeof h == "number" && (a[l] = h) : z.has(l) ? (n[l] = h, c = !0) : l === "text" ? typeof h == "string" && H(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));
|
|
721
|
+
if (Object.keys(i).length > 0 || s) {
|
|
722
|
+
const l = this.buildCssTransformString(i, s);
|
|
723
|
+
e.style.transform = l, V(e);
|
|
627
724
|
}
|
|
628
725
|
if (Object.keys(o).length > 0) {
|
|
629
|
-
const
|
|
630
|
-
|
|
726
|
+
const l = e.style;
|
|
727
|
+
l.transformBox = "fill-box", l.transformOrigin = `${o.originX ?? 50}% ${o.originY ?? 50}%`;
|
|
631
728
|
}
|
|
632
|
-
if (Object.keys(
|
|
633
|
-
const
|
|
634
|
-
e.style.clipPath = `inset(${
|
|
729
|
+
if (Object.keys(a).length > 0) {
|
|
730
|
+
const l = a.clipTop ?? 0, h = a.clipRight ?? 0, f = a.clipBottom ?? 0, p = a.clipLeft ?? 0;
|
|
731
|
+
e.style.clipPath = `inset(${l}% ${h}% ${f}% ${p}%)`;
|
|
635
732
|
}
|
|
636
|
-
if (
|
|
637
|
-
const
|
|
638
|
-
|
|
733
|
+
if (c) {
|
|
734
|
+
const l = $(n);
|
|
735
|
+
l && (e.style.filter = l);
|
|
639
736
|
}
|
|
640
737
|
}
|
|
641
738
|
/**
|
|
642
739
|
* Build a CSS transform string (for use with transform-origin).
|
|
643
740
|
*/
|
|
644
|
-
buildCssTransformString(e) {
|
|
645
|
-
const
|
|
646
|
-
e.perspective !== void 0 &&
|
|
647
|
-
const
|
|
648
|
-
(
|
|
649
|
-
const
|
|
650
|
-
if (
|
|
651
|
-
|
|
741
|
+
buildCssTransformString(e, t = null) {
|
|
742
|
+
const i = [];
|
|
743
|
+
e.perspective !== void 0 && e.perspective > 0 && i.push(`perspective(${e.perspective}px)`);
|
|
744
|
+
const s = e.motionPathX ?? e.x ?? e.translateX, o = e.motionPathY ?? e.y ?? e.translateY;
|
|
745
|
+
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)`);
|
|
746
|
+
const a = e.motionPathRotate ?? e.rotate ?? e.rotateZ;
|
|
747
|
+
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
|
+
i.push(`scale(${e.scale})`);
|
|
652
749
|
else if (e.scaleX !== void 0 || e.scaleY !== void 0) {
|
|
653
|
-
const
|
|
654
|
-
|
|
750
|
+
const n = e.scaleX ?? 1, c = e.scaleY ?? 1;
|
|
751
|
+
i.push(`scale(${n}, ${c})`);
|
|
655
752
|
}
|
|
656
|
-
return e.skewX !== void 0 &&
|
|
753
|
+
return e.skewX !== void 0 && i.push(`skewX(${e.skewX}deg)`), e.skewY !== void 0 && i.push(`skewY(${e.skewY}deg)`), i.join(" ");
|
|
657
754
|
}
|
|
658
755
|
/**
|
|
659
756
|
* Apply a single attribute to an SVG element.
|
|
@@ -664,39 +761,39 @@ class oe {
|
|
|
664
761
|
* gradient lives in the owner SVG's <defs> and is reused across frames.
|
|
665
762
|
*/
|
|
666
763
|
applyShine(e, t) {
|
|
667
|
-
const i = e.ownerSVGElement,
|
|
668
|
-
if (!i || !
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
const a =
|
|
764
|
+
const i = e.ownerSVGElement, s = e.ownerDocument;
|
|
765
|
+
if (!i || !s) return;
|
|
766
|
+
const o = e;
|
|
767
|
+
o.dataset.shineBase || (o.dataset.shineBase = e.getAttribute("fill") || "#000000");
|
|
768
|
+
const a = o.dataset.shineBase;
|
|
672
769
|
let n = i.querySelector("defs");
|
|
673
|
-
n || (n =
|
|
674
|
-
let
|
|
675
|
-
for (l || (
|
|
676
|
-
for (const h of
|
|
677
|
-
const f =
|
|
770
|
+
n || (n = s.createElementNS(S, "defs"), i.insertBefore(n, i.firstChild));
|
|
771
|
+
let c = o.dataset.shineGrad, l = c ? n.querySelector(`#${c}`) : null;
|
|
772
|
+
for (l || (c = `tinyfly-shine-${Math.random().toString(36).slice(2, 9)}`, o.dataset.shineGrad = c, l = s.createElementNS(S, "linearGradient"), l.setAttribute("id", c), n.appendChild(l)); l.firstChild; ) l.removeChild(l.firstChild);
|
|
773
|
+
for (const h of I(t, a)) {
|
|
774
|
+
const f = s.createElementNS(S, "stop");
|
|
678
775
|
f.setAttribute("offset", String(h.offset)), f.setAttribute("stop-color", h.color), l.appendChild(f);
|
|
679
776
|
}
|
|
680
|
-
e.setAttribute("fill", `url(#${
|
|
777
|
+
e.setAttribute("fill", `url(#${c})`);
|
|
681
778
|
}
|
|
682
779
|
applyAttribute(e, t, i) {
|
|
683
|
-
let
|
|
684
|
-
|
|
685
|
-
const
|
|
686
|
-
e.setAttribute(
|
|
780
|
+
let s = t;
|
|
781
|
+
A[t] ? s = A[t] : te.has(t) && (s = t);
|
|
782
|
+
const o = Array.isArray(i) ? i.join(" ") : String(i);
|
|
783
|
+
e.setAttribute(s, o);
|
|
687
784
|
}
|
|
688
785
|
}
|
|
689
|
-
const
|
|
786
|
+
const oe = `
|
|
690
787
|
attribute vec2 a_position;
|
|
691
788
|
attribute vec2 a_texCoord;
|
|
692
|
-
uniform
|
|
789
|
+
uniform mat4 u_matrix;
|
|
693
790
|
varying vec2 v_texCoord;
|
|
694
791
|
void main() {
|
|
695
|
-
|
|
696
|
-
gl_Position = vec4(
|
|
792
|
+
// w carries the perspective, so textures are interpolated perspective-correct.
|
|
793
|
+
gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);
|
|
697
794
|
v_texCoord = a_texCoord;
|
|
698
795
|
}
|
|
699
|
-
`,
|
|
796
|
+
`, ne = `
|
|
700
797
|
precision mediump float;
|
|
701
798
|
uniform vec4 u_color;
|
|
702
799
|
uniform sampler2D u_texture;
|
|
@@ -707,7 +804,7 @@ void main() {
|
|
|
707
804
|
vec4 color = u_useTexture ? texture2D(u_texture, v_texCoord) : u_color;
|
|
708
805
|
gl_FragColor = vec4(color.rgb, color.a * u_opacity);
|
|
709
806
|
}
|
|
710
|
-
`,
|
|
807
|
+
`, re = /* @__PURE__ */ new Set([
|
|
711
808
|
"x",
|
|
712
809
|
"y",
|
|
713
810
|
"width",
|
|
@@ -715,6 +812,10 @@ void main() {
|
|
|
715
812
|
"opacity",
|
|
716
813
|
"rotate",
|
|
717
814
|
"rotateZ",
|
|
815
|
+
"rotateX",
|
|
816
|
+
"rotateY",
|
|
817
|
+
"z",
|
|
818
|
+
"perspective",
|
|
718
819
|
"scale",
|
|
719
820
|
"scaleX",
|
|
720
821
|
"scaleY",
|
|
@@ -724,7 +825,7 @@ void main() {
|
|
|
724
825
|
"motionPathY",
|
|
725
826
|
"motionPathRotate"
|
|
726
827
|
]);
|
|
727
|
-
class
|
|
828
|
+
class me {
|
|
728
829
|
gl;
|
|
729
830
|
program;
|
|
730
831
|
positionBuffer;
|
|
@@ -735,7 +836,7 @@ class se {
|
|
|
735
836
|
basePositions = /* @__PURE__ */ new Map();
|
|
736
837
|
locations;
|
|
737
838
|
constructor(e) {
|
|
738
|
-
this.gl = e, this.program =
|
|
839
|
+
this.gl = e, this.program = le(e, oe, ne), this.locations = {
|
|
739
840
|
position: e.getAttribLocation(this.program, "a_position"),
|
|
740
841
|
texCoord: e.getAttribLocation(this.program, "a_texCoord"),
|
|
741
842
|
matrix: e.getUniformLocation(this.program, "u_matrix"),
|
|
@@ -762,79 +863,92 @@ class se {
|
|
|
762
863
|
/** Apply engine state to the registered targets. */
|
|
763
864
|
applyState(e) {
|
|
764
865
|
for (const [t, i] of e.values) {
|
|
765
|
-
const
|
|
766
|
-
if (!
|
|
767
|
-
const
|
|
866
|
+
const s = this.targets.get(t);
|
|
867
|
+
if (!s) continue;
|
|
868
|
+
const o = this.basePositions.get(t) ?? { x: 0, y: 0 };
|
|
768
869
|
for (const [a, n] of i)
|
|
769
|
-
this.applyProperty(
|
|
870
|
+
this.applyProperty(s, o, a, n);
|
|
770
871
|
}
|
|
771
872
|
}
|
|
772
|
-
applyProperty(e, t, i,
|
|
773
|
-
if (typeof
|
|
873
|
+
applyProperty(e, t, i, s) {
|
|
874
|
+
if (typeof s == "number") {
|
|
774
875
|
if (i === "x" || i === "motionPathX") {
|
|
775
|
-
e.x = t.x +
|
|
876
|
+
e.x = t.x + s;
|
|
776
877
|
return;
|
|
777
878
|
}
|
|
778
879
|
if (i === "y" || i === "motionPathY") {
|
|
779
|
-
e.y = t.y +
|
|
880
|
+
e.y = t.y + s;
|
|
780
881
|
return;
|
|
781
882
|
}
|
|
782
883
|
if (i === "rotateZ" || i === "motionPathRotate") {
|
|
783
|
-
e.rotate =
|
|
884
|
+
e.rotate = s;
|
|
784
885
|
return;
|
|
785
886
|
}
|
|
786
|
-
if (
|
|
787
|
-
e[i] =
|
|
887
|
+
if (re.has(i)) {
|
|
888
|
+
e[i] = s;
|
|
788
889
|
return;
|
|
789
890
|
}
|
|
790
891
|
}
|
|
791
|
-
typeof
|
|
892
|
+
typeof s == "string" && i === "fill" && (e.fill = s), i === "quaternion" && Array.isArray(s) && (e.quaternion = s);
|
|
792
893
|
}
|
|
793
894
|
/** Draw every registered target. */
|
|
794
895
|
render() {
|
|
795
896
|
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
|
-
|
|
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), X(e, this.positionBuffer, this.locations.position), X(e, this.texCoordBuffer, this.locations.texCoord);
|
|
898
|
+
for (const [s, o] of this.targets)
|
|
899
|
+
this.drawTarget(s, o, t, i);
|
|
900
|
+
}
|
|
901
|
+
drawTarget(e, t, i, s) {
|
|
902
|
+
const o = this.gl;
|
|
903
|
+
if (t.backfaceVisibility === "hidden" && Y(B(t))) return;
|
|
904
|
+
const a = ae(t, i, s);
|
|
905
|
+
if (o.uniformMatrix4fv(this.locations.matrix, !1, a), o.uniform1f(this.locations.opacity, t.opacity ?? 1), t.texture)
|
|
906
|
+
o.bindTexture(o.TEXTURE_2D, this.textureFor(e, t.texture)), o.uniform1i(this.locations.useTexture, 1), o.uniform1i(this.locations.texture, 0);
|
|
804
907
|
else {
|
|
805
|
-
|
|
806
|
-
const [n,
|
|
807
|
-
|
|
908
|
+
o.uniform1i(this.locations.useTexture, 0);
|
|
909
|
+
const [n, c, l] = ce(t.fill ?? "#ffffff");
|
|
910
|
+
o.uniform4f(this.locations.color, n, c, l, 1);
|
|
808
911
|
}
|
|
809
|
-
|
|
912
|
+
o.drawArrays(o.TRIANGLES, 0, 6);
|
|
810
913
|
}
|
|
811
914
|
textureFor(e, t) {
|
|
812
915
|
const i = this.textures.get(e);
|
|
813
916
|
if (i) return i;
|
|
814
|
-
const
|
|
815
|
-
return
|
|
917
|
+
const s = this.gl, o = s.createTexture();
|
|
918
|
+
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
919
|
}
|
|
817
920
|
/** Release GL resources. */
|
|
818
921
|
destroy() {
|
|
819
922
|
this.clearTargets(), this.gl.deleteProgram(this.program), this.gl.deleteBuffer(this.positionBuffer), this.gl.deleteBuffer(this.texCoordBuffer);
|
|
820
923
|
}
|
|
821
924
|
}
|
|
822
|
-
function
|
|
823
|
-
const i = (
|
|
925
|
+
function we(r, e, t) {
|
|
926
|
+
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, y = c * s, w = r.x + p * h + d * f, L = r.y + u * h + y * f, v = 2 / e, P = -2 / t;
|
|
824
927
|
return new Float32Array([
|
|
825
|
-
p *
|
|
928
|
+
p * v,
|
|
826
929
|
u * P,
|
|
827
930
|
0,
|
|
828
|
-
d *
|
|
829
|
-
|
|
931
|
+
d * v,
|
|
932
|
+
y * P,
|
|
830
933
|
0,
|
|
831
|
-
|
|
832
|
-
|
|
934
|
+
w * v - 1,
|
|
935
|
+
L * P + 1,
|
|
833
936
|
1
|
|
834
937
|
]);
|
|
835
938
|
}
|
|
836
|
-
function
|
|
837
|
-
const e =
|
|
939
|
+
function B(r) {
|
|
940
|
+
const e = (r.originX ?? 50) / 100, t = (r.originY ?? 50) / 100, i = { x: r.x, y: r.y }, s = m.multiply(
|
|
941
|
+
m.translation([r.x, r.y, 0]),
|
|
942
|
+
m.multiply(m.scaling([r.width, r.height, 1]), m.translation([-e, -t, 0]))
|
|
943
|
+
);
|
|
944
|
+
return m.multiply(_(r, { x: 0, y: 0 }, i), s);
|
|
945
|
+
}
|
|
946
|
+
function ae(r, e, t) {
|
|
947
|
+
const i = [2 / e, 0, 0, 0, 0, -2 / t, 0, 0, 0, 0, 0, 0, -1, 1, 0, 1];
|
|
948
|
+
return new Float32Array(m.multiply(i, B(r)));
|
|
949
|
+
}
|
|
950
|
+
function ce(r) {
|
|
951
|
+
const e = r.trim().replace("#", "");
|
|
838
952
|
return e.length === 3 ? [
|
|
839
953
|
Number.parseInt(e[0] + e[0], 16) / 255,
|
|
840
954
|
Number.parseInt(e[1] + e[1], 16) / 255,
|
|
@@ -845,46 +959,47 @@ function Z(c) {
|
|
|
845
959
|
Number.parseInt(e.slice(4, 6), 16) / 255
|
|
846
960
|
] : [1, 1, 1];
|
|
847
961
|
}
|
|
848
|
-
function
|
|
849
|
-
const i =
|
|
962
|
+
function le(r, e, t) {
|
|
963
|
+
const i = r.createProgram();
|
|
850
964
|
if (!i) throw new Error("WebGLAdapter: could not create a program");
|
|
851
|
-
if (
|
|
852
|
-
throw new Error(`WebGLAdapter: program link failed — ${
|
|
965
|
+
if (r.attachShader(i, k(r, r.VERTEX_SHADER, e)), r.attachShader(i, k(r, r.FRAGMENT_SHADER, t)), r.linkProgram(i), !r.getProgramParameter(i, r.LINK_STATUS))
|
|
966
|
+
throw new Error(`WebGLAdapter: program link failed — ${r.getProgramInfoLog(i)}`);
|
|
853
967
|
return i;
|
|
854
968
|
}
|
|
855
|
-
function
|
|
856
|
-
const i =
|
|
969
|
+
function k(r, e, t) {
|
|
970
|
+
const i = r.createShader(e);
|
|
857
971
|
if (!i) throw new Error("WebGLAdapter: could not create a shader");
|
|
858
|
-
if (
|
|
859
|
-
throw new Error(`WebGLAdapter: shader compile failed — ${
|
|
972
|
+
if (r.shaderSource(i, t), r.compileShader(i), !r.getShaderParameter(i, r.COMPILE_STATUS))
|
|
973
|
+
throw new Error(`WebGLAdapter: shader compile failed — ${r.getShaderInfoLog(i)}`);
|
|
860
974
|
return i;
|
|
861
975
|
}
|
|
862
|
-
function E(
|
|
863
|
-
const t =
|
|
976
|
+
function E(r, e) {
|
|
977
|
+
const t = r.createBuffer();
|
|
864
978
|
if (!t) throw new Error("WebGLAdapter: could not create a buffer");
|
|
865
|
-
return
|
|
979
|
+
return r.bindBuffer(r.ARRAY_BUFFER, t), r.bufferData(r.ARRAY_BUFFER, new Float32Array(e), r.STATIC_DRAW), t;
|
|
866
980
|
}
|
|
867
|
-
function
|
|
868
|
-
t < 0 || (
|
|
981
|
+
function X(r, e, t) {
|
|
982
|
+
t < 0 || (r.bindBuffer(r.ARRAY_BUFFER, e), r.enableVertexAttribArray(t), r.vertexAttribPointer(t, 2, r.FLOAT, !1, 0, 0));
|
|
869
983
|
}
|
|
870
984
|
export {
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
985
|
+
x as CanvasAdapter,
|
|
986
|
+
Pe as DOMAdapter,
|
|
987
|
+
ye as SVGAdapter,
|
|
988
|
+
me as WebGLAdapter,
|
|
989
|
+
Se as boilFrame,
|
|
990
|
+
K as buildFlipTracks,
|
|
991
|
+
b as drawOutline,
|
|
992
|
+
de as flip,
|
|
993
|
+
pe as isGradient,
|
|
994
|
+
ce as parseColor,
|
|
995
|
+
j as partialPath,
|
|
996
|
+
Re as pathLength,
|
|
883
997
|
R as pathOutline,
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
998
|
+
xe as pointAlong,
|
|
999
|
+
we as quadMatrix,
|
|
1000
|
+
ae as quadMatrix3d,
|
|
1001
|
+
J as recordFlipState,
|
|
1002
|
+
Q as rectOutline,
|
|
1003
|
+
H as setTextContent,
|
|
1004
|
+
Z as sketchPen
|
|
890
1005
|
};
|