@ogygia/compiler 0.0.0-stage → 0.14.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 (156) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -2
  3. package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
  4. package/dist/app-spec.d.ts +18 -0
  5. package/dist/app-spec.js +22 -0
  6. package/dist/blank-styles.d.ts +1 -0
  7. package/dist/blank-styles.js +24 -0
  8. package/dist/bom.d.ts +2 -0
  9. package/dist/bom.js +7 -0
  10. package/dist/build-cache.d.ts +13 -0
  11. package/dist/build-cache.js +65 -0
  12. package/dist/ctx.d.ts +238 -0
  13. package/dist/ctx.js +221 -0
  14. package/dist/dev/css-scope.d.ts +16 -0
  15. package/dist/dev/css-scope.js +32 -0
  16. package/dist/dev/dev-hmr.d.ts +24 -0
  17. package/dist/dev/dev-hmr.js +51 -0
  18. package/dist/dev/hmr.d.ts +34 -0
  19. package/dist/dev/hmr.js +52 -0
  20. package/dist/driver.d.ts +349 -0
  21. package/dist/driver.js +1401 -0
  22. package/dist/exports/index.d.ts +77 -0
  23. package/dist/exports/index.js +349 -0
  24. package/dist/exports/parse.d.ts +65 -0
  25. package/dist/exports/parse.js +251 -0
  26. package/dist/fouc-css.d.ts +102 -0
  27. package/dist/fouc-css.js +304 -0
  28. package/dist/free-vars.d.ts +32 -0
  29. package/dist/free-vars.js +454 -0
  30. package/dist/fs.d.ts +31 -0
  31. package/dist/fs.js +82 -0
  32. package/dist/ids.d.ts +49 -0
  33. package/dist/ids.js +52 -0
  34. package/dist/index.d.ts +23 -0
  35. package/dist/index.js +23 -0
  36. package/dist/kit.d.ts +204 -0
  37. package/dist/kit.js +554 -0
  38. package/dist/leg.d.ts +34 -0
  39. package/dist/leg.js +26 -0
  40. package/dist/link/analyses.d.ts +26 -0
  41. package/dist/link/analyses.js +237 -0
  42. package/dist/link/build-output.d.ts +47 -0
  43. package/dist/link/build-output.js +168 -0
  44. package/dist/link/caps.d.ts +32 -0
  45. package/dist/link/caps.js +39 -0
  46. package/dist/link/context-detect.d.ts +28 -0
  47. package/dist/link/context-detect.js +143 -0
  48. package/dist/link/emit-gate.d.ts +43 -0
  49. package/dist/link/emit-gate.js +55 -0
  50. package/dist/link/file-token.d.ts +11 -0
  51. package/dist/link/file-token.js +15 -0
  52. package/dist/link/island-deps.d.ts +183 -0
  53. package/dist/link/island-deps.js +802 -0
  54. package/dist/link/location-map.d.ts +24 -0
  55. package/dist/link/location-map.js +51 -0
  56. package/dist/link/own-reach.d.ts +15 -0
  57. package/dist/link/own-reach.js +188 -0
  58. package/dist/link/registry-stub.d.ts +50 -0
  59. package/dist/link/registry-stub.js +163 -0
  60. package/dist/link/relocations.d.ts +79 -0
  61. package/dist/link/relocations.js +198 -0
  62. package/dist/link/router-css.d.ts +38 -0
  63. package/dist/link/router-css.js +124 -0
  64. package/dist/link/runtime-entry.d.ts +103 -0
  65. package/dist/link/runtime-entry.js +183 -0
  66. package/dist/link/server-manifest.d.ts +25 -0
  67. package/dist/link/server-manifest.js +102 -0
  68. package/dist/link/transport.d.ts +42 -0
  69. package/dist/link/transport.js +91 -0
  70. package/dist/macros/dollar.d.ts +24 -0
  71. package/dist/macros/dollar.js +397 -0
  72. package/dist/macros/pipeline.d.ts +50 -0
  73. package/dist/macros/pipeline.js +133 -0
  74. package/dist/macros/source.d.ts +9 -0
  75. package/dist/macros/source.js +115 -0
  76. package/dist/macros/store.d.ts +22 -0
  77. package/dist/macros/store.js +217 -0
  78. package/dist/macros/wire.d.ts +17 -0
  79. package/dist/macros/wire.js +116 -0
  80. package/dist/map-chain.d.ts +18 -0
  81. package/dist/map-chain.js +42 -0
  82. package/dist/messages.d.ts +672 -0
  83. package/dist/messages.js +938 -0
  84. package/dist/ownership-stamps.d.ts +9 -0
  85. package/dist/ownership-stamps.js +101 -0
  86. package/dist/parse/oxc.d.ts +36 -0
  87. package/dist/parse/oxc.js +35 -0
  88. package/dist/parse/roots.d.ts +4 -0
  89. package/dist/parse/roots.js +27 -0
  90. package/dist/parse/scan.d.ts +65 -0
  91. package/dist/parse/scan.js +297 -0
  92. package/dist/parse/svelte-ast.d.ts +7 -0
  93. package/dist/parse/svelte-ast.js +99 -0
  94. package/dist/program.d.ts +140 -0
  95. package/dist/program.js +304 -0
  96. package/dist/queries.d.ts +105 -0
  97. package/dist/queries.js +326 -0
  98. package/dist/region/emit.d.ts +168 -0
  99. package/dist/region/emit.js +292 -0
  100. package/dist/region/identity.d.ts +32 -0
  101. package/dist/region/identity.js +46 -0
  102. package/dist/region/ir.d.ts +56 -0
  103. package/dist/region/ir.js +0 -0
  104. package/dist/region/marked-imports.d.ts +27 -0
  105. package/dist/region/marked-imports.js +265 -0
  106. package/dist/region/transform.d.ts +189 -0
  107. package/dist/region/transform.js +1565 -0
  108. package/dist/scan-facts.d.ts +36 -0
  109. package/dist/scan-facts.js +54 -0
  110. package/dist/script-request.d.ts +1 -0
  111. package/dist/script-request.js +33 -0
  112. package/dist/splice.d.ts +11 -0
  113. package/dist/splice.js +33 -0
  114. package/dist/transportables.d.ts +23 -0
  115. package/dist/transportables.js +144 -0
  116. package/dist/virtual/core.d.ts +158 -0
  117. package/dist/virtual/core.js +588 -0
  118. package/dist/virtual/resolver.d.ts +56 -0
  119. package/dist/virtual/resolver.js +249 -0
  120. package/dist/virtual/specifier.d.ts +10 -0
  121. package/dist/virtual/specifier.js +6 -0
  122. package/dist/virtual/table.d.ts +118 -0
  123. package/dist/virtual/table.js +54 -0
  124. package/dist/virtual/types.d.ts +17 -0
  125. package/dist/virtual/types.js +100 -0
  126. package/dist/virtual/value-names.d.ts +2 -0
  127. package/dist/virtual/value-names.js +18 -0
  128. package/dist/vite/definers.d.ts +16 -0
  129. package/dist/vite/definers.js +69 -0
  130. package/dist/vite/dev-maps.d.ts +34 -0
  131. package/dist/vite/dev-maps.js +91 -0
  132. package/dist/vite/index.d.ts +21 -0
  133. package/dist/vite/index.js +874 -0
  134. package/dist/vite/kit-dirs.d.ts +6 -0
  135. package/dist/vite/kit-dirs.js +53 -0
  136. package/dist/vite/late-island.d.ts +11 -0
  137. package/dist/vite/late-island.js +19 -0
  138. package/dist/vite/lazy-files.d.ts +2 -0
  139. package/dist/vite/lazy-files.js +72 -0
  140. package/dist/vite/options.d.ts +195 -0
  141. package/dist/vite/options.js +72 -0
  142. package/dist/vite/package-files.d.ts +3 -0
  143. package/dist/vite/package-files.js +88 -0
  144. package/dist/vite/paths.d.ts +14 -0
  145. package/dist/vite/paths.js +37 -0
  146. package/dist/vite/plugin-api.d.ts +316 -0
  147. package/dist/vite/plugin-api.js +328 -0
  148. package/dist/vite/session.d.ts +28 -0
  149. package/dist/vite/session.js +43 -0
  150. package/dist/vite/sourcemaps.d.ts +19 -0
  151. package/dist/vite/sourcemaps.js +75 -0
  152. package/dist/vite/style-preprocess.d.ts +2 -0
  153. package/dist/vite/style-preprocess.js +84 -0
  154. package/dist/vite/svelte-entries.d.ts +4 -0
  155. package/dist/vite/svelte-entries.js +10 -0
  156. package/package.json +85 -3
