@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.
@@ -1,4 +1,4 @@
1
- /*! @fabiplay/engine 0.9.0 (lite: load fabi-play.js first) | Fabi Play Kit License | https://docs.fabiplay.app */
1
+ /*! @fabiplay/engine 0.9.1 (lite: load fabi-play.js first) | 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((resolve, 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 ? resolve(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 = {
@@ -120,7 +172,10 @@ function aimPoint(who, side, opts = {}) {
120
172
  const body = Array.isArray(who) ? who : who.body;
121
173
  if (!Array.isArray(body)) return null;
122
174
  const w2 = side === "left" ? P.leftWrist : P.rightWrist;
123
- const at = (i) => isNumber(body[i * 3]) && isNumber(body[i * 3 + 1]) && (body[i * 3 + 2] ?? 0) >= AIM_VISIBLE ? i : -1;
175
+ const at = (i) => {
176
+ var _a2;
177
+ return isNumber(body[i * 3]) && isNumber(body[i * 3 + 1]) && ((_a2 = body[i * 3 + 2]) != null ? _a2 : 0) >= AIM_VISIBLE ? i : -1;
178
+ };
124
179
  if (at(w2) < 0) return null;
125
180
  const wx = body[w2 * 3];
126
181
  const wy = body[w2 * 3 + 1];
@@ -188,7 +243,7 @@ var POSE_HEADER = 12;
188
243
  var POSE_BODY_BYTES = LANDMARKS * 4;
189
244
  var poseBytes = (bodies) => POSE_HEADER + bodies * POSE_BODY_BYTES;
190
245
  var POSE_MAX_BYTES = poseBytes(MAX_PLAYERS);
191
- var legacyStorageKey = (key) => key.startsWith("fabi-play.") ? `fablee-play.${key.slice("fabi-play.".length)}` : null;
246
+ var legacyStorageKey = (key) => key.startsWith("fabi-play.") ? "fablee-play.".concat(key.slice("fabi-play.".length)) : null;
192
247
  function migrateStorageKey(store, newKey, oldKey = legacyStorageKey(newKey)) {
193
248
  if (!store || !oldKey) return;
194
249
  try {
@@ -196,12 +251,13 @@ function migrateStorageKey(store, newKey, oldKey = legacyStorageKey(newKey)) {
196
251
  if (old === null) return;
197
252
  if (store.getItem(newKey) === null) store.setItem(newKey, old);
198
253
  store.removeItem(oldKey);
199
- } catch {
254
+ } catch (e) {
200
255
  }
201
256
  }
202
257
 
203
258
  // src/lite/avatars.ts
204
- var shared = globalThis.FabiPlay?.avatars;
259
+ var _a;
260
+ var shared = (_a = __fabiGlobalThis.FabiPlay) == null ? void 0 : _a.avatars;
205
261
  if (!shared) throw new Error("[engine] fabi-play-engine.lite.js needs fabi-play.js (with FabiPlay.avatars) loaded before it");
206
262
  var { avatarById, avatarShapes, BAND_BODY, DEFAULT_AVATAR, drawShapes, frameOf, iconShapes } = shared;
207
263
 
@@ -245,6 +301,7 @@ function applyInverse(m, x, y) {
245
301
  var named = { white: 16777215, black: 0, red: 16711680, transparent: 0 };
246
302
  var cache = /* @__PURE__ */ new Map();
