@hackersheet/next-document-content-components 0.1.0-alpha.1 → 0.1.0-alpha.10

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.
Files changed (46) hide show
  1. package/dist/cjs/components/code-block/code-block-copy-button.js +1 -1
  2. package/dist/cjs/components/code-block/code-block.d.ts +1 -1
  3. package/dist/cjs/components/code-block/code-block.js +3 -9
  4. package/dist/cjs/components/code-block/directory-tree.d.ts +6 -0
  5. package/dist/cjs/components/code-block/directory-tree.js +93 -0
  6. package/dist/cjs/components/code-block/shiki.js +7 -2
  7. package/dist/cjs/components/gist/gist.d.ts +6 -0
  8. package/dist/cjs/components/gist/gist.js +55 -0
  9. package/dist/cjs/components/heading/heading.d.ts +6 -0
  10. package/dist/cjs/components/{kifu-to/kifu-to.js → heading/heading.js} +7 -9
  11. package/dist/cjs/components/index.d.ts +4 -1
  12. package/dist/cjs/components/index.js +12 -3
  13. package/dist/cjs/components/link-card/link-card.js +1 -1
  14. package/dist/cjs/components/mermaid/mermaid.d.ts +6 -0
  15. package/dist/cjs/components/{code-block/code-block-mermaid.js → mermaid/mermaid.js} +9 -8
  16. package/dist/cjs/components/youtube/youtube.js +1 -1
  17. package/dist/cjs/index.d.ts +4 -1
  18. package/dist/esm/components/code-block/code-block-copy-button.mjs +1 -1
  19. package/dist/esm/components/code-block/code-block.d.mts +1 -1
  20. package/dist/esm/components/code-block/code-block.mjs +3 -9
  21. package/dist/esm/components/code-block/directory-tree.d.mts +6 -0
  22. package/dist/esm/components/code-block/directory-tree.mjs +63 -0
  23. package/dist/esm/components/code-block/shiki.mjs +13 -3
  24. package/dist/esm/components/gist/gist.d.mts +6 -0
  25. package/dist/esm/components/gist/gist.mjs +25 -0
  26. package/dist/esm/components/heading/heading.d.mts +6 -0
  27. package/dist/esm/components/heading/heading.mjs +9 -0
  28. package/dist/esm/components/index.d.mts +4 -1
  29. package/dist/esm/components/index.mjs +8 -2
  30. package/dist/esm/components/link-card/link-card.mjs +1 -1
  31. package/dist/esm/components/mermaid/mermaid.d.mts +6 -0
  32. package/dist/esm/components/{code-block/code-block-mermaid.mjs → mermaid/mermaid.mjs} +6 -5
  33. package/dist/esm/components/youtube/youtube.mjs +1 -1
  34. package/dist/esm/index.d.mts +4 -1
  35. package/package.json +6 -20
  36. package/dist/cjs/components/code-block/code-block-kifu.d.ts +0 -9
  37. package/dist/cjs/components/code-block/code-block-kifu.js +0 -66
  38. package/dist/cjs/components/code-block/code-block-mermaid.d.ts +0 -8
  39. package/dist/cjs/components/kifu-to/kifu-to.d.ts +0 -6
  40. package/dist/esm/components/code-block/code-block-kifu.d.mts +0 -9
  41. package/dist/esm/components/code-block/code-block-kifu.mjs +0 -36
  42. package/dist/esm/components/code-block/code-block-mermaid.d.mts +0 -8
  43. package/dist/esm/components/kifu-to/kifu-to.d.mts +0 -6
  44. package/dist/esm/components/kifu-to/kifu-to.mjs +0 -11
  45. package/dist/style.module.css +0 -279
  46. package/dist/style.module.scss.d.ts +0 -9
@@ -43,5 +43,5 @@ function CodeBlockCopyButton({ code }) {
43
43
  setTimeout(() => setCopied(false), 1e3);
44
44
  });
45
45
  };
46
- return /* @__PURE__ */ import_react.default.createElement("button", { onClick: handleClick }, copied ? /* @__PURE__ */ import_react.default.createElement(import_hi2.HiCheck, { size: 18 }) : /* @__PURE__ */ import_react.default.createElement(import_hi2.HiOutlineClipboardDocumentList, { size: 18 }));
46
+ return /* @__PURE__ */ import_react.default.createElement("button", { onClick: handleClick, "aria-label": "Copy code to clipboard" }, copied ? /* @__PURE__ */ import_react.default.createElement(import_hi2.HiCheck, { size: 18 }) : /* @__PURE__ */ import_react.default.createElement(import_hi2.HiOutlineClipboardDocumentList, { size: 18 }));
47
47
  }
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { CodeBlockComponentProps } from '@hackersheet/react-document-content';
3
3
 
