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

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,6 +1,13 @@
1
- import { CSSResultGroup, LitElement } from 'lit';
1
+ import { CSSResultGroup, LitElement, PropertyValues } from 'lit';
2
2
  import type { TileModel } from '../models';
3
3
  export declare class ItemImage extends LitElement {
4
+ /**
5
+ * Map to cache which identifiers have waveform-style thumbnails, so that
6
+ * they can have their waveform styling applied immediately, rather than
7
+ * waiting for the image content to load before applying it (which can
8
+ * cause noticeable flicker when such tiles refresh).
9
+ */
10
+ private static readonly waveformByIdentifier;
4
11
  model?: TileModel;
5
12
  baseImageUrl?: string;
6
13
  isListTile: boolean;
@@ -10,6 +17,7 @@ export declare class ItemImage extends LitElement {
10
17
  private isWaveform;
11
18
  private isNotFound;
12
19
  private baseImage;
20
+ protected willUpdate(changed: PropertyValues): void;
13
21
  render(): import("lit").TemplateResult<1>;
14
22
  private get imageTemplate();
15
23
  /**
@@ -1,5 +1,6 @@
1
+ var ItemImage_1;
1
2
  import { __decorate } from "tslib";
2
- import { css, html, LitElement, nothing } from 'lit';
3
+ import { css, html, LitElement, nothing, } from 'lit';
3
4
  import { customElement, property, query, state } from 'lit/decorators.js';
4
5
  import { classMap } from 'lit/directives/class-map.js';
5
6
  import { baseItemImageStyles, waveformGradientStyles, } from '../styles/item-image-styles';
@@ -14,6 +15,22 @@ let ItemImage = class ItemImage extends LitElement {
14
15
  this.isWaveform = false;
15
16
  this.isNotFound = false;
16
17
  }
18
+ static { ItemImage_1 = this; }
19
+ /**
20
+ * Map to cache which identifiers have waveform-style thumbnails, so that
21
+ * they can have their waveform styling applied immediately, rather than
22
+ * waiting for the image content to load before applying it (which can
23
+ * cause noticeable flicker when such tiles refresh).
24
+ */
25
+ static { this.waveformByIdentifier = new Map(); }
26
+ willUpdate(changed) {
27
+ if (changed.has('model')) {
28
+ // If this identifier is known to have a waveform image, then set isWaveform upfront
29
+ const identifier = this.model?.identifier;
30
+ this.isWaveform =
31
+ ItemImage_1.waveformByIdentifier.get(identifier) === true;
32
+ }
33
+ }
17
34
  render() {
18
35
  return html `
19
36
  <div class=${classMap(this.itemBaseClass)}>${this.imageTemplate}</div>
@@ -116,6 +133,9 @@ let ItemImage = class ItemImage extends LitElement {
116
133
  this.model?.mediatype === 'etree') &&
117
134
  this.baseImage.naturalWidth / this.baseImage.naturalHeight === 4) {
118
135
  this.isWaveform = true;
136
+ if (this.model?.identifier) {
137
+ ItemImage_1.waveformByIdentifier.set(this.model.identifier, true);
138
+ }
119
139
  }
120
140
  }
121
141
  onError() {
@@ -177,7 +197,7 @@ __decorate([
177
197
  __decorate([
178
198
  query('img')
179
199
  ], ItemImage.prototype, "baseImage", void 0);
180
- ItemImage = __decorate([
200
+ ItemImage = ItemImage_1 = __decorate([
181
201
  customElement('item-image')
182
202
  ], ItemImage);
183
203
  export { ItemImage };
@@ -1 +1 @@
1
- {"version":3,"file":"item-image.js","sourceRoot":"","sources":["../../../src/tiles/item-image.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAkB,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAa,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAIlE,OAAO,EACL,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAG3D,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,UAAU;IAAlC;;QAKwB,eAAU,GAAG,KAAK,CAAC;QAEnB,kBAAa,GAAG,KAAK,CAAC;QAEtB,aAAQ,GAAG,KAAK,CAAC;QAEjB,qBAAgB,GAAG,KAAK,C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ErB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;6CAAoB;AAEnB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;gDAAuB;AAEtB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;2CAAkB;AAEjB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;mDAA0B;AAErC;IAAhB,KAAK,EAAE;6CAA4B;AAEnB;IAAhB,KAAK,EAAE;6CAA4B;AAEd;IAArB,KAAK,CAAC,KAAK,CAAC;4CAAsC;AAjBxC,SAAS;IADrB,aAAa,CAAC,YAAY,CAAC;GACf,SAAS,CA6KrB","sourcesContent":["import { css, CSSResultGroup, html, LitElement, nothing } from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { ClassInfo, classMap } from 'lit/directives/class-map.js';\n\nimport type { TileModel } from '../models';\n\nimport {\n baseItemImageStyles,\n waveformGradientStyles,\n} from '../styles/item-image-styles';\nimport { searchIcon } from '../assets/img/icons/mediatype/search';\n\n@customElement('item-image')\nexport class ItemImage extends LitElement {\n @property({ type: Object }) model?: TileModel;\n\n @property({ type: String }) baseImageUrl?: string;\n\n @property({ type: Boolean }) isListTile = false;\n\n @property({ type: Boolean }) isCompactTile = false;\n\n @property({ type: Boolean }) loggedIn = false;\n\n @property({ type: Boolean }) suppressBlurring = false;\n\n @state() private isWaveform = false;\n\n @state() private isNotFound = false;\n\n @query('img') private baseImage!: HTMLImageElement;\n\n render() {\n return html`\n <div class=${classMap(this.itemBaseClass)}>${this.imageTemplate}</div>\n `;\n }\n\n private get imageTemplate() {\n if (this.model?.mediatype === 'search') {\n return html`${searchIcon}`;\n }\n\n return html`\n <img\n class=${classMap(this.itemImageClass)}\n src=\"${this.imageSrc}\"\n alt=\"\"\n @load=${this.onLoad}\n @error=${this.onError}\n />\n `;\n }\n\n /**\n * Helpers\n */\n private get imageSrc() {\n if (this.isNotFound) return this.notFoundSrc;\n\n // Use the correct image for web capture tiles, if possible\n if (this.model?.captureDates && this.model.identifier) {\n try {\n const url = new URL(this.model.identifier);\n const domain = encodeURIComponent(url.hostname);\n return this.baseImageUrl\n ? `https://web.archive.org/thumb/${domain}?generate=1`\n : nothing;\n } catch {\n return `${this.baseImageUrl}/images/notfound.png`;\n }\n }\n\n // Use the thumbnail URL specified in the model if it exists\n if (this.model?.thumbnailUrl) return this.model.thumbnailUrl;\n\n // Don't try to load invalid image URLs\n return this.baseImageUrl && this.model?.identifier\n ? `${this.baseImageUrl}/services/img/${this.model.identifier}`\n : nothing;\n }\n\n private get notFoundSrc() {\n return this.baseImageUrl\n ? `${this.baseImageUrl}/images/notfound.png`\n : nothing;\n }\n\n private get hashBasedGradient() {\n if (!this.model?.identifier) {\n return 'waveform-grad0';\n }\n const gradient = this.hashStrToInt(this.model.identifier) % 6; // returns 0-5\n return `waveform-grad${gradient}`;\n }\n\n private hashStrToInt(str: string): number {\n return str\n .split('')\n .reduce((acc: number, char: string) => acc + char.charCodeAt(0), 0);\n }\n\n /**\n * Classes\n */\n private get itemBaseClass(): ClassInfo {\n return {\n 'drop-shadow': true,\n 'list-box': this.isListTile,\n 'search-image': this.model?.mediatype === 'search',\n [this.hashBasedGradient]: this.isWaveform,\n };\n }\n\n private get itemImageClass(): ClassInfo {\n const hasSensitiveContent = !!(\n this.model?.contentWarning || this.model?.loginRequired\n );\n const shouldBlur = hasSensitiveContent && !this.suppressBlurring;\n\n return {\n contain: !this.isCompactTile && !this.isWaveform,\n cover: this.isCompactTile,\n blur: shouldBlur,\n waveform: this.isWaveform,\n 'account-image': this.isAccountImage, // for account tile image\n 'collection-image': this.model?.mediatype === 'collection', // for collection tile image\n };\n }\n\n /**\n * Helper function to determine if account tile image\n */\n private get isAccountImage() {\n return (\n this.model?.mediatype === 'account' &&\n !this.isCompactTile &&\n !this.isListTile\n );\n }\n\n /**\n * Event listener sets isWaveform true if image is waveform\n */\n private onLoad() {\n if (\n (this.model?.mediatype === 'audio' ||\n this.model?.mediatype === 'etree') &&\n this.baseImage.naturalWidth / this.baseImage.naturalHeight === 4\n ) {\n this.isWaveform = true;\n }\n }\n\n private onError() {\n this.isNotFound = true;\n }\n\n /**\n * CSS\n */\n static get styles(): CSSResultGroup {\n return [\n baseItemImageStyles,\n waveformGradientStyles,\n css`\n img {\n height: var(--imgHeight, 16rem);\n width: var(--imgWidth, 16rem);\n }\n\n .search-image {\n display: flex;\n align-items: center;\n justify-content: center;\n background: rgb(245, 245, 247);\n border-radius: 4px;\n }\n\n svg {\n height: 10rem;\n width: 10rem;\n }\n `,\n ];\n }\n}\n"]}
1
+ {"version":3,"file":"item-image.js","sourceRoot":"","sources":["../../../src/tiles/item-image.ts"],"names":[],"mappings":";;AAAA,OAAO,EACL,GAAG,EAEH,IAAI,EACJ,UAAU,EACV,OAAO,GAER,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAa,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAIlE,OAAO,EACL,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAG3D,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,UAAU;IAAlC;;QAawB,eAAU,GAAG,KAAK,CAAC;QAEnB,kBAAa,GAAG,KAAK,CAAC;QAEtB,aAAQ,GAAG,KAAK,CAAC;QAEjB,qBAAgB,GAAG,KAAK,CAAC;QAErC,eAAU,GAAG,KAAK,CAAC;QAEnB,eAAU,GAAG,KAAK,CAAC;IA0KtC,CAAC;;IAhMC;;;;;OAKG;aACqB,yBAAoB,GAAG,IAAI,GAAG,EAAmB,AAA7B,CAA8B;IAoBhE,UAAU,CAAC,OAAuB;QAC1C,IAAI,OAAO,CAAC,GAAG,CAAC,OA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AC;IAED;;OAEG;IACH,MAAM,KAAK,MAAM;QACf,OAAO;YACL,mBAAmB;YACnB,sBAAsB;YACtB,GAAG,CAAA;;;;;;;;;;;;;;;;;;OAkBF;SACF,CAAC;IACJ,CAAC;;AAvL2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCAAmB;AAElB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CAAuB;AAErB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;6CAAoB;AAEnB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;gDAAuB;AAEtB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;2CAAkB;AAEjB;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;mDAA0B;AAErC;IAAhB,KAAK,EAAE;6CAA4B;AAEnB;IAAhB,KAAK,EAAE;6CAA4B;AAEd;IAArB,KAAK,CAAC,KAAK,CAAC;4CAAsC;AAzBxC,SAAS;IADrB,aAAa,CAAC,YAAY,CAAC;GACf,SAAS,CAiMrB","sourcesContent":["import {\n css,\n CSSResultGroup,\n html,\n LitElement,\n nothing,\n PropertyValues,\n} from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { ClassInfo, classMap } from 'lit/directives/class-map.js';\n\nimport type { TileModel } from '../models';\n\nimport {\n baseItemImageStyles,\n waveformGradientStyles,\n} from '../styles/item-image-styles';\nimport { searchIcon } from '../assets/img/icons/mediatype/search';\n\n@customElement('item-image')\nexport class ItemImage extends LitElement {\n /**\n * Map to cache which identifiers have waveform-style thumbnails, so that\n * they can have their waveform styling applied immediately, rather than\n * waiting for the image content to load before applying it (which can\n * cause noticeable flicker when such tiles refresh).\n */\n private static readonly waveformByIdentifier = new Map<string, boolean>();\n\n @property({ type: Object }) model?: TileModel;\n\n @property({ type: String }) baseImageUrl?: string;\n\n @property({ type: Boolean }) isListTile = false;\n\n @property({ type: Boolean }) isCompactTile = false;\n\n @property({ type: Boolean }) loggedIn = false;\n\n @property({ type: Boolean }) suppressBlurring = false;\n\n @state() private isWaveform = false;\n\n @state() private isNotFound = false;\n\n @query('img') private baseImage!: HTMLImageElement;\n\n protected willUpdate(changed: PropertyValues): void {\n if (changed.has('model')) {\n // If this identifier is known to have a waveform image, then set isWaveform upfront\n const identifier = this.model?.identifier;\n this.isWaveform =\n ItemImage.waveformByIdentifier.get(identifier as string) === true;\n }\n }\n\n render() {\n return html`\n <div class=${classMap(this.itemBaseClass)}>${this.imageTemplate}</div>\n `;\n }\n\n private get imageTemplate() {\n if (this.model?.mediatype === 'search') {\n return html`${searchIcon}`;\n }\n\n return html`\n <img\n class=${classMap(this.itemImageClass)}\n src=\"${this.imageSrc}\"\n alt=\"\"\n @load=${this.onLoad}\n @error=${this.onError}\n />\n `;\n }\n\n /**\n * Helpers\n */\n private get imageSrc() {\n if (this.isNotFound) return this.notFoundSrc;\n\n // Use the correct image for web capture tiles, if possible\n if (this.model?.captureDates && this.model.identifier) {\n try {\n const url = new URL(this.model.identifier);\n const domain = encodeURIComponent(url.hostname);\n return this.baseImageUrl\n ? `https://web.archive.org/thumb/${domain}?generate=1`\n : nothing;\n } catch {\n return `${this.baseImageUrl}/images/notfound.png`;\n }\n }\n\n // Use the thumbnail URL specified in the model if it exists\n if (this.model?.thumbnailUrl) return this.model.thumbnailUrl;\n\n // Don't try to load invalid image URLs\n return this.baseImageUrl && this.model?.identifier\n ? `${this.baseImageUrl}/services/img/${this.model.identifier}`\n : nothing;\n }\n\n private get notFoundSrc() {\n return this.baseImageUrl\n ? `${this.baseImageUrl}/images/notfound.png`\n : nothing;\n }\n\n private get hashBasedGradient() {\n if (!this.model?.identifier) {\n return 'waveform-grad0';\n }\n const gradient = this.hashStrToInt(this.model.identifier) % 6; // returns 0-5\n return `waveform-grad${gradient}`;\n }\n\n private hashStrToInt(str: string): number {\n return str\n .split('')\n .reduce((acc: number, char: string) => acc + char.charCodeAt(0), 0);\n }\n\n /**\n * Classes\n */\n private get itemBaseClass(): ClassInfo {\n return {\n 'drop-shadow': true,\n 'list-box': this.isListTile,\n 'search-image': this.model?.mediatype === 'search',\n [this.hashBasedGradient]: this.isWaveform,\n };\n }\n\n private get itemImageClass(): ClassInfo {\n const hasSensitiveContent = !!(\n this.model?.contentWarning || this.model?.loginRequired\n );\n const shouldBlur = hasSensitiveContent && !this.suppressBlurring;\n\n return {\n contain: !this.isCompactTile && !this.isWaveform,\n cover: this.isCompactTile,\n blur: shouldBlur,\n waveform: this.isWaveform,\n 'account-image': this.isAccountImage, // for account tile image\n 'collection-image': this.model?.mediatype === 'collection', // for collection tile image\n };\n }\n\n /**\n * Helper function to determine if account tile image\n */\n private get isAccountImage() {\n return (\n this.model?.mediatype === 'account' &&\n !this.isCompactTile &&\n !this.isListTile\n );\n }\n\n /**\n * Event listener sets isWaveform true if image is waveform\n */\n private onLoad() {\n if (\n (this.model?.mediatype === 'audio' ||\n this.model?.mediatype === 'etree') &&\n this.baseImage.naturalWidth / this.baseImage.naturalHeight === 4\n ) {\n this.isWaveform = true;\n if (this.model?.identifier) {\n ItemImage.waveformByIdentifier.set(this.model.identifier, true);\n }\n }\n }\n\n private onError() {\n this.isNotFound = true;\n }\n\n /**\n * CSS\n */\n static get styles(): CSSResultGroup {\n return [\n baseItemImageStyles,\n waveformGradientStyles,\n css`\n img {\n height: var(--imgHeight, 16rem);\n width: var(--imgWidth, 16rem);\n }\n\n .search-image {\n display: flex;\n align-items: center;\n justify-content: center;\n background: rgb(245, 245, 247);\n border-radius: 4px;\n }\n\n svg {\n height: 10rem;\n width: 10rem;\n }\n `,\n ];\n }\n}\n"]}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "The Internet Archive Collection Browser.",
4
4
  "license": "AGPL-3.0-only",
5
5
  "author": "Internet Archive",
6
- "version": "4.3.2-alpha-webdev7939.5",
6
+ "version": "4.3.2-alpha-webdev7939.6",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.js",
9
9
  "scripts": {
@@ -31,7 +31,7 @@
31
31
  "@internetarchive/histogram-date-range": "^1.4.2",
32
32
  "@internetarchive/ia-dropdown": "^2.0.0",
33
33
  "@internetarchive/iaux-item-metadata": "^1.0.5",
34
- "@internetarchive/infinite-scroller": "1.1.0-alpha-webdev7939.7",
34
+ "@internetarchive/infinite-scroller": "1.1.0-alpha-webdev7939.8",
35
35
  "@internetarchive/modal-manager": "^2.0.5",
36
36
  "@internetarchive/search-service": "^2.7.1",
37
37
  "@internetarchive/shared-resize-observer": "^0.2.0",
@@ -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