@internationalized/number 3.5.2-nightly.4555 → 3.5.2-nightly.4560

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.
@@ -0,0 +1,164 @@
1
+
2
+ function $parcel$export(e, n, v, s) {
3
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
+ }
5
+
6
+ $parcel$export(module.exports, "NumberFormatter", () => $0c1d5654b62fc485$export$cc77c4ff7e8673c5);
7
+ /*
8
+ * Copyright 2020 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */ let $0c1d5654b62fc485$var$formatterCache = new Map();
18
+ let $0c1d5654b62fc485$var$supportsSignDisplay = false;
19
+ try {
20
+ // @ts-ignore
21
+ $0c1d5654b62fc485$var$supportsSignDisplay = new Intl.NumberFormat("de-DE", {
22
+ signDisplay: "exceptZero"
23
+ }).resolvedOptions().signDisplay === "exceptZero";
24
+ // eslint-disable-next-line no-empty
25
+ } catch (e) {}
26
+ let $0c1d5654b62fc485$var$supportsUnit = false;
27
+ try {
28
+ // @ts-ignore
29
+ $0c1d5654b62fc485$var$supportsUnit = new Intl.NumberFormat("de-DE", {
30
+ style: "unit",
31
+ unit: "degree"
32
+ }).resolvedOptions().style === "unit";
33
+ // eslint-disable-next-line no-empty
34
+ } catch (e) {}
35
+ // Polyfill for units since Safari doesn't support them yet. See https://bugs.webkit.org/show_bug.cgi?id=215438.
36
+ // Currently only polyfilling the unit degree in narrow format for ColorSlider in our supported locales.
37
+ // Values were determined by switching to each locale manually in Chrome.
38
+ const $0c1d5654b62fc485$var$UNITS = {
39
+ degree: {
40
+ narrow: {
41
+ default: "\xb0",
42
+ "ja-JP": " \u5EA6",
43
+ "zh-TW": "\u5EA6",
44
+ "sl-SI": " \xb0"
45
+ }
46
+ }
47
+ };
48
+ class $0c1d5654b62fc485$export$cc77c4ff7e8673c5 {
49
+ /** Formats a number value as a string, according to the locale and options provided to the constructor. */ format(value) {
50
+ let res = "";
51
+ if (!$0c1d5654b62fc485$var$supportsSignDisplay && this.options.signDisplay != null) res = $0c1d5654b62fc485$export$711b50b3c525e0f2(this.numberFormatter, this.options.signDisplay, value);
52
+ else res = this.numberFormatter.format(value);
53
+ if (this.options.style === "unit" && !$0c1d5654b62fc485$var$supportsUnit) {
54
+ var _UNITS_unit;
55
+ let { unit: unit, unitDisplay: unitDisplay = "short", locale: locale } = this.resolvedOptions();
56
+ if (!unit) return res;
57
+ let values = (_UNITS_unit = $0c1d5654b62fc485$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay];
58
+ res += values[locale] || values.default;
59
+ }
60
+ return res;
61
+ }
62
+ /** Formats a number to an array of parts such as separators, digits, punctuation, and more. */ formatToParts(value) {
63
+ // TODO: implement signDisplay for formatToParts
64
+ // @ts-ignore
65
+ return this.numberFormatter.formatToParts(value);
66
+ }
67
+ /** Formats a number range as a string. */ formatRange(start, end) {
68
+ // @ts-ignore
69
+ if (typeof this.numberFormatter.formatRange === "function") // @ts-ignore
70
+ return this.numberFormatter.formatRange(start, end);
71
+ if (end < start) throw new RangeError("End date must be >= start date");
72
+ // Very basic fallback for old browsers.
73
+ return `${this.format(start)} \u{2013} ${this.format(end)}`;
74
+ }
75
+ /** Formats a number range as an array of parts. */ formatRangeToParts(start, end) {
76
+ // @ts-ignore
77
+ if (typeof this.numberFormatter.formatRangeToParts === "function") // @ts-ignore
78
+ return this.numberFormatter.formatRangeToParts(start, end);
79
+ if (end < start) throw new RangeError("End date must be >= start date");
80
+ let startParts = this.numberFormatter.formatToParts(start);
81
+ let endParts = this.numberFormatter.formatToParts(end);
82
+ return [
83
+ ...startParts.map((p)=>({
84
+ ...p,
85
+ source: "startRange"
86
+ })),
87
+ {
88
+ type: "literal",
89
+ value: " \u2013 ",
90
+ source: "shared"
91
+ },
92
+ ...endParts.map((p)=>({
93
+ ...p,
94
+ source: "endRange"
95
+ }))
96
+ ];
97
+ }
98
+ /** Returns the resolved formatting options based on the values passed to the constructor. */ resolvedOptions() {
99
+ let options = this.numberFormatter.resolvedOptions();
100
+ if (!$0c1d5654b62fc485$var$supportsSignDisplay && this.options.signDisplay != null) options = {
101
+ ...options,
102
+ signDisplay: this.options.signDisplay
103
+ };
104
+ if (!$0c1d5654b62fc485$var$supportsUnit && this.options.style === "unit") options = {
105
+ ...options,
106
+ style: "unit",
107
+ unit: this.options.unit,
108
+ unitDisplay: this.options.unitDisplay
109
+ };
110
+ return options;
111
+ }
112
+ constructor(locale, options = {}){
113
+ this.numberFormatter = $0c1d5654b62fc485$var$getCachedNumberFormatter(locale, options);
114
+ this.options = options;
115
+ }
116
+ }
117
+ function $0c1d5654b62fc485$var$getCachedNumberFormatter(locale, options = {}) {
118
+ let { numberingSystem: numberingSystem } = options;
119
+ if (numberingSystem && locale.includes("-nu-")) {
120
+ if (!locale.includes("-u-")) locale += "-u-";
121
+ locale += `-nu-${numberingSystem}`;
122
+ }
123
+ if (options.style === "unit" && !$0c1d5654b62fc485$var$supportsUnit) {
124
+ var _UNITS_unit;
125
+ let { unit: unit, unitDisplay: unitDisplay = "short" } = options;
126
+ if (!unit) throw new Error('unit option must be provided with style: "unit"');
127
+ if (!((_UNITS_unit = $0c1d5654b62fc485$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay])) throw new Error(`Unsupported unit ${unit} with unitDisplay = ${unitDisplay}`);
128
+ options = {
129
+ ...options,
130
+ style: "decimal"
131
+ };
132
+ }
133
+ let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : "");
134
+ if ($0c1d5654b62fc485$var$formatterCache.has(cacheKey)) return $0c1d5654b62fc485$var$formatterCache.get(cacheKey);
135
+ let numberFormatter = new Intl.NumberFormat(locale, options);
136
+ $0c1d5654b62fc485$var$formatterCache.set(cacheKey, numberFormatter);
137
+ return numberFormatter;
138
+ }
139
+ function $0c1d5654b62fc485$export$711b50b3c525e0f2(numberFormat, signDisplay, num) {
140
+ if (signDisplay === "auto") return numberFormat.format(num);
141
+ else if (signDisplay === "never") return numberFormat.format(Math.abs(num));
142
+ else {
143
+ let needsPositiveSign = false;
144
+ if (signDisplay === "always") needsPositiveSign = num > 0 || Object.is(num, 0);
145
+ else if (signDisplay === "exceptZero") {
146
+ if (Object.is(num, -0) || Object.is(num, 0)) num = Math.abs(num);
147
+ else needsPositiveSign = num > 0;
148
+ }
149
+ if (needsPositiveSign) {
150
+ let negative = numberFormat.format(-num);
151
+ let noSign = numberFormat.format(num);
152
+ // ignore RTL/LTR marker character
153
+ let minus = negative.replace(noSign, "").replace(/\u200e|\u061C/, "");
154
+ if ([
155
+ ...minus
156
+ ].length !== 1) console.warn("@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case");
157
+ let positive = negative.replace(noSign, "!!!").replace(minus, "+").replace("!!!", noSign);
158
+ return positive;
159
+ } else return numberFormat.format(num);
160
+ }
161
+ }
162
+
163
+
164
+ //# sourceMappingURL=NumberFormatter.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAED,IAAI,uCAAiB,IAAI;AAEzB,IAAI,4CAAsB;AAC1B,IAAI;IACF,aAAa;IACb,4CAAsB,AAAC,IAAI,KAAK,YAAY,CAAC,SAAS;QAAC,aAAa;IAAY,GAAI,eAAe,GAAG,WAAW,KAAK;AACtH,oCAAoC;AACtC,EAAE,OAAO,GAAG,CAAC;AAEb,IAAI,qCAAe;AACnB,IAAI;IACF,aAAa;IACb,qCAAe,AAAC,IAAI,KAAK,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C,KAAK;aACzC,IAAI,gBAAgB;YACzB,IAAI,OAAO,EAAE,CAAC,KAAK,OAAO,OAAO,EAAE,CAAC,KAAK,IACvC,MAAM,KAAK,GAAG,CAAC;iBAEf,oBAAoB,MAAM;;QAI9B,IAAI,mBAAmB;YACrB,IAAI,WAAW,aAAa,MAAM,CAAC,CAAC;YACpC,IAAI,SAAS,aAAa,MAAM,CAAC;YACjC,kCAAkC;YAClC,IAAI,QAAQ,SAAS,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,iBAAiB;YAClE,IAAI;mBAAI;aAAM,CAAC,MAAM,KAAK,GACxB,QAAQ,IAAI,CAAC;YAEf,IAAI,WAAW,SAAS,OAAO,CAAC,QAAQ,OAAO,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO;YAClF,OAAO;QACT,OACE,OAAO,aAAa,MAAM,CAAC;IAE/B;AACF","sources":["packages/@internationalized/number/src/NumberFormatter.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nlet formatterCache = new Map<string, Intl.NumberFormat>();\n\nlet supportsSignDisplay = false;\ntry {\n // @ts-ignore\n supportsSignDisplay = (new Intl.NumberFormat('de-DE', {signDisplay: 'exceptZero'})).resolvedOptions().signDisplay === 'exceptZero';\n // eslint-disable-next-line no-empty\n} catch (e) {}\n\nlet supportsUnit = false;\ntry {\n // @ts-ignore\n supportsUnit = (new Intl.NumberFormat('de-DE', {style: 'unit', unit: 'degree'})).resolvedOptions().style === 'unit';\n // eslint-disable-next-line no-empty\n} catch (e) {}\n\n// Polyfill for units since Safari doesn't support them yet. See https://bugs.webkit.org/show_bug.cgi?id=215438.\n// Currently only polyfilling the unit degree in narrow format for ColorSlider in our supported locales.\n// Values were determined by switching to each locale manually in Chrome.\nconst UNITS = {\n degree: {\n narrow: {\n default: '°',\n 'ja-JP': ' 度',\n 'zh-TW': '度',\n 'sl-SI': ' °'\n // Arabic?? But Safari already doesn't use Arabic digits so might be ok...\n // https://bugs.webkit.org/show_bug.cgi?id=218139\n }\n }\n};\n\nexport interface NumberFormatOptions extends Intl.NumberFormatOptions {\n /** Overrides default numbering system for the current locale. */\n numberingSystem?: string\n}\n\ninterface NumberRangeFormatPart extends Intl.NumberFormatPart {\n source: 'startRange' | 'endRange' | 'shared'\n}\n\n/**\n * A wrapper around Intl.NumberFormat providing additional options, polyfills, and caching for performance.\n */\nexport class NumberFormatter implements Intl.NumberFormat {\n private numberFormatter: Intl.NumberFormat;\n private options: NumberFormatOptions;\n\n constructor(locale: string, options: NumberFormatOptions = {}) {\n this.numberFormatter = getCachedNumberFormatter(locale, options);\n this.options = options;\n }\n\n /** Formats a number value as a string, according to the locale and options provided to the constructor. */\n format(value: number): string {\n let res = '';\n if (!supportsSignDisplay && this.options.signDisplay != null) {\n res = numberFormatSignDisplayPolyfill(this.numberFormatter, this.options.signDisplay, value);\n } else {\n res = this.numberFormatter.format(value);\n }\n\n if (this.options.style === 'unit' && !supportsUnit) {\n let {unit, unitDisplay = 'short', locale} = this.resolvedOptions();\n if (!unit) {\n return res;\n }\n let values = UNITS[unit]?.[unitDisplay];\n res += values[locale] || values.default;\n }\n\n return res;\n }\n\n /** Formats a number to an array of parts such as separators, digits, punctuation, and more. */\n formatToParts(value: number): Intl.NumberFormatPart[] {\n // TODO: implement signDisplay for formatToParts\n // @ts-ignore\n return this.numberFormatter.formatToParts(value);\n }\n\n /** Formats a number range as a string. */\n formatRange(start: number, end: number): string {\n // @ts-ignore\n if (typeof this.numberFormatter.formatRange === 'function') {\n // @ts-ignore\n return this.numberFormatter.formatRange(start, end);\n }\n\n if (end < start) {\n throw new RangeError('End date must be >= start date');\n }\n\n // Very basic fallback for old browsers.\n return `${this.format(start)} – ${this.format(end)}`;\n }\n\n /** Formats a number range as an array of parts. */\n formatRangeToParts(start: number, end: number): NumberRangeFormatPart[] {\n // @ts-ignore\n if (typeof this.numberFormatter.formatRangeToParts === 'function') {\n // @ts-ignore\n return this.numberFormatter.formatRangeToParts(start, end);\n }\n\n if (end < start) {\n throw new RangeError('End date must be >= start date');\n }\n\n let startParts = this.numberFormatter.formatToParts(start);\n let endParts = this.numberFormatter.formatToParts(end);\n return [\n ...startParts.map(p => ({...p, source: 'startRange'} as NumberRangeFormatPart)),\n {type: 'literal', value: ' – ', source: 'shared'},\n ...endParts.map(p => ({...p, source: 'endRange'} as NumberRangeFormatPart))\n ];\n }\n\n /** Returns the resolved formatting options based on the values passed to the constructor. */\n resolvedOptions(): Intl.ResolvedNumberFormatOptions {\n let options = this.numberFormatter.resolvedOptions();\n if (!supportsSignDisplay && this.options.signDisplay != null) {\n options = {...options, signDisplay: this.options.signDisplay};\n }\n\n if (!supportsUnit && this.options.style === 'unit') {\n options = {...options, style: 'unit', unit: this.options.unit, unitDisplay: this.options.unitDisplay};\n }\n\n return options;\n }\n}\n\nfunction getCachedNumberFormatter(locale: string, options: NumberFormatOptions = {}): Intl.NumberFormat {\n let {numberingSystem} = options;\n if (numberingSystem && locale.includes('-nu-')) {\n if (!locale.includes('-u-')) {\n locale += '-u-';\n }\n locale += `-nu-${numberingSystem}`;\n }\n\n if (options.style === 'unit' && !supportsUnit) {\n let {unit, unitDisplay = 'short'} = options;\n if (!unit) {\n throw new Error('unit option must be provided with style: \"unit\"');\n }\n if (!UNITS[unit]?.[unitDisplay]) {\n throw new Error(`Unsupported unit ${unit} with unitDisplay = ${unitDisplay}`);\n }\n options = {...options, style: 'decimal'};\n }\n\n let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');\n if (formatterCache.has(cacheKey)) {\n return formatterCache.get(cacheKey)!;\n }\n\n let numberFormatter = new Intl.NumberFormat(locale, options);\n formatterCache.set(cacheKey, numberFormatter);\n return numberFormatter;\n}\n\n/** @private - exported for tests */\nexport function numberFormatSignDisplayPolyfill(numberFormat: Intl.NumberFormat, signDisplay: string, num: number) {\n if (signDisplay === 'auto') {\n return numberFormat.format(num);\n } else if (signDisplay === 'never') {\n return numberFormat.format(Math.abs(num));\n } else {\n let needsPositiveSign = false;\n if (signDisplay === 'always') {\n needsPositiveSign = num > 0 || Object.is(num, 0);\n } else if (signDisplay === 'exceptZero') {\n if (Object.is(num, -0) || Object.is(num, 0)) {\n num = Math.abs(num);\n } else {\n needsPositiveSign = num > 0;\n }\n }\n\n if (needsPositiveSign) {\n let negative = numberFormat.format(-num);\n let noSign = numberFormat.format(num);\n // ignore RTL/LTR marker character\n let minus = negative.replace(noSign, '').replace(/\\u200e|\\u061C/, '');\n if ([...minus].length !== 1) {\n console.warn('@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case');\n }\n let positive = negative.replace(noSign, '!!!').replace(minus, '+').replace('!!!', noSign);\n return positive;\n } else {\n return numberFormat.format(num);\n }\n }\n}\n"],"names":[],"version":3,"file":"NumberFormatter.main.js.map"}
@@ -0,0 +1,159 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ let $488c6ddbf4ef74c2$var$formatterCache = new Map();
12
+ let $488c6ddbf4ef74c2$var$supportsSignDisplay = false;
13
+ try {
14
+ // @ts-ignore
15
+ $488c6ddbf4ef74c2$var$supportsSignDisplay = new Intl.NumberFormat("de-DE", {
16
+ signDisplay: "exceptZero"
17
+ }).resolvedOptions().signDisplay === "exceptZero";
18
+ // eslint-disable-next-line no-empty
19
+ } catch (e) {}
20
+ let $488c6ddbf4ef74c2$var$supportsUnit = false;
21
+ try {
22
+ // @ts-ignore
23
+ $488c6ddbf4ef74c2$var$supportsUnit = new Intl.NumberFormat("de-DE", {
24
+ style: "unit",
25
+ unit: "degree"
26
+ }).resolvedOptions().style === "unit";
27
+ // eslint-disable-next-line no-empty
28
+ } catch (e) {}
29
+ // Polyfill for units since Safari doesn't support them yet. See https://bugs.webkit.org/show_bug.cgi?id=215438.
30
+ // Currently only polyfilling the unit degree in narrow format for ColorSlider in our supported locales.
31
+ // Values were determined by switching to each locale manually in Chrome.
32
+ const $488c6ddbf4ef74c2$var$UNITS = {
33
+ degree: {
34
+ narrow: {
35
+ default: "\xb0",
36
+ "ja-JP": " \u5EA6",
37
+ "zh-TW": "\u5EA6",
38
+ "sl-SI": " \xb0"
39
+ }
40
+ }
41
+ };
42
+ class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
43
+ /** Formats a number value as a string, according to the locale and options provided to the constructor. */ format(value) {
44
+ let res = "";
45
+ if (!$488c6ddbf4ef74c2$var$supportsSignDisplay && this.options.signDisplay != null) res = $488c6ddbf4ef74c2$export$711b50b3c525e0f2(this.numberFormatter, this.options.signDisplay, value);
46
+ else res = this.numberFormatter.format(value);
47
+ if (this.options.style === "unit" && !$488c6ddbf4ef74c2$var$supportsUnit) {
48
+ var _UNITS_unit;
49
+ let { unit: unit, unitDisplay: unitDisplay = "short", locale: locale } = this.resolvedOptions();
50
+ if (!unit) return res;
51
+ let values = (_UNITS_unit = $488c6ddbf4ef74c2$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay];
52
+ res += values[locale] || values.default;
53
+ }
54
+ return res;
55
+ }
56
+ /** Formats a number to an array of parts such as separators, digits, punctuation, and more. */ formatToParts(value) {
57
+ // TODO: implement signDisplay for formatToParts
58
+ // @ts-ignore
59
+ return this.numberFormatter.formatToParts(value);
60
+ }
61
+ /** Formats a number range as a string. */ formatRange(start, end) {
62
+ // @ts-ignore
63
+ if (typeof this.numberFormatter.formatRange === "function") // @ts-ignore
64
+ return this.numberFormatter.formatRange(start, end);
65
+ if (end < start) throw new RangeError("End date must be >= start date");
66
+ // Very basic fallback for old browsers.
67
+ return `${this.format(start)} \u{2013} ${this.format(end)}`;
68
+ }
69
+ /** Formats a number range as an array of parts. */ formatRangeToParts(start, end) {
70
+ // @ts-ignore
71
+ if (typeof this.numberFormatter.formatRangeToParts === "function") // @ts-ignore
72
+ return this.numberFormatter.formatRangeToParts(start, end);
73
+ if (end < start) throw new RangeError("End date must be >= start date");
74
+ let startParts = this.numberFormatter.formatToParts(start);
75
+ let endParts = this.numberFormatter.formatToParts(end);
76
+ return [
77
+ ...startParts.map((p)=>({
78
+ ...p,
79
+ source: "startRange"
80
+ })),
81
+ {
82
+ type: "literal",
83
+ value: " \u2013 ",
84
+ source: "shared"
85
+ },
86
+ ...endParts.map((p)=>({
87
+ ...p,
88
+ source: "endRange"
89
+ }))
90
+ ];
91
+ }
92
+ /** Returns the resolved formatting options based on the values passed to the constructor. */ resolvedOptions() {
93
+ let options = this.numberFormatter.resolvedOptions();
94
+ if (!$488c6ddbf4ef74c2$var$supportsSignDisplay && this.options.signDisplay != null) options = {
95
+ ...options,
96
+ signDisplay: this.options.signDisplay
97
+ };
98
+ if (!$488c6ddbf4ef74c2$var$supportsUnit && this.options.style === "unit") options = {
99
+ ...options,
100
+ style: "unit",
101
+ unit: this.options.unit,
102
+ unitDisplay: this.options.unitDisplay
103
+ };
104
+ return options;
105
+ }
106
+ constructor(locale, options = {}){
107
+ this.numberFormatter = $488c6ddbf4ef74c2$var$getCachedNumberFormatter(locale, options);
108
+ this.options = options;
109
+ }
110
+ }
111
+ function $488c6ddbf4ef74c2$var$getCachedNumberFormatter(locale, options = {}) {
112
+ let { numberingSystem: numberingSystem } = options;
113
+ if (numberingSystem && locale.includes("-nu-")) {
114
+ if (!locale.includes("-u-")) locale += "-u-";
115
+ locale += `-nu-${numberingSystem}`;
116
+ }
117
+ if (options.style === "unit" && !$488c6ddbf4ef74c2$var$supportsUnit) {
118
+ var _UNITS_unit;
119
+ let { unit: unit, unitDisplay: unitDisplay = "short" } = options;
120
+ if (!unit) throw new Error('unit option must be provided with style: "unit"');
121
+ if (!((_UNITS_unit = $488c6ddbf4ef74c2$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay])) throw new Error(`Unsupported unit ${unit} with unitDisplay = ${unitDisplay}`);
122
+ options = {
123
+ ...options,
124
+ style: "decimal"
125
+ };
126
+ }
127
+ let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : "");
128
+ if ($488c6ddbf4ef74c2$var$formatterCache.has(cacheKey)) return $488c6ddbf4ef74c2$var$formatterCache.get(cacheKey);
129
+ let numberFormatter = new Intl.NumberFormat(locale, options);
130
+ $488c6ddbf4ef74c2$var$formatterCache.set(cacheKey, numberFormatter);
131
+ return numberFormatter;
132
+ }
133
+ function $488c6ddbf4ef74c2$export$711b50b3c525e0f2(numberFormat, signDisplay, num) {
134
+ if (signDisplay === "auto") return numberFormat.format(num);
135
+ else if (signDisplay === "never") return numberFormat.format(Math.abs(num));
136
+ else {
137
+ let needsPositiveSign = false;
138
+ if (signDisplay === "always") needsPositiveSign = num > 0 || Object.is(num, 0);
139
+ else if (signDisplay === "exceptZero") {
140
+ if (Object.is(num, -0) || Object.is(num, 0)) num = Math.abs(num);
141
+ else needsPositiveSign = num > 0;
142
+ }
143
+ if (needsPositiveSign) {
144
+ let negative = numberFormat.format(-num);
145
+ let noSign = numberFormat.format(num);
146
+ // ignore RTL/LTR marker character
147
+ let minus = negative.replace(noSign, "").replace(/\u200e|\u061C/, "");
148
+ if ([
149
+ ...minus
150
+ ].length !== 1) console.warn("@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case");
151
+ let positive = negative.replace(noSign, "!!!").replace(minus, "+").replace("!!!", noSign);
152
+ return positive;
153
+ } else return numberFormat.format(num);
154
+ }
155
+ }
156
+
157
+
158
+ export {$488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 as NumberFormatter, $488c6ddbf4ef74c2$export$711b50b3c525e0f2 as numberFormatSignDisplayPolyfill};
159
+ //# sourceMappingURL=NumberFormatter.mjs.map
@@ -0,0 +1,159 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */ let $488c6ddbf4ef74c2$var$formatterCache = new Map();
12
+ let $488c6ddbf4ef74c2$var$supportsSignDisplay = false;
13
+ try {
14
+ // @ts-ignore
15
+ $488c6ddbf4ef74c2$var$supportsSignDisplay = new Intl.NumberFormat("de-DE", {
16
+ signDisplay: "exceptZero"
17
+ }).resolvedOptions().signDisplay === "exceptZero";
18
+ // eslint-disable-next-line no-empty
19
+ } catch (e) {}
20
+ let $488c6ddbf4ef74c2$var$supportsUnit = false;
21
+ try {
22
+ // @ts-ignore
23
+ $488c6ddbf4ef74c2$var$supportsUnit = new Intl.NumberFormat("de-DE", {
24
+ style: "unit",
25
+ unit: "degree"
26
+ }).resolvedOptions().style === "unit";
27
+ // eslint-disable-next-line no-empty
28
+ } catch (e) {}
29
+ // Polyfill for units since Safari doesn't support them yet. See https://bugs.webkit.org/show_bug.cgi?id=215438.
30
+ // Currently only polyfilling the unit degree in narrow format for ColorSlider in our supported locales.
31
+ // Values were determined by switching to each locale manually in Chrome.
32
+ const $488c6ddbf4ef74c2$var$UNITS = {
33
+ degree: {
34
+ narrow: {
35
+ default: "\xb0",
36
+ "ja-JP": " \u5EA6",
37
+ "zh-TW": "\u5EA6",
38
+ "sl-SI": " \xb0"
39
+ }
40
+ }
41
+ };
42
+ class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
43
+ /** Formats a number value as a string, according to the locale and options provided to the constructor. */ format(value) {
44
+ let res = "";
45
+ if (!$488c6ddbf4ef74c2$var$supportsSignDisplay && this.options.signDisplay != null) res = $488c6ddbf4ef74c2$export$711b50b3c525e0f2(this.numberFormatter, this.options.signDisplay, value);
46
+ else res = this.numberFormatter.format(value);
47
+ if (this.options.style === "unit" && !$488c6ddbf4ef74c2$var$supportsUnit) {
48
+ var _UNITS_unit;
49
+ let { unit: unit, unitDisplay: unitDisplay = "short", locale: locale } = this.resolvedOptions();
50
+ if (!unit) return res;
51
+ let values = (_UNITS_unit = $488c6ddbf4ef74c2$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay];
52
+ res += values[locale] || values.default;
53
+ }
54
+ return res;
55
+ }
56
+ /** Formats a number to an array of parts such as separators, digits, punctuation, and more. */ formatToParts(value) {
57
+ // TODO: implement signDisplay for formatToParts
58
+ // @ts-ignore
59
+ return this.numberFormatter.formatToParts(value);
60
+ }
61
+ /** Formats a number range as a string. */ formatRange(start, end) {
62
+ // @ts-ignore
63
+ if (typeof this.numberFormatter.formatRange === "function") // @ts-ignore
64
+ return this.numberFormatter.formatRange(start, end);
65
+ if (end < start) throw new RangeError("End date must be >= start date");
66
+ // Very basic fallback for old browsers.
67
+ return `${this.format(start)} \u{2013} ${this.format(end)}`;
68
+ }
69
+ /** Formats a number range as an array of parts. */ formatRangeToParts(start, end) {
70
+ // @ts-ignore
71
+ if (typeof this.numberFormatter.formatRangeToParts === "function") // @ts-ignore
72
+ return this.numberFormatter.formatRangeToParts(start, end);
73
+ if (end < start) throw new RangeError("End date must be >= start date");
74
+ let startParts = this.numberFormatter.formatToParts(start);
75
+ let endParts = this.numberFormatter.formatToParts(end);
76
+ return [
77
+ ...startParts.map((p)=>({
78
+ ...p,
79
+ source: "startRange"
80
+ })),
81
+ {
82
+ type: "literal",
83
+ value: " \u2013 ",
84
+ source: "shared"
85
+ },
86
+ ...endParts.map((p)=>({
87
+ ...p,
88
+ source: "endRange"
89
+ }))
90
+ ];
91
+ }
92
+ /** Returns the resolved formatting options based on the values passed to the constructor. */ resolvedOptions() {
93
+ let options = this.numberFormatter.resolvedOptions();
94
+ if (!$488c6ddbf4ef74c2$var$supportsSignDisplay && this.options.signDisplay != null) options = {
95
+ ...options,
96
+ signDisplay: this.options.signDisplay
97
+ };
98
+ if (!$488c6ddbf4ef74c2$var$supportsUnit && this.options.style === "unit") options = {
99
+ ...options,
100
+ style: "unit",
101
+ unit: this.options.unit,
102
+ unitDisplay: this.options.unitDisplay
103
+ };
104
+ return options;
105
+ }
106
+ constructor(locale, options = {}){
107
+ this.numberFormatter = $488c6ddbf4ef74c2$var$getCachedNumberFormatter(locale, options);
108
+ this.options = options;
109
+ }
110
+ }
111
+ function $488c6ddbf4ef74c2$var$getCachedNumberFormatter(locale, options = {}) {
112
+ let { numberingSystem: numberingSystem } = options;
113
+ if (numberingSystem && locale.includes("-nu-")) {
114
+ if (!locale.includes("-u-")) locale += "-u-";
115
+ locale += `-nu-${numberingSystem}`;
116
+ }
117
+ if (options.style === "unit" && !$488c6ddbf4ef74c2$var$supportsUnit) {
118
+ var _UNITS_unit;
119
+ let { unit: unit, unitDisplay: unitDisplay = "short" } = options;
120
+ if (!unit) throw new Error('unit option must be provided with style: "unit"');
121
+ if (!((_UNITS_unit = $488c6ddbf4ef74c2$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay])) throw new Error(`Unsupported unit ${unit} with unitDisplay = ${unitDisplay}`);
122
+ options = {
123
+ ...options,
124
+ style: "decimal"
125
+ };
126
+ }
127
+ let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : "");
128
+ if ($488c6ddbf4ef74c2$var$formatterCache.has(cacheKey)) return $488c6ddbf4ef74c2$var$formatterCache.get(cacheKey);
129
+ let numberFormatter = new Intl.NumberFormat(locale, options);
130
+ $488c6ddbf4ef74c2$var$formatterCache.set(cacheKey, numberFormatter);
131
+ return numberFormatter;
132
+ }
133
+ function $488c6ddbf4ef74c2$export$711b50b3c525e0f2(numberFormat, signDisplay, num) {
134
+ if (signDisplay === "auto") return numberFormat.format(num);
135
+ else if (signDisplay === "never") return numberFormat.format(Math.abs(num));
136
+ else {
137
+ let needsPositiveSign = false;
138
+ if (signDisplay === "always") needsPositiveSign = num > 0 || Object.is(num, 0);
139
+ else if (signDisplay === "exceptZero") {
140
+ if (Object.is(num, -0) || Object.is(num, 0)) num = Math.abs(num);
141
+ else needsPositiveSign = num > 0;
142
+ }
143
+ if (needsPositiveSign) {
144
+ let negative = numberFormat.format(-num);
145
+ let noSign = numberFormat.format(num);
146
+ // ignore RTL/LTR marker character
147
+ let minus = negative.replace(noSign, "").replace(/\u200e|\u061C/, "");
148
+ if ([
149
+ ...minus
150
+ ].length !== 1) console.warn("@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case");
151
+ let positive = negative.replace(noSign, "!!!").replace(minus, "+").replace("!!!", noSign);
152
+ return positive;
153
+ } else return numberFormat.format(num);
154
+ }
155
+ }
156
+
157
+
158
+ export {$488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 as NumberFormatter, $488c6ddbf4ef74c2$export$711b50b3c525e0f2 as numberFormatSignDisplayPolyfill};
159
+ //# sourceMappingURL=NumberFormatter.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAED,IAAI,uCAAiB,IAAI;AAEzB,IAAI,4CAAsB;AAC1B,IAAI;IACF,aAAa;IACb,4CAAsB,AAAC,IAAI,KAAK,YAAY,CAAC,SAAS;Q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CAAC;SACtB,IAAI,gBAAgB,SACzB,OAAO,aAAa,MAAM,CAAC,KAAK,GAAG,CAAC;SAC/B;QACL,IAAI,oBAAoB;QACxB,IAAI,gBAAgB,UAClB,oBAAoB,MAAM,KAAK,OAAO,EAAE,CAAC,KAAK;aACzC,IAAI,gBAAgB;YACzB,IAAI,OAAO,EAAE,CAAC,KAAK,OAAO,OAAO,EAAE,CAAC,KAAK,IACvC,MAAM,KAAK,GAAG,CAAC;iBAEf,oBAAoB,MAAM;;QAI9B,IAAI,mBAAmB;YACrB,IAAI,WAAW,aAAa,MAAM,CAAC,CAAC;YACpC,IAAI,SAAS,aAAa,MAAM,CAAC;YACjC,kCAAkC;YAClC,IAAI,QAAQ,SAAS,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,iBAAiB;YAClE,IAAI;mBAAI;aAAM,CAAC,MAAM,KAAK,GACxB,QAAQ,IAAI,CAAC;YAEf,IAAI,WAAW,SAAS,OAAO,CAAC,QAAQ,OAAO,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO;YAClF,OAAO;QACT,OACE,OAAO,aAAa,MAAM,CAAC;IAE/B;AACF","sources":["packages/@internationalized/number/src/NumberFormatter.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nlet formatterCache = new Map<string, Intl.NumberFormat>();\n\nlet supportsSignDisplay = false;\ntry {\n // @ts-ignore\n supportsSignDisplay = (new Intl.NumberFormat('de-DE', {signDisplay: 'exceptZero'})).resolvedOptions().signDisplay === 'exceptZero';\n // eslint-disable-next-line no-empty\n} catch (e) {}\n\nlet supportsUnit = false;\ntry {\n // @ts-ignore\n supportsUnit = (new Intl.NumberFormat('de-DE', {style: 'unit', unit: 'degree'})).resolvedOptions().style === 'unit';\n // eslint-disable-next-line no-empty\n} catch (e) {}\n\n// Polyfill for units since Safari doesn't support them yet. See https://bugs.webkit.org/show_bug.cgi?id=215438.\n// Currently only polyfilling the unit degree in narrow format for ColorSlider in our supported locales.\n// Values were determined by switching to each locale manually in Chrome.\nconst UNITS = {\n degree: {\n narrow: {\n default: '°',\n 'ja-JP': ' 度',\n 'zh-TW': '度',\n 'sl-SI': ' °'\n // Arabic?? But Safari already doesn't use Arabic digits so might be ok...\n // https://bugs.webkit.org/show_bug.cgi?id=218139\n }\n }\n};\n\nexport interface NumberFormatOptions extends Intl.NumberFormatOptions {\n /** Overrides default numbering system for the current locale. */\n numberingSystem?: string\n}\n\ninterface NumberRangeFormatPart extends Intl.NumberFormatPart {\n source: 'startRange' | 'endRange' | 'shared'\n}\n\n/**\n * A wrapper around Intl.NumberFormat providing additional options, polyfills, and caching for performance.\n */\nexport class NumberFormatter implements Intl.NumberFormat {\n private numberFormatter: Intl.NumberFormat;\n private options: NumberFormatOptions;\n\n constructor(locale: string, options: NumberFormatOptions = {}) {\n this.numberFormatter = getCachedNumberFormatter(locale, options);\n this.options = options;\n }\n\n /** Formats a number value as a string, according to the locale and options provided to the constructor. */\n format(value: number): string {\n let res = '';\n if (!supportsSignDisplay && this.options.signDisplay != null) {\n res = numberFormatSignDisplayPolyfill(this.numberFormatter, this.options.signDisplay, value);\n } else {\n res = this.numberFormatter.format(value);\n }\n\n if (this.options.style === 'unit' && !supportsUnit) {\n let {unit, unitDisplay = 'short', locale} = this.resolvedOptions();\n if (!unit) {\n return res;\n }\n let values = UNITS[unit]?.[unitDisplay];\n res += values[locale] || values.default;\n }\n\n return res;\n }\n\n /** Formats a number to an array of parts such as separators, digits, punctuation, and more. */\n formatToParts(value: number): Intl.NumberFormatPart[] {\n // TODO: implement signDisplay for formatToParts\n // @ts-ignore\n return this.numberFormatter.formatToParts(value);\n }\n\n /** Formats a number range as a string. */\n formatRange(start: number, end: number): string {\n // @ts-ignore\n if (typeof this.numberFormatter.formatRange === 'function') {\n // @ts-ignore\n return this.numberFormatter.formatRange(start, end);\n }\n\n if (end < start) {\n throw new RangeError('End date must be >= start date');\n }\n\n // Very basic fallback for old browsers.\n return `${this.format(start)} – ${this.format(end)}`;\n }\n\n /** Formats a number range as an array of parts. */\n formatRangeToParts(start: number, end: number): NumberRangeFormatPart[] {\n // @ts-ignore\n if (typeof this.numberFormatter.formatRangeToParts === 'function') {\n // @ts-ignore\n return this.numberFormatter.formatRangeToParts(start, end);\n }\n\n if (end < start) {\n throw new RangeError('End date must be >= start date');\n }\n\n let startParts = this.numberFormatter.formatToParts(start);\n let endParts = this.numberFormatter.formatToParts(end);\n return [\n ...startParts.map(p => ({...p, source: 'startRange'} as NumberRangeFormatPart)),\n {type: 'literal', value: ' – ', source: 'shared'},\n ...endParts.map(p => ({...p, source: 'endRange'} as NumberRangeFormatPart))\n ];\n }\n\n /** Returns the resolved formatting options based on the values passed to the constructor. */\n resolvedOptions(): Intl.ResolvedNumberFormatOptions {\n let options = this.numberFormatter.resolvedOptions();\n if (!supportsSignDisplay && this.options.signDisplay != null) {\n options = {...options, signDisplay: this.options.signDisplay};\n }\n\n if (!supportsUnit && this.options.style === 'unit') {\n options = {...options, style: 'unit', unit: this.options.unit, unitDisplay: this.options.unitDisplay};\n }\n\n return options;\n }\n}\n\nfunction getCachedNumberFormatter(locale: string, options: NumberFormatOptions = {}): Intl.NumberFormat {\n let {numberingSystem} = options;\n if (numberingSystem && locale.includes('-nu-')) {\n if (!locale.includes('-u-')) {\n locale += '-u-';\n }\n locale += `-nu-${numberingSystem}`;\n }\n\n if (options.style === 'unit' && !supportsUnit) {\n let {unit, unitDisplay = 'short'} = options;\n if (!unit) {\n throw new Error('unit option must be provided with style: \"unit\"');\n }\n if (!UNITS[unit]?.[unitDisplay]) {\n throw new Error(`Unsupported unit ${unit} with unitDisplay = ${unitDisplay}`);\n }\n options = {...options, style: 'decimal'};\n }\n\n let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');\n if (formatterCache.has(cacheKey)) {\n return formatterCache.get(cacheKey)!;\n }\n\n let numberFormatter = new Intl.NumberFormat(locale, options);\n formatterCache.set(cacheKey, numberFormatter);\n return numberFormatter;\n}\n\n/** @private - exported for tests */\nexport function numberFormatSignDisplayPolyfill(numberFormat: Intl.NumberFormat, signDisplay: string, num: number) {\n if (signDisplay === 'auto') {\n return numberFormat.format(num);\n } else if (signDisplay === 'never') {\n return numberFormat.format(Math.abs(num));\n } else {\n let needsPositiveSign = false;\n if (signDisplay === 'always') {\n needsPositiveSign = num > 0 || Object.is(num, 0);\n } else if (signDisplay === 'exceptZero') {\n if (Object.is(num, -0) || Object.is(num, 0)) {\n num = Math.abs(num);\n } else {\n needsPositiveSign = num > 0;\n }\n }\n\n if (needsPositiveSign) {\n let negative = numberFormat.format(-num);\n let noSign = numberFormat.format(num);\n // ignore RTL/LTR marker character\n let minus = negative.replace(noSign, '').replace(/\\u200e|\\u061C/, '');\n if ([...minus].length !== 1) {\n console.warn('@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case');\n }\n let positive = negative.replace(noSign, '!!!').replace(minus, '+').replace('!!!', noSign);\n return positive;\n } else {\n return numberFormat.format(num);\n }\n }\n}\n"],"names":[],"version":3,"file":"NumberFormatter.module.js.map"}