@micropasts/iiif-manifest-summary 0.1.0 → 0.1.5

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # IIIF Manifest Summary
1
+ # IIIF Manifest Summary Card
2
2
 
3
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
4
 
@@ -12,6 +12,7 @@ Package: `@micropasts/iiif-manifest-summary`
12
12
  - Shared in-memory fetch and summary cache
13
13
  - Loading and fetch-error states
14
14
  - HTML-safe plain-text summaries and metadata
15
+ - Long descriptions have a compact preview and an accessible read-more control
15
16
  - Creative Commons and RightsStatements-friendly license labels
16
17
  - Clickable thumbnails with a native modal/overlay
17
18
  - Copy-to-clipboard URI button
@@ -125,6 +126,7 @@ The built-in template exposes the following parts for `::part(...)` styling:
125
126
  | `title` | Manifest title |
126
127
  | `summary` | Summary text |
127
128
  | `meta` | Metadata grid |
129
+ | `rights` | Rights or licence badge |
128
130
 
129
131
  ```css
130
132
  iiif-manifest-summary::part(card) {
@@ -164,6 +166,10 @@ element.template = (summary, escapeHtml) => `
164
166
 
165
167
  The instance template takes precedence over the global template. The escape callback HTML-escapes `&`, `<`, `>`, `"`, and control text used in templates.
166
168
 
169
+ Both built-in card templates show a preview of descriptions longer than 220
170
+ characters and offer Read more / Read less controls. Custom shadow templates
171
+ can use `summary.fullSummary` to display the complete description.
172
+
167
173
  ### `<iiif-manifest-summary-tw>` — Tailwind/light DOM
168
174
 
169
175
  This component renders directly into the host element, so its utility classes can be scanned and provided by Tailwind in the host application.
@@ -185,7 +191,20 @@ It is registered globally under `iiif-manifest-summary-tw` when it is not alread
185
191
  | `listen` | No | Custom event name | Listens for the named window event and uses `event.detail.manifest` to change manifests. |
186
192
  | `card-class` | No | Tailwind/CSS classes | Extra classes appended to the built-in card classes. |
187
193
 
188
- The Tailwind component uses a dark variant for Tailwind's `dark` class strategy and is intended for a Tailwind-enabled page.
194
+ The component's `dark:` utilities follow the host application's Tailwind dark-mode
195
+ configuration. With Tailwind's default media-based strategy, they automatically
196
+ follow the system color scheme, including changes while the page is open. If the
197
+ application configures a class- or selector-based dark variant instead, the
198
+ application is responsible for updating that selector; the component does not
199
+ change the page's theme.
200
+
201
+ Ensure Tailwind scans the component's source (including dependencies if installed
202
+ from npm), or otherwise includes its utility classes in the generated CSS. For
203
+ example, Tailwind v3 can include
204
+ `./node_modules/@micropasts/iiif-manifest-summary/src/tailwind.js` in its
205
+ `content` configuration; Tailwind v4 can register the same file with `@source`.
206
+ The demo uses a class-based variant, follows system changes until its theme toggle
207
+ is used, and then preserves the chosen theme in local storage.
189
208
 
190
209
  #### Static Tailwind classes
191
210
 
@@ -294,6 +313,7 @@ The returned shape is:
294
313
  version: 'IIIF v3',
295
314
  label: 'Manifest title',
296
315
  summary: 'Short description',
316
+ fullSummary: 'Short description',
297
317
  rights: 'http://creativecommons.org/licenses/by/4.0/',
298
318
  rightsLabel: 'CC BY 4.0',
299
319
  thumbnail: 'https://example.org/thumbnail.jpg',
@@ -310,6 +330,7 @@ The normalizer:
310
330
 
311
331
  - Detects v3 from a Presentation 3 context or a top-level `items` array
312
332
  - Prefers v3 `summary`, then v2 `description`
333
+ - Returns the full plain-text description in `fullSummary` and a preview of at most 220 characters in `summary` (shortened at a word boundary when possible)
313
334
  - Uses v3 `rights`, or v2 `license`
314
335
  - Checks a v3 manifest thumbnail, v2 sequence thumbnail, or v3 first-canvas thumbnail
315
336
  - Counts `items` that are canvases or falls back to v2 sequence canvases
@@ -335,6 +356,7 @@ The request sends `Accept: application/json`. Concurrent requests for the same U
335
356
  version: 'IIIF',
336
357
  label: uri,
337
358
  summary: 'Unable to load manifest (HTTP 404).',
359
+ fullSummary: 'Unable to load manifest (HTTP 404).',
338
360
  rights: 'Unavailable',
339
361
  thumbnail: null,
340
362
  canvasCount: 0,
@@ -398,10 +420,16 @@ Converts common Creative Commons and RightsStatements URIs into readable labels.
398
420
  formatRightsLabel('http://creativecommons.org/licenses/by-sa/4.0/');
399
421
  // 'CC BY-SA 4.0'
400
422
 
423
+ formatRightsLabel('http://creativecommons.org/licenses/cc-by/4.0/');
424
+ // 'CC BY 4.0'
425
+
401
426
  formatRightsLabel('http://rightsstatements.org/vocab/InC-EDU/1.0/');
