@builder.io/partytown
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -15,2 +15,11 @@ /** | ||
/** | ||
* The `resolveUrl()` hook can be used to modify the URL about to be | ||
* requested, which could be used to rewrite urls so they go through a proxy. | ||
* | ||
* @param url - The URL to be resolved. This is a URL https://developer.mozilla.org/en-US/docs/Web/API/URL, not a string. | ||
* @param location - The current window location. | ||
* @returns The returned value must be a URL interface, otherwise the default resolved URL is used. | ||
*/ | ||
resolveUrl?(url: URL, location: Location): URL | undefined | null; | ||
/** | ||
* When set to `true`, Partytown scripts are not inlined and not minified. | ||
@@ -17,0 +26,0 @@ */ |
@@ -6,4 +6,4 @@ { | ||
"types": "index.d.ts", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"private": true | ||
} |
@@ -0,1 +1,3 @@ | ||
const isPromise = v => "object" == typeof v && v && v.then; | ||
const noop = () => !0; | ||
@@ -30,2 +32,6 @@ | ||
const instances = []; | ||
const mainRefs = new Map; | ||
const winCtxs = {}; | ||
@@ -58,4 +64,13 @@ | ||
const getInstance = (winId, instanceId, instanceItem) => { | ||
const win = winCtxs[winId].$window$; | ||
const doc = win.document; | ||
return 0 === instanceId ? win : 1 === instanceId ? doc : 2 === instanceId ? doc.documentElement : 3 === instanceId ? doc.head : 4 === instanceId ? doc.body : (instanceItem = instances.find((i => i[0] === instanceId))) ? instanceItem[1] : void 0; | ||
}; | ||
const setInstanceId = (instance, instanceId) => { | ||
instance && instanceIds.set(instance, instanceId); | ||
if (instance) { | ||
instances.push([ instanceId, instance ]); | ||
instanceIds.set(instance, instanceId); | ||
} | ||
}; | ||
@@ -115,4 +130,120 @@ | ||
const deserializeFromWorker = (worker, serializedTransfer, serializedType, serializedValue) => { | ||
if (serializedTransfer) { | ||
serializedType = serializedTransfer[0]; | ||
serializedValue = serializedTransfer[1]; | ||
if (9 === serializedType) { | ||
return serializedValue; | ||
} | ||
if (10 === serializedType) { | ||
return deserializeRefFromWorker(worker, serializedValue); | ||
} | ||
if (0 === serializedType) { | ||
return serializedValue.map((v => deserializeFromWorker(worker, v))); | ||
} | ||
if (6 === serializedType) { | ||
return getInstance(serializedValue.$winId$, serializedValue.$instanceId$); | ||
} | ||
if (4 === serializedType) { | ||
return constructEvent(deserializeObjectFromWorker(worker, serializedValue)); | ||
} | ||
if (8 === serializedType) { | ||
return deserializeObjectFromWorker(worker, serializedValue); | ||
} | ||
} | ||
}; | ||
const deserializeRefFromWorker = (worker, {$winId$: $winId$, $instanceId$: $instanceId$, $refId$: $refId$}) => { | ||
let ref = mainRefs.get($refId$); | ||
if (!ref) { | ||
ref = function(...args) { | ||
const refHandlerData = { | ||
$instanceId$: $instanceId$, | ||
$refId$: $refId$, | ||
$thisArg$: serializeForWorker($winId$, this), | ||
$args$: serializeForWorker($winId$, args) | ||
}; | ||
worker.postMessage([ 7, refHandlerData ]); | ||
}; | ||
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 applyToInstance = (worker, instance, applyPath, groupedGetters) => { | ||
let i = 0; | ||
let l = len(applyPath); | ||
let next; | ||
let current; | ||
let previous; | ||
let args; | ||
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) { | ||
const 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); | ||
"insertRule" === previous && args[1] > len(instance.cssRules) && (args[1] = len(instance.cssRules)); | ||
instance = instance[previous].apply(instance, args); | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
console.warn(err); | ||
} | ||
} | ||
return instance; | ||
}; | ||
const registerWindow = (worker, $winId$, $window$) => { | ||
if (!windowIds.has($window$)) { | ||
windowIds.set($window$, $winId$); | ||
const doc = $window$.document; | ||
const $url$ = doc.baseURI; | ||
const envData = { | ||
$winId$: $winId$, | ||
$parentWinId$: windowIds.get($window$.parent), | ||
$url$: $url$ | ||
}; | ||
const sendInitEnvData = () => worker.postMessage([ 3, envData ]); | ||
winCtxs[$winId$] = { | ||
$winId$: $winId$, | ||
$window$: $window$, | ||
$url$: $url$ | ||
}; | ||
winCtxs[$winId$].$startTime$ = performance.now(); | ||
{ | ||
const winType = envData.$winId$ === envData.$parentWinId$ ? "top" : "iframe"; | ||
logMain(`Registered ${winType} window ${normalizedWinId($winId$)} (${$winId$})`); | ||
} | ||
"complete" === doc.readyState ? sendInitEnvData() : $window$.addEventListener("load", sendInitEnvData); | ||
} | ||
}; | ||
const readNextScript = (worker, winCtx) => { | ||
@@ -162,40 +293,2 @@ let $winId$ = winCtx.$winId$; | ||
const readMainPlatform = win => { | ||
const doc = win.document; | ||
const $config$ = win.partytown || {}; | ||
const $libPath$ = ($config$.lib || "/~partytown/") + "debug/"; | ||
return { | ||
$config$: $config$, | ||
$libPath$: new URL($libPath$, win.location) + "", | ||
$interfaces$: readMainInterfaces(win, doc) | ||
}; | ||
}; | ||
const readMainInterfaces = (win, doc) => { | ||
const startTime = performance.now(); | ||
const docImpl = doc.implementation.createHTMLDocument(); | ||
const textNode = docImpl.createTextNode(""); | ||
const comment = docImpl.createComment(""); | ||
const frag = docImpl.createDocumentFragment(); | ||
const elm = docImpl.createElement("i"); | ||
const svg = docImpl.createElementNS("http://www.w3.org/2000/svg", "svg"); | ||
const canvasRenderingContext2D = docImpl.createElement("canvas").getContext("2d"); | ||
const mutationObserver = new MutationObserver(noop); | ||
const resizeObserver = new ResizeObserver(noop); | ||
const elms = Object.getOwnPropertyNames(win).filter((c => /^HTML.+Element$/.test(c))).map((htmlCstrName => { | ||
const htmlTagName = getHtmlTagNameFromConstructor(htmlCstrName); | ||
return [ docImpl.createElement(htmlTagName) ]; | ||
})); | ||
const impls = [ [ win.localStorage ], [ win.history ], [ win.screen ], [ win.screen.orientation ], [ mutationObserver, 12 ], [ resizeObserver, 12 ], [ textNode ], [ comment ], [ frag ], [ elm ], [ elm.attributes ], [ elm.classList ], [ elm.dataset ], [ elm.style ], [ svg ], [ docImpl ], [ docImpl.doctype ], [ canvasRenderingContext2D ], ...elms ].filter((implData => implData[0])).map((implData => { | ||
const impl = implData[0]; | ||
const interfaceType = implData[1]; | ||
const cstrName = impl.constructor.name; | ||
return [ cstrName, win[cstrName].prototype, impl, interfaceType ]; | ||
})); | ||
const interfaces = [ readImplentation("Window", win), readImplentation("Node", textNode) ]; | ||
impls.map((([cstrName, CstrPrototype, impl, intefaceType]) => readOwnImplentation(interfaces, cstrName, CstrPrototype, impl, intefaceType))); | ||
logMain(`Read ${interfaces.length} interfaces in ${(performance.now() - startTime).toFixed(1)}ms`); | ||
return interfaces; | ||
}; | ||
const readImplentation = (cstrName, impl) => { | ||
@@ -249,35 +342,9 @@ const interfaceMembers = []; | ||
const registerWindow = (worker, $winId$, $window$) => { | ||
if (!windowIds.has($window$)) { | ||
windowIds.set($window$, $winId$); | ||
const doc = $window$.document; | ||
const $url$ = doc.baseURI; | ||
const envData = { | ||
$winId$: $winId$, | ||
$parentWinId$: windowIds.get($window$.parent), | ||
$url$: $url$ | ||
}; | ||
const sendInitEnvData = () => worker.postMessage([ 3, envData ]); | ||
winCtxs[$winId$] = { | ||
$winId$: $winId$, | ||
$window$: $window$, | ||
$url$: $url$ | ||
}; | ||
winCtxs[$winId$].$startTime$ = performance.now(); | ||
{ | ||
const winType = envData.$winId$ === envData.$parentWinId$ ? "top" : "iframe"; | ||
logMain(`Registered ${winType} window ${normalizedWinId($winId$)} (${$winId$})`); | ||
} | ||
"complete" === doc.readyState ? sendInitEnvData() : $window$.addEventListener("load", sendInitEnvData); | ||
} | ||
}; | ||
const onMessageFromWebWorker = (worker, mainWindow, msg) => { | ||
const msgType = msg[0]; | ||
if (0 === msgType) { | ||
worker.postMessage([ 1, readMainPlatform(mainWindow) ]); | ||
} else if (2 === msgType) { | ||
if (2 === msgType) { | ||
registerWindow(worker, randomId(), mainWindow); | ||
} else { | ||
const winCtx = winCtxs[msg[1]]; | ||
const winId = msg[1]; | ||
const winCtx = winCtxs[winId]; | ||
winCtx && (6 === msgType ? readNextScript(worker, winCtx) : 5 === msgType && ((worker, winCtx, instanceId, errorMsg, script) => { | ||
@@ -290,14 +357,111 @@ (script = winCtx.$window$.document.querySelector(`[data-ptid="${instanceId}"]`)) && (errorMsg ? script.dataset.pterror = errorMsg : script.type += "-x"); | ||
const createMessengerAtomics = async (sandboxWindow, receiveMessage) => { | ||
const sharedDataBuffer = new SharedArrayBuffer(1073741824); | ||
const sharedData = new Int32Array(sharedDataBuffer); | ||
return (worker, mainWindow, msg) => { | ||
const msgType = msg[0]; | ||
if (0 === msgType) { | ||
const initData = (win => { | ||
const startTime = performance.now(); | ||
const docImpl = win.document.implementation.createHTMLDocument(); | ||
const textNode = docImpl.createTextNode(""); | ||
const comment = docImpl.createComment(""); | ||
const frag = docImpl.createDocumentFragment(); | ||
const elm = docImpl.createElement("i"); | ||
const svg = docImpl.createElementNS("http://www.w3.org/2000/svg", "svg"); | ||
const canvasRenderingContext2D = docImpl.createElement("canvas").getContext("2d"); | ||
const mutationObserver = new MutationObserver(noop); | ||
const resizeObserver = new ResizeObserver(noop); | ||
const elms = Object.getOwnPropertyNames(win).filter((c => /^HTML.+Element$/.test(c))).map((htmlCstrName => { | ||
const htmlTagName = getHtmlTagNameFromConstructor(htmlCstrName); | ||
return [ docImpl.createElement(htmlTagName) ]; | ||
})); | ||
const impls = [ [ win.localStorage ], [ win.history ], [ win.screen ], [ win.screen.orientation ], [ mutationObserver, 12 ], [ resizeObserver, 12 ], [ textNode ], [ comment ], [ frag ], [ elm ], [ elm.attributes ], [ elm.classList ], [ elm.dataset ], [ elm.style ], [ svg ], [ docImpl ], [ docImpl.doctype ], [ canvasRenderingContext2D ], ...elms ].filter((implData => implData[0])).map((implData => { | ||
const impl = implData[0]; | ||
const interfaceType = implData[1]; | ||
const cstrName = impl.constructor.name; | ||
return [ cstrName, win[cstrName].prototype, impl, interfaceType ]; | ||
})); | ||
const $interfaces$ = [ readImplentation("Window", win), readImplentation("Node", textNode) ]; | ||
const config = win.partytown || {}; | ||
const libPath = (config.lib || "/~partytown/") + "debug/"; | ||
const initWebWorkerData = { | ||
$config$: JSON.stringify(config, ((_, v) => "function" == typeof v ? String(v) : v)), | ||
$libPath$: new URL(libPath, win.location) + "", | ||
$interfaces$: $interfaces$ | ||
}; | ||
impls.map((([cstrName, CstrPrototype, impl, intefaceType]) => readOwnImplentation($interfaces$, cstrName, CstrPrototype, impl, intefaceType))); | ||
logMain(`Read ${$interfaces$.length} interfaces in ${(performance.now() - startTime).toFixed(1)}ms`); | ||
return initWebWorkerData; | ||
})(mainWindow); | ||
initData.$sharedDataBuffer$ = sharedDataBuffer; | ||
worker.postMessage([ 1, initData ]); | ||
} else if (9 === msgType) { | ||
const accessReq = msg[1]; | ||
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); | ||
})); | ||
} else { | ||
onMessageFromWebWorker(worker, mainWindow, msg); | ||
} | ||
}; | ||
}; | ||
(async sandboxWindow => { | ||
let worker; | ||
const mainWindow = sandboxWindow.parent; | ||
const success = await (async (sandboxWindow, _receiveMessage) => { | ||
console.log("ATOMICS ⚛️", sandboxWindow.location.href); | ||
return !0; | ||
})(sandboxWindow); | ||
if (success) { | ||
const onMessageHandler = await createMessengerAtomics(0, ((accessReq, responseCallback) => (async (worker, accessReq) => { | ||
const accessRsp = { | ||
$msgId$: accessReq.$msgId$ | ||
}; | ||
const totalTasks = len(accessReq.$tasks$); | ||
for (let i = 0; i < totalTasks; i++) { | ||
try { | ||
let task = accessReq.$tasks$[i]; | ||
let winId = task.$winId$; | ||
let instanceId = task.$instanceId$; | ||
let applyPath = task.$applyPath$; | ||
let instance; | ||
let rtnValue; | ||
winCtxs[winId] || await new Promise((resolve => { | ||
let i = 0; | ||
let callback = () => { | ||
winCtxs[winId] || i++ > 999 ? resolve() : setTimeout(callback, 9); | ||
}; | ||
callback(); | ||
})); | ||
if (1 === applyPath[0] && applyPath[1] in winCtxs[winId].$window$) { | ||
const constructedInstance = new winCtxs[winId].$window$[applyPath[1]](...deserializeFromWorker(worker, applyPath[2])); | ||
setInstanceId(constructedInstance, instanceId); | ||
} else { | ||
instance = getInstance(winId, instanceId); | ||
if (instance) { | ||
rtnValue = applyToInstance(worker, instance, applyPath, task.$groupedGetters$); | ||
task.$assignInstanceId$ && setInstanceId(rtnValue, task.$assignInstanceId$); | ||
if (isPromise(rtnValue)) { | ||
rtnValue = await rtnValue; | ||
accessRsp.$isPromise$ = !0; | ||
} | ||
accessRsp.$rtnValue$ = serializeForWorker(winId, rtnValue); | ||
} else { | ||
accessRsp.$error$ = instanceId + " not found"; | ||
} | ||
} | ||
} catch (e) { | ||
i === totalTasks - 1 ? accessRsp.$error$ = String(e.stack || e) : console.error(e); | ||
} | ||
} | ||
return accessRsp; | ||
})(worker, accessReq).then(responseCallback))); | ||
if (onMessageHandler) { | ||
worker = new Worker("./partytown-ww-atomics.js", { | ||
name: "Partytown 🎉" | ||
}); | ||
worker.onmessage = ev => onMessageFromWebWorker(worker, mainWindow, ev.data); | ||
worker.onmessage = ev => onMessageHandler(worker, mainWindow, ev.data); | ||
logMain("Created web worker"); | ||
@@ -304,0 +468,0 @@ worker.onerror = ev => console.error("Web Worker Error", ev); |
@@ -166,21 +166,25 @@ (window => { | ||
previous = applyPath[i - 1]; | ||
if (!Array.isArray(next)) { | ||
if ("string" == typeof current || "number" == typeof current) { | ||
if (i + 1 === l && groupedGetters) { | ||
const groupedRtnValues = {}; | ||
groupedGetters.map((propName => groupedRtnValues[propName] = instance[propName])); | ||
return groupedRtnValues; | ||
try { | ||
if (!Array.isArray(next)) { | ||
if ("string" == typeof current || "number" == typeof current) { | ||
if (i + 1 === l && groupedGetters) { | ||
const 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); | ||
"insertRule" === previous && args[1] > len(instance.cssRules) && (args[1] = len(instance.cssRules)); | ||
instance = instance[previous].apply(instance, args); | ||
} | ||
} | ||
instance = instance[current]; | ||
} else { | ||
if (0 === next) { | ||
instance[previous] = deserializeFromWorker(worker, current); | ||
return; | ||
} | ||
if ("function" == typeof instance[previous]) { | ||
args = deserializeFromWorker(worker, current); | ||
"insertRule" === previous && args[1] > len(instance.cssRules) && (args[1] = len(instance.cssRules)); | ||
instance = instance[previous].apply(instance, args); | ||
} | ||
} | ||
} catch (err) { | ||
console.warn(err); | ||
} | ||
@@ -190,2 +194,26 @@ } | ||
}; | ||
const registerWindow = (worker, $winId$, $window$) => { | ||
if (!windowIds.has($window$)) { | ||
windowIds.set($window$, $winId$); | ||
const doc = $window$.document; | ||
const $url$ = doc.baseURI; | ||
const envData = { | ||
$winId$: $winId$, | ||
$parentWinId$: windowIds.get($window$.parent), | ||
$url$: $url$ | ||
}; | ||
const sendInitEnvData = () => worker.postMessage([ 3, envData ]); | ||
winCtxs[$winId$] = { | ||
$winId$: $winId$, | ||
$window$: $window$, | ||
$url$: $url$ | ||
}; | ||
winCtxs[$winId$].$startTime$ = performance.now(); | ||
{ | ||
const winType = envData.$winId$ === envData.$parentWinId$ ? "top" : "iframe"; | ||
logMain(`Registered ${winType} window ${normalizedWinId($winId$)} (${$winId$})`); | ||
} | ||
"complete" === doc.readyState ? sendInitEnvData() : $window$.addEventListener("load", sendInitEnvData); | ||
} | ||
}; | ||
const readNextScript = (worker, winCtx) => { | ||
@@ -235,14 +263,4 @@ let $winId$ = winCtx.$winId$; | ||
const readMainPlatform = win => { | ||
const doc = win.document; | ||
const $config$ = win.partytown || {}; | ||
const $libPath$ = ($config$.lib || "/~partytown/") + "debug/"; | ||
return { | ||
$config$: $config$, | ||
$libPath$: new URL($libPath$, win.location) + "", | ||
$interfaces$: readMainInterfaces(win, doc) | ||
}; | ||
}; | ||
const readMainInterfaces = (win, doc) => { | ||
const startTime = performance.now(); | ||
const docImpl = doc.implementation.createHTMLDocument(); | ||
const docImpl = win.document.implementation.createHTMLDocument(); | ||
const textNode = docImpl.createTextNode(""); | ||
@@ -266,6 +284,13 @@ const comment = docImpl.createComment(""); | ||
})); | ||
const interfaces = [ readImplentation("Window", win), readImplentation("Node", textNode) ]; | ||
impls.map((([cstrName, CstrPrototype, impl, intefaceType]) => readOwnImplentation(interfaces, cstrName, CstrPrototype, impl, intefaceType))); | ||
logMain(`Read ${interfaces.length} interfaces in ${(performance.now() - startTime).toFixed(1)}ms`); | ||
return interfaces; | ||
const $interfaces$ = [ readImplentation("Window", win), readImplentation("Node", textNode) ]; | ||
const config = win.partytown || {}; | ||
const libPath = (config.lib || "/~partytown/") + "debug/"; | ||
const initWebWorkerData = { | ||
$config$: JSON.stringify(config, ((_, v) => "function" == typeof v ? String(v) : v)), | ||
$libPath$: new URL(libPath, win.location) + "", | ||
$interfaces$: $interfaces$ | ||
}; | ||
impls.map((([cstrName, CstrPrototype, impl, intefaceType]) => readOwnImplentation($interfaces$, cstrName, CstrPrototype, impl, intefaceType))); | ||
logMain(`Read ${$interfaces$.length} interfaces in ${(performance.now() - startTime).toFixed(1)}ms`); | ||
return initWebWorkerData; | ||
}; | ||
@@ -315,34 +340,9 @@ const readImplentation = (cstrName, impl) => { | ||
}; | ||
const registerWindow = (worker, $winId$, $window$) => { | ||
if (!windowIds.has($window$)) { | ||
windowIds.set($window$, $winId$); | ||
const doc = $window$.document; | ||
const $url$ = doc.baseURI; | ||
const envData = { | ||
$winId$: $winId$, | ||
$parentWinId$: windowIds.get($window$.parent), | ||
$url$: $url$ | ||
}; | ||
const sendInitEnvData = () => worker.postMessage([ 3, envData ]); | ||
winCtxs[$winId$] = { | ||
$winId$: $winId$, | ||
$window$: $window$, | ||
$url$: $url$ | ||
}; | ||
winCtxs[$winId$].$startTime$ = performance.now(); | ||
{ | ||
const winType = envData.$winId$ === envData.$parentWinId$ ? "top" : "iframe"; | ||
logMain(`Registered ${winType} window ${normalizedWinId($winId$)} (${$winId$})`); | ||
} | ||
"complete" === doc.readyState ? sendInitEnvData() : $window$.addEventListener("load", sendInitEnvData); | ||
} | ||
}; | ||
const onMessageFromWebWorker = (worker, mainWindow, msg) => { | ||
const msgType = msg[0]; | ||
if (0 === msgType) { | ||
worker.postMessage([ 1, readMainPlatform(mainWindow) ]); | ||
} else if (2 === msgType) { | ||
if (2 === msgType) { | ||
registerWindow(worker, randomId(), mainWindow); | ||
} else { | ||
const winCtx = winCtxs[msg[1]]; | ||
const winId = msg[1]; | ||
const winCtx = winCtxs[winId]; | ||
winCtx && (6 === msgType ? readNextScript(worker, winCtx) : 5 === msgType && ((worker, winCtx, instanceId, errorMsg, script) => { | ||
@@ -357,7 +357,9 @@ (script = winCtx.$window$.document.querySelector(`[data-ptid="${instanceId}"]`)) && (errorMsg ? script.dataset.pterror = errorMsg : script.type += "-x"); | ||
const mainWindow = sandboxWindow.parent; | ||
const success = await (async (sandboxWindow, receiveMessage) => { | ||
const onMessageHandler = await (async (sandboxWindow, receiveMessage) => { | ||
const swContainer = sandboxWindow.navigator.serviceWorker; | ||
const swRegistration = await swContainer.getRegistration(); | ||
swContainer.addEventListener("message", (ev => receiveMessage(ev.data, (accessRsp => swRegistration.active && swRegistration.active.postMessage(accessRsp))))); | ||
return !!swRegistration; | ||
return swRegistration ? (worker, mainWindow, msg) => { | ||
0 === msg[0] ? worker.postMessage([ 1, readMainPlatform(mainWindow) ]) : onMessageFromWebWorker(worker, mainWindow, msg); | ||
} : null; | ||
})(sandboxWindow, ((accessReq, responseCallback) => (async (worker, accessReq) => { | ||
@@ -406,7 +408,7 @@ const accessRsp = { | ||
})(worker, accessReq).then(responseCallback))); | ||
if (success) { | ||
if (onMessageHandler) { | ||
worker = new Worker("./partytown-ww-sw.js", { | ||
name: "Partytown 🎉" | ||
}); | ||
worker.onmessage = ev => onMessageFromWebWorker(worker, mainWindow, ev.data); | ||
worker.onmessage = ev => onMessageHandler(worker, mainWindow, ev.data); | ||
logMain("Created web worker"); | ||
@@ -413,0 +415,0 @@ worker.onerror = ev => console.error("Web Worker Error", ev); |
@@ -12,3 +12,3 @@ const EMPTY_ARRAY = []; | ||
const httpRequestFromWebWorker = req => new Promise((async resolve => { | ||
const httpRequestFromWebWorker = (req, isolated) => new Promise((async resolve => { | ||
const accessReq = await req.clone().json(); | ||
@@ -28,11 +28,15 @@ const responseData = await (accessReq => new Promise((async resolve => { | ||
})))(accessReq); | ||
resolve(response(JSON.stringify(responseData), "application/json")); | ||
resolve(response(JSON.stringify(responseData), isolated, "application/json")); | ||
})); | ||
const response = (body, contentType) => new Response(body, { | ||
headers: { | ||
const response = (body, isolated, contentType) => { | ||
const headers = { | ||
"content-type": contentType || "text/html", | ||
"Cache-Control": "no-store" | ||
} | ||
}); | ||
}; | ||
isolated && (headers["Cross-Origin-Embedder-Policy"] = "require-corp"); | ||
return new Response(body, { | ||
headers: headers | ||
}); | ||
}; | ||
@@ -57,6 +61,6 @@ self.oninstall = () => self.skipWaiting(); | ||
if (pathname.endsWith("debug/partytown-sandbox-sw.html")) { | ||
ev.respondWith(response('<!DOCTYPE html><html><head><meta charset="utf-8"><script src="./partytown-sandbox-sw.js"><\/script></head></html>')); | ||
ev.respondWith(response('<!DOCTYPE html><html><head><meta charset="utf-8"><script src="./partytown-sandbox-sw.js"><\/script></head></html>', false)); | ||
} else { | ||
pathname.endsWith("proxytown") && ev.respondWith(httpRequestFromWebWorker(req)); | ||
pathname.endsWith("proxytown") && ev.respondWith(httpRequestFromWebWorker(req, false)); | ||
} | ||
}; |
@@ -205,8 +205,25 @@ (self => { | ||
taskQueue.length = 0; | ||
const accessRsp = ((webWorkerCtx, accessReq) => ({ | ||
$msgId$: accessReq.$msgId$, | ||
$error$: "Atomics not implemented (yet)" | ||
}))(0, accessReq); | ||
deserializeFromMain(endTask.$instanceId$, endTask.$applyPath$, accessRsp.$rtnValue$); | ||
throw new Error(accessRsp.$error$); | ||
const accessRsp = ((webWorkerCtx, accessReq) => { | ||
const sharedDataBuffer = webWorkerCtx.$sharedDataBuffer$; | ||
const sharedData = new Int32Array(sharedDataBuffer); | ||
Atomics.store(sharedData, 0, 0); | ||
webWorkerCtx.$postMessage$([ 9, accessReq ]); | ||
Atomics.wait(sharedData, 0, 0); | ||
let dataLength = Atomics.load(sharedData, 0); | ||
0 === dataLength && console.error("Atomics failed", sharedDataBuffer); | ||
let accessRespStr = ""; | ||
for (let i = 0; i < dataLength; i++) { | ||
accessRespStr += String.fromCharCode(sharedData[i + 1]); | ||
} | ||
return JSON.parse(accessRespStr); | ||
})(webWorkerCtx, accessReq); | ||
const isPromise = accessRsp.$isPromise$; | ||
const rtnValue = deserializeFromMain(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; | ||
} | ||
@@ -302,3 +319,10 @@ }; | ||
} | ||
return new URL(url || "", baseLocation); | ||
const resolvedUrl = new URL(url || "", baseLocation); | ||
if (webWorkerCtx.$config$.resolveUrl) { | ||
const configResolvedUrl = webWorkerCtx.$config$.resolveUrl(resolvedUrl, baseLocation); | ||
if (configResolvedUrl) { | ||
return configResolvedUrl; | ||
} | ||
} | ||
return resolvedUrl; | ||
}; | ||
@@ -1152,2 +1176,9 @@ const resolveUrl = (env, url) => resolveToUrl(env, url) + ""; | ||
})); | ||
const parseConfigFn = optionName => { | ||
let fnStr = webWorkerCtx.$config$[optionName]; | ||
if (fnStr) { | ||
(fnStr.startsWith("(") || fnStr.startsWith("function")) && (fnStr = `${optionName}:${fnStr}`); | ||
Object.assign(webWorkerCtx.$config$, new Function(`return{${fnStr}}`)()); | ||
} | ||
}; | ||
const queuedEvents = []; | ||
@@ -1174,11 +1205,2 @@ const receiveMessageFromSandboxToWorker = ev => { | ||
webWorkerCtx.$config$.logScriptExecution && logWorker(`Execute script (${instanceId}) src: ${scriptSrc}`, winId); | ||
try { | ||
rsp = await self.fetch(scriptSrc); | ||
} catch (e) { | ||
if (scriptUrl.origin === origin) { | ||
throw e; | ||
} | ||
scriptSrc = "https://partytown.builder.io/api/proxy?p=" + scriptSrc; | ||
logWorker(`Proxied script (${instanceId}) src: ${scriptSrc}`, winId); | ||
} | ||
rsp = await self.fetch(scriptSrc); | ||
@@ -1246,2 +1268,4 @@ if (rsp.ok) { | ||
Object.assign(webWorkerCtx, initWebWorkerData); | ||
webWorkerCtx.$config$ = JSON.parse(webWorkerCtx.$config$); | ||
parseConfigFn("resolveUrl"); | ||
webWorkerCtx.$forwardedTriggers$ = (webWorkerCtx.$config$.forward || EMPTY_ARRAY).map((f => f[0])); | ||
@@ -1248,0 +1272,0 @@ webWorkerCtx.$postMessage$ = postMessage.bind(self); |
@@ -311,3 +311,10 @@ (self => { | ||
} | ||
return new URL(url || "", baseLocation); | ||
const resolvedUrl = new URL(url || "", baseLocation); | ||
if (webWorkerCtx.$config$.resolveUrl) { | ||
const configResolvedUrl = webWorkerCtx.$config$.resolveUrl(resolvedUrl, baseLocation); | ||
if (configResolvedUrl) { | ||
return configResolvedUrl; | ||
} | ||
} | ||
return resolvedUrl; | ||
}; | ||
@@ -1161,2 +1168,9 @@ const resolveUrl = (env, url) => resolveToUrl(env, url) + ""; | ||
})); | ||
const parseConfigFn = optionName => { | ||
let fnStr = webWorkerCtx.$config$[optionName]; | ||
if (fnStr) { | ||
(fnStr.startsWith("(") || fnStr.startsWith("function")) && (fnStr = `${optionName}:${fnStr}`); | ||
Object.assign(webWorkerCtx.$config$, new Function(`return{${fnStr}}`)()); | ||
} | ||
}; | ||
const queuedEvents = []; | ||
@@ -1183,11 +1197,2 @@ const receiveMessageFromSandboxToWorker = ev => { | ||
webWorkerCtx.$config$.logScriptExecution && logWorker(`Execute script (${instanceId}) src: ${scriptSrc}`, winId); | ||
try { | ||
rsp = await self.fetch(scriptSrc); | ||
} catch (e) { | ||
if (scriptUrl.origin === origin) { | ||
throw e; | ||
} | ||
scriptSrc = "https://partytown.builder.io/api/proxy?p=" + scriptSrc; | ||
logWorker(`Proxied script (${instanceId}) src: ${scriptSrc}`, winId); | ||
} | ||
rsp = await self.fetch(scriptSrc); | ||
@@ -1255,2 +1260,4 @@ if (rsp.ok) { | ||
Object.assign(webWorkerCtx, initWebWorkerData); | ||
webWorkerCtx.$config$ = JSON.parse(webWorkerCtx.$config$); | ||
parseConfigFn("resolveUrl"); | ||
webWorkerCtx.$forwardedTriggers$ = (webWorkerCtx.$config$.forward || EMPTY_ARRAY).map((f => f[0])); | ||
@@ -1257,0 +1264,0 @@ webWorkerCtx.$postMessage$ = postMessage.bind(self); |
@@ -36,12 +36,21 @@ const EMPTY_ARRAY = []; | ||
})); | ||
win.crossOriginIsolated ? ready("atomics") : "serviceWorker" in nav ? nav.serviceWorker.register(libPath + "partytown-sw.js", { | ||
scope: libPath | ||
}).then((function(swRegistration) { | ||
swRegistration.active ? ready("sw") : swRegistration.installing ? swRegistration.installing.addEventListener("statechange", (function(ev) { | ||
"activated" === ev.target.state && ready("sw"); | ||
})) : console.warn(swRegistration); | ||
}), (function(e) { | ||
console.error(e); | ||
})) : fallback(); | ||
let useAtomics = win.crossOriginIsolated; | ||
useAtomics && (useAtomics = !window.location.search.includes("forceServiceWorker")); | ||
if (useAtomics) { | ||
ready("atomics"); | ||
} else if ("serviceWorker" in nav) { | ||
const isolatedQuery = win.crossOriginIsolated ? "?isolated" : ""; | ||
nav.serviceWorker.register(libPath + "partytown-sw.js" + isolatedQuery, { | ||
scope: libPath | ||
}).then((function(swRegistration) { | ||
swRegistration.active ? ready("sw") : swRegistration.installing ? swRegistration.installing.addEventListener("statechange", (function(ev) { | ||
"activated" === ev.target.state && ready("sw"); | ||
})) : console.warn(swRegistration); | ||
}), (function(e) { | ||
console.error(e); | ||
})); | ||
} else { | ||
fallback(); | ||
} | ||
} | ||
}(window, document, navigator); |
@@ -1,1 +0,1 @@ | ||
const t=new Map,e=(t,e)=>({C:t.C,m:e}),r=(t,e)=>new Response(t,{headers:{"content-type":e||"text/html","Cache-Control":"no-store"}});self.oninstall=()=>self.skipWaiting(),self.onactivate=()=>self.clients.claim(),self.onmessage=e=>{const r=e.data,n=t.get(r.C);n&&(t.delete(r.C),clearTimeout(n[1]),n[0](r))},self.onfetch=n=>{const s=n.request,o=new URL(s.url).pathname;o.endsWith("partytown-sandbox-sw.html")?n.respondWith(r('<!DOCTYPE html><html><head><meta charset="utf-8"><script type="module">(t=>{const e=()=>!0,r=t=>t.length,n=t=>t&&t.constructor&&t.constructor.name||"",s=(t,e)=>t.startsWith(e),o=t=>!(s(t,"webkit")||s(t,"toJSON")||s(t,"constructor")||s(t,"toString")),i=()=>Math.round(9999999999*Math.random()+4),a=new WeakMap,c=[],l=new Map,u={},h=new WeakMap,p=(t,e,r)=>t?t===t.window?0:"#document"===(r=t.nodeName)?1:"HTML"===r?2:"HEAD"===r?3:"BODY"===r?4:("number"!=typeof(e=a.get(t))&&m(t,e=i()),e):-1,d=(t,e,r)=>{const n=u[t].L,s=n.document;return 0===e?n:1===e?s:2===e?s.documentElement:3===e?s.head:4===e?s.body:(r=c.find((t=>t[0]===e)))?r[1]:void 0},m=(t,e)=>{t&&(c.push([e,t]),a.set(t,e))},g=(t,e,r,s,o)=>{if(void 0!==e){if("string"==(s=typeof e)||"number"===s||"boolean"===s||null==e)return[9,e];if("function"===s)return[5];if(r=r||new Set,Array.isArray(e))return r.has(e)?[0,[]]:(r.add(e),[0,e.map((e=>g(t,e,r)))]);if("object"===s)return"Window"===(o=n(e))?[6,{O:t,t:0}]:"HTMLCollection"===o||"NodeList"===o?[7,Array.from(e).map((e=>g(t,e,r)[1]))]:"Event"===o?[4,f(t,e,r)]:"CSSRuleList"===o?[3,Array.from(e).map(y)]:o.startsWith("CSS")&&o.endsWith("Rule")?[2,y(e)]:"CSSStyleDeclaration"===o?[8,f(t,e,r)]:"Attr"===o?[1,[e.name,e.value]]:e.nodeType?[6,{O:t,t:p(e),D:e.nodeName}]:[8,f(t,e,r,!0,!0)]}},f=(t,e,r,n,s,i,a,c)=>{if(i={},!r.has(e))for(a in r.add(e),e)o(a)&&(c=e[a],(n||"function"!=typeof c)&&(s||""!==c)&&(i[a]=g(t,c,r)));return i},y=t=>{let e,r={};for(e in t)E.includes(e)&&(r[e]=t[e]);return r},$=(t,e,r,n)=>{if(e){if(r=e[0],n=e[1],9===r)return n;if(10===r)return w(t,n);if(0===r)return n.map((e=>$(t,e)));if(6===r)return d(n.O,n.t);if(4===r)return v(b(t,n));if(8===r)return b(t,n)}},w=(t,{O:e,t:r,G:n})=>{let s=l.get(n);return s||(s=function(...s){const o={t:r,G:n,J:g(e,this),b:g(e,s)};t.postMessage([7,o])},l.set(n,s)),s},v=t=>new("detail"in t?CustomEvent:Event)(t.type,t),b=(t,e,r,n)=>{for(n in r={},e)r[n]=$(t,e[n]);return r},E="cssText,selectorText,href,media,namespaceURI,prefix,name,conditionText".split(","),T=(t,e,n,s)=>{let o,i,a,c,l=0,u=r(n);for(;l<u;l++)if(i=n[l],o=n[l+1],a=n[l-1],!Array.isArray(o))if("string"==typeof i||"number"==typeof i){if(l+1===u&&s){const t={};return s.map((r=>t[r]=e[r])),t}e=e[i]}else{if(0===o)return void(e[a]=$(t,i));"function"==typeof e[a]&&(c=$(t,i),"insertRule"===a&&c[1]>r(e.cssRules)&&(c[1]=r(e.cssRules)),e=e[a].apply(e,c))}return e},S=(t,e)=>{let n,s,o=e.O,i=e.L,a=i.document,c=a.querySelector(\'script[type="text/partytown"]:not([data-ptid]):not([data-pterror]):not([async]):not([defer])\');c||(c=a.querySelector(\'script[type="text/partytown"]:not([data-ptid]):not([data-pterror])\')),c?(c.dataset.ptid=n=p(c,o),s={O:o,t:n},c.src?s.K=c.src:s.f=c.innerHTML,t.postMessage([6,s])):e.v||(e.v=1,((t,e,n)=>{let s=n._ptf,o=n._ptf=[],i=0;if(o.push=(r,n)=>t.postMessage([8,{O:e,t:0,n:r,b:g(e,Array.from(n))}]),s)for(;i<r(s);i+=2)o.push(s[i],s[i+1])})(t,o,i),a.dispatchEvent(new CustomEvent("pt0")),t.postMessage([4,o]))},L=t=>{const e=t.document,r=t.partytown||{},n=(r.lib||"/~partytown/")+"";return{e:r,z:new URL(n,t.location)+"",s:N(t,e)}},N=(t,r)=>{const n=r.implementation.createHTMLDocument(),s=n.createTextNode(""),o=n.createComment(""),i=n.createDocumentFragment(),a=n.createElement("i"),c=n.createElementNS("http://www.w3.org/2000/svg","svg"),l=n.createElement("canvas").getContext("2d"),u=new MutationObserver(e),h=new ResizeObserver(e),p=Object.getOwnPropertyNames(t).filter((t=>/^HTML.+Element$/.test(t))).map((t=>{const e=R(t);return[n.createElement(e)]})),d=[[t.localStorage],[t.history],[t.screen],[t.screen.orientation],[u,12],[h,12],[s],[o],[i],[a],[a.attributes],[a.classList],[a.dataset],[a.style],[c],[n],[n.doctype],[l],...p].filter((t=>t[0])).map((e=>{const r=e[0],n=e[1],s=r.constructor.name;return[s,t[s].prototype,r,n]})),m=[I("Window",t),I("Node",s)];return d.map((([t,e,r,n])=>O(m,t,e,r,n))),m},I=(t,e)=>{const r=[],n=[t,"Object",r];for(const t in e)M(r,e,t);return n},O=(t,e,r,n,s)=>{if("Object"!==e&&!t.some((t=>t[0]===e))){const o=Object.getPrototypeOf(r),i=o.constructor.name,a=[];O(t,i,o,n,s),Object.keys(Object.getOwnPropertyDescriptors(r)).map((t=>M(a,n,t)));const c=[e,i,a,s,n.nodeName];t.push(c)}},M=(t,e,r,s)=>{if(o(r)){const o=e[r],i=typeof o;"function"===i?t.push([r,5]):"object"===i&&null!=o&&"Object"!==(s=n(o))?o.nodeType?t.push([r,o.nodeType]):t.push([r,s]):"symbol"!==i&&(r.toUpperCase()===r?t.push([r,6,o]):t.push([r,6]))}},x={Anchor:"A",DList:"DL",Image:"IMG",OList:"OL",Paragraph:"P",TableCaption:"CAPTION",TableCell:"TD",TableCol:"COLGROUP",TableRow:"TR",TableSection:"TBODY",UList:"UL"},R=t=>(t=t.substr(4).replace("Element",""),x[t]||t),C=(t,e,r)=>{if(!h.has(r)){h.set(r,e);const n=r.document,s=n.baseURI,o={O:e,E:h.get(r.parent),K:s},i=()=>t.postMessage([3,o]);u[e]={O:e,L:r,K:s},"complete"===n.readyState?i():r.addEventListener("load",i)}};(async t=>{let e;const n=t.parent,s=await(async(t,n)=>{const s=t.navigator.serviceWorker,o=await s.getRegistration();return s.addEventListener("message",(t=>{return n=t.data,s=t=>o.active&&o.active.postMessage(t),(async(t,e)=>{const n={C:e.C},s=r(e.$tasks$);for(let r=0;r<s;r++)try{let s,i,a=e.$tasks$[r],c=a.O,l=a.t,h=a.a;if(u[c]||await new Promise((t=>{let e=0,r=()=>{u[c]||e++>999?t():setTimeout(r,9)};r()})),1===h[0]&&h[1]in u[c].L){const e=new u[c].L[h[1]](...$(t,h[2]));m(e,l)}else s=d(c,l),s?(i=T(t,s,h,a.$groupedGetters$),a.c&&m(i,a.c),"object"==typeof(o=i)&&o&&o.then&&(i=await i,n.w=!0),n.H=g(c,i)):n.m=l+" not found"}catch(t){r===s-1?n.m=String(t.stack||t):console.error(t)}var o;return n})(e,n).then(s);var n,s})),!!o})(t);s&&(e=new Worker(URL.createObjectURL(new Blob([\'(t=>{const e=Symbol(),r=Symbol(),n=Symbol(),s=Symbol(),i=Symbol(),o=new Map,a={},c=new WeakMap,l={},h={},u={},$={},d={},p=new Map,g=new Map,m="getClientRects,getBoundingClientRect".split(","),f="innerHeight,innerWidth,outerHeight,outerWidth,clientHeight,clientWidth,clientTop,clientLeft,scrollHeight,scrollWidth,scrollTop,scrollLeft,offsetHeight,offsetWidth,offsetTop,offsetLeft".split(","),w="childElementCount,children,firstElementChild,lastElementChild,nextElementSibling,previousElementSibling",y=()=>!0,I=t=>t.length,v=(t,e)=>Object.defineProperty(t,"name",{value:e}),b=[],S=()=>Math.round(9999999999*Math.random()+4),E="text/partytown",T=(t,e,r)=>Object.defineProperty(t.prototype,e,{...r,configurable:!0}),N=(t,e)=>Object.defineProperties(t.prototype,e),x=(t,e,r)=>T(t,e,{value:r,writable:!0}),M=[],L=(t,n,i,o,a)=>{const c=t[r];if(M.push({O:t[e],t:c,a:[...t[s],...n],c:o,$groupedGetters$:a}),!i)return C();setTimeout(C,40)},C=()=>{if(I(M)){const t=M[I(M)-1],e={C:S(),$tasks$:M.slice()};M.length=0;const r=((t,e)=>{const r=new XMLHttpRequest,n=t.z+"proxytown";return r.open("POST",n,!1),r.send(JSON.stringify(e)),JSON.parse(r.responseText)})($,e),n=r.w,s=st(t.t,t.a,r.H);if(r.m){if(n)return Promise.reject(r.m);throw new Error(r.m)}return n?Promise.resolve(s):s}},W=(t,e,r)=>L(t,e,!1,void 0,r),R=(t,e,r)=>{const n=[...e,nt(t,r),0];L(t,n,!0)},P=(t,e,r,n)=>{const s=e[I(e)-1],i=A.includes(s),o=[...e,nt(t,r)],a=L(t,o,i,n);return i||m.includes(s)||p.clear(),a},A="addEventListener,removeEventListener,createElement,createTextNode,insertBefore,insertRule,deleteRule,setAttribute,setItem,removeItem,classList.add,classList.remove,classList.toggle".split(","),H=(t,e)=>O(t[r],e),O=(t,e,r)=>(r=u[t])?r[e]:void 0,j=(t,e,n)=>D(t[r],e,n),D=(t,e,r,n)=>{(n=u[t]||{})[e]=r,u[t]=n},k=(t,e,r,n)=>{let s="";try{t.g=e,t.h="",B(t,r)}catch(t){console.error(r,t),s=String(t.stack||t)+""}return t.g=-1,t.h="",s},B=(t,e)=>{new Function(`with(this){${e}}`).apply(t.L)},U=(t,e,r)=>{(r=O(t,e))&&setTimeout((()=>r.map((t=>t({type:e})))),undefined)},F=(t,e,r)=>{for(r=t.A;!r.host&&(r=(t=d[t.E]).A,t.O!==t.E););return new URL(e||"",r)},_=(t,e)=>F(t,e)+"",z=t=>F(Z(t),H(t,4)),q=()=>`<script src=${JSON.stringify($.z+"partytown.js")} async defer><\\\\/script>`,G=t=>class{constructor(){this.s="",this.l=[],this.e=[]}get src(){return this.s}set src(e){const r=d[t];fetch(_(r,e),{mode:"no-cors",keepalive:!0}).then((t=>{t.ok?this.l.map((t=>t({type:"load"}))):this.e.map((t=>t({type:"error"})))}),(()=>this.e.forEach((t=>t({type:"error"})))))}addEventListener(t,e){"load"===t&&this.l.push(e),"error"===t&&this.e.push(e)}get onload(){return this.l[0]}set onload(t){this.l=[t]}get onerror(){return this.e[0]}set onerror(t){this.e=[t]}},J=(t,e,r)=>{let n=o.get(e);return n||(n=V(t,e,r),o.set(e,n)),n},V=(e,r,n)=>new(l[n]?l[n]:n.includes("-")?l.UNKNOWN:t.HTMLElement)(e,r,[],n);class X extends URL{assign(){}reload(){}replace(){}}class Y{constructor(t,o,a,c){this[e]=t,this[r]=o,this[s]=a||[],this[n]=c,this[i]={}}}class K extends Y{constructor(t,e,r,n){return super(t,e,r,n),new Proxy(this,{get:(t,e)=>W(t,[e]),set:(t,e,r)=>(R(t,[e],r),!0)})}}class Window extends Y{constructor(e,r,n){super(e,0);for(const e in t)if(!(e in this)&&"onmessage"!==e){const r=t[e];if(null!=r){const n="function"==typeof r&&!r.toString().startsWith("class");this[e]=n?r.bind(t):r}}Object.getOwnPropertyNames(t).map((e=>{e in this||(this[e]=t[e])}));for(const t in h)this[t]=v(class{constructor(...r){const n=new(0,h[t])(e,S()),s=nt(n,r);return L(n,[1,t,s]),n}},t);const s=new Proxy(this,{has:()=>!0});return d[e]={O:e,E:r,L:s,k:V(e,1,"#document"),l:V(e,2,"HTML"),p:V(e,3,"HEAD"),d:V(e,4,"BODY"),A:new X(n)},this.requestAnimationFrame=t=>setTimeout((()=>t(performance.now())),9),this.cancelAnimationFrame=t=>clearTimeout(t),s}get body(){return Z(this).d}get document(){return Z(this).k}get documentElement(){return Z(this).l}get frameElement(){const t=Z(this),e=t.E,r=t.O;return r===e?null:J(e,r,"IFRAME")}get globalThis(){return this}get head(){return Z(this).p}get location(){return Z(this).A}set location(t){Z(this).A.href=t+""}get Image(){return G(this[e])}get name(){const t=this[e];return name+t}get navigator(){return(e=>{const r=t.navigator;return r.sendBeacon=(t,r)=>{const n=d[e];try{return fetch(_(n,t),{method:"POST",body:r,mode:"no-cors",keepalive:!0}),!0}catch(t){return console.error(t),!1}},r})(this[e])}get origin(){return Z(this).A.origin}get parent(){return d[Z(this).E].L}get self(){return this}get top(){for(const t in d)if(d[t].O===d[t].E)return d[t].L}get window(){return this}}const Q=({O:t,E:e,K:r})=>{d[t]?d[t].A.href=r:new Window(t,e,r),$.F([6,t])},Z=t=>d[t[e]];class Node extends Y{appendChild(t){return this.insertBefore(t,null)}get href(){}set href(t){}insertBefore(t,s){const i=t[e]=this[e],o=t[r],a=t[n],c="SCRIPT"===a,l="IFRAME"===a;if(c){const e=H(t,3);if(e){const r=k(Z(t),o,e),n=r?"pterror":"ptid",s=r||o;R(t,["type"],E+"-x"),R(t,["dataset",n],s),R(t,["innerHTML"],e)}}return P(this,["insertBefore"],[t,s]),l&&(t=>{let e=0;const n=t[r],s=()=>{if(d[n]&&d[n].v){let e=H(t,1)?"error":"load",r=H(t,e);r&&r.map((t=>t({type:e})))}else if(e++>2e3){let e=H(t,"error");e&&e.map((t=>t({type:"error"}))),console.error("Timeout")}else setTimeout(s,9)};s()})(t),c&&(C(),$.F([6,i])),t}get nodeName(){return this[n]}get nodeType(){return 3}get ownerDocument(){return Z(this).k}}class tt{constructor(t){this.name=t[0],this.value=t[1]}get nodeName(){return this.name}get nodeType(){return 2}}class NodeList{constructor(t){(this._=t).map(((t,e)=>this[e]=t))}entries(){return this._.entries()}forEach(t,e){this._.map(t,e)}item(t){return this[t]}keys(){return this._.keys()}get length(){return I(this._)}values(){return this._.values()}[Symbol.iterator](){return this._[Symbol.iterator]()}}const et=(t,n,s,i)=>{if(void 0!==s){let h=typeof s;if("string"===h||"boolean"===h||"number"===h||null==s)return[9,s];if("function"===h)return[10,{O:t,t:n,G:(o=s,(l=c.get(o))||(c.set(o,l=S()),a[l]=o),l)}];if(i=i||new Set,Array.isArray(s))return i.has(s)?[0,[]]:[0,s.map((e=>et(t,n,e,i)))];if("object"===h)return"number"==typeof s[r]?[6,{O:s[e],t:s[r]}]:s instanceof Event?[4,rt(t,n,s,!1,i)]:[8,rt(t,n,s,!0,i)]}var o,l},rt=(t,e,r,n,s,i,o,a)=>{if(i={},!s.has(r))for(o in s.add(r),r)a=r[o],(n||"function"!=typeof a)&&(i[o]=et(t,e,a,s));return i},nt=(t,n)=>t?et(t[e],t[r],n):[9,n],st=(t,e,r,n,s)=>{if(r){if(n=r[0],s=r[1],9===n||2===n||3===n)return s;if(10===n)return ct(e,s);if(6===n)return ot(s);if(7===n)return new NodeList(s.map(ot));if(1===n)return new tt(s);if(0===n)return s.map((r=>st(t,e,r)));if(4===n)return i=it(t,e,s),new Proxy(new Event(i.type,i),{get:(t,e)=>e in i?i[e]:t[String(e)]});if(8===n)return it(t,e,s)}var i},it=(t,e,r,n,s)=>{for(s in n={},r)n[s]=st(t,[...e,s],r[s]);return n},ot=({O:t,t:e,D:r})=>at(t,e)||J(t,e,r),at=(t,e)=>{const r=d[t];return 0===e?r.L:1===e?r.k:2===e?r.l:3===e?r.p:4===e?r.d:void 0},ct=(t,{O:e,t:r,D:n,G:s})=>(a[s]||c.set(a[s]=function(...s){const i=J(e,r,n);return P(i,t,s)},s),a[s]),lt={sheet:{get(){return new ht(this)}}};class ht{constructor(t){this.ownerNode=t}get cssRules(){const t=this.ownerNode;return new Proxy({},{get(e,r){const n=String(r);return"item"===n?e=>$t(t,e):"length"===n?ut(t).length:isNaN(n)?e[r]:$t(t,n)}})}insertRule(t,e){const r=ut(this.ownerNode);return(e=void 0===e?0:e)>=0&&e<=r.length&&(P(this.ownerNode,["sheet","insertRule"],[t,e]),r.splice(e,0,0)),e}deleteRule(t){P(this.ownerNode,["sheet","deleteRule"],[t]),ut(this.ownerNode).splice(t,1)}}const ut=t=>{let e=H(t,2);return e||(e=W(t,["sheet","cssRules"]),j(t,2,e)),e},$t=(t,e)=>{let r=ut(t);return 0===r[e]&&(r[e]=W(t,["sheet","cssRules",parseInt(e,10)])),r[e]},dt={body:{get(){return Z(this).d}},createElement:{value(t){t=t.toUpperCase();const r=this[e],n=S(),s=J(r,n,t);return P(this,["createElement"],[t],n),"IFRAME"===t?(Q({O:n,E:r,K:"about:blank"}),R(s,["srcdoc"],q())):"SCRIPT"===t&&R(s,["type"],E),s}},createElementNS:{value(t,r){r=r.toUpperCase();const n=this[e],s=S(),i=J(n,s,r);return P(this,["createElementNS"],[t,r],s),i}},createTextNode:{value(t){const r=this[e],n=S(),s=J(r,n,"#text");return P(this,["createTextNode"],[t],n),s}},createEvent:{value:t=>new Event(t)},currentScript:{get(){const t=this[e],r=Z(this).g;return r>0?J(t,r,"SCRIPT"):null}},defaultView:{get(){return Z(this).L}},documentElement:{get(){return Z(this).l}},getElementsByTagName:{value(t){return"BODY"===(t=t.toUpperCase())?[Z(this).d]:"HEAD"===t?[Z(this).p]:P(this,["getElementsByTagName"],[t])}},head:{get(){return Z(this).p}},implementation:{value:{hasFeature:y}},location:{get(){return Z(this).A},set(t){Z(this).A.href=t+""}},nodeType:{value:9},parentNode:{value:null},parentElement:{value:null},readyState:{value:"complete"}},pt={localName:{get(){return this[n].toLowerCase()}},namespaceURI:{get(){return"http://www.w3.org/"+("SVG"===this[n]?"2000/svg":"1999/xhtml")}},nodeType:{value:1},tagName:{get(){return this[n]}}},gt={hash:{get(){return z(this).hash}},host:{get(){return z(this).host}},hostname:{get(){return z(this).hostname}},href:{get(){return z(this).href},set(t){j(this,4,t+=""),R(this,["href"],t)}},origin:{get(){return z(this).origin}},pathname:{get(){return z(this).pathname}},port:{get(){return z(this).port}},protocol:{get(){return z(this).protocol}},search:{get(){return z(this).search}}},mt={getContext:{value(...n){const s=["getContext",nt(this,n)];return new t.CanvasRenderingContext2D(this[e],this[r],s)}}},ft={addEventListener:{value(...t){const e=t[0],r=H(this,e)||[];r.push(t[1]),j(this,e,r)}},async:{get:y,set:y},defer:{get:y,set:y},onload:{get(){let t=H(this,"load");return t&&t[0]||null},set(t){j(this,"load",t?[t]:null)}},onerror:{get(){let t=H(this,"error");return t&&t[0]||null},set(t){j(this,"error",t?[t]:null)}}},wt={contentDocument:{get(){return this.contentWindow.document}},contentWindow:{get(){const t=this[r];return d[t].L}},src:{get(){return H(this,4)||""},set(t){let e,r=new XMLHttpRequest;t=_(Z(this),t),j(this,1,void 0),j(this,4,t),r.open("GET",t,!1),r.send(),e=r.status,e>199&&e<300?R(this,["srcdoc"],((t,e)=>`<base href="${t}">`+e.replace(/<script>/g,\\\'<script type="text/partytown">\\\').replace(/<script /g,\\\'<script type="text/partytown" \\\').replace(/text\\\\/javascript/g,E)+q())(t,r.responseText)):j(this,1,e)}},...ft},yt={get(){return H(this,3)||""},set(t){j(this,3,t)}},It={innerHTML:yt,innerText:yt,src:{get(){return H(this,4)||""},set(t){t=_(Z(this),t),j(this,4,t),R(this,["src"],t)}},getAttribute:{value(t){return"src"===t?this.src:P(this,["getAttribute"],[t])}},setAttribute:{value(t,e){"src"===t?this.src=e:P(this,["setAttribute"],[t,e])}},textContent:yt,type:{get(){return W(this,["type"])},set(t){"text/javascript"!==t&&R(this,["type"],t)}},...ft},vt=([o,a,c,u,$])=>{const d=bt[o]?K:"Object"===a||"EventTarget"===a?Y:t[a],p=t[o]=v(t[o]||class extends d{},o);12===u&&(h[o]=p),$&&(l[$]=p),c.map((([o,a,c])=>{o in p.prototype||o in d.prototype||("string"==typeof a?T(p,o,{get(){if(!this[i][o]){const c=this[e],l=this[r],h=[...this[s],o],u=this[n],$=t[a];this[i][o]=new $(c,l,h,u)}return this[i][o]},set(t){this[i][o]=t}}):5===a?x(p,o,(function(...t){return P(this,[o],t)})):a>0&&(void 0!==c?x(p,o,c):T(p,o,{get(){return W(this,[o])},set(t){return R(this,[o],t)}})))}))},bt={CSSStyleDeclaration:1,DOMStringMap:1,NamedNodeMap:1},St=(t,e)=>x(t,"nodeType",e),Et=(t,e)=>e.split(",").map((e=>T(t,e,{get(){let t=Tt(this,e),r=g.get(t);return r||(r=W(this,[e]),g.set(t,r)),r}}))),Tt=(t,n)=>t[e]+"."+t[r]+"."+n,Nt=(t,e)=>Object.keys(e).map((r=>x(t,r,e[r]))),xt=t=>f.map((e=>{T(t,e,{get(){const t=p.get(Tt(this,e));if("number"==typeof t)return t;const r=W(this,[e],f);return Object.entries(r).map((([t,e])=>{p.set(Tt(this,t),e)})),r[e]}})})),Mt=t=>m.map((e=>{t.prototype[e]=function(){let t=Tt(this,e),r=p.get(t);return r||(r=P(this,[e],b),p.set(t,r)),r}})),Lt=[],Ct=e=>{const r=e.data,n=r[0];var s;$.v?6===n?(async e=>{let r,n,s=e.O,i=e.t,o=e.f,a=e.K,c="",l=d[s];if(a)try{n=F(l,a),a=n+"",D(i,4,a);try{r=await t.fetch(a)}catch(t){if(n.origin===origin)throw t;a="https://partytown.builder.io/api/proxy?p="+a}r=await t.fetch(a),r.ok?(o=await r.text(),l.g=i,l.h=a,B(l,o),U(i,"load")):(console.error(r.status,"url:",a),c=r.statusText,U(i,"error"))}catch(t){console.error("url:",a,t),c=String(t.stack||t)+"",U(i,"error")}else o&&(c=k(l,i,o));l.g=-1,l.h="",$.F([5,s,i,c])})(r[1]):7===n?(({t:t,G:e,J:r,b:n})=>{if(a[e])try{const s=st(t,[],r),i=st(t,[],n);a[e].apply(s,i)}catch(t){console.error(t)}})(r[1]):8===n?(({O:e,t:r,n:n,b:s})=>{try{const i=d[e].L,o=n[0]in i?i:n[0]in t?t:{},a=st(r,[],s),c=o[n[0]];Array.isArray(c)?c.push(...a):"function"==typeof c&&c.apply(o,a)}catch(t){console.error(t)}})(r[1]):3===n?Q(r[1]):4===n&&(d[r[1]].v=1):1===n?(s=r[1],Object.assign($,s),$.o=($.e.forward||b).map((t=>t[0])),$.F=postMessage.bind(t),t.postMessage=t.importScripts=void 0,t.Node=Node,t.Window=Window,t.CSSStyleSheet=ht,$.s.map(vt),(()=>{const e=t.Element,r=t.DocumentFragment;"atob,btoa,crypto,indexedDB,performance,setTimeout,setInterval,clearTimeout,clearInterval".split(",").map((t=>delete Window.prototype[t])),N(e,pt),N(t.Document,dt),N(t.HTMLAnchorElement,gt),N(t.HTMLCanvasElement,mt),N(t.HTMLIFrameElement,wt),N(t.HTMLScriptElement,It),N(t.HTMLStyleElement,lt),Nt(ht,{type:"text/css"}),St(t.Comment,8),St(t.DocumentType,10),St(r,11),Et(Node,"childNodes,firstChild,isConnected,lastChild,nextSibling,parentElement,parentNode,previousSibling"),Et(e,w),Et(r,w),xt(e),xt(Window),Mt(e)})(),$.v=1,$.F([2]),Lt.slice().forEach(Ct),Lt.length=0):Lt.push(e)};t.onmessage=Ct,postMessage([0])})(self);\\n\'],{type:"text/javascript"})),{name:"Partytown 🎉"}),e.onmessage=t=>((t,e,r)=>{const n=r[0];if(0===n)t.postMessage([1,L(e)]);else if(2===n)C(t,i(),e);else{const e=u[r[1]];e&&(6===n?S(t,e):5===n&&((t,e,r,n,s)=>{(s=e.L.document.querySelector(`[data-ptid="${r}"]`))&&(n?s.dataset.pterror=n:s.type+="-x"),S(t,e)})(t,e,r[2],r[3]))}})(e,n,t.data),n.addEventListener("pt1",(t=>{const r=t.detail,n=p(r.frameElement);C(e,n,r)})))})(t)})(window);\n<\/script></head></html>')):o.endsWith("proxytown")&&n.respondWith((n=>new Promise((async s=>{const o=await n.clone().json(),i=await(r=>new Promise((async n=>{const s=[...await self.clients.matchAll()].sort(((t,e)=>t.url>e.url?-1:t.url<e.url?1:0))[0];if(s){const o=[n,setTimeout((()=>{t.delete(r.C),n(e(r,"Timeout"))}),1e4)];t.set(r.C,o),s.postMessage(r)}else n(e(r,"No Party"))})))(o);s(r(JSON.stringify(i),"application/json"))})))(s))}; | ||
const t=new Map,e=(t,e)=>({C:t.C,m:e}),r=(t,e,r)=>{const n={"content-type":r||"text/html","Cache-Control":"no-store"};return e&&(n["Cross-Origin-Embedder-Policy"]="require-corp"),new Response(t,{headers:n})};self.oninstall=()=>self.skipWaiting(),self.onactivate=()=>self.clients.claim(),self.onmessage=e=>{const r=e.data,n=t.get(r.C);n&&(t.delete(r.C),clearTimeout(n[1]),n[0](r))},self.onfetch=n=>{const s=n.request,o=new URL(s.url).pathname;o.endsWith("partytown-sandbox-sw.html")?n.respondWith(r('<!DOCTYPE html><html><head><meta charset="utf-8"><script type="module">(t=>{const e=()=>!0,r=t=>t.length,n=t=>t&&t.constructor&&t.constructor.name||"",s=(t,e)=>t.startsWith(e),o=t=>!(s(t,"webkit")||s(t,"toJSON")||s(t,"constructor")||s(t,"toString")),i=()=>Math.round(9999999999*Math.random()+4),a=new WeakMap,c=[],l=new Map,u={},h=new WeakMap,p=(t,e,r)=>t?t===t.window?0:"#document"===(r=t.nodeName)?1:"HTML"===r?2:"HEAD"===r?3:"BODY"===r?4:("number"!=typeof(e=a.get(t))&&m(t,e=i()),e):-1,d=(t,e,r)=>{const n=u[t].L,s=n.document;return 0===e?n:1===e?s:2===e?s.documentElement:3===e?s.head:4===e?s.body:(r=c.find((t=>t[0]===e)))?r[1]:void 0},m=(t,e)=>{t&&(c.push([e,t]),a.set(t,e))},g=(t,e,r,s,o)=>{if(void 0!==e){if("string"==(s=typeof e)||"number"===s||"boolean"===s||null==e)return[9,e];if("function"===s)return[5];if(r=r||new Set,Array.isArray(e))return r.has(e)?[0,[]]:(r.add(e),[0,e.map((e=>g(t,e,r)))]);if("object"===s)return"Window"===(o=n(e))?[6,{O:t,t:0}]:"HTMLCollection"===o||"NodeList"===o?[7,Array.from(e).map((e=>g(t,e,r)[1]))]:"Event"===o?[4,f(t,e,r)]:"CSSRuleList"===o?[3,Array.from(e).map(y)]:o.startsWith("CSS")&&o.endsWith("Rule")?[2,y(e)]:"CSSStyleDeclaration"===o?[8,f(t,e,r)]:"Attr"===o?[1,[e.name,e.value]]:e.nodeType?[6,{O:t,t:p(e),D:e.nodeName}]:[8,f(t,e,r,!0,!0)]}},f=(t,e,r,n,s,i,a,c)=>{if(i={},!r.has(e))for(a in r.add(e),e)o(a)&&(c=e[a],(n||"function"!=typeof c)&&(s||""!==c)&&(i[a]=g(t,c,r)));return i},y=t=>{let e,r={};for(e in t)E.includes(e)&&(r[e]=t[e]);return r},$=(t,e,r,n)=>{if(e){if(r=e[0],n=e[1],9===r)return n;if(10===r)return w(t,n);if(0===r)return n.map((e=>$(t,e)));if(6===r)return d(n.O,n.t);if(4===r)return v(b(t,n));if(8===r)return b(t,n)}},w=(t,{O:e,t:r,G:n})=>{let s=l.get(n);return s||(s=function(...s){const o={t:r,G:n,J:g(e,this),b:g(e,s)};t.postMessage([7,o])},l.set(n,s)),s},v=t=>new("detail"in t?CustomEvent:Event)(t.type,t),b=(t,e,r,n)=>{for(n in r={},e)r[n]=$(t,e[n]);return r},E="cssText,selectorText,href,media,namespaceURI,prefix,name,conditionText".split(","),T=(t,e,n,s)=>{let o,i,a,c,l=0,u=r(n);for(;l<u;l++){i=n[l],o=n[l+1],a=n[l-1];try{if(!Array.isArray(o))if("string"==typeof i||"number"==typeof i){if(l+1===u&&s){const t={};return s.map((r=>t[r]=e[r])),t}e=e[i]}else{if(0===o)return void(e[a]=$(t,i));"function"==typeof e[a]&&(c=$(t,i),"insertRule"===a&&c[1]>r(e.cssRules)&&(c[1]=r(e.cssRules)),e=e[a].apply(e,c))}}catch(t){console.warn(t)}}return e},O=(t,e,r)=>{if(!h.has(r)){h.set(r,e);const n=r.document,s=n.baseURI,o={O:e,E:h.get(r.parent),K:s},i=()=>t.postMessage([3,o]);u[e]={O:e,L:r,K:s},"complete"===n.readyState?i():r.addEventListener("load",i)}},S=(t,e)=>{let n,s,o=e.O,i=e.L,a=i.document,c=a.querySelector(\'script[type="text/partytown"]:not([data-ptid]):not([data-pterror]):not([async]):not([defer])\');c||(c=a.querySelector(\'script[type="text/partytown"]:not([data-ptid]):not([data-pterror])\')),c?(c.dataset.ptid=n=p(c,o),s={O:o,t:n},c.src?s.K=c.src:s.f=c.innerHTML,t.postMessage([6,s])):e.v||(e.v=1,((t,e,n)=>{let s=n._ptf,o=n._ptf=[],i=0;if(o.push=(r,n)=>t.postMessage([8,{O:e,t:0,n:r,b:g(e,Array.from(n))}]),s)for(;i<r(s);i+=2)o.push(s[i],s[i+1])})(t,o,i),a.dispatchEvent(new CustomEvent("pt0")),t.postMessage([4,o]))},L=t=>{const r=t.document.implementation.createHTMLDocument(),n=r.createTextNode(""),s=r.createComment(""),o=r.createDocumentFragment(),i=r.createElement("i"),a=r.createElementNS("http://www.w3.org/2000/svg","svg"),c=r.createElement("canvas").getContext("2d"),l=new MutationObserver(e),u=new ResizeObserver(e),h=Object.getOwnPropertyNames(t).filter((t=>/^HTML.+Element$/.test(t))).map((t=>{const e=A(t);return[r.createElement(e)]})),p=[[t.localStorage],[t.history],[t.screen],[t.screen.orientation],[l,12],[u,12],[n],[s],[o],[i],[i.attributes],[i.classList],[i.dataset],[i.style],[a],[r],[r.doctype],[c],...h].filter((t=>t[0])).map((e=>{const r=e[0],n=e[1],s=r.constructor.name;return[s,t[s].prototype,r,n]})),d=[N("Window",t),N("Node",n)],m=t.partytown||{},g=(m.lib||"/~partytown/")+"",f={e:JSON.stringify(m,((t,e)=>"function"==typeof e?String(e):e)),z:new URL(g,t.location)+"",s:d};return p.map((([t,e,r,n])=>M(d,t,e,r,n))),f},N=(t,e)=>{const r=[],n=[t,"Object",r];for(const t in e)I(r,e,t);return n},M=(t,e,r,n,s)=>{if("Object"!==e&&!t.some((t=>t[0]===e))){const o=Object.getPrototypeOf(r),i=o.constructor.name,a=[];M(t,i,o,n,s),Object.keys(Object.getOwnPropertyDescriptors(r)).map((t=>I(a,n,t)));const c=[e,i,a,s,n.nodeName];t.push(c)}},I=(t,e,r,s)=>{if(o(r)){const o=e[r],i=typeof o;"function"===i?t.push([r,5]):"object"===i&&null!=o&&"Object"!==(s=n(o))?o.nodeType?t.push([r,o.nodeType]):t.push([r,s]):"symbol"!==i&&(r.toUpperCase()===r?t.push([r,6,o]):t.push([r,6]))}},x={Anchor:"A",DList:"DL",Image:"IMG",OList:"OL",Paragraph:"P",TableCaption:"CAPTION",TableCell:"TD",TableCol:"COLGROUP",TableRow:"TR",TableSection:"TBODY",UList:"UL"},A=t=>(t=t.substr(4).replace("Element",""),x[t]||t);(async t=>{let e;const n=t.parent,s=await(async(t,n)=>{const s=t.navigator.serviceWorker,o=await s.getRegistration();return s.addEventListener("message",(t=>{return n=t.data,s=t=>o.active&&o.active.postMessage(t),(async(t,e)=>{const n={C:e.C},s=r(e.$tasks$);for(let r=0;r<s;r++)try{let s,i,a=e.$tasks$[r],c=a.O,l=a.t,h=a.a;if(u[c]||await new Promise((t=>{let e=0,r=()=>{u[c]||e++>999?t():setTimeout(r,9)};r()})),1===h[0]&&h[1]in u[c].L){const e=new u[c].L[h[1]](...$(t,h[2]));m(e,l)}else s=d(c,l),s?(i=T(t,s,h,a.$groupedGetters$),a.c&&m(i,a.c),"object"==typeof(o=i)&&o&&o.then&&(i=await i,n.w=!0),n.H=g(c,i)):n.m=l+" not found"}catch(t){r===s-1?n.m=String(t.stack||t):console.error(t)}var o;return n})(e,n).then(s);var n,s})),o?(t,e,r)=>{0===r[0]?t.postMessage([1,L(e)]):((t,e,r)=>{const n=r[0];if(2===n)O(t,i(),e);else{const e=r[1],s=u[e];s&&(6===n?S(t,s):5===n&&((t,e,r,n,s)=>{(s=e.L.document.querySelector(`[data-ptid="${r}"]`))&&(n?s.dataset.pterror=n:s.type+="-x"),S(t,e)})(t,s,r[2],r[3]))}})(t,e,r)}:null})(t);s&&(e=new Worker(URL.createObjectURL(new Blob([\'(t=>{const e=Symbol(),r=Symbol(),n=Symbol(),s=Symbol(),i=Symbol(),o=new Map,a={},c=new WeakMap,l={},u={},h={},$={},d={},p=new Map,g=new Map,m="getClientRects,getBoundingClientRect".split(","),f="innerHeight,innerWidth,outerHeight,outerWidth,clientHeight,clientWidth,clientTop,clientLeft,scrollHeight,scrollWidth,scrollTop,scrollLeft,offsetHeight,offsetWidth,offsetTop,offsetLeft".split(","),w="childElementCount,children,firstElementChild,lastElementChild,nextElementSibling,previousElementSibling",y=()=>!0,v=t=>t.length,I=(t,e)=>Object.defineProperty(t,"name",{value:e}),S=[],b=()=>Math.round(9999999999*Math.random()+4),E="text/partytown",T=(t,e,r)=>Object.defineProperty(t.prototype,e,{...r,configurable:!0}),N=(t,e)=>Object.defineProperties(t.prototype,e),x=(t,e,r)=>T(t,e,{value:r,writable:!0}),M=[],L=(t,n,i,o,a)=>{const c=t[r];if(M.push({O:t[e],t:c,a:[...t[s],...n],c:o,$groupedGetters$:a}),!i)return W();setTimeout(W,40)},W=()=>{if(v(M)){const t=M[v(M)-1],e={C:b(),$tasks$:M.slice()};M.length=0;const r=((t,e)=>{const r=new XMLHttpRequest,n=t.z+"proxytown";return r.open("POST",n,!1),r.send(JSON.stringify(e)),JSON.parse(r.responseText)})($,e),n=r.w,s=st(t.t,t.a,r.H);if(r.m){if(n)return Promise.reject(r.m);throw new Error(r.m)}return n?Promise.resolve(s):s}},C=(t,e,r)=>L(t,e,!1,void 0,r),R=(t,e,r)=>{const n=[...e,nt(t,r),0];L(t,n,!0)},O=(t,e,r,n)=>{const s=e[v(e)-1],i=P.includes(s),o=[...e,nt(t,r)],a=L(t,o,i,n);return i||m.includes(s)||p.clear(),a},P="addEventListener,removeEventListener,createElement,createTextNode,insertBefore,insertRule,deleteRule,setAttribute,setItem,removeItem,classList.add,classList.remove,classList.toggle".split(","),A=(t,e)=>H(t[r],e),H=(t,e,r)=>(r=h[t])?r[e]:void 0,j=(t,e,n)=>U(t[r],e,n),U=(t,e,r,n)=>{(n=h[t]||{})[e]=r,h[t]=n},D=(t,e,r,n)=>{let s="";try{t.g=e,t.h="",k(t,r)}catch(t){console.error(r,t),s=String(t.stack||t)+""}return t.g=-1,t.h="",s},k=(t,e)=>{new Function(`with(this){${e}}`).apply(t.L)},B=(t,e,r)=>{(r=H(t,e))&&setTimeout((()=>r.map((t=>t({type:e})))),undefined)},F=(t,e,r)=>{for(r=t.A;!r.host&&(r=(t=d[t.E]).A,t.O!==t.E););const n=new URL(e||"",r);if($.e.resolveUrl){const t=$.e.resolveUrl(n,r);if(t)return t}return n},_=(t,e)=>F(t,e)+"",z=t=>F(Z(t),A(t,4)),J=()=>`<script src=${JSON.stringify($.z+"partytown.js")} async defer><\\\\/script>`,q=t=>class{constructor(){this.s="",this.l=[],this.e=[]}get src(){return this.s}set src(e){const r=d[t];fetch(_(r,e),{mode:"no-cors",keepalive:!0}).then((t=>{t.ok?this.l.map((t=>t({type:"load"}))):this.e.map((t=>t({type:"error"})))}),(()=>this.e.forEach((t=>t({type:"error"})))))}addEventListener(t,e){"load"===t&&this.l.push(e),"error"===t&&this.e.push(e)}get onload(){return this.l[0]}set onload(t){this.l=[t]}get onerror(){return this.e[0]}set onerror(t){this.e=[t]}},G=(t,e,r)=>{let n=o.get(e);return n||(n=V(t,e,r),o.set(e,n)),n},V=(e,r,n)=>new(l[n]?l[n]:n.includes("-")?l.UNKNOWN:t.HTMLElement)(e,r,[],n);class X extends URL{assign(){}reload(){}replace(){}}class Y{constructor(t,o,a,c){this[e]=t,this[r]=o,this[s]=a||[],this[n]=c,this[i]={}}}class K extends Y{constructor(t,e,r,n){return super(t,e,r,n),new Proxy(this,{get:(t,e)=>C(t,[e]),set:(t,e,r)=>(R(t,[e],r),!0)})}}class Window extends Y{constructor(e,r,n){super(e,0);for(const e in t)if(!(e in this)&&"onmessage"!==e){const r=t[e];if(null!=r){const n="function"==typeof r&&!r.toString().startsWith("class");this[e]=n?r.bind(t):r}}Object.getOwnPropertyNames(t).map((e=>{e in this||(this[e]=t[e])}));for(const t in u)this[t]=I(class{constructor(...r){const n=new(0,u[t])(e,b()),s=nt(n,r);return L(n,[1,t,s]),n}},t);const s=new Proxy(this,{has:()=>!0});return d[e]={O:e,E:r,L:s,k:V(e,1,"#document"),l:V(e,2,"HTML"),p:V(e,3,"HEAD"),d:V(e,4,"BODY"),A:new X(n)},this.requestAnimationFrame=t=>setTimeout((()=>t(performance.now())),9),this.cancelAnimationFrame=t=>clearTimeout(t),s}get body(){return Z(this).d}get document(){return Z(this).k}get documentElement(){return Z(this).l}get frameElement(){const t=Z(this),e=t.E,r=t.O;return r===e?null:G(e,r,"IFRAME")}get globalThis(){return this}get head(){return Z(this).p}get location(){return Z(this).A}set location(t){Z(this).A.href=t+""}get Image(){return q(this[e])}get name(){const t=this[e];return name+t}get navigator(){return(e=>{const r=t.navigator;return r.sendBeacon=(t,r)=>{const n=d[e];try{return fetch(_(n,t),{method:"POST",body:r,mode:"no-cors",keepalive:!0}),!0}catch(t){return console.error(t),!1}},r})(this[e])}get origin(){return Z(this).A.origin}get parent(){return d[Z(this).E].L}get self(){return this}get top(){for(const t in d)if(d[t].O===d[t].E)return d[t].L}get window(){return this}}const Q=({O:t,E:e,K:r})=>{d[t]?d[t].A.href=r:new Window(t,e,r),$.F([6,t])},Z=t=>d[t[e]];class Node extends Y{appendChild(t){return this.insertBefore(t,null)}get href(){}set href(t){}insertBefore(t,s){const i=t[e]=this[e],o=t[r],a=t[n],c="SCRIPT"===a,l="IFRAME"===a;if(c){const e=A(t,3);if(e){const r=D(Z(t),o,e),n=r?"pterror":"ptid",s=r||o;R(t,["type"],E+"-x"),R(t,["dataset",n],s),R(t,["innerHTML"],e)}}return O(this,["insertBefore"],[t,s]),l&&(t=>{let e=0;const n=t[r],s=()=>{if(d[n]&&d[n].v){let e=A(t,1)?"error":"load",r=A(t,e);r&&r.map((t=>t({type:e})))}else if(e++>2e3){let e=A(t,"error");e&&e.map((t=>t({type:"error"}))),console.error("Timeout")}else setTimeout(s,9)};s()})(t),c&&(W(),$.F([6,i])),t}get nodeName(){return this[n]}get nodeType(){return 3}get ownerDocument(){return Z(this).k}}class tt{constructor(t){this.name=t[0],this.value=t[1]}get nodeName(){return this.name}get nodeType(){return 2}}class NodeList{constructor(t){(this._=t).map(((t,e)=>this[e]=t))}entries(){return this._.entries()}forEach(t,e){this._.map(t,e)}item(t){return this[t]}keys(){return this._.keys()}get length(){return v(this._)}values(){return this._.values()}[Symbol.iterator](){return this._[Symbol.iterator]()}}const et=(t,n,s,i)=>{if(void 0!==s){let u=typeof s;if("string"===u||"boolean"===u||"number"===u||null==s)return[9,s];if("function"===u)return[10,{O:t,t:n,G:(o=s,(l=c.get(o))||(c.set(o,l=b()),a[l]=o),l)}];if(i=i||new Set,Array.isArray(s))return i.has(s)?[0,[]]:[0,s.map((e=>et(t,n,e,i)))];if("object"===u)return"number"==typeof s[r]?[6,{O:s[e],t:s[r]}]:s instanceof Event?[4,rt(t,n,s,!1,i)]:[8,rt(t,n,s,!0,i)]}var o,l},rt=(t,e,r,n,s,i,o,a)=>{if(i={},!s.has(r))for(o in s.add(r),r)a=r[o],(n||"function"!=typeof a)&&(i[o]=et(t,e,a,s));return i},nt=(t,n)=>t?et(t[e],t[r],n):[9,n],st=(t,e,r,n,s)=>{if(r){if(n=r[0],s=r[1],9===n||2===n||3===n)return s;if(10===n)return ct(e,s);if(6===n)return ot(s);if(7===n)return new NodeList(s.map(ot));if(1===n)return new tt(s);if(0===n)return s.map((r=>st(t,e,r)));if(4===n)return i=it(t,e,s),new Proxy(new Event(i.type,i),{get:(t,e)=>e in i?i[e]:t[String(e)]});if(8===n)return it(t,e,s)}var i},it=(t,e,r,n,s)=>{for(s in n={},r)n[s]=st(t,[...e,s],r[s]);return n},ot=({O:t,t:e,D:r})=>at(t,e)||G(t,e,r),at=(t,e)=>{const r=d[t];return 0===e?r.L:1===e?r.k:2===e?r.l:3===e?r.p:4===e?r.d:void 0},ct=(t,{O:e,t:r,D:n,G:s})=>(a[s]||c.set(a[s]=function(...s){const i=G(e,r,n);return O(i,t,s)},s),a[s]),lt={sheet:{get(){return new ut(this)}}};class ut{constructor(t){this.ownerNode=t}get cssRules(){const t=this.ownerNode;return new Proxy({},{get(e,r){const n=String(r);return"item"===n?e=>$t(t,e):"length"===n?ht(t).length:isNaN(n)?e[r]:$t(t,n)}})}insertRule(t,e){const r=ht(this.ownerNode);return(e=void 0===e?0:e)>=0&&e<=r.length&&(O(this.ownerNode,["sheet","insertRule"],[t,e]),r.splice(e,0,0)),e}deleteRule(t){O(this.ownerNode,["sheet","deleteRule"],[t]),ht(this.ownerNode).splice(t,1)}}const ht=t=>{let e=A(t,2);return e||(e=C(t,["sheet","cssRules"]),j(t,2,e)),e},$t=(t,e)=>{let r=ht(t);return 0===r[e]&&(r[e]=C(t,["sheet","cssRules",parseInt(e,10)])),r[e]},dt={body:{get(){return Z(this).d}},createElement:{value(t){t=t.toUpperCase();const r=this[e],n=b(),s=G(r,n,t);return O(this,["createElement"],[t],n),"IFRAME"===t?(Q({O:n,E:r,K:"about:blank"}),R(s,["srcdoc"],J())):"SCRIPT"===t&&R(s,["type"],E),s}},createElementNS:{value(t,r){r=r.toUpperCase();const n=this[e],s=b(),i=G(n,s,r);return O(this,["createElementNS"],[t,r],s),i}},createTextNode:{value(t){const r=this[e],n=b(),s=G(r,n,"#text");return O(this,["createTextNode"],[t],n),s}},createEvent:{value:t=>new Event(t)},currentScript:{get(){const t=this[e],r=Z(this).g;return r>0?G(t,r,"SCRIPT"):null}},defaultView:{get(){return Z(this).L}},documentElement:{get(){return Z(this).l}},getElementsByTagName:{value(t){return"BODY"===(t=t.toUpperCase())?[Z(this).d]:"HEAD"===t?[Z(this).p]:O(this,["getElementsByTagName"],[t])}},head:{get(){return Z(this).p}},implementation:{value:{hasFeature:y}},location:{get(){return Z(this).A},set(t){Z(this).A.href=t+""}},nodeType:{value:9},parentNode:{value:null},parentElement:{value:null},readyState:{value:"complete"}},pt={localName:{get(){return this[n].toLowerCase()}},namespaceURI:{get(){return"http://www.w3.org/"+("SVG"===this[n]?"2000/svg":"1999/xhtml")}},nodeType:{value:1},tagName:{get(){return this[n]}}},gt={hash:{get(){return z(this).hash}},host:{get(){return z(this).host}},hostname:{get(){return z(this).hostname}},href:{get(){return z(this).href},set(t){j(this,4,t+=""),R(this,["href"],t)}},origin:{get(){return z(this).origin}},pathname:{get(){return z(this).pathname}},port:{get(){return z(this).port}},protocol:{get(){return z(this).protocol}},search:{get(){return z(this).search}}},mt={getContext:{value(...n){const s=["getContext",nt(this,n)];return new t.CanvasRenderingContext2D(this[e],this[r],s)}}},ft={addEventListener:{value(...t){const e=t[0],r=A(this,e)||[];r.push(t[1]),j(this,e,r)}},async:{get:y,set:y},defer:{get:y,set:y},onload:{get(){let t=A(this,"load");return t&&t[0]||null},set(t){j(this,"load",t?[t]:null)}},onerror:{get(){let t=A(this,"error");return t&&t[0]||null},set(t){j(this,"error",t?[t]:null)}}},wt={contentDocument:{get(){return this.contentWindow.document}},contentWindow:{get(){const t=this[r];return d[t].L}},src:{get(){return A(this,4)||""},set(t){let e,r=new XMLHttpRequest;t=_(Z(this),t),j(this,1,void 0),j(this,4,t),r.open("GET",t,!1),r.send(),e=r.status,e>199&&e<300?R(this,["srcdoc"],((t,e)=>`<base href="${t}">`+e.replace(/<script>/g,\\\'<script type="text/partytown">\\\').replace(/<script /g,\\\'<script type="text/partytown" \\\').replace(/text\\\\/javascript/g,E)+J())(t,r.responseText)):j(this,1,e)}},...ft},yt={get(){return A(this,3)||""},set(t){j(this,3,t)}},vt={innerHTML:yt,innerText:yt,src:{get(){return A(this,4)||""},set(t){t=_(Z(this),t),j(this,4,t),R(this,["src"],t)}},getAttribute:{value(t){return"src"===t?this.src:O(this,["getAttribute"],[t])}},setAttribute:{value(t,e){"src"===t?this.src=e:O(this,["setAttribute"],[t,e])}},textContent:yt,type:{get(){return C(this,["type"])},set(t){"text/javascript"!==t&&R(this,["type"],t)}},...ft},It=([o,a,c,h,$])=>{const d=St[o]?K:"Object"===a||"EventTarget"===a?Y:t[a],p=t[o]=I(t[o]||class extends d{},o);12===h&&(u[o]=p),$&&(l[$]=p),c.map((([o,a,c])=>{o in p.prototype||o in d.prototype||("string"==typeof a?T(p,o,{get(){if(!this[i][o]){const c=this[e],l=this[r],u=[...this[s],o],h=this[n],$=t[a];this[i][o]=new $(c,l,u,h)}return this[i][o]},set(t){this[i][o]=t}}):5===a?x(p,o,(function(...t){return O(this,[o],t)})):a>0&&(void 0!==c?x(p,o,c):T(p,o,{get(){return C(this,[o])},set(t){return R(this,[o],t)}})))}))},St={CSSStyleDeclaration:1,DOMStringMap:1,NamedNodeMap:1},bt=(t,e)=>x(t,"nodeType",e),Et=(t,e)=>e.split(",").map((e=>T(t,e,{get(){let t=Tt(this,e),r=g.get(t);return r||(r=C(this,[e]),g.set(t,r)),r}}))),Tt=(t,n)=>t[e]+"."+t[r]+"."+n,Nt=(t,e)=>Object.keys(e).map((r=>x(t,r,e[r]))),xt=t=>f.map((e=>{T(t,e,{get(){const t=p.get(Tt(this,e));if("number"==typeof t)return t;const r=C(this,[e],f);return Object.entries(r).map((([t,e])=>{p.set(Tt(this,t),e)})),r[e]}})})),Mt=t=>m.map((e=>{t.prototype[e]=function(){let t=Tt(this,e),r=p.get(t);return r||(r=O(this,[e],S),p.set(t,r)),r}})),Lt=[],Wt=e=>{const r=e.data,n=r[0];var s;$.v?6===n?(async e=>{let r,n,s=e.O,i=e.t,o=e.f,a=e.K,c="",l=d[s];if(a)try{n=F(l,a),a=n+"",U(i,4,a),r=await t.fetch(a),r.ok?(o=await r.text(),l.g=i,l.h=a,k(l,o),B(i,"load")):(console.error(r.status,"url:",a),c=r.statusText,B(i,"error"))}catch(t){console.error("url:",a,t),c=String(t.stack||t)+"",B(i,"error")}else o&&(c=D(l,i,o));l.g=-1,l.h="",$.F([5,s,i,c])})(r[1]):7===n?(({t:t,G:e,J:r,b:n})=>{if(a[e])try{const s=st(t,[],r),i=st(t,[],n);a[e].apply(s,i)}catch(t){console.error(t)}})(r[1]):8===n?(({O:e,t:r,n:n,b:s})=>{try{const i=d[e].L,o=n[0]in i?i:n[0]in t?t:{},a=st(r,[],s),c=o[n[0]];Array.isArray(c)?c.push(...a):"function"==typeof c&&c.apply(o,a)}catch(t){console.error(t)}})(r[1]):3===n?Q(r[1]):4===n&&(d[r[1]].v=1):1===n?(s=r[1],Object.assign($,s),$.e=JSON.parse($.e),(t=>{let e=$.e[t];e&&((e.startsWith("(")||e.startsWith("function"))&&(e=`${t}:${e}`),Object.assign($.e,new Function(`return{${e}}`)()))})("resolveUrl"),$.o=($.e.forward||S).map((t=>t[0])),$.F=postMessage.bind(t),t.postMessage=t.importScripts=void 0,t.Node=Node,t.Window=Window,t.CSSStyleSheet=ut,$.s.map(It),(()=>{const e=t.Element,r=t.DocumentFragment;"atob,btoa,crypto,indexedDB,performance,setTimeout,setInterval,clearTimeout,clearInterval".split(",").map((t=>delete Window.prototype[t])),N(e,pt),N(t.Document,dt),N(t.HTMLAnchorElement,gt),N(t.HTMLCanvasElement,mt),N(t.HTMLIFrameElement,wt),N(t.HTMLScriptElement,vt),N(t.HTMLStyleElement,lt),Nt(ut,{type:"text/css"}),bt(t.Comment,8),bt(t.DocumentType,10),bt(r,11),Et(Node,"childNodes,firstChild,isConnected,lastChild,nextSibling,parentElement,parentNode,previousSibling"),Et(e,w),Et(r,w),xt(e),xt(Window),Mt(e)})(),$.v=1,$.F([2]),Lt.slice().forEach(Wt),Lt.length=0):Lt.push(e)};t.onmessage=Wt,postMessage([0])})(self);\\n\'],{type:"text/javascript"})),{name:"Partytown 🎉"}),e.onmessage=t=>s(e,n,t.data),n.addEventListener("pt1",(t=>{const r=t.detail,n=p(r.frameElement);O(e,n,r)})))})(t)})(window);\n<\/script></head></html>',false)):o.endsWith("proxytown")&&n.respondWith(((n,s)=>new Promise((async o=>{const i=await n.clone().json(),a=await(r=>new Promise((async n=>{const s=[...await self.clients.matchAll()].sort(((t,e)=>t.url>e.url?-1:t.url<e.url?1:0))[0];if(s){const o=[n,setTimeout((()=>{t.delete(r.C),n(e(r,"Timeout"))}),1e4)];t.set(r.C,o),s.postMessage(r)}else n(e(r,"No Party"))})))(i);o(r(JSON.stringify(a),s,"application/json"))})))(s,false))}; |
@@ -1,1 +0,1 @@ | ||
!function(t,e,n,i,r,o,a){function s(t){r||((r=e.createElement("iframe")).dataset.partytown="sandbox",r.setAttribute("style","display:block;width:0;height:0;border:0;visibility:hidden"),r.setAttribute("aria-hidden","true"),r.src=i+"partytown-sandbox-"+t+".html?"+Date.now(),e.body.appendChild(r))}function c(t,n){for(clearTimeout(a),r=1,t=0;t<o.length;t++)(n=e.createElement("script")).innerHTML=o[t].innerHTML,e.body.appendChild(n)}i=(t.partytown||{}).lib||"/~partytown/",o=e.querySelectorAll('script[type="text/partytown"]'),top!==t?top.dispatchEvent(new CustomEvent("pt1",{detail:t})):o.length&&(a=setTimeout(c,1e4),e.addEventListener("pt0",(function(){clearTimeout(a)})),t.crossOriginIsolated?s("atomics"):"serviceWorker"in n?n.serviceWorker.register(i+"partytown-sw.js",{scope:i}).then((function(t){t.active?s("sw"):t.installing?t.installing.addEventListener("statechange",(function(t){"activated"===t.target.state&&s("sw")})):console.warn(t)}),(function(t){console.error(t)})):c())}(window,document,navigator); | ||
!function(t,e,n,i,o,r,s){function a(t){o||((o=e.createElement("iframe")).dataset.partytown="sandbox",o.setAttribute("style","display:block;width:0;height:0;border:0;visibility:hidden"),o.setAttribute("aria-hidden","true"),o.src=i+"partytown-sandbox-"+t+".html?"+Date.now(),e.body.appendChild(o))}function c(t,n){for(clearTimeout(s),o=1,t=0;t<r.length;t++)(n=e.createElement("script")).innerHTML=r[t].innerHTML,e.body.appendChild(n)}if(i=(t.partytown||{}).lib||"/~partytown/",r=e.querySelectorAll('script[type="text/partytown"]'),top!==t)top.dispatchEvent(new CustomEvent("pt1",{detail:t}));else if(r.length){if(s=setTimeout(c,1e4),e.addEventListener("pt0",(function(){clearTimeout(s)})),t.crossOriginIsolated)a("atomics");else if("serviceWorker"in n){const e=t.crossOriginIsolated?"?isolated":"";n.serviceWorker.register(i+"partytown-sw.js"+e,{scope:i}).then((function(t){t.active?a("sw"):t.installing?t.installing.addEventListener("statechange",(function(t){"activated"===t.target.state&&a("sw")})):console.warn(t)}),(function(t){console.error(t)}))}else c()}}(window,document,navigator); |
{ | ||
"name": "@builder.io/partytown", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Relocate resource intensive 3rd-party scripts off of the main thread and into a web worker.", | ||
@@ -31,8 +31,12 @@ "license": "MIT", | ||
"release": "npm run build && npm test && np --no-tests", | ||
"serve": "sirv tests --port 4000 --dev", | ||
"serve.test": "sirv tests --port 4001 --dev --quiet", | ||
"serve": "node scripts/serve.js 4000", | ||
"serve.test": "node scripts/serve.js 4001", | ||
"serve.atomics": "node scripts/serve.js 4000 --atomics", | ||
"serve.atomics.test": "node scripts/serve.js 4002 --atomics", | ||
"test": "playwright test tests/platform --browser=chromium", | ||
"test.atomics": "playwright test tests/platform --config playwright.atomics.config.ts --browser=chromium", | ||
"test.webkit": "playwright test tests/platform --browser=webkit", | ||
"tsc.watch": "tsc -w", | ||
"version": "npm run build.prod" | ||
"version": "npm run build.prod", | ||
"fmt": "prettier --config package.json --write src" | ||
}, | ||
@@ -43,3 +47,3 @@ "devDependencies": { | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/react": "^17.0.35", | ||
"@types/react": "^17.0.37", | ||
"concurrently": "^6.4.0", | ||
@@ -51,5 +55,4 @@ "fs-extra": "^10.0.0", | ||
"prettier": "^2.4.1", | ||
"rollup": "^2.60.0", | ||
"rollup": "^2.60.1", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"sirv-cli": "^1.0.14", | ||
"tslib": "^2.3.1", | ||
@@ -56,0 +59,0 @@ "typescript": "^4.5.2" |
@@ -48,2 +48,11 @@ /** | ||
/** | ||
* The `resolveUrl()` hook can be used to modify the URL about to be | ||
* requested, which could be used to rewrite urls so they go through a proxy. | ||
* | ||
* @param url - The URL to be resolved. This is a URL https://developer.mozilla.org/en-US/docs/Web/API/URL, not a string. | ||
* @param location - The current window location. | ||
* @returns The returned value must be a URL interface, otherwise the default resolved URL is used. | ||
*/ | ||
resolveUrl?(url: URL, location: Location): URL | undefined | null; | ||
/** | ||
* When set to `true`, Partytown scripts are not inlined and not minified. | ||
@@ -50,0 +59,0 @@ */ |
@@ -6,4 +6,4 @@ { | ||
"types": "index.d.ts", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"private": true | ||
} |
@@ -12,3 +12,3 @@ # Partytown 🎉 | ||
Partytown is a lazy-loaded `6kb` library to help relocate resource intensive scripts into a [web worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API), and off of the [main thread](https://developer.mozilla.org/en-US/docs/Glossary/Main_thread). Its goal is to help speed up sites by dedicating the main thread to your code, and offloading third-party scripts to a web worker. | ||
Partytown is a lazy-loaded library to help relocate resource intensive scripts into a [web worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API), and off of the [main thread](https://developer.mozilla.org/en-US/docs/Glossary/Main_thread). Its goal is to help speed up sites by dedicating the main thread to your code, and offloading third-party scripts to a web worker. | ||
@@ -157,6 +157,8 @@ - [Information](#information) | ||
[Atomics](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics) are the latest and greatest way to accomplish the challenge of _synchronously_ sending data between the main thread and the web worker. Honestly, it looks like Atomics may be the preferred and "correct" way to perform these tasks. However, as of right now, more research is needed into how Atomics could be used in production, while also using with the service worker fallback when Atomics are not supported. | ||
Partytown will use [Atomics](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics) when they're enabled by the browser. | ||
See [Draft PR #10](https://github.com/BuilderIO/partytown/pull/10) for more info. | ||
To enable Atomics communication, the browser's [crossOriginIsolated](https://developer.mozilla.org/en-US/docs/Web/API/crossOriginIsolated) boolean must be `true`. More details can be found at [Making your website "cross-origin isolated" using COOP and COEP](https://web.dev/coop-coep/). | ||
More research needs to be done to better document and understand how to best enable Atomics. If you're interested in helping, please ping us in the [Partytown Discord](https://discord.gg/hbuEtxdEZ3). ⚛️ | ||
### Browser Features And Fallback | ||
@@ -163,0 +165,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
246720
14
4164
372