zreader 0.0.0-stage → 0.1.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 (63) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +234 -2
  4. package/dist/blocks-DwR7l7pz.d.ts +20 -0
  5. package/dist/chunk-3WQBK6DE.js +47 -0
  6. package/dist/chunk-3WQBK6DE.js.map +1 -0
  7. package/dist/chunk-DYQNGV46.js +31 -0
  8. package/dist/chunk-DYQNGV46.js.map +1 -0
  9. package/dist/chunk-ISI35TCM.js +62 -0
  10. package/dist/chunk-ISI35TCM.js.map +1 -0
  11. package/dist/chunk-RNSAFDZ5.js +105 -0
  12. package/dist/chunk-RNSAFDZ5.js.map +1 -0
  13. package/dist/config/index.cjs +196 -0
  14. package/dist/config/index.cjs.map +1 -0
  15. package/dist/config/index.d.cts +159 -0
  16. package/dist/config/index.d.ts +159 -0
  17. package/dist/config/index.js +182 -0
  18. package/dist/config/index.js.map +1 -0
  19. package/dist/content/index.d.ts +143 -0
  20. package/dist/content/index.js +379 -0
  21. package/dist/content/index.js.map +1 -0
  22. package/dist/core/index.d.ts +262 -0
  23. package/dist/core/index.js +935 -0
  24. package/dist/core/index.js.map +1 -0
  25. package/dist/editor/index.d.ts +19 -0
  26. package/dist/editor/index.js +277 -0
  27. package/dist/editor/index.js.map +1 -0
  28. package/dist/index-Bp5oIiZd.d.ts +61 -0
  29. package/dist/next/client/index.d.ts +8 -0
  30. package/dist/next/client/index.js +13 -0
  31. package/dist/next/client/index.js.map +1 -0
  32. package/dist/next/index.cjs +272 -0
  33. package/dist/next/index.cjs.map +1 -0
  34. package/dist/next/index.d.cts +47 -0
  35. package/dist/next/index.d.ts +47 -0
  36. package/dist/next/index.js +262 -0
  37. package/dist/next/index.js.map +1 -0
  38. package/dist/next/server/index.d.ts +58 -0
  39. package/dist/next/server/index.js +44 -0
  40. package/dist/next/server/index.js.map +1 -0
  41. package/dist/react/index.d.ts +376 -0
  42. package/dist/react/index.js +2793 -0
  43. package/dist/react/index.js.map +1 -0
  44. package/dist/reader.css +116 -0
  45. package/dist/rehype/index.d.ts +27 -0
  46. package/dist/rehype/index.js +4 -0
  47. package/dist/rehype/index.js.map +1 -0
  48. package/dist/stubs/empty-config.d.ts +9 -0
  49. package/dist/stubs/empty-config.js +7 -0
  50. package/dist/stubs/empty-config.js.map +1 -0
  51. package/dist/stubs/server-only.d.ts +2 -0
  52. package/dist/stubs/server-only.js +6 -0
  53. package/dist/stubs/server-only.js.map +1 -0
  54. package/dist/styles.css +1 -0
  55. package/dist/tailwind.css +41 -0
  56. package/dist/types-xkdpkPxA.d.ts +147 -0
  57. package/dist/user-config/index.d.ts +17 -0
  58. package/dist/user-config/index.js +35 -0
  59. package/dist/user-config/index.js.map +1 -0
  60. package/dist/virtual-config/index.d.ts +6 -0
  61. package/dist/virtual-config/index.js +10 -0
  62. package/dist/virtual-config/index.js.map +1 -0
  63. package/package.json +225 -4
