@moku-labs/web 2.4.14 → 2.4.16

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/dist/index.d.cts CHANGED
@@ -914,9 +914,55 @@ type Api$4 = {
914
914
  */
915
915
  composeTitle(head: HeadConfig | undefined): string;
916
916
  };
917
+ //#endregion
918
+ //#region src/plugins/spa/prefetch.d.ts
919
+ /** The live preloader the kernel keeps on `state.prefetch`. */
920
+ interface Prefetcher {
921
+ /**
922
+ * Take the preload for `path` and remove it: one use only. Undefined on a miss or an
923
+ * entry older than 30 s.
924
+ *
925
+ * @param path - The page path (pathname + search).
926
+ * @returns The pending or settled page HTML, or `undefined`.
927
+ * @example
928
+ * // A navigation to /en/about/ right after a pointerdown on its link:
929
+ * state.prefetch?.take("/en/about/"); // Promise<string>; a second take returns undefined
930
+ */
931
+ take(path: string): Promise<string> | undefined;
932
+ /**
933
+ * Re-observe every eligible `a[href]` in the document. `"visible"` only; a no-op for
934
+ * `"intent"`. The kernel calls it at boot and after every swap.
935
+ *
936
+ * @example
937
+ * // After a swap mounted the new page's islands, watch the new page's links:
938
+ * state.prefetch?.observe();
939
+ */
940
+ observe(): void;
941
+ /**
942
+ * Remove the listeners, disconnect the observer, clear timers and idle callbacks, abort
943
+ * in-flight preloads, empty the map. Idempotent.
944
+ *
945
+ * @example
946
+ * // kernel.dispose() on app.stop(): no preload listener stays on document
947
+ * state.prefetch?.dispose();
948
+ * state.prefetch = null;
949
+ */
950
+ dispose(): void;
951
+ }
917
952
  declare namespace types_d_exports$8 {
918
- export { AnyVNode, ExtractApi$1 as ExtractApi, ISLAND_HOOK_NAMES, IslandContext, IslandDef, IslandEventHandler, IslandEvents, IslandHooks, IslandInstance, IslandRender, IslandRouteSlice, IslandSpec, IslandSpecExtras, IslandStateFactory, NavigateOptions, PageData, RenderResult, ResolvedSpaConfig, ScrollMode, SpaApi, SpaConfig, SpaContext, SpaDataReader, SpaEmitFunction, SpaEvents, SpaKernel, SpaKernelDeps, SpaRequire, SpaState, TransitionMode };
953
+ export { AnyVNode, ExtractApi$1 as ExtractApi, ISLAND_HOOK_NAMES, IslandContext, IslandDef, IslandEventHandler, IslandEvents, IslandHooks, IslandInstance, IslandRender, IslandRouteSlice, IslandSpec, IslandSpecExtras, IslandStateFactory, NavigateOptions, PageData, PrefetchMode, RenderResult, ResolvedSpaConfig, ScrollMode, SpaApi, SpaConfig, SpaContext, SpaDataReader, SpaEmitFunction, SpaEvents, SpaKernel, SpaKernelDeps, SpaRequire, SpaState, TransitionMode };
919
954
  }
955
+ /**
956
+ * When the spa preloads a linked page's HTML before the tap (`spa.prefetch`):
957
+ * - `false` — never; the page is fetched on click, as without the option;
958
+ * - `"intent"` — on `pointerdown` / `touchstart` at once, or after 65 ms of mouse hover;
959
+ * - `"visible"` — as `"intent"`, plus every link that enters the viewport, drained in idle
960
+ * time with at most 2 preloads in flight.
961
+ *
962
+ * @example
963
+ * createApp({ pluginConfigs: { spa: { prefetch: "visible" } } });
964
+ */
965
+ type PrefetchMode = false | "intent" | "visible";
920
966
  /** Per-navigation options for the programmatic navigators (`ctx.navigate` / `app.spa.navigate`). */
