brumate 0.1.1 → 0.3.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.
Files changed (136) hide show
  1. package/dist/{boot-DN1ZU8Hg.d.ts → boot-C25Sa6vq.d.ts} +27 -2
  2. package/dist/cli.js +2 -2
  3. package/dist/client-BD6XT-s5.js +1968 -0
  4. package/dist/client-BD6XT-s5.js.map +1 -0
  5. package/dist/{client-DwJInP_a.d.ts → client-D0CqSxoO.d.ts} +211 -30
  6. package/dist/{client-routes-DakuM32C.js → client-routes-JTbGtukf.js} +28 -15
  7. package/dist/client-routes-JTbGtukf.js.map +1 -0
  8. package/dist/context-CTiSzQRc.js +27 -0
  9. package/dist/context-CTiSzQRc.js.map +1 -0
  10. package/dist/context-btHuB01Z.d.ts +42 -0
  11. package/dist/{cookies-Av5WFmcf.js → cookies-BzllthiF.js} +2 -1
  12. package/dist/cookies-BzllthiF.js.map +1 -0
  13. package/dist/defer-BbD7JQhj.js +56 -0
  14. package/dist/defer-BbD7JQhj.js.map +1 -0
  15. package/dist/devtools-CQgD7NPB.js +623 -0
  16. package/dist/devtools-CQgD7NPB.js.map +1 -0
  17. package/dist/devtools-panel-BVB-W5q4.js +1930 -0
  18. package/dist/devtools-panel-BVB-W5q4.js.map +1 -0
  19. package/dist/events-CSs7OwIC.js +85 -0
  20. package/dist/events-CSs7OwIC.js.map +1 -0
  21. package/dist/{files-DdT84mPy.js → files-BXSSrQgc.js} +34 -6
  22. package/dist/files-BXSSrQgc.js.map +1 -0
  23. package/dist/forms-Bg-CwGqX.js +406 -0
  24. package/dist/forms-Bg-CwGqX.js.map +1 -0
  25. package/dist/forms-Cl21hkHt.d.ts +281 -0
  26. package/dist/highlight.d.ts +17 -0
  27. package/dist/highlight.js +269 -0
  28. package/dist/highlight.js.map +1 -0
  29. package/dist/html-Bq1rFxX_.d.ts +92 -0
  30. package/dist/html-mNTKzaDD.js +241 -0
  31. package/dist/html-mNTKzaDD.js.map +1 -0
  32. package/dist/index.d.ts +123 -30
  33. package/dist/index.js +14 -6
  34. package/dist/index.js.map +1 -1
  35. package/dist/{inspect-BPchdWbU.js → inspect-BHpOw1LF.js} +1400 -121
  36. package/dist/inspect-BHpOw1LF.js.map +1 -0
  37. package/dist/{loader-Dc9OwY5I.js → loader-Dos_3NP0.js} +47 -11
  38. package/dist/loader-Dos_3NP0.js.map +1 -0
  39. package/dist/{navigate-CzLjnoPH.js → navigate-O78d_zGN.js} +115 -13
  40. package/dist/navigate-O78d_zGN.js.map +1 -0
  41. package/dist/produce-D0V0ICkz.d.ts +114 -0
  42. package/dist/produce-Doc91GkX.js +274 -0
  43. package/dist/produce-Doc91GkX.js.map +1 -0
  44. package/dist/routes-BZNt7DSZ.d.ts +38 -0
  45. package/dist/{rpc-9fSqL_YK.js → rpc-ygMRPmN4.js} +39 -23
  46. package/dist/rpc-ygMRPmN4.js.map +1 -0
  47. package/dist/runtime/batch.d.ts +23 -0
  48. package/dist/runtime/batch.js +69 -0
  49. package/dist/runtime/batch.js.map +1 -0
  50. package/dist/runtime/client.d.ts +5 -5
  51. package/dist/runtime/client.js +5 -1345
  52. package/dist/runtime/context.d.ts +2 -2
  53. package/dist/runtime/context.js +1 -1
  54. package/dist/runtime/devtools.d.ts +191 -5
  55. package/dist/runtime/devtools.js +1 -1
  56. package/dist/runtime/env.d.ts +44 -0
  57. package/dist/runtime/env.js +61 -0
  58. package/dist/runtime/env.js.map +1 -0
  59. package/dist/runtime/events.d.ts +42 -0
  60. package/dist/runtime/events.js +1 -0
  61. package/dist/runtime/forms.d.ts +2 -0
  62. package/dist/runtime/forms.js +1 -0
  63. package/dist/runtime/gather.d.ts +25 -0
  64. package/dist/runtime/gather.js +33 -0
  65. package/dist/runtime/gather.js.map +1 -0
  66. package/dist/runtime/hot.d.ts +1 -1
  67. package/dist/runtime/html.d.ts +2 -2
  68. package/dist/runtime/html.js +1 -1
  69. package/dist/runtime/loader.d.ts +2 -2
  70. package/dist/runtime/loader.js +2 -2
  71. package/dist/runtime/routes.d.ts +2 -21
  72. package/dist/runtime/routes.js +31 -1
  73. package/dist/runtime/routes.js.map +1 -1
  74. package/dist/runtime/server.d.ts +7 -5
  75. package/dist/runtime/server.js +6 -7
  76. package/dist/runtime/signals.d.ts +60 -3
  77. package/dist/runtime/signals.js +40 -2
  78. package/dist/runtime/signals.js.map +1 -1
  79. package/dist/runtime/static-loader.d.ts +2 -2
  80. package/dist/runtime/static-loader.js +1 -1
  81. package/dist/runtime/testing.d.ts +46 -5
  82. package/dist/runtime/testing.js +240 -33
  83. package/dist/runtime/testing.js.map +1 -1
  84. package/dist/runtime/values.d.ts +2 -0
  85. package/dist/runtime/values.js +24 -0
  86. package/dist/runtime/values.js.map +1 -0
  87. package/dist/secrets-BxagsJxJ.js +23 -0
  88. package/dist/secrets-BxagsJxJ.js.map +1 -0
  89. package/dist/server-CxVDYE_V.js +3417 -0
  90. package/dist/server-CxVDYE_V.js.map +1 -0
  91. package/dist/server-DuFYRXrd.d.ts +1460 -0
  92. package/dist/skew-FRmAy9iy.js +49 -0
  93. package/dist/skew-FRmAy9iy.js.map +1 -0
  94. package/dist/standard-schema-BNY82yX3.d.ts +63 -0
  95. package/dist/{static-loader-BcFh4ebX.d.ts → static-loader-Drpr0AzI.d.ts} +2 -2
  96. package/dist/static-loader-nZssh66R.js +333 -0
  97. package/dist/static-loader-nZssh66R.js.map +1 -0
  98. package/dist/stream-DCYZO4IF.js +424 -0
  99. package/dist/stream-DCYZO4IF.js.map +1 -0
  100. package/dist/values-B8C7CLvG.d.ts +63 -0
  101. package/dist/vite.d.ts +49 -1
  102. package/dist/vite.js +598 -68
  103. package/dist/vite.js.map +1 -1
  104. package/forms/forms.brm.ts +141 -0
  105. package/package.json +45 -3
  106. package/types.d.ts +9 -1
  107. package/dist/client-routes-DakuM32C.js.map +0 -1
  108. package/dist/context-BG8KCF3v.js +0 -15
  109. package/dist/context-BG8KCF3v.js.map +0 -1
  110. package/dist/context-aeo9esY9.d.ts +0 -16
  111. package/dist/cookies-Av5WFmcf.js.map +0 -1
  112. package/dist/devtools-BKjnHrnv.js +0 -113
  113. package/dist/devtools-BKjnHrnv.js.map +0 -1
  114. package/dist/devtools-panel-AWOn0VK2.js +0 -434
  115. package/dist/devtools-panel-AWOn0VK2.js.map +0 -1
  116. package/dist/files-DdT84mPy.js.map +0 -1
  117. package/dist/html-DEeoepg3.js +0 -152
  118. package/dist/html-DEeoepg3.js.map +0 -1
  119. package/dist/html-Du8jY2Cc.d.ts +0 -53
  120. package/dist/inspect-BPchdWbU.js.map +0 -1
  121. package/dist/loader-Dc9OwY5I.js.map +0 -1
  122. package/dist/navigate-CzLjnoPH.js.map +0 -1
  123. package/dist/produce-BRGHP7e0.js +0 -126
  124. package/dist/produce-BRGHP7e0.js.map +0 -1
  125. package/dist/produce-CtZ32UGG.d.ts +0 -60
  126. package/dist/rpc-9fSqL_YK.js.map +0 -1
  127. package/dist/runtime/client.js.map +0 -1
  128. package/dist/server-BxqjLUnV.d.ts +0 -753
  129. package/dist/server-DZsgnPKS.js +0 -1615
  130. package/dist/server-DZsgnPKS.js.map +0 -1
  131. package/dist/shared-CWYOd0H3.js +0 -40
  132. package/dist/shared-CWYOd0H3.js.map +0 -1
  133. package/dist/static-loader-ClNkHZGn.js +0 -185
  134. package/dist/static-loader-ClNkHZGn.js.map +0 -1
  135. package/dist/stream-bgNCMcaA.js +0 -280
  136. package/dist/stream-bgNCMcaA.js.map +0 -1