4
- declare function CodeBlock({ code, language }: CodeBlockComponentProps): Promise<React.JSX.Element>;
4
+ declare function CodeBlock({ code, ...props }: CodeBlockComponentProps): Promise<React.JSX.Element>;
5
5
 
6
6
  export { CodeBlock as default };
@@ -34,15 +34,9 @@ module.exports = __toCommonJS(code_block_exports);
34
34
  var import_react = __toESM(require("react"));
35
35
  var import_code_block_copy_button = __toESM(require("./code-block-copy-button"));
36
36
  var import_code_block_icon = __toESM(require("./code-block-icon"));
37
- var import_code_block_kifu = __toESM(require("./code-block-kifu"));
38
- var import_code_block_mermaid = __toESM(require("./code-block-mermaid"));
39
37
  var import_shiki = require("./shiki");
40
- async function CodeBlock({ code, language }) {
41
- const [lang, filename] = language.split(":");
42
- const isMermaid = lang === "mermaid";
43
- const isKifu = lang === "kifu";
44
- if (isMermaid) return /* @__PURE__ */ import_react.default.createElement(import_code_block_mermaid.default, { code });
45
- if (isKifu) return /* @__PURE__ */ import_react.default.createElement(import_code_block_kifu.default, { kifu: code, filename });
46
- const html = await (0, import_shiki.highlighteCode)(code, lang);
38
+ async function CodeBlock({ code, ...props }) {
39
+ const [language, filename] = props.language.split(":");
40
+ const html = await (0, import_shiki.highlighteCode)(code, language);
47
41
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "code-block" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "code-block-header" }, /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(import_code_block_icon.default, { language })), /* @__PURE__ */ import_react.default.createElement("div", { className: "code-block-filename" }, filename), /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(import_code_block_copy_button.default, { code }))), html && /* @__PURE__ */ import_react.default.createElement("div", { dangerouslySetInnerHTML: { __html: html } }), !html && /* @__PURE__ */ import_react.default.createElement("pre", null, code));
48
42
  }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { DirectoryTreeComponentProps } from '@hackersheet/react-document-content';