247
303
  function parseColor(c) {
304
+ var _a2, _b;
248
305
  if (typeof c === "number") return [c & 16777215, 1];
249
306
  const hit = cache.get(c);
250
307
  if (hit) return hit;
@@ -256,7 +313,7 @@ function parseColor(c) {
256
313
  const v = parseInt(full.slice(0, 6), 16);
257
314
  if (Number.isFinite(v)) out = [v, full.length === 8 ? parseInt(full.slice(6, 8), 16) / 255 : 1];
258
315
  } else if (s.startsWith("rgb")) {
259
- const n = s.match(/-?\d*\.?\d+%?/g)?.map((t) => t.endsWith("%") ? parseFloat(t) / 100 * 255 : parseFloat(t)) ?? [];
316
+ const n = (_b = (_a2 = s.match(/-?\d*\.?\d+%?/g)) == null ? void 0 : _a2.map((t) => t.endsWith("%") ? parseFloat(t) / 100 * 255 : parseFloat(t))) != null ? _b : [];
260
317
  const [r = 255, g = 255, b = 255] = n;
261
318
  const a = n[3] === void 0 ? 1 : s.match(/,\s*[\d.]+%\s*\)$/) ? n[3] / 255 : n[3];
262
319
  out = [(clamp255(r) << 16 | clamp255(g) << 8 | clamp255(b)) >>> 0, Math.min(Math.max(a, 0), 1)];
@@ -283,7 +340,7 @@ function packColor(rgb, alpha, additive = false) {
283
340
  const A = additive ? 0 : a * 255;
284
341
  return (Math.round(A) << 24 | Math.round(b) << 16 | Math.round(g) << 8 | Math.round(r)) >>> 0;
285
342
  }
286
- var cssColor = (rgb, alpha = 1) => `rgba(${rgb >> 16 & 255},${rgb >> 8 & 255},${rgb & 255},${alpha})`;
343
+ var cssColor = (rgb, alpha = 1) => "rgba(".concat(rgb >> 16 & 255, ",").concat(rgb >> 8 & 255, ",").concat(rgb & 255, ",").concat(alpha, ")");
287
344
  function mulColor(x, y) {
288
345
  if (x === 16777215) return y;
289
346
  if (y === 16777215) return x;
@@ -295,13 +352,13 @@ var EASE = {
295
352
  quadIn: (t) => t * t,
296
353
  quadOut: (t) => t * (2 - t),
297
354
  quadInOut: (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t,
298
- cubicOut: (t) => 1 - (1 - t) ** 3,
355
+ cubicOut: (t) => 1 - __pow(1 - t, 3),
299
356
  sineInOut: (t) => -(Math.cos(Math.PI * t) - 1) / 2,
300
357
  backOut: (t) => {
301
358
  const c = 1.70158;
302
- return 1 + (c + 1) * (t - 1) ** 3 + c * (t - 1) ** 2;
359
+ return 1 + (c + 1) * __pow(t - 1, 3) + c * __pow(t - 1, 2);
303
360
  },
304
- elasticOut: (t) => t === 0 || t === 1 ? t : 2 ** (-10 * t) * Math.sin((t * 10 - 0.75) * (2 * Math.PI / 3)) + 1,
361
+ elasticOut: (t) => t === 0 || t === 1 ? t : __pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * (2 * Math.PI / 3)) + 1,
305
362
  bounceOut: (t) => {
306
363
  const n = 7.5625;
307
364
  const d = 2.75;
@@ -327,21 +384,22 @@ var WATCHED = ["x", "y", "scale", "scaleX", "scaleY", "rotation", "alpha", "visi
327
384
  var warned = /* @__PURE__ */ new WeakSet();
328
385
  var trapped = /* @__PURE__ */ new WeakMap();
329
386
  function describe(n) {
387
+ var _a2;
330
388
  const o = n;
331
- const kind = n.constructor?.name || "Node";
332
- if (typeof o.text === "string") return `${kind} '${o.text.length > 24 ? `${o.text.slice(0, 24)}\u2026` : o.text}'`;
333
- if (o.spec && typeof o.spec.type === "string") return `${kind} (${o.spec.type})`;
334
- if (o.frameName) return `${kind} '${o.frameName}'`;
389
+ const kind = ((_a2 = n.constructor) == null ? void 0 : _a2.name) || "Node";
390
+ if (typeof o.text === "string") return "".concat(kind, " '").concat(o.text.length > 24 ? "".concat(o.text.slice(0, 24), "\u2026") : o.text, "'");
391
+ if (o.spec && typeof o.spec.type === "string") return "".concat(kind, " (").concat(o.spec.type, ")");
392
+ if (o.frameName) return "".concat(kind, " '").concat(o.frameName, "'");
335
393
  return kind;
336
394
  }
337
395
  function warnUse(n, what) {
396
+ var _a2, _b;
338
397
  if (warned.has(n)) return;
339
398
  warned.add(n);
340
399
  const w2 = n;
341
400
  const after = w2.destroyed ? "destroy()" : "release() to its node pool";
342
- const where = new Error().stack?.split("\n").slice(3, 6).join("\n") ?? "";
343
- console.warn(`[engine] ${describe(n)} used after ${after}: ${what}. It is not on the stage${w2._free ? ", and the pool gives it to the next get()" : ""}: drop your reference to it.
344
- ${where}`);
401
+ const where = (_b = (_a2 = new Error().stack) == null ? void 0 : _a2.split("\n").slice(3, 6).join("\n")) != null ? _b : "";
402
+ 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));
345
403
  }
346
404
  function watch(n) {
347
405
  if (trapped.has(n) || warned.has(n)) return;
@@ -356,7 +414,7 @@ function watch(n) {
356
414
  enumerable: isOwn,
357
415
  get: () => isOwn ? own.get(k) : Reflect.get(Object.getPrototypeOf(n), k, n),
358
416
  set: (v) => {
359
- warnUse(n, `setting ${k}`);
417
+ warnUse(n, "setting ".concat(k));
360
418
  unwatch(n);
361
419
  n[k] = v;
362
420
  }
@@ -740,7 +798,8 @@ var Node = class {
740
798
  }
741
799
  /** Free for the game: speed, state, anything (made on first use). */
742
800
  get data() {
743
- return this._data ?? (this._data = {});
801
+ var _a2;
802
+ return (_a2 = this._data) != null ? _a2 : this._data = {};
744
803
  }
745
804
  set data(v) {
746
805
  this._data = v;
@@ -799,6 +858,7 @@ var Node = class {
799
858
  }
800
859
  /** Removes the node: invisible at once (its parent null), out of its group's children at the end of the frame. Its tweens stop. */
801
860
  destroy() {
861
+ var _a2;
802
862
  if (this.destroyed) return;
803
863
  if (this._free) unwatch(this);
804
864
  this.visible = false;
@@ -809,7 +869,7 @@ var Node = class {
809
869
  release(this._i, this);
810
870
  untrack(this);
811
871
  this.kernel.tweens.stopAll(this);
812
- this._pool?.forget(this);
872
+ (_a2 = this._pool) == null ? void 0 : _a2.forget(this);
813
873
  if (true) watch(this);
814
874
  }
815
875
  /** world, computed now from the parents (for hit tests between draws). */
@@ -1059,7 +1119,7 @@ var Sprite = class extends Node {
1059
1119
  /** The name the frame came from: baked frames are looked up again after the atlas was wiped. */
1060
1120
  __publicField(this, "frameName", null);
1061
1121
  if (frame) this.frame = frame;
1062
- if (props?.anchor === void 0) this.useFrameAnchor();
1122
+ if ((props == null ? void 0 : props.anchor) === void 0) this.useFrameAnchor();
1063
1123
  if (props) this.set(props);
1064
1124
  }
1065
1125
  /** What it shows: set a frame or the name of a loaded or baked one (an animation swaps it every few frames). */
@@ -1078,24 +1138,28 @@ var Sprite = class extends Node {
1078
1138
  }
1079
1139
  /** The content size the frame has, stage units (without its margin; untrimmed). */
1080
1140
  get naturalWidth() {
1141
+ var _a2;
1081
1142
  const f = this.frameNow();
1082
- return f ? (f.sw ?? f.w) / f.scale - f.margin * 2 : 0;
1143
+ return f ? ((_a2 = f.sw) != null ? _a2 : f.w) / f.scale - f.margin * 2 : 0;
1083
1144
  }
1084
1145
  /** The content height the frame has, stage units (without its margin; untrimmed). */
1085
1146
  get naturalHeight() {
1147
+ var _a2;
1086
1148
  const f = this.frameNow();
1087
- return f ? (f.sh ?? f.h) / f.scale - f.margin * 2 : 0;
1149
+ return f ? ((_a2 = f.sh) != null ? _a2 : f.h) / f.scale - f.margin * 2 : 0;
1088
1150
  }
1089
1151
  /** Local width, stage units: the frame's own (naturalWidth) until set; setting it stretches the sprite. */
1090
1152
  get width() {
1091
- return this._w ?? this.naturalWidth;
1153
+ var _a2;
1154
+ return (_a2 = this._w) != null ? _a2 : this.naturalWidth;
1092
1155
  }
1093
1156
  set width(v) {
1094
1157
  this._w = v;
1095
1158
  }
1096
1159
  /** Local height, stage units: the frame's own (naturalHeight) until set; setting it stretches the sprite. */
1097
1160
  get height() {
1098
- return this._h ?? this.naturalHeight;
1161
+ var _a2;
1162
+ return (_a2 = this._h) != null ? _a2 : this.naturalHeight;
1099
1163
  }
1100
1164
  set height(v) {
1101
1165
  this._h = v;
@@ -1105,8 +1169,9 @@ var Sprite = class extends Node {
1105
1169
  * (a number returned through a getter on several classes is boxed on every call).
1106
1170
  */
1107
1171
  sizeQ(f) {
1108
- frameQ[0] = this._w ?? (f.sw ?? f.w) / f.scale - f.margin * 2;
1109
- frameQ[1] = this._h ?? (f.sh ?? f.h) / f.scale - f.margin * 2;
1172
+ var _a2, _b, _c, _d;
1173
+ frameQ[0] = (_b = this._w) != null ? _b : ((_a2 = f.sw) != null ? _a2 : f.w) / f.scale - f.margin * 2;
1174
+ frameQ[1] = (_d = this._h) != null ? _d : ((_c = f.sh) != null ? _c : f.h) / f.scale - f.margin * 2;
1110
1175
  }
1111
1176
  /** The frame to draw now (subclasses bake it on demand). */
1112
1177
  frameNow() {
@@ -1114,10 +1179,11 @@ var Sprite = class extends Node {
1114
1179
  return this._frame;
1115
1180
  }
1116
1181
  useFrameAnchor() {
1182
+ var _a2, _b;
1117
1183
  const f = this._frame;
1118
1184
  if (!f) return;
1119
- const w2 = (f.sw ?? f.w) / f.scale - f.margin * 2;
1120
- const h = (f.sh ?? f.h) / f.scale - f.margin * 2;
1185
+ const w2 = ((_a2 = f.sw) != null ? _a2 : f.w) / f.scale - f.margin * 2;
1186
+ const h = ((_b = f.sh) != null ? _b : f.h) / f.scale - f.margin * 2;
1121
1187
  this.anchorX = w2 > 0 ? (f.ox - f.margin) / w2 : 0;
1122
1188
  this.anchorY = h > 0 ? (f.oy - f.margin) / h : 0;
1123
1189
  }
@@ -1164,6 +1230,7 @@ function spans(out, size, a, b, px, scale) {
1164
1230
  }
1165
1231
  var frameQ = new Float64Array(5);
1166
1232
  function drawFrameQ(ctx, f, m, slice, tint2, blend) {
1233
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1167
1234
  const q = frameQ;
1168
1235
  const w2 = q[0];
1169
1236
  const h = q[1];
@@ -1171,14 +1238,14 @@ function drawFrameQ(ctx, f, m, slice, tint2, blend) {
1171
1238
  const ay = q[3];
1172
1239
  const alpha = q[4];
1173
1240
  const tex = ctx.tex(f.surface);
1174
- const s = slice === 0 ? f.slice ?? 0 : slice;
1241
+ const s = slice === 0 ? (_a2 = f.slice) != null ? _a2 : 0 : slice;
1175
1242
  if (s === 0) {
1176
- const nw = (f.sw ?? f.w) / f.scale - f.margin * 2;
1177
- const nh = (f.sh ?? f.h) / f.scale - f.margin * 2;
1243
+ const nw = ((_b = f.sw) != null ? _b : f.w) / f.scale - f.margin * 2;
1244
+ const nh = ((_c = f.sh) != null ? _c : f.h) / f.scale - f.margin * 2;
1178
1245
  const kx = nw > 0 ? w2 / nw : 1;
1179
1246
  const ky = nh > 0 ? h / nh : 1;
1180
- const x02 = -ax * w2 + ((f.tx ?? 0) / f.scale - f.margin) * kx;
1181
- const y02 = -ay * h + ((f.ty ?? 0) / f.scale - f.margin) * ky;
1247
+ const x02 = -ax * w2 + (((_d = f.tx) != null ? _d : 0) / f.scale - f.margin) * kx;
1248
+ const y02 = -ay * h + (((_e = f.ty) != null ? _e : 0) / f.scale - f.margin) * ky;
1182
1249
  translated(m, x02, y02);
1183
1250
  QUAD[0] = f.w / f.scale * kx;
1184
1251
  QUAD[1] = f.h / f.scale * ky;
@@ -1186,17 +1253,17 @@ function drawFrameQ(ctx, f, m, slice, tint2, blend) {
1186
1253
  ctx.r.quadQ(tex, f, tmp, tint2, blend);
1187
1254
  return;
1188
1255
  }
1189
- const tx = f.tx ?? 0;
1190
- const ty = f.ty ?? 0;
1191
- const rx = (f.sw ?? f.w) - f.w - tx;
1192
- const by = (f.sh ?? f.h) - f.h - ty;
1256
+ const tx = (_f = f.tx) != null ? _f : 0;
1257
+ const ty = (_g = f.ty) != null ? _g : 0;
1258
+ const rx = ((_h = f.sw) != null ? _h : f.w) - f.w - tx;
1259
+ const by = ((_i = f.sh) != null ? _i : f.h) - f.h - ty;
1193
1260
  const x0 = -ax * w2 - f.margin + tx / f.scale;
1194
1261
  const y0 = -ay * h - f.margin + ty / f.scale;
1195
1262
  spans(cols, w2 + f.margin * 2 - (tx + rx) / f.scale, (typeof s === "number" ? s : s[3]) - tx, (typeof s === "number" ? s : s[1]) - rx, f.w, f.scale);
1196
1263
  spans(rows, h + f.margin * 2 - (ty + by) / f.scale, (typeof s === "number" ? s : s[0]) - ty, (typeof s === "number" ? s : s[2]) - by, f.h, f.scale);
1197
1264
  translated(m, x0, y0);
1198
1265
  QUAD[2] = alpha;
1199
- if (ctx.r.nineQ?.(tex, f, cols, rows, tmp, tint2, blend)) return;
1266
+ if ((_k = (_j = ctx.r).nineQ) == null ? void 0 : _k.call(_j, tex, f, cols, rows, tmp, tint2, blend)) return;
1200
1267
  for (let j = 0; j < 12; j += 4) {
1201
1268
  const rh = rows[j + 1];
1202
1269
  const th = rows[j + 3];
@@ -1261,20 +1328,23 @@ var Shape = class extends Sprite {
1261
1328
  return this.bake().frame;
1262
1329
  }
1263
1330
  sizeQ() {
1331
+ var _a2, _b;
1264
1332
  const b = this.bake();
1265
- frameQ[0] = this._w ?? b.w;
1266
- frameQ[1] = this._h ?? b.h;
1333
+ frameQ[0] = (_a2 = this._w) != null ? _a2 : b.w;
1334
+ frameQ[1] = (_b = this._h) != null ? _b : b.h;
1267
1335
  }
1268
1336
  /** Local width, stage units: the shape's own until set (a roundRect is redrawn to it, others stretched). */
1269
1337
  get width() {
1270
- return this._w ?? this.bake().w;
1338
+ var _a2;
1339
+ return (_a2 = this._w) != null ? _a2 : this.bake().w;
1271
1340
  }
1272
1341
  set width(v) {
1273
1342
  this._w = v;
1274
1343
  }
1275
1344
  /** Local height, stage units: the shape's own until set. */
1276
1345
  get height() {
1277
- return this._h ?? this.bake().h;
1346
+ var _a2;
1347
+ return (_a2 = this._h) != null ? _a2 : this.bake().h;
1278
1348
  }
1279
1349
  set height(v) {
1280
1350
  this._h = v;
@@ -1284,6 +1354,7 @@ var pick = (v, d, rand) => v === void 0 ? d : typeof v === "number" ? v : v[0] +
1284
1354
  var _Particles = class _Particles extends Node {
1285
1355
  /** Use engine.particles(frame, opts). */
1286
1356
  constructor(kernel, frame, opts = {}) {
1357
+ var _a2, _b, _c, _d;
1287
1358
  super(kernel);
1288
1359
  /** The pool's size: most particles alive at once. */
1289
1360
  __publicField(this, "max");
@@ -1299,12 +1370,12 @@ var _Particles = class _Particles extends Node {
1299
1370
  /** The random source for bursts (a seeded rng in tests and replays). */
1300
1371
  __publicField(this, "random", Math.random);
1301
1372
  this.frameRef = frame;
1302
- this.max = Math.max(1, Math.floor(opts.max ?? 200));
1373
+ this.max = Math.max(1, Math.floor((_a2 = opts.max) != null ? _a2 : 200));
1303
1374
  this.f = new Float32Array(this.max * _Particles.W);
1304
1375
  this.tints = new Uint32Array(this.max);
1305
- this.blend = opts.blend ?? "normal";
1306
- this.gravity = opts.gravity ?? 0;
1307
- this.drag = opts.drag ?? 1;
1376
+ this.blend = (_b = opts.blend) != null ? _b : "normal";
1377
+ this.gravity = (_c = opts.gravity) != null ? _c : 0;
1378
+ this.drag = (_d = opts.drag) != null ? _d : 1;
1308
1379
  }
1309
1380
  /** Particles alive. */
1310
1381
  get alive() {
@@ -1317,6 +1388,7 @@ var _Particles = class _Particles extends Node {
1317
1388
  * sparks.burst(star.x, star.y, engine.tier.scale(24), { tint: hand.color, speed: [100, 300] })
1318
1389
  */
1319
1390
  burst(x, y, n, o = {}) {
1391
+ var _a2, _b, _c, _d, _e;
1320
1392
  const W = _Particles.W;
1321
1393
  const rand = this.random;
1322
1394
  const tint2 = o.tint === void 0 ? 16777215 : parseColor(o.tint)[0];
@@ -1334,10 +1406,10 @@ var _Particles = class _Particles extends Node {
1334
1406
  }
1335
1407
  i = best;
1336
1408
  } else this.count++;
1337
- const a = (o.angle ?? 0) + (o.spread === void 0 ? rand() * Math.PI * 2 : (rand() - 0.5) * o.spread);
1409
+ const a = ((_a2 = o.angle) != null ? _a2 : 0) + (o.spread === void 0 ? rand() * Math.PI * 2 : (rand() - 0.5) * o.spread);
1338
1410
  const sp = pick(o.speed, 200, rand);
1339
- const s0 = Array.isArray(o.scale) ? o.scale[0] : o.scale ?? 1;
1340
- const s1 = Array.isArray(o.scale) ? o.scale[1] : o.scale ?? 1;
1411
+ const s0 = Array.isArray(o.scale) ? o.scale[0] : (_b = o.scale) != null ? _b : 1;
1412
+ const s1 = Array.isArray(o.scale) ? o.scale[1] : (_c = o.scale) != null ? _c : 1;
1341
1413
  const p = i * W;
1342
1414
  this.f[p] = x;
1343
1415
  this.f[p + 1] = y;
@@ -1346,10 +1418,10 @@ var _Particles = class _Particles extends Node {
1346
1418
  this.f[p + 4] = 0;
1347
1419
  this.f[p + 5] = Math.max(pick(o.life, 0.8, rand), 0.01);
1348
1420
  this.f[p + 6] = rand() * Math.PI * 2;
1349
- this.f[p + 7] = (rand() - 0.5) * 2 * (o.spin ?? 0);
1421
+ this.f[p + 7] = (rand() - 0.5) * 2 * ((_d = o.spin) != null ? _d : 0);
1350
1422
  this.f[p + 8] = s0;
1351
1423
  this.f[p + 9] = s1;
1352
- this.f[p + 10] = o.alpha ?? 1;
1424
+ this.f[p + 10] = (_e = o.alpha) != null ? _e : 1;
1353
1425
  this.tints[i] = tint2;
1354
1426
  }
1355
1427
  }
@@ -1428,7 +1500,7 @@ var Particles = _Particles;
1428
1500
  var AnimatedSprite = class extends Sprite {
1429
1501
  /** Use engine.animation(frames, props). */
1430
1502
  constructor(kernel, def, props = {}) {
1431
- const { fps, loop, playing, speed, onComplete, ...rest } = props;
1503
+ const _a2 = props, { fps, loop, playing, speed, onComplete } = _a2, rest = __objRest(_a2, ["fps", "loop", "playing", "speed", "onComplete"]);
1432
1504
  if (!def.frames.length) throw new Error("[engine] an animation needs at least one frame");
1433
1505
  super(kernel, def.frames[0], rest);
1434
1506
  /** The frames, in order. */
@@ -1449,10 +1521,10 @@ var AnimatedSprite = class extends Sprite {
1449
1521
  __publicField(this, "t", 0);
1450
1522
  this.frames = def.frames;
1451
1523
  this.durations = def.durations && fps === void 0 ? def.durations : null;
1452
- this.fps = fps ?? 12;
1524
+ this.fps = fps != null ? fps : 12;
1453
1525
  this.loop = loop !== false;
1454
- this.speed = speed ?? 1;
1455
- this.onComplete = onComplete ?? null;
1526
+ this.speed = speed != null ? speed : 1;
1527
+ this.onComplete = onComplete != null ? onComplete : null;
1456
1528
  this._playing = playing !== false;
1457
1529
  if (this.speed < 0) this.show(def.frames.length - 1);
1458
1530
  }
@@ -1502,11 +1574,13 @@ var AnimatedSprite = class extends Sprite {
1502
1574
  this.frame = this.frames[i];
1503
1575
  }
1504
1576
  secondsOf(i) {
1505
- const d = this.durations?.[i];
1577
+ var _a2;
1578
+ const d = (_a2 = this.durations) == null ? void 0 : _a2[i];
1506
1579
  return d !== void 0 && d > 0 ? d : 1 / Math.max(this.fps, 1e-3);
1507
1580
  }
1508
1581
  /** Advances by dt seconds of game time (the engine calls it). */
1509
1582
  update(dt) {
1583
+ var _a2;
1510
1584
  if (!this._playing || this.destroyed || this.speed === 0) return;
1511
1585
  const n = this.frames.length;
1512
1586
  const back = this.speed < 0;
@@ -1522,7 +1596,7 @@ var AnimatedSprite = class extends Sprite {
1522
1596
  this.t = 0;
1523
1597
  this._playing = false;
1524
1598
  this.show(i);
1525
- this.onComplete?.();
1599
+ (_a2 = this.onComplete) == null ? void 0 : _a2.call(this);
1526
1600
  return;
1527
1601
  }
1528
1602
  i = back ? n - 1 : 0;
@@ -1553,7 +1627,7 @@ var ShelfPacker = class {
1553
1627
  const f = this.free[i];
1554
1628
  if (f.w >= pw && f.h >= ph && f.w * f.h <= pw * ph * 2) {
1555
1629
  this.free.splice(i, 1);
1556
- return { ...this.inner(f.x, f.y, w2, h), slot: f };
1630
+ return __spreadProps(__spreadValues({}, this.inner(f.x, f.y, w2, h)), { slot: f });
1557
1631
  }
1558
1632
  }
1559
1633
  let best = null;
@@ -1639,7 +1713,7 @@ var Atlas = class {
1639
1713
  release(f) {
1640
1714
  if (f.gen !== this.gen) return;
1641
1715
  const p = this.pages.find((pg) => pg.surface === f.surface);
1642
- p?.packer.release(f);
1716
+ p == null ? void 0 : p.packer.release(f);
1643
1717
  }
1644
1718
  /**
1645
1719
  * Bakes again into the same place, if the new size fits in it (texts that change): the frame, updated, or null
@@ -1677,7 +1751,7 @@ var Atlas = class {
1677
1751
  place = page.packer.alloc(W, H);
1678
1752
  }
1679
1753
  }
1680
- if (!place) throw new Error(`[engine] ${W}\xD7${H} does not fit an atlas page`);
1754
+ if (!place) throw new Error("[engine] ".concat(W, "\xD7").concat(H, " does not fit an atlas page"));
1681
1755
  const r = place;
1682
1756
  if (r.slot) {
1683
1757
  const s = r.slot;
@@ -1730,7 +1804,7 @@ var Atlas = class {
1730
1804
  };
1731
1805
 
1732
1806
  // src/lite/sdk.ts
1733
- var sdk = () => globalThis.FabiPlay;
1807
+ var sdk = () => __fabiGlobalThis.FabiPlay;
1734
1808
  var AvatarBook = class {
1735
1809
  constructor() {
1736
1810
  __publicField(this, "amount", 0.5);
@@ -1748,8 +1822,9 @@ var AvatarBook = class {
1748
1822
  }
1749
1823
  /** The body to draw for this player now: smoothed (amount below 1) and interpolated, as the SDK's AvatarBook. */
1750
1824
  posed(player, body, amount, interpolate = true) {
1825
+ var _a2, _b;
1751
1826
  const frame = { id: player, body };
1752
- return sdk()?.smoothedBody(frame, { smooth: amount < 1 ? amount : false, interpolate }) ?? body;
1827
+ return (_b = (_a2 = sdk()) == null ? void 0 : _a2.smoothedBody(frame, { smooth: amount < 1 ? amount : false, interpolate })) != null ? _b : body;
1753
1828
  }
1754
1829
  };
1755
1830
 
@@ -2109,8 +2184,9 @@ var Canvas2DRenderer = class extends Layered {
2109
2184
  this.updateTexture(t);
2110
2185
  }
2111
2186
  begin(clear, clearAlpha, scale) {
2187
+ var _a2;
2112
2188
  this.resetLayers(scale);
2113
- this.fxr?.tick();
2189
+ (_a2 = this.fxr) == null ? void 0 : _a2.tick();
2114
2190
  this.frame++;
2115
2191
  this.quads = 0;
2116
2192
  this.top = this.base;
@@ -2170,7 +2246,7 @@ var Canvas2DRenderer = class extends Layered {
2170
2246
  * side (sharp pieces rather than a scratch canvas that big, or a downscaled, blurred whole).
2171
2247
  */
2172
2248
  nineQ(t, r, cols2, rows2, m, tint2, blend) {
2173
- var _a, _b;
2249
+ var _a2, _b, _c;
2174
2250
  const w2 = cols2[8] + cols2[9];
2175
2251
  const h = rows2[8] + rows2[9];
2176
2252
  const pw = Math.ceil(w2 * Math.hypot(m[0], m[1]) * this.scale - 1e-6);
@@ -2178,7 +2254,7 @@ var Canvas2DRenderer = class extends Layered {
2178
2254
  if (m[1] === 0 && m[2] === 0 || pw > 4096 || ph > 4096) return false;
2179
2255
  if (!(pw > 0 && ph > 0 && QUAD[2] > 0) || this.mute) return true;
2180
2256
  let sc = this.kept(t, r, cols2, rows2, pw, ph, tint2);
2181
- const k = (sc ?? (sc = (_a = this.scratch)[_b = 13 * Math.ceil(Math.log2(pw)) + Math.ceil(Math.log2(ph))] ?? (_a[_b] = document.createElement("canvas").getContext("2d")))).canvas;
2257
+ const k = (sc != null ? sc : sc = (_c = (_a2 = this.scratch)[_b = 13 * Math.ceil(Math.log2(pw)) + Math.ceil(Math.log2(ph))]) != null ? _c : _a2[_b] = document.createElement("canvas").getContext("2d")).canvas;
2182
2258
  if (k.width < pw) k.width = pw;
2183
2259
  if (k.height < ph) k.height = ph;
2184
2260
  if (!this.hit) {
@@ -2244,7 +2320,7 @@ var Canvas2DRenderer = class extends Layered {
2244
2320
  this.dropNine(old, fits);
2245
2321
  if (fits) reuse = old.ctx;
2246
2322
  }
2247
- const ctx = reuse ?? document.createElement("canvas").getContext("2d");
2323
+ const ctx = reuse != null ? reuse : document.createElement("canvas").getContext("2d");
2248
2324
  const c = ctx.canvas;
2249
2325
  if (!reuse) {
2250
2326
  c.width = pw;
@@ -2390,9 +2466,10 @@ var Canvas2DRenderer = class extends Layered {
2390
2466
  }
2391
2467
  /** A layer's canvas over the area rx0… (pixels), under the clip: 'destination-in' for a mask, through filters. */
2392
2468
  composite(src, mask, alpha, filters) {
2469
+ var _a2;
2393
2470
  let img = src;
2394
2471
  let css = "none";
2395
- const f = filters && fx.c2d ? this.fxr ?? (this.fxr = fx.c2d(this)) : null;
2472
+ const f = filters && fx.c2d ? (_a2 = this.fxr) != null ? _a2 : this.fxr = fx.c2d(this) : null;
2396
2473
  if (f) {
2397
2474
  img = f.chain(src, filters);
2398
2475
  css = f.css;
@@ -2426,11 +2503,12 @@ var Canvas2DRenderer = class extends Layered {
2426
2503
  this.restoredListeners.push(l);
2427
2504
  }
2428
2505
  destroy() {
2506
+ var _a2;
2429
2507
  this.tinted.clear();
2430
2508
  this.dropNines();
2431
2509
  this.layers = [];
2432
2510
  this.scratch = [];
2433
- this.fxr?.destroy();
2511
+ (_a2 = this.fxr) == null ? void 0 : _a2.destroy();
2434
2512
  this.fxr = null;
2435
2513
  }
2436
2514
  };
@@ -2569,11 +2647,12 @@ function grow2(a, n) {
2569
2647
  }
2570
2648
  var parsed = /* @__PURE__ */ new Map();
2571
2649
  function pathData(d) {
2650
+ var _a2, _b;
2572
2651
  if (typeof d !== "string") return d;
2573
2652
  let out = parsed.get(d);
2574
2653
  if (out) return out;
2575
2654
  out = [];
2576
- const tokens = d.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi) ?? [];
2655
+ const tokens = (_a2 = d.match(/[MLQCZ]|-?\d*\.?\d+(?:e-?\d+)?/gi)) != null ? _a2 : [];
2577
2656
  let cmd = -1;
2578
2657
  for (let i = 0; i < tokens.length; ) {
2579
2658
  const t = tokens[i];
@@ -2590,7 +2669,7 @@ function pathData(d) {
2590
2669
  }
2591
2670
  const n = ARGS[cmd];
2592
2671
  out.push(cmd);
2593
- for (let k = 0; k < n; k++) out.push(Number(tokens[i + k] ?? 0));
2672
+ for (let k = 0; k < n; k++) out.push(Number((_b = tokens[i + k]) != null ? _b : 0));
2594
2673
  i += n;
2595
2674
  if (cmd === PATH.M) cmd = PATH.L;
2596
2675
  }
@@ -2602,9 +2681,10 @@ var flat = { subs: [], count: 0 };
2602
2681
  var fm = null;
2603
2682
  var fcur = null;
2604
2683
  function fpush(px, py) {
2684
+ var _a2;
2605
2685
  let c = fcur;
2606
2686
  if (!c) {
2607
- c = flat.subs[flat.count] ?? null;
2687
+ c = (_a2 = flat.subs[flat.count]) != null ? _a2 : null;
2608
2688
  if (!c) flat.subs.push(c = { pts: new Float64Array(64), n: 0, closed: false });
2609
2689
  c.n = 0;
2610
2690
  c.closed = false;
@@ -2898,56 +2978,10 @@ function kitCanvas() {
2898
2978
 
2899
2979
  // src/render/webgl.ts
2900
2980
  var MAX_SLOTS = 8;
2901
- var PRECISION = `
2902
- #ifdef GL_FRAGMENT_PRECISION_HIGH
2903
- precision highp float;
2904
- #else
2905
- precision mediump float;
2906
- #endif
2907
- `;
2908
- var fragment = (slots) => `${PRECISION}
2909
- uniform sampler2D uTex[${slots}];
2910
- varying vec2 vUv;
2911
- varying vec4 vColor;
2912
- varying float vSlot;
2913
- void main() {
2914
- vec4 c;
2915
- ${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 ")}
2916
- gl_FragColor = c * vColor;
2917
- }`;
2918
- var VERTEX_PLAIN = `
2919
- attribute vec2 aPos;
2920
- attribute vec2 aUv;
2921
- attribute vec4 aColor;
2922
- attribute float aSlot;
2923
- uniform vec2 uScale;
2924
- varying vec2 vUv;
2925
- varying vec4 vColor;
2926
- varying float vSlot;
2927
- void main() {
2928
- vUv = aUv;
2929
- vColor = aColor;
2930
- vSlot = aSlot;
2931
- gl_Position = vec4(aPos * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
2932
- }`;
2933
- var VERTEX_INSTANCED = `
2934
- attribute vec4 aCorner;
2935
- attribute vec4 aP01;
2936
- attribute vec4 aP23;
2937
- attribute vec4 aUvRect;
2938
- attribute vec4 aColor;
2939
- attribute float aSlot;
2940
- uniform vec2 uScale;
2941
- varying vec2 vUv;
2942
- varying vec4 vColor;
2943
- varying float vSlot;
2944
- void main() {
2945
- vec2 p = aP01.xy * aCorner.x + aP01.zw * aCorner.y + aP23.xy * aCorner.z + aP23.zw * aCorner.w;
2946
- vUv = vec2(mix(aUvRect.x, aUvRect.z, aCorner.y + aCorner.z), mix(aUvRect.y, aUvRect.w, aCorner.z + aCorner.w));
2947
- vColor = aColor;
2948
- vSlot = aSlot;
2949
- gl_Position = vec4(p * uScale + vec2(-1.0, 1.0), 0.0, 1.0);
2950
- }`;
2981
+ var PRECISION = "\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n";
2982
+ 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}");
2983
+ 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}";
2984
+ 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}";
2951
2985
  var GL_ATTRIBUTES = {
2952
2986
  alpha: true,
2953
2987
  premultipliedAlpha: true,
@@ -2960,14 +2994,15 @@ var GL_ATTRIBUTES = {
2960
2994
  var ATTRS_INSTANCED = ["aCorner", "aP01", "aP23", "aUvRect", "aColor", "aSlot"];
2961
2995
  var ATTRS_PLAIN = ["aPos", "aUv", "aColor", "aSlot"];
2962
2996
  function createWebGL(canvas, version, opts = {}) {
2963
- const attrs = { ...GL_ATTRIBUTES, failIfMajorPerformanceCaveat: opts.failIfMajorPerformanceCaveat !== false };
2964
- const gl = version === 2 ? canvas.getContext("webgl2", attrs) : canvas.getContext("webgl", attrs) ?? canvas.getContext("experimental-webgl", attrs);
2997
+ var _a2, _b;
2998
+ const attrs = __spreadProps(__spreadValues({}, GL_ATTRIBUTES), { failIfMajorPerformanceCaveat: opts.failIfMajorPerformanceCaveat !== false });
2999
+ const gl = version === 2 ? canvas.getContext("webgl2", attrs) : (_a2 = canvas.getContext("webgl", attrs)) != null ? _a2 : canvas.getContext("experimental-webgl", attrs);
2965
3000
  if (!gl || gl.isContextLost()) return null;
2966
3001
  try {
2967
3002
  return new GLRenderer(canvas, gl, version, opts);
2968
3003
  } catch (e) {
2969
3004
  console.warn("[engine] WebGL setup failed:", e);
2970
- gl.getExtension("WEBGL_lose_context")?.loseContext();
3005
+ (_b = gl.getExtension("WEBGL_lose_context")) == null ? void 0 : _b.loseContext();
2971
3006
  return null;
2972
3007
  }
2973
3008
  }
@@ -3218,6 +3253,7 @@ var GLRenderer = class extends Layered {
3218
3253
  }
3219
3254
  /** A program of fragment shader fs with the batch's vertex shader and attribute locations; throws the log. */
3220
3255
  build(fs) {
3256
+ var _a2;
3221
3257
  const gl = this.gl;
3222
3258
  const v = compile(gl, gl.VERTEX_SHADER, this.vsrc);
3223
3259
  let f;
@@ -3235,9 +3271,9 @@ var GLRenderer = class extends Layered {
3235
3271
  gl.deleteShader(v);
3236
3272
  gl.deleteShader(f);
3237
3273
  if (!gl.getProgramParameter(p, gl.LINK_STATUS)) {
3238
- const log = gl.getProgramInfoLog(p) ?? "?";
3274
+ const log = (_a2 = gl.getProgramInfoLog(p)) != null ? _a2 : "?";
3239
3275
  gl.deleteProgram(p);
3240
- throw new Error(`link: ${log}`);
3276
+ throw new Error("link: ".concat(log));
3241
3277
  }
3242
3278
  return { p, uScale: gl.getUniformLocation(p, "uScale"), locs: /* @__PURE__ */ new Map() };
3243
3279
  }
@@ -3510,14 +3546,15 @@ var GLRenderer = class extends Layered {
3510
3546
  }
3511
3547
  /** The layer framebuffer at depth d, made (or made again at the canvas's size) on demand; null if it can't be. */
3512
3548
  layerAt(d) {
3549
+ var _a2;
3513
3550
  const w2 = this.canvas.width;
3514
3551
  const h = this.canvas.height;
3515
- let L = this.layers[d] ?? null;
3552
+ let L = (_a2 = this.layers[d]) != null ? _a2 : null;
3516
3553
  if (L && (L.w !== w2 || L.h !== h)) {
3517
3554
  this.drop(L);
3518
3555
  L = this.layers[d] = null;
3519
3556
  }
3520
- return L ?? (this.layers[d] = this.target(w2, h, 1, false));
3557
+ return L != null ? L : this.layers[d] = this.target(w2, h, 1, false);
3521
3558
  }
3522
3559
  pushLayer() {
3523
3560
  if (this.lost) return false;
@@ -3538,11 +3575,13 @@ var GLRenderer = class extends Layered {
3538
3575
  }
3539
3576
  /** The filter runtime (made on first use), or null: none installed (no filter was ever made), or the context is lost. */
3540
3577
  filters() {
3578
+ var _a2;
3541
3579
  if (this.lost || !fx.gl) return null;
3542
- return this.fxr ?? (this.fxr = fx.gl(this));
3580
+ return (_a2 = this.fxr) != null ? _a2 : this.fxr = fx.gl(this);
3543
3581
  }
3544
3582
  composite(t, mask, alpha, filters) {
3545
- if (filters && this.filters()?.chain(t, alpha, filters)) return;
3583
+ var _a2;
3584
+ if (filters && ((_a2 = this.filters()) == null ? void 0 : _a2.chain(t, alpha, filters))) return;
3546
3585
  const gl = this.gl;
3547
3586
  if (mask) gl.blendFunc(gl.ZERO, gl.SRC_ALPHA);
3548
3587
  this.final(this.main, t, 1, alpha);
@@ -3607,6 +3646,7 @@ var GLRenderer = class extends Layered {
3607
3646
  gl.bufferSubData(gl.ARRAY_BUFFER, 0, v);
3608
3647
  }
3609
3648
  flush() {
3649
+ var _a2, _b;
3610
3650
  const b = this.batch;
3611
3651
  if (!b.quads || this.lost) return b.reset();
3612
3652
  const gl = this.gl;
@@ -3617,7 +3657,7 @@ var GLRenderer = class extends Layered {
3617
3657
  this.upload2(b);
3618
3658
  for (let i = 0; i < b.bound; i++) {
3619
3659
  const t = b.textures[i];
3620
- this.bindTex(this.textures.get(t) ?? this.layerTex.get(t) ?? null, i);
3660
+ this.bindTex((_b = (_a2 = this.textures.get(t)) != null ? _a2 : this.layerTex.get(t)) != null ? _b : null, i);
3621
3661
  }
3622
3662
  if (this.inst) this.inst.draw(6, b.quads);
3623
3663
  else gl.drawElements(gl.TRIANGLES, b.quads * 6, gl.UNSIGNED_SHORT, 0);
@@ -3638,6 +3678,7 @@ var GLRenderer = class extends Layered {
3638
3678
  this.restoredListeners.push(l);
3639
3679
  }
3640
3680
  destroy() {
3681
+ var _a2, _b;
3641
3682
  const gl = this.gl;
3642
3683
  if (fx.live === this) fx.live = null;
3643
3684
  this.canvas.removeEventListener("webglcontextlost", this.onContextLost);
@@ -3649,25 +3690,26 @@ var GLRenderer = class extends Layered {
3649
3690
  gl.deleteTexture(L.gl);
3650
3691
  gl.deleteFramebuffer(L.fb);
3651
3692
  }
3652
- this.fxr?.destroy();
3693
+ (_a2 = this.fxr) == null ? void 0 : _a2.destroy();
3653
3694
  this.fxr = null;
3654
3695
  gl.deleteBuffer(this.dynamic);
3655
3696
  gl.deleteBuffer(this.index);
3656
3697
  if (this.staticBuf) gl.deleteBuffer(this.staticBuf);
3657
3698
  if (this.vao && this.vaoApi) this.vaoApi.remove(this.vao);
3658
3699
  gl.deleteProgram(this.main.p);
3659
- gl.getExtension("WEBGL_lose_context")?.loseContext();
3660
- } catch {
3700
+ (_b = gl.getExtension("WEBGL_lose_context")) == null ? void 0 : _b.loseContext();
3701
+ } catch (e) {
3661
3702
  }
3662
3703
  this.textures.clear();
3663
3704
  }
3664
3705
  };
3665
3706
  function compile(gl, type, src) {
3707
+ var _a2;
3666
3708
  const s = gl.createShader(type);
3667
3709
  gl.shaderSource(s, src);
3668
3710
  gl.compileShader(s);
3669
3711
  if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) {
3670
- const log = gl.getShaderInfoLog(s) ?? "?";
3712
+ const log = (_a2 = gl.getShaderInfoLog(s)) != null ? _a2 : "?";
3671
3713
  gl.deleteShader(s);
3672
3714
  throw new Error(log);
3673
3715
  }
@@ -3700,8 +3742,9 @@ function createRenderer(canvas, opts = {}) {
3700
3742
  throw new Error("No renderer: this browser has neither WebGL nor Canvas 2D");
3701
3743
  }
3702
3744
  function freshCanvas(c) {
3745
+ var _a2;
3703
3746
  const n = c.cloneNode(false);
3704
- c.parentNode?.replaceChild(n, c);
3747
+ (_a2 = c.parentNode) == null ? void 0 : _a2.replaceChild(n, c);
3705
3748
  return n;
3706
3749
  }
3707
3750
  function rendererFromUrl(search = typeof location !== "undefined" ? location.search : "") {
@@ -3723,8 +3766,9 @@ var NameTags = class {
3723
3766
  /** The tag's height, drawing units. */
3724
3767
  __publicField(this, "height");
3725
3768
  __publicField(this, "font");
3726
- this.height = o.tagHeight ?? 34;
3727
- this.font = o.tagFont ?? "Nunito, sans-serif";
3769
+ var _a2, _b;
3770
+ this.height = (_a2 = o.tagHeight) != null ? _a2 : 34;
3771
+ this.font = (_b = o.tagFont) != null ? _b : "Nunito, sans-serif";
3728
3772
  }
3729
3773
  /** Forgets every tag (bake them again: the web font arrived). */
3730
3774
  drop() {
@@ -3744,9 +3788,10 @@ var NameTags = class {
3744
3788
  }
3745
3789
  /** get's slow path, apart (its closure's context would be made on every get otherwise). */
3746
3790
  bake(name, color, ratio) {
3791
+ var _a2;
3747
3792
  const tagH = this.height;
3748
- const font = `700 ${Math.round(tagH * 0.65)}px ${this.font}`;
3749
- const measure = this.measure ?? (this.measure = document.createElement("canvas").getContext("2d"));
3793
+ const font = "700 ".concat(Math.round(tagH * 0.65), "px ").concat(this.font);
3794
+ const measure = (_a2 = this.measure) != null ? _a2 : this.measure = document.createElement("canvas").getContext("2d");
3750
3795
  measure.font = font;
3751
3796
  const pad = Math.round(tagH * 0.4);
3752
3797
  const w2 = Math.ceil(measure.measureText(name).width) + pad * 2;
@@ -3799,8 +3844,9 @@ var NameTags = class {
3799
3844
  var bandOf = (def) => def.band === "3-5" || def.band === "9-12" ? def.band : "6-8";
3800
3845
 
3801
3846
  // src/avatars.ts
3802
- var bakeBucket = (px, coarse = false) => coarse ? Math.min(2 ** Math.round(Math.log2(Math.max(px, 8))), 256) : Math.min(2 ** (Math.ceil(Math.log2(Math.max(px, 8)) * 2) / 2), 512);
3847
+ 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);
3803
3848
  function shapeBounds(shapes, m = null) {
3849
+ var _a2, _b, _c, _d;
3804
3850
  const b = { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
3805
3851
  const add = (x, y, pad) => {
3806
3852
  const px = m ? m[0] * x + m[2] * y + m[4] : x;
@@ -3812,7 +3858,7 @@ function shapeBounds(shapes, m = null) {
3812
3858
  b.maxY = Math.max(b.maxY, py + pad * k);
3813
3859
  };
3814
3860
  for (const s of shapes) {
3815
- const pad = "lw" in s && s.stroke ? (s.lw ?? 1) / 2 : 0;
3861
+ const pad = "lw" in s && s.stroke ? ((_a2 = s.lw) != null ? _a2 : 1) / 2 : 0;
3816
3862
  switch (s.k) {
3817
3863
  case "circle":
3818
3864
  add(s.x - s.r, s.y - s.r, pad), add(s.x + s.r, s.y + s.r, pad), add(s.x - s.r, s.y + s.r, pad), add(s.x + s.r, s.y - s.r, pad);
@@ -3835,7 +3881,7 @@ function shapeBounds(shapes, m = null) {
3835
3881
  for (let i = 0; i + 1 < s.pts.length; i += 2) add(s.pts[i], s.pts[i + 1], pad);
3836
3882
  break;
3837
3883
  case "group": {
3838
- const g = composeMat(mat(), m, s.x, s.y, s.rot ?? 0, s.s ?? 1, s.s ?? 1);
3884
+ 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);
3839
3885
  const inner = shapeBounds(s.items, g);
3840
3886
  if (Number.isFinite(inner.minX)) {
3841
3887
  b.minX = Math.min(b.minX, inner.minX);
@@ -3889,7 +3935,8 @@ var AvatarPainter = class {
3889
3935
  * don't show through each other.
3890
3936
  */
3891
3937
  draw(r, tex, body, avatar, box, alpha, pixelScale) {
3892
- const def = typeof avatar === "string" ? avatarById(avatar) ?? DEFAULT_AVATAR : avatar;
3938
+ var _a2;
3939
+ const def = typeof avatar === "string" ? (_a2 = avatarById(avatar)) != null ? _a2 : DEFAULT_AVATAR : avatar;
3893
3940
  const shapes = avatarShapes(body, def, box);
3894
3941
  if (!shapes.length) return false;
3895
3942
  if (alpha <= 0) return true;
@@ -3901,12 +3948,12 @@ var AvatarPainter = class {
3901
3948
  }
3902
3949
  /** Paints a shape list under the transform m (a similarity: translate, rotate, uniform scale) with an alpha. */
3903
3950
  paint(r, tex, shapes, m, alpha, pixelScale, depth = 0) {
3904
- var _a;
3951
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3905
3952
  for (let si = 0; si < shapes.length; si++) {
3906
3953
  const s = shapes[si];
3907
3954
  if (s.k === "group") {
3908
- const g = composeMat((_a = this.stack)[depth] ?? (_a[depth] = mat()), m, s.x, s.y, s.rot ?? 0, s.s ?? 1, s.s ?? 1);
3909
- const a2 = alpha * (s.alpha ?? 1);
3955
+ const g = composeMat((_b = (_a2 = this.stack)[depth]) != null ? _b : _a2[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);
3956
+ const a2 = alpha * ((_f = s.alpha) != null ? _f : 1);
3910
3957
  if (this.bakeGroups && this.seen.has(s.items)) {
3911
3958
  const k = len2(g[0], g[1]) * pixelScale;
3912
3959
  const b = this.bake(s.items, k);
@@ -3926,18 +3973,18 @@ var AvatarPainter = class {
3926
3973
  this.paint(r, tex, s.items, g, a2, pixelScale, depth + 1);
3927
3974
  continue;
3928
3975
  }
3929
- const a = alpha * (s.alpha ?? 1);
3976
+ const a = alpha * ((_g = s.alpha) != null ? _g : 1);
3930
3977
  const scale = m ? len2(m[0], m[1]) : 1;
3931
3978
  const rot = m ? Math.atan2(m[1], m[0]) : 0;
3932
- const lw = (s.lw ?? 1) * scale;
3933
- const stroke = s.stroke && (s.lw ?? 1) > 0 ? parseColor(s.stroke) : null;
3979
+ const lw = ((_h = s.lw) != null ? _h : 1) * scale;
3980
+ const stroke = s.stroke && ((_i = s.lw) != null ? _i : 1) > 0 ? parseColor(s.stroke) : null;
3934
3981
  const fill = s.fill && s.k !== "line" ? parseColor(s.fill) : null;
3935
3982
  if (s.k === "circle" || s.k === "ellipse") {
3936
3983
  const cx = m ? m[0] * s.x + m[2] * s.y + m[4] : s.x;
3937
3984
  const cy = m ? m[1] * s.x + m[3] * s.y + m[5] : s.y;
3938
3985
  const rx = (s.k === "circle" ? s.r : s.rx) * scale;
3939
3986
  const ry = (s.k === "circle" ? s.r : s.ry) * scale;
3940
- const er = (s.k === "ellipse" ? s.rot ?? 0 : 0) + rot;
3987
+ const er = (s.k === "ellipse" ? (_j = s.rot) != null ? _j : 0 : 0) + rot;
3941
3988
  if (fill && stroke) {
3942
3989
  r.ellipse(cx, cy, rx + lw / 2, ry + lw / 2, er, stroke[0], a * stroke[1]);
3943
3990
  r.ellipse(cx, cy, Math.max(rx - lw / 2, 0), Math.max(ry - lw / 2, 0), er, fill[0], a * fill[1]);
@@ -3971,7 +4018,7 @@ var AvatarPainter = class {
3971
4018
  r.stroke(pts, n, lw, stroke[0], a * stroke[1], false);
3972
4019
  continue;
3973
4020
  }
3974
- const flat2 = s.k === "path" ? flatten(s.d, m, scale * pixelScale) : roundRectFlat(s, composeMat(this.local, m, s.x, s.y, s.rot ?? 0, 1, 1), pixelScale * scale);
4021
+ 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);
3975
4022
  for (let j = 0; j < flat2.count; j++) {
3976
4023
  const sp = flat2.subs[j];
3977
4024
  const n = sp.n;
@@ -3988,7 +4035,7 @@ var AvatarPainter = class {
3988
4035
  bake(items, k) {
3989
4036
  const kb = bakeBucket(k, this.coarse);
3990
4037
  let byK = this.baked.get(items);
3991
- const hit = byK?.get(kb);
4038
+ const hit = byK == null ? void 0 : byK.get(kb);
3992
4039
  if (hit && hit.gen === this.gen && this.atlas.valid(hit.frame)) return hit;
3993
4040
  if (hit) this.live.delete(hit);
3994
4041
  const b = shapeBounds(items);
@@ -4041,6 +4088,7 @@ function roundRectFlat(s, local, pxPerUnit) {
4041
4088
  return flatten(rectPath, local, pxPerUnit);
4042
4089
  }
4043
4090
  function createAvatarRenderer(canvas, opts = {}) {
4091
+ var _a2, _b;
4044
4092
  let renderer = createRenderer(canvas, opts);
4045
4093
  const atlas = new Atlas(Math.min(1024, renderer.maxTextureSize), 2);
4046
4094
  atlas.onDrop = (s) => {
@@ -4065,10 +4113,10 @@ function createAvatarRenderer(canvas, opts = {}) {
4065
4113
  let destroyed = false;
4066
4114
  const dropTags = () => tags.drop();
4067
4115
  const fonts = typeof document !== "undefined" ? document.fonts : void 0;
4068
- void fonts?.ready?.then(() => {
4116
+ void ((_a2 = fonts == null ? void 0 : fonts.ready) == null ? void 0 : _a2.then(() => {
4069
4117
  if (!destroyed) dropTags();
4070
- });
4071
- fonts?.addEventListener?.("loadingdone", dropTags);
4118
+ }));
4119
+ (_b = fonts == null ? void 0 : fonts.addEventListener) == null ? void 0 : _b.call(fonts, "loadingdone", dropTags);
4072
4120
  const toCanvas2D = () => {
4073
4121
  const c = freshCanvas(renderer.canvas);
4074
4122
  const r = createCanvas2D(c);
@@ -4091,13 +4139,14 @@ function createAvatarRenderer(canvas, opts = {}) {
4091
4139
  return !renderer.lost;
4092
4140
  };
4093
4141
  const begin2 = () => {
4142
+ var _a3, _b2;
4094
4143
  const c = renderer.canvas;
4095
4144
  if (opts.units) {
4096
- ratio = opts.pixelRatio ?? 1;
4145
+ ratio = (_a3 = opts.pixelRatio) != null ? _a3 : 1;
4097
4146
  units.w = opts.units.width;
4098
4147
  units.h = opts.units.height;
4099
4148
  } else {
4100
- ratio = opts.pixelRatio ?? Math.min(globalThis.devicePixelRatio || 1, 2);
4149
+ ratio = (_b2 = opts.pixelRatio) != null ? _b2 : Math.min(__fabiGlobalThis.devicePixelRatio || 1, 2);
4101
4150
  units.w = c.clientWidth || c.width / ratio;
4102
4151
  units.h = c.clientHeight || c.height / ratio;
4103
4152
  }
@@ -4105,7 +4154,8 @@ function createAvatarRenderer(canvas, opts = {}) {
4105
4154
  renderer.begin(0, 0, ratio);
4106
4155
  };
4107
4156
  const idOf = (p, i) => {
4108
- if (p.key === void 0) return p.id ?? i + 1;
4157
+ var _a3;
4158
+ if (p.key === void 0) return (_a3 = p.id) != null ? _a3 : i + 1;
4109
4159
  let id = keyIds.get(p.key);
4110
4160
  if (id === void 0) {
4111
4161
  if (keyIds.size > 256) keyIds.clear();
@@ -4127,6 +4177,7 @@ function createAvatarRenderer(canvas, opts = {}) {
4127
4177
  return renderer.canvas;
4128
4178
  },
4129
4179
  draw(players, box) {
4180
+ var _a3, _b2, _c, _d;
4130
4181
  if (!ready()) return;
4131
4182
  begin2();
4132
4183
  for (let i = 0; i < players.length; i++) {
@@ -4134,10 +4185,10 @@ function createAvatarRenderer(canvas, opts = {}) {
4134
4185
  if (!Array.isArray(p.body)) continue;
4135
4186
  const id = idOf(p, i);
4136
4187
  const body = amount < 1 || opts.interpolate !== false ? book.posed(id, p.body, amount, opts.interpolate !== false) : p.body;
4137
- const def = avatarById(p.avatar ?? "") ?? DEFAULT_AVATAR;
4138
- const alpha = p.alpha ?? 1;
4188
+ const def = (_b2 = avatarById((_a3 = p.avatar) != null ? _a3 : "")) != null ? _b2 : DEFAULT_AVATAR;
4189
+ const alpha = (_c = p.alpha) != null ? _c : 1;
4139
4190
  if (!painter.draw(renderer, tex, body, def, box, alpha, ratio) || !p.name) continue;
4140
- tags.draw(renderer, tex, body, def, box, p.name, p.color ?? "#6FA0E0", alpha, ratio, units.w, units.h);
4191
+ tags.draw(renderer, tex, body, def, box, p.name, (_d = p.color) != null ? _d : "#6FA0E0", alpha, ratio, units.w, units.h);
4141
4192
  }
4142
4193
  renderer.end();
4143
4194
  },
@@ -4151,15 +4202,17 @@ function createAvatarRenderer(canvas, opts = {}) {
4151
4202
  keyIds.clear();
4152
4203
  },
4153
4204
  destroy() {
4205
+ var _a3;
4154
4206
  destroyed = true;
4155
- fonts?.removeEventListener?.("loadingdone", dropTags);
4207
+ (_a3 = fonts == null ? void 0 : fonts.removeEventListener) == null ? void 0 : _a3.call(fonts, "loadingdone", dropTags);
4156
4208
  renderer.destroy();
4157
4209
  }
4158
4210
  };
4159
4211
  }
4160
4212
  var portraits = /* @__PURE__ */ new Map();
4161
- function avatarPortrait(avatar, size, pixelRatio = Math.min(globalThis.devicePixelRatio || 1, 2)) {
4162
- const key = `${avatar}|${size}|${pixelRatio}`;
4213
+ function avatarPortrait(avatar, size, pixelRatio = Math.min(__fabiGlobalThis.devicePixelRatio || 1, 2)) {
4214
+ var _a2;
4215
+ const key = "".concat(avatar, "|").concat(size, "|").concat(pixelRatio);
4163
4216
  let c = portraits.get(key);
4164
4217
  if (c) return c;
4165
4218
  c = document.createElement("canvas");
@@ -4169,7 +4222,7 @@ function avatarPortrait(avatar, size, pixelRatio = Math.min(globalThis.devicePix
4169
4222
  ctx.beginPath();
4170
4223
  ctx.rect(0, 0, size, size);
4171
4224
  ctx.clip();
4172
- drawShapes(ctx, iconShapes(avatarById(avatar) ?? DEFAULT_AVATAR, size));
4225
+ drawShapes(ctx, iconShapes((_a2 = avatarById(avatar)) != null ? _a2 : DEFAULT_AVATAR, size));
4173
4226
  if (portraits.size > 64) portraits.clear();
4174
4227
  portraits.set(key, c);
4175
4228
  return c;
@@ -4192,14 +4245,15 @@ function textureOf(r) {
4192
4245
  var DEFAULT_FONT = 'Fredoka, Nunito, "Varela Round", system-ui, sans-serif';
4193
4246
  var HALO = "rgba(10,16,30,0.75)";
4194
4247
  function lookOf(st, effects) {
4195
- const size = st.size ?? 40;
4248
+ var _a2, _b, _c, _d, _e, _f;
4249
+ const size = (_a2 = st.size) != null ? _a2 : 40;
4196
4250
  const outline = st.outline ? st.outline === true ? HALO : st.outline : null;
4197
- const ow = outline ? st.outlineWidth ?? Math.max(size * 0.12, 3) : 0;
4251
+ const ow = outline ? (_b = st.outlineWidth) != null ? _b : Math.max(size * 0.12, 3) : 0;
4198
4252
  const shadow = st.shadow && effects ? st.shadow === true ? HALO : st.shadow : null;
4199
- const blur2 = shadow ? st.shadowBlur ?? size * 0.25 : 0;
4200
- return { size, font: st.font ?? DEFAULT_FONT, weight: st.weight ?? 700, color: st.color ?? "#FBEFE3", outline, ow, shadow, blur: blur2, pad: ow / 2 + blur2 * 1.2 + 2, th: size * 1.25 };
4253
+ const blur2 = shadow ? (_c = st.shadowBlur) != null ? _c : size * 0.25 : 0;
4254
+ 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 };
4201
4255
  }
4202
- var fontOf = (l, scale) => `${l.weight} ${l.size * scale}px ${l.font}`;
4256
+ var fontOf = (l, scale) => "".concat(l.weight, " ").concat(l.size * scale, "px ").concat(l.font);
4203
4257
  function paintLine(ctx, text, l, scale, x, y) {
4204
4258
  ctx.scale(scale, scale);
4205
4259
  ctx.font = fontOf(l, 1);
@@ -4221,7 +4275,7 @@ function paintLine(ctx, text, l, scale, x, y) {
4221
4275
  }
4222
4276
  var measurer = null;
4223
4277
  function measureLine(text, l, scale) {
4224
- measurer ?? (measurer = document.createElement("canvas").getContext("2d"));
4278
+ measurer != null ? measurer : measurer = document.createElement("canvas").getContext("2d");
4225
4279
  measurer.font = fontOf(l, scale);
4226
4280
  return measurer.measureText(text).width / scale;
4227
4281
  }
@@ -4241,7 +4295,7 @@ var Text = class extends Sprite {
4241
4295
  __publicField(this, "capW", 0);
4242
4296
  __publicField(this, "capH", 0);
4243
4297
  this._text = text;
4244
- const { x, y, rotation, scale, scaleX, scaleY, alpha, visible, tint: tint2, blend, z, anchor, hitRadius, clip, mask, filters, ...rest } = style;
4298
+ const _a2 = style, { x, y, rotation, scale, scaleX, scaleY, alpha, visible, tint: tint2, blend, z, anchor, hitRadius, clip, mask, filters } = _a2, rest = __objRest(_a2, ["x", "y", "rotation", "scale", "scaleX", "scaleY", "alpha", "visible", "tint", "blend", "z", "anchor", "hitRadius", "clip", "mask", "filters"]);
4245
4299
  this._style = rest;
4246
4300
  this.bake();
4247
4301
  this.set({ x, y, rotation, scale, scaleX, scaleY, alpha, visible, tint: tint2, blend, z, hitRadius, clip, mask, filters });
@@ -4263,7 +4317,7 @@ var Text = class extends Sprite {
4263
4317
  }
4264
4318
  /** A new style (merged with the current one). */
4265
4319
  set style(s) {
4266
- this._style = { ...this._style, ...s };
4320
+ this._style = __spreadValues(__spreadValues({}, this._style), s);
4267
4321
  this.dirty = true;
4268
4322
  }
4269
4323
  /** The bitmap font it is drawn with, or null (a baked text). Sets the anchor from align while it is automatic. */
@@ -4280,24 +4334,27 @@ var Text = class extends Sprite {
4280
4334
  }
4281
4335
  /** The content width, stage units: the text's own. */
4282
4336
  get naturalWidth() {
4337
+ var _a2;
4283
4338
  const f = this.bitmap();
4284
4339
  if (!f) return super.naturalWidth;
4285
- return f.measure(this._text) * ((this._style.size ?? f.size) / f.size);
4340
+ return f.measure(this._text) * (((_a2 = this._style.size) != null ? _a2 : f.size) / f.size);
4286
4341
  }
4287
4342
  /** The content height, stage units: the line's. */
4288
4343
  get naturalHeight() {
4344
+ var _a2;
4289
4345
  const f = this.bitmap();
4290
4346
  if (!f) return super.naturalHeight;
4291
- return f.lineHeight * ((this._style.size ?? f.size) / f.size);
4347
+ return f.lineHeight * (((_a2 = this._style.size) != null ? _a2 : f.size) / f.size);
4292
4348
  }
4293
4349
  frameNow() {
4294
4350
  return this._style.bitmapFont ? null : this.bake();
4295
4351
  }
4296
4352
  /** Draws the text (the engine calls it): its baked frame, or its glyphs. */
4297
4353
  draw(ctx, alpha, tint2) {
4354
+ var _a2;
4298
4355
  const f = this.bitmap();
4299
4356
  if (!f) return super.draw(ctx, alpha, tint2);
4300
- const k = (this._style.size ?? f.size) / f.size;
4357
+ const k = ((_a2 = this._style.size) != null ? _a2 : f.size) / f.size;
4301
4358
  const nw = f.measure(this._text) * k;
4302
4359
  const nh = f.lineHeight * k;
4303
4360
  const w2 = this.width;
@@ -4321,6 +4378,7 @@ var Text = class extends Sprite {
4321
4378
  }
4322
4379
  /** bake's slow path, apart: its closure's context would otherwise be made on every call, even the cheap ones. */
4323
4380
  rebake() {
4381
+ var _a2;
4324
4382
  const k = this.kernel;
4325
4383
  const scale = k.pixelScale;
4326
4384
  const effects = k.effects;
@@ -4333,7 +4391,7 @@ var Text = class extends Sprite {
4333
4391
  const tw = measureLine(this._text, l, scale);
4334
4392
  const W = (tw + pad * 2) * scale;
4335
4393
  const H = (th + pad * 2) * scale;
4336
- const align = this._style.align ?? "center";
4394
+ const align = (_a2 = this._style.align) != null ? _a2 : "center";
4337
4395
  const ox = align === "left" ? pad : align === "right" ? pad + tw : pad + tw / 2;
4338
4396
  const draw = (ctx) => paintLine(ctx, this._text, l, scale, pad, pad + th / 2);
4339
4397
  const old = this._frame;
@@ -4363,30 +4421,32 @@ var num = (v, d = 0) => {
4363
4421
  return Number.isFinite(n) ? n : d;
4364
4422
  };
4365
4423
  function parseBMFont(src) {
4424
+ var _a2, _b, _c, _d, _e, _f;
4366
4425
  if (typeof src === "string" && /^\s*[{[]/.test(src)) src = JSON.parse(src);
4367
4426
  const out = { size: 0, lineHeight: 0, base: 0, pages: [], chars: [], kernings: [] };
4368
4427
  const rec = (kind, a) => {
4428
+ var _a3;
4369
4429
  if (kind === "info") out.size = Math.abs(num(a.size));
4370
4430
  else if (kind === "common") {
4371
4431
  out.lineHeight = num(a.lineHeight);
4372
4432
  out.base = num(a.base);
4373
- } else if (kind === "page") out.pages[num(a.id)] = String(a.file ?? "");
4433
+ } else if (kind === "page") out.pages[num(a.id)] = String((_a3 = a.file) != null ? _a3 : "");
4374
4434
  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) });
4375
4435
  else out.kernings.push({ first: num(a.first), second: num(a.second), amount: num(a.amount) });
4376
4436
  };
4377
4437
  if (typeof src === "object") {
4378
4438
  const j = src;
4379
- rec("info", j.info ?? {});
4380
- rec("common", j.common ?? {});
4381
- for (const [id, file] of (j.pages ?? []).entries()) rec("page", { id, file });
4382
- for (const c of j.chars ?? []) rec("char", c);
4383
- for (const k of j.kernings ?? []) rec("kerning", k);
4439
+ rec("info", (_a2 = j.info) != null ? _a2 : {});
4440
+ rec("common", (_b = j.common) != null ? _b : {});
4441
+ for (const [id, file] of ((_c = j.pages) != null ? _c : []).entries()) rec("page", { id, file });
4442
+ for (const c of (_d = j.chars) != null ? _d : []) rec("char", c);
4443
+ for (const k of (_e = j.kernings) != null ? _e : []) rec("kerning", k);
4384
4444
  } else {
4385
4445
  const tag = /(?:^|<)\s*(info|common|page|char|kerning)\s([^\n<>]*)/gm;
4386
4446
  const attr = /(\w+)=(?:"([^"]*)"|([^\s/>]+))/g;
4387
4447
  for (let m = tag.exec(src); m; m = tag.exec(src)) {
4388
4448
  const a = {};
4389
- for (let t = attr.exec(m[2]); t; t = attr.exec(m[2])) a[t[1]] = t[2] ?? t[3];
4449
+ for (let t = attr.exec(m[2]); t; t = attr.exec(m[2])) a[t[1]] = (_f = t[2]) != null ? _f : t[3];
4390
4450
  rec(m[1], a);
4391
4451
  }
4392
4452
  }
@@ -4449,7 +4509,8 @@ var BitmapFont = class {
4449
4509
  }
4450
4510
  /** Kerning between two code points, font units (0 for most pairs). */
4451
4511
  kerning(a, b) {
4452
- return this.kern.size ? this.kern.get(a * 1114112 + b) ?? 0 : 0;
4512
+ var _a2;
4513
+ return this.kern.size ? (_a2 = this.kern.get(a * 1114112 + b)) != null ? _a2 : 0 : 0;
4453
4514
  }
4454
4515
  /** A string's width, font units. */
4455
4516
  measure(text) {
@@ -4494,8 +4555,9 @@ function bmFont(data, pages) {
4494
4555
  return f;
4495
4556
  }
4496
4557
  function generatedFont(host, o) {
4497
- const style = { ...o };
4498
- const size = o.size ?? 40;
4558
+ var _a2, _b;
4559
+ const style = __spreadValues({}, o);
4560
+ const size = (_a2 = o.size) != null ? _a2 : 40;
4499
4561
  const baker = (code) => {
4500
4562
  const ch = String.fromCodePoint(code);
4501
4563
  const scale = host.pixelScale;
@@ -4506,7 +4568,7 @@ function generatedFont(host, o) {
4506
4568
  };
4507
4569
  const f = new BitmapFont(size, size * 1.25, size, baker, host);
4508
4570
  f.prepare();
4509
- for (const ch of o.chars ?? "0123456789") f.glyph(ch.codePointAt(0));
4571
+ for (const ch of (_b = o.chars) != null ? _b : "0123456789") f.glyph(ch.codePointAt(0));
4510
4572
  return f;
4511
4573
  }
4512
4574
 
@@ -4521,21 +4583,22 @@ function wrists(body) {
4521
4583
  const x = body[i * 3];
4522
4584
  const y = body[i * 3 + 1];
4523
4585
  const v = body[i * 3 + 2];
4524
- if (x !== void 0 && y !== void 0 && Number.isFinite(x) && Number.isFinite(y) && (v ?? 0) >= VISIBLE2) out.push({ side, x, y });
4586
+ if (x !== void 0 && y !== void 0 && Number.isFinite(x) && Number.isFinite(y) && (v != null ? v : 0) >= VISIBLE2) out.push({ side, x, y });
4525
4587
  }
4526
4588
  return out;
4527
4589
  }
4528
4590
  var playerColor = (player) => PLAYER_COLORS[((player - 1) % PLAYER_COLORS.length + PLAYER_COLORS.length) % PLAYER_COLORS.length];
4529
4591
  var SIDES = ["left", "right"];
4530
4592
  function handsOf(frames, toScreen2, width, height, bodyOf = () => null, aim = {}) {
4593
+ var _a2, _b;
4531
4594
  const out = [];
4532
4595
  for (const f of frames) {
4533
- const body = bodyOf(f) ?? f.body;
4596
+ const body = (_a2 = bodyOf(f)) != null ? _a2 : f.body;
4534
4597
  if (!Array.isArray(body)) continue;
4535
4598
  if (aim.orientation === "portrait") {
4536
4599
  for (const side of SIDES) {
4537
4600
  let p = aimPoint(body, side, { orientation: "portrait" });
4538
- if (aim.hold) p = aim.hold.at(AimHold.key(f.id, side), p, aim.t ?? 0);
4601
+ if (aim.hold) p = aim.hold.at(AimHold.key(f.id, side), p, (_b = aim.t) != null ? _b : 0);
4539
4602
  if (p) out.push({ player: f.id, side, x: p.x * width, y: p.y * height, color: playerColor(f.id) });
4540
4603
  }
4541
4604
  continue;
@@ -4571,6 +4634,7 @@ function touching(node, hands, player, pad = 0) {
4571
4634
 
4572
4635
  // src/shapes.ts
4573
4636
  function shapeSize(s) {
4637
+ var _a2;
4574
4638
  switch (s.type) {
4575
4639
  case "circle":
4576
4640
  case "ring":
@@ -4581,17 +4645,18 @@ function shapeSize(s) {
4581
4645
  case "roundRect":
4582
4646
  return [s.w, s.h];
4583
4647
  case "line":
4584
- return [s.length, s.lw ?? 4];
4648
+ return [s.length, (_a2 = s.lw) != null ? _a2 : 4];
4585
4649
  case "path":
4586
4650
  return s.r ? [s.r * 2, s.r * 2] : [s.size, s.size];
4587
4651
  }
4588
4652
  }
4589
4653
  function shapeMargin(s) {
4590
- const out = s.type === "line" ? 0 : s.stroke ? (s.lw ?? 2) / 2 : 0;
4591
- const sh = s.shadow ? s.shadow.blur * 1.5 + Math.max(Math.abs(s.shadow.x ?? 0), Math.abs(s.shadow.y ?? 0)) : 0;
4654
+ var _a2, _b, _c;
4655
+ const out = s.type === "line" ? 0 : s.stroke ? ((_a2 = s.lw) != null ? _a2 : 2) / 2 : 0;
4656
+ 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;
4592
4657
  return Math.ceil(out + sh + 1);
4593
4658
  }
4594
- var forTier = (s, effects) => effects || !s.shadow ? s : { ...s, shadow: void 0 };
4659
+ var forTier = (s, effects) => effects || !s.shadow ? s : __spreadProps(__spreadValues({}, s), { shadow: void 0 });
4595
4660
  function bakeShape(atlas, s, scale) {
4596
4661
  const m = shapeMargin(s);
4597
4662
  const nine = s.type === "roundRect";
@@ -4614,6 +4679,7 @@ function bakeShape(atlas, s, scale) {
4614
4679
  return { frame, slice: nine ? Math.ceil((s.r + m) * scale) : 0, w: nine ? s.w : w2, h: nine ? s.h : h };
4615
4680
  }
4616
4681
  function paint(ctx, s, w2, h) {
4682
+ var _a2, _b, _c, _d, _e, _f, _g;
4617
4683
  ctx.lineJoin = "round";
4618
4684
  ctx.lineCap = "round";
4619
4685
  const path = new Path2D();
@@ -4629,8 +4695,8 @@ function paint(ctx, s, w2, h) {
4629
4695
  path.roundRect(-w2 / 2, -h / 2, w2, h, Math.min(s.r, w2 / 2, h / 2));
4630
4696
  break;
4631
4697
  case "star": {
4632
- const n = s.points ?? 5;
4633
- const inner = s.r * (s.inner ?? 0.5);
4698
+ const n = (_a2 = s.points) != null ? _a2 : 5;
4699
+ const inner = s.r * ((_b = s.inner) != null ? _b : 0.5);
4634
4700
  for (let i = 0; i < n * 2; i++) {
4635
4701
  const r = i % 2 ? inner : s.r;
4636
4702
  const a = -Math.PI / 2 + i * Math.PI / n;
@@ -4653,12 +4719,13 @@ function paint(ctx, s, w2, h) {
4653
4719
  }
4654
4720
  const sh = s.shadow;
4655
4721
  const shadow = () => {
4722
+ var _a3, _b2;
4656
4723
  if (!sh) return;
4657
4724
  const t = ctx.getTransform();
4658
4725
  ctx.shadowColor = sh.color;
4659
4726
  ctx.shadowBlur = sh.blur * t.a;
4660
- ctx.shadowOffsetX = (sh.x ?? 0) * t.a;
4661
- ctx.shadowOffsetY = (sh.y ?? 0) * t.a;
4727
+ ctx.shadowOffsetX = ((_a3 = sh.x) != null ? _a3 : 0) * t.a;
4728
+ ctx.shadowOffsetY = ((_b2 = sh.y) != null ? _b2 : 0) * t.a;
4662
4729
  };
4663
4730
  const noShadow = () => {
4664
4731
  ctx.shadowColor = "transparent";
@@ -4666,7 +4733,7 @@ function paint(ctx, s, w2, h) {
4666
4733
  };
4667
4734
  if (s.type === "line") {
4668
4735
  shadow();
4669
- ctx.strokeStyle = s.stroke ?? s.fill ?? "#fff";
4736
+ ctx.strokeStyle = (_d = (_c = s.stroke) != null ? _c : s.fill) != null ? _d : "#fff";
4670
4737
  ctx.lineWidth = h;
4671
4738
  ctx.stroke(path);
4672
4739
  return;
@@ -4675,7 +4742,7 @@ function paint(ctx, s, w2, h) {
4675
4742
  if (s.outlineBelow && s.fill && s.stroke && !isRing) {
4676
4743
  shadow();
4677
4744
  ctx.strokeStyle = s.stroke;
4678
- ctx.lineWidth = s.lw ?? 2;
4745
+ ctx.lineWidth = (_e = s.lw) != null ? _e : 2;
4679
4746
  ctx.stroke(path);
4680
4747
  noShadow();
4681
4748
  ctx.fillStyle = s.fill;
@@ -4694,8 +4761,8 @@ function paint(ctx, s, w2, h) {
4694
4761
  ctx.fillStyle = s.fill;
4695
4762
  ctx.fill(path);
4696
4763
  }
4697
- ctx.strokeStyle = s.stroke ?? "#fff";
4698
- ctx.lineWidth = s.lw ?? 2;
4764
+ ctx.strokeStyle = (_f = s.stroke) != null ? _f : "#fff";
4765
+ ctx.lineWidth = (_g = s.lw) != null ? _g : 2;
4699
4766
  ctx.stroke(path);
4700
4767
  noShadow();
4701
4768
  }
@@ -4714,31 +4781,37 @@ var Sound = class {
4714
4781
  /** Master volume, 0–1. */
4715
4782
  __publicField(this, "volume", 1);
4716
4783
  if (typeof addEventListener === "function") {
4717
- const unlock = () => void this.context()?.resume().catch(() => void 0);
4784
+ const unlock = () => {
4785
+ var _a2;
4786
+ return void ((_a2 = this.context()) == null ? void 0 : _a2.resume().catch(() => void 0));
4787
+ };
4718
4788
  for (const e of ["pointerdown", "keydown", "touchstart"]) addEventListener(e, unlock, { once: true, capture: true });
4719
4789
  }
4720
4790
  }
4721
4791
  /** The audio context, made on first use (null without Web Audio). */
4722
4792
  context() {
4793
+ var _a2;
4723
4794
  if (this.ctx) return this.ctx;
4724
- const AC = globalThis.AudioContext ?? globalThis.webkitAudioContext;
4795
+ const AC = (_a2 = __fabiGlobalThis.AudioContext) != null ? _a2 : __fabiGlobalThis.webkitAudioContext;
4725
4796
  if (!AC) return null;
4726
4797
  try {
4727
4798
  this.ctx = new AC();
4728
4799
  this.master = this.ctx.createGain();
4729
4800
  this.master.connect(this.ctx.destination);
4730
4801
  if (this.held) void this.ctx.suspend();
4731
- } catch {
4802
+ } catch (e) {
4732
4803
  return null;
4733
4804
  }
4734
4805
  return this.ctx;
4735
4806
  }
4736
4807
  /** Decodes a sound file (mp3, aac, ogg, wav) under a name. */
4737
- async load(name, url) {
4738
- const ctx = this.context();
4739
- if (!ctx) return;
4740
- const data = await (await fetch(url)).arrayBuffer();
4741
- this.buffers.set(name, await ctx.decodeAudioData(data));
4808
+ load(name, url) {
4809
+ return __async(this, null, function* () {
4810
+ const ctx = this.context();
4811
+ if (!ctx) return;
4812
+ const data = yield (yield fetch(url)).arrayBuffer();
4813
+ this.buffers.set(name, yield ctx.decodeAudioData(data));
4814
+ });
4742
4815
  }
4743
4816
  /** Whether a sound of that name is loaded. */
4744
4817
  has(name) {
@@ -4746,41 +4819,43 @@ var Sound = class {
4746
4819
  }
4747
4820
  /** Plays a loaded sound; returns stop(). */
4748
4821
  play(name, o = {}) {
4822
+ var _a2, _b, _c;
4749
4823
  const ctx = this.context();
4750
4824
  const buf = this.buffers.get(name);
4751
4825
  if (!ctx || !buf || !this.audible) return () => {
4752
4826
  };
4753
4827
  const src = ctx.createBufferSource();
4754
4828
  src.buffer = buf;
4755
- src.loop = o.loop ?? false;
4756
- src.playbackRate.value = o.rate ?? 1;
4829
+ src.loop = (_a2 = o.loop) != null ? _a2 : false;
4830
+ src.playbackRate.value = (_b = o.rate) != null ? _b : 1;
4757
4831
  const gain = ctx.createGain();
4758
- gain.gain.value = (o.volume ?? 1) * this.volume;
4832
+ gain.gain.value = ((_c = o.volume) != null ? _c : 1) * this.volume;
4759
4833
  src.connect(gain).connect(this.master);
4760
4834
  src.start();
4761
4835
  return () => {
4762
4836
  try {
4763
4837
  src.stop();
4764
- } catch {
4838
+ } catch (e) {
4765
4839
  }
4766
4840
  };
4767
4841
  }
4768
4842
  /** A short tone (a "ding"): frequency Hz, seconds, fading out. */
4769
4843
  tone(freq, seconds = 0.25, o = {}) {
4844
+ var _a2, _b;
4770
4845
  const ctx = this.context();
4771
4846
  if (!ctx || !this.audible) return;
4772
4847
  try {
4773
4848
  const osc = ctx.createOscillator();
4774
4849
  const gain = ctx.createGain();
4775
- osc.type = o.type ?? "sine";
4850
+ osc.type = (_a2 = o.type) != null ? _a2 : "sine";
4776
4851
  osc.frequency.setValueAtTime(freq, ctx.currentTime);
4777
4852
  if (o.to) osc.frequency.exponentialRampToValueAtTime(o.to, ctx.currentTime + seconds);
4778
- gain.gain.setValueAtTime((o.volume ?? 0.12) * this.volume, ctx.currentTime);
4853
+ gain.gain.setValueAtTime(((_b = o.volume) != null ? _b : 0.12) * this.volume, ctx.currentTime);
4779
4854
  gain.gain.exponentialRampToValueAtTime(1e-3, ctx.currentTime + seconds);
4780
4855
  osc.connect(gain).connect(this.master);
4781
4856
  osc.start();
4782
4857
  osc.stop(ctx.currentTime + seconds);
4783
- } catch {
4858
+ } catch (e) {
4784
4859
  }
4785
4860
  }
4786
4861
  get audible() {
@@ -4788,17 +4863,20 @@ var Sound = class {
4788
4863
  }
4789
4864
  /** Pauses and breaks: everything stops until release(). */
4790
4865
  hold() {
4866
+ var _a2;
4791
4867
  this.held = true;
4792
- void this.ctx?.suspend().catch(() => void 0);
4868
+ void ((_a2 = this.ctx) == null ? void 0 : _a2.suspend().catch(() => void 0));
4793
4869
  }
4794
4870
  /** Sound again after hold(). */
4795
4871
  release() {
4872
+ var _a2;
4796
4873
  this.held = false;
4797
- void this.ctx?.resume().catch(() => void 0);
4874
+ void ((_a2 = this.ctx) == null ? void 0 : _a2.resume().catch(() => void 0));
4798
4875
  }
4799
4876
  /** Closes the audio context. */
4800
4877
  destroy() {
4801
- void this.ctx?.close().catch(() => void 0);
4878
+ var _a2;
4879
+ void ((_a2 = this.ctx) == null ? void 0 : _a2.close().catch(() => void 0));
4802
4880
  this.ctx = null;
4803
4881
  }
4804
4882
  };
@@ -4812,7 +4890,7 @@ var TABLE = {
4812
4890
  var TIERS = ["high", "medium", "low"];
4813
4891
  function tier(name) {
4814
4892
  const t = TABLE[name];
4815
- return { name, ...t, scale: (n) => n <= 0 ? 0 : Math.max(1, Math.round(n * t.particles)) };
4893
+ return __spreadProps(__spreadValues({ name }, t), { scale: (n) => n <= 0 ? 0 : Math.max(1, Math.round(n * t.particles)) });
4816
4894
  }
4817
4895
  var lower = (name) => TIERS[Math.min(TIERS.indexOf(name) + 1, TIERS.length - 1)];
4818
4896
  var quantile = (xs, q) => {
@@ -4848,21 +4926,22 @@ function shouldDrop(intervals, frame) {
4848
4926
  }
4849
4927
  var ENGINE_VERSION = "0.1.1";
4850
4928
  var DAYS_30 = 30 * 24 * 3600 * 1e3;
4851
- var tierCacheKey = (kind, gpu, screen2) => `fabi-play.engine-tier:${ENGINE_VERSION}:${kind}:${gpu}:${screen2}`;
4852
- var legacyTierCacheKey = (kind, gpu, screen2) => `fablee-engine-tier:${ENGINE_VERSION}:${kind}:${gpu}:${screen2}`;
4929
+ var tierCacheKey = (kind, gpu, screen2) => "fabi-play.engine-tier:".concat(ENGINE_VERSION, ":").concat(kind, ":").concat(gpu, ":").concat(screen2);
4930
+ var legacyTierCacheKey = (kind, gpu, screen2) => "fablee-engine-tier:".concat(ENGINE_VERSION, ":").concat(kind, ":").concat(gpu, ":").concat(screen2);
4853
4931
  function readTier(store, key, now2 = Date.now()) {
4932
+ var _a2;
4854
4933
  try {
4855
- const v = JSON.parse(store?.getItem(key) ?? "null");
4934
+ const v = JSON.parse((_a2 = store == null ? void 0 : store.getItem(key)) != null ? _a2 : "null");
4856
4935
  if (v && TIERS.includes(v.tier) && typeof v.at === "number" && now2 - v.at < DAYS_30)
4857
4936
  return typeof v.refresh === "number" && v.refresh > 0 ? { name: v.tier, refresh: v.refresh } : { name: v.tier };
4858
- } catch {
4937
+ } catch (e) {
4859
4938
  }
4860
4939
  return null;
4861
4940
  }
4862
4941
  function writeTier(store, key, name, refresh, now2 = Date.now()) {
4863
4942
  try {
4864
- store?.setItem(key, JSON.stringify(refresh !== void 0 && Number.isFinite(refresh) ? { tier: name, at: now2, refresh } : { tier: name, at: now2 }));
4865
- } catch {
4943
+ store == null ? void 0 : store.setItem(key, JSON.stringify(refresh !== void 0 && Number.isFinite(refresh) ? { tier: name, at: now2, refresh } : { tier: name, at: now2 }));
4944
+ } catch (e) {
4866
4945
  }
4867
4946
  }
4868
4947
  function tierFromUrl(search = typeof location !== "undefined" ? location.search : "") {
@@ -4870,11 +4949,11 @@ function tierFromUrl(search = typeof location !== "undefined" ? location.search
4870
4949
  return TIERS.includes(v) ? v : void 0;
4871
4950
  }
4872
4951
  function hintedTier(kind, hint) {
4873
- const t = hint?.tier;
4952
+ const t = hint == null ? void 0 : hint.tier;
4874
4953
  if (!TIERS.includes(t)) return void 0;
4875
4954
  return kind === "canvas2d" && t === "high" ? "medium" : t;
4876
4955
  }
4877
- var hintedRefresh = (hint) => typeof hint?.hz === "number" && hint.hz >= 20 && hint.hz <= 240 ? refreshInterval([1e3 / hint.hz], 0.5) : NaN;
4956
+ var hintedRefresh = (hint) => typeof (hint == null ? void 0 : hint.hz) === "number" && hint.hz >= 20 && hint.hz <= 240 ? refreshInterval([1e3 / hint.hz], 0.5) : NaN;
4878
4957
  var lowerOf = (a, b) => TIERS.indexOf(a) >= TIERS.indexOf(b) ? a : b;
4879
4958
  function startTier(forced, hinted, cached) {
4880
4959
  if (forced) return { name: forced, from: "forced" };
@@ -4906,9 +4985,10 @@ var Timeline = class {
4906
4985
  __publicField(this, "yoyo");
4907
4986
  /** Called when the last play ends. */
4908
4987
  __publicField(this, "onComplete");
4909
- this.repeat = Math.floor(o.repeat ?? 0);
4988
+ var _a2, _b;
4989
+ this.repeat = Math.floor((_a2 = o.repeat) != null ? _a2 : 0);
4910
4990
  this.yoyo = !!o.yoyo;
4911
- this.delayLeft = o.delay ?? 0;
4991
+ this.delayLeft = (_b = o.delay) != null ? _b : 0;
4912
4992
  this._paused = !!o.paused;
4913
4993
  this.onComplete = o.onComplete;
4914
4994
  this.promise = new Promise((r) => this.resolve = r);
@@ -4934,7 +5014,7 @@ var Timeline = class {
4934
5014
  if (pos2 === void 0) return this.end;
4935
5015
  if (typeof pos2 === "number") return Math.max(pos2, 0);
4936
5016
  const m = POS.exec(pos2);
4937
- if (!m) throw new Error(`[engine] timeline: bad position "${pos2}"`);
5017
+ if (!m) throw new Error('[engine] timeline: bad position "'.concat(pos2, '"'));
4938
5018
  const [, base, sign, n] = m;
4939
5019
  const off = n ? (sign === "-" ? -1 : 1) * Number(n) : 0;
4940
5020
  let t = this.end;
@@ -4961,9 +5041,10 @@ var Timeline = class {
4961
5041
  * engine.timeline().to(a, { x: 600 }, 0.5).to(b, { alpha: 0 }, 0.3, { at: '<' })
4962
5042
  */
4963
5043
  to(target, to, seconds, ease = "quadOut") {
5044
+ var _a2, _b;
4964
5045
  const o = typeof ease === "object" ? ease : { ease };
4965
- const e = typeof o.ease === "function" ? o.ease : EASE[o.ease ?? "quadOut"];
4966
- return this.add({ target, to, from: null, fn: null, start: this.at(o.at) + (o.delay ?? 0), dur: Math.max(seconds, 0), ease: e, onUpdate: o.onUpdate, p: -1 });
5046
+ const e = typeof o.ease === "function" ? o.ease : EASE[(_a2 = o.ease) != null ? _a2 : "quadOut"];
5047
+ 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 });
4967
5048
  }
4968
5049
  /** Sets fields at once, when the playhead gets there. */
4969
5050
  set(target, values, at) {
@@ -5044,9 +5125,10 @@ var Timeline = class {
5044
5125
  if (e >= total) this.complete();
5045
5126
  }
5046
5127
  complete() {
5128
+ var _a2;
5047
5129
  if (this.done) return;
5048
5130
  this.done = true;
5049
- this.onComplete?.();
5131
+ (_a2 = this.onComplete) == null ? void 0 : _a2.call(this);
5050
5132
  this.resolve();
5051
5133
  }
5052
5134
  /** Writes every step at playhead t: forwards in start order, backwards in reverse (see the file's comment). */
@@ -5066,6 +5148,7 @@ var Timeline = class {
5066
5148
  this.last = t;
5067
5149
  }
5068
5150
  apply(st, t) {
5151
+ var _a2, _b;
5069
5152
  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;
5070
5153
  if (p === st.p) return;
5071
5154
  st.p = p;
@@ -5078,11 +5161,11 @@ var Timeline = class {
5078
5161
  const to = st.to;
5079
5162
  if (!st.from) {
5080
5163
  st.from = {};
5081
- for (const k2 in to) st.from[k2] = Number(target[k2] ?? 0);
5164
+ for (const k2 in to) st.from[k2] = Number((_a2 = target[k2]) != null ? _a2 : 0);
5082
5165
  }
5083
5166
  const k = st.ease(p);
5084
5167
  for (const key in to) target[key] = st.from[key] + (to[key] - st.from[key]) * k;
5085
- st.onUpdate?.(k);
5168
+ (_b = st.onUpdate) == null ? void 0 : _b.call(st, k);
5086
5169
  }
5087
5170
  };
5088
5171
 
@@ -5100,15 +5183,17 @@ var Tweens = class {
5100
5183
  }
5101
5184
  /** Eases target's numeric fields to `to` over `seconds`. */
5102
5185
  tween(target, to, seconds, ease = "quadOut") {
5186
+ var _a2;
5103
5187
  if (target.destroyed || target._free) warnUse(target, "a tween started on it");
5104
5188
  const o = typeof ease === "object" ? ease : { ease };
5105
- const e = typeof o.ease === "function" ? o.ease : EASE[o.ease ?? "quadOut"];
5189
+ const e = typeof o.ease === "function" ? o.ease : EASE[(_a2 = o.ease) != null ? _a2 : "quadOut"];
5106
5190
  let run;
5107
5191
  const p = new Promise((resolve) => {
5192
+ var _a3;
5108
5193
  const keys = Object.keys(to);
5109
5194
  const end = new Float64Array(keys.length);
5110
5195
  keys.forEach((k, i) => end[i] = Number(to[k]));
5111
- run = { target, keys, to: end, from: new Float64Array(keys.length), started: false, duration: Math.max(seconds, 0), time: 0, delay: o.delay ?? 0, ease: e, onUpdate: o.onUpdate, done: resolve, dead: false };
5196
+ run = { target, keys, to: end, from: new Float64Array(keys.length), started: false, duration: Math.max(seconds, 0), time: 0, delay: (_a3 = o.delay) != null ? _a3 : 0, ease: e, onUpdate: o.onUpdate, done: resolve, dead: false };
5112
5197
  });
5113
5198
  this.list.push(run);
5114
5199
  return Object.assign(p, { stop: () => this.finish(run) });
@@ -5145,6 +5230,7 @@ var Tweens = class {
5145
5230
  if (j !== l.length) l.length = j;
5146
5231
  }
5147
5232
  step(r, dt) {
5233
+ var _a2, _b;
5148
5234
  if (r.target.destroyed) return this.finish(r);
5149
5235
  let step = dt;
5150
5236
  if (r.delay > 0) {
@@ -5155,13 +5241,13 @@ var Tweens = class {
5155
5241
  const keys = r.keys;
5156
5242
  if (!r.started) {
5157
5243
  r.started = true;
5158
- for (let i = 0; i < keys.length; i++) r.from[i] = Number(r.target[keys[i]] ?? 0);
5244
+ for (let i = 0; i < keys.length; i++) r.from[i] = Number((_a2 = r.target[keys[i]]) != null ? _a2 : 0);
5159
5245
  }
5160
5246
  r.time += step;
5161
5247
  const t = r.duration > 0 ? Math.min(r.time / r.duration, 1) : 1;
5162
5248
  const k = r.ease(t);
5163
5249
  for (let i = 0; i < keys.length; i++) r.target[keys[i]] = r.from[i] + (r.to[i] - r.from[i]) * k;
5164
- r.onUpdate?.(k);
5250
+ (_b = r.onUpdate) == null ? void 0 : _b.call(r, k);
5165
5251
  if (t >= 1) this.finish(r);
5166
5252
  }
5167
5253
  finish(r) {
@@ -5205,629 +5291,652 @@ var frozenSafeArea = (v) => {
5205
5291
  const sa = parseSafeArea(v);
5206
5292
  return sa && Object.freeze(sa);
5207
5293
  };
5208
- async function createEngine(opts = {}) {
5209
- const play = opts.play ?? null;
5210
- let canvas = opts.canvas ?? null;
5211
- if (!canvas) {
5212
- canvas = document.createElement("canvas");
5213
- canvas.style.cssText = "position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none";
5214
- document.body.appendChild(canvas);
5215
- }
5216
- let renderer = createRenderer(canvas, {
5217
- renderer: opts.renderer ?? rendererFromUrl(),
5218
- failIfMajorPerformanceCaveat: opts.failIfMajorPerformanceCaveat,
5219
- instancing: opts.instancing
5220
- });
5221
- canvas = renderer.canvas;
5222
- const surfaces = /* @__PURE__ */ new Set();
5223
- const atlas = new Atlas(Math.min(2048, renderer.maxTextureSize), 4);
5224
- atlas.onPage = (s) => surfaces.add(s);
5225
- atlas.onDrop = (s) => {
5226
- surfaces.delete(s);
5227
- if (s.texture) renderer.destroyTexture(s.texture);
5228
- s.texture = null;
5229
- };
5230
- let tex = textureOf(renderer);
5231
- const tweens = new Tweens();
5232
- const sound = new Sound();
5233
- const painter = new AvatarPainter(atlas);
5234
- const shapeCaches = /* @__PURE__ */ new Map();
5235
- const frames = /* @__PURE__ */ new Map();
5236
- const bakes = /* @__PURE__ */ new Map();
5237
- const bitmapFonts = /* @__PURE__ */ new Map();
5238
- const animations = /* @__PURE__ */ new Map();
5239
- const tagSets = /* @__PURE__ */ new Set();
5240
- let fontGen = 0;
5241
- const forced = opts.tier ?? tierFromUrl();
5242
- const gpu = String(renderer.info.renderer ?? "");
5243
- const store = (() => {
5244
- try {
5245
- return globalThis.localStorage ?? null;
5246
- } catch {
5247
- return null;
5248
- }
5249
- })();
5250
- const screenSize = typeof screen !== "undefined" ? `${screen.width}x${screen.height}` : "";
5251
- const cacheKey = tierCacheKey(renderer.kind, gpu, screenSize);
5252
- migrateStorageKey(store, cacheKey, legacyTierCacheKey(renderer.kind, gpu, screenSize));
5253
- const cached = readTier(store, cacheKey);
5254
- const start = startTier(forced, hintedTier(renderer.kind, play?.device), cached?.name);
5255
- let tierName = start?.name ?? "medium";
5256
- let tierObj = tier(tierName);
5257
- painter.setTier(tierName);
5258
- let hinted = start?.from === "hint";
5259
- let ceiling = cached?.name;
5260
- let refresh = cached?.refresh ?? hintedRefresh(play?.device);
5261
- let pixelScale = 1;
5262
- let cssW = 1;
5263
- let cssH = 1;
5264
- const kernel = {
5265
- atlas,
5266
- get pixelScale() {
5267
- return pixelScale;
5268
- },
5269
- get fontGen() {
5270
- return fontGen;
5271
- },
5272
- get effects() {
5273
- return tierObj.effects;
5274
- },
5275
- tweens,
5276
- frame: (name) => engine.frame(name),
5277
- shape: (spec) => {
5278
- const fx2 = tierObj.effects;
5279
- const v = fx2 ? pixelScale : -pixelScale;
5280
- let cache2 = shapeCaches.get(v);
5281
- if (!cache2) {
5282
- if (shapeCaches.size >= 8) shapeCaches.clear();
5283
- shapeCaches.set(v, cache2 = new KeyCache(2e3));
5294
+ function createEngine() {
5295
+ return __async(this, arguments, function* (opts = {}) {
5296
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
5297
+ const play = (_a2 = opts.play) != null ? _a2 : null;
5298
+ let canvas = (_b = opts.canvas) != null ? _b : null;
5299
+ if (!canvas) {
5300
+ canvas = document.createElement("canvas");
5301
+ canvas.style.cssText = "position:fixed;top:0;left:0;width:100%;height:100%;display:block;touch-action:none";
5302
+ document.body.appendChild(canvas);
5303
+ }
5304
+ let renderer = createRenderer(canvas, {
5305
+ renderer: (_c = opts.renderer) != null ? _c : rendererFromUrl(),
5306
+ failIfMajorPerformanceCaveat: opts.failIfMajorPerformanceCaveat,
5307
+ instancing: opts.instancing
5308
+ });
5309
+ canvas = renderer.canvas;
5310
+ const surfaces = /* @__PURE__ */ new Set();
5311
+ const atlas = new Atlas(Math.min(2048, renderer.maxTextureSize), 4);
5312
+ atlas.onPage = (s) => surfaces.add(s);
5313
+ atlas.onDrop = (s) => {
5314
+ surfaces.delete(s);
5315
+ if (s.texture) renderer.destroyTexture(s.texture);
5316
+ s.texture = null;
5317
+ };
5318
+ let tex = textureOf(renderer);
5319
+ const tweens = new Tweens();
5320
+ const sound = new Sound();
5321
+ const painter = new AvatarPainter(atlas);
5322
+ const shapeCaches = /* @__PURE__ */ new Map();
5323
+ const frames = /* @__PURE__ */ new Map();
5324
+ const bakes = /* @__PURE__ */ new Map();
5325
+ const bitmapFonts = /* @__PURE__ */ new Map();
5326
+ const animations = /* @__PURE__ */ new Map();
5327
+ const tagSets = /* @__PURE__ */ new Set();
5328
+ let fontGen = 0;
5329
+ const forced = (_d = opts.tier) != null ? _d : tierFromUrl();
5330
+ const gpu = String((_e = renderer.info.renderer) != null ? _e : "");
5331
+ const store = (() => {
5332
+ var _a3;
5333
+ try {
5334
+ return (_a3 = __fabiGlobalThis.localStorage) != null ? _a3 : null;
5335
+ } catch (e) {
5336
+ return null;
5284
5337
  }
5285
- const h = hash(spec);
5286
- let b = cache2.get(spec, h);
5287
- if (!b || !atlas.valid(b.frame)) {
5288
- cache2.set(spec, b = bakeShape(atlas, forTier(spec, fx2), pixelScale), h);
5338
+ })();
5339
+ const screenSize = typeof screen !== "undefined" ? "".concat(screen.width, "x").concat(screen.height) : "";
5340
+ const cacheKey = tierCacheKey(renderer.kind, gpu, screenSize);
5341
+ migrateStorageKey(store, cacheKey, legacyTierCacheKey(renderer.kind, gpu, screenSize));
5342
+ const cached = readTier(store, cacheKey);
5343
+ const start = startTier(forced, hintedTier(renderer.kind, play == null ? void 0 : play.device), cached == null ? void 0 : cached.name);
5344
+ let tierName = (_f = start == null ? void 0 : start.name) != null ? _f : "medium";
5345
+ let tierObj = tier(tierName);
5346
+ painter.setTier(tierName);
5347
+ let hinted = (start == null ? void 0 : start.from) === "hint";
5348
+ let ceiling = cached == null ? void 0 : cached.name;
5349
+ let refresh = (_g = cached == null ? void 0 : cached.refresh) != null ? _g : hintedRefresh(play == null ? void 0 : play.device);
5350
+ let pixelScale = 1;
5351
+ let cssW = 1;
5352
+ let cssH = 1;
5353
+ const kernel = {
5354
+ atlas,
5355
+ get pixelScale() {
5356
+ return pixelScale;
5357
+ },
5358
+ get fontGen() {
5359
+ return fontGen;
5360
+ },
5361
+ get effects() {
5362
+ return tierObj.effects;
5363
+ },
5364
+ tweens,
5365
+ frame: (name) => engine.frame(name),
5366
+ shape: (spec) => {
5367
+ const fx2 = tierObj.effects;
5368
+ const v = fx2 ? pixelScale : -pixelScale;
5369
+ let cache2 = shapeCaches.get(v);
5370
+ if (!cache2) {
5371
+ if (shapeCaches.size >= 8) shapeCaches.clear();
5372
+ shapeCaches.set(v, cache2 = new KeyCache(2e3));
5373
+ }
5374
+ const h = hash(spec);
5375
+ let b = cache2.get(spec, h);
5376
+ if (!b || !atlas.valid(b.frame)) {
5377
+ cache2.set(spec, b = bakeShape(atlas, forTier(spec, fx2), pixelScale), h);
5378
+ }
5379
+ return b;
5380
+ },
5381
+ bitmapFont: (name) => engine.bitmapFont(name)
5382
+ };
5383
+ let stageW = 1280;
5384
+ let hudEl = null;
5385
+ class StageGroup extends Group {
5386
+ get width() {
5387
+ return stageW;
5388
+ }
5389
+ set width(_) {
5390
+ }
5391
+ get height() {
5392
+ return STAGE_HEIGHT;
5393
+ }
5394
+ set height(_) {
5395
+ }
5396
+ get safe() {
5397
+ const w2 = Math.min(stageW, STAGE_HEIGHT * 16 / 9);
5398
+ return { x: (stageW - w2) / 2, y: 0, w: w2, h: STAGE_HEIGHT };
5289
5399
  }
5290
- return b;
5291
- },
5292
- bitmapFont: (name) => engine.bitmapFont(name)
5293
- };
5294
- let stageW = 1280;
5295
- let hudEl = null;
5296
- class StageGroup extends Group {
5297
- get width() {
5298
- return stageW;
5299
- }
5300
- set width(_) {
5301
- }
5302
- get height() {
5303
- return STAGE_HEIGHT;
5304
- }
5305
- set height(_) {
5306
- }
5307
- get safe() {
5308
- const w2 = Math.min(stageW, STAGE_HEIGHT * 16 / 9);
5309
- return { x: (stageW - w2) / 2, y: 0, w: w2, h: STAGE_HEIGHT };
5310
5400
  }
5311
- }
5312
- const stage = new StageGroup(kernel);
5313
- const resize = () => {
5314
- const c = renderer.canvas;
5315
- const r = c.getBoundingClientRect();
5316
- cssW = Math.max(1, r.width || c.clientWidth || innerWidth);
5317
- cssH = Math.max(1, r.height || c.clientHeight || innerHeight);
5318
- stageW = STAGE_HEIGHT * cssW / cssH;
5319
- const dpr = Math.min(globalThis.devicePixelRatio || 1, opts.maxPixelRatio ?? 2);
5320
- const want = cssH * dpr / STAGE_HEIGHT;
5321
- if (want <= tierObj.resolution) {
5322
- const h = Math.max(1, Math.round(cssH * dpr));
5323
- pixelScale = h / STAGE_HEIGHT;
5324
- renderer.resize(Math.max(1, Math.round(cssW * dpr)), h);
5325
- } else {
5326
- pixelScale = tierObj.resolution;
5327
- renderer.resize(Math.round(stageW * pixelScale), Math.round(STAGE_HEIGHT * pixelScale));
5401
+ const stage = new StageGroup(kernel);
5402
+ const resize = () => {
5403
+ var _a3;
5404
+ const c = renderer.canvas;
5405
+ const r = c.getBoundingClientRect();
5406
+ cssW = Math.max(1, r.width || c.clientWidth || innerWidth);
5407
+ cssH = Math.max(1, r.height || c.clientHeight || innerHeight);
5408
+ stageW = STAGE_HEIGHT * cssW / cssH;
5409
+ const dpr = Math.min(__fabiGlobalThis.devicePixelRatio || 1, (_a3 = opts.maxPixelRatio) != null ? _a3 : 2);
5410
+ const want = cssH * dpr / STAGE_HEIGHT;
5411
+ if (want <= tierObj.resolution) {
5412
+ const h = Math.max(1, Math.round(cssH * dpr));
5413
+ pixelScale = h / STAGE_HEIGHT;
5414
+ renderer.resize(Math.max(1, Math.round(cssW * dpr)), h);
5415
+ } else {
5416
+ pixelScale = tierObj.resolution;
5417
+ renderer.resize(Math.round(stageW * pixelScale), Math.round(STAGE_HEIGHT * pixelScale));
5418
+ }
5419
+ if (hudEl) hudEl.style.setProperty("--unit", "".concat(cssH / STAGE_HEIGHT, "px"));
5420
+ };
5421
+ addEventListener("resize", resize);
5422
+ const setTier = (name) => {
5423
+ tierName = name;
5424
+ tierObj = tier(name);
5425
+ painter.setTier(name);
5426
+ resize();
5427
+ };
5428
+ const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(resize) : null;
5429
+ ro == null ? void 0 : ro.observe(canvas);
5430
+ let backdrop = (play == null ? void 0 : play.backdrop) === "video" ? "video" : "none";
5431
+ let view = (_h = play == null ? void 0 : play.view) != null ? _h : null;
5432
+ let orientation = (play == null ? void 0 : play.orientation) === "portrait" ? "portrait" : "landscape";
5433
+ let safeArea = (_i = frozenSafeArea(play == null ? void 0 : play.safeArea)) != null ? _i : NO_SAFE_AREA;
5434
+ let livePlayers = [];
5435
+ let lastPlayersAt = -Infinity;
5436
+ let hostPaused = false;
5437
+ let userPaused = false;
5438
+ const backdropListeners = /* @__PURE__ */ new Set();
5439
+ const applyBackdrop = () => {
5440
+ const color = backdrop === "video" ? "transparent" : "";
5441
+ document.documentElement.style.background = color;
5442
+ document.body.style.background = color;
5443
+ };
5444
+ const setBackdrop = (b, v) => {
5445
+ const next = b === "video" ? "video" : "none";
5446
+ const nv = v != null ? v : null;
5447
+ if (next === backdrop && (nv === view || nv && view && nv.x === view.x && nv.y === view.y && nv.w === view.w && nv.h === view.h)) return;
5448
+ backdrop = next;
5449
+ view = nv;
5450
+ applyBackdrop();
5451
+ for (const l of [...backdropListeners]) l(backdrop, view);
5452
+ };
5453
+ const unlisten = [];
5454
+ if (play) {
5455
+ const setPlayers = (p) => {
5456
+ if (Array.isArray(p)) {
5457
+ livePlayers = p;
5458
+ lastPlayersAt = now();
5459
+ }
5460
+ };
5461
+ const hold2 = (on) => {
5462
+ hostPaused = on;
5463
+ syncSound();
5464
+ };
5465
+ const lateHint = (device) => {
5466
+ if (forced || hinted) return;
5467
+ if (!Number.isFinite(refresh)) refresh = hintedRefresh(device);
5468
+ const h = hintedTier(renderer.kind, device);
5469
+ if (!h) return;
5470
+ hinted = true;
5471
+ setTier(ceiling ? lowerOf(h, ceiling) : h);
5472
+ };
5473
+ unlisten.push(
5474
+ play.on("start", (m) => lateHint(m == null ? void 0 : m.device)),
5475
+ play.on("start", (m) => {
5476
+ if ((m == null ? void 0 : m.orientation) === "portrait" || (m == null ? void 0 : m.orientation) === "landscape") orientation = m.orientation;
5477
+ const sa = frozenSafeArea(m == null ? void 0 : m.safeArea);
5478
+ if (sa) safeArea = sa;
5479
+ }),
5480
+ // The simple API knows muted only from the start (its getter is false before): read it again then.
5481
+ play.on("start", (m) => {
5482
+ if (typeof (m == null ? void 0 : m.muted) === "boolean") sound.muted = m.muted;
5483
+ }),
5484
+ play.on("frame", (m) => setPlayers(m == null ? void 0 : m.players)),
5485
+ play.on("players", (m) => setPlayers(m == null ? void 0 : m.players)),
5486
+ play.on("backdrop", (m) => setBackdrop(m == null ? void 0 : m.backdrop, m == null ? void 0 : m.view)),
5487
+ play.on("start", (m) => {
5488
+ var _a3;
5489
+ return setBackdrop(m == null ? void 0 : m.backdrop, (_a3 = m == null ? void 0 : m.view) != null ? _a3 : play.view);
5490
+ }),
5491
+ play.on("pause", () => hold2(true)),
5492
+ play.on("resume", () => hold2(false)),
5493
+ play.on("break-start", () => hold2(true)),
5494
+ play.on("break-done", () => hold2(false)),
5495
+ play.on("break-end", () => hold2(false))
5496
+ );
5497
+ sound.muted = play.muted === true;
5328
5498
  }
5329
- if (hudEl) hudEl.style.setProperty("--unit", `${cssH / STAGE_HEIGHT}px`);
5330
- };
5331
- addEventListener("resize", resize);
5332
- const setTier = (name) => {
5333
- tierName = name;
5334
- tierObj = tier(name);
5335
- painter.setTier(name);
5336
- resize();
5337
- };
5338
- const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(resize) : null;
5339
- ro?.observe(canvas);
5340
- let backdrop = play?.backdrop === "video" ? "video" : "none";
5341
- let view = play?.view ?? null;
5342
- let orientation = play?.orientation === "portrait" ? "portrait" : "landscape";
5343
- let safeArea = frozenSafeArea(play?.safeArea) ?? NO_SAFE_AREA;
5344
- let livePlayers = [];
5345
- let lastPlayersAt = -Infinity;
5346
- let hostPaused = false;
5347
- let userPaused = false;
5348
- const backdropListeners = /* @__PURE__ */ new Set();
5349
- const applyBackdrop = () => {
5350
- const color = backdrop === "video" ? "transparent" : "";
5351
- document.documentElement.style.background = color;
5352
- document.body.style.background = color;
5353
- };
5354
- const setBackdrop = (b, v) => {
5355
- const next = b === "video" ? "video" : "none";
5356
- const nv = v ?? null;
5357
- if (next === backdrop && (nv === view || nv && view && nv.x === view.x && nv.y === view.y && nv.w === view.w && nv.h === view.h)) return;
5358
- backdrop = next;
5359
- view = nv;
5360
5499
  applyBackdrop();
5361
- for (const l of [...backdropListeners]) l(backdrop, view);
5362
- };
5363
- const unlisten = [];
5364
- if (play) {
5365
- const setPlayers = (p) => {
5366
- if (Array.isArray(p)) {
5367
- livePlayers = p;
5368
- lastPlayersAt = now();
5369
- }
5500
+ const syncSound = () => hostPaused || userPaused || document.hidden ? sound.hold() : sound.release();
5501
+ let handsAt = -1;
5502
+ let handsCache = [];
5503
+ let tick = 0;
5504
+ const live = () => now() - lastPlayersAt < 1e3 ? livePlayers : [];
5505
+ const toScreen2 = (p) => play ? play.toScreen(p) : toScreen(view, p);
5506
+ const hold = new AimHold();
5507
+ const allHands = () => {
5508
+ if (handsAt === tick) return handsCache;
5509
+ handsAt = tick;
5510
+ const portrait = orientation === "portrait";
5511
+ const bodyOf = backdrop === "video" && !portrait || !(play == null ? void 0 : play.smoothedBody) ? () => null : (f) => play.smoothedBody(f);
5512
+ handsCache = handsOf(live(), toScreen2, stageW, STAGE_HEIGHT, bodyOf, portrait ? { orientation, hold, t: now() } : void 0);
5513
+ return handsCache;
5370
5514
  };
5371
- const hold2 = (on) => {
5372
- hostPaused = on;
5373
- syncSound();
5515
+ const box = { x: 0, y: 0, w: 1, h: 1 };
5516
+ const avatarBox = () => {
5517
+ box.x = view ? view.x * stageW : 0;
5518
+ box.y = view ? view.y * STAGE_HEIGHT : 0;
5519
+ box.w = view ? view.w * stageW : stageW;
5520
+ box.h = view ? view.h * STAGE_HEIGHT : STAGE_HEIGHT;
5521
+ return box;
5374
5522
  };
5375
- const lateHint = (device) => {
5376
- if (forced || hinted) return;
5377
- if (!Number.isFinite(refresh)) refresh = hintedRefresh(device);
5378
- const h = hintedTier(renderer.kind, device);
5379
- if (!h) return;
5380
- hinted = true;
5381
- setTier(ceiling ? lowerOf(h, ceiling) : h);
5523
+ const paintAvatars = (o) => {
5524
+ var _a3;
5525
+ const alpha = (_a3 = o.alpha) != null ? _a3 : 1;
5526
+ const tags = o.tags ? new NameTags(atlas, o) : null;
5527
+ if (tags) tagSets.add(tags);
5528
+ const tagOf = typeof o.tags === "function" ? o.tags : (p) => String(p);
5529
+ return (ctx2, a) => {
5530
+ var _a4, _b2, _c2, _d2, _e2, _f2;
5531
+ if (backdrop === "video") return;
5532
+ const b = avatarBox();
5533
+ for (const f of live()) {
5534
+ const body = (_b2 = (_a4 = play == null ? void 0 : play.smoothedBody) == null ? void 0 : _a4.call(play, f)) != null ? _b2 : f.body;
5535
+ const def = (_f2 = avatarById((_e2 = (_d2 = (_c2 = play == null ? void 0 : play.avatarOf) == null ? void 0 : _c2.call(play, f)) != null ? _d2 : f.avatar) != null ? _e2 : "")) != null ? _f2 : DEFAULT_AVATAR;
5536
+ if (!painter.draw(ctx2.r, ctx2.tex, body, def, b, alpha * a, pixelScale) || !tags) continue;
5537
+ const name = tagOf(f.id);
5538
+ if (name) tags.draw(ctx2.r, ctx2.tex, body, def, b, name, playerColor(f.id), alpha * a, pixelScale, stageW, STAGE_HEIGHT);
5539
+ }
5540
+ };
5382
5541
  };
5383
- unlisten.push(
5384
- play.on("start", (m) => lateHint(m?.device)),
5385
- play.on("start", (m) => {
5386
- if (m?.orientation === "portrait" || m?.orientation === "landscape") orientation = m.orientation;
5387
- const sa = frozenSafeArea(m?.safeArea);
5388
- if (sa) safeArea = sa;
5389
- }),
5390
- // The simple API knows muted only from the start (its getter is false before): read it again then.
5391
- play.on("start", (m) => {
5392
- if (typeof m?.muted === "boolean") sound.muted = m.muted;
5393
- }),
5394
- play.on("frame", (m) => setPlayers(m?.players)),
5395
- play.on("players", (m) => setPlayers(m?.players)),
5396
- play.on("backdrop", (m) => setBackdrop(m?.backdrop, m?.view)),
5397
- play.on("start", (m) => setBackdrop(m?.backdrop, m?.view ?? play.view)),
5398
- play.on("pause", () => hold2(true)),
5399
- play.on("resume", () => hold2(false)),
5400
- play.on("break-start", () => hold2(true)),
5401
- play.on("break-done", () => hold2(false)),
5402
- play.on("break-end", () => hold2(false))
5403
- );
5404
- sound.muted = play.muted === true;
5405
- }
5406
- applyBackdrop();
5407
- const syncSound = () => hostPaused || userPaused || document.hidden ? sound.hold() : sound.release();
5408
- let handsAt = -1;
5409
- let handsCache = [];
5410
- let tick = 0;
5411
- const live = () => now() - lastPlayersAt < 1e3 ? livePlayers : [];
5412
- const toScreen2 = (p) => play ? play.toScreen(p) : toScreen(view, p);
5413
- const hold = new AimHold();
5414
- const allHands = () => {
5415
- if (handsAt === tick) return handsCache;
5416
- handsAt = tick;
5417
- const portrait = orientation === "portrait";
5418
- const bodyOf = backdrop === "video" && !portrait || !play?.smoothedBody ? () => null : (f) => play.smoothedBody(f);
5419
- handsCache = handsOf(live(), toScreen2, stageW, STAGE_HEIGHT, bodyOf, portrait ? { orientation, hold, t: now() } : void 0);
5420
- return handsCache;
5421
- };
5422
- const box = { x: 0, y: 0, w: 1, h: 1 };
5423
- const avatarBox = () => {
5424
- box.x = view ? view.x * stageW : 0;
5425
- box.y = view ? view.y * STAGE_HEIGHT : 0;
5426
- box.w = view ? view.w * stageW : stageW;
5427
- box.h = view ? view.h * STAGE_HEIGHT : STAGE_HEIGHT;
5428
- return box;
5429
- };
5430
- const paintAvatars = (o) => {
5431
- const alpha = o.alpha ?? 1;
5432
- const tags = o.tags ? new NameTags(atlas, o) : null;
5433
- if (tags) tagSets.add(tags);
5434
- const tagOf = typeof o.tags === "function" ? o.tags : (p) => String(p);
5435
- return (ctx2, a) => {
5436
- if (backdrop === "video") return;
5437
- const b = avatarBox();
5438
- for (const f of live()) {
5439
- const body = play?.smoothedBody?.(f) ?? f.body;
5440
- const def = avatarById(play?.avatarOf?.(f) ?? f.avatar ?? "") ?? DEFAULT_AVATAR;
5441
- if (!painter.draw(ctx2.r, ctx2.tex, body, def, b, alpha * a, pixelScale) || !tags) continue;
5442
- const name = tagOf(f.id);
5443
- if (name) tags.draw(ctx2.r, ctx2.tex, body, def, b, name, playerColor(f.id), alpha * a, pixelScale, stageW, STAGE_HEIGHT);
5444
- }
5542
+ const updates = /* @__PURE__ */ new Set();
5543
+ const renders = /* @__PURE__ */ new Set();
5544
+ const tickers = /* @__PURE__ */ new Set();
5545
+ let running = false;
5546
+ let raf = 0;
5547
+ let last2 = 0;
5548
+ let time = 0;
5549
+ const stats = { fps: 0, cpuMs: 0, drawCalls: 0, quads: 0, filtersSkipped: 0 };
5550
+ let statFrames = 0;
5551
+ let statCpu = 0;
5552
+ let statSince = now();
5553
+ const windowIntervals = [];
5554
+ let lostSince = 0;
5555
+ const drawCtx = () => ({ r: renderer, kernel, tex });
5556
+ let ctx = drawCtx();
5557
+ const render = () => {
5558
+ if (renderer.lost) return;
5559
+ const [rgb, a] = backdrop === "video" || opts.background === void 0 ? [0, 0] : parseColor(opts.background);
5560
+ renderer.time = time;
5561
+ renderer.maxBlur = tierObj.maxBlur;
5562
+ renderer.begin(rgb, a, pixelScale);
5563
+ composeMat(stage.world, null, stage.x, stage.y, stage.rotation, stage.scaleX, stage.scaleY);
5564
+ drawNode(ctx, stage, stage.alpha, stage.tint);
5565
+ const s = renderer.end();
5566
+ stats.drawCalls = s.drawCalls;
5567
+ stats.quads = s.quads;
5568
+ stats.filtersSkipped = s.filtersSkipped;
5445
5569
  };
5446
- };
5447
- const updates = /* @__PURE__ */ new Set();
5448
- const renders = /* @__PURE__ */ new Set();
5449
- const tickers = /* @__PURE__ */ new Set();
5450
- let running = false;
5451
- let raf = 0;
5452
- let last2 = 0;
5453
- let time = 0;
5454
- const stats = { fps: 0, cpuMs: 0, drawCalls: 0, quads: 0, filtersSkipped: 0 };
5455
- let statFrames = 0;
5456
- let statCpu = 0;
5457
- let statSince = now();
5458
- const windowIntervals = [];
5459
- let lostSince = 0;
5460
- const drawCtx = () => ({ r: renderer, kernel, tex });
5461
- let ctx = drawCtx();
5462
- const render = () => {
5463
- if (renderer.lost) return;
5464
- const [rgb, a] = backdrop === "video" || opts.background === void 0 ? [0, 0] : parseColor(opts.background);
5465
- renderer.time = time;
5466
- renderer.maxBlur = tierObj.maxBlur;
5467
- renderer.begin(rgb, a, pixelScale);
5468
- composeMat(stage.world, null, stage.x, stage.y, stage.rotation, stage.scaleX, stage.scaleY);
5469
- drawNode(ctx, stage, stage.alpha, stage.tint);
5470
- const s = renderer.end();
5471
- stats.drawCalls = s.drawCalls;
5472
- stats.quads = s.quads;
5473
- stats.filtersSkipped = s.filtersSkipped;
5474
- };
5475
- const frame = (t) => {
5476
- if (!running) return;
5477
- raf = requestAnimationFrame(frame);
5478
- const dt = Math.min(Math.max((t - last2) / 1e3, 0), 0.1);
5479
- if (last2) windowIntervals.push(t - last2);
5480
- last2 = t;
5481
- tick++;
5482
- const t0 = now();
5483
- const paused = hostPaused || userPaused;
5484
- if (!paused) {
5485
- time += dt;
5486
- tweens.update(dt);
5487
- for (const p of tickers) if (!p.destroyed) p.update(dt);
5488
- for (const fn of updates) fn(dt, time);
5489
- }
5490
- for (const fn of renders) fn(dt);
5491
- stage.sweep();
5492
- for (const p of tickers) if (p.destroyed) tickers.delete(p);
5493
- if (renderer.lost) {
5494
- lostSince || (lostSince = t);
5495
- if (t - lostSince > 3e3) switchToCanvas2D();
5496
- } else {
5497
- lostSince = 0;
5498
- render();
5499
- }
5500
- statFrames++;
5501
- statCpu += now() - t0;
5502
- if (t0 - statSince >= 1e3) {
5503
- stats.fps = Math.round(statFrames * 1e3 / (t0 - statSince));
5504
- stats.cpuMs = Math.round(statCpu / Math.max(statFrames, 1) * 100) / 100;
5505
- play?.reportStats?.({ fps: stats.fps, renderer: renderer.kind, tier: tierName });
5506
- statFrames = 0;
5507
- statCpu = 0;
5508
- statSince = t0;
5509
- }
5510
- if (windowIntervals.length >= 180) {
5511
- const display = Number.isFinite(refresh) ? refresh : refreshInterval(windowIntervals);
5512
- if (!forced && !paused && shouldDrop(windowIntervals, display) && tierName !== "low") {
5513
- setTier(lower(tierName));
5514
- ceiling = tierName;
5515
- writeTier(store, cacheKey, tierName, Number.isFinite(refresh) ? refresh : void 0);
5516
- console.info(`[engine] slow frames: tier ${tierName}`);
5570
+ const frame = (t) => {
5571
+ var _a3;
5572
+ if (!running) return;
5573
+ raf = requestAnimationFrame(frame);
5574
+ const dt = Math.min(Math.max((t - last2) / 1e3, 0), 0.1);
5575
+ if (last2) windowIntervals.push(t - last2);
5576
+ last2 = t;
5577
+ tick++;
5578
+ const t0 = now();
5579
+ const paused = hostPaused || userPaused;
5580
+ if (!paused) {
5581
+ time += dt;
5582
+ tweens.update(dt);
5583
+ for (const p of tickers) if (!p.destroyed) p.update(dt);
5584
+ for (const fn of updates) fn(dt, time);
5517
5585
  }
5518
- windowIntervals.length = 0;
5519
- }
5520
- };
5521
- const switchToCanvas2D = () => {
5522
- const c = freshCanvas(renderer.canvas);
5523
- const r = createCanvas2D(c);
5524
- if (!r) return;
5525
- console.warn("[engine] WebGL context lost for good: switching to Canvas 2D");
5526
- renderer.destroy();
5527
- renderer = r;
5528
- for (const s of surfaces) s.texture = null;
5529
- for (const p of atlas.pages) surfaces.add(p.surface);
5530
- tex = textureOf(renderer);
5531
- ctx = drawCtx();
5532
- ro?.disconnect();
5533
- ro?.observe(c);
5534
- resize();
5535
- };
5536
- const onVisibility = () => {
5537
- syncSound();
5538
- if (!document.hidden) last2 = 0;
5539
- };
5540
- document.addEventListener("visibilitychange", onVisibility);
5541
- const onFonts = () => {
5542
- fontGen++;
5543
- for (const t of tagSets) t.drop();
5544
- };
5545
- document.fonts?.addEventListener?.("loadingdone", onFonts);
5546
- resize();
5547
- if (!start && opts.probe !== false) {
5548
- if (!Number.isFinite(refresh)) refresh = displayInterval(await idleIntervals(IDLE_FRAMES));
5549
- if (!hinted) {
5550
- tierObj = tier("high");
5551
- resize();
5552
- const result = await probe(renderer, atlas, () => tex, () => pixelScale, stageW, () => hinted);
5553
- result.refresh = refresh;
5554
- if (!hinted) {
5555
- const picked = pickTier(renderer.kind, result);
5556
- writeTier(store, cacheKey, picked, refresh);
5557
- ceiling = picked;
5558
- setTier(picked);
5586
+ for (const fn of renders) fn(dt);
5587
+ stage.sweep();
5588
+ for (const p of tickers) if (p.destroyed) tickers.delete(p);
5589
+ if (renderer.lost) {
5590
+ lostSince || (lostSince = t);
5591
+ if (t - lostSince > 3e3) switchToCanvas2D();
5592
+ } else {
5593
+ lostSince = 0;
5594
+ render();
5559
5595
  }
5560
- }
5561
- }
5562
- const engine = {
5563
- stage,
5564
- get tier() {
5565
- return tierObj;
5566
- },
5567
- get renderer() {
5568
- return renderer;
5569
- },
5570
- get canvas() {
5571
- return renderer.canvas;
5572
- },
5573
- get pixelScale() {
5574
- return pixelScale;
5575
- },
5576
- get backdrop() {
5577
- return backdrop;
5578
- },
5579
- get view() {
5580
- return view;
5581
- },
5582
- get orientation() {
5583
- return orientation;
5584
- },
5585
- get safeArea() {
5586
- return safeArea;
5587
- },
5588
- get paused() {
5589
- return hostPaused || userPaused;
5590
- },
5591
- sound,
5592
- stats,
5593
- get time() {
5594
- return time;
5595
- },
5596
- get supports() {
5597
- const s = renderer.support;
5598
- return {
5599
- filters: s.filters,
5600
- blur: s.filters && tierObj.maxBlur > 0,
5601
- shaders: s.shaders,
5602
- maxBlur: s.filters ? tierObj.maxBlur : 0,
5603
- tiers: { high: { maxBlur: tier("high").maxBlur }, medium: { maxBlur: tier("medium").maxBlur }, low: { maxBlur: tier("low").maxBlur } }
5604
- };
5605
- },
5606
- sprite: (f, props) => new Sprite(kernel, f, props),
5607
- shape: (spec, props) => new Shape(kernel, spec, props),
5608
- text: (t, style) => new Text(kernel, t, style),
5609
- group: (props) => new Group(kernel).set(props ?? {}),
5610
- particles(f, o = {}) {
5611
- const fr = typeof f === "object" && "type" in f ? kernel.shape(f).frame : f;
5612
- const p = new Particles(kernel, fr, o);
5613
- const { max: _m, blend: _b, gravity: _g, drag: _d, ...props } = o;
5614
- p.set(props);
5615
- tickers.add(p);
5616
- return p;
5617
- },
5618
- tween: (target, to, seconds, ease) => tweens.tween(target, to, seconds, ease),
5619
- bake(name, w2, h, draw, origin) {
5620
- bakes.set(name, { w: w2, h, draw, origin });
5621
- frames.delete(name);
5622
- return engine.frame(name);
5623
- },
5624
- frame(name) {
5625
- const f = frames.get(name);
5626
- if (f && atlas.valid(f) && (f.gen === 0 || f.scale === pixelScale)) return f;
5627
- const b = bakes.get(name);
5628
- if (b) {
5629
- const k = pixelScale;
5630
- const nf = atlas.bake(b.w * k, b.h * k, (c) => (c.scale(k, k), b.draw(c)), k, b.origin?.x ?? 0, b.origin?.y ?? 0);
5631
- frames.set(name, nf);
5632
- return nf;
5596
+ statFrames++;
5597
+ statCpu += now() - t0;
5598
+ if (t0 - statSince >= 1e3) {
5599
+ stats.fps = Math.round(statFrames * 1e3 / (t0 - statSince));
5600
+ stats.cpuMs = Math.round(statCpu / Math.max(statFrames, 1) * 100) / 100;
5601
+ (_a3 = play == null ? void 0 : play.reportStats) == null ? void 0 : _a3.call(play, { fps: stats.fps, renderer: renderer.kind, tier: tierName });
5602
+ statFrames = 0;
5603
+ statCpu = 0;
5604
+ statSince = t0;
5633
5605
  }
5634
- if (f) return f;
5635
- throw new Error(`[engine] no frame "${name}": load it or bake it first`);
5636
- },
5637
- async load(assets) {
5638
- await Promise.all(Object.entries(assets).map(([name, url]) => loadAsset(name, url)));
5639
- },
5640
- hands: (player) => player === void 0 ? allHands() : allHands().filter((h) => h.player === player),
5641
- touched(node, player, o = {}) {
5642
- node.updateWorld();
5643
- return touching(node, allHands(), player, o.padding ?? 0);
5644
- },
5645
- hits(node, x, y, padding = 0) {
5646
- node.updateWorld();
5647
- return hits(node, x, y, padding);
5648
- },
5649
- avatars: (o = {}) => new AvatarsNode(kernel, paintAvatars(o)),
5650
- handMarkers(o = {}) {
5651
- const r = o.radius ?? 36;
5652
- const look = o.look ?? "auto";
5653
- const handMat = new Float64Array(6);
5654
- const lw = Math.max(r * 0.12, 3);
5655
- const ring = { type: "ring", r, lw, fill: "rgba(251,231,184,0.3)", stroke: "#ffffff" };
5656
- const halo = { type: "ring", r, lw: lw * 1.8, stroke: HALO, shadow: { color: HALO, blur: r * 0.2 } };
5657
- const put = (c, f, x, y, tint2, a) => {
5658
- const w2 = f.w / f.scale;
5659
- composeMat(handMat, null, x - w2 / 2, y - w2 / 2, 0, 1, 1);
5660
- c.r.quad(c.tex(f.surface), f, handMat, w2, w2, tint2, a, "normal");
5661
- };
5662
- const memo = (spec) => {
5663
- let b = null;
5664
- let fx2 = false;
5665
- return () => (b && atlas.valid(b.frame) && b.frame.scale === pixelScale && fx2 === tierObj.effects ? b : (fx2 = tierObj.effects, b = kernel.shape(spec))).frame;
5666
- };
5667
- const ringOf = memo(ring);
5668
- const haloOf = memo(halo);
5669
- return new HandMarkers(kernel, (c, a) => {
5670
- const video = look === "video" || look === "auto" && backdrop === "video";
5671
- const b = ringOf();
5672
- const u = video ? haloOf() : null;
5673
- for (const h of allHands()) {
5674
- if (u) put(c, u, h.x, h.y, 16777215, a);
5675
- put(c, b, h.x, h.y, parseColor(h.color)[0], a);
5606
+ if (windowIntervals.length >= 180) {
5607
+ const display = Number.isFinite(refresh) ? refresh : refreshInterval(windowIntervals);
5608
+ if (!forced && !paused && shouldDrop(windowIntervals, display) && tierName !== "low") {
5609
+ setTier(lower(tierName));
5610
+ ceiling = tierName;
5611
+ writeTier(store, cacheKey, tierName, Number.isFinite(refresh) ? refresh : void 0);
5612
+ console.info("[engine] slow frames: tier ".concat(tierName));
5676
5613
  }
5677
- });
5678
- },
5679
- timeline: (o) => tweens.timeline(o),
5680
- animation(src, props) {
5681
- const def = typeof src === "string" ? animationOf(src) : { frames: src };
5682
- const a = new AnimatedSprite(kernel, def, props);
5683
- tickers.add(a);
5684
- return a;
5685
- },
5686
- bitmapFont(name, source) {
5687
- if (!source) {
5688
- const f2 = bitmapFonts.get(name);
5689
- if (!f2) throw new Error(`[engine] no bitmap font "${name}": load or make it first`);
5690
- return f2;
5614
+ windowIntervals.length = 0;
5691
5615
  }
5692
- const f = "data" in source ? fontOf2(parseBMFont(source.data), source.pages) : generatedFont(kernel, source);
5693
- bitmapFonts.set(name, f);
5694
- return f;
5695
- },
5696
- players: () => live(),
5697
- onFrame(fn) {
5698
- updates.add(fn);
5699
- return () => void updates.delete(fn);
5700
- },
5701
- onRender(fn) {
5702
- renders.add(fn);
5703
- return () => void renders.delete(fn);
5704
- },
5705
- onBackdrop(fn) {
5706
- backdropListeners.add(fn);
5707
- return () => void backdropListeners.delete(fn);
5708
- },
5709
- get hud() {
5710
- if (!hudEl) {
5711
- hudEl = document.createElement("div");
5712
- hudEl.style.cssText = "position:fixed;inset:0;pointer-events:none;overflow:hidden";
5713
- document.body.appendChild(hudEl);
5616
+ };
5617
+ const switchToCanvas2D = () => {
5618
+ const c = freshCanvas(renderer.canvas);
5619
+ const r = createCanvas2D(c);
5620
+ if (!r) return;
5621
+ console.warn("[engine] WebGL context lost for good: switching to Canvas 2D");
5622
+ renderer.destroy();
5623
+ renderer = r;
5624
+ for (const s of surfaces) s.texture = null;
5625
+ for (const p of atlas.pages) surfaces.add(p.surface);
5626
+ tex = textureOf(renderer);
5627
+ ctx = drawCtx();
5628
+ ro == null ? void 0 : ro.disconnect();
5629
+ ro == null ? void 0 : ro.observe(c);
5630
+ resize();
5631
+ };
5632
+ const onVisibility = () => {
5633
+ syncSound();
5634
+ if (!document.hidden) last2 = 0;
5635
+ };
5636
+ document.addEventListener("visibilitychange", onVisibility);
5637
+ const onFonts = () => {
5638
+ fontGen++;
5639
+ for (const t of tagSets) t.drop();
5640
+ };
5641
+ (_k = (_j = document.fonts) == null ? void 0 : _j.addEventListener) == null ? void 0 : _k.call(_j, "loadingdone", onFonts);
5642
+ resize();
5643
+ if (!start && opts.probe !== false) {
5644
+ if (!Number.isFinite(refresh)) refresh = displayInterval(yield idleIntervals(IDLE_FRAMES));
5645
+ if (!hinted) {
5646
+ tierObj = tier("high");
5714
5647
  resize();
5648
+ const result = yield probe(renderer, atlas, () => tex, () => pixelScale, stageW, () => hinted);
5649
+ result.refresh = refresh;
5650
+ if (!hinted) {
5651
+ const picked = pickTier(renderer.kind, result);
5652
+ writeTier(store, cacheKey, picked, refresh);
5653
+ ceiling = picked;
5654
+ setTier(picked);
5655
+ }
5715
5656
  }
5716
- return hudEl;
5717
- },
5718
- random: (min = 0, max = 1) => min + Math.random() * (max - min),
5719
- start() {
5720
- if (running) return;
5721
- running = true;
5722
- last2 = 0;
5723
- raf = requestAnimationFrame(frame);
5724
- },
5725
- pause() {
5726
- userPaused = true;
5727
- syncSound();
5728
- },
5729
- resume() {
5730
- userPaused = false;
5731
- syncSound();
5732
- },
5733
- destroy() {
5734
- running = false;
5735
- cancelAnimationFrame(raf);
5736
- unlisten.forEach((u) => u());
5737
- removeEventListener("resize", resize);
5738
- ro?.disconnect();
5739
- document.removeEventListener("visibilitychange", onVisibility);
5740
- document.fonts?.removeEventListener?.("loadingdone", onFonts);
5741
- tweens.clear();
5742
- forgetNodes(kernel);
5743
- sound.destroy();
5744
- renderer.destroy();
5745
- hudEl?.remove();
5746
5657
  }
5747
- };
5748
- function animationOf(name) {
5749
- const a = animations.get(name);
5750
- if (a) return a;
5751
- const names = [.../* @__PURE__ */ new Set([...frames.keys(), ...bakes.keys()])].filter((n) => n.startsWith(name)).sort(naturalOrder);
5752
- if (!names.length) throw new Error(`[engine] no animation or frames "${name}\u2026"`);
5753
- return { frames: names };
5754
- }
5755
- async function loadAsset(name, url) {
5756
- const ext = url.split("?")[0].split(".").pop().toLowerCase();
5757
- if (["mp3", "ogg", "wav", "m4a", "aac", "webm"].includes(ext)) return sound.load(name, url);
5758
- if (["woff", "woff2", "ttf", "otf"].includes(ext)) {
5759
- const face = new FontFace(name, `url(${url})`);
5760
- document.fonts.add(await face.load());
5761
- fontGen++;
5762
- return;
5658
+ const engine = {
5659
+ stage,
5660
+ get tier() {
5661
+ return tierObj;
5662
+ },
5663
+ get renderer() {
5664
+ return renderer;
5665
+ },
5666
+ get canvas() {
5667
+ return renderer.canvas;
5668
+ },
5669
+ get pixelScale() {
5670
+ return pixelScale;
5671
+ },
5672
+ get backdrop() {
5673
+ return backdrop;
5674
+ },
5675
+ get view() {
5676
+ return view;
5677
+ },
5678
+ get orientation() {
5679
+ return orientation;
5680
+ },
5681
+ get safeArea() {
5682
+ return safeArea;
5683
+ },
5684
+ get paused() {
5685
+ return hostPaused || userPaused;
5686
+ },
5687
+ sound,
5688
+ stats,
5689
+ get time() {
5690
+ return time;
5691
+ },
5692
+ get supports() {
5693
+ const s = renderer.support;
5694
+ return {
5695
+ filters: s.filters,
5696
+ blur: s.filters && tierObj.maxBlur > 0,
5697
+ shaders: s.shaders,
5698
+ maxBlur: s.filters ? tierObj.maxBlur : 0,
5699
+ tiers: { high: { maxBlur: tier("high").maxBlur }, medium: { maxBlur: tier("medium").maxBlur }, low: { maxBlur: tier("low").maxBlur } }
5700
+ };
5701
+ },
5702
+ sprite: (f, props) => new Sprite(kernel, f, props),
5703
+ shape: (spec, props) => new Shape(kernel, spec, props),
5704
+ text: (t, style) => new Text(kernel, t, style),
5705
+ group: (props) => new Group(kernel).set(props != null ? props : {}),
5706
+ particles(f, o = {}) {
5707
+ const fr = typeof f === "object" && "type" in f ? kernel.shape(f).frame : f;
5708
+ const p = new Particles(kernel, fr, o);
5709
+ const _a3 = o, { max: _m, blend: _b2, gravity: _g2, drag: _d2 } = _a3, props = __objRest(_a3, ["max", "blend", "gravity", "drag"]);
5710
+ p.set(props);
5711
+ tickers.add(p);
5712
+ return p;
5713
+ },
5714
+ tween: (target, to, seconds, ease) => tweens.tween(target, to, seconds, ease),
5715
+ bake(name, w2, h, draw, origin) {
5716
+ bakes.set(name, { w: w2, h, draw, origin });
5717
+ frames.delete(name);
5718
+ return engine.frame(name);
5719
+ },
5720
+ frame(name) {
5721
+ var _a3, _b2, _c2, _d2;
5722
+ const f = frames.get(name);
5723
+ if (f && atlas.valid(f) && (f.gen === 0 || f.scale === pixelScale)) return f;
5724
+ const b = bakes.get(name);
5725
+ if (b) {
5726
+ const k = pixelScale;
5727
+ const nf = atlas.bake(b.w * k, b.h * k, (c) => (c.scale(k, k), b.draw(c)), k, (_b2 = (_a3 = b.origin) == null ? void 0 : _a3.x) != null ? _b2 : 0, (_d2 = (_c2 = b.origin) == null ? void 0 : _c2.y) != null ? _d2 : 0);
5728
+ frames.set(name, nf);
5729
+ return nf;
5730
+ }
5731
+ if (f) return f;
5732
+ throw new Error('[engine] no frame "'.concat(name, '": load it or bake it first'));
5733
+ },
5734
+ load(assets) {
5735
+ return __async(this, null, function* () {
5736
+ yield Promise.all(Object.entries(assets).map(([name, url]) => loadAsset(name, url)));
5737
+ });
5738
+ },
5739
+ hands: (player) => player === void 0 ? allHands() : allHands().filter((h) => h.player === player),
5740
+ touched(node, player, o = {}) {
5741
+ var _a3;
5742
+ node.updateWorld();
5743
+ return touching(node, allHands(), player, (_a3 = o.padding) != null ? _a3 : 0);
5744
+ },
5745
+ hits(node, x, y, padding = 0) {
5746
+ node.updateWorld();
5747
+ return hits(node, x, y, padding);
5748
+ },
5749
+ avatars: (o = {}) => new AvatarsNode(kernel, paintAvatars(o)),
5750
+ handMarkers(o = {}) {
5751
+ var _a3, _b2;
5752
+ const r = (_a3 = o.radius) != null ? _a3 : 36;
5753
+ const look = (_b2 = o.look) != null ? _b2 : "auto";
5754
+ const handMat = new Float64Array(6);
5755
+ const lw = Math.max(r * 0.12, 3);
5756
+ const ring = { type: "ring", r, lw, fill: "rgba(251,231,184,0.3)", stroke: "#ffffff" };
5757
+ const halo = { type: "ring", r, lw: lw * 1.8, stroke: HALO, shadow: { color: HALO, blur: r * 0.2 } };
5758
+ const put = (c, f, x, y, tint2, a) => {
5759
+ const w2 = f.w / f.scale;
5760
+ composeMat(handMat, null, x - w2 / 2, y - w2 / 2, 0, 1, 1);
5761
+ c.r.quad(c.tex(f.surface), f, handMat, w2, w2, tint2, a, "normal");
5762
+ };
5763
+ const memo = (spec) => {
5764
+ let b = null;
5765
+ let fx2 = false;
5766
+ return () => (b && atlas.valid(b.frame) && b.frame.scale === pixelScale && fx2 === tierObj.effects ? b : (fx2 = tierObj.effects, b = kernel.shape(spec))).frame;
5767
+ };
5768
+ const ringOf = memo(ring);
5769
+ const haloOf = memo(halo);
5770
+ return new HandMarkers(kernel, (c, a) => {
5771
+ const video = look === "video" || look === "auto" && backdrop === "video";
5772
+ const b = ringOf();
5773
+ const u = video ? haloOf() : null;
5774
+ for (const h of allHands()) {
5775
+ if (u) put(c, u, h.x, h.y, 16777215, a);
5776
+ put(c, b, h.x, h.y, parseColor(h.color)[0], a);
5777
+ }
5778
+ });
5779
+ },
5780
+ timeline: (o) => tweens.timeline(o),
5781
+ animation(src, props) {
5782
+ const def = typeof src === "string" ? animationOf(src) : { frames: src };
5783
+ const a = new AnimatedSprite(kernel, def, props);
5784
+ tickers.add(a);
5785
+ return a;
5786
+ },
5787
+ bitmapFont(name, source) {
5788
+ if (!source) {
5789
+ const f2 = bitmapFonts.get(name);
5790
+ if (!f2) throw new Error('[engine] no bitmap font "'.concat(name, '": load or make it first'));
5791
+ return f2;
5792
+ }
5793
+ const f = "data" in source ? fontOf2(parseBMFont(source.data), source.pages) : generatedFont(kernel, source);
5794
+ bitmapFonts.set(name, f);
5795
+ return f;
5796
+ },
5797
+ players: () => live(),
5798
+ onFrame(fn) {
5799
+ updates.add(fn);
5800
+ return () => void updates.delete(fn);
5801
+ },
5802
+ onRender(fn) {
5803
+ renders.add(fn);
5804
+ return () => void renders.delete(fn);
5805
+ },
5806
+ onBackdrop(fn) {
5807
+ backdropListeners.add(fn);
5808
+ return () => void backdropListeners.delete(fn);
5809
+ },
5810
+ get hud() {
5811
+ if (!hudEl) {
5812
+ hudEl = document.createElement("div");
5813
+ hudEl.style.cssText = "position:fixed;top:0;right:0;bottom:0;left:0;pointer-events:none;overflow:hidden";
5814
+ document.body.appendChild(hudEl);
5815
+ resize();
5816
+ }
5817
+ return hudEl;
5818
+ },
5819
+ random: (min = 0, max = 1) => min + Math.random() * (max - min),
5820
+ start() {
5821
+ if (running) return;
5822
+ running = true;
5823
+ last2 = 0;
5824
+ raf = requestAnimationFrame(frame);
5825
+ },
5826
+ pause() {
5827
+ userPaused = true;
5828
+ syncSound();
5829
+ },
5830
+ resume() {
5831
+ userPaused = false;
5832
+ syncSound();
5833
+ },
5834
+ destroy() {
5835
+ var _a3, _b2;
5836
+ running = false;
5837
+ cancelAnimationFrame(raf);
5838
+ unlisten.forEach((u) => u());
5839
+ removeEventListener("resize", resize);
5840
+ ro == null ? void 0 : ro.disconnect();
5841
+ document.removeEventListener("visibilitychange", onVisibility);
5842
+ (_b2 = (_a3 = document.fonts) == null ? void 0 : _a3.removeEventListener) == null ? void 0 : _b2.call(_a3, "loadingdone", onFonts);
5843
+ tweens.clear();
5844
+ forgetNodes(kernel);
5845
+ sound.destroy();
5846
+ renderer.destroy();
5847
+ hudEl == null ? void 0 : hudEl.remove();
5848
+ }
5849
+ };
5850
+ function animationOf(name) {
5851
+ const a = animations.get(name);
5852
+ if (a) return a;
5853
+ const names = [.../* @__PURE__ */ new Set([...frames.keys(), ...bakes.keys()])].filter((n) => n.startsWith(name)).sort(naturalOrder);
5854
+ if (!names.length) throw new Error('[engine] no animation or frames "'.concat(name, '\u2026"'));
5855
+ return { frames: names };
5856
+ }
5857
+ function loadAsset(name, url) {
5858
+ return __async(this, null, function* () {
5859
+ var _a3, _b2;
5860
+ const ext = url.split("?")[0].split(".").pop().toLowerCase();
5861
+ if (["mp3", "ogg", "wav", "m4a", "aac", "webm"].includes(ext)) return sound.load(name, url);
5862
+ if (["woff", "woff2", "ttf", "otf"].includes(ext)) {
5863
+ const face = new FontFace(name, "url(".concat(url, ")"));
5864
+ document.fonts.add(yield face.load());
5865
+ fontGen++;
5866
+ return;
5867
+ }
5868
+ const base = new URL(url, location.href);
5869
+ if (ext === "fnt") return loadFont(name, parseBMFont(yield (yield fetch(url)).text()), base);
5870
+ if (ext === "json") {
5871
+ const data = yield (yield fetch(url)).json();
5872
+ if (Array.isArray(data.chars) && !data.frames) return loadFont(name, parseBMFont(data), base);
5873
+ const img2 = yield loadImage(new URL((_b2 = (_a3 = data.meta) == null ? void 0 : _a3.image) != null ? _b2 : url.replace(/\.json$/, ".png"), base).href);
5874
+ readAtlas(name, data, surfaceOf(img2));
5875
+ return;
5876
+ }
5877
+ const img = yield loadImage(url);
5878
+ const s = surfaceOf(img);
5879
+ surfaces.add(s);
5880
+ 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 });
5881
+ });
5763
5882
  }
5764
- const base = new URL(url, location.href);
5765
- if (ext === "fnt") return loadFont(name, parseBMFont(await (await fetch(url)).text()), base);
5766
- if (ext === "json") {
5767
- const data = await (await fetch(url)).json();
5768
- if (Array.isArray(data.chars) && !data.frames) return loadFont(name, parseBMFont(data), base);
5769
- const img2 = await loadImage(new URL(data.meta?.image ?? url.replace(/\.json$/, ".png"), base).href);
5770
- readAtlas(name, data, surfaceOf(img2));
5771
- return;
5883
+ function fontOf2(data, pages) {
5884
+ return bmFont(
5885
+ data,
5886
+ pages.map((p) => {
5887
+ const s = surfaceOf(p);
5888
+ surfaces.add(s);
5889
+ return s;
5890
+ })
5891
+ );
5892
+ }
5893
+ function loadFont(name, data, base) {
5894
+ return __async(this, null, function* () {
5895
+ bitmapFonts.set(name, fontOf2(data, yield Promise.all(data.pages.map((p) => loadImage(new URL(p, base).href)))));
5896
+ });
5772
5897
  }
5773
- const img = await loadImage(url);
5774
- const s = surfaceOf(img);
5775
- surfaces.add(s);
5776
- 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 });
5777
- }
5778
- function fontOf2(data, pages) {
5779
- return bmFont(
5780
- data,
5781
- pages.map((p) => {
5782
- const s = surfaceOf(p);
5783
- surfaces.add(s);
5784
- return s;
5785
- })
5786
- );
5787
- }
5788
- async function loadFont(name, data, base) {
5789
- bitmapFonts.set(name, fontOf2(data, await Promise.all(data.pages.map((p) => loadImage(new URL(p, base).href)))));
5790
- }
5791
- function readAtlas(name, data, s) {
5792
- surfaces.add(s);
5793
- const list = Array.isArray(data.frames) ? data.frames : Object.entries(data.frames).map(([filename, f]) => ({ ...f, filename }));
5794
- const keys = [];
5795
- const durations = [];
5796
- for (const f of list) {
5797
- const fr = f.frame;
5798
- const key = f.filename.replace(IMAGE_EXT, "");
5799
- if (f.rotated) console.warn(`[engine] ${name}/${key} is rotated: export without rotation`);
5800
- 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 };
5801
- if (f.trimmed && f.sourceSize && f.spriteSourceSize) {
5802
- frame2.sw = f.sourceSize.w;
5803
- frame2.sh = f.sourceSize.h;
5804
- frame2.tx = f.spriteSourceSize.x;
5805
- frame2.ty = f.spriteSourceSize.y;
5898
+ function readAtlas(name, data, s) {
5899
+ var _a3, _b2, _c2, _d2, _e2, _f2;
5900
+ surfaces.add(s);
5901
+ const list = Array.isArray(data.frames) ? data.frames : Object.entries(data.frames).map(([filename, f]) => __spreadProps(__spreadValues({}, f), { filename }));
5902
+ const keys = [];
5903
+ const durations = [];
5904
+ for (const f of list) {
5905
+ const fr = f.frame;
5906
+ const key = f.filename.replace(IMAGE_EXT, "");
5907
+ if (f.rotated) console.warn("[engine] ".concat(name, "/").concat(key, " is rotated: export without rotation"));
5908
+ 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 };
5909
+ if (f.trimmed && f.sourceSize && f.spriteSourceSize) {
5910
+ frame2.sw = f.sourceSize.w;
5911
+ frame2.sh = f.sourceSize.h;
5912
+ frame2.tx = f.spriteSourceSize.x;
5913
+ frame2.ty = f.spriteSourceSize.y;
5914
+ }
5915
+ const b = f.scale9Borders;
5916
+ if (b) frame2.slice = [b.y, ((_a3 = frame2.sw) != null ? _a3 : fr.w) - b.x - b.w, ((_b2 = frame2.sh) != null ? _b2 : fr.h) - b.y - b.h, b.x];
5917
+ frames.set("".concat(name, "/").concat(key), frame2);
5918
+ keys.push("".concat(name, "/").concat(key));
5919
+ durations.push(((_c2 = f.duration) != null ? _c2 : 0) / 1e3);
5806
5920
  }
5807
- const b = f.scale9Borders;
5808
- if (b) frame2.slice = [b.y, (frame2.sw ?? fr.w) - b.x - b.w, (frame2.sh ?? fr.h) - b.y - b.h, b.x];
5809
- frames.set(`${name}/${key}`, frame2);
5810
- keys.push(`${name}/${key}`);
5811
- durations.push((f.duration ?? 0) / 1e3);
5812
- }
5813
- for (const [anim, names] of Object.entries(data.animations ?? {})) animations.set(`${name}/${anim}`, { frames: names.map((n) => `${name}/${n.replace(IMAGE_EXT, "")}`) });
5814
- for (const tag of data.meta?.frameTags ?? []) {
5815
- const idx = [];
5816
- for (let i = tag.from; i <= tag.to; i++) idx.push(i);
5817
- if (tag.direction === "reverse") idx.reverse();
5818
- if (tag.direction === "pingpong") idx.push(...idx.slice(1, -1).reverse());
5819
- const timed = idx.every((i) => durations[i] > 0);
5820
- animations.set(`${name}/${tag.name}`, { frames: idx.map((i) => keys[i]), ...timed ? { durations: idx.map((i) => durations[i]) } : {} });
5821
- }
5822
- }
5823
- return engine;
5921
+ 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, ""))) });
5922
+ for (const tag of (_f2 = (_e2 = data.meta) == null ? void 0 : _e2.frameTags) != null ? _f2 : []) {
5923
+ const idx = [];
5924
+ for (let i = tag.from; i <= tag.to; i++) idx.push(i);
5925
+ if (tag.direction === "reverse") idx.reverse();
5926
+ if (tag.direction === "pingpong") idx.push(...idx.slice(1, -1).reverse());
5927
+ const timed = idx.every((i) => durations[i] > 0);
5928
+ animations.set("".concat(name, "/").concat(tag.name), __spreadValues({ frames: idx.map((i) => keys[i]) }, timed ? { durations: idx.map((i) => durations[i]) } : {}));
5929
+ }
5930
+ }
5931
+ return engine;
5932
+ });
5824
5933
  }
5825
5934
  var IMAGE_EXT = /\.(png|webp|jpe?g|gif|bmp)$/i;
5826
5935
  function loadImage(url) {
5827
5936
  return new Promise((resolve, reject) => {
5828
5937
  const img = new Image();
5829
5938
  img.onload = () => resolve(img);
5830
- img.onerror = () => reject(new Error(`[engine] image did not load: ${url}`));
5939
+ img.onerror = () => reject(new Error("[engine] image did not load: ".concat(url)));
5831
5940
  img.src = url;
5832
5941
  });
5833
5942
  }
@@ -5844,52 +5953,54 @@ function idleIntervals(n) {
5844
5953
  requestAnimationFrame(step);
5845
5954
  });
5846
5955
  }
5847
- async function probe(renderer, atlas, tex, scale, width, stop = () => false) {
5848
- const k = scale();
5849
- const star = bakeShape(atlas, { type: "star", r: 30, fill: "#ffd23f", stroke: "#3a2a10", lw: 3 }, k).frame;
5850
- const intervals = [];
5851
- const cpu = [];
5852
- const m = new Float64Array(6);
5853
- const ALPHA = 4e-3;
5854
- const ctx2d = renderer.kind === "canvas2d" ? renderer.canvas.getContext("2d") : null;
5855
- const start = now();
5856
- let last2 = 0;
5857
- await new Promise((done) => {
5858
- const step = (t) => {
5859
- if (last2 && t - start > 250) intervals.push(t - last2);
5860
- last2 = t;
5861
- const t0 = now();
5862
- renderer.begin(0, 0, k);
5863
- const tx = tex();
5864
- for (let i = 0; i < 300; i++) {
5865
- const a = t / 1e3 + i;
5866
- composeMat(m, null, i * 37 % width, i * 53 % STAGE_HEIGHT, a, 1, 1);
5867
- renderer.quad(tx(star.surface), star, m, star.w / k, star.h / k, 16777215, ALPHA, "normal");
5868
- }
5869
- for (let i = 0; i < 40; i++) {
5870
- renderer.ellipse(100 + i * 20, 300, 20, 14, i, 16746496, ALPHA);
5871
- renderer.stroke([100 + i * 20, 400, 120 + i * 20, 460, 100 + i * 20, 520], 3, 18, 3368703, ALPHA, false);
5872
- }
5873
- renderer.end();
5874
- ctx2d?.getImageData(0, 0, 1, 1);
5875
- if (t - start > 250) cpu.push(now() - t0);
5876
- if (t - start < 750 && !stop()) requestAnimationFrame(step);
5877
- else {
5956
+ function probe(renderer, atlas, tex, scale, width, stop = () => false) {
5957
+ return __async(this, null, function* () {
5958
+ const k = scale();
5959
+ const star = bakeShape(atlas, { type: "star", r: 30, fill: "#ffd23f", stroke: "#3a2a10", lw: 3 }, k).frame;
5960
+ const intervals = [];
5961
+ const cpu = [];
5962
+ const m = new Float64Array(6);
5963
+ const ALPHA = 4e-3;
5964
+ const ctx2d = renderer.kind === "canvas2d" ? renderer.canvas.getContext("2d") : null;
5965
+ const start = now();
5966
+ let last2 = 0;
5967
+ yield new Promise((done) => {
5968
+ const step = (t) => {
5969
+ if (last2 && t - start > 250) intervals.push(t - last2);
5970
+ last2 = t;
5971
+ const t0 = now();
5878
5972
  renderer.begin(0, 0, k);
5973
+ const tx = tex();
5974
+ for (let i = 0; i < 300; i++) {
5975
+ const a = t / 1e3 + i;
5976
+ composeMat(m, null, i * 37 % width, i * 53 % STAGE_HEIGHT, a, 1, 1);
5977
+ renderer.quad(tx(star.surface), star, m, star.w / k, star.h / k, 16777215, ALPHA, "normal");
5978
+ }
5979
+ for (let i = 0; i < 40; i++) {
5980
+ renderer.ellipse(100 + i * 20, 300, 20, 14, i, 16746496, ALPHA);
5981
+ renderer.stroke([100 + i * 20, 400, 120 + i * 20, 460, 100 + i * 20, 520], 3, 18, 3368703, ALPHA, false);
5982
+ }
5879
5983
  renderer.end();
5880
- done();
5881
- }
5882
- };
5883
- requestAnimationFrame(step);
5984
+ ctx2d == null ? void 0 : ctx2d.getImageData(0, 0, 1, 1);
5985
+ if (t - start > 250) cpu.push(now() - t0);
5986
+ if (t - start < 750 && !stop()) requestAnimationFrame(step);
5987
+ else {
5988
+ renderer.begin(0, 0, k);
5989
+ renderer.end();
5990
+ done();
5991
+ }
5992
+ };
5993
+ requestAnimationFrame(step);
5994
+ });
5995
+ return { intervals, cpu };
5884
5996
  });
5885
- return { intervals, cpu };
5886
5997
  }
5887
5998
 
5888
5999
  // src/render/canvas2d-filters.ts
5889
6000
  var PLANS = 64;
5890
6001
  var SWEEP = 32;
5891
6002
  var svgIds = 0;
5892
- var svgPre = `fabi-cm-${Math.random().toString(36).slice(2, 7)}-`;
6003
+ var svgPre = "fabi-cm-".concat(Math.random().toString(36).slice(2, 7), "-");
5893
6004
  var warned2 = /* @__PURE__ */ new Set();
5894
6005
  var warnOnce = (k, msg) => {
5895
6006
  if (warned2.has(k)) return;
@@ -5918,7 +6029,7 @@ var C2DFx = class {
5918
6029
  __publicField(this, "flip", 0);
5919
6030
  }
5920
6031
  chain(src, filters) {
5921
- var _a;
6032
+ var _a2, _b;
5922
6033
  const r = this.r;
5923
6034
  let b = this.buf;
5924
6035
  b[0] = r.scale;
@@ -5937,7 +6048,7 @@ var C2DFx = class {
5937
6048
  b[n++] = f.enabled ? 1 : 0;
5938
6049
  if (f.params) n = f.params(b, n);
5939
6050
  }
5940
- const k = (_a = this.keys)[n] ?? (_a[n] = new Float64Array(n));
6051
+ const k = (_b = (_a2 = this.keys)[n]) != null ? _b : _a2[n] = new Float64Array(n);
5941
6052
  for (let i = 0; i < n; i++) k[i] = b[i];
5942
6053
  const kh = hash(k);
5943
6054
  let plan = this.plans.get(k, kh);
@@ -5972,7 +6083,10 @@ var C2DFx = class {
5972
6083
  /** url(#…) of an SVG filter for colour matrix m, shared by every plan with the same numbers (null: no page). */
5973
6084
  svg(m) {
5974
6085
  if (typeof document === "undefined" || !document.body) return null;
5975
- const key = Array.from({ length: 20 }, (_, k) => m[k] ?? 0).join(" ");
6086
+ const key = Array.from({ length: 20 }, (_, k) => {
6087
+ var _a2;
6088
+ return (_a2 = m[k]) != null ? _a2 : 0;
6089
+ }).join(" ");
5976
6090
  let s = this.svgs.get(key);
5977
6091
  if (!s) {
5978
6092
  const ns = "http://www.w3.org/2000/svg";
@@ -5993,7 +6107,7 @@ var C2DFx = class {
5993
6107
  this.attach(s = { key, id, el, used: this.t });
5994
6108
  }
5995
6109
  this.cur.svgs.push(s);
5996
- return `url(#${s.id})`;
6110
+ return "url(#".concat(s.id, ")");
5997
6111
  }
5998
6112
  attach(s) {
5999
6113
  document.body.append(s.el);
@@ -6019,7 +6133,7 @@ var C2DFx = class {
6019
6133
  continue;
6020
6134
  }
6021
6135
  const s = r.support.filters && f.css ? f.css(r.scale, r.maxBlur, this.svgFn) : null;
6022
- if (s !== null) css += css ? ` ${s}` : s;
6136
+ if (s !== null) css += css ? " ".concat(s) : s;
6023
6137
  else if (f.paint2d) {
6024
6138
  p.parts.push(css);
6025
6139
  p.paints.push(i);
@@ -6058,44 +6172,8 @@ var C2DFx = class {
6058
6172
  // src/render/webgl-filters.ts
6059
6173
  var MAX_SHADERS = 64;
6060
6174
  var TAPS = 17;
6061
- var colorFs = (n) => `${PRECISION}
6062
- uniform sampler2D uTexture;
6063
- uniform mat4 uM[${n}];
6064
- uniform vec4 uO[${n}];
6065
- uniform int uK;
6066
- varying vec2 vUv;
6067
- varying vec4 vColor;
6068
- void main() {
6069
- vec4 c = texture2D(uTexture, vUv);
6070
- if (c.a > 0.0) c.rgb /= c.a;
6071
- for (int i = 0; i < ${n}; i++) {
6072
- if (i >= uK) break;
6073
- c = clamp(uM[i] * c + uO[i], 0.0, 1.0);
6074
- }
6075
- c.rgb *= c.a;
6076
- gl_FragColor = c * vColor;
6077
- }`;
6078
- var blurFs = () => `${PRECISION}
6079
- uniform sampler2D uTexture;
6080
- uniform vec2 uDir;
6081
- uniform vec2 uOff;
6082
- uniform vec2 uTaps[${TAPS}];
6083
- uniform int uN;
6084
- uniform float uMode;
6085
- uniform vec4 uShadow;
6086
- varying vec2 vUv;
6087
- varying vec4 vColor;
6088
- void main() {
6089
- vec2 p = vUv + uOff;
6090
- vec4 c = texture2D(uTexture, p) * uTaps[0].y;
6091
- for (int i = 1; i < ${TAPS}; i++) {
6092
- if (i >= uN) break;
6093
- vec2 d = uDir * uTaps[i].x;
6094
- c += (texture2D(uTexture, p + d) + texture2D(uTexture, p - d)) * uTaps[i].y;
6095
- }
6096
- if (uMode > 0.5) c = uShadow * c.a;
6097
- gl_FragColor = c * vColor;
6098
- }`;
6175
+ 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}");
6176
+ 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}");
6099
6177
  function composeInto(acc, m, tmp2 = new Float32Array(20)) {
6100
6178
  for (let r = 0; r < 4; r++) {
6101
6179
  for (let c = 0; c < 5; c++) {
@@ -6139,9 +6217,10 @@ var GLFx = class {
6139
6217
  this.o4 = new Float32Array(4 * this.colorN);
6140
6218
  }
6141
6219
  check(src) {
6220
+ var _a2;
6142
6221
  if (this.r.lost) return null;
6143
6222
  this.userProg(src, false);
6144
- return this.userErr.get(src) ?? null;
6223
+ return (_a2 = this.userErr.get(src)) != null ? _a2 : null;
6145
6224
  }
6146
6225
  destroy() {
6147
6226
  const gl = this.r.gl;
@@ -6179,19 +6258,19 @@ var GLFx = class {
6179
6258
  p = null;
6180
6259
  const msg = e2.message;
6181
6260
  this.userErr.set(src, msg);
6182
- if (log) console.error(`[engine] a shader filter does not compile: it is skipped.
6183
- ${msg}`);
6261
+ if (log) console.error("[engine] a shader filter does not compile: it is skipped.\n".concat(msg));
6184
6262
  }
6185
6263
  user.set(src, { p, t: ++this.uses });
6186
6264
  return p;
6187
6265
  }
6188
6266
  /** Filter scratch target `slot` at 1/f of the canvas's size, made on demand. */
6189
6267
  scratch(f, slot) {
6268
+ var _a2;
6190
6269
  const r = this.r;
6191
6270
  const w2 = Math.ceil(r.canvas.width / f);
6192
6271
  const h = Math.ceil(r.canvas.height / f);
6193
6272
  const k = f * 8 + slot;
6194
- let T2 = this.scratchT.get(k) ?? null;
6273
+ let T2 = (_a2 = this.scratchT.get(k)) != null ? _a2 : null;
6195
6274
  if (T2 && (T2.w !== w2 || T2.h !== h)) {
6196
6275
  r.drop(T2);
6197
6276
  T2 = null;
@@ -6234,14 +6313,16 @@ ${msg}`);
6234
6313
  }
6235
6314
  /** A filter program, made on first use. */
6236
6315
  post(which) {
6237
- if (which === "color") return this.colorProg ?? (this.colorProg = this.r.build(colorFs(this.colorN)));
6238
- return this.blurProg ?? (this.blurProg = this.r.build(blurFs()));
6316
+ var _a2, _b;
6317
+ if (which === "color") return (_a2 = this.colorProg) != null ? _a2 : this.colorProg = this.r.build(colorFs(this.colorN));
6318
+ return (_b = this.blurProg) != null ? _b : this.blurProg = this.r.build(blurFs());
6239
6319
  }
6240
6320
  /** Bilinear filtering on a layer texture while a blur reads it between its texels (layers are NEAREST). */
6241
6321
  linear(t, on) {
6322
+ var _a2;
6242
6323
  const r = this.r;
6243
6324
  const gl = r.gl;
6244
- r.bindTex(r.layerTex.get(t) ?? null, 0);
6325
+ r.bindTex((_a2 = r.layerTex.get(t)) != null ? _a2 : null, 0);
6245
6326
  const f = on ? gl.LINEAR : gl.NEAREST;
6246
6327
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, f);
6247
6328
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, f);
@@ -6322,7 +6403,7 @@ ${msg}`);
6322
6403
  const y = this.scratch(1, 2);
6323
6404
  if (!y) break;
6324
6405
  this.blur(src, idx < 0, Math.max(Math.min(sh.blur, maxBlur), 0) * scale, y, 1, sh);
6325
- const into = out ?? (alpha < 1 ? this.scratch(1, o) : null);
6406
+ const into = out != null ? out : alpha < 1 ? this.scratch(1, o) : null;
6326
6407
  if (into) {
6327
6408
  this.pass(r.main, y.tex, 1, into);
6328
6409
  this.pass(r.main, src, 1, into, true);
@@ -6482,7 +6563,7 @@ var Brightness = class extends Amount {
6482
6563
  linear(m, pos(this.amount), 0);
6483
6564
  }
6484
6565
  css() {
6485
- return `brightness(${pos(this.amount)})`;
6566
+ return "brightness(".concat(pos(this.amount), ")");
6486
6567
  }
6487
6568
  };
6488
6569
  var Contrast = class extends Amount {
@@ -6491,7 +6572,7 @@ var Contrast = class extends Amount {
6491
6572
  linear(m, v, 0.5 - 0.5 * v);
6492
6573
  }
6493
6574
  css() {
6494
- return `contrast(${pos(this.amount)})`;
6575
+ return "contrast(".concat(pos(this.amount), ")");
6495
6576
  }
6496
6577
  };
6497
6578
  var Invert = class extends Amount {
@@ -6500,7 +6581,7 @@ var Invert = class extends Amount {
6500
6581
  linear(m, 1 - 2 * a, a);
6501
6582
  }
6502
6583
  css() {
6503
- return `invert(${clamp012(this.amount)})`;
6584
+ return "invert(".concat(clamp012(this.amount), ")");
6504
6585
  }
6505
6586
  };
6506
6587
  var Saturate = class extends Amount {
@@ -6518,7 +6599,7 @@ var Saturate = class extends Amount {
6518
6599
  rgb3(m, m9);
6519
6600
  }
6520
6601
  css() {
6521
- return `saturate(${pos(this.amount)})`;
6602
+ return "saturate(".concat(pos(this.amount), ")");
6522
6603
  }
6523
6604
  };
6524
6605
  var Grayscale = class extends Amount {
@@ -6536,7 +6617,7 @@ var Grayscale = class extends Amount {
6536
6617
  rgb3(m, m9);
6537
6618
  }
6538
6619
  css() {
6539
- return `grayscale(${clamp012(this.amount)})`;
6620
+ return "grayscale(".concat(clamp012(this.amount), ")");
6540
6621
  }
6541
6622
  };
6542
6623
  var Sepia = class extends Amount {
@@ -6554,7 +6635,7 @@ var Sepia = class extends Amount {
6554
6635
  rgb3(m, m9);
6555
6636
  }
6556
6637
  css() {
6557
- return `sepia(${clamp012(this.amount)})`;
6638
+ return "sepia(".concat(clamp012(this.amount), ")");
6558
6639
  }
6559
6640
  };
6560
6641
  var HueRotate = class extends Amount {
@@ -6580,7 +6661,7 @@ var HueRotate = class extends Amount {
6580
6661
  rgb3(m, m9);
6581
6662
  }
6582
6663
  css() {
6583
- return `hue-rotate(${this.amount}deg)`;
6664
+ return "hue-rotate(".concat(this.amount, "deg)");
6584
6665
  }
6585
6666
  };
6586
6667
  var Tint = class extends Amount {
@@ -6630,14 +6711,16 @@ var ColorMatrix = class extends Base {
6630
6711
  super();
6631
6712
  __publicField(this, "kind", F_COLOR);
6632
6713
  __publicField(this, "values");
6633
- if (m.length !== 20) throw new Error(`colorMatrix: 20 numbers expected (4 rows of 5), got ${m.length}`);
6714
+ if (m.length !== 20) throw new Error("colorMatrix: 20 numbers expected (4 rows of 5), got ".concat(m.length));
6634
6715
  this.values = Array.from(m);
6635
6716
  }
6636
6717
  toMatrix(m) {
6637
- for (let i = 0; i < 20; i++) m[i] = this.values[i] ?? 0;
6718
+ var _a2;
6719
+ for (let i = 0; i < 20; i++) m[i] = (_a2 = this.values[i]) != null ? _a2 : 0;
6638
6720
  }
6639
6721
  params(o, i) {
6640
- for (let k = 0; k < 20; k++) o[i + k] = this.values[k] ?? 0;
6722
+ var _a2;
6723
+ for (let k = 0; k < 20; k++) o[i + k] = (_a2 = this.values[k]) != null ? _a2 : 0;
6641
6724
  return i + 20;
6642
6725
  }
6643
6726
  /**
@@ -6662,7 +6745,7 @@ var Blur = class extends Base {
6662
6745
  return 3 * Math.min(pos(this.radius), max);
6663
6746
  }
6664
6747
  css(scale, max) {
6665
- return `blur(${Math.min(pos(this.radius), max) * scale}px)`;
6748
+ return "blur(".concat(Math.min(pos(this.radius), max) * scale, "px)");
6666
6749
  }
6667
6750
  };
6668
6751
  var DropShadow = class extends Base {
@@ -6702,40 +6785,22 @@ var DropShadow = class extends Base {
6702
6785
  return 3 * Math.min(pos(this.blur), max) + Math.max(Math.abs(this.dx), Math.abs(this.dy));
6703
6786
  }
6704
6787
  css(scale, max) {
6705
- return `drop-shadow(${this.dx * scale}px ${this.dy * scale}px ${2 * Math.min(pos(this.blur), max) * scale}px ${cssColor(this.rgb, this.opacity)})`;
6788
+ 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), ")");
6706
6789
  }
6707
6790
  };
6708
- var HEADER = `#ifdef GL_FRAGMENT_PRECISION_HIGH
6709
- precision highp float;
6710
- #else
6711
- precision mediump float;
6712
- #endif
6713
- uniform sampler2D uTexture;
6714
- uniform vec2 uResolution;
6715
- uniform float uTime;
6716
- uniform vec4 uRect;
6717
- varying vec2 vUv;
6718
- varying vec4 vColor;
6719
- #define main fabiUserMain
6720
- #line 1
6721
- `;
6722
- var shaderSource = (fragment2) => `${HEADER}${fragment2}
6723
- #undef main
6724
- void main() {
6725
- fabiUserMain();
6726
- gl_FragColor *= vColor.a;
6727
- }
6728
- `;
6791
+ 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";
6792
+ var shaderSource = (fragment2) => "".concat(HEADER).concat(fragment2, "\n#undef main\nvoid main() {\n fabiUserMain();\n gl_FragColor *= vColor.a;\n}\n");
6729
6793
  var Shader = class extends Base {
6730
6794
  constructor(o) {
6795
+ var _a2, _b;
6731
6796
  super();
6732
6797
  __publicField(this, "kind", F_SHADER);
6733
6798
  __publicField(this, "source");
6734
6799
  __publicField(this, "uniforms", {});
6735
6800
  __publicField(this, "padding");
6736
6801
  this.source = shaderSource(o.fragment);
6737
- this.padding = o.padding ?? 0;
6738
- for (const k in o.uniforms ?? {}) {
6802
+ this.padding = (_a2 = o.padding) != null ? _a2 : 0;
6803
+ for (const k in (_b = o.uniforms) != null ? _b : {}) {
6739
6804
  const v = o.uniforms[k];
6740
6805
  this.uniforms[k] = typeof v === "number" ? v : Float32Array.from(v);
6741
6806
  }
@@ -6756,10 +6821,10 @@ var colorMatrix = (m) => new ColorMatrix(m);
6756
6821
  var blur = (radius) => new Blur(radius);
6757
6822
  var dropShadow = (dx, dy, blur2, color = "rgba(0,0,0,0.5)") => new DropShadow(dx, dy, blur2, color);
6758
6823
  function shader(o) {
6824
+ var _a2, _b;
6759
6825
  const f = new Shader(o);
6760
- const err = fx.live?.filters()?.check(f.source);
6761
- if (err) throw new Error(`shader(): the fragment does not compile:
6762
- ${err}`);
6826
+ const err = (_b = (_a2 = fx.live) == null ? void 0 : _a2.filters()) == null ? void 0 : _b.check(f.source);
6827
+ if (err) throw new Error("shader(): the fragment does not compile:\n".concat(err));
6763
6828
  return f;
6764
6829
  }
6765
6830
 
@@ -6804,10 +6869,10 @@ function restore(n, s) {
6804
6869
  }
6805
6870
  var warned3 = null;
6806
6871
  var warnOnce2 = (n, msg) => {
6807
- warned3 ?? (warned3 = /* @__PURE__ */ new WeakSet());
6872
+ warned3 != null ? warned3 : warned3 = /* @__PURE__ */ new WeakSet();
6808
6873
  if (warned3.has(n)) return;
6809
6874
  warned3.add(n);
6810
- console.warn(`[engine] ${msg}`);
6875
+ console.warn("[engine] ".concat(msg));
6811
6876
  };
6812
6877
  var NodePool = class {
6813
6878
  /** Use nodePool(factory, options). */
@@ -6859,18 +6924,19 @@ var NodePool = class {
6859
6924
  * destroyed instead. Releasing a node twice, or one of another pool, does nothing (and says so once).
6860
6925
  */
6861
6926
  release(node) {
6927
+ var _a2, _b, _c;
6862
6928
  const s = this.states.get(node);
6863
- if (!s || node.destroyed) return true ? warnOnce2(node, `nodePool.release(): ${node.destroyed ? "a destroyed node" : "a node this pool did not make"}: ignored`) : void 0;
6929
+ 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;
6864
6930
  if (node._free) return true ? warnOnce2(node, "nodePool.release(): this node was already released: ignored") : void 0;
6865
6931
  if (this.opts.max !== void 0 && this.free.length >= this.opts.max) return node.destroy();
6866
- node.parent?.remove(node);
6932
+ (_a2 = node.parent) == null ? void 0 : _a2.remove(node);
6867
6933
  node.kernel.tweens.stopAll(node);
6868
6934
  this.stats.live--;
6869
6935
  restore(node, s);
6870
6936
  if (node instanceof AnimatedSprite) node.stop();
6871
6937
  node.visible = false;
6872
6938
  node._free = true;
6873
- this.opts.reset?.(node);
6939
+ (_c = (_b = this.opts).reset) == null ? void 0 : _c.call(_b, node);
6874
6940
  this.free.push(node);
6875
6941
  this.stats.free++;
6876
6942
  if (true) watch(node);