@faststore/core 2.2.37 → 2.2.39

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.
Files changed (156) hide show
  1. package/.turbo/turbo-test.log +7 -7
  2. package/package.json +9 -9
  3. package/src/components/ui/ProductGallery/ProductGallery.tsx +38 -34
  4. package/.next/BUILD_ID +0 -1
  5. package/.next/build-manifest.json +0 -126
  6. package/.next/cache/.tsbuildinfo +0 -1
  7. package/.next/cache/config.json +0 -7
  8. package/.next/cache/eslint/.cache_1gneedd +0 -1
  9. package/.next/cache/next-server.js.nft.json +0 -1
  10. package/.next/cache/webpack/client-production/0.pack +0 -0
  11. package/.next/cache/webpack/client-production/index.pack +0 -0
  12. package/.next/cache/webpack/server-production/0.pack +0 -0
  13. package/.next/cache/webpack/server-production/index.pack +0 -0
  14. package/.next/export-marker.json +0 -1
  15. package/.next/images-manifest.json +0 -1
  16. package/.next/next-server.js.nft.json +0 -1
  17. package/.next/package.json +0 -1
  18. package/.next/prerender-manifest.json +0 -1
  19. package/.next/react-loadable-manifest.json +0 -47
  20. package/.next/required-server-files.json +0 -1
  21. package/.next/routes-manifest.json +0 -1
  22. package/.next/server/chunks/117.js +0 -430
  23. package/.next/server/chunks/177.js +0 -125
  24. package/.next/server/chunks/183.js +0 -121
  25. package/.next/server/chunks/184.js +0 -61
  26. package/.next/server/chunks/289.js +0 -240
  27. package/.next/server/chunks/312.js +0 -678
  28. package/.next/server/chunks/350.js +0 -200
  29. package/.next/server/chunks/386.js +0 -200
  30. package/.next/server/chunks/390.js +0 -550
  31. package/.next/server/chunks/398.js +0 -611
  32. package/.next/server/chunks/52.js +0 -4007
  33. package/.next/server/chunks/53.js +0 -61
  34. package/.next/server/chunks/574.js +0 -145
  35. package/.next/server/chunks/576.js +0 -121
  36. package/.next/server/chunks/585.js +0 -640
  37. package/.next/server/chunks/676.js +0 -32
  38. package/.next/server/chunks/693.js +0 -58
  39. package/.next/server/chunks/732.js +0 -1880
  40. package/.next/server/chunks/74.js +0 -4066
  41. package/.next/server/chunks/779.js +0 -58
  42. package/.next/server/chunks/817.js +0 -4007
  43. package/.next/server/chunks/825.js +0 -4074
  44. package/.next/server/chunks/854.js +0 -72
  45. package/.next/server/chunks/859.js +0 -959
  46. package/.next/server/chunks/863.js +0 -111
  47. package/.next/server/chunks/979.js +0 -1305
  48. package/.next/server/chunks/98.js +0 -163
  49. package/.next/server/chunks/988.js +0 -211
  50. package/.next/server/chunks/font-manifest.json +0 -1
  51. package/.next/server/font-manifest.json +0 -1
  52. package/.next/server/middleware-build-manifest.js +0 -1
  53. package/.next/server/middleware-manifest.json +0 -6
  54. package/.next/server/middleware-react-loadable-manifest.js +0 -1
  55. package/.next/server/pages/404.js +0 -391
  56. package/.next/server/pages/404.js.nft.json +0 -1
  57. package/.next/server/pages/500.js +0 -395
  58. package/.next/server/pages/500.js.nft.json +0 -1
  59. package/.next/server/pages/[...slug].js +0 -1084
  60. package/.next/server/pages/[...slug].js.nft.json +0 -1
  61. package/.next/server/pages/[slug]/p.js +0 -2271
  62. package/.next/server/pages/[slug]/p.js.nft.json +0 -1
  63. package/.next/server/pages/_app.js +0 -287
  64. package/.next/server/pages/_app.js.nft.json +0 -1
  65. package/.next/server/pages/_document.js +0 -363
  66. package/.next/server/pages/_document.js.nft.json +0 -1
  67. package/.next/server/pages/_error.js +0 -164
  68. package/.next/server/pages/_error.js.nft.json +0 -1
  69. package/.next/server/pages/account.js +0 -370
  70. package/.next/server/pages/account.js.nft.json +0 -1
  71. package/.next/server/pages/api/graphql.js +0 -464
  72. package/.next/server/pages/api/graphql.js.nft.json +0 -1
  73. package/.next/server/pages/api/health/live.js +0 -31
  74. package/.next/server/pages/api/health/live.js.nft.json +0 -1
  75. package/.next/server/pages/api/health/ready.js +0 -31
  76. package/.next/server/pages/api/health/ready.js.nft.json +0 -1
  77. package/.next/server/pages/api/preview.js +0 -137
  78. package/.next/server/pages/api/preview.js.nft.json +0 -1
  79. package/.next/server/pages/checkout.js +0 -370
  80. package/.next/server/pages/checkout.js.nft.json +0 -1
  81. package/.next/server/pages/en-US/404.html +0 -81
  82. package/.next/server/pages/en-US/404.json +0 -1
  83. package/.next/server/pages/en-US/500.html +0 -81
  84. package/.next/server/pages/en-US/500.json +0 -1
  85. package/.next/server/pages/en-US/account.html +0 -81
  86. package/.next/server/pages/en-US/account.json +0 -1
  87. package/.next/server/pages/en-US/checkout.html +0 -81
  88. package/.next/server/pages/en-US/checkout.json +0 -1
  89. package/.next/server/pages/en-US/login.html +0 -81
  90. package/.next/server/pages/en-US/login.json +0 -1
  91. package/.next/server/pages/en-US/s.html +0 -81
  92. package/.next/server/pages/en-US/s.json +0 -1
  93. package/.next/server/pages/en-US.html +0 -90
  94. package/.next/server/pages/en-US.json +0 -1
  95. package/.next/server/pages/index.js +0 -439
  96. package/.next/server/pages/index.js.nft.json +0 -1
  97. package/.next/server/pages/login.js +0 -382
  98. package/.next/server/pages/login.js.nft.json +0 -1
  99. package/.next/server/pages/s.js +0 -554
  100. package/.next/server/pages/s.js.nft.json +0 -1
  101. package/.next/server/pages-manifest.json +0 -18
  102. package/.next/server/webpack-api-runtime.js +0 -229
  103. package/.next/server/webpack-runtime.js +0 -229
  104. package/.next/static/chunks/251.1c79f06f2a2814b1.js +0 -1
  105. package/.next/static/chunks/386.d01e0db26c523f0f.js +0 -1
  106. package/.next/static/chunks/400-8a0173291a21a213.js +0 -1
  107. package/.next/static/chunks/469-7259b855711d4ad3.js +0 -1
  108. package/.next/static/chunks/574.70612be06fd1365f.js +0 -1
  109. package/.next/static/chunks/585.4c5d40fc6a72a611.js +0 -1
  110. package/.next/static/chunks/651.7142f31ce1e052b3.js +0 -1
  111. package/.next/static/chunks/741.52f7fb873418346f.js +0 -1
  112. package/.next/static/chunks/742-e32d18d91fe6f08b.js +0 -1
  113. package/.next/static/chunks/783-fbcb7a3216c40744.js +0 -1
  114. package/.next/static/chunks/800.ee4f8b9622001e8c.js +0 -1
  115. package/.next/static/chunks/98.40c7e17d9de4eb8f.js +0 -1
  116. package/.next/static/chunks/988.afda042dd9ba11d1.js +0 -1
  117. package/.next/static/chunks/framework-dfd14d7ce6600b03.js +0 -1
  118. package/.next/static/chunks/main-e4e873ee741162eb.js +0 -1
  119. package/.next/static/chunks/pages/404-6763ce07878a1456.js +0 -1
  120. package/.next/static/chunks/pages/500-0f4374f30595d27c.js +0 -1
  121. package/.next/static/chunks/pages/[...slug]-a81fd568b3032a9e.js +0 -1
  122. package/.next/static/chunks/pages/[slug]/p-46e7cb105136dc7a.js +0 -1
  123. package/.next/static/chunks/pages/_app-fea7ed14d8f4d0c6.js +0 -1
  124. package/.next/static/chunks/pages/_error-a7a0c1d9bfbb4f38.js +0 -1
  125. package/.next/static/chunks/pages/account-9eb6fab139286c66.js +0 -1
  126. package/.next/static/chunks/pages/checkout-7cd7b110c7cf2f10.js +0 -1
  127. package/.next/static/chunks/pages/index-4767c1028f4df135.js +0 -1
  128. package/.next/static/chunks/pages/login-5fd09e6402f47896.js +0 -1
  129. package/.next/static/chunks/pages/s-8e32a9b170819fa9.js +0 -1
  130. package/.next/static/chunks/polyfills-c67a75d1b6f99dc8.js +0 -1
  131. package/.next/static/chunks/webpack-4ccaf6613cbd7224.js +0 -1
  132. package/.next/static/css/29868543c76bc6fd.css +0 -1
  133. package/.next/static/css/527e334fa69cf40a.css +0 -1
  134. package/.next/static/css/5d1f64b61ea581f4.css +0 -1
  135. package/.next/static/css/6a7fdc5a21fbead5.css +0 -1
  136. package/.next/static/css/723835bce380750d.css +0 -1
  137. package/.next/static/css/a2eefb25a4608343.css +0 -1
  138. package/.next/static/css/cb7d1fcea42fab9c.css +0 -1
  139. package/.next/static/css/d7bbfbd552f407e9.css +0 -1
  140. package/.next/static/css/df588bb98c0b0ca6.css +0 -1
  141. package/.next/static/css/dfbdb0f27fd64782.css +0 -1
  142. package/.next/static/css/e84fc497732ea596.css +0 -1
  143. package/.next/static/pVGOsmYTXFPMzLlXhIM3h/_buildManifest.js +0 -1
  144. package/.next/static/pVGOsmYTXFPMzLlXhIM3h/_ssgManifest.js +0 -1
  145. package/.next/trace +0 -78
  146. package/public/~partytown/debug/partytown-atomics.js +0 -556
  147. package/public/~partytown/debug/partytown-media.js +0 -374
  148. package/public/~partytown/debug/partytown-sandbox-sw.js +0 -543
  149. package/public/~partytown/debug/partytown-sw.js +0 -59
  150. package/public/~partytown/debug/partytown-ww-atomics.js +0 -1789
  151. package/public/~partytown/debug/partytown-ww-sw.js +0 -1781
  152. package/public/~partytown/debug/partytown.js +0 -72
  153. package/public/~partytown/partytown-atomics.js +0 -2
  154. package/public/~partytown/partytown-media.js +0 -2
  155. package/public/~partytown/partytown-sw.js +0 -2
  156. package/public/~partytown/partytown.js +0 -2