3
+
4
+ declare function DirectoryTree({ code, ...props }: DirectoryTreeComponentProps): Promise<React.JSX.Element>;
5
+
6
+ export { DirectoryTree as default };
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var directory_tree_exports = {};
30
+ __export(directory_tree_exports, {
31
+ default: () => DirectoryTree
32
+ });
33
+ module.exports = __toCommonJS(directory_tree_exports);
34
+ var import_react = __toESM(require("react"));
35
+ var import_lu = require("react-icons/lu");
36
+ var import_code_block_copy_button = __toESM(require("./code-block-copy-button"));
37
+ async function DirectoryTree({ code, ...props }) {
38
+ const [, filename] = props.language.split(":");
39
+ const treeNode = parseTreeOutput(code);
40
+ const renderTree = (node) => {
41
+ return /* @__PURE__ */ import_react.default.createElement("li", { className: `${node.type === "directory" ? "directory-tree-directory" : "directory-tree-file"}` }, /* @__PURE__ */ import_react.default.createElement("div", { className: "directory-tree-node-content" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "directory-tree-icon" }, node.type === "directory" && /* @__PURE__ */ import_react.default.createElement(import_lu.LuFolder, null), node.type === "file" && /* @__PURE__ */ import_react.default.createElement(import_lu.LuFile, null)), /* @__PURE__ */ import_react.default.createElement("div", null, node.name)), node.children && /* @__PURE__ */ import_react.default.createElement("ul", null, node.children.map((child) => renderTree(child))));
42
+ };
43
+ return /* @__PURE__ */ import_react.default.createElement("div", { className: "code-block" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "code-block-header" }, /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(import_lu.LuFolderTree, null)), /* @__PURE__ */ import_react.default.createElement("div", { className: "code-block-filename" }, filename), /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(import_code_block_copy_button.default, { code }))), /* @__PURE__ */ import_react.default.createElement("div", null, treeNode ? /* @__PURE__ */ import_react.default.createElement("ul", { className: "directory-tree" }, renderTree(treeNode)) : /* @__PURE__ */ import_react.default.createElement("pre", null, code)));
44
+ }
45
+ function parseTreeOutput(treeOutput) {
46
+ const lines = treeOutput.trim().split("\n");
47
+ const rootNode = {
48
+ name: "",
49
+ type: "directory",
50
+ level: 0,
51
+ children: []
52
+ };
53
+ const stack = [{ node: rootNode, level: 0 }];
54
+ let rootNodeSet = false;
55
+ const getExtension = (filename) => filename.match(/\.(\w+)$/)?.[1];
56
+ const cleanNodeName = (name) => name.replace(/^[\s│├└─]+/, "").trim();
57
+ try {
58
+ lines.forEach((line) => {
59
+ const trimmedLine = line.trimStart();
60
+ const indent = (trimmedLine.match(/^[\s│├└─]+/) || [""])[0];
61
+ const level = indent.length / 4;
62
+ const cleanedLine = cleanNodeName(trimmedLine);
63
+ if (level === 0 && !rootNodeSet) {
64
+ rootNode.name = cleanedLine;
65
+ rootNodeSet = true;
66
+ return;
67
+ }
68
+ const isDirectory = !cleanedLine.includes(".");
69
+ const newNode = {
70
+ name: cleanedLine,
71
+ type: isDirectory ? "directory" : "file",
72
+ extension: isDirectory ? void 0 : getExtension(cleanedLine),
73
+ level,
74
+ children: isDirectory ? [] : void 0
75
+ };
76
+ while (stack.length > 0 && stack[stack.length - 1].level >= level) {
77
+ stack.pop();
78
+ }
79
+ if (stack[stack.length - 1] === void 0) {
80
+ throw new Error("Tree parsing failed");
81
+ }
82
+ const parentNode = stack[stack.length - 1].node;
83
+ parentNode.children = parentNode.children || [];
84
+ parentNode.children.push(newNode);
85
+ if (newNode.type === "directory") {
86
+ stack.push({ node: newNode, level });
87
+ }
88
+ });
89
+ return rootNode;
90
+ } catch (e) {
91
+ return null;
92
+ }
93
+ }
@@ -30,13 +30,18 @@ async function highlighteCode(code, language) {
30
30
  if (shikiLang === void 0 && language !== "text") {
31
31
  return null;
32
32
  }
33
- const html = highlighter.codeToHtml(code, {
33
+ const html = highlighter.codeToHtml(code.trim(), {
34
34
  lang: shikiLang || "text",
35
35
  themes: {
36
36
  light: "github-light",
37
37
  dark: "github-dark-dimmed"
38
38
  },
39
- transformers: [(0, import_transformers.transformerNotationDiff)(), (0, import_transformers.transformerNotationWordHighlight)()]
39
+ transformers: [
40
+ (0, import_transformers.transformerNotationDiff)(),
41
+ (0, import_transformers.transformerNotationHighlight)(),
42
+ (0, import_transformers.transformerNotationWordHighlight)(),
43
+ (0, import_transformers.transformerRemoveNotationEscape)()
44
+ ]
40
45
  });
41
46
  return html;
42
47
  }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { GistComponentProps } from '@hackersheet/react-document-content';
3
+
4
+ declare function Gist({ gistId, username, filename }: GistComponentProps): Promise<React.JSX.Element>;
5
+
6
+ export { Gist as default };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var gist_exports = {};
30
+ __export(gist_exports, {
31
+ default: () => Gist
32
+ });
33
+ module.exports = __toCommonJS(gist_exports);
34
+ var import_script = __toESM(require("next/script"));
35
+ var import_react = __toESM(require("react"));
36
+ async function Gist({ gistId, username, filename }) {
37
+ const gistUrl = (() => {
38
+ const base = `https://gist.github.com/${username}/${gistId}.json`;
39
+ if (filename) {
40
+ return base + `?file=${filename}`;
41
+ }
42
+ return base;
43
+ })();
44
+ const result = await fetch(gistUrl);
45
+ const json = await result.json();
46
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
47
+ "div",
48
+ {
49
+ className: "gist-block",
50
+ dangerouslySetInnerHTML: {
51
+ __html: json.div
52
+ }
53
+ }
54
+ ), /* @__PURE__ */ import_react.default.createElement(import_script.default, { stylesheets: [json.stylesheet] }));
55
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { HeadingComponentProps } from '@hackersheet/react-document-content';
3
+
4
+ declare function Heading({ HeadingTag, id, children }: HeadingComponentProps): React.JSX.Element;
5
+
6
+ export { Heading as default };
@@ -26,16 +26,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var kifu_to_exports = {};
30
- __export(kifu_to_exports, {
31
- default: () => KifuTo
29
+ var heading_exports = {};
30
+ __export(heading_exports, {
31
+ default: () => Heading
32
32
  });
33
- module.exports = __toCommonJS(kifu_to_exports);
33
+ module.exports = __toCommonJS(heading_exports);
34
34
  var import_link = __toESM(require("next/link"));
35
35
  var import_react = __toESM(require("react"));
36
- function KifuTo({ id, ply, label: defaultLabel }) {
37
- const fullId = `user-content-${id}`;
38
- const href = `?ply=${ply}#${fullId}`;
39
- const label = defaultLabel ?? `${ply}\u624B\u76EE`;
40
- return /* @__PURE__ */ import_react.default.createElement(import_link.default, { href }, label);
36
+ var import_md = require("react-icons/md");
37
+ function Heading({ HeadingTag, id, children }) {
38
+ return /* @__PURE__ */ import_react.default.createElement(HeadingTag, { id, className: "heading" }, /* @__PURE__ */ import_react.default.createElement(import_link.default, { href: `#${id}` }, /* @__PURE__ */ import_react.default.createElement("span", { className: "heading-label" }, children), /* @__PURE__ */ import_react.default.createElement("span", { className: "heading-link-icon" }, /* @__PURE__ */ import_react.default.createElement(import_md.MdLink, null))));
41
39
  }
@@ -1,8 +1,11 @@
1
1
  export { default as CodeBlock } from './code-block/code-block.js';
2
+ export { default as DirectoryTree } from './code-block/directory-tree.js';
3
+ export { default as Gist } from './gist/gist.js';
4
+ export { default as Heading } from './heading/heading.js';
2
5
  export { default as Image } from './image/image.js';
3
- export { default as KifuTo } from './kifu-to/kifu-to.js';
4
6
  export { default as Link } from './link/link.js';
5
7
  export { default as LinkCard } from './link-card/link-card.js';
8
+ export { default as Mermaid } from './mermaid/mermaid.js';
6
9
  export { default as XPost } from './x-post/x-post.js';
7
10
  export { default as Youtube } from './youtube/youtube.js';
8
11
  import 'react';
@@ -29,28 +29,37 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var components_exports = {};
30
30
  __export(components_exports, {
31
31
  CodeBlock: () => import_code_block.default,
32
+ DirectoryTree: () => import_directory_tree.default,
33
+ Gist: () => import_gist.default,
34
+ Heading: () => import_heading.default,
32
35
  Image: () => import_image.default,
33
- KifuTo: () => import_kifu_to.default,
34
36
  Link: () => import_link.default,
35
37
  LinkCard: () => import_link_card.default,
38
+ Mermaid: () => import_mermaid.default,
36
39
  XPost: () => import_x_post.default,
37
40
  Youtube: () => import_youtube.default
38
41
  });
39
42
  module.exports = __toCommonJS(components_exports);
40
43
  var import_code_block = __toESM(require("./code-block/code-block"));
44
+ var import_directory_tree = __toESM(require("./code-block/directory-tree"));
45
+ var import_gist = __toESM(require("./gist/gist"));
46
+ var import_heading = __toESM(require("./heading/heading"));
41
47
  var import_image = __toESM(require("./image/image"));
42
- var import_kifu_to = __toESM(require("./kifu-to/kifu-to"));
43
48
  var import_link = __toESM(require("./link/link"));
44
49
  var import_link_card = __toESM(require("./link-card/link-card"));
50
+ var import_mermaid = __toESM(require("./mermaid/mermaid"));
45
51
  var import_x_post = __toESM(require("./x-post/x-post"));
46
52
  var import_youtube = __toESM(require("./youtube/youtube"));
47
53
  // Annotate the CommonJS export names for ESM import in node:
48
54
  0 && (module.exports = {
49
55
  CodeBlock,
56
+ DirectoryTree,
57
+ Gist,
58
+ Heading,
50
59
  Image,
51
- KifuTo,
52
60
  Link,
53
61
  LinkCard,
62
+ Mermaid,
54
63
  XPost,
55
64
  Youtube
56
65
  });
@@ -43,5 +43,5 @@ function LinkCard({
43
43
  imageWidth
44
44
  }) {
45
45
  const faviconUrl = `https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://${domain}&size=16`;
46
- return /* @__PURE__ */ import_react.default.createElement("a", { href: url, className: "link-card" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "link-card-main" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "link-card-title" }, title), /* @__PURE__ */ import_react.default.createElement("div", { className: "link-card-description" }, description), /* @__PURE__ */ import_react.default.createElement("div", { className: "link-card-domain" }, /* @__PURE__ */ import_react.default.createElement("picture", null, /* @__PURE__ */ import_react.default.createElement("img", { src: faviconUrl, alt: `${domain} favicon`, width: 16, height: 16 })), /* @__PURE__ */ import_react.default.createElement("div", null, domain))), imageUrl && /* @__PURE__ */ import_react.default.createElement("div", { className: "link-card-image" }, /* @__PURE__ */ import_react.default.createElement(import_image.default, { alt: title, src: imageUrl, height: imageHeight, width: imageWidth })));
46
+ return /* @__PURE__ */ import_react.default.createElement("a", { href: url, className: "link-card" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "link-card-main" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "link-card-title-container" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "link-card-title" }, title)), /* @__PURE__ */ import_react.default.createElement("div", { className: "link-card-description" }, description), /* @__PURE__ */ import_react.default.createElement("div", { className: "link-card-domain" }, /* @__PURE__ */ import_react.default.createElement("picture", null, /* @__PURE__ */ import_react.default.createElement("img", { src: faviconUrl, alt: `${domain} favicon`, width: 16, height: 16 })), /* @__PURE__ */ import_react.default.createElement("div", null, domain))), imageUrl && /* @__PURE__ */ import_react.default.createElement("div", { className: "link-card-image" }, /* @__PURE__ */ import_react.default.createElement(import_image.default, { alt: title, src: imageUrl, height: imageHeight, width: imageWidth })));
47
47
  }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { MermaidComponentProps } from '@hackersheet/react-document-content';
