@mirrordown/core 0.1.1 → 0.1.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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Changelog
2
2
 
3
3
 
4
+
5
+ ## 0.1.2
6
+ <sub>2026-10-28</sub>
7
+
8
+ - *(patch)*
9
+ Add the tab-icons plugin set, a port of vitepress-plugin-group-icons for Mirrordown's tabs: each tab label gets the icon its text matches (a keyword such as `npm`, `pnpm` or `vite` as a whole word, the longest winning, else a file name or extension such as `package.json` or `.ts`), or the one a `[!keyword]` marker at its start names; `[!none]` turns matching off for one label. The icon is an inline `<svg class="markdown-tab-icon" aria-hidden="true">` before the label's text, and the marker comes out of the label and its panel's `aria-label`. It ships group-icons' built-in icons (from VSCode Icons and SVG Logos); the `icons` option adds or replaces them, with light and dark pairs, and `builtin` and `match` turn the built-in icons and matching off. The markdown-it, remark and Sätteri plugins emit identical HTML.
10
+
4
11
  ## 0.1.1
5
12
  <sub>2026-10-28</sub>
6
13
 
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { a as mermaidSource, i as mermaidIdPrefixes, n as mermaidDiagram, o as mermaidSvg, r as mermaidFailure, t as hastAttributes } from "./mermaid-pele-BMyyDozN.mjs";
1
2
  // src/escapes.ts
