partytown-fix 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Builder.io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Partytown 🎉
2
+
3
+ <img width="838" alt="Partytown github fit 2x" src="https://user-images.githubusercontent.com/452425/134568488-f36f4640-9ada-4a78-a969-2b8315cf7f47.png">
4
+
5
+ - [Introducing Partytown: Run Third-Party Scripts From a Web Worker](https://dev.to/adamdbradley/introducing-partytown-run-third-party-scripts-from-a-web-worker-2cnp)
6
+ - [How Partytown's Sync Communication Works](https://dev.to/adamdbradley/how-partytown-s-sync-communication-works-4244)
7
+ - [How we cut 99% of our JavaScript with Qwik + Partytown](https://www.builder.io/blog/how-we-cut-99-percent-js-with-qwik-and-partytown)
8
+ - [Partytown is now in Beta](https://www.builder.io/blog/partytown-is-now-in-beta)
9
+
10
+ > A fun location for your third-party scripts to hang out
11
+
12
+ 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.
13
+
14
+ > Note: Partytown is still in beta and not guaranteed to work in every scenario. Please see our [FAQ](https://partytown.qwik.dev/faq) and [Trade-Off](https://partytown.qwik.dev/trade-offs) sections for more info.
15
+
16
+ The philosophy is that the main thread should be dedicated to your code, and any scripts that are not required to be in the [critical path](https://developers.google.com/web/fundamentals/performance/critical-rendering-path) should be moved to a web worker. Main thread performance is, without question, more important than web worker thread performance.
17
+
18
+ - [Getting Started](https://partytown.qwik.dev/getting-started)
19
+ - [Integrations](https://partytown.qwik.dev/integrations)
20
+ - [Configuration](https://partytown.qwik.dev/configuration)
21
+ - [Releases](https://github.com/BuilderIO/partytown/releases)
22
+ - [FAQs](https://partytown.qwik.dev/faq)
23
+
24
+ ![Without Partytown and With Partytown: Your code and third-party code compete for main thread resources](https://user-images.githubusercontent.com/452425/152393346-6f721a4f-3f66-410a-8878-a2b49e24307f.png)
25
+
26
+ ## Community
27
+
28
+ - [@QwikDev](https://twitter.com/QwikDev)
29
+ - [@Builderio](https://twitter.com/builderio)
30
+ - [Local Development](https://github.com/BuilderIO/partytown/blob/main/CONTRIBUTING.md#local-development)
31
+ - [For Plugin Authors / Developers](https://github.com/BuilderIO/partytown/blob/main/CONTRIBUTING.md#plugin-authors-developers)
32
+
33
+ ## Related Projects
34
+
35
+ - [Qwik](https://github.com/BuilderIO/qwik): An open-source framework designed for best possible time to interactive, by focusing on resumability of server-side-rendering of HTML, and fine-grained lazy-loading of code.
36
+ - [Mitosis](https://github.com/BuilderIO/mitosis): Write components once, run everywhere. Compiles to Vue, React, Solid, Angular, Svelte, and more.
37
+ - [Builder](https://github.com/BuilderIO/builder): Drag and drop page builder and CMS for React, Vue, Angular, and more.
38
+
39
+ <br>
40
+ <br>
41
+ <p align="center">
42
+ <a href="https://www.builder.io/m/developers">
43
+ <picture>
44
+ <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/844291/230786554-eb225eeb-2f6b-4286-b8c2-535b1131744a.png">
45
+ <img width="250" alt="Made with love by Builder.io" src="https://user-images.githubusercontent.com/844291/230786555-a58479e4-75f3-4222-a6eb-74c5af953eac.png">
46
+ </picture>
47
+ </a>
48
+ </p>
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+
3
+ async function run() {
4
+ const task = process.argv.slice(2).filter((a) => !a.startsWith('-'))[0];
5
+ const args = process.argv.slice(2).filter((a) => a !== task);
6
+
7
+ if (task === 'help' || args.includes('--help') || args.includes('-h')) {
8
+ help();
9
+ } else if (task === 'version' || args.includes('--version') || args.includes('-v')) {
10
+ console.log(version());
11
+ } else if (task === 'copylib') {
12
+ await copyLibTask(args);
13
+ } else {
14
+ panic('Unknown partytown task: ' + task);
15
+ }
16
+ }
17
+
18
+ async function copyLibTask(args) {
19
+ try {
20
+ const utils = require('../utils/index.cjs');
21
+ const destDir = args.filter((a) => !a.startsWith('-'))[0];
22
+ const logResult = !args.includes('--silent');
23
+ const includeDebugDir = !args.includes('--no-debug');
24
+ const result = await utils.copyLibFiles(destDir, {
25
+ debugDir: includeDebugDir,
26
+ });
27
+
28
+ if (logResult) {
29
+ console.log('Partytown lib copied to: ' + result.dest);
30
+ }
31
+ } catch (e) {
32
+ panic(String(e.message || e));
33
+ }
34
+ }
35
+
36
+ function help() {
37
+ console.log(``);
38
+ console.log(`Partytown (${version()}):`);
39
+ console.log(``);
40
+ console.log(` copylib <destDir> [--no-debug | --silent]`);
41
+ console.log(``);
42
+ }
43
+
44
+ function version() {
45
+ return require('../package.json').version;
46
+ }
47
+
48
+ function panic(msg) {
49
+ console.error('\n❌ ' + msg);
50
+ help();
51
+ process.exit(1);
52
+ }
53
+
54
+ run();
package/index.cjs ADDED
@@ -0,0 +1 @@
1
+ exports.version = "0.13.0-dev1774181540811";
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const version: string;
package/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export const version = "0.13.0-dev1774181540811";
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ const PartytownSnippet = "/* Partytown 0.13.0-dev1774181540811 - MIT QwikDev */\nconst t={preserveBehavior:!1},e=e=>{if(\"string\"==typeof e)return[e,t];const[n,r=t]=e;return[n,{...t,...r}]},n=Object.freeze((t=>{const e=new Set;let n=[];do{Object.getOwnPropertyNames(n).forEach((t=>{\"function\"==typeof n[t]&&e.add(t)}))}while((n=Object.getPrototypeOf(n))!==Object.prototype);return Array.from(e)})());!function(t,r,o,i,a,s,c,l,d,p,u=t,f){function h(){f||(f=1,\"/\"==(c=(s.lib||\"/~partytown/\")+(s.debug?\"debug/\":\"\"))[0]&&(d=r.querySelectorAll('script[type=\"text/partytown\"]'),i!=t?i.dispatchEvent(new CustomEvent(\"pt1\",{detail:t})):(l=setTimeout(v,(null==s?void 0:s.fallbackTimeout)||999999999),r.addEventListener(\"pt0\",w),a?y(1):o.serviceWorker?o.serviceWorker.register(c+(s.swPath||\"partytown-sw.js\"),{scope:c}).then((function(t){t.active?y():t.installing&&t.installing.addEventListener(\"statechange\",(function(t){\"activated\"==t.target.state&&y()}))}),console.error):v())))}function y(e){p=r.createElement(e?\"script\":\"iframe\"),t._pttab=Date.now(),e||(p.style.display=\"block\",p.style.width=\"0\",p.style.height=\"0\",p.style.border=\"0\",p.style.visibility=\"hidden\",p.setAttribute(\"aria-hidden\",!0)),p.src=c+\"partytown-\"+(e?\"atomics.js?v=0.13.0-dev1774181540811\":\"sandbox-sw.html?\"+t._pttab),r.querySelector(s.sandboxParent||\"body\").appendChild(p)}function v(n,o){for(w(),i==t&&(s.forward||[]).map((function(n){const[r]=e(n);delete t[r.split(\".\")[0]]})),n=0;n<d.length;n++)(o=r.createElement(\"script\")).innerHTML=d[n].innerHTML,o.nonce=s.nonce,r.head.appendChild(o);p&&p.parentNode.removeChild(p)}function w(){clearTimeout(l)}s=t.partytown||{},i==t&&(s.forward||[]).map((function(r){const[o,{preserveBehavior:i}]=e(r);u=t,o.split(\".\").map((function(e,r,o){var a;u=u[o[r]]=r+1<o.length?u[o[r]]||(a=o[r+1],n.includes(a)?[]:{}):(()=>{let e=null;if(i){const{methodOrProperty:n,thisObject:r}=((t,e)=>{let n=t;for(let t=0;t<e.length-1;t+=1)n=n[e[t]];return{thisObject:n,methodOrProperty:e.length>0?n[e[e.length-1]]:void 0}})(t,o);\"function\"==typeof n&&(e=(...t)=>n.apply(r,...t))}return function(){let n;return e&&(n=e(arguments)),(t._ptf=t._ptf||[]).push(o,arguments),n}})()}))})),\"complete\"==r.readyState?h():(t.addEventListener(\"DOMContentLoaded\",h),t.addEventListener(\"load\",h))}(window,document,navigator,top,window.crossOriginIsolated);";
4
+
5
+ /**
6
+ * The `type` attribute for Partytown scripts, which does two things:
7
+ *
8
+ * 1. Prevents the `<script>` from executing on the main thread.
9
+ * 2. Is used as a selector so the Partytown library can find all scripts to execute in a web worker.
10
+ *
11
+ * @public
12
+ */
13
+ const SCRIPT_TYPE = `text/partytown`;
14
+ const getMethods = (obj) => {
15
+ const properties = new Set();
16
+ let currentObj = obj;
17
+ do {
18
+ Object.getOwnPropertyNames(currentObj).forEach((item) => {
19
+ if (typeof currentObj[item] === 'function') {
20
+ properties.add(item);
21
+ }
22
+ });
23
+ } while ((currentObj = Object.getPrototypeOf(currentObj)) !== Object.prototype);
24
+ return Array.from(properties);
25
+ };
26
+ Object.freeze(getMethods([]));
27
+ function serializeConfig(config) {
28
+ return JSON.stringify(config, (key, value) => {
29
+ if (typeof value === 'function') {
30
+ value = String(value);
31
+ if (value.startsWith(key + '(')) {
32
+ value = 'function ' + value;
33
+ }
34
+ }
35
+ if (key === 'loadScriptsOnMainThread') {
36
+ value = value.map((scriptUrl) => Array.isArray(scriptUrl)
37
+ ? scriptUrl
38
+ : [
39
+ typeof scriptUrl === 'string' ? 'string' : 'regexp',
40
+ typeof scriptUrl === 'string' ? scriptUrl : scriptUrl.source,
41
+ ]);
42
+ }
43
+ return value;
44
+ });
45
+ }
46
+
47
+ const createSnippet = (config, snippetCode) => {
48
+ const { forward = [], ...filteredConfig } = config || {};
49
+ const configStr = serializeConfig(filteredConfig);
50
+ return [
51
+ `!(function(w,p,f,c){`,
52
+ `if(!window.crossOriginIsolated && !navigator.serviceWorker) return;`,
53
+ Object.keys(filteredConfig).length > 0
54
+ ? `c=w[p]=Object.assign(w[p]||{},${configStr});`
55
+ : `c=w[p]=w[p]||{};`,
56
+ `c[f]=(c[f]||[])`,
57
+ forward.length > 0 ? `.concat(${JSON.stringify(forward)})` : ``,
58
+ `})(window,'partytown','forward');`,
59
+ snippetCode,
60
+ ].join('');
61
+ };
62
+
63
+ /**
64
+ * Function that returns the Partytown snippet as a string, which can be
65
+ * used as the innerHTML of the inlined Partytown script in the head.
66
+ *
67
+ * @public
68
+ */
69
+ const partytownSnippet = (config) => createSnippet(config, PartytownSnippet);
70
+
71
+ exports.SCRIPT_TYPE = SCRIPT_TYPE;
72
+ exports.partytownSnippet = partytownSnippet;
@@ -0,0 +1,69 @@
1
+ const PartytownSnippet = "/* Partytown 0.13.0-dev1774181540811 - MIT QwikDev */\nconst t={preserveBehavior:!1},e=e=>{if(\"string\"==typeof e)return[e,t];const[n,r=t]=e;return[n,{...t,...r}]},n=Object.freeze((t=>{const e=new Set;let n=[];do{Object.getOwnPropertyNames(n).forEach((t=>{\"function\"==typeof n[t]&&e.add(t)}))}while((n=Object.getPrototypeOf(n))!==Object.prototype);return Array.from(e)})());!function(t,r,o,i,a,s,c,l,d,p,u=t,f){function h(){f||(f=1,\"/\"==(c=(s.lib||\"/~partytown/\")+(s.debug?\"debug/\":\"\"))[0]&&(d=r.querySelectorAll('script[type=\"text/partytown\"]'),i!=t?i.dispatchEvent(new CustomEvent(\"pt1\",{detail:t})):(l=setTimeout(v,(null==s?void 0:s.fallbackTimeout)||999999999),r.addEventListener(\"pt0\",w),a?y(1):o.serviceWorker?o.serviceWorker.register(c+(s.swPath||\"partytown-sw.js\"),{scope:c}).then((function(t){t.active?y():t.installing&&t.installing.addEventListener(\"statechange\",(function(t){\"activated\"==t.target.state&&y()}))}),console.error):v())))}function y(e){p=r.createElement(e?\"script\":\"iframe\"),t._pttab=Date.now(),e||(p.style.display=\"block\",p.style.width=\"0\",p.style.height=\"0\",p.style.border=\"0\",p.style.visibility=\"hidden\",p.setAttribute(\"aria-hidden\",!0)),p.src=c+\"partytown-\"+(e?\"atomics.js?v=0.13.0-dev1774181540811\":\"sandbox-sw.html?\"+t._pttab),r.querySelector(s.sandboxParent||\"body\").appendChild(p)}function v(n,o){for(w(),i==t&&(s.forward||[]).map((function(n){const[r]=e(n);delete t[r.split(\".\")[0]]})),n=0;n<d.length;n++)(o=r.createElement(\"script\")).innerHTML=d[n].innerHTML,o.nonce=s.nonce,r.head.appendChild(o);p&&p.parentNode.removeChild(p)}function w(){clearTimeout(l)}s=t.partytown||{},i==t&&(s.forward||[]).map((function(r){const[o,{preserveBehavior:i}]=e(r);u=t,o.split(\".\").map((function(e,r,o){var a;u=u[o[r]]=r+1<o.length?u[o[r]]||(a=o[r+1],n.includes(a)?[]:{}):(()=>{let e=null;if(i){const{methodOrProperty:n,thisObject:r}=((t,e)=>{let n=t;for(let t=0;t<e.length-1;t+=1)n=n[e[t]];return{thisObject:n,methodOrProperty:e.length>0?n[e[e.length-1]]:void 0}})(t,o);\"function\"==typeof n&&(e=(...t)=>n.apply(r,...t))}return function(){let n;return e&&(n=e(arguments)),(t._ptf=t._ptf||[]).push(o,arguments),n}})()}))})),\"complete\"==r.readyState?h():(t.addEventListener(\"DOMContentLoaded\",h),t.addEventListener(\"load\",h))}(window,document,navigator,top,window.crossOriginIsolated);";
2
+
3
+ /**
4
+ * The `type` attribute for Partytown scripts, which does two things:
5
+ *
6
+ * 1. Prevents the `<script>` from executing on the main thread.
7
+ * 2. Is used as a selector so the Partytown library can find all scripts to execute in a web worker.
8
+ *
9
+ * @public
10
+ */
11
+ const SCRIPT_TYPE = `text/partytown`;
12
+ const getMethods = (obj) => {
13
+ const properties = new Set();
14
+ let currentObj = obj;
15
+ do {
16
+ Object.getOwnPropertyNames(currentObj).forEach((item) => {
17
+ if (typeof currentObj[item] === 'function') {
18
+ properties.add(item);
19
+ }
20
+ });
21
+ } while ((currentObj = Object.getPrototypeOf(currentObj)) !== Object.prototype);
22
+ return Array.from(properties);
23
+ };
24
+ Object.freeze(getMethods([]));
25
+ function serializeConfig(config) {
26
+ return JSON.stringify(config, (key, value) => {
27
+ if (typeof value === 'function') {
28
+ value = String(value);
29
+ if (value.startsWith(key + '(')) {
30
+ value = 'function ' + value;
31
+ }
32
+ }
33
+ if (key === 'loadScriptsOnMainThread') {
34
+ value = value.map((scriptUrl) => Array.isArray(scriptUrl)
35
+ ? scriptUrl
36
+ : [
37
+ typeof scriptUrl === 'string' ? 'string' : 'regexp',
38
+ typeof scriptUrl === 'string' ? scriptUrl : scriptUrl.source,
39
+ ]);
40
+ }
41
+ return value;
42
+ });
43
+ }
44
+
45
+ const createSnippet = (config, snippetCode) => {
46
+ const { forward = [], ...filteredConfig } = config || {};
47
+ const configStr = serializeConfig(filteredConfig);
48
+ return [
49
+ `!(function(w,p,f,c){`,
50
+ `if(!window.crossOriginIsolated && !navigator.serviceWorker) return;`,
51
+ Object.keys(filteredConfig).length > 0
52
+ ? `c=w[p]=Object.assign(w[p]||{},${configStr});`
53
+ : `c=w[p]=w[p]||{};`,
54
+ `c[f]=(c[f]||[])`,
55
+ forward.length > 0 ? `.concat(${JSON.stringify(forward)})` : ``,
56
+ `})(window,'partytown','forward');`,
57
+ snippetCode,
58
+ ].join('');
59
+ };
60
+
61
+ /**
62
+ * Function that returns the Partytown snippet as a string, which can be
63
+ * used as the innerHTML of the inlined Partytown script in the head.
64
+ *
65
+ * @public
66
+ */
67
+ const partytownSnippet = (config) => createSnippet(config, PartytownSnippet);
68
+
69
+ export { SCRIPT_TYPE, partytownSnippet };
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@qwik.dev/partytown/integration",
3
+ "main": "index.cjs",
4
+ "module": "index.mjs",
5
+ "types": "index.d.ts",
6
+ "version": "0.13.0-dev1774181540811",
7
+ "private": true
8
+ }