@noirmd/previewer 1.2.0 → 2.0.0

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 (53) hide show
  1. package/dist/NReditor.cjs +851 -895
  2. package/dist/NReditor.cjs.map +1 -1
  3. package/dist/NReditor.d.cts +1 -1
  4. package/dist/NReditor.d.ts +1 -1
  5. package/dist/NReditor.js +852 -896
  6. package/dist/NReditor.js.map +1 -1
  7. package/dist/admonition.css +55 -0
  8. package/dist/{markdown.css → base.css} +96 -126
  9. package/dist/blockquote.css +16 -0
  10. package/dist/button.css +32 -0
  11. package/dist/card.css +143 -0
  12. package/dist/codeblock.css +59 -0
  13. package/dist/core.cjs +9 -1
  14. package/dist/core.cjs.map +1 -1
  15. package/dist/core.js +9 -1
  16. package/dist/core.js.map +1 -1
  17. package/dist/details.css +45 -0
  18. package/dist/editor.css +56 -9
  19. package/dist/fonts/material-icons-round.woff2 +0 -0
  20. package/dist/index.cjs +852 -883
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +41 -70
  23. package/dist/index.d.ts +41 -70
  24. package/dist/index.js +851 -877
  25. package/dist/index.js.map +1 -1
  26. package/dist/list.css +18 -0
  27. package/dist/modal.css +82 -0
  28. package/dist/react.cjs +852 -886
  29. package/dist/react.cjs.map +1 -1
  30. package/dist/react.d.cts +44 -73
  31. package/dist/react.d.ts +44 -73
  32. package/dist/react.js +851 -880
  33. package/dist/react.js.map +1 -1
  34. package/dist/slide.css +21 -0
  35. package/dist/table.css +36 -0
  36. package/dist/toc.css +45 -0
  37. package/dist/vanilla.cjs +42 -28
  38. package/dist/vanilla.cjs.map +1 -1
  39. package/dist/vanilla.css +32 -677
  40. package/dist/vanilla.d.cts +8 -2
  41. package/dist/vanilla.d.ts +8 -2
  42. package/dist/vanilla.js +41 -28
  43. package/dist/vanilla.js.map +1 -1
  44. package/dist/variables.css +53 -0
  45. package/dist/vue.cjs +931 -1121
  46. package/dist/vue.cjs.map +1 -1
  47. package/dist/vue.d.cts +63 -214
  48. package/dist/vue.d.ts +63 -214
  49. package/dist/vue.js +930 -1120
  50. package/dist/vue.js.map +1 -1
  51. package/editor.css +56 -9
  52. package/package.json +5 -10
  53. package/markdown.css +0 -344