3
+
4
+ declare function Mermaid({ code }: MermaidComponentProps): React.JSX.Element;
5
+
6
+ export { Mermaid as default };
@@ -27,11 +27,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  mod
28
28
  ));
29
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var code_block_mermaid_exports = {};
31
- __export(code_block_mermaid_exports, {
32
- default: () => CodeBlockMermaid
30
+ var mermaid_exports = {};
31
+ __export(mermaid_exports, {
32
+ default: () => Mermaid
33
33
  });
34
- module.exports = __toCommonJS(code_block_mermaid_exports);
34
+ module.exports = __toCommonJS(mermaid_exports);
35
35
  var import_crypto = require("crypto");
36
36
  var import_mermaid = __toESM(require("mermaid"));
37
37
  var import_next_themes = require("next-themes");
@@ -41,7 +41,7 @@ function createId(code) {
41
41
  hash.update(code);
42
42
  return "id-" + hash.digest("hex");
43
43
  }
44
- function CodeBlockMermaid({ code }) {
44
+ function Mermaid({ code }) {
45
45
  const ref = (0, import_react.useRef)(null);
46
46
  const [mounted, setMounted] = (0, import_react.useState)(false);
47
47
  const [svg, setSvg] = (0, import_react.useState)("");
@@ -65,7 +65,8 @@ function CodeBlockMermaid({ code }) {
65
65
  };
66
66
  renderMermaid();
67
67
  }, [mounted, code, id, theme, systemTheme, setSvg, setMounted]);
68
- if (!mounted)
69
- return /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", null, "Loading..."));
70
- return /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { dangerouslySetInnerHTML: { __html: svg }, ref }));
68
+ if (!mounted) {
69
+ return /* @__PURE__ */ import_react.default.createElement("div", { className: "mermaid-block mermaid-loading" }, /* @__PURE__ */ import_react.default.createElement("div", null, "Loading..."));
70
+ }
71
+ return /* @__PURE__ */ import_react.default.createElement("div", { className: "mermaid-block", dangerouslySetInnerHTML: { __html: svg }, ref });
71
72
  }