@@ -0,0 +1,292 @@
1
+ import { lazyEntryVirtualId, regionBindingVirtualId } from "../ids.js";
2
+ // src/region/emit.ts
3
+ function render_html_source(moduleUrl) {
4
+ return `(props, wakes) => __ogRegionHtml(__ogRegionComp, ${JSON.stringify(moduleUrl)}, props, wakes)`;
5
+ }
6
+ /**
7
+ * The component-import line for a generated module — a NAMED export (`import { Header as X } from
8
+ * '@barrel'`, a marked named import) or a plain default (`import X from './X.svelte'`, a
9
+ * `.svelte` file or a package default). `exportName` is undefined/`'default'` for the default case.
10
+ */
11
+ function component_import_line(local, spec, exportName) {
12
+ return exportName && exportName !== "default" ? `import { ${exportName} as ${local} } from ${JSON.stringify(spec)};` : `import ${local} from ${JSON.stringify(spec)};`;
13
+ }
14
+ function region_entry_source(componentPath, iid, exportName) {
15
+ return `${component_import_line(`__OgygiaComp_${iid}`, componentPath, exportName)}
16
+ export default __OgygiaComp_${iid};
17
+ `;
18
+ }
19
+ /**
20
+ * The island ENTRY module — a JS re-export of the real component, loaded on both client hydrate and
21
+ * server render. The transportables import registers every `[ogygia.wire]` codec before props decode,
22
+ * so an island receiving a transportable prop never needs to import the class itself. Shared by the
23
+ * `.svelte` host and the `.ts` registry (a `wake:` mark) so a mountable binding is built the same way
24
+ * from either.
25
+ */
26
+ function island_entry_source(componentPath, iid, exportName) {
27
+ return `import 'ogygia:region/transportables-eager';
28
+ ${component_import_line(`__OgygiaComp_${iid}`, componentPath, exportName)}
29
+ export default __OgygiaComp_${iid};
30
+ ${FOREIGN_HYDRATE_MARK}import { og_entry_hydrate as __og_hy, og_entry_unmount as __og_unmount } from 'ogygia/internal';
31
+ export function __og_hydrate(target, props, options) {
32
+ \treturn __og_hy(__OgygiaComp_${iid}, target, props, options);
33
+ }
34
+ export { __og_unmount };
35
+ `;
36
+ }
37
+ /** Where an island entry's foreign-hydrate exports begin (compiler/driver.ts cuts from here). */
38
+ const FOREIGN_HYDRATE_MARK = "// og:foreign-hydrate\n";
39
+ /**
40
+ * The island WRAPPER (`.svelte`) — a MOUNTABLE component that renders `<ogygia-region>` on its wake
41
+ * schedule. Placing it (`<C/>`, `<svelte:component this={C}/>`) emits the shell; the island's JS is
42
+ * fetched only when the shell wakes (e.g. `wake: 'visible'` → on scroll-into-view). Shared by the
43
+ * `.svelte` host and the `.ts` registry. `entry_url` is the resolved client/dev module URL the caller
44
+ * computes (ctx-dependent). Plain JavaScript, whatever the host's lang: every host that marks the
45
+ * component this way shares this one module (test/region-identity-canonical.test.ts).
46
+ */
47
+ function island_wrapper_source(iid, componentPath, entryPath, strategy, options, exportName, entry_url) {
48
+ return region_wrapper(`\timport __OgygiaEntry from ${JSON.stringify(entryPath)};
49
+ \t${component_import_line("__OgygiaCss", componentPath, exportName)}`, [
50
+ ["mode", "\"island\""],
51
+ ...island_wake_fields(strategy, options),
52
+ ["entry", JSON.stringify(entry_url)],
53
+ ["component", "__OgygiaEntry"],
54
+ ["css", "__OgygiaCss"]
55
+ ], "let { children, ...__props } = $props();", "{__props} {children} />");
56
+ }
57
+ function region_wrapper(imports, bag, instance, tail) {
58
+ const fields = bag.map(([k, v]) => `${k}: ${v}`).join(", ");
59
+ return `<script module>
60
+ \timport { Region as OgygiaRegion__Wrapper } from 'ogygia/internal';
61
+ ${imports ? `${imports}\n` : ""}\tconst __og = { ${fields} };
62
+ <\/script>
63
+ <script>
64
+ \t${instance}
65
+ <\/script>
66
+ <OgygiaRegion__Wrapper {__og} ${tail}
67
+ `;
68
+ }
69
+ function island_wake_fields(strategy, options) {
70
+ const fields = [["wake", JSON.stringify(strategy || "load")]];
71
+ if (strategy === "visible" && options?.margin != null) fields.push(["wakeMargin", JSON.stringify(options.margin)]);
72
+ if (options?.keep) fields.push(["keep", JSON.stringify(options.keep)]);
73
+ return fields;
74
+ }
75
+ /**
76
+ * The island wrapper's CLIENT leg (a csr=true-capable host imports it; Kit hydrates the island
77
+ * inline as a normal component). The SSR wrapper imports the component statically — it must
78
+ * render. The client wrapper must NOT: Kit links a route's `node.stylesheets` and preloads from the
79
+ * page's STATIC client graph, so a registry of N marked blocks imported by a csr=true route linked
80
+ * every block's CSS + chunk on every page (a newsroom page: 172 stylesheets for 4 islands). The
81
+ * component therefore comes through `lazy_entry_source` — a top-level-await module that imports
82
+ * the real entry only for the islands this document RENDERED (the SSR stamped a
83
+ * `<meta name="ogygia-kit-island">` per rendered island), so Kit still hydrates them in place with
84
+ * the component in hand, and a block nobody rendered costs nothing. Mounted fresh on a Kit
85
+ * client-side navigation (no SSR, no stamp), the wrapper loads the entry on demand and renders once
86
+ * it lands — a client render, so no hydration to mismatch.
87
+ */
88
+ function island_wrapper_client_source(iid, lazyPath, strategy, options, entry_url) {
89
+ return region_wrapper(`\timport __OgygiaEntry, { load as __OgygiaLoad } from ${JSON.stringify(lazyPath)};`, [
90
+ ["mode", "\"island\""],
91
+ ...island_wake_fields(strategy, options),
92
+ ["entry", JSON.stringify(entry_url)],
93
+ ["component", "__OgygiaEntry"],
94
+ ["load", "__OgygiaLoad"]
95
+ ], "let { children, ...__props } = $props();", "{__props} {children} />");
96
+ }
97
+ /**
98
+ * The client wrapper's component source (`lazyEntryVirtualId`). Decides ONCE, at module
99
+ * evaluation — before Kit hydrates, because Kit awaits the page node's import and a top-level
100
+ * await holds it. The two facts it reads are the document's own: `documentIsCsrTrue()` (the ONE
101
+ * csr fact Region reads on both legs) and the `<meta name="ogygia-kit-island">` stamp Region
102
+ * emits per rendered inline island (context.ts `claim_kit_island`).
103
+ * - not a Kit-hydrated document (the runtime woke this island's parent; no stamp exists there):
104
+ * import the entry now — a nested island must be in hand when its parent hydrates;
105
+ * - a Kit document that rendered this island: import the entry now, Kit hydrates it in place;
106
+ * - a Kit document that did NOT render it (an unrendered registry block): `undefined`, nothing
107
+ * fetched, nothing linked — `load()` is the on-demand path a client-side navigation takes.
108
+ * `entry_url` is the same string Region bakes into the stamp (`__entry`), on both legs.
109
+ */
110
+ function lazy_entry_source(entryPath, entry_url) {
111
+ const entry = JSON.stringify(entryPath);
112
+ return `import { documentIsCsrTrue } from 'ogygia/internal';
113
+ const rendered = typeof document !== 'undefined' && !!document.querySelector(${JSON.stringify(`meta[name="ogygia-kit-island"][content=${JSON.stringify(entry_url)}]`)});
114
+ export default documentIsCsrTrue() && !rendered ? undefined : (await import(${entry})).default;
115
+ export const load = () => import(${entry}).then((m) => m.default);
116
+ `;
117
+ }
118
+ /**
119
+ * Build the held-region descriptor shared by the `.svelte` and `.ts` paths. It ALWAYS carries a
120
+ * client chunk + `__module` (the region MIGHT be woken); when used statically the chunk is simply
121
+ * never fetched (HTML only at runtime). Two marker flavors feed it:
122
+ * - `wake: 'x'` → bakes `__hydrate: 'x'` — `region(C, props)` wakes on that schedule.
123
+ * - `region: 'raw'` → bakes NO schedule — `region(C, props, { wake })` sets it at the call.
124
+ * `region()` reads `opts.wake ?? binding.__hydrate`, so a baked schedule is the default and the call
125
+ * can override. `kind` is always `'hydrate'` so the chunk is emitted; `server:true` — the endpoint
126
+ * renders the HTML either way.
127
+ */
128
+ function make_region_binding(opts) {
129
+ const meta = `__ogRegion: ${JSON.stringify(opts.iid)}, __module: ${JSON.stringify(opts.moduleUrl)}${opts.hydrate ? `, __hydrate: ${JSON.stringify(opts.hydrate)}` : ""}${opts.hydrate && opts.hydrateMargin != null ? `, __hydrateMargin: ${JSON.stringify(opts.hydrateMargin)}` : ""}`;
130
+ const ssr_source = `${component_import_line("__ogRegionComp", opts.componentPath, opts.exportName)}
131
+ import { make_region_endpoint as __ogRegionSign, render_region_html as __ogRegionHtml } from 'ogygia/internal/server';
132
+ export default { ${meta}, __component: __ogRegionComp, __sign: __ogRegionSign, __renderHtml: ${render_html_source(opts.moduleUrl)} };
133
+ `;
134
+ return {
135
+ id: opts.iid,
136
+ virtualPath: opts.entryPath,
137
+ source: region_entry_source(opts.componentPath, opts.iid, opts.exportName),
138
+ bindingPath: regionBindingVirtualId(opts.iid),
139
+ bindingSsrSource: ssr_source,
140
+ bindingClientSource: `export default { ${meta} };\n`,
141
+ hostPath: opts.hostPath,
142
+ componentPath: opts.componentPath,
143
+ server: true,
144
+ kind: "hydrate",
145
+ held: true,
146
+ lakes: [],
147
+ identity: opts.identity
148
+ };
149
+ }
150
+ function wrapper_attach_binding(opts) {
151
+ const meta = `__ogRegion: ${JSON.stringify(opts.iid)}, __module: ${JSON.stringify(opts.moduleUrl)}${opts.hydrate ? `, __hydrate: ${JSON.stringify(opts.hydrate)}` : ""}${opts.hydrate && opts.hydrateMargin != null ? `, __hydrateMargin: ${JSON.stringify(opts.hydrateMargin)}` : ""}`;
152
+ return {
153
+ ssr: `import __OgygiaWrap from ${JSON.stringify(opts.wrapperPath)};
154
+ ${component_import_line("__ogRegionComp", opts.componentPath, opts.exportName)}
155
+ import { make_region_endpoint as __ogRegionSign, render_region_html as __ogRegionHtml } from 'ogygia/internal/server';
156
+ Object.assign(__OgygiaWrap, { ${meta}, __component: __ogRegionComp, __sign: __ogRegionSign, __renderHtml: ${render_html_source(opts.moduleUrl)} });
157
+ export default __OgygiaWrap;
158
+ `,
159
+ client: `import __OgygiaWrap from ${JSON.stringify(opts.wrapperPath)};
160
+ Object.assign(__OgygiaWrap, { ${meta} });
161
+ export default __OgygiaWrap;
162
+ `
163
+ };
164
+ }
165
+ /**
166
+ * The complete island record for a `wake:` mark — the ONE emitter shared by the `.svelte` host (a
167
+ * placed `import X with { wake }`) and the `.ts` registry (a `wake:` mark handed to a renderer). The
168
+ * binding it produces is BOTH mountable (placing it, incl. via `<svelte:component>`, renders the
169
+ * `<ogygia-region>` shell that fetches the island JS only on its schedule) AND holdable (the descriptor
170
+ * fields ride on the wrapper, so `region(C)` still works). Threading both paths through here is what
171
+ * keeps `.svelte` and `.ts` `wake:` byte-identical — a `.ts` `wake: 'visible'` is exactly a `.svelte`
172
+ * `wake: 'visible'`. Callers own the host-specific import rewrite; this owns the record.
173
+ * `moduleUrl` is the resolved client/dev module URL.
174
+ */
175
+ function make_wake_island(opts) {
176
+ const margin = opts.strategy === "visible" ? opts.options?.margin : void 0;
177
+ const attach = wrapper_attach_binding({
178
+ iid: opts.iid,
179
+ wrapperPath: opts.wrapperPath,
180
+ componentPath: opts.componentPath,
181
+ moduleUrl: opts.moduleUrl,
182
+ hydrate: opts.strategy,
183
+ hydrateMargin: margin,
184
+ exportName: opts.exportName
185
+ });
186
+ const lazyPath = lazyEntryVirtualId(opts.iid);
187
+ return {
188
+ id: opts.iid,
189
+ virtualPath: opts.entryPath,
190
+ wrapperPath: opts.wrapperPath,
191
+ wrapperSource: island_wrapper_source(opts.iid, opts.componentPath, opts.entryPath, opts.strategy, opts.options, opts.exportName, opts.moduleUrl),
192
+ wrapperClientSource: island_wrapper_client_source(opts.iid, lazyPath, opts.strategy, opts.options, opts.moduleUrl),
193
+ lazyPath,
194
+ lazySource: lazy_entry_source(opts.entryPath, opts.moduleUrl),
195
+ bindingPath: regionBindingVirtualId(opts.iid),
196
+ bindingSsrSource: attach.ssr,
197
+ bindingClientSource: attach.client,
198
+ source: island_entry_source(opts.componentPath, opts.iid, opts.exportName),
199
+ hostPath: opts.hostPath,
200
+ componentPath: opts.componentPath,
201
+ server: !!opts.held,
202
+ ...opts.held ? { held: true } : {},
203
+ kind: "hydrate",
204
+ lakes: [],
205
+ identity: opts.identity,
206
+ strategy: opts.strategy,
207
+ keep: opts.options?.keep
208
+ };
209
+ }
210
+ /**
211
+ * The SERVER-island wrapper (`.svelte`) — `render: 'deferred'`: a hole whose HTML is fetched on the
212
+ * `wake` schedule. `__defer` carries the fetch schedule; `__cacheTtl` (when signed) sets the hole's
213
+ * response cache; a deferred island that ALSO hydrates carries `__hydrate` + `__module` (its client
214
+ * entry URL). `module_url` is the resolved client/dev entry URL (used only when it hydrates).
215
+ * @param component false for the client leg, which imports no component: a hole ships no JS.
216
+ */
217
+ function server_wrapper_source(iid, componentPath, entryPath, options, exportName, module_url, component = true) {
218
+ const bag = [["mode", "\"server\""], ["entry", JSON.stringify(iid)]];
219
+ if (component) bag.push(["component", "__OgygiaEntry"], ["css", "__OgygiaCss"]);
220
+ bag.push(["when", JSON.stringify(options?.when || "load")]);
221
+ if (options?.stitch) bag.push(["stitch", JSON.stringify(options.stitch)]);
222
+ if (options?.prefetch) bag.push(["prefetch", JSON.stringify(options.prefetch)]);
223
+ if (options?.margin != null) bag.push(["margin", JSON.stringify(options.margin)]);
224
+ if (options?.cacheTtlSec != null) bag.push(["cacheTtl", JSON.stringify(options.cacheTtlSec)]);
225
+ if (options?.hydrate) {
226
+ bag.push(["wake", JSON.stringify(options.hydrate)], ["module", JSON.stringify(module_url)]);
227
+ if (options.hydrateMargin != null) bag.push(["wakeMargin", JSON.stringify(options.hydrateMargin)]);
228
+ }
229
+ return region_wrapper(component ? `\timport __OgygiaEntry from ${JSON.stringify(entryPath)};
230
+ \t${component_import_line("__OgygiaCss", componentPath, exportName)}` : "", bag, "let { ogygiaFallback, ...__props } = $props();", "{__props} {ogygiaFallback} />");
231
+ }
232
+ /**
233
+ * The LAKE wrapper (`.svelte`) — `render: page, wake: none`: a frozen region inside a hydrated island.
234
+ * Every lake hands Region its props (`__props`): its identity (`data-og-lake`) is a fingerprint of
235
+ * them. A `swr` lake also carries an endpoint (`__when`) to remount on its schedule; `cache`/`empty`
236
+ * are wrapper-only. Static `<OgygiaLakeInner>` (not dynamic) preserves the LAKE-ENVELOPE; the client
237
+ * build swaps that import for the render-nothing stub.
238
+ */
239
+ function lake_wrapper_source(iid, componentPath, options, exportName) {
240
+ const remount = options?.remount || "cache";
241
+ const bag = [
242
+ ["mode", "\"lake\""],
243
+ ["entry", JSON.stringify(iid)],
244
+ ["remount", JSON.stringify(remount)]
245
+ ];
246
+ if (options?.maxAgeMs != null) bag.push(["maxAge", JSON.stringify(options.maxAgeMs)]);
247
+ if (options?.onExpire) bag.push(["onExpire", JSON.stringify(options.onExpire)]);
248
+ if (remount === "swr") {
249
+ bag.push(["when", JSON.stringify(options?.when || "load")]);
250
+ if (options?.margin != null) bag.push(["margin", JSON.stringify(options.margin)]);
251
+ }
252
+ return region_wrapper(`\t${component_import_line("OgygiaLakeInner", componentPath, exportName)}`, bag, "let __props = $props();", "{__props}><OgygiaLakeInner {...__props} /></OgygiaRegion__Wrapper>");
253
+ }
254
+ /** Rewrite `$app/{state,stores,navigation}` string literals to absolute shim paths. */
255
+ const APP_SHIM_IMPORT = /(['"])\$app\/(state|stores|navigation)\1/g;
256
+ const REGEXP_META = /[.*+?^${}()|[\]\\]/g;
257
+ const IMPORT_AS_CLAUSE = /^(.+?)(?:\s+as\s+(\w+))?$/;
258
+ /**
259
+ * Rewrite a lake binding's import to the render-nothing placeholder (client island modules only).
260
+ * Default imports are repointed; named imports drop that specifier (and keep siblings) then add a
261
+ * default import of the placeholder under the same local name.
262
+ *
263
+ * @internal Used by the plugin client emit and unit tests.
264
+ */
265
+ function rewrite_lake_import_to_placeholder(src, local, placeholder) {
266
+ const esc = local.replace(REGEXP_META, "\\$&");
267
+ const ph = JSON.stringify(placeholder);
268
+ src = src.replace(new RegExp(`import\\s+${esc}\\s+from\\s+(['"])[^'"]+\\1`, "g"), `import ${local} from ${ph}`);
269
+ src = src.replace(new RegExp(`import\\s*\\{([^}]*)\\}\\s*from\\s*(['"])([^'"]+)\\2`, "g"), (full, specs, _q, from) => {
270
+ const parts = String(specs).split(",").map((s) => s.trim()).filter(Boolean);
271
+ const kept = [];
272
+ let hit = false;
273
+ for (const p of parts) {
274
+ const m = p.match(IMPORT_AS_CLAUSE);
275
+ if (!m) {
276
+ kept.push(p);
277
+ continue;
278
+ }
279
+ const imported = m[1].trim();
280
+ if ((m[2] || imported).trim() === local) {
281
+ hit = true;
282
+ continue;
283
+ }
284
+ kept.push(p);
285
+ }
286
+ if (!hit) return full;
287
+ const named = kept.length ? `import { ${kept.join(", ")} } from ${JSON.stringify(from)};` : "";
288
+ return `import ${local} from ${ph};${named ? `\n\t${named}` : ""}`;
289
+ });
290
+ return src;
291
+ }
292
+ export { APP_SHIM_IMPORT, FOREIGN_HYDRATE_MARK, component_import_line, island_entry_source, island_wrapper_client_source, island_wrapper_source, lake_wrapper_source, lazy_entry_source, make_region_binding, make_wake_island, rewrite_lake_import_to_placeholder, server_wrapper_source };
@@ -0,0 +1,32 @@
1
+ import { MarkOptions } from "./ir.js";
2
+ /**
3
+ * Fingerprint of a region mark for dedupe. Same component path + same key → one wrapper/entry.
4
+ * Every option baked into the wrapper is in the key (a cache TTL, the stitch mode, the warm
5
+ * schedule, a `keep` name, a margin), so two marks that differ in one never share a wrapper. A
6
+ * held region's key starts `region:`, apart from a placed wrapper of the same schedule.
7
+ * @param mark
8
+ */
9
+ export declare function strategyKey(mark: {
10
+ strategy: string;
11
+ options?: MarkOptions | null;
12
+ }): string;
13
+ /**
14
+ * Cross-host stable identity: posix component path + {@link strategyKey}.
15
+ * Drives region ids so multiple hosts / import sites / `<A />` usages share one module.
16
+ */
17
+ export declare function regionIdentity(componentRelPath: string, mark: {
18
+ strategy: string;
19
+ options?: MarkOptions | null;
20
+ }): string;
21
+ /**
22
+ * A server-rendered region's RENDER identity: what the islands endpoint renders — the component
23
+ * alone (posix path, `#export` for a named one). A region id names a WRAPPER (the component ⊕ its
24
+ * page-side schedule ⊕ the build's salt); the endpoint's render of a component is the same under
25
+ * every schedule, so a capability that names its render identity is answered by any build that
26
+ * still serves the component as a region, whatever its schedule, its preset or the build's salt.
27
+ * Unsalted: it is never a file name (nothing to enumerate) and only rides inside a signed URL.
28
+ * @param identityOrPath a {@link regionIdentity} (its component half is taken) or a component path
29
+ */
30
+ export declare function renderId(identityOrPath: string): string;
31
+ /** Hash an identity string (optional production salt) → 12-char region id. */
32
+ export declare function regionId(identityKey: string, salt?: string): string;
@@ -0,0 +1,46 @@
1
+ import { createHash } from "node:crypto";
2
+ // src/region/identity.ts
3
+ const PATH_SEP = /[/\\]/;
4
+ /**
5
+ * Fingerprint of a region mark for dedupe. Same component path + same key → one wrapper/entry.
6
+ * Every option baked into the wrapper is in the key (a cache TTL, the stitch mode, the warm
7
+ * schedule, a `keep` name, a margin), so two marks that differ in one never share a wrapper. A
8
+ * held region's key starts `region:`, apart from a placed wrapper of the same schedule.
9
+ * @param mark
10
+ */
11
+ function strategyKey(mark) {
12
+ const o = mark.options || {};
13
+ const margin = o.margin != null ? `:margin:${o.margin}` : "";
14
+ const hmargin = o.hydrateMargin != null ? `:hmargin:${o.hydrateMargin}` : "";
15
+ if (mark.strategy === "server") return `defer:${o.when ?? "load"}${margin}${o.cacheTtlSec != null ? `:ttl:${o.cacheTtlSec}` : ""}${o.stitch ? `:stitch:${o.stitch}` : ""}${o.prefetch ? `:prefetch:${o.prefetch}` : ""}${o.hydrate ? `+hydrate:${o.hydrate}${hmargin}` : ""}`;
16
+ if (mark.strategy === "lake") return `lake:${o.remount || "cache"}${o.when ? `:when:${o.when}` : ""}${o.maxAgeMs != null ? `:maxAge:${o.maxAgeMs}` : ""}${o.onExpire ? `:onExpire:${o.onExpire}` : ""}${margin}`;
17
+ if (mark.strategy === "held") return `region:${o.hydrate || "raw"}${hmargin}`;
18
+ return `hydrate:${mark.strategy}${margin}${o.keep != null ? `:keep:${o.keep}` : ""}`;
19
+ }
20
+ /**
21
+ * Cross-host stable identity: posix component path + {@link strategyKey}.
22
+ * Drives region ids so multiple hosts / import sites / `<A />` usages share one module.
23
+ */
24
+ function regionIdentity(componentRelPath, mark) {
25
+ return `${String(componentRelPath).split(PATH_SEP).join("/")}\0${strategyKey(mark)}`;
26
+ }
27
+ /**
28
+ * A server-rendered region's RENDER identity: what the islands endpoint renders — the component
29
+ * alone (posix path, `#export` for a named one). A region id names a WRAPPER (the component ⊕ its
30
+ * page-side schedule ⊕ the build's salt); the endpoint's render of a component is the same under
31
+ * every schedule, so a capability that names its render identity is answered by any build that
32
+ * still serves the component as a region, whatever its schedule, its preset or the build's salt.
33
+ * Unsalted: it is never a file name (nothing to enumerate) and only rides inside a signed URL.
34
+ * @param identityOrPath a {@link regionIdentity} (its component half is taken) or a component path
35
+ */
36
+ function renderId(identityOrPath) {
37
+ const nul = identityOrPath.indexOf("\0");
38
+ const component = (nul === -1 ? identityOrPath : identityOrPath.slice(0, nul)).split(PATH_SEP).join("/");
39
+ return createHash("md5").update(`render\0${component}`).digest("hex").slice(0, 12);
40
+ }
41
+ /** Hash an identity string (optional production salt) → 12-char region id. */
42
+ function regionId(identityKey, salt = "") {
43
+ const msg = salt ? `${salt}\0${identityKey}` : identityKey;
44
+ return createHash("md5").update(msg).digest("hex").slice(0, 12);
45
+ }
46
+ export { regionId, regionIdentity, renderId, strategyKey };
@@ -0,0 +1,56 @@
1
+ import { ImportKeys } from "./transform.js";
2
+ import { AstNode } from "../parse/oxc.js";
3
+ /** A Svelte / ESTree node as the front-end walks it — dynamic access, loosely typed by design. */
4
+ export type SvelteNode = AstNode;
5
+ export type MarkOptions = Record<string, string | number | undefined>;
6
+ /** A region mark — the `{ strategy, options }` a `with { … }` clause resolves to. */
7
+ export interface RegionMark {
8
+ strategy: string;
9
+ options: MarkOptions;
10
+ }
11
+ /** One host import the analyze pass indexed: its ImportDeclaration node + the `with {…}`-stripped text. */
12
+ export interface HostImport {
13
+ /** the ImportDeclaration, with its offsets */
14
+ node: SvelteNode & {
15
+ start: number;
16
+ end: number;
17
+ };
18
+ cleaned: string;
19
+ }
20
+ /**
21
+ * `FileIR` — analyze's output, lower's input. Everything the lowering pass reads about one file,
22
+ * bundled as plain data. Cross-file knowledge never enters here: a file's IR knows only its own
23
+ * source, never what another file did (the join is by content-hashed region id, in the Program).
24
+ */
25
+ export interface FileIR {
26
+ source: string;
27
+ id: string;
28
+ /** the parsed Svelte AST (root `.fragment` / `.instance` / `.module`). */
29
+ ast: SvelteNode;
30
+ /** `<script>` (instance) top-level statements. */
31
+ instance_body: SvelteNode[];
32
+ /** `<script module>` top-level statements. */
33
+ module_body: SvelteNode[];
34
+ /** the `<script>` lang attribute (`''` for plain JS) — of the host's own synthesized script and
35
+ * its portable snippets (authored markup); never of a shared wrapper. */
36
+ lang: string;
37
+ /** posix root-relative host path — the stable prefix of error messages + snippet identities. */
38
+ rel_host: string;
39
+ /** the resolved import-attribute key names for this build. */
40
+ import_keys: ImportKeys;
41
+ /** localName → { node, cleaned } for every host import. */
42
+ imports: Map<string, HostImport>;
43
+ /** localName → the region mark its `with {…}` import carries. */
44
+ marked_components: Map<string, RegionMark>;
45
+ /** ImportDeclaration nodes to remove from the host (marked imports the file never uses). */
46
+ imports_to_strip: Set<{
47
+ start: number;
48
+ end: number;
49
+ }>;
50
+ /** marked localName → the export it reads (`'default'`, or a named export's name). */
51
+ export_names: Map<string, string>;
52
+ /** a hydrate island with real host children was placed (the app needs the wire slot revivers). */
53
+ has_island_children: boolean;
54
+ /** the cheap island-hint gate result (a marker-less snippet-only file is not "hinted"). */
55
+ has_island_hint: boolean;
56
+ }
File without changes
@@ -0,0 +1,27 @@
1
+ import { SvelteNode } from "./ir.js";
2
+ /** One name a marked import binds: its local name and the export it reads (`'default'` or a name). */
3
+ export interface MarkedBinding {
4
+ local: string;
5
+ exportName: string;
6
+ }
7
+ /**
8
+ * The names a marked import declaration binds, each with the export it reads. Throws the coded error
9
+ * for a shape that binds no component: a type-only import (or a `type` specifier), a namespace, or
10
+ * nothing at all.
11
+ */
12
+ export declare function marked_import_bindings(node: SvelteNode, source: string, host: string): MarkedBinding[];
13
+ /**
14
+ * `import.meta.og.asRegion(…)` is gone. Any call anywhere in `roots` throws `as_region_removed`,
15
+ * listing for each call the marked import that replaces it (same options, aliased to the `const`).
16
+ */
17
+ export declare function refuse_as_region(roots: unknown[], source: string, host: string): void;
18
+ /**
19
+ * A marked binding is a component: placed as `<Name />`, or handed on as a value (`region(Name)`, a
20
+ * prop, a registry entry, an export). Any other use (a call, a member read, a spread, `typeof`, text,
21
+ * a store subscription, an action…) throws `region_binding_not_component` at the first one, naming
22
+ * its line and the plain import line to split it onto. `marked` maps each local to its import.
23
+ */
24
+ export declare function check_marked_uses(roots: unknown[], marked: ReadonlyMap<string, {
25
+ node: SvelteNode;
26
+ exportName: string;
27
+ }>, source: string, host: string): void;