package/dist/index.js CHANGED
@@ -1657,6 +1657,7 @@ function parseMarkdown(markdown2) {
1657
1657
  if (!markdown2) return [];
1658
1658
  const lines = markdown2.replace(/\r\n/g, "\n").replace(/\r/g, "").split("\n");
1659
1659
  const result = [];
1660
+ const usedIds = /* @__PURE__ */ new Set();
1660
1661
  let i = 0;
1661
1662
  while (i < lines.length) {
1662
1663
  const line = lines[i];
@@ -1666,7 +1667,14 @@ function parseMarkdown(markdown2) {
1666
1667
  const level = match[1].length;
1667
1668
  const rawText = match[2];
1668
1669
  const { text: text2, classes: classes2, id: customId } = extractAttributes(rawText);
1669
- const id2 = customId || generateId(text2.replace(/->|<-/g, ""));
1670
+ const baseId = customId || generateId(text2.replace(/->|<-/g, ""));
1671
+ let id2 = baseId;
1672
+ let n = 1;
1673
+ while (usedIds.has(id2)) {
1674
+ n++;
1675
+ id2 = `${baseId}-${n}`;
1676
+ }
1677
+ usedIds.add(id2);
1670
1678
  result.push({ type: "header", level, text: text2, id: id2, classes: classes2 || void 0 });
1671
1679
  i++;
1672
1680
  continue;
@@ -1982,10 +1990,7 @@ function splitSlots(rawContent) {
1982
1990
  }
1983
1991
 
1984
1992
  // react/CustomMarkdownRenderer.tsx
1985
- import React8, { useState as useState3, useEffect as useEffect4, useCallback as useCallback2, useMemo, useId as useId3, useRef as useRef5 } from "react";
1986
-
1987
- // react/ui-components.tsx
1988
- import { useState, useRef } from "react";
1993
+ import { useEffect as useEffect2, useRef as useRef2 } from "react";
1989
1994
 
1990
1995
  // node_modules/highlight.js/es/core.js
1991
1996
  var import_core = __toESM(require_core(), 1);
@@ -10883,7 +10888,7 @@ function shell(hljs) {
10883
10888
  };
10884
10889
  }
10885
10890
 
10886
- // react/highlightSetup.ts
10891
+ // vanilla/highlightSetup.ts
10887
10892
  core_default.registerLanguage("javascript", javascript);
10888
10893
  core_default.registerLanguage("js", javascript);
10889
10894
  core_default.registerLanguage("jsx", javascript);
@@ -10907,729 +10912,922 @@ core_default.registerLanguage("java", java);
10907
10912
  core_default.registerLanguage("csharp", csharp);
10908
10913
  core_default.registerLanguage("cs", csharp);
10909
10914
  core_default.registerLanguage("cpp", cpp);
10910
- core_default.registerLanguage("c", cpp);
10911
10915
  core_default.registerLanguage("go", go);
10912
10916
  core_default.registerLanguage("rust", rust);
10913
- core_default.registerLanguage("rs", rust);
10914
10917
  core_default.registerLanguage("php", php);
10915
10918
  core_default.registerLanguage("ruby", ruby);
10916
- core_default.registerLanguage("rb", ruby);
10917
10919
  core_default.registerLanguage("swift", swift);
10918
10920
  core_default.registerLanguage("kotlin", kotlin);
10919
- core_default.registerLanguage("kt", kotlin);
10920
10921
  core_default.registerLanguage("dart", dart);
10921
10922
  core_default.registerLanguage("yaml", yaml);
10922
- core_default.registerLanguage("yml", yaml);
10923
10923
  core_default.registerLanguage("toml", ini);
10924
- core_default.registerLanguage("ini", ini);
10925
10924
  core_default.registerLanguage("dockerfile", dockerfile);
10926
- core_default.registerLanguage("docker", dockerfile);
10927
10925
  core_default.registerLanguage("diff", diff);
10928
10926
  core_default.registerLanguage("shell", shell);
10929
10927
  var highlightSetup_default = core_default;
10930
10928
 
10931
- // react/ui-components.tsx
10932
- import { Dialog } from "@base-ui/react/dialog";
10933
- import { jsx, jsxs } from "react/jsx-runtime";
10934
- var IconRenderer = ({ iconName, extraClasses = "" }) => {
10935
- if (!iconName) return null;
10936
- const baseClass = `material-symbols-rounded !text-[1em] leading-none align-top ${extraClasses}`;
10929
+ // vanilla/components.ts
10930
+ function createIcon(iconName, extraClasses) {
10931
+ const span = document.createElement("span");
10932
+ const cls = `nr-icon material-icons-round${extraClasses ? ` ${extraClasses}` : ""}`;
10933
+ span.className = cls;
10934
+ span.setAttribute("aria-hidden", "true");
10937
10935
  const isCodepoint = /^[eE][0-9a-fA-F]{3,4}$/.test(iconName);
10938
10936
  if (isCodepoint) {
10939
- return /* @__PURE__ */ jsx(
10940
- "span",
10941
- {
10942
- className: baseClass,
10943
- dangerouslySetInnerHTML: { __html: `&#x${iconName};` },
10944
- "aria-hidden": "true"
10945
- }
10946
- );
10937
+ span.innerHTML = `&#x${iconName};`;
10938
+ } else {
10939
+ span.textContent = iconName;
10947
10940
  }
10948
- return /* @__PURE__ */ jsx("span", { className: baseClass, "aria-hidden": "true", children: iconName });
10949
- };
10950
- var CodeBlock = ({ code, language, title }) => {
10951
- const [copied, setCopied] = useState(false);
10952
- const timerRef = useRef(null);
10941
+ return span;
10942
+ }
10943
+ function createCodeBlock(code, language, title) {
10944
+ const wrapper = document.createElement("div");
10945
+ wrapper.className = "nr-codeblock";
10953
10946
  const lang = language?.split(/[\s{]/)[0]?.trim() || "";
10954
- let html;
10947
+ if (title) {
10948
+ const header = document.createElement("div");
10949
+ header.className = "nr-codeblock__header";
10950
+ header.appendChild(createIcon("description"));
10951
+ const titleSpan = document.createElement("span");
10952
+ titleSpan.textContent = title;
10953
+ header.appendChild(titleSpan);
10954
+ wrapper.appendChild(header);
10955
+ }
10956
+ const pre = document.createElement("pre");
10957
+ pre.className = "nr-codeblock__pre";
10958
+ const codeEl = document.createElement("code");
10959
+ codeEl.className = `language-${lang || "plaintext"}`;
10955
10960
  try {
10956
10961
  if (lang && highlightSetup_default.getLanguage(lang)) {
10957
- html = highlightSetup_default.highlight(code, { language: lang }).value;
10962
+ codeEl.innerHTML = highlightSetup_default.highlight(code, { language: lang }).value;
10958
10963
  } else {
10959
- html = highlightSetup_default.highlightAuto(code).value;
10964
+ codeEl.innerHTML = highlightSetup_default.highlightAuto(code).value;
10960
10965
  }
10961
10966
  } catch {
10962
- html = "";
10967
+ codeEl.textContent = code;
10963
10968
  }
10964
- const handleCopy = () => {
10969
+ pre.appendChild(codeEl);
10970
+ wrapper.appendChild(pre);
10971
+ const copyBtn = document.createElement("button");
10972
+ copyBtn.className = "nr-codeblock__copy";
10973
+ copyBtn.title = "Copy code";
10974
+ const copyIcon = createIcon("content_copy");
10975
+ copyIcon.style.fontSize = "1rem";
10976
+ copyBtn.appendChild(copyIcon);
10977
+ let timer = null;
10978
+ copyBtn.addEventListener("click", () => {
10965
10979
  navigator.clipboard.writeText(code);
10966
- setCopied(true);
10967
- if (timerRef.current) clearTimeout(timerRef.current);
10968
- timerRef.current = setTimeout(() => setCopied(false), 1800);
10969
- };
10970
- return /* @__PURE__ */ jsxs("div", { className: "not-prose my-4 rounded-2xl border border-border overflow-hidden bg-background-secondary-solid/5", children: [
10971
- title && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-4 py-2 border-b border-border bg-background-secondary-solid/10 text-xs sm:text-sm font-mono text-text-secondary", children: [
10972
- /* @__PURE__ */ jsx("span", { className: "material-symbols-rounded text-base", children: "description" }),
10973
- title
10974
- ] }),
10975
- /* @__PURE__ */ jsx("div", { className: "overflow-auto [&_pre]:m-0 [&_pre]:p-4 [&_pre]:text-xs sm:[&_pre]:text-sm", children: /* @__PURE__ */ jsx("pre", { className: "m-0", children: /* @__PURE__ */ jsx("code", { className: `language-${lang || "plaintext"}`, dangerouslySetInnerHTML: { __html: html } }) }) }),
10976
- /* @__PURE__ */ jsx("button", { className: "absolute top-2 right-2 p-1.5 rounded-lg bg-background-secondary-solid/20 hover:bg-background-secondary-solid/40 transition-colors cursor-pointer border-none text-text-secondary hover:text-text-primary", onClick: handleCopy, title: "Copy code", children: /* @__PURE__ */ jsx("span", { className: "material-symbols-rounded", style: { fontSize: "1rem" }, children: copied ? "check" : "content_copy" }) })
10977
- ] });
10978
- };
10979
- var defaultIcons = {
10980
+ copyIcon.textContent = "check";
10981
+ if (timer) clearTimeout(timer);
10982
+ timer = setTimeout(() => {
10983
+ copyIcon.textContent = "content_copy";
10984
+ }, 1800);
10985
+ });
10986
+ wrapper.appendChild(copyBtn);
10987
+ return wrapper;
10988
+ }
10989
+ var DEFAULT_ADMONITION_ICONS = {
10980
10990
  note: "info",
10981
10991
  info: "lightbulb",
10982
10992
  warning: "warning",
10983
10993
  danger: "report",
10984
- greentext: "subdirectory_play_arrow"
10985
- };
10986
- var typeClasses = {
10987
- note: "border-info/20 bg-info/5 text-info",
10988
- info: "border-info/30 bg-info/10 text-info",
10989
- warning: "border-amber-500/30 bg-amber-500/10 text-amber-500",
10990
- danger: "border-danger/30 bg-danger/10 text-danger",
10991
- greentext: "border-success/30 bg-success/10 text-success"
10994
+ greentext: "subdirectory_arrow_right"
10992
10995
  };
10993
- var Admonition = ({ type, title, icon, className = "", style, children }) => {
10994
- const iconToRender = icon || defaultIcons[type] || "info";
10995
- return /* @__PURE__ */ jsxs(
10996
- "div",
10997
- {
10998
- className: `not-prose rounded-2xl mb-6 border shadow-xs p-4 ${typeClasses[type] || typeClasses.note} ${className}`,
10999
- style,
11000
- children: [
11001
- title && /* @__PURE__ */ jsxs("h5", { className: "font-bold text-base mb-2 m-0 flex items-center gap-2", children: [
11002
- /* @__PURE__ */ jsx(IconRenderer, { iconName: iconToRender, extraClasses: "shrink-0" }),
11003
- /* @__PURE__ */ jsx("span", { children: title })
11004
- ] }),
11005
- /* @__PURE__ */ jsx("div", { className: "text-sm leading-relaxed opacity-90", children })
11006
- ]
11007
- }
11008
- );
11009
- };
11010
- var Details = ({
11011
- title,
11012
- icon,
11013
- defaultOpen = false,
11014
- className = "",
11015
- style,
11016
- children
11017
- }) => {
11018
- const [isOpen, setIsOpen] = useState(defaultOpen);
10996
+ function createAdmonition(type, title, icon) {
10997
+ const el = document.createElement("div");
10998
+ el.className = `nr-admonition nr-admonition--${type || "note"}`;
10999
+ if (title) {
11000
+ const header = document.createElement("h5");
11001
+ header.className = "nr-admonition__title";
11002
+ const iconToRender = icon || DEFAULT_ADMONITION_ICONS[type] || "info";
11003
+ header.appendChild(createIcon(iconToRender, "nr-admonition__icon"));
11004
+ const titleSpan = document.createElement("span");
11005
+ titleSpan.textContent = title;
11006
+ header.appendChild(titleSpan);
11007
+ el.appendChild(header);
11008
+ }
11009
+ const body = document.createElement("div");
11010
+ body.className = "nr-admonition__body";
11011
+ el.appendChild(body);
11012
+ return el;
11013
+ }
11014
+ function createDetails(title, icon, defaultOpen) {
11015
+ const details = document.createElement("details");
11016
+ details.className = "nr-details";
11017
+ if (defaultOpen) details.open = true;
11018
+ const summary = document.createElement("summary");
11019
+ summary.className = "nr-details__summary";
11019
11020
  const iconToRender = icon || "play_arrow";
11020
- return /* @__PURE__ */ jsxs(
11021
- "details",
11022
- {
11023
- className: `not-prose rounded-2xl border border-border mb-4 bg-background-primary/5 ${className}`,
11024
- open: isOpen,
11025
- style,
11026
- children: [
11027
- /* @__PURE__ */ jsxs(
11028
- "summary",
11029
- {
11030
- className: "cursor-pointer p-4 font-bold flex items-center gap-2 list-none [&::-webkit-details-marker]:hidden hover:text-accent-primary transition-colors",
11031
- onClick: (e) => {
11032
- e.preventDefault();
11033
- setIsOpen((prev) => !prev);
11034
- },
11035
- children: [
11036
- /* @__PURE__ */ jsx(
11037
- IconRenderer,
11038
- {
11039
- iconName: iconToRender,
11040
- extraClasses: `transition-transform ${isOpen ? "rotate-90" : ""}`
11041
- }
11042
- ),
11043
- /* @__PURE__ */ jsx("span", { children: title })
11044
- ]
11045
- }
11046
- ),
11047
- isOpen && /* @__PURE__ */ jsx("div", { className: "px-4 pb-4 border-t border-border pt-3 text-sm leading-relaxed opacity-90 overflow-hidden min-w-0", children })
11048
- ]
11049
- }
11050
- );
11051
- };
11052
- var Modal = ({ title, isOpen, onClose, children }) => {
11053
- return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: (open) => {
11054
- if (!open) onClose();
11055
- }, children: /* @__PURE__ */ jsxs(Dialog.Portal, { children: [
11056
- /* @__PURE__ */ jsx(Dialog.Backdrop, { className: "fixed inset-0 z-[9999] bg-black/60" }),
11057
- /* @__PURE__ */ jsx(Dialog.Viewport, { className: "fixed inset-0 z-[9999] flex items-center justify-center p-4", children: /* @__PURE__ */ jsxs(Dialog.Popup, { className: "bg-background-primary border border-border shadow-2xl rounded-3xl w-full max-w-3xl max-h-[85vh] flex flex-col overflow-hidden", children: [
11058
- /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center p-4 border-b border-border bg-background-secondary-solid/20", children: [
11059
- /* @__PURE__ */ jsx(Dialog.Title, { className: "text-lg font-bold !m-0", children: title }),
11060
- /* @__PURE__ */ jsx(Dialog.Close, { className: "w-8 h-8 rounded-full hover:bg-white/10 flex items-center justify-center transition-colors cursor-pointer border-none bg-transparent", children: /* @__PURE__ */ jsx("span", { className: "material-symbols-rounded text-base", children: "close" }) })
11061
- ] }),
11062
- /* @__PURE__ */ jsx("div", { className: "p-6 overflow-auto min-h-0 text-text-primary [&_h1:first-child]:mt-0 [&_h2:first-child]:mt-0 [&_h3:first-child]:mt-0 [&_h4:first-child]:mt-0 [&_h5:first-child]:mt-0 [&_h6:first-child]:mt-0", children })
11063
- ] }) })
11064
- ] }) });
11065
- };
11066
-
11067
- // react/renderers.tsx
11068
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
11069
- function renderInline(text) {
11070
- if (!text) return text;
11071
- const parsePart = (part, key) => {
11072
- let match2;
11073
- if (match2 = part.match(/^\|\[([^\]]+)\]\|$/)) {
11074
- return /* @__PURE__ */ jsx2(IconRenderer, { iconName: match2[1] }, key);
11075
- }
11076
- if (match2 = part.match(/^!~(.+?)~!$/)) {
11077
- const content = match2[1];
11078
- const parts = content.split(";");
11079
- let color = "currentColor";
11080
- let decorationStyle = "solid";
11081
- let type = "underline";
11082
- let textIndex = 0;
11083
- if (parts[textIndex]?.match(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/) || ["red", "blue", "green", "purple", "orange", "yellow", "pink"].includes(parts[textIndex])) {
11084
- color = parts[textIndex++];
11085
- }
11086
- if (["solid", "double", "dotted", "dashed", "wavy"].includes(parts[textIndex])) {
11087
- decorationStyle = parts[textIndex++];
11088
- }
11089
- if (["underline", "line-through", "overline", "both"].includes(parts[textIndex])) {
11090
- type = parts[textIndex] === "both" ? "underline line-through" : parts[textIndex++];
11091
- }
11092
- const innerText = parts.slice(textIndex).join(";");
11093
- return /* @__PURE__ */ jsx2(
11094
- "span",
11095
- {
11096
- style: {
11097
- textDecoration: `${type} ${decorationStyle} ${color}`,
11098
- textDecorationThickness: "auto"
11099
- },
11100
- children: renderInline(innerText)
11101
- },
11102
- key
11103
- );
11104
- }
11105
- if (match2 = part.match(/%([^%\s]+?)%([\s\S]+?)%%/)) {
11106
- return /* @__PURE__ */ jsx2("span", { style: { color: match2[1] }, children: renderInline(match2[2]) }, key);
11107
- }
11108
- if (match2 = part.match(/^!>([^<]+?)<!$/)) {
11109
- return /* @__PURE__ */ jsx2("span", { className: "bg-text-primary text-bg-primary px-1 rounded hover:bg-transparent transition-colors cursor-pointer", children: renderInline(match2[1]) }, key);
11110
- }
11111
- if (match2 = part.match(/^==(.+?)==$/)) {
11112
- return /* @__PURE__ */ jsx2("mark", { className: "bg-yellow-500/20 text-inherit px-0.5 rounded", children: renderInline(match2[1]) }, key);
11113
- }
11114
- if (match2 = part.match(/^\*\*\*(.+?)\*\*\*$/)) {
11115
- return /* @__PURE__ */ jsx2("strong", { children: /* @__PURE__ */ jsx2("em", { children: renderInline(match2[1]) }) }, key);
11116
- }
11117
- if (match2 = part.match(/^\*\*(.+?)\*\*$/)) {
11118
- return /* @__PURE__ */ jsx2("strong", { children: renderInline(match2[1]) }, key);
11119
- }
11120
- if (match2 = part.match(/^_(.+?)_$/)) {
11121
- return /* @__PURE__ */ jsx2("em", { children: renderInline(match2[1]) }, key);
11122
- }
11123
- if (match2 = part.match(/^~~(.+?)~~$/)) {
11124
- return /* @__PURE__ */ jsx2("del", { children: renderInline(match2[1]) }, key);
11125
- }
11126
- if (match2 = part.match(/^`([^`]+)`$/)) {
11127
- return /* @__PURE__ */ jsx2("code", { className: "text-[0.875em] font-mono bg-background-secondary/50 px-1.5 py-0.5 rounded text-text-primary", children: match2[1] }, key);
11128
- }
11129
- if (match2 = part.match(/^\[([^\]]+?)\]\(([^)]+?)\)$/)) {
11130
- return /* @__PURE__ */ jsx2(
11131
- "a",
11132
- {
11133
- href: match2[2],
11134
- className: "text-accent-primary underline decoration-accent-primary/40 hover:decoration-accent-primary transition-colors",
11135
- target: "_blank",
11136
- rel: "noopener noreferrer",
11137
- children: renderInline(match2[1])
11138
- },
11139
- key
11140
- );
11141
- }
11142
- if (part.startsWith("<") && part.endsWith(">")) {
11143
- return /* @__PURE__ */ jsx2("span", { dangerouslySetInnerHTML: { __html: part } }, key);
11144
- }
11145
- return part;
11146
- };
11147
- const regex = /(\|\[[^\]]+\]\||\*\*\*.+?\*\*\*|\*\*.+?\*\*|_.+?_|~~.+?~~|`[^`]+?`|!~.+?~!|%[^%\s]+?%[\s\S]+?%%|!>.+?<!|==.+?==|\[[^\]]+?\]\([^)]+?\)|<[^>]+>)/g;
11148
- const elements = [];
11149
- let lastIndex = 0;
11150
- let match;
11151
- let keyCounter = 0;
11152
- while ((match = regex.exec(text)) !== null) {
11153
- if (match.index > lastIndex) {
11154
- elements.push(text.slice(lastIndex, match.index));
11021
+ const iconEl = createIcon(iconToRender, "nr-details__icon");
11022
+ summary.appendChild(iconEl);
11023
+ const titleSpan = document.createElement("span");
11024
+ titleSpan.textContent = title || "Details";
11025
+ summary.appendChild(titleSpan);
11026
+ details.addEventListener("toggle", () => {
11027
+ iconEl.classList.toggle("nr-details__icon--open", details.open);
11028
+ });
11029
+ details.appendChild(summary);
11030
+ const body = document.createElement("div");
11031
+ body.className = "nr-details__body";
11032
+ details.appendChild(body);
11033
+ return details;
11034
+ }
11035
+ function createModal(title) {
11036
+ const dialog = document.createElement("dialog");
11037
+ dialog.className = "nr-modal";
11038
+ dialog.addEventListener("click", (e) => {
11039
+ if (e.target === dialog) {
11040
+ dialog.close();
11155
11041
  }
11156
- elements.push(parsePart(match[0], `inline-${keyCounter++}`));
11157
- lastIndex = regex.lastIndex;
11158
- }
11159
- if (lastIndex < text.length) {
11160
- elements.push(text.slice(lastIndex));
11161
- }
11162
- return elements;
11042
+ });
11043
+ const popup = document.createElement("div");
11044
+ popup.className = "nr-modal__popup";
11045
+ const header = document.createElement("div");
11046
+ header.className = "nr-modal__header";
11047
+ const titleEl = document.createElement("h2");
11048
+ titleEl.className = "nr-modal__title";
11049
+ titleEl.textContent = title;
11050
+ header.appendChild(titleEl);
11051
+ const closeBtn = document.createElement("button");
11052
+ closeBtn.className = "nr-modal__close";
11053
+ closeBtn.appendChild(createIcon("close"));
11054
+ closeBtn.addEventListener("click", () => dialog.close());
11055
+ header.appendChild(closeBtn);
11056
+ popup.appendChild(header);
11057
+ const body = document.createElement("div");
11058
+ body.className = "nr-modal__body";
11059
+ popup.appendChild(body);
11060
+ dialog.appendChild(popup);
11061
+ return dialog;
11163
11062
  }