@@ -1,1781 +0,0 @@
1
- /* Partytown 0.6.4 - MIT builder.io */
2
- (self => {
3
- const WinIdKey = Symbol();
4
- const InstanceIdKey = Symbol();
5
- const InstanceDataKey = Symbol();
6
- const NamespaceKey = Symbol();
7
- const ApplyPathKey = Symbol();
8
- const InstanceStateKey = Symbol();
9
- const HookContinue = Symbol();
10
- const HookPrevent = Symbol();
11
- const webWorkerInstances = new Map;
12
- const webWorkerRefsByRefId = {};
13
- const webWorkerRefIdsByRef = new WeakMap;
14
- const postMessages = [];
15
- const webWorkerCtx = {};
16
- const webWorkerlocalStorage = new Map;
17
- const webWorkerSessionStorage = new Map;
18
- const environments = {};
19
- const cachedDimensions = new Map;
20
- const cachedStructure = new Map;
21
- const commaSplit = str => str.split(",");
22
- const partytownLibUrl = url => {
23
- url = webWorkerCtx.$libPath$ + url;
24
- if (new URL(url).origin != location.origin) {
25
- throw "Invalid " + url;
26
- }
27
- return url;
28
- };
29
- const getterDimensionPropNames = commaSplit("clientWidth,clientHeight,clientTop,clientLeft,innerWidth,innerHeight,offsetWidth,offsetHeight,offsetTop,offsetLeft,outerWidth,outerHeight,pageXOffset,pageYOffset,scrollWidth,scrollHeight,scrollTop,scrollLeft");
30
- const elementStructurePropNames = commaSplit("childElementCount,children,firstElementChild,lastElementChild,nextElementSibling,previousElementSibling");
31
- const structureChangingMethodNames = commaSplit("insertBefore,remove,removeChild,replaceChild");
32
- const dimensionChangingSetterNames = commaSplit("className,width,height,hidden,innerHTML,innerText,textContent");
33
- const dimensionChangingMethodNames = commaSplit("setAttribute,setAttributeNS,setProperty");
34
- const eventTargetMethods = commaSplit("addEventListener,dispatchEvent,removeEventListener");
35
- const nonBlockingMethods = eventTargetMethods.concat(dimensionChangingMethodNames, commaSplit("add,observe,remove,unobserve"));
36
- const IS_TAG_REG = /^[A-Z_]([A-Z0-9-]*[A-Z0-9])?$/;
37
- const noop = () => {};
38
- const len = obj => obj.length;
39
- const getConstructorName = obj => {
40
- var _a, _b, _c;
41
- try {
42
- const constructorName = null === (_a = null == obj ? void 0 : obj.constructor) || void 0 === _a ? void 0 : _a.name;
43
- if (constructorName) {
44
- return constructorName;
45
- }
46
- } catch (e) {}
47
- try {
48
- 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;
49
- if (zoneJsConstructorName) {
50
- return zoneJsConstructorName;
51
- }
52
- } catch (e) {}
53
- return "";
54
- };
55
- const EMPTY_ARRAY = [];
56
- const randomId = () => Math.round(Math.random() * Number.MAX_SAFE_INTEGER).toString(36);
57
- const defineProperty = (obj, memberName, descriptor) => Object.defineProperty(obj, memberName, {
58
- ...descriptor,
59
- configurable: true
60
- });
61
- const defineConstructorName = (Cstr, value) => defineProperty(Cstr, "name", {
62
- value: value
63
- });
64
- const definePrototypeProperty = (Cstr, memberName, descriptor) => defineProperty(Cstr.prototype, memberName, descriptor);
65
- const definePrototypePropertyDescriptor = (Cstr, propertyDescriptorMap) => Object.defineProperties(Cstr.prototype, propertyDescriptorMap);
66
- const definePrototypeValue = (Cstr, memberName, value) => definePrototypeProperty(Cstr, memberName, {
67
- value: value,
68
- writable: true
69
- });
70
- const hasInstanceStateValue = (instance, stateKey) => stateKey in instance[InstanceStateKey];
71
- const getInstanceStateValue = (instance, stateKey) => instance[InstanceStateKey][stateKey];
72
- const setInstanceStateValue = (instance, stateKey, stateValue) => instance[InstanceStateKey][stateKey] = stateValue;
73
- const setWorkerRef = (ref, refId) => {
74
- if (!(refId = webWorkerRefIdsByRef.get(ref))) {
75
- webWorkerRefIdsByRef.set(ref, refId = randomId());
76
- webWorkerRefsByRefId[refId] = ref;
77
- }
78
- return refId;
79
- };
80
- const getOrCreateNodeInstance = (winId, instanceId, nodeName, namespace, instance) => {
81
- instance = webWorkerInstances.get(instanceId);
82
- if (!instance && nodeName && environments[winId]) {
83
- instance = environments[winId].$createNode$(nodeName, instanceId, namespace);
84
- webWorkerInstances.set(instanceId, instance);
85
- }
86
- return instance;
87
- };
88
- const definePrototypeNodeType = (Cstr, nodeType) => definePrototypeValue(Cstr, "nodeType", nodeType);
89
- const cachedTreeProps = (Cstr, treeProps) => treeProps.map((propName => definePrototypeProperty(Cstr, propName, {
90
- get() {
91
- let cacheKey = getInstanceCacheKey(this, propName);
92
- let result = cachedStructure.get(cacheKey);
93
- if (!result) {
94
- result = getter(this, [ propName ]);
95
- cachedStructure.set(cacheKey, result);
96
- }
97
- return result;
98
- }
99
- })));
100
- const getInstanceCacheKey = (instance, memberName, args) => [ instance[WinIdKey], instance[InstanceIdKey], memberName, ...(args || EMPTY_ARRAY).map((arg => String(arg && arg[WinIdKey] ? arg[InstanceIdKey] : arg))) ].join(".");
101
- const cachedProps = (Cstr, propNames) => commaSplit(propNames).map((propName => definePrototypeProperty(Cstr, propName, {
102
- get() {
103
- hasInstanceStateValue(this, propName) || setInstanceStateValue(this, propName, getter(this, [ propName ]));
104
- return getInstanceStateValue(this, propName);
105
- },
106
- set(val) {
107
- getInstanceStateValue(this, propName) !== val && setter(this, [ propName ], val);
108
- setInstanceStateValue(this, propName, val);
109
- }
110
- })));
111
- const cachedDimensionProps = Cstr => getterDimensionPropNames.map((propName => definePrototypeProperty(Cstr, propName, {
112
- get() {
113
- const dimension = cachedDimensions.get(getInstanceCacheKey(this, propName));
114
- if ("number" == typeof dimension) {
115
- return dimension;
116
- }
117
- const groupedDimensions = getter(this, [ propName ], getterDimensionPropNames);
118
- if (groupedDimensions && "object" == typeof groupedDimensions) {
119
- Object.entries(groupedDimensions).map((([dimensionPropName, value]) => cachedDimensions.set(getInstanceCacheKey(this, dimensionPropName), value)));
120
- return groupedDimensions[propName];
121
- }
122
- return groupedDimensions;
123
- }
124
- })));
125
- const cachedDimensionMethods = (Cstr, dimensionMethodNames) => dimensionMethodNames.map((methodName => {
126
- Cstr.prototype[methodName] = function(...args) {
127
- let cacheKey = getInstanceCacheKey(this, methodName, args);
128
- let dimensions = cachedDimensions.get(cacheKey);
129
- if (!dimensions) {
130
- dimensions = callMethod(this, [ methodName ], args);
131
- cachedDimensions.set(cacheKey, dimensions);
132
- }
133
- return dimensions;
134
- };
135
- }));
136
- const serializeForMain = ($winId$, $instanceId$, value, added, type) => void 0 !== value && (type = typeof value) ? "string" === type || "boolean" === type || "number" === type || null == value ? [ 0, value ] : "function" === type ? [ 4, {
137
- $winId$: $winId$,
138
- $instanceId$: $instanceId$,
139
- $refId$: setWorkerRef(value)
140
- } ] : (added = added || new Set) && Array.isArray(value) ? added.has(value) ? [ 1, [] ] : added.add(value) && [ 1, value.map((v => serializeForMain($winId$, $instanceId$, v, added))) ] : "object" === type ? value[InstanceIdKey] ? [ 3, [ value[WinIdKey], value[InstanceIdKey] ] ] : value instanceof Event ? [ 5, serializeObjectForMain($winId$, $instanceId$, value, false, added) ] : supportsTrustedHTML && value instanceof TrustedHTML ? [ 0, value.toString() ] : value instanceof ArrayBuffer ? [ 8, value ] : ArrayBuffer.isView(value) ? [ 9, value.buffer, getConstructorName(value) ] : [ 2, serializeObjectForMain($winId$, $instanceId$, value, true, added) ] : void 0 : value;
141
- const supportsTrustedHTML = "undefined" != typeof TrustedHTML;
142
- const serializeObjectForMain = (winId, instanceId, obj, includeFunctions, added, serializedObj, propName, propValue) => {
143
- serializedObj = {};
144
- if (!added.has(obj)) {
145
- added.add(obj);
146
- for (propName in obj) {
147
- propValue = obj[propName];
148
- (includeFunctions || "function" != typeof propValue) && (serializedObj[propName] = serializeForMain(winId, instanceId, propValue, added));
149
- }
150
- }
151
- return serializedObj;
152
- };
153
- const serializeInstanceForMain = (instance, value) => instance ? serializeForMain(instance[WinIdKey], instance[InstanceIdKey], value) : [ 0, value ];
154
- const deserializeFromMain = (winId, instanceId, applyPath, serializedValueTransfer, serializedType, serializedValue, obj, key) => {
155
- if (serializedValueTransfer) {
156
- serializedType = serializedValueTransfer[0];
157
- serializedValue = serializedValueTransfer[1];
158
- if (0 === serializedType || 11 === serializedType || 12 === serializedType) {
159
- return serializedValue;
160
- }
161
- if (4 === serializedType) {
162
- return deserializeRefFromMain(applyPath, serializedValue);
163
- }
164
- if (6 === serializedType) {
165
- return winId && applyPath.length > 0 ? (...args) => callMethod(environments[winId].$window$, applyPath, args, 1) : noop;
166
- }
167
- if (3 === serializedType) {
168
- return getOrCreateSerializedInstance(serializedValue);
169
- }
170
- if (7 === serializedType) {
171
- return new NodeList(serializedValue.map(getOrCreateSerializedInstance));
172
- }
173
- if (10 === serializedType) {
174
- return new Attr(serializedValue);
175
- }
176
- if (1 === serializedType) {
177
- return serializedValue.map((v => deserializeFromMain(winId, instanceId, applyPath, v)));
178
- }
179
- if (14 === serializedType) {
180
- return new CustomError(serializedValue);
181
- }
182
- obj = {};
183
- for (key in serializedValue) {
184
- obj[key] = deserializeFromMain(winId, instanceId, [ ...applyPath, key ], serializedValue[key]);
185
- }
186
- if (13 === serializedType) {
187
- return new environments[winId].$window$.CSSStyleDeclaration(winId, instanceId, applyPath, obj);
188
- }
189
- if (5 === serializedType) {
190
- if ("message" === obj.type && obj.origin) {
191
- let postMessageKey = JSON.stringify(obj.data);
192
- let postMessageData = postMessages.find((pm => pm.$data$ === postMessageKey));
193
- let env;
194
- if (postMessageData) {
195
- env = environments[postMessageData.$winId$];
196
- if (env) {
197
- obj.source = env.$window$;
198
- obj.origin = env.$location$.origin;
199
- }
200
- }
201
- }
202
- return new Proxy(new Event(obj.type, obj), {
203
- get: (target, propName) => propName in obj ? obj[propName] : "function" == typeof target[String(propName)] ? noop : target[String(propName)]
204
- });
205
- }
206
- if (2 === serializedType) {
207
- return obj;
208
- }
209
- }
210
- };
211
- const getOrCreateSerializedInstance = ([winId, instanceId, nodeName]) => instanceId === winId && environments[winId] ? environments[winId].$window$ : getOrCreateNodeInstance(winId, instanceId, nodeName);
212
- const deserializeRefFromMain = (applyPath, {$winId$: $winId$, $instanceId$: $instanceId$, $nodeName$: $nodeName$, $refId$: $refId$}) => {
213
- webWorkerRefsByRefId[$refId$] || webWorkerRefIdsByRef.set(webWorkerRefsByRefId[$refId$] = function(...args) {
214
- const instance = getOrCreateNodeInstance($winId$, $instanceId$, $nodeName$);
215
- return callMethod(instance, applyPath, args);
216
- }, $refId$);
217
- return webWorkerRefsByRefId[$refId$];
218
- };
219
- class CustomError extends Error {
220
- constructor(errorObject) {
221
- super(errorObject.message);
222
- this.name = errorObject.name;
223
- this.message = errorObject.message;
224
- this.stack = errorObject.stack;
225
- }
226
- }
227
- const NodeList = class {
228
- constructor(nodes) {
229
- (this._ = nodes).map(((node, index) => this[index] = node));
230
- }
231
- entries() {
232
- return this._.entries();
233
- }
234
- forEach(cb, thisArg) {
235
- this._.map(cb, thisArg);
236
- }
237
- item(index) {
238
- return this[index];
239
- }
240
- keys() {
241
- return this._.keys();
242
- }
243
- get length() {
244
- return len(this._);
245
- }
246
- values() {
247
- return this._.values();
248
- }
249
- [Symbol.iterator]() {
250
- return this._[Symbol.iterator]();
251
- }
252
- };
253
- const Attr = class {
254
- constructor(serializedAttr) {
255
- this.name = serializedAttr[0];
256
- this.value = serializedAttr[1];
257
- }
258
- get nodeName() {
259
- return this.name;
260
- }
261
- get nodeType() {
262
- return 2;
263
- }
264
- };
265
- const warnCrossOrgin = (apiType, apiName, env) => console.warn(`Partytown unable to ${apiType} cross-origin ${apiName}: ` + env.$location$);
266
- const logWorker = (msg, winId) => {
267
- try {
268
- const config = webWorkerCtx.$config$;
269
- if (config.logStackTraces) {
270
- const frames = (new Error).stack.split("\n");
271
- const i = frames.findIndex((f => f.includes("logWorker")));
272
- msg += "\n" + frames.slice(i + 1).join("\n");
273
- }
274
- let prefix;
275
- let color;
276
- if (winId) {
277
- prefix = `Worker (${normalizedWinId(winId)}) 🎉`;
278
- color = winColor(winId);
279
- } else {
280
- prefix = self.name;
281
- color = "#9844bf";
282
- }
283
- if (webWorkerCtx.lastLog !== msg) {
284
- webWorkerCtx.lastLog = msg;
285
- console.debug.apply(console, [ `%c${prefix}`, `background: ${color}; color: white; padding: 2px 3px; border-radius: 2px; font-size: 0.8em;`, msg ]);
286
- }
287
- } catch (e) {}
288
- };
289
- const winIds = [];
290
- const normalizedWinId = winId => {
291
- winIds.includes(winId) || winIds.push(winId);
292
- return winIds.indexOf(winId) + 1;
293
- };
294
- const winColor = winId => {
295
- const colors = [ "#00309e", "#ea3655", "#eea727" ];
296
- const index = normalizedWinId(winId) - 1;
297
- return colors[index] || colors[colors.length - 1];
298
- };
299
- const getTargetProp = (target, applyPath) => {
300
- let n = "";
301
- if (target) {
302
- target[InstanceIdKey];
303
- const cstrName = getConstructorName(target);
304
- if ("Window" === cstrName) {
305
- n = "";
306
- } else if ("string" == typeof target[InstanceDataKey]) {
307
- let nodeName = target[InstanceDataKey];
308
- n = "#text" === nodeName ? "textNode." : "#comment" === nodeName ? "commentNode." : "#document" === nodeName ? "document." : "html" === nodeName ? "doctype." : nodeName.toLowerCase() + ".";
309
- } else {
310
- n = "nodeType" in target && 2 === target.nodeType ? "attributes." : "CanvasRenderingContext2D" === cstrName ? "context2D." : "CanvasRenderingContextWebGL" === cstrName ? "contextWebGL." : "CSSStyleDeclaration" === cstrName ? "style." : "MutationObserver" === cstrName ? "mutationObserver." : "NamedNodeMap" === cstrName ? "namedNodeMap." : "ResizeObserver" === cstrName ? "resizeObserver." : cstrName.substring(0, 1).toLowerCase() + cstrName.substring(1) + ".";
311
- }
312
- target[ApplyPathKey] && target[ApplyPathKey].length && (n += [ ...target[ApplyPathKey] ].join(".") + ".");
313
- }
314
- if (applyPath.length > 1) {
315
- const first = applyPath.slice(0, applyPath.length - 1);
316
- const last = applyPath[applyPath.length - 1];
317
- if (!isNaN(last)) {
318
- return n + `${first.join(".")}[${last}]`;
319
- }
320
- }
321
- return n + applyPath.join(".");
322
- };
323
- const getLogValue = (applyPath, v) => {
324
- const type = typeof v;
325
- if (void 0 === v) {
326
- return "undefined";
327
- }
328
- if ("boolean" === type || "number" === type || null == v) {
329
- return JSON.stringify(v);
330
- }
331
- if ("string" === type) {
332
- return applyPath.includes("cookie") ? JSON.stringify(v.slice(0, 10) + "...") : JSON.stringify(v.length > 50 ? v.slice(0, 40) + "..." : v);
333
- }
334
- if (Array.isArray(v)) {
335
- return `[${v.map(getLogValue).join(", ")}]`;
336
- }
337
- if ("object" === type) {
338
- const instanceId = v[InstanceIdKey];
339
- const cstrName = getConstructorName(v);
340
- if ("string" == typeof instanceId) {
341
- if ("Window" === cstrName) {
342
- return "window";
343
- }
344
- if ("string" == typeof v[InstanceDataKey]) {
345
- if (1 === v.nodeType) {
346
- return `<${v[InstanceDataKey].toLowerCase()}>`;
347
- }
348
- if (10 === v.nodeType) {
349
- return `<!DOCTYPE ${v[InstanceDataKey]}>`;
350
- }
351
- if (v.nodeType <= 11) {
352
- return v[InstanceDataKey];
353
- }
354
- }
355
- return "¯\\_(ツ)_/¯ instance obj";
356
- }
357
- return v[Symbol.iterator] ? `[${Array.from(v).map((i => getLogValue(applyPath, i))).join(", ")}]` : "value" in v ? "string" == typeof v.value ? `"${v.value}"` : objToString(v.value) : objToString(v);
358
- }
359
- return (v => "object" == typeof v && v && v.then)(v) ? "Promise" : "function" === type ? `ƒ() ${v.name || ""}`.trim() : `¯\\_(ツ)_/¯ ${String(v)}`.trim();
360
- };
361
- const objToString = obj => {
362
- const s = [];
363
- for (let key in obj) {
364
- const value = obj[key];
365
- const type = typeof value;
366
- "string" === type ? s.push(`${key}: "${value}"`) : "function" === type ? s.push(`${key}: ƒ`) : Array.isArray(type) ? s.push(`${key}: [..]`) : "object" === type && value ? s.push(`${key}: {..}`) : s.push(`${key}: ${String(value)}`);
367
- }
368
- let str = s.join(", ");
369
- str.length > 200 && (str = str.substring(0, 200) + "..");
370
- return `{ ${str} }`;
371
- };
372
- const logDimensionCacheClearStyle = (target, propName) => {
373
- (webWorkerCtx.$config$.logGetters || webWorkerCtx.$config$.logSetters) && logWorker(`Dimension cache cleared from style.${propName} setter`, target[WinIdKey]);
374
- };
375
- const logDimensionCacheClearMethod = (target, methodName) => {
376
- (webWorkerCtx.$config$.logGetters || webWorkerCtx.$config$.logCalls) && logWorker(`Dimension cache cleared from method call ${methodName}()`, target[WinIdKey]);
377
- };
378
- const taskQueue = [];
379
- const queue = (instance, $applyPath$, callType, $assignInstanceId$, $groupedGetters$, buffer) => {
380
- if (instance[ApplyPathKey]) {
381
- taskQueue.push({
382
- $winId$: instance[WinIdKey],
383
- $instanceId$: instance[InstanceIdKey],
384
- $applyPath$: [ ...instance[ApplyPathKey], ...$applyPath$ ],
385
- $assignInstanceId$: $assignInstanceId$,
386
- $groupedGetters$: $groupedGetters$
387
- });
388
- taskQueue[len(taskQueue) - 1].$debug$ = ((target, applyPath, callType) => {
389
- let m = getTargetProp(target, applyPath);
390
- 1 === callType ? m += " (blocking)" : 2 === callType ? m += " (non-blocking)" : 3 === callType && (m += " (non-blocking, no-side-effect)");
391
- return m.trim();
392
- })(instance, $applyPath$, callType);
393
- buffer && 3 !== callType && console.error("buffer must be sent NonBlockingNoSideEffect");
394
- if (3 === callType) {
395
- webWorkerCtx.$postMessage$([ 12, {
396
- $msgId$: randomId(),
397
- $tasks$: [ ...taskQueue ]
398
- } ], buffer ? [ buffer instanceof ArrayBuffer ? buffer : buffer.buffer ] : void 0);
399
- taskQueue.length = 0;
400
- } else if (1 === callType) {
401
- return sendToMain(true);
402
- }
403
- webWorkerCtx.$asyncMsgTimer$ = setTimeout(sendToMain, 20);
404
- }
405
- };
406
- const sendToMain = isBlocking => {
407
- clearTimeout(webWorkerCtx.$asyncMsgTimer$);
408
- if (len(taskQueue)) {
409
- webWorkerCtx.$config$.logMainAccess && logWorker(`Main access, tasks sent: ${taskQueue.length}`);
410
- const endTask = taskQueue[len(taskQueue) - 1];
411
- const accessReq = {
412
- $msgId$: randomId(),
413
- $tasks$: [ ...taskQueue ]
414
- };
415
- taskQueue.length = 0;
416
- if (isBlocking) {
417
- const accessRsp = ((webWorkerCtx, accessReq) => {
418
- const xhr = new XMLHttpRequest;
419
- xhr.open("POST", partytownLibUrl("proxytown"), false);
420
- xhr.send(JSON.stringify(accessReq));
421
- return JSON.parse(xhr.responseText);
422
- })(0, accessReq);
423
- const isPromise = accessRsp.$isPromise$;
424
- const rtnValue = deserializeFromMain(endTask.$winId$, endTask.$instanceId$, endTask.$applyPath$, accessRsp.$rtnValue$);
425
- if (accessRsp.$error$) {
426
- if (isPromise) {
427
- return Promise.reject(accessRsp.$error$);
428
- }
429
- throw new Error(accessRsp.$error$);
430
- }
431
- return isPromise ? Promise.resolve(rtnValue) : rtnValue;
432
- }
433
- webWorkerCtx.$postMessage$([ 12, accessReq ]);
434
- }
435
- };
436
- const getter = (instance, applyPath, groupedGetters, rtnValue) => {
437
- if (webWorkerCtx.$config$.get) {
438
- rtnValue = webWorkerCtx.$config$.get(createHookOptions(instance, applyPath));
439
- if (rtnValue !== HookContinue) {
440
- return rtnValue;
441
- }
442
- }
443
- rtnValue = queue(instance, applyPath, 1, void 0, groupedGetters);
444
- ((target, applyPath, rtnValue, restrictedToWorker = false, groupedGetters = false) => {
445
- if (webWorkerCtx.$config$.logGetters) {
446
- try {
447
- const msg = `Get ${getTargetProp(target, applyPath)}, returned: ${getLogValue(applyPath, rtnValue)}${restrictedToWorker ? " (restricted to worker)" : ""}${groupedGetters ? " (grouped getter)" : ""}`;
448
- msg.includes("Symbol(") || logWorker(msg, target[WinIdKey]);
449
- } catch (e) {}
450
- }
451
- })(instance, applyPath, rtnValue, false, !!groupedGetters);
452
- return rtnValue;
453
- };
454
- const setter = (instance, applyPath, value, hookSetterValue) => {
455
- if (webWorkerCtx.$config$.set) {
456
- hookSetterValue = webWorkerCtx.$config$.set({
457
- value: value,
458
- prevent: HookPrevent,
459
- ...createHookOptions(instance, applyPath)
460
- });
461
- if (hookSetterValue === HookPrevent) {
462
- return;
463
- }
464
- hookSetterValue !== HookContinue && (value = hookSetterValue);
465
- }
466
- if (dimensionChangingSetterNames.some((s => applyPath.includes(s)))) {
467
- cachedDimensions.clear();
468
- ((target, propName) => {
469
- (webWorkerCtx.$config$.logGetters || webWorkerCtx.$config$.logSetters) && logWorker(`Dimension cache cleared from setter "${propName}"`, target[WinIdKey]);
470
- })(instance, applyPath[applyPath.length - 1]);
471
- }
472
- applyPath = [ ...applyPath, serializeInstanceForMain(instance, value), 0 ];
473
- ((target, applyPath, value, restrictedToWorker = false) => {
474
- if (webWorkerCtx.$config$.logSetters) {
475
- try {
476
- applyPath = applyPath.slice(0, applyPath.length - 2);
477
- logWorker(`Set ${getTargetProp(target, applyPath)}, value: ${getLogValue(applyPath, value)}${restrictedToWorker ? " (restricted to worker)" : ""}`, target[WinIdKey]);
478
- } catch (e) {}
479
- }
480
- })(instance, applyPath, value);
481
- queue(instance, applyPath, 2);
482
- };
483
- const callMethod = (instance, applyPath, args, callType, assignInstanceId, buffer, rtnValue, methodName) => {
484
- if (webWorkerCtx.$config$.apply) {
485
- rtnValue = webWorkerCtx.$config$.apply({
486
- args: args,
487
- ...createHookOptions(instance, applyPath)
488
- });
489
- if (rtnValue !== HookContinue) {
490
- return rtnValue;
491
- }
492
- }
493
- methodName = applyPath[len(applyPath) - 1];
494
- applyPath = [ ...applyPath, serializeInstanceForMain(instance, args) ];
495
- callType = callType || (nonBlockingMethods.includes(methodName) ? 2 : 1);
496
- if ("setAttribute" === methodName && hasInstanceStateValue(instance, args[0])) {
497
- setInstanceStateValue(instance, args[0], args[1]);
498
- } else if (structureChangingMethodNames.includes(methodName)) {
499
- cachedDimensions.clear();
500
- cachedStructure.clear();
501
- ((target, methodName) => {
502
- (webWorkerCtx.$config$.logGetters || webWorkerCtx.$config$.logCalls) && logWorker(`Dimension and DOM structure cache cleared from method call ${methodName}()`, target[WinIdKey]);
503
- })(instance, methodName);
504
- } else if (dimensionChangingMethodNames.includes(methodName)) {
505
- callType = 2;
506
- cachedDimensions.clear();
507
- logDimensionCacheClearMethod(instance, methodName);
508
- }
509
- rtnValue = queue(instance, applyPath, callType, assignInstanceId, void 0, buffer);
510
- ((target, applyPath, args, rtnValue) => {
511
- if (webWorkerCtx.$config$.logCalls) {
512
- try {
513
- applyPath = applyPath.slice(0, applyPath.length - 1);
514
- logWorker(`Call ${getTargetProp(target, applyPath)}(${args.map((v => getLogValue(applyPath, v))).join(", ")}), returned: ${getLogValue(applyPath, rtnValue)}`, target[WinIdKey]);
515
- } catch (e) {}
516
- }
517
- })(instance, applyPath, args, rtnValue);
518
- return rtnValue;
519
- };
520
- const constructGlobal = (instance, cstrName, args) => {
521
- ((target, cstrName, args) => {
522
- if (webWorkerCtx.$config$.logCalls) {
523
- try {
524
- logWorker(`Construct new ${cstrName}(${args.map((v => getLogValue([], v))).join(", ")})`, target[WinIdKey]);
525
- } catch (e) {}
526
- }
527
- })(instance, cstrName, args);
528
- queue(instance, [ 1, cstrName, serializeInstanceForMain(instance, args) ], 1);
529
- };
530
- const createHookOptions = (instance, applyPath) => ({
531
- name: applyPath.join("."),
532
- continue: HookContinue,
533
- nodeName: instance[InstanceDataKey],
534
- constructor: getConstructorName(instance)
535
- });
536
- const addStorageApi = (win, storageName, storages, isSameOrigin, env) => {
537
- let getItems = items => {
538
- items = storages.get(win.origin);
539
- items || storages.set(win.origin, items = []);
540
- return items;
541
- };
542
- let getIndexByKey = key => getItems().findIndex((i => i[STORAGE_KEY] === key));
543
- let index;
544
- let item;
545
- let storage = {
546
- getItem(key) {
547
- index = getIndexByKey(key);
548
- return index > -1 ? getItems()[index][STORAGE_VALUE] : null;
549
- },
550
- setItem(key, value) {
551
- index = getIndexByKey(key);
552
- index > -1 ? getItems()[index][STORAGE_VALUE] = value : getItems().push([ key, value ]);
553
- isSameOrigin ? callMethod(win, [ storageName, "setItem" ], [ key, value ], 2) : warnCrossOrgin("set", storageName, env);
554
- },
555
- removeItem(key) {
556
- index = getIndexByKey(key);
557
- index > -1 && getItems().splice(index, 1);
558
- isSameOrigin ? callMethod(win, [ storageName, "removeItem" ], [ key ], 2) : warnCrossOrgin("remove", storageName, env);
559
- },
560
- key(index) {
561
- item = getItems()[index];
562
- return item ? item[STORAGE_KEY] : null;
563
- },
564
- clear() {
565
- getItems().length = 0;
566
- isSameOrigin ? callMethod(win, [ storageName, "clear" ], EMPTY_ARRAY, 2) : warnCrossOrgin("clear", storageName, env);
567
- },
568
- get length() {
569
- return getItems().length;
570
- }
571
- };
572
- win[storageName] = storage;
573
- };
574
- const STORAGE_KEY = 0;
575
- const STORAGE_VALUE = 1;
576
- const createCSSStyleDeclarationCstr = (win, WorkerBase, cstrName) => {
577
- win[cstrName] = defineConstructorName(class extends WorkerBase {
578
- constructor(winId, instanceId, applyPath, styles) {
579
- super(winId, instanceId, applyPath, styles || {});
580
- return new Proxy(this, {
581
- get(target, propName) {
582
- if (target[propName]) {
583
- return target[propName];
584
- }
585
- target[propName] || "string" != typeof propName || target[InstanceDataKey][propName] || (target[InstanceDataKey][propName] = getter(target, [ propName ]));
586
- return target[InstanceDataKey][propName];
587
- },
588
- set(target, propName, propValue) {
589
- target[InstanceDataKey][propName] = propValue;
590
- setter(target, [ propName ], propValue);
591
- logDimensionCacheClearStyle(target, propName);
592
- cachedDimensions.clear();
593
- return true;
594
- }
595
- });
596
- }
597
- setProperty(...args) {
598
- this[InstanceDataKey][args[0]] = args[1];
599
- callMethod(this, [ "setProperty" ], args, 2);
600
- logDimensionCacheClearStyle(this, args[0]);
601
- cachedDimensions.clear();
602
- }
603
- getPropertyValue(propName) {
604
- return this[propName];
605
- }
606
- removeProperty(propName) {
607
- let value = this[InstanceDataKey][propName];
608
- callMethod(this, [ "removeProperty" ], [ propName ], 2);
609
- logDimensionCacheClearStyle(this, propName);
610
- cachedDimensions.clear();
611
- this[InstanceDataKey][propName] = void 0;
612
- return value;
613
- }
614
- }, cstrName);
615
- };
616
- const createCSSStyleSheetConstructor = (win, cssStyleSheetCstrName) => {
617
- win[cssStyleSheetCstrName] = defineConstructorName(class {
618
- constructor(ownerNode) {
619
- this.ownerNode = ownerNode;
620
- }
621
- get cssRules() {
622
- const ownerNode = this.ownerNode;
623
- return new Proxy({}, {
624
- get(target, propKey) {
625
- const propName = String(propKey);
626
- return "item" === propName ? index => getCssRule(ownerNode, index) : "length" === propName ? getCssRules(ownerNode).length : isNaN(propName) ? target[propKey] : getCssRule(ownerNode, propName);
627
- }
628
- });
629
- }
630
- insertRule(ruleText, index) {
631
- const cssRules = getCssRules(this.ownerNode);
632
- index = void 0 === index ? 0 : index;
633
- if (index >= 0 && index <= cssRules.length) {
634
- callMethod(this.ownerNode, [ "sheet", "insertRule" ], [ ruleText, index ], 2);
635
- cssRules.splice(index, 0, 0);
636
- }
637
- logDimensionCacheClearMethod(this.ownerNode, "insertRule");
638
- cachedDimensions.clear();
639
- return index;
640
- }
641
- deleteRule(index) {
642
- callMethod(this.ownerNode, [ "sheet", "deleteRule" ], [ index ], 2);
643
- getCssRules(this.ownerNode).splice(index, 1);
644
- logDimensionCacheClearMethod(this.ownerNode, "deleteRule");
645
- cachedDimensions.clear();
646
- }
647
- get type() {
648
- return "text/css";
649
- }
650
- }, cssStyleSheetCstrName);
651
- const HTMLStyleDescriptorMap = {
652
- sheet: {
653
- get() {
654
- return new win[cssStyleSheetCstrName](this);
655
- }
656
- }
657
- };
658
- definePrototypePropertyDescriptor(win.HTMLStyleElement, HTMLStyleDescriptorMap);
659
- };
660
- const getCssRules = (ownerNode, cssRules) => {
661
- cssRules = getInstanceStateValue(ownerNode, 2);
662
- if (!cssRules) {
663
- cssRules = getter(ownerNode, [ "sheet", "cssRules" ]);
664
- setInstanceStateValue(ownerNode, 2, cssRules);
665
- }
666
- return cssRules;
667
- };
668
- const getCssRule = (ownerNode, index, cssRules) => {
669
- cssRules = getCssRules(ownerNode);
670
- 0 === cssRules[index] && (cssRules[index] = getter(ownerNode, [ "sheet", "cssRules", parseInt(index, 10) ]));
671
- return cssRules[index];
672
- };
673
- const runScriptContent = (env, instanceId, scriptContent, winId, errorMsg) => {
674
- try {
675
- webWorkerCtx.$config$.logScriptExecution && logWorker(`Execute script: ${scriptContent.substring(0, 100).split("\n").map((l => l.trim())).join(" ").trim().substring(0, 60)}...`, winId);
676
- env.$currentScriptId$ = instanceId;
677
- run(env, scriptContent);
678
- } catch (contentError) {
679
- console.error(scriptContent, contentError);
680
- errorMsg = String(contentError.stack || contentError);
681
- }
682
- env.$currentScriptId$ = "";
683
- return errorMsg;
684
- };
685
- const run = (env, scriptContent, scriptUrl) => {
686
- env.$runWindowLoadEvent$ = 1;
687
- scriptContent = `with(this){${(webWorkerCtx.$config$.globalFns || []).filter((globalFnName => /[a-zA-Z_$][0-9a-zA-Z_$]*/.test(globalFnName))).map((g => `(typeof ${g}=='function'&&(window.${g}=${g}))`)).join(";") + scriptContent.replace(/\bthis\b/g, "(thi$(this)?window:this)").replace(/\/\/# so/g, "//Xso")}\n;function thi$(t){return t===this}}` + (scriptUrl ? "\n//# sourceURL=" + scriptUrl : "");
688
- env.$isSameOrigin$ || (scriptContent = scriptContent.replace(/.postMessage\(/g, `.postMessage('${env.$winId$}',`));
689
- new Function(scriptContent).call(env.$window$);
690
- env.$runWindowLoadEvent$ = 0;
691
- };
692
- const runStateLoadHandlers = (instance, type, handlers) => {
693
- handlers = getInstanceStateValue(instance, type);
694
- handlers && setTimeout((() => handlers.map((cb => cb({
695
- type: type
696
- })))));
697
- };
698
- const resolveToUrl = (env, url, type, baseLocation, resolvedUrl, configResolvedUrl) => {
699
- baseLocation = env.$location$;
700
- while (!baseLocation.host) {
701
- env = environments[env.$parentWinId$];
702
- baseLocation = env.$location$;
703
- if (env.$winId$ === env.$parentWinId$) {
704
- break;
705
- }
706
- }
707
- resolvedUrl = new URL(url || "", baseLocation);
708
- if (type && webWorkerCtx.$config$.resolveUrl) {
709
- configResolvedUrl = webWorkerCtx.$config$.resolveUrl(resolvedUrl, baseLocation, type);
710
- if (configResolvedUrl) {
711
- return configResolvedUrl;
712
- }
713
- }
714
- return resolvedUrl;
715
- };
716
- const resolveUrl = (env, url, type) => resolveToUrl(env, url, type) + "";
717
- const getPartytownScript = () => `<script src="${partytownLibUrl("partytown.js?v=0.6.4")}"><\/script>`;
718
- const createImageConstructor = env => class HTMLImageElement {
719
- constructor() {
720
- this.s = "";
721
- this.l = [];
722
- this.e = [];
723
- }
724
- get src() {
725
- return this.s;
726
- }
727
- set src(src) {
728
- webWorkerCtx.$config$.logImageRequests && logWorker(`Image() request: ${resolveUrl(env, src, null)}`, env.$winId$);
729
- this.s = src;
730
- fetch(resolveUrl(env, src, null), {
731
- mode: "no-cors",
732
- credentials: "include",
733
- keepalive: true
734
- }).then((rsp => {
735
- rsp.ok || 0 === rsp.status ? this.l.map((cb => cb({
736
- type: "load"
737
- }))) : this.e.map((cb => cb({
738
- type: "error"
739
- })));
740
- }), (() => this.e.forEach((cb => cb({
741
- type: "error"
742
- })))));
743
- }
744
- addEventListener(eventName, cb) {
745
- "load" === eventName && this.l.push(cb);
746
- "error" === eventName && this.e.push(cb);
747
- }
748
- get onload() {
749
- return this.l[0];
750
- }
751
- set onload(cb) {
752
- this.l = [ cb ];
753
- }
754
- get onerror() {
755
- return this.e[0];
756
- }
757
- set onerror(cb) {
758
- this.e = [ cb ];
759
- }
760
- };
761
- const HTMLSrcElementDescriptorMap = {
762
- addEventListener: {
763
- value(...args) {
764
- const eventName = args[0];
765
- const callbacks = getInstanceStateValue(this, eventName) || [];
766
- callbacks.push(args[1]);
767
- setInstanceStateValue(this, eventName, callbacks);
768
- }
769
- },
770
- async: {
771
- get: noop,
772
- set: noop
773
- },
774
- defer: {
775
- get: noop,
776
- set: noop
777
- },
778
- onload: {
779
- get() {
780
- let callbacks = getInstanceStateValue(this, "load");
781
- return callbacks && callbacks[0] || null;
782
- },
783
- set(cb) {
784
- setInstanceStateValue(this, "load", cb ? [ cb ] : null);
785
- }
786
- },
787
- onerror: {
788
- get() {
789
- let callbacks = getInstanceStateValue(this, "error");
790
- return callbacks && callbacks[0] || null;
791
- },
792
- set(cb) {
793
- setInstanceStateValue(this, "error", cb ? [ cb ] : null);
794
- }
795
- },
796
- getAttribute: {
797
- value(attrName) {
798
- return "src" === attrName ? this.src : callMethod(this, [ "getAttribute" ], [ attrName ]);
799
- }
800
- },
801
- setAttribute: {
802
- value(attrName, attrValue) {
803
- scriptAttrPropNames.includes(attrName) ? this[attrName] = attrValue : callMethod(this, [ "setAttribute" ], [ attrName, attrValue ]);
804
- }
805
- }
806
- };
807
- const scriptAttrPropNames = commaSplit("src,type");
808
- const patchHTMLScriptElement = (WorkerHTMLScriptElement, env) => {
809
- const HTMLScriptDescriptorMap = {
810
- innerHTML: innerHTMLDescriptor,
811
- innerText: innerHTMLDescriptor,
812
- src: {
813
- get() {
814
- return getInstanceStateValue(this, 4) || "";
815
- },
816
- set(url) {
817
- const orgUrl = resolveUrl(env, url, null);
818
- const config = webWorkerCtx.$config$;
819
- url = resolveUrl(env, url, "script");
820
- setInstanceStateValue(this, 4, url);
821
- setter(this, [ "src" ], url);
822
- orgUrl !== url && setter(this, [ "dataset", "ptsrc" ], orgUrl);
823
- if (this.type && config.loadScriptsOnMainThread) {
824
- const shouldExecuteScriptViaMainThread = config.loadScriptsOnMainThread.some((scriptUrl => scriptUrl === url));
825
- shouldExecuteScriptViaMainThread && setter(this, [ "type" ], "text/javascript");
826
- }
827
- }
828
- },
829
- textContent: innerHTMLDescriptor,
830
- type: {
831
- get() {
832
- return getter(this, [ "type" ]);
833
- },
834
- set(type) {
835
- if (!isScriptJsType(type)) {
836
- setInstanceStateValue(this, 5, type);
837
- setter(this, [ "type" ], type);
838
- }
839
- }
840
- },
841
- ...HTMLSrcElementDescriptorMap
842
- };
843
- definePrototypePropertyDescriptor(WorkerHTMLScriptElement, HTMLScriptDescriptorMap);
844
- };
845
- const innerHTMLDescriptor = {
846
- get() {
847
- return getInstanceStateValue(this, 3) || "";
848
- },
849
- set(scriptContent) {
850
- setInstanceStateValue(this, 3, scriptContent);
851
- }
852
- };
853
- const isScriptJsType = scriptType => !scriptType || "text/javascript" === scriptType;
854
- const createNodeCstr = (win, env, WorkerBase) => {
855
- const WorkerNode = defineConstructorName(class extends WorkerBase {
856
- appendChild(node) {
857
- return this.insertBefore(node, null);
858
- }
859
- get href() {}
860
- set href(_) {}
861
- insertBefore(newNode, referenceNode) {
862
- const winId = newNode[WinIdKey] = this[WinIdKey];
863
- const instanceId = newNode[InstanceIdKey];
864
- const nodeName = newNode[InstanceDataKey];
865
- const isScript = "SCRIPT" === nodeName;
866
- const isIFrame = "IFRAME" === nodeName;
867
- if (isScript) {
868
- const scriptContent = getInstanceStateValue(newNode, 3);
869
- const scriptType = getInstanceStateValue(newNode, 5);
870
- if (scriptContent) {
871
- if (isScriptJsType(scriptType)) {
872
- const errorMsg = runScriptContent(env, instanceId, scriptContent, winId, "");
873
- const datasetType = errorMsg ? "pterror" : "ptid";
874
- const datasetValue = errorMsg || instanceId;
875
- setter(newNode, [ "type" ], "text/partytown-x");
876
- setter(newNode, [ "dataset", datasetType ], datasetValue);
877
- }
878
- setter(newNode, [ "innerHTML" ], scriptContent);
879
- }
880
- }
881
- callMethod(this, [ "insertBefore" ], [ newNode, referenceNode ], 2);
882
- if (isIFrame) {
883
- const src = getInstanceStateValue(newNode, 0);
884
- if (src && src.startsWith("javascript:")) {
885
- const scriptContent = src.split("javascript:")[1];
886
- runScriptContent(env, instanceId, scriptContent, winId, "");
887
- }
888
- ((winId, iframe) => {
889
- let i = 0;
890
- let type;
891
- let handlers;
892
- let callback = () => {
893
- if (environments[winId] && environments[winId].$isInitialized$ && !environments[winId].$isLoading$) {
894
- type = getInstanceStateValue(iframe, 1) ? "error" : "load";
895
- handlers = getInstanceStateValue(iframe, type);
896
- handlers && handlers.map((handler => handler({
897
- type: type
898
- })));
899
- } else if (i++ > 2e3) {
900
- handlers = getInstanceStateValue(iframe, "error");
901
- handlers && handlers.map((handler => handler({
902
- type: "error"
903
- })));
904
- } else {
905
- setTimeout(callback, 9);
906
- }
907
- };
908
- callback();
909
- })(instanceId, newNode);
910
- }
911
- if (isScript) {
912
- sendToMain(true);
913
- webWorkerCtx.$postMessage$([ 7, winId ]);
914
- }
915
- return newNode;
916
- }
917
- get nodeName() {
918
- return "#s" === this[InstanceDataKey] ? "#document-fragment" : this[InstanceDataKey];
919
- }
920
- get nodeType() {
921
- return 3;
922
- }
923
- get ownerDocument() {
924
- return env.$document$;
925
- }
926
- }, "Node");
927
- cachedTreeProps(WorkerNode, commaSplit("childNodes,firstChild,isConnected,lastChild,nextSibling,parentElement,parentNode,previousSibling"));
928
- win.Node = WorkerNode;
929
- };
930
- const htmlMedia = commaSplit("AUDIO,CANVAS,VIDEO");
931
- const windowMediaConstructors = commaSplit("Audio,MediaSource");
932
- const patchDocument = (WorkerDocument, env, isDocumentImplementation) => {
933
- const DocumentDescriptorMap = {
934
- body: {
935
- get: () => env.$body$
936
- },
937
- cookie: {
938
- get() {
939
- if (env.$isSameOrigin$) {
940
- return getter(this, [ "cookie" ]);
941
- }
942
- warnCrossOrgin("get", "cookie", env);
943
- return "";
944
- },
945
- set(value) {
946
- if (env.$isSameOrigin$) {
947
- setter(this, [ "cookie" ], value);
948
- } else {
949
- warnCrossOrgin("set", "cookie", env);
950
- }
951
- }
952
- },
953
- createElement: {
954
- value(tagName) {
955
- tagName = tagName.toUpperCase();
956
- if (!IS_TAG_REG.test(tagName)) {
957
- throw tagName + " not valid";
958
- }
959
- const isIframe = "IFRAME" === tagName;
960
- const winId = this[WinIdKey];
961
- const instanceId = (isIframe ? "f_" : "") + randomId();
962
- callMethod(this, [ "createElement" ], [ tagName ], 2, instanceId);
963
- const elm = getOrCreateNodeInstance(winId, instanceId, tagName);
964
- if (isIframe) {
965
- const env = createEnvironment({
966
- $winId$: instanceId,
967
- $parentWinId$: winId,
968
- $url$: "about:blank"
969
- }, true);
970
- env.$window$.fetch = fetch;
971
- setter(elm, [ "srcdoc" ], getPartytownScript());
972
- } else if ("SCRIPT" === tagName) {
973
- const scriptType = getInstanceStateValue(elm, 5);
974
- isScriptJsType(scriptType) && setter(elm, [ "type" ], "text/partytown");
975
- }
976
- return elm;
977
- }
978
- },
979
- createElementNS: {
980
- value(namespace, tagName) {
981
- const instanceId = randomId();
982
- const nsElm = getOrCreateNodeInstance(this[WinIdKey], instanceId, tagName, namespace);
983
- callMethod(this, [ "createElementNS" ], [ namespace, tagName ], 2, instanceId);
984
- return nsElm;
985
- }
986
- },
987
- createTextNode: {
988
- value(text) {
989
- const winId = this[WinIdKey];
990
- const instanceId = randomId();
991
- const textNode = getOrCreateNodeInstance(winId, instanceId, "#text");
992
- callMethod(this, [ "createTextNode" ], [ text ], 2, instanceId);
993
- return textNode;
994
- }
995
- },
996
- createEvent: {
997
- value: type => new Event(type)
998
- },
999
- currentScript: {
1000
- get() {
1001
- return env.$currentScriptId$ ? getOrCreateNodeInstance(this[WinIdKey], env.$currentScriptId$, "SCRIPT") : null;
1002
- }
1003
- },
1004
- defaultView: {
1005
- get: () => isDocumentImplementation ? null : env.$window$
1006
- },
1007
- documentElement: {
1008
- get: () => env.$documentElement$
1009
- },
1010
- getElementsByTagName: {
1011
- value(tagName) {
1012
- tagName = tagName.toUpperCase();
1013
- return "BODY" === tagName ? [ env.$body$ ] : "HEAD" === tagName ? [ env.$head$ ] : callMethod(this, [ "getElementsByTagName" ], [ tagName ]);
1014
- }
1015
- },
1016
- head: {
1017
- get: () => env.$head$
1018
- },
1019
- images: {
1020
- get() {
1021
- return getter(this, [ "images" ]);
1022
- }
1023
- },
1024
- implementation: {
1025
- get() {
1026
- return {
1027
- hasFeature: () => true,
1028
- createHTMLDocument: title => {
1029
- const $winId$ = randomId();
1030
- callMethod(this, [ "implementation", "createHTMLDocument" ], [ title ], 1, {
1031
- $winId$: $winId$
1032
- });
1033
- const docEnv = createEnvironment({
1034
- $winId$: $winId$,
1035
- $parentWinId$: $winId$,
1036
- $url$: env.$location$ + "",
1037
- $visibilityState$: "hidden"
1038
- }, true, true);
1039
- return docEnv.$document$;
1040
- }
1041
- };
1042
- }
1043
- },
1044
- location: {
1045
- get: () => env.$location$,
1046
- set(url) {
1047
- env.$location$.href = url + "";
1048
- }
1049
- },
1050
- nodeType: {
1051
- value: 9
1052
- },
1053
- parentNode: {
1054
- value: null
1055
- },
1056
- parentElement: {
1057
- value: null
1058
- },
1059
- readyState: {
1060
- value: "complete"
1061
- },
1062
- visibilityState: {
1063
- get: () => env.$visibilityState$ || "visible"
1064
- }
1065
- };
1066
- definePrototypePropertyDescriptor(WorkerDocument, DocumentDescriptorMap);
1067
- cachedProps(WorkerDocument, "compatMode,referrer,forms");
1068
- };
1069
- const patchDocumentElementChild = (WokerDocumentElementChild, env) => {
1070
- const DocumentElementChildDescriptorMap = {
1071
- parentElement: {
1072
- get() {
1073
- return this.parentNode;
1074
- }
1075
- },
1076
- parentNode: {
1077
- get: () => env.$documentElement$
1078
- }
1079
- };
1080
- definePrototypePropertyDescriptor(WokerDocumentElementChild, DocumentElementChildDescriptorMap);
1081
- };
1082
- const patchElement = (WorkerElement, WorkerHTMLElement) => {
1083
- const ElementDescriptorMap = {
1084
- localName: {
1085
- get() {
1086
- return this[InstanceDataKey].toLowerCase();
1087
- }
1088
- },
1089
- namespaceURI: {
1090
- get() {
1091
- return this[NamespaceKey] || "http://www.w3.org/1999/xhtml";
1092
- }
1093
- },
1094
- nodeType: {
1095
- value: 1
1096
- },
1097
- tagName: {
1098
- get() {
1099
- return this[InstanceDataKey];
1100
- }
1101
- }
1102
- };
1103
- definePrototypePropertyDescriptor(WorkerElement, ElementDescriptorMap);
1104
- cachedTreeProps(WorkerElement, elementStructurePropNames);
1105
- cachedProps(WorkerElement, "id");
1106
- cachedDimensionProps(WorkerHTMLElement);
1107
- cachedDimensionMethods(WorkerHTMLElement, commaSplit("getClientRects,getBoundingClientRect"));
1108
- };
1109
- const patchHTMLAnchorElement = (WorkerHTMLAnchorElement, env) => {
1110
- const HTMLAnchorDescriptorMap = {};
1111
- commaSplit("hash,host,hostname,href,origin,pathname,port,protocol,search").map((anchorProp => {
1112
- HTMLAnchorDescriptorMap[anchorProp] = {
1113
- get() {
1114
- let value = getInstanceStateValue(this, 4);
1115
- let href;
1116
- if ("string" != typeof value) {
1117
- href = getter(this, [ "href" ]);
1118
- setInstanceStateValue(this, 4, href);
1119
- value = new URL(href)[anchorProp];
1120
- }
1121
- return resolveToUrl(env, value, null)[anchorProp];
1122
- },
1123
- set(value) {
1124
- let url;
1125
- if ("href" === anchorProp) {
1126
- if ((url => {
1127
- try {
1128
- new URL(url);
1129
- return true;
1130
- } catch (_) {
1131
- return false;
1132
- }
1133
- })(value)) {
1134
- url = new URL(value);
1135
- } else {
1136
- const baseHref = env.$location$.href;
1137
- url = resolveToUrl(env, baseHref, null);
1138
- url.href = new URL(value + "", url.href);
1139
- }
1140
- } else {
1141
- url = resolveToUrl(env, this.href, null);
1142
- url[anchorProp] = value;
1143
- }
1144
- setInstanceStateValue(this, 4, url.href);
1145
- setter(this, [ "href" ], url.href);
1146
- }
1147
- };
1148
- }));
1149
- definePrototypePropertyDescriptor(WorkerHTMLAnchorElement, HTMLAnchorDescriptorMap);
1150
- };
1151
- const patchHTMLIFrameElement = (WorkerHTMLIFrameElement, env) => {
1152
- const HTMLIFrameDescriptorMap = {
1153
- contentDocument: {
1154
- get() {
1155
- return getIframeEnv(this).$document$;
1156
- }
1157
- },
1158
- contentWindow: {
1159
- get() {
1160
- return getIframeEnv(this).$window$;
1161
- }
1162
- },
1163
- src: {
1164
- get() {
1165
- let src = getInstanceStateValue(this, 0);
1166
- if (src && src.startsWith("javascript:")) {
1167
- return src;
1168
- }
1169
- src = getIframeEnv(this).$location$.href;
1170
- return src.startsWith("about:") ? "" : src;
1171
- },
1172
- set(src) {
1173
- if (src) {
1174
- if (src.startsWith("javascript:")) {
1175
- setInstanceStateValue(this, 0, src);
1176
- } else if (!src.startsWith("about:")) {
1177
- let xhr = new XMLHttpRequest;
1178
- let xhrStatus;
1179
- let env = getIframeEnv(this);
1180
- env.$location$.href = src = resolveUrl(env, src, "iframe");
1181
- env.$isLoading$ = 1;
1182
- setInstanceStateValue(this, 1, void 0);
1183
- xhr.open("GET", src, false);
1184
- xhr.send();
1185
- xhrStatus = xhr.status;
1186
- if (xhrStatus > 199 && xhrStatus < 300) {
1187
- setter(this, [ "srcdoc" ], `<base href="${src}">` + xhr.responseText.replace(/<script>/g, '<script type="text/partytown">').replace(/<script /g, '<script type="text/partytown" ').replace(/text\/javascript/g, "text/partytown") + getPartytownScript());
1188
- sendToMain(true);
1189
- webWorkerCtx.$postMessage$([ 7, env.$winId$ ]);
1190
- } else {
1191
- setInstanceStateValue(this, 1, xhrStatus);
1192
- env.$isLoading$ = 0;
1193
- }
1194
- }
1195
- }
1196
- }
1197
- },
1198
- ...HTMLSrcElementDescriptorMap
1199
- };
1200
- definePrototypePropertyDescriptor(WorkerHTMLIFrameElement, HTMLIFrameDescriptorMap);
1201
- };
1202
- const getIframeEnv = iframe => {
1203
- const $winId$ = iframe[InstanceIdKey];
1204
- environments[$winId$] || createEnvironment({
1205
- $winId$: $winId$,
1206
- $parentWinId$: iframe[WinIdKey],
1207
- $url$: getter(iframe, [ "src" ]) || "about:blank"
1208
- }, true);
1209
- return environments[$winId$];
1210
- };
1211
- const patchSvgElement = WorkerSVGGraphicsElement => {
1212
- const getMatrix = (elm, methodName) => {
1213
- const {a: a, b: b, c: c, d: d, e: e, f: f} = callMethod(elm, [ methodName ], EMPTY_ARRAY);
1214
- return new DOMMatrixReadOnly([ a, b, c, d, e, f ]);
1215
- };
1216
- const SVGGraphicsElementDescriptorMap = {
1217
- ...WorkerSVGGraphicsElement,
1218
- getCTM: {
1219
- value: function() {
1220
- return getMatrix(this, "getCTM");
1221
- }
1222
- },
1223
- getScreenCTM: {
1224
- value: function() {
1225
- return getMatrix(this, "getScreenCTM");
1226
- }
1227
- }
1228
- };
1229
- definePrototypePropertyDescriptor(WorkerSVGGraphicsElement, SVGGraphicsElementDescriptorMap);
1230
- };
1231
- const createWindow = ($winId$, $parentWinId$, url, $visibilityState$, isIframeWindow, isDocumentImplementation) => {
1232
- let cstrInstanceId;
1233
- let cstrNodeName;
1234
- let cstrNamespace;
1235
- const WorkerBase = class {
1236
- constructor(winId, instanceId, applyPath, instanceData, namespace) {
1237
- this[WinIdKey] = winId || $winId$;
1238
- this[InstanceIdKey] = instanceId || cstrInstanceId || randomId();
1239
- this[ApplyPathKey] = applyPath || [];
1240
- this[InstanceDataKey] = instanceData || cstrNodeName;
1241
- this[NamespaceKey] = namespace || cstrNamespace;
1242
- this[InstanceStateKey] = {};
1243
- cstrInstanceId = cstrNodeName = cstrNamespace = void 0;
1244
- }
1245
- };
1246
- const WorkerLocation = defineConstructorName(class extends URL {
1247
- assign() {
1248
- logWorker("location.assign(), noop");
1249
- }
1250
- reload() {
1251
- logWorker("location.reload(), noop");
1252
- }
1253
- replace() {
1254
- logWorker("location.replace(), noop");
1255
- }
1256
- }, "Location");
1257
- const $location$ = new WorkerLocation(url);
1258
- const $isSameOrigin$ = $location$.origin === webWorkerCtx.$origin$ || "about:blank" === $location$.origin;
1259
- const $isTopWindow$ = $parentWinId$ === $winId$;
1260
- const env = {};
1261
- const getChildEnvs = () => {
1262
- let childEnv = [];
1263
- let envWinId;
1264
- let otherEnv;
1265
- for (envWinId in environments) {
1266
- otherEnv = environments[envWinId];
1267
- otherEnv.$parentWinId$ !== $winId$ || otherEnv.$isTopWindow$ || childEnv.push(otherEnv);
1268
- }
1269
- return childEnv;
1270
- };
1271
- const WorkerWindow = defineConstructorName(class extends WorkerBase {
1272
- constructor() {
1273
- super($winId$, $winId$);
1274
- let win = this;
1275
- let value;
1276
- let historyState;
1277
- let hasInitializedMedia = 0;
1278
- let initWindowMedia = () => {
1279
- if (!hasInitializedMedia) {
1280
- (() => {
1281
- if (!webWorkerCtx.$initWindowMedia$) {
1282
- self.$bridgeToMedia$ = [ getter, setter, callMethod, constructGlobal, definePrototypePropertyDescriptor, randomId, WinIdKey, InstanceIdKey, ApplyPathKey ];
1283
- webWorkerCtx.$importScripts$(partytownLibUrl("partytown-media.js?v=0.6.4"));
1284
- webWorkerCtx.$initWindowMedia$ = self.$bridgeFromMedia$;
1285
- delete self.$bridgeFromMedia$;
1286
- }
1287
- return webWorkerCtx.$initWindowMedia$;
1288
- })()(WorkerBase, WorkerEventTargetProxy, env, win, windowMediaConstructors);
1289
- hasInitializedMedia = 1;
1290
- }
1291
- };
1292
- let nodeCstrs = {};
1293
- let $createNode$ = (nodeName, instanceId, namespace) => {
1294
- htmlMedia.includes(nodeName) && initWindowMedia();
1295
- const NodeCstr = nodeCstrs[nodeName] ? nodeCstrs[nodeName] : nodeName.includes("-") ? nodeCstrs.UNKNOWN : nodeCstrs.I;
1296
- cstrInstanceId = instanceId;
1297
- cstrNodeName = nodeName;
1298
- cstrNamespace = namespace;
1299
- return new NodeCstr;
1300
- };
1301
- win.Window = WorkerWindow;
1302
- win.name = name + `${normalizedWinId($winId$)} (${$winId$})`;
1303
- createNodeCstr(win, env, WorkerBase);
1304
- createCSSStyleDeclarationCstr(win, WorkerBase, "CSSStyleDeclaration");
1305
- ((win, WorkerBase, cstrName) => {
1306
- win[cstrName] = defineConstructorName(class extends WorkerBase {
1307
- now() {
1308
- return performance.now();
1309
- }
1310
- }, cstrName);
1311
- })(win, WorkerBase, "Performance");
1312
- ((win, nodeCstrs) => {
1313
- const registry = new Map;
1314
- win.customElements = {
1315
- define(tagName, Cstr, opts) {
1316
- registry.set(tagName, Cstr);
1317
- nodeCstrs[tagName.toUpperCase()] = Cstr;
1318
- const ceData = [ Cstr.name, Cstr.observedAttributes ];
1319
- callMethod(win, [ "customElements", "define" ], [ tagName, ceData, opts ]);
1320
- },
1321
- get: tagName => registry.get(tagName) || callMethod(win, [ "customElements", "get" ], [ tagName ]),
1322
- whenDefined: tagName => registry.has(tagName) ? Promise.resolve() : callMethod(win, [ "customElements", "whenDefined" ], [ tagName ]),
1323
- upgrade: elm => callMethod(win, [ "customElements", "upgrade" ], [ elm ])
1324
- };
1325
- })(win, nodeCstrs);
1326
- webWorkerCtx.$interfaces$.map((([cstrName, superCstrName, members, interfaceType, nodeName]) => {
1327
- const SuperCstr = TrapConstructors[cstrName] ? WorkerTrapProxy : "EventTarget" === superCstrName ? WorkerEventTargetProxy : "Object" === superCstrName ? WorkerBase : win[superCstrName];
1328
- const Cstr = win[cstrName] = defineConstructorName(12 === interfaceType ? class extends WorkerBase {
1329
- constructor(...args) {
1330
- super();
1331
- constructGlobal(this, cstrName, args);
1332
- }
1333
- } : win[cstrName] || class extends SuperCstr {}, cstrName);
1334
- nodeName && (nodeCstrs[nodeName] = Cstr);
1335
- members.map((([memberName, memberType, staticValue]) => {
1336
- memberName in Cstr.prototype || memberName in SuperCstr.prototype || ("string" == typeof memberType ? definePrototypeProperty(Cstr, memberName, {
1337
- get() {
1338
- if (!hasInstanceStateValue(this, memberName)) {
1339
- const instanceId = this[InstanceIdKey];
1340
- const applyPath = [ ...this[ApplyPathKey], memberName ];
1341
- const PropCstr = win[memberType];
1342
- PropCstr && setInstanceStateValue(this, memberName, new PropCstr($winId$, instanceId, applyPath));
1343
- }
1344
- return getInstanceStateValue(this, memberName);
1345
- },
1346
- set(value) {
1347
- setInstanceStateValue(this, memberName, value);
1348
- }
1349
- }) : 5 === memberType ? definePrototypeValue(Cstr, memberName, (function(...args) {
1350
- return callMethod(this, [ memberName ], args);
1351
- })) : memberType > 0 && (void 0 !== staticValue ? definePrototypeValue(Cstr, memberName, staticValue) : definePrototypeProperty(Cstr, memberName, {
1352
- get() {
1353
- return getter(this, [ memberName ]);
1354
- },
1355
- set(value) {
1356
- return setter(this, [ memberName ], value);
1357
- }
1358
- })));
1359
- }));
1360
- }));
1361
- commaSplit("atob,btoa,crypto,indexedDB,setTimeout,setInterval,clearTimeout,clearInterval").map((globalName => {
1362
- delete WorkerWindow.prototype[globalName];
1363
- if (!(globalName in win)) {
1364
- value = self[globalName];
1365
- null != value && (win[globalName] = "function" != typeof value || value.toString().startsWith("class") ? value : value.bind(self));
1366
- }
1367
- }));
1368
- Object.getOwnPropertyNames(self).map((globalName => {
1369
- globalName in win || (win[globalName] = self[globalName]);
1370
- }));
1371
- windowMediaConstructors.map((cstrName => defineProperty(win, cstrName, {
1372
- get() {
1373
- initWindowMedia();
1374
- return win[cstrName];
1375
- }
1376
- })));
1377
- "trustedTypes" in self && (win.trustedTypes = self.trustedTypes);
1378
- patchElement(win.Element, win.HTMLElement);
1379
- patchDocument(win.Document, env, isDocumentImplementation);
1380
- (WorkerDocumentFragment => {
1381
- definePrototypeNodeType(WorkerDocumentFragment, 11);
1382
- cachedTreeProps(WorkerDocumentFragment, elementStructurePropNames);
1383
- })(win.DocumentFragment);
1384
- patchHTMLAnchorElement(win.HTMLAnchorElement, env);
1385
- (WorkerHTMLFormElement => {
1386
- definePrototypePropertyDescriptor(WorkerHTMLFormElement, {});
1387
- cachedProps(WorkerHTMLFormElement, "elements");
1388
- })(win.HTMLFormElement);
1389
- patchHTMLIFrameElement(win.HTMLIFrameElement);
1390
- patchHTMLScriptElement(win.HTMLScriptElement, env);
1391
- patchSvgElement(win.SVGGraphicsElement);
1392
- patchDocumentElementChild(win.HTMLHeadElement, env);
1393
- patchDocumentElementChild(win.HTMLBodyElement, env);
1394
- ((WorkerHTMLHtmlElement, env) => {
1395
- const DocumentElementDescriptorMap = {
1396
- parentElement: {
1397
- value: null
1398
- },
1399
- parentNode: {
1400
- get: () => env.$document$
1401
- }
1402
- };
1403
- definePrototypePropertyDescriptor(WorkerHTMLHtmlElement, DocumentElementDescriptorMap);
1404
- })(win.HTMLHtmlElement, env);
1405
- createCSSStyleSheetConstructor(win, "CSSStyleSheet");
1406
- definePrototypeNodeType(win.Comment, 8);
1407
- definePrototypeNodeType(win.DocumentType, 10);
1408
- Object.assign(env, {
1409
- $winId$: $winId$,
1410
- $parentWinId$: $parentWinId$,
1411
- $window$: new Proxy(win, {
1412
- get: (win, propName) => {
1413
- var _a;
1414
- if ("string" != typeof propName || isNaN(propName)) {
1415
- return (null === (_a = webWorkerCtx.$config$.mainWindowAccessors) || void 0 === _a ? void 0 : _a.includes(propName)) ? getter(this, [ propName ]) : win[propName];
1416
- }
1417
- {
1418
- let frame = getChildEnvs()[propName];
1419
- return frame ? frame.$window$ : void 0;
1420
- }
1421
- },
1422
- has: () => true
1423
- }),
1424
- $document$: $createNode$("#document", $winId$ + ".d"),
1425
- $documentElement$: $createNode$("HTML", $winId$ + ".e"),
1426
- $head$: $createNode$("HEAD", $winId$ + ".h"),
1427
- $body$: $createNode$("BODY", $winId$ + ".b"),
1428
- $location$: $location$,
1429
- $visibilityState$: $visibilityState$,
1430
- $isSameOrigin$: $isSameOrigin$,
1431
- $isTopWindow$: $isTopWindow$,
1432
- $createNode$: $createNode$
1433
- });
1434
- win.requestAnimationFrame = cb => setTimeout((() => cb(performance.now())), 9);
1435
- win.cancelAnimationFrame = id => clearTimeout(id);
1436
- win.requestIdleCallback = (cb, start) => {
1437
- start = Date.now();
1438
- return setTimeout((() => cb({
1439
- didTimeout: false,
1440
- timeRemaining: () => Math.max(0, 50 - (Date.now() - start))
1441
- })), 1);
1442
- };
1443
- win.cancelIdleCallback = id => clearTimeout(id);
1444
- addStorageApi(win, "localStorage", webWorkerlocalStorage, $isSameOrigin$, env);
1445
- addStorageApi(win, "sessionStorage", webWorkerSessionStorage, $isSameOrigin$, env);
1446
- $isSameOrigin$ || (win.indexeddb = void 0);
1447
- if (isIframeWindow) {
1448
- historyState = {};
1449
- win.history = {
1450
- pushState(stateObj) {
1451
- historyState = stateObj;
1452
- },
1453
- replaceState(stateObj) {
1454
- historyState = stateObj;
1455
- },
1456
- get state() {
1457
- return historyState;
1458
- },
1459
- length: 0
1460
- };
1461
- win.indexeddb = void 0;
1462
- } else {
1463
- const originalPushState = win.history.pushState.bind(win.history);
1464
- const originalReplaceState = win.history.replaceState.bind(win.history);
1465
- win.history.pushState = (stateObj, _, newUrl) => {
1466
- false !== env.$propagateHistoryChange$ && originalPushState(stateObj, _, newUrl);
1467
- };
1468
- win.history.replaceState = (stateObj, _, newUrl) => {
1469
- false !== env.$propagateHistoryChange$ && originalReplaceState(stateObj, _, newUrl);
1470
- };
1471
- }
1472
- win.Worker = void 0;
1473
- }
1474
- addEventListener(...args) {
1475
- "load" === args[0] ? env.$runWindowLoadEvent$ && setTimeout((() => args[1]({
1476
- type: "load"
1477
- }))) : callMethod(this, [ "addEventListener" ], args, 2);
1478
- }
1479
- get body() {
1480
- return env.$body$;
1481
- }
1482
- get document() {
1483
- return env.$document$;
1484
- }
1485
- get documentElement() {
1486
- return env.$documentElement$;
1487
- }
1488
- fetch(input, init) {
1489
- input = "string" == typeof input || input instanceof URL ? String(input) : input.url;
1490
- return fetch(resolveUrl(env, input, "fetch"), init);
1491
- }
1492
- get frames() {
1493
- return env.$window$;
1494
- }
1495
- get frameElement() {
1496
- return $isTopWindow$ ? null : getOrCreateNodeInstance($parentWinId$, $winId$, "IFRAME");
1497
- }
1498
- get globalThis() {
1499
- return env.$window$;
1500
- }
1501
- get head() {
1502
- return env.$head$;
1503
- }
1504
- get length() {
1505
- return getChildEnvs().length;
1506
- }
1507
- get location() {
1508
- return $location$;
1509
- }
1510
- set location(loc) {
1511
- $location$.href = loc + "";
1512
- }
1513
- get Image() {
1514
- return createImageConstructor(env);
1515
- }
1516
- get navigator() {
1517
- return (env => {
1518
- let key;
1519
- let nav = {
1520
- sendBeacon: (url, body) => {
1521
- if (webWorkerCtx.$config$.logSendBeaconRequests) {
1522
- try {
1523
- logWorker(`sendBeacon: ${resolveUrl(env, url, null)}${body ? ", data: " + JSON.stringify(body) : ""}`);
1524
- } catch (e) {
1525
- console.error(e);
1526
- }
1527
- }
1528
- try {
1529
- fetch(resolveUrl(env, url, null), {
1530
- method: "POST",
1531
- body: body,
1532
- mode: "no-cors",
1533
- keepalive: true
1534
- });
1535
- return true;
1536
- } catch (e) {
1537
- console.error(e);
1538
- return false;
1539
- }
1540
- }
1541
- };
1542
- for (key in navigator) {
1543
- nav[key] = navigator[key];
1544
- }
1545
- return nav;
1546
- })(env);
1547
- }
1548
- get origin() {
1549
- return $location$.origin;
1550
- }
1551
- set origin(_) {}
1552
- get parent() {
1553
- for (let envWinId in environments) {
1554
- if (environments[envWinId].$winId$ === $parentWinId$) {
1555
- return environments[envWinId].$window$;
1556
- }
1557
- }
1558
- return env.$window$;
1559
- }
1560
- postMessage(...args) {
1561
- if (environments[args[0]]) {
1562
- len(postMessages) > 50 && postMessages.splice(0, 5);
1563
- postMessages.push({
1564
- $winId$: args[0],
1565
- $data$: JSON.stringify(args[1])
1566
- });
1567
- args = args.slice(1);
1568
- }
1569
- callMethod(this, [ "postMessage" ], args, 3);
1570
- }
1571
- get self() {
1572
- return env.$window$;
1573
- }
1574
- get top() {
1575
- for (let envWinId in environments) {
1576
- if (environments[envWinId].$isTopWindow$) {
1577
- return environments[envWinId].$window$;
1578
- }
1579
- }
1580
- return env.$window$;
1581
- }
1582
- get window() {
1583
- return env.$window$;
1584
- }
1585
- get XMLHttpRequest() {
1586
- const Xhr = XMLHttpRequest;
1587
- const str = String(Xhr);
1588
- const ExtendedXhr = defineConstructorName(class extends Xhr {
1589
- open(...args) {
1590
- args[1] = resolveUrl(env, args[1], "xhr");
1591
- super.open(...args);
1592
- }
1593
- set withCredentials(_) {}
1594
- toString() {
1595
- return str;
1596
- }
1597
- }, getConstructorName(Xhr));
1598
- ExtendedXhr.prototype.constructor.toString = () => str;
1599
- return ExtendedXhr;
1600
- }
1601
- }, "Window");
1602
- const WorkerTrapProxy = class extends WorkerBase {
1603
- constructor(winId, instanceId, applyPath, nodeName) {
1604
- super(winId, instanceId, applyPath, nodeName);
1605
- return new Proxy(this, {
1606
- get: (instance, propName) => getter(instance, [ propName ]),
1607
- set(instance, propName, propValue) {
1608
- setter(instance, [ propName ], propValue);
1609
- return true;
1610
- }
1611
- });
1612
- }
1613
- };
1614
- const WorkerEventTargetProxy = class extends WorkerBase {};
1615
- eventTargetMethods.map((methodName => WorkerEventTargetProxy.prototype[methodName] = function(...args) {
1616
- return callMethod(this, [ methodName ], args, 2);
1617
- }));
1618
- cachedProps(WorkerWindow, "devicePixelRatio");
1619
- cachedDimensionProps(WorkerWindow);
1620
- cachedDimensionMethods(WorkerWindow, [ "getComputedStyle" ]);
1621
- new WorkerWindow;
1622
- return env;
1623
- };
1624
- const TrapConstructors = {
1625
- DOMStringMap: 1,
1626
- NamedNodeMap: 1
1627
- };
1628
- const createEnvironment = ({$winId$: $winId$, $parentWinId$: $parentWinId$, $url$: $url$, $visibilityState$: $visibilityState$}, isIframeWindow, isDocumentImplementation) => {
1629
- if (!environments[$winId$]) {
1630
- environments[$winId$] = createWindow($winId$, $parentWinId$, $url$, $visibilityState$, isIframeWindow, isDocumentImplementation);
1631
- {
1632
- const winType = $winId$ === $parentWinId$ ? "top" : "iframe";
1633
- logWorker(`Created ${winType} window ${normalizedWinId($winId$)} environment`, $winId$);
1634
- }
1635
- }
1636
- webWorkerCtx.$postMessage$([ 7, $winId$ ]);
1637
- return environments[$winId$];
1638
- };
1639
- const queuedEvents = [];
1640
- const receiveMessageFromSandboxToWorker = ev => {
1641
- const msg = ev.data;
1642
- const msgType = msg[0];
1643
- const msgValue = msg[1];
1644
- if (webWorkerCtx.$isInitialized$) {
1645
- if (7 === msgType) {
1646
- (async initScript => {
1647
- let winId = initScript.$winId$;
1648
- let instanceId = initScript.$instanceId$;
1649
- let instance = getOrCreateNodeInstance(winId, instanceId, "SCRIPT");
1650
- let scriptContent = initScript.$content$;
1651
- let scriptSrc = initScript.$url$;
1652
- let scriptOrgSrc = initScript.$orgUrl$;
1653
- let errorMsg = "";
1654
- let env = environments[winId];
1655
- let rsp;
1656
- if (scriptSrc) {
1657
- try {
1658
- scriptSrc = resolveToUrl(env, scriptSrc, "script") + "";
1659
- setInstanceStateValue(instance, 4, scriptSrc);
1660
- webWorkerCtx.$config$.logScriptExecution && logWorker(`Execute script src: ${scriptOrgSrc}`, winId);
1661
- rsp = await fetch(scriptSrc);
1662
- if (rsp.ok) {
1663
- scriptContent = await rsp.text();
1664
- env.$currentScriptId$ = instanceId;
1665
- run(env, scriptContent, scriptOrgSrc || scriptSrc);
1666
- runStateLoadHandlers(instance, "load");
1667
- } else {
1668
- errorMsg = rsp.statusText;
1669
- runStateLoadHandlers(instance, "error");
1670
- }
1671
- } catch (urlError) {
1672
- console.error(urlError);
1673
- errorMsg = String(urlError.stack || urlError);
1674
- runStateLoadHandlers(instance, "error");
1675
- }
1676
- } else {
1677
- scriptContent && (errorMsg = runScriptContent(env, instanceId, scriptContent, winId, errorMsg));
1678
- }
1679
- env.$currentScriptId$ = "";
1680
- webWorkerCtx.$postMessage$([ 6, winId, instanceId, errorMsg ]);
1681
- })(msgValue);
1682
- } else if (9 === msgType) {
1683
- (({$winId$: $winId$, $instanceId$: $instanceId$, $refId$: $refId$, $thisArg$: $thisArg$, $args$: $args$}) => {
1684
- if (webWorkerRefsByRefId[$refId$]) {
1685
- try {
1686
- webWorkerRefsByRefId[$refId$].apply(deserializeFromMain($winId$, $instanceId$, [], $thisArg$), deserializeFromMain($winId$, $instanceId$, [], $args$));
1687
- } catch (e) {
1688
- console.error(e);
1689
- }
1690
- }
1691
- })(msgValue);
1692
- } else if (10 === msgType) {
1693
- (({$winId$: $winId$, $forward$: $forward$, $args$: $args$}) => {
1694
- try {
1695
- let target = environments[$winId$].$window$;
1696
- let i = 0;
1697
- let l = len($forward$);
1698
- for (;i < l; i++) {
1699
- i + 1 < l ? target = target[$forward$[i]] : target[$forward$[i]].apply(target, deserializeFromMain(null, $winId$, [], $args$));
1700
- }
1701
- } catch (e) {
1702
- console.error(e);
1703
- }
1704
- })(msgValue);
1705
- } else if (5 === msgType) {
1706
- createEnvironment(msgValue);
1707
- } else if (8 === msgType) {
1708
- if (1 !== environments[msgValue].$isInitialized$) {
1709
- const winId = msgValue;
1710
- const env = environments[winId];
1711
- const winType = env.$winId$ === env.$parentWinId$ ? "top" : "iframe";
1712
- logWorker(`Initialized ${winType} window ${normalizedWinId(winId)} environment 🎉`, winId);
1713
- }
1714
- environments[msgValue].$isInitialized$ = 1;
1715
- environments[msgValue].$isLoading$ = 0;
1716
- } else if (14 === msgType) {
1717
- environments[msgValue].$visibilityState$ = msg[2];
1718
- } else if (13 === msgType) {
1719
- const $winId$ = msgValue.$winId$;
1720
- const env = environments[$winId$];
1721
- env.$location$.href = msgValue.url;
1722
- !function($winId$, env, data) {
1723
- const history = env.$window$.history;
1724
- switch (data.type) {
1725
- case 0:
1726
- env.$propagateHistoryChange$ = false;
1727
- try {
1728
- history.pushState(data.state, "", data.newUrl);
1729
- } catch (e) {}
1730
- env.$propagateHistoryChange$ = true;
1731
- break;
1732
-
1733
- case 1:
1734
- env.$propagateHistoryChange$ = false;
1735
- try {
1736
- history.replaceState(data.state, "", data.newUrl);
1737
- } catch (e) {}
1738
- env.$propagateHistoryChange$ = true;
1739
- }
1740
- }(msgValue.$winId$, env, msgValue);
1741
- } else {
1742
- 15 === msgType && ((_type, winId, instanceId, callbackName, args) => {
1743
- const elm = getOrCreateNodeInstance(winId, instanceId);
1744
- elm && "function" == typeof elm[callbackName] && elm[callbackName].apply(elm, args);
1745
- })(...msg);
1746
- }
1747
- } else if (1 === msgType) {
1748
- (initWebWorkerData => {
1749
- const config = webWorkerCtx.$config$ = JSON.parse(initWebWorkerData.$config$);
1750
- const locOrigin = initWebWorkerData.$origin$;
1751
- webWorkerCtx.$importScripts$ = importScripts.bind(self);
1752
- webWorkerCtx.$interfaces$ = initWebWorkerData.$interfaces$;
1753
- webWorkerCtx.$libPath$ = initWebWorkerData.$libPath$;
1754
- webWorkerCtx.$origin$ = locOrigin;
1755
- webWorkerCtx.$postMessage$ = postMessage.bind(self);
1756
- webWorkerCtx.$sharedDataBuffer$ = initWebWorkerData.$sharedDataBuffer$;
1757
- webWorkerlocalStorage.set(locOrigin, initWebWorkerData.$localStorage$);
1758
- webWorkerSessionStorage.set(locOrigin, initWebWorkerData.$sessionStorage$);
1759
- self.importScripts = void 0;
1760
- delete self.postMessage;
1761
- delete self.WorkerGlobalScope;
1762
- commaSplit("resolveUrl,get,set,apply").map((configName => {
1763
- config[configName] && (config[configName] = new Function("return " + config[configName])());
1764
- }));
1765
- })(msgValue);
1766
- webWorkerCtx.$postMessage$([ 2 ]);
1767
- } else if (3 === msgType) {
1768
- webWorkerCtx.$interfaces$ = [ ...webWorkerCtx.$interfaces$, ...msgValue ];
1769
- webWorkerCtx.$isInitialized$ = 1;
1770
- logWorker("Initialized web worker");
1771
- webWorkerCtx.$postMessage$([ 4 ]);
1772
- queuedEvents.length && logWorker(`Queued ready messages: ${queuedEvents.length}`);
1773
- [ ...queuedEvents ].map(receiveMessageFromSandboxToWorker);
1774
- queuedEvents.length = 0;
1775
- } else {
1776
- queuedEvents.push(ev);
1777
- }
1778
- };
1779
- self.onmessage = receiveMessageFromSandboxToWorker;
1780
- postMessage([ 0 ]);
1781
- })(self);