@pithyjs/ssr 0.0.0-stage → 0.1.2-beta.9
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/LICENSE +21 -0
- package/README.md +100 -2
- package/bin/pithy-ssg.mjs +23 -0
- package/dist/browser.d.ts +38 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +40 -0
- package/dist/browser.js.map +1 -0
- package/dist/build/cli-args.d.ts +104 -0
- package/dist/build/cli-args.d.ts.map +1 -0
- package/dist/build/cli-args.js +88 -0
- package/dist/build/cli-args.js.map +1 -0
- package/dist/build/cli-exit.d.ts +95 -0
- package/dist/build/cli-exit.d.ts.map +1 -0
- package/dist/build/cli-exit.js +237 -0
- package/dist/build/cli-exit.js.map +1 -0
- package/dist/build/cli.d.ts +11 -0
- package/dist/build/cli.d.ts.map +1 -0
- package/dist/build/cli.js +93 -0
- package/dist/build/cli.js.map +1 -0
- package/dist/build/collect-css.d.ts +168 -0
- package/dist/build/collect-css.d.ts.map +1 -0
- package/dist/build/collect-css.js +479 -0
- package/dist/build/collect-css.js.map +1 -0
- package/dist/build/css-live-props.d.ts +89 -0
- package/dist/build/css-live-props.d.ts.map +1 -0
- package/dist/build/css-live-props.js +704 -0
- package/dist/build/css-live-props.js.map +1 -0
- package/dist/build/css-purge.d.ts +153 -0
- package/dist/build/css-purge.d.ts.map +1 -0
- package/dist/build/css-purge.js +463 -0
- package/dist/build/css-purge.js.map +1 -0
- package/dist/build/index.d.ts +24 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +31 -0
- package/dist/build/index.js.map +1 -0
- package/dist/build/not-found.d.ts +94 -0
- package/dist/build/not-found.d.ts.map +1 -0
- package/dist/build/not-found.js +99 -0
- package/dist/build/not-found.js.map +1 -0
- package/dist/build/relative-links.d.ts +31 -0
- package/dist/build/relative-links.d.ts.map +1 -0
- package/dist/build/relative-links.js +79 -0
- package/dist/build/relative-links.js.map +1 -0
- package/dist/build/shell-head.d.ts +68 -0
- package/dist/build/shell-head.d.ts.map +1 -0
- package/dist/build/shell-head.js +236 -0
- package/dist/build/shell-head.js.map +1 -0
- package/dist/build/sprite-ssg.d.ts +61 -0
- package/dist/build/sprite-ssg.d.ts.map +1 -0
- package/dist/build/sprite-ssg.js +114 -0
- package/dist/build/sprite-ssg.js.map +1 -0
- package/dist/build/ssg.d.ts +117 -0
- package/dist/build/ssg.d.ts.map +1 -0
- package/dist/build/ssg.js +404 -0
- package/dist/build/ssg.js.map +1 -0
- package/dist/build/vite-ssg.d.ts +396 -0
- package/dist/build/vite-ssg.d.ts.map +1 -0
- package/dist/build/vite-ssg.js +1130 -0
- package/dist/build/vite-ssg.js.map +1 -0
- package/dist/client/bootstrap.d.ts +51 -0
- package/dist/client/bootstrap.d.ts.map +1 -0
- package/dist/client/bootstrap.js +121 -0
- package/dist/client/bootstrap.js.map +1 -0
- package/dist/client/hydrate.d.ts +60 -0
- package/dist/client/hydrate.d.ts.map +1 -0
- package/dist/client/hydrate.js +168 -0
- package/dist/client/hydrate.js.map +1 -0
- package/dist/client/index.d.ts +21 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +16 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/server/app.d.ts +166 -0
- package/dist/server/app.d.ts.map +1 -0
- package/dist/server/app.js +200 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/context.d.ts +238 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +371 -0
- package/dist/server/context.js.map +1 -0
- package/dist/server/environment.d.ts +88 -0
- package/dist/server/environment.d.ts.map +1 -0
- package/dist/server/environment.js +261 -0
- package/dist/server/environment.js.map +1 -0
- package/dist/server/html-shell.d.ts +41 -0
- package/dist/server/html-shell.d.ts.map +1 -0
- package/dist/server/html-shell.js +208 -0
- package/dist/server/html-shell.js.map +1 -0
- package/dist/server/index.d.ts +26 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +37 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/layout-taint.d.ts +62 -0
- package/dist/server/layout-taint.d.ts.map +1 -0
- package/dist/server/layout-taint.js +313 -0
- package/dist/server/layout-taint.js.map +1 -0
- package/dist/server/loaders.d.ts +194 -0
- package/dist/server/loaders.d.ts.map +1 -0
- package/dist/server/loaders.js +479 -0
- package/dist/server/loaders.js.map +1 -0
- package/dist/server/render-route.d.ts +102 -0
- package/dist/server/render-route.d.ts.map +1 -0
- package/dist/server/render-route.js +182 -0
- package/dist/server/render-route.js.map +1 -0
- package/dist/server/render.d.ts +80 -0
- package/dist/server/render.d.ts.map +1 -0
- package/dist/server/render.js +256 -0
- package/dist/server/render.js.map +1 -0
- package/dist/server/router-adapter.d.ts +134 -0
- package/dist/server/router-adapter.d.ts.map +1 -0
- package/dist/server/router-adapter.js +225 -0
- package/dist/server/router-adapter.js.map +1 -0
- package/dist/server/serialization.d.ts +54 -0
- package/dist/server/serialization.d.ts.map +1 -0
- package/dist/server/serialization.js +287 -0
- package/dist/server/serialization.js.map +1 -0
- package/dist/server/ssr-worker.d.ts +18 -0
- package/dist/server/ssr-worker.d.ts.map +1 -0
- package/dist/server/ssr-worker.js +118 -0
- package/dist/server/ssr-worker.js.map +1 -0
- package/dist/server/utils.d.ts +11 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/dist/server/utils.js +14 -0
- package/dist/server/utils.js.map +1 -0
- package/dist/server/worker-pool.d.ts +153 -0
- package/dist/server/worker-pool.d.ts.map +1 -0
- package/dist/server/worker-pool.js +451 -0
- package/dist/server/worker-pool.js.map +1 -0
- package/dist/server/worker-protocol.d.ts +61 -0
- package/dist/server/worker-protocol.d.ts.map +1 -0
- package/dist/server/worker-protocol.js +9 -0
- package/dist/server/worker-protocol.js.map +1 -0
- package/dist/shared/css-purge.d.ts +71 -0
- package/dist/shared/css-purge.d.ts.map +1 -0
- package/dist/shared/css-purge.js +177 -0
- package/dist/shared/css-purge.js.map +1 -0
- package/dist/shared/entry-path.d.ts +41 -0
- package/dist/shared/entry-path.d.ts.map +1 -0
- package/dist/shared/entry-path.js +87 -0
- package/dist/shared/entry-path.js.map +1 -0
- package/dist/shared/head.d.ts +87 -0
- package/dist/shared/head.d.ts.map +1 -0
- package/dist/shared/head.js +412 -0
- package/dist/shared/head.js.map +1 -0
- package/dist/shared/shell-helpers.d.ts +69 -0
- package/dist/shared/shell-helpers.d.ts.map +1 -0
- package/dist/shared/shell-helpers.js +160 -0
- package/dist/shared/shell-helpers.js.map +1 -0
- package/dist/shared/types.d.ts +332 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +27 -0
- package/dist/shared/types.js.map +1 -0
- package/package.json +84 -3
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @codex { "id": "pithy.ssr.build.not-found", "title": "Not-Found Document Identity", "category": "runtime", "risk": "medium" }
|
|
3
|
+
*
|
|
4
|
+
* The identity of the site-wide not-found document, in one place.
|
|
5
|
+
*
|
|
6
|
+
* Two independent SSG entry points emit a 404 — `generateStaticSite()` in
|
|
7
|
+
* `./ssg.ts` and `buildSSG()` in `./vite-ssg.ts` — and they agreed only by
|
|
8
|
+
* having the same literals typed into both. A disagreement would not fail any
|
|
9
|
+
* test: each side would emit a self-consistent 404 at a different filename, and
|
|
10
|
+
* the host would serve whichever one it looked for.
|
|
11
|
+
*
|
|
12
|
+
* Two constraints put this file HERE rather than under `shared/`:
|
|
13
|
+
*
|
|
14
|
+
* - It must have NO imports. `vite-ssg.ts` deliberately reaches the server
|
|
15
|
+
* modules through `vite.ssrLoadModule()` rather than statically, to avoid tsx
|
|
16
|
+
* resolution issues, so it cannot pick this up from `ssg.ts` without dragging
|
|
17
|
+
* that graph back in statically.
|
|
18
|
+
* - knip does not count a use made from `src/build/**`, so a `shared/` module
|
|
19
|
+
* consumed only by the pipeline is reported as an unused export and fails the
|
|
20
|
+
* quality gate while being in active use.
|
|
21
|
+
*/
|
|
22
|
+
/** @codexApi {"parent":"pithy.ssr.build.not-found","name":"NOT_FOUND_OUTPUT","stability":"experimental","signature":"{ entry: '404.html'; renderPath: '/404'; linkBase: null }"} */
|
|
23
|
+
/**
|
|
24
|
+
* How the site-wide not-found document is rendered and written.
|
|
25
|
+
*
|
|
26
|
+
* Netlify, Vercel, GitHub Pages and Cloudflare Pages serve a root `404.html`
|
|
27
|
+
* for an unmatched URL with no per-host configuration. S3 serves it too, but
|
|
28
|
+
* only once the bucket's static-website endpoint sets `ErrorDocument: 404.html`
|
|
29
|
+
* — the file is the prerequisite either way, which is why the app's top-level
|
|
30
|
+
* catch-all route is rendered into exactly that file.
|
|
31
|
+
*
|
|
32
|
+
* The three values are deliberately different from one another:
|
|
33
|
+
*
|
|
34
|
+
* - `entry` is a ROOT-level filename, not `pathToFilePath('/404')`. Nesting it
|
|
35
|
+
* as `404/index.html` would hide it from every host convention above.
|
|
36
|
+
* - `renderPath` needs at least one path segment, because the router matcher
|
|
37
|
+
* requires a catch-all to consume one or more segments (PR #166) — `/` would
|
|
38
|
+
* not resolve to the catch-all at all.
|
|
39
|
+
* - `linkBase` is `null`, which means "this document has NO fixed depth", and
|
|
40
|
+
* is not the same as `'/'`. Every other page is served at one known URL, so
|
|
41
|
+
* its `../` count is computable; the 404 is served at whatever URL the
|
|
42
|
+
* visitor mistyped, and a browser resolves relative URLs against the REQUEST
|
|
43
|
+
* rather than against the file's location on disk. Depth 0 is correct only
|
|
44
|
+
* for a request to `/nope` — `/nope/`, `/docs/whatever` and
|
|
45
|
+
* `/blog/2024/old-post` each need a different number of `../`, so no fixed
|
|
46
|
+
* value works and relativisation is disabled entirely (BUG-015).
|
|
47
|
+
*
|
|
48
|
+
* Two more things worth knowing about `renderPath`: when an app has BOTH a
|
|
49
|
+
* real static `/404` route and a top-level catch-all, the App **shell** is
|
|
50
|
+
* still rendered at `url: '/404'`, so the router matches the static route —
|
|
51
|
+
* its layout chrome and `shellResult.head` merge into a document whose body
|
|
52
|
+
* came from the catch-all. Separately, most static hosts resolve a request
|
|
53
|
+
* for `/404` to `404.html` before `404/index.html`, so the app's own `/404`
|
|
54
|
+
* page is shadowed by this generated file. No collision is reported because
|
|
55
|
+
* the two entry keys (`404.html` vs `404/index.html`) differ.
|
|
56
|
+
*/
|
|
57
|
+
export declare const NOT_FOUND_OUTPUT: {
|
|
58
|
+
readonly entry: "404.html";
|
|
59
|
+
readonly renderPath: "/404";
|
|
60
|
+
readonly linkBase: null;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Does rendered page HTML carry any text a reader would see?
|
|
64
|
+
*
|
|
65
|
+
* Used to tell a real prerendered 404 from a shell-only one. A page that
|
|
66
|
+
* portals its UI to `document.body` returns an inert placeholder, so the
|
|
67
|
+
* injected markup is something like `<div></div>` — non-empty as a string,
|
|
68
|
+
* empty as a page.
|
|
69
|
+
*
|
|
70
|
+
* `<script>` and `<style>` bodies are removed with their tags, not just their
|
|
71
|
+
* angle brackets. Stripping tags alone left the CSS and JS BETWEEN them behind
|
|
72
|
+
* and counted it as text, so a portal-style catch-all that also emitted scoped
|
|
73
|
+
* styles into the outlet passed the guard and shipped the shell-only 404 anyway.
|
|
74
|
+
*
|
|
75
|
+
* Used by `buildSSG()` alone. Studio's exporter had a copy of this and no
|
|
76
|
+
* longer does — it reads `textContent` from the band's DOM instead, because a
|
|
77
|
+
* tag-strip regex stops at the first `>`, including one inside an attribute
|
|
78
|
+
* value, and author content carries those far more often than the framework's
|
|
79
|
+
* outlet HTML does. The earlier note here about "both exporters" and a
|
|
80
|
+
* "byte-for-byte copy" outlived that change and sent readers looking for a
|
|
81
|
+
* duplicate that no longer exists.
|
|
82
|
+
*
|
|
83
|
+
* WHAT YOU PASS MATTERS. The framework passes outlet content, shell excluded. A
|
|
84
|
+
* caller that passes a whole page — navbar and footer included — is asking a
|
|
85
|
+
* different question, and gets `true` for a body whose only words are its nav
|
|
86
|
+
* labels.
|
|
87
|
+
*
|
|
88
|
+
* Text specifically, because every not-found page has words in it. An
|
|
89
|
+
* image-only page would be reported as empty and skipped, which errs toward
|
|
90
|
+
* leaving the host's 404 in place — the safe direction, and warned about.
|
|
91
|
+
*/
|
|
92
|
+
/** @codexApi {"parent":"pithy.ssr.build.not-found","name":"hasRenderedText","stability":"internal","signature":"(html: string) => boolean"} */
|
|
93
|
+
export declare function hasRenderedText(html: string): boolean;
|
|
94
|
+
//# sourceMappingURL=not-found.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-found.d.ts","sourceRoot":"","sources":["../../src/build/not-found.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,oLAAoL;AACpL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,gBAAgB;;;;CAInB,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,+IAA+I;AAC/I,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOrD"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @codex { "id": "pithy.ssr.build.not-found", "title": "Not-Found Document Identity", "category": "runtime", "risk": "medium" }
|
|
3
|
+
*
|
|
4
|
+
* The identity of the site-wide not-found document, in one place.
|
|
5
|
+
*
|
|
6
|
+
* Two independent SSG entry points emit a 404 — `generateStaticSite()` in
|
|
7
|
+
* `./ssg.ts` and `buildSSG()` in `./vite-ssg.ts` — and they agreed only by
|
|
8
|
+
* having the same literals typed into both. A disagreement would not fail any
|
|
9
|
+
* test: each side would emit a self-consistent 404 at a different filename, and
|
|
10
|
+
* the host would serve whichever one it looked for.
|
|
11
|
+
*
|
|
12
|
+
* Two constraints put this file HERE rather than under `shared/`:
|
|
13
|
+
*
|
|
14
|
+
* - It must have NO imports. `vite-ssg.ts` deliberately reaches the server
|
|
15
|
+
* modules through `vite.ssrLoadModule()` rather than statically, to avoid tsx
|
|
16
|
+
* resolution issues, so it cannot pick this up from `ssg.ts` without dragging
|
|
17
|
+
* that graph back in statically.
|
|
18
|
+
* - knip does not count a use made from `src/build/**`, so a `shared/` module
|
|
19
|
+
* consumed only by the pipeline is reported as an unused export and fails the
|
|
20
|
+
* quality gate while being in active use.
|
|
21
|
+
*/
|
|
22
|
+
/** @codexApi {"parent":"pithy.ssr.build.not-found","name":"NOT_FOUND_OUTPUT","stability":"experimental","signature":"{ entry: '404.html'; renderPath: '/404'; linkBase: null }"} */
|
|
23
|
+
/**
|
|
24
|
+
* How the site-wide not-found document is rendered and written.
|
|
25
|
+
*
|
|
26
|
+
* Netlify, Vercel, GitHub Pages and Cloudflare Pages serve a root `404.html`
|
|
27
|
+
* for an unmatched URL with no per-host configuration. S3 serves it too, but
|
|
28
|
+
* only once the bucket's static-website endpoint sets `ErrorDocument: 404.html`
|
|
29
|
+
* — the file is the prerequisite either way, which is why the app's top-level
|
|
30
|
+
* catch-all route is rendered into exactly that file.
|
|
31
|
+
*
|
|
32
|
+
* The three values are deliberately different from one another:
|
|
33
|
+
*
|
|
34
|
+
* - `entry` is a ROOT-level filename, not `pathToFilePath('/404')`. Nesting it
|
|
35
|
+
* as `404/index.html` would hide it from every host convention above.
|
|
36
|
+
* - `renderPath` needs at least one path segment, because the router matcher
|
|
37
|
+
* requires a catch-all to consume one or more segments (PR #166) — `/` would
|
|
38
|
+
* not resolve to the catch-all at all.
|
|
39
|
+
* - `linkBase` is `null`, which means "this document has NO fixed depth", and
|
|
40
|
+
* is not the same as `'/'`. Every other page is served at one known URL, so
|
|
41
|
+
* its `../` count is computable; the 404 is served at whatever URL the
|
|
42
|
+
* visitor mistyped, and a browser resolves relative URLs against the REQUEST
|
|
43
|
+
* rather than against the file's location on disk. Depth 0 is correct only
|
|
44
|
+
* for a request to `/nope` — `/nope/`, `/docs/whatever` and
|
|
45
|
+
* `/blog/2024/old-post` each need a different number of `../`, so no fixed
|
|
46
|
+
* value works and relativisation is disabled entirely (BUG-015).
|
|
47
|
+
*
|
|
48
|
+
* Two more things worth knowing about `renderPath`: when an app has BOTH a
|
|
49
|
+
* real static `/404` route and a top-level catch-all, the App **shell** is
|
|
50
|
+
* still rendered at `url: '/404'`, so the router matches the static route —
|
|
51
|
+
* its layout chrome and `shellResult.head` merge into a document whose body
|
|
52
|
+
* came from the catch-all. Separately, most static hosts resolve a request
|
|
53
|
+
* for `/404` to `404.html` before `404/index.html`, so the app's own `/404`
|
|
54
|
+
* page is shadowed by this generated file. No collision is reported because
|
|
55
|
+
* the two entry keys (`404.html` vs `404/index.html`) differ.
|
|
56
|
+
*/
|
|
57
|
+
export const NOT_FOUND_OUTPUT = {
|
|
58
|
+
entry: '404.html',
|
|
59
|
+
renderPath: '/404',
|
|
60
|
+
linkBase: null,
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Does rendered page HTML carry any text a reader would see?
|
|
64
|
+
*
|
|
65
|
+
* Used to tell a real prerendered 404 from a shell-only one. A page that
|
|
66
|
+
* portals its UI to `document.body` returns an inert placeholder, so the
|
|
67
|
+
* injected markup is something like `<div></div>` — non-empty as a string,
|
|
68
|
+
* empty as a page.
|
|
69
|
+
*
|
|
70
|
+
* `<script>` and `<style>` bodies are removed with their tags, not just their
|
|
71
|
+
* angle brackets. Stripping tags alone left the CSS and JS BETWEEN them behind
|
|
72
|
+
* and counted it as text, so a portal-style catch-all that also emitted scoped
|
|
73
|
+
* styles into the outlet passed the guard and shipped the shell-only 404 anyway.
|
|
74
|
+
*
|
|
75
|
+
* Used by `buildSSG()` alone. Studio's exporter had a copy of this and no
|
|
76
|
+
* longer does — it reads `textContent` from the band's DOM instead, because a
|
|
77
|
+
* tag-strip regex stops at the first `>`, including one inside an attribute
|
|
78
|
+
* value, and author content carries those far more often than the framework's
|
|
79
|
+
* outlet HTML does. The earlier note here about "both exporters" and a
|
|
80
|
+
* "byte-for-byte copy" outlived that change and sent readers looking for a
|
|
81
|
+
* duplicate that no longer exists.
|
|
82
|
+
*
|
|
83
|
+
* WHAT YOU PASS MATTERS. The framework passes outlet content, shell excluded. A
|
|
84
|
+
* caller that passes a whole page — navbar and footer included — is asking a
|
|
85
|
+
* different question, and gets `true` for a body whose only words are its nav
|
|
86
|
+
* labels.
|
|
87
|
+
*
|
|
88
|
+
* Text specifically, because every not-found page has words in it. An
|
|
89
|
+
* image-only page would be reported as empty and skipped, which errs toward
|
|
90
|
+
* leaving the host's 404 in place — the safe direction, and warned about.
|
|
91
|
+
*/
|
|
92
|
+
/** @codexApi {"parent":"pithy.ssr.build.not-found","name":"hasRenderedText","stability":"internal","signature":"(html: string) => boolean"} */
|
|
93
|
+
export function hasRenderedText(html) {
|
|
94
|
+
return (html
|
|
95
|
+
.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, '')
|
|
96
|
+
.replace(/<[^>]*>/g, '')
|
|
97
|
+
.trim() !== '');
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=not-found.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"not-found.js","sourceRoot":"","sources":["../../src/build/not-found.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,oLAAoL;AACpL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,KAAK,EAAE,UAAU;IACjB,UAAU,EAAE,MAAM;IAClB,QAAQ,EAAE,IAAI;CACN,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,+IAA+I;AAC/I,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,CACL,IAAI;SACD,OAAO,CAAC,4CAA4C,EAAE,EAAE,CAAC;SACzD,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,IAAI,EAAE,KAAK,EAAE,CACjB,CAAC;AACJ,CAAC","sourcesContent":["/**\n * @codex { \"id\": \"pithy.ssr.build.not-found\", \"title\": \"Not-Found Document Identity\", \"category\": \"runtime\", \"risk\": \"medium\" }\n *\n * The identity of the site-wide not-found document, in one place.\n *\n * Two independent SSG entry points emit a 404 — `generateStaticSite()` in\n * `./ssg.ts` and `buildSSG()` in `./vite-ssg.ts` — and they agreed only by\n * having the same literals typed into both. A disagreement would not fail any\n * test: each side would emit a self-consistent 404 at a different filename, and\n * the host would serve whichever one it looked for.\n *\n * Two constraints put this file HERE rather than under `shared/`:\n *\n * - It must have NO imports. `vite-ssg.ts` deliberately reaches the server\n * modules through `vite.ssrLoadModule()` rather than statically, to avoid tsx\n * resolution issues, so it cannot pick this up from `ssg.ts` without dragging\n * that graph back in statically.\n * - knip does not count a use made from `src/build/**`, so a `shared/` module\n * consumed only by the pipeline is reported as an unused export and fails the\n * quality gate while being in active use.\n */\n\n/** @codexApi {\"parent\":\"pithy.ssr.build.not-found\",\"name\":\"NOT_FOUND_OUTPUT\",\"stability\":\"experimental\",\"signature\":\"{ entry: '404.html'; renderPath: '/404'; linkBase: null }\"} */\n/**\n * How the site-wide not-found document is rendered and written.\n *\n * Netlify, Vercel, GitHub Pages and Cloudflare Pages serve a root `404.html`\n * for an unmatched URL with no per-host configuration. S3 serves it too, but\n * only once the bucket's static-website endpoint sets `ErrorDocument: 404.html`\n * — the file is the prerequisite either way, which is why the app's top-level\n * catch-all route is rendered into exactly that file.\n *\n * The three values are deliberately different from one another:\n *\n * - `entry` is a ROOT-level filename, not `pathToFilePath('/404')`. Nesting it\n * as `404/index.html` would hide it from every host convention above.\n * - `renderPath` needs at least one path segment, because the router matcher\n * requires a catch-all to consume one or more segments (PR #166) — `/` would\n * not resolve to the catch-all at all.\n * - `linkBase` is `null`, which means \"this document has NO fixed depth\", and\n * is not the same as `'/'`. Every other page is served at one known URL, so\n * its `../` count is computable; the 404 is served at whatever URL the\n * visitor mistyped, and a browser resolves relative URLs against the REQUEST\n * rather than against the file's location on disk. Depth 0 is correct only\n * for a request to `/nope` — `/nope/`, `/docs/whatever` and\n * `/blog/2024/old-post` each need a different number of `../`, so no fixed\n * value works and relativisation is disabled entirely (BUG-015).\n *\n * Two more things worth knowing about `renderPath`: when an app has BOTH a\n * real static `/404` route and a top-level catch-all, the App **shell** is\n * still rendered at `url: '/404'`, so the router matches the static route —\n * its layout chrome and `shellResult.head` merge into a document whose body\n * came from the catch-all. Separately, most static hosts resolve a request\n * for `/404` to `404.html` before `404/index.html`, so the app's own `/404`\n * page is shadowed by this generated file. No collision is reported because\n * the two entry keys (`404.html` vs `404/index.html`) differ.\n */\nexport const NOT_FOUND_OUTPUT = {\n entry: '404.html',\n renderPath: '/404',\n linkBase: null,\n} as const;\n\n/**\n * Does rendered page HTML carry any text a reader would see?\n *\n * Used to tell a real prerendered 404 from a shell-only one. A page that\n * portals its UI to `document.body` returns an inert placeholder, so the\n * injected markup is something like `<div></div>` — non-empty as a string,\n * empty as a page.\n *\n * `<script>` and `<style>` bodies are removed with their tags, not just their\n * angle brackets. Stripping tags alone left the CSS and JS BETWEEN them behind\n * and counted it as text, so a portal-style catch-all that also emitted scoped\n * styles into the outlet passed the guard and shipped the shell-only 404 anyway.\n *\n * Used by `buildSSG()` alone. Studio's exporter had a copy of this and no\n * longer does — it reads `textContent` from the band's DOM instead, because a\n * tag-strip regex stops at the first `>`, including one inside an attribute\n * value, and author content carries those far more often than the framework's\n * outlet HTML does. The earlier note here about \"both exporters\" and a\n * \"byte-for-byte copy\" outlived that change and sent readers looking for a\n * duplicate that no longer exists.\n *\n * WHAT YOU PASS MATTERS. The framework passes outlet content, shell excluded. A\n * caller that passes a whole page — navbar and footer included — is asking a\n * different question, and gets `true` for a body whose only words are its nav\n * labels.\n *\n * Text specifically, because every not-found page has words in it. An\n * image-only page would be reported as empty and skipped, which errs toward\n * leaving the host's 404 in place — the safe direction, and warned about.\n */\n/** @codexApi {\"parent\":\"pithy.ssr.build.not-found\",\"name\":\"hasRenderedText\",\"stability\":\"internal\",\"signature\":\"(html: string) => boolean\"} */\nexport function hasRenderedText(html: string): boolean {\n return (\n html\n .replace(/<(script|style)\\b[^>]*>[\\s\\S]*?<\\/\\1\\s*>/gi, '')\n .replace(/<[^>]*>/g, '')\n .trim() !== ''\n );\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** @codex { "id": "pithy.ssr.build.relative-links", "title": "SSG Relative Link Rewriter", "category": "runtime" } */
|
|
2
|
+
/**
|
|
3
|
+
* Convert absolute links in HTML to relative paths.
|
|
4
|
+
*
|
|
5
|
+
* Makes SSG output portable — works from file:// (double-click) and
|
|
6
|
+
* any static hosting root without requiring server-side URL rewriting.
|
|
7
|
+
*
|
|
8
|
+
* From /ui-kit/for/index.html:
|
|
9
|
+
* href="/about" → href="../../about/index.html"
|
|
10
|
+
* src="/assets/client.js" → src="../../assets/client.js"
|
|
11
|
+
* href="/assets/style.css" → href="../../assets/style.css"
|
|
12
|
+
*/
|
|
13
|
+
export interface MakeLinksRelativeOptions {
|
|
14
|
+
/**
|
|
15
|
+
* When true, only rewrite asset URLs (with file extensions like .css, .js)
|
|
16
|
+
* and leave route-like URLs (/about, /dashboard) absolute.
|
|
17
|
+
* Use this in hydrate mode where the client router needs absolute paths.
|
|
18
|
+
*/
|
|
19
|
+
assetsOnly?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Convert all absolute href="/..." and src="/..." to relative paths.
|
|
23
|
+
*
|
|
24
|
+
* @param html - Full HTML string
|
|
25
|
+
* @param currentPath - The route path this HTML was rendered for (e.g., '/ui-kit/for')
|
|
26
|
+
* @param options - Options for link rewriting
|
|
27
|
+
* @returns HTML with relative links
|
|
28
|
+
*/
|
|
29
|
+
/** @codexApi {"parent":"pithy.ssr.build.relative-links","name":"makeLinksRelative","stability":"stable","signature":"(html: string, currentPath: string, options?: MakeLinksRelativeOptions) => string"} */
|
|
30
|
+
export declare function makeLinksRelative(html: string, currentPath: string, options?: MakeLinksRelativeOptions): string;
|
|
31
|
+
//# sourceMappingURL=relative-links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relative-links.d.ts","sourceRoot":"","sources":["../../src/build/relative-links.ts"],"names":[],"mappings":"AAAA,sHAAsH;AAEtH;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,4MAA4M;AAC5M,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,wBAAwB,GACjC,MAAM,CAoFR"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** @codex { "id": "pithy.ssr.build.relative-links", "title": "SSG Relative Link Rewriter", "category": "runtime" } */
|
|
2
|
+
/**
|
|
3
|
+
* Convert all absolute href="/..." and src="/..." to relative paths.
|
|
4
|
+
*
|
|
5
|
+
* @param html - Full HTML string
|
|
6
|
+
* @param currentPath - The route path this HTML was rendered for (e.g., '/ui-kit/for')
|
|
7
|
+
* @param options - Options for link rewriting
|
|
8
|
+
* @returns HTML with relative links
|
|
9
|
+
*/
|
|
10
|
+
/** @codexApi {"parent":"pithy.ssr.build.relative-links","name":"makeLinksRelative","stability":"stable","signature":"(html: string, currentPath: string, options?: MakeLinksRelativeOptions) => string"} */
|
|
11
|
+
export function makeLinksRelative(html, currentPath, options) {
|
|
12
|
+
const assetsOnly = options?.assetsOnly ?? false;
|
|
13
|
+
const depth = currentPath.split('/').filter(Boolean).length;
|
|
14
|
+
const prefix = depth > 0 ? '../'.repeat(depth) : '';
|
|
15
|
+
// Pass 1: Rewrite <base> tags separately — they define directory URLs,
|
|
16
|
+
// never append /index.html. Dedicated pass avoids fragile lookbehind.
|
|
17
|
+
// In assetsOnly mode, skip <base> rewriting entirely — the client
|
|
18
|
+
// router relies on <base href="/"> for absolute route matching.
|
|
19
|
+
let result = assetsOnly
|
|
20
|
+
? html
|
|
21
|
+
: html.replace(/(<base\s[^>]*?)href=(["'])\/([^"']*?)\2/gi, (_match, before, quote, rawPath) => {
|
|
22
|
+
// Skip protocol-relative URLs (//cdn.example.com/)
|
|
23
|
+
if (rawPath.startsWith('/'))
|
|
24
|
+
return _match;
|
|
25
|
+
const target = rawPath.replace(/\/$/, '');
|
|
26
|
+
if (!target)
|
|
27
|
+
return `${before}href=${quote}${prefix || './'}${quote}`;
|
|
28
|
+
return `${before}href=${quote}${prefix}${target}/${quote}`;
|
|
29
|
+
});
|
|
30
|
+
// Pass 2: Rewrite remaining href="/..." (supports double and single quotes)
|
|
31
|
+
// For file-like paths (with extension): always rewrite
|
|
32
|
+
// For route-like paths: append /index.html (unless assetsOnly)
|
|
33
|
+
// Preserves query strings and hash fragments
|
|
34
|
+
result = result.replace(/href=(["'])\/([^"']*?)\1/g, (_match, quote, rawPath) => {
|
|
35
|
+
// Skip protocol-relative URLs (//cdn.example.com/...)
|
|
36
|
+
if (rawPath.startsWith('/'))
|
|
37
|
+
return _match;
|
|
38
|
+
// Split off query and hash
|
|
39
|
+
const [pathPart, ...rest] = rawPath.split(/([?#])/);
|
|
40
|
+
const suffix = rest.join(''); // preserves ?query#hash
|
|
41
|
+
const target = pathPart.replace(/\/$/, '');
|
|
42
|
+
// If path has a file extension (e.g. .css, .js, .png), it's an asset — always rewrite
|
|
43
|
+
if (target && /\.\w+$/.test(target)) {
|
|
44
|
+
return `href=${quote}${prefix}${target}${suffix}${quote}`;
|
|
45
|
+
}
|
|
46
|
+
// In assetsOnly mode, skip route-like paths (no extension) so the
|
|
47
|
+
// client router can still match them by their absolute pattern
|
|
48
|
+
if (assetsOnly)
|
|
49
|
+
return _match;
|
|
50
|
+
if (!target) {
|
|
51
|
+
return `href=${quote}${prefix}index.html${suffix}${quote}`;
|
|
52
|
+
}
|
|
53
|
+
return `href=${quote}${prefix}${target}/index.html${suffix}${quote}`;
|
|
54
|
+
});
|
|
55
|
+
// Pass 3: Rewrite src="/..." (supports double and single quotes)
|
|
56
|
+
// Same asset-vs-route logic as href: only rewrite assets in assetsOnly mode
|
|
57
|
+
result = result.replace(/src=(["'])\/([^"']*?)\1/g, (_match, quote, rawPath) => {
|
|
58
|
+
if (rawPath.startsWith('/'))
|
|
59
|
+
return _match;
|
|
60
|
+
// Split off query and hash (same as href logic)
|
|
61
|
+
const [pathPart, ...rest] = rawPath.split(/([?#])/);
|
|
62
|
+
const suffix = rest.join('');
|
|
63
|
+
// If path has a file extension, it's an asset — always rewrite
|
|
64
|
+
if (pathPart && /\.\w+$/.test(pathPart)) {
|
|
65
|
+
return `src=${quote}${prefix}${pathPart}${suffix}${quote}`;
|
|
66
|
+
}
|
|
67
|
+
// In assetsOnly mode, skip route-like src (e.g. <iframe src="/about">)
|
|
68
|
+
if (assetsOnly)
|
|
69
|
+
return _match;
|
|
70
|
+
// Route-like src: append /index.html (same as href) for file:// portability
|
|
71
|
+
const target = pathPart.replace(/\/$/, '');
|
|
72
|
+
if (!target) {
|
|
73
|
+
return `src=${quote}${prefix}index.html${suffix}${quote}`;
|
|
74
|
+
}
|
|
75
|
+
return `src=${quote}${prefix}${target}/index.html${suffix}${quote}`;
|
|
76
|
+
});
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=relative-links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relative-links.js","sourceRoot":"","sources":["../../src/build/relative-links.ts"],"names":[],"mappings":"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","sourcesContent":["/** @codex { \"id\": \"pithy.ssr.build.relative-links\", \"title\": \"SSG Relative Link Rewriter\", \"category\": \"runtime\" } */\n\n/**\n * Convert absolute links in HTML to relative paths.\n *\n * Makes SSG output portable — works from file:// (double-click) and\n * any static hosting root without requiring server-side URL rewriting.\n *\n * From /ui-kit/for/index.html:\n * href=\"/about\" → href=\"../../about/index.html\"\n * src=\"/assets/client.js\" → src=\"../../assets/client.js\"\n * href=\"/assets/style.css\" → href=\"../../assets/style.css\"\n */\n\nexport interface MakeLinksRelativeOptions {\n /**\n * When true, only rewrite asset URLs (with file extensions like .css, .js)\n * and leave route-like URLs (/about, /dashboard) absolute.\n * Use this in hydrate mode where the client router needs absolute paths.\n */\n assetsOnly?: boolean;\n}\n\n/**\n * Convert all absolute href=\"/...\" and src=\"/...\" to relative paths.\n *\n * @param html - Full HTML string\n * @param currentPath - The route path this HTML was rendered for (e.g., '/ui-kit/for')\n * @param options - Options for link rewriting\n * @returns HTML with relative links\n */\n/** @codexApi {\"parent\":\"pithy.ssr.build.relative-links\",\"name\":\"makeLinksRelative\",\"stability\":\"stable\",\"signature\":\"(html: string, currentPath: string, options?: MakeLinksRelativeOptions) => string\"} */\nexport function makeLinksRelative(\n html: string,\n currentPath: string,\n options?: MakeLinksRelativeOptions\n): string {\n const assetsOnly = options?.assetsOnly ?? false;\n const depth = currentPath.split('/').filter(Boolean).length;\n const prefix = depth > 0 ? '../'.repeat(depth) : '';\n\n // Pass 1: Rewrite <base> tags separately — they define directory URLs,\n // never append /index.html. Dedicated pass avoids fragile lookbehind.\n // In assetsOnly mode, skip <base> rewriting entirely — the client\n // router relies on <base href=\"/\"> for absolute route matching.\n let result = assetsOnly\n ? html\n : html.replace(\n /(<base\\s[^>]*?)href=([\"'])\\/([^\"']*?)\\2/gi,\n (_match, before: string, quote: string, rawPath: string) => {\n // Skip protocol-relative URLs (//cdn.example.com/)\n if (rawPath.startsWith('/')) return _match;\n\n const target = rawPath.replace(/\\/$/, '');\n if (!target) return `${before}href=${quote}${prefix || './'}${quote}`;\n return `${before}href=${quote}${prefix}${target}/${quote}`;\n }\n );\n\n // Pass 2: Rewrite remaining href=\"/...\" (supports double and single quotes)\n // For file-like paths (with extension): always rewrite\n // For route-like paths: append /index.html (unless assetsOnly)\n // Preserves query strings and hash fragments\n result = result.replace(\n /href=([\"'])\\/([^\"']*?)\\1/g,\n (_match, quote: string, rawPath: string) => {\n // Skip protocol-relative URLs (//cdn.example.com/...)\n if (rawPath.startsWith('/')) return _match;\n\n // Split off query and hash\n const [pathPart, ...rest] = rawPath.split(/([?#])/);\n const suffix = rest.join(''); // preserves ?query#hash\n const target = pathPart.replace(/\\/$/, '');\n\n // If path has a file extension (e.g. .css, .js, .png), it's an asset — always rewrite\n if (target && /\\.\\w+$/.test(target)) {\n return `href=${quote}${prefix}${target}${suffix}${quote}`;\n }\n\n // In assetsOnly mode, skip route-like paths (no extension) so the\n // client router can still match them by their absolute pattern\n if (assetsOnly) return _match;\n\n if (!target) {\n return `href=${quote}${prefix}index.html${suffix}${quote}`;\n }\n\n return `href=${quote}${prefix}${target}/index.html${suffix}${quote}`;\n }\n );\n\n // Pass 3: Rewrite src=\"/...\" (supports double and single quotes)\n // Same asset-vs-route logic as href: only rewrite assets in assetsOnly mode\n result = result.replace(\n /src=([\"'])\\/([^\"']*?)\\1/g,\n (_match, quote: string, rawPath: string) => {\n if (rawPath.startsWith('/')) return _match;\n\n // Split off query and hash (same as href logic)\n const [pathPart, ...rest] = rawPath.split(/([?#])/);\n const suffix = rest.join('');\n\n // If path has a file extension, it's an asset — always rewrite\n if (pathPart && /\\.\\w+$/.test(pathPart)) {\n return `src=${quote}${prefix}${pathPart}${suffix}${quote}`;\n }\n\n // In assetsOnly mode, skip route-like src (e.g. <iframe src=\"/about\">)\n if (assetsOnly) return _match;\n\n // Route-like src: append /index.html (same as href) for file:// portability\n const target = pathPart.replace(/\\/$/, '');\n if (!target) {\n return `src=${quote}${prefix}index.html${suffix}${quote}`;\n }\n return `src=${quote}${prefix}${target}/index.html${suffix}${quote}`;\n }\n );\n\n return result;\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.ssr.build.shell-head",
|
|
4
|
+
"title": "SSG App-Shell Head Bridge",
|
|
5
|
+
"category": "feature",
|
|
6
|
+
"risk": "medium"
|
|
7
|
+
}
|
|
8
|
+
*/
|
|
9
|
+
import type { HeadState } from '../shared/types.js';
|
|
10
|
+
/** @codexApi {"parent":"pithy.ssr.build.shell-head","name":"parseShellHead","stability":"experimental","signature":"(html: string) => Partial<HeadState>"} */
|
|
11
|
+
/**
|
|
12
|
+
* Parse the carried head values out of an HTML shell.
|
|
13
|
+
*
|
|
14
|
+
* @param html - Contents of the app's shell document.
|
|
15
|
+
* @returns Title, meta and link entries worth carrying, empty when there are none.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseShellHead(html: string): Partial<HeadState>;
|
|
18
|
+
/** Options for {@link readShellHead}. */
|
|
19
|
+
/** @codexApi {"parent":"pithy.ssr.build.shell-head","name":"ReadShellHeadOptions","stability":"experimental","signature":"interface ReadShellHeadOptions"} */
|
|
20
|
+
export interface ReadShellHeadOptions {
|
|
21
|
+
/** Shell filename relative to `root` (default: `index.html`). */
|
|
22
|
+
shellFile?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Run the shell through Vite before parsing.
|
|
25
|
+
*
|
|
26
|
+
* `%VITE_*%` placeholders and `transformIndexHtml` plugin hooks are what dev
|
|
27
|
+
* and `vite build` render. Skipping them carries a literal `%VITE_APP_TITLE%`
|
|
28
|
+
* into the artifact and diverges from every other way the app is built.
|
|
29
|
+
*
|
|
30
|
+
* Called once for the whole build, and `buildSSG()` passes `/` as the URL, so
|
|
31
|
+
* a plugin whose `transformIndexHtml` varies by URL contributes its `/`
|
|
32
|
+
* variant to every page.
|
|
33
|
+
*/
|
|
34
|
+
transform?: (html: string) => Promise<string>;
|
|
35
|
+
}
|
|
36
|
+
/** @codexApi {"parent":"pithy.ssr.build.shell-head","name":"readShellHead","stability":"experimental","signature":"(root: string, options?: ReadShellHeadOptions) => Promise<Partial<HeadState>>"} */
|
|
37
|
+
/**
|
|
38
|
+
* Read the head an app declares in its HTML shell.
|
|
39
|
+
*
|
|
40
|
+
* An app with no shell file has nothing to carry and is not an error. A shell
|
|
41
|
+
* that exists but cannot be read or transformed is: `vite build` fails when a
|
|
42
|
+
* `transformIndexHtml` hook throws, and continuing here would report success
|
|
43
|
+
* while writing the untitled page this module exists to prevent.
|
|
44
|
+
*
|
|
45
|
+
* @param root - App root directory.
|
|
46
|
+
* @param options - See {@link ReadShellHeadOptions}.
|
|
47
|
+
* @returns Carried head values, empty when there is no shell file.
|
|
48
|
+
* @throws When the shell exists but cannot be read or transformed.
|
|
49
|
+
*/
|
|
50
|
+
export declare function readShellHead(root: string, options?: ReadShellHeadOptions): Promise<Partial<HeadState>>;
|
|
51
|
+
/** @codexApi {"parent":"pithy.ssr.build.shell-head","name":"resolvePageHead","stability":"experimental","signature":"(shellFile: Partial<HeadState>, shell: Partial<HeadState>, page: Partial<HeadState>) => HeadState"} */
|
|
52
|
+
/**
|
|
53
|
+
* Layer a page's head over the app shell's, over the shell file's.
|
|
54
|
+
*
|
|
55
|
+
* Precedence for the title is page, then app shell, then shell file — so a
|
|
56
|
+
* route that names itself still wins, and one that names nothing inherits
|
|
57
|
+
* rather than shipping untitled. Meta follows the same precedence via
|
|
58
|
+
* `mergeHead`; links the shell file carries yield per relation, since two
|
|
59
|
+
* `<link rel="icon">` lets the shell's beat the page's on rules the page
|
|
60
|
+
* cannot see.
|
|
61
|
+
*
|
|
62
|
+
* @param shellFile - Head values read from the app's HTML shell.
|
|
63
|
+
* @param shell - Head state from the App shell render.
|
|
64
|
+
* @param page - Head state from the page render.
|
|
65
|
+
* @returns The merged head state.
|
|
66
|
+
*/
|
|
67
|
+
export declare function resolvePageHead(shellFile: Partial<HeadState>, shell: Partial<HeadState>, page: Partial<HeadState>): HeadState;
|
|
68
|
+
//# sourceMappingURL=shell-head.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-head.d.ts","sourceRoot":"","sources":["../../src/build/shell-head.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAyBF,OAAO,KAAK,EACV,SAAS,EAIV,MAAM,oBAAoB,CAAC;AA4G5B,8JAA8J;AAC9J;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAwD/D;AAED,yCAAyC;AACzC,8JAA8J;AAC9J,MAAM,WAAW,oBAAoB;IACnC,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/C;AAED,sMAAsM;AACtM;;;;;;;;;;;;GAYG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAc7B;AAoBD,4NAA4N;AAC5N;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,EAC7B,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,EACzB,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,GACvB,SAAS,CAOX"}
|