appscms-tools-theme 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,559 +1,920 @@
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;
63
- }
64
- };
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;
83
- }
84
- }
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;
97
- }
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
- }
136
- }
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;
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
+ ));
154
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$,
155
331
  };
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
- } ]);
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);
167
354
  };
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);
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);
230
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
+ }
231
396
  }
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);
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;
276
431
  }
277
- }
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$ ]);
432
+ instance = instance[current];
433
+ } else {
434
+ if (0 === next) {
435
+ instance[previous] = deserializeFromWorker(worker, current);
436
+ return;
337
437
  }
338
- } else {
339
- requestAnimationFrame((() => readNextScript(worker, winCtx)));
340
- }
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$)}`);
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
+ }
407
450
  }
408
- "complete" === doc.readyState ? sendInitEnvData() : $window$.addEventListener("load", sendInitEnvData);
451
+ }
409
452
  }
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);
423
- })(worker, winCtx, msg[2], msg[3]));
453
+ } catch (err) {
454
+ if (isLast) {
455
+ throw err;
424
456
  }
425
- };
426
- const readMainPlatform = () => {
427
- const elm = docImpl.createElement("i");
428
- const textNode = docImpl.createTextNode("");
429
- const comment = docImpl.createComment("");
430
- const frag = docImpl.createDocumentFragment();
431
- const shadowRoot = docImpl.createElement("p").attachShadow({
432
- mode: "open"
433
- });
434
- const intersectionObserver = getGlobalConstructor(mainWindow, "IntersectionObserver");
435
- const mutationObserver = getGlobalConstructor(mainWindow, "MutationObserver");
436
- const resizeObserver = getGlobalConstructor(mainWindow, "ResizeObserver");
437
- const perf = mainWindow.performance;
438
- const screen = mainWindow.screen;
439
- 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 ] ];
440
- const initialInterfaces = [ readImplementation("Window", mainWindow), readImplementation("Node", textNode) ];
441
- const $config$ = JSON.stringify(config, ((k, v) => {
442
- if ("function" == typeof v) {
443
- v = String(v);
444
- v.startsWith(k + "(") && (v = "function " + v);
445
- }
446
- return v;
447
- }));
448
- const initWebWorkerData = {
449
- $config$: $config$,
450
- $interfaces$: readImplementations(impls, initialInterfaces),
451
- $libPath$: new URL(libPath, mainWindow.location) + "",
452
- $origin$: origin,
453
- $localStorage$: readStorage("localStorage"),
454
- $sessionStorage$: readStorage("sessionStorage")
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$,
455
484
  };
456
- addGlobalConstructorUsingPrototype(initWebWorkerData.$interfaces$, mainWindow, "IntersectionObserverEntry");
457
- return initWebWorkerData;
458
- };
459
- const readMainInterfaces = () => {
460
- const elms = Object.getOwnPropertyNames(mainWindow).map((interfaceName => ((doc, interfaceName, r, tag) => {
461
- r = interfaceName.match(/^(HTML|SVG)(.+)Element$/);
462
- if (r) {
463
- tag = r[2];
464
- 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);
465
- }
466
- })(docImpl, interfaceName))).filter((elm => elm)).map((elm => [ elm ]));
467
- return readImplementations(elms, []);
468
- };
469
- const cstrs = new Set([ "Object" ]);
470
- const readImplementations = (impls, interfaces) => {
471
- const cstrImpls = impls.filter((implData => implData[0])).map((implData => {
472
- const impl = implData[0];
473
- const interfaceType = implData[1];
474
- const cstrName = getConstructorName(impl);
475
- const CstrPrototype = mainWindow[cstrName].prototype;
476
- return [ cstrName, CstrPrototype, impl, interfaceType ];
477
- }));
478
- cstrImpls.map((([cstrName, CstrPrototype, impl, intefaceType]) => readOwnImplementation(cstrs, interfaces, cstrName, CstrPrototype, impl, intefaceType)));
479
- return interfaces;
480
- };
481
- const readImplementation = (cstrName, impl, memberName) => {
482
- let interfaceMembers = [];
483
- let interfaceInfo = [ cstrName, "Object", interfaceMembers ];
484
- for (memberName in impl) {
485
- readImplementationMember(interfaceMembers, impl, memberName);
486
- }
487
- return interfaceInfo;
488
- };
489
- const readOwnImplementation = (cstrs, interfaces, cstrName, CstrPrototype, impl, interfaceType) => {
490
- if (!cstrs.has(cstrName)) {
491
- cstrs.add(cstrName);
492
- const SuperCstr = Object.getPrototypeOf(CstrPrototype);
493
- const superCstrName = getConstructorName(SuperCstr);
494
- const interfaceMembers = [];
495
- const propDescriptors = Object.getOwnPropertyDescriptors(CstrPrototype);
496
- readOwnImplementation(cstrs, interfaces, superCstrName, SuperCstr, impl, interfaceType);
497
- for (const memberName in propDescriptors) {
498
- readImplementationMember(interfaceMembers, impl, memberName);
499
- }
500
- interfaces.push([ cstrName, superCstrName, interfaceMembers, interfaceType, getNodeName(impl) ]);
485
+ if (scriptElm.src) {
486
+ scriptData.$url$ = scriptElm.src;
487
+ scriptData.$orgUrl$ = scriptElm.dataset.ptsrc || scriptElm.src;
488
+ } else {
489
+ scriptData.$content$ = scriptElm.innerHTML;
501
490
  }
502
- };
503
- const readImplementationMember = (interfaceMembers, implementation, memberName, value, memberType, cstrName) => {
504
- try {
505
- if (isValidMemberName(memberName) && isNaN(memberName[0]) && "all" !== memberName) {
506
- value = implementation[memberName];
507
- memberType = typeof value;
508
- if ("function" === memberType) {
509
- (String(value).includes("[native") || Object.getPrototypeOf(implementation)[memberName]) && interfaceMembers.push([ memberName, 5 ]);
510
- } else if ("object" === memberType && null != value) {
511
- cstrName = getConstructorName(value);
512
- "Object" !== cstrName && self[cstrName] && interfaceMembers.push([ memberName, value.nodeType || cstrName ]);
513
- } else {
514
- "symbol" !== memberType && (memberName.toUpperCase() === memberName ? interfaceMembers.push([ memberName, 6, value ]) : interfaceMembers.push([ memberName, 6 ]));
515
- }
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
+ }
516
523
  }
517
- } catch (e) {
518
- console.warn(e);
524
+ })(worker, $winId$, win);
525
+ doc.dispatchEvent(new CustomEvent("pt0"));
526
+ {
527
+ const winType = win === win.top ? "top" : "iframe";
528
+ logMain(
529
+ `Executed ${winType} window ${normalizedWinId(
530
+ $winId$
531
+ )} environment scripts in ${(
532
+ performance.now() - winCtx.$startTime$
533
+ ).toFixed(1)}ms`
534
+ );
535
+ }
519
536
  }
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" : "iframe";
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);
654
+ })(worker, winCtx, msg[2], msg[3]));
655
+ }
656
+ };
657
+ const readMainPlatform = () => {
658
+ const elm = docImpl.createElement("i");
659
+ const textNode = docImpl.createTextNode("");
660
+ const comment = docImpl.createComment("");
661
+ const frag = docImpl.createDocumentFragment();
662
+ const shadowRoot = docImpl.createElement("p").attachShadow({
663
+ mode: "open",
664
+ });
665
+ const intersectionObserver = getGlobalConstructor(
666
+ mainWindow,
667
+ "IntersectionObserver"
668
+ );
669
+ const mutationObserver = getGlobalConstructor(
670
+ mainWindow,
671
+ "MutationObserver"
672
+ );
673
+ const resizeObserver = getGlobalConstructor(mainWindow, "ResizeObserver");
674
+ const perf = mainWindow.performance;
675
+ const screen = mainWindow.screen;
676
+ const impls = [
677
+ [mainWindow.history],
678
+ [perf],
679
+ [perf.navigation],
680
+ [perf.timing],
681
+ [screen],
682
+ [screen.orientation],
683
+ [mainWindow.visualViewport],
684
+ [intersectionObserver, 12],
685
+ [mutationObserver, 12],
686
+ [resizeObserver, 12],
687
+ [textNode],
688
+ [comment],
689
+ [frag],
690
+ [shadowRoot],
691
+ [elm],
692
+ [elm.attributes],
693
+ [elm.classList],
694
+ [elm.dataset],
695
+ [elm.style],
696
+ [docImpl],
697
+ [docImpl.doctype],
698
+ ];
699
+ const initialInterfaces = [
700
+ readImplementation("Window", mainWindow),
701
+ readImplementation("Node", textNode),
702
+ ];
703
+ const $config$ = JSON.stringify(config, (k, v) => {
704
+ if ("function" == typeof v) {
705
+ v = String(v);
706
+ v.startsWith(k + "(") && (v = "function " + v);
707
+ }
708
+ return v;
709
+ });
710
+ const initWebWorkerData = {
711
+ $config$: $config$,
712
+ $interfaces$: readImplementations(impls, initialInterfaces),
713
+ $libPath$: new URL(libPath, mainWindow.location) + "",
714
+ $origin$: origin,
715
+ $localStorage$: readStorage("localStorage"),
716
+ $sessionStorage$: readStorage("sessionStorage"),
520
717
  };
521
- const readStorage = storageName => {
522
- let items = [];
523
- let i = 0;
524
- let l = len(mainWindow[storageName]);
525
- let key;
526
- for (;i < l; i++) {
527
- key = mainWindow[storageName].key(i);
528
- items.push([ key, mainWindow[storageName].getItem(key) ]);
529
- }
530
- return items;
531
- };
532
- const getGlobalConstructor = (mainWindow, cstrName) => void 0 !== mainWindow[cstrName] ? new mainWindow[cstrName](noop) : 0;
533
- const addGlobalConstructorUsingPrototype = ($interfaces$, mainWindow, cstrName) => {
534
- void 0 !== mainWindow[cstrName] && $interfaces$.push([ cstrName, "Object", Object.keys(mainWindow[cstrName].prototype).map((propName => [ propName, 6 ])), 12 ]);
535
- };
536
- let worker;
537
- (receiveMessage => {
538
- const swContainer = window.navigator.serviceWorker;
539
- return swContainer.getRegistration().then((swRegistration => {
540
- swContainer.addEventListener("message", (ev => receiveMessage(ev.data, (accessRsp => swRegistration.active && swRegistration.active.postMessage(accessRsp)))));
541
- return (worker, msg) => {
542
- 0 === msg[0] ? worker.postMessage([ 1, readMainPlatform() ]) : 2 === msg[0] ? worker.postMessage([ 3, readMainInterfaces() ]) : onMessageFromWebWorker(worker, msg);
543
- };
544
- }));
545
- })(((accessReq, responseCallback) => mainAccessHandler(worker, accessReq).then(responseCallback))).then((onMessageHandler => {
546
- if (onMessageHandler) {
547
- worker = new Worker(libPath + "partytown-ww-sw.js?v=0.7.5", {
548
- name: "Partytown 🎉"
549
- });
550
- worker.onmessage = ev => {
551
- const msg = ev.data;
552
- 12 === msg[0] ? mainAccessHandler(worker, msg[1]) : onMessageHandler(worker, msg);
553
- };
554
- logMain("Created Partytown web worker (0.7.5)");
555
- worker.onerror = ev => console.error("Web Worker Error", ev);
556
- mainWindow.addEventListener("pt1", (ev => registerWindow(worker, getAndSetInstanceId(ev.detail.frameElement), ev.detail)));
718
+ addGlobalConstructorUsingPrototype(
719
+ initWebWorkerData.$interfaces$,
720
+ mainWindow,
721
+ "IntersectionObserverEntry"
722
+ );
723
+ return initWebWorkerData;
724
+ };
725
+ const readMainInterfaces = () => {
726
+ const elms = Object.getOwnPropertyNames(mainWindow)
727
+ .map((interfaceName) =>
728
+ ((doc, interfaceName, r, tag) => {
729
+ r = interfaceName.match(/^(HTML|SVG)(.+)Element$/);
730
+ if (r) {
731
+ tag = r[2];
732
+ return "S" == interfaceName[0]
733
+ ? doc.createElementNS(
734
+ "http://www.w3.org/2000/svg",
735
+ svgConstructorTags[tag] ||
736
+ tag.slice(0, 2).toLowerCase() + tag.slice(2)
737
+ )
738
+ : doc.createElement(htmlConstructorTags[tag] || tag);
739
+ }
740
+ })(docImpl, interfaceName)
741
+ )
742
+ .filter((elm) => elm)
743
+ .map((elm) => [elm]);
744
+ return readImplementations(elms, []);
745
+ };
746
+ const cstrs = new Set(["Object"]);
747
+ const readImplementations = (impls, interfaces) => {
748
+ const cstrImpls = impls
749
+ .filter((implData) => implData[0])
750
+ .map((implData) => {
751
+ const impl = implData[0];
752
+ const interfaceType = implData[1];
753
+ const cstrName = getConstructorName(impl);
754
+ const CstrPrototype = mainWindow[cstrName].prototype;
755
+ return [cstrName, CstrPrototype, impl, interfaceType];
756
+ });
757
+ cstrImpls.map(([cstrName, CstrPrototype, impl, intefaceType]) =>
758
+ readOwnImplementation(
759
+ cstrs,
760
+ interfaces,
761
+ cstrName,
762
+ CstrPrototype,
763
+ impl,
764
+ intefaceType
765
+ )
766
+ );
767
+ return interfaces;
768
+ };
769
+ const readImplementation = (cstrName, impl, memberName) => {
770
+ let interfaceMembers = [];
771
+ let interfaceInfo = [cstrName, "Object", interfaceMembers];
772
+ for (memberName in impl) {
773
+ readImplementationMember(interfaceMembers, impl, memberName);
774
+ }
775
+ return interfaceInfo;
776
+ };
777
+ const readOwnImplementation = (
778
+ cstrs,
779
+ interfaces,
780
+ cstrName,
781
+ CstrPrototype,
782
+ impl,
783
+ interfaceType
784
+ ) => {
785
+ if (!cstrs.has(cstrName)) {
786
+ cstrs.add(cstrName);
787
+ const SuperCstr = Object.getPrototypeOf(CstrPrototype);
788
+ const superCstrName = getConstructorName(SuperCstr);
789
+ const interfaceMembers = [];
790
+ const propDescriptors = Object.getOwnPropertyDescriptors(CstrPrototype);
791
+ readOwnImplementation(
792
+ cstrs,
793
+ interfaces,
794
+ superCstrName,
795
+ SuperCstr,
796
+ impl,
797
+ interfaceType
798
+ );
799
+ for (const memberName in propDescriptors) {
800
+ readImplementationMember(interfaceMembers, impl, memberName);
801
+ }
802
+ interfaces.push([
803
+ cstrName,
804
+ superCstrName,
805
+ interfaceMembers,
806
+ interfaceType,
807
+ getNodeName(impl),
808
+ ]);
809
+ }
810
+ };
811
+ const readImplementationMember = (
812
+ interfaceMembers,
813
+ implementation,
814
+ memberName,
815
+ value,
816
+ memberType,
817
+ cstrName
818
+ ) => {
819
+ try {
820
+ if (
821
+ isValidMemberName(memberName) &&
822
+ isNaN(memberName[0]) &&
823
+ "all" !== memberName
824
+ ) {
825
+ value = implementation[memberName];
826
+ memberType = typeof value;
827
+ if ("function" === memberType) {
828
+ (String(value).includes("[native") ||
829
+ Object.getPrototypeOf(implementation)[memberName]) &&
830
+ interfaceMembers.push([memberName, 5]);
831
+ } else if ("object" === memberType && null != value) {
832
+ cstrName = getConstructorName(value);
833
+ "Object" !== cstrName &&
834
+ self[cstrName] &&
835
+ interfaceMembers.push([memberName, value.nodeType || cstrName]);
836
+ } else {
837
+ "symbol" !== memberType &&
838
+ (memberName.toUpperCase() === memberName
839
+ ? interfaceMembers.push([memberName, 6, value])
840
+ : interfaceMembers.push([memberName, 6]));
557
841
  }
558
- }));
842
+ }
843
+ } catch (e) {
844
+ console.warn(e);
845
+ }
846
+ };
847
+ const readStorage = (storageName) => {
848
+ let items = [];
849
+ let i = 0;
850
+ let l = len(mainWindow[storageName]);
851
+ let key;
852
+ for (; i < l; i++) {
853
+ key = mainWindow[storageName].key(i);
854
+ items.push([key, mainWindow[storageName].getItem(key)]);
855
+ }
856
+ return items;
857
+ };
858
+ const getGlobalConstructor = (mainWindow, cstrName) =>
859
+ void 0 !== mainWindow[cstrName] ? new mainWindow[cstrName](noop) : 0;
860
+ const addGlobalConstructorUsingPrototype = (
861
+ $interfaces$,
862
+ mainWindow,
863
+ cstrName
864
+ ) => {
865
+ void 0 !== mainWindow[cstrName] &&
866
+ $interfaces$.push([
867
+ cstrName,
868
+ "Object",
869
+ Object.keys(mainWindow[cstrName].prototype).map((propName) => [
870
+ propName,
871
+ 6,
872
+ ]),
873
+ 12,
874
+ ]);
875
+ };
876
+ let worker;
877
+ ((receiveMessage) => {
878
+ const swContainer = window.navigator.serviceWorker;
879
+ return swContainer.getRegistration().then((swRegistration) => {
880
+ swContainer.addEventListener("message", (ev) =>
881
+ receiveMessage(
882
+ ev.data,
883
+ (accessRsp) =>
884
+ swRegistration.active &&
885
+ swRegistration.active.postMessage(accessRsp)
886
+ )
887
+ );
888
+ return (worker, msg) => {
889
+ 0 === msg[0]
890
+ ? worker.postMessage([1, readMainPlatform()])
891
+ : 2 === msg[0]
892
+ ? worker.postMessage([3, readMainInterfaces()])
893
+ : onMessageFromWebWorker(worker, msg);
894
+ };
895
+ });
896
+ })((accessReq, responseCallback) =>
897
+ mainAccessHandler(worker, accessReq).then(responseCallback)
898
+ ).then((onMessageHandler) => {
899
+ if (onMessageHandler) {
900
+ worker = new Worker(libPath + "partytown-ww-sw.js?v=0.7.5", {
901
+ name: "Partytown 🎉",
902
+ });
903
+ worker.onmessage = (ev) => {
904
+ const msg = ev.data;
905
+ 12 === msg[0]
906
+ ? mainAccessHandler(worker, msg[1])
907
+ : onMessageHandler(worker, msg);
908
+ };
909
+ logMain("Created Partytown web worker (0.7.5)");
910
+ worker.onerror = (ev) => console.error("Web Worker Error", ev);
911
+ mainWindow.addEventListener("pt1", (ev) =>
912
+ registerWindow(
913
+ worker,
914
+ getAndSetInstanceId(ev.detail.frameElement),
915
+ ev.detail
916
+ )
917
+ );
918
+ }
919
+ });
559
920
  })(window);