2
3
  const ASCII_PUNCTUATION = /^[!-/:-@[-`{-~]$/;
3
4
  const ENTITY = /^&(?:#\d+|#x[\da-f]+|[a-z][\da-z]*);/i;
@@ -2128,7 +2129,7 @@ const editableTree = (root, build, setChildren, setData) => {
2128
2129
  };
2129
2130
  };
2130
2131
  // src/inline-svg.ts
2131
- const hash$1 = (str) => {
2132
+ const hash = (str) => {
2132
2133
  let h = 2166136261;
2133
2134
  for (let i = 0; i < str.length; i++) h = Math.imul(h ^ str.charCodeAt(i), 16777619) >>> 0;
2134
2135
  return h.toString(36);
@@ -2136,7 +2137,7 @@ const hash$1 = (str) => {
2136
2137
  /**
2137
2138
  * The id of a deduplicated SVG's sprite: a hash of its path relative to the document, with `/` separators, so the same document renders the same ids on any machine or OS (an absolute path would leak the build machine into the HTML).
2138
2139
  */
2139
- const svgSpriteId = (relativePath) => `svg-sprite-${hash$1(relativePath)}`;
2140
+ const svgSpriteId = (relativePath) => `svg-sprite-${hash(relativePath)}`;
2140
2141
  const extractSvgParts = (content) => {
2141
2142
  const openTag = /<svg([^>]*?)>/i.exec(content)?.[1] ?? ``;
2142
2143
  return {
@@ -2176,95 +2177,6 @@ const inlineSvgMarkup = (content, alts, relativePath, limits) => {
2176
2177
  return index === 0 ? sprite + use : use;
2177
2178
  });
2178
2179
  };
2179
- // src/mermaid-pele.ts
2180
- /** The class a fenced `mermaid` block's `<code>` takes. */
2181
- const MERMAID_LANGUAGE_CLASS = `language-mermaid`;
2182
- /** The class a `<pre>` holding a diagram written as HTML takes, as Mermaid reads it in the browser. */
2183
- const MERMAID_PRE_CLASS = `mermaid`;
2184
- const hash = (str) => {
2185
- let h = 2166136261;
2186
- for (let i = 0; i < str.length; i++) h = Math.imul(h ^ str.charCodeAt(i), 16777619) >>> 0;
2187
- return h.toString(36);
2188
- };
2189
- /** A diagram's source as Pele reads it: line endings normalized, as markdown-it already has them. */
2190
- const mermaidSource = (text) => text.replace(/\r\n?/g, `\n`);
2191
- /**
2192
- * A document's id prefixes, one per diagram in document order: `prefix`, then a hash of the diagram's source, so a diagram's ids don't change when others are edited, with `-2`, `-3`… for repeats of one diagram. Pele namespaces every id it writes (an accessible title, a gradient) under it. Create one per document.
2193
- */
2194
- const mermaidIdPrefixes = (prefix) => {
2195
- const seen = /* @__PURE__ */ new Map();
2196
- return (source) => {
2197
- const id = `${prefix}-${hash(source)}`;
2198
- const count = (seen.get(id) ?? 0) + 1;
2199
- seen.set(id, count);
2200
- return count === 1 ? id : `${id}-${count}`;
2201
- };
2202
- };
2203
- const escapeAttribute = (value) => value.replace(/&/g, `&amp;`).replace(/"/g, `&quot;`);
2204
- const classes = (value) => value.split(/\s+/).filter((name) => name !== `` && name !== MERMAID_LANGUAGE_CLASS && name !== MERMAID_PRE_CLASS);
2205
- /**
2206
- * Pele's `<svg>` with the attributes the diagram's element had (from an attribute block such as `{#id .class}`): classes are added after Pele's, a style after Pele's (whose theme variables the diagram needs), and anything else is set, replacing Pele's value. The class that marked the element as a diagram is dropped.
2207
- */
2208
- const mermaidSvg = (svg, attributes) => {
2209
- const open = /^<svg\b[^>]*>/.exec(svg)?.[0];
2210
- if (!open || attributes.length === 0) return svg;
2211
- const own = [...open.slice(4, -1).matchAll(/\s([^\s=]+)="([^"]*)"/g)].map(([, name = ``, value = ``]) => [name, value]);
2212
- const merged = new Map(own);
2213
- for (const [name, value] of attributes) {
2214
- const escaped = escapeAttribute(value);
2215
- const current = merged.get(name);
2216
- if (name === `class`) {
2217
- const added = classes(value).map(escapeAttribute).join(` `);
2218
- if (added) merged.set(name, current ? `${current} ${added}` : added);
2219
- } else if (name === `style` && current) merged.set(name, `${current.replace(/;$/, ``)};${escaped}`);
2220
- else merged.set(name, escaped);
2221
- }
2222
- return `<svg${[...merged].map(([name, value]) => ` ${name}="${value}"`).join(``)}>${svg.slice(open.length)}`;
2223
- };
2224
- /** A hast element's properties as attributes; `className` becomes `class`, and other names are kept as the attribute plugins write them. */
2225
- const hastAttributes = (properties) => {
2226
- const text = (value) => typeof value === `string` ? value : typeof value === `number` ? String(value) : value === true ? `` : Array.isArray(value) ? value.map((item) => text(item) ?? ``).join(` `) : void 0;
2227
- const attributes = [];
2228
- for (const [key, value] of Object.entries(properties ?? {})) {
2229
- const written = text(value);
2230
- if (written !== void 0) attributes.push([key === `className` ? `class` : key, written]);
2231
- }
2232
- return attributes;
2233
- };
2234
- const hasClass = (node, name) => {
2235
- const value = node.properties?.className;
2236
- return Array.isArray(value) ? value.includes(name) : typeof value === `string` && value.split(/\s+/).includes(name);
2237
- };
2238
- const textOf = (node) => node.type === `text` ? node.value ?? `` : (node.children ?? []).map(textOf).join(``);
2239
- /**
2240
- * The diagram a `<pre>` holds, as rehype-mermaid finds them: a `<pre>` whose only content (besides whitespace) is a `<code class="language-mermaid">`, which is how a fenced `mermaid` block renders, or a `<pre class="mermaid">`. `element` is the one whose attributes the `<svg>` takes. `undefined` for anything else.
2241
- */
2242
- const mermaidDiagram = (pre) => {
2243
- if (pre.tagName !== `pre`) return void 0;
2244
- if (hasClass(pre, MERMAID_PRE_CLASS)) return {
2245
- source: mermaidSource(textOf(pre)),
2246
- element: pre
2247
- };
2248
- let code;
2249
- for (const child of pre.children ?? []) {
2250
- if (child.type === `text` && /^\s*$/.test(child.value ?? ``)) continue;
2251
- if (code || child.tagName !== `code`) return void 0;
2252
- code = child;
2253
- }
2254
- return code && hasClass(code, MERMAID_LANGUAGE_CLASS) ? {
2255
- source: mermaidSource(textOf(code)),
2256
- element: code
2257
- } : void 0;
2258
- };
2259
- /**
2260
- * The error a diagram that failed to render throws: Pele's message, at the document line Pele located the problem on (counting from `line`, the line the diagram's element starts on), or at `line` itself when Pele has no location. The original error is the `cause`.
2261
- */
2262
- const mermaidFailure = (error, line) => {
2263
- const reason = error instanceof Error ? error.message : String(error);
2264
- const within = error instanceof Error && `line` in error && typeof error.line === `number` && error.line > 0 ? error.line : 0;
2265
- const at = line === void 0 ? `` : ` on line ${String(line + within)}`;
2266
- return new Error(`Could not render the mermaid diagram${at}: ${reason}`, { cause: error });
2267
- };
2268
2180
  export { ALERT_ALIASES, CAPTION_CLASS, DEFAULT_TITLE, ICONS, LIGHTBOX_MARKER, containersKept, createAbbreviationScan, createAlertResolver, createDelimitedTransform, createKbdTransform, editableTree, escapedIndices, figureProperties, hastAttributes, headingRank, inlineSvgMarkup, isAlertMarkerLine, isCaptionFigure, isCaptionLine, isEmptyParagraph, isImageParagraph, itemColumns, lightboxDialog, lightboxId, lightboxTrigger, maskEscaped, maskTreeEscapes, mermaidDiagram, mermaidFailure, mermaidIdPrefixes, mermaidSource, mermaidSvg, parseAbbreviations, placeCutAttributes, plainText, processCaptions, processSteps, processStepsInChildren, processTabs, processTabsInChildren, scriptSyntax, sectionize, splitAlertParagraph, startsCaption, stripAttrs, stripCaptionMarker, svgSpriteId, tabLabelText, tabsBlockId, unmaskEscaped };
2269
2181
 
2270
2182
  //# sourceMappingURL=index.mjs.map