@@ -0,0 +1,182 @@
1
+ import { z } from 'zod/v4';
2
+ export { z } from 'zod/v4';
3
+
4
+ // src/config/index.ts
5
+
6
+ // src/core/defaults.ts
7
+ var DEFAULT_CLIENT_OPTIONS = {
8
+ storagePrefix: "zr",
9
+ highlightColors: ["yellow", "green", "blue", "pink"],
10
+ defaultHighlightColor: "yellow",
11
+ scratchpad: { enabled: true, scopes: ["chapter", "book", "global"] },
12
+ themes: ["system", "light", "sepia", "dark"],
13
+ defaultTheme: "system",
14
+ defaultSettings: {
15
+ textSize: "lg",
16
+ leading: "relaxed",
17
+ measure: "normal",
18
+ fontFamily: "serif",
19
+ highlightMode: false
20
+ },
21
+ progress: { completeAt: 0.9, saveIntervalMs: 1e3 },
22
+ backupReminder: true,
23
+ basePath: "/books"
24
+ };
25
+
26
+ // src/core/types.ts
27
+ var THEMES = ["system", "light", "sepia", "dark"];
28
+ var TEXT_SIZES = ["sm", "base", "lg", "xl", "2xl"];
29
+ var LEADINGS = ["tight", "normal", "relaxed"];
30
+ var MEASURES = ["narrow", "normal", "wide"];
31
+ var FONT_FAMILIES = ["serif", "sans", "mono"];
32
+ var HIGHLIGHT_COLORS = ["yellow", "green", "blue", "pink", "purple", "orange"];
33
+
34
+ // src/config/index.ts
35
+ function glob(opts) {
36
+ return { kind: "glob", base: opts.base, pattern: opts.pattern ?? "**/*.{md,mdx,html}", ignore: opts.ignore };
37
+ }
38
+ var defaultBookSchema = z.looseObject({
39
+ title: z.string(),
40
+ subtitle: z.string().optional(),
41
+ authors: z.array(z.string()).default([]),
42
+ description: z.string().optional(),
43
+ cover: z.string().optional(),
44
+ /** Optional explicit chapter order (chapter slugs). */
45
+ chapters: z.array(z.string()).optional()
46
+ });
47
+ var defaultChapterSchema = z.looseObject({
48
+ title: z.string(),
49
+ order: z.number().optional(),
50
+ description: z.string().optional(),
51
+ part: z.string().optional(),
52
+ label: z.string().optional(),
53
+ number: z.union([z.string(), z.number()]).transform(String).optional(),
54
+ draft: z.boolean().default(false)
55
+ });
56
+ function isDev() {
57
+ return typeof process !== "undefined" && process.env?.NODE_ENV === "development";
58
+ }
59
+ function defaultContentConfig() {
60
+ return {
61
+ loader: glob({ base: "./content/books" }),
62
+ schemas: { book: defaultBookSchema, chapter: defaultChapterSchema },
63
+ remarkPlugins: [],
64
+ rehypePlugins: [],
65
+ sanitize: {},
66
+ includeDrafts: isDev(),
67
+ cacheDir: typeof process !== "undefined" && process.env?.ZREADER_CACHE_DIR || "node_modules/.cache/zreader"
68
+ };
69
+ }
70
+ function defineConfig(config) {
71
+ return config;
72
+ }
73
+ function isPlainObject(x) {
74
+ if (typeof x !== "object" || x === null || Array.isArray(x)) return false;
75
+ const proto = Object.getPrototypeOf(x);
76
+ return proto === Object.prototype || proto === null;
77
+ }
78
+ function mergeConfig(base, ...overrides) {
79
+ let out = base;
80
+ for (const o of overrides) out = mergeTwo(out, o);
81
+ return out;
82
+ }
83
+ function mergeTwo(a, b) {
84
+ if (b === void 0) return a;
85
+ if (isPlainObject(a) && isPlainObject(b)) {
86
+ const out = { ...a };
87
+ for (const [k, v] of Object.entries(b)) out[k] = mergeTwo(a[k], v);
88
+ return out;
89
+ }
90
+ return b;
91
+ }
92
+ var themeName = z.enum(THEMES);
93
+ var highlightColor = z.enum(HIGHLIGHT_COLORS);
94
+ var clientSchema = z.object({
95
+ storagePrefix: z.string().regex(/^[a-z0-9_-]+$/i, "use letters, digits, '-' or '_'"),
96
+ highlightColors: z.array(highlightColor).min(1, "must be non-empty"),
97
+ defaultHighlightColor: highlightColor,
98
+ scratchpad: z.object({
99
+ enabled: z.boolean(),
100
+ scopes: z.array(z.enum(["global", "book", "chapter"])).min(1, "must be non-empty")
101
+ }),
102
+ themes: z.array(themeName).min(1),
103
+ defaultTheme: themeName,
104
+ defaultSettings: z.object({
105
+ textSize: z.enum(TEXT_SIZES),
106
+ leading: z.enum(LEADINGS),
107
+ measure: z.enum(MEASURES),
108
+ fontFamily: z.enum(FONT_FAMILIES),
109
+ highlightMode: z.boolean()
110
+ }),
111
+ progress: z.object({ completeAt: z.number().gt(0).max(1), saveIntervalMs: z.number().min(100) }),
112
+ backupReminder: z.boolean(),
113
+ basePath: z.string().startsWith("/")
114
+ }).refine((c) => c.highlightColors.includes(c.defaultHighlightColor), {
115
+ message: "defaultHighlightColor must be one of highlightColors",
116
+ path: ["defaultHighlightColor"]
117
+ }).refine((c) => c.themes.includes(c.defaultTheme), {
118
+ message: "defaultTheme must be one of themes",
119
+ path: ["defaultTheme"]
120
+ });
121
+ function isSchemaLike(v) {
122
+ return typeof v === "object" && v !== null && typeof v.safeParse === "function";
123
+ }
124
+ var contentSchema = z.object({
125
+ loader: z.object({
126
+ kind: z.literal("glob"),
127
+ base: z.string().min(1),
128
+ pattern: z.union([z.string(), z.array(z.string()).min(1)]),
129
+ ignore: z.array(z.string()).optional()
130
+ }),
131
+ schemas: z.object({
132
+ book: z.custom(isSchemaLike, "must be a zod (or safeParse-compatible) schema"),
133
+ chapter: z.custom(isSchemaLike, "must be a zod (or safeParse-compatible) schema")
134
+ }),
135
+ remarkPlugins: z.array(z.any()),
136
+ rehypePlugins: z.array(z.any()),
137
+ sanitize: z.object({
138
+ allowIframes: z.array(z.string()).optional(),
139
+ allowTags: z.array(z.string()).optional(),
140
+ allowAttributes: z.array(z.string()).optional()
141
+ }),
142
+ includeDrafts: z.boolean(),
143
+ cacheDir: z.string()
144
+ });
145
+ var ReaderConfigError = class extends Error {
146
+ constructor(message, issues = []) {
147
+ super(message);
148
+ this.issues = issues;
149
+ this.name = "ReaderConfigError";
150
+ }
151
+ issues;
152
+ };
153
+ function formatIssues(source, section, error) {
154
+ const issues = error.issues.map((i) => ({ path: [section, ...i.path.map(String)].join("."), message: i.message }));
155
+ return new ReaderConfigError(
156
+ `Invalid reader config${source ? ` (${source})` : ""}:
157
+ ` + issues.map((i) => ` - ${i.path}: ${i.message}`).join("\n"),
158
+ issues
159
+ );
160
+ }
161
+ function resolveConfig(user, inline, opts = {}) {
162
+ const root = opts.root ?? (typeof process !== "undefined" && process.cwd ? process.cwd() : "/");
163
+ const reader = mergeConfig(
164
+ structuredClone(DEFAULT_CLIENT_OPTIONS),
165
+ user?.reader,
166
+ inline?.reader
167
+ );
168
+ const content = mergeConfig(defaultContentConfig(), user?.content, inline?.content);
169
+ const r = clientSchema.safeParse(reader);
170
+ if (!r.success) throw formatIssues(opts.source ?? "", "reader", r.error);
171
+ const c = contentSchema.safeParse(content);
172
+ if (!c.success) throw formatIssues(opts.source ?? "", "content", c.error);
173
+ return { root, content, reader };
174
+ }
175
+ function clientOptions(config) {
176
+ return config.reader;
177
+ }
178
+ var CONFIG_FILE_NAMES = ["reader.config.ts", "reader.config.mts", "reader.config.mjs", "reader.config.js"];
179
+
180
+ export { CONFIG_FILE_NAMES, ReaderConfigError, clientOptions, defaultBookSchema, defaultChapterSchema, defaultContentConfig, defineConfig, glob, mergeConfig, resolveConfig };
181
+ //# sourceMappingURL=index.js.map
182
+ //# sourceMappingURL=index.js.map
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,CAAA,CAAE,OAAA,EAAS,MAAM,YAAA,CAAa,KAAK,MAAA,IAAU,EAAA,EAAI,QAAA,EAAU,CAAA,CAAE,KAAK,CAAA;AACvE,EAAA,MAAM,CAAA,GAAI,aAAA,CAAc,SAAA,CAAU,OAAO,CAAA;AACzC,EAAA,IAAI,CAAC,CAAA,CAAE,OAAA,EAAS,MAAM,YAAA,CAAa,KAAK,MAAA,IAAU,EAAA,EAAI,SAAA,EAAW,CAAA,CAAE,KAAK,CAAA;AAExE,EAAA,OAAO,EAAE,IAAA,EAAM,OAAA,EAAS,MAAA,EAAO;AACjC;AAGO,SAAS,cAAc,MAAA,EAAmD;AAC/E,EAAA,OAAO,MAAA,CAAO,MAAA;AAChB;AAEO,IAAM,iBAAA,GAAoB,CAAC,kBAAA,EAAoB,mBAAA,EAAqB,qBAAqB,kBAAkB","file":"index.js","sourcesContent":["import type { ReaderClientOptions } from \"./types\";\n\nexport const DEFAULT_CLIENT_OPTIONS: ReaderClientOptions = {\n storagePrefix: \"zr\",\n highlightColors: [\"yellow\", \"green\", \"blue\", \"pink\"],\n defaultHighlightColor: \"yellow\",\n scratchpad: { enabled: true, scopes: [\"chapter\", \"book\", \"global\"] },\n themes: [\"system\", \"light\", \"sepia\", \"dark\"],\n defaultTheme: \"system\",\n defaultSettings: {\n textSize: \"lg\",\n leading: \"relaxed\",\n measure: \"normal\",\n fontFamily: \"serif\",\n highlightMode: false,\n },\n progress: { completeAt: 0.9, saveIntervalMs: 1000 },\n backupReminder: true,\n basePath: \"/books\",\n};\n","/** Shared, framework-agnostic data model for zreader. */\n\nexport type ISODate = string;\n\n/** W3C Web Annotation-style anchor. Offsets are measured over the chapter root's text. */\nexport interface Anchor {\n /** `data-block-id` of the block containing the start of the selection. */\n blockId: string;\n /** Offsets relative to the start block's text (fast path). */\n blockStart: number;\n /** TextPositionSelector over the whole chapter text. */\n start: number;\n end: number;\n /** TextQuoteSelector. */\n exact: string;\n prefix: string;\n suffix: string;\n /** Content hash of the chapter when the anchor was created. */\n contentHash?: string;\n}\n\nexport interface Highlight {\n id: string;\n bookId: string;\n chapterId: string;\n anchor: Anchor;\n color: string;\n note?: string;\n createdAt: ISODate;\n updatedAt: ISODate;\n}\n\nexport interface Bookmark {\n id: string;\n bookId: string;\n chapterId: string;\n /** Absent for whole-chapter bookmarks. */\n blockId?: string;\n label?: string;\n excerpt?: string;\n createdAt: ISODate;\n updatedAt: ISODate;\n}\n\nexport interface ChapterProgress {\n chapterId: string;\n blockId?: string;\n /** 0..1 */\n percent: number;\n completed: boolean;\n updatedAt: ISODate;\n}\n\nexport interface BookProgress {\n bookId: string;\n chapters: Record<string, ChapterProgress>;\n last?: { chapterId: string; blockId?: string; updatedAt: ISODate };\n}\n\nexport type PadScope =\n | { kind: \"global\" }\n | { kind: \"book\"; bookId: string }\n | { kind: \"chapter\"; bookId: string; chapterId: string };\n\nexport type PadScopeKind = PadScope[\"kind\"];\n\nexport interface Pad {\n /** Markdown is the interchange/source format. */\n markdown: string;\n /** Lossless editor JSON cache. Cleared whenever `markdown` is changed outside the editor. */\n json?: unknown;\n updatedAt: ISODate;\n}\n\nexport type ThemeName = \"system\" | \"light\" | \"sepia\" | \"dark\";\nexport type Measure = \"narrow\" | \"normal\" | \"wide\";\nexport type FontFamily = \"serif\" | \"sans\" | \"mono\";\nexport type TextSize = \"sm\" | \"base\" | \"lg\" | \"xl\" | \"2xl\";\nexport type Leading = \"tight\" | \"normal\" | \"relaxed\";\n\nexport const THEMES = [\"system\", \"light\", \"sepia\", \"dark\"] as const satisfies readonly ThemeName[];\nexport const TEXT_SIZES = [\"sm\", \"base\", \"lg\", \"xl\", \"2xl\"] as const satisfies readonly TextSize[];\nexport const LEADINGS = [\"tight\", \"normal\", \"relaxed\"] as const satisfies readonly Leading[];\nexport const MEASURES = [\"narrow\", \"normal\", \"wide\"] as const satisfies readonly Measure[];\nexport const FONT_FAMILIES = [\"serif\", \"sans\", \"mono\"] as const satisfies readonly FontFamily[];\n/** The palette the UI ships styles for (`::highlight(zr-<color>)`). */\nexport const HIGHLIGHT_COLORS = [\"yellow\", \"green\", \"blue\", \"pink\", \"purple\", \"orange\"] as const;\nexport type HighlightColor = (typeof HIGHLIGHT_COLORS)[number];\n\nexport interface ReaderSettings {\n textSize: TextSize;\n leading: Leading;\n measure: Measure;\n fontFamily: FontFamily;\n /** Tap a sentence to highlight it with the default colour. */\n highlightMode: boolean;\n updatedAt: ISODate;\n}\n\n/** Serializable client options (the `reader` half of reader.config.ts). */\nexport interface ReaderClientOptions {\n storagePrefix: string;\n highlightColors: HighlightColor[];\n defaultHighlightColor: HighlightColor;\n scratchpad: { enabled: boolean; scopes: PadScopeKind[] };\n /** Themes offered in the UI. Applied as a class on <html> via next-themes. */\n themes: ThemeName[];\n defaultTheme: ThemeName;\n defaultSettings: Omit<ReaderSettings, \"updatedAt\">;\n progress: { completeAt: number; saveIntervalMs: number };\n /** Show a \"your notes only live in this browser\" reminder. */\n backupReminder: boolean;\n /** Base path used to build links back into the reader (e.g. quote-to-pad). */\n basePath: string;\n}\n\nexport interface TocEntry {\n id: string;\n depth: number;\n text: string;\n}\n\nexport interface ChapterMeta {\n id: string;\n title: string;\n order: number;\n description?: string;\n /** Section the chapter belongs to, e.g. \"Part I · For the Builders\". Groups the contents list. */\n part?: string;\n /** Eyebrow shown above the title, e.g. \"Chapter 5\" or \"Appendix A\". */\n label?: string;\n /** Short marker for lists, e.g. \"5\" or \"A\". */\n number?: string;\n}\n\nexport interface BookMeta {\n id: string;\n title: string;\n subtitle?: string;\n authors: string[];\n description?: string;\n cover?: string;\n chapters: ChapterMeta[];\n}\n","import { z } from \"zod/v4\";\nimport { DEFAULT_CLIENT_OPTIONS } from \"../core/defaults\";\nimport {\n FONT_FAMILIES,\n HIGHLIGHT_COLORS,\n LEADINGS,\n MEASURES,\n TEXT_SIZES,\n THEMES,\n type ReaderClientOptions,\n} from \"../core/types\";\n\nexport { z };\n\n// ---------------------------------------------------------------- types\n\nexport interface GlobLoader {\n kind: \"glob\";\n /** Directory containing one folder per book. Relative to the project root. */\n base: string;\n /** Chapter files, relative to `base`. */\n pattern: string | string[];\n ignore?: string[];\n}\n\n/** Astro-style glob loader: `content/books/<book>/{book.json, 01-intro.md, ...}` */\nexport function glob(opts: { base: string; pattern?: string | string[]; ignore?: string[] }): GlobLoader {\n return { kind: \"glob\", base: opts.base, pattern: opts.pattern ?? \"**/*.{md,mdx,html}\", ignore: opts.ignore };\n}\n\n// unified's PluggableList, kept loose to avoid a type dependency in this entry.\nexport type PluginList = unknown[];\n\nexport interface SanitizeOptions {\n /** Hostnames allowed for <iframe src>. Iframes are stripped unless listed here. */\n allowIframes?: string[];\n /** Extra tags to allow on top of DOMPurify's safe HTML profile. */\n allowTags?: string[];\n /** Extra attributes to allow. */\n allowAttributes?: string[];\n}\n\nexport interface ContentConfig {\n loader: GlobLoader;\n schemas: { book: z.ZodType; chapter: z.ZodType };\n /** Applied to `.md` and `.mdx`. */\n remarkPlugins: PluginList;\n rehypePlugins: PluginList;\n sanitize: SanitizeOptions;\n /** Include chapters with `draft: true`. Defaults to `true` in development. */\n includeDrafts: boolean;\n /** Where compiled chapters are cached. */\n cacheDir: string;\n}\n\ntype DeepPartial<T> = T extends unknown[] ? T : T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } : T;\n\nexport interface ReaderUserConfig {\n content?: DeepPartial<Omit<ContentConfig, \"schemas\" | \"loader\">> & {\n loader?: GlobLoader;\n schemas?: Partial<ContentConfig[\"schemas\"]>;\n };\n reader?: DeepPartial<ReaderClientOptions>;\n}\n\nexport interface ResolvedReaderConfig {\n root: string;\n content: ContentConfig;\n reader: ReaderClientOptions;\n}\n\n// ------------------------------------------------------------- defaults\n\nexport const defaultBookSchema = z.looseObject({\n title: z.string(),\n subtitle: z.string().optional(),\n authors: z.array(z.string()).default([]),\n description: z.string().optional(),\n cover: z.string().optional(),\n /** Optional explicit chapter order (chapter slugs). */\n chapters: z.array(z.string()).optional(),\n});\n\nexport const defaultChapterSchema = z.looseObject({\n title: z.string(),\n order: z.number().optional(),\n description: z.string().optional(),\n part: z.string().optional(),\n label: z.string().optional(),\n number: z.union([z.string(), z.number()]).transform(String).optional(),\n draft: z.boolean().default(false),\n});\n\nfunction isDev() {\n return typeof process !== \"undefined\" && process.env?.NODE_ENV === \"development\";\n}\n\nexport function defaultContentConfig(): ContentConfig {\n return {\n loader: glob({ base: \"./content/books\" }),\n schemas: { book: defaultBookSchema, chapter: defaultChapterSchema },\n remarkPlugins: [],\n rehypePlugins: [],\n sanitize: {},\n includeDrafts: isDev(),\n cacheDir:\n (typeof process !== \"undefined\" && process.env?.ZREADER_CACHE_DIR) || \"node_modules/.cache/zreader\",\n };\n}\n\n// ------------------------------------------------------------ define/merge\n\n/** Identity helper that gives `reader.config.ts` full type-checking. */\nexport function defineConfig(config: ReaderUserConfig): ReaderUserConfig {\n return config;\n}\n\nfunction isPlainObject(x: unknown): x is Record<string, unknown> {\n if (typeof x !== \"object\" || x === null || Array.isArray(x)) return false;\n const proto = Object.getPrototypeOf(x);\n return proto === Object.prototype || proto === null;\n}\n\n/**\n * Deep merge: plain objects merge key-by-key, arrays and class instances\n * (e.g. zod schemas) replace, `undefined` never overrides.\n */\nexport function mergeConfig<T>(base: T, ...overrides: unknown[]): T {\n let out: unknown = base;\n for (const o of overrides) out = mergeTwo(out, o);\n return out as T;\n}\n\nfunction mergeTwo(a: unknown, b: unknown): unknown {\n if (b === undefined) return a;\n if (isPlainObject(a) && isPlainObject(b)) {\n const out: Record<string, unknown> = { ...a };\n for (const [k, v] of Object.entries(b)) out[k] = mergeTwo(a[k], v);\n return out;\n }\n return b;\n}\n\n// --------------------------------------------------------------- validate\n\nconst themeName = z.enum(THEMES);\nconst highlightColor = z.enum(HIGHLIGHT_COLORS);\nconst clientSchema = z\n .object({\n storagePrefix: z.string().regex(/^[a-z0-9_-]+$/i, \"use letters, digits, '-' or '_'\"),\n highlightColors: z.array(highlightColor).min(1, \"must be non-empty\"),\n defaultHighlightColor: highlightColor,\n scratchpad: z.object({\n enabled: z.boolean(),\n scopes: z.array(z.enum([\"global\", \"book\", \"chapter\"])).min(1, \"must be non-empty\"),\n }),\n themes: z.array(themeName).min(1),\n defaultTheme: themeName,\n defaultSettings: z.object({\n textSize: z.enum(TEXT_SIZES),\n leading: z.enum(LEADINGS),\n measure: z.enum(MEASURES),\n fontFamily: z.enum(FONT_FAMILIES),\n highlightMode: z.boolean(),\n }),\n progress: z.object({ completeAt: z.number().gt(0).max(1), saveIntervalMs: z.number().min(100) }),\n backupReminder: z.boolean(),\n basePath: z.string().startsWith(\"/\"),\n })\n .refine((c) => c.highlightColors.includes(c.defaultHighlightColor), {\n message: \"defaultHighlightColor must be one of highlightColors\",\n path: [\"defaultHighlightColor\"],\n })\n .refine((c) => c.themes.includes(c.defaultTheme), {\n message: \"defaultTheme must be one of themes\",\n path: [\"defaultTheme\"],\n });\n\nfunction isSchemaLike(v: unknown): boolean {\n return typeof v === \"object\" && v !== null && typeof (v as { safeParse?: unknown }).safeParse === \"function\";\n}\n\nconst contentSchema = z.object({\n loader: z.object({\n kind: z.literal(\"glob\"),\n base: z.string().min(1),\n pattern: z.union([z.string(), z.array(z.string()).min(1)]),\n ignore: z.array(z.string()).optional(),\n }),\n schemas: z.object({\n book: z.custom<z.ZodType>(isSchemaLike, \"must be a zod (or safeParse-compatible) schema\"),\n chapter: z.custom<z.ZodType>(isSchemaLike, \"must be a zod (or safeParse-compatible) schema\"),\n }),\n remarkPlugins: z.array(z.any()),\n rehypePlugins: z.array(z.any()),\n sanitize: z.object({\n allowIframes: z.array(z.string()).optional(),\n allowTags: z.array(z.string()).optional(),\n allowAttributes: z.array(z.string()).optional(),\n }),\n includeDrafts: z.boolean(),\n cacheDir: z.string(),\n});\n\nexport class ReaderConfigError extends Error {\n constructor(\n message: string,\n public readonly issues: { path: string; message: string }[] = [],\n ) {\n super(message);\n this.name = \"ReaderConfigError\";\n }\n}\n\nfunction formatIssues(source: string, section: string, error: z.ZodError) {\n const issues = error.issues.map((i) => ({ path: [section, ...i.path.map(String)].join(\".\"), message: i.message }));\n return new ReaderConfigError(\n `Invalid reader config${source ? ` (${source})` : \"\"}:\\n` + issues.map((i) => ` - ${i.path}: ${i.message}`).join(\"\\n\"),\n issues,\n );\n}\n\n/**\n * Resolve the final config: package defaults ← reader.config.ts ← inline overrides.\n * Throws `ReaderConfigError` with readable messages.\n */\nexport function resolveConfig(\n user?: ReaderUserConfig | null,\n inline?: ReaderUserConfig | null,\n opts: { root?: string; source?: string } = {},\n): ResolvedReaderConfig {\n const root = opts.root ?? (typeof process !== \"undefined\" && process.cwd ? process.cwd() : \"/\");\n const reader = mergeConfig<ReaderClientOptions>(\n structuredClone(DEFAULT_CLIENT_OPTIONS),\n user?.reader,\n inline?.reader,\n );\n const content = mergeConfig<ContentConfig>(defaultContentConfig(), user?.content, inline?.content);\n\n const r = clientSchema.safeParse(reader);\n if (!r.success) throw formatIssues(opts.source ?? \"\", \"reader\", r.error);\n const c = contentSchema.safeParse(content);\n if (!c.success) throw formatIssues(opts.source ?? \"\", \"content\", c.error);\n\n return { root, content, reader };\n}\n\n/** Only the serializable, client-safe half. */\nexport function clientOptions(config: ResolvedReaderConfig): ReaderClientOptions {\n return config.reader;\n}\n\nexport const CONFIG_FILE_NAMES = [\"reader.config.ts\", \"reader.config.mts\", \"reader.config.mjs\", \"reader.config.js\"];\n"]}
@@ -0,0 +1,143 @@
1
+ import { S as SanitizeOptions, a as ResolvedReaderConfig, R as ReaderUserConfig } from '../index-Bp5oIiZd.js';
2
+ export { C as ContentConfig, G as GlobLoader, d as defineConfig, g as glob } from '../index-Bp5oIiZd.js';
3
+ import { BookMeta, ChapterMeta, TocEntry } from '../core/index.js';
4
+ import { PluggableList } from 'unified';
5
+ import { ComponentType } from 'react';
6
+ import { BlocksData, BlockInfo } from '../rehype/index.js';
7
+ export { default as rehypeBlocks } from '../rehype/index.js';
8
+ export { h as hashString } from '../blocks-DwR7l7pz.js';
9
+ export { z } from 'zod/v4';
10
+ import 'hast';
11
+ import 'vfile';
12
+
13
+ type ChapterFormat = "md" | "mdx" | "html";
14
+ interface PipelineOptions {
15
+ sanitize?: SanitizeOptions;
16
+ remarkPlugins?: PluggableList;
17
+ rehypePlugins?: PluggableList;
18
+ }
19
+ interface HtmlResult extends BlocksData {
20
+ kind: "html";
21
+ html: string;
22
+ }
23
+ interface MdxCompiled extends BlocksData {
24
+ kind: "mdx";
25
+ /** Compiled function body; run with `runMdx`. Serializable (cacheable). */
26
+ code: string;
27
+ }
28
+ /** Add block ids / heading ids / TOC to already-sanitized HTML. */
29
+ declare function annotateHtml(html: string): Promise<HtmlResult>;
30
+ /** Untrusted HTML string → sanitized, annotated HTML. */
31
+ declare function renderHtml(html: string, opts?: PipelineOptions): Promise<HtmlResult>;
32
+ /**
33
+ * Markdown (GFM, inline HTML allowed) → sanitized, annotated HTML.
34
+ * Inline HTML is parsed, then the whole output goes through DOMPurify.
35
+ */
36
+ declare function renderMarkdown(markdown: string, opts?: PipelineOptions): Promise<HtmlResult>;
37
+ /**
38
+ * Trusted MDX → compiled function body. MDX is code: only compile files you
39
+ * author (e.g. from your repo), never user-supplied input.
40
+ */
41
+ declare function compileMdx(source: string, opts?: PipelineOptions): Promise<MdxCompiled>;
42
+ type MdxComponents = Record<string, ComponentType<Record<string, unknown>>>;
43
+ type MdxContent = ComponentType<{
44
+ components?: MdxComponents;
45
+ }>;
46
+ declare function runMdx(code: string): Promise<MdxContent>;
47
+
48
+ interface ChapterEntry extends ChapterMeta {
49
+ bookId: string;
50
+ file: string;
51
+ format: ChapterFormat;
52
+ /** Validated frontmatter. */
53
+ data: Record<string, unknown>;
54
+ body: string;
55
+ draft: boolean;
56
+ mtimeMs: number;
57
+ }
58
+ interface BookEntry extends BookMeta {
59
+ /** Validated book.json. */
60
+ data: Record<string, unknown>;
61
+ dir: string;
62
+ chapterEntries: ChapterEntry[];
63
+ }
64
+ declare class ContentError extends Error {
65
+ readonly file?: string | undefined;
66
+ constructor(message: string, file?: string | undefined);
67
+ }
68
+ /** Read every book + chapter frontmatter (bodies are compiled lazily). */
69
+ declare function loadBooks(config: ResolvedReaderConfig): Promise<BookEntry[]>;
70
+ declare function compileChapter(entry: ChapterEntry, config: ResolvedReaderConfig): Promise<HtmlResult | MdxCompiled>;
71
+
72
+ /**
73
+ * Sanitize untrusted HTML with DOMPurify (html profile, no scripts, no event
74
+ * handlers, no javascript: URLs, no inline styles, no forms). Iframes are
75
+ * stripped unless their https host is in `allowIframes`. External links opened
76
+ * in a new tab get `rel="noopener noreferrer"`.
77
+ */
78
+ declare function sanitizeHtml(html: string, options?: SanitizeOptions): string;
79
+
80
+ /**
81
+ * `zreader/content` — Astro-style content layer (server/build only).
82
+ *
83
+ * const books = await getBooks();
84
+ * const { chapter } = await getChapter("my-book", "intro");
85
+ * const rendered = await renderChapter(chapter);
86
+ */
87
+
88
+ type RenderedChapter = {
89
+ kind: "html";
90
+ html: string;
91
+ toc: TocEntry[];
92
+ blocks: BlockInfo[];
93
+ contentHash: string;
94
+ } | {
95
+ kind: "mdx";
96
+ Content: MdxContent;
97
+ toc: TocEntry[];
98
+ blocks: BlockInfo[];
99
+ contentHash: string;
100
+ };
101
+ interface ChapterLookup {
102
+ book: BookEntry;
103
+ chapter: ChapterEntry;
104
+ index: number;
105
+ prev: ChapterMeta | null;
106
+ next: ChapterMeta | null;
107
+ }
108
+ declare function globalConfig(): Promise<ResolvedReaderConfig>;
109
+ declare function toBookMeta(book: BookEntry): BookMeta;
110
+ declare const getBooks: () => Promise<BookEntry[]>;
111
+ declare const getBookMetas: () => Promise<BookMeta[]>;
112
+ declare const getBook: (bookId: string) => Promise<BookEntry | null>;
113
+ declare const getChapter: (bookId: string, chapterId: string) => Promise<ChapterLookup | null>;
114
+ declare const renderChapter: (entry: ChapterEntry) => Promise<RenderedChapter>;
115
+ declare const getStaticParams: <B extends string = "book", C extends string = "chapter">(names?: {
116
+ book?: B;
117
+ chapter?: C;
118
+ }) => Promise<Array<Record<B | C, string>>>;
119
+ declare const getReaderConfig: typeof globalConfig;
120
+ type InlineContent = ReaderUserConfig["content"];
121
+ /**
122
+ * Inline form: merge content options on top of the global reader.config.ts.
123
+ *
124
+ * export const handbook = defineBooks({ loader: glob({ base: "./content/handbook" }) });
125
+ * await handbook.getBooks();
126
+ */
127
+ declare function defineBooks(inline?: InlineContent | ResolvedReaderConfig): {
128
+ config: () => Promise<ResolvedReaderConfig>;
129
+ getBooks(): Promise<BookEntry[]>;
130
+ /** Plain, serializable book metadata (safe to pass to client components). */
131
+ getBookMetas(): Promise<BookMeta[]>;
132
+ getBook(bookId: string): Promise<BookEntry | null>;
133
+ getChapter(bookId: string, chapterId: string): Promise<ChapterLookup | null>;
134
+ renderChapter(entry: ChapterEntry): Promise<RenderedChapter>;
135
+ /** For `generateStaticParams`. Param names are configurable. */
136
+ getStaticParams<B extends string = "book", C extends string = "chapter">(names?: {
137
+ book?: B;
138
+ chapter?: C;
139
+ }): Promise<Array<Record<B | C, string>>>;
140
+ };
141
+
142
+ export { BlockInfo, BlocksData, ContentError, ReaderUserConfig, ResolvedReaderConfig, SanitizeOptions, annotateHtml, compileChapter, compileMdx, defineBooks, getBook, getBookMetas, getBooks, getChapter, getReaderConfig, getStaticParams, loadBooks, renderChapter, renderHtml, renderMarkdown, runMdx, sanitizeHtml, toBookMeta };
143
+ export type { BookEntry, ChapterEntry, ChapterFormat, ChapterLookup, HtmlResult, MdxCompiled, MdxComponents, MdxContent, PipelineOptions, RenderedChapter };