@internetarchive/elements 1.9.0 → 1.9.2
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 +17 -0
- package/dist/src/elements/ia-donation-form/form-elements/contact-form/ia-donation-contact-form.d.ts.map +1 -1
- package/dist/src/elements/ia-donation-form/form-elements/contact-form/ia-donation-contact-form.js +7 -7
- package/dist/src/elements/ia-donation-form/form-elements/contact-form/ia-donation-contact-form.js.map +1 -1
- package/dist/src/elements/ia-donation-form/form-elements/ia-donation-edit-donation.d.ts.map +1 -1
- package/dist/src/elements/ia-donation-form/form-elements/ia-donation-edit-donation.js +6 -6
- package/dist/src/elements/ia-donation-form/form-elements/ia-donation-edit-donation.js.map +1 -1
- package/dist/src/elements/ia-donation-form/form-elements/ia-donation-summary.d.ts.map +1 -1
- package/dist/src/elements/ia-donation-form/form-elements/ia-donation-summary.js +5 -4
- package/dist/src/elements/ia-donation-form/form-elements/ia-donation-summary.js.map +1 -1
- package/dist/src/elements/ia-donation-form/form-elements/ia-donation-total-amount.d.ts.map +1 -1
- package/dist/src/elements/ia-donation-form/form-elements/ia-donation-total-amount.js +5 -4
- package/dist/src/elements/ia-donation-form/form-elements/ia-donation-total-amount.js.map +1 -1
- package/dist/src/elements/ia-donation-form/localized-format.d.ts +20 -0
- package/dist/src/elements/ia-donation-form/localized-format.d.ts.map +1 -0
- package/dist/src/elements/ia-donation-form/localized-format.js +73 -0
- package/dist/src/elements/ia-donation-form/localized-format.js.map +1 -0
- package/dist/src/elements/ia-donation-form/modals/ia-donation-confirm-modal.d.ts.map +1 -1
- package/dist/src/elements/ia-donation-form/modals/ia-donation-confirm-modal.js +6 -2
- package/dist/src/elements/ia-donation-form/modals/ia-donation-confirm-modal.js.map +1 -1
- package/dist/src/elements/ia-donation-thermometer/ia-donation-thermometer.d.ts +12 -1
- package/dist/src/elements/ia-donation-thermometer/ia-donation-thermometer.d.ts.map +1 -1
- package/dist/src/elements/ia-donation-thermometer/ia-donation-thermometer.js +21 -9
- package/dist/src/elements/ia-donation-thermometer/ia-donation-thermometer.js.map +1 -1
- package/dist/src/locales/es.d.ts +249 -0
- package/dist/src/locales/es.d.ts.map +1 -1
- package/dist/src/locales/es.js +288 -0
- package/dist/src/locales/es.js.map +1 -1
- package/package.json +5 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The language the app last finished loading, falling back to the page's
|
|
3
|
+
* `lang`. `@lit/localize` only hands `getLocale` to whoever configures it, and
|
|
4
|
+
* this package never does, so the locale is read from its status event.
|
|
5
|
+
*/
|
|
6
|
+
export declare function currentLocale(): string;
|
|
7
|
+
/**
|
|
8
|
+
* Formats a US dollar amount for the current language. English keeps the
|
|
9
|
+
* `$10.00` form. Other languages get `Intl.NumberFormat`'s USD form, like
|
|
10
|
+
* `10,00 US$` in Spanish.
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatUsd(amount: number, precision?: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* The country choices as `[code, name]` pairs. English keeps the list in its
|
|
15
|
+
* own order and spelling. Other languages get each name from
|
|
16
|
+
* `Intl.DisplayNames`, sorted in that language, and a country the browser
|
|
17
|
+
* can't name keeps its English name.
|
|
18
|
+
*/
|
|
19
|
+
export declare function localizedCountries(): [string, string][];
|
|
20
|
+
//# sourceMappingURL=localized-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localized-format.d.ts","sourceRoot":"","sources":["../../../../src/elements/ia-donation-form/localized-format.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAItC;AAMD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,MAAM,CAe/D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAgBvD"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import currency from 'currency.js';
|
|
2
|
+
import { countries } from './form-elements/contact-form/countries.js';
|
|
3
|
+
let readyLocale;
|
|
4
|
+
if (typeof window !== 'undefined') {
|
|
5
|
+
window.addEventListener('lit-localize-status', (event) => {
|
|
6
|
+
const detail = event.detail;
|
|
7
|
+
if (detail.status === 'ready')
|
|
8
|
+
readyLocale = detail.readyLocale;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The language the app last finished loading, falling back to the page's
|
|
13
|
+
* `lang`. `@lit/localize` only hands `getLocale` to whoever configures it, and
|
|
14
|
+
* this package never does, so the locale is read from its status event.
|
|
15
|
+
*/
|
|
16
|
+
export function currentLocale() {
|
|
17
|
+
if (readyLocale)
|
|
18
|
+
return readyLocale;
|
|
19
|
+
if (typeof document === 'undefined')
|
|
20
|
+
return 'en';
|
|
21
|
+
return document.documentElement.lang || 'en';
|
|
22
|
+
}
|
|
23
|
+
function isEnglish(locale) {
|
|
24
|
+
return locale === 'en' || locale.startsWith('en-');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Formats a US dollar amount for the current language. English keeps the
|
|
28
|
+
* `$10.00` form. Other languages get `Intl.NumberFormat`'s USD form, like
|
|
29
|
+
* `10,00 US$` in Spanish.
|
|
30
|
+
*/
|
|
31
|
+
export function formatUsd(amount, precision = 2) {
|
|
32
|
+
const locale = currentLocale();
|
|
33
|
+
if (isEnglish(locale)) {
|
|
34
|
+
return currency(amount, { symbol: '$', precision }).format();
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
return new Intl.NumberFormat(locale, {
|
|
38
|
+
style: 'currency',
|
|
39
|
+
currency: 'USD',
|
|
40
|
+
minimumFractionDigits: precision,
|
|
41
|
+
maximumFractionDigits: precision,
|
|
42
|
+
}).format(amount);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return currency(amount, { symbol: '$', precision }).format();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The country choices as `[code, name]` pairs. English keeps the list in its
|
|
50
|
+
* own order and spelling. Other languages get each name from
|
|
51
|
+
* `Intl.DisplayNames`, sorted in that language, and a country the browser
|
|
52
|
+
* can't name keeps its English name.
|
|
53
|
+
*/
|
|
54
|
+
export function localizedCountries() {
|
|
55
|
+
const locale = currentLocale();
|
|
56
|
+
const entries = Object.entries(countries);
|
|
57
|
+
if (isEnglish(locale))
|
|
58
|
+
return entries;
|
|
59
|
+
try {
|
|
60
|
+
const displayNames = new Intl.DisplayNames([locale], { type: 'region' });
|
|
61
|
+
const collator = new Intl.Collator(locale);
|
|
62
|
+
return entries
|
|
63
|
+
.map(([code, englishName]) => {
|
|
64
|
+
const name = displayNames.of(code);
|
|
65
|
+
return [code, name && name !== code ? name : englishName.trim()];
|
|
66
|
+
})
|
|
67
|
+
.sort((a, b) => collator.compare(a[1], b[1]));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return entries;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=localized-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localized-format.js","sourceRoot":"","sources":["../../../../src/elements/ia-donation-form/localized-format.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,aAAa,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAInE,IAAI,WAA+B,CAAC;AAEpC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,MAAM,CAAC,gBAAgB,CAAC,qBAAqB,EAAE,CAAC,KAAK,EAAE,EAAE;QACvD,MAAM,MAAM,GAAI,KAAyC,CAAC,MAAM,CAAC;QACjE,IAAI,MAAM,CAAC,MAAM,KAAK,OAAO;YAAE,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,U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IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QACzE,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC3C,OAAO,OAAO;aACX,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,EAAoB,EAAE;YAC7C,MAAM,IAAI,GAAG,YAAY,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YACnC,OAAO,CAAC,IAAI,EAAE,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;QACnE,CAAC,CAAC;aACD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC","sourcesContent":["import currency from 'currency.js';\n\nimport { countries } from './form-elements/contact-form/countries';\n\ntype LocaleStatusDetail = { status: string; readyLocale?: string };\n\nlet readyLocale: string | undefined;\n\nif (typeof window !== 'undefined') {\n window.addEventListener('lit-localize-status', (event) => {\n const detail = (event as CustomEvent<LocaleStatusDetail>).detail;\n if (detail.status === 'ready') readyLocale = detail.readyLocale;\n });\n}\n\n/**\n * The language the app last finished loading, falling back to the page's\n * `lang`. `@lit/localize` only hands `getLocale` to whoever configures it, and\n * this package never does, so the locale is read from its status event.\n */\nexport function currentLocale(): string {\n if (readyLocale) return readyLocale;\n if (typeof document === 'undefined') return 'en';\n return document.documentElement.lang || 'en';\n}\n\nfunction isEnglish(locale: string): boolean {\n return locale === 'en' || locale.startsWith('en-');\n}\n\n/**\n * Formats a US dollar amount for the current language. English keeps the\n * `$10.00` form. Other languages get `Intl.NumberFormat`'s USD form, like\n * `10,00 US$` in Spanish.\n */\nexport function formatUsd(amount: number, precision = 2): string {\n const locale = currentLocale();\n if (isEnglish(locale)) {\n return currency(amount, { symbol: '$', precision }).format();\n }\n try {\n return new Intl.NumberFormat(locale, {\n style: 'currency',\n currency: 'USD',\n minimumFractionDigits: precision,\n maximumFractionDigits: precision,\n }).format(amount);\n } catch {\n return currency(amount, { symbol: '$', precision }).format();\n }\n}\n\n/**\n * The country choices as `[code, name]` pairs. English keeps the list in its\n * own order and spelling. Other languages get each name from\n * `Intl.DisplayNames`, sorted in that language, and a country the browser\n * can't name keeps its English name.\n */\nexport function localizedCountries(): [string, string][] {\n const locale = currentLocale();\n const entries = Object.entries(countries);\n if (isEnglish(locale)) return entries;\n try {\n const displayNames = new Intl.DisplayNames([locale], { type: 'region' });\n const collator = new Intl.Collator(locale);\n return entries\n .map(([code, englishName]): [string, string] => {\n const name = displayNames.of(code);\n return [code, name && name !== code ? name : englishName.trim()];\n })\n .sort((a, b) => collator.compare(a[1], b[1]));\n } catch {\n return entries;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ia-donation-confirm-modal.d.ts","sourceRoot":"","sources":["../../../../../src/elements/ia-donation-form/modals/ia-donation-confirm-modal.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"ia-donation-confirm-modal.d.ts","sourceRoot":"","sources":["../../../../../src/elements/ia-donation-form/modals/ia-donation-confirm-modal.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,KAAK,CAAC;AAQb,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;;GAGG;AACH,qBAEa,sBAAuB,SAAQ,UAAU;IACxB,MAAM,SAAK;IAEvC,iFAAiF;IACrD,YAAY,SAAS;IAErB,YAAY,EAAE,YAAY,CAAwB;IAE9C,eAAe,EAAE,MAAM,IAAI,CAAY;IAEvC,cAAc,EAAE,MAAM,IAAI,CAAY;IAEtE,OAAO,KAAK,eAAe,GAG1B;IAED,IAAI,gBAAgB,IAAI,cAAc,CAQrC;IAED,IAAI,iBAAiB,IAAI,cAAc,CAQtC;IAED,IAAI,UAAU,IAAI,MAAM,CAIvB;IAED,MAAM,IAAI,cAAc;IAiBxB,MAAM,KAAK,MAAM,IAAI,cAAc,CAsDlC;IAED;;;;OAIG;IACH,IAAI,cAAc,IAAI,MAAM,CAiD3B;CACF"}
|
|
@@ -2,7 +2,8 @@ import { __decorate } from "tslib";
|
|
|
2
2
|
import { css, html, LitElement, } from 'lit';
|
|
3
3
|
import { property } from 'lit/decorators.js';
|
|
4
4
|
import { customElement } from '../../../utils/custom-element.js';
|
|
5
|
-
import { msg } from '@lit/localize';
|
|
5
|
+
import { localized, msg } from '@lit/localize';
|
|
6
|
+
import { formatUsd } from '../localized-format.js';
|
|
6
7
|
import currency from 'currency.js';
|
|
7
8
|
import themeStyles from '../../../themes/theme-styles.js';
|
|
8
9
|
import { DonationType } from '../models/donation-type.js';
|
|
@@ -21,6 +22,8 @@ let IADonationConfirmModal = class IADonationConfirmModal extends LitElement {
|
|
|
21
22
|
this.cancelDonation = () => { };
|
|
22
23
|
}
|
|
23
24
|
get formattedAmount() {
|
|
25
|
+
if (this.currencyType === 'USD')
|
|
26
|
+
return formatUsd(this.amount);
|
|
24
27
|
return currency(this.amount, { symbol: this.currencySymbol }).format();
|
|
25
28
|
}
|
|
26
29
|
get confirmationText() {
|
|
@@ -189,7 +192,8 @@ __decorate([
|
|
|
189
192
|
property({ attribute: false })
|
|
190
193
|
], IADonationConfirmModal.prototype, "cancelDonation", void 0);
|
|
191
194
|
IADonationConfirmModal = __decorate([
|
|
192
|
-
customElement('ia-donation-confirm-modal')
|
|
195
|
+
customElement('ia-donation-confirm-modal'),
|
|
196
|
+
localized()
|
|
193
197
|
], IADonationConfirmModal);
|
|
194
198
|
export { IADonationConfirmModal };
|
|
195
199
|
//# sourceMappingURL=ia-donation-confirm-modal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ia-donation-confirm-modal.js","sourceRoot":"","sources":["../../../../../src/elements/ia-donation-form/modals/ia-donation-confirm-modal.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,GAAG,EACH,IAAI,EACJ,UAAU,GAGX,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"ia-donation-confirm-modal.js","sourceRoot":"","sources":["../../../../../src/elements/ia-donation-form/modals/ia-donation-confirm-modal.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,GAAG,EACH,IAAI,EACJ,UAAU,GAGX,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,QAAQ,MAAM,aAAa,CAAC;AAEnC,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;;GAGG;AAGI,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,UAAU;IAA/C;;QACuB,WAAM,GAAG,CAAC,CAAC;QAEvC,iFAAiF;QACrD,iBAAY,GAAG,KAAK,CAAC;QAErB,iBAAY,GAAiB,YAAY,CAAC,OAAO,CAAC;QAE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AAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4DAAsB;AAErB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4DAAmD;AAE9C;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;+DAAwC;AAEvC;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;8DAAuC;AAV3D,sBAAsB;IAFlC,aAAa,CAAC,2BAA2B,CAAC;IAC1C,SAAS,EAAE;GACC,sBAAsB,CA2KlC","sourcesContent":["import {\n css,\n html,\n LitElement,\n type CSSResultGroup,\n type TemplateResult,\n} from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { customElement } from '@src/utils/custom-element';\nimport { localized, msg } from '@lit/localize';\nimport { formatUsd } from '../localized-format';\nimport currency from 'currency.js';\n\nimport themeStyles from '@src/themes/theme-styles';\nimport { DonationType } from '../models/donation-type';\n\n/**\n * The confirmation step shown before a PayPal donation goes through: what the\n * donor is about to give, with Complete and Cancel buttons.\n */\n@customElement('ia-donation-confirm-modal')\n@localized()\nexport class IADonationConfirmModal extends LitElement {\n @property({ type: Number }) amount = 5;\n\n /** An ISO currency code, e.g. `USD`. Drives the symbol shown with the amount. */\n @property({ type: String }) currencyType = 'USD';\n\n @property({ type: String }) donationType: DonationType = DonationType.OneTime;\n\n @property({ attribute: false }) confirmDonation: () => void = () => {};\n\n @property({ attribute: false }) cancelDonation: () => void = () => {};\n\n private get formattedAmount(): string {\n if (this.currencyType === 'USD') return formatUsd(this.amount);\n return currency(this.amount, { symbol: this.currencySymbol }).format();\n }\n\n get confirmationText(): TemplateResult {\n return msg(html`\n <p>\n You are about to make a <b>${this.donationType}</b> donation of\n <b>${this.formattedAmount} ${this.currencyType}</b> to the Internet\n Archive.\n </p>\n `);\n }\n\n get confirmUpsellText(): TemplateResult {\n return msg(html`\n <p>\n You are about to begin making <b>monthly</b> donations of\n <b>${this.formattedAmount} ${this.currencyType}</b> to the Internet\n Archive. (Your first recurring contribution will be next month.)\n </p>\n `);\n }\n\n get confirmCTA(): string {\n return this.donationType === DonationType.Upsell\n ? msg('Start monthly donation')\n : msg('Complete donation');\n }\n\n render(): TemplateResult {\n return html`\n ${this.donationType === DonationType.Upsell\n ? this.confirmUpsellText\n : this.confirmationText}\n\n <div class=\"cta-group\">\n <button id=\"confirm\" @click=${() => this.confirmDonation()}>\n ${this.confirmCTA}\n </button>\n <button id=\"cancel\" @click=${() => this.cancelDonation()}>\n ${msg('Cancel')}\n </button>\n </div>\n `;\n }\n\n static get styles(): CSSResultGroup {\n return [\n themeStyles,\n css`\n :host {\n --donation-confirm-base-font-size--: var(\n --ia-donation-form-base-font-size,\n 10px\n );\n --donation-confirm-cta-color--: var(\n --ia-donation-upsell-cta-button-color,\n var(--navy-blue)\n );\n --donation-confirm-cta-disabled-color--: var(\n --ia-donation-upsell-cta-button-disabled-color,\n rgba(109, 148, 201, 0.5)\n );\n\n display: block;\n }\n\n button {\n outline: none;\n cursor: pointer;\n }\n\n button#confirm {\n font-size: calc(var(--donation-confirm-base-font-size--) * 2);\n display: block;\n width: 100%;\n margin-top: var(--padding-sm);\n padding: var(--donation-confirm-base-font-size--)\n calc(var(--donation-confirm-base-font-size--) * 2);\n background-color: var(--donation-confirm-cta-color--);\n color: var(--true-white);\n border-radius: 5px;\n border: 0;\n font-weight: bold;\n line-height: normal;\n }\n\n button#cancel {\n margin-top: var(--donation-confirm-base-font-size--);\n border: 0;\n text-decoration: underline;\n background-color: transparent;\n }\n\n button:disabled {\n background-color: var(--donation-confirm-cta-disabled-color--);\n cursor: not-allowed;\n }\n `,\n ];\n }\n\n /**\n * The symbol for a PayPal-supported currency code. Dollars for anything\n * unlisted, which covers USD and NZD.\n * https://developer.paypal.com/docs/reports/reference/paypal-supported-currencies/\n */\n get currencySymbol(): string {\n switch (this.currencyType) {\n case 'AUD':\n return 'AU$';\n case 'BRL':\n return 'R$';\n case 'CAD':\n return 'CA$';\n case 'CHF':\n return 'Fr';\n case 'CNY':\n return '¥';\n case 'CZK':\n return 'Kč';\n case 'DKK':\n return 'Kr';\n case 'EUR':\n return '€';\n case 'GBP':\n return '£';\n case 'HKD':\n return 'HK$';\n case 'HUF':\n return 'Ft';\n case 'ILS':\n return '₪';\n case 'JPY':\n return '¥';\n case 'MXN':\n return 'MX$';\n case 'MYR':\n return 'RM';\n case 'NOK':\n return 'kr';\n case 'PLN':\n return 'zł';\n case 'RUB':\n return '₽';\n case 'SEK':\n return 'kr';\n case 'SGD':\n return 'S$';\n case 'THB':\n return '฿';\n case 'TWD':\n return 'NT$';\n default:\n return '$';\n }\n }\n}\n"]}
|
|
@@ -11,9 +11,20 @@ export type CurrentAmountMode = 'on' | 'off';
|
|
|
11
11
|
*/
|
|
12
12
|
export declare class IADonationThermometer extends LitElement {
|
|
13
13
|
goalMessageMode: GoalMessageMode;
|
|
14
|
+
/**
|
|
15
|
+
* The message shown when the goal is near. Empty shows the built-in message
|
|
16
|
+
* in the current language.
|
|
17
|
+
*/
|
|
14
18
|
goalNearMessage: string;
|
|
19
|
+
/**
|
|
20
|
+
* The message shown when the goal is reached. Empty shows the built-in
|
|
21
|
+
* message in the current language.
|
|
22
|
+
*/
|
|
15
23
|
goalReachedMessage: string;
|
|
16
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* The accessible name of the progress bar, for screen readers. Empty uses
|
|
26
|
+
* the built-in name in the current language.
|
|
27
|
+
*/
|
|
17
28
|
label: string;
|
|
18
29
|
goalAmount: number;
|
|
19
30
|
currentAmountMode: CurrentAmountMode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ia-donation-thermometer.d.ts","sourceRoot":"","sources":["../../../../src/elements/ia-donation-thermometer/ia-donation-thermometer.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EAEV,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,KAAK,CAAC;AAOb,iFAAiF;AACjF,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE3D,wDAAwD;AACxD,MAAM,MAAM,iBAAiB,GAAG,IAAI,GAAG,KAAK,CAAC;AAE7C;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"ia-donation-thermometer.d.ts","sourceRoot":"","sources":["../../../../src/elements/ia-donation-thermometer/ia-donation-thermometer.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EAEV,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,KAAK,CAAC;AAOb,iFAAiF;AACjF,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE3D,wDAAwD;AACxD,MAAM,MAAM,iBAAiB,GAAG,IAAI,GAAG,KAAK,CAAC;AAE7C;;;;;GAKG;AACH,qBAEa,qBAAsB,SAAQ,UAAU;IACvB,eAAe,EAAE,eAAe,CAAY;IAExE;;;OAGG;IACyB,eAAe,SAAM;IAEjD;;;OAGG;IACyB,kBAAkB,SAAM;IAEpD;;;OAGG;IACyB,KAAK,SAAM;IAEX,UAAU,SAAa;IAEvB,iBAAiB,EAAE,iBAAiB,CAAQ;IAE5C,aAAa,SAAK;IAEjB,OAAO,CAAC,gBAAgB,CAAC,CAAiB;IAE3C,OAAO,CAAC,eAAe,CAAC,CAAiB;IAE5D,OAAO,CAAC,qBAAqB,CAAK;IAElC,OAAO,CAAC,oBAAoB,CAAK;IAE1C;;;OAGG;IACH,OAAO,CAAC,cAAc,CAAC,CAAiB;IAExC;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB,CAAwB;IAEnD,OAAO,CAAC,oBAAoB,CAAwB;IAEpD,MAAM,IAAI,cAAc;IA2BxB,OAAO,KAAK,wBAAwB,GAMnC;IAED;;;;;OAKG;IACH,OAAO,KAAK,wBAAwB,GAKnC;IAED,iBAAiB,IAAI,IAAI;IAUzB,oBAAoB,IAAI,IAAI;IAQ5B,OAAO,IAAI,IAAI;IAIf,kFAAkF;IAClF,OAAO,CAAC,YAAY;IAgBpB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,YAAY;IAYpB,OAAO,KAAK,WAAW,GAItB;IAED,OAAO,KAAK,yBAAyB,GAEpC;IAED,OAAO,KAAK,sBAAsB,GAEjC;IAED;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAYpB,OAAO,KAAK,kBAAkB,GAS7B;IAED;;;;;OAKG;IACH,OAAO,KAAK,WAAW,GAItB;IAED;;;;OAIG;IACH,OAAO,KAAK,aAAa,GAGxB;IAED;;;OAGG;IACH,OAAO,KAAK,eAAe,GAK1B;IAED,MAAM,KAAK,MAAM,IAAI,cAAc,CAmIlC;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,yBAAyB,EAAE,qBAAqB,CAAC;KAClD;CACF"}
|
|
@@ -2,7 +2,7 @@ import { __decorate } from "tslib";
|
|
|
2
2
|
import { css, html, LitElement, nothing, } from 'lit';
|
|
3
3
|
import { property, query, state } from 'lit/decorators.js';
|
|
4
4
|
import { customElement } from '../../utils/custom-element.js';
|
|
5
|
-
import { msg, str } from '@lit/localize';
|
|
5
|
+
import { localized, msg, str } from '@lit/localize';
|
|
6
6
|
import themeStyles from '../../themes/theme-styles.js';
|
|
7
7
|
/**
|
|
8
8
|
* A horizontal progress bar for a fundraising goal, as shown in the
|
|
@@ -14,10 +14,21 @@ let IADonationThermometer = class IADonationThermometer extends LitElement {
|
|
|
14
14
|
constructor() {
|
|
15
15
|
super(...arguments);
|
|
16
16
|
this.goalMessageMode = 'amount';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The message shown when the goal is near. Empty shows the built-in message
|
|
19
|
+
* in the current language.
|
|
20
|
+
*/
|
|
21
|
+
this.goalNearMessage = '';
|
|
22
|
+
/**
|
|
23
|
+
* The message shown when the goal is reached. Empty shows the built-in
|
|
24
|
+
* message in the current language.
|
|
25
|
+
*/
|
|
26
|
+
this.goalReachedMessage = '';
|
|
27
|
+
/**
|
|
28
|
+
* The accessible name of the progress bar, for screen readers. Empty uses
|
|
29
|
+
* the built-in name in the current language.
|
|
30
|
+
*/
|
|
31
|
+
this.label = '';
|
|
21
32
|
this.goalAmount = 7_500_000;
|
|
22
33
|
this.currentAmountMode = 'on';
|
|
23
34
|
this.currentAmount = 0;
|
|
@@ -40,7 +51,7 @@ let IADonationThermometer = class IADonationThermometer extends LitElement {
|
|
|
40
51
|
class="thermometer-background ${this.thermometerValuePosition}"
|
|
41
52
|
style="--fill-end--: ${this.percentComplete}%"
|
|
42
53
|
role="progressbar"
|
|
43
|
-
aria-label="${this.label}"
|
|
54
|
+
aria-label="${this.label || msg('Donation progress')}"
|
|
44
55
|
aria-valuemin="0"
|
|
45
56
|
aria-valuemax="${this.progressMax}"
|
|
46
57
|
aria-valuenow="${this.progressValue}"
|
|
@@ -128,8 +139,8 @@ let IADonationThermometer = class IADonationThermometer extends LitElement {
|
|
|
128
139
|
}
|
|
129
140
|
get goalMessage() {
|
|
130
141
|
return this.currentAmount >= this.goalAmount
|
|
131
|
-
? this.goalReachedMessage
|
|
132
|
-
: this.goalNearMessage;
|
|
142
|
+
? this.goalReachedMessage || msg('We’ve reached our goal!')
|
|
143
|
+
: this.goalNearMessage || msg('We’ve almost reached our goal!');
|
|
133
144
|
}
|
|
134
145
|
get currentAmountDisplayValue() {
|
|
135
146
|
return this.formatNumber(this.currentAmount);
|
|
@@ -363,7 +374,8 @@ __decorate([
|
|
|
363
374
|
state()
|
|
364
375
|
], IADonationThermometer.prototype, "thermometerFillWidth", void 0);
|
|
365
376
|
IADonationThermometer = __decorate([
|
|
366
|
-
customElement('ia-donation-thermometer')
|
|
377
|
+
customElement('ia-donation-thermometer'),
|
|
378
|
+
localized()
|
|
367
379
|
], IADonationThermometer);
|
|
368
380
|
export { IADonationThermometer };
|
|
369
381
|
//# sourceMappingURL=ia-donation-thermometer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ia-donation-thermometer.js","sourceRoot":"","sources":["../../../../src/elements/ia-donation-thermometer/ia-donation-thermometer.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,GAAG,EACH,IAAI,EACJ,UAAU,EACV,OAAO,GAGR,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,WAAW,MAAM,0BAA0B,CAAC;AAQnD;;;;;GAKG;AAEI,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,UAAU;IAA9C;;QACuB,oBAAe,GAAoB,QAAQ,CAAC;QAE5C,oBAAe,GAAG,GAAG,CAC/C,gCAAgC,CACjC,CAAC;QAE0B,uBAAkB,GAAG,GAAG,CAClD,yBAAyB,CAC1B,CAAC;QAEF,mEAAmE;QACvC,UAAK,GAAG,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAEjC,eAAU,GAAG,SAAS,CAAC;QAEvB,sBAAiB,GAAsB,IAAI,CAAC;QAE5C,kBAAa,GAAG,CAAC,CAAC;QAM7B,0BAAqB,GAAG,CAAC,CAAC;QAE1B,yBAAoB,GAAG,CAAC,CAAC;QAQ1C;;;;;WAKG;QACK,wBAAmB,GAAmB,IAAI,CAAC;QAE3C,yBAAoB,GAAmB,IAAI,CAAC;IAmUtD,CAAC;IAjUC,MAAM;QACJ,OAAO,IAAI,CAAA;;;;4CAI6B,IAAI,CAAC,wBAAwB;mCACtC,IAAI,CAAC,eAAe;;0BAE7B,IAAI,CAAC,KAAK;;6BAEP,IAAI,CAAC,WAAW;6BAChB,IAAI,CAAC,aAAa;8BACjB,IAAI,CAAC,yBAAyB;;;;;cAK9C,IAAI,CAAC,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jC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yDAAwB;AAEvB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gEAA6C;AAE5C;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4DAAmB;AAET;IAApC,KAAK,CAAC,oBAAoB,CAAC;+DAA2C;AAEnC;IAAnC,KAAK,CAAC,mBAAmB,CAAC;8DAA0C;AAEpD;IAAhB,KAAK,EAAE;oEAAmC;AAE1B;IAAhB,KAAK,EAAE;mEAAkC;AA1B/B,qBAAqB;IADjC,aAAa,CAAC,yBAAyB,CAAC;GAC5B,qBAAqB,CA6WjC","sourcesContent":["import {\n css,\n html,\n LitElement,\n nothing,\n type CSSResultGroup,\n type TemplateResult,\n} from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport { customElement } from '@src/utils/custom-element';\nimport { msg, str } from '@lit/localize';\n\nimport themeStyles from '@src/themes/theme-styles';\n\n/** What the text beside the bar says: the goal amount, a message, or nothing. */\nexport type GoalMessageMode = 'off' | 'amount' | 'message';\n\n/** Whether the current amount is printed on the bar. */\nexport type CurrentAmountMode = 'on' | 'off';\n\n/**\n * A horizontal progress bar for a fundraising goal, as shown in the\n * archive.org donation banner. The fill grows with `currentAmount`, the amount\n * raised is printed on the fill when it fits and beside it when it doesn't,\n * and the goal (or a goal message) sits to the right of the bar.\n */\n@customElement('ia-donation-thermometer')\nexport class IADonationThermometer extends LitElement {\n @property({ type: String }) goalMessageMode: GoalMessageMode = 'amount';\n\n @property({ type: String }) goalNearMessage = msg(\n 'We’ve almost reached our goal!',\n );\n\n @property({ type: String }) goalReachedMessage = msg(\n 'We’ve reached our goal!',\n );\n\n /** The accessible name of the progress bar, for screen readers. */\n @property({ type: String }) label = msg('Donation progress');\n\n @property({ type: Number }) goalAmount = 7_500_000;\n\n @property({ type: String }) currentAmountMode: CurrentAmountMode = 'on';\n\n @property({ type: Number }) currentAmount = 0;\n\n @query('.thermometer-value') private thermometerValue?: HTMLDivElement;\n\n @query('.thermometer-fill') private thermometerFill?: HTMLDivElement;\n\n @state() private thermometerValueWidth = 0;\n\n @state() private thermometerFillWidth = 0;\n\n /**\n * Watches the fill and the value label so the label can move to whichever\n * side of the fill has room for it.\n */\n private resizeObserver?: ResizeObserver;\n\n /**\n * The observed nodes are tracked so each is observed exactly once. Calling\n * `observe` on an already-observed target re-reports its size, which costs a\n * notification on every render. Lit also discards the value label when\n * `currentAmountMode` turns it off, so a replacement has to be picked up.\n */\n private observedFillElement: Element | null = null;\n\n private observedValueElement: Element | null = null;\n\n render(): TemplateResult {\n return html`\n <div class=\"thermometer-message-container\">\n <div class=\"thermometer-container\">\n <div\n class=\"thermometer-background ${this.thermometerValuePosition}\"\n style=\"--fill-end--: ${this.percentComplete}%\"\n role=\"progressbar\"\n aria-label=\"${this.label}\"\n aria-valuemin=\"0\"\n aria-valuemax=\"${this.progressMax}\"\n aria-valuenow=\"${this.progressValue}\"\n aria-valuetext=\"${this.currentAmountDisplayValue}\"\n >\n <div class=\"thermometer-clip\">\n <div class=\"thermometer-fill\"></div>\n </div>\n ${this.thermometerValueTemplate}\n </div>\n </div>\n ${this.goalMessageMode !== 'off'\n ? html`<div class=\"donate-goal\">${this.currentGoalMessage}</div>`\n : nothing}\n </div>\n `;\n }\n\n private get thermometerValueTemplate(): TemplateResult | typeof nothing {\n return this.currentAmountMode === 'off'\n ? nothing\n : html`\n <div class=\"thermometer-value\">${this.currentAmountDisplayValue}</div>\n `;\n }\n\n /**\n * Which side of the fill's end the value label sits on, as a class name for\n * the CSS that places it. The label sits over the fill when the fill is\n * wider than the label plus a little breathing room, and just past the\n * fill's right edge otherwise.\n */\n private get thermometerValuePosition(): 'value-left' | 'value-right' {\n const buffer = 10;\n return this.thermometerValueWidth + buffer < this.thermometerFillWidth\n ? 'value-left'\n : 'value-right';\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n this.resizeObserver = new ResizeObserver((entries) =>\n this.handleResize(entries),\n );\n // On a re-connect the fill already exists; on first connect it doesn't\n // until the first render, and `updated` picks it up then.\n this.observeParts();\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.resizeObserver?.disconnect();\n this.resizeObserver = undefined;\n this.observedFillElement = null;\n this.observedValueElement = null;\n }\n\n updated(): void {\n this.observeParts();\n }\n\n /** Observes the fill and the value label, picking up either if it is replaced. */\n private observeParts(): void {\n const observer = this.resizeObserver;\n if (!observer) return;\n\n this.observedFillElement = this.observeInPlaceOf(\n observer,\n this.observedFillElement,\n this.thermometerFill ?? null,\n );\n this.observedValueElement = this.observeInPlaceOf(\n observer,\n this.observedValueElement,\n this.thermometerValue ?? null,\n );\n }\n\n /**\n * Swaps `observed` for `current` on the observer and returns whichever is\n * now being watched. A target that hasn't changed is left alone.\n */\n private observeInPlaceOf(\n observer: ResizeObserver,\n observed: Element | null,\n current: Element | null,\n ): Element | null {\n if (current === observed) return observed;\n if (observed) observer.unobserve(observed);\n if (current) observer.observe(current);\n return current;\n }\n\n private handleResize(entries: ResizeObserverEntry[]): void {\n for (const entry of entries) {\n const width =\n entry.borderBoxSize?.[0]?.inlineSize ?? entry.contentRect.width;\n if (entry.target === this.observedFillElement) {\n this.thermometerFillWidth = width;\n } else if (entry.target === this.observedValueElement) {\n this.thermometerValueWidth = width;\n }\n }\n }\n\n private get goalMessage(): string {\n return this.currentAmount >= this.goalAmount\n ? this.goalReachedMessage\n : this.goalNearMessage;\n }\n\n private get currentAmountDisplayValue(): string {\n return this.formatNumber(this.currentAmount);\n }\n\n private get goalAmountDisplayValue(): string {\n return this.formatNumber(this.goalAmount);\n }\n\n /**\n * Formats a dollar amount in millions, e.g. `$0.5MM` or `$35MM`. Amounts\n * under ten million keep one decimal place, larger ones round to a whole\n * number.\n */\n private formatNumber(number: number): string {\n if (!Number.isFinite(number) || number === 0) return '$0';\n const suffix = 'MM';\n const divisor = 1_000_000;\n const result = number / divisor;\n const roundToOne = result < 10;\n const rounded = roundToOne\n ? Math.round((result + Number.EPSILON) * 10) / 10\n : Math.round(result);\n return `$${rounded}${suffix}`;\n }\n\n private get currentGoalMessage(): string {\n switch (this.goalMessageMode) {\n case 'amount':\n return msg(str`${this.goalAmountDisplayValue} goal`);\n case 'message':\n return this.goalMessage;\n case 'off':\n return '';\n }\n }\n\n /**\n * The goal the bar measures against. A goal that isn't a positive, finite\n * number leaves the bar empty, since there is no range to report progress\n * against. Named clear of `ariaValueMax`, which `HTMLElement` declares as a\n * public string.\n */\n private get progressMax(): number {\n return Number.isFinite(this.goalAmount) && this.goalAmount > 0\n ? this.goalAmount\n : 0;\n }\n\n /**\n * The progress reported to screen readers, clamped into the\n * `aria-valuemin`/`aria-valuemax` range the spec requires.\n * `aria-valuetext` carries the amount as it is displayed.\n */\n private get progressValue(): number {\n if (!Number.isFinite(this.currentAmount)) return 0;\n return Math.min(Math.max(this.currentAmount, 0), this.progressMax);\n }\n\n /**\n * How much of the bar is filled, as a percentage, clamped to `0`-`100`. An\n * amount or goal that can't produce a usable percentage empties the bar.\n */\n private get percentComplete(): number {\n const goal = this.progressMax;\n if (goal === 0 || !Number.isFinite(this.currentAmount)) return 0;\n const percent = (this.currentAmount / goal) * 100;\n return Math.min(Math.max(percent, 0), 100);\n }\n\n static get styles(): CSSResultGroup {\n return [\n themeStyles,\n css`\n :host {\n --donation-thermometer-height--: var(\n --ia-donation-thermometer-height,\n 20px\n );\n --donation-thermometer-fill-color--: var(\n --ia-donation-thermometer-fill-color,\n #23765d\n );\n --donation-thermometer-track-color--: var(\n --ia-donation-thermometer-track-color,\n #b8f5e2\n );\n --donation-thermometer-border--: var(\n --ia-donation-thermometer-border,\n 1px solid var(--donation-thermometer-fill-color--)\n );\n /* Large enough to round any height into a pill */\n --donation-thermometer-border-radius--: var(\n --ia-donation-thermometer-border-radius,\n 9999px\n );\n --donation-thermometer-value-on-fill-color--: var(\n --ia-donation-thermometer-value-on-fill-color,\n var(--true-white)\n );\n --donation-thermometer-value-on-track-color--: var(\n --ia-donation-thermometer-value-on-track-color,\n var(--donation-thermometer-fill-color--)\n );\n --donation-thermometer-goal-color--: var(--primary-text-color);\n --donation-thermometer-goal-padding--: var(\n --ia-donation-thermometer-goal-padding,\n 0 10px\n );\n\n display: block;\n height: var(--donation-thermometer-height--);\n }\n\n .thermometer-message-container {\n height: 100%;\n display: flex;\n align-items: center;\n }\n\n .thermometer-container {\n height: 100%;\n flex: 1;\n }\n\n .thermometer-background {\n box-sizing: border-box;\n position: relative;\n background-color: var(--donation-thermometer-track-color--);\n height: 100%;\n border-radius: var(--donation-thermometer-border-radius--);\n border: var(--donation-thermometer-border--);\n }\n\n /*\n * Clips the square-ended fill to the rounded track. It covers only the\n * fill, so the label is never cut off by it.\n */\n .thermometer-clip {\n position: absolute;\n inset: 0;\n overflow: hidden;\n border-radius: var(--donation-thermometer-border-radius--);\n }\n\n .thermometer-fill {\n background-color: var(--donation-thermometer-fill-color--);\n height: 100%;\n /*\n * The fallback matters: without it a missing --fill-end-- makes the\n * declaration invalid, width resolves to auto, and the bar paints as\n * a fully funded fundraiser.\n */\n width: var(--fill-end--, 0%);\n }\n\n /*\n * The label is placed by offset from the end of the fill, so it is one\n * node in one position in the DOM whichever side it shows on, and it\n * never counts towards the width of the fill it is measured against.\n */\n .thermometer-value {\n position: absolute;\n top: 0;\n bottom: 0;\n left: var(--fill-end--, 0%);\n /*\n * Without this, the left offset caps the shrink-to-fit width of a\n * translated label and it collapses to its padding.\n */\n width: max-content;\n display: flex;\n align-items: center;\n font-weight: bold;\n white-space: nowrap;\n }\n\n /*\n * Both paddings total 1.5rem, so changing sides leaves the label the\n * same width and cannot feed back into the side it is placed on.\n */\n .value-left .thermometer-value {\n transform: translateX(-100%);\n color: var(--donation-thermometer-value-on-fill-color--);\n padding: 0 0.5rem 0 1rem;\n }\n\n .value-right .thermometer-value {\n color: var(--donation-thermometer-value-on-track-color--);\n padding: 0 1rem 0 0.5rem;\n }\n\n .donate-goal {\n text-align: left;\n padding: var(--donation-thermometer-goal-padding--);\n text-transform: uppercase;\n font-weight: bold;\n color: var(--donation-thermometer-goal-color--);\n }\n `,\n ];\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ia-donation-thermometer': IADonationThermometer;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ia-donation-thermometer.js","sourceRoot":"","sources":["../../../../src/elements/ia-donation-thermometer/ia-donation-thermometer.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,GAAG,EACH,IAAI,EACJ,UAAU,EACV,OAAO,GAGR,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,WAAW,MAAM,0BAA0B,CAAC;AAQnD;;;;;GAKG;AAGI,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,UAAU;IAA9C;;QACuB,oBAAe,GAAoB,QAAQ,CAAC;QAExE;;;WAGG;QACyB,oBAAe,GAAG,EAAE,CAAC;QAEjD;;;WAGG;QACyB,uBAAkB,GAAG,EAAE,CAAC;QAEpD;;;WAGG;QACyB,UAAK,GAAG,EAAE,CAAC;QAEX,eAAU,GAAG,SAAS,CAAC;QAEvB,sBAAiB,GAAsB,IAAI,CAAC;QAE5C,kBAAa,GAAG,CAAC,CAAC;QAM7B,0BAAqB,GAAG,CAAC,CAAC;QAE1B,yBAAoB,GAAG,CAAC,CAAC;QAQ1C;;;;;WAKG;QACK,wBAAmB,GAAmB,IAAI,CAAC;QAE3C,yBAAoB,GAAmB,IAAI,CAAC;IAmUtD,CAAC;IAjUC,MAAM;QACJ,OAAO,IAAI,CAAA;;;;4CAI6B,IAAI,CAAC,wBAAwB;mCACtC,IAAI,CAAC,eAAe;;0BAE7B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;AAM5C;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8DAAsB;AAMrB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iEAAyB;AAMxB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oDAAY;AAEX;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yDAAwB;AAEvB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gEAA6C;AAE5C;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4DAAmB;AAET;IAApC,KAAK,CAAC,oBAAoB,CAAC;+DAA2C;AAEnC;IAAnC,KAAK,CAAC,mBAAmB,CAAC;8DAA0C;AAEpD;IAAhB,KAAK,EAAE;oEAAmC;AAE1B;IAAhB,KAAK,EAAE;mEAAkC;AAjC/B,qBAAqB;IAFjC,aAAa,CAAC,yBAAyB,CAAC;IACxC,SAAS,EAAE;GACC,qBAAqB,CAoXjC","sourcesContent":["import {\n css,\n html,\n LitElement,\n nothing,\n type CSSResultGroup,\n type TemplateResult,\n} from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport { customElement } from '@src/utils/custom-element';\nimport { localized, msg, str } from '@lit/localize';\n\nimport themeStyles from '@src/themes/theme-styles';\n\n/** What the text beside the bar says: the goal amount, a message, or nothing. */\nexport type GoalMessageMode = 'off' | 'amount' | 'message';\n\n/** Whether the current amount is printed on the bar. */\nexport type CurrentAmountMode = 'on' | 'off';\n\n/**\n * A horizontal progress bar for a fundraising goal, as shown in the\n * archive.org donation banner. The fill grows with `currentAmount`, the amount\n * raised is printed on the fill when it fits and beside it when it doesn't,\n * and the goal (or a goal message) sits to the right of the bar.\n */\n@customElement('ia-donation-thermometer')\n@localized()\nexport class IADonationThermometer extends LitElement {\n @property({ type: String }) goalMessageMode: GoalMessageMode = 'amount';\n\n /**\n * The message shown when the goal is near. Empty shows the built-in message\n * in the current language.\n */\n @property({ type: String }) goalNearMessage = '';\n\n /**\n * The message shown when the goal is reached. Empty shows the built-in\n * message in the current language.\n */\n @property({ type: String }) goalReachedMessage = '';\n\n /**\n * The accessible name of the progress bar, for screen readers. Empty uses\n * the built-in name in the current language.\n */\n @property({ type: String }) label = '';\n\n @property({ type: Number }) goalAmount = 7_500_000;\n\n @property({ type: String }) currentAmountMode: CurrentAmountMode = 'on';\n\n @property({ type: Number }) currentAmount = 0;\n\n @query('.thermometer-value') private thermometerValue?: HTMLDivElement;\n\n @query('.thermometer-fill') private thermometerFill?: HTMLDivElement;\n\n @state() private thermometerValueWidth = 0;\n\n @state() private thermometerFillWidth = 0;\n\n /**\n * Watches the fill and the value label so the label can move to whichever\n * side of the fill has room for it.\n */\n private resizeObserver?: ResizeObserver;\n\n /**\n * The observed nodes are tracked so each is observed exactly once. Calling\n * `observe` on an already-observed target re-reports its size, which costs a\n * notification on every render. Lit also discards the value label when\n * `currentAmountMode` turns it off, so a replacement has to be picked up.\n */\n private observedFillElement: Element | null = null;\n\n private observedValueElement: Element | null = null;\n\n render(): TemplateResult {\n return html`\n <div class=\"thermometer-message-container\">\n <div class=\"thermometer-container\">\n <div\n class=\"thermometer-background ${this.thermometerValuePosition}\"\n style=\"--fill-end--: ${this.percentComplete}%\"\n role=\"progressbar\"\n aria-label=\"${this.label || msg('Donation progress')}\"\n aria-valuemin=\"0\"\n aria-valuemax=\"${this.progressMax}\"\n aria-valuenow=\"${this.progressValue}\"\n aria-valuetext=\"${this.currentAmountDisplayValue}\"\n >\n <div class=\"thermometer-clip\">\n <div class=\"thermometer-fill\"></div>\n </div>\n ${this.thermometerValueTemplate}\n </div>\n </div>\n ${this.goalMessageMode !== 'off'\n ? html`<div class=\"donate-goal\">${this.currentGoalMessage}</div>`\n : nothing}\n </div>\n `;\n }\n\n private get thermometerValueTemplate(): TemplateResult | typeof nothing {\n return this.currentAmountMode === 'off'\n ? nothing\n : html`\n <div class=\"thermometer-value\">${this.currentAmountDisplayValue}</div>\n `;\n }\n\n /**\n * Which side of the fill's end the value label sits on, as a class name for\n * the CSS that places it. The label sits over the fill when the fill is\n * wider than the label plus a little breathing room, and just past the\n * fill's right edge otherwise.\n */\n private get thermometerValuePosition(): 'value-left' | 'value-right' {\n const buffer = 10;\n return this.thermometerValueWidth + buffer < this.thermometerFillWidth\n ? 'value-left'\n : 'value-right';\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n this.resizeObserver = new ResizeObserver((entries) =>\n this.handleResize(entries),\n );\n // On a re-connect the fill already exists; on first connect it doesn't\n // until the first render, and `updated` picks it up then.\n this.observeParts();\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.resizeObserver?.disconnect();\n this.resizeObserver = undefined;\n this.observedFillElement = null;\n this.observedValueElement = null;\n }\n\n updated(): void {\n this.observeParts();\n }\n\n /** Observes the fill and the value label, picking up either if it is replaced. */\n private observeParts(): void {\n const observer = this.resizeObserver;\n if (!observer) return;\n\n this.observedFillElement = this.observeInPlaceOf(\n observer,\n this.observedFillElement,\n this.thermometerFill ?? null,\n );\n this.observedValueElement = this.observeInPlaceOf(\n observer,\n this.observedValueElement,\n this.thermometerValue ?? null,\n );\n }\n\n /**\n * Swaps `observed` for `current` on the observer and returns whichever is\n * now being watched. A target that hasn't changed is left alone.\n */\n private observeInPlaceOf(\n observer: ResizeObserver,\n observed: Element | null,\n current: Element | null,\n ): Element | null {\n if (current === observed) return observed;\n if (observed) observer.unobserve(observed);\n if (current) observer.observe(current);\n return current;\n }\n\n private handleResize(entries: ResizeObserverEntry[]): void {\n for (const entry of entries) {\n const width =\n entry.borderBoxSize?.[0]?.inlineSize ?? entry.contentRect.width;\n if (entry.target === this.observedFillElement) {\n this.thermometerFillWidth = width;\n } else if (entry.target === this.observedValueElement) {\n this.thermometerValueWidth = width;\n }\n }\n }\n\n private get goalMessage(): string {\n return this.currentAmount >= this.goalAmount\n ? this.goalReachedMessage || msg('We’ve reached our goal!')\n : this.goalNearMessage || msg('We’ve almost reached our goal!');\n }\n\n private get currentAmountDisplayValue(): string {\n return this.formatNumber(this.currentAmount);\n }\n\n private get goalAmountDisplayValue(): string {\n return this.formatNumber(this.goalAmount);\n }\n\n /**\n * Formats a dollar amount in millions, e.g. `$0.5MM` or `$35MM`. Amounts\n * under ten million keep one decimal place, larger ones round to a whole\n * number.\n */\n private formatNumber(number: number): string {\n if (!Number.isFinite(number) || number === 0) return '$0';\n const suffix = 'MM';\n const divisor = 1_000_000;\n const result = number / divisor;\n const roundToOne = result < 10;\n const rounded = roundToOne\n ? Math.round((result + Number.EPSILON) * 10) / 10\n : Math.round(result);\n return `$${rounded}${suffix}`;\n }\n\n private get currentGoalMessage(): string {\n switch (this.goalMessageMode) {\n case 'amount':\n return msg(str`${this.goalAmountDisplayValue} goal`);\n case 'message':\n return this.goalMessage;\n case 'off':\n return '';\n }\n }\n\n /**\n * The goal the bar measures against. A goal that isn't a positive, finite\n * number leaves the bar empty, since there is no range to report progress\n * against. Named clear of `ariaValueMax`, which `HTMLElement` declares as a\n * public string.\n */\n private get progressMax(): number {\n return Number.isFinite(this.goalAmount) && this.goalAmount > 0\n ? this.goalAmount\n : 0;\n }\n\n /**\n * The progress reported to screen readers, clamped into the\n * `aria-valuemin`/`aria-valuemax` range the spec requires.\n * `aria-valuetext` carries the amount as it is displayed.\n */\n private get progressValue(): number {\n if (!Number.isFinite(this.currentAmount)) return 0;\n return Math.min(Math.max(this.currentAmount, 0), this.progressMax);\n }\n\n /**\n * How much of the bar is filled, as a percentage, clamped to `0`-`100`. An\n * amount or goal that can't produce a usable percentage empties the bar.\n */\n private get percentComplete(): number {\n const goal = this.progressMax;\n if (goal === 0 || !Number.isFinite(this.currentAmount)) return 0;\n const percent = (this.currentAmount / goal) * 100;\n return Math.min(Math.max(percent, 0), 100);\n }\n\n static get styles(): CSSResultGroup {\n return [\n themeStyles,\n css`\n :host {\n --donation-thermometer-height--: var(\n --ia-donation-thermometer-height,\n 20px\n );\n --donation-thermometer-fill-color--: var(\n --ia-donation-thermometer-fill-color,\n #23765d\n );\n --donation-thermometer-track-color--: var(\n --ia-donation-thermometer-track-color,\n #b8f5e2\n );\n --donation-thermometer-border--: var(\n --ia-donation-thermometer-border,\n 1px solid var(--donation-thermometer-fill-color--)\n );\n /* Large enough to round any height into a pill */\n --donation-thermometer-border-radius--: var(\n --ia-donation-thermometer-border-radius,\n 9999px\n );\n --donation-thermometer-value-on-fill-color--: var(\n --ia-donation-thermometer-value-on-fill-color,\n var(--true-white)\n );\n --donation-thermometer-value-on-track-color--: var(\n --ia-donation-thermometer-value-on-track-color,\n var(--donation-thermometer-fill-color--)\n );\n --donation-thermometer-goal-color--: var(--primary-text-color);\n --donation-thermometer-goal-padding--: var(\n --ia-donation-thermometer-goal-padding,\n 0 10px\n );\n\n display: block;\n height: var(--donation-thermometer-height--);\n }\n\n .thermometer-message-container {\n height: 100%;\n display: flex;\n align-items: center;\n }\n\n .thermometer-container {\n height: 100%;\n flex: 1;\n }\n\n .thermometer-background {\n box-sizing: border-box;\n position: relative;\n background-color: var(--donation-thermometer-track-color--);\n height: 100%;\n border-radius: var(--donation-thermometer-border-radius--);\n border: var(--donation-thermometer-border--);\n }\n\n /*\n * Clips the square-ended fill to the rounded track. It covers only the\n * fill, so the label is never cut off by it.\n */\n .thermometer-clip {\n position: absolute;\n inset: 0;\n overflow: hidden;\n border-radius: var(--donation-thermometer-border-radius--);\n }\n\n .thermometer-fill {\n background-color: var(--donation-thermometer-fill-color--);\n height: 100%;\n /*\n * The fallback matters: without it a missing --fill-end-- makes the\n * declaration invalid, width resolves to auto, and the bar paints as\n * a fully funded fundraiser.\n */\n width: var(--fill-end--, 0%);\n }\n\n /*\n * The label is placed by offset from the end of the fill, so it is one\n * node in one position in the DOM whichever side it shows on, and it\n * never counts towards the width of the fill it is measured against.\n */\n .thermometer-value {\n position: absolute;\n top: 0;\n bottom: 0;\n left: var(--fill-end--, 0%);\n /*\n * Without this, the left offset caps the shrink-to-fit width of a\n * translated label and it collapses to its padding.\n */\n width: max-content;\n display: flex;\n align-items: center;\n font-weight: bold;\n white-space: nowrap;\n }\n\n /*\n * Both paddings total 1.5rem, so changing sides leaves the label the\n * same width and cannot feed back into the side it is placed on.\n */\n .value-left .thermometer-value {\n transform: translateX(-100%);\n color: var(--donation-thermometer-value-on-fill-color--);\n padding: 0 0.5rem 0 1rem;\n }\n\n .value-right .thermometer-value {\n color: var(--donation-thermometer-value-on-track-color--);\n padding: 0 1rem 0 0.5rem;\n }\n\n .donate-goal {\n text-align: left;\n padding: var(--donation-thermometer-goal-padding--);\n text-transform: uppercase;\n font-weight: bold;\n color: var(--donation-thermometer-goal-color--);\n }\n `,\n ];\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ia-donation-thermometer': IADonationThermometer;\n }\n}\n"]}
|