@vonage/ml-transformers 7.0.0-alpha.3 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  async function is() {
2
2
  return new Promise(async (r, e) => {
3
- await si() || oi() ? r() : e(
3
+ !ss() && (await si() || oi()) ? r() : e(
4
4
  "Your browser does not support the MediaStreamTrack API for Insertable Streams of Media."
5
5
  );
6
6
  });
@@ -19,6 +19,10 @@ function os() {
19
19
  self.AudioWorkletNode
20
20
  ].filter((r) => r === void 0).length === 0;
21
21
  }
22
+ function ss() {
23
+ const r = navigator.userAgent.toLowerCase();
24
+ return navigator.vendor && navigator.vendor.toLowerCase().indexOf("apple") > -1 && !(r.indexOf("applewebkit") > -1 && r.indexOf("version") === -1) ? parseInt((r.split(" ").find((e) => e.includes("version/")) ?? "/0").split("/")[1]) < 26 : !1;
25
+ }
22
26
  function si() {
23
27
  return new Promise((r) => {
24
28
  function e() {
@@ -51,7 +55,7 @@ function je(r, e) {
51
55
  if (n.has(t))
52
56
  return n.get(t);
53
57
  }
54
- function ss(r, e, t) {
58
+ function as(r, e, t) {
55
59
  const n = q.get(r);
56
60
  if (n.has(e))
57
61
  for (const i of n.get(e))
@@ -213,7 +217,7 @@ class J {
213
217
  async emit(e, t) {
214
218
  if (Ae(e), Me(e) && !Ft)
215
219
  throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");
216
- this.logIfDebugEnabled("emit", e, t), ss(this, e, t);
220
+ this.logIfDebugEnabled("emit", e, t), as(this, e, t);
217
221
  const n = Te(this, e) ?? /* @__PURE__ */ new Set(), i = ee.get(this), o = [...n], s = Me(e) ? [] : [...i];
218
222
  await Tn, await Promise.all([
219
223
  ...o.map(async (a) => {
@@ -316,30 +320,30 @@ Object.defineProperty(J, "listenerRemoved", {
316
320
  enumerable: !0,
317
321
  configurable: !1
318
322
  });
319
- var as = Object.defineProperty, cs = (r, e, t) => e in r ? as(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, us = (r, e, t) => (cs(r, e + "", t), t);
320
- const ls = "hlg.tokbox.com/prod/logging/vcp_webrtc", fs = "https://", ds = 1e4;
323
+ var cs = Object.defineProperty, us = (r, e, t) => e in r ? cs(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, ls = (r, e, t) => (us(r, e + "", t), t);
324
+ const fs = "hlg.tokbox.com/prod/logging/vcp_webrtc", ds = "https://", hs = 1e4;
321
325
  let ht;
322
- const hs = new Uint8Array(16);
323
- function ms() {
326
+ const ms = new Uint8Array(16);
327
+ function ps() {
324
328
  if (!ht && (ht = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !ht))
325
329
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
326
- return ht(hs);
330
+ return ht(ms);
327
331
  }
328
332
  const F = [];
329
333
  for (let r = 0; r < 256; ++r)
330
334
  F.push((r + 256).toString(16).slice(1));
331
- function ps(r, e = 0) {
335
+ function gs(r, e = 0) {
332
336
  return (F[r[e + 0]] + F[r[e + 1]] + F[r[e + 2]] + F[r[e + 3]] + "-" + F[r[e + 4]] + F[r[e + 5]] + "-" + F[r[e + 6]] + F[r[e + 7]] + "-" + F[r[e + 8]] + F[r[e + 9]] + "-" + F[r[e + 10]] + F[r[e + 11]] + F[r[e + 12]] + F[r[e + 13]] + F[r[e + 14]] + F[r[e + 15]]).toLowerCase();
333
337
  }
334
- const gs = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), kn = {
335
- randomUUID: gs
338
+ const ys = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), kn = {
339
+ randomUUID: ys
336
340
  };
337
- function ys(r, e, t) {
341
+ function bs(r, e, t) {
338
342
  if (kn.randomUUID && !r)
339
343
  return kn.randomUUID();
340
344
  r = r || {};
341
- const n = r.random || (r.rng || ms)();
342
- return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, ps(n);
345
+ const n = r.random || (r.rng || ps)();
346
+ return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, gs(n);
343
347
  }
344
348
  function Ur(r, e) {
345
349
  globalThis.vonage || (globalThis.vonage = {}), globalThis.vonage.workerizer || (globalThis.vonage.workerizer = {});
@@ -354,9 +358,9 @@ var ye = /* @__PURE__ */ ((r) => (r.INIT = "INIT", r.FORWARD = "FORWARD", r.TERM
354
358
  function ai(r) {
355
359
  return [ImageBitmap, ReadableStream, WritableStream].some((e) => r instanceof e);
356
360
  }
357
- let bs = 0;
358
- function ws(r, e, t, n, i) {
359
- const o = bs++;
361
+ let ws = 0;
362
+ function xs(r, e, t, n, i) {
363
+ const o = ws++;
360
364
  return r.postMessage(
361
365
  {
362
366
  id: o,
@@ -384,7 +388,7 @@ const Pn = Ur("workerized", {});
384
388
  function ci() {
385
389
  return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope;
386
390
  }
387
- async function xs() {
391
+ async function vs() {
388
392
  if (ci())
389
393
  Ze({ type: ye.GLOBALS_SYNC }, ie);
390
394
  else {
@@ -392,7 +396,7 @@ async function xs() {
392
396
  for (const e in Pn) {
393
397
  const { worker: t, resolvers: n } = Pn[e].workerContext;
394
398
  t && r.push(
395
- ws(
399
+ xs(
396
400
  t,
397
401
  ye.GLOBALS_SYNC,
398
402
  "",
@@ -413,7 +417,7 @@ function Ot(r, e) {
413
417
  for (const t in r)
414
418
  Array.isArray(r[t]) ? (e[t] = [], Ot(r[t], e[t])) : typeof r[t] == "object" ? (e[t] = {}, Ot(r[t], e[t])) : e[t] = r[t];
415
419
  }
416
- async function vs(r, e) {
420
+ async function _s(r, e) {
417
421
  const { functionName: t, args: n } = r;
418
422
  if (!e.instance)
419
423
  throw "instance not initialized";
@@ -423,78 +427,78 @@ async function vs(r, e) {
423
427
  throw `undefined function [${t}] in class ${e.instance.constructor.workerId}`;
424
428
  Ze(r, await e.instance[t](...n ?? []));
425
429
  }
426
- const _s = Ur("registeredWorkers", {});
427
- function Es(r, e) {
430
+ const Es = Ur("registeredWorkers", {});
431
+ function As(r, e) {
428
432
  if (!r.args)
429
433
  throw "Missing className while initializing worker";
430
- const [t, n] = r.args, i = _s[t];
434
+ const [t, n] = r.args, i = Es[t];
431
435
  if (i)
432
436
  e.instance = new i(r.args.slice(1));
433
437
  else
434
438
  throw `unknown worker class ${t}`;
435
439
  Ot(n, ie), Ze(r, typeof e.instance !== void 0);
436
440
  }
437
- async function As(r, e) {
441
+ async function Ts(r, e) {
438
442
  const { args: t } = r;
439
443
  if (!e.instance)
440
444
  throw "instance not initialized";
441
445
  let n;
442
446
  e.instance.terminate && (n = await e.instance.terminate(...t ?? [])), Ze(r, n);
443
447
  }
444
- function Ts(r) {
448
+ function Ss(r) {
445
449
  if (!r.args)
446
450
  throw "Missing globals while syncing";
447
451
  Ot(r.args[0], ie), Ze(r, {});
448
452
  }
449
- function Ss() {
453
+ function Is() {
450
454
  const r = {};
451
455
  onmessage = async (e) => {
452
456
  const t = e.data;
453
457
  switch (t.type) {
454
458
  case ye.INIT:
455
- Es(t, r);
459
+ As(t, r);
456
460
  break;
457
461
  case ye.FORWARD:
458
- vs(t, r);
462
+ _s(t, r);
459
463
  break;
460
464
  case ye.TERMINATE:
461
- As(t, r);
465
+ Ts(t, r);
462
466
  break;
463
467
  case ye.GLOBALS_SYNC:
464
- Ts(t);
468
+ Ss(t);
465
469
  break;
466
470
  }
467
471
  };
468
472
  }
469
- ci() && Ss();
470
- function Is(r, e) {
473
+ ci() && Is();
474
+ function Rs(r, e) {
471
475
  return ie[r] || (ie[r] = e), [
472
476
  () => ie[r],
473
477
  async (t) => {
474
- ie[r] = t, await xs();
478
+ ie[r] = t, await vs();
475
479
  }
476
480
  ];
477
481
  }
478
- function Rs(r, e) {
479
- return Is(r, e);
482
+ function ks(r, e) {
483
+ return Rs(r, e);
480
484
  }
481
- const [ks, Ps] = Rs("metadata");
482
- function Fs(r) {
483
- Ps(r);
485
+ const [Ps, Fs] = ks("metadata");
486
+ function Cs(r) {
487
+ Fs(r);
484
488
  }
485
489
  function Tt() {
486
- return ks();
490
+ return Ps();
487
491
  }
488
492
  let Lr = class {
489
493
  constructor(e, t) {
490
- us(this, "uuid"), this.config = e, this.uuid = t ?? ys();
494
+ ls(this, "uuid"), this.config = e, this.uuid = t ?? bs();
491
495
  }
492
496
  async send(e) {
493
497
  var t, n, i;
494
498
  const { appId: o, sourceType: s } = (t = Tt()) != null ? t : {};
495
499
  if (!o || !s)
496
500
  return "metadata missing";
497
- const a = new AbortController(), c = setTimeout(() => a.abort(), ds);
501
+ const a = new AbortController(), c = setTimeout(() => a.abort(), hs);
498
502
  return await ((i = (n = this.config) == null ? void 0 : n.fetch) != null ? i : fetch)(this.getUrl(), {
499
503
  method: "POST",
500
504
  headers: this.getHeaders(),
@@ -504,8 +508,8 @@ let Lr = class {
504
508
  }
505
509
  getUrl() {
506
510
  var e;
507
- let t = (e = Tt().proxyUrl) != null ? e : fs;
508
- return t += (t.at(-1) === "/" ? "" : "/") + ls, t;
511
+ let t = (e = Tt().proxyUrl) != null ? e : ds;
512
+ return t += (t.at(-1) === "/" ? "" : "/") + fs, t;
509
513
  }
510
514
  getHeaders() {
511
515
  return {
@@ -524,7 +528,7 @@ let Lr = class {
524
528
  };
525
529
  }
526
530
  };
527
- const St = "3.0.1-alpha.0", _r = class {
531
+ const St = "3.0.1", _r = class {
528
532
  };
529
533
  _r.updates = {
530
534
  transformer_new: "New transformer",
@@ -538,11 +542,11 @@ _r.updates = {
538
542
  writable_null: "Writable is null"
539
543
  };
540
544
  let be = _r;
541
- function Cs(r) {
545
+ function Os(r) {
542
546
  return typeof r == "object" && r !== null && "message" in r && typeof r.message == "string";
543
547
  }
544
- function Os(r) {
545
- if (Cs(r)) return r;
548
+ function Ms(r) {
549
+ if (Os(r)) return r;
546
550
  try {
547
551
  return new Error(JSON.stringify(r));
548
552
  } catch {
@@ -550,9 +554,9 @@ function Os(r) {
550
554
  }
551
555
  }
552
556
  function pr(r) {
553
- return Os(r).message;
557
+ return Ms(r).message;
554
558
  }
555
- class Ms {
559
+ class Bs {
556
560
  constructor(e, t) {
557
561
  this.config = e, this.frameTransformedCount = 0, this.frameFromSourceCount = 0, this.startAt = 0, this.reporter = new Lr(e, t);
558
562
  }
@@ -576,12 +580,12 @@ class Ms {
576
580
  })) : "success";
577
581
  }
578
582
  }
579
- var Bs = /* @__PURE__ */ ((r) => (r.FPS_DROP = "fps_drop", r))(Bs || {}), Ds = /* @__PURE__ */ ((r) => (r.start = "start", r.transform = "transform", r.flush = "flush", r))(Ds || {}), Er = /* @__PURE__ */ ((r) => (r.pipeline_ended = "pipeline_ended", r.pipeline_ended_with_error = "pipeline_ended_with_error", r.pipeline_started = "pipeline_started", r.pipeline_started_with_error = "pipeline_started_with_error", r.pipeline_restarted = "pipeline_restarted", r.pipeline_restarted_with_error = "pipeline_restarted_with_error", r))(Er || {});
580
- const Us = 500, Ls = 0.8;
581
- class zs extends J {
583
+ var Ds = /* @__PURE__ */ ((r) => (r.FPS_DROP = "fps_drop", r))(Ds || {}), Us = /* @__PURE__ */ ((r) => (r.start = "start", r.transform = "transform", r.flush = "flush", r))(Us || {}), Er = /* @__PURE__ */ ((r) => (r.pipeline_ended = "pipeline_ended", r.pipeline_ended_with_error = "pipeline_ended_with_error", r.pipeline_started = "pipeline_started", r.pipeline_started_with_error = "pipeline_started_with_error", r.pipeline_restarted = "pipeline_restarted", r.pipeline_restarted_with_error = "pipeline_restarted_with_error", r))(Er || {});
584
+ const Ls = 500, zs = 0.8;
585
+ class Ns extends J {
582
586
  constructor(e, t) {
583
- super(), this.reporter_ = new Lr(), this.reporterQos_ = new Ms({
584
- loggingIntervalFrameCount: Us,
587
+ super(), this.reporter_ = new Lr(), this.reporterQos_ = new Bs({
588
+ loggingIntervalFrameCount: Ls,
585
589
  report: {
586
590
  version: St
587
591
  }
@@ -632,7 +636,7 @@ class zs extends J {
632
636
  };
633
637
  this.emit("error", i);
634
638
  }
635
- if (this.trackExpectedRate_ != -1 && this.trackExpectedRate_ * Ls > this.reporterQos_.fps) {
639
+ if (this.trackExpectedRate_ != -1 && this.trackExpectedRate_ * zs > this.reporterQos_.fps) {
636
640
  const n = {
637
641
  eventMetaData: {
638
642
  transformerIndex: this.index_
@@ -697,11 +701,11 @@ class zs extends J {
697
701
  );
698
702
  }
699
703
  }
700
- class Ns extends J {
704
+ class $s extends J {
701
705
  constructor(e) {
702
706
  super(), this.transformers_ = [], this.trackExpectedRate_ = -1;
703
707
  for (let t = 0; t < e.length; t++) {
704
- let n = new zs(e[t], t);
708
+ let n = new Ns(e[t], t);
705
709
  n.on("error", (i) => {
706
710
  this.emit("error", i);
707
711
  }), n.on("warn", (i) => {
@@ -825,7 +829,7 @@ class ui extends J {
825
829
  return;
826
830
  }
827
831
  let n = !1;
828
- this.pipeline_ && (n = !0, this.pipeline_.clearListeners(), this.pipeline_.destroy()), this.pipeline_ = new Ns(this.transformers_), this.pipeline_.on("warn", (i) => {
832
+ this.pipeline_ && (n = !0, this.pipeline_.clearListeners(), this.pipeline_.destroy()), this.pipeline_ = new $s(this.transformers_), this.pipeline_.on("warn", (i) => {
829
833
  this.emit("warn", i);
830
834
  }), this.pipeline_.on("error", (i) => {
831
835
  this.emit("error", i);
@@ -872,7 +876,7 @@ class ui extends J {
872
876
  return "kind" in e;
873
877
  }
874
878
  }
875
- class $s {
879
+ class Ws {
876
880
  constructor({ kind: e }) {
877
881
  if (e == "video") {
878
882
  const t = document.createElement("canvas"), n = t.getContext("2d", {
@@ -917,10 +921,10 @@ class $s {
917
921
  }
918
922
  }
919
923
  }
920
- function Ws() {
921
- return self.MediaStreamTrackGenerator ? self.MediaStreamTrackGenerator : $s;
924
+ function Gs() {
925
+ return self.MediaStreamTrackGenerator ? self.MediaStreamTrackGenerator : Ws;
922
926
  }
923
- class Gs {
927
+ class Vs {
924
928
  constructor(e) {
925
929
  const t = e.track ?? e;
926
930
  t.kind == "video" ? this.readable = new ReadableStream({
@@ -1007,17 +1011,17 @@ class Gs {
1007
1011
  }));
1008
1012
  }
1009
1013
  }
1010
- function Vs() {
1011
- return self.MediaStreamTrackProcessor ? self.MediaStreamTrackProcessor : Gs;
1014
+ function Hs() {
1015
+ return self.MediaStreamTrackProcessor ? self.MediaStreamTrackProcessor : Vs;
1012
1016
  }
1013
- class Hs {
1017
+ class js {
1014
1018
  constructor() {
1015
1019
  this.processor_ = null, this.generator_ = null;
1016
1020
  }
1017
1021
  init(e) {
1018
1022
  return new Promise((t, n) => {
1019
1023
  try {
1020
- const i = Vs();
1024
+ const i = Hs();
1021
1025
  this.processor_ = new i(e);
1022
1026
  } catch (i) {
1023
1027
  console.log(
@@ -1025,7 +1029,7 @@ class Hs {
1025
1029
  ), n(i);
1026
1030
  }
1027
1031
  try {
1028
- const i = Ws();
1032
+ const i = Gs();
1029
1033
  e.kind === "audio" ? this.generator_ = new i({
1030
1034
  kind: "audio"
1031
1035
  }) : e.kind === "video" ? this.generator_ = new i({
@@ -1049,7 +1053,7 @@ class Hs {
1049
1053
  return this.generator_;
1050
1054
  }
1051
1055
  }
1052
- class js {
1056
+ class Ys {
1053
1057
  /**
1054
1058
  * - When running insertable streams on the main `MediaProcessorInterface` should be instance of `MediaProcessor` class.
1055
1059
  * - When running insertable streams on WebWorker `MediaProcessorInterface` should be instance of bridge calss created by the user. Example can be found [here](/docs/intro.md#using-the-transformer-on-webworker)
@@ -1072,7 +1076,7 @@ class js {
1072
1076
  return await this.mediaProcessor_.transform(e);
1073
1077
  }
1074
1078
  if (oi()) {
1075
- const t = new Hs();
1079
+ const t = new js();
1076
1080
  return await t.init(e), await this.mediaProcessor_.transform(
1077
1081
  t.getReadable(),
1078
1082
  t.getWriteable()
@@ -1093,10 +1097,10 @@ class js {
1093
1097
  });
1094
1098
  }
1095
1099
  }
1096
- var It = /* @__PURE__ */ ((r) => (r.Low = "Low", r.High = "High", r))(It || {}), Ys = /* @__PURE__ */ ((r) => (r.BackgroundBlur = "BackgroundBlur", r.VirtualBackground = "VirtualBackground", r.VideoBackground = "VideoBackground", r.SilhouetteBlur = "SilhouetteBlur", r))(Ys || {}), Ar = /* @__PURE__ */ ((r) => (r.FAST = "FAST", r.PRECISE = "PRECISE", r))(Ar || {}), Mt = /* @__PURE__ */ ((r) => (r.CANVAS = "CANVAS", r.WEBGL = "WEBGL", r))(Mt || {});
1097
- const Qs = async () => WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 10, 1, 8, 0, 65, 0, 253, 15, 253, 98, 11]));
1098
- async function Md() {
1099
- const { wasm: r, insertableStreams: e, simd: t, webgl: n } = await qs();
1100
+ var It = /* @__PURE__ */ ((r) => (r.Low = "Low", r.High = "High", r))(It || {}), Qs = /* @__PURE__ */ ((r) => (r.BackgroundBlur = "BackgroundBlur", r.VirtualBackground = "VirtualBackground", r.VideoBackground = "VideoBackground", r.SilhouetteBlur = "SilhouetteBlur", r))(Qs || {}), Ar = /* @__PURE__ */ ((r) => (r.FAST = "FAST", r.PRECISE = "PRECISE", r))(Ar || {}), Mt = /* @__PURE__ */ ((r) => (r.CANVAS = "CANVAS", r.WEBGL = "WEBGL", r))(Mt || {});
1101
+ const qs = async () => WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 10, 1, 8, 0, 65, 0, 253, 15, 253, 98, 11]));
1102
+ async function Bd() {
1103
+ const { wasm: r, insertableStreams: e, simd: t, webgl: n } = await Xs();
1100
1104
  if (!r.supported)
1101
1105
  throw r.message;
1102
1106
  if (!e.supported)
@@ -1106,14 +1110,14 @@ async function Md() {
1106
1110
  if (!n.supported)
1107
1111
  throw n.message;
1108
1112
  }
1109
- async function qs() {
1113
+ async function Xs() {
1110
1114
  const r = {
1111
1115
  wasm: {
1112
1116
  supported: typeof WebAssembly == "object" && typeof WebAssembly.instantiate == "function",
1113
1117
  message: "Your browser does not support WebAssembly features."
1114
1118
  },
1115
1119
  simd: {
1116
- supported: await Qs(),
1120
+ supported: await qs(),
1117
1121
  message: "Your browser does not support simd features."
1118
1122
  },
1119
1123
  insertableStreams: { supported: !0 },
@@ -1122,7 +1126,7 @@ async function qs() {
1122
1126
  supported: !0
1123
1127
  // This is a legacy check from the previous segmentation engine. now we just return true always
1124
1128
  },
1125
- webgl: Xs(),
1129
+ webgl: Ks(),
1126
1130
  performance: li()
1127
1131
  };
1128
1132
  try {
@@ -1132,7 +1136,7 @@ async function qs() {
1132
1136
  }
1133
1137
  return r;
1134
1138
  }
1135
- function Xs() {
1139
+ function Ks() {
1136
1140
  if (!OffscreenCanvas)
1137
1141
  return {
1138
1142
  supported: !1,
@@ -1184,7 +1188,7 @@ function Ye(r, e) {
1184
1188
  if (n.has(t))
1185
1189
  return n.get(t);
1186
1190
  }
1187
- function Ks(r, e, t) {
1191
+ function Js(r, e, t) {
1188
1192
  const n = X.get(r);
1189
1193
  if (n.has(e))
1190
1194
  for (const i of n.get(e))
@@ -1346,7 +1350,7 @@ let et = class Tr {
1346
1350
  async emit(e, t) {
1347
1351
  if (Se(e), Be(e) && !Lt)
1348
1352
  throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");
1349
- this.logIfDebugEnabled("emit", e, t), Ks(this, e, t);
1353
+ this.logIfDebugEnabled("emit", e, t), Js(this, e, t);
1350
1354
  const n = Ie(this, e) ?? /* @__PURE__ */ new Set(), i = te.get(this), o = [...n], s = Be(e) ? [] : [...i];
1351
1355
  await Fn, await Promise.all([
1352
1356
  ...o.map(async (a) => {
@@ -1462,9 +1466,9 @@ var z = /* @__PURE__ */ ((r) => (r.INIT = "INIT", r.FORWARD = "FORWARD", r.TERMI
1462
1466
  function fi(r) {
1463
1467
  return [ImageBitmap, ReadableStream, WritableStream].some((t) => r instanceof t);
1464
1468
  }
1465
- let Js = 0;
1469
+ let Zs = 0;
1466
1470
  function Nt(r, e, t, n, i) {
1467
- const o = Js++;
1471
+ const o = Zs++;
1468
1472
  return r.postMessage(
1469
1473
  {
1470
1474
  id: o,
@@ -1492,7 +1496,7 @@ const $t = zr("workerized", {});
1492
1496
  function Nr() {
1493
1497
  return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope;
1494
1498
  }
1495
- async function Zs() {
1499
+ async function ea() {
1496
1500
  if (Nr())
1497
1501
  ze({ type: z.GLOBALS_SYNC }, Le);
1498
1502
  else {
@@ -1521,7 +1525,7 @@ function qe(r, e) {
1521
1525
  for (const t in r)
1522
1526
  Array.isArray(r[t]) ? (e[t] = [], qe(r[t], e[t])) : typeof r[t] == "object" ? (e[t] = {}, qe(r[t], e[t])) : e[t] = r[t];
1523
1527
  }
1524
- async function ea(r, e, t, n) {
1528
+ async function ta(r, e, t, n) {
1525
1529
  const i = new e();
1526
1530
  if (i.addEventListener(
1527
1531
  "message",
@@ -1529,7 +1533,7 @@ async function ea(r, e, t, n) {
1529
1533
  var a, c, u, f, m, p, b;
1530
1534
  switch (s.type) {
1531
1535
  case z.GLOBALS_SYNC:
1532
- s.id ? ((c = t.get((a = s.id) != null ? a : -1)) == null || c(s.result), t.delete((u = s.id) != null ? u : -1)) : (qe((f = s.result) != null ? f : {}, Le), await Zs());
1536
+ s.id ? ((c = t.get((a = s.id) != null ? a : -1)) == null || c(s.result), t.delete((u = s.id) != null ? u : -1)) : (qe((f = s.result) != null ? f : {}, Le), await ea());
1533
1537
  break;
1534
1538
  case z.EVENT:
1535
1539
  const { result: d } = s, g = d;
@@ -1571,7 +1575,7 @@ function Qe(r, e) {
1571
1575
  if (n.has(t))
1572
1576
  return n.get(t);
1573
1577
  }
1574
- function ta(r, e, t) {
1578
+ function ra(r, e, t) {
1575
1579
  const n = K.get(r);
1576
1580
  if (n.has(e))
1577
1581
  for (const i of n.get(e))
@@ -1731,7 +1735,7 @@ class ve {
1731
1735
  var n;
1732
1736
  if (Re(e), De(e) && !Ht)
1733
1737
  throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");
1734
- this.logIfDebugEnabled("emit", e, t), ta(this, e, t);
1738
+ this.logIfDebugEnabled("emit", e, t), ra(this, e, t);
1735
1739
  const i = (n = ke(this, e)) != null ? n : /* @__PURE__ */ new Set(), o = re.get(this), s = [...i], a = De(e) ? [] : [...o];
1736
1740
  await Bn, await Promise.all([
1737
1741
  ...s.map(async (c) => {
@@ -1832,15 +1836,15 @@ Object.defineProperty(ve, "listenerRemoved", {
1832
1836
  enumerable: !0,
1833
1837
  configurable: !1
1834
1838
  });
1835
- function ra(r) {
1839
+ function na(r) {
1836
1840
  return r.onAny && r.emit;
1837
1841
  }
1838
- function na(r) {
1842
+ function ia(r) {
1839
1843
  return r.prototype.onAny && r.prototype.emit;
1840
1844
  }
1841
- let ia = 0;
1842
- async function oa(r, e, t) {
1843
- const i = na(r) ? new ve() : {}, o = ia++;
1845
+ let oa = 0;
1846
+ async function sa(r, e, t) {
1847
+ const i = ia(r) ? new ve() : {}, o = oa++;
1844
1848
  return Object.getOwnPropertyNames(r.prototype).forEach(
1845
1849
  (s) => {
1846
1850
  i[s] = (...a) => Nt(e, z.FORWARD, s, a, t);
@@ -1860,10 +1864,10 @@ async function oa(r, e, t) {
1860
1864
  resolvers: t
1861
1865
  }, $t[o] = i, i;
1862
1866
  }
1863
- async function sa(r, e) {
1867
+ async function aa(r, e) {
1864
1868
  const t = /* @__PURE__ */ new Map();
1865
1869
  let n;
1866
- const i = await ea(
1870
+ const i = await ta(
1867
1871
  r,
1868
1872
  e,
1869
1873
  t,
@@ -1871,13 +1875,13 @@ async function sa(r, e) {
1871
1875
  n?.emit && n?.emit(o, s);
1872
1876
  }
1873
1877
  );
1874
- return n = await oa(
1878
+ return n = await sa(
1875
1879
  r,
1876
1880
  i,
1877
1881
  t
1878
1882
  ), n;
1879
1883
  }
1880
- async function aa(r, e) {
1884
+ async function ca(r, e) {
1881
1885
  const { functionName: t, args: n } = r;
1882
1886
  if (!e.instance)
1883
1887
  throw "instance not initialized";
@@ -1888,10 +1892,10 @@ async function aa(r, e) {
1888
1892
  ze(r, await e.instance[t](...n ?? []));
1889
1893
  }
1890
1894
  const di = zr("registeredWorkers", {});
1891
- function ca(r, e) {
1895
+ function ua(r, e) {
1892
1896
  e.workerId = r, Nr() && (di[e.workerId] = e);
1893
1897
  }
1894
- function ua(r, e) {
1898
+ function la(r, e) {
1895
1899
  if (!r.args)
1896
1900
  throw "Missing className while initializing worker";
1897
1901
  const [t, n] = r.args, i = di[t];
@@ -1899,7 +1903,7 @@ function ua(r, e) {
1899
1903
  e.instance = new i(r.args.slice(1));
1900
1904
  else
1901
1905
  throw `unknown worker class ${t}`;
1902
- qe(n, Le), ra(e.instance) && e.instance.onAny((o, s) => {
1906
+ qe(n, Le), na(e.instance) && e.instance.onAny((o, s) => {
1903
1907
  ze(
1904
1908
  {
1905
1909
  type: z.EVENT
@@ -1908,39 +1912,39 @@ function ua(r, e) {
1908
1912
  );
1909
1913
  }), ze(r, typeof e.instance !== void 0);
1910
1914
  }
1911
- async function la(r, e) {
1915
+ async function fa(r, e) {
1912
1916
  const { args: t } = r;
1913
1917
  if (!e.instance)
1914
1918
  throw "instance not initialized";
1915
1919
  let n;
1916
1920
  e.instance.terminate && (n = await e.instance.terminate(...t ?? [])), ze(r, n);
1917
1921
  }
1918
- function fa(r) {
1922
+ function da(r) {
1919
1923
  if (!r.args)
1920
1924
  throw "Missing globals while syncing";
1921
1925
  qe(r.args[0], Le), ze(r, {});
1922
1926
  }
1923
- function da() {
1927
+ function ha() {
1924
1928
  const r = {};
1925
1929
  onmessage = async (e) => {
1926
1930
  const t = e.data;
1927
1931
  switch (t.type) {
1928
1932
  case z.INIT:
1929
- ua(t, r);
1933
+ la(t, r);
1930
1934
  break;
1931
1935
  case z.FORWARD:
1932
- aa(t, r);
1936
+ ca(t, r);
1933
1937
  break;
1934
1938
  case z.TERMINATE:
1935
- la(t, r);
1939
+ fa(t, r);
1936
1940
  break;
1937
1941
  case z.GLOBALS_SYNC:
1938
- fa(t);
1942
+ da(t);
1939
1943
  break;
1940
1944
  }
1941
1945
  };
1942
1946
  }
1943
- Nr() && da();
1947
+ Nr() && ha();
1944
1948
  class zn {
1945
1949
  static async createVideoReadable(e) {
1946
1950
  return new Promise((t, n) => {
@@ -1975,30 +1979,30 @@ class zn {
1975
1979
  return await createImageBitmap(n);
1976
1980
  }
1977
1981
  }
1978
- var ha = Object.defineProperty, ma = (r, e, t) => e in r ? ha(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, pa = (r, e, t) => (ma(r, e + "", t), t);
1979
- const ga = "hlg.tokbox.com/prod/logging/vcp_webrtc", ya = "https://", ba = 1e4;
1982
+ var ma = Object.defineProperty, pa = (r, e, t) => e in r ? ma(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, ga = (r, e, t) => (pa(r, e + "", t), t);
1983
+ const ya = "hlg.tokbox.com/prod/logging/vcp_webrtc", ba = "https://", wa = 1e4;
1980
1984
  let bt;
1981
- const wa = new Uint8Array(16);
1982
- function xa() {
1985
+ const xa = new Uint8Array(16);
1986
+ function va() {
1983
1987
  if (!bt && (bt = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !bt))
1984
1988
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1985
- return bt(wa);
1989
+ return bt(xa);
1986
1990
  }
1987
1991
  const C = [];
1988
1992
  for (let r = 0; r < 256; ++r)
1989
1993
  C.push((r + 256).toString(16).slice(1));
1990
- function va(r, e = 0) {
1994
+ function _a(r, e = 0) {
1991
1995
  return (C[r[e + 0]] + C[r[e + 1]] + C[r[e + 2]] + C[r[e + 3]] + "-" + C[r[e + 4]] + C[r[e + 5]] + "-" + C[r[e + 6]] + C[r[e + 7]] + "-" + C[r[e + 8]] + C[r[e + 9]] + "-" + C[r[e + 10]] + C[r[e + 11]] + C[r[e + 12]] + C[r[e + 13]] + C[r[e + 14]] + C[r[e + 15]]).toLowerCase();
1992
1996
  }
1993
- const _a = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Nn = {
1994
- randomUUID: _a
1997
+ const Ea = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Nn = {
1998
+ randomUUID: Ea
1995
1999
  };
1996
- function Ea(r, e, t) {
2000
+ function Aa(r, e, t) {
1997
2001
  if (Nn.randomUUID && !e && !r)
1998
2002
  return Nn.randomUUID();
1999
2003
  r = r || {};
2000
- const n = r.random || (r.rng || xa)();
2001
- return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, va(n);
2004
+ const n = r.random || (r.rng || va)();
2005
+ return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, _a(n);
2002
2006
  }
2003
2007
  function $r(r, e) {
2004
2008
  globalThis.vonage || (globalThis.vonage = {}), globalThis.vonage.workerizer || (globalThis.vonage.workerizer = {});
@@ -2013,9 +2017,9 @@ var we = /* @__PURE__ */ ((r) => (r.INIT = "INIT", r.FORWARD = "FORWARD", r.TERM
2013
2017
  function hi(r) {
2014
2018
  return [ImageBitmap, ReadableStream, WritableStream].some((e) => r instanceof e);
2015
2019
  }
2016
- let Aa = 0;
2017
- function Ta(r, e, t, n, i) {
2018
- const o = Aa++;
2020
+ let Ta = 0;
2021
+ function Sa(r, e, t, n, i) {
2022
+ const o = Ta++;
2019
2023
  return r.postMessage(
2020
2024
  {
2021
2025
  id: o,
@@ -2043,7 +2047,7 @@ const $n = $r("workerized", {});
2043
2047
  function mi() {
2044
2048
  return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope;
2045
2049
  }
2046
- async function Sa() {
2050
+ async function Ia() {
2047
2051
  if (mi())
2048
2052
  tt({ type: we.GLOBALS_SYNC }, oe);
2049
2053
  else {
@@ -2051,7 +2055,7 @@ async function Sa() {
2051
2055
  for (const e in $n) {
2052
2056
  const { worker: t, resolvers: n } = $n[e].workerContext;
2053
2057
  t && r.push(
2054
- Ta(
2058
+ Sa(
2055
2059
  t,
2056
2060
  we.GLOBALS_SYNC,
2057
2061
  "",
@@ -2072,7 +2076,7 @@ function jt(r, e) {
2072
2076
  for (const t in r)
2073
2077
  Array.isArray(r[t]) ? (e[t] = [], jt(r[t], e[t])) : typeof r[t] == "object" ? (e[t] = {}, jt(r[t], e[t])) : e[t] = r[t];
2074
2078
  }
2075
- async function Ia(r, e) {
2079
+ async function Ra(r, e) {
2076
2080
  const { functionName: t, args: n } = r;
2077
2081
  if (!e.instance)
2078
2082
  throw "instance not initialized";
@@ -2082,75 +2086,75 @@ async function Ia(r, e) {
2082
2086
  throw `undefined function [${t}] in class ${e.instance.constructor.workerId}`;
2083
2087
  tt(r, await e.instance[t](...n ?? []));
2084
2088
  }
2085
- const Ra = $r("registeredWorkers", {});
2086
- function ka(r, e) {
2089
+ const ka = $r("registeredWorkers", {});
2090
+ function Pa(r, e) {
2087
2091
  if (!r.args)
2088
2092
  throw "Missing className while initializing worker";
2089
- const [t, n] = r.args, i = Ra[t];
2093
+ const [t, n] = r.args, i = ka[t];
2090
2094
  if (i)
2091
2095
  e.instance = new i(r.args.slice(1));
2092
2096
  else
2093
2097
  throw `unknown worker class ${t}`;
2094
2098
  jt(n, oe), tt(r, typeof e.instance !== void 0);
2095
2099
  }
2096
- async function Pa(r, e) {
2100
+ async function Fa(r, e) {
2097
2101
  const { args: t } = r;
2098
2102
  if (!e.instance)
2099
2103
  throw "instance not initialized";
2100
2104
  let n;
2101
2105
  e.instance.terminate && (n = await e.instance.terminate(...t ?? [])), tt(r, n);
2102
2106
  }
2103
- function Fa(r) {
2107
+ function Ca(r) {
2104
2108
  if (!r.args)
2105
2109
  throw "Missing globals while syncing";
2106
2110
  jt(r.args[0], oe), tt(r, {});
2107
2111
  }
2108
- function Ca() {
2112
+ function Oa() {
2109
2113
  const r = {};
2110
2114
  onmessage = async (e) => {
2111
2115
  const t = e.data;
2112
2116
  switch (t.type) {
2113
2117
  case we.INIT:
2114
- ka(t, r);
2118
+ Pa(t, r);
2115
2119
  break;
2116
2120
  case we.FORWARD:
2117
- Ia(t, r);
2121
+ Ra(t, r);
2118
2122
  break;
2119
2123
  case we.TERMINATE:
2120
- Pa(t, r);
2124
+ Fa(t, r);
2121
2125
  break;
2122
2126
  case we.GLOBALS_SYNC:
2123
- Fa(t);
2127
+ Ca(t);
2124
2128
  break;
2125
2129
  }
2126
2130
  };
2127
2131
  }
2128
- mi() && Ca();
2129
- function Oa(r, e) {
2132
+ mi() && Oa();
2133
+ function Ma(r, e) {
2130
2134
  return oe[r] || (oe[r] = e), [
2131
2135
  () => oe[r],
2132
2136
  async (t) => {
2133
- oe[r] = t, await Sa();
2137
+ oe[r] = t, await Ia();
2134
2138
  }
2135
2139
  ];
2136
2140
  }
2137
- function Ma(r, e) {
2138
- return Oa(r, e);
2141
+ function Ba(r, e) {
2142
+ return Ma(r, e);
2139
2143
  }
2140
- const [Ba] = Ma("metadata");
2144
+ const [Da] = Ba("metadata");
2141
2145
  function br() {
2142
- return Ba();
2146
+ return Da();
2143
2147
  }
2144
- class Da {
2148
+ class Ua {
2145
2149
  constructor(e) {
2146
- pa(this, "uuid", Ea()), this.config = e;
2150
+ ga(this, "uuid", Aa()), this.config = e;
2147
2151
  }
2148
2152
  async send(e) {
2149
2153
  var t, n, i;
2150
2154
  const { appId: o, sourceType: s } = (t = br()) != null ? t : {};
2151
2155
  if (!o || !s)
2152
2156
  return "metadata missing";
2153
- const a = new AbortController(), c = setTimeout(() => a.abort(), ba);
2157
+ const a = new AbortController(), c = setTimeout(() => a.abort(), wa);
2154
2158
  return await ((i = (n = this.config) == null ? void 0 : n.fetch) != null ? i : fetch)(this.getUrl(), {
2155
2159
  method: "POST",
2156
2160
  headers: this.getHeaders(),
@@ -2160,8 +2164,8 @@ class Da {
2160
2164
  }
2161
2165
  getUrl() {
2162
2166
  var e;
2163
- let t = (e = br().proxyUrl) != null ? e : ya;
2164
- return t += (t.at(-1) === "/" ? "" : "/") + ga, t;
2167
+ let t = (e = br().proxyUrl) != null ? e : ba;
2168
+ return t += (t.at(-1) === "/" ? "" : "/") + ya, t;
2165
2169
  }
2166
2170
  getHeaders() {
2167
2171
  return {
@@ -2180,7 +2184,7 @@ class Da {
2180
2184
  };
2181
2185
  }
2182
2186
  }
2183
- const Ua = "7.0.0-alpha.3";
2187
+ const La = "7.0.0";
2184
2188
  class Wr {
2185
2189
  constructor() {
2186
2190
  const e = new OffscreenCanvas(0, 0), t = e.getContext("2d", { willReadFrequently: !0 });
@@ -2239,7 +2243,7 @@ class Wr {
2239
2243
  destroy() {
2240
2244
  }
2241
2245
  }
2242
- class La extends Wr {
2246
+ class za extends Wr {
2243
2247
  constructor(e) {
2244
2248
  super(), this.radius = e;
2245
2249
  }
@@ -2249,7 +2253,7 @@ class La extends Wr {
2249
2253
  return this.renderSilhouette(e, n), this.context.save(), this.context.filter = `blur(${this.radius}px)`, this.context.globalCompositeOperation = "destination-over", this.context.drawImage(e, 0, 0, e.width, e.height), this.context.restore(), super.render(e, t);
2250
2254
  }
2251
2255
  }
2252
- class za extends Wr {
2256
+ class Na extends Wr {
2253
2257
  constructor(e) {
2254
2258
  super(), this.radius = e;
2255
2259
  }
@@ -2259,7 +2263,7 @@ class za extends Wr {
2259
2263
  return this.renderSilhouette(e, n, `blur(${this.radius}px)`), this.context.save(), this.context.filter = "none", this.context.globalCompositeOperation = "destination-over", this.context.drawImage(e, 0, 0, e.width, e.height), this.context.restore(), super.render(e, t);
2260
2264
  }
2261
2265
  }
2262
- class Na extends Wr {
2266
+ class $a extends Wr {
2263
2267
  setBackgroundImage(e) {
2264
2268
  this.backgroundImage = e;
2265
2269
  }
@@ -2279,10 +2283,10 @@ class Na extends Wr {
2279
2283
  ), this.context.restore()), super.render(e, t);
2280
2284
  }
2281
2285
  }
2282
- const Gr = 5120, Xe = 5121, Vr = 5122, Hr = 5123, jr = 5124, Yr = 5125, Qr = 5126, $a = 32819, Wa = 32820, Ga = 33635, Va = 5131, Ha = 33640, ja = 35899, Ya = 35902, Qa = 36269, qa = 34042, pi = {};
2286
+ const Gr = 5120, Xe = 5121, Vr = 5122, Hr = 5123, jr = 5124, Yr = 5125, Qr = 5126, Wa = 32819, Ga = 32820, Va = 33635, Ha = 5131, ja = 33640, Ya = 35899, Qa = 35902, qa = 36269, Xa = 34042, pi = {};
2283
2287
  {
2284
2288
  const r = pi;
2285
- r[Gr] = Int8Array, r[Xe] = Uint8Array, r[Vr] = Int16Array, r[Hr] = Uint16Array, r[jr] = Int32Array, r[Yr] = Uint32Array, r[Qr] = Float32Array, r[$a] = Uint16Array, r[Wa] = Uint16Array, r[Ga] = Uint16Array, r[Va] = Uint16Array, r[Ha] = Uint32Array, r[ja] = Uint32Array, r[Ya] = Uint32Array, r[Qa] = Uint32Array, r[qa] = Uint32Array;
2289
+ r[Gr] = Int8Array, r[Xe] = Uint8Array, r[Vr] = Int16Array, r[Hr] = Uint16Array, r[jr] = Int32Array, r[Yr] = Uint32Array, r[Qr] = Float32Array, r[Wa] = Uint16Array, r[Ga] = Uint16Array, r[Va] = Uint16Array, r[Ha] = Uint16Array, r[ja] = Uint32Array, r[Ya] = Uint32Array, r[Qa] = Uint32Array, r[qa] = Uint32Array, r[Xa] = Uint32Array;
2286
2290
  }
2287
2291
  function qr(r) {
2288
2292
  if (r instanceof Int8Array)
@@ -2345,49 +2349,49 @@ function Zt(r, e) {
2345
2349
  }
2346
2350
  return n;
2347
2351
  }
2348
- function Xa(r, e) {
2352
+ function Ka(r, e) {
2349
2353
  return typeof WebGLBuffer < "u" && Zt(e, "WebGLBuffer");
2350
2354
  }
2351
- function Ka(r, e) {
2355
+ function Ja(r, e) {
2352
2356
  return typeof WebGLRenderbuffer < "u" && Zt(e, "WebGLRenderbuffer");
2353
2357
  }
2354
2358
  function Xr(r, e) {
2355
2359
  return typeof WebGLTexture < "u" && Zt(e, "WebGLTexture");
2356
2360
  }
2357
- function Ja(r, e) {
2361
+ function Za(r, e) {
2358
2362
  return typeof WebGLSampler < "u" && Zt(e, "WebGLSampler");
2359
2363
  }
2360
- const wi = 35044, xe = 34962, Za = 34963, ec = 34660, tc = 5120, rc = 5121, nc = 5122, ic = 5123, oc = 5124, sc = 5125, xi = 5126, vi = {
2364
+ const wi = 35044, xe = 34962, ec = 34963, tc = 34660, rc = 5120, nc = 5121, ic = 5122, oc = 5123, sc = 5124, ac = 5125, xi = 5126, vi = {
2361
2365
  attribPrefix: ""
2362
2366
  };
2363
- function ac(r, e, t, n, i) {
2367
+ function cc(r, e, t, n, i) {
2364
2368
  r.bindBuffer(e, t), r.bufferData(e, n, i || wi);
2365
2369
  }
2366
2370
  function _i(r, e, t, n) {
2367
- if (Xa(r, e))
2371
+ if (Ka(r, e))
2368
2372
  return e;
2369
2373
  t = t || xe;
2370
2374
  const i = r.createBuffer();
2371
- return ac(r, t, i, e, n), i;
2375
+ return cc(r, t, i, e, n), i;
2372
2376
  }
2373
2377
  function Ei(r) {
2374
2378
  return r === "indices";
2375
2379
  }
2376
- function cc(r) {
2380
+ function uc(r) {
2377
2381
  return r === Int8Array || r === Uint8Array;
2378
2382
  }
2379
- function uc(r) {
2383
+ function lc(r) {
2380
2384
  return r.length ? r : r.data;
2381
2385
  }
2382
- const lc = /coord|texture/i, fc = /color|colour/i;
2383
- function dc(r, e) {
2386
+ const fc = /coord|texture/i, dc = /color|colour/i;
2387
+ function hc(r, e) {
2384
2388
  let t;
2385
- if (lc.test(r) ? t = 2 : fc.test(r) ? t = 4 : t = 3, e % t > 0)
2389
+ if (fc.test(r) ? t = 2 : dc.test(r) ? t = 4 : t = 3, e % t > 0)
2386
2390
  throw new Error(`Can not guess numComponents for attribute '${r}'. Tried ${t} but ${e} values is not evenly divisible by ${t}. You should specify it.`);
2387
2391
  return t;
2388
2392
  }
2389
- function hc(r, e, t) {
2390
- return r.numComponents || r.size || dc(e, t || uc(r).length);
2393
+ function mc(r, e, t) {
2394
+ return r.numComponents || r.size || hc(e, t || lc(r).length);
2391
2395
  }
2392
2396
  function Ai(r, e) {
2393
2397
  if (Yt(r))
@@ -2400,22 +2404,22 @@ function Ai(r, e) {
2400
2404
  let t = r.type ? Kr(r.type) : void 0;
2401
2405
  return t || (Ei(e) ? t = Uint16Array : t = Float32Array), new t(r.data);
2402
2406
  }
2403
- function mc(r) {
2407
+ function pc(r) {
2404
2408
  return typeof r == "number" ? r : r ? gi(r) : xi;
2405
2409
  }
2406
2410
  function Kr(r) {
2407
2411
  return typeof r == "number" ? yi(r) : r || Float32Array;
2408
2412
  }
2409
- function pc(r, e) {
2413
+ function gc(r, e) {
2410
2414
  return {
2411
2415
  buffer: e.buffer,
2412
2416
  numValues: 24,
2413
2417
  // safely divided by 2, 3, 4
2414
- type: mc(e.type),
2418
+ type: pc(e.type),
2415
2419
  arrayType: Kr(e.type)
2416
2420
  };
2417
2421
  }
2418
- function gc(r, e) {
2422
+ function yc(r, e) {
2419
2423
  const t = e.data || e, n = Kr(e.type), i = t * n.BYTES_PER_ELEMENT, o = r.createBuffer();
2420
2424
  return r.bindBuffer(xe, o), r.bufferData(xe, i, e.drawType || wi), {
2421
2425
  buffer: o,
@@ -2424,7 +2428,7 @@ function gc(r, e) {
2424
2428
  arrayType: n
2425
2429
  };
2426
2430
  }
2427
- function yc(r, e, t) {
2431
+ function bc(r, e, t) {
2428
2432
  const n = Ai(e, t);
2429
2433
  return {
2430
2434
  arrayType: n.constructor,
@@ -2433,7 +2437,7 @@ function yc(r, e, t) {
2433
2437
  numValues: 0
2434
2438
  };
2435
2439
  }
2436
- function bc(r, e) {
2440
+ function wc(r, e) {
2437
2441
  const t = {};
2438
2442
  return Object.keys(e).forEach(function(n) {
2439
2443
  if (!Ei(n)) {
@@ -2446,8 +2450,8 @@ function bc(r, e) {
2446
2450
  };
2447
2451
  } else {
2448
2452
  let s;
2449
- i.buffer && i.buffer instanceof WebGLBuffer ? s = pc : typeof i == "number" || typeof i.data == "number" ? s = gc : s = yc;
2450
- const { buffer: a, type: c, numValues: u, arrayType: f } = s(r, i, n), m = i.normalize !== void 0 ? i.normalize : cc(f), p = hc(i, n, u);
2453
+ i.buffer && i.buffer instanceof WebGLBuffer ? s = gc : typeof i == "number" || typeof i.data == "number" ? s = yc : s = bc;
2454
+ const { buffer: a, type: c, numValues: u, arrayType: f } = s(r, i, n), m = i.normalize !== void 0 ? i.normalize : uc(f), p = mc(i, n, u);
2451
2455
  t[o] = {
2452
2456
  buffer: a,
2453
2457
  numComponents: p,
@@ -2462,11 +2466,11 @@ function bc(r, e) {
2462
2466
  }
2463
2467
  }), r.bindBuffer(xe, null), t;
2464
2468
  }
2465
- function wc(r, e) {
2466
- return e === tc || e === rc ? 1 : e === nc || e === ic ? 2 : e === oc || e === sc || e === xi ? 4 : 0;
2469
+ function xc(r, e) {
2470
+ return e === rc || e === nc ? 1 : e === ic || e === oc ? 2 : e === sc || e === ac || e === xi ? 4 : 0;
2467
2471
  }
2468
2472
  const wr = ["position", "positions", "a_position"];
2469
- function xc(r, e) {
2473
+ function vc(r, e) {
2470
2474
  let t, n;
2471
2475
  for (n = 0; n < wr.length && (t = wr[n], !(t in e || (t = vi.attribPrefix + t, t in e))); ++n)
2472
2476
  ;
@@ -2475,21 +2479,21 @@ function xc(r, e) {
2475
2479
  if (!i.buffer)
2476
2480
  return 1;
2477
2481
  r.bindBuffer(xe, i.buffer);
2478
- const o = r.getBufferParameter(xe, ec);
2482
+ const o = r.getBufferParameter(xe, tc);
2479
2483
  r.bindBuffer(xe, null);
2480
- const s = wc(r, i.type), a = o / s, c = i.numComponents || i.size, u = a / c;
2484
+ const s = xc(r, i.type), a = o / s, c = i.numComponents || i.size, u = a / c;
2481
2485
  if (u % 1 !== 0)
2482
2486
  throw new Error(`numComponents ${c} not correct for length ${length}`);
2483
2487
  return u;
2484
2488
  }
2485
- function vc(r, e, t) {
2486
- const n = bc(r, e), i = Object.assign({}, t || {});
2489
+ function _c(r, e, t) {
2490
+ const n = wc(r, e), i = Object.assign({}, t || {});
2487
2491
  i.attribs = Object.assign({}, t ? t.attribs : {}, n);
2488
2492
  const o = e.indices;
2489
2493
  if (o) {
2490
2494
  const s = Ai(o, "indices");
2491
- i.indices = _i(r, s, Za), i.numElements = s.length, i.elementType = qr(s);
2492
- } else i.numElements || (i.numElements = xc(r, i.attribs));
2495
+ i.indices = _i(r, s, ec), i.numElements = s.length, i.elementType = qr(s);
2496
+ } else i.numElements || (i.numElements = vc(r, i.attribs));
2493
2497
  return i;
2494
2498
  }
2495
2499
  function rt(r) {
@@ -2520,12 +2524,12 @@ const Ti = /* @__PURE__ */ (function() {
2520
2524
  return function() {
2521
2525
  return r = r || (typeof document < "u" && document.createElement ? document.createElement("canvas").getContext("2d") : null), r;
2522
2526
  };
2523
- })(), Gn = 6406, j = 6407, T = 6408, Vn = 6409, Hn = 6410, Ve = 6402, jn = 34041, Qt = 33071, _c = 9728, Ec = 9729, ce = 3553, se = 34067, _e = 32879, Ee = 35866, Jr = 34069, Ac = 34070, Tc = 34071, Sc = 34072, Ic = 34073, Rc = 34074, Sr = 10241, Ir = 10240, qt = 10242, Xt = 10243, Yn = 32882, kc = 33082, Pc = 33083, Fc = 33084, Cc = 33085, Oc = 34892, Mc = 34893, Zr = 3317, Ii = 3314, Ri = 32878, ki = 3316, Pi = 3315, Fi = 32877, Bc = 37443, Dc = 37441, Uc = 37440, Lc = 33321, zc = 36756, Nc = 33325, $c = 33326, Wc = 33330, Gc = 33329, Vc = 33338, Hc = 33337, jc = 33340, Yc = 33339, Qc = 33323, qc = 36757, Xc = 33327, Kc = 33328, Jc = 33336, Zc = 33335, eu = 33332, tu = 33331, ru = 33334, nu = 33333, iu = 32849, ou = 35905, su = 36194, au = 36758, cu = 35898, uu = 35901, lu = 34843, fu = 34837, du = 36221, hu = 36239, mu = 36215, pu = 36233, gu = 36209, yu = 36227, bu = 32856, wu = 35907, xu = 36759, vu = 32855, _u = 32854, Eu = 32857, Au = 34842, Tu = 34836, Su = 36220, Iu = 36238, Ru = 36975, ku = 36214, Pu = 36232, Fu = 36226, Cu = 36208, Ou = 33189, Mu = 33190, Bu = 36012, Du = 36013, Uu = 35056, ne = 5120, A = 5121, wt = 5122, Pe = 5123, xt = 5124, de = 5125, M = 5126, Qn = 32819, qn = 32820, Xn = 33635, G = 5131, He = 36193, xr = 33640, Lu = 35899, zu = 35902, Nu = 36269, $u = 34042, vt = 33319, Fe = 33320, _t = 6403, Ce = 36244, Oe = 36248, he = 36249;
2527
+ })(), Gn = 6406, j = 6407, T = 6408, Vn = 6409, Hn = 6410, Ve = 6402, jn = 34041, Qt = 33071, Ec = 9728, Ac = 9729, ce = 3553, se = 34067, _e = 32879, Ee = 35866, Jr = 34069, Tc = 34070, Sc = 34071, Ic = 34072, Rc = 34073, kc = 34074, Sr = 10241, Ir = 10240, qt = 10242, Xt = 10243, Yn = 32882, Pc = 33082, Fc = 33083, Cc = 33084, Oc = 33085, Mc = 34892, Bc = 34893, Zr = 3317, Ii = 3314, Ri = 32878, ki = 3316, Pi = 3315, Fi = 32877, Dc = 37443, Uc = 37441, Lc = 37440, zc = 33321, Nc = 36756, $c = 33325, Wc = 33326, Gc = 33330, Vc = 33329, Hc = 33338, jc = 33337, Yc = 33340, Qc = 33339, qc = 33323, Xc = 36757, Kc = 33327, Jc = 33328, Zc = 33336, eu = 33335, tu = 33332, ru = 33331, nu = 33334, iu = 33333, ou = 32849, su = 35905, au = 36194, cu = 36758, uu = 35898, lu = 35901, fu = 34843, du = 34837, hu = 36221, mu = 36239, pu = 36215, gu = 36233, yu = 36209, bu = 36227, wu = 32856, xu = 35907, vu = 36759, _u = 32855, Eu = 32854, Au = 32857, Tu = 34842, Su = 34836, Iu = 36220, Ru = 36238, ku = 36975, Pu = 36214, Fu = 36232, Cu = 36226, Ou = 36208, Mu = 33189, Bu = 33190, Du = 36012, Uu = 36013, Lu = 35056, ne = 5120, A = 5121, wt = 5122, Pe = 5123, xt = 5124, de = 5125, M = 5126, Qn = 32819, qn = 32820, Xn = 33635, G = 5131, He = 36193, xr = 33640, zu = 35899, Nu = 35902, $u = 36269, Wu = 34042, vt = 33319, Fe = 33320, _t = 6403, Ce = 36244, Oe = 36248, he = 36249;
2524
2528
  let vr;
2525
2529
  function er(r) {
2526
2530
  if (!vr) {
2527
2531
  const e = {};
2528
- e[Gn] = { textureFormat: Gn, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [1, 2, 2, 4], type: [A, G, He, M] }, e[Vn] = { textureFormat: Vn, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [1, 2, 2, 4], type: [A, G, He, M] }, e[Hn] = { textureFormat: Hn, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [2, 4, 4, 8], type: [A, G, He, M] }, e[j] = { textureFormat: j, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [3, 6, 6, 12, 2], type: [A, G, He, M, Xn] }, e[T] = { textureFormat: T, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4, 8, 8, 16, 2, 2], type: [A, G, He, M, Qn, qn] }, e[Ve] = { textureFormat: Ve, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2, 4], type: [de, Pe] }, e[Lc] = { textureFormat: _t, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [1], type: [A] }, e[zc] = { textureFormat: _t, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [1], type: [ne] }, e[Nc] = { textureFormat: _t, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [4, 2], type: [M, G] }, e[$c] = { textureFormat: _t, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [4], type: [M] }, e[Wc] = { textureFormat: Ce, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [1], type: [A] }, e[Gc] = { textureFormat: Ce, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [1], type: [ne] }, e[eu] = { textureFormat: Ce, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2], type: [Pe] }, e[tu] = { textureFormat: Ce, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2], type: [wt] }, e[ru] = { textureFormat: Ce, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [de] }, e[nu] = { textureFormat: Ce, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [xt] }, e[Qc] = { textureFormat: vt, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [2], type: [A] }, e[qc] = { textureFormat: vt, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [2], type: [ne] }, e[Xc] = { textureFormat: vt, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [8, 4], type: [M, G] }, e[Kc] = { textureFormat: vt, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [8], type: [M] }, e[Jc] = { textureFormat: Fe, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2], type: [A] }, e[Zc] = { textureFormat: Fe, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2], type: [ne] }, e[Vc] = { textureFormat: Fe, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [Pe] }, e[Hc] = { textureFormat: Fe, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [wt] }, e[jc] = { textureFormat: Fe, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [8], type: [de] }, e[Yc] = { textureFormat: Fe, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [8], type: [xt] }, e[iu] = { textureFormat: j, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [3], type: [A] }, e[ou] = { textureFormat: j, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [3], type: [A] }, e[su] = { textureFormat: j, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [3, 2], type: [A, Xn] }, e[au] = { textureFormat: j, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [3], type: [ne] }, e[cu] = { textureFormat: j, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [12, 6, 4], type: [M, G, Lu] }, e[uu] = { textureFormat: j, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [12, 6, 4], type: [M, G, zu] }, e[lu] = { textureFormat: j, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [12, 6], type: [M, G] }, e[fu] = { textureFormat: j, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [12], type: [M] }, e[du] = { textureFormat: Oe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [3], type: [A] }, e[hu] = { textureFormat: Oe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [3], type: [ne] }, e[mu] = { textureFormat: Oe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [6], type: [Pe] }, e[pu] = { textureFormat: Oe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [6], type: [wt] }, e[gu] = { textureFormat: Oe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [12], type: [de] }, e[yu] = { textureFormat: Oe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [12], type: [xt] }, e[bu] = { textureFormat: T, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4], type: [A] }, e[wu] = { textureFormat: T, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4], type: [A] }, e[xu] = { textureFormat: T, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [4], type: [ne] }, e[vu] = { textureFormat: T, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4, 2, 4], type: [A, qn, xr] }, e[_u] = { textureFormat: T, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4, 2], type: [A, Qn] }, e[Eu] = { textureFormat: T, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4], type: [xr] }, e[Au] = { textureFormat: T, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [16, 8], type: [M, G] }, e[Tu] = { textureFormat: T, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [16], type: [M] }, e[Su] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [A] }, e[Iu] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [ne] }, e[Ru] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [xr] }, e[ku] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [8], type: [Pe] }, e[Pu] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [8], type: [wt] }, e[Fu] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [16], type: [xt] }, e[Cu] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [16], type: [de] }, e[Ou] = { textureFormat: Ve, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2, 4], type: [Pe, de] }, e[Mu] = { textureFormat: Ve, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [de] }, e[Bu] = { textureFormat: Ve, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [M] }, e[Uu] = { textureFormat: jn, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [$u] }, e[Du] = { textureFormat: jn, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [Nu] }, Object.keys(e).forEach(function(t) {
2532
+ e[Gn] = { textureFormat: Gn, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [1, 2, 2, 4], type: [A, G, He, M] }, e[Vn] = { textureFormat: Vn, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [1, 2, 2, 4], type: [A, G, He, M] }, e[Hn] = { textureFormat: Hn, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [2, 4, 4, 8], type: [A, G, He, M] }, e[j] = { textureFormat: j, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [3, 6, 6, 12, 2], type: [A, G, He, M, Xn] }, e[T] = { textureFormat: T, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4, 8, 8, 16, 2, 2], type: [A, G, He, M, Qn, qn] }, e[Ve] = { textureFormat: Ve, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2, 4], type: [de, Pe] }, e[zc] = { textureFormat: _t, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [1], type: [A] }, e[Nc] = { textureFormat: _t, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [1], type: [ne] }, e[$c] = { textureFormat: _t, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [4, 2], type: [M, G] }, e[Wc] = { textureFormat: _t, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [4], type: [M] }, e[Gc] = { textureFormat: Ce, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [1], type: [A] }, e[Vc] = { textureFormat: Ce, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [1], type: [ne] }, e[tu] = { textureFormat: Ce, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2], type: [Pe] }, e[ru] = { textureFormat: Ce, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2], type: [wt] }, e[nu] = { textureFormat: Ce, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [de] }, e[iu] = { textureFormat: Ce, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [xt] }, e[qc] = { textureFormat: vt, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [2], type: [A] }, e[Xc] = { textureFormat: vt, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [2], type: [ne] }, e[Kc] = { textureFormat: vt, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [8, 4], type: [M, G] }, e[Jc] = { textureFormat: vt, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [8], type: [M] }, e[Zc] = { textureFormat: Fe, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2], type: [A] }, e[eu] = { textureFormat: Fe, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2], type: [ne] }, e[Hc] = { textureFormat: Fe, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [Pe] }, e[jc] = { textureFormat: Fe, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [wt] }, e[Yc] = { textureFormat: Fe, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [8], type: [de] }, e[Qc] = { textureFormat: Fe, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [8], type: [xt] }, e[ou] = { textureFormat: j, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [3], type: [A] }, e[su] = { textureFormat: j, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [3], type: [A] }, e[au] = { textureFormat: j, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [3, 2], type: [A, Xn] }, e[cu] = { textureFormat: j, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [3], type: [ne] }, e[uu] = { textureFormat: j, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [12, 6, 4], type: [M, G, zu] }, e[lu] = { textureFormat: j, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [12, 6, 4], type: [M, G, Nu] }, e[fu] = { textureFormat: j, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [12, 6], type: [M, G] }, e[du] = { textureFormat: j, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [12], type: [M] }, e[hu] = { textureFormat: Oe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [3], type: [A] }, e[mu] = { textureFormat: Oe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [3], type: [ne] }, e[pu] = { textureFormat: Oe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [6], type: [Pe] }, e[gu] = { textureFormat: Oe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [6], type: [wt] }, e[yu] = { textureFormat: Oe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [12], type: [de] }, e[bu] = { textureFormat: Oe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [12], type: [xt] }, e[wu] = { textureFormat: T, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4], type: [A] }, e[xu] = { textureFormat: T, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4], type: [A] }, e[vu] = { textureFormat: T, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [4], type: [ne] }, e[_u] = { textureFormat: T, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4, 2, 4], type: [A, qn, xr] }, e[Eu] = { textureFormat: T, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4, 2], type: [A, Qn] }, e[Au] = { textureFormat: T, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4], type: [xr] }, e[Tu] = { textureFormat: T, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [16, 8], type: [M, G] }, e[Su] = { textureFormat: T, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [16], type: [M] }, e[Iu] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [A] }, e[Ru] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [ne] }, e[ku] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [xr] }, e[Pu] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [8], type: [Pe] }, e[Fu] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [8], type: [wt] }, e[Cu] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [16], type: [xt] }, e[Ou] = { textureFormat: he, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [16], type: [de] }, e[Mu] = { textureFormat: Ve, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2, 4], type: [Pe, de] }, e[Bu] = { textureFormat: Ve, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [de] }, e[Du] = { textureFormat: Ve, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [M] }, e[Lu] = { textureFormat: jn, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [Wu] }, e[Uu] = { textureFormat: jn, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [$u] }, Object.keys(e).forEach(function(t) {
2529
2533
  const n = e[t];
2530
2534
  n.bytesPerElementMap = {}, n.bytesPerElement.forEach(function(i, o) {
2531
2535
  const s = n.type[o];
@@ -2535,7 +2539,7 @@ function er(r) {
2535
2539
  }
2536
2540
  return vr[r];
2537
2541
  }
2538
- function Wu(r, e) {
2542
+ function Gu(r, e) {
2539
2543
  const t = er(r);
2540
2544
  if (!t)
2541
2545
  throw "unknown internal format";
@@ -2556,7 +2560,7 @@ function nt(r) {
2556
2560
  function Kn(r) {
2557
2561
  return (r & r - 1) === 0;
2558
2562
  }
2559
- function Gu(r, e, t, n) {
2563
+ function Vu(r, e, t, n) {
2560
2564
  if (!rt(r))
2561
2565
  return Kn(e) && Kn(t);
2562
2566
  const i = er(n);
@@ -2564,13 +2568,13 @@ function Gu(r, e, t, n) {
2564
2568
  throw "unknown internal format";
2565
2569
  return i.colorRenderable && i.textureFilterable;
2566
2570
  }
2567
- function Vu(r) {
2571
+ function Hu(r) {
2568
2572
  const e = er(r);
2569
2573
  if (!e)
2570
2574
  throw "unknown internal format";
2571
2575
  return e.textureFilterable;
2572
2576
  }
2573
- function Hu(r, e, t) {
2577
+ function ju(r, e, t) {
2574
2578
  return Ke(e) ? qr(e) : t || A;
2575
2579
  }
2576
2580
  function Et(r, e, t, n, i) {
@@ -2590,28 +2594,28 @@ function Et(r, e, t, n, i) {
2590
2594
  };
2591
2595
  }
2592
2596
  function Ne(r, e) {
2593
- e.colorspaceConversion !== void 0 && r.pixelStorei(Bc, e.colorspaceConversion), e.premultiplyAlpha !== void 0 && r.pixelStorei(Dc, e.premultiplyAlpha), e.flipY !== void 0 && r.pixelStorei(Uc, e.flipY);
2597
+ e.colorspaceConversion !== void 0 && r.pixelStorei(Dc, e.colorspaceConversion), e.premultiplyAlpha !== void 0 && r.pixelStorei(Uc, e.premultiplyAlpha), e.flipY !== void 0 && r.pixelStorei(Lc, e.flipY);
2594
2598
  }
2595
2599
  function Ci(r) {
2596
2600
  r.pixelStorei(Zr, 4), rt(r) && (r.pixelStorei(Ii, 0), r.pixelStorei(Ri, 0), r.pixelStorei(ki, 0), r.pixelStorei(Pi, 0), r.pixelStorei(Fi, 0));
2597
2601
  }
2598
- function ju(r, e, t, n) {
2599
- n.minMag && (t.call(r, e, Sr, n.minMag), t.call(r, e, Ir, n.minMag)), n.min && t.call(r, e, Sr, n.min), n.mag && t.call(r, e, Ir, n.mag), n.wrap && (t.call(r, e, qt, n.wrap), t.call(r, e, Xt, n.wrap), (e === _e || Ja(r, e)) && t.call(r, e, Yn, n.wrap)), n.wrapR && t.call(r, e, Yn, n.wrapR), n.wrapS && t.call(r, e, qt, n.wrapS), n.wrapT && t.call(r, e, Xt, n.wrapT), n.minLod !== void 0 && t.call(r, e, kc, n.minLod), n.maxLod !== void 0 && t.call(r, e, Pc, n.maxLod), n.baseLevel !== void 0 && t.call(r, e, Fc, n.baseLevel), n.maxLevel !== void 0 && t.call(r, e, Cc, n.maxLevel), n.compareFunc !== void 0 && t.call(r, e, Mc, n.compareFunc), n.compareMode !== void 0 && t.call(r, e, Oc, n.compareMode);
2602
+ function Yu(r, e, t, n) {
2603
+ n.minMag && (t.call(r, e, Sr, n.minMag), t.call(r, e, Ir, n.minMag)), n.min && t.call(r, e, Sr, n.min), n.mag && t.call(r, e, Ir, n.mag), n.wrap && (t.call(r, e, qt, n.wrap), t.call(r, e, Xt, n.wrap), (e === _e || Za(r, e)) && t.call(r, e, Yn, n.wrap)), n.wrapR && t.call(r, e, Yn, n.wrapR), n.wrapS && t.call(r, e, qt, n.wrapS), n.wrapT && t.call(r, e, Xt, n.wrapT), n.minLod !== void 0 && t.call(r, e, Pc, n.minLod), n.maxLod !== void 0 && t.call(r, e, Fc, n.maxLod), n.baseLevel !== void 0 && t.call(r, e, Cc, n.baseLevel), n.maxLevel !== void 0 && t.call(r, e, Oc, n.maxLevel), n.compareFunc !== void 0 && t.call(r, e, Bc, n.compareFunc), n.compareMode !== void 0 && t.call(r, e, Mc, n.compareMode);
2600
2604
  }
2601
2605
  function Oi(r, e, t) {
2602
2606
  const n = t.target || ce;
2603
- r.bindTexture(n, e), ju(r, n, r.texParameteri, t);
2607
+ r.bindTexture(n, e), Yu(r, n, r.texParameteri, t);
2604
2608
  }
2605
- function Yu(r) {
2609
+ function Qu(r) {
2606
2610
  return r = r || ae.textureColor, Ke(r) ? r : new Uint8Array([r[0] * 255, r[1] * 255, r[2] * 255, r[3] * 255]);
2607
2611
  }
2608
2612
  function Rr(r, e, t, n, i, o) {
2609
2613
  t = t || ae.textureOptions, o = o || T;
2610
2614
  const s = t.target || ce;
2611
- if (n = n || t.width, i = i || t.height, r.bindTexture(s, e), Gu(r, n, i, o))
2615
+ if (n = n || t.width, i = i || t.height, r.bindTexture(s, e), Vu(r, n, i, o))
2612
2616
  r.generateMipmap(s);
2613
2617
  else {
2614
- const a = Vu(o) ? Ec : _c;
2618
+ const a = Hu(o) ? Ac : Ec;
2615
2619
  r.texParameteri(s, Sr, a), r.texParameteri(s, Ir, a), r.texParameteri(s, qt, Qt), r.texParameteri(s, Xt, Qt);
2616
2620
  }
2617
2621
  }
@@ -2621,11 +2625,11 @@ function Je(r) {
2621
2625
  function kr(r, e) {
2622
2626
  return e = e || {}, e.cubeFaceOrder || [
2623
2627
  Jr,
2624
- Ac,
2625
2628
  Tc,
2626
2629
  Sc,
2627
2630
  Ic,
2628
- Rc
2631
+ Rc,
2632
+ kc
2629
2633
  ];
2630
2634
  }
2631
2635
  function Pr(r, e) {
@@ -2684,7 +2688,7 @@ function Mi(r, e, t, n) {
2684
2688
  }
2685
2689
  function it() {
2686
2690
  }
2687
- function Qu(r) {
2691
+ function qu(r) {
2688
2692
  if (typeof document < "u") {
2689
2693
  const e = document.createElement("a");
2690
2694
  return e.href = r, e.hostname === location.hostname && e.port === location.port && e.protocol === location.protocol;
@@ -2693,13 +2697,13 @@ function Qu(r) {
2693
2697
  return new URL(r, location.href).origin === e;
2694
2698
  }
2695
2699
  }
2696
- function qu(r, e) {
2697
- return e === void 0 && !Qu(r) ? "anonymous" : e;
2700
+ function Xu(r, e) {
2701
+ return e === void 0 && !qu(r) ? "anonymous" : e;
2698
2702
  }
2699
- function Xu(r, e, t) {
2703
+ function Ku(r, e, t) {
2700
2704
  t = t || it;
2701
2705
  let n;
2702
- if (e = e !== void 0 ? e : ae.crossOrigin, e = qu(r, e), typeof Image < "u") {
2706
+ if (e = e !== void 0 ? e : ae.crossOrigin, e = Xu(r, e), typeof Image < "u") {
2703
2707
  n = new Image(), e !== void 0 && (n.crossOrigin = e);
2704
2708
  const i = function() {
2705
2709
  n.removeEventListener("error", o), n.removeEventListener("load", s), n = null;
@@ -2738,25 +2742,25 @@ function Bi(r) {
2738
2742
  function en(r, e, t) {
2739
2743
  return Bi(r) ? (setTimeout(function() {
2740
2744
  t(null, r);
2741
- }), r) : Xu(r, e, t);
2745
+ }), r) : Ku(r, e, t);
2742
2746
  }
2743
2747
  function tn(r, e, t) {
2744
2748
  t = t || ae.textureOptions;
2745
2749
  const n = t.target || ce;
2746
2750
  if (r.bindTexture(n, e), t.color === !1)
2747
2751
  return;
2748
- const i = Yu(t.color);
2752
+ const i = Qu(t.color);
2749
2753
  if (n === se)
2750
2754
  for (let o = 0; o < 6; ++o)
2751
2755
  r.texImage2D(Jr + o, 0, T, 1, 1, 0, T, A, i);
2752
2756
  else n === _e || n === Ee ? r.texImage3D(n, 0, T, 1, 1, 1, 0, T, A, i) : r.texImage2D(n, 0, T, 1, 1, 0, T, A, i);
2753
2757
  }
2754
- function Ku(r, e, t, n) {
2758
+ function Ju(r, e, t, n) {
2755
2759
  return n = n || it, t = t || ae.textureOptions, tn(r, e, t), t = Object.assign({}, t), en(t.src, t.crossOrigin, function(o, s) {
2756
2760
  o ? n(o, e, s) : (Mi(r, e, s, t), n(null, e, s));
2757
2761
  });
2758
2762
  }
2759
- function Ju(r, e, t, n) {
2763
+ function Zu(r, e, t, n) {
2760
2764
  n = n || it;
2761
2765
  const i = t.src;
2762
2766
  if (i.length !== 6)
@@ -2779,7 +2783,7 @@ function Ju(r, e, t, n) {
2779
2783
  return en(x, t.crossOrigin, g(b[v]));
2780
2784
  });
2781
2785
  }
2782
- function Zu(r, e, t, n) {
2786
+ function el(r, e, t, n) {
2783
2787
  n = n || it;
2784
2788
  const i = t.src, o = t.internalFormat || t.format || T, s = nt(o), a = t.format || s.format, c = t.type || A, u = t.target || Ee;
2785
2789
  if (u !== _e && u !== Ee)
@@ -2814,19 +2818,19 @@ function Zu(r, e, t, n) {
2814
2818
  return en(k, t.crossOrigin, R(L));
2815
2819
  });
2816
2820
  }
2817
- function el(r, e, t, n) {
2821
+ function tl(r, e, t, n) {
2818
2822
  n = n || ae.textureOptions;
2819
2823
  const i = n.target || ce;
2820
2824
  r.bindTexture(i, e);
2821
2825
  let o = n.width, s = n.height, a = n.depth;
2822
- const c = n.level || 0, u = n.internalFormat || n.format || T, f = nt(u), m = n.format || f.format, p = n.type || Hu(r, t, f.type);
2826
+ const c = n.level || 0, u = n.internalFormat || n.format || T, f = nt(u), m = n.format || f.format, p = n.type || ju(r, t, f.type);
2823
2827
  if (Ke(t))
2824
2828
  t instanceof Uint8ClampedArray && (t = new Uint8Array(t.buffer));
2825
2829
  else {
2826
2830
  const x = yi(p);
2827
2831
  t = new x(t);
2828
2832
  }
2829
- const b = Wu(u, p), d = t.byteLength / b;
2833
+ const b = Gu(u, p), d = t.byteLength / b;
2830
2834
  if (d % 1)
2831
2835
  throw "length wrong size for format: " + Ti(r, m);
2832
2836
  let g;
@@ -2853,7 +2857,7 @@ function el(r, e, t, n) {
2853
2857
  type: p
2854
2858
  };
2855
2859
  }
2856
- function tl(r, e, t) {
2860
+ function rl(r, e, t) {
2857
2861
  const n = t.target || ce;
2858
2862
  r.bindTexture(n, e);
2859
2863
  const i = t.level || 0, o = t.internalFormat || t.format || T, s = nt(o), a = t.format || s.format, c = t.type || s.type;
@@ -2871,44 +2875,44 @@ function Di(r, e, t) {
2871
2875
  let c = e.src;
2872
2876
  if (c)
2873
2877
  if (typeof c == "function" && (c = c(r, e)), typeof c == "string")
2874
- Ku(r, n, e, t);
2878
+ Ju(r, n, e, t);
2875
2879
  else if (Ke(c) || Array.isArray(c) && (typeof c[0] == "number" || Array.isArray(c[0]) || Ke(c[0]))) {
2876
- const u = el(r, n, c, e);
2880
+ const u = tl(r, n, c, e);
2877
2881
  o = u.width, s = u.height;
2878
- } else Array.isArray(c) && (typeof c[0] == "string" || Bi(c[0])) ? i === se ? Ju(r, n, e, t) : Zu(r, n, e, t) : (Mi(r, n, c, e), o = c.width, s = c.height);
2882
+ } else Array.isArray(c) && (typeof c[0] == "string" || Bi(c[0])) ? i === se ? Zu(r, n, e, t) : el(r, n, e, t) : (Mi(r, n, c, e), o = c.width, s = c.height);
2879
2883
  else
2880
- tl(r, n, e);
2884
+ rl(r, n, e);
2881
2885
  return Je(e) && Rr(r, n, e, o, s, a), Oi(r, n, e), n;
2882
2886
  }
2883
2887
  const rn = bi;
2884
2888
  function Ui(r) {
2885
2889
  return typeof document < "u" && document.getElementById ? document.getElementById(r) : null;
2886
2890
  }
2887
- const Kt = 33984, tr = 34962, rl = 34963, nl = 35713, il = 35714, ol = 35632, sl = 35633, al = 35981, Li = 35718, cl = 35721, ul = 35971, ll = 35382, fl = 35396, dl = 35398, hl = 35392, ml = 35395, rr = 5126, zi = 35664, Ni = 35665, $i = 35666, nn = 5124, Wi = 35667, Gi = 35668, Vi = 35669, Hi = 35670, ji = 35671, Yi = 35672, Qi = 35673, qi = 35674, Xi = 35675, Ki = 35676, pl = 35678, gl = 35680, yl = 35679, bl = 35682, wl = 35685, xl = 35686, vl = 35687, _l = 35688, El = 35689, Al = 35690, Tl = 36289, Sl = 36292, Il = 36293, on = 5125, Ji = 36294, Zi = 36295, eo = 36296, Rl = 36298, kl = 36299, Pl = 36300, Fl = 36303, Cl = 36306, Ol = 36307, Ml = 36308, Bl = 36311, nr = 3553, ir = 34067, sn = 32879, or = 35866, w = {};
2891
+ const Kt = 33984, tr = 34962, nl = 34963, il = 35713, ol = 35714, sl = 35632, al = 35633, cl = 35981, Li = 35718, ul = 35721, ll = 35971, fl = 35382, dl = 35396, hl = 35398, ml = 35392, pl = 35395, rr = 5126, zi = 35664, Ni = 35665, $i = 35666, nn = 5124, Wi = 35667, Gi = 35668, Vi = 35669, Hi = 35670, ji = 35671, Yi = 35672, Qi = 35673, qi = 35674, Xi = 35675, Ki = 35676, gl = 35678, yl = 35680, bl = 35679, wl = 35682, xl = 35685, vl = 35686, _l = 35687, El = 35688, Al = 35689, Tl = 35690, Sl = 36289, Il = 36292, Rl = 36293, on = 5125, Ji = 36294, Zi = 36295, eo = 36296, kl = 36298, Pl = 36299, Fl = 36300, Cl = 36303, Ol = 36306, Ml = 36307, Bl = 36308, Dl = 36311, nr = 3553, ir = 34067, sn = 32879, or = 35866, w = {};
2888
2892
  function to(r, e) {
2889
2893
  return w[e].bindPoint;
2890
2894
  }
2891
- function Dl(r, e) {
2895
+ function Ul(r, e) {
2892
2896
  return function(t) {
2893
2897
  r.uniform1f(e, t);
2894
2898
  };
2895
2899
  }
2896
- function Ul(r, e) {
2900
+ function Ll(r, e) {
2897
2901
  return function(t) {
2898
2902
  r.uniform1fv(e, t);
2899
2903
  };
2900
2904
  }
2901
- function Ll(r, e) {
2905
+ function zl(r, e) {
2902
2906
  return function(t) {
2903
2907
  r.uniform2fv(e, t);
2904
2908
  };
2905
2909
  }
2906
- function zl(r, e) {
2910
+ function Nl(r, e) {
2907
2911
  return function(t) {
2908
2912
  r.uniform3fv(e, t);
2909
2913
  };
2910
2914
  }
2911
- function Nl(r, e) {
2915
+ function $l(r, e) {
2912
2916
  return function(t) {
2913
2917
  r.uniform4fv(e, t);
2914
2918
  };
@@ -2938,72 +2942,72 @@ function so(r, e) {
2938
2942
  r.uniform4iv(e, t);
2939
2943
  };
2940
2944
  }
2941
- function $l(r, e) {
2945
+ function Wl(r, e) {
2942
2946
  return function(t) {
2943
2947
  r.uniform1ui(e, t);
2944
2948
  };
2945
2949
  }
2946
- function Wl(r, e) {
2950
+ function Gl(r, e) {
2947
2951
  return function(t) {
2948
2952
  r.uniform1uiv(e, t);
2949
2953
  };
2950
2954
  }
2951
- function Gl(r, e) {
2955
+ function Vl(r, e) {
2952
2956
  return function(t) {
2953
2957
  r.uniform2uiv(e, t);
2954
2958
  };
2955
2959
  }
2956
- function Vl(r, e) {
2960
+ function Hl(r, e) {
2957
2961
  return function(t) {
2958
2962
  r.uniform3uiv(e, t);
2959
2963
  };
2960
2964
  }
2961
- function Hl(r, e) {
2965
+ function jl(r, e) {
2962
2966
  return function(t) {
2963
2967
  r.uniform4uiv(e, t);
2964
2968
  };
2965
2969
  }
2966
- function jl(r, e) {
2970
+ function Yl(r, e) {
2967
2971
  return function(t) {
2968
2972
  r.uniformMatrix2fv(e, !1, t);
2969
2973
  };
2970
2974
  }
2971
- function Yl(r, e) {
2975
+ function Ql(r, e) {
2972
2976
  return function(t) {
2973
2977
  r.uniformMatrix3fv(e, !1, t);
2974
2978
  };
2975
2979
  }
2976
- function Ql(r, e) {
2980
+ function ql(r, e) {
2977
2981
  return function(t) {
2978
2982
  r.uniformMatrix4fv(e, !1, t);
2979
2983
  };
2980
2984
  }
2981
- function ql(r, e) {
2985
+ function Xl(r, e) {
2982
2986
  return function(t) {
2983
2987
  r.uniformMatrix2x3fv(e, !1, t);
2984
2988
  };
2985
2989
  }
2986
- function Xl(r, e) {
2990
+ function Kl(r, e) {
2987
2991
  return function(t) {
2988
2992
  r.uniformMatrix3x2fv(e, !1, t);
2989
2993
  };
2990
2994
  }
2991
- function Kl(r, e) {
2995
+ function Jl(r, e) {
2992
2996
  return function(t) {
2993
2997
  r.uniformMatrix2x4fv(e, !1, t);
2994
2998
  };
2995
2999
  }
2996
- function Jl(r, e) {
3000
+ function Zl(r, e) {
2997
3001
  return function(t) {
2998
3002
  r.uniformMatrix4x2fv(e, !1, t);
2999
3003
  };
3000
3004
  }
3001
- function Zl(r, e) {
3005
+ function ef(r, e) {
3002
3006
  return function(t) {
3003
3007
  r.uniformMatrix3x4fv(e, !1, t);
3004
3008
  };
3005
3009
  }
3006
- function ef(r, e) {
3010
+ function tf(r, e) {
3007
3011
  return function(t) {
3008
3012
  r.uniformMatrix4x3fv(e, !1, t);
3009
3013
  };
@@ -3033,46 +3037,46 @@ function U(r, e, t, n, i) {
3033
3037
  });
3034
3038
  };
3035
3039
  }
3036
- w[rr] = { Type: Float32Array, size: 4, setter: Dl, arraySetter: Ul };
3037
- w[zi] = { Type: Float32Array, size: 8, setter: Ll, cols: 2 };
3038
- w[Ni] = { Type: Float32Array, size: 12, setter: zl, cols: 3 };
3039
- w[$i] = { Type: Float32Array, size: 16, setter: Nl, cols: 4 };
3040
+ w[rr] = { Type: Float32Array, size: 4, setter: Ul, arraySetter: Ll };
3041
+ w[zi] = { Type: Float32Array, size: 8, setter: zl, cols: 2 };
3042
+ w[Ni] = { Type: Float32Array, size: 12, setter: Nl, cols: 3 };
3043
+ w[$i] = { Type: Float32Array, size: 16, setter: $l, cols: 4 };
3040
3044
  w[nn] = { Type: Int32Array, size: 4, setter: ro, arraySetter: no };
3041
3045
  w[Wi] = { Type: Int32Array, size: 8, setter: io, cols: 2 };
3042
3046
  w[Gi] = { Type: Int32Array, size: 12, setter: oo, cols: 3 };
3043
3047
  w[Vi] = { Type: Int32Array, size: 16, setter: so, cols: 4 };
3044
- w[on] = { Type: Uint32Array, size: 4, setter: $l, arraySetter: Wl };
3045
- w[Ji] = { Type: Uint32Array, size: 8, setter: Gl, cols: 2 };
3046
- w[Zi] = { Type: Uint32Array, size: 12, setter: Vl, cols: 3 };
3047
- w[eo] = { Type: Uint32Array, size: 16, setter: Hl, cols: 4 };
3048
+ w[on] = { Type: Uint32Array, size: 4, setter: Wl, arraySetter: Gl };
3049
+ w[Ji] = { Type: Uint32Array, size: 8, setter: Vl, cols: 2 };
3050
+ w[Zi] = { Type: Uint32Array, size: 12, setter: Hl, cols: 3 };
3051
+ w[eo] = { Type: Uint32Array, size: 16, setter: jl, cols: 4 };
3048
3052
  w[Hi] = { Type: Uint32Array, size: 4, setter: ro, arraySetter: no };
3049
3053
  w[ji] = { Type: Uint32Array, size: 8, setter: io, cols: 2 };
3050
3054
  w[Yi] = { Type: Uint32Array, size: 12, setter: oo, cols: 3 };
3051
3055
  w[Qi] = { Type: Uint32Array, size: 16, setter: so, cols: 4 };
3052
- w[qi] = { Type: Float32Array, size: 32, setter: jl, rows: 2, cols: 2 };
3053
- w[Xi] = { Type: Float32Array, size: 48, setter: Yl, rows: 3, cols: 3 };
3054
- w[Ki] = { Type: Float32Array, size: 64, setter: Ql, rows: 4, cols: 4 };
3055
- w[wl] = { Type: Float32Array, size: 32, setter: ql, rows: 2, cols: 3 };
3056
- w[xl] = { Type: Float32Array, size: 32, setter: Kl, rows: 2, cols: 4 };
3057
- w[vl] = { Type: Float32Array, size: 48, setter: Xl, rows: 3, cols: 2 };
3058
- w[_l] = { Type: Float32Array, size: 48, setter: Zl, rows: 3, cols: 4 };
3059
- w[El] = { Type: Float32Array, size: 64, setter: Jl, rows: 4, cols: 2 };
3060
- w[Al] = { Type: Float32Array, size: 64, setter: ef, rows: 4, cols: 3 };
3061
- w[pl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: nr };
3062
- w[gl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: ir };
3063
- w[yl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: sn };
3064
- w[bl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: nr };
3065
- w[Tl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: or };
3056
+ w[qi] = { Type: Float32Array, size: 32, setter: Yl, rows: 2, cols: 2 };
3057
+ w[Xi] = { Type: Float32Array, size: 48, setter: Ql, rows: 3, cols: 3 };
3058
+ w[Ki] = { Type: Float32Array, size: 64, setter: ql, rows: 4, cols: 4 };
3059
+ w[xl] = { Type: Float32Array, size: 32, setter: Xl, rows: 2, cols: 3 };
3060
+ w[vl] = { Type: Float32Array, size: 32, setter: Jl, rows: 2, cols: 4 };
3061
+ w[_l] = { Type: Float32Array, size: 48, setter: Kl, rows: 3, cols: 2 };
3062
+ w[El] = { Type: Float32Array, size: 48, setter: ef, rows: 3, cols: 4 };
3063
+ w[Al] = { Type: Float32Array, size: 64, setter: Zl, rows: 4, cols: 2 };
3064
+ w[Tl] = { Type: Float32Array, size: 64, setter: tf, rows: 4, cols: 3 };
3065
+ w[gl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: nr };
3066
+ w[yl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: ir };
3067
+ w[bl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: sn };
3068
+ w[wl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: nr };
3066
3069
  w[Sl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: or };
3067
- w[Il] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: ir };
3068
- w[Rl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: nr };
3069
- w[kl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: sn };
3070
- w[Pl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: ir };
3071
- w[Fl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: or };
3072
- w[Cl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: nr };
3073
- w[Ol] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: sn };
3074
- w[Ml] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: ir };
3075
- w[Bl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: or };
3070
+ w[Il] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: or };
3071
+ w[Rl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: ir };
3072
+ w[kl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: nr };
3073
+ w[Pl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: sn };
3074
+ w[Fl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: ir };
3075
+ w[Cl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: or };
3076
+ w[Ol] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: nr };
3077
+ w[Ml] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: sn };
3078
+ w[Bl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: ir };
3079
+ w[Dl] = { Type: null, size: 0, setter: D, arraySetter: U, bindPoint: or };
3076
3080
  function sr(r, e) {
3077
3081
  return function(t) {
3078
3082
  if (t.value)
@@ -3173,9 +3177,9 @@ I[Qi] = { size: 16, setter: ue };
3173
3177
  I[qi] = { size: 4, setter: an, count: 2 };
3174
3178
  I[Xi] = { size: 9, setter: an, count: 3 };
3175
3179
  I[Ki] = { size: 16, setter: an, count: 4 };
3176
- const tf = /ERROR:\s*\d+:(\d+)/gi;
3177
- function rf(r, e = "", t = 0) {
3178
- const n = [...e.matchAll(tf)], i = new Map(n.map((o, s) => {
3180
+ const rf = /ERROR:\s*\d+:(\d+)/gi;
3181
+ function nf(r, e = "", t = 0) {
3182
+ const n = [...e.matchAll(rf)], i = new Map(n.map((o, s) => {
3179
3183
  const a = parseInt(o[1]), c = n[s + 1], u = c ? c.index : e.length, f = e.substring(o.index, u);
3180
3184
  return [a - 1, f];
3181
3185
  }));
@@ -3193,16 +3197,16 @@ function ao(r) {
3193
3197
  let e = 0;
3194
3198
  return Jn.test(r) && (e = 1, r = r.replace(Jn, "")), { lineOffset: e, shaderSource: r };
3195
3199
  }
3196
- function nf(r, e) {
3200
+ function of(r, e) {
3197
3201
  return r.errorCallback(e), r.callback && setTimeout(() => {
3198
3202
  r.callback(`${e}
3199
3203
  ${r.errors.join(`
3200
3204
  `)}`);
3201
3205
  }), null;
3202
3206
  }
3203
- function of(r, e, t, n) {
3204
- if (n = n || rn, !r.getShaderParameter(t, nl)) {
3205
- const o = r.getShaderInfoLog(t), { lineOffset: s, shaderSource: a } = ao(r.getShaderSource(t)), c = `${rf(a, o, s)}
3207
+ function sf(r, e, t, n) {
3208
+ if (n = n || rn, !r.getShaderParameter(t, il)) {
3209
+ const o = r.getShaderInfoLog(t), { lineOffset: s, shaderSource: a } = ao(r.getShaderSource(t)), c = `${nf(a, o, s)}
3206
3210
  Error compiling ${Ti(r, e)}: ${o}`;
3207
3211
  return n(c), c;
3208
3212
  }
@@ -3233,24 +3237,24 @@ function cn(r, e, t) {
3233
3237
  }
3234
3238
  return c;
3235
3239
  }
3236
- const sf = [
3240
+ const af = [
3237
3241
  "VERTEX_SHADER",
3238
3242
  "FRAGMENT_SHADER"
3239
3243
  ];
3240
- function af(r, e) {
3244
+ function cf(r, e) {
3241
3245
  if (e.indexOf("frag") >= 0)
3242
- return ol;
3243
- if (e.indexOf("vert") >= 0)
3244
3246
  return sl;
3247
+ if (e.indexOf("vert") >= 0)
3248
+ return al;
3245
3249
  }
3246
- function cf(r, e, t) {
3250
+ function uf(r, e, t) {
3247
3251
  const n = r.getAttachedShaders(e);
3248
3252
  for (const i of n)
3249
3253
  t.has(i) && r.deleteShader(i);
3250
3254
  r.deleteProgram(e);
3251
3255
  }
3252
- const uf = (r = 0) => new Promise((e) => setTimeout(e, r));
3253
- function lf(r, e, t) {
3256
+ const lf = (r = 0) => new Promise((e) => setTimeout(e, r));
3257
+ function ff(r, e, t) {
3254
3258
  const n = r.createProgram(), {
3255
3259
  attribLocations: i,
3256
3260
  transformFeedbackVaryings: o,
@@ -3260,25 +3264,25 @@ function lf(r, e, t) {
3260
3264
  let c = e[a];
3261
3265
  if (typeof c == "string") {
3262
3266
  const u = Ui(c), f = u ? u.text : c;
3263
- let m = r[sf[a]];
3264
- u && u.type && (m = af(r, u.type) || m), c = r.createShader(m), r.shaderSource(c, ao(f).shaderSource), r.compileShader(c), r.attachShader(n, c);
3267
+ let m = r[af[a]];
3268
+ u && u.type && (m = cf(r, u.type) || m), c = r.createShader(m), r.shaderSource(c, ao(f).shaderSource), r.compileShader(c), r.attachShader(n, c);
3265
3269
  }
3266
3270
  }
3267
3271
  Object.entries(i).forEach(([a, c]) => r.bindAttribLocation(n, c, a));
3268
3272
  {
3269
3273
  let a = o;
3270
- a && (a.attribs && (a = a.attribs), Array.isArray(a) || (a = Object.keys(a)), r.transformFeedbackVaryings(n, a, s || al));
3274
+ a && (a.attribs && (a = a.attribs), Array.isArray(a) || (a = Object.keys(a)), r.transformFeedbackVaryings(n, a, s || cl));
3271
3275
  }
3272
3276
  return r.linkProgram(n), n;
3273
3277
  }
3274
- function ff(r, e, t, n, i) {
3275
- const o = cn(t, n, i), s = new Set(e), a = lf(r, e, o);
3278
+ function df(r, e, t, n, i) {
3279
+ const o = cn(t, n, i), s = new Set(e), a = ff(r, e, o);
3276
3280
  function c(u, f) {
3277
- const m = hf(u, f, o.errorCallback);
3278
- return m && cf(u, f, s), m;
3281
+ const m = mf(u, f, o.errorCallback);
3282
+ return m && uf(u, f, s), m;
3279
3283
  }
3280
3284
  if (o.callback) {
3281
- df(r, a).then(() => {
3285
+ hf(r, a).then(() => {
3282
3286
  const u = c(r, a);
3283
3287
  o.callback(u, u ? void 0 : a);
3284
3288
  });
@@ -3286,38 +3290,38 @@ function ff(r, e, t, n, i) {
3286
3290
  }
3287
3291
  return c(r, a) ? void 0 : a;
3288
3292
  }
3289
- async function df(r, e) {
3293
+ async function hf(r, e) {
3290
3294
  const t = r.getExtension("KHR_parallel_shader_compile"), n = t ? (o, s) => o.getProgramParameter(s, t.COMPLETION_STATUS_KHR) : () => !0;
3291
3295
  let i = 0;
3292
3296
  do
3293
- await uf(i), i = 1e3 / 60;
3297
+ await lf(i), i = 1e3 / 60;
3294
3298
  while (!n(r, e));
3295
3299
  }
3296
- function hf(r, e, t) {
3297
- if (t = t || rn, !r.getProgramParameter(e, il)) {
3300
+ function mf(r, e, t) {
3301
+ if (t = t || rn, !r.getProgramParameter(e, ol)) {
3298
3302
  const i = r.getProgramInfoLog(e);
3299
3303
  t(`Error in program linking: ${i}`);
3300
- const s = r.getAttachedShaders(e).map((a) => of(r, r.getShaderParameter(a, r.SHADER_TYPE), a, t));
3304
+ const s = r.getAttachedShaders(e).map((a) => sf(r, r.getShaderParameter(a, r.SHADER_TYPE), a, t));
3301
3305
  return `${i}
3302
3306
  ${s.filter((a) => a).join(`
3303
3307
  `)}`;
3304
3308
  }
3305
3309
  }
3306
- function mf(r, e, t, n, i) {
3307
- return ff(r, e, t, n, i);
3310
+ function pf(r, e, t, n, i) {
3311
+ return df(r, e, t, n, i);
3308
3312
  }
3309
3313
  function co(r) {
3310
3314
  const e = r.name;
3311
3315
  return e.startsWith("gl_") || e.startsWith("webgl_");
3312
3316
  }
3313
- const pf = /(\.|\[|]|\w+)/g, gf = (r) => r >= "0" && r <= "9";
3314
- function yf(r, e, t, n) {
3315
- const i = r.split(pf).filter((a) => a !== "");
3317
+ const gf = /(\.|\[|]|\w+)/g, yf = (r) => r >= "0" && r <= "9";
3318
+ function bf(r, e, t, n) {
3319
+ const i = r.split(gf).filter((a) => a !== "");
3316
3320
  let o = 0, s = "";
3317
3321
  for (; ; ) {
3318
3322
  const a = i[o++];
3319
3323
  s += a;
3320
- const c = gf(a[0]), u = c ? parseInt(a) : a;
3324
+ const c = yf(a[0]), u = c ? parseInt(a) : a;
3321
3325
  if (c && (s += i[o++]), o === i.length) {
3322
3326
  t[u] = e;
3323
3327
  break;
@@ -3331,7 +3335,7 @@ function yf(r, e, t, n) {
3331
3335
  }
3332
3336
  }
3333
3337
  }
3334
- function bf(r, e) {
3338
+ function wf(r, e) {
3335
3339
  let t = 0;
3336
3340
  function n(a, c, u) {
3337
3341
  const f = c.name.endsWith("[0]"), m = c.type, p = w[m];
@@ -3355,13 +3359,13 @@ function bf(r, e) {
3355
3359
  const f = r.getUniformLocation(e, c.name);
3356
3360
  if (f) {
3357
3361
  const m = n(e, c, f);
3358
- i[u] = m, yf(u, m, o, i);
3362
+ i[u] = m, bf(u, m, o, i);
3359
3363
  }
3360
3364
  }
3361
3365
  return i;
3362
3366
  }
3363
- function wf(r, e) {
3364
- const t = {}, n = r.getProgramParameter(e, ul);
3367
+ function xf(r, e) {
3368
+ const t = {}, n = r.getProgramParameter(e, ll);
3365
3369
  for (let i = 0; i < n; ++i) {
3366
3370
  const o = r.getTransformFeedbackVarying(e, i);
3367
3371
  t[o.name] = {
@@ -3372,7 +3376,7 @@ function wf(r, e) {
3372
3376
  }
3373
3377
  return t;
3374
3378
  }
3375
- function xf(r, e) {
3379
+ function vf(r, e) {
3376
3380
  const t = r.getProgramParameter(e, Li), n = [], i = [];
3377
3381
  for (let a = 0; a < t; ++a) {
3378
3382
  i.push(a), n.push({});
@@ -3391,14 +3395,14 @@ function xf(r, e) {
3391
3395
  n[m][u] = f;
3392
3396
  });
3393
3397
  });
3394
- const o = {}, s = r.getProgramParameter(e, ll);
3398
+ const o = {}, s = r.getProgramParameter(e, fl);
3395
3399
  for (let a = 0; a < s; ++a) {
3396
3400
  const c = r.getActiveUniformBlockName(e, a), u = {
3397
3401
  index: r.getUniformBlockIndex(e, c),
3398
- usedByVertexShader: r.getActiveUniformBlockParameter(e, a, fl),
3399
- usedByFragmentShader: r.getActiveUniformBlockParameter(e, a, dl),
3400
- size: r.getActiveUniformBlockParameter(e, a, hl),
3401
- uniformIndices: r.getActiveUniformBlockParameter(e, a, ml)
3402
+ usedByVertexShader: r.getActiveUniformBlockParameter(e, a, dl),
3403
+ usedByFragmentShader: r.getActiveUniformBlockParameter(e, a, hl),
3404
+ size: r.getActiveUniformBlockParameter(e, a, ml),
3405
+ uniformIndices: r.getActiveUniformBlockParameter(e, a, pl)
3402
3406
  };
3403
3407
  u.used = u.usedByVertexShader || u.usedByFragmentShader, o[c] = u;
3404
3408
  }
@@ -3428,8 +3432,8 @@ function lo(r, ...e) {
3428
3432
  }
3429
3433
  }
3430
3434
  }
3431
- function vf(r, e) {
3432
- const t = {}, n = r.getProgramParameter(e, cl);
3435
+ function _f(r, e) {
3436
+ const t = {}, n = r.getProgramParameter(e, ul);
3433
3437
  for (let i = 0; i < n; ++i) {
3434
3438
  const o = r.getActiveAttrib(e, i);
3435
3439
  if (co(o))
@@ -3439,28 +3443,28 @@ function vf(r, e) {
3439
3443
  }
3440
3444
  return t;
3441
3445
  }
3442
- function _f(r, e) {
3446
+ function Ef(r, e) {
3443
3447
  for (const t in e) {
3444
3448
  const n = r[t];
3445
3449
  n && n(e[t]);
3446
3450
  }
3447
3451
  }
3448
- function Ef(r, e, t) {
3449
- t.vertexArrayObject ? r.bindVertexArray(t.vertexArrayObject) : (_f(e.attribSetters || e, t.attribs), t.indices && r.bindBuffer(rl, t.indices));
3452
+ function Af(r, e, t) {
3453
+ t.vertexArrayObject ? r.bindVertexArray(t.vertexArrayObject) : (Ef(e.attribSetters || e, t.attribs), t.indices && r.bindBuffer(nl, t.indices));
3450
3454
  }
3451
3455
  function Zn(r, e) {
3452
- const t = bf(r, e), n = vf(r, e), i = {
3456
+ const t = wf(r, e), n = _f(r, e), i = {
3453
3457
  program: e,
3454
3458
  uniformSetters: t,
3455
3459
  attribSetters: n
3456
3460
  };
3457
- return rt(r) && (i.uniformBlockSpec = xf(r, e), i.transformFeedbackInfo = wf(r, e)), i;
3461
+ return rt(r) && (i.uniformBlockSpec = vf(r, e), i.transformFeedbackInfo = xf(r, e)), i;
3458
3462
  }
3459
- const Af = /\s|{|}|;/;
3460
- function Tf(r, e, t, n, i) {
3463
+ const Tf = /\s|{|}|;/;
3464
+ function Sf(r, e, t, n, i) {
3461
3465
  const o = cn(t, n, i), s = [];
3462
3466
  if (e = e.map(function(u) {
3463
- if (!Af.test(u)) {
3467
+ if (!Tf.test(u)) {
3464
3468
  const f = Ui(u);
3465
3469
  if (f)
3466
3470
  u = f.text;
@@ -3471,54 +3475,54 @@ function Tf(r, e, t, n, i) {
3471
3475
  }
3472
3476
  return u;
3473
3477
  }), s.length)
3474
- return nf(o, "");
3478
+ return of(o, "");
3475
3479
  const a = o.callback;
3476
3480
  a && (o.callback = (u, f) => {
3477
3481
  a(u, u ? void 0 : Zn(r, f));
3478
3482
  });
3479
- const c = mf(r, e, o);
3483
+ const c = pf(r, e, o);
3480
3484
  return c ? Zn(r, c) : null;
3481
3485
  }
3482
- const Sf = 4, ei = 5123;
3483
- function If(r, e, t, n, i, o) {
3484
- t = t === void 0 ? Sf : t;
3486
+ const If = 4, ei = 5123;
3487
+ function Rf(r, e, t, n, i, o) {
3488
+ t = t === void 0 ? If : t;
3485
3489
  const s = e.indices, a = e.elementType, c = n === void 0 ? e.numElements : n;
3486
3490
  i = i === void 0 ? 0 : i, a || s ? o !== void 0 ? r.drawElementsInstanced(t, c, a === void 0 ? ei : e.elementType, i, o) : r.drawElements(t, c, a === void 0 ? ei : e.elementType, i) : o !== void 0 ? r.drawArraysInstanced(t, i, c, o) : r.drawArrays(t, i, c);
3487
3491
  }
3488
- const fo = 36160, At = 36161, Rf = 3553, kf = 5121, Pf = 6402, Ff = 6408, Cf = 33190, Of = 36012, Mf = 35056, Bf = 36013, Df = 32854, Uf = 32855, Lf = 36194, ho = 33189, mo = 6401, po = 36168, un = 34041, Fr = 36064, cr = 36096, go = 36128, ln = 33306, Cr = 33071, Or = 9729, zf = [
3489
- { format: Ff, type: kf, min: Or, wrap: Cr },
3492
+ const fo = 36160, At = 36161, kf = 3553, Pf = 5121, Ff = 6402, Cf = 6408, Of = 33190, Mf = 36012, Bf = 35056, Df = 36013, Uf = 32854, Lf = 32855, zf = 36194, ho = 33189, mo = 6401, po = 36168, un = 34041, Fr = 36064, cr = 36096, go = 36128, ln = 33306, Cr = 33071, Or = 9729, Nf = [
3493
+ { format: Cf, type: Pf, min: Or, wrap: Cr },
3490
3494
  { format: un }
3491
3495
  ], V = {};
3492
3496
  V[un] = ln;
3493
3497
  V[mo] = go;
3494
3498
  V[po] = go;
3495
- V[Pf] = cr;
3499
+ V[Ff] = cr;
3496
3500
  V[ho] = cr;
3497
- V[Cf] = cr;
3498
3501
  V[Of] = cr;
3499
- V[Mf] = ln;
3502
+ V[Mf] = cr;
3500
3503
  V[Bf] = ln;
3501
- function Nf(r, e) {
3504
+ V[Df] = ln;
3505
+ function $f(r, e) {
3502
3506
  return V[r] || V[e];
3503
3507
  }
3504
3508
  const le = {};
3505
- le[Df] = !0;
3506
3509
  le[Uf] = !0;
3507
3510
  le[Lf] = !0;
3511
+ le[zf] = !0;
3508
3512
  le[un] = !0;
3509
3513
  le[ho] = !0;
3510
3514
  le[mo] = !0;
3511
3515
  le[po] = !0;
3512
- function $f(r) {
3516
+ function Wf(r) {
3513
3517
  return le[r];
3514
3518
  }
3515
- const Wf = 32;
3516
- function Gf(r) {
3517
- return r >= Fr && r < Fr + Wf;
3519
+ const Gf = 32;
3520
+ function Vf(r) {
3521
+ return r >= Fr && r < Fr + Gf;
3518
3522
  }
3519
3523
  function ti(r, e, t, n) {
3520
3524
  const i = fo, o = r.createFramebuffer();
3521
- r.bindFramebuffer(i, o), t = t || r.drawingBufferWidth, n = n || r.drawingBufferHeight, e = e || zf;
3525
+ r.bindFramebuffer(i, o), t = t || r.drawingBufferWidth, n = n || r.drawingBufferHeight, e = e || Nf;
3522
3526
  const s = [], a = {
3523
3527
  framebuffer: o,
3524
3528
  attachments: [],
@@ -3528,15 +3532,15 @@ function ti(r, e, t, n) {
3528
3532
  return e.forEach(function(c, u) {
3529
3533
  let f = c.attachment;
3530
3534
  const m = c.samples, p = c.format;
3531
- let b = c.attachmentPoint || Nf(p, c.internalFormat);
3532
- if (b || (b = Fr + u), Gf(b) && s.push(b), !f)
3533
- if (m !== void 0 || $f(p))
3535
+ let b = c.attachmentPoint || $f(p, c.internalFormat);
3536
+ if (b || (b = Fr + u), Vf(b) && s.push(b), !f)
3537
+ if (m !== void 0 || Wf(p))
3534
3538
  f = r.createRenderbuffer(), r.bindRenderbuffer(At, f), m > 1 ? r.renderbufferStorageMultisample(At, m, p, t, n) : r.renderbufferStorage(At, p, t, n);
3535
3539
  else {
3536
3540
  const d = Object.assign({}, c);
3537
3541
  d.width = t, d.height = n, d.auto === void 0 && (d.auto = !1, d.min = d.min || d.minMag || Or, d.mag = d.mag || d.minMag || Or, d.wrapS = d.wrapS || d.wrap || Cr, d.wrapT = d.wrapT || d.wrap || Cr), f = Di(r, d);
3538
3542
  }
3539
- if (Ka(r, f))
3543
+ if (Ja(r, f))
3540
3544
  r.framebufferRenderbuffer(i, b, At, f);
3541
3545
  else if (Xr(r, f))
3542
3546
  c.layer !== void 0 ? r.framebufferTextureLayer(
@@ -3548,7 +3552,7 @@ function ti(r, e, t, n) {
3548
3552
  ) : r.framebufferTexture2D(
3549
3553
  i,
3550
3554
  b,
3551
- c.target || Rf,
3555
+ c.target || kf,
3552
3556
  f,
3553
3557
  c.level || 0
3554
3558
  );
@@ -3557,7 +3561,7 @@ function ti(r, e, t, n) {
3557
3561
  a.attachments.push(f);
3558
3562
  }), r.drawBuffers && r.drawBuffers(s), a;
3559
3563
  }
3560
- function Vf(r, e, t) {
3564
+ function Hf(r, e, t) {
3561
3565
  t = t || fo, e ? (r.bindFramebuffer(t, e.framebuffer), r.viewport(0, 0, e.width, e.height)) : (r.bindFramebuffer(t, null), r.viewport(0, 0, r.drawingBufferWidth, r.drawingBufferHeight));
3562
3566
  }
3563
3567
  function B(r, e) {
@@ -3573,10 +3577,10 @@ class ot {
3573
3577
  const { context: t, width: n, height: i } = e;
3574
3578
  this.context = t, this.options = e;
3575
3579
  const o = this.buildDefines();
3576
- this.programInfo = Tf(this.context, [
3580
+ this.programInfo = Sf(this.context, [
3577
3581
  o + this.getVertexShader(),
3578
3582
  o + this.getFragmentShader()
3579
- ]), this.bufferInfo = vc(
3583
+ ]), this.bufferInfo = _c(
3580
3584
  this.context,
3581
3585
  this.getBuffers()
3582
3586
  ), this.fbi = ti(
@@ -3662,7 +3666,7 @@ class ot {
3662
3666
  0,
3663
3667
  this.context.canvas.width,
3664
3668
  this.context.canvas.height
3665
- ), this.context.useProgram(this.programInfo.program), Ef(
3669
+ ), this.context.useProgram(this.programInfo.program), Af(
3666
3670
  this.context,
3667
3671
  this.programInfo,
3668
3672
  this.bufferInfo
@@ -3670,10 +3674,10 @@ class ot {
3670
3674
  delta: n,
3671
3675
  canvas: [this.context.canvas.width, this.context.canvas.height],
3672
3676
  ...e
3673
- }), Vf(
3677
+ }), Hf(
3674
3678
  this.context,
3675
3679
  this.options.disableFramebuffer ? null : this.fbi
3676
- ), If(this.context, this.bufferInfo), this.profiler?.popContext(
3680
+ ), Rf(this.context, this.bufferInfo), this.profiler?.popContext(
3677
3681
  `[${this.id}] PROG : ${this.constructor.name}`
3678
3682
  );
3679
3683
  }
@@ -3681,7 +3685,7 @@ class ot {
3681
3685
  this.profiler = e;
3682
3686
  }
3683
3687
  }
3684
- const Hf = `precision mediump float;
3688
+ const jf = `precision mediump float;
3685
3689
 
3686
3690
  varying vec2 _texture_coord;
3687
3691
 
@@ -3696,7 +3700,7 @@ void main() {
3696
3700
  gl_FragColor = foregroundColor * tresholdColor.a +
3697
3701
  backgroundColor * (1. - tresholdColor.a);
3698
3702
  }
3699
- `, jf = `varying vec2 _texture_coord;
3703
+ `, Yf = `varying vec2 _texture_coord;
3700
3704
 
3701
3705
  attribute vec2 position;
3702
3706
  attribute vec2 texture_coord;
@@ -3709,10 +3713,10 @@ void main() {
3709
3713
  `;
3710
3714
  class fn extends ot {
3711
3715
  getFragmentShader() {
3712
- return Hf;
3716
+ return jf;
3713
3717
  }
3714
3718
  getVertexShader() {
3715
- return jf;
3719
+ return Yf;
3716
3720
  }
3717
3721
  }
3718
3722
  class dn {
@@ -3775,13 +3779,13 @@ class yo extends hn {
3775
3779
  this.inputImage = e, this.inputMask = t;
3776
3780
  }
3777
3781
  }
3778
- const Yf = `precision mediump float;
3782
+ const Qf = `precision mediump float;
3779
3783
 
3780
3784
  varying vec2 _texture_coord;
3781
3785
  uniform sampler2D texture;
3782
3786
 
3783
3787
  void main() { gl_FragColor = texture2D(texture, _texture_coord); }
3784
- `, Qf = `varying vec2 _texture_coord;
3788
+ `, qf = `varying vec2 _texture_coord;
3785
3789
 
3786
3790
  attribute vec2 position;
3787
3791
  attribute vec2 texture_coord;
@@ -3795,15 +3799,15 @@ void main() {
3795
3799
  }
3796
3800
  }
3797
3801
  `;
3798
- class qf extends ot {
3802
+ class Xf extends ot {
3799
3803
  getFragmentShader() {
3800
- return Yf;
3804
+ return Qf;
3801
3805
  }
3802
3806
  getVertexShader() {
3803
- return Qf;
3807
+ return qf;
3804
3808
  }
3805
3809
  }
3806
- class Xf extends dn {
3810
+ class Kf extends dn {
3807
3811
  constructor(e, t, n) {
3808
3812
  super(), this.context = e;
3809
3813
  const i = {
@@ -3812,7 +3816,7 @@ class Xf extends dn {
3812
3816
  width: t
3813
3817
  };
3814
3818
  this.addStep({
3815
- program: new qf({
3819
+ program: new Xf({
3816
3820
  ...i,
3817
3821
  disableFramebuffer: !0
3818
3822
  }),
@@ -3833,7 +3837,7 @@ async function bo(r) {
3833
3837
  }, r);
3834
3838
  });
3835
3839
  }
3836
- const Kf = `precision mediump float;
3840
+ const Jf = `precision mediump float;
3837
3841
 
3838
3842
  varying vec2 _texture_coord;
3839
3843
 
@@ -3843,7 +3847,7 @@ uniform sampler2D texture;
3843
3847
  vec4 loop();
3844
3848
 
3845
3849
  void main() { gl_FragColor = loop(); }
3846
- `, Jf = `varying vec2 _texture_coord;
3850
+ `, Zf = `varying vec2 _texture_coord;
3847
3851
 
3848
3852
  attribute vec2 position;
3849
3853
  attribute vec2 texture_coord;
@@ -3859,10 +3863,10 @@ class wo extends ot {
3859
3863
  return { RADIUS: this.options.radius ?? 1 };
3860
3864
  }
3861
3865
  getFragmentShader() {
3862
- return Kf + this.createLoopFunction();
3866
+ return Jf + this.createLoopFunction();
3863
3867
  }
3864
3868
  getVertexShader() {
3865
- return Jf;
3869
+ return Zf;
3866
3870
  }
3867
3871
  createLoopFunction() {
3868
3872
  let e = this.options.radius ?? 1;
@@ -3890,7 +3894,7 @@ class wo extends ot {
3890
3894
  }`;
3891
3895
  }
3892
3896
  }
3893
- const Zf = `#version 300 es
3897
+ const ed = `#version 300 es
3894
3898
  // https://github.com/Volcomix/virtual-background/blob/main/src/pipelines/webgl2/jointBilateralFilterStage.ts
3895
3899
 
3896
3900
  precision highp float;
@@ -3936,7 +3940,7 @@ void main() {
3936
3940
  }
3937
3941
  newVal /= totalWeight;
3938
3942
  outColor = vec4(vec3(0.), newVal);
3939
- }`, ed = `#version 300 es
3943
+ }`, td = `#version 300 es
3940
3944
  in vec2 position;
3941
3945
  in vec2 texture_coord;
3942
3946
  out vec2 _texture_coord;
@@ -3944,15 +3948,15 @@ void main() {
3944
3948
  gl_Position = vec4(position, 0.0, 1.0);
3945
3949
  _texture_coord = texture_coord;
3946
3950
  }`;
3947
- class td extends ot {
3951
+ class rd extends ot {
3948
3952
  getFragmentShader() {
3949
- return Zf;
3953
+ return ed;
3950
3954
  }
3951
3955
  getVertexShader() {
3952
- return ed;
3956
+ return td;
3953
3957
  }
3954
3958
  }
3955
- class rd extends dn {
3959
+ class nd extends dn {
3956
3960
  constructor(e, t, n) {
3957
3961
  super(), this.context = e;
3958
3962
  const i = {
@@ -3964,7 +3968,7 @@ class rd extends dn {
3964
3968
  radius: 1,
3965
3969
  type: mn.GAUSSIAN
3966
3970
  });
3967
- this.jointBilateral = new td(i), this.addStep({
3971
+ this.jointBilateral = new rd(i), this.addStep({
3968
3972
  program: o,
3969
3973
  getUniforms: () => ({
3970
3974
  inputs: B(e, this.inputMask)
@@ -4000,7 +4004,7 @@ class rd extends dn {
4000
4004
  }
4001
4005
  }
4002
4006
  var xo = /* @__PURE__ */ ((r) => (r.PUSH = "PUSH", r.POP = "POP", r))(xo || {});
4003
- class nd {
4007
+ class id {
4004
4008
  constructor(e) {
4005
4009
  this.queries = [], this.context = e, this.extension = e.getExtension(
4006
4010
  "EXT_disjoint_timer_query_webgl2"
@@ -4072,7 +4076,7 @@ class ur {
4072
4076
  const e = new OffscreenCanvas(0, 0), t = e.getContext("webgl2");
4073
4077
  if (!t)
4074
4078
  throw "Fail to retrieve webgl2 context";
4075
- this.canvas = e, this.context = t, this.improveMask = new rd(
4079
+ this.canvas = e, this.context = t, this.improveMask = new nd(
4076
4080
  this.context,
4077
4081
  Ue,
4078
4082
  Ue
@@ -4085,7 +4089,7 @@ class ur {
4085
4089
  this.postProcessingEnabled = !1;
4086
4090
  }
4087
4091
  async profileWebgl(e) {
4088
- const t = new nd(this.context);
4092
+ const t = new id(this.context);
4089
4093
  return this.profiler = t, t.start(), await bo(e), this.profiler = void 0, t.stop(), t.getResolvedQueries();
4090
4094
  }
4091
4095
  async render(e, t) {
@@ -4112,7 +4116,7 @@ class vo extends ur {
4112
4116
  const e = new OffscreenCanvas(0, 0), t = e.getContext("webgl2");
4113
4117
  if (!t)
4114
4118
  throw "Fail to retrieve webgl context";
4115
- this.backgroundImageResizerCanvas = e, this.backgroundImageResizerContext = t, this.backgroundImageResizer = new Xf(
4119
+ this.backgroundImageResizerCanvas = e, this.backgroundImageResizerContext = t, this.backgroundImageResizer = new Kf(
4116
4120
  this.backgroundImageResizerContext,
4117
4121
  0,
4118
4122
  0
@@ -4133,7 +4137,7 @@ class vo extends ur {
4133
4137
  e && e.loseContext(), super.destroy();
4134
4138
  }
4135
4139
  }
4136
- class id extends vo {
4140
+ class od extends vo {
4137
4141
  setBackgroundVideo(e) {
4138
4142
  this.frameReader = e;
4139
4143
  }
@@ -4150,19 +4154,19 @@ class id extends vo {
4150
4154
  }
4151
4155
  class ri {
4152
4156
  blurBackground(e) {
4153
- return new La(e);
4157
+ return new za(e);
4154
4158
  }
4155
4159
  blurSilhouette(e) {
4156
- return new za(e);
4160
+ return new Na(e);
4157
4161
  }
4158
4162
  imageBackground() {
4159
- return new Na();
4163
+ return new $a();
4160
4164
  }
4161
4165
  videoBackground() {
4162
- return new id();
4166
+ return new od();
4163
4167
  }
4164
4168
  }
4165
- const od = `precision mediump float;
4169
+ const sd = `precision mediump float;
4166
4170
 
4167
4171
  varying vec2 _texture_coord;
4168
4172
 
@@ -4173,7 +4177,7 @@ uniform sampler2D mask;
4173
4177
  vec4 loop();
4174
4178
 
4175
4179
  void main() { gl_FragColor = loop(); }
4176
- `, sd = `varying vec2 _texture_coord;
4180
+ `, ad = `varying vec2 _texture_coord;
4177
4181
 
4178
4182
  attribute vec2 position;
4179
4183
  attribute vec2 texture_coord;
@@ -4183,15 +4187,15 @@ void main() {
4183
4187
  _texture_coord = texture_coord;
4184
4188
  }
4185
4189
  `;
4186
- class ad extends ot {
4190
+ class cd extends ot {
4187
4191
  getDefines() {
4188
4192
  return { RADIUS: this.options.radius ?? 1 };
4189
4193
  }
4190
4194
  getFragmentShader() {
4191
- return od + this.createLoopFunction();
4195
+ return sd + this.createLoopFunction();
4192
4196
  }
4193
4197
  getVertexShader() {
4194
- return sd;
4198
+ return ad;
4195
4199
  }
4196
4200
  createLoopFunction() {
4197
4201
  let e = this.options.radius ?? 1;
@@ -4220,8 +4224,8 @@ class ad extends ot {
4220
4224
  }`;
4221
4225
  }
4222
4226
  }
4223
- const cd = 10, ud = 2, ld = 8;
4224
- class fd extends hn {
4227
+ const ud = 10, ld = 2, fd = 8;
4228
+ class dd extends hn {
4225
4229
  constructor(e, t) {
4226
4230
  super(), this.context = e, this.radius = t;
4227
4231
  const n = {
@@ -4229,7 +4233,7 @@ class fd extends hn {
4229
4233
  height: e.canvas.height,
4230
4234
  width: e.canvas.width
4231
4235
  };
4232
- this.blur = new ad({
4236
+ this.blur = new cd({
4233
4237
  ...n,
4234
4238
  radius: t,
4235
4239
  ...this.getBlurTextureSize(
@@ -4255,7 +4259,7 @@ class fd extends hn {
4255
4259
  });
4256
4260
  }
4257
4261
  getBlurTextureSize(e, t) {
4258
- const n = this.radius > cd ? ld : ud;
4262
+ const n = this.radius > ud ? fd : ld;
4259
4263
  return {
4260
4264
  width: Math.max(Ue, e / n),
4261
4265
  height: Math.max(Ue, t / n)
@@ -4270,12 +4274,12 @@ class fd extends hn {
4270
4274
  this.blur.resizeOutput(n.width, n.height);
4271
4275
  }
4272
4276
  }
4273
- class dd extends ur {
4277
+ class hd extends ur {
4274
4278
  constructor(e) {
4275
- super(), this.pipeline = new fd(this.context, e), this.disablePostProcessing();
4279
+ super(), this.pipeline = new dd(this.context, e), this.disablePostProcessing();
4276
4280
  }
4277
4281
  }
4278
- class hd extends hn {
4282
+ class md extends hn {
4279
4283
  constructor(e, t) {
4280
4284
  super(), this.context = e;
4281
4285
  const n = {
@@ -4305,12 +4309,12 @@ class hd extends hn {
4305
4309
  this.inputImage = e, this.inputMask = t;
4306
4310
  }
4307
4311
  }
4308
- class md extends ur {
4312
+ class pd extends ur {
4309
4313
  constructor(e) {
4310
- super(), this.pipeline = new hd(this.context, e), this.disablePostProcessing();
4314
+ super(), this.pipeline = new md(this.context, e), this.disablePostProcessing();
4311
4315
  }
4312
4316
  }
4313
- class pd extends yo {
4317
+ class gd extends yo {
4314
4318
  constructor() {
4315
4319
  super(...arguments), this.preciseMaskEnabled = !0;
4316
4320
  }
@@ -4325,9 +4329,9 @@ class pd extends yo {
4325
4329
  e?.value && (this.inputBackgroundImage = await createImageBitmap(e.value), e.value.close());
4326
4330
  }
4327
4331
  }
4328
- class gd extends ur {
4332
+ class yd extends ur {
4329
4333
  constructor() {
4330
- super(), this.pipeline = new pd(this.context);
4334
+ super(), this.pipeline = new gd(this.context);
4331
4335
  }
4332
4336
  setBackgroundVideo(e) {
4333
4337
  this.pipeline.reader = e;
@@ -4335,19 +4339,19 @@ class gd extends ur {
4335
4339
  }
4336
4340
  class ni {
4337
4341
  blurBackground(e) {
4338
- return new dd(e);
4342
+ return new hd(e);
4339
4343
  }
4340
4344
  blurSilhouette(e) {
4341
- return new md(e);
4345
+ return new pd(e);
4342
4346
  }
4343
4347
  imageBackground() {
4344
4348
  return new vo();
4345
4349
  }
4346
4350
  videoBackground() {
4347
- return new gd();
4351
+ return new yd();
4348
4352
  }
4349
4353
  }
4350
- class yd {
4354
+ class bd {
4351
4355
  constructor(e) {
4352
4356
  switch (e) {
4353
4357
  case Mt.CANVAS:
@@ -4379,10 +4383,10 @@ class yd {
4379
4383
  return this.factory;
4380
4384
  }
4381
4385
  }
4382
- class bd {
4386
+ class wd {
4383
4387
  setBackgroundOptions(e) {
4384
4388
  this.renderer && this.renderer.destroy();
4385
- const t = new yd(e.renderingOptions?.type);
4389
+ const t = new bd(e.renderingOptions?.type);
4386
4390
  switch (e.transformerType) {
4387
4391
  case "BackgroundBlur":
4388
4392
  this.renderer = t.blurBackground(
@@ -4435,7 +4439,7 @@ class bd {
4435
4439
  return this.renderer?.profileWebgl(e) ?? [];
4436
4440
  }
4437
4441
  }
4438
- var wd = (function() {
4442
+ var xd = (function() {
4439
4443
  var r = typeof document < "u" && document.currentScript ? document.currentScript.src : void 0;
4440
4444
  return (function(e) {
4441
4445
  e = e || {};
@@ -4815,17 +4819,17 @@ var wd = (function() {
4815
4819
  return hr(), e.ready;
4816
4820
  });
4817
4821
  })();
4818
- class xd {
4822
+ class vd {
4819
4823
  constructor() {
4820
4824
  this.isSIMDSupported = !1, this.isThreadsSupported = !1, this.inputWidth = 0, this.inputHeight = 0, this.inputChannelCount = 0, this.inputMemoryOffset = 0, this.outputWidth = 0, this.outputHeight = 0, this.outputChannelCount = 0, this.outputMemoryOffset = 0;
4821
4825
  }
4822
4826
  }
4823
- const vd = "https://d3opqjmqzxf057.cloudfront.net/vonage-tensorflow-wasm/tflite-simd-wasm/1.1.3/", _d = "https://d3opqjmqzxf057.cloudfront.net/ml/selfie_segmentation/4.0.0/selfie_segmentation_landscape.tflite";
4824
- async function Ed(r = vd, e = _d) {
4825
- let t = new xd();
4827
+ const _d = "https://d3opqjmqzxf057.cloudfront.net/vonage-tensorflow-wasm/tflite-simd-wasm/1.1.3/", Ed = "https://d3opqjmqzxf057.cloudfront.net/ml/selfie_segmentation/4.0.0/selfie_segmentation_landscape.tflite";
4828
+ async function Ad(r = _d, e = Ed) {
4829
+ let t = new vd();
4826
4830
  var n = new Promise(function(i, o) {
4827
4831
  async function s() {
4828
- return wd({
4832
+ return xd({
4829
4833
  locateFile: function(u) {
4830
4834
  return r + u;
4831
4835
  }
@@ -4890,8 +4894,8 @@ async function Ed(r = vd, e = _d) {
4890
4894
  });
4891
4895
  return n;
4892
4896
  }
4893
- const Ad = 0.1, Td = 0.7, Sd = "https://d3opqjmqzxf057.cloudfront.net/ml/vonage_selfie_segmenter/float16/v1/vonage_selfie_segmenter.tflite";
4894
- class Id {
4897
+ const Td = 0.1, Sd = 0.7, Id = "https://d3opqjmqzxf057.cloudfront.net/ml/vonage_selfie_segmenter/float16/v1/vonage_selfie_segmenter.tflite";
4898
+ class Rd {
4895
4899
  constructor() {
4896
4900
  this.canvas = new OffscreenCanvas(0, 0), this.context = this.canvas.getContext(
4897
4901
  "2d",
@@ -4917,7 +4921,7 @@ class Id {
4917
4921
  });
4918
4922
  }
4919
4923
  async loadMediapipeAssets(e, t) {
4920
- this.modelAssetUriPath = e || Sd;
4924
+ this.modelAssetUriPath = e || Id;
4921
4925
  const n = t ? `${t}/task-vision.js` : "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.20/+esm", i = t ? `${t}/wasm` : "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.20/wasm", { FilesetResolver: o, ImageSegmenter: s } = await import(
4922
4926
  /* @vite-ignore */
4923
4927
  n
@@ -4967,7 +4971,7 @@ class Id {
4967
4971
  }), o = [255, 0, 0];
4968
4972
  for (let s = 0; s < i?.length; s++) {
4969
4973
  const a = 1 - i[s];
4970
- a > Ad ? (a < Td ? (this.mask.data[s * 4] = o[0] * a, this.mask.data[s * 4 + 3] = 255 * a) : (this.mask.data[s * 4] = o[0], this.mask.data[s * 4 + 3] = 255), this.mask.data[s * 4 + 1] = o[1], this.mask.data[s * 4 + 2] = o[2]) : this.mask.data[s * 4] = this.mask.data[s * 4 + 1] = this.mask.data[s * 4 + 2] = this.mask.data[s * 4 + 3] = 0;
4974
+ a > Td ? (a < Sd ? (this.mask.data[s * 4] = o[0] * a, this.mask.data[s * 4 + 3] = 255 * a) : (this.mask.data[s * 4] = o[0], this.mask.data[s * 4 + 3] = 255), this.mask.data[s * 4 + 1] = o[1], this.mask.data[s * 4 + 2] = o[2]) : this.mask.data[s * 4] = this.mask.data[s * 4 + 1] = this.mask.data[s * 4 + 2] = this.mask.data[s * 4 + 3] = 0;
4971
4975
  }
4972
4976
  return this.previousConfidenceMask = i.slice(), this.mask;
4973
4977
  }
@@ -4980,7 +4984,7 @@ class Id {
4980
4984
  return t + (e - t) * (f * 0.9);
4981
4985
  }
4982
4986
  }
4983
- class Rd {
4987
+ class kd {
4984
4988
  constructor() {
4985
4989
  this.canvas = new OffscreenCanvas(0, 0), this.context = this.canvas.getContext(
4986
4990
  "2d",
@@ -4996,7 +5000,7 @@ class Rd {
4996
5000
  ), this.inputOffset = this.infos.inputMemoryOffset / 4, this.outputOffset = this.infos.outputMemoryOffset / 4);
4997
5001
  }
4998
5002
  async initWasm(e, t) {
4999
- this.infos = await Ed(
5003
+ this.infos = await Ad(
5000
5004
  e,
5001
5005
  t
5002
5006
  );
@@ -5032,16 +5036,16 @@ class Rd {
5032
5036
  return this.infos?.selectedTFLite?._isGPUEnabled() ?? !1;
5033
5037
  }
5034
5038
  }
5035
- class kd {
5039
+ class Pd {
5036
5040
  constructor() {
5037
- this.reporter = new Da(), this.isEnabled = !0;
5041
+ this.reporter = new Ua(), this.isEnabled = !0;
5038
5042
  }
5039
5043
  async init(e, t) {
5040
- t.segmentationOptions?.lightWeightEngine === !0 ? this.selfieSegmentation = new Rd() : this.selfieSegmentation = new Id(), this.selfieSegmentation?.init(
5044
+ t.segmentationOptions?.lightWeightEngine === !0 ? this.selfieSegmentation = new kd() : this.selfieSegmentation = new Rd(), this.selfieSegmentation?.init(
5041
5045
  t.modelAssetUriPath,
5042
5046
  t.mediapipeBaseAssetsUri,
5043
5047
  t.segmentationOptions?.gpuSupport
5044
- ), this.backgroundFilter = new bd(), this.report({
5048
+ ), this.backgroundFilter = new wd(), this.report({
5045
5049
  variation: "Create"
5046
5050
  });
5047
5051
  }
@@ -5082,7 +5086,7 @@ class kd {
5082
5086
  }
5083
5087
  report(e) {
5084
5088
  this.reporter.send({
5085
- version: Ua,
5089
+ version: La,
5086
5090
  action: "MlTransformers",
5087
5091
  transformerType: this.backgroundOptions?.transformerType,
5088
5092
  config: JSON.stringify(this.backgroundOptions),
@@ -5092,7 +5096,7 @@ class kd {
5092
5096
  }
5093
5097
  const pn = class pn {
5094
5098
  constructor() {
5095
- this.backgroundTransformer = new kd(), this.mediaProcessor = new ui(), this.rate = 30, this.eventsQueue = [], this.frameTransformLatencyMs = [];
5099
+ this.backgroundTransformer = new Pd(), this.mediaProcessor = new ui(), this.rate = 30, this.eventsQueue = [], this.frameTransformLatencyMs = [];
5096
5100
  }
5097
5101
  async init(e, t) {
5098
5102
  this.frameTransformLatencyMs = [], await this.backgroundTransformer.init(e, t), await this.mediaProcessor.setTransformers([this.backgroundTransformer]), this.mediaProcessor.setTrackExpectedRate(this.rate), this.mediaProcessor.onAny((n, i) => {
@@ -5132,7 +5136,7 @@ const pn = class pn {
5132
5136
  console.log(`Transform latency average is: ${t} ms`);
5133
5137
  }
5134
5138
  setVonageMetadata(e) {
5135
- Fs(e);
5139
+ Cs(e);
5136
5140
  }
5137
5141
  async profile(e) {
5138
5142
  return JSON.stringify(
@@ -5140,10 +5144,10 @@ const pn = class pn {
5140
5144
  );
5141
5145
  }
5142
5146
  };
5143
- ca("ProcessorWorker", pn);
5147
+ ua("ProcessorWorker", pn);
5144
5148
  let Mr = pn;
5145
- const _o = '(function(){"use strict";function Vt(r,e){globalThis.vonage||(globalThis.vonage={}),globalThis.vonage.workerizer||(globalThis.vonage.workerizer={});let t=globalThis.vonage.workerizer;return t[r]||(t[r]=e),t[r]}const Vr=Vt("globals",{});var xe=(r=>(r.INIT="INIT",r.FORWARD="FORWARD",r.TERMINATE="TERMINATE",r.GLOBALS_SYNC="GLOBALS_SYNC",r.EVENT="EVENT",r))(xe||{});function zi(r){return[ImageBitmap,ReadableStream,WritableStream].some(t=>r instanceof t)}function Be(r,e){const{id:t,type:n}=r,i=Array.isArray(e)?e:[e];postMessage({id:t,type:n,result:e},i.filter(s=>zi(s)))}Vt("workerized",{});function Hr(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function qe(r,e){if(Array.isArray(e))e.splice(0,e.length);else if(typeof e=="object")for(const t in e)delete e[t];for(const t in r)Array.isArray(r[t])?(e[t]=[],qe(r[t],e[t])):typeof r[t]=="object"?(e[t]={},qe(r[t],e[t])):e[t]=r[t]}const K=new WeakMap,ce=new WeakMap,j=new WeakMap,Ke=Symbol("anyProducer"),jr=Promise.resolve(),Je=Symbol("listenerAdded"),Ze=Symbol("listenerRemoved");let et=!1,Ht=!1;function _e(r){if(typeof r!="string"&&typeof r!="symbol"&&typeof r!="number")throw new TypeError("`eventName` must be a string, symbol, or number")}function tt(r){if(typeof r!="function")throw new TypeError("listener must be a function")}function Ee(r,e){const t=ce.get(r);if(t.has(e))return t.get(e)}function De(r,e){const t=typeof e=="string"||typeof e=="symbol"||typeof e=="number"?e:Ke,n=j.get(r);if(n.has(t))return n.get(t)}function Gi(r,e,t){const n=j.get(r);if(n.has(e))for(const i of n.get(e))i.enqueue(t);if(n.has(Ke)){const i=Promise.all([e,t]);for(const s of n.get(Ke))s.enqueue(i)}}function Xr(r,e){e=Array.isArray(e)?e:[e];let t=!1,n=()=>{},i=[];const s={enqueue(o){i.push(o),n()},finish(){t=!0,n()}};for(const o of e){let a=De(r,o);a||(a=new Set,j.get(r).set(o,a)),a.add(s)}return{async next(){return i?i.length===0?t?(i=void 0,this.next()):(await new Promise(o=>{n=o}),this.next()):{done:!1,value:await i.shift()}:{done:!0}},async return(o){i=void 0;for(const a of e){const c=De(r,a);c&&(c.delete(s),c.size===0&&j.get(r).delete(a))}return n(),arguments.length>0?{done:!0,value:await o}:{done:!0}},[Symbol.asyncIterator](){return this}}}function Yr(r){if(r===void 0)return Qr;if(!Array.isArray(r))throw new TypeError("`methodNames` must be an array of strings");for(const e of r)if(!Qr.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return r}const we=r=>r===Je||r===Ze;function rt(r,e,t){if(we(e))try{et=!0,r.emit(e,t)}finally{et=!1}}class ve{static mixin(e,t){return t=Yr(t),n=>{if(typeof n!="function")throw new TypeError("`target` must be function");for(const o of t)if(n.prototype[o]!==void 0)throw new Error(`The property \\`${o}\\` already exists on \\`target\\``);function i(){return Object.defineProperty(this,e,{enumerable:!1,value:new ve}),this[e]}Object.defineProperty(n.prototype,e,{enumerable:!1,get:i});const s=o=>function(...a){return this[e][o](...a)};for(const o of t)Object.defineProperty(n.prototype,o,{enumerable:!1,value:s(o)});return n}}static get isDebugEnabled(){var e,t;if(typeof((e=globalThis.process)==null?void 0:e.env)!="object")return Ht;const{env:n}=(t=globalThis.process)!=null?t:{env:{}};return n.DEBUG==="emittery"||n.DEBUG==="*"||Ht}static set isDebugEnabled(e){Ht=e}constructor(e={}){var t;K.set(this,new Set),ce.set(this,new Map),j.set(this,new Map),j.get(this).set(Ke,new Set),this.debug=(t=e.debug)!=null?t:{},this.debug.enabled===void 0&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(n,i,s,o)=>{try{o=JSON.stringify(o)}catch{o=`Object with the following keys failed to stringify: ${Object.keys(o).join(",")}`}(typeof s=="symbol"||typeof s=="number")&&(s=s.toString());const a=new Date,c=`${a.getHours()}:${a.getMinutes()}:${a.getSeconds()}.${a.getMilliseconds()}`;console.log(`[${c}][emittery:${n}][${i}] Event Name: ${s}\n data: ${o}`)})}logIfDebugEnabled(e,t,n){(ve.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,t,n)}on(e,t){tt(t),e=Array.isArray(e)?e:[e];for(const n of e){_e(n);let i=Ee(this,n);i||(i=new Set,ce.get(this).set(n,i)),i.add(t),this.logIfDebugEnabled("subscribe",n,void 0),we(n)||rt(this,Je,{eventName:n,listener:t})}return this.off.bind(this,e,t)}off(e,t){tt(t),e=Array.isArray(e)?e:[e];for(const n of e){_e(n);const i=Ee(this,n);i&&(i.delete(t),i.size===0&&ce.get(this).delete(n)),this.logIfDebugEnabled("unsubscribe",n,void 0),we(n)||rt(this,Ze,{eventName:n,listener:t})}}once(e){let t;const n=new Promise(i=>{t=this.on(e,s=>{t(),i(s)})});return n.off=t,n}events(e){e=Array.isArray(e)?e:[e];for(const t of e)_e(t);return Xr(this,e)}async emit(e,t){var n;if(_e(e),we(e)&&!et)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emit",e,t),Gi(this,e,t);const i=(n=Ee(this,e))!=null?n:new Set,s=K.get(this),o=[...i],a=we(e)?[]:[...s];await jr,await Promise.all([...o.map(async c=>{if(i.has(c))return c(t)}),...a.map(async c=>{if(s.has(c))return c(e,t)})])}async emitSerial(e,t){var n;if(_e(e),we(e)&&!et)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emitSerial",e,t);const i=(n=Ee(this,e))!=null?n:new Set,s=K.get(this),o=[...i],a=[...s];await jr;for(const c of o)i.has(c)&&await c(t);for(const c of a)s.has(c)&&await c(e,t)}onAny(e){return tt(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),K.get(this).add(e),rt(this,Je,{listener:e}),this.offAny.bind(this,e)}anyEvent(){return Xr(this)}offAny(e){tt(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),rt(this,Ze,{listener:e}),K.get(this).delete(e)}clearListeners(e){e=Array.isArray(e)?e:[e];for(const t of e)if(this.logIfDebugEnabled("clear",t,void 0),typeof t=="string"||typeof t=="symbol"||typeof t=="number"){const n=Ee(this,t);n&&n.clear();const i=De(this,t);if(i){for(const s of i)s.finish();i.clear()}}else{K.get(this).clear();for(const[n,i]of ce.get(this).entries())i.clear(),ce.get(this).delete(n);for(const[n,i]of j.get(this).entries()){for(const s of i)s.finish();i.clear(),j.get(this).delete(n)}}}listenerCount(e){var t,n,i,s,o,a;e=Array.isArray(e)?e:[e];let c=0;for(const u of e){if(typeof u=="string"){c+=K.get(this).size+((n=(t=Ee(this,u))==null?void 0:t.size)!=null?n:0)+((s=(i=De(this,u))==null?void 0:i.size)!=null?s:0)+((a=(o=De(this))==null?void 0:o.size)!=null?a:0);continue}typeof u<"u"&&_e(u),c+=K.get(this).size;for(const d of ce.get(this).values())c+=d.size;for(const d of j.get(this).values())c+=d.size}return c}bindMethods(e,t){if(typeof e!="object"||e===null)throw new TypeError("`target` must be an object");t=Yr(t);for(const n of t){if(e[n]!==void 0)throw new Error(`The property \\`${n}\\` already exists on \\`target\\``);Object.defineProperty(e,n,{enumerable:!1,value:this[n].bind(this)})}}}const Qr=Object.getOwnPropertyNames(ve.prototype).filter(r=>r!=="constructor");Object.defineProperty(ve,"listenerAdded",{value:Je,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(ve,"listenerRemoved",{value:Ze,writable:!1,enumerable:!0,configurable:!1});function $i(r){return r.onAny&&r.emit}async function Wi(r,e){const{functionName:t,args:n}=r;if(!e.instance)throw"instance not initialized";if(!t)throw"missing function name to call";if(!e.instance[t])throw`undefined function [${t}] in class ${e.instance.constructor.workerId}`;Be(r,await e.instance[t](...n??[]))}const qr=Vt("registeredWorkers",{});function Vi(r,e){e.workerId=r,Hr()&&(qr[e.workerId]=e)}function Hi(r,e){if(!r.args)throw"Missing className while initializing worker";const[t,n]=r.args,i=qr[t];if(i)e.instance=new i(r.args.slice(1));else throw`unknown worker class ${t}`;qe(n,Vr),$i(e.instance)&&e.instance.onAny((s,o)=>{Be({type:xe.EVENT},{name:s,data:o})}),Be(r,typeof e.instance!==void 0)}async function ji(r,e){const{args:t}=r;if(!e.instance)throw"instance not initialized";let n;e.instance.terminate&&(n=await e.instance.terminate(...t??[])),Be(r,n)}function Xi(r){if(!r.args)throw"Missing globals while syncing";qe(r.args[0],Vr),Be(r,{})}function Yi(){const r={};onmessage=async e=>{const t=e.data;switch(t.type){case xe.INIT:Hi(t,r);break;case xe.FORWARD:Wi(t,r);break;case xe.TERMINATE:ji(t,r);break;case xe.GLOBALS_SYNC:Xi(t);break}}}Hr()&&Yi();const J=new WeakMap,ue=new WeakMap,X=new WeakMap,nt=Symbol("anyProducer"),Kr=Promise.resolve(),it=Symbol("listenerAdded"),st=Symbol("listenerRemoved");let ot=!1,jt=!1;const at=r=>typeof r=="string"||typeof r=="symbol"||typeof r=="number";function Te(r){if(!at(r))throw new TypeError("`eventName` must be a string, symbol, or number")}function ct(r){if(typeof r!="function")throw new TypeError("listener must be a function")}function Ae(r,e){const t=ue.get(r);if(t.has(e))return t.get(e)}function Me(r,e){const t=at(e)?e:nt,n=X.get(r);if(n.has(t))return n.get(t)}function Qi(r,e,t){const n=X.get(r);if(n.has(e))for(const i of n.get(e))i.enqueue(t);if(n.has(nt)){const i=Promise.all([e,t]);for(const s of n.get(nt))s.enqueue(i)}}function Jr(r,e){e=Array.isArray(e)?e:[e];let t=!1,n=()=>{},i=[];const s={enqueue(o){i.push(o),n()},finish(){t=!0,n()}};for(const o of e){let a=Me(r,o);a||(a=new Set,X.get(r).set(o,a)),a.add(s)}return{async next(){return i?i.length===0?t?(i=void 0,this.next()):(await new Promise(o=>{n=o}),this.next()):{done:!1,value:await i.shift()}:{done:!0}},async return(o){i=void 0;for(const a of e){const c=Me(r,a);c&&(c.delete(s),c.size===0&&X.get(r).delete(a))}return n(),arguments.length>0?{done:!0,value:await o}:{done:!0}},[Symbol.asyncIterator](){return this}}}function Zr(r){if(r===void 0)return en;if(!Array.isArray(r))throw new TypeError("`methodNames` must be an array of strings");for(const e of r)if(!en.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return r}const Ie=r=>r===it||r===st;function ut(r,e,t){if(Ie(e))try{ot=!0,r.emit(e,t)}finally{ot=!1}}class Y{static mixin(e,t){return t=Zr(t),n=>{if(typeof n!="function")throw new TypeError("`target` must be function");for(const o of t)if(n.prototype[o]!==void 0)throw new Error(`The property \\`${o}\\` already exists on \\`target\\``);function i(){return Object.defineProperty(this,e,{enumerable:!1,value:new Y}),this[e]}Object.defineProperty(n.prototype,e,{enumerable:!1,get:i});const s=o=>function(...a){return this[e][o](...a)};for(const o of t)Object.defineProperty(n.prototype,o,{enumerable:!1,value:s(o)});return n}}static get isDebugEnabled(){if(typeof globalThis.process?.env!="object")return jt;const{env:e}=globalThis.process??{env:{}};return e.DEBUG==="emittery"||e.DEBUG==="*"||jt}static set isDebugEnabled(e){jt=e}constructor(e={}){J.set(this,new Set),ue.set(this,new Map),X.set(this,new Map),X.get(this).set(nt,new Set),this.debug=e.debug??{},this.debug.enabled===void 0&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(t,n,i,s)=>{try{s=JSON.stringify(s)}catch{s=`Object with the following keys failed to stringify: ${Object.keys(s).join(",")}`}(typeof i=="symbol"||typeof i=="number")&&(i=i.toString());const o=new Date,a=`${o.getHours()}:${o.getMinutes()}:${o.getSeconds()}.${o.getMilliseconds()}`;console.log(`[${a}][emittery:${t}][${n}] Event Name: ${i}\n data: ${s}`)})}logIfDebugEnabled(e,t,n){(Y.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,t,n)}on(e,t,{signal:n}={}){ct(t),e=Array.isArray(e)?e:[e];for(const s of e){Te(s);let o=Ae(this,s);o||(o=new Set,ue.get(this).set(s,o)),o.add(t),this.logIfDebugEnabled("subscribe",s,void 0),Ie(s)||ut(this,it,{eventName:s,listener:t})}const i=()=>{this.off(e,t),n?.removeEventListener("abort",i)};return n?.addEventListener("abort",i,{once:!0}),n?.aborted&&i(),i}off(e,t){ct(t),e=Array.isArray(e)?e:[e];for(const n of e){Te(n);const i=Ae(this,n);i&&(i.delete(t),i.size===0&&ue.get(this).delete(n)),this.logIfDebugEnabled("unsubscribe",n,void 0),Ie(n)||ut(this,st,{eventName:n,listener:t})}}once(e,t){if(t!==void 0&&typeof t!="function")throw new TypeError("predicate must be a function");let n;const i=new Promise(s=>{n=this.on(e,o=>{t&&!t(o)||(n(),s(o))})});return i.off=n,i}events(e){e=Array.isArray(e)?e:[e];for(const t of e)Te(t);return Jr(this,e)}async emit(e,t){if(Te(e),Ie(e)&&!ot)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emit",e,t),Qi(this,e,t);const n=Ae(this,e)??new Set,i=J.get(this),s=[...n],o=Ie(e)?[]:[...i];await Kr,await Promise.all([...s.map(async a=>{if(n.has(a))return a(t)}),...o.map(async a=>{if(i.has(a))return a(e,t)})])}async emitSerial(e,t){if(Te(e),Ie(e)&&!ot)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emitSerial",e,t);const n=Ae(this,e)??new Set,i=J.get(this),s=[...n],o=[...i];await Kr;for(const a of s)n.has(a)&&await a(t);for(const a of o)i.has(a)&&await a(e,t)}onAny(e,{signal:t}={}){ct(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),J.get(this).add(e),ut(this,it,{listener:e});const n=()=>{this.offAny(e),t?.removeEventListener("abort",n)};return t?.addEventListener("abort",n,{once:!0}),t?.aborted&&n(),n}anyEvent(){return Jr(this)}offAny(e){ct(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),ut(this,st,{listener:e}),J.get(this).delete(e)}clearListeners(e){e=Array.isArray(e)?e:[e];for(const t of e)if(this.logIfDebugEnabled("clear",t,void 0),at(t)){const n=Ae(this,t);n&&n.clear();const i=Me(this,t);if(i){for(const s of i)s.finish();i.clear()}}else{J.get(this).clear();for(const[n,i]of ue.get(this).entries())i.clear(),ue.get(this).delete(n);for(const[n,i]of X.get(this).entries()){for(const s of i)s.finish();i.clear(),X.get(this).delete(n)}}}listenerCount(e){e=Array.isArray(e)?e:[e];let t=0;for(const n of e){if(at(n)){t+=J.get(this).size+(Ae(this,n)?.size??0)+(Me(this,n)?.size??0)+(Me(this)?.size??0);continue}n!==void 0&&Te(n),t+=J.get(this).size;for(const i of ue.get(this).values())t+=i.size;for(const i of X.get(this).values())t+=i.size}return t}bindMethods(e,t){if(typeof e!="object"||e===null)throw new TypeError("`target` must be an object");t=Zr(t);for(const n of t){if(e[n]!==void 0)throw new Error(`The property \\`${n}\\` already exists on \\`target\\``);Object.defineProperty(e,n,{enumerable:!1,value:this[n].bind(this)})}}}const en=Object.getOwnPropertyNames(Y.prototype).filter(r=>r!=="constructor");Object.defineProperty(Y,"listenerAdded",{value:it,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(Y,"listenerRemoved",{value:st,writable:!1,enumerable:!0,configurable:!1});var qi=Object.defineProperty,Ki=(r,e,t)=>e in r?qi(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Ji=(r,e,t)=>(Ki(r,e+"",t),t);const Zi="hlg.tokbox.com/prod/logging/vcp_webrtc",es="https://",ts=1e4;let ft;const rs=new Uint8Array(16);function ns(){if(!ft&&(ft=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ft))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ft(rs)}const F=[];for(let r=0;r<256;++r)F.push((r+256).toString(16).slice(1));function is(r,e=0){return(F[r[e+0]]+F[r[e+1]]+F[r[e+2]]+F[r[e+3]]+"-"+F[r[e+4]]+F[r[e+5]]+"-"+F[r[e+6]]+F[r[e+7]]+"-"+F[r[e+8]]+F[r[e+9]]+"-"+F[r[e+10]]+F[r[e+11]]+F[r[e+12]]+F[r[e+13]]+F[r[e+14]]+F[r[e+15]]).toLowerCase()}const ss=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),tn={randomUUID:ss};function os(r,e,t){if(tn.randomUUID&&!r)return tn.randomUUID();r=r||{};const n=r.random||(r.rng||ns)();return n[6]=n[6]&15|64,n[8]=n[8]&63|128,is(n)}function Xt(r,e){globalThis.vonage||(globalThis.vonage={}),globalThis.vonage.workerizer||(globalThis.vonage.workerizer={});let t=globalThis.vonage.workerizer;return t[r]||(t[r]=e),t[r]}const Z=Xt("globals",{});var fe=(r=>(r.INIT="INIT",r.FORWARD="FORWARD",r.TERMINATE="TERMINATE",r.GLOBALS_SYNC="GLOBALS_SYNC",r))(fe||{});function rn(r){return[ImageBitmap,ReadableStream,WritableStream].some(e=>r instanceof e)}let as=0;function cs(r,e,t,n,i){const s=as++;return r.postMessage({id:s,type:e,functionName:t,args:n},n.filter(o=>rn(o))),new Promise(o=>{i?.set(s,o)})}function Oe(r,e){const{id:t,type:n}=r,i=Array.isArray(e)?e:[e];postMessage({id:t,type:n,result:e},i.filter(s=>rn(s)))}const nn=Xt("workerized",{});function sn(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}async function us(){if(sn())Oe({type:fe.GLOBALS_SYNC},Z);else{const r=[];for(const e in nn){const{worker:t,resolvers:n}=nn[e].workerContext;t&&r.push(cs(t,fe.GLOBALS_SYNC,"",[Z],n))}await Promise.all(r)}}function lt(r,e){if(Array.isArray(e))e.splice(0,e.length);else if(typeof e=="object")for(const t in e)delete e[t];for(const t in r)Array.isArray(r[t])?(e[t]=[],lt(r[t],e[t])):typeof r[t]=="object"?(e[t]={},lt(r[t],e[t])):e[t]=r[t]}async function fs(r,e){const{functionName:t,args:n}=r;if(!e.instance)throw"instance not initialized";if(!t)throw"missing function name to call";if(!e.instance[t])throw`undefined function [${t}] in class ${e.instance.constructor.workerId}`;Oe(r,await e.instance[t](...n??[]))}const ls=Xt("registeredWorkers",{});function ds(r,e){if(!r.args)throw"Missing className while initializing worker";const[t,n]=r.args,i=ls[t];if(i)e.instance=new i(r.args.slice(1));else throw`unknown worker class ${t}`;lt(n,Z),Oe(r,typeof e.instance!==void 0)}async function hs(r,e){const{args:t}=r;if(!e.instance)throw"instance not initialized";let n;e.instance.terminate&&(n=await e.instance.terminate(...t??[])),Oe(r,n)}function ms(r){if(!r.args)throw"Missing globals while syncing";lt(r.args[0],Z),Oe(r,{})}function ps(){const r={};onmessage=async e=>{const t=e.data;switch(t.type){case fe.INIT:ds(t,r);break;case fe.FORWARD:fs(t,r);break;case fe.TERMINATE:hs(t,r);break;case fe.GLOBALS_SYNC:ms(t);break}}}sn()&&ps();function gs(r,e){return Z[r]||(Z[r]=e),[()=>Z[r],async t=>{Z[r]=t,await us()}]}function ys(r,e){return gs(r,e)}const[bs,xs]=ys("metadata");function _s(r){xs(r)}function Yt(){return bs()}let Qt=class{constructor(e,t){Ji(this,"uuid"),this.config=e,this.uuid=t??os()}async send(e){var t,n,i;const{appId:s,sourceType:o}=(t=Yt())!=null?t:{};if(!s||!o)return"metadata missing";const a=new AbortController,c=setTimeout(()=>a.abort(),ts);return await((i=(n=this.config)==null?void 0:n.fetch)!=null?i:fetch)(this.getUrl(),{method:"POST",headers:this.getHeaders(),body:JSON.stringify(this.buildReport(e)),signal:a.signal}),clearTimeout(c),"success"}getUrl(){var e;let t=(e=Yt().proxyUrl)!=null?e:es;return t+=(t.at(-1)==="/"?"":"/")+Zi,t}getHeaders(){return{"Content-Type":"application/json"}}buildReport(e){const t=Yt();return{guid:this.uuid,...e,applicationId:t.appId,timestamp:Date.now(),proxyUrl:t.proxyUrl,source:t.sourceType}}};const dt="3.0.1-alpha.0",qt=class{};qt.updates={transformer_new:"New transformer",transformer_null:"Null transformer"},qt.errors={transformer_none:"No transformers provided",transformer_start:"Cannot start transformer",transformer_transform:"Cannot transform frame",transformer_flush:"Cannot flush transformer",readable_null:"Readable is null",writable_null:"Writable is null"};let le=qt;function Es(r){return typeof r=="object"&&r!==null&&"message"in r&&typeof r.message=="string"}function ws(r){if(Es(r))return r;try{return new Error(JSON.stringify(r))}catch{return new Error(String(r))}}function Kt(r){return ws(r).message}class vs{constructor(e,t){this.config=e,this.frameTransformedCount=0,this.frameFromSourceCount=0,this.startAt=0,this.reporter=new Qt(e,t)}async onFrameFromSource(){this.frameFromSourceCount++}get fps(){const{startAt:e,frameFromSourceCount:t}=this,n=(Date.now()-e)/1e3;return t/n}async onFrameTransformed(e={},t=!1){this.startAt===0&&(this.startAt=Date.now()),this.frameTransformedCount++;const{startAt:n,frameTransformedCount:i,frameFromSourceCount:s}=this,o=Date.now(),a=(o-n)/1e3,c=i/a,u=s/a;return t||this.frameTransformedCount>=this.config.loggingIntervalFrameCount?(this.frameFromSourceCount=0,this.frameTransformedCount=0,this.startAt=o,this.reporter.config=this.config,this.reporter.send({...this.config.report,variation:"QoS",fps:u,transformedFps:c,framesTransformed:i,...e})):"success"}}var Jt=(r=>(r.pipeline_ended="pipeline_ended",r.pipeline_ended_with_error="pipeline_ended_with_error",r.pipeline_started="pipeline_started",r.pipeline_started_with_error="pipeline_started_with_error",r.pipeline_restarted="pipeline_restarted",r.pipeline_restarted_with_error="pipeline_restarted_with_error",r))(Jt||{});const Ts=500,As=.8;class Is extends Y{constructor(e,t){super(),this.reporter_=new Qt,this.reporterQos_=new vs({loggingIntervalFrameCount:Ts,report:{version:dt}}),this.index_=t,this.transformer_=e,this.shouldStop_=!1,this.isFlashed_=!1,this.mediaTransformerQosReportStartTimestamp_=0,this.videoHeight_=0,this.videoWidth_=0,this.trackExpectedRate_=-1,this.transformerType_="Custom","getTransformerType"in e&&(this.transformerType_=e.getTransformerType()),this.report({variation:"Create"})}setTrackExpectedRate(e){this.trackExpectedRate_=e}async start(e){if(this.controller_=e,this.transformer_&&typeof this.transformer_.start=="function")try{await this.transformer_.start(e)}catch(t){this.report({message:le.errors.transformer_start,variation:"Error",error:Kt(t)});const n={eventMetaData:{transformerIndex:this.index_},error:t,function:"start"};this.emit("error",n)}}async transform(e,t){if(this.mediaTransformerQosReportStartTimestamp_===0&&(this.mediaTransformerQosReportStartTimestamp_=Date.now()),e instanceof VideoFrame&&(this.videoHeight_=e?.displayHeight??0,this.videoWidth_=e?.displayWidth??0),this.reporterQos_.onFrameFromSource(),this.transformer_)if(this.shouldStop_)console.warn("[Pipeline] flush from transform"),e.close(),this.flush(t),t.terminate();else{try{await this.transformer_.transform?.(e,t),this.reportQos()}catch(n){this.report({message:le.errors.transformer_transform,variation:"Error",error:Kt(n)});const i={eventMetaData:{transformerIndex:this.index_},error:n,function:"transform"};this.emit("error",i)}if(this.trackExpectedRate_!=-1&&this.trackExpectedRate_*As>this.reporterQos_.fps){const n={eventMetaData:{transformerIndex:this.index_},warningType:"fps_drop",dropInfo:{requested:this.trackExpectedRate_,current:this.reporterQos_.fps}};this.emit("warn",n)}}}async flush(e){if(this.transformer_&&typeof this.transformer_.flush=="function"&&!this.isFlashed_){this.isFlashed_=!0;try{await this.transformer_.flush(e)}catch(t){this.report({message:le.errors.transformer_flush,variation:"Error",error:Kt(t)});const n={eventMetaData:{transformerIndex:this.index_},error:t,function:"flush"};this.emit("error",n)}}this.reportQos(!0),this.report({variation:"Delete"})}stop(){console.log("[Pipeline] Stop stream."),this.controller_&&(this.flush(this.controller_),this.controller_.terminate()),this.shouldStop_=!0}report(e){this.reporter_.send({version:dt,action:"MediaTransformer",transformerType:this.transformerType_,...e})}reportQos(e=!1){this.reporterQos_.config={...this.reporterQos_.config},this.reporterQos_.onFrameTransformed({version:dt,action:"MediaTransformer",transformerType:this.transformerType_,videoWidth:this.videoWidth_,videoHeight:this.videoHeight_},e)}}class Ss extends Y{constructor(e){super(),this.transformers_=[],this.trackExpectedRate_=-1;for(let t=0;t<e.length;t++){let n=new Is(e[t],t);n.on("error",i=>{this.emit("error",i)}),n.on("warn",i=>{this.emit("warn",i)}),this.transformers_.push(n)}}setTrackExpectedRate(e){this.trackExpectedRate_=e;for(let t of this.transformers_)t.setTrackExpectedRate(this.trackExpectedRate_)}async start(e,t){if(!this.transformers_||this.transformers_.length===0){console.log("[Pipeline] No transformers.");return}try{let n=e;for(let i of this.transformers_)e=e.pipeThrough(new TransformStream(i));e.pipeTo(t).then(async()=>{console.log("[Pipeline] Setup."),await t.abort(),await n.cancel(),this.emit("pipelineInfo","pipeline_ended")}).catch(async i=>{e.cancel().then(()=>{console.log("[Pipeline] Shutting down streams after abort.")}).catch(s=>{console.error("[Pipeline] Error from stream transform:",s)}),await t.abort(i),await n.cancel(i),this.emit("pipelineInfo","pipeline_ended_with_error")})}catch{this.emit("pipelineInfo","pipeline_started_with_error"),this.destroy();return}this.emit("pipelineInfo","pipeline_started"),console.log("[Pipeline] Pipeline started.")}async destroy(){console.log("[Pipeline] Destroying Pipeline.");for(let e of this.transformers_)e.stop()}}class Rs extends Y{constructor(){super(),this.reporter_=new Qt,this.trackExpectedRate_=-1,this.report({variation:"Create"})}setTrackExpectedRate(e){this.trackExpectedRate_=e,this.pipeline_&&this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_)}async transform(e,t){if(this.isTrack(e)){if(e.kind==="video"){const n=new MediaStreamTrackProcessor({track:e}),i=new VideoTrackGenerator;return this.readable_=n.readable,this.writable_=i.writable,await this.transformInternal(),i.track}throw Error("Cannot process audio tracks inside a web worker when passing a track to transform")}else return this.readable_=e,this.writable_=t,this.transformInternal()}transformInternal(){return new Promise(async(e,t)=>{if(!this.transformers_||this.transformers_.length===0){this.report({message:le.errors.transformer_none,variation:"Error"}),t("[MediaProcessor] Need to set transformers.");return}if(!this.readable_){this.report({variation:"Error",message:le.errors.readable_null}),t("[MediaProcessor] Readable is null.");return}if(!this.writable_){this.report({variation:"Error",message:le.errors.writable_null}),t("[MediaProcessor] Writable is null.");return}let n=!1;this.pipeline_&&(n=!0,this.pipeline_.clearListeners(),this.pipeline_.destroy()),this.pipeline_=new Ss(this.transformers_),this.pipeline_.on("warn",i=>{this.emit("warn",i)}),this.pipeline_.on("error",i=>{this.emit("error",i)}),this.pipeline_.on("pipelineInfo",i=>{n&&(i==="pipeline_started"?i=Jt.pipeline_restarted:i==="pipeline_started_with_error"&&(i=Jt.pipeline_restarted_with_error)),this.emit("pipelineInfo",i)}),this.trackExpectedRate_!=-1&&this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_),this.pipeline_.start(this.readable_,this.writable_).then(()=>{e()}).catch(i=>{t(i)})})}setTransformers(e){return this.report({variation:"Update",message:le.updates.transformer_new}),this.transformers_=e,this.readable_&&this.writable_?this.transformInternal():Promise.resolve()}destroy(){return new Promise(async e=>{this.pipeline_&&this.pipeline_.destroy(),this.report({variation:"Delete"}),e()})}report(e){this.reporter_.send({version:dt,action:"MediaProcessor",...e})}isTrack(e){return"kind"in e}}var Fs=Object.defineProperty,Ps=(r,e,t)=>e in r?Fs(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,ks=(r,e,t)=>(Ps(r,e+"",t),t);const Cs="hlg.tokbox.com/prod/logging/vcp_webrtc",Bs="https://",Ds=1e4;let ht;const Ms=new Uint8Array(16);function Os(){if(!ht&&(ht=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ht))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ht(Ms)}const P=[];for(let r=0;r<256;++r)P.push((r+256).toString(16).slice(1));function Us(r,e=0){return(P[r[e+0]]+P[r[e+1]]+P[r[e+2]]+P[r[e+3]]+"-"+P[r[e+4]]+P[r[e+5]]+"-"+P[r[e+6]]+P[r[e+7]]+"-"+P[r[e+8]]+P[r[e+9]]+"-"+P[r[e+10]]+P[r[e+11]]+P[r[e+12]]+P[r[e+13]]+P[r[e+14]]+P[r[e+15]]).toLowerCase()}const Ns=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),on={randomUUID:Ns};function Ls(r,e,t){if(on.randomUUID&&!e&&!r)return on.randomUUID();r=r||{};const n=r.random||(r.rng||Os)();return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Us(n)}function Zt(r,e){globalThis.vonage||(globalThis.vonage={}),globalThis.vonage.workerizer||(globalThis.vonage.workerizer={});let t=globalThis.vonage.workerizer;return t[r]||(t[r]=e),t[r]}const ee=Zt("globals",{});var de=(r=>(r.INIT="INIT",r.FORWARD="FORWARD",r.TERMINATE="TERMINATE",r.GLOBALS_SYNC="GLOBALS_SYNC",r))(de||{});function an(r){return[ImageBitmap,ReadableStream,WritableStream].some(e=>r instanceof e)}let zs=0;function Gs(r,e,t,n,i){const s=zs++;return r.postMessage({id:s,type:e,functionName:t,args:n},n.filter(o=>an(o))),new Promise(o=>{i?.set(s,o)})}function Ue(r,e){const{id:t,type:n}=r,i=Array.isArray(e)?e:[e];postMessage({id:t,type:n,result:e},i.filter(s=>an(s)))}const cn=Zt("workerized",{});function un(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}async function $s(){if(un())Ue({type:de.GLOBALS_SYNC},ee);else{const r=[];for(const e in cn){const{worker:t,resolvers:n}=cn[e].workerContext;t&&r.push(Gs(t,de.GLOBALS_SYNC,"",[ee],n))}await Promise.all(r)}}function mt(r,e){if(Array.isArray(e))e.splice(0,e.length);else if(typeof e=="object")for(const t in e)delete e[t];for(const t in r)Array.isArray(r[t])?(e[t]=[],mt(r[t],e[t])):typeof r[t]=="object"?(e[t]={},mt(r[t],e[t])):e[t]=r[t]}async function Ws(r,e){const{functionName:t,args:n}=r;if(!e.instance)throw"instance not initialized";if(!t)throw"missing function name to call";if(!e.instance[t])throw`undefined function [${t}] in class ${e.instance.constructor.workerId}`;Ue(r,await e.instance[t](...n??[]))}const Vs=Zt("registeredWorkers",{});function Hs(r,e){if(!r.args)throw"Missing className while initializing worker";const[t,n]=r.args,i=Vs[t];if(i)e.instance=new i(r.args.slice(1));else throw`unknown worker class ${t}`;mt(n,ee),Ue(r,typeof e.instance!==void 0)}async function js(r,e){const{args:t}=r;if(!e.instance)throw"instance not initialized";let n;e.instance.terminate&&(n=await e.instance.terminate(...t??[])),Ue(r,n)}function Xs(r){if(!r.args)throw"Missing globals while syncing";mt(r.args[0],ee),Ue(r,{})}function Ys(){const r={};onmessage=async e=>{const t=e.data;switch(t.type){case de.INIT:Hs(t,r);break;case de.FORWARD:Ws(t,r);break;case de.TERMINATE:js(t,r);break;case de.GLOBALS_SYNC:Xs(t);break}}}un()&&Ys();function Qs(r,e){return ee[r]||(ee[r]=e),[()=>ee[r],async t=>{ee[r]=t,await $s()}]}function qs(r,e){return Qs(r,e)}const[Ks]=qs("metadata");function er(){return Ks()}class Js{constructor(e){ks(this,"uuid",Ls()),this.config=e}async send(e){var t,n,i;const{appId:s,sourceType:o}=(t=er())!=null?t:{};if(!s||!o)return"metadata missing";const a=new AbortController,c=setTimeout(()=>a.abort(),Ds);return await((i=(n=this.config)==null?void 0:n.fetch)!=null?i:fetch)(this.getUrl(),{method:"POST",headers:this.getHeaders(),body:JSON.stringify(this.buildReport(e)),signal:a.signal}),clearTimeout(c),"success"}getUrl(){var e;let t=(e=er().proxyUrl)!=null?e:Bs;return t+=(t.at(-1)==="/"?"":"/")+Cs,t}getHeaders(){return{"Content-Type":"application/json"}}buildReport(e){const t=er();return{guid:this.uuid,...e,applicationId:t.appId,timestamp:Date.now(),proxyUrl:t.proxyUrl,source:t.sourceType}}}const Zs="7.0.0-alpha.3";var pt=(r=>(r.Low="Low",r.High="High",r))(pt||{}),tr=(r=>(r.FAST="FAST",r.PRECISE="PRECISE",r))(tr||{}),gt=(r=>(r.CANVAS="CANVAS",r.WEBGL="WEBGL",r))(gt||{});function eo(){const e=new OffscreenCanvas(0,0).getContext("webgl2",{failIfMajorPerformanceCaveat:!0});if(e){const t=e?.getExtension("WEBGL_lose_context");t&&t.loseContext()}else return{supported:!1,message:"Your hardware does not perform good enough to run the library efficiently"};return{supported:!0}}class rr{constructor(){const e=new OffscreenCanvas(0,0),t=e.getContext("2d",{willReadFrequently:!0});if(!t)throw"Fail to retrieve 2d context";this.canvas=e,this.context=t}enablePostProcessing(){}disablePostProcessing(){}async profileWebgl(e){return[]}async render(e,t){return this.canvas}resizeCanvas(e){const{width:t,height:n}=e;this.canvas.width=t,this.canvas.height=n}renderSilhouette(e,t,n="none"){const{width:i,height:s}=e;this.context.save(),this.context.drawImage(t,0,0,t.width,t.height,0,0,i,s),this.context.filter="blur(5px)",this.context.globalCompositeOperation="source-in",this.context.drawImage(t,0,0,t.width,t.height,0,0,i,s),this.context.globalCompositeOperation="source-in",this.context.filter=n,this.context.drawImage(e,0,0,i,s,0,0,this.canvas.width,this.canvas.height),this.context.restore()}destroy(){}}class to extends rr{constructor(e){super(),this.radius=e}async render(e,t){super.resizeCanvas(e);const n=await createImageBitmap(t);return this.renderSilhouette(e,n),this.context.save(),this.context.filter=`blur(${this.radius}px)`,this.context.globalCompositeOperation="destination-over",this.context.drawImage(e,0,0,e.width,e.height),this.context.restore(),super.render(e,t)}}class ro extends rr{constructor(e){super(),this.radius=e}async render(e,t){super.resizeCanvas(e);const n=await createImageBitmap(t);return this.renderSilhouette(e,n,`blur(${this.radius}px)`),this.context.save(),this.context.filter="none",this.context.globalCompositeOperation="destination-over",this.context.drawImage(e,0,0,e.width,e.height),this.context.restore(),super.render(e,t)}}class no extends rr{setBackgroundImage(e){this.backgroundImage=e}async render(e,t){super.resizeCanvas(e);const n=await createImageBitmap(t);return this.renderSilhouette(e,n),this.backgroundImage&&(this.context.save(),this.context.filter="none",this.context.globalCompositeOperation="destination-over",this.context.drawImage(this.backgroundImage,0,0,this.backgroundImage.width,this.backgroundImage.height,0,0,e.width,e.height),this.context.restore()),super.render(e,t)}}const nr=5120,Ne=5121,ir=5122,sr=5123,or=5124,ar=5125,cr=5126,io=32819,so=32820,oo=33635,ao=5131,co=33640,uo=35899,fo=35902,lo=36269,ho=34042,fn={};{const r=fn;r[nr]=Int8Array,r[Ne]=Uint8Array,r[ir]=Int16Array,r[sr]=Uint16Array,r[or]=Int32Array,r[ar]=Uint32Array,r[cr]=Float32Array,r[io]=Uint16Array,r[so]=Uint16Array,r[oo]=Uint16Array,r[ao]=Uint16Array,r[co]=Uint32Array,r[uo]=Uint32Array,r[fo]=Uint32Array,r[lo]=Uint32Array,r[ho]=Uint32Array}function ur(r){if(r instanceof Int8Array)return nr;if(r instanceof Uint8Array||r instanceof Uint8ClampedArray)return Ne;if(r instanceof Int16Array)return ir;if(r instanceof Uint16Array)return sr;if(r instanceof Int32Array)return or;if(r instanceof Uint32Array)return ar;if(r instanceof Float32Array)return cr;throw new Error("unsupported typed array type")}function ln(r){if(r===Int8Array)return nr;if(r===Uint8Array||r===Uint8ClampedArray)return Ne;if(r===Int16Array)return ir;if(r===Uint16Array)return sr;if(r===Int32Array)return or;if(r===Uint32Array)return ar;if(r===Float32Array)return cr;throw new Error("unsupported typed array type")}function dn(r){const e=fn[r];if(!e)throw new Error("unknown gl type");return e}const yt=typeof SharedArrayBuffer<"u"?function(e){return e&&e.buffer&&(e.buffer instanceof ArrayBuffer||e.buffer instanceof SharedArrayBuffer)}:function(e){return e&&e.buffer&&e.buffer instanceof ArrayBuffer};function hn(...r){console.error(...r)}const mn=new Map;function bt(r,e){if(!r||typeof r!="object")return!1;let t=mn.get(e);t||(t=new WeakMap,mn.set(e,t));let n=t.get(r);if(n===void 0){const i=Object.prototype.toString.call(r);n=i.substring(8,i.length-1)===e,t.set(r,n)}return n}function mo(r,e){return typeof WebGLBuffer<"u"&&bt(e,"WebGLBuffer")}function po(r,e){return typeof WebGLRenderbuffer<"u"&&bt(e,"WebGLRenderbuffer")}function fr(r,e){return typeof WebGLTexture<"u"&&bt(e,"WebGLTexture")}function go(r,e){return typeof WebGLSampler<"u"&&bt(e,"WebGLSampler")}const pn=35044,he=34962,yo=34963,bo=34660,xo=5120,_o=5121,Eo=5122,wo=5123,vo=5124,To=5125,gn=5126,yn={attribPrefix:""};function Ao(r,e,t,n,i){r.bindBuffer(e,t),r.bufferData(e,n,i||pn)}function bn(r,e,t,n){if(mo(r,e))return e;t=t||he;const i=r.createBuffer();return Ao(r,t,i,e,n),i}function xn(r){return r==="indices"}function Io(r){return r===Int8Array||r===Uint8Array}function So(r){return r.length?r:r.data}const Ro=/coord|texture/i,Fo=/color|colour/i;function Po(r,e){let t;if(Ro.test(r)?t=2:Fo.test(r)?t=4:t=3,e%t>0)throw new Error(`Can not guess numComponents for attribute \'${r}\'. Tried ${t} but ${e} values is not evenly divisible by ${t}. You should specify it.`);return t}function ko(r,e,t){return r.numComponents||r.size||Po(e,t||So(r).length)}function _n(r,e){if(yt(r))return r;if(yt(r.data))return r.data;Array.isArray(r)&&(r={data:r});let t=r.type?lr(r.type):void 0;return t||(xn(e)?t=Uint16Array:t=Float32Array),new t(r.data)}function Co(r){return typeof r=="number"?r:r?ln(r):gn}function lr(r){return typeof r=="number"?dn(r):r||Float32Array}function Bo(r,e){return{buffer:e.buffer,numValues:24,type:Co(e.type),arrayType:lr(e.type)}}function Do(r,e){const t=e.data||e,n=lr(e.type),i=t*n.BYTES_PER_ELEMENT,s=r.createBuffer();return r.bindBuffer(he,s),r.bufferData(he,i,e.drawType||pn),{buffer:s,numValues:t,type:ln(n),arrayType:n}}function Mo(r,e,t){const n=_n(e,t);return{arrayType:n.constructor,buffer:bn(r,n,void 0,e.drawType),type:ur(n),numValues:0}}function Oo(r,e){const t={};return Object.keys(e).forEach(function(n){if(!xn(n)){const i=e[n],s=i.attrib||i.name||i.attribName||yn.attribPrefix+n;if(i.value){if(!Array.isArray(i.value)&&!yt(i.value))throw new Error("array.value is not array or typedarray");t[s]={value:i.value}}else{let o;i.buffer&&i.buffer instanceof WebGLBuffer?o=Bo:typeof i=="number"||typeof i.data=="number"?o=Do:o=Mo;const{buffer:a,type:c,numValues:u,arrayType:d}=o(r,i,n),m=i.normalize!==void 0?i.normalize:Io(d),p=ko(i,n,u);t[s]={buffer:a,numComponents:p,type:c,normalize:m,stride:i.stride||0,offset:i.offset||0,divisor:i.divisor===void 0?void 0:i.divisor,drawType:i.drawType}}}}),r.bindBuffer(he,null),t}function Uo(r,e){return e===xo||e===_o?1:e===Eo||e===wo?2:e===vo||e===To||e===gn?4:0}const dr=["position","positions","a_position"];function No(r,e){let t,n;for(n=0;n<dr.length&&(t=dr[n],!(t in e||(t=yn.attribPrefix+t,t in e)));++n);n===dr.length&&(t=Object.keys(e)[0]);const i=e[t];if(!i.buffer)return 1;r.bindBuffer(he,i.buffer);const s=r.getBufferParameter(he,bo);r.bindBuffer(he,null);const o=Uo(r,i.type),a=s/o,c=i.numComponents||i.size,u=a/c;if(u%1!==0)throw new Error(`numComponents ${c} not correct for length ${length}`);return u}function Lo(r,e,t){const n=Oo(r,e),i=Object.assign({},t||{});i.attribs=Object.assign({},t?t.attribs:{},n);const s=e.indices;if(s){const o=_n(s,"indices");i.indices=bn(r,o,yo),i.numElements=o.length,i.elementType=ur(o)}else i.numElements||(i.numElements=No(r,i.attribs));return i}function Le(r){return!!r.texStorage2D}const En=(function(){const r={},e={};function t(n){const i=n.constructor.name;if(!r[i]){for(const s in n)if(typeof n[s]=="number"){const o=e[n[s]];e[n[s]]=o?`${o} | ${s}`:s}r[i]=!0}}return function(i,s){return t(i),e[s]||(typeof s=="number"?`0x${s.toString(16)}`:s)}})(),te={textureColor:new Uint8Array([128,192,255,255]),textureOptions:{},crossOrigin:void 0},ze=yt,wn=(function(){let r;return function(){return r=r||(typeof document<"u"&&document.createElement?document.createElement("canvas").getContext("2d"):null),r}})(),vn=6406,V=6407,A=6408,Tn=6409,An=6410,Ge=6402,In=34041,xt=33071,zo=9728,Go=9729,re=3553,ne=34067,me=32879,pe=35866,hr=34069,$o=34070,Wo=34071,Vo=34072,Ho=34073,jo=34074,mr=10241,pr=10240,_t=10242,Et=10243,Sn=32882,Xo=33082,Yo=33083,Qo=33084,qo=33085,Ko=34892,Jo=34893,gr=3317,Rn=3314,Fn=32878,Pn=3316,kn=3315,Cn=32877,Zo=37443,ea=37441,ta=37440,ra=33321,na=36756,ia=33325,sa=33326,oa=33330,aa=33329,ca=33338,ua=33337,fa=33340,la=33339,da=33323,ha=36757,ma=33327,pa=33328,ga=33336,ya=33335,ba=33332,xa=33331,_a=33334,Ea=33333,wa=32849,va=35905,Ta=36194,Aa=36758,Ia=35898,Sa=35901,Ra=34843,Fa=34837,Pa=36221,ka=36239,Ca=36215,Ba=36233,Da=36209,Ma=36227,Oa=32856,Ua=35907,Na=36759,La=32855,za=32854,Ga=32857,$a=34842,Wa=34836,Va=36220,Ha=36238,ja=36975,Xa=36214,Ya=36232,Qa=36226,qa=36208,Ka=33189,Ja=33190,Za=36012,ec=36013,tc=35056,ie=5120,T=5121,wt=5122,Se=5123,vt=5124,ge=5125,B=5126,Bn=32819,Dn=32820,Mn=33635,z=5131,$e=36193,yr=33640,rc=35899,nc=35902,ic=36269,sc=34042,Tt=33319,Re=33320,At=6403,Fe=36244,Pe=36248,ye=36249;let br;function It(r){if(!br){const e={};e[vn]={textureFormat:vn,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[1,2,2,4],type:[T,z,$e,B]},e[Tn]={textureFormat:Tn,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[1,2,2,4],type:[T,z,$e,B]},e[An]={textureFormat:An,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[2,4,4,8],type:[T,z,$e,B]},e[V]={textureFormat:V,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[3,6,6,12,2],type:[T,z,$e,B,Mn]},e[A]={textureFormat:A,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4,8,8,16,2,2],type:[T,z,$e,B,Bn,Dn]},e[Ge]={textureFormat:Ge,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2,4],type:[ge,Se]},e[ra]={textureFormat:At,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[1],type:[T]},e[na]={textureFormat:At,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[1],type:[ie]},e[ia]={textureFormat:At,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[4,2],type:[B,z]},e[sa]={textureFormat:At,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[4],type:[B]},e[oa]={textureFormat:Fe,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[1],type:[T]},e[aa]={textureFormat:Fe,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[1],type:[ie]},e[ba]={textureFormat:Fe,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[Se]},e[xa]={textureFormat:Fe,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[wt]},e[_a]={textureFormat:Fe,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[ge]},e[Ea]={textureFormat:Fe,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[vt]},e[da]={textureFormat:Tt,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[2],type:[T]},e[ha]={textureFormat:Tt,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[2],type:[ie]},e[ma]={textureFormat:Tt,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[8,4],type:[B,z]},e[pa]={textureFormat:Tt,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[8],type:[B]},e[ga]={textureFormat:Re,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[T]},e[ya]={textureFormat:Re,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[ie]},e[ca]={textureFormat:Re,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[Se]},e[ua]={textureFormat:Re,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[wt]},e[fa]={textureFormat:Re,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[ge]},e[la]={textureFormat:Re,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[vt]},e[wa]={textureFormat:V,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[3],type:[T]},e[va]={textureFormat:V,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[3],type:[T]},e[Ta]={textureFormat:V,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[3,2],type:[T,Mn]},e[Aa]={textureFormat:V,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[3],type:[ie]},e[Ia]={textureFormat:V,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[12,6,4],type:[B,z,rc]},e[Sa]={textureFormat:V,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[12,6,4],type:[B,z,nc]},e[Ra]={textureFormat:V,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[12,6],type:[B,z]},e[Fa]={textureFormat:V,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[12],type:[B]},e[Pa]={textureFormat:Pe,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[3],type:[T]},e[ka]={textureFormat:Pe,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[3],type:[ie]},e[Ca]={textureFormat:Pe,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[6],type:[Se]},e[Ba]={textureFormat:Pe,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[6],type:[wt]},e[Da]={textureFormat:Pe,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[12],type:[ge]},e[Ma]={textureFormat:Pe,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[12],type:[vt]},e[Oa]={textureFormat:A,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4],type:[T]},e[Ua]={textureFormat:A,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4],type:[T]},e[Na]={textureFormat:A,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[4],type:[ie]},e[La]={textureFormat:A,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4,2,4],type:[T,Dn,yr]},e[za]={textureFormat:A,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4,2],type:[T,Bn]},e[Ga]={textureFormat:A,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4],type:[yr]},e[$a]={textureFormat:A,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[16,8],type:[B,z]},e[Wa]={textureFormat:A,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[16],type:[B]},e[Va]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[T]},e[Ha]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[ie]},e[ja]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[yr]},e[Xa]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[Se]},e[Ya]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[wt]},e[Qa]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[16],type:[vt]},e[qa]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[16],type:[ge]},e[Ka]={textureFormat:Ge,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2,4],type:[Se,ge]},e[Ja]={textureFormat:Ge,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[ge]},e[Za]={textureFormat:Ge,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[B]},e[tc]={textureFormat:In,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[sc]},e[ec]={textureFormat:In,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[ic]},Object.keys(e).forEach(function(t){const n=e[t];n.bytesPerElementMap={},n.bytesPerElement.forEach(function(i,s){const o=n.type[s];n.bytesPerElementMap[o]=i})}),br=e}return br[r]}function oc(r,e){const t=It(r);if(!t)throw"unknown internal format";const n=t.bytesPerElementMap[e];if(n===void 0)throw"unknown internal format";return n}function We(r){const e=It(r);if(!e)throw"unknown internal format";return{format:e.textureFormat,type:e.type[0]}}function On(r){return(r&r-1)===0}function ac(r,e,t,n){if(!Le(r))return On(e)&&On(t);const i=It(n);if(!i)throw"unknown internal format";return i.colorRenderable&&i.textureFilterable}function cc(r){const e=It(r);if(!e)throw"unknown internal format";return e.textureFilterable}function uc(r,e,t){return ze(e)?ur(e):t||T}function St(r,e,t,n,i){if(i%1!==0)throw"can\'t guess dimensions";if(!t&&!n){const s=Math.sqrt(i/(e===ne?6:1));s%1===0?(t=s,n=s):(t=i,n=1)}else if(n){if(!t&&(t=i/n,t%1))throw"can\'t guess dimensions"}else if(n=i/t,n%1)throw"can\'t guess dimensions";return{width:t,height:n}}function ke(r,e){e.colorspaceConversion!==void 0&&r.pixelStorei(Zo,e.colorspaceConversion),e.premultiplyAlpha!==void 0&&r.pixelStorei(ea,e.premultiplyAlpha),e.flipY!==void 0&&r.pixelStorei(ta,e.flipY)}function Un(r){r.pixelStorei(gr,4),Le(r)&&(r.pixelStorei(Rn,0),r.pixelStorei(Fn,0),r.pixelStorei(Pn,0),r.pixelStorei(kn,0),r.pixelStorei(Cn,0))}function fc(r,e,t,n){n.minMag&&(t.call(r,e,mr,n.minMag),t.call(r,e,pr,n.minMag)),n.min&&t.call(r,e,mr,n.min),n.mag&&t.call(r,e,pr,n.mag),n.wrap&&(t.call(r,e,_t,n.wrap),t.call(r,e,Et,n.wrap),(e===me||go(r,e))&&t.call(r,e,Sn,n.wrap)),n.wrapR&&t.call(r,e,Sn,n.wrapR),n.wrapS&&t.call(r,e,_t,n.wrapS),n.wrapT&&t.call(r,e,Et,n.wrapT),n.minLod!==void 0&&t.call(r,e,Xo,n.minLod),n.maxLod!==void 0&&t.call(r,e,Yo,n.maxLod),n.baseLevel!==void 0&&t.call(r,e,Qo,n.baseLevel),n.maxLevel!==void 0&&t.call(r,e,qo,n.maxLevel),n.compareFunc!==void 0&&t.call(r,e,Jo,n.compareFunc),n.compareMode!==void 0&&t.call(r,e,Ko,n.compareMode)}function Nn(r,e,t){const n=t.target||re;r.bindTexture(n,e),fc(r,n,r.texParameteri,t)}function lc(r){return r=r||te.textureColor,ze(r)?r:new Uint8Array([r[0]*255,r[1]*255,r[2]*255,r[3]*255])}function xr(r,e,t,n,i,s){t=t||te.textureOptions,s=s||A;const o=t.target||re;if(n=n||t.width,i=i||t.height,r.bindTexture(o,e),ac(r,n,i,s))r.generateMipmap(o);else{const a=cc(s)?Go:zo;r.texParameteri(o,mr,a),r.texParameteri(o,pr,a),r.texParameteri(o,_t,xt),r.texParameteri(o,Et,xt)}}function Ve(r){return r.auto===!0||r.auto===void 0&&r.level===void 0}function _r(r,e){return e=e||{},e.cubeFaceOrder||[hr,$o,Wo,Vo,Ho,jo]}function Er(r,e){const n=_r(r,e).map(function(i,s){return{face:i,ndx:s}});return n.sort(function(i,s){return i.face-s.face}),n}function Ln(r,e,t,n){n=n||te.textureOptions;const i=n.target||re,s=n.level||0;let o=t.width,a=t.height;const c=n.internalFormat||n.format||A,u=We(c),d=n.format||u.format,m=n.type||u.type;if(ke(r,n),r.bindTexture(i,e),i===ne){const p=t.width,y=t.height;let l,b;if(p/6===y)l=y,b=[0,0,1,0,2,0,3,0,4,0,5,0];else if(y/6===p)l=p,b=[0,0,0,1,0,2,0,3,0,4,0,5];else if(p/3===y/2)l=p/3,b=[0,0,1,0,2,0,0,1,1,1,2,1];else if(p/2===y/3)l=p/2,b=[0,0,1,0,0,1,1,1,0,2,1,2];else throw"can\'t figure out cube map from element: "+(t.src?t.src:t.nodeName);const _=wn();_?(_.canvas.width=l,_.canvas.height=l,o=l,a=l,Er(r,n).forEach(function(E){const R=b[E.ndx*2+0]*l,k=b[E.ndx*2+1]*l;_.drawImage(t,R,k,l,l,0,0,l,l),r.texImage2D(E.face,s,c,d,m,_.canvas)}),_.canvas.width=1,_.canvas.height=1):typeof createImageBitmap<"u"&&(o=l,a=l,Er(r,n).forEach(function(E){const R=b[E.ndx*2+0]*l,k=b[E.ndx*2+1]*l;r.texImage2D(E.face,s,c,l,l,0,d,m,null),createImageBitmap(t,R,k,l,l,{premultiplyAlpha:"none",colorSpaceConversion:"none"}).then(function(N){ke(r,n),r.bindTexture(i,e),r.texImage2D(E.face,s,c,d,m,N),Ve(n)&&xr(r,e,n,o,a,c)})}))}else if(i===me||i===pe){const p=Math.min(t.width,t.height),y=Math.max(t.width,t.height),l=y/p;if(l%1!==0)throw"can not compute 3D dimensions of element";const b=t.width===y?1:0,_=t.height===y?1:0;r.pixelStorei(gr,1),r.pixelStorei(Rn,t.width),r.pixelStorei(Fn,0),r.pixelStorei(Cn,0),r.texImage3D(i,s,c,p,p,p,0,d,m,null);for(let E=0;E<l;++E){const R=E*p*b,k=E*p*_;r.pixelStorei(Pn,R),r.pixelStorei(kn,k),r.texSubImage3D(i,s,0,0,E,p,p,1,d,m,t)}Un(r)}else r.texImage2D(i,s,c,d,m,t);Ve(n)&&xr(r,e,n,o,a,c),Nn(r,e,n)}function He(){}function dc(r){if(typeof document<"u"){const e=document.createElement("a");return e.href=r,e.hostname===location.hostname&&e.port===location.port&&e.protocol===location.protocol}else{const e=new URL(location.href).origin;return new URL(r,location.href).origin===e}}function hc(r,e){return e===void 0&&!dc(r)?"anonymous":e}function mc(r,e,t){t=t||He;let n;if(e=e!==void 0?e:te.crossOrigin,e=hc(r,e),typeof Image<"u"){n=new Image,e!==void 0&&(n.crossOrigin=e);const i=function(){n.removeEventListener("error",s),n.removeEventListener("load",o),n=null},s=function(){const c="couldn\'t load image: "+r;hn(c),t(c,n),i()},o=function(){t(null,n),i()};return n.addEventListener("error",s),n.addEventListener("load",o),n.src=r,n}else if(typeof ImageBitmap<"u"){let i,s;const o=function(){t(i,s)},a={};e&&(a.mode="cors"),fetch(r,a).then(function(c){if(!c.ok)throw c;return c.blob()}).then(function(c){return createImageBitmap(c,{premultiplyAlpha:"none",colorSpaceConversion:"none"})}).then(function(c){s=c,setTimeout(o)}).catch(function(c){i=c,setTimeout(o)}),n=null}return n}function zn(r){return typeof ImageBitmap<"u"&&r instanceof ImageBitmap||typeof ImageData<"u"&&r instanceof ImageData||typeof HTMLElement<"u"&&r instanceof HTMLElement}function wr(r,e,t){return zn(r)?(setTimeout(function(){t(null,r)}),r):mc(r,e,t)}function vr(r,e,t){t=t||te.textureOptions;const n=t.target||re;if(r.bindTexture(n,e),t.color===!1)return;const i=lc(t.color);if(n===ne)for(let s=0;s<6;++s)r.texImage2D(hr+s,0,A,1,1,0,A,T,i);else n===me||n===pe?r.texImage3D(n,0,A,1,1,1,0,A,T,i):r.texImage2D(n,0,A,1,1,0,A,T,i)}function pc(r,e,t,n){return n=n||He,t=t||te.textureOptions,vr(r,e,t),t=Object.assign({},t),wr(t.src,t.crossOrigin,function(s,o){s?n(s,e,o):(Ln(r,e,o,t),n(null,e,o))})}function gc(r,e,t,n){n=n||He;const i=t.src;if(i.length!==6)throw"there must be 6 urls for a cubemap";const s=t.level||0,o=t.internalFormat||t.format||A,a=We(o),c=t.format||a.format,u=t.type||T,d=t.target||re;if(d!==ne)throw"target must be TEXTURE_CUBE_MAP";vr(r,e,t),t=Object.assign({},t);let m=6;const p=[],y=_r(r,t);let l;function b(_){return function(E,R){--m,E?p.push(E):R.width!==R.height?p.push("cubemap face img is not a square: "+R.src):(ke(r,t),r.bindTexture(d,e),m===5?_r().forEach(function(k){r.texImage2D(k,s,o,c,u,R)}):r.texImage2D(_,s,o,c,u,R),Ve(t)&&r.generateMipmap(d)),m===0&&n(p.length?p:void 0,e,l)}}l=i.map(function(_,E){return wr(_,t.crossOrigin,b(y[E]))})}function yc(r,e,t,n){n=n||He;const i=t.src,s=t.internalFormat||t.format||A,o=We(s),a=t.format||o.format,c=t.type||T,u=t.target||pe;if(u!==me&&u!==pe)throw"target must be TEXTURE_3D or TEXTURE_2D_ARRAY";vr(r,e,t),t=Object.assign({},t);let d=i.length;const m=[];let p;const y=t.level||0;let l=t.width,b=t.height;const _=i.length;let E=!0;function R(k){return function(N,Q){if(--d,N)m.push(N);else{if(ke(r,t),r.bindTexture(u,e),E){E=!1,l=t.width||Q.width,b=t.height||Q.height,r.texImage3D(u,y,s,l,b,_,0,a,c,null);for(let q=0;q<_;++q)r.texSubImage3D(u,y,0,0,q,l,b,1,a,c,Q)}else{let q=Q,L;(Q.width!==l||Q.height!==b)&&(L=wn(),q=L.canvas,L.canvas.width=l,L.canvas.height=b,L.drawImage(Q,0,0,l,b)),r.texSubImage3D(u,y,0,0,k,l,b,1,a,c,q),L&&q===L.canvas&&(L.canvas.width=0,L.canvas.height=0)}Ve(t)&&r.generateMipmap(u)}d===0&&n(m.length?m:void 0,e,p)}}p=i.map(function(k,N){return wr(k,t.crossOrigin,R(N))})}function bc(r,e,t,n){n=n||te.textureOptions;const i=n.target||re;r.bindTexture(i,e);let s=n.width,o=n.height,a=n.depth;const c=n.level||0,u=n.internalFormat||n.format||A,d=We(u),m=n.format||d.format,p=n.type||uc(r,t,d.type);if(ze(t))t instanceof Uint8ClampedArray&&(t=new Uint8Array(t.buffer));else{const _=dn(p);t=new _(t)}const y=oc(u,p),l=t.byteLength/y;if(l%1)throw"length wrong size for format: "+En(r,m);let b;if(i===me||i===pe)if(!s&&!o&&!a){const _=Math.cbrt(l);if(_%1!==0)throw"can\'t guess cube size of array of numElements: "+l;s=_,o=_,a=_}else s&&(!o||!a)?(b=St(r,i,o,a,l/s),o=b.width,a=b.height):o&&(!s||!a)?(b=St(r,i,s,a,l/o),s=b.width,a=b.height):(b=St(r,i,s,o,l/a),s=b.width,o=b.height);else b=St(r,i,s,o,l),s=b.width,o=b.height;if(Un(r),r.pixelStorei(gr,n.unpackAlignment||1),ke(r,n),i===ne){const _=y/t.BYTES_PER_ELEMENT,E=l/6*_;Er(r,n).forEach(R=>{const k=E*R.ndx,N=t.subarray(k,k+E);r.texImage2D(R.face,c,u,s,o,0,m,p,N)})}else i===me||i===pe?r.texImage3D(i,c,u,s,o,a,0,m,p,t):r.texImage2D(i,c,u,s,o,0,m,p,t);return{width:s,height:o,depth:a,type:p}}function xc(r,e,t){const n=t.target||re;r.bindTexture(n,e);const i=t.level||0,s=t.internalFormat||t.format||A,o=We(s),a=t.format||o.format,c=t.type||o.type;if(ke(r,t),n===ne)for(let u=0;u<6;++u)r.texImage2D(hr+u,i,s,t.width,t.height,0,a,c,null);else n===me||n===pe?r.texImage3D(n,i,s,t.width,t.height,t.depth,0,a,c,null):r.texImage2D(n,i,s,t.width,t.height,0,a,c,null)}function Gn(r,e,t){t=t||He,e=e||te.textureOptions;const n=r.createTexture(),i=e.target||re;let s=e.width||1,o=e.height||1;const a=e.internalFormat||A;r.bindTexture(i,n),i===ne&&(r.texParameteri(i,_t,xt),r.texParameteri(i,Et,xt));let c=e.src;if(c)if(typeof c=="function"&&(c=c(r,e)),typeof c=="string")pc(r,n,e,t);else if(ze(c)||Array.isArray(c)&&(typeof c[0]=="number"||Array.isArray(c[0])||ze(c[0]))){const u=bc(r,n,c,e);s=u.width,o=u.height}else Array.isArray(c)&&(typeof c[0]=="string"||zn(c[0]))?i===ne?gc(r,n,e,t):yc(r,n,e,t):(Ln(r,n,c,e),s=c.width,o=c.height);else xc(r,n,e);return Ve(e)&&xr(r,n,e,s,o,a),Nn(r,n,e),n}const Tr=hn;function $n(r){return typeof document<"u"&&document.getElementById?document.getElementById(r):null}const Rt=33984,Ft=34962,_c=34963,Ec=35713,wc=35714,vc=35632,Tc=35633,Ac=35981,Wn=35718,Ic=35721,Sc=35971,Rc=35382,Fc=35396,Pc=35398,kc=35392,Cc=35395,Pt=5126,Vn=35664,Hn=35665,jn=35666,Ar=5124,Xn=35667,Yn=35668,Qn=35669,qn=35670,Kn=35671,Jn=35672,Zn=35673,ei=35674,ti=35675,ri=35676,Bc=35678,Dc=35680,Mc=35679,Oc=35682,Uc=35685,Nc=35686,Lc=35687,zc=35688,Gc=35689,$c=35690,Wc=36289,Vc=36292,Hc=36293,Ir=5125,ni=36294,ii=36295,si=36296,jc=36298,Xc=36299,Yc=36300,Qc=36303,qc=36306,Kc=36307,Jc=36308,Zc=36311,kt=3553,Ct=34067,Sr=32879,Bt=35866,x={};function oi(r,e){return x[e].bindPoint}function eu(r,e){return function(t){r.uniform1f(e,t)}}function tu(r,e){return function(t){r.uniform1fv(e,t)}}function ru(r,e){return function(t){r.uniform2fv(e,t)}}function nu(r,e){return function(t){r.uniform3fv(e,t)}}function iu(r,e){return function(t){r.uniform4fv(e,t)}}function ai(r,e){return function(t){r.uniform1i(e,t)}}function ci(r,e){return function(t){r.uniform1iv(e,t)}}function ui(r,e){return function(t){r.uniform2iv(e,t)}}function fi(r,e){return function(t){r.uniform3iv(e,t)}}function li(r,e){return function(t){r.uniform4iv(e,t)}}function su(r,e){return function(t){r.uniform1ui(e,t)}}function ou(r,e){return function(t){r.uniform1uiv(e,t)}}function au(r,e){return function(t){r.uniform2uiv(e,t)}}function cu(r,e){return function(t){r.uniform3uiv(e,t)}}function uu(r,e){return function(t){r.uniform4uiv(e,t)}}function fu(r,e){return function(t){r.uniformMatrix2fv(e,!1,t)}}function lu(r,e){return function(t){r.uniformMatrix3fv(e,!1,t)}}function du(r,e){return function(t){r.uniformMatrix4fv(e,!1,t)}}function hu(r,e){return function(t){r.uniformMatrix2x3fv(e,!1,t)}}function mu(r,e){return function(t){r.uniformMatrix3x2fv(e,!1,t)}}function pu(r,e){return function(t){r.uniformMatrix2x4fv(e,!1,t)}}function gu(r,e){return function(t){r.uniformMatrix4x2fv(e,!1,t)}}function yu(r,e){return function(t){r.uniformMatrix3x4fv(e,!1,t)}}function bu(r,e){return function(t){r.uniformMatrix4x3fv(e,!1,t)}}function O(r,e,t,n){const i=oi(r,e);return Le(r)?function(s){let o,a;!s||fr(r,s)?(o=s,a=null):(o=s.texture,a=s.sampler),r.uniform1i(n,t),r.activeTexture(Rt+t),r.bindTexture(i,o),r.bindSampler(t,a)}:function(s){r.uniform1i(n,t),r.activeTexture(Rt+t),r.bindTexture(i,s)}}function U(r,e,t,n,i){const s=oi(r,e),o=new Int32Array(i);for(let a=0;a<i;++a)o[a]=t+a;return Le(r)?function(a){r.uniform1iv(n,o),a.forEach(function(c,u){r.activeTexture(Rt+o[u]);let d,m;!c||fr(r,c)?(d=c,m=null):(d=c.texture,m=c.sampler),r.bindSampler(t,m),r.bindTexture(s,d)})}:function(a){r.uniform1iv(n,o),a.forEach(function(c,u){r.activeTexture(Rt+o[u]),r.bindTexture(s,c)})}}x[Pt]={Type:Float32Array,size:4,setter:eu,arraySetter:tu},x[Vn]={Type:Float32Array,size:8,setter:ru,cols:2},x[Hn]={Type:Float32Array,size:12,setter:nu,cols:3},x[jn]={Type:Float32Array,size:16,setter:iu,cols:4},x[Ar]={Type:Int32Array,size:4,setter:ai,arraySetter:ci},x[Xn]={Type:Int32Array,size:8,setter:ui,cols:2},x[Yn]={Type:Int32Array,size:12,setter:fi,cols:3},x[Qn]={Type:Int32Array,size:16,setter:li,cols:4},x[Ir]={Type:Uint32Array,size:4,setter:su,arraySetter:ou},x[ni]={Type:Uint32Array,size:8,setter:au,cols:2},x[ii]={Type:Uint32Array,size:12,setter:cu,cols:3},x[si]={Type:Uint32Array,size:16,setter:uu,cols:4},x[qn]={Type:Uint32Array,size:4,setter:ai,arraySetter:ci},x[Kn]={Type:Uint32Array,size:8,setter:ui,cols:2},x[Jn]={Type:Uint32Array,size:12,setter:fi,cols:3},x[Zn]={Type:Uint32Array,size:16,setter:li,cols:4},x[ei]={Type:Float32Array,size:32,setter:fu,rows:2,cols:2},x[ti]={Type:Float32Array,size:48,setter:lu,rows:3,cols:3},x[ri]={Type:Float32Array,size:64,setter:du,rows:4,cols:4},x[Uc]={Type:Float32Array,size:32,setter:hu,rows:2,cols:3},x[Nc]={Type:Float32Array,size:32,setter:pu,rows:2,cols:4},x[Lc]={Type:Float32Array,size:48,setter:mu,rows:3,cols:2},x[zc]={Type:Float32Array,size:48,setter:yu,rows:3,cols:4},x[Gc]={Type:Float32Array,size:64,setter:gu,rows:4,cols:2},x[$c]={Type:Float32Array,size:64,setter:bu,rows:4,cols:3},x[Bc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:kt},x[Dc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Ct},x[Mc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Sr},x[Oc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:kt},x[Wc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Bt},x[Vc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Bt},x[Hc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Ct},x[jc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:kt},x[Xc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Sr},x[Yc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Ct},x[Qc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Bt},x[qc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:kt},x[Kc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Sr},x[Jc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Ct},x[Zc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Bt};function Dt(r,e){return function(t){if(t.value)switch(r.disableVertexAttribArray(e),t.value.length){case 4:r.vertexAttrib4fv(e,t.value);break;case 3:r.vertexAttrib3fv(e,t.value);break;case 2:r.vertexAttrib2fv(e,t.value);break;case 1:r.vertexAttrib1fv(e,t.value);break;default:throw new Error("the length of a float constant value must be between 1 and 4!")}else r.bindBuffer(Ft,t.buffer),r.enableVertexAttribArray(e),r.vertexAttribPointer(e,t.numComponents||t.size,t.type||Pt,t.normalize||!1,t.stride||0,t.offset||0),r.vertexAttribDivisor&&r.vertexAttribDivisor(e,t.divisor||0)}}function se(r,e){return function(t){if(t.value)if(r.disableVertexAttribArray(e),t.value.length===4)r.vertexAttrib4iv(e,t.value);else throw new Error("The length of an integer constant value must be 4!");else r.bindBuffer(Ft,t.buffer),r.enableVertexAttribArray(e),r.vertexAttribIPointer(e,t.numComponents||t.size,t.type||Ar,t.stride||0,t.offset||0),r.vertexAttribDivisor&&r.vertexAttribDivisor(e,t.divisor||0)}}function Mt(r,e){return function(t){if(t.value)if(r.disableVertexAttribArray(e),t.value.length===4)r.vertexAttrib4uiv(e,t.value);else throw new Error("The length of an unsigned integer constant value must be 4!");else r.bindBuffer(Ft,t.buffer),r.enableVertexAttribArray(e),r.vertexAttribIPointer(e,t.numComponents||t.size,t.type||Ir,t.stride||0,t.offset||0),r.vertexAttribDivisor&&r.vertexAttribDivisor(e,t.divisor||0)}}function Rr(r,e,t){const n=t.size,i=t.count;return function(s){r.bindBuffer(Ft,s.buffer);const o=s.size||s.numComponents||n,a=o/i,c=s.type||Pt,d=x[c].size*o,m=s.normalize||!1,p=s.offset||0,y=d/i;for(let l=0;l<i;++l)r.enableVertexAttribArray(e+l),r.vertexAttribPointer(e+l,a,c,m,d,p+y*l),r.vertexAttribDivisor&&r.vertexAttribDivisor(e+l,s.divisor||0)}}const I={};I[Pt]={size:4,setter:Dt},I[Vn]={size:8,setter:Dt},I[Hn]={size:12,setter:Dt},I[jn]={size:16,setter:Dt},I[Ar]={size:4,setter:se},I[Xn]={size:8,setter:se},I[Yn]={size:12,setter:se},I[Qn]={size:16,setter:se},I[Ir]={size:4,setter:Mt},I[ni]={size:8,setter:Mt},I[ii]={size:12,setter:Mt},I[si]={size:16,setter:Mt},I[qn]={size:4,setter:se},I[Kn]={size:8,setter:se},I[Jn]={size:12,setter:se},I[Zn]={size:16,setter:se},I[ei]={size:4,setter:Rr,count:2},I[ti]={size:9,setter:Rr,count:3},I[ri]={size:16,setter:Rr,count:4};const xu=/ERROR:\\s*\\d+:(\\d+)/gi;function _u(r,e="",t=0){const n=[...e.matchAll(xu)],i=new Map(n.map((s,o)=>{const a=parseInt(s[1]),c=n[o+1],u=c?c.index:e.length,d=e.substring(s.index,u);return[a-1,d]}));return r.split(`\n`).map((s,o)=>{const a=i.get(o);return`${o+1+t}: ${s}${a?`\n\n^^^ ${a}`:""}`}).join(`\n`)}const di=/^[ \\t]*\\n/;function hi(r){let e=0;return di.test(r)&&(e=1,r=r.replace(di,"")),{lineOffset:e,shaderSource:r}}function Eu(r,e){return r.errorCallback(e),r.callback&&setTimeout(()=>{r.callback(`${e}\n${r.errors.join(`\n`)}`)}),null}function wu(r,e,t,n){if(n=n||Tr,!r.getShaderParameter(t,Ec)){const s=r.getShaderInfoLog(t),{lineOffset:o,shaderSource:a}=hi(r.getShaderSource(t)),c=`${_u(a,s,o)}\nError compiling ${En(r,e)}: ${s}`;return n(c),c}return""}function Fr(r,e,t){let n,i,s;if(typeof e=="function"&&(t=e,e=void 0),typeof r=="function")t=r,r=void 0;else if(r&&!Array.isArray(r)){const u=r;t=u.errorCallback,r=u.attribLocations,n=u.transformFeedbackVaryings,i=u.transformFeedbackMode,s=u.callback}const o=t||Tr,a=[],c={errorCallback(u,...d){a.push(u),o(u,...d)},transformFeedbackVaryings:n,transformFeedbackMode:i,callback:s,errors:a};{let u={};Array.isArray(r)?r.forEach(function(d,m){u[d]=e?e[m]:m}):u=r||{},c.attribLocations=u}return c}const vu=["VERTEX_SHADER","FRAGMENT_SHADER"];function Tu(r,e){if(e.indexOf("frag")>=0)return vc;if(e.indexOf("vert")>=0)return Tc}function Au(r,e,t){const n=r.getAttachedShaders(e);for(const i of n)t.has(i)&&r.deleteShader(i);r.deleteProgram(e)}const Iu=(r=0)=>new Promise(e=>setTimeout(e,r));function Su(r,e,t){const n=r.createProgram(),{attribLocations:i,transformFeedbackVaryings:s,transformFeedbackMode:o}=Fr(t);for(let a=0;a<e.length;++a){let c=e[a];if(typeof c=="string"){const u=$n(c),d=u?u.text:c;let m=r[vu[a]];u&&u.type&&(m=Tu(r,u.type)||m),c=r.createShader(m),r.shaderSource(c,hi(d).shaderSource),r.compileShader(c),r.attachShader(n,c)}}Object.entries(i).forEach(([a,c])=>r.bindAttribLocation(n,c,a));{let a=s;a&&(a.attribs&&(a=a.attribs),Array.isArray(a)||(a=Object.keys(a)),r.transformFeedbackVaryings(n,a,o||Ac))}return r.linkProgram(n),n}function Ru(r,e,t,n,i){const s=Fr(t,n,i),o=new Set(e),a=Su(r,e,s);function c(u,d){const m=Pu(u,d,s.errorCallback);return m&&Au(u,d,o),m}if(s.callback){Fu(r,a).then(()=>{const u=c(r,a);s.callback(u,u?void 0:a)});return}return c(r,a)?void 0:a}async function Fu(r,e){const t=r.getExtension("KHR_parallel_shader_compile"),n=t?(s,o)=>s.getProgramParameter(o,t.COMPLETION_STATUS_KHR):()=>!0;let i=0;do await Iu(i),i=1e3/60;while(!n(r,e))}function Pu(r,e,t){if(t=t||Tr,!r.getProgramParameter(e,wc)){const i=r.getProgramInfoLog(e);t(`Error in program linking: ${i}`);const o=r.getAttachedShaders(e).map(a=>wu(r,r.getShaderParameter(a,r.SHADER_TYPE),a,t));return`${i}\n${o.filter(a=>a).join(`\n`)}`}}function ku(r,e,t,n,i){return Ru(r,e,t,n,i)}function mi(r){const e=r.name;return e.startsWith("gl_")||e.startsWith("webgl_")}const Cu=/(\\.|\\[|]|\\w+)/g,Bu=r=>r>="0"&&r<="9";function Du(r,e,t,n){const i=r.split(Cu).filter(a=>a!=="");let s=0,o="";for(;;){const a=i[s++];o+=a;const c=Bu(a[0]),u=c?parseInt(a):a;if(c&&(o+=i[s++]),s===i.length){t[u]=e;break}else{const m=i[s++],p=m==="[",y=t[u]||(p?[]:{});t[u]=y,t=y,n[o]=n[o]||(function(l){return function(b){pi(l,b)}})(y),o+=m}}}function Mu(r,e){let t=0;function n(a,c,u){const d=c.name.endsWith("[0]"),m=c.type,p=x[m];if(!p)throw new Error(`unknown type: 0x${m.toString(16)}`);let y;if(p.bindPoint){const l=t;t+=c.size,d?y=p.arraySetter(r,m,l,u,c.size):y=p.setter(r,m,l,u,c.size)}else p.arraySetter&&d?y=p.arraySetter(r,u):y=p.setter(r,u);return y.location=u,y}const i={},s={},o=r.getProgramParameter(e,Wn);for(let a=0;a<o;++a){const c=r.getActiveUniform(e,a);if(mi(c))continue;let u=c.name;u.endsWith("[0]")&&(u=u.substr(0,u.length-3));const d=r.getUniformLocation(e,c.name);if(d){const m=n(e,c,d);i[u]=m,Du(u,m,s,i)}}return i}function Ou(r,e){const t={},n=r.getProgramParameter(e,Sc);for(let i=0;i<n;++i){const s=r.getTransformFeedbackVarying(e,i);t[s.name]={index:i,type:s.type,size:s.size}}return t}function Uu(r,e){const t=r.getProgramParameter(e,Wn),n=[],i=[];for(let a=0;a<t;++a){i.push(a),n.push({});const c=r.getActiveUniform(e,a);n[a].name=c.name}[["UNIFORM_TYPE","type"],["UNIFORM_SIZE","size"],["UNIFORM_BLOCK_INDEX","blockNdx"],["UNIFORM_OFFSET","offset"]].forEach(function(a){const c=a[0],u=a[1];r.getActiveUniforms(e,i,r[c]).forEach(function(d,m){n[m][u]=d})});const s={},o=r.getProgramParameter(e,Rc);for(let a=0;a<o;++a){const c=r.getActiveUniformBlockName(e,a),u={index:r.getUniformBlockIndex(e,c),usedByVertexShader:r.getActiveUniformBlockParameter(e,a,Fc),usedByFragmentShader:r.getActiveUniformBlockParameter(e,a,Pc),size:r.getActiveUniformBlockParameter(e,a,kc),uniformIndices:r.getActiveUniformBlockParameter(e,a,Cc)};u.used=u.usedByVertexShader||u.usedByFragmentShader,s[c]=u}return{blockSpecs:s,uniformData:n}}function pi(r,e){for(const t in e){const n=r[t];typeof n=="function"?n(e[t]):pi(r[t],e[t])}}function gi(r,...e){const t=r.uniformSetters||r,n=e.length;for(let i=0;i<n;++i){const s=e[i];if(Array.isArray(s)){const o=s.length;for(let a=0;a<o;++a)gi(t,s[a])}else for(const o in s){const a=t[o];a&&a(s[o])}}}function Nu(r,e){const t={},n=r.getProgramParameter(e,Ic);for(let i=0;i<n;++i){const s=r.getActiveAttrib(e,i);if(mi(s))continue;const o=r.getAttribLocation(e,s.name),a=I[s.type],c=a.setter(r,o,a);c.location=o,t[s.name]=c}return t}function Lu(r,e){for(const t in e){const n=r[t];n&&n(e[t])}}function zu(r,e,t){t.vertexArrayObject?r.bindVertexArray(t.vertexArrayObject):(Lu(e.attribSetters||e,t.attribs),t.indices&&r.bindBuffer(_c,t.indices))}function yi(r,e){const t=Mu(r,e),n=Nu(r,e),i={program:e,uniformSetters:t,attribSetters:n};return Le(r)&&(i.uniformBlockSpec=Uu(r,e),i.transformFeedbackInfo=Ou(r,e)),i}const Gu=/\\s|{|}|;/;function $u(r,e,t,n,i){const s=Fr(t,n,i),o=[];if(e=e.map(function(u){if(!Gu.test(u)){const d=$n(u);if(d)u=d.text;else{const m=`no element with id: ${u}`;s.errorCallback(m),o.push(m)}}return u}),o.length)return Eu(s,"");const a=s.callback;a&&(s.callback=(u,d)=>{a(u,u?void 0:yi(r,d))});const c=ku(r,e,s);return c?yi(r,c):null}const Wu=4,bi=5123;function Vu(r,e,t,n,i,s){t=t===void 0?Wu:t;const o=e.indices,a=e.elementType,c=n===void 0?e.numElements:n;i=i===void 0?0:i,a||o?s!==void 0?r.drawElementsInstanced(t,c,a===void 0?bi:e.elementType,i,s):r.drawElements(t,c,a===void 0?bi:e.elementType,i):s!==void 0?r.drawArraysInstanced(t,i,c,s):r.drawArrays(t,i,c)}const xi=36160,Ot=36161,Hu=3553,ju=5121,Xu=6402,Yu=6408,Qu=33190,qu=36012,Ku=35056,Ju=36013,Zu=32854,ef=32855,tf=36194,_i=33189,Ei=6401,wi=36168,Pr=34041,kr=36064,Ut=36096,vi=36128,Cr=33306,Br=33071,Dr=9729,rf=[{format:Yu,type:ju,min:Dr,wrap:Br},{format:Pr}],G={};G[Pr]=Cr,G[Ei]=vi,G[wi]=vi,G[Xu]=Ut,G[_i]=Ut,G[Qu]=Ut,G[qu]=Ut,G[Ku]=Cr,G[Ju]=Cr;function nf(r,e){return G[r]||G[e]}const oe={};oe[Zu]=!0,oe[ef]=!0,oe[tf]=!0,oe[Pr]=!0,oe[_i]=!0,oe[Ei]=!0,oe[wi]=!0;function sf(r){return oe[r]}const of=32;function af(r){return r>=kr&&r<kr+of}function Ti(r,e,t,n){const i=xi,s=r.createFramebuffer();r.bindFramebuffer(i,s),t=t||r.drawingBufferWidth,n=n||r.drawingBufferHeight,e=e||rf;const o=[],a={framebuffer:s,attachments:[],width:t,height:n};return e.forEach(function(c,u){let d=c.attachment;const m=c.samples,p=c.format;let y=c.attachmentPoint||nf(p,c.internalFormat);if(y||(y=kr+u),af(y)&&o.push(y),!d)if(m!==void 0||sf(p))d=r.createRenderbuffer(),r.bindRenderbuffer(Ot,d),m>1?r.renderbufferStorageMultisample(Ot,m,p,t,n):r.renderbufferStorage(Ot,p,t,n);else{const l=Object.assign({},c);l.width=t,l.height=n,l.auto===void 0&&(l.auto=!1,l.min=l.min||l.minMag||Dr,l.mag=l.mag||l.minMag||Dr,l.wrapS=l.wrapS||l.wrap||Br,l.wrapT=l.wrapT||l.wrap||Br),d=Gn(r,l)}if(po(r,d))r.framebufferRenderbuffer(i,y,Ot,d);else if(fr(r,d))c.layer!==void 0?r.framebufferTextureLayer(i,y,d,c.level||0,c.layer):r.framebufferTexture2D(i,y,c.target||Hu,d,c.level||0);else throw new Error("unknown attachment type");a.attachments.push(d)}),r.drawBuffers&&r.drawBuffers(o),a}function cf(r,e,t){t=t||xi,e?(r.bindFramebuffer(t,e.framebuffer),r.viewport(0,0,e.width,e.height)):(r.bindFramebuffer(t,null),r.viewport(0,0,r.drawingBufferWidth,r.drawingBufferHeight))}function D(r,e){return()=>e instanceof WebGLTexture?e:Gn(r,{src:e,wrap:r.CLAMP_TO_EDGE})}const Ce=2;class je{constructor(e){this.id="_";const{context:t,width:n,height:i}=e;this.context=t,this.options=e;const s=this.buildDefines();this.programInfo=$u(this.context,[s+this.getVertexShader(),s+this.getFragmentShader()]),this.bufferInfo=Lo(this.context,this.getBuffers()),this.fbi=Ti(this.context,[{format:this.context.RGBA,type:this.context.UNSIGNED_BYTE,min:this.context.LINEAR,wrap:this.context.CLAMP_TO_EDGE}],n,i),this.output=this.fbi.attachments[0]}resizeOutput(e,t){this.fbi=Ti(this.context,[{format:this.context.RGBA,type:this.context.UNSIGNED_BYTE,min:this.context.LINEAR,wrap:this.context.CLAMP_TO_EDGE}],e,t),this.options.width=e,this.options.height=t,this.output=this.fbi.attachments[0]}getDefines(){return{}}getBuffers(){return{position:{numComponents:2,data:[-1,-1,-1,1,1,-1,1,1,-1,1,1,-1]},texture_coord:{numComponents:2,data:[0,0,0,1,1,0,1,1,0,1,1,0]}}}buildDefines(){let e="";const t=this.getDefines();for(let n in t)e+=`#define ${n} ${t[n].toFixed(1)}\n`;return e}run(e){this.profiler?.pushContext(`[${this.id}] PROG : ${this.constructor.name}`),this.profiler?.pushContext(`[${this.id}] UNIFORMS`);for(const i in e)typeof e[i]=="function"&&(this.profiler?.pushContext(`[${this.id}] UNI : ${i}`),e[i]=e[i](),this.profiler?.popContext(`[${this.id}] UNI : ${i}`));this.profiler?.popContext(`[${this.id}] UNIFORMS`);const t=Date.now();let n=0;this.lastRun&&(n=(t-this.lastRun)/1e3),this.lastRun=t,this.context.viewport(0,0,this.context.canvas.width,this.context.canvas.height),this.context.useProgram(this.programInfo.program),zu(this.context,this.programInfo,this.bufferInfo),gi(this.programInfo,{delta:n,canvas:[this.context.canvas.width,this.context.canvas.height],...e}),cf(this.context,this.options.disableFramebuffer?null:this.fbi),Vu(this.context,this.bufferInfo),this.profiler?.popContext(`[${this.id}] PROG : ${this.constructor.name}`)}setProfiler(e){this.profiler=e}}var uf=`precision mediump float;\n\nvarying vec2 _texture_coord;\n\nuniform sampler2D background;\nuniform sampler2D foreground;\nuniform sampler2D threshold;\n\nvoid main() {\n vec4 backgroundColor = texture2D(background, _texture_coord);\n vec4 foregroundColor = texture2D(foreground, _texture_coord);\n vec4 tresholdColor = texture2D(threshold, _texture_coord);\n gl_FragColor = foregroundColor * tresholdColor.a +\n backgroundColor * (1. - tresholdColor.a);\n}\n`,ff=`varying vec2 _texture_coord;\n\nattribute vec2 position;\nattribute vec2 texture_coord;\n\nvoid main() {\n gl_Position = vec4(position, 0., 1.);\n _texture_coord = texture_coord;\n _texture_coord.y = 1. - texture_coord.y;\n}\n`;class Mr extends je{getFragmentShader(){return uf}getVertexShader(){return ff}}class Or{constructor(){this.steps=[]}addStep(e){this.steps.push(e)}async run(){for(const e of this.steps)e.program.run(e.getUniforms())}resizeOutput(e,t){this.profiler?.pushContext(`PIP [${this.constructor.name}]`);for(const n of this.steps)n.preventResize||n.program.resizeOutput(e,t);this.profiler?.popContext(`PIP [${this.constructor.name}]`)}setProfiler(e){this.profiler=e;for(const t of this.steps)t.program.setProfiler(e)}setId(e){for(const t of this.steps)t.program.id=e}}class Ur extends Or{constructor(){super(...arguments),this.preciseMaskEnabled=!1}}class Ai extends Ur{constructor(e){super(),this.context=e,this.preciseMaskEnabled=!0;const t={context:e,height:e.canvas.height,width:e.canvas.width},n=new Mr({...t,disableFramebuffer:!0});this.addStep({program:n,getUniforms:()=>({background:D(e,this.inputBackgroundImage),foreground:D(e,this.inputImage),threshold:D(e,this.inputMask)})})}setData(e,t){this.inputImage=e,this.inputMask=t}}var lf=`precision mediump float;\n\nvarying vec2 _texture_coord;\nuniform sampler2D texture;\n\nvoid main() { gl_FragColor = texture2D(texture, _texture_coord); }\n`,df=`varying vec2 _texture_coord;\n\nattribute vec2 position;\nattribute vec2 texture_coord;\nuniform bool invert_y;\n\nvoid main() {\n gl_Position = vec4(position, 0., 1.);\n _texture_coord = texture_coord;\n if (invert_y) {\n _texture_coord.y = 1. - texture_coord.y;\n }\n}\n`;class hf extends je{getFragmentShader(){return lf}getVertexShader(){return df}}class mf extends Or{constructor(e,t,n){super(),this.context=e;const i={context:e,height:n,width:t};this.addStep({program:new hf({...i,disableFramebuffer:!0}),getUniforms:()=>({texture:D(e,this.inputImage),invert_y:!0})})}setData(e){this.inputImage=e}}async function Ii(r){return new Promise(e=>{setTimeout(()=>{e()},r)})}var pf=`precision mediump float;\n\nvarying vec2 _texture_coord;\n\nuniform vec2 canvas;\nuniform sampler2D texture;\n\nvec4 loop();\n\nvoid main() { gl_FragColor = loop(); }\n`,gf=`varying vec2 _texture_coord;\n\nattribute vec2 position;\nattribute vec2 texture_coord;\n\nvoid main() {\n gl_Position = vec4(position, 0., 1.);\n _texture_coord = texture_coord;\n}\n`,Nr=(r=>(r[r.LINEAR=0]="LINEAR",r[r.GAUSSIAN=1]="GAUSSIAN",r))(Nr||{});class Si extends je{getDefines(){return{RADIUS:this.options.radius??1}}getFragmentShader(){return pf+this.createLoopFunction()}getVertexShader(){return gf}createLoopFunction(){let e=this.options.radius??1;return`\n\n vec4 loop() { \n vec4 result = vec4(0,0,0,0);\n float factorSum = 0.;\n\n vec2 normalizedRadius = vec2(-${e}.) / canvas;\n vec2 normalizedIncrement = vec2(1.) / canvas;\n vec2 diff = normalizedRadius;\n\n for(int y=-${e}; y<${e+1}; ++y) {\n for(int x=-${e}; x<${e+1}; ++x) {\n float factor = 1.;\n result += factor * texture2D(texture, _texture_coord + diff);\n factorSum += factor;\n diff.x += normalizedIncrement.x;\n }\n diff.y += normalizedIncrement.y;\n diff.x = normalizedRadius.x;\n }\n return result / factorSum;\n }`}}var yf=`#version 300 es\n// https://github.com/Volcomix/virtual-background/blob/main/src/pipelines/webgl2/jointBilateralFilterStage.ts\n\nprecision highp float;\nuniform sampler2D input_frame;\nuniform sampler2D segmentation_mask;\nuniform sampler2D threshold;\nuniform vec2 texel_size;\nuniform float step;\nuniform float radius;\nuniform float offset;\nuniform float sigma_texel;\nuniform float sigma_color;\n\nin vec2 _texture_coord;\nout vec4 outColor;\n\nfloat gaussian(float x, float sigma) {\n float coeff = -0.5 / (sigma * sigma * 4.0 + 1.0e-6);\n return exp((x * x) * coeff);\n}\n\nvoid main() {\n vec2 centerCoord = _texture_coord;\n vec3 centerColor = texture(input_frame, centerCoord).rgb;\n float newVal = 0.0;\n float spaceWeight = 0.0;\n float colorWeight = 0.0;\n float totalWeight = 0.0;\n // Subsample kernel space.\n for (float i = -radius + offset; i <= radius; i += step) {\n for (float j = -radius + offset; j <= radius; j += step) {\n vec2 shift = vec2(j, i) * texel_size;\n vec2 coord = vec2(centerCoord + shift);\n vec3 frameColor = texture(input_frame, coord).rgb;\n float threshold = texture(threshold, coord).a;\n float outVal = texture(segmentation_mask, coord).a;\n\n spaceWeight = gaussian(distance(centerCoord, coord), sigma_texel);\n colorWeight = gaussian(distance(centerColor, frameColor), sigma_color);\n totalWeight += spaceWeight * colorWeight;\n newVal += spaceWeight * colorWeight * outVal * threshold;\n }\n }\n newVal /= totalWeight;\n outColor = vec4(vec3(0.), newVal);\n}`,bf=`#version 300 es\nin vec2 position;\nin vec2 texture_coord;\nout vec2 _texture_coord;\nvoid main() {\n gl_Position = vec4(position, 0.0, 1.0);\n _texture_coord = texture_coord;\n}`;class xf extends je{getFragmentShader(){return yf}getVertexShader(){return bf}}class _f extends Or{constructor(e,t,n){super(),this.context=e;const i={context:e,height:n,width:t},s=new Si({...i,radius:1,type:Nr.GAUSSIAN});this.jointBilateral=new xf(i),this.addStep({program:s,getUniforms:()=>({inputs:D(e,this.inputMask)})}),this.addStep({program:this.jointBilateral,getUniforms:()=>{const a=this.inputImage?.width??1,c=this.inputImage?.height??1;this.inputMask?.width,this.inputMask?.height;const u=3,d=Math.max(1,Math.sqrt(u)*.66),m=1/a,p=1/c;return{input_frame:D(e,this.inputImage),segmentation_mask:D(e,this.inputMask),texel_size:[m,p],step:d,radius:u,offset:d>1?d*.5:0,sigma_texel:Math.max(m,p)*u,sigma_color:u}}}),this.output=this.jointBilateral.output}setData(e,t){this.previousInputImage=this.inputImage?this.inputImage:e,this.previousInputMask=this.inputMask?this.inputMask:t,this.inputImage=e,this.inputMask=t}resizeOutput(e,t){super.resizeOutput(e,t),this.output=this.jointBilateral.output}}class Ef{constructor(e){this.queries=[],this.context=e,this.extension=e.getExtension("EXT_disjoint_timer_query_webgl2")}start(){}stop(){this.activeQuery&&this.context.endQuery(this.extension.TIME_ELAPSED_EXT)}pushContext(e){this.createQuery("PUSH",e)}popContext(e){this.createQuery("POP",e)}createQuery(e,t){this.activeQuery&&this.context.endQuery(this.extension.TIME_ELAPSED_EXT),this.activeQuery=this.context.createQuery(),this.context.beginQuery(this.extension.TIME_ELAPSED_EXT,this.activeQuery),this.queries.push({name:t,action:e,query:this.activeQuery})}async getResolvedQueries(){const e=(await Promise.all([...this.queries].map(t=>this.resolveQuery(t)))).filter(t=>t);for(let t=1;t<e.length;++t)e[t].timestamp+=e[t-1].duration+e[t-1].timestamp;return e}async resolveQuery(e){if(!await this.awaitQueryAvailable(e)){console.log("Unawaitable query",e);return}if(this.context.getParameter(this.extension.GPU_DISJOINT_EXT)){console.log("Disjointed query",e);return}return{...e,duration:this.context.getQueryParameter(e.query,this.context.QUERY_RESULT),timestamp:0}}async awaitQueryAvailable(e){for(let t=0;t<10;++t){if(this.context.getQueryParameter(e.query,this.context.QUERY_RESULT_AVAILABLE))return e;await Ii(200)}}}class Nt{constructor(){this.previousImageWidth=0,this.previousImageHeight=0,this.previousMaskWidth=Ce,this.previousMaskHeight=Ce,this.postProcessingEnabled=!0;const e=new OffscreenCanvas(0,0),t=e.getContext("webgl2");if(!t)throw"Fail to retrieve webgl2 context";this.canvas=e,this.context=t,this.improveMask=new _f(this.context,Ce,Ce)}enablePostProcessing(){this.postProcessingEnabled=!0}disablePostProcessing(){this.postProcessingEnabled=!1}async profileWebgl(e){const t=new Ef(this.context);return this.profiler=t,t.start(),await Ii(e),this.profiler=void 0,t.stop(),t.getResolvedQueries()}async render(e,t){if(!this.pipeline)throw"missing pipeline";(this.previousImageHeight!==e.height||this.previousImageWidth!==e.width)&&this.resizeOutput(e.width,e.height),(this.previousMaskHeight!==t.height||this.previousMaskWidth!==t.width)&&(this.improveMask.resizeOutput(t.width,t.height),this.previousMaskWidth=t.width,this.previousMaskHeight=t.height);const n="renderer";this.profiler?.pushContext(n),this.improveMask.setProfiler(this.profiler),this.pipeline.setProfiler(this.profiler);const i=await createImageBitmap(t);let s=i;return this.postProcessingEnabled&&(this.improveMask.setData(e,i),this.improveMask.run(),s=this.improveMask.output),this.pipeline.setData(e,s),await this.pipeline.run(),this.profiler?.popContext(n),this.canvas}resizeOutput(e,t){this.canvas.width=e,this.canvas.height=t,this.pipeline?.resizeOutput(e,t),this.previousImageWidth=e,this.previousImageHeight=t}destroy(){const e=this.context?.getExtension("WEBGL_lose_context");e&&e.loseContext()}}class Ri extends Nt{constructor(){super(),this.pipeline=new Ai(this.context);const e=new OffscreenCanvas(0,0),t=e.getContext("webgl2");if(!t)throw"Fail to retrieve webgl context";this.backgroundImageResizerCanvas=e,this.backgroundImageResizerContext=t,this.backgroundImageResizer=new mf(this.backgroundImageResizerContext,0,0)}setBackgroundImage(e){this.backgroundImage=e,this.updateBackgroundImage()}updateBackgroundImage(){const{width:e,height:t}=this.canvas;this.backgroundImageResizer.resizeOutput(e,t),this.backgroundImageResizer.setData(this.backgroundImage),this.backgroundImageResizer.run(),this.pipeline.inputBackgroundImage=this.backgroundImageResizerCanvas}resizeOutput(e,t){super.resizeOutput(e,t),this.backgroundImageResizerCanvas.width=e,this.backgroundImageResizerCanvas.height=t,this.backgroundImageResizer.resizeOutput(e,t),this.updateBackgroundImage()}destroy(){const e=this.backgroundImageResizerContext?.getExtension("WEBGL_lose_context");e&&e.loseContext(),super.destroy()}}class wf extends Ri{setBackgroundVideo(e){this.frameReader=e}async render(e,t){return await this.readNextVideoFrame(),super.render(e,t)}async readNextVideoFrame(){const e=await this.frameReader?.read();if(e?.value){const t=await createImageBitmap(e.value);this.setBackgroundImage(t),e.value.close()}}}class Fi{blurBackground(e){return new to(e)}blurSilhouette(e){return new ro(e)}imageBackground(){return new no}videoBackground(){return new wf}}var vf=`precision mediump float;\n\nvarying vec2 _texture_coord;\n\nuniform vec2 canvas;\nuniform sampler2D texture;\nuniform sampler2D mask;\n\nvec4 loop();\n\nvoid main() { gl_FragColor = loop(); }\n`,Tf=`varying vec2 _texture_coord;\n\nattribute vec2 position;\nattribute vec2 texture_coord;\n\nvoid main() {\n gl_Position = vec4(position, 0., 1.);\n _texture_coord = texture_coord;\n}\n`;class Af extends je{getDefines(){return{RADIUS:this.options.radius??1}}getFragmentShader(){return vf+this.createLoopFunction()}getVertexShader(){return Tf}createLoopFunction(){let e=this.options.radius??1;return`\n\n vec4 loop() { \n vec4 result = vec4(0,0,0,0);\n float factorSum = 0.;\n\n vec2 normalizedRadius = vec2(-${e}.) / canvas;\n vec2 normalizedIncrement = vec2(1.) / canvas;\n vec2 diff = normalizedRadius;\n float maxLength = length(normalizedRadius);\n\n for(int y=-${e}; y<${e+1}; ++y) {\n for(int x=-${e}; x<${e+1}; ++x) {\n float factor = (1.- texture2D(mask, _texture_coord + diff).a) * (maxLength - length(diff)) / maxLength;\n result += factor * texture2D(texture, _texture_coord + diff);\n factorSum += factor;\n diff.x += normalizedIncrement.x;\n }\n diff.y += normalizedIncrement.y;\n diff.x = normalizedRadius.x;\n }\n return result / factorSum;\n }`}}const If=10,Sf=2,Rf=8;class Ff extends Ur{constructor(e,t){super(),this.context=e,this.radius=t;const n={context:e,height:e.canvas.height,width:e.canvas.width};this.blur=new Af({...n,radius:t,...this.getBlurTextureSize(e.canvas.width,e.canvas.height)});const i=new Mr({...n,disableFramebuffer:!0});this.addStep({program:this.blur,preventResize:!0,getUniforms:()=>({texture:D(e,this.inputImage),mask:D(e,this.inputMask)})}),this.addStep({program:i,getUniforms:()=>({background:D(e,this.blur.output),foreground:D(e,this.inputImage),threshold:D(e,this.inputMask)})})}getBlurTextureSize(e,t){const n=this.radius>If?Rf:Sf;return{width:Math.max(Ce,e/n),height:Math.max(Ce,t/n)}}setData(e,t){this.inputImage=e,this.inputMask=t}resizeOutput(e,t){super.resizeOutput(e,t);const n=this.getBlurTextureSize(e,t);this.blur.resizeOutput(n.width,n.height)}}class Pf extends Nt{constructor(e){super(),this.pipeline=new Ff(this.context,e),this.disablePostProcessing()}}class kf extends Ur{constructor(e,t){super(),this.context=e;const n={context:e,height:e.canvas.height,width:e.canvas.width},i=new Si({...n,radius:t,type:Nr.GAUSSIAN}),s=new Mr({...n,disableFramebuffer:!0});this.addStep({program:i,getUniforms:()=>({texture:D(e,this.inputImage)})}),this.addStep({program:s,getUniforms:()=>({background:D(e,this.inputImage),foreground:D(e,i.output),threshold:D(e,this.inputMask)})})}setData(e,t){this.inputImage=e,this.inputMask=t}}class Cf extends Nt{constructor(e){super(),this.pipeline=new kf(this.context,e),this.disablePostProcessing()}}class Bf extends Ai{constructor(){super(...arguments),this.preciseMaskEnabled=!0}set reader(e){this.frameReader=e}async run(){this.frameReader&&(await this.readNextVideoFrame(),await super.run())}async readNextVideoFrame(){const e=await this.frameReader?.read();e?.value&&(this.inputBackgroundImage=await createImageBitmap(e.value),e.value.close())}}class Df extends Nt{constructor(){super(),this.pipeline=new Bf(this.context)}setBackgroundVideo(e){this.pipeline.reader=e}}class Pi{blurBackground(e){return new Pf(e)}blurSilhouette(e){return new Cf(e)}imageBackground(){return new Ri}videoBackground(){return new Df}}class Mf{constructor(e){switch(e){case gt.CANVAS:this.factory=new Fi;break;case gt.WEBGL:this.factory=new Pi;break;default:const t=eo();this.factory=t.supported?new Pi:new Fi}}blurBackground(e){return this.getFactory().blurBackground(e)}blurSilhouette(e){return this.getFactory().blurSilhouette(e)}imageBackground(){return this.getFactory().imageBackground()}videoBackground(){return this.getFactory().videoBackground()}getFactory(){if(!this.factory)throw"Factory is not initialized";return this.factory}}class Of{setBackgroundOptions(e){this.renderer&&this.renderer.destroy();const t=new Mf(e.renderingOptions?.type);switch(e.transformerType){case"BackgroundBlur":this.renderer=t.blurBackground(this.getBlurSize(e.radius));break;case"SilhouetteBlur":this.renderer=t.blurSilhouette(this.getBlurSize(e.radius));break;case"VideoBackground":const n=t.videoBackground();this.backgroundVideo&&n.setBackgroundVideo(this.backgroundVideo),this.renderer=n;break;case"VirtualBackground":const i=t.imageBackground();this.backgroundImage&&i.setBackgroundImage(this.backgroundImage),this.renderer=i;break;default:throw`Unknown rendering type [${e.transformerType}]`}e.renderingOptions?.type===gt.WEBGL&&(e.renderingOptions.selfieSegmentationType===tr.PRECISE?this.renderer.enablePostProcessing():e.renderingOptions.selfieSegmentationType===tr.FAST&&this.renderer.disablePostProcessing())}setVideoBGReadable(e){this.backgroundVideo=e.getReader();const t=this.renderer;t?.setBackgroundVideo&&t.setBackgroundVideo(this.backgroundVideo)}async setVirtualBGImage(e){const t=this.renderer;t?.setBackgroundImage&&t.setBackgroundImage(e),this.backgroundImage=e}async process(e,t){if(this.renderer)return this.renderer.render(e,t)}async resizeForeground(e,t){}getBlurSize(e=pt.Low){switch(e){case pt.Low:return 5;case pt.High:return 12}return e}async profile(e){return this.renderer?.profileWebgl(e)??[]}}var Uf=(function(){var r=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0;return(function(e){e=e||{};var t=typeof e<"u"?e:{},n,i;t.ready=new Promise(function(f,h){n=f,i=h});var s={},o;for(o in t)t.hasOwnProperty(o)&&(s[o]=t[o]);var a="./this.program",c=function(f,h){throw h},u=!0,d="";function m(f){return t.locateFile?t.locateFile(f,d):d+f}var p;typeof document<"u"&&document.currentScript&&(d=document.currentScript.src),r&&(d=r),d.indexOf("blob:")!==0?d=d.substr(0,d.replace(/[?#].*/,"").lastIndexOf("/")+1):d="";var y=t.print||console.log.bind(console),l=t.printErr||console.warn.bind(console);for(o in s)s.hasOwnProperty(o)&&(t[o]=s[o]);s=null,t.arguments&&t.arguments,t.thisProgram&&(a=t.thisProgram),t.quit&&(c=t.quit);var b;t.wasmBinary&&(b=t.wasmBinary),t.noExitRuntime,typeof WebAssembly!="object"&&ae("no native wasm support detected");var _,E=!1,R=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0;function k(f,h,g){for(var w=h+g,S=h;f[S]&&!(S>=w);)++S;if(S-h>16&&f.subarray&&R)return R.decode(f.subarray(h,S));for(var C="";h<S;){var v=f[h++];if(!(v&128)){C+=String.fromCharCode(v);continue}var M=f[h++]&63;if((v&224)==192){C+=String.fromCharCode((v&31)<<6|M);continue}var H=f[h++]&63;if((v&240)==224?v=(v&15)<<12|M<<6|H:v=(v&7)<<18|M<<12|H<<6|f[h++]&63,v<65536)C+=String.fromCharCode(v);else{var Li=v-65536;C+=String.fromCharCode(55296|Li>>10,56320|Li&1023)}}return C}function N(f,h){return f?k(Xe,f,h):""}function Q(f,h,g){for(var w=0;w<f.length;++w)Lt[h++>>0]=f.charCodeAt(w);Lt[h>>0]=0}function q(f,h){return f%h>0&&(f+=h-f%h),f}var L,Lt,Xe,$;function Ci(f){L=f,t.HEAP8=Lt=new Int8Array(f),t.HEAP16=new Int16Array(f),t.HEAP32=$=new Int32Array(f),t.HEAPU8=Xe=new Uint8Array(f),t.HEAPU16=new Uint16Array(f),t.HEAPU32=new Uint32Array(f),t.HEAPF32=new Float32Array(f),t.HEAPF64=new Float64Array(f)}t.INITIAL_MEMORY;var zr,Bi=[],Di=[],Mi=[];function Yf(){if(t.preRun)for(typeof t.preRun=="function"&&(t.preRun=[t.preRun]);t.preRun.length;)Kf(t.preRun.shift());Gr(Bi)}function Qf(){Gr(Di)}function qf(){if(t.postRun)for(typeof t.postRun=="function"&&(t.postRun=[t.postRun]);t.postRun.length;)Zf(t.postRun.shift());Gr(Mi)}function Kf(f){Bi.unshift(f)}function Jf(f){Di.unshift(f)}function Zf(f){Mi.unshift(f)}var be=0,Ye=null;function el(f){be++,t.monitorRunDependencies&&t.monitorRunDependencies(be)}function tl(f){if(be--,t.monitorRunDependencies&&t.monitorRunDependencies(be),be==0&&Ye){var h=Ye;Ye=null,h()}}t.preloadedImages={},t.preloadedAudios={};function ae(f){t.onAbort&&t.onAbort(f),f="Aborted("+f+")",l(f),E=!0,f+=". Build with -s ASSERTIONS=1 for more info.";var h=new WebAssembly.RuntimeError(f);throw i(h),h}var rl="data:application/octet-stream;base64,";function Oi(f){return f.startsWith(rl)}var W;W="tflite-simd.wasm",Oi(W)||(W=m(W));function Ui(f){try{if(f==W&&b)return new Uint8Array(b);if(!p)throw"both async and sync fetching of the wasm failed"}catch(h){ae(h)}}function nl(){return!b&&u&&typeof fetch=="function"?fetch(W,{credentials:"same-origin"}).then(function(f){if(!f.ok)throw"failed to load wasm binary file at \'"+W+"\'";return f.arrayBuffer()}).catch(function(){return Ui(W)}):Promise.resolve().then(function(){return Ui(W)})}function il(){var f={a:Al};function h(v,M){var H=v.exports;t.asm=H,_=t.asm.q,Ci(_.buffer),zr=t.asm.E,Jf(t.asm.r),tl()}el();function g(v){h(v.instance)}function w(v){return nl().then(function(M){return WebAssembly.instantiate(M,f)}).then(function(M){return M}).then(v,function(M){l("failed to asynchronously prepare wasm: "+M),ae(M)})}function S(){return!b&&typeof WebAssembly.instantiateStreaming=="function"&&!Oi(W)&&typeof fetch=="function"?fetch(W,{credentials:"same-origin"}).then(function(v){var M=WebAssembly.instantiateStreaming(v,f);return M.then(g,function(H){return l("wasm streaming compile failed: "+H),l("falling back to ArrayBuffer instantiation"),w(g)})}):w(g)}if(t.instantiateWasm)try{var C=t.instantiateWasm(f,h);return C}catch(v){return l("Module.instantiateWasm callback failed with error: "+v),!1}return S().catch(i),{}}function Gr(f){for(;f.length>0;){var h=f.shift();if(typeof h=="function"){h(t);continue}var g=h.func;typeof g=="number"?h.arg===void 0?zr.get(g)():zr.get(g)(h.arg):g(h.arg===void 0?null:h.arg)}}function sl(f,h,g,w){ae("Assertion failed: "+N(f)+", at: "+[h?N(h):"unknown filename",g,w?N(w):"unknown function"])}function ol(f,h){ae("To use dlopen, you need to use Emscripten\'s linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking")}function al(f,h){ae("To use dlopen, you need to use Emscripten\'s linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking")}function cl(){ae("")}var zt;zt=function(){return performance.now()};var ul=!0;function fl(f){return $[Ni()>>2]=f,f}function ll(f,h){var g;if(f===0)g=Date.now();else if((f===1||f===4)&&ul)g=zt();else return fl(28),-1;return $[h>>2]=g/1e3|0,$[h+4>>2]=g%1e3*1e3*1e3|0,0}function dl(){return 2147483648}function hl(f,h,g){Xe.copyWithin(f,h,h+g)}function ml(f){try{return _.grow(f-L.byteLength+65535>>>16),Ci(_.buffer),1}catch{}}function pl(f){var h=Xe.length;f=f>>>0;var g=2147483648;if(f>g)return!1;for(var w=1;w<=4;w*=2){var S=h*(1+.2/w);S=Math.min(S,f+100663296);var C=Math.min(g,q(Math.max(f,S),65536)),v=ml(C);if(v)return!0}return!1}function gl(f){for(var h=zt();zt()-h<f;);}var $r={};function yl(){return a||"./this.program"}function Qe(){if(!Qe.strings){var f=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",h={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:f,_:yl()};for(var g in $r)$r[g]===void 0?delete h[g]:h[g]=$r[g];var w=[];for(var g in h)w.push(g+"="+h[g]);Qe.strings=w}return Qe.strings}var Gt={mappings:{},buffers:[null,[],[]],printChar:function(f,h){var g=Gt.buffers[f];h===0||h===10?((f===1?y:l)(k(g,0)),g.length=0):g.push(h)},varargs:void 0,get:function(){Gt.varargs+=4;var f=$[Gt.varargs-4>>2];return f},getStr:function(f){var h=N(f);return h},get64:function(f,h){return f}};function bl(f,h){var g=0;return Qe().forEach(function(w,S){var C=h+g;$[f+S*4>>2]=C,Q(w,C),g+=w.length+1}),0}function xl(f,h){var g=Qe();$[f>>2]=g.length;var w=0;return g.forEach(function(S){w+=S.length+1}),$[h>>2]=w,0}function _l(f){Sl(f)}function El(f){return 0}function wl(f,h,g,w,S){}function vl(f,h,g,w){for(var S=0,C=0;C<g;C++){for(var v=$[h+C*8>>2],M=$[h+(C*8+4)>>2],H=0;H<M;H++)Gt.printChar(f,Xe[v+H]);S+=M}return $[w>>2]=S,0}function Tl(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var f=new Uint8Array(1);return function(){return crypto.getRandomValues(f),f[0]}}else return function(){ae("randomDevice")}}function $t(f,h){$t.randomDevice||($t.randomDevice=Tl());for(var g=0;g<h;g++)Lt[f+g>>0]=$t.randomDevice();return 0}var Al={a:sl,e:ol,d:al,b:cl,n:ll,h:dl,l:hl,m:pl,p:gl,f:bl,g:xl,j:_l,i:El,k:wl,c:vl,o:$t};il(),t.___wasm_call_ctors=function(){return(t.___wasm_call_ctors=t.asm.r).apply(null,arguments)},t._getModelBufferMemoryOffset=function(){return(t._getModelBufferMemoryOffset=t.asm.s).apply(null,arguments)},t._getInputMemoryOffset=function(){return(t._getInputMemoryOffset=t.asm.t).apply(null,arguments)},t._getInputHeight=function(){return(t._getInputHeight=t.asm.u).apply(null,arguments)},t._getInputWidth=function(){return(t._getInputWidth=t.asm.v).apply(null,arguments)},t._getInputChannelCount=function(){return(t._getInputChannelCount=t.asm.w).apply(null,arguments)},t._getOutputMemoryOffset=function(){return(t._getOutputMemoryOffset=t.asm.x).apply(null,arguments)},t._getOutputHeight=function(){return(t._getOutputHeight=t.asm.y).apply(null,arguments)},t._getOutputWidth=function(){return(t._getOutputWidth=t.asm.z).apply(null,arguments)},t._getOutputChannelCount=function(){return(t._getOutputChannelCount=t.asm.A).apply(null,arguments)},t._loadModel=function(){return(t._loadModel=t.asm.B).apply(null,arguments)},t._runInference=function(){return(t._runInference=t.asm.C).apply(null,arguments)},t._isGPUEnabled=function(){return(t._isGPUEnabled=t.asm.D).apply(null,arguments)};var Ni=t.___errno_location=function(){return(Ni=t.___errno_location=t.asm.F).apply(null,arguments)},Wt;function Il(f){this.name="ExitStatus",this.message="Program terminated with exit("+f+")",this.status=f}Ye=function f(){Wt||Wr(),Wt||(Ye=f)};function Wr(f){if(be>0||(Yf(),be>0))return;function h(){Wt||(Wt=!0,t.calledRun=!0,!E&&(Qf(),n(t),t.onRuntimeInitialized&&t.onRuntimeInitialized(),qf()))}t.setStatus?(t.setStatus("Running..."),setTimeout(function(){setTimeout(function(){t.setStatus("")},1),h()},1)):h()}t.run=Wr;function Sl(f,h){Rl(f)}function Rl(f){c(f,new Il(f))}if(t.preInit)for(typeof t.preInit=="function"&&(t.preInit=[t.preInit]);t.preInit.length>0;)t.preInit.pop()();return Wr(),e.ready})})();class Nf{constructor(){this.isSIMDSupported=!1,this.isThreadsSupported=!1,this.inputWidth=0,this.inputHeight=0,this.inputChannelCount=0,this.inputMemoryOffset=0,this.outputWidth=0,this.outputHeight=0,this.outputChannelCount=0,this.outputMemoryOffset=0}}const Lf="https://d3opqjmqzxf057.cloudfront.net/vonage-tensorflow-wasm/tflite-simd-wasm/1.1.3/",zf="https://d3opqjmqzxf057.cloudfront.net/ml/selfie_segmentation/4.0.0/selfie_segmentation_landscape.tflite";async function Gf(r=Lf,e=zf){let t=new Nf;var n=new Promise(function(i,s){async function o(){return Uf({locateFile:function(u){return r+u}})}async function a(c){return new Promise(async(u,d)=>{const m=c;if(typeof m>"u")return d("TFLite backend unavailable: wasmSimd");let p=e;console.log("TFLite modelUrl: "+p);try{const l=await(await fetch(p)).arrayBuffer();console.log("Model buffer size:",l.byteLength);const b=m._getModelBufferMemoryOffset();console.log("Model buffer memory offset:",b),console.log("Loading model buffer..."),m.HEAPU8.set(new Uint8Array(l),b);const _=m._loadModel(l.byteLength);if(console.log("Load model result:",_),_!==0){d("Cannot load model");return}t.inputWidth=m._getInputWidth(),t.inputHeight=m._getInputHeight(),t.inputChannelCount=m._getInputChannelCount(),t.inputMemoryOffset=m._getInputMemoryOffset(),console.log("Input memory offset:",t.inputMemoryOffset),console.log("Input height:",t.inputHeight),console.log("Input width:",t.inputWidth),console.log("Input channels:",t.inputChannelCount),t.outputMemoryOffset=m._getOutputMemoryOffset(),t.outputWidth=m._getOutputWidth(),t.outputHeight=m._getOutputHeight(),t.outputChannelCount=m._getOutputChannelCount(),console.log("Output memory offset:",t.outputMemoryOffset),console.log("Output height:",t.outputHeight),console.log("Output width:",t.outputWidth),console.log("Output channels:",t.outputChannelCount),t.selectedTFLite=m}catch(y){d(y);return}u()})}o().then(c=>{if(c===null)throw console.error("loadTFLite null"),"loadTFLite null";a(c).then(u=>{i(t)}).catch(u=>{console.error("loadTFLiteModel error"),s("loadTFLiteModel error")})}).catch(c=>{console.error("loadTFLite error:",c),s("loadTFLite error:"+c)})});return n}const $f=.1,Wf=.7,Vf="https://d3opqjmqzxf057.cloudfront.net/ml/vonage_selfie_segmenter/float16/v1/vonage_selfie_segmenter.tflite";class Hf{constructor(){this.canvas=new OffscreenCanvas(0,0),this.context=this.canvas.getContext("2d",{willReadFrequently:!0}),this.width=0,this.height=0,this.gpuDelegate=!0}async createImageSegmenter(){if(!this.ImageSegmenter||!this.wasmFileset){console.warn("Mediapipe objects not loaded");return}this.imageSegmenter=await this.ImageSegmenter.createFromOptions(this.wasmFileset,{baseOptions:{modelAssetPath:this.modelAssetUriPath,delegate:this.gpuDelegate?"GPU":"CPU"},runningMode:"VIDEO",outputCategoryMask:!0,outputConfidenceMasks:!0})}async loadMediapipeAssets(e,t){this.modelAssetUriPath=e||Vf;const n=t?`${t}/task-vision.js`:"https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.20/+esm",i=t?`${t}/wasm`:"https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.20/wasm",{FilesetResolver:s,ImageSegmenter:o}=await import(n);this.ImageSegmenter=o,this.wasmFileset=await s.forVisionTasks(i)}async init(e,t,n){n===!1&&(this.gpuDelegate=!1),await this.loadMediapipeAssets(e,t),globalThis.document={},await this.createImageSegmenter()}async process(e){if(!this.imageSegmenter){console.warn("ImageSegmenter instance not available");return}(this.width!==e.width||this.height!==e.height)&&(this.canvas.width=this.width=e.width,this.canvas.height=this.height=e.height,this.mask&&(this.mask=new ImageData(this.width,this.height))),this.mask||(this.mask=new ImageData(this.width,this.height)),this.context.drawImage(e,0,0,e.width,e.height);const t=Date.now();let n;try{this.imageSegmenter?.segmentForVideo(this.context.getImageData(0,0,e.width,e.height),t,o=>{n=o.confidenceMasks?.[0]?.getAsFloat32Array()})}catch{await this.createImageSegmenter();return}if(!n)return;if(!this.previousConfidenceMask){this.previousConfidenceMask=n.slice();return}const i=n.map((o,a)=>{const c=this.previousConfidenceMask?.[a];return c!==void 0?this.blend(c,o):o}),s=[255,0,0];for(let o=0;o<i?.length;o++){const a=1-i[o];a>$f?(a<Wf?(this.mask.data[o*4]=s[0]*a,this.mask.data[o*4+3]=255*a):(this.mask.data[o*4]=s[0],this.mask.data[o*4+3]=255),this.mask.data[o*4+1]=s[1],this.mask.data[o*4+2]=s[2]):this.mask.data[o*4]=this.mask.data[o*4+1]=this.mask.data[o*4+2]=this.mask.data[o*4+3]=0}return this.previousConfidenceMask=i.slice(),this.mask}isGpuSupported(){return!0}blend(e,t){const i=-.748699,s=-57.8051,o=291.309,a=-624.717,c=t-.5,u=c*c,d=1-Math.min(1,u*(5.68842+u*(i+u*(s+u*(o+u*a)))));return t+(e-t)*(d*.9)}}class jf{constructor(){this.canvas=new OffscreenCanvas(0,0),this.context=this.canvas.getContext("2d",{willReadFrequently:!0}),this.pixelCount=0,this.inputOffset=0,this.outputOffset=0}async init(e,t,n){await this.initWasm(t,e),this.infos&&(this.canvas.width=this.infos.inputWidth,this.canvas.height=this.infos.inputHeight,this.pixelCount=this.infos.inputWidth*this.infos.inputHeight,this.mask=new ImageData(this.infos.inputWidth,this.infos.inputHeight),this.inputOffset=this.infos.inputMemoryOffset/4,this.outputOffset=this.infos.outputMemoryOffset/4)}async initWasm(e,t){this.infos=await Gf(e,t)}async process(e){if(!this.mask||!this.infos)return;const t=this.infos.inputWidth,n=this.infos.inputHeight;this.context.drawImage(e,0,0,e.width,e.height,0,0,t,n);const i=this.context.getImageData(0,0,t,n),s=this.infos.selectedTFLite.HEAPF32;for(let o=0;o<this.pixelCount;o++){const a=this.inputOffset+o*3;s[a]=i.data[o*4]/255,s[a+1]=i.data[o*4+1]/255,s[a+2]=i.data[o*4+2]/255}this.infos.selectedTFLite._runInference();for(let o=0;o<this.pixelCount;o++){const a=this.infos.selectedTFLite.HEAPF32[this.outputOffset+o];this.mask.data[o*4]=this.mask.data[o*4+3]=255*a}return this.mask}isGpuSupported(){return this.infos?.selectedTFLite?._isGPUEnabled()??!1}}class Xf{constructor(){this.reporter=new Js,this.isEnabled=!0}async init(e,t){t.segmentationOptions?.lightWeightEngine===!0?this.selfieSegmentation=new jf:this.selfieSegmentation=new Hf,this.selfieSegmentation?.init(t.modelAssetUriPath,t.mediapipeBaseAssetsUri,t.segmentationOptions?.gpuSupport),this.backgroundFilter=new Of,this.report({variation:"Create"})}async transform(e,t){if(!this.isEnabled)return t.enqueue(e);let n;const i=e.timestamp??0,s=await createImageBitmap(e),o=await this.selfieSegmentation?.process(s);o&&(n=await this.backgroundFilter?.process(s,o)),n?(e.close(),t.enqueue(new VideoFrame(n,{timestamp:i,alpha:"discard"}))):t.enqueue(e)}async setBackgroundOptions(e){this.backgroundOptions=e,this.backgroundFilter?.setBackgroundOptions(e),this.report({variation:"Update"})}setVideoBGReadable(e){this.backgroundFilter?.setVideoBGReadable(e)}async setVirtualBGImage(e){await this.backgroundFilter?.setVirtualBGImage(e)}async profile(e){return this.backgroundFilter?.profile(e)??[]}getTransformerType(){return this.backgroundOptions?.transformerType??"Undefined"}enable(){this.isEnabled=!0}disable(){this.isEnabled=!1}report(e){this.reporter.send({version:Zs,action:"MlTransformers",transformerType:this.backgroundOptions?.transformerType,config:JSON.stringify(this.backgroundOptions),...e})}}const Lr=class Lr{constructor(){this.backgroundTransformer=new Xf,this.mediaProcessor=new Rs,this.rate=30,this.eventsQueue=[],this.frameTransformLatencyMs=[]}async init(e,t){this.frameTransformLatencyMs=[],await this.backgroundTransformer.init(e,t),await this.mediaProcessor.setTransformers([this.backgroundTransformer]),this.mediaProcessor.setTrackExpectedRate(this.rate),this.mediaProcessor.onAny((n,i)=>{this.resolveOnMediaProcessor?(this.resolveOnMediaProcessor({name:n,data:i}),this.resolveOnMediaProcessor=void 0):this.eventsQueue.push({name:n,data:i})})}enable(){this.backgroundTransformer.enable()}disable(){this.backgroundTransformer.disable()}async onMediaProcessorEvent(){return await new Promise(e=>{this.eventsQueue.length>0?e(this.eventsQueue.shift()):this.resolveOnMediaProcessor=e})}async setTrackExpectedRate(e){this.rate=e,this.mediaProcessor.setTrackExpectedRate(e)}async transform(e,t){let n=this.mediaProcessor.transform(e,t),i=performance.now();return this.frameTransformLatencyMs.push(performance.now()-i),n}async setBackgroundOptions(e){await this.backgroundTransformer?.setBackgroundOptions(e)}setVideoBGReadable(e){this.backgroundTransformer.setVideoBGReadable(e)}async setVirtualBGImage(e){await this.backgroundTransformer.setVirtualBGImage(e)}async terminate(){await this.mediaProcessor.destroy();const t=this.frameTransformLatencyMs.reduce((n,i)=>n+i,0)/this.frameTransformLatencyMs.length||0;console.log(`Transform latency average is: ${t} ms`)}setVonageMetadata(e){_s(e)}async profile(e){return JSON.stringify(await this.backgroundTransformer.profile(e))}};Vi("ProcessorWorker",Lr);let ki=Lr})();\n//# sourceMappingURL=processor-worker-CR7IjkAn.js.map\n', ii = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", _o], { type: "text/javascript;charset=utf-8" });
5146
- function Pd(r) {
5149
+ const _o = '(function(){"use strict";function Vt(r,e){globalThis.vonage||(globalThis.vonage={}),globalThis.vonage.workerizer||(globalThis.vonage.workerizer={});let t=globalThis.vonage.workerizer;return t[r]||(t[r]=e),t[r]}const Vr=Vt("globals",{});var xe=(r=>(r.INIT="INIT",r.FORWARD="FORWARD",r.TERMINATE="TERMINATE",r.GLOBALS_SYNC="GLOBALS_SYNC",r.EVENT="EVENT",r))(xe||{});function zi(r){return[ImageBitmap,ReadableStream,WritableStream].some(t=>r instanceof t)}function Be(r,e){const{id:t,type:n}=r,i=Array.isArray(e)?e:[e];postMessage({id:t,type:n,result:e},i.filter(s=>zi(s)))}Vt("workerized",{});function Hr(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function qe(r,e){if(Array.isArray(e))e.splice(0,e.length);else if(typeof e=="object")for(const t in e)delete e[t];for(const t in r)Array.isArray(r[t])?(e[t]=[],qe(r[t],e[t])):typeof r[t]=="object"?(e[t]={},qe(r[t],e[t])):e[t]=r[t]}const K=new WeakMap,ce=new WeakMap,j=new WeakMap,Ke=Symbol("anyProducer"),jr=Promise.resolve(),Je=Symbol("listenerAdded"),Ze=Symbol("listenerRemoved");let et=!1,Ht=!1;function _e(r){if(typeof r!="string"&&typeof r!="symbol"&&typeof r!="number")throw new TypeError("`eventName` must be a string, symbol, or number")}function tt(r){if(typeof r!="function")throw new TypeError("listener must be a function")}function Ee(r,e){const t=ce.get(r);if(t.has(e))return t.get(e)}function De(r,e){const t=typeof e=="string"||typeof e=="symbol"||typeof e=="number"?e:Ke,n=j.get(r);if(n.has(t))return n.get(t)}function Gi(r,e,t){const n=j.get(r);if(n.has(e))for(const i of n.get(e))i.enqueue(t);if(n.has(Ke)){const i=Promise.all([e,t]);for(const s of n.get(Ke))s.enqueue(i)}}function Xr(r,e){e=Array.isArray(e)?e:[e];let t=!1,n=()=>{},i=[];const s={enqueue(o){i.push(o),n()},finish(){t=!0,n()}};for(const o of e){let a=De(r,o);a||(a=new Set,j.get(r).set(o,a)),a.add(s)}return{async next(){return i?i.length===0?t?(i=void 0,this.next()):(await new Promise(o=>{n=o}),this.next()):{done:!1,value:await i.shift()}:{done:!0}},async return(o){i=void 0;for(const a of e){const c=De(r,a);c&&(c.delete(s),c.size===0&&j.get(r).delete(a))}return n(),arguments.length>0?{done:!0,value:await o}:{done:!0}},[Symbol.asyncIterator](){return this}}}function Yr(r){if(r===void 0)return Qr;if(!Array.isArray(r))throw new TypeError("`methodNames` must be an array of strings");for(const e of r)if(!Qr.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return r}const we=r=>r===Je||r===Ze;function rt(r,e,t){if(we(e))try{et=!0,r.emit(e,t)}finally{et=!1}}class ve{static mixin(e,t){return t=Yr(t),n=>{if(typeof n!="function")throw new TypeError("`target` must be function");for(const o of t)if(n.prototype[o]!==void 0)throw new Error(`The property \\`${o}\\` already exists on \\`target\\``);function i(){return Object.defineProperty(this,e,{enumerable:!1,value:new ve}),this[e]}Object.defineProperty(n.prototype,e,{enumerable:!1,get:i});const s=o=>function(...a){return this[e][o](...a)};for(const o of t)Object.defineProperty(n.prototype,o,{enumerable:!1,value:s(o)});return n}}static get isDebugEnabled(){var e,t;if(typeof((e=globalThis.process)==null?void 0:e.env)!="object")return Ht;const{env:n}=(t=globalThis.process)!=null?t:{env:{}};return n.DEBUG==="emittery"||n.DEBUG==="*"||Ht}static set isDebugEnabled(e){Ht=e}constructor(e={}){var t;K.set(this,new Set),ce.set(this,new Map),j.set(this,new Map),j.get(this).set(Ke,new Set),this.debug=(t=e.debug)!=null?t:{},this.debug.enabled===void 0&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(n,i,s,o)=>{try{o=JSON.stringify(o)}catch{o=`Object with the following keys failed to stringify: ${Object.keys(o).join(",")}`}(typeof s=="symbol"||typeof s=="number")&&(s=s.toString());const a=new Date,c=`${a.getHours()}:${a.getMinutes()}:${a.getSeconds()}.${a.getMilliseconds()}`;console.log(`[${c}][emittery:${n}][${i}] Event Name: ${s}\n data: ${o}`)})}logIfDebugEnabled(e,t,n){(ve.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,t,n)}on(e,t){tt(t),e=Array.isArray(e)?e:[e];for(const n of e){_e(n);let i=Ee(this,n);i||(i=new Set,ce.get(this).set(n,i)),i.add(t),this.logIfDebugEnabled("subscribe",n,void 0),we(n)||rt(this,Je,{eventName:n,listener:t})}return this.off.bind(this,e,t)}off(e,t){tt(t),e=Array.isArray(e)?e:[e];for(const n of e){_e(n);const i=Ee(this,n);i&&(i.delete(t),i.size===0&&ce.get(this).delete(n)),this.logIfDebugEnabled("unsubscribe",n,void 0),we(n)||rt(this,Ze,{eventName:n,listener:t})}}once(e){let t;const n=new Promise(i=>{t=this.on(e,s=>{t(),i(s)})});return n.off=t,n}events(e){e=Array.isArray(e)?e:[e];for(const t of e)_e(t);return Xr(this,e)}async emit(e,t){var n;if(_e(e),we(e)&&!et)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emit",e,t),Gi(this,e,t);const i=(n=Ee(this,e))!=null?n:new Set,s=K.get(this),o=[...i],a=we(e)?[]:[...s];await jr,await Promise.all([...o.map(async c=>{if(i.has(c))return c(t)}),...a.map(async c=>{if(s.has(c))return c(e,t)})])}async emitSerial(e,t){var n;if(_e(e),we(e)&&!et)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emitSerial",e,t);const i=(n=Ee(this,e))!=null?n:new Set,s=K.get(this),o=[...i],a=[...s];await jr;for(const c of o)i.has(c)&&await c(t);for(const c of a)s.has(c)&&await c(e,t)}onAny(e){return tt(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),K.get(this).add(e),rt(this,Je,{listener:e}),this.offAny.bind(this,e)}anyEvent(){return Xr(this)}offAny(e){tt(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),rt(this,Ze,{listener:e}),K.get(this).delete(e)}clearListeners(e){e=Array.isArray(e)?e:[e];for(const t of e)if(this.logIfDebugEnabled("clear",t,void 0),typeof t=="string"||typeof t=="symbol"||typeof t=="number"){const n=Ee(this,t);n&&n.clear();const i=De(this,t);if(i){for(const s of i)s.finish();i.clear()}}else{K.get(this).clear();for(const[n,i]of ce.get(this).entries())i.clear(),ce.get(this).delete(n);for(const[n,i]of j.get(this).entries()){for(const s of i)s.finish();i.clear(),j.get(this).delete(n)}}}listenerCount(e){var t,n,i,s,o,a;e=Array.isArray(e)?e:[e];let c=0;for(const u of e){if(typeof u=="string"){c+=K.get(this).size+((n=(t=Ee(this,u))==null?void 0:t.size)!=null?n:0)+((s=(i=De(this,u))==null?void 0:i.size)!=null?s:0)+((a=(o=De(this))==null?void 0:o.size)!=null?a:0);continue}typeof u<"u"&&_e(u),c+=K.get(this).size;for(const d of ce.get(this).values())c+=d.size;for(const d of j.get(this).values())c+=d.size}return c}bindMethods(e,t){if(typeof e!="object"||e===null)throw new TypeError("`target` must be an object");t=Yr(t);for(const n of t){if(e[n]!==void 0)throw new Error(`The property \\`${n}\\` already exists on \\`target\\``);Object.defineProperty(e,n,{enumerable:!1,value:this[n].bind(this)})}}}const Qr=Object.getOwnPropertyNames(ve.prototype).filter(r=>r!=="constructor");Object.defineProperty(ve,"listenerAdded",{value:Je,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(ve,"listenerRemoved",{value:Ze,writable:!1,enumerable:!0,configurable:!1});function $i(r){return r.onAny&&r.emit}async function Wi(r,e){const{functionName:t,args:n}=r;if(!e.instance)throw"instance not initialized";if(!t)throw"missing function name to call";if(!e.instance[t])throw`undefined function [${t}] in class ${e.instance.constructor.workerId}`;Be(r,await e.instance[t](...n??[]))}const qr=Vt("registeredWorkers",{});function Vi(r,e){e.workerId=r,Hr()&&(qr[e.workerId]=e)}function Hi(r,e){if(!r.args)throw"Missing className while initializing worker";const[t,n]=r.args,i=qr[t];if(i)e.instance=new i(r.args.slice(1));else throw`unknown worker class ${t}`;qe(n,Vr),$i(e.instance)&&e.instance.onAny((s,o)=>{Be({type:xe.EVENT},{name:s,data:o})}),Be(r,typeof e.instance!==void 0)}async function ji(r,e){const{args:t}=r;if(!e.instance)throw"instance not initialized";let n;e.instance.terminate&&(n=await e.instance.terminate(...t??[])),Be(r,n)}function Xi(r){if(!r.args)throw"Missing globals while syncing";qe(r.args[0],Vr),Be(r,{})}function Yi(){const r={};onmessage=async e=>{const t=e.data;switch(t.type){case xe.INIT:Hi(t,r);break;case xe.FORWARD:Wi(t,r);break;case xe.TERMINATE:ji(t,r);break;case xe.GLOBALS_SYNC:Xi(t);break}}}Hr()&&Yi();const J=new WeakMap,ue=new WeakMap,X=new WeakMap,nt=Symbol("anyProducer"),Kr=Promise.resolve(),it=Symbol("listenerAdded"),st=Symbol("listenerRemoved");let ot=!1,jt=!1;const at=r=>typeof r=="string"||typeof r=="symbol"||typeof r=="number";function Te(r){if(!at(r))throw new TypeError("`eventName` must be a string, symbol, or number")}function ct(r){if(typeof r!="function")throw new TypeError("listener must be a function")}function Ae(r,e){const t=ue.get(r);if(t.has(e))return t.get(e)}function Me(r,e){const t=at(e)?e:nt,n=X.get(r);if(n.has(t))return n.get(t)}function Qi(r,e,t){const n=X.get(r);if(n.has(e))for(const i of n.get(e))i.enqueue(t);if(n.has(nt)){const i=Promise.all([e,t]);for(const s of n.get(nt))s.enqueue(i)}}function Jr(r,e){e=Array.isArray(e)?e:[e];let t=!1,n=()=>{},i=[];const s={enqueue(o){i.push(o),n()},finish(){t=!0,n()}};for(const o of e){let a=Me(r,o);a||(a=new Set,X.get(r).set(o,a)),a.add(s)}return{async next(){return i?i.length===0?t?(i=void 0,this.next()):(await new Promise(o=>{n=o}),this.next()):{done:!1,value:await i.shift()}:{done:!0}},async return(o){i=void 0;for(const a of e){const c=Me(r,a);c&&(c.delete(s),c.size===0&&X.get(r).delete(a))}return n(),arguments.length>0?{done:!0,value:await o}:{done:!0}},[Symbol.asyncIterator](){return this}}}function Zr(r){if(r===void 0)return en;if(!Array.isArray(r))throw new TypeError("`methodNames` must be an array of strings");for(const e of r)if(!en.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return r}const Ie=r=>r===it||r===st;function ut(r,e,t){if(Ie(e))try{ot=!0,r.emit(e,t)}finally{ot=!1}}class Y{static mixin(e,t){return t=Zr(t),n=>{if(typeof n!="function")throw new TypeError("`target` must be function");for(const o of t)if(n.prototype[o]!==void 0)throw new Error(`The property \\`${o}\\` already exists on \\`target\\``);function i(){return Object.defineProperty(this,e,{enumerable:!1,value:new Y}),this[e]}Object.defineProperty(n.prototype,e,{enumerable:!1,get:i});const s=o=>function(...a){return this[e][o](...a)};for(const o of t)Object.defineProperty(n.prototype,o,{enumerable:!1,value:s(o)});return n}}static get isDebugEnabled(){if(typeof globalThis.process?.env!="object")return jt;const{env:e}=globalThis.process??{env:{}};return e.DEBUG==="emittery"||e.DEBUG==="*"||jt}static set isDebugEnabled(e){jt=e}constructor(e={}){J.set(this,new Set),ue.set(this,new Map),X.set(this,new Map),X.get(this).set(nt,new Set),this.debug=e.debug??{},this.debug.enabled===void 0&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(t,n,i,s)=>{try{s=JSON.stringify(s)}catch{s=`Object with the following keys failed to stringify: ${Object.keys(s).join(",")}`}(typeof i=="symbol"||typeof i=="number")&&(i=i.toString());const o=new Date,a=`${o.getHours()}:${o.getMinutes()}:${o.getSeconds()}.${o.getMilliseconds()}`;console.log(`[${a}][emittery:${t}][${n}] Event Name: ${i}\n data: ${s}`)})}logIfDebugEnabled(e,t,n){(Y.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,t,n)}on(e,t,{signal:n}={}){ct(t),e=Array.isArray(e)?e:[e];for(const s of e){Te(s);let o=Ae(this,s);o||(o=new Set,ue.get(this).set(s,o)),o.add(t),this.logIfDebugEnabled("subscribe",s,void 0),Ie(s)||ut(this,it,{eventName:s,listener:t})}const i=()=>{this.off(e,t),n?.removeEventListener("abort",i)};return n?.addEventListener("abort",i,{once:!0}),n?.aborted&&i(),i}off(e,t){ct(t),e=Array.isArray(e)?e:[e];for(const n of e){Te(n);const i=Ae(this,n);i&&(i.delete(t),i.size===0&&ue.get(this).delete(n)),this.logIfDebugEnabled("unsubscribe",n,void 0),Ie(n)||ut(this,st,{eventName:n,listener:t})}}once(e,t){if(t!==void 0&&typeof t!="function")throw new TypeError("predicate must be a function");let n;const i=new Promise(s=>{n=this.on(e,o=>{t&&!t(o)||(n(),s(o))})});return i.off=n,i}events(e){e=Array.isArray(e)?e:[e];for(const t of e)Te(t);return Jr(this,e)}async emit(e,t){if(Te(e),Ie(e)&&!ot)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emit",e,t),Qi(this,e,t);const n=Ae(this,e)??new Set,i=J.get(this),s=[...n],o=Ie(e)?[]:[...i];await Kr,await Promise.all([...s.map(async a=>{if(n.has(a))return a(t)}),...o.map(async a=>{if(i.has(a))return a(e,t)})])}async emitSerial(e,t){if(Te(e),Ie(e)&&!ot)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emitSerial",e,t);const n=Ae(this,e)??new Set,i=J.get(this),s=[...n],o=[...i];await Kr;for(const a of s)n.has(a)&&await a(t);for(const a of o)i.has(a)&&await a(e,t)}onAny(e,{signal:t}={}){ct(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),J.get(this).add(e),ut(this,it,{listener:e});const n=()=>{this.offAny(e),t?.removeEventListener("abort",n)};return t?.addEventListener("abort",n,{once:!0}),t?.aborted&&n(),n}anyEvent(){return Jr(this)}offAny(e){ct(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),ut(this,st,{listener:e}),J.get(this).delete(e)}clearListeners(e){e=Array.isArray(e)?e:[e];for(const t of e)if(this.logIfDebugEnabled("clear",t,void 0),at(t)){const n=Ae(this,t);n&&n.clear();const i=Me(this,t);if(i){for(const s of i)s.finish();i.clear()}}else{J.get(this).clear();for(const[n,i]of ue.get(this).entries())i.clear(),ue.get(this).delete(n);for(const[n,i]of X.get(this).entries()){for(const s of i)s.finish();i.clear(),X.get(this).delete(n)}}}listenerCount(e){e=Array.isArray(e)?e:[e];let t=0;for(const n of e){if(at(n)){t+=J.get(this).size+(Ae(this,n)?.size??0)+(Me(this,n)?.size??0)+(Me(this)?.size??0);continue}n!==void 0&&Te(n),t+=J.get(this).size;for(const i of ue.get(this).values())t+=i.size;for(const i of X.get(this).values())t+=i.size}return t}bindMethods(e,t){if(typeof e!="object"||e===null)throw new TypeError("`target` must be an object");t=Zr(t);for(const n of t){if(e[n]!==void 0)throw new Error(`The property \\`${n}\\` already exists on \\`target\\``);Object.defineProperty(e,n,{enumerable:!1,value:this[n].bind(this)})}}}const en=Object.getOwnPropertyNames(Y.prototype).filter(r=>r!=="constructor");Object.defineProperty(Y,"listenerAdded",{value:it,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(Y,"listenerRemoved",{value:st,writable:!1,enumerable:!0,configurable:!1});var qi=Object.defineProperty,Ki=(r,e,t)=>e in r?qi(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Ji=(r,e,t)=>(Ki(r,e+"",t),t);const Zi="hlg.tokbox.com/prod/logging/vcp_webrtc",es="https://",ts=1e4;let ft;const rs=new Uint8Array(16);function ns(){if(!ft&&(ft=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ft))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ft(rs)}const F=[];for(let r=0;r<256;++r)F.push((r+256).toString(16).slice(1));function is(r,e=0){return(F[r[e+0]]+F[r[e+1]]+F[r[e+2]]+F[r[e+3]]+"-"+F[r[e+4]]+F[r[e+5]]+"-"+F[r[e+6]]+F[r[e+7]]+"-"+F[r[e+8]]+F[r[e+9]]+"-"+F[r[e+10]]+F[r[e+11]]+F[r[e+12]]+F[r[e+13]]+F[r[e+14]]+F[r[e+15]]).toLowerCase()}const ss=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),tn={randomUUID:ss};function os(r,e,t){if(tn.randomUUID&&!r)return tn.randomUUID();r=r||{};const n=r.random||(r.rng||ns)();return n[6]=n[6]&15|64,n[8]=n[8]&63|128,is(n)}function Xt(r,e){globalThis.vonage||(globalThis.vonage={}),globalThis.vonage.workerizer||(globalThis.vonage.workerizer={});let t=globalThis.vonage.workerizer;return t[r]||(t[r]=e),t[r]}const Z=Xt("globals",{});var fe=(r=>(r.INIT="INIT",r.FORWARD="FORWARD",r.TERMINATE="TERMINATE",r.GLOBALS_SYNC="GLOBALS_SYNC",r))(fe||{});function rn(r){return[ImageBitmap,ReadableStream,WritableStream].some(e=>r instanceof e)}let as=0;function cs(r,e,t,n,i){const s=as++;return r.postMessage({id:s,type:e,functionName:t,args:n},n.filter(o=>rn(o))),new Promise(o=>{i?.set(s,o)})}function Oe(r,e){const{id:t,type:n}=r,i=Array.isArray(e)?e:[e];postMessage({id:t,type:n,result:e},i.filter(s=>rn(s)))}const nn=Xt("workerized",{});function sn(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}async function us(){if(sn())Oe({type:fe.GLOBALS_SYNC},Z);else{const r=[];for(const e in nn){const{worker:t,resolvers:n}=nn[e].workerContext;t&&r.push(cs(t,fe.GLOBALS_SYNC,"",[Z],n))}await Promise.all(r)}}function lt(r,e){if(Array.isArray(e))e.splice(0,e.length);else if(typeof e=="object")for(const t in e)delete e[t];for(const t in r)Array.isArray(r[t])?(e[t]=[],lt(r[t],e[t])):typeof r[t]=="object"?(e[t]={},lt(r[t],e[t])):e[t]=r[t]}async function fs(r,e){const{functionName:t,args:n}=r;if(!e.instance)throw"instance not initialized";if(!t)throw"missing function name to call";if(!e.instance[t])throw`undefined function [${t}] in class ${e.instance.constructor.workerId}`;Oe(r,await e.instance[t](...n??[]))}const ls=Xt("registeredWorkers",{});function ds(r,e){if(!r.args)throw"Missing className while initializing worker";const[t,n]=r.args,i=ls[t];if(i)e.instance=new i(r.args.slice(1));else throw`unknown worker class ${t}`;lt(n,Z),Oe(r,typeof e.instance!==void 0)}async function hs(r,e){const{args:t}=r;if(!e.instance)throw"instance not initialized";let n;e.instance.terminate&&(n=await e.instance.terminate(...t??[])),Oe(r,n)}function ms(r){if(!r.args)throw"Missing globals while syncing";lt(r.args[0],Z),Oe(r,{})}function ps(){const r={};onmessage=async e=>{const t=e.data;switch(t.type){case fe.INIT:ds(t,r);break;case fe.FORWARD:fs(t,r);break;case fe.TERMINATE:hs(t,r);break;case fe.GLOBALS_SYNC:ms(t);break}}}sn()&&ps();function gs(r,e){return Z[r]||(Z[r]=e),[()=>Z[r],async t=>{Z[r]=t,await us()}]}function ys(r,e){return gs(r,e)}const[bs,xs]=ys("metadata");function _s(r){xs(r)}function Yt(){return bs()}let Qt=class{constructor(e,t){Ji(this,"uuid"),this.config=e,this.uuid=t??os()}async send(e){var t,n,i;const{appId:s,sourceType:o}=(t=Yt())!=null?t:{};if(!s||!o)return"metadata missing";const a=new AbortController,c=setTimeout(()=>a.abort(),ts);return await((i=(n=this.config)==null?void 0:n.fetch)!=null?i:fetch)(this.getUrl(),{method:"POST",headers:this.getHeaders(),body:JSON.stringify(this.buildReport(e)),signal:a.signal}),clearTimeout(c),"success"}getUrl(){var e;let t=(e=Yt().proxyUrl)!=null?e:es;return t+=(t.at(-1)==="/"?"":"/")+Zi,t}getHeaders(){return{"Content-Type":"application/json"}}buildReport(e){const t=Yt();return{guid:this.uuid,...e,applicationId:t.appId,timestamp:Date.now(),proxyUrl:t.proxyUrl,source:t.sourceType}}};const dt="3.0.1",qt=class{};qt.updates={transformer_new:"New transformer",transformer_null:"Null transformer"},qt.errors={transformer_none:"No transformers provided",transformer_start:"Cannot start transformer",transformer_transform:"Cannot transform frame",transformer_flush:"Cannot flush transformer",readable_null:"Readable is null",writable_null:"Writable is null"};let le=qt;function Es(r){return typeof r=="object"&&r!==null&&"message"in r&&typeof r.message=="string"}function ws(r){if(Es(r))return r;try{return new Error(JSON.stringify(r))}catch{return new Error(String(r))}}function Kt(r){return ws(r).message}class vs{constructor(e,t){this.config=e,this.frameTransformedCount=0,this.frameFromSourceCount=0,this.startAt=0,this.reporter=new Qt(e,t)}async onFrameFromSource(){this.frameFromSourceCount++}get fps(){const{startAt:e,frameFromSourceCount:t}=this,n=(Date.now()-e)/1e3;return t/n}async onFrameTransformed(e={},t=!1){this.startAt===0&&(this.startAt=Date.now()),this.frameTransformedCount++;const{startAt:n,frameTransformedCount:i,frameFromSourceCount:s}=this,o=Date.now(),a=(o-n)/1e3,c=i/a,u=s/a;return t||this.frameTransformedCount>=this.config.loggingIntervalFrameCount?(this.frameFromSourceCount=0,this.frameTransformedCount=0,this.startAt=o,this.reporter.config=this.config,this.reporter.send({...this.config.report,variation:"QoS",fps:u,transformedFps:c,framesTransformed:i,...e})):"success"}}var Jt=(r=>(r.pipeline_ended="pipeline_ended",r.pipeline_ended_with_error="pipeline_ended_with_error",r.pipeline_started="pipeline_started",r.pipeline_started_with_error="pipeline_started_with_error",r.pipeline_restarted="pipeline_restarted",r.pipeline_restarted_with_error="pipeline_restarted_with_error",r))(Jt||{});const Ts=500,As=.8;class Is extends Y{constructor(e,t){super(),this.reporter_=new Qt,this.reporterQos_=new vs({loggingIntervalFrameCount:Ts,report:{version:dt}}),this.index_=t,this.transformer_=e,this.shouldStop_=!1,this.isFlashed_=!1,this.mediaTransformerQosReportStartTimestamp_=0,this.videoHeight_=0,this.videoWidth_=0,this.trackExpectedRate_=-1,this.transformerType_="Custom","getTransformerType"in e&&(this.transformerType_=e.getTransformerType()),this.report({variation:"Create"})}setTrackExpectedRate(e){this.trackExpectedRate_=e}async start(e){if(this.controller_=e,this.transformer_&&typeof this.transformer_.start=="function")try{await this.transformer_.start(e)}catch(t){this.report({message:le.errors.transformer_start,variation:"Error",error:Kt(t)});const n={eventMetaData:{transformerIndex:this.index_},error:t,function:"start"};this.emit("error",n)}}async transform(e,t){if(this.mediaTransformerQosReportStartTimestamp_===0&&(this.mediaTransformerQosReportStartTimestamp_=Date.now()),e instanceof VideoFrame&&(this.videoHeight_=e?.displayHeight??0,this.videoWidth_=e?.displayWidth??0),this.reporterQos_.onFrameFromSource(),this.transformer_)if(this.shouldStop_)console.warn("[Pipeline] flush from transform"),e.close(),this.flush(t),t.terminate();else{try{await this.transformer_.transform?.(e,t),this.reportQos()}catch(n){this.report({message:le.errors.transformer_transform,variation:"Error",error:Kt(n)});const i={eventMetaData:{transformerIndex:this.index_},error:n,function:"transform"};this.emit("error",i)}if(this.trackExpectedRate_!=-1&&this.trackExpectedRate_*As>this.reporterQos_.fps){const n={eventMetaData:{transformerIndex:this.index_},warningType:"fps_drop",dropInfo:{requested:this.trackExpectedRate_,current:this.reporterQos_.fps}};this.emit("warn",n)}}}async flush(e){if(this.transformer_&&typeof this.transformer_.flush=="function"&&!this.isFlashed_){this.isFlashed_=!0;try{await this.transformer_.flush(e)}catch(t){this.report({message:le.errors.transformer_flush,variation:"Error",error:Kt(t)});const n={eventMetaData:{transformerIndex:this.index_},error:t,function:"flush"};this.emit("error",n)}}this.reportQos(!0),this.report({variation:"Delete"})}stop(){console.log("[Pipeline] Stop stream."),this.controller_&&(this.flush(this.controller_),this.controller_.terminate()),this.shouldStop_=!0}report(e){this.reporter_.send({version:dt,action:"MediaTransformer",transformerType:this.transformerType_,...e})}reportQos(e=!1){this.reporterQos_.config={...this.reporterQos_.config},this.reporterQos_.onFrameTransformed({version:dt,action:"MediaTransformer",transformerType:this.transformerType_,videoWidth:this.videoWidth_,videoHeight:this.videoHeight_},e)}}class Ss extends Y{constructor(e){super(),this.transformers_=[],this.trackExpectedRate_=-1;for(let t=0;t<e.length;t++){let n=new Is(e[t],t);n.on("error",i=>{this.emit("error",i)}),n.on("warn",i=>{this.emit("warn",i)}),this.transformers_.push(n)}}setTrackExpectedRate(e){this.trackExpectedRate_=e;for(let t of this.transformers_)t.setTrackExpectedRate(this.trackExpectedRate_)}async start(e,t){if(!this.transformers_||this.transformers_.length===0){console.log("[Pipeline] No transformers.");return}try{let n=e;for(let i of this.transformers_)e=e.pipeThrough(new TransformStream(i));e.pipeTo(t).then(async()=>{console.log("[Pipeline] Setup."),await t.abort(),await n.cancel(),this.emit("pipelineInfo","pipeline_ended")}).catch(async i=>{e.cancel().then(()=>{console.log("[Pipeline] Shutting down streams after abort.")}).catch(s=>{console.error("[Pipeline] Error from stream transform:",s)}),await t.abort(i),await n.cancel(i),this.emit("pipelineInfo","pipeline_ended_with_error")})}catch{this.emit("pipelineInfo","pipeline_started_with_error"),this.destroy();return}this.emit("pipelineInfo","pipeline_started"),console.log("[Pipeline] Pipeline started.")}async destroy(){console.log("[Pipeline] Destroying Pipeline.");for(let e of this.transformers_)e.stop()}}class Rs extends Y{constructor(){super(),this.reporter_=new Qt,this.trackExpectedRate_=-1,this.report({variation:"Create"})}setTrackExpectedRate(e){this.trackExpectedRate_=e,this.pipeline_&&this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_)}async transform(e,t){if(this.isTrack(e)){if(e.kind==="video"){const n=new MediaStreamTrackProcessor({track:e}),i=new VideoTrackGenerator;return this.readable_=n.readable,this.writable_=i.writable,await this.transformInternal(),i.track}throw Error("Cannot process audio tracks inside a web worker when passing a track to transform")}else return this.readable_=e,this.writable_=t,this.transformInternal()}transformInternal(){return new Promise(async(e,t)=>{if(!this.transformers_||this.transformers_.length===0){this.report({message:le.errors.transformer_none,variation:"Error"}),t("[MediaProcessor] Need to set transformers.");return}if(!this.readable_){this.report({variation:"Error",message:le.errors.readable_null}),t("[MediaProcessor] Readable is null.");return}if(!this.writable_){this.report({variation:"Error",message:le.errors.writable_null}),t("[MediaProcessor] Writable is null.");return}let n=!1;this.pipeline_&&(n=!0,this.pipeline_.clearListeners(),this.pipeline_.destroy()),this.pipeline_=new Ss(this.transformers_),this.pipeline_.on("warn",i=>{this.emit("warn",i)}),this.pipeline_.on("error",i=>{this.emit("error",i)}),this.pipeline_.on("pipelineInfo",i=>{n&&(i==="pipeline_started"?i=Jt.pipeline_restarted:i==="pipeline_started_with_error"&&(i=Jt.pipeline_restarted_with_error)),this.emit("pipelineInfo",i)}),this.trackExpectedRate_!=-1&&this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_),this.pipeline_.start(this.readable_,this.writable_).then(()=>{e()}).catch(i=>{t(i)})})}setTransformers(e){return this.report({variation:"Update",message:le.updates.transformer_new}),this.transformers_=e,this.readable_&&this.writable_?this.transformInternal():Promise.resolve()}destroy(){return new Promise(async e=>{this.pipeline_&&this.pipeline_.destroy(),this.report({variation:"Delete"}),e()})}report(e){this.reporter_.send({version:dt,action:"MediaProcessor",...e})}isTrack(e){return"kind"in e}}var Fs=Object.defineProperty,Ps=(r,e,t)=>e in r?Fs(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,ks=(r,e,t)=>(Ps(r,e+"",t),t);const Cs="hlg.tokbox.com/prod/logging/vcp_webrtc",Bs="https://",Ds=1e4;let ht;const Ms=new Uint8Array(16);function Os(){if(!ht&&(ht=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ht))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ht(Ms)}const P=[];for(let r=0;r<256;++r)P.push((r+256).toString(16).slice(1));function Us(r,e=0){return(P[r[e+0]]+P[r[e+1]]+P[r[e+2]]+P[r[e+3]]+"-"+P[r[e+4]]+P[r[e+5]]+"-"+P[r[e+6]]+P[r[e+7]]+"-"+P[r[e+8]]+P[r[e+9]]+"-"+P[r[e+10]]+P[r[e+11]]+P[r[e+12]]+P[r[e+13]]+P[r[e+14]]+P[r[e+15]]).toLowerCase()}const Ns=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),on={randomUUID:Ns};function Ls(r,e,t){if(on.randomUUID&&!e&&!r)return on.randomUUID();r=r||{};const n=r.random||(r.rng||Os)();return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Us(n)}function Zt(r,e){globalThis.vonage||(globalThis.vonage={}),globalThis.vonage.workerizer||(globalThis.vonage.workerizer={});let t=globalThis.vonage.workerizer;return t[r]||(t[r]=e),t[r]}const ee=Zt("globals",{});var de=(r=>(r.INIT="INIT",r.FORWARD="FORWARD",r.TERMINATE="TERMINATE",r.GLOBALS_SYNC="GLOBALS_SYNC",r))(de||{});function an(r){return[ImageBitmap,ReadableStream,WritableStream].some(e=>r instanceof e)}let zs=0;function Gs(r,e,t,n,i){const s=zs++;return r.postMessage({id:s,type:e,functionName:t,args:n},n.filter(o=>an(o))),new Promise(o=>{i?.set(s,o)})}function Ue(r,e){const{id:t,type:n}=r,i=Array.isArray(e)?e:[e];postMessage({id:t,type:n,result:e},i.filter(s=>an(s)))}const cn=Zt("workerized",{});function un(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}async function $s(){if(un())Ue({type:de.GLOBALS_SYNC},ee);else{const r=[];for(const e in cn){const{worker:t,resolvers:n}=cn[e].workerContext;t&&r.push(Gs(t,de.GLOBALS_SYNC,"",[ee],n))}await Promise.all(r)}}function mt(r,e){if(Array.isArray(e))e.splice(0,e.length);else if(typeof e=="object")for(const t in e)delete e[t];for(const t in r)Array.isArray(r[t])?(e[t]=[],mt(r[t],e[t])):typeof r[t]=="object"?(e[t]={},mt(r[t],e[t])):e[t]=r[t]}async function Ws(r,e){const{functionName:t,args:n}=r;if(!e.instance)throw"instance not initialized";if(!t)throw"missing function name to call";if(!e.instance[t])throw`undefined function [${t}] in class ${e.instance.constructor.workerId}`;Ue(r,await e.instance[t](...n??[]))}const Vs=Zt("registeredWorkers",{});function Hs(r,e){if(!r.args)throw"Missing className while initializing worker";const[t,n]=r.args,i=Vs[t];if(i)e.instance=new i(r.args.slice(1));else throw`unknown worker class ${t}`;mt(n,ee),Ue(r,typeof e.instance!==void 0)}async function js(r,e){const{args:t}=r;if(!e.instance)throw"instance not initialized";let n;e.instance.terminate&&(n=await e.instance.terminate(...t??[])),Ue(r,n)}function Xs(r){if(!r.args)throw"Missing globals while syncing";mt(r.args[0],ee),Ue(r,{})}function Ys(){const r={};onmessage=async e=>{const t=e.data;switch(t.type){case de.INIT:Hs(t,r);break;case de.FORWARD:Ws(t,r);break;case de.TERMINATE:js(t,r);break;case de.GLOBALS_SYNC:Xs(t);break}}}un()&&Ys();function Qs(r,e){return ee[r]||(ee[r]=e),[()=>ee[r],async t=>{ee[r]=t,await $s()}]}function qs(r,e){return Qs(r,e)}const[Ks]=qs("metadata");function er(){return Ks()}class Js{constructor(e){ks(this,"uuid",Ls()),this.config=e}async send(e){var t,n,i;const{appId:s,sourceType:o}=(t=er())!=null?t:{};if(!s||!o)return"metadata missing";const a=new AbortController,c=setTimeout(()=>a.abort(),Ds);return await((i=(n=this.config)==null?void 0:n.fetch)!=null?i:fetch)(this.getUrl(),{method:"POST",headers:this.getHeaders(),body:JSON.stringify(this.buildReport(e)),signal:a.signal}),clearTimeout(c),"success"}getUrl(){var e;let t=(e=er().proxyUrl)!=null?e:Bs;return t+=(t.at(-1)==="/"?"":"/")+Cs,t}getHeaders(){return{"Content-Type":"application/json"}}buildReport(e){const t=er();return{guid:this.uuid,...e,applicationId:t.appId,timestamp:Date.now(),proxyUrl:t.proxyUrl,source:t.sourceType}}}const Zs="7.0.0";var pt=(r=>(r.Low="Low",r.High="High",r))(pt||{}),tr=(r=>(r.FAST="FAST",r.PRECISE="PRECISE",r))(tr||{}),gt=(r=>(r.CANVAS="CANVAS",r.WEBGL="WEBGL",r))(gt||{});function eo(){const e=new OffscreenCanvas(0,0).getContext("webgl2",{failIfMajorPerformanceCaveat:!0});if(e){const t=e?.getExtension("WEBGL_lose_context");t&&t.loseContext()}else return{supported:!1,message:"Your hardware does not perform good enough to run the library efficiently"};return{supported:!0}}class rr{constructor(){const e=new OffscreenCanvas(0,0),t=e.getContext("2d",{willReadFrequently:!0});if(!t)throw"Fail to retrieve 2d context";this.canvas=e,this.context=t}enablePostProcessing(){}disablePostProcessing(){}async profileWebgl(e){return[]}async render(e,t){return this.canvas}resizeCanvas(e){const{width:t,height:n}=e;this.canvas.width=t,this.canvas.height=n}renderSilhouette(e,t,n="none"){const{width:i,height:s}=e;this.context.save(),this.context.drawImage(t,0,0,t.width,t.height,0,0,i,s),this.context.filter="blur(5px)",this.context.globalCompositeOperation="source-in",this.context.drawImage(t,0,0,t.width,t.height,0,0,i,s),this.context.globalCompositeOperation="source-in",this.context.filter=n,this.context.drawImage(e,0,0,i,s,0,0,this.canvas.width,this.canvas.height),this.context.restore()}destroy(){}}class to extends rr{constructor(e){super(),this.radius=e}async render(e,t){super.resizeCanvas(e);const n=await createImageBitmap(t);return this.renderSilhouette(e,n),this.context.save(),this.context.filter=`blur(${this.radius}px)`,this.context.globalCompositeOperation="destination-over",this.context.drawImage(e,0,0,e.width,e.height),this.context.restore(),super.render(e,t)}}class ro extends rr{constructor(e){super(),this.radius=e}async render(e,t){super.resizeCanvas(e);const n=await createImageBitmap(t);return this.renderSilhouette(e,n,`blur(${this.radius}px)`),this.context.save(),this.context.filter="none",this.context.globalCompositeOperation="destination-over",this.context.drawImage(e,0,0,e.width,e.height),this.context.restore(),super.render(e,t)}}class no extends rr{setBackgroundImage(e){this.backgroundImage=e}async render(e,t){super.resizeCanvas(e);const n=await createImageBitmap(t);return this.renderSilhouette(e,n),this.backgroundImage&&(this.context.save(),this.context.filter="none",this.context.globalCompositeOperation="destination-over",this.context.drawImage(this.backgroundImage,0,0,this.backgroundImage.width,this.backgroundImage.height,0,0,e.width,e.height),this.context.restore()),super.render(e,t)}}const nr=5120,Ne=5121,ir=5122,sr=5123,or=5124,ar=5125,cr=5126,io=32819,so=32820,oo=33635,ao=5131,co=33640,uo=35899,fo=35902,lo=36269,ho=34042,fn={};{const r=fn;r[nr]=Int8Array,r[Ne]=Uint8Array,r[ir]=Int16Array,r[sr]=Uint16Array,r[or]=Int32Array,r[ar]=Uint32Array,r[cr]=Float32Array,r[io]=Uint16Array,r[so]=Uint16Array,r[oo]=Uint16Array,r[ao]=Uint16Array,r[co]=Uint32Array,r[uo]=Uint32Array,r[fo]=Uint32Array,r[lo]=Uint32Array,r[ho]=Uint32Array}function ur(r){if(r instanceof Int8Array)return nr;if(r instanceof Uint8Array||r instanceof Uint8ClampedArray)return Ne;if(r instanceof Int16Array)return ir;if(r instanceof Uint16Array)return sr;if(r instanceof Int32Array)return or;if(r instanceof Uint32Array)return ar;if(r instanceof Float32Array)return cr;throw new Error("unsupported typed array type")}function ln(r){if(r===Int8Array)return nr;if(r===Uint8Array||r===Uint8ClampedArray)return Ne;if(r===Int16Array)return ir;if(r===Uint16Array)return sr;if(r===Int32Array)return or;if(r===Uint32Array)return ar;if(r===Float32Array)return cr;throw new Error("unsupported typed array type")}function dn(r){const e=fn[r];if(!e)throw new Error("unknown gl type");return e}const yt=typeof SharedArrayBuffer<"u"?function(e){return e&&e.buffer&&(e.buffer instanceof ArrayBuffer||e.buffer instanceof SharedArrayBuffer)}:function(e){return e&&e.buffer&&e.buffer instanceof ArrayBuffer};function hn(...r){console.error(...r)}const mn=new Map;function bt(r,e){if(!r||typeof r!="object")return!1;let t=mn.get(e);t||(t=new WeakMap,mn.set(e,t));let n=t.get(r);if(n===void 0){const i=Object.prototype.toString.call(r);n=i.substring(8,i.length-1)===e,t.set(r,n)}return n}function mo(r,e){return typeof WebGLBuffer<"u"&&bt(e,"WebGLBuffer")}function po(r,e){return typeof WebGLRenderbuffer<"u"&&bt(e,"WebGLRenderbuffer")}function fr(r,e){return typeof WebGLTexture<"u"&&bt(e,"WebGLTexture")}function go(r,e){return typeof WebGLSampler<"u"&&bt(e,"WebGLSampler")}const pn=35044,he=34962,yo=34963,bo=34660,xo=5120,_o=5121,Eo=5122,wo=5123,vo=5124,To=5125,gn=5126,yn={attribPrefix:""};function Ao(r,e,t,n,i){r.bindBuffer(e,t),r.bufferData(e,n,i||pn)}function bn(r,e,t,n){if(mo(r,e))return e;t=t||he;const i=r.createBuffer();return Ao(r,t,i,e,n),i}function xn(r){return r==="indices"}function Io(r){return r===Int8Array||r===Uint8Array}function So(r){return r.length?r:r.data}const Ro=/coord|texture/i,Fo=/color|colour/i;function Po(r,e){let t;if(Ro.test(r)?t=2:Fo.test(r)?t=4:t=3,e%t>0)throw new Error(`Can not guess numComponents for attribute \'${r}\'. Tried ${t} but ${e} values is not evenly divisible by ${t}. You should specify it.`);return t}function ko(r,e,t){return r.numComponents||r.size||Po(e,t||So(r).length)}function _n(r,e){if(yt(r))return r;if(yt(r.data))return r.data;Array.isArray(r)&&(r={data:r});let t=r.type?lr(r.type):void 0;return t||(xn(e)?t=Uint16Array:t=Float32Array),new t(r.data)}function Co(r){return typeof r=="number"?r:r?ln(r):gn}function lr(r){return typeof r=="number"?dn(r):r||Float32Array}function Bo(r,e){return{buffer:e.buffer,numValues:24,type:Co(e.type),arrayType:lr(e.type)}}function Do(r,e){const t=e.data||e,n=lr(e.type),i=t*n.BYTES_PER_ELEMENT,s=r.createBuffer();return r.bindBuffer(he,s),r.bufferData(he,i,e.drawType||pn),{buffer:s,numValues:t,type:ln(n),arrayType:n}}function Mo(r,e,t){const n=_n(e,t);return{arrayType:n.constructor,buffer:bn(r,n,void 0,e.drawType),type:ur(n),numValues:0}}function Oo(r,e){const t={};return Object.keys(e).forEach(function(n){if(!xn(n)){const i=e[n],s=i.attrib||i.name||i.attribName||yn.attribPrefix+n;if(i.value){if(!Array.isArray(i.value)&&!yt(i.value))throw new Error("array.value is not array or typedarray");t[s]={value:i.value}}else{let o;i.buffer&&i.buffer instanceof WebGLBuffer?o=Bo:typeof i=="number"||typeof i.data=="number"?o=Do:o=Mo;const{buffer:a,type:c,numValues:u,arrayType:d}=o(r,i,n),m=i.normalize!==void 0?i.normalize:Io(d),p=ko(i,n,u);t[s]={buffer:a,numComponents:p,type:c,normalize:m,stride:i.stride||0,offset:i.offset||0,divisor:i.divisor===void 0?void 0:i.divisor,drawType:i.drawType}}}}),r.bindBuffer(he,null),t}function Uo(r,e){return e===xo||e===_o?1:e===Eo||e===wo?2:e===vo||e===To||e===gn?4:0}const dr=["position","positions","a_position"];function No(r,e){let t,n;for(n=0;n<dr.length&&(t=dr[n],!(t in e||(t=yn.attribPrefix+t,t in e)));++n);n===dr.length&&(t=Object.keys(e)[0]);const i=e[t];if(!i.buffer)return 1;r.bindBuffer(he,i.buffer);const s=r.getBufferParameter(he,bo);r.bindBuffer(he,null);const o=Uo(r,i.type),a=s/o,c=i.numComponents||i.size,u=a/c;if(u%1!==0)throw new Error(`numComponents ${c} not correct for length ${length}`);return u}function Lo(r,e,t){const n=Oo(r,e),i=Object.assign({},t||{});i.attribs=Object.assign({},t?t.attribs:{},n);const s=e.indices;if(s){const o=_n(s,"indices");i.indices=bn(r,o,yo),i.numElements=o.length,i.elementType=ur(o)}else i.numElements||(i.numElements=No(r,i.attribs));return i}function Le(r){return!!r.texStorage2D}const En=(function(){const r={},e={};function t(n){const i=n.constructor.name;if(!r[i]){for(const s in n)if(typeof n[s]=="number"){const o=e[n[s]];e[n[s]]=o?`${o} | ${s}`:s}r[i]=!0}}return function(i,s){return t(i),e[s]||(typeof s=="number"?`0x${s.toString(16)}`:s)}})(),te={textureColor:new Uint8Array([128,192,255,255]),textureOptions:{},crossOrigin:void 0},ze=yt,wn=(function(){let r;return function(){return r=r||(typeof document<"u"&&document.createElement?document.createElement("canvas").getContext("2d"):null),r}})(),vn=6406,V=6407,A=6408,Tn=6409,An=6410,Ge=6402,In=34041,xt=33071,zo=9728,Go=9729,re=3553,ne=34067,me=32879,pe=35866,hr=34069,$o=34070,Wo=34071,Vo=34072,Ho=34073,jo=34074,mr=10241,pr=10240,_t=10242,Et=10243,Sn=32882,Xo=33082,Yo=33083,Qo=33084,qo=33085,Ko=34892,Jo=34893,gr=3317,Rn=3314,Fn=32878,Pn=3316,kn=3315,Cn=32877,Zo=37443,ea=37441,ta=37440,ra=33321,na=36756,ia=33325,sa=33326,oa=33330,aa=33329,ca=33338,ua=33337,fa=33340,la=33339,da=33323,ha=36757,ma=33327,pa=33328,ga=33336,ya=33335,ba=33332,xa=33331,_a=33334,Ea=33333,wa=32849,va=35905,Ta=36194,Aa=36758,Ia=35898,Sa=35901,Ra=34843,Fa=34837,Pa=36221,ka=36239,Ca=36215,Ba=36233,Da=36209,Ma=36227,Oa=32856,Ua=35907,Na=36759,La=32855,za=32854,Ga=32857,$a=34842,Wa=34836,Va=36220,Ha=36238,ja=36975,Xa=36214,Ya=36232,Qa=36226,qa=36208,Ka=33189,Ja=33190,Za=36012,ec=36013,tc=35056,ie=5120,T=5121,wt=5122,Se=5123,vt=5124,ge=5125,B=5126,Bn=32819,Dn=32820,Mn=33635,z=5131,$e=36193,yr=33640,rc=35899,nc=35902,ic=36269,sc=34042,Tt=33319,Re=33320,At=6403,Fe=36244,Pe=36248,ye=36249;let br;function It(r){if(!br){const e={};e[vn]={textureFormat:vn,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[1,2,2,4],type:[T,z,$e,B]},e[Tn]={textureFormat:Tn,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[1,2,2,4],type:[T,z,$e,B]},e[An]={textureFormat:An,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[2,4,4,8],type:[T,z,$e,B]},e[V]={textureFormat:V,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[3,6,6,12,2],type:[T,z,$e,B,Mn]},e[A]={textureFormat:A,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4,8,8,16,2,2],type:[T,z,$e,B,Bn,Dn]},e[Ge]={textureFormat:Ge,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2,4],type:[ge,Se]},e[ra]={textureFormat:At,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[1],type:[T]},e[na]={textureFormat:At,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[1],type:[ie]},e[ia]={textureFormat:At,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[4,2],type:[B,z]},e[sa]={textureFormat:At,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[4],type:[B]},e[oa]={textureFormat:Fe,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[1],type:[T]},e[aa]={textureFormat:Fe,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[1],type:[ie]},e[ba]={textureFormat:Fe,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[Se]},e[xa]={textureFormat:Fe,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[wt]},e[_a]={textureFormat:Fe,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[ge]},e[Ea]={textureFormat:Fe,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[vt]},e[da]={textureFormat:Tt,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[2],type:[T]},e[ha]={textureFormat:Tt,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[2],type:[ie]},e[ma]={textureFormat:Tt,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[8,4],type:[B,z]},e[pa]={textureFormat:Tt,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[8],type:[B]},e[ga]={textureFormat:Re,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[T]},e[ya]={textureFormat:Re,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2],type:[ie]},e[ca]={textureFormat:Re,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[Se]},e[ua]={textureFormat:Re,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[wt]},e[fa]={textureFormat:Re,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[ge]},e[la]={textureFormat:Re,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[vt]},e[wa]={textureFormat:V,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[3],type:[T]},e[va]={textureFormat:V,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[3],type:[T]},e[Ta]={textureFormat:V,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[3,2],type:[T,Mn]},e[Aa]={textureFormat:V,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[3],type:[ie]},e[Ia]={textureFormat:V,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[12,6,4],type:[B,z,rc]},e[Sa]={textureFormat:V,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[12,6,4],type:[B,z,nc]},e[Ra]={textureFormat:V,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[12,6],type:[B,z]},e[Fa]={textureFormat:V,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[12],type:[B]},e[Pa]={textureFormat:Pe,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[3],type:[T]},e[ka]={textureFormat:Pe,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[3],type:[ie]},e[Ca]={textureFormat:Pe,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[6],type:[Se]},e[Ba]={textureFormat:Pe,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[6],type:[wt]},e[Da]={textureFormat:Pe,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[12],type:[ge]},e[Ma]={textureFormat:Pe,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[12],type:[vt]},e[Oa]={textureFormat:A,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4],type:[T]},e[Ua]={textureFormat:A,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4],type:[T]},e[Na]={textureFormat:A,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[4],type:[ie]},e[La]={textureFormat:A,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4,2,4],type:[T,Dn,yr]},e[za]={textureFormat:A,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4,2],type:[T,Bn]},e[Ga]={textureFormat:A,colorRenderable:!0,textureFilterable:!0,bytesPerElement:[4],type:[yr]},e[$a]={textureFormat:A,colorRenderable:!1,textureFilterable:!0,bytesPerElement:[16,8],type:[B,z]},e[Wa]={textureFormat:A,colorRenderable:!1,textureFilterable:!1,bytesPerElement:[16],type:[B]},e[Va]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[T]},e[Ha]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[ie]},e[ja]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[yr]},e[Xa]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[Se]},e[Ya]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[8],type:[wt]},e[Qa]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[16],type:[vt]},e[qa]={textureFormat:ye,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[16],type:[ge]},e[Ka]={textureFormat:Ge,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[2,4],type:[Se,ge]},e[Ja]={textureFormat:Ge,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[ge]},e[Za]={textureFormat:Ge,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[B]},e[tc]={textureFormat:In,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[sc]},e[ec]={textureFormat:In,colorRenderable:!0,textureFilterable:!1,bytesPerElement:[4],type:[ic]},Object.keys(e).forEach(function(t){const n=e[t];n.bytesPerElementMap={},n.bytesPerElement.forEach(function(i,s){const o=n.type[s];n.bytesPerElementMap[o]=i})}),br=e}return br[r]}function oc(r,e){const t=It(r);if(!t)throw"unknown internal format";const n=t.bytesPerElementMap[e];if(n===void 0)throw"unknown internal format";return n}function We(r){const e=It(r);if(!e)throw"unknown internal format";return{format:e.textureFormat,type:e.type[0]}}function On(r){return(r&r-1)===0}function ac(r,e,t,n){if(!Le(r))return On(e)&&On(t);const i=It(n);if(!i)throw"unknown internal format";return i.colorRenderable&&i.textureFilterable}function cc(r){const e=It(r);if(!e)throw"unknown internal format";return e.textureFilterable}function uc(r,e,t){return ze(e)?ur(e):t||T}function St(r,e,t,n,i){if(i%1!==0)throw"can\'t guess dimensions";if(!t&&!n){const s=Math.sqrt(i/(e===ne?6:1));s%1===0?(t=s,n=s):(t=i,n=1)}else if(n){if(!t&&(t=i/n,t%1))throw"can\'t guess dimensions"}else if(n=i/t,n%1)throw"can\'t guess dimensions";return{width:t,height:n}}function ke(r,e){e.colorspaceConversion!==void 0&&r.pixelStorei(Zo,e.colorspaceConversion),e.premultiplyAlpha!==void 0&&r.pixelStorei(ea,e.premultiplyAlpha),e.flipY!==void 0&&r.pixelStorei(ta,e.flipY)}function Un(r){r.pixelStorei(gr,4),Le(r)&&(r.pixelStorei(Rn,0),r.pixelStorei(Fn,0),r.pixelStorei(Pn,0),r.pixelStorei(kn,0),r.pixelStorei(Cn,0))}function fc(r,e,t,n){n.minMag&&(t.call(r,e,mr,n.minMag),t.call(r,e,pr,n.minMag)),n.min&&t.call(r,e,mr,n.min),n.mag&&t.call(r,e,pr,n.mag),n.wrap&&(t.call(r,e,_t,n.wrap),t.call(r,e,Et,n.wrap),(e===me||go(r,e))&&t.call(r,e,Sn,n.wrap)),n.wrapR&&t.call(r,e,Sn,n.wrapR),n.wrapS&&t.call(r,e,_t,n.wrapS),n.wrapT&&t.call(r,e,Et,n.wrapT),n.minLod!==void 0&&t.call(r,e,Xo,n.minLod),n.maxLod!==void 0&&t.call(r,e,Yo,n.maxLod),n.baseLevel!==void 0&&t.call(r,e,Qo,n.baseLevel),n.maxLevel!==void 0&&t.call(r,e,qo,n.maxLevel),n.compareFunc!==void 0&&t.call(r,e,Jo,n.compareFunc),n.compareMode!==void 0&&t.call(r,e,Ko,n.compareMode)}function Nn(r,e,t){const n=t.target||re;r.bindTexture(n,e),fc(r,n,r.texParameteri,t)}function lc(r){return r=r||te.textureColor,ze(r)?r:new Uint8Array([r[0]*255,r[1]*255,r[2]*255,r[3]*255])}function xr(r,e,t,n,i,s){t=t||te.textureOptions,s=s||A;const o=t.target||re;if(n=n||t.width,i=i||t.height,r.bindTexture(o,e),ac(r,n,i,s))r.generateMipmap(o);else{const a=cc(s)?Go:zo;r.texParameteri(o,mr,a),r.texParameteri(o,pr,a),r.texParameteri(o,_t,xt),r.texParameteri(o,Et,xt)}}function Ve(r){return r.auto===!0||r.auto===void 0&&r.level===void 0}function _r(r,e){return e=e||{},e.cubeFaceOrder||[hr,$o,Wo,Vo,Ho,jo]}function Er(r,e){const n=_r(r,e).map(function(i,s){return{face:i,ndx:s}});return n.sort(function(i,s){return i.face-s.face}),n}function Ln(r,e,t,n){n=n||te.textureOptions;const i=n.target||re,s=n.level||0;let o=t.width,a=t.height;const c=n.internalFormat||n.format||A,u=We(c),d=n.format||u.format,m=n.type||u.type;if(ke(r,n),r.bindTexture(i,e),i===ne){const p=t.width,y=t.height;let l,b;if(p/6===y)l=y,b=[0,0,1,0,2,0,3,0,4,0,5,0];else if(y/6===p)l=p,b=[0,0,0,1,0,2,0,3,0,4,0,5];else if(p/3===y/2)l=p/3,b=[0,0,1,0,2,0,0,1,1,1,2,1];else if(p/2===y/3)l=p/2,b=[0,0,1,0,0,1,1,1,0,2,1,2];else throw"can\'t figure out cube map from element: "+(t.src?t.src:t.nodeName);const _=wn();_?(_.canvas.width=l,_.canvas.height=l,o=l,a=l,Er(r,n).forEach(function(E){const R=b[E.ndx*2+0]*l,k=b[E.ndx*2+1]*l;_.drawImage(t,R,k,l,l,0,0,l,l),r.texImage2D(E.face,s,c,d,m,_.canvas)}),_.canvas.width=1,_.canvas.height=1):typeof createImageBitmap<"u"&&(o=l,a=l,Er(r,n).forEach(function(E){const R=b[E.ndx*2+0]*l,k=b[E.ndx*2+1]*l;r.texImage2D(E.face,s,c,l,l,0,d,m,null),createImageBitmap(t,R,k,l,l,{premultiplyAlpha:"none",colorSpaceConversion:"none"}).then(function(N){ke(r,n),r.bindTexture(i,e),r.texImage2D(E.face,s,c,d,m,N),Ve(n)&&xr(r,e,n,o,a,c)})}))}else if(i===me||i===pe){const p=Math.min(t.width,t.height),y=Math.max(t.width,t.height),l=y/p;if(l%1!==0)throw"can not compute 3D dimensions of element";const b=t.width===y?1:0,_=t.height===y?1:0;r.pixelStorei(gr,1),r.pixelStorei(Rn,t.width),r.pixelStorei(Fn,0),r.pixelStorei(Cn,0),r.texImage3D(i,s,c,p,p,p,0,d,m,null);for(let E=0;E<l;++E){const R=E*p*b,k=E*p*_;r.pixelStorei(Pn,R),r.pixelStorei(kn,k),r.texSubImage3D(i,s,0,0,E,p,p,1,d,m,t)}Un(r)}else r.texImage2D(i,s,c,d,m,t);Ve(n)&&xr(r,e,n,o,a,c),Nn(r,e,n)}function He(){}function dc(r){if(typeof document<"u"){const e=document.createElement("a");return e.href=r,e.hostname===location.hostname&&e.port===location.port&&e.protocol===location.protocol}else{const e=new URL(location.href).origin;return new URL(r,location.href).origin===e}}function hc(r,e){return e===void 0&&!dc(r)?"anonymous":e}function mc(r,e,t){t=t||He;let n;if(e=e!==void 0?e:te.crossOrigin,e=hc(r,e),typeof Image<"u"){n=new Image,e!==void 0&&(n.crossOrigin=e);const i=function(){n.removeEventListener("error",s),n.removeEventListener("load",o),n=null},s=function(){const c="couldn\'t load image: "+r;hn(c),t(c,n),i()},o=function(){t(null,n),i()};return n.addEventListener("error",s),n.addEventListener("load",o),n.src=r,n}else if(typeof ImageBitmap<"u"){let i,s;const o=function(){t(i,s)},a={};e&&(a.mode="cors"),fetch(r,a).then(function(c){if(!c.ok)throw c;return c.blob()}).then(function(c){return createImageBitmap(c,{premultiplyAlpha:"none",colorSpaceConversion:"none"})}).then(function(c){s=c,setTimeout(o)}).catch(function(c){i=c,setTimeout(o)}),n=null}return n}function zn(r){return typeof ImageBitmap<"u"&&r instanceof ImageBitmap||typeof ImageData<"u"&&r instanceof ImageData||typeof HTMLElement<"u"&&r instanceof HTMLElement}function wr(r,e,t){return zn(r)?(setTimeout(function(){t(null,r)}),r):mc(r,e,t)}function vr(r,e,t){t=t||te.textureOptions;const n=t.target||re;if(r.bindTexture(n,e),t.color===!1)return;const i=lc(t.color);if(n===ne)for(let s=0;s<6;++s)r.texImage2D(hr+s,0,A,1,1,0,A,T,i);else n===me||n===pe?r.texImage3D(n,0,A,1,1,1,0,A,T,i):r.texImage2D(n,0,A,1,1,0,A,T,i)}function pc(r,e,t,n){return n=n||He,t=t||te.textureOptions,vr(r,e,t),t=Object.assign({},t),wr(t.src,t.crossOrigin,function(s,o){s?n(s,e,o):(Ln(r,e,o,t),n(null,e,o))})}function gc(r,e,t,n){n=n||He;const i=t.src;if(i.length!==6)throw"there must be 6 urls for a cubemap";const s=t.level||0,o=t.internalFormat||t.format||A,a=We(o),c=t.format||a.format,u=t.type||T,d=t.target||re;if(d!==ne)throw"target must be TEXTURE_CUBE_MAP";vr(r,e,t),t=Object.assign({},t);let m=6;const p=[],y=_r(r,t);let l;function b(_){return function(E,R){--m,E?p.push(E):R.width!==R.height?p.push("cubemap face img is not a square: "+R.src):(ke(r,t),r.bindTexture(d,e),m===5?_r().forEach(function(k){r.texImage2D(k,s,o,c,u,R)}):r.texImage2D(_,s,o,c,u,R),Ve(t)&&r.generateMipmap(d)),m===0&&n(p.length?p:void 0,e,l)}}l=i.map(function(_,E){return wr(_,t.crossOrigin,b(y[E]))})}function yc(r,e,t,n){n=n||He;const i=t.src,s=t.internalFormat||t.format||A,o=We(s),a=t.format||o.format,c=t.type||T,u=t.target||pe;if(u!==me&&u!==pe)throw"target must be TEXTURE_3D or TEXTURE_2D_ARRAY";vr(r,e,t),t=Object.assign({},t);let d=i.length;const m=[];let p;const y=t.level||0;let l=t.width,b=t.height;const _=i.length;let E=!0;function R(k){return function(N,Q){if(--d,N)m.push(N);else{if(ke(r,t),r.bindTexture(u,e),E){E=!1,l=t.width||Q.width,b=t.height||Q.height,r.texImage3D(u,y,s,l,b,_,0,a,c,null);for(let q=0;q<_;++q)r.texSubImage3D(u,y,0,0,q,l,b,1,a,c,Q)}else{let q=Q,L;(Q.width!==l||Q.height!==b)&&(L=wn(),q=L.canvas,L.canvas.width=l,L.canvas.height=b,L.drawImage(Q,0,0,l,b)),r.texSubImage3D(u,y,0,0,k,l,b,1,a,c,q),L&&q===L.canvas&&(L.canvas.width=0,L.canvas.height=0)}Ve(t)&&r.generateMipmap(u)}d===0&&n(m.length?m:void 0,e,p)}}p=i.map(function(k,N){return wr(k,t.crossOrigin,R(N))})}function bc(r,e,t,n){n=n||te.textureOptions;const i=n.target||re;r.bindTexture(i,e);let s=n.width,o=n.height,a=n.depth;const c=n.level||0,u=n.internalFormat||n.format||A,d=We(u),m=n.format||d.format,p=n.type||uc(r,t,d.type);if(ze(t))t instanceof Uint8ClampedArray&&(t=new Uint8Array(t.buffer));else{const _=dn(p);t=new _(t)}const y=oc(u,p),l=t.byteLength/y;if(l%1)throw"length wrong size for format: "+En(r,m);let b;if(i===me||i===pe)if(!s&&!o&&!a){const _=Math.cbrt(l);if(_%1!==0)throw"can\'t guess cube size of array of numElements: "+l;s=_,o=_,a=_}else s&&(!o||!a)?(b=St(r,i,o,a,l/s),o=b.width,a=b.height):o&&(!s||!a)?(b=St(r,i,s,a,l/o),s=b.width,a=b.height):(b=St(r,i,s,o,l/a),s=b.width,o=b.height);else b=St(r,i,s,o,l),s=b.width,o=b.height;if(Un(r),r.pixelStorei(gr,n.unpackAlignment||1),ke(r,n),i===ne){const _=y/t.BYTES_PER_ELEMENT,E=l/6*_;Er(r,n).forEach(R=>{const k=E*R.ndx,N=t.subarray(k,k+E);r.texImage2D(R.face,c,u,s,o,0,m,p,N)})}else i===me||i===pe?r.texImage3D(i,c,u,s,o,a,0,m,p,t):r.texImage2D(i,c,u,s,o,0,m,p,t);return{width:s,height:o,depth:a,type:p}}function xc(r,e,t){const n=t.target||re;r.bindTexture(n,e);const i=t.level||0,s=t.internalFormat||t.format||A,o=We(s),a=t.format||o.format,c=t.type||o.type;if(ke(r,t),n===ne)for(let u=0;u<6;++u)r.texImage2D(hr+u,i,s,t.width,t.height,0,a,c,null);else n===me||n===pe?r.texImage3D(n,i,s,t.width,t.height,t.depth,0,a,c,null):r.texImage2D(n,i,s,t.width,t.height,0,a,c,null)}function Gn(r,e,t){t=t||He,e=e||te.textureOptions;const n=r.createTexture(),i=e.target||re;let s=e.width||1,o=e.height||1;const a=e.internalFormat||A;r.bindTexture(i,n),i===ne&&(r.texParameteri(i,_t,xt),r.texParameteri(i,Et,xt));let c=e.src;if(c)if(typeof c=="function"&&(c=c(r,e)),typeof c=="string")pc(r,n,e,t);else if(ze(c)||Array.isArray(c)&&(typeof c[0]=="number"||Array.isArray(c[0])||ze(c[0]))){const u=bc(r,n,c,e);s=u.width,o=u.height}else Array.isArray(c)&&(typeof c[0]=="string"||zn(c[0]))?i===ne?gc(r,n,e,t):yc(r,n,e,t):(Ln(r,n,c,e),s=c.width,o=c.height);else xc(r,n,e);return Ve(e)&&xr(r,n,e,s,o,a),Nn(r,n,e),n}const Tr=hn;function $n(r){return typeof document<"u"&&document.getElementById?document.getElementById(r):null}const Rt=33984,Ft=34962,_c=34963,Ec=35713,wc=35714,vc=35632,Tc=35633,Ac=35981,Wn=35718,Ic=35721,Sc=35971,Rc=35382,Fc=35396,Pc=35398,kc=35392,Cc=35395,Pt=5126,Vn=35664,Hn=35665,jn=35666,Ar=5124,Xn=35667,Yn=35668,Qn=35669,qn=35670,Kn=35671,Jn=35672,Zn=35673,ei=35674,ti=35675,ri=35676,Bc=35678,Dc=35680,Mc=35679,Oc=35682,Uc=35685,Nc=35686,Lc=35687,zc=35688,Gc=35689,$c=35690,Wc=36289,Vc=36292,Hc=36293,Ir=5125,ni=36294,ii=36295,si=36296,jc=36298,Xc=36299,Yc=36300,Qc=36303,qc=36306,Kc=36307,Jc=36308,Zc=36311,kt=3553,Ct=34067,Sr=32879,Bt=35866,x={};function oi(r,e){return x[e].bindPoint}function eu(r,e){return function(t){r.uniform1f(e,t)}}function tu(r,e){return function(t){r.uniform1fv(e,t)}}function ru(r,e){return function(t){r.uniform2fv(e,t)}}function nu(r,e){return function(t){r.uniform3fv(e,t)}}function iu(r,e){return function(t){r.uniform4fv(e,t)}}function ai(r,e){return function(t){r.uniform1i(e,t)}}function ci(r,e){return function(t){r.uniform1iv(e,t)}}function ui(r,e){return function(t){r.uniform2iv(e,t)}}function fi(r,e){return function(t){r.uniform3iv(e,t)}}function li(r,e){return function(t){r.uniform4iv(e,t)}}function su(r,e){return function(t){r.uniform1ui(e,t)}}function ou(r,e){return function(t){r.uniform1uiv(e,t)}}function au(r,e){return function(t){r.uniform2uiv(e,t)}}function cu(r,e){return function(t){r.uniform3uiv(e,t)}}function uu(r,e){return function(t){r.uniform4uiv(e,t)}}function fu(r,e){return function(t){r.uniformMatrix2fv(e,!1,t)}}function lu(r,e){return function(t){r.uniformMatrix3fv(e,!1,t)}}function du(r,e){return function(t){r.uniformMatrix4fv(e,!1,t)}}function hu(r,e){return function(t){r.uniformMatrix2x3fv(e,!1,t)}}function mu(r,e){return function(t){r.uniformMatrix3x2fv(e,!1,t)}}function pu(r,e){return function(t){r.uniformMatrix2x4fv(e,!1,t)}}function gu(r,e){return function(t){r.uniformMatrix4x2fv(e,!1,t)}}function yu(r,e){return function(t){r.uniformMatrix3x4fv(e,!1,t)}}function bu(r,e){return function(t){r.uniformMatrix4x3fv(e,!1,t)}}function O(r,e,t,n){const i=oi(r,e);return Le(r)?function(s){let o,a;!s||fr(r,s)?(o=s,a=null):(o=s.texture,a=s.sampler),r.uniform1i(n,t),r.activeTexture(Rt+t),r.bindTexture(i,o),r.bindSampler(t,a)}:function(s){r.uniform1i(n,t),r.activeTexture(Rt+t),r.bindTexture(i,s)}}function U(r,e,t,n,i){const s=oi(r,e),o=new Int32Array(i);for(let a=0;a<i;++a)o[a]=t+a;return Le(r)?function(a){r.uniform1iv(n,o),a.forEach(function(c,u){r.activeTexture(Rt+o[u]);let d,m;!c||fr(r,c)?(d=c,m=null):(d=c.texture,m=c.sampler),r.bindSampler(t,m),r.bindTexture(s,d)})}:function(a){r.uniform1iv(n,o),a.forEach(function(c,u){r.activeTexture(Rt+o[u]),r.bindTexture(s,c)})}}x[Pt]={Type:Float32Array,size:4,setter:eu,arraySetter:tu},x[Vn]={Type:Float32Array,size:8,setter:ru,cols:2},x[Hn]={Type:Float32Array,size:12,setter:nu,cols:3},x[jn]={Type:Float32Array,size:16,setter:iu,cols:4},x[Ar]={Type:Int32Array,size:4,setter:ai,arraySetter:ci},x[Xn]={Type:Int32Array,size:8,setter:ui,cols:2},x[Yn]={Type:Int32Array,size:12,setter:fi,cols:3},x[Qn]={Type:Int32Array,size:16,setter:li,cols:4},x[Ir]={Type:Uint32Array,size:4,setter:su,arraySetter:ou},x[ni]={Type:Uint32Array,size:8,setter:au,cols:2},x[ii]={Type:Uint32Array,size:12,setter:cu,cols:3},x[si]={Type:Uint32Array,size:16,setter:uu,cols:4},x[qn]={Type:Uint32Array,size:4,setter:ai,arraySetter:ci},x[Kn]={Type:Uint32Array,size:8,setter:ui,cols:2},x[Jn]={Type:Uint32Array,size:12,setter:fi,cols:3},x[Zn]={Type:Uint32Array,size:16,setter:li,cols:4},x[ei]={Type:Float32Array,size:32,setter:fu,rows:2,cols:2},x[ti]={Type:Float32Array,size:48,setter:lu,rows:3,cols:3},x[ri]={Type:Float32Array,size:64,setter:du,rows:4,cols:4},x[Uc]={Type:Float32Array,size:32,setter:hu,rows:2,cols:3},x[Nc]={Type:Float32Array,size:32,setter:pu,rows:2,cols:4},x[Lc]={Type:Float32Array,size:48,setter:mu,rows:3,cols:2},x[zc]={Type:Float32Array,size:48,setter:yu,rows:3,cols:4},x[Gc]={Type:Float32Array,size:64,setter:gu,rows:4,cols:2},x[$c]={Type:Float32Array,size:64,setter:bu,rows:4,cols:3},x[Bc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:kt},x[Dc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Ct},x[Mc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Sr},x[Oc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:kt},x[Wc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Bt},x[Vc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Bt},x[Hc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Ct},x[jc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:kt},x[Xc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Sr},x[Yc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Ct},x[Qc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Bt},x[qc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:kt},x[Kc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Sr},x[Jc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Ct},x[Zc]={Type:null,size:0,setter:O,arraySetter:U,bindPoint:Bt};function Dt(r,e){return function(t){if(t.value)switch(r.disableVertexAttribArray(e),t.value.length){case 4:r.vertexAttrib4fv(e,t.value);break;case 3:r.vertexAttrib3fv(e,t.value);break;case 2:r.vertexAttrib2fv(e,t.value);break;case 1:r.vertexAttrib1fv(e,t.value);break;default:throw new Error("the length of a float constant value must be between 1 and 4!")}else r.bindBuffer(Ft,t.buffer),r.enableVertexAttribArray(e),r.vertexAttribPointer(e,t.numComponents||t.size,t.type||Pt,t.normalize||!1,t.stride||0,t.offset||0),r.vertexAttribDivisor&&r.vertexAttribDivisor(e,t.divisor||0)}}function se(r,e){return function(t){if(t.value)if(r.disableVertexAttribArray(e),t.value.length===4)r.vertexAttrib4iv(e,t.value);else throw new Error("The length of an integer constant value must be 4!");else r.bindBuffer(Ft,t.buffer),r.enableVertexAttribArray(e),r.vertexAttribIPointer(e,t.numComponents||t.size,t.type||Ar,t.stride||0,t.offset||0),r.vertexAttribDivisor&&r.vertexAttribDivisor(e,t.divisor||0)}}function Mt(r,e){return function(t){if(t.value)if(r.disableVertexAttribArray(e),t.value.length===4)r.vertexAttrib4uiv(e,t.value);else throw new Error("The length of an unsigned integer constant value must be 4!");else r.bindBuffer(Ft,t.buffer),r.enableVertexAttribArray(e),r.vertexAttribIPointer(e,t.numComponents||t.size,t.type||Ir,t.stride||0,t.offset||0),r.vertexAttribDivisor&&r.vertexAttribDivisor(e,t.divisor||0)}}function Rr(r,e,t){const n=t.size,i=t.count;return function(s){r.bindBuffer(Ft,s.buffer);const o=s.size||s.numComponents||n,a=o/i,c=s.type||Pt,d=x[c].size*o,m=s.normalize||!1,p=s.offset||0,y=d/i;for(let l=0;l<i;++l)r.enableVertexAttribArray(e+l),r.vertexAttribPointer(e+l,a,c,m,d,p+y*l),r.vertexAttribDivisor&&r.vertexAttribDivisor(e+l,s.divisor||0)}}const I={};I[Pt]={size:4,setter:Dt},I[Vn]={size:8,setter:Dt},I[Hn]={size:12,setter:Dt},I[jn]={size:16,setter:Dt},I[Ar]={size:4,setter:se},I[Xn]={size:8,setter:se},I[Yn]={size:12,setter:se},I[Qn]={size:16,setter:se},I[Ir]={size:4,setter:Mt},I[ni]={size:8,setter:Mt},I[ii]={size:12,setter:Mt},I[si]={size:16,setter:Mt},I[qn]={size:4,setter:se},I[Kn]={size:8,setter:se},I[Jn]={size:12,setter:se},I[Zn]={size:16,setter:se},I[ei]={size:4,setter:Rr,count:2},I[ti]={size:9,setter:Rr,count:3},I[ri]={size:16,setter:Rr,count:4};const xu=/ERROR:\\s*\\d+:(\\d+)/gi;function _u(r,e="",t=0){const n=[...e.matchAll(xu)],i=new Map(n.map((s,o)=>{const a=parseInt(s[1]),c=n[o+1],u=c?c.index:e.length,d=e.substring(s.index,u);return[a-1,d]}));return r.split(`\n`).map((s,o)=>{const a=i.get(o);return`${o+1+t}: ${s}${a?`\n\n^^^ ${a}`:""}`}).join(`\n`)}const di=/^[ \\t]*\\n/;function hi(r){let e=0;return di.test(r)&&(e=1,r=r.replace(di,"")),{lineOffset:e,shaderSource:r}}function Eu(r,e){return r.errorCallback(e),r.callback&&setTimeout(()=>{r.callback(`${e}\n${r.errors.join(`\n`)}`)}),null}function wu(r,e,t,n){if(n=n||Tr,!r.getShaderParameter(t,Ec)){const s=r.getShaderInfoLog(t),{lineOffset:o,shaderSource:a}=hi(r.getShaderSource(t)),c=`${_u(a,s,o)}\nError compiling ${En(r,e)}: ${s}`;return n(c),c}return""}function Fr(r,e,t){let n,i,s;if(typeof e=="function"&&(t=e,e=void 0),typeof r=="function")t=r,r=void 0;else if(r&&!Array.isArray(r)){const u=r;t=u.errorCallback,r=u.attribLocations,n=u.transformFeedbackVaryings,i=u.transformFeedbackMode,s=u.callback}const o=t||Tr,a=[],c={errorCallback(u,...d){a.push(u),o(u,...d)},transformFeedbackVaryings:n,transformFeedbackMode:i,callback:s,errors:a};{let u={};Array.isArray(r)?r.forEach(function(d,m){u[d]=e?e[m]:m}):u=r||{},c.attribLocations=u}return c}const vu=["VERTEX_SHADER","FRAGMENT_SHADER"];function Tu(r,e){if(e.indexOf("frag")>=0)return vc;if(e.indexOf("vert")>=0)return Tc}function Au(r,e,t){const n=r.getAttachedShaders(e);for(const i of n)t.has(i)&&r.deleteShader(i);r.deleteProgram(e)}const Iu=(r=0)=>new Promise(e=>setTimeout(e,r));function Su(r,e,t){const n=r.createProgram(),{attribLocations:i,transformFeedbackVaryings:s,transformFeedbackMode:o}=Fr(t);for(let a=0;a<e.length;++a){let c=e[a];if(typeof c=="string"){const u=$n(c),d=u?u.text:c;let m=r[vu[a]];u&&u.type&&(m=Tu(r,u.type)||m),c=r.createShader(m),r.shaderSource(c,hi(d).shaderSource),r.compileShader(c),r.attachShader(n,c)}}Object.entries(i).forEach(([a,c])=>r.bindAttribLocation(n,c,a));{let a=s;a&&(a.attribs&&(a=a.attribs),Array.isArray(a)||(a=Object.keys(a)),r.transformFeedbackVaryings(n,a,o||Ac))}return r.linkProgram(n),n}function Ru(r,e,t,n,i){const s=Fr(t,n,i),o=new Set(e),a=Su(r,e,s);function c(u,d){const m=Pu(u,d,s.errorCallback);return m&&Au(u,d,o),m}if(s.callback){Fu(r,a).then(()=>{const u=c(r,a);s.callback(u,u?void 0:a)});return}return c(r,a)?void 0:a}async function Fu(r,e){const t=r.getExtension("KHR_parallel_shader_compile"),n=t?(s,o)=>s.getProgramParameter(o,t.COMPLETION_STATUS_KHR):()=>!0;let i=0;do await Iu(i),i=1e3/60;while(!n(r,e))}function Pu(r,e,t){if(t=t||Tr,!r.getProgramParameter(e,wc)){const i=r.getProgramInfoLog(e);t(`Error in program linking: ${i}`);const o=r.getAttachedShaders(e).map(a=>wu(r,r.getShaderParameter(a,r.SHADER_TYPE),a,t));return`${i}\n${o.filter(a=>a).join(`\n`)}`}}function ku(r,e,t,n,i){return Ru(r,e,t,n,i)}function mi(r){const e=r.name;return e.startsWith("gl_")||e.startsWith("webgl_")}const Cu=/(\\.|\\[|]|\\w+)/g,Bu=r=>r>="0"&&r<="9";function Du(r,e,t,n){const i=r.split(Cu).filter(a=>a!=="");let s=0,o="";for(;;){const a=i[s++];o+=a;const c=Bu(a[0]),u=c?parseInt(a):a;if(c&&(o+=i[s++]),s===i.length){t[u]=e;break}else{const m=i[s++],p=m==="[",y=t[u]||(p?[]:{});t[u]=y,t=y,n[o]=n[o]||(function(l){return function(b){pi(l,b)}})(y),o+=m}}}function Mu(r,e){let t=0;function n(a,c,u){const d=c.name.endsWith("[0]"),m=c.type,p=x[m];if(!p)throw new Error(`unknown type: 0x${m.toString(16)}`);let y;if(p.bindPoint){const l=t;t+=c.size,d?y=p.arraySetter(r,m,l,u,c.size):y=p.setter(r,m,l,u,c.size)}else p.arraySetter&&d?y=p.arraySetter(r,u):y=p.setter(r,u);return y.location=u,y}const i={},s={},o=r.getProgramParameter(e,Wn);for(let a=0;a<o;++a){const c=r.getActiveUniform(e,a);if(mi(c))continue;let u=c.name;u.endsWith("[0]")&&(u=u.substr(0,u.length-3));const d=r.getUniformLocation(e,c.name);if(d){const m=n(e,c,d);i[u]=m,Du(u,m,s,i)}}return i}function Ou(r,e){const t={},n=r.getProgramParameter(e,Sc);for(let i=0;i<n;++i){const s=r.getTransformFeedbackVarying(e,i);t[s.name]={index:i,type:s.type,size:s.size}}return t}function Uu(r,e){const t=r.getProgramParameter(e,Wn),n=[],i=[];for(let a=0;a<t;++a){i.push(a),n.push({});const c=r.getActiveUniform(e,a);n[a].name=c.name}[["UNIFORM_TYPE","type"],["UNIFORM_SIZE","size"],["UNIFORM_BLOCK_INDEX","blockNdx"],["UNIFORM_OFFSET","offset"]].forEach(function(a){const c=a[0],u=a[1];r.getActiveUniforms(e,i,r[c]).forEach(function(d,m){n[m][u]=d})});const s={},o=r.getProgramParameter(e,Rc);for(let a=0;a<o;++a){const c=r.getActiveUniformBlockName(e,a),u={index:r.getUniformBlockIndex(e,c),usedByVertexShader:r.getActiveUniformBlockParameter(e,a,Fc),usedByFragmentShader:r.getActiveUniformBlockParameter(e,a,Pc),size:r.getActiveUniformBlockParameter(e,a,kc),uniformIndices:r.getActiveUniformBlockParameter(e,a,Cc)};u.used=u.usedByVertexShader||u.usedByFragmentShader,s[c]=u}return{blockSpecs:s,uniformData:n}}function pi(r,e){for(const t in e){const n=r[t];typeof n=="function"?n(e[t]):pi(r[t],e[t])}}function gi(r,...e){const t=r.uniformSetters||r,n=e.length;for(let i=0;i<n;++i){const s=e[i];if(Array.isArray(s)){const o=s.length;for(let a=0;a<o;++a)gi(t,s[a])}else for(const o in s){const a=t[o];a&&a(s[o])}}}function Nu(r,e){const t={},n=r.getProgramParameter(e,Ic);for(let i=0;i<n;++i){const s=r.getActiveAttrib(e,i);if(mi(s))continue;const o=r.getAttribLocation(e,s.name),a=I[s.type],c=a.setter(r,o,a);c.location=o,t[s.name]=c}return t}function Lu(r,e){for(const t in e){const n=r[t];n&&n(e[t])}}function zu(r,e,t){t.vertexArrayObject?r.bindVertexArray(t.vertexArrayObject):(Lu(e.attribSetters||e,t.attribs),t.indices&&r.bindBuffer(_c,t.indices))}function yi(r,e){const t=Mu(r,e),n=Nu(r,e),i={program:e,uniformSetters:t,attribSetters:n};return Le(r)&&(i.uniformBlockSpec=Uu(r,e),i.transformFeedbackInfo=Ou(r,e)),i}const Gu=/\\s|{|}|;/;function $u(r,e,t,n,i){const s=Fr(t,n,i),o=[];if(e=e.map(function(u){if(!Gu.test(u)){const d=$n(u);if(d)u=d.text;else{const m=`no element with id: ${u}`;s.errorCallback(m),o.push(m)}}return u}),o.length)return Eu(s,"");const a=s.callback;a&&(s.callback=(u,d)=>{a(u,u?void 0:yi(r,d))});const c=ku(r,e,s);return c?yi(r,c):null}const Wu=4,bi=5123;function Vu(r,e,t,n,i,s){t=t===void 0?Wu:t;const o=e.indices,a=e.elementType,c=n===void 0?e.numElements:n;i=i===void 0?0:i,a||o?s!==void 0?r.drawElementsInstanced(t,c,a===void 0?bi:e.elementType,i,s):r.drawElements(t,c,a===void 0?bi:e.elementType,i):s!==void 0?r.drawArraysInstanced(t,i,c,s):r.drawArrays(t,i,c)}const xi=36160,Ot=36161,Hu=3553,ju=5121,Xu=6402,Yu=6408,Qu=33190,qu=36012,Ku=35056,Ju=36013,Zu=32854,ef=32855,tf=36194,_i=33189,Ei=6401,wi=36168,Pr=34041,kr=36064,Ut=36096,vi=36128,Cr=33306,Br=33071,Dr=9729,rf=[{format:Yu,type:ju,min:Dr,wrap:Br},{format:Pr}],G={};G[Pr]=Cr,G[Ei]=vi,G[wi]=vi,G[Xu]=Ut,G[_i]=Ut,G[Qu]=Ut,G[qu]=Ut,G[Ku]=Cr,G[Ju]=Cr;function nf(r,e){return G[r]||G[e]}const oe={};oe[Zu]=!0,oe[ef]=!0,oe[tf]=!0,oe[Pr]=!0,oe[_i]=!0,oe[Ei]=!0,oe[wi]=!0;function sf(r){return oe[r]}const of=32;function af(r){return r>=kr&&r<kr+of}function Ti(r,e,t,n){const i=xi,s=r.createFramebuffer();r.bindFramebuffer(i,s),t=t||r.drawingBufferWidth,n=n||r.drawingBufferHeight,e=e||rf;const o=[],a={framebuffer:s,attachments:[],width:t,height:n};return e.forEach(function(c,u){let d=c.attachment;const m=c.samples,p=c.format;let y=c.attachmentPoint||nf(p,c.internalFormat);if(y||(y=kr+u),af(y)&&o.push(y),!d)if(m!==void 0||sf(p))d=r.createRenderbuffer(),r.bindRenderbuffer(Ot,d),m>1?r.renderbufferStorageMultisample(Ot,m,p,t,n):r.renderbufferStorage(Ot,p,t,n);else{const l=Object.assign({},c);l.width=t,l.height=n,l.auto===void 0&&(l.auto=!1,l.min=l.min||l.minMag||Dr,l.mag=l.mag||l.minMag||Dr,l.wrapS=l.wrapS||l.wrap||Br,l.wrapT=l.wrapT||l.wrap||Br),d=Gn(r,l)}if(po(r,d))r.framebufferRenderbuffer(i,y,Ot,d);else if(fr(r,d))c.layer!==void 0?r.framebufferTextureLayer(i,y,d,c.level||0,c.layer):r.framebufferTexture2D(i,y,c.target||Hu,d,c.level||0);else throw new Error("unknown attachment type");a.attachments.push(d)}),r.drawBuffers&&r.drawBuffers(o),a}function cf(r,e,t){t=t||xi,e?(r.bindFramebuffer(t,e.framebuffer),r.viewport(0,0,e.width,e.height)):(r.bindFramebuffer(t,null),r.viewport(0,0,r.drawingBufferWidth,r.drawingBufferHeight))}function D(r,e){return()=>e instanceof WebGLTexture?e:Gn(r,{src:e,wrap:r.CLAMP_TO_EDGE})}const Ce=2;class je{constructor(e){this.id="_";const{context:t,width:n,height:i}=e;this.context=t,this.options=e;const s=this.buildDefines();this.programInfo=$u(this.context,[s+this.getVertexShader(),s+this.getFragmentShader()]),this.bufferInfo=Lo(this.context,this.getBuffers()),this.fbi=Ti(this.context,[{format:this.context.RGBA,type:this.context.UNSIGNED_BYTE,min:this.context.LINEAR,wrap:this.context.CLAMP_TO_EDGE}],n,i),this.output=this.fbi.attachments[0]}resizeOutput(e,t){this.fbi=Ti(this.context,[{format:this.context.RGBA,type:this.context.UNSIGNED_BYTE,min:this.context.LINEAR,wrap:this.context.CLAMP_TO_EDGE}],e,t),this.options.width=e,this.options.height=t,this.output=this.fbi.attachments[0]}getDefines(){return{}}getBuffers(){return{position:{numComponents:2,data:[-1,-1,-1,1,1,-1,1,1,-1,1,1,-1]},texture_coord:{numComponents:2,data:[0,0,0,1,1,0,1,1,0,1,1,0]}}}buildDefines(){let e="";const t=this.getDefines();for(let n in t)e+=`#define ${n} ${t[n].toFixed(1)}\n`;return e}run(e){this.profiler?.pushContext(`[${this.id}] PROG : ${this.constructor.name}`),this.profiler?.pushContext(`[${this.id}] UNIFORMS`);for(const i in e)typeof e[i]=="function"&&(this.profiler?.pushContext(`[${this.id}] UNI : ${i}`),e[i]=e[i](),this.profiler?.popContext(`[${this.id}] UNI : ${i}`));this.profiler?.popContext(`[${this.id}] UNIFORMS`);const t=Date.now();let n=0;this.lastRun&&(n=(t-this.lastRun)/1e3),this.lastRun=t,this.context.viewport(0,0,this.context.canvas.width,this.context.canvas.height),this.context.useProgram(this.programInfo.program),zu(this.context,this.programInfo,this.bufferInfo),gi(this.programInfo,{delta:n,canvas:[this.context.canvas.width,this.context.canvas.height],...e}),cf(this.context,this.options.disableFramebuffer?null:this.fbi),Vu(this.context,this.bufferInfo),this.profiler?.popContext(`[${this.id}] PROG : ${this.constructor.name}`)}setProfiler(e){this.profiler=e}}var uf=`precision mediump float;\n\nvarying vec2 _texture_coord;\n\nuniform sampler2D background;\nuniform sampler2D foreground;\nuniform sampler2D threshold;\n\nvoid main() {\n vec4 backgroundColor = texture2D(background, _texture_coord);\n vec4 foregroundColor = texture2D(foreground, _texture_coord);\n vec4 tresholdColor = texture2D(threshold, _texture_coord);\n gl_FragColor = foregroundColor * tresholdColor.a +\n backgroundColor * (1. - tresholdColor.a);\n}\n`,ff=`varying vec2 _texture_coord;\n\nattribute vec2 position;\nattribute vec2 texture_coord;\n\nvoid main() {\n gl_Position = vec4(position, 0., 1.);\n _texture_coord = texture_coord;\n _texture_coord.y = 1. - texture_coord.y;\n}\n`;class Mr extends je{getFragmentShader(){return uf}getVertexShader(){return ff}}class Or{constructor(){this.steps=[]}addStep(e){this.steps.push(e)}async run(){for(const e of this.steps)e.program.run(e.getUniforms())}resizeOutput(e,t){this.profiler?.pushContext(`PIP [${this.constructor.name}]`);for(const n of this.steps)n.preventResize||n.program.resizeOutput(e,t);this.profiler?.popContext(`PIP [${this.constructor.name}]`)}setProfiler(e){this.profiler=e;for(const t of this.steps)t.program.setProfiler(e)}setId(e){for(const t of this.steps)t.program.id=e}}class Ur extends Or{constructor(){super(...arguments),this.preciseMaskEnabled=!1}}class Ai extends Ur{constructor(e){super(),this.context=e,this.preciseMaskEnabled=!0;const t={context:e,height:e.canvas.height,width:e.canvas.width},n=new Mr({...t,disableFramebuffer:!0});this.addStep({program:n,getUniforms:()=>({background:D(e,this.inputBackgroundImage),foreground:D(e,this.inputImage),threshold:D(e,this.inputMask)})})}setData(e,t){this.inputImage=e,this.inputMask=t}}var lf=`precision mediump float;\n\nvarying vec2 _texture_coord;\nuniform sampler2D texture;\n\nvoid main() { gl_FragColor = texture2D(texture, _texture_coord); }\n`,df=`varying vec2 _texture_coord;\n\nattribute vec2 position;\nattribute vec2 texture_coord;\nuniform bool invert_y;\n\nvoid main() {\n gl_Position = vec4(position, 0., 1.);\n _texture_coord = texture_coord;\n if (invert_y) {\n _texture_coord.y = 1. - texture_coord.y;\n }\n}\n`;class hf extends je{getFragmentShader(){return lf}getVertexShader(){return df}}class mf extends Or{constructor(e,t,n){super(),this.context=e;const i={context:e,height:n,width:t};this.addStep({program:new hf({...i,disableFramebuffer:!0}),getUniforms:()=>({texture:D(e,this.inputImage),invert_y:!0})})}setData(e){this.inputImage=e}}async function Ii(r){return new Promise(e=>{setTimeout(()=>{e()},r)})}var pf=`precision mediump float;\n\nvarying vec2 _texture_coord;\n\nuniform vec2 canvas;\nuniform sampler2D texture;\n\nvec4 loop();\n\nvoid main() { gl_FragColor = loop(); }\n`,gf=`varying vec2 _texture_coord;\n\nattribute vec2 position;\nattribute vec2 texture_coord;\n\nvoid main() {\n gl_Position = vec4(position, 0., 1.);\n _texture_coord = texture_coord;\n}\n`,Nr=(r=>(r[r.LINEAR=0]="LINEAR",r[r.GAUSSIAN=1]="GAUSSIAN",r))(Nr||{});class Si extends je{getDefines(){return{RADIUS:this.options.radius??1}}getFragmentShader(){return pf+this.createLoopFunction()}getVertexShader(){return gf}createLoopFunction(){let e=this.options.radius??1;return`\n\n vec4 loop() { \n vec4 result = vec4(0,0,0,0);\n float factorSum = 0.;\n\n vec2 normalizedRadius = vec2(-${e}.) / canvas;\n vec2 normalizedIncrement = vec2(1.) / canvas;\n vec2 diff = normalizedRadius;\n\n for(int y=-${e}; y<${e+1}; ++y) {\n for(int x=-${e}; x<${e+1}; ++x) {\n float factor = 1.;\n result += factor * texture2D(texture, _texture_coord + diff);\n factorSum += factor;\n diff.x += normalizedIncrement.x;\n }\n diff.y += normalizedIncrement.y;\n diff.x = normalizedRadius.x;\n }\n return result / factorSum;\n }`}}var yf=`#version 300 es\n// https://github.com/Volcomix/virtual-background/blob/main/src/pipelines/webgl2/jointBilateralFilterStage.ts\n\nprecision highp float;\nuniform sampler2D input_frame;\nuniform sampler2D segmentation_mask;\nuniform sampler2D threshold;\nuniform vec2 texel_size;\nuniform float step;\nuniform float radius;\nuniform float offset;\nuniform float sigma_texel;\nuniform float sigma_color;\n\nin vec2 _texture_coord;\nout vec4 outColor;\n\nfloat gaussian(float x, float sigma) {\n float coeff = -0.5 / (sigma * sigma * 4.0 + 1.0e-6);\n return exp((x * x) * coeff);\n}\n\nvoid main() {\n vec2 centerCoord = _texture_coord;\n vec3 centerColor = texture(input_frame, centerCoord).rgb;\n float newVal = 0.0;\n float spaceWeight = 0.0;\n float colorWeight = 0.0;\n float totalWeight = 0.0;\n // Subsample kernel space.\n for (float i = -radius + offset; i <= radius; i += step) {\n for (float j = -radius + offset; j <= radius; j += step) {\n vec2 shift = vec2(j, i) * texel_size;\n vec2 coord = vec2(centerCoord + shift);\n vec3 frameColor = texture(input_frame, coord).rgb;\n float threshold = texture(threshold, coord).a;\n float outVal = texture(segmentation_mask, coord).a;\n\n spaceWeight = gaussian(distance(centerCoord, coord), sigma_texel);\n colorWeight = gaussian(distance(centerColor, frameColor), sigma_color);\n totalWeight += spaceWeight * colorWeight;\n newVal += spaceWeight * colorWeight * outVal * threshold;\n }\n }\n newVal /= totalWeight;\n outColor = vec4(vec3(0.), newVal);\n}`,bf=`#version 300 es\nin vec2 position;\nin vec2 texture_coord;\nout vec2 _texture_coord;\nvoid main() {\n gl_Position = vec4(position, 0.0, 1.0);\n _texture_coord = texture_coord;\n}`;class xf extends je{getFragmentShader(){return yf}getVertexShader(){return bf}}class _f extends Or{constructor(e,t,n){super(),this.context=e;const i={context:e,height:n,width:t},s=new Si({...i,radius:1,type:Nr.GAUSSIAN});this.jointBilateral=new xf(i),this.addStep({program:s,getUniforms:()=>({inputs:D(e,this.inputMask)})}),this.addStep({program:this.jointBilateral,getUniforms:()=>{const a=this.inputImage?.width??1,c=this.inputImage?.height??1;this.inputMask?.width,this.inputMask?.height;const u=3,d=Math.max(1,Math.sqrt(u)*.66),m=1/a,p=1/c;return{input_frame:D(e,this.inputImage),segmentation_mask:D(e,this.inputMask),texel_size:[m,p],step:d,radius:u,offset:d>1?d*.5:0,sigma_texel:Math.max(m,p)*u,sigma_color:u}}}),this.output=this.jointBilateral.output}setData(e,t){this.previousInputImage=this.inputImage?this.inputImage:e,this.previousInputMask=this.inputMask?this.inputMask:t,this.inputImage=e,this.inputMask=t}resizeOutput(e,t){super.resizeOutput(e,t),this.output=this.jointBilateral.output}}class Ef{constructor(e){this.queries=[],this.context=e,this.extension=e.getExtension("EXT_disjoint_timer_query_webgl2")}start(){}stop(){this.activeQuery&&this.context.endQuery(this.extension.TIME_ELAPSED_EXT)}pushContext(e){this.createQuery("PUSH",e)}popContext(e){this.createQuery("POP",e)}createQuery(e,t){this.activeQuery&&this.context.endQuery(this.extension.TIME_ELAPSED_EXT),this.activeQuery=this.context.createQuery(),this.context.beginQuery(this.extension.TIME_ELAPSED_EXT,this.activeQuery),this.queries.push({name:t,action:e,query:this.activeQuery})}async getResolvedQueries(){const e=(await Promise.all([...this.queries].map(t=>this.resolveQuery(t)))).filter(t=>t);for(let t=1;t<e.length;++t)e[t].timestamp+=e[t-1].duration+e[t-1].timestamp;return e}async resolveQuery(e){if(!await this.awaitQueryAvailable(e)){console.log("Unawaitable query",e);return}if(this.context.getParameter(this.extension.GPU_DISJOINT_EXT)){console.log("Disjointed query",e);return}return{...e,duration:this.context.getQueryParameter(e.query,this.context.QUERY_RESULT),timestamp:0}}async awaitQueryAvailable(e){for(let t=0;t<10;++t){if(this.context.getQueryParameter(e.query,this.context.QUERY_RESULT_AVAILABLE))return e;await Ii(200)}}}class Nt{constructor(){this.previousImageWidth=0,this.previousImageHeight=0,this.previousMaskWidth=Ce,this.previousMaskHeight=Ce,this.postProcessingEnabled=!0;const e=new OffscreenCanvas(0,0),t=e.getContext("webgl2");if(!t)throw"Fail to retrieve webgl2 context";this.canvas=e,this.context=t,this.improveMask=new _f(this.context,Ce,Ce)}enablePostProcessing(){this.postProcessingEnabled=!0}disablePostProcessing(){this.postProcessingEnabled=!1}async profileWebgl(e){const t=new Ef(this.context);return this.profiler=t,t.start(),await Ii(e),this.profiler=void 0,t.stop(),t.getResolvedQueries()}async render(e,t){if(!this.pipeline)throw"missing pipeline";(this.previousImageHeight!==e.height||this.previousImageWidth!==e.width)&&this.resizeOutput(e.width,e.height),(this.previousMaskHeight!==t.height||this.previousMaskWidth!==t.width)&&(this.improveMask.resizeOutput(t.width,t.height),this.previousMaskWidth=t.width,this.previousMaskHeight=t.height);const n="renderer";this.profiler?.pushContext(n),this.improveMask.setProfiler(this.profiler),this.pipeline.setProfiler(this.profiler);const i=await createImageBitmap(t);let s=i;return this.postProcessingEnabled&&(this.improveMask.setData(e,i),this.improveMask.run(),s=this.improveMask.output),this.pipeline.setData(e,s),await this.pipeline.run(),this.profiler?.popContext(n),this.canvas}resizeOutput(e,t){this.canvas.width=e,this.canvas.height=t,this.pipeline?.resizeOutput(e,t),this.previousImageWidth=e,this.previousImageHeight=t}destroy(){const e=this.context?.getExtension("WEBGL_lose_context");e&&e.loseContext()}}class Ri extends Nt{constructor(){super(),this.pipeline=new Ai(this.context);const e=new OffscreenCanvas(0,0),t=e.getContext("webgl2");if(!t)throw"Fail to retrieve webgl context";this.backgroundImageResizerCanvas=e,this.backgroundImageResizerContext=t,this.backgroundImageResizer=new mf(this.backgroundImageResizerContext,0,0)}setBackgroundImage(e){this.backgroundImage=e,this.updateBackgroundImage()}updateBackgroundImage(){const{width:e,height:t}=this.canvas;this.backgroundImageResizer.resizeOutput(e,t),this.backgroundImageResizer.setData(this.backgroundImage),this.backgroundImageResizer.run(),this.pipeline.inputBackgroundImage=this.backgroundImageResizerCanvas}resizeOutput(e,t){super.resizeOutput(e,t),this.backgroundImageResizerCanvas.width=e,this.backgroundImageResizerCanvas.height=t,this.backgroundImageResizer.resizeOutput(e,t),this.updateBackgroundImage()}destroy(){const e=this.backgroundImageResizerContext?.getExtension("WEBGL_lose_context");e&&e.loseContext(),super.destroy()}}class wf extends Ri{setBackgroundVideo(e){this.frameReader=e}async render(e,t){return await this.readNextVideoFrame(),super.render(e,t)}async readNextVideoFrame(){const e=await this.frameReader?.read();if(e?.value){const t=await createImageBitmap(e.value);this.setBackgroundImage(t),e.value.close()}}}class Fi{blurBackground(e){return new to(e)}blurSilhouette(e){return new ro(e)}imageBackground(){return new no}videoBackground(){return new wf}}var vf=`precision mediump float;\n\nvarying vec2 _texture_coord;\n\nuniform vec2 canvas;\nuniform sampler2D texture;\nuniform sampler2D mask;\n\nvec4 loop();\n\nvoid main() { gl_FragColor = loop(); }\n`,Tf=`varying vec2 _texture_coord;\n\nattribute vec2 position;\nattribute vec2 texture_coord;\n\nvoid main() {\n gl_Position = vec4(position, 0., 1.);\n _texture_coord = texture_coord;\n}\n`;class Af extends je{getDefines(){return{RADIUS:this.options.radius??1}}getFragmentShader(){return vf+this.createLoopFunction()}getVertexShader(){return Tf}createLoopFunction(){let e=this.options.radius??1;return`\n\n vec4 loop() { \n vec4 result = vec4(0,0,0,0);\n float factorSum = 0.;\n\n vec2 normalizedRadius = vec2(-${e}.) / canvas;\n vec2 normalizedIncrement = vec2(1.) / canvas;\n vec2 diff = normalizedRadius;\n float maxLength = length(normalizedRadius);\n\n for(int y=-${e}; y<${e+1}; ++y) {\n for(int x=-${e}; x<${e+1}; ++x) {\n float factor = (1.- texture2D(mask, _texture_coord + diff).a) * (maxLength - length(diff)) / maxLength;\n result += factor * texture2D(texture, _texture_coord + diff);\n factorSum += factor;\n diff.x += normalizedIncrement.x;\n }\n diff.y += normalizedIncrement.y;\n diff.x = normalizedRadius.x;\n }\n return result / factorSum;\n }`}}const If=10,Sf=2,Rf=8;class Ff extends Ur{constructor(e,t){super(),this.context=e,this.radius=t;const n={context:e,height:e.canvas.height,width:e.canvas.width};this.blur=new Af({...n,radius:t,...this.getBlurTextureSize(e.canvas.width,e.canvas.height)});const i=new Mr({...n,disableFramebuffer:!0});this.addStep({program:this.blur,preventResize:!0,getUniforms:()=>({texture:D(e,this.inputImage),mask:D(e,this.inputMask)})}),this.addStep({program:i,getUniforms:()=>({background:D(e,this.blur.output),foreground:D(e,this.inputImage),threshold:D(e,this.inputMask)})})}getBlurTextureSize(e,t){const n=this.radius>If?Rf:Sf;return{width:Math.max(Ce,e/n),height:Math.max(Ce,t/n)}}setData(e,t){this.inputImage=e,this.inputMask=t}resizeOutput(e,t){super.resizeOutput(e,t);const n=this.getBlurTextureSize(e,t);this.blur.resizeOutput(n.width,n.height)}}class Pf extends Nt{constructor(e){super(),this.pipeline=new Ff(this.context,e),this.disablePostProcessing()}}class kf extends Ur{constructor(e,t){super(),this.context=e;const n={context:e,height:e.canvas.height,width:e.canvas.width},i=new Si({...n,radius:t,type:Nr.GAUSSIAN}),s=new Mr({...n,disableFramebuffer:!0});this.addStep({program:i,getUniforms:()=>({texture:D(e,this.inputImage)})}),this.addStep({program:s,getUniforms:()=>({background:D(e,this.inputImage),foreground:D(e,i.output),threshold:D(e,this.inputMask)})})}setData(e,t){this.inputImage=e,this.inputMask=t}}class Cf extends Nt{constructor(e){super(),this.pipeline=new kf(this.context,e),this.disablePostProcessing()}}class Bf extends Ai{constructor(){super(...arguments),this.preciseMaskEnabled=!0}set reader(e){this.frameReader=e}async run(){this.frameReader&&(await this.readNextVideoFrame(),await super.run())}async readNextVideoFrame(){const e=await this.frameReader?.read();e?.value&&(this.inputBackgroundImage=await createImageBitmap(e.value),e.value.close())}}class Df extends Nt{constructor(){super(),this.pipeline=new Bf(this.context)}setBackgroundVideo(e){this.pipeline.reader=e}}class Pi{blurBackground(e){return new Pf(e)}blurSilhouette(e){return new Cf(e)}imageBackground(){return new Ri}videoBackground(){return new Df}}class Mf{constructor(e){switch(e){case gt.CANVAS:this.factory=new Fi;break;case gt.WEBGL:this.factory=new Pi;break;default:const t=eo();this.factory=t.supported?new Pi:new Fi}}blurBackground(e){return this.getFactory().blurBackground(e)}blurSilhouette(e){return this.getFactory().blurSilhouette(e)}imageBackground(){return this.getFactory().imageBackground()}videoBackground(){return this.getFactory().videoBackground()}getFactory(){if(!this.factory)throw"Factory is not initialized";return this.factory}}class Of{setBackgroundOptions(e){this.renderer&&this.renderer.destroy();const t=new Mf(e.renderingOptions?.type);switch(e.transformerType){case"BackgroundBlur":this.renderer=t.blurBackground(this.getBlurSize(e.radius));break;case"SilhouetteBlur":this.renderer=t.blurSilhouette(this.getBlurSize(e.radius));break;case"VideoBackground":const n=t.videoBackground();this.backgroundVideo&&n.setBackgroundVideo(this.backgroundVideo),this.renderer=n;break;case"VirtualBackground":const i=t.imageBackground();this.backgroundImage&&i.setBackgroundImage(this.backgroundImage),this.renderer=i;break;default:throw`Unknown rendering type [${e.transformerType}]`}e.renderingOptions?.type===gt.WEBGL&&(e.renderingOptions.selfieSegmentationType===tr.PRECISE?this.renderer.enablePostProcessing():e.renderingOptions.selfieSegmentationType===tr.FAST&&this.renderer.disablePostProcessing())}setVideoBGReadable(e){this.backgroundVideo=e.getReader();const t=this.renderer;t?.setBackgroundVideo&&t.setBackgroundVideo(this.backgroundVideo)}async setVirtualBGImage(e){const t=this.renderer;t?.setBackgroundImage&&t.setBackgroundImage(e),this.backgroundImage=e}async process(e,t){if(this.renderer)return this.renderer.render(e,t)}async resizeForeground(e,t){}getBlurSize(e=pt.Low){switch(e){case pt.Low:return 5;case pt.High:return 12}return e}async profile(e){return this.renderer?.profileWebgl(e)??[]}}var Uf=(function(){var r=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0;return(function(e){e=e||{};var t=typeof e<"u"?e:{},n,i;t.ready=new Promise(function(f,h){n=f,i=h});var s={},o;for(o in t)t.hasOwnProperty(o)&&(s[o]=t[o]);var a="./this.program",c=function(f,h){throw h},u=!0,d="";function m(f){return t.locateFile?t.locateFile(f,d):d+f}var p;typeof document<"u"&&document.currentScript&&(d=document.currentScript.src),r&&(d=r),d.indexOf("blob:")!==0?d=d.substr(0,d.replace(/[?#].*/,"").lastIndexOf("/")+1):d="";var y=t.print||console.log.bind(console),l=t.printErr||console.warn.bind(console);for(o in s)s.hasOwnProperty(o)&&(t[o]=s[o]);s=null,t.arguments&&t.arguments,t.thisProgram&&(a=t.thisProgram),t.quit&&(c=t.quit);var b;t.wasmBinary&&(b=t.wasmBinary),t.noExitRuntime,typeof WebAssembly!="object"&&ae("no native wasm support detected");var _,E=!1,R=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0;function k(f,h,g){for(var w=h+g,S=h;f[S]&&!(S>=w);)++S;if(S-h>16&&f.subarray&&R)return R.decode(f.subarray(h,S));for(var C="";h<S;){var v=f[h++];if(!(v&128)){C+=String.fromCharCode(v);continue}var M=f[h++]&63;if((v&224)==192){C+=String.fromCharCode((v&31)<<6|M);continue}var H=f[h++]&63;if((v&240)==224?v=(v&15)<<12|M<<6|H:v=(v&7)<<18|M<<12|H<<6|f[h++]&63,v<65536)C+=String.fromCharCode(v);else{var Li=v-65536;C+=String.fromCharCode(55296|Li>>10,56320|Li&1023)}}return C}function N(f,h){return f?k(Xe,f,h):""}function Q(f,h,g){for(var w=0;w<f.length;++w)Lt[h++>>0]=f.charCodeAt(w);Lt[h>>0]=0}function q(f,h){return f%h>0&&(f+=h-f%h),f}var L,Lt,Xe,$;function Ci(f){L=f,t.HEAP8=Lt=new Int8Array(f),t.HEAP16=new Int16Array(f),t.HEAP32=$=new Int32Array(f),t.HEAPU8=Xe=new Uint8Array(f),t.HEAPU16=new Uint16Array(f),t.HEAPU32=new Uint32Array(f),t.HEAPF32=new Float32Array(f),t.HEAPF64=new Float64Array(f)}t.INITIAL_MEMORY;var zr,Bi=[],Di=[],Mi=[];function Yf(){if(t.preRun)for(typeof t.preRun=="function"&&(t.preRun=[t.preRun]);t.preRun.length;)Kf(t.preRun.shift());Gr(Bi)}function Qf(){Gr(Di)}function qf(){if(t.postRun)for(typeof t.postRun=="function"&&(t.postRun=[t.postRun]);t.postRun.length;)Zf(t.postRun.shift());Gr(Mi)}function Kf(f){Bi.unshift(f)}function Jf(f){Di.unshift(f)}function Zf(f){Mi.unshift(f)}var be=0,Ye=null;function el(f){be++,t.monitorRunDependencies&&t.monitorRunDependencies(be)}function tl(f){if(be--,t.monitorRunDependencies&&t.monitorRunDependencies(be),be==0&&Ye){var h=Ye;Ye=null,h()}}t.preloadedImages={},t.preloadedAudios={};function ae(f){t.onAbort&&t.onAbort(f),f="Aborted("+f+")",l(f),E=!0,f+=". Build with -s ASSERTIONS=1 for more info.";var h=new WebAssembly.RuntimeError(f);throw i(h),h}var rl="data:application/octet-stream;base64,";function Oi(f){return f.startsWith(rl)}var W;W="tflite-simd.wasm",Oi(W)||(W=m(W));function Ui(f){try{if(f==W&&b)return new Uint8Array(b);if(!p)throw"both async and sync fetching of the wasm failed"}catch(h){ae(h)}}function nl(){return!b&&u&&typeof fetch=="function"?fetch(W,{credentials:"same-origin"}).then(function(f){if(!f.ok)throw"failed to load wasm binary file at \'"+W+"\'";return f.arrayBuffer()}).catch(function(){return Ui(W)}):Promise.resolve().then(function(){return Ui(W)})}function il(){var f={a:Al};function h(v,M){var H=v.exports;t.asm=H,_=t.asm.q,Ci(_.buffer),zr=t.asm.E,Jf(t.asm.r),tl()}el();function g(v){h(v.instance)}function w(v){return nl().then(function(M){return WebAssembly.instantiate(M,f)}).then(function(M){return M}).then(v,function(M){l("failed to asynchronously prepare wasm: "+M),ae(M)})}function S(){return!b&&typeof WebAssembly.instantiateStreaming=="function"&&!Oi(W)&&typeof fetch=="function"?fetch(W,{credentials:"same-origin"}).then(function(v){var M=WebAssembly.instantiateStreaming(v,f);return M.then(g,function(H){return l("wasm streaming compile failed: "+H),l("falling back to ArrayBuffer instantiation"),w(g)})}):w(g)}if(t.instantiateWasm)try{var C=t.instantiateWasm(f,h);return C}catch(v){return l("Module.instantiateWasm callback failed with error: "+v),!1}return S().catch(i),{}}function Gr(f){for(;f.length>0;){var h=f.shift();if(typeof h=="function"){h(t);continue}var g=h.func;typeof g=="number"?h.arg===void 0?zr.get(g)():zr.get(g)(h.arg):g(h.arg===void 0?null:h.arg)}}function sl(f,h,g,w){ae("Assertion failed: "+N(f)+", at: "+[h?N(h):"unknown filename",g,w?N(w):"unknown function"])}function ol(f,h){ae("To use dlopen, you need to use Emscripten\'s linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking")}function al(f,h){ae("To use dlopen, you need to use Emscripten\'s linking support, see https://github.com/emscripten-core/emscripten/wiki/Linking")}function cl(){ae("")}var zt;zt=function(){return performance.now()};var ul=!0;function fl(f){return $[Ni()>>2]=f,f}function ll(f,h){var g;if(f===0)g=Date.now();else if((f===1||f===4)&&ul)g=zt();else return fl(28),-1;return $[h>>2]=g/1e3|0,$[h+4>>2]=g%1e3*1e3*1e3|0,0}function dl(){return 2147483648}function hl(f,h,g){Xe.copyWithin(f,h,h+g)}function ml(f){try{return _.grow(f-L.byteLength+65535>>>16),Ci(_.buffer),1}catch{}}function pl(f){var h=Xe.length;f=f>>>0;var g=2147483648;if(f>g)return!1;for(var w=1;w<=4;w*=2){var S=h*(1+.2/w);S=Math.min(S,f+100663296);var C=Math.min(g,q(Math.max(f,S),65536)),v=ml(C);if(v)return!0}return!1}function gl(f){for(var h=zt();zt()-h<f;);}var $r={};function yl(){return a||"./this.program"}function Qe(){if(!Qe.strings){var f=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",h={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:f,_:yl()};for(var g in $r)$r[g]===void 0?delete h[g]:h[g]=$r[g];var w=[];for(var g in h)w.push(g+"="+h[g]);Qe.strings=w}return Qe.strings}var Gt={mappings:{},buffers:[null,[],[]],printChar:function(f,h){var g=Gt.buffers[f];h===0||h===10?((f===1?y:l)(k(g,0)),g.length=0):g.push(h)},varargs:void 0,get:function(){Gt.varargs+=4;var f=$[Gt.varargs-4>>2];return f},getStr:function(f){var h=N(f);return h},get64:function(f,h){return f}};function bl(f,h){var g=0;return Qe().forEach(function(w,S){var C=h+g;$[f+S*4>>2]=C,Q(w,C),g+=w.length+1}),0}function xl(f,h){var g=Qe();$[f>>2]=g.length;var w=0;return g.forEach(function(S){w+=S.length+1}),$[h>>2]=w,0}function _l(f){Sl(f)}function El(f){return 0}function wl(f,h,g,w,S){}function vl(f,h,g,w){for(var S=0,C=0;C<g;C++){for(var v=$[h+C*8>>2],M=$[h+(C*8+4)>>2],H=0;H<M;H++)Gt.printChar(f,Xe[v+H]);S+=M}return $[w>>2]=S,0}function Tl(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var f=new Uint8Array(1);return function(){return crypto.getRandomValues(f),f[0]}}else return function(){ae("randomDevice")}}function $t(f,h){$t.randomDevice||($t.randomDevice=Tl());for(var g=0;g<h;g++)Lt[f+g>>0]=$t.randomDevice();return 0}var Al={a:sl,e:ol,d:al,b:cl,n:ll,h:dl,l:hl,m:pl,p:gl,f:bl,g:xl,j:_l,i:El,k:wl,c:vl,o:$t};il(),t.___wasm_call_ctors=function(){return(t.___wasm_call_ctors=t.asm.r).apply(null,arguments)},t._getModelBufferMemoryOffset=function(){return(t._getModelBufferMemoryOffset=t.asm.s).apply(null,arguments)},t._getInputMemoryOffset=function(){return(t._getInputMemoryOffset=t.asm.t).apply(null,arguments)},t._getInputHeight=function(){return(t._getInputHeight=t.asm.u).apply(null,arguments)},t._getInputWidth=function(){return(t._getInputWidth=t.asm.v).apply(null,arguments)},t._getInputChannelCount=function(){return(t._getInputChannelCount=t.asm.w).apply(null,arguments)},t._getOutputMemoryOffset=function(){return(t._getOutputMemoryOffset=t.asm.x).apply(null,arguments)},t._getOutputHeight=function(){return(t._getOutputHeight=t.asm.y).apply(null,arguments)},t._getOutputWidth=function(){return(t._getOutputWidth=t.asm.z).apply(null,arguments)},t._getOutputChannelCount=function(){return(t._getOutputChannelCount=t.asm.A).apply(null,arguments)},t._loadModel=function(){return(t._loadModel=t.asm.B).apply(null,arguments)},t._runInference=function(){return(t._runInference=t.asm.C).apply(null,arguments)},t._isGPUEnabled=function(){return(t._isGPUEnabled=t.asm.D).apply(null,arguments)};var Ni=t.___errno_location=function(){return(Ni=t.___errno_location=t.asm.F).apply(null,arguments)},Wt;function Il(f){this.name="ExitStatus",this.message="Program terminated with exit("+f+")",this.status=f}Ye=function f(){Wt||Wr(),Wt||(Ye=f)};function Wr(f){if(be>0||(Yf(),be>0))return;function h(){Wt||(Wt=!0,t.calledRun=!0,!E&&(Qf(),n(t),t.onRuntimeInitialized&&t.onRuntimeInitialized(),qf()))}t.setStatus?(t.setStatus("Running..."),setTimeout(function(){setTimeout(function(){t.setStatus("")},1),h()},1)):h()}t.run=Wr;function Sl(f,h){Rl(f)}function Rl(f){c(f,new Il(f))}if(t.preInit)for(typeof t.preInit=="function"&&(t.preInit=[t.preInit]);t.preInit.length>0;)t.preInit.pop()();return Wr(),e.ready})})();class Nf{constructor(){this.isSIMDSupported=!1,this.isThreadsSupported=!1,this.inputWidth=0,this.inputHeight=0,this.inputChannelCount=0,this.inputMemoryOffset=0,this.outputWidth=0,this.outputHeight=0,this.outputChannelCount=0,this.outputMemoryOffset=0}}const Lf="https://d3opqjmqzxf057.cloudfront.net/vonage-tensorflow-wasm/tflite-simd-wasm/1.1.3/",zf="https://d3opqjmqzxf057.cloudfront.net/ml/selfie_segmentation/4.0.0/selfie_segmentation_landscape.tflite";async function Gf(r=Lf,e=zf){let t=new Nf;var n=new Promise(function(i,s){async function o(){return Uf({locateFile:function(u){return r+u}})}async function a(c){return new Promise(async(u,d)=>{const m=c;if(typeof m>"u")return d("TFLite backend unavailable: wasmSimd");let p=e;console.log("TFLite modelUrl: "+p);try{const l=await(await fetch(p)).arrayBuffer();console.log("Model buffer size:",l.byteLength);const b=m._getModelBufferMemoryOffset();console.log("Model buffer memory offset:",b),console.log("Loading model buffer..."),m.HEAPU8.set(new Uint8Array(l),b);const _=m._loadModel(l.byteLength);if(console.log("Load model result:",_),_!==0){d("Cannot load model");return}t.inputWidth=m._getInputWidth(),t.inputHeight=m._getInputHeight(),t.inputChannelCount=m._getInputChannelCount(),t.inputMemoryOffset=m._getInputMemoryOffset(),console.log("Input memory offset:",t.inputMemoryOffset),console.log("Input height:",t.inputHeight),console.log("Input width:",t.inputWidth),console.log("Input channels:",t.inputChannelCount),t.outputMemoryOffset=m._getOutputMemoryOffset(),t.outputWidth=m._getOutputWidth(),t.outputHeight=m._getOutputHeight(),t.outputChannelCount=m._getOutputChannelCount(),console.log("Output memory offset:",t.outputMemoryOffset),console.log("Output height:",t.outputHeight),console.log("Output width:",t.outputWidth),console.log("Output channels:",t.outputChannelCount),t.selectedTFLite=m}catch(y){d(y);return}u()})}o().then(c=>{if(c===null)throw console.error("loadTFLite null"),"loadTFLite null";a(c).then(u=>{i(t)}).catch(u=>{console.error("loadTFLiteModel error"),s("loadTFLiteModel error")})}).catch(c=>{console.error("loadTFLite error:",c),s("loadTFLite error:"+c)})});return n}const $f=.1,Wf=.7,Vf="https://d3opqjmqzxf057.cloudfront.net/ml/vonage_selfie_segmenter/float16/v1/vonage_selfie_segmenter.tflite";class Hf{constructor(){this.canvas=new OffscreenCanvas(0,0),this.context=this.canvas.getContext("2d",{willReadFrequently:!0}),this.width=0,this.height=0,this.gpuDelegate=!0}async createImageSegmenter(){if(!this.ImageSegmenter||!this.wasmFileset){console.warn("Mediapipe objects not loaded");return}this.imageSegmenter=await this.ImageSegmenter.createFromOptions(this.wasmFileset,{baseOptions:{modelAssetPath:this.modelAssetUriPath,delegate:this.gpuDelegate?"GPU":"CPU"},runningMode:"VIDEO",outputCategoryMask:!0,outputConfidenceMasks:!0})}async loadMediapipeAssets(e,t){this.modelAssetUriPath=e||Vf;const n=t?`${t}/task-vision.js`:"https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.20/+esm",i=t?`${t}/wasm`:"https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.20/wasm",{FilesetResolver:s,ImageSegmenter:o}=await import(n);this.ImageSegmenter=o,this.wasmFileset=await s.forVisionTasks(i)}async init(e,t,n){n===!1&&(this.gpuDelegate=!1),await this.loadMediapipeAssets(e,t),globalThis.document={},await this.createImageSegmenter()}async process(e){if(!this.imageSegmenter){console.warn("ImageSegmenter instance not available");return}(this.width!==e.width||this.height!==e.height)&&(this.canvas.width=this.width=e.width,this.canvas.height=this.height=e.height,this.mask&&(this.mask=new ImageData(this.width,this.height))),this.mask||(this.mask=new ImageData(this.width,this.height)),this.context.drawImage(e,0,0,e.width,e.height);const t=Date.now();let n;try{this.imageSegmenter?.segmentForVideo(this.context.getImageData(0,0,e.width,e.height),t,o=>{n=o.confidenceMasks?.[0]?.getAsFloat32Array()})}catch{await this.createImageSegmenter();return}if(!n)return;if(!this.previousConfidenceMask){this.previousConfidenceMask=n.slice();return}const i=n.map((o,a)=>{const c=this.previousConfidenceMask?.[a];return c!==void 0?this.blend(c,o):o}),s=[255,0,0];for(let o=0;o<i?.length;o++){const a=1-i[o];a>$f?(a<Wf?(this.mask.data[o*4]=s[0]*a,this.mask.data[o*4+3]=255*a):(this.mask.data[o*4]=s[0],this.mask.data[o*4+3]=255),this.mask.data[o*4+1]=s[1],this.mask.data[o*4+2]=s[2]):this.mask.data[o*4]=this.mask.data[o*4+1]=this.mask.data[o*4+2]=this.mask.data[o*4+3]=0}return this.previousConfidenceMask=i.slice(),this.mask}isGpuSupported(){return!0}blend(e,t){const i=-.748699,s=-57.8051,o=291.309,a=-624.717,c=t-.5,u=c*c,d=1-Math.min(1,u*(5.68842+u*(i+u*(s+u*(o+u*a)))));return t+(e-t)*(d*.9)}}class jf{constructor(){this.canvas=new OffscreenCanvas(0,0),this.context=this.canvas.getContext("2d",{willReadFrequently:!0}),this.pixelCount=0,this.inputOffset=0,this.outputOffset=0}async init(e,t,n){await this.initWasm(t,e),this.infos&&(this.canvas.width=this.infos.inputWidth,this.canvas.height=this.infos.inputHeight,this.pixelCount=this.infos.inputWidth*this.infos.inputHeight,this.mask=new ImageData(this.infos.inputWidth,this.infos.inputHeight),this.inputOffset=this.infos.inputMemoryOffset/4,this.outputOffset=this.infos.outputMemoryOffset/4)}async initWasm(e,t){this.infos=await Gf(e,t)}async process(e){if(!this.mask||!this.infos)return;const t=this.infos.inputWidth,n=this.infos.inputHeight;this.context.drawImage(e,0,0,e.width,e.height,0,0,t,n);const i=this.context.getImageData(0,0,t,n),s=this.infos.selectedTFLite.HEAPF32;for(let o=0;o<this.pixelCount;o++){const a=this.inputOffset+o*3;s[a]=i.data[o*4]/255,s[a+1]=i.data[o*4+1]/255,s[a+2]=i.data[o*4+2]/255}this.infos.selectedTFLite._runInference();for(let o=0;o<this.pixelCount;o++){const a=this.infos.selectedTFLite.HEAPF32[this.outputOffset+o];this.mask.data[o*4]=this.mask.data[o*4+3]=255*a}return this.mask}isGpuSupported(){return this.infos?.selectedTFLite?._isGPUEnabled()??!1}}class Xf{constructor(){this.reporter=new Js,this.isEnabled=!0}async init(e,t){t.segmentationOptions?.lightWeightEngine===!0?this.selfieSegmentation=new jf:this.selfieSegmentation=new Hf,this.selfieSegmentation?.init(t.modelAssetUriPath,t.mediapipeBaseAssetsUri,t.segmentationOptions?.gpuSupport),this.backgroundFilter=new Of,this.report({variation:"Create"})}async transform(e,t){if(!this.isEnabled)return t.enqueue(e);let n;const i=e.timestamp??0,s=await createImageBitmap(e),o=await this.selfieSegmentation?.process(s);o&&(n=await this.backgroundFilter?.process(s,o)),n?(e.close(),t.enqueue(new VideoFrame(n,{timestamp:i,alpha:"discard"}))):t.enqueue(e)}async setBackgroundOptions(e){this.backgroundOptions=e,this.backgroundFilter?.setBackgroundOptions(e),this.report({variation:"Update"})}setVideoBGReadable(e){this.backgroundFilter?.setVideoBGReadable(e)}async setVirtualBGImage(e){await this.backgroundFilter?.setVirtualBGImage(e)}async profile(e){return this.backgroundFilter?.profile(e)??[]}getTransformerType(){return this.backgroundOptions?.transformerType??"Undefined"}enable(){this.isEnabled=!0}disable(){this.isEnabled=!1}report(e){this.reporter.send({version:Zs,action:"MlTransformers",transformerType:this.backgroundOptions?.transformerType,config:JSON.stringify(this.backgroundOptions),...e})}}const Lr=class Lr{constructor(){this.backgroundTransformer=new Xf,this.mediaProcessor=new Rs,this.rate=30,this.eventsQueue=[],this.frameTransformLatencyMs=[]}async init(e,t){this.frameTransformLatencyMs=[],await this.backgroundTransformer.init(e,t),await this.mediaProcessor.setTransformers([this.backgroundTransformer]),this.mediaProcessor.setTrackExpectedRate(this.rate),this.mediaProcessor.onAny((n,i)=>{this.resolveOnMediaProcessor?(this.resolveOnMediaProcessor({name:n,data:i}),this.resolveOnMediaProcessor=void 0):this.eventsQueue.push({name:n,data:i})})}enable(){this.backgroundTransformer.enable()}disable(){this.backgroundTransformer.disable()}async onMediaProcessorEvent(){return await new Promise(e=>{this.eventsQueue.length>0?e(this.eventsQueue.shift()):this.resolveOnMediaProcessor=e})}async setTrackExpectedRate(e){this.rate=e,this.mediaProcessor.setTrackExpectedRate(e)}async transform(e,t){let n=this.mediaProcessor.transform(e,t),i=performance.now();return this.frameTransformLatencyMs.push(performance.now()-i),n}async setBackgroundOptions(e){await this.backgroundTransformer?.setBackgroundOptions(e)}setVideoBGReadable(e){this.backgroundTransformer.setVideoBGReadable(e)}async setVirtualBGImage(e){await this.backgroundTransformer.setVirtualBGImage(e)}async terminate(){await this.mediaProcessor.destroy();const t=this.frameTransformLatencyMs.reduce((n,i)=>n+i,0)/this.frameTransformLatencyMs.length||0;console.log(`Transform latency average is: ${t} ms`)}setVonageMetadata(e){_s(e)}async profile(e){return JSON.stringify(await this.backgroundTransformer.profile(e))}};Vi("ProcessorWorker",Lr);let ki=Lr})();\n//# sourceMappingURL=processor-worker-BCzl4yxZ.js.map\n', ii = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", _o], { type: "text/javascript;charset=utf-8" });
5150
+ function Fd(r) {
5147
5151
  let e;
5148
5152
  try {
5149
5153
  if (e = ii && (self.URL || self.webkitURL).createObjectURL(ii), !e) throw "";
@@ -5208,7 +5212,7 @@ const Jt = class Jt extends et {
5208
5212
  }
5209
5213
  }
5210
5214
  async startWorker() {
5211
- !this.config || this.worker || (this.worker = await sa(Mr, Pd), this.isEnabled || await this.worker.disable(), await this.worker.init(
5215
+ !this.config || this.worker || (this.worker = await aa(Mr, Fd), this.isEnabled || await this.worker.disable(), await this.worker.init(
5212
5216
  `worker_${Jt.initCount++}`,
5213
5217
  this.config
5214
5218
  ), await this.worker.setVonageMetadata(Tt()), this.backgroundOptions ? await this.setBackgroundOptions(this.backgroundOptions) : await this.setBackgroundOptions(this.config), this.listenWorker());
@@ -5237,7 +5241,7 @@ const Jt = class Jt extends et {
5237
5241
  };
5238
5242
  Jt.initCount = 0;
5239
5243
  let Br = Jt;
5240
- class Fd {
5244
+ class Cd {
5241
5245
  constructor(e) {
5242
5246
  this.queries = e;
5243
5247
  }
@@ -5288,7 +5292,7 @@ const gn = class gn extends et {
5288
5292
  * @internal
5289
5293
  */
5290
5294
  constructor(e) {
5291
- super(), this.worker = new Br(e), this.connector = new js(this.worker), this.worker.onAny(
5295
+ super(), this.worker = new Br(e), this.connector = new Ys(this.worker), this.worker.onAny(
5292
5296
  (t, n) => this.emit(t, n)
5293
5297
  );
5294
5298
  }
@@ -5343,7 +5347,7 @@ const gn = class gn extends et {
5343
5347
  const t = await Promise.all(
5344
5348
  this.instances.map((n) => n.profile(e))
5345
5349
  );
5346
- return new Fd(t);
5350
+ return new Cd(t);
5347
5351
  }
5348
5352
  /**
5349
5353
  * Asynchronous constructor of VonageMediaProcessor
@@ -5357,21 +5361,21 @@ const gn = class gn extends et {
5357
5361
  };
5358
5362
  gn.instances = [];
5359
5363
  let Dr = gn;
5360
- async function Bd(r) {
5364
+ async function Dd(r) {
5361
5365
  return await Dr.create(r);
5362
5366
  }
5363
5367
  export {
5364
- kd as BackgroundTransformer,
5365
- Ys as BackgroundTransformerType,
5368
+ Pd as BackgroundTransformer,
5369
+ Qs as BackgroundTransformerType,
5366
5370
  It as BlurRadius,
5367
- Ds as ErrorFunction,
5371
+ Us as ErrorFunction,
5368
5372
  Er as PipelineInfoData,
5369
5373
  Mt as RenderingType,
5370
5374
  Dr as VonageMediaProcessor,
5371
- Bs as WarningType,
5375
+ Ds as WarningType,
5372
5376
  Ar as WebglSelfieSegmentationType,
5373
- Bd as createVonageMediaProcessor,
5374
- qs as getSupportedBrowserFeatures,
5375
- Md as isSupported
5377
+ Dd as createVonageMediaProcessor,
5378
+ Xs as getSupportedBrowserFeatures,
5379
+ Bd as isSupported
5376
5380
  };
5377
5381
  //# sourceMappingURL=ml-transformers.es.js.map