@@ -35,5 +35,5 @@ var import_google = require("@next/third-parties/google");
35
35
  var import_react = __toESM(require("react"));
36
36
  async function Youtube({ videoId, params, playLabel, ...props }) {
37
37
  const paramsString = params ? Object.entries(params).filter(([, value]) => value !== void 0).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join("&") : void 0;
38
- return /* @__PURE__ */ import_react.default.createElement(import_google.YouTubeEmbed, { ...props, videoid: videoId, params: paramsString, playlabel: playLabel });
38
+ return /* @__PURE__ */ import_react.default.createElement("div", { className: "youtube-block" }, /* @__PURE__ */ import_react.default.createElement(import_google.YouTubeEmbed, { ...props, videoid: videoId, params: paramsString, playlabel: playLabel }));
39
39
  }
@@ -1,8 +1,11 @@
1
1
  export { default as CodeBlock } from './components/code-block/code-block.js';
2
+ export { default as DirectoryTree } from './components/code-block/directory-tree.js';
3
+ export { default as Gist } from './components/gist/gist.js';
4
+ export { default as Heading } from './components/heading/heading.js';
2
5
  export { default as Image } from './components/image/image.js';
3
- export { default as KifuTo } from './components/kifu-to/kifu-to.js';
4
6
  export { default as Link } from './components/link/link.js';
