@micropasts/iiif-manifest-summary 0.1.1 → 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.
@@ -307,6 +313,7 @@ The returned shape is:
307
313
  version: 'IIIF v3',
308
314
  label: 'Manifest title',
309
315
  summary: 'Short description',
316
+ fullSummary: 'Short description',
310
317
  rights: 'http://creativecommons.org/licenses/by/4.0/',
311
318
  rightsLabel: 'CC BY 4.0',
312
319
  thumbnail: 'https://example.org/thumbnail.jpg',
@@ -323,6 +330,7 @@ The normalizer:
323
330
 
324
331
  - Detects v3 from a Presentation 3 context or a top-level `items` array
325
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)
326
334
  - Uses v3 `rights`, or v2 `license`
327
335
  - Checks a v3 manifest thumbnail, v2 sequence thumbnail, or v3 first-canvas thumbnail
328
336
  - Counts `items` that are canvases or falls back to v2 sequence canvases
@@ -348,6 +356,7 @@ The request sends `Accept: application/json`. Concurrent requests for the same U
348
356
  version: 'IIIF',
349
357
  label: uri,
350
358
  summary: 'Unable to load manifest (HTTP 404).',
359
+ fullSummary: 'Unable to load manifest (HTTP 404).',
351
360
  rights: 'Unavailable',
352
361
  thumbnail: null,
353
362
  canvasCount: 0,
@@ -411,10 +420,16 @@ Converts common Creative Commons and RightsStatements URIs into readable labels.
411
420
  formatRightsLabel('http://creativecommons.org/licenses/by-sa/4.0/');
412
421
  // 'CC BY-SA 4.0'
413
422
 
423
+ formatRightsLabel('http://creativecommons.org/licenses/cc-by/4.0/');
424
+ // 'CC BY 4.0'
425
+
414
426
  formatRightsLabel('http://rightsstatements.org/vocab/InC-EDU/1.0/');
415
427
  // 'In Copyright - Educational Use'
416
428
  ```
417
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
+
418
433
  ## Demo
419
434
 
420
435
  Run the local demo:
@@ -442,6 +457,29 @@ The build script creates:
442
457
 
443
458
  The IIFE build exposes the package API through `window.IiifManifestSummaryLib`.
444
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
+
445
483
  ## Browser support
446
484
 
447
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();
@@ -597,6 +612,7 @@ 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
@@ -610,7 +626,7 @@ export class IiifManifestSummaryTailwind extends HTMLElement {
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();
@@ -595,6 +610,7 @@ 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
@@ -608,7 +624,7 @@ class IiifManifestSummaryTailwind extends HTMLElement {
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.1",
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",
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/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
@@ -83,6 +83,7 @@ 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
@@ -96,7 +97,7 @@ export class IiifManifestSummaryTailwind extends HTMLElement {
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();