@micropasts/iiif-manifest-summary 0.0.0-stage → 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daniel Pett
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,438 @@
1
- # Temporary Holding Version
1
+ # IIIF Manifest Summary
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Zero-dependency JavaScript web components for displaying compact summaries of IIIF Presentation API v2 and v3 manifests. The components show the manifest title, summary, rights/license, thumbnail, canvas count, and up to four metadata fields without loading a heavy IIIF viewer.
4
+
5
+ Package: `@micropasts/iiif-manifest-summary`
6
+
7
+ ## Features
8
+
9
+ - IIIF Presentation API v2 and v3 support
10
+ - Named shadow-DOM and Tailwind CSS/light-DOM components
11
+ - Fetches manifests with the browser `fetch()` API
12
+ - Shared in-memory fetch and summary cache
13
+ - Loading and fetch-error states
14
+ - HTML-safe plain-text summaries and metadata
15
+ - Creative Commons and RightsStatements-friendly license labels
16
+ - Clickable thumbnails with a native modal/overlay
17
+ - Copy-to-clipboard URI button
18
+ - Composed `heritage:select` event
19
+ - Support for IIIF language maps and legacy v2 values
20
+ - Custom templates for the shadow-DOM component
21
+ - No runtime dependencies
22
+
23
+ ## Installation
24
+
25
+ ### npm
26
+
27
+ ```bash
28
+ npm install @micropasts/iiif-manifest-summary
29
+ ```
30
+
31
+ ESM usage:
32
+
33
+ ```html
34
+ <script type="module">
35
+ import '@micropasts/iiif-manifest-summary';
36
+ </script>
37
+ ```
38
+
39
+ ### CDN
40
+
41
+ The IIFE build exposes `window.IiifManifestSummaryLib`:
42
+
43
+ ```html
44
+ <script src="https://cdn.jsdelivr.net/npm/@micropasts/iiif-manifest-summary/dist/iiif-manifest-summary.iife.js"></script>
45
+
46
+ <iiif-manifest-summary
47
+ manifest="https://example.org/iiif/manifest.json"
48
+ ></iiif-manifest-summary>
49
+ ```
50
+
51
+ The ESM build can also be loaded directly:
52
+
53
+ ```html
54
+ <script type="module">
55
+ import {
56
+ IiifManifestSummary,
57
+ IiifManifestSummaryTailwind,
58
+ } from 'https://cdn.jsdelivr.net/npm/@micropasts/iiif-manifest-summary/dist/iiif-manifest-summary.esm.js';
59
+ </script>
60
+ ```
61
+
62
+ CDNs do not rewrite package subpath exports. When importing individual source exports, use an npm-aware environment or configure the appropriate source/specifier paths.
63
+
64
+ ## Components
65
+
66
+ ### `<iiif-manifest-summary>` — Shadow DOM
67
+
68
+ The default component renders inside an open shadow root and is isolated from page styles.
69
+
70
+ ```html
71
+ <iiif-manifest-summary
72
+ manifest="https://example.org/iiif/manifest.json"
73
+ theme="dark"
74
+ ></iiif-manifest-summary>
75
+ ```
76
+
77
+ It is registered globally under `iiif-manifest-summary` when it is not already defined.
78
+
79
+ #### Attributes
80
+
81
+ | Attribute | Required | Values | Description |
82
+ | --- | --- | --- | --- |
83
+ | `manifest` | Yes | Manifest URL | URI to fetch and summarize. Initial load and subsequent changes are supported. |
84
+ | `listen` | No | Custom event name | Listens for the named window event and uses `event.detail.manifest` to change manifests. |
85
+ | `theme` | No | `light`, `dark`, or omitted | Controls the built-in theme. `light` forces the light colors; `dark` forces dark colors; omitted follows `prefers-color-scheme: dark`. |
86
+
87
+ #### CSS custom properties
88
+
89
+ These variables can be set on the host element:
90
+
91
+ | Variable | Default in light mode | Purpose |
92
+ | --- | --- | --- |
93
+ | `--iiif-bg` | `#ffffff` | Card background |
94
+ | `--iiif-fg` | `#18181b` | Primary text |
95
+ | `--iiif-muted` | `#52525b` | Secondary text |
96
+ | `--iiif-border` | `#e4e4e7` | Card and thumbnail borders |
97
+ | `--iiif-surface` | `rgba(127, 127, 127, 0.08)` | Metadata and hover surface |
98
+ | `--iiif-accent` | `#0284c7` | IIIF version badge |
99
+ | `--iiif-radius` | `0.5rem` | Card radius |
100
+ | `--iiif-font` | `system-ui, -apple-system, sans-serif` | Component font |
101
+
102
+ Example:
103
+
104
+ ```css
105
+ iiif-manifest-summary {
106
+ --iiif-accent: #7c3aed;
107
+ --iiif-radius: 0.75rem;
108
+ --iiif-bg: #fafafa;
109
+ }
110
+ ```
111
+
112
+ Dark-mode defaults for `--iiif-bg`, `--iiif-fg`, `--iiif-muted`, and `--iiif-border` are applied automatically for dark system preference unless the host has `theme="light"`. The `theme="dark"` attribute overrides system preference.
113
+
114
+ #### Shadow parts
115
+
116
+ The built-in template exposes the following parts for `::part(...)` styling:
117
+
118
+ | Part | Element |
119
+ | --- | --- |
120
+ | `card` | Outer card |
121
+ | `header` | Header row |
122
+ | `badge` | Version badge |
123
+ | `canvases` | Canvas-count text |
124
+ | `thumb` | Thumbnail image |
125
+ | `title` | Manifest title |
126
+ | `summary` | Summary text |
127
+ | `meta` | Metadata grid |
128
+
129
+ ```css
130
+ iiif-manifest-summary::part(card) {
131
+ max-width: 32rem;
132
+ box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
133
+ }
134
+
135
+ iiif-manifest-summary::part(badge) {
136
+ background: #7c3aed;
137
+ }
138
+ ```
139
+
140
+ #### Custom template
141
+
142
+ Pass a render function to `IiifManifestSummary.setTemplate(...)` to replace the built-in card template for every shadow-DOM component:
143
+
144
+ ```js
145
+ import { IiifManifestSummary } from '@micropasts/iiif-manifest-summary';
146
+
147
+ IiifManifestSummary.setTemplate((summary, escapeHtml) => `
148
+ <article>
149
+ <h2>${escapeHtml(summary.label)}</h2>
150
+ <p>${escapeHtml(summary.canvasCount)} canvases</p>
151
+ </article>
152
+ `);
153
+ ```
154
+
155
+ Set the template on an individual instance before or after connected content is loaded:
156
+
157
+ ```js
158
+ const element = document.querySelector('iiif-manifest-summary');
159
+
160
+ element.template = (summary, escapeHtml) => `
161
+ <strong>${escapeHtml(summary.label)}</strong>
162
+ `;
163
+ ```
164
+
165
+ The instance template takes precedence over the global template. The escape callback HTML-escapes `&`, `<`, `>`, `"`, and control text used in templates.
166
+
167
+ ### `<iiif-manifest-summary-tw>` — Tailwind/light DOM
168
+
169
+ This component renders directly into the host element, so its utility classes can be scanned and provided by Tailwind in the host application.
170
+
171
+ ```html
172
+ <iiif-manifest-summary-tw
173
+ manifest="https://example.org/iiif/manifest.json"
174
+ card-class="border-sky-300 shadow-lg"
175
+ ></iiif-manifest-summary-tw>
176
+ ```
177
+
178
+ It is registered globally under `iiif-manifest-summary-tw` when it is not already defined.
179
+
180
+ #### Attributes
181
+
182
+ | Attribute | Required | Values | Description |
183
+ | --- | --- | --- | --- |
184
+ | `manifest` | Yes | Manifest URL | Initial URI to fetch and summarize. |
185
+ | `listen` | No | Custom event name | Listens for the named window event and uses `event.detail.manifest` to change manifests. |
186
+ | `card-class` | No | Tailwind/CSS classes | Extra classes appended to the built-in card classes. |
187
+
188
+ The Tailwind component uses a dark variant for Tailwind's `dark` class strategy and is intended for a Tailwind-enabled page.
189
+
190
+ #### Static Tailwind classes
191
+
192
+ The Tailwind component's default class groups are available as `IiifManifestSummaryTailwind.classes` and can be overridden before rendering:
193
+
194
+ ```js
195
+ import { IiifManifestSummaryTailwind } from '@micropasts/iiif-manifest-summary';
196
+
197
+ IiifManifestSummaryTailwind.classes.card =
198
+ 'rounded-lg border border-slate-300 bg-white p-4';
199
+ IiifManifestSummaryTailwind.classes.btn =
200
+ 'rounded border px-2 py-1 text-xs';
201
+ ```
202
+
203
+ ## Listening to external selection events
204
+
205
+ Set `listen` to an event name on either component:
206
+
207
+ ```html
208
+ <iiif-manifest-summary listen="catalog:select"></iiif-manifest-summary>
209
+ ```
210
+
211
+ Dispatch the event on `window`:
212
+
213
+ ```js
214
+ window.dispatchEvent(
215
+ new CustomEvent('catalog:select', {
216
+ detail: {
217
+ manifest: 'https://example.org/iiif/manifest.json',
218
+ },
219
+ }),
220
+ );
221
+ ```
222
+
223
+ The listener is added on `connectedCallback()` and removed on `disconnectedCallback()`.
224
+
225
+ ## Selection event
226
+
227
+ Both components dispatch a bubbling, composed `heritage:select` event when **Inspect** is clicked. `composed: true` allows the event to cross the shadow-DOM boundary.
228
+
229
+ ```js
230
+ document.addEventListener('heritage:select', (event) => {
231
+ const { uri, label, canvasCount, version } = event.detail;
232
+ console.log(uri, label, canvasCount, version);
233
+ });
234
+ ```
235
+
236
+ | Detail field | Type | Description |
237
+ | --- | --- | --- |
238
+ | `uri` | `string` | Resolved manifest URI |
239
+ | `label` | `string` | Displayed manifest label |
240
+ | `canvasCount` | `number` | Number of canvases/items found |
241
+ | `version` | `string` | `IIIF v2`, `IIIF v3`, or `IIIF` for fetch failures |
242
+
243
+ ## Public methods
244
+
245
+ Methods are available on component instances:
246
+
247
+ | Method | Class | Description |
248
+ | --- | --- | --- |
249
+ | `load(url)` | Both | Fetch or retrieve a manifest summary and render it |
250
+ | `setTemplate(fn)` | `IiifManifestSummary` only (static) | Set a global custom shadow-DOM render function |
251
+
252
+ The shadow-DOM component also supports an instance `template` property that is checked before the global template.
253
+
254
+ ## JavaScript API
255
+
256
+ All named exports are exported from the package entry point.
257
+
258
+ ```js
259
+ import {
260
+ summarizeManifest,
261
+ seedManifest,
262
+ clearManifestCache,
263
+ fetchManifestSummary,
264
+ emitManifestSelect,
265
+ copyTextToClipboard,
266
+ stripHtml,
267
+ formatRightsLabel,
268
+ IiifManifestSummary,
269
+ IiifManifestSummaryTailwind,
270
+ } from '@micropasts/iiif-manifest-summary';
271
+ ```
272
+
273
+ Subpath exports are also declared:
274
+
275
+ | Import | Exports |
276
+ | --- | --- |
277
+ | `@micropasts/iiif-manifest-summary/core` | Core utilities |
278
+ | `@micropasts/iiif-manifest-summary/shadow` | Shadow-DOM component |
279
+ | `@micropasts/iiif-manifest-summary/tailwind` | Tailwind component |
280
+
281
+ ### `summarizeManifest(manifest, manifestUri?)`
282
+
283
+ Normalizes a raw IIIF v2 or v3 manifest object into a summary object.
284
+
285
+ ```js
286
+ const summary = summarizeManifest(rawManifest, 'https://example.org/manifest');
287
+ ```
288
+
289
+ The returned shape is:
290
+
291
+ ```js
292
+ {
293
+ uri: 'https://example.org/manifest',
294
+ version: 'IIIF v3',
295
+ label: 'Manifest title',
296
+ summary: 'Short description',
297
+ rights: 'http://creativecommons.org/licenses/by/4.0/',
298
+ rightsLabel: 'CC BY 4.0',
299
+ thumbnail: 'https://example.org/thumbnail.jpg',
300
+ canvasCount: 12,
301
+ metadata: [
302
+ { label: 'Repository', value: 'Example Archive' },
303
+ ],
304
+ // present on fetch failure only:
305
+ error: true,
306
+ }
307
+ ```
308
+
309
+ The normalizer:
310
+
311
+ - Detects v3 from a Presentation 3 context or a top-level `items` array
312
+ - Prefers v3 `summary`, then v2 `description`
313
+ - Uses v3 `rights`, or v2 `license`
314
+ - Checks a v3 manifest thumbnail, v2 sequence thumbnail, or v3 first-canvas thumbnail
315
+ - Counts `items` that are canvases or falls back to v2 sequence canvases
316
+ - Includes at most four metadata entries
317
+
318
+ Language-map values prefer the `en` language, then `none`, then the first available language. Arrays are joined with ` · `.
319
+
320
+ ### `fetchManifestSummary(uri)`
321
+
322
+ Fetches and summarizes a manifest URI.
323
+
324
+ ```js
325
+ const summary = await fetchManifestSummary(
326
+ 'https://example.org/iiif/manifest.json',
327
+ );
328
+ ```
329
+
330
+ The request sends `Accept: application/json`. Concurrent requests for the same URI share an in-flight promise. HTTP and network failures return an error summary rather than rejecting:
331
+
332
+ ```js
333
+ {
334
+ uri,
335
+ version: 'IIIF',
336
+ label: uri,
337
+ summary: 'Unable to load manifest (HTTP 404).',
338
+ rights: 'Unavailable',
339
+ thumbnail: null,
340
+ canvasCount: 0,
341
+ metadata: [],
342
+ error: true,
343
+ }
344
+ ```
345
+
346
+ ### `seedManifest(uri, manifestJson)`
347
+
348
+ Places a raw manifest into the summary cache. This is useful for server-rendered data, testing, demos, and offline sandboxes.
349
+
350
+ ```js
351
+ seedManifest('https://example.org/manifest.json', rawManifestJson);
352
+
353
+ const summary = await fetchManifestSummary(
354
+ 'https://example.org/manifest.json',
355
+ );
356
+ ```
357
+
358
+ ### `clearManifestCache()`
359
+
360
+ Clears the successful summary cache. In-flight fetches are not cancelled or cleared.
361
+
362
+ ```js
363
+ clearManifestCache();
364
+ ```
365
+
366
+ ### `emitManifestSelect(target, summary)`
367
+
368
+ Dispatches `heritage:select` from `target` with a selected subset of summary fields. It is also used internally by the components.
369
+
370
+ ```js
371
+ emitManifestSelect(document.querySelector('.container'), summary);
372
+ ```
373
+
374
+ ### `copyTextToClipboard(text)`
375
+
376
+ Copies text using `navigator.clipboard` in a secure context and falls back to a temporary textarea and `document.execCommand('copy')`.
377
+
378
+ ```js
379
+ const copied = await copyTextToClipboard('https://example.org/manifest.json');
380
+ ```
381
+
382
+ Returns `true` when the copy operation reports success, otherwise `false`.
383
+
384
+ ### `stripHtml(value)`
385
+
386
+ Converts HTML markup to plain text. It is used for manifest labels, summaries, and metadata values. The browser implementation uses `DOMParser`; a built-in fallback handles tags and common character references.
387
+
388
+ ```js
389
+ stripHtml('<p>A <strong>plain</strong> description &amp; title.</p>');
390
+ // 'A plain description & title.'
391
+ ```
392
+
393
+ ### `formatRightsLabel(rights)`
394
+
395
+ Converts common Creative Commons and RightsStatements URIs into readable labels.
396
+
397
+ ```js
398
+ formatRightsLabel('http://creativecommons.org/licenses/by-sa/4.0/');
399
+ // 'CC BY-SA 4.0'
400
+
401
+ formatRightsLabel('http://rightsstatements.org/vocab/InC-EDU/1.0/');
402
+ // 'In Copyright - Educational Use'
403
+ ```
404
+
405
+ ## Demo
406
+
407
+ Run the local demo:
408
+
409
+ ```bash
410
+ npm run dev
411
+ ```
412
+
413
+ This builds `dist/` and `docs/`, then serves the demo directory on a local development server.
414
+
415
+ Open the demo to compare the Tailwind light-DOM component with the shadow-DOM component. The demo seeds both v2 and v3 sample manifests, so it can render without live manifest requests.
416
+
417
+ ## Build
418
+
419
+ ```bash
420
+ npm run build
421
+ ```
422
+
423
+ The build script creates:
424
+
425
+ - `dist/iiif-manifest-summary.esm.js`
426
+ - `dist/iiif-manifest-summary.iife.js`
427
+ - `docs/iiif-manifest-summary.esm.js`
428
+ - `docs/index.html`
429
+
430
+ The IIFE build exposes the package API through `window.IiifManifestSummaryLib`.
431
+
432
+ ## Browser support
433
+
434
+ The components use standard custom elements, shadow DOM, `fetch`, `Map`, `async`/`await`, and template literals. Serve module builds over HTTP(S); opening module files directly with `file://` may be restricted by browser module-loading rules.
435
+
436
+ ## License
437
+
438
+ MIT