appscms-tools-theme 3.2.1 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,572 +1,929 @@
1
1
  /* Partytown 0.7.5 - MIT builder.io */
2
- (window => {
3
- const isPromise = v => "object" == typeof v && v && v.then;
4
- const noop = () => {};
5
- const len = obj => obj.length;
6
- const getConstructorName = obj => {
7
- var _a, _b, _c;
8
- try {
9
- const constructorName = null === (_a = null == obj ? void 0 : obj.constructor) || void 0 === _a ? void 0 : _a.name;
10
- if (constructorName) {
11
- return constructorName;
12
- }
13
- } catch (e) {}
14
- try {
15
- const zoneJsConstructorName = null === (_c = null === (_b = null == obj ? void 0 : obj.__zone_symbol__originalInstance) || void 0 === _b ? void 0 : _b.constructor) || void 0 === _c ? void 0 : _c.name;
16
- if (zoneJsConstructorName) {
17
- return zoneJsConstructorName;
18
- }
19
- } catch (e) {}
20
- return "";
21
- };
22
- const startsWith = (str, val) => str.startsWith(val);
23
- const isValidMemberName = memberName => !(startsWith(memberName, "webkit") || startsWith(memberName, "toJSON") || startsWith(memberName, "constructor") || startsWith(memberName, "toString") || startsWith(memberName, "_"));
24
- const getNodeName = node => 11 === node.nodeType && node.host ? "#s" : node.nodeName;
25
- const randomId = () => Math.round(Math.random() * Number.MAX_SAFE_INTEGER).toString(36);
26
- const defineConstructorName = (Cstr, value) => ((obj, memberName, descriptor) => Object.defineProperty(obj, memberName, {
2
+ ((window) => {
3
+ const isPromise = (v) => "object" == typeof v && v && v.then;
4
+ const noop = () => {};
5
+ const len = (obj) => obj.length;
6
+ const getConstructorName = (obj) => {
7
+ var _a, _b, _c;
8
+ try {
9
+ const constructorName =
10
+ null === (_a = null == obj ? void 0 : obj.constructor) || void 0 === _a
11
+ ? void 0
12
+ : _a.name;
13
+ if (constructorName) {
14
+ return constructorName;
15
+ }
16
+ } catch (e) {}
17
+ try {
18
+ const zoneJsConstructorName =
19
+ null ===
20
+ (_c =
21
+ null ===
22
+ (_b =
23
+ null == obj ? void 0 : obj.__zone_symbol__originalInstance) ||
24
+ void 0 === _b
25
+ ? void 0
26
+ : _b.constructor) || void 0 === _c
27
+ ? void 0
28
+ : _c.name;
29
+ if (zoneJsConstructorName) {
30
+ return zoneJsConstructorName;
31
+ }
32
+ } catch (e) {}
33
+ return "";
34
+ };
35
+ const startsWith = (str, val) => str.startsWith(val);
36
+ const isValidMemberName = (memberName) =>
37
+ !(
38
+ startsWith(memberName, "webkit") ||
39
+ startsWith(memberName, "toJSON") ||
40
+ startsWith(memberName, "constructor") ||
41
+ startsWith(memberName, "toString") ||
42
+ startsWith(memberName, "_")
43
+ );
44
+ const getNodeName = (node) =>
45
+ 11 === node.nodeType && node.host ? "#s" : node.nodeName;
46
+ const randomId = () =>
47
+ Math.round(Math.random() * Number.MAX_SAFE_INTEGER).toString(36);
48
+ const defineConstructorName = (Cstr, value) =>
49
+ ((obj, memberName, descriptor) =>
50
+ Object.defineProperty(obj, memberName, {
27
51
  ...descriptor,
28
- configurable: true
29
- }))(Cstr, "name", {
30
- value: value
52
+ configurable: true,
53
+ }))(Cstr, "name", {
54
+ value: value,
31
55
  });
32
- const htmlConstructorTags = {
33
- Anchor: "a",
34
- DList: "dl",
35
- Image: "img",
36
- OList: "ol",
37
- Paragraph: "p",
38
- Quote: "q",
39
- TableCaption: "caption",
40
- TableCell: "td",
41
- TableCol: "colgroup",
42
- TableRow: "tr",
43
- TableSection: "tbody",
44
- UList: "ul"
45
- };
46
- const svgConstructorTags = {
47
- Graphics: "g",
48
- SVG: "svg"
49
- };
50
- const InstanceIdKey = Symbol();
51
- const CreatedKey = Symbol();
52
- const instances = new Map;
53
- const mainRefs = new Map;
54
- const winCtxs = {};
55
- const windowIds = new WeakMap;
56
- const getAndSetInstanceId = (instance, instanceId) => {
57
- if (instance) {
58
- if (instanceId = windowIds.get(instance)) {
59
- return instanceId;
60
- }
61
- (instanceId = instance[InstanceIdKey]) || setInstanceId(instance, instanceId = randomId());
62
- return instanceId;
56
+ const htmlConstructorTags = {
57
+ Anchor: "a",
58
+ DList: "dl",
59
+ Image: "img",
60
+ OList: "ol",
61
+ Paragraph: "p",
62
+ Quote: "q",
63
+ TableCaption: "caption",
64
+ TableCell: "td",
65
+ TableCol: "colgroup",
66
+ TableRow: "tr",
67
+ TableSection: "tbody",
68
+ UList: "ul",
69
+ };
70
+ const svgConstructorTags = {
71
+ Graphics: "g",
72
+ SVG: "svg",
73
+ };
74
+ const InstanceIdKey = Symbol();
75
+ const CreatedKey = Symbol();
76
+ const instances = new Map();
77
+ const mainRefs = new Map();
78
+ const winCtxs = {};
79
+ const windowIds = new WeakMap();
80
+ const getAndSetInstanceId = (instance, instanceId) => {
81
+ if (instance) {
82
+ if ((instanceId = windowIds.get(instance))) {
83
+ return instanceId;
84
+ }
85
+ (instanceId = instance[InstanceIdKey]) ||
86
+ setInstanceId(instance, (instanceId = randomId()));
87
+ return instanceId;
88
+ }
89
+ };
90
+ const getInstance = (winId, instanceId, win, doc, docId) => {
91
+ if ((win = winCtxs[winId]) && win.$window$) {
92
+ if (winId === instanceId) {
93
+ return win.$window$;
94
+ }
95
+ doc = win.$window$.document;
96
+ docId = instanceId.split(".").pop();
97
+ if ("d" === docId) {
98
+ return doc;
99
+ }
100
+ if ("e" === docId) {
101
+ return doc.documentElement;
102
+ }
103
+ if ("h" === docId) {
104
+ return doc.head;
105
+ }
106
+ if ("b" === docId) {
107
+ return doc.body;
108
+ }
109
+ }
110
+ return instances.get(instanceId);
111
+ };
112
+ const setInstanceId = (instance, instanceId, now) => {
113
+ if (instance) {
114
+ instances.set(instanceId, instance);
115
+ instance[InstanceIdKey] = instanceId;
116
+ instance[CreatedKey] = now = Date.now();
117
+ if (now > lastCleanup + 5e3) {
118
+ instances.forEach((storedInstance, instanceId) => {
119
+ storedInstance[CreatedKey] < lastCleanup &&
120
+ storedInstance.nodeType &&
121
+ !storedInstance.isConnected &&
122
+ instances.delete(instanceId);
123
+ });
124
+ lastCleanup = now;
125
+ }
126
+ }
127
+ };
128
+ let lastCleanup = 0;
129
+ const mainWindow = window.parent;
130
+ const docImpl = document.implementation.createHTMLDocument();
131
+ const config = mainWindow.partytown || {};
132
+ const libPath = (config.lib || "/partytown/") + "debug/";
133
+ const logMain = (msg) => {
134
+ console.debug.apply(console, [
135
+ "%cMain 🌎",
136
+ "background: #717171; color: white; padding: 2px 3px; border-radius: 2px; font-size: 0.8em;",
137
+ msg,
138
+ ]);
139
+ };
140
+ const winIds = [];
141
+ const normalizedWinId = (winId) => {
142
+ winIds.includes(winId) || winIds.push(winId);
143
+ return winIds.indexOf(winId) + 1;
144
+ };
145
+ const defineCustomElement = (winId, worker, ceData) => {
146
+ const Cstr = defineConstructorName(
147
+ class extends winCtxs[winId].$window$.HTMLElement {},
148
+ ceData[0]
149
+ );
150
+ const ceCallbackMethods =
151
+ "connectedCallback,disconnectedCallback,attributeChangedCallback,adoptedCallback".split(
152
+ ","
153
+ );
154
+ ceCallbackMethods.map(
155
+ (callbackMethodName) =>
156
+ (Cstr.prototype[callbackMethodName] = function (...args) {
157
+ worker.postMessage([
158
+ 15,
159
+ winId,
160
+ getAndSetInstanceId(this),
161
+ callbackMethodName,
162
+ args,
163
+ ]);
164
+ })
165
+ );
166
+ Cstr.observedAttributes = ceData[1];
167
+ return Cstr;
168
+ };
169
+ const serializeForWorker = ($winId$, value, added, type, cstrName) =>
170
+ void 0 !== value && (type = typeof value)
171
+ ? "string" === type ||
172
+ "number" === type ||
173
+ "boolean" === type ||
174
+ null == value
175
+ ? [0, value]
176
+ : "function" === type
177
+ ? [6]
178
+ : (added = added || new Set()) && Array.isArray(value)
179
+ ? added.has(value)
180
+ ? [1, []]
181
+ : added.add(value) && [
182
+ 1,
183
+ value.map((v) => serializeForWorker($winId$, v, added)),
184
+ ]
185
+ : "object" === type
186
+ ? serializedValueIsError(value)
187
+ ? [
188
+ 14,
189
+ {
190
+ name: value.name,
191
+ message: value.message,
192
+ stack: value.stack,
193
+ },
194
+ ]
195
+ : "" === (cstrName = getConstructorName(value))
196
+ ? [2, {}]
197
+ : "Window" === cstrName
198
+ ? [3, [$winId$, $winId$]]
199
+ : "HTMLCollection" === cstrName || "NodeList" === cstrName
200
+ ? [
201
+ 7,
202
+ Array.from(value).map(
203
+ (v) => serializeForWorker($winId$, v, added)[1]
204
+ ),
205
+ ]
206
+ : cstrName.endsWith("Event")
207
+ ? [5, serializeObjectForWorker($winId$, value, added)]
208
+ : "CSSRuleList" === cstrName
209
+ ? [12, Array.from(value).map(serializeCssRuleForWorker)]
210
+ : startsWith(cstrName, "CSS") && cstrName.endsWith("Rule")
211
+ ? [11, serializeCssRuleForWorker(value)]
212
+ : "CSSStyleDeclaration" === cstrName
213
+ ? [13, serializeObjectForWorker($winId$, value, added)]
214
+ : "Attr" === cstrName
215
+ ? [10, [value.name, value.value]]
216
+ : value.nodeType
217
+ ? [3, [$winId$, getAndSetInstanceId(value), getNodeName(value)]]
218
+ : [2, serializeObjectForWorker($winId$, value, added, true, true)]
219
+ : void 0
220
+ : value;
221
+ const serializeObjectForWorker = (
222
+ winId,
223
+ obj,
224
+ added,
225
+ includeFunctions,
226
+ includeEmptyStrings,
227
+ serializedObj,
228
+ propName,
229
+ propValue
230
+ ) => {
231
+ serializedObj = {};
232
+ if (!added.has(obj)) {
233
+ added.add(obj);
234
+ for (propName in obj) {
235
+ if (isValidMemberName(propName)) {
236
+ propValue =
237
+ "path" === propName && getConstructorName(obj).endsWith("Event")
238
+ ? obj.composedPath()
239
+ : obj[propName];
240
+ (includeFunctions || "function" != typeof propValue) &&
241
+ (includeEmptyStrings || "" !== propValue) &&
242
+ (serializedObj[propName] = serializeForWorker(
243
+ winId,
244
+ propValue,
245
+ added
246
+ ));
63
247
  }
248
+ }
249
+ }
250
+ return serializedObj;
251
+ };
252
+ const serializeCssRuleForWorker = (cssRule) => {
253
+ let obj = {};
254
+ let key;
255
+ for (key in cssRule) {
256
+ validCssRuleProps.includes(key) && (obj[key] = String(cssRule[key]));
257
+ }
258
+ return obj;
259
+ };
260
+ const serializedValueIsError = (value) => value instanceof window.top.Error;
261
+ const deserializeFromWorker = (
262
+ worker,
263
+ serializedTransfer,
264
+ serializedType,
265
+ serializedValue
266
+ ) => {
267
+ if (serializedTransfer) {
268
+ serializedType = serializedTransfer[0];
269
+ serializedValue = serializedTransfer[1];
270
+ return 0 === serializedType
271
+ ? serializedValue
272
+ : 4 === serializedType
273
+ ? deserializeRefFromWorker(worker, serializedValue)
274
+ : 1 === serializedType
275
+ ? serializedValue.map((v) => deserializeFromWorker(worker, v))
276
+ : 3 === serializedType
277
+ ? getInstance(serializedValue[0], serializedValue[1])
278
+ : 5 === serializedType
279
+ ? constructEvent(deserializeObjectFromWorker(worker, serializedValue))
280
+ : 2 === serializedType
281
+ ? deserializeObjectFromWorker(worker, serializedValue)
282
+ : 8 === serializedType
283
+ ? serializedValue
284
+ : 9 === serializedType
285
+ ? new window[serializedTransfer[2]](serializedValue)
286
+ : void 0;
287
+ }
288
+ };
289
+ const deserializeRefFromWorker = (
290
+ worker,
291
+ { $winId$: $winId$, $instanceId$: $instanceId$, $refId$: $refId$ },
292
+ ref
293
+ ) => {
294
+ ref = mainRefs.get($refId$);
295
+ if (!ref) {
296
+ ref = function (...args) {
297
+ worker.postMessage([
298
+ 9,
299
+ {
300
+ $winId$: $winId$,
301
+ $instanceId$: $instanceId$,
302
+ $refId$: $refId$,
303
+ $thisArg$: serializeForWorker($winId$, this),
304
+ $args$: serializeForWorker($winId$, args),
305
+ },
306
+ ]);
307
+ };
308
+ mainRefs.set($refId$, ref);
309
+ }
310
+ return ref;
311
+ };
312
+ const constructEvent = (eventProps) =>
313
+ new ("detail" in eventProps ? CustomEvent : Event)(
314
+ eventProps.type,
315
+ eventProps
316
+ );
317
+ const deserializeObjectFromWorker = (worker, serializedValue, obj, key) => {
318
+ obj = {};
319
+ for (key in serializedValue) {
320
+ obj[key] = deserializeFromWorker(worker, serializedValue[key]);
321
+ }
322
+ return obj;
323
+ };
324
+ const validCssRuleProps =
325
+ "cssText,selectorText,href,media,namespaceURI,prefix,name,conditionText".split(
326
+ ","
327
+ );
328
+ const mainAccessHandler = async (worker, accessReq) => {
329
+ let accessRsp = {
330
+ $msgId$: accessReq.$msgId$,
64
331
  };
65
- const getInstance = (winId, instanceId, win, doc, docId) => {
66
- if ((win = winCtxs[winId]) && win.$window$) {
67
- if (winId === instanceId) {
68
- return win.$window$;
69
- }
70
- doc = win.$window$.document;
71
- docId = instanceId.split(".").pop();
72
- if ("d" === docId) {
73
- return doc;
74
- }
75
- if ("e" === docId) {
76
- return doc.documentElement;
77
- }
78
- if ("h" === docId) {
79
- return doc.head;
80
- }
81
- if ("b" === docId) {
82
- return doc.body;
332
+ let totalTasks = len(accessReq.$tasks$);
333
+ let i = 0;
334
+ let task;
335
+ let winId;
336
+ let applyPath;
337
+ let instance;
338
+ let rtnValue;
339
+ let isLast;
340
+ for (; i < totalTasks; i++) {
341
+ try {
342
+ isLast = i === totalTasks - 1;
343
+ task = accessReq.$tasks$[i];
344
+ winId = task.$winId$;
345
+ applyPath = task.$applyPath$;
346
+ !winCtxs[winId] &&
347
+ winId.startsWith("f_") &&
348
+ (await new Promise((resolve) => {
349
+ let check = 0;
350
+ let callback = () => {
351
+ winCtxs[winId] || check++ > 1e3
352
+ ? resolve()
353
+ : requestAnimationFrame(callback);
354
+ };
355
+ callback();
356
+ }));
357
+ if (1 === applyPath[0] && applyPath[1] in winCtxs[winId].$window$) {
358
+ setInstanceId(
359
+ new winCtxs[winId].$window$[applyPath[1]](
360
+ ...deserializeFromWorker(worker, applyPath[2])
361
+ ),
362
+ task.$instanceId$
363
+ );
364
+ } else {
365
+ instance = getInstance(winId, task.$instanceId$);
366
+ if (instance) {
367
+ rtnValue = applyToInstance(
368
+ worker,
369
+ winId,
370
+ instance,
371
+ applyPath,
372
+ isLast,
373
+ task.$groupedGetters$
374
+ );
375
+ task.$assignInstanceId$ &&
376
+ ("string" == typeof task.$assignInstanceId$
377
+ ? setInstanceId(rtnValue, task.$assignInstanceId$)
378
+ : (winCtxs[task.$assignInstanceId$.$winId$] = {
379
+ $winId$: task.$assignInstanceId$.$winId$,
380
+ $window$: {
381
+ document: rtnValue,
382
+ },
383
+ }));
384
+ if (isPromise(rtnValue)) {
385
+ rtnValue = await rtnValue;
386
+ isLast && (accessRsp.$isPromise$ = true);
83
387
  }
388
+ isLast &&
389
+ (accessRsp.$rtnValue$ = serializeForWorker(winId, rtnValue));
390
+ } else {
391
+ accessRsp.$error$ = `Error finding instance "${
392
+ task.$instanceId$
393
+ }" on window ${normalizedWinId(winId)}`;
394
+ console.error(accessRsp.$error$, task);
395
+ }
84
396
  }
85
- return instances.get(instanceId);
86
- };
87
- const setInstanceId = (instance, instanceId, now) => {
88
- if (instance) {
89
- instances.set(instanceId, instance);
90
- instance[InstanceIdKey] = instanceId;
91
- instance[CreatedKey] = now = Date.now();
92
- if (now > lastCleanup + 5e3) {
93
- instances.forEach(((storedInstance, instanceId) => {
94
- storedInstance[CreatedKey] < lastCleanup && storedInstance.nodeType && !storedInstance.isConnected && instances.delete(instanceId);
95
- }));
96
- lastCleanup = now;
397
+ } catch (e) {
398
+ isLast ? (accessRsp.$error$ = String(e.stack || e)) : console.error(e);
399
+ }
400
+ }
401
+ return accessRsp;
402
+ };
403
+ const applyToInstance = (
404
+ worker,
405
+ winId,
406
+ instance,
407
+ applyPath,
408
+ isLast,
409
+ groupedGetters
410
+ ) => {
411
+ let i = 0;
412
+ let l = len(applyPath);
413
+ let next;
414
+ let current;
415
+ let previous;
416
+ let args;
417
+ let groupedRtnValues;
418
+ for (; i < l; i++) {
419
+ current = applyPath[i];
420
+ next = applyPath[i + 1];
421
+ previous = applyPath[i - 1];
422
+ try {
423
+ if (!Array.isArray(next)) {
424
+ if ("string" == typeof current || "number" == typeof current) {
425
+ if (i + 1 === l && groupedGetters) {
426
+ groupedRtnValues = {};
427
+ groupedGetters.map(
428
+ (propName) => (groupedRtnValues[propName] = instance[propName])
429
+ );
430
+ return groupedRtnValues;
97
431
  }
98
- }
99
- };
100
- let lastCleanup = 0;
101
- const mainWindow = window.parent;
102
- const docImpl = document.implementation.createHTMLDocument();
103
- const config = mainWindow.partytown || {};
104
- const libPath = (config.lib || "/partytown/") + "debug/";
105
- const logMain = msg => {
106
- console.debug.apply(console, [ "%cMain 🌎", "background: #717171; color: white; padding: 2px 3px; border-radius: 2px; font-size: 0.8em;", msg ]);
107
- };
108
- const winIds = [];
109
- const normalizedWinId = winId => {
110
- winIds.includes(winId) || winIds.push(winId);
111
- return winIds.indexOf(winId) + 1;
112
- };
113
- const defineCustomElement = (winId, worker, ceData) => {
114
- const Cstr = defineConstructorName(class extends winCtxs[winId].$window$.HTMLElement {}, ceData[0]);
115
- const ceCallbackMethods = "connectedCallback,disconnectedCallback,attributeChangedCallback,adoptedCallback".split(",");
116
- ceCallbackMethods.map((callbackMethodName => Cstr.prototype[callbackMethodName] = function(...args) {
117
- worker.postMessage([ 15, winId, getAndSetInstanceId(this), callbackMethodName, args ]);
118
- }));
119
- Cstr.observedAttributes = ceData[1];
120
- return Cstr;
121
- };
122
- const serializeForWorker = ($winId$, value, added, type, cstrName) => void 0 !== value && (type = typeof value) ? "string" === type || "number" === type || "boolean" === type || null == value ? [ 0, value ] : "function" === type ? [ 6 ] : (added = added || new Set) && Array.isArray(value) ? added.has(value) ? [ 1, [] ] : added.add(value) && [ 1, value.map((v => serializeForWorker($winId$, v, added))) ] : "object" === type ? serializedValueIsError(value) ? [ 14, {
123
- name: value.name,
124
- message: value.message,
125
- stack: value.stack
126
- } ] : "" === (cstrName = getConstructorName(value)) ? [ 2, {} ] : "Window" === cstrName ? [ 3, [ $winId$, $winId$ ] ] : "HTMLCollection" === cstrName || "NodeList" === cstrName ? [ 7, Array.from(value).map((v => serializeForWorker($winId$, v, added)[1])) ] : cstrName.endsWith("Event") ? [ 5, serializeObjectForWorker($winId$, value, added) ] : "CSSRuleList" === cstrName ? [ 12, Array.from(value).map(serializeCssRuleForWorker) ] : startsWith(cstrName, "CSS") && cstrName.endsWith("Rule") ? [ 11, serializeCssRuleForWorker(value) ] : "CSSStyleDeclaration" === cstrName ? [ 13, serializeObjectForWorker($winId$, value, added) ] : "Attr" === cstrName ? [ 10, [ value.name, value.value ] ] : value.nodeType ? [ 3, [ $winId$, getAndSetInstanceId(value), getNodeName(value) ] ] : [ 2, serializeObjectForWorker($winId$, value, added, true, true) ] : void 0 : value;
127
- const serializeObjectForWorker = (winId, obj, added, includeFunctions, includeEmptyStrings, serializedObj, propName, propValue) => {
128
- serializedObj = {};
129
- if (!added.has(obj)) {
130
- added.add(obj);
131
- for (propName in obj) {
132
- if (isValidMemberName(propName)) {
133
- propValue = "path" === propName && getConstructorName(obj).endsWith("Event") ? obj.composedPath() : obj[propName];
134
- (includeFunctions || "function" != typeof propValue) && (includeEmptyStrings || "" !== propValue) && (serializedObj[propName] = serializeForWorker(winId, propValue, added));
135
- }
432
+ instance = instance[current];
433
+ } else {
434
+ if (0 === next) {
435
+ instance[previous] = deserializeFromWorker(worker, current);
436
+ return;
136
437
  }
137
- }
138
- return serializedObj;
139
- };
140
- const serializeCssRuleForWorker = cssRule => {
141
- let obj = {};
142
- let key;
143
- for (key in cssRule) {
144
- validCssRuleProps.includes(key) && (obj[key] = String(cssRule[key]));
145
- }
146
- return obj;
147
- };
148
- const serializedValueIsError = value => value instanceof window.top.Error;
149
- const deserializeFromWorker = (worker, serializedTransfer, serializedType, serializedValue) => {
150
- if (serializedTransfer) {
151
- serializedType = serializedTransfer[0];
152
- serializedValue = serializedTransfer[1];
153
- return 0 === serializedType ? serializedValue : 4 === serializedType ? deserializeRefFromWorker(worker, serializedValue) : 1 === serializedType ? serializedValue.map((v => deserializeFromWorker(worker, v))) : 3 === serializedType ? getInstance(serializedValue[0], serializedValue[1]) : 5 === serializedType ? constructEvent(deserializeObjectFromWorker(worker, serializedValue)) : 2 === serializedType ? deserializeObjectFromWorker(worker, serializedValue) : 8 === serializedType ? serializedValue : 9 === serializedType ? new window[serializedTransfer[2]](serializedValue) : void 0;
154
- }
155
- };
156
- const deserializeRefFromWorker = (worker, {$winId$: $winId$, $instanceId$: $instanceId$, $refId$: $refId$}, ref) => {
157
- ref = mainRefs.get($refId$);
158
- if (!ref) {
159
- ref = function(...args) {
160
- worker.postMessage([ 9, {
161
- $winId$: $winId$,
162
- $instanceId$: $instanceId$,
163
- $refId$: $refId$,
164
- $thisArg$: serializeForWorker($winId$, this),
165
- $args$: serializeForWorker($winId$, args)
166
- } ]);
167
- };
168
- mainRefs.set($refId$, ref);
169
- }
170
- return ref;
171
- };
172
- const constructEvent = eventProps => new ("detail" in eventProps ? CustomEvent : Event)(eventProps.type, eventProps);
173
- const deserializeObjectFromWorker = (worker, serializedValue, obj, key) => {
174
- obj = {};
175
- for (key in serializedValue) {
176
- obj[key] = deserializeFromWorker(worker, serializedValue[key]);
177
- }
178
- return obj;
179
- };
180
- const validCssRuleProps = "cssText,selectorText,href,media,namespaceURI,prefix,name,conditionText".split(",");
181
- const mainAccessHandler = async (worker, accessReq) => {
182
- let accessRsp = {
183
- $msgId$: accessReq.$msgId$
184
- };
185
- let totalTasks = len(accessReq.$tasks$);
186
- let i = 0;
187
- let task;
188
- let winId;
189
- let applyPath;
190
- let instance;
191
- let rtnValue;
192
- let isLast;
193
- for (;i < totalTasks; i++) {
194
- try {
195
- isLast = i === totalTasks - 1;
196
- task = accessReq.$tasks$[i];
197
- winId = task.$winId$;
198
- applyPath = task.$applyPath$;
199
- !winCtxs[winId] && winId.startsWith("f_") && await new Promise((resolve => {
200
- let check = 0;
201
- let callback = () => {
202
- winCtxs[winId] || check++ > 1e3 ? resolve() : requestAnimationFrame(callback);
203
- };
204
- callback();
205
- }));
206
- if (1 === applyPath[0] && applyPath[1] in winCtxs[winId].$window$) {
207
- setInstanceId(new winCtxs[winId].$window$[applyPath[1]](...deserializeFromWorker(worker, applyPath[2])), task.$instanceId$);
208
- } else {
209
- instance = getInstance(winId, task.$instanceId$);
210
- if (instance) {
211
- rtnValue = applyToInstance(worker, winId, instance, applyPath, isLast, task.$groupedGetters$);
212
- task.$assignInstanceId$ && ("string" == typeof task.$assignInstanceId$ ? setInstanceId(rtnValue, task.$assignInstanceId$) : winCtxs[task.$assignInstanceId$.$winId$] = {
213
- $winId$: task.$assignInstanceId$.$winId$,
214
- $window$: {
215
- document: rtnValue
216
- }
217
- });
218
- if (isPromise(rtnValue)) {
219
- rtnValue = await rtnValue;
220
- isLast && (accessRsp.$isPromise$ = true);
221
- }
222
- isLast && (accessRsp.$rtnValue$ = serializeForWorker(winId, rtnValue));
223
- } else {
224
- accessRsp.$error$ = `Error finding instance "${task.$instanceId$}" on window ${normalizedWinId(winId)}`;
225
- console.error(accessRsp.$error$, task);
226
- }
227
- }
228
- } catch (e) {
229
- isLast ? accessRsp.$error$ = String(e.stack || e) : console.error(e);
438
+ if ("function" == typeof instance[previous]) {
439
+ args = deserializeFromWorker(worker, current);
440
+ "define" === previous &&
441
+ "CustomElementRegistry" === getConstructorName(instance) &&
442
+ (args[1] = defineCustomElement(winId, worker, args[1]));
443
+ "insertRule" === previous &&
444
+ args[1] > len(instance.cssRules) &&
445
+ (args[1] = len(instance.cssRules));
446
+ instance = instance[previous].apply(instance, args);
447
+ if ("play" === previous) {
448
+ return Promise.resolve();
449
+ }
230
450
  }
451
+ }
231
452
  }
232
- return accessRsp;
233
- };
234
- const applyToInstance = (worker, winId, instance, applyPath, isLast, groupedGetters) => {
235
- let i = 0;
236
- let l = len(applyPath);
237
- let next;
238
- let current;
239
- let previous;
240
- let args;
241
- let groupedRtnValues;
242
- for (;i < l; i++) {
243
- current = applyPath[i];
244
- next = applyPath[i + 1];
245
- previous = applyPath[i - 1];
246
- try {
247
- if (!Array.isArray(next)) {
248
- if ("string" == typeof current || "number" == typeof current) {
249
- if (i + 1 === l && groupedGetters) {
250
- groupedRtnValues = {};
251
- groupedGetters.map((propName => groupedRtnValues[propName] = instance[propName]));
252
- return groupedRtnValues;
253
- }
254
- instance = instance[current];
255
- } else {
256
- if (0 === next) {
257
- instance[previous] = deserializeFromWorker(worker, current);
258
- return;
259
- }
260
- if ("function" == typeof instance[previous]) {
261
- args = deserializeFromWorker(worker, current);
262
- "define" === previous && "CustomElementRegistry" === getConstructorName(instance) && (args[1] = defineCustomElement(winId, worker, args[1]));
263
- "insertRule" === previous && args[1] > len(instance.cssRules) && (args[1] = len(instance.cssRules));
264
- instance = instance[previous].apply(instance, args);
265
- if ("play" === previous) {
266
- return Promise.resolve();
267
- }
268
- }
269
- }
270
- }
271
- } catch (err) {
272
- if (isLast) {
273
- throw err;
274
- }
275
- console.debug("Non-blocking setter error:", err);
276
- }
453
+ } catch (err) {
454
+ if (isLast) {
455
+ throw err;
277
456
  }
278
- return instance;
279
- };
280
- const readNextScript = (worker, winCtx) => {
281
- let $winId$ = winCtx.$winId$;
282
- let win = winCtx.$window$;
283
- let doc = win.document;
284
- let scriptSelector = 'script[type="text/partytown"]:not([data-ptid]):not([data-pterror])';
285
- let scriptElm;
286
- let $instanceId$;
287
- let scriptData;
288
- if (doc && doc.body) {
289
- scriptElm = doc.querySelector('script[type="text/partytown"]:not([data-ptid]):not([data-pterror]):not([async]):not([defer])');
290
- scriptElm || (scriptElm = doc.querySelector(scriptSelector));
291
- if (scriptElm) {
292
- scriptElm.dataset.ptid = $instanceId$ = getAndSetInstanceId(scriptElm, $winId$);
293
- scriptData = {
294
- $winId$: $winId$,
295
- $instanceId$: $instanceId$
296
- };
297
- if (scriptElm.src) {
298
- scriptData.$url$ = scriptElm.src;
299
- scriptData.$orgUrl$ = scriptElm.dataset.ptsrc || scriptElm.src;
300
- } else {
301
- scriptData.$content$ = scriptElm.innerHTML;
302
- }
303
- worker.postMessage([ 7, scriptData ]);
304
- } else {
305
- if (!winCtx.$isInitialized$) {
306
- winCtx.$isInitialized$ = 1;
307
- ((worker, $winId$, win) => {
308
- let queuedForwardCalls = win._ptf;
309
- let forwards = (win.partytown || {}).forward || [];
310
- let i;
311
- let mainForwardFn;
312
- let forwardCall = ($forward$, args) => worker.postMessage([ 10, {
313
- $winId$: $winId$,
314
- $forward$: $forward$,
315
- $args$: serializeForWorker($winId$, Array.from(args))
316
- } ]);
317
- win._ptf = void 0;
318
- forwards.map((forwardProps => {
319
- mainForwardFn = win;
320
- forwardProps.split(".").map(((_, i, arr) => {
321
- mainForwardFn = mainForwardFn[arr[i]] = i + 1 < len(arr) ? mainForwardFn[arr[i]] || ("push" === arr[i + 1] ? [] : {}) : (...args) => forwardCall(arr, args);
322
- }));
323
- }));
324
- if (queuedForwardCalls) {
325
- for (i = 0; i < len(queuedForwardCalls); i += 2) {
326
- forwardCall(queuedForwardCalls[i], queuedForwardCalls[i + 1]);
327
- }
328
- }
329
- })(worker, $winId$, win);
330
- doc.dispatchEvent(new CustomEvent("pt0"));
331
- {
332
- const winType = win === win.top ? "top" : "iframe";
333
- logMain(`Executed ${winType} window ${normalizedWinId($winId$)} environment scripts in ${(performance.now() - winCtx.$startTime$).toFixed(1)}ms`);
334
- }
335
- }
336
- worker.postMessage([ 8, $winId$ ]);
337
- }
457
+ console.debug("Non-blocking setter error:", err);
458
+ }
459
+ }
460
+ return instance;
461
+ };
462
+ const readNextScript = (worker, winCtx) => {
463
+ let $winId$ = winCtx.$winId$;
464
+ let win = winCtx.$window$;
465
+ let doc = win.document;
466
+ let scriptSelector =
467
+ 'script[type="text/partytown"]:not([data-ptid]):not([data-pterror])';
468
+ let scriptElm;
469
+ let $instanceId$;
470
+ let scriptData;
471
+ if (doc && doc.body) {
472
+ scriptElm = doc.querySelector(
473
+ 'script[type="text/partytown"]:not([data-ptid]):not([data-pterror]):not([async]):not([defer])'
474
+ );
475
+ scriptElm || (scriptElm = doc.querySelector(scriptSelector));
476
+ if (scriptElm) {
477
+ scriptElm.dataset.ptid = $instanceId$ = getAndSetInstanceId(
478
+ scriptElm,
479
+ $winId$
480
+ );
481
+ scriptData = {
482
+ $winId$: $winId$,
483
+ $instanceId$: $instanceId$,
484
+ };
485
+ if (scriptElm.src) {
486
+ scriptData.$url$ = scriptElm.src;
487
+ scriptData.$orgUrl$ = scriptElm.dataset.ptsrc || scriptElm.src;
338
488
  } else {
339
- requestAnimationFrame((() => readNextScript(worker, winCtx)));
489
+ scriptData.$content$ = scriptElm.innerHTML;
340
490
  }
341
- };
342
- const registerWindow = (worker, $winId$, $window$) => {
343
- if (!windowIds.has($window$)) {
344
- windowIds.set($window$, $winId$);
345
- const doc = $window$.document;
346
- const history = $window$.history;
347
- const $parentWinId$ = windowIds.get($window$.parent);
348
- let initialised = false;
349
- const onInitialisedQueue = [];
350
- const onInitialised = callback => {
351
- initialised ? callback() : onInitialisedQueue.push(callback);
352
- };
353
- const sendInitEnvData = () => {
354
- worker.postMessage([ 5, {
355
- $winId$: $winId$,
356
- $parentWinId$: $parentWinId$,
357
- $url$: doc.baseURI,
358
- $visibilityState$: doc.visibilityState
359
- } ]);
360
- setTimeout((() => {
361
- initialised = true;
362
- onInitialisedQueue.forEach((callback => {
363
- callback();
364
- }));
365
- }));
366
- };
367
- const pushState = history.pushState.bind(history);
368
- const replaceState = history.replaceState.bind(history);
369
- const onLocationChange = (type, state, newUrl, oldUrl) => () => {
370
- setTimeout((() => {
371
- worker.postMessage([ 13, {
372
- $winId$: $winId$,
373
- type: type,
374
- state: state,
375
- url: doc.baseURI,
376
- newUrl: newUrl,
377
- oldUrl: oldUrl
378
- } ]);
379
- }));
380
- };
381
- history.pushState = (state, _, newUrl) => {
382
- pushState(state, _, newUrl);
383
- onInitialised(onLocationChange(0, state, null == newUrl ? void 0 : newUrl.toString()));
384
- };
385
- history.replaceState = (state, _, newUrl) => {
386
- replaceState(state, _, newUrl);
387
- onInitialised(onLocationChange(1, state, null == newUrl ? void 0 : newUrl.toString()));
388
- };
389
- $window$.addEventListener("popstate", (event => {
390
- onInitialised(onLocationChange(2, event.state));
391
- }));
392
- $window$.addEventListener("hashchange", (event => {
393
- onInitialised(onLocationChange(3, {}, event.newURL, event.oldURL));
394
- }));
395
- $window$.addEventListener("ptupdate", (() => {
396
- readNextScript(worker, winCtxs[$winId$]);
397
- }));
398
- doc.addEventListener("visibilitychange", (() => worker.postMessage([ 14, $winId$, doc.visibilityState ])));
399
- winCtxs[$winId$] = {
400
- $winId$: $winId$,
401
- $window$: $window$
402
- };
403
- winCtxs[$winId$].$startTime$ = performance.now();
404
- {
405
- const winType = $winId$ === $parentWinId$ ? "top" : "iframe";
406
- logMain(`Registered ${winType} window ${normalizedWinId($winId$)}`);
491
+ worker.postMessage([7, scriptData]);
492
+ } else {
493
+ if (!winCtx.$isInitialized$) {
494
+ winCtx.$isInitialized$ = 1;
495
+ ((worker, $winId$, win) => {
496
+ let queuedForwardCalls = win._ptf;
497
+ let forwards = (win.partytown || {}).forward || [];
498
+ let i;
499
+ let mainForwardFn;
500
+ let forwardCall = ($forward$, args) =>
501
+ worker.postMessage([
502
+ 10,
503
+ {
504
+ $winId$: $winId$,
505
+ $forward$: $forward$,
506
+ $args$: serializeForWorker($winId$, Array.from(args)),
507
+ },
508
+ ]);
509
+ win._ptf = void 0;
510
+ forwards.map((forwardProps) => {
511
+ mainForwardFn = win;
512
+ forwardProps.split(".").map((_, i, arr) => {
513
+ mainForwardFn = mainForwardFn[arr[i]] =
514
+ i + 1 < len(arr)
515
+ ? mainForwardFn[arr[i]] || ("push" === arr[i + 1] ? [] : {})
516
+ : (...args) => forwardCall(arr, args);
517
+ });
518
+ });
519
+ if (queuedForwardCalls) {
520
+ for (i = 0; i < len(queuedForwardCalls); i += 2) {
521
+ forwardCall(queuedForwardCalls[i], queuedForwardCalls[i + 1]);
522
+ }
407
523
  }
408
- "complete" === doc.readyState ? sendInitEnvData() : $window$.addEventListener("load", sendInitEnvData);
524
+ })(worker, $winId$, win);
525
+ doc.dispatchEvent(new CustomEvent("pt0"));
526
+ {
527
+ const winType = win === win.top ? "top" : "input";
528
+ logMain(
529
+ `Executed ${winType} window ${normalizedWinId(
530
+ $winId$
531
+ )} environment scripts in ${(
532
+ performance.now() - winCtx.$startTime$
533
+ ).toFixed(1)}ms`
534
+ );
535
+ }
409
536
  }
410
- };
411
- const onMessageFromWebWorker = (worker, msg, winCtx) => {
412
- if (4 === msg[0]) {
413
- registerWindow(worker, randomId(), mainWindow);
414
- } else {
415
- winCtx = winCtxs[msg[1]];
416
- winCtx && (7 === msg[0] ? requestAnimationFrame((() => readNextScript(worker, winCtx))) : 6 === msg[0] && ((worker, winCtx, instanceId, errorMsg, scriptElm) => {
417
- scriptElm = winCtx.$window$.document.querySelector(`[data-ptid="${instanceId}"]`);
418
- if (scriptElm) {
419
- errorMsg ? scriptElm.dataset.pterror = errorMsg : scriptElm.type += "-x";
420
- delete scriptElm.dataset.ptid;
421
- }
422
- readNextScript(worker, winCtx);
537
+ worker.postMessage([8, $winId$]);
538
+ }
539
+ } else {
540
+ requestAnimationFrame(() => readNextScript(worker, winCtx));
541
+ }
542
+ };
543
+ const registerWindow = (worker, $winId$, $window$) => {
544
+ if (!windowIds.has($window$)) {
545
+ windowIds.set($window$, $winId$);
546
+ const doc = $window$.document;
547
+ const history = $window$.history;
548
+ const $parentWinId$ = windowIds.get($window$.parent);
549
+ let initialised = false;
550
+ const onInitialisedQueue = [];
551
+ const onInitialised = (callback) => {
552
+ initialised ? callback() : onInitialisedQueue.push(callback);
553
+ };
554
+ const sendInitEnvData = () => {
555
+ worker.postMessage([
556
+ 5,
557
+ {
558
+ $winId$: $winId$,
559
+ $parentWinId$: $parentWinId$,
560
+ $url$: doc.baseURI,
561
+ $visibilityState$: doc.visibilityState,
562
+ },
563
+ ]);
564
+ setTimeout(() => {
565
+ initialised = true;
566
+ onInitialisedQueue.forEach((callback) => {
567
+ callback();
568
+ });
569
+ });
570
+ };
571
+ const pushState = history.pushState.bind(history);
572
+ const replaceState = history.replaceState.bind(history);
573
+ const onLocationChange = (type, state, newUrl, oldUrl) => () => {
574
+ setTimeout(() => {
575
+ worker.postMessage([
576
+ 13,
577
+ {
578
+ $winId$: $winId$,
579
+ type: type,
580
+ state: state,
581
+ url: doc.baseURI,
582
+ newUrl: newUrl,
583
+ oldUrl: oldUrl,
584
+ },
585
+ ]);
586
+ });
587
+ };
588
+ history.pushState = (state, _, newUrl) => {
589
+ pushState(state, _, newUrl);
590
+ onInitialised(
591
+ onLocationChange(
592
+ 0,
593
+ state,
594
+ null == newUrl ? void 0 : newUrl.toString()
595
+ )
596
+ );
597
+ };
598
+ history.replaceState = (state, _, newUrl) => {
599
+ replaceState(state, _, newUrl);
600
+ onInitialised(
601
+ onLocationChange(
602
+ 1,
603
+ state,
604
+ null == newUrl ? void 0 : newUrl.toString()
605
+ )
606
+ );
607
+ };
608
+ $window$.addEventListener("popstate", (event) => {
609
+ onInitialised(onLocationChange(2, event.state));
610
+ });
611
+ $window$.addEventListener("hashchange", (event) => {
612
+ onInitialised(onLocationChange(3, {}, event.newURL, event.oldURL));
613
+ });
614
+ $window$.addEventListener("ptupdate", () => {
615
+ readNextScript(worker, winCtxs[$winId$]);
616
+ });
617
+ doc.addEventListener("visibilitychange", () =>
618
+ worker.postMessage([14, $winId$, doc.visibilityState])
619
+ );
620
+ winCtxs[$winId$] = {
621
+ $winId$: $winId$,
622
+ $window$: $window$,
623
+ };
624
+ winCtxs[$winId$].$startTime$ = performance.now();
625
+ {
626
+ const winType = $winId$ === $parentWinId$ ? "top" : "input";
627
+ logMain(`Registered ${winType} window ${normalizedWinId($winId$)}`);
628
+ }
629
+ "complete" === doc.readyState
630
+ ? sendInitEnvData()
631
+ : $window$.addEventListener("load", sendInitEnvData);
632
+ }
633
+ };
634
+ const onMessageFromWebWorker = (worker, msg, winCtx) => {
635
+ if (4 === msg[0]) {
636
+ registerWindow(worker, randomId(), mainWindow);
637
+ } else {
638
+ winCtx = winCtxs[msg[1]];
639
+ winCtx &&
640
+ (7 === msg[0]
641
+ ? requestAnimationFrame(() => readNextScript(worker, winCtx))
642
+ : 6 === msg[0] &&
643
+ ((worker, winCtx, instanceId, errorMsg, scriptElm) => {
644
+ scriptElm = winCtx.$window$.document.querySelector(
645
+ `[data-ptid="${instanceId}"]`
646
+ );
647
+ if (scriptElm) {
648
+ errorMsg
649
+ ? (scriptElm.dataset.pterror = errorMsg)
650
+ : (scriptElm.type += "-x");
651
+ delete scriptElm.dataset.ptid;
652
+ }
653
+ readNextScript(worker, winCtx);
423
654
  })(worker, winCtx, msg[2], msg[3]));
655
+ }
656
+ };
657
+ const readMainInterfaces = () => {
658
+ const elms = Object.getOwnPropertyNames(mainWindow)
659
+ .map((interfaceName) =>
660
+ ((doc, interfaceName, r, tag) => {
661
+ r = interfaceName.match(/^(HTML|SVG)(.+)Element$/);
662
+ if (r) {
663
+ tag = r[2];
664
+ return "S" == interfaceName[0]
665
+ ? doc.createElementNS(
666
+ "http://www.w3.org/2000/svg",
667
+ svgConstructorTags[tag] ||
668
+ tag.slice(0, 2).toLowerCase() + tag.slice(2)
669
+ )
670
+ : doc.createElement(htmlConstructorTags[tag] || tag);
671
+ }
672
+ })(docImpl, interfaceName)
673
+ )
674
+ .filter((elm) => elm)
675
+ .map((elm) => [elm]);
676
+ return readImplementations(elms, []);
677
+ };
678
+ const cstrs = new Set(["Object"]);
679
+ const readImplementations = (impls, interfaces) => {
680
+ const cstrImpls = impls
681
+ .filter((implData) => implData[0])
682
+ .map((implData) => {
683
+ const impl = implData[0];
684
+ const interfaceType = implData[1];
685
+ const cstrName = getConstructorName(impl);
686
+ const CstrPrototype = mainWindow[cstrName].prototype;
687
+ return [cstrName, CstrPrototype, impl, interfaceType];
688
+ });
689
+ cstrImpls.map(([cstrName, CstrPrototype, impl, intefaceType]) =>
690
+ readOwnImplementation(
691
+ cstrs,
692
+ interfaces,
693
+ cstrName,
694
+ CstrPrototype,
695
+ impl,
696
+ intefaceType
697
+ )
698
+ );
699
+ return interfaces;
700
+ };
701
+ const readImplementation = (cstrName, impl, memberName) => {
702
+ let interfaceMembers = [];
703
+ let interfaceInfo = [cstrName, "Object", interfaceMembers];
704
+ for (memberName in impl) {
705
+ readImplementationMember(interfaceMembers, impl, memberName);
706
+ }
707
+ return interfaceInfo;
708
+ };
709
+ const readOwnImplementation = (
710
+ cstrs,
711
+ interfaces,
712
+ cstrName,
713
+ CstrPrototype,
714
+ impl,
715
+ interfaceType
716
+ ) => {
717
+ if (!cstrs.has(cstrName)) {
718
+ cstrs.add(cstrName);
719
+ const SuperCstr = Object.getPrototypeOf(CstrPrototype);
720
+ const superCstrName = getConstructorName(SuperCstr);
721
+ const interfaceMembers = [];
722
+ const propDescriptors = Object.getOwnPropertyDescriptors(CstrPrototype);
723
+ readOwnImplementation(
724
+ cstrs,
725
+ interfaces,
726
+ superCstrName,
727
+ SuperCstr,
728
+ impl,
729
+ interfaceType
730
+ );
731
+ for (const memberName in propDescriptors) {
732
+ readImplementationMember(interfaceMembers, impl, memberName);
733
+ }
734
+ interfaces.push([
735
+ cstrName,
736
+ superCstrName,
737
+ interfaceMembers,
738
+ interfaceType,
739
+ getNodeName(impl),
740
+ ]);
741
+ }
742
+ };
743
+ const readImplementationMember = (
744
+ interfaceMembers,
745
+ implementation,
746
+ memberName,
747
+ value,
748
+ memberType,
749
+ cstrName
750
+ ) => {
751
+ try {
752
+ if (
753
+ isValidMemberName(memberName) &&
754
+ isNaN(memberName[0]) &&
755
+ "all" !== memberName
756
+ ) {
757
+ value = implementation[memberName];
758
+ memberType = typeof value;
759
+ if ("function" === memberType) {
760
+ (String(value).includes("[native") ||
761
+ Object.getPrototypeOf(implementation)[memberName]) &&
762
+ interfaceMembers.push([memberName, 5]);
763
+ } else if ("object" === memberType && null != value) {
764
+ cstrName = getConstructorName(value);
765
+ "Object" !== cstrName &&
766
+ self[cstrName] &&
767
+ interfaceMembers.push([memberName, value.nodeType || cstrName]);
768
+ } else {
769
+ "symbol" !== memberType &&
770
+ (memberName.toUpperCase() === memberName
771
+ ? interfaceMembers.push([memberName, 6, value])
772
+ : interfaceMembers.push([memberName, 6]));
424
773
  }
425
- };
426
- const readMainInterfaces = () => {
427
- const elms = Object.getOwnPropertyNames(mainWindow).map((interfaceName => ((doc, interfaceName, r, tag) => {
428
- r = interfaceName.match(/^(HTML|SVG)(.+)Element$/);
429
- if (r) {
430
- tag = r[2];
431
- return "S" == interfaceName[0] ? doc.createElementNS("http://www.w3.org/2000/svg", svgConstructorTags[tag] || tag.slice(0, 2).toLowerCase() + tag.slice(2)) : doc.createElement(htmlConstructorTags[tag] || tag);
432
- }
433
- })(docImpl, interfaceName))).filter((elm => elm)).map((elm => [ elm ]));
434
- return readImplementations(elms, []);
435
- };
436
- const cstrs = new Set([ "Object" ]);
437
- const readImplementations = (impls, interfaces) => {
438
- const cstrImpls = impls.filter((implData => implData[0])).map((implData => {
439
- const impl = implData[0];
440
- const interfaceType = implData[1];
441
- const cstrName = getConstructorName(impl);
442
- const CstrPrototype = mainWindow[cstrName].prototype;
443
- return [ cstrName, CstrPrototype, impl, interfaceType ];
444
- }));
445
- cstrImpls.map((([cstrName, CstrPrototype, impl, intefaceType]) => readOwnImplementation(cstrs, interfaces, cstrName, CstrPrototype, impl, intefaceType)));
446
- return interfaces;
447
- };
448
- const readImplementation = (cstrName, impl, memberName) => {
449
- let interfaceMembers = [];
450
- let interfaceInfo = [ cstrName, "Object", interfaceMembers ];
451
- for (memberName in impl) {
452
- readImplementationMember(interfaceMembers, impl, memberName);
453
- }
454
- return interfaceInfo;
455
- };
456
- const readOwnImplementation = (cstrs, interfaces, cstrName, CstrPrototype, impl, interfaceType) => {
457
- if (!cstrs.has(cstrName)) {
458
- cstrs.add(cstrName);
459
- const SuperCstr = Object.getPrototypeOf(CstrPrototype);
460
- const superCstrName = getConstructorName(SuperCstr);
461
- const interfaceMembers = [];
462
- const propDescriptors = Object.getOwnPropertyDescriptors(CstrPrototype);
463
- readOwnImplementation(cstrs, interfaces, superCstrName, SuperCstr, impl, interfaceType);
464
- for (const memberName in propDescriptors) {
465
- readImplementationMember(interfaceMembers, impl, memberName);
466
- }
467
- interfaces.push([ cstrName, superCstrName, interfaceMembers, interfaceType, getNodeName(impl) ]);
468
- }
469
- };
470
- const readImplementationMember = (interfaceMembers, implementation, memberName, value, memberType, cstrName) => {
471
- try {
472
- if (isValidMemberName(memberName) && isNaN(memberName[0]) && "all" !== memberName) {
473
- value = implementation[memberName];
474
- memberType = typeof value;
475
- if ("function" === memberType) {
476
- (String(value).includes("[native") || Object.getPrototypeOf(implementation)[memberName]) && interfaceMembers.push([ memberName, 5 ]);
477
- } else if ("object" === memberType && null != value) {
478
- cstrName = getConstructorName(value);
479
- "Object" !== cstrName && self[cstrName] && interfaceMembers.push([ memberName, value.nodeType || cstrName ]);
480
- } else {
481
- "symbol" !== memberType && (memberName.toUpperCase() === memberName ? interfaceMembers.push([ memberName, 6, value ]) : interfaceMembers.push([ memberName, 6 ]));
482
- }
774
+ }
775
+ } catch (e) {
776
+ console.warn(e);
777
+ }
778
+ };
779
+ const readStorage = (storageName) => {
780
+ let items = [];
781
+ let i = 0;
782
+ let l = len(mainWindow[storageName]);
783
+ let key;
784
+ for (; i < l; i++) {
785
+ key = mainWindow[storageName].key(i);
786
+ items.push([key, mainWindow[storageName].getItem(key)]);
787
+ }
788
+ return items;
789
+ };
790
+ const getGlobalConstructor = (mainWindow, cstrName) =>
791
+ void 0 !== mainWindow[cstrName] ? new mainWindow[cstrName](noop) : 0;
792
+ const addGlobalConstructorUsingPrototype = (
793
+ $interfaces$,
794
+ mainWindow,
795
+ cstrName
796
+ ) => {
797
+ void 0 !== mainWindow[cstrName] &&
798
+ $interfaces$.push([
799
+ cstrName,
800
+ "Object",
801
+ Object.keys(mainWindow[cstrName].prototype).map((propName) => [
802
+ propName,
803
+ 6,
804
+ ]),
805
+ 12,
806
+ ]);
807
+ };
808
+ let worker;
809
+ (async (receiveMessage) => {
810
+ const sharedDataBuffer = new SharedArrayBuffer(1073741824);
811
+ const sharedData = new Int32Array(sharedDataBuffer);
812
+ return (worker, msg) => {
813
+ const msgType = msg[0];
814
+ const accessReq = msg[1];
815
+ if (0 === msgType) {
816
+ const initData = (() => {
817
+ const elm = docImpl.createElement("i");
818
+ const textNode = docImpl.createTextNode("");
819
+ const comment = docImpl.createComment("");
820
+ const frag = docImpl.createDocumentFragment();
821
+ const shadowRoot = docImpl.createElement("p").attachShadow({
822
+ mode: "open",
823
+ });
824
+ const intersectionObserver = getGlobalConstructor(
825
+ mainWindow,
826
+ "IntersectionObserver"
827
+ );
828
+ const mutationObserver = getGlobalConstructor(
829
+ mainWindow,
830
+ "MutationObserver"
831
+ );
832
+ const resizeObserver = getGlobalConstructor(
833
+ mainWindow,
834
+ "ResizeObserver"
835
+ );
836
+ const perf = mainWindow.performance;
837
+ const screen = mainWindow.screen;
838
+ const impls = [
839
+ [mainWindow.history],
840
+ [perf],
841
+ [perf.navigation],
842
+ [perf.timing],
843
+ [screen],
844
+ [screen.orientation],
845
+ [mainWindow.visualViewport],
846
+ [intersectionObserver, 12],
847
+ [mutationObserver, 12],
848
+ [resizeObserver, 12],
849
+ [textNode],
850
+ [comment],
851
+ [frag],
852
+ [shadowRoot],
853
+ [elm],
854
+ [elm.attributes],
855
+ [elm.classList],
856
+ [elm.dataset],
857
+ [elm.style],
858
+ [docImpl],
859
+ [docImpl.doctype],
860
+ ];
861
+ const initialInterfaces = [
862
+ readImplementation("Window", mainWindow),
863
+ readImplementation("Node", textNode),
864
+ ];
865
+ const $config$ = JSON.stringify(config, (k, v) => {
866
+ if ("function" == typeof v) {
867
+ v = String(v);
868
+ v.startsWith(k + "(") && (v = "function " + v);
483
869
  }
484
- } catch (e) {
485
- console.warn(e);
486
- }
870
+ return v;
871
+ });
872
+ const initWebWorkerData = {
873
+ $config$: $config$,
874
+ $interfaces$: readImplementations(impls, initialInterfaces),
875
+ $libPath$: new URL(libPath, mainWindow.location) + "",
876
+ $origin$: origin,
877
+ $localStorage$: readStorage("localStorage"),
878
+ $sessionStorage$: readStorage("sessionStorage"),
879
+ };
880
+ addGlobalConstructorUsingPrototype(
881
+ initWebWorkerData.$interfaces$,
882
+ mainWindow,
883
+ "IntersectionObserverEntry"
884
+ );
885
+ return initWebWorkerData;
886
+ })();
887
+ initData.$sharedDataBuffer$ = sharedDataBuffer;
888
+ worker.postMessage([1, initData]);
889
+ } else {
890
+ 2 === msg[0]
891
+ ? worker.postMessage([3, readMainInterfaces()])
892
+ : 11 === msgType
893
+ ? receiveMessage(accessReq, (accessRsp) => {
894
+ const stringifiedData = JSON.stringify(accessRsp);
895
+ const stringifiedDataLength = stringifiedData.length;
896
+ for (let i = 0; i < stringifiedDataLength; i++) {
897
+ sharedData[i + 1] = stringifiedData.charCodeAt(i);
898
+ }
899
+ sharedData[0] = stringifiedDataLength;
900
+ Atomics.notify(sharedData, 0);
901
+ })
902
+ : onMessageFromWebWorker(worker, msg);
903
+ }
487
904
  };
488
- const readStorage = storageName => {
489
- let items = [];
490
- let i = 0;
491
- let l = len(mainWindow[storageName]);
492
- let key;
493
- for (;i < l; i++) {
494
- key = mainWindow[storageName].key(i);
495
- items.push([ key, mainWindow[storageName].getItem(key) ]);
496
- }
497
- return items;
498
- };
499
- const getGlobalConstructor = (mainWindow, cstrName) => void 0 !== mainWindow[cstrName] ? new mainWindow[cstrName](noop) : 0;
500
- const addGlobalConstructorUsingPrototype = ($interfaces$, mainWindow, cstrName) => {
501
- void 0 !== mainWindow[cstrName] && $interfaces$.push([ cstrName, "Object", Object.keys(mainWindow[cstrName].prototype).map((propName => [ propName, 6 ])), 12 ]);
502
- };
503
- let worker;
504
- (async receiveMessage => {
505
- const sharedDataBuffer = new SharedArrayBuffer(1073741824);
506
- const sharedData = new Int32Array(sharedDataBuffer);
507
- return (worker, msg) => {
508
- const msgType = msg[0];
509
- const accessReq = msg[1];
510
- if (0 === msgType) {
511
- const initData = (() => {
512
- const elm = docImpl.createElement("i");
513
- const textNode = docImpl.createTextNode("");
514
- const comment = docImpl.createComment("");
515
- const frag = docImpl.createDocumentFragment();
516
- const shadowRoot = docImpl.createElement("p").attachShadow({
517
- mode: "open"
518
- });
519
- const intersectionObserver = getGlobalConstructor(mainWindow, "IntersectionObserver");
520
- const mutationObserver = getGlobalConstructor(mainWindow, "MutationObserver");
521
- const resizeObserver = getGlobalConstructor(mainWindow, "ResizeObserver");
522
- const perf = mainWindow.performance;
523
- const screen = mainWindow.screen;
524
- const impls = [ [ mainWindow.history ], [ perf ], [ perf.navigation ], [ perf.timing ], [ screen ], [ screen.orientation ], [ mainWindow.visualViewport ], [ intersectionObserver, 12 ], [ mutationObserver, 12 ], [ resizeObserver, 12 ], [ textNode ], [ comment ], [ frag ], [ shadowRoot ], [ elm ], [ elm.attributes ], [ elm.classList ], [ elm.dataset ], [ elm.style ], [ docImpl ], [ docImpl.doctype ] ];
525
- const initialInterfaces = [ readImplementation("Window", mainWindow), readImplementation("Node", textNode) ];
526
- const $config$ = JSON.stringify(config, ((k, v) => {
527
- if ("function" == typeof v) {
528
- v = String(v);
529
- v.startsWith(k + "(") && (v = "function " + v);
530
- }
531
- return v;
532
- }));
533
- const initWebWorkerData = {
534
- $config$: $config$,
535
- $interfaces$: readImplementations(impls, initialInterfaces),
536
- $libPath$: new URL(libPath, mainWindow.location) + "",
537
- $origin$: origin,
538
- $localStorage$: readStorage("localStorage"),
539
- $sessionStorage$: readStorage("sessionStorage")
540
- };
541
- addGlobalConstructorUsingPrototype(initWebWorkerData.$interfaces$, mainWindow, "IntersectionObserverEntry");
542
- return initWebWorkerData;
543
- })();
544
- initData.$sharedDataBuffer$ = sharedDataBuffer;
545
- worker.postMessage([ 1, initData ]);
546
- } else {
547
- 2 === msg[0] ? worker.postMessage([ 3, readMainInterfaces() ]) : 11 === msgType ? receiveMessage(accessReq, (accessRsp => {
548
- const stringifiedData = JSON.stringify(accessRsp);
549
- const stringifiedDataLength = stringifiedData.length;
550
- for (let i = 0; i < stringifiedDataLength; i++) {
551
- sharedData[i + 1] = stringifiedData.charCodeAt(i);
552
- }
553
- sharedData[0] = stringifiedDataLength;
554
- Atomics.notify(sharedData, 0);
555
- })) : onMessageFromWebWorker(worker, msg);
556
- }
557
- };
558
- })(((accessReq, responseCallback) => mainAccessHandler(worker, accessReq).then(responseCallback))).then((onMessageHandler => {
559
- if (onMessageHandler) {
560
- worker = new Worker(libPath + "partytown-ww-atomics.js?v=0.7.5", {
561
- name: "Partytown 🎉"
562
- });
563
- worker.onmessage = ev => {
564
- const msg = ev.data;
565
- 12 === msg[0] ? mainAccessHandler(worker, msg[1]) : onMessageHandler(worker, msg);
566
- };
567
- logMain("Created Partytown web worker (0.7.5)");
568
- worker.onerror = ev => console.error("Web Worker Error", ev);
569
- mainWindow.addEventListener("pt1", (ev => registerWindow(worker, getAndSetInstanceId(ev.detail.frameElement), ev.detail)));
570
- }
571
- }));
905
+ })((accessReq, responseCallback) =>
906
+ mainAccessHandler(worker, accessReq).then(responseCallback)
907
+ ).then((onMessageHandler) => {
908
+ if (onMessageHandler) {
909
+ worker = new Worker(libPath + "partytown-ww-atomics.js?v=0.7.5", {
910
+ name: "Partytown 🎉",
911
+ });
912
+ worker.onmessage = (ev) => {
913
+ const msg = ev.data;
914
+ 12 === msg[0]
915
+ ? mainAccessHandler(worker, msg[1])
916
+ : onMessageHandler(worker, msg);
917
+ };
918
+ logMain("Created Partytown web worker (0.7.5)");
919
+ worker.onerror = (ev) => console.error("Web Worker Error", ev);
920
+ mainWindow.addEventListener("pt1", (ev) =>
921
+ registerWindow(
922
+ worker,
923
+ getAndSetInstanceId(ev.detail.frameElement),
924
+ ev.detail
925
+ )
926
+ );
927
+ }
928
+ });
572
929
  })(window);