@damiro/stylo 0.13.6 → 0.15.1
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/dist/{InPlaceView-BccqyOao.js → InPlaceView-BLlGJ9mh.js} +3 -2
- package/dist/{InPlaceView-BccqyOao.js.map → InPlaceView-BLlGJ9mh.js.map} +1 -1
- package/dist/Preview-DKOoZ-vr.js +295 -0
- package/dist/Preview-DKOoZ-vr.js.map +1 -0
- package/dist/SplitView.d.ts +4 -2
- package/dist/SplitView.d.ts.map +1 -1
- package/dist/Stylo.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/inplace/theme-table-gizmos.d.ts +1 -0
- package/dist/inplace/theme-table-gizmos.d.ts.map +1 -1
- package/dist/{markdown-BYXs9Tj8.js → markdown-DcS6jMel.js} +484 -469
- package/dist/markdown-DcS6jMel.js.map +1 -0
- package/dist/render/Preview.d.ts +20 -2
- package/dist/render/Preview.d.ts.map +1 -1
- package/dist/render/taskCheckbox.d.ts +13 -0
- package/dist/render/taskCheckbox.d.ts.map +1 -0
- package/dist/stylo.js +63 -57
- package/dist/stylo.js.map +1 -1
- package/dist/types.d.ts +36 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/dist/Preview-ClaSJYJW.js +0 -238
- package/dist/Preview-ClaSJYJW.js.map +0 -1
- package/dist/markdown-BYXs9Tj8.js.map +0 -1
package/dist/Preview-ClaSJYJW.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./markdown-BYXs9Tj8.js";
|
|
2
|
-
import { a as s, i as c, o as l, t as u } from "./highlight-BLVSvron.js";
|
|
3
|
-
import { a as d, i as f, n as p, o as m, t as h } from "./embed-Dsu6b-MV.js";
|
|
4
|
-
import { useEffect as g, useMemo as _, useState as v } from "react";
|
|
5
|
-
import { LanguageDescription as y } from "@codemirror/language";
|
|
6
|
-
import { highlightTree as b, tagHighlighter as x } from "@lezer/highlight";
|
|
7
|
-
import { jsx as S, jsxs as C } from "react/jsx-runtime";
|
|
8
|
-
//#region src/render/highlightCode.ts
|
|
9
|
-
var w = x(u.map(({ tags: e, token: t }) => ({
|
|
10
|
-
tag: e,
|
|
11
|
-
class: `stylo-tok-${t}`
|
|
12
|
-
}))), T = {
|
|
13
|
-
"&": "&",
|
|
14
|
-
"<": "<",
|
|
15
|
-
">": ">"
|
|
16
|
-
}, E = (e) => e.replace(/[&<>]/g, (e) => T[e] ?? e);
|
|
17
|
-
function D(e, t) {
|
|
18
|
-
return typeof t == "function" ? t(e) : y.matchLanguageName(t, e, !0);
|
|
19
|
-
}
|
|
20
|
-
async function O(e, t, n) {
|
|
21
|
-
let r = /\S*/.exec(t)?.[0] ?? "";
|
|
22
|
-
if (!r) return null;
|
|
23
|
-
let i = D(r, n);
|
|
24
|
-
if (!i) return null;
|
|
25
|
-
let a;
|
|
26
|
-
if (i instanceof y) try {
|
|
27
|
-
a = (await i.load()).language;
|
|
28
|
-
} catch {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
else a = i;
|
|
32
|
-
let o = a.parser.parse(e), s = "", c = 0;
|
|
33
|
-
return b(o, w, (t, n, r) => {
|
|
34
|
-
t > c && (s += E(e.slice(c, t))), s += `<span class="${r}">${E(e.slice(t, n))}</span>`, c = n;
|
|
35
|
-
}), c < e.length && (s += E(e.slice(c))), s;
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/render/CodeBlock.tsx
|
|
39
|
-
function k({ code: e, language: t, codeLanguages: n, className: r }) {
|
|
40
|
-
let [i, a] = v(null);
|
|
41
|
-
return g(() => {
|
|
42
|
-
let r = !0;
|
|
43
|
-
return a(null), O(e, t, n).then((e) => {
|
|
44
|
-
r && a(e);
|
|
45
|
-
}), () => {
|
|
46
|
-
r = !1;
|
|
47
|
-
};
|
|
48
|
-
}, [
|
|
49
|
-
e,
|
|
50
|
-
t,
|
|
51
|
-
n
|
|
52
|
-
]), i == null ? /* @__PURE__ */ S("code", {
|
|
53
|
-
className: r,
|
|
54
|
-
children: e
|
|
55
|
-
}) : /* @__PURE__ */ S("code", {
|
|
56
|
-
className: r,
|
|
57
|
-
dangerouslySetInnerHTML: { __html: i }
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/render/remark-callout.ts
|
|
62
|
-
function A() {
|
|
63
|
-
return (e) => {
|
|
64
|
-
r(e, "blockquote", (e) => {
|
|
65
|
-
let t = e.children[0];
|
|
66
|
-
if (t?.type !== "paragraph") return;
|
|
67
|
-
let n = t.children[0];
|
|
68
|
-
if (n?.type !== "text") return;
|
|
69
|
-
let r = f.exec(n.value);
|
|
70
|
-
if (!r) return;
|
|
71
|
-
n.value = n.value.slice(r[0].length);
|
|
72
|
-
let i = r[1].toLowerCase();
|
|
73
|
-
e.data ??= {};
|
|
74
|
-
let a = e.data.hProperties ??= {};
|
|
75
|
-
a.className = ["stylo-callout", `stylo-callout-${d(i)}`], a["data-callout"] = i;
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region src/render/remark-embed.ts
|
|
81
|
-
function j() {
|
|
82
|
-
return (e) => {
|
|
83
|
-
r(e, "paragraph", (e) => {
|
|
84
|
-
let t = e.children.length === 1 ? e.children[0] : void 0;
|
|
85
|
-
if (t?.type !== "text" || !p(t.value)) return;
|
|
86
|
-
h.lastIndex = 0;
|
|
87
|
-
let n = (h.exec(t.value.trim())?.[1] ?? "").trim();
|
|
88
|
-
n && (e.children = [], e.data ??= {}, e.data.hName = "div", e.data.hProperties = {
|
|
89
|
-
className: ["stylo-embed"],
|
|
90
|
-
"data-stylo-embed": n
|
|
91
|
-
});
|
|
92
|
-
}), r(e, "text", (e, t, n) => {
|
|
93
|
-
if (t == null || n == null || !e.value.includes("![[")) return;
|
|
94
|
-
let r = [], i = 0;
|
|
95
|
-
h.lastIndex = 0;
|
|
96
|
-
for (let t of e.value.matchAll(h)) {
|
|
97
|
-
let n = (t[1] ?? "").trim();
|
|
98
|
-
if (!n) continue;
|
|
99
|
-
let a = t.index ?? 0;
|
|
100
|
-
a > i && r.push({
|
|
101
|
-
type: "text",
|
|
102
|
-
value: e.value.slice(i, a)
|
|
103
|
-
}), r.push({
|
|
104
|
-
type: "text",
|
|
105
|
-
value: "",
|
|
106
|
-
data: {
|
|
107
|
-
hName: "span",
|
|
108
|
-
hProperties: {
|
|
109
|
-
className: ["stylo-embed"],
|
|
110
|
-
"data-stylo-embed-inline": n
|
|
111
|
-
},
|
|
112
|
-
hChildren: []
|
|
113
|
-
}
|
|
114
|
-
}), i = a + t[0].length;
|
|
115
|
-
}
|
|
116
|
-
if (r.length) return i < e.value.length && r.push({
|
|
117
|
-
type: "text",
|
|
118
|
-
value: e.value.slice(i)
|
|
119
|
-
}), n.children.splice(t, 1, ...r), [a, t + r.length];
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region src/render/remark-wikilink.ts
|
|
125
|
-
function M() {
|
|
126
|
-
return (e) => {
|
|
127
|
-
r(e, "text", (e, t, n) => {
|
|
128
|
-
if (n == null || t == null || !e.value.includes("[[")) return;
|
|
129
|
-
let r = [], i = 0;
|
|
130
|
-
for (let t of e.value.matchAll(s)) {
|
|
131
|
-
let [n = "", a = "", o] = t, s = t.index ?? 0;
|
|
132
|
-
s > i && r.push({
|
|
133
|
-
type: "text",
|
|
134
|
-
value: e.value.slice(i, s)
|
|
135
|
-
}), r.push({
|
|
136
|
-
type: "link",
|
|
137
|
-
url: "#",
|
|
138
|
-
data: { hProperties: { "data-wikilink": a.trim() } },
|
|
139
|
-
children: [{
|
|
140
|
-
type: "text",
|
|
141
|
-
value: (o ?? a).trim()
|
|
142
|
-
}]
|
|
143
|
-
}), i = s + n.length;
|
|
144
|
-
}
|
|
145
|
-
if (i !== 0) return i < e.value.length && r.push({
|
|
146
|
-
type: "text",
|
|
147
|
-
value: e.value.slice(i)
|
|
148
|
-
}), n.children.splice(t, 1, ...r), t + r.length;
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region src/render/Preview.tsx
|
|
154
|
-
var N = [t];
|
|
155
|
-
function P({ value: t, onWikiLinkClick: r, embedSource: a, onResolveError: s, frontmatter: u = "hidden", codeLanguages: d }) {
|
|
156
|
-
let f = u === "code" ? c(t) : null, p = _(() => [
|
|
157
|
-
i,
|
|
158
|
-
n,
|
|
159
|
-
o,
|
|
160
|
-
...a ? [j] : [],
|
|
161
|
-
M,
|
|
162
|
-
A
|
|
163
|
-
], [a]);
|
|
164
|
-
return /* @__PURE__ */ C("div", {
|
|
165
|
-
className: l.preview,
|
|
166
|
-
children: [f && /* @__PURE__ */ S("div", {
|
|
167
|
-
className: "stylo-frontmatter",
|
|
168
|
-
children: f.frontmatter
|
|
169
|
-
}), /* @__PURE__ */ S(e, {
|
|
170
|
-
remarkPlugins: p,
|
|
171
|
-
rehypePlugins: N,
|
|
172
|
-
components: {
|
|
173
|
-
a({ node: e, children: t, ...n }) {
|
|
174
|
-
let i = n["data-wikilink"];
|
|
175
|
-
return typeof i == "string" ? /* @__PURE__ */ S("a", {
|
|
176
|
-
...n,
|
|
177
|
-
href: "#",
|
|
178
|
-
onClick: (e) => {
|
|
179
|
-
e.preventDefault(), r?.(i);
|
|
180
|
-
},
|
|
181
|
-
children: t
|
|
182
|
-
}) : /* @__PURE__ */ S("a", {
|
|
183
|
-
...n,
|
|
184
|
-
rel: "noreferrer",
|
|
185
|
-
children: t
|
|
186
|
-
});
|
|
187
|
-
},
|
|
188
|
-
div({ node: e, children: t, ...n }) {
|
|
189
|
-
let r = n["data-stylo-embed"];
|
|
190
|
-
return typeof r == "string" && a ? /* @__PURE__ */ S("div", {
|
|
191
|
-
...n,
|
|
192
|
-
children: /* @__PURE__ */ S(m, {
|
|
193
|
-
reference: r,
|
|
194
|
-
source: a,
|
|
195
|
-
onError: s
|
|
196
|
-
})
|
|
197
|
-
}) : /* @__PURE__ */ S("div", {
|
|
198
|
-
...n,
|
|
199
|
-
children: t
|
|
200
|
-
});
|
|
201
|
-
},
|
|
202
|
-
span({ node: e, children: t, ...n }) {
|
|
203
|
-
let r = n["data-stylo-embed-inline"];
|
|
204
|
-
return typeof r == "string" && a ? /* @__PURE__ */ S("span", {
|
|
205
|
-
...n,
|
|
206
|
-
children: /* @__PURE__ */ S(m, {
|
|
207
|
-
reference: r,
|
|
208
|
-
source: a,
|
|
209
|
-
onError: s,
|
|
210
|
-
inline: !0
|
|
211
|
-
})
|
|
212
|
-
}) : /* @__PURE__ */ S("span", {
|
|
213
|
-
...n,
|
|
214
|
-
children: t
|
|
215
|
-
});
|
|
216
|
-
},
|
|
217
|
-
code({ node: e, className: t, children: n, ...r }) {
|
|
218
|
-
let i = /language-(\w+)/.exec(t || "")?.[1];
|
|
219
|
-
return i && d ? /* @__PURE__ */ S(k, {
|
|
220
|
-
className: t,
|
|
221
|
-
language: i,
|
|
222
|
-
code: String(n).replace(/\n$/, ""),
|
|
223
|
-
codeLanguages: d
|
|
224
|
-
}) : /* @__PURE__ */ S("code", {
|
|
225
|
-
...r,
|
|
226
|
-
className: t,
|
|
227
|
-
children: n
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
children: t
|
|
232
|
-
})]
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
//#endregion
|
|
236
|
-
export { P as Preview };
|
|
237
|
-
|
|
238
|
-
//# sourceMappingURL=Preview-ClaSJYJW.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Preview-ClaSJYJW.js","names":[],"sources":["../src/render/highlightCode.ts","../src/render/CodeBlock.tsx","../src/render/remark-callout.ts","../src/render/remark-embed.ts","../src/render/remark-wikilink.ts","../src/render/Preview.tsx"],"sourcesContent":["import { LanguageDescription, type Language } from \"@codemirror/language\"\nimport { highlightTree, tagHighlighter } from \"@lezer/highlight\"\nimport { SYNTAX_TAG_GROUPS } from \"../editor/highlight\"\nimport type { CodeLanguages } from \"../types\"\n\n/**\n * `preview`'s counterpart to `src/editor/highlight.ts`'s `styloHighlightStyle`\n * — same `SYNTAX_TAG_GROUPS`, same tags, but emitting plain `stylo-tok-<token>`\n * classes (styled in `stylo.module.css`) instead of a CodeMirror `StyleModule`,\n * since `highlightTree` here runs outside of any `EditorView`.\n */\nconst previewHighlighter = tagHighlighter(\n SYNTAX_TAG_GROUPS.map(({ tags, token }) => ({ tag: tags, class: `stylo-tok-${token}` })),\n)\n\nconst ESCAPES: Record<string, string> = { \"&\": \"&\", \"<\": \"<\", \">\": \">\" }\nconst escapeHtml = (text: string) => text.replace(/[&<>]/g, (c) => ESCAPES[c] ?? c)\n\n/**\n * Resolves a fence's language the same way `@codemirror/lang-markdown`\n * resolves `codeLanguages` for the CodeMirror surfaces, so a name that matches\n * on one matches on the other: the function form is called with the name\n * directly, an array is matched fuzzily by `LanguageDescription.matchLanguageName`.\n */\nfunction resolveLanguage(\n name: string,\n codeLanguages: CodeLanguages,\n): Language | LanguageDescription | null {\n if (typeof codeLanguages === \"function\") return codeLanguages(name)\n return LanguageDescription.matchLanguageName(codeLanguages, name, true)\n}\n\n/**\n * Tokenizes one fenced code block for `preview`, reusing the exact grammars\n * and colour mapping the in-place canvas's CodeMirror highlighter uses, so a\n * block looks identical whether the note is being read or edited. Returns\n * `null` — the block stays plain, un-highlighted text — when `codeLanguages`\n * has no match for `info`, or the match fails to load.\n */\nexport async function highlightToHtml(\n code: string,\n info: string,\n codeLanguages: CodeLanguages,\n): Promise<string | null> {\n const name = /\\S*/.exec(info)?.[0] ?? \"\"\n if (!name) return null\n\n const match = resolveLanguage(name, codeLanguages)\n if (!match) return null\n\n let language: Language\n if (match instanceof LanguageDescription) {\n try {\n language = (await match.load()).language\n } catch {\n return null\n }\n } else {\n language = match\n }\n\n const tree = language.parser.parse(code)\n let html = \"\"\n let pos = 0\n highlightTree(tree, previewHighlighter, (from, to, classes) => {\n if (from > pos) html += escapeHtml(code.slice(pos, from))\n html += `<span class=\"${classes}\">${escapeHtml(code.slice(from, to))}</span>`\n pos = to\n })\n if (pos < code.length) html += escapeHtml(code.slice(pos))\n return html\n}\n","import { useEffect, useState } from \"react\"\nimport type { CodeLanguages } from \"../types\"\nimport { highlightToHtml } from \"./highlightCode\"\n\ninterface CodeBlockProps {\n code: string\n language: string\n codeLanguages: CodeLanguages\n className?: string\n}\n\n/**\n * One fenced code block in `preview`. Renders plain text immediately — so\n * there is never a loading flash for something this small — then swaps in\n * `--stylo-syntax-*`-coloured spans once `codeLanguages` resolves and the\n * block's grammar parses. Per-language grammars stay exactly as lazy as they\n * already are for the CodeMirror surfaces (`codeLanguages` is host-supplied),\n * so a `preview`-only consumer never pays for one it never shows.\n */\nexport function CodeBlock({ code, language, codeLanguages, className }: CodeBlockProps) {\n const [html, setHtml] = useState<string | null>(null)\n\n useEffect(() => {\n let live = true\n setHtml(null)\n highlightToHtml(code, language, codeLanguages).then((result) => {\n if (live) setHtml(result)\n })\n return () => {\n live = false\n }\n }, [code, language, codeLanguages])\n\n if (html == null) return <code className={className}>{code}</code>\n // `html` is built in highlightCode.ts from the parsed source text (HTML-escaped)\n // and fixed `stylo-tok-*` class names only — no host or document input reaches it.\n return <code className={className} dangerouslySetInnerHTML={{ __html: html }} />\n}\n","import type { Blockquote, Root } from \"mdast\"\nimport { visit } from \"unist-util-visit\"\nimport { CALLOUT_TOKEN, calloutBucket } from \"../callout\"\n\n/**\n * Turns an Obsidian callout blockquote (`> [!note] Title`) into a\n * `<blockquote class=\"stylo-callout stylo-callout-<bucket>\" data-callout=\"note\">`.\n * The `[!type]` token is stripped from the first line; a `::before` label keyed\n * off `data-callout` stands in for it (matching the in-place canvas). The\n * `-` / `+` fold marker is accepted and ignored — the box always renders open.\n */\nexport function remarkCallout() {\n return (tree: Root) => {\n visit(tree, \"blockquote\", (node: Blockquote) => {\n const para = node.children[0]\n if (para?.type !== \"paragraph\") return\n const first = para.children[0]\n if (first?.type !== \"text\") return\n\n const m = CALLOUT_TOKEN.exec(first.value)\n if (!m) return\n\n first.value = first.value.slice(m[0].length)\n const type = m[1]!.toLowerCase()\n node.data ??= {}\n const props = (node.data.hProperties ??= {}) as Record<string, unknown>\n props.className = [\"stylo-callout\", `stylo-callout-${calloutBucket(type)}`]\n props[\"data-callout\"] = type\n })\n }\n}\n","import type { Paragraph, PhrasingContent, Root, Text } from \"mdast\"\nimport { SKIP, visit } from \"unist-util-visit\"\nimport { EMBED_PATTERN, isLoneEmbed } from \"../embed\"\n\n/**\n * Turns `![[ref]]` transclusion syntax into empty carrier elements the `Embed`\n * component (wired in `Preview`) fills from the host's `embedSource`.\n *\n * - A **lone** `![[ref]]` — the whole paragraph, trimmed — becomes a block\n * `<div class=\"stylo-embed\" data-stylo-embed=\"ref\">`.\n * - A `![[ref]]` **inside other text** becomes an inline\n * `<span class=\"stylo-embed\" data-stylo-embed-inline=\"ref\">`, and the\n * surrounding text is preserved around it. The host node should be phrasing\n * content in this case.\n *\n * `![[…]]` inside inline or fenced code is left literal (it is not a `text`\n * node). Must run before `remarkWikilink`, or the inner `[[ref]]` is rewritten\n * to a link first. Off unless the consumer passes `embedSource` — `Preview` only\n * adds this plugin then.\n */\nexport function remarkEmbed() {\n return (tree: Root) => {\n visit(tree, \"paragraph\", (node: Paragraph) => {\n const only = node.children.length === 1 ? node.children[0] : undefined\n if (only?.type !== \"text\" || !isLoneEmbed(only.value)) return\n\n EMBED_PATTERN.lastIndex = 0\n const ref = (EMBED_PATTERN.exec(only.value.trim())?.[1] ?? \"\").trim()\n if (!ref) return\n\n node.children = []\n node.data ??= {}\n node.data.hName = \"div\"\n node.data.hProperties = { className: [\"stylo-embed\"], \"data-stylo-embed\": ref }\n })\n\n visit(tree, \"text\", (node: Text, index, parent) => {\n if (index == null || parent == null || !node.value.includes(\"![[\")) return\n\n const parts: PhrasingContent[] = []\n let cursor = 0\n // `matchAll` seeds its internal copy from the shared regex's `lastIndex`;\n // reset it so the scan starts at 0 (the lone-paragraph pass above left it\n // mid-string).\n EMBED_PATTERN.lastIndex = 0\n for (const match of node.value.matchAll(EMBED_PATTERN)) {\n const ref = (match[1] ?? \"\").trim()\n if (!ref) continue\n const start = match.index ?? 0\n if (start > cursor) parts.push({ type: \"text\", value: node.value.slice(cursor, start) })\n parts.push({\n type: \"text\",\n value: \"\",\n data: {\n hName: \"span\",\n hProperties: { className: [\"stylo-embed\"], \"data-stylo-embed-inline\": ref },\n hChildren: [],\n },\n })\n cursor = start + match[0].length\n }\n\n if (!parts.length) return\n if (cursor < node.value.length) parts.push({ type: \"text\", value: node.value.slice(cursor) })\n parent.children.splice(index, 1, ...parts)\n return [SKIP, index + parts.length]\n })\n }\n}\n","import type { Link, Root, Text } from \"mdast\"\nimport { visit } from \"unist-util-visit\"\nimport { WIKILINK_PATTERN } from \"../wikilink\"\n\n/**\n * Rewrites `[[target]]` and `[[target|label]]` inside text into link nodes that\n * carry a `data-wikilink` attribute holding the target. The rendered href is\n * inert (`#`); navigation is the host's job via `onWikiLinkClick`.\n */\nexport function remarkWikilink() {\n return (tree: Root) => {\n visit(tree, \"text\", (node: Text, index, parent) => {\n if (parent == null || index == null || !node.value.includes(\"[[\")) return\n\n const out: Array<Text | Link> = []\n let cursor = 0\n\n for (const match of node.value.matchAll(WIKILINK_PATTERN)) {\n const [raw = \"\", rawTarget = \"\", rawLabel] = match\n const start = match.index ?? 0\n if (start > cursor) {\n out.push({ type: \"text\", value: node.value.slice(cursor, start) })\n }\n out.push({\n type: \"link\",\n url: \"#\",\n data: { hProperties: { \"data-wikilink\": rawTarget.trim() } },\n children: [{ type: \"text\", value: (rawLabel ?? rawTarget).trim() }],\n })\n cursor = start + raw.length\n }\n\n if (cursor === 0) return\n if (cursor < node.value.length) {\n out.push({ type: \"text\", value: node.value.slice(cursor) })\n }\n\n parent.children.splice(index, 1, ...out)\n return index + out.length\n })\n }\n}\n","import { useMemo } from \"react\"\nimport Markdown, { type Components } from \"react-markdown\"\nimport rehypeKatex from \"rehype-katex\"\nimport remarkFrontmatter from \"remark-frontmatter\"\nimport remarkGfm from \"remark-gfm\"\nimport remarkMath from \"remark-math\"\nimport { splitFrontmatter } from \"../frontmatter\"\nimport styles from \"../styles/stylo.module.css\"\nimport type { CodeLanguages, EmbedSource, FrontmatterDisplay, ResolveErrorInfo } from \"../types\"\nimport { CodeBlock } from \"./CodeBlock\"\nimport { Embed } from \"./Embed\"\nimport { remarkCallout } from \"./remark-callout\"\nimport { remarkEmbed } from \"./remark-embed\"\nimport { remarkWikilink } from \"./remark-wikilink\"\n\nconst REHYPE_PLUGINS = [rehypeKatex]\n\nexport interface PreviewProps {\n value: string\n onWikiLinkClick?: (target: string) => void\n /** Resolves `![[ref]]` embeds. Omit and `![[…]]` stays literal. */\n embedSource?: EmbedSource\n /** Notified when `embedSource` rejects; the literal fallback still renders. */\n onResolveError?: (error: unknown, info: ResolveErrorInfo) => void\n /** `\"code\"` renders the `---` block as a styled `<pre>`; `\"hidden\"` (default) drops it. */\n frontmatter?: FrontmatterDisplay\n /**\n * Grammars for fenced-code syntax highlighting, matching the CodeMirror\n * surfaces' `codeLanguages` prop exactly (same resolution rules, same\n * `--stylo-syntax-*` colours). Omit and fenced code renders as plain,\n * un-highlighted text — today's behaviour.\n */\n codeLanguages?: CodeLanguages\n}\n\n/** Rendered Markdown + KaTeX view. A pure function of the string. */\nexport function Preview({\n value,\n onWikiLinkClick,\n embedSource,\n onResolveError,\n frontmatter = \"hidden\",\n codeLanguages,\n}: PreviewProps) {\n const fm = frontmatter === \"code\" ? splitFrontmatter(value) : null\n\n // `remarkEmbed` must precede `remarkWikilink` (it consumes the `![[…]]` before\n // the inner `[[…]]` is rewritten) and is only in the pipeline when the host\n // opts in, so a bare `![[x]]` renders unchanged otherwise.\n const remarkPlugins = useMemo(\n () => [\n remarkFrontmatter,\n remarkGfm,\n remarkMath,\n ...(embedSource ? [remarkEmbed] : []),\n remarkWikilink,\n remarkCallout,\n ],\n [embedSource],\n )\n\n const components: Components = {\n a({ node: _node, children, ...rest }) {\n const target = (rest as Record<string, unknown>)[\"data-wikilink\"]\n if (typeof target === \"string\") {\n return (\n <a\n {...rest}\n href=\"#\"\n onClick={(event) => {\n event.preventDefault()\n onWikiLinkClick?.(target)\n }}\n >\n {children}\n </a>\n )\n }\n return (\n <a {...rest} rel=\"noreferrer\">\n {children}\n </a>\n )\n },\n div({ node: _node, children, ...rest }) {\n const reference = (rest as Record<string, unknown>)[\"data-stylo-embed\"]\n if (typeof reference === \"string\" && embedSource) {\n return (\n <div {...rest}>\n <Embed reference={reference} source={embedSource} onError={onResolveError} />\n </div>\n )\n }\n return <div {...rest}>{children}</div>\n },\n span({ node: _node, children, ...rest }) {\n const reference = (rest as Record<string, unknown>)[\"data-stylo-embed-inline\"]\n if (typeof reference === \"string\" && embedSource) {\n return (\n <span {...rest}>\n <Embed reference={reference} source={embedSource} onError={onResolveError} inline />\n </span>\n )\n }\n return <span {...rest}>{children}</span>\n },\n code({ node: _node, className, children, ...rest }) {\n const language = /language-(\\w+)/.exec(className || \"\")?.[1]\n if (language && codeLanguages) {\n return (\n <CodeBlock\n className={className}\n language={language}\n code={String(children).replace(/\\n$/, \"\")}\n codeLanguages={codeLanguages}\n />\n )\n }\n return (\n <code {...rest} className={className}>\n {children}\n </code>\n )\n },\n }\n\n return (\n <div className={styles.preview}>\n {fm && <div className=\"stylo-frontmatter\">{fm.frontmatter}</div>}\n <Markdown\n remarkPlugins={remarkPlugins}\n rehypePlugins={REHYPE_PLUGINS}\n components={components}\n >\n {value}\n </Markdown>\n </div>\n )\n}\n"],"mappings":";;;;;;;;AAWA,IAAM,IAAqB,EACzB,EAAkB,KAAK,EAAE,SAAM,gBAAa;CAAE,KAAK;CAAM,OAAO,aAAa;AAAQ,EAAE,CACzF,GAEM,IAAkC;CAAE,KAAK;CAAS,KAAK;C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