@uvalib/web-components 1.6.0 → 1.8.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/CHANGELOG.md +36 -0
- package/README.md +133 -12
- package/dist/base/states.d.ts +12 -0
- package/dist/base/states.js +33 -0
- package/dist/base/states.js.map +1 -0
- package/dist/base.css +15 -5
- package/dist/components/bento-box/BentoBox.js +1 -0
- package/dist/components/bento-box/BentoBox.js.map +1 -1
- package/dist/components/events-section/EventsSection.js +1 -0
- package/dist/components/events-section/EventsSection.js.map +1 -1
- package/dist/components/library-hours/hours-data.js +1 -1
- package/dist/components/library-hours/hours-data.js.map +1 -1
- package/dist/components/library-weekly-hours/LibraryWeeklyHours.js +1 -0
- package/dist/components/library-weekly-hours/LibraryWeeklyHours.js.map +1 -1
- package/dist/components/uvalib-card/UvalibCard.js +6 -0
- package/dist/components/uvalib-card/UvalibCard.js.map +1 -1
- package/dist/components/uvalib-combobox/UvalibCombobox.d.ts +27 -0
- package/dist/components/uvalib-combobox/UvalibCombobox.js +85 -1
- package/dist/components/uvalib-combobox/UvalibCombobox.js.map +1 -1
- package/dist/components/uvalib-contents/UvalibContents.js +5 -0
- package/dist/components/uvalib-contents/UvalibContents.js.map +1 -1
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.d.ts +6 -0
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js +10 -0
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js.map +1 -1
- package/dist/components/uvalib-image-regions/UvalibImageRegions.d.ts +1 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.js +4 -1
- package/dist/components/uvalib-image-regions/UvalibImageRegions.js.map +1 -1
- package/dist/components/uvalib-image-regions/regions.d.ts +6 -2
- package/dist/components/uvalib-image-regions/regions.js +6 -3
- package/dist/components/uvalib-image-regions/regions.js.map +1 -1
- package/dist/components/uvalib-lightbox/UvalibLightbox.d.ts +100 -7
- package/dist/components/uvalib-lightbox/UvalibLightbox.js +310 -83
- package/dist/components/uvalib-lightbox/UvalibLightbox.js.map +1 -1
- package/dist/components/uvalib-lightbox/compare.d.ts +48 -8
- package/dist/components/uvalib-lightbox/compare.js +226 -22
- package/dist/components/uvalib-lightbox/compare.js.map +1 -1
- package/dist/components/uvalib-map/UvalibMap.js +2 -2
- package/dist/components/uvalib-map/UvalibMap.js.map +1 -1
- package/dist/components/uvalib-metadata/UvalibMetadata.js +3 -0
- package/dist/components/uvalib-metadata/UvalibMetadata.js.map +1 -1
- package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js +3 -1
- package/dist/components/uvalib-pagefind-search/UvalibPagefindSearch.js.map +1 -1
- package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.d.ts +3 -3
- package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js +16 -8
- package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js.map +1 -1
- package/dist/components/uvalib-tag-list/UvalibTagList.d.ts +4 -1
- package/dist/components/uvalib-tag-list/UvalibTagList.js +9 -2
- package/dist/components/uvalib-tag-list/UvalibTagList.js.map +1 -1
- package/dist/custom-elements.json +596 -19
- package/dist/styles/message.js +4 -0
- package/dist/styles/message.js.map +1 -1
- package/dist/styles/result-list.js +25 -4
- package/dist/styles/result-list.js.map +1 -1
- package/dist/styles/results.js +17 -2
- package/dist/styles/results.js.map +1 -1
- package/dist-cdn/base.css +15 -5
- package/dist-cdn/bento-box.js +1 -0
- package/dist-cdn/bento-box.js.map +1 -1
- package/dist-cdn/chunks/{compare-D4VdaIJN.js → compare-C0nhByn7.js} +185 -56
- package/dist-cdn/chunks/compare-C0nhByn7.js.map +1 -0
- package/dist-cdn/chunks/{hours-data-Bw6vkIw7.js → hours-data-gMu5uT7H.js} +2 -2
- package/dist-cdn/chunks/hours-data-gMu5uT7H.js.map +1 -0
- package/dist-cdn/chunks/{library-weekly-hours-CrV3TlP5.js → library-weekly-hours-BJgxAyah.js} +3 -2
- package/dist-cdn/chunks/library-weekly-hours-BJgxAyah.js.map +1 -0
- package/dist-cdn/chunks/{regions-B8ExwUGP.js → regions-B-rOwa-v.js} +15 -15
- package/dist-cdn/chunks/regions-B-rOwa-v.js.map +1 -0
- package/dist-cdn/chunks/states-DGXGzcte.js +17 -0
- package/dist-cdn/chunks/states-DGXGzcte.js.map +1 -0
- package/dist-cdn/custom-elements.json +596 -19
- package/dist-cdn/events-section.js +1 -0
- package/dist-cdn/events-section.js.map +1 -1
- package/dist-cdn/library-hours-setup.js +1 -1
- package/dist-cdn/library-weekly-hours.js +1 -1
- package/dist-cdn/manifest.json +1 -1
- package/dist-cdn/site-hours-section.js +1 -1
- package/dist-cdn/skills/uvalib-web-components/SKILL.md +8 -6
- package/dist-cdn/skills/uvalib-web-components/reference/components.md +37 -6
- package/dist-cdn/uvalib-card.js +6 -0
- package/dist-cdn/uvalib-card.js.map +1 -1
- package/dist-cdn/uvalib-combobox.js +107 -68
- package/dist-cdn/uvalib-combobox.js.map +1 -1
- package/dist-cdn/uvalib-contents.js +5 -0
- package/dist-cdn/uvalib-contents.js.map +1 -1
- package/dist-cdn/uvalib-filter-drawer.js +27 -25
- package/dist-cdn/uvalib-filter-drawer.js.map +1 -1
- package/dist-cdn/uvalib-image-regions.js +4 -2
- package/dist-cdn/uvalib-image-regions.js.map +1 -1
- package/dist-cdn/uvalib-lightbox.js +230 -129
- package/dist-cdn/uvalib-lightbox.js.map +1 -1
- package/dist-cdn/uvalib-map.js +2 -2
- package/dist-cdn/uvalib-map.js.map +1 -1
- package/dist-cdn/uvalib-metadata.js +3 -0
- package/dist-cdn/uvalib-metadata.js.map +1 -1
- package/dist-cdn/uvalib-pagefind-search.js +2 -1
- package/dist-cdn/uvalib-pagefind-search.js.map +1 -1
- package/dist-cdn/uvalib-photo-grid.js +4 -5
- package/dist-cdn/uvalib-photo-grid.js.map +1 -1
- package/dist-cdn/uvalib-tag-list.js +21 -16
- package/dist-cdn/uvalib-tag-list.js.map +1 -1
- package/package.json +1 -1
- package/skills/uvalib-web-components/SKILL.md +8 -6
- package/skills/uvalib-web-components/reference/components.md +37 -6
- package/dist-cdn/chunks/compare-D4VdaIJN.js.map +0 -1
- package/dist-cdn/chunks/hours-data-Bw6vkIw7.js.map +0 -1
- package/dist-cdn/chunks/library-weekly-hours-CrV3TlP5.js.map +0 -1
- package/dist-cdn/chunks/regions-B8ExwUGP.js.map +0 -1
|
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { css, html, nothing, unsafeCSS } from 'lit';
|
|
8
8
|
import { property, state } from 'lit/decorators.js';
|
|
9
9
|
import { trackEvent } from '../../base/analytics.js';
|
|
10
|
+
import { attachStateInternals, setState } from '../../base/states.js';
|
|
10
11
|
import { UvalibElement } from '../../base/UvalibElement.js';
|
|
11
12
|
import { installLightDomStyles } from '../../base/light-dom-styles.js';
|
|
12
13
|
import { accessible } from '../../styles/accessible.js';
|
|
@@ -14,6 +15,8 @@ import { parseRegions, toRegion } from '../uvalib-image-regions/regions.js';
|
|
|
14
15
|
import { hrefWithParam, iiifIdentifier, paramFromLocation, sizedIiifUrl, usableImageUrl, usesHashParam, viewportIiifSize, } from './media.js';
|
|
15
16
|
/** The slot (shadow mode) a page's region list is lent to while its image is open. */
|
|
16
17
|
const LIST_SLOT = 'uvalib-regions-list';
|
|
18
|
+
/** The slot (shadow mode) a `data-details-id` element is lent to while its image is open. */
|
|
19
|
+
const DETAILS_SLOT = 'uvalib-details';
|
|
17
20
|
/** Attributes `<uvalib-image-regions>` puts on a list's entries. */
|
|
18
21
|
const ENTRY_MARKS = ['data-uvalib-region', 'data-uvalib-active'];
|
|
19
22
|
const positive = (v) => {
|
|
@@ -69,6 +72,7 @@ const structuralRules = (host) => `
|
|
|
69
72
|
}
|
|
70
73
|
${host} .regions { display: block; }
|
|
71
74
|
${host} .stack { position: relative; width: fit-content; max-width: 100%; margin-inline: auto; }
|
|
75
|
+
${host} .stack.starting > * { visibility: hidden !important; }
|
|
72
76
|
${host} .details:empty { display: none; }
|
|
73
77
|
${host} > [slot="details"] { display: none; }
|
|
74
78
|
${host}[hidden], ${host} [hidden] { display: none !important; }
|
|
@@ -78,6 +82,8 @@ let nextCaption = 0;
|
|
|
78
82
|
/** The comparison UI, loaded the first time an open image has versions. */
|
|
79
83
|
let compareModule = null;
|
|
80
84
|
let compareLoading = null;
|
|
85
|
+
/** The comparison could not be loaded: an image opening on another version shows the original. */
|
|
86
|
+
let compareFailed = false;
|
|
81
87
|
/** `<uvalib-image-regions>` is loaded the first time an open image has regions. */
|
|
82
88
|
let regionsLoading = null;
|
|
83
89
|
function loadRegions() {
|
|
@@ -107,7 +113,14 @@ function loadRegions() {
|
|
|
107
113
|
* Optional details: children with `slot="details"` (and `data-for` equal to the item's id or
|
|
108
114
|
* its position from 1; without `data-for` they show for every image), or `data-details-id` on
|
|
109
115
|
* a link pointing at an element elsewhere on the page. Either is shown inside the dialog and
|
|
110
|
-
* put back when the viewer moves on or closes.
|
|
116
|
+
* put back exactly (same place, `hidden` and `slot`) when the viewer moves on or closes. The
|
|
117
|
+
* `data-details-id` element stays in the page (in shadow mode it becomes a child of the
|
|
118
|
+
* lightbox slotted into the dialog), so `getElementById`, the page's CSS (except selectors
|
|
119
|
+
* through its old ancestors) and listeners keep working; nothing is cloned. Details that appear
|
|
120
|
+
* while their image is open (rendered after a fetch) are shown then.
|
|
121
|
+
*
|
|
122
|
+
* `open(idOrIndex)` and `close({ focus })` let the page open or close the viewer itself;
|
|
123
|
+
* `uvalib-lightbox-open` and `uvalib-lightbox-close` say when it did.
|
|
111
124
|
*
|
|
112
125
|
* Optional regions (people, objects, inscriptions): `data-regions` on a link, a JSON array of
|
|
113
126
|
* `{ label, x, y, w, h, unit? }` or `xywh` values each followed by its label, separated by
|
|
@@ -134,11 +147,19 @@ function loadRegions() {
|
|
|
134
147
|
* the image's accessible name ends with the label of the version shown. `version-param`
|
|
135
148
|
* (with `url-param`) keeps the comparison in the address: `?version=2` (Switch, the version
|
|
136
149
|
* from 0), `?version=wipe:40` or `?version=fade:60` (the percentage of the other version
|
|
137
|
-
* shown; `wipe:40:2` compares the original with version 2).
|
|
150
|
+
* shown; `wipe:40:2` compares the original with version 2). `data-version` on a link (the
|
|
151
|
+
* same values) opens that image on that version, from a click, `open()` or Previous and
|
|
152
|
+
* Next; an address with `version-param` wins. A version with a different
|
|
153
|
+
* framing (an AI-expanded frame, a crop, the whole plate) gives `frame`, the original's box
|
|
154
|
+
* in it (`percent:x,y,w,h`, or pixels of its `width` × `height`): the viewer draws every
|
|
155
|
+
* version at the original's scale in one box, the original lined up, and regions stay on it.
|
|
156
|
+
*
|
|
157
|
+
* Pages can style the element while the viewer is open with `:state(open)`.
|
|
138
158
|
*
|
|
139
159
|
* @tagname uvalib-lightbox
|
|
140
160
|
* @slot - The image links. A plain click opens the viewer; without JavaScript they open the image.
|
|
141
161
|
* @slot details - Details for the open image. `data-for` selects one item by its id or position (from 1); without it the details show for every image.
|
|
162
|
+
* @cssstate open - The viewer is open.
|
|
142
163
|
* @csspart dialog - The modal dialog.
|
|
143
164
|
* @csspart panel - The surface inside the dialog.
|
|
144
165
|
* @csspart caption - The caption that names the dialog.
|
|
@@ -147,6 +168,8 @@ function loadRegions() {
|
|
|
147
168
|
* @csspart details - The details panel.
|
|
148
169
|
* @csspart regions - The `<uvalib-image-regions>` around an image with regions.
|
|
149
170
|
* @csspart compare - The version comparison controls and notes under the photo.
|
|
171
|
+
* @fires uvalib-lightbox-open - The viewer opened (a click, `open()`, or restored from the address): `detail` is `{ id, index, restored }` (`index` from 0; `restored` true for the address, Back and Forward). Not fired when it moves to another image. Bubbles and is composed.
|
|
172
|
+
* @fires uvalib-lightbox-close - The viewer closed: `detail` is `{ id, index, reason }`, the image shown and `reason` `close` (Close, Escape, the backdrop), `api` (`close()`), `history` (Back or Forward) or `empty` (the last image left the page). Not fired when the element is removed. Bubbles and is composed.
|
|
150
173
|
* @fires uvalib-lightbox-version - The visitor changed the comparison (mode, version or position; once a slider settles): `detail` is `{ id, mode, index, value }` (`mode` `switch`, `wipe` or `fade`; `index` the version shown or compared, from 0; `value` the percentage of it shown, null for Switch). Not fired on open or for a comparison restored from the URL. Bubbles and is composed.
|
|
151
174
|
* @fires uvalib-analytics-event - For `<site-analytics>`: `['uvalib-lightbox', 'open'|'next'|'previous'|'full-size', 'image N', N]` (N from 1, the image's place in the set), and `['uvalib-lightbox', 'compare', 'switch'|'wipe'|'fade', N]` when the visitor changes a comparison (N the version's place from 1; once a slider settles). Never the URL, the caption or a version's label. Not fired for a viewer restored from the URL or from Back and Forward. Bubbles and is composed.
|
|
152
175
|
* @cssprop --uva-color-surface-raised - Dark-mode role token: dialog surface (else `--uva-color-surface`, else #fff).
|
|
@@ -193,13 +216,14 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
193
216
|
this.versionParam = '';
|
|
194
217
|
this.slides = [];
|
|
195
218
|
this.index = 0;
|
|
196
|
-
this.
|
|
219
|
+
this.shown = false;
|
|
197
220
|
this.status = 'loading';
|
|
198
221
|
this.fitW = 0;
|
|
199
222
|
this.fitH = 0;
|
|
200
223
|
/** The "Show regions" toggle: outlines over an image that has regions. */
|
|
201
224
|
this.showRegions = true;
|
|
202
225
|
this.captionId = `uvalib-lightbox-caption-${++nextCaption}`;
|
|
226
|
+
this.internals = attachStateInternals(this);
|
|
203
227
|
this.trigger = null;
|
|
204
228
|
/** The open image pushed a history entry, so Back (and Close) returns to the page. */
|
|
205
229
|
this.historyPushed = false;
|
|
@@ -232,6 +256,9 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
232
256
|
/** Details elements moved into the dialog, and where they go back to. */
|
|
233
257
|
this.parked = [];
|
|
234
258
|
this.parkedKey = '';
|
|
259
|
+
this.lateDetailsId = '';
|
|
260
|
+
/** The open image after its link left the page: still shown, dropped once the viewer moves on. */
|
|
261
|
+
this.orphan = null;
|
|
235
262
|
/** The page's region list lent to the viewer, and how to give it back as it was. */
|
|
236
263
|
this.lent = null;
|
|
237
264
|
/** Each entry's own `tabindex` (null: none), so one the viewer added is removed. */
|
|
@@ -241,11 +268,11 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
241
268
|
/** The comparison from the address, for the image opened from it. */
|
|
242
269
|
this.pendingVersion = null;
|
|
243
270
|
this.onResize = () => {
|
|
244
|
-
if (!this.
|
|
271
|
+
if (!this.shown)
|
|
245
272
|
return;
|
|
246
273
|
window.clearTimeout(this.resizeTimer);
|
|
247
274
|
this.resizeTimer = window.setTimeout(() => {
|
|
248
|
-
if (this.isConnected && this.
|
|
275
|
+
if (this.isConnected && this.shown)
|
|
249
276
|
this.measure();
|
|
250
277
|
}, 150);
|
|
251
278
|
};
|
|
@@ -283,14 +310,14 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
283
310
|
this.measure();
|
|
284
311
|
const id = queued.slides[queued.i]?.id ?? null;
|
|
285
312
|
this.historyPushed = this.writeParam(id, 'push', this.backInHash);
|
|
286
|
-
if (!this.
|
|
287
|
-
this.
|
|
313
|
+
if (!this.shown)
|
|
314
|
+
this.shown = true;
|
|
288
315
|
return;
|
|
289
316
|
}
|
|
290
317
|
const id = paramFromLocation(this.loc(), this.urlParam);
|
|
291
318
|
if (!id) {
|
|
292
319
|
this.historyPushed = false;
|
|
293
|
-
if (this.
|
|
320
|
+
if (this.shown)
|
|
294
321
|
this.dismiss('pop');
|
|
295
322
|
return;
|
|
296
323
|
}
|
|
@@ -298,7 +325,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
298
325
|
const slides = this.collect();
|
|
299
326
|
const i = slides.findIndex((s) => s.id === id);
|
|
300
327
|
if (i < 0) {
|
|
301
|
-
if (this.
|
|
328
|
+
if (this.shown)
|
|
302
329
|
this.dismiss('pop');
|
|
303
330
|
return;
|
|
304
331
|
}
|
|
@@ -307,10 +334,13 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
307
334
|
this.index = i;
|
|
308
335
|
this.trigger = slides[i]?.el ?? null;
|
|
309
336
|
this.historyPushed = true;
|
|
337
|
+
this.orphan = null;
|
|
310
338
|
this.measure();
|
|
311
339
|
this.armReopenGuard();
|
|
312
|
-
if (!this.
|
|
313
|
-
this.
|
|
340
|
+
if (!this.shown) {
|
|
341
|
+
this.shown = true;
|
|
342
|
+
this.announce('open', { id, index: i, restored: true });
|
|
343
|
+
}
|
|
314
344
|
};
|
|
315
345
|
this.onKey = (e) => {
|
|
316
346
|
if (this.typing(e))
|
|
@@ -379,6 +409,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
379
409
|
font-size: 1.125rem;
|
|
380
410
|
line-height: 1.4;
|
|
381
411
|
font-weight: 600;
|
|
412
|
+
text-wrap: balance;
|
|
382
413
|
}
|
|
383
414
|
.count {
|
|
384
415
|
font-variant-numeric: tabular-nums;
|
|
@@ -505,7 +536,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
505
536
|
// it: do not run history.back(), which could leave the page. `open` goes false so a later
|
|
506
537
|
// connect can open again from the URL.
|
|
507
538
|
this.suppressClose = true;
|
|
508
|
-
this.
|
|
539
|
+
this.shown = false;
|
|
509
540
|
const dialog = this.dialogEl;
|
|
510
541
|
if (dialog?.open)
|
|
511
542
|
dialog.close();
|
|
@@ -514,7 +545,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
514
545
|
}
|
|
515
546
|
willUpdate() {
|
|
516
547
|
this.lendList();
|
|
517
|
-
if (!this.
|
|
548
|
+
if (!this.shown) {
|
|
518
549
|
this.lastSrc = '';
|
|
519
550
|
return;
|
|
520
551
|
}
|
|
@@ -536,17 +567,19 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
536
567
|
}
|
|
537
568
|
updated(changed) {
|
|
538
569
|
super.updated(changed);
|
|
570
|
+
if (changed.has('shown'))
|
|
571
|
+
setState(this.internals, 'open', this.shown);
|
|
539
572
|
if (changed.has('selector'))
|
|
540
573
|
this.watch();
|
|
541
574
|
if ((changed.has('regions') || changed.has('regionsList') || changed.has('versions')) &&
|
|
542
575
|
this.isConnected)
|
|
543
576
|
this.scheduleSync(true);
|
|
544
|
-
if (!this.
|
|
545
|
-
if (changed.has('
|
|
577
|
+
if (!this.shown) {
|
|
578
|
+
if (changed.has('shown'))
|
|
546
579
|
this.restoreDetails();
|
|
547
580
|
return;
|
|
548
581
|
}
|
|
549
|
-
if (changed.has('
|
|
582
|
+
if (changed.has('shown') || changed.has('index') || changed.has('slides'))
|
|
550
583
|
this.placeDetails();
|
|
551
584
|
if (this.current?.regions.length || this.current?.list)
|
|
552
585
|
loadRegions();
|
|
@@ -558,7 +591,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
558
591
|
this.closeBtn?.focus();
|
|
559
592
|
}
|
|
560
593
|
this.bindDialogObserver();
|
|
561
|
-
if (changed.has('
|
|
594
|
+
if (changed.has('shown'))
|
|
562
595
|
this.reveal();
|
|
563
596
|
// Reading the image and writing `status` from inside `updated` makes Lit warn and schedule
|
|
564
597
|
// a nested update. A microtask is still before the next paint.
|
|
@@ -611,6 +644,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
611
644
|
}
|
|
612
645
|
watch() {
|
|
613
646
|
this.observer?.disconnect();
|
|
647
|
+
this.watchedBox = undefined;
|
|
614
648
|
this.observer = new MutationObserver(() => this.scheduleSync());
|
|
615
649
|
this.observer.observe(this, {
|
|
616
650
|
attributes: true,
|
|
@@ -622,9 +656,11 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
622
656
|
'data-caption',
|
|
623
657
|
'data-id',
|
|
624
658
|
'data-details-id',
|
|
659
|
+
'data-for',
|
|
625
660
|
'data-regions',
|
|
626
661
|
'data-regions-list',
|
|
627
662
|
'data-versions',
|
|
663
|
+
'data-version',
|
|
628
664
|
'data-image-width',
|
|
629
665
|
'data-image-height',
|
|
630
666
|
'slot',
|
|
@@ -657,28 +693,47 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
657
693
|
s.caption === this.slides[i]?.caption &&
|
|
658
694
|
s.detailsId === this.slides[i]?.detailsId &&
|
|
659
695
|
s.list === this.slides[i]?.list &&
|
|
660
|
-
JSON.stringify([s.regions, s.imageWidth, s.imageHeight, s.versions]) ===
|
|
696
|
+
JSON.stringify([s.regions, s.imageWidth, s.imageHeight, s.versions, s.start]) ===
|
|
661
697
|
JSON.stringify([
|
|
662
698
|
this.slides[i]?.regions,
|
|
663
699
|
this.slides[i]?.imageWidth,
|
|
664
700
|
this.slides[i]?.imageHeight,
|
|
665
701
|
this.slides[i]?.versions,
|
|
702
|
+
this.slides[i]?.start,
|
|
666
703
|
]));
|
|
667
704
|
this.noteEntries();
|
|
668
705
|
if (!same) {
|
|
669
|
-
const current = this.current
|
|
670
|
-
this.
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
706
|
+
const current = this.current;
|
|
707
|
+
if (!this.shown)
|
|
708
|
+
this.slides = next;
|
|
709
|
+
else {
|
|
710
|
+
const at = current ? next.findIndex((s) => s.el === current.el) : -1;
|
|
711
|
+
if (at >= 0 || !current) {
|
|
712
|
+
this.slides = next;
|
|
713
|
+
this.index = Math.max(at, 0);
|
|
714
|
+
this.orphan = null;
|
|
715
|
+
}
|
|
716
|
+
else if (!next.length) {
|
|
676
717
|
this.dismiss('empty');
|
|
677
|
-
|
|
678
|
-
this.index =
|
|
718
|
+
this.slides = next;
|
|
719
|
+
this.index = 0;
|
|
720
|
+
}
|
|
721
|
+
else {
|
|
722
|
+
// The open image's link left the page (the page deleted it). Keep showing it, so
|
|
723
|
+
// the viewer does not jump to another image while the address names this one; it
|
|
724
|
+
// drops out when the visitor moves on, and the page can call close().
|
|
725
|
+
const k = Math.min(this.index, next.length);
|
|
726
|
+
next.splice(k, 0, current);
|
|
727
|
+
this.slides = next;
|
|
728
|
+
this.index = k;
|
|
729
|
+
this.orphan = current;
|
|
730
|
+
}
|
|
679
731
|
}
|
|
680
732
|
}
|
|
681
|
-
|
|
733
|
+
// Details added, removed or retargeted (`data-for`) while an image is open.
|
|
734
|
+
if (this.shown)
|
|
735
|
+
this.placeDetails();
|
|
736
|
+
else
|
|
682
737
|
this.openFromUrl();
|
|
683
738
|
});
|
|
684
739
|
}
|
|
@@ -716,7 +771,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
716
771
|
return;
|
|
717
772
|
if (this.mount?.contains(a) || a.closest('dialog'))
|
|
718
773
|
return;
|
|
719
|
-
if (a.closest(
|
|
774
|
+
if (a.closest(`[slot="details"], [slot="${DETAILS_SLOT}"]`))
|
|
720
775
|
return;
|
|
721
776
|
// Links in a page's region list are its actions, not images (and it may be lent here).
|
|
722
777
|
if (this.lent?.el.contains(a))
|
|
@@ -774,6 +829,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
774
829
|
imageWidth: positive(el.dataset.imageWidth),
|
|
775
830
|
imageHeight: positive(el.dataset.imageHeight),
|
|
776
831
|
versions: this.versionsOf(el, id, href, index),
|
|
832
|
+
start: normalize(el.dataset.version) || null,
|
|
777
833
|
};
|
|
778
834
|
}
|
|
779
835
|
/** `data-versions` (checked by the comparison module), else the `versions` callback's list. */
|
|
@@ -804,9 +860,11 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
804
860
|
compareLoading ??= import('./compare.js')
|
|
805
861
|
.then((m) => {
|
|
806
862
|
compareModule = m;
|
|
863
|
+
compareFailed = false;
|
|
807
864
|
})
|
|
808
865
|
.catch((err) => {
|
|
809
866
|
compareLoading = null;
|
|
867
|
+
compareFailed = true;
|
|
810
868
|
console.warn('uvalib-lightbox: could not load the version comparison.', err);
|
|
811
869
|
});
|
|
812
870
|
void compareLoading.then(() => {
|
|
@@ -824,7 +882,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
824
882
|
mode: () => this.compare,
|
|
825
883
|
size: (href) => this.sized(href),
|
|
826
884
|
write: (value) => {
|
|
827
|
-
if (this.versionParam && this.
|
|
885
|
+
if (this.versionParam && this.shown)
|
|
828
886
|
this.writeParam(this.current?.id ?? null, 'replace', undefined, value);
|
|
829
887
|
},
|
|
830
888
|
update: () => this.requestUpdate(),
|
|
@@ -925,19 +983,56 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
925
983
|
const t = e.target;
|
|
926
984
|
return t instanceof Element ? t.closest('a[href]') : null;
|
|
927
985
|
}
|
|
986
|
+
/**
|
|
987
|
+
* Opens an item as a click on its link would: `item` is its id (as `url-param` writes it)
|
|
988
|
+
* or its place in the set from 0. Returns false when there is no such item. Focus goes back
|
|
989
|
+
* to the item's link on close. With the viewer open it shows that item instead. Fires
|
|
990
|
+
* `uvalib-lightbox-open` (when the viewer was closed), not analytics: it is the page's call.
|
|
991
|
+
*/
|
|
992
|
+
open(item) {
|
|
993
|
+
if (!this.isConnected)
|
|
994
|
+
return false;
|
|
995
|
+
const slides = this.collect();
|
|
996
|
+
const i = typeof item === 'number'
|
|
997
|
+
? Number.isInteger(item) && item >= 0 && item < slides.length
|
|
998
|
+
? item
|
|
999
|
+
: -1
|
|
1000
|
+
: slides.findIndex((s) => s.id === item);
|
|
1001
|
+
if (i < 0)
|
|
1002
|
+
return false;
|
|
1003
|
+
this.activate(i, slides, false);
|
|
1004
|
+
return true;
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Closes the viewer as Close does, `url-param` and `version-param` included (Back when the
|
|
1008
|
+
* viewer pushed the entry, else they are removed). Focus goes to `focus` when given, else to
|
|
1009
|
+
* the item's link; when that link has left the page, to the first image link left, else to
|
|
1010
|
+
* the lightbox itself (made focusable with `tabindex="-1"` until it loses focus). Returns
|
|
1011
|
+
* false when the viewer was not open.
|
|
1012
|
+
*/
|
|
1013
|
+
close(options = {}) {
|
|
1014
|
+
if (!this.shown && !this.dialogEl?.open)
|
|
1015
|
+
return false;
|
|
1016
|
+
this.dismiss('api', options.focus ?? null);
|
|
1017
|
+
return true;
|
|
1018
|
+
}
|
|
1019
|
+
announce(type, detail) {
|
|
1020
|
+
this.dispatchEvent(new CustomEvent(`uvalib-lightbox-${type}`, { detail, bubbles: true, composed: true }));
|
|
1021
|
+
}
|
|
928
1022
|
/** A visitor chose `slides[i]`. The first open pushes a history entry; a later choice replaces it. */
|
|
929
|
-
activate(i, slides) {
|
|
930
|
-
const already = this.
|
|
1023
|
+
activate(i, slides, track = true) {
|
|
1024
|
+
const already = this.shown;
|
|
931
1025
|
if (already && this.index === i)
|
|
932
1026
|
return;
|
|
933
1027
|
this.slides = slides;
|
|
934
1028
|
this.index = i;
|
|
1029
|
+
this.orphan = null;
|
|
935
1030
|
this.trigger = slides[i]?.el ?? null;
|
|
936
1031
|
this.userClosed = false;
|
|
937
1032
|
this.pendingVersion = null;
|
|
938
1033
|
this.cmp?.reset();
|
|
939
1034
|
this.measure();
|
|
940
|
-
this.
|
|
1035
|
+
this.shown = true;
|
|
941
1036
|
if (this.pendingBack) {
|
|
942
1037
|
// Close already asked for history.back(). Writing now would push on the entry that
|
|
943
1038
|
// popstate is about to remove, and that pop would shut the viewer again.
|
|
@@ -958,11 +1053,14 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
958
1053
|
this.historyPushed = this.writeParam(id, 'push', hashMode);
|
|
959
1054
|
}
|
|
960
1055
|
}
|
|
961
|
-
|
|
1056
|
+
if (track)
|
|
1057
|
+
trackEvent(this, ['uvalib-lightbox', 'open', `image ${i + 1}`, i + 1]);
|
|
1058
|
+
if (!already)
|
|
1059
|
+
this.announce('open', { id: slides[i]?.id ?? '', index: i, restored: false });
|
|
962
1060
|
}
|
|
963
1061
|
/** Restore a viewer the URL already points at. No analytics: it is not a new action. */
|
|
964
1062
|
openFromUrl() {
|
|
965
|
-
if (this.
|
|
1063
|
+
if (this.shown || this.userClosed || !this.urlParam)
|
|
966
1064
|
return;
|
|
967
1065
|
const id = paramFromLocation(this.loc(), this.urlParam);
|
|
968
1066
|
if (!id)
|
|
@@ -982,16 +1080,26 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
982
1080
|
const hashMode = usesHashParam(location.hash);
|
|
983
1081
|
this.writeParam(null, 'replace', hashMode);
|
|
984
1082
|
this.historyPushed = this.writeParam(id, 'push', hashMode, version);
|
|
985
|
-
this.
|
|
1083
|
+
this.orphan = null;
|
|
1084
|
+
this.shown = true;
|
|
1085
|
+
this.announce('open', { id, index: i, restored: true });
|
|
986
1086
|
}
|
|
987
1087
|
versionFromUrl() {
|
|
988
1088
|
return this.versionParam ? paramFromLocation(this.loc(), this.versionParam) : null;
|
|
989
1089
|
}
|
|
990
1090
|
step(delta) {
|
|
991
|
-
|
|
1091
|
+
let n = this.slides.length;
|
|
992
1092
|
if (n < 2)
|
|
993
1093
|
return;
|
|
994
|
-
|
|
1094
|
+
let i = (this.index + delta + n) % n;
|
|
1095
|
+
if (this.orphan && this.current === this.orphan) {
|
|
1096
|
+
// Moving on from an image whose link has gone: it leaves the set.
|
|
1097
|
+
const at = this.index;
|
|
1098
|
+
this.slides = this.slides.filter((s) => s !== this.orphan);
|
|
1099
|
+
this.orphan = null;
|
|
1100
|
+
n = this.slides.length;
|
|
1101
|
+
i = delta > 0 ? at % n : (at - 1 + n) % n;
|
|
1102
|
+
}
|
|
995
1103
|
this.index = i;
|
|
996
1104
|
this.pendingVersion = null;
|
|
997
1105
|
this.trigger = this.slides[i]?.el ?? this.trigger;
|
|
@@ -1005,27 +1113,29 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
1005
1113
|
* param). `pop` is the browser already moving: the URL is already right. `empty` is the
|
|
1006
1114
|
* last image leaving the page: drop the param and do not reopen from it.
|
|
1007
1115
|
*/
|
|
1008
|
-
dismiss(source) {
|
|
1116
|
+
dismiss(source, focus = null) {
|
|
1009
1117
|
if (this.dismissing)
|
|
1010
1118
|
return;
|
|
1011
1119
|
const dialog = this.dialogEl;
|
|
1012
|
-
if (!this.
|
|
1120
|
+
if (!this.shown && !dialog?.open)
|
|
1013
1121
|
return;
|
|
1014
1122
|
this.dismissing = true;
|
|
1123
|
+
const was = { id: this.current?.id ?? '', index: this.index };
|
|
1124
|
+
const fromUi = source === 'ui' || source === 'api';
|
|
1015
1125
|
this.cmp?.reset();
|
|
1016
1126
|
try {
|
|
1017
1127
|
const pushed = this.historyPushed;
|
|
1018
1128
|
this.historyPushed = false;
|
|
1019
1129
|
this.ignoreClose = true;
|
|
1020
1130
|
this.cancelReveal();
|
|
1021
|
-
this.
|
|
1022
|
-
if (
|
|
1131
|
+
this.shown = false;
|
|
1132
|
+
if (fromUi || source === 'empty')
|
|
1023
1133
|
this.userClosed = true;
|
|
1024
1134
|
this.restoreDetails();
|
|
1025
1135
|
if (dialog?.open)
|
|
1026
1136
|
dialog.close();
|
|
1027
|
-
this.
|
|
1028
|
-
if (
|
|
1137
|
+
this.focusAfterClose(focus);
|
|
1138
|
+
if (fromUi && this.urlParam) {
|
|
1029
1139
|
if (pushed) {
|
|
1030
1140
|
this.backInHash = usesHashParam(location.hash);
|
|
1031
1141
|
this.pendingBack = true;
|
|
@@ -1039,6 +1149,9 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
1039
1149
|
this.queuedOpen = null;
|
|
1040
1150
|
this.writeParam(null, 'replace', usesHashParam(location.hash));
|
|
1041
1151
|
}
|
|
1152
|
+
this.orphan = null;
|
|
1153
|
+
const reason = source === 'ui' ? 'close' : source === 'pop' ? 'history' : source;
|
|
1154
|
+
this.announce('close', { ...was, reason });
|
|
1042
1155
|
}
|
|
1043
1156
|
finally {
|
|
1044
1157
|
// Leave `ignoreClose` set. `dialog.close()` can queue a second close event for the
|
|
@@ -1118,14 +1231,14 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
1118
1231
|
* event after `showModal`, or a history traversal) is not the visitor dismissing it.
|
|
1119
1232
|
*/
|
|
1120
1233
|
onNativeClose() {
|
|
1121
|
-
if (this.ignoreClose || this.suppressClose || !this.
|
|
1234
|
+
if (this.ignoreClose || this.suppressClose || !this.shown)
|
|
1122
1235
|
return;
|
|
1123
1236
|
if (this.dialogEl?.open)
|
|
1124
1237
|
return;
|
|
1125
1238
|
if (this.reopenGuard) {
|
|
1126
1239
|
const view = this.ownerDocument.defaultView;
|
|
1127
1240
|
view?.queueMicrotask(() => {
|
|
1128
|
-
if (this.
|
|
1241
|
+
if (this.shown && this.isConnected && !this.dialogEl?.open)
|
|
1129
1242
|
this.reveal();
|
|
1130
1243
|
});
|
|
1131
1244
|
return;
|
|
@@ -1141,10 +1254,33 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
1141
1254
|
get detailsBox() {
|
|
1142
1255
|
return this.renderRoot.querySelector('.details');
|
|
1143
1256
|
}
|
|
1144
|
-
|
|
1257
|
+
/**
|
|
1258
|
+
* Focus after a close: `focus` when the page gave one, else the trigger; when the trigger
|
|
1259
|
+
* has left the page, the first image link left, else the lightbox itself (focusable with
|
|
1260
|
+
* `tabindex="-1"` until it loses focus), so focus is never dropped on the body.
|
|
1261
|
+
*/
|
|
1262
|
+
focusAfterClose(focus) {
|
|
1263
|
+
if (focus?.isConnected) {
|
|
1264
|
+
focus.focus();
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1145
1267
|
const trigger = this.trigger;
|
|
1146
|
-
if (trigger?.isConnected)
|
|
1268
|
+
if (trigger?.isConnected && !trigger.closest('[hidden]')) {
|
|
1147
1269
|
trigger.focus();
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
if (!this.isConnected)
|
|
1273
|
+
return;
|
|
1274
|
+
const first = this.collect()[0]?.el;
|
|
1275
|
+
if (first) {
|
|
1276
|
+
first.focus();
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
if (!this.hasAttribute('tabindex')) {
|
|
1280
|
+
this.setAttribute('tabindex', '-1');
|
|
1281
|
+
this.addEventListener('blur', () => this.removeAttribute('tabindex'), { once: true });
|
|
1282
|
+
}
|
|
1283
|
+
this.focus();
|
|
1148
1284
|
}
|
|
1149
1285
|
/**
|
|
1150
1286
|
* Open the dialog and focus Close. `showModal` can throw while a dialog is still leaving
|
|
@@ -1172,7 +1308,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
1172
1308
|
reveal() {
|
|
1173
1309
|
this.ensureRoot();
|
|
1174
1310
|
const dialog = this.dialogEl;
|
|
1175
|
-
if (!this.
|
|
1311
|
+
if (!this.shown || !dialog)
|
|
1176
1312
|
return;
|
|
1177
1313
|
const again = () => {
|
|
1178
1314
|
if (this.revealTries++ > 8) {
|
|
@@ -1184,7 +1320,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
1184
1320
|
return;
|
|
1185
1321
|
this.revealFrame = view.requestAnimationFrame(() => {
|
|
1186
1322
|
this.revealFrame = 0;
|
|
1187
|
-
if (this.
|
|
1323
|
+
if (this.shown)
|
|
1188
1324
|
this.reveal();
|
|
1189
1325
|
});
|
|
1190
1326
|
};
|
|
@@ -1258,54 +1394,140 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
1258
1394
|
return !!slide?.detailsId && el.id === slide.detailsId;
|
|
1259
1395
|
});
|
|
1260
1396
|
}
|
|
1397
|
+
/**
|
|
1398
|
+
* Show the open image's details. `slot="details"` children move into the details panel. A
|
|
1399
|
+
* `data-details-id` element stays in the page: in shadow mode it becomes a light-DOM child of
|
|
1400
|
+
* the lightbox slotted into the panel (so `getElementById`, the page's CSS and its listeners
|
|
1401
|
+
* keep working); in light DOM it moves into the panel, which is in the page too. Nothing is
|
|
1402
|
+
* cloned. Called again for late details; a key keeps it from moving anything twice.
|
|
1403
|
+
*/
|
|
1261
1404
|
placeDetails() {
|
|
1262
1405
|
const want = this.matchingDetails();
|
|
1263
1406
|
const key = `${want.map((el) => this.detailToken(el)).join('|')}@${this.index}`;
|
|
1264
|
-
if (key
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1407
|
+
if (key !== this.parkedKey) {
|
|
1408
|
+
const keep = new Set(want);
|
|
1409
|
+
const still = [];
|
|
1410
|
+
for (const item of this.parked) {
|
|
1411
|
+
if (keep.has(item.el) && item.el.parentNode === item.at)
|
|
1412
|
+
still.push(item);
|
|
1413
|
+
else
|
|
1414
|
+
this.putBack(item);
|
|
1415
|
+
}
|
|
1416
|
+
this.parked = still;
|
|
1417
|
+
const box = this.detailsBox;
|
|
1418
|
+
if (box) {
|
|
1419
|
+
for (const el of want) {
|
|
1420
|
+
if (still.some((item) => item.el === el))
|
|
1421
|
+
continue;
|
|
1422
|
+
const parent = el.parentNode;
|
|
1423
|
+
if (!parent)
|
|
1424
|
+
continue;
|
|
1425
|
+
const slotted = !this.isLight && el.getAttribute('slot') !== 'details';
|
|
1426
|
+
const at = slotted ? this : box;
|
|
1427
|
+
this.parked.push({
|
|
1428
|
+
el,
|
|
1429
|
+
parent,
|
|
1430
|
+
next: el.nextSibling,
|
|
1431
|
+
hidden: el.hidden,
|
|
1432
|
+
slot: el.getAttribute('slot'),
|
|
1433
|
+
at,
|
|
1434
|
+
});
|
|
1435
|
+
el.hidden = false;
|
|
1436
|
+
if (slotted)
|
|
1437
|
+
el.setAttribute('slot', DETAILS_SLOT);
|
|
1438
|
+
at.appendChild(el);
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
this.parkedKey = key;
|
|
1273
1442
|
}
|
|
1274
|
-
this.
|
|
1443
|
+
this.markDetailsBox();
|
|
1444
|
+
this.awaitDetails();
|
|
1445
|
+
}
|
|
1446
|
+
/** The panel shows only while it has something in it. */
|
|
1447
|
+
markDetailsBox() {
|
|
1275
1448
|
const box = this.detailsBox;
|
|
1276
|
-
if (box)
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1449
|
+
if (!box)
|
|
1450
|
+
return;
|
|
1451
|
+
box.hidden = !this.parked.some((item) => item.el.parentNode === item.at);
|
|
1452
|
+
if (!this.isLight && box !== this.watchedBox && this.observer) {
|
|
1453
|
+
// Details moved into the shadow panel leave the lightbox's subtree; a change to their
|
|
1454
|
+
// `data-for` must still be seen.
|
|
1455
|
+
this.watchedBox = box;
|
|
1456
|
+
this.observer.observe(box, {
|
|
1457
|
+
attributes: true,
|
|
1458
|
+
attributeFilter: ['data-for', 'slot'],
|
|
1459
|
+
subtree: true,
|
|
1460
|
+
});
|
|
1287
1461
|
}
|
|
1288
|
-
this.parkedKey = key;
|
|
1289
1462
|
}
|
|
1290
1463
|
/**
|
|
1291
|
-
*
|
|
1292
|
-
*
|
|
1464
|
+
* The open image names a details element that is not in the page yet (a framework renders
|
|
1465
|
+
* it after a fetch): watch this root, only while open and only for that id, and show it
|
|
1466
|
+
* when it appears.
|
|
1467
|
+
*/
|
|
1468
|
+
awaitDetails() {
|
|
1469
|
+
const id = this.shown ? (this.current?.detailsId ?? '') : '';
|
|
1470
|
+
const missing = !!id && !this.scope.getElementById(id);
|
|
1471
|
+
if (!missing) {
|
|
1472
|
+
this.stopAwaitingDetails();
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
if (this.lateDetails && this.lateDetailsId === id)
|
|
1476
|
+
return;
|
|
1477
|
+
this.stopAwaitingDetails();
|
|
1478
|
+
this.lateDetailsId = id;
|
|
1479
|
+
this.lateDetails = new MutationObserver(() => {
|
|
1480
|
+
if (!this.shown || this.current?.detailsId !== id) {
|
|
1481
|
+
this.stopAwaitingDetails();
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
if (this.scope.getElementById(id)) {
|
|
1485
|
+
this.stopAwaitingDetails();
|
|
1486
|
+
this.placeDetails();
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1489
|
+
this.lateDetails.observe(this.scope, {
|
|
1490
|
+
childList: true,
|
|
1491
|
+
subtree: true,
|
|
1492
|
+
attributes: true,
|
|
1493
|
+
attributeFilter: ['id'],
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
stopAwaitingDetails() {
|
|
1497
|
+
this.lateDetails?.disconnect();
|
|
1498
|
+
this.lateDetails = undefined;
|
|
1499
|
+
this.lateDetailsId = '';
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Put a parked element back as it was: same parent and place, same `hidden` and `slot`.
|
|
1503
|
+
* Restoring later siblings first keeps `next` inside `parent`; if it is not (it was parked
|
|
1504
|
+
* too), insert at the end instead of throwing NotFoundError. An element the page has
|
|
1505
|
+
* removed or moved meanwhile stays where the page put it.
|
|
1293
1506
|
*/
|
|
1294
1507
|
putBack(item) {
|
|
1295
|
-
|
|
1508
|
+
const { el } = item;
|
|
1509
|
+
el.hidden = item.hidden;
|
|
1510
|
+
if (item.slot == null)
|
|
1511
|
+
el.removeAttribute('slot');
|
|
1512
|
+
else
|
|
1513
|
+
el.setAttribute('slot', item.slot);
|
|
1514
|
+
if (el.parentNode !== item.at)
|
|
1515
|
+
return;
|
|
1296
1516
|
const next = item.next?.parentNode === item.parent ? item.next : null;
|
|
1297
|
-
item.parent.insertBefore(
|
|
1517
|
+
item.parent.insertBefore(el, next);
|
|
1298
1518
|
}
|
|
1299
1519
|
restoreDetails() {
|
|
1520
|
+
this.stopAwaitingDetails();
|
|
1300
1521
|
for (let i = this.parked.length - 1; i >= 0; i--)
|
|
1301
1522
|
this.putBack(this.parked[i]);
|
|
1302
1523
|
this.parked = [];
|
|
1303
1524
|
this.parkedKey = '';
|
|
1525
|
+
this.markDetailsBox();
|
|
1304
1526
|
this.returnList();
|
|
1305
1527
|
}
|
|
1306
1528
|
/** The list the open image shows (none while its image cannot be drawn). */
|
|
1307
1529
|
get wantedList() {
|
|
1308
|
-
if (!this.
|
|
1530
|
+
if (!this.shown)
|
|
1309
1531
|
return null;
|
|
1310
1532
|
const list = this.current?.list ?? null;
|
|
1311
1533
|
return list && this.displaySrc ? list : null;
|
|
@@ -1368,7 +1590,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
1368
1590
|
const { el } = lent;
|
|
1369
1591
|
const active = this.shadowRoot?.activeElement ?? this.ownerDocument.activeElement;
|
|
1370
1592
|
// Focus in the list would be lost with it; Close takes it while the viewer stays open.
|
|
1371
|
-
if (this.
|
|
1593
|
+
if (this.shown && active && el.contains(active))
|
|
1372
1594
|
this.refocus = true;
|
|
1373
1595
|
for (const li of el.children) {
|
|
1374
1596
|
for (const name of ENTRY_MARKS)
|
|
@@ -1391,7 +1613,7 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
1391
1613
|
lent.parent.insertBefore(el, next);
|
|
1392
1614
|
}
|
|
1393
1615
|
get statusText() {
|
|
1394
|
-
if (!this.
|
|
1616
|
+
if (!this.shown)
|
|
1395
1617
|
return '';
|
|
1396
1618
|
if (this.status === 'loading')
|
|
1397
1619
|
return 'Loading image.';
|
|
@@ -1419,8 +1641,10 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
1419
1641
|
/>`;
|
|
1420
1642
|
let controls = nothing;
|
|
1421
1643
|
if (slide.versions) {
|
|
1644
|
+
// Opening on another version: hidden until the comparison has loaded and drawn it.
|
|
1645
|
+
const waiting = !this.cmp && slide.start && !compareFailed ? 'starting' : '';
|
|
1422
1646
|
img = html `<div
|
|
1423
|
-
class="stack ${cmp?.stackClass ??
|
|
1647
|
+
class="stack ${cmp?.stackClass ?? waiting}"
|
|
1424
1648
|
slot=${outlined ? 'image' : nothing}
|
|
1425
1649
|
style=${cmp?.stackStyle ?? nothing}
|
|
1426
1650
|
@pointerdown=${this.onStack}
|
|
@@ -1447,11 +1671,12 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
1447
1671
|
image-height=${slide.imageHeight ?? nothing}
|
|
1448
1672
|
?hide-outlines=${!this.showRegions}
|
|
1449
1673
|
?no-style=${this.noStyle}
|
|
1674
|
+
style=${cmp?.regionsStyle || nothing}
|
|
1450
1675
|
>${img}${controls}${list}</uvalib-image-regions
|
|
1451
1676
|
>`;
|
|
1452
1677
|
}
|
|
1453
1678
|
render() {
|
|
1454
|
-
const slide = this.
|
|
1679
|
+
const slide = this.shown ? this.current : undefined;
|
|
1455
1680
|
const src = slide ? this.displaySrc : '';
|
|
1456
1681
|
const full = slide && usableImageUrl(slide.href, this.base) ? slide.href : '';
|
|
1457
1682
|
const fullLinks = full && slide?.versions && this.cmp?.active ? this.cmp.full() : null;
|
|
@@ -1511,7 +1736,9 @@ export class UvalibLightbox extends UvalibElement {
|
|
|
1511
1736
|
></a
|
|
1512
1737
|
>`)}
|
|
1513
1738
|
</div>
|
|
1514
|
-
<div class="details" part="details"
|
|
1739
|
+
<div class="details" part="details" hidden>
|
|
1740
|
+
${this.isLight ? nothing : html `<slot name=${DETAILS_SLOT}></slot>`}
|
|
1741
|
+
</div>
|
|
1515
1742
|
</div>
|
|
1516
1743
|
</dialog>
|
|
1517
1744
|
`;
|
|
@@ -1549,7 +1776,7 @@ __decorate([
|
|
|
1549
1776
|
], UvalibLightbox.prototype, "index", void 0);
|
|
1550
1777
|
__decorate([
|
|
1551
1778
|
state()
|
|
1552
|
-
], UvalibLightbox.prototype, "
|
|
1779
|
+
], UvalibLightbox.prototype, "shown", void 0);
|
|
1553
1780
|
__decorate([
|
|
1554
1781
|
state()
|
|
1555
1782
|
], UvalibLightbox.prototype, "status", void 0);
|