@takazudo/zfb 0.1.0-next.10

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 (45) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/LICENSE +21 -0
  3. package/README.md +207 -0
  4. package/bin/zfb.mjs +82 -0
  5. package/dist/config.d.ts +542 -0
  6. package/dist/config.d.ts.map +1 -0
  7. package/dist/config.js +24 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/content.d.ts +240 -0
  10. package/dist/content.d.ts.map +1 -0
  11. package/dist/content.js +460 -0
  12. package/dist/content.js.map +1 -0
  13. package/dist/frontmatter.d.ts +23 -0
  14. package/dist/frontmatter.d.ts.map +1 -0
  15. package/dist/frontmatter.js +142 -0
  16. package/dist/frontmatter.js.map +1 -0
  17. package/dist/index.d.ts +7 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +21 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/island.d.ts +121 -0
  22. package/dist/island.d.ts.map +1 -0
  23. package/dist/island.js +273 -0
  24. package/dist/island.js.map +1 -0
  25. package/dist/jsx-types.d.ts +37 -0
  26. package/dist/jsx-types.d.ts.map +1 -0
  27. package/dist/jsx-types.js +12 -0
  28. package/dist/jsx-types.js.map +1 -0
  29. package/dist/paginate.d.ts +43 -0
  30. package/dist/paginate.d.ts.map +1 -0
  31. package/dist/paginate.js +44 -0
  32. package/dist/paginate.js.map +1 -0
  33. package/dist/plugins.d.ts +259 -0
  34. package/dist/plugins.d.ts.map +1 -0
  35. package/dist/plugins.js +42 -0
  36. package/dist/plugins.js.map +1 -0
  37. package/dist/runtime.d.ts +101 -0
  38. package/dist/runtime.d.ts.map +1 -0
  39. package/dist/runtime.js +454 -0
  40. package/dist/runtime.js.map +1 -0
  41. package/dist/types.d.ts +27 -0
  42. package/dist/types.d.ts.map +1 -0
  43. package/dist/types.js +33 -0
  44. package/dist/types.js.map +1 -0
  45. package/package.json +98 -0
