@enhance-eng/sandbox 0.5.5 → 0.7.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/README.md +47 -14
- package/dist/cli.js +4 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.js +36 -1
- package/dist/next/index.d.ts +2 -1
- package/dist/next/index.js +86 -1
- package/dist/vite/index.d.ts +6 -6
- package/dist/vite/index.js +39 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,17 @@ npm install @enhance-eng/sandbox
|
|
|
12
12
|
|
|
13
13
|
## Next.js (App Router)
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Generate the service worker file, then add the `EnhanceScripts` component to your root layout.
|
|
16
|
+
|
|
17
|
+
**Step 1:** Generate the service worker:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx enhance-sandbox init --publishable-key pk_your_key
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This writes `public/enhance-sw.js`. Commit the file to your repository.
|
|
24
|
+
|
|
25
|
+
**Step 2:** Add the component to your root layout:
|
|
16
26
|
|
|
17
27
|
```tsx
|
|
18
28
|
// app/layout.tsx
|
|
@@ -30,11 +40,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
30
40
|
}
|
|
31
41
|
```
|
|
32
42
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
- The Service Worker is installed reliably.
|
|
36
|
-
- HMR works correctly through the preview proxy.
|
|
37
|
-
- React hydrates without mismatch errors by rendering the scripts natively.
|
|
43
|
+
The `EnhanceScripts` component registers the service worker, bootstraps the overlay, and renders scripts natively so React hydrates without mismatch errors.
|
|
38
44
|
|
|
39
45
|
## Vite
|
|
40
46
|
|
|
@@ -42,29 +48,56 @@ Add the plugin to your Vite config:
|
|
|
42
48
|
|
|
43
49
|
```typescript
|
|
44
50
|
// vite.config.ts
|
|
51
|
+
import { defineConfig } from "vite";
|
|
45
52
|
import { enhance } from "@enhance-eng/sandbox/vite";
|
|
46
53
|
|
|
47
54
|
export default defineConfig({
|
|
48
|
-
plugins: [
|
|
55
|
+
plugins: [
|
|
56
|
+
enhance({
|
|
57
|
+
publishableKey: "pk_your_key",
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
49
60
|
});
|
|
50
61
|
```
|
|
51
62
|
|
|
52
|
-
|
|
63
|
+
The plugin generates the service worker, serves it in dev, emits it as a build asset, and injects the registration script automatically.
|
|
53
64
|
|
|
54
65
|
## Other Build Tools
|
|
55
66
|
|
|
56
|
-
For non-Vite setups,
|
|
67
|
+
For non-Vite, non-Next.js setups, generate the service worker with the CLI, then register it in your app.
|
|
68
|
+
|
|
69
|
+
**Step 1:** Generate the service worker:
|
|
57
70
|
|
|
58
71
|
```bash
|
|
59
|
-
npx enhance-sandbox
|
|
72
|
+
npx enhance-sandbox init --publishable-key pk_your_key
|
|
60
73
|
```
|
|
61
74
|
|
|
62
|
-
|
|
75
|
+
**Step 2:** Register it in your application entry point:
|
|
63
76
|
|
|
64
77
|
```typescript
|
|
65
|
-
import {
|
|
78
|
+
import { enhance } from "@enhance-eng/sandbox";
|
|
66
79
|
|
|
67
|
-
|
|
80
|
+
enhance();
|
|
68
81
|
```
|
|
69
82
|
|
|
70
|
-
|
|
83
|
+
## Existing Service Worker
|
|
84
|
+
|
|
85
|
+
If your app already uses a service worker (e.g. for offline support or caching), pass its URL with the `serviceWorker` option so Enhance registers only during playground sessions and falls back to your service worker for normal visitors.
|
|
86
|
+
|
|
87
|
+
**Vite:**
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
enhance({ publishableKey: "pk_your_key", serviceWorker: "/sw.js" });
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Next.js:**
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
<EnhanceScripts serviceWorker="/sw.js" />
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Other:**
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
enhance({ serviceWorker: "/sw.js" });
|
|
103
|
+
```
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON[
|
|
5
|
-
self.__ENHANCE_CDN__ = ${JSON[
|
|
3
|
+
const _0x4b528f=_0x18f9;(function(_0x212534,_0x31f7cb){const _0x2e97bf=_0x18f9,_0x52500d=_0x212534();while(!![]){try{const _0x58c11e=parseInt(_0x2e97bf(0x1f0))/0x1+-parseInt(_0x2e97bf(0x1e8))/0x2+parseInt(_0x2e97bf(0x1de))/0x3+parseInt(_0x2e97bf(0x1ce))/0x4*(-parseInt(_0x2e97bf(0x1d0))/0x5)+parseInt(_0x2e97bf(0x1cf))/0x6+parseInt(_0x2e97bf(0x1ed))/0x7*(-parseInt(_0x2e97bf(0x1e9))/0x8)+-parseInt(_0x2e97bf(0x1e6))/0x9*(-parseInt(_0x2e97bf(0x1f2))/0xa);if(_0x58c11e===_0x31f7cb)break;else _0x52500d['push'](_0x52500d['shift']());}catch(_0x194d58){_0x52500d['push'](_0x52500d['shift']());}}}(_0xfd0e,0x569ea));import{Command}from'commander';import{writeFile,mkdir}from'fs/promises';import{dirname,resolve}from'path';import _0x10d255 from'dedent';function _0xfd0e(){const _0x24708c=['write','option','init','parseAsync','\x20});\x0a','1647vhWURF','serviceWorker','203742dAdFMo','8hyJeBW','Output\x20path\x20for\x20the\x20service\x20worker\x20file','stringify','https://cdn.enhancelabs.ai','1987951VUpLQA','stdout','URL\x20of\x20your\x20existing\x20service\x20worker\x20(e.g.\x20/sw.js)','609803rKKFFT','Enhance\x20sandbox\x20utility\x20CLI','2620snbvQO','command','cdnUrl','2003012sHovuD','3154428kCTbNR','5prTIdj','enhance-sandbox','0.0.0','--cdn-url\x20<url>','cwd','CDN\x20URL\x20for\x20enhance\x20assets\x20(defaults\x20to\x20production)','description','Created\x20','action','version','requiredOption','name','Publishable\x20key\x20for\x20enhance','public/enhance-sw.js','173772cLWIpV','output','Generate\x20the\x20service\x20worker\x20loader\x20file'];_0xfd0e=function(){return _0x24708c;};return _0xfd0e();}var DEFAULT_CDN_URL=_0x4b528f(0x1ec);function buildSwSource(_0x401f28){const _0x2e2dc0=_0x4b528f,_0x1b52aa=_0x401f28[_0x2e2dc0(0x1cd)]??DEFAULT_CDN_URL;return _0x10d255`
|
|
4
|
+
self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON[_0x2e2dc0(0x1eb)](_0x401f28['publishableKey'])};
|
|
5
|
+
self.__ENHANCE_CDN__ = ${JSON[_0x2e2dc0(0x1eb)](_0x1b52aa)};
|
|
6
6
|
importScripts(self.__ENHANCE_CDN__ + "/loader/loader.v1.js");
|
|
7
|
-
`;}var program=new Command();program[
|
|
7
|
+
`;}function _0x18f9(_0x35d564,_0x5b0fb2){_0x35d564=_0x35d564-0x1cd;const _0xfd0ee5=_0xfd0e();let _0x18f9d8=_0xfd0ee5[_0x35d564];return _0x18f9d8;}var program=new Command();program[_0x4b528f(0x1db)](_0x4b528f(0x1d1))[_0x4b528f(0x1d6)](_0x4b528f(0x1f1))[_0x4b528f(0x1d9)](_0x4b528f(0x1d2)),program[_0x4b528f(0x1f3)](_0x4b528f(0x1e3))[_0x4b528f(0x1d6)](_0x4b528f(0x1e0))[_0x4b528f(0x1da)]('--publishable-key\x20<key>',_0x4b528f(0x1dc))['option'](_0x4b528f(0x1d3),_0x4b528f(0x1d5))[_0x4b528f(0x1e2)]('--output\x20<path>',_0x4b528f(0x1ea),_0x4b528f(0x1dd))['option']('--service-worker\x20<url>',_0x4b528f(0x1ef))[_0x4b528f(0x1d8)](async _0x4be961=>{const _0x4a2374=_0x4b528f,_0x47ff6d=resolve(process[_0x4a2374(0x1d4)](),_0x4be961[_0x4a2374(0x1df)]),_0x59f269=buildSwSource({'publishableKey':_0x4be961['publishableKey'],'cdnUrl':_0x4be961[_0x4a2374(0x1cd)]});await mkdir(dirname(_0x47ff6d),{'recursive':!![]}),await writeFile(_0x47ff6d,_0x59f269,'utf-8'),process['stdout']['write'](_0x4a2374(0x1d7)+_0x4be961[_0x4a2374(0x1df)]+'\x0a'),_0x4be961[_0x4a2374(0x1e7)]&&process[_0x4a2374(0x1ee)][_0x4a2374(0x1e1)]('\x0aRegister\x20with:\x0a\x0a\x20\x20import\x20{\x20enhance\x20}\x20from\x20\x22@enhance-eng/sandbox\x22;\x0a\x20\x20enhance({\x20serviceWorker:\x20'+JSON[_0x4a2374(0x1eb)](_0x4be961[_0x4a2374(0x1e7)])+_0x4a2374(0x1e5));}),program[_0x4b528f(0x1e4)]();
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
var _0x5590ac=_0x1a19;(function(_0x5b403b,_0x540534){var _0x1312de=_0x1a19,_0x11eb11=_0x5b403b();while(!![]){try{var _0x56002c=parseInt(_0x1312de(0x17d))/0x1*(parseInt(_0x1312de(0x17f))/0x2)+parseInt(_0x1312de(0x178))/0x3*(-parseInt(_0x1312de(0x189))/0x4)+-parseInt(_0x1312de(0x17e))/0x5+-parseInt(_0x1312de(0x17a))/0x6*(-parseInt(_0x1312de(0x188))/0x7)+parseInt(_0x1312de(0x183))/0x8*(parseInt(_0x1312de(0x187))/0x9)+parseInt(_0x1312de(0x181))/0xa+-parseInt(_0x1312de(0x176))/0xb*(parseInt(_0x1312de(0x184))/0xc);if(_0x56002c===_0x540534)break;else _0x11eb11['push'](_0x11eb11['shift']());}catch(_0x4487dd){_0x11eb11['push'](_0x11eb11['shift']());}}}(_0x143e,0xa0ace));import _0x54713e from'dedent';var SW_PATH=_0x5590ac(0x17b),PLAYGROUND_COOKIE=_0x5590ac(0x179),INTEROP_QUERY_PARAM='enhance_interop',INTEROP_QUERY_VALUE='1',BOOTSTRAP_COOKIE_MAX_AGE=0x2*0x3c;function buildRegistrationScript({serviceWorker:_0x3d716d}){var _0x3eeee4=_0x5590ac;if(!_0x3d716d)return _0x3eeee4(0x180)+SW_PATH+_0x3eeee4(0x177);const _0x55a012=SW_PATH+'?'+INTEROP_QUERY_PARAM+'='+INTEROP_QUERY_VALUE;return _0x54713e`
|
|
2
|
+
(function() {
|
|
3
|
+
var sw = navigator.serviceWorker;
|
|
4
|
+
if (!sw) return;
|
|
5
|
+
var search = new URLSearchParams(location.search);
|
|
6
|
+
var isExit = search.get("enhance_exit") === "1" || search.get("exit_enhance") === "1" || search.get("enhance_exited") === "1";
|
|
7
|
+
if (isExit) {
|
|
8
|
+
document.cookie = "${PLAYGROUND_COOKIE}=; path=/; max-age=0";
|
|
9
|
+
search.delete("enhance_exit");
|
|
10
|
+
search.delete("exit_enhance");
|
|
11
|
+
search.delete("enhance_exited");
|
|
12
|
+
var cleanUrl = location.pathname + (search.toString() ? "?" + search : "") + location.hash;
|
|
13
|
+
history.replaceState(null, "", cleanUrl);
|
|
14
|
+
sw.register(${JSON['stringify'](_0x3d716d)});
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
var playgroundId = search.get("playground");
|
|
18
|
+
if (!playgroundId) {
|
|
19
|
+
var hashIdx = location.hash.indexOf("?");
|
|
20
|
+
if (hashIdx !== -1) {
|
|
21
|
+
playgroundId = new URLSearchParams(location.hash.slice(hashIdx + 1)).get("playground");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (playgroundId) {
|
|
25
|
+
var secure = location.protocol === "https:" ? "; secure" : "";
|
|
26
|
+
document.cookie = "${PLAYGROUND_COOKIE}=" + encodeURIComponent(playgroundId) + "; path=/; max-age=${BOOTSTRAP_COOKIE_MAX_AGE}; samesite=lax" + secure;
|
|
27
|
+
sw.register("${_0x55a012}");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1) {
|
|
31
|
+
sw.register("${_0x55a012}");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
sw.register(${JSON[_0x3eeee4(0x186)](_0x3d716d)});
|
|
35
|
+
})();
|
|
36
|
+
`;}function enhance(_0x1a7053){var _0x339a51=_0x5590ac;const _0x2b005a=document[_0x339a51(0x17c)]('script');_0x2b005a[_0x339a51(0x182)]=buildRegistrationScript({'serviceWorker':_0x1a7053?.['serviceWorker']}),document[_0x339a51(0x185)]['appendChild'](_0x2b005a);}function _0x143e(){var _0x2cb754=['4570330eZqutb','57340FivxOq','navigator.serviceWorker?.register(\x22','9356330DQVDBF','textContent','1960eEvrJl','24BfLPMh','head','stringify','21177hyStSr','7jPJJgK','508ZUhWAq','111364xNTtwO','\x22);','16233IIPXBD','enhance_playground','1680774lLYIFr','/enhance-sw.js','createElement','17lIPXXm'];_0x143e=function(){return _0x2cb754;};return _0x143e();}function _0x1a19(_0x100f5e,_0x4be7c5){_0x100f5e=_0x100f5e-0x176;var _0x143e87=_0x143e();var _0x1a1924=_0x143e87[_0x100f5e];return _0x1a1924;}export{enhance};
|
package/dist/next/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
|
-
declare function EnhanceScripts({ nonce }: {
|
|
3
|
+
declare function EnhanceScripts({ nonce, serviceWorker }: {
|
|
4
4
|
nonce?: string;
|
|
5
|
+
serviceWorker?: string;
|
|
5
6
|
}): react_jsx_runtime.JSX.Element;
|
|
6
7
|
|
|
7
8
|
export { EnhanceScripts };
|
package/dist/next/index.js
CHANGED
|
@@ -1 +1,86 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
var _0x592b33=_0x41d0;(function(_0x1df2c0,_0x679265){var _0x205615=_0x41d0,_0x43a16d=_0x1df2c0();while(!![]){try{var _0x3f9388=-parseInt(_0x205615(0xe7))/0x1*(-parseInt(_0x205615(0xe9))/0x2)+-parseInt(_0x205615(0xe3))/0x3+parseInt(_0x205615(0xe8))/0x4*(-parseInt(_0x205615(0xe0))/0x5)+-parseInt(_0x205615(0xd9))/0x6+-parseInt(_0x205615(0xdc))/0x7+parseInt(_0x205615(0xda))/0x8+-parseInt(_0x205615(0xdf))/0x9*(-parseInt(_0x205615(0xdd))/0xa);if(_0x3f9388===_0x679265)break;else _0x43a16d['push'](_0x43a16d['shift']());}catch(_0x2677fe){_0x43a16d['push'](_0x43a16d['shift']());}}}(_0x2b22,0xd5010));import _0x3c89cb from'next/script';import _0x2e4b67 from'dedent';import _0xa43f77 from'dedent';var SW_PATH=_0x592b33(0xe5),PLAYGROUND_COOKIE='enhance_playground',INTEROP_QUERY_PARAM=_0x592b33(0xe2),INTEROP_QUERY_VALUE='1',BOOTSTRAP_COOKIE_MAX_AGE=0x2*0x3c;function _0x41d0(_0x4b1331,_0x14ff97){_0x4b1331=_0x4b1331-0xd9;var _0x2b22df=_0x2b22();var _0x41d097=_0x2b22df[_0x4b1331];return _0x41d097;}function buildRegistrationScript({serviceWorker:_0x133c56}){var _0x47f44b=_0x592b33;if(!_0x133c56)return'navigator.serviceWorker?.register(\x22'+SW_PATH+_0x47f44b(0xe6);const _0x30d910=SW_PATH+'?'+INTEROP_QUERY_PARAM+'='+INTEROP_QUERY_VALUE;return _0xa43f77`
|
|
2
|
+
(function() {
|
|
3
|
+
var sw = navigator.serviceWorker;
|
|
4
|
+
if (!sw) return;
|
|
5
|
+
var search = new URLSearchParams(location.search);
|
|
6
|
+
var isExit = search.get("enhance_exit") === "1" || search.get("exit_enhance") === "1" || search.get("enhance_exited") === "1";
|
|
7
|
+
if (isExit) {
|
|
8
|
+
document.cookie = "${PLAYGROUND_COOKIE}=; path=/; max-age=0";
|
|
9
|
+
search.delete("enhance_exit");
|
|
10
|
+
search.delete("exit_enhance");
|
|
11
|
+
search.delete("enhance_exited");
|
|
12
|
+
var cleanUrl = location.pathname + (search.toString() ? "?" + search : "") + location.hash;
|
|
13
|
+
history.replaceState(null, "", cleanUrl);
|
|
14
|
+
sw.register(${JSON[_0x47f44b(0xe1)](_0x133c56)});
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
var playgroundId = search.get("playground");
|
|
18
|
+
if (!playgroundId) {
|
|
19
|
+
var hashIdx = location.hash.indexOf("?");
|
|
20
|
+
if (hashIdx !== -1) {
|
|
21
|
+
playgroundId = new URLSearchParams(location.hash.slice(hashIdx + 1)).get("playground");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (playgroundId) {
|
|
25
|
+
var secure = location.protocol === "https:" ? "; secure" : "";
|
|
26
|
+
document.cookie = "${PLAYGROUND_COOKIE}=" + encodeURIComponent(playgroundId) + "; path=/; max-age=${BOOTSTRAP_COOKIE_MAX_AGE}; samesite=lax" + secure;
|
|
27
|
+
sw.register("${_0x30d910}");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1) {
|
|
31
|
+
sw.register("${_0x30d910}");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
sw.register(${JSON[_0x47f44b(0xe1)](_0x133c56)});
|
|
35
|
+
})();
|
|
36
|
+
`;}import{Fragment,jsx,jsxs}from'react/jsx-runtime';function _0x2b22(){var _0x4484a7=['\x22);','5323aZzrBU','1572344YEfsSV','32zEPhnu','7834554VqUDHk','12101088rnXlHy','meta','11334554iBhCMV','130ZgRVZQ','beforeInteractive','3084678qEweem','10zecidS','stringify','enhance_interop','4409499cQrnUa','enhance-bootstrap','/enhance-sw.js'];_0x2b22=function(){return _0x4484a7;};return _0x2b22();}function buildBootstrapScript({nonce:_0x55f40b,serviceWorker:_0xf063be}){const _0xe0f885=_0xf063be?_0x2e4b67`
|
|
37
|
+
var hasParam = new URLSearchParams(location.search).has("playground");
|
|
38
|
+
var hasCookie = document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1;
|
|
39
|
+
if (!hasParam && !hasCookie) return;
|
|
40
|
+
`:'';return _0x2e4b67`
|
|
41
|
+
(function() {
|
|
42
|
+
${_0xe0f885}
|
|
43
|
+
var inject = function() {
|
|
44
|
+
if (window.__ENHANCE_BOOTSTRAPPED__) return;
|
|
45
|
+
window.__ENHANCE_BOOTSTRAPPED__ = true;
|
|
46
|
+
|
|
47
|
+
var s = document.createElement('script');
|
|
48
|
+
s.src = '/__enhance/init.js';
|
|
49
|
+
s.nonce = '${_0x55f40b||''}';
|
|
50
|
+
document.head.appendChild(s);
|
|
51
|
+
|
|
52
|
+
var o = document.createElement('script');
|
|
53
|
+
o.src = '/__enhance/overlay.js';
|
|
54
|
+
o.type = 'module';
|
|
55
|
+
o.nonce = '${_0x55f40b||''}';
|
|
56
|
+
document.head.appendChild(o);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (navigator.serviceWorker) {
|
|
60
|
+
if (!${Boolean(_0xf063be)}) {
|
|
61
|
+
if (navigator.serviceWorker.controller) {
|
|
62
|
+
inject();
|
|
63
|
+
} else {
|
|
64
|
+
navigator.serviceWorker.addEventListener('controllerchange', inject);
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var injectWhenEnhanceController = function() {
|
|
70
|
+
var controller = navigator.serviceWorker.controller;
|
|
71
|
+
if (!controller) return;
|
|
72
|
+
try {
|
|
73
|
+
if (new URL(controller.scriptURL).pathname !== '${SW_PATH}') return;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
inject();
|
|
79
|
+
navigator.serviceWorker.removeEventListener('controllerchange', injectWhenEnhanceController);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
navigator.serviceWorker.addEventListener('controllerchange', injectWhenEnhanceController);
|
|
83
|
+
injectWhenEnhanceController();
|
|
84
|
+
}
|
|
85
|
+
})();
|
|
86
|
+
`;}function EnhanceScripts({nonce:_0x21c9e6,serviceWorker:_0x688946}){var _0x29d823=_0x592b33;return jsxs(Fragment,{'children':[jsx(_0x29d823(0xdb),{'name':'enhance-integrated','content':'1'}),jsx(_0x3c89cb,{'id':'enhance-sw-register','strategy':_0x29d823(0xde),'nonce':_0x21c9e6,'children':buildRegistrationScript({'serviceWorker':_0x688946})}),jsx(_0x3c89cb,{'id':_0x29d823(0xe4),'strategy':_0x29d823(0xde),'nonce':_0x21c9e6,'children':buildBootstrapScript({'nonce':_0x21c9e6,'serviceWorker':_0x688946})})]});}export{EnhanceScripts};
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
|
|
2
|
+
import { E as EnhanceOptions } from '../sw-source-CUI8GVoj.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
type EnhancePluginOptions = EnhanceOptions & {
|
|
5
|
+
serviceWorker?: string;
|
|
6
|
+
};
|
|
7
|
+
declare const enhance: (options: EnhancePluginOptions) => Plugin;
|
|
8
8
|
|
|
9
|
-
export { enhance };
|
|
9
|
+
export { type EnhancePluginOptions, enhance };
|
package/dist/vite/index.js
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
|
-
var
|
|
2
|
-
self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON[
|
|
3
|
-
self.__ENHANCE_CDN__ = ${JSON[
|
|
1
|
+
var _0x37ae85=_0x45e8;(function(_0x2981b4,_0x2e6435){var _0x5c60aa=_0x45e8,_0x266a22=_0x2981b4();while(!![]){try{var _0x1867dc=parseInt(_0x5c60aa(0x84))/0x1+parseInt(_0x5c60aa(0x7e))/0x2*(parseInt(_0x5c60aa(0x8b))/0x3)+parseInt(_0x5c60aa(0x82))/0x4*(-parseInt(_0x5c60aa(0x76))/0x5)+parseInt(_0x5c60aa(0x86))/0x6+parseInt(_0x5c60aa(0x7a))/0x7+parseInt(_0x5c60aa(0x8d))/0x8*(parseInt(_0x5c60aa(0x71))/0x9)+-parseInt(_0x5c60aa(0x75))/0xa;if(_0x1867dc===_0x2e6435)break;else _0x266a22['push'](_0x266a22['shift']());}catch(_0x2c1311){_0x266a22['push'](_0x266a22['shift']());}}}(_0x5da4,0x21fa5));function _0x45e8(_0x38d35f,_0xff6165){_0x38d35f=_0x38d35f-0x6c;var _0x5da4f8=_0x5da4();var _0x45e8bb=_0x5da4f8[_0x38d35f];return _0x45e8bb;}import _0xc9db64 from'dedent';var DEFAULT_CDN_URL=_0x37ae85(0x8e);function buildSwSource(_0x3d5e44){var _0x486403=_0x37ae85;const _0x219f3d=_0x3d5e44[_0x486403(0x77)]??DEFAULT_CDN_URL;return _0xc9db64`
|
|
2
|
+
self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON[_0x486403(0x85)](_0x3d5e44[_0x486403(0x83)])};
|
|
3
|
+
self.__ENHANCE_CDN__ = ${JSON[_0x486403(0x85)](_0x219f3d)};
|
|
4
4
|
importScripts(self.__ENHANCE_CDN__ + "/loader/loader.v1.js");
|
|
5
|
-
`;}var SW_PATH=
|
|
5
|
+
`;}import _0xf8edd4 from'dedent';var SW_PATH=_0x37ae85(0x88),PLAYGROUND_COOKIE=_0x37ae85(0x6f),INTEROP_QUERY_PARAM=_0x37ae85(0x7d),INTEROP_QUERY_VALUE='1',BOOTSTRAP_COOKIE_MAX_AGE=0x2*0x3c;function _0x5da4(){var _0x9c79ce=['</script>','86980aOtitg','publishableKey','17858eupoiu','stringify','535584VBoohP','replace','/enhance-sw.js','setHeader','navigator.serviceWorker?.register(\x22','22107vTwTcu','middlewares','8608RtYluJ','https://cdn.enhancelabs.ai','asset','<head$1>','pathname','enhance_playground','enhance-sw.js','1233DnVPhk','Content-Type','enhance','http://localhost','1381510KFwFxP','10ZnmHfO','cdnUrl','end','\x22);','412377IApoOx','serviceWorker','url','enhance_interop','2NNcrBE','application/javascript','use'];_0x5da4=function(){return _0x9c79ce;};return _0x5da4();}function buildRegistrationScript({serviceWorker:_0x362627}){var _0x1d7ee6=_0x37ae85;if(!_0x362627)return _0x1d7ee6(0x8a)+SW_PATH+_0x1d7ee6(0x79);const _0x385fda=SW_PATH+'?'+INTEROP_QUERY_PARAM+'='+INTEROP_QUERY_VALUE;return _0xf8edd4`
|
|
6
|
+
(function() {
|
|
7
|
+
var sw = navigator.serviceWorker;
|
|
8
|
+
if (!sw) return;
|
|
9
|
+
var search = new URLSearchParams(location.search);
|
|
10
|
+
var isExit = search.get("enhance_exit") === "1" || search.get("exit_enhance") === "1" || search.get("enhance_exited") === "1";
|
|
11
|
+
if (isExit) {
|
|
12
|
+
document.cookie = "${PLAYGROUND_COOKIE}=; path=/; max-age=0";
|
|
13
|
+
search.delete("enhance_exit");
|
|
14
|
+
search.delete("exit_enhance");
|
|
15
|
+
search.delete("enhance_exited");
|
|
16
|
+
var cleanUrl = location.pathname + (search.toString() ? "?" + search : "") + location.hash;
|
|
17
|
+
history.replaceState(null, "", cleanUrl);
|
|
18
|
+
sw.register(${JSON[_0x1d7ee6(0x85)](_0x362627)});
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
var playgroundId = search.get("playground");
|
|
22
|
+
if (!playgroundId) {
|
|
23
|
+
var hashIdx = location.hash.indexOf("?");
|
|
24
|
+
if (hashIdx !== -1) {
|
|
25
|
+
playgroundId = new URLSearchParams(location.hash.slice(hashIdx + 1)).get("playground");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (playgroundId) {
|
|
29
|
+
var secure = location.protocol === "https:" ? "; secure" : "";
|
|
30
|
+
document.cookie = "${PLAYGROUND_COOKIE}=" + encodeURIComponent(playgroundId) + "; path=/; max-age=${BOOTSTRAP_COOKIE_MAX_AGE}; samesite=lax" + secure;
|
|
31
|
+
sw.register("${_0x385fda}");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1) {
|
|
35
|
+
sw.register("${_0x385fda}");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
sw.register(${JSON['stringify'](_0x362627)});
|
|
39
|
+
})();
|
|
40
|
+
`;}function isServiceWorkerRequest(_0x4b6279){var _0x603232=_0x37ae85;if(!_0x4b6279)return![];return new URL(_0x4b6279,_0x603232(0x74))[_0x603232(0x6e)]===SW_PATH;}var enhance=_0x200df1=>{var _0x3841b3=_0x37ae85;const _0x23762f=buildSwSource(_0x200df1),_0x1b24e1='<script>'+buildRegistrationScript({'serviceWorker':_0x200df1[_0x3841b3(0x7b)]})+_0x3841b3(0x81);return{'name':_0x3841b3(0x73),'configureServer'(_0x8f6d16){var _0x51d626=_0x3841b3;_0x8f6d16[_0x51d626(0x8c)][_0x51d626(0x80)]((_0x5761ec,_0x240be4,_0x2ac662)=>{var _0x23ca81=_0x51d626;if(isServiceWorkerRequest(_0x5761ec[_0x23ca81(0x7c)])){_0x240be4['setHeader'](_0x23ca81(0x72),'application/javascript'),_0x240be4['end'](_0x23762f);return;}_0x2ac662();});},'configurePreviewServer'(_0x788149){var _0x3c73a0=_0x3841b3;_0x788149[_0x3c73a0(0x8c)][_0x3c73a0(0x80)]((_0x5eb3bb,_0x4ba7f3,_0x4ea06b)=>{var _0x18220a=_0x3c73a0;if(isServiceWorkerRequest(_0x5eb3bb[_0x18220a(0x7c)])){_0x4ba7f3[_0x18220a(0x89)](_0x18220a(0x72),_0x18220a(0x7f)),_0x4ba7f3[_0x18220a(0x78)](_0x23762f);return;}_0x4ea06b();});},'generateBundle'(){var _0x54a906=_0x3841b3;this['emitFile']({'type':_0x54a906(0x6c),'fileName':_0x54a906(0x70),'source':_0x23762f});},'transformIndexHtml'(_0x331359){var _0x3f2336=_0x3841b3;return _0x331359[_0x3f2336(0x87)](/<head([^>]*)>/,_0x3f2336(0x6d)+_0x1b24e1);}};};export{enhance};
|