402
427
  // 'In Copyright - Educational Use'
403
428
  ```
404
429
 
430
+ The `cc-by` form is recognized for display, but the canonical Creative Commons
431
+ URL uses `by` rather than `cc-by`. The original URI is preserved.
432
+
405
433
  ## Demo
406
434
 
407
435
  Run the local demo:
@@ -429,6 +457,29 @@ The build script creates:
429
457
 
430
458
  The IIFE build exposes the package API through `window.IiifManifestSummaryLib`.
431
459
 
460
+ ## Publishing
461
+
462
+ The package is authored by Daniel Pett and published as
463
+ `@micropasts/iiif-manifest-summary`. To release it:
464
+
465
+ 1. Update the version in `package.json` and `package-lock.json`, run `npm test`
466
+ and `npm run build`, and commit the changes.
467
+ 2. Ensure the repository has an `NPM_TOKEN` Actions secret containing a granular
468
+ npm access token with publish permission for the `@micropasts` package and
469
+ permission to bypass 2FA in CI. The npm account must have publishing access.
470
+ 3. Publish a GitHub release from that commit with a tag matching the version,
471
+ such as `v0.1.4`. The workflow tests the release and publishes separately to
472
+ npm and GitHub Packages. Prereleases use the `next` dist-tag instead of `latest`.
473
+
474
+ npm publishes are public and include provenance. GitHub Packages has its own
475
+ visibility setting: an organization package administrator must make the package
476
+ public in its GitHub package settings if it is not already public. The workflow's
477
+ `GITHUB_TOKEN` also needs package write access; for an existing package, grant
478
+ this repository Actions access in its package settings if necessary. GitHub's
479
+ npm registry requires authentication even for public packages. If only one
480
+ registry fails, rerun the failed job after correcting access rather than
481
+ republishing the version that succeeded.
482
+
432
483
  ## Browser support
433
484
 
434
485
  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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @micropasts/iiif-manifest-summary v0.1.0
2
+ * @micropasts/iiif-manifest-summary v0.1.5
3
3
  * Zero-dependency IIIF Presentation v2/v3 summary Web Components
4
4
  * License: MIT
5
5
  */
@@ -71,7 +71,7 @@ export function formatRightsLabel(rights) {
71
71
  if (ccZero) return `CC0 ${ccZero[1]}`;
72
72
  if (/creativecommons\.org\/publicdomain\/zero/i.test(value)) return 'CC0';
73
73
 
74
- const ccLicense = value.match(/creativecommons\.org\/licenses\/(by(?:-nc|-nd|-sa|-nc-sa|-nc-nd)?|zero)\/([0-9.]+)/i);
74
+ const ccLicense = value.match(/creativecommons\.org\/licenses\/(?:cc-)?(by(?:-nc|-nd|-sa|-nc-sa|-nc-nd)?|zero)\/([0-9.]+)/i);
75
75
  if (ccLicense) {
76
76
  const code = ccLicense[1].toUpperCase();
77
77
  const version = ccLicense[2];
@@ -168,9 +168,12 @@ export function summarizeManifest(manifest, manifestUri = '') {
168
168
  pickLangValue(manifest?.description) ||
169
169
  '';
170
170
  const plainSummary = stripHtml(summary);
171
+ const summaryCharacters = Array.from(plainSummary);
172
+ const summaryStart = summaryCharacters.slice(0, 219).join('');
173
+ const lastWordBoundary = summaryStart.search(/\s+\S*$/);
171
174
  const compactSummary =
172
- plainSummary.length > 220
173
- ? `${plainSummary.slice(0, 219).replace(/\s+$/, '')}…`
175
+ summaryCharacters.length > 220
176
+ ? `${(lastWordBoundary >= 110 ? summaryStart.slice(0, lastWordBoundary) : summaryStart).trimEnd()}…`
174
177
  : plainSummary;
175
178
 
176
179
  const rights =
@@ -187,6 +190,7 @@ export function summarizeManifest(manifest, manifestUri = '') {
187
190
  version,
188
191
  label,
189
192
  summary: compactSummary,
193
+ fullSummary: plainSummary,
190
194
  rights,
191
195
  rightsLabel: formatRightsLabel(rights),
192
196
  thumbnail,
@@ -226,6 +230,7 @@ export async function fetchManifestSummary(uri) {
226
230
  version: 'IIIF',
227
231
  label: uri,
228
232
  summary: `Unable to load manifest (${err?.message || 'CORS or network error'}).`,
233
+ fullSummary: `Unable to load manifest (${err?.message || 'CORS or network error'}).`,
229
234
  rights: 'Unavailable',
230
235
  rightsLabel: 'Unavailable',
231
236
  thumbnail: null,
@@ -425,10 +430,11 @@ export class IiifManifestSummary extends HTMLElement {
425
430
  .thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 4px; flex-shrink: 0; border: 1px solid var(--iiif-border); }
426
431
  .title { font-weight: 700; font-size: 15px; line-height: 1.3; }
427
432
  .summary { margin: 8px 0; font-size: 12.5px; line-height: 1.45; color: var(--iiif-fg); }
433
+ .summary-toggle { margin-top: -4px; }
428
434
  .meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 6px; margin: 8px 0; padding: 8px; border-radius: 4px; background: var(--iiif-surface); font-size: 11px; }
429
435
  .meta span { display: block; color: var(--iiif-muted); }
430
436
  .footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--iiif-border); padding-top: 8px; margin-top: 8px; font-size: 11px; }
431
- .rights { color: var(--iiif-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
437
+ .rights { display: inline-block; max-width: 100%; box-sizing: border-box; padding: 2px 6px; border: 1px solid var(--iiif-border); border-radius: 4px; background: var(--iiif-surface); color: var(--iiif-fg); font-weight: 500; overflow-wrap: anywhere; }
432
438
  .btns { display: flex; gap: 6px; }
433
439
  button { font-size: 11px; padding: 3px 8px; border-radius: 4px; border: 1px solid var(--iiif-border); background: transparent; color: inherit; cursor: pointer; }
434
440
  button:hover { background: var(--iiif-surface); }
@@ -459,6 +465,7 @@ export class IiifManifestSummary extends HTMLElement {
459
465
  </div>
460
466
  </div>
461
467
  ${d.summary ? `<p part="summary" class="summary">${this._esc(d.summary)}</p>` : ''}
468
+ ${d.fullSummary && d.fullSummary !== d.summary ? '<button type="button" class="summary-toggle" aria-expanded="false">Read more</button>' : ''}
462
469
  ${
463
470
  d.metadata?.length
464
471
  ? `<div part="meta" class="meta">${d.metadata
@@ -467,7 +474,7 @@ export class IiifManifestSummary extends HTMLElement {
467
474
  : ''
468
475
  }
469
476
  <div class="footer">
470
- <span class="rights" title="${this._esc(d.rights)}">Rights: ${this._esc(d.rightsLabel || d.rights)}</span>
477
+ <span part="rights" class="rights" title="${this._esc(d.rights)}">Rights: ${this._esc(d.rightsLabel || d.rights)}</span>
471
478
  <div class="btns">
472
479
  <button type="button" class="copy-uri" data-uri="${this._esc(d.uri)}">Copy URI</button>
473
480
  <button type="button" class="select-btn">Inspect</button>
@@ -480,6 +487,14 @@ export class IiifManifestSummary extends HTMLElement {
480
487
  </dialog>` : ''}
481
488
  `;
482
489
 
490
+ this.shadowRoot.querySelector('.summary-toggle')?.addEventListener('click', (event) => {
491
+ const button = event.currentTarget;
492
+ const expanded = button.getAttribute('aria-expanded') === 'true';
493
+ this.shadowRoot.querySelector('.summary').textContent = expanded ? d.summary : d.fullSummary;
494
+ button.setAttribute('aria-expanded', String(!expanded));
495
+ button.textContent = expanded ? 'Read more' : 'Read less';
496
+ });
497
+
483
498
  const lightbox = this.shadowRoot.querySelector('.lightbox');
484
499
  this.shadowRoot.querySelector('[data-open-lightbox]')?.addEventListener('click', () => {
485
500
  if (typeof lightbox?.showModal === 'function') lightbox.showModal();
@@ -561,7 +576,7 @@ export class IiifManifestSummaryTailwind extends HTMLElement {
561
576
 
562
577
  async load(url) {
563
578
  const c = IiifManifestSummaryTailwind.classes;
564
- this.innerHTML = `<div class="${c.card} text-xs text-zinc-500 animate-pulse">Loading IIIF manifest summary…</div>`;
579
+ this.innerHTML = `<div class="${c.card} text-xs text-zinc-500 dark:text-zinc-400 animate-pulse">Loading IIIF manifest summary…</div>`;
565
580
  this._data = await fetchManifestSummary(url);
566
581
  this._renderData();
567
582
  }
@@ -597,20 +612,21 @@ export class IiifManifestSummaryTailwind extends HTMLElement {
597
612
  </div>
598
613
 
599
614
  ${d.summary ? `<p class="mt-2 text-xs leading-relaxed text-zinc-700 dark:text-zinc-300">${this._esc(d.summary)}</p>` : ''}
615
+ ${d.fullSummary && d.fullSummary !== d.summary ? `<button type="button" data-iiif-summary-toggle aria-expanded="false" class="${c.btn} mt-1">Read more</button>` : ''}
600
616
 
601
617
  ${
602
618
  d.metadata?.length
603
619
  ? `<div class="mt-2.5 grid grid-cols-2 gap-2 rounded-md bg-zinc-50 dark:bg-zinc-950/70 p-2 text-xs border border-zinc-200/70 dark:border-zinc-800">${d.metadata
604
620
  .map(
605
621
  (m) =>
606
- `<div><span class="block text-[10px] uppercase tracking-wide text-zinc-500">${this._esc(m.label)}</span><strong class="font-medium text-zinc-900 dark:text-zinc-100">${this._esc(m.value)}</strong></div>`
622
+ `<div><span class="block text-[10px] uppercase tracking-wide text-zinc-500 dark:text-zinc-400">${this._esc(m.label)}</span><strong class="font-medium text-zinc-900 dark:text-zinc-100">${this._esc(m.value)}</strong></div>`
607
623
  )
608
624
  .join('')}</div>`
609
625
  : ''
610
626
  }
611
627
 
612
628
  <div class="mt-3 flex flex-wrap items-center justify-between gap-2 border-t border-zinc-200 dark:border-zinc-800 pt-2 text-[11px]">
613
- <span class="truncate max-w-[200px] text-zinc-500 dark:text-zinc-400" title="${this._esc(d.rights)}">Rights: ${this._esc(d.rightsLabel || d.rights)}</span>
629
+ <span class="inline-block max-w-full break-words rounded border border-zinc-200 dark:border-zinc-700 bg-zinc-100 dark:bg-zinc-800 px-1.5 py-0.5 font-medium text-zinc-800 dark:text-zinc-200" title="${this._esc(d.rights)}">Rights: ${this._esc(d.rightsLabel || d.rights)}</span>
614
630
  <div class="flex items-center gap-1.5">
615
631
  <button type="button" data-iiif-copy data-uri="${this._esc(d.uri)}" class="${c.btn}">Copy URI</button>
616
632
  <button type="button" data-iiif-select class="${c.btn}">Inspect</button>
@@ -623,6 +639,14 @@ export class IiifManifestSummaryTailwind extends HTMLElement {
623
639
  </dialog>` : ''}
624
640
  `;
625
641
 
642
+ this.querySelector('[data-iiif-summary-toggle]')?.addEventListener('click', (event) => {
643
+ const button = event.currentTarget;
644
+ const expanded = button.getAttribute('aria-expanded') === 'true';
645
+ button.previousElementSibling.textContent = expanded ? d.summary : d.fullSummary;
646
+ button.setAttribute('aria-expanded', String(!expanded));
647
+ button.textContent = expanded ? 'Read more' : 'Read less';
648
+ });
649
+
626
650
  const lightbox = this.querySelector('[data-iiif-lightbox]');
627
651
  this.querySelector('[data-open-lightbox]')?.addEventListener('click', () => {
628
652
  if (typeof lightbox?.showModal === 'function') lightbox.showModal();
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @micropasts/iiif-manifest-summary v0.1.0
2
+ * @micropasts/iiif-manifest-summary v0.1.5
3
3
  * Zero-dependency IIIF Presentation v2/v3 summary Web Components
4
4
  * License: MIT
5
5
  */
@@ -71,7 +71,7 @@ function formatRightsLabel(rights) {
71
71
  if (ccZero) return `CC0 ${ccZero[1]}`;
72
72
  if (/creativecommons\.org\/publicdomain\/zero/i.test(value)) return 'CC0';
73
73
 
74
- const ccLicense = value.match(/creativecommons\.org\/licenses\/(by(?:-nc|-nd|-sa|-nc-sa|-nc-nd)?|zero)\/([0-9.]+)/i);
74
+ const ccLicense = value.match(/creativecommons\.org\/licenses\/(?:cc-)?(by(?:-nc|-nd|-sa|-nc-sa|-nc-nd)?|zero)\/([0-9.]+)/i);
75
75
  if (ccLicense) {
76
76
  const code = ccLicense[1].toUpperCase();
77
77
  const version = ccLicense[2];
@@ -168,9 +168,12 @@ function summarizeManifest(manifest, manifestUri = '') {
168
168
  pickLangValue(manifest?.description) ||
169
169
  '';
170
170
  const plainSummary = stripHtml(summary);
171
+ const summaryCharacters = Array.from(plainSummary);
172
+ const summaryStart = summaryCharacters.slice(0, 219).join('');
173
+ const lastWordBoundary = summaryStart.search(/\s+\S*$/);
171
174
  const compactSummary =
172
- plainSummary.length > 220
173
- ? `${plainSummary.slice(0, 219).replace(/\s+$/, '')}…`
175
+ summaryCharacters.length > 220
176
+ ? `${(lastWordBoundary >= 110 ? summaryStart.slice(0, lastWordBoundary) : summaryStart).trimEnd()}…`
174
177
  : plainSummary;
175
178
 
176
179
  const rights =
@@ -187,6 +190,7 @@ function summarizeManifest(manifest, manifestUri = '') {
187
190
  version,
188
191
  label,
189
192
  summary: compactSummary,
193
+ fullSummary: plainSummary,
190
194
  rights,
191
195
  rightsLabel: formatRightsLabel(rights),
192
196
  thumbnail,
@@ -226,6 +230,7 @@ async function fetchManifestSummary(uri) {
226
230
  version: 'IIIF',
227
231
  label: uri,
228
232
  summary: `Unable to load manifest (${err?.message || 'CORS or network error'}).`,
233
+ fullSummary: `Unable to load manifest (${err?.message || 'CORS or network error'}).`,
229
234
  rights: 'Unavailable',
230
235
  rightsLabel: 'Unavailable',
231
236
  thumbnail: null,
@@ -424,10 +429,11 @@ class IiifManifestSummary extends HTMLElement {
424
429
  .thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 4px; flex-shrink: 0; border: 1px solid var(--iiif-border); }
425
430
  .title { font-weight: 700; font-size: 15px; line-height: 1.3; }
426
431
  .summary { margin: 8px 0; font-size: 12.5px; line-height: 1.45; color: var(--iiif-fg); }
432
+ .summary-toggle { margin-top: -4px; }
427
433
  .meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 6px; margin: 8px 0; padding: 8px; border-radius: 4px; background: var(--iiif-surface); font-size: 11px; }
428
434
  .meta span { display: block; color: var(--iiif-muted); }
429
435
  .footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--iiif-border); padding-top: 8px; margin-top: 8px; font-size: 11px; }
430
- .rights { color: var(--iiif-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
436
+ .rights { display: inline-block; max-width: 100%; box-sizing: border-box; padding: 2px 6px; border: 1px solid var(--iiif-border); border-radius: 4px; background: var(--iiif-surface); color: var(--iiif-fg); font-weight: 500; overflow-wrap: anywhere; }
431
437
  .btns { display: flex; gap: 6px; }
432
438
  button { font-size: 11px; padding: 3px 8px; border-radius: 4px; border: 1px solid var(--iiif-border); background: transparent; color: inherit; cursor: pointer; }
433
439
  button:hover { background: var(--iiif-surface); }
@@ -458,6 +464,7 @@ class IiifManifestSummary extends HTMLElement {
458
464
  </div>
459
465
  </div>
460
466
  ${d.summary ? `<p part="summary" class="summary">${this._esc(d.summary)}</p>` : ''}
467
+ ${d.fullSummary && d.fullSummary !== d.summary ? '<button type="button" class="summary-toggle" aria-expanded="false">Read more</button>' : ''}
461
468
  ${
462
469
  d.metadata?.length
463
470
  ? `<div part="meta" class="meta">${d.metadata
@@ -466,7 +473,7 @@ class IiifManifestSummary extends HTMLElement {
466
473
  : ''
467
474
  }
468
475
  <div class="footer">
469
- <span class="rights" title="${this._esc(d.rights)}">Rights: ${this._esc(d.rightsLabel || d.rights)}</span>
476
+ <span part="rights" class="rights" title="${this._esc(d.rights)}">Rights: ${this._esc(d.rightsLabel || d.rights)}</span>
470
477
  <div class="btns">
471
478
  <button type="button" class="copy-uri" data-uri="${this._esc(d.uri)}">Copy URI</button>
472
479
  <button type="button" class="select-btn">Inspect</button>
@@ -479,6 +486,14 @@ class IiifManifestSummary extends HTMLElement {
479
486
  </dialog>` : ''}
480
487
  `;
481
488
 
489
+ this.shadowRoot.querySelector('.summary-toggle')?.addEventListener('click', (event) => {
490
+ const button = event.currentTarget;
491
+ const expanded = button.getAttribute('aria-expanded') === 'true';
492
+ this.shadowRoot.querySelector('.summary').textContent = expanded ? d.summary : d.fullSummary;
493
+ button.setAttribute('aria-expanded', String(!expanded));
494
+ button.textContent = expanded ? 'Read more' : 'Read less';
495
+ });
496
+
482
497
  const lightbox = this.shadowRoot.querySelector('.lightbox');
483
498
  this.shadowRoot.querySelector('[data-open-lightbox]')?.addEventListener('click', () => {
484
499
  if (typeof lightbox?.showModal === 'function') lightbox.showModal();
@@ -559,7 +574,7 @@ class IiifManifestSummaryTailwind extends HTMLElement {
559
574
 
560
575
  async load(url) {
561
576
  const c = IiifManifestSummaryTailwind.classes;
562
- this.innerHTML = `<div class="${c.card} text-xs text-zinc-500 animate-pulse">Loading IIIF manifest summary…</div>`;
577
+ this.innerHTML = `<div class="${c.card} text-xs text-zinc-500 dark:text-zinc-400 animate-pulse">Loading IIIF manifest summary…</div>`;
563
578
  this._data = await fetchManifestSummary(url);
564
579
  this._renderData();
565
580
  }
@@ -595,20 +610,21 @@ class IiifManifestSummaryTailwind extends HTMLElement {
595
610
  </div>
596
611
 
597
612
  ${d.summary ? `<p class="mt-2 text-xs leading-relaxed text-zinc-700 dark:text-zinc-300">${this._esc(d.summary)}</p>` : ''}
613
+ ${d.fullSummary && d.fullSummary !== d.summary ? `<button type="button" data-iiif-summary-toggle aria-expanded="false" class="${c.btn} mt-1">Read more</button>` : ''}
598
614
 
599
615
  ${
600
616
  d.metadata?.length
601
617
  ? `<div class="mt-2.5 grid grid-cols-2 gap-2 rounded-md bg-zinc-50 dark:bg-zinc-950/70 p-2 text-xs border border-zinc-200/70 dark:border-zinc-800">${d.metadata
602
618
  .map(
603
619
  (m) =>
604
- `<div><span class="block text-[10px] uppercase tracking-wide text-zinc-500">${this._esc(m.label)}</span><strong class="font-medium text-zinc-900 dark:text-zinc-100">${this._esc(m.value)}</strong></div>`
620
+ `<div><span class="block text-[10px] uppercase tracking-wide text-zinc-500 dark:text-zinc-400">${this._esc(m.label)}</span><strong class="font-medium text-zinc-900 dark:text-zinc-100">${this._esc(m.value)}</strong></div>`
605
621
  )
606
622
  .join('')}</div>`
607
623
  : ''
608
624
  }
609
625
 
610
626
  <div class="mt-3 flex flex-wrap items-center justify-between gap-2 border-t border-zinc-200 dark:border-zinc-800 pt-2 text-[11px]">
611
- <span class="truncate max-w-[200px] text-zinc-500 dark:text-zinc-400" title="${this._esc(d.rights)}">Rights: ${this._esc(d.rightsLabel || d.rights)}</span>
627
+ <span class="inline-block max-w-full break-words rounded border border-zinc-200 dark:border-zinc-700 bg-zinc-100 dark:bg-zinc-800 px-1.5 py-0.5 font-medium text-zinc-800 dark:text-zinc-200" title="${this._esc(d.rights)}">Rights: ${this._esc(d.rightsLabel || d.rights)}</span>
612
628
  <div class="flex items-center gap-1.5">
613
629
  <button type="button" data-iiif-copy data-uri="${this._esc(d.uri)}" class="${c.btn}">Copy URI</button>
614
630
  <button type="button" data-iiif-select class="${c.btn}">Inspect</button>
@@ -621,6 +637,14 @@ class IiifManifestSummaryTailwind extends HTMLElement {
621
637
  </dialog>` : ''}
622
638
  `;
623
639
 
640
+ this.querySelector('[data-iiif-summary-toggle]')?.addEventListener('click', (event) => {
641
+ const button = event.currentTarget;
642
+ const expanded = button.getAttribute('aria-expanded') === 'true';
643
+ button.previousElementSibling.textContent = expanded ? d.summary : d.fullSummary;
644
+ button.setAttribute('aria-expanded', String(!expanded));
645
+ button.textContent = expanded ? 'Read more' : 'Read less';
646
+ });
647
+
624
648
  const lightbox = this.querySelector('[data-iiif-lightbox]');
625
649
  this.querySelector('[data-open-lightbox]')?.addEventListener('click', () => {
626
650
  if (typeof lightbox?.showModal === 'function') lightbox.showModal();
package/package.json CHANGED
@@ -1,7 +1,19 @@
1
1
  {
2
2
  "name": "@micropasts/iiif-manifest-summary",
3
- "version": "0.1.0",
3
+ "version": "0.1.5",
4
4
  "description": "Zero-dependency JavaScript Web Components for summarizing IIIF Presentation v2 and v3 manifests with thumbnails, rights, canvas counts, and Shadow DOM / Tailwind CSS support.",
5
+ "author": "Daniel Pett",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/MicroPasts/iiif-manifest-summary.git"
9
+ },
10
+ "homepage": "https://github.com/MicroPasts/iiif-manifest-summary#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/MicroPasts/iiif-manifest-summary/issues"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
5
17
  "type": "module",
6
18
  "main": "./dist/iiif-manifest-summary.esm.js",
7
19
  "module": "./dist/iiif-manifest-summary.esm.js",
@@ -24,6 +36,7 @@
24
36
  "scripts": {
25
37
  "build": "node scripts/build.js",
26
38
  "dev": "node scripts/build.js && npx serve docs",
39
+ "test": "node --test",
27
40
  "prepare": "npm run build"
28
41
  },
29
42
  "keywords": [
@@ -37,4 +50,4 @@
37
50
  "micropasts"
38
51
  ],
39
52
  "license": "MIT"
40
- }
53
+ }
package/src/core.js CHANGED
@@ -64,7 +64,7 @@ export function formatRightsLabel(rights) {
64
64
  if (ccZero) return `CC0 ${ccZero[1]}`;
65
65
  if (/creativecommons\.org\/publicdomain\/zero/i.test(value)) return 'CC0';
66
66
 
67
- const ccLicense = value.match(/creativecommons\.org\/licenses\/(by(?:-nc|-nd|-sa|-nc-sa|-nc-nd)?|zero)\/([0-9.]+)/i);
67
+ const ccLicense = value.match(/creativecommons\.org\/licenses\/(?:cc-)?(by(?:-nc|-nd|-sa|-nc-sa|-nc-nd)?|zero)\/([0-9.]+)/i);
68
68
  if (ccLicense) {
69
69
  const code = ccLicense[1].toUpperCase();
70
70
  const version = ccLicense[2];
@@ -161,9 +161,12 @@ export function summarizeManifest(manifest, manifestUri = '') {
161
161
  pickLangValue(manifest?.description) ||
162
162
  '';
163
163
  const plainSummary = stripHtml(summary);
164
+ const summaryCharacters = Array.from(plainSummary);
165
+ const summaryStart = summaryCharacters.slice(0, 219).join('');
166
+ const lastWordBoundary = summaryStart.search(/\s+\S*$/);
164
167
  const compactSummary =
165
- plainSummary.length > 220
166
- ? `${plainSummary.slice(0, 219).replace(/\s+$/, '')}…`
168
+ summaryCharacters.length > 220
169
+ ? `${(lastWordBoundary >= 110 ? summaryStart.slice(0, lastWordBoundary) : summaryStart).trimEnd()}…`
167
170
  : plainSummary;
168
171
 
169
172
  const rights =
@@ -180,6 +183,7 @@ export function summarizeManifest(manifest, manifestUri = '') {
180
183
  version,
181
184
  label,
182
185
  summary: compactSummary,
186
+ fullSummary: plainSummary,
183
187
  rights,
184
188
  rightsLabel: formatRightsLabel(rights),
185
189
  thumbnail,
@@ -219,6 +223,7 @@ export async function fetchManifestSummary(uri) {
219
223
  version: 'IIIF',
220
224
  label: uri,
221
225
  summary: `Unable to load manifest (${err?.message || 'CORS or network error'}).`,
226
+ fullSummary: `Unable to load manifest (${err?.message || 'CORS or network error'}).`,
222
227
  rights: 'Unavailable',
223
228
  rightsLabel: 'Unavailable',
224
229
  thumbnail: null,
package/src/demo.html CHANGED
@@ -6,11 +6,15 @@
6
6
  <title>@micropasts/iiif-manifest-summary — IIIF Summary Demo</title>
7
7
  <script>
8
8
  (function () {
9
- const saved = localStorage.getItem('iiif-demo-theme');
10
- const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
11
- if (saved === 'dark' || (!saved && prefersDark)) {
12
- document.documentElement.classList.add('dark');
13
- }
9
+ const systemTheme = window.matchMedia('(prefers-color-scheme: dark)');
10
+ const applyTheme = () => {
11
+ const saved = localStorage.getItem('iiif-demo-theme');
12
+ document.documentElement.classList.toggle(
13
+ 'dark', saved === 'dark' || (saved !== 'light' && systemTheme.matches)
14
+ );
15
+ };
16
+ applyTheme();
17
+ systemTheme.addEventListener('change', applyTheme);
14
18
  })();
15
19
  </script>
16
20
  <script src="https://cdn.tailwindcss.com"></script>
package/src/shadow.js CHANGED
@@ -136,10 +136,11 @@ export class IiifManifestSummary extends HTMLElement {
136
136
  .thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 4px; flex-shrink: 0; border: 1px solid var(--iiif-border); }
137
137
  .title { font-weight: 700; font-size: 15px; line-height: 1.3; }
138
138
  .summary { margin: 8px 0; font-size: 12.5px; line-height: 1.45; color: var(--iiif-fg); }
139
+ .summary-toggle { margin-top: -4px; }
139
140
  .meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 6px; margin: 8px 0; padding: 8px; border-radius: 4px; background: var(--iiif-surface); font-size: 11px; }
140
141
  .meta span { display: block; color: var(--iiif-muted); }
141
142
  .footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--iiif-border); padding-top: 8px; margin-top: 8px; font-size: 11px; }
142
- .rights { color: var(--iiif-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
143
+ .rights { display: inline-block; max-width: 100%; box-sizing: border-box; padding: 2px 6px; border: 1px solid var(--iiif-border); border-radius: 4px; background: var(--iiif-surface); color: var(--iiif-fg); font-weight: 500; overflow-wrap: anywhere; }
143
144
  .btns { display: flex; gap: 6px; }
144
145
  button { font-size: 11px; padding: 3px 8px; border-radius: 4px; border: 1px solid var(--iiif-border); background: transparent; color: inherit; cursor: pointer; }
145
146
  button:hover { background: var(--iiif-surface); }
@@ -170,6 +171,7 @@ export class IiifManifestSummary extends HTMLElement {
170
171
  </div>
171
172
  </div>
172
173
  ${d.summary ? `<p part="summary" class="summary">${this._esc(d.summary)}</p>` : ''}
174
+ ${d.fullSummary && d.fullSummary !== d.summary ? '<button type="button" class="summary-toggle" aria-expanded="false">Read more</button>' : ''}
173
175
  ${
174
176
  d.metadata?.length
175
177
  ? `<div part="meta" class="meta">${d.metadata
@@ -178,7 +180,7 @@ export class IiifManifestSummary extends HTMLElement {
178
180
  : ''
179
181
  }
180
182
  <div class="footer">
181
- <span class="rights" title="${this._esc(d.rights)}">Rights: ${this._esc(d.rightsLabel || d.rights)}</span>
183
+ <span part="rights" class="rights" title="${this._esc(d.rights)}">Rights: ${this._esc(d.rightsLabel || d.rights)}</span>
182
184
  <div class="btns">
183
185
  <button type="button" class="copy-uri" data-uri="${this._esc(d.uri)}">Copy URI</button>
184
186
  <button type="button" class="select-btn">Inspect</button>
@@ -191,6 +193,14 @@ export class IiifManifestSummary extends HTMLElement {
191
193
  </dialog>` : ''}
192
194
  `;
193
195
 
196
+ this.shadowRoot.querySelector('.summary-toggle')?.addEventListener('click', (event) => {
197
+ const button = event.currentTarget;
198
+ const expanded = button.getAttribute('aria-expanded') === 'true';
199
+ this.shadowRoot.querySelector('.summary').textContent = expanded ? d.summary : d.fullSummary;
200
+ button.setAttribute('aria-expanded', String(!expanded));
201
+ button.textContent = expanded ? 'Read more' : 'Read less';
202
+ });
203
+
194
204
  const lightbox = this.shadowRoot.querySelector('.lightbox');
195
205
  this.shadowRoot.querySelector('[data-open-lightbox]')?.addEventListener('click', () => {
196
206
  if (typeof lightbox?.showModal === 'function') lightbox.showModal();
package/src/tailwind.js CHANGED
@@ -47,7 +47,7 @@ export class IiifManifestSummaryTailwind extends HTMLElement {
47
47
 
48
48
  async load(url) {
49
49
  const c = IiifManifestSummaryTailwind.classes;
50
- this.innerHTML = `<div class="${c.card} text-xs text-zinc-500 animate-pulse">Loading IIIF manifest summary…</div>`;
50
+ this.innerHTML = `<div class="${c.card} text-xs text-zinc-500 dark:text-zinc-400 animate-pulse">Loading IIIF manifest summary…</div>`;
51
51
  this._data = await fetchManifestSummary(url);
52
52
  this._renderData();
53
53
  }
@@ -83,20 +83,21 @@ export class IiifManifestSummaryTailwind extends HTMLElement {
83
83
  </div>
84
84
 
85
85
  ${d.summary ? `<p class="mt-2 text-xs leading-relaxed text-zinc-700 dark:text-zinc-300">${this._esc(d.summary)}</p>` : ''}
86
+ ${d.fullSummary && d.fullSummary !== d.summary ? `<button type="button" data-iiif-summary-toggle aria-expanded="false" class="${c.btn} mt-1">Read more</button>` : ''}
86
87
 
87
88
  ${
88
89
  d.metadata?.length
89
90
  ? `<div class="mt-2.5 grid grid-cols-2 gap-2 rounded-md bg-zinc-50 dark:bg-zinc-950/70 p-2 text-xs border border-zinc-200/70 dark:border-zinc-800">${d.metadata
90
91
  .map(
91
92
  (m) =>
92
- `<div><span class="block text-[10px] uppercase tracking-wide text-zinc-500">${this._esc(m.label)}</span><strong class="font-medium text-zinc-900 dark:text-zinc-100">${this._esc(m.value)}</strong></div>`
93
+ `<div><span class="block text-[10px] uppercase tracking-wide text-zinc-500 dark:text-zinc-400">${this._esc(m.label)}</span><strong class="font-medium text-zinc-900 dark:text-zinc-100">${this._esc(m.value)}</strong></div>`
93
94
  )
94
95
  .join('')}</div>`
95
96
  : ''
96
97
  }
97
98
 
98
99
  <div class="mt-3 flex flex-wrap items-center justify-between gap-2 border-t border-zinc-200 dark:border-zinc-800 pt-2 text-[11px]">
99
- <span class="truncate max-w-[200px] text-zinc-500 dark:text-zinc-400" title="${this._esc(d.rights)}">Rights: ${this._esc(d.rightsLabel || d.rights)}</span>
100
+ <span class="inline-block max-w-full break-words rounded border border-zinc-200 dark:border-zinc-700 bg-zinc-100 dark:bg-zinc-800 px-1.5 py-0.5 font-medium text-zinc-800 dark:text-zinc-200" title="${this._esc(d.rights)}">Rights: ${this._esc(d.rightsLabel || d.rights)}</span>
100
101
  <div class="flex items-center gap-1.5">
101
102
  <button type="button" data-iiif-copy data-uri="${this._esc(d.uri)}" class="${c.btn}">Copy URI</button>
102
103
  <button type="button" data-iiif-select class="${c.btn}">Inspect</button>
@@ -109,6 +110,14 @@ export class IiifManifestSummaryTailwind extends HTMLElement {
109
110
  </dialog>` : ''}
110
111
  `;
111
112
 
113
+ this.querySelector('[data-iiif-summary-toggle]')?.addEventListener('click', (event) => {
114
+ const button = event.currentTarget;
115
+ const expanded = button.getAttribute('aria-expanded') === 'true';
116
+ button.previousElementSibling.textContent = expanded ? d.summary : d.fullSummary;
117
+ button.setAttribute('aria-expanded', String(!expanded));
118
+ button.textContent = expanded ? 'Read more' : 'Read less';
119
+ });
120
+
112
121
  const lightbox = this.querySelector('[data-iiif-lightbox]');
113
122
  this.querySelector('[data-open-lightbox]')?.addEventListener('click', () => {
114
123
  if (typeof lightbox?.showModal === 'function') lightbox.showModal();