|
1 |
| -/* Partytown 0.6.4 - MIT builder.io */ |
| 1 | +/* Partytown 0.7.1 - MIT builder.io */ |
2 | 2 | (self => {
|
3 | 3 | const WinIdKey = Symbol();
|
4 | 4 | const InstanceIdKey = Symbol();
|
|
224 | 224 | this.stack = errorObject.stack;
|
225 | 225 | }
|
226 | 226 | }
|
227 |
| - const NodeList = class { |
| 227 | + class NodeList { |
228 | 228 | constructor(nodes) {
|
229 | 229 | (this._ = nodes).map(((node, index) => this[index] = node));
|
230 | 230 | }
|
|
249 | 249 | [Symbol.iterator]() {
|
250 | 250 | return this._[Symbol.iterator]();
|
251 | 251 | }
|
252 |
| - }; |
| 252 | + } |
253 | 253 | const Attr = class {
|
254 | 254 | constructor(serializedAttr) {
|
255 | 255 | this.name = serializedAttr[0];
|
|
692 | 692 | };
|
693 | 693 | const run = (env, scriptContent, scriptUrl) => {
|
694 | 694 | env.$runWindowLoadEvent$ = 1;
|
695 |
| - 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 : ""); |
| 695 | + scriptContent = `with(this){${scriptContent.replace(/\bthis\b/g, "(thi$(this)?window:this)").replace(/\/\/# so/g, "//Xso")}\n;function thi$(t){return t===this}};${(webWorkerCtx.$config$.globalFns || []).filter((globalFnName => /[a-zA-Z_$][0-9a-zA-Z_$]*/.test(globalFnName))).map((g => `(typeof ${g}=='function'&&(this.${g}=${g}))`)).join(";")};` + (scriptUrl ? "\n//# sourceURL=" + scriptUrl : ""); |
696 | 696 | env.$isSameOrigin$ || (scriptContent = scriptContent.replace(/.postMessage\(/g, `.postMessage('${env.$winId$}',`));
|
697 | 697 | new Function(scriptContent).call(env.$window$);
|
698 | 698 | env.$runWindowLoadEvent$ = 0;
|
|
722 | 722 | return resolvedUrl;
|
723 | 723 | };
|
724 | 724 | const resolveUrl = (env, url, type) => resolveToUrl(env, url, type) + "";
|
725 |
| - const getPartytownScript = () => `<script src="${partytownLibUrl("partytown.js?v=0.6.4")}"><\/script>`; |
| 725 | + const getPartytownScript = () => `<script src="${partytownLibUrl("partytown.js?v=0.7.1")}"><\/script>`; |
726 | 726 | const createImageConstructor = env => class HTMLImageElement {
|
727 | 727 | constructor() {
|
728 | 728 | this.s = "";
|
729 | 729 | this.l = [];
|
730 | 730 | this.e = [];
|
| 731 | + this.style = {}; |
731 | 732 | }
|
732 | 733 | get src() {
|
733 | 734 | return this.s;
|
|
860 | 861 | };
|
861 | 862 | const isScriptJsType = scriptType => !scriptType || "text/javascript" === scriptType;
|
862 | 863 | const createNodeCstr = (win, env, WorkerBase) => {
|
| 864 | + const config = webWorkerCtx.$config$; |
863 | 865 | const WorkerNode = defineConstructorName(class extends WorkerBase {
|
864 | 866 | appendChild(node) {
|
865 | 867 | return this.insertBefore(node, null);
|
866 | 868 | }
|
867 | 869 | get href() {}
|
868 | 870 | set href(_) {}
|
869 | 871 | insertBefore(newNode, referenceNode) {
|
| 872 | + var _a, _b; |
870 | 873 | const winId = newNode[WinIdKey] = this[WinIdKey];
|
871 | 874 | const instanceId = newNode[InstanceIdKey];
|
872 | 875 | const nodeName = newNode[InstanceDataKey];
|
|
877 | 880 | const scriptType = getInstanceStateValue(newNode, 5);
|
878 | 881 | if (scriptContent) {
|
879 | 882 | if (isScriptJsType(scriptType)) {
|
880 |
| - const errorMsg = runScriptContent(env, instanceId, scriptContent, winId, ""); |
881 |
| - const datasetType = errorMsg ? "pterror" : "ptid"; |
882 |
| - const datasetValue = errorMsg || instanceId; |
883 |
| - setter(newNode, [ "type" ], "text/partytown-x"); |
884 |
| - setter(newNode, [ "dataset", datasetType ], datasetValue); |
| 883 | + const scriptId = newNode.id; |
| 884 | + const loadOnMainThread = scriptId && (null === (_b = null === (_a = config.loadScriptsOnMainThread) || void 0 === _a ? void 0 : _a.includes) || void 0 === _b ? void 0 : _b.call(_a, scriptId)); |
| 885 | + if (loadOnMainThread) { |
| 886 | + setter(newNode, [ "type" ], "text/javascript"); |
| 887 | + } else { |
| 888 | + const errorMsg = runScriptContent(env, instanceId, scriptContent, winId, ""); |
| 889 | + const datasetType = errorMsg ? "pterror" : "ptid"; |
| 890 | + const datasetValue = errorMsg || instanceId; |
| 891 | + setter(newNode, [ "type" ], "text/partytown-x"); |
| 892 | + setter(newNode, [ "dataset", datasetType ], datasetValue); |
| 893 | + } |
885 | 894 | }
|
886 | 895 | setter(newNode, [ "innerHTML" ], scriptContent);
|
887 | 896 | }
|
|
1288 | 1297 | (() => {
|
1289 | 1298 | if (!webWorkerCtx.$initWindowMedia$) {
|
1290 | 1299 | self.$bridgeToMedia$ = [ getter, setter, callMethod, constructGlobal, definePrototypePropertyDescriptor, randomId, WinIdKey, InstanceIdKey, ApplyPathKey ];
|
1291 |
| - webWorkerCtx.$importScripts$(partytownLibUrl("partytown-media.js?v=0.6.4")); |
| 1300 | + webWorkerCtx.$importScripts$(partytownLibUrl("partytown-media.js?v=0.7.1")); |
1292 | 1301 | webWorkerCtx.$initWindowMedia$ = self.$bridgeFromMedia$;
|
1293 | 1302 | delete self.$bridgeFromMedia$;
|
1294 | 1303 | }
|
|
1309 | 1318 | win.Window = WorkerWindow;
|
1310 | 1319 | win.name = name + `${normalizedWinId($winId$)} (${$winId$})`;
|
1311 | 1320 | createNodeCstr(win, env, WorkerBase);
|
| 1321 | + (win => { |
| 1322 | + win.NodeList = defineConstructorName(NodeList, "NodeList"); |
| 1323 | + })(win); |
1312 | 1324 | createCSSStyleDeclarationCstr(win, WorkerBase, "CSSStyleDeclaration");
|
1313 | 1325 | ((win, WorkerBase, cstrName) => {
|
1314 | 1326 | win[cstrName] = defineConstructorName(class extends WorkerBase {
|
|
1661 | 1673 | let errorMsg = "";
|
1662 | 1674 | let env = environments[winId];
|
1663 | 1675 | let rsp;
|
| 1676 | + let javascriptContentTypes = [ "text/jscript", "text/javascript", "text/x-javascript", "application/javascript", "application/x-javascript", "text/ecmascript", "text/x-ecmascript", "application/ecmascript" ]; |
1664 | 1677 | if (scriptSrc) {
|
1665 | 1678 | try {
|
1666 | 1679 | scriptSrc = resolveToUrl(env, scriptSrc, "script") + "";
|
1667 | 1680 | setInstanceStateValue(instance, 4, scriptSrc);
|
1668 | 1681 | webWorkerCtx.$config$.logScriptExecution && logWorker(`Execute script src: ${scriptOrgSrc}`, winId);
|
1669 | 1682 | rsp = await fetch(scriptSrc);
|
1670 | 1683 | if (rsp.ok) {
|
1671 |
| - scriptContent = await rsp.text(); |
1672 |
| - env.$currentScriptId$ = instanceId; |
1673 |
| - run(env, scriptContent, scriptOrgSrc || scriptSrc); |
| 1684 | + let responseContentType = rsp.headers.get("content-type"); |
| 1685 | + let shouldExecute = javascriptContentTypes.some((ct => { |
| 1686 | + var _a, _b, _c; |
| 1687 | + return null === (_c = null === (_a = null == responseContentType ? void 0 : responseContentType.toLowerCase) || void 0 === _a ? void 0 : (_b = _a.call(responseContentType)).includes) || void 0 === _c ? void 0 : _c.call(_b, ct); |
| 1688 | + })); |
| 1689 | + if (shouldExecute) { |
| 1690 | + scriptContent = await rsp.text(); |
| 1691 | + env.$currentScriptId$ = instanceId; |
| 1692 | + run(env, scriptContent, scriptOrgSrc || scriptSrc); |
| 1693 | + } |
1674 | 1694 | runStateLoadHandlers(instance, "load");
|
1675 | 1695 | } else {
|
1676 | 1696 | errorMsg = rsp.statusText;
|
|
0 commit comments