5
7
  export { default as LinkCard } from './components/link-card/link-card.js';
8
+ export { default as Mermaid } from './components/mermaid/mermaid.js';
6
9
  export { default as XPost } from './components/x-post/x-post.js';
7
10
  export { default as Youtube } from './components/youtube/youtube.js';
8
11
  import 'react';
@@ -10,7 +10,7 @@ function CodeBlockCopyButton({ code }) {
10
10
  setTimeout(() => setCopied(false), 1e3);
11
11
  });
12
12
  };
13
- return /* @__PURE__ */ React.createElement("button", { onClick: handleClick }, copied ? /* @__PURE__ */ React.createElement(HiCheck, { size: 18 }) : /* @__PURE__ */ React.createElement(HiOutlineClipboardDocumentList, { size: 18 }));
13
+ return /* @__PURE__ */ React.createElement("button", { onClick: handleClick, "aria-label": "Copy code to clipboard" }, copied ? /* @__PURE__ */ React.createElement(HiCheck, { size: 18 }) : /* @__PURE__ */ React.createElement(HiOutlineClipboardDocumentList, { size: 18 }));
14
14
  }
15
15
  export {
16
16
  CodeBlockCopyButton as default
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { CodeBlockComponentProps } from '@hackersheet/react-document-content';
3
3
 
4
- declare function CodeBlock({ code, language }: CodeBlockComponentProps): Promise<React.JSX.Element>;
4
+ declare function CodeBlock({ code, ...props }: CodeBlockComponentProps): Promise<React.JSX.Element>;
5
5
 
6
6
  export { CodeBlock as default };
@@ -1,16 +1,10 @@
1
1
  import React from "react";
2
2
  import CodeBlockCopyButton from "./code-block-copy-button";
3
3
  import CodeBlockIcon from "./code-block-icon";
4
- import CodeBlockKifu from "./code-block-kifu";
5
- import CodeBlockMermaid from "./code-block-mermaid";
6
4
  import { highlighteCode } from "./shiki";
7
- async function CodeBlock({ code, language }) {
8
- const [lang, filename] = language.split(":");
9
- const isMermaid = lang === "mermaid";
10
- const isKifu = lang === "kifu";
11
- if (isMermaid) return /* @__PURE__ */ React.createElement(CodeBlockMermaid, { code });
12
- if (isKifu) return /* @__PURE__ */ React.createElement(CodeBlockKifu, { kifu: code, filename });
13
- const html = await highlighteCode(code, lang);
5
+ async function CodeBlock({ code, ...props }) {
6
+ const [language, filename] = props.language.split(":");
7
+ const html = await highlighteCode(code, language);
14
8
  return /* @__PURE__ */ React.createElement("div", { className: "code-block" }, /* @__PURE__ */ React.createElement("div", { className: "code-block-header" }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(CodeBlockIcon, { language })), /* @__PURE__ */ React.createElement("div", { className: "code-block-filename" }, filename), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(CodeBlockCopyButton, { code }))), html && /* @__PURE__ */ React.createElement("div", { dangerouslySetInnerHTML: { __html: html } }), !html && /* @__PURE__ */ React.createElement("pre", null, code));
15
9
  }
