@docubook/core 2.0.0-beta.0 → 2.0.0-beta.2

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/index.js CHANGED
@@ -1,463 +1,286 @@
1
- import {
2
- cn,
3
- formatDate,
4
- formatDate2,
5
- parseDate,
6
- stringToDate,
7
- toIsoDateOnly
8
- } from "./chunk-HZJLRYAI.js";
9
- import {
10
- serialize
11
- } from "./chunk-J7CN2VUH.js";
12
-
13
- // src/compile.ts
14
- import { visit as visit4 } from "unist-util-visit";
15
- import remarkGfm from "remark-gfm";
16
- import rehypePrism from "rehype-prism-plus";
17
- import rehypeAutolinkHeadings from "rehype-autolink-headings";
18
- import rehypeSlug from "rehype-slug";
19
- import rehypeCodeTitles from "rehype-code-titles";
20
-
21
- // src/plugins/handleCodeTitles.ts
22
- import { visit } from "unist-util-visit";
23
- var handleCodeTitles = () => (tree) => {
24
- const toRemove = [];
25
- visit(tree, "element", (node, index, parent) => {
26
- if (!parent || index === null || node.tagName !== "div") {
27
- return;
28
- }
29
- const isTitleDiv = node.properties?.className?.includes("rehype-code-title");
30
- if (!isTitleDiv) {
31
- return;
32
- }
33
- let nextElement = null;
34
- for (let i = index + 1; i < parent.children.length; i++) {
35
- const sibling = parent.children[i];
36
- if (sibling.type === "element") {
37
- nextElement = sibling;
38
- break;
39
- }
40
- }
41
- if (nextElement?.tagName === "pre") {
42
- const titleNode = node.children?.[0];
43
- if (titleNode?.type === "text") {
44
- if (!nextElement.properties) {
45
- nextElement.properties = {};
46
- }
47
- nextElement.properties["data-title"] = titleNode.value;
48
- nextElement.codeTitle = titleNode.value;
49
- toRemove.push({ parent, index });
50
- }
51
- }
52
- });
53
- for (let i = toRemove.length - 1; i >= 0; i--) {
54
- const { parent, index } = toRemove[i];
55
- parent.children.splice(index, 1);
56
- }
1
+ import { cn as e, formatDate as t, formatDate2 as n, parseDate as r, stringToDate as i, toIsoDateOnly as a } from "./utils.js";
2
+ import { t as o } from "./serialize-DEuXE4Xm.js";
3
+ import { visit as s } from "unist-util-visit";
4
+ import c from "remark-gfm";
5
+ import l from "rehype-prism-plus";
6
+ import u from "rehype-autolink-headings";
7
+ import d from "rehype-slug";
8
+ import f from "rehype-code-titles";
9
+ import p from "remark-directive";
10
+ import m, { useEffect as h, useMemo as g, useState as _ } from "react";
11
+ import * as v from "react/jsx-runtime";
12
+ import * as y from "react/jsx-dev-runtime";
13
+ import * as b from "@mdx-js/react";
14
+ import x from "@11ty/gray-matter";
15
+ //#region src/plugins/handleCodeTitles.ts
16
+ var S = () => (e) => {
17
+ let t = [];
18
+ s(e, "element", (e, n, r) => {
19
+ if (!r || n === null || e.tagName !== "div" || !e.properties?.className?.includes("rehype-code-title")) return;
20
+ let i = null;
21
+ for (let e = n + 1; e < r.children.length; e++) {
22
+ let t = r.children[e];
23
+ if (t.type === "element") {
24
+ i = t;
25
+ break;
26
+ }
27
+ }
28
+ if (i?.tagName === "pre") {
29
+ let a = e.children?.[0];
30
+ a?.type === "text" && (i.properties || (i.properties = {}), i.properties["data-title"] = a.value, i.codeTitle = a.value, t.push({
31
+ parent: r,
32
+ index: n
33
+ }));
34
+ }
35
+ });
36
+ for (let e = t.length - 1; e >= 0; e--) {
37
+ let { parent: n, index: r } = t[e];
38
+ n.children.splice(r, 1);
39
+ }
57
40
  };
58
-
59
- // src/plugins/handleCodeExpandable.ts
60
- import { visit as visit2 } from "unist-util-visit";
61
- function escapeMeta(s) {
62
- let out = "";
63
- for (let i = 0; i < s.length; i++) {
64
- const ch = s[i];
65
- if (ch === "<" && s[i + 1] === "/") {
66
- out += "\\u003C/";
67
- i++;
68
- continue;
69
- }
70
- if (ch === "`" || ch === "$" || ch === "{" || ch === "}" || ch === '"' || ch === "\\") {
71
- out += `\\${ch}`;
72
- continue;
73
- }
74
- out += ch;
75
- }
76
- return out;
41
+ //#endregion
42
+ //#region src/plugins/handleCodeExpandable.ts
43
+ function C(e) {
44
+ let t = "";
45
+ for (let n = 0; n < e.length; n++) {
46
+ let r = e[n];
47
+ if (r === "<" && e[n + 1] === "/") {
48
+ t += "\\u003C/", n++;
49
+ continue;
50
+ }
51
+ if (r === "`" || r === "$" || r === "{" || r === "}" || r === "\"" || r === "\\") {
52
+ t += `\\${r}`;
53
+ continue;
54
+ }
55
+ t += r;
56
+ }
57
+ return t;
77
58
  }
78
- function countCodeLines(raw) {
79
- let normalized = raw.replace(/\r\n/g, "\n");
80
- if (normalized.startsWith("\n")) normalized = normalized.slice(1);
81
- if (normalized.endsWith("\n")) normalized = normalized.slice(0, -1);
82
- if (normalized.length === 0) return 0;
83
- return normalized.split("\n").length;
59
+ function w(e) {
60
+ let t = e.replace(/\r\n/g, "\n");
61
+ return t.startsWith("\n") && (t = t.slice(1)), t.endsWith("\n") && (t = t.slice(0, -1)), t.length === 0 ? 0 : t.split("\n").length;
84
62
  }
85
- var handleCodeExpandableRemark = () => (tree) => {
86
- visit2(tree, "code", (node) => {
87
- if (!node.meta) return;
88
- const isExpandable = node.meta.includes("Expandable");
89
- const [languagePart, titlePart] = (node.lang ?? "").split(":");
90
- const normalizedLanguage = languagePart?.trim();
91
- const normalizedTitle = titlePart?.trim();
92
- if (!isExpandable) return;
93
- const lineCount = countCodeLines(node.value);
94
- if (!node.data) {
95
- node.data = {};
96
- }
97
- if (!node.data.hProperties) {
98
- node.data.hProperties = {};
99
- }
100
- node.data.hProperties["data-expandable"] = "true";
101
- node.data.hProperties["data-expandable-lines"] = lineCount.toString();
102
- if (normalizedLanguage) {
103
- node.data.hProperties["data-language"] = normalizedLanguage;
104
- }
105
- if (normalizedTitle) {
106
- node.data.hProperties["data-title"] = normalizedTitle;
107
- }
108
- const currentClassName = node.data.hProperties.className;
109
- const classList = Array.isArray(currentClassName) ? currentClassName : typeof currentClassName === "string" ? currentClassName.split(" ").filter(Boolean) : [];
110
- if (!classList.includes("mdx-expandable-meta")) {
111
- classList.push("mdx-expandable-meta");
112
- }
113
- node.data.hProperties.className = classList;
114
- if (normalizedLanguage && !node.meta.includes("dbLang(")) {
115
- node.meta = `${node.meta} dbLang(${escapeMeta(normalizedLanguage)})`.trim();
116
- }
117
- if (normalizedTitle && !node.meta.includes("dbTitle(")) {
118
- node.meta = `${node.meta} dbTitle(${escapeMeta(normalizedTitle)})`.trim();
119
- }
120
- });
121
- };
122
- var handleCodeExpandable = () => (tree) => {
123
- visit2(tree, "element", (node) => {
124
- if (node.tagName !== "pre") return;
125
- const codeElement = node.children?.find((child) => {
126
- const element = child;
127
- return element.type === "element" && element.tagName === "code";
128
- });
129
- const codeClassName = codeElement?.properties?.className;
130
- const codeClassList = Array.isArray(codeClassName) ? codeClassName : typeof codeClassName === "string" ? codeClassName.split(" ").filter(Boolean) : [];
131
- const codeMeta = codeElement?.data && typeof codeElement.data === "object" && typeof codeElement.data["meta"] === "string" ? codeElement.data["meta"] : void 0;
132
- const languageFromMeta = codeMeta?.match(/dbLang\(([^)]+)\)/)?.[1];
133
- const titleFromMeta = codeMeta?.match(/dbTitle\(([^)]+)\)/)?.[1];
134
- const languageFromProps = typeof codeElement?.properties?.["data-language"] === "string" ? codeElement.properties["data-language"] : void 0;
135
- const titleFromProps = typeof codeElement?.properties?.["data-title"] === "string" ? codeElement.properties["data-title"] : void 0;
136
- const languageFromCodeClass = codeClassList.find((item) => item.startsWith("language-"))?.replace("language-", "");
137
- const existingPreLanguage = typeof node.properties?.["data-language"] === "string" ? node.properties["data-language"] : void 0;
138
- const existingPreTitle = typeof node.properties?.["data-title"] === "string" ? node.properties["data-title"] : void 0;
139
- const isExpandable = codeElement?.properties?.["data-expandable"] === "true" || codeClassList.includes("mdx-expandable-meta") || codeMeta?.includes("Expandable") === true;
140
- const expandableLines = codeElement?.properties?.["data-expandable-lines"];
141
- if (!isExpandable) return;
142
- if (!node.properties) {
143
- node.properties = {};
144
- }
145
- node.properties["data-expandable"] = "true";
146
- if (typeof expandableLines === "string" || typeof expandableLines === "number") {
147
- node.properties["data-expandable-lines"] = expandableLines.toString();
148
- } else if (node.raw) {
149
- node.properties["data-expandable-lines"] = countCodeLines(node.raw).toString();
150
- }
151
- const resolvedLanguage = languageFromProps || languageFromMeta || languageFromCodeClass || existingPreLanguage || node.language;
152
- const resolvedTitle = titleFromProps || titleFromMeta || existingPreTitle || node.codeTitle;
153
- if (resolvedLanguage) {
154
- node.properties["data-language"] = resolvedLanguage;
155
- }
156
- if (resolvedTitle) {
157
- node.properties["data-title"] = resolvedTitle;
158
- }
159
- const className = node.properties.className;
160
- if (!className) {
161
- node.properties.className = [];
162
- }
163
- if (Array.isArray(node.properties.className)) {
164
- if (!node.properties.className.includes("mdx-expandable-code")) {
165
- node.properties.className.push("mdx-expandable-code");
166
- }
167
- } else if (typeof className === "string") {
168
- const hasMarker = className.split(" ").includes("mdx-expandable-code");
169
- if (!hasMarker) {
170
- node.properties.className = `${className} mdx-expandable-code`.trim().split(" ");
171
- }
172
- } else {
173
- node.properties.className = ["mdx-expandable-code"];
174
- }
175
- if (codeElement?.properties) {
176
- const cleanedCodeClassList = codeClassList.filter((item) => item !== "mdx-expandable-meta");
177
- codeElement.properties.className = cleanedCodeClassList;
178
- }
179
- });
63
+ var T = () => (e) => {
64
+ s(e, "code", (e) => {
65
+ if (!e.meta) return;
66
+ let t = e.meta.includes("Expandable"), [n, r] = (e.lang ?? "").split(":"), i = n?.trim(), a = r?.trim();
67
+ if (!t) return;
68
+ let o = w(e.value);
69
+ e.data ||= {}, e.data.hProperties || (e.data.hProperties = {}), e.data.hProperties["data-expandable"] = "true", e.data.hProperties["data-expandable-lines"] = o.toString(), i && (e.data.hProperties["data-language"] = i), a && (e.data.hProperties["data-title"] = a);
70
+ let s = e.data.hProperties.className, c = Array.isArray(s) ? s : typeof s == "string" ? s.split(" ").filter(Boolean) : [];
71
+ c.includes("mdx-expandable-meta") || c.push("mdx-expandable-meta"), e.data.hProperties.className = c, i && !e.meta.includes("dbLang(") && (e.meta = `${e.meta} dbLang(${C(i)})`.trim()), a && !e.meta.includes("dbTitle(") && (e.meta = `${e.meta} dbTitle(${C(a)})`.trim());
72
+ });
73
+ }, E = () => (e) => {
74
+ s(e, "element", (e) => {
75
+ if (e.tagName !== "pre") return;
76
+ let t = e.children?.find((e) => {
77
+ let t = e;
78
+ return t.type === "element" && t.tagName === "code";
79
+ }), n = t?.properties?.className, r = Array.isArray(n) ? n : typeof n == "string" ? n.split(" ").filter(Boolean) : [], i = t?.data && typeof t.data == "object" && typeof t.data.meta == "string" ? t.data.meta : void 0, a = i?.match(/dbLang\(([^)]+)\)/)?.[1], o = i?.match(/dbTitle\(([^)]+)\)/)?.[1], s = typeof t?.properties?.["data-language"] == "string" ? t.properties["data-language"] : void 0, c = typeof t?.properties?.["data-title"] == "string" ? t.properties["data-title"] : void 0, l = r.find((e) => e.startsWith("language-"))?.replace("language-", ""), u = typeof e.properties?.["data-language"] == "string" ? e.properties["data-language"] : void 0, d = typeof e.properties?.["data-title"] == "string" ? e.properties["data-title"] : void 0, f = t?.properties?.["data-expandable"] === "true" || r.includes("mdx-expandable-meta") || i?.includes("Expandable") === !0, p = t?.properties?.["data-expandable-lines"];
80
+ if (!f) return;
81
+ e.properties ||= {}, e.properties["data-expandable"] = "true", typeof p == "string" || typeof p == "number" ? e.properties["data-expandable-lines"] = p.toString() : e.raw && (e.properties["data-expandable-lines"] = w(e.raw).toString());
82
+ let m = s || a || l || u || e.language, h = c || o || d || e.codeTitle;
83
+ m && (e.properties["data-language"] = m), h && (e.properties["data-title"] = h);
84
+ let g = e.properties.className;
85
+ if (g || (e.properties.className = []), Array.isArray(e.properties.className) ? e.properties.className.includes("mdx-expandable-code") || e.properties.className.push("mdx-expandable-code") : typeof g == "string" ? g.split(" ").includes("mdx-expandable-code") || (e.properties.className = `${g} mdx-expandable-code`.trim().split(" ")) : e.properties.className = ["mdx-expandable-code"], t?.properties) {
86
+ let e = r.filter((e) => e !== "mdx-expandable-meta");
87
+ t.properties.className = e;
88
+ }
89
+ });
90
+ }, D = () => (e) => {
91
+ s(e, "element", (e, t, n) => {
92
+ if (!n || t === null || e.tagName !== "pre") return;
93
+ let r = e.children?.find((e) => e.type === "element" && e.tagName === "code");
94
+ if (!r || !(Array.isArray(r.properties?.className) ? r.properties.className : typeof r.properties?.className == "string" ? r.properties.className.split(" ").filter(Boolean) : []).includes("language-mermaid")) return;
95
+ let i = r.children?.find((e) => e.type === "text")?.value ?? "";
96
+ n.children[t] = {
97
+ type: "element",
98
+ tagName: "Mermaid",
99
+ properties: { chart: i },
100
+ children: []
101
+ };
102
+ });
180
103
  };