@@ -0,0 +1,240 @@
1
+ import { parseFrontmatter } from "./frontmatter.js";
2
+ import type { ParsedFrontmatter } from "./frontmatter.js";
3
+ import type { VNode } from "./jsx-types.js";
4
+ export { parseFrontmatter };
5
+ export type { ParsedFrontmatter };
6
+ /**
7
+ * One entry in an embedded content snapshot. Mirrors
8
+ * `crates/zfb-content/src/content_bridge.rs::EntrySnapshot`. Re-exported
9
+ * by `@takazudo/zfb-runtime/snapshot` for the runtime-side bundle. See
10
+ * that module for field-by-field documentation.
11
+ */
12
+ export interface SnapshotEntry {
13
+ readonly slug: string;
14
+ readonly frontmatter: unknown;
15
+ readonly body: string;
16
+ readonly module_specifier: string;
17
+ readonly rel_path: string;
18
+ }
19
+ /**
20
+ * Point-in-time snapshot of every configured collection. Mirrors
21
+ * `crates/zfb-content/src/content_bridge.rs::ContentSnapshot`.
22
+ */
23
+ export interface Snapshot {
24
+ readonly collections: Readonly<Record<string, readonly SnapshotEntry[]>>;
25
+ }
26
+ /**
27
+ * Register a [`Snapshot`] so [`getCollection`] resolves from memory.
28
+ *
29
+ * Pass `undefined` to clear (used by tests that need to restore the v0
30
+ * filesystem path between runs). Idempotent: the latest call wins.
31
+ *
32
+ * Stored on `globalThis.__zfb.contentSnapshot` rather than a
33
+ * module-level `let` so a worker bundle that ends up with two
34
+ * `zfb/content` module instances still sees a single shared snapshot —
35
+ * see the [`SnapshotBridgeNamespace`] doc above for the full
36
+ * pnpm-symlink rationale.
37
+ */
38
+ export declare function setContentSnapshot(snapshot: Snapshot | undefined): void;
39
+ /**
40
+ * Read the currently-installed [`Snapshot`], or `undefined` if none is
41
+ * registered. Exposed mostly for tests; production callers should not
42
+ * need to introspect the bridge state.
43
+ *
44
+ * Reads from `globalThis.__zfb.contentSnapshot`; see
45
+ * [`setContentSnapshot`] for why the slot lives on `globalThis`.
46
+ */
47
+ export declare function getContentSnapshot(): Snapshot | undefined;
48
+ /**
49
+ * Props accepted by an entry's [`CollectionEntry.Content`] component.
50
+ *
51
+ * `components` mirrors Astro's `<Content components={...}>` contract:
52
+ * a flat record of element-name → override component (e.g. `{ h1: MyH1 }`).
53
+ * The default-components convention ships from `zfb`'s root export
54
+ * (`defaultComponents`, lands in Sub 6) and users compose with their own
55
+ * via `{ ...defaultComponents, ...mine }`.
56
+ */
57
+ export interface ContentProps {
58
+ /** Element-name → override component map. Optional. */
59
+ components?: Record<string, unknown>;
60
+ }
61
+ /**
62
+ * Public JSX-element shape returned by [`CollectionEntry.Content`].
63
+ *
64
+ * Matches the structural shape that both Preact's and React's `jsx-runtime`
65
+ * accept on either side of the boundary, mirroring the Island wrapper's
66
+ * approach. Consumers should treat this as opaque — its only contract is
67
+ * "renderable JSX value".
68
+ *
69
+ * Aliased as `JSX.Element` in the field signature: the JS runtime is
70
+ * type-erased and the actual VNode shape is supplied by the framework
71
+ * adapter at evaluation time.
72
+ */
73
+ export type ContentElement = {
74
+ readonly type: string | ((...args: unknown[]) => unknown);
75
+ readonly props: Readonly<Record<string, unknown>>;
76
+ readonly key: unknown;
77
+ };
78
+ /**
79
+ * Generic shape returned for one entry in a content collection. The `data`
80
+ * field carries parsed frontmatter, typed by the caller via the generic
81
+ * parameter.
82
+ */
83
+ export type CollectionEntry<T = Record<string, unknown>> = {
84
+ /** Filename without `.md` extension. Stable across runs. */
85
+ slug: string;
86
+ /** Parsed frontmatter. */
87
+ data: T;
88
+ /** Raw markdown body (frontmatter stripped). */
89
+ body: string;
90
+ /**
91
+ * Stable module specifier used as the bridge lookup key. Format:
92
+ * `mdx://<collection>/<slug>` (no hash component — the JS stub does
93
+ * not compile MDX, so it has no body hash to attach; the production
94
+ * Rust-side `zfb-content::collection::Entry::module_specifier` adds a
95
+ * `#<hash>` suffix and the bridge is responsible for matching either
96
+ * form against its registered components).
97
+ *
98
+ * This field is part of the v0+ JS surface so the bridge has something
99
+ * deterministic to key on without consulting per-call state.
100
+ */
101
+ module_specifier: string;
102
+ /**
103
+ * Renderable component for this entry.
104
+ *
105
+ * **Bridge contract.** At call time, `Content` consults
106
+ * `globalThis.__zfb?.content?.get(entry.module_specifier)`. If the
107
+ * bridge is present and returns a function, that function is invoked
108
+ * with `props` and its result returned verbatim.
109
+ *
110
+ * **Fallback.** Outside the renderer (unit tests, dev sandboxes, or any
111
+ * environment where `globalThis.__zfb.content.get` is absent or returns
112
+ * `undefined`), `Content` returns a JSX-shaped element rendering the
113
+ * raw markdown body inside a `<pre data-zfb-content-fallback>` block,
114
+ * with a leading `[zfb fallback render]` marker line so the visual
115
+ * distinction survives unstyled environments. The marker is also a
116
+ * grep target for "did the production renderer not run?" diagnostics.
117
+ *
118
+ * **Typed signature.** Returns `ContentElement` (a structural alias for
119
+ * `JSX.Element`) so consumers can drop `<entry.Content components={...} />`
120
+ * into both React and Preact JSX without per-framework type setup.
121
+ *
122
+ * @example
123
+ * const post = (await getCollection("blog"))[0];
124
+ * return <post.Content components={{ ...defaultComponents, h1: MyH1 }} />;
125
+ */
126
+ Content: (props: ContentProps) => ContentElement;
127
+ };
128
+ /**
129
+ * Load every `*.md` file in the named collection. Files starting with `.`
130
+ * or that lack a `.md` extension are ignored.
131
+ *
132
+ * **ADR-004 contract: this function is synchronous.** TSX page modules
133
+ * call it from anywhere — top-level, inside a render body, inside a
134
+ * `useMemo` — and SSR completes in a single pass without yielding. The
135
+ * snapshot path returns from memory; the filesystem fallback uses sync
136
+ * `node:fs` APIs so the surface stays unified. (The legacy async
137
+ * implementation was an oversight — the ADR predates it; SSG paths
138
+ * always saw a Promise where ADR-004 says they should see an array,
139
+ * which is why migrations from Astro tripped on `getCollection().filter
140
+ * is not a function`.)
141
+ *
142
+ * @example
143
+ * const posts = getCollection<{ title: string; date: string }>("blog");
144
+ */
145
+ export declare function getCollection<T = Record<string, unknown>>(name: string): CollectionEntry<T>[];
146
+ /**
147
+ * @internal
148
+ *
149
+ * Convert a `path.relative()` result into a forward-slash-separated
150
+ * slug with the trailing `.md` extension stripped.
151
+ *
152
+ * Slugs are URL-flavored identifiers, not filesystem paths — they
153
+ * MUST use `/` regardless of the host OS so a nested entry like
154
+ * `2024/hello.md` produces the slug `2024/hello` on both POSIX and
155
+ * Windows. Without this normalisation, Windows callers would see
156
+ * `2024\hello`, which then leaks through to `module_specifier` and
157
+ * any URL the consumer derives from the slug.
158
+ *
159
+ * Exported solely so the unit test suite can pin the Windows
160
+ * behaviour without needing an actual Windows host. Do not depend on
161
+ * this from application code — name and signature may change.
162
+ */
163
+ export declare function _relPathToSlug(relPath: string): string;
164
+ /**
165
+ * Public JSX-element shape returned by every override in [`defaultComponents`].
166
+ *
167
+ * Mirrors [`ContentElement`] and [`IslandElement`]: a structural alias for
168
+ * `JSX.Element` so consumers can drop these overrides into both React and
169
+ * Preact JSX without per-framework type setup.
170
+ */
171
+ export type ContentComponentElement = {
172
+ readonly type: string;
173
+ readonly props: Readonly<Record<string, unknown>>;
174
+ readonly key: unknown;
175
+ };
176
+ /**
177
+ * Props accepted by every default override. `children` and any extra
178
+ * attributes (`className`, `id`, `href`, …) are passed through verbatim
179
+ * to the underlying HTML element.
180
+ */
181
+ export interface ContentComponentProps {
182
+ children?: VNode;
183
+ [key: string]: unknown;
184
+ }
185
+ /**
186
+ * `<h2>` passthrough override. Ported from zudo-doc's `HeadingH2`, stripped
187
+ * of styling — v0 ships pass-through behaviour; visual treatment is layered
188
+ * on by the consumer (or by a follow-up enhancement pass).
189
+ */
190
+ export declare function ContentH2(props: ContentComponentProps): ContentComponentElement;
191
+ /** `<h3>` passthrough override. See [`ContentH2`] for the contract. */
192
+ export declare function ContentH3(props: ContentComponentProps): ContentComponentElement;
193
+ /** `<h4>` passthrough override. See [`ContentH2`] for the contract. */
194
+ export declare function ContentH4(props: ContentComponentProps): ContentComponentElement;
195
+ /** `<p>` passthrough override. Mirrors zudo-doc's `ContentParagraph`. */
196
+ export declare function ContentParagraph(props: ContentComponentProps): ContentComponentElement;
197
+ /** `<a>` passthrough override. Mirrors zudo-doc's `ContentLink`. */
198
+ export declare function ContentLink(props: ContentComponentProps): ContentComponentElement;
199
+ /** `<strong>` passthrough override. Mirrors zudo-doc's `ContentStrong`. */
200
+ export declare function ContentStrong(props: ContentComponentProps): ContentComponentElement;
201
+ /** `<blockquote>` passthrough override. Mirrors zudo-doc's `ContentBlockquote`. */
202
+ export declare function ContentBlockquote(props: ContentComponentProps): ContentComponentElement;
203
+ /** `<ul>` passthrough override. Mirrors zudo-doc's `ContentUl`. */
204
+ export declare function ContentUl(props: ContentComponentProps): ContentComponentElement;
205
+ /** `<ol>` passthrough override. Mirrors zudo-doc's `ContentOl`. */
206
+ export declare function ContentOl(props: ContentComponentProps): ContentComponentElement;
207
+ /** `<table>` passthrough override. Mirrors zudo-doc's `ContentTable`. */
208
+ export declare function ContentTable(props: ContentComponentProps): ContentComponentElement;
209
+ /** `<code>` passthrough override. Mirrors zudo-doc's `ContentCode`. */
210
+ export declare function ContentCode(props: ContentComponentProps): ContentComponentElement;
211
+ /**
212
+ * Default per-element override map — eleven entries covering the markdown
213
+ * tags the zudo-doc convention overrides (`h2`, `h3`, `h4`, `p`, `a`,
214
+ * `strong`, `blockquote`, `ul`, `ol`, `table`, `code`).
215
+ *
216
+ * `h1` is intentionally absent: page titles render from frontmatter, per
217
+ * the zudo-doc convention.
218
+ *
219
+ * Spread into a `components` prop to compose with custom overrides:
220
+ *
221
+ * ```tsx
222
+ * import { defaultComponents } from "zfb";
223
+ *
224
+ * <entry.Content components={{ ...defaultComponents, h2: MyFancyH2 }} />
225
+ * ```
226
+ */
227
+ export declare const defaultComponents: {
228
+ readonly h2: typeof ContentH2;
229
+ readonly h3: typeof ContentH3;
230
+ readonly h4: typeof ContentH4;
231
+ readonly p: typeof ContentParagraph;
232
+ readonly a: typeof ContentLink;
233
+ readonly strong: typeof ContentStrong;
234
+ readonly blockquote: typeof ContentBlockquote;
235
+ readonly ul: typeof ContentUl;
236
+ readonly ol: typeof ContentOl;
237
+ readonly table: typeof ContentTable;
238
+ readonly code: typeof ContentCode;
239
+ };
240
+ //# sourceMappingURL=content.d.ts.map
@@ -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