16
10
  export {
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { DirectoryTreeComponentProps } from '@hackersheet/react-document-content';
3
+
4
+ declare function DirectoryTree({ code, ...props }: DirectoryTreeComponentProps): Promise<React.JSX.Element>;
5
+
6
+ export { DirectoryTree as default };
@@ -0,0 +1,63 @@
1
+ import React from "react";
2
+ import { LuFolder, LuFile, LuFolderTree } from "react-icons/lu";
3
+ import CodeBlockCopyButton from "./code-block-copy-button";
4
+ async function DirectoryTree({ code, ...props }) {
5
+ const [, filename] = props.language.split(":");
6
+ const treeNode = parseTreeOutput(code);
7
+ const renderTree = (node) => {
8
+ return /* @__PURE__ */ React.createElement("li", { className: `${node.type === "directory" ? "directory-tree-directory" : "directory-tree-file"}` }, /* @__PURE__ */ React.createElement("div", { className: "directory-tree-node-content" }, /* @__PURE__ */ React.createElement("div", { className: "directory-tree-icon" }, node.type === "directory" && /* @__PURE__ */ React.createElement(LuFolder, null), node.type === "file" && /* @__PURE__ */ React.createElement(LuFile, null)), /* @__PURE__ */ React.createElement("div", null, node.name)), node.children && /* @__PURE__ */ React.createElement("ul", null, node.children.map((child) => renderTree(child))));
9
+ };
10
+ return /* @__PURE__ */ React.createElement("div", { className: "code-block" }, /* @__PURE__ */ React.createElement("div", { className: "code-block-header" }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(LuFolderTree, null)), /* @__PURE__ */ React.createElement("div", { className: "code-block-filename" }, filename), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(CodeBlockCopyButton, { code }))), /* @__PURE__ */ React.createElement("div", null, treeNode ? /* @__PURE__ */ React.createElement("ul", { className: "directory-tree" }, renderTree(treeNode)) : /* @__PURE__ */ React.createElement("pre", null, code)));
11
+ }
12
+ function parseTreeOutput(treeOutput) {
13
+ const lines = treeOutput.trim().split("\n");
14
+ const rootNode = {
15
+ name: "",
16
+ type: "directory",
17
+ level: 0,
18
+ children: []
19
+ };
20
+ const stack = [{ node: rootNode, level: 0 }];
21
+ let rootNodeSet = false;
22
+ const getExtension = (filename) => filename.match(/\.(\w+)$/)?.[1];
23
+ const cleanNodeName = (name) => name.replace(/^[\s│├└─]+/, "").trim();
24
+ try {
25
+ lines.forEach((line) => {
26
+ const trimmedLine = line.trimStart();
27
+ const indent = (trimmedLine.match(/^[\s│├└─]+/) || [""])[0];
28
+ const level = indent.length / 4;
29
+ const cleanedLine = cleanNodeName(trimmedLine);
30
+ if (level === 0 && !rootNodeSet) {
31
+ rootNode.name = cleanedLine;
32
+ rootNodeSet = true;
33
+ return;
34
+ }
35
+ const isDirectory = !cleanedLine.includes(".");
36
+ const newNode = {
37
+ name: cleanedLine,
38
+ type: isDirectory ? "directory" : "file",
39
+ extension: isDirectory ? void 0 : getExtension(cleanedLine),
40
+ level,
41
+ children: isDirectory ? [] : void 0
42
+ };
43
+ while (stack.length > 0 && stack[stack.length - 1].level >= level) {
44
+ stack.pop();
45
+ }
46
+ if (stack[stack.length - 1] === void 0) {
47
+ throw new Error("Tree parsing failed");
48
+ }
49
+ const parentNode = stack[stack.length - 1].node;
50
+ parentNode.children = parentNode.children || [];
51
+ parentNode.children.push(newNode);
52
+ if (newNode.type === "directory") {
53
+ stack.push({ node: newNode, level });
54
+ }
55
+ });
56
+ return rootNode;
57
+ } catch (e) {
58
+ return null;
59
+ }
60
+ }
61
+ export {
62
+ DirectoryTree as default
63
+ };
@@ -1,4 +1,9 @@
1
- import { transformerNotationDiff, transformerNotationWordHighlight } from "@shikijs/transformers";
1
+ import {
2
+ transformerNotationDiff,
3
+ transformerNotationWordHighlight,
4
+ transformerRemoveNotationEscape,
5
+ transformerNotationHighlight
6
+ } from "@shikijs/transformers";
2
7
  import { cache } from "react";
3
8
  import { bundledLanguages, bundledThemes, getSingletonHighlighter } from "shiki";
