@rasenganjs/mdx 1.0.1 → 1.0.3
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/README.md +7 -11
- package/lib/components/codeblock.d.ts +15 -0
- package/lib/components/codeblock.js +63 -0
- package/lib/components/codeblock.js.map +1 -0
- package/lib/components/heading.d.ts +2 -0
- package/lib/components/heading.js +40 -0
- package/lib/components/heading.js.map +1 -0
- package/lib/components/index.d.ts +2 -25
- package/lib/components/index.js +12 -78
- package/lib/components/index.js.map +1 -1
- package/lib/components/table.d.ts +3 -0
- package/lib/components/table.js +5 -0
- package/lib/components/table.js.map +1 -0
- package/lib/index.d.ts +3 -26
- package/lib/index.js +3 -5
- package/lib/index.js.map +1 -1
- package/lib/types/index.d.ts +25 -1
- package/lib/utils/extract-toc.d.ts +1 -0
- package/lib/utils/extract-toc.js +12 -0
- package/lib/utils/extract-toc.js.map +1 -0
- package/lib/utils/index.d.ts +1 -3
- package/lib/utils/index.js +1 -4
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mark-to-html.d.ts +1 -0
- package/lib/utils/mark-to-html.js +15 -0
- package/lib/utils/mark-to-html.js.map +1 -0
- package/lib/utils/plugin.d.ts +2 -2
- package/lib/utils/plugin.js +19 -6
- package/lib/utils/plugin.js.map +1 -1
- package/package.json +59 -52
- package/lib/utils/generate-page.d.ts +0 -10
- package/lib/utils/generate-page.js +0 -18
- package/lib/utils/generate-page.js.map +0 -1
- package/lib/utils/globals.d.ts +0 -20
- package/lib/utils/globals.js +0 -30
- package/lib/utils/globals.js.map +0 -1
- package/lib/utils/polyfills.d.ts +0 -29
- package/lib/utils/polyfills.js +0 -120
- package/lib/utils/polyfills.js.map +0 -1
- package/lib/utils/test.d.ts +0 -1
- package/lib/utils/test.js +0 -6
- package/lib/utils/test.js.map +0 -1
- package/src/components/index.tsx +0 -219
- package/src/index.ts +0 -15
- package/src/types/index.ts +0 -15
- package/src/utils/create-filter.ts +0 -26
- package/src/utils/generate-page.tsx +0 -24
- package/src/utils/globals.ts +0 -32
- package/src/utils/index.ts +0 -6
- package/src/utils/plugin.ts +0 -83
- package/src/utils/polyfills.ts +0 -120
- package/src/utils/test.js +0 -7
package/README.md
CHANGED
|
@@ -35,13 +35,8 @@ import { defineConfig } from "rasengan";
|
|
|
35
35
|
import mdx from "@rasenganjs/mdx";
|
|
36
36
|
|
|
37
37
|
export default defineConfig({
|
|
38
|
-
reactStrictMode: true,
|
|
39
|
-
|
|
40
|
-
// Define aliases
|
|
41
38
|
vite: {
|
|
42
|
-
plugins: [
|
|
43
|
-
...mdx(),
|
|
44
|
-
],
|
|
39
|
+
plugins: [mdx()],
|
|
45
40
|
},
|
|
46
41
|
});
|
|
47
42
|
```
|
|
@@ -69,25 +64,26 @@ This is a `blog` page.
|
|
|
69
64
|
|
|
70
65
|
3. Use your `markdown` file.
|
|
71
66
|
|
|
72
|
-
Inside the `app.router.ts` file, import your Markdown Component and the `
|
|
67
|
+
Inside the `app.router.ts` file, import your Markdown Component and the `MDXRenderer` component from `@rasenganjs/mdx` and add it to `defineRouter` option like this:
|
|
73
68
|
|
|
74
69
|
```typescript
|
|
75
70
|
import { RouterComponent, defineRouter } from "rasengan";
|
|
76
71
|
import AppLayout from "@app/app.layout";
|
|
77
72
|
import Blog from "@app/blog.page.mdx";
|
|
78
|
-
import {
|
|
79
|
-
|
|
80
|
-
const BlogPage = generatePage(Blog);
|
|
73
|
+
import { MDXRenderer } from "@rasenganjs/mdx";
|
|
81
74
|
|
|
82
75
|
class AppRouter extends RouterComponent {}
|
|
83
76
|
|
|
84
77
|
export default defineRouter({
|
|
85
78
|
imports: [],
|
|
86
79
|
layout: AppLayout,
|
|
87
|
-
pages: [
|
|
80
|
+
pages: [Blog],
|
|
81
|
+
MDXRenderer
|
|
88
82
|
})(AppRouter);
|
|
89
83
|
```
|
|
90
84
|
|
|
85
|
+
The `MDXRenderer` component is used to render the Markdown content.
|
|
86
|
+
|
|
91
87
|
Now visit [http://localhost:5320/blog](http://localhost:5320/blog)
|
|
92
88
|
|
|
93
89
|
## Community
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { CodeBlockProps, ComponentWithTextChildrenProps } from "../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
5
|
+
*
|
|
6
|
+
* The component uses the `prism-react-renderer` library to provide syntax highlighting for the code block.
|
|
7
|
+
* It also includes a copy button that allows the user to copy the code to their clipboard.
|
|
8
|
+
*
|
|
9
|
+
* @param {object} props - The component props.
|
|
10
|
+
* @param {string} props.children - The code content to be displayed in the code block.
|
|
11
|
+
* @param {string} [props.className] - The CSS class name to apply to the code block.
|
|
12
|
+
* @returns {React.ReactElement} - The rendered code block component.
|
|
13
|
+
*/
|
|
14
|
+
export declare const CodeBlock: ({ children, className, ...rest }: CodeBlockProps) => React.ReactElement;
|
|
15
|
+
export declare const SimpleBlock: ({ children, }: ComponentWithTextChildrenProps) => React.ReactElement;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { renderToString } from "react-dom/server";
|
|
4
|
+
/**
|
|
5
|
+
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
6
|
+
*
|
|
7
|
+
* The component uses the `prism-react-renderer` library to provide syntax highlighting for the code block.
|
|
8
|
+
* It also includes a copy button that allows the user to copy the code to their clipboard.
|
|
9
|
+
*
|
|
10
|
+
* @param {object} props - The component props.
|
|
11
|
+
* @param {string} props.children - The code content to be displayed in the code block.
|
|
12
|
+
* @param {string} [props.className] - The CSS class name to apply to the code block.
|
|
13
|
+
* @returns {React.ReactElement} - The rendered code block component.
|
|
14
|
+
*/
|
|
15
|
+
export const CodeBlock = ({ children, className = "", ...rest }) => {
|
|
16
|
+
const language = rest["data-language"] || "";
|
|
17
|
+
const numbers = rest["data-line-numbers"];
|
|
18
|
+
// const theme = rest["data-theme"] || "github-dark-dimmed";
|
|
19
|
+
const [hover, setHover] = React.useState(false);
|
|
20
|
+
const [copied, setCopied] = React.useState(false);
|
|
21
|
+
React.useEffect(() => {
|
|
22
|
+
/**
|
|
23
|
+
* Sets the `copied` state to `false` after 2 seconds, effectively hiding the "copied" indicator.
|
|
24
|
+
* This function is called after the user's clipboard is updated with the code content.
|
|
25
|
+
*/
|
|
26
|
+
const timer = setTimeout(() => {
|
|
27
|
+
setCopied(false);
|
|
28
|
+
}, 2000);
|
|
29
|
+
return () => clearTimeout(timer);
|
|
30
|
+
}, [copied]);
|
|
31
|
+
/**
|
|
32
|
+
* Copies the trimmed text content of the `children` prop to the user's clipboard.
|
|
33
|
+
* This function is called when the "Copy" button is clicked in the code block component.
|
|
34
|
+
* It sets the `copied` state to `true` for 2 seconds to display a "copied" indicator.
|
|
35
|
+
*/
|
|
36
|
+
const handleCopy = () => {
|
|
37
|
+
const content = renderToString(children);
|
|
38
|
+
const code = extractTextFromHTML(content);
|
|
39
|
+
navigator.clipboard.writeText(code);
|
|
40
|
+
setCopied(true);
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Extracts the text content from an HTML string.
|
|
44
|
+
*
|
|
45
|
+
* This function takes an HTML string as input and returns the plain text content of the HTML, excluding any HTML tags or markup.
|
|
46
|
+
*
|
|
47
|
+
* @param htmlString - The HTML string to extract text from.
|
|
48
|
+
* @returns The plain text content of the HTML string.
|
|
49
|
+
*/
|
|
50
|
+
const extractTextFromHTML = (htmlString) => {
|
|
51
|
+
const parser = new DOMParser();
|
|
52
|
+
const doc = parser.parseFromString(htmlString, "text/html");
|
|
53
|
+
return doc.body.textContent || "";
|
|
54
|
+
};
|
|
55
|
+
if (!language) {
|
|
56
|
+
return _jsx(SimpleBlock, { children: children });
|
|
57
|
+
}
|
|
58
|
+
return (_jsxs("div", { onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), children: [hover ? (_jsx("button", { className: 'copy-button', onClick: handleCopy, children: copied ? (_jsxs("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', width: '20', height: '20', color: '#f0f0f0', fill: 'none', children: [_jsx("path", { d: 'M22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12Z', stroke: 'currentColor', strokeWidth: '1.5' }), _jsx("path", { d: 'M8 12.5L10.5 15L16 9', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round', strokeLinejoin: 'round' })] })) : (_jsxs("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', width: '20', height: '20', color: '#f0f0f0', fill: 'none', children: [_jsx("path", { d: 'M9 15C9 12.1716 9 10.7574 9.87868 9.87868C10.7574 9 12.1716 9 15 9L16 9C18.8284 9 20.2426 9 21.1213 9.87868C22 10.7574 22 12.1716 22 15V16C22 18.8284 22 20.2426 21.1213 21.1213C20.2426 22 18.8284 22 16 22H15C12.1716 22 10.7574 22 9.87868 21.1213C9 20.2426 9 18.8284 9 16L9 15Z', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round', strokeLinejoin: 'round' }), _jsx("path", { d: 'M16.9999 9C16.9975 6.04291 16.9528 4.51121 16.092 3.46243C15.9258 3.25989 15.7401 3.07418 15.5376 2.90796C14.4312 2 12.7875 2 9.5 2C6.21252 2 4.56878 2 3.46243 2.90796C3.25989 3.07417 3.07418 3.25989 2.90796 3.46243C2 4.56878 2 6.21252 2 9.5C2 12.7875 2 14.4312 2.90796 15.5376C3.07417 15.7401 3.25989 15.9258 3.46243 16.092C4.51121 16.9528 6.04291 16.9975 9 16.9999', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round', strokeLinejoin: 'round' })] })) })) : (_jsx("span", { className: 'lang', children: language })), _jsx("code", { className: `${className} code-block`, "data-line-numbers": numbers !== undefined ? "" : undefined, children: children })] }));
|
|
59
|
+
};
|
|
60
|
+
export const SimpleBlock = ({ children, }) => {
|
|
61
|
+
return _jsx("code", { className: 'simple-block', children: children });
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=codeblock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeblock.js","sourceRoot":"","sources":["../../src/components/codeblock.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EACzB,QAAQ,EACR,SAAS,GAAG,EAAE,EACd,GAAG,IAAI,EACS,EAAsB,EAAE;IACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAC1C,4DAA4D;IAC5D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAElD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACpB;;;WAGG;QACH,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC7B,SAAS,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC,EAAE,IAAI,CAAC,CAAC;QAET,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb;;;;OAIG;IACH,MAAM,UAAU,GAAG,GAAG,EAAE;QACvB,MAAM,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;QAEzC,MAAM,IAAI,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAE1C,SAAS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AK,EAAC,SAAS,EACf,IAAI,EAAC,MAAM,aAEX,eACC,CAAC,EAAC,sRAAsR,EACxR,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACrB,EACF,eACC,CAAC,EAAC,gXAAgX,EAClX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,GACrB,IACG,CACN,GACO,CACT,CAAC,CAAC,CAAC,CACH,eAAM,SAAS,EAAC,MAAM,YAAE,QAAQ,GAAQ,CACxC,EACD,eACC,SAAS,EAAE,GAAG,SAAS,aAAa,uBACjB,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,YAExD,QAAQ,GACH,IACF,CACN,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAC3B,QAAQ,GACwB,EAAsB,EAAE;IACxD,OAAO,eAAM,SAAS,EAAC,cAAc,YAAE,QAAQ,GAAQ,CAAC;AACzD,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createElement, useMemo } from "react";
|
|
3
|
+
export const Heading = ({ variant }) => {
|
|
4
|
+
return ({ children }) => {
|
|
5
|
+
const { text, id } = useMemo(() => {
|
|
6
|
+
// Regex pattern to match links in the format [#link text]
|
|
7
|
+
const regex = new RegExp("^\\[#.+\\]");
|
|
8
|
+
// split the children into an array of strings based on space
|
|
9
|
+
const childrenArray = children.split(" [#");
|
|
10
|
+
let lastWord = "";
|
|
11
|
+
let restOfTheWords = "";
|
|
12
|
+
let link = "";
|
|
13
|
+
// Check if we have more than one word and if the last word is a link
|
|
14
|
+
if (childrenArray.length > 1 &&
|
|
15
|
+
childrenArray.at(-1).includes("]") &&
|
|
16
|
+
regex.test(`[#${childrenArray.at(-1)}`)) {
|
|
17
|
+
lastWord = childrenArray.pop();
|
|
18
|
+
}
|
|
19
|
+
if (lastWord) {
|
|
20
|
+
link = lastWord.replace("]", "").split(" ").join("-").toLowerCase();
|
|
21
|
+
restOfTheWords = childrenArray[0];
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
link = children.split(" ").join("-").toLowerCase();
|
|
25
|
+
restOfTheWords = children;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
id: variant === "h1" ? undefined : link,
|
|
29
|
+
text: restOfTheWords,
|
|
30
|
+
};
|
|
31
|
+
}, [children]);
|
|
32
|
+
const heading = createElement(variant, {
|
|
33
|
+
id,
|
|
34
|
+
className: "heading",
|
|
35
|
+
children: text,
|
|
36
|
+
});
|
|
37
|
+
return (_jsxs("div", { className: 'ra-heading-wrapper', children: [heading, id && (_jsx("a", { href: `#${id}`, children: _jsxs("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', width: '24', height: '24', color: '#ffffff', fill: 'none', children: [_jsx("path", { d: 'M10 13.229C10.1416 13.4609 10.3097 13.6804 10.5042 13.8828C11.7117 15.1395 13.5522 15.336 14.9576 14.4722C15.218 14.3121 15.4634 14.1157 15.6872 13.8828L18.9266 10.5114C20.3578 9.02184 20.3578 6.60676 18.9266 5.11718C17.4953 3.6276 15.1748 3.62761 13.7435 5.11718L13.03 5.85978', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round' }), _jsx("path", { d: 'M10.9703 18.14L10.2565 18.8828C8.82526 20.3724 6.50471 20.3724 5.07345 18.8828C3.64218 17.3932 3.64218 14.9782 5.07345 13.4886L8.31287 10.1172C9.74413 8.62761 12.0647 8.6276 13.4959 10.1172C13.6904 10.3195 13.8584 10.539 14 10.7708', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round' })] }) }))] }));
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=heading.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,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;gBAC/C,cAAc,GAAG,QAAQ,CAAC;YAC/B,CAAC;YAED,OAAO;gBACN,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;gBACvC,IAAI,EAAE,cAAc;aACpB,CAAC;QACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QAEf,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,EAAE;YACtC,EAAE;YACF,SAAS,EAAE,SAAS;YACpB,QAAQ,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,OAAO,CACN,eAAK,SAAS,EAAC,oBAAoB,aACjC,OAAO,EACP,EAAE,IAAI,CACN,YAAG,IAAI,EAAE,IAAI,EAAE,EAAE,YAChB,eACC,KAAK,EAAC,4BAA4B,EAClC,OAAO,EAAC,WAAW,EACnB,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,KAAK,EAAC,SAAS,EACf,IAAI,EAAC,MAAM,aAEX,eACC,CAAC,EAAC,uRAAuR,EACzR,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,GACpB,EACF,eACC,CAAC,EAAC,yOAAyO,EAC3O,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,GACpB,IACG,GACH,CACJ,IACI,CACN,CAAC;IACH,CAAC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,28 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
type ComponentWithTextChildrenProps = {
|
|
4
|
-
children: string;
|
|
5
|
-
};
|
|
6
|
-
type MDXRendererProps = {
|
|
7
|
-
children: MDXPageComponent;
|
|
8
|
-
className?: string;
|
|
9
|
-
};
|
|
10
|
-
type CodeBlockProps = ComponentWithTextChildrenProps & {
|
|
11
|
-
className?: string;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
15
|
-
*
|
|
16
|
-
* The component uses the `prism-react-renderer` library to provide syntax highlighting for the code block.
|
|
17
|
-
* It also includes a copy button that allows the user to copy the code to their clipboard.
|
|
18
|
-
*
|
|
19
|
-
* @param {object} props - The component props.
|
|
20
|
-
* @param {string} props.children - The code content to be displayed in the code block.
|
|
21
|
-
* @param {string} [props.className] - The CSS class name to apply to the code block.
|
|
22
|
-
* @returns {React.ReactElement} - The rendered code block component.
|
|
23
|
-
*/
|
|
24
|
-
declare const CodeBlock: ({ children, className }: CodeBlockProps) => React.ReactElement;
|
|
25
|
-
declare const SimpleBlock: ({ children }: ComponentWithTextChildrenProps) => React.ReactElement;
|
|
2
|
+
import { MDXRendererProps } from "../types/index.js";
|
|
26
3
|
/**
|
|
27
4
|
* Renders an MDX content component with a custom code block component.
|
|
28
5
|
*
|
|
@@ -32,4 +9,4 @@ declare const SimpleBlock: ({ children }: ComponentWithTextChildrenProps) => Rea
|
|
|
32
9
|
* @returns {React.ReactElement} - The rendered MDX content with the custom code block component.
|
|
33
10
|
*/
|
|
34
11
|
declare const MDXRenderer: ({ children: MDXContent, className }: MDXRendererProps) => React.ReactElement;
|
|
35
|
-
export { MDXRenderer
|
|
12
|
+
export { MDXRenderer };
|
package/lib/components/index.js
CHANGED
|
@@ -1,80 +1,7 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
6
|
-
*
|
|
7
|
-
* The component uses the `prism-react-renderer` library to provide syntax highlighting for the code block.
|
|
8
|
-
* It also includes a copy button that allows the user to copy the code to their clipboard.
|
|
9
|
-
*
|
|
10
|
-
* @param {object} props - The component props.
|
|
11
|
-
* @param {string} props.children - The code content to be displayed in the code block.
|
|
12
|
-
* @param {string} [props.className] - The CSS class name to apply to the code block.
|
|
13
|
-
* @returns {React.ReactElement} - The rendered code block component.
|
|
14
|
-
*/
|
|
15
|
-
const CodeBlock = ({ children, className = "" }) => {
|
|
16
|
-
const language = className.replace(/language-/, "");
|
|
17
|
-
if (!language) {
|
|
18
|
-
return _jsx(SimpleBlock, { children: children });
|
|
19
|
-
}
|
|
20
|
-
return (_jsx(Highlight, { theme: themes.oneDark, code: children.trim(), language: language, children: ({ className, tokens, getLineProps, getTokenProps }) => {
|
|
21
|
-
const [copied, setCopied] = React.useState(false);
|
|
22
|
-
React.useEffect(() => {
|
|
23
|
-
/**
|
|
24
|
-
* Sets the `copied` state to `false` after 2 seconds, effectively hiding the "copied" indicator.
|
|
25
|
-
* This function is called after the user's clipboard is updated with the code content.
|
|
26
|
-
*/
|
|
27
|
-
const timer = setTimeout(() => {
|
|
28
|
-
setCopied(false);
|
|
29
|
-
}, 2000);
|
|
30
|
-
return () => clearTimeout(timer);
|
|
31
|
-
}, [copied]);
|
|
32
|
-
/**
|
|
33
|
-
* Copies the trimmed text content of the `children` prop to the user's clipboard.
|
|
34
|
-
* This function is called when the "Copy" button is clicked in the code block component.
|
|
35
|
-
* It sets the `copied` state to `true` for 2 seconds to display a "copied" indicator.
|
|
36
|
-
*/
|
|
37
|
-
const handleCopy = () => {
|
|
38
|
-
navigator.clipboard.writeText(children.trim());
|
|
39
|
-
setCopied(true);
|
|
40
|
-
};
|
|
41
|
-
return (_jsxs("pre", { className: className, style: {
|
|
42
|
-
color: "#fff",
|
|
43
|
-
backgroundColor: "#1d2529",
|
|
44
|
-
borderRadius: "20px",
|
|
45
|
-
overflow: "hidden",
|
|
46
|
-
padding: "0px",
|
|
47
|
-
}, children: [_jsxs("div", { style: {
|
|
48
|
-
width: "100%",
|
|
49
|
-
height: "50px",
|
|
50
|
-
backgroundColor: "#28373f",
|
|
51
|
-
display: "flex",
|
|
52
|
-
justifyContent: "space-between",
|
|
53
|
-
alignItems: "center",
|
|
54
|
-
paddingLeft: "20px",
|
|
55
|
-
paddingRight: "20px",
|
|
56
|
-
}, children: [_jsx("span", { children: "Filename" }), _jsx("button", { className: 'copy-button', onClick: handleCopy, children: copied ? (_jsxs("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', width: '24', height: '24', color: '#f0f0f0', fill: 'none', children: [_jsx("path", { d: 'M22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12Z', stroke: 'currentColor', strokeWidth: '1.5' }), _jsx("path", { d: 'M8 12.5L10.5 15L16 9', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round', strokeLinejoin: 'round' })] })) : (_jsxs("svg", { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', width: '24', height: '24', color: '#f0f0f0', fill: 'none', children: [_jsx("path", { d: 'M9 15C9 12.1716 9 10.7574 9.87868 9.87868C10.7574 9 12.1716 9 15 9L16 9C18.8284 9 20.2426 9 21.1213 9.87868C22 10.7574 22 12.1716 22 15V16C22 18.8284 22 20.2426 21.1213 21.1213C20.2426 22 18.8284 22 16 22H15C12.1716 22 10.7574 22 9.87868 21.1213C9 20.2426 9 18.8284 9 16L9 15Z', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round', strokeLinejoin: 'round' }), _jsx("path", { d: 'M16.9999 9C16.9975 6.04291 16.9528 4.51121 16.092 3.46243C15.9258 3.25989 15.7401 3.07418 15.5376 2.90796C14.4312 2 12.7875 2 9.5 2C6.21252 2 4.56878 2 3.46243 2.90796C3.25989 3.07417 3.07418 3.25989 2.90796 3.46243C2 4.56878 2 6.21252 2 9.5C2 12.7875 2 14.4312 2.90796 15.5376C3.07417 15.7401 3.25989 15.9258 3.46243 16.092C4.51121 16.9528 6.04291 16.9975 9 16.9999', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round', strokeLinejoin: 'round' })] })) })] }), _jsx("div", { style: {
|
|
57
|
-
padding: "20px",
|
|
58
|
-
fontSize: "14px",
|
|
59
|
-
}, children: _jsx("code", { children: tokens.map((line, i) => (_jsxs("div", { ...getLineProps({ line }), children: [_jsx("span", { style: {
|
|
60
|
-
opacity: 0.6,
|
|
61
|
-
marginRight: "5px",
|
|
62
|
-
}, children: i + 1 }), _jsx("span", { children: " " }), line.map((token, key) => (_jsx("span", { ...getTokenProps({ token }) }, key)))] }, i))) }) })] }));
|
|
63
|
-
} }));
|
|
64
|
-
};
|
|
65
|
-
const SimpleBlock = ({ children }) => {
|
|
66
|
-
return (_jsx("span", { className: "simple-block", style: {
|
|
67
|
-
fontSize: "14px",
|
|
68
|
-
borderRadius: "5px",
|
|
69
|
-
paddingLeft: "3.6px",
|
|
70
|
-
paddingRight: "3.6px",
|
|
71
|
-
paddingTop: "2px",
|
|
72
|
-
paddingBottom: "2px",
|
|
73
|
-
marginInline: "0px",
|
|
74
|
-
backgroundColor: "#f7f7f7",
|
|
75
|
-
border: "1px solid #f0f0f0",
|
|
76
|
-
}, children: children }));
|
|
77
|
-
};
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { CodeBlock } from "./codeblock.js";
|
|
3
|
+
import { Table } from "./table.js";
|
|
4
|
+
import { Heading } from "./heading.js";
|
|
78
5
|
/**
|
|
79
6
|
* Renders an MDX content component with a custom code block component.
|
|
80
7
|
*
|
|
@@ -86,7 +13,14 @@ const SimpleBlock = ({ children }) => {
|
|
|
86
13
|
const MDXRenderer = ({ children: MDXContent, className }) => {
|
|
87
14
|
return (_jsx("section", { className: "rasengan-markdown-body " + className, children: _jsx(MDXContent, { components: {
|
|
88
15
|
code: CodeBlock,
|
|
16
|
+
table: Table,
|
|
17
|
+
h1: Heading({ variant: "h1" }),
|
|
18
|
+
h2: Heading({ variant: "h2" }),
|
|
19
|
+
h3: Heading({ variant: "h3" }),
|
|
20
|
+
h4: Heading({ variant: "h4" }),
|
|
21
|
+
h5: Heading({ variant: "h5" }),
|
|
22
|
+
h6: Heading({ variant: "h6" }),
|
|
89
23
|
} }) }));
|
|
90
24
|
};
|
|
91
|
-
export { MDXRenderer
|
|
25
|
+
export { MDXRenderer };
|
|
92
26
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAe,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC;;;;;;;GAOG;AACH,MAAM,WAAW,GAAG,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAoB,EAAsB,EAAE;IACjG,OAAO,CACN,kBAAS,SAAS,EAAE,yBAAyB,GAAG,SAAS,YACxD,KAAC,UAAU,IACV,UAAU,EAAE;gBACX,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,KAAK;gBACZ,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;aAC9B,GACA,GACO,CACV,CAAC;AACH,CAAC,CAAC;AAEF,OAAO,EACL,WAAW,EACZ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/components/table.tsx"],"names":[],"mappings":";AAGA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EACrB,QAAQ,GACwB,EAAsB,EAAE;IACxD,OAAO,CACN,cAAK,SAAS,EAAC,kBAAkB,YAChC,0BAAQ,QAAQ,GAAS,GACpB,CACN,CAAC;AACH,CAAC,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,30 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* This package is inspired by @mdx-js/rollup to provide a custom implement of the MDX plugin for RasenganJs.
|
|
7
7
|
*/
|
|
8
|
-
/// <reference types="node" />
|
|
9
8
|
export * from './types/index.js';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
enforce: string;
|
|
14
|
-
config(config: unknown, env: any): void;
|
|
15
|
-
configResolved(resolvedConfig: unknown): void;
|
|
16
|
-
transform(code: string, id: string): Promise<{
|
|
17
|
-
code: string;
|
|
18
|
-
map: import("rollup").SourceMapInput;
|
|
19
|
-
}>;
|
|
20
|
-
} | {
|
|
21
|
-
name: string;
|
|
22
|
-
config: (config: any, env: any) => {
|
|
23
|
-
define: {
|
|
24
|
-
process: NodeJS.Process;
|
|
25
|
-
};
|
|
26
|
-
build: {
|
|
27
|
-
rollupOptions: {
|
|
28
|
-
plugins: import("rollup").Plugin<any>[];
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
apply: string;
|
|
33
|
-
})[];
|
|
34
|
-
export { generatePage };
|
|
9
|
+
export * from './components/index.js';
|
|
10
|
+
import { plugin } from "./utils/index.js";
|
|
11
|
+
export default plugin;
|
package/lib/index.js
CHANGED
|
@@ -6,9 +6,7 @@
|
|
|
6
6
|
* This package is inspired by @mdx-js/rollup to provide a custom implement of the MDX plugin for RasenganJs.
|
|
7
7
|
*/
|
|
8
8
|
export * from './types/index.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
export { generatePage };
|
|
9
|
+
export * from './components/index.js';
|
|
10
|
+
import { plugin } from "./utils/index.js";
|
|
11
|
+
export default plugin;
|
|
14
12
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,kBAAkB,CAAC;AACjC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,eAAe,MAAM,CAAC"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type Metadata } from "rasengan";
|
|
3
2
|
/**
|
|
4
3
|
* A React functional component that represents an MDX page.
|
|
@@ -13,3 +12,28 @@ export type MDXPageComponent = React.FC<any> & {
|
|
|
13
12
|
metadata: Metadata;
|
|
14
13
|
};
|
|
15
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* A React functional component that represents a simple block element.
|
|
17
|
+
*/
|
|
18
|
+
export type ComponentWithTextChildrenProps = {
|
|
19
|
+
children: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A React functional component that represents a simple block element.
|
|
23
|
+
*/
|
|
24
|
+
export type MDXRendererProps = {
|
|
25
|
+
children: MDXPageComponent;
|
|
26
|
+
className?: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A React functional component that represents a simple block element.
|
|
30
|
+
*/
|
|
31
|
+
export type CodeBlockProps = ComponentWithTextChildrenProps & {
|
|
32
|
+
className?: string;
|
|
33
|
+
};
|
|
34
|
+
export type HeadingProps = {
|
|
35
|
+
variant: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
36
|
+
};
|
|
37
|
+
export type HeadingProps2 = ComponentWithTextChildrenProps & {
|
|
38
|
+
className?: string;
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractToc(markdown: string): Promise<string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { remark } from "remark";
|
|
2
|
+
import remarkToc from "remark-toc";
|
|
3
|
+
export async function extractToc(markdown) {
|
|
4
|
+
const file = await remark()
|
|
5
|
+
.use(remarkToc, {
|
|
6
|
+
heading: "structure",
|
|
7
|
+
maxDepth: 3,
|
|
8
|
+
})
|
|
9
|
+
.process(markdown);
|
|
10
|
+
return String(file);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=extract-toc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-toc.js","sourceRoot":"","sources":["../../src/utils/extract-toc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAgB;IAChD,MAAM,IAAI,GAAG,MAAM,MAAM,EAAE;SACzB,GAAG,CAAC,SAAS,EAAE;QACf,OAAO,EAAE,WAAW;QACpB,QAAQ,EAAE,CAAC;KACX,CAAC;SACD,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEpB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC"}
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import generatePage from "./generate-page.js";
|
|
2
1
|
import plugin from "./plugin.js";
|
|
3
|
-
|
|
4
|
-
import globalsPolyfill from "./globals.js";
|
|
5
|
-
export { generatePage, plugin, globalsPolyfill };
|
|
2
|
+
export { plugin };
|
|
6
3
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function markToHtml(markdown: string): Promise<string>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import rehypeStringify from "rehype-stringify";
|
|
2
|
+
import remarkGfm from "remark-gfm";
|
|
3
|
+
import remarkParse from "remark-parse";
|
|
4
|
+
import remarkRehype from "remark-rehype";
|
|
5
|
+
import { unified } from "unified";
|
|
6
|
+
export default async function markToHtml(markdown) {
|
|
7
|
+
const file = await unified()
|
|
8
|
+
.use(remarkParse)
|
|
9
|
+
.use(remarkGfm)
|
|
10
|
+
.use(remarkRehype)
|
|
11
|
+
.use(rehypeStringify)
|
|
12
|
+
.process(markdown);
|
|
13
|
+
return String(file);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=mark-to-html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mark-to-html.js","sourceRoot":"","sources":["../../src/utils/mark-to-html.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,UAAU,CAAC,QAAgB;IACxD,MAAM,IAAI,GAAG,MAAM,OAAO,EAAE;SAC1B,GAAG,CAAC,WAAW,CAAC;SAChB,GAAG,CAAC,SAAS,CAAC;SACd,GAAG,CAAC,YAAY,CAAC;SACjB,GAAG,CAAC,eAAe,CAAC;SACpB,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEpB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC"}
|
package/lib/utils/plugin.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* The transformed MDX content can then be used in the RasenganJs application, with the `metadata` object providing additional information about the content.
|
|
11
11
|
*/
|
|
12
|
-
export default function plugin(): {
|
|
12
|
+
export default function plugin(): Promise<{
|
|
13
13
|
name: string;
|
|
14
14
|
enforce: string;
|
|
15
15
|
config(config: unknown, env: any): void;
|
|
@@ -30,4 +30,4 @@ export default function plugin(): {
|
|
|
30
30
|
code: string;
|
|
31
31
|
map: import("rollup").SourceMapInput;
|
|
32
32
|
}>;
|
|
33
|
-
}
|
|
33
|
+
}>;
|
package/lib/utils/plugin.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import matter from "gray-matter";
|
|
2
|
+
import createFilter from "./create-filter.js";
|
|
3
|
+
import remarkGfm from "remark-gfm";
|
|
4
|
+
import rehypeStringify from "rehype-stringify";
|
|
5
|
+
import remarkParse from "remark-parse";
|
|
6
|
+
import remarkRehype from "remark-rehype";
|
|
7
|
+
import { extractToc } from "./extract-toc.js";
|
|
8
|
+
import rehypePrettyCode from "rehype-pretty-code";
|
|
4
9
|
/**
|
|
5
10
|
* A Vite plugin that transforms MDX files into a format that can be used in a RasenganJs application.
|
|
6
11
|
*
|
|
@@ -12,14 +17,18 @@ import createFilter from './create-filter.js';
|
|
|
12
17
|
*
|
|
13
18
|
* The transformed MDX content can then be used in the RasenganJs application, with the `metadata` object providing additional information about the content.
|
|
14
19
|
*/
|
|
15
|
-
export default function plugin() {
|
|
20
|
+
export default async function plugin() {
|
|
21
|
+
const mdx = (await import("@mdx-js/rollup")).default;
|
|
16
22
|
let config;
|
|
17
23
|
const filter = createFilter("**/*.md?(x)");
|
|
18
|
-
const mdxInstance = mdx(
|
|
24
|
+
const mdxInstance = mdx({
|
|
25
|
+
remarkPlugins: [remarkParse, remarkGfm],
|
|
26
|
+
rehypePlugins: [remarkRehype, rehypeStringify, rehypePrettyCode],
|
|
27
|
+
});
|
|
19
28
|
return {
|
|
20
29
|
name: "vite-plugin-rasengan-mdx",
|
|
21
30
|
// Apply transformation of the mdx file before other plugins
|
|
22
|
-
enforce:
|
|
31
|
+
enforce: "pre",
|
|
23
32
|
config(config, env) {
|
|
24
33
|
mdxInstance.config(config, env);
|
|
25
34
|
},
|
|
@@ -46,6 +55,9 @@ export default function plugin() {
|
|
|
46
55
|
const { content, data: frontmatter } = matter(code);
|
|
47
56
|
// Apply transformation of the mdx file
|
|
48
57
|
const result = await mdxInstance.transform(content, id);
|
|
58
|
+
const toc = await extractToc(content);
|
|
59
|
+
// const html = await markToHtml(content);
|
|
60
|
+
// console.log({ toc });
|
|
49
61
|
// Extract the file name from the path
|
|
50
62
|
const fileName = id
|
|
51
63
|
.split("/")
|
|
@@ -58,6 +70,7 @@ export default function plugin() {
|
|
|
58
70
|
title: fileName,
|
|
59
71
|
},
|
|
60
72
|
};
|
|
73
|
+
// console.log(result.code)
|
|
61
74
|
return {
|
|
62
75
|
code: `
|
|
63
76
|
${result.code}
|
package/lib/utils/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/utils/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/utils/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,eAAe,MAAM,kBAAkB,CAA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