@roomle/embedding-lib 7.3.0-alpha.3 → 8.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,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,
@@ -105,18 +103,18 @@ var r = class {
105
103
  },
106
104
  rotationSnapDegrees: 10,
107
105
  interactionsCollapsed: !1
108
- }, u = (e) => e.trim() !== "" && Number.isFinite(Number(e.trim())), d = (e) => {
106
+ }, c = (e) => e.trim() !== "" && Number.isFinite(Number(e.trim())), l = (e) => {
109
107
  if (!e || typeof e != "object") return;
110
108
  let t = Object.keys(e);
111
109
  for (let n of t) {
112
110
  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));
111
+ if (Array.isArray(t) || typeof t != "object" || !t || l(t), Array.isArray(t)) for (let e of t) l(e);
112
+ t === "true" || t === "false" ? e[n] = t === "true" : typeof t == "string" && c(t) && (e[n] = Number(t));
115
113
  }
116
- }, f = () => {
117
- let e = c(l);
118
- e.locale ||= t(null, !0), e.id === "(idle)" && delete e.id;
119
- let n = (() => {
114
+ }, u = () => {
115
+ let t = o(s);
116
+ t.locale ||= e(null, !0), t.id === "(idle)" && delete t.id;
117
+ let r = (() => {
120
118
  let e = (() => {
121
119
  try {
122
120
  return window.self !== window.top;
@@ -131,13 +129,13 @@ var r = class {
131
129
  let { hostname: n } = new URL(t);
132
130
  return n;
133
131
  })();
134
- return n && ((e) => {
132
+ return r && ((e) => {
135
133
  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) => {
134
+ return !!(n.includes(e) || t.test(e) || e.endsWith("roomle.com") || e.endsWith("gitlab.io") || e.endsWith("gitlab.com"));
135
+ })(r) && (t.configuratorId = "demoConfigurator"), t.customApiUrl = "https://rubens.alpha.roomle.com/api/v2", t.emails = !1, t;
136
+ }, d = (e) => {
139
137
  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 {
138
+ }, f = () => /(android)/i.test(navigator.userAgent), p = class {
141
139
  _messageHandler = null;
142
140
  isSetupDone = !1;
143
141
  viewName = "main";
@@ -175,7 +173,7 @@ var r = class {
175
173
  setupPlugins(e, t, n = "website") {
176
174
  for (let r of e) typeof r == "string" && r === "dragIn" ? this.pluginsLoaded.push(new Promise((e, r) => {
177
175
  try {
178
- import("./drag-in-DDGopCLr.mjs").then((e) => e.n).then(({ DragIn: i }) => {
176
+ import("./drag-in-CV1E-DO6.mjs").then((e) => e.n).then(({ DragIn: i }) => {
179
177
  let a = new i(this.ui, t, n, this.viewName);
180
178
  a.init().then(() => {
181
179
  this.plugins.dragIn = a, e();
@@ -197,7 +195,7 @@ var r = class {
197
195
  }
198
196
  }));
199
197
  }
200
- }, g = () => {
198
+ }, m = () => {
201
199
  let e, t;
202
200
  return {
203
201
  promise: new Promise((n, r) => {
@@ -206,7 +204,7 @@ var r = class {
206
204
  resolve: e,
207
205
  reject: t
208
206
  };
209
- }, _ = {
207
+ }, h = {
210
208
  SDK: "extended",
211
209
  CONFIGURATOR_SDK: "configurator",
212
210
  CALLBACKS: "callbacks",
@@ -214,20 +212,20 @@ var r = class {
214
212
  ANALYTICS: "analytics",
215
213
  GLOBAL: "global",
216
214
  RAPI: "rapi"
217
- }, v = ".", y = _.SDK + "." + _.CALLBACKS, b = {
215
+ }, g = ".", _ = h.SDK + "." + h.CALLBACKS, v = {
218
216
  REQUEST_BOOT: "requestBoot",
219
217
  SETUP: "setup",
220
218
  WEBSITE_READY: "websiteReady"
221
- }, x = {
219
+ }, y = {
222
220
  GET_METHODS: "getMethods",
223
221
  RETURN_METHODS: "returnMethods",
224
222
  REGISTER_CUSTOM_VIEW: "registerCustomView",
225
223
  REGISTER_CUSTOM_VIEW_DONE: "registerCustomViewDone"
226
- }, S = ["constructor", "callbacks"], C = (e) => e[0] !== "_" && !S.includes(e), w = (e, t, n = !1) => {
224
+ }, b = ["constructor", "callbacks"], x = (e) => e[0] !== "_" && !b.includes(e), S = (e, t, n = !1) => {
227
225
  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) => {
226
+ let r = Object.getOwnPropertyNames(e), i = n ? h.CALLBACKS + "." : "";
227
+ return r.filter(x).map((e) => t + "." + i + e);
228
+ }, C = async (e, t) => {
231
229
  if (typeof e != "string") throw Error("Configurator ID is not a string type: \"" + typeof e + "\"");
232
230
  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
231
  method: "GET",
@@ -244,7 +242,7 @@ var r = class {
244
242
  cache: "default"
245
243
  }), { configurator: s } = await (await fetch(o)).json();
246
244
  return s;
247
- }, E = "data-rml-interaction-container", D = (e, t, n) => {
245
+ }, w = "data-rml-interaction-container", T = (e, t, n) => {
248
246
  let r = null;
249
247
  Object.defineProperty(e, t, {
250
248
  get: () => r || n,
@@ -252,32 +250,32 @@ var r = class {
252
250
  r = e?.mute ? e.value : e;
253
251
  }
254
252
  });
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 {
253
+ }, E = () => .01 * window.innerHeight + "px", D = (e) => {
254
+ e && setTimeout(() => e.style.setProperty(k, E()), 0);
255
+ }, 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
256
  static createPlanner(e, t, n, r = []) {
259
257
  return this._create(e, t, n, r);
260
258
  }
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 }) => {
259
+ static async connect(e, n = []) {
260
+ let r = new p();
261
+ r.viewName = e;
262
+ 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
263
  switch (e) {
266
- case x.REGISTER_CUSTOM_VIEW_DONE:
264
+ case y.REGISTER_CUSTOM_VIEW_DONE:
267
265
  i();
268
266
  break;
269
- case x.RETURN_METHODS:
270
- n.handleSetup(t[0]), o();
267
+ case y.RETURN_METHODS:
268
+ r.handleSetup(t[0]), o();
271
269
  break;
272
- default: if (n.isSetupDone) return n.executeMessage({
270
+ default: if (r.isSetupDone) return r.executeMessage({
273
271
  message: e,
274
272
  args: t
275
273
  });
276
274
  }
277
275
  });
278
- n.setMessageHandler(c);
276
+ r.setMessageHandler(c);
279
277
  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;
278
+ 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
279
  }
282
280
  static createConfigurator(e, t, n, r = []) {
283
281
  return this._create(e, t, n, r);
@@ -288,36 +286,27 @@ var r = class {
288
286
  static createViewer(e, t, n, r = []) {
289
287
  return this._create(e, t, n, r);
290
288
  }
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) => {
289
+ static async _create(e, t, n, i) {
290
+ return new Promise(async (a, s) => {
302
291
  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));
292
+ 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();
293
+ d(c);
294
+ let f = await C(e, r(c, s));
306
295
  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) => {
296
+ let n = o(t), i = u();
297
+ d(i);
298
+ let a = r(r(i, e.settings || {}), n);
299
+ return a.configuratorId = e.id, !a.overrideTenant && e.tenant && (a.overrideTenant = e.tenant), ((e) => {
311
300
  let t = e.featureFlags;
312
301
  if (!t || typeof t != "object" || Array.isArray(t)) return;
313
302
  let n = t;
314
303
  !("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;
304
+ })(a), a;
305
+ })(f, s);
306
+ let p = new this(f, t, n, i, a);
307
+ return await Promise.allSettled(p.pluginsLoaded), p;
319
308
  } catch (e) {
320
- return o(e);
309
+ return s(e);
321
310
  }
322
311
  });
323
312
  }
@@ -326,46 +315,46 @@ var r = class {
326
315
  _configuratorSettings;
327
316
  _initData = {};
328
317
  _iframe;
329
- constructor(e, t, n, i, a) {
318
+ constructor(e, n, r, i, a) {
330
319
  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);
320
+ if (F.has(n)) throw Error("There is already an instance on this DOM element");
321
+ if (!document.getElementById(O)) {
322
+ let e = r.zIndex || 9999999, t = document.createElement("style");
323
+ t.type = "text/css", t.id = O;
324
+ let n = "transition:all ease-in-out 450ms;", i = ["-webkit-", "-o-"].reduce((e, t) => e + (t + n), "") + n;
325
+ 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
326
  }
338
327
  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;
328
+ let o = new t("website", window, null, this._executeMessage);
329
+ 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
330
  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);
331
+ 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
332
  }
344
333
  teardown() {
345
- this._container && L.delete(this._container);
334
+ this._container && F.delete(this._container);
346
335
  let e = this._container.querySelector("iframe");
347
336
  e && this._container.removeChild(e), window.removeEventListener("resize", this._onResize);
348
337
  }
349
338
  _createIframe() {
350
339
  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;
340
+ 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
341
  }
353
342
  _onResize() {
354
- k(this._iframe);
343
+ D(this._iframe);
355
344
  }
356
345
  _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));
346
+ 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
347
  }
359
348
  _onBackToWebsite() {
360
- this._iframe.classList.remove(P), this._iframe.classList.remove(F), document.documentElement.classList.remove(I), window.document.body.classList.remove(I);
349
+ this._iframe.classList.remove(M), this._iframe.classList.remove(N), document.documentElement.classList.remove(P), window.document.body.classList.remove(P);
361
350
  }
362
351
  _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);
352
+ 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(() => {
353
+ this._messageHandler && this._messageHandler.sendMessage(v.WEBSITE_READY);
365
354
  }, 0), Promise.resolve({ result: null })) : this.executeMessage({
366
355
  message: e,
367
356
  args: t
368
357
  });
369
358
  }
370
359
  };
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 };
360
+ 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 };