181
-
182
- // src/plugins/rehypeMermaid.ts
183
- import { visit as visit3 } from "unist-util-visit";
184
- var rehypeMermaid = () => (tree) => {
185
- visit3(tree, "element", (node, index, parent) => {
186
- if (!parent || index === null || node.tagName !== "pre") return;
187
- const codeEl = node.children?.find(
188
- (child) => child.type === "element" && child.tagName === "code"
189
- );
190
- if (!codeEl) return;
191
- const classList = Array.isArray(codeEl.properties?.className) ? codeEl.properties.className : typeof codeEl.properties?.className === "string" ? codeEl.properties.className.split(" ").filter(Boolean) : [];
192
- if (!classList.includes("language-mermaid")) return;
193
- const textNode = codeEl.children?.find((child) => child.type === "text");
194
- const chart = textNode?.value ?? "";
195
- parent.children[index] = {
196
- type: "element",
197
- tagName: "Mermaid",
198
- properties: { chart },
199
- children: []
200
- };
201
- });
202
- };
203
-
204
- // src/plugins/remarkDirectiveToMdx.ts
205
- function remarkDirectiveToMdx() {
206
- return (tree) => {
207
- const root = tree;
208
- root.children = root.children.map(transform);
209
- return tree;
210
- };
104
+ //#endregion
105
+ //#region src/plugins/remarkDirectiveToMdx.ts
106
+ function O() {
107
+ return (e) => {
108
+ let t = e;
109
+ return t.children = t.children.map(j), e;
110
+ };
211
111
  }
212
- var PURE_LEAVES = /* @__PURE__ */ new Set(["youtube"]);
213
- function isDirective(node) {
214
- return node.type === "containerDirective" || node.type === "leafDirective" || node.type === "textDirective";
112
+ var k = /* @__PURE__ */ new Set(["youtube"]);
113
+ function A(e) {
114
+ return e.type === "containerDirective" || e.type === "leafDirective" || e.type === "textDirective";
215
115
  }
216
- function transform(node) {
217
- if (!isDirective(node)) {
218
- const children2 = node.children;
219
- if (Array.isArray(children2)) {
220
- node.children = children2.map(transform);
221
- }
222
- return node;
223
- }
224
- if (node.type === "textDirective") {
225
- if (node.name === "tooltip") {
226
- return inlineTooltip(node);
227
- }
228
- return literalDirective(node);
229
- }
230
- if (node.type === "leafDirective" && node.name === "tooltip") {
231
- return literalDirective(node);
232
- }
233
- const children = node.type === "containerDirective" && !PURE_LEAVES.has(node.name) ? (node.children ?? []).map(transform) : [];
234
- return directiveToElement(node, children);
116
+ function j(e) {
117
+ if (!A(e)) {
118
+ let t = e.children;
119
+ return Array.isArray(t) && (e.children = t.map(j)), e;
120
+ }
121
+ return e.type === "textDirective" ? e.name === "tooltip" ? P(e) : N(e) : e.type === "leafDirective" && e.name === "tooltip" ? N(e) : M(e, e.type === "containerDirective" && !k.has(e.name) ? (e.children ?? []).map(j) : []);
235
122
  }
236
- function directiveToElement(directive, children) {
237
- const name = pascalCase(directive.name);
238
- const attributes = Object.entries(directive.attributes ?? {}).map(([attrName, value]) => ({
239
- type: "mdxJsxAttribute",
240
- name: attrName,
241
- value: value === "" ? null : value
242
- }));
243
- return {
244
- type: "mdxJsxFlowElement",
245
- name,
246
- attributes,
247
- children
248
- };
123
+ function M(e, t) {
124
+ return {
125
+ type: "mdxJsxFlowElement",
126
+ name: F(e.name),
127
+ attributes: Object.entries(e.attributes ?? {}).map(([e, t]) => ({
128
+ type: "mdxJsxAttribute",
129
+ name: e,
130
+ value: t === "" ? null : t
131
+ })),
132
+ children: t
133
+ };
249
134
  }
250
- function literalDirective(directive) {
251
- const literal = ":" + directive.name + (directive.label ? `[${directive.label}]` : "");
252
- const attrStr = Object.entries(directive.attributes ?? {}).map(([k, v]) => v === "" ? k : `${k}="${v}"`).join(" ");
253
- return { type: "text", value: literal + (attrStr ? `{${attrStr}}` : "") };
135
+ function N(e) {
136
+ let t = ":" + e.name + (e.label ? `[${e.label}]` : ""), n = Object.entries(e.attributes ?? {}).map(([e, t]) => t === "" ? e : `${e}="${t}"`).join(" ");
137
+ return {
138
+ type: "text",
139
+ value: t + (n ? `{${n}}` : "")
140
+ };
254
141
  }
255
- function inlineTooltip(directive) {
256
- const label = (directive.children ?? []).map((child) => child.value ?? "").join("");
257
- const attrs = directive.attributes ?? {};
258
- const attributes = [
259
- { type: "mdxJsxAttribute", name: "text", value: attrs.text || label || "?" },
260
- { type: "mdxJsxAttribute", name: "tip", value: attrs.tip || label || "" }
261
- ];
262
- return { type: "mdxJsxTextElement", name: "Tooltip", attributes, children: [] };
142
+ function P(e) {
143
+ let t = (e.children ?? []).map((e) => e.value ?? "").join(""), n = e.attributes ?? {};
144
+ return {
145
+ type: "mdxJsxTextElement",
146
+ name: "Tooltip",
147
+ attributes: [{
148
+ type: "mdxJsxAttribute",
149
+ name: "text",
150
+ value: n.text || t || "?"
151
+ }, {
152
+ type: "mdxJsxAttribute",
153
+ name: "tip",
154
+ value: n.tip || t || ""
155
+ }],
156
+ children: []
157
+ };
263
158
  }
264
- function pascalCase(name) {
265
- return name.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
159
+ function F(e) {
160
+ return e.split("-").map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join("");
266
161
  }
267
-
268
- // src/compile.ts
269
- import remarkDirective from "remark-directive";
270
-
271
- // src/mdx-compiler/index.ts
272
- import React, { useEffect, useState, useMemo } from "react";
273
- import * as jsxRuntime from "react/jsx-runtime";
274
- import * as jsxDevRuntime from "react/jsx-dev-runtime";
275
- import * as mdx from "@mdx-js/react";
276
- function MDXRemote({
277
- compiledSource,
278
- frontmatter,
279
- scope = {},
280
- components = {},
281
- lazy
282
- }) {
283
- const [ready, setReady] = useState(!lazy || typeof window === "undefined");
284
- useEffect(() => {
285
- if (!lazy) return;
286
- const id = window.requestIdleCallback ? window.requestIdleCallback(() => setReady(true), { timeout: 500 }) : setTimeout(() => setReady(true), 1);
287
- return () => {
288
- if (window.cancelIdleCallback) window.cancelIdleCallback(id);
289
- else clearTimeout(id);
290
- };
291
- }, [lazy]);
292
- const Content = useMemo(() => {
293
- const fullScope = {
294
- opts: { ...mdx, ...jsxRuntime, ...jsxDevRuntime },
295
- frontmatter,
296
- ...scope
297
- };
298
- const keys = Object.keys(fullScope);
299
- const values = Object.values(fullScope);
300
- const fn = Reflect.construct(Function, keys.concat(`${compiledSource}`));
301
- return fn.apply(fn, values).default;
302
- }, [compiledSource, scope, frontmatter]);
303
- if (!ready) {
304
- return React.createElement("div", {
305
- dangerouslySetInnerHTML: { __html: "" },
306
- suppressHydrationWarning: true
307
- });
308
- }
309
- const content = React.createElement(
310
- mdx.MDXProvider,
311
- { components },
312
- React.createElement(Content, null)
313
- );
314
- return lazy ? React.createElement("div", null, content) : content;
162
+ //#endregion
163
+ //#region src/mdx-compiler/index.ts
164
+ function I({ compiledSource: e, frontmatter: t, scope: n = {}, components: r = {}, lazy: i }) {
165
+ let [a, o] = _(!i || typeof window > "u");
166
+ h(() => {
167
+ if (!i) return;
168
+ let e = window.requestIdleCallback ? window.requestIdleCallback(() => o(!0), { timeout: 500 }) : setTimeout(() => o(!0), 1);
169
+ return () => {
170
+ window.cancelIdleCallback ? window.cancelIdleCallback(e) : clearTimeout(e);
171
+ };
172
+ }, [i]);
173
+ let s = g(() => {
174
+ let r = {
175
+ opts: {
176
+ ...b,
177
+ ...v,
178
+ ...y
179
+ },
180
+ frontmatter: t,
181
+ ...n
182
+ }, i = Object.keys(r), a = Object.values(r), o = Reflect.construct(Function, i.concat(`${e}`));
183
+ return o.apply(o, a).default;
184
+ }, [
185
+ e,
186
+ n,
187
+ t
188
+ ]);
189
+ if (!a) return m.createElement("div", {
190
+ dangerouslySetInnerHTML: { __html: "" },
191
+ suppressHydrationWarning: !0
192
+ });
193
+ let c = m.createElement(b.MDXProvider, { components: r }, m.createElement(s, null));
194
+ return i ? m.createElement("div", null, c) : c;
315
195
  }
316
-
317
- // src/compile.ts
318
- var preProcess = () => (tree) => {
319
- visit4(tree, (node) => {
320
- const element = node;
321
- if (element?.type === "element" && element?.tagName === "pre" && element.children) {
322
- const [codeEl] = element.children;
323
- if (codeEl.tagName !== "code" || !codeEl.children?.[0]) return;
324
- const className = codeEl.properties?.className;
325
- const classList = Array.isArray(className) ? className : typeof className === "string" ? className.split(" ").filter(Boolean) : [];
326
- const languageClass = classList.find((item) => item.startsWith("language-"));
327
- if (languageClass) {
328
- element.language = languageClass.replace("language-", "").split(":")[0];
329
- }
330
- const textNode = codeEl.children[0];
331
- if (textNode.type === "text" && textNode.value) {
332
- element.raw = textNode.value;
333
- }
334
- }
335
- });
336
- return tree;
337
- };
338
- var postProcess = () => (tree) => {
339
- visit4(tree, "element", (node) => {
340
- const element = node;
341
- if (element?.type === "element" && element?.tagName === "pre") {
342
- if (element.properties && element.raw) {
343
- element.properties.raw = element.raw;
344
- }
345
- if (element.properties && element.language && !element.properties["data-language"]) {
346
- element.properties["data-language"] = element.language;
347
- }
348
- if (element.properties && element.codeTitle && !element.properties["data-title"]) {
349
- element.properties["data-title"] = element.codeTitle;
350
- }
351
- }
352
- });
353
- return tree;
354
- };
355
- function createDefaultRehypePlugins() {
356
- return [
357
- preProcess,
358
- rehypeMermaid,
359
- // Transform ```mermaid before code transforms
360
- rehypeCodeTitles,
361
- handleCodeTitles,
362
- handleCodeExpandable,
363
- // Copy expandable metadata from <code> to <pre> before prism transforms nodes.
364
- rehypePrism,
365
- handleCodeExpandable,
366
- // Re-apply expandable attrs after prism tokenization.
367
- rehypeSlug,
368
- rehypeAutolinkHeadings,
369
- postProcess
370
- ];
196
+ //#endregion
197
+ //#region src/compile.ts
198
+ var L = () => (e) => (s(e, (e) => {
199
+ let t = e;
200
+ if (t?.type === "element" && t?.tagName === "pre" && t.children) {
201
+ let [e] = t.children;
202
+ if (e.tagName !== "code" || !e.children?.[0]) return;
203
+ let n = e.properties?.className, r = (Array.isArray(n) ? n : typeof n == "string" ? n.split(" ").filter(Boolean) : []).find((e) => e.startsWith("language-"));
204
+ r && (t.language = r.replace("language-", "").split(":")[0]);
205
+ let i = e.children[0];
206
+ i.type === "text" && i.value && (t.raw = i.value);
207
+ }
208
+ }), e), R = () => (e) => (s(e, "element", (e) => {
209
+ let t = e;
210
+ t?.type === "element" && t?.tagName === "pre" && (t.properties && t.raw && (t.properties.raw = t.raw), t.properties && t.language && !t.properties["data-language"] && (t.properties["data-language"] = t.language), t.properties && t.codeTitle && !t.properties["data-title"] && (t.properties["data-title"] = t.codeTitle));
211
+ }), e);
212
+ function z() {
213
+ return [
214
+ L,
215
+ D,
216
+ f,
217
+ S,
218
+ E,
219
+ l,
220
+ E,
221
+ d,
222
+ u,
223
+ R
224
+ ];
371
225
  }
372
- function createDefaultRemarkPlugins() {
373
- return [remarkGfm, handleCodeExpandableRemark, remarkDirective, remarkDirectiveToMdx];
226
+ function B() {
227
+ return [
228
+ c,
229
+ T,
230
+ p,
231
+ O
232
+ ];
374
233
  }
375
-
376
- // src/extract.ts
377
- import matter from "@11ty/gray-matter";
378
- var FENCE_MARKER_REGEX = /^(````|```)(?!`)/;
379
- var HEADING_REGEX = /^(#{2,4})\s+(.+)$/;
380
- function sluggify(text) {
381
- const normalized = text.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
382
- const slug = normalized.toLowerCase().replace(/\s+/g, "-");
383
- return slug.replace(/[^a-z0-9-]/g, "");
234
+ //#endregion
235
+ //#region src/extract.ts
236
+ var V = /^(````|```)(?!`)/, H = /^(#{2,4})\s+(.+)$/;
237
+ function U(e) {
238
+ return e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
384
239
  }
385
- function extractTocsFromRawMdx(rawMdx) {
386
- const extractedHeadings = [];
387
- const lines = rawMdx.split(/\r?\n/);
388
- let inFence = false;
389
- let fenceLength = 0;
390
- for (const line of lines) {
391
- const trimmed = line.trimStart();
392
- const fenceMatch = FENCE_MARKER_REGEX.exec(trimmed);
393
- if (fenceMatch) {
394
- const marker = fenceMatch[1];
395
- if (!inFence) {
396
- inFence = true;
397
- fenceLength = marker.length;
398
- } else if (marker.length === fenceLength) {
399
- inFence = false;
400
- }
401
- continue;
402
- }
403
- if (inFence) {
404
- continue;
405
- }
406
- const headingMatch = HEADING_REGEX.exec(trimmed);
407
- if (headingMatch) {
408
- const headingLevel = headingMatch[1].length;
409
- const headingText = headingMatch[2].trim().replace(/\s+#+\s*$/, "");
410
- extractedHeadings.push({
411
- level: headingLevel,
412
- text: headingText,
413
- href: `#${sluggify(headingText)}`
414
- });
415
- continue;
416
- }
417
- }
418
- return extractedHeadings;
240
+ function W(e) {
241
+ let t = [], n = e.split(/\r?\n/), r = !1, i = 0;
242
+ for (let e of n) {
243
+ let n = e.trimStart(), a = V.exec(n);
244
+ if (a) {
245
+ let e = a[1];
246
+ r ? e.length === i && (r = !1) : (r = !0, i = e.length);
247
+ continue;
248
+ }
249
+ if (r) continue;
250
+ let o = H.exec(n);
251
+ if (o) {
252
+ let e = o[1].length, n = o[2].trim().replace(/\s+#+\s*$/, "");
253
+ t.push({
254
+ level: e,
255
+ text: n,
256
+ href: `#${U(n)}`
257
+ });
258
+ continue;
259
+ }
260
+ }
261
+ return t;
419
262
  }
420
- function extractFrontmatter(content) {
421
- try {
422
- return matter(content).data;
423
- } catch (error) {
424
- const reason = error instanceof Error ? error.message : String(error);
425
- throw new Error(`Failed to extract frontmatter: ${reason}`, { cause: error });
426
- }
263
+ function G(e) {
264
+ try {
265
+ return x(e).data;
266
+ } catch (e) {
267
+ let t = e instanceof Error ? e.message : String(e);
268
+ throw Error(`Failed to extract frontmatter: ${t}`, { cause: e });
269
+ }
427
270
  }
428
- function extractFrontmatterWithContent(content, schema) {
429
- try {
430
- const { data, content: strippedContent } = matter(content);
431
- return {
432
- frontmatter: schema ? schema.parse(data) : data,
433
- strippedContent
434
- };
435
- } catch (error) {
436
- const reason = error instanceof Error ? error.message : String(error);
437
- throw new Error(`Failed to extract frontmatter: ${reason}`, { cause: error });
438
- }
271
+ function K(e, t) {
272
+ try {
273
+ let { data: n, content: r } = x(e);
274
+ return {
275
+ frontmatter: t ? t.parse(n) : n,
276
+ strippedContent: r
277
+ };
278
+ } catch (e) {
279
+ let t = e instanceof Error ? e.message : String(e);
280
+ throw Error(`Failed to extract frontmatter: ${t}`, { cause: e });
281
+ }
439
282
  }
440
- export {
441
- MDXRemote,
442
- cn,
443
- createDefaultRehypePlugins,
444
- createDefaultRemarkPlugins,
445
- extractFrontmatter,
446
- extractFrontmatterWithContent,
447
- extractTocsFromRawMdx,
448
- formatDate,
449
- formatDate2,
450
- handleCodeExpandable,
451
- handleCodeExpandableRemark,
452
- handleCodeTitles,
453
- parseDate,
454
- postProcess,
455
- preProcess,
456
- rehypeMermaid,
457
- remarkDirectiveToMdx,
458
- serialize,
459
- sluggify,
460
- stringToDate,
461
- toIsoDateOnly
462
- };
283
+ //#endregion
284
+ export { I as MDXRemote, e as cn, z as createDefaultRehypePlugins, B as createDefaultRemarkPlugins, G as extractFrontmatter, K as extractFrontmatterWithContent, W as extractTocsFromRawMdx, t as formatDate, n as formatDate2, E as handleCodeExpandable, T as handleCodeExpandableRemark, S as handleCodeTitles, r as parseDate, R as postProcess, L as preProcess, D as rehypeMermaid, O as remarkDirectiveToMdx, o as serialize, U as sluggify, i as stringToDate, a as toIsoDateOnly };
285
+
463
286
  //# sourceMappingURL=index.js.map