@roomle/embedding-lib 7.3.0-alpha.4 → 8.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,5 @@
1
- import { n as e } from "./comlink-Dds_bpug.mjs";
2
- import { t } from "./browser-DRgK3Fk8.mjs";
3
- import { t as n } from "./utils-Co3lE-Ji.mjs";
4
- var r = class {
1
+ import { t as e } from "./browser-BxG7yIaK.mjs";
2
+ var t = class {
5
3
  _side;
6
4
  _incomingMessageBus = null;
7
5
  _outgoingMessageBus = null;
@@ -63,20 +61,20 @@ var r = class {
63
61
  _prepareError(e) {
64
62
  return typeof e == "string" ? this._side + ": " + e : (e.message = this._side + ": " + e.message, e.message);
65
63
  }
66
- }, i = [
64
+ }, n = [
67
65
  "127.0.0.1",
68
66
  "localhost",
69
67
  "0.0.0.0"
70
- ], a = (e, t) => o(JSON.parse(JSON.stringify(e)), t), o = (e, t) => {
68
+ ], r = (e, t) => i(JSON.parse(JSON.stringify(e)), t), i = (e, t) => {
71
69
  for (let n in t) try {
72
- t[n].constructor === Object ? e[n] = o(e[n], t[n]) : e[n] = t[n];
70
+ t[n].constructor === Object ? e[n] = i(e[n], t[n]) : e[n] = t[n];
73
71
  } catch {
74
72
  e[n] = t[n];
75
73
  }
76
74
  return e;
77
- }, s = function(e) {
75
+ }, a = function(e) {
78
76
  return e.BOTTOM_BAR = "bottom_bar", e.PARTLIST_BOUNDS = "partlist_bounds", e.INTERACTION_NOTES = "interaction_notes", e.PARAMETER_GROUPS = "parameter_groups", e;
79
- }({}), c = (e) => JSON.parse(JSON.stringify(e)), l = {
77
+ }({}), o = (e) => JSON.parse(JSON.stringify(e)), s = {
80
78
  mobileLandscape: !0,
81
79
  floorMaterialRootTag: "materials_root",
82
80
  buttons: {
@@ -86,7 +84,7 @@ var r = class {
86
84
  load_product: !0,
87
85
  partlist_print: !0
88
86
  },
89
- elements: { [s.INTERACTION_NOTES]: !0 },
87
+ elements: { [a.INTERACTION_NOTES]: !0 },
90
88
  helpcenter: {
91
89
  roomdesigner: !0,
92
90
  configurator: !1,
@@ -103,20 +101,21 @@ var r = class {
103
101
  openCloseAnimation: !0,
104
102
  localExport3d: !1
105
103
  },
104
+ configuratorZoom: !1,
106
105
  rotationSnapDegrees: 10,
107
106
  interactionsCollapsed: !1
108
- }, u = (e) => e.trim() !== "" && Number.isFinite(Number(e.trim())), d = (e) => {
107
+ }, c = (e) => e.trim() !== "" && Number.isFinite(Number(e.trim())), l = (e) => {
109
108
  if (!e || typeof e != "object") return;
110
109
  let t = Object.keys(e);
111
110
  for (let n of t) {
112
111
  let t = e[n];
113
- if (Array.isArray(t) || typeof t != "object" || !t || d(t), Array.isArray(t)) for (let e of t) d(e);
114
- t === "true" || t === "false" ? e[n] = t === "true" : typeof t == "string" && u(t) && (e[n] = Number(t));
112
+ if (Array.isArray(t) || typeof t != "object" || !t || l(t), Array.isArray(t)) for (let e of t) l(e);
113
+ t === "true" || t === "false" ? e[n] = t === "true" : typeof t == "string" && c(t) && (e[n] = Number(t));
115
114
  }
116
- }, f = () => {
117
- let e = c(l);
118
- e.locale ||= t(null, !0), e.id === "(idle)" && delete e.id;
119
- let n = (() => {
115
+ }, u = () => {
116
+ let t = o(s);
117
+ t.locale ||= e(null, !0), t.id === "(idle)" && delete t.id;
118
+ let r = (() => {
120
119
  let e = (() => {
121
120
  try {
122
121
  return window.self !== window.top;
@@ -131,13 +130,13 @@ var r = class {
131
130
  let { hostname: n } = new URL(t);
132
131
  return n;
133
132
  })();
134
- return n && ((e) => {
133
+ return r && ((e) => {
135
134
  let t = /* @__PURE__ */ new RegExp(/^(10\.|172\.(1[6-9]|2\d|3[01])\.|192\.168\.)/);
136
- return !!(i.includes(e) || t.test(e) || e.endsWith("roomle.com") || e.endsWith("gitlab.io") || e.endsWith("gitlab.com"));
137
- })(n) && (e.configuratorId = "demoConfigurator"), e.customApiUrl = "https://rubens.alpha.roomle.com/api/v2", e.emails = !1, e;
138
- }, p = (e) => {
135
+ return !!(n.includes(e) || t.test(e) || e.endsWith("roomle.com") || e.endsWith("gitlab.io") || e.endsWith("gitlab.com"));
136
+ })(r) && (t.configuratorId = "demoConfigurator"), t.customApiUrl = "https://rubens.alpha.roomle.com/api/v2", t.emails = !1, t;
137
+ }, d = (e) => {
139
138
  e.featureFlags ||= {}, typeof e.featureFlags.realPartList != "boolean" && (e.featureFlags.realPartList = !0), typeof e.featureFlags.globalCallbacks != "boolean" && (e.featureFlags.globalCallbacks = !0), typeof e.featureFlags.mocAr != "boolean" && (e.featureFlags.mocAr = !1);
140
- }, m = () => /(android)/i.test(navigator.userAgent), h = class {
139
+ }, f = () => /(android)/i.test(navigator.userAgent), p = class {
141
140
  _messageHandler = null;
142
141
  isSetupDone = !1;
143
142
  viewName = "main";
@@ -175,7 +174,7 @@ var r = class {
175
174
  setupPlugins(e, t, n = "website") {
176
175
  for (let r of e) typeof r == "string" && r === "dragIn" ? this.pluginsLoaded.push(new Promise((e, r) => {
177
176
  try {
178
- import("./drag-in-DDGopCLr.mjs").then((e) => e.n).then(({ DragIn: i }) => {
177
+ import("./drag-in-CV1E-DO6.mjs").then((e) => e.n).then(({ DragIn: i }) => {
179
178
  let a = new i(this.ui, t, n, this.viewName);
180
179
  a.init().then(() => {
181
180
  this.plugins.dragIn = a, e();
@@ -197,7 +196,7 @@ var r = class {
197
196
  }
198
197
  }));
199
198
  }
200
- }, g = () => {
199
+ }, m = () => {
201
200
  let e, t;
202
201
  return {
203
202
  promise: new Promise((n, r) => {
@@ -206,7 +205,7 @@ var r = class {
206
205
  resolve: e,
207
206
  reject: t
208
207
  };
209
- }, _ = {
208
+ }, h = {
210
209
  SDK: "extended",
211
210
  CONFIGURATOR_SDK: "configurator",
212
211
  CALLBACKS: "callbacks",
@@ -214,20 +213,20 @@ var r = class {
214
213
  ANALYTICS: "analytics",
215
214
  GLOBAL: "global",
216
215
  RAPI: "rapi"
217
- }, v = ".", y = _.SDK + "." + _.CALLBACKS, b = {
216
+ }, g = ".", _ = h.SDK + "." + h.CALLBACKS, v = {
218
217
  REQUEST_BOOT: "requestBoot",
219
218
  SETUP: "setup",
220
219
  WEBSITE_READY: "websiteReady"
221
- }, x = {
220
+ }, y = {
222
221
  GET_METHODS: "getMethods",
223
222
  RETURN_METHODS: "returnMethods",
224
223
  REGISTER_CUSTOM_VIEW: "registerCustomView",
225
224
  REGISTER_CUSTOM_VIEW_DONE: "registerCustomViewDone"
226
- }, S = ["constructor", "callbacks"], C = (e) => e[0] !== "_" && !S.includes(e), w = (e, t, n = !1) => {
225
+ }, b = ["constructor", "callbacks"], x = (e) => e[0] !== "_" && !b.includes(e), S = (e, t, n = !1) => {
227
226
  if (!e) return [];
228
- let r = Object.getOwnPropertyNames(e), i = n ? _.CALLBACKS + "." : "";
229
- return r.filter(C).map((e) => t + "." + i + e);
230
- }, T = async (e, t) => {
227
+ let r = Object.getOwnPropertyNames(e), i = n ? h.CALLBACKS + "." : "";
228
+ return r.filter(x).map((e) => t + "." + i + e);
229
+ }, C = async (e, t) => {
231
230
  if (typeof e != "string") throw Error("Configurator ID is not a string type: \"" + typeof e + "\"");
232
231
  let n = t.customApiUrl ? t.customApiUrl : "https://api.roomle.com/v2", r = t.overrideTenant || 9, i = n + "/configurators/" + e, a = "03-" + window.btoa((/* @__PURE__ */ new Date()).toISOString() + ";anonymous;roomle_portal_v2"), o = new Request(i, {
233
232
  method: "GET",
@@ -244,7 +243,7 @@ var r = class {
244
243
  cache: "default"
245
244
  }), { configurator: s } = await (await fetch(o)).json();
246
245
  return s;
247
- }, E = "data-rml-interaction-container", D = (e, t, n) => {
246
+ }, w = "data-rml-interaction-container", T = (e, t, n) => {
248
247
  let r = null;
249
248
  Object.defineProperty(e, t, {
250
249
  get: () => r || n,
@@ -252,32 +251,32 @@ var r = class {
252
251
  r = e?.mute ? e.value : e;
253
252
  }
254
253
  });
255
- }, O = () => .01 * window.innerHeight + "px", k = (e) => {
256
- e && setTimeout(() => e.style.setProperty(j, O()), 0);
257
- }, A = "rml-styles", j = "--rml-full-height", M = "rml-container", N = "rml-fill", P = "rml-pos", F = "rml-android-height", I = "rml-overflow-hidden", L = /* @__PURE__ */ new Map(), R = class extends h {
254
+ }, E = () => .01 * window.innerHeight + "px", D = (e) => {
255
+ e && setTimeout(() => e.style.setProperty(k, E()), 0);
256
+ }, O = "rml-styles", k = "--rml-full-height", A = "rml-container", j = "rml-fill", M = "rml-pos", N = "rml-android-height", P = "rml-overflow-hidden", F = /* @__PURE__ */ new Map(), I = class extends p {
258
257
  static createPlanner(e, t, n, r = []) {
259
258
  return this._create(e, t, n, r);
260
259
  }
261
- static async connect(e, t = []) {
262
- let n = new h();
263
- n.viewName = e;
264
- let { resolve: i, promise: a } = g(), { resolve: o, promise: s } = g(), c = new r("custom-view-" + e, window, window.parent, ({ message: e, args: t }) => {
260
+ static async connect(e, n = []) {
261
+ let r = new p();
262
+ r.viewName = e;
263
+ let { resolve: i, promise: a } = m(), { resolve: o, promise: s } = m(), c = new t("custom-view-" + e, window, window.parent, ({ message: e, args: t }) => {
265
264
  switch (e) {
266
- case x.REGISTER_CUSTOM_VIEW_DONE:
265
+ case y.REGISTER_CUSTOM_VIEW_DONE:
267
266
  i();
268
267
  break;
269
- case x.RETURN_METHODS:
270
- n.handleSetup(t[0]), o();
268
+ case y.RETURN_METHODS:
269
+ r.handleSetup(t[0]), o();
271
270
  break;
272
- default: if (n.isSetupDone) return n.executeMessage({
271
+ default: if (r.isSetupDone) return r.executeMessage({
273
272
  message: e,
274
273
  args: t
275
274
  });
276
275
  }
277
276
  });
278
- n.setMessageHandler(c);
277
+ r.setMessageHandler(c);
279
278
  let l = [e];
280
- return c.sendMessage(x.REGISTER_CUSTOM_VIEW, l), await a, c.sendMessage(x.GET_METHODS, l), await s, n.setupPlugins(t, document.body, "custom-view"), await Promise.allSettled(n.pluginsLoaded), n;
279
+ return c.sendMessage(y.REGISTER_CUSTOM_VIEW, l), await a, c.sendMessage(y.GET_METHODS, l), await s, r.setupPlugins(n, document.body, "custom-view"), await Promise.allSettled(r.pluginsLoaded), r;
281
280
  }
282
281
  static createConfigurator(e, t, n, r = []) {
283
282
  return this._create(e, t, n, r);
@@ -288,36 +287,27 @@ var r = class {
288
287
  static createViewer(e, t, n, r = []) {
289
288
  return this._create(e, t, n, r);
290
289
  }
291
- static hiMessageHandler = null;
292
- static setupHi(t) {
293
- this.hiMessageHandler && window.removeEventListener("message", this.hiMessageHandler), this.hiMessageHandler = (r) => {
294
- if (r.data.type === "connect_hi" && r.data.port) {
295
- let i = r.data.port;
296
- i.start?.(), e(n(t), i);
297
- }
298
- }, window.addEventListener("message", this.hiMessageHandler);
299
- }
300
- static async _create(e, t, n, r) {
301
- return new Promise(async (i, o) => {
290
+ static async _create(e, t, n, i) {
291
+ return new Promise(async (a, s) => {
302
292
  try {
303
- let o = ((e) => (d(e), e?.customApiUrl && (e.customApiUrl = decodeURIComponent(e.customApiUrl)), e.shareUrl && (e.deeplink = e.shareUrl.replace("<CONF_ID>", "#CONFIGURATIONID#")), e))(n), s = f();
304
- p(s);
305
- let l = await T(e, a(s, o));
293
+ let s = ((e) => (l(e), e?.customApiUrl && (e.customApiUrl = decodeURIComponent(e.customApiUrl)), e.shareUrl && (e.deeplink = e.shareUrl.replace("<CONF_ID>", "#CONFIGURATIONID#")), e))(n), c = u();
294
+ d(c);
295
+ let f = await C(e, r(c, s));
306
296
  n = ((e, t) => {
307
- let n = c(t), r = f();
308
- p(r);
309
- let i = a(a(r, e.settings || {}), n);
310
- return i.configuratorId = e.id, !i.overrideTenant && e.tenant && (i.overrideTenant = e.tenant), ((e) => {
297
+ let n = o(t), i = u();
298
+ d(i);
299
+ let a = r(r(i, e.settings || {}), n);
300
+ return a.configuratorId = e.id, !a.overrideTenant && e.tenant && (a.overrideTenant = e.tenant), ((e) => {
311
301
  let t = e.featureFlags;
312
302
  if (!t || typeof t != "object" || Array.isArray(t)) return;
313
303
  let n = t;
314
304
  !("enableTwoLevelCatalog" in n) || typeof n.enableTwoLevelCatalog != "boolean" || !1 !== e.enableTwoLevelCatalog && e.enableTwoLevelCatalog !== void 0 || (e.enableTwoLevelCatalog = n.enableTwoLevelCatalog), !("webGpu" in n) || typeof n.webGpu != "boolean" || !1 !== e.webGpu && e.webGpu !== void 0 || (e.webGpu = n.webGpu);
315
- })(i), i;
316
- })(l, o);
317
- let u = new this(l, t, n, r, i);
318
- return await Promise.allSettled(u.pluginsLoaded), u;
305
+ })(a), a;
306
+ })(f, s);
307
+ let p = new this(f, t, n, i, a);
308
+ return await Promise.allSettled(p.pluginsLoaded), p;
319
309
  } catch (e) {
320
- return o(e);
310
+ return s(e);
321
311
  }
322
312
  });
323
313
  }
@@ -326,46 +316,46 @@ var r = class {
326
316
  _configuratorSettings;
327
317
  _initData = {};
328
318
  _iframe;
329
- constructor(e, t, n, i, a) {
319
+ constructor(e, n, r, i, a) {
330
320
  if (super(), !e || typeof e.id != "string") throw Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");
331
- if (L.has(t)) throw Error("There is already an instance on this DOM element");
332
- if (!document.getElementById(A)) {
333
- let e = n.zIndex || 9999999, t = document.createElement("style");
334
- t.type = "text/css", t.id = A;
335
- let r = "transition:all ease-in-out 450ms;", i = ["-webkit-", "-o-"].reduce((e, t) => e + (t + r), "") + r;
336
- t.innerHTML = `\n .${M}{${j}:${O()};}\n .${P}{position:fixed;top:0;left:0;z-index:${e};opacity:0}\n .rml-transition{${i}}\n .${N}{width:100%;height:100%;opacity:1}\n .${F}{height:calc(var(${j},1vh)*100)}\n .${I}{overflow:hidden}\n `, document.head.appendChild(t);
321
+ if (F.has(n)) throw Error("There is already an instance on this DOM element");
322
+ if (!document.getElementById(O)) {
323
+ let e = r.zIndex || 9999999, t = document.createElement("style");
324
+ t.type = "text/css", t.id = O;
325
+ let n = "transition:all ease-in-out 450ms;", i = ["-webkit-", "-o-"].reduce((e, t) => e + (t + n), "") + n;
326
+ t.innerHTML = `\n .${A}{${k}:${E()};}\n .${M}{position:fixed;top:0;left:0;z-index:${e};opacity:0}\n .rml-transition{${i}}\n .${j}{width:100%;height:100%;opacity:1}\n .${N}{height:calc(var(${k},1vh)*100)}\n .${P}{overflow:hidden}\n `, document.head.appendChild(t);
337
327
  }
338
328
  this._executeMessage = this._executeMessage.bind(this);
339
- let o = new r("website", window, null, this._executeMessage);
340
- this.setMessageHandler(o), this._onResize = this._onResize.bind(this), m() && window.addEventListener("resize", this._onResize), this._container = t, this._initData = n, this._configuratorSettings = e;
329
+ let o = new t("website", window, null, this._executeMessage);
330
+ this.setMessageHandler(o), this._onResize = this._onResize.bind(this), f() && window.addEventListener("resize", this._onResize), this._container = n, this._initData = r, this._configuratorSettings = e;
341
331
  let s = this._createIframe();
342
- this._onUseFullPage = this._onUseFullPage.bind(this), this._onBackToWebsite = this._onBackToWebsite.bind(this), this._waitForIframe = a, this._container.appendChild(s), this._iframe = s, this.setupPlugins(i, this._iframe), L.set(t, !0);
332
+ this._onUseFullPage = this._onUseFullPage.bind(this), this._onBackToWebsite = this._onBackToWebsite.bind(this), this._waitForIframe = a, this._container.appendChild(s), this._iframe = s, this.setupPlugins(i, this._iframe), F.set(n, !0);
343
333
  }
344
334
  teardown() {
345
- this._container && L.delete(this._container);
335
+ this._container && F.delete(this._container);
346
336
  let e = this._container.querySelector("iframe");
347
337
  e && this._container.removeChild(e), window.removeEventListener("resize", this._onResize);
348
338
  }
349
339
  _createIframe() {
350
340
  let e = document.createElement("iframe"), t = this._configuratorSettings?.url || "https://www.roomle.com/t/cp/";
351
- return this._initData.useLocalRoomle && (t = location.href.replace("embedding.html", "")), location.href.includes("roomle.gitlab.io") && (t = location.href.replace("embedding.html", "index.html")), this._initData.overrideServerUrl && (t = this._initData.overrideServerUrl), e.src = t, e.classList.add(M), e.classList.add(N), e;
341
+ return this._initData.useLocalRoomle && (t = location.href.replace("embedding.html", "")), location.href.includes("roomle.gitlab.io") && (t = location.href.replace("embedding.html", "index.html")), this._initData.overrideServerUrl && (t = this._initData.overrideServerUrl), e.src = t, e.classList.add(A), e.classList.add(j), e;
352
342
  }
353
343
  _onResize() {
354
- k(this._iframe);
344
+ D(this._iframe);
355
345
  }
356
346
  _onUseFullPage() {
357
- this._iframe.classList.add(P), document.documentElement.classList.add(I), window.document.body.classList.add(I), m() && (k(this._iframe), this._iframe.classList.add(F));
347
+ this._iframe.classList.add(M), document.documentElement.classList.add(P), window.document.body.classList.add(P), f() && (D(this._iframe), this._iframe.classList.add(N));
358
348
  }
359
349
  _onBackToWebsite() {
360
- this._iframe.classList.remove(P), this._iframe.classList.remove(F), document.documentElement.classList.remove(I), window.document.body.classList.remove(I);
350
+ this._iframe.classList.remove(M), this._iframe.classList.remove(N), document.documentElement.classList.remove(P), window.document.body.classList.remove(P);
361
351
  }
362
352
  _executeMessage({ message: e, args: t }, n) {
363
- if (n.source && n.source === this._iframe?.contentWindow) return e === b.REQUEST_BOOT ? this._messageHandler ? (this._messageHandler.setOutgoingMessageBus(n.source), Promise.resolve({ result: this._initData })) : Promise.resolve({ error: "MessageHandler not set" }) : e === b.SETUP ? (this.handleSetup(t[0]), D(this.ui.callbacks, "onUseFullPage", this._onUseFullPage), D(this.ui.callbacks, "onBackToWebsite", this._onBackToWebsite), this._waitForIframe(this), setTimeout(() => {
364
- this._messageHandler && this._messageHandler.sendMessage(b.WEBSITE_READY);
353
+ if (n.source && n.source === this._iframe?.contentWindow) return e === v.REQUEST_BOOT ? this._messageHandler ? (this._messageHandler.setOutgoingMessageBus(n.source), Promise.resolve({ result: this._initData })) : Promise.resolve({ error: "MessageHandler not set" }) : e === v.SETUP ? (this.handleSetup(t[0]), T(this.ui.callbacks, "onUseFullPage", this._onUseFullPage), T(this.ui.callbacks, "onBackToWebsite", this._onBackToWebsite), this._waitForIframe(this), setTimeout(() => {
354
+ this._messageHandler && this._messageHandler.sendMessage(v.WEBSITE_READY);
365
355
  }, 0), Promise.resolve({ result: null })) : this.executeMessage({
366
356
  message: e,
367
357
  args: t
368
358
  });
369
359
  }
370
360
  };
371
- export { b as HANDSHAKE_MESSAGES, E as INTERACTION_CONTAINER_SELECTOR, _ as NAMESPACE, v as NAMESPACE_SEPARATOR, y as SDK_CALLBACK, x as WELL_KNOWN_MESSAGES, R as default, T as getConfiguratorSettings, w as getMethodNames, C as isExposable };
361
+ export { v as HANDSHAKE_MESSAGES, w as INTERACTION_CONTAINER_SELECTOR, h as NAMESPACE, g as NAMESPACE_SEPARATOR, _ as SDK_CALLBACK, y as WELL_KNOWN_MESSAGES, I as default, C as getConfiguratorSettings, S as getMethodNames, x as isExposable };
@@ -1,237 +0,0 @@
1
- import { t as e } from "./rolldown-runtime-C-QNzSnW.mjs";
2
- //#region node_modules/comlink/dist/esm/comlink.mjs
3
- var t = /* @__PURE__ */ e({
4
- createEndpoint: () => r,
5
- expose: () => u,
6
- finalizer: () => a,
7
- proxy: () => T,
8
- proxyMarker: () => n,
9
- releaseProxy: () => i,
10
- transfer: () => w,
11
- transferHandlers: () => c,
12
- wrap: () => p
13
- }), n = Symbol("Comlink.proxy"), r = Symbol("Comlink.endpoint"), i = Symbol("Comlink.releaseProxy"), a = Symbol("Comlink.finalizer"), o = Symbol("Comlink.thrown"), s = (e) => typeof e == "object" && !!e || typeof e == "function", c = new Map([["proxy", {
14
- canHandle: (e) => s(e) && e[n],
15
- serialize(e) {
16
- let { port1: t, port2: n } = new MessageChannel();
17
- return u(e, t), [n, [n]];
18
- },
19
- deserialize(e) {
20
- return e.start(), p(e);
21
- }
22
- }], ["throw", {
23
- canHandle: (e) => s(e) && o in e,
24
- serialize({ value: e }) {
25
- let t;
26
- return t = e instanceof Error ? {
27
- isError: !0,
28
- value: {
29
- message: e.message,
30
- name: e.name,
31
- stack: e.stack
32
- }
33
- } : {
34
- isError: !1,
35
- value: e
36
- }, [t, []];
37
- },
38
- deserialize(e) {
39
- throw e.isError ? Object.assign(Error(e.value.message), e.value) : e.value;
40
- }
41
- }]]);
42
- function l(e, t) {
43
- for (let n of e) if (t === n || n === "*" || n instanceof RegExp && n.test(t)) return !0;
44
- return !1;
45
- }
46
- function u(e, t = globalThis, n = ["*"]) {
47
- t.addEventListener("message", function r(i) {
48
- if (!i || !i.data) return;
49
- if (!l(n, i.origin)) {
50
- console.warn(`Invalid origin '${i.origin}' for comlink proxy`);
51
- return;
52
- }
53
- let { id: s, type: c, path: d } = Object.assign({ path: [] }, i.data), p = (i.data.argumentList || []).map(D), m;
54
- try {
55
- let t = d.slice(0, -1).reduce((e, t) => e[t], e), n = d.reduce((e, t) => e[t], e);
56
- switch (c) {
57
- case "GET":
58
- m = n;
59
- break;
60
- case "SET":
61
- t[d.slice(-1)[0]] = D(i.data.value), m = !0;
62
- break;
63
- case "APPLY":
64
- m = n.apply(t, p);
65
- break;
66
- case "CONSTRUCT":
67
- m = T(new n(...p));
68
- break;
69
- case "ENDPOINT":
70
- {
71
- let { port1: t, port2: n } = new MessageChannel();
72
- u(e, n), m = w(t, [t]);
73
- }
74
- break;
75
- case "RELEASE":
76
- m = void 0;
77
- break;
78
- default: return;
79
- }
80
- } catch (e) {
81
- m = {
82
- value: e,
83
- [o]: 0
84
- };
85
- }
86
- Promise.resolve(m).catch((e) => ({
87
- value: e,
88
- [o]: 0
89
- })).then((n) => {
90
- let [i, o] = E(n);
91
- t.postMessage(Object.assign(Object.assign({}, i), { id: s }), o), c === "RELEASE" && (t.removeEventListener("message", r), f(t), a in e && typeof e[a] == "function" && e[a]());
92
- }).catch((e) => {
93
- let [n, r] = E({
94
- value: /* @__PURE__ */ TypeError("Unserializable return value"),
95
- [o]: 0
96
- });
97
- t.postMessage(Object.assign(Object.assign({}, n), { id: s }), r);
98
- });
99
- }), t.start && t.start();
100
- }
101
- function d(e) {
102
- return e.constructor.name === "MessagePort";
103
- }
104
- function f(e) {
105
- d(e) && e.close();
106
- }
107
- function p(e, t) {
108
- let n = /* @__PURE__ */ new Map();
109
- return e.addEventListener("message", function(e) {
110
- let { data: t } = e;
111
- if (!t || !t.id) return;
112
- let r = n.get(t.id);
113
- if (r) try {
114
- r(t);
115
- } finally {
116
- n.delete(t.id);
117
- }
118
- }), b(e, n, [], t);
119
- }
120
- function m(e) {
121
- if (e) throw Error("Proxy has been released and is not useable");
122
- }
123
- function h(e) {
124
- return O(e, /* @__PURE__ */ new Map(), { type: "RELEASE" }).then(() => {
125
- f(e);
126
- });
127
- }
128
- var g = /* @__PURE__ */ new WeakMap(), _ = "FinalizationRegistry" in globalThis && new FinalizationRegistry((e) => {
129
- let t = (g.get(e) || 0) - 1;
130
- g.set(e, t), t === 0 && h(e);
131
- });
132
- function v(e, t) {
133
- let n = (g.get(t) || 0) + 1;
134
- g.set(t, n), _ && _.register(e, t, e);
135
- }
136
- function y(e) {
137
- _ && _.unregister(e);
138
- }
139
- function b(e, t, n = [], a = function() {}) {
140
- let o = !1, s = new Proxy(a, {
141
- get(r, a) {
142
- if (m(o), a === i) return () => {
143
- y(s), h(e), t.clear(), o = !0;
144
- };
145
- if (a === "then") {
146
- if (n.length === 0) return { then: () => s };
147
- let r = O(e, t, {
148
- type: "GET",
149
- path: n.map((e) => e.toString())
150
- }).then(D);
151
- return r.then.bind(r);
152
- }
153
- return b(e, t, [...n, a]);
154
- },
155
- set(r, i, a) {
156
- m(o);
157
- let [s, c] = E(a);
158
- return O(e, t, {
159
- type: "SET",
160
- path: [...n, i].map((e) => e.toString()),
161
- value: s
162
- }, c).then(D);
163
- },
164
- apply(i, a, s) {
165
- m(o);
166
- let c = n[n.length - 1];
167
- if (c === r) return O(e, t, { type: "ENDPOINT" }).then(D);
168
- if (c === "bind") return b(e, t, n.slice(0, -1));
169
- let [l, u] = S(s);
170
- return O(e, t, {
171
- type: "APPLY",
172
- path: n.map((e) => e.toString()),
173
- argumentList: l
174
- }, u).then(D);
175
- },
176
- construct(r, i) {
177
- m(o);
178
- let [a, s] = S(i);
179
- return O(e, t, {
180
- type: "CONSTRUCT",
181
- path: n.map((e) => e.toString()),
182
- argumentList: a
183
- }, s).then(D);
184
- }
185
- });
186
- return v(s, e), s;
187
- }
188
- function x(e) {
189
- return Array.prototype.concat.apply([], e);
190
- }
191
- function S(e) {
192
- let t = e.map(E);
193
- return [t.map((e) => e[0]), x(t.map((e) => e[1]))];
194
- }
195
- var C = /* @__PURE__ */ new WeakMap();
196
- function w(e, t) {
197
- return C.set(e, t), e;
198
- }
199
- function T(e) {
200
- return Object.assign(e, { [n]: !0 });
201
- }
202
- function E(e) {
203
- for (let [t, n] of c) if (n.canHandle(e)) {
204
- let [r, i] = n.serialize(e);
205
- return [{
206
- type: "HANDLER",
207
- name: t,
208
- value: r
209
- }, i];
210
- }
211
- return [{
212
- type: "RAW",
213
- value: e
214
- }, C.get(e) || []];
215
- }
216
- function D(e) {
217
- switch (e.type) {
218
- case "HANDLER": return c.get(e.name).deserialize(e.value);
219
- case "RAW": return e.value;
220
- }
221
- }
222
- function O(e, t, n, r) {
223
- return new Promise((i) => {
224
- let a = k();
225
- t.set(a, i), e.start && e.start(), e.postMessage(Object.assign({ id: a }, n), r);
226
- });
227
- }
228
- function k() {
229
- return [
230
- ,
231
- ,
232
- ,
233
- ,
234
- ].fill(0).map(() => Math.floor(Math.random() * (2 ** 53 - 1)).toString(16)).join("-");
235
- }
236
- //#endregion
237
- export { u as n, t };