921
967
  interface NavigateOptions {
922
968
  /** Override the scroll behaviour for this single navigation (else the route/app default). */
@@ -1024,6 +1070,12 @@ type SpaConfig = {
1024
1070
  * Defaults to an empty array.
1025
1071
  */
1026
1072
  islands?: IslandDef[];
1073
+ /**
1074
+ * Preload a linked page's HTML before the tap, so the swap does not wait for the network.
1075
+ * A preload is used once, lives 30 s, and is skipped with save-data on, on a 2G connection,
1076
+ * and for a route the client DATA path renders. Defaults to `false` (fetch on click only).
1077
+ */
1078
+ prefetch?: PrefetchMode;
1027
1079
  };
1028
1080
  /** Resolved SPA config after defaults are applied. */
1029
1081
  interface ResolvedSpaConfig {
@@ -1039,6 +1091,8 @@ interface ResolvedSpaConfig {
1039
1091
  progressBar: boolean;
1040
1092
  /** Pre-registered islands. */
1041
1093
  islands: IslandDef[];
1094
+ /** The validated preload mode (`false` ⇒ no preload listeners at all). */
1095
+ prefetch: PrefetchMode;
1042
1096
  }
1043
1097
  /**
1044
1098
  * What a island's `render` may return:
@@ -1450,6 +1504,11 @@ interface SpaState {
1450
1504
  navigate: ((path: string, options?: NavigateOptions) => void) | null;
1451
1505
  /** The single shared SPA kernel instance (null until onInit builds it). */
1452
1506
  kernel: SpaKernel | null;
1507
+ /**
1508
+ * The live HTML preloader, built by `kernel.boot()` when `spa.prefetch` is not `false`.
1509
+ * Null before boot, after stop or `hardNavigate`, and when the mode is `false`.
1510
+ */
1511
+ prefetch: Prefetcher | null;
1453
1512
  }
1454
1513
  /** Public API of the spa plugin (registration / control surface). */
1455
1514
  type SpaApi = {
@@ -3491,12 +3550,6 @@ interface DataState {
3491
3550
  * the fetch settles, on success and on failure, so a failure is never cached.
3492
3551
  */
3493
3552
  pending: Map<string, Promise<unknown | null>>;
3494
- /**
3495
- * The preload bundle fetch while it is in flight (browser, `preload: "all"`).
3496
- * `at()` awaits it before fetching a single file. Never rejects. `null` when no
3497
- * bundle fetch is running.
3498
- */
3499
- bundle: Promise<void> | null;
3500
3553
  /** Cancels the scheduled idle callback or aborts the bundle fetch. `null` when nothing is scheduled. */
3501
3554
  cancelPreload: (() => void) | null;
3502
3555
  }
package/dist/index.d.mts CHANGED
@@ -912,9 +912,55 @@ type Api$4 = {
912
912
  */
913
913
  composeTitle(head: HeadConfig | undefined): string;
914
914
  };
915
+ //#endregion
916
+ //#region src/plugins/spa/prefetch.d.ts
917
+ /** The live preloader the kernel keeps on `state.prefetch`. */
918
+ interface Prefetcher {
919
+ /**
920
+ * Take the preload for `path` and remove it: one use only. Undefined on a miss or an
921
+ * entry older than 30 s.
922
+ *
923
+ * @param path - The page path (pathname + search).
924
+ * @returns The pending or settled page HTML, or `undefined`.
925
+ * @example
926
+ * // A navigation to /en/about/ right after a pointerdown on its link:
927
+ * state.prefetch?.take("/en/about/"); // Promise<string>; a second take returns undefined
928
+ */
929
+ take(path: string): Promise<string> | undefined;
930
+ /**
931
+ * Re-observe every eligible `a[href]` in the document. `"visible"` only; a no-op for
932
+ * `"intent"`. The kernel calls it at boot and after every swap.
933
+ *
934
+ * @example
935
+ * // After a swap mounted the new page's islands, watch the new page's links:
936
+ * state.prefetch?.observe();
937
+ */
938
+ observe(): void;
939
+ /**
940
+ * Remove the listeners, disconnect the observer, clear timers and idle callbacks, abort
941
+ * in-flight preloads, empty the map. Idempotent.
942
+ *
943
+ * @example
944
+ * // kernel.dispose() on app.stop(): no preload listener stays on document
945
+ * state.prefetch?.dispose();
946
+ * state.prefetch = null;
947
+ */
948
+ dispose(): void;
949
+ }
915
950
  declare namespace types_d_exports$8 {
916
- export { AnyVNode, ExtractApi$1 as ExtractApi, ISLAND_HOOK_NAMES, IslandContext, IslandDef, IslandEventHandler, IslandEvents, IslandHooks, IslandInstance, IslandRender, IslandRouteSlice, IslandSpec, IslandSpecExtras, IslandStateFactory, NavigateOptions, PageData, RenderResult, ResolvedSpaConfig, ScrollMode, SpaApi, SpaConfig, SpaContext, SpaDataReader, SpaEmitFunction, SpaEvents, SpaKernel, SpaKernelDeps, SpaRequire, SpaState, TransitionMode };
951
+ export { AnyVNode, ExtractApi$1 as ExtractApi, ISLAND_HOOK_NAMES, IslandContext, IslandDef, IslandEventHandler, IslandEvents, IslandHooks, IslandInstance, IslandRender, IslandRouteSlice, IslandSpec, IslandSpecExtras, IslandStateFactory, NavigateOptions, PageData, PrefetchMode, RenderResult, ResolvedSpaConfig, ScrollMode, SpaApi, SpaConfig, SpaContext, SpaDataReader, SpaEmitFunction, SpaEvents, SpaKernel, SpaKernelDeps, SpaRequire, SpaState, TransitionMode };
917
952
  }
953
+ /**
954
+ * When the spa preloads a linked page's HTML before the tap (`spa.prefetch`):
955
+ * - `false` — never; the page is fetched on click, as without the option;
956
+ * - `"intent"` — on `pointerdown` / `touchstart` at once, or after 65 ms of mouse hover;
957
+ * - `"visible"` — as `"intent"`, plus every link that enters the viewport, drained in idle
958
+ * time with at most 2 preloads in flight.
959
+ *
960
+ * @example
961
+ * createApp({ pluginConfigs: { spa: { prefetch: "visible" } } });
962
+ */
963
+ type PrefetchMode = false | "intent" | "visible";
918
964
  /** Per-navigation options for the programmatic navigators (`ctx.navigate` / `app.spa.navigate`). */
919
965
  interface NavigateOptions {
920
966
  /** Override the scroll behaviour for this single navigation (else the route/app default). */
@@ -1022,6 +1068,12 @@ type SpaConfig = {
1022
1068
  * Defaults to an empty array.
1023
1069
  */
1024
1070
  islands?: IslandDef[];
1071
+ /**
1072
+ * Preload a linked page's HTML before the tap, so the swap does not wait for the network.
1073
+ * A preload is used once, lives 30 s, and is skipped with save-data on, on a 2G connection,
1074
+ * and for a route the client DATA path renders. Defaults to `false` (fetch on click only).
1075
+ */
1076
+ prefetch?: PrefetchMode;
1025
1077
  };
1026
1078
  /** Resolved SPA config after defaults are applied. */
1027
1079
  interface ResolvedSpaConfig {
@@ -1037,6 +1089,8 @@ interface ResolvedSpaConfig {
1037
1089
  progressBar: boolean;
1038
1090
  /** Pre-registered islands. */
1039
1091
  islands: IslandDef[];
1092
+ /** The validated preload mode (`false` ⇒ no preload listeners at all). */
1093
+ prefetch: PrefetchMode;
1040
1094
  }
1041
1095
  /**
1042
1096
  * What a island's `render` may return:
@@ -1448,6 +1502,11 @@ interface SpaState {
1448
1502
  navigate: ((path: string, options?: NavigateOptions) => void) | null;
1449
1503
  /** The single shared SPA kernel instance (null until onInit builds it). */
1450
1504
  kernel: SpaKernel | null;
1505
+ /**
1506
+ * The live HTML preloader, built by `kernel.boot()` when `spa.prefetch` is not `false`.
1507
+ * Null before boot, after stop or `hardNavigate`, and when the mode is `false`.
1508
+ */
1509
+ prefetch: Prefetcher | null;
1451
1510
  }
1452
1511
  /** Public API of the spa plugin (registration / control surface). */
1453
1512
  type SpaApi = {
@@ -3489,12 +3548,6 @@ interface DataState {
3489
3548
  * the fetch settles, on success and on failure, so a failure is never cached.
3490
3549
  */
3491
3550
  pending: Map<string, Promise<unknown | null>>;
3492
- /**
3493
- * The preload bundle fetch while it is in flight (browser, `preload: "all"`).
3494
- * `at()` awaits it before fetching a single file. Never rejects. `null` when no
3495
- * bundle fetch is running.
3496
- */
3497
- bundle: Promise<void> | null;
3498
3551
  /** Cancels the scheduled idle callback or aborts the bundle fetch. `null` when nothing is scheduled. */
3499
3552
  cancelPreload: (() => void) | null;
3500
3553
  }