@fabiplay/engine 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fabi-play-engine.js +1 -105
- package/dist/fabi-play-engine.lite.js +1 -105
- package/dist/fabi-play-engine.lite.umd.js +1038 -972
- package/dist/fabi-play-engine.lite.umd.min.js +1 -105
- package/dist/fabi-play-engine.umd.js +1225 -1131
- package/dist/fabi-play-engine.umd.min.js +1 -105
- package/dist/index.development.js +2 -2
- package/dist/index.js +1 -1
- package/dist/integrity.json +7 -7
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @fabiplay/engine 0.9.
|
|
1
|
+
/*! @fabiplay/engine 0.9.1 (full) | Fabi Play Kit License | https://docs.fabiplay.app */
|
|
2
2
|
(function (root, factory) {
|
|
3
3
|
var script = typeof document !== 'undefined' ? document.currentScript : null;
|
|
4
4
|
if (typeof define === 'function' && define.amd) define([], function () { return factory(script); });
|
|
@@ -9,10 +9,39 @@
|
|
|
9
9
|
var module = { exports: {} };
|
|
10
10
|
var exports = module.exports;
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
12
|
+
var __defProps = Object.defineProperties;
|
|
12
13
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
13
15
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
14
17
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
18
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
19
|
+
var __pow = Math.pow;
|
|
15
20
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
21
|
+
var __spreadValues = (a, b) => {
|
|
22
|
+
for (var prop in b || (b = {}))
|
|
23
|
+
if (__hasOwnProp.call(b, prop))
|
|
24
|
+
__defNormalProp(a, prop, b[prop]);
|
|
25
|
+
if (__getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
27
|
+
if (__propIsEnum.call(b, prop))
|
|
28
|
+
__defNormalProp(a, prop, b[prop]);
|
|
29
|
+
}
|
|
30
|
+
return a;
|
|
31
|
+
};
|
|
32
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
33
|
+
var __objRest = (source, exclude) => {
|
|
34
|
+
var target = {};
|
|
35
|
+
for (var prop in source)
|
|
36
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
37
|
+
target[prop] = source[prop];
|
|
38
|
+
if (source != null && __getOwnPropSymbols)
|
|
39
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
40
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
41
|
+
target[prop] = source[prop];
|
|
42
|
+
}
|
|
43
|
+
return target;
|
|
44
|
+
};
|
|
16
45
|
var __export = (target, all) => {
|
|
17
46
|
for (var name in all)
|
|
18
47
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -27,6 +56,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
27
56
|
};
|
|
28
57
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
58
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
59
|
+
var __async = (__this, __arguments, generator) => {
|
|
60
|
+
return new Promise((resolve2, reject) => {
|
|
61
|
+
var fulfilled = (value) => {
|
|
62
|
+
try {
|
|
63
|
+
step(generator.next(value));
|
|
64
|
+
} catch (e) {
|
|
65
|
+
reject(e);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var rejected = (value) => {
|
|
69
|
+
try {
|
|
70
|
+
step(generator.throw(value));
|
|
71
|
+
} catch (e) {
|
|
72
|
+
reject(e);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var step = (x) => x.done ? resolve2(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
76
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
77
|
+
});
|
|
78
|
+
};
|
|
30
79
|
|
|
31
80
|
// src/index.ts
|
|
32
81
|
var index_exports = {};
|
|
@@ -87,6 +136,9 @@ __export(index_exports, {
|
|
|
87
136
|
});
|
|
88
137
|
module.exports = __toCommonJS(index_exports);
|
|
89
138
|
|
|
139
|
+
// ../../scripts/global-this.js
|
|
140
|
+
var __fabiGlobalThis = typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {};
|
|
141
|
+
|
|
90
142
|
// ../protocol/src/index.ts
|
|
91
143
|
var LANDMARKS = 33;
|
|
92
144
|
var P = {
|
|
@@ -126,7 +178,10 @@ function aimPoint(who, side, opts = {}) {
|
|
|
126
178
|
const body = Array.isArray(who) ? who : who.body;
|
|
127
179
|
if (!Array.isArray(body)) return null;
|
|
128
180
|
const w2 = side === "left" ? P.leftWrist : P.rightWrist;
|
|
129
|
-
const at = (i) =>
|
|
181
|
+
const at = (i) => {
|
|
182
|
+
var _a;
|
|
183
|
+
return isNumber(body[i * 3]) && isNumber(body[i * 3 + 1]) && ((_a = body[i * 3 + 2]) != null ? _a : 0) >= AIM_VISIBLE ? i : -1;
|
|
184
|
+
};
|
|
130
185
|
if (at(w2) < 0) return null;
|
|
131
186
|
const wx = body[w2 * 3];
|
|
132
187
|
const wy = body[w2 * 3 + 1];
|
|
@@ -194,7 +249,7 @@ var POSE_HEADER = 12;
|
|
|
194
249
|
var POSE_BODY_BYTES = LANDMARKS * 4;
|
|
195
250
|
var poseBytes = (bodies) => POSE_HEADER + bodies * POSE_BODY_BYTES;
|
|
196
251
|
var POSE_MAX_BYTES = poseBytes(MAX_PLAYERS);
|
|
197
|
-
var legacyStorageKey = (key) => key.startsWith("fabi-play.") ?
|
|
252
|
+
var legacyStorageKey = (key) => key.startsWith("fabi-play.") ? "fablee-play.".concat(key.slice("fabi-play.".length)) : null;
|
|
198
253
|
function migrateStorageKey(store, newKey, oldKey = legacyStorageKey(newKey)) {
|
|
199
254
|
if (!store || !oldKey) return;
|
|
200
255
|
try {
|
|
@@ -202,7 +257,7 @@ function migrateStorageKey(store, newKey, oldKey = legacyStorageKey(newKey)) {
|
|
|
202
257
|
if (old === null) return;
|
|
203
258
|
if (store.getItem(newKey) === null) store.setItem(newKey, old);
|
|
204
259
|
store.removeItem(oldKey);
|
|
205
|
-
} catch {
|
|
260
|
+
} catch (e) {
|
|
206
261
|
}
|
|
207
262
|
}
|
|
208
263
|
|
|
@@ -731,6 +786,7 @@ function drawShapes(ctx, shapes) {
|
|
|
731
786
|
for (const s of shapes) drawShape(ctx, s);
|
|
732
787
|
}
|
|
733
788
|
function drawShape(ctx, s) {
|
|
789
|
+
var _a, _b, _c, _d, _e;
|
|
734
790
|
if (s.k === "group") {
|
|
735
791
|
ctx.save();
|
|
736
792
|
ctx.translate(s.x, s.y);
|
|
@@ -749,7 +805,7 @@ function drawShape(ctx, s) {
|
|
|
749
805
|
ctx.arc(s.x, s.y, Math.max(s.r, 0), 0, Math.PI * 2);
|
|
750
806
|
break;
|
|
751
807
|
case "ellipse":
|
|
752
|
-
ctx.ellipse(s.x, s.y, Math.max(s.rx, 0), Math.max(s.ry, 0), s.rot
|
|
808
|
+
ctx.ellipse(s.x, s.y, Math.max(s.rx, 0), Math.max(s.ry, 0), (_a = s.rot) != null ? _a : 0, 0, Math.PI * 2);
|
|
753
809
|
break;
|
|
754
810
|
case "rect":
|
|
755
811
|
roundRect(ctx, s);
|
|
@@ -759,7 +815,7 @@ function drawShape(ctx, s) {
|
|
|
759
815
|
else traceData(ctx, s.d);
|
|
760
816
|
break;
|
|
761
817
|
case "line":
|
|
762
|
-
ctx.moveTo(s.pts[0]
|
|
818
|
+
ctx.moveTo((_b = s.pts[0]) != null ? _b : 0, (_c = s.pts[1]) != null ? _c : 0);
|
|
763
819
|
for (let i = 2; i + 1 < s.pts.length; i += 2) ctx.lineTo(s.pts[i], s.pts[i + 1]);
|
|
764
820
|
break;
|
|
765
821
|
}
|
|
@@ -769,9 +825,9 @@ function drawShape(ctx, s) {
|
|
|
769
825
|
ctx.fillStyle = s.fill;
|
|
770
826
|
ctx.fill();
|
|
771
827
|
}
|
|
772
|
-
if (s.stroke && (s.lw
|
|
828
|
+
if (s.stroke && ((_d = s.lw) != null ? _d : 1) > 0) {
|
|
773
829
|
ctx.strokeStyle = s.stroke;
|
|
774
|
-
ctx.lineWidth = s.lw
|
|
830
|
+
ctx.lineWidth = (_e = s.lw) != null ? _e : 1;
|
|
775
831
|
ctx.stroke();
|
|
776
832
|
}
|
|
777
833
|
ctx.restore();
|
|
@@ -806,7 +862,8 @@ function traceData(ctx, d) {
|
|
|
806
862
|
}
|
|
807
863
|
}
|
|
808
864
|
function pathPoints(d) {
|
|
809
|
-
|
|
865
|
+
var _a;
|
|
866
|
+
if (typeof d === "string") return ((_a = d.match(/-?\d*\.?\d+(?:e-?\d+)?/gi)) != null ? _a : []).map(Number);
|
|
810
867
|
const out = [];
|
|
811
868
|
for (let i = 0; i < d.length; ) {
|
|
812
869
|
const n = PATH_ARGS[d[i++]];
|
|
@@ -817,7 +874,8 @@ function pathPoints(d) {
|
|
|
817
874
|
return out;
|
|
818
875
|
}
|
|
819
876
|
function tracePath(ctx, d) {
|
|
820
|
-
|
|
877
|
+
var _a;
|
|
878
|
+
const tokens = (_a = d.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)) != null ? _a : [];
|
|
821
879
|
let cmd = "";
|
|
822
880
|
let i = 0;
|
|
823
881
|
const n = () => Number(tokens[i++]);
|
|
@@ -905,79 +963,83 @@ var pts = (...xy) => {
|
|
|
905
963
|
return out;
|
|
906
964
|
};
|
|
907
965
|
function headShapes(def, ow) {
|
|
966
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
908
967
|
const p = def.palette;
|
|
909
968
|
const out = [];
|
|
910
969
|
const ol = { stroke: p.outline, lw: ow };
|
|
911
970
|
const has = (x) => def.headExtras.includes(x);
|
|
912
|
-
const extra = (i, fallback) =>
|
|
971
|
+
const extra = (i, fallback) => {
|
|
972
|
+
var _a2, _b2;
|
|
973
|
+
return (_b2 = (_a2 = def.extraColors) == null ? void 0 : _a2[i]) != null ? _b2 : fallback;
|
|
974
|
+
};
|
|
913
975
|
if (has("mane")) {
|
|
914
976
|
const n = 12;
|
|
915
977
|
for (let i = 0; i < n; i++) {
|
|
916
978
|
const a = i / n * Math.PI * 2;
|
|
917
|
-
out.push({ k: "circle", x: Math.cos(a) * 1.02, y: Math.sin(a) * 1 + 0.04, r: 0.42, fill: extra(0, p.accent),
|
|
979
|
+
out.push(__spreadValues({ k: "circle", x: Math.cos(a) * 1.02, y: Math.sin(a) * 1 + 0.04, r: 0.42, fill: extra(0, p.accent) }, ol));
|
|
918
980
|
}
|
|
919
981
|
out.push({ k: "circle", x: 0, y: 0.04, r: 1.08, fill: extra(0, p.accent) });
|
|
920
982
|
}
|
|
921
983
|
if (has("rainbow-mane")) {
|
|
922
|
-
const c = def.extraColors
|
|
984
|
+
const c = (_a = def.extraColors) != null ? _a : ["#f59ac0", "#fbd46a", "#8fd3f4"];
|
|
923
985
|
const locks = [
|
|
924
986
|
[0.98, 0.05, 0.3, 0.5, -0.25],
|
|
925
987
|
[0.92, 0.58, 0.26, 0.42, -0.1],
|
|
926
988
|
[0.62, 0.92, 0.22, 0.32, 0.4]
|
|
927
989
|
];
|
|
928
|
-
locks.forEach(([x, y, rx, ry, rot], i) => out.push({ k: "ellipse", x, y, rx, ry, rot, fill: c[i % c.length],
|
|
990
|
+
locks.forEach(([x, y, rx, ry, rot], i) => out.push(__spreadValues({ k: "ellipse", x, y, rx, ry, rot, fill: c[i % c.length] }, ol)));
|
|
929
991
|
}
|
|
930
992
|
if (has("spikes")) {
|
|
931
993
|
for (const a of [-0.55, 0, 0.55]) {
|
|
932
994
|
const tip = polar(a, 1.48);
|
|
933
995
|
const b1 = polar(a - 0.32, 0.86);
|
|
934
996
|
const b2 = polar(a + 0.32, 0.86);
|
|
935
|
-
out.push({ k: "path", d: roundedPolygon([b1, tip, b2], 0.22), fill: p.accent,
|
|
997
|
+
out.push(__spreadValues({ k: "path", d: roundedPolygon([b1, tip, b2], 0.22), fill: p.accent }, ol));
|
|
936
998
|
}
|
|
937
999
|
}
|
|
938
1000
|
if (has("curl")) {
|
|
939
|
-
out.push({ k: "path", d: smoothClosed([{ x: -0.2, y: -0.9 }, { x: -0.05, y: -1.3 }, { x: 0.32, y: -1.42 }, { x: 0.16, y: -1.18 }, { x: 0.2, y: -0.9 }]), fill: p.body,
|
|
1001
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed([{ x: -0.2, y: -0.9 }, { x: -0.05, y: -1.3 }, { x: 0.32, y: -1.42 }, { x: 0.16, y: -1.18 }, { x: 0.2, y: -0.9 }]), fill: p.body }, ol));
|
|
940
1002
|
}
|
|
941
1003
|
if (has("wool")) {
|
|
942
1004
|
for (let i = 0; i <= 8; i++) {
|
|
943
1005
|
const a = -1.75 + i / 8 * 3.5;
|
|
944
|
-
out.push({ k: "circle", x: Math.sin(a) * 0.98, y: -Math.cos(a) * 0.92 - 0.04, r: 0.34, fill: p.body,
|
|
1006
|
+
out.push(__spreadValues({ k: "circle", x: Math.sin(a) * 0.98, y: -Math.cos(a) * 0.92 - 0.04, r: 0.34, fill: p.body }, ol));
|
|
945
1007
|
}
|
|
946
1008
|
}
|
|
947
1009
|
if (has("crest")) {
|
|
948
1010
|
;
|
|
949
1011
|
[-0.38, 0, 0.38].forEach((a, i) => {
|
|
950
1012
|
const c = polar(a, 1.12);
|
|
951
|
-
out.push({ k: "ellipse", x: c.x, y: c.y, rx: 0.15, ry: 0.42, rot: a, fill: extra(i, p.accent),
|
|
1013
|
+
out.push(__spreadValues({ k: "ellipse", x: c.x, y: c.y, rx: 0.15, ry: 0.42, rot: a, fill: extra(i, p.accent) }, ol));
|
|
952
1014
|
});
|
|
953
1015
|
}
|
|
954
1016
|
if (has("plume")) {
|
|
955
|
-
out.push({ k: "path", d: smoothClosed(pts(-0.12, -0.92, -0.2, -1.42, 0.1, -1.78, 0.62, -1.74, 0.36, -1.46, 0.16, -0.98)), fill: p.accent,
|
|
1017
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed(pts(-0.12, -0.92, -0.2, -1.42, 0.1, -1.78, 0.62, -1.74, 0.36, -1.46, 0.16, -0.98)), fill: p.accent }, ol));
|
|
956
1018
|
}
|
|
957
1019
|
if (has("locks")) {
|
|
958
|
-
out.push({ k: "path", d: smoothClosed(pts(-1.14, 0.58, -1.24, -0.2, -0.86, -0.98, 0, -1.2, 0.86, -0.98, 1.24, -0.2, 1.14, 0.58, 0.8, 0.66, 0, 0.2, -0.8, 0.66)), fill: p.hair
|
|
1020
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed(pts(-1.14, 0.58, -1.24, -0.2, -0.86, -0.98, 0, -1.2, 0.86, -0.98, 1.24, -0.2, 1.14, 0.58, 0.8, 0.66, 0, 0.2, -0.8, 0.66)), fill: (_b = p.hair) != null ? _b : p.outline }, ol));
|
|
959
1021
|
}
|
|
960
|
-
if (has("bun")) out.push({ k: "circle", x: 0.04, y: -1.14, r: 0.4, fill: p.hair
|
|
1022
|
+
if (has("bun")) out.push(__spreadValues({ k: "circle", x: 0.04, y: -1.14, r: 0.4, fill: (_c = p.hair) != null ? _c : p.outline }, ol));
|
|
961
1023
|
if (has("ninja-hood")) {
|
|
962
1024
|
for (const [rot, len3] of [
|
|
963
1025
|
[0.35, 0.5],
|
|
964
1026
|
[0.85, 0.42]
|
|
965
1027
|
])
|
|
966
|
-
out.push({ k: "ellipse", x: 1 + Math.cos(rot) * len3 * 0.8, y: -0.5 + Math.sin(rot) * len3 * 0.8, rx: len3, ry: 0.11, rot, fill: p.accent,
|
|
1028
|
+
out.push(__spreadValues({ k: "ellipse", x: 1 + Math.cos(rot) * len3 * 0.8, y: -0.5 + Math.sin(rot) * len3 * 0.8, rx: len3, ry: 0.11, rot, fill: p.accent }, ol));
|
|
967
1029
|
}
|
|
968
1030
|
if (has("bandana")) {
|
|
969
1031
|
for (const [rot, len3] of [
|
|
970
1032
|
[Math.PI - 0.5, 0.42],
|
|
971
1033
|
[Math.PI - 1, 0.36]
|
|
972
1034
|
])
|
|
973
|
-
out.push({ k: "ellipse", x: -0.98 + Math.cos(rot) * len3 * 0.8, y: -0.36 + Math.sin(rot) * len3 * 0.8, rx: len3, ry: 0.12, rot, fill: p.accent,
|
|
1035
|
+
out.push(__spreadValues({ k: "ellipse", x: -0.98 + Math.cos(rot) * len3 * 0.8, y: -0.36 + Math.sin(rot) * len3 * 0.8, rx: len3, ry: 0.12, rot, fill: p.accent }, ol));
|
|
974
1036
|
}
|
|
975
1037
|
if (has("ruff")) {
|
|
976
1038
|
for (const s of SIDES)
|
|
977
|
-
out.push({ k: "path", d: roundedPolygon(pts(s * 0.7, -0.3, s * 1.32, 0, s * 1.02, 0.18, s * 1.26, 0.46, s * 0.86, 0.56, s * 0.98, 0.84, s * 0.4, 0.7), 0.25), fill: p.body,
|
|
1039
|
+
out.push(__spreadValues({ k: "path", d: roundedPolygon(pts(s * 0.7, -0.3, s * 1.32, 0, s * 1.02, 0.18, s * 1.26, 0.46, s * 0.86, 0.56, s * 0.98, 0.84, s * 0.4, 0.7), 0.25), fill: p.body }, ol));
|
|
978
1040
|
}
|
|
979
1041
|
if (def.face.eyesOnTop) {
|
|
980
|
-
for (const s of SIDES) out.push({ k: "circle", x: s * 0.46, y: -0.72, r: 0.38, fill: p.body,
|
|
1042
|
+
for (const s of SIDES) out.push(__spreadValues({ k: "circle", x: s * 0.46, y: -0.72, r: 0.38, fill: p.body }, ol));
|
|
981
1043
|
}
|
|
982
1044
|
out.push(...ears(def, ow));
|
|
983
1045
|
out.push(headShape(def, ol));
|
|
@@ -1026,27 +1088,27 @@ function headShapes(def, ow) {
|
|
|
1026
1088
|
out.push({ k: "ellipse", x, y, rx: r, ry: r * 0.8, rot: -0.3, fill: p.outline, alpha: 0.85 });
|
|
1027
1089
|
}
|
|
1028
1090
|
if (has("forehead")) out.push({ k: "path", d: smoothClosed(pts(-0.62, -0.66, 0, -0.86, 0.62, -0.66, 0.26, -0.36, 0, -0.1, -0.26, -0.36), 0.9), fill: extra(0, p.accent) });
|
|
1029
|
-
if (has("eye-spot")) out.push({ k: "ellipse", x: 0.42, y: -0.06, rx: 0.3, ry: 0.33, rot: 0.3, fill: p.ears
|
|
1091
|
+
if (has("eye-spot")) out.push({ k: "ellipse", x: 0.42, y: -0.06, rx: 0.3, ry: 0.33, rot: 0.3, fill: (_d = p.ears) != null ? _d : p.accent });
|
|
1030
1092
|
if (has("gills")) {
|
|
1031
|
-
for (const s of SIDES) for (const dx of [0, 0.12, 0.24]) out.push({ k: "path", d:
|
|
1093
|
+
for (const s of SIDES) for (const dx of [0, 0.12, 0.24]) out.push({ k: "path", d: "M".concat(s * (0.66 + dx), " 0.06 Q").concat(s * (0.6 + dx), " 0.22 ").concat(s * (0.66 + dx), " 0.38"), stroke: p.accent, lw: ow * 0.9 });
|
|
1032
1094
|
}
|
|
1033
|
-
const hair = p.hair
|
|
1034
|
-
if (has("hair")) out.push({ k: "path", d: smoothClosed(pts(-1.02, -0.06, -1.02, -0.58, -0.62, -1.04, 0.08, -1.14, 0.76, -0.92, 1.05, -0.42, 1, -0.06, 0.84, -0.4, 0.42, -0.5, 0.06, -0.4, -0.34, -0.56, -0.74, -0.38)), fill: hair,
|
|
1035
|
-
if (has("locks")) out.push({ k: "path", d: smoothClosed(pts(-1, -0.08, -0.98, -0.62, -0.56, -1.02, 0, -1.1, 0.56, -1.02, 0.98, -0.62, 1, -0.08, 0.8, -0.38, 0.36, -0.44, 0, -0.4, -0.36, -0.44, -0.8, -0.38)), fill: hair,
|
|
1036
|
-
if (has("bun")) out.push({ k: "path", d: smoothClosed(pts(-1.02, -0.1, -0.98, -0.62, -0.56, -1.02, 0, -1.1, 0.56, -1.02, 0.98, -0.62, 1.02, -0.1, 0.84, -0.36, 0.5, -0.56, 0.12, -0.48, -0.22, -0.6, -0.6, -0.5, -0.86, -0.36)), fill: hair,
|
|
1095
|
+
const hair = (_e = p.hair) != null ? _e : p.outline;
|
|
1096
|
+
if (has("hair")) out.push(__spreadValues({ k: "path", d: smoothClosed(pts(-1.02, -0.06, -1.02, -0.58, -0.62, -1.04, 0.08, -1.14, 0.76, -0.92, 1.05, -0.42, 1, -0.06, 0.84, -0.4, 0.42, -0.5, 0.06, -0.4, -0.34, -0.56, -0.74, -0.38)), fill: hair }, ol));
|
|
1097
|
+
if (has("locks")) out.push(__spreadValues({ k: "path", d: smoothClosed(pts(-1, -0.08, -0.98, -0.62, -0.56, -1.02, 0, -1.1, 0.56, -1.02, 0.98, -0.62, 1, -0.08, 0.8, -0.38, 0.36, -0.44, 0, -0.4, -0.36, -0.44, -0.8, -0.38)), fill: hair }, ol));
|
|
1098
|
+
if (has("bun")) out.push(__spreadValues({ k: "path", d: smoothClosed(pts(-1.02, -0.1, -0.98, -0.62, -0.56, -1.02, 0, -1.1, 0.56, -1.02, 0.98, -0.62, 1.02, -0.1, 0.84, -0.36, 0.5, -0.56, 0.12, -0.48, -0.22, -0.6, -0.6, -0.5, -0.86, -0.36)), fill: hair }, ol));
|
|
1037
1099
|
if (has("curls")) {
|
|
1038
1100
|
for (let i = 0; i < 7; i++) {
|
|
1039
1101
|
const c = polar(-1.3 + i / 6 * 2.6, 0.86);
|
|
1040
|
-
out.push({ k: "circle", x: c.x, y: c.y, r: 0.3, fill: hair,
|
|
1102
|
+
out.push(__spreadValues({ k: "circle", x: c.x, y: c.y, r: 0.3, fill: hair }, ol));
|
|
1041
1103
|
}
|
|
1042
1104
|
out.push({ k: "ellipse", x: 0, y: -0.64, rx: 0.8, ry: 0.36, fill: hair });
|
|
1043
1105
|
}
|
|
1044
1106
|
if (has("ninja-hood")) {
|
|
1045
|
-
out.push({ k: "rect", x: 0, y: 0, w: 1.56, h: 0.6, r: 0.28, fill: p.skin
|
|
1046
|
-
out.push({ k: "path", d: "M-0.98 -0.42 Q0 -0.74 0.98 -0.42 L1.0 -0.62 Q0 -0.94 -1.0 -0.62 Z", fill: p.accent,
|
|
1107
|
+
out.push({ k: "rect", x: 0, y: 0, w: 1.56, h: 0.6, r: 0.28, fill: (_f = p.skin) != null ? _f : WHITE, stroke: p.outline, lw: ow * 0.8 });
|
|
1108
|
+
out.push(__spreadValues({ k: "path", d: "M-0.98 -0.42 Q0 -0.74 0.98 -0.42 L1.0 -0.62 Q0 -0.94 -1.0 -0.62 Z", fill: p.accent }, ol));
|
|
1047
1109
|
}
|
|
1048
1110
|
if (has("domino")) {
|
|
1049
|
-
out.push({ k: "path", d: smoothClosed(pts(-0.86, -0.04, -0.62, -0.3, -0.18, -0.24, 0, -0.16, 0.18, -0.24, 0.62, -0.3, 0.86, -0.04, 0.6, 0.22, 0.16, 0.16, 0, 0.1, -0.16, 0.16, -0.6, 0.22), 0.9), fill: p.accent,
|
|
1111
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed(pts(-0.86, -0.04, -0.62, -0.3, -0.18, -0.24, 0, -0.16, 0.18, -0.24, 0.62, -0.3, 0.86, -0.04, 0.6, 0.22, 0.16, 0.16, 0, 0.1, -0.16, 0.16, -0.6, 0.22), 0.9), fill: p.accent }, ol));
|
|
1050
1112
|
for (const s of SIDES) out.push({ k: "ellipse", x: s * 0.38, y: 0, rx: 0.19, ry: 0.13, fill: WHITE });
|
|
1051
1113
|
}
|
|
1052
1114
|
out.push(...eyes(def, ow));
|
|
@@ -1061,9 +1123,9 @@ function headShapes(def, ow) {
|
|
|
1061
1123
|
for (const dy of [-0.1, 0.06]) out.push({ k: "line", pts: [s * 0.62, 0.38 + dy, s * 1.06, 0.3 + dy * 2.2], stroke: p.outline, lw: ow * 0.7, alpha: 0.75 });
|
|
1062
1124
|
}
|
|
1063
1125
|
if (has("rainbow-mane")) {
|
|
1064
|
-
const c = def.extraColors
|
|
1065
|
-
out.push({ k: "ellipse", x: 0.42, y: -0.82, rx: 0.34, ry: 0.22, rot: 0.5, fill: c[0],
|
|
1066
|
-
out.push({ k: "ellipse", x: 0.1, y: -0.92, rx: 0.3, ry: 0.2, rot: 0.25, fill: c[1 % c.length],
|
|
1126
|
+
const c = (_g = def.extraColors) != null ? _g : ["#f59ac0", "#fbd46a", "#8fd3f4"];
|
|
1127
|
+
out.push(__spreadValues({ k: "ellipse", x: 0.42, y: -0.82, rx: 0.34, ry: 0.22, rot: 0.5, fill: c[0] }, ol));
|
|
1128
|
+
out.push(__spreadValues({ k: "ellipse", x: 0.1, y: -0.92, rx: 0.3, ry: 0.2, rot: 0.25, fill: c[1 % c.length] }, ol));
|
|
1067
1129
|
}
|
|
1068
1130
|
if (def.ears === "unicorn") {
|
|
1069
1131
|
const horn = [
|
|
@@ -1071,7 +1133,7 @@ function headShapes(def, ow) {
|
|
|
1071
1133
|
{ x: 0.02, y: -1.72 },
|
|
1072
1134
|
{ x: 0.18, y: -0.84 }
|
|
1073
1135
|
];
|
|
1074
|
-
out.push({ k: "path", d: roundedPolygon(horn, 0.12), fill: p.accent,
|
|
1136
|
+
out.push(__spreadValues({ k: "path", d: roundedPolygon(horn, 0.12), fill: p.accent }, ol));
|
|
1075
1137
|
for (const y of [-1, -1.2, -1.4]) {
|
|
1076
1138
|
const w2 = 0.16 * ((y + 1.72) / 0.88);
|
|
1077
1139
|
out.push({ k: "line", pts: [-w2, y + 0.04, w2, y - 0.04], stroke: p.outline, lw: ow * 0.7, alpha: 0.6 });
|
|
@@ -1096,42 +1158,42 @@ function headShapes(def, ow) {
|
|
|
1096
1158
|
});
|
|
1097
1159
|
}
|
|
1098
1160
|
if (has("helmet")) {
|
|
1099
|
-
for (const s of SIDES) out.push({ k: "rect", x: s * 1, y: 0.05, w: 0.26, h: 0.56, r: 0.12, fill: p.accent,
|
|
1161
|
+
for (const s of SIDES) out.push(__spreadValues({ k: "rect", x: s * 1, y: 0.05, w: 0.26, h: 0.56, r: 0.12, fill: p.accent }, ol));
|
|
1100
1162
|
out.push({ k: "path", d: "M-0.62 -0.62 Q-0.3 -0.92 0.12 -0.9", stroke: WHITE, lw: 0.1, alpha: 0.9 });
|
|
1101
1163
|
}
|
|
1102
|
-
if (has("bolts")) for (const s of SIDES) out.push({ k: "rect", x: s * 1.08, y: 0.08, w: 0.2, h: 0.44, r: 0.08, fill: p.accent,
|
|
1164
|
+
if (has("bolts")) for (const s of SIDES) out.push(__spreadValues({ k: "rect", x: s * 1.08, y: 0.08, w: 0.2, h: 0.44, r: 0.08, fill: p.accent }, ol));
|
|
1103
1165
|
if (has("tuft")) {
|
|
1104
|
-
out.push({ k: "path", d: smoothClosed([{ x: -0.26, y: -0.95 }, { x: -0.12, y: -1.22 }, { x: 0.02, y: -1.04 }, { x: 0.16, y: -1.28 }, { x: 0.28, y: -0.95 }, { x: 0, y: -0.86 }]), fill: p.body,
|
|
1166
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed([{ x: -0.26, y: -0.95 }, { x: -0.12, y: -1.22 }, { x: 0.02, y: -1.04 }, { x: 0.16, y: -1.28 }, { x: 0.28, y: -0.95 }, { x: 0, y: -0.86 }]), fill: p.body }, ol));
|
|
1105
1167
|
}
|
|
1106
1168
|
if (has("eggshell")) {
|
|
1107
|
-
out.push({ k: "path", d: "M-0.88 -0.5 C-0.88 -1.12 -0.46 -1.42 0 -1.42 C0.46 -1.42 0.88 -1.12 0.88 -0.5 L0.66 -0.66 L0.44 -0.48 L0.22 -0.66 L0 -0.48 L-0.22 -0.66 L-0.44 -0.48 L-0.66 -0.66 Z", fill: extra(0, WHITE),
|
|
1169
|
+
out.push(__spreadValues({ k: "path", d: "M-0.88 -0.5 C-0.88 -1.12 -0.46 -1.42 0 -1.42 C0.46 -1.42 0.88 -1.12 0.88 -0.5 L0.66 -0.66 L0.44 -0.48 L0.22 -0.66 L0 -0.48 L-0.22 -0.66 L-0.44 -0.48 L-0.66 -0.66 Z", fill: extra(0, WHITE) }, ol));
|
|
1108
1170
|
}
|
|
1109
|
-
if (has("wool")) for (const [x, y] of [[-0.36, -0.84], [0.02, -0.94], [0.4, -0.82]]) out.push({ k: "circle", x, y, r: 0.27, fill: p.body,
|
|
1171
|
+
if (has("wool")) for (const [x, y] of [[-0.36, -0.84], [0.02, -0.94], [0.4, -0.82]]) out.push(__spreadValues({ k: "circle", x, y, r: 0.27, fill: p.body }, ol));
|
|
1110
1172
|
if (has("stripe")) out.push({ k: "rect", x: 0, y: -0.64, w: 0.38, h: 0.62, r: 0.06, fill: p.accent });
|
|
1111
1173
|
if (has("eye-patch")) {
|
|
1112
1174
|
out.push({ k: "line", pts: [-0.97, -0.5, 0.97, 0.13], stroke: p.outline, lw: 0.07 });
|
|
1113
1175
|
out.push({ k: "ellipse", x: 0.38, y: 0.02, rx: 0.21, ry: 0.19, fill: p.outline });
|
|
1114
1176
|
}
|
|
1115
1177
|
if (has("bandana")) {
|
|
1116
|
-
out.push({ k: "path", d: smoothClosed(pts(-1.05, -0.22, -0.96, -0.72, -0.5, -1.08, 0.1, -1.14, 0.72, -0.96, 1.04, -0.56, 1.05, -0.22, 0.5, -0.46, -0.5, -0.46)), fill: p.accent,
|
|
1178
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed(pts(-1.05, -0.22, -0.96, -0.72, -0.5, -1.08, 0.1, -1.14, 0.72, -0.96, 1.04, -0.56, 1.05, -0.22, 0.5, -0.46, -0.5, -0.46)), fill: p.accent }, ol));
|
|
1117
1179
|
for (const [x, y] of [[-0.5, -0.8], [0.08, -0.92], [0.6, -0.74], [-0.12, -0.62], [0.36, -0.6]]) out.push({ k: "circle", x, y, r: 0.06, fill: WHITE, alpha: 0.85 });
|
|
1118
|
-
out.push({ k: "circle", x: -0.98, y: -0.34, r: 0.15, fill: p.accent,
|
|
1180
|
+
out.push(__spreadValues({ k: "circle", x: -0.98, y: -0.34, r: 0.15, fill: p.accent }, ol));
|
|
1119
1181
|
}
|
|
1120
1182
|
if (has("cap")) {
|
|
1121
1183
|
for (const s of SIDES) out.push({ k: "line", pts: [s * 0.98, -0.2, s * 0.5, 0.82, -s * 0.05, 0.98], stroke: p.outline, lw: 0.06 });
|
|
1122
|
-
out.push({ k: "path", d: smoothClosed(pts(-1.1, -0.16, -1.04, -0.66, -0.6, -1.12, 0, -1.24, 0.6, -1.12, 1.04, -0.66, 1.1, -0.16, 0.5, -0.4, -0.5, -0.4)), fill: p.accent,
|
|
1123
|
-
out.push({ k: "path", d: "M-0.74 -0.4 Q0 -0.6 0.74 -0.4 Q0.8 -0.24 0.6 -0.22 Q0 -0.36 -0.6 -0.22 Q-0.8 -0.24 -0.74 -0.4 Z", fill: p.accent,
|
|
1124
|
-
out.push({ k: "circle", x: 0.5, y: -0.82, r: 0.15, fill: extra(0, WHITE),
|
|
1184
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed(pts(-1.1, -0.16, -1.04, -0.66, -0.6, -1.12, 0, -1.24, 0.6, -1.12, 1.04, -0.66, 1.1, -0.16, 0.5, -0.4, -0.5, -0.4)), fill: p.accent }, ol));
|
|
1185
|
+
out.push(__spreadValues({ k: "path", d: "M-0.74 -0.4 Q0 -0.6 0.74 -0.4 Q0.8 -0.24 0.6 -0.22 Q0 -0.36 -0.6 -0.22 Q-0.8 -0.24 -0.74 -0.4 Z", fill: p.accent }, ol));
|
|
1186
|
+
out.push(__spreadValues({ k: "circle", x: 0.5, y: -0.82, r: 0.15, fill: extra(0, WHITE) }, ol));
|
|
1125
1187
|
for (const x of [-0.42, -0.14]) out.push({ k: "line", pts: [x, -1.04, x + 0.02, -0.78], stroke: p.outline, lw: 0.07, alpha: 0.7 });
|
|
1126
1188
|
}
|
|
1127
1189
|
if (has("safari-hat")) {
|
|
1128
|
-
out.push({ k: "ellipse", x: 0, y: -0.56, rx: 1.48, ry: 0.3, fill: p.accent,
|
|
1129
|
-
out.push({ k: "path", d: smoothClosed(pts(-0.78, -0.58, -0.7, -1.1, -0.3, -1.38, 0.3, -1.38, 0.7, -1.1, 0.78, -0.58, 0, -0.5), 0.8), fill: p.accent,
|
|
1190
|
+
out.push(__spreadValues({ k: "ellipse", x: 0, y: -0.56, rx: 1.48, ry: 0.3, fill: p.accent }, ol));
|
|
1191
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed(pts(-0.78, -0.58, -0.7, -1.1, -0.3, -1.38, 0.3, -1.38, 0.7, -1.1, 0.78, -0.58, 0, -0.5), 0.8), fill: p.accent }, ol));
|
|
1130
1192
|
out.push({ k: "path", d: "M-0.77 -0.72 Q0 -0.62 0.77 -0.72 L0.74 -0.9 Q0 -0.8 -0.74 -0.9 Z", fill: extra(1, p.outline), stroke: p.outline, lw: ow * 0.8 });
|
|
1131
1193
|
}
|
|
1132
1194
|
if (has("wizard-hat")) {
|
|
1133
|
-
out.push({ k: "ellipse", x: 0, y: -0.62, rx: 1.32, ry: 0.26, fill: p.accent,
|
|
1134
|
-
out.push({ k: "path", d: roundedPolygon(pts(-0.8, -0.66, -0.36, -1.5, 0.5, -2.2, 0.3, -1.46, 0.8, -0.66), 0.3), fill: p.accent,
|
|
1195
|
+
out.push(__spreadValues({ k: "ellipse", x: 0, y: -0.62, rx: 1.32, ry: 0.26, fill: p.accent }, ol));
|
|
1196
|
+
out.push(__spreadValues({ k: "path", d: roundedPolygon(pts(-0.8, -0.66, -0.36, -1.5, 0.5, -2.2, 0.3, -1.46, 0.8, -0.66), 0.3), fill: p.accent }, ol));
|
|
1135
1197
|
const star = extra(0, GOLD);
|
|
1136
1198
|
for (const [x, y, k] of [[0.02, -1.08, 0.18], [-0.38, -0.84, 0.1], [0.36, -1.5, 0.11]]) out.push({ k: "group", x, y, s: k, items: [{ k: "path", d: STAR, fill: star }] });
|
|
1137
1199
|
}
|
|
@@ -1147,22 +1209,23 @@ function headShapes(def, ow) {
|
|
|
1147
1209
|
return out;
|
|
1148
1210
|
}
|
|
1149
1211
|
function headShape(def, ol) {
|
|
1150
|
-
|
|
1212
|
+
var _a;
|
|
1213
|
+
const fill = def.headExtras.includes("ninja-hood") ? def.palette.body : (_a = def.palette.skin) != null ? _a : def.palette.body;
|
|
1151
1214
|
switch (def.head) {
|
|
1152
1215
|
case "round":
|
|
1153
|
-
return { k: "circle", x: 0, y: 0, r: 1, fill,
|
|
1216
|
+
return __spreadValues({ k: "circle", x: 0, y: 0, r: 1, fill }, ol);
|
|
1154
1217
|
case "wide":
|
|
1155
|
-
return { k: "ellipse", x: 0, y: 0.03, rx: 1.12, ry: 0.94, fill,
|
|
1218
|
+
return __spreadValues({ k: "ellipse", x: 0, y: 0.03, rx: 1.12, ry: 0.94, fill }, ol);
|
|
1156
1219
|
case "tall":
|
|
1157
|
-
return { k: "ellipse", x: 0, y: -0.02, rx: 0.94, ry: 1.04, fill,
|
|
1220
|
+
return __spreadValues({ k: "ellipse", x: 0, y: -0.02, rx: 0.94, ry: 1.04, fill }, ol);
|
|
1158
1221
|
case "square":
|
|
1159
|
-
return { k: "rect", x: 0, y: 0, w: 2, h: 1.8, r: 0.46, fill,
|
|
1222
|
+
return __spreadValues({ k: "rect", x: 0, y: 0, w: 2, h: 1.8, r: 0.46, fill }, ol);
|
|
1160
1223
|
case "bucket":
|
|
1161
|
-
return { k: "path", d: roundedPolygon(pts(-0.94, 0.96, -0.98, -0.36, -0.62, -1.04, 0.62, -1.04, 0.98, -0.36, 0.94, 0.96), 0.42), fill,
|
|
1224
|
+
return __spreadValues({ k: "path", d: roundedPolygon(pts(-0.94, 0.96, -0.98, -0.36, -0.62, -1.04, 0.62, -1.04, 0.98, -0.36, 0.94, 0.96), 0.42), fill }, ol);
|
|
1162
1225
|
case "snout-long":
|
|
1163
|
-
return { k: "path", d: smoothClosed(SNOUT_HEAD, 0.95), fill,
|
|
1226
|
+
return __spreadValues({ k: "path", d: smoothClosed(SNOUT_HEAD, 0.95), fill }, ol);
|
|
1164
1227
|
case "bulb":
|
|
1165
|
-
return {
|
|
1228
|
+
return __spreadValues({
|
|
1166
1229
|
k: "path",
|
|
1167
1230
|
d: smoothClosed([
|
|
1168
1231
|
{ x: 0, y: -1.02 },
|
|
@@ -1174,9 +1237,8 @@ function headShape(def, ol) {
|
|
|
1174
1237
|
{ x: -1.08, y: -0.12 },
|
|
1175
1238
|
{ x: -0.86, y: -0.74 }
|
|
1176
1239
|
]),
|
|
1177
|
-
fill
|
|
1178
|
-
|
|
1179
|
-
};
|
|
1240
|
+
fill
|
|
1241
|
+
}, ol);
|
|
1180
1242
|
}
|
|
1181
1243
|
}
|
|
1182
1244
|
var SNOUT_HEAD = pts(0.7, -0.88, 0.12, -1.04, -0.3, -0.98, -0.72, -0.74, -1.2, -0.56, -1.5, -0.32, -1.6, 0.04, -1.44, 0.42, -0.9, 0.72, -0.2, 0.92, 0.5, 0.88, 0.96, 0.56, 1.08, 0, 0.98, -0.5);
|
|
@@ -1221,6 +1283,7 @@ function lowerFace(def, ow) {
|
|
|
1221
1283
|
return d;
|
|
1222
1284
|
}
|
|
1223
1285
|
function ears(def, ow) {
|
|
1286
|
+
var _a, _b, _c, _d, _e;
|
|
1224
1287
|
const p = def.palette;
|
|
1225
1288
|
const ol = { stroke: p.outline, lw: ow };
|
|
1226
1289
|
const out = [];
|
|
@@ -1232,52 +1295,52 @@ function ears(def, ow) {
|
|
|
1232
1295
|
const base1 = { x: s * 0.3, y: -0.82 };
|
|
1233
1296
|
const tip = { x: s * 0.86, y: -0.82 - 0.62 * k };
|
|
1234
1297
|
const base2 = { x: s * 0.94, y: -0.36 };
|
|
1235
|
-
out.push({ k: "path", d: roundedPolygon([base1, tip, base2], 0.2), fill: p.body,
|
|
1298
|
+
out.push(__spreadValues({ k: "path", d: roundedPolygon([base1, tip, base2], 0.2), fill: p.body }, ol));
|
|
1236
1299
|
const c = { x: (base1.x + tip.x + base2.x) / 3, y: (base1.y + tip.y + base2.y) / 3 };
|
|
1237
1300
|
const inner = [base1, tip, base2].map((q) => ({ x: c.x + (q.x - c.x) * 0.55, y: c.y + (q.y - c.y) * 0.55 + 0.04 }));
|
|
1238
1301
|
out.push({ k: "path", d: roundedPolygon(inner, 0.25), fill: p.accent });
|
|
1239
1302
|
break;
|
|
1240
1303
|
}
|
|
1241
1304
|
case "round":
|
|
1242
|
-
out.push({ k: "circle", x: s * 0.72, y: -0.72, r: 0.36, fill: p.ears
|
|
1305
|
+
out.push(__spreadValues({ k: "circle", x: s * 0.72, y: -0.72, r: 0.36, fill: (_a = p.ears) != null ? _a : p.body }, ol));
|
|
1243
1306
|
if (!p.ears) out.push({ k: "circle", x: s * 0.74, y: -0.74, r: 0.19, fill: p.accent });
|
|
1244
1307
|
break;
|
|
1245
1308
|
case "big-round":
|
|
1246
|
-
out.push({ k: "circle", x: s * 0.96, y: -0.46, r: 0.52, fill: p.body,
|
|
1309
|
+
out.push(__spreadValues({ k: "circle", x: s * 0.96, y: -0.46, r: 0.52, fill: p.body }, ol));
|
|
1247
1310
|
out.push({ k: "circle", x: s * 1, y: -0.44, r: 0.32, fill: p.accent });
|
|
1248
1311
|
break;
|
|
1249
1312
|
case "long":
|
|
1250
|
-
out.push({ k: "ellipse", x: s * 0.38, y: -1.42, rx: 0.25, ry: 0.68, rot: s * 0.14, fill: p.body,
|
|
1313
|
+
out.push(__spreadValues({ k: "ellipse", x: s * 0.38, y: -1.42, rx: 0.25, ry: 0.68, rot: s * 0.14, fill: p.body }, ol));
|
|
1251
1314
|
out.push({ k: "ellipse", x: s * 0.39, y: -1.36, rx: 0.12, ry: 0.48, rot: s * 0.14, fill: p.accent });
|
|
1252
1315
|
break;
|
|
1253
1316
|
case "side":
|
|
1254
|
-
out.push({ k: "circle", x: s * 1, y: 0.02, r: 0.34, fill: p.body,
|
|
1317
|
+
out.push(__spreadValues({ k: "circle", x: s * 1, y: 0.02, r: 0.34, fill: p.body }, ol));
|
|
1255
1318
|
out.push({ k: "circle", x: s * 1.02, y: 0.02, r: 0.2, fill: p.belly });
|
|
1256
1319
|
break;
|
|
1257
1320
|
case "tufts":
|
|
1258
|
-
out.push({ k: "path", d: roundedPolygon([{ x: s * 0.3, y: -0.84 }, { x: s * 1.22, y: -1.12 }, { x: s * 0.92, y: -0.42 }], 0.16), fill: p.body,
|
|
1321
|
+
out.push(__spreadValues({ k: "path", d: roundedPolygon([{ x: s * 0.3, y: -0.84 }, { x: s * 1.22, y: -1.12 }, { x: s * 0.92, y: -0.42 }], 0.16), fill: p.body }, ol));
|
|
1259
1322
|
out.push({ k: "line", pts: [s * 0.62, -0.78, s * 1, -0.98], stroke: p.accent, lw: 0.08 });
|
|
1260
1323
|
break;
|
|
1261
1324
|
case "antennae": {
|
|
1262
1325
|
const tip = { x: s * 0.62, y: -1.42 };
|
|
1263
|
-
out.push({ k: "path", d:
|
|
1264
|
-
out.push({ k: "path", d:
|
|
1265
|
-
out.push({ k: "circle", x: tip.x, y: tip.y, r: 0.17, fill: p.accent,
|
|
1326
|
+
out.push({ k: "path", d: "M".concat(s * 0.3, " -0.8 Q").concat(s * 0.36, " -1.2 ").concat(tip.x, " ").concat(tip.y), stroke: p.outline, lw: ow * 2.6 });
|
|
1327
|
+
out.push({ k: "path", d: "M".concat(s * 0.3, " -0.8 Q").concat(s * 0.36, " -1.2 ").concat(tip.x, " ").concat(tip.y), stroke: p.body, lw: ow * 1.2 });
|
|
1328
|
+
out.push(__spreadValues({ k: "circle", x: tip.x, y: tip.y, r: 0.17, fill: p.accent }, ol));
|
|
1266
1329
|
break;
|
|
1267
1330
|
}
|
|
1268
1331
|
case "floppy":
|
|
1269
|
-
out.push({ k: "ellipse", x: s * 0.96, y: 0.02, rx: 0.3, ry: 0.62, rot: -s * 0.36, fill: p.ears
|
|
1332
|
+
out.push(__spreadValues({ k: "ellipse", x: s * 0.96, y: 0.02, rx: 0.3, ry: 0.62, rot: -s * 0.36, fill: (_b = p.ears) != null ? _b : p.body }, ol));
|
|
1270
1333
|
break;
|
|
1271
1334
|
case "droopy":
|
|
1272
|
-
out.push({ k: "ellipse", x: s * 1.04, y: -0.22, rx: 0.4, ry: 0.18, rot: s * 0.32, fill: p.skin
|
|
1335
|
+
out.push(__spreadValues({ k: "ellipse", x: s * 1.04, y: -0.22, rx: 0.4, ry: 0.18, rot: s * 0.32, fill: (_c = p.skin) != null ? _c : p.body }, ol));
|
|
1273
1336
|
out.push({ k: "ellipse", x: s * 1.08, y: -0.2, rx: 0.24, ry: 0.08, rot: s * 0.32, fill: p.accent });
|
|
1274
1337
|
break;
|
|
1275
1338
|
case "pixie":
|
|
1276
|
-
out.push({ k: "path", d: roundedPolygon(pts(s * 0.86, -0.22, s * 1.36, -0.5, s * 1.02, 0.26), 0.28), fill: p.skin
|
|
1339
|
+
out.push(__spreadValues({ k: "path", d: roundedPolygon(pts(s * 0.86, -0.22, s * 1.36, -0.5, s * 1.02, 0.26), 0.28), fill: (_d = p.skin) != null ? _d : p.body }, ol));
|
|
1277
1340
|
out.push({ k: "line", pts: [s * 0.98, -0.12, s * 1.16, -0.3], stroke: p.accent, lw: ow * 0.8, alpha: 0.5 });
|
|
1278
1341
|
break;
|
|
1279
1342
|
case "human":
|
|
1280
|
-
out.push({ k: "ellipse", x: s * 0.98, y: 0.06, rx: 0.17, ry: 0.23, fill: p.skin
|
|
1343
|
+
out.push(__spreadValues({ k: "ellipse", x: s * 0.98, y: 0.06, rx: 0.17, ry: 0.23, fill: (_e = p.skin) != null ? _e : p.body }, ol));
|
|
1281
1344
|
break;
|
|
1282
1345
|
case "horns": {
|
|
1283
1346
|
const pts2 = [
|
|
@@ -1285,20 +1348,21 @@ function ears(def, ow) {
|
|
|
1285
1348
|
{ x: s * 0.6, y: -1.5 },
|
|
1286
1349
|
{ x: s * 0.66, y: -0.68 }
|
|
1287
1350
|
];
|
|
1288
|
-
out.push({ k: "path", d: roundedPolygon(pts2, 0.18), fill: p.accent,
|
|
1351
|
+
out.push(__spreadValues({ k: "path", d: roundedPolygon(pts2, 0.18), fill: p.accent }, ol));
|
|
1289
1352
|
break;
|
|
1290
1353
|
}
|
|
1291
1354
|
}
|
|
1292
1355
|
}
|
|
1293
|
-
if (def.ears === "fin") out.push({ k: "path", d: roundedPolygon(pts(-0.4, -0.82, 0.2, -1.62, 0.46, -0.78), 0.2), fill: p.body,
|
|
1356
|
+
if (def.ears === "fin") out.push(__spreadValues({ k: "path", d: roundedPolygon(pts(-0.4, -0.82, 0.2, -1.62, 0.46, -0.78), 0.2), fill: p.body }, ol));
|
|
1294
1357
|
if (def.ears === "antenna") {
|
|
1295
1358
|
out.push({ k: "line", pts: [0, -0.85, 0, -1.42], stroke: p.outline, lw: ow * 2.6 });
|
|
1296
1359
|
out.push({ k: "line", pts: [0, -0.85, 0, -1.42], stroke: p.limbs, lw: ow * 1.2 });
|
|
1297
|
-
out.push({ k: "circle", x: 0, y: -1.5, r: 0.18, fill: p.accent,
|
|
1360
|
+
out.push(__spreadValues({ k: "circle", x: 0, y: -1.5, r: 0.18, fill: p.accent }, ol));
|
|
1298
1361
|
}
|
|
1299
1362
|
return out;
|
|
1300
1363
|
}
|
|
1301
1364
|
function eyes(def, ow) {
|
|
1365
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1302
1366
|
const p = def.palette;
|
|
1303
1367
|
const f2 = def.face;
|
|
1304
1368
|
const out = [];
|
|
@@ -1323,7 +1387,7 @@ function eyes(def, ow) {
|
|
|
1323
1387
|
for (const s of SIDES) {
|
|
1324
1388
|
if (f2.eyeRing) out.push({ k: "circle", x: s * ex, y: ey, r: 0.36, fill: f2.eyeRing, stroke: ink, lw: ow * 0.8 });
|
|
1325
1389
|
out.push({ k: "circle", x: s * ex, y: ey, r: 0.25, fill: WHITE, stroke: ink, lw: ow * 0.8 });
|
|
1326
|
-
out.push({ k: "circle", x: s * ex + s * -0.03, y: ey + 0.03, r: 0.14, fill: f2.eyeColor
|
|
1390
|
+
out.push({ k: "circle", x: s * ex + s * -0.03, y: ey + 0.03, r: 0.14, fill: (_a = f2.eyeColor) != null ? _a : ink });
|
|
1327
1391
|
out.push(shine(s * ex + s * -0.03 + 0.05, ey - 0.03, 0.05));
|
|
1328
1392
|
}
|
|
1329
1393
|
break;
|
|
@@ -1337,13 +1401,13 @@ function eyes(def, ow) {
|
|
|
1337
1401
|
case "screen":
|
|
1338
1402
|
out.push({ k: "rect", x: 0, y: 0, w: 1.5, h: 0.66, r: 0.26, fill: "#24323d", stroke: ink, lw: ow * 0.8 });
|
|
1339
1403
|
for (const s of SIDES) {
|
|
1340
|
-
out.push({ k: "ellipse", x: s * 0.36, y: 0, rx: 0.2, ry: 0.24, fill: f2.eyeColor
|
|
1341
|
-
out.push({ k: "ellipse", x: s * 0.36, y: 0, rx: 0.12, ry: 0.16, fill: f2.eyeColor
|
|
1404
|
+
out.push({ k: "ellipse", x: s * 0.36, y: 0, rx: 0.2, ry: 0.24, fill: (_b = f2.eyeColor) != null ? _b : "#7ff0ff", alpha: 0.3 });
|
|
1405
|
+
out.push({ k: "ellipse", x: s * 0.36, y: 0, rx: 0.12, ry: 0.16, fill: (_c = f2.eyeColor) != null ? _c : "#7ff0ff" });
|
|
1342
1406
|
}
|
|
1343
1407
|
break;
|
|
1344
1408
|
case "almond":
|
|
1345
1409
|
for (const s of SIDES) {
|
|
1346
|
-
out.push({ k: "ellipse", x: s * 0.42, y: -0.02, rx: 0.3, ry: 0.2, rot: -s * 0.5, fill: f2.eyeColor
|
|
1410
|
+
out.push({ k: "ellipse", x: s * 0.42, y: -0.02, rx: 0.3, ry: 0.2, rot: -s * 0.5, fill: (_d = f2.eyeColor) != null ? _d : ink });
|
|
1347
1411
|
out.push(shine(s * 0.42 - s * 0.07, -0.08, 0.07));
|
|
1348
1412
|
}
|
|
1349
1413
|
break;
|
|
@@ -1358,7 +1422,7 @@ function eyes(def, ow) {
|
|
|
1358
1422
|
out.push({ k: "rect", x: 0, y: -0.04, w: 1.56, h: 0.26, r: 0.1, fill: DARK_GLASS, stroke: ink, lw: ow * 0.8 });
|
|
1359
1423
|
out.push({ k: "rect", x: 0, y: 0.3, w: 0.22, h: 0.46, r: 0.08, fill: DARK_GLASS, stroke: ink, lw: ow * 0.8 });
|
|
1360
1424
|
for (const s of SIDES) {
|
|
1361
|
-
out.push({ k: "ellipse", x: s * 0.4, y: -0.04, rx: 0.12, ry: 0.07, fill: f2.eyeColor
|
|
1425
|
+
out.push({ k: "ellipse", x: s * 0.4, y: -0.04, rx: 0.12, ry: 0.07, fill: (_e = f2.eyeColor) != null ? _e : WHITE });
|
|
1362
1426
|
for (const dy of [0.36, 0.56]) out.push({ k: "circle", x: s * 0.42, y: dy, r: 0.05, fill: ink, alpha: 0.6 });
|
|
1363
1427
|
}
|
|
1364
1428
|
break;
|
|
@@ -1366,13 +1430,13 @@ function eyes(def, ow) {
|
|
|
1366
1430
|
for (const s of SIDES) out.push({ k: "circle", x: s * 0.9, y: 0, r: 0.13, fill: p.accent, stroke: ink, lw: ow * 0.8 });
|
|
1367
1431
|
out.push({ k: "rect", x: 0, y: 0, w: 1.66, h: 0.62, r: 0.3, fill: DARK_GLASS, stroke: ink, lw: ow * 0.8 });
|
|
1368
1432
|
out.push({ k: "path", d: "M-0.6 -0.16 Q-0.42 -0.24 -0.12 -0.24", stroke: WHITE, lw: 0.07, alpha: 0.8 });
|
|
1369
|
-
for (const s of SIDES) out.push({ k: "path", d:
|
|
1433
|
+
for (const s of SIDES) out.push({ k: "path", d: "M".concat(s * 0.5, " 0.04 Q").concat(s * 0.34, " -0.08 ").concat(s * 0.16, " 0.02"), stroke: (_f = f2.eyeColor) != null ? _f : "#7fd6ff", lw: 0.08 });
|
|
1370
1434
|
for (const x of [-0.18, 0, 0.18]) out.push({ k: "line", pts: [x, 0.56, x, 0.72], stroke: ink, lw: ow * 0.8, alpha: 0.6 });
|
|
1371
1435
|
break;
|
|
1372
1436
|
case "visor":
|
|
1373
1437
|
out.push({ k: "ellipse", x: 0, y: 0.08, rx: 0.8, ry: 0.64, fill: "#2a3f6b", stroke: ink, lw: ow * 0.8 });
|
|
1374
1438
|
out.push({ k: "path", d: "M-0.56 -0.14 Q-0.46 -0.4 -0.16 -0.46", stroke: WHITE, lw: 0.08, alpha: 0.7 });
|
|
1375
|
-
for (const s of SIDES) out.push({ k: "ellipse", x: s * 0.28, y: 0.04, rx: 0.1, ry: 0.14, fill: f2.eyeColor
|
|
1439
|
+
for (const s of SIDES) out.push({ k: "ellipse", x: s * 0.28, y: 0.04, rx: 0.1, ry: 0.14, fill: (_g = f2.eyeColor) != null ? _g : "#cfeeff" });
|
|
1376
1440
|
break;
|
|
1377
1441
|
}
|
|
1378
1442
|
return out;
|
|
@@ -1463,7 +1527,8 @@ var BAND_BODY = {
|
|
|
1463
1527
|
};
|
|
1464
1528
|
var DEFAULT_BAND = "6-8";
|
|
1465
1529
|
var bodyBand = (def, shown) => {
|
|
1466
|
-
|
|
1530
|
+
var _a;
|
|
1531
|
+
if (shown !== void 0 && def.band !== "all" && ((_a = def.alsoIn) == null ? void 0 : _a.includes(shown)) && shown in BAND_BODY) return shown;
|
|
1467
1532
|
return def.band in BAND_BODY ? def.band : DEFAULT_BAND;
|
|
1468
1533
|
};
|
|
1469
1534
|
var HEAD = BAND_BODY[DEFAULT_BAND].head;
|
|
@@ -1497,6 +1562,7 @@ function joints(body, box, mirrored = false) {
|
|
|
1497
1562
|
};
|
|
1498
1563
|
}
|
|
1499
1564
|
function frameOf(body, box, opts = {}) {
|
|
1565
|
+
var _a, _b;
|
|
1500
1566
|
const at = joints(body, box, opts.mirrored);
|
|
1501
1567
|
const ls = at(P.leftShoulder);
|
|
1502
1568
|
const rs = at(P.rightShoulder);
|
|
@@ -1530,7 +1596,7 @@ function frameOf(body, box, opts = {}) {
|
|
|
1530
1596
|
const r = { x: d.y, y: -d.x };
|
|
1531
1597
|
const angle = Math.atan2(r.y, r.x);
|
|
1532
1598
|
const up = mul(d, -1);
|
|
1533
|
-
const bb = BAND_BODY[opts.band
|
|
1599
|
+
const bb = (_b = BAND_BODY[(_a = opts.band) != null ? _a : DEFAULT_BAND]) != null ? _b : BAND_BODY[DEFAULT_BAND];
|
|
1534
1600
|
const headR = bb.head * U;
|
|
1535
1601
|
let head = add(S2, mul(up, headR * bb.neck));
|
|
1536
1602
|
const nose = at(P.nose);
|
|
@@ -1559,9 +1625,10 @@ function headTilt(body, at, angle, U) {
|
|
|
1559
1625
|
return 0;
|
|
1560
1626
|
}
|
|
1561
1627
|
function avatarShapes(body, def, box, opts = {}) {
|
|
1628
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1562
1629
|
const band = bodyBand(def, opts.band);
|
|
1563
1630
|
const bb = BAND_BODY[band];
|
|
1564
|
-
const F = frameOf(body, box, {
|
|
1631
|
+
const F = frameOf(body, box, __spreadProps(__spreadValues({}, opts), { band }));
|
|
1565
1632
|
if (!F) return [];
|
|
1566
1633
|
const at = joints(body, box, opts.mirrored);
|
|
1567
1634
|
const p = def.palette;
|
|
@@ -1605,7 +1672,7 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1605
1672
|
const top = add(hip, mul(d, -0.12 * U));
|
|
1606
1673
|
const pts2 = ankle.ok ? [top, knee, ankle] : [top, knee];
|
|
1607
1674
|
limb(legs, pts2, legW, p.limbs);
|
|
1608
|
-
if (has("joints")) legs.push({ k: "circle", x: knee.x, y: knee.y, r: 0.15 * U * pad, fill: p.accent,
|
|
1675
|
+
if (has("joints")) legs.push(__spreadValues({ k: "circle", x: knee.x, y: knee.y, r: 0.15 * U * pad, fill: p.accent }, ol));
|
|
1609
1676
|
if (ankle.ok) legs.push(...feet(def, ankle, F, side, ow, bb.foot));
|
|
1610
1677
|
}
|
|
1611
1678
|
}
|
|
@@ -1617,7 +1684,7 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1617
1684
|
const wrist = at(wristI);
|
|
1618
1685
|
if (has("pauldrons")) {
|
|
1619
1686
|
const c = add(sh, mul(d, 0.02 * U));
|
|
1620
|
-
arms.push({ k: "ellipse", x: c.x, y: c.y, rx: 0.25 * U, ry: 0.17 * U, rot: F.angle + side * 0.25, fill: p.body,
|
|
1687
|
+
arms.push(__spreadValues({ k: "ellipse", x: c.x, y: c.y, rx: 0.25 * U, ry: 0.17 * U, rot: F.angle + side * 0.25, fill: p.body }, ol));
|
|
1621
1688
|
const q = add(c, mul(d, 0.05 * U));
|
|
1622
1689
|
arms.push({ k: "ellipse", x: q.x, y: q.y, rx: 0.17 * U, ry: 0.07 * U, rot: F.angle + side * 0.25, fill: p.belly });
|
|
1623
1690
|
}
|
|
@@ -1626,7 +1693,7 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1626
1693
|
const out = raised ? front : arms;
|
|
1627
1694
|
const top = add(sh, mul(d, 0.04 * U));
|
|
1628
1695
|
limb(out, wrist.ok ? [top, elbow, wrist] : [top, elbow], armW, p.limbs);
|
|
1629
|
-
if (has("joints")) out.push({ k: "circle", x: elbow.x, y: elbow.y, r: 0.13 * U * pad, fill: p.accent,
|
|
1696
|
+
if (has("joints")) out.push(__spreadValues({ k: "circle", x: elbow.x, y: elbow.y, r: 0.13 * U * pad, fill: p.accent }, ol));
|
|
1630
1697
|
if (!wrist.ok) continue;
|
|
1631
1698
|
const dir = norm(sub(wrist, elbow));
|
|
1632
1699
|
const hand = add(wrist, mul(dir, 0.05 * U));
|
|
@@ -1636,7 +1703,7 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1636
1703
|
const s = Math.sin(a) * side;
|
|
1637
1704
|
const fd = { x: dir.x * c - dir.y * s, y: dir.x * s + dir.y * c };
|
|
1638
1705
|
const q = add(hand, mul(fd, 0.16 * U));
|
|
1639
|
-
out.push({ k: "ellipse", x: q.x, y: q.y, rx: 0.2 * U, ry: 0.09 * U, rot: Math.atan2(fd.y, fd.x), fill: p.hands
|
|
1706
|
+
out.push(__spreadValues({ k: "ellipse", x: q.x, y: q.y, rx: 0.2 * U, ry: 0.09 * U, rot: Math.atan2(fd.y, fd.x), fill: (_a = p.hands) != null ? _a : p.accent }, ol));
|
|
1640
1707
|
}
|
|
1641
1708
|
}
|
|
1642
1709
|
if (has("wand") && side === 1 && !opts.portrait) out.push(...wand(def, hand, norm(add(mul(dir, 0.4), sub(mul(r, 0.6), d))), U, ow));
|
|
@@ -1649,10 +1716,10 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1649
1716
|
const base = add(hand, mul(cd, handR * 0.75));
|
|
1650
1717
|
const tip = add(hand, mul(cd, handR * 1.6));
|
|
1651
1718
|
const nrm = { x: -cd.y * handR * 0.32, y: cd.x * handR * 0.32 };
|
|
1652
|
-
out.push({ k: "path", d: roundedPolygon([add(base, nrm), tip, sub(base, nrm)], 0.2), fill: p.belly,
|
|
1719
|
+
out.push(__spreadValues({ k: "path", d: roundedPolygon([add(base, nrm), tip, sub(base, nrm)], 0.2), fill: p.belly }, ol));
|
|
1653
1720
|
}
|
|
1654
1721
|
}
|
|
1655
|
-
out.push({ k: "circle", x: hand.x, y: hand.y, r: handR, fill: p.hands
|
|
1722
|
+
out.push(__spreadValues({ k: "circle", x: hand.x, y: hand.y, r: handR, fill: (_b = p.hands) != null ? _b : p.limbs }, ol));
|
|
1656
1723
|
}
|
|
1657
1724
|
if (has("wings")) {
|
|
1658
1725
|
for (const s of [-1, 1]) {
|
|
@@ -1664,7 +1731,7 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1664
1731
|
[s * (ht + 0.3 * U), 0.32 * U],
|
|
1665
1732
|
[s * ht * 0.6, 0.55 * U]
|
|
1666
1733
|
]);
|
|
1667
|
-
back.push({ k: "path", d: roundedPolygon(w2, 0.18), fill: p.accent,
|
|
1734
|
+
back.push(__spreadValues({ k: "path", d: roundedPolygon(w2, 0.18), fill: p.accent }, ol));
|
|
1668
1735
|
}
|
|
1669
1736
|
}
|
|
1670
1737
|
if (has("wings-fairy")) back.push(...fairyWings(def, T2, ht, U, ow));
|
|
@@ -1682,18 +1749,18 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1682
1749
|
[-wb, yb],
|
|
1683
1750
|
[-ht - 0.16 * U, L * 0.5]
|
|
1684
1751
|
]);
|
|
1685
|
-
back.push({ k: "path", d: smoothClosed(cape, 0.6), fill: p.accent,
|
|
1752
|
+
back.push(__spreadValues({ k: "path", d: smoothClosed(cape, 0.6), fill: p.accent }, ol));
|
|
1686
1753
|
}
|
|
1687
1754
|
if (has("backpack")) {
|
|
1688
1755
|
const c = T2(0, 0.35 * U);
|
|
1689
|
-
back.push({ k: "rect", x: c.x, y: c.y, w: ht * 2 + 0.34 * U, h: 0.8 * U, r: 0.16 * U, rot: F.angle, fill: def.extraColors
|
|
1756
|
+
back.push(__spreadValues({ k: "rect", x: c.x, y: c.y, w: ht * 2 + 0.34 * U, h: 0.8 * U, r: 0.16 * U, rot: F.angle, fill: (_d = (_c = def.extraColors) == null ? void 0 : _c[0]) != null ? _d : p.limbs }, ol));
|
|
1690
1757
|
}
|
|
1691
1758
|
if (has("tank")) {
|
|
1692
1759
|
const c = T2(ht * 0.95, 0.24 * U);
|
|
1693
|
-
const col = def.extraColors
|
|
1760
|
+
const col = (_f = (_e = def.extraColors) == null ? void 0 : _e[0]) != null ? _f : p.accent;
|
|
1694
1761
|
const valve = T2(ht * 0.95, -0.3 * U);
|
|
1695
1762
|
back.push({ k: "rect", x: valve.x, y: valve.y, w: 0.14 * U, h: 0.16 * U, r: 0.04 * U, rot: F.angle, fill: p.outline });
|
|
1696
|
-
back.push({ k: "rect", x: c.x, y: c.y, w: 0.34 * U, h: 1 * U, r: 0.17 * U, rot: F.angle, fill: col,
|
|
1763
|
+
back.push(__spreadValues({ k: "rect", x: c.x, y: c.y, w: 0.34 * U, h: 1 * U, r: 0.17 * U, rot: F.angle, fill: col }, ol));
|
|
1697
1764
|
}
|
|
1698
1765
|
if (F.hipsOk && !opts.portrait) back.push(...tail(def, F, hb, ow));
|
|
1699
1766
|
if (has("tentacles") && F.hipsOk) {
|
|
@@ -1720,15 +1787,15 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1720
1787
|
])
|
|
1721
1788
|
for (const s of [-1, 1]) {
|
|
1722
1789
|
const q2 = T2(s * x, y);
|
|
1723
|
-
torso.push({ k: "circle", x: q2.x, y: q2.y, r: 0.2 * U, fill: p.body,
|
|
1790
|
+
torso.push(__spreadValues({ k: "circle", x: q2.x, y: q2.y, r: 0.2 * U, fill: p.body }, ol));
|
|
1724
1791
|
}
|
|
1725
1792
|
const q = T2(0, y1 + 0.02 * U);
|
|
1726
|
-
torso.push({ k: "circle", x: q.x, y: q.y, r: 0.2 * U, fill: p.body,
|
|
1793
|
+
torso.push(__spreadValues({ k: "circle", x: q.x, y: q.y, r: 0.2 * U, fill: p.body }, ol));
|
|
1727
1794
|
}
|
|
1728
1795
|
if (has("robe")) {
|
|
1729
1796
|
const yb = L + 0.58 * U;
|
|
1730
1797
|
const wb = hb * 1.4;
|
|
1731
|
-
torso.push({
|
|
1798
|
+
torso.push(__spreadValues({
|
|
1732
1799
|
k: "path",
|
|
1733
1800
|
d: smoothClosed(
|
|
1734
1801
|
TP([
|
|
@@ -1743,19 +1810,18 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1743
1810
|
]),
|
|
1744
1811
|
0.7
|
|
1745
1812
|
),
|
|
1746
|
-
fill: p.body
|
|
1747
|
-
|
|
1748
|
-
});
|
|
1813
|
+
fill: p.body
|
|
1814
|
+
}, ol));
|
|
1749
1815
|
const hem = TP([
|
|
1750
1816
|
[-wb * 0.94, yb - 0.1 * U],
|
|
1751
1817
|
[0, yb - 0.04 * U],
|
|
1752
1818
|
[wb * 0.94, yb - 0.1 * U]
|
|
1753
1819
|
]);
|
|
1754
|
-
torso.push({ k: "path", d: smoothOpen(hem), stroke: def.extraColors
|
|
1820
|
+
torso.push({ k: "path", d: smoothOpen(hem), stroke: (_h = (_g = def.extraColors) == null ? void 0 : _g[0]) != null ? _h : p.accent, lw: 0.07 * U });
|
|
1755
1821
|
} else if (has("sheet")) {
|
|
1756
1822
|
const yb = L + 0.78 * U;
|
|
1757
1823
|
const wb = hb * 1.3;
|
|
1758
|
-
torso.push({
|
|
1824
|
+
torso.push(__spreadValues({
|
|
1759
1825
|
k: "path",
|
|
1760
1826
|
d: smoothClosed(
|
|
1761
1827
|
TP([
|
|
@@ -1771,11 +1837,10 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1771
1837
|
]),
|
|
1772
1838
|
0.9
|
|
1773
1839
|
),
|
|
1774
|
-
fill: p.body
|
|
1775
|
-
|
|
1776
|
-
});
|
|
1840
|
+
fill: p.body
|
|
1841
|
+
}, ol));
|
|
1777
1842
|
} else {
|
|
1778
|
-
torso.push({
|
|
1843
|
+
torso.push(__spreadValues({
|
|
1779
1844
|
k: "path",
|
|
1780
1845
|
d: smoothClosed(
|
|
1781
1846
|
TP([
|
|
@@ -1790,9 +1855,8 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1790
1855
|
]),
|
|
1791
1856
|
0.85
|
|
1792
1857
|
),
|
|
1793
|
-
fill: p.body
|
|
1794
|
-
|
|
1795
|
-
});
|
|
1858
|
+
fill: p.body
|
|
1859
|
+
}, ol));
|
|
1796
1860
|
}
|
|
1797
1861
|
const minW = Math.min(ht, hb);
|
|
1798
1862
|
if (has("pocket")) {
|
|
@@ -1809,7 +1873,7 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1809
1873
|
torso.push({ k: "ellipse", x: c.x, y: c.y, rx: minW * 0.64, ry: Math.max(L * 0.36, 0.2 * U), rot: F.angle, fill: p.belly });
|
|
1810
1874
|
}
|
|
1811
1875
|
if (has("spots")) {
|
|
1812
|
-
const c = def.extraColors
|
|
1876
|
+
const c = (_j = (_i = def.extraColors) == null ? void 0 : _i[1]) != null ? _j : p.belly;
|
|
1813
1877
|
for (const [x, y, rr] of [
|
|
1814
1878
|
[-0.55, 0.35, 0.09],
|
|
1815
1879
|
[0.5, 0.62, 0.11],
|
|
@@ -1820,7 +1884,7 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1820
1884
|
}
|
|
1821
1885
|
}
|
|
1822
1886
|
if (has("stripes")) {
|
|
1823
|
-
const c = def.extraColors
|
|
1887
|
+
const c = (_l = (_k = def.extraColors) == null ? void 0 : _k[1]) != null ? _l : p.accent;
|
|
1824
1888
|
for (const y of [0.22, 0.44, 0.66]) {
|
|
1825
1889
|
const a = T2(-minW * 0.98, L * y);
|
|
1826
1890
|
const b = T2(minW * 0.98, L * y);
|
|
@@ -1828,7 +1892,7 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1828
1892
|
}
|
|
1829
1893
|
}
|
|
1830
1894
|
if (has("straps")) {
|
|
1831
|
-
const c = def.extraColors
|
|
1895
|
+
const c = (_n = (_m = def.extraColors) == null ? void 0 : _m[1]) != null ? _n : p.outline;
|
|
1832
1896
|
for (const s of [-1, 1]) {
|
|
1833
1897
|
const a = T2(s * ht * 0.62, y0 + 0.02 * U);
|
|
1834
1898
|
const b = T2(s * minW * 0.62, L * 0.72);
|
|
@@ -1838,12 +1902,12 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1838
1902
|
}
|
|
1839
1903
|
if (has("belt")) {
|
|
1840
1904
|
const c = T2(0, L * 0.9);
|
|
1841
|
-
torso.push({ k: "rect", x: c.x, y: c.y, w: hb * 1.92, h: 0.17 * U, r: 0.06 * U, rot: F.angle, fill: def.extraColors
|
|
1842
|
-
torso.push({ k: "rect", x: c.x, y: c.y, w: 0.2 * U, h: 0.19 * U, r: 0.04 * U, rot: F.angle, fill: "#ffd84a",
|
|
1905
|
+
torso.push(__spreadValues({ k: "rect", x: c.x, y: c.y, w: hb * 1.92, h: 0.17 * U, r: 0.06 * U, rot: F.angle, fill: (_p = (_o = def.extraColors) == null ? void 0 : _o[2]) != null ? _p : "#4a3426" }, ol));
|
|
1906
|
+
torso.push(__spreadValues({ k: "rect", x: c.x, y: c.y, w: 0.2 * U, h: 0.19 * U, r: 0.04 * U, rot: F.angle, fill: "#ffd84a" }, ol));
|
|
1843
1907
|
}
|
|
1844
1908
|
if (has("emblem")) {
|
|
1845
1909
|
const c = T2(0, L * 0.4);
|
|
1846
|
-
const fill = def.extraColors
|
|
1910
|
+
const fill = (_r = (_q = def.extraColors) == null ? void 0 : _q[0]) != null ? _r : p.accent;
|
|
1847
1911
|
const shield = roundedPolygon(
|
|
1848
1912
|
[
|
|
1849
1913
|
{ x: -0.22, y: -0.2 },
|
|
@@ -1868,8 +1932,8 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1868
1932
|
}
|
|
1869
1933
|
if (has("panel")) {
|
|
1870
1934
|
const c = T2(0, L * 0.5);
|
|
1871
|
-
torso.push({ k: "rect", x: c.x, y: c.y, w: minW * 1.2, h: 0.38 * U, r: 0.1 * U, rot: F.angle, fill: "#24323d",
|
|
1872
|
-
const lights = def.extraColors
|
|
1935
|
+
torso.push(__spreadValues({ k: "rect", x: c.x, y: c.y, w: minW * 1.2, h: 0.38 * U, r: 0.1 * U, rot: F.angle, fill: "#24323d" }, ol));
|
|
1936
|
+
const lights = (_s = def.extraColors) != null ? _s : ["#ff7a6b", "#fbd46a", "#7ff0ff"];
|
|
1873
1937
|
lights.slice(0, 3).forEach((col, i) => {
|
|
1874
1938
|
const q = T2((i - 1) * minW * 0.34, L * 0.5);
|
|
1875
1939
|
torso.push({ k: "circle", x: q.x, y: q.y, r: 0.075 * U, fill: col });
|
|
@@ -1877,22 +1941,22 @@ function avatarShapes(body, def, box, opts = {}) {
|
|
|
1877
1941
|
}
|
|
1878
1942
|
if (has("badge")) {
|
|
1879
1943
|
const c = T2(-minW * 0.42, L * 0.36);
|
|
1880
|
-
torso.push({ k: "circle", x: c.x, y: c.y, r: 0.15 * U, fill: p.accent,
|
|
1944
|
+
torso.push(__spreadValues({ k: "circle", x: c.x, y: c.y, r: 0.15 * U, fill: p.accent }, ol));
|
|
1881
1945
|
torso.push({ k: "group", x: c.x, y: c.y, rot: F.angle, s: 0.09 * U, items: [{ k: "path", d: STAR, fill: "#ffffff" }] });
|
|
1882
1946
|
}
|
|
1883
1947
|
if (has("star")) {
|
|
1884
1948
|
const c = T2(-minW * 0.5, L * 0.3);
|
|
1885
1949
|
const k = 0.15 * U;
|
|
1886
|
-
torso.push({ k: "group", x: c.x, y: c.y, rot: F.angle - 0.2, s: k, items: [{ k: "path", d: STAR, fill: def.extraColors
|
|
1950
|
+
torso.push({ k: "group", x: c.x, y: c.y, rot: F.angle - 0.2, s: k, items: [{ k: "path", d: STAR, fill: (_u = (_t = def.extraColors) == null ? void 0 : _t[0]) != null ? _u : "#ffd84a", stroke: p.outline, lw: ow * 0.8 / k }] });
|
|
1887
1951
|
}
|
|
1888
1952
|
if (has("petals")) torso.push(...petals(def, T2, ht, hb, bulge, L, y1, U, ow, bb));
|
|
1889
1953
|
if (has("scarf")) {
|
|
1890
1954
|
const y = Math.max(0.04, bb.head * (1 - bb.neck) - 0.06) * U;
|
|
1891
1955
|
const c = T2(0, y);
|
|
1892
|
-
const col = def.extraColors
|
|
1956
|
+
const col = (_w = (_v = def.extraColors) == null ? void 0 : _v[0]) != null ? _w : p.accent;
|
|
1893
1957
|
const tailEnd = T2(ht * 0.45, y + 0.28 * U);
|
|
1894
|
-
torso.push({ k: "rect", x: tailEnd.x, y: tailEnd.y, w: 0.16 * U, h: 0.42 * U, r: 0.06 * U, rot: F.angle + 0.15, fill: col,
|
|
1895
|
-
torso.push({ k: "rect", x: c.x, y: c.y, w: ht * 2.05, h: 0.2 * U, r: 0.1 * U, rot: F.angle, fill: col,
|
|
1958
|
+
torso.push(__spreadValues({ k: "rect", x: tailEnd.x, y: tailEnd.y, w: 0.16 * U, h: 0.42 * U, r: 0.06 * U, rot: F.angle + 0.15, fill: col }, ol));
|
|
1959
|
+
torso.push(__spreadValues({ k: "rect", x: c.x, y: c.y, w: ht * 2.05, h: 0.2 * U, r: 0.1 * U, rot: F.angle, fill: col }, ol));
|
|
1896
1960
|
}
|
|
1897
1961
|
const head = { k: "group", x: F.head.x, y: F.head.y, rot: F.headRot, s: F.headR, items: cachedHead(def, ow / F.headR) };
|
|
1898
1962
|
return [...back, ...legs, ...torso, ...arms, head, ...front];
|
|
@@ -1923,12 +1987,13 @@ function feet(def, ankle, F, side, ow, k) {
|
|
|
1923
1987
|
return out;
|
|
1924
1988
|
}
|
|
1925
1989
|
function foot(def, ankle, F, side, ow, k) {
|
|
1990
|
+
var _a;
|
|
1926
1991
|
const p = def.palette;
|
|
1927
1992
|
const { d, r } = F;
|
|
1928
1993
|
const U = F.U * k;
|
|
1929
1994
|
const c = add(add(ankle, mul(d, 0.07 * U)), mul(r, side * 0.06 * U));
|
|
1930
1995
|
const ol = { stroke: p.outline, lw: ow };
|
|
1931
|
-
const fill = p.feet
|
|
1996
|
+
const fill = (_a = p.feet) != null ? _a : p.limbs;
|
|
1932
1997
|
if (def.bodyExtras.includes("fins")) {
|
|
1933
1998
|
const fin = roundedPolygon(
|
|
1934
1999
|
[
|
|
@@ -1951,11 +2016,12 @@ function foot(def, ankle, F, side, ow, k) {
|
|
|
1951
2016
|
]
|
|
1952
2017
|
};
|
|
1953
2018
|
}
|
|
1954
|
-
if (def.bodyExtras.includes("flippers")) return { k: "ellipse", x: c.x, y: c.y, rx: 0.27 * U, ry: 0.11 * U, rot: F.angle, fill,
|
|
1955
|
-
if (def.bodyExtras.includes("boots")) return { k: "rect", x: c.x, y: c.y, w: 0.4 * U, h: 0.24 * U, r: 0.09 * U, rot: F.angle, fill,
|
|
1956
|
-
return { k: "ellipse", x: c.x, y: c.y, rx: 0.2 * U, ry: 0.13 * U, rot: F.angle, fill,
|
|
2019
|
+
if (def.bodyExtras.includes("flippers")) return __spreadValues({ k: "ellipse", x: c.x, y: c.y, rx: 0.27 * U, ry: 0.11 * U, rot: F.angle, fill }, ol);
|
|
2020
|
+
if (def.bodyExtras.includes("boots")) return __spreadValues({ k: "rect", x: c.x, y: c.y, w: 0.4 * U, h: 0.24 * U, r: 0.09 * U, rot: F.angle, fill }, ol);
|
|
2021
|
+
return __spreadValues({ k: "ellipse", x: c.x, y: c.y, rx: 0.2 * U, ry: 0.13 * U, rot: F.angle, fill }, ol);
|
|
1957
2022
|
}
|
|
1958
2023
|
function tail(def, F, hb, ow) {
|
|
2024
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1959
2025
|
const p = def.palette;
|
|
1960
2026
|
const { U, L, S: S2, r, d } = F;
|
|
1961
2027
|
const T2 = (x, y) => ({ x: S2.x + r.x * x + d.x * y, y: S2.y + r.y * x + d.y * y });
|
|
@@ -1979,9 +2045,9 @@ function tail(def, F, hb, ow) {
|
|
|
1979
2045
|
[hb + 0.3 * U, L * 0.6],
|
|
1980
2046
|
[hb * 0.6, L * 0.7]
|
|
1981
2047
|
]);
|
|
1982
|
-
out.push({ k: "path", d: smoothClosed(pts2), fill: p.body,
|
|
2048
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed(pts2), fill: p.body }, ol));
|
|
1983
2049
|
const tip = T2(hb + 0.72 * U, L * 0.2);
|
|
1984
|
-
out.push({ k: "ellipse", x: tip.x, y: tip.y, rx: 0.13 * U, ry: 0.2 * U, rot: F.angle + 0.25, fill: p.belly,
|
|
2050
|
+
out.push(__spreadValues({ k: "ellipse", x: tip.x, y: tip.y, rx: 0.13 * U, ry: 0.2 * U, rot: F.angle + 0.25, fill: p.belly }, ol));
|
|
1985
2051
|
break;
|
|
1986
2052
|
}
|
|
1987
2053
|
case "brush": {
|
|
@@ -1995,7 +2061,7 @@ function tail(def, F, hb, ow) {
|
|
|
1995
2061
|
[hb + 0.3 * U, L * 0.66],
|
|
1996
2062
|
[hb * 0.5, L * 0.68]
|
|
1997
2063
|
]);
|
|
1998
|
-
out.push({ k: "path", d: smoothClosed(pts2), fill: p.body,
|
|
2064
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed(pts2), fill: p.body }, ol));
|
|
1999
2065
|
const tip = TP([
|
|
2000
2066
|
[hb + 1.03 * U, L * 0.36],
|
|
2001
2067
|
[hb + 1.06 * U, L * 0.12],
|
|
@@ -2003,12 +2069,12 @@ function tail(def, F, hb, ow) {
|
|
|
2003
2069
|
[hb + 0.72 * U, L * 0.24],
|
|
2004
2070
|
[hb + 0.86 * U, L * 0.34]
|
|
2005
2071
|
]);
|
|
2006
|
-
out.push({ k: "path", d: smoothClosed(tip), fill: p.belly,
|
|
2072
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed(tip), fill: p.belly }, ol));
|
|
2007
2073
|
break;
|
|
2008
2074
|
}
|
|
2009
2075
|
case "pom": {
|
|
2010
2076
|
const c = T2(hb + 0.06 * U, L * 0.88);
|
|
2011
|
-
out.push({ k: "circle", x: c.x, y: c.y, r: 0.2 * U, fill: p.belly,
|
|
2077
|
+
out.push(__spreadValues({ k: "circle", x: c.x, y: c.y, r: 0.2 * U, fill: p.belly }, ol));
|
|
2012
2078
|
break;
|
|
2013
2079
|
}
|
|
2014
2080
|
case "long":
|
|
@@ -2023,15 +2089,15 @@ function tail(def, F, hb, ow) {
|
|
|
2023
2089
|
out.push(...stroke(pts2, 0.14 * U, p.body));
|
|
2024
2090
|
if (def.tail === "tuft") {
|
|
2025
2091
|
const end = pts2[pts2.length - 1];
|
|
2026
|
-
out.push({ k: "circle", x: end.x, y: end.y, r: 0.16 * U, fill: def.extraColors
|
|
2092
|
+
out.push(__spreadValues({ k: "circle", x: end.x, y: end.y, r: 0.16 * U, fill: (_b = (_a = def.extraColors) == null ? void 0 : _a[0]) != null ? _b : p.accent }, ol));
|
|
2027
2093
|
}
|
|
2028
2094
|
if (def.tail === "striped") {
|
|
2029
2095
|
for (const t of [0.35, 0.6, 0.85]) {
|
|
2030
2096
|
const q = T2(hb + 0.35 * U + (0.58 - 0.35) * U * (t * 1.4 > 1 ? 1 : t * 1.4), L * (0.85 - (0.85 - 0) * t));
|
|
2031
|
-
out.push({ k: "line", pts: [q.x - r.x * 0.08 * U, q.y - r.y * 0.08 * U, q.x + r.x * 0.08 * U, q.y + r.y * 0.08 * U], stroke: def.extraColors
|
|
2097
|
+
out.push({ k: "line", pts: [q.x - r.x * 0.08 * U, q.y - r.y * 0.08 * U, q.x + r.x * 0.08 * U, q.y + r.y * 0.08 * U], stroke: (_d = (_c = def.extraColors) == null ? void 0 : _c[0]) != null ? _d : p.outline, lw: 0.06 * U });
|
|
2032
2098
|
}
|
|
2033
2099
|
const end = pts2[pts2.length - 1];
|
|
2034
|
-
out.push({ k: "circle", x: end.x, y: end.y, r: 0.07 * U, fill: def.extraColors
|
|
2100
|
+
out.push({ k: "circle", x: end.x, y: end.y, r: 0.07 * U, fill: (_f = (_e = def.extraColors) == null ? void 0 : _e[0]) != null ? _f : p.outline });
|
|
2035
2101
|
}
|
|
2036
2102
|
break;
|
|
2037
2103
|
}
|
|
@@ -2068,10 +2134,10 @@ function tail(def, F, hb, ow) {
|
|
|
2068
2134
|
break;
|
|
2069
2135
|
}
|
|
2070
2136
|
case "plume": {
|
|
2071
|
-
const cols2 = def.extraColors
|
|
2137
|
+
const cols2 = (_g = def.extraColors) != null ? _g : [p.accent];
|
|
2072
2138
|
[0, 1, 2].forEach((i) => {
|
|
2073
2139
|
const c = T2(hb + (0.12 + i * 0.13) * U, L + (0.32 - i * 0.06) * U);
|
|
2074
|
-
out.push({ k: "ellipse", x: c.x, y: c.y, rx: 0.11 * U, ry: 0.44 * U, rot: F.angle - 0.55 + i * 0.28, fill: cols2[(i + 1) % cols2.length],
|
|
2140
|
+
out.push(__spreadValues({ k: "ellipse", x: c.x, y: c.y, rx: 0.11 * U, ry: 0.44 * U, rot: F.angle - 0.55 + i * 0.28, fill: cols2[(i + 1) % cols2.length] }, ol));
|
|
2075
2141
|
});
|
|
2076
2142
|
break;
|
|
2077
2143
|
}
|
|
@@ -2086,8 +2152,8 @@ function tail(def, F, hb, ow) {
|
|
|
2086
2152
|
[hb + 0.4 * U, L * 1.22],
|
|
2087
2153
|
[hb * 0.3, L * 1.12]
|
|
2088
2154
|
]);
|
|
2089
|
-
out.push({ k: "path", d: smoothClosed(pts2, 0.8), fill: p.body,
|
|
2090
|
-
const c = def.extraColors
|
|
2155
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed(pts2, 0.8), fill: p.body }, ol));
|
|
2156
|
+
const c = (_i = (_h = def.extraColors) == null ? void 0 : _h[0]) != null ? _i : p.accent;
|
|
2091
2157
|
for (const [x, y, l] of [
|
|
2092
2158
|
[0.28, 0.58, 0.26],
|
|
2093
2159
|
[0.62, 0.8, 0.22],
|
|
@@ -2112,9 +2178,9 @@ function tail(def, F, hb, ow) {
|
|
|
2112
2178
|
for (const t of [0.15, 0.45, 0.72]) {
|
|
2113
2179
|
const x = hb + (0.2 + t * 0.7) * U;
|
|
2114
2180
|
const y = L * (0.66 + t * 0.19);
|
|
2115
|
-
out.push({ k: "path", d: roundedPolygon(TP([[x - 0.12 * U, y + 0.05 * U], [x, y - 0.2 * U], [x + 0.12 * U, y + 0.07 * U]]), 0.2), fill: p.accent,
|
|
2181
|
+
out.push(__spreadValues({ k: "path", d: roundedPolygon(TP([[x - 0.12 * U, y + 0.05 * U], [x, y - 0.2 * U], [x + 0.12 * U, y + 0.07 * U]]), 0.2), fill: p.accent }, ol));
|
|
2116
2182
|
}
|
|
2117
|
-
out.push({ k: "path", d: smoothClosed(pts2, 0.7), fill: p.body,
|
|
2183
|
+
out.push(__spreadValues({ k: "path", d: smoothClosed(pts2, 0.7), fill: p.body }, ol));
|
|
2118
2184
|
} else {
|
|
2119
2185
|
const line = TP([
|
|
2120
2186
|
[hb * 0.6, L * 0.9],
|
|
@@ -2144,8 +2210,9 @@ function wand(def, hand, wd, U, ow) {
|
|
|
2144
2210
|
];
|
|
2145
2211
|
}
|
|
2146
2212
|
function fairyWings(def, T2, ht, U, ow) {
|
|
2213
|
+
var _a, _b;
|
|
2147
2214
|
const p = def.palette;
|
|
2148
|
-
const fill = def.extraColors
|
|
2215
|
+
const fill = (_b = (_a = def.extraColors) == null ? void 0 : _a[0]) != null ? _b : "#cdeeff";
|
|
2149
2216
|
const out = [];
|
|
2150
2217
|
for (const s of [-1, 1]) {
|
|
2151
2218
|
const lobes = [
|
|
@@ -2186,8 +2253,9 @@ function fairyWings(def, T2, ht, U, ow) {
|
|
|
2186
2253
|
return out;
|
|
2187
2254
|
}
|
|
2188
2255
|
function petals(def, T2, ht, hb, bulge, L, y1, U, ow, bb) {
|
|
2256
|
+
var _a, _b;
|
|
2189
2257
|
const p = def.palette;
|
|
2190
|
-
const second = def.extraColors
|
|
2258
|
+
const second = (_b = (_a = def.extraColors) == null ? void 0 : _a[1]) != null ? _b : p.belly;
|
|
2191
2259
|
const out = [];
|
|
2192
2260
|
const ang = Math.atan2(T2(1, 0).y - T2(0, 0).y, T2(1, 0).x - T2(0, 0).x);
|
|
2193
2261
|
const n = 5;
|
|
@@ -2224,7 +2292,8 @@ var STAND = {
|
|
|
2224
2292
|
rightAnkle: [0.33, 2.18]
|
|
2225
2293
|
};
|
|
2226
2294
|
function poseBody(spec, { cx = 0.5, cy = 0.36, T: T2 = 0.18 } = {}) {
|
|
2227
|
-
|
|
2295
|
+
var _a;
|
|
2296
|
+
const s = __spreadValues(__spreadValues({}, STAND), spec);
|
|
2228
2297
|
const b = new Array(LANDMARKS * 3).fill(0);
|
|
2229
2298
|
const set = (i, [x, y], v = 0.99) => {
|
|
2230
2299
|
b[i * 3] = cx + x * T2;
|
|
@@ -2232,7 +2301,7 @@ function poseBody(spec, { cx = 0.5, cy = 0.36, T: T2 = 0.18 } = {}) {
|
|
|
2232
2301
|
b[i * 3 + 2] = v;
|
|
2233
2302
|
};
|
|
2234
2303
|
for (const key of Object.keys(P)) set(P[key], s[key]);
|
|
2235
|
-
const tilt = s.tilt
|
|
2304
|
+
const tilt = (_a = s.tilt) != null ? _a : 0;
|
|
2236
2305
|
const around = (dx, dy) => [s.nose[0] + dx * Math.cos(tilt) - dy * Math.sin(tilt), s.nose[1] + dx * Math.sin(tilt) + dy * Math.cos(tilt)];
|
|
2237
2306
|
set(FACE.leftEye, around(-0.1, -0.08));
|
|
2238
2307
|
set(FACE.rightEye, around(0.1, -0.08));
|
|
@@ -2259,8 +2328,9 @@ var BodyInterpolator = class {
|
|
|
2259
2328
|
__publicField(this, "maxExtrapolateMs");
|
|
2260
2329
|
__publicField(this, "lag");
|
|
2261
2330
|
__publicField(this, "extrapolate");
|
|
2262
|
-
|
|
2263
|
-
this.
|
|
2331
|
+
var _a, _b;
|
|
2332
|
+
this.lostMs = (_a = o.lostMs) != null ? _a : 250;
|
|
2333
|
+
this.maxExtrapolateMs = (_b = o.maxExtrapolateMs) != null ? _b : 25;
|
|
2264
2334
|
this.lag = clamp012(o.lag, 1);
|
|
2265
2335
|
this.extrapolate = clamp012(o.extrapolate, 0.5);
|
|
2266
2336
|
}
|
|
@@ -2324,7 +2394,10 @@ var BodyInterpolator = class {
|
|
|
2324
2394
|
if (!(t <= this.lastT)) this.lastT = t;
|
|
2325
2395
|
}
|
|
2326
2396
|
};
|
|
2327
|
-
var now = () =>
|
|
2397
|
+
var now = () => {
|
|
2398
|
+
var _a, _b;
|
|
2399
|
+
return (_b = (_a = __fabiGlobalThis.performance) == null ? void 0 : _a.now()) != null ? _b : Date.now();
|
|
2400
|
+
};
|
|
2328
2401
|
var clamp012 = (v, fallback) => typeof v === "number" && Number.isFinite(v) ? Math.min(Math.max(v, 0), 1) : fallback;
|
|
2329
2402
|
function blend(a, b, u) {
|
|
2330
2403
|
const out = b.slice();
|
|
@@ -2353,7 +2426,10 @@ var BY_ID = new Map(AVATARS.map((a) => [a.id, a]));
|
|
|
2353
2426
|
var DEFAULT_AVATAR = BY_ID.get("fox");
|
|
2354
2427
|
var isAvatarId = (v) => typeof v === "string" && BY_ID.has(v);
|
|
2355
2428
|
var avatarById = (id) => BY_ID.get(id);
|
|
2356
|
-
var resolve = (def) =>
|
|
2429
|
+
var resolve = (def) => {
|
|
2430
|
+
var _a;
|
|
2431
|
+
return typeof def === "string" ? (_a = BY_ID.get(def)) != null ? _a : DEFAULT_AVATAR : def;
|
|
2432
|
+
};
|
|
2357
2433
|
function iconShapes(def, size, band) {
|
|
2358
2434
|
const d = resolve(def);
|
|
2359
2435
|
const body = neutralPose();
|
|
@@ -2415,6 +2491,7 @@ function smoothFace(prev, next, out, amount) {
|
|
|
2415
2491
|
}
|
|
2416
2492
|
}
|
|
2417
2493
|
function bounds(shapes) {
|
|
2494
|
+
var _a, _b, _c, _d;
|
|
2418
2495
|
const b = { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
|
|
2419
2496
|
const addPt = (x, y) => {
|
|
2420
2497
|
b.minX = Math.min(b.minX, x);
|
|
@@ -2423,7 +2500,7 @@ function bounds(shapes) {
|
|
|
2423
2500
|
b.maxY = Math.max(b.maxY, y);
|
|
2424
2501
|
};
|
|
2425
2502
|
for (const s of shapes) {
|
|
2426
|
-
const pad = "lw" in s && s.stroke ? (s.lw
|
|
2503
|
+
const pad = "lw" in s && s.stroke ? ((_a = s.lw) != null ? _a : 1) / 2 : 0;
|
|
2427
2504
|
switch (s.k) {
|
|
2428
2505
|
case "circle":
|
|
2429
2506
|
addPt(s.x - s.r - pad, s.y - s.r - pad);
|
|
@@ -2449,9 +2526,9 @@ function bounds(shapes) {
|
|
|
2449
2526
|
case "group": {
|
|
2450
2527
|
const inner = bounds(s.items);
|
|
2451
2528
|
if (!Number.isFinite(inner.minX)) break;
|
|
2452
|
-
const k = s.s
|
|
2453
|
-
const c = Math.cos(s.rot
|
|
2454
|
-
const sn = Math.sin(s.rot
|
|
2529
|
+
const k = (_b = s.s) != null ? _b : 1;
|
|
2530
|
+
const c = Math.cos((_c = s.rot) != null ? _c : 0);
|
|
2531
|
+
const sn = Math.sin((_d = s.rot) != null ? _d : 0);
|
|
2455
2532
|
for (const [x, y] of [
|
|
2456
2533
|
[inner.minX, inner.minY],
|
|
2457
2534
|
[inner.maxX, inner.minY],
|
|
@@ -2506,6 +2583,7 @@ function applyInverse(m, x, y) {
|
|
|
2506
2583
|
var named = { white: 16777215, black: 0, red: 16711680, transparent: 0 };
|
|
2507
2584
|
var cache = /* @__PURE__ */ new Map();
|
|
2508
2585
|
function parseColor(c) {
|
|
2586
|
+
var _a, _b;
|
|
2509
2587
|
if (typeof c === "number") return [c & 16777215, 1];
|
|
2510
2588
|
const hit = cache.get(c);
|
|
2511
2589
|
if (hit) return hit;
|
|
@@ -2517,7 +2595,7 @@ function parseColor(c) {
|
|
|
2517
2595
|
const v = parseInt(full.slice(0, 6), 16);
|
|
2518
2596
|
if (Number.isFinite(v)) out = [v, full.length === 8 ? parseInt(full.slice(6, 8), 16) / 255 : 1];
|
|
2519
2597
|
} else if (s.startsWith("rgb")) {
|
|
2520
|
-
const n = s.match(/-?\d*\.?\d+%?/g)
|
|
2598
|
+
const n = (_b = (_a = s.match(/-?\d*\.?\d+%?/g)) == null ? void 0 : _a.map((t) => t.endsWith("%") ? parseFloat(t) / 100 * 255 : parseFloat(t))) != null ? _b : [];
|
|
2521
2599
|
const [r = 255, g = 255, b = 255] = n;
|
|
2522
2600
|
const a = n[3] === void 0 ? 1 : s.match(/,\s*[\d.]+%\s*\)$/) ? n[3] / 255 : n[3];
|
|
2523
2601
|
out = [(clamp255(r) << 16 | clamp255(g) << 8 | clamp255(b)) >>> 0, Math.min(Math.max(a, 0), 1)];
|
|
@@ -2544,7 +2622,7 @@ function packColor(rgb, alpha, additive = false) {
|
|
|
2544
2622
|
const A = additive ? 0 : a * 255;
|
|
2545
2623
|
return (Math.round(A) << 24 | Math.round(b) << 16 | Math.round(g) << 8 | Math.round(r)) >>> 0;
|
|
2546
2624
|
}
|
|
2547
|
-
var cssColor = (rgb, alpha = 1) =>
|
|
2625
|
+
var cssColor = (rgb, alpha = 1) => "rgba(".concat(rgb >> 16 & 255, ",").concat(rgb >> 8 & 255, ",").concat(rgb & 255, ",").concat(alpha, ")");
|
|
2548
2626
|
function mulColor(x, y) {
|
|
2549
2627
|
if (x === 16777215) return y;
|
|
2550
2628
|
if (y === 16777215) return x;
|
|
@@ -2556,13 +2634,13 @@ var EASE = {
|
|
|
2556
2634
|
quadIn: (t) => t * t,
|
|
2557
2635
|
quadOut: (t) => t * (2 - t),
|
|
2558
2636
|
quadInOut: (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t,
|
|
2559
|
-
cubicOut: (t) => 1 - (1 - t
|
|
2637
|
+
cubicOut: (t) => 1 - __pow(1 - t, 3),
|
|
2560
2638
|
sineInOut: (t) => -(Math.cos(Math.PI * t) - 1) / 2,
|
|
2561
2639
|
backOut: (t) => {
|
|
2562
2640
|
const c = 1.70158;
|
|
2563
|
-
return 1 + (c + 1) * (t - 1
|
|
2641
|
+
return 1 + (c + 1) * __pow(t - 1, 3) + c * __pow(t - 1, 2);
|
|
2564
2642
|
},
|
|
2565
|
-
elasticOut: (t) => t === 0 || t === 1 ? t : 2
|
|
2643
|
+
elasticOut: (t) => t === 0 || t === 1 ? t : __pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * (2 * Math.PI / 3)) + 1,
|
|
2566
2644
|
bounceOut: (t) => {
|
|
2567
2645
|
const n = 7.5625;
|
|
2568
2646
|
const d = 2.75;
|
|
@@ -2588,21 +2666,22 @@ var WATCHED = ["x", "y", "scale", "scaleX", "scaleY", "rotation", "alpha", "visi
|
|
|
2588
2666
|
var warned = /* @__PURE__ */ new WeakSet();
|
|
2589
2667
|
var trapped = /* @__PURE__ */ new WeakMap();
|
|
2590
2668
|
function describe(n) {
|
|
2669
|
+
var _a;
|
|
2591
2670
|
const o = n;
|
|
2592
|
-
const kind = n.constructor
|
|
2593
|
-
if (typeof o.text === "string") return
|
|
2594
|
-
if (o.spec && typeof o.spec.type === "string") return
|
|
2595
|
-
if (o.frameName) return
|
|
2671
|
+
const kind = ((_a = n.constructor) == null ? void 0 : _a.name) || "Node";
|
|
2672
|
+
if (typeof o.text === "string") return "".concat(kind, " '").concat(o.text.length > 24 ? "".concat(o.text.slice(0, 24), "\u2026") : o.text, "'");
|
|
2673
|
+
if (o.spec && typeof o.spec.type === "string") return "".concat(kind, " (").concat(o.spec.type, ")");
|
|
2674
|
+
if (o.frameName) return "".concat(kind, " '").concat(o.frameName, "'");
|
|
2596
2675
|
return kind;
|
|
2597
2676
|
}
|
|
2598
2677
|
function warnUse(n, what) {
|
|
2678
|
+
var _a, _b;
|
|
2599
2679
|
if (warned.has(n)) return;
|
|
2600
2680
|
warned.add(n);
|
|
2601
2681
|
const w2 = n;
|
|
2602
2682
|
const after = w2.destroyed ? "destroy()" : "release() to its node pool";
|
|
2603
|
-
const where = new Error().stack
|
|
2604
|
-
console.warn(
|
|
2605
|
-
${where}`);
|
|
2683
|
+
const where = (_b = (_a = new Error().stack) == null ? void 0 : _a.split("\n").slice(3, 6).join("\n")) != null ? _b : "";
|
|
2684
|
+
console.warn("[engine] ".concat(describe(n), " used after ").concat(after, ": ").concat(what, ". It is not on the stage").concat(w2._free ? ", and the pool gives it to the next get()" : "", ": drop your reference to it.\n").concat(where));
|
|
2606
2685
|
}
|
|
2607
2686
|
function watch(n) {
|
|
2608
2687
|
if (trapped.has(n) || warned.has(n)) return;
|
|
@@ -2617,7 +2696,7 @@ function watch(n) {
|
|
|
2617
2696
|
enumerable: isOwn,
|
|
2618
2697
|
get: () => isOwn ? own.get(k) : Reflect.get(Object.getPrototypeOf(n), k, n),
|
|
2619
2698
|
set: (v) => {
|
|
2620
|
-
warnUse(n,
|
|
2699
|
+
warnUse(n, "setting ".concat(k));
|
|
2621
2700
|
unwatch(n);
|
|
2622
2701
|
n[k] = v;
|
|
2623
2702
|
}
|
|
@@ -3001,7 +3080,8 @@ var Node = class {
|
|
|
3001
3080
|
}
|
|
3002
3081
|
/** Free for the game: speed, state, anything (made on first use). */
|
|
3003
3082
|
get data() {
|
|
3004
|
-
|
|
3083
|
+
var _a;
|
|
3084
|
+
return (_a = this._data) != null ? _a : this._data = {};
|
|
3005
3085
|
}
|
|
3006
3086
|
set data(v) {
|
|
3007
3087
|
this._data = v;
|
|
@@ -3060,6 +3140,7 @@ var Node = class {
|
|
|
3060
3140
|
}
|
|
3061
3141
|
/** Removes the node: invisible at once (its parent null), out of its group's children at the end of the frame. Its tweens stop. */
|
|
3062
3142
|
destroy() {
|
|
3143
|
+
var _a;
|
|
3063
3144
|
if (this.destroyed) return;
|
|
3064
3145
|
if (this._free) unwatch(this);
|
|
3065
3146
|
this.visible = false;
|
|
@@ -3070,7 +3151,7 @@ var Node = class {
|
|
|
3070
3151
|
release(this._i, this);
|
|
3071
3152
|
untrack(this);
|
|
3072
3153
|
this.kernel.tweens.stopAll(this);
|
|
3073
|
-
this._pool
|
|
3154
|
+
(_a = this._pool) == null ? void 0 : _a.forget(this);
|
|
3074
3155
|
if (true) watch(this);
|
|
3075
3156
|
}
|
|
3076
3157
|
/** world, computed now from the parents (for hit tests between draws). */
|
|
@@ -3320,7 +3401,7 @@ var Sprite = class extends Node {
|
|
|
3320
3401
|
/** The name the frame came from: baked frames are looked up again after the atlas was wiped. */
|
|
3321
3402
|
__publicField(this, "frameName", null);
|
|
3322
3403
|
if (frame) this.frame = frame;
|
|
3323
|
-
if (props
|
|
3404
|
+
if ((props == null ? void 0 : props.anchor) === void 0) this.useFrameAnchor();
|
|
3324
3405
|
if (props) this.set(props);
|
|
3325
3406
|
}
|
|
3326
3407
|
/** What it shows: set a frame or the name of a loaded or baked one (an animation swaps it every few frames). */
|
|
@@ -3339,24 +3420,28 @@ var Sprite = class extends Node {
|
|
|
3339
3420
|
}
|
|
3340
3421
|
/** The content size the frame has, stage units (without its margin; untrimmed). */
|
|
3341
3422
|
get naturalWidth() {
|
|
3423
|
+
var _a;
|
|
3342
3424
|
const f2 = this.frameNow();
|
|
3343
|
-
return f2 ? (f2.sw
|
|
3425
|
+
return f2 ? ((_a = f2.sw) != null ? _a : f2.w) / f2.scale - f2.margin * 2 : 0;
|
|
3344
3426
|
}
|
|
3345
3427
|
/** The content height the frame has, stage units (without its margin; untrimmed). */
|
|
3346
3428
|
get naturalHeight() {
|
|
3429
|
+
var _a;
|
|
3347
3430
|
const f2 = this.frameNow();
|
|
3348
|
-
return f2 ? (f2.sh
|
|
3431
|
+
return f2 ? ((_a = f2.sh) != null ? _a : f2.h) / f2.scale - f2.margin * 2 : 0;
|
|
3349
3432
|
}
|
|
3350
3433
|
/** Local width, stage units: the frame's own (naturalWidth) until set; setting it stretches the sprite. */
|
|
3351
3434
|
get width() {
|
|
3352
|
-
|
|
3435
|
+
var _a;
|
|
3436
|
+
return (_a = this._w) != null ? _a : this.naturalWidth;
|
|
3353
3437
|
}
|
|
3354
3438
|
set width(v) {
|
|
3355
3439
|
this._w = v;
|
|
3356
3440
|
}
|
|
3357
3441
|
/** Local height, stage units: the frame's own (naturalHeight) until set; setting it stretches the sprite. */
|
|
3358
3442
|
get height() {
|
|
3359
|
-
|
|
3443
|
+
var _a;
|
|
3444
|
+
return (_a = this._h) != null ? _a : this.naturalHeight;
|
|
3360
3445
|
}
|
|
3361
3446
|
set height(v) {
|
|
3362
3447
|
this._h = v;
|
|
@@ -3366,8 +3451,9 @@ var Sprite = class extends Node {
|
|
|
3366
3451
|
* (a number returned through a getter on several classes is boxed on every call).
|
|
3367
3452
|
*/
|
|
3368
3453
|
sizeQ(f2) {
|
|
3369
|
-
|
|
3370
|
-
frameQ[
|
|
3454
|
+
var _a, _b, _c, _d;
|
|
3455
|
+
frameQ[0] = (_b = this._w) != null ? _b : ((_a = f2.sw) != null ? _a : f2.w) / f2.scale - f2.margin * 2;
|
|
3456
|
+
frameQ[1] = (_d = this._h) != null ? _d : ((_c = f2.sh) != null ? _c : f2.h) / f2.scale - f2.margin * 2;
|
|
3371
3457
|
}
|
|
3372
3458
|
/** The frame to draw now (subclasses bake it on demand). */
|
|
3373
3459
|
frameNow() {
|
|
@@ -3375,10 +3461,11 @@ var Sprite = class extends Node {
|
|
|
3375
3461
|
return this._frame;
|
|
3376
3462
|
}
|
|
3377
3463
|
useFrameAnchor() {
|
|
3464
|
+
var _a, _b;
|
|
3378
3465
|
const f2 = this._frame;
|
|
3379
3466
|
if (!f2) return;
|
|
3380
|
-
const w2 = (f2.sw
|
|
3381
|
-
const h = (f2.sh
|
|
3467
|
+
const w2 = ((_a = f2.sw) != null ? _a : f2.w) / f2.scale - f2.margin * 2;
|
|
3468
|
+
const h = ((_b = f2.sh) != null ? _b : f2.h) / f2.scale - f2.margin * 2;
|
|
3382
3469
|
this.anchorX = w2 > 0 ? (f2.ox - f2.margin) / w2 : 0;
|
|
3383
3470
|
this.anchorY = h > 0 ? (f2.oy - f2.margin) / h : 0;
|
|
3384
3471
|
}
|
|
@@ -3425,6 +3512,7 @@ function spans(out, size, a, b, px, scale) {
|
|
|
3425
3512
|
}
|
|
3426
3513
|
var frameQ = new Float64Array(5);
|
|
3427
3514
|
function drawFrameQ(ctx, f2, m, slice, tint2, blend2) {
|
|
3515
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3428
3516
|
const q = frameQ;
|
|
3429
3517
|
const w2 = q[0];
|
|
3430
3518
|
const h = q[1];
|
|
@@ -3432,14 +3520,14 @@ function drawFrameQ(ctx, f2, m, slice, tint2, blend2) {
|
|
|
3432
3520
|
const ay = q[3];
|
|
3433
3521
|
const alpha = q[4];
|
|
3434
3522
|
const tex = ctx.tex(f2.surface);
|
|
3435
|
-
const s = slice === 0 ? f2.slice
|
|
3523
|
+
const s = slice === 0 ? (_a = f2.slice) != null ? _a : 0 : slice;
|
|
3436
3524
|
if (s === 0) {
|
|
3437
|
-
const nw = (f2.sw
|
|
3438
|
-
const nh = (f2.sh
|
|
3525
|
+
const nw = ((_b = f2.sw) != null ? _b : f2.w) / f2.scale - f2.margin * 2;
|
|
3526
|
+
const nh = ((_c = f2.sh) != null ? _c : f2.h) / f2.scale - f2.margin * 2;
|
|
3439
3527
|
const kx = nw > 0 ? w2 / nw : 1;
|
|
3440
3528
|
const ky = nh > 0 ? h / nh : 1;
|
|
3441
|
-
const x02 = -ax * w2 + ((f2.tx
|
|
3442
|
-
const y02 = -ay * h + ((f2.ty
|
|
3529
|
+
const x02 = -ax * w2 + (((_d = f2.tx) != null ? _d : 0) / f2.scale - f2.margin) * kx;
|
|
3530
|
+
const y02 = -ay * h + (((_e = f2.ty) != null ? _e : 0) / f2.scale - f2.margin) * ky;
|
|
3443
3531
|
translated(m, x02, y02);
|
|
3444
3532
|
QUAD[0] = f2.w / f2.scale * kx;
|
|
3445
3533
|
QUAD[1] = f2.h / f2.scale * ky;
|
|
@@ -3447,17 +3535,17 @@ function drawFrameQ(ctx, f2, m, slice, tint2, blend2) {
|
|
|
3447
3535
|
ctx.r.quadQ(tex, f2, tmp, tint2, blend2);
|
|
3448
3536
|
return;
|
|
3449
3537
|
}
|
|
3450
|
-
const tx = f2.tx
|
|
3451
|
-
const ty = f2.ty
|
|
3452
|
-
const rx = (f2.sw
|
|
3453
|
-
const by = (f2.sh
|
|
3538
|
+
const tx = (_f = f2.tx) != null ? _f : 0;
|
|
3539
|
+
const ty = (_g = f2.ty) != null ? _g : 0;
|
|
3540
|
+
const rx = ((_h = f2.sw) != null ? _h : f2.w) - f2.w - tx;
|
|
3541
|
+
const by = ((_i = f2.sh) != null ? _i : f2.h) - f2.h - ty;
|
|
3454
3542
|
const x0 = -ax * w2 - f2.margin + tx / f2.scale;
|
|
3455
3543
|
const y0 = -ay * h - f2.margin + ty / f2.scale;
|
|
3456
3544
|
spans(cols, w2 + f2.margin * 2 - (tx + rx) / f2.scale, (typeof s === "number" ? s : s[3]) - tx, (typeof s === "number" ? s : s[1]) - rx, f2.w, f2.scale);
|
|
3457
3545
|
spans(rows, h + f2.margin * 2 - (ty + by) / f2.scale, (typeof s === "number" ? s : s[0]) - ty, (typeof s === "number" ? s : s[2]) - by, f2.h, f2.scale);
|
|
3458
3546
|
translated(m, x0, y0);
|
|
3459
3547
|
QUAD[2] = alpha;
|
|
3460
|
-
if (ctx.r.nineQ
|
|
3548
|
+
if ((_k = (_j = ctx.r).nineQ) == null ? void 0 : _k.call(_j, tex, f2, cols, rows, tmp, tint2, blend2)) return;
|
|
3461
3549
|
for (let j = 0; j < 12; j += 4) {
|
|
3462
3550
|
const rh = rows[j + 1];
|
|
3463
3551
|
const th = rows[j + 3];
|
|
@@ -3522,20 +3610,23 @@ var Shape = class extends Sprite {
|
|
|
3522
3610
|
return this.bake().frame;
|
|
3523
3611
|
}
|
|
3524
3612
|
sizeQ() {
|
|
3613
|
+
var _a, _b;
|
|
3525
3614
|
const b = this.bake();
|
|
3526
|
-
frameQ[0] = this._w
|
|
3527
|
-
frameQ[1] = this._h
|
|
3615
|
+
frameQ[0] = (_a = this._w) != null ? _a : b.w;
|
|
3616
|
+
frameQ[1] = (_b = this._h) != null ? _b : b.h;
|
|
3528
3617
|
}
|
|
3529
3618
|
/** Local width, stage units: the shape's own until set (a roundRect is redrawn to it, others stretched). */
|
|
3530
3619
|
get width() {
|
|
3531
|
-
|
|
3620
|
+
var _a;
|
|
3621
|
+
return (_a = this._w) != null ? _a : this.bake().w;
|
|
3532
3622
|
}
|
|
3533
3623
|
set width(v) {
|
|
3534
3624
|
this._w = v;
|
|
3535
3625
|
}
|
|
3536
3626
|
/** Local height, stage units: the shape's own until set. */
|
|
3537
3627
|
get height() {
|
|
3538
|
-
|
|
3628
|
+
var _a;
|
|
3629
|
+
return (_a = this._h) != null ? _a : this.bake().h;
|
|
3539
3630
|
}
|
|
3540
3631
|
set height(v) {
|
|
3541
3632
|
this._h = v;
|
|
@@ -3545,6 +3636,7 @@ var pick = (v, d, rand) => v === void 0 ? d : typeof v === "number" ? v : v[0] +
|
|
|
3545
3636
|
var _Particles = class _Particles extends Node {
|
|
3546
3637
|
/** Use engine.particles(frame, opts). */
|
|
3547
3638
|
constructor(kernel, frame, opts = {}) {
|
|
3639
|
+
var _a, _b, _c, _d;
|
|
3548
3640
|
super(kernel);
|
|
3549
3641
|
/** The pool's size: most particles alive at once. */
|
|
3550
3642
|
__publicField(this, "max");
|
|
@@ -3560,12 +3652,12 @@ var _Particles = class _Particles extends Node {
|
|
|
3560
3652
|
/** The random source for bursts (a seeded rng in tests and replays). */
|
|
3561
3653
|
__publicField(this, "random", Math.random);
|
|
3562
3654
|
this.frameRef = frame;
|
|
3563
|
-
this.max = Math.max(1, Math.floor(opts.max
|
|
3655
|
+
this.max = Math.max(1, Math.floor((_a = opts.max) != null ? _a : 200));
|
|
3564
3656
|
this.f = new Float32Array(this.max * _Particles.W);
|
|
3565
3657
|
this.tints = new Uint32Array(this.max);
|
|
3566
|
-
this.blend = opts.blend
|
|
3567
|
-
this.gravity = opts.gravity
|
|
3568
|
-
this.drag = opts.drag
|
|
3658
|
+
this.blend = (_b = opts.blend) != null ? _b : "normal";
|
|
3659
|
+
this.gravity = (_c = opts.gravity) != null ? _c : 0;
|
|
3660
|
+
this.drag = (_d = opts.drag) != null ? _d : 1;
|
|
3569
3661
|
}
|
|
3570
3662
|
/** Particles alive. */
|
|
3571
3663
|
get alive() {
|
|
@@ -3578,6 +3670,7 @@ var _Particles = class _Particles extends Node {
|
|
|
3578
3670
|
* sparks.burst(star.x, star.y, engine.tier.scale(24), { tint: hand.color, speed: [100, 300] })
|
|
3579
3671
|
*/
|
|
3580
3672
|
burst(x, y, n, o = {}) {
|
|
3673
|
+
var _a, _b, _c, _d, _e;
|
|
3581
3674
|
const W = _Particles.W;
|
|
3582
3675
|
const rand = this.random;
|
|
3583
3676
|
const tint2 = o.tint === void 0 ? 16777215 : parseColor(o.tint)[0];
|
|
@@ -3595,10 +3688,10 @@ var _Particles = class _Particles extends Node {
|
|
|
3595
3688
|
}
|
|
3596
3689
|
i = best;
|
|
3597
3690
|
} else this.count++;
|
|
3598
|
-
const a = (o.angle
|
|
3691
|
+
const a = ((_a = o.angle) != null ? _a : 0) + (o.spread === void 0 ? rand() * Math.PI * 2 : (rand() - 0.5) * o.spread);
|
|
3599
3692
|
const sp = pick(o.speed, 200, rand);
|
|
3600
|
-
const s0 = Array.isArray(o.scale) ? o.scale[0] : o.scale
|
|
3601
|
-
const s1 = Array.isArray(o.scale) ? o.scale[1] : o.scale
|
|
3693
|
+
const s0 = Array.isArray(o.scale) ? o.scale[0] : (_b = o.scale) != null ? _b : 1;
|
|
3694
|
+
const s1 = Array.isArray(o.scale) ? o.scale[1] : (_c = o.scale) != null ? _c : 1;
|
|
3602
3695
|
const p = i * W;
|
|
3603
3696
|
this.f[p] = x;
|
|
3604
3697
|
this.f[p + 1] = y;
|
|
@@ -3607,10 +3700,10 @@ var _Particles = class _Particles extends Node {
|
|
|
3607
3700
|
this.f[p + 4] = 0;
|
|
3608
3701
|
this.f[p + 5] = Math.max(pick(o.life, 0.8, rand), 0.01);
|
|
3609
3702
|
this.f[p + 6] = rand() * Math.PI * 2;
|
|
3610
|
-
this.f[p + 7] = (rand() - 0.5) * 2 * (o.spin
|
|
3703
|
+
this.f[p + 7] = (rand() - 0.5) * 2 * ((_d = o.spin) != null ? _d : 0);
|
|
3611
3704
|
this.f[p + 8] = s0;
|
|
3612
3705
|
this.f[p + 9] = s1;
|
|
3613
|
-
this.f[p + 10] = o.alpha
|
|
3706
|
+
this.f[p + 10] = (_e = o.alpha) != null ? _e : 1;
|
|
3614
3707
|
this.tints[i] = tint2;
|
|
3615
3708
|
}
|
|
3616
3709
|
}
|
|
@@ -3689,7 +3782,7 @@ var Particles = _Particles;
|
|
|
3689
3782
|
var AnimatedSprite = class extends Sprite {
|
|
3690
3783
|
/** Use engine.animation(frames, props). */
|
|
3691
3784
|
constructor(kernel, def, props = {}) {
|
|
3692
|
-
const { fps, loop, playing, speed, onComplete,
|
|
3785
|
+
const _a = props, { fps, loop, playing, speed, onComplete } = _a, rest = __objRest(_a, ["fps", "loop", "playing", "speed", "onComplete"]);
|
|
3693
3786
|
if (!def.frames.length) throw new Error("[engine] an animation needs at least one frame");
|
|
3694
3787
|
super(kernel, def.frames[0], rest);
|
|
3695
3788
|
/** The frames, in order. */
|
|
@@ -3710,10 +3803,10 @@ var AnimatedSprite = class extends Sprite {
|
|
|
3710
3803
|
__publicField(this, "t", 0);
|
|
3711
3804
|
this.frames = def.frames;
|
|
3712
3805
|
this.durations = def.durations && fps === void 0 ? def.durations : null;
|
|
3713
|
-
this.fps = fps
|
|
3806
|
+
this.fps = fps != null ? fps : 12;
|
|
3714
3807
|
this.loop = loop !== false;
|
|
3715
|
-
this.speed = speed
|
|
3716
|
-
this.onComplete = onComplete
|
|
3808
|
+
this.speed = speed != null ? speed : 1;
|
|
3809
|
+
this.onComplete = onComplete != null ? onComplete : null;
|
|
3717
3810
|
this._playing = playing !== false;
|
|
3718
3811
|
if (this.speed < 0) this.show(def.frames.length - 1);
|
|
3719
3812
|
}
|
|
@@ -3763,11 +3856,13 @@ var AnimatedSprite = class extends Sprite {
|
|
|
3763
3856
|
this.frame = this.frames[i];
|
|
3764
3857
|
}
|
|
3765
3858
|
secondsOf(i) {
|
|
3766
|
-
|
|
3859
|
+
var _a;
|
|
3860
|
+
const d = (_a = this.durations) == null ? void 0 : _a[i];
|
|
3767
3861
|
return d !== void 0 && d > 0 ? d : 1 / Math.max(this.fps, 1e-3);
|
|
3768
3862
|
}
|
|
3769
3863
|
/** Advances by dt seconds of game time (the engine calls it). */
|
|
3770
3864
|
update(dt) {
|
|
3865
|
+
var _a;
|
|
3771
3866
|
if (!this._playing || this.destroyed || this.speed === 0) return;
|
|
3772
3867
|
const n = this.frames.length;
|
|
3773
3868
|
const back = this.speed < 0;
|
|
@@ -3783,7 +3878,7 @@ var AnimatedSprite = class extends Sprite {
|
|
|
3783
3878
|
this.t = 0;
|
|
3784
3879
|
this._playing = false;
|
|
3785
3880
|
this.show(i);
|
|
3786
|
-
this.onComplete
|
|
3881
|
+
(_a = this.onComplete) == null ? void 0 : _a.call(this);
|
|
3787
3882
|
return;
|
|
3788
3883
|
}
|
|
3789
3884
|
i = back ? n - 1 : 0;
|
|
@@ -3814,7 +3909,7 @@ var ShelfPacker = class {
|
|
|
3814
3909
|
const f2 = this.free[i];
|
|
3815
3910
|
if (f2.w >= pw && f2.h >= ph && f2.w * f2.h <= pw * ph * 2) {
|
|
3816
3911
|
this.free.splice(i, 1);
|
|
3817
|
-
return {
|
|
3912
|
+
return __spreadProps(__spreadValues({}, this.inner(f2.x, f2.y, w2, h)), { slot: f2 });
|
|
3818
3913
|
}
|
|
3819
3914
|
}
|
|
3820
3915
|
let best = null;
|
|
@@ -3900,7 +3995,7 @@ var Atlas = class {
|
|
|
3900
3995
|
release(f2) {
|
|
3901
3996
|
if (f2.gen !== this.gen) return;
|
|
3902
3997
|
const p = this.pages.find((pg) => pg.surface === f2.surface);
|
|
3903
|
-
p
|
|
3998
|
+
p == null ? void 0 : p.packer.release(f2);
|
|
3904
3999
|
}
|
|
3905
4000
|
/**
|
|
3906
4001
|
* Bakes again into the same place, if the new size fits in it (texts that change): the frame, updated, or null
|
|
@@ -3938,7 +4033,7 @@ var Atlas = class {
|
|
|
3938
4033
|
place = page.packer.alloc(W, H);
|
|
3939
4034
|
}
|
|
3940
4035
|
}
|
|
3941
|
-
if (!place) throw new Error(
|
|
4036
|
+
if (!place) throw new Error("[engine] ".concat(W, "\xD7").concat(H, " does not fit an atlas page"));
|
|
3942
4037
|
const r = place;
|
|
3943
4038
|
if (r.slot) {
|
|
3944
4039
|
const s = r.slot;
|
|
@@ -3992,10 +4087,14 @@ var Atlas = class {
|
|
|
3992
4087
|
|
|
3993
4088
|
// ../sdk/src/avatars.ts
|
|
3994
4089
|
var frameTime = () => {
|
|
3995
|
-
|
|
3996
|
-
|
|
4090
|
+
var _a, _b, _c;
|
|
4091
|
+
const t = typeof document !== "undefined" ? (_a = document.timeline) == null ? void 0 : _a.currentTime : null;
|
|
4092
|
+
return typeof t === "number" && Number.isFinite(t) ? t : (_c = (_b = __fabiGlobalThis.performance) == null ? void 0 : _b.now()) != null ? _c : Date.now();
|
|
4093
|
+
};
|
|
4094
|
+
var clockNow = () => {
|
|
4095
|
+
var _a, _b;
|
|
4096
|
+
return (_b = (_a = __fabiGlobalThis.performance) == null ? void 0 : _a.now()) != null ? _b : Date.now();
|
|
3997
4097
|
};
|
|
3998
|
-
var clockNow = () => globalThis.performance?.now() ?? Date.now();
|
|
3999
4098
|
var AvatarBook = class {
|
|
4000
4099
|
/** now: this frame's time (tests). */
|
|
4001
4100
|
constructor(now3 = frameTime) {
|
|
@@ -4014,11 +4113,12 @@ var AvatarBook = class {
|
|
|
4014
4113
|
* this animation frame, or a player id's (null if none yet).
|
|
4015
4114
|
*/
|
|
4016
4115
|
__publicField(this, "smoothedBody", (who, options = {}) => {
|
|
4116
|
+
var _a;
|
|
4017
4117
|
const interpolate = options.interpolate !== false;
|
|
4018
4118
|
if (typeof who === "number") {
|
|
4019
4119
|
const last2 = this.smoothed.get(who);
|
|
4020
4120
|
if (!last2) return null;
|
|
4021
|
-
return interpolate ? this.lerp.at(who, this.tick())
|
|
4121
|
+
return interpolate ? (_a = this.lerp.at(who, this.tick())) != null ? _a : last2.body : last2.body;
|
|
4022
4122
|
}
|
|
4023
4123
|
if (typeof who !== "object" || who === null || !Array.isArray(who.body)) return null;
|
|
4024
4124
|
return this.posed(who.id, who.body, smoothAmount(options.smooth, this.defaultAmount), interpolate);
|
|
@@ -4049,27 +4149,30 @@ var AvatarBook = class {
|
|
|
4049
4149
|
* (fox, lion, dragon, unicorn: the 6–8 band's, as no age is known here) before the first frame, from an older host, or for an id this SDK doesn't know.
|
|
4050
4150
|
*/
|
|
4051
4151
|
of(player) {
|
|
4152
|
+
var _a;
|
|
4052
4153
|
if (typeof player === "object" && player !== null) return player.avatar !== void 0 ? this.resolve(player.id, player.avatar) : this.of(player.id);
|
|
4053
|
-
return this.known.get(player)
|
|
4154
|
+
return (_a = this.known.get(player)) != null ? _a : defaultAvatarFor(player - 1);
|
|
4054
4155
|
}
|
|
4055
4156
|
/**
|
|
4056
4157
|
* The body to draw for this player now: body smoothed (amount below 1) against the player's previous one, then,
|
|
4057
4158
|
* with interpolate, at this animation frame's time between the last two.
|
|
4058
4159
|
*/
|
|
4059
4160
|
posed(player, body, amount, interpolate = true) {
|
|
4161
|
+
var _a;
|
|
4060
4162
|
const sample = this.smooth(player, body, amount);
|
|
4061
|
-
return interpolate ? this.lerp.at(player, this.tick())
|
|
4163
|
+
return interpolate ? (_a = this.lerp.at(player, this.tick())) != null ? _a : sample : sample;
|
|
4062
4164
|
}
|
|
4063
4165
|
/** body smoothed against this player's previous one; the same body twice in a row is smoothed once. */
|
|
4064
4166
|
smooth(player, body, amount) {
|
|
4167
|
+
var _a, _b;
|
|
4065
4168
|
const last2 = this.smoothed.get(player);
|
|
4066
4169
|
if (last2 && last2.raw === body && last2.amount === amount) return last2.body;
|
|
4067
4170
|
if (last2 && last2.amount !== amount) this.lerp.forget(player);
|
|
4068
|
-
const next = amount < 1 ? smoothBody(last2
|
|
4171
|
+
const next = amount < 1 ? smoothBody(last2 == null ? void 0 : last2.body, body, amount) : body;
|
|
4069
4172
|
this.smoothed.set(player, { raw: body, body: next, amount });
|
|
4070
4173
|
const at = this.times.get(body);
|
|
4071
|
-
const arrival = at
|
|
4072
|
-
this.lerp.push(player, at
|
|
4174
|
+
const arrival = (_a = at == null ? void 0 : at.arrival) != null ? _a : clockNow();
|
|
4175
|
+
this.lerp.push(player, (_b = at == null ? void 0 : at.t) != null ? _b : arrival, next, arrival);
|
|
4073
4176
|
return next;
|
|
4074
4177
|
}
|
|
4075
4178
|
/**
|
|
@@ -4452,8 +4555,9 @@ var Canvas2DRenderer = class extends Layered {
|
|
|
4452
4555
|
this.updateTexture(t);
|
|
4453
4556
|
}
|
|
4454
4557
|
begin(clear, clearAlpha, scale) {
|
|
4558
|
+
var _a;
|
|
4455
4559
|
this.resetLayers(scale);
|
|
4456
|
-
this.fxr
|
|
4560
|
+
(_a = this.fxr) == null ? void 0 : _a.tick();
|
|
4457
4561
|
this.frame++;
|
|
4458
4562
|
this.quads = 0;
|
|
4459
4563
|
this.top = this.base;
|
|
@@ -4513,7 +4617,7 @@ var Canvas2DRenderer = class extends Layered {
|
|
|
4513
4617
|
* side (sharp pieces rather than a scratch canvas that big, or a downscaled, blurred whole).
|
|
4514
4618
|
*/
|
|
4515
4619
|
nineQ(t, r, cols2, rows2, m, tint2, blend2) {
|
|
4516
|
-
var _a, _b;
|
|
4620
|
+
var _a, _b, _c;
|
|
4517
4621
|
const w2 = cols2[8] + cols2[9];
|
|
4518
4622
|
const h = rows2[8] + rows2[9];
|
|
4519
4623
|
const pw = Math.ceil(w2 * Math.hypot(m[0], m[1]) * this.scale - 1e-6);
|
|
@@ -4521,7 +4625,7 @@ var Canvas2DRenderer = class extends Layered {
|
|
|
4521
4625
|
if (m[1] === 0 && m[2] === 0 || pw > 4096 || ph > 4096) return false;
|
|
4522
4626
|
if (!(pw > 0 && ph > 0 && QUAD[2] > 0) || this.mute) return true;
|
|
4523
4627
|
let sc = this.kept(t, r, cols2, rows2, pw, ph, tint2);
|
|
4524
|
-
const k = (sc
|
|
4628
|
+
const k = (sc != null ? sc : sc = (_c = (_a = this.scratch)[_b = 13 * Math.ceil(Math.log2(pw)) + Math.ceil(Math.log2(ph))]) != null ? _c : _a[_b] = document.createElement("canvas").getContext("2d")).canvas;
|
|
4525
4629
|
if (k.width < pw) k.width = pw;
|
|
4526
4630
|
if (k.height < ph) k.height = ph;
|
|
4527
4631
|
if (!this.hit) {
|
|
@@ -4587,7 +4691,7 @@ var Canvas2DRenderer = class extends Layered {
|
|
|
4587
4691
|
this.dropNine(old, fits);
|
|
4588
4692
|
if (fits) reuse = old.ctx;
|
|
4589
4693
|
}
|
|
4590
|
-
const ctx = reuse
|
|
4694
|
+
const ctx = reuse != null ? reuse : document.createElement("canvas").getContext("2d");
|
|
4591
4695
|
const c = ctx.canvas;
|
|
4592
4696
|
if (!reuse) {
|
|
4593
4697
|
c.width = pw;
|
|
@@ -4733,9 +4837,10 @@ var Canvas2DRenderer = class extends Layered {
|
|
|
4733
4837
|
}
|
|
4734
4838
|
/** A layer's canvas over the area rx0… (pixels), under the clip: 'destination-in' for a mask, through filters. */
|
|
4735
4839
|
composite(src, mask, alpha, filters) {
|
|
4840
|
+
var _a;
|
|
4736
4841
|
let img = src;
|
|
4737
4842
|
let css = "none";
|
|
4738
|
-
const f2 = filters && fx.c2d ? this.fxr
|
|
4843
|
+
const f2 = filters && fx.c2d ? (_a = this.fxr) != null ? _a : this.fxr = fx.c2d(this) : null;
|
|
4739
4844
|
if (f2) {
|
|
4740
4845
|
img = f2.chain(src, filters);
|
|
4741
4846
|
css = f2.css;
|
|
@@ -4769,11 +4874,12 @@ var Canvas2DRenderer = class extends Layered {
|
|
|
4769
4874
|
this.restoredListeners.push(l);
|
|
4770
4875
|
}
|
|
4771
4876
|
destroy() {
|
|
4877
|
+
var _a;
|
|
4772
4878
|
this.tinted.clear();
|
|
4773
4879
|
this.dropNines();
|
|
4774
4880
|
this.layers = [];
|
|
4775
4881
|
this.scratch = [];
|
|
4776
|
-
this.fxr
|
|
4882
|
+
(_a = this.fxr) == null ? void 0 : _a.destroy();
|
|
4777
4883
|
this.fxr = null;
|
|
4778
4884
|
}
|
|
4779
4885
|
};
|
|
@@ -4912,11 +5018,12 @@ function grow2(a, n) {
|
|
|
4912
5018
|
}
|
|
4913
5019
|
var parsed = /* @__PURE__ */ new Map();
|
|
4914
5020
|
function pathData(d) {
|
|
5021
|
+
var _a, _b;
|
|
4915
5022
|
if (typeof d !== "string") return d;
|
|
4916
5023
|
let out = parsed.get(d);
|
|
4917
5024
|
if (out) return out;
|
|
4918
5025
|
out = [];
|
|
4919
|
-
const tokens = d.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)
|
|
5026
|
+
const tokens = (_a = d.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)) != null ? _a : [];
|
|
4920
5027
|
let cmd = -1;
|
|
4921
5028
|
for (let i = 0; i < tokens.length; ) {
|
|
4922
5029
|
const t = tokens[i];
|
|
@@ -4933,7 +5040,7 @@ function pathData(d) {
|
|
|
4933
5040
|
}
|
|
4934
5041
|
const n = ARGS[cmd];
|
|
4935
5042
|
out.push(cmd);
|
|
4936
|
-
for (let k = 0; k < n; k++) out.push(Number(tokens[i + k]
|
|
5043
|
+
for (let k = 0; k < n; k++) out.push(Number((_b = tokens[i + k]) != null ? _b : 0));
|
|
4937
5044
|
i += n;
|
|
4938
5045
|
if (cmd === PATH2.M) cmd = PATH2.L;
|
|
4939
5046
|
}
|
|
@@ -4945,9 +5052,10 @@ var flat = { subs: [], count: 0 };
|
|
|
4945
5052
|
var fm = null;
|
|
4946
5053
|
var fcur = null;
|
|
4947
5054
|
function fpush(px, py) {
|
|
5055
|
+
var _a;
|
|
4948
5056
|
let c = fcur;
|
|
4949
5057
|
if (!c) {
|
|
4950
|
-
c = flat.subs[flat.count]
|
|
5058
|
+
c = (_a = flat.subs[flat.count]) != null ? _a : null;
|
|
4951
5059
|
if (!c) flat.subs.push(c = { pts: new Float64Array(64), n: 0, closed: false });
|
|
4952
5060
|
c.n = 0;
|
|
4953
5061
|
c.closed = false;
|
|
@@ -5241,56 +5349,10 @@ function kitCanvas() {
|
|
|
5241
5349
|
|
|
5242
5350
|
// src/render/webgl.ts
|
|
5243
5351
|
var MAX_SLOTS = 8;
|
|
5244
|
-
var PRECISION =
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
precision mediump float;
|
|
5249
|
-
#endif
|
|
5250
|
-
`;
|
|
5251
|
-
var fragment = (slots) => `${PRECISION}
|
|
5252
|
-
uniform sampler2D uTex[${slots}];
|
|
5253
|
-
varying vec2 vUv;
|
|
5254
|
-
varying vec4 vColor;
|
|
5255
|
-
varying float vSlot;
|
|
5256
|
-
void main() {
|
|
5257
|
-
vec4 c;
|
|
5258
|
-
${Array.from({ length: slots }, (_, i) => i === slots - 1 ? `c = texture2D(uTex[${i}], vUv);` : `if (vSlot < ${i}.5) c = texture2D(uTex[${i}], vUv); else `).join("\n ")}
|
|
5259
|
-
gl_FragColor = c * vColor;
|
|
5260
|
-
}`;
|
|
5261
|
-
var VERTEX_PLAIN = `
|
|
5262
|
-
attribute vec2 aPos;
|
|
5263
|
-
attribute vec2 aUv;
|
|
5264
|
-
attribute vec4 aColor;
|
|
5265
|
-
attribute float aSlot;
|
|
5266
|
-
uniform vec2 uScale;
|
|
5267
|
-
varying vec2 vUv;
|
|
5268
|
-
varying vec4 vColor;
|
|
5269
|
-
varying float vSlot;
|
|
5270
|
-
void main() {
|
|
5271
|
-
vUv = aUv;
|
|
5272
|
-
vColor = aColor;
|
|
5273
|
-
vSlot = aSlot;
|
|
5274
|
-
gl_Position = vec4(aPos * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
5275
|
-
}`;
|
|
5276
|
-
var VERTEX_INSTANCED = `
|
|
5277
|
-
attribute vec4 aCorner;
|
|
5278
|
-
attribute vec4 aP01;
|
|
5279
|
-
attribute vec4 aP23;
|
|
5280
|
-
attribute vec4 aUvRect;
|
|
5281
|
-
attribute vec4 aColor;
|
|
5282
|
-
attribute float aSlot;
|
|
5283
|
-
uniform vec2 uScale;
|
|
5284
|
-
varying vec2 vUv;
|
|
5285
|
-
varying vec4 vColor;
|
|
5286
|
-
varying float vSlot;
|
|
5287
|
-
void main() {
|
|
5288
|
-
vec2 p = aP01.xy * aCorner.x + aP01.zw * aCorner.y + aP23.xy * aCorner.z + aP23.zw * aCorner.w;
|
|
5289
|
-
vUv = vec2(mix(aUvRect.x, aUvRect.z, aCorner.y + aCorner.z), mix(aUvRect.y, aUvRect.w, aCorner.z + aCorner.w));
|
|
5290
|
-
vColor = aColor;
|
|
5291
|
-
vSlot = aSlot;
|
|
5292
|
-
gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
|
|
5293
|
-
}`;
|
|
5352
|
+
var PRECISION = "\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n";
|
|
5353
|
+
var fragment = (slots) => "".concat(PRECISION, "\nuniform sampler2D uTex[").concat(slots, "];\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vec4 c;\n ").concat(Array.from({ length: slots }, (_, i) => i === slots - 1 ? "c = texture2D(uTex[".concat(i, "], vUv);") : "if (vSlot < ".concat(i, ".5) c = texture2D(uTex[").concat(i, "], vUv); else ")).join("\n "), "\n gl_FragColor = c * vColor;\n}");
|
|
5354
|
+
var VERTEX_PLAIN = "\nattribute vec2 aPos;\nattribute vec2 aUv;\nattribute vec4 aColor;\nattribute float aSlot;\nuniform vec2 uScale;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vUv = aUv;\n vColor = aColor;\n vSlot = aSlot;\n gl_Position = vec4(aPos * uScale + vec2(-1.0, 1.0), 0.0, 1.0);\n}";
|
|
5355
|
+
var VERTEX_INSTANCED = "\nattribute vec4 aCorner;\nattribute vec4 aP01;\nattribute vec4 aP23;\nattribute vec4 aUvRect;\nattribute vec4 aColor;\nattribute float aSlot;\nuniform vec2 uScale;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvarying float vSlot;\nvoid main() {\n vec2 p = aP01.xy * aCorner.x + aP01.zw * aCorner.y + aP23.xy * aCorner.z + aP23.zw * aCorner.w;\n vUv = vec2(mix(aUvRect.x, aUvRect.z, aCorner.y + aCorner.z), mix(aUvRect.y, aUvRect.w, aCorner.z + aCorner.w));\n vColor = aColor;\n vSlot = aSlot;\n gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);\n}";
|
|
5294
5356
|
var GL_ATTRIBUTES = {
|
|
5295
5357
|
alpha: true,
|
|
5296
5358
|
premultipliedAlpha: true,
|
|
@@ -5303,14 +5365,15 @@ var GL_ATTRIBUTES = {
|
|
|
5303
5365
|
var ATTRS_INSTANCED = ["aCorner", "aP01", "aP23", "aUvRect", "aColor", "aSlot"];
|
|
5304
5366
|
var ATTRS_PLAIN = ["aPos", "aUv", "aColor", "aSlot"];
|
|
5305
5367
|
function createWebGL(canvas, version, opts = {}) {
|
|
5306
|
-
|
|
5307
|
-
const
|
|
5368
|
+
var _a, _b;
|
|
5369
|
+
const attrs = __spreadProps(__spreadValues({}, GL_ATTRIBUTES), { failIfMajorPerformanceCaveat: opts.failIfMajorPerformanceCaveat !== false });
|
|
5370
|
+
const gl = version === 2 ? canvas.getContext("webgl2", attrs) : (_a = canvas.getContext("webgl", attrs)) != null ? _a : canvas.getContext("experimental-webgl", attrs);
|
|
5308
5371
|
if (!gl || gl.isContextLost()) return null;
|
|
5309
5372
|
try {
|
|
5310
5373
|
return new GLRenderer(canvas, gl, version, opts);
|
|
5311
5374
|
} catch (e) {
|
|
5312
5375
|
console.warn("[engine] WebGL setup failed:", e);
|
|
5313
|
-
gl.getExtension("WEBGL_lose_context")
|
|
5376
|
+
(_b = gl.getExtension("WEBGL_lose_context")) == null ? void 0 : _b.loseContext();
|
|
5314
5377
|
return null;
|
|
5315
5378
|
}
|
|
5316
5379
|
}
|
|
@@ -5561,6 +5624,7 @@ var GLRenderer = class extends Layered {
|
|
|
5561
5624
|
}
|
|
5562
5625
|
/** A program of fragment shader fs with the batch's vertex shader and attribute locations; throws the log. */
|
|
5563
5626
|
build(fs) {
|
|
5627
|
+
var _a;
|
|
5564
5628
|
const gl = this.gl;
|
|
5565
5629
|
const v = compile(gl, gl.VERTEX_SHADER, this.vsrc);
|
|
5566
5630
|
let f2;
|
|
@@ -5578,9 +5642,9 @@ var GLRenderer = class extends Layered {
|
|
|
5578
5642
|
gl.deleteShader(v);
|
|
5579
5643
|
gl.deleteShader(f2);
|
|
5580
5644
|
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) {
|
|
5581
|
-
const log = gl.getProgramInfoLog(p)
|
|
5645
|
+
const log = (_a = gl.getProgramInfoLog(p)) != null ? _a : "?";
|
|
5582
5646
|
gl.deleteProgram(p);
|
|
5583
|
-
throw new Error(
|
|
5647
|
+
throw new Error("link: ".concat(log));
|
|
5584
5648
|
}
|
|
5585
5649
|
return { p, uScale: gl.getUniformLocation(p, "uScale"), locs: /* @__PURE__ */ new Map() };
|
|
5586
5650
|
}
|
|
@@ -5853,14 +5917,15 @@ var GLRenderer = class extends Layered {
|
|
|
5853
5917
|
}
|
|
5854
5918
|
/** The layer framebuffer at depth d, made (or made again at the canvas's size) on demand; null if it can't be. */
|
|
5855
5919
|
layerAt(d) {
|
|
5920
|
+
var _a;
|
|
5856
5921
|
const w2 = this.canvas.width;
|
|
5857
5922
|
const h = this.canvas.height;
|
|
5858
|
-
let L = this.layers[d]
|
|
5923
|
+
let L = (_a = this.layers[d]) != null ? _a : null;
|
|
5859
5924
|
if (L && (L.w !== w2 || L.h !== h)) {
|
|
5860
5925
|
this.drop(L);
|
|
5861
5926
|
L = this.layers[d] = null;
|
|
5862
5927
|
}
|
|
5863
|
-
return L
|
|
5928
|
+
return L != null ? L : this.layers[d] = this.target(w2, h, 1, false);
|
|
5864
5929
|
}
|
|
5865
5930
|
pushLayer() {
|
|
5866
5931
|
if (this.lost) return false;
|
|
@@ -5881,11 +5946,13 @@ var GLRenderer = class extends Layered {
|
|
|
5881
5946
|
}
|
|
5882
5947
|
/** The filter runtime (made on first use), or null: none installed (no filter was ever made), or the context is lost. */
|
|
5883
5948
|
filters() {
|
|
5949
|
+
var _a;
|
|
5884
5950
|
if (this.lost || !fx.gl) return null;
|
|
5885
|
-
return this.fxr
|
|
5951
|
+
return (_a = this.fxr) != null ? _a : this.fxr = fx.gl(this);
|
|
5886
5952
|
}
|
|
5887
5953
|
composite(t, mask, alpha, filters) {
|
|
5888
|
-
|
|
5954
|
+
var _a;
|
|
5955
|
+
if (filters && ((_a = this.filters()) == null ? void 0 : _a.chain(t, alpha, filters))) return;
|
|
5889
5956
|
const gl = this.gl;
|
|
5890
5957
|
if (mask) gl.blendFunc(gl.ZERO, gl.SRC_ALPHA);
|
|
5891
5958
|
this.final(this.main, t, 1, alpha);
|
|
@@ -5950,6 +6017,7 @@ var GLRenderer = class extends Layered {
|
|
|
5950
6017
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, v);
|
|
5951
6018
|
}
|
|
5952
6019
|
flush() {
|
|
6020
|
+
var _a, _b;
|
|
5953
6021
|
const b = this.batch;
|
|
5954
6022
|
if (!b.quads || this.lost) return b.reset();
|
|
5955
6023
|
const gl = this.gl;
|
|
@@ -5960,7 +6028,7 @@ var GLRenderer = class extends Layered {
|
|
|
5960
6028
|
this.upload2(b);
|
|
5961
6029
|
for (let i = 0; i < b.bound; i++) {
|
|
5962
6030
|
const t = b.textures[i];
|
|
5963
|
-
this.bindTex(this.textures.get(t)
|
|
6031
|
+
this.bindTex((_b = (_a = this.textures.get(t)) != null ? _a : this.layerTex.get(t)) != null ? _b : null, i);
|
|
5964
6032
|
}
|
|
5965
6033
|
if (this.inst) this.inst.draw(6, b.quads);
|
|
5966
6034
|
else gl.drawElements(gl.TRIANGLES, b.quads * 6, gl.UNSIGNED_SHORT, 0);
|
|
@@ -5981,6 +6049,7 @@ var GLRenderer = class extends Layered {
|
|
|
5981
6049
|
this.restoredListeners.push(l);
|
|
5982
6050
|
}
|
|
5983
6051
|
destroy() {
|
|
6052
|
+
var _a, _b;
|
|
5984
6053
|
const gl = this.gl;
|
|
5985
6054
|
if (fx.live === this) fx.live = null;
|
|
5986
6055
|
this.canvas.removeEventListener("webglcontextlost", this.onContextLost);
|
|
@@ -5992,25 +6061,26 @@ var GLRenderer = class extends Layered {
|
|
|
5992
6061
|
gl.deleteTexture(L.gl);
|
|
5993
6062
|
gl.deleteFramebuffer(L.fb);
|
|
5994
6063
|
}
|
|
5995
|
-
this.fxr
|
|
6064
|
+
(_a = this.fxr) == null ? void 0 : _a.destroy();
|
|
5996
6065
|
this.fxr = null;
|
|
5997
6066
|
gl.deleteBuffer(this.dynamic);
|
|
5998
6067
|
gl.deleteBuffer(this.index);
|
|
5999
6068
|
if (this.staticBuf) gl.deleteBuffer(this.staticBuf);
|
|
6000
6069
|
if (this.vao && this.vaoApi) this.vaoApi.remove(this.vao);
|
|
6001
6070
|
gl.deleteProgram(this.main.p);
|
|
6002
|
-
gl.getExtension("WEBGL_lose_context")
|
|
6003
|
-
} catch {
|
|
6071
|
+
(_b = gl.getExtension("WEBGL_lose_context")) == null ? void 0 : _b.loseContext();
|
|
6072
|
+
} catch (e) {
|
|
6004
6073
|
}
|
|
6005
6074
|
this.textures.clear();
|
|
6006
6075
|
}
|
|
6007
6076
|
};
|
|
6008
6077
|
function compile(gl, type, src) {
|
|
6078
|
+
var _a;
|
|
6009
6079
|
const s = gl.createShader(type);
|
|
6010
6080
|
gl.shaderSource(s, src);
|
|
6011
6081
|
gl.compileShader(s);
|
|
6012
6082
|
if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) {
|
|
6013
|
-
const log = gl.getShaderInfoLog(s)
|
|
6083
|
+
const log = (_a = gl.getShaderInfoLog(s)) != null ? _a : "?";
|
|
6014
6084
|
gl.deleteShader(s);
|
|
6015
6085
|
throw new Error(log);
|
|
6016
6086
|
}
|
|
@@ -6043,8 +6113,9 @@ function createRenderer(canvas, opts = {}) {
|
|
|
6043
6113
|
throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D");
|
|
6044
6114
|
}
|
|
6045
6115
|
function freshCanvas(c) {
|
|
6116
|
+
var _a;
|
|
6046
6117
|
const n = c.cloneNode(false);
|
|
6047
|
-
c.parentNode
|
|
6118
|
+
(_a = c.parentNode) == null ? void 0 : _a.replaceChild(n, c);
|
|
6048
6119
|
return n;
|
|
6049
6120
|
}
|
|
6050
6121
|
function rendererFromUrl(search = typeof location !== "undefined" ? location.search : "") {
|
|
@@ -6066,8 +6137,9 @@ var NameTags = class {
|
|
|
6066
6137
|
/** The tag's height, drawing units. */
|
|
6067
6138
|
__publicField(this, "height");
|
|
6068
6139
|
__publicField(this, "font");
|
|
6069
|
-
|
|
6070
|
-
this.
|
|
6140
|
+
var _a, _b;
|
|
6141
|
+
this.height = (_a = o.tagHeight) != null ? _a : 34;
|
|
6142
|
+
this.font = (_b = o.tagFont) != null ? _b : "Nunito, sans-serif";
|
|
6071
6143
|
}
|
|
6072
6144
|
/** Forgets every tag (bake them again: the web font arrived). */
|
|
6073
6145
|
drop() {
|
|
@@ -6087,9 +6159,10 @@ var NameTags = class {
|
|
|
6087
6159
|
}
|
|
6088
6160
|
/** get's slow path, apart (its closure's context would be made on every get otherwise). */
|
|
6089
6161
|
bake(name, color, ratio) {
|
|
6162
|
+
var _a;
|
|
6090
6163
|
const tagH = this.height;
|
|
6091
|
-
const font =
|
|
6092
|
-
const measure = this.measure
|
|
6164
|
+
const font = "700 ".concat(Math.round(tagH * 0.65), "px ").concat(this.font);
|
|
6165
|
+
const measure = (_a = this.measure) != null ? _a : this.measure = document.createElement("canvas").getContext("2d");
|
|
6093
6166
|
measure.font = font;
|
|
6094
6167
|
const pad = Math.round(tagH * 0.4);
|
|
6095
6168
|
const w2 = Math.ceil(measure.measureText(name).width) + pad * 2;
|
|
@@ -6142,8 +6215,9 @@ var NameTags = class {
|
|
|
6142
6215
|
var bandOf = (def) => def.band === "3-5" || def.band === "9-12" ? def.band : "6-8";
|
|
6143
6216
|
|
|
6144
6217
|
// src/avatars.ts
|
|
6145
|
-
var bakeBucket = (px, coarse = false) => coarse ? Math.min(2
|
|
6218
|
+
var bakeBucket = (px, coarse = false) => coarse ? Math.min(__pow(2, Math.round(Math.log2(Math.max(px, 8)))), 256) : Math.min(__pow(2, Math.ceil(Math.log2(Math.max(px, 8)) * 2) / 2), 512);
|
|
6146
6219
|
function shapeBounds(shapes, m = null) {
|
|
6220
|
+
var _a, _b, _c, _d;
|
|
6147
6221
|
const b = { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
|
|
6148
6222
|
const add2 = (x, y, pad) => {
|
|
6149
6223
|
const px = m ? m[0] * x + m[2] * y + m[4] : x;
|
|
@@ -6155,7 +6229,7 @@ function shapeBounds(shapes, m = null) {
|
|
|
6155
6229
|
b.maxY = Math.max(b.maxY, py + pad * k);
|
|
6156
6230
|
};
|
|
6157
6231
|
for (const s of shapes) {
|
|
6158
|
-
const pad = "lw" in s && s.stroke ? (s.lw
|
|
6232
|
+
const pad = "lw" in s && s.stroke ? ((_a = s.lw) != null ? _a : 1) / 2 : 0;
|
|
6159
6233
|
switch (s.k) {
|
|
6160
6234
|
case "circle":
|
|
6161
6235
|
add2(s.x - s.r, s.y - s.r, pad), add2(s.x + s.r, s.y + s.r, pad), add2(s.x - s.r, s.y + s.r, pad), add2(s.x + s.r, s.y - s.r, pad);
|
|
@@ -6178,7 +6252,7 @@ function shapeBounds(shapes, m = null) {
|
|
|
6178
6252
|
for (let i = 0; i + 1 < s.pts.length; i += 2) add2(s.pts[i], s.pts[i + 1], pad);
|
|
6179
6253
|
break;
|
|
6180
6254
|
case "group": {
|
|
6181
|
-
const g = composeMat(mat(), m, s.x, s.y, s.rot
|
|
6255
|
+
const g = composeMat(mat(), m, s.x, s.y, (_b = s.rot) != null ? _b : 0, (_c = s.s) != null ? _c : 1, (_d = s.s) != null ? _d : 1);
|
|
6182
6256
|
const inner = shapeBounds(s.items, g);
|
|
6183
6257
|
if (Number.isFinite(inner.minX)) {
|
|
6184
6258
|
b.minX = Math.min(b.minX, inner.minX);
|
|
@@ -6232,7 +6306,8 @@ var AvatarPainter = class {
|
|
|
6232
6306
|
* don't show through each other.
|
|
6233
6307
|
*/
|
|
6234
6308
|
draw(r, tex, body, avatar, box, alpha, pixelScale) {
|
|
6235
|
-
|
|
6309
|
+
var _a;
|
|
6310
|
+
const def = typeof avatar === "string" ? (_a = avatarById(avatar)) != null ? _a : DEFAULT_AVATAR : avatar;
|
|
6236
6311
|
const shapes = avatarShapes(body, def, box);
|
|
6237
6312
|
if (!shapes.length) return false;
|
|
6238
6313
|
if (alpha <= 0) return true;
|
|
@@ -6244,12 +6319,12 @@ var AvatarPainter = class {
|
|
|
6244
6319
|
}
|
|
6245
6320
|
/** Paints a shape list under the transform m (a similarity: translate, rotate, uniform scale) with an alpha. */
|
|
6246
6321
|
paint(r, tex, shapes, m, alpha, pixelScale, depth = 0) {
|
|
6247
|
-
var _a;
|
|
6322
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
6248
6323
|
for (let si = 0; si < shapes.length; si++) {
|
|
6249
6324
|
const s = shapes[si];
|
|
6250
6325
|
if (s.k === "group") {
|
|
6251
|
-
const g = composeMat((_a = this.stack)[depth]
|
|
6252
|
-
const a2 = alpha * (s.alpha
|
|
6326
|
+
const g = composeMat((_b = (_a = this.stack)[depth]) != null ? _b : _a[depth] = mat(), m, s.x, s.y, (_c = s.rot) != null ? _c : 0, (_d = s.s) != null ? _d : 1, (_e = s.s) != null ? _e : 1);
|
|
6327
|
+
const a2 = alpha * ((_f = s.alpha) != null ? _f : 1);
|
|
6253
6328
|
if (this.bakeGroups && this.seen.has(s.items)) {
|
|
6254
6329
|
const k = len2(g[0], g[1]) * pixelScale;
|
|
6255
6330
|
const b = this.bake(s.items, k);
|
|
@@ -6269,18 +6344,18 @@ var AvatarPainter = class {
|
|
|
6269
6344
|
this.paint(r, tex, s.items, g, a2, pixelScale, depth + 1);
|
|
6270
6345
|
continue;
|
|
6271
6346
|
}
|
|
6272
|
-
const a = alpha * (s.alpha
|
|
6347
|
+
const a = alpha * ((_g = s.alpha) != null ? _g : 1);
|
|
6273
6348
|
const scale = m ? len2(m[0], m[1]) : 1;
|
|
6274
6349
|
const rot = m ? Math.atan2(m[1], m[0]) : 0;
|
|
6275
|
-
const lw = (s.lw
|
|
6276
|
-
const stroke = s.stroke && (s.lw
|
|
6350
|
+
const lw = ((_h = s.lw) != null ? _h : 1) * scale;
|
|
6351
|
+
const stroke = s.stroke && ((_i = s.lw) != null ? _i : 1) > 0 ? parseColor(s.stroke) : null;
|
|
6277
6352
|
const fill = s.fill && s.k !== "line" ? parseColor(s.fill) : null;
|
|
6278
6353
|
if (s.k === "circle" || s.k === "ellipse") {
|
|
6279
6354
|
const cx = m ? m[0] * s.x + m[2] * s.y + m[4] : s.x;
|
|
6280
6355
|
const cy = m ? m[1] * s.x + m[3] * s.y + m[5] : s.y;
|
|
6281
6356
|
const rx = (s.k === "circle" ? s.r : s.rx) * scale;
|
|
6282
6357
|
const ry = (s.k === "circle" ? s.r : s.ry) * scale;
|
|
6283
|
-
const er = (s.k === "ellipse" ? s.rot
|
|
6358
|
+
const er = (s.k === "ellipse" ? (_j = s.rot) != null ? _j : 0 : 0) + rot;
|
|
6284
6359
|
if (fill && stroke) {
|
|
6285
6360
|
r.ellipse(cx, cy, rx + lw / 2, ry + lw / 2, er, stroke[0], a * stroke[1]);
|
|
6286
6361
|
r.ellipse(cx, cy, Math.max(rx - lw / 2, 0), Math.max(ry - lw / 2, 0), er, fill[0], a * fill[1]);
|
|
@@ -6314,7 +6389,7 @@ var AvatarPainter = class {
|
|
|
6314
6389
|
r.stroke(pts2, n, lw, stroke[0], a * stroke[1], false);
|
|
6315
6390
|
continue;
|
|
6316
6391
|
}
|
|
6317
|
-
const flat2 = s.k === "path" ? flatten(s.d, m, scale * pixelScale) : roundRectFlat(s, composeMat(this.local, m, s.x, s.y, s.rot
|
|
6392
|
+
const flat2 = s.k === "path" ? flatten(s.d, m, scale * pixelScale) : roundRectFlat(s, composeMat(this.local, m, s.x, s.y, (_k = s.rot) != null ? _k : 0, 1, 1), pixelScale * scale);
|
|
6318
6393
|
for (let j = 0; j < flat2.count; j++) {
|
|
6319
6394
|
const sp = flat2.subs[j];
|
|
6320
6395
|
const n = sp.n;
|
|
@@ -6331,7 +6406,7 @@ var AvatarPainter = class {
|
|
|
6331
6406
|
bake(items, k) {
|
|
6332
6407
|
const kb = bakeBucket(k, this.coarse);
|
|
6333
6408
|
let byK = this.baked.get(items);
|
|
6334
|
-
const hit = byK
|
|
6409
|
+
const hit = byK == null ? void 0 : byK.get(kb);
|
|
6335
6410
|
if (hit && hit.gen === this.gen && this.atlas.valid(hit.frame)) return hit;
|
|
6336
6411
|
if (hit) this.live.delete(hit);
|
|
6337
6412
|
const b = shapeBounds(items);
|
|
@@ -6384,6 +6459,7 @@ function roundRectFlat(s, local, pxPerUnit) {
|
|
|
6384
6459
|
return flatten(rectPath, local, pxPerUnit);
|
|
6385
6460
|
}
|
|
6386
6461
|
function createAvatarRenderer(canvas, opts = {}) {
|
|
6462
|
+
var _a, _b;
|
|
6387
6463
|
let renderer = createRenderer(canvas, opts);
|
|
6388
6464
|
const atlas = new Atlas(Math.min(1024, renderer.maxTextureSize), 2);
|
|
6389
6465
|
atlas.onDrop = (s) => {
|
|
@@ -6408,10 +6484,10 @@ function createAvatarRenderer(canvas, opts = {}) {
|
|
|
6408
6484
|
let destroyed = false;
|
|
6409
6485
|
const dropTags = () => tags.drop();
|
|
6410
6486
|
const fonts = typeof document !== "undefined" ? document.fonts : void 0;
|
|
6411
|
-
void fonts
|
|
6487
|
+
void ((_a = fonts == null ? void 0 : fonts.ready) == null ? void 0 : _a.then(() => {
|
|
6412
6488
|
if (!destroyed) dropTags();
|
|
6413
|
-
});
|
|
6414
|
-
fonts
|
|
6489
|
+
}));
|
|
6490
|
+
(_b = fonts == null ? void 0 : fonts.addEventListener) == null ? void 0 : _b.call(fonts, "loadingdone", dropTags);
|
|
6415
6491
|
const toCanvas2D = () => {
|
|
6416
6492
|
const c = freshCanvas(renderer.canvas);
|
|
6417
6493
|
const r = createCanvas2D(c);
|
|
@@ -6434,13 +6510,14 @@ function createAvatarRenderer(canvas, opts = {}) {
|
|
|
6434
6510
|
return !renderer.lost;
|
|
6435
6511
|
};
|
|
6436
6512
|
const begin2 = () => {
|
|
6513
|
+
var _a2, _b2;
|
|
6437
6514
|
const c = renderer.canvas;
|
|
6438
6515
|
if (opts.units) {
|
|
6439
|
-
ratio = opts.pixelRatio
|
|
6516
|
+
ratio = (_a2 = opts.pixelRatio) != null ? _a2 : 1;
|
|
6440
6517
|
units.w = opts.units.width;
|
|
6441
6518
|
units.h = opts.units.height;
|
|
6442
6519
|
} else {
|
|
6443
|
-
ratio = opts.pixelRatio
|
|
6520
|
+
ratio = (_b2 = opts.pixelRatio) != null ? _b2 : Math.min(__fabiGlobalThis.devicePixelRatio || 1, 2);
|
|
6444
6521
|
units.w = c.clientWidth || c.width / ratio;
|
|
6445
6522
|
units.h = c.clientHeight || c.height / ratio;
|
|
6446
6523
|
}
|
|
@@ -6448,7 +6525,8 @@ function createAvatarRenderer(canvas, opts = {}) {
|
|
|
6448
6525
|
renderer.begin(0, 0, ratio);
|
|
6449
6526
|
};
|
|
6450
6527
|
const idOf = (p, i) => {
|
|
6451
|
-
|
|
6528
|
+
var _a2;
|
|
6529
|
+
if (p.key === void 0) return (_a2 = p.id) != null ? _a2 : i + 1;
|
|
6452
6530
|
let id = keyIds.get(p.key);
|
|
6453
6531
|
if (id === void 0) {
|
|
6454
6532
|
if (keyIds.size > 256) keyIds.clear();
|
|
@@ -6470,6 +6548,7 @@ function createAvatarRenderer(canvas, opts = {}) {
|
|
|
6470
6548
|
return renderer.canvas;
|
|
6471
6549
|
},
|
|
6472
6550
|
draw(players, box) {
|
|
6551
|
+
var _a2, _b2, _c, _d;
|
|
6473
6552
|
if (!ready()) return;
|
|
6474
6553
|
begin2();
|
|
6475
6554
|
for (let i = 0; i < players.length; i++) {
|
|
@@ -6477,10 +6556,10 @@ function createAvatarRenderer(canvas, opts = {}) {
|
|
|
6477
6556
|
if (!Array.isArray(p.body)) continue;
|
|
6478
6557
|
const id = idOf(p, i);
|
|
6479
6558
|
const body = amount < 1 || opts.interpolate !== false ? book.posed(id, p.body, amount, opts.interpolate !== false) : p.body;
|
|
6480
|
-
const def = avatarById(p.avatar
|
|
6481
|
-
const alpha = p.alpha
|
|
6559
|
+
const def = (_b2 = avatarById((_a2 = p.avatar) != null ? _a2 : "")) != null ? _b2 : DEFAULT_AVATAR;
|
|
6560
|
+
const alpha = (_c = p.alpha) != null ? _c : 1;
|
|
6482
6561
|
if (!painter.draw(renderer, tex, body, def, box, alpha, ratio) || !p.name) continue;
|
|
6483
|
-
tags.draw(renderer, tex, body, def, box, p.name, p.color
|
|
6562
|
+
tags.draw(renderer, tex, body, def, box, p.name, (_d = p.color) != null ? _d : "#6FA0E0", alpha, ratio, units.w, units.h);
|
|
6484
6563
|
}
|
|
6485
6564
|
renderer.end();
|
|
6486
6565
|
},
|
|
@@ -6494,15 +6573,17 @@ function createAvatarRenderer(canvas, opts = {}) {
|
|
|
6494
6573
|
keyIds.clear();
|
|
6495
6574
|
},
|
|
6496
6575
|
destroy() {
|
|
6576
|
+
var _a2;
|
|
6497
6577
|
destroyed = true;
|
|
6498
|
-
fonts
|
|
6578
|
+
(_a2 = fonts == null ? void 0 : fonts.removeEventListener) == null ? void 0 : _a2.call(fonts, "loadingdone", dropTags);
|
|
6499
6579
|
renderer.destroy();
|
|
6500
6580
|
}
|
|
6501
6581
|
};
|
|
6502
6582
|
}
|
|
6503
6583
|
var portraits = /* @__PURE__ */ new Map();
|
|
6504
|
-
function avatarPortrait(avatar, size, pixelRatio = Math.min(
|
|
6505
|
-
|
|
6584
|
+
function avatarPortrait(avatar, size, pixelRatio = Math.min(__fabiGlobalThis.devicePixelRatio || 1, 2)) {
|
|
6585
|
+
var _a;
|
|
6586
|
+
const key = "".concat(avatar, "|").concat(size, "|").concat(pixelRatio);
|
|
6506
6587
|
let c = portraits.get(key);
|
|
6507
6588
|
if (c) return c;
|
|
6508
6589
|
c = document.createElement("canvas");
|
|
@@ -6512,7 +6593,7 @@ function avatarPortrait(avatar, size, pixelRatio = Math.min(globalThis.devicePix
|
|
|
6512
6593
|
ctx.beginPath();
|
|
6513
6594
|
ctx.rect(0, 0, size, size);
|
|
6514
6595
|
ctx.clip();
|
|
6515
|
-
drawShapes(ctx, iconShapes(avatarById(avatar)
|
|
6596
|
+
drawShapes(ctx, iconShapes((_a = avatarById(avatar)) != null ? _a : DEFAULT_AVATAR, size));
|
|
6516
6597
|
if (portraits.size > 64) portraits.clear();
|
|
6517
6598
|
portraits.set(key, c);
|
|
6518
6599
|
return c;
|
|
@@ -6535,14 +6616,15 @@ function textureOf(r) {
|
|
|
6535
6616
|
var DEFAULT_FONT = 'Fredoka, Nunito, "Varela Round", system-ui, sans-serif';
|
|
6536
6617
|
var HALO = "rgba(10,16,30,0.75)";
|
|
6537
6618
|
function lookOf(st, effects) {
|
|
6538
|
-
|
|
6619
|
+
var _a, _b, _c, _d, _e, _f;
|
|
6620
|
+
const size = (_a = st.size) != null ? _a : 40;
|
|
6539
6621
|
const outline = st.outline ? st.outline === true ? HALO : st.outline : null;
|
|
6540
|
-
const ow = outline ? st.outlineWidth
|
|
6622
|
+
const ow = outline ? (_b = st.outlineWidth) != null ? _b : Math.max(size * 0.12, 3) : 0;
|
|
6541
6623
|
const shadow = st.shadow && effects ? st.shadow === true ? HALO : st.shadow : null;
|
|
6542
|
-
const blur2 = shadow ? st.shadowBlur
|
|
6543
|
-
return { size, font: st.font
|
|
6624
|
+
const blur2 = shadow ? (_c = st.shadowBlur) != null ? _c : size * 0.25 : 0;
|
|
6625
|
+
return { size, font: (_d = st.font) != null ? _d : DEFAULT_FONT, weight: (_e = st.weight) != null ? _e : 700, color: (_f = st.color) != null ? _f : "#FBEFE3", outline, ow, shadow, blur: blur2, pad: ow / 2 + blur2 * 1.2 + 2, th: size * 1.25 };
|
|
6544
6626
|
}
|
|
6545
|
-
var fontOf = (l, scale) =>
|
|
6627
|
+
var fontOf = (l, scale) => "".concat(l.weight, " ").concat(l.size * scale, "px ").concat(l.font);
|
|
6546
6628
|
function paintLine(ctx, text, l, scale, x, y) {
|
|
6547
6629
|
ctx.scale(scale, scale);
|
|
6548
6630
|
ctx.font = fontOf(l, 1);
|
|
@@ -6564,7 +6646,7 @@ function paintLine(ctx, text, l, scale, x, y) {
|
|
|
6564
6646
|
}
|
|
6565
6647
|
var measurer = null;
|
|
6566
6648
|
function measureLine(text, l, scale) {
|
|
6567
|
-
measurer
|
|
6649
|
+
measurer != null ? measurer : measurer = document.createElement("canvas").getContext("2d");
|
|
6568
6650
|
measurer.font = fontOf(l, scale);
|
|
6569
6651
|
return measurer.measureText(text).width / scale;
|
|
6570
6652
|
}
|
|
@@ -6584,7 +6666,7 @@ var Text = class extends Sprite {
|
|
|
6584
6666
|
__publicField(this, "capW", 0);
|
|
6585
6667
|
__publicField(this, "capH", 0);
|
|
6586
6668
|
this._text = text;
|
|
6587
|
-
const { x, y, rotation, scale, scaleX, scaleY, alpha, visible, tint: tint2, blend: blend2, z, anchor, hitRadius, clip, mask, filters,
|
|
6669
|
+
const _a = style, { x, y, rotation, scale, scaleX, scaleY, alpha, visible, tint: tint2, blend: blend2, z, anchor, hitRadius, clip, mask, filters } = _a, rest = __objRest(_a, ["x", "y", "rotation", "scale", "scaleX", "scaleY", "alpha", "visible", "tint", "blend", "z", "anchor", "hitRadius", "clip", "mask", "filters"]);
|
|
6588
6670
|
this._style = rest;
|
|
6589
6671
|
this.bake();
|
|
6590
6672
|
this.set({ x, y, rotation, scale, scaleX, scaleY, alpha, visible, tint: tint2, blend: blend2, z, hitRadius, clip, mask, filters });
|
|
@@ -6606,7 +6688,7 @@ var Text = class extends Sprite {
|
|
|
6606
6688
|
}
|
|
6607
6689
|
/** A new style (merged with the current one). */
|
|
6608
6690
|
set style(s) {
|
|
6609
|
-
this._style = {
|
|
6691
|
+
this._style = __spreadValues(__spreadValues({}, this._style), s);
|
|
6610
6692
|
this.dirty = true;
|
|
6611
6693
|
}
|
|
6612
6694
|
/** The bitmap font it is drawn with, or null (a baked text). Sets the anchor from align while it is automatic. */
|
|
@@ -6623,24 +6705,27 @@ var Text = class extends Sprite {
|
|
|
6623
6705
|
}
|
|
6624
6706
|
/** The content width, stage units: the text's own. */
|
|
6625
6707
|
get naturalWidth() {
|
|
6708
|
+
var _a;
|
|
6626
6709
|
const f2 = this.bitmap();
|
|
6627
6710
|
if (!f2) return super.naturalWidth;
|
|
6628
|
-
return f2.measure(this._text) * ((this._style.size
|
|
6711
|
+
return f2.measure(this._text) * (((_a = this._style.size) != null ? _a : f2.size) / f2.size);
|
|
6629
6712
|
}
|
|
6630
6713
|
/** The content height, stage units: the line's. */
|
|
6631
6714
|
get naturalHeight() {
|
|
6715
|
+
var _a;
|
|
6632
6716
|
const f2 = this.bitmap();
|
|
6633
6717
|
if (!f2) return super.naturalHeight;
|
|
6634
|
-
return f2.lineHeight * ((this._style.size
|
|
6718
|
+
return f2.lineHeight * (((_a = this._style.size) != null ? _a : f2.size) / f2.size);
|
|
6635
6719
|
}
|
|
6636
6720
|
frameNow() {
|
|
6637
6721
|
return this._style.bitmapFont ? null : this.bake();
|
|
6638
6722
|
}
|
|
6639
6723
|
/** Draws the text (the engine calls it): its baked frame, or its glyphs. */
|
|
6640
6724
|
draw(ctx, alpha, tint2) {
|
|
6725
|
+
var _a;
|
|
6641
6726
|
const f2 = this.bitmap();
|
|
6642
6727
|
if (!f2) return super.draw(ctx, alpha, tint2);
|
|
6643
|
-
const k = (this._style.size
|
|
6728
|
+
const k = ((_a = this._style.size) != null ? _a : f2.size) / f2.size;
|
|
6644
6729
|
const nw = f2.measure(this._text) * k;
|
|
6645
6730
|
const nh = f2.lineHeight * k;
|
|
6646
6731
|
const w2 = this.width;
|
|
@@ -6664,6 +6749,7 @@ var Text = class extends Sprite {
|
|
|
6664
6749
|
}
|
|
6665
6750
|
/** bake's slow path, apart: its closure's context would otherwise be made on every call, even the cheap ones. */
|
|
6666
6751
|
rebake() {
|
|
6752
|
+
var _a;
|
|
6667
6753
|
const k = this.kernel;
|
|
6668
6754
|
const scale = k.pixelScale;
|
|
6669
6755
|
const effects = k.effects;
|
|
@@ -6676,7 +6762,7 @@ var Text = class extends Sprite {
|
|
|
6676
6762
|
const tw = measureLine(this._text, l, scale);
|
|
6677
6763
|
const W = (tw + pad * 2) * scale;
|
|
6678
6764
|
const H = (th + pad * 2) * scale;
|
|
6679
|
-
const align = this._style.align
|
|
6765
|
+
const align = (_a = this._style.align) != null ? _a : "center";
|
|
6680
6766
|
const ox = align === "left" ? pad : align === "right" ? pad + tw : pad + tw / 2;
|
|
6681
6767
|
const draw = (ctx) => paintLine(ctx, this._text, l, scale, pad, pad + th / 2);
|
|
6682
6768
|
const old = this._frame;
|
|
@@ -6706,30 +6792,32 @@ var num = (v, d = 0) => {
|
|
|
6706
6792
|
return Number.isFinite(n) ? n : d;
|
|
6707
6793
|
};
|
|
6708
6794
|
function parseBMFont(src) {
|
|
6795
|
+
var _a, _b, _c, _d, _e, _f;
|
|
6709
6796
|
if (typeof src === "string" && /^\s*[{[]/.test(src)) src = JSON.parse(src);
|
|
6710
6797
|
const out = { size: 0, lineHeight: 0, base: 0, pages: [], chars: [], kernings: [] };
|
|
6711
6798
|
const rec = (kind, a) => {
|
|
6799
|
+
var _a2;
|
|
6712
6800
|
if (kind === "info") out.size = Math.abs(num(a.size));
|
|
6713
6801
|
else if (kind === "common") {
|
|
6714
6802
|
out.lineHeight = num(a.lineHeight);
|
|
6715
6803
|
out.base = num(a.base);
|
|
6716
|
-
} else if (kind === "page") out.pages[num(a.id)] = String(a.file
|
|
6804
|
+
} else if (kind === "page") out.pages[num(a.id)] = String((_a2 = a.file) != null ? _a2 : "");
|
|
6717
6805
|
else if (kind === "char") out.chars.push({ id: num(a.id), x: num(a.x), y: num(a.y), width: num(a.width), height: num(a.height), xoffset: num(a.xoffset), yoffset: num(a.yoffset), xadvance: num(a.xadvance), page: num(a.page) });
|
|
6718
6806
|
else out.kernings.push({ first: num(a.first), second: num(a.second), amount: num(a.amount) });
|
|
6719
6807
|
};
|
|
6720
6808
|
if (typeof src === "object") {
|
|
6721
6809
|
const j = src;
|
|
6722
|
-
rec("info", j.info
|
|
6723
|
-
rec("common", j.common
|
|
6724
|
-
for (const [id, file] of (j.pages
|
|
6725
|
-
for (const c of j.chars
|
|
6726
|
-
for (const k of j.kernings
|
|
6810
|
+
rec("info", (_a = j.info) != null ? _a : {});
|
|
6811
|
+
rec("common", (_b = j.common) != null ? _b : {});
|
|
6812
|
+
for (const [id, file] of ((_c = j.pages) != null ? _c : []).entries()) rec("page", { id, file });
|
|
6813
|
+
for (const c of (_d = j.chars) != null ? _d : []) rec("char", c);
|
|
6814
|
+
for (const k of (_e = j.kernings) != null ? _e : []) rec("kerning", k);
|
|
6727
6815
|
} else {
|
|
6728
6816
|
const tag = /(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm;
|
|
6729
6817
|
const attr = /(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;
|
|
6730
6818
|
for (let m = tag.exec(src); m; m = tag.exec(src)) {
|
|
6731
6819
|
const a = {};
|
|
6732
|
-
for (let t = attr.exec(m[2]); t; t = attr.exec(m[2])) a[t[1]] = t[2]
|
|
6820
|
+
for (let t = attr.exec(m[2]); t; t = attr.exec(m[2])) a[t[1]] = (_f = t[2]) != null ? _f : t[3];
|
|
6733
6821
|
rec(m[1], a);
|
|
6734
6822
|
}
|
|
6735
6823
|
}
|
|
@@ -6792,7 +6880,8 @@ var BitmapFont = class {
|
|
|
6792
6880
|
}
|
|
6793
6881
|
/** Kerning between two code points, font units (0 for most pairs). */
|
|
6794
6882
|
kerning(a, b) {
|
|
6795
|
-
|
|
6883
|
+
var _a;
|
|
6884
|
+
return this.kern.size ? (_a = this.kern.get(a * 1114112 + b)) != null ? _a : 0 : 0;
|
|
6796
6885
|
}
|
|
6797
6886
|
/** A string's width, font units. */
|
|
6798
6887
|
measure(text) {
|
|
@@ -6837,8 +6926,9 @@ function bmFont(data, pages) {
|
|
|
6837
6926
|
return f2;
|
|
6838
6927
|
}
|
|
6839
6928
|
function generatedFont(host, o) {
|
|
6840
|
-
|
|
6841
|
-
const
|
|
6929
|
+
var _a, _b;
|
|
6930
|
+
const style = __spreadValues({}, o);
|
|
6931
|
+
const size = (_a = o.size) != null ? _a : 40;
|
|
6842
6932
|
const baker = (code) => {
|
|
6843
6933
|
const ch = String.fromCodePoint(code);
|
|
6844
6934
|
const scale = host.pixelScale;
|
|
@@ -6849,7 +6939,7 @@ function generatedFont(host, o) {
|
|
|
6849
6939
|
};
|
|
6850
6940
|
const f2 = new BitmapFont(size, size * 1.25, size, baker, host);
|
|
6851
6941
|
f2.prepare();
|
|
6852
|
-
for (const ch of o.chars
|
|
6942
|
+
for (const ch of (_b = o.chars) != null ? _b : "0123456789") f2.glyph(ch.codePointAt(0));
|
|
6853
6943
|
return f2;
|
|
6854
6944
|
}
|
|
6855
6945
|
|
|
@@ -6864,21 +6954,22 @@ function wrists(body) {
|
|
|
6864
6954
|
const x = body[i * 3];
|
|
6865
6955
|
const y = body[i * 3 + 1];
|
|
6866
6956
|
const v = body[i * 3 + 2];
|
|
6867
|
-
if (x !== void 0 && y !== void 0 && Number.isFinite(x) && Number.isFinite(y) && (v
|
|
6957
|
+
if (x !== void 0 && y !== void 0 && Number.isFinite(x) && Number.isFinite(y) && (v != null ? v : 0) >= VISIBLE3) out.push({ side, x, y });
|
|
6868
6958
|
}
|
|
6869
6959
|
return out;
|
|
6870
6960
|
}
|
|
6871
6961
|
var playerColor = (player) => PLAYER_COLORS[((player - 1) % PLAYER_COLORS.length + PLAYER_COLORS.length) % PLAYER_COLORS.length];
|
|
6872
6962
|
var SIDES2 = ["left", "right"];
|
|
6873
6963
|
function handsOf(frames, toScreen2, width, height, bodyOf = () => null, aim = {}) {
|
|
6964
|
+
var _a, _b;
|
|
6874
6965
|
const out = [];
|
|
6875
6966
|
for (const f2 of frames) {
|
|
6876
|
-
const body = bodyOf(f2)
|
|
6967
|
+
const body = (_a = bodyOf(f2)) != null ? _a : f2.body;
|
|
6877
6968
|
if (!Array.isArray(body)) continue;
|
|
6878
6969
|
if (aim.orientation === "portrait") {
|
|
6879
6970
|
for (const side of SIDES2) {
|
|
6880
6971
|
let p = aimPoint(body, side, { orientation: "portrait" });
|
|
6881
|
-
if (aim.hold) p = aim.hold.at(AimHold.key(f2.id, side), p, aim.t
|
|
6972
|
+
if (aim.hold) p = aim.hold.at(AimHold.key(f2.id, side), p, (_b = aim.t) != null ? _b : 0);
|
|
6882
6973
|
if (p) out.push({ player: f2.id, side, x: p.x * width, y: p.y * height, color: playerColor(f2.id) });
|
|
6883
6974
|
}
|
|
6884
6975
|
continue;
|
|
@@ -6914,6 +7005,7 @@ function touching(node, hands, player, pad = 0) {
|
|
|
6914
7005
|
|
|
6915
7006
|
// src/shapes.ts
|
|
6916
7007
|
function shapeSize(s) {
|
|
7008
|
+
var _a;
|
|
6917
7009
|
switch (s.type) {
|
|
6918
7010
|
case "circle":
|
|
6919
7011
|
case "ring":
|
|
@@ -6924,17 +7016,18 @@ function shapeSize(s) {
|
|
|
6924
7016
|
case "roundRect":
|
|
6925
7017
|
return [s.w, s.h];
|
|
6926
7018
|
case "line":
|
|
6927
|
-
return [s.length, s.lw
|
|
7019
|
+
return [s.length, (_a = s.lw) != null ? _a : 4];
|
|
6928
7020
|
case "path":
|
|
6929
7021
|
return s.r ? [s.r * 2, s.r * 2] : [s.size, s.size];
|
|
6930
7022
|
}
|
|
6931
7023
|
}
|
|
6932
7024
|
function shapeMargin(s) {
|
|
6933
|
-
|
|
6934
|
-
const
|
|
7025
|
+
var _a, _b, _c;
|
|
7026
|
+
const out = s.type === "line" ? 0 : s.stroke ? ((_a = s.lw) != null ? _a : 2) / 2 : 0;
|
|
7027
|
+
const sh = s.shadow ? s.shadow.blur * 1.5 + Math.max(Math.abs((_b = s.shadow.x) != null ? _b : 0), Math.abs((_c = s.shadow.y) != null ? _c : 0)) : 0;
|
|
6935
7028
|
return Math.ceil(out + sh + 1);
|
|
6936
7029
|
}
|
|
6937
|
-
var forTier = (s, effects) => effects || !s.shadow ? s : {
|
|
7030
|
+
var forTier = (s, effects) => effects || !s.shadow ? s : __spreadProps(__spreadValues({}, s), { shadow: void 0 });
|
|
6938
7031
|
function bakeShape(atlas, s, scale) {
|
|
6939
7032
|
const m = shapeMargin(s);
|
|
6940
7033
|
const nine = s.type === "roundRect";
|
|
@@ -6957,6 +7050,7 @@ function bakeShape(atlas, s, scale) {
|
|
|
6957
7050
|
return { frame, slice: nine ? Math.ceil((s.r + m) * scale) : 0, w: nine ? s.w : w2, h: nine ? s.h : h };
|
|
6958
7051
|
}
|
|
6959
7052
|
function paint(ctx, s, w2, h) {
|
|
7053
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
6960
7054
|
ctx.lineJoin = "round";
|
|
6961
7055
|
ctx.lineCap = "round";
|
|
6962
7056
|
const path = new Path2D();
|
|
@@ -6972,8 +7066,8 @@ function paint(ctx, s, w2, h) {
|
|
|
6972
7066
|
path.roundRect(-w2 / 2, -h / 2, w2, h, Math.min(s.r, w2 / 2, h / 2));
|
|
6973
7067
|
break;
|
|
6974
7068
|
case "star": {
|
|
6975
|
-
const n = s.points
|
|
6976
|
-
const inner = s.r * (s.inner
|
|
7069
|
+
const n = (_a = s.points) != null ? _a : 5;
|
|
7070
|
+
const inner = s.r * ((_b = s.inner) != null ? _b : 0.5);
|
|
6977
7071
|
for (let i = 0; i < n * 2; i++) {
|
|
6978
7072
|
const r = i % 2 ? inner : s.r;
|
|
6979
7073
|
const a = -Math.PI / 2 + i * Math.PI / n;
|
|
@@ -6996,12 +7090,13 @@ function paint(ctx, s, w2, h) {
|
|
|
6996
7090
|
}
|
|
6997
7091
|
const sh = s.shadow;
|
|
6998
7092
|
const shadow = () => {
|
|
7093
|
+
var _a2, _b2;
|
|
6999
7094
|
if (!sh) return;
|
|
7000
7095
|
const t = ctx.getTransform();
|
|
7001
7096
|
ctx.shadowColor = sh.color;
|
|
7002
7097
|
ctx.shadowBlur = sh.blur * t.a;
|
|
7003
|
-
ctx.shadowOffsetX = (sh.x
|
|
7004
|
-
ctx.shadowOffsetY = (sh.y
|
|
7098
|
+
ctx.shadowOffsetX = ((_a2 = sh.x) != null ? _a2 : 0) * t.a;
|
|
7099
|
+
ctx.shadowOffsetY = ((_b2 = sh.y) != null ? _b2 : 0) * t.a;
|
|
7005
7100
|
};
|
|
7006
7101
|
const noShadow = () => {
|
|
7007
7102
|
ctx.shadowColor = "transparent";
|
|
@@ -7009,7 +7104,7 @@ function paint(ctx, s, w2, h) {
|
|
|
7009
7104
|
};
|
|
7010
7105
|
if (s.type === "line") {
|
|
7011
7106
|
shadow();
|
|
7012
|
-
ctx.strokeStyle = s.stroke
|
|
7107
|
+
ctx.strokeStyle = (_d = (_c = s.stroke) != null ? _c : s.fill) != null ? _d : "#fff";
|
|
7013
7108
|
ctx.lineWidth = h;
|
|
7014
7109
|
ctx.stroke(path);
|
|
7015
7110
|
return;
|
|
@@ -7018,7 +7113,7 @@ function paint(ctx, s, w2, h) {
|
|
|
7018
7113
|
if (s.outlineBelow && s.fill && s.stroke && !isRing) {
|
|
7019
7114
|
shadow();
|
|
7020
7115
|
ctx.strokeStyle = s.stroke;
|
|
7021
|
-
ctx.lineWidth = s.lw
|
|
7116
|
+
ctx.lineWidth = (_e = s.lw) != null ? _e : 2;
|
|
7022
7117
|
ctx.stroke(path);
|
|
7023
7118
|
noShadow();
|
|
7024
7119
|
ctx.fillStyle = s.fill;
|
|
@@ -7037,8 +7132,8 @@ function paint(ctx, s, w2, h) {
|
|
|
7037
7132
|
ctx.fillStyle = s.fill;
|
|
7038
7133
|
ctx.fill(path);
|
|
7039
7134
|
}
|
|
7040
|
-
ctx.strokeStyle = s.stroke
|
|
7041
|
-
ctx.lineWidth = s.lw
|
|
7135
|
+
ctx.strokeStyle = (_f = s.stroke) != null ? _f : "#fff";
|
|
7136
|
+
ctx.lineWidth = (_g = s.lw) != null ? _g : 2;
|
|
7042
7137
|
ctx.stroke(path);
|
|
7043
7138
|
noShadow();
|
|
7044
7139
|
}
|
|
@@ -7057,31 +7152,37 @@ var Sound = class {
|
|
|
7057
7152
|
/** Master volume, 0–1. */
|
|
7058
7153
|
__publicField(this, "volume", 1);
|
|
7059
7154
|
if (typeof addEventListener === "function") {
|
|
7060
|
-
const unlock = () =>
|
|
7155
|
+
const unlock = () => {
|
|
7156
|
+
var _a;
|
|
7157
|
+
return void ((_a = this.context()) == null ? void 0 : _a.resume().catch(() => void 0));
|
|
7158
|
+
};
|
|
7061
7159
|
for (const e of ["pointerdown", "keydown", "touchstart"]) addEventListener(e, unlock, { once: true, capture: true });
|
|
7062
7160
|
}
|
|
7063
7161
|
}
|
|
7064
7162
|
/** The audio context, made on first use (null without Web Audio). */
|
|
7065
7163
|
context() {
|
|
7164
|
+
var _a;
|
|
7066
7165
|
if (this.ctx) return this.ctx;
|
|
7067
|
-
const AC =
|
|
7166
|
+
const AC = (_a = __fabiGlobalThis.AudioContext) != null ? _a : __fabiGlobalThis.webkitAudioContext;
|
|
7068
7167
|
if (!AC) return null;
|
|
7069
7168
|
try {
|
|
7070
7169
|
this.ctx = new AC();
|
|
7071
7170
|
this.master = this.ctx.createGain();
|
|
7072
7171
|
this.master.connect(this.ctx.destination);
|
|
7073
7172
|
if (this.held) void this.ctx.suspend();
|
|
7074
|
-
} catch {
|
|
7173
|
+
} catch (e) {
|
|
7075
7174
|
return null;
|
|
7076
7175
|
}
|
|
7077
7176
|
return this.ctx;
|
|
7078
7177
|
}
|
|
7079
7178
|
/** Decodes a sound file (mp3, aac, ogg, wav) under a name. */
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7179
|
+
load(name, url) {
|
|
7180
|
+
return __async(this, null, function* () {
|
|
7181
|
+
const ctx = this.context();
|
|
7182
|
+
if (!ctx) return;
|
|
7183
|
+
const data = yield (yield fetch(url)).arrayBuffer();
|
|
7184
|
+
this.buffers.set(name, yield ctx.decodeAudioData(data));
|
|
7185
|
+
});
|
|
7085
7186
|
}
|
|
7086
7187
|
/** Whether a sound of that name is loaded. */
|
|
7087
7188
|
has(name) {
|
|
@@ -7089,41 +7190,43 @@ var Sound = class {
|
|
|
7089
7190
|
}
|
|
7090
7191
|
/** Plays a loaded sound; returns stop(). */
|
|
7091
7192
|
play(name, o = {}) {
|
|
7193
|
+
var _a, _b, _c;
|
|
7092
7194
|
const ctx = this.context();
|
|
7093
7195
|
const buf = this.buffers.get(name);
|
|
7094
7196
|
if (!ctx || !buf || !this.audible) return () => {
|
|
7095
7197
|
};
|
|
7096
7198
|
const src = ctx.createBufferSource();
|
|
7097
7199
|
src.buffer = buf;
|
|
7098
|
-
src.loop = o.loop
|
|
7099
|
-
src.playbackRate.value = o.rate
|
|
7200
|
+
src.loop = (_a = o.loop) != null ? _a : false;
|
|
7201
|
+
src.playbackRate.value = (_b = o.rate) != null ? _b : 1;
|
|
7100
7202
|
const gain = ctx.createGain();
|
|
7101
|
-
gain.gain.value = (o.volume
|
|
7203
|
+
gain.gain.value = ((_c = o.volume) != null ? _c : 1) * this.volume;
|
|
7102
7204
|
src.connect(gain).connect(this.master);
|
|
7103
7205
|
src.start();
|
|
7104
7206
|
return () => {
|
|
7105
7207
|
try {
|
|
7106
7208
|
src.stop();
|
|
7107
|
-
} catch {
|
|
7209
|
+
} catch (e) {
|
|
7108
7210
|
}
|
|
7109
7211
|
};
|
|
7110
7212
|
}
|
|
7111
7213
|
/** A short tone (a "ding"): frequency Hz, seconds, fading out. */
|
|
7112
7214
|
tone(freq, seconds = 0.25, o = {}) {
|
|
7215
|
+
var _a, _b;
|
|
7113
7216
|
const ctx = this.context();
|
|
7114
7217
|
if (!ctx || !this.audible) return;
|
|
7115
7218
|
try {
|
|
7116
7219
|
const osc = ctx.createOscillator();
|
|
7117
7220
|
const gain = ctx.createGain();
|
|
7118
|
-
osc.type = o.type
|
|
7221
|
+
osc.type = (_a = o.type) != null ? _a : "sine";
|
|
7119
7222
|
osc.frequency.setValueAtTime(freq, ctx.currentTime);
|
|
7120
7223
|
if (o.to) osc.frequency.exponentialRampToValueAtTime(o.to, ctx.currentTime + seconds);
|
|
7121
|
-
gain.gain.setValueAtTime((o.volume
|
|
7224
|
+
gain.gain.setValueAtTime(((_b = o.volume) != null ? _b : 0.12) * this.volume, ctx.currentTime);
|
|
7122
7225
|
gain.gain.exponentialRampToValueAtTime(1e-3, ctx.currentTime + seconds);
|
|
7123
7226
|
osc.connect(gain).connect(this.master);
|
|
7124
7227
|
osc.start();
|
|
7125
7228
|
osc.stop(ctx.currentTime + seconds);
|
|
7126
|
-
} catch {
|
|
7229
|
+
} catch (e) {
|
|
7127
7230
|
}
|
|
7128
7231
|
}
|
|
7129
7232
|
get audible() {
|
|
@@ -7131,17 +7234,20 @@ var Sound = class {
|
|
|
7131
7234
|
}
|
|
7132
7235
|
/** Pauses and breaks: everything stops until release(). */
|
|
7133
7236
|
hold() {
|
|
7237
|
+
var _a;
|
|
7134
7238
|
this.held = true;
|
|
7135
|
-
void this.ctx
|
|
7239
|
+
void ((_a = this.ctx) == null ? void 0 : _a.suspend().catch(() => void 0));
|
|
7136
7240
|
}
|
|
7137
7241
|
/** Sound again after hold(). */
|
|
7138
7242
|
release() {
|
|
7243
|
+
var _a;
|
|
7139
7244
|
this.held = false;
|
|
7140
|
-
void this.ctx
|
|
7245
|
+
void ((_a = this.ctx) == null ? void 0 : _a.resume().catch(() => void 0));
|
|
7141
7246
|
}
|
|
7142
7247
|
/** Closes the audio context. */
|
|
7143
7248
|
destroy() {
|
|
7144
|
-
|
|
7249
|
+
var _a;
|
|
7250
|
+
void ((_a = this.ctx) == null ? void 0 : _a.close().catch(() => void 0));
|
|
7145
7251
|
this.ctx = null;
|
|
7146
7252
|
}
|
|
7147
7253
|
};
|
|
@@ -7155,7 +7261,7 @@ var TABLE = {
|
|
|
7155
7261
|
var TIERS = ["high", "medium", "low"];
|
|
7156
7262
|
function tier(name) {
|
|
7157
7263
|
const t = TABLE[name];
|
|
7158
|
-
return { name,
|
|
7264
|
+
return __spreadProps(__spreadValues({ name }, t), { scale: (n) => n <= 0 ? 0 : Math.max(1, Math.round(n * t.particles)) });
|
|
7159
7265
|
}
|
|
7160
7266
|
var lower = (name) => TIERS[Math.min(TIERS.indexOf(name) + 1, TIERS.length - 1)];
|
|
7161
7267
|
var quantile = (xs, q) => {
|
|
@@ -7191,21 +7297,22 @@ function shouldDrop(intervals, frame) {
|
|
|
7191
7297
|
}
|
|
7192
7298
|
var ENGINE_VERSION = "0.1.1";
|
|
7193
7299
|
var DAYS_30 = 30 * 24 * 3600 * 1e3;
|
|
7194
|
-
var tierCacheKey = (kind, gpu, screen2) =>
|
|
7195
|
-
var legacyTierCacheKey = (kind, gpu, screen2) =>
|
|
7300
|
+
var tierCacheKey = (kind, gpu, screen2) => "fabi-play.engine-tier:".concat(ENGINE_VERSION, ":").concat(kind, ":").concat(gpu, ":").concat(screen2);
|
|
7301
|
+
var legacyTierCacheKey = (kind, gpu, screen2) => "fablee-engine-tier:".concat(ENGINE_VERSION, ":").concat(kind, ":").concat(gpu, ":").concat(screen2);
|
|
7196
7302
|
function readTier(store, key, now3 = Date.now()) {
|
|
7303
|
+
var _a;
|
|
7197
7304
|
try {
|
|
7198
|
-
const v = JSON.parse(store
|
|
7305
|
+
const v = JSON.parse((_a = store == null ? void 0 : store.getItem(key)) != null ? _a : "null");
|
|
7199
7306
|
if (v && TIERS.includes(v.tier) && typeof v.at === "number" && now3 - v.at < DAYS_30)
|
|
7200
7307
|
return typeof v.refresh === "number" && v.refresh > 0 ? { name: v.tier, refresh: v.refresh } : { name: v.tier };
|
|
7201
|
-
} catch {
|
|
7308
|
+
} catch (e) {
|
|
7202
7309
|
}
|
|
7203
7310
|
return null;
|
|
7204
7311
|
}
|
|
7205
7312
|
function writeTier(store, key, name, refresh, now3 = Date.now()) {
|
|
7206
7313
|
try {
|
|
7207
|
-
store
|
|
7208
|
-
} catch {
|
|
7314
|
+
store == null ? void 0 : store.setItem(key, JSON.stringify(refresh !== void 0 && Number.isFinite(refresh) ? { tier: name, at: now3, refresh } : { tier: name, at: now3 }));
|
|
7315
|
+
} catch (e) {
|
|
7209
7316
|
}
|
|
7210
7317
|
}
|
|
7211
7318
|
function tierFromUrl(search = typeof location !== "undefined" ? location.search : "") {
|
|
@@ -7213,11 +7320,11 @@ function tierFromUrl(search = typeof location !== "undefined" ? location.search
|
|
|
7213
7320
|
return TIERS.includes(v) ? v : void 0;
|
|
7214
7321
|
}
|
|
7215
7322
|
function hintedTier(kind, hint) {
|
|
7216
|
-
const t = hint
|
|
7323
|
+
const t = hint == null ? void 0 : hint.tier;
|
|
7217
7324
|
if (!TIERS.includes(t)) return void 0;
|
|
7218
7325
|
return kind === "canvas2d" && t === "high" ? "medium" : t;
|
|
7219
7326
|
}
|
|
7220
|
-
var hintedRefresh = (hint) => typeof hint
|
|
7327
|
+
var hintedRefresh = (hint) => typeof (hint == null ? void 0 : hint.hz) === "number" && hint.hz >= 20 && hint.hz <= 240 ? refreshInterval([1e3 / hint.hz], 0.5) : NaN;
|
|
7221
7328
|
var lowerOf = (a, b) => TIERS.indexOf(a) >= TIERS.indexOf(b) ? a : b;
|
|
7222
7329
|
function startTier(forced, hinted, cached) {
|
|
7223
7330
|
if (forced) return { name: forced, from: "forced" };
|
|
@@ -7249,9 +7356,10 @@ var Timeline = class {
|
|
|
7249
7356
|
__publicField(this, "yoyo");
|
|
7250
7357
|
/** Called when the last play ends. */
|
|
7251
7358
|
__publicField(this, "onComplete");
|
|
7252
|
-
|
|
7359
|
+
var _a, _b;
|
|
7360
|
+
this.repeat = Math.floor((_a = o.repeat) != null ? _a : 0);
|
|
7253
7361
|
this.yoyo = !!o.yoyo;
|
|
7254
|
-
this.delayLeft = o.delay
|
|
7362
|
+
this.delayLeft = (_b = o.delay) != null ? _b : 0;
|
|
7255
7363
|
this._paused = !!o.paused;
|
|
7256
7364
|
this.onComplete = o.onComplete;
|
|
7257
7365
|
this.promise = new Promise((r) => this.resolve = r);
|
|
@@ -7277,7 +7385,7 @@ var Timeline = class {
|
|
|
7277
7385
|
if (pos2 === void 0) return this.end;
|
|
7278
7386
|
if (typeof pos2 === "number") return Math.max(pos2, 0);
|
|
7279
7387
|
const m = POS.exec(pos2);
|
|
7280
|
-
if (!m) throw new Error(
|
|
7388
|
+
if (!m) throw new Error('[engine] timeline: bad position "'.concat(pos2, '"'));
|
|
7281
7389
|
const [, base, sign, n] = m;
|
|
7282
7390
|
const off = n ? (sign === "-" ? -1 : 1) * Number(n) : 0;
|
|
7283
7391
|
let t = this.end;
|
|
@@ -7304,9 +7412,10 @@ var Timeline = class {
|
|
|
7304
7412
|
* engine.timeline().to(a, { x: 600 }, 0.5).to(b, { alpha: 0 }, 0.3, { at: '<' })
|
|
7305
7413
|
*/
|
|
7306
7414
|
to(target, to, seconds, ease = "quadOut") {
|
|
7415
|
+
var _a, _b;
|
|
7307
7416
|
const o = typeof ease === "object" ? ease : { ease };
|
|
7308
|
-
const e = typeof o.ease === "function" ? o.ease : EASE[o.ease
|
|
7309
|
-
return this.add({ target, to, from: null, fn: null, start: this.at(o.at) + (o.delay
|
|
7417
|
+
const e = typeof o.ease === "function" ? o.ease : EASE[(_a = o.ease) != null ? _a : "quadOut"];
|
|
7418
|
+
return this.add({ target, to, from: null, fn: null, start: this.at(o.at) + ((_b = o.delay) != null ? _b : 0), dur: Math.max(seconds, 0), ease: e, onUpdate: o.onUpdate, p: -1 });
|
|
7310
7419
|
}
|
|
7311
7420
|
/** Sets fields at once, when the playhead gets there. */
|
|
7312
7421
|
set(target, values, at) {
|
|
@@ -7387,9 +7496,10 @@ var Timeline = class {
|
|
|
7387
7496
|
if (e >= total) this.complete();
|
|
7388
7497
|
}
|
|
7389
7498
|
complete() {
|
|
7499
|
+
var _a;
|
|
7390
7500
|
if (this.done) return;
|
|
7391
7501
|
this.done = true;
|
|
7392
|
-
this.onComplete
|
|
7502
|
+
(_a = this.onComplete) == null ? void 0 : _a.call(this);
|
|
7393
7503
|
this.resolve();
|
|
7394
7504
|
}
|
|
7395
7505
|
/** Writes every step at playhead t: forwards in start order, backwards in reverse (see the file's comment). */
|
|
@@ -7409,6 +7519,7 @@ var Timeline = class {
|
|
|
7409
7519
|
this.last = t;
|
|
7410
7520
|
}
|
|
7411
7521
|
apply(st, t) {
|
|
7522
|
+
var _a, _b;
|
|
7412
7523
|
const p = st.dur > 0 ? Math.min(Math.max((t - st.start) / st.dur, 0), 1) : t > st.start || t === st.start && !this.rewinding ? 1 : 0;
|
|
7413
7524
|
if (p === st.p) return;
|
|
7414
7525
|
st.p = p;
|
|
@@ -7421,11 +7532,11 @@ var Timeline = class {
|
|
|
7421
7532
|
const to = st.to;
|
|
7422
7533
|
if (!st.from) {
|
|
7423
7534
|
st.from = {};
|
|
7424
|
-
for (const k2 in to) st.from[k2] = Number(target[k2]
|
|
7535
|
+
for (const k2 in to) st.from[k2] = Number((_a = target[k2]) != null ? _a : 0);
|
|
7425
7536
|
}
|
|
7426
7537
|
const k = st.ease(p);
|
|
7427
7538
|
for (const key in to) target[key] = st.from[key] + (to[key] - st.from[key]) * k;
|
|
7428
|
-
st.onUpdate
|
|
7539
|
+
(_b = st.onUpdate) == null ? void 0 : _b.call(st, k);
|
|
7429
7540
|
}
|
|
7430
7541
|
};
|
|
7431
7542
|
|
|
@@ -7443,15 +7554,17 @@ var Tweens = class {
|
|
|
7443
7554
|
}
|
|
7444
7555
|
/** Eases target's numeric fields to `to` over `seconds`. */
|
|
7445
7556
|
tween(target, to, seconds, ease = "quadOut") {
|
|
7557
|
+
var _a;
|
|
7446
7558
|
if (target.destroyed || target._free) warnUse(target, "a tween started on it");
|
|
7447
7559
|
const o = typeof ease === "object" ? ease : { ease };
|
|
7448
|
-
const e = typeof o.ease === "function" ? o.ease : EASE[o.ease
|
|
7560
|
+
const e = typeof o.ease === "function" ? o.ease : EASE[(_a = o.ease) != null ? _a : "quadOut"];
|
|
7449
7561
|
let run;
|
|
7450
7562
|
const p = new Promise((resolve2) => {
|
|
7563
|
+
var _a2;
|
|
7451
7564
|
const keys = Object.keys(to);
|
|
7452
7565
|
const end = new Float64Array(keys.length);
|
|
7453
7566
|
keys.forEach((k, i) => end[i] = Number(to[k]));
|
|
7454
|
-
run = { target, keys, to: end, from: new Float64Array(keys.length), started: false, duration: Math.max(seconds, 0), time: 0, delay: o.delay
|
|
7567
|
+
run = { target, keys, to: end, from: new Float64Array(keys.length), started: false, duration: Math.max(seconds, 0), time: 0, delay: (_a2 = o.delay) != null ? _a2 : 0, ease: e, onUpdate: o.onUpdate, done: resolve2, dead: false };
|
|
7455
7568
|
});
|
|
7456
7569
|
this.list.push(run);
|
|
7457
7570
|
return Object.assign(p, { stop: () => this.finish(run) });
|
|
@@ -7488,6 +7601,7 @@ var Tweens = class {
|
|
|
7488
7601
|
if (j !== l.length) l.length = j;
|
|
7489
7602
|
}
|
|
7490
7603
|
step(r, dt) {
|
|
7604
|
+
var _a, _b;
|
|
7491
7605
|
if (r.target.destroyed) return this.finish(r);
|
|
7492
7606
|
let step = dt;
|
|
7493
7607
|
if (r.delay > 0) {
|
|
@@ -7498,13 +7612,13 @@ var Tweens = class {
|
|
|
7498
7612
|
const keys = r.keys;
|
|
7499
7613
|
if (!r.started) {
|
|
7500
7614
|
r.started = true;
|
|
7501
|
-
for (let i = 0; i < keys.length; i++) r.from[i] = Number(r.target[keys[i]]
|
|
7615
|
+
for (let i = 0; i < keys.length; i++) r.from[i] = Number((_a = r.target[keys[i]]) != null ? _a : 0);
|
|
7502
7616
|
}
|
|
7503
7617
|
r.time += step;
|
|
7504
7618
|
const t = r.duration > 0 ? Math.min(r.time / r.duration, 1) : 1;
|
|
7505
7619
|
const k = r.ease(t);
|
|
7506
7620
|
for (let i = 0; i < keys.length; i++) r.target[keys[i]] = r.from[i] + (r.to[i] - r.from[i]) * k;
|
|
7507
|
-
r.onUpdate
|
|
7621
|
+
(_b = r.onUpdate) == null ? void 0 : _b.call(r, k);
|
|
7508
7622
|
if (t >= 1) this.finish(r);
|
|
7509
7623
|
}
|
|
7510
7624
|
finish(r) {
|
|
@@ -7548,629 +7662,652 @@ var frozenSafeArea = (v) => {
|
|
|
7548
7662
|
const sa = parseSafeArea(v);
|
|
7549
7663
|
return sa && Object.freeze(sa);
|
|
7550
7664
|
};
|
|
7551
|
-
|
|
7552
|
-
|
|
7553
|
-
|
|
7554
|
-
|
|
7555
|
-
canvas =
|
|
7556
|
-
canvas
|
|
7557
|
-
|
|
7558
|
-
|
|
7559
|
-
|
|
7560
|
-
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7566
|
-
|
|
7567
|
-
|
|
7568
|
-
|
|
7569
|
-
surfaces.
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
|
|
7573
|
-
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
|
|
7601
|
-
|
|
7602
|
-
|
|
7603
|
-
|
|
7604
|
-
|
|
7605
|
-
|
|
7606
|
-
|
|
7607
|
-
|
|
7608
|
-
|
|
7609
|
-
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
|
|
7613
|
-
|
|
7614
|
-
|
|
7615
|
-
|
|
7616
|
-
|
|
7617
|
-
|
|
7618
|
-
|
|
7619
|
-
|
|
7620
|
-
|
|
7621
|
-
|
|
7622
|
-
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
|
-
|
|
7626
|
-
|
|
7665
|
+
function createEngine() {
|
|
7666
|
+
return __async(this, arguments, function* (opts = {}) {
|
|
7667
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
7668
|
+
const play = (_a = opts.play) != null ? _a : null;
|
|
7669
|
+
let canvas = (_b = opts.canvas) != null ? _b : null;
|
|
7670
|
+
if (!canvas) {
|
|
7671
|
+
canvas = document.createElement("canvas");
|
|
7672
|
+
canvas.style.cssText = "position:fixed;top:0;left:0;width:100%;height:100%;display:block;touch-action:none";
|
|
7673
|
+
document.body.appendChild(canvas);
|
|
7674
|
+
}
|
|
7675
|
+
let renderer = createRenderer(canvas, {
|
|
7676
|
+
renderer: (_c = opts.renderer) != null ? _c : rendererFromUrl(),
|
|
7677
|
+
failIfMajorPerformanceCaveat: opts.failIfMajorPerformanceCaveat,
|
|
7678
|
+
instancing: opts.instancing
|
|
7679
|
+
});
|
|
7680
|
+
canvas = renderer.canvas;
|
|
7681
|
+
const surfaces = /* @__PURE__ */ new Set();
|
|
7682
|
+
const atlas = new Atlas(Math.min(2048, renderer.maxTextureSize), 4);
|
|
7683
|
+
atlas.onPage = (s) => surfaces.add(s);
|
|
7684
|
+
atlas.onDrop = (s) => {
|
|
7685
|
+
surfaces.delete(s);
|
|
7686
|
+
if (s.texture) renderer.destroyTexture(s.texture);
|
|
7687
|
+
s.texture = null;
|
|
7688
|
+
};
|
|
7689
|
+
let tex = textureOf(renderer);
|
|
7690
|
+
const tweens = new Tweens();
|
|
7691
|
+
const sound = new Sound();
|
|
7692
|
+
const painter = new AvatarPainter(atlas);
|
|
7693
|
+
const shapeCaches = /* @__PURE__ */ new Map();
|
|
7694
|
+
const frames = /* @__PURE__ */ new Map();
|
|
7695
|
+
const bakes = /* @__PURE__ */ new Map();
|
|
7696
|
+
const bitmapFonts = /* @__PURE__ */ new Map();
|
|
7697
|
+
const animations = /* @__PURE__ */ new Map();
|
|
7698
|
+
const tagSets = /* @__PURE__ */ new Set();
|
|
7699
|
+
let fontGen = 0;
|
|
7700
|
+
const forced = (_d = opts.tier) != null ? _d : tierFromUrl();
|
|
7701
|
+
const gpu = String((_e = renderer.info.renderer) != null ? _e : "");
|
|
7702
|
+
const store = (() => {
|
|
7703
|
+
var _a2;
|
|
7704
|
+
try {
|
|
7705
|
+
return (_a2 = __fabiGlobalThis.localStorage) != null ? _a2 : null;
|
|
7706
|
+
} catch (e) {
|
|
7707
|
+
return null;
|
|
7708
|
+
}
|
|
7709
|
+
})();
|
|
7710
|
+
const screenSize = typeof screen !== "undefined" ? "".concat(screen.width, "x").concat(screen.height) : "";
|
|
7711
|
+
const cacheKey = tierCacheKey(renderer.kind, gpu, screenSize);
|
|
7712
|
+
migrateStorageKey(store, cacheKey, legacyTierCacheKey(renderer.kind, gpu, screenSize));
|
|
7713
|
+
const cached = readTier(store, cacheKey);
|
|
7714
|
+
const start = startTier(forced, hintedTier(renderer.kind, play == null ? void 0 : play.device), cached == null ? void 0 : cached.name);
|
|
7715
|
+
let tierName = (_f = start == null ? void 0 : start.name) != null ? _f : "medium";
|
|
7716
|
+
let tierObj = tier(tierName);
|
|
7717
|
+
painter.setTier(tierName);
|
|
7718
|
+
let hinted = (start == null ? void 0 : start.from) === "hint";
|
|
7719
|
+
let ceiling = cached == null ? void 0 : cached.name;
|
|
7720
|
+
let refresh = (_g = cached == null ? void 0 : cached.refresh) != null ? _g : hintedRefresh(play == null ? void 0 : play.device);
|
|
7721
|
+
let pixelScale = 1;
|
|
7722
|
+
let cssW = 1;
|
|
7723
|
+
let cssH = 1;
|
|
7724
|
+
const kernel = {
|
|
7725
|
+
atlas,
|
|
7726
|
+
get pixelScale() {
|
|
7727
|
+
return pixelScale;
|
|
7728
|
+
},
|
|
7729
|
+
get fontGen() {
|
|
7730
|
+
return fontGen;
|
|
7731
|
+
},
|
|
7732
|
+
get effects() {
|
|
7733
|
+
return tierObj.effects;
|
|
7734
|
+
},
|
|
7735
|
+
tweens,
|
|
7736
|
+
frame: (name) => engine.frame(name),
|
|
7737
|
+
shape: (spec) => {
|
|
7738
|
+
const fx2 = tierObj.effects;
|
|
7739
|
+
const v = fx2 ? pixelScale : -pixelScale;
|
|
7740
|
+
let cache2 = shapeCaches.get(v);
|
|
7741
|
+
if (!cache2) {
|
|
7742
|
+
if (shapeCaches.size >= 8) shapeCaches.clear();
|
|
7743
|
+
shapeCaches.set(v, cache2 = new KeyCache(2e3));
|
|
7744
|
+
}
|
|
7745
|
+
const h = hash(spec);
|
|
7746
|
+
let b = cache2.get(spec, h);
|
|
7747
|
+
if (!b || !atlas.valid(b.frame)) {
|
|
7748
|
+
cache2.set(spec, b = bakeShape(atlas, forTier(spec, fx2), pixelScale), h);
|
|
7749
|
+
}
|
|
7750
|
+
return b;
|
|
7751
|
+
},
|
|
7752
|
+
bitmapFont: (name) => engine.bitmapFont(name)
|
|
7753
|
+
};
|
|
7754
|
+
let stageW = 1280;
|
|
7755
|
+
let hudEl = null;
|
|
7756
|
+
class StageGroup extends Group {
|
|
7757
|
+
get width() {
|
|
7758
|
+
return stageW;
|
|
7627
7759
|
}
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
|
|
7760
|
+
set width(_) {
|
|
7761
|
+
}
|
|
7762
|
+
get height() {
|
|
7763
|
+
return STAGE_HEIGHT;
|
|
7764
|
+
}
|
|
7765
|
+
set height(_) {
|
|
7766
|
+
}
|
|
7767
|
+
get safe() {
|
|
7768
|
+
const w2 = Math.min(stageW, STAGE_HEIGHT * 16 / 9);
|
|
7769
|
+
return { x: (stageW - w2) / 2, y: 0, w: w2, h: STAGE_HEIGHT };
|
|
7632
7770
|
}
|
|
7633
|
-
return b;
|
|
7634
|
-
},
|
|
7635
|
-
bitmapFont: (name) => engine.bitmapFont(name)
|
|
7636
|
-
};
|
|
7637
|
-
let stageW = 1280;
|
|
7638
|
-
let hudEl = null;
|
|
7639
|
-
class StageGroup extends Group {
|
|
7640
|
-
get width() {
|
|
7641
|
-
return stageW;
|
|
7642
|
-
}
|
|
7643
|
-
set width(_) {
|
|
7644
|
-
}
|
|
7645
|
-
get height() {
|
|
7646
|
-
return STAGE_HEIGHT;
|
|
7647
|
-
}
|
|
7648
|
-
set height(_) {
|
|
7649
|
-
}
|
|
7650
|
-
get safe() {
|
|
7651
|
-
const w2 = Math.min(stageW, STAGE_HEIGHT * 16 / 9);
|
|
7652
|
-
return { x: (stageW - w2) / 2, y: 0, w: w2, h: STAGE_HEIGHT };
|
|
7653
7771
|
}
|
|
7654
|
-
|
|
7655
|
-
|
|
7656
|
-
|
|
7657
|
-
|
|
7658
|
-
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
7665
|
-
|
|
7666
|
-
|
|
7667
|
-
|
|
7668
|
-
|
|
7669
|
-
|
|
7670
|
-
|
|
7772
|
+
const stage = new StageGroup(kernel);
|
|
7773
|
+
const resize = () => {
|
|
7774
|
+
var _a2;
|
|
7775
|
+
const c = renderer.canvas;
|
|
7776
|
+
const r = c.getBoundingClientRect();
|
|
7777
|
+
cssW = Math.max(1, r.width || c.clientWidth || innerWidth);
|
|
7778
|
+
cssH = Math.max(1, r.height || c.clientHeight || innerHeight);
|
|
7779
|
+
stageW = STAGE_HEIGHT * cssW / cssH;
|
|
7780
|
+
const dpr = Math.min(__fabiGlobalThis.devicePixelRatio || 1, (_a2 = opts.maxPixelRatio) != null ? _a2 : 2);
|
|
7781
|
+
const want = cssH * dpr / STAGE_HEIGHT;
|
|
7782
|
+
if (want <= tierObj.resolution) {
|
|
7783
|
+
const h = Math.max(1, Math.round(cssH * dpr));
|
|
7784
|
+
pixelScale = h / STAGE_HEIGHT;
|
|
7785
|
+
renderer.resize(Math.max(1, Math.round(cssW * dpr)), h);
|
|
7786
|
+
} else {
|
|
7787
|
+
pixelScale = tierObj.resolution;
|
|
7788
|
+
renderer.resize(Math.round(stageW * pixelScale), Math.round(STAGE_HEIGHT * pixelScale));
|
|
7789
|
+
}
|
|
7790
|
+
if (hudEl) hudEl.style.setProperty("--unit", "".concat(cssH / STAGE_HEIGHT, "px"));
|
|
7791
|
+
};
|
|
7792
|
+
addEventListener("resize", resize);
|
|
7793
|
+
const setTier = (name) => {
|
|
7794
|
+
tierName = name;
|
|
7795
|
+
tierObj = tier(name);
|
|
7796
|
+
painter.setTier(name);
|
|
7797
|
+
resize();
|
|
7798
|
+
};
|
|
7799
|
+
const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(resize) : null;
|
|
7800
|
+
ro == null ? void 0 : ro.observe(canvas);
|
|
7801
|
+
let backdrop = (play == null ? void 0 : play.backdrop) === "video" ? "video" : "none";
|
|
7802
|
+
let view = (_h = play == null ? void 0 : play.view) != null ? _h : null;
|
|
7803
|
+
let orientation = (play == null ? void 0 : play.orientation) === "portrait" ? "portrait" : "landscape";
|
|
7804
|
+
let safeArea = (_i = frozenSafeArea(play == null ? void 0 : play.safeArea)) != null ? _i : NO_SAFE_AREA;
|
|
7805
|
+
let livePlayers = [];
|
|
7806
|
+
let lastPlayersAt = -Infinity;
|
|
7807
|
+
let hostPaused = false;
|
|
7808
|
+
let userPaused = false;
|
|
7809
|
+
const backdropListeners = /* @__PURE__ */ new Set();
|
|
7810
|
+
const applyBackdrop = () => {
|
|
7811
|
+
const color = backdrop === "video" ? "transparent" : "";
|
|
7812
|
+
document.documentElement.style.background = color;
|
|
7813
|
+
document.body.style.background = color;
|
|
7814
|
+
};
|
|
7815
|
+
const setBackdrop = (b, v) => {
|
|
7816
|
+
const next = b === "video" ? "video" : "none";
|
|
7817
|
+
const nv = v != null ? v : null;
|
|
7818
|
+
if (next === backdrop && (nv === view || nv && view && nv.x === view.x && nv.y === view.y && nv.w === view.w && nv.h === view.h)) return;
|
|
7819
|
+
backdrop = next;
|
|
7820
|
+
view = nv;
|
|
7821
|
+
applyBackdrop();
|
|
7822
|
+
for (const l of [...backdropListeners]) l(backdrop, view);
|
|
7823
|
+
};
|
|
7824
|
+
const unlisten = [];
|
|
7825
|
+
if (play) {
|
|
7826
|
+
const setPlayers = (p) => {
|
|
7827
|
+
if (Array.isArray(p)) {
|
|
7828
|
+
livePlayers = p;
|
|
7829
|
+
lastPlayersAt = now2();
|
|
7830
|
+
}
|
|
7831
|
+
};
|
|
7832
|
+
const hold2 = (on) => {
|
|
7833
|
+
hostPaused = on;
|
|
7834
|
+
syncSound();
|
|
7835
|
+
};
|
|
7836
|
+
const lateHint = (device) => {
|
|
7837
|
+
if (forced || hinted) return;
|
|
7838
|
+
if (!Number.isFinite(refresh)) refresh = hintedRefresh(device);
|
|
7839
|
+
const h = hintedTier(renderer.kind, device);
|
|
7840
|
+
if (!h) return;
|
|
7841
|
+
hinted = true;
|
|
7842
|
+
setTier(ceiling ? lowerOf(h, ceiling) : h);
|
|
7843
|
+
};
|
|
7844
|
+
unlisten.push(
|
|
7845
|
+
play.on("start", (m) => lateHint(m == null ? void 0 : m.device)),
|
|
7846
|
+
play.on("start", (m) => {
|
|
7847
|
+
if ((m == null ? void 0 : m.orientation) === "portrait" || (m == null ? void 0 : m.orientation) === "landscape") orientation = m.orientation;
|
|
7848
|
+
const sa = frozenSafeArea(m == null ? void 0 : m.safeArea);
|
|
7849
|
+
if (sa) safeArea = sa;
|
|
7850
|
+
}),
|
|
7851
|
+
// The simple API knows muted only from the start (its getter is false before): read it again then.
|
|
7852
|
+
play.on("start", (m) => {
|
|
7853
|
+
if (typeof (m == null ? void 0 : m.muted) === "boolean") sound.muted = m.muted;
|
|
7854
|
+
}),
|
|
7855
|
+
play.on("frame", (m) => setPlayers(m == null ? void 0 : m.players)),
|
|
7856
|
+
play.on("players", (m) => setPlayers(m == null ? void 0 : m.players)),
|
|
7857
|
+
play.on("backdrop", (m) => setBackdrop(m == null ? void 0 : m.backdrop, m == null ? void 0 : m.view)),
|
|
7858
|
+
play.on("start", (m) => {
|
|
7859
|
+
var _a2;
|
|
7860
|
+
return setBackdrop(m == null ? void 0 : m.backdrop, (_a2 = m == null ? void 0 : m.view) != null ? _a2 : play.view);
|
|
7861
|
+
}),
|
|
7862
|
+
play.on("pause", () => hold2(true)),
|
|
7863
|
+
play.on("resume", () => hold2(false)),
|
|
7864
|
+
play.on("break-start", () => hold2(true)),
|
|
7865
|
+
play.on("break-done", () => hold2(false)),
|
|
7866
|
+
play.on("break-end", () => hold2(false))
|
|
7867
|
+
);
|
|
7868
|
+
sound.muted = play.muted === true;
|
|
7671
7869
|
}
|
|
7672
|
-
if (hudEl) hudEl.style.setProperty("--unit", `${cssH / STAGE_HEIGHT}px`);
|
|
7673
|
-
};
|
|
7674
|
-
addEventListener("resize", resize);
|
|
7675
|
-
const setTier = (name) => {
|
|
7676
|
-
tierName = name;
|
|
7677
|
-
tierObj = tier(name);
|
|
7678
|
-
painter.setTier(name);
|
|
7679
|
-
resize();
|
|
7680
|
-
};
|
|
7681
|
-
const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(resize) : null;
|
|
7682
|
-
ro?.observe(canvas);
|
|
7683
|
-
let backdrop = play?.backdrop === "video" ? "video" : "none";
|
|
7684
|
-
let view = play?.view ?? null;
|
|
7685
|
-
let orientation = play?.orientation === "portrait" ? "portrait" : "landscape";
|
|
7686
|
-
let safeArea = frozenSafeArea(play?.safeArea) ?? NO_SAFE_AREA;
|
|
7687
|
-
let livePlayers = [];
|
|
7688
|
-
let lastPlayersAt = -Infinity;
|
|
7689
|
-
let hostPaused = false;
|
|
7690
|
-
let userPaused = false;
|
|
7691
|
-
const backdropListeners = /* @__PURE__ */ new Set();
|
|
7692
|
-
const applyBackdrop = () => {
|
|
7693
|
-
const color = backdrop === "video" ? "transparent" : "";
|
|
7694
|
-
document.documentElement.style.background = color;
|
|
7695
|
-
document.body.style.background = color;
|
|
7696
|
-
};
|
|
7697
|
-
const setBackdrop = (b, v) => {
|
|
7698
|
-
const next = b === "video" ? "video" : "none";
|
|
7699
|
-
const nv = v ?? null;
|
|
7700
|
-
if (next === backdrop && (nv === view || nv && view && nv.x === view.x && nv.y === view.y && nv.w === view.w && nv.h === view.h)) return;
|
|
7701
|
-
backdrop = next;
|
|
7702
|
-
view = nv;
|
|
7703
7870
|
applyBackdrop();
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
const
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7871
|
+
const syncSound = () => hostPaused || userPaused || document.hidden ? sound.hold() : sound.release();
|
|
7872
|
+
let handsAt = -1;
|
|
7873
|
+
let handsCache = [];
|
|
7874
|
+
let tick = 0;
|
|
7875
|
+
const live = () => now2() - lastPlayersAt < 1e3 ? livePlayers : [];
|
|
7876
|
+
const toScreen2 = (p) => play ? play.toScreen(p) : toScreen(view, p);
|
|
7877
|
+
const hold = new AimHold();
|
|
7878
|
+
const allHands = () => {
|
|
7879
|
+
if (handsAt === tick) return handsCache;
|
|
7880
|
+
handsAt = tick;
|
|
7881
|
+
const portrait = orientation === "portrait";
|
|
7882
|
+
const bodyOf = backdrop === "video" && !portrait || !(play == null ? void 0 : play.smoothedBody) ? () => null : (f2) => play.smoothedBody(f2);
|
|
7883
|
+
handsCache = handsOf(live(), toScreen2, stageW, STAGE_HEIGHT, bodyOf, portrait ? { orientation, hold, t: now2() } : void 0);
|
|
7884
|
+
return handsCache;
|
|
7713
7885
|
};
|
|
7714
|
-
const
|
|
7715
|
-
|
|
7716
|
-
|
|
7886
|
+
const box = { x: 0, y: 0, w: 1, h: 1 };
|
|
7887
|
+
const avatarBox = () => {
|
|
7888
|
+
box.x = view ? view.x * stageW : 0;
|
|
7889
|
+
box.y = view ? view.y * STAGE_HEIGHT : 0;
|
|
7890
|
+
box.w = view ? view.w * stageW : stageW;
|
|
7891
|
+
box.h = view ? view.h * STAGE_HEIGHT : STAGE_HEIGHT;
|
|
7892
|
+
return box;
|
|
7717
7893
|
};
|
|
7718
|
-
const
|
|
7719
|
-
|
|
7720
|
-
|
|
7721
|
-
const
|
|
7722
|
-
if (
|
|
7723
|
-
|
|
7724
|
-
|
|
7894
|
+
const paintAvatars = (o) => {
|
|
7895
|
+
var _a2;
|
|
7896
|
+
const alpha = (_a2 = o.alpha) != null ? _a2 : 1;
|
|
7897
|
+
const tags = o.tags ? new NameTags(atlas, o) : null;
|
|
7898
|
+
if (tags) tagSets.add(tags);
|
|
7899
|
+
const tagOf = typeof o.tags === "function" ? o.tags : (p) => String(p);
|
|
7900
|
+
return (ctx2, a) => {
|
|
7901
|
+
var _a3, _b2, _c2, _d2, _e2, _f2;
|
|
7902
|
+
if (backdrop === "video") return;
|
|
7903
|
+
const b = avatarBox();
|
|
7904
|
+
for (const f2 of live()) {
|
|
7905
|
+
const body = (_b2 = (_a3 = play == null ? void 0 : play.smoothedBody) == null ? void 0 : _a3.call(play, f2)) != null ? _b2 : f2.body;
|
|
7906
|
+
const def = (_f2 = avatarById((_e2 = (_d2 = (_c2 = play == null ? void 0 : play.avatarOf) == null ? void 0 : _c2.call(play, f2)) != null ? _d2 : f2.avatar) != null ? _e2 : "")) != null ? _f2 : DEFAULT_AVATAR;
|
|
7907
|
+
if (!painter.draw(ctx2.r, ctx2.tex, body, def, b, alpha * a, pixelScale) || !tags) continue;
|
|
7908
|
+
const name = tagOf(f2.id);
|
|
7909
|
+
if (name) tags.draw(ctx2.r, ctx2.tex, body, def, b, name, playerColor(f2.id), alpha * a, pixelScale, stageW, STAGE_HEIGHT);
|
|
7910
|
+
}
|
|
7911
|
+
};
|
|
7725
7912
|
};
|
|
7726
|
-
|
|
7727
|
-
|
|
7728
|
-
|
|
7729
|
-
|
|
7730
|
-
|
|
7731
|
-
|
|
7732
|
-
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7736
|
-
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7746
|
-
|
|
7747
|
-
|
|
7748
|
-
|
|
7749
|
-
|
|
7750
|
-
|
|
7751
|
-
|
|
7752
|
-
|
|
7753
|
-
let tick = 0;
|
|
7754
|
-
const live = () => now2() - lastPlayersAt < 1e3 ? livePlayers : [];
|
|
7755
|
-
const toScreen2 = (p) => play ? play.toScreen(p) : toScreen(view, p);
|
|
7756
|
-
const hold = new AimHold();
|
|
7757
|
-
const allHands = () => {
|
|
7758
|
-
if (handsAt === tick) return handsCache;
|
|
7759
|
-
handsAt = tick;
|
|
7760
|
-
const portrait = orientation === "portrait";
|
|
7761
|
-
const bodyOf = backdrop === "video" && !portrait || !play?.smoothedBody ? () => null : (f2) => play.smoothedBody(f2);
|
|
7762
|
-
handsCache = handsOf(live(), toScreen2, stageW, STAGE_HEIGHT, bodyOf, portrait ? { orientation, hold, t: now2() } : void 0);
|
|
7763
|
-
return handsCache;
|
|
7764
|
-
};
|
|
7765
|
-
const box = { x: 0, y: 0, w: 1, h: 1 };
|
|
7766
|
-
const avatarBox = () => {
|
|
7767
|
-
box.x = view ? view.x * stageW : 0;
|
|
7768
|
-
box.y = view ? view.y * STAGE_HEIGHT : 0;
|
|
7769
|
-
box.w = view ? view.w * stageW : stageW;
|
|
7770
|
-
box.h = view ? view.h * STAGE_HEIGHT : STAGE_HEIGHT;
|
|
7771
|
-
return box;
|
|
7772
|
-
};
|
|
7773
|
-
const paintAvatars = (o) => {
|
|
7774
|
-
const alpha = o.alpha ?? 1;
|
|
7775
|
-
const tags = o.tags ? new NameTags(atlas, o) : null;
|
|
7776
|
-
if (tags) tagSets.add(tags);
|
|
7777
|
-
const tagOf = typeof o.tags === "function" ? o.tags : (p) => String(p);
|
|
7778
|
-
return (ctx2, a) => {
|
|
7779
|
-
if (backdrop === "video") return;
|
|
7780
|
-
const b = avatarBox();
|
|
7781
|
-
for (const f2 of live()) {
|
|
7782
|
-
const body = play?.smoothedBody?.(f2) ?? f2.body;
|
|
7783
|
-
const def = avatarById(play?.avatarOf?.(f2) ?? f2.avatar ?? "") ?? DEFAULT_AVATAR;
|
|
7784
|
-
if (!painter.draw(ctx2.r, ctx2.tex, body, def, b, alpha * a, pixelScale) || !tags) continue;
|
|
7785
|
-
const name = tagOf(f2.id);
|
|
7786
|
-
if (name) tags.draw(ctx2.r, ctx2.tex, body, def, b, name, playerColor(f2.id), alpha * a, pixelScale, stageW, STAGE_HEIGHT);
|
|
7787
|
-
}
|
|
7913
|
+
const updates = /* @__PURE__ */ new Set();
|
|
7914
|
+
const renders = /* @__PURE__ */ new Set();
|
|
7915
|
+
const tickers = /* @__PURE__ */ new Set();
|
|
7916
|
+
let running = false;
|
|
7917
|
+
let raf = 0;
|
|
7918
|
+
let last2 = 0;
|
|
7919
|
+
let time = 0;
|
|
7920
|
+
const stats = { fps: 0, cpuMs: 0, drawCalls: 0, quads: 0, filtersSkipped: 0 };
|
|
7921
|
+
let statFrames = 0;
|
|
7922
|
+
let statCpu = 0;
|
|
7923
|
+
let statSince = now2();
|
|
7924
|
+
const windowIntervals = [];
|
|
7925
|
+
let lostSince = 0;
|
|
7926
|
+
const drawCtx = () => ({ r: renderer, kernel, tex });
|
|
7927
|
+
let ctx = drawCtx();
|
|
7928
|
+
const render = () => {
|
|
7929
|
+
if (renderer.lost) return;
|
|
7930
|
+
const [rgb, a] = backdrop === "video" || opts.background === void 0 ? [0, 0] : parseColor(opts.background);
|
|
7931
|
+
renderer.time = time;
|
|
7932
|
+
renderer.maxBlur = tierObj.maxBlur;
|
|
7933
|
+
renderer.begin(rgb, a, pixelScale);
|
|
7934
|
+
composeMat(stage.world, null, stage.x, stage.y, stage.rotation, stage.scaleX, stage.scaleY);
|
|
7935
|
+
drawNode(ctx, stage, stage.alpha, stage.tint);
|
|
7936
|
+
const s = renderer.end();
|
|
7937
|
+
stats.drawCalls = s.drawCalls;
|
|
7938
|
+
stats.quads = s.quads;
|
|
7939
|
+
stats.filtersSkipped = s.filtersSkipped;
|
|
7788
7940
|
};
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
let ctx = drawCtx();
|
|
7805
|
-
const render = () => {
|
|
7806
|
-
if (renderer.lost) return;
|
|
7807
|
-
const [rgb, a] = backdrop === "video" || opts.background === void 0 ? [0, 0] : parseColor(opts.background);
|
|
7808
|
-
renderer.time = time;
|
|
7809
|
-
renderer.maxBlur = tierObj.maxBlur;
|
|
7810
|
-
renderer.begin(rgb, a, pixelScale);
|
|
7811
|
-
composeMat(stage.world, null, stage.x, stage.y, stage.rotation, stage.scaleX, stage.scaleY);
|
|
7812
|
-
drawNode(ctx, stage, stage.alpha, stage.tint);
|
|
7813
|
-
const s = renderer.end();
|
|
7814
|
-
stats.drawCalls = s.drawCalls;
|
|
7815
|
-
stats.quads = s.quads;
|
|
7816
|
-
stats.filtersSkipped = s.filtersSkipped;
|
|
7817
|
-
};
|
|
7818
|
-
const frame = (t) => {
|
|
7819
|
-
if (!running) return;
|
|
7820
|
-
raf = requestAnimationFrame(frame);
|
|
7821
|
-
const dt = Math.min(Math.max((t - last2) / 1e3, 0), 0.1);
|
|
7822
|
-
if (last2) windowIntervals.push(t - last2);
|
|
7823
|
-
last2 = t;
|
|
7824
|
-
tick++;
|
|
7825
|
-
const t0 = now2();
|
|
7826
|
-
const paused = hostPaused || userPaused;
|
|
7827
|
-
if (!paused) {
|
|
7828
|
-
time += dt;
|
|
7829
|
-
tweens.update(dt);
|
|
7830
|
-
for (const p of tickers) if (!p.destroyed) p.update(dt);
|
|
7831
|
-
for (const fn of updates) fn(dt, time);
|
|
7832
|
-
}
|
|
7833
|
-
for (const fn of renders) fn(dt);
|
|
7834
|
-
stage.sweep();
|
|
7835
|
-
for (const p of tickers) if (p.destroyed) tickers.delete(p);
|
|
7836
|
-
if (renderer.lost) {
|
|
7837
|
-
lostSince || (lostSince = t);
|
|
7838
|
-
if (t - lostSince > 3e3) switchToCanvas2D();
|
|
7839
|
-
} else {
|
|
7840
|
-
lostSince = 0;
|
|
7841
|
-
render();
|
|
7842
|
-
}
|
|
7843
|
-
statFrames++;
|
|
7844
|
-
statCpu += now2() - t0;
|
|
7845
|
-
if (t0 - statSince >= 1e3) {
|
|
7846
|
-
stats.fps = Math.round(statFrames * 1e3 / (t0 - statSince));
|
|
7847
|
-
stats.cpuMs = Math.round(statCpu / Math.max(statFrames, 1) * 100) / 100;
|
|
7848
|
-
play?.reportStats?.({ fps: stats.fps, renderer: renderer.kind, tier: tierName });
|
|
7849
|
-
statFrames = 0;
|
|
7850
|
-
statCpu = 0;
|
|
7851
|
-
statSince = t0;
|
|
7852
|
-
}
|
|
7853
|
-
if (windowIntervals.length >= 180) {
|
|
7854
|
-
const display = Number.isFinite(refresh) ? refresh : refreshInterval(windowIntervals);
|
|
7855
|
-
if (!forced && !paused && shouldDrop(windowIntervals, display) && tierName !== "low") {
|
|
7856
|
-
setTier(lower(tierName));
|
|
7857
|
-
ceiling = tierName;
|
|
7858
|
-
writeTier(store, cacheKey, tierName, Number.isFinite(refresh) ? refresh : void 0);
|
|
7859
|
-
console.info(`[engine] slow frames: tier ${tierName}`);
|
|
7941
|
+
const frame = (t) => {
|
|
7942
|
+
var _a2;
|
|
7943
|
+
if (!running) return;
|
|
7944
|
+
raf = requestAnimationFrame(frame);
|
|
7945
|
+
const dt = Math.min(Math.max((t - last2) / 1e3, 0), 0.1);
|
|
7946
|
+
if (last2) windowIntervals.push(t - last2);
|
|
7947
|
+
last2 = t;
|
|
7948
|
+
tick++;
|
|
7949
|
+
const t0 = now2();
|
|
7950
|
+
const paused = hostPaused || userPaused;
|
|
7951
|
+
if (!paused) {
|
|
7952
|
+
time += dt;
|
|
7953
|
+
tweens.update(dt);
|
|
7954
|
+
for (const p of tickers) if (!p.destroyed) p.update(dt);
|
|
7955
|
+
for (const fn of updates) fn(dt, time);
|
|
7860
7956
|
}
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7957
|
+
for (const fn of renders) fn(dt);
|
|
7958
|
+
stage.sweep();
|
|
7959
|
+
for (const p of tickers) if (p.destroyed) tickers.delete(p);
|
|
7960
|
+
if (renderer.lost) {
|
|
7961
|
+
lostSince || (lostSince = t);
|
|
7962
|
+
if (t - lostSince > 3e3) switchToCanvas2D();
|
|
7963
|
+
} else {
|
|
7964
|
+
lostSince = 0;
|
|
7965
|
+
render();
|
|
7966
|
+
}
|
|
7967
|
+
statFrames++;
|
|
7968
|
+
statCpu += now2() - t0;
|
|
7969
|
+
if (t0 - statSince >= 1e3) {
|
|
7970
|
+
stats.fps = Math.round(statFrames * 1e3 / (t0 - statSince));
|
|
7971
|
+
stats.cpuMs = Math.round(statCpu / Math.max(statFrames, 1) * 100) / 100;
|
|
7972
|
+
(_a2 = play == null ? void 0 : play.reportStats) == null ? void 0 : _a2.call(play, { fps: stats.fps, renderer: renderer.kind, tier: tierName });
|
|
7973
|
+
statFrames = 0;
|
|
7974
|
+
statCpu = 0;
|
|
7975
|
+
statSince = t0;
|
|
7976
|
+
}
|
|
7977
|
+
if (windowIntervals.length >= 180) {
|
|
7978
|
+
const display = Number.isFinite(refresh) ? refresh : refreshInterval(windowIntervals);
|
|
7979
|
+
if (!forced && !paused && shouldDrop(windowIntervals, display) && tierName !== "low") {
|
|
7980
|
+
setTier(lower(tierName));
|
|
7981
|
+
ceiling = tierName;
|
|
7982
|
+
writeTier(store, cacheKey, tierName, Number.isFinite(refresh) ? refresh : void 0);
|
|
7983
|
+
console.info("[engine] slow frames: tier ".concat(tierName));
|
|
7984
|
+
}
|
|
7985
|
+
windowIntervals.length = 0;
|
|
7986
|
+
}
|
|
7987
|
+
};
|
|
7988
|
+
const switchToCanvas2D = () => {
|
|
7989
|
+
const c = freshCanvas(renderer.canvas);
|
|
7990
|
+
const r = createCanvas2D(c);
|
|
7991
|
+
if (!r) return;
|
|
7992
|
+
console.warn("[engine] WebGL context lost for good: switching to Canvas 2D");
|
|
7993
|
+
renderer.destroy();
|
|
7994
|
+
renderer = r;
|
|
7995
|
+
for (const s of surfaces) s.texture = null;
|
|
7996
|
+
for (const p of atlas.pages) surfaces.add(p.surface);
|
|
7997
|
+
tex = textureOf(renderer);
|
|
7998
|
+
ctx = drawCtx();
|
|
7999
|
+
ro == null ? void 0 : ro.disconnect();
|
|
8000
|
+
ro == null ? void 0 : ro.observe(c);
|
|
7894
8001
|
resize();
|
|
7895
|
-
|
|
7896
|
-
|
|
8002
|
+
};
|
|
8003
|
+
const onVisibility = () => {
|
|
8004
|
+
syncSound();
|
|
8005
|
+
if (!document.hidden) last2 = 0;
|
|
8006
|
+
};
|
|
8007
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
8008
|
+
const onFonts = () => {
|
|
8009
|
+
fontGen++;
|
|
8010
|
+
for (const t of tagSets) t.drop();
|
|
8011
|
+
};
|
|
8012
|
+
(_k = (_j = document.fonts) == null ? void 0 : _j.addEventListener) == null ? void 0 : _k.call(_j, "loadingdone", onFonts);
|
|
8013
|
+
resize();
|
|
8014
|
+
if (!start && opts.probe !== false) {
|
|
8015
|
+
if (!Number.isFinite(refresh)) refresh = displayInterval(yield idleIntervals(IDLE_FRAMES));
|
|
7897
8016
|
if (!hinted) {
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
8017
|
+
tierObj = tier("high");
|
|
8018
|
+
resize();
|
|
8019
|
+
const result = yield probe(renderer, atlas, () => tex, () => pixelScale, stageW, () => hinted);
|
|
8020
|
+
result.refresh = refresh;
|
|
8021
|
+
if (!hinted) {
|
|
8022
|
+
const picked = pickTier(renderer.kind, result);
|
|
8023
|
+
writeTier(store, cacheKey, picked, refresh);
|
|
8024
|
+
ceiling = picked;
|
|
8025
|
+
setTier(picked);
|
|
8026
|
+
}
|
|
7902
8027
|
}
|
|
7903
8028
|
}
|
|
7904
|
-
|
|
7905
|
-
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
7915
|
-
|
|
7916
|
-
|
|
7917
|
-
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
7925
|
-
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
|
|
7929
|
-
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
|
|
7934
|
-
|
|
7935
|
-
|
|
7936
|
-
|
|
7937
|
-
|
|
7938
|
-
|
|
7939
|
-
|
|
7940
|
-
|
|
7941
|
-
|
|
7942
|
-
|
|
7943
|
-
|
|
7944
|
-
|
|
7945
|
-
|
|
7946
|
-
|
|
7947
|
-
}
|
|
7948
|
-
|
|
7949
|
-
|
|
7950
|
-
|
|
7951
|
-
|
|
7952
|
-
|
|
7953
|
-
|
|
7954
|
-
|
|
7955
|
-
|
|
7956
|
-
|
|
7957
|
-
|
|
7958
|
-
|
|
7959
|
-
|
|
7960
|
-
|
|
7961
|
-
|
|
7962
|
-
|
|
7963
|
-
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
|
|
8029
|
+
const engine = {
|
|
8030
|
+
stage,
|
|
8031
|
+
get tier() {
|
|
8032
|
+
return tierObj;
|
|
8033
|
+
},
|
|
8034
|
+
get renderer() {
|
|
8035
|
+
return renderer;
|
|
8036
|
+
},
|
|
8037
|
+
get canvas() {
|
|
8038
|
+
return renderer.canvas;
|
|
8039
|
+
},
|
|
8040
|
+
get pixelScale() {
|
|
8041
|
+
return pixelScale;
|
|
8042
|
+
},
|
|
8043
|
+
get backdrop() {
|
|
8044
|
+
return backdrop;
|
|
8045
|
+
},
|
|
8046
|
+
get view() {
|
|
8047
|
+
return view;
|
|
8048
|
+
},
|
|
8049
|
+
get orientation() {
|
|
8050
|
+
return orientation;
|
|
8051
|
+
},
|
|
8052
|
+
get safeArea() {
|
|
8053
|
+
return safeArea;
|
|
8054
|
+
},
|
|
8055
|
+
get paused() {
|
|
8056
|
+
return hostPaused || userPaused;
|
|
8057
|
+
},
|
|
8058
|
+
sound,
|
|
8059
|
+
stats,
|
|
8060
|
+
get time() {
|
|
8061
|
+
return time;
|
|
8062
|
+
},
|
|
8063
|
+
get supports() {
|
|
8064
|
+
const s = renderer.support;
|
|
8065
|
+
return {
|
|
8066
|
+
filters: s.filters,
|
|
8067
|
+
blur: s.filters && tierObj.maxBlur > 0,
|
|
8068
|
+
shaders: s.shaders,
|
|
8069
|
+
maxBlur: s.filters ? tierObj.maxBlur : 0,
|
|
8070
|
+
tiers: { high: { maxBlur: tier("high").maxBlur }, medium: { maxBlur: tier("medium").maxBlur }, low: { maxBlur: tier("low").maxBlur } }
|
|
8071
|
+
};
|
|
8072
|
+
},
|
|
8073
|
+
sprite: (f2, props) => new Sprite(kernel, f2, props),
|
|
8074
|
+
shape: (spec, props) => new Shape(kernel, spec, props),
|
|
8075
|
+
text: (t, style) => new Text(kernel, t, style),
|
|
8076
|
+
group: (props) => new Group(kernel).set(props != null ? props : {}),
|
|
8077
|
+
particles(f2, o = {}) {
|
|
8078
|
+
const fr = typeof f2 === "object" && "type" in f2 ? kernel.shape(f2).frame : f2;
|
|
8079
|
+
const p = new Particles(kernel, fr, o);
|
|
8080
|
+
const _a2 = o, { max: _m, blend: _b2, gravity: _g2, drag: _d2 } = _a2, props = __objRest(_a2, ["max", "blend", "gravity", "drag"]);
|
|
8081
|
+
p.set(props);
|
|
8082
|
+
tickers.add(p);
|
|
8083
|
+
return p;
|
|
8084
|
+
},
|
|
8085
|
+
tween: (target, to, seconds, ease) => tweens.tween(target, to, seconds, ease),
|
|
8086
|
+
bake(name, w2, h, draw, origin) {
|
|
8087
|
+
bakes.set(name, { w: w2, h, draw, origin });
|
|
8088
|
+
frames.delete(name);
|
|
8089
|
+
return engine.frame(name);
|
|
8090
|
+
},
|
|
8091
|
+
frame(name) {
|
|
8092
|
+
var _a2, _b2, _c2, _d2;
|
|
8093
|
+
const f2 = frames.get(name);
|
|
8094
|
+
if (f2 && atlas.valid(f2) && (f2.gen === 0 || f2.scale === pixelScale)) return f2;
|
|
8095
|
+
const b = bakes.get(name);
|
|
8096
|
+
if (b) {
|
|
8097
|
+
const k = pixelScale;
|
|
8098
|
+
const nf = atlas.bake(b.w * k, b.h * k, (c) => (c.scale(k, k), b.draw(c)), k, (_b2 = (_a2 = b.origin) == null ? void 0 : _a2.x) != null ? _b2 : 0, (_d2 = (_c2 = b.origin) == null ? void 0 : _c2.y) != null ? _d2 : 0);
|
|
8099
|
+
frames.set(name, nf);
|
|
8100
|
+
return nf;
|
|
8101
|
+
}
|
|
8102
|
+
if (f2) return f2;
|
|
8103
|
+
throw new Error('[engine] no frame "'.concat(name, '": load it or bake it first'));
|
|
8104
|
+
},
|
|
8105
|
+
load(assets) {
|
|
8106
|
+
return __async(this, null, function* () {
|
|
8107
|
+
yield Promise.all(Object.entries(assets).map(([name, url]) => loadAsset(name, url)));
|
|
8108
|
+
});
|
|
8109
|
+
},
|
|
8110
|
+
hands: (player) => player === void 0 ? allHands() : allHands().filter((h) => h.player === player),
|
|
8111
|
+
touched(node, player, o = {}) {
|
|
8112
|
+
var _a2;
|
|
8113
|
+
node.updateWorld();
|
|
8114
|
+
return touching(node, allHands(), player, (_a2 = o.padding) != null ? _a2 : 0);
|
|
8115
|
+
},
|
|
8116
|
+
hits(node, x, y, padding = 0) {
|
|
8117
|
+
node.updateWorld();
|
|
8118
|
+
return hits(node, x, y, padding);
|
|
8119
|
+
},
|
|
8120
|
+
avatars: (o = {}) => new AvatarsNode(kernel, paintAvatars(o)),
|
|
8121
|
+
handMarkers(o = {}) {
|
|
8122
|
+
var _a2, _b2;
|
|
8123
|
+
const r = (_a2 = o.radius) != null ? _a2 : 36;
|
|
8124
|
+
const look = (_b2 = o.look) != null ? _b2 : "auto";
|
|
8125
|
+
const handMat = new Float64Array(6);
|
|
8126
|
+
const lw = Math.max(r * 0.12, 3);
|
|
8127
|
+
const ring = { type: "ring", r, lw, fill: "rgba(251,231,184,0.3)", stroke: "#ffffff" };
|
|
8128
|
+
const halo = { type: "ring", r, lw: lw * 1.8, stroke: HALO, shadow: { color: HALO, blur: r * 0.2 } };
|
|
8129
|
+
const put = (c, f2, x, y, tint2, a) => {
|
|
8130
|
+
const w2 = f2.w / f2.scale;
|
|
8131
|
+
composeMat(handMat, null, x - w2 / 2, y - w2 / 2, 0, 1, 1);
|
|
8132
|
+
c.r.quad(c.tex(f2.surface), f2, handMat, w2, w2, tint2, a, "normal");
|
|
8133
|
+
};
|
|
8134
|
+
const memo = (spec) => {
|
|
8135
|
+
let b = null;
|
|
8136
|
+
let fx2 = false;
|
|
8137
|
+
return () => (b && atlas.valid(b.frame) && b.frame.scale === pixelScale && fx2 === tierObj.effects ? b : (fx2 = tierObj.effects, b = kernel.shape(spec))).frame;
|
|
8138
|
+
};
|
|
8139
|
+
const ringOf = memo(ring);
|
|
8140
|
+
const haloOf = memo(halo);
|
|
8141
|
+
return new HandMarkers(kernel, (c, a) => {
|
|
8142
|
+
const video = look === "video" || look === "auto" && backdrop === "video";
|
|
8143
|
+
const b = ringOf();
|
|
8144
|
+
const u = video ? haloOf() : null;
|
|
8145
|
+
for (const h of allHands()) {
|
|
8146
|
+
if (u) put(c, u, h.x, h.y, 16777215, a);
|
|
8147
|
+
put(c, b, h.x, h.y, parseColor(h.color)[0], a);
|
|
8148
|
+
}
|
|
8149
|
+
});
|
|
8150
|
+
},
|
|
8151
|
+
timeline: (o) => tweens.timeline(o),
|
|
8152
|
+
animation(src, props) {
|
|
8153
|
+
const def = typeof src === "string" ? animationOf(src) : { frames: src };
|
|
8154
|
+
const a = new AnimatedSprite(kernel, def, props);
|
|
8155
|
+
tickers.add(a);
|
|
8156
|
+
return a;
|
|
8157
|
+
},
|
|
8158
|
+
bitmapFont(name, source) {
|
|
8159
|
+
if (!source) {
|
|
8160
|
+
const f3 = bitmapFonts.get(name);
|
|
8161
|
+
if (!f3) throw new Error('[engine] no bitmap font "'.concat(name, '": load or make it first'));
|
|
8162
|
+
return f3;
|
|
8163
|
+
}
|
|
8164
|
+
const f2 = "data" in source ? fontOf2(parseBMFont(source.data), source.pages) : generatedFont(kernel, source);
|
|
8165
|
+
bitmapFonts.set(name, f2);
|
|
8166
|
+
return f2;
|
|
8167
|
+
},
|
|
8168
|
+
players: () => live(),
|
|
8169
|
+
onFrame(fn) {
|
|
8170
|
+
updates.add(fn);
|
|
8171
|
+
return () => void updates.delete(fn);
|
|
8172
|
+
},
|
|
8173
|
+
onRender(fn) {
|
|
8174
|
+
renders.add(fn);
|
|
8175
|
+
return () => void renders.delete(fn);
|
|
8176
|
+
},
|
|
8177
|
+
onBackdrop(fn) {
|
|
8178
|
+
backdropListeners.add(fn);
|
|
8179
|
+
return () => void backdropListeners.delete(fn);
|
|
8180
|
+
},
|
|
8181
|
+
get hud() {
|
|
8182
|
+
if (!hudEl) {
|
|
8183
|
+
hudEl = document.createElement("div");
|
|
8184
|
+
hudEl.style.cssText = "position:fixed;top:0;right:0;bottom:0;left:0;pointer-events:none;overflow:hidden";
|
|
8185
|
+
document.body.appendChild(hudEl);
|
|
8186
|
+
resize();
|
|
8187
|
+
}
|
|
8188
|
+
return hudEl;
|
|
8189
|
+
},
|
|
8190
|
+
random: (min = 0, max = 1) => min + Math.random() * (max - min),
|
|
8191
|
+
start() {
|
|
8192
|
+
if (running) return;
|
|
8193
|
+
running = true;
|
|
8194
|
+
last2 = 0;
|
|
8195
|
+
raf = requestAnimationFrame(frame);
|
|
8196
|
+
},
|
|
8197
|
+
pause() {
|
|
8198
|
+
userPaused = true;
|
|
8199
|
+
syncSound();
|
|
8200
|
+
},
|
|
8201
|
+
resume() {
|
|
8202
|
+
userPaused = false;
|
|
8203
|
+
syncSound();
|
|
8204
|
+
},
|
|
8205
|
+
destroy() {
|
|
8206
|
+
var _a2, _b2;
|
|
8207
|
+
running = false;
|
|
8208
|
+
cancelAnimationFrame(raf);
|
|
8209
|
+
unlisten.forEach((u) => u());
|
|
8210
|
+
removeEventListener("resize", resize);
|
|
8211
|
+
ro == null ? void 0 : ro.disconnect();
|
|
8212
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
8213
|
+
(_b2 = (_a2 = document.fonts) == null ? void 0 : _a2.removeEventListener) == null ? void 0 : _b2.call(_a2, "loadingdone", onFonts);
|
|
8214
|
+
tweens.clear();
|
|
8215
|
+
forgetNodes(kernel);
|
|
8216
|
+
sound.destroy();
|
|
8217
|
+
renderer.destroy();
|
|
8218
|
+
hudEl == null ? void 0 : hudEl.remove();
|
|
7976
8219
|
}
|
|
7977
|
-
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
|
|
7984
|
-
|
|
7985
|
-
|
|
7986
|
-
return
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
-
|
|
7990
|
-
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
|
|
7997
|
-
|
|
7998
|
-
|
|
7999
|
-
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
};
|
|
8005
|
-
const memo = (spec) => {
|
|
8006
|
-
let b = null;
|
|
8007
|
-
let fx2 = false;
|
|
8008
|
-
return () => (b && atlas.valid(b.frame) && b.frame.scale === pixelScale && fx2 === tierObj.effects ? b : (fx2 = tierObj.effects, b = kernel.shape(spec))).frame;
|
|
8009
|
-
};
|
|
8010
|
-
const ringOf = memo(ring);
|
|
8011
|
-
const haloOf = memo(halo);
|
|
8012
|
-
return new HandMarkers(kernel, (c, a) => {
|
|
8013
|
-
const video = look === "video" || look === "auto" && backdrop === "video";
|
|
8014
|
-
const b = ringOf();
|
|
8015
|
-
const u = video ? haloOf() : null;
|
|
8016
|
-
for (const h of allHands()) {
|
|
8017
|
-
if (u) put(c, u, h.x, h.y, 16777215, a);
|
|
8018
|
-
put(c, b, h.x, h.y, parseColor(h.color)[0], a);
|
|
8220
|
+
};
|
|
8221
|
+
function animationOf(name) {
|
|
8222
|
+
const a = animations.get(name);
|
|
8223
|
+
if (a) return a;
|
|
8224
|
+
const names = [.../* @__PURE__ */ new Set([...frames.keys(), ...bakes.keys()])].filter((n) => n.startsWith(name)).sort(naturalOrder);
|
|
8225
|
+
if (!names.length) throw new Error('[engine] no animation or frames "'.concat(name, '\u2026"'));
|
|
8226
|
+
return { frames: names };
|
|
8227
|
+
}
|
|
8228
|
+
function loadAsset(name, url) {
|
|
8229
|
+
return __async(this, null, function* () {
|
|
8230
|
+
var _a2, _b2;
|
|
8231
|
+
const ext = url.split("?")[0].split(".").pop().toLowerCase();
|
|
8232
|
+
if (["mp3", "ogg", "wav", "m4a", "aac", "webm"].includes(ext)) return sound.load(name, url);
|
|
8233
|
+
if (["woff", "woff2", "ttf", "otf"].includes(ext)) {
|
|
8234
|
+
const face = new FontFace(name, "url(".concat(url, ")"));
|
|
8235
|
+
document.fonts.add(yield face.load());
|
|
8236
|
+
fontGen++;
|
|
8237
|
+
return;
|
|
8238
|
+
}
|
|
8239
|
+
const base = new URL(url, location.href);
|
|
8240
|
+
if (ext === "fnt") return loadFont(name, parseBMFont(yield (yield fetch(url)).text()), base);
|
|
8241
|
+
if (ext === "json") {
|
|
8242
|
+
const data = yield (yield fetch(url)).json();
|
|
8243
|
+
if (Array.isArray(data.chars) && !data.frames) return loadFont(name, parseBMFont(data), base);
|
|
8244
|
+
const img2 = yield loadImage(new URL((_b2 = (_a2 = data.meta) == null ? void 0 : _a2.image) != null ? _b2 : url.replace(/\.json$/, ".png"), base).href);
|
|
8245
|
+
readAtlas(name, data, surfaceOf(img2));
|
|
8246
|
+
return;
|
|
8019
8247
|
}
|
|
8248
|
+
const img = yield loadImage(url);
|
|
8249
|
+
const s = surfaceOf(img);
|
|
8250
|
+
surfaces.add(s);
|
|
8251
|
+
frames.set(name, { surface: s, x: 0, y: 0, w: img.width, h: img.height, scale: 1, gen: 0, ox: 0, oy: 0, margin: 0 });
|
|
8020
8252
|
});
|
|
8021
|
-
},
|
|
8022
|
-
timeline: (o) => tweens.timeline(o),
|
|
8023
|
-
animation(src, props) {
|
|
8024
|
-
const def = typeof src === "string" ? animationOf(src) : { frames: src };
|
|
8025
|
-
const a = new AnimatedSprite(kernel, def, props);
|
|
8026
|
-
tickers.add(a);
|
|
8027
|
-
return a;
|
|
8028
|
-
},
|
|
8029
|
-
bitmapFont(name, source) {
|
|
8030
|
-
if (!source) {
|
|
8031
|
-
const f3 = bitmapFonts.get(name);
|
|
8032
|
-
if (!f3) throw new Error(`[engine] no bitmap font "${name}": load or make it first`);
|
|
8033
|
-
return f3;
|
|
8034
|
-
}
|
|
8035
|
-
const f2 = "data" in source ? fontOf2(parseBMFont(source.data), source.pages) : generatedFont(kernel, source);
|
|
8036
|
-
bitmapFonts.set(name, f2);
|
|
8037
|
-
return f2;
|
|
8038
|
-
},
|
|
8039
|
-
players: () => live(),
|
|
8040
|
-
onFrame(fn) {
|
|
8041
|
-
updates.add(fn);
|
|
8042
|
-
return () => void updates.delete(fn);
|
|
8043
|
-
},
|
|
8044
|
-
onRender(fn) {
|
|
8045
|
-
renders.add(fn);
|
|
8046
|
-
return () => void renders.delete(fn);
|
|
8047
|
-
},
|
|
8048
|
-
onBackdrop(fn) {
|
|
8049
|
-
backdropListeners.add(fn);
|
|
8050
|
-
return () => void backdropListeners.delete(fn);
|
|
8051
|
-
},
|
|
8052
|
-
get hud() {
|
|
8053
|
-
if (!hudEl) {
|
|
8054
|
-
hudEl = document.createElement("div");
|
|
8055
|
-
hudEl.style.cssText = "position:fixed;inset:0;pointer-events:none;overflow:hidden";
|
|
8056
|
-
document.body.appendChild(hudEl);
|
|
8057
|
-
resize();
|
|
8058
|
-
}
|
|
8059
|
-
return hudEl;
|
|
8060
|
-
},
|
|
8061
|
-
random: (min = 0, max = 1) => min + Math.random() * (max - min),
|
|
8062
|
-
start() {
|
|
8063
|
-
if (running) return;
|
|
8064
|
-
running = true;
|
|
8065
|
-
last2 = 0;
|
|
8066
|
-
raf = requestAnimationFrame(frame);
|
|
8067
|
-
},
|
|
8068
|
-
pause() {
|
|
8069
|
-
userPaused = true;
|
|
8070
|
-
syncSound();
|
|
8071
|
-
},
|
|
8072
|
-
resume() {
|
|
8073
|
-
userPaused = false;
|
|
8074
|
-
syncSound();
|
|
8075
|
-
},
|
|
8076
|
-
destroy() {
|
|
8077
|
-
running = false;
|
|
8078
|
-
cancelAnimationFrame(raf);
|
|
8079
|
-
unlisten.forEach((u) => u());
|
|
8080
|
-
removeEventListener("resize", resize);
|
|
8081
|
-
ro?.disconnect();
|
|
8082
|
-
document.removeEventListener("visibilitychange", onVisibility);
|
|
8083
|
-
document.fonts?.removeEventListener?.("loadingdone", onFonts);
|
|
8084
|
-
tweens.clear();
|
|
8085
|
-
forgetNodes(kernel);
|
|
8086
|
-
sound.destroy();
|
|
8087
|
-
renderer.destroy();
|
|
8088
|
-
hudEl?.remove();
|
|
8089
8253
|
}
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
8093
|
-
|
|
8094
|
-
|
|
8095
|
-
|
|
8096
|
-
|
|
8097
|
-
|
|
8098
|
-
|
|
8099
|
-
const ext = url.split("?")[0].split(".").pop().toLowerCase();
|
|
8100
|
-
if (["mp3", "ogg", "wav", "m4a", "aac", "webm"].includes(ext)) return sound.load(name, url);
|
|
8101
|
-
if (["woff", "woff2", "ttf", "otf"].includes(ext)) {
|
|
8102
|
-
const face = new FontFace(name, `url(${url})`);
|
|
8103
|
-
document.fonts.add(await face.load());
|
|
8104
|
-
fontGen++;
|
|
8105
|
-
return;
|
|
8254
|
+
function fontOf2(data, pages) {
|
|
8255
|
+
return bmFont(
|
|
8256
|
+
data,
|
|
8257
|
+
pages.map((p) => {
|
|
8258
|
+
const s = surfaceOf(p);
|
|
8259
|
+
surfaces.add(s);
|
|
8260
|
+
return s;
|
|
8261
|
+
})
|
|
8262
|
+
);
|
|
8106
8263
|
}
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
if (Array.isArray(data.chars) && !data.frames) return loadFont(name, parseBMFont(data), base);
|
|
8112
|
-
const img2 = await loadImage(new URL(data.meta?.image ?? url.replace(/\.json$/, ".png"), base).href);
|
|
8113
|
-
readAtlas(name, data, surfaceOf(img2));
|
|
8114
|
-
return;
|
|
8264
|
+
function loadFont(name, data, base) {
|
|
8265
|
+
return __async(this, null, function* () {
|
|
8266
|
+
bitmapFonts.set(name, fontOf2(data, yield Promise.all(data.pages.map((p) => loadImage(new URL(p, base).href)))));
|
|
8267
|
+
});
|
|
8115
8268
|
}
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
8124
|
-
|
|
8125
|
-
|
|
8126
|
-
|
|
8127
|
-
|
|
8128
|
-
|
|
8129
|
-
|
|
8130
|
-
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
const
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
|
|
8145
|
-
|
|
8146
|
-
|
|
8147
|
-
frame2.tx = f2.spriteSourceSize.x;
|
|
8148
|
-
frame2.ty = f2.spriteSourceSize.y;
|
|
8269
|
+
function readAtlas(name, data, s) {
|
|
8270
|
+
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
8271
|
+
surfaces.add(s);
|
|
8272
|
+
const list = Array.isArray(data.frames) ? data.frames : Object.entries(data.frames).map(([filename, f2]) => __spreadProps(__spreadValues({}, f2), { filename }));
|
|
8273
|
+
const keys = [];
|
|
8274
|
+
const durations = [];
|
|
8275
|
+
for (const f2 of list) {
|
|
8276
|
+
const fr = f2.frame;
|
|
8277
|
+
const key = f2.filename.replace(IMAGE_EXT, "");
|
|
8278
|
+
if (f2.rotated) console.warn("[engine] ".concat(name, "/").concat(key, " is rotated: export without rotation"));
|
|
8279
|
+
const frame2 = { surface: s, x: fr.x, y: fr.y, w: fr.w, h: fr.h, scale: 1, gen: 0, ox: 0, oy: 0, margin: 0 };
|
|
8280
|
+
if (f2.trimmed && f2.sourceSize && f2.spriteSourceSize) {
|
|
8281
|
+
frame2.sw = f2.sourceSize.w;
|
|
8282
|
+
frame2.sh = f2.sourceSize.h;
|
|
8283
|
+
frame2.tx = f2.spriteSourceSize.x;
|
|
8284
|
+
frame2.ty = f2.spriteSourceSize.y;
|
|
8285
|
+
}
|
|
8286
|
+
const b = f2.scale9Borders;
|
|
8287
|
+
if (b) frame2.slice = [b.y, ((_a2 = frame2.sw) != null ? _a2 : fr.w) - b.x - b.w, ((_b2 = frame2.sh) != null ? _b2 : fr.h) - b.y - b.h, b.x];
|
|
8288
|
+
frames.set("".concat(name, "/").concat(key), frame2);
|
|
8289
|
+
keys.push("".concat(name, "/").concat(key));
|
|
8290
|
+
durations.push(((_c2 = f2.duration) != null ? _c2 : 0) / 1e3);
|
|
8291
|
+
}
|
|
8292
|
+
for (const [anim, names] of Object.entries((_d2 = data.animations) != null ? _d2 : {})) animations.set("".concat(name, "/").concat(anim), { frames: names.map((n) => "".concat(name, "/").concat(n.replace(IMAGE_EXT, ""))) });
|
|
8293
|
+
for (const tag of (_f2 = (_e2 = data.meta) == null ? void 0 : _e2.frameTags) != null ? _f2 : []) {
|
|
8294
|
+
const idx = [];
|
|
8295
|
+
for (let i = tag.from; i <= tag.to; i++) idx.push(i);
|
|
8296
|
+
if (tag.direction === "reverse") idx.reverse();
|
|
8297
|
+
if (tag.direction === "pingpong") idx.push(...idx.slice(1, -1).reverse());
|
|
8298
|
+
const timed = idx.every((i) => durations[i] > 0);
|
|
8299
|
+
animations.set("".concat(name, "/").concat(tag.name), __spreadValues({ frames: idx.map((i) => keys[i]) }, timed ? { durations: idx.map((i) => durations[i]) } : {}));
|
|
8149
8300
|
}
|
|
8150
|
-
const b = f2.scale9Borders;
|
|
8151
|
-
if (b) frame2.slice = [b.y, (frame2.sw ?? fr.w) - b.x - b.w, (frame2.sh ?? fr.h) - b.y - b.h, b.x];
|
|
8152
|
-
frames.set(`${name}/${key}`, frame2);
|
|
8153
|
-
keys.push(`${name}/${key}`);
|
|
8154
|
-
durations.push((f2.duration ?? 0) / 1e3);
|
|
8155
|
-
}
|
|
8156
|
-
for (const [anim, names] of Object.entries(data.animations ?? {})) animations.set(`${name}/${anim}`, { frames: names.map((n) => `${name}/${n.replace(IMAGE_EXT, "")}`) });
|
|
8157
|
-
for (const tag of data.meta?.frameTags ?? []) {
|
|
8158
|
-
const idx = [];
|
|
8159
|
-
for (let i = tag.from; i <= tag.to; i++) idx.push(i);
|
|
8160
|
-
if (tag.direction === "reverse") idx.reverse();
|
|
8161
|
-
if (tag.direction === "pingpong") idx.push(...idx.slice(1, -1).reverse());
|
|
8162
|
-
const timed = idx.every((i) => durations[i] > 0);
|
|
8163
|
-
animations.set(`${name}/${tag.name}`, { frames: idx.map((i) => keys[i]), ...timed ? { durations: idx.map((i) => durations[i]) } : {} });
|
|
8164
8301
|
}
|
|
8165
|
-
|
|
8166
|
-
|
|
8302
|
+
return engine;
|
|
8303
|
+
});
|
|
8167
8304
|
}
|
|
8168
8305
|
var IMAGE_EXT = /\.(png|webp|jpe?g|gif|bmp)$/i;
|
|
8169
8306
|
function loadImage(url) {
|
|
8170
8307
|
return new Promise((resolve2, reject) => {
|
|
8171
8308
|
const img = new Image();
|
|
8172
8309
|
img.onload = () => resolve2(img);
|
|
8173
|
-
img.onerror = () => reject(new Error(
|
|
8310
|
+
img.onerror = () => reject(new Error("[engine] image did not load: ".concat(url)));
|
|
8174
8311
|
img.src = url;
|
|
8175
8312
|
});
|
|
8176
8313
|
}
|
|
@@ -8187,52 +8324,54 @@ function idleIntervals(n) {
|
|
|
8187
8324
|
requestAnimationFrame(step);
|
|
8188
8325
|
});
|
|
8189
8326
|
}
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
8203
|
-
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
const tx = tex();
|
|
8207
|
-
for (let i = 0; i < 300; i++) {
|
|
8208
|
-
const a = t / 1e3 + i;
|
|
8209
|
-
composeMat(m, null, i * 37 % width, i * 53 % STAGE_HEIGHT, a, 1, 1);
|
|
8210
|
-
renderer.quad(tx(star.surface), star, m, star.w / k, star.h / k, 16777215, ALPHA, "normal");
|
|
8211
|
-
}
|
|
8212
|
-
for (let i = 0; i < 40; i++) {
|
|
8213
|
-
renderer.ellipse(100 + i * 20, 300, 20, 14, i, 16746496, ALPHA);
|
|
8214
|
-
renderer.stroke([100 + i * 20, 400, 120 + i * 20, 460, 100 + i * 20, 520], 3, 18, 3368703, ALPHA, false);
|
|
8215
|
-
}
|
|
8216
|
-
renderer.end();
|
|
8217
|
-
ctx2d?.getImageData(0, 0, 1, 1);
|
|
8218
|
-
if (t - start > 250) cpu.push(now2() - t0);
|
|
8219
|
-
if (t - start < 750 && !stop()) requestAnimationFrame(step);
|
|
8220
|
-
else {
|
|
8327
|
+
function probe(renderer, atlas, tex, scale, width, stop = () => false) {
|
|
8328
|
+
return __async(this, null, function* () {
|
|
8329
|
+
const k = scale();
|
|
8330
|
+
const star = bakeShape(atlas, { type: "star", r: 30, fill: "#ffd23f", stroke: "#3a2a10", lw: 3 }, k).frame;
|
|
8331
|
+
const intervals = [];
|
|
8332
|
+
const cpu = [];
|
|
8333
|
+
const m = new Float64Array(6);
|
|
8334
|
+
const ALPHA = 4e-3;
|
|
8335
|
+
const ctx2d = renderer.kind === "canvas2d" ? renderer.canvas.getContext("2d") : null;
|
|
8336
|
+
const start = now2();
|
|
8337
|
+
let last2 = 0;
|
|
8338
|
+
yield new Promise((done) => {
|
|
8339
|
+
const step = (t) => {
|
|
8340
|
+
if (last2 && t - start > 250) intervals.push(t - last2);
|
|
8341
|
+
last2 = t;
|
|
8342
|
+
const t0 = now2();
|
|
8221
8343
|
renderer.begin(0, 0, k);
|
|
8344
|
+
const tx = tex();
|
|
8345
|
+
for (let i = 0; i < 300; i++) {
|
|
8346
|
+
const a = t / 1e3 + i;
|
|
8347
|
+
composeMat(m, null, i * 37 % width, i * 53 % STAGE_HEIGHT, a, 1, 1);
|
|
8348
|
+
renderer.quad(tx(star.surface), star, m, star.w / k, star.h / k, 16777215, ALPHA, "normal");
|
|
8349
|
+
}
|
|
8350
|
+
for (let i = 0; i < 40; i++) {
|
|
8351
|
+
renderer.ellipse(100 + i * 20, 300, 20, 14, i, 16746496, ALPHA);
|
|
8352
|
+
renderer.stroke([100 + i * 20, 400, 120 + i * 20, 460, 100 + i * 20, 520], 3, 18, 3368703, ALPHA, false);
|
|
8353
|
+
}
|
|
8222
8354
|
renderer.end();
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
|
|
8226
|
-
|
|
8355
|
+
ctx2d == null ? void 0 : ctx2d.getImageData(0, 0, 1, 1);
|
|
8356
|
+
if (t - start > 250) cpu.push(now2() - t0);
|
|
8357
|
+
if (t - start < 750 && !stop()) requestAnimationFrame(step);
|
|
8358
|
+
else {
|
|
8359
|
+
renderer.begin(0, 0, k);
|
|
8360
|
+
renderer.end();
|
|
8361
|
+
done();
|
|
8362
|
+
}
|
|
8363
|
+
};
|
|
8364
|
+
requestAnimationFrame(step);
|
|
8365
|
+
});
|
|
8366
|
+
return { intervals, cpu };
|
|
8227
8367
|
});
|
|
8228
|
-
return { intervals, cpu };
|
|
8229
8368
|
}
|
|
8230
8369
|
|
|
8231
8370
|
// src/render/canvas2d-filters.ts
|
|
8232
8371
|
var PLANS = 64;
|
|
8233
8372
|
var SWEEP = 32;
|
|
8234
8373
|
var svgIds = 0;
|
|
8235
|
-
var svgPre =
|
|
8374
|
+
var svgPre = "fabi-cm-".concat(Math.random().toString(36).slice(2, 7), "-");
|
|
8236
8375
|
var warned2 = /* @__PURE__ */ new Set();
|
|
8237
8376
|
var warnOnce = (k, msg) => {
|
|
8238
8377
|
if (warned2.has(k)) return;
|
|
@@ -8261,7 +8400,7 @@ var C2DFx = class {
|
|
|
8261
8400
|
__publicField(this, "flip", 0);
|
|
8262
8401
|
}
|
|
8263
8402
|
chain(src, filters) {
|
|
8264
|
-
var _a;
|
|
8403
|
+
var _a, _b;
|
|
8265
8404
|
const r = this.r;
|
|
8266
8405
|
let b = this.buf;
|
|
8267
8406
|
b[0] = r.scale;
|
|
@@ -8280,7 +8419,7 @@ var C2DFx = class {
|
|
|
8280
8419
|
b[n++] = f2.enabled ? 1 : 0;
|
|
8281
8420
|
if (f2.params) n = f2.params(b, n);
|
|
8282
8421
|
}
|
|
8283
|
-
const k = (_a = this.keys)[n]
|
|
8422
|
+
const k = (_b = (_a = this.keys)[n]) != null ? _b : _a[n] = new Float64Array(n);
|
|
8284
8423
|
for (let i = 0; i < n; i++) k[i] = b[i];
|
|
8285
8424
|
const kh = hash(k);
|
|
8286
8425
|
let plan = this.plans.get(k, kh);
|
|
@@ -8315,7 +8454,10 @@ var C2DFx = class {
|
|
|
8315
8454
|
/** url(#…) of an SVG filter for colour matrix m, shared by every plan with the same numbers (null: no page). */
|
|
8316
8455
|
svg(m) {
|
|
8317
8456
|
if (typeof document === "undefined" || !document.body) return null;
|
|
8318
|
-
const key = Array.from({ length: 20 }, (_, k) =>
|
|
8457
|
+
const key = Array.from({ length: 20 }, (_, k) => {
|
|
8458
|
+
var _a;
|
|
8459
|
+
return (_a = m[k]) != null ? _a : 0;
|
|
8460
|
+
}).join(" ");
|
|
8319
8461
|
let s = this.svgs.get(key);
|
|
8320
8462
|
if (!s) {
|
|
8321
8463
|
const ns = "http://www.w3.org/2000/svg";
|
|
@@ -8336,7 +8478,7 @@ var C2DFx = class {
|
|
|
8336
8478
|
this.attach(s = { key, id, el, used: this.t });
|
|
8337
8479
|
}
|
|
8338
8480
|
this.cur.svgs.push(s);
|
|
8339
|
-
return
|
|
8481
|
+
return "url(#".concat(s.id, ")");
|
|
8340
8482
|
}
|
|
8341
8483
|
attach(s) {
|
|
8342
8484
|
document.body.append(s.el);
|
|
@@ -8362,7 +8504,7 @@ var C2DFx = class {
|
|
|
8362
8504
|
continue;
|
|
8363
8505
|
}
|
|
8364
8506
|
const s = r.support.filters && f2.css ? f2.css(r.scale, r.maxBlur, this.svgFn) : null;
|
|
8365
|
-
if (s !== null) css += css ?
|
|
8507
|
+
if (s !== null) css += css ? " ".concat(s) : s;
|
|
8366
8508
|
else if (f2.paint2d) {
|
|
8367
8509
|
p.parts.push(css);
|
|
8368
8510
|
p.paints.push(i);
|
|
@@ -8401,44 +8543,8 @@ var C2DFx = class {
|
|
|
8401
8543
|
// src/render/webgl-filters.ts
|
|
8402
8544
|
var MAX_SHADERS = 64;
|
|
8403
8545
|
var TAPS = 17;
|
|
8404
|
-
var colorFs = (n) =>
|
|
8405
|
-
|
|
8406
|
-
uniform mat4 uM[${n}];
|
|
8407
|
-
uniform vec4 uO[${n}];
|
|
8408
|
-
uniform int uK;
|
|
8409
|
-
varying vec2 vUv;
|
|
8410
|
-
varying vec4 vColor;
|
|
8411
|
-
void main() {
|
|
8412
|
-
vec4 c = texture2D(uTexture, vUv);
|
|
8413
|
-
if (c.a > 0.0) c.rgb /= c.a;
|
|
8414
|
-
for (int i = 0; i < ${n}; i++) {
|
|
8415
|
-
if (i >= uK) break;
|
|
8416
|
-
c = clamp(uM[i] * c + uO[i], 0.0, 1.0);
|
|
8417
|
-
}
|
|
8418
|
-
c.rgb *= c.a;
|
|
8419
|
-
gl_FragColor = c * vColor;
|
|
8420
|
-
}`;
|
|
8421
|
-
var blurFs = () => `${PRECISION}
|
|
8422
|
-
uniform sampler2D uTexture;
|
|
8423
|
-
uniform vec2 uDir;
|
|
8424
|
-
uniform vec2 uOff;
|
|
8425
|
-
uniform vec2 uTaps[${TAPS}];
|
|
8426
|
-
uniform int uN;
|
|
8427
|
-
uniform float uMode;
|
|
8428
|
-
uniform vec4 uShadow;
|
|
8429
|
-
varying vec2 vUv;
|
|
8430
|
-
varying vec4 vColor;
|
|
8431
|
-
void main() {
|
|
8432
|
-
vec2 p = vUv + uOff;
|
|
8433
|
-
vec4 c = texture2D(uTexture, p) * uTaps[0].y;
|
|
8434
|
-
for (int i = 1; i < ${TAPS}; i++) {
|
|
8435
|
-
if (i >= uN) break;
|
|
8436
|
-
vec2 d = uDir * uTaps[i].x;
|
|
8437
|
-
c += (texture2D(uTexture, p + d) + texture2D(uTexture, p - d)) * uTaps[i].y;
|
|
8438
|
-
}
|
|
8439
|
-
if (uMode > 0.5) c = uShadow * c.a;
|
|
8440
|
-
gl_FragColor = c * vColor;
|
|
8441
|
-
}`;
|
|
8546
|
+
var colorFs = (n) => "".concat(PRECISION, "\nuniform sampler2D uTexture;\nuniform mat4 uM[").concat(n, "];\nuniform vec4 uO[").concat(n, "];\nuniform int uK;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvoid main() {\n vec4 c = texture2D(uTexture, vUv);\n if (c.a > 0.0) c.rgb /= c.a;\n for (int i = 0; i < ").concat(n, "; i++) {\n if (i >= uK) break;\n c = clamp(uM[i] * c + uO[i], 0.0, 1.0);\n }\n c.rgb *= c.a;\n gl_FragColor = c * vColor;\n}");
|
|
8547
|
+
var blurFs = () => "".concat(PRECISION, "\nuniform sampler2D uTexture;\nuniform vec2 uDir;\nuniform vec2 uOff;\nuniform vec2 uTaps[").concat(TAPS, "];\nuniform int uN;\nuniform float uMode;\nuniform vec4 uShadow;\nvarying vec2 vUv;\nvarying vec4 vColor;\nvoid main() {\n vec2 p = vUv + uOff;\n vec4 c = texture2D(uTexture, p) * uTaps[0].y;\n for (int i = 1; i < ").concat(TAPS, "; i++) {\n if (i >= uN) break;\n vec2 d = uDir * uTaps[i].x;\n c += (texture2D(uTexture, p + d) + texture2D(uTexture, p - d)) * uTaps[i].y;\n }\n if (uMode > 0.5) c = uShadow * c.a;\n gl_FragColor = c * vColor;\n}");
|
|
8442
8548
|
function composeInto(acc, m, tmp2 = new Float32Array(20)) {
|
|
8443
8549
|
for (let r = 0; r < 4; r++) {
|
|
8444
8550
|
for (let c = 0; c < 5; c++) {
|
|
@@ -8482,9 +8588,10 @@ var GLFx = class {
|
|
|
8482
8588
|
this.o4 = new Float32Array(4 * this.colorN);
|
|
8483
8589
|
}
|
|
8484
8590
|
check(src) {
|
|
8591
|
+
var _a;
|
|
8485
8592
|
if (this.r.lost) return null;
|
|
8486
8593
|
this.userProg(src, false);
|
|
8487
|
-
return this.userErr.get(src)
|
|
8594
|
+
return (_a = this.userErr.get(src)) != null ? _a : null;
|
|
8488
8595
|
}
|
|
8489
8596
|
destroy() {
|
|
8490
8597
|
const gl = this.r.gl;
|
|
@@ -8522,19 +8629,19 @@ var GLFx = class {
|
|
|
8522
8629
|
p = null;
|
|
8523
8630
|
const msg = e2.message;
|
|
8524
8631
|
this.userErr.set(src, msg);
|
|
8525
|
-
if (log) console.error(
|
|
8526
|
-
${msg}`);
|
|
8632
|
+
if (log) console.error("[engine] a shader filter does not compile: it is skipped.\n".concat(msg));
|
|
8527
8633
|
}
|
|
8528
8634
|
user.set(src, { p, t: ++this.uses });
|
|
8529
8635
|
return p;
|
|
8530
8636
|
}
|
|
8531
8637
|
/** Filter scratch target `slot` at 1/f of the canvas's size, made on demand. */
|
|
8532
8638
|
scratch(f2, slot) {
|
|
8639
|
+
var _a;
|
|
8533
8640
|
const r = this.r;
|
|
8534
8641
|
const w2 = Math.ceil(r.canvas.width / f2);
|
|
8535
8642
|
const h = Math.ceil(r.canvas.height / f2);
|
|
8536
8643
|
const k = f2 * 8 + slot;
|
|
8537
|
-
let T2 = this.scratchT.get(k)
|
|
8644
|
+
let T2 = (_a = this.scratchT.get(k)) != null ? _a : null;
|
|
8538
8645
|
if (T2 && (T2.w !== w2 || T2.h !== h)) {
|
|
8539
8646
|
r.drop(T2);
|
|
8540
8647
|
T2 = null;
|
|
@@ -8577,14 +8684,16 @@ ${msg}`);
|
|
|
8577
8684
|
}
|
|
8578
8685
|
/** A filter program, made on first use. */
|
|
8579
8686
|
post(which) {
|
|
8580
|
-
|
|
8581
|
-
return this.
|
|
8687
|
+
var _a, _b;
|
|
8688
|
+
if (which === "color") return (_a = this.colorProg) != null ? _a : this.colorProg = this.r.build(colorFs(this.colorN));
|
|
8689
|
+
return (_b = this.blurProg) != null ? _b : this.blurProg = this.r.build(blurFs());
|
|
8582
8690
|
}
|
|
8583
8691
|
/** Bilinear filtering on a layer texture while a blur reads it between its texels (layers are NEAREST). */
|
|
8584
8692
|
linear(t, on) {
|
|
8693
|
+
var _a;
|
|
8585
8694
|
const r = this.r;
|
|
8586
8695
|
const gl = r.gl;
|
|
8587
|
-
r.bindTex(r.layerTex.get(t)
|
|
8696
|
+
r.bindTex((_a = r.layerTex.get(t)) != null ? _a : null, 0);
|
|
8588
8697
|
const f2 = on ? gl.LINEAR : gl.NEAREST;
|
|
8589
8698
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, f2);
|
|
8590
8699
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, f2);
|
|
@@ -8665,7 +8774,7 @@ ${msg}`);
|
|
|
8665
8774
|
const y = this.scratch(1, 2);
|
|
8666
8775
|
if (!y) break;
|
|
8667
8776
|
this.blur(src, idx < 0, Math.max(Math.min(sh.blur, maxBlur), 0) * scale, y, 1, sh);
|
|
8668
|
-
const into = out
|
|
8777
|
+
const into = out != null ? out : alpha < 1 ? this.scratch(1, o) : null;
|
|
8669
8778
|
if (into) {
|
|
8670
8779
|
this.pass(r.main, y.tex, 1, into);
|
|
8671
8780
|
this.pass(r.main, src, 1, into, true);
|
|
@@ -8825,7 +8934,7 @@ var Brightness = class extends Amount {
|
|
|
8825
8934
|
linear(m, pos(this.amount), 0);
|
|
8826
8935
|
}
|
|
8827
8936
|
css() {
|
|
8828
|
-
return
|
|
8937
|
+
return "brightness(".concat(pos(this.amount), ")");
|
|
8829
8938
|
}
|
|
8830
8939
|
};
|
|
8831
8940
|
var Contrast = class extends Amount {
|
|
@@ -8834,7 +8943,7 @@ var Contrast = class extends Amount {
|
|
|
8834
8943
|
linear(m, v, 0.5 - 0.5 * v);
|
|
8835
8944
|
}
|
|
8836
8945
|
css() {
|
|
8837
|
-
return
|
|
8946
|
+
return "contrast(".concat(pos(this.amount), ")");
|
|
8838
8947
|
}
|
|
8839
8948
|
};
|
|
8840
8949
|
var Invert = class extends Amount {
|
|
@@ -8843,7 +8952,7 @@ var Invert = class extends Amount {
|
|
|
8843
8952
|
linear(m, 1 - 2 * a, a);
|
|
8844
8953
|
}
|
|
8845
8954
|
css() {
|
|
8846
|
-
return
|
|
8955
|
+
return "invert(".concat(clamp013(this.amount), ")");
|
|
8847
8956
|
}
|
|
8848
8957
|
};
|
|
8849
8958
|
var Saturate = class extends Amount {
|
|
@@ -8861,7 +8970,7 @@ var Saturate = class extends Amount {
|
|
|
8861
8970
|
rgb3(m, m9);
|
|
8862
8971
|
}
|
|
8863
8972
|
css() {
|
|
8864
|
-
return
|
|
8973
|
+
return "saturate(".concat(pos(this.amount), ")");
|
|
8865
8974
|
}
|
|
8866
8975
|
};
|
|
8867
8976
|
var Grayscale = class extends Amount {
|
|
@@ -8879,7 +8988,7 @@ var Grayscale = class extends Amount {
|
|
|
8879
8988
|
rgb3(m, m9);
|
|
8880
8989
|
}
|
|
8881
8990
|
css() {
|
|
8882
|
-
return
|
|
8991
|
+
return "grayscale(".concat(clamp013(this.amount), ")");
|
|
8883
8992
|
}
|
|
8884
8993
|
};
|
|
8885
8994
|
var Sepia = class extends Amount {
|
|
@@ -8897,7 +9006,7 @@ var Sepia = class extends Amount {
|
|
|
8897
9006
|
rgb3(m, m9);
|
|
8898
9007
|
}
|
|
8899
9008
|
css() {
|
|
8900
|
-
return
|
|
9009
|
+
return "sepia(".concat(clamp013(this.amount), ")");
|
|
8901
9010
|
}
|
|
8902
9011
|
};
|
|
8903
9012
|
var HueRotate = class extends Amount {
|
|
@@ -8923,7 +9032,7 @@ var HueRotate = class extends Amount {
|
|
|
8923
9032
|
rgb3(m, m9);
|
|
8924
9033
|
}
|
|
8925
9034
|
css() {
|
|
8926
|
-
return
|
|
9035
|
+
return "hue-rotate(".concat(this.amount, "deg)");
|
|
8927
9036
|
}
|
|
8928
9037
|
};
|
|
8929
9038
|
var Tint = class extends Amount {
|
|
@@ -8973,14 +9082,16 @@ var ColorMatrix = class extends Base {
|
|
|
8973
9082
|
super();
|
|
8974
9083
|
__publicField(this, "kind", F_COLOR);
|
|
8975
9084
|
__publicField(this, "values");
|
|
8976
|
-
if (m.length !== 20) throw new Error(
|
|
9085
|
+
if (m.length !== 20) throw new Error("colorMatrix: 20 numbers expected (4 rows of 5), got ".concat(m.length));
|
|
8977
9086
|
this.values = Array.from(m);
|
|
8978
9087
|
}
|
|
8979
9088
|
toMatrix(m) {
|
|
8980
|
-
|
|
9089
|
+
var _a;
|
|
9090
|
+
for (let i = 0; i < 20; i++) m[i] = (_a = this.values[i]) != null ? _a : 0;
|
|
8981
9091
|
}
|
|
8982
9092
|
params(o, i) {
|
|
8983
|
-
|
|
9093
|
+
var _a;
|
|
9094
|
+
for (let k = 0; k < 20; k++) o[i + k] = (_a = this.values[k]) != null ? _a : 0;
|
|
8984
9095
|
return i + 20;
|
|
8985
9096
|
}
|
|
8986
9097
|
/**
|
|
@@ -9005,7 +9116,7 @@ var Blur = class extends Base {
|
|
|
9005
9116
|
return 3 * Math.min(pos(this.radius), max);
|
|
9006
9117
|
}
|
|
9007
9118
|
css(scale, max) {
|
|
9008
|
-
return
|
|
9119
|
+
return "blur(".concat(Math.min(pos(this.radius), max) * scale, "px)");
|
|
9009
9120
|
}
|
|
9010
9121
|
};
|
|
9011
9122
|
var DropShadow = class extends Base {
|
|
@@ -9045,40 +9156,22 @@ var DropShadow = class extends Base {
|
|
|
9045
9156
|
return 3 * Math.min(pos(this.blur), max) + Math.max(Math.abs(this.dx), Math.abs(this.dy));
|
|
9046
9157
|
}
|
|
9047
9158
|
css(scale, max) {
|
|
9048
|
-
return
|
|
9159
|
+
return "drop-shadow(".concat(this.dx * scale, "px ").concat(this.dy * scale, "px ").concat(2 * Math.min(pos(this.blur), max) * scale, "px ").concat(cssColor(this.rgb, this.opacity), ")");
|
|
9049
9160
|
}
|
|
9050
9161
|
};
|
|
9051
|
-
var HEADER =
|
|
9052
|
-
|
|
9053
|
-
#else
|
|
9054
|
-
precision mediump float;
|
|
9055
|
-
#endif
|
|
9056
|
-
uniform sampler2D uTexture;
|
|
9057
|
-
uniform vec2 uResolution;
|
|
9058
|
-
uniform float uTime;
|
|
9059
|
-
uniform vec4 uRect;
|
|
9060
|
-
varying vec2 vUv;
|
|
9061
|
-
varying vec4 vColor;
|
|
9062
|
-
#define main fabiUserMain
|
|
9063
|
-
#line 1
|
|
9064
|
-
`;
|
|
9065
|
-
var shaderSource = (fragment2) => `${HEADER}${fragment2}
|
|
9066
|
-
#undef main
|
|
9067
|
-
void main() {
|
|
9068
|
-
fabiUserMain();
|
|
9069
|
-
gl_FragColor *= vColor.a;
|
|
9070
|
-
}
|
|
9071
|
-
`;
|
|
9162
|
+
var HEADER = "#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nuniform sampler2D uTexture;\nuniform vec2 uResolution;\nuniform float uTime;\nuniform vec4 uRect;\nvarying vec2 vUv;\nvarying vec4 vColor;\n#define main fabiUserMain\n#line 1\n";
|
|
9163
|
+
var shaderSource = (fragment2) => "".concat(HEADER).concat(fragment2, "\n#undef main\nvoid main() {\n fabiUserMain();\n gl_FragColor *= vColor.a;\n}\n");
|
|
9072
9164
|
var Shader = class extends Base {
|
|
9073
9165
|
constructor(o) {
|
|
9166
|
+
var _a, _b;
|
|
9074
9167
|
super();
|
|
9075
9168
|
__publicField(this, "kind", F_SHADER);
|
|
9076
9169
|
__publicField(this, "source");
|
|
9077
9170
|
__publicField(this, "uniforms", {});
|
|
9078
9171
|
__publicField(this, "padding");
|
|
9079
9172
|
this.source = shaderSource(o.fragment);
|
|
9080
|
-
this.padding = o.padding
|
|
9081
|
-
for (const k in o.uniforms
|
|
9173
|
+
this.padding = (_a = o.padding) != null ? _a : 0;
|
|
9174
|
+
for (const k in (_b = o.uniforms) != null ? _b : {}) {
|
|
9082
9175
|
const v = o.uniforms[k];
|
|
9083
9176
|
this.uniforms[k] = typeof v === "number" ? v : Float32Array.from(v);
|
|
9084
9177
|
}
|
|
@@ -9099,10 +9192,10 @@ var colorMatrix = (m) => new ColorMatrix(m);
|
|
|
9099
9192
|
var blur = (radius) => new Blur(radius);
|
|
9100
9193
|
var dropShadow = (dx, dy, blur2, color = "rgba(0,0,0,0.5)") => new DropShadow(dx, dy, blur2, color);
|
|
9101
9194
|
function shader(o) {
|
|
9195
|
+
var _a, _b;
|
|
9102
9196
|
const f2 = new Shader(o);
|
|
9103
|
-
const err = fx.live
|
|
9104
|
-
if (err) throw new Error(
|
|
9105
|
-
${err}`);
|
|
9197
|
+
const err = (_b = (_a = fx.live) == null ? void 0 : _a.filters()) == null ? void 0 : _b.check(f2.source);
|
|
9198
|
+
if (err) throw new Error("shader(): the fragment does not compile:\n".concat(err));
|
|
9106
9199
|
return f2;
|
|
9107
9200
|
}
|
|
9108
9201
|
|
|
@@ -9147,10 +9240,10 @@ function restore(n, s) {
|
|
|
9147
9240
|
}
|
|
9148
9241
|
var warned3 = null;
|
|
9149
9242
|
var warnOnce2 = (n, msg) => {
|
|
9150
|
-
warned3
|
|
9243
|
+
warned3 != null ? warned3 : warned3 = /* @__PURE__ */ new WeakSet();
|
|
9151
9244
|
if (warned3.has(n)) return;
|
|
9152
9245
|
warned3.add(n);
|
|
9153
|
-
console.warn(
|
|
9246
|
+
console.warn("[engine] ".concat(msg));
|
|
9154
9247
|
};
|
|
9155
9248
|
var NodePool = class {
|
|
9156
9249
|
/** Use nodePool(factory, options). */
|
|
@@ -9202,18 +9295,19 @@ var NodePool = class {
|
|
|
9202
9295
|
* destroyed instead. Releasing a node twice, or one of another pool, does nothing (and says so once).
|
|
9203
9296
|
*/
|
|
9204
9297
|
release(node) {
|
|
9298
|
+
var _a, _b, _c;
|
|
9205
9299
|
const s = this.states.get(node);
|
|
9206
|
-
if (!s || node.destroyed) return true ? warnOnce2(node,
|
|
9300
|
+
if (!s || node.destroyed) return true ? warnOnce2(node, "nodePool.release(): ".concat(node.destroyed ? "a destroyed node" : "a node this pool did not make", ": ignored")) : void 0;
|
|
9207
9301
|
if (node._free) return true ? warnOnce2(node, "nodePool.release(): this node was already released: ignored") : void 0;
|
|
9208
9302
|
if (this.opts.max !== void 0 && this.free.length >= this.opts.max) return node.destroy();
|
|
9209
|
-
node.parent
|
|
9303
|
+
(_a = node.parent) == null ? void 0 : _a.remove(node);
|
|
9210
9304
|
node.kernel.tweens.stopAll(node);
|
|
9211
9305
|
this.stats.live--;
|
|
9212
9306
|
restore(node, s);
|
|
9213
9307
|
if (node instanceof AnimatedSprite) node.stop();
|
|
9214
9308
|
node.visible = false;
|
|
9215
9309
|
node._free = true;
|
|
9216
|
-
this.opts.reset
|
|
9310
|
+
(_c = (_b = this.opts).reset) == null ? void 0 : _c.call(_b, node);
|
|
9217
9311
|
this.free.push(node);
|
|
9218
9312
|
this.stats.free++;
|
|
9219
9313
|
if (true) watch(node);
|