11164
- function renderTable(content) {
11063
+ function createTable(content, renderInline2) {
11165
11064
  const rows = content.split("\n").filter((r) => r.trim());
11166
- if (rows.length < 2) return /* @__PURE__ */ jsx2("p", { children: content });
11065
+ if (rows.length < 2) {
11066
+ const p = document.createElement("p");
11067
+ p.textContent = content;
11068
+ return p;
11069
+ }
11167
11070
  const parseRow = (row) => row.split("|").map((c) => c.trim()).filter(Boolean);
11168
11071
  const headerCells = parseRow(rows[0]);
11169
11072
  const bodyRows = rows.slice(2).map(parseRow);
11170
- return /* @__PURE__ */ jsx2("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxs2("table", { className: "w-full text-sm sm:text-base border-collapse my-4", children: [
11171
- /* @__PURE__ */ jsx2("thead", { children: /* @__PURE__ */ jsx2("tr", { children: headerCells.map((cell, ci) => /* @__PURE__ */ jsx2("th", { className: "border border-border px-3 py-2 bg-background-secondary-solid/10 text-left font-bold", children: renderInline(cell) }, ci)) }) }),
11172
- /* @__PURE__ */ jsx2("tbody", { children: bodyRows.map((cells, ri) => /* @__PURE__ */ jsx2("tr", { children: cells.map((cell, ci) => /* @__PURE__ */ jsx2("td", { className: "border border-border px-3 py-2", children: renderInline(cell) }, ci)) }, ri)) })
11173
- ] }) });
11073
+ const wrapper = document.createElement("div");
11074
+ wrapper.className = "nr-table-wrap";
11075
+ const table = document.createElement("table");
11076
+ table.className = "nr-table";
11077
+ const thead = document.createElement("thead");
11078
+ const tr = document.createElement("tr");
11079
+ for (const cell of headerCells) {
11080
+ const th = document.createElement("th");
11081
+ th.className = "nr-table__th";
11082
+ th.appendChild(renderInline2(cell));
11083
+ tr.appendChild(th);
11084
+ }
11085
+ thead.appendChild(tr);
11086
+ table.appendChild(thead);
11087
+ const tbody = document.createElement("tbody");
11088
+ for (const cells of bodyRows) {
11089
+ const tr2 = document.createElement("tr");
11090
+ for (const cell of cells) {
11091
+ const td = document.createElement("td");
11092
+ td.className = "nr-table__td";
11093
+ td.appendChild(renderInline2(cell));
11094
+ tr2.appendChild(td);
11095
+ }
11096
+ tbody.appendChild(tr2);
11097
+ }
11098
+ table.appendChild(tbody);
11099
+ wrapper.appendChild(table);
11100
+ return wrapper;
11174
11101
  }
11175
- function renderList(content) {
11102
+ function createList(content, renderInline2) {
11176
11103
  const lines = content.split("\n");
11177
11104
  const items = [];
11178
11105
  for (const line of lines) {
11179
11106
  if (!line.trim()) continue;
11180
11107
  const match = line.match(/^(\s*)([-*+]|\d+\.)\s+(.+)$/);
11181
11108
  if (match) {
11182
- items.push({
11183
- indent: match[1].length,
11184
- marker: match[2],
11185
- text: match[3]
11186
- });
11109
+ items.push({ indent: match[1].length, marker: match[2], text: match[3] });
11187
11110
  }
11188
11111
  }
11189
- if (items.length === 0) return /* @__PURE__ */ jsx2("p", { children: content });
11112
+ if (items.length === 0) {
11113
+ const p = document.createElement("p");
11114
+ p.textContent = content;
11115
+ return p;
11116
+ }
11190
11117
  const isOrdered = /^\d+\.$/.test(items[0].marker);
11191
- const Tag = isOrdered ? "ol" : "ul";
11192
- return /* @__PURE__ */ jsx2(Tag, { className: `${isOrdered ? "list-decimal" : "list-disc"} pl-6 my-3 space-y-1 text-sm sm:text-base`, children: items.map((item, index) => /* @__PURE__ */ jsx2("li", { className: "leading-relaxed", children: renderInline(item.text) }, index)) });
11118
+ const list = document.createElement(isOrdered ? "ol" : "ul");
11119
+ list.className = "nr-list";
11120
+ for (const item of items) {
11121
+ const li = document.createElement("li");
11122
+ li.className = "nr-list__item";
11123
+ li.appendChild(renderInline2(item.text));
11124
+ list.appendChild(li);
11125
+ }
11126
+ return list;
11193
11127
  }
11194
- function extractHeaders(elements) {
11195
- return elements.filter((el) => el.type === "header");
11128
+ function createTOC(headers, renderInline2) {
11129
+ const nav = document.createElement("nav");
11130
+ nav.className = "nr-toc";
11131
+ const title = document.createElement("div");
11132
+ title.className = "nr-toc__title";
11133
+ title.textContent = "Table of Contents";
11134
+ nav.appendChild(title);
11135
+ const ul = document.createElement("ul");
11136
+ ul.className = "nr-toc__list";
11137
+ for (const h of headers) {
11138
+ const li = document.createElement("li");
11139
+ li.className = `nr-toc__item nr-toc__item--h${h.level}`;
11140
+ const a = document.createElement("a");
11141
+ a.className = "nr-toc__link";
11142
+ a.href = `#${h.id}`;
11143
+ a.appendChild(renderInline2(h.text.replace(/->|<-/g, "").trim()));
11144
+ a.addEventListener("click", (e) => {
11145
+ e.preventDefault();
11146
+ const target = document.getElementById(h.id);
11147
+ if (target) target.scrollIntoView({ behavior: "smooth", block: "start" });
11148
+ });
11149
+ li.appendChild(a);
11150
+ ul.appendChild(li);
11151
+ }
11152
+ nav.appendChild(ul);
11153
+ return nav;
11154
+ }
11155
+ function createBlockquote(content, classes, renderInline2) {
11156
+ const el = document.createElement("blockquote");
11157
+ el.className = `nr-blockquote${classes ? ` ${classes}` : ""}`;
11158
+ el.appendChild(renderInline2(content));
11159
+ return el;
11196
11160
  }
11197
11161
 
11198
- // react/directives/AdmonitionDirective.tsx
11199
- import { jsx as jsx3 } from "react/jsx-runtime";
11200
- var AdmonitionDirective = ({
11201
- directiveType,
11202
- props,
11203
- renderSlot
11204
- }) => {
11205
- return /* @__PURE__ */ jsx3(
11206
- Admonition,
11207
- {
11208
- type: directiveType,
11209
- title: props.title,
11210
- icon: props.icon,
11211
- className: props.class,
11212
- style: props.style ? parseCssString(props.style) : void 0,
11213
- children: renderSlot("default")
11162
+ // vanilla/inline.ts
11163
+ function renderInline(text) {
11164
+ const fragment = document.createDocumentFragment();
11165
+ if (!text) return fragment;
11166
+ const regex = /(\|\[[^\]]+\]\||\*\*\*.+?\*\*\*|\*\*.+?\*\*|_.+?_|~~.+?~~|`[^`]+?`|!~.+?~!|%[^%\s]+?%[\s\S]+?%%|!>.+?<!|==.+?==|\[[^\]]+?\]\([^)]+?\)|<[^>]+>)/g;
11167
+ let lastIndex = 0;
11168
+ let match;
11169
+ while ((match = regex.exec(text)) !== null) {
11170
+ if (match.index > lastIndex) {
11171
+ fragment.appendChild(document.createTextNode(text.slice(lastIndex, match.index)));
11214
11172
  }
11215
- );
11216
- };
11217
- var AdmonitionDirective_default = AdmonitionDirective;
11173
+ fragment.appendChild(parseInlinePart(match[0]));
11174
+ lastIndex = regex.lastIndex;
11175
+ }
11176
+ if (lastIndex < text.length) {
11177
+ fragment.appendChild(document.createTextNode(text.slice(lastIndex)));
11178
+ }
11179
+ return fragment;
11180
+ }
11181
+ function parseInlinePart(part) {
11182
+ let match;
11183
+ if (match = part.match(/^\|\[([^\]]+)\]\|$/)) {
11184
+ return createIcon(match[1]);
11185
+ }
11186
+ if (match = part.match(/^!~(.+?)~!$/)) {
11187
+ const content = match[1];
11188
+ const parts = content.split(";");
11189
+ let color = "currentColor";
11190
+ let decorationStyle = "solid";
11191
+ let type = "underline";
11192
+ let textIndex = 0;
11193
+ if (parts[textIndex]?.match(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/) || ["red", "blue", "green", "purple", "orange", "yellow", "pink"].includes(parts[textIndex])) {
11194
+ color = parts[textIndex++];
11195
+ }
11196
+ if (["solid", "double", "dotted", "dashed", "wavy"].includes(parts[textIndex])) {
11197
+ decorationStyle = parts[textIndex++];
11198
+ }
11199
+ if (["underline", "line-through", "overline", "both"].includes(parts[textIndex])) {
11200
+ type = parts[textIndex] === "both" ? "underline line-through" : parts[textIndex++];
11201
+ }
11202
+ const innerText = parts.slice(textIndex).join(";");
11203
+ const span = document.createElement("span");
11204
+ span.className = "nr-underline";
11205
+ span.style.textDecoration = `${type} ${decorationStyle} ${color}`;
11206
+ span.style.textDecorationThickness = "auto";
11207
+ span.appendChild(renderInline(innerText));
11208
+ return span;
11209
+ }
11210
+ if (match = part.match(/%([^%\s]+?)%([\s\S]+?)%%/)) {
11211
+ const span = document.createElement("span");
11212
+ span.style.color = match[1];
11213
+ span.appendChild(renderInline(match[2]));
11214
+ return span;
11215
+ }
11216
+ if (match = part.match(/^!>([^<]+?)<!$/)) {
11217
+ const span = document.createElement("span");
11218
+ span.className = "nr-spoiler";
11219
+ span.appendChild(renderInline(match[1]));
11220
+ return span;
11221
+ }
11222
+ if (match = part.match(/^==(.+?)==$/)) {
11223
+ const mark = document.createElement("mark");
11224
+ mark.className = "nr-highlight";
11225
+ mark.appendChild(renderInline(match[1]));
11226
+ return mark;
11227
+ }
11228
+ if (match = part.match(/^\*\*\*(.+?)\*\*\*$/)) {
11229
+ const strong = document.createElement("strong");
11230
+ const em = document.createElement("em");
11231
+ em.appendChild(renderInline(match[1]));
11232
+ strong.appendChild(em);
11233
+ return strong;
11234
+ }
11235
+ if (match = part.match(/^\*\*(.+?)\*\*$/)) {
11236
+ const strong = document.createElement("strong");
11237
+ strong.appendChild(renderInline(match[1]));
11238
+ return strong;
11239
+ }
11240
+ if (match = part.match(/^_(.+?)_$/)) {
11241
+ const em = document.createElement("em");
11242
+ em.appendChild(renderInline(match[1]));
11243
+ return em;
11244
+ }
11245
+ if (match = part.match(/^~~(.+?)~~$/)) {
11246
+ const del = document.createElement("del");
11247
+ del.appendChild(renderInline(match[1]));
11248
+ return del;
11249
+ }
11250
+ if (match = part.match(/^`([^`]+)`$/)) {
11251
+ const code = document.createElement("code");
11252
+ code.className = "nr-inline-code";
11253
+ code.textContent = match[1];
11254
+ return code;
11255
+ }
11256
+ if (match = part.match(/^\[([^\]]+?)\]\(([^)]+?)\)$/)) {
11257
+ const a = document.createElement("a");
11258
+ a.className = "nr-link";
11259
+ a.href = match[2];
11260
+ a.target = "_blank";
11261
+ a.rel = "noopener noreferrer";
11262
+ a.appendChild(renderInline(match[1]));
11263
+ return a;
11264
+ }
11265
+ if (part.startsWith("<") && part.endsWith(">")) {
11266
+ const span = document.createElement("span");
11267
+ span.innerHTML = part;
11268
+ return span;
11269
+ }
11270
+ return document.createTextNode(part);
11271
+ }
11218
11272
 
11219
- // react/directives/CardDirective.tsx
11220
- import React2, { useId } from "react";
11221
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
11222
- var CardDirective = ({
11223
- directiveType,
11224
- props,
11225
- slots,
11226
- renderSlot,
11227
- context,
11228
- options = {}
11229
- }) => {
11230
- const stableId = useId();
11231
- const { title, image, icon, class: customClass, url, target } = props;
11232
- const hasDescription = !!slots.description;
11233
- const { isSingleCard } = options;
11234
- const isModal = directiveType === "card-m";
11235
- const isLink = directiveType === "card-b";
11236
- const modalId = `modal-card-${props.id || stableId}`;
11237
- const wrapperClass = customClass || "";
11238
- const inlineStyles = props.style ? parseCssString(props.style) : {};
11239
- const description = hasDescription ? renderSlot("description") : null;
11240
- const content = renderSlot("content") || renderSlot("default");
11241
- return /* @__PURE__ */ jsxs3(React2.Fragment, { children: [
11242
- /* @__PURE__ */ jsxs3(
11243
- "div",
11244
- {
11245
- className: `flex flex-col h-full rounded-3xl transition-all relative overflow-hidden group border min-w-[18rem] w-[18rem] max-w-[20rem] ${isModal || isLink ? "cursor-pointer !border-accent-primary/10 hover:border-accent-primary/50" : "border-border"} ${wrapperClass}`,
11246
- style: inlineStyles,
11247
- onClick: isModal ? (e) => {
11248
- e.preventDefault();
11249
- e.stopPropagation();
11250
- context.setModals((prev) => ({ ...prev, [modalId]: true }));
11251
- } : isLink && url ? () => window.open(url, "_blank") : void 0,
11252
- role: isModal ? "button" : void 0,
11253
- tabIndex: isModal ? 0 : void 0,
11254
- onKeyDown: isModal ? (e) => {
11255
- if (e.key === "Enter" || e.key === " ") context.setModals((prev) => ({ ...prev, [modalId]: true }));
11256
- } : void 0,
11257
- children: [
11258
- image && /* @__PURE__ */ jsxs3("div", { className: `w-full ${isSingleCard ? "h-[240px]" : "h-[160px]"} overflow-hidden relative transition-all duration-500`, children: [
11259
- /* @__PURE__ */ jsx4("img", { src: image, alt: title || "", className: "w-full h-full object-cover !m-0" }),
11260
- /* @__PURE__ */ jsx4("div", { className: "absolute inset-0 bg-gradient-to-t from-background-primary/40 to-transparent" })
11261
- ] }),
11262
- /* @__PURE__ */ jsxs3("div", { className: `flex flex-col flex-1 bg-background-primary/80 rounded-t-xl p-6 relative ${image ? "-mt-10" : ""} border-t border-white/5 shadow-2xl`, children: [
11263
- /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-3 mb-3", children: [
11264
- icon && /* @__PURE__ */ jsx4("div", { className: "w-10 h-10 text-[1.6em] rounded-xl bg-accent-primary/20 flex items-center justify-center shrink-0 text-accent-primary", children: /* @__PURE__ */ jsx4(IconRenderer, { iconName: icon }) }),
11265
- /* @__PURE__ */ jsx4("h3", { className: "text-base font-black tracking-tight leading-tight !m-0", children: title })
11266
- ] }),
11267
- /* @__PURE__ */ jsxs3("div", { className: "flex-1 flex flex-col gap-2", children: [
11268
- description && /* @__PURE__ */ jsx4("div", { className: "text-sm opacity-80 leading-relaxed font-medium", children: description }),
11269
- directiveType === "card" && content && /* @__PURE__ */ jsx4("div", { className: "mt-2", children: content })
11270
- ] }),
11271
- (isModal || isLink) && /* @__PURE__ */ jsx4("div", { className: "mt-6 flex justify-end", children: isLink && url ? /* @__PURE__ */ jsxs3(
11272
- "a",
11273
- {
11274
- href: url,
11275
- target: "_blank",
11276
- rel: "noopener noreferrer",
11277
- className: "bg-accent-primary/20 hover:bg-accent-primary/30 px-4 py-2 rounded-xl flex items-center gap-1.5 text-[10px] font-black uppercase tracking-widest opacity-50 group-hover:opacity-100 group-hover:text-accent-primary transition-all no-underline",
11278
- onClick: (e) => e.stopPropagation(),
11279
- children: [
11280
- /* @__PURE__ */ jsx4(IconRenderer, { iconName: "open_in_new" }),
11281
- " Link"
11282
- ]
11283
- }
11284
- ) : isModal ? /* @__PURE__ */ jsxs3("div", { className: "bg-accent-primary/20 hover:bg-accent-primary/30 px-4 py-2 cursor-pointer rounded-xl flex items-center gap-1.5 text-[10px] font-black uppercase tracking-widest opacity-50 group-hover:opacity-100 group-hover:text-accent-primary transition-all", children: [
11285
- /* @__PURE__ */ jsx4(IconRenderer, { iconName: "arrow_forward" }),
11286
- " Abrir"
11287
- ] }) : null })
11288
- ] })
11289
- ]
11290
- }
11291
- ),
11292
- isModal && /* @__PURE__ */ jsx4(
11293
- Modal,
11294
- {
11295
- title: title || "Detalles",
11296
- isOpen: !!context.modals[modalId],
11297
- onClose: () => context.setModals((prev) => ({ ...prev, [modalId]: false })),
11298
- children: /* @__PURE__ */ jsx4("div", { className: "prose prose-sm max-w-none", children: content })
11299
- }
11300
- )
11301
- ] });
11273
+ // vanilla/directives/admonition.ts
11274
+ var admonitionDirective = ({ directiveType, props, renderSlot }) => {
11275
+ const el = createAdmonition(directiveType, props.title, props.icon);
11276
+ if (props.class) el.classList.add(...props.class.split(/\s+/).filter(Boolean));
11277
+ if (props.style) el.setAttribute("style", props.style);
11278
+ const body = el.querySelector(".nr-admonition__body");
11279
+ if (body) {
11280
+ body.appendChild(renderSlot("default"));
11281
+ }
11282
+ return el;
11302
11283
  };
11303
- var CardDirective_default = CardDirective;
11284
+ var admonition_default = admonitionDirective;
11304
11285
 
11305
- // react/directives/DetailsDirective.tsx
11306
- import { jsx as jsx5 } from "react/jsx-runtime";
11307
- var DetailsDirective = ({
11308
- props,
11309
- renderSlot
11310
- }) => {
11311
- return /* @__PURE__ */ jsx5(
11312
- Details,
11313
- {
11314
- title: props.title || "Details",
11315
- icon: props.icon,
11316
- defaultOpen: props.defaultOpen === "true",
11317
- className: props.class,
11318
- style: props.style ? parseCssString(props.style) : void 0,
11319
- children: renderSlot("default")
11320
- }
11286
+ // vanilla/directives/details.ts
11287
+ var detailsDirective = ({ props, renderSlot }) => {
11288
+ const el = createDetails(
11289
+ props.title || "Details",
11290
+ props.icon,
11291
+ props.defaultOpen === "true"
11321
11292
  );
11293
+ if (props.class) el.classList.add(...props.class.split(/\s+/).filter(Boolean));
11294
+ if (props.style) el.setAttribute("style", props.style);
11295
+ const body = el.querySelector(".nr-details__body");
11296
+ if (body) {
11297
+ body.appendChild(renderSlot("default"));
11298
+ }
11299
+ return el;
11322
11300
  };
11323
- var DetailsDirective_default = DetailsDirective;
11301
+ var details_default = detailsDirective;
11324
11302
 
11325
- // react/directives/ModalDirective.tsx
11326
- import { useId as useId2 } from "react";
11327
- import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
11328
- var ModalDirective = ({
11329
- props,
11330
- renderSlot,
11331
- context
11332
- }) => {
11333
- const stableId = useId2();
11334
- const modalId = `modal-${props.id || stableId}`;
11303
+ // vanilla/directives/modal.ts
11304
+ var modalDirective = ({ props, renderSlot }) => {
11335
11305
  const label = props.label || props.title || "Open";
11336
11306
  const modalTitle = props.title || "Modal";
11337
11307
  const customClass = props.class || "";
11338
- const hasSizeClass = /\btext-(xs|sm|base|lg|xl|[2-9]xl)\b/.test(customClass);
11339
- const sizeClass = hasSizeClass ? "" : "text-sm";
11340
- const hasDisplayClass = /\b(flex|inline-flex|block|inline-block|grid|inline-grid|hidden)\b/.test(customClass);
11341
- const displayClass = hasDisplayClass ? "" : "inline-flex";
11342
- const isInlineFlex = /\binline-flex\b/.test(customClass);
11343
- const marginClass = isInlineFlex ? "my-1 mx-1" : "my-4";
11344
- const btnBase = `${displayClass} items-center w-fit ${marginClass} ${sizeClass} px-4 py-2 rounded-xl font-bold no-underline gap-2 transition-all hover:scale-105 active:scale-95 border border-border bg-background-primary/5 hover:bg-background-primary/10 text-text-primary hover:text-text-primary`.replace(/\s+/g, " ");
11345
- const btnClass = `${btnBase} ${customClass}`.trim();
11346
- const positionMap = {
11347
- "#left": "text-left",
11348
- "#center": "text-center",
11349
- "#right": "text-right"
11350
- };
11351
- const wrapperClass = customClass.split(/\s+/).map((c) => positionMap[c] || c).join(" ");
11352
- const handleOpen = () => {
11353
- context.setModals((prev) => ({ ...prev, [modalId]: true }));
11354
- };
11355
- const handleClose = () => {
11356
- context.setModals((prev) => ({ ...prev, [modalId]: false }));
11357
- };
11358
- return /* @__PURE__ */ jsxs4("div", { className: `not-prose ${wrapperClass}`.trim(), children: [
11359
- /* @__PURE__ */ jsxs4("button", { className: btnClass, onClick: handleOpen, children: [
11360
- props.icon && /* @__PURE__ */ jsx6(IconRenderer, { iconName: props.icon }),
11361
- label
11362
- ] }),
11363
- /* @__PURE__ */ jsx6(
11364
- Modal,
11365
- {
11366
- title: modalTitle,
11367
- isOpen: !!context.modals[modalId],
11368
- onClose: handleClose,
11369
- children: renderSlot("default")
11370
- }
11371
- )
11372
- ] });
11308
+ const wrapper = document.createElement("div");
11309
+ wrapper.className = "nr-modal-trigger";
11310
+ const btn = document.createElement("button");
11311
+ btn.className = `nr-button nr-button--default`;
11312
+ if (customClass) btn.classList.add(...customClass.split(/\s+/).filter(Boolean));
11313
+ const icon = props.icon || "open_in_new";
11314
+ if (icon) btn.appendChild(createIcon(icon));
11315
+ btn.appendChild(document.createTextNode(label));
11316
+ const dialog = createModal(modalTitle);
11317
+ const body = dialog.querySelector(".nr-modal__body");
11318
+ if (body) {
11319
+ body.appendChild(renderSlot("default"));
11320
+ }
11321
+ btn.addEventListener("click", () => {
11322
+ if (!dialog.open) {
11323
+ document.body.appendChild(dialog);
11324
+ dialog.showModal();
11325
+ dialog.addEventListener("close", () => {
11326
+ dialog.remove();
11327
+ }, { once: true });
11328
+ }
11329
+ });
11330
+ wrapper.appendChild(btn);
11331
+ wrapper.appendChild(dialog);
11332
+ return wrapper;
11373
11333
  };
11374
- var ModalDirective_default = ModalDirective;
11334
+ var modal_default = modalDirective;
11375
11335
 
11376
- // react/directives/ButtonDirective.tsx
11377
- import React4 from "react";
11378
- import { Fragment, jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
11379
- var ButtonDirective = ({
11380
- props,
11381
- renderSlot
11382
- }) => {
11336
+ // vanilla/directives/button.ts
11337
+ var buttonDirective = ({ props, renderSlot }) => {
11383
11338
  const url = props.url || props.href || "#";
11384
11339
  const label = props.label;
11385
11340
  const icon = props.icon || "near_me";
11386
11341
  const target = props.target || "_blank";
11387
11342
  const customClass = props.class || "";
11388
- const hasSizeClass = /\btext-(xs|sm|base|lg|xl|[2-9]xl)\b/.test(customClass);
11389
- const sizeClass = hasSizeClass ? "" : "text-sm";
11390
- const hasDisplayClass = /\b(flex|inline-flex|block|inline-block|grid|inline-grid|hidden)\b/.test(customClass);
11391
- const displayClass = hasDisplayClass ? "" : "inline-flex";
11392
- const isInline = !customClass || !/\b(flex|block|grid)\b/.test(customClass) || /\binline-flex\b/.test(customClass);
11393
- const marginClass = isInline ? "my-1 mx-1" : "my-4";
11394
- const btnBase = `${displayClass} items-center w-fit ${marginClass} ${sizeClass} px-4 py-2 rounded-xl font-bold no-underline gap-2 transition-all hover:scale-105 active:scale-95 border border-border bg-background-primary/5 hover:bg-background-primary/10 text-text-primary hover:text-text-primary`.replace(/\s+/g, " ");
11395
- const btnClass = `${btnBase} ${customClass}`.trim();
11396
- const positionMap = {
11397
- "#left": "flex justify-start",
11398
- "#center": "flex justify-center",
11399
- "#right": "flex justify-end"
11400
- };
11401
- const wrapperClass = customClass.split(/\s+/).map((c) => positionMap[c] || c).join(" ");
11343
+ const wrapper = document.createElement("div");
11344
+ wrapper.className = "nr-button-wrap";
11402
11345
  if (label) {
11403
- return /* @__PURE__ */ jsx7("div", { className: `not-prose ${wrapperClass}`.trim(), children: /* @__PURE__ */ jsxs5(
11404
- "a",
11405
- {
11406
- href: url,
11407
- target,
11408
- rel: "noopener noreferrer",
11409
- className: btnClass,
11410
- children: [
11411
- /* @__PURE__ */ jsx7(IconRenderer, { iconName: icon }),
11412
- label
11413
- ]
11414
- }
11415
- ) });
11346
+ const a = document.createElement("a");
11347
+ a.href = url;
11348
+ a.target = target;
11349
+ a.rel = "noopener noreferrer";
11350
+ a.className = "nr-button nr-button--default";
11351
+ if (customClass) a.classList.add(...customClass.split(/\s+/).filter(Boolean));
11352
+ a.appendChild(createIcon(icon));
11353
+ a.appendChild(document.createTextNode(label));
11354
+ wrapper.appendChild(a);
11355
+ return wrapper;
11416
11356
  }
11417
11357
  const slotContent = renderSlot("default");
11418
- const findLinks = (element) => {
11419
- if (!element) return [];
11420
- if (React4.isValidElement(element) && element.type === "a") {
11421
- return [element];
11422
- }
11423
- if (Array.isArray(element)) {
11424
- return element.flatMap(findLinks);
11425
- }
11426
- if (React4.isValidElement(element) && element.props.children) {
11427
- return findLinks(element.props.children);
11428
- }
11429
- return [];
11430
- };
11431
- const links = findLinks(slotContent);
11358
+ const links = slotContent.querySelectorAll("a");
11432
11359
  if (links.length > 0) {
11433
- return /* @__PURE__ */ jsx7("div", { className: `not-prose ${wrapperClass}`.trim(), children: links.map(
11434
- (link, index) => React4.cloneElement(
11435
- link,
11436
- {
11437
- key: index,
11438
- className: `${link.props.className || ""} ${btnClass}`.trim(),
11439
- target,
11440
- rel: "noopener noreferrer"
11441
- },
11442
- /* @__PURE__ */ jsxs5(Fragment, { children: [
11443
- /* @__PURE__ */ jsx7(IconRenderer, { iconName: icon }),
11444
- link.props.children
11445
- ] })
11446
- )
11447
- ) });
11360
+ links.forEach((link) => {
11361
+ link.classList.add("nr-button", "nr-button--default");
11362
+ if (customClass) link.classList.add(...customClass.split(/\s+/).filter(Boolean));
11363
+ });
11364
+ wrapper.appendChild(slotContent);
11365
+ } else {
11366
+ const a = document.createElement("a");
11367
+ a.href = url;
11368
+ a.target = target;
11369
+ a.rel = "noopener noreferrer";
11370
+ a.className = "nr-button nr-button--default";
11371
+ if (customClass) a.classList.add(...customClass.split(/\s+/).filter(Boolean));
11372
+ a.appendChild(createIcon(icon));
11373
+ a.appendChild(slotContent);
11374
+ wrapper.appendChild(a);
11448
11375
  }
11449
- return /* @__PURE__ */ jsx7("div", { className: `not-prose ${wrapperClass}`.trim(), children: /* @__PURE__ */ jsxs5("a", { href: url, target, rel: "noopener noreferrer", className: btnClass, children: [
11450
- /* @__PURE__ */ jsx7(IconRenderer, { iconName: icon }),
11451
- slotContent
11452
- ] }) });
11376
+ return wrapper;
11453
11377
  };
11454
- var ButtonDirective_default = ButtonDirective;
11378
+ var button_default = buttonDirective;
11455
11379
 
11456
- // react/directives/WrapperDirective.tsx
11457
- import { jsx as jsx8 } from "react/jsx-runtime";
11458
- var WrapperDirective = ({
11380
+ // vanilla/directives/card.ts
11381
+ var cardDirective = ({
11382
+ directiveType,
11459
11383
  props,
11460
- renderSlot
11384
+ slots,
11385
+ renderSlot,
11386
+ options
11461
11387
  }) => {
11462
- const className = props.class || "";
11463
- const id = props.id || "";
11464
- const inlineStyle = props.style ? parseCssString(props.style) : {};
11465
- const wrapperProps = {};
11466
- if (className) wrapperProps.className = className;
11467
- if (id) wrapperProps.id = id;
11468
- if (Object.keys(inlineStyle).length > 0) wrapperProps.style = inlineStyle;
11388
+ const { title, image, icon, url, target } = props;
11389
+ const customClass = props.class || "";
11390
+ const hasDescription = !!slots.description;
11391
+ const { isSingleCard } = options || {};
11392
+ const isModal = directiveType === "card-m";
11393
+ const isLink = directiveType === "card-b";
11394
+ const inlineStyles = props.style ? parseCssString(props.style) : {};
11395
+ const card = document.createElement("div");
11396
+ card.className = `nr-card${isModal || isLink ? " nr-card--interactive" : ""} ${customClass}`.trim();
11397
+ for (const [key, value] of Object.entries(inlineStyles)) {
11398
+ card.style.setProperty(key, String(value));
11399
+ }
11400
+ if (image) {
11401
+ const imgWrap = document.createElement("div");
11402
+ imgWrap.className = `nr-card__image${isSingleCard ? " nr-card__image--tall" : ""}`;
11403
+ const img = document.createElement("img");
11404
+ img.src = image;
11405
+ img.alt = title || "";
11406
+ img.className = "nr-card__img";
11407
+ imgWrap.appendChild(img);
11408
+ const gradient = document.createElement("div");
11409
+ gradient.className = "nr-card__gradient";
11410
+ imgWrap.appendChild(gradient);
11411
+ card.appendChild(imgWrap);
11412
+ }
11413
+ const body = document.createElement("div");
11414
+ body.className = `nr-card__body${image ? " nr-card__body--overlap" : ""}`;
11415
+ if (icon || title) {
11416
+ const header = document.createElement("div");
11417
+ header.className = "nr-card__header";
11418
+ if (icon) {
11419
+ const iconWrap = document.createElement("div");
11420
+ iconWrap.className = "nr-card__icon-wrap";
11421
+ iconWrap.appendChild(createIcon(icon));
11422
+ header.appendChild(iconWrap);
11423
+ }
11424
+ if (title) {
11425
+ const h3 = document.createElement("h3");
11426
+ h3.className = "nr-card__title";
11427
+ h3.textContent = title;
11428
+ header.appendChild(h3);
11429
+ }
11430
+ body.appendChild(header);
11431
+ }
11432
+ if (hasDescription) {
11433
+ const desc = document.createElement("div");
11434
+ desc.className = "nr-card__description";
11435
+ desc.appendChild(renderSlot("description"));
11436
+ body.appendChild(desc);
11437
+ }
11438
+ if (directiveType === "card") {
11439
+ const contentSlot = renderSlot("content") || renderSlot("default");
11440
+ if (contentSlot.childNodes.length > 0) {
11441
+ const contentDiv = document.createElement("div");
11442
+ contentDiv.className = "nr-card__content";
11443
+ contentDiv.appendChild(contentSlot);
11444
+ body.appendChild(contentDiv);
11445
+ }
11446
+ }
11447
+ if (isModal || isLink) {
11448
+ const action = document.createElement("div");
11449
+ action.className = "nr-card__action";
11450
+ if (isLink && url) {
11451
+ const a = document.createElement("a");
11452
+ a.href = url;
11453
+ a.target = target || "_blank";
11454
+ a.rel = "noopener noreferrer";
11455
+ a.className = "nr-card__action-link";
11456
+ a.appendChild(createIcon("open_in_new"));
11457
+ a.appendChild(document.createTextNode(" Link"));
11458
+ action.appendChild(a);
11459
+ } else if (isModal) {
11460
+ const modalBtn = document.createElement("div");
11461
+ modalBtn.className = "nr-card__action-link";
11462
+ modalBtn.appendChild(createIcon("arrow_forward"));
11463
+ modalBtn.appendChild(document.createTextNode(" Abrir"));
11464
+ action.appendChild(modalBtn);
11465
+ }
11466
+ body.appendChild(action);
11467
+ }
11468
+ card.appendChild(body);
11469
+ if (isModal) {
11470
+ const dialog = createModal(title || "Detalles");
11471
+ const modalBody = dialog.querySelector(".nr-modal__body");
11472
+ if (modalBody) {
11473
+ const contentSlot = renderSlot("content") || renderSlot("default");
11474
+ modalBody.appendChild(contentSlot);
11475
+ }
11476
+ card.addEventListener("click", () => {
11477
+ if (!dialog.open) {
11478
+ document.body.appendChild(dialog);
11479
+ dialog.showModal();
11480
+ dialog.addEventListener("close", () => dialog.remove(), { once: true });
11481
+ }
11482
+ });
11483
+ const frag = document.createDocumentFragment();
11484
+ frag.appendChild(card);
11485
+ frag.appendChild(dialog);
11486
+ return frag;
11487
+ }
11488
+ if (isLink && url) {
11489
+ card.addEventListener("click", () => window.open(url, target || "_blank"));
11490
+ }
11491
+ return card;
11492
+ };
11493
+ var card_default = cardDirective;
11494
+
11495
+ // vanilla/directives/wrapper.ts
11496
+ var wrapperDirective = ({ props, renderSlot }) => {
11497
+ const el = document.createElement("div");
11498
+ el.className = "nr-wrapper";
11499
+ if (props.class) el.classList.add(...props.class.split(/\s+/).filter(Boolean));
11500
+ if (props.id) el.id = props.id;
11501
+ if (props.style) {
11502
+ const styles = parseCssString(props.style);
11503
+ for (const [key, value] of Object.entries(styles)) {
11504
+ el.style.setProperty(key, String(value));
11505
+ }
11506
+ }
11469
11507
  for (const [key, value] of Object.entries(props)) {
11470
11508
  if (key.startsWith("data-")) {
11471
- wrapperProps[key] = value;
11509
+ el.setAttribute(key, value);
11472
11510
  }
11473
11511
  }
11474
- return /* @__PURE__ */ jsx8("div", { ...wrapperProps, children: renderSlot("default") });
11512
+ el.appendChild(renderSlot("default"));
11513
+ return el;
11475
11514
  };
11476
- var WrapperDirective_default = WrapperDirective;
11515
+ var wrapper_default = wrapperDirective;
11477
11516
 
11478
- // react/directives/SlideDirective.tsx
11479
- import { useState as useState2, useEffect, useCallback, useRef as useRef2, useLayoutEffect } from "react";
11480
- import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
11517
+ // vanilla/directives/slide.ts
11481
11518
  var slideCounter = 0;
11482
- var SlideDirective = ({
11519
+ var slideDirective = ({
11483
11520
  props,
11484
- context,
11485
- slots
11521
+ slots,
11522
+ renderInline: renderInline2,
11523
+ renderMarkdown
11486
11524
  }) => {
11487
11525
  const rawContent = slots.default || "";
11488
11526
  const lines = rawContent.split("\n").map((l) => l.trim()).filter(Boolean);
11489
- const elements = lines.map((line) => context.parseMarkdown(line));
11490
- const [current, setCurrent] = useState2(0);
11527
+ if (lines.length === 0) {
11528
+ return document.createDocumentFragment();
11529
+ }
11491
11530
  const interval = parseInt(props.interval || "3000", 10);
11492
11531
  const speed = parseInt(props.speed || "500", 10);
11493
- const elRefs = useRef2([]);
11494
- const [maxH, setMaxH] = useState2(0);
11495
- useLayoutEffect(() => {
11496
- let h = 0;
11497
- elRefs.current.forEach((el) => {
11498
- if (el) h = Math.max(h, el.offsetHeight);
11499
- });
11500
- if (h > 0) setMaxH(h);
11501
- }, [elements]);
11502
- const cycle = useCallback(() => {
11503
- if (elements.length <= 1) return;
11504
- setCurrent((prev) => (prev + 1) % elements.length);
11505
- }, [elements.length]);
11506
- useEffect(() => {
11507
- if (elements.length <= 1) return;
11508
- const id = setInterval(cycle, interval);
11509
- return () => clearInterval(id);
11510
- }, [cycle, interval, elements.length]);
11511
- if (elements.length === 0) return null;
11512
11532
  const rawClass = props.class || "";
11513
11533
  const inlineStyle = props.style ? parseCssString(props.style) : {};
11514
- const textSizeMap = {
11515
- "text-xs": "0.75rem",
11516
- "text-sm": "0.875rem",
11517
- "text-base": "1rem",
11518
- "text-lg": "1.125rem",
11519
- "text-xl": "1.25rem",
11520
- "text-2xl": "1.5rem",
11521
- "text-3xl": "1.875rem",
11522
- "text-4xl": "2.25rem",
11523
- "text-5xl": "3rem",
11524
- "text-6xl": "3.75rem",
11525
- "text-7xl": "4.5rem",
11526
- "text-8xl": "6rem",
11527
- "text-9xl": "8rem"
11528
- };
11529
- const textSizeMatch = rawClass.match(/\btext-(xs|sm|base|lg|xl|[2-9]xl)\b/);
11530
- const forcedFontSize = textSizeMatch ? textSizeMap[textSizeMatch[0]] : null;
11531
11534
  const scopeClass = `sld-${++slideCounter}`;
11532
- const className = textSizeMatch ? rawClass.replace(textSizeMatch[0], "").replace(/\s+/g, " ").trim() : rawClass;
11533
- return /* @__PURE__ */ jsxs6(
11534
- "div",
11535
- {
11536
- className: "not-prose",
11537
- style: { height: maxH || "auto", position: "relative", overflow: "hidden", ...inlineStyle },
11538
- children: [
11539
- forcedFontSize && /* @__PURE__ */ jsx9("style", { children: `.${scopeClass} * { font-size: ${forcedFontSize} !important; line-height: normal !important; }` }),
11540
- /* @__PURE__ */ jsx9(
11541
- "div",
11542
- {
11543
- style: {
11544
- position: "absolute",
11545
- left: 0,
11546
- right: 0,
11547
- top: 0,
11548
- transition: `transform ${speed}ms cubic-bezier(0.16, 1, 0.3, 1)`,
11549
- transform: `translateY(${-current * maxH}px)`
11550
- },
11551
- children: elements.map((tokens, i) => /* @__PURE__ */ jsx9(
11552
- "div",
11553
- {
11554
- ref: (el) => {
11555
- elRefs.current[i] = el;
11556
- },
11557
- style: maxH ? { height: maxH, display: "flex", alignItems: "center", overflow: "hidden" } : { display: "flex", alignItems: "center" },
11558
- children: /* @__PURE__ */ jsx9("div", { className: `${scopeClass} ${className}`, style: { width: "100%" }, children: context.processAndRenderElements(tokens) })
11559
- },
11560
- i
11561
- ))
11562
- }
11563
- )
11564
- ]
11535
+ const container = document.createElement("div");
11536
+ container.className = "nr-slide";
11537
+ Object.assign(container.style, {
11538
+ position: "relative",
11539
+ overflow: "hidden",
11540
+ ...inlineStyle
11541
+ });
11542
+ const track = document.createElement("div");
11543
+ track.className = "nr-slide__track";
11544
+ track.style.transition = `transform ${speed}ms cubic-bezier(0.16, 1, 0.3, 1)`;
11545
+ const slideEls = [];
11546
+ for (const line of lines) {
11547
+ const slideEl = document.createElement("div");
11548
+ slideEl.className = `nr-slide__item ${scopeClass} ${rawClass}`.trim();
11549
+ slideEl.style.display = "flex";
11550
+ slideEl.style.alignItems = "center";
11551
+ if (renderMarkdown) {
11552
+ const tokens = renderMarkdown(line);
11553
+ slideEl.appendChild(tokens);
11554
+ } else if (renderInline2) {
11555
+ slideEl.appendChild(renderInline2(line));
11565
11556
  }
11566
- );
11557
+ track.appendChild(slideEl);
11558
+ slideEls.push(slideEl);
11559
+ }
11560
+ container.appendChild(track);
11561
+ let current = 0;
11562
+ let maxH = 0;
11563
+ const measureAndSetHeight = () => {
11564
+ maxH = 0;
11565
+ for (const el of slideEls) {
11566
+ maxH = Math.max(maxH, el.offsetHeight);
11567
+ }
11568
+ if (maxH > 0) {
11569
+ container.style.height = `${maxH}px`;
11570
+ for (const el of slideEls) {
11571
+ el.style.height = `${maxH}px`;
11572
+ }
11573
+ }
11574
+ };
11575
+ requestAnimationFrame(() => {
11576
+ measureAndSetHeight();
11577
+ if (document.fonts?.ready) {
11578
+ document.fonts.ready.then(measureAndSetHeight);
11579
+ }
11580
+ });
11581
+ if (lines.length > 1) {
11582
+ setInterval(() => {
11583
+ current = (current + 1) % lines.length;
11584
+ track.style.transform = `translateY(${-current * maxH}px)`;
11585
+ }, interval);
11586
+ }
11587
+ return container;
11567
11588
  };
11568
- var SlideDirective_default = SlideDirective;
11589
+ var slide_default = slideDirective;
11569
11590
 
11570
- // react/directives/index.ts
11591
+ // vanilla/directives/index.ts
11571
11592
  var directiveRegistry = {
11572
11593
  // Admonitions
11573
- note: AdmonitionDirective_default,
11574
- info: AdmonitionDirective_default,
11575
- warning: AdmonitionDirective_default,
11576
- danger: AdmonitionDirective_default,
11577
- greentext: AdmonitionDirective_default,
11594
+ note: admonition_default,
11595
+ info: admonition_default,
11596
+ warning: admonition_default,
11597
+ danger: admonition_default,
11598
+ greentext: admonition_default,
11578
11599
  // Cards
11579
- card: CardDirective_default,
11580
- "card-m": CardDirective_default,
11581
- "card-b": CardDirective_default,
11600
+ card: card_default,
11601
+ "card-m": card_default,
11602
+ "card-b": card_default,
11582
11603
  // Interactive
11583
- details: DetailsDirective_default,
11584
- modal: ModalDirective_default,
11585
- button: ButtonDirective_default,
11604
+ details: details_default,
11605
+ modal: modal_default,
11606
+ button: button_default,
11586
11607
  // Layout / generic wrappers
11587
- div: WrapperDirective_default,
11588
- style: WrapperDirective_default,
11589
- custom: WrapperDirective_default,
11590
- raw: WrapperDirective_default,
11608
+ div: wrapper_default,
11609
+ style: wrapper_default,
11610
+ custom: wrapper_default,
11611
+ raw: wrapper_default,
11591
11612
  // Animation
11592
- slide: SlideDirective_default
11613
+ slide: slide_default
11593
11614
  };
11594
11615
  var directives_default = directiveRegistry;
11595
11616
 
11596
- // react/DirectiveRenderer.tsx
11597
- import { jsx as jsx10 } from "react/jsx-runtime";
11598
- var DirectiveRenderer = ({
11599
- element,
11600
- context,
11601
- index,
11602
- allElements
11603
- }) => {
11617
+ // vanilla/renderer.ts
11618
+ function renderTokens(tokens) {
11619
+ const article = document.createElement("article");
11620
+ article.className = "nr-prose";
11621
+ const ctx = {
11622
+ parseMarkdown,
11623
+ renderElements: (tks) => renderTokensInner(tks, ctx),
11624
+ renderInline,
11625
+ renderMarkdown: (md) => renderTokensInner(parseMarkdown(md), ctx)
11626
+ };
11627
+ article.appendChild(processElements(tokens, ctx, tokens));
11628
+ return article;
11629
+ }
11630
+ function renderMarkdownString(markdown2) {
11631
+ const tokens = parseMarkdown(markdown2);
11632
+ return renderTokens(tokens);
11633
+ }
11634
+ function renderHtmlString(html) {
11635
+ let processedContent = html;
11636
+ processedContent = processedContent.replace(
11637
+ /<style(?:\s+[^>]*)?>([\s\S]*?)<\/style>/gi,
11638
+ (_match, cssContent) => {
11639
+ const styleEl = document.createElement("style");
11640
+ styleEl.setAttribute("data-nr-global", "");
11641
+ styleEl.textContent = cssContent;
11642
+ document.head.appendChild(styleEl);
11643
+ return "";
11644
+ }
11645
+ );
11646
+ const wrapper = document.createElement("div");
11647
+ wrapper.className = "nr-raw-html";
11648
+ wrapper.innerHTML = processedContent;
11649
+ const scripts = wrapper.querySelectorAll("script");
11650
+ scripts.forEach((oldScript) => {
11651
+ const newScript = document.createElement("script");
11652
+ Array.from(oldScript.attributes).forEach(
11653
+ (attr) => newScript.setAttribute(attr.name, attr.value)
11654
+ );
11655
+ newScript.textContent = oldScript.textContent;
11656
+ oldScript.parentNode?.replaceChild(newScript, oldScript);
11657
+ });
11658
+ return wrapper;
11659
+ }
11660
+ function renderTokensInner(tokens, ctx) {
11661
+ const container = document.createElement("div");
11662
+ container.appendChild(processElements(tokens, ctx, tokens));
11663
+ return container;
11664
+ }
11665
+ function processElements(elements, ctx, allElements) {
11666
+ const fragment = document.createDocumentFragment();
11667
+ let i = 0;
11668
+ while (i < elements.length) {
11669
+ const el = elements[i];
11670
+ if (el.type === "directive" && ["card", "card-m", "card-b"].includes(el.directiveType)) {
11671
+ const cards = [];
11672
+ while (i < elements.length && elements[i].type === "directive" && ["card", "card-m", "card-b"].includes(elements[i].directiveType)) {
11673
+ cards.push(elements[i]);
11674
+ i++;
11675
+ }
11676
+ if (cards.length === 1 || cards[0].props?.batch === "off") {
11677
+ for (const card of cards) {
11678
+ const rendered = renderElement(card, ctx, allElements);
11679
+ if (rendered) fragment.appendChild(rendered);
11680
+ }
11681
+ } else {
11682
+ const grid = document.createElement("div");
11683
+ grid.className = "nr-card-grid";
11684
+ for (const card of cards) {
11685
+ const rendered = renderElement(card, ctx, allElements);
11686
+ if (rendered) grid.appendChild(rendered);
11687
+ }
11688
+ fragment.appendChild(grid);
11689
+ }
11690
+ } else {
11691
+ const rendered = renderElement(el, ctx, allElements);
11692
+ if (rendered) fragment.appendChild(rendered);
11693
+ i++;
11694
+ }
11695
+ }
11696
+ return fragment;
11697
+ }
11698
+ function renderElement(element, ctx, allElements) {
11699
+ switch (element.type) {
11700
+ case "header": {
11701
+ const tag = `h${element.level}`;
11702
+ let text = element.text;
11703
+ const alignCenter = text.match(/^->\s*(.+?)\s*<-\s*$/);
11704
+ const alignRight = text.match(/^->\s*(.+?)\s*->\s*$/);
11705
+ if (alignCenter) text = alignCenter[1];
11706
+ else if (alignRight) text = alignRight[1];
11707
+ const h = document.createElement(tag);
11708
+ h.id = element.id;
11709
+ let cls = `md-h${element.level}`;
11710
+ if (alignCenter) cls += " text-center";
11711
+ if (alignRight) cls += " text-right";
11712
+ if (element.classes) cls += ` ${element.classes}`;
11713
+ h.className = cls;
11714
+ h.appendChild(renderInline(text));
11715
+ return h;
11716
+ }
11717
+ case "paragraph": {
11718
+ const p = document.createElement("p");
11719
+ let cls = "md-p";
11720
+ if (element.classes) cls += ` ${element.classes}`;
11721
+ if (element.align) cls += ` text-${element.align}`;
11722
+ p.className = cls;
11723
+ if (element.id) p.id = element.id;
11724
+ const lines = element.content.split("\n");
11725
+ for (let li = 0; li < lines.length; li++) {
11726
+ const line = lines[li];
11727
+ const hardBreakMatch = line.match(/^(.*?)(\s{2,})$/);
11728
+ if (hardBreakMatch) {
11729
+ p.appendChild(renderInline(hardBreakMatch[1]));
11730
+ p.appendChild(document.createElement("br"));
11731
+ } else {
11732
+ p.appendChild(renderInline(line));
11733
+ if (li < lines.length - 1) {
11734
+ p.appendChild(document.createTextNode(" "));
11735
+ }
11736
+ }
11737
+ }
11738
+ return p;
11739
+ }
11740
+ case "codeblock":
11741
+ return createCodeBlock(element.content, element.language, element.title);
11742
+ case "directive":
11743
+ return renderDirective(element, ctx, allElements);
11744
+ case "html": {
11745
+ const el = element;
11746
+ return renderHtmlString(el.content);
11747
+ }
11748
+ case "html-block": {
11749
+ const htmlBlock = element;
11750
+ const rawProps = parseHtmlAttrs(htmlBlock.attrs);
11751
+ const el = document.createElement(htmlBlock.tag);
11752
+ for (const [key, value] of Object.entries(rawProps)) {
11753
+ if (key === "style" && typeof value === "object") {
11754
+ for (const [prop, val] of Object.entries(value)) {
11755
+ el.style.setProperty(prop, String(val));
11756
+ }
11757
+ } else if (value === true) {
11758
+ el.setAttribute(key, "");
11759
+ } else {
11760
+ el.setAttribute(key, String(value));
11761
+ }
11762
+ }
11763
+ const childFrag = processElements(htmlBlock.children, ctx, allElements);
11764
+ el.appendChild(childFrag);
11765
+ return el;
11766
+ }
11767
+ case "image": {
11768
+ const img = document.createElement("img");
11769
+ img.src = element.src;
11770
+ img.alt = element.alt;
11771
+ img.className = "nr-image";
11772
+ if (element.style) {
11773
+ for (const [key, value] of Object.entries(element.style)) {
11774
+ img.style.setProperty(key, String(value));
11775
+ }
11776
+ }
11777
+ return img;
11778
+ }
11779
+ case "table":
11780
+ return createTable(element.content, renderInline);
11781
+ case "list":
11782
+ return createList(element.content, renderInline);
11783
+ case "blockquote":
11784
+ return createBlockquote(element.content, element.classes, renderInline);
11785
+ case "hr": {
11786
+ const hr = document.createElement("hr");
11787
+ hr.className = "nr-hr";
11788
+ return hr;
11789
+ }
11790
+ case "toc": {
11791
+ const headers = allElements.filter((e) => e.type === "header");
11792
+ return createTOC(headers.map((h) => ({ level: h.level, text: h.text, id: h.id })), renderInline);
11793
+ }
11794
+ default:
11795
+ return null;
11796
+ }
11797
+ }
11798
+ function renderDirective(element, ctx, allElements) {
11604
11799
  const { directiveType, props, slots, scopeId } = element;
11605
- const Component = directives_default[directiveType];
11800
+ const renderer = directives_default[directiveType];
11606
11801
  const renderSlot = (name) => {
11802
+ const frag = document.createDocumentFragment();
11607
11803
  const slotContent = slots[name];
11608
- if (!slotContent) return null;
11609
- const parsed = context.parseMarkdown(slotContent);
11610
- return context.processAndRenderElements(parsed);
11804
+ if (!slotContent) return frag;
11805
+ const tokens = ctx.parseMarkdown(slotContent);
11806
+ frag.appendChild(ctx.renderElements(tokens));
11807
+ return frag;
11611
11808
  };
11612
11809
  const directiveProps = {
11613
11810
  directiveType,
11614
11811
  props,
11615
11812
  slots,
11616
11813
  renderSlot,
11617
- context,
11618
- index,
11619
- allElements
11814
+ context: ctx,
11815
+ index: 0,
11816
+ allElements,
11817
+ renderInline,
11818
+ renderMarkdown: ctx.renderMarkdown
11620
11819
  };
11621
- if (Component) {
11622
- return /* @__PURE__ */ jsx10(Component, { ...directiveProps }, index);
11820
+ if (renderer) {
11821
+ return renderer(directiveProps);
11623
11822
  }
11624
- return /* @__PURE__ */ jsx10("div", { className: `my-4 p-4 rounded-2xl border border-border bg-background-primary/5`, children: renderSlot("default") }, index);
11625
- };
11626
- var DirectiveRenderer_default = DirectiveRenderer;
11627
-
11628
- // react/RawHtmlRenderer.tsx
11629
- import { useRef as useRef4, useEffect as useEffect3 } from "react";
11823
+ const fallback = document.createElement("div");
11824
+ fallback.className = "nr-unknown-directive";
11825
+ fallback.appendChild(renderSlot("default"));
11826
+ return fallback;
11827
+ }
11630
11828
 
11631
11829
  // react/useTailwindCDN.ts
11632
- import { useEffect as useEffect2, useRef as useRef3 } from "react";
11830
+ import { useEffect, useRef } from "react";
11633
11831
  var CDN_URL = "https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4";
11634
11832
  var SCRIPT_ID = "tailwind-cdn-v4-runtime";
11635
11833
  var CONFIG_ID = "tailwind-cdn-v4-config";
@@ -11642,8 +11840,8 @@ window.tailwind.config = {
11642
11840
  };
11643
11841
  `;
11644
11842
  function useLazyTailwindCDN(enabled) {
11645
- const loadedRef = useRef3(false);
11646
- useEffect2(() => {
11843
+ const loadedRef = useRef(false);
11844
+ useEffect(() => {
11647
11845
  if (!enabled) {
11648
11846
  window.__twCDNRefs = (window.__twCDNRefs ?? 1) - 1;
11649
11847
  if ((window.__twCDNRefs ?? 0) <= 0) {
@@ -11706,272 +11904,52 @@ function preloadTailwindCDN() {
11706
11904
  }
11707
11905
  }
11708
11906
 
11709
- // react/RawHtmlRenderer.tsx
11710
- import { jsx as jsx11 } from "react/jsx-runtime";
11711
- var RawHtmlRenderer = ({
11712
- content,
11713
- globalStyles,
11714
- wrapperClassName
11715
- }) => {
11716
- const containerRef = useRef4(null);
11717
- useEffect3(() => {
11718
- if (!containerRef.current) return;
11719
- const scripts = containerRef.current.querySelectorAll("script");
11720
- scripts.forEach((oldScript) => {
11721
- const newScript = document.createElement("script");
11722
- Array.from(oldScript.attributes).forEach(
11723
- (attr) => newScript.setAttribute(attr.name, attr.value)
11724
- );
11725
- newScript.textContent = oldScript.textContent;
11726
- oldScript.parentNode?.replaceChild(newScript, oldScript);
11727
- });
11728
- scanTailwindCDN();
11729
- }, [content]);
11730
- useEffect3(() => {
11731
- if (!globalStyles) return;
11732
- const styleEl = document.createElement("style");
11733
- styleEl.setAttribute("data-global", "");
11734
- styleEl.textContent = globalStyles;
11735
- document.head.appendChild(styleEl);
11736
- return () => {
11737
- if (styleEl.parentNode) document.head.removeChild(styleEl);
11738
- };
11739
- }, [globalStyles]);
11740
- return /* @__PURE__ */ jsx11("div", { className: wrapperClassName, ref: containerRef, children: /* @__PURE__ */ jsx11("div", { dangerouslySetInnerHTML: { __html: content } }) });
11741
- };
11742
- var RawHtmlRenderer_default = RawHtmlRenderer;
11743
-
11744
- // react/context.tsx
11745
- import { createContext, useContext } from "react";
11746
- var RenderCtx = createContext(null);
11747
- var RenderContextProvider = RenderCtx.Provider;
11748
-
11749
11907
  // react/CustomMarkdownRenderer.tsx
11750
- import { jsx as jsx12, jsxs as jsxs7 } from "react/jsx-runtime";
11751
- var CustomMarkdownRenderer = ({ content: initialContent }) => {
11752
- const [modals, setModals] = useState3({});
11753
- const baseId = useId3().replace(/:/g, "");
11754
- const articleClass = `scope-${baseId}`;
11755
- const contextRef = useRef5(null);
11756
- resetScopeCounter();
11757
- const allElements = useMemo(() => parseMarkdown(initialContent), [initialContent]);
11758
- useEffect4(() => {
11908
+ import { jsx } from "react/jsx-runtime";
11909
+ var CustomMarkdownRenderer = ({ content }) => {
11910
+ const containerRef = useRef2(null);
11911
+ useEffect2(() => {
11912
+ const container = containerRef.current;
11913
+ if (!container) return;
11914
+ container.replaceChildren();
11915
+ container.appendChild(renderMarkdownString(content));
11916
+ scanTailwindCDN();
11759
11917
  const handleHashChange = () => {
11760
11918
  const hash = window.location.hash;
11761
11919
  if (hash) {
11762
11920
  const parts = hash.split("#");
11763
- const id = parts[parts.length - 1];
11764
- scrollToId(id);
11921
+ scrollToId(parts[parts.length - 1]);
11765
11922
  }
11766
11923
  };
11767
11924
  handleHashChange();
11768
11925
  window.addEventListener("hashchange", handleHashChange);
11769
11926
  return () => window.removeEventListener("hashchange", handleHashChange);
11770
- }, [initialContent]);
11771
- const renderElement = useCallback2(
11772
- (element, index, _depth = 0) => {
11773
- switch (element.type) {
11774
- case "header": {
11775
- const HeaderTag = `h${element.level}`;
11776
- let text = element.text;
11777
- const alignCenter = text.match(/^->\s*(.+?)\s*<-\s*$/);
11778
- const alignRight = text.match(/^->\s*(.+?)\s*->\s*$/);
11779
- if (alignCenter) {
11780
- text = alignCenter[1];
11781
- } else if (alignRight) {
11782
- text = alignRight[1];
11783
- }
11784
- const userClasses = element.classes || "";
11785
- let headerClasses = `md-h${element.level}`;
11786
- if (alignCenter) headerClasses += " text-center";
11787
- if (alignRight) headerClasses += " text-right";
11788
- if (userClasses) headerClasses += ` ${userClasses}`;
11789
- return React8.createElement(
11790
- HeaderTag,
11791
- { key: index, id: element.id, className: headerClasses },
11792
- renderInline(text)
11793
- );
11794
- }
11795
- case "paragraph": {
11796
- const lines = element.content.split("\n");
11797
- const processedContent = lines.map((line, lineIndex) => {
11798
- const hardBreakMatch = line.match(/^(.*?)(\s{2,})$/);
11799
- if (hardBreakMatch) {
11800
- return /* @__PURE__ */ jsxs7(React8.Fragment, { children: [
11801
- renderInline(hardBreakMatch[1]),
11802
- /* @__PURE__ */ jsx12("br", {})
11803
- ] }, lineIndex);
11804
- }
11805
- const isLastLine = lineIndex === lines.length - 1;
11806
- return /* @__PURE__ */ jsxs7(React8.Fragment, { children: [
11807
- renderInline(line),
11808
- !isLastLine && " "
11809
- ] }, lineIndex);
11810
- });
11811
- const pUserClasses = element.classes || "";
11812
- let pClasses = "md-p";
11813
- if (pUserClasses) pClasses += ` ${pUserClasses}`;
11814
- if (element.align) pClasses += ` text-${element.align}`;
11815
- return /* @__PURE__ */ jsx12("p", { id: element.id, className: pClasses, children: processedContent }, index);
11816
- }
11817
- case "codeblock":
11818
- return /* @__PURE__ */ jsx12(
11819
- CodeBlock,
11820
- {
11821
- code: element.content,
11822
- language: element.language,
11823
- title: element.title
11824
- },
11825
- index
11826
- );
11827
- case "directive":
11828
- return /* @__PURE__ */ jsx12(
11829
- DirectiveRenderer_default,
11830
- {
11831
- element,
11832
- context: contextRef.current,
11833
- index,
11834
- allElements
11835
- },
11836
- index
11837
- );
11838
- case "html": {
11839
- let processedContent = element.content;
11840
- let globalStyles = "";
11841
- processedContent = processedContent.replace(
11842
- /<style(?:\s+[^>]*)?>([\s\S]*?)<\/style>/gi,
11843
- (_match, cssContent) => {
11844
- globalStyles += cssContent + "\n";
11845
- return "";
11846
- }
11847
- );
11848
- const wrapperClassName = "w-full my-4";
11849
- return /* @__PURE__ */ jsx12(
11850
- RawHtmlRenderer_default,
11851
- {
11852
- content: processedContent,
11853
- globalStyles: globalStyles || void 0,
11854
- wrapperClassName
11855
- },
11856
- index
11857
- );
11858
- }
11859
- case "html-block": {
11860
- const htmlBlock = element;
11861
- const rawProps = parseHtmlAttrs(htmlBlock.attrs);
11862
- const props = {};
11863
- for (const [key, value] of Object.entries(rawProps)) {
11864
- if (key === "class") props["className"] = value;
11865
- else if (key === "for") props["htmlFor"] = value;
11866
- else if (key === "tabindex") props["tabIndex"] = value;
11867
- else props[key] = value;
11868
- }
11869
- return React8.createElement(
11870
- htmlBlock.tag,
11871
- { key: index, ...props },
11872
- ...processAndRenderElements(htmlBlock.children, _depth + 1)
11873
- );
11874
- }
11875
- case "image":
11876
- return /* @__PURE__ */ jsx12(
11877
- "img",
11878
- {
11879
- alt: element.alt,
11880
- src: element.src,
11881
- style: element.style,
11882
- className: "max-w-full h-auto"
11883
- },
11884
- index
11885
- );
11886
- case "table":
11887
- return /* @__PURE__ */ jsx12("div", { children: renderTable(element.content) }, index);
11888
- case "list":
11889
- return /* @__PURE__ */ jsx12("div", { children: renderList(element.content) }, index);
11890
- case "blockquote":
11891
- return /* @__PURE__ */ jsx12("blockquote", { className: `border-l-4 border-accent-primary/30 pl-4 italic text-text-secondary my-4 text-sm sm:text-base${element.classes ? ` ${element.classes}` : ""}`, children: renderInline(element.content) }, index);
11892
- case "hr":
11893
- return /* @__PURE__ */ jsx12("hr", { className: "my-8 border-border" }, index);
11894
- case "toc":
11895
- return /* @__PURE__ */ jsx12("div", { children: generateToc(allElements) }, index);
11896
- default:
11897
- return null;
11898
- }
11899
- },
11900
- [allElements]
11901
- );
11902
- const processAndRenderElements = useCallback2(
11903
- (elements, depth = 0) => {
11904
- const result = [];
11905
- let i = 0;
11906
- while (i < elements.length) {
11907
- const el = elements[i];
11908
- if (el.type === "directive" && ["card", "card-m", "card-b"].includes(el.directiveType)) {
11909
- const cards = [];
11910
- while (i < elements.length && elements[i].type === "directive" && ["card", "card-m", "card-b"].includes(elements[i].directiveType)) {
11911
- cards.push(elements[i]);
11912
- i++;
11913
- }
11914
- if (cards.length === 1 || cards[0].props?.batch === "off") {
11915
- for (let c = 0; c < cards.length; c++) {
11916
- result.push(renderElement(cards[c], result.length, depth));
11917
- }
11918
- } else {
11919
- const firstCardClass = cards[0].props?.["class"] || "";
11920
- const justifyClasses = firstCardClass.match(/\bjustify-\S+/g) || [];
11921
- const wrapperJustify = justifyClasses.length > 0 ? justifyClasses.join(" ") : "";
11922
- result.push(
11923
- /* @__PURE__ */ jsx12("div", { className: `not-prose flex flex-wrap gap-6 my-6 ${wrapperJustify}`, children: cards.map((card, ci) => /* @__PURE__ */ jsx12(React8.Fragment, { children: renderElement(card, ci, depth) }, ci)) }, `card-grid-${result.length}`)
11924
- );
11925
- }
11926
- } else {
11927
- result.push(renderElement(el, result.length, depth));
11928
- i++;
11929
- }
11930
- }
11931
- return result;
11932
- },
11933
- [renderElement]
11934
- );
11935
- const generateToc = (elements) => {
11936
- const headers = extractHeaders(elements);
11937
- if (headers.length === 0) return null;
11938
- return /* @__PURE__ */ jsxs7("nav", { className: "not-prose my-6 p-4 rounded-2xl border border-border bg-background-primary/5", children: [
11939
- /* @__PURE__ */ jsx12("div", { className: "text-base font-bold mb-3", children: "Table of Contents" }),
11940
- /* @__PURE__ */ jsx12("ul", { className: "space-y-1 list-none p-0 m-0", children: headers.map((h, i) => {
11941
- if (h.type !== "header") return null;
11942
- const indentClass = h.level <= 2 ? "pl-0" : h.level === 3 ? "pl-4" : h.level === 4 ? "pl-8" : "pl-12";
11943
- return /* @__PURE__ */ jsx12("li", { className: `${indentClass} text-sm sm:text-base`, children: /* @__PURE__ */ jsx12(
11944
- "a",
11945
- {
11946
- href: `#${h.id}`,
11947
- className: "text-accent-primary hover:text-accent-primary/80 no-underline hover:underline transition-colors",
11948
- onClick: (e) => {
11949
- e.preventDefault();
11950
- scrollToId(h.id);
11951
- },
11952
- children: renderInline(h.text.replace(/->|<-/g, "").trim())
11953
- }
11954
- ) }, i);
11955
- }) })
11956
- ] });
11957
- };
11958
- const contextForDirectives = {
11959
- modals,
11960
- setModals,
11961
- articleClass,
11962
- allElements,
11963
- parseMarkdown,
11964
- renderElement,
11965
- renderInline,
11966
- processAndRenderElements
11967
- };
11968
- contextRef.current = contextForDirectives;
11969
- return /* @__PURE__ */ jsx12(RenderContextProvider, { value: contextForDirectives, children: processAndRenderElements(allElements) });
11927
+ }, [content]);
11928
+ return /* @__PURE__ */ jsx("div", { ref: containerRef });
11970
11929
  };
11971
11930
  var CustomMarkdownRenderer_default = CustomMarkdownRenderer;
11972
11931
 
11932
+ // react/RawHtmlRenderer.tsx
11933
+ import { useEffect as useEffect3, useRef as useRef3 } from "react";
11934
+ import { jsx as jsx2 } from "react/jsx-runtime";
11935
+ var RawHtmlRenderer = ({
11936
+ content,
11937
+ wrapperClassName = "nr-raw-html"
11938
+ }) => {
11939
+ const containerRef = useRef3(null);
11940
+ useEffect3(() => {
11941
+ const container = containerRef.current;
11942
+ if (!container) return;
11943
+ container.replaceChildren();
11944
+ container.appendChild(renderHtmlString(content));
11945
+ scanTailwindCDN();
11946
+ }, [content]);
11947
+ return /* @__PURE__ */ jsx2("div", { ref: containerRef, className: wrapperClassName });
11948
+ };
11949
+ var RawHtmlRenderer_default = RawHtmlRenderer;
11950
+
11973
11951
  // react/NRpreviewer.tsx
11974
- import { jsx as jsx13 } from "react/jsx-runtime";
11952
+ import { jsx as jsx3 } from "react/jsx-runtime";
11975
11953
  var NRpreviewer = ({
11976
11954
  content,
11977
11955
  html,
@@ -11980,36 +11958,32 @@ var NRpreviewer = ({
11980
11958
  style
11981
11959
  }) => {
11982
11960
  useLazyTailwindCDN(tailwindCDN);
11961
+ const wrapperClass = `nr-prose${className ? ` ${className}` : ""}`;
11983
11962
  if (content) {
11984
- return /* @__PURE__ */ jsx13("div", { className: `nr-prose${className ? ` ${className}` : ""}`, style, children: /* @__PURE__ */ jsx13(CustomMarkdownRenderer_default, { content }) });
11963
+ return /* @__PURE__ */ jsx3("div", { className: wrapperClass, style, children: /* @__PURE__ */ jsx3(CustomMarkdownRenderer_default, { content }) });
11985
11964
  }
11986
11965
  if (html) {
11987
- return /* @__PURE__ */ jsx13("div", { className: `nr-prose${className ? ` ${className}` : ""}`, style, children: /* @__PURE__ */ jsx13(RawHtmlRenderer_default, { content: html, wrapperClassName: "nr-preview-html" }) });
11966
+ return /* @__PURE__ */ jsx3("div", { className: wrapperClass, style, children: /* @__PURE__ */ jsx3(RawHtmlRenderer_default, { content: html }) });
11988
11967
  }
11989
11968
  return null;
11990
11969
  };
11991
11970
  var NRpreviewer_default = NRpreviewer;
11992
11971
 
11993
11972
  // react/useDebounce.ts
11994
- import { useState as useState4, useEffect as useEffect5 } from "react";
11973
+ import { useState, useEffect as useEffect4 } from "react";
11995
11974
  function useDebounce(value, delay) {
11996
- const [debouncedValue, setDebouncedValue] = useState4(value);
11997
- useEffect5(() => {
11975
+ const [debouncedValue, setDebouncedValue] = useState(value);
11976
+ useEffect4(() => {
11998
11977
  const timer = setTimeout(() => setDebouncedValue(value), delay);
11999
11978
  return () => clearTimeout(timer);
12000
11979
  }, [value, delay]);
12001
11980
  return debouncedValue;
12002
11981
  }
12003
11982
  export {
12004
- Admonition,
12005
- CodeBlock,
12006
11983
  CustomMarkdownRenderer_default as CustomMarkdownRenderer,
12007
- Details,
12008
- IconRenderer,
12009
- Modal,
12010
11984
  NRpreviewer_default as NRpreviewer,
11985
+ RawHtmlRenderer_default as RawHtmlRenderer,
12011
11986
  extractAttributes,
12012
- extractHeaders,
12013
11987
  generateId,
12014
11988
  generateScopeId,
12015
11989
  parseCssString,