@enhance-eng/sandbox 0.5.4 → 0.6.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 +13 -1
- package/dist/next/index.d.ts +2 -1
- package/dist/next/index.js +63 -1
- package/dist/vite/index.d.ts +6 -6
- package/dist/vite/index.js +16 -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['stringify'](
|
|
5
|
-
self.__ENHANCE_CDN__ = ${JSON[
|
|
3
|
+
const _0x31af8d=_0x49ab;(function(_0x502963,_0x5c2180){const _0x135f3b=_0x49ab,_0x168507=_0x502963();while(!![]){try{const _0x221103=parseInt(_0x135f3b(0xfe))/0x1*(parseInt(_0x135f3b(0xfb))/0x2)+-parseInt(_0x135f3b(0xf5))/0x3+-parseInt(_0x135f3b(0xeb))/0x4+-parseInt(_0x135f3b(0xe9))/0x5+-parseInt(_0x135f3b(0x106))/0x6*(-parseInt(_0x135f3b(0xf6))/0x7)+parseInt(_0x135f3b(0xf2))/0x8*(parseInt(_0x135f3b(0xf7))/0x9)+parseInt(_0x135f3b(0x109))/0xa;if(_0x221103===_0x5c2180)break;else _0x168507['push'](_0x168507['shift']());}catch(_0x3279aa){_0x168507['push'](_0x168507['shift']());}}}(_0x3c5f,0x1da02));import{Command}from'commander';import{writeFile,mkdir}from'fs/promises';import{dirname,resolve}from'path';function _0x3c5f(){const _0xd61fe3=['utf-8','write','19384yfxiZD','--publishable-key\x20<key>','version','20kjGbHa','requiredOption','CDN\x20URL\x20for\x20enhance\x20assets\x20(defaults\x20to\x20production)','public/enhance-sw.js','output','action','option','--cdn-url\x20<url>','211530zdgdOU','cdnUrl','init','695220QLDdIG','stringify','Generate\x20the\x20service\x20worker\x20loader\x20file','name','--service-worker\x20<url>','1200815pSoPzM','serviceWorker','598268SfaAHa','enhance-sandbox','description','\x0aRegister\x20with:\x0a\x0a\x20\x20import\x20{\x20enhance\x20}\x20from\x20\x22@enhance-eng/sandbox\x22;\x0a\x20\x20enhance({\x20serviceWorker:\x20','Publishable\x20key\x20for\x20enhance','Enhance\x20sandbox\x20utility\x20CLI','URL\x20of\x20your\x20existing\x20service\x20worker\x20(e.g.\x20/sw.js)','48tLFGZm','\x20});\x0a','publishableKey','52869wZwkQe','7FNPxHJ','345123QAGBWh','--output\x20<path>'];_0x3c5f=function(){return _0xd61fe3;};return _0x3c5f();}import _0x5f4d43 from'dedent';var DEFAULT_CDN_URL='https://cdn.enhancelabs.ai';function _0x49ab(_0x4bad38,_0x306c6b){_0x4bad38=_0x4bad38-0xe8;const _0x3c5f32=_0x3c5f();let _0x49ab88=_0x3c5f32[_0x4bad38];return _0x49ab88;}function buildSwSource(_0x5e0b58){const _0x149dcd=_0x49ab,_0xf49fdb=_0x5e0b58[_0x149dcd(0x107)]??DEFAULT_CDN_URL;return _0x5f4d43`
|
|
4
|
+
self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON['stringify'](_0x5e0b58[_0x149dcd(0xf4)])};
|
|
5
|
+
self.__ENHANCE_CDN__ = ${JSON[_0x149dcd(0x10a)](_0xf49fdb)};
|
|
6
6
|
importScripts(self.__ENHANCE_CDN__ + "/loader/loader.v1.js");
|
|
7
|
-
`;}var program=new Command();program[
|
|
7
|
+
`;}var program=new Command();program[_0x31af8d(0x10c)](_0x31af8d(0xec))['description'](_0x31af8d(0xf0))[_0x31af8d(0xfd)]('0.0.0'),program['command'](_0x31af8d(0x108))[_0x31af8d(0xed)](_0x31af8d(0x10b))[_0x31af8d(0xff)](_0x31af8d(0xfc),_0x31af8d(0xef))['option'](_0x31af8d(0x105),_0x31af8d(0x100))[_0x31af8d(0x104)](_0x31af8d(0xf8),'Output\x20path\x20for\x20the\x20service\x20worker\x20file',_0x31af8d(0x101))['option'](_0x31af8d(0xe8),_0x31af8d(0xf1))[_0x31af8d(0x103)](async _0x55ec5d=>{const _0x2a3257=_0x31af8d,_0x39fe77=resolve(process['cwd'](),_0x55ec5d[_0x2a3257(0x102)]),_0x252b8c=buildSwSource({'publishableKey':_0x55ec5d[_0x2a3257(0xf4)],'cdnUrl':_0x55ec5d[_0x2a3257(0x107)]});await mkdir(dirname(_0x39fe77),{'recursive':!![]}),await writeFile(_0x39fe77,_0x252b8c,_0x2a3257(0xf9)),process['stdout']['write']('Created\x20'+_0x55ec5d['output']+'\x0a'),_0x55ec5d['serviceWorker']&&process['stdout'][_0x2a3257(0xfa)](_0x2a3257(0xee)+JSON['stringify'](_0x55ec5d[_0x2a3257(0xea)])+_0x2a3257(0xf3));}),program['parseAsync']();
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
function _0x37a4(){var _0x10ff3b=['serviceWorker','textContent','head','navigator.serviceWorker?.register(\x22','4390857baNFsl','16nGqXVo','1xtkIlr','stringify','1870120OnpSut','enhance_interop','3330912Mynnnk','904920QaqBiX','enhance_playground','script','createElement','102162FdEyqP','appendChild','1277292HHETsT','840308ebeAMM'];_0x37a4=function(){return _0x10ff3b;};return _0x37a4();}var _0x490382=_0x2dcc;(function(_0x22b375,_0x328357){var _0x427c50=_0x2dcc,_0x3188a9=_0x22b375();while(!![]){try{var _0x3c7300=parseInt(_0x427c50(0x193))/0x1*(parseInt(_0x427c50(0x18b))/0x2)+parseInt(_0x427c50(0x189))/0x3+-parseInt(_0x427c50(0x182))/0x4+-parseInt(_0x427c50(0x185))/0x5+parseInt(_0x427c50(0x184))/0x6+parseInt(_0x427c50(0x18c))/0x7*(parseInt(_0x427c50(0x192))/0x8)+-parseInt(_0x427c50(0x191))/0x9;if(_0x3c7300===_0x328357)break;else _0x3188a9['push'](_0x3188a9['shift']());}catch(_0x30be21){_0x3188a9['push'](_0x3188a9['shift']());}}}(_0x37a4,0x50f21));import _0xde264c from'dedent';function _0x2dcc(_0x303b99,_0x210496){_0x303b99=_0x303b99-0x181;var _0x37a423=_0x37a4();var _0x2dcce8=_0x37a423[_0x303b99];return _0x2dcce8;}var SW_PATH='/enhance-sw.js',PLAYGROUND_COOKIE=_0x490382(0x186),INTEROP_QUERY_PARAM=_0x490382(0x183),INTEROP_QUERY_VALUE='1';function buildRegistrationScript({serviceWorker:_0x21a0a0}){var _0x5377c8=_0x490382;if(!_0x21a0a0)return _0x5377c8(0x190)+SW_PATH+'\x22);';const _0x949c8e=SW_PATH+'?'+INTEROP_QUERY_PARAM+'='+INTEROP_QUERY_VALUE;return _0xde264c`
|
|
2
|
+
(function() {
|
|
3
|
+
var sw = navigator.serviceWorker;
|
|
4
|
+
if (!sw) return;
|
|
5
|
+
var hasParam = new URLSearchParams(location.search).has("playground");
|
|
6
|
+
var hasCookie = document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1;
|
|
7
|
+
if (hasParam || hasCookie) {
|
|
8
|
+
sw.register("${_0x949c8e}");
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
sw.register(${JSON[_0x5377c8(0x181)](_0x21a0a0)});
|
|
12
|
+
})();
|
|
13
|
+
`;}function enhance(_0x39b02c){var _0x9f3cc2=_0x490382;const _0x5f20a5=document[_0x9f3cc2(0x188)](_0x9f3cc2(0x187));_0x5f20a5[_0x9f3cc2(0x18e)]=buildRegistrationScript({'serviceWorker':_0x39b02c?.[_0x9f3cc2(0x18d)]}),document[_0x9f3cc2(0x18f)][_0x9f3cc2(0x18a)](_0x5f20a5);}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,63 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
var _0x2207cf=_0x2c5f;(function(_0x1983c1,_0x570c22){var _0x24caff=_0x2c5f,_0x4a3a26=_0x1983c1();while(!![]){try{var _0x2b1baa=parseInt(_0x24caff(0x139))/0x1*(-parseInt(_0x24caff(0x137))/0x2)+parseInt(_0x24caff(0x136))/0x3*(-parseInt(_0x24caff(0x13c))/0x4)+parseInt(_0x24caff(0x131))/0x5*(parseInt(_0x24caff(0x12b))/0x6)+parseInt(_0x24caff(0x133))/0x7+parseInt(_0x24caff(0x12f))/0x8*(parseInt(_0x24caff(0x12d))/0x9)+-parseInt(_0x24caff(0x13e))/0xa+-parseInt(_0x24caff(0x13f))/0xb*(-parseInt(_0x24caff(0x13b))/0xc);if(_0x2b1baa===_0x570c22)break;else _0x4a3a26['push'](_0x4a3a26['shift']());}catch(_0x1a225c){_0x4a3a26['push'](_0x4a3a26['shift']());}}}(_0x4325,0x7e202));import _0x52069f from'next/script';import _0x56e445 from'dedent';import _0x3b56a9 from'dedent';function _0x4325(){var _0x4d267c=['stringify','3707991HnHuMk','enhance_playground','\x22);','3ObmdkM','5322OhjYmJ','beforeInteractive','338wwtCDy','navigator.serviceWorker?.register(\x22','108dDloJa','2926160vmMiOo','meta','4778380HIhqBo','1383789gsemVe','4476IFKxCJ','enhance-sw-register','288405UDnxDO','enhance-bootstrap','80FYmeLx','/enhance-sw.js','4310kPShkl'];_0x4325=function(){return _0x4d267c;};return _0x4325();}var SW_PATH=_0x2207cf(0x130),PLAYGROUND_COOKIE=_0x2207cf(0x134),INTEROP_QUERY_PARAM='enhance_interop',INTEROP_QUERY_VALUE='1';function _0x2c5f(_0x44fae2,_0x59f4d0){_0x44fae2=_0x44fae2-0x12b;var _0x432548=_0x4325();var _0x2c5f0b=_0x432548[_0x44fae2];return _0x2c5f0b;}function buildRegistrationScript({serviceWorker:_0x37d3eb}){var _0xff7464=_0x2207cf;if(!_0x37d3eb)return _0xff7464(0x13a)+SW_PATH+_0xff7464(0x135);const _0x13194c=SW_PATH+'?'+INTEROP_QUERY_PARAM+'='+INTEROP_QUERY_VALUE;return _0x3b56a9`
|
|
2
|
+
(function() {
|
|
3
|
+
var sw = navigator.serviceWorker;
|
|
4
|
+
if (!sw) return;
|
|
5
|
+
var hasParam = new URLSearchParams(location.search).has("playground");
|
|
6
|
+
var hasCookie = document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1;
|
|
7
|
+
if (hasParam || hasCookie) {
|
|
8
|
+
sw.register("${_0x13194c}");
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
sw.register(${JSON[_0xff7464(0x132)](_0x37d3eb)});
|
|
12
|
+
})();
|
|
13
|
+
`;}import{Fragment,jsx,jsxs}from'react/jsx-runtime';function buildBootstrapScript({nonce:_0x321fbf,serviceWorker:_0x48ffe}){const _0x563d1a=_0x48ffe?_0x56e445`
|
|
14
|
+
var hasParam = new URLSearchParams(location.search).has("playground");
|
|
15
|
+
var hasCookie = document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1;
|
|
16
|
+
if (!hasParam && !hasCookie) return;
|
|
17
|
+
`:'';return _0x56e445`
|
|
18
|
+
(function() {
|
|
19
|
+
${_0x563d1a}
|
|
20
|
+
var inject = function() {
|
|
21
|
+
if (window.__ENHANCE_BOOTSTRAPPED__) return;
|
|
22
|
+
window.__ENHANCE_BOOTSTRAPPED__ = true;
|
|
23
|
+
|
|
24
|
+
var s = document.createElement('script');
|
|
25
|
+
s.src = '/__enhance/init.js';
|
|
26
|
+
s.nonce = '${_0x321fbf||''}';
|
|
27
|
+
document.head.appendChild(s);
|
|
28
|
+
|
|
29
|
+
var o = document.createElement('script');
|
|
30
|
+
o.src = '/__enhance/overlay.js';
|
|
31
|
+
o.type = 'module';
|
|
32
|
+
o.nonce = '${_0x321fbf||''}';
|
|
33
|
+
document.head.appendChild(o);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
if (navigator.serviceWorker) {
|
|
37
|
+
if (!${Boolean(_0x48ffe)}) {
|
|
38
|
+
if (navigator.serviceWorker.controller) {
|
|
39
|
+
inject();
|
|
40
|
+
} else {
|
|
41
|
+
navigator.serviceWorker.addEventListener('controllerchange', inject);
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var injectWhenEnhanceController = function() {
|
|
47
|
+
var controller = navigator.serviceWorker.controller;
|
|
48
|
+
if (!controller) return;
|
|
49
|
+
try {
|
|
50
|
+
if (new URL(controller.scriptURL).pathname !== '${SW_PATH}') return;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
inject();
|
|
56
|
+
navigator.serviceWorker.removeEventListener('controllerchange', injectWhenEnhanceController);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
navigator.serviceWorker.addEventListener('controllerchange', injectWhenEnhanceController);
|
|
60
|
+
injectWhenEnhanceController();
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
`;}function EnhanceScripts({nonce:_0x1f9da8,serviceWorker:_0x55ea14}){var _0x5543a2=_0x2207cf;return jsxs(Fragment,{'children':[jsx(_0x5543a2(0x13d),{'name':'enhance-integrated','content':'1'}),jsx(_0x52069f,{'id':_0x5543a2(0x12c),'strategy':'beforeInteractive','nonce':_0x1f9da8,'children':buildRegistrationScript({'serviceWorker':_0x55ea14})}),jsx(_0x52069f,{'id':_0x5543a2(0x12e),'strategy':_0x5543a2(0x138),'nonce':_0x1f9da8,'children':buildBootstrapScript({'nonce':_0x1f9da8,'serviceWorker':_0x55ea14})})]});}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,17 @@
|
|
|
1
|
-
var
|
|
2
|
-
self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON['stringify'](
|
|
3
|
-
self.__ENHANCE_CDN__ = ${JSON[
|
|
1
|
+
var _0xd3c566=_0x3941;(function(_0x3a2491,_0x566cfe){var _0xc7b940=_0x3941,_0x538090=_0x3a2491();while(!![]){try{var _0x4d25be=-parseInt(_0xc7b940(0xbd))/0x1*(-parseInt(_0xc7b940(0xae))/0x2)+parseInt(_0xc7b940(0xb5))/0x3*(parseInt(_0xc7b940(0xaa))/0x4)+parseInt(_0xc7b940(0xb9))/0x5*(parseInt(_0xc7b940(0xc5))/0x6)+-parseInt(_0xc7b940(0xc3))/0x7+parseInt(_0xc7b940(0xab))/0x8+-parseInt(_0xc7b940(0xc7))/0x9+-parseInt(_0xc7b940(0xb3))/0xa;if(_0x4d25be===_0x566cfe)break;else _0x538090['push'](_0x538090['shift']());}catch(_0x458c4f){_0x538090['push'](_0x538090['shift']());}}}(_0x1d8b,0xd0335));import _0xe26b4a from'dedent';function _0x3941(_0xbdd36,_0x6455b0){_0xbdd36=_0xbdd36-0xaa;var _0x1d8b97=_0x1d8b();var _0x394131=_0x1d8b97[_0xbdd36];return _0x394131;}var DEFAULT_CDN_URL=_0xd3c566(0xb1);function buildSwSource(_0x726b96){var _0xda8325=_0xd3c566;const _0xeb99a=_0x726b96[_0xda8325(0xc8)]??DEFAULT_CDN_URL;return _0xe26b4a`
|
|
2
|
+
self.__ENHANCE_PUBLISHABLE_KEY__ = ${JSON['stringify'](_0x726b96['publishableKey'])};
|
|
3
|
+
self.__ENHANCE_CDN__ = ${JSON['stringify'](_0xeb99a)};
|
|
4
4
|
importScripts(self.__ENHANCE_CDN__ + "/loader/loader.v1.js");
|
|
5
|
-
`;}
|
|
5
|
+
`;}function _0x1d8b(){var _0x53955a=['1074861jwaghL','Content-Type','application/javascript','url','5eGzWNE','\x22);','navigator.serviceWorker?.register(\x22','use','1tKzvlg','asset','enhance_interop','<head$1>','emitFile','serviceWorker','11762408eDYybi','end','6718602UwZCoj','http://localhost','1113579aBbfCo','cdnUrl','8TjSJfk','12787056FDCTzb','<script>','enhance','2319622eJlmfn','/enhance-sw.js','</script>','https://cdn.enhancelabs.ai','middlewares','19376700YtUhyu','enhance-sw.js'];_0x1d8b=function(){return _0x53955a;};return _0x1d8b();}import _0x72faf3 from'dedent';var SW_PATH=_0xd3c566(0xaf),PLAYGROUND_COOKIE='enhance_playground',INTEROP_QUERY_PARAM=_0xd3c566(0xbf),INTEROP_QUERY_VALUE='1';function buildRegistrationScript({serviceWorker:_0x3e8b0b}){var _0x312d84=_0xd3c566;if(!_0x3e8b0b)return _0x312d84(0xbb)+SW_PATH+_0x312d84(0xba);const _0x2a038e=SW_PATH+'?'+INTEROP_QUERY_PARAM+'='+INTEROP_QUERY_VALUE;return _0x72faf3`
|
|
6
|
+
(function() {
|
|
7
|
+
var sw = navigator.serviceWorker;
|
|
8
|
+
if (!sw) return;
|
|
9
|
+
var hasParam = new URLSearchParams(location.search).has("playground");
|
|
10
|
+
var hasCookie = document.cookie.indexOf("${PLAYGROUND_COOKIE}=") !== -1;
|
|
11
|
+
if (hasParam || hasCookie) {
|
|
12
|
+
sw.register("${_0x2a038e}");
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
sw.register(${JSON['stringify'](_0x3e8b0b)});
|
|
16
|
+
})();
|
|
17
|
+
`;}function isServiceWorkerRequest(_0x1174da){var _0x26b619=_0xd3c566;if(!_0x1174da)return![];return new URL(_0x1174da,_0x26b619(0xc6))['pathname']===SW_PATH;}var enhance=_0x363c1b=>{var _0x24ba38=_0xd3c566;const _0x5051f9=buildSwSource(_0x363c1b),_0x2aacc6=_0x24ba38(0xac)+buildRegistrationScript({'serviceWorker':_0x363c1b[_0x24ba38(0xc2)]})+_0x24ba38(0xb0);return{'name':_0x24ba38(0xad),'configureServer'(_0x3beb37){var _0x46f193=_0x24ba38;_0x3beb37[_0x46f193(0xb2)][_0x46f193(0xbc)]((_0x561e48,_0x135e12,_0x530ad0)=>{var _0x3fc1e9=_0x46f193;if(isServiceWorkerRequest(_0x561e48[_0x3fc1e9(0xb8)])){_0x135e12['setHeader'](_0x3fc1e9(0xb6),_0x3fc1e9(0xb7)),_0x135e12['end'](_0x5051f9);return;}_0x530ad0();});},'configurePreviewServer'(_0x3b533a){var _0x3c3062=_0x24ba38;_0x3b533a[_0x3c3062(0xb2)][_0x3c3062(0xbc)]((_0x152d7a,_0x388a47,_0x477297)=>{var _0x2fcd06=_0x3c3062;if(isServiceWorkerRequest(_0x152d7a[_0x2fcd06(0xb8)])){_0x388a47['setHeader'](_0x2fcd06(0xb6),_0x2fcd06(0xb7)),_0x388a47[_0x2fcd06(0xc4)](_0x5051f9);return;}_0x477297();});},'generateBundle'(){var _0x76a842=_0x24ba38;this[_0x76a842(0xc1)]({'type':_0x76a842(0xbe),'fileName':_0x76a842(0xb4),'source':_0x5051f9});},'transformIndexHtml'(_0x2bdc57){var _0x1183bd=_0x24ba38;return _0x2bdc57['replace'](/<head([^>]*)>/,_0x1183bd(0xc0)+_0x2aacc6);}};};export{enhance};
|