@nulib/canopy 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.
package/lib/build/dev.js CHANGED
@@ -1202,6 +1202,11 @@ async function dev() {
1202
1202
  "[tailwind] compile after UI Sass change failed"
1203
1203
  );
1204
1204
  };
1205
+ // What the UI stylesheet is made of: its Sass, and the plain CSS its compiled
1206
+ // `index.css` imports (`version-parity.css`, ui-styles.js). Never `index.css`
1207
+ // itself, which this writes.
1208
+ const isUiStyleSource = (fn) =>
1209
+ /\.s[ac]ss$/i.test(String(fn)) || /(^|[\\/])version-parity\.css$/i.test(String(fn));
1205
1210
  if (fs.existsSync(uiStylesDir)) {
1206
1211
  try {
1207
1212
  fs.watch(
@@ -1209,7 +1214,7 @@ async function dev() {
1209
1214
  { persistent: false, recursive: true },
1210
1215
  (evt, fn) => {
1211
1216
  try {
1212
- if (fn && /\.s[ac]ss$/i.test(String(fn))) handleUiSassChange();
1217
+ if (fn && isUiStyleSource(fn)) handleUiSassChange();
1213
1218
  } catch (_) {}
1214
1219
  }
1215
1220
  );
@@ -1223,7 +1228,7 @@ async function dev() {
1223
1228
  { persistent: false },
1224
1229
  (evt, fn) => {
1225
1230
  try {
1226
- if (fn && /\.s[ac]ss$/i.test(String(fn))) handleUiSassChange();
1231
+ if (fn && isUiStyleSource(fn)) handleUiSassChange();
1227
1232
  } catch (_) {}
1228
1233
  scan(dir);
1229
1234
  }
package/lib/build/mdx.js CHANGED
@@ -1515,11 +1515,47 @@ async function ensureFacetsRuntime() {
1515
1515
  const entry = `
1516
1516
  function ready(fn){ if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',fn,{once:true}); else fn(); }
1517
1517
  function parseProps(el){ try{ const s=el.querySelector('script[type="application/json"]'); if(s) return JSON.parse(s.textContent||'{}'); }catch(_){ } return {}; }
1518
- function buildSliderProps(iiifContent, options){
1519
- const props = { iiifContent };
1518
+ // Canopy draws each slider's header (makeHeader), so Clover draws only its items, the
1519
+ // list named by the slider's value.
1520
+ function buildSliderProps(iiifContent, options, name){
1521
+ const props = { iiifContent, header: false };
1522
+ if (name) props['aria-label'] = String(name);
1520
1523
  if (options && typeof options === 'object') props.options = options;
1521
1524
  return props;
1522
1525
  }
1526
+ // A slider's header: its value, the link to every work with it on the search page
1527
+ // (with the page's "View all" for words a screen reader hears, 2.4.4), and its facet
1528
+ // under it. Clover's classes, so it looks as Clover's own header did.
1529
+ function makeHeader(value, facet, href, viewAll){
1530
+ try {
1531
+ const header = document.createElement('header');
1532
+ header.className = 'clover-items-header canopy-slider__header';
1533
+ const title = document.createElement('h2');
1534
+ title.className = 'clover-items-title clover-title canopy-slider__title';
1535
+ const link = document.createElement('a');
1536
+ link.className = 'canopy-slider__title-link';
1537
+ link.href = href;
1538
+ link.textContent = String(value);
1539
+ if (viewAll) {
1540
+ const more = document.createElement('span');
1541
+ more.className = 'canopy-slider__more';
1542
+ more.textContent = ', ' + viewAll;
1543
+ link.appendChild(more);
1544
+ }
1545
+ title.appendChild(link);
1546
+ header.appendChild(title);
1547
+ if (facet) {
1548
+ const about = document.createElement('p');
1549
+ about.className = 'clover-items-description';
1550
+ about.textContent = String(facet);
1551
+ header.appendChild(about);
1552
+ }
1553
+ return header;
1554
+ } catch(_) { return null; }
1555
+ }
1556
+ function searchHref(labelSlug, valueSlug){
1557
+ return rootBase() + '/search/index.html?' + encodeURIComponent(labelSlug) + '=' + encodeURIComponent(valueSlug);
1558
+ }
1523
1559
  function rootBase(){
1524
1560
  try {
1525
1561
  var bp = (window && window.CANOPY_BASE_PATH) ? String(window.CANOPY_BASE_PATH) : '';
@@ -1551,6 +1587,7 @@ async function ensureFacetsRuntime() {
1551
1587
  const ver = await getApiVersion();
1552
1588
  const verQ = ver ? ('?v=' + encodeURIComponent(ver)) : '';
1553
1589
  const sliderOptions = (props && typeof props.sliderOptions === 'object') ? props.sliderOptions : null;
1590
+ const viewAll = typeof props.viewAll === 'string' ? props.viewAll : 'View all';
1554
1591
  const res = await fetch(rootBase() + '/api/search/facets.json' + verQ).catch(()=>null);
1555
1592
  if(!res || !res.ok) return;
1556
1593
  const json = await res.json().catch(()=>null);
@@ -1573,7 +1610,9 @@ async function ensureFacetsRuntime() {
1573
1610
  const wrap = document.createElement('div');
1574
1611
  wrap.setAttribute('data-facet-label', entry.label);
1575
1612
  wrap.setAttribute('class', 'canopy-slider');
1576
- const ph = makeSliderPlaceholder(buildSliderProps(rootBase() + '/api/facet/' + (allow.slug) + '/' + pick.valueSlug + '.json' + verQ, sliderOptions));
1613
+ const header = makeHeader(pick.value, entry.label, searchHref(allow.slug, pick.valueSlug), viewAll);
1614
+ if (header) wrap.appendChild(header);
1615
+ const ph = makeSliderPlaceholder(buildSliderProps(rootBase() + '/api/facet/' + (allow.slug) + '/' + pick.valueSlug + '.json' + verQ, sliderOptions, pick.value));
1577
1616
  if (ph) wrap.appendChild(ph);
1578
1617
  el.appendChild(wrap);
1579
1618
  });
@@ -1587,7 +1626,9 @@ async function ensureFacetsRuntime() {
1587
1626
  const wrap = document.createElement('div');
1588
1627
  wrap.setAttribute('data-facet-label', s.label);
1589
1628
  wrap.setAttribute('class', 'canopy-slider');
1590
- const ph = makeSliderPlaceholder(buildSliderProps(rootBase() + '/api/facet/' + s.labelSlug + '/' + s.valueSlug + '.json' + verQ, sliderOptions));
1629
+ const header = makeHeader(s.value, s.label, searchHref(s.labelSlug, s.valueSlug), viewAll);
1630
+ if (header) wrap.appendChild(header);
1631
+ const ph = makeSliderPlaceholder(buildSliderProps(rootBase() + '/api/facet/' + s.labelSlug + '/' + s.valueSlug + '.json' + verQ, sliderOptions, s.value));
1591
1632
  if (ph) wrap.appendChild(ph);
1592
1633
  el.appendChild(wrap);
1593
1634
  });
@@ -7,6 +7,7 @@
7
7
  const fs = require('fs');
8
8
  const path = require('path');
9
9
  const {PACKAGE_NAME, LEGACY_NAMES} = require('./package-names');
10
+ const {DEFAULT_ACCENT, DEFAULT_GRAY} = require('../../ui/theme');
10
11
 
11
12
  // What 1.x sites installed for Canopy and 2.x does without.
12
13
  const LEFT_OVER = [
@@ -24,6 +25,23 @@ function readJson(file) {
24
25
  }
25
26
  }
26
27
 
28
+ // The `theme` a site's `canopy.yml` names, or null with no `canopy.yml` to read.
29
+ function readTheme(root) {
30
+ try {
31
+ const yaml = require('js-yaml');
32
+ const config = yaml.load(fs.readFileSync(path.join(root, 'canopy.yml'), 'utf8')) || {};
33
+ return config.theme && typeof config.theme === 'object' ? config.theme : {};
34
+ } catch (_) {
35
+ return null;
36
+ }
37
+ }
38
+
39
+ // The colors a site that names none takes, and the ones it took before 2.0.2.
40
+ const DEFAULT_COLORS = [
41
+ {key: 'accentColor', now: DEFAULT_ACCENT, before: 'indigo'},
42
+ {key: 'grayColor', now: DEFAULT_GRAY, before: 'slate'},
43
+ ];
44
+
27
45
  // The site's own components that import a package, as paths from the site's root.
28
46
  function filesImporting(root, name) {
29
47
  const found = [];
@@ -67,6 +85,18 @@ function upgradeNotices(root = process.cwd()) {
67
85
  );
68
86
  }
69
87
 
88
+ // A site made before 2.0 that names no colors had indigo on slate; it is gold on sand now.
89
+ const theme = legacy ? readTheme(root) : null;
90
+ const unnamed = theme ? DEFAULT_COLORS.filter(({key}) => !theme[key]) : [];
91
+ if (unnamed.length) {
92
+ const list = (pick, joiner = ' and ') => unnamed.map(pick).join(joiner);
93
+ notes.push(
94
+ `canopy.yml names no ${list(({key}) => key, ' or ')}, so the site takes Canopy's: ` +
95
+ `${list(({now}) => now)} since 2.0.2, where it was ${list(({before}) => before)}. To keep ` +
96
+ `those, set ${list(({key, before}) => `${key}: ${before}`)} under theme in canopy.yml. ${GUIDE}`,
97
+ );
98
+ }
99
+
70
100
  for (const {name, label, why} of LEFT_OVER) {
71
101
  if (!deps[name]) continue;
72
102
  const named = label ? `${name} (${label})` : name;
package/lib/common.js CHANGED
@@ -264,7 +264,7 @@ function resolveThemeAppearance() {
264
264
 
265
265
  function resolveThemeAccent() {
266
266
  if (cachedAccent) return cachedAccent;
267
- cachedAccent = 'indigo';
267
+ cachedAccent = require('../ui/theme').DEFAULT_ACCENT;
268
268
  try {
269
269
  const { loadCanopyTheme } = require('../ui/theme');
270
270
  if (typeof loadCanopyTheme === 'function') {
@@ -448,7 +448,7 @@ function htmlShell({ title, body, cssHref, scriptHref, headExtra, bodyClass, lan
448
448
  const htmlAttrs = [];
449
449
  if (appearance === 'dark') htmlAttrs.push('class="dark"');
450
450
  if (appearance === 'auto') htmlAttrs.push('data-appearance="auto"');
451
- htmlAttrs.push(`data-accent="${accent || 'indigo'}"`);
451
+ htmlAttrs.push(`data-accent="${accent || require('../ui/theme').DEFAULT_ACCENT}"`);
452
452
  const htmlAttr = htmlAttrs.length ? ` ${htmlAttrs.join(' ')}` : '';
453
453
  // `appearance: auto`: inline and ahead of the stylesheet, so the first paint is in the
454
454
  // visitor's appearance (lib/build/appearance.js).
@@ -1,19 +1,15 @@
1
- // The hero carousel (`<Interstitials.Hero />`), after WAI-ARIA APG's "Auto-Rotating
2
- // Image Carousel". Hand-rolled: it shows one slide at a time (the others `hidden`),
3
- // so no slide off screen ever takes focus, and nothing moves but the slide shown.
1
+ // The hero carousel (`<Interstitials.Hero />`), after WAI-ARIA APG's "Carousel".
2
+ // Hand-rolled: it shows one slide at a time (the others `hidden`), so no slide off
3
+ // screen ever takes focus.
4
4
  //
5
- // WCAG 2.2.2 (packages/app/DESIGN.md §0, "Nothing moves on its own without a pause"):
6
- // - the rotation control is first in the carousel's reading order;
7
- // - rotation holds while the pointer is over the carousel, and stops for good when
8
- // keyboard focus enters it, or the visitor uses any of its controls or swipes;
9
- // - it never starts under `prefers-reduced-motion: reduce`;
10
- // - rotation is never announced (`aria-live="off"`); once stopped, the slides are
11
- // polite, so a slide the visitor moves to is announced.
5
+ // Nothing in it moves on its own (WCAG 2.2.2 has nothing to pause): a slide changes
6
+ // only when the visitor moves it, by previous or next, a slide's button, or a swipe.
7
+ // The slides are polite (`aria-live`, Hero.jsx), so the slide a visitor moves to is
8
+ // announced.
12
9
  //
13
10
  // The server renders every slide and control (Hero.jsx), words from `locale.yml`
14
11
  // included; this shows the controls and runs them.
15
12
 
16
- const ROTATE_MS = 6000;
17
13
  const SWIPE_PX = 48;
18
14
 
19
15
  function ready(fn) {
@@ -34,7 +30,6 @@ function initCarousel(host) {
34
30
  if (slides.length <= 1) return;
35
31
 
36
32
  const wrapper = region.querySelector('.canopy-interstitial__slide-wrapper');
37
- const rotation = region.querySelector('.canopy-interstitial__rotation');
38
33
  const nav = region.querySelector('.canopy-interstitial__nav');
39
34
  const prev = region.querySelector('.canopy-interstitial__nav-btn--prev');
40
35
  const next = region.querySelector('.canopy-interstitial__nav-btn--next');
@@ -43,20 +38,10 @@ function initCarousel(host) {
43
38
  ? Array.from(pagination.querySelectorAll('.canopy-interstitial__dot'))
44
39
  : [];
45
40
 
46
- const reduceMotion =
47
- typeof window.matchMedia === 'function'
48
- ? window.matchMedia('(prefers-reduced-motion: reduce)')
49
- : null;
50
-
51
41
  let current = Math.max(
52
42
  0,
53
43
  slides.findIndex((slide) => !slide.hidden),
54
44
  );
55
- // Stopped for good: by the rotation control, any other control, keyboard focus, or
56
- // the visitor's motion preference. Held: while the pointer is over the carousel.
57
- let stopped = Boolean(reduceMotion && reduceMotion.matches);
58
- let held = false;
59
- let timer = null;
60
45
 
61
46
  function preload(index) {
62
47
  const slide = slides[(index + slides.length) % slides.length];
@@ -77,79 +62,13 @@ function initCarousel(host) {
77
62
  preload(current + 1);
78
63
  }
79
64
 
80
- function rotating() {
81
- return !stopped && !held;
82
- }
83
-
84
- function update() {
85
- if (wrapper) wrapper.setAttribute('aria-live', stopped ? 'polite' : 'off');
86
- if (rotation) {
87
- const label = stopped
88
- ? rotation.getAttribute('data-label-start')
89
- : rotation.getAttribute('data-label-stop');
90
- if (label) rotation.setAttribute('aria-label', label);
91
- rotation.setAttribute('data-rotation', stopped ? 'off' : 'on');
92
- }
93
- clearTimeout(timer);
94
- timer = null;
95
- if (rotating()) {
96
- timer = setTimeout(() => {
97
- show(current + 1);
98
- update();
99
- }, ROTATE_MS);
100
- }
101
- }
102
-
103
- function stop() {
104
- if (stopped) return;
105
- stopped = true;
106
- update();
107
- }
108
-
109
- // A visitor's move: rotation stops for good, then the slide changes, so the slides
110
- // are already polite when it does and the new one is announced.
111
- function go(index) {
112
- stop();
113
- show(index);
114
- }
115
-
116
- [rotation, nav, pagination].forEach((el) => {
65
+ [nav, pagination].forEach((el) => {
117
66
  if (el) el.hidden = false;
118
67
  });
119
68
 
120
- if (rotation) {
121
- rotation.addEventListener('click', () => {
122
- stopped = !stopped;
123
- // Started from its own control, rotation runs even with the pointer still on it.
124
- if (!stopped) held = false;
125
- update();
126
- });
127
- }
128
- if (prev) prev.addEventListener('click', () => go(current - 1));
129
- if (next) next.addEventListener('click', () => go(current + 1));
130
- dots.forEach((dot, i) => dot.addEventListener('click', () => go(i)));
131
-
132
- region.addEventListener('pointerenter', (event) => {
133
- if (event.pointerType !== 'mouse') return;
134
- held = true;
135
- update();
136
- });
137
- region.addEventListener('pointerleave', (event) => {
138
- if (event.pointerType !== 'mouse') return;
139
- held = false;
140
- update();
141
- });
142
-
143
- // Keyboard focus stops it for good; a click's focus does not, so a pointer can still
144
- // start and pause it with its own control.
145
- region.addEventListener('focusin', (event) => {
146
- const target = event.target;
147
- let visible = true;
148
- try {
149
- visible = target.matches(':focus-visible');
150
- } catch (_) {}
151
- if (visible) stop();
152
- });
69
+ if (prev) prev.addEventListener('click', () => show(current - 1));
70
+ if (next) next.addEventListener('click', () => show(current + 1));
71
+ dots.forEach((dot, i) => dot.addEventListener('click', () => show(i)));
153
72
 
154
73
  // A swipe across the slide, by touch or pen, moves to the slide beside it. The
155
74
  // buttons are its single-pointer alternative (2.5.1, 2.5.7).
@@ -165,26 +84,14 @@ function initCarousel(host) {
165
84
  const dy = event.clientY - start.y;
166
85
  start = null;
167
86
  if (Math.abs(dx) < SWIPE_PX || Math.abs(dx) <= Math.abs(dy)) return;
168
- go(dx < 0 ? current + 1 : current - 1);
87
+ show(dx < 0 ? current + 1 : current - 1);
169
88
  });
170
89
  wrapper.addEventListener('pointercancel', () => {
171
90
  start = null;
172
91
  });
173
92
  }
174
93
 
175
- if (reduceMotion) {
176
- const onChange = () => {
177
- if (reduceMotion.matches) stop();
178
- };
179
- if (typeof reduceMotion.addEventListener === 'function') {
180
- reduceMotion.addEventListener('change', onChange);
181
- } else if (typeof reduceMotion.addListener === 'function') {
182
- reduceMotion.addListener(onChange);
183
- }
184
- }
185
-
186
94
  show(current);
187
- update();
188
95
  }
189
96
 
190
97
  function observeHosts() {
@@ -81,7 +81,57 @@ function mountAll(selector, key) {
81
81
  } catch (_) {}
82
82
  }
83
83
 
84
+ /*
85
+ * A work page's viewer (`.canopy-work--layout`, a site's `content/works/_layout.mdx`): a
86
+ * toggle at its top corner spreads it across the column, the work's words stacked under
87
+ * it, and back. A toggle button (`aria-pressed`) named in the page's words (the Viewer's
88
+ * `data-canopy-viewer-widen`, `common.actions.widen_viewer`), its name the same either
89
+ * way. The visitor's choice holds for the next work they open, where the browser keeps it.
90
+ * Its look, and where it shows, are `ui/styles/components/_work.scss`.
91
+ */
92
+ const WORK_VIEWER_KEY = 'canopy:work-viewer';
93
+ const WIDEN_ICONS =
94
+ '<svg class="canopy-work__widen-icon canopy-work__widen-icon--widen" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3 12h18M7 8l-4 4 4 4M17 8l4 4-4 4"/></svg>' +
95
+ '<svg class="canopy-work__widen-icon canopy-work__widen-icon--narrow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3 8l4 4-4 4M21 8l-4 4 4 4M10 12h4"/></svg>';
96
+
97
+ function setupWorkLayouts() {
98
+ document.querySelectorAll('.canopy-work--layout').forEach((layout) => {
99
+ try {
100
+ const primary = layout.querySelector(':scope > .canopy-work--primary');
101
+ const viewer = primary && primary.querySelector('[data-canopy-viewer]');
102
+ if (!viewer || primary.querySelector(':scope > .canopy-work__widen')) return;
103
+ const button = document.createElement('button');
104
+ button.type = 'button';
105
+ button.className = 'canopy-work__widen';
106
+ button.setAttribute('aria-label', viewer.getAttribute('data-canopy-viewer-widen') || 'Widen the viewer');
107
+ button.innerHTML = WIDEN_ICONS;
108
+ let wide = false;
109
+ try {
110
+ wide = window.localStorage.getItem(WORK_VIEWER_KEY) === 'wide';
111
+ } catch (_) {}
112
+ const apply = (next) => {
113
+ wide = next;
114
+ layout.setAttribute('data-viewer', wide ? 'wide' : 'split');
115
+ button.setAttribute('aria-pressed', wide ? 'true' : 'false');
116
+ // The viewer's canvas fits itself to its new width.
117
+ try {
118
+ window.dispatchEvent(new Event('resize'));
119
+ } catch (_) {}
120
+ };
121
+ button.addEventListener('click', () => {
122
+ apply(!wide);
123
+ try {
124
+ window.localStorage.setItem(WORK_VIEWER_KEY, wide ? 'wide' : 'split');
125
+ } catch (_) {}
126
+ });
127
+ primary.insertBefore(button, primary.firstChild);
128
+ apply(wide);
129
+ } catch (_) {}
130
+ });
131
+ }
132
+
84
133
  ready(() => {
134
+ setupWorkLayouts();
85
135
  mountAll('[data-canopy-viewer]', 'viewer');
86
136
  mountAll('[data-canopy-scroll]', 'scroll');
87
137
  mountAll('[data-canopy-image]', 'image');
@@ -17,6 +17,8 @@ module.exports = {
17
17
  show: 'Show',
18
18
  hide: 'Hide',
19
19
  view_work: 'View work',
20
+ view_all: 'View all',
21
+ widen_viewer: 'Widen the viewer',
20
22
  copy: 'Copy'
21
23
  },
22
24
  nouns: {
@@ -105,9 +107,7 @@ module.exports = {
105
107
  slide: '{index} of {total}',
106
108
  previous: 'Previous slide',
107
109
  next: 'Next slide',
108
- go_to: 'Go to slide {index}',
109
- stop: 'Pause the slideshow',
110
- start: 'Play the slideshow'
110
+ go_to: 'Go to slide {index}'
111
111
  }
112
112
  }
113
113
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nulib/canopy",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "private": false,
5
5
  "description": "Canopy builds a static site for discovering and telling stories with IIIF collections, from Markdown and MDX.",
6
6
  "license": "MIT",
package/ui/dist/index.mjs CHANGED
@@ -43,6 +43,8 @@ var require_default_locale = __commonJS({
43
43
  show: "Show",
44
44
  hide: "Hide",
45
45
  view_work: "View work",
46
+ view_all: "View all",
47
+ widen_viewer: "Widen the viewer",
46
48
  copy: "Copy"
47
49
  },
48
50
  nouns: {
@@ -131,9 +133,7 @@ var require_default_locale = __commonJS({
131
133
  slide: "{index} of {total}",
132
134
  previous: "Previous slide",
133
135
  next: "Next slide",
134
- go_to: "Go to slide {index}",
135
- stop: "Pause the slideshow",
136
- start: "Play the slideshow"
136
+ go_to: "Go to slide {index}"
137
137
  }
138
138
  }
139
139
  };
@@ -1716,6 +1716,80 @@ function HeaderScript() {
1716
1716
 
1717
1717
  ready(trackHeaderHeight);
1718
1718
 
1719
+ // The search at desktop widths: a button that opens into the field, the field gone back
1720
+ // into the button when it is left empty. Run as the header is read, so the field never
1721
+ // shows closed-to-open on load; without this script the field shows (the markup's own).
1722
+ // - The button says it is a disclosure (aria-expanded, aria-controls); opening it puts
1723
+ // focus in the field.
1724
+ // - Escape closes the suggestions first (the field's own script), then the field, and
1725
+ // focus goes back to the button. Leaving it empty, by Tab or a click, closes it too.
1726
+ // - The shortcut (Cmd or Ctrl K) opens it before the field's script focuses it.
1727
+ // - On the search page the field is the page's own, driving its results, so it stays
1728
+ // open there, with no button.
1729
+ function setupDesktopSearch() {
1730
+ var box = doc.querySelector('.canopy-header [data-canopy-header-search]');
1731
+ if (!box) return;
1732
+ var toggle = box.querySelector('.canopy-header__search-toggle');
1733
+ var input = box.querySelector('[data-canopy-search-form-input]');
1734
+ if (!toggle || !input) return;
1735
+
1736
+ function isOpen() {
1737
+ return box.getAttribute('data-expanded') === 'true';
1738
+ }
1739
+ function setOpen(open, focusTarget) {
1740
+ box.setAttribute('data-expanded', open ? 'true' : 'false');
1741
+ toggle.setAttribute('aria-expanded', open ? 'true' : 'false');
1742
+ if (focusTarget && focusTarget.focus) {
1743
+ try { focusTarget.focus(); } catch (_) {}
1744
+ }
1745
+ }
1746
+ function suggesting() {
1747
+ var teaser = box.querySelector('.canopy-search-teaser');
1748
+ return !!(teaser && !teaser.hidden && !teaser.classList.contains('is-empty'));
1749
+ }
1750
+ function onSearchPage() {
1751
+ try {
1752
+ if (window.CanopySearchPage) return true;
1753
+ return /\\/search(\\/index\\.html)?\\/?$/.test(String(window.location.pathname || ''));
1754
+ } catch (_) {
1755
+ return false;
1756
+ }
1757
+ }
1758
+
1759
+ if (onSearchPage()) return;
1760
+ toggle.hidden = false;
1761
+ box.setAttribute('data-canopy-header-search', 'ready');
1762
+ setOpen(Boolean(input.value));
1763
+
1764
+ toggle.addEventListener('click', function () {
1765
+ setOpen(true, input);
1766
+ });
1767
+
1768
+ box.addEventListener('keydown', function (event) {
1769
+ if (event.key !== 'Escape' || !isOpen() || suggesting()) return;
1770
+ event.preventDefault();
1771
+ setOpen(false, toggle);
1772
+ }, true);
1773
+
1774
+ box.addEventListener('focusout', function () {
1775
+ setTimeout(function () {
1776
+ if (!isOpen() || input.value || box.contains(doc.activeElement)) return;
1777
+ setOpen(false);
1778
+ }, 0);
1779
+ });
1780
+
1781
+ doc.addEventListener('keydown', function (event) {
1782
+ if (!(event.metaKey || event.ctrlKey) || (event.key !== 'k' && event.key !== 'K')) return;
1783
+ if (isOpen()) return;
1784
+ try {
1785
+ if (!window.matchMedia(desktopBreakpointQuery()).matches) return;
1786
+ } catch (_) {}
1787
+ setOpen(true);
1788
+ }, true);
1789
+ }
1790
+
1791
+ setupDesktopSearch();
1792
+
1719
1793
  ready(function () {
1720
1794
  var header = doc.querySelector('.canopy-header');
1721
1795
  if (!header) return;
@@ -2119,6 +2193,7 @@ function CanopyHeader(props = {}) {
2119
2193
  const contextNavigation = context && context.navigation ? context.navigation : null;
2120
2194
  const contextSite = context && context.site ? context.site : null;
2121
2195
  const pageData = context && context.page ? context.page : null;
2196
+ const isSearchPage = Boolean(pageData && pageData.type === "search");
2122
2197
  const contextSiteTitle = contextSite && typeof contextSite.title === "string" ? contextSite.title.trim() : "";
2123
2198
  const siteLanguageToggle = contextSite && contextSite.languageToggle ? contextSite.languageToggle : null;
2124
2199
  const siteRoutes = contextSite && contextSite.routes ? contextSite.routes : null;
@@ -2204,15 +2279,61 @@ function CanopyHeader(props = {}) {
2204
2279
  Logo: SiteLogo
2205
2280
  }
2206
2281
  )),
2207
- /* @__PURE__ */ React22.createElement("div", { className: "canopy-header__desktop-search" }, /* @__PURE__ */ React22.createElement(
2208
- SearchPanel,
2282
+ /* @__PURE__ */ React22.createElement(
2283
+ "div",
2209
2284
  {
2210
- label: resolvedSearchLabel,
2211
- hotkey: searchHotkey,
2212
- placeholder: resolvedSearchPlaceholder,
2213
- searchPath: normalizedSearchRoute
2214
- }
2215
- )),
2285
+ className: "canopy-header__desktop-search",
2286
+ "data-canopy-header-search": isSearchPage ? void 0 : "",
2287
+ "data-expanded": "true"
2288
+ },
2289
+ isSearchPage ? null : /* @__PURE__ */ React22.createElement(
2290
+ "button",
2291
+ {
2292
+ type: "button",
2293
+ className: "canopy-header__search-toggle",
2294
+ "aria-expanded": "true",
2295
+ "aria-controls": "canopy-header-search-field",
2296
+ hidden: true
2297
+ },
2298
+ /* @__PURE__ */ React22.createElement(
2299
+ "svg",
2300
+ {
2301
+ xmlns: "http://www.w3.org/2000/svg",
2302
+ viewBox: "0 0 24 24",
2303
+ fill: "none",
2304
+ stroke: "currentColor",
2305
+ strokeWidth: "1.75",
2306
+ "aria-hidden": "true",
2307
+ focusable: "false"
2308
+ },
2309
+ /* @__PURE__ */ React22.createElement(
2310
+ "path",
2311
+ {
2312
+ strokeLinecap: "round",
2313
+ strokeLinejoin: "round",
2314
+ d: "m21 21-3.8-3.8M10.5 18a7.5 7.5 0 1 1 0-15 7.5 7.5 0 0 1 0 15Z"
2315
+ }
2316
+ )
2317
+ ),
2318
+ /* @__PURE__ */ React22.createElement("span", null, resolvedSearchLabel)
2319
+ ),
2320
+ /* @__PURE__ */ React22.createElement(
2321
+ "div",
2322
+ {
2323
+ id: "canopy-header-search-field",
2324
+ className: "canopy-header__search-field"
2325
+ },
2326
+ /* @__PURE__ */ React22.createElement(
2327
+ SearchPanel,
2328
+ {
2329
+ label: resolvedSearchLabel,
2330
+ hotkey: searchHotkey,
2331
+ placeholder: resolvedSearchPlaceholder,
2332
+ searchPath: normalizedSearchRoute
2333
+ }
2334
+ )
2335
+ )
2336
+ ),
2216
2337
  /* @__PURE__ */ React22.createElement(
2217
2338
  "nav",
2218
2339
  {
@@ -2828,6 +2949,7 @@ function deepMerge(base, override) {
2828
2949
  }
2829
2950
  var Viewer = (props) => {
2830
2951
  const [CloverViewer, setCloverViewer] = useState2(null);
2952
+ const { getString } = useLocale();
2831
2953
  const mergedOptions = deepMerge(
2832
2954
  DEFAULT_VIEWER_OPTIONS,
2833
2955
  props && props.options
@@ -2867,13 +2989,23 @@ var Viewer = (props) => {
2867
2989
  }
2868
2990
  return (
2869
2991
  // `clover-viewer`, Clover 3's root, for a site's 1.x styles (`version-parity.css`).
2870
- /* @__PURE__ */ React28.createElement("div", { "data-canopy-viewer": "1", className: "not-prose clover-viewer" }, /* @__PURE__ */ React28.createElement(
2871
- "script",
2992
+ // On a work page the viewer runtime adds a toggle beside it, named in the page's
2993
+ // words (`viewer-runtime-entry.js`).
2994
+ /* @__PURE__ */ React28.createElement(
2995
+ "div",
2872
2996
  {
2873
- type: "application/json",
2874
- dangerouslySetInnerHTML: { __html: json }
2875
- }
2876
- ))
2997
+ "data-canopy-viewer": "1",
2998
+ "data-canopy-viewer-widen": getString("common.actions.widen_viewer", "Widen the viewer"),
2999
+ className: "not-prose clover-viewer"
3000
+ },
3001
+ /* @__PURE__ */ React28.createElement(
3002
+ "script",
3003
+ {
3004
+ type: "application/json",
3005
+ dangerouslySetInnerHTML: { __html: json }
3006
+ }
3007
+ )
3008
+ )
2877
3009
  );
2878
3010
  }
2879
3011
  return /* @__PURE__ */ React28.createElement(CloverViewer, { ...props, options: mergedOptions });
@@ -3517,9 +3649,13 @@ function Id({ title = "IIIF Manifest", id, ...props }) {
3517
3649
  // ui/src/iiif/MdxRelatedItems.jsx
3518
3650
  import React34 from "react";
3519
3651
  function MdxRelatedItems(props) {
3652
+ const { getString } = useLocale();
3520
3653
  let json = "{}";
3521
3654
  try {
3522
- json = JSON.stringify(props || {});
3655
+ json = JSON.stringify({
3656
+ ...props || {},
3657
+ viewAll: getString("common.actions.view_all", "View all")
3658
+ });
3523
3659
  } catch (_) {
3524
3660
  json = "{}";
3525
3661
  }