@internetarchive/collection-browser 4.9.1-webdev-9670.1 → 4.10.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/README.md +33 -11
- package/dist/src/app-root.d.ts +0 -11
- package/dist/src/app-root.js +1 -95
- package/dist/src/app-root.js.map +1 -1
- package/dist/src/collection-browser.d.ts +2 -43
- package/dist/src/collection-browser.js +13 -194
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/collection-facets/facet-row-template.d.ts +1 -1
- package/dist/src/collection-facets/facet-row-template.js +14 -7
- package/dist/src/collection-facets/facet-row-template.js.map +1 -1
- package/dist/src/collection-facets/facet-row.js +3 -1
- package/dist/src/collection-facets/facet-row.js.map +1 -1
- package/dist/src/collection-facets/more-facets-content.js +6 -5
- package/dist/src/collection-facets/more-facets-content.js.map +1 -1
- package/dist/src/collection-facets/more-facets-scroller.js +3 -2
- package/dist/src/collection-facets/more-facets-scroller.js.map +1 -1
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.js +13 -4
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.js.map +1 -1
- package/dist/src/collection-facets/smart-facets/smart-facet-bar.js +6 -2
- package/dist/src/collection-facets/smart-facets/smart-facet-bar.js.map +1 -1
- package/dist/src/collection-facets.js +6 -5
- package/dist/src/collection-facets.js.map +1 -1
- package/dist/src/empty-placeholder.d.ts +7 -7
- package/dist/src/empty-placeholder.js +29 -15
- package/dist/src/empty-placeholder.js.map +1 -1
- package/dist/src/expanded-date-picker.js +3 -2
- package/dist/src/expanded-date-picker.js.map +1 -1
- package/dist/src/locales/es.d.ts +200 -0
- package/dist/src/locales/es.js +215 -0
- package/dist/src/locales/es.js.map +1 -0
- package/dist/src/manage/manage-bar.d.ts +3 -2
- package/dist/src/manage/manage-bar.js +15 -16
- package/dist/src/manage/manage-bar.js.map +1 -1
- package/dist/src/manage/remove-items-modal-content.js +3 -2
- package/dist/src/manage/remove-items-modal-content.js.map +1 -1
- package/dist/src/mediatype/mediatype-config.js +55 -18
- package/dist/src/mediatype/mediatype-config.js.map +1 -1
- package/dist/src/models.js +120 -40
- package/dist/src/models.js.map +1 -1
- package/dist/src/sort-filter-bar/alpha-bar-tooltip.js +8 -2
- package/dist/src/sort-filter-bar/alpha-bar-tooltip.js.map +1 -1
- package/dist/src/sort-filter-bar/alpha-bar.js +7 -2
- package/dist/src/sort-filter-bar/alpha-bar.js.map +1 -1
- package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +0 -12
- package/dist/src/sort-filter-bar/sort-filter-bar.js +9 -72
- package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
- package/dist/src/tiles/grid/account-tile.js +3 -2
- package/dist/src/tiles/grid/account-tile.js.map +1 -1
- package/dist/src/tiles/grid/collection-tile.js +12 -11
- package/dist/src/tiles/grid/collection-tile.js.map +1 -1
- package/dist/src/tiles/grid/item-tile.d.ts +0 -4
- package/dist/src/tiles/grid/item-tile.js +8 -23
- package/dist/src/tiles/grid/item-tile.js.map +1 -1
- package/dist/src/tiles/grid/tile-stats.js +6 -3
- package/dist/src/tiles/grid/tile-stats.js.map +1 -1
- package/dist/src/tiles/hover/hover-pane-controller.d.ts +1 -2
- package/dist/src/tiles/hover/hover-pane-controller.js +1 -1
- package/dist/src/tiles/hover/hover-pane-controller.js.map +1 -1
- package/dist/src/tiles/image-block.d.ts +0 -5
- package/dist/src/tiles/image-block.js +0 -29
- package/dist/src/tiles/image-block.js.map +1 -1
- package/dist/src/tiles/list/tile-list-compact-header.js +3 -2
- package/dist/src/tiles/list/tile-list-compact-header.js.map +1 -1
- package/dist/src/tiles/list/tile-list-compact.js +3 -1
- package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
- package/dist/src/tiles/list/tile-list.js +15 -5
- package/dist/src/tiles/list/tile-list.js.map +1 -1
- package/dist/src/tiles/models.d.ts +1 -2
- package/dist/src/tiles/models.js.map +1 -1
- package/dist/src/tiles/overlay/text-overlay.js +3 -1
- package/dist/src/tiles/overlay/text-overlay.js.map +1 -1
- package/dist/src/tiles/review-block.js +3 -2
- package/dist/src/tiles/review-block.js.map +1 -1
- package/dist/src/tiles/tile-dispatcher.d.ts +2 -8
- package/dist/src/tiles/tile-dispatcher.js +6 -36
- package/dist/src/tiles/tile-dispatcher.js.map +1 -1
- package/dist/src/tiles/tile-mediatype-icon.js +3 -1
- package/dist/src/tiles/tile-mediatype-icon.js.map +1 -1
- package/dist/src/utils/format-count.d.ts +3 -1
- package/dist/src/utils/format-count.js +19 -59
- package/dist/src/utils/format-count.js.map +1 -1
- package/dist/src/utils/format-unit-size.d.ts +1 -1
- package/dist/src/utils/format-unit-size.js +21 -18
- package/dist/src/utils/format-unit-size.js.map +1 -1
- package/dist/src/utils/get-locale.d.ts +14 -0
- package/dist/src/utils/get-locale.js +20 -0
- package/dist/src/utils/get-locale.js.map +1 -0
- package/locales/es.d.ts +1 -0
- package/locales/es.js +1 -0
- package/package.json +6 -2
- package/dist/src/tiles/preview/tile-preview-controller.d.ts +0 -61
- package/dist/src/tiles/preview/tile-preview-controller.js +0 -216
- package/dist/src/tiles/preview/tile-preview-controller.js.map +0 -1
- package/dist/src/tiles/preview/tile-preview-media.d.ts +0 -44
- package/dist/src/tiles/preview/tile-preview-media.js +0 -151
- package/dist/src/tiles/preview/tile-preview-media.js.map +0 -1
- package/dist/src/tiles/preview/tile-preview.d.ts +0 -66
- package/dist/src/tiles/preview/tile-preview.js +0 -494
- package/dist/src/tiles/preview/tile-preview.js.map +0 -1
- package/dist/src/utils/grid-zoom-controller.d.ts +0 -69
- package/dist/src/utils/grid-zoom-controller.js +0 -261
- package/dist/src/utils/grid-zoom-controller.js.map +0 -1
- package/dist/src/utils/grid-zoom.d.ts +0 -31
- package/dist/src/utils/grid-zoom.js +0 -109
- package/dist/src/utils/grid-zoom.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tile-mediatype-icon.js","sourceRoot":"","sources":["../../../src/tiles/tile-mediatype-icon.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAkB,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"tile-mediatype-icon.js","sourceRoot":"","sources":["../../../src/tiles/tile-mediatype-icon.ts"],"names":[],"mappings":"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","sourcesContent":["import { css, CSSResultGroup, html, LitElement } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { localized } from '@lit/localize';\n\nimport {\n mediatypeConfig,\n MediatypeConfigKey,\n} from '../mediatype/mediatype-config';\nimport type { TileModel } from '../models';\n\nconst TV_COMMERCIAL_COLLECTION = 'tv_ads';\nconst TV_FACT_CHECK_COLLECTION = 'factchecked';\nconst TV_COLLECTIONS = new Set(['tvnews', 'tvarchive', 'television']);\nconst RADIO_COLLECTIONS = new Set(['radio', 'radioprogram']);\n\n@customElement('tile-mediatype-icon')\n@localized()\nexport class TileMediatypeIcon extends LitElement {\n @property({ type: Object }) model?: TileModel;\n\n @property({ type: Boolean }) showText = false;\n\n /**\n * Returns the appropriate mediatype config key for the current mediatype/collections.\n */\n private get displayMediatype(): MediatypeConfigKey {\n if (this.isTvItem) return this.tvDisplayMediatype;\n if (this.isRadioItem) return 'radio';\n return this.model?.mediatype ?? 'none';\n }\n\n /**\n * Returns the appropriate TV mediatype, depending on the current collections.\n */\n private get tvDisplayMediatype(): MediatypeConfigKey {\n if (this.isTvCommercial) {\n return 'tvCommercial';\n } else if (this.model?.isTvSearchResult && this.isTvFactCheck) {\n return 'tvFactCheck';\n } else if (this.model?.isTvSearchResult && this.isTvQuote) {\n return 'tvQuote';\n }\n\n return 'tv';\n }\n\n /**\n * Whether this represents a TV item\n */\n private get isTvItem(): boolean {\n return !!(\n this.model?.mediatype === 'movies' &&\n this.model?.collections.some(id => TV_COLLECTIONS.has(id))\n );\n }\n\n private get isTvCommercial(): boolean {\n // Contains one or more TV ad identifiers or is in the tv_ads collection\n return !!(\n this.model?.adIds?.length ||\n this.model?.collections.includes(TV_COMMERCIAL_COLLECTION)\n );\n }\n\n private get isTvFactCheck(): boolean {\n // Contains one or more fact-check URLs or is in the factchecked collection\n return !!(\n this.model?.factChecks?.length ||\n this.model?.collections.includes(TV_FACT_CHECK_COLLECTION)\n );\n }\n\n private get isTvQuote(): boolean {\n return !!this.model?.isClip;\n }\n\n /**\n * Whether this represents a radio item\n */\n private get isRadioItem(): boolean {\n return !!(\n this.model?.mediatype === 'audio' &&\n this.model?.collections.some(id => RADIO_COLLECTIONS.has(id))\n );\n }\n\n render() {\n const config = mediatypeConfig[this.displayMediatype];\n if (!config) {\n return html``;\n }\n\n return html`\n <div\n id=\"icon\"\n class=\"${this.showText ? 'show-text' : 'hide-text'}\"\n title=\"${config.text}\"\n style=\"--iconFillColor: ${config.color}\"\n >\n ${config.icon}\n <p class=\"status-text\">${config.text}</p>\n </div>\n `;\n }\n\n static get styles(): CSSResultGroup {\n return css`\n #icon {\n height: var(--iconHeight, 25px);\n }\n\n .status-text {\n font-size: 14px;\n color: #2c2c2c;\n margin: auto;\n display: block;\n text-align: var(--iconTextAlign, center);\n }\n\n #icon.hide-text p {\n display: none;\n }\n\n svg {\n height: var(--iconHeight, 10px);\n width: var(--iconWidth, 10px);\n pointer-events: none;\n }\n\n .fill-color {\n fill: var(--iconFillColor, '#000000');\n }\n `;\n }\n}\n"]}
|
|
@@ -2,6 +2,8 @@ export type NumberFormat = 'short' | 'long';
|
|
|
2
2
|
export type LabelFormat = 'short' | 'long';
|
|
3
3
|
/**
|
|
4
4
|
* Format a "count" number into short "icon" or longer text string.
|
|
5
|
-
* For positive numbers only.
|
|
5
|
+
* For positive numbers only. Uses `Intl.NumberFormat` so both the digit
|
|
6
|
+
* grouping and the abbreviation word/letter (e.g. "K" vs "mil") follow the
|
|
7
|
+
* given locale's conventions.
|
|
6
8
|
*/
|
|
7
9
|
export declare function formatCount(count: number | undefined, numberFormat?: NumberFormat, labelFormat?: LabelFormat, locale?: string): string;
|
|
@@ -2,75 +2,35 @@
|
|
|
2
2
|
* Replaces Petabox www/common/Util::number_format()
|
|
3
3
|
* For positive numbers only.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { getLocale } from './get-locale';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Whether a number should be abbreviated to a compact form (e.g. "77K")
|
|
8
|
+
* rather than shown in full. Millions and up always abbreviate; thousands
|
|
9
|
+
* only abbreviate when the caller asked for the short NumberFormat.
|
|
8
10
|
*/
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
else if (number >= 1_000_000) {
|
|
15
|
-
divisor = 1_000_000;
|
|
16
|
-
}
|
|
17
|
-
else if (number >= 1_000 && numberFormat === 'short') {
|
|
18
|
-
divisor = 1_000;
|
|
19
|
-
}
|
|
20
|
-
return divisor;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Round a number given passed magnitude.
|
|
24
|
-
* Significant digits of value less than 10 get a decimal.
|
|
25
|
-
*/
|
|
26
|
-
function round(number = 0, divisor) {
|
|
27
|
-
const result = number / divisor;
|
|
28
|
-
const roundToOne = result < 10;
|
|
29
|
-
let rounded = 0;
|
|
30
|
-
if (roundToOne) {
|
|
31
|
-
rounded = Math.round((result + Number.EPSILON) * 10) / 10;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
rounded = Math.round(result);
|
|
35
|
-
}
|
|
36
|
-
return rounded;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Return a label for a number and format.
|
|
40
|
-
*/
|
|
41
|
-
function labelize(rounded, divisor, format, locale) {
|
|
42
|
-
switch (divisor) {
|
|
43
|
-
case 1_000_000_000:
|
|
44
|
-
if (format === 'short') {
|
|
45
|
-
return msg(str `${rounded}B`);
|
|
46
|
-
}
|
|
47
|
-
return msg(str `${rounded} billion`);
|
|
48
|
-
case 1_000_000:
|
|
49
|
-
if (format === 'short') {
|
|
50
|
-
return msg(str `${rounded}M`);
|
|
51
|
-
}
|
|
52
|
-
return msg(str `${rounded} million`);
|
|
53
|
-
case 1_000:
|
|
54
|
-
if (format === 'short') {
|
|
55
|
-
return msg(str `${rounded}K`);
|
|
56
|
-
}
|
|
57
|
-
return msg(str `${rounded} thousand`);
|
|
58
|
-
default:
|
|
59
|
-
return new Intl.NumberFormat(locale).format(rounded);
|
|
60
|
-
}
|
|
11
|
+
function shouldAbbreviate(number, numberFormat) {
|
|
12
|
+
if (number >= 1_000_000)
|
|
13
|
+
return true;
|
|
14
|
+
return numberFormat === 'short' && number >= 1_000;
|
|
61
15
|
}
|
|
62
16
|
/**
|
|
63
17
|
* Format a "count" number into short "icon" or longer text string.
|
|
64
|
-
* For positive numbers only.
|
|
18
|
+
* For positive numbers only. Uses `Intl.NumberFormat` so both the digit
|
|
19
|
+
* grouping and the abbreviation word/letter (e.g. "K" vs "mil") follow the
|
|
20
|
+
* given locale's conventions.
|
|
65
21
|
*/
|
|
66
|
-
export function formatCount(count, numberFormat = 'long', labelFormat = 'short', locale =
|
|
22
|
+
export function formatCount(count, numberFormat = 'long', labelFormat = 'short', locale = getLocale()) {
|
|
67
23
|
// Return blank if undefined
|
|
68
24
|
const number = count ?? -1;
|
|
69
25
|
if (number < 0) {
|
|
70
26
|
return '';
|
|
71
27
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
28
|
+
if (shouldAbbreviate(number, numberFormat)) {
|
|
29
|
+
return new Intl.NumberFormat(locale, {
|
|
30
|
+
notation: 'compact',
|
|
31
|
+
compactDisplay: labelFormat === 'short' ? 'short' : 'long',
|
|
32
|
+
}).format(number);
|
|
33
|
+
}
|
|
34
|
+
return new Intl.NumberFormat(locale).format(number);
|
|
75
35
|
}
|
|
76
36
|
//# sourceMappingURL=format-count.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-count.js","sourceRoot":"","sources":["../../../src/utils/format-count.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"format-count.js","sourceRoot":"","sources":["../../../src/utils/format-count.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AASzC;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,MAAc,EAAE,YAA0B;IAClE,IAAI,MAAM,IAAI,SAAS;QAAE,OAAO,IAAI,CAAC;IACrC,OAAO,YAAY,KAAK,OAAO,IAAI,MAAM,IAAI,KAAK,CAAC;AACrD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACzB,KAAyB,EACzB,eAA6B,MAAM,EACnC,cAA2B,OAAO,EAClC,SAAiB,SAAS,EAAE;IAE5B,4BAA4B;IAC5B,MAAM,MAAM,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC;IAC3B,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACf,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,gBAAgB,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC;QAC3C,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;YACnC,QAAQ,EAAE,SAAS;YACnB,cAAc,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;SAC3D,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC","sourcesContent":["/*\n * Replaces Petabox www/common/Util::number_format()\n * For positive numbers only.\n */\nimport { getLocale } from './get-locale';\n\nexport type NumberFormat =\n | 'short' // 1.2 [K | thousand]\n | 'long'; // 1,200 [No label for numbers < 1,000,000]\nexport type LabelFormat =\n | 'short' // [1.2]K\n | 'long'; // [1.2] thousand\n\n/**\n * Whether a number should be abbreviated to a compact form (e.g. \"77K\")\n * rather than shown in full. Millions and up always abbreviate; thousands\n * only abbreviate when the caller asked for the short NumberFormat.\n */\nfunction shouldAbbreviate(number: number, numberFormat: NumberFormat): boolean {\n if (number >= 1_000_000) return true;\n return numberFormat === 'short' && number >= 1_000;\n}\n\n/**\n * Format a \"count\" number into short \"icon\" or longer text string.\n * For positive numbers only. Uses `Intl.NumberFormat` so both the digit\n * grouping and the abbreviation word/letter (e.g. \"K\" vs \"mil\") follow the\n * given locale's conventions.\n */\nexport function formatCount(\n count: number | undefined,\n numberFormat: NumberFormat = 'long',\n labelFormat: LabelFormat = 'short',\n locale: string = getLocale(),\n): string {\n // Return blank if undefined\n const number = count ?? -1;\n if (number < 0) {\n return '';\n }\n if (shouldAbbreviate(number, numberFormat)) {\n return new Intl.NumberFormat(locale, {\n notation: 'compact',\n compactDisplay: labelFormat === 'short' ? 'short' : 'long',\n }).format(number);\n }\n return new Intl.NumberFormat(locale).format(number);\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { nothing } from 'lit';
|
|
2
|
-
export declare function formatUnitSize(size: number | undefined, nDecimals: number,
|
|
2
|
+
export declare function formatUnitSize(size: number | undefined, nDecimals: number, locale?: string): string | typeof nothing;
|
|
@@ -2,33 +2,36 @@
|
|
|
2
2
|
* Replaces Petabox www/common/Util::humanSize()
|
|
3
3
|
*/
|
|
4
4
|
import { nothing } from 'lit';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
import { msg, str } from '@lit/localize';
|
|
6
|
+
import { getLocale } from './get-locale';
|
|
7
|
+
/**
|
|
8
|
+
* Labels a formatted size with its unit, one entry per power of 1024 starting
|
|
9
|
+
* at bytes. Each entry is a function so the label is read in the current
|
|
10
|
+
* locale at call time.
|
|
11
|
+
*/
|
|
12
|
+
const unitLabels = [
|
|
13
|
+
(size, singular) => singular ? msg(str `${size} byte`) : msg(str `${size} bytes`),
|
|
14
|
+
(size, singular) => singular ? msg(str `${size} kilobyte`) : msg(str `${size} kilobytes`),
|
|
15
|
+
(size, singular) => singular ? msg(str `${size} megabyte`) : msg(str `${size} megabytes`),
|
|
16
|
+
(size, singular) => singular ? msg(str `${size} gigabyte`) : msg(str `${size} gigabytes`),
|
|
17
|
+
(size, singular) => singular ? msg(str `${size} terabyte`) : msg(str `${size} terabytes`),
|
|
18
|
+
(size, singular) => singular ? msg(str `${size} petabyte`) : msg(str `${size} petabytes`),
|
|
19
|
+
(size, singular) => singular ? msg(str `${size} exabyte`) : msg(str `${size} exabytes`),
|
|
20
|
+
(size, singular) => singular ? msg(str `${size} zettabyte`) : msg(str `${size} zettabytes`),
|
|
21
|
+
(size, singular) => singular ? msg(str `${size} yottabyte`) : msg(str `${size} yottabytes`),
|
|
22
|
+
];
|
|
23
|
+
export function formatUnitSize(size, nDecimals, locale = getLocale()) {
|
|
18
24
|
let itemSize = size;
|
|
19
25
|
if (itemSize === undefined)
|
|
20
26
|
return nothing; // early return.
|
|
21
27
|
let unitIndex = 0;
|
|
22
28
|
// convert byte to highest possible unit
|
|
23
|
-
while (itemSize > 1024) {
|
|
29
|
+
while (itemSize > 1024 && unitIndex < unitLabels.length - 1) {
|
|
24
30
|
itemSize /= 1024;
|
|
25
31
|
unitIndex += 1;
|
|
26
32
|
}
|
|
27
33
|
const magnitude = 10 ** nDecimals;
|
|
28
34
|
itemSize = Math.round(itemSize * magnitude) / magnitude;
|
|
29
|
-
|
|
30
|
-
// convert plural to singular.
|
|
31
|
-
unitText = itemSize === 1 ? unitText.slice(0, -1) : unitText;
|
|
32
|
-
return `${itemSize.toLocaleString() + separator + unitText}`;
|
|
35
|
+
return unitLabels[unitIndex](new Intl.NumberFormat(locale).format(itemSize), itemSize === 1);
|
|
33
36
|
}
|
|
34
37
|
//# sourceMappingURL=format-unit-size.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-unit-size.js","sourceRoot":"","sources":["../../../src/utils/format-unit-size.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"format-unit-size.js","sourceRoot":"","sources":["../../../src/utils/format-unit-size.ts"],"names":[],"mappings":"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","sourcesContent":["/*\n * Replaces Petabox www/common/Util::humanSize()\n */\nimport { nothing } from 'lit';\nimport { msg, str } from '@lit/localize';\nimport { getLocale } from './get-locale';\n\n/**\n * Labels a formatted size with its unit, one entry per power of 1024 starting\n * at bytes. Each entry is a function so the label is read in the current\n * locale at call time.\n */\nconst unitLabels: ((size: string, singular: boolean) => string)[] = [\n (size, singular) =>\n singular ? msg(str`${size} byte`) : msg(str`${size} bytes`),\n (size, singular) =>\n singular ? msg(str`${size} kilobyte`) : msg(str`${size} kilobytes`),\n (size, singular) =>\n singular ? msg(str`${size} megabyte`) : msg(str`${size} megabytes`),\n (size, singular) =>\n singular ? msg(str`${size} gigabyte`) : msg(str`${size} gigabytes`),\n (size, singular) =>\n singular ? msg(str`${size} terabyte`) : msg(str`${size} terabytes`),\n (size, singular) =>\n singular ? msg(str`${size} petabyte`) : msg(str`${size} petabytes`),\n (size, singular) =>\n singular ? msg(str`${size} exabyte`) : msg(str`${size} exabytes`),\n (size, singular) =>\n singular ? msg(str`${size} zettabyte`) : msg(str`${size} zettabytes`),\n (size, singular) =>\n singular ? msg(str`${size} yottabyte`) : msg(str`${size} yottabytes`),\n];\n\nexport function formatUnitSize(\n size: number | undefined,\n nDecimals: number,\n locale: string = getLocale(),\n) {\n let itemSize = size;\n if (itemSize === undefined) return nothing; // early return.\n\n let unitIndex = 0;\n\n // convert byte to highest possible unit\n while (itemSize > 1024 && unitIndex < unitLabels.length - 1) {\n itemSize /= 1024;\n unitIndex += 1;\n }\n\n const magnitude = 10 ** nDecimals;\n itemSize = Math.round(itemSize * magnitude) / magnitude;\n\n return unitLabels[unitIndex](\n new Intl.NumberFormat(locale).format(itemSize),\n itemSize === 1,\n );\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the locale code currently active in the host app.
|
|
3
|
+
*
|
|
4
|
+
* This package never sets up `@lit/localize` itself (the host app owns that,
|
|
5
|
+
* once), so `@lit/localize`'s own `getLocale()` isn't available here — it's
|
|
6
|
+
* only returned from the host's one setup call. `msg()` always reflects the
|
|
7
|
+
* host app's current locale, read fresh on every call, with no dependency on
|
|
8
|
+
* when this package happened to load relative to the host setting its
|
|
9
|
+
* locale. This probes a string whose only translation is the ISO code of
|
|
10
|
+
* the locale it was translated into, and reads the locale off whichever
|
|
11
|
+
* string comes back: the untranslated source for the source locale, or the
|
|
12
|
+
* code itself once a target locale's translation is in place.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getLocale(): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { msg } from '@lit/localize';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the locale code currently active in the host app.
|
|
4
|
+
*
|
|
5
|
+
* This package never sets up `@lit/localize` itself (the host app owns that,
|
|
6
|
+
* once), so `@lit/localize`'s own `getLocale()` isn't available here — it's
|
|
7
|
+
* only returned from the host's one setup call. `msg()` always reflects the
|
|
8
|
+
* host app's current locale, read fresh on every call, with no dependency on
|
|
9
|
+
* when this package happened to load relative to the host setting its
|
|
10
|
+
* locale. This probes a string whose only translation is the ISO code of
|
|
11
|
+
* the locale it was translated into, and reads the locale off whichever
|
|
12
|
+
* string comes back: the untranslated source for the source locale, or the
|
|
13
|
+
* code itself once a target locale's translation is in place.
|
|
14
|
+
*/
|
|
15
|
+
export function getLocale() {
|
|
16
|
+
return msg('en', {
|
|
17
|
+
desc: 'Not shown to users. Reports the active locale: translators should translate this to the ISO code of the locale they are translating into.',
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=get-locale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-locale.js","sourceRoot":"","sources":["../../../src/utils/get-locale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,GAAG,CAAC,IAAI,EAAE;QACf,IAAI,EAAE,2IAA2I;KAClJ,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { msg } from '@lit/localize';\n\n/**\n * Returns the locale code currently active in the host app.\n *\n * This package never sets up `@lit/localize` itself (the host app owns that,\n * once), so `@lit/localize`'s own `getLocale()` isn't available here — it's\n * only returned from the host's one setup call. `msg()` always reflects the\n * host app's current locale, read fresh on every call, with no dependency on\n * when this package happened to load relative to the host setting its\n * locale. This probes a string whose only translation is the ISO code of\n * the locale it was translated into, and reads the locale off whichever\n * string comes back: the untranslated source for the source locale, or the\n * code itself once a target locale's translation is in place.\n */\nexport function getLocale(): string {\n return msg('en', {\n desc: 'Not shown to users. Reports the active locale: translators should translate this to the ISO code of the locale they are translating into.',\n });\n}\n"]}
|
package/locales/es.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { templates } from '../dist/src/locales/es.js';
|
package/locales/es.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { templates } from '../dist/src/locales/es.js';
|
package/package.json
CHANGED
|
@@ -7,12 +7,13 @@
|
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/internetarchive/iaux-collection-browser.git"
|
|
9
9
|
},
|
|
10
|
-
"version": "4.
|
|
10
|
+
"version": "4.10.0",
|
|
11
11
|
"main": "dist/index.js",
|
|
12
12
|
"module": "dist/index.js",
|
|
13
13
|
"files": [
|
|
14
14
|
"dist",
|
|
15
|
-
"!dist/test"
|
|
15
|
+
"!dist/test",
|
|
16
|
+
"locales"
|
|
16
17
|
],
|
|
17
18
|
"packageManager": "pnpm@11.27.1",
|
|
18
19
|
"engines": {
|
|
@@ -26,6 +27,8 @@
|
|
|
26
27
|
"lint": "eslint . && prettier \"**/*.ts\" --check",
|
|
27
28
|
"format": "eslint . --fix && prettier \"**/*.ts\" --write",
|
|
28
29
|
"circular": "madge --circular --extensions ts .",
|
|
30
|
+
"strings:extract": "lit-localize extract",
|
|
31
|
+
"strings:build": "node scripts/build-locales.mts && prettier --write \"src/locales/*.ts\"",
|
|
29
32
|
"test": "tsc && pnpm run lint && pnpm run circular && wtr --coverage",
|
|
30
33
|
"test:fast": "tsc && wtr --coverage",
|
|
31
34
|
"test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --watch\"",
|
|
@@ -58,6 +61,7 @@
|
|
|
58
61
|
"@eslint/eslintrc": "^3.3.7",
|
|
59
62
|
"@eslint/js": "^9.22.0",
|
|
60
63
|
"@internetarchive/result-type": "^0.0.1",
|
|
64
|
+
"@lit/localize-tools": "^0.8.2",
|
|
61
65
|
"@open-wc/eslint-config": "^13.0.0",
|
|
62
66
|
"@open-wc/testing": "^4.0.0",
|
|
63
67
|
"@rollup/plugin-image": "^3.0.3",
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
-
/** How long the pointer must rest on a tile before its preview starts. */
|
|
3
|
-
export declare const HOVER_INTENT_MS = 300;
|
|
4
|
-
/** Keyboard focus waits a little longer, so tabbing through tiles stays quiet. */
|
|
5
|
-
export declare const FOCUS_INTENT_MS = 600;
|
|
6
|
-
export declare const LONG_PRESS_MS = 500;
|
|
7
|
-
/** How long the hover info pane waits on a tile that shows previews (a bit longer than one preview cycle). */
|
|
8
|
-
export declare const PREVIEW_PANE_DELAY_MS = 5000;
|
|
9
|
-
/** Whether this user and connection should see animated previews at all. */
|
|
10
|
-
export declare function previewsAllowed(): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Decides when a tile's preview is active: after a hover-intent delay for a
|
|
13
|
-
* mouse, on keyboard focus, and on long-press for touch. Starting one preview
|
|
14
|
-
* stops whichever was active before.
|
|
15
|
-
*/
|
|
16
|
-
export declare class TilePreviewController implements ReactiveController {
|
|
17
|
-
private host;
|
|
18
|
-
private options;
|
|
19
|
-
active: boolean;
|
|
20
|
-
private timer?;
|
|
21
|
-
private pressOrigin?;
|
|
22
|
-
private suppressClick;
|
|
23
|
-
private suppressTimer?;
|
|
24
|
-
/** Whether the press in progress is the one that started the preview. */
|
|
25
|
-
private pressStartedPreview;
|
|
26
|
-
constructor(host: ReactiveControllerHost & HTMLElement, options: {
|
|
27
|
-
enabled: () => boolean;
|
|
28
|
-
});
|
|
29
|
-
hostConnected(): void;
|
|
30
|
-
hostDisconnected(): void;
|
|
31
|
-
/** Stops this tile's preview and any pending start. */
|
|
32
|
-
deactivate(): void;
|
|
33
|
-
private schedule;
|
|
34
|
-
/**
|
|
35
|
-
* A pinch (a second finger, a Safari gesture or a trackpad ctrl+wheel) is a
|
|
36
|
-
* zoom, not a request for a preview, so it cancels a pending or active one.
|
|
37
|
-
* The listeners only exist while a preview is pending or showing.
|
|
38
|
-
*/
|
|
39
|
-
private addZoomGuards;
|
|
40
|
-
private removeZoomGuards;
|
|
41
|
-
private onAnyPointerDown;
|
|
42
|
-
private onZoomGesture;
|
|
43
|
-
private onWheel;
|
|
44
|
-
private activate;
|
|
45
|
-
private onPointerEnter;
|
|
46
|
-
private onPointerLeave;
|
|
47
|
-
private onPointerDown;
|
|
48
|
-
private onPointerMove;
|
|
49
|
-
/** Ends a press. If it started the preview, the click that follows is swallowed. */
|
|
50
|
-
private onPointerUp;
|
|
51
|
-
/** A cancelled or moved press never produces a click. */
|
|
52
|
-
private onPointerCancel;
|
|
53
|
-
private onClick;
|
|
54
|
-
/** Keeps the long-press from opening the browser's link menu. */
|
|
55
|
-
private onContextMenu;
|
|
56
|
-
private onFocusIn;
|
|
57
|
-
private onFocusOut;
|
|
58
|
-
private onKeyDown;
|
|
59
|
-
private onOutsidePointerDown;
|
|
60
|
-
private onScroll;
|
|
61
|
-
}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
/** How long the pointer must rest on a tile before its preview starts. */
|
|
2
|
-
export const HOVER_INTENT_MS = 300;
|
|
3
|
-
/** Keyboard focus waits a little longer, so tabbing through tiles stays quiet. */
|
|
4
|
-
export const FOCUS_INTENT_MS = 600;
|
|
5
|
-
export const LONG_PRESS_MS = 500;
|
|
6
|
-
/** How long the hover info pane waits on a tile that shows previews (a bit longer than one preview cycle). */
|
|
7
|
-
export const PREVIEW_PANE_DELAY_MS = 5000;
|
|
8
|
-
const LONG_PRESS_MOVE_TOLERANCE_PX = 10;
|
|
9
|
-
/** The tile whose preview is currently showing. Only one is ever active. */
|
|
10
|
-
let current;
|
|
11
|
-
/** Whether this user and connection should see animated previews at all. */
|
|
12
|
-
export function previewsAllowed() {
|
|
13
|
-
if (window.matchMedia?.('(prefers-reduced-motion: reduce)').matches) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
const connection = navigator.connection;
|
|
17
|
-
if (connection?.saveData)
|
|
18
|
-
return false;
|
|
19
|
-
if (/^(slow-)?2g$/.test(connection?.effectiveType ?? ''))
|
|
20
|
-
return false;
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Decides when a tile's preview is active: after a hover-intent delay for a
|
|
25
|
-
* mouse, on keyboard focus, and on long-press for touch. Starting one preview
|
|
26
|
-
* stops whichever was active before.
|
|
27
|
-
*/
|
|
28
|
-
export class TilePreviewController {
|
|
29
|
-
constructor(host, options) {
|
|
30
|
-
this.host = host;
|
|
31
|
-
this.options = options;
|
|
32
|
-
this.active = false;
|
|
33
|
-
this.suppressClick = false;
|
|
34
|
-
/** Whether the press in progress is the one that started the preview. */
|
|
35
|
-
this.pressStartedPreview = false;
|
|
36
|
-
this.onAnyPointerDown = (e) => {
|
|
37
|
-
if (e.pointerType === 'touch' && !e.isPrimary)
|
|
38
|
-
this.deactivate();
|
|
39
|
-
};
|
|
40
|
-
this.onZoomGesture = () => {
|
|
41
|
-
this.deactivate();
|
|
42
|
-
};
|
|
43
|
-
this.onWheel = (e) => {
|
|
44
|
-
if (e.ctrlKey)
|
|
45
|
-
this.deactivate();
|
|
46
|
-
};
|
|
47
|
-
this.onPointerEnter = (e) => {
|
|
48
|
-
if (e.pointerType === 'touch')
|
|
49
|
-
return;
|
|
50
|
-
this.schedule('hover', HOVER_INTENT_MS);
|
|
51
|
-
};
|
|
52
|
-
this.onPointerLeave = (e) => {
|
|
53
|
-
if (e.pointerType === 'touch')
|
|
54
|
-
return;
|
|
55
|
-
this.deactivate();
|
|
56
|
-
};
|
|
57
|
-
this.onPointerDown = (e) => {
|
|
58
|
-
if (e.pointerType !== 'touch')
|
|
59
|
-
return;
|
|
60
|
-
if (!this.options.enabled() || !previewsAllowed())
|
|
61
|
-
return;
|
|
62
|
-
this.pressStartedPreview = false;
|
|
63
|
-
this.pressOrigin = { x: e.clientX, y: e.clientY };
|
|
64
|
-
this.schedule('long-press', LONG_PRESS_MS);
|
|
65
|
-
};
|
|
66
|
-
this.onPointerMove = (e) => {
|
|
67
|
-
if (!this.pressOrigin)
|
|
68
|
-
return;
|
|
69
|
-
const moved = Math.hypot(e.clientX - this.pressOrigin.x, e.clientY - this.pressOrigin.y);
|
|
70
|
-
if (moved > LONG_PRESS_MOVE_TOLERANCE_PX)
|
|
71
|
-
this.onPointerCancel();
|
|
72
|
-
};
|
|
73
|
-
/** Ends a press. If it started the preview, the click that follows is swallowed. */
|
|
74
|
-
this.onPointerUp = () => {
|
|
75
|
-
if (!this.pressOrigin)
|
|
76
|
-
return;
|
|
77
|
-
this.pressOrigin = undefined;
|
|
78
|
-
if (this.pressStartedPreview) {
|
|
79
|
-
this.pressStartedPreview = false;
|
|
80
|
-
this.suppressClick = true;
|
|
81
|
-
window.clearTimeout(this.suppressTimer);
|
|
82
|
-
this.suppressTimer = window.setTimeout(() => {
|
|
83
|
-
this.suppressClick = false;
|
|
84
|
-
}, 400);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
window.clearTimeout(this.timer);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
/** A cancelled or moved press never produces a click. */
|
|
91
|
-
this.onPointerCancel = () => {
|
|
92
|
-
if (!this.pressOrigin)
|
|
93
|
-
return;
|
|
94
|
-
this.pressOrigin = undefined;
|
|
95
|
-
this.pressStartedPreview = false;
|
|
96
|
-
window.clearTimeout(this.timer);
|
|
97
|
-
};
|
|
98
|
-
this.onClick = (e) => {
|
|
99
|
-
if (!this.suppressClick)
|
|
100
|
-
return;
|
|
101
|
-
this.suppressClick = false;
|
|
102
|
-
e.preventDefault();
|
|
103
|
-
e.stopPropagation();
|
|
104
|
-
};
|
|
105
|
-
/** Keeps the long-press from opening the browser's link menu. */
|
|
106
|
-
this.onContextMenu = (e) => {
|
|
107
|
-
if (this.pressOrigin || this.active)
|
|
108
|
-
e.preventDefault();
|
|
109
|
-
};
|
|
110
|
-
this.onFocusIn = (e) => {
|
|
111
|
-
const target = e.composedPath()[0];
|
|
112
|
-
if (target?.matches?.(':focus-visible')) {
|
|
113
|
-
this.schedule('focus', FOCUS_INTENT_MS);
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
this.onFocusOut = () => {
|
|
117
|
-
this.deactivate();
|
|
118
|
-
};
|
|
119
|
-
this.onKeyDown = (e) => {
|
|
120
|
-
if (e.key === 'Escape')
|
|
121
|
-
this.deactivate();
|
|
122
|
-
};
|
|
123
|
-
this.onOutsidePointerDown = (e) => {
|
|
124
|
-
if (!e.composedPath().includes(this.host))
|
|
125
|
-
this.deactivate();
|
|
126
|
-
};
|
|
127
|
-
this.onScroll = () => {
|
|
128
|
-
this.deactivate();
|
|
129
|
-
};
|
|
130
|
-
host.addController(this);
|
|
131
|
-
}
|
|
132
|
-
hostConnected() {
|
|
133
|
-
const h = this.host;
|
|
134
|
-
h.addEventListener('pointerenter', this.onPointerEnter);
|
|
135
|
-
h.addEventListener('pointerleave', this.onPointerLeave);
|
|
136
|
-
h.addEventListener('pointerdown', this.onPointerDown);
|
|
137
|
-
h.addEventListener('pointermove', this.onPointerMove);
|
|
138
|
-
h.addEventListener('pointerup', this.onPointerUp);
|
|
139
|
-
h.addEventListener('pointercancel', this.onPointerCancel);
|
|
140
|
-
h.addEventListener('contextmenu', this.onContextMenu);
|
|
141
|
-
h.addEventListener('click', this.onClick, true);
|
|
142
|
-
h.addEventListener('focusin', this.onFocusIn);
|
|
143
|
-
h.addEventListener('focusout', this.onFocusOut);
|
|
144
|
-
h.addEventListener('keydown', this.onKeyDown);
|
|
145
|
-
}
|
|
146
|
-
hostDisconnected() {
|
|
147
|
-
const h = this.host;
|
|
148
|
-
h.removeEventListener('pointerenter', this.onPointerEnter);
|
|
149
|
-
h.removeEventListener('pointerleave', this.onPointerLeave);
|
|
150
|
-
h.removeEventListener('pointerdown', this.onPointerDown);
|
|
151
|
-
h.removeEventListener('pointermove', this.onPointerMove);
|
|
152
|
-
h.removeEventListener('pointerup', this.onPointerUp);
|
|
153
|
-
h.removeEventListener('pointercancel', this.onPointerCancel);
|
|
154
|
-
h.removeEventListener('contextmenu', this.onContextMenu);
|
|
155
|
-
h.removeEventListener('click', this.onClick, true);
|
|
156
|
-
h.removeEventListener('focusin', this.onFocusIn);
|
|
157
|
-
h.removeEventListener('focusout', this.onFocusOut);
|
|
158
|
-
h.removeEventListener('keydown', this.onKeyDown);
|
|
159
|
-
this.deactivate();
|
|
160
|
-
}
|
|
161
|
-
/** Stops this tile's preview and any pending start. */
|
|
162
|
-
deactivate() {
|
|
163
|
-
window.clearTimeout(this.timer);
|
|
164
|
-
window.clearTimeout(this.suppressTimer);
|
|
165
|
-
this.timer = undefined;
|
|
166
|
-
this.pressOrigin = undefined;
|
|
167
|
-
this.pressStartedPreview = false;
|
|
168
|
-
document.removeEventListener('pointerdown', this.onOutsidePointerDown, true);
|
|
169
|
-
window.removeEventListener('scroll', this.onScroll, true);
|
|
170
|
-
this.removeZoomGuards();
|
|
171
|
-
if (current?.owner === this.host)
|
|
172
|
-
current = undefined;
|
|
173
|
-
if (this.active) {
|
|
174
|
-
this.active = false;
|
|
175
|
-
this.host.requestUpdate();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
schedule(how, delay) {
|
|
179
|
-
window.clearTimeout(this.timer);
|
|
180
|
-
if (!this.options.enabled() || !previewsAllowed())
|
|
181
|
-
return;
|
|
182
|
-
this.timer = window.setTimeout(() => this.activate(how), delay);
|
|
183
|
-
this.addZoomGuards();
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* A pinch (a second finger, a Safari gesture or a trackpad ctrl+wheel) is a
|
|
187
|
-
* zoom, not a request for a preview, so it cancels a pending or active one.
|
|
188
|
-
* The listeners only exist while a preview is pending or showing.
|
|
189
|
-
*/
|
|
190
|
-
addZoomGuards() {
|
|
191
|
-
document.addEventListener('pointerdown', this.onAnyPointerDown, true);
|
|
192
|
-
window.addEventListener('gesturestart', this.onZoomGesture);
|
|
193
|
-
window.addEventListener('wheel', this.onWheel, { passive: true });
|
|
194
|
-
}
|
|
195
|
-
removeZoomGuards() {
|
|
196
|
-
document.removeEventListener('pointerdown', this.onAnyPointerDown, true);
|
|
197
|
-
window.removeEventListener('gesturestart', this.onZoomGesture);
|
|
198
|
-
window.removeEventListener('wheel', this.onWheel);
|
|
199
|
-
}
|
|
200
|
-
activate(how) {
|
|
201
|
-
if (!this.options.enabled() || !previewsAllowed())
|
|
202
|
-
return;
|
|
203
|
-
if (current && current.owner !== this.host)
|
|
204
|
-
current.stop();
|
|
205
|
-
current = { owner: this.host, stop: () => this.deactivate() };
|
|
206
|
-
this.active = true;
|
|
207
|
-
this.host.requestUpdate();
|
|
208
|
-
if (how === 'long-press') {
|
|
209
|
-
this.pressStartedPreview = true;
|
|
210
|
-
// A touch preview stays up until the next touch elsewhere or a scroll.
|
|
211
|
-
document.addEventListener('pointerdown', this.onOutsidePointerDown, true);
|
|
212
|
-
window.addEventListener('scroll', this.onScroll, true);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
//# sourceMappingURL=tile-preview-controller.js.map
|