@@ -0,0 +1,49 @@
1
+ //#region src/runtime/trusted.ts
2
+ /** The name of the policy, for `trusted-types brumate` in the policy of the site. */
3
+ const POLICY = "brumate";
4
+ /** The policy, made on the first insert. Null where the browser has no Trusted Types. */
5
+ let policy;
6
+ function ensure() {
7
+ if (policy !== void 0) return policy;
8
+ const factory = globalThis.trustedTypes;
9
+ policy = null;
10
+ if (factory) try {
11
+ policy = factory.createPolicy(POLICY, {
12
+ createHTML: (html) => html,
13
+ createScript: (code) => code
14
+ });
15
+ } catch (error) {
16
+ console.error(`brumate: the Content Security Policy does not allow the Trusted Types policy "${POLICY}". Add "trusted-types ${POLICY}" to it`, error);
17
+ }
18
+ return policy;
19
+ }
20
+ /** Markup that the core made, as the browser accepts it in `innerHTML`. */
21
+ function trustedHTML(html) {
22
+ return ensure()?.createHTML(html) ?? html;
23
+ }
24
+ /** The code of a script that came with the page, as the browser accepts it in a script's text. */
25
+ function trustedScript(code) {
26
+ return ensure()?.createScript(code) ?? code;
27
+ }
28
+ //#endregion
29
+ //#region src/runtime/skew.ts
30
+ const KEY = "brumate:builds";
31
+ /**
32
+ * True the first time in this tab that a page loads in full for `build`,
33
+ * the build that it loads. The build is kept, so the next time is false.
34
+ * Without session storage it is false, since the page cannot tell a loop.
35
+ */
36
+ function loadOnce(build) {
37
+ try {
38
+ const builds = JSON.parse(sessionStorage.getItem(KEY) ?? "[]");
39
+ if (builds.includes(build)) return false;
40
+ sessionStorage.setItem(KEY, JSON.stringify([...builds, build].slice(-8)));
41
+ return true;
42
+ } catch {
43
+ return false;
44
+ }
45
+ }
46
+ //#endregion
47
+ export { trustedHTML as n, trustedScript as r, loadOnce as t };
48
+
49
+ //# sourceMappingURL=skew-FRmAy9iy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skew-FRmAy9iy.js","names":[],"sources":["../src/runtime/trusted.ts","../src/runtime/skew.ts"],"sourcesContent":["// Trusted Types. A site whose Content Security Policy has\n// `require-trusted-types-for 'script'` refuses a string in `innerHTML` and\n// in the text of a script. The core passes the markup that it inserts, and\n// the scripts that it copies to run them, through a policy named `brumate`.\n// The markup is what brumate's own render code made, with every value\n// escaped, and the scripts come from the server with the page, so the\n// policy passes them as they are.\n\n/** The name of the policy, for `trusted-types brumate` in the policy of the site. */\nexport const POLICY = 'brumate';\n\ninterface Policy {\n createHTML(html: string): string;\n createScript(code: string): string;\n}\n\n/** The policy, made on the first insert. Null where the browser has no Trusted Types. */\nlet policy: Policy | null | undefined;\n\nfunction ensure(): Policy | null {\n if (policy !== undefined) {\n return policy;\n }\n const factory = (\n globalThis as {\n trustedTypes?: { createPolicy(name: string, rules: Policy): Policy };\n }\n ).trustedTypes;\n policy = null;\n if (factory) {\n try {\n policy = factory.createPolicy(POLICY, {\n createHTML: (html) => html,\n createScript: (code) => code,\n });\n } catch (error) {\n // The policy of the site names other policies, so the inserts below fail too.\n console.error(\n `brumate: the Content Security Policy does not allow the Trusted Types policy \"${POLICY}\". Add \"trusted-types ${POLICY}\" to it`,\n error,\n );\n }\n }\n return policy;\n}\n\n/** Markup that the core made, as the browser accepts it in `innerHTML`. */\nexport function trustedHTML(html: string): string {\n return ensure()?.createHTML(html) ?? html;\n}\n\n/** The code of a script that came with the page, as the browser accepts it in a script's text. */\nexport function trustedScript(code: string): string {\n return ensure()?.createScript(code) ?? code;\n}\n","// Skew protection in the browser. A page loads again, or in full, when the\n// site was deployed since it loaded. It does so once for each build in a\n// tab, so a deploy whose files are broken, a cache that serves an old page,\n// or a host that serves two builds at once cannot load pages in a loop.\n\nconst KEY = 'brumate:builds';\n\n/**\n * True the first time in this tab that a page loads in full for `build`,\n * the build that it loads. The build is kept, so the next time is false.\n * Without session storage it is false, since the page cannot tell a loop.\n */\nexport function loadOnce(build: string): boolean {\n try {\n const builds = JSON.parse(sessionStorage.getItem(KEY) ?? '[]') as string[];\n if (builds.includes(build)) {\n return false;\n }\n // The last builds are enough to stop a loop between two of them.\n sessionStorage.setItem(KEY, JSON.stringify([...builds, build].slice(-8)));\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":";;AASA,MAAa,SAAS;;AAQtB,IAAI;AAEJ,SAAS,SAAwB;CAC/B,IAAI,WAAW,KAAA,GACb,OAAO;CAET,MAAM,UACJ,WAGA;CACF,SAAS;CACT,IAAI,SACF,IAAI;EACF,SAAS,QAAQ,aAAa,QAAQ;GACpC,aAAa,SAAS;GACtB,eAAe,SAAS;EAC1B,CAAC;CACH,SAAS,OAAO;EAEd,QAAQ,MACN,iFAAiF,OAAO,wBAAwB,OAAO,UACvH,KACF;CACF;CAEF,OAAO;AACT;;AAGA,SAAgB,YAAY,MAAsB;CAChD,OAAO,OAAO,CAAC,EAAE,WAAW,IAAI,KAAK;AACvC;;AAGA,SAAgB,cAAc,MAAsB;CAClD,OAAO,OAAO,CAAC,EAAE,aAAa,IAAI,KAAK;AACzC;;;ACjDA,MAAM,MAAM;;;;;;AAOZ,SAAgB,SAAS,OAAwB;CAC/C,IAAI;EACF,MAAM,SAAS,KAAK,MAAM,eAAe,QAAQ,GAAG,KAAK,IAAI;EAC7D,IAAI,OAAO,SAAS,KAAK,GACvB,OAAO;EAGT,eAAe,QAAQ,KAAK,KAAK,UAAU,CAAC,GAAG,QAAQ,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;EACxE,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF"}
@@ -0,0 +1,63 @@
1
+ //#region src/runtime/standard-schema.d.ts
2
+ /** The Standard Schema interface. */
3
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
4
+ /** The Standard Schema properties. */
5
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
6
+ }
7
+ declare namespace StandardSchemaV1 {
8
+ /** The Standard Schema properties interface. */
9
+ export interface Props<Input = unknown, Output = Input> {
10
+ /** The version number of the standard. */
11
+ readonly version: 1;
12
+ /** The vendor name of the schema library. */
13
+ readonly vendor: string;
14
+ /** Validates unknown input values. */
15
+ readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
16
+ /** Inferred types associated with the schema. */
17
+ readonly types?: Types<Input, Output> | undefined;
18
+ }
19
+ /** The result interface of the validate function. */
20
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
21
+ /** The result interface if validation succeeds. */
22
+ export interface SuccessResult<Output> {
23
+ /** The typed output value. */
24
+ readonly value: Output;
25
+ /** A falsy value for `issues` indicates success. */
26
+ readonly issues?: undefined;
27
+ }
28
+ export interface Options {
29
+ /** Explicit support for additional vendor-specific parameters, if needed. */
30
+ readonly libraryOptions?: Record<string, unknown> | undefined;
31
+ }
32
+ /** The result interface if validation fails. */
33
+ export interface FailureResult {
34
+ /** The issues of failed validation. */
35
+ readonly issues: ReadonlyArray<Issue>;
36
+ }
37
+ /** The issue interface of the failure output. */
38
+ export interface Issue {
39
+ /** The error message of the issue. */
40
+ readonly message: string;
41
+ /** The path of the issue, if any. */
42
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
43
+ }
44
+ /** The path segment interface of the issue. */
45
+ export interface PathSegment {
46
+ /** The key representing a path segment. */
47
+ readonly key: PropertyKey;
48
+ }
49
+ /** The Standard Schema types interface. */
50
+ export interface Types<Input = unknown, Output = Input> {
51
+ /** The input type of the schema. */
52
+ readonly input: Input;
53
+ /** The output type of the schema. */
54
+ readonly output: Output;
55
+ }
56
+ /** Infers the input type of a Standard Schema. */
57
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
58
+ /** Infers the output type of a Standard Schema. */
59
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
60
+ }
61
+ //#endregion
62
+ export { StandardSchemaV1 as t };
63
+ //# sourceMappingURL=standard-schema-BNY82yX3.d.ts.map
@@ -1,4 +1,4 @@
1
- import { t as LoaderOptions } from "./boot-DN1ZU8Hg.js";
1
+ import { t as LoaderOptions } from "./boot-C25Sa6vq.js";
2
2
  //#region src/runtime/static-loader.d.ts