4
9
  async function highlighteCode(code, language) {
@@ -7,13 +12,18 @@ async function highlighteCode(code, language) {
7
12
  if (shikiLang === void 0 && language !== "text") {
8
13
  return null;
9
14
  }
10
- const html = highlighter.codeToHtml(code, {
15
+ const html = highlighter.codeToHtml(code.trim(), {
11
16
  lang: shikiLang || "text",
12
17
  themes: {
13
18
  light: "github-light",
14
19
  dark: "github-dark-dimmed"
15
20
  },
16
- transformers: [transformerNotationDiff(), transformerNotationWordHighlight()]
21
+ transformers: [
22
+ transformerNotationDiff(),
23
+ transformerNotationHighlight(),
24
+ transformerNotationWordHighlight(),
25
+ transformerRemoveNotationEscape()
26
+ ]
17
27
  });
18
28
  return html;
19
29
  }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { GistComponentProps } from '@hackersheet/react-document-content';
3
+
4
+ declare function Gist({ gistId, username, filename }: GistComponentProps): Promise<React.JSX.Element>;
5
+
6
+ export { Gist as default };
@@ -0,0 +1,25 @@
1
+ import Script from "next/script";
2
+ import React from "react";
3
+ async function Gist({ gistId, username, filename }) {
4
+ const gistUrl = (() => {
5
+ const base = `https://gist.github.com/${username}/${gistId}.json`;
6
+ if (filename) {
7
+ return base + `?file=${filename}`;
8
+ }
9
+ return base;
10
+ })();
11
+ const result = await fetch(gistUrl);
12
+ const json = await result.json();
13
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
14
+ "div",
15
+ {
16
+ className: "gist-block",
17
+ dangerouslySetInnerHTML: {
18
+ __html: json.div
19
+ }
20
+ }
21
+ ), /* @__PURE__ */ React.createElement(Script, { stylesheets: [json.stylesheet] }));
22
+ }
23
+ export {
24
+ Gist as default
25
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { HeadingComponentProps } from '@hackersheet/react-document-content';
3
+
4
+ declare function Heading({ HeadingTag, id, children }: HeadingComponentProps): React.JSX.Element;
5
+
6
+ export { Heading as default };
@@ -0,0 +1,9 @@
1
+ import Link from "next/link";
2
+ import React from "react";
3
+ import { MdLink } from "react-icons/md";
4
+ function Heading({ HeadingTag, id, children }) {
5
+ return /* @__PURE__ */ React.createElement(HeadingTag, { id, className: "heading" }, /* @__PURE__ */ React.createElement(Link, { href: `#${id}` }, /* @__PURE__ */ React.createElement("span", { className: "heading-label" }, children), /* @__PURE__ */ React.createElement("span", { className: "heading-link-icon" }, /* @__PURE__ */ React.createElement(MdLink, null))));
6
+ }
7
+ export {
8
+ Heading as default
9
+ };
@@ -1,8 +1,11 @@
1
1
  export { default as CodeBlock } from './code-block/code-block.mjs';
2
+ export { default as DirectoryTree } from './code-block/directory-tree.mjs';
3
+ export { default as Gist } from './gist/gist.mjs';
4
+ export { default as Heading } from './heading/heading.mjs';
2
5
  export { default as Image } from './image/image.mjs';
3
- export { default as KifuTo } from './kifu-to/kifu-to.mjs';
4
6
  export { default as Link } from './link/link.mjs';
5
7
  export { default as LinkCard } from './link-card/link-card.mjs';
8
+ export { default as Mermaid } from './mermaid/mermaid.mjs';
6
9
  export { default as XPost } from './x-post/x-post.mjs';
7
10
  export { default as Youtube } from './youtube/youtube.mjs';
8
11
  import 'react';
@@ -1,16 +1,22 @@
1
1
  import CodeBlock from "./code-block/code-block";
2
+ import DirectoryTree from "./code-block/directory-tree";
3
+ import Gist from "./gist/gist";
4
+ import Heading from "./heading/heading";
2
5
  import Image from "./image/image";
3
- import KifuTo from "./kifu-to/kifu-to";
4
6
  import Link from "./link/link";
5
7
  import LinkCard from "./link-card/link-card";
8
+ import Mermaid from "./mermaid/mermaid";
6
9
  import XPost from "./x-post/x-post";
7
10
  import Youtube from "./youtube/youtube";
8
11
  export {
9
12
  CodeBlock,
13
+ DirectoryTree,
14
+ Gist,
15
+ Heading,
10
16
  Image,
11
- KifuTo,
12
17
  Link,
13
18
  LinkCard,
19
+ Mermaid,
14
20
  XPost,
15
21
  Youtube
16
22
  };