@loidolt/theme-docs 0.11.1 → 0.12.1

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.
@@ -71,7 +71,12 @@
71
71
  >
72
72
  {#if filename || copyable}
73
73
  <figcaption class="ldt-code__header">
74
- {#if filename}<span class="ldt-code__filename">{filename}</span>{/if}
74
+ {#if filename}<span class="ldt-code__filename">{filename}</span
75
+ >{:else if lang}<!-- The bar holds the copy button anyway; the language fills its left end.
76
+ Hidden from assistive tech: the code is already named "‹lang› code". --><span
77
+ class="ldt-code__filename"
78
+ aria-hidden="true">{lang}</span
79
+ >{/if}
75
80
  {#if copyable}<button type="button" class="ldt-code__copy" data-ldt-copy>{copyLabel}</button
76
81
  >{/if}
77
82
  </figcaption>
@@ -165,7 +165,14 @@ function parse(source, options) {
165
165
  return `<pre class="ldt-mermaid" data-ldt-mermaid>${escapeHtml(text)}</pre>\n`;
166
166
  }
167
167
  codes.push({ text, lang: language });
168
- const header = `<figcaption class="ldt-code__header">${filename ? `<span class="ldt-code__filename">${escapeHtml(filename)}</span>` : ''}<button type="button" class="ldt-code__copy" data-ldt-copy>${escapeHtml(copyLabel)}</button></figcaption>`;
168
+ // As `CodeSnippet` does: without a filename the language fills the bar's left end, hidden
169
+ // from assistive tech, which already hears the block named "‹lang› code".
170
+ const label = filename
171
+ ? `<span class="ldt-code__filename">${escapeHtml(filename)}</span>`
172
+ : language
173
+ ? `<span class="ldt-code__filename" aria-hidden="true">${escapeHtml(language)}</span>`
174
+ : '';
175
+ const header = `<figcaption class="ldt-code__header">${label}<button type="button" class="ldt-code__copy" data-ldt-copy>${escapeHtml(copyLabel)}</button></figcaption>`;
169
176
  return `<figure class="ldt-code"${language ? ` data-lang="${escapeHtml(language)}"` : ''}>${header}<pre class="ldt-code__pre" tabindex="0" aria-label="${escapeHtml(filename ?? codeLabel(language))}"><code${language ? ` class="language-${escapeHtml(language)}"` : ''}>${CODE_MARK(codes.length - 1)}</code></pre></figure>\n`;
170
177
  },
171
178
  html({ text }) {
@@ -27,6 +27,19 @@ export const themeVariables = (colors) => ({
27
27
  fontSize: '14px',
28
28
  });
29
29
  let counter = 0;
30
+ /**
31
+ * Mermaid sizes a diagram to its container, so a wide flowchart on a phone shrinks until its
32
+ * labels are a few pixels tall. Below three quarters of its drawn size it stops shrinking and the
33
+ * figure scrolls sideways instead.
34
+ */
35
+ function keepLegible(svg) {
36
+ const width = Number(svg
37
+ ?.getAttribute('viewBox')
38
+ ?.trim()
39
+ .split(/[\s,]+/)[2]);
40
+ if (svg && width > 0)
41
+ svg.style.minWidth = `${Math.round(width * 0.75)}px`;
42
+ }
30
43
  /**
31
44
  * Draws a diagram into `target` from `source`. Leaves `target` alone — still showing the source —
32
45
  * when Mermaid is not available or the source does not parse.
@@ -39,6 +52,7 @@ export async function drawDiagram(target, source, colors) {
39
52
  counter += 1;
40
53
  const svg = await renderMermaid(api, `ldt-mermaid-${counter}`, source, themeVariables(colors));
41
54
  target.innerHTML = svg;
55
+ keepLegible(target.querySelector('svg'));
42
56
  return true;
43
57
  }
44
58
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loidolt/theme-docs",
3
- "version": "0.11.1",
3
+ "version": "0.12.1",
4
4
  "description": "Accessible Markdown documentation components for Loidolt applications",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -31,8 +31,8 @@
31
31
  "clean": "rimraf dist"
32
32
  },
33
33
  "dependencies": {
34
- "@loidolt/theme-svelte": "^0.11.1",
35
- "@loidolt/theme-tokens": "^0.11.1",
34
+ "@loidolt/theme-svelte": "^0.12.1",
35
+ "@loidolt/theme-tokens": "^0.12.1",
36
36
  "marked": "^18.0.0"
37
37
  },
38
38
  "peerDependencies": {