@writedocs/generator 0.10.9 → 0.10.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@writedocs/generator",
3
- "version": "0.10.9",
3
+ "version": "0.10.11",
4
4
  "description": "Static site generator for docs — a writedocs.json + MDX folder in, a static site out.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,9 +1,11 @@
1
1
  ---
2
2
  import { extraClasses } from './class-names';
3
3
  import AppIcon from "./AppIcon.astro";
4
+ import { plainText } from "../lib/plain-text.js";
4
5
 
5
6
  interface Props {
6
- title: string;
7
+ // A string, or JSX - `title={<><code>X</code> details</>}`, as Mintlify allows.
8
+ title: string | object;
7
9
  icon?: string;
8
10
  // Mintlify parity: `description` is a muted second line under the title,
9
11
  // `defaultOpen` renders the accordion already expanded.
@@ -30,7 +32,7 @@ function slugify(value: string): string {
30
32
  .replace(/[^a-z0-9]+/g, "-")
31
33
  .replace(/^-+|-+$/g, "");
32
34
  }
33
- const titleId = _titleId ?? slugify(title);
35
+ const titleId = _titleId ?? slugify(plainText(title));
34
36
  ---
35
37
 
36
38
  <details class:list={["wd-accordion", extraClasses(Astro.props)]} open={defaultOpen}>
@@ -39,7 +41,7 @@ const titleId = _titleId ?? slugify(title);
39
41
  {icon && <AppIcon icon={icon} class="wd-accordion-icon" />}
40
42
  <span class="wd-accordion-text">
41
43
  <span class="wd-accordion-title" id={titleId}>
42
- {title}
44
+ {Astro.slots.has("wd-title") ? <slot name="wd-title" /> : title}
43
45
  <a class="wd-heading-anchor" href={`#${titleId}`} aria-label="Link to this section"> # </a>
44
46
  </span>
45
47
  {description && <span class="wd-accordion-description">{description}</span>}
@@ -6,10 +6,11 @@ import { extraClasses } from './class-names';
6
6
  // shorthand `<Info>` and get an identical result. Both forms take the
7
7
  // same `title` prop.
8
8
  import AppIcon from "./AppIcon.astro";
9
+ import { plainText } from "../lib/plain-text.js";
9
10
 
10
11
  interface Props {
11
12
  type?: "note" | "tip" | "warning" | "danger" | "info" | "check";
12
- title?: string;
13
+ title?: string | object;
13
14
  // Set automatically by remarkCalloutAnchorIds (src/lib/mdx-callout-anchor-ids.js)
14
15
  // for every <Callout title="...">/<Note title="...">/etc. it finds in an
15
16
  // .mdx file's own JSX, already deduped (-2, -3, ...) against every other
@@ -27,6 +28,10 @@ interface Props {
27
28
  color?: string;
28
29
  }
29
30
  const { type = "note", title, _titleId, icon, color } = Astro.props as Props;
31
+ // A JSX title, moved into the `wd-title` slot by lib/mdx-title-anchor-ids.js.
32
+ // Checked by its content: the Note/Info/... wrappers forward the slot even
33
+ // when nothing fills it.
34
+ const titleHtml = Astro.slots.has("wd-title") ? (await Astro.slots.render("wd-title")).trim() : "";
30
35
  const accentStyle = color ? `--wd-callout-accent: ${color}` : undefined;
31
36
  // FontAwesome Solid (fa6-solid, already an installed @iconify-json/*
32
37
  // collection - see astro.config.mjs's own comment on icon() needing no
@@ -49,7 +54,7 @@ function slugify(value: string): string {
49
54
  .replace(/[^a-z0-9]+/g, "-")
50
55
  .replace(/^-+|-+$/g, "");
51
56
  }
52
- const titleId = title ? (_titleId ?? slugify(title)) : undefined;
57
+ const titleId = title ? (_titleId ?? slugify(plainText(title))) : undefined;
53
58
  ---
54
59
 
55
60
  <div class:list={["wd-callout", `wd-callout-${type}`, { "wd-callout-titled": Boolean(title) }, extraClasses(Astro.props)]} style={accentStyle}>
@@ -58,7 +63,7 @@ const titleId = title ? (_titleId ?? slugify(title)) : undefined;
58
63
  {
59
64
  title && (
60
65
  <div class="wd-callout-title" id={titleId}>
61
- {title}
66
+ {titleHtml ? <Fragment set:html={titleHtml} /> : title}
62
67
  <a class="wd-heading-anchor" href={`#${titleId}`} aria-label="Link to this section">
63
68
  #
64
69
  </a>
@@ -38,6 +38,9 @@ interface Props {
38
38
  }
39
39
  const { title, icon, img, method, href, color, horizontal = false, cta, arrow = false } = Astro.props as Props;
40
40
  const iconStyle = color ? `color: ${color}` : undefined;
41
+ // An icon written as markup (an inline <svg>), moved into the `wd-icon` slot
42
+ // by lib/mdx-title-anchor-ids.js.
43
+ const iconHtml = Astro.slots.has('wd-icon') ? (await Astro.slots.render('wd-icon')).trim() : '';
41
44
  const Tag = href ? 'a' : 'div';
42
45
  const KNOWN_METHODS = ['get', 'post', 'put', 'patch', 'delete'];
43
46
  const methodLower = method?.toLowerCase();
@@ -45,7 +48,7 @@ const methodClass = methodLower && KNOWN_METHODS.includes(methodLower) ? methodL
45
48
  ---
46
49
  <Tag class:list={['wd-card', { 'wd-card-horizontal': horizontal, 'wd-card-has-arrow': arrow && href }, extraClasses(Astro.props)]} href={href}>
47
50
  {img && <img src={img} alt="" class="wd-card-image" />}
48
- {!img && <AppIcon icon={icon} class="wd-card-icon" style={iconStyle} />}
51
+ {!img && (iconHtml ? <span class="wd-card-icon" style={iconStyle} set:html={iconHtml} /> : <AppIcon icon={icon} class="wd-card-icon" style={iconStyle} />)}
49
52
  <div class="wd-card-text">
50
53
  <div class="wd-card-title-row">
51
54
  <h3 class="wd-card-title">{title}</h3>
@@ -10,4 +10,4 @@ interface Props {
10
10
  }
11
11
  const { title, _titleId } = Astro.props as Props;
12
12
  ---
13
- <Callout type="check" title={title} _titleId={_titleId} class={Astro.props.class} className={Astro.props.className}><slot /></Callout>
13
+ <Callout type="check" title={title} _titleId={_titleId} class={Astro.props.class} className={Astro.props.className}><slot name="wd-title" slot="wd-title" /><slot /></Callout>
@@ -9,4 +9,4 @@ interface Props {
9
9
  }
10
10
  const { title, _titleId } = Astro.props as Props;
11
11
  ---
12
- <Callout type="danger" title={title} _titleId={_titleId} class={Astro.props.class} className={Astro.props.className}><slot /></Callout>
12
+ <Callout type="danger" title={title} _titleId={_titleId} class={Astro.props.class} className={Astro.props.className}><slot name="wd-title" slot="wd-title" /><slot /></Callout>
@@ -57,8 +57,8 @@ interface Props {
57
57
  // src/scripts/image-zoom.ts) - rendered as a bare `nozoom` attribute
58
58
  // on both <img> tags, the same attribute a raw
59
59
  // `<img nozoom src="..." />` written directly in MDX would carry, so
60
- // one selector in image-zoom.ts handles both cases identically rather
61
- // than needing to special-case this component.
60
+ // lib/image-zoom-rules.js handles both cases identically rather than
61
+ // needing to special-case this component.
62
62
  noZoom?: boolean;
63
63
  }
64
64
  const { src, srcDark, size, alt = "", caption, noZoom } = Astro.props as Props;
@@ -9,4 +9,4 @@ interface Props {
9
9
  }
10
10
  const { title, _titleId } = Astro.props as Props;
11
11
  ---
12
- <Callout type="info" title={title} _titleId={_titleId} class={Astro.props.class} className={Astro.props.className}><slot /></Callout>
12
+ <Callout type="info" title={title} _titleId={_titleId} class={Astro.props.class} className={Astro.props.className}><slot name="wd-title" slot="wd-title" /><slot /></Callout>
@@ -9,4 +9,4 @@ interface Props {
9
9
  }
10
10
  const { title, _titleId } = Astro.props as Props;
11
11
  ---
12
- <Callout type="note" title={title} _titleId={_titleId} class={Astro.props.class} className={Astro.props.className}><slot /></Callout>
12
+ <Callout type="note" title={title} _titleId={_titleId} class={Astro.props.class} className={Astro.props.className}><slot name="wd-title" slot="wd-title" /><slot /></Callout>
@@ -45,11 +45,31 @@ const { defaultTabIndex = 0 } = Astro.props as Props;
45
45
  document.addEventListener('astro:page-load', () => initTabs(document));
46
46
  </script>
47
47
  <style is:global>
48
+ /* A border around the whole component - the tabs and the open tab's
49
+ content - so it's clear where it ends and the page goes on. */
50
+ .wd-tabs {
51
+ margin: 1.25rem 0;
52
+ border: 1px solid var(--wd-border);
53
+ border-radius: 0.6rem;
54
+ }
48
55
  .wd-tabs-nav {
49
56
  display: flex;
57
+ flex-wrap: wrap;
50
58
  gap: 0.25rem;
59
+ padding: 0 0.5rem;
51
60
  border-bottom: 1px solid var(--wd-border);
52
- margin-bottom: 1rem;
61
+ }
62
+ .wd-tab {
63
+ padding: 1rem 1.1rem;
64
+ min-width: 0;
65
+ }
66
+ /* The first thing shown - after the hidden icon a tab with `icon` holds. */
67
+ .wd-tab > :first-child,
68
+ .wd-tab > [hidden]:first-child + * {
69
+ margin-top: 0;
70
+ }
71
+ .wd-tab > :last-child {
72
+ margin-bottom: 0;
53
73
  }
54
74
  .wd-tabs-btn {
55
75
  background: none;
@@ -59,6 +79,8 @@ const { defaultTabIndex = 0 } = Astro.props as Props;
59
79
  font-size: 0.9rem;
60
80
  color: var(--wd-text);
61
81
  border-bottom: 2px solid transparent;
82
+ /* The current tab's underline sits on the row's bottom border. */
83
+ margin-bottom: -1px;
62
84
  }
63
85
  .wd-tabs-btn {
64
86
  display: inline-flex;
@@ -9,4 +9,4 @@ interface Props {
9
9
  }
10
10
  const { title, _titleId } = Astro.props as Props;
11
11
  ---
12
- <Callout type="tip" title={title} _titleId={_titleId} class={Astro.props.class} className={Astro.props.className}><slot /></Callout>
12
+ <Callout type="tip" title={title} _titleId={_titleId} class={Astro.props.class} className={Astro.props.className}><slot name="wd-title" slot="wd-title" /><slot /></Callout>
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  import { extraClasses } from './class-names';
3
+ import { plainText } from '../lib/plain-text.js';
3
4
  // Mintlify's <Update> - one changelog entry: `label` (usually a date or
4
5
  // version) in a left column that sticks while its content scrolls, with
5
6
  // `description` and `tags` under it. The label is a linkable anchor, deduped
@@ -11,7 +12,7 @@ import { extraClasses } from './class-names';
11
12
  // in its right-hand panel. `rss` is accepted but unused: writedocs doesn't
12
13
  // generate an RSS feed from updates.
13
14
  interface Props {
14
- label: string;
15
+ label: string | object;
15
16
  description?: string;
16
17
  tags?: string[];
17
18
  rss?: { title?: string; description?: string };
@@ -24,12 +25,12 @@ function slugify(value: string): string {
24
25
  .replace(/[^a-z0-9]+/g, '-')
25
26
  .replace(/^-+|-+$/g, '');
26
27
  }
27
- const id = _titleId ?? slugify(label);
28
+ const id = _titleId ?? slugify(plainText(label));
28
29
  ---
29
30
  <section class:list={["wd-update", extraClasses(Astro.props)]} data-update-tags={JSON.stringify(tags)}>
30
31
  <div class="wd-update-meta">
31
32
  <div class="wd-update-label" id={id}>
32
- <a href={`#${id}`}>{label}</a>
33
+ <a href={`#${id}`}>{Astro.slots.has('wd-title') ? <slot name="wd-title" /> : label}</a>
33
34
  </div>
34
35
  {description && <div class="wd-update-description">{description}</div>}
35
36
  {tags.length > 0 && (
@@ -9,4 +9,4 @@ interface Props {
9
9
  }
10
10
  const { title, _titleId } = Astro.props as Props;
11
11
  ---
12
- <Callout type="warning" title={title} _titleId={_titleId} class={Astro.props.class} className={Astro.props.className}><slot /></Callout>
12
+ <Callout type="warning" title={title} _titleId={_titleId} class={Astro.props.class} className={Astro.props.className}><slot name="wd-title" slot="wd-title" /><slot /></Callout>
@@ -0,0 +1,20 @@
1
+ // Which page images open in the zoom lightbox (src/scripts/image-zoom.ts).
2
+ // Plain JavaScript, so scripts/image-zoom-rules.test.js can check it.
3
+ //
4
+ // Every image in a page's article zooms, except:
5
+ // - one opted out with `noZoom` (`<img noZoom>`, `<Image noZoom>`) - the
6
+ // DOM sees it as `nozoom`, since attribute names aren't case-sensitive;
7
+ // - a component's own picture - a Card's header image (.wd-card-image), an
8
+ // Icon's image (.wd-icon-image), anything in a Tile's preview
9
+ // (.wd-tile-preview): part of the component, not content to inspect;
10
+ // - an image inside a link (`[![...](...)](/page/)`, `<a><img></a>`, a Tile
11
+ // or Card with `href`) - a click follows the link instead.
12
+
13
+ /** Images that never zoom, as a selector for `closest()`. */
14
+ export const NO_ZOOM_SELECTOR = '[nozoom], .wd-card-image, .wd-icon-image, .wd-tile-preview, a[href]';
15
+
16
+ /** Whether a page image opens in the lightbox. `img` is an <img> element
17
+ * (anything with `closest()`); only images in the article are passed in. */
18
+ export function zoomsOnClick(img) {
19
+ return img.closest(NO_ZOOM_SELECTOR) === null;
20
+ }
@@ -27,6 +27,7 @@
27
27
  //
28
28
  // External links (http:, mailto:, ...) aren't checked.
29
29
  import fs from 'node:fs';
30
+ import { estreeText } from './plain-text.js';
30
31
  import path from 'node:path';
31
32
  import { createRequire } from 'node:module';
32
33
  import { pathToFileURL } from 'node:url';
@@ -108,6 +109,14 @@ function attribute(node, name) {
108
109
  return attr && typeof attr.value === 'string' ? attr.value : null;
109
110
  }
110
111
 
112
+ /** A component's title as text - a JSX title (`title={<><code>X</code> y</>}`)
113
+ * included, the way lib/mdx-title-anchor-ids.js reads it. */
114
+ function titleText(node, name) {
115
+ const attr = node.attributes?.find((a) => a.type === 'mdxJsxAttribute' && a.name === name);
116
+ if (!attr) return null;
117
+ return typeof attr.value === 'string' ? attr.value : estreeText(attr.value?.data?.estree) || null;
118
+ }
119
+
111
120
  /** Everything a page or snippet file links to and can be linked to. */
112
121
  async function scanFile(absPath, { slug, Slugger }) {
113
122
  let raw;
@@ -175,7 +184,7 @@ async function scanFile(absPath, { slug, Slugger }) {
175
184
  const id = attribute(node, 'id');
176
185
  if (id) anchors.add(id);
177
186
  if (TITLED_COMPONENTS.includes(node.name)) {
178
- const title = attribute(node, node.name === 'Update' ? 'label' : 'title');
187
+ const title = titleText(node, node.name === 'Update' ? 'label' : 'title');
179
188
  const base = title ? titleSlug(title) : '';
180
189
  if (base) {
181
190
  const prior = titleSeen.get(base) ?? 0;
@@ -1,4 +1,5 @@
1
1
  import { visit } from 'unist-util-visit';
2
+ import { estreeText } from './plain-text.js';
2
3
 
3
4
  // Every JSX tag name that can carry a `title` prop and render a linkable
4
5
  // heading of its own - the 6 Callout variants remarkInjectBuiltinComponents
@@ -52,12 +53,12 @@ function slugify(value) {
52
53
  * github-slugger itself runs once per document rather than being
53
54
  * reimplemented per-heading.
54
55
  *
55
- * Only handles a literal string `title="..."` - mdast-util-mdx-jsx gives a
56
- * plain JS string for that form's attribute value, vs. an
57
- * mdxJsxAttributeValueExpression node for a dynamic `title={expr}`. Every
58
- * real usage in this codebase passes a plain string; a dynamic one is left
59
- * alone and falls back to that component's own un-deduped slugify(title) -
60
- * same behavior as before this plugin existed.
56
+ * A literal `title="..."` comes as a plain string; `title={expr}` as an
57
+ * mdxJsxAttributeValueExpression, whose estree gives the text of a JSX title
58
+ * (`{<><code>SUCCEEDED</code> status details</>}` -> "SUCCEEDED status
59
+ * details", estreeText() in plain-text.js). An expression with no text of
60
+ * its own (a variable) gets no id here, and the component falls back to
61
+ * its own un-deduped slugify(plainText(title)).
61
62
  *
62
63
  * Scoped per MDX *file*, not per rendered page - a snippet imported into a
63
64
  * page (see docs/dev/docs/snippets.mdx) is its own independently-compiled
@@ -66,18 +67,62 @@ function slugify(value) {
66
67
  * remarkInjectBuiltinComponents' own per-file scope is: there's no single
67
68
  * shared AST spanning both by the time either one's transform runs.
68
69
  */
70
+ /** Whether an estree program holds JSX - a title written as markup, not a
71
+ * plain expression like a variable. */
72
+ function hasJsx(node) {
73
+ if (!node || typeof node !== 'object') return false;
74
+ if (Array.isArray(node)) return node.some(hasJsx);
75
+ if (node.type === 'JSXElement' || node.type === 'JSXFragment') return true;
76
+ return Object.entries(node).some(([key, child]) => key !== 'loc' && key !== 'range' && child && typeof child === 'object' && hasJsx(child));
77
+ }
78
+
79
+ /** A `<span slot="...">` child holding an attribute's JSX expression. */
80
+ function slotChild(slot, expression) {
81
+ return {
82
+ type: 'mdxJsxFlowElement',
83
+ name: 'span',
84
+ attributes: [{ type: 'mdxJsxAttribute', name: 'slot', value: slot }],
85
+ children: [{ type: 'mdxFlowExpression', value: expression.value, data: { estree: expression.data.estree } }],
86
+ };
87
+ }
88
+
69
89
  export function remarkTitleAnchorIds() {
70
90
  return (tree) => {
71
91
  const seen = new Map();
72
92
  visit(tree, ['mdxJsxFlowElement', 'mdxJsxTextElement'], (node) => {
93
+ // A Card's icon written as markup - an inline `<svg>` - moves into a
94
+ // `wd-icon` slot the same way a JSX title does (below), since an
95
+ // .astro component can't print JSX passed as a prop.
96
+ if (node.name === 'Card') {
97
+ const iconAttr = node.attributes?.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'icon');
98
+ const iconTree = iconAttr && typeof iconAttr.value !== 'string' ? iconAttr.value?.data?.estree : null;
99
+ if (iconTree && hasJsx(iconTree)) {
100
+ node.children.unshift(slotChild('wd-icon', iconAttr.value));
101
+ node.attributes = node.attributes.filter((attr) => attr !== iconAttr);
102
+ }
103
+ return;
104
+ }
73
105
  if (!node.name || !TITLED_COMPONENT_NAMES.includes(node.name)) return;
74
106
  const attrName = ANCHOR_ATTRIBUTE[node.name] ?? 'title';
75
107
  const titleAttr = node.attributes?.find(
76
108
  (attr) => attr.type === 'mdxJsxAttribute' && attr.name === attrName
77
109
  );
78
- if (!titleAttr || typeof titleAttr.value !== 'string') return;
79
-
80
- const base = slugify(titleAttr.value);
110
+ if (!titleAttr) return;
111
+ // A JSX title - `title={<><code>SUCCEEDED</code> status details</>}` -
112
+ // gets its id from its text, like a plain one.
113
+ const estree = typeof titleAttr.value === 'string' ? null : titleAttr.value?.data?.estree;
114
+ const text = estree ? estreeText(estree) : typeof titleAttr.value === 'string' ? titleAttr.value : '';
115
+ // An .astro component can't print JSX passed as a prop ("[object
116
+ // Object]"), but it renders a named slot: the JSX moves into a
117
+ // `<span slot="wd-title">` child (the component shows that slot in
118
+ // place of the prop), and the prop becomes its text - for the
119
+ // component's own checks. Not a slot named `title`: Astro drops a
120
+ // prop that has the same name as a slot.
121
+ if (estree && hasJsx(estree)) {
122
+ node.children.unshift(slotChild('wd-title', titleAttr.value));
123
+ titleAttr.value = text;
124
+ }
125
+ const base = slugify(text);
81
126
  if (!base) return;
82
127
  const priorCount = seen.get(base) ?? 0;
83
128
  seen.set(base, priorCount + 1);
@@ -0,0 +1,32 @@
1
+ // The text of a component prop that may be JSX rather than a string -
2
+ // Mintlify allows `title={<><code>SUCCEEDED</code> status details</>}` on an
3
+ // Accordion or a Callout. Used to make an anchor id from such a title.
4
+ // Plain JavaScript, so scripts/plain-text.test.js can check it.
5
+
6
+ /** The text of a rendered prop: a string, a number, an array of them, or a
7
+ * JSX element (its `props.children`, however deep). '' for anything else. */
8
+ export function plainText(value) {
9
+ if (value === null || value === undefined || typeof value === 'boolean') return '';
10
+ if (typeof value === 'string' || typeof value === 'number') return String(value);
11
+ if (Array.isArray(value)) return value.map(plainText).join('');
12
+ if (typeof value === 'object' && value.props) return plainText(value.props.children);
13
+ return '';
14
+ }
15
+
16
+ /** The text of a JSX expression in MDX's syntax tree (an estree program, from
17
+ * an attribute like `title={<>...</>}`): its JSX text and string literals,
18
+ * in order. */
19
+ export function estreeText(node) {
20
+ if (!node || typeof node !== 'object') return '';
21
+ if (Array.isArray(node)) return node.map(estreeText).join('');
22
+ if (node.type === 'JSXText') return node.value;
23
+ if (node.type === 'Literal') return typeof node.value === 'string' || typeof node.value === 'number' ? String(node.value) : '';
24
+ if (node.type === 'TemplateLiteral') return node.quasis.map((q) => q.value.cooked ?? '').join('');
25
+ if (node.type === 'JSXAttribute') return '';
26
+ let text = '';
27
+ for (const [key, child] of Object.entries(node)) {
28
+ if (key === 'loc' || key === 'range' || key === 'position') continue;
29
+ if (child && typeof child === 'object') text += estreeText(child);
30
+ }
31
+ return text;
32
+ }
@@ -1,31 +1,21 @@
1
1
  // Click-to-zoom lightbox for content images - opened by ImageZoom.astro's
2
2
  // own overlay markup, mounted once in BaseLayout.astro alongside
3
3
  // SearchModal. Every <img> inside .wd-article becomes clickable and opens
4
- // a fullscreen view of itself, *except*:
5
- // - Card's own image (.wd-card-image) - a UI element of the card
6
- // itself (its header art), not "content" a reader would want to
7
- // inspect at full size.
8
- // - Icon's own inline image (.wd-icon-image) - a small inline glyph
9
- // sized in em to match surrounding text, not a photo/screenshot.
10
- // - any image explicitly opted out via a `nozoom` attribute - written
11
- // as `<img noZoom src="..." />` in source (Image.astro's own
12
- // `noZoom` prop renders the same attribute - see its own comment),
13
- // but HTML attribute names are ASCII-case-insensitive during
14
- // parsing, so the DOM (and this selector) sees it as `nozoom`
15
- // regardless of how it was cased in source.
16
- // Scoped to .wd-article (not a bare `img` selector) so this never
17
- // touches chrome images - the topbar/sidebar logo, sidebar icons, or
18
- // anything else outside actual page content.
4
+ // a fullscreen view of itself - except the ones lib/image-zoom-rules.js
5
+ // leaves out: `noZoom`, a component's own picture (Card, Icon, Tile), and an
6
+ // image inside a link. Scoped to .wd-article (not a bare `img` selector) so
7
+ // this never touches chrome images - the topbar/sidebar logo, sidebar icons,
8
+ // or anything else outside actual page content.
9
+ import { zoomsOnClick } from '../lib/image-zoom-rules.js';
10
+
19
11
  export function initImageZoom(root: ParentNode) {
20
12
  const overlay = document.querySelector<HTMLElement>('#wd-zoom-overlay');
21
13
  const overlayImg = document.querySelector<HTMLImageElement>('#wd-zoom-image');
22
14
  if (!overlay || !overlayImg) return;
23
15
 
24
- const images = root.querySelectorAll<HTMLImageElement>(
25
- '.wd-article img:not(.wd-card-image):not(.wd-icon-image):not([nozoom])',
26
- );
16
+ const images = root.querySelectorAll<HTMLImageElement>('.wd-article img');
27
17
  images.forEach((img) => {
28
- if (img.dataset.wdInit) return;
18
+ if (img.dataset.wdInit || !zoomsOnClick(img)) return;
29
19
  img.dataset.wdInit = 'true';
30
20
  img.classList.add('wd-zoomable');
31
21
  img.addEventListener('click', () => open(img));