3
3
  /**
4
4
  * `start` for a site that loads every page with a full page load, as with
@@ -8,4 +8,4 @@ import { t as LoaderOptions } from "./boot-DN1ZU8Hg.js";
8
8
  declare function startWithoutNavigation(options: LoaderOptions): () => void;
9
9
  //#endregion
10
10
  export { startWithoutNavigation as t };
11
- //# sourceMappingURL=static-loader-BcFh4ebX.d.ts.map
11
+ //# sourceMappingURL=static-loader-Drpr0AzI.d.ts.map
@@ -0,0 +1,333 @@
1
+ //#region src/runtime/boot.ts
2
+ /** True on the dev server. A Vite build replaces it with `false`, so the devtools calls go. */
3
+ const DEV = import.meta.env?.DEV;
4
+ /** The hooks of the devtools overlay, under the same key as the core's. */
5
+ function devtools() {
6
+ return globalThis[Symbol.for("brumate.devtools")];
7
+ }
8
+ const parsed = /* @__PURE__ */ new Map();
9
+ function entries(element) {
10
+ const value = element.getAttribute("b-on") ?? "";
11
+ return parsed.get(value) ?? parsed.set(value, value.split(" ").filter(Boolean).map((entry) => {
12
+ const [name, ref] = entry.split("=");
13
+ const [type, ...modifiers] = name.split(":");
14
+ return {
15
+ raw: entry,
16
+ type,
17
+ modifiers,
18
+ ref
19
+ };
20
+ })).get(value);
21
+ }
22
+ /** The `prefetch` strategy of an element, from its `data-prefetch`. */
23
+ function strategy(element) {
24
+ return element.getAttribute("data-prefetch") ?? "hover";
25
+ }
26
+ /**
27
+ * Imports the core. It reads one export by name, so a build keeps only it and
28
+ * the helpers that compiled components call.
29
+ */
30
+ let corePromise;
31
+ const importCore = () => corePromise ??= import("./runtime/client.js").then((client) => client.loader, (error) => {
32
+ corePromise = void 0;
33
+ throw error;
34
+ });
35
+ /** Runs a function when the browser is idle. */
36
+ const idle = (fn) => (window.requestIdleCallback ?? setTimeout)(fn);
37
+ /**
38
+ * Starts resuming the page. Listens to the events in `b-on` attributes
39
+ * and loads `brumate/client` and the component's module on the first one.
40
+ * `navigate` adds client navigation, and returns how to import the core.
41
+ * Returns a function that removes the listeners and stops the core.
42
+ */
43
+ function boot(options, navigate) {
44
+ let core;
45
+ /** The event types that the document listens to, and whether each listener is passive. */
46
+ const types = /* @__PURE__ */ new Map();
47
+ const removers = [];
48
+ const listen = (target, type, listener, flags) => {
49
+ target.addEventListener(type, listener, flags);
50
+ removers.push(() => target.removeEventListener(type, listener, flags));
51
+ };
52
+ let load = importCore;
53
+ const modules = /* @__PURE__ */ new Map();
54
+ const loadModule = (id) => {
55
+ if (modules.has(id)) return modules.get(id);
56
+ const promise = options.load(id);
57
+ modules.set(id, promise);
58
+ promise?.catch(() => modules.delete(id));
59
+ return promise;
60
+ };
61
+ const partLoads = /* @__PURE__ */ new Map();
62
+ const loadPart = (module, part) => {
63
+ const key = `${module.id}#${part}`;
64
+ let promise = partLoads.get(key);
65
+ if (!promise) {
66
+ promise = module.load(part);
67
+ partLoads.set(key, promise);
68
+ promise.catch(() => partLoads.delete(key));
69
+ }
70
+ return promise;
71
+ };
72
+ let serialLoad;
73
+ const loadSerial = () => {
74
+ serialLoad ??= options.serial?.();
75
+ serialLoad?.catch(() => serialLoad = void 0);
76
+ return serialLoad;
77
+ };
78
+ const loadCore = () => core ??= Promise.all([load(), loadSerial()]).then(([client, serial]) => {
79
+ client.init({
80
+ ...options,
81
+ load: loadModule,
82
+ loadPart,
83
+ listen: scanInsert,
84
+ inserted,
85
+ serial
86
+ });
87
+ return client;
88
+ });
89
+ listen(document, "brumate:core", () => void loadCore());
90
+ const warmed = /* @__PURE__ */ new Set();
91
+ const parts = /* @__PURE__ */ new Map();
92
+ const partOf = (ref) => {
93
+ if (parts.has(ref)) return parts.get(ref);
94
+ let found;
95
+ if (!ref.startsWith("$")) {
96
+ const [id, name] = ref.split("@")[0].split("#");
97
+ found = [id, /^[hct]\d/.test(name) ? name : "update"];
98
+ }
99
+ parts.set(ref, found);
100
+ return found;
101
+ };
102
+ const warmedAll = (element) => {
103
+ for (const entry of entries(element)) {
104
+ const found = partOf(entry.ref);
105
+ if (found && !warmed.has(`${found[0]}#${found[1]}`)) return false;
106
+ }
107
+ return true;
108
+ };
109
+ const warm = (ref, reason) => {
110
+ const found = partOf(ref);
111
+ if (!found) return;
112
+ const [id, part] = found;
113
+ const key = `${id}#${part}`;
114
+ if (warmed.has(key)) return;
115
+ warmed.add(key);
116
+ const done = loadModule(id)?.then((module) => {
117
+ if (!module.load) return;
118
+ if (part !== "update") loadPart(module, "update").catch(() => {});
119
+ return loadPart(module, part);
120
+ });
121
+ done?.catch(() => warmed.delete(key));
122
+ if (DEV && done) devtools()?.load?.(id, part, reason, done);
123
+ };
124
+ const run = (element, ref, event) => {
125
+ warm(ref, event ? "event" : "block");
126
+ loadCore().then((client) => client.handle(element, ref, event));
127
+ };
128
+ const apply = (event, element, entry) => {
129
+ for (const modifier of entry.modifiers) if (modifier === "prevent" || modifier.startsWith("prevent(") && modifier.slice(8, -1).split(",").includes(event.key === " " ? "Space" : event.key)) event.preventDefault();
130
+ if (entry.modifiers.includes("once")) element.setAttribute("b-on", entries(element).map((item) => item.raw).filter((raw) => raw !== entry.raw).join(" "));
131
+ run(element, entry.ref, event);
132
+ return entry.modifiers.includes("stop");
133
+ };
134
+ /**
135
+ * Handlers run as if each element had its own listener: those with
136
+ * `capture` from the outside in, then the others from the target outwards.
137
+ * An event that does not bubble, such as `focus`, reaches only the others
138
+ * of its target. `stop` ends the event where it is.
139
+ */
140
+ const onEvent = (event) => {
141
+ const path = [];
142
+ for (let node = event.target; node && node !== document; node = node.parentNode) if (node.nodeType === 1 && node.hasAttribute("b-on")) path.push(node);
143
+ const phase = (elements, capture) => {
144
+ for (const element of elements) {
145
+ let stop = false;
146
+ for (const entry of entries(element)) if (entry.type === event.type && entry.modifiers.includes("capture") === capture && apply(event, element, entry)) stop = true;
147
+ if (stop) {
148
+ event.stopPropagation();
149
+ return true;
150
+ }
151
+ }
152
+ return false;
153
+ };
154
+ if (!phase([...path].reverse(), true)) phase(event.bubbles ? path : path.filter((element) => element === event.target), false);
155
+ };
156
+ /** True for an entry that prevents the default action, which a passive listener cannot do. */
157
+ const prevents = (entry) => entry.modifiers.some((modifier) => modifier.startsWith("prevent"));
158
+ /**
159
+ * Listens to an event type on the document. The listener is passive, so
160
+ * scrolling does not wait for it, until an entry of the type prevents.
161
+ */
162
+ const delegate = (type, prevent) => {
163
+ const passive = types.get(type);
164
+ if (passive === false || passive === true && !prevent) return;
165
+ if (passive) document.removeEventListener(type, onEvent, true);
166
+ types.set(type, !prevent);
167
+ listen(document, type, onEvent, {
168
+ capture: true,
169
+ passive: !prevent
170
+ });
171
+ };
172
+ const started = /* @__PURE__ */ new WeakSet();
173
+ const select = (root, selector) => {
174
+ const found = [];
175
+ const add = (element) => {
176
+ if (element.tagName === "TEMPLATE") {
177
+ if (started.has(element)) return;
178
+ started.add(element);
179
+ }
180
+ found.push(element);
181
+ };
182
+ if (root.matches?.(selector)) add(root);
183
+ for (const element of root.querySelectorAll(selector)) add(element);
184
+ return found;
185
+ };
186
+ const visible = typeof IntersectionObserver === "undefined" ? void 0 : new IntersectionObserver((records) => {
187
+ for (const record of records) if (record.isIntersecting) {
188
+ visible.unobserve(record.target);
189
+ preload(record.target, eagerly.has(record.target) ? "eager" : "visible");
190
+ }
191
+ }, { rootMargin: "25%" });
192
+ removers.push(() => visible?.disconnect());
193
+ const eagerly = /* @__PURE__ */ new WeakSet();
194
+ let eager = false;
195
+ const delegated = /* @__PURE__ */ new Set();
196
+ const ready = /* @__PURE__ */ new Set();
197
+ const onElement = (element) => {
198
+ const value = element.getAttribute("b-on");
199
+ if (!delegated.has(value)) {
200
+ delegated.add(value);
201
+ for (const entry of entries(element)) delegate(entry.type, prevents(entry));
202
+ }
203
+ if (!eager || ready.has(value) || strategy(element) !== "hover") return;
204
+ if (warmedAll(element)) {
205
+ ready.add(value);
206
+ return;
207
+ }
208
+ eagerly.add(element);
209
+ visible?.observe(element);
210
+ };
211
+ const onListener = (template) => {
212
+ const target = template.getAttribute("b-listen") === "window" ? window : document;
213
+ for (const entry of entries(template)) listen(target, entry.type, (event) => {
214
+ if (template.isConnected) apply(event, template, entry);
215
+ }, {
216
+ capture: entry.modifiers.includes("capture"),
217
+ passive: !prevents(entry)
218
+ });
219
+ };
220
+ const onBlock = (root, template) => {
221
+ const client = template.getAttribute("b-client");
222
+ const [trigger, ref] = (client ?? template.getAttribute("b-defer")).split(client ? "=" : ":");
223
+ const go = () => {
224
+ if (client) {
225
+ run(template, ref);
226
+ return;
227
+ }
228
+ const done = import("./defer-BbD7JQhj.js").then((module) => module.loadDeferred(template));
229
+ if (DEV) devtools()?.defer?.(template, done);
230
+ };
231
+ const near = template.getAttribute("b-near");
232
+ const next = near && (root.querySelector(`[b-b="${near}"]`) ?? document.querySelector(`[b-b="${near}"]`)) || template.nextElementSibling;
233
+ if (trigger === "idle") idle(go);
234
+ else if (trigger === "visible" && next && visible) {
235
+ const observer = new IntersectionObserver((records) => {
236
+ if (records.some((record) => record.isIntersecting)) {
237
+ observer.disconnect();
238
+ go();
239
+ }
240
+ });
241
+ observer.observe(next);
242
+ } else go();
243
+ };
244
+ const SCANNED = "[data-prefetch=visible],[data-prefetch=idle],[b-on],template[b-listen],template[b-client],template[b-defer]";
245
+ const scan = (root) => {
246
+ const blocks = [];
247
+ for (const element of select(root, SCANNED)) {
248
+ if (element.tagName === "TEMPLATE") {
249
+ if (element.hasAttribute("b-listen")) onListener(element);
250
+ else if (element.hasAttribute("b-client") || element.hasAttribute("b-defer") && !element.hasAttribute("b-hole")) blocks.push(element);
251
+ continue;
252
+ }
253
+ if (element.hasAttribute("data-prefetch")) {
254
+ const prefetch = element.getAttribute("data-prefetch");
255
+ if (prefetch === "visible" || prefetch === "idle") {
256
+ if (strategy(element) === "idle" || !visible) idle(() => preload(element, strategy(element) === "idle" ? "idle" : "visible"));
257
+ else visible.observe(element);
258
+ }
259
+ }
260
+ if (element.hasAttribute("b-on")) onElement(element);
261
+ }
262
+ for (const template of blocks) onBlock(root, template);
263
+ };
264
+ const preloaded = /* @__PURE__ */ new WeakSet();
265
+ const preload = (element, reason) => {
266
+ if (preloaded.has(element)) return;
267
+ preloaded.add(element);
268
+ importCore();
269
+ loadSerial()?.catch(() => {});
270
+ for (const entry of entries(element)) warm(entry.ref, reason);
271
+ };
272
+ const hover = (event) => {
273
+ const element = event.target.closest?.("[b-on]");
274
+ if (element && strategy(element) === "hover") preload(element, "hover");
275
+ };
276
+ listen(document, "pointerover", hover, { passive: true });
277
+ listen(document, "focusin", hover);
278
+ listen(document, "submit", (event) => {
279
+ const form = event.target;
280
+ if (event.defaultPrevented || !form.hasAttribute?.("b-result")) return;
281
+ event.preventDefault();
282
+ const submitter = event.submitter;
283
+ loadCore().then((client) => client.submitAction(form, submitter));
284
+ });
285
+ if (navigate) load = navigate({
286
+ options,
287
+ listen,
288
+ core: () => core,
289
+ start: loadCore,
290
+ scan
291
+ });
292
+ else listen(document, "brumate:reload", () => location.reload());
293
+ scan(document);
294
+ const scanAdded = (records) => {
295
+ for (const record of records) for (const node of record.addedNodes) if (node.nodeType === 1) scan(node);
296
+ };
297
+ const observer = new MutationObserver(scanAdded);
298
+ observer.observe(document, {
299
+ childList: true,
300
+ subtree: true
301
+ });
302
+ const scanInsert = (root) => {
303
+ scanAdded(observer.takeRecords());
304
+ scan(root);
305
+ };
306
+ const inserted = () => {
307
+ observer.takeRecords();
308
+ };
309
+ const connection = navigator.connection;
310
+ if (options.preload !== false && !connection?.saveData && !/2g/.test(connection?.effectiveType)) listen(window, "load", () => idle(() => {
311
+ eager = true;
312
+ scan(document);
313
+ }));
314
+ return () => {
315
+ observer.disconnect();
316
+ for (const remove of removers.splice(0)) remove();
317
+ core?.then((client) => client.dispose());
318
+ };
319
+ }
320
+ //#endregion
321
+ //#region src/runtime/static-loader.ts
322
+ /**
323
+ * `start` for a site that loads every page with a full page load, as with
324
+ * `navigate: false`. A bundle that only calls it leaves out the code of
325
+ * client navigation.
326
+ */
327
+ function startWithoutNavigation(options) {
328
+ return boot(options);
329
+ }
330
+ //#endregion
331
+ export { strategy as i, boot as n, importCore as r, startWithoutNavigation as t };
332
+
333
+ //# sourceMappingURL=static-loader-nZssh66R.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-loader-nZssh66R.js","names":[],"sources":["../src/runtime/boot.ts","../src/runtime/static-loader.ts"],"sourcesContent":["// The loader's code that every page runs. `loader.ts` adds client navigation,\n// and `static-loader.ts` starts it without, so a site that turns navigation\n// off does not have its code, or the parts of the core that only it uses, in\n// its bundle.\n\nimport type * as Client from './client.ts';\nimport type { ClientModule, DevtoolsHooks, Part } from './client.ts';\nimport type { SerialEntry } from './values.ts';\n\n/** True on the dev server. A Vite build replaces it with `false`, so the devtools calls go. */\nconst DEV = (import.meta as { env?: { DEV?: boolean } }).env?.DEV;\n\n/** The hooks of the devtools overlay, under the same key as the core's. */\nfunction devtools(): DevtoolsHooks | undefined {\n return (globalThis as Record<symbol, DevtoolsHooks | undefined>)[Symbol.for('brumate.devtools')];\n}\n\nexport interface LoaderOptions {\n /**\n * Imports the client module of a component, by component ID. Undefined for\n * a component that has no client code.\n */\n load: (id: string) => Promise<ClientModule> | undefined;\n /** The URL prefix of server function calls. */\n rpc?: string;\n /** Imports the serial entry, which the core takes before it reads the page state. */\n serial?: () => Promise<SerialEntry>;\n /**\n * Loads pages without a full page load: links to the same origin, the back\n * and forward buttons, forms that post to a server function, and redirects\n * from server functions to the same origin. Defaults to true.\n */\n navigate?: boolean | NavigateOptions;\n /**\n * After the page loads, while the browser is idle, loads the core and the\n * code of the handlers of elements in or near the viewport, so a first\n * event needs no request. Elements with `data-prefetch=\"none\"` are left\n * out, and nothing loads when the browser asks to save data or the\n * connection is 2G. Defaults to true.\n */\n preload?: boolean;\n /**\n * The ID of the build of the page, for skew protection. The Vite plugin\n * sets it. Calls send it, and a page of another build, or a call that\n * answers 409 after a deploy, makes the next navigation a full page load.\n */\n build?: string;\n /**\n * Receives every error of client code first: of a handler, an effect, a\n * `$client` callback or a memo that loads, such as for a reporting\n * service. `scope` is the ID of the scope that the code belongs to. The\n * error then renders the `#catch` body of the nearest `#try`, or the page\n * gets a `brumate:error` event on `window` and the error is logged.\n */\n onError?: (error: unknown, info: { scope?: number | string }) => void;\n}\n\nexport interface NavigateOptions {\n /**\n * Swaps the page inside a view transition, where the browser has them.\n * CSS can tell links, the back and forward buttons and forms apart with\n * the types `push`, `traverse` and `form`. A redirect from a server\n * function has the type `form`.\n */\n transition?: boolean;\n /**\n * After a navigation, moves the focus to the first `<h1>` of the routes\n * that changed, or to `<main>`, as a full page load starts it at the top.\n * Defaults to true.\n */\n focus?: boolean;\n}\n\ninterface Entry {\n raw: string;\n type: string;\n modifiers: string[];\n ref: string;\n}\n\n// Parsed `b-on` values, so repeated events do not parse them again.\nconst parsed = new Map<string, Entry[]>();\n\nexport function entries(element: Element): Entry[] {\n const value = element.getAttribute('b-on') ?? '';\n return (parsed.get(value) ??\n parsed\n .set(\n value,\n value\n .split(' ')\n .filter(Boolean)\n .map((entry) => {\n const [name, ref] = entry.split('=') as [string, string];\n const [type, ...modifiers] = name.split(':') as [string, ...string[]];\n return { raw: entry, type, modifiers, ref };\n }),\n )\n .get(value))!;\n}\n\n/** The `prefetch` strategy of an element, from its `data-prefetch`. */\nexport function strategy(element: Element): string {\n return element.getAttribute('data-prefetch') ?? 'hover';\n}\n\n/** The functions of the core that the loader calls. */\nexport type Core = (typeof Client)['loader'];\n\n/**\n * Imports the core. It reads one export by name, so a build keeps only it and\n * the helpers that compiled components call.\n */\nlet corePromise: Promise<Core> | undefined;\nexport const importCore = (): Promise<Core> =>\n (corePromise ??= import('./client.ts').then(\n (client) => client.loader,\n (error: unknown) => {\n // A load that fails can start again, such as after the network comes back.\n corePromise = undefined;\n throw error;\n },\n ));\n\n/** Runs a function when the browser is idle. */\nconst idle = (fn: () => void): unknown => (window.requestIdleCallback ?? setTimeout)(fn);\n\n/** What the loader gives the code that loads pages without a full page load. */\nexport interface Navigation {\n options: LoaderOptions;\n listen: (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ) => void;\n core: () => Promise<Core> | undefined;\n /** Starts the core, or returns the one that runs. */\n start: () => Promise<Core>;\n scan: (root: ParentNode) => void;\n}\n\n/**\n * Starts resuming the page. Listens to the events in `b-on` attributes\n * and loads `brumate/client` and the component's module on the first one.\n * `navigate` adds client navigation, and returns how to import the core.\n * Returns a function that removes the listeners and stops the core.\n */\nexport function boot(\n options: LoaderOptions,\n navigate?: (navigation: Navigation) => () => Promise<Core>,\n): () => void {\n let core: Promise<Core> | undefined;\n /** The event types that the document listens to, and whether each listener is passive. */\n const types = new Map<string, boolean>();\n const removers: (() => void)[] = [];\n const listen = (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ): void => {\n target.addEventListener(type, listener, flags);\n removers.push(() => target.removeEventListener(type, listener, flags));\n };\n\n // Client navigation imports the core with the code that reads the pages it adds.\n let load = importCore;\n // The modules and parts that the loader asked for, which the core takes, so a handler whose\n // code loaded runs without another `import()`. In Chrome, an `import()` of a module that is\n // loaded already still resolves in a task of its own, which can wait for the next frame.\n const modules = new Map<string, Promise<ClientModule> | undefined>();\n const loadModule = (id: string): Promise<ClientModule> | undefined => {\n if (modules.has(id)) {\n return modules.get(id);\n }\n const promise = options.load(id);\n modules.set(id, promise);\n // A load that fails can start again, such as after the network comes back.\n promise?.catch(() => modules.delete(id));\n return promise;\n };\n const partLoads = new Map<string, Promise<Part>>();\n const loadPart = (module: ClientModule, part: string): Promise<Part> => {\n const key = `${module.id}#${part}`;\n let promise = partLoads.get(key);\n if (!promise) {\n promise = module.load!(part);\n partLoads.set(key, promise);\n promise.catch(() => partLoads.delete(key));\n }\n return promise;\n };\n // The serial entry loads with the core, so the core can make the values of the app.\n let serialLoad: Promise<SerialEntry> | undefined;\n const loadSerial = (): Promise<SerialEntry> | undefined => {\n serialLoad ??= options.serial?.();\n serialLoad?.catch(() => (serialLoad = undefined));\n return serialLoad;\n };\n const loadCore = (): Promise<Core> =>\n (core ??= Promise.all([load(), loadSerial()]).then(([client, serial]) => {\n client.init({ ...options, load: loadModule, loadPart, listen: scanInsert, inserted, serial });\n return client;\n }));\n\n // The devtools panel asks for the core when it opens, so it can show the page before any event.\n listen(document, 'brumate:core', () => void loadCore());\n\n // Starts loading the module of a handler and its part, as one step when the module holds them.\n // The core reports an error of the load when it runs the handler.\n // `reason` tells the devtools why: an event, a block, or a preload on hover, near the viewport,\n // on idle or after `load`.\n // The parts that loaded or are loading. A list of 1,000 rows names the same handlers 1,000\n // times, and each part loads once.\n const warmed = new Set<string>();\n // The module and part of each ref, which repeats for each row of a list.\n const parts = new Map<string, [id: string, part: string] | undefined>();\n const partOf = (ref: string): [id: string, part: string] | undefined => {\n if (parts.has(ref)) {\n return parts.get(ref);\n }\n let found: [string, string] | undefined;\n // A built-in of the core, such as `$bind`, has no code of a component to load.\n if (!ref.startsWith('$')) {\n // A handler that a spread passed on names its scope after `@`.\n const [id, name] = ref.split('@')[0]!.split('#') as [string, string];\n found = [id, /^[hct]\\d/.test(name) ? name : 'update'];\n }\n parts.set(ref, found);\n return found;\n };\n const warmedAll = (element: Element): boolean => {\n for (const entry of entries(element)) {\n const found = partOf(entry.ref);\n if (found && !warmed.has(`${found[0]}#${found[1]}`)) {\n return false;\n }\n }\n return true;\n };\n const warm = (ref: string, reason: string): void => {\n const found = partOf(ref);\n if (!found) {\n return;\n }\n const [id, part] = found;\n const key = `${id}#${part}`;\n if (warmed.has(key)) {\n return;\n }\n warmed.add(key);\n // The updates of the module too, which the handler's writes run.\n const done = loadModule(id)?.then((module) => {\n if (!module.load) {\n return undefined;\n }\n if (part !== 'update') {\n loadPart(module, 'update').catch(() => {});\n }\n return loadPart(module, part);\n });\n // A load that fails can start again, such as after the network comes back.\n void done?.catch(() => warmed.delete(key));\n if (DEV && done) {\n devtools()?.load?.(id, part, reason, done);\n }\n };\n\n const run = (element: Element, ref: string, event?: Event): void => {\n // The module loads while the core does, not after it.\n warm(ref, event ? 'event' : 'block');\n void loadCore().then((client) => client.handle(element, ref, event));\n };\n\n const apply = (event: Event, element: Element, entry: Entry): boolean => {\n for (const modifier of entry.modifiers) {\n // `prevent(ArrowDown,Enter)` prevents only these keys, by `event.key`.\n if (\n modifier === 'prevent' ||\n (modifier.startsWith('prevent(') &&\n modifier\n .slice(8, -1)\n .split(',')\n .includes(\n (event as KeyboardEvent).key === ' ' ? 'Space' : (event as KeyboardEvent).key,\n ))\n ) {\n event.preventDefault();\n }\n }\n if (entry.modifiers.includes('once')) {\n element.setAttribute(\n 'b-on',\n entries(element)\n .map((item) => item.raw)\n .filter((raw) => raw !== entry.raw)\n .join(' '),\n );\n }\n run(element, entry.ref, event);\n return entry.modifiers.includes('stop');\n };\n\n /**\n * Handlers run as if each element had its own listener: those with\n * `capture` from the outside in, then the others from the target outwards.\n * An event that does not bubble, such as `focus`, reaches only the others\n * of its target. `stop` ends the event where it is.\n */\n const onEvent = (event: Event): void => {\n const path: Element[] = [];\n for (\n let node = event.target as Node | null;\n node && node !== document;\n node = node.parentNode\n ) {\n if (node.nodeType === 1 && (node as Element).hasAttribute('b-on')) {\n path.push(node as Element);\n }\n }\n const phase = (elements: Element[], capture: boolean): boolean => {\n for (const element of elements) {\n let stop = false;\n for (const entry of entries(element)) {\n if (\n entry.type === event.type &&\n entry.modifiers.includes('capture') === capture &&\n apply(event, element, entry)\n ) {\n stop = true;\n }\n }\n if (stop) {\n event.stopPropagation();\n return true;\n }\n }\n return false;\n };\n if (!phase([...path].reverse(), true)) {\n phase(event.bubbles ? path : path.filter((element) => element === event.target), false);\n }\n };\n\n /** True for an entry that prevents the default action, which a passive listener cannot do. */\n const prevents = (entry: Entry): boolean =>\n entry.modifiers.some((modifier) => modifier.startsWith('prevent'));\n\n /**\n * Listens to an event type on the document. The listener is passive, so\n * scrolling does not wait for it, until an entry of the type prevents.\n */\n const delegate = (type: string, prevent: boolean): void => {\n const passive = types.get(type);\n if (passive === false || (passive === true && !prevent)) {\n return;\n }\n if (passive) {\n document.removeEventListener(type, onEvent, true);\n }\n types.set(type, !prevent);\n listen(document, type, onEvent, { capture: true, passive: !prevent });\n };\n\n // Templates are started once, even when markup is scanned again.\n const started = new WeakSet<Element>();\n const select = (root: ParentNode, selector: string): Element[] => {\n const found: Element[] = [];\n const add = (element: Element): void => {\n if (element.tagName === 'TEMPLATE') {\n if (started.has(element)) {\n return;\n }\n started.add(element);\n }\n found.push(element);\n };\n if ((root as Element).matches?.(selector)) {\n add(root as Element);\n }\n for (const element of root.querySelectorAll(selector)) {\n add(element);\n }\n return found;\n };\n\n const visible =\n typeof IntersectionObserver === 'undefined'\n ? undefined\n : new IntersectionObserver(\n (records) => {\n for (const record of records) {\n if (record.isIntersecting) {\n visible!.unobserve(record.target);\n preload(record.target, eagerly.has(record.target) ? 'eager' : 'visible');\n }\n }\n },\n // Near the viewport counts too, so code loads before an element scrolls in.\n { rootMargin: '25%' },\n );\n removers.push(() => visible?.disconnect());\n // Elements that preload near the viewport because the page is idle after `load`.\n const eagerly = new WeakSet<Element>();\n\n // True once the page is idle after `load`, when elements with the default strategy preload\n // as they come near the viewport. See `preload` in the options.\n let eager = false;\n\n // The values of `b-on` whose event types the document listens to already. The rows of a\n // list repeat the same few values.\n const delegated = new Set<string>();\n // The values of `b-on` whose parts loaded, so the elements with them have nothing to preload.\n const ready = new Set<string>();\n const onElement = (element: Element): void => {\n const value = element.getAttribute('b-on')!;\n if (!delegated.has(value)) {\n delegated.add(value);\n for (const entry of entries(element)) {\n delegate(entry.type, prevents(entry));\n }\n }\n // An element whose parts loaded already, such as a new row of a list, has nothing to preload.\n if (!eager || ready.has(value) || strategy(element) !== 'hover') {\n return;\n }\n if (warmedAll(element)) {\n ready.add(value);\n return;\n }\n eagerly.add(element);\n visible?.observe(element);\n };\n const onListener = (template: Element): void => {\n const target = template.getAttribute('b-listen') === 'window' ? window : document;\n for (const entry of entries(template)) {\n // Markup that is gone, such as a page that navigation replaced, no longer listens.\n listen(\n target,\n entry.type,\n (event) => {\n if (template.isConnected) {\n apply(event, template, entry);\n }\n },\n { capture: entry.modifiers.includes('capture'), passive: !prevents(entry) },\n );\n }\n };\n // A `#defer` block whose body the server sends in the same response, with `b-hole`, waits for it.\n const onBlock = (root: ParentNode, template: Element): void => {\n const client = template.getAttribute('b-client');\n const [trigger, ref] = (client ?? template.getAttribute('b-defer')!).split(\n client ? '=' : ':',\n ) as [string, string];\n // A `#defer` block asks the server for its body, with a module that only it needs.\n const go = (): void => {\n if (client) {\n run(template, ref);\n return;\n }\n const done = import('./defer.ts').then((module) => module.loadDeferred(template));\n if (DEV) {\n devtools()?.defer?.(template, done);\n }\n };\n // The element that a `$client` callback reads through `ref`, or the one after the marker.\n const near = template.getAttribute('b-near');\n const next =\n (near &&\n (root.querySelector(`[b-b=\"${near}\"]`) ?? document.querySelector(`[b-b=\"${near}\"]`))) ||\n template.nextElementSibling;\n if (trigger === 'idle') {\n idle(go);\n } else if (trigger === 'visible' && next && visible) {\n const observer = new IntersectionObserver((records) => {\n if (records.some((record) => record.isIntersecting)) {\n observer.disconnect();\n go();\n }\n });\n observer.observe(next);\n } else {\n go();\n }\n };\n const SCANNED =\n '[data-prefetch=visible],[data-prefetch=idle],[b-on],template[b-listen],template[b-client],template[b-defer]';\n // One query of the markup for everything that the loader starts. The blocks start after the\n // rest, as they did when each kind had its own query.\n const scan = (root: ParentNode): void => {\n const blocks: Element[] = [];\n for (const element of select(root, SCANNED)) {\n if (element.tagName === 'TEMPLATE') {\n if (element.hasAttribute('b-listen')) {\n onListener(element);\n } else if (\n element.hasAttribute('b-client') ||\n (element.hasAttribute('b-defer') && !element.hasAttribute('b-hole'))\n ) {\n blocks.push(element);\n }\n continue;\n }\n if (element.hasAttribute('data-prefetch')) {\n const prefetch = element.getAttribute('data-prefetch');\n if (prefetch === 'visible' || prefetch === 'idle') {\n if (strategy(element) === 'idle' || !visible) {\n idle(() => preload(element, strategy(element) === 'idle' ? 'idle' : 'visible'));\n } else {\n visible.observe(element);\n }\n }\n }\n if (element.hasAttribute('b-on')) {\n onElement(element);\n }\n }\n for (const template of blocks) {\n onBlock(root, template);\n }\n };\n\n // Preloads the core and the parts of an element's handlers, so its first event does not wait for them.\n const preloaded = new WeakSet<Element>();\n const preload = (element: Element, reason: string): void => {\n if (preloaded.has(element)) {\n return;\n }\n preloaded.add(element);\n void importCore();\n loadSerial()?.catch(() => {});\n for (const entry of entries(element)) {\n warm(entry.ref, reason);\n }\n };\n\n const hover = (event: Event): void => {\n const element = (event.target as Element).closest?.('[b-on]');\n if (element && strategy(element) === 'hover') {\n preload(element, 'hover');\n }\n };\n listen(document, 'pointerover', hover, { passive: true });\n listen(document, 'focusin', hover);\n\n // A form of an `$action` sends its data with `fetch`, and the core writes the result into the page.\n listen(document, 'submit', (event) => {\n const form = event.target as HTMLFormElement;\n if (event.defaultPrevented || !form.hasAttribute?.('b-result')) {\n return;\n }\n event.preventDefault();\n const submitter = (event as SubmitEvent).submitter;\n void loadCore().then((client) => client.submitAction(form, submitter));\n });\n\n if (navigate) {\n load = navigate({ options, listen, core: () => core, start: loadCore, scan });\n } else {\n // A hot update whose markup changed loads the page again.\n listen(document, 'brumate:reload', () => location.reload());\n }\n\n scan(document);\n // Markup that streams in later, such as a `#loading` body, has handlers too.\n const scanAdded = (records: MutationRecord[]): void => {\n for (const record of records) {\n for (const node of record.addedNodes) {\n if (node.nodeType === 1) {\n scan(node as Element);\n }\n }\n }\n };\n const observer = new MutationObserver(scanAdded);\n observer.observe(document, { childList: true, subtree: true });\n // The core scans the markup that it inserts before the insert, so the records of the insert\n // are dropped instead of scanned again. The markup that others inserted first is scanned\n // first.\n const scanInsert = (root: ParentNode): void => {\n scanAdded(observer.takeRecords());\n scan(root);\n };\n const inserted = (): void => {\n observer.takeRecords();\n };\n\n // After `load`, so the page's own requests go first, and only when the browser is idle.\n // `2g` matches `slow-2g` too.\n const connection = (navigator as { connection?: { saveData?: boolean; effectiveType?: string } })\n .connection;\n if (\n options.preload !== false &&\n !connection?.saveData &&\n !/2g/.test(connection?.effectiveType as string)\n ) {\n listen(window, 'load', () =>\n idle(() => {\n eager = true;\n scan(document);\n }),\n );\n }\n return () => {\n observer.disconnect();\n for (const remove of removers.splice(0)) {\n remove();\n }\n void core?.then((client) => client.dispose());\n };\n}\n","// The loader without client navigation, for `navigate: false`. It is a module\n// of its own, so a bundle that starts it has no import of the navigation code,\n// and keeps none of the core's exports that only navigation reads.\n\nimport { boot } from './boot.ts';\nimport type { LoaderOptions } from './boot.ts';\n\nexport type { LoaderOptions } from './boot.ts';\n\n/**\n * `start` for a site that loads every page with a full page load, as with\n * `navigate: false`. A bundle that only calls it leaves out the code of\n * client navigation.\n */\nexport function startWithoutNavigation(options: LoaderOptions): () => void {\n return boot(options);\n}\n"],"mappings":";;AAUA,MAAM,MAAO,YAA4C,KAAK;;AAG9D,SAAS,WAAsC;CAC7C,OAAQ,WAAyD,OAAO,IAAI,kBAAkB;AAChG;AAkEA,MAAM,yBAAS,IAAI,IAAqB;AAExC,SAAgB,QAAQ,SAA2B;CACjD,MAAM,QAAQ,QAAQ,aAAa,MAAM,KAAK;CAC9C,OAAQ,OAAO,IAAI,KAAK,KACtB,OACG,IACC,OACA,MACG,MAAM,GAAG,CAAC,CACV,OAAO,OAAO,CAAC,CACf,KAAK,UAAU;EACd,MAAM,CAAC,MAAM,OAAO,MAAM,MAAM,GAAG;EACnC,MAAM,CAAC,MAAM,GAAG,aAAa,KAAK,MAAM,GAAG;EAC3C,OAAO;GAAE,KAAK;GAAO;GAAM;GAAW;EAAI;CAC5C,CAAC,CACL,CAAC,CACA,IAAI,KAAK;AAChB;;AAGA,SAAgB,SAAS,SAA0B;CACjD,OAAO,QAAQ,aAAa,eAAe,KAAK;AAClD;;;;;AASA,IAAI;AACJ,MAAa,mBACV,gBAAgB,OAAO,sBAAc,CAAC,MACpC,WAAW,OAAO,SAClB,UAAmB;CAElB,cAAc,KAAA;CACd,MAAM;AACR,CACF;;AAGF,MAAM,QAAQ,QAA6B,OAAO,uBAAuB,WAAA,CAAY,EAAE;;;;;;;AAuBvF,SAAgB,KACd,SACA,UACY;CACZ,IAAI;;CAEJ,MAAM,wBAAQ,IAAI,IAAqB;CACvC,MAAM,WAA2B,CAAC;CAClC,MAAM,UACJ,QACA,MACA,UACA,UACS;EACT,OAAO,iBAAiB,MAAM,UAAU,KAAK;EAC7C,SAAS,WAAW,OAAO,oBAAoB,MAAM,UAAU,KAAK,CAAC;CACvE;CAGA,IAAI,OAAO;CAIX,MAAM,0BAAU,IAAI,IAA+C;CACnE,MAAM,cAAc,OAAkD;EACpE,IAAI,QAAQ,IAAI,EAAE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