@internetarchive/collection-browser 4.3.2-alpha-webdev7939.5 → 4.3.2-alpha-webdev7939.7

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.
@@ -1,4 +1,11 @@
1
- import { css, CSSResultGroup, html, LitElement, nothing } from 'lit';
1
+ import {
2
+ css,
3
+ CSSResultGroup,
4
+ html,
5
+ LitElement,
6
+ nothing,
7
+ PropertyValues,
8
+ } from 'lit';
2
9
  import { customElement, property, query, state } from 'lit/decorators.js';
3
10
  import { ClassInfo, classMap } from 'lit/directives/class-map.js';
4
11
 
@@ -12,6 +19,14 @@ import { searchIcon } from '../assets/img/icons/mediatype/search';
12
19
 
13
20
  @customElement('item-image')
14
21
  export class ItemImage extends LitElement {
22
+ /**
23
+ * Map to cache which identifiers have waveform-style thumbnails, so that
24
+ * they can have their waveform styling applied immediately, rather than
25
+ * waiting for the image content to load before applying it (which can
26
+ * cause noticeable flicker when such tiles refresh).
27
+ */
28
+ private static readonly waveformByIdentifier = new Map<string, boolean>();
29
+
15
30
  @property({ type: Object }) model?: TileModel;
16
31
 
17
32
  @property({ type: String }) baseImageUrl?: string;
@@ -30,6 +45,15 @@ export class ItemImage extends LitElement {
30
45
 
31
46
  @query('img') private baseImage!: HTMLImageElement;
32
47
 
48
+ protected willUpdate(changed: PropertyValues): void {
49
+ if (changed.has('model')) {
50
+ // If this identifier is known to have a waveform image, then set isWaveform upfront
51
+ const identifier = this.model?.identifier;
52
+ this.isWaveform =
53
+ ItemImage.waveformByIdentifier.get(identifier as string) === true;
54
+ }
55
+ }
56
+
33
57
  render() {
34
58
  return html`
35
59
  <div class=${classMap(this.itemBaseClass)}>${this.imageTemplate}</div>
@@ -149,6 +173,9 @@ export class ItemImage extends LitElement {
149
173
  this.baseImage.naturalWidth / this.baseImage.naturalHeight === 4
150
174
  ) {
151
175
  this.isWaveform = true;
176
+ if (this.model?.identifier) {
177
+ ItemImage.waveformByIdentifier.set(this.model.identifier, true);
178
+ }
152
179
  }
153
180
  }
154
181