From ee3633b5329fda315c24892e28fb0b48ef72e893 Mon Sep 17 00:00:00 2001 From: gimenes Date: Tue, 26 Mar 2024 16:08:57 -0300 Subject: [PATCH] remove partytown files --- static/~partytown/debug/partytown-atomics.js | 559 ----- static/~partytown/debug/partytown-media.js | 374 ---- .../~partytown/debug/partytown-sandbox-sw.js | 546 ----- static/~partytown/debug/partytown-sw.js | 59 - .../~partytown/debug/partytown-ww-atomics.js | 1811 ----------------- static/~partytown/debug/partytown-ww-sw.js | 1803 ---------------- static/~partytown/debug/partytown.js | 72 - static/~partytown/partytown-atomics.js | 2 - static/~partytown/partytown-media.js | 2 - static/~partytown/partytown-sw.js | 2 - static/~partytown/partytown.js | 2 - 11 files changed, 5232 deletions(-) delete mode 100644 static/~partytown/debug/partytown-atomics.js delete mode 100644 static/~partytown/debug/partytown-media.js delete mode 100644 static/~partytown/debug/partytown-sandbox-sw.js delete mode 100644 static/~partytown/debug/partytown-sw.js delete mode 100644 static/~partytown/debug/partytown-ww-atomics.js delete mode 100644 static/~partytown/debug/partytown-ww-sw.js delete mode 100644 static/~partytown/debug/partytown.js delete mode 100644 static/~partytown/partytown-atomics.js delete mode 100644 static/~partytown/partytown-media.js delete mode 100644 static/~partytown/partytown-sw.js delete mode 100644 static/~partytown/partytown.js diff --git a/static/~partytown/debug/partytown-atomics.js b/static/~partytown/debug/partytown-atomics.js deleted file mode 100644 index 6ae8f65..0000000 --- a/static/~partytown/debug/partytown-atomics.js +++ /dev/null @@ -1,559 +0,0 @@ -/* Partytown 0.7.2 - MIT builder.io */ -(window => { - const isPromise = v => "object" == typeof v && v && v.then; - const noop = () => {}; - const len = obj => obj.length; - const getConstructorName = obj => { - var _a, _b, _c; - try { - const constructorName = null === (_a = null == obj ? void 0 : obj.constructor) || void 0 === _a ? void 0 : _a.name; - if (constructorName) { - return constructorName; - } - } catch (e) {} - try { - 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; - if (zoneJsConstructorName) { - return zoneJsConstructorName; - } - } catch (e) {} - return ""; - }; - const startsWith = (str, val) => str.startsWith(val); - const isValidMemberName = memberName => !(startsWith(memberName, "webkit") || startsWith(memberName, "toJSON") || startsWith(memberName, "constructor") || startsWith(memberName, "toString") || startsWith(memberName, "_")); - const getNodeName = node => 11 === node.nodeType && node.host ? "#s" : node.nodeName; - const randomId = () => Math.round(Math.random() * Number.MAX_SAFE_INTEGER).toString(36); - const defineConstructorName = (Cstr, value) => ((obj, memberName, descriptor) => Object.defineProperty(obj, memberName, { - ...descriptor, - configurable: true - }))(Cstr, "name", { - value: value - }); - const htmlConstructorTags = { - Anchor: "a", - DList: "dl", - Image: "img", - OList: "ol", - Paragraph: "p", - Quote: "q", - TableCaption: "caption", - TableCell: "td", - TableCol: "colgroup", - TableRow: "tr", - TableSection: "tbody", - UList: "ul" - }; - const svgConstructorTags = { - Graphics: "g", - SVG: "svg" - }; - const InstanceIdKey = Symbol(); - const CreatedKey = Symbol(); - const instances = new Map; - const mainRefs = new Map; - const winCtxs = {}; - const windowIds = new WeakMap; - const getAndSetInstanceId = (instance, instanceId) => { - if (instance) { - if (instanceId = windowIds.get(instance)) { - return instanceId; - } - (instanceId = instance[InstanceIdKey]) || setInstanceId(instance, instanceId = randomId()); - return instanceId; - } - }; - const getInstance = (winId, instanceId, win, doc, docId) => { - if ((win = winCtxs[winId]) && win.$window$) { - if (winId === instanceId) { - return win.$window$; - } - doc = win.$window$.document; - docId = instanceId.split(".").pop(); - if ("d" === docId) { - return doc; - } - if ("e" === docId) { - return doc.documentElement; - } - if ("h" === docId) { - return doc.head; - } - if ("b" === docId) { - return doc.body; - } - } - return instances.get(instanceId); - }; - const setInstanceId = (instance, instanceId, now) => { - if (instance) { - instances.set(instanceId, instance); - instance[InstanceIdKey] = instanceId; - instance[CreatedKey] = now = Date.now(); - if (now > lastCleanup + 5e3) { - instances.forEach(((storedInstance, instanceId) => { - storedInstance[CreatedKey] < lastCleanup && storedInstance.nodeType && !storedInstance.isConnected && instances.delete(instanceId); - })); - lastCleanup = now; - } - } - }; - let lastCleanup = 0; - const mainWindow = window.parent; - const docImpl = document.implementation.createHTMLDocument(); - const config = mainWindow.partytown || {}; - const libPath = (config.lib || "/~partytown/") + "debug/"; - const logMain = msg => { - console.debug.apply(console, [ "%cMain 🌎", "background: #717171; color: white; padding: 2px 3px; border-radius: 2px; font-size: 0.8em;", msg ]); - }; - const winIds = []; - const normalizedWinId = winId => { - winIds.includes(winId) || winIds.push(winId); - return winIds.indexOf(winId) + 1; - }; - const defineCustomElement = (winId, worker, ceData) => { - const Cstr = defineConstructorName(class extends winCtxs[winId].$window$.HTMLElement {}, ceData[0]); - const ceCallbackMethods = "connectedCallback,disconnectedCallback,attributeChangedCallback,adoptedCallback".split(","); - ceCallbackMethods.map((callbackMethodName => Cstr.prototype[callbackMethodName] = function(...args) { - worker.postMessage([ 15, winId, getAndSetInstanceId(this), callbackMethodName, args ]); - })); - Cstr.observedAttributes = ceData[1]; - return Cstr; - }; - const serializeForWorker = ($winId$, value, added, type, cstrName) => void 0 !== value && (type = typeof value) ? "string" === type || "number" === type || "boolean" === type || null == value ? [ 0, value ] : "function" === type ? [ 6 ] : (added = added || new Set) && Array.isArray(value) ? added.has(value) ? [ 1, [] ] : added.add(value) && [ 1, value.map((v => serializeForWorker($winId$, v, added))) ] : "object" === type ? serializedValueIsError(value) ? [ 14, { - name: value.name, - message: value.message, - stack: value.stack - } ] : "" === (cstrName = getConstructorName(value)) ? [ 2, {} ] : "Window" === cstrName ? [ 3, [ $winId$, $winId$ ] ] : "HTMLCollection" === cstrName || "NodeList" === cstrName ? [ 7, Array.from(value).map((v => serializeForWorker($winId$, v, added)[1])) ] : cstrName.endsWith("Event") ? [ 5, serializeObjectForWorker($winId$, value, added) ] : "CSSRuleList" === cstrName ? [ 12, Array.from(value).map(serializeCssRuleForWorker) ] : startsWith(cstrName, "CSS") && cstrName.endsWith("Rule") ? [ 11, serializeCssRuleForWorker(value) ] : "CSSStyleDeclaration" === cstrName ? [ 13, serializeObjectForWorker($winId$, value, added) ] : "Attr" === cstrName ? [ 10, [ value.name, value.value ] ] : value.nodeType ? [ 3, [ $winId$, getAndSetInstanceId(value), getNodeName(value) ] ] : [ 2, serializeObjectForWorker($winId$, value, added, true, true) ] : void 0 : value; - const serializeObjectForWorker = (winId, obj, added, includeFunctions, includeEmptyStrings, serializedObj, propName, propValue) => { - serializedObj = {}; - if (!added.has(obj)) { - added.add(obj); - for (propName in obj) { - if (isValidMemberName(propName)) { - propValue = "path" === propName && obj instanceof Event ? obj.composedPath() : obj[propName]; - (includeFunctions || "function" != typeof propValue) && (includeEmptyStrings || "" !== propValue) && (serializedObj[propName] = serializeForWorker(winId, propValue, added)); - } - } - } - return serializedObj; - }; - const serializeCssRuleForWorker = cssRule => { - let obj = {}; - let key; - for (key in cssRule) { - validCssRuleProps.includes(key) && (obj[key] = String(cssRule[key])); - } - return obj; - }; - const serializedValueIsError = value => value instanceof window.top.Error; - const deserializeFromWorker = (worker, serializedTransfer, serializedType, serializedValue) => { - if (serializedTransfer) { - serializedType = serializedTransfer[0]; - serializedValue = serializedTransfer[1]; - return 0 === serializedType ? serializedValue : 4 === serializedType ? deserializeRefFromWorker(worker, serializedValue) : 1 === serializedType ? serializedValue.map((v => deserializeFromWorker(worker, v))) : 3 === serializedType ? getInstance(serializedValue[0], serializedValue[1]) : 5 === serializedType ? constructEvent(deserializeObjectFromWorker(worker, serializedValue)) : 2 === serializedType ? deserializeObjectFromWorker(worker, serializedValue) : 8 === serializedType ? serializedValue : 9 === serializedType ? new window[serializedTransfer[2]](serializedValue) : void 0; - } - }; - const deserializeRefFromWorker = (worker, {$winId$: $winId$, $instanceId$: $instanceId$, $refId$: $refId$}, ref) => { - ref = mainRefs.get($refId$); - if (!ref) { - ref = function(...args) { - worker.postMessage([ 9, { - $winId$: $winId$, - $instanceId$: $instanceId$, - $refId$: $refId$, - $thisArg$: serializeForWorker($winId$, this), - $args$: serializeForWorker($winId$, args) - } ]); - }; - mainRefs.set($refId$, ref); - } - return ref; - }; - const constructEvent = eventProps => new ("detail" in eventProps ? CustomEvent : Event)(eventProps.type, eventProps); - const deserializeObjectFromWorker = (worker, serializedValue, obj, key) => { - obj = {}; - for (key in serializedValue) { - obj[key] = deserializeFromWorker(worker, serializedValue[key]); - } - return obj; - }; - const validCssRuleProps = "cssText,selectorText,href,media,namespaceURI,prefix,name,conditionText".split(","); - const mainAccessHandler = async (worker, accessReq) => { - let accessRsp = { - $msgId$: accessReq.$msgId$ - }; - let totalTasks = len(accessReq.$tasks$); - let i = 0; - let task; - let winId; - let applyPath; - let instance; - let rtnValue; - let isLast; - for (;i < totalTasks; i++) { - try { - isLast = i === totalTasks - 1; - task = accessReq.$tasks$[i]; - winId = task.$winId$; - applyPath = task.$applyPath$; - !winCtxs[winId] && winId.startsWith("f_") && await new Promise((resolve => { - let check = 0; - let callback = () => { - winCtxs[winId] || check++ > 1e3 ? resolve() : requestAnimationFrame(callback); - }; - callback(); - })); - if (1 === applyPath[0] && applyPath[1] in winCtxs[winId].$window$) { - setInstanceId(new winCtxs[winId].$window$[applyPath[1]](...deserializeFromWorker(worker, applyPath[2])), task.$instanceId$); - } else { - instance = getInstance(winId, task.$instanceId$); - if (instance) { - rtnValue = applyToInstance(worker, winId, instance, applyPath, isLast, task.$groupedGetters$); - task.$assignInstanceId$ && ("string" == typeof task.$assignInstanceId$ ? setInstanceId(rtnValue, task.$assignInstanceId$) : winCtxs[task.$assignInstanceId$.$winId$] = { - $winId$: task.$assignInstanceId$.$winId$, - $window$: { - document: rtnValue - } - }); - if (isPromise(rtnValue)) { - rtnValue = await rtnValue; - isLast && (accessRsp.$isPromise$ = true); - } - isLast && (accessRsp.$rtnValue$ = serializeForWorker(winId, rtnValue)); - } else { - accessRsp.$error$ = `Error finding instance "${task.$instanceId$}" on window ${normalizedWinId(winId)}`; - console.error(accessRsp.$error$, task); - } - } - } catch (e) { - isLast ? accessRsp.$error$ = String(e.stack || e) : console.error(e); - } - } - return accessRsp; - }; - const applyToInstance = (worker, winId, instance, applyPath, isLast, groupedGetters) => { - let i = 0; - let l = len(applyPath); - let next; - let current; - let previous; - let args; - let groupedRtnValues; - for (;i < l; i++) { - current = applyPath[i]; - next = applyPath[i + 1]; - previous = applyPath[i - 1]; - try { - if (!Array.isArray(next)) { - if ("string" == typeof current || "number" == typeof current) { - if (i + 1 === l && groupedGetters) { - groupedRtnValues = {}; - groupedGetters.map((propName => groupedRtnValues[propName] = instance[propName])); - return groupedRtnValues; - } - instance = instance[current]; - } else { - if (0 === next) { - instance[previous] = deserializeFromWorker(worker, current); - return; - } - if ("function" == typeof instance[previous]) { - args = deserializeFromWorker(worker, current); - "define" === previous && "CustomElementRegistry" === getConstructorName(instance) && (args[1] = defineCustomElement(winId, worker, args[1])); - "insertRule" === previous && args[1] > len(instance.cssRules) && (args[1] = len(instance.cssRules)); - instance = instance[previous].apply(instance, args); - if ("play" === previous) { - return Promise.resolve(); - } - } - } - } - } catch (err) { - if (isLast) { - throw err; - } - console.debug("Non-blocking setter error:", err); - } - } - return instance; - }; - const readNextScript = (worker, winCtx) => { - let $winId$ = winCtx.$winId$; - let win = winCtx.$window$; - let doc = win.document; - let scriptSelector = 'script[type="text/partytown"]:not([data-ptid]):not([data-pterror])'; - let scriptElm; - let $instanceId$; - let scriptData; - if (doc && doc.body) { - scriptElm = doc.querySelector('script[type="text/partytown"]:not([data-ptid]):not([data-pterror]):not([async]):not([defer])'); - scriptElm || (scriptElm = doc.querySelector(scriptSelector)); - if (scriptElm) { - scriptElm.dataset.ptid = $instanceId$ = getAndSetInstanceId(scriptElm, $winId$); - scriptData = { - $winId$: $winId$, - $instanceId$: $instanceId$ - }; - if (scriptElm.src) { - scriptData.$url$ = scriptElm.src; - scriptData.$orgUrl$ = scriptElm.dataset.ptsrc || scriptElm.src; - } else { - scriptData.$content$ = scriptElm.innerHTML; - } - worker.postMessage([ 7, scriptData ]); - } else { - if (!winCtx.$isInitialized$) { - winCtx.$isInitialized$ = 1; - ((worker, $winId$, win) => { - let queuedForwardCalls = win._ptf; - let forwards = (win.partytown || {}).forward || []; - let i; - let mainForwardFn; - let forwardCall = ($forward$, args) => worker.postMessage([ 10, { - $winId$: $winId$, - $forward$: $forward$, - $args$: serializeForWorker($winId$, Array.from(args)) - } ]); - win._ptf = void 0; - forwards.map((forwardProps => { - mainForwardFn = win; - forwardProps.split(".").map(((_, i, arr) => { - mainForwardFn = mainForwardFn[arr[i]] = i + 1 < len(arr) ? mainForwardFn[arr[i]] || ("push" === arr[i + 1] ? [] : {}) : (...args) => forwardCall(arr, args); - })); - })); - if (queuedForwardCalls) { - for (i = 0; i < len(queuedForwardCalls); i += 2) { - forwardCall(queuedForwardCalls[i], queuedForwardCalls[i + 1]); - } - } - })(worker, $winId$, win); - doc.dispatchEvent(new CustomEvent("pt0")); - { - const winType = win === win.top ? "top" : "iframe"; - logMain(`Executed ${winType} window ${normalizedWinId($winId$)} environment scripts in ${(performance.now() - winCtx.$startTime$).toFixed(1)}ms`); - } - } - worker.postMessage([ 8, $winId$ ]); - } - } else { - requestAnimationFrame((() => readNextScript(worker, winCtx))); - } - }; - const registerWindow = (worker, $winId$, $window$) => { - if (!windowIds.has($window$)) { - windowIds.set($window$, $winId$); - const doc = $window$.document; - const history = $window$.history; - const $parentWinId$ = windowIds.get($window$.parent); - const sendInitEnvData = () => worker.postMessage([ 5, { - $winId$: $winId$, - $parentWinId$: $parentWinId$, - $url$: doc.baseURI, - $visibilityState$: doc.visibilityState - } ]); - const pushState = history.pushState.bind(history); - const replaceState = history.replaceState.bind(history); - const onLocationChange = (type, state, newUrl, oldUrl) => { - setTimeout((() => { - worker.postMessage([ 13, { - $winId$: $winId$, - type: type, - state: state, - url: doc.baseURI, - newUrl: newUrl, - oldUrl: oldUrl - } ]); - })); - }; - history.pushState = (state, _, newUrl) => { - pushState(state, _, newUrl); - onLocationChange(0, state, null == newUrl ? void 0 : newUrl.toString()); - }; - history.replaceState = (state, _, newUrl) => { - replaceState(state, _, newUrl); - onLocationChange(1, state, null == newUrl ? void 0 : newUrl.toString()); - }; - $window$.addEventListener("popstate", (event => { - onLocationChange(2, event.state); - })); - $window$.addEventListener("hashchange", (event => { - onLocationChange(3, {}, event.newURL, event.oldURL); - })); - $window$.addEventListener("ptupdate", (() => { - readNextScript(worker, winCtxs[$winId$]); - })); - doc.addEventListener("visibilitychange", (() => worker.postMessage([ 14, $winId$, doc.visibilityState ]))); - winCtxs[$winId$] = { - $winId$: $winId$, - $window$: $window$ - }; - winCtxs[$winId$].$startTime$ = performance.now(); - { - const winType = $winId$ === $parentWinId$ ? "top" : "iframe"; - logMain(`Registered ${winType} window ${normalizedWinId($winId$)}`); - } - "complete" === doc.readyState ? sendInitEnvData() : $window$.addEventListener("load", sendInitEnvData); - } - }; - const onMessageFromWebWorker = (worker, msg, winCtx) => { - if (4 === msg[0]) { - registerWindow(worker, randomId(), mainWindow); - } else { - winCtx = winCtxs[msg[1]]; - winCtx && (7 === msg[0] ? requestAnimationFrame((() => readNextScript(worker, winCtx))) : 6 === msg[0] && ((worker, winCtx, instanceId, errorMsg, scriptElm) => { - scriptElm = winCtx.$window$.document.querySelector(`[data-ptid="${instanceId}"]`); - if (scriptElm) { - errorMsg ? scriptElm.dataset.pterror = errorMsg : scriptElm.type += "-x"; - delete scriptElm.dataset.ptid; - } - readNextScript(worker, winCtx); - })(worker, winCtx, msg[2], msg[3])); - } - }; - const readMainInterfaces = () => { - const elms = Object.getOwnPropertyNames(mainWindow).map((interfaceName => ((doc, interfaceName, r, tag) => { - r = interfaceName.match(/^(HTML|SVG)(.+)Element$/); - if (r) { - tag = r[2]; - 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); - } - })(docImpl, interfaceName))).filter((elm => elm)).map((elm => [ elm ])); - return readImplementations(elms, []); - }; - const cstrs = new Set([ "Object" ]); - const readImplementations = (impls, interfaces) => { - const cstrImpls = impls.filter((implData => implData[0])).map((implData => { - const impl = implData[0]; - const interfaceType = implData[1]; - const cstrName = getConstructorName(impl); - const CstrPrototype = mainWindow[cstrName].prototype; - return [ cstrName, CstrPrototype, impl, interfaceType ]; - })); - cstrImpls.map((([cstrName, CstrPrototype, impl, intefaceType]) => readOwnImplementation(cstrs, interfaces, cstrName, CstrPrototype, impl, intefaceType))); - return interfaces; - }; - const readImplementation = (cstrName, impl, memberName) => { - let interfaceMembers = []; - let interfaceInfo = [ cstrName, "Object", interfaceMembers ]; - for (memberName in impl) { - readImplementationMember(interfaceMembers, impl, memberName); - } - return interfaceInfo; - }; - const readOwnImplementation = (cstrs, interfaces, cstrName, CstrPrototype, impl, interfaceType) => { - if (!cstrs.has(cstrName)) { - cstrs.add(cstrName); - const SuperCstr = Object.getPrototypeOf(CstrPrototype); - const superCstrName = getConstructorName(SuperCstr); - const interfaceMembers = []; - const propDescriptors = Object.getOwnPropertyDescriptors(CstrPrototype); - readOwnImplementation(cstrs, interfaces, superCstrName, SuperCstr, impl, interfaceType); - for (const memberName in propDescriptors) { - readImplementationMember(interfaceMembers, impl, memberName); - } - interfaces.push([ cstrName, superCstrName, interfaceMembers, interfaceType, getNodeName(impl) ]); - } - }; - const readImplementationMember = (interfaceMembers, implementation, memberName, value, memberType, cstrName) => { - try { - if (isValidMemberName(memberName) && isNaN(memberName[0]) && "all" !== memberName) { - value = implementation[memberName]; - memberType = typeof value; - if ("function" === memberType) { - (String(value).includes("[native") || Object.getPrototypeOf(implementation)[memberName]) && interfaceMembers.push([ memberName, 5 ]); - } else if ("object" === memberType && null != value) { - cstrName = getConstructorName(value); - "Object" !== cstrName && self[cstrName] && interfaceMembers.push([ memberName, value.nodeType || cstrName ]); - } else { - "symbol" !== memberType && (memberName.toUpperCase() === memberName ? interfaceMembers.push([ memberName, 6, value ]) : interfaceMembers.push([ memberName, 6 ])); - } - } - } catch (e) { - console.warn(e); - } - }; - const readStorage = storageName => { - let items = []; - let i = 0; - let l = len(mainWindow[storageName]); - let key; - for (;i < l; i++) { - key = mainWindow[storageName].key(i); - items.push([ key, mainWindow[storageName].getItem(key) ]); - } - return items; - }; - const getGlobalConstructor = (mainWindow, cstrName) => void 0 !== mainWindow[cstrName] ? new mainWindow[cstrName](noop) : 0; - const addGlobalConstructorUsingPrototype = ($interfaces$, mainWindow, cstrName) => { - void 0 !== mainWindow[cstrName] && $interfaces$.push([ cstrName, "Object", Object.keys(mainWindow[cstrName].prototype).map((propName => [ propName, 6 ])), 12 ]); - }; - let worker; - (async receiveMessage => { - const sharedDataBuffer = new SharedArrayBuffer(1073741824); - const sharedData = new Int32Array(sharedDataBuffer); - return (worker, msg) => { - const msgType = msg[0]; - const accessReq = msg[1]; - if (0 === msgType) { - const initData = (() => { - const elm = docImpl.createElement("i"); - const textNode = docImpl.createTextNode(""); - const comment = docImpl.createComment(""); - const frag = docImpl.createDocumentFragment(); - const shadowRoot = docImpl.createElement("p").attachShadow({ - mode: "open" - }); - const intersectionObserver = getGlobalConstructor(mainWindow, "IntersectionObserver"); - const mutationObserver = getGlobalConstructor(mainWindow, "MutationObserver"); - const resizeObserver = getGlobalConstructor(mainWindow, "ResizeObserver"); - const perf = mainWindow.performance; - const screen = mainWindow.screen; - const impls = [ [ mainWindow.history ], [ perf ], [ perf.navigation ], [ perf.timing ], [ screen ], [ screen.orientation ], [ mainWindow.visualViewport ], [ intersectionObserver, 12 ], [ mutationObserver, 12 ], [ resizeObserver, 12 ], [ textNode ], [ comment ], [ frag ], [ shadowRoot ], [ elm ], [ elm.attributes ], [ elm.classList ], [ elm.dataset ], [ elm.style ], [ docImpl ], [ docImpl.doctype ] ]; - const initialInterfaces = [ readImplementation("Window", mainWindow), readImplementation("Node", textNode) ]; - const $config$ = JSON.stringify(config, ((k, v) => { - if ("function" == typeof v) { - v = String(v); - v.startsWith(k + "(") && (v = "function " + v); - } - return v; - })); - const initWebWorkerData = { - $config$: $config$, - $interfaces$: readImplementations(impls, initialInterfaces), - $libPath$: new URL(libPath, mainWindow.location) + "", - $origin$: origin, - $localStorage$: readStorage("localStorage"), - $sessionStorage$: readStorage("sessionStorage") - }; - addGlobalConstructorUsingPrototype(initWebWorkerData.$interfaces$, mainWindow, "IntersectionObserverEntry"); - return initWebWorkerData; - })(); - initData.$sharedDataBuffer$ = sharedDataBuffer; - worker.postMessage([ 1, initData ]); - } else { - 2 === msg[0] ? worker.postMessage([ 3, readMainInterfaces() ]) : 11 === msgType ? receiveMessage(accessReq, (accessRsp => { - const stringifiedData = JSON.stringify(accessRsp); - const stringifiedDataLength = stringifiedData.length; - for (let i = 0; i < stringifiedDataLength; i++) { - sharedData[i + 1] = stringifiedData.charCodeAt(i); - } - sharedData[0] = stringifiedDataLength; - Atomics.notify(sharedData, 0); - })) : onMessageFromWebWorker(worker, msg); - } - }; - })(((accessReq, responseCallback) => mainAccessHandler(worker, accessReq).then(responseCallback))).then((onMessageHandler => { - if (onMessageHandler) { - worker = new Worker(libPath + "partytown-ww-atomics.js?v=0.7.2", { - name: "Partytown 🎉" - }); - worker.onmessage = ev => { - const msg = ev.data; - 12 === msg[0] ? mainAccessHandler(worker, msg[1]) : onMessageHandler(worker, msg); - }; - logMain("Created Partytown web worker (0.7.2)"); - worker.onerror = ev => console.error("Web Worker Error", ev); - mainWindow.addEventListener("pt1", (ev => registerWindow(worker, getAndSetInstanceId(ev.detail.frameElement), ev.detail))); - } - })); -})(window); diff --git a/static/~partytown/debug/partytown-media.js b/static/~partytown/debug/partytown-media.js deleted file mode 100644 index fc1b533..0000000 --- a/static/~partytown/debug/partytown-media.js +++ /dev/null @@ -1,374 +0,0 @@ -/* Partytown 0.7.2 - MIT builder.io */ -(self => { - const [getter, setter, callMethod, constructGlobal, definePrototypePropertyDescriptor, randomId, WinIdKey, InstanceIdKey, ApplyPathKey] = self.$bridgeToMedia$; - delete self.$bridgeToMedia$; - const ContextKey = Symbol(); - const MediaSourceKey = Symbol(); - const ReadyStateKey = Symbol(); - const SourceBuffersKey = Symbol(); - const SourceBufferTasksKey = Symbol(); - const TimeRangesKey = Symbol(); - const EMPTY_ARRAY = []; - const defineCstr = (win, cstrName, Cstr) => win[cstrName] = defineCstrName(cstrName, Cstr); - const defineCstrName = (cstrName, Cstr) => Object.defineProperty(Cstr, "name", { - value: cstrName - }); - const initCanvas = (WorkerBase, win) => { - const HTMLCanvasDescriptorMap = { - getContext: { - value(contextType, contextAttributes) { - this[ContextKey] || (this[ContextKey] = (contextType.includes("webgl") ? createContextWebGL : createContext2D)(this, contextType, contextAttributes)); - return this[ContextKey]; - } - } - }; - const WorkerCanvasGradient = defineCstr(win, "CanvasGradient", class extends WorkerBase { - addColorStop(...args) { - callMethod(this, [ "addColorStop" ], args, 2); - } - }); - const WorkerCanvasPattern = defineCstr(win, "CanvasPattern", class extends WorkerBase { - setTransform(...args) { - callMethod(this, [ "setTransform" ], args, 2); - } - }); - const createContext2D = (canvasInstance, contextType, contextAttributes) => { - const winId = canvasInstance[WinIdKey]; - const ctxInstanceId = randomId(); - const ctxInstance = { - [WinIdKey]: winId, - [InstanceIdKey]: ctxInstanceId, - [ApplyPathKey]: [] - }; - const ctx = callMethod(canvasInstance, [ "getContext" ], [ contextType, contextAttributes ], 1, ctxInstanceId); - const ctx2dGetterMethods = "getContextAttributes,getImageData,getLineDash,getTransform,isPointInPath,isPointInStroke,measureText".split(","); - const CanvasRenderingContext2D = { - get: (target, propName) => "string" == typeof propName && propName in ctx ? "function" == typeof ctx[propName] ? (...args) => { - if (propName.startsWith("create")) { - const instanceId = randomId(); - callMethod(ctxInstance, [ propName ], args, 2, instanceId); - if ("createImageData" === propName || "createPattern" === propName) { - (api => { - console.warn(`${api} not implemented`); - })(`${propName}()`); - return { - setTransform: () => {} - }; - } - return new WorkerCanvasGradient(winId, instanceId); - } - const methodCallType = ctx2dGetterMethods.includes(propName) ? 1 : 2; - return callMethod(ctxInstance, [ propName ], args, methodCallType); - } : ctx[propName] : target[propName], - set(target, propName, value) { - if ("string" == typeof propName && propName in ctx) { - ctx[propName] !== value && "function" != typeof value && setter(ctxInstance, [ propName ], value); - ctx[propName] = value; - } else { - target[propName] = value; - } - return true; - } - }; - return new Proxy(ctx, CanvasRenderingContext2D); - }; - const createContextWebGL = (canvasInstance, contextType, contextAttributes) => { - const winId = canvasInstance[WinIdKey]; - const ctxInstanceId = randomId(); - const ctxInstance = { - [WinIdKey]: winId, - [InstanceIdKey]: ctxInstanceId, - [ApplyPathKey]: [] - }; - const ctx = callMethod(canvasInstance, [ "getContext" ], [ contextType, contextAttributes ], 1, ctxInstanceId); - const WebGLRenderingContextHandler = { - get: (target, propName) => "string" == typeof propName ? "function" != typeof ctx[propName] ? ctx[propName] : (...args) => callMethod(ctxInstance, [ propName ], args, getWebGlMethodCallType(propName)) : target[propName], - set(target, propName, value) { - if ("string" == typeof propName && propName in ctx) { - ctx[propName] !== value && "function" != typeof value && setter(ctxInstance, [ propName ], value); - ctx[propName] = value; - } else { - target[propName] = value; - } - return true; - } - }; - return new Proxy(ctx, WebGLRenderingContextHandler); - }; - const ctxWebGLGetterMethods = "checkFramebufferStatus,makeXRCompatible".split(","); - const getWebGlMethodCallType = methodName => methodName.startsWith("create") || methodName.startsWith("get") || methodName.startsWith("is") || ctxWebGLGetterMethods.includes(methodName) ? 1 : 2; - defineCstr(win, "CanvasGradient", WorkerCanvasGradient); - defineCstr(win, "CanvasPattern", WorkerCanvasPattern); - definePrototypePropertyDescriptor(win.HTMLCanvasElement, HTMLCanvasDescriptorMap); - }; - const initMedia = (WorkerBase, WorkerEventTargetProxy, env, win) => { - var _a, _b; - win.Audio = defineCstrName("HTMLAudioElement", class { - constructor(src) { - const audio = env.$createNode$("audio", randomId()); - audio.src = src; - return audio; - } - }); - const WorkerAudioTrack = class extends WorkerBase { - get enabled() { - return getter(this, [ "enabled" ]); - } - set enabled(value) { - setter(this, [ "enabled" ], value); - } - get id() { - return getter(this, [ "id" ]); - } - get kind() { - return getter(this, [ "kind" ]); - } - get label() { - return getter(this, [ "label" ]); - } - get language() { - return getter(this, [ "language" ]); - } - get sourceBuffer() { - return new WorkerSourceBuffer(this); - } - }; - const WorkerAudioTrackList = class { - constructor(mediaElm) { - const winId = mediaElm[WinIdKey]; - const instanceId = mediaElm[InstanceIdKey]; - const instance = { - addEventListener(...args) { - callMethod(mediaElm, [ "audioTracks", "addEventListener" ], args, 3); - }, - getTrackById: (...args) => callMethod(mediaElm, [ "audioTracks", "getTrackById" ], args), - get length() { - return getter(mediaElm, [ "audioTracks", "length" ]); - }, - removeEventListener(...args) { - callMethod(mediaElm, [ "audioTracks", "removeEventListener" ], args, 3); - } - }; - return new Proxy(instance, { - get: (target, propName) => "number" == typeof propName ? new WorkerAudioTrack(winId, instanceId, [ "audioTracks", propName ]) : target[propName] - }); - } - }; - const WorkerSourceBufferList = defineCstr(win, "SourceBufferList", class extends Array { - constructor(mediaSource) { - super(); - this[MediaSourceKey] = mediaSource; - } - addEventListener(...args) { - callMethod(this[MediaSourceKey], [ "sourceBuffers", "addEventListener" ], args, 3); - } - removeEventListener(...args) { - callMethod(this[MediaSourceKey], [ "sourceBuffers", "removeEventListener" ], args, 3); - } - }); - const WorkerSourceBuffer = defineCstr(win, "SourceBuffer", (_b = class extends WorkerEventTargetProxy { - constructor(mediaSource) { - super(mediaSource[WinIdKey], mediaSource[InstanceIdKey], [ "sourceBuffers" ]); - this[_a] = []; - this[MediaSourceKey] = mediaSource; - } - abort() { - const sbIndex = getSourceBufferIndex(this); - callMethod(this, [ sbIndex, "appendWindowStart" ], EMPTY_ARRAY, 1); - } - addEventListener(...args) { - const sbIndex = getSourceBufferIndex(this); - callMethod(this, [ sbIndex, "addEventListener" ], args, 3); - } - appendBuffer(buf) { - this[SourceBufferTasksKey].push([ "appendBuffer", [ buf ], buf ]); - drainSourceBufferQueue(this); - } - get appendWindowStart() { - const sbIndex = getSourceBufferIndex(this); - return getter(this, [ sbIndex, "appendWindowStart" ]); - } - set appendWindowStart(value) { - const sbIndex = getSourceBufferIndex(this); - setter(this, [ sbIndex, "appendWindowStart" ], value); - } - get appendWindowEnd() { - const sbIndex = getSourceBufferIndex(this); - return getter(this, [ sbIndex, "appendWindowEnd" ]); - } - set appendWindowEnd(value) { - const sbIndex = getSourceBufferIndex(this); - setter(this, [ sbIndex, "appendWindowEnd" ], value); - } - get buffered() { - const mediaSource = this[MediaSourceKey]; - const sbIndex = getSourceBufferIndex(this); - const timeRanges = new WorkerTimeRanges(mediaSource[WinIdKey], mediaSource[InstanceIdKey], [ "sourceBuffers", sbIndex, "buffered" ]); - return timeRanges; - } - changeType(mimeType) { - const sbIndex = getSourceBufferIndex(this); - callMethod(this, [ sbIndex, "changeType" ], [ mimeType ], 2); - } - get mode() { - const sbIndex = getSourceBufferIndex(this); - return getter(this, [ sbIndex, "mode" ]); - } - set mode(value) { - const sbIndex = getSourceBufferIndex(this); - setter(this, [ sbIndex, "mode" ], value); - } - remove(start, end) { - this[SourceBufferTasksKey].push([ "remove", [ start, end ] ]); - drainSourceBufferQueue(this); - } - removeEventListener(...args) { - const sbIndex = getSourceBufferIndex(this); - callMethod(this, [ sbIndex, "removeEventListener" ], args, 3); - } - get timestampOffset() { - const sbIndex = getSourceBufferIndex(this); - return getter(this, [ sbIndex, "timestampOffset" ]); - } - set timestampOffset(value) { - const sbIndex = getSourceBufferIndex(this); - setter(this, [ sbIndex, "timestampOffset" ], value); - } - get updating() { - const sbIndex = getSourceBufferIndex(this); - return getter(this, [ sbIndex, "updating" ]); - } - }, _a = SourceBufferTasksKey, _b)); - const WorkerTimeRanges = defineCstr(win, "TimeRanges", class extends WorkerBase { - start(...args) { - return callMethod(this, [ "start" ], args); - } - end(...args) { - return callMethod(this, [ "end" ], args); - } - get length() { - return getter(this, [ "length" ]); - } - }); - const getSourceBufferIndex = sourceBuffer => { - if (sourceBuffer) { - const mediaSource = sourceBuffer[MediaSourceKey]; - const sourceBufferList = mediaSource[SourceBuffersKey]; - return sourceBufferList.indexOf(sourceBuffer); - } - return -1; - }; - const drainSourceBufferQueue = sourceBuffer => { - if (sourceBuffer[SourceBufferTasksKey].length) { - if (!sourceBuffer.updating) { - const task = sourceBuffer[SourceBufferTasksKey].shift(); - if (task) { - const sbIndex = getSourceBufferIndex(sourceBuffer); - callMethod(sourceBuffer, [ sbIndex, task[0] ], task[1], 3, void 0, task[2]); - } - } - setTimeout((() => drainSourceBufferQueue(sourceBuffer)), 50); - } - }; - const HTMLMediaDescriptorMap = { - buffered: { - get() { - if (!this[TimeRangesKey]) { - this[TimeRangesKey] = new WorkerTimeRanges(this[WinIdKey], this[InstanceIdKey], [ "buffered" ]); - setTimeout((() => { - this[TimeRangesKey] = void 0; - }), 5e3); - } - return this[TimeRangesKey]; - } - }, - readyState: { - get() { - if (4 === this[ReadyStateKey]) { - return 4; - } - if ("number" != typeof this[ReadyStateKey]) { - this[ReadyStateKey] = getter(this, [ "readyState" ]); - setTimeout((() => { - this[ReadyStateKey] = void 0; - }), 1e3); - } - return this[ReadyStateKey]; - } - } - }; - defineCstr(win, "MediaSource", class extends WorkerEventTargetProxy { - constructor() { - super(env.$winId$); - this[SourceBuffersKey] = new WorkerSourceBufferList(this); - constructGlobal(this, "MediaSource", EMPTY_ARRAY); - } - get activeSourceBuffers() { - return []; - } - addSourceBuffer(mimeType) { - const sourceBuffer = new WorkerSourceBuffer(this); - this[SourceBuffersKey].push(sourceBuffer); - callMethod(this, [ "addSourceBuffer" ], [ mimeType ]); - return sourceBuffer; - } - clearLiveSeekableRange() { - callMethod(this, [ "clearLiveSeekableRange" ], EMPTY_ARRAY, 2); - } - get duration() { - return getter(this, [ "duration" ]); - } - set duration(value) { - setter(this, [ "duration" ], value); - } - endOfStream(endOfStreamError) { - callMethod(this, [ "endOfStream" ], [ endOfStreamError ], 3); - } - get readyState() { - return getter(this, [ "readyState" ]); - } - removeSourceBuffer(sourceBuffer) { - const index = getSourceBufferIndex(sourceBuffer); - if (index > -1) { - this[SourceBuffersKey].splice(index, 1); - callMethod(this, [ "removeSourceBuffer" ], [ index ], 1); - } - } - setLiveSeekableRange(start, end) { - callMethod(this, [ "setLiveSeekableRange" ], [ start, end ], 2); - } - get sourceBuffers() { - return this[SourceBuffersKey]; - } - static isTypeSupported(mimeType) { - if (!isStaticTypeSupported.has(mimeType)) { - const isSupported = callMethod(win, [ "MediaSource", "isTypeSupported" ], [ mimeType ]); - isStaticTypeSupported.set(mimeType, isSupported); - } - return isStaticTypeSupported.get(mimeType); - } - }); - const winURL = win.URL = defineCstrName("URL", class extends URL {}); - const hasAudioTracks = "audioTracks" in win.HTMLMediaElement.prototype; - if (hasAudioTracks) { - defineCstr(win, "AudioTrackList", WorkerAudioTrackList); - defineCstr(win, "AudioTrack", WorkerAudioTrack); - HTMLMediaDescriptorMap.audioTracks = { - get() { - return new WorkerAudioTrackList(this); - } - }; - } - definePrototypePropertyDescriptor(win.HTMLMediaElement, HTMLMediaDescriptorMap); - winURL.createObjectURL = obj => callMethod(win, [ "URL", "createObjectURL" ], [ obj ]); - winURL.revokeObjectURL = obj => callMethod(win, [ "URL", "revokeObjectURL" ], [ obj ]); - }; - const isStaticTypeSupported = new Map; - self.$bridgeFromMedia$ = (WorkerBase, WorkerEventTargetProxy, env, win, windowMediaConstructors) => { - windowMediaConstructors.map((mediaCstrName => { - delete win[mediaCstrName]; - })); - initCanvas(WorkerBase, win); - initMedia(WorkerBase, WorkerEventTargetProxy, env, win); - }; -})(self); diff --git a/static/~partytown/debug/partytown-sandbox-sw.js b/static/~partytown/debug/partytown-sandbox-sw.js deleted file mode 100644 index 69a9fa7..0000000 --- a/static/~partytown/debug/partytown-sandbox-sw.js +++ /dev/null @@ -1,546 +0,0 @@ -/* Partytown 0.7.2 - MIT builder.io */ -(window => { - const isPromise = v => "object" == typeof v && v && v.then; - const noop = () => {}; - const len = obj => obj.length; - const getConstructorName = obj => { - var _a, _b, _c; - try { - const constructorName = null === (_a = null == obj ? void 0 : obj.constructor) || void 0 === _a ? void 0 : _a.name; - if (constructorName) { - return constructorName; - } - } catch (e) {} - try { - 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; - if (zoneJsConstructorName) { - return zoneJsConstructorName; - } - } catch (e) {} - return ""; - }; - const startsWith = (str, val) => str.startsWith(val); - const isValidMemberName = memberName => !(startsWith(memberName, "webkit") || startsWith(memberName, "toJSON") || startsWith(memberName, "constructor") || startsWith(memberName, "toString") || startsWith(memberName, "_")); - const getNodeName = node => 11 === node.nodeType && node.host ? "#s" : node.nodeName; - const randomId = () => Math.round(Math.random() * Number.MAX_SAFE_INTEGER).toString(36); - const defineConstructorName = (Cstr, value) => ((obj, memberName, descriptor) => Object.defineProperty(obj, memberName, { - ...descriptor, - configurable: true - }))(Cstr, "name", { - value: value - }); - const htmlConstructorTags = { - Anchor: "a", - DList: "dl", - Image: "img", - OList: "ol", - Paragraph: "p", - Quote: "q", - TableCaption: "caption", - TableCell: "td", - TableCol: "colgroup", - TableRow: "tr", - TableSection: "tbody", - UList: "ul" - }; - const svgConstructorTags = { - Graphics: "g", - SVG: "svg" - }; - const InstanceIdKey = Symbol(); - const CreatedKey = Symbol(); - const instances = new Map; - const mainRefs = new Map; - const winCtxs = {}; - const windowIds = new WeakMap; - const getAndSetInstanceId = (instance, instanceId) => { - if (instance) { - if (instanceId = windowIds.get(instance)) { - return instanceId; - } - (instanceId = instance[InstanceIdKey]) || setInstanceId(instance, instanceId = randomId()); - return instanceId; - } - }; - const getInstance = (winId, instanceId, win, doc, docId) => { - if ((win = winCtxs[winId]) && win.$window$) { - if (winId === instanceId) { - return win.$window$; - } - doc = win.$window$.document; - docId = instanceId.split(".").pop(); - if ("d" === docId) { - return doc; - } - if ("e" === docId) { - return doc.documentElement; - } - if ("h" === docId) { - return doc.head; - } - if ("b" === docId) { - return doc.body; - } - } - return instances.get(instanceId); - }; - const setInstanceId = (instance, instanceId, now) => { - if (instance) { - instances.set(instanceId, instance); - instance[InstanceIdKey] = instanceId; - instance[CreatedKey] = now = Date.now(); - if (now > lastCleanup + 5e3) { - instances.forEach(((storedInstance, instanceId) => { - storedInstance[CreatedKey] < lastCleanup && storedInstance.nodeType && !storedInstance.isConnected && instances.delete(instanceId); - })); - lastCleanup = now; - } - } - }; - let lastCleanup = 0; - const mainWindow = window.parent; - const docImpl = document.implementation.createHTMLDocument(); - const config = mainWindow.partytown || {}; - const libPath = (config.lib || "/~partytown/") + "debug/"; - const logMain = msg => { - console.debug.apply(console, [ "%cMain 🌎", "background: #717171; color: white; padding: 2px 3px; border-radius: 2px; font-size: 0.8em;", msg ]); - }; - const winIds = []; - const normalizedWinId = winId => { - winIds.includes(winId) || winIds.push(winId); - return winIds.indexOf(winId) + 1; - }; - const defineCustomElement = (winId, worker, ceData) => { - const Cstr = defineConstructorName(class extends winCtxs[winId].$window$.HTMLElement {}, ceData[0]); - const ceCallbackMethods = "connectedCallback,disconnectedCallback,attributeChangedCallback,adoptedCallback".split(","); - ceCallbackMethods.map((callbackMethodName => Cstr.prototype[callbackMethodName] = function(...args) { - worker.postMessage([ 15, winId, getAndSetInstanceId(this), callbackMethodName, args ]); - })); - Cstr.observedAttributes = ceData[1]; - return Cstr; - }; - const serializeForWorker = ($winId$, value, added, type, cstrName) => void 0 !== value && (type = typeof value) ? "string" === type || "number" === type || "boolean" === type || null == value ? [ 0, value ] : "function" === type ? [ 6 ] : (added = added || new Set) && Array.isArray(value) ? added.has(value) ? [ 1, [] ] : added.add(value) && [ 1, value.map((v => serializeForWorker($winId$, v, added))) ] : "object" === type ? serializedValueIsError(value) ? [ 14, { - name: value.name, - message: value.message, - stack: value.stack - } ] : "" === (cstrName = getConstructorName(value)) ? [ 2, {} ] : "Window" === cstrName ? [ 3, [ $winId$, $winId$ ] ] : "HTMLCollection" === cstrName || "NodeList" === cstrName ? [ 7, Array.from(value).map((v => serializeForWorker($winId$, v, added)[1])) ] : cstrName.endsWith("Event") ? [ 5, serializeObjectForWorker($winId$, value, added) ] : "CSSRuleList" === cstrName ? [ 12, Array.from(value).map(serializeCssRuleForWorker) ] : startsWith(cstrName, "CSS") && cstrName.endsWith("Rule") ? [ 11, serializeCssRuleForWorker(value) ] : "CSSStyleDeclaration" === cstrName ? [ 13, serializeObjectForWorker($winId$, value, added) ] : "Attr" === cstrName ? [ 10, [ value.name, value.value ] ] : value.nodeType ? [ 3, [ $winId$, getAndSetInstanceId(value), getNodeName(value) ] ] : [ 2, serializeObjectForWorker($winId$, value, added, true, true) ] : void 0 : value; - const serializeObjectForWorker = (winId, obj, added, includeFunctions, includeEmptyStrings, serializedObj, propName, propValue) => { - serializedObj = {}; - if (!added.has(obj)) { - added.add(obj); - for (propName in obj) { - if (isValidMemberName(propName)) { - propValue = "path" === propName && obj instanceof Event ? obj.composedPath() : obj[propName]; - (includeFunctions || "function" != typeof propValue) && (includeEmptyStrings || "" !== propValue) && (serializedObj[propName] = serializeForWorker(winId, propValue, added)); - } - } - } - return serializedObj; - }; - const serializeCssRuleForWorker = cssRule => { - let obj = {}; - let key; - for (key in cssRule) { - validCssRuleProps.includes(key) && (obj[key] = String(cssRule[key])); - } - return obj; - }; - const serializedValueIsError = value => value instanceof window.top.Error; - const deserializeFromWorker = (worker, serializedTransfer, serializedType, serializedValue) => { - if (serializedTransfer) { - serializedType = serializedTransfer[0]; - serializedValue = serializedTransfer[1]; - return 0 === serializedType ? serializedValue : 4 === serializedType ? deserializeRefFromWorker(worker, serializedValue) : 1 === serializedType ? serializedValue.map((v => deserializeFromWorker(worker, v))) : 3 === serializedType ? getInstance(serializedValue[0], serializedValue[1]) : 5 === serializedType ? constructEvent(deserializeObjectFromWorker(worker, serializedValue)) : 2 === serializedType ? deserializeObjectFromWorker(worker, serializedValue) : 8 === serializedType ? serializedValue : 9 === serializedType ? new window[serializedTransfer[2]](serializedValue) : void 0; - } - }; - const deserializeRefFromWorker = (worker, {$winId$: $winId$, $instanceId$: $instanceId$, $refId$: $refId$}, ref) => { - ref = mainRefs.get($refId$); - if (!ref) { - ref = function(...args) { - worker.postMessage([ 9, { - $winId$: $winId$, - $instanceId$: $instanceId$, - $refId$: $refId$, - $thisArg$: serializeForWorker($winId$, this), - $args$: serializeForWorker($winId$, args) - } ]); - }; - mainRefs.set($refId$, ref); - } - return ref; - }; - const constructEvent = eventProps => new ("detail" in eventProps ? CustomEvent : Event)(eventProps.type, eventProps); - const deserializeObjectFromWorker = (worker, serializedValue, obj, key) => { - obj = {}; - for (key in serializedValue) { - obj[key] = deserializeFromWorker(worker, serializedValue[key]); - } - return obj; - }; - const validCssRuleProps = "cssText,selectorText,href,media,namespaceURI,prefix,name,conditionText".split(","); - const mainAccessHandler = async (worker, accessReq) => { - let accessRsp = { - $msgId$: accessReq.$msgId$ - }; - let totalTasks = len(accessReq.$tasks$); - let i = 0; - let task; - let winId; - let applyPath; - let instance; - let rtnValue; - let isLast; - for (;i < totalTasks; i++) { - try { - isLast = i === totalTasks - 1; - task = accessReq.$tasks$[i]; - winId = task.$winId$; - applyPath = task.$applyPath$; - !winCtxs[winId] && winId.startsWith("f_") && await new Promise((resolve => { - let check = 0; - let callback = () => { - winCtxs[winId] || check++ > 1e3 ? resolve() : requestAnimationFrame(callback); - }; - callback(); - })); - if (1 === applyPath[0] && applyPath[1] in winCtxs[winId].$window$) { - setInstanceId(new winCtxs[winId].$window$[applyPath[1]](...deserializeFromWorker(worker, applyPath[2])), task.$instanceId$); - } else { - instance = getInstance(winId, task.$instanceId$); - if (instance) { - rtnValue = applyToInstance(worker, winId, instance, applyPath, isLast, task.$groupedGetters$); - task.$assignInstanceId$ && ("string" == typeof task.$assignInstanceId$ ? setInstanceId(rtnValue, task.$assignInstanceId$) : winCtxs[task.$assignInstanceId$.$winId$] = { - $winId$: task.$assignInstanceId$.$winId$, - $window$: { - document: rtnValue - } - }); - if (isPromise(rtnValue)) { - rtnValue = await rtnValue; - isLast && (accessRsp.$isPromise$ = true); - } - isLast && (accessRsp.$rtnValue$ = serializeForWorker(winId, rtnValue)); - } else { - accessRsp.$error$ = `Error finding instance "${task.$instanceId$}" on window ${normalizedWinId(winId)}`; - console.error(accessRsp.$error$, task); - } - } - } catch (e) { - isLast ? accessRsp.$error$ = String(e.stack || e) : console.error(e); - } - } - return accessRsp; - }; - const applyToInstance = (worker, winId, instance, applyPath, isLast, groupedGetters) => { - let i = 0; - let l = len(applyPath); - let next; - let current; - let previous; - let args; - let groupedRtnValues; - for (;i < l; i++) { - current = applyPath[i]; - next = applyPath[i + 1]; - previous = applyPath[i - 1]; - try { - if (!Array.isArray(next)) { - if ("string" == typeof current || "number" == typeof current) { - if (i + 1 === l && groupedGetters) { - groupedRtnValues = {}; - groupedGetters.map((propName => groupedRtnValues[propName] = instance[propName])); - return groupedRtnValues; - } - instance = instance[current]; - } else { - if (0 === next) { - instance[previous] = deserializeFromWorker(worker, current); - return; - } - if ("function" == typeof instance[previous]) { - args = deserializeFromWorker(worker, current); - "define" === previous && "CustomElementRegistry" === getConstructorName(instance) && (args[1] = defineCustomElement(winId, worker, args[1])); - "insertRule" === previous && args[1] > len(instance.cssRules) && (args[1] = len(instance.cssRules)); - instance = instance[previous].apply(instance, args); - if ("play" === previous) { - return Promise.resolve(); - } - } - } - } - } catch (err) { - if (isLast) { - throw err; - } - console.debug("Non-blocking setter error:", err); - } - } - return instance; - }; - const readNextScript = (worker, winCtx) => { - let $winId$ = winCtx.$winId$; - let win = winCtx.$window$; - let doc = win.document; - let scriptSelector = 'script[type="text/partytown"]:not([data-ptid]):not([data-pterror])'; - let scriptElm; - let $instanceId$; - let scriptData; - if (doc && doc.body) { - scriptElm = doc.querySelector('script[type="text/partytown"]:not([data-ptid]):not([data-pterror]):not([async]):not([defer])'); - scriptElm || (scriptElm = doc.querySelector(scriptSelector)); - if (scriptElm) { - scriptElm.dataset.ptid = $instanceId$ = getAndSetInstanceId(scriptElm, $winId$); - scriptData = { - $winId$: $winId$, - $instanceId$: $instanceId$ - }; - if (scriptElm.src) { - scriptData.$url$ = scriptElm.src; - scriptData.$orgUrl$ = scriptElm.dataset.ptsrc || scriptElm.src; - } else { - scriptData.$content$ = scriptElm.innerHTML; - } - worker.postMessage([ 7, scriptData ]); - } else { - if (!winCtx.$isInitialized$) { - winCtx.$isInitialized$ = 1; - ((worker, $winId$, win) => { - let queuedForwardCalls = win._ptf; - let forwards = (win.partytown || {}).forward || []; - let i; - let mainForwardFn; - let forwardCall = ($forward$, args) => worker.postMessage([ 10, { - $winId$: $winId$, - $forward$: $forward$, - $args$: serializeForWorker($winId$, Array.from(args)) - } ]); - win._ptf = void 0; - forwards.map((forwardProps => { - mainForwardFn = win; - forwardProps.split(".").map(((_, i, arr) => { - mainForwardFn = mainForwardFn[arr[i]] = i + 1 < len(arr) ? mainForwardFn[arr[i]] || ("push" === arr[i + 1] ? [] : {}) : (...args) => forwardCall(arr, args); - })); - })); - if (queuedForwardCalls) { - for (i = 0; i < len(queuedForwardCalls); i += 2) { - forwardCall(queuedForwardCalls[i], queuedForwardCalls[i + 1]); - } - } - })(worker, $winId$, win); - doc.dispatchEvent(new CustomEvent("pt0")); - { - const winType = win === win.top ? "top" : "iframe"; - logMain(`Executed ${winType} window ${normalizedWinId($winId$)} environment scripts in ${(performance.now() - winCtx.$startTime$).toFixed(1)}ms`); - } - } - worker.postMessage([ 8, $winId$ ]); - } - } else { - requestAnimationFrame((() => readNextScript(worker, winCtx))); - } - }; - const registerWindow = (worker, $winId$, $window$) => { - if (!windowIds.has($window$)) { - windowIds.set($window$, $winId$); - const doc = $window$.document; - const history = $window$.history; - const $parentWinId$ = windowIds.get($window$.parent); - const sendInitEnvData = () => worker.postMessage([ 5, { - $winId$: $winId$, - $parentWinId$: $parentWinId$, - $url$: doc.baseURI, - $visibilityState$: doc.visibilityState - } ]); - const pushState = history.pushState.bind(history); - const replaceState = history.replaceState.bind(history); - const onLocationChange = (type, state, newUrl, oldUrl) => { - setTimeout((() => { - worker.postMessage([ 13, { - $winId$: $winId$, - type: type, - state: state, - url: doc.baseURI, - newUrl: newUrl, - oldUrl: oldUrl - } ]); - })); - }; - history.pushState = (state, _, newUrl) => { - pushState(state, _, newUrl); - onLocationChange(0, state, null == newUrl ? void 0 : newUrl.toString()); - }; - history.replaceState = (state, _, newUrl) => { - replaceState(state, _, newUrl); - onLocationChange(1, state, null == newUrl ? void 0 : newUrl.toString()); - }; - $window$.addEventListener("popstate", (event => { - onLocationChange(2, event.state); - })); - $window$.addEventListener("hashchange", (event => { - onLocationChange(3, {}, event.newURL, event.oldURL); - })); - $window$.addEventListener("ptupdate", (() => { - readNextScript(worker, winCtxs[$winId$]); - })); - doc.addEventListener("visibilitychange", (() => worker.postMessage([ 14, $winId$, doc.visibilityState ]))); - winCtxs[$winId$] = { - $winId$: $winId$, - $window$: $window$ - }; - winCtxs[$winId$].$startTime$ = performance.now(); - { - const winType = $winId$ === $parentWinId$ ? "top" : "iframe"; - logMain(`Registered ${winType} window ${normalizedWinId($winId$)}`); - } - "complete" === doc.readyState ? sendInitEnvData() : $window$.addEventListener("load", sendInitEnvData); - } - }; - const onMessageFromWebWorker = (worker, msg, winCtx) => { - if (4 === msg[0]) { - registerWindow(worker, randomId(), mainWindow); - } else { - winCtx = winCtxs[msg[1]]; - winCtx && (7 === msg[0] ? requestAnimationFrame((() => readNextScript(worker, winCtx))) : 6 === msg[0] && ((worker, winCtx, instanceId, errorMsg, scriptElm) => { - scriptElm = winCtx.$window$.document.querySelector(`[data-ptid="${instanceId}"]`); - if (scriptElm) { - errorMsg ? scriptElm.dataset.pterror = errorMsg : scriptElm.type += "-x"; - delete scriptElm.dataset.ptid; - } - readNextScript(worker, winCtx); - })(worker, winCtx, msg[2], msg[3])); - } - }; - const readMainPlatform = () => { - const elm = docImpl.createElement("i"); - const textNode = docImpl.createTextNode(""); - const comment = docImpl.createComment(""); - const frag = docImpl.createDocumentFragment(); - const shadowRoot = docImpl.createElement("p").attachShadow({ - mode: "open" - }); - const intersectionObserver = getGlobalConstructor(mainWindow, "IntersectionObserver"); - const mutationObserver = getGlobalConstructor(mainWindow, "MutationObserver"); - const resizeObserver = getGlobalConstructor(mainWindow, "ResizeObserver"); - const perf = mainWindow.performance; - const screen = mainWindow.screen; - const impls = [ [ mainWindow.history ], [ perf ], [ perf.navigation ], [ perf.timing ], [ screen ], [ screen.orientation ], [ mainWindow.visualViewport ], [ intersectionObserver, 12 ], [ mutationObserver, 12 ], [ resizeObserver, 12 ], [ textNode ], [ comment ], [ frag ], [ shadowRoot ], [ elm ], [ elm.attributes ], [ elm.classList ], [ elm.dataset ], [ elm.style ], [ docImpl ], [ docImpl.doctype ] ]; - const initialInterfaces = [ readImplementation("Window", mainWindow), readImplementation("Node", textNode) ]; - const $config$ = JSON.stringify(config, ((k, v) => { - if ("function" == typeof v) { - v = String(v); - v.startsWith(k + "(") && (v = "function " + v); - } - return v; - })); - const initWebWorkerData = { - $config$: $config$, - $interfaces$: readImplementations(impls, initialInterfaces), - $libPath$: new URL(libPath, mainWindow.location) + "", - $origin$: origin, - $localStorage$: readStorage("localStorage"), - $sessionStorage$: readStorage("sessionStorage") - }; - addGlobalConstructorUsingPrototype(initWebWorkerData.$interfaces$, mainWindow, "IntersectionObserverEntry"); - return initWebWorkerData; - }; - const readMainInterfaces = () => { - const elms = Object.getOwnPropertyNames(mainWindow).map((interfaceName => ((doc, interfaceName, r, tag) => { - r = interfaceName.match(/^(HTML|SVG)(.+)Element$/); - if (r) { - tag = r[2]; - 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); - } - })(docImpl, interfaceName))).filter((elm => elm)).map((elm => [ elm ])); - return readImplementations(elms, []); - }; - const cstrs = new Set([ "Object" ]); - const readImplementations = (impls, interfaces) => { - const cstrImpls = impls.filter((implData => implData[0])).map((implData => { - const impl = implData[0]; - const interfaceType = implData[1]; - const cstrName = getConstructorName(impl); - const CstrPrototype = mainWindow[cstrName].prototype; - return [ cstrName, CstrPrototype, impl, interfaceType ]; - })); - cstrImpls.map((([cstrName, CstrPrototype, impl, intefaceType]) => readOwnImplementation(cstrs, interfaces, cstrName, CstrPrototype, impl, intefaceType))); - return interfaces; - }; - const readImplementation = (cstrName, impl, memberName) => { - let interfaceMembers = []; - let interfaceInfo = [ cstrName, "Object", interfaceMembers ]; - for (memberName in impl) { - readImplementationMember(interfaceMembers, impl, memberName); - } - return interfaceInfo; - }; - const readOwnImplementation = (cstrs, interfaces, cstrName, CstrPrototype, impl, interfaceType) => { - if (!cstrs.has(cstrName)) { - cstrs.add(cstrName); - const SuperCstr = Object.getPrototypeOf(CstrPrototype); - const superCstrName = getConstructorName(SuperCstr); - const interfaceMembers = []; - const propDescriptors = Object.getOwnPropertyDescriptors(CstrPrototype); - readOwnImplementation(cstrs, interfaces, superCstrName, SuperCstr, impl, interfaceType); - for (const memberName in propDescriptors) { - readImplementationMember(interfaceMembers, impl, memberName); - } - interfaces.push([ cstrName, superCstrName, interfaceMembers, interfaceType, getNodeName(impl) ]); - } - }; - const readImplementationMember = (interfaceMembers, implementation, memberName, value, memberType, cstrName) => { - try { - if (isValidMemberName(memberName) && isNaN(memberName[0]) && "all" !== memberName) { - value = implementation[memberName]; - memberType = typeof value; - if ("function" === memberType) { - (String(value).includes("[native") || Object.getPrototypeOf(implementation)[memberName]) && interfaceMembers.push([ memberName, 5 ]); - } else if ("object" === memberType && null != value) { - cstrName = getConstructorName(value); - "Object" !== cstrName && self[cstrName] && interfaceMembers.push([ memberName, value.nodeType || cstrName ]); - } else { - "symbol" !== memberType && (memberName.toUpperCase() === memberName ? interfaceMembers.push([ memberName, 6, value ]) : interfaceMembers.push([ memberName, 6 ])); - } - } - } catch (e) { - console.warn(e); - } - }; - const readStorage = storageName => { - let items = []; - let i = 0; - let l = len(mainWindow[storageName]); - let key; - for (;i < l; i++) { - key = mainWindow[storageName].key(i); - items.push([ key, mainWindow[storageName].getItem(key) ]); - } - return items; - }; - const getGlobalConstructor = (mainWindow, cstrName) => void 0 !== mainWindow[cstrName] ? new mainWindow[cstrName](noop) : 0; - const addGlobalConstructorUsingPrototype = ($interfaces$, mainWindow, cstrName) => { - void 0 !== mainWindow[cstrName] && $interfaces$.push([ cstrName, "Object", Object.keys(mainWindow[cstrName].prototype).map((propName => [ propName, 6 ])), 12 ]); - }; - let worker; - (receiveMessage => { - const swContainer = window.navigator.serviceWorker; - return swContainer.getRegistration().then((swRegistration => { - swContainer.addEventListener("message", (ev => receiveMessage(ev.data, (accessRsp => swRegistration.active && swRegistration.active.postMessage(accessRsp))))); - return (worker, msg) => { - 0 === msg[0] ? worker.postMessage([ 1, readMainPlatform() ]) : 2 === msg[0] ? worker.postMessage([ 3, readMainInterfaces() ]) : onMessageFromWebWorker(worker, msg); - }; - })); - })(((accessReq, responseCallback) => mainAccessHandler(worker, accessReq).then(responseCallback))).then((onMessageHandler => { - if (onMessageHandler) { - worker = new Worker(libPath + "partytown-ww-sw.js?v=0.7.2", { - name: "Partytown 🎉" - }); - worker.onmessage = ev => { - const msg = ev.data; - 12 === msg[0] ? mainAccessHandler(worker, msg[1]) : onMessageHandler(worker, msg); - }; - logMain("Created Partytown web worker (0.7.2)"); - worker.onerror = ev => console.error("Web Worker Error", ev); - mainWindow.addEventListener("pt1", (ev => registerWindow(worker, getAndSetInstanceId(ev.detail.frameElement), ev.detail))); - } - })); -})(window); diff --git a/static/~partytown/debug/partytown-sw.js b/static/~partytown/debug/partytown-sw.js deleted file mode 100644 index 6e919fa..0000000 --- a/static/~partytown/debug/partytown-sw.js +++ /dev/null @@ -1,59 +0,0 @@ -/* Partytown 0.7.2 - MIT builder.io */ -const resolves = new Map; - -const swMessageError = (accessReq, $error$) => ({ - $msgId$: accessReq.$msgId$, - $error$: $error$ -}); - -const httpRequestFromWebWorker = req => new Promise((async resolve => { - const accessReq = await req.clone().json(); - const responseData = await (accessReq => new Promise((async resolve => { - const clients = await self.clients.matchAll(); - const client = [ ...clients ].sort(((a, b) => a.url > b.url ? -1 : a.url < b.url ? 1 : 0))[0]; - if (client) { - const timeout = 12e4; - const msgResolve = [ resolve, setTimeout((() => { - resolves.delete(accessReq.$msgId$); - resolve(swMessageError(accessReq, "Timeout")); - }), timeout) ]; - resolves.set(accessReq.$msgId$, msgResolve); - client.postMessage(accessReq); - } else { - resolve(swMessageError(accessReq, "NoParty")); - } - })))(accessReq); - resolve(response(JSON.stringify(responseData), "application/json")); -})); - -const response = (body, contentType) => new Response(body, { - headers: { - "content-type": contentType || "text/html", - "Cache-Control": "no-store" - } -}); - -self.oninstall = () => self.skipWaiting(); - -self.onactivate = () => self.clients.claim(); - -self.onmessage = ev => { - const accessRsp = ev.data; - const r = resolves.get(accessRsp.$msgId$); - if (r) { - resolves.delete(accessRsp.$msgId$); - clearTimeout(r[1]); - r[0](accessRsp); - } -}; - -self.onfetch = ev => { - const req = ev.request; - const url = new URL(req.url); - const pathname = url.pathname; - if (pathname.endsWith("sw.html")) { - ev.respondWith(response('')); - } else { - pathname.endsWith("proxytown") && ev.respondWith(httpRequestFromWebWorker(req)); - } -}; diff --git a/static/~partytown/debug/partytown-ww-atomics.js b/static/~partytown/debug/partytown-ww-atomics.js deleted file mode 100644 index 93ddea7..0000000 --- a/static/~partytown/debug/partytown-ww-atomics.js +++ /dev/null @@ -1,1811 +0,0 @@ -/* Partytown 0.7.2 - MIT builder.io */ -(self => { - const WinIdKey = Symbol(); - const InstanceIdKey = Symbol(); - const InstanceDataKey = Symbol(); - const NamespaceKey = Symbol(); - const ApplyPathKey = Symbol(); - const InstanceStateKey = Symbol(); - const HookContinue = Symbol(); - const HookPrevent = Symbol(); - const webWorkerInstances = new Map; - const webWorkerRefsByRefId = {}; - const webWorkerRefIdsByRef = new WeakMap; - const postMessages = []; - const webWorkerCtx = {}; - const webWorkerlocalStorage = new Map; - const webWorkerSessionStorage = new Map; - const environments = {}; - const cachedDimensions = new Map; - const cachedStructure = new Map; - const commaSplit = str => str.split(","); - const partytownLibUrl = url => { - url = webWorkerCtx.$libPath$ + url; - if (new URL(url).origin != location.origin) { - throw "Invalid " + url; - } - return url; - }; - const getterDimensionPropNames = commaSplit("clientWidth,clientHeight,clientTop,clientLeft,innerWidth,innerHeight,offsetWidth,offsetHeight,offsetTop,offsetLeft,outerWidth,outerHeight,pageXOffset,pageYOffset,scrollWidth,scrollHeight,scrollTop,scrollLeft"); - const elementStructurePropNames = commaSplit("childElementCount,children,firstElementChild,lastElementChild,nextElementSibling,previousElementSibling"); - const structureChangingMethodNames = commaSplit("insertBefore,remove,removeChild,replaceChild"); - const dimensionChangingSetterNames = commaSplit("className,width,height,hidden,innerHTML,innerText,textContent"); - const dimensionChangingMethodNames = commaSplit("setAttribute,setAttributeNS,setProperty"); - const eventTargetMethods = commaSplit("addEventListener,dispatchEvent,removeEventListener"); - const nonBlockingMethods = eventTargetMethods.concat(dimensionChangingMethodNames, commaSplit("add,observe,remove,unobserve")); - const IS_TAG_REG = /^[A-Z_]([A-Z0-9-]*[A-Z0-9])?$/; - const noop = () => {}; - const len = obj => obj.length; - const getConstructorName = obj => { - var _a, _b, _c; - try { - const constructorName = null === (_a = null == obj ? void 0 : obj.constructor) || void 0 === _a ? void 0 : _a.name; - if (constructorName) { - return constructorName; - } - } catch (e) {} - try { - 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; - if (zoneJsConstructorName) { - return zoneJsConstructorName; - } - } catch (e) {} - return ""; - }; - const EMPTY_ARRAY = []; - const randomId = () => Math.round(Math.random() * Number.MAX_SAFE_INTEGER).toString(36); - const defineProperty = (obj, memberName, descriptor) => Object.defineProperty(obj, memberName, { - ...descriptor, - configurable: true - }); - const defineConstructorName = (Cstr, value) => defineProperty(Cstr, "name", { - value: value - }); - const definePrototypeProperty = (Cstr, memberName, descriptor) => defineProperty(Cstr.prototype, memberName, descriptor); - const definePrototypePropertyDescriptor = (Cstr, propertyDescriptorMap) => Object.defineProperties(Cstr.prototype, propertyDescriptorMap); - const definePrototypeValue = (Cstr, memberName, value) => definePrototypeProperty(Cstr, memberName, { - value: value, - writable: true - }); - const hasInstanceStateValue = (instance, stateKey) => stateKey in instance[InstanceStateKey]; - const getInstanceStateValue = (instance, stateKey) => instance[InstanceStateKey][stateKey]; - const setInstanceStateValue = (instance, stateKey, stateValue) => instance[InstanceStateKey][stateKey] = stateValue; - const setWorkerRef = (ref, refId) => { - if (!(refId = webWorkerRefIdsByRef.get(ref))) { - webWorkerRefIdsByRef.set(ref, refId = randomId()); - webWorkerRefsByRefId[refId] = ref; - } - return refId; - }; - const getOrCreateNodeInstance = (winId, instanceId, nodeName, namespace, instance) => { - instance = webWorkerInstances.get(instanceId); - if (!instance && nodeName && environments[winId]) { - instance = environments[winId].$createNode$(nodeName, instanceId, namespace); - webWorkerInstances.set(instanceId, instance); - } - return instance; - }; - const definePrototypeNodeType = (Cstr, nodeType) => definePrototypeValue(Cstr, "nodeType", nodeType); - const cachedTreeProps = (Cstr, treeProps) => treeProps.map((propName => definePrototypeProperty(Cstr, propName, { - get() { - let cacheKey = getInstanceCacheKey(this, propName); - let result = cachedStructure.get(cacheKey); - if (!result) { - result = getter(this, [ propName ]); - cachedStructure.set(cacheKey, result); - } - return result; - } - }))); - const getInstanceCacheKey = (instance, memberName, args) => [ instance[WinIdKey], instance[InstanceIdKey], memberName, ...(args || EMPTY_ARRAY).map((arg => String(arg && arg[WinIdKey] ? arg[InstanceIdKey] : arg))) ].join("."); - const cachedProps = (Cstr, propNames) => commaSplit(propNames).map((propName => definePrototypeProperty(Cstr, propName, { - get() { - hasInstanceStateValue(this, propName) || setInstanceStateValue(this, propName, getter(this, [ propName ])); - return getInstanceStateValue(this, propName); - }, - set(val) { - getInstanceStateValue(this, propName) !== val && setter(this, [ propName ], val); - setInstanceStateValue(this, propName, val); - } - }))); - const cachedDimensionProps = Cstr => getterDimensionPropNames.map((propName => definePrototypeProperty(Cstr, propName, { - get() { - const dimension = cachedDimensions.get(getInstanceCacheKey(this, propName)); - if ("number" == typeof dimension) { - return dimension; - } - const groupedDimensions = getter(this, [ propName ], getterDimensionPropNames); - if (groupedDimensions && "object" == typeof groupedDimensions) { - Object.entries(groupedDimensions).map((([dimensionPropName, value]) => cachedDimensions.set(getInstanceCacheKey(this, dimensionPropName), value))); - return groupedDimensions[propName]; - } - return groupedDimensions; - } - }))); - const cachedDimensionMethods = (Cstr, dimensionMethodNames) => dimensionMethodNames.map((methodName => { - Cstr.prototype[methodName] = function(...args) { - let cacheKey = getInstanceCacheKey(this, methodName, args); - let dimensions = cachedDimensions.get(cacheKey); - if (!dimensions) { - dimensions = callMethod(this, [ methodName ], args); - cachedDimensions.set(cacheKey, dimensions); - } - return dimensions; - }; - })); - 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, { - $winId$: $winId$, - $instanceId$: $instanceId$, - $refId$: setWorkerRef(value) - } ] : (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; - const supportsTrustedHTML = "undefined" != typeof TrustedHTML; - const serializeObjectForMain = (winId, instanceId, obj, includeFunctions, added, serializedObj, propName, propValue) => { - serializedObj = {}; - if (!added.has(obj)) { - added.add(obj); - for (propName in obj) { - propValue = obj[propName]; - (includeFunctions || "function" != typeof propValue) && (serializedObj[propName] = serializeForMain(winId, instanceId, propValue, added)); - } - } - return serializedObj; - }; - const serializeInstanceForMain = (instance, value) => instance ? serializeForMain(instance[WinIdKey], instance[InstanceIdKey], value) : [ 0, value ]; - const deserializeFromMain = (winId, instanceId, applyPath, serializedValueTransfer, serializedType, serializedValue, obj, key) => { - if (serializedValueTransfer) { - serializedType = serializedValueTransfer[0]; - serializedValue = serializedValueTransfer[1]; - if (0 === serializedType || 11 === serializedType || 12 === serializedType) { - return serializedValue; - } - if (4 === serializedType) { - return deserializeRefFromMain(applyPath, serializedValue); - } - if (6 === serializedType) { - return winId && applyPath.length > 0 ? (...args) => callMethod(environments[winId].$window$, applyPath, args, 1) : noop; - } - if (3 === serializedType) { - return getOrCreateSerializedInstance(serializedValue); - } - if (7 === serializedType) { - return new NodeList(serializedValue.map(getOrCreateSerializedInstance)); - } - if (10 === serializedType) { - return new Attr(serializedValue); - } - if (1 === serializedType) { - return serializedValue.map((v => deserializeFromMain(winId, instanceId, applyPath, v))); - } - if (14 === serializedType) { - return new CustomError(serializedValue); - } - obj = {}; - for (key in serializedValue) { - obj[key] = deserializeFromMain(winId, instanceId, [ ...applyPath, key ], serializedValue[key]); - } - if (13 === serializedType) { - return new environments[winId].$window$.CSSStyleDeclaration(winId, instanceId, applyPath, obj); - } - if (5 === serializedType) { - if ("message" === obj.type && obj.origin) { - let postMessageKey = JSON.stringify(obj.data); - let postMessageData = postMessages.find((pm => pm.$data$ === postMessageKey)); - let env; - if (postMessageData) { - env = environments[postMessageData.$winId$]; - if (env) { - obj.source = env.$window$; - obj.origin = env.$location$.origin; - } - } - } - return new Proxy(new Event(obj.type, obj), { - get: (target, propName) => propName in obj ? obj[propName] : "function" == typeof target[String(propName)] ? noop : target[String(propName)] - }); - } - if (2 === serializedType) { - return obj; - } - } - }; - const getOrCreateSerializedInstance = ([winId, instanceId, nodeName]) => instanceId === winId && environments[winId] ? environments[winId].$window$ : getOrCreateNodeInstance(winId, instanceId, nodeName); - const deserializeRefFromMain = (applyPath, {$winId$: $winId$, $instanceId$: $instanceId$, $nodeName$: $nodeName$, $refId$: $refId$}) => { - webWorkerRefsByRefId[$refId$] || webWorkerRefIdsByRef.set(webWorkerRefsByRefId[$refId$] = function(...args) { - const instance = getOrCreateNodeInstance($winId$, $instanceId$, $nodeName$); - return callMethod(instance, applyPath, args); - }, $refId$); - return webWorkerRefsByRefId[$refId$]; - }; - class CustomError extends Error { - constructor(errorObject) { - super(errorObject.message); - this.name = errorObject.name; - this.message = errorObject.message; - this.stack = errorObject.stack; - } - } - class NodeList { - constructor(nodes) { - (this._ = nodes).map(((node, index) => this[index] = node)); - } - entries() { - return this._.entries(); - } - forEach(cb, thisArg) { - this._.map(cb, thisArg); - } - item(index) { - return this[index]; - } - keys() { - return this._.keys(); - } - get length() { - return len(this._); - } - values() { - return this._.values(); - } - [Symbol.iterator]() { - return this._[Symbol.iterator](); - } - } - const Attr = class { - constructor(serializedAttr) { - this.name = serializedAttr[0]; - this.value = serializedAttr[1]; - } - get nodeName() { - return this.name; - } - get nodeType() { - return 2; - } - }; - const warnCrossOrgin = (apiType, apiName, env) => console.warn(`Partytown unable to ${apiType} cross-origin ${apiName}: ` + env.$location$); - const logWorker = (msg, winId) => { - try { - const config = webWorkerCtx.$config$; - if (config.logStackTraces) { - const frames = (new Error).stack.split("\n"); - const i = frames.findIndex((f => f.includes("logWorker"))); - msg += "\n" + frames.slice(i + 1).join("\n"); - } - let prefix; - let color; - if (winId) { - prefix = `Worker (${normalizedWinId(winId)}) 🎉`; - color = winColor(winId); - } else { - prefix = self.name; - color = "#9844bf"; - } - if (webWorkerCtx.lastLog !== msg) { - webWorkerCtx.lastLog = msg; - console.debug.apply(console, [ `%c${prefix}`, `background: ${color}; color: white; padding: 2px 3px; border-radius: 2px; font-size: 0.8em;`, msg ]); - } - } catch (e) {} - }; - const winIds = []; - const normalizedWinId = winId => { - winIds.includes(winId) || winIds.push(winId); - return winIds.indexOf(winId) + 1; - }; - const winColor = winId => { - const colors = [ "#00309e", "#ea3655", "#eea727" ]; - const index = normalizedWinId(winId) - 1; - return colors[index] || colors[colors.length - 1]; - }; - const getTargetProp = (target, applyPath) => { - let n = ""; - if (target) { - target[InstanceIdKey]; - const cstrName = getConstructorName(target); - if ("Window" === cstrName) { - n = ""; - } else if ("string" == typeof target[InstanceDataKey]) { - let nodeName = target[InstanceDataKey]; - n = "#text" === nodeName ? "textNode." : "#comment" === nodeName ? "commentNode." : "#document" === nodeName ? "document." : "html" === nodeName ? "doctype." : nodeName.toLowerCase() + "."; - } else { - 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) + "."; - } - target[ApplyPathKey] && target[ApplyPathKey].length && (n += [ ...target[ApplyPathKey] ].join(".") + "."); - } - if (applyPath.length > 1) { - const first = applyPath.slice(0, applyPath.length - 1); - const last = applyPath[applyPath.length - 1]; - if (!isNaN(last)) { - return n + `${first.join(".")}[${last}]`; - } - } - return n + applyPath.join("."); - }; - const getLogValue = (applyPath, v) => { - const type = typeof v; - if (void 0 === v) { - return "undefined"; - } - if ("boolean" === type || "number" === type || null == v) { - return JSON.stringify(v); - } - if ("string" === type) { - return applyPath.includes("cookie") ? JSON.stringify(v.slice(0, 10) + "...") : JSON.stringify(v.length > 50 ? v.slice(0, 40) + "..." : v); - } - if (Array.isArray(v)) { - return `[${v.map(getLogValue).join(", ")}]`; - } - if ("object" === type) { - const instanceId = v[InstanceIdKey]; - const cstrName = getConstructorName(v); - if ("string" == typeof instanceId) { - if ("Window" === cstrName) { - return "window"; - } - if ("string" == typeof v[InstanceDataKey]) { - if (1 === v.nodeType) { - return `<${v[InstanceDataKey].toLowerCase()}>`; - } - if (10 === v.nodeType) { - return ``; - } - if (v.nodeType <= 11) { - return v[InstanceDataKey]; - } - } - return "¯\\_(ツ)_/¯ instance obj"; - } - 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); - } - return (v => "object" == typeof v && v && v.then)(v) ? "Promise" : "function" === type ? `ƒ() ${v.name || ""}`.trim() : `¯\\_(ツ)_/¯ ${String(v)}`.trim(); - }; - const objToString = obj => { - const s = []; - for (let key in obj) { - const value = obj[key]; - const type = typeof value; - "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)}`); - } - let str = s.join(", "); - str.length > 200 && (str = str.substring(0, 200) + ".."); - return `{ ${str} }`; - }; - const logDimensionCacheClearStyle = (target, propName) => { - (webWorkerCtx.$config$.logGetters || webWorkerCtx.$config$.logSetters) && logWorker(`Dimension cache cleared from style.${propName} setter`, target[WinIdKey]); - }; - const logDimensionCacheClearMethod = (target, methodName) => { - (webWorkerCtx.$config$.logGetters || webWorkerCtx.$config$.logCalls) && logWorker(`Dimension cache cleared from method call ${methodName}()`, target[WinIdKey]); - }; - const taskQueue = []; - const queue = (instance, $applyPath$, callType, $assignInstanceId$, $groupedGetters$, buffer) => { - if (instance[ApplyPathKey]) { - taskQueue.push({ - $winId$: instance[WinIdKey], - $instanceId$: instance[InstanceIdKey], - $applyPath$: [ ...instance[ApplyPathKey], ...$applyPath$ ], - $assignInstanceId$: $assignInstanceId$, - $groupedGetters$: $groupedGetters$ - }); - taskQueue[len(taskQueue) - 1].$debug$ = ((target, applyPath, callType) => { - let m = getTargetProp(target, applyPath); - 1 === callType ? m += " (blocking)" : 2 === callType ? m += " (non-blocking)" : 3 === callType && (m += " (non-blocking, no-side-effect)"); - return m.trim(); - })(instance, $applyPath$, callType); - buffer && 3 !== callType && console.error("buffer must be sent NonBlockingNoSideEffect"); - if (3 === callType) { - webWorkerCtx.$postMessage$([ 12, { - $msgId$: randomId(), - $tasks$: [ ...taskQueue ] - } ], buffer ? [ buffer instanceof ArrayBuffer ? buffer : buffer.buffer ] : void 0); - taskQueue.length = 0; - } else if (1 === callType) { - return sendToMain(true); - } - webWorkerCtx.$asyncMsgTimer$ = setTimeout(sendToMain, 20); - } - }; - const sendToMain = isBlocking => { - clearTimeout(webWorkerCtx.$asyncMsgTimer$); - if (len(taskQueue)) { - webWorkerCtx.$config$.logMainAccess && logWorker(`Main access, tasks sent: ${taskQueue.length}`); - const endTask = taskQueue[len(taskQueue) - 1]; - const accessReq = { - $msgId$: randomId(), - $tasks$: [ ...taskQueue ] - }; - taskQueue.length = 0; - if (isBlocking) { - const accessRsp = ((webWorkerCtx, accessReq) => { - const sharedDataBuffer = webWorkerCtx.$sharedDataBuffer$; - const sharedData = new Int32Array(sharedDataBuffer); - Atomics.store(sharedData, 0, 0); - webWorkerCtx.$postMessage$([ 11, accessReq ]); - Atomics.wait(sharedData, 0, 0); - let dataLength = Atomics.load(sharedData, 0); - let accessRespStr = ""; - let i = 0; - for (;i < dataLength; i++) { - accessRespStr += String.fromCharCode(sharedData[i + 1]); - } - return JSON.parse(accessRespStr); - })(webWorkerCtx, accessReq); - const isPromise = accessRsp.$isPromise$; - const rtnValue = deserializeFromMain(endTask.$winId$, endTask.$instanceId$, endTask.$applyPath$, accessRsp.$rtnValue$); - if (accessRsp.$error$) { - if (isPromise) { - return Promise.reject(accessRsp.$error$); - } - throw new Error(accessRsp.$error$); - } - return isPromise ? Promise.resolve(rtnValue) : rtnValue; - } - webWorkerCtx.$postMessage$([ 12, accessReq ]); - } - }; - const getter = (instance, applyPath, groupedGetters, rtnValue) => { - if (webWorkerCtx.$config$.get) { - rtnValue = webWorkerCtx.$config$.get(createHookOptions(instance, applyPath)); - if (rtnValue !== HookContinue) { - return rtnValue; - } - } - rtnValue = queue(instance, applyPath, 1, void 0, groupedGetters); - ((target, applyPath, rtnValue, restrictedToWorker = false, groupedGetters = false) => { - if (webWorkerCtx.$config$.logGetters) { - try { - const msg = `Get ${getTargetProp(target, applyPath)}, returned: ${getLogValue(applyPath, rtnValue)}${restrictedToWorker ? " (restricted to worker)" : ""}${groupedGetters ? " (grouped getter)" : ""}`; - msg.includes("Symbol(") || logWorker(msg, target[WinIdKey]); - } catch (e) {} - } - })(instance, applyPath, rtnValue, false, !!groupedGetters); - return rtnValue; - }; - const setter = (instance, applyPath, value, hookSetterValue) => { - if (webWorkerCtx.$config$.set) { - hookSetterValue = webWorkerCtx.$config$.set({ - value: value, - prevent: HookPrevent, - ...createHookOptions(instance, applyPath) - }); - if (hookSetterValue === HookPrevent) { - return; - } - hookSetterValue !== HookContinue && (value = hookSetterValue); - } - if (dimensionChangingSetterNames.some((s => applyPath.includes(s)))) { - cachedDimensions.clear(); - ((target, propName) => { - (webWorkerCtx.$config$.logGetters || webWorkerCtx.$config$.logSetters) && logWorker(`Dimension cache cleared from setter "${propName}"`, target[WinIdKey]); - })(instance, applyPath[applyPath.length - 1]); - } - applyPath = [ ...applyPath, serializeInstanceForMain(instance, value), 0 ]; - ((target, applyPath, value, restrictedToWorker = false) => { - if (webWorkerCtx.$config$.logSetters) { - try { - applyPath = applyPath.slice(0, applyPath.length - 2); - logWorker(`Set ${getTargetProp(target, applyPath)}, value: ${getLogValue(applyPath, value)}${restrictedToWorker ? " (restricted to worker)" : ""}`, target[WinIdKey]); - } catch (e) {} - } - })(instance, applyPath, value); - queue(instance, applyPath, 2); - }; - const callMethod = (instance, applyPath, args, callType, assignInstanceId, buffer, rtnValue, methodName) => { - if (webWorkerCtx.$config$.apply) { - rtnValue = webWorkerCtx.$config$.apply({ - args: args, - ...createHookOptions(instance, applyPath) - }); - if (rtnValue !== HookContinue) { - return rtnValue; - } - } - methodName = applyPath[len(applyPath) - 1]; - applyPath = [ ...applyPath, serializeInstanceForMain(instance, args) ]; - callType = callType || (nonBlockingMethods.includes(methodName) ? 2 : 1); - if ("setAttribute" === methodName && hasInstanceStateValue(instance, args[0])) { - setInstanceStateValue(instance, args[0], args[1]); - } else if (structureChangingMethodNames.includes(methodName)) { - cachedDimensions.clear(); - cachedStructure.clear(); - ((target, methodName) => { - (webWorkerCtx.$config$.logGetters || webWorkerCtx.$config$.logCalls) && logWorker(`Dimension and DOM structure cache cleared from method call ${methodName}()`, target[WinIdKey]); - })(instance, methodName); - } else if (dimensionChangingMethodNames.includes(methodName)) { - callType = 2; - cachedDimensions.clear(); - logDimensionCacheClearMethod(instance, methodName); - } - rtnValue = queue(instance, applyPath, callType, assignInstanceId, void 0, buffer); - ((target, applyPath, args, rtnValue) => { - if (webWorkerCtx.$config$.logCalls) { - try { - applyPath = applyPath.slice(0, applyPath.length - 1); - logWorker(`Call ${getTargetProp(target, applyPath)}(${args.map((v => getLogValue(applyPath, v))).join(", ")}), returned: ${getLogValue(applyPath, rtnValue)}`, target[WinIdKey]); - } catch (e) {} - } - })(instance, applyPath, args, rtnValue); - return rtnValue; - }; - const constructGlobal = (instance, cstrName, args) => { - ((target, cstrName, args) => { - if (webWorkerCtx.$config$.logCalls) { - try { - logWorker(`Construct new ${cstrName}(${args.map((v => getLogValue([], v))).join(", ")})`, target[WinIdKey]); - } catch (e) {} - } - })(instance, cstrName, args); - queue(instance, [ 1, cstrName, serializeInstanceForMain(instance, args) ], 1); - }; - const createHookOptions = (instance, applyPath) => ({ - name: applyPath.join("."), - continue: HookContinue, - nodeName: instance[InstanceDataKey], - constructor: getConstructorName(instance), - instance: instance, - window: environments[instance[WinIdKey]].$window$ - }); - const addStorageApi = (win, storageName, storages, isSameOrigin, env) => { - let getItems = items => { - items = storages.get(win.origin); - items || storages.set(win.origin, items = []); - return items; - }; - let getIndexByKey = key => getItems().findIndex((i => i[STORAGE_KEY] === key)); - let index; - let item; - let storage = { - getItem(key) { - index = getIndexByKey(key); - return index > -1 ? getItems()[index][STORAGE_VALUE] : null; - }, - setItem(key, value) { - index = getIndexByKey(key); - index > -1 ? getItems()[index][STORAGE_VALUE] = value : getItems().push([ key, value ]); - isSameOrigin ? callMethod(win, [ storageName, "setItem" ], [ key, value ], 2) : warnCrossOrgin("set", storageName, env); - }, - removeItem(key) { - index = getIndexByKey(key); - index > -1 && getItems().splice(index, 1); - isSameOrigin ? callMethod(win, [ storageName, "removeItem" ], [ key ], 2) : warnCrossOrgin("remove", storageName, env); - }, - key(index) { - item = getItems()[index]; - return item ? item[STORAGE_KEY] : null; - }, - clear() { - getItems().length = 0; - isSameOrigin ? callMethod(win, [ storageName, "clear" ], EMPTY_ARRAY, 2) : warnCrossOrgin("clear", storageName, env); - }, - get length() { - return getItems().length; - } - }; - win[storageName] = storage; - }; - const STORAGE_KEY = 0; - const STORAGE_VALUE = 1; - const createCSSStyleDeclarationCstr = (win, WorkerBase, cstrName) => { - win[cstrName] = defineConstructorName(class extends WorkerBase { - constructor(winId, instanceId, applyPath, styles) { - super(winId, instanceId, applyPath, styles || {}); - return new Proxy(this, { - get(target, propName) { - if (target[propName]) { - return target[propName]; - } - target[propName] || "string" != typeof propName || target[InstanceDataKey][propName] || (target[InstanceDataKey][propName] = getter(target, [ propName ])); - return target[InstanceDataKey][propName]; - }, - set(target, propName, propValue) { - target[InstanceDataKey][propName] = propValue; - setter(target, [ propName ], propValue); - logDimensionCacheClearStyle(target, propName); - cachedDimensions.clear(); - return true; - } - }); - } - setProperty(...args) { - this[InstanceDataKey][args[0]] = args[1]; - callMethod(this, [ "setProperty" ], args, 2); - logDimensionCacheClearStyle(this, args[0]); - cachedDimensions.clear(); - } - getPropertyValue(propName) { - return this[propName]; - } - removeProperty(propName) { - let value = this[InstanceDataKey][propName]; - callMethod(this, [ "removeProperty" ], [ propName ], 2); - logDimensionCacheClearStyle(this, propName); - cachedDimensions.clear(); - this[InstanceDataKey][propName] = void 0; - return value; - } - }, cstrName); - }; - const createCSSStyleSheetConstructor = (win, cssStyleSheetCstrName) => { - win[cssStyleSheetCstrName] = defineConstructorName(class { - constructor(ownerNode) { - this.ownerNode = ownerNode; - } - get cssRules() { - const ownerNode = this.ownerNode; - return new Proxy({}, { - get(target, propKey) { - const propName = String(propKey); - return "item" === propName ? index => getCssRule(ownerNode, index) : "length" === propName ? getCssRules(ownerNode).length : isNaN(propName) ? target[propKey] : getCssRule(ownerNode, propName); - } - }); - } - insertRule(ruleText, index) { - const cssRules = getCssRules(this.ownerNode); - index = void 0 === index ? 0 : index; - if (index >= 0 && index <= cssRules.length) { - callMethod(this.ownerNode, [ "sheet", "insertRule" ], [ ruleText, index ], 2); - cssRules.splice(index, 0, 0); - } - logDimensionCacheClearMethod(this.ownerNode, "insertRule"); - cachedDimensions.clear(); - return index; - } - deleteRule(index) { - callMethod(this.ownerNode, [ "sheet", "deleteRule" ], [ index ], 2); - getCssRules(this.ownerNode).splice(index, 1); - logDimensionCacheClearMethod(this.ownerNode, "deleteRule"); - cachedDimensions.clear(); - } - get type() { - return "text/css"; - } - }, cssStyleSheetCstrName); - const HTMLStyleDescriptorMap = { - sheet: { - get() { - return new win[cssStyleSheetCstrName](this); - } - } - }; - definePrototypePropertyDescriptor(win.HTMLStyleElement, HTMLStyleDescriptorMap); - }; - const getCssRules = (ownerNode, cssRules) => { - cssRules = getInstanceStateValue(ownerNode, 2); - if (!cssRules) { - cssRules = getter(ownerNode, [ "sheet", "cssRules" ]); - setInstanceStateValue(ownerNode, 2, cssRules); - } - return cssRules; - }; - const getCssRule = (ownerNode, index, cssRules) => { - cssRules = getCssRules(ownerNode); - 0 === cssRules[index] && (cssRules[index] = getter(ownerNode, [ "sheet", "cssRules", parseInt(index, 10) ])); - return cssRules[index]; - }; - const runScriptContent = (env, instanceId, scriptContent, winId, errorMsg) => { - try { - webWorkerCtx.$config$.logScriptExecution && logWorker(`Execute script: ${scriptContent.substring(0, 100).split("\n").map((l => l.trim())).join(" ").trim().substring(0, 60)}...`, winId); - env.$currentScriptId$ = instanceId; - run(env, scriptContent); - } catch (contentError) { - console.error(scriptContent, contentError); - errorMsg = String(contentError.stack || contentError); - } - env.$currentScriptId$ = ""; - return errorMsg; - }; - const run = (env, scriptContent, scriptUrl) => { - env.$runWindowLoadEvent$ = 1; - 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 : ""); - env.$isSameOrigin$ || (scriptContent = scriptContent.replace(/.postMessage\(/g, `.postMessage('${env.$winId$}',`)); - new Function(scriptContent).call(env.$window$); - env.$runWindowLoadEvent$ = 0; - }; - const runStateLoadHandlers = (instance, type, handlers) => { - handlers = getInstanceStateValue(instance, type); - handlers && setTimeout((() => handlers.map((cb => cb({ - type: type - }))))); - }; - const resolveToUrl = (env, url, type, baseLocation, resolvedUrl, configResolvedUrl) => { - baseLocation = env.$location$; - while (!baseLocation.host) { - env = environments[env.$parentWinId$]; - baseLocation = env.$location$; - if (env.$winId$ === env.$parentWinId$) { - break; - } - } - resolvedUrl = new URL(url || "", baseLocation); - if (type && webWorkerCtx.$config$.resolveUrl) { - configResolvedUrl = webWorkerCtx.$config$.resolveUrl(resolvedUrl, baseLocation, type); - if (configResolvedUrl) { - return configResolvedUrl; - } - } - return resolvedUrl; - }; - const resolveUrl = (env, url, type) => resolveToUrl(env, url, type) + ""; - const getPartytownScript = () => ``; - const createImageConstructor = env => class HTMLImageElement { - constructor() { - this.s = ""; - this.l = []; - this.e = []; - this.style = {}; - } - get src() { - return this.s; - } - set src(src) { - webWorkerCtx.$config$.logImageRequests && logWorker(`Image() request: ${resolveUrl(env, src, null)}`, env.$winId$); - this.s = src; - fetch(resolveUrl(env, src, null), { - mode: "no-cors", - credentials: "include", - keepalive: true - }).then((rsp => { - rsp.ok || 0 === rsp.status ? this.l.map((cb => cb({ - type: "load" - }))) : this.e.map((cb => cb({ - type: "error" - }))); - }), (() => this.e.forEach((cb => cb({ - type: "error" - }))))); - } - addEventListener(eventName, cb) { - "load" === eventName && this.l.push(cb); - "error" === eventName && this.e.push(cb); - } - get onload() { - return this.l[0]; - } - set onload(cb) { - this.l = [ cb ]; - } - get onerror() { - return this.e[0]; - } - set onerror(cb) { - this.e = [ cb ]; - } - }; - const HTMLSrcElementDescriptorMap = { - addEventListener: { - value(...args) { - const eventName = args[0]; - const callbacks = getInstanceStateValue(this, eventName) || []; - callbacks.push(args[1]); - setInstanceStateValue(this, eventName, callbacks); - } - }, - async: { - get: noop, - set: noop - }, - defer: { - get: noop, - set: noop - }, - onload: { - get() { - let callbacks = getInstanceStateValue(this, "load"); - return callbacks && callbacks[0] || null; - }, - set(cb) { - setInstanceStateValue(this, "load", cb ? [ cb ] : null); - } - }, - onerror: { - get() { - let callbacks = getInstanceStateValue(this, "error"); - return callbacks && callbacks[0] || null; - }, - set(cb) { - setInstanceStateValue(this, "error", cb ? [ cb ] : null); - } - }, - getAttribute: { - value(attrName) { - return "src" === attrName ? this.src : callMethod(this, [ "getAttribute" ], [ attrName ]); - } - }, - setAttribute: { - value(attrName, attrValue) { - scriptAttrPropNames.includes(attrName) ? this[attrName] = attrValue : callMethod(this, [ "setAttribute" ], [ attrName, attrValue ]); - } - } - }; - const scriptAttrPropNames = commaSplit("src,type"); - const patchHTMLScriptElement = (WorkerHTMLScriptElement, env) => { - const HTMLScriptDescriptorMap = { - innerHTML: innerHTMLDescriptor, - innerText: innerHTMLDescriptor, - src: { - get() { - return getInstanceStateValue(this, 4) || ""; - }, - set(url) { - const orgUrl = resolveUrl(env, url, null); - const config = webWorkerCtx.$config$; - url = resolveUrl(env, url, "script"); - setInstanceStateValue(this, 4, url); - setter(this, [ "src" ], url); - orgUrl !== url && setter(this, [ "dataset", "ptsrc" ], orgUrl); - if (this.type && config.loadScriptsOnMainThread) { - const shouldExecuteScriptViaMainThread = config.loadScriptsOnMainThread.some((scriptUrl => scriptUrl === url)); - shouldExecuteScriptViaMainThread && setter(this, [ "type" ], "text/javascript"); - } - } - }, - textContent: innerHTMLDescriptor, - type: { - get() { - return getter(this, [ "type" ]); - }, - set(type) { - if (!isScriptJsType(type)) { - setInstanceStateValue(this, 5, type); - setter(this, [ "type" ], type); - } - } - }, - ...HTMLSrcElementDescriptorMap - }; - definePrototypePropertyDescriptor(WorkerHTMLScriptElement, HTMLScriptDescriptorMap); - }; - const innerHTMLDescriptor = { - get() { - return getInstanceStateValue(this, 3) || ""; - }, - set(scriptContent) { - setInstanceStateValue(this, 3, scriptContent); - } - }; - const isScriptJsType = scriptType => !scriptType || "text/javascript" === scriptType; - const createNodeCstr = (win, env, WorkerBase) => { - const config = webWorkerCtx.$config$; - const WorkerNode = defineConstructorName(class extends WorkerBase { - appendChild(node) { - return this.insertBefore(node, null); - } - get href() {} - set href(_) {} - insertBefore(newNode, referenceNode) { - var _a, _b; - const winId = newNode[WinIdKey] = this[WinIdKey]; - const instanceId = newNode[InstanceIdKey]; - const nodeName = newNode[InstanceDataKey]; - const isScript = "SCRIPT" === nodeName; - const isIFrame = "IFRAME" === nodeName; - if (isScript) { - const scriptContent = getInstanceStateValue(newNode, 3); - const scriptType = getInstanceStateValue(newNode, 5); - if (scriptContent) { - if (isScriptJsType(scriptType)) { - const scriptId = newNode.id; - 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)); - if (loadOnMainThread) { - setter(newNode, [ "type" ], "text/javascript"); - } else { - const errorMsg = runScriptContent(env, instanceId, scriptContent, winId, ""); - const datasetType = errorMsg ? "pterror" : "ptid"; - const datasetValue = errorMsg || instanceId; - setter(newNode, [ "type" ], "text/partytown-x"); - setter(newNode, [ "dataset", datasetType ], datasetValue); - } - } - setter(newNode, [ "innerHTML" ], scriptContent); - } - } - callMethod(this, [ "insertBefore" ], [ newNode, referenceNode ], 2); - if (isIFrame) { - const src = getInstanceStateValue(newNode, 0); - if (src && src.startsWith("javascript:")) { - const scriptContent = src.split("javascript:")[1]; - runScriptContent(env, instanceId, scriptContent, winId, ""); - } - ((winId, iframe) => { - let i = 0; - let type; - let handlers; - let callback = () => { - if (environments[winId] && environments[winId].$isInitialized$ && !environments[winId].$isLoading$) { - type = getInstanceStateValue(iframe, 1) ? "error" : "load"; - handlers = getInstanceStateValue(iframe, type); - handlers && handlers.map((handler => handler({ - type: type - }))); - } else if (i++ > 2e3) { - handlers = getInstanceStateValue(iframe, "error"); - handlers && handlers.map((handler => handler({ - type: "error" - }))); - } else { - setTimeout(callback, 9); - } - }; - callback(); - })(instanceId, newNode); - } - if (isScript) { - sendToMain(true); - webWorkerCtx.$postMessage$([ 7, winId ]); - } - return newNode; - } - get nodeName() { - return "#s" === this[InstanceDataKey] ? "#document-fragment" : this[InstanceDataKey]; - } - get nodeType() { - return 3; - } - get ownerDocument() { - return env.$document$; - } - }, "Node"); - cachedTreeProps(WorkerNode, commaSplit("childNodes,firstChild,isConnected,lastChild,nextSibling,parentElement,parentNode,previousSibling")); - win.Node = WorkerNode; - }; - const htmlMedia = commaSplit("AUDIO,CANVAS,VIDEO"); - const windowMediaConstructors = commaSplit("Audio,MediaSource"); - const patchDocument = (WorkerDocument, env, isDocumentImplementation) => { - const DocumentDescriptorMap = { - body: { - get: () => env.$body$ - }, - cookie: { - get() { - if (env.$isSameOrigin$) { - return getter(this, [ "cookie" ]); - } - warnCrossOrgin("get", "cookie", env); - return ""; - }, - set(value) { - if (env.$isSameOrigin$) { - setter(this, [ "cookie" ], value); - } else { - warnCrossOrgin("set", "cookie", env); - } - } - }, - createElement: { - value(tagName) { - tagName = tagName.toUpperCase(); - if (!IS_TAG_REG.test(tagName)) { - throw tagName + " not valid"; - } - const isIframe = "IFRAME" === tagName; - const winId = this[WinIdKey]; - const instanceId = (isIframe ? "f_" : "") + randomId(); - callMethod(this, [ "createElement" ], [ tagName ], 2, instanceId); - const elm = getOrCreateNodeInstance(winId, instanceId, tagName); - if (isIframe) { - const env = createEnvironment({ - $winId$: instanceId, - $parentWinId$: winId, - $url$: "about:blank" - }, true); - env.$window$.fetch = fetch; - setter(elm, [ "srcdoc" ], getPartytownScript()); - } else if ("SCRIPT" === tagName) { - const scriptType = getInstanceStateValue(elm, 5); - isScriptJsType(scriptType) && setter(elm, [ "type" ], "text/partytown"); - } - return elm; - } - }, - createElementNS: { - value(namespace, tagName) { - const instanceId = randomId(); - const nsElm = getOrCreateNodeInstance(this[WinIdKey], instanceId, tagName, namespace); - callMethod(this, [ "createElementNS" ], [ namespace, tagName ], 2, instanceId); - return nsElm; - } - }, - createTextNode: { - value(text) { - const winId = this[WinIdKey]; - const instanceId = randomId(); - const textNode = getOrCreateNodeInstance(winId, instanceId, "#text"); - callMethod(this, [ "createTextNode" ], [ text ], 2, instanceId); - return textNode; - } - }, - createEvent: { - value: type => new Event(type) - }, - currentScript: { - get() { - return env.$currentScriptId$ ? getOrCreateNodeInstance(this[WinIdKey], env.$currentScriptId$, "SCRIPT") : null; - } - }, - defaultView: { - get: () => isDocumentImplementation ? null : env.$window$ - }, - documentElement: { - get: () => env.$documentElement$ - }, - getElementsByTagName: { - value(tagName) { - tagName = tagName.toUpperCase(); - return "BODY" === tagName ? [ env.$body$ ] : "HEAD" === tagName ? [ env.$head$ ] : callMethod(this, [ "getElementsByTagName" ], [ tagName ]); - } - }, - head: { - get: () => env.$head$ - }, - images: { - get() { - return getter(this, [ "images" ]); - } - }, - implementation: { - get() { - return { - hasFeature: () => true, - createHTMLDocument: title => { - const $winId$ = randomId(); - callMethod(this, [ "implementation", "createHTMLDocument" ], [ title ], 1, { - $winId$: $winId$ - }); - const docEnv = createEnvironment({ - $winId$: $winId$, - $parentWinId$: $winId$, - $url$: env.$location$ + "", - $visibilityState$: "hidden" - }, true, true); - return docEnv.$document$; - } - }; - } - }, - location: { - get: () => env.$location$, - set(url) { - env.$location$.href = url + ""; - } - }, - nodeType: { - value: 9 - }, - parentNode: { - value: null - }, - parentElement: { - value: null - }, - readyState: { - value: "complete" - }, - visibilityState: { - get: () => env.$visibilityState$ || "visible" - } - }; - definePrototypePropertyDescriptor(WorkerDocument, DocumentDescriptorMap); - cachedProps(WorkerDocument, "compatMode,referrer,forms"); - }; - const patchDocumentElementChild = (WokerDocumentElementChild, env) => { - const DocumentElementChildDescriptorMap = { - parentElement: { - get() { - return this.parentNode; - } - }, - parentNode: { - get: () => env.$documentElement$ - } - }; - definePrototypePropertyDescriptor(WokerDocumentElementChild, DocumentElementChildDescriptorMap); - }; - const patchElement = (WorkerElement, WorkerHTMLElement) => { - const ElementDescriptorMap = { - localName: { - get() { - return this[InstanceDataKey].toLowerCase(); - } - }, - namespaceURI: { - get() { - return this[NamespaceKey] || "http://www.w3.org/1999/xhtml"; - } - }, - nodeType: { - value: 1 - }, - tagName: { - get() { - return this[InstanceDataKey]; - } - } - }; - definePrototypePropertyDescriptor(WorkerElement, ElementDescriptorMap); - cachedTreeProps(WorkerElement, elementStructurePropNames); - cachedProps(WorkerElement, "id"); - cachedDimensionProps(WorkerHTMLElement); - cachedDimensionMethods(WorkerHTMLElement, commaSplit("getClientRects,getBoundingClientRect")); - }; - const patchHTMLAnchorElement = (WorkerHTMLAnchorElement, env) => { - const HTMLAnchorDescriptorMap = {}; - commaSplit("hash,host,hostname,href,origin,pathname,port,protocol,search").map((anchorProp => { - HTMLAnchorDescriptorMap[anchorProp] = { - get() { - let value = getInstanceStateValue(this, 4); - let href; - if ("string" != typeof value) { - href = getter(this, [ "href" ]); - setInstanceStateValue(this, 4, href); - value = new URL(href)[anchorProp]; - } - return resolveToUrl(env, value, null)[anchorProp]; - }, - set(value) { - let url; - if ("href" === anchorProp) { - if ((url => { - try { - new URL(url); - return true; - } catch (_) { - return false; - } - })(value)) { - url = new URL(value); - } else { - const baseHref = env.$location$.href; - url = resolveToUrl(env, baseHref, null); - url.href = new URL(value + "", url.href); - } - } else { - url = resolveToUrl(env, this.href, null); - url[anchorProp] = value; - } - setInstanceStateValue(this, 4, url.href); - setter(this, [ "href" ], url.href); - } - }; - })); - definePrototypePropertyDescriptor(WorkerHTMLAnchorElement, HTMLAnchorDescriptorMap); - }; - const patchHTMLIFrameElement = (WorkerHTMLIFrameElement, env) => { - const HTMLIFrameDescriptorMap = { - contentDocument: { - get() { - return getIframeEnv(this).$document$; - } - }, - contentWindow: { - get() { - return getIframeEnv(this).$window$; - } - }, - src: { - get() { - let src = getInstanceStateValue(this, 0); - if (src && src.startsWith("javascript:")) { - return src; - } - src = getIframeEnv(this).$location$.href; - return src.startsWith("about:") ? "" : src; - }, - set(src) { - if (src) { - if (src.startsWith("javascript:")) { - setInstanceStateValue(this, 0, src); - } else if (!src.startsWith("about:")) { - let xhr = new XMLHttpRequest; - let xhrStatus; - let env = getIframeEnv(this); - env.$location$.href = src = resolveUrl(env, src, "iframe"); - env.$isLoading$ = 1; - setInstanceStateValue(this, 1, void 0); - xhr.open("GET", src, false); - xhr.send(); - xhrStatus = xhr.status; - if (xhrStatus > 199 && xhrStatus < 300) { - setter(this, [ "srcdoc" ], `` + xhr.responseText.replace(/`; - const createImageConstructor = env => class HTMLImageElement { - constructor() { - this.s = ""; - this.l = []; - this.e = []; - this.style = {}; - } - get src() { - return this.s; - } - set src(src) { - webWorkerCtx.$config$.logImageRequests && logWorker(`Image() request: ${resolveUrl(env, src, null)}`, env.$winId$); - this.s = src; - fetch(resolveUrl(env, src, null), { - mode: "no-cors", - credentials: "include", - keepalive: true - }).then((rsp => { - rsp.ok || 0 === rsp.status ? this.l.map((cb => cb({ - type: "load" - }))) : this.e.map((cb => cb({ - type: "error" - }))); - }), (() => this.e.forEach((cb => cb({ - type: "error" - }))))); - } - addEventListener(eventName, cb) { - "load" === eventName && this.l.push(cb); - "error" === eventName && this.e.push(cb); - } - get onload() { - return this.l[0]; - } - set onload(cb) { - this.l = [ cb ]; - } - get onerror() { - return this.e[0]; - } - set onerror(cb) { - this.e = [ cb ]; - } - }; - const HTMLSrcElementDescriptorMap = { - addEventListener: { - value(...args) { - const eventName = args[0]; - const callbacks = getInstanceStateValue(this, eventName) || []; - callbacks.push(args[1]); - setInstanceStateValue(this, eventName, callbacks); - } - }, - async: { - get: noop, - set: noop - }, - defer: { - get: noop, - set: noop - }, - onload: { - get() { - let callbacks = getInstanceStateValue(this, "load"); - return callbacks && callbacks[0] || null; - }, - set(cb) { - setInstanceStateValue(this, "load", cb ? [ cb ] : null); - } - }, - onerror: { - get() { - let callbacks = getInstanceStateValue(this, "error"); - return callbacks && callbacks[0] || null; - }, - set(cb) { - setInstanceStateValue(this, "error", cb ? [ cb ] : null); - } - }, - getAttribute: { - value(attrName) { - return "src" === attrName ? this.src : callMethod(this, [ "getAttribute" ], [ attrName ]); - } - }, - setAttribute: { - value(attrName, attrValue) { - scriptAttrPropNames.includes(attrName) ? this[attrName] = attrValue : callMethod(this, [ "setAttribute" ], [ attrName, attrValue ]); - } - } - }; - const scriptAttrPropNames = commaSplit("src,type"); - const patchHTMLScriptElement = (WorkerHTMLScriptElement, env) => { - const HTMLScriptDescriptorMap = { - innerHTML: innerHTMLDescriptor, - innerText: innerHTMLDescriptor, - src: { - get() { - return getInstanceStateValue(this, 4) || ""; - }, - set(url) { - const orgUrl = resolveUrl(env, url, null); - const config = webWorkerCtx.$config$; - url = resolveUrl(env, url, "script"); - setInstanceStateValue(this, 4, url); - setter(this, [ "src" ], url); - orgUrl !== url && setter(this, [ "dataset", "ptsrc" ], orgUrl); - if (this.type && config.loadScriptsOnMainThread) { - const shouldExecuteScriptViaMainThread = config.loadScriptsOnMainThread.some((scriptUrl => scriptUrl === url)); - shouldExecuteScriptViaMainThread && setter(this, [ "type" ], "text/javascript"); - } - } - }, - textContent: innerHTMLDescriptor, - type: { - get() { - return getter(this, [ "type" ]); - }, - set(type) { - if (!isScriptJsType(type)) { - setInstanceStateValue(this, 5, type); - setter(this, [ "type" ], type); - } - } - }, - ...HTMLSrcElementDescriptorMap - }; - definePrototypePropertyDescriptor(WorkerHTMLScriptElement, HTMLScriptDescriptorMap); - }; - const innerHTMLDescriptor = { - get() { - return getInstanceStateValue(this, 3) || ""; - }, - set(scriptContent) { - setInstanceStateValue(this, 3, scriptContent); - } - }; - const isScriptJsType = scriptType => !scriptType || "text/javascript" === scriptType; - const createNodeCstr = (win, env, WorkerBase) => { - const config = webWorkerCtx.$config$; - const WorkerNode = defineConstructorName(class extends WorkerBase { - appendChild(node) { - return this.insertBefore(node, null); - } - get href() {} - set href(_) {} - insertBefore(newNode, referenceNode) { - var _a, _b; - const winId = newNode[WinIdKey] = this[WinIdKey]; - const instanceId = newNode[InstanceIdKey]; - const nodeName = newNode[InstanceDataKey]; - const isScript = "SCRIPT" === nodeName; - const isIFrame = "IFRAME" === nodeName; - if (isScript) { - const scriptContent = getInstanceStateValue(newNode, 3); - const scriptType = getInstanceStateValue(newNode, 5); - if (scriptContent) { - if (isScriptJsType(scriptType)) { - const scriptId = newNode.id; - 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)); - if (loadOnMainThread) { - setter(newNode, [ "type" ], "text/javascript"); - } else { - const errorMsg = runScriptContent(env, instanceId, scriptContent, winId, ""); - const datasetType = errorMsg ? "pterror" : "ptid"; - const datasetValue = errorMsg || instanceId; - setter(newNode, [ "type" ], "text/partytown-x"); - setter(newNode, [ "dataset", datasetType ], datasetValue); - } - } - setter(newNode, [ "innerHTML" ], scriptContent); - } - } - callMethod(this, [ "insertBefore" ], [ newNode, referenceNode ], 2); - if (isIFrame) { - const src = getInstanceStateValue(newNode, 0); - if (src && src.startsWith("javascript:")) { - const scriptContent = src.split("javascript:")[1]; - runScriptContent(env, instanceId, scriptContent, winId, ""); - } - ((winId, iframe) => { - let i = 0; - let type; - let handlers; - let callback = () => { - if (environments[winId] && environments[winId].$isInitialized$ && !environments[winId].$isLoading$) { - type = getInstanceStateValue(iframe, 1) ? "error" : "load"; - handlers = getInstanceStateValue(iframe, type); - handlers && handlers.map((handler => handler({ - type: type - }))); - } else if (i++ > 2e3) { - handlers = getInstanceStateValue(iframe, "error"); - handlers && handlers.map((handler => handler({ - type: "error" - }))); - } else { - setTimeout(callback, 9); - } - }; - callback(); - })(instanceId, newNode); - } - if (isScript) { - sendToMain(true); - webWorkerCtx.$postMessage$([ 7, winId ]); - } - return newNode; - } - get nodeName() { - return "#s" === this[InstanceDataKey] ? "#document-fragment" : this[InstanceDataKey]; - } - get nodeType() { - return 3; - } - get ownerDocument() { - return env.$document$; - } - }, "Node"); - cachedTreeProps(WorkerNode, commaSplit("childNodes,firstChild,isConnected,lastChild,nextSibling,parentElement,parentNode,previousSibling")); - win.Node = WorkerNode; - }; - const htmlMedia = commaSplit("AUDIO,CANVAS,VIDEO"); - const windowMediaConstructors = commaSplit("Audio,MediaSource"); - const patchDocument = (WorkerDocument, env, isDocumentImplementation) => { - const DocumentDescriptorMap = { - body: { - get: () => env.$body$ - }, - cookie: { - get() { - if (env.$isSameOrigin$) { - return getter(this, [ "cookie" ]); - } - warnCrossOrgin("get", "cookie", env); - return ""; - }, - set(value) { - if (env.$isSameOrigin$) { - setter(this, [ "cookie" ], value); - } else { - warnCrossOrgin("set", "cookie", env); - } - } - }, - createElement: { - value(tagName) { - tagName = tagName.toUpperCase(); - if (!IS_TAG_REG.test(tagName)) { - throw tagName + " not valid"; - } - const isIframe = "IFRAME" === tagName; - const winId = this[WinIdKey]; - const instanceId = (isIframe ? "f_" : "") + randomId(); - callMethod(this, [ "createElement" ], [ tagName ], 2, instanceId); - const elm = getOrCreateNodeInstance(winId, instanceId, tagName); - if (isIframe) { - const env = createEnvironment({ - $winId$: instanceId, - $parentWinId$: winId, - $url$: "about:blank" - }, true); - env.$window$.fetch = fetch; - setter(elm, [ "srcdoc" ], getPartytownScript()); - } else if ("SCRIPT" === tagName) { - const scriptType = getInstanceStateValue(elm, 5); - isScriptJsType(scriptType) && setter(elm, [ "type" ], "text/partytown"); - } - return elm; - } - }, - createElementNS: { - value(namespace, tagName) { - const instanceId = randomId(); - const nsElm = getOrCreateNodeInstance(this[WinIdKey], instanceId, tagName, namespace); - callMethod(this, [ "createElementNS" ], [ namespace, tagName ], 2, instanceId); - return nsElm; - } - }, - createTextNode: { - value(text) { - const winId = this[WinIdKey]; - const instanceId = randomId(); - const textNode = getOrCreateNodeInstance(winId, instanceId, "#text"); - callMethod(this, [ "createTextNode" ], [ text ], 2, instanceId); - return textNode; - } - }, - createEvent: { - value: type => new Event(type) - }, - currentScript: { - get() { - return env.$currentScriptId$ ? getOrCreateNodeInstance(this[WinIdKey], env.$currentScriptId$, "SCRIPT") : null; - } - }, - defaultView: { - get: () => isDocumentImplementation ? null : env.$window$ - }, - documentElement: { - get: () => env.$documentElement$ - }, - getElementsByTagName: { - value(tagName) { - tagName = tagName.toUpperCase(); - return "BODY" === tagName ? [ env.$body$ ] : "HEAD" === tagName ? [ env.$head$ ] : callMethod(this, [ "getElementsByTagName" ], [ tagName ]); - } - }, - head: { - get: () => env.$head$ - }, - images: { - get() { - return getter(this, [ "images" ]); - } - }, - implementation: { - get() { - return { - hasFeature: () => true, - createHTMLDocument: title => { - const $winId$ = randomId(); - callMethod(this, [ "implementation", "createHTMLDocument" ], [ title ], 1, { - $winId$: $winId$ - }); - const docEnv = createEnvironment({ - $winId$: $winId$, - $parentWinId$: $winId$, - $url$: env.$location$ + "", - $visibilityState$: "hidden" - }, true, true); - return docEnv.$document$; - } - }; - } - }, - location: { - get: () => env.$location$, - set(url) { - env.$location$.href = url + ""; - } - }, - nodeType: { - value: 9 - }, - parentNode: { - value: null - }, - parentElement: { - value: null - }, - readyState: { - value: "complete" - }, - visibilityState: { - get: () => env.$visibilityState$ || "visible" - } - }; - definePrototypePropertyDescriptor(WorkerDocument, DocumentDescriptorMap); - cachedProps(WorkerDocument, "compatMode,referrer,forms"); - }; - const patchDocumentElementChild = (WokerDocumentElementChild, env) => { - const DocumentElementChildDescriptorMap = { - parentElement: { - get() { - return this.parentNode; - } - }, - parentNode: { - get: () => env.$documentElement$ - } - }; - definePrototypePropertyDescriptor(WokerDocumentElementChild, DocumentElementChildDescriptorMap); - }; - const patchElement = (WorkerElement, WorkerHTMLElement) => { - const ElementDescriptorMap = { - localName: { - get() { - return this[InstanceDataKey].toLowerCase(); - } - }, - namespaceURI: { - get() { - return this[NamespaceKey] || "http://www.w3.org/1999/xhtml"; - } - }, - nodeType: { - value: 1 - }, - tagName: { - get() { - return this[InstanceDataKey]; - } - } - }; - definePrototypePropertyDescriptor(WorkerElement, ElementDescriptorMap); - cachedTreeProps(WorkerElement, elementStructurePropNames); - cachedProps(WorkerElement, "id"); - cachedDimensionProps(WorkerHTMLElement); - cachedDimensionMethods(WorkerHTMLElement, commaSplit("getClientRects,getBoundingClientRect")); - }; - const patchHTMLAnchorElement = (WorkerHTMLAnchorElement, env) => { - const HTMLAnchorDescriptorMap = {}; - commaSplit("hash,host,hostname,href,origin,pathname,port,protocol,search").map((anchorProp => { - HTMLAnchorDescriptorMap[anchorProp] = { - get() { - let value = getInstanceStateValue(this, 4); - let href; - if ("string" != typeof value) { - href = getter(this, [ "href" ]); - setInstanceStateValue(this, 4, href); - value = new URL(href)[anchorProp]; - } - return resolveToUrl(env, value, null)[anchorProp]; - }, - set(value) { - let url; - if ("href" === anchorProp) { - if ((url => { - try { - new URL(url); - return true; - } catch (_) { - return false; - } - })(value)) { - url = new URL(value); - } else { - const baseHref = env.$location$.href; - url = resolveToUrl(env, baseHref, null); - url.href = new URL(value + "", url.href); - } - } else { - url = resolveToUrl(env, this.href, null); - url[anchorProp] = value; - } - setInstanceStateValue(this, 4, url.href); - setter(this, [ "href" ], url.href); - } - }; - })); - definePrototypePropertyDescriptor(WorkerHTMLAnchorElement, HTMLAnchorDescriptorMap); - }; - const patchHTMLIFrameElement = (WorkerHTMLIFrameElement, env) => { - const HTMLIFrameDescriptorMap = { - contentDocument: { - get() { - return getIframeEnv(this).$document$; - } - }, - contentWindow: { - get() { - return getIframeEnv(this).$window$; - } - }, - src: { - get() { - let src = getInstanceStateValue(this, 0); - if (src && src.startsWith("javascript:")) { - return src; - } - src = getIframeEnv(this).$location$.href; - return src.startsWith("about:") ? "" : src; - }, - set(src) { - if (src) { - if (src.startsWith("javascript:")) { - setInstanceStateValue(this, 0, src); - } else if (!src.startsWith("about:")) { - let xhr = new XMLHttpRequest; - let xhrStatus; - let env = getIframeEnv(this); - env.$location$.href = src = resolveUrl(env, src, "iframe"); - env.$isLoading$ = 1; - setInstanceStateValue(this, 1, void 0); - xhr.open("GET", src, false); - xhr.send(); - xhrStatus = xhr.status; - if (xhrStatus > 199 && xhrStatus < 300) { - setter(this, [ "srcdoc" ], `` + xhr.responseText.replace(/')):s.endsWith("proxytown")&&n.respondWith((n=>new Promise((async i=>{const s=await n.clone().json(),o=await(r=>new Promise((async n=>{const i=[...await self.clients.matchAll()].sort(((e,t)=>e.url>t.url?-1:e.url{e.delete(r.F),n(t(r,"Timeout"))}),1e4)];e.set(r.F,s),i.postMessage(r)}else n(t(r,"NoParty"))})))(s);i(r(JSON.stringify(o),"application/json"))})))(i))}; diff --git a/static/~partytown/partytown.js b/static/~partytown/partytown.js deleted file mode 100644 index 65d6307..0000000 --- a/static/~partytown/partytown.js +++ /dev/null @@ -1,2 +0,0 @@ -/* Partytown 0.7.2 - MIT builder.io */ -!function(t,e,n,i,r,o,a,d,s,c,p,l){function u(){l||(l=1,"/"==(a=(o.lib||"/~partytown/")+(o.debug?"debug/":""))[0]&&(s=e.querySelectorAll('script[type="text/partytown"]'),i!=t?i.dispatchEvent(new CustomEvent("pt1",{detail:t})):(d=setTimeout(w,1e4),e.addEventListener("pt0",f),r?h(1):n.serviceWorker?n.serviceWorker.register(a+(o.swPath||"partytown-sw.js"),{scope:a}).then((function(t){t.active?h():t.installing&&t.installing.addEventListener("statechange",(function(t){"activated"==t.target.state&&h()}))}),console.error):w())))}function h(t){c=e.createElement(t?"script":"iframe"),t||(c.setAttribute("style","display:block;width:0;height:0;border:0;visibility:hidden"),c.setAttribute("aria-hidden",!0)),c.src=a+"partytown-"+(t?"atomics.js?v=0.7.2":"sandbox-sw.html?"+Date.now()),e.body.appendChild(c)}function w(t,n){for(f(),t=0;t