@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/README.md CHANGED
@@ -225,6 +225,8 @@ Importing `@moku-labs/web/browser` can **never** drag node/native code into a cl
225
225
  bun run check:bundle # asserts: zero static node/native imports + under the gzip budget
226
226
  ```
227
227
 
228
+ The shipped `browser.mjs` has no JSDoc comments. This keeps it under the budget. `browser.d.mts` keeps them, so your editor still shows the docs.
229
+
228
230
  ## The route is the contract
229
231
 
230
232
  A route is a fluent builder. Each step is optional except `render`, and every type flows from it:
@@ -913,9 +913,55 @@ type Api$1 = {
913
913
  */
914
914
  composeTitle(head: HeadConfig | undefined): string;
915
915
  };
916
+ //#endregion
917
+ //#region src/plugins/spa/prefetch.d.ts
918
+ /** The live preloader the kernel keeps on `state.prefetch`. */
919
+ interface Prefetcher {
920
+ /**
921
+ * Take the preload for `path` and remove it: one use only. Undefined on a miss or an
922
+ * entry older than 30 s.
923
+ *
924
+ * @param path - The page path (pathname + search).
925
+ * @returns The pending or settled page HTML, or `undefined`.
926
+ * @example
927
+ * // A navigation to /en/about/ right after a pointerdown on its link:
928
+ * state.prefetch?.take("/en/about/"); // Promise<string>; a second take returns undefined
929
+ */
930
+ take(path: string): Promise<string> | undefined;
931
+ /**
932
+ * Re-observe every eligible `a[href]` in the document. `"visible"` only; a no-op for
933
+ * `"intent"`. The kernel calls it at boot and after every swap.
934
+ *
935
+ * @example
936
+ * // After a swap mounted the new page's islands, watch the new page's links:
937
+ * state.prefetch?.observe();
938
+ */
939
+ observe(): void;
940
+ /**
941
+ * Remove the listeners, disconnect the observer, clear timers and idle callbacks, abort
942
+ * in-flight preloads, empty the map. Idempotent.
943
+ *
944
+ * @example
945
+ * // kernel.dispose() on app.stop(): no preload listener stays on document
946
+ * state.prefetch?.dispose();
947
+ * state.prefetch = null;
948
+ */
949
+ dispose(): void;
950
+ }
916
951
  declare namespace types_d_exports$5 {
917
- export { AnyVNode, 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 };
952
+ export { AnyVNode, 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 };
918
953
  }
954
+ /**
955
+ * When the spa preloads a linked page's HTML before the tap (`spa.prefetch`):
956
+ * - `false` — never; the page is fetched on click, as without the option;
957
+ * - `"intent"` — on `pointerdown` / `touchstart` at once, or after 65 ms of mouse hover;
958
+ * - `"visible"` — as `"intent"`, plus every link that enters the viewport, drained in idle
959
+ * time with at most 2 preloads in flight.
960
+ *
961
+ * @example
962
+ * createApp({ pluginConfigs: { spa: { prefetch: "visible" } } });
963
+ */
964
+ type PrefetchMode = false | "intent" | "visible";
919
965
  /** Per-navigation options for the programmatic navigators (`ctx.navigate` / `app.spa.navigate`). */
920
966
  interface NavigateOptions {
921
967
  /** Override the scroll behaviour for this single navigation (else the route/app default). */
@@ -1023,6 +1069,12 @@ type SpaConfig = {
1023
1069
  * Defaults to an empty array.
1024
1070
  */
1025
1071
  islands?: IslandDef[];
1072
+ /**
1073
+ * Preload a linked page's HTML before the tap, so the swap does not wait for the network.
1074
+ * A preload is used once, lives 30 s, and is skipped with save-data on, on a 2G connection,
1075
+ * and for a route the client DATA path renders. Defaults to `false` (fetch on click only).
1076
+ */
1077
+ prefetch?: PrefetchMode;
1026
1078
  };
1027
1079
  /** Resolved SPA config after defaults are applied. */
1028
1080
  interface ResolvedSpaConfig {
@@ -1038,6 +1090,8 @@ interface ResolvedSpaConfig {
1038
1090
  progressBar: boolean;
1039
1091
  /** Pre-registered islands. */
1040
1092
  islands: IslandDef[];
1093
+ /** The validated preload mode (`false` ⇒ no preload listeners at all). */
1094
+ prefetch: PrefetchMode;
1041
1095
  }
1042
1096
  /**
1043
1097
  * What a island's `render` may return:
@@ -1449,6 +1503,11 @@ interface SpaState {
1449
1503
  navigate: ((path: string, options?: NavigateOptions) => void) | null;
1450
1504
  /** The single shared SPA kernel instance (null until onInit builds it). */
1451
1505
  kernel: SpaKernel | null;
1506
+ /**
1507
+ * The live HTML preloader, built by `kernel.boot()` when `spa.prefetch` is not `false`.
1508
+ * Null before boot, after stop or `hardNavigate`, and when the mode is `false`.
1509
+ */
1510
+ prefetch: Prefetcher | null;
1452
1511
  }
1453
1512
  /** Public API of the spa plugin (registration / control surface). */
1454
1513
  type SpaApi = {
@@ -2022,12 +2081,6 @@ interface DataState {
2022
2081
  * the fetch settles, on success and on failure, so a failure is never cached.
2023
2082
  */
2024
2083
  pending: Map<string, Promise<unknown | null>>;
2025
- /**
2026
- * The preload bundle fetch while it is in flight (browser, `preload: "all"`).
2027
- * `at()` awaits it before fetching a single file. Never rejects. `null` when no
2028
- * bundle fetch is running.
2029
- */
2030
- bundle: Promise<void> | null;
2031
2084
  /** Cancels the scheduled idle callback or aborts the bundle fetch. `null` when nothing is scheduled. */
2032
2085
  cancelPreload: (() => void) | null;
2033
2086
  }