@internationalized/number 3.6.4 → 3.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{main.js → index.cjs} +5 -5
- package/dist/{main.js.map → index.cjs.map} +1 -1
- package/dist/{import.mjs → index.js} +4 -4
- package/dist/{module.js.map → index.js.map} +1 -1
- package/dist/{module.js → index.mjs} +4 -4
- package/dist/index.mjs.map +1 -0
- package/dist/{NumberFormatter.main.js → private/NumberFormatter.cjs} +24 -26
- package/dist/private/NumberFormatter.cjs.map +1 -0
- package/dist/{NumberFormatter.mjs → private/NumberFormatter.js} +21 -21
- package/dist/{NumberFormatter.module.js.map → private/NumberFormatter.js.map} +1 -1
- package/dist/{NumberFormatter.module.js → private/NumberFormatter.mjs} +24 -26
- package/dist/private/NumberFormatter.mjs.map +1 -0
- package/dist/{NumberParser.main.js → private/NumberParser.cjs} +92 -76
- package/dist/private/NumberParser.cjs.map +1 -0
- package/dist/{NumberParser.mjs → private/NumberParser.js} +65 -45
- package/dist/private/NumberParser.js.map +1 -0
- package/dist/{NumberParser.module.js → private/NumberParser.mjs} +92 -76
- package/dist/private/NumberParser.mjs.map +1 -0
- package/dist/types/src/NumberFormatter.d.ts +28 -0
- package/dist/types/src/NumberParser.d.ts +27 -0
- package/dist/types/src/index.d.ts +3 -0
- package/package.json +26 -11
- package/src/NumberParser.ts +43 -20
- package/dist/NumberFormatter.main.js.map +0 -1
- package/dist/NumberParser.main.js.map +0 -1
- package/dist/NumberParser.module.js.map +0 -1
- package/dist/types.d.ts +0 -50
- package/dist/types.d.ts.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
1
|
+
var $7fe67f77592add0a$exports = require("./private/NumberFormatter.cjs");
|
|
2
|
+
var $52ebab2a875d5a2c$exports = require("./private/NumberParser.cjs");
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
function $parcel$export(e, n, v, s) {
|
|
6
6
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
$parcel$export(module.exports, "NumberFormatter", ()
|
|
10
|
-
$parcel$export(module.exports, "NumberParser", ()
|
|
9
|
+
$parcel$export(module.exports, "NumberFormatter", function () { return $7fe67f77592add0a$exports.NumberFormatter; });
|
|
10
|
+
$parcel$export(module.exports, "NumberParser", function () { return $52ebab2a875d5a2c$exports.NumberParser; });
|
|
11
11
|
/*
|
|
12
12
|
* Copyright 2020 Adobe. All rights reserved.
|
|
13
13
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -22,4 +22,4 @@ $parcel$export(module.exports, "NumberParser", () => $d68f3f4c684426c6$exports.N
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
//# sourceMappingURL=
|
|
25
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@internationalized/number/src/index.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\nexport type {NumberFormatOptions} from './NumberFormatter';\n\nexport {NumberFormatter} from './NumberFormatter';\nexport {NumberParser} from './NumberParser';\n"],"names":[],"version":3,"file":"
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@internationalized/number/src/index.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\nexport type {NumberFormatOptions} from './NumberFormatter';\n\nexport {NumberFormatter} from './NumberFormatter';\nexport {NumberParser} from './NumberParser';\n"],"names":[],"version":3,"file":"index.cjs.map"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {NumberFormatter as $
|
|
2
|
-
import {NumberParser as $
|
|
1
|
+
import {NumberFormatter as $6c0bb0183c96ba81$export$cc77c4ff7e8673c5} from "./private/NumberFormatter.js";
|
|
2
|
+
import {NumberParser as $8f9e7ac92b21e8dd$export$cd11ab140839f11d} from "./private/NumberParser.js";
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -15,5 +15,5 @@ import {NumberParser as $6c7bd7858deea686$export$cd11ab140839f11d} from "./Numbe
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
export {$
|
|
19
|
-
//# sourceMappingURL=
|
|
18
|
+
export {$6c0bb0183c96ba81$export$cc77c4ff7e8673c5 as NumberFormatter, $8f9e7ac92b21e8dd$export$cd11ab140839f11d as NumberParser};
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@internationalized/number/src/index.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\nexport type {NumberFormatOptions} from './NumberFormatter';\n\nexport {NumberFormatter} from './NumberFormatter';\nexport {NumberParser} from './NumberParser';\n"],"names":[],"version":3,"file":"
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@internationalized/number/src/index.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\nexport type {NumberFormatOptions} from './NumberFormatter';\n\nexport {NumberFormatter} from './NumberFormatter';\nexport {NumberParser} from './NumberParser';\n"],"names":[],"version":3,"file":"index.js.map"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {NumberFormatter as $
|
|
2
|
-
import {NumberParser as $
|
|
1
|
+
import {NumberFormatter as $1dfb119a85e764e5$export$cc77c4ff7e8673c5} from "./private/NumberFormatter.mjs";
|
|
2
|
+
import {NumberParser as $eb76cf4feb040f77$export$cd11ab140839f11d} from "./private/NumberParser.mjs";
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -15,5 +15,5 @@ import {NumberParser as $6c7bd7858deea686$export$cd11ab140839f11d} from "./Numbe
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
export {$
|
|
19
|
-
//# sourceMappingURL=
|
|
18
|
+
export {$1dfb119a85e764e5$export$cc77c4ff7e8673c5 as NumberFormatter, $eb76cf4feb040f77$export$cd11ab140839f11d as NumberParser};
|
|
19
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@internationalized/number/src/index.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\nexport type {NumberFormatOptions} from './NumberFormatter';\n\nexport {NumberFormatter} from './NumberFormatter';\nexport {NumberParser} from './NumberParser';\n"],"names":[],"version":3,"file":"index.mjs.map"}
|
|
@@ -3,7 +3,7 @@ function $parcel$export(e, n, v, s) {
|
|
|
3
3
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
$parcel$export(module.exports, "NumberFormatter", ()
|
|
6
|
+
$parcel$export(module.exports, "NumberFormatter", function () { return $7fe67f77592add0a$export$cc77c4ff7e8673c5; });
|
|
7
7
|
/*
|
|
8
8
|
* Copyright 2020 Adobe. All rights reserved.
|
|
9
9
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -14,17 +14,17 @@ $parcel$export(module.exports, "NumberFormatter", () => $0c1d5654b62fc485$export
|
|
|
14
14
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
15
15
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
16
16
|
* governing permissions and limitations under the License.
|
|
17
|
-
*/ let $
|
|
18
|
-
let $
|
|
17
|
+
*/ let $7fe67f77592add0a$var$formatterCache = new Map();
|
|
18
|
+
let $7fe67f77592add0a$var$supportsSignDisplay = false;
|
|
19
19
|
try {
|
|
20
|
-
$
|
|
20
|
+
$7fe67f77592add0a$var$supportsSignDisplay = new Intl.NumberFormat('de-DE', {
|
|
21
21
|
signDisplay: 'exceptZero'
|
|
22
22
|
}).resolvedOptions().signDisplay === 'exceptZero';
|
|
23
23
|
// eslint-disable-next-line no-empty
|
|
24
24
|
} catch {}
|
|
25
|
-
let $
|
|
25
|
+
let $7fe67f77592add0a$var$supportsUnit = false;
|
|
26
26
|
try {
|
|
27
|
-
$
|
|
27
|
+
$7fe67f77592add0a$var$supportsUnit = new Intl.NumberFormat('de-DE', {
|
|
28
28
|
style: 'unit',
|
|
29
29
|
unit: 'degree'
|
|
30
30
|
}).resolvedOptions().style === 'unit';
|
|
@@ -33,7 +33,7 @@ try {
|
|
|
33
33
|
// Polyfill for units since Safari doesn't support them yet. See https://bugs.webkit.org/show_bug.cgi?id=215438.
|
|
34
34
|
// Currently only polyfilling the unit degree in narrow format for ColorSlider in our supported locales.
|
|
35
35
|
// Values were determined by switching to each locale manually in Chrome.
|
|
36
|
-
const $
|
|
36
|
+
const $7fe67f77592add0a$var$UNITS = {
|
|
37
37
|
degree: {
|
|
38
38
|
narrow: {
|
|
39
39
|
default: "\xb0",
|
|
@@ -43,16 +43,19 @@ const $0c1d5654b62fc485$var$UNITS = {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
-
class $
|
|
46
|
+
class $7fe67f77592add0a$export$cc77c4ff7e8673c5 {
|
|
47
|
+
constructor(locale, options = {}){
|
|
48
|
+
this.numberFormatter = $7fe67f77592add0a$var$getCachedNumberFormatter(locale, options);
|
|
49
|
+
this.options = options;
|
|
50
|
+
}
|
|
47
51
|
/** Formats a number value as a string, according to the locale and options provided to the constructor. */ format(value) {
|
|
48
52
|
let res = '';
|
|
49
|
-
if (!$
|
|
53
|
+
if (!$7fe67f77592add0a$var$supportsSignDisplay && this.options.signDisplay != null) res = $7fe67f77592add0a$export$711b50b3c525e0f2(this.numberFormatter, this.options.signDisplay, value);
|
|
50
54
|
else res = this.numberFormatter.format(value);
|
|
51
|
-
if (this.options.style === 'unit' && !$
|
|
52
|
-
var _UNITS_unit;
|
|
55
|
+
if (this.options.style === 'unit' && !$7fe67f77592add0a$var$supportsUnit) {
|
|
53
56
|
let { unit: unit, unitDisplay: unitDisplay = 'short', locale: locale } = this.resolvedOptions();
|
|
54
57
|
if (!unit) return res;
|
|
55
|
-
let values =
|
|
58
|
+
let values = $7fe67f77592add0a$var$UNITS[unit]?.[unitDisplay];
|
|
56
59
|
res += values[locale] || values.default;
|
|
57
60
|
}
|
|
58
61
|
return res;
|
|
@@ -90,11 +93,11 @@ class $0c1d5654b62fc485$export$cc77c4ff7e8673c5 {
|
|
|
90
93
|
}
|
|
91
94
|
/** Returns the resolved formatting options based on the values passed to the constructor. */ resolvedOptions() {
|
|
92
95
|
let options = this.numberFormatter.resolvedOptions();
|
|
93
|
-
if (!$
|
|
96
|
+
if (!$7fe67f77592add0a$var$supportsSignDisplay && this.options.signDisplay != null) options = {
|
|
94
97
|
...options,
|
|
95
98
|
signDisplay: this.options.signDisplay
|
|
96
99
|
};
|
|
97
|
-
if (!$
|
|
100
|
+
if (!$7fe67f77592add0a$var$supportsUnit && this.options.style === 'unit') options = {
|
|
98
101
|
...options,
|
|
99
102
|
style: 'unit',
|
|
100
103
|
unit: this.options.unit,
|
|
@@ -102,34 +105,29 @@ class $0c1d5654b62fc485$export$cc77c4ff7e8673c5 {
|
|
|
102
105
|
};
|
|
103
106
|
return options;
|
|
104
107
|
}
|
|
105
|
-
constructor(locale, options = {}){
|
|
106
|
-
this.numberFormatter = $0c1d5654b62fc485$var$getCachedNumberFormatter(locale, options);
|
|
107
|
-
this.options = options;
|
|
108
|
-
}
|
|
109
108
|
}
|
|
110
|
-
function $
|
|
109
|
+
function $7fe67f77592add0a$var$getCachedNumberFormatter(locale, options = {}) {
|
|
111
110
|
let { numberingSystem: numberingSystem } = options;
|
|
112
111
|
if (numberingSystem && locale.includes('-nu-')) {
|
|
113
112
|
if (!locale.includes('-u-')) locale += '-u-';
|
|
114
113
|
locale += `-nu-${numberingSystem}`;
|
|
115
114
|
}
|
|
116
|
-
if (options.style === 'unit' && !$
|
|
117
|
-
var _UNITS_unit;
|
|
115
|
+
if (options.style === 'unit' && !$7fe67f77592add0a$var$supportsUnit) {
|
|
118
116
|
let { unit: unit, unitDisplay: unitDisplay = 'short' } = options;
|
|
119
117
|
if (!unit) throw new Error('unit option must be provided with style: "unit"');
|
|
120
|
-
if (
|
|
118
|
+
if (!$7fe67f77592add0a$var$UNITS[unit]?.[unitDisplay]) throw new Error(`Unsupported unit ${unit} with unitDisplay = ${unitDisplay}`);
|
|
121
119
|
options = {
|
|
122
120
|
...options,
|
|
123
121
|
style: 'decimal'
|
|
124
122
|
};
|
|
125
123
|
}
|
|
126
124
|
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : '');
|
|
127
|
-
if ($
|
|
125
|
+
if ($7fe67f77592add0a$var$formatterCache.has(cacheKey)) return $7fe67f77592add0a$var$formatterCache.get(cacheKey);
|
|
128
126
|
let numberFormatter = new Intl.NumberFormat(locale, options);
|
|
129
|
-
$
|
|
127
|
+
$7fe67f77592add0a$var$formatterCache.set(cacheKey, numberFormatter);
|
|
130
128
|
return numberFormatter;
|
|
131
129
|
}
|
|
132
|
-
function $
|
|
130
|
+
function $7fe67f77592add0a$export$711b50b3c525e0f2(numberFormat, signDisplay, num) {
|
|
133
131
|
if (signDisplay === 'auto') return numberFormat.format(num);
|
|
134
132
|
else if (signDisplay === 'never') return numberFormat.format(Math.abs(num));
|
|
135
133
|
else {
|
|
@@ -154,4 +152,4 @@ function $0c1d5654b62fc485$export$711b50b3c525e0f2(numberFormat, signDisplay, nu
|
|
|
154
152
|
}
|
|
155
153
|
|
|
156
154
|
|
|
157
|
-
//# sourceMappingURL=NumberFormatter.
|
|
155
|
+
//# sourceMappingURL=NumberFormatter.cjs.map
|
|
@@ -0,0 +1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a,MAAM,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 supportsSignDisplay = (new Intl.NumberFormat('de-DE', {signDisplay: 'exceptZero'})).resolvedOptions().signDisplay === 'exceptZero';\n // eslint-disable-next-line no-empty\n} catch {}\n\nlet supportsUnit = false;\ntry {\n supportsUnit = (new Intl.NumberFormat('de-DE', {style: 'unit', unit: 'degree'})).resolvedOptions().style === 'unit';\n // eslint-disable-next-line no-empty\n} catch {}\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 return this.numberFormatter.formatToParts(value);\n }\n\n /** Formats a number range as a string. */\n formatRange(start: number, end: number): string {\n if (typeof this.numberFormatter.formatRange === 'function') {\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 if (typeof this.numberFormatter.formatRangeToParts === 'function') {\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): string {\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.cjs.map"}
|
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
|
-
*/ let $
|
|
12
|
-
let $
|
|
11
|
+
*/ let $6c0bb0183c96ba81$var$formatterCache = new Map();
|
|
12
|
+
let $6c0bb0183c96ba81$var$supportsSignDisplay = false;
|
|
13
13
|
try {
|
|
14
|
-
$
|
|
14
|
+
$6c0bb0183c96ba81$var$supportsSignDisplay = new Intl.NumberFormat('de-DE', {
|
|
15
15
|
signDisplay: 'exceptZero'
|
|
16
16
|
}).resolvedOptions().signDisplay === 'exceptZero';
|
|
17
17
|
// eslint-disable-next-line no-empty
|
|
18
18
|
} catch {}
|
|
19
|
-
let $
|
|
19
|
+
let $6c0bb0183c96ba81$var$supportsUnit = false;
|
|
20
20
|
try {
|
|
21
|
-
$
|
|
21
|
+
$6c0bb0183c96ba81$var$supportsUnit = new Intl.NumberFormat('de-DE', {
|
|
22
22
|
style: 'unit',
|
|
23
23
|
unit: 'degree'
|
|
24
24
|
}).resolvedOptions().style === 'unit';
|
|
@@ -27,7 +27,7 @@ try {
|
|
|
27
27
|
// Polyfill for units since Safari doesn't support them yet. See https://bugs.webkit.org/show_bug.cgi?id=215438.
|
|
28
28
|
// Currently only polyfilling the unit degree in narrow format for ColorSlider in our supported locales.
|
|
29
29
|
// Values were determined by switching to each locale manually in Chrome.
|
|
30
|
-
const $
|
|
30
|
+
const $6c0bb0183c96ba81$var$UNITS = {
|
|
31
31
|
degree: {
|
|
32
32
|
narrow: {
|
|
33
33
|
default: "\xb0",
|
|
@@ -37,16 +37,16 @@ const $488c6ddbf4ef74c2$var$UNITS = {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
class $
|
|
40
|
+
class $6c0bb0183c96ba81$export$cc77c4ff7e8673c5 {
|
|
41
41
|
/** Formats a number value as a string, according to the locale and options provided to the constructor. */ format(value) {
|
|
42
42
|
let res = '';
|
|
43
|
-
if (!$
|
|
43
|
+
if (!$6c0bb0183c96ba81$var$supportsSignDisplay && this.options.signDisplay != null) res = $6c0bb0183c96ba81$export$711b50b3c525e0f2(this.numberFormatter, this.options.signDisplay, value);
|
|
44
44
|
else res = this.numberFormatter.format(value);
|
|
45
|
-
if (this.options.style === 'unit' && !$
|
|
45
|
+
if (this.options.style === 'unit' && !$6c0bb0183c96ba81$var$supportsUnit) {
|
|
46
46
|
var _UNITS_unit;
|
|
47
47
|
let { unit: unit, unitDisplay: unitDisplay = 'short', locale: locale } = this.resolvedOptions();
|
|
48
48
|
if (!unit) return res;
|
|
49
|
-
let values = (_UNITS_unit = $
|
|
49
|
+
let values = (_UNITS_unit = $6c0bb0183c96ba81$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay];
|
|
50
50
|
res += values[locale] || values.default;
|
|
51
51
|
}
|
|
52
52
|
return res;
|
|
@@ -84,11 +84,11 @@ class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
|
|
|
84
84
|
}
|
|
85
85
|
/** Returns the resolved formatting options based on the values passed to the constructor. */ resolvedOptions() {
|
|
86
86
|
let options = this.numberFormatter.resolvedOptions();
|
|
87
|
-
if (!$
|
|
87
|
+
if (!$6c0bb0183c96ba81$var$supportsSignDisplay && this.options.signDisplay != null) options = {
|
|
88
88
|
...options,
|
|
89
89
|
signDisplay: this.options.signDisplay
|
|
90
90
|
};
|
|
91
|
-
if (!$
|
|
91
|
+
if (!$6c0bb0183c96ba81$var$supportsUnit && this.options.style === 'unit') options = {
|
|
92
92
|
...options,
|
|
93
93
|
style: 'unit',
|
|
94
94
|
unit: this.options.unit,
|
|
@@ -97,33 +97,33 @@ class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
|
|
|
97
97
|
return options;
|
|
98
98
|
}
|
|
99
99
|
constructor(locale, options = {}){
|
|
100
|
-
this.numberFormatter = $
|
|
100
|
+
this.numberFormatter = $6c0bb0183c96ba81$var$getCachedNumberFormatter(locale, options);
|
|
101
101
|
this.options = options;
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
function $
|
|
104
|
+
function $6c0bb0183c96ba81$var$getCachedNumberFormatter(locale, options = {}) {
|
|
105
105
|
let { numberingSystem: numberingSystem } = options;
|
|
106
106
|
if (numberingSystem && locale.includes('-nu-')) {
|
|
107
107
|
if (!locale.includes('-u-')) locale += '-u-';
|
|
108
108
|
locale += `-nu-${numberingSystem}`;
|
|
109
109
|
}
|
|
110
|
-
if (options.style === 'unit' && !$
|
|
110
|
+
if (options.style === 'unit' && !$6c0bb0183c96ba81$var$supportsUnit) {
|
|
111
111
|
var _UNITS_unit;
|
|
112
112
|
let { unit: unit, unitDisplay: unitDisplay = 'short' } = options;
|
|
113
113
|
if (!unit) throw new Error('unit option must be provided with style: "unit"');
|
|
114
|
-
if (!((_UNITS_unit = $
|
|
114
|
+
if (!((_UNITS_unit = $6c0bb0183c96ba81$var$UNITS[unit]) === null || _UNITS_unit === void 0 ? void 0 : _UNITS_unit[unitDisplay])) throw new Error(`Unsupported unit ${unit} with unitDisplay = ${unitDisplay}`);
|
|
115
115
|
options = {
|
|
116
116
|
...options,
|
|
117
117
|
style: 'decimal'
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : '');
|
|
121
|
-
if ($
|
|
121
|
+
if ($6c0bb0183c96ba81$var$formatterCache.has(cacheKey)) return $6c0bb0183c96ba81$var$formatterCache.get(cacheKey);
|
|
122
122
|
let numberFormatter = new Intl.NumberFormat(locale, options);
|
|
123
|
-
$
|
|
123
|
+
$6c0bb0183c96ba81$var$formatterCache.set(cacheKey, numberFormatter);
|
|
124
124
|
return numberFormatter;
|
|
125
125
|
}
|
|
126
|
-
function $
|
|
126
|
+
function $6c0bb0183c96ba81$export$711b50b3c525e0f2(numberFormat, signDisplay, num) {
|
|
127
127
|
if (signDisplay === 'auto') return numberFormat.format(num);
|
|
128
128
|
else if (signDisplay === 'never') return numberFormat.format(Math.abs(num));
|
|
129
129
|
else {
|
|
@@ -148,5 +148,5 @@ function $488c6ddbf4ef74c2$export$711b50b3c525e0f2(numberFormat, signDisplay, nu
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
|
|
151
|
-
export {$
|
|
152
|
-
//# sourceMappingURL=NumberFormatter.
|
|
151
|
+
export {$6c0bb0183c96ba81$export$cc77c4ff7e8673c5 as NumberFormatter, $6c0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Y,CAAC,QAAQ;IACpD,qCAAe,GAAG,CAAC,UAAU;IAC7B,OAAO;AACT;AAGO,SAAS,0CAAgC,YAA+B,EAAE,WAAmB,EAAE,GAAW;IAC/G,IAAI,gBAAgB,QAClB,OAAO,aAAa,MAAM,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 supportsSignDisplay = (new Intl.NumberFormat('de-DE', {signDisplay: 'exceptZero'})).resolvedOptions().signDisplay === 'exceptZero';\n // eslint-disable-next-line no-empty\n} catch {}\n\nlet supportsUnit = false;\ntry {\n supportsUnit = (new Intl.NumberFormat('de-DE', {style: 'unit', unit: 'degree'})).resolvedOptions().style === 'unit';\n // eslint-disable-next-line no-empty\n} catch {}\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 return this.numberFormatter.formatToParts(value);\n }\n\n /** Formats a number range as a string. */\n formatRange(start: number, end: number): string {\n if (typeof this.numberFormatter.formatRange === 'function') {\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 if (typeof this.numberFormatter.formatRangeToParts === 'function') {\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): string {\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"}
|
|
1
|
+
{"mappings":"AAAA;;;;;;;;;;CAUC,GAED,IAAI,uCAAiB,IAAI;AAEzB,IAAI,4CAAsB;AAC1B,IAAI;IACF,4CAAsB,AAAC,IAAI,KAAK,YAAY,CAAC,SAAS;QAAC,aAAa;IAAY,GAAI,eAAe,GAAG,WAAW,KAAK;AACtH,oCAAoC;AACtC,EAAE,OAAM,CA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BAAgB;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 supportsSignDisplay = (new Intl.NumberFormat('de-DE', {signDisplay: 'exceptZero'})).resolvedOptions().signDisplay === 'exceptZero';\n // eslint-disable-next-line no-empty\n} catch {}\n\nlet supportsUnit = false;\ntry {\n supportsUnit = (new Intl.NumberFormat('de-DE', {style: 'unit', unit: 'degree'})).resolvedOptions().style === 'unit';\n // eslint-disable-next-line no-empty\n} catch {}\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 return this.numberFormatter.formatToParts(value);\n }\n\n /** Formats a number range as a string. */\n formatRange(start: number, end: number): string {\n if (typeof this.numberFormatter.formatRange === 'function') {\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 if (typeof this.numberFormatter.formatRangeToParts === 'function') {\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): string {\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.js.map"}
|
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
|
-
*/ let $
|
|
12
|
-
let $
|
|
11
|
+
*/ let $1dfb119a85e764e5$var$formatterCache = new Map();
|
|
12
|
+
let $1dfb119a85e764e5$var$supportsSignDisplay = false;
|
|
13
13
|
try {
|
|
14
|
-
$
|
|
14
|
+
$1dfb119a85e764e5$var$supportsSignDisplay = new Intl.NumberFormat('de-DE', {
|
|
15
15
|
signDisplay: 'exceptZero'
|
|
16
16
|
}).resolvedOptions().signDisplay === 'exceptZero';
|
|
17
17
|
// eslint-disable-next-line no-empty
|
|
18
18
|
} catch {}
|
|
19
|
-
let $
|
|
19
|
+
let $1dfb119a85e764e5$var$supportsUnit = false;
|
|
20
20
|
try {
|
|
21
|
-
$
|
|
21
|
+
$1dfb119a85e764e5$var$supportsUnit = new Intl.NumberFormat('de-DE', {
|
|
22
22
|
style: 'unit',
|
|
23
23
|
unit: 'degree'
|
|
24
24
|
}).resolvedOptions().style === 'unit';
|
|
@@ -27,7 +27,7 @@ try {
|
|
|
27
27
|
// Polyfill for units since Safari doesn't support them yet. See https://bugs.webkit.org/show_bug.cgi?id=215438.
|
|
28
28
|
// Currently only polyfilling the unit degree in narrow format for ColorSlider in our supported locales.
|
|
29
29
|
// Values were determined by switching to each locale manually in Chrome.
|
|
30
|
-
const $
|
|
30
|
+
const $1dfb119a85e764e5$var$UNITS = {
|
|
31
31
|
degree: {
|
|
32
32
|
narrow: {
|
|
33
33
|
default: "\xb0",
|
|
@@ -37,16 +37,19 @@ const $488c6ddbf4ef74c2$var$UNITS = {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
class $
|
|
40
|
+
class $1dfb119a85e764e5$export$cc77c4ff7e8673c5 {
|
|
41
|
+
constructor(locale, options = {}){
|
|
42
|
+
this.numberFormatter = $1dfb119a85e764e5$var$getCachedNumberFormatter(locale, options);
|
|
43
|
+
this.options = options;
|
|
44
|
+
}
|
|
41
45
|
/** Formats a number value as a string, according to the locale and options provided to the constructor. */ format(value) {
|
|
42
46
|
let res = '';
|
|
43
|
-
if (!$
|
|
47
|
+
if (!$1dfb119a85e764e5$var$supportsSignDisplay && this.options.signDisplay != null) res = $1dfb119a85e764e5$export$711b50b3c525e0f2(this.numberFormatter, this.options.signDisplay, value);
|
|
44
48
|
else res = this.numberFormatter.format(value);
|
|
45
|
-
if (this.options.style === 'unit' && !$
|
|
46
|
-
var _UNITS_unit;
|
|
49
|
+
if (this.options.style === 'unit' && !$1dfb119a85e764e5$var$supportsUnit) {
|
|
47
50
|
let { unit: unit, unitDisplay: unitDisplay = 'short', locale: locale } = this.resolvedOptions();
|
|
48
51
|
if (!unit) return res;
|
|
49
|
-
let values =
|
|
52
|
+
let values = $1dfb119a85e764e5$var$UNITS[unit]?.[unitDisplay];
|
|
50
53
|
res += values[locale] || values.default;
|
|
51
54
|
}
|
|
52
55
|
return res;
|
|
@@ -84,11 +87,11 @@ class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
|
|
|
84
87
|
}
|
|
85
88
|
/** Returns the resolved formatting options based on the values passed to the constructor. */ resolvedOptions() {
|
|
86
89
|
let options = this.numberFormatter.resolvedOptions();
|
|
87
|
-
if (!$
|
|
90
|
+
if (!$1dfb119a85e764e5$var$supportsSignDisplay && this.options.signDisplay != null) options = {
|
|
88
91
|
...options,
|
|
89
92
|
signDisplay: this.options.signDisplay
|
|
90
93
|
};
|
|
91
|
-
if (!$
|
|
94
|
+
if (!$1dfb119a85e764e5$var$supportsUnit && this.options.style === 'unit') options = {
|
|
92
95
|
...options,
|
|
93
96
|
style: 'unit',
|
|
94
97
|
unit: this.options.unit,
|
|
@@ -96,34 +99,29 @@ class $488c6ddbf4ef74c2$export$cc77c4ff7e8673c5 {
|
|
|
96
99
|
};
|
|
97
100
|
return options;
|
|
98
101
|
}
|
|
99
|
-
constructor(locale, options = {}){
|
|
100
|
-
this.numberFormatter = $488c6ddbf4ef74c2$var$getCachedNumberFormatter(locale, options);
|
|
101
|
-
this.options = options;
|
|
102
|
-
}
|
|
103
102
|
}
|
|
104
|
-
function $
|
|
103
|
+
function $1dfb119a85e764e5$var$getCachedNumberFormatter(locale, options = {}) {
|
|
105
104
|
let { numberingSystem: numberingSystem } = options;
|
|
106
105
|
if (numberingSystem && locale.includes('-nu-')) {
|
|
107
106
|
if (!locale.includes('-u-')) locale += '-u-';
|
|
108
107
|
locale += `-nu-${numberingSystem}`;
|
|
109
108
|
}
|
|
110
|
-
if (options.style === 'unit' && !$
|
|
111
|
-
var _UNITS_unit;
|
|
109
|
+
if (options.style === 'unit' && !$1dfb119a85e764e5$var$supportsUnit) {
|
|
112
110
|
let { unit: unit, unitDisplay: unitDisplay = 'short' } = options;
|
|
113
111
|
if (!unit) throw new Error('unit option must be provided with style: "unit"');
|
|
114
|
-
if (
|
|
112
|
+
if (!$1dfb119a85e764e5$var$UNITS[unit]?.[unitDisplay]) throw new Error(`Unsupported unit ${unit} with unitDisplay = ${unitDisplay}`);
|
|
115
113
|
options = {
|
|
116
114
|
...options,
|
|
117
115
|
style: 'decimal'
|
|
118
116
|
};
|
|
119
117
|
}
|
|
120
118
|
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : '');
|
|
121
|
-
if ($
|
|
119
|
+
if ($1dfb119a85e764e5$var$formatterCache.has(cacheKey)) return $1dfb119a85e764e5$var$formatterCache.get(cacheKey);
|
|
122
120
|
let numberFormatter = new Intl.NumberFormat(locale, options);
|
|
123
|
-
$
|
|
121
|
+
$1dfb119a85e764e5$var$formatterCache.set(cacheKey, numberFormatter);
|
|
124
122
|
return numberFormatter;
|
|
125
123
|
}
|
|
126
|
-
function $
|
|
124
|
+
function $1dfb119a85e764e5$export$711b50b3c525e0f2(numberFormat, signDisplay, num) {
|
|
127
125
|
if (signDisplay === 'auto') return numberFormat.format(num);
|
|
128
126
|
else if (signDisplay === 'never') return numberFormat.format(Math.abs(num));
|
|
129
127
|
else {
|
|
@@ -148,5 +146,5 @@ function $488c6ddbf4ef74c2$export$711b50b3c525e0f2(numberFormat, signDisplay, nu
|
|
|
148
146
|
}
|
|
149
147
|
|
|
150
148
|
|
|
151
|
-
export {$
|
|
152
|
-
//# sourceMappingURL=NumberFormatter.
|
|
149
|
+
export {$1dfb119a85e764e5$export$cc77c4ff7e8673c5 as NumberFormatter, $1dfb119a85e764e5$export$711b50b3c525e0f2 as numberFormatSignDisplayPolyfill};
|
|
150
|
+
//# sourceMappingURL=NumberFormatter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAAA;;;;;;;;;;CAUC,GAED,IAAI,uCAAiB,IAAI;AAEzB,IAAI,4CAAsB;AAC1B,IAAI;IACF,4CAA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gB,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 supportsSignDisplay = (new Intl.NumberFormat('de-DE', {signDisplay: 'exceptZero'})).resolvedOptions().signDisplay === 'exceptZero';\n // eslint-disable-next-line no-empty\n} catch {}\n\nlet supportsUnit = false;\ntry {\n supportsUnit = (new Intl.NumberFormat('de-DE', {style: 'unit', unit: 'degree'})).resolvedOptions().style === 'unit';\n // eslint-disable-next-line no-empty\n} catch {}\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 return this.numberFormatter.formatToParts(value);\n }\n\n /** Formats a number range as a string. */\n formatRange(start: number, end: number): string {\n if (typeof this.numberFormatter.formatRange === 'function') {\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 if (typeof this.numberFormatter.formatRangeToParts === 'function') {\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): string {\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.mjs.map"}
|