@internetarchive/elements 0.2.12 → 0.2.13-webdev-9022.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.
Files changed (102) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +20 -0
  3. package/dist/src/elements/ia-combo-box/caret-closed.svg +8 -8
  4. package/dist/src/elements/ia-combo-box/caret-open.svg +8 -8
  5. package/dist/src/elements/ia-combo-box/clear.svg +8 -8
  6. package/dist/src/elements/ia-dropdown-search-bar/search.svg +10 -10
  7. package/dist/src/elements/ia-image-viewer/ia-image-viewer.d.ts +142 -0
  8. package/dist/src/elements/ia-image-viewer/ia-image-viewer.d.ts.map +1 -0
  9. package/dist/src/elements/ia-image-viewer/ia-image-viewer.js +508 -0
  10. package/dist/src/elements/ia-image-viewer/ia-image-viewer.js.map +1 -0
  11. package/dist/src/elements/ia-image-viewer/ia-imgview-controls.d.ts +27 -0
  12. package/dist/src/elements/ia-image-viewer/ia-imgview-controls.d.ts.map +1 -0
  13. package/dist/src/elements/ia-image-viewer/ia-imgview-controls.js +157 -0
  14. package/dist/src/elements/ia-image-viewer/ia-imgview-controls.js.map +1 -0
  15. package/dist/src/elements/ia-image-viewer/ia-imgview-slide.d.ts +49 -0
  16. package/dist/src/elements/ia-image-viewer/ia-imgview-slide.d.ts.map +1 -0
  17. package/dist/src/elements/ia-image-viewer/ia-imgview-slide.js +225 -0
  18. package/dist/src/elements/ia-image-viewer/ia-imgview-slide.js.map +1 -0
  19. package/dist/src/elements/ia-image-viewer/image-viewer-gestures.d.ts +79 -0
  20. package/dist/src/elements/ia-image-viewer/image-viewer-gestures.d.ts.map +1 -0
  21. package/dist/src/elements/ia-image-viewer/image-viewer-gestures.js +254 -0
  22. package/dist/src/elements/ia-image-viewer/image-viewer-gestures.js.map +1 -0
  23. package/dist/src/elements/ia-image-viewer/models.d.ts +20 -0
  24. package/dist/src/elements/ia-image-viewer/models.d.ts.map +1 -0
  25. package/dist/src/elements/ia-image-viewer/models.js +2 -0
  26. package/dist/src/elements/ia-image-viewer/models.js.map +1 -0
  27. package/dist/src/elements/ia-item-navigator/ia-item-navigator.d.ts +97 -0
  28. package/dist/src/elements/ia-item-navigator/ia-item-navigator.d.ts.map +1 -0
  29. package/dist/src/elements/ia-item-navigator/ia-item-navigator.js +588 -0
  30. package/dist/src/elements/ia-item-navigator/ia-item-navigator.js.map +1 -0
  31. package/dist/src/elements/ia-item-navigator/ia-itemnav-menu-button.d.ts +39 -0
  32. package/dist/src/elements/ia-item-navigator/ia-itemnav-menu-button.d.ts.map +1 -0
  33. package/dist/src/elements/ia-item-navigator/ia-itemnav-menu-button.js +249 -0
  34. package/dist/src/elements/ia-item-navigator/ia-itemnav-menu-button.js.map +1 -0
  35. package/dist/src/elements/ia-item-navigator/ia-itemnav-menu-slider.d.ts +55 -0
  36. package/dist/src/elements/ia-item-navigator/ia-itemnav-menu-slider.d.ts.map +1 -0
  37. package/dist/src/elements/ia-item-navigator/ia-itemnav-menu-slider.js +394 -0
  38. package/dist/src/elements/ia-item-navigator/ia-itemnav-menu-slider.js.map +1 -0
  39. package/dist/src/elements/ia-item-navigator/ia-itemnav-no-theater-available.d.ts +20 -0
  40. package/dist/src/elements/ia-item-navigator/ia-itemnav-no-theater-available.d.ts.map +1 -0
  41. package/dist/src/elements/ia-item-navigator/ia-itemnav-no-theater-available.js +102 -0
  42. package/dist/src/elements/ia-item-navigator/ia-itemnav-no-theater-available.js.map +1 -0
  43. package/dist/src/elements/ia-item-navigator/icons/collapse-sidebar.svg +7 -0
  44. package/dist/src/elements/ia-item-navigator/icons/ellipses.svg +7 -0
  45. package/dist/src/elements/ia-item-navigator/icons.d.ts +13 -0
  46. package/dist/src/elements/ia-item-navigator/icons.d.ts.map +1 -0
  47. package/dist/src/elements/ia-item-navigator/icons.js +16 -0
  48. package/dist/src/elements/ia-item-navigator/icons.js.map +1 -0
  49. package/dist/src/elements/ia-item-navigator/interfaces/event-interfaces.d.ts +41 -0
  50. package/dist/src/elements/ia-item-navigator/interfaces/event-interfaces.d.ts.map +1 -0
  51. package/dist/src/elements/ia-item-navigator/interfaces/event-interfaces.js +2 -0
  52. package/dist/src/elements/ia-item-navigator/interfaces/event-interfaces.js.map +1 -0
  53. package/dist/src/elements/ia-item-navigator/interfaces/menu-interfaces.d.ts +23 -0
  54. package/dist/src/elements/ia-item-navigator/interfaces/menu-interfaces.d.ts.map +1 -0
  55. package/dist/src/elements/ia-item-navigator/interfaces/menu-interfaces.js +2 -0
  56. package/dist/src/elements/ia-item-navigator/interfaces/menu-interfaces.js.map +1 -0
  57. package/dist/src/elements/ia-item-navigator/masked-icon.d.ts +24 -0
  58. package/dist/src/elements/ia-item-navigator/masked-icon.d.ts.map +1 -0
  59. package/dist/src/elements/ia-item-navigator/masked-icon.js +30 -0
  60. package/dist/src/elements/ia-item-navigator/masked-icon.js.map +1 -0
  61. package/dist/src/elements/ia-item-navigator/menus/ia-itemnav-share-panel.d.ts +47 -0
  62. package/dist/src/elements/ia-item-navigator/menus/ia-itemnav-share-panel.d.ts.map +1 -0
  63. package/dist/src/elements/ia-item-navigator/menus/ia-itemnav-share-panel.js +352 -0
  64. package/dist/src/elements/ia-item-navigator/menus/ia-itemnav-share-panel.js.map +1 -0
  65. package/dist/src/elements/ia-item-navigator/menus/ia-itemnav-sort-files-button.d.ts +22 -0
  66. package/dist/src/elements/ia-item-navigator/menus/ia-itemnav-sort-files-button.d.ts.map +1 -0
  67. package/dist/src/elements/ia-item-navigator/menus/ia-itemnav-sort-files-button.js +137 -0
  68. package/dist/src/elements/ia-item-navigator/menus/ia-itemnav-sort-files-button.js.map +1 -0
  69. package/dist/src/elements/ia-item-navigator/menus/ia-itemnav-viewable-files-panel.d.ts +40 -0
  70. package/dist/src/elements/ia-item-navigator/menus/ia-itemnav-viewable-files-panel.d.ts.map +1 -0
  71. package/dist/src/elements/ia-item-navigator/menus/ia-itemnav-viewable-files-panel.js +217 -0
  72. package/dist/src/elements/ia-item-navigator/menus/ia-itemnav-viewable-files-panel.js.map +1 -0
  73. package/dist/src/elements/ia-item-navigator/menus/icons/email.svg +6 -0
  74. package/dist/src/elements/ia-item-navigator/menus/icons/facebook.svg +6 -0
  75. package/dist/src/elements/ia-item-navigator/menus/icons/link.svg +6 -0
  76. package/dist/src/elements/ia-item-navigator/menus/icons/list.svg +3 -0
  77. package/dist/src/elements/ia-item-navigator/menus/icons/pinterest.svg +6 -0
  78. package/dist/src/elements/ia-item-navigator/menus/icons/share.svg +6 -0
  79. package/dist/src/elements/ia-item-navigator/menus/icons/sort-asc.svg +22 -0
  80. package/dist/src/elements/ia-item-navigator/menus/icons/sort-desc.svg +21 -0
  81. package/dist/src/elements/ia-item-navigator/menus/icons/sort-neutral.svg +13 -0
  82. package/dist/src/elements/ia-item-navigator/menus/icons/tumblr.svg +6 -0
  83. package/dist/src/elements/ia-item-navigator/menus/icons/twitter.svg +6 -0
  84. package/dist/src/elements/ia-item-navigator/menus/icons/viewable-files.svg +6 -0
  85. package/dist/src/elements/ia-item-navigator/menus/models.d.ts +17 -0
  86. package/dist/src/elements/ia-item-navigator/menus/models.d.ts.map +1 -0
  87. package/dist/src/elements/ia-item-navigator/menus/models.js +2 -0
  88. package/dist/src/elements/ia-item-navigator/menus/models.js.map +1 -0
  89. package/dist/src/elements/ia-item-navigator/menus/share-icons.d.ts +16 -0
  90. package/dist/src/elements/ia-item-navigator/menus/share-icons.d.ts.map +1 -0
  91. package/dist/src/elements/ia-item-navigator/menus/share-icons.js +23 -0
  92. package/dist/src/elements/ia-item-navigator/menus/share-icons.js.map +1 -0
  93. package/dist/src/elements/index.d.ts +5 -0
  94. package/dist/src/elements/index.d.ts.map +1 -1
  95. package/dist/src/elements/index.js +5 -0
  96. package/dist/src/elements/index.js.map +1 -1
  97. package/dist/src/labs/ia-snow/flake.svg +1 -1
  98. package/dist/src/util/prefers-reduced-motion.d.ts +10 -0
  99. package/dist/src/util/prefers-reduced-motion.d.ts.map +1 -0
  100. package/dist/src/util/prefers-reduced-motion.js +12 -0
  101. package/dist/src/util/prefers-reduced-motion.js.map +1 -0
  102. package/package.json +1 -1
