appscms-tools-theme 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/assets/js/partytown/debug/partytown-atomics.js +1 -1
- data/assets/js/partytown/debug/partytown-sandbox-sw.js +900 -539
- data/assets/js/partytown/debug/partytown.js +108 -69
- data/assets/js/partytown/partytown-atomics.js +599 -1
- data/assets/js/partytown/partytown-sw.js +49 -1
- metadata +2 -2
@@ -1,559 +1,920 @@
|
|
1
1
|
/* Partytown 0.7.5 - MIT builder.io */
|
2
|
-
(window => {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
30
|
-
|
52
|
+
configurable: true,
|
53
|
+
}))(Cstr, "name", {
|
54
|
+
value: value,
|
31
55
|
});
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
}
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
const
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
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
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
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
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
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
|
-
|
451
|
+
}
|
409
452
|
}
|
410
|
-
|
411
|
-
|
412
|
-
|
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
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
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
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
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
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
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
|
-
|
518
|
-
|
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
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
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);
|