@utoo/web 1.0.4 → 1.0.5

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.
@@ -1 +1 @@
1
- export declare function installServiceWorker(url: string, scope: string): Promise<void>;
1
+ export declare function installServiceWorker(url: string, scope: string, relativeDirToCwd?: string): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import { ServiceWorkerHandShake } from "./message";
2
- export async function installServiceWorker(url, scope) {
2
+ export async function installServiceWorker(url, scope, relativeDirToCwd) {
3
3
  const registration = await navigator.serviceWorker.register(url, {
4
4
  scope: "/",
5
5
  });
@@ -8,6 +8,7 @@ export async function installServiceWorker(url, scope) {
8
8
  sw.postMessage({
9
9
  [ServiceWorkerHandShake]: true,
10
10
  scope,
11
+ relativeDirToCwd,
11
12
  });
12
13
  resolve();
13
14
  }
package/esm/project.js CHANGED
@@ -55,9 +55,9 @@ export class Project {
55
55
  }
56
56
  async installServiceWorker() {
57
57
  if (this.serviceWorkerOptions) {
58
- const { url, scope } = this.serviceWorkerOptions;
58
+ const { url, scope, relativeDirToCwd } = this.serviceWorkerOptions;
59
59
  // Should add "Service-Worker-Allowed": "/" in page root response headers,
60
- return await installServiceWorker(url, scope);
60
+ return await installServiceWorker(url, scope, relativeDirToCwd);
61
61
  }
62
62
  }
63
63
  async mount() {
@@ -6,6 +6,7 @@ let _promise = new Promise((resolve) => {
6
6
  });
7
7
  let _projectEndpoint;
8
8
  let _serviceWorkerScope;
9
+ let _relativeDirToCwd;
9
10
  self.addEventListener("install", (event) => {
10
11
  event.waitUntil(self.skipWaiting());
11
12
  });
@@ -15,18 +16,20 @@ self.addEventListener("activate", (event) => {
15
16
  self.addEventListener("message", (event) => {
16
17
  if (event.data && event.data[ServiceWorkerHandShake] === true) {
17
18
  _serviceWorkerScope = event.data.scope;
19
+ _relativeDirToCwd = event.data.relativeDirToCwd;
18
20
  _projectEndpoint = Project.fork(new MessageChannel(), event.source);
19
21
  _resolve();
20
22
  }
21
23
  });
22
24
  self.addEventListener("fetch", async (event) => {
23
25
  await _promise;
24
- let { url, referrer } = event.request;
25
- url = decodeURIComponent(url);
26
- if (new URL(url).pathname.startsWith(_serviceWorkerScope) ||
26
+ let { url: url_str, referrer } = event.request;
27
+ let url = new URL(url_str);
28
+ if (url.pathname.startsWith(_serviceWorkerScope) ||
27
29
  (referrer && new URL(referrer).pathname.startsWith(_serviceWorkerScope))) {
28
- const projectPath = "." + new URL(url).pathname.replace(_serviceWorkerScope, "");
29
- event.respondWith(readFileFromProject(projectPath));
30
+ const relateivePathToCwd = (_relativeDirToCwd !== null && _relativeDirToCwd !== void 0 ? _relativeDirToCwd : ".") +
31
+ url.pathname.replace(_serviceWorkerScope, "");
32
+ event.respondWith(readFileFromProject(relateivePathToCwd));
30
33
  }
31
34
  else {
32
35
  return;
package/esm/type.d.ts CHANGED
@@ -52,5 +52,6 @@ export interface ProjectOptions {
52
52
  export interface ServiceWorkerOptions {
53
53
  url: string;
54
54
  scope: string;
55
+ relativeDirToCwd?: string;
55
56
  }
56
57
  export type Binding = Awaited<ReturnType<typeof initWasm>>;
package/esm/utoo/index.js CHANGED
@@ -315,6 +315,9 @@ function passArray8ToWasm0(arg, malloc) {
315
315
  export function wasm_thread_entry_point(ptr) {
316
316
  wasm.wasm_thread_entry_point(ptr);
317
317
  }
318
+ function __wbg_adapter_6(arg0, arg1, arg2) {
319
+ wasm.__wbindgen_export_6(arg0, arg1, addHeapObject(arg2));
320
+ }
318
321
  let stack_pointer = 128;
319
322
  function addBorrowedObject(obj) {
320
323
  if (stack_pointer == 1)
@@ -322,21 +325,18 @@ function addBorrowedObject(obj) {
322
325
  heap[--stack_pointer] = obj;
323
326
  return stack_pointer;
324
327
  }
325
- function __wbg_adapter_10(arg0, arg1, arg2) {
328
+ function __wbg_adapter_9(arg0, arg1, arg2) {
326
329
  try {
327
- wasm.__wbindgen_export_6(arg0, arg1, addBorrowedObject(arg2));
330
+ wasm.__wbindgen_export_7(arg0, arg1, addBorrowedObject(arg2));
328
331
  }
329
332
  finally {
330
333
  heap[stack_pointer++] = undefined;
331
334
  }
332
335
  }
333
- function __wbg_adapter_15(arg0, arg1) {
334
- wasm.__wbindgen_export_7(arg0, arg1);
335
- }
336
- function __wbg_adapter_18(arg0, arg1, arg2) {
337
- wasm.__wbindgen_export_8(arg0, arg1, addHeapObject(arg2));
336
+ function __wbg_adapter_12(arg0, arg1) {
337
+ wasm.__wbindgen_export_8(arg0, arg1);
338
338
  }
339
- function __wbg_adapter_21(arg0, arg1, arg2) {
339
+ function __wbg_adapter_15(arg0, arg1, arg2) {
340
340
  wasm.__wbindgen_export_9(arg0, arg1, addHeapObject(arg2));
341
341
  }
342
342
  function __wbg_adapter_94(arg0, arg1, arg2, arg3) {
@@ -1625,14 +1625,14 @@ function __wbg_get_imports() {
1625
1625
  const ret = getStringFromWasm0(arg0, arg1);
1626
1626
  return addHeapObject(ret);
1627
1627
  };
1628
- imports.wbg.__wbindgen_cast_2aafe3a70f74f3e0 = function (arg0, arg1) {
1629
- // Cast intrinsic for `Closure(Closure { dtor_idx: 8681, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 8682, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1630
- const ret = makeMutClosure(arg0, arg1, 8681, __wbg_adapter_18);
1628
+ imports.wbg.__wbindgen_cast_228b11ff07fcd80f = function (arg0, arg1) {
1629
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 8687, function: Function { arguments: [], shim_idx: 600, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1630
+ const ret = makeMutClosure(arg0, arg1, 8687, __wbg_adapter_12);
1631
1631
  return addHeapObject(ret);
1632
1632
  };
1633
- imports.wbg.__wbindgen_cast_3bfef9a8628dc119 = function (arg0, arg1) {
1634
- // Cast intrinsic for `Closure(Closure { dtor_idx: 8688, function: Function { arguments: [], shim_idx: 600, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1635
- const ret = makeMutClosure(arg0, arg1, 8688, __wbg_adapter_15);
1633
+ imports.wbg.__wbindgen_cast_3255823a0b603d96 = function (arg0, arg1) {
1634
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 8661, function: Function { arguments: [Ref(NamedExternref("MessageEvent"))], shim_idx: 8685, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1635
+ const ret = makeMutClosure(arg0, arg1, 8661, __wbg_adapter_9);
1636
1636
  return addHeapObject(ret);
1637
1637
  };
1638
1638
  imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function (arg0) {
@@ -1642,12 +1642,12 @@ function __wbg_get_imports() {
1642
1642
  };
1643
1643
  imports.wbg.__wbindgen_cast_4c807b347a3d0cbf = function (arg0, arg1) {
1644
1644
  // Cast intrinsic for `Closure(Closure { dtor_idx: 599, function: Function { arguments: [], shim_idx: 600, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1645
- const ret = makeMutClosure(arg0, arg1, 599, __wbg_adapter_15);
1645
+ const ret = makeMutClosure(arg0, arg1, 599, __wbg_adapter_12);
1646
1646
  return addHeapObject(ret);
1647
1647
  };
1648
- imports.wbg.__wbindgen_cast_5cc12922bca91779 = function (arg0, arg1) {
1649
- // Cast intrinsic for `Closure(Closure { dtor_idx: 8681, function: Function { arguments: [Externref], shim_idx: 8682, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1650
- const ret = makeMutClosure(arg0, arg1, 8681, __wbg_adapter_18);
1648
+ imports.wbg.__wbindgen_cast_535e935a655d72df = function (arg0, arg1) {
1649
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 8680, function: Function { arguments: [Externref], shim_idx: 8681, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1650
+ const ret = makeMutClosure(arg0, arg1, 8680, __wbg_adapter_6);
1651
1651
  return addHeapObject(ret);
1652
1652
  };
1653
1653
  imports.wbg.__wbindgen_cast_76322aab70622876 = function (arg0, arg1) {
@@ -1669,19 +1669,19 @@ function __wbg_get_imports() {
1669
1669
  const ret = arg0;
1670
1670
  return addHeapObject(ret);
1671
1671
  };
1672
- imports.wbg.__wbindgen_cast_9b1d89ef740b288c = function (arg0, arg1) {
1673
- // Cast intrinsic for `Closure(Closure { dtor_idx: 8662, function: Function { arguments: [Ref(NamedExternref("MessageEvent"))], shim_idx: 8686, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1674
- const ret = makeMutClosure(arg0, arg1, 8662, __wbg_adapter_10);
1672
+ imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function (arg0) {
1673
+ // Cast intrinsic for `F64 -> Externref`.
1674
+ const ret = arg0;
1675
1675
  return addHeapObject(ret);
1676
1676
  };
1677
- imports.wbg.__wbindgen_cast_9c5a3d861803a5de = function (arg0, arg1) {
1678
- // Cast intrinsic for `Closure(Closure { dtor_idx: 8662, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx: 8663, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
1679
- const ret = makeClosure(arg0, arg1, 8662, __wbg_adapter_21);
1677
+ imports.wbg.__wbindgen_cast_ded0188a991d8b3c = function (arg0, arg1) {
1678
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 8680, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 8681, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1679
+ const ret = makeMutClosure(arg0, arg1, 8680, __wbg_adapter_6);
1680
1680
  return addHeapObject(ret);
1681
1681
  };
1682
- imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function (arg0) {
1683
- // Cast intrinsic for `F64 -> Externref`.
1684
- const ret = arg0;
1682
+ imports.wbg.__wbindgen_cast_ffa04fbd359d627f = function (arg0, arg1) {
1683
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 8661, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx: 8662, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
1684
+ const ret = makeClosure(arg0, arg1, 8661, __wbg_adapter_15);
1685
1685
  return addHeapObject(ret);
1686
1686
  };
1687
1687
  imports.wbg.__wbindgen_link_dd5153a359f2e504 = function (arg0) {
Binary file