@@ -0,0 +1,508 @@
1
+ import { __decorate } from "tslib";
2
+ import { css, html, LitElement, nothing, } from 'lit';
3
+ import { customElement, property, query, state } from 'lit/decorators.js';
4
+ import { classMap } from 'lit/directives/class-map.js';
5
+ import { keyed } from 'lit/directives/keyed.js';
6
+ import { msg, str } from '@lit/localize';
7
+ import themeStyles from '../../themes/theme-styles.js';
8
+ import { prefersReducedMotion } from '../../util/prefers-reduced-motion.js';
9
+ import { ImageViewerGestures } from './image-viewer-gestures.js';
10
+ import './ia-imgview-slide.js';
11
+ import './ia-imgview-controls.js';
12
+ /**
13
+ * A swipeable image carousel.
14
+ *
15
+ * Shows one image at a time from a list, with previous/next buttons, a
16
+ * counter, keyboard arrows, horizontal wheel scrolling and touch swipes.
17
+ * Clicking an image opens it in a new tab.
18
+ *
19
+ * The viewer holds no opinion about where the images came from: it takes a
20
+ * plain list of names and URLs, and reports the image it lands on through
21
+ * `imageChanged` so a host can mirror that into its own URL or analytics.
22
+ *
23
+ * @fires imageChanged - The viewer settled on a new image.
24
+ * @fires imageLoaded - An image the viewer showed finished loading.
25
+ * @fires imageLoadFailed - An image the viewer showed could not be loaded.
26
+ * Fires once per image until it loads successfully or the set changes.
27
+ * @fires imageActivated - An image was clicked. Cancelable: preventing it
28
+ * stops the default of opening the image in a new tab.
29
+ */
30
+ let IAImageViewer = class IAImageViewer extends LitElement {
31
+ constructor() {
32
+ super(...arguments);
33
+ this.images = [];
34
+ /** Read by the gesture controller to navigate relative to the current image. */
35
+ this.currentIndex = 0;
36
+ this.animating = false;
37
+ /**
38
+ * Incremented when an animation is interrupted to force the track element to
39
+ * be recreated via the `keyed()` directive, which guarantees the CSS
40
+ * animation restarts even if the direction is the same.
41
+ */
42
+ this.slideGeneration = 0;
43
+ /** Which edge just wrapped, if any. Drives the glow indicator. */
44
+ this.wrapEdge = null;
45
+ /**
46
+ * Images already reported as failed, so a broken image isn't counted again
47
+ * every time the viewer passes over it. Navigating back re-fires `error` on
48
+ * the recreated element, and the neighbouring slides staged during an
49
+ * animation or a drag load the same image too, so without this a single
50
+ * broken derivative reports several times a session.
51
+ *
52
+ * Cleared when the image set changes, which is the point a name stops
53
+ * standing for the same file.
54
+ */
55
+ this.reportedFailures = new Set();
56
+ this.slideTarget = null;
57
+ this.slideDirection = null;
58
+ this.gestures = new ImageViewerGestures(this);
59
+ }
60
+ get imageCount() {
61
+ return this.images.length;
62
+ }
63
+ /** The image currently on screen, if there is one. */
64
+ get currentImage() {
65
+ return this.images[this.currentIndex];
66
+ }
67
+ willUpdate(changed) {
68
+ if (changed.has('images') || changed.has('currentImageName')) {
69
+ const requested = this.currentImageName
70
+ ? this.images.findIndex((i) => i.name === this.currentImageName)
71
+ : -1;
72
+ this.currentIndex = requested >= 0 ? requested : 0;
73
+ this.animating = false;
74
+ this.slideGeneration = 0;
75
+ this.slideTarget = null;
76
+ this.slideDirection = null;
77
+ this.wrapEdge = null;
78
+ this.reportedFailures.clear();
79
+ this.preloadAdjacentImages();
80
+ }
81
+ }
82
+ render() {
83
+ if (this.images.length === 0)
84
+ return nothing;
85
+ const { dragging } = this.gestures;
86
+ const current = this.images[this.currentIndex];
87
+ const showControls = this.images.length > 1;
88
+ const trackClasses = {
89
+ 'slide-track': true,
90
+ 'sliding-next': this.animating && !dragging && this.slideDirection === 'next',
91
+ 'sliding-prev': this.animating && !dragging && this.slideDirection === 'prev',
92
+ dragging,
93
+ };
94
+ const prevIndex = (this.currentIndex - 1 + this.images.length) % this.images.length;
95
+ const nextIndex = (this.currentIndex + 1) % this.images.length;
96
+ const slideTarget = this.animating && !dragging && this.slideTarget !== null
97
+ ? this.images[this.slideTarget]
98
+ : null;
99
+ const prevImage = dragging ? this.images[prevIndex] : slideTarget;
100
+ const nextImage = dragging ? this.images[nextIndex] : slideTarget;
101
+ const showPrev = dragging || (slideTarget !== null && this.slideDirection === 'prev');
102
+ const showNext = dragging || (slideTarget !== null && this.slideDirection === 'next');
103
+ const displayIndex = this.animating && this.slideTarget !== null
104
+ ? this.slideTarget
105
+ : this.currentIndex;
106
+ return html `
107
+ <div class="viewer">
108
+ <div class="image-area">
109
+ ${this.wrapEdge
110
+ ? html `<div
111
+ class="wrap-glow ${this.wrapEdge === 'start'
112
+ ? 'glow-start'
113
+ : 'glow-end'}"
114
+ @animationend=${this.onWrapGlowEnd}
115
+ ></div>`
116
+ : nothing}
117
+ ${keyed(this.slideGeneration, html `<div
118
+ class=${classMap(trackClasses)}
119
+ @animationend=${this.onSlideEnd}
120
+ @imageLoaded=${this.onImageLoaded}
121
+ @imageFailed=${this.onImageFailed}
122
+ @imageActivated=${this.onImageActivated}
123
+ >
124
+ ${showPrev && prevImage ? this.slideTemplate(prevImage) : nothing}
125
+ ${this.slideTemplate(current)}
126
+ ${showNext && nextImage ? this.slideTemplate(nextImage) : nothing}
127
+ </div>`)}
128
+ </div>
129
+ ${showControls
130
+ ? html `
131
+ <ia-imgview-controls
132
+ .currentIndex=${displayIndex}
133
+ .totalImages=${this.images.length}
134
+ @showPrevious=${this.showPrevious}
135
+ @showNext=${this.showNext}
136
+ ></ia-imgview-controls>
137
+ `
138
+ : nothing}
139
+ ${this.announcementTemplate}
140
+ </div>
141
+ `;
142
+ }
143
+ slideTemplate(image) {
144
+ return html `<ia-imgview-slide .image=${image}></ia-imgview-slide>`;
145
+ }
146
+ /**
147
+ * Announces the image to a screen reader, which otherwise gets nothing when
148
+ * the counter and the picture change under it.
149
+ */
150
+ get announcementTemplate() {
151
+ const current = this.images[this.currentIndex];
152
+ const position = msg(str `Image ${this.currentIndex + 1} of ${this.images.length}`);
153
+ const label = current?.title ?? current?.name;
154
+ return html `
155
+ <div class="sr-only" role="status" aria-live="polite" aria-atomic="true">
156
+ ${label ? `${position}: ${label}` : position}
157
+ </div>
158
+ `;
159
+ }
160
+ /**
161
+ * Passes a slide's load result on to the host, which is where reporting
162
+ * belongs. The slide's own events stop at this shadow root, so they're
163
+ * re-dispatched rather than allowed to escape.
164
+ */
165
+ onImageLoaded(e) {
166
+ // A load that succeeds clears the failure, so an image that breaks again
167
+ // later is reported again rather than swallowed as a repeat.
168
+ this.reportedFailures.delete(e.detail.image.name);
169
+ this.dispatchEvent(new CustomEvent('imageLoaded', { detail: { image: e.detail.image } }));
170
+ }
171
+ onImageFailed(e) {
172
+ const { image } = e.detail;
173
+ if (this.reportedFailures.has(image.name))
174
+ return;
175
+ this.reportedFailures.add(image.name);
176
+ this.dispatchEvent(new CustomEvent('imageLoadFailed', { detail: { image } }));
177
+ }
178
+ /**
179
+ * Decides whether a click on a slide opens the image.
180
+ *
181
+ * Two things can stop it: the click is the tail end of a swipe, or the host
182
+ * cancels the event to show the image its own way. The slide's event doesn't
183
+ * cross this shadow root, so it's re-raised here for the host to see, and a
184
+ * veto is passed back down to cancel the click.
185
+ */
186
+ onImageActivated(e) {
187
+ if (this.gestures.consumeSwipeTap()) {
188
+ e.preventDefault();
189
+ return;
190
+ }
191
+ const allowed = this.dispatchEvent(new CustomEvent('imageActivated', {
192
+ detail: { image: e.detail.image },
193
+ cancelable: true,
194
+ }));
195
+ if (!allowed)
196
+ e.preventDefault();
197
+ }
198
+ /**
199
+ * Inserts the neighbouring slides around the current one so the touch target
200
+ * element stays in the DOM (avoiding touchcancel). These aren't rendered
201
+ * from the template, so they're marked for the gesture controller to clean
202
+ * up. The dragging class shifts the track to centre on the middle slide.
203
+ */
204
+ insertDragSlides() {
205
+ const track = this.slideTrack;
206
+ if (!track)
207
+ return;
208
+ const prevIdx = (this.currentIndex - 1 + this.images.length) % this.images.length;
209
+ const nextIdx = (this.currentIndex + 1) % this.images.length;
210
+ track.insertBefore(this.createDragSlide(this.images[prevIdx]), track.firstChild);
211
+ track.appendChild(this.createDragSlide(this.images[nextIdx]));
212
+ track.classList.add('dragging');
213
+ }
214
+ removeDragSlides() {
215
+ const track = this.slideTrack;
216
+ if (!track)
217
+ return;
218
+ track.querySelectorAll('[data-drag-slide]').forEach((el) => el.remove());
219
+ track.classList.remove('dragging');
220
+ }
221
+ createDragSlide(image) {
222
+ const slide = document.createElement('ia-imgview-slide');
223
+ slide.image = image;
224
+ slide.dataset.dragSlide = '';
225
+ return slide;
226
+ }
227
+ showNext() {
228
+ this.settleIfAnimating();
229
+ this.moveTo((this.currentIndex + 1) % this.images.length, 'next');
230
+ }
231
+ showPrevious() {
232
+ this.settleIfAnimating();
233
+ this.moveTo((this.currentIndex - 1 + this.images.length) % this.images.length, 'prev');
234
+ }
235
+ /**
236
+ * Starts the move to another image. With reduced motion there's no animation
237
+ * to wait on, so the move lands immediately: nothing would fire the
238
+ * `animationend` that otherwise commits it.
239
+ */
240
+ moveTo(target, direction) {
241
+ const wraps = direction === 'next'
242
+ ? this.currentIndex === this.images.length - 1
243
+ : this.currentIndex === 0;
244
+ this.preloadAroundIndex(target);
245
+ if (prefersReducedMotion()) {
246
+ this.currentIndex = target;
247
+ this.settleAtCurrentIndex();
248
+ return;
249
+ }
250
+ this.slideTarget = target;
251
+ this.slideDirection = direction;
252
+ this.animating = true;
253
+ this.wrapEdge = wraps ? (direction === 'next' ? 'end' : 'start') : null;
254
+ }
255
+ /**
256
+ * Moves to the image a completed drag landed on. The drag has already
257
+ * animated the track there, so this only updates state.
258
+ */
259
+ commitDrag(direction) {
260
+ const wraps = direction === 'next'
261
+ ? this.currentIndex === this.images.length - 1
262
+ : this.currentIndex === 0;
263
+ const step = direction === 'next' ? 1 : -1;
264
+ this.currentIndex =
265
+ (this.currentIndex + step + this.images.length) % this.images.length;
266
+ if (wraps && !prefersReducedMotion()) {
267
+ this.wrapEdge = direction === 'next' ? 'end' : 'start';
268
+ }
269
+ this.emitImageChanged();
270
+ }
271
+ /**
272
+ * If an animation is in progress, immediately commit its target so the next
273
+ * animation starts from the right position. Bumps the generation key to
274
+ * force the track element to be recreated, which restarts the CSS animation.
275
+ */
276
+ settleIfAnimating() {
277
+ if (!this.animating || this.slideTarget === null)
278
+ return;
279
+ this.currentIndex = this.slideTarget;
280
+ this.slideGeneration++;
281
+ }
282
+ onWrapGlowEnd() {
283
+ this.wrapEdge = null;
284
+ }
285
+ onSlideEnd() {
286
+ if (this.slideTarget === null)
287
+ return;
288
+ this.currentIndex = this.slideTarget;
289
+ this.settleAtCurrentIndex();
290
+ }
291
+ /** Finishes a move, however it was driven. */
292
+ settleAtCurrentIndex() {
293
+ this.slideTarget = null;
294
+ this.slideDirection = null;
295
+ this.animating = false;
296
+ this.gestures.animationSettled();
297
+ this.emitImageChanged();
298
+ this.preloadAdjacentImages();
299
+ }
300
+ emitImageChanged() {
301
+ const image = this.images[this.currentIndex];
302
+ if (!image)
303
+ return;
304
+ this.dispatchEvent(new CustomEvent('imageChanged', {
305
+ detail: { image, index: this.currentIndex },
306
+ }));
307
+ }
308
+ /**
309
+ * Preloads the next and previous images around `currentIndex` so the first
310
+ * navigation feels instant.
311
+ */
312
+ preloadAdjacentImages() {
313
+ this.preloadAroundIndex(this.currentIndex);
314
+ }
315
+ /**
316
+ * Preloads images adjacent to the given index. Called both at rest (around
317
+ * `currentIndex`) and at the start of a move (around the target) so rapid
318
+ * navigation stays ahead of the browser cache.
319
+ *
320
+ * A preload that fails is deliberately not reported. These requests are
321
+ * speculative and the viewer may never show them, so counting them would
322
+ * inflate the failure rate with images nobody looked at. Navigating to a
323
+ * broken image renders a real slide, whose `error` reports it then.
324
+ */
325
+ preloadAroundIndex(index) {
326
+ if (this.images.length <= 1)
327
+ return;
328
+ const next = (index + 1) % this.images.length;
329
+ const prev = (index - 1 + this.images.length) % this.images.length;
330
+ for (const idx of [next, prev]) {
331
+ const img = new Image();
332
+ img.src = this.images[idx].url;
333
+ }
334
+ }
335
+ static get styles() {
336
+ return [
337
+ themeStyles,
338
+ css `
339
+ :host {
340
+ --image-viewer-height--: var(--image-viewer-height, 100%);
341
+ --image-viewer-max-width--: var(--image-viewer-max-width, none);
342
+ --image-viewer-slide-duration--: var(
343
+ --image-viewer-slide-duration,
344
+ 500ms
345
+ );
346
+ --image-viewer-glow-color--: var(
347
+ --image-viewer-glow-color,
348
+ rgba(255, 255, 255, 0.25)
349
+ );
350
+ --image-viewer-glow-width--: var(--image-viewer-glow-width, 100px);
351
+ /*
352
+ * The breakpoint the controls query against. Named so the query in
353
+ * ia-imgview-controls resolves to this host rather than to whatever
354
+ * container the consumer happens to have further up.
355
+ */
356
+ container: image-viewer / inline-size;
357
+
358
+ display: block;
359
+ height: var(--image-viewer-height--);
360
+ max-width: var(--image-viewer-max-width--);
361
+ margin: 0 auto;
362
+ }
363
+
364
+ .viewer {
365
+ position: relative;
366
+ width: 100%;
367
+ height: 100%;
368
+ display: flex;
369
+ flex-direction: column;
370
+ align-items: center;
371
+ justify-content: center;
372
+ }
373
+
374
+ .image-area {
375
+ position: relative;
376
+ flex: 1;
377
+ min-height: 0;
378
+ width: 100%;
379
+ display: flex;
380
+ align-items: center;
381
+ justify-content: center;
382
+ overflow: hidden;
383
+ touch-action: pan-y pinch-zoom;
384
+ }
385
+
386
+ .wrap-glow {
387
+ position: absolute;
388
+ top: 0;
389
+ bottom: 0;
390
+ width: var(--image-viewer-glow-width--);
391
+ pointer-events: none;
392
+ z-index: 2;
393
+ animation: glow-fade 700ms ease-out both;
394
+ }
395
+
396
+ .glow-start {
397
+ left: 0;
398
+ background: linear-gradient(
399
+ to right,
400
+ var(--image-viewer-glow-color--),
401
+ transparent
402
+ );
403
+ }
404
+
405
+ .glow-end {
406
+ right: 0;
407
+ background: linear-gradient(
408
+ to left,
409
+ var(--image-viewer-glow-color--),
410
+ transparent
411
+ );
412
+ }
413
+
414
+ @keyframes glow-fade {
415
+ 0% {
416
+ opacity: 0;
417
+ }
418
+ 20% {
419
+ opacity: 1;
420
+ }
421
+ 100% {
422
+ opacity: 0;
423
+ }
424
+ }
425
+
426
+ .slide-track {
427
+ display: flex;
428
+ width: 100%;
429
+ height: 100%;
430
+ flex-shrink: 0;
431
+ }
432
+
433
+ @keyframes slide-next {
434
+ from {
435
+ transform: translateX(0);
436
+ }
437
+ to {
438
+ transform: translateX(-100%);
439
+ }
440
+ }
441
+
442
+ @keyframes slide-prev {
443
+ from {
444
+ transform: translateX(-100%);
445
+ }
446
+ to {
447
+ transform: translateX(0);
448
+ }
449
+ }
450
+
451
+ .slide-track.dragging {
452
+ transform: translateX(-100%);
453
+ }
454
+
455
+ .slide-track.sliding-next {
456
+ animation: slide-next var(--image-viewer-slide-duration--) ease-in-out
457
+ both;
458
+ }
459
+
460
+ .slide-track.sliding-prev {
461
+ animation: slide-prev var(--image-viewer-slide-duration--) ease-in-out
462
+ both;
463
+ }
464
+
465
+ .sr-only {
466
+ position: absolute;
467
+ width: 1px;
468
+ height: 1px;
469
+ margin: -1px;
470
+ padding: 0;
471
+ border: 0;
472
+ overflow: hidden;
473
+ white-space: nowrap;
474
+ clip-path: inset(50%);
475
+ }
476
+ `,
477
+ ];
478
+ }
479
+ };
480
+ __decorate([
481
+ property({ type: Array })
482
+ ], IAImageViewer.prototype, "images", void 0);
483
+ __decorate([
484
+ property({ type: String })
485
+ ], IAImageViewer.prototype, "currentImageName", void 0);
486
+ __decorate([
487
+ query('.image-area')
488
+ ], IAImageViewer.prototype, "imageArea", void 0);
489
+ __decorate([
490
+ query('.slide-track')
491
+ ], IAImageViewer.prototype, "slideTrack", void 0);
492
+ __decorate([
493
+ state()
494
+ ], IAImageViewer.prototype, "currentIndex", void 0);
495
+ __decorate([
496
+ state()
497
+ ], IAImageViewer.prototype, "animating", void 0);
498
+ __decorate([
499
+ state()
500
+ ], IAImageViewer.prototype, "slideGeneration", void 0);
501
+ __decorate([
502
+ state()
503
+ ], IAImageViewer.prototype, "wrapEdge", void 0);
504
+ IAImageViewer = __decorate([
505
+ customElement('ia-image-viewer')
506
+ ], IAImageViewer);
507
+ export { IAImageViewer };
508
+ //# sourceMappingURL=ia-image-viewer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ia-image-viewer.js","sourceRoot":"","sources":["../../../../src/elements/ia-image-viewer/ia-image-viewer.ts"],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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0IF;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAxgB4B;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;6CAAiC;AAM/B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uDAA2B;AAGhC;IAArB,KAAK,CAAC,aAAa,CAAC;gDAAyB;AAGvB;IAAtB,KAAK,CAAC,cAAc,CAAC;iDAA0B;AAGvC;IAAR,KAAK,EAAE;mDAAkB;AAET;IAAhB,KAAK,EAAE;gDAA2B;AAOlB;IAAhB,KAAK,EAAE;sDAA6B;AAGpB;IAAhB,KAAK,EAAE;+CAA0C;AA5BvC,aAAa;IADzB,aAAa,CAAC,iBAAiB,CAAC;GACpB,aAAa,CAygBzB","sourcesContent":["import {\n css,\n type CSSResultGroup,\n html,\n LitElement,\n nothing,\n type PropertyValues,\n type TemplateResult,\n} from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { keyed } from 'lit/directives/keyed.js';\nimport { msg, str } from '@lit/localize';\n\nimport themeStyles from '@src/themes/theme-styles';\nimport { prefersReducedMotion } from '@src/util/prefers-reduced-motion';\nimport { ImageViewerGestures } from './image-viewer-gestures';\nimport type { ImageViewerImage, SlideDirection, WrapEdge } from './models';\nimport type { IAImageViewerSlide } from './ia-imgview-slide';\nimport './ia-imgview-slide';\nimport './ia-imgview-controls';\n\n/** Detail carried by the load and failure events a slide reports. */\ntype SlideImageEvent = CustomEvent<{ image: ImageViewerImage }>;\n\n/**\n * A swipeable image carousel.\n *\n * Shows one image at a time from a list, with previous/next buttons, a\n * counter, keyboard arrows, horizontal wheel scrolling and touch swipes.\n * Clicking an image opens it in a new tab.\n *\n * The viewer holds no opinion about where the images came from: it takes a\n * plain list of names and URLs, and reports the image it lands on through\n * `imageChanged` so a host can mirror that into its own URL or analytics.\n *\n * @fires imageChanged - The viewer settled on a new image.\n * @fires imageLoaded - An image the viewer showed finished loading.\n * @fires imageLoadFailed - An image the viewer showed could not be loaded.\n * Fires once per image until it loads successfully or the set changes.\n * @fires imageActivated - An image was clicked. Cancelable: preventing it\n * stops the default of opening the image in a new tab.\n */\n@customElement('ia-image-viewer')\nexport class IAImageViewer extends LitElement {\n @property({ type: Array }) images: ImageViewerImage[] = [];\n\n /**\n * Name of the image to show. Changing it jumps straight to that image\n * without animating. An unknown name shows the first image.\n */\n @property({ type: String }) currentImageName?: string;\n\n /** Read by the gesture controller, which tracks touches against it. */\n @query('.image-area') imageArea?: HTMLElement;\n\n /** Read by the gesture controller, which translates it during a drag. */\n @query('.slide-track') slideTrack?: HTMLElement;\n\n /** Read by the gesture controller to navigate relative to the current image. */\n @state() currentIndex = 0;\n\n @state() private animating = false;\n\n /**\n * Incremented when an animation is interrupted to force the track element to\n * be recreated via the `keyed()` directive, which guarantees the CSS\n * animation restarts even if the direction is the same.\n */\n @state() private slideGeneration = 0;\n\n /** Which edge just wrapped, if any. Drives the glow indicator. */\n @state() private wrapEdge: WrapEdge | null = null;\n\n /**\n * Images already reported as failed, so a broken image isn't counted again\n * every time the viewer passes over it. Navigating back re-fires `error` on\n * the recreated element, and the neighbouring slides staged during an\n * animation or a drag load the same image too, so without this a single\n * broken derivative reports several times a session.\n *\n * Cleared when the image set changes, which is the point a name stops\n * standing for the same file.\n */\n private reportedFailures = new Set<string>();\n\n private slideTarget: number | null = null;\n\n private slideDirection: SlideDirection | null = null;\n\n private gestures = new ImageViewerGestures(this);\n\n get imageCount(): number {\n return this.images.length;\n }\n\n /** The image currently on screen, if there is one. */\n get currentImage(): ImageViewerImage | undefined {\n return this.images[this.currentIndex];\n }\n\n protected willUpdate(changed: PropertyValues): void {\n if (changed.has('images') || changed.has('currentImageName')) {\n const requested = this.currentImageName\n ? this.images.findIndex((i) => i.name === this.currentImageName)\n : -1;\n this.currentIndex = requested >= 0 ? requested : 0;\n\n this.animating = false;\n this.slideGeneration = 0;\n this.slideTarget = null;\n this.slideDirection = null;\n this.wrapEdge = null;\n this.reportedFailures.clear();\n this.preloadAdjacentImages();\n }\n }\n\n render(): TemplateResult | typeof nothing {\n if (this.images.length === 0) return nothing;\n\n const { dragging } = this.gestures;\n const current = this.images[this.currentIndex];\n const showControls = this.images.length > 1;\n\n const trackClasses = {\n 'slide-track': true,\n 'sliding-next':\n this.animating && !dragging && this.slideDirection === 'next',\n 'sliding-prev':\n this.animating && !dragging && this.slideDirection === 'prev',\n dragging,\n };\n\n const prevIndex =\n (this.currentIndex - 1 + this.images.length) % this.images.length;\n const nextIndex = (this.currentIndex + 1) % this.images.length;\n\n const slideTarget =\n this.animating && !dragging && this.slideTarget !== null\n ? this.images[this.slideTarget]\n : null;\n const prevImage = dragging ? this.images[prevIndex] : slideTarget;\n const nextImage = dragging ? this.images[nextIndex] : slideTarget;\n const showPrev =\n dragging || (slideTarget !== null && this.slideDirection === 'prev');\n const showNext =\n dragging || (slideTarget !== null && this.slideDirection === 'next');\n\n const displayIndex =\n this.animating && this.slideTarget !== null\n ? this.slideTarget\n : this.currentIndex;\n\n return html`\n <div class=\"viewer\">\n <div class=\"image-area\">\n ${this.wrapEdge\n ? html`<div\n class=\"wrap-glow ${this.wrapEdge === 'start'\n ? 'glow-start'\n : 'glow-end'}\"\n @animationend=${this.onWrapGlowEnd}\n ></div>`\n : nothing}\n ${keyed(\n this.slideGeneration,\n html`<div\n class=${classMap(trackClasses)}\n @animationend=${this.onSlideEnd}\n @imageLoaded=${this.onImageLoaded}\n @imageFailed=${this.onImageFailed}\n @imageActivated=${this.onImageActivated}\n >\n ${showPrev && prevImage ? this.slideTemplate(prevImage) : nothing}\n ${this.slideTemplate(current)}\n ${showNext && nextImage ? this.slideTemplate(nextImage) : nothing}\n </div>`,\n )}\n </div>\n ${showControls\n ? html`\n <ia-imgview-controls\n .currentIndex=${displayIndex}\n .totalImages=${this.images.length}\n @showPrevious=${this.showPrevious}\n @showNext=${this.showNext}\n ></ia-imgview-controls>\n `\n : nothing}\n ${this.announcementTemplate}\n </div>\n `;\n }\n\n private slideTemplate(image: ImageViewerImage): TemplateResult {\n return html`<ia-imgview-slide .image=${image}></ia-imgview-slide>`;\n }\n\n /**\n * Announces the image to a screen reader, which otherwise gets nothing when\n * the counter and the picture change under it.\n */\n private get announcementTemplate(): TemplateResult {\n const current = this.images[this.currentIndex];\n const position = msg(\n str`Image ${this.currentIndex + 1} of ${this.images.length}`,\n );\n const label = current?.title ?? current?.name;\n return html`\n <div class=\"sr-only\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\">\n ${label ? `${position}: ${label}` : position}\n </div>\n `;\n }\n\n /**\n * Passes a slide's load result on to the host, which is where reporting\n * belongs. The slide's own events stop at this shadow root, so they're\n * re-dispatched rather than allowed to escape.\n */\n private onImageLoaded(e: SlideImageEvent): void {\n // A load that succeeds clears the failure, so an image that breaks again\n // later is reported again rather than swallowed as a repeat.\n this.reportedFailures.delete(e.detail.image.name);\n this.dispatchEvent(\n new CustomEvent('imageLoaded', { detail: { image: e.detail.image } }),\n );\n }\n\n private onImageFailed(e: SlideImageEvent): void {\n const { image } = e.detail;\n if (this.reportedFailures.has(image.name)) return;\n this.reportedFailures.add(image.name);\n this.dispatchEvent(\n new CustomEvent('imageLoadFailed', { detail: { image } }),\n );\n }\n\n /**\n * Decides whether a click on a slide opens the image.\n *\n * Two things can stop it: the click is the tail end of a swipe, or the host\n * cancels the event to show the image its own way. The slide's event doesn't\n * cross this shadow root, so it's re-raised here for the host to see, and a\n * veto is passed back down to cancel the click.\n */\n private onImageActivated(e: SlideImageEvent): void {\n if (this.gestures.consumeSwipeTap()) {\n e.preventDefault();\n return;\n }\n const allowed = this.dispatchEvent(\n new CustomEvent('imageActivated', {\n detail: { image: e.detail.image },\n cancelable: true,\n }),\n );\n if (!allowed) e.preventDefault();\n }\n\n /**\n * Inserts the neighbouring slides around the current one so the touch target\n * element stays in the DOM (avoiding touchcancel). These aren't rendered\n * from the template, so they're marked for the gesture controller to clean\n * up. The dragging class shifts the track to centre on the middle slide.\n */\n insertDragSlides(): void {\n const track = this.slideTrack;\n if (!track) return;\n const prevIdx =\n (this.currentIndex - 1 + this.images.length) % this.images.length;\n const nextIdx = (this.currentIndex + 1) % this.images.length;\n\n track.insertBefore(\n this.createDragSlide(this.images[prevIdx]),\n track.firstChild,\n );\n track.appendChild(this.createDragSlide(this.images[nextIdx]));\n\n track.classList.add('dragging');\n }\n\n removeDragSlides(): void {\n const track = this.slideTrack;\n if (!track) return;\n track.querySelectorAll('[data-drag-slide]').forEach((el) => el.remove());\n track.classList.remove('dragging');\n }\n\n private createDragSlide(image: ImageViewerImage): IAImageViewerSlide {\n const slide = document.createElement('ia-imgview-slide');\n slide.image = image;\n slide.dataset.dragSlide = '';\n return slide;\n }\n\n showNext(): void {\n this.settleIfAnimating();\n this.moveTo((this.currentIndex + 1) % this.images.length, 'next');\n }\n\n showPrevious(): void {\n this.settleIfAnimating();\n this.moveTo(\n (this.currentIndex - 1 + this.images.length) % this.images.length,\n 'prev',\n );\n }\n\n /**\n * Starts the move to another image. With reduced motion there's no animation\n * to wait on, so the move lands immediately: nothing would fire the\n * `animationend` that otherwise commits it.\n */\n private moveTo(target: number, direction: SlideDirection): void {\n const wraps =\n direction === 'next'\n ? this.currentIndex === this.images.length - 1\n : this.currentIndex === 0;\n this.preloadAroundIndex(target);\n\n if (prefersReducedMotion()) {\n this.currentIndex = target;\n this.settleAtCurrentIndex();\n return;\n }\n\n this.slideTarget = target;\n this.slideDirection = direction;\n this.animating = true;\n this.wrapEdge = wraps ? (direction === 'next' ? 'end' : 'start') : null;\n }\n\n /**\n * Moves to the image a completed drag landed on. The drag has already\n * animated the track there, so this only updates state.\n */\n commitDrag(direction: SlideDirection): void {\n const wraps =\n direction === 'next'\n ? this.currentIndex === this.images.length - 1\n : this.currentIndex === 0;\n const step = direction === 'next' ? 1 : -1;\n this.currentIndex =\n (this.currentIndex + step + this.images.length) % this.images.length;\n if (wraps && !prefersReducedMotion()) {\n this.wrapEdge = direction === 'next' ? 'end' : 'start';\n }\n this.emitImageChanged();\n }\n\n /**\n * If an animation is in progress, immediately commit its target so the next\n * animation starts from the right position. Bumps the generation key to\n * force the track element to be recreated, which restarts the CSS animation.\n */\n settleIfAnimating(): void {\n if (!this.animating || this.slideTarget === null) return;\n this.currentIndex = this.slideTarget;\n this.slideGeneration++;\n }\n\n private onWrapGlowEnd(): void {\n this.wrapEdge = null;\n }\n\n private onSlideEnd(): void {\n if (this.slideTarget === null) return;\n this.currentIndex = this.slideTarget;\n this.settleAtCurrentIndex();\n }\n\n /** Finishes a move, however it was driven. */\n private settleAtCurrentIndex(): void {\n this.slideTarget = null;\n this.slideDirection = null;\n this.animating = false;\n this.gestures.animationSettled();\n this.emitImageChanged();\n this.preloadAdjacentImages();\n }\n\n private emitImageChanged(): void {\n const image = this.images[this.currentIndex];\n if (!image) return;\n this.dispatchEvent(\n new CustomEvent('imageChanged', {\n detail: { image, index: this.currentIndex },\n }),\n );\n }\n\n /**\n * Preloads the next and previous images around `currentIndex` so the first\n * navigation feels instant.\n */\n private preloadAdjacentImages(): void {\n this.preloadAroundIndex(this.currentIndex);\n }\n\n /**\n * Preloads images adjacent to the given index. Called both at rest (around\n * `currentIndex`) and at the start of a move (around the target) so rapid\n * navigation stays ahead of the browser cache.\n *\n * A preload that fails is deliberately not reported. These requests are\n * speculative and the viewer may never show them, so counting them would\n * inflate the failure rate with images nobody looked at. Navigating to a\n * broken image renders a real slide, whose `error` reports it then.\n */\n preloadAroundIndex(index: number): void {\n if (this.images.length <= 1) return;\n const next = (index + 1) % this.images.length;\n const prev = (index - 1 + this.images.length) % this.images.length;\n for (const idx of [next, prev]) {\n const img = new Image();\n img.src = this.images[idx].url;\n }\n }\n\n static get styles(): CSSResultGroup {\n return [\n themeStyles,\n css`\n :host {\n --image-viewer-height--: var(--image-viewer-height, 100%);\n --image-viewer-max-width--: var(--image-viewer-max-width, none);\n --image-viewer-slide-duration--: var(\n --image-viewer-slide-duration,\n 500ms\n );\n --image-viewer-glow-color--: var(\n --image-viewer-glow-color,\n rgba(255, 255, 255, 0.25)\n );\n --image-viewer-glow-width--: var(--image-viewer-glow-width, 100px);\n /*\n * The breakpoint the controls query against. Named so the query in\n * ia-imgview-controls resolves to this host rather than to whatever\n * container the consumer happens to have further up.\n */\n container: image-viewer / inline-size;\n\n display: block;\n height: var(--image-viewer-height--);\n max-width: var(--image-viewer-max-width--);\n margin: 0 auto;\n }\n\n .viewer {\n position: relative;\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n }\n\n .image-area {\n position: relative;\n flex: 1;\n min-height: 0;\n width: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n overflow: hidden;\n touch-action: pan-y pinch-zoom;\n }\n\n .wrap-glow {\n position: absolute;\n top: 0;\n bottom: 0;\n width: var(--image-viewer-glow-width--);\n pointer-events: none;\n z-index: 2;\n animation: glow-fade 700ms ease-out both;\n }\n\n .glow-start {\n left: 0;\n background: linear-gradient(\n to right,\n var(--image-viewer-glow-color--),\n transparent\n );\n }\n\n .glow-end {\n right: 0;\n background: linear-gradient(\n to left,\n var(--image-viewer-glow-color--),\n transparent\n );\n }\n\n @keyframes glow-fade {\n 0% {\n opacity: 0;\n }\n 20% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n\n .slide-track {\n display: flex;\n width: 100%;\n height: 100%;\n flex-shrink: 0;\n }\n\n @keyframes slide-next {\n from {\n transform: translateX(0);\n }\n to {\n transform: translateX(-100%);\n }\n }\n\n @keyframes slide-prev {\n from {\n transform: translateX(-100%);\n }\n to {\n transform: translateX(0);\n }\n }\n\n .slide-track.dragging {\n transform: translateX(-100%);\n }\n\n .slide-track.sliding-next {\n animation: slide-next var(--image-viewer-slide-duration--) ease-in-out\n both;\n }\n\n .slide-track.sliding-prev {\n animation: slide-prev var(--image-viewer-slide-duration--) ease-in-out\n both;\n }\n\n .sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n border: 0;\n overflow: hidden;\n white-space: nowrap;\n clip-path: inset(50%);\n }\n `,\n ];\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ia-image-viewer': IAImageViewer;\n }\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import { type CSSResultGroup, LitElement, type TemplateResult } from 'lit';
2
+ /**
3
+ * The image viewer's previous / next buttons and the "n / total" counter.
4
+ *
5
+ * Past the wide breakpoint the buttons position themselves over the image
6
+ * area, which lives in the viewer's shadow root. That works because an
7
+ * absolutely positioned element finds its containing block through the flat
8
+ * tree, so the viewer's frame is still the reference as long as this element's
9
+ * own host box stays unpositioned. The breakpoint queries the `image-viewer`
10
+ * container by name, so it tracks the viewer's width rather than whichever
11
+ * container a consumer happens to have further up the tree.
12
+ */
13
+ export declare class IAImageViewerControls extends LitElement {
14
+ /** Zero-based index of the image being shown, for the counter. */
15
+ currentIndex: number;
16
+ totalImages: number;
17
+ render(): TemplateResult;
18
+ private onPrevious;
19
+ private onNext;
20
+ static get styles(): CSSResultGroup;
21
+ }
22
+ declare global {
23
+ interface HTMLElementTagNameMap {
24
+ 'ia-imgview-controls': IAImageViewerControls;
25
+ }
26
+ }
27
+ //# sourceMappingURL=ia-imgview-controls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ia-imgview-controls.d.ts","sourceRoot":"","sources":["../../../../src/elements/ia-image-viewer/ia-imgview-controls.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EAEnB,UAAU,EACV,KAAK,cAAc,EACpB,MAAM,KAAK,CAAC;AAMb;;;;;;;;;;GAUG;AACH,qBACa,qBAAsB,SAAQ,UAAU;IACnD,kEAAkE;IACtC,YAAY,SAAK;IAEjB,WAAW,SAAK;IAE5C,MAAM,IAAI,cAAc;IAoBxB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,MAAM;IAId,MAAM,KAAK,MAAM,IAAI,cAAc,CAgGlC;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,qBAAqB,EAAE,qBAAqB,CAAC;KAC9C;CACF"}