zreader 0.0.0-stage → 0.2.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.
- package/CHANGELOG.md +25 -0
- package/LICENSE +21 -0
- package/README.md +467 -2
- package/dist/agent/index.d.ts +90 -0
- package/dist/agent/index.js +293 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/react/index.d.ts +65 -0
- package/dist/agent/react/index.js +286 -0
- package/dist/agent/react/index.js.map +1 -0
- package/dist/blocks-DwR7l7pz.d.ts +20 -0
- package/dist/chunk-3WQBK6DE.js +47 -0
- package/dist/chunk-3WQBK6DE.js.map +1 -0
- package/dist/chunk-DYQNGV46.js +31 -0
- package/dist/chunk-DYQNGV46.js.map +1 -0
- package/dist/chunk-ISI35TCM.js +62 -0
- package/dist/chunk-ISI35TCM.js.map +1 -0
- package/dist/chunk-RNSAFDZ5.js +105 -0
- package/dist/chunk-RNSAFDZ5.js.map +1 -0
- package/dist/config/index.cjs +196 -0
- package/dist/config/index.cjs.map +1 -0
- package/dist/config/index.d.cts +159 -0
- package/dist/config/index.d.ts +159 -0
- package/dist/config/index.js +182 -0
- package/dist/config/index.js.map +1 -0
- package/dist/content/index.d.ts +143 -0
- package/dist/content/index.js +379 -0
- package/dist/content/index.js.map +1 -0
- package/dist/core/index.d.ts +262 -0
- package/dist/core/index.js +935 -0
- package/dist/core/index.js.map +1 -0
- package/dist/editor/index.d.ts +19 -0
- package/dist/editor/index.js +277 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/index-Bp5oIiZd.d.ts +61 -0
- package/dist/next/client/index.d.ts +8 -0
- package/dist/next/client/index.js +13 -0
- package/dist/next/client/index.js.map +1 -0
- package/dist/next/index.cjs +275 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +47 -0
- package/dist/next/index.d.ts +47 -0
- package/dist/next/index.js +265 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/server/index.d.ts +81 -0
- package/dist/next/server/index.js +51 -0
- package/dist/next/server/index.js.map +1 -0
- package/dist/react/index.d.ts +392 -0
- package/dist/react/index.js +2798 -0
- package/dist/react/index.js.map +1 -0
- package/dist/reader.css +116 -0
- package/dist/rehype/index.d.ts +27 -0
- package/dist/rehype/index.js +4 -0
- package/dist/rehype/index.js.map +1 -0
- package/dist/stubs/empty-config.d.ts +9 -0
- package/dist/stubs/empty-config.js +7 -0
- package/dist/stubs/empty-config.js.map +1 -0
- package/dist/stubs/server-only.d.ts +2 -0
- package/dist/stubs/server-only.js +6 -0
- package/dist/stubs/server-only.js.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/tailwind.css +42 -0
- package/dist/types-xkdpkPxA.d.ts +147 -0
- package/dist/user-config/index.d.ts +17 -0
- package/dist/user-config/index.js +35 -0
- package/dist/user-config/index.js.map +1 -0
- package/dist/virtual-config/index.d.ts +6 -0
- package/dist/virtual-config/index.js +10 -0
- package/dist/virtual-config/index.js.map +1 -0
- package/package.json +237 -4
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { cn } from 'cn';
|
|
4
|
+
import { toast } from 'sonner';
|
|
5
|
+
import { LinkIcon, ChevronDownIcon, CopyIcon, FileTextIcon, ExternalLinkIcon } from 'lucide-react';
|
|
6
|
+
import { useReaderChapter, copyText } from 'zreader/react';
|
|
7
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
8
|
+
import { cva } from 'class-variance-authority';
|
|
9
|
+
import { Tooltip as Tooltip$1, Slot, DropdownMenu as DropdownMenu$1 } from 'radix-ui';
|
|
10
|
+
|
|
11
|
+
// src/agent/react/copy-reference.tsx
|
|
12
|
+
function useOptionalReaderChapter() {
|
|
13
|
+
try {
|
|
14
|
+
return useReaderChapter();
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function markdownHref(href) {
|
|
20
|
+
const path = href.split("#")[0].split("?")[0].replace(/\/+$/, "");
|
|
21
|
+
if (!path) return "/index.md";
|
|
22
|
+
return path.endsWith(".md") ? path : `${path}.md`;
|
|
23
|
+
}
|
|
24
|
+
function MarkdownAlternate() {
|
|
25
|
+
const ctx = useOptionalReaderChapter();
|
|
26
|
+
if (!ctx) return null;
|
|
27
|
+
return /* @__PURE__ */ jsx("link", { rel: "alternate", type: "text/markdown", href: markdownHref(ctx.href(ctx.chapter.id)), title: ctx.chapter.title });
|
|
28
|
+
}
|
|
29
|
+
var buttonVariants = cva(
|
|
30
|
+
"inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
31
|
+
{
|
|
32
|
+
variants: {
|
|
33
|
+
variant: {
|
|
34
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
35
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40",
|
|
36
|
+
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
|
37
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
38
|
+
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
39
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
40
|
+
},
|
|
41
|
+
size: {
|
|
42
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
43
|
+
xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
44
|
+
sm: "h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",
|
|
45
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
46
|
+
icon: "size-9",
|
|
47
|
+
"icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
|
|
48
|
+
"icon-sm": "size-8",
|
|
49
|
+
"icon-lg": "size-10"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
defaultVariants: {
|
|
53
|
+
variant: "default",
|
|
54
|
+
size: "default"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
function Button({
|
|
59
|
+
className,
|
|
60
|
+
variant = "default",
|
|
61
|
+
size = "default",
|
|
62
|
+
asChild = false,
|
|
63
|
+
...props
|
|
64
|
+
}) {
|
|
65
|
+
const Comp = asChild ? Slot.Root : "button";
|
|
66
|
+
return /* @__PURE__ */ jsx(
|
|
67
|
+
Comp,
|
|
68
|
+
{
|
|
69
|
+
"data-slot": "button",
|
|
70
|
+
"data-variant": variant,
|
|
71
|
+
"data-size": size,
|
|
72
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
73
|
+
...props
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
function DropdownMenu({
|
|
78
|
+
...props
|
|
79
|
+
}) {
|
|
80
|
+
return /* @__PURE__ */ jsx(DropdownMenu$1.Root, { "data-slot": "dropdown-menu", ...props });
|
|
81
|
+
}
|
|
82
|
+
function DropdownMenuTrigger({
|
|
83
|
+
...props
|
|
84
|
+
}) {
|
|
85
|
+
return /* @__PURE__ */ jsx(
|
|
86
|
+
DropdownMenu$1.Trigger,
|
|
87
|
+
{
|
|
88
|
+
"data-slot": "dropdown-menu-trigger",
|
|
89
|
+
...props
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
function DropdownMenuContent({
|
|
94
|
+
className,
|
|
95
|
+
sideOffset = 4,
|
|
96
|
+
...props
|
|
97
|
+
}) {
|
|
98
|
+
return /* @__PURE__ */ jsx(DropdownMenu$1.Portal, { children: /* @__PURE__ */ jsx(
|
|
99
|
+
DropdownMenu$1.Content,
|
|
100
|
+
{
|
|
101
|
+
"data-slot": "dropdown-menu-content",
|
|
102
|
+
sideOffset,
|
|
103
|
+
className: cn(
|
|
104
|
+
"z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
|
105
|
+
className
|
|
106
|
+
),
|
|
107
|
+
...props
|
|
108
|
+
}
|
|
109
|
+
) });
|
|
110
|
+
}
|
|
111
|
+
function DropdownMenuItem({
|
|
112
|
+
className,
|
|
113
|
+
inset,
|
|
114
|
+
variant = "default",
|
|
115
|
+
...props
|
|
116
|
+
}) {
|
|
117
|
+
return /* @__PURE__ */ jsx(
|
|
118
|
+
DropdownMenu$1.Item,
|
|
119
|
+
{
|
|
120
|
+
"data-slot": "dropdown-menu-item",
|
|
121
|
+
"data-inset": inset,
|
|
122
|
+
"data-variant": variant,
|
|
123
|
+
className: cn(
|
|
124
|
+
"relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",
|
|
125
|
+
className
|
|
126
|
+
),
|
|
127
|
+
...props
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
function DropdownMenuLabel({
|
|
132
|
+
className,
|
|
133
|
+
inset,
|
|
134
|
+
...props
|
|
135
|
+
}) {
|
|
136
|
+
return /* @__PURE__ */ jsx(
|
|
137
|
+
DropdownMenu$1.Label,
|
|
138
|
+
{
|
|
139
|
+
"data-slot": "dropdown-menu-label",
|
|
140
|
+
"data-inset": inset,
|
|
141
|
+
className: cn(
|
|
142
|
+
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
|
143
|
+
className
|
|
144
|
+
),
|
|
145
|
+
...props
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
function DropdownMenuSeparator({
|
|
150
|
+
className,
|
|
151
|
+
...props
|
|
152
|
+
}) {
|
|
153
|
+
return /* @__PURE__ */ jsx(
|
|
154
|
+
DropdownMenu$1.Separator,
|
|
155
|
+
{
|
|
156
|
+
"data-slot": "dropdown-menu-separator",
|
|
157
|
+
className: cn("-mx-1 my-1 h-px bg-border", className),
|
|
158
|
+
...props
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
function Tooltip({
|
|
163
|
+
...props
|
|
164
|
+
}) {
|
|
165
|
+
return /* @__PURE__ */ jsx(Tooltip$1.Root, { "data-slot": "tooltip", ...props });
|
|
166
|
+
}
|
|
167
|
+
function TooltipTrigger({
|
|
168
|
+
...props
|
|
169
|
+
}) {
|
|
170
|
+
return /* @__PURE__ */ jsx(Tooltip$1.Trigger, { "data-slot": "tooltip-trigger", ...props });
|
|
171
|
+
}
|
|
172
|
+
function TooltipContent({
|
|
173
|
+
className,
|
|
174
|
+
sideOffset = 0,
|
|
175
|
+
children,
|
|
176
|
+
...props
|
|
177
|
+
}) {
|
|
178
|
+
return /* @__PURE__ */ jsx(Tooltip$1.Portal, { children: /* @__PURE__ */ jsxs(
|
|
179
|
+
Tooltip$1.Content,
|
|
180
|
+
{
|
|
181
|
+
"data-slot": "tooltip-content",
|
|
182
|
+
sideOffset,
|
|
183
|
+
className: cn(
|
|
184
|
+
"z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",
|
|
185
|
+
className
|
|
186
|
+
),
|
|
187
|
+
...props,
|
|
188
|
+
children: [
|
|
189
|
+
children,
|
|
190
|
+
/* @__PURE__ */ jsx(Tooltip$1.Arrow, { className: "z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground" })
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
) });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/agent/react/reference.ts
|
|
197
|
+
var DEFAULT_PROMPT = "Refer the content at {url}";
|
|
198
|
+
var DEFAULT_ASK_PROMPT = "Read from {url} so I can ask questions about it.";
|
|
199
|
+
var PROVIDERS = {
|
|
200
|
+
chatgpt: { id: "chatgpt", label: "ChatGPT", href: (q) => `https://chatgpt.com/?hints=search&q=${encodeURIComponent(q)}` },
|
|
201
|
+
claude: { id: "claude", label: "Claude", href: (q) => `https://claude.ai/new?q=${encodeURIComponent(q)}` },
|
|
202
|
+
grok: { id: "grok", label: "Grok", href: (q) => `https://grok.com/?q=${encodeURIComponent(q)}` }
|
|
203
|
+
};
|
|
204
|
+
var DEFAULT_PROVIDERS = ["chatgpt", "claude", "grok"];
|
|
205
|
+
function resolveProvider(p) {
|
|
206
|
+
return typeof p === "string" ? PROVIDERS[p] : p;
|
|
207
|
+
}
|
|
208
|
+
function markdownUrl(pageUrl) {
|
|
209
|
+
const url = new URL(pageUrl);
|
|
210
|
+
url.search = "";
|
|
211
|
+
url.hash = "";
|
|
212
|
+
let path = url.pathname.replace(/\/+$/, "");
|
|
213
|
+
if (!path) path = "/index";
|
|
214
|
+
if (!path.endsWith(".md")) path += ".md";
|
|
215
|
+
url.pathname = path;
|
|
216
|
+
return url.href;
|
|
217
|
+
}
|
|
218
|
+
function formatPrompt(template, url) {
|
|
219
|
+
return template.includes("{url}") ? template.replaceAll("{url}", url) : `${template} ${url}`.trim();
|
|
220
|
+
}
|
|
221
|
+
function providerUrl(provider, prompt) {
|
|
222
|
+
return resolveProvider(provider).href(prompt);
|
|
223
|
+
}
|
|
224
|
+
function CopyReference({
|
|
225
|
+
markdown = false,
|
|
226
|
+
prompt = DEFAULT_PROMPT,
|
|
227
|
+
askPrompt = DEFAULT_ASK_PROMPT,
|
|
228
|
+
providers = DEFAULT_PROVIDERS,
|
|
229
|
+
label = "Copy reference",
|
|
230
|
+
className
|
|
231
|
+
}) {
|
|
232
|
+
const ctx = useOptionalReaderChapter();
|
|
233
|
+
const referenceUrl = useCallback(() => {
|
|
234
|
+
const page = ctx ? new URL(ctx.href(ctx.chapter.id), window.location.href).href : window.location.href;
|
|
235
|
+
if (!markdown) return page.split("#")[0];
|
|
236
|
+
return typeof markdown === "function" ? markdown(page) : markdownUrl(page);
|
|
237
|
+
}, [ctx, markdown]);
|
|
238
|
+
const copy = async (text, what) => {
|
|
239
|
+
if (await copyText(text)) toast.success(`${what} copied`, { description: text });
|
|
240
|
+
else toast.error("Could not copy");
|
|
241
|
+
};
|
|
242
|
+
const copyPrompt = () => void copy(formatPrompt(prompt, referenceUrl()), "Reference");
|
|
243
|
+
const copyUrl = () => void copy(referenceUrl(), markdown ? "Markdown URL" : "Link");
|
|
244
|
+
const open = (p) => {
|
|
245
|
+
window.open(p.href(formatPrompt(askPrompt, referenceUrl())), "_blank", "noopener,noreferrer");
|
|
246
|
+
};
|
|
247
|
+
const specs = providers.map(resolveProvider);
|
|
248
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex items-center", className), "data-zr-copy-reference": "", children: [
|
|
249
|
+
/* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
250
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { type: "button", variant: "ghost", size: "icon", "aria-label": label, onClick: copyPrompt, className: "hidden rounded-r-none sm:inline-flex lg:w-auto lg:px-3", children: [
|
|
251
|
+
/* @__PURE__ */ jsx(LinkIcon, {}),
|
|
252
|
+
/* @__PURE__ */ jsx("span", { className: "hidden lg:inline", children: label })
|
|
253
|
+
] }) }),
|
|
254
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: "Copy a prompt that points an AI agent at this page" })
|
|
255
|
+
] }),
|
|
256
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
257
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { type: "button", variant: "ghost", size: "icon", "aria-label": "Reference options", className: "sm:w-6 sm:rounded-l-none", children: [
|
|
258
|
+
/* @__PURE__ */ jsx(LinkIcon, { className: "sm:hidden" }),
|
|
259
|
+
/* @__PURE__ */ jsx(ChevronDownIcon, { className: "hidden sm:block" })
|
|
260
|
+
] }) }),
|
|
261
|
+
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "w-60", children: [
|
|
262
|
+
/* @__PURE__ */ jsxs(DropdownMenuItem, { onSelect: copyPrompt, children: [
|
|
263
|
+
/* @__PURE__ */ jsx(CopyIcon, {}),
|
|
264
|
+
label
|
|
265
|
+
] }),
|
|
266
|
+
/* @__PURE__ */ jsxs(DropdownMenuItem, { onSelect: copyUrl, children: [
|
|
267
|
+
/* @__PURE__ */ jsx(FileTextIcon, {}),
|
|
268
|
+
markdown ? "Copy Markdown URL" : "Copy link"
|
|
269
|
+
] }),
|
|
270
|
+
specs.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
271
|
+
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
272
|
+
/* @__PURE__ */ jsx(DropdownMenuLabel, { className: "text-xs font-normal text-muted-foreground", children: "Ask about this page" }),
|
|
273
|
+
specs.map((p) => /* @__PURE__ */ jsxs(DropdownMenuItem, { onSelect: () => open(p), children: [
|
|
274
|
+
/* @__PURE__ */ jsx(ExternalLinkIcon, {}),
|
|
275
|
+
"Open in ",
|
|
276
|
+
p.label
|
|
277
|
+
] }, p.id))
|
|
278
|
+
] })
|
|
279
|
+
] })
|
|
280
|
+
] })
|
|
281
|
+
] });
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export { CopyReference, DEFAULT_ASK_PROMPT, DEFAULT_PROMPT, DEFAULT_PROVIDERS, MarkdownAlternate, PROVIDERS, formatPrompt, markdownHref, markdownUrl, providerUrl, resolveProvider };
|
|
285
|
+
//# sourceMappingURL=index.js.map
|
|
286
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/agent/react/markdown-alternate.tsx","../../../src/react/components/ui/button.tsx","../../../src/react/components/ui/dropdown-menu.tsx","../../../src/react/components/ui/tooltip.tsx","../../../src/agent/react/reference.ts","../../../src/agent/react/copy-reference.tsx"],"names":["jsx","DropdownMenuPrimitive","cn","TooltipPrimitive","jsxs"],"mappings":";;;;;;;;;;AAEA,SAAS,wBAAA,GAAsD;AAG7D,EAAA,IAAI;AACF,IAAA,OAAO,gBAAA,EAAiB;AAAA,EAC1B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAKO,SAAS,aAAa,IAAA,EAAsB;AACjD,EAAA,MAAM,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,GAAG,EAAE,CAAC,CAAA,CAAG,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,CAAG,OAAA,CAAQ,QAAQ,EAAE,CAAA;AAClE,EAAA,I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AAA,EAAA,EAAoB,KAAA,EAAM,KAAA,EAAM,WAAU,MAAA,EACzC,QAAA,EAAA;AAAA,wBAAAA,IAAAA,CAAC,gBAAA,EAAA,EAAiB,QAAA,EAAU,UAAA,EAC1B,QAAA,EAAA;AAAA,0BAAAJ,IAAC,QAAA,EAAA,EAAS,CAAA;AAAA,UACT;AAAA,SAAA,EACH,CAAA;AAAA,wBACAI,IAAAA,CAAC,gBAAA,EAAA,EAAiB,QAAA,EAAU,OAAA,EAC1B,QAAA,EAAA;AAAA,0BAAAJ,IAAC,YAAA,EAAA,EAAa,CAAA;AAAA,UACb,WAAW,mBAAA,GAAsB;AAAA,SAAA,EACpC,CAAA;AAAA,QACC,KAAA,CAAM,MAAA,GAAS,CAAA,oBACdI,KAAA,QAAA,EAAA,EACE,QAAA,EAAA;AAAA,0BAAAJ,IAAC,qBAAA,EAAA,EAAsB,CAAA;AAAA,0BACvBA,GAAAA,CAAC,iBAAA,EAAA,EAAkB,SAAA,EAAU,6CAA4C,QAAA,EAAA,qBAAA,EAAmB,CAAA;AAAA,UAC3F,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,qBACVI,IAAAA,CAAC,gBAAA,EAAA,EAA4B,QAAA,EAAU,MAAM,IAAA,CAAK,CAAC,CAAA,EACjD,QAAA,EAAA;AAAA,4BAAAJ,IAAC,gBAAA,EAAA,EAAiB,CAAA;AAAA,YAAE,UAAA;AAAA,YACX,CAAA,CAAE;AAAA,WAAA,EAAA,EAFU,CAAA,CAAE,EAGzB,CACD;AAAA,SAAA,EACH;AAAA,OAAA,EAEJ;AAAA,KAAA,EACF;AAAA,GAAA,EACF,CAAA;AAEJ","file":"index.js","sourcesContent":["import { useReaderChapter, type ReaderChapterValue } from \"zreader/react\";\n\nfunction useOptionalReaderChapter(): ReaderChapterValue | null {\n // useReaderChapter() reads a context and throws outside <Reader>; the hook\n // itself is always called, so this keeps hook order stable.\n try {\n return useReaderChapter();\n } catch {\n return null;\n }\n}\n\nexport { useOptionalReaderChapter };\n\n/** `.md` twin of a reader href (relative or absolute): drops the hash/query, appends `.md`. */\nexport function markdownHref(href: string): string {\n const path = href.split(\"#\")[0]!.split(\"?\")[0]!.replace(/\\/+$/, \"\");\n if (!path) return \"/index.md\";\n return path.endsWith(\".md\") ? path : `${path}.md`;\n}\n\n/**\n * `<link rel=\"alternate\" type=\"text/markdown\">` for the current chapter, so\n * agents and crawlers can find its Markdown twin. React 19 hoists it into\n * <head>. Renders nothing outside <Reader>.\n */\nexport function MarkdownAlternate() {\n const ctx = useOptionalReaderChapter();\n if (!ctx) return null;\n return <link rel=\"alternate\" type=\"text/markdown\" href={markdownHref(ctx.href(ctx.chapter.id))} title={ctx.chapter.title} />;\n}\n","import * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { cn } from \"cn\"\nimport { Slot } from \"radix-ui\"\n\nconst buttonVariants = cva(\n \"inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n {\n variants: {\n variant: {\n default: \"bg-primary text-primary-foreground hover:bg-primary/90\",\n destructive:\n \"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40\",\n outline:\n \"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50\",\n secondary:\n \"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\n ghost:\n \"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50\",\n link: \"text-primary underline-offset-4 hover:underline\",\n },\n size: {\n default: \"h-9 px-4 py-2 has-[>svg]:px-3\",\n xs: \"h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3\",\n sm: \"h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5\",\n lg: \"h-10 rounded-md px-6 has-[>svg]:px-4\",\n icon: \"size-9\",\n \"icon-xs\": \"size-6 rounded-md [&_svg:not([class*='size-'])]:size-3\",\n \"icon-sm\": \"size-8\",\n \"icon-lg\": \"size-10\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n size: \"default\",\n },\n }\n)\n\nfunction Button({\n className,\n variant = \"default\",\n size = \"default\",\n asChild = false,\n ...props\n}: React.ComponentProps<\"button\"> &\n VariantProps<typeof buttonVariants> & {\n asChild?: boolean\n }) {\n const Comp = asChild ? Slot.Root : \"button\"\n\n return (\n <Comp\n data-slot=\"button\"\n data-variant={variant}\n data-size={size}\n className={cn(buttonVariants({ variant, size, className }))}\n {...props}\n />\n )\n}\n\nexport { Button, buttonVariants }\n","\"use client\"\n\nimport * as React from \"react\"\nimport { cn } from \"cn\"\nimport { CheckIcon, ChevronRightIcon, CircleIcon } from \"lucide-react\"\nimport { DropdownMenu as DropdownMenuPrimitive } from \"radix-ui\"\n\nfunction DropdownMenu({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {\n return <DropdownMenuPrimitive.Root data-slot=\"dropdown-menu\" {...props} />\n}\n\nfunction DropdownMenuPortal({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {\n return (\n <DropdownMenuPrimitive.Portal data-slot=\"dropdown-menu-portal\" {...props} />\n )\n}\n\nfunction DropdownMenuTrigger({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {\n return (\n <DropdownMenuPrimitive.Trigger\n data-slot=\"dropdown-menu-trigger\"\n {...props}\n />\n )\n}\n\nfunction DropdownMenuContent({\n className,\n sideOffset = 4,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {\n return (\n <DropdownMenuPrimitive.Portal>\n <DropdownMenuPrimitive.Content\n data-slot=\"dropdown-menu-content\"\n sideOffset={sideOffset}\n className={cn(\n \"z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95\",\n className\n )}\n {...props}\n />\n </DropdownMenuPrimitive.Portal>\n )\n}\n\nfunction DropdownMenuGroup({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {\n return (\n <DropdownMenuPrimitive.Group data-slot=\"dropdown-menu-group\" {...props} />\n )\n}\n\nfunction DropdownMenuItem({\n className,\n inset,\n variant = \"default\",\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {\n inset?: boolean\n variant?: \"default\" | \"destructive\"\n}) {\n return (\n <DropdownMenuPrimitive.Item\n data-slot=\"dropdown-menu-item\"\n data-inset={inset}\n data-variant={variant}\n className={cn(\n \"relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!\",\n className\n )}\n {...props}\n />\n )\n}\n\nfunction DropdownMenuCheckboxItem({\n className,\n children,\n checked,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {\n return (\n <DropdownMenuPrimitive.CheckboxItem\n data-slot=\"dropdown-menu-checkbox-item\"\n className={cn(\n \"relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n className\n )}\n checked={checked}\n {...props}\n >\n <span className=\"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center\">\n <DropdownMenuPrimitive.ItemIndicator>\n <CheckIcon className=\"size-4\" />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n {children}\n </DropdownMenuPrimitive.CheckboxItem>\n )\n}\n\nfunction DropdownMenuRadioGroup({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {\n return (\n <DropdownMenuPrimitive.RadioGroup\n data-slot=\"dropdown-menu-radio-group\"\n {...props}\n />\n )\n}\n\nfunction DropdownMenuRadioItem({\n className,\n children,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {\n return (\n <DropdownMenuPrimitive.RadioItem\n data-slot=\"dropdown-menu-radio-item\"\n className={cn(\n \"relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n className\n )}\n {...props}\n >\n <span className=\"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center\">\n <DropdownMenuPrimitive.ItemIndicator>\n <CircleIcon className=\"size-2 fill-current\" />\n </DropdownMenuPrimitive.ItemIndicator>\n </span>\n {children}\n </DropdownMenuPrimitive.RadioItem>\n )\n}\n\nfunction DropdownMenuLabel({\n className,\n inset,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {\n inset?: boolean\n}) {\n return (\n <DropdownMenuPrimitive.Label\n data-slot=\"dropdown-menu-label\"\n data-inset={inset}\n className={cn(\n \"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8\",\n className\n )}\n {...props}\n />\n )\n}\n\nfunction DropdownMenuSeparator({\n className,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {\n return (\n <DropdownMenuPrimitive.Separator\n data-slot=\"dropdown-menu-separator\"\n className={cn(\"-mx-1 my-1 h-px bg-border\", className)}\n {...props}\n />\n )\n}\n\nfunction DropdownMenuShortcut({\n className,\n ...props\n}: React.ComponentProps<\"span\">) {\n return (\n <span\n data-slot=\"dropdown-menu-shortcut\"\n className={cn(\n \"ml-auto text-xs tracking-widest text-muted-foreground\",\n className\n )}\n {...props}\n />\n )\n}\n\nfunction DropdownMenuSub({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {\n return <DropdownMenuPrimitive.Sub data-slot=\"dropdown-menu-sub\" {...props} />\n}\n\nfunction DropdownMenuSubTrigger({\n className,\n inset,\n children,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {\n inset?: boolean\n}) {\n return (\n <DropdownMenuPrimitive.SubTrigger\n data-slot=\"dropdown-menu-sub-trigger\"\n data-inset={inset}\n className={cn(\n \"flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[inset]:pl-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground\",\n className\n )}\n {...props}\n >\n {children}\n <ChevronRightIcon className=\"ml-auto size-4\" />\n </DropdownMenuPrimitive.SubTrigger>\n )\n}\n\nfunction DropdownMenuSubContent({\n className,\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {\n return (\n <DropdownMenuPrimitive.SubContent\n data-slot=\"dropdown-menu-sub-content\"\n className={cn(\n \"z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95\",\n className\n )}\n {...props}\n />\n )\n}\n\nexport {\n DropdownMenu,\n DropdownMenuPortal,\n DropdownMenuTrigger,\n DropdownMenuContent,\n DropdownMenuGroup,\n DropdownMenuLabel,\n DropdownMenuItem,\n DropdownMenuCheckboxItem,\n DropdownMenuRadioGroup,\n DropdownMenuRadioItem,\n DropdownMenuSeparator,\n DropdownMenuShortcut,\n DropdownMenuSub,\n DropdownMenuSubTrigger,\n DropdownMenuSubContent,\n}\n","import * as React from \"react\"\nimport { cn } from \"cn\"\nimport { Tooltip as TooltipPrimitive } from \"radix-ui\"\n\nfunction TooltipProvider({\n delayDuration = 0,\n ...props\n}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {\n return (\n <TooltipPrimitive.Provider\n data-slot=\"tooltip-provider\"\n delayDuration={delayDuration}\n {...props}\n />\n )\n}\n\nfunction Tooltip({\n ...props\n}: React.ComponentProps<typeof TooltipPrimitive.Root>) {\n return <TooltipPrimitive.Root data-slot=\"tooltip\" {...props} />\n}\n\nfunction TooltipTrigger({\n ...props\n}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {\n return <TooltipPrimitive.Trigger data-slot=\"tooltip-trigger\" {...props} />\n}\n\nfunction TooltipContent({\n className,\n sideOffset = 0,\n children,\n ...props\n}: React.ComponentProps<typeof TooltipPrimitive.Content>) {\n return (\n <TooltipPrimitive.Portal>\n <TooltipPrimitive.Content\n data-slot=\"tooltip-content\"\n sideOffset={sideOffset}\n className={cn(\n \"z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95\",\n className\n )}\n {...props}\n >\n {children}\n <TooltipPrimitive.Arrow className=\"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground\" />\n </TooltipPrimitive.Content>\n </TooltipPrimitive.Portal>\n )\n}\n\nexport { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }\n","/**\n * Pure helpers for building agent references (no DOM, no React).\n */\n\nexport type BuiltInProvider = \"chatgpt\" | \"claude\" | \"grok\";\n\nexport interface ProviderSpec {\n id: string;\n label: string;\n /** URL that opens the assistant with `prompt` pre-filled. */\n href(prompt: string): string;\n}\n\nexport const DEFAULT_PROMPT = \"Refer the content at {url}\";\nexport const DEFAULT_ASK_PROMPT = \"Read from {url} so I can ask questions about it.\";\n\nexport const PROVIDERS: Record<BuiltInProvider, ProviderSpec> = {\n chatgpt: { id: \"chatgpt\", label: \"ChatGPT\", href: (q) => `https://chatgpt.com/?hints=search&q=${encodeURIComponent(q)}` },\n claude: { id: \"claude\", label: \"Claude\", href: (q) => `https://claude.ai/new?q=${encodeURIComponent(q)}` },\n grok: { id: \"grok\", label: \"Grok\", href: (q) => `https://grok.com/?q=${encodeURIComponent(q)}` },\n};\n\nexport const DEFAULT_PROVIDERS: BuiltInProvider[] = [\"chatgpt\", \"claude\", \"grok\"];\n\nexport function resolveProvider(p: BuiltInProvider | ProviderSpec): ProviderSpec {\n return typeof p === \"string\" ? PROVIDERS[p] : p;\n}\n\n/**\n * The `.md` twin of a page URL: drops the query and hash and any trailing\n * slash, then appends `.md` (`/` becomes `/index.md`).\n */\nexport function markdownUrl(pageUrl: string): string {\n const url = new URL(pageUrl);\n url.search = \"\";\n url.hash = \"\";\n let path = url.pathname.replace(/\\/+$/, \"\");\n if (!path) path = \"/index\";\n if (!path.endsWith(\".md\")) path += \".md\";\n url.pathname = path;\n return url.href;\n}\n\n/** Fill `{url}` in a prompt template (appends the URL when there is no placeholder). */\nexport function formatPrompt(template: string, url: string): string {\n return template.includes(\"{url}\") ? template.replaceAll(\"{url}\", url) : `${template} ${url}`.trim();\n}\n\n/** URL that opens an assistant with the prompt pre-filled. */\nexport function providerUrl(provider: BuiltInProvider | ProviderSpec, prompt: string): string {\n return resolveProvider(provider).href(prompt);\n}\n","import { useCallback } from \"react\";\nimport { cn } from \"cn\";\nimport { toast } from \"sonner\";\nimport { ChevronDownIcon, CopyIcon, ExternalLinkIcon, FileTextIcon, LinkIcon } from \"lucide-react\";\nimport { copyText } from \"zreader/react\";\nimport { useOptionalReaderChapter } from \"./markdown-alternate\";\nimport { Button } from \"@/components/ui/button\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuLabel,\n DropdownMenuSeparator,\n DropdownMenuTrigger,\n} from \"@/components/ui/dropdown-menu\";\nimport { Tooltip, TooltipContent, TooltipTrigger } from \"@/components/ui/tooltip\";\nimport {\n DEFAULT_ASK_PROMPT,\n DEFAULT_PROMPT,\n DEFAULT_PROVIDERS,\n formatPrompt,\n markdownUrl,\n resolveProvider,\n type BuiltInProvider,\n type ProviderSpec,\n} from \"./reference\";\n\nexport interface CopyReferenceProps {\n /**\n * Reference the page's `.md` twin (served by `createAgentHandler()` from\n * `zreader/agent`). `false` (default) references the page URL itself, so the\n * button never points at a route your app doesn't serve. Pass a function to\n * map page URLs to Markdown URLs yourself (e.g. for hash routing).\n */\n markdown?: boolean | ((pageUrl: string) => string);\n /** Copied text. `{url}` is replaced with the reference URL. */\n prompt?: string;\n /** Prompt sent to the assistants in the menu. */\n askPrompt?: string;\n /** Assistants offered in the menu, in order. `[]` hides them. */\n providers?: Array<BuiltInProvider | ProviderSpec>;\n /** Button text from the `lg` breakpoint up (icon-only below). */\n label?: string;\n className?: string;\n}\n\n/**\n * \"Copy reference\" split button for the reader's top bar: copies a prompt that\n * points an AI agent at this chapter, with a menu to open it in ChatGPT,\n * Claude or Grok.\n *\n * <Reader … actions={<CopyReference markdown />} />\n */\nexport function CopyReference({\n markdown = false,\n prompt = DEFAULT_PROMPT,\n askPrompt = DEFAULT_ASK_PROMPT,\n providers = DEFAULT_PROVIDERS,\n label = \"Copy reference\",\n className,\n}: CopyReferenceProps) {\n const ctx = useOptionalReaderChapter();\n\n // Built on click (not render), so SSR and hydration never see `window`.\n const referenceUrl = useCallback(() => {\n const page = ctx ? new URL(ctx.href(ctx.chapter.id), window.location.href).href : window.location.href;\n if (!markdown) return page.split(\"#\")[0]!;\n return typeof markdown === \"function\" ? markdown(page) : markdownUrl(page);\n }, [ctx, markdown]);\n\n const copy = async (text: string, what: string) => {\n if (await copyText(text)) toast.success(`${what} copied`, { description: text });\n else toast.error(\"Could not copy\");\n };\n const copyPrompt = () => void copy(formatPrompt(prompt, referenceUrl()), \"Reference\");\n const copyUrl = () => void copy(referenceUrl(), markdown ? \"Markdown URL\" : \"Link\");\n const open = (p: ProviderSpec) => {\n window.open(p.href(formatPrompt(askPrompt, referenceUrl())), \"_blank\", \"noopener,noreferrer\");\n };\n const specs = providers.map(resolveProvider);\n\n return (\n <div className={cn(\"flex items-center\", className)} data-zr-copy-reference=\"\">\n <Tooltip>\n <TooltipTrigger asChild>\n <Button type=\"button\" variant=\"ghost\" size=\"icon\" aria-label={label} onClick={copyPrompt} className=\"hidden rounded-r-none sm:inline-flex lg:w-auto lg:px-3\">\n <LinkIcon />\n <span className=\"hidden lg:inline\">{label}</span>\n </Button>\n </TooltipTrigger>\n <TooltipContent>Copy a prompt that points an AI agent at this page</TooltipContent>\n </Tooltip>\n <DropdownMenu>\n <DropdownMenuTrigger asChild>\n <Button type=\"button\" variant=\"ghost\" size=\"icon\" aria-label=\"Reference options\" className=\"sm:w-6 sm:rounded-l-none\">\n <LinkIcon className=\"sm:hidden\" />\n <ChevronDownIcon className=\"hidden sm:block\" />\n </Button>\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\" className=\"w-60\">\n <DropdownMenuItem onSelect={copyPrompt}>\n <CopyIcon />\n {label}\n </DropdownMenuItem>\n <DropdownMenuItem onSelect={copyUrl}>\n <FileTextIcon />\n {markdown ? \"Copy Markdown URL\" : \"Copy link\"}\n </DropdownMenuItem>\n {specs.length > 0 && (\n <>\n <DropdownMenuSeparator />\n <DropdownMenuLabel className=\"text-xs font-normal text-muted-foreground\">Ask about this page</DropdownMenuLabel>\n {specs.map((p) => (\n <DropdownMenuItem key={p.id} onSelect={() => open(p)}>\n <ExternalLinkIcon />\n Open in {p.label}\n </DropdownMenuItem>\n ))}\n </>\n )}\n </DropdownMenuContent>\n </DropdownMenu>\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare const BLOCK_TAG_NAMES: readonly ["p", "h1", "h2", "h3", "h4", "h5", "h6", "li", "blockquote", "pre", "figcaption", "td", "th", "dt", "dd"];
|
|
2
|
+
declare const BLOCK_TAGS: ReadonlySet<string>;
|
|
3
|
+
/** Collapse whitespace the same way on the server (hast) and in the DOM. */
|
|
4
|
+
declare function normalizeBlockText(text: string): string;
|
|
5
|
+
/** Hex digest of `text`, `length` characters long (up to 26). */
|
|
6
|
+
declare function hashString(text: string, length?: number): string;
|
|
7
|
+
/**
|
|
8
|
+
* Allocates content-derived block ids (`p-3fa9c1`) for one chapter. Inserting a
|
|
9
|
+
* paragraph doesn't shift other blocks' ids; repeated text gets `-2`, `-3`…
|
|
10
|
+
*/
|
|
11
|
+
declare function createBlockIdAllocator(): (tag: string, text: string) => string;
|
|
12
|
+
/** GitHub-style heading slugs, unique within one chapter. */
|
|
13
|
+
declare function createSlugger(): {
|
|
14
|
+
/** Slug for a heading's text. */
|
|
15
|
+
slug: (text: string) => string;
|
|
16
|
+
/** Keep an author-supplied id (made unique). */
|
|
17
|
+
keep: (id: string) => string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { BLOCK_TAGS as B, BLOCK_TAG_NAMES as a, createSlugger as b, createBlockIdAllocator as c, hashString as h, normalizeBlockText as n };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createSlugger, createBlockIdAllocator, BLOCK_TAGS, normalizeBlockText, hashString } from './chunk-ISI35TCM.js';
|
|
2
|
+
import { toString } from 'hast-util-to-string';
|
|
3
|
+
import { visit } from 'unist-util-visit';
|
|
4
|
+
|
|
5
|
+
var HEADING = /^h([1-6])$/;
|
|
6
|
+
function containsBlock(node) {
|
|
7
|
+
for (const child of node.children) {
|
|
8
|
+
if (child.type === "element" && (BLOCK_TAGS.has(child.tagName) || containsBlock(child))) return true;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
function rehypeBlocks(options = {}) {
|
|
13
|
+
const [minDepth, maxDepth] = options.tocDepth ?? [2, 3];
|
|
14
|
+
return (tree, file) => {
|
|
15
|
+
const slugger = createSlugger();
|
|
16
|
+
const allocate = createBlockIdAllocator();
|
|
17
|
+
const toc = [];
|
|
18
|
+
const blocks = [];
|
|
19
|
+
const texts = [];
|
|
20
|
+
visit(tree, "element", (node) => {
|
|
21
|
+
if (!BLOCK_TAGS.has(node.tagName)) return;
|
|
22
|
+
const text = normalizeBlockText(toString(node));
|
|
23
|
+
const heading = HEADING.exec(node.tagName);
|
|
24
|
+
node.properties ??= {};
|
|
25
|
+
if (heading) {
|
|
26
|
+
const existing = typeof node.properties.id === "string" ? node.properties.id : "";
|
|
27
|
+
const id2 = existing ? slugger.keep(existing) : slugger.slug(text);
|
|
28
|
+
node.properties.id = id2;
|
|
29
|
+
const depth = Number(heading[1]);
|
|
30
|
+
if (depth >= minDepth && depth <= maxDepth && text) toc.push({ id: id2, depth, text });
|
|
31
|
+
}
|
|
32
|
+
if (containsBlock(node)) return;
|
|
33
|
+
if (!text) return;
|
|
34
|
+
const id = allocate(node.tagName, text);
|
|
35
|
+
node.properties.dataBlockId = id;
|
|
36
|
+
blocks.push({ id, tag: node.tagName, excerpt: text.slice(0, 80) });
|
|
37
|
+
texts.push(text);
|
|
38
|
+
});
|
|
39
|
+
const data = { toc, blocks, contentHash: hashString(texts.join("\n")) };
|
|
40
|
+
file.data.reader = data;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
var rehype_default = rehypeBlocks;
|
|
44
|
+
|
|
45
|
+
export { rehypeBlocks, rehype_default };
|
|
46
|
+
//# sourceMappingURL=chunk-3WQBK6DE.js.map
|
|
47
|
+
//# sourceMappingURL=chunk-3WQBK6DE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rehype/index.ts"],"names":["id"],"mappings":";;;;AAiBA,IAAM,OAAA,GAAU,YAAA;AAehB,SAAS,cAAc,IAAA,EAAwB;AAC7C,EAAA,KAAA,MAAW,KAAA,IAAS,KAAK,QAAA,EAAU;AACjC,IAAA,IAAI,KAAA,CAAM,IAAA,KAAS,SAAA,KAAc,UAAA,CAAW,GAAA,CAAI,KAAA,CAAM,OAAO,CAAA,IAAK,aAAA,CAAc,KAAK,CAAA,CAAA,EAAI,OAAO,IAAA;AAAA,EAClG;AACA,EAAA,OAAO,KAAA;AACT;AAWO,SAAS,YAAA,CAAa,OAAA,GAA+B,EAAC,EAAG;AAC9D,EAAA,MAAM,CAAC,UAAU,QAAQ,CAAA,GAAI,QAAQ,QAAA,IAAY,CAAC,GAAG,CAAC,CAAA;AACtD,EAAA,OAAO,CAAC,MAAY,IAAA,KAAgB;AAClC,IAAA,MAAM,UAAU,aAAA,EAAc;AAC9B,IAAA,MAAM,WAAW,sBAAA,EAAuB;AACxC,IAAA,MAAM,MAAkB,EAAC;AACzB,IAAA,MAAM,SAAsB,EAAC;AAC7B,IAA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S,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,EAAG,CAAA;AACjE,MAAA,KAAA,CAAM,KAAK,IAAI,CAAA;AAAA,IACjB,CAAC,CAAA;AAED,IAAA,MAAM,IAAA,GAAmB,EAAE,GAAA,EAAK,MAAA,EAAQ,WAAA,EAAa,WAAW,KAAA,CAAM,IAAA,CAAK,IAAI,CAAC,CAAA,EAAE;AAClF,IAAC,IAAA,CAAK,KAAiC,MAAA,GAAS,IAAA;AAAA,EAClD,CAAA;AACF;AAEA,IAAO,cAAA,GAAQ","file":"chunk-3WQBK6DE.js","sourcesContent":["/**\n * `zreader/rehype` — the block-id plugin for any MDX/Markdown\n * pipeline (Vite's @mdx-js/rollup, @next/mdx, unified…). Runs anywhere: no Node APIs.\n *\n * // vite.config.ts\n * mdx({ rehypePlugins: [rehypeBlocks] })\n *\n * Without it, <Reader> assigns the same ids in the browser; with it, they are in\n * the HTML from the start.\n */\nimport { toString } from \"hast-util-to-string\";\nimport type { Element, Root } from \"hast\";\nimport { visit } from \"unist-util-visit\";\nimport type { VFile } from \"vfile\";\nimport { BLOCK_TAGS, createBlockIdAllocator, createSlugger, hashString, normalizeBlockText } from \"../core/blocks\";\nimport type { TocEntry } from \"../core/types\";\n\nconst HEADING = /^h([1-6])$/;\n\nexport interface BlockInfo {\n id: string;\n tag: string;\n /** First 80 chars, for bookmarks/progress UIs. */\n excerpt: string;\n}\n\nexport interface BlocksData {\n toc: TocEntry[];\n blocks: BlockInfo[];\n contentHash: string;\n}\n\nfunction containsBlock(node: Element): boolean {\n for (const child of node.children) {\n if (child.type === \"element\" && (BLOCK_TAGS.has(child.tagName) || containsBlock(child))) return true;\n }\n return false;\n}\n\nexport interface RehypeBlocksOptions {\n /** Heading depths included in the TOC. Default: 2–3 (h1 is the chapter title). */\n tocDepth?: [min: number, max: number];\n}\n\n/**\n * Adds stable `data-block-id` attributes to leaf blocks, slug `id`s to headings,\n * and collects `{ toc, blocks, contentHash }` into `file.data.reader`.\n */\nexport function rehypeBlocks(options: RehypeBlocksOptions = {}) {\n const [minDepth, maxDepth] = options.tocDepth ?? [2, 3];\n return (tree: Root, file: VFile) => {\n const slugger = createSlugger();\n const allocate = createBlockIdAllocator();\n const toc: TocEntry[] = [];\n const blocks: BlockInfo[] = [];\n const texts: string[] = [];\n\n visit(tree, \"element\", (node: Element) => {\n if (!BLOCK_TAGS.has(node.tagName)) return;\n const text = normalizeBlockText(toString(node));\n const heading = HEADING.exec(node.tagName);\n node.properties ??= {};\n\n if (heading) {\n const existing = typeof node.properties.id === \"string\" ? node.properties.id : \"\";\n const id = existing ? slugger.keep(existing) : slugger.slug(text);\n node.properties.id = id;\n const depth = Number(heading[1]);\n if (depth >= minDepth && depth <= maxDepth && text) toc.push({ id, depth, text });\n }\n\n if (containsBlock(node)) return; // only innermost blocks are anchors\n if (!text) return;\n const id = allocate(node.tagName, text);\n node.properties.dataBlockId = id;\n blocks.push({ id, tag: node.tagName, excerpt: text.slice(0, 80) });\n texts.push(text);\n });\n\n const data: BlocksData = { toc, blocks, contentHash: hashString(texts.join(\"\\n\")) };\n (file.data as { reader?: BlocksData }).reader = data;\n };\n}\n\nexport default rehypeBlocks;\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/core/types.ts
|
|
2
|
+
var THEMES = ["system", "light", "sepia", "dark"];
|
|
3
|
+
var TEXT_SIZES = ["sm", "base", "lg", "xl", "2xl"];
|
|
4
|
+
var LEADINGS = ["tight", "normal", "relaxed"];
|
|
5
|
+
var MEASURES = ["narrow", "normal", "wide"];
|
|
6
|
+
var FONT_FAMILIES = ["serif", "sans", "mono"];
|
|
7
|
+
var HIGHLIGHT_COLORS = ["yellow", "green", "blue", "pink", "purple", "orange"];
|
|
8
|
+
|
|
9
|
+
// src/core/defaults.ts
|
|
10
|
+
var DEFAULT_CLIENT_OPTIONS = {
|
|
11
|
+
storagePrefix: "zr",
|
|
12
|
+
highlightColors: ["yellow", "green", "blue", "pink"],
|
|
13
|
+
defaultHighlightColor: "yellow",
|
|
14
|
+
scratchpad: { enabled: true, scopes: ["chapter", "book", "global"] },
|
|
15
|
+
themes: ["system", "light", "sepia", "dark"],
|
|
16
|
+
defaultTheme: "system",
|
|
17
|
+
defaultSettings: {
|
|
18
|
+
textSize: "lg",
|
|
19
|
+
leading: "relaxed",
|
|
20
|
+
measure: "normal",
|
|
21
|
+
fontFamily: "serif",
|
|
22
|
+
highlightMode: false
|
|
23
|
+
},
|
|
24
|
+
progress: { completeAt: 0.9, saveIntervalMs: 1e3 },
|
|
25
|
+
backupReminder: true,
|
|
26
|
+
basePath: "/books"
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { DEFAULT_CLIENT_OPTIONS, FONT_FAMILIES, HIGHLIGHT_COLORS, LEADINGS, MEASURES, TEXT_SIZES, THEMES };
|
|
30
|
+
//# sourceMappingURL=chunk-DYQNGV46.js.map
|
|
31
|
+
//# sourceMappingURL=chunk-DYQNGV46.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/types.ts","../src/core/defaults.ts"],"names":[],"mappings":";AAgFO,IAAM,MAAA,GAAS,CAAC,QAAA,EAAU,OAAA,EAAS,SAAS,MAAM;AAClD,IAAM,aAAa,CAAC,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,MAAM,KAAK;AACnD,IAAM,QAAA,GAAW,CAAC,OAAA,EAAS,QAAA,EAAU,SAAS;AAC9C,IAAM,QAAA,GAAW,CAAC,QAAA,EAAU,QAAA,EAAU,MAAM;AAC5C,IAAM,aAAA,GAAgB,CAAC,OAAA,EAAS,MAAA,EAAQ,MAAM;AAE9C,IAAM,mBAAmB,CAAC,QAAA,EAAU,SAAS,MAAA,EAAQ,MAAA,EAAQ,UAAU,QAAQ;;;ACpF/E,IAAM,sBAAA,GAA8C;AAAA,EACzD,aAAA,EAAe,IAAA;AAAA,EACf,eAAA,EAAiB,CAAC,QAAA,EAAU,OAAA,EAAS,QAAQ,MAAM,CAAA;AAAA,EACnD,qBAAA,EAAuB,QAAA;AAAA,EACvB,UAAA,EAAY,EAAE,OAAA,EAAS,IAAA,EAAM,QAAQ,CAAC,SAAA,EAAW,MAAA,EAAQ,QAAQ,CAAA,EAAE;AAAA,EACnE,MAAA,EAAQ,CAAC,QAAA,EAAU,OAAA,EAAS,SAAS,MAAM,CAAA;AAAA,EAC3C,YAAA,EAAc,QAAA;AAAA,EACd,eAAA,EAAiB;AAAA,IACf,QAAA,EAAU,IAAA;AAAA,IACV,OAAA,EAAS,SAAA;AAAA,IACT,OAAA,EAAS,QAAA;AAAA,IACT,UAAA,EAAY,OAAA;AAAA,IACZ,aAAA,EAAe;AAAA,GACjB;AAAA,EACA,QAAA,EAAU,EAAE,UAAA,EAAY,GAAA,EAAK,gBAAgB,GAAA,EAAK;AAAA,EAClD,cAAA,EAAgB,IAAA;AAAA,EAChB,QAAA,EAAU;AACZ","file":"chunk-DYQNGV46.js","sourcesContent":["/** 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 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"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import GithubSlugger from 'github-slugger';
|
|
2
|
+
|
|
3
|
+
// src/core/blocks.ts
|
|
4
|
+
var BLOCK_TAG_NAMES = [
|
|
5
|
+
"p",
|
|
6
|
+
"h1",
|
|
7
|
+
"h2",
|
|
8
|
+
"h3",
|
|
9
|
+
"h4",
|
|
10
|
+
"h5",
|
|
11
|
+
"h6",
|
|
12
|
+
"li",
|
|
13
|
+
"blockquote",
|
|
14
|
+
"pre",
|
|
15
|
+
"figcaption",
|
|
16
|
+
"td",
|
|
17
|
+
"th",
|
|
18
|
+
"dt",
|
|
19
|
+
"dd"
|
|
20
|
+
];
|
|
21
|
+
var BLOCK_TAGS = new Set(BLOCK_TAG_NAMES);
|
|
22
|
+
function normalizeBlockText(text) {
|
|
23
|
+
return text.replace(/\s+/g, " ").trim();
|
|
24
|
+
}
|
|
25
|
+
function cyrb53(str, seed = 0) {
|
|
26
|
+
let h1 = 3735928559 ^ seed;
|
|
27
|
+
let h2 = 1103547991 ^ seed;
|
|
28
|
+
for (let i = 0; i < str.length; i++) {
|
|
29
|
+
const ch = str.charCodeAt(i);
|
|
30
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
31
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
32
|
+
}
|
|
33
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
34
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
35
|
+
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
36
|
+
}
|
|
37
|
+
function hashString(text, length = 16) {
|
|
38
|
+
const hex = cyrb53(text, 0).toString(16).padStart(14, "0") + cyrb53(text, 2654435769).toString(16).padStart(14, "0");
|
|
39
|
+
return hex.slice(0, length);
|
|
40
|
+
}
|
|
41
|
+
function createBlockIdAllocator() {
|
|
42
|
+
const seen = /* @__PURE__ */ new Map();
|
|
43
|
+
return (tag, text) => {
|
|
44
|
+
const base = `${tag.toLowerCase()}-${hashString(normalizeBlockText(text), 6)}`;
|
|
45
|
+
const n = (seen.get(base) ?? 0) + 1;
|
|
46
|
+
seen.set(base, n);
|
|
47
|
+
return n === 1 ? base : `${base}-${n}`;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function createSlugger() {
|
|
51
|
+
const slugger = new GithubSlugger();
|
|
52
|
+
return {
|
|
53
|
+
/** Slug for a heading's text. */
|
|
54
|
+
slug: (text) => slugger.slug(text || "section"),
|
|
55
|
+
/** Keep an author-supplied id (made unique). */
|
|
56
|
+
keep: (id) => slugger.slug(id, true)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { BLOCK_TAGS, BLOCK_TAG_NAMES, createBlockIdAllocator, createSlugger, hashString, normalizeBlockText };
|
|
61
|
+
//# sourceMappingURL=chunk-ISI35TCM.js.map
|
|
62
|
+
//# sourceMappingURL=chunk-ISI35TCM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/blocks.ts"],"names":[],"mappings":";;;AAOO,IAAM,eAAA,GAAkB;AAAA,EAC7B,GAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,YAAA;AAAA,EACA,KAAA;AAAA,EACA,YAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF;AAEO,IAAM,UAAA,GAAkC,IAAI,GAAA,CAAI,eAAe;AAG/D,SAAS,mBAAmB,IAAA,EAAsB;AACvD,EAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,MAAA,EAAQ,GAAG,EAAE,IAAA,EAAK;AACxC;AAGA,SAAS,MAAA,CAAO,GAAA,EAAa,IAAA,GAAO,CAAA,EAAW;AAC7C,EAAA,IAAI,KAAK,UAAA,GAAa,IAAA;AACtB,EAAA,IAAI,KAAK,UAAA,GAAa,IAAA;AACtB,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,GAAA,C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GAAA,CAAI,WAAA,EAAa,CAAA,CAAA,EAAI,UAAA,CAAW,kBAAA,CAAmB,IAAI,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA;AAC5E,IAAA,MAAM,CAAA,GAAA,CAAK,IAAA,CAAK,GAAA,CAAI,IAAI,KAAK,CAAA,IAAK,CAAA;AAClC,IAAA,IAAA,CAAK,GAAA,CAAI,MAAM,CAAC,CAAA;AAChB,IAAA,OAAO,MAAM,CAAA,GAAI,IAAA,GAAO,CAAA,EAAG,IAAI,IAAI,CAAC,CAAA,CAAA;AAAA,EACtC,CAAA;AACF;AAGO,SAAS,aAAA,GAAgB;AAC9B,EAAA,MAAM,OAAA,GAAU,IAAI,aAAA,EAAc;AAClC,EAAA,OAAO;AAAA;AAAA,IAEL,MAAM,CAAC,IAAA,KAAiB,OAAA,CAAQ,IAAA,CAAK,QAAQ,SAAS,CAAA;AAAA;AAAA,IAEtD,MAAM,CAAC,EAAA,KAAe,OAAA,CAAQ,IAAA,CAAK,IAAI,IAAI;AAAA,GAC7C;AACF","file":"chunk-ISI35TCM.js","sourcesContent":["/**\n * Block ids and heading slugs, shared by the build-time rehype plugin\n * (`zreader/rehype`) and the in-browser fallback in <Reader>, so\n * both produce identical ids for the same content. No Node APIs.\n */\nimport GithubSlugger from \"github-slugger\";\n\nexport const BLOCK_TAG_NAMES = [\n \"p\",\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n \"li\",\n \"blockquote\",\n \"pre\",\n \"figcaption\",\n \"td\",\n \"th\",\n \"dt\",\n \"dd\",\n] as const;\n\nexport const BLOCK_TAGS: ReadonlySet<string> = new Set(BLOCK_TAG_NAMES);\n\n/** Collapse whitespace the same way on the server (hast) and in the DOM. */\nexport function normalizeBlockText(text: string): string {\n return text.replace(/\\s+/g, \" \").trim();\n}\n\n/** cyrb53: a fast, well-distributed 53-bit string hash (public domain). */\nfunction cyrb53(str: string, seed = 0): number {\n let h1 = 0xdeadbeef ^ seed;\n let h2 = 0x41c6ce57 ^ seed;\n for (let i = 0; i < str.length; i++) {\n const ch = str.charCodeAt(i);\n h1 = Math.imul(h1 ^ ch, 2654435761);\n h2 = Math.imul(h2 ^ ch, 1597334677);\n }\n h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);\n h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);\n return 4294967296 * (2097151 & h2) + (h1 >>> 0);\n}\n\n/** Hex digest of `text`, `length` characters long (up to 26). */\nexport function hashString(text: string, length = 16): string {\n const hex = cyrb53(text, 0).toString(16).padStart(14, \"0\") + cyrb53(text, 0x9e3779b9).toString(16).padStart(14, \"0\");\n return hex.slice(0, length);\n}\n\n/**\n * Allocates content-derived block ids (`p-3fa9c1`) for one chapter. Inserting a\n * paragraph doesn't shift other blocks' ids; repeated text gets `-2`, `-3`…\n */\nexport function createBlockIdAllocator() {\n const seen = new Map<string, number>();\n return (tag: string, text: string): string => {\n const base = `${tag.toLowerCase()}-${hashString(normalizeBlockText(text), 6)}`;\n const n = (seen.get(base) ?? 0) + 1;\n seen.set(base, n);\n return n === 1 ? base : `${base}-${n}`;\n };\n}\n\n/** GitHub-style heading slugs, unique within one chapter. */\nexport function createSlugger() {\n const slugger = new GithubSlugger();\n return {\n /** Slug for a heading's text. */\n slug: (text: string) => slugger.slug(text || \"section\"),\n /** Keep an author-supplied id (made unique). */\n keep: (id: string) => slugger.slug(id, true),\n };\n}\n"]}
|