@noirmd/previewer 2.0.0 → 2.0.2

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.
@@ -176,4 +176,20 @@ interface DirectiveProps {
176
176
  type DirectiveRendererFn = (props: DirectiveProps) => HTMLElement | DocumentFragment;
177
177
  declare const directiveRegistry: Record<string, DirectiveRendererFn>;
178
178
 
179
- export { type DirectiveProps, type DirectiveRendererFn, type VanillaRenderContext, createAdmonition, createBlockquote, createCodeBlock, createDetails, createIcon, createList, createModal, createTOC, createTable, directiveRegistry, renderHtmlString, renderInline, renderMarkdownString, renderTokens };
179
+ /**
180
+ * Detect whether the host page already provides a color theme
181
+ * (daisyUI, a Tailwind @theme block, or --color-* variables).
182
+ */
183
+ declare function hasHostTheme(): boolean;
184
+ /**
185
+ * Inject the NoirMD @theme block so Tailwind CDN color classes
186
+ * (bg-primary, text-secondary, ...) resolve inside markdown.
187
+ * Skipped when the host already defines a theme. Idempotent.
188
+ */
189
+ declare function injectNRTailwindTheme(): void;
190
+ /**
191
+ * Remove the injected NoirMD @theme block (idempotent).
192
+ */
193
+ declare function removeNRTailwindTheme(): void;
194
+
195
+ export { type DirectiveProps, type DirectiveRendererFn, type VanillaRenderContext, createAdmonition, createBlockquote, createCodeBlock, createDetails, createIcon, createList, createModal, createTOC, createTable, directiveRegistry, hasHostTheme, injectNRTailwindTheme, removeNRTailwindTheme, renderHtmlString, renderInline, renderMarkdownString, renderTokens };
package/dist/vanilla.d.ts CHANGED
@@ -176,4 +176,20 @@ interface DirectiveProps {
176
176
  type DirectiveRendererFn = (props: DirectiveProps) => HTMLElement | DocumentFragment;
177
177
  declare const directiveRegistry: Record<string, DirectiveRendererFn>;
178
178
 
179
- export { type DirectiveProps, type DirectiveRendererFn, type VanillaRenderContext, createAdmonition, createBlockquote, createCodeBlock, createDetails, createIcon, createList, createModal, createTOC, createTable, directiveRegistry, renderHtmlString, renderInline, renderMarkdownString, renderTokens };
179
+ /**
180
+ * Detect whether the host page already provides a color theme
181
+ * (daisyUI, a Tailwind @theme block, or --color-* variables).
182
+ */
183
+ declare function hasHostTheme(): boolean;
184
+ /**
185
+ * Inject the NoirMD @theme block so Tailwind CDN color classes
186
+ * (bg-primary, text-secondary, ...) resolve inside markdown.
187
+ * Skipped when the host already defines a theme. Idempotent.
188
+ */
189
+ declare function injectNRTailwindTheme(): void;
190
+ /**
191
+ * Remove the injected NoirMD @theme block (idempotent).
192
+ */
193
+ declare function removeNRTailwindTheme(): void;
194
+
195
+ export { type DirectiveProps, type DirectiveRendererFn, type VanillaRenderContext, createAdmonition, createBlockquote, createCodeBlock, createDetails, createIcon, createList, createModal, createTOC, createTable, directiveRegistry, hasHostTheme, injectNRTailwindTheme, removeNRTailwindTheme, renderHtmlString, renderInline, renderMarkdownString, renderTokens };
package/dist/vanilla.js CHANGED
@@ -11303,7 +11303,10 @@ var modalDirective = ({ props, renderSlot }) => {
11303
11303
  const dialog = createModal(modalTitle);
11304
11304
  const body = dialog.querySelector(".nr-modal__body");
11305
11305
  if (body) {
11306
- body.appendChild(renderSlot("default"));
11306
+ const prose = document.createElement("div");
11307
+ prose.className = "nr-prose";
11308
+ prose.appendChild(renderSlot("default"));
11309
+ body.appendChild(prose);
11307
11310
  }
11308
11311
  btn.addEventListener("click", () => {
11309
11312
  if (!dialog.open) {
@@ -11457,8 +11460,10 @@ var cardDirective = ({
11457
11460
  const dialog = createModal(title || "Detalles");
11458
11461
  const modalBody = dialog.querySelector(".nr-modal__body");
11459
11462
  if (modalBody) {
11460
- const contentSlot = renderSlot("content") || renderSlot("default");
11461
- modalBody.appendChild(contentSlot);
11463
+ const prose = document.createElement("div");
11464
+ prose.className = "nr-prose";
11465
+ prose.appendChild(renderSlot("content") || renderSlot("default"));
11466
+ modalBody.appendChild(prose);
11462
11467
  }
11463
11468
  card.addEventListener("click", () => {
11464
11469
  if (!dialog.open) {
@@ -11812,6 +11817,73 @@ function renderDirective(element, ctx, allElements) {
11812
11817
  fallback.appendChild(renderSlot("default"));
11813
11818
  return fallback;
11814
11819
  }
11820
+
11821
+ // vanilla/tailwindTheme.ts
11822
+ var THEME_STYLE_ID = "nr-tailwind-theme";
11823
+ var NR_THEME_CSS = `
11824
+ @theme {
11825
+ --color-primary: var(--color-accent-primary, oklch(var(--p, 55% 0.3 240) / 1));
11826
+ --color-primary-content: #ffffff;
11827
+ --color-secondary: oklch(var(--s, 55% 0.25 200) / 1);
11828
+ --color-secondary-content: #ffffff;
11829
+ --color-accent: var(--color-accent-primary, oklch(var(--a, 65% 0.25 160) / 1));
11830
+ --color-accent-content: #ffffff;
11831
+ --color-neutral: oklch(var(--n, 50% 0.05 240) / 1);
11832
+ --color-neutral-content: var(--color-text-primary, oklch(var(--nc, 92% 0.02 240) / 1));
11833
+ --color-base-100: var(--color-background-primary, oklch(var(--b1, 15% 0.01 260) / 1));
11834
+ --color-base-200: var(--color-background-secondary-solid, oklch(var(--b2, 20% 0.02 260) / 1));
11835
+ --color-base-300: var(--color-border, oklch(var(--b3, 25% 0.03 260) / 1));
11836
+ --color-base-content: var(--color-text-primary, oklch(var(--bc, 92% 0.02 260) / 1));
11837
+ --color-info: oklch(var(--in, 70% 0.2 220) / 1);
11838
+ --color-info-content: #ffffff;
11839
+ --color-success: oklch(var(--su, 65% 0.25 140) / 1);
11840
+ --color-success-content: #ffffff;
11841
+ --color-warning: oklch(var(--wa, 80% 0.25 80) / 1);
11842
+ --color-warning-content: #1f2937;
11843
+ --color-error: oklch(var(--er, 65% 0.3 30) / 1);
11844
+ --color-error-content: #ffffff;
11845
+ }
11846
+ `;
11847
+ function getVar(root, name) {
11848
+ return getComputedStyle(root).getPropertyValue(name).trim();
11849
+ }
11850
+ function stylesheetHasTheme() {
11851
+ for (const sheet of Array.from(document.styleSheets)) {
11852
+ let rules = null;
11853
+ try {
11854
+ rules = sheet.cssRules;
11855
+ } catch {
11856
+ continue;
11857
+ }
11858
+ if (!rules) continue;
11859
+ for (const rule of Array.from(rules)) {
11860
+ const css2 = rule.cssText || "";
11861
+ if (css2.includes("@theme") || css2.includes('@plugin "daisyui"')) return true;
11862
+ }
11863
+ }
11864
+ return false;
11865
+ }
11866
+ function hasHostTheme() {
11867
+ if (typeof window === "undefined" || typeof document === "undefined") return true;
11868
+ if (getVar(document.documentElement, "--color-primary")) return true;
11869
+ if (getVar(document.documentElement, "--color-base-100")) return true;
11870
+ if (document.body && (getVar(document.body, "--color-primary") || getVar(document.body, "--color-base-100"))) return true;
11871
+ return stylesheetHasTheme();
11872
+ }
11873
+ function injectNRTailwindTheme() {
11874
+ if (typeof document === "undefined") return;
11875
+ if (document.getElementById(THEME_STYLE_ID)) return;
11876
+ if (hasHostTheme()) return;
11877
+ const style = document.createElement("style");
11878
+ style.id = THEME_STYLE_ID;
11879
+ style.setAttribute("type", "text/tailwindcss");
11880
+ style.textContent = NR_THEME_CSS;
11881
+ document.head.appendChild(style);
11882
+ }
11883
+ function removeNRTailwindTheme() {
11884
+ if (typeof document === "undefined") return;
11885
+ document.getElementById(THEME_STYLE_ID)?.remove();
11886
+ }
11815
11887
  export {
11816
11888
  createAdmonition,
11817
11889
  createBlockquote,
@@ -11823,6 +11895,9 @@ export {
11823
11895
  createTOC,
11824
11896
  createTable,
11825
11897
  directives_default as directiveRegistry,
11898
+ hasHostTheme,
11899
+ injectNRTailwindTheme,
11900
+ removeNRTailwindTheme,
11826
11901
  renderHtmlString,
11827
11902
  renderInline,
11828
11903
  renderMarkdownString,