@vezham/docs-core 1.0.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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/advanced-Ct13khZr.js +79 -0
- package/dist/algolia-C0E5qQhM.d.ts +66 -0
- package/dist/breadcrumb.d.ts +46 -0
- package/dist/breadcrumb.js +59 -0
- package/dist/build-doc-4OvfjVN2.js +85 -0
- package/dist/client-kQ39Ub0-.d.ts +247 -0
- package/dist/codeblock-utils-CyP8qsYv.d.ts +29 -0
- package/dist/content/github.d.ts +41 -0
- package/dist/content/github.js +28 -0
- package/dist/content/md/frontmatter.d.ts +15 -0
- package/dist/content/md/frontmatter.js +24 -0
- package/dist/content/md.d.ts +24 -0
- package/dist/content/md.js +43 -0
- package/dist/content/mdx/preset-bundler.d.ts +29 -0
- package/dist/content/mdx/preset-bundler.js +39 -0
- package/dist/content/mdx/preset-runtime.d.ts +26 -0
- package/dist/content/mdx/preset-runtime.js +36 -0
- package/dist/content/toc.d.ts +19 -0
- package/dist/content/toc.js +14 -0
- package/dist/definitions-CFOhwE1k.d.ts +72 -0
- package/dist/dynamic-CTsodhTH.js +905 -0
- package/dist/dynamic-link.d.ts +12 -0
- package/dist/dynamic-link.js +31 -0
- package/dist/endpoint-MyoBU5IC.js +28 -0
- package/dist/framework/astro.d.ts +21 -0
- package/dist/framework/astro.js +52 -0
- package/dist/framework/index.d.ts +40 -0
- package/dist/framework/index.js +66 -0
- package/dist/framework/next.d.ts +10 -0
- package/dist/framework/next.js +19 -0
- package/dist/framework/react-router.d.ts +10 -0
- package/dist/framework/react-router.js +43 -0
- package/dist/framework/tanstack.d.ts +13 -0
- package/dist/framework/tanstack.js +54 -0
- package/dist/framework/waku.d.ts +10 -0
- package/dist/framework/waku.js +46 -0
- package/dist/highlight/client.d.ts +11 -0
- package/dist/highlight/client.js +15 -0
- package/dist/highlight/index.d.ts +31 -0
- package/dist/highlight/index.js +30 -0
- package/dist/highlight/shiki/full.d.ts +7 -0
- package/dist/highlight/shiki/full.js +23 -0
- package/dist/highlight/shiki/index.d.ts +2 -0
- package/dist/highlight/shiki/index.js +27 -0
- package/dist/highlight/shiki/react.d.ts +23 -0
- package/dist/highlight/shiki/react.js +50 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.js +63 -0
- package/dist/i18n/middleware.d.ts +34 -0
- package/dist/i18n/middleware.js +3855 -0
- package/dist/icon-BILaoXeg.js +17 -0
- package/dist/index-B-0R0VbS.d.ts +18 -0
- package/dist/index-BM36H-xw.d.ts +36 -0
- package/dist/index-BMEUQz-F.d.ts +21 -0
- package/dist/index-DAYtLGbx.d.ts +16 -0
- package/dist/index-DIwKCYOz.d.ts +513 -0
- package/dist/index-DydiXvgS.d.ts +90 -0
- package/dist/index-E8Qh_yQs.d.ts +49 -0
- package/dist/is-equal-LdLqRs0o.js +8 -0
- package/dist/link.d.ts +17 -0
- package/dist/link.js +23 -0
- package/dist/mdx-plugins/codeblock-utils.d.ts +2 -0
- package/dist/mdx-plugins/codeblock-utils.js +68 -0
- package/dist/mdx-plugins/index.d.ts +20 -0
- package/dist/mdx-plugins/index.js +18 -0
- package/dist/mdx-plugins/rehype-code.core.d.ts +3 -0
- package/dist/mdx-plugins/rehype-code.core.js +3 -0
- package/dist/mdx-plugins/rehype-code.d.ts +4 -0
- package/dist/mdx-plugins/rehype-code.js +24 -0
- package/dist/mdx-plugins/rehype-toc.d.ts +2 -0
- package/dist/mdx-plugins/rehype-toc.js +139 -0
- package/dist/mdx-plugins/remark-admonition.d.ts +2 -0
- package/dist/mdx-plugins/remark-admonition.js +71 -0
- package/dist/mdx-plugins/remark-block-id.d.ts +37 -0
- package/dist/mdx-plugins/remark-block-id.js +41 -0
- package/dist/mdx-plugins/remark-code-tab.d.ts +2 -0
- package/dist/mdx-plugins/remark-code-tab.js +190 -0
- package/dist/mdx-plugins/remark-directive-admonition.d.ts +2 -0
- package/dist/mdx-plugins/remark-directive-admonition.js +57 -0
- package/dist/mdx-plugins/remark-feedback-block.d.ts +2 -0
- package/dist/mdx-plugins/remark-feedback-block.js +54 -0
- package/dist/mdx-plugins/remark-gfm.d.ts +2 -0
- package/dist/mdx-plugins/remark-gfm.js +2 -0
- package/dist/mdx-plugins/remark-heading.d.ts +2 -0
- package/dist/mdx-plugins/remark-heading.js +46 -0
- package/dist/mdx-plugins/remark-image.d.ts +2 -0
- package/dist/mdx-plugins/remark-image.js +167 -0
- package/dist/mdx-plugins/remark-llms.d.ts +2 -0
- package/dist/mdx-plugins/remark-llms.js +338 -0
- package/dist/mdx-plugins/remark-llms.runtime.d.ts +10 -0
- package/dist/mdx-plugins/remark-llms.runtime.js +24 -0
- package/dist/mdx-plugins/remark-mdx-files.d.ts +2 -0
- package/dist/mdx-plugins/remark-mdx-files.js +182 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +2 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.js +28 -0
- package/dist/mdx-plugins/remark-npm.d.ts +2 -0
- package/dist/mdx-plugins/remark-npm.js +76 -0
- package/dist/mdx-plugins/remark-steps.d.ts +2 -0
- package/dist/mdx-plugins/remark-steps.js +93 -0
- package/dist/mdx-plugins/remark-structure.d.ts +2 -0
- package/dist/mdx-plugins/remark-structure.js +118 -0
- package/dist/mdx-plugins/stringifier.d.ts +2 -0
- package/dist/mdx-plugins/stringifier.js +91 -0
- package/dist/mdx-plugins/transformer-icon.d.ts +2 -0
- package/dist/mdx-plugins/transformer-icon.js +145 -0
- package/dist/negotiation/index.d.ts +17 -0
- package/dist/negotiation/index.js +378 -0
- package/dist/page-tree/index.d.ts +3 -0
- package/dist/page-tree/index.js +2 -0
- package/dist/path-1H5VzYiT.js +75 -0
- package/dist/rehype-code-D-RFJb9W.d.ts +14 -0
- package/dist/rehype-code.core-BUwNuchP.js +548 -0
- package/dist/rehype-code.core-BjH1uHWj.d.ts +115 -0
- package/dist/rehype-toc-K51AGb5U.d.ts +43 -0
- package/dist/remark-admonition-BwTcmI_S.d.ts +20 -0
- package/dist/remark-code-tab-DE_4bdnu.d.ts +34 -0
- package/dist/remark-directive-admonition-BLiJ5l43.d.ts +27 -0
- package/dist/remark-feedback-block-BxtINXN-.d.ts +45 -0
- package/dist/remark-gfm-DpVfAX1x.d.ts +2 -0
- package/dist/remark-heading-DEIzTkU5.d.ts +33 -0
- package/dist/remark-image-BI2S9LOb.d.ts +57 -0
- package/dist/remark-llms-bD3WvU2V.d.ts +73 -0
- package/dist/remark-mdx-files-Buvxc-sa.d.ts +54 -0
- package/dist/remark-mdx-mermaid-C1bCHHc6.d.ts +15 -0
- package/dist/remark-npm-BbpvkJaT.d.ts +31 -0
- package/dist/remark-steps-DqVEo0iq.d.ts +23 -0
- package/dist/remark-structure-CnHwvNZr.d.ts +87 -0
- package/dist/remove-markdown-DfKNMl9w.js +40 -0
- package/dist/remove-undefined-CzMSKybq.js +24 -0
- package/dist/rolldown-runtime-DC62tzP2.js +33 -0
- package/dist/search/algolia.d.ts +2 -0
- package/dist/search/algolia.js +75 -0
- package/dist/search/client/algolia.d.ts +2 -0
- package/dist/search/client/algolia.js +53 -0
- package/dist/search/client/fetch.d.ts +2 -0
- package/dist/search/client/fetch.js +28 -0
- package/dist/search/client/flexsearch-static.d.ts +2 -0
- package/dist/search/client/flexsearch-static.js +42 -0
- package/dist/search/client/mixedbread.d.ts +2 -0
- package/dist/search/client/mixedbread.js +65 -0
- package/dist/search/client/orama-cloud-legacy.d.ts +2 -0
- package/dist/search/client/orama-cloud-legacy.js +84 -0
- package/dist/search/client/orama-cloud.d.ts +2 -0
- package/dist/search/client/orama-cloud.js +86 -0
- package/dist/search/client/orama-static.d.ts +2 -0
- package/dist/search/client/orama-static.js +75 -0
- package/dist/search/client.d.ts +2 -0
- package/dist/search/client.js +97 -0
- package/dist/search/flexsearch.d.ts +56 -0
- package/dist/search/flexsearch.js +128 -0
- package/dist/search/index.d.ts +2 -0
- package/dist/search/index.js +74 -0
- package/dist/search/mixedbread.d.ts +49 -0
- package/dist/search/mixedbread.js +77 -0
- package/dist/search/orama-cloud-legacy.d.ts +75 -0
- package/dist/search/orama-cloud-legacy.js +48 -0
- package/dist/search/orama-cloud.d.ts +75 -0
- package/dist/search/orama-cloud.js +50 -0
- package/dist/search/server.d.ts +2 -0
- package/dist/search/server.js +237 -0
- package/dist/server-CCqACwlF.d.ts +165 -0
- package/dist/server.browser.d.ts +13 -0
- package/dist/server.browser.js +22 -0
- package/dist/server.d.ts +42 -0
- package/dist/server.js +398 -0
- package/dist/source/client/index.d.ts +2 -0
- package/dist/source/client/index.js +37 -0
- package/dist/source/dynamic.d.ts +2 -0
- package/dist/source/dynamic.js +2 -0
- package/dist/source/index.d.ts +2 -0
- package/dist/source/index.js +5 -0
- package/dist/source/llms.d.ts +2 -0
- package/dist/source/llms.js +74 -0
- package/dist/source/plugins/lucide-icons.d.ts +11 -0
- package/dist/source/plugins/lucide-icons.js +21 -0
- package/dist/source/plugins/slugs.d.ts +2 -0
- package/dist/source/plugins/slugs.js +75 -0
- package/dist/source/plugins/status-badges.d.ts +50 -0
- package/dist/source/plugins/status-badges.js +52 -0
- package/dist/source/schema.d.ts +30 -0
- package/dist/source/schema.js +28 -0
- package/dist/stringifier-B_QUcUyo.d.ts +63 -0
- package/dist/toc-CtW5lwA1.d.ts +64 -0
- package/dist/toc.d.ts +2 -0
- package/dist/toc.js +245 -0
- package/dist/transformer-icon-DlrneIS3.d.ts +17 -0
- package/dist/types-D89QoQR-.d.ts +4 -0
- package/dist/url-BVHvi3_K.js +29 -0
- package/dist/util-BDsqOxh3.d.ts +6 -0
- package/dist/util-DjBr9b3w.js +8 -0
- package/dist/utils/use-media-query.d.ts +4 -0
- package/dist/utils/use-media-query.js +20 -0
- package/dist/utils/use-on-change.d.ts +9 -0
- package/dist/utils/use-on-change.js +17 -0
- package/dist/utils-Bvy3V-fv.js +59 -0
- package/dist/utils-Cgs-6U-z.js +39 -0
- package/dist/utils-DEVq3cEC.js +151 -0
- package/dist/utils-Yx0IL9eW.js +48 -0
- package/package.json +251 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { generateCodeBlockTabs, parseCodeBlockAttributes } from "./codeblock-utils.js";
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
//#region src/mdx-plugins/remark-code-tab.ts
|
|
4
|
+
const Types = {
|
|
5
|
+
CodeBlockTabs(processor, nodes, withMdx, withParent) {
|
|
6
|
+
const tabs = processTabValue(nodes);
|
|
7
|
+
let isFirstTab = true;
|
|
8
|
+
const options = {
|
|
9
|
+
triggers: [],
|
|
10
|
+
tabs: []
|
|
11
|
+
};
|
|
12
|
+
for (const [value, list] of tabs) {
|
|
13
|
+
if (isFirstTab) {
|
|
14
|
+
const tagGroup = list[0].data?.tabGroup;
|
|
15
|
+
options.defaultValue = value;
|
|
16
|
+
if (tagGroup) options.persist = { id: tagGroup };
|
|
17
|
+
isFirstTab = false;
|
|
18
|
+
}
|
|
19
|
+
options.triggers.push({
|
|
20
|
+
value,
|
|
21
|
+
children: withMdx ? mdxToAst(processor, value).children : [{
|
|
22
|
+
type: "text",
|
|
23
|
+
value
|
|
24
|
+
}]
|
|
25
|
+
});
|
|
26
|
+
options.tabs.push({
|
|
27
|
+
value,
|
|
28
|
+
children: list
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const node = generateCodeBlockTabs(options);
|
|
32
|
+
if (!withParent) return node.children;
|
|
33
|
+
return [node];
|
|
34
|
+
},
|
|
35
|
+
Tabs(processor, nodes, withMdx, withParent) {
|
|
36
|
+
const tabs = Array.from(processTabValue(nodes).entries());
|
|
37
|
+
if (!withMdx) {
|
|
38
|
+
const children = tabs.map(([name, codes]) => {
|
|
39
|
+
return {
|
|
40
|
+
type: "mdxJsxFlowElement",
|
|
41
|
+
name: "Tab",
|
|
42
|
+
attributes: [{
|
|
43
|
+
type: "mdxJsxAttribute",
|
|
44
|
+
name: "value",
|
|
45
|
+
value: name
|
|
46
|
+
}],
|
|
47
|
+
children: codes
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
if (!withParent) return children;
|
|
51
|
+
return [{
|
|
52
|
+
type: "mdxJsxFlowElement",
|
|
53
|
+
name: "Tabs",
|
|
54
|
+
attributes: [{
|
|
55
|
+
type: "mdxJsxAttribute",
|
|
56
|
+
name: "items",
|
|
57
|
+
value: {
|
|
58
|
+
type: "mdxJsxAttributeValueExpression",
|
|
59
|
+
value: tabs.map(([name]) => name).join(", "),
|
|
60
|
+
data: { estree: {
|
|
61
|
+
type: "Program",
|
|
62
|
+
sourceType: "module",
|
|
63
|
+
comments: [],
|
|
64
|
+
body: [{
|
|
65
|
+
type: "ExpressionStatement",
|
|
66
|
+
expression: {
|
|
67
|
+
type: "ArrayExpression",
|
|
68
|
+
elements: tabs.map(([name]) => ({
|
|
69
|
+
type: "Literal",
|
|
70
|
+
value: name
|
|
71
|
+
}))
|
|
72
|
+
}
|
|
73
|
+
}]
|
|
74
|
+
} }
|
|
75
|
+
}
|
|
76
|
+
}],
|
|
77
|
+
children
|
|
78
|
+
}];
|
|
79
|
+
}
|
|
80
|
+
const children = [{
|
|
81
|
+
type: "mdxJsxFlowElement",
|
|
82
|
+
name: "TabsList",
|
|
83
|
+
attributes: [],
|
|
84
|
+
children: tabs.map(([name]) => ({
|
|
85
|
+
type: "mdxJsxFlowElement",
|
|
86
|
+
name: "TabsTrigger",
|
|
87
|
+
attributes: [{
|
|
88
|
+
type: "mdxJsxAttribute",
|
|
89
|
+
name: "value",
|
|
90
|
+
value: name
|
|
91
|
+
}],
|
|
92
|
+
children: [mdxToAst(processor, name)]
|
|
93
|
+
}))
|
|
94
|
+
}, ...tabs.map(([name, codes]) => ({
|
|
95
|
+
type: "mdxJsxFlowElement",
|
|
96
|
+
name: "TabsContent",
|
|
97
|
+
attributes: [{
|
|
98
|
+
type: "mdxJsxAttribute",
|
|
99
|
+
name: "value",
|
|
100
|
+
value: name
|
|
101
|
+
}],
|
|
102
|
+
children: codes
|
|
103
|
+
}))];
|
|
104
|
+
if (!withParent) return children;
|
|
105
|
+
return [{
|
|
106
|
+
type: "mdxJsxFlowElement",
|
|
107
|
+
name: "Tabs",
|
|
108
|
+
attributes: [{
|
|
109
|
+
type: "mdxJsxAttribute",
|
|
110
|
+
name: "defaultValue",
|
|
111
|
+
value: tabs[0][0]
|
|
112
|
+
}],
|
|
113
|
+
children
|
|
114
|
+
}];
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function remarkCodeTab(options = {}) {
|
|
118
|
+
const { parseMdx = false, Tabs = "CodeBlockTabs" } = options;
|
|
119
|
+
return (tree) => {
|
|
120
|
+
visit(tree, (node) => {
|
|
121
|
+
if (!("children" in node) || node.data?._code_tab_visited) return "skip";
|
|
122
|
+
let localTabs = Tabs;
|
|
123
|
+
let localParseMdx = parseMdx;
|
|
124
|
+
let withParent = true;
|
|
125
|
+
if (node.type === "mdxJsxFlowElement" && node.name && node.name in Types) {
|
|
126
|
+
withParent = false;
|
|
127
|
+
localTabs = node.name;
|
|
128
|
+
if (node.name === "Tabs" && localParseMdx) localParseMdx = node.attributes.every((attribute) => attribute.type !== "mdxJsxAttribute" || attribute.name !== "items");
|
|
129
|
+
}
|
|
130
|
+
let start = -1;
|
|
131
|
+
let end = 0;
|
|
132
|
+
const close = () => {
|
|
133
|
+
if (start === -1 || start === end) return;
|
|
134
|
+
const replacement = Types[localTabs](this, node.children.slice(start, end), localParseMdx, withParent);
|
|
135
|
+
for (const element of replacement) {
|
|
136
|
+
element.data ??= {};
|
|
137
|
+
element.data._code_tab_visited = true;
|
|
138
|
+
}
|
|
139
|
+
node.children.splice(start, end - start, ...replacement);
|
|
140
|
+
end = start;
|
|
141
|
+
start = -1;
|
|
142
|
+
};
|
|
143
|
+
for (; end < node.children.length; end++) {
|
|
144
|
+
const child = node.children[end];
|
|
145
|
+
if (child.type !== "code" || !child.meta) {
|
|
146
|
+
close();
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const meta = parseCodeBlockAttributes(child.meta, ["tab", "tab-group"]);
|
|
150
|
+
if (typeof meta.attributes.tab !== "string") {
|
|
151
|
+
close();
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (start === -1) start = end;
|
|
155
|
+
child.meta = meta.rest;
|
|
156
|
+
child.data ??= {};
|
|
157
|
+
child.data.tab = meta.attributes.tab;
|
|
158
|
+
if (typeof meta.attributes["tab-group"] === "string") child.data.tabGroup = meta.attributes["tab-group"];
|
|
159
|
+
}
|
|
160
|
+
close();
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function processTabValue(nodes) {
|
|
165
|
+
const out = /* @__PURE__ */ new Map();
|
|
166
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
167
|
+
const node = nodes[i];
|
|
168
|
+
const name = node.data?.tab ?? `Tab ${i + 1}`;
|
|
169
|
+
let li = out.get(name);
|
|
170
|
+
if (!li) {
|
|
171
|
+
li = [];
|
|
172
|
+
out.set(name, li);
|
|
173
|
+
}
|
|
174
|
+
li.push(node);
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* MDX tab name to tab trigger node children
|
|
180
|
+
*/
|
|
181
|
+
function mdxToAst(processor, name) {
|
|
182
|
+
const node = processor.parse(name);
|
|
183
|
+
node.children = node.children.flatMap((child) => {
|
|
184
|
+
if (child.type === "paragraph") return child.children;
|
|
185
|
+
return child;
|
|
186
|
+
});
|
|
187
|
+
return node;
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
export { remarkCodeTab };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { visit } from "unist-util-visit";
|
|
2
|
+
//#region src/mdx-plugins/remark-directive-admonition.ts
|
|
3
|
+
/**
|
|
4
|
+
* Remark Plugin to support Admonition syntax in Docusaurus, useful for migrating from Docusaurus.
|
|
5
|
+
*
|
|
6
|
+
* Requires [`remark-directive`](https://github.com/remarkjs/remark-directive) to be configured.
|
|
7
|
+
*/
|
|
8
|
+
function remarkDirectiveAdmonition({ tags: { CalloutContainer = "CalloutContainer", CalloutTitle = "CalloutTitle", CalloutDescription = "CalloutDescription" } = {}, types = {
|
|
9
|
+
note: "info",
|
|
10
|
+
tip: "info",
|
|
11
|
+
info: "info",
|
|
12
|
+
warn: "warning",
|
|
13
|
+
warning: "warning",
|
|
14
|
+
danger: "error",
|
|
15
|
+
success: "success"
|
|
16
|
+
} } = {}) {
|
|
17
|
+
return (tree) => {
|
|
18
|
+
visit(tree, "containerDirective", (node) => {
|
|
19
|
+
if (!(node.name in types)) return;
|
|
20
|
+
const attributes = [{
|
|
21
|
+
type: "mdxJsxAttribute",
|
|
22
|
+
name: "type",
|
|
23
|
+
value: types[node.name]
|
|
24
|
+
}];
|
|
25
|
+
for (const [k, v] of Object.entries(node.attributes ?? {})) attributes.push({
|
|
26
|
+
type: "mdxJsxAttribute",
|
|
27
|
+
name: k,
|
|
28
|
+
value: v
|
|
29
|
+
});
|
|
30
|
+
const titleNodes = [];
|
|
31
|
+
const descriptionNodes = [];
|
|
32
|
+
for (const item of node.children) if (item.type === "paragraph" && item.data?.directiveLabel) titleNodes.push(...item.children);
|
|
33
|
+
else descriptionNodes.push(item);
|
|
34
|
+
const children = [];
|
|
35
|
+
if (titleNodes.length > 0) children.push({
|
|
36
|
+
type: "mdxJsxFlowElement",
|
|
37
|
+
name: CalloutTitle,
|
|
38
|
+
attributes: [],
|
|
39
|
+
children: titleNodes
|
|
40
|
+
});
|
|
41
|
+
if (descriptionNodes.length > 0) children.push({
|
|
42
|
+
type: "mdxJsxFlowElement",
|
|
43
|
+
name: CalloutDescription,
|
|
44
|
+
attributes: [],
|
|
45
|
+
children: descriptionNodes
|
|
46
|
+
});
|
|
47
|
+
Object.assign(node, {
|
|
48
|
+
type: "mdxJsxFlowElement",
|
|
49
|
+
attributes,
|
|
50
|
+
name: CalloutContainer,
|
|
51
|
+
children
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { remarkDirectiveAdmonition };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { t as flattenNode } from "../utils-Yx0IL9eW.js";
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
//#region src/mdx-plugins/remark-feedback-block.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generate MDX `<FeedbackBlock />` elements with an unique `id` for every block-like element.
|
|
7
|
+
*
|
|
8
|
+
* Note: the uniqueness is only guaranteed per MDX file/page.
|
|
9
|
+
*/
|
|
10
|
+
function remarkFeedbackBlock({ generateHash = ({ body }) => createHash("md5").update(body).digest("hex").substring(0, 16), tagName = "FeedbackBlock", resolve = (node) => {
|
|
11
|
+
switch (node.type) {
|
|
12
|
+
case "mdxJsxFlowElement": return "skip";
|
|
13
|
+
case "paragraph":
|
|
14
|
+
case "image":
|
|
15
|
+
case "listItem": return true;
|
|
16
|
+
default: return false;
|
|
17
|
+
}
|
|
18
|
+
}, generateBody = true } = {}) {
|
|
19
|
+
return (tree) => {
|
|
20
|
+
const counts = /* @__PURE__ */ new Map();
|
|
21
|
+
visit(tree, (node, index, parent) => {
|
|
22
|
+
if (node.type === "root" || !parent || typeof index !== "number") return;
|
|
23
|
+
const resolved = resolve(node);
|
|
24
|
+
if (resolved === false) return;
|
|
25
|
+
if (resolved === "skip") return "skip";
|
|
26
|
+
const text = flattenNode(node).trim();
|
|
27
|
+
if (text.length === 0) return;
|
|
28
|
+
let id = generateHash({ body: text });
|
|
29
|
+
const count = counts.get(id) ?? 0;
|
|
30
|
+
if (count > 0) id = `${id}-${count}`;
|
|
31
|
+
counts.set(id, count + 1);
|
|
32
|
+
const wrapper = {
|
|
33
|
+
type: "mdxJsxFlowElement",
|
|
34
|
+
name: tagName,
|
|
35
|
+
attributes: [{
|
|
36
|
+
type: "mdxJsxAttribute",
|
|
37
|
+
name: "id",
|
|
38
|
+
value: id
|
|
39
|
+
}],
|
|
40
|
+
data: { _stringify: "children-only" },
|
|
41
|
+
children: [node]
|
|
42
|
+
};
|
|
43
|
+
if (generateBody) wrapper.attributes.push({
|
|
44
|
+
type: "mdxJsxAttribute",
|
|
45
|
+
name: "body",
|
|
46
|
+
value: text
|
|
47
|
+
});
|
|
48
|
+
parent.children[index] = wrapper;
|
|
49
|
+
return "skip";
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { remarkFeedbackBlock };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { t as flattenNode } from "../utils-Yx0IL9eW.js";
|
|
2
|
+
import Slugger from "github-slugger";
|
|
3
|
+
import { visit } from "unist-util-visit";
|
|
4
|
+
//#region src/mdx-plugins/remark-heading.ts
|
|
5
|
+
const regex = /\s*\[#(?<slug>[^]+?)]\s*$/;
|
|
6
|
+
/**
|
|
7
|
+
* Add heading ids and extract TOC
|
|
8
|
+
*/
|
|
9
|
+
function remarkHeading({ slug, customId = true, generateToc = true } = {}) {
|
|
10
|
+
let slugger;
|
|
11
|
+
if (!slug) {
|
|
12
|
+
slugger = new Slugger();
|
|
13
|
+
slug = (_root, _heading, text) => slugger.slug(text);
|
|
14
|
+
}
|
|
15
|
+
return (root, file) => {
|
|
16
|
+
const toc = [];
|
|
17
|
+
slugger?.reset();
|
|
18
|
+
visit(root, "heading", (heading) => {
|
|
19
|
+
heading.data ||= {};
|
|
20
|
+
heading.data.hProperties ||= {};
|
|
21
|
+
const props = heading.data.hProperties;
|
|
22
|
+
const lastNode = heading.children.at(-1);
|
|
23
|
+
if (lastNode?.type === "text" && customId) {
|
|
24
|
+
const match = regex.exec(lastNode.value);
|
|
25
|
+
if (match?.[1]) {
|
|
26
|
+
props.id = match[1];
|
|
27
|
+
lastNode.value = lastNode.value.slice(0, match.index);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
let flattened = null;
|
|
31
|
+
if (!props.id) {
|
|
32
|
+
flattened ??= flattenNode(heading);
|
|
33
|
+
props.id = slug(root, heading, flattened);
|
|
34
|
+
}
|
|
35
|
+
if (generateToc) toc.push({
|
|
36
|
+
title: flattened ?? flattenNode(heading),
|
|
37
|
+
url: `#${props.id}`,
|
|
38
|
+
depth: heading.depth
|
|
39
|
+
});
|
|
40
|
+
return "skip";
|
|
41
|
+
});
|
|
42
|
+
if (generateToc) file.data.toc = toc;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { remarkHeading };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { visit } from "unist-util-visit";
|
|
2
|
+
import * as path$1 from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
//#region src/mdx-plugins/remark-image.ts
|
|
5
|
+
const VALID_BLUR_EXT = [
|
|
6
|
+
".jpeg",
|
|
7
|
+
".png",
|
|
8
|
+
".webp",
|
|
9
|
+
".avif",
|
|
10
|
+
".jpg"
|
|
11
|
+
];
|
|
12
|
+
const EXTERNAL_URL_REGEX = /^https?:\/\//;
|
|
13
|
+
/**
|
|
14
|
+
* Turn images into Next.js Image compatible usage.
|
|
15
|
+
*/
|
|
16
|
+
function remarkImage({ placeholder = "none", external = true, useImport = true, onError = "error", publicDir = path$1.join(process.cwd(), "public") } = {}) {
|
|
17
|
+
return async (tree, file) => {
|
|
18
|
+
const importsToInject = [];
|
|
19
|
+
const promises = [];
|
|
20
|
+
async function updateImage(src, node) {
|
|
21
|
+
if (src.type === "file" && useImport) {
|
|
22
|
+
const variableName = `__img${importsToInject.length}`;
|
|
23
|
+
const hasBlur = placeholder === "blur" && VALID_BLUR_EXT.some((ext) => src.file.endsWith(ext));
|
|
24
|
+
if (!file.dirname) throw new Error("When `useImport` is enabled, you must specify `dirname` in the VFile passed to compiler.");
|
|
25
|
+
importsToInject.push({
|
|
26
|
+
variableName,
|
|
27
|
+
importPath: getImportPath(src.file, file.dirname)
|
|
28
|
+
});
|
|
29
|
+
const out = {
|
|
30
|
+
children: [],
|
|
31
|
+
type: "mdxJsxFlowElement",
|
|
32
|
+
name: "img",
|
|
33
|
+
attributes: [{
|
|
34
|
+
type: "mdxJsxAttribute",
|
|
35
|
+
name: "alt",
|
|
36
|
+
value: node.alt ?? "image"
|
|
37
|
+
}, {
|
|
38
|
+
type: "mdxJsxAttribute",
|
|
39
|
+
name: "src",
|
|
40
|
+
value: {
|
|
41
|
+
type: "mdxJsxAttributeValueExpression",
|
|
42
|
+
value: variableName,
|
|
43
|
+
data: { estree: {
|
|
44
|
+
body: [{
|
|
45
|
+
type: "ExpressionStatement",
|
|
46
|
+
expression: {
|
|
47
|
+
type: "Identifier",
|
|
48
|
+
name: variableName
|
|
49
|
+
}
|
|
50
|
+
}],
|
|
51
|
+
type: "Program",
|
|
52
|
+
sourceType: "script"
|
|
53
|
+
} }
|
|
54
|
+
}
|
|
55
|
+
}]
|
|
56
|
+
};
|
|
57
|
+
if (node.title) out.attributes.push({
|
|
58
|
+
type: "mdxJsxAttribute",
|
|
59
|
+
name: "title",
|
|
60
|
+
value: node.title
|
|
61
|
+
});
|
|
62
|
+
if (hasBlur) out.attributes.push({
|
|
63
|
+
type: "mdxJsxAttribute",
|
|
64
|
+
name: "placeholder",
|
|
65
|
+
value: "blur"
|
|
66
|
+
});
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
const size = await getImageSize(src, external).catch((e) => {
|
|
70
|
+
throw new Error(`[Remark Image] Failed obtain image size for ${node.url} (public directory configured as ${publicDir})`, { cause: e });
|
|
71
|
+
});
|
|
72
|
+
if (!size) return;
|
|
73
|
+
node.data ??= {};
|
|
74
|
+
node.data.hProperties ??= {};
|
|
75
|
+
node.data.hProperties.src = src.type === "url" ? src.url.href : node.url;
|
|
76
|
+
node.data.hProperties.width = size.width.toString();
|
|
77
|
+
node.data.hProperties.height = size.height.toString();
|
|
78
|
+
}
|
|
79
|
+
visit(tree, "image", (node, idx, parent) => {
|
|
80
|
+
if (typeof idx !== "number" || !parent) return;
|
|
81
|
+
const src = parseSrc(decodeURI(node.url), publicDir, file.dirname);
|
|
82
|
+
if (!src) return;
|
|
83
|
+
const task = updateImage(src, node).catch((e) => {
|
|
84
|
+
if (onError === "ignore" || node.url.endsWith(".svg")) return;
|
|
85
|
+
if (onError === "hide") {
|
|
86
|
+
parent.children.splice(idx, 1);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (onError === "error") throw e;
|
|
90
|
+
onError(e);
|
|
91
|
+
}).then((res) => {
|
|
92
|
+
if (res) parent.children[idx] = res;
|
|
93
|
+
});
|
|
94
|
+
promises.push(task);
|
|
95
|
+
});
|
|
96
|
+
await Promise.all(promises);
|
|
97
|
+
if (importsToInject.length === 0) return;
|
|
98
|
+
const imports = importsToInject.map(({ variableName, importPath }) => ({
|
|
99
|
+
type: "mdxjsEsm",
|
|
100
|
+
data: { estree: { body: [{
|
|
101
|
+
type: "ImportDeclaration",
|
|
102
|
+
source: {
|
|
103
|
+
type: "Literal",
|
|
104
|
+
value: importPath
|
|
105
|
+
},
|
|
106
|
+
specifiers: [{
|
|
107
|
+
type: "ImportDefaultSpecifier",
|
|
108
|
+
local: {
|
|
109
|
+
type: "Identifier",
|
|
110
|
+
name: variableName
|
|
111
|
+
}
|
|
112
|
+
}]
|
|
113
|
+
}] } }
|
|
114
|
+
}));
|
|
115
|
+
tree.children.unshift(...imports);
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function getImportPath(file, dir) {
|
|
119
|
+
const relative = path$1.relative(dir, file).replaceAll(path$1.sep, "/");
|
|
120
|
+
return relative.startsWith("../") ? relative : `./${relative}`;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @param src - src href
|
|
124
|
+
* @param publicDir - dir/url to resolve absolute paths
|
|
125
|
+
* @param dir - dir to resolve relative paths
|
|
126
|
+
*/
|
|
127
|
+
function parseSrc(src, publicDir, dir) {
|
|
128
|
+
if (src.startsWith("file:///")) return {
|
|
129
|
+
type: "file",
|
|
130
|
+
file: fileURLToPath(src)
|
|
131
|
+
};
|
|
132
|
+
if (EXTERNAL_URL_REGEX.test(src)) return {
|
|
133
|
+
type: "url",
|
|
134
|
+
url: new URL(src)
|
|
135
|
+
};
|
|
136
|
+
if (src.startsWith("/")) {
|
|
137
|
+
if (EXTERNAL_URL_REGEX.test(publicDir)) {
|
|
138
|
+
const url = new URL(publicDir);
|
|
139
|
+
url.pathname = `/${[...url.pathname.split("/"), ...src.split("/")].filter((v) => v.length > 0).join("/")}`;
|
|
140
|
+
return {
|
|
141
|
+
type: "url",
|
|
142
|
+
url
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
type: "file",
|
|
147
|
+
file: path$1.join(publicDir, src)
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (!dir) {
|
|
151
|
+
console.warn(`[Remark Image] found relative path ${src} but missing 'dirname' in VFile, this image will be skipped for now.`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
type: "file",
|
|
156
|
+
file: path$1.join(dir, src)
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
async function getImageSize(src, onExternal) {
|
|
160
|
+
const { probe } = await import("@fumari/image-size");
|
|
161
|
+
if (src.type === "file") return probe(src.file);
|
|
162
|
+
if (onExternal === false) return;
|
|
163
|
+
const { timeout } = typeof onExternal === "object" ? onExternal : {};
|
|
164
|
+
return probe(src.url, { timeout });
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
export { remarkImage };
|