nested-markdown 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,40 +1,11 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __typeError = (msg) => {
8
- throw TypeError(msg);
9
- };
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __commonJS = (cb, mod) => function __require() {
12
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
- };
14
- var __export = (target, all4) => {
15
- for (var name2 in all4)
16
- __defProp(target, name2, { get: all4[name2], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
- // If the importer is in node compatibility mode or this is not an ESM
28
- // file that has been converted to a CommonJS file using a Babel-
29
- // compatible transform (i.e. "__esModule" has not been set), then set
30
- // "default" to the CommonJS "module.exports" for node compatibility.
31
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
- mod
33
- ));
34
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
35
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
36
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
37
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
1
+ import {
2
+ __commonJS,
3
+ __export,
4
+ __privateAdd,
5
+ __privateMethod,
6
+ __publicField,
7
+ __toESM
8
+ } from "./chunk-Q4XP6UTR.js";
38
9
 
39
10
  // node_modules/inline-style-parser/cjs/index.js
40
11
  var require_cjs = __commonJS({
@@ -6677,7 +6648,10 @@ var require_parser = __commonJS({
6677
6648
  });
6678
6649
 
6679
6650
  // src/NestedMarkdown.tsx
6680
- import { useState as useState3, useEffect as useEffect3 } from "react";
6651
+ import {
6652
+ useState as useState2,
6653
+ useEffect as useEffect2
6654
+ } from "react";
6681
6655
 
6682
6656
  // node_modules/devlop/lib/default.js
6683
6657
  function ok() {
@@ -8326,11 +8300,11 @@ function addChildren(props, children2) {
8326
8300
  }
8327
8301
  }
8328
8302
  }
8329
- function productionCreate(_, jsx4, jsxs3) {
8303
+ function productionCreate(_, jsx3, jsxs3) {
8330
8304
  return create3;
8331
8305
  function create3(_2, type, props, key) {
8332
8306
  const isStaticChildren = Array.isArray(props.children);
8333
- const fn = isStaticChildren ? jsxs3 : jsx4;
8307
+ const fn = isStaticChildren ? jsxs3 : jsx3;
8334
8308
  return key ? fn(type, props, key) : fn(type, props);
8335
8309
  }
8336
8310
  }
@@ -28234,69 +28208,8 @@ function expandNestedMarkdownSync(markdown, options2) {
28234
28208
  );
28235
28209
  }
28236
28210
 
28237
- // src/Mermaid.tsx
28238
- import { useEffect as useEffect2, useState as useState2, useId } from "react";
28239
- import { jsx as jsx2 } from "react/jsx-runtime";
28240
- var MermaidClient = ({ chart, theme }) => {
28241
- const id = useId().replace(/:/g, "");
28242
- const [svg5, setSvg] = useState2("");
28243
- const [hydrated, setHydrated] = useState2(false);
28244
- useEffect2(() => {
28245
- let cancelled = false;
28246
- setHydrated(true);
28247
- const renderChart = async () => {
28248
- try {
28249
- const { default: mermaid } = await import("mermaid");
28250
- let mermaidTheme = "default";
28251
- if (theme === "dark") {
28252
- mermaidTheme = "dark";
28253
- } else if (theme === "light") {
28254
- mermaidTheme = "default";
28255
- } else {
28256
- if (typeof window !== "undefined") {
28257
- mermaidTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "default";
28258
- }
28259
- }
28260
- mermaid.initialize({
28261
- startOnLoad: false,
28262
- theme: mermaidTheme,
28263
- securityLevel: "loose",
28264
- suppressErrorRendering: true
28265
- });
28266
- const { svg: svg6 } = await mermaid.render(`mermaid-${id}`, chart);
28267
- if (!cancelled) {
28268
- setSvg(svg6);
28269
- }
28270
- } catch (error) {
28271
- console.error("Failed to render mermaid chart:", error);
28272
- if (!cancelled) {
28273
- setSvg(
28274
- `<pre class="mermaid-error" style="color: var(--nmd-error, #ef4444); padding: 8px; background: var(--nmd-error-bg, #fee2e2); border-radius: 4px;">Mermaid syntax error</pre>`
28275
- );
28276
- }
28277
- }
28278
- };
28279
- if (chart) {
28280
- renderChart();
28281
- }
28282
- return () => {
28283
- cancelled = true;
28284
- };
28285
- }, [chart, id, theme]);
28286
- if (!hydrated) {
28287
- return /* @__PURE__ */ jsx2("pre", { className: "mermaid", children: chart });
28288
- }
28289
- return /* @__PURE__ */ jsx2("div", { className: "mermaid", dangerouslySetInnerHTML: { __html: svg5 } });
28290
- };
28291
- var Mermaid = ({ chart, theme }) => {
28292
- if (typeof window === "undefined") {
28293
- return /* @__PURE__ */ jsx2("pre", { className: "mermaid", children: chart });
28294
- }
28295
- return /* @__PURE__ */ jsx2(MermaidClient, { chart, theme });
28296
- };
28297
-
28298
28211
  // src/NestedMarkdown.tsx
28299
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
28212
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
28300
28213
  function toKebabCase(propertyName) {
28301
28214
  if (propertyName.startsWith("--")) return propertyName;
28302
28215
  if (propertyName.startsWith("Webkit")) {
@@ -28388,6 +28301,45 @@ var remarkForceLooseLists = () => {
28388
28301
  visit3(tree);
28389
28302
  };
28390
28303
  };
28304
+ var MermaidRenderer = ({
28305
+ chart,
28306
+ theme,
28307
+ className,
28308
+ codeProps
28309
+ }) => {
28310
+ const [MermaidComponent, setMermaidComponent] = useState2(null);
28311
+ useEffect2(() => {
28312
+ let mounted = true;
28313
+ if (typeof window === "undefined" || typeof document === "undefined") {
28314
+ return () => {
28315
+ mounted = false;
28316
+ };
28317
+ }
28318
+ import("./Mermaid-N3HH3ZBE.js").then((mod) => {
28319
+ if (mounted) {
28320
+ setMermaidComponent(() => mod.Mermaid);
28321
+ }
28322
+ }).catch(() => {
28323
+ if (mounted) {
28324
+ setMermaidComponent(null);
28325
+ }
28326
+ });
28327
+ return () => {
28328
+ mounted = false;
28329
+ };
28330
+ }, []);
28331
+ if (!MermaidComponent) {
28332
+ return /* @__PURE__ */ jsx2("pre", { className: "nmd-pre", children: /* @__PURE__ */ jsx2(
28333
+ "code",
28334
+ {
28335
+ ...codeProps,
28336
+ className: [className, "nmd-code"].filter(Boolean).join(" "),
28337
+ children: chart
28338
+ }
28339
+ ) });
28340
+ }
28341
+ return /* @__PURE__ */ jsx2(MermaidComponent, { chart, theme });
28342
+ };
28391
28343
  var NestedMarkdown = ({
28392
28344
  content: content3,
28393
28345
  children: children2,
@@ -28401,7 +28353,7 @@ var NestedMarkdown = ({
28401
28353
  ...reactMarkdownProps
28402
28354
  }) => {
28403
28355
  const markdownSource = content3 ?? children2 ?? "";
28404
- const [expandedMarkdown, setExpandedMarkdown] = useState3(() => {
28356
+ const [expandedMarkdown, setExpandedMarkdown] = useState2(() => {
28405
28357
  try {
28406
28358
  return expandNestedMarkdownSync(markdownSource, { defaultShow });
28407
28359
  } catch (err) {
@@ -28409,7 +28361,7 @@ var NestedMarkdown = ({
28409
28361
  return markdownSource;
28410
28362
  }
28411
28363
  });
28412
- useEffect3(() => {
28364
+ useEffect2(() => {
28413
28365
  let mounted = true;
28414
28366
  const process = async () => {
28415
28367
  try {
@@ -28430,36 +28382,34 @@ var NestedMarkdown = ({
28430
28382
  };
28431
28383
  }, [content3, children2, defaultShow]);
28432
28384
  const defaultComponents = {
28433
- a: ({ node: node2, ...props }) => /* @__PURE__ */ jsx3(
28385
+ a: ({ node: node2, ...props }) => /* @__PURE__ */ jsx2(
28434
28386
  "a",
28435
28387
  {
28436
28388
  ...props,
28437
28389
  rel: props.target === "_blank" ? "noopener noreferrer" : props.rel
28438
28390
  }
28439
28391
  ),
28440
- table: ({ node: node2, ...props }) => /* @__PURE__ */ jsx3("div", { className: "nmd-table-wrap", children: /* @__PURE__ */ jsx3("table", { className: "nmd-table", ...props }) }),
28441
- th: ({ node: node2, ...props }) => /* @__PURE__ */ jsx3("th", { className: "nmd-th", ...props }),
28442
- td: ({ node: node2, ...props }) => /* @__PURE__ */ jsx3("td", { className: "nmd-td", ...props }),
28443
- pre: ({ node: node2, ...props }) => /* @__PURE__ */ jsx3("pre", { className: "nmd-pre", ...props }),
28392
+ table: ({ node: node2, ...props }) => /* @__PURE__ */ jsx2("div", { className: "nmd-table-wrap", children: /* @__PURE__ */ jsx2("table", { className: "nmd-table", ...props }) }),
28393
+ th: ({ node: node2, ...props }) => /* @__PURE__ */ jsx2("th", { className: "nmd-th", ...props }),
28394
+ td: ({ node: node2, ...props }) => /* @__PURE__ */ jsx2("td", { className: "nmd-td", ...props }),
28395
+ pre: ({ node: node2, ...props }) => /* @__PURE__ */ jsx2("pre", { className: "nmd-pre", ...props }),
28444
28396
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
28445
28397
  code: ({ node: node2, inline: inline2, className: className2, children: children3, ...props }) => {
28446
28398
  const match = /language-(\w+)/.exec(className2 || "");
28447
28399
  const isMermaid = match && match[1] === "mermaid";
28448
28400
  if (!inline2 && isMermaid) {
28449
28401
  const chart = String(children3).replace(/\n$/, "");
28450
- if (typeof window === "undefined") {
28451
- return /* @__PURE__ */ jsx3("pre", { className: "nmd-pre", children: /* @__PURE__ */ jsx3(
28452
- "code",
28453
- {
28454
- ...props,
28455
- className: [className2, "nmd-code"].filter(Boolean).join(" "),
28456
- children: chart
28457
- }
28458
- ) });
28459
- }
28460
- return /* @__PURE__ */ jsx3(Mermaid, { chart, theme: theme === "auto" ? void 0 : theme });
28402
+ return /* @__PURE__ */ jsx2(
28403
+ MermaidRenderer,
28404
+ {
28405
+ chart,
28406
+ theme: theme === "auto" ? void 0 : theme,
28407
+ className: className2,
28408
+ codeProps: props
28409
+ }
28410
+ );
28461
28411
  }
28462
- return /* @__PURE__ */ jsx3(
28412
+ return /* @__PURE__ */ jsx2(
28463
28413
  "code",
28464
28414
  {
28465
28415
  ...props,
@@ -28475,7 +28425,7 @@ var NestedMarkdown = ({
28475
28425
  if (src && !src.startsWith("http") && !src.startsWith("/") && !src.startsWith("data:")) {
28476
28426
  src = `/${src}`;
28477
28427
  }
28478
- return /* @__PURE__ */ jsx3(
28428
+ return /* @__PURE__ */ jsx2(
28479
28429
  "img",
28480
28430
  {
28481
28431
  ...imgProps,
@@ -28486,7 +28436,7 @@ var NestedMarkdown = ({
28486
28436
  );
28487
28437
  },
28488
28438
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
28489
- blockquote: ({ node: node2, ...props }) => /* @__PURE__ */ jsx3("blockquote", { className: "nmd-blockquote", ...props })
28439
+ blockquote: ({ node: node2, ...props }) => /* @__PURE__ */ jsx2("blockquote", { className: "nmd-blockquote", ...props })
28490
28440
  };
28491
28441
  const mergedComponents = { ...defaultComponents, ...components };
28492
28442
  const mergedRemarkPlugins = [
@@ -28724,9 +28674,9 @@ var NestedMarkdown = ({
28724
28674
  style: style2,
28725
28675
  "data-theme": theme,
28726
28676
  children: [
28727
- /* @__PURE__ */ jsx3("style", { children: `${stylesheet}
28677
+ /* @__PURE__ */ jsx2("style", { children: `${stylesheet}
28728
28678
  ${autoDarkStylesheet}` }),
28729
- /* @__PURE__ */ jsx3(
28679
+ /* @__PURE__ */ jsx2(
28730
28680
  Markdown,
28731
28681
  {
28732
28682
  ...reactMarkdownProps,