@nulib/canopy 0.0.0 → 2.0.0
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/bin/canopy.js +16 -0
- package/lib/AGENTS.md +107 -0
- package/lib/base-path.js +67 -0
- package/lib/build/appearance.js +76 -0
- package/lib/build/assets.js +30 -0
- package/lib/build/build.js +350 -0
- package/lib/build/dev.js +1355 -0
- package/lib/build/devtoast.config.json +6 -0
- package/lib/build/devtoast.css +14 -0
- package/lib/build/facets.js +19 -0
- package/lib/build/fonts.js +105 -0
- package/lib/build/iiif.js +2990 -0
- package/lib/build/log.js +31 -0
- package/lib/build/mdx.js +1967 -0
- package/lib/build/package-names.js +111 -0
- package/lib/build/pages.js +420 -0
- package/lib/build/rehype-task-list-labels.js +54 -0
- package/lib/build/runtimes.js +141 -0
- package/lib/build/search-index.js +55 -0
- package/lib/build/search-text.js +160 -0
- package/lib/build/search-workflow.js +72 -0
- package/lib/build/search.js +302 -0
- package/lib/build/sitemap.js +197 -0
- package/lib/build/styles.js +140 -0
- package/lib/build/theme-tokens.js +78 -0
- package/lib/build/ui-styles.js +25 -0
- package/lib/build/upgrade-notices.js +121 -0
- package/lib/cli.js +64 -0
- package/lib/common.js +580 -0
- package/lib/components/bibliography.js +197 -0
- package/lib/components/featured.js +237 -0
- package/lib/components/hero-slider-runtime.js +215 -0
- package/lib/components/image-story-runtime-entry.js +249 -0
- package/lib/components/map-runtime.js +114 -0
- package/lib/components/metadata-index.js +32 -0
- package/lib/components/nav-place.js +227 -0
- package/lib/components/navigation.js +381 -0
- package/lib/components/referenced.js +217 -0
- package/lib/components/slider-runtime-entry.js +106 -0
- package/lib/components/timeline-runtime.js +80 -0
- package/lib/components/viewer-runtime-entry.js +88 -0
- package/lib/config-path.js +78 -0
- package/lib/default-locale.js +113 -0
- package/lib/discovery/browser-loader.js +107 -0
- package/lib/discovery/browser.js +115 -0
- package/lib/discovery/config.js +25 -0
- package/lib/discovery/envelope.js +124 -0
- package/lib/discovery/export.js +226 -0
- package/lib/discovery/ingestion.js +62 -0
- package/lib/discovery/pagination.js +66 -0
- package/lib/discovery/provenance.js +79 -0
- package/lib/discovery/search.js +81 -0
- package/lib/discovery/tools.js +155 -0
- package/lib/discovery/validation.js +121 -0
- package/lib/head.js +154 -0
- package/lib/iiif/thumbnail.js +402 -0
- package/lib/index.js +9 -0
- package/lib/locale-runtime.js +69 -0
- package/lib/locales.js +203 -0
- package/lib/orchestrator.js +231 -0
- package/lib/page-context.js +24 -0
- package/lib/search/bundle.js +25 -0
- package/lib/search/data.js +202 -0
- package/lib/search/engine.js +86 -0
- package/lib/search/index-cache.js +95 -0
- package/lib/search/search-app.jsx +835 -0
- package/lib/search/search-engine-runtime.js +44 -0
- package/lib/search/search-form-runtime.js +462 -0
- package/lib/search/search.js +676 -0
- package/package.json +109 -3
- package/types/base-path.d.ts +4 -0
- package/types/orchestrator.d.ts +17 -0
- package/ui/dist/index.mjs +7358 -0
- package/ui/dist/index.mjs.map +7 -0
- package/ui/dist/server.mjs +12731 -0
- package/ui/dist/server.mjs.map +7 -0
- package/ui/fonts/OFL.txt +98 -0
- package/ui/fonts/google-sans-flex-latin-ext.woff2 +0 -0
- package/ui/fonts/google-sans-flex-latin.woff2 +0 -0
- package/ui/fonts/source-serif-4-italic-latin-ext.woff2 +0 -0
- package/ui/fonts/source-serif-4-italic-latin.woff2 +0 -0
- package/ui/fonts/source-serif-4-latin-ext.woff2 +0 -0
- package/ui/fonts/source-serif-4-latin.woff2 +0 -0
- package/ui/styles/base/_common.scss +97 -0
- package/ui/styles/base/_heading.scss +61 -0
- package/ui/styles/base/_markdown.scss +188 -0
- package/ui/styles/base/_type.scss +51 -0
- package/ui/styles/base/_utilities.scss +7 -0
- package/ui/styles/base/index.scss +5 -0
- package/ui/styles/components/_article-card.scss +108 -0
- package/ui/styles/components/_band.scss +104 -0
- package/ui/styles/components/_bibliography.scss +88 -0
- package/ui/styles/components/_buttons.scss +143 -0
- package/ui/styles/components/_card.scss +109 -0
- package/ui/styles/components/_diagram.scss +76 -0
- package/ui/styles/components/_feature.scss +66 -0
- package/ui/styles/components/_footer.scss +136 -0
- package/ui/styles/components/_gallery.scss +476 -0
- package/ui/styles/components/_image-story.scss +56 -0
- package/ui/styles/components/_interstitial-hero.scss +625 -0
- package/ui/styles/components/_layout.scss +83 -0
- package/ui/styles/components/_map.scss +296 -0
- package/ui/styles/components/_metadata-index.scss +68 -0
- package/ui/styles/components/_nav-tree.scss +80 -0
- package/ui/styles/components/_referenced-items.scss +69 -0
- package/ui/styles/components/_sub-navigation.scss +208 -0
- package/ui/styles/components/_swoosh.scss +50 -0
- package/ui/styles/components/_timeline.scss +350 -0
- package/ui/styles/components/_work.scss +71 -0
- package/ui/styles/components/header/_header.scss +294 -0
- package/ui/styles/components/header/_logo.scss +99 -0
- package/ui/styles/components/header/_navbar.scss +143 -0
- package/ui/styles/components/header/index.scss +3 -0
- package/ui/styles/components/iiif/_image.scss +32 -0
- package/ui/styles/components/iiif/_slider.scss +5 -0
- package/ui/styles/components/iiif/index.scss +2 -0
- package/ui/styles/components/index.scss +25 -0
- package/ui/styles/components/modal/_modal.scss +130 -0
- package/ui/styles/components/modal/index.scss +1 -0
- package/ui/styles/components/search/_filters.scss +259 -0
- package/ui/styles/components/search/_form.scss +187 -0
- package/ui/styles/components/search/_panel.scss +7 -0
- package/ui/styles/components/search/_results.scss +241 -0
- package/ui/styles/components/search/_tabs.scss +60 -0
- package/ui/styles/components/search/index.scss +4 -0
- package/ui/styles/index.css +5007 -0
- package/ui/styles/index.scss +11 -0
- package/ui/styles/settings/_breakpoints.scss +7 -0
- package/ui/styles/settings/_focus.scss +15 -0
- package/ui/styles/settings/_tokens.scss +170 -0
- package/ui/styles/settings/_type.scss +126 -0
- package/ui/styles/version-parity.css +116 -0
- package/ui/tailwind-canopy-iiif-plugin.js +39 -0
- package/ui/tailwind-canopy-iiif-preset.js +32 -0
- package/ui/tailwind-config.d.ts +29 -0
- package/ui/tailwind-config.js +159 -0
- package/ui/tailwind-default.config.mjs +4 -0
- package/ui/theme-color.js +130 -0
- package/ui/theme-palette.js +337 -0
- package/ui/theme.js +153 -0
- package/README.md +0 -3
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const {
|
|
4
|
+
CONTENT_DIR,
|
|
5
|
+
rootRelativeHref,
|
|
6
|
+
ensureDirSync,
|
|
7
|
+
} = require('../common');
|
|
8
|
+
const mdx = require('../build/mdx.js');
|
|
9
|
+
const {fromMarkdown} = require('mdast-util-from-markdown');
|
|
10
|
+
const {gfmFootnote} = require('micromark-extension-gfm-footnote');
|
|
11
|
+
const {gfmFootnoteFromMarkdown} = require('mdast-util-gfm-footnote');
|
|
12
|
+
const {toString} = require('mdast-util-to-string');
|
|
13
|
+
const {toHast} = require('mdast-util-to-hast');
|
|
14
|
+
const {toHtml} = require('hast-util-to-html');
|
|
15
|
+
|
|
16
|
+
const CACHE_FILE = path.resolve('.cache', 'bibliography.json');
|
|
17
|
+
|
|
18
|
+
let bibliographyEntries = null;
|
|
19
|
+
let bibliographyBuilt = false;
|
|
20
|
+
|
|
21
|
+
function isReservedContentFile(filePath) {
|
|
22
|
+
if (mdx && typeof mdx.isReservedFile === 'function') {
|
|
23
|
+
return mdx.isReservedFile(filePath);
|
|
24
|
+
}
|
|
25
|
+
const base = path.basename(filePath);
|
|
26
|
+
return base.startsWith('_');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function normalizeHtmlFromChildren(children) {
|
|
30
|
+
if (!Array.isArray(children) || !children.length) return '';
|
|
31
|
+
const hast = toHast(
|
|
32
|
+
{
|
|
33
|
+
type: 'root',
|
|
34
|
+
children,
|
|
35
|
+
},
|
|
36
|
+
{allowDangerousHtml: true}
|
|
37
|
+
);
|
|
38
|
+
try {
|
|
39
|
+
return toHtml(hast, {allowDangerousHtml: true});
|
|
40
|
+
} catch (_) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function collectFootnotesFromSource(source) {
|
|
46
|
+
if (!source) return [];
|
|
47
|
+
const parsed = mdx.parseFrontmatter ? mdx.parseFrontmatter(source) : {content: source};
|
|
48
|
+
const content = parsed && typeof parsed.content === 'string' ? parsed.content : '';
|
|
49
|
+
if (!content.trim()) return [];
|
|
50
|
+
const tree = fromMarkdown(content, {
|
|
51
|
+
extensions: [gfmFootnote()],
|
|
52
|
+
mdastExtensions: [gfmFootnoteFromMarkdown()],
|
|
53
|
+
});
|
|
54
|
+
const results = [];
|
|
55
|
+
const visit = (node) => {
|
|
56
|
+
if (!node || typeof node !== 'object') return;
|
|
57
|
+
if (node.type === 'footnoteDefinition') {
|
|
58
|
+
const identifier = node.identifier || node.label || String(results.length + 1);
|
|
59
|
+
const text = toString(node).trim();
|
|
60
|
+
const html = normalizeHtmlFromChildren(node.children || []);
|
|
61
|
+
if (text || html) {
|
|
62
|
+
results.push({
|
|
63
|
+
identifier: String(identifier || results.length + 1),
|
|
64
|
+
text,
|
|
65
|
+
html,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(node.children)) {
|
|
71
|
+
node.children.forEach(visit);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
visit(tree);
|
|
75
|
+
return results;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function readPageFootnotes(filePath) {
|
|
79
|
+
let raw = '';
|
|
80
|
+
try {
|
|
81
|
+
raw = fs.readFileSync(filePath, 'utf8');
|
|
82
|
+
} catch (_) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const footnotes = collectFootnotesFromSource(raw);
|
|
86
|
+
if (!footnotes.length) return null;
|
|
87
|
+
const frontmatter = mdx.parseFrontmatter ? mdx.parseFrontmatter(raw) : {data: null};
|
|
88
|
+
const data = frontmatter && frontmatter.data ? frontmatter.data : null;
|
|
89
|
+
let title = '';
|
|
90
|
+
if (data && typeof data.title === 'string' && data.title.trim()) {
|
|
91
|
+
title = data.title.trim();
|
|
92
|
+
} else if (typeof mdx.extractTitle === 'function') {
|
|
93
|
+
title = mdx.extractTitle(raw);
|
|
94
|
+
}
|
|
95
|
+
const rel = path.relative(CONTENT_DIR, filePath).replace(/\\/g, '/');
|
|
96
|
+
const href = rootRelativeHref(rel.replace(/\.mdx$/i, '.html'));
|
|
97
|
+
return {
|
|
98
|
+
title,
|
|
99
|
+
href,
|
|
100
|
+
relativePath: rel,
|
|
101
|
+
footnotes,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function sortBibliography(entries) {
|
|
106
|
+
return entries.sort((a, b) => {
|
|
107
|
+
const titleA = (a && a.title) || '';
|
|
108
|
+
const titleB = (b && b.title) || '';
|
|
109
|
+
if (titleA && titleB) {
|
|
110
|
+
const cmp = titleA.localeCompare(titleB);
|
|
111
|
+
if (cmp !== 0) return cmp;
|
|
112
|
+
}
|
|
113
|
+
const hrefA = (a && a.href) || '';
|
|
114
|
+
const hrefB = (b && b.href) || '';
|
|
115
|
+
return hrefA.localeCompare(hrefB);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function walkContentDir(dir, entries) {
|
|
120
|
+
let dirents = [];
|
|
121
|
+
try {
|
|
122
|
+
dirents = fs.readdirSync(dir, {withFileTypes: true});
|
|
123
|
+
} catch (_) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
for (const dirent of dirents) {
|
|
127
|
+
if (!dirent) continue;
|
|
128
|
+
const name = dirent.name || '';
|
|
129
|
+
if (!name || name.startsWith('.')) continue;
|
|
130
|
+
const absPath = path.join(dir, name);
|
|
131
|
+
if (dirent.isDirectory()) {
|
|
132
|
+
if (name.startsWith('_')) continue;
|
|
133
|
+
walkContentDir(absPath, entries);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (!dirent.isFile() || !/\.mdx$/i.test(name)) continue;
|
|
137
|
+
if (isReservedContentFile(absPath)) continue;
|
|
138
|
+
const record = readPageFootnotes(absPath);
|
|
139
|
+
if (record) entries.push(record);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function writeCache(entries) {
|
|
144
|
+
try {
|
|
145
|
+
ensureDirSync(path.dirname(CACHE_FILE));
|
|
146
|
+
fs.writeFileSync(CACHE_FILE, JSON.stringify(entries, null, 2), 'utf8');
|
|
147
|
+
} catch (_) {}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function readCache() {
|
|
151
|
+
try {
|
|
152
|
+
if (!fs.existsSync(CACHE_FILE)) return null;
|
|
153
|
+
const raw = fs.readFileSync(CACHE_FILE, 'utf8');
|
|
154
|
+
const parsed = JSON.parse(raw);
|
|
155
|
+
if (Array.isArray(parsed)) return parsed;
|
|
156
|
+
} catch (_) {}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function buildBibliographyIndexSync() {
|
|
161
|
+
if (!fs.existsSync(CONTENT_DIR)) {
|
|
162
|
+
bibliographyEntries = [];
|
|
163
|
+
bibliographyBuilt = true;
|
|
164
|
+
return bibliographyEntries;
|
|
165
|
+
}
|
|
166
|
+
const entries = [];
|
|
167
|
+
walkContentDir(CONTENT_DIR, entries);
|
|
168
|
+
const sorted = sortBibliography(entries);
|
|
169
|
+
bibliographyEntries = sorted;
|
|
170
|
+
bibliographyBuilt = true;
|
|
171
|
+
writeCache(sorted);
|
|
172
|
+
return bibliographyEntries;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function getBibliographyEntries() {
|
|
176
|
+
if (bibliographyBuilt && Array.isArray(bibliographyEntries)) {
|
|
177
|
+
return bibliographyEntries;
|
|
178
|
+
}
|
|
179
|
+
const cached = readCache();
|
|
180
|
+
if (cached) {
|
|
181
|
+
bibliographyEntries = cached;
|
|
182
|
+
bibliographyBuilt = true;
|
|
183
|
+
return bibliographyEntries;
|
|
184
|
+
}
|
|
185
|
+
return buildBibliographyIndexSync();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function resetBibliographyIndex() {
|
|
189
|
+
bibliographyEntries = null;
|
|
190
|
+
bibliographyBuilt = false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
module.exports = {
|
|
194
|
+
getBibliographyEntries,
|
|
195
|
+
buildBibliographyIndexSync,
|
|
196
|
+
resetBibliographyIndex,
|
|
197
|
+
};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const yaml = require('js-yaml');
|
|
4
|
+
const { rootRelativeHref } = require('../common');
|
|
5
|
+
const { resolveCanopyConfigPath } = require('../config-path');
|
|
6
|
+
|
|
7
|
+
const IIIF_MANIFESTS_DIR = path.resolve('.cache/iiif/manifests');
|
|
8
|
+
const SLUG_MEMO = new Map();
|
|
9
|
+
|
|
10
|
+
function firstLabelString(label) {
|
|
11
|
+
if (!label) return 'Untitled';
|
|
12
|
+
if (typeof label === 'string') return label;
|
|
13
|
+
try {
|
|
14
|
+
const keys = Object.keys(label || {});
|
|
15
|
+
if (!keys.length) return 'Untitled';
|
|
16
|
+
const arr = label[keys[0]];
|
|
17
|
+
if (Array.isArray(arr) && arr.length) return String(arr[0]);
|
|
18
|
+
} catch (_) {}
|
|
19
|
+
return 'Untitled';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function normalizeIiifId(raw) {
|
|
23
|
+
try {
|
|
24
|
+
const s = String(raw || '');
|
|
25
|
+
if (!/^https?:\/\//i.test(s)) return s;
|
|
26
|
+
const u = new URL(s);
|
|
27
|
+
const entries = Array.from(u.searchParams.entries()).sort(
|
|
28
|
+
(a, b) => a[0].localeCompare(b[0]) || a[1].localeCompare(b[1])
|
|
29
|
+
);
|
|
30
|
+
u.search = '';
|
|
31
|
+
for (const [k, v] of entries) u.searchParams.append(k, v);
|
|
32
|
+
return u.toString();
|
|
33
|
+
} catch (_) {
|
|
34
|
+
return String(raw || '');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function equalIiifId(a, b) {
|
|
39
|
+
try {
|
|
40
|
+
const an = normalizeIiifId(a);
|
|
41
|
+
const bn = normalizeIiifId(b);
|
|
42
|
+
if (an === bn) return true;
|
|
43
|
+
const ua = new URL(an);
|
|
44
|
+
const ub = new URL(bn);
|
|
45
|
+
return ua.origin === ub.origin && ua.pathname === ub.pathname;
|
|
46
|
+
} catch (_) {
|
|
47
|
+
return String(a || '') === String(b || '');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function readYaml(p) {
|
|
52
|
+
try {
|
|
53
|
+
if (!fs.existsSync(p)) return null;
|
|
54
|
+
const raw = fs.readFileSync(p, 'utf8');
|
|
55
|
+
return yaml.load(raw) || null;
|
|
56
|
+
} catch (_) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function readJson(p) {
|
|
62
|
+
try {
|
|
63
|
+
if (!fs.existsSync(p)) return null;
|
|
64
|
+
const raw = fs.readFileSync(p, 'utf8');
|
|
65
|
+
return JSON.parse(raw);
|
|
66
|
+
} catch (_) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function findSlugByIdFromDiskSync(nid) {
|
|
72
|
+
try {
|
|
73
|
+
if (!fs.existsSync(IIIF_MANIFESTS_DIR)) return null;
|
|
74
|
+
const names = fs.readdirSync(IIIF_MANIFESTS_DIR);
|
|
75
|
+
for (const name of names) {
|
|
76
|
+
if (!name || !name.toLowerCase().endsWith('.json')) continue;
|
|
77
|
+
const fp = path.join(IIIF_MANIFESTS_DIR, name);
|
|
78
|
+
try {
|
|
79
|
+
const obj = readJson(fp);
|
|
80
|
+
const mid = normalizeIiifId(String((obj && (obj.id || obj['@id'])) || ''));
|
|
81
|
+
if (mid && equalIiifId(mid, nid)) return name.replace(/\.json$/i, '');
|
|
82
|
+
} catch (_) {}
|
|
83
|
+
}
|
|
84
|
+
} catch (_) {}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function manifestPathFromSlug(slug) {
|
|
89
|
+
try {
|
|
90
|
+
const normalized = String(slug || '').trim();
|
|
91
|
+
if (!normalized || /[\\/]/.test(normalized)) return '';
|
|
92
|
+
return path.resolve(IIIF_MANIFESTS_DIR, `${normalized}.json`);
|
|
93
|
+
} catch (_) {
|
|
94
|
+
return '';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function manifestExistsForSlug(slug) {
|
|
99
|
+
const fp = manifestPathFromSlug(slug);
|
|
100
|
+
if (!fp) return false;
|
|
101
|
+
try {
|
|
102
|
+
return fs.existsSync(fp);
|
|
103
|
+
} catch (_) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function readManifestBySlug(slug) {
|
|
109
|
+
const fp = manifestPathFromSlug(slug);
|
|
110
|
+
if (!fp) return null;
|
|
111
|
+
return readJson(fp);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function resolveSlugForFeaturedEntry(rawId, byId) {
|
|
115
|
+
if (rawId == null) return null;
|
|
116
|
+
const rawValue = String(rawId).trim();
|
|
117
|
+
if (!rawValue) return null;
|
|
118
|
+
if (!/^https?:\/\//i.test(rawValue) && manifestExistsForSlug(rawValue)) {
|
|
119
|
+
const entry = Array.isArray(byId)
|
|
120
|
+
? byId.find((candidate) => candidate && candidate.slug === rawValue)
|
|
121
|
+
: null;
|
|
122
|
+
return {slug: rawValue, entry};
|
|
123
|
+
}
|
|
124
|
+
const normalizedId = normalizeIiifId(rawValue);
|
|
125
|
+
if (!normalizedId) return null;
|
|
126
|
+
const memoSlug = SLUG_MEMO.get(normalizedId);
|
|
127
|
+
if (memoSlug && manifestExistsForSlug(memoSlug)) {
|
|
128
|
+
const memoEntry = Array.isArray(byId)
|
|
129
|
+
? byId.find((candidate) => candidate && candidate.slug === memoSlug)
|
|
130
|
+
: null;
|
|
131
|
+
return {slug: memoSlug, entry: memoEntry};
|
|
132
|
+
}
|
|
133
|
+
const entry = byId.find(
|
|
134
|
+
(candidate) =>
|
|
135
|
+
candidate && candidate.type === 'Manifest' && equalIiifId(candidate.id, normalizedId)
|
|
136
|
+
);
|
|
137
|
+
if (entry && entry.slug && manifestExistsForSlug(entry.slug)) {
|
|
138
|
+
SLUG_MEMO.set(normalizedId, entry.slug);
|
|
139
|
+
return {slug: entry.slug, entry};
|
|
140
|
+
}
|
|
141
|
+
const fallbackSlug = findSlugByIdFromDiskSync(normalizedId);
|
|
142
|
+
if (fallbackSlug && manifestExistsForSlug(fallbackSlug)) {
|
|
143
|
+
SLUG_MEMO.set(normalizedId, fallbackSlug);
|
|
144
|
+
const fallbackEntry = Array.isArray(byId)
|
|
145
|
+
? byId.find(
|
|
146
|
+
(candidate) =>
|
|
147
|
+
candidate &&
|
|
148
|
+
candidate.type === 'Manifest' &&
|
|
149
|
+
(candidate.slug === fallbackSlug || equalIiifId(candidate.id, normalizedId))
|
|
150
|
+
)
|
|
151
|
+
: null;
|
|
152
|
+
return {slug: fallbackSlug, entry: fallbackEntry};
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function readFeaturedFromCacheSync() {
|
|
158
|
+
try {
|
|
159
|
+
const debug = !!process.env.CANOPY_DEBUG_FEATURED;
|
|
160
|
+
const cfg = readYaml(resolveCanopyConfigPath()) || {};
|
|
161
|
+
const featured = Array.isArray(cfg && cfg.featured) ? cfg.featured : [];
|
|
162
|
+
if (!featured.length) return [];
|
|
163
|
+
const idx = readJson(path.resolve('.cache/iiif/index.json')) || {};
|
|
164
|
+
const byId = Array.isArray(idx && idx.byId) ? idx.byId : [];
|
|
165
|
+
const out = [];
|
|
166
|
+
for (const id of featured) {
|
|
167
|
+
if (debug) { try { console.log('[featured] id:', id); } catch (_) {} }
|
|
168
|
+
const resolved = resolveSlugForFeaturedEntry(id, byId);
|
|
169
|
+
const slug = resolved && resolved.slug ? resolved.slug : '';
|
|
170
|
+
const entry = resolved && resolved.entry ? resolved.entry : null;
|
|
171
|
+
if (debug) { try { console.log('[featured] - slug:', slug || '(none)'); } catch (_) {} }
|
|
172
|
+
if (!slug) continue;
|
|
173
|
+
const m = readManifestBySlug(slug);
|
|
174
|
+
if (!m) continue;
|
|
175
|
+
const rec = {
|
|
176
|
+
title: firstLabelString(m && m.label),
|
|
177
|
+
href: rootRelativeHref(path.join('works', slug + '.html').split(path.sep).join('/')),
|
|
178
|
+
type: 'work',
|
|
179
|
+
};
|
|
180
|
+
if (entry && entry.heroThumbnail) {
|
|
181
|
+
rec.thumbnail = String(entry.heroThumbnail);
|
|
182
|
+
if (typeof entry.heroThumbnailWidth === 'number') {
|
|
183
|
+
rec.thumbnailWidth = entry.heroThumbnailWidth;
|
|
184
|
+
} else if (typeof entry.thumbnailWidth === 'number') {
|
|
185
|
+
rec.thumbnailWidth = entry.thumbnailWidth;
|
|
186
|
+
}
|
|
187
|
+
if (typeof entry.heroThumbnailHeight === 'number') {
|
|
188
|
+
rec.thumbnailHeight = entry.heroThumbnailHeight;
|
|
189
|
+
} else if (typeof entry.thumbnailHeight === 'number') {
|
|
190
|
+
rec.thumbnailHeight = entry.thumbnailHeight;
|
|
191
|
+
}
|
|
192
|
+
if (entry && entry.heroThumbnailSrcset) {
|
|
193
|
+
rec.srcset = String(entry.heroThumbnailSrcset);
|
|
194
|
+
}
|
|
195
|
+
if (entry && entry.heroThumbnailSizes) {
|
|
196
|
+
rec.sizes = String(entry.heroThumbnailSizes);
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
if (entry && entry.thumbnail) rec.thumbnail = String(entry.thumbnail);
|
|
200
|
+
if (entry && typeof entry.thumbnailWidth === 'number') rec.thumbnailWidth = entry.thumbnailWidth;
|
|
201
|
+
if (entry && typeof entry.thumbnailHeight === 'number') rec.thumbnailHeight = entry.thumbnailHeight;
|
|
202
|
+
}
|
|
203
|
+
if (!rec.thumbnail) {
|
|
204
|
+
try {
|
|
205
|
+
const t = m && m.thumbnail;
|
|
206
|
+
if (Array.isArray(t) && t.length) {
|
|
207
|
+
const first = t[0] || {};
|
|
208
|
+
const tid = first.id || first['@id'] || first.url || '';
|
|
209
|
+
if (tid) rec.thumbnail = String(tid);
|
|
210
|
+
if (typeof first.width === 'number') rec.thumbnailWidth = first.width;
|
|
211
|
+
if (typeof first.height === 'number') rec.thumbnailHeight = first.height;
|
|
212
|
+
} else if (t && typeof t === 'object') {
|
|
213
|
+
const tid = t.id || t['@id'] || t.url || '';
|
|
214
|
+
if (tid) rec.thumbnail = String(tid);
|
|
215
|
+
if (typeof t.width === 'number') rec.thumbnailWidth = t.width;
|
|
216
|
+
if (typeof t.height === 'number') rec.thumbnailHeight = t.height;
|
|
217
|
+
}
|
|
218
|
+
} catch (_) {}
|
|
219
|
+
}
|
|
220
|
+
out.push(rec);
|
|
221
|
+
}
|
|
222
|
+
if (debug) { try { console.log('[featured] total:', out.length); } catch (_) {} }
|
|
223
|
+
return out;
|
|
224
|
+
} catch (_) {
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
module.exports = {
|
|
230
|
+
firstLabelString,
|
|
231
|
+
normalizeIiifId,
|
|
232
|
+
equalIiifId,
|
|
233
|
+
readYaml,
|
|
234
|
+
readJson,
|
|
235
|
+
findSlugByIdFromDiskSync,
|
|
236
|
+
readFeaturedFromCacheSync,
|
|
237
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
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.
|
|
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.
|
|
12
|
+
//
|
|
13
|
+
// The server renders every slide and control (Hero.jsx), words from `locale.yml`
|
|
14
|
+
// included; this shows the controls and runs them.
|
|
15
|
+
|
|
16
|
+
const ROTATE_MS = 6000;
|
|
17
|
+
const SWIPE_PX = 48;
|
|
18
|
+
|
|
19
|
+
function ready(fn) {
|
|
20
|
+
if (typeof document === 'undefined') return;
|
|
21
|
+
if (document.readyState === 'loading') {
|
|
22
|
+
document.addEventListener('DOMContentLoaded', fn, { once: true });
|
|
23
|
+
} else {
|
|
24
|
+
fn();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function initCarousel(host) {
|
|
29
|
+
if (!host || host.__canopyHeroBound) return;
|
|
30
|
+
host.__canopyHeroBound = true;
|
|
31
|
+
const region = host.querySelector('[data-canopy-hero-carousel]');
|
|
32
|
+
if (!region) return;
|
|
33
|
+
const slides = Array.from(region.querySelectorAll('.canopy-interstitial__slide'));
|
|
34
|
+
if (slides.length <= 1) return;
|
|
35
|
+
|
|
36
|
+
const wrapper = region.querySelector('.canopy-interstitial__slide-wrapper');
|
|
37
|
+
const rotation = region.querySelector('.canopy-interstitial__rotation');
|
|
38
|
+
const nav = region.querySelector('.canopy-interstitial__nav');
|
|
39
|
+
const prev = region.querySelector('.canopy-interstitial__nav-btn--prev');
|
|
40
|
+
const next = region.querySelector('.canopy-interstitial__nav-btn--next');
|
|
41
|
+
const pagination = region.querySelector('.canopy-interstitial__pagination');
|
|
42
|
+
const dots = pagination
|
|
43
|
+
? Array.from(pagination.querySelectorAll('.canopy-interstitial__dot'))
|
|
44
|
+
: [];
|
|
45
|
+
|
|
46
|
+
const reduceMotion =
|
|
47
|
+
typeof window.matchMedia === 'function'
|
|
48
|
+
? window.matchMedia('(prefers-reduced-motion: reduce)')
|
|
49
|
+
: null;
|
|
50
|
+
|
|
51
|
+
let current = Math.max(
|
|
52
|
+
0,
|
|
53
|
+
slides.findIndex((slide) => !slide.hidden),
|
|
54
|
+
);
|
|
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
|
+
|
|
61
|
+
function preload(index) {
|
|
62
|
+
const slide = slides[(index + slides.length) % slides.length];
|
|
63
|
+
const image = slide && slide.querySelector('img[loading="lazy"]');
|
|
64
|
+
if (image) image.loading = 'eager';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function show(index) {
|
|
68
|
+
current = (index + slides.length) % slides.length;
|
|
69
|
+
slides.forEach((slide, i) => {
|
|
70
|
+
slide.hidden = i !== current;
|
|
71
|
+
});
|
|
72
|
+
dots.forEach((dot, i) => {
|
|
73
|
+
const active = i === current;
|
|
74
|
+
dot.classList.toggle('canopy-interstitial__dot--active', active);
|
|
75
|
+
dot.setAttribute('aria-current', active ? 'true' : 'false');
|
|
76
|
+
});
|
|
77
|
+
preload(current + 1);
|
|
78
|
+
}
|
|
79
|
+
|
|
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) => {
|
|
117
|
+
if (el) el.hidden = false;
|
|
118
|
+
});
|
|
119
|
+
|
|
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
|
+
});
|
|
153
|
+
|
|
154
|
+
// A swipe across the slide, by touch or pen, moves to the slide beside it. The
|
|
155
|
+
// buttons are its single-pointer alternative (2.5.1, 2.5.7).
|
|
156
|
+
let start = null;
|
|
157
|
+
if (wrapper) {
|
|
158
|
+
wrapper.addEventListener('pointerdown', (event) => {
|
|
159
|
+
if (event.pointerType === 'mouse' || !event.isPrimary) return;
|
|
160
|
+
start = { x: event.clientX, y: event.clientY };
|
|
161
|
+
});
|
|
162
|
+
wrapper.addEventListener('pointerup', (event) => {
|
|
163
|
+
if (!start) return;
|
|
164
|
+
const dx = event.clientX - start.x;
|
|
165
|
+
const dy = event.clientY - start.y;
|
|
166
|
+
start = null;
|
|
167
|
+
if (Math.abs(dx) < SWIPE_PX || Math.abs(dx) <= Math.abs(dy)) return;
|
|
168
|
+
go(dx < 0 ? current + 1 : current - 1);
|
|
169
|
+
});
|
|
170
|
+
wrapper.addEventListener('pointercancel', () => {
|
|
171
|
+
start = null;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
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
|
+
show(current);
|
|
187
|
+
update();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function observeHosts() {
|
|
191
|
+
try {
|
|
192
|
+
new MutationObserver((mutations) => {
|
|
193
|
+
mutations.forEach((mutation) => {
|
|
194
|
+
mutation.addedNodes &&
|
|
195
|
+
mutation.addedNodes.forEach((node) => {
|
|
196
|
+
if (!(node instanceof Element)) return;
|
|
197
|
+
if (node.matches && node.matches('[data-canopy-hero-slider]')) initCarousel(node);
|
|
198
|
+
const inner = node.querySelectorAll
|
|
199
|
+
? node.querySelectorAll('[data-canopy-hero-slider]')
|
|
200
|
+
: [];
|
|
201
|
+
inner && inner.forEach && inner.forEach((el) => initCarousel(el));
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}).observe(document.documentElement || document.body, {
|
|
205
|
+
childList: true,
|
|
206
|
+
subtree: true,
|
|
207
|
+
});
|
|
208
|
+
} catch (_) {}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
ready(() => {
|
|
212
|
+
if (typeof document === 'undefined') return;
|
|
213
|
+
document.querySelectorAll('[data-canopy-hero-slider]').forEach((host) => initCarousel(host));
|
|
214
|
+
observeHosts();
|
|
215
|
+
});
|