@univerjs/core 1.0.0-alpha.3 → 1.0.0-alpha.4
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/lib/cjs/index.js +3899 -92
- package/lib/es/index.js +3902 -93
- package/lib/index.js +3902 -93
- package/lib/types/docs/data-model/index.d.ts +2 -1
- package/lib/types/docs/data-model/rich-text-builder.d.ts +186 -0
- package/lib/types/docs/data-model/text-x/build-utils/drawings.d.ts +2 -2
- package/lib/types/docs/data-model/text-x/build-utils/index.d.ts +1 -0
- package/lib/types/shared/numfmt/api.d.ts +82 -0
- package/lib/types/shared/numfmt/clamp.d.ts +16 -0
- package/lib/types/shared/numfmt/code-to-locale.d.ts +16 -0
- package/lib/types/shared/numfmt/constants.d.ts +68 -0
- package/lib/types/shared/numfmt/dec-to-frac.d.ts +26 -0
- package/lib/types/shared/numfmt/decimal.d.ts +37 -0
- package/lib/types/shared/numfmt/format-info.d.ts +21 -0
- package/lib/types/shared/numfmt/format-number.d.ts +18 -0
- package/lib/types/shared/numfmt/general.d.ts +18 -0
- package/lib/types/shared/numfmt/index.d.ts +18 -0
- package/lib/types/shared/numfmt/locale.d.ts +89 -0
- package/lib/types/shared/numfmt/num-dec.d.ts +17 -0
- package/lib/types/shared/numfmt/number-props.d.ts +17 -0
- package/lib/types/shared/numfmt/options.d.ts +17 -0
- package/lib/types/shared/numfmt/pad.d.ts +22 -0
- package/lib/types/shared/numfmt/parse-format-section.d.ts +17 -0
- package/lib/types/shared/numfmt/parse-pattern.d.ts +18 -0
- package/lib/types/shared/numfmt/parse-value.d.ts +30 -0
- package/lib/types/shared/numfmt/round.d.ts +26 -0
- package/lib/types/shared/numfmt/run-part.d.ts +18 -0
- package/lib/types/shared/numfmt/serial-date.d.ts +32 -0
- package/lib/types/shared/numfmt/to-ymd.d.ts +20 -0
- package/lib/types/shared/numfmt/tokenize.d.ts +20 -0
- package/lib/types/shared/numfmt/types.d.ts +193 -0
- package/lib/types/shared/{numfmt.d.ts → numfmt/utils.d.ts} +3 -4
- package/lib/types/types/interfaces/i-document-data.d.ts +4 -0
- package/lib/types/types/interfaces/i-style-data.d.ts +3 -1
- package/lib/umd/index.js +21 -19
- package/package.json +4 -5
package/lib/cjs/index.js
CHANGED
|
@@ -6,6 +6,19 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __exportAll = (all, no_symbols) => {
|
|
10
|
+
let target = {};
|
|
11
|
+
for (var name in all) {
|
|
12
|
+
__defProp(target, name, {
|
|
13
|
+
get: all[name],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (!no_symbols) {
|
|
18
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
19
|
+
}
|
|
20
|
+
return target;
|
|
21
|
+
};
|
|
9
22
|
var __copyProps = (to, from, except, desc) => {
|
|
10
23
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
24
|
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
@@ -31,8 +44,6 @@ let _univerjs_protocol = require("@univerjs/protocol");
|
|
|
31
44
|
let rxjs_operators = require("rxjs/operators");
|
|
32
45
|
let _wendellhu_redi = require("@wendellhu/redi");
|
|
33
46
|
let lodash_es = require("lodash-es");
|
|
34
|
-
let numfmt = require("numfmt");
|
|
35
|
-
numfmt = __toESM(numfmt);
|
|
36
47
|
let rbush = require("rbush");
|
|
37
48
|
rbush = __toESM(rbush);
|
|
38
49
|
let async_lock = require("async-lock");
|
|
@@ -1732,7 +1743,7 @@ let ThemeColors = /* @__PURE__ */ function(ThemeColors) {
|
|
|
1732
1743
|
//#endregion
|
|
1733
1744
|
//#region package.json
|
|
1734
1745
|
var name = "@univerjs/core";
|
|
1735
|
-
var version = "1.0.0-alpha.
|
|
1746
|
+
var version = "1.0.0-alpha.4";
|
|
1736
1747
|
|
|
1737
1748
|
//#endregion
|
|
1738
1749
|
//#region src/common/array.ts
|
|
@@ -3903,79 +3914,3516 @@ let DOC_RANGE_TYPE = /* @__PURE__ */ function(DOC_RANGE_TYPE) {
|
|
|
3903
3914
|
return DOC_RANGE_TYPE;
|
|
3904
3915
|
}({});
|
|
3905
3916
|
/**
|
|
3906
|
-
* Determines whether the cell(row, column) is within the range of the merged cells.
|
|
3907
|
-
* @deprecated please use worksheet.getCellInfoInMergeData instead
|
|
3917
|
+
* Determines whether the cell(row, column) is within the range of the merged cells.
|
|
3918
|
+
* @deprecated please use worksheet.getCellInfoInMergeData instead
|
|
3919
|
+
*/
|
|
3920
|
+
function getCellInfoInMergeData(row, column, mergeData) {
|
|
3921
|
+
let isMerged = false;
|
|
3922
|
+
let isMergedMainCell = false;
|
|
3923
|
+
let newEndRow = row;
|
|
3924
|
+
let newEndColumn = column;
|
|
3925
|
+
let mergeRow = row;
|
|
3926
|
+
let mergeColumn = column;
|
|
3927
|
+
if (mergeData == null) return {
|
|
3928
|
+
actualRow: row,
|
|
3929
|
+
actualColumn: column,
|
|
3930
|
+
isMergedMainCell,
|
|
3931
|
+
isMerged,
|
|
3932
|
+
endRow: newEndRow,
|
|
3933
|
+
endColumn: newEndColumn,
|
|
3934
|
+
startRow: mergeRow,
|
|
3935
|
+
startColumn: mergeColumn
|
|
3936
|
+
};
|
|
3937
|
+
for (let i = 0; i < mergeData.length; i++) {
|
|
3938
|
+
const { startRow: startRowMarge, endRow: endRowMarge, startColumn: startColumnMarge, endColumn: endColumnMarge } = mergeData[i];
|
|
3939
|
+
if (row === startRowMarge && column === startColumnMarge) {
|
|
3940
|
+
newEndRow = endRowMarge;
|
|
3941
|
+
newEndColumn = endColumnMarge;
|
|
3942
|
+
mergeRow = startRowMarge;
|
|
3943
|
+
mergeColumn = startColumnMarge;
|
|
3944
|
+
isMergedMainCell = true;
|
|
3945
|
+
break;
|
|
3946
|
+
}
|
|
3947
|
+
if (row >= startRowMarge && row <= endRowMarge && column >= startColumnMarge && column <= endColumnMarge) {
|
|
3948
|
+
newEndRow = endRowMarge;
|
|
3949
|
+
newEndColumn = endColumnMarge;
|
|
3950
|
+
mergeRow = startRowMarge;
|
|
3951
|
+
mergeColumn = startColumnMarge;
|
|
3952
|
+
isMerged = true;
|
|
3953
|
+
break;
|
|
3954
|
+
}
|
|
3955
|
+
}
|
|
3956
|
+
return {
|
|
3957
|
+
actualRow: row,
|
|
3958
|
+
actualColumn: column,
|
|
3959
|
+
isMergedMainCell,
|
|
3960
|
+
isMerged,
|
|
3961
|
+
endRow: newEndRow,
|
|
3962
|
+
endColumn: newEndColumn,
|
|
3963
|
+
startRow: mergeRow,
|
|
3964
|
+
startColumn: mergeColumn
|
|
3965
|
+
};
|
|
3966
|
+
}
|
|
3967
|
+
let CellModeEnum = /* @__PURE__ */ function(CellModeEnum) {
|
|
3968
|
+
CellModeEnum["Raw"] = "raw";
|
|
3969
|
+
CellModeEnum["Intercepted"] = "intercepted";
|
|
3970
|
+
CellModeEnum["Both"] = "both";
|
|
3971
|
+
return CellModeEnum;
|
|
3972
|
+
}({});
|
|
3973
|
+
|
|
3974
|
+
//#endregion
|
|
3975
|
+
//#region src/types/const/theme-color-map.ts
|
|
3976
|
+
const THEME_COLORS = { ["Office"]: {
|
|
3977
|
+
[4]: "#4472C4",
|
|
3978
|
+
[5]: "#ED7D31",
|
|
3979
|
+
[6]: "#A5A5A5",
|
|
3980
|
+
[7]: "#70AD47",
|
|
3981
|
+
[8]: "#5B9BD5",
|
|
3982
|
+
[9]: "#70AD47",
|
|
3983
|
+
[0]: "#000000",
|
|
3984
|
+
[2]: "#44546A",
|
|
3985
|
+
[1]: "#FFFFFF",
|
|
3986
|
+
[3]: "#E7E6E6",
|
|
3987
|
+
[10]: "#0563C1",
|
|
3988
|
+
[11]: "#954F72"
|
|
3989
|
+
} };
|
|
3990
|
+
|
|
3991
|
+
//#endregion
|
|
3992
|
+
//#region src/shared/numfmt/constants.ts
|
|
3993
|
+
const MAX_S_DATE = 2958466;
|
|
3994
|
+
const MIN_L_DATE = -694324;
|
|
3995
|
+
const MAX_L_DATE = 35830291;
|
|
3996
|
+
const TOKEN_GENERAL = "general";
|
|
3997
|
+
const TOKEN_HASH = "hash";
|
|
3998
|
+
const TOKEN_ZERO = "zero";
|
|
3999
|
+
const TOKEN_QMARK = "qmark";
|
|
4000
|
+
const TOKEN_SLASH = "slash";
|
|
4001
|
+
const TOKEN_GROUP = "group";
|
|
4002
|
+
const TOKEN_SCALE = "scale";
|
|
4003
|
+
const TOKEN_COMMA = "comma";
|
|
4004
|
+
const TOKEN_BREAK = "break";
|
|
4005
|
+
const TOKEN_TEXT = "text";
|
|
4006
|
+
const TOKEN_PLUS = "plus";
|
|
4007
|
+
const TOKEN_MINUS = "minus";
|
|
4008
|
+
const TOKEN_POINT = "point";
|
|
4009
|
+
const TOKEN_SPACE = "space";
|
|
4010
|
+
const TOKEN_PERCENT = "percent";
|
|
4011
|
+
const TOKEN_DIGIT = "digit";
|
|
4012
|
+
const TOKEN_CALENDAR = "calendar";
|
|
4013
|
+
const TOKEN_ERROR = "error";
|
|
4014
|
+
const TOKEN_DATETIME = "datetime";
|
|
4015
|
+
const TOKEN_DURATION = "duration";
|
|
4016
|
+
const TOKEN_CONDITION = "condition";
|
|
4017
|
+
const TOKEN_DBNUM = "dbnum";
|
|
4018
|
+
const TOKEN_NATNUM = "natnum";
|
|
4019
|
+
const TOKEN_LOCALE = "locale";
|
|
4020
|
+
const TOKEN_COLOR = "color";
|
|
4021
|
+
const TOKEN_MODIFIER = "modifier";
|
|
4022
|
+
const TOKEN_AMPM = "ampm";
|
|
4023
|
+
const TOKEN_ESCAPED = "escaped";
|
|
4024
|
+
const TOKEN_STRING = "string";
|
|
4025
|
+
const TOKEN_SKIP = "skip";
|
|
4026
|
+
const TOKEN_FILL = "fill";
|
|
4027
|
+
const TOKEN_PAREN = "paren";
|
|
4028
|
+
const TOKEN_CHAR = "char";
|
|
4029
|
+
const indexColors = [
|
|
4030
|
+
"#000000",
|
|
4031
|
+
"#FFFFFF",
|
|
4032
|
+
"#FF0000",
|
|
4033
|
+
"#00FF00",
|
|
4034
|
+
"#0000FF",
|
|
4035
|
+
"#FFFF00",
|
|
4036
|
+
"#FF00FF",
|
|
4037
|
+
"#00FFFF",
|
|
4038
|
+
"#800000",
|
|
4039
|
+
"#008000",
|
|
4040
|
+
"#000080",
|
|
4041
|
+
"#808000",
|
|
4042
|
+
"#800080",
|
|
4043
|
+
"#008080",
|
|
4044
|
+
"#C0C0C0",
|
|
4045
|
+
"#808080",
|
|
4046
|
+
"#9999FF",
|
|
4047
|
+
"#993366",
|
|
4048
|
+
"#FFFFCC",
|
|
4049
|
+
"#CCFFFF",
|
|
4050
|
+
"#660066",
|
|
4051
|
+
"#FF8080",
|
|
4052
|
+
"#0066CC",
|
|
4053
|
+
"#CCCCFF",
|
|
4054
|
+
"#000080",
|
|
4055
|
+
"#FF00FF",
|
|
4056
|
+
"#FFFF00",
|
|
4057
|
+
"#00FFFF",
|
|
4058
|
+
"#800080",
|
|
4059
|
+
"#800000",
|
|
4060
|
+
"#008080",
|
|
4061
|
+
"#0000FF",
|
|
4062
|
+
"#00CCFF",
|
|
4063
|
+
"#CCFFFF",
|
|
4064
|
+
"#CCFFCC",
|
|
4065
|
+
"#FFFF99",
|
|
4066
|
+
"#99CCFF",
|
|
4067
|
+
"#FF99CC",
|
|
4068
|
+
"#CC99FF",
|
|
4069
|
+
"#FFCC99",
|
|
4070
|
+
"#3366FF",
|
|
4071
|
+
"#33CCCC",
|
|
4072
|
+
"#99CC00",
|
|
4073
|
+
"#FFCC00",
|
|
4074
|
+
"#FF9900",
|
|
4075
|
+
"#FF6600",
|
|
4076
|
+
"#666699",
|
|
4077
|
+
"#969696",
|
|
4078
|
+
"#003366",
|
|
4079
|
+
"#339966",
|
|
4080
|
+
"#003300",
|
|
4081
|
+
"#333300",
|
|
4082
|
+
"#993300",
|
|
4083
|
+
"#993366",
|
|
4084
|
+
"#333399",
|
|
4085
|
+
"#333333"
|
|
4086
|
+
];
|
|
4087
|
+
const currencySymbols$1 = [
|
|
4088
|
+
"¤",
|
|
4089
|
+
"$",
|
|
4090
|
+
"£",
|
|
4091
|
+
"¥",
|
|
4092
|
+
"֏",
|
|
4093
|
+
"؋",
|
|
4094
|
+
"৳",
|
|
4095
|
+
"฿",
|
|
4096
|
+
"៛",
|
|
4097
|
+
"₡",
|
|
4098
|
+
"₦",
|
|
4099
|
+
"₩",
|
|
4100
|
+
"₪",
|
|
4101
|
+
"₫",
|
|
4102
|
+
"€",
|
|
4103
|
+
"₭",
|
|
4104
|
+
"₮",
|
|
4105
|
+
"₱",
|
|
4106
|
+
"₲",
|
|
4107
|
+
"₴",
|
|
4108
|
+
"₸",
|
|
4109
|
+
"₹",
|
|
4110
|
+
"₺",
|
|
4111
|
+
"₼",
|
|
4112
|
+
"₽",
|
|
4113
|
+
"₾",
|
|
4114
|
+
"₿"
|
|
4115
|
+
];
|
|
4116
|
+
const reCurrencySymbols = new RegExp(`[${currencySymbols$1.join("")}]`);
|
|
4117
|
+
|
|
4118
|
+
//#endregion
|
|
4119
|
+
//#region src/shared/numfmt/format-info.ts
|
|
4120
|
+
function isParsedSection$1(part) {
|
|
4121
|
+
return !!part && "scale" in part;
|
|
4122
|
+
}
|
|
4123
|
+
function isGenerated(part) {
|
|
4124
|
+
return !!part && "generated" in part && Boolean(part.generated);
|
|
4125
|
+
}
|
|
4126
|
+
function isPercent(partitions) {
|
|
4127
|
+
return !!(isParsedSection$1(partitions[0]) && partitions[0].percent || isParsedSection$1(partitions[1]) && partitions[1].percent || isParsedSection$1(partitions[2]) && partitions[2].percent || isParsedSection$1(partitions[3]) && partitions[3].percent);
|
|
4128
|
+
}
|
|
4129
|
+
function isDate(partitions) {
|
|
4130
|
+
return !!(isParsedSection$1(partitions[0]) && partitions[0].date || isParsedSection$1(partitions[1]) && partitions[1].date || isParsedSection$1(partitions[2]) && partitions[2].date || isParsedSection$1(partitions[3]) && partitions[3].date);
|
|
4131
|
+
}
|
|
4132
|
+
function isText(partitions) {
|
|
4133
|
+
const [part1, part2, part3, part4] = partitions;
|
|
4134
|
+
return !!((!part1 || isGenerated(part1)) && (!part2 || isGenerated(part2)) && (!part3 || isGenerated(part3)) && isParsedSection$1(part4) && part4.text && !isGenerated(part4));
|
|
4135
|
+
}
|
|
4136
|
+
const level = {
|
|
4137
|
+
text: 15,
|
|
4138
|
+
datetime: 10.8,
|
|
4139
|
+
date: 10.8,
|
|
4140
|
+
time: 10.8,
|
|
4141
|
+
percent: 10.6,
|
|
4142
|
+
currency: 10.4,
|
|
4143
|
+
grouped: 10.2,
|
|
4144
|
+
scientific: 6,
|
|
4145
|
+
number: 4,
|
|
4146
|
+
fraction: 2,
|
|
4147
|
+
general: 0,
|
|
4148
|
+
error: 0
|
|
4149
|
+
};
|
|
4150
|
+
const dateCodes = [
|
|
4151
|
+
["DMY", 1],
|
|
4152
|
+
["DM", 2],
|
|
4153
|
+
["MY", 3],
|
|
4154
|
+
["MDY", 4],
|
|
4155
|
+
["MD", 5],
|
|
4156
|
+
["hmsa", 6],
|
|
4157
|
+
["hma", 7],
|
|
4158
|
+
["hms", 8],
|
|
4159
|
+
["hm", 9]
|
|
4160
|
+
];
|
|
4161
|
+
function info(partitions, currencyId = null) {
|
|
4162
|
+
var _positive$scale;
|
|
4163
|
+
const [partPositive, partNegative] = partitions;
|
|
4164
|
+
if (!partPositive) throw new TypeError("Cannot read properties of undefined (reading 'frac_max')");
|
|
4165
|
+
const positive = isParsedSection$1(partPositive) ? partPositive : void 0;
|
|
4166
|
+
const negative = isParsedSection$1(partNegative) ? partNegative : void 0;
|
|
4167
|
+
const isError = "error" in partPositive;
|
|
4168
|
+
const fracMax = positive === null || positive === void 0 ? void 0 : positive.frac_max;
|
|
4169
|
+
const output = {
|
|
4170
|
+
type: "general",
|
|
4171
|
+
isDate: isDate(partitions),
|
|
4172
|
+
isText: isText(partitions),
|
|
4173
|
+
isPercent: isPercent(partitions),
|
|
4174
|
+
maxDecimals: (positive === null || positive === void 0 ? void 0 : positive.general) ? 9 : fracMax !== null && fracMax !== void 0 ? fracMax : 0,
|
|
4175
|
+
scale: (_positive$scale = positive === null || positive === void 0 ? void 0 : positive.scale) !== null && _positive$scale !== void 0 ? _positive$scale : 1,
|
|
4176
|
+
color: 0,
|
|
4177
|
+
parentheses: 0,
|
|
4178
|
+
grouped: (positive === null || positive === void 0 ? void 0 : positive.grouping) ? 1 : 0,
|
|
4179
|
+
code: "",
|
|
4180
|
+
level: 0
|
|
4181
|
+
};
|
|
4182
|
+
const isCurrency = !output.isDate && !output.isText && !isError && partPositive.tokens.some((token) => token.type === "string" && typeof token.value === "string" && (currencyId ? token.value === currencyId : reCurrencySymbols.test(token.value)));
|
|
4183
|
+
let codeType = "G";
|
|
4184
|
+
let codeNumber = fracMax !== void 0 && fracMax >= 0 ? Math.min(15, fracMax) : "";
|
|
4185
|
+
let codeParentheses = "";
|
|
4186
|
+
let codeDash = "";
|
|
4187
|
+
if (negative === null || negative === void 0 ? void 0 : negative.color) {
|
|
4188
|
+
codeDash = "-";
|
|
4189
|
+
output.color = 1;
|
|
4190
|
+
}
|
|
4191
|
+
if (positive === null || positive === void 0 ? void 0 : positive.parens) {
|
|
4192
|
+
codeParentheses = "()";
|
|
4193
|
+
output.parentheses = 1;
|
|
4194
|
+
}
|
|
4195
|
+
if (isCurrency) {
|
|
4196
|
+
codeType = "C";
|
|
4197
|
+
output.type = "currency";
|
|
4198
|
+
} else if (isError) {
|
|
4199
|
+
output.type = "error";
|
|
4200
|
+
output.maxDecimals = 0;
|
|
4201
|
+
} else if (output.isDate) {
|
|
4202
|
+
let haveTime = 0;
|
|
4203
|
+
let haveDate = 0;
|
|
4204
|
+
let order = "";
|
|
4205
|
+
partPositive.tokens.forEach((token) => {
|
|
4206
|
+
const type = token.type;
|
|
4207
|
+
if (/^(b-)?year/.test(type)) {
|
|
4208
|
+
order += "Y";
|
|
4209
|
+
haveDate++;
|
|
4210
|
+
} else if (type.startsWith("month")) {
|
|
4211
|
+
order += "M";
|
|
4212
|
+
haveDate++;
|
|
4213
|
+
} else if (/^(week)?day/.test(type)) {
|
|
4214
|
+
order += "D";
|
|
4215
|
+
haveDate++;
|
|
4216
|
+
} else if (type === "hour" || type === "min" || type === "sec" || type === "ampm") {
|
|
4217
|
+
order += type[0];
|
|
4218
|
+
haveTime++;
|
|
4219
|
+
}
|
|
4220
|
+
});
|
|
4221
|
+
output.type = "date";
|
|
4222
|
+
if (haveDate && haveTime) output.type = "datetime";
|
|
4223
|
+
else if (!haveDate && haveTime) output.type = "time";
|
|
4224
|
+
const code = dateCodes.find(([prefix]) => order.startsWith(prefix));
|
|
4225
|
+
codeType = code ? "D" : "G";
|
|
4226
|
+
codeNumber = code ? code[1] : "";
|
|
4227
|
+
} else if (output.isText) {
|
|
4228
|
+
codeType = "G";
|
|
4229
|
+
output.type = "text";
|
|
4230
|
+
codeNumber = "";
|
|
4231
|
+
output.maxDecimals = 0;
|
|
4232
|
+
} else if (positive === null || positive === void 0 ? void 0 : positive.general) {
|
|
4233
|
+
codeType = "G";
|
|
4234
|
+
output.type = "general";
|
|
4235
|
+
codeNumber = "";
|
|
4236
|
+
} else if (positive === null || positive === void 0 ? void 0 : positive.fractions) {
|
|
4237
|
+
codeType = "G";
|
|
4238
|
+
output.type = "fraction";
|
|
4239
|
+
codeNumber = "";
|
|
4240
|
+
} else if (positive === null || positive === void 0 ? void 0 : positive.exponential) {
|
|
4241
|
+
codeType = "S";
|
|
4242
|
+
output.type = "scientific";
|
|
4243
|
+
} else if (output.isPercent) {
|
|
4244
|
+
codeType = "P";
|
|
4245
|
+
output.type = "percent";
|
|
4246
|
+
} else if (positive === null || positive === void 0 ? void 0 : positive.grouping) {
|
|
4247
|
+
codeType = ",";
|
|
4248
|
+
output.type = "grouped";
|
|
4249
|
+
} else if (positive && (positive.int_max || fracMax)) {
|
|
4250
|
+
codeType = "F";
|
|
4251
|
+
output.type = "number";
|
|
4252
|
+
}
|
|
4253
|
+
output.code = codeType + codeNumber + codeDash + codeParentheses;
|
|
4254
|
+
output.level = level[output.type];
|
|
4255
|
+
return Object.freeze(output);
|
|
4256
|
+
}
|
|
4257
|
+
function dateInfo(partitions) {
|
|
4258
|
+
var _positive$date;
|
|
4259
|
+
const [partPositive] = partitions;
|
|
4260
|
+
if (!partPositive) throw new TypeError("Cannot read properties of undefined (reading 'date')");
|
|
4261
|
+
const positive = isParsedSection$1(partPositive) ? partPositive : void 0;
|
|
4262
|
+
const date = (_positive$date = positive === null || positive === void 0 ? void 0 : positive.date) !== null && _positive$date !== void 0 ? _positive$date : 0;
|
|
4263
|
+
return {
|
|
4264
|
+
year: !!(date & 2),
|
|
4265
|
+
month: !!(date & 4),
|
|
4266
|
+
day: !!(date & 8),
|
|
4267
|
+
hours: !!(date & 16),
|
|
4268
|
+
minutes: !!(date & 32),
|
|
4269
|
+
seconds: !!(date & 64),
|
|
4270
|
+
clockType: (positive === null || positive === void 0 ? void 0 : positive.clock) === 12 ? 12 : 24
|
|
4271
|
+
};
|
|
4272
|
+
}
|
|
4273
|
+
|
|
4274
|
+
//#endregion
|
|
4275
|
+
//#region src/shared/numfmt/decimal.ts
|
|
4276
|
+
/**
|
|
4277
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
4278
|
+
*
|
|
4279
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4280
|
+
* you may not use this file except in compliance with the License.
|
|
4281
|
+
* You may obtain a copy of the License at
|
|
4282
|
+
*
|
|
4283
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4284
|
+
*
|
|
4285
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
4286
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4287
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4288
|
+
* See the License for the specific language governing permissions and
|
|
4289
|
+
* limitations under the License.
|
|
4290
|
+
*/
|
|
4291
|
+
const SPREADSHEET_SIGNIFICANT_DIGITS = 15;
|
|
4292
|
+
function decimalFromNumber(value) {
|
|
4293
|
+
if (!Number.isFinite(value)) throw new RangeError("decimalFromNumber requires a finite number");
|
|
4294
|
+
const negative = value < 0 || Object.is(value, -0);
|
|
4295
|
+
if (value === 0) return {
|
|
4296
|
+
negative,
|
|
4297
|
+
digits: "0",
|
|
4298
|
+
exponent: 0
|
|
4299
|
+
};
|
|
4300
|
+
const [mantissa, exponentText] = Math.abs(value).toExponential(15 - 1).split("e");
|
|
4301
|
+
return {
|
|
4302
|
+
negative,
|
|
4303
|
+
digits: mantissa.replace(".", "").replace(/0+$/, "") || "0",
|
|
4304
|
+
exponent: Number(exponentText)
|
|
4305
|
+
};
|
|
4306
|
+
}
|
|
4307
|
+
function shiftDecimal(value, power) {
|
|
4308
|
+
return {
|
|
4309
|
+
...value,
|
|
4310
|
+
exponent: value.digits === "0" ? 0 : value.exponent + Math.trunc(power)
|
|
4311
|
+
};
|
|
4312
|
+
}
|
|
4313
|
+
function incrementDigits(value) {
|
|
4314
|
+
const characters = [...value];
|
|
4315
|
+
for (let index = characters.length - 1; index >= 0; index--) {
|
|
4316
|
+
if (characters[index] !== "9") {
|
|
4317
|
+
characters[index] = String(Number(characters[index]) + 1);
|
|
4318
|
+
return characters.join("");
|
|
4319
|
+
}
|
|
4320
|
+
characters[index] = "0";
|
|
4321
|
+
}
|
|
4322
|
+
return `1${characters.join("")}`;
|
|
4323
|
+
}
|
|
4324
|
+
function roundDecimal(value, places = 0) {
|
|
4325
|
+
const normalizedPlaces = Math.trunc(places);
|
|
4326
|
+
const keep = value.exponent + 1 + normalizedPlaces;
|
|
4327
|
+
let units;
|
|
4328
|
+
if (keep < 0) units = "0";
|
|
4329
|
+
else if (keep === 0) units = value.digits[0] >= "5" ? "1" : "0";
|
|
4330
|
+
else {
|
|
4331
|
+
units = value.digits.slice(0, keep).padEnd(keep, "0") || "0";
|
|
4332
|
+
if (keep < value.digits.length && value.digits[keep] >= "5") units = incrementDigits(units);
|
|
4333
|
+
}
|
|
4334
|
+
if (/^0+$/.test(units)) return {
|
|
4335
|
+
negative: value.negative,
|
|
4336
|
+
integer: "0",
|
|
4337
|
+
fraction: "",
|
|
4338
|
+
zero: true
|
|
4339
|
+
};
|
|
4340
|
+
if (normalizedPlaces <= 0) return {
|
|
4341
|
+
negative: value.negative,
|
|
4342
|
+
integer: units + "0".repeat(-normalizedPlaces),
|
|
4343
|
+
fraction: "",
|
|
4344
|
+
zero: false
|
|
4345
|
+
};
|
|
4346
|
+
const fixed = units.padStart(normalizedPlaces + 1, "0");
|
|
4347
|
+
return {
|
|
4348
|
+
negative: value.negative,
|
|
4349
|
+
integer: fixed.slice(0, -normalizedPlaces),
|
|
4350
|
+
fraction: fixed.slice(-normalizedPlaces).replace(/0+$/, ""),
|
|
4351
|
+
zero: false
|
|
4352
|
+
};
|
|
4353
|
+
}
|
|
4354
|
+
function decimalPartsToNumber(value) {
|
|
4355
|
+
const magnitude = Number(value.fraction ? `${value.integer}.${value.fraction}` : value.integer);
|
|
4356
|
+
return value.negative && !value.zero ? -magnitude : magnitude;
|
|
4357
|
+
}
|
|
4358
|
+
function decimalPartsToPlainString(value) {
|
|
4359
|
+
return `${value.negative && !value.zero ? "-" : ""}${value.integer}${value.fraction ? `.${value.fraction}` : ""}`;
|
|
4360
|
+
}
|
|
4361
|
+
function roundScientificDecimal(value, integerDigits, hasIntegerPattern, fractionDigits) {
|
|
4362
|
+
if (value.digits === "0") return {
|
|
4363
|
+
exponent: 0,
|
|
4364
|
+
rounded: roundDecimal(value, fractionDigits)
|
|
4365
|
+
};
|
|
4366
|
+
let exponent = integerDigits > 1 ? Math.floor(value.exponent / integerDigits) * integerDigits : value.exponent;
|
|
4367
|
+
if (!hasIntegerPattern) exponent++;
|
|
4368
|
+
let rounded = roundDecimal(shiftDecimal(value, -exponent), fractionDigits);
|
|
4369
|
+
if (integerDigits === 1 && rounded.integer.length > 1) {
|
|
4370
|
+
exponent++;
|
|
4371
|
+
rounded = roundDecimal(shiftDecimal(value, -exponent), fractionDigits);
|
|
4372
|
+
}
|
|
4373
|
+
return {
|
|
4374
|
+
exponent,
|
|
4375
|
+
rounded
|
|
4376
|
+
};
|
|
4377
|
+
}
|
|
4378
|
+
|
|
4379
|
+
//#endregion
|
|
4380
|
+
//#region src/shared/numfmt/code-to-locale.ts
|
|
4381
|
+
/**
|
|
4382
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
4383
|
+
*
|
|
4384
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4385
|
+
* you may not use this file except in compliance with the License.
|
|
4386
|
+
* You may obtain a copy of the License at
|
|
4387
|
+
*
|
|
4388
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4389
|
+
*
|
|
4390
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
4391
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4392
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4393
|
+
* See the License for the specific language governing permissions and
|
|
4394
|
+
* limitations under the License.
|
|
4395
|
+
*/
|
|
4396
|
+
const codeToLocale = Object.freeze({
|
|
4397
|
+
1078: "af",
|
|
4398
|
+
1052: "sq",
|
|
4399
|
+
1118: "am",
|
|
4400
|
+
5121: "ar_DZ",
|
|
4401
|
+
15361: "ar_BH",
|
|
4402
|
+
3073: "ar_EG",
|
|
4403
|
+
2049: "ar_IQ",
|
|
4404
|
+
11265: "ar_JO",
|
|
4405
|
+
13313: "ar_KW",
|
|
4406
|
+
12289: "ar_LB",
|
|
4407
|
+
4097: "ar_LY",
|
|
4408
|
+
6145: "ar_MA",
|
|
4409
|
+
8193: "ar_OM",
|
|
4410
|
+
16385: "ar_QA",
|
|
4411
|
+
1025: "ar_SA",
|
|
4412
|
+
10241: "ar_SY",
|
|
4413
|
+
7169: "ar_TN",
|
|
4414
|
+
14337: "ar_AE",
|
|
4415
|
+
9217: "ar_YE",
|
|
4416
|
+
1067: "hy",
|
|
4417
|
+
1101: "as",
|
|
4418
|
+
2092: "az_AZ",
|
|
4419
|
+
1068: "az_AZ",
|
|
4420
|
+
1069: "eu",
|
|
4421
|
+
1059: "be",
|
|
4422
|
+
2117: "bn",
|
|
4423
|
+
1093: "bn_IN",
|
|
4424
|
+
5146: "bs",
|
|
4425
|
+
1026: "bg",
|
|
4426
|
+
1109: "my",
|
|
4427
|
+
1027: "ca",
|
|
4428
|
+
2052: "zh_CN",
|
|
4429
|
+
3076: "zh_HK",
|
|
4430
|
+
5124: "zh_MO",
|
|
4431
|
+
4100: "zh_SG",
|
|
4432
|
+
1028: "zh_TW",
|
|
4433
|
+
1050: "hr",
|
|
4434
|
+
1029: "cs",
|
|
4435
|
+
1030: "da",
|
|
4436
|
+
1125: "dv",
|
|
4437
|
+
2067: "nl_BE",
|
|
4438
|
+
1043: "nl_NL",
|
|
4439
|
+
1126: "bin",
|
|
4440
|
+
3081: "en_AU",
|
|
4441
|
+
10249: "en_BZ",
|
|
4442
|
+
4105: "en_CA",
|
|
4443
|
+
9225: "en_CB",
|
|
4444
|
+
2057: "en_GB",
|
|
4445
|
+
16393: "en_IN",
|
|
4446
|
+
6153: "en_IE",
|
|
4447
|
+
8201: "en_JM",
|
|
4448
|
+
5129: "en_NZ",
|
|
4449
|
+
13321: "en_PH",
|
|
4450
|
+
7177: "en_ZA",
|
|
4451
|
+
11273: "en_TT",
|
|
4452
|
+
1033: "en_US",
|
|
4453
|
+
12297: "en_ZW",
|
|
4454
|
+
1061: "et",
|
|
4455
|
+
1071: "mk",
|
|
4456
|
+
1080: "fo",
|
|
4457
|
+
1065: "fa",
|
|
4458
|
+
1124: "fil",
|
|
4459
|
+
1035: "fi",
|
|
4460
|
+
2060: "fr_BE",
|
|
4461
|
+
11276: "fr_CM",
|
|
4462
|
+
3084: "fr_CA",
|
|
4463
|
+
9228: "fr_CG",
|
|
4464
|
+
12300: "fr_CI",
|
|
4465
|
+
1036: "fr_FR",
|
|
4466
|
+
5132: "fr_LU",
|
|
4467
|
+
13324: "fr_ML",
|
|
4468
|
+
6156: "fr_MC",
|
|
4469
|
+
14348: "fr_MA",
|
|
4470
|
+
10252: "fr_SN",
|
|
4471
|
+
4108: "fr_CH",
|
|
4472
|
+
7180: "fr",
|
|
4473
|
+
1122: "fy_NL",
|
|
4474
|
+
2108: "gd_IE",
|
|
4475
|
+
1084: "gd",
|
|
4476
|
+
1110: "gl",
|
|
4477
|
+
1079: "ka",
|
|
4478
|
+
3079: "de_AT",
|
|
4479
|
+
1031: "de_DE",
|
|
4480
|
+
5127: "de_LI",
|
|
4481
|
+
4103: "de_LU",
|
|
4482
|
+
2055: "de_CH",
|
|
4483
|
+
1032: "el",
|
|
4484
|
+
1140: "gn",
|
|
4485
|
+
1095: "gu",
|
|
4486
|
+
1279: "en",
|
|
4487
|
+
1037: "he",
|
|
4488
|
+
1081: "hi",
|
|
4489
|
+
1038: "hu",
|
|
4490
|
+
1039: "is",
|
|
4491
|
+
1136: "ig_NG",
|
|
4492
|
+
1057: "id",
|
|
4493
|
+
1040: "it_IT",
|
|
4494
|
+
2064: "it_CH",
|
|
4495
|
+
1041: "ja",
|
|
4496
|
+
1099: "kn",
|
|
4497
|
+
1120: "ks",
|
|
4498
|
+
1087: "kk",
|
|
4499
|
+
1107: "km",
|
|
4500
|
+
1111: "kok",
|
|
4501
|
+
1042: "ko",
|
|
4502
|
+
1088: "ky",
|
|
4503
|
+
1108: "lo",
|
|
4504
|
+
1142: "la",
|
|
4505
|
+
1062: "lv",
|
|
4506
|
+
1063: "lt",
|
|
4507
|
+
2110: "ms_BN",
|
|
4508
|
+
1086: "ms_MY",
|
|
4509
|
+
1100: "ml",
|
|
4510
|
+
1082: "mt",
|
|
4511
|
+
1112: "mni",
|
|
4512
|
+
1153: "mi",
|
|
4513
|
+
1102: "mr",
|
|
4514
|
+
1104: "mn",
|
|
4515
|
+
2128: "mn",
|
|
4516
|
+
1121: "ne",
|
|
4517
|
+
1044: "no_NO",
|
|
4518
|
+
2068: "no_NO",
|
|
4519
|
+
1096: "or",
|
|
4520
|
+
1045: "pl",
|
|
4521
|
+
1046: "pt_BR",
|
|
4522
|
+
2070: "pt_PT",
|
|
4523
|
+
1094: "pa",
|
|
4524
|
+
1047: "rm",
|
|
4525
|
+
2072: "ro_MO",
|
|
4526
|
+
1048: "ro_RO",
|
|
4527
|
+
1049: "ru",
|
|
4528
|
+
2073: "ru_MO",
|
|
4529
|
+
1083: "se",
|
|
4530
|
+
1103: "sa",
|
|
4531
|
+
3098: "sr_SP",
|
|
4532
|
+
2074: "sr_SP",
|
|
4533
|
+
1072: "st",
|
|
4534
|
+
1074: "tn",
|
|
4535
|
+
1113: "sd",
|
|
4536
|
+
1115: "si",
|
|
4537
|
+
1051: "sk",
|
|
4538
|
+
1060: "sl",
|
|
4539
|
+
1143: "so",
|
|
4540
|
+
1070: "sb",
|
|
4541
|
+
11274: "es_AR",
|
|
4542
|
+
16394: "es_BO",
|
|
4543
|
+
13322: "es_CL",
|
|
4544
|
+
9226: "es_CO",
|
|
4545
|
+
5130: "es_CR",
|
|
4546
|
+
7178: "es_DO",
|
|
4547
|
+
12298: "es_EC",
|
|
4548
|
+
17418: "es_SV",
|
|
4549
|
+
4106: "es_GT",
|
|
4550
|
+
18442: "es_HN",
|
|
4551
|
+
2058: "es_MX",
|
|
4552
|
+
19466: "es_NI",
|
|
4553
|
+
6154: "es_PA",
|
|
4554
|
+
15370: "es_PY",
|
|
4555
|
+
10250: "es_PE",
|
|
4556
|
+
20490: "es_PR",
|
|
4557
|
+
1034: "es_ES",
|
|
4558
|
+
14346: "es_UY",
|
|
4559
|
+
8202: "es_VE",
|
|
4560
|
+
1089: "sw",
|
|
4561
|
+
2077: "sv_FI",
|
|
4562
|
+
1053: "sv_SE",
|
|
4563
|
+
1114: "syc",
|
|
4564
|
+
1064: "tg",
|
|
4565
|
+
1097: "ta",
|
|
4566
|
+
1092: "tt",
|
|
4567
|
+
1098: "te",
|
|
4568
|
+
1054: "th",
|
|
4569
|
+
1105: "bo",
|
|
4570
|
+
1073: "ts",
|
|
4571
|
+
1055: "tr",
|
|
4572
|
+
1090: "tk",
|
|
4573
|
+
1058: "uk",
|
|
4574
|
+
1056: "ur",
|
|
4575
|
+
2115: "uz_UZ",
|
|
4576
|
+
1091: "uz_UZ",
|
|
4577
|
+
1075: "ve",
|
|
4578
|
+
1066: "vi",
|
|
4579
|
+
1106: "cy",
|
|
4580
|
+
1076: "xh",
|
|
4581
|
+
1085: "yi",
|
|
4582
|
+
1077: "zu"
|
|
4583
|
+
});
|
|
4584
|
+
|
|
4585
|
+
//#endregion
|
|
4586
|
+
//#region src/shared/numfmt/locale.ts
|
|
4587
|
+
const re_locale = /^([a-z\d]+)(?:[_-]([a-z\d]+))?(?:\.([a-z\d]+))?(?:@([a-z\d]+))?$/i;
|
|
4588
|
+
const locales = {};
|
|
4589
|
+
/**
|
|
4590
|
+
* Split a semicolon delimited string and replace instances of characters
|
|
4591
|
+
* @ignore
|
|
4592
|
+
* @param {string} str Semicolon delimited string
|
|
4593
|
+
* @param {string} [tilde] String to be inserted on every instance of ~
|
|
4594
|
+
* @returns {string[]} Array of strings
|
|
4595
|
+
*/
|
|
4596
|
+
const _ = (str, tilde = "") => str.replace(/~/g, tilde).split(";");
|
|
4597
|
+
const xm = (o, ml = 0, dl = 0) => {
|
|
4598
|
+
if (!o.mmm) o.mmm = ml < 1 ? o.mmmm.concat() : o.mmmm.map((d) => {
|
|
4599
|
+
const s = d.slice(0, ml % 10);
|
|
4600
|
+
return s + (ml < 10 || d === s ? "" : ".");
|
|
4601
|
+
});
|
|
4602
|
+
if (!o.ddd) o.ddd = dl < 1 ? o.dddd.concat() : o.dddd.map((d) => {
|
|
4603
|
+
const s = d.slice(0, dl % 10);
|
|
4604
|
+
return s + (dl < 10 || d === s ? "" : ".");
|
|
4605
|
+
});
|
|
4606
|
+
if (!o.mmm6 && o.mmmm6) o.mmm6 = o.mmmm6;
|
|
4607
|
+
return o;
|
|
4608
|
+
};
|
|
4609
|
+
/**
|
|
4610
|
+
* @typedef {object} LocaleData
|
|
4611
|
+
* An object of properties used by a formatter when printing a number in a certain locale.
|
|
4612
|
+
* @property {string} group - Symbol used as a grouping separator (`1,000,000` uses `,`)
|
|
4613
|
+
* @property {string} decimal - Symbol used to separate integers from fractions (usually `.`)
|
|
4614
|
+
* @property {string} positive - Symbol used to indicate positive numbers (usually `+`)
|
|
4615
|
+
* @property {string} negative - Symbol used to indicate positive numbers (usually `-`)
|
|
4616
|
+
* @property {string} percent - Symbol used to indicate a percentage (usually `%`)
|
|
4617
|
+
* @property {string} exponent - Symbol used to indicate an exponent (usually `E`)
|
|
4618
|
+
* @property {string} nan - Symbol used to indicate NaN values (`NaN`)
|
|
4619
|
+
* @property {string} infinity - Symbol used to indicate infinite values (`∞`)
|
|
4620
|
+
* @property {Array<string>} ampm - How AM and PM should be presented
|
|
4621
|
+
* @property {Array<string>} mmmm6 - Long month names for the Islamic calendar (`Rajab`)
|
|
4622
|
+
* @property {Array<string>} mmm6 - Short month names for the Islamic calendar (`Raj.`)
|
|
4623
|
+
* @property {Array<string>} mmmm - Long month names for the Gregorian calendar (`November`)
|
|
4624
|
+
* @property {Array<string>} mmm - Short month names for the Gregorian calendar (`Nov`)
|
|
4625
|
+
* @property {Array<string>} dddd - Long day names (`Wednesday`)
|
|
4626
|
+
* @property {Array<string>} ddd - Shortened day names (`Wed`)
|
|
4627
|
+
* @property {Array<string>} bool - How TRUE and FALSE should be presented
|
|
4628
|
+
* @property {boolean} preferMDY - Is the prefered date format month first (12/31/2025) or day first (31/12/2025)
|
|
4629
|
+
*/
|
|
4630
|
+
/**
|
|
4631
|
+
* @ignore
|
|
4632
|
+
* @type {LocaleData}
|
|
4633
|
+
*/
|
|
4634
|
+
const baseLocaleData = {
|
|
4635
|
+
group: "\xA0",
|
|
4636
|
+
decimal: ".",
|
|
4637
|
+
positive: "+",
|
|
4638
|
+
negative: "-",
|
|
4639
|
+
percent: "%",
|
|
4640
|
+
exponent: "E",
|
|
4641
|
+
nan: "NaN",
|
|
4642
|
+
infinity: "∞",
|
|
4643
|
+
ampm: _("AM;PM"),
|
|
4644
|
+
mmmm6: _("Muharram;Safar;Rabiʻ I;Rabiʻ II;Jumada I;Jumada II;Rajab;Shaʻban;Ramadan;Shawwal;Dhuʻl-Qiʻdah;Dhuʻl-Hijjah"),
|
|
4645
|
+
mmm6: _("Muh.;Saf.;Rab. I;Rab. II;Jum. I;Jum. II;Raj.;Sha.;Ram.;Shaw.;Dhuʻl-Q.;Dhuʻl-H."),
|
|
4646
|
+
mmmm: _("January;February;March;April;May;June;July;August;September;October;November;December"),
|
|
4647
|
+
mmm: _("Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec"),
|
|
4648
|
+
dddd: _("Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday"),
|
|
4649
|
+
ddd: _("Sun;Mon;Tue;Wed;Thu;Fri;Sat"),
|
|
4650
|
+
bool: _("TRUE;FALSE"),
|
|
4651
|
+
preferMDY: false
|
|
4652
|
+
};
|
|
4653
|
+
/**
|
|
4654
|
+
* @typedef {object} LocaleToken - An object of properties for a locale tag.
|
|
4655
|
+
* @property {string} lang - The basic tag such as `zh_CN` or `fi`
|
|
4656
|
+
* @property {string} language - The language section (`zh` for `zh_CN`)
|
|
4657
|
+
* @property {string} territory - The territory section (`CN` for `zh_CN`)
|
|
4658
|
+
*/
|
|
4659
|
+
/**
|
|
4660
|
+
* Parse a regular IETF BCP 47 locale tag and emit an object of its parts.
|
|
4661
|
+
* Irregular tags and subtags are not supported.
|
|
4662
|
+
*
|
|
4663
|
+
* @param {string} locale - A BCP 47 string tag of the locale.
|
|
4664
|
+
* @returns {LocaleToken} - An object describing the locale.
|
|
4665
|
+
*/
|
|
4666
|
+
function parseLocale(locale) {
|
|
4667
|
+
const lm = re_locale.exec(locale);
|
|
4668
|
+
if (!lm) throw new SyntaxError(`Malformed locale: ${locale}`);
|
|
4669
|
+
return {
|
|
4670
|
+
lang: lm[1] + (lm[2] ? `_${lm[2]}` : ""),
|
|
4671
|
+
language: lm[1],
|
|
4672
|
+
territory: lm[2] || ""
|
|
4673
|
+
};
|
|
4674
|
+
}
|
|
4675
|
+
function resolveLocale(locale) {
|
|
4676
|
+
if (typeof locale === "number") return codeToLocale[locale & 65535] || null;
|
|
4677
|
+
const wincode = Number.parseInt(locale, 16);
|
|
4678
|
+
if (Number.isFinite(wincode) && codeToLocale[wincode & 65535]) return codeToLocale[wincode & 65535] || null;
|
|
4679
|
+
if (re_locale.test(locale)) return locale;
|
|
4680
|
+
return null;
|
|
4681
|
+
}
|
|
4682
|
+
/**
|
|
4683
|
+
* Used by the formatter to pull a locate from its registered locales. If
|
|
4684
|
+
* subtag isn't available but the base language is, the base language is used.
|
|
4685
|
+
* So if `en-CA` is not found, the formatter tries to find `en` else it
|
|
4686
|
+
* returns a `null`.
|
|
4687
|
+
*
|
|
4688
|
+
* @param {string} locale - A BCP 47 string tag of the locale, or an Excel locale code.
|
|
4689
|
+
* @returns {LocaleData | null} - An object of format date properties.
|
|
4690
|
+
*/
|
|
4691
|
+
function getLocale(locale) {
|
|
4692
|
+
const tag = resolveLocale(locale);
|
|
4693
|
+
let obj = null;
|
|
4694
|
+
if (tag) {
|
|
4695
|
+
const c = parseLocale(tag);
|
|
4696
|
+
obj = locales[c.lang] || locales[c.language] || null;
|
|
4697
|
+
}
|
|
4698
|
+
return obj;
|
|
4699
|
+
}
|
|
4700
|
+
function createLocale(settings) {
|
|
4701
|
+
return Object.assign({}, baseLocaleData, settings);
|
|
4702
|
+
}
|
|
4703
|
+
/**
|
|
4704
|
+
* Register locale data for a language so for use when formatting.
|
|
4705
|
+
*
|
|
4706
|
+
* Any partial set of properties may be returned to have the defaults used where properties are missing.
|
|
4707
|
+
*
|
|
4708
|
+
* @see {LocaleData}
|
|
4709
|
+
* @param {object} settings - A collection of settings for a locale.
|
|
4710
|
+
* @param {string} [settings.group]
|
|
4711
|
+
* Symbol used as a grouping separator (`1,000,000` uses `,`)
|
|
4712
|
+
* @param {string} [settings.decimal]
|
|
4713
|
+
* Symbol used to separate integers from fractions (usually `.`)
|
|
4714
|
+
* @param {string} [settings.positive]
|
|
4715
|
+
* Symbol used to indicate positive numbers (usually `+`)
|
|
4716
|
+
* @param {string} [settings.negative]
|
|
4717
|
+
* Symbol used to indicate positive numbers (usually `-`)
|
|
4718
|
+
* @param {string} [settings.percent]
|
|
4719
|
+
* Symbol used to indicate a percentage (usually `%`)
|
|
4720
|
+
* @param {string} [settings.exponent]
|
|
4721
|
+
* Symbol used to indicate an exponent (usually `E`)
|
|
4722
|
+
* @param {string} [settings.nan]
|
|
4723
|
+
* Symbol used to indicate NaN values (`NaN`)
|
|
4724
|
+
* @param {string} [settings.infinity]
|
|
4725
|
+
* Symbol used to indicate infinite values (`∞`)
|
|
4726
|
+
* @param {Array<string>} [settings.ampm]
|
|
4727
|
+
* How AM and PM should be presented.
|
|
4728
|
+
* @param {Array<string>} [settings.mmmm6]
|
|
4729
|
+
* Long month names for the Islamic calendar (e.g. `Rajab`)
|
|
4730
|
+
* @param {Array<string>} [settings.mmm6]
|
|
4731
|
+
* Short month names for the Islamic calendar (e.g. `Raj.`)
|
|
4732
|
+
* @param {Array<string>} [settings.mmmm]
|
|
4733
|
+
* Long month names for the Gregorian calendar (e.g. `November`)
|
|
4734
|
+
* @param {Array<string>} [settings.mmm]
|
|
4735
|
+
* Short month names for the Gregorian calendar (e.g. `Nov`)
|
|
4736
|
+
* @param {Array<string>} [settings.dddd]
|
|
4737
|
+
* Long day names (e.g. `Wednesday`)
|
|
4738
|
+
* @param {Array<string>} [settings.ddd]
|
|
4739
|
+
* Shortened day names (e.g. `Wed`)
|
|
4740
|
+
* @param {Array<string>} [settings.bool]
|
|
4741
|
+
* How TRUE and FALSE should be presented.
|
|
4742
|
+
* @param {boolean} [settings.preferMDY]
|
|
4743
|
+
* Is the prefered date format month first (12/31/2025) or day first (31/12/2025)
|
|
4744
|
+
* @param {string | LocaleToken} locale - A string BCP 47 tag or parsed locale token.
|
|
4745
|
+
* @returns {LocaleData} - A full collection of settings for a locale
|
|
4746
|
+
*/
|
|
4747
|
+
function addLocale(settings, locale) {
|
|
4748
|
+
const c = typeof locale === "object" ? locale : parseLocale(locale);
|
|
4749
|
+
locales[c.lang] = createLocale(settings);
|
|
4750
|
+
if (c.language !== c.lang && !locales[c.language]) locales[c.language] = createLocale(settings);
|
|
4751
|
+
return locales[c.lang];
|
|
4752
|
+
}
|
|
4753
|
+
const defaultLocale = createLocale({
|
|
4754
|
+
group: ",",
|
|
4755
|
+
preferMDY: true
|
|
4756
|
+
});
|
|
4757
|
+
defaultLocale.isDefault = true;
|
|
4758
|
+
addLocale({
|
|
4759
|
+
group: ",",
|
|
4760
|
+
ampm: _("上午;下午"),
|
|
4761
|
+
mmmm: _("一月;二月;三月;四月;五月;六月;七月;八月;九月;十月;十一月;十二月"),
|
|
4762
|
+
mmm: _("1月;2月;3月;4月;5月;6月;7月;8月;9月;10月;11月;12月"),
|
|
4763
|
+
dddd: _("~日;~一;~二;~三;~四;~五;~六", "星期"),
|
|
4764
|
+
ddd: _("周日;周一;周二;周三;周四;周五;周六")
|
|
4765
|
+
}, "zh_CN");
|
|
4766
|
+
const _zh = {
|
|
4767
|
+
group: ",",
|
|
4768
|
+
ampm: _("上午;下午"),
|
|
4769
|
+
mmmm: _("1月;2月;3月;4月;5月;6月;7月;8月;9月;10月;11月;12月"),
|
|
4770
|
+
mmm: _("1月;2月;3月;4月;5月;6月;7月;8月;9月;10月;11月;12月"),
|
|
4771
|
+
dddd: _("~日;~一;~二;~三;~四;~五;~六", "星期"),
|
|
4772
|
+
ddd: _("周日;周一;周二;周三;周四;周五;周六")
|
|
4773
|
+
};
|
|
4774
|
+
addLocale({
|
|
4775
|
+
..._zh,
|
|
4776
|
+
nan: "非數值",
|
|
4777
|
+
dddd: _("~日;~一;~二;~三;~四;~五;~六", "星期")
|
|
4778
|
+
}, "zh_TW");
|
|
4779
|
+
addLocale({
|
|
4780
|
+
..._zh,
|
|
4781
|
+
dddd: _("~日;~一;~二;~三;~四;~五;~六", "星期")
|
|
4782
|
+
}, "zh_HK");
|
|
4783
|
+
addLocale({
|
|
4784
|
+
..._zh,
|
|
4785
|
+
ampm: _("午前;午後"),
|
|
4786
|
+
dddd: _("日~;月~;火~;水~;木~;金~;土~", "曜日"),
|
|
4787
|
+
ddd: _("日;月;火;水;木;金;土")
|
|
4788
|
+
}, "ja");
|
|
4789
|
+
addLocale({
|
|
4790
|
+
group: ",",
|
|
4791
|
+
ampm: _("오전;오후"),
|
|
4792
|
+
mmmm: _("1월;2월;3월;4월;5월;6월;7월;8월;9월;10월;11월;12월"),
|
|
4793
|
+
mmm: _("1월;2월;3월;4월;5월;6월;7월;8월;9월;10월;11월;12월"),
|
|
4794
|
+
dddd: _("일요일;월요일;화요일;수요일;목요일;금요일;토요일"),
|
|
4795
|
+
ddd: _("일;월;화;수;목;금;토")
|
|
4796
|
+
}, "ko");
|
|
4797
|
+
addLocale({
|
|
4798
|
+
group: ",",
|
|
4799
|
+
ampm: _("ก่อนเที่ยง;หลังเที่ยง"),
|
|
4800
|
+
mmmm: _("มกร~;กุมภาพันธ์;มีน~;เมษายน;พฤษภ~;มิถุนายน;กรกฎ~;สิงห~;กันยายน;ตุล~;พฤศจิกายน;ธันว~", "าคม"),
|
|
4801
|
+
mmm: _("ม.ค.;ก.พ.;มี.ค.;เม.ย.;พ.ค.;มิ.ย.;ก.ค.;ส.ค.;ก.ย.;ต.ค.;พ.ย.;ธ.ค."),
|
|
4802
|
+
dddd: _("วันอาทิตย์;วันจันทร์;วันอังคาร;วันพุธ;วันพฤหัสบดี;วันศุกร์;วันเสาร์"),
|
|
4803
|
+
ddd: _("อา.;จ.;อ.;พ.;พฤ.;ศ.;ส.")
|
|
4804
|
+
}, "th");
|
|
4805
|
+
addLocale(xm({
|
|
4806
|
+
decimal: ",",
|
|
4807
|
+
ampm: _("dop.;odp."),
|
|
4808
|
+
mmmm: _("ledna;února;března;dubna;května;června;července;srpna;září;října;listopadu;prosince"),
|
|
4809
|
+
mmm: _("I;II;III;IV;V;VI;VII;VIII;IX;X;XI;XII"),
|
|
4810
|
+
dddd: _("neděle;pondělí;úterý;středa;čtvrtek;pátek;sobota"),
|
|
4811
|
+
bool: _("PRAVDA;NEPRAVDA")
|
|
4812
|
+
}, -1, 2), "cs");
|
|
4813
|
+
addLocale(xm({
|
|
4814
|
+
group: ".",
|
|
4815
|
+
decimal: ",",
|
|
4816
|
+
mmmm: _("januar;februar;marts;april;maj;juni;juli;august;september;oktober;november;december"),
|
|
4817
|
+
dddd: _("søn~;man~;tirs~;ons~;tors~;fre~;lør~", "dag"),
|
|
4818
|
+
bool: _("SAND;FALSK")
|
|
4819
|
+
}, 13, 13), "da");
|
|
4820
|
+
addLocale(xm({
|
|
4821
|
+
group: ".",
|
|
4822
|
+
decimal: ",",
|
|
4823
|
+
ampm: _("a.m.;p.m."),
|
|
4824
|
+
mmmm: _("januari;februari;maart;april;mei;juni;juli;augustus;september;oktober;november;december"),
|
|
4825
|
+
mmm: _("jan.;feb.;mrt.;apr.;mei;jun.;jul.;aug.;sep.;okt.;nov.;dec."),
|
|
4826
|
+
dddd: _("zondag;maandag;dinsdag;woensdag;donderdag;vrijdag;zaterdag"),
|
|
4827
|
+
bool: _("WAAR;ONWAAR")
|
|
4828
|
+
}, -1, 2), "nl");
|
|
4829
|
+
addLocale({
|
|
4830
|
+
group: ",",
|
|
4831
|
+
preferMDY: true
|
|
4832
|
+
}, "en");
|
|
4833
|
+
addLocale({
|
|
4834
|
+
group: ",",
|
|
4835
|
+
preferMDY: true
|
|
4836
|
+
}, "en_US");
|
|
4837
|
+
addLocale({ group: "," }, "en_AU");
|
|
4838
|
+
addLocale({ group: "," }, "en_CA");
|
|
4839
|
+
addLocale({ group: "," }, "en_GB");
|
|
4840
|
+
addLocale({
|
|
4841
|
+
group: ",",
|
|
4842
|
+
mmm: _("Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sept;Oct;Nov;Dec")
|
|
4843
|
+
}, "en_IE");
|
|
4844
|
+
addLocale(xm({
|
|
4845
|
+
decimal: ",",
|
|
4846
|
+
nan: "epäluku",
|
|
4847
|
+
ampm: _("ap.;ip."),
|
|
4848
|
+
mmmm: _("tammi~;helmi~;maalis~;huhti~;touko~;kesä~;heinä~;elo~;syys~;loka~;marras~;joulu~", "kuuta"),
|
|
4849
|
+
mmm: _("tammik.;helmik.;maalisk.;huhtik.;toukok.;kesäk.;heinäk.;elok.;syysk.;lokak.;marrask.;jouluk."),
|
|
4850
|
+
dddd: _("sunnun~;maanan~;tiis~;keskiviikkona;tors~;perjan~;lauan~", "taina"),
|
|
4851
|
+
bool: _("TOSI;EPÄTOSI")
|
|
4852
|
+
}, -1, 2), "fi");
|
|
4853
|
+
const _fr = xm({
|
|
4854
|
+
group: " ",
|
|
4855
|
+
decimal: ",",
|
|
4856
|
+
mmmm: _("janvier;février;mars;avril;mai;juin;juillet;août;septembre;octobre;novembre;décembre"),
|
|
4857
|
+
mmm: _("janv.;févr.;mars;avr.;mai;juin;juil.;août;sept.;oct.;nov.;déc."),
|
|
4858
|
+
dddd: _("~manche;lun~;mar~;mercre~;jeu~;vendre~;same~", "di"),
|
|
4859
|
+
bool: _("VRAI;FAUX")
|
|
4860
|
+
}, -1, 13);
|
|
4861
|
+
addLocale({ ..._fr }, "fr");
|
|
4862
|
+
addLocale({
|
|
4863
|
+
..._fr,
|
|
4864
|
+
mmm: _("janv.;févr.;mars;avr.;mai;juin;juill.;août;sept.;oct.;nov.;déc.")
|
|
4865
|
+
}, "fr_CA");
|
|
4866
|
+
addLocale({
|
|
4867
|
+
group: "'",
|
|
4868
|
+
decimal: ".",
|
|
4869
|
+
..._fr
|
|
4870
|
+
}, "fr_CH");
|
|
4871
|
+
const _de = xm({
|
|
4872
|
+
mmmm: _("Januar;Februar;März;April;Mai;Juni;Juli;August;September;Oktober;November;Dezember"),
|
|
4873
|
+
mmm: _("Jan.;Feb.;März;Apr.;Mai;Juni;Juli;Aug.;Sept.;Okt.;Nov.;Dez."),
|
|
4874
|
+
dddd: _("Sonn~;Mon~;Diens~;Mittwoch;Donners~;Frei~;Sams~", "tag"),
|
|
4875
|
+
bool: _("WAHR;FALSCH")
|
|
4876
|
+
}, -1, 12);
|
|
4877
|
+
addLocale({
|
|
4878
|
+
group: ".",
|
|
4879
|
+
decimal: ",",
|
|
4880
|
+
..._de
|
|
4881
|
+
}, "de");
|
|
4882
|
+
addLocale({
|
|
4883
|
+
group: "'",
|
|
4884
|
+
decimal: ".",
|
|
4885
|
+
..._de
|
|
4886
|
+
}, "de_CH");
|
|
4887
|
+
addLocale(xm({
|
|
4888
|
+
group: ".",
|
|
4889
|
+
decimal: ",",
|
|
4890
|
+
ampm: _("π.μ.;μ.μ."),
|
|
4891
|
+
mmmm: _("Ιανουαρ~;Φεβρουαρ~;Μαρτ~;Απριλ~;Μαΐου;Ιουν~;Ιουλ~;Αυγούστου;Σεπτεμβρ~;Οκτωβρ~;Νοεμβρ~;Δεκεμβρ~", "ίου"),
|
|
4892
|
+
mmm: _("Ιαν;Φεβ;Μαρ;Απρ;Μαΐ;Ιουν;Ιουλ;Αυγ;Σεπ;Οκτ;Νοε;Δεκ"),
|
|
4893
|
+
dddd: _("Κυριακή;Δευτέρα;Τρίτη;Τετάρτη;Πέμπτη;Παρασκευή;Σάββατο")
|
|
4894
|
+
}, -1, 3), "el");
|
|
4895
|
+
addLocale({
|
|
4896
|
+
decimal: ",",
|
|
4897
|
+
ampm: _("de.;du."),
|
|
4898
|
+
mmmm: _("január;február;március;április;május;június;július;augusztus;szeptember;október;november;december"),
|
|
4899
|
+
mmm: _("jan.;febr.;márc.;ápr.;máj.;jún.;júl.;aug.;szept.;okt.;nov.;dec."),
|
|
4900
|
+
dddd: _("vasárnap;hétfő;kedd;szerda;csütörtök;péntek;szombat"),
|
|
4901
|
+
ddd: _("V;H;K;Sze;Cs;P;Szo"),
|
|
4902
|
+
bool: _("IGAZ;HAMIS")
|
|
4903
|
+
}, "hu");
|
|
4904
|
+
addLocale(xm({
|
|
4905
|
+
group: ".",
|
|
4906
|
+
decimal: ",",
|
|
4907
|
+
ampm: _("f.h.;e.h."),
|
|
4908
|
+
mmmm: _("janúar;febrúar;mars;apríl;maí;júní;júlí;ágúst;september;október;nóvember;desember"),
|
|
4909
|
+
dddd: _("sunnu~;mánu~;þriðju~;miðviku~;fimmtu~;föstu~;laugar~", "dagur")
|
|
4910
|
+
}, 13, 13), "is");
|
|
4911
|
+
addLocale(xm({
|
|
4912
|
+
group: ".",
|
|
4913
|
+
decimal: ",",
|
|
4914
|
+
mmmm: _("Januari;Februari;Maret;April;Mei;Juni;Juli;Agustus;September;Oktober;November;Desember"),
|
|
4915
|
+
dddd: _("Minggu;Senin;Selasa;Rabu;Kamis;Jumat;Sabtu")
|
|
4916
|
+
}, 3, 3), "id");
|
|
4917
|
+
const _it = xm({
|
|
4918
|
+
mmmm: _("gennaio;febbraio;marzo;aprile;maggio;giugno;luglio;agosto;settembre;ottobre;novembre;dicembre"),
|
|
4919
|
+
dddd: _("domenica;lunedì;martedì;mercoledì;giovedì;venerdì;sabato"),
|
|
4920
|
+
bool: _("VERO;FALSO")
|
|
4921
|
+
}, 3, 3);
|
|
4922
|
+
addLocale({
|
|
4923
|
+
group: ".",
|
|
4924
|
+
decimal: ",",
|
|
4925
|
+
..._it
|
|
4926
|
+
}, "it");
|
|
4927
|
+
addLocale({
|
|
4928
|
+
group: "'",
|
|
4929
|
+
decimal: ".",
|
|
4930
|
+
..._it
|
|
4931
|
+
}, "it_CH");
|
|
4932
|
+
const _no = {
|
|
4933
|
+
decimal: ",",
|
|
4934
|
+
ampm: _("a.m.;p.m."),
|
|
4935
|
+
mmmm: _("januar;februar;mars;april;mai;juni;juli;august;september;oktober;november;desember"),
|
|
4936
|
+
mmm: _("jan.;feb.;mar.;apr.;mai;jun.;jul.;aug.;sep.;okt.;nov.;des."),
|
|
4937
|
+
dddd: _("søn~;man~;tirs~;ons~;tors~;fre~;lør~", "dag"),
|
|
4938
|
+
bool: _("SANN;USANN")
|
|
4939
|
+
};
|
|
4940
|
+
addLocale(xm({ ..._no }, -1, 13), "nb");
|
|
4941
|
+
addLocale(xm({ ..._no }, -1, 13), "no");
|
|
4942
|
+
addLocale(xm({
|
|
4943
|
+
decimal: ",",
|
|
4944
|
+
mmmm: _("stycznia;lutego;marca;kwietnia;maja;czerwca;lipca;sierpnia;września;października;listopada;grudnia"),
|
|
4945
|
+
dddd: _("niedziela;poniedziałek;wtorek;środa;czwartek;piątek;sobota"),
|
|
4946
|
+
ddd: _("niedz.;pon.;wt.;śr.;czw.;pt.;sob."),
|
|
4947
|
+
bool: _("PRAWDA;FAŁSZ")
|
|
4948
|
+
}, 3, -1), "pl");
|
|
4949
|
+
const _pt = {
|
|
4950
|
+
group: ".",
|
|
4951
|
+
decimal: ",",
|
|
4952
|
+
mmmm: _("janeiro;fevereiro;março;abril;maio;junho;julho;agosto;setembro;outubro;novembro;dezembro"),
|
|
4953
|
+
dddd: _("domingo;segunda-feira;terça-feira;quarta-feira;quinta-feira;sexta-feira;sábado"),
|
|
4954
|
+
bool: _("VERDADEIRO;FALSO")
|
|
4955
|
+
};
|
|
4956
|
+
addLocale(xm(_pt, 13, 13), "pt");
|
|
4957
|
+
addLocale(xm(_pt, 13, 13), "pt_BR");
|
|
4958
|
+
addLocale({
|
|
4959
|
+
decimal: ",",
|
|
4960
|
+
nan: "не\xA0число",
|
|
4961
|
+
mmmm: _("января;февраля;марта;апреля;мая;июня;июля;августа;сентября;октября;ноября;декабря"),
|
|
4962
|
+
mmm: _("янв.;февр.;мар.;апр.;мая;июн.;июл.;авг.;сент.;окт.;нояб.;дек."),
|
|
4963
|
+
dddd: _("воскресенье;понедельник;вторник;среда;четверг;пятница;суббота"),
|
|
4964
|
+
ddd: _("вс;пн;вт;ср;чт;пт;сб"),
|
|
4965
|
+
mmmm6: _("рамадан;шавваль;зуль-каада;зуль-хиджжа;мухаррам;раби-уль-авваль;раби-уль-ахир;джумад-уль-авваль;джумад-уль-ахир;раджаб;шаабан;рамадан"),
|
|
4966
|
+
mmm6: _("рам.;шав.;зуль-к.;зуль-х.;мух.;раб. I;раб. II;джум. I;джум. II;радж.;шааб.;рам."),
|
|
4967
|
+
bool: _("ИСТИНА;ЛОЖЬ")
|
|
4968
|
+
}, "ru");
|
|
4969
|
+
addLocale(xm({
|
|
4970
|
+
decimal: ",",
|
|
4971
|
+
mmmm: _("januára;februára;marca;apríla;mája;júna;júla;augusta;septembra;októbra;novembra;decembra"),
|
|
4972
|
+
dddd: _("nedeľa;pondelok;utorok;streda;štvrtok;piatok;sobota")
|
|
4973
|
+
}, 3, 2), "sk");
|
|
4974
|
+
const _es = {
|
|
4975
|
+
group: ".",
|
|
4976
|
+
decimal: ",",
|
|
4977
|
+
ampm: _("a.\xA0m.;p.\xA0m."),
|
|
4978
|
+
mmmm: _("enero;febrero;marzo;abril;mayo;junio;julio;agosto;septiem~;octu~;noviem~;diciem~", "bre"),
|
|
4979
|
+
mmm: _("ene;feb;mar;abr;may;jun;jul;ago;sept;oct;nov;dic"),
|
|
4980
|
+
dddd: _("domingo;lunes;martes;miércoles;jueves;viernes;sábado"),
|
|
4981
|
+
ddd: _("dom;lun;mar;mié;jue;vie;sáb"),
|
|
4982
|
+
bool: _("VERDADERO;FALSO")
|
|
4983
|
+
};
|
|
4984
|
+
const _esM3 = _("ene;feb;mar;abr;may;jun;jul;ago;sep;oct;nov;dic");
|
|
4985
|
+
const _esM13 = _("ene.;feb.;mar.;abr.;may.;jun.;jul.;ago.;sept.;oct.;nov.;dic.");
|
|
4986
|
+
addLocale({ ..._es }, "es");
|
|
4987
|
+
addLocale({ ..._es }, "es_AR");
|
|
4988
|
+
addLocale({ ..._es }, "es_BO");
|
|
4989
|
+
addLocale({ ..._es }, "es_CL");
|
|
4990
|
+
addLocale({ ..._es }, "es_CO");
|
|
4991
|
+
addLocale({ ..._es }, "es_EC");
|
|
4992
|
+
addLocale({
|
|
4993
|
+
..._es,
|
|
4994
|
+
mmm: _esM3,
|
|
4995
|
+
ampm: _("a.m.;p.m.")
|
|
4996
|
+
}, "es_MX");
|
|
4997
|
+
addLocale({
|
|
4998
|
+
..._es,
|
|
4999
|
+
mmm: _esM13
|
|
5000
|
+
}, "es_PY");
|
|
5001
|
+
addLocale({
|
|
5002
|
+
..._es,
|
|
5003
|
+
mmm: _esM13
|
|
5004
|
+
}, "es_UY");
|
|
5005
|
+
addLocale({
|
|
5006
|
+
..._es,
|
|
5007
|
+
mmm: _esM13,
|
|
5008
|
+
mmmm: _("enero;febrero;marzo;abril;mayo;junio;julio;agosto;setiembre;octubre;noviembre;diciembre")
|
|
5009
|
+
}, "es_VE");
|
|
5010
|
+
addLocale({
|
|
5011
|
+
decimal: ",",
|
|
5012
|
+
ampm: _("fm;em"),
|
|
5013
|
+
mmmm: _("januari;februari;mars;april;maj;juni;juli;augusti;september;oktober;november;december"),
|
|
5014
|
+
mmm: _("jan.;feb.;mars;apr.;maj;juni;juli;aug.;sep.;okt.;nov.;dec."),
|
|
5015
|
+
dddd: _("sön~;mån~;tis~;ons~;tors~;fre~;lör~", "dag"),
|
|
5016
|
+
ddd: _("sön;mån;tis;ons;tors;fre;lör")
|
|
5017
|
+
}, "sv");
|
|
5018
|
+
addLocale(xm({
|
|
5019
|
+
group: ".",
|
|
5020
|
+
decimal: ",",
|
|
5021
|
+
ampm: _("ÖÖ;ÖS"),
|
|
5022
|
+
mmmm: _("Ocak;Şubat;Mart;Nisan;Mayıs;Haziran;Temmuz;Ağustos;Eylül;Ekim;Kasım;Aralık"),
|
|
5023
|
+
mmm: _("Oca;Şub;Mar;Nis;May;Haz;Tem;Ağu;Eyl;Eki;Kas;Ara"),
|
|
5024
|
+
dddd: _("Pazar;Pazartesi;Salı;Çarşamba;Perşembe;Cuma;Cumartesi"),
|
|
5025
|
+
ddd: _("Paz;Pzt;Sal;Çar;Per;Cum;Cmt"),
|
|
5026
|
+
bool: _("DOĞRU;YANLIŞ")
|
|
5027
|
+
}, 3, -1), "tr");
|
|
5028
|
+
addLocale({
|
|
5029
|
+
group: ",",
|
|
5030
|
+
ampm: _("yb;yh"),
|
|
5031
|
+
mmmm: _("Ionawr;Chwefror;Mawrth;Ebrill;Mai;Mehefin;Gorffennaf;Awst;Medi;Hydref;Tachwedd;Rhagfyr"),
|
|
5032
|
+
mmm: _("Ion;Chwef;Maw;Ebr;Mai;Meh;Gorff;Awst;Medi;Hyd;Tach;Rhag"),
|
|
5033
|
+
dddd: _("Dydd Sul;Dydd Llun;Dydd Mawrth;Dydd Mercher;Dydd Iau;Dydd Gwener;Dydd Sadwrn"),
|
|
5034
|
+
ddd: _("Sul;Llun;Maw;Mer;Iau;Gwen;Sad")
|
|
5035
|
+
}, "cy");
|
|
5036
|
+
addLocale({
|
|
5037
|
+
group: ".",
|
|
5038
|
+
decimal: ",",
|
|
5039
|
+
mmmm: _("yanvar;fevral;mart;aprel;may;iyun;iyul;avqust;sentyabr;oktyabr;noyabr;dekabr"),
|
|
5040
|
+
mmm: _("yan;fev;mar;apr;may;iyn;iyl;avq;sen;okt;noy;dek"),
|
|
5041
|
+
dddd: _("bazar;bazar ertəsi;çərşənbə axşamı;çərşənbə;cümə axşamı;cümə;şənbə"),
|
|
5042
|
+
ddd: _("B.;B.e.;Ç.a.;Ç.;C.a.;C.;Ş.")
|
|
5043
|
+
}, "az");
|
|
5044
|
+
addLocale(xm({
|
|
5045
|
+
decimal: ",",
|
|
5046
|
+
mmmm: _("студзеня;лютага;сакавіка;красавіка;мая;чэрвеня;ліпеня;жніўня;верасня;кастрычніка;лістапада;снежня"),
|
|
5047
|
+
dddd: _("нядзеля;панядзелак;аўторак;серада;чацвер;пятніца;субота"),
|
|
5048
|
+
ddd: _("нд;пн;аў;ср;чц;пт;сб")
|
|
5049
|
+
}, 3, -1), "be");
|
|
5050
|
+
addLocale({
|
|
5051
|
+
decimal: ",",
|
|
5052
|
+
ampm: _("пр.об.;сл.об."),
|
|
5053
|
+
mmmm: _("януари;февруари;март;април;май;юни;юли;август;септември;октомври;ноември;декември"),
|
|
5054
|
+
mmm: _("яну;фев;март;апр;май;юни;юли;авг;сеп;окт;ное;дек"),
|
|
5055
|
+
dddd: _("неделя;понеделник;вторник;сряда;четвъртък;петък;събота"),
|
|
5056
|
+
ddd: _("нд;пн;вт;ср;чт;пт;сб"),
|
|
5057
|
+
bool: _("ИСТИНА;ЛОЖЬ")
|
|
5058
|
+
}, "bg");
|
|
5059
|
+
addLocale({
|
|
5060
|
+
group: ".",
|
|
5061
|
+
decimal: ",",
|
|
5062
|
+
mmmm: _("de gener;de febrer;de març;d’abril;de maig;de juny;de juliol;d’agost;de setembre;d’octubre;de novembre;de desembre"),
|
|
5063
|
+
mmm: _("de gen.;de febr.;de març;d’abr.;de maig;de juny;de jul.;d’ag.;de set.;d’oct.;de nov.;de des."),
|
|
5064
|
+
dddd: _("diumenge;dilluns;dimarts;dimecres;dijous;divendres;dissabte"),
|
|
5065
|
+
ddd: _("dg.;dl.;dt.;dc.;dj.;dv.;ds."),
|
|
5066
|
+
ampm: _("a.\xA0m.;p.\xA0m.")
|
|
5067
|
+
}, "ca");
|
|
5068
|
+
addLocale(xm({
|
|
5069
|
+
group: ",",
|
|
5070
|
+
decimal: ".",
|
|
5071
|
+
mmmm: _("Enero;Pebrero;Marso;Abril;Mayo;Hunyo;Hulyo;Agosto;Setyembre;Oktubre;Nobyembre;Disyembre"),
|
|
5072
|
+
dddd: _("Linggo;Lunes;Martes;Miyerkules;Huwebes;Biyernes;Sabado")
|
|
5073
|
+
}, 3, 3), "fil");
|
|
5074
|
+
addLocale({
|
|
5075
|
+
group: ",",
|
|
5076
|
+
decimal: ".",
|
|
5077
|
+
mmmm: _("જાન્યુઆરી;ફેબ્રુઆરી;માર્ચ;એપ્રિલ;મે;જૂન;જુલાઈ;ઑગસ્ટ;સપ્ટેમ્બર;ઑક્ટોબર;નવેમ્બર;ડિસેમ્બર"),
|
|
5078
|
+
mmm: _("જાન્યુ;ફેબ્રુ;માર્ચ;એપ્રિલ;મે;જૂન;જુલાઈ;ઑગસ્ટ;સપ્ટે;ઑક્ટો;નવે;ડિસે"),
|
|
5079
|
+
dddd: _("રવિ~;સોમ~;મંગળ~;બુધ~;ગુરુ~;શુક્ર~;શનિ~", "વાર"),
|
|
5080
|
+
ddd: _("રવિ;સોમ;મંગળ;બુધ;ગુરુ;શુક્ર;શનિ")
|
|
5081
|
+
}, "gu");
|
|
5082
|
+
addLocale({
|
|
5083
|
+
group: ",",
|
|
5084
|
+
decimal: ".",
|
|
5085
|
+
ampm: _("לפנה״צ;אחה״צ"),
|
|
5086
|
+
dddd: _("~ראשון;~שני;~שלישי;~רביעי;~חמישי;~שישי;~שבת", "יום "),
|
|
5087
|
+
ddd: _("~א׳;~ב׳;~ג׳;~ד׳;~ה׳;~ו׳;שבת", "יום "),
|
|
5088
|
+
mmmm: _("ינואר;פברואר;מרץ;אפריל;מאי;יוני;יולי;אוגוסט;ספטמבר;אוקטובר;נובמבר;דצמבר"),
|
|
5089
|
+
mmm: _("ינו׳;פבר׳;מרץ;אפר׳;מאי;יוני;יולי;אוג׳;ספט׳;אוק׳;נוב׳;דצמ׳"),
|
|
5090
|
+
mmmm6: _("רמדאן;שוואל;ד׳ו אל־קעדה;ד׳ו אל־חיג׳ה;מוחרם;רביע אל־אוול;רביע א־ת׳אני;ג׳ומאדא אל־אולא;ג׳ומאדא א־ת׳אניה;רג׳ב;שעבאן;רמדאן"),
|
|
5091
|
+
mmm6: _("רמדאן;שוואל;ד׳ו אל־קעדה;ד׳ו אל־חיג׳ה;מוחרם;רביע א׳;רביע ב׳;ג׳ומאדא א׳;ג׳ומאדא ב׳;רג׳ב;שעבאן;רמדאן")
|
|
5092
|
+
}, "he");
|
|
5093
|
+
addLocale(xm({
|
|
5094
|
+
group: ".",
|
|
5095
|
+
decimal: ",",
|
|
5096
|
+
mmmm: _("siječnja;veljače;ožujka;travnja;svibnja;lipnja;srpnja;kolovoza;rujna;listopada;studenoga;prosinca"),
|
|
5097
|
+
mmm: _("sij;velj;ožu;tra;svi;lip;srp;kol;ruj;lis;stu;pro"),
|
|
5098
|
+
dddd: _("nedjelja;ponedjeljak;utorak;srijeda;četvrtak;petak;subota")
|
|
5099
|
+
}, -1, 3), "hr");
|
|
5100
|
+
addLocale({
|
|
5101
|
+
decimal: ",",
|
|
5102
|
+
mmmm: _("հունվարի;փետրվարի;մարտի;ապրիլի;մայիսի;հունիսի;հուլիսի;օգոստոսի;սեպտեմբերի;հոկտեմբերի;նոյեմբերի;դեկտեմբերի"),
|
|
5103
|
+
mmm: _("հնվ;փտվ;մրտ;ապր;մյս;հնս;հլս;օգս;սեպ;հոկ;նոյ;դեկ"),
|
|
5104
|
+
dddd: _("կիրակի;երկուշաբթի;երեքշաբթի;չորեքշաբթի;հինգշաբթի;ուրբաթ;շաբաթ"),
|
|
5105
|
+
ddd: _("կիր;երկ;երք;չրք;հնգ;ուր;շբթ")
|
|
5106
|
+
}, "hy");
|
|
5107
|
+
addLocale(xm({
|
|
5108
|
+
decimal: ",",
|
|
5109
|
+
mmmm: _("იანვარი;თებერვალი;მარტი;აპრილი;მაისი;ივნისი;ივლისი;აგვისტო;სექტემბერი;ოქტომბერი;ნოემბერი;დეკემბერი"),
|
|
5110
|
+
dddd: _("კვირა;ორშაბათი;სამშაბათი;ოთხშაბათი;ხუთშაბათი;პარასკევი;შაბათი")
|
|
5111
|
+
}, 3, 3), "ka");
|
|
5112
|
+
addLocale(xm({
|
|
5113
|
+
decimal: ",",
|
|
5114
|
+
mmmm: _("қаңтар;ақпан;наурыз;сәуір;мамыр;маусым;шілде;тамыз;қыркүйек;қазан;қараша;желтоқсан"),
|
|
5115
|
+
dddd: _("жексенбі;дүйсенбі;сейсенбі;сәрсенбі;бейсенбі;жұма;сенбі"),
|
|
5116
|
+
ddd: _("жс;дс;сс;ср;бс;жм;сб")
|
|
5117
|
+
}, 13, -1), "kk");
|
|
5118
|
+
addLocale({
|
|
5119
|
+
group: ",",
|
|
5120
|
+
mmmm: _("ಜನವರಿ;ಫೆಬ್ರವರಿ;ಮಾರ್ಚ್;ಏಪ್ರಿಲ್;ಮೇ;ಜೂನ್;ಜುಲೈ;ಆಗಸ್ಟ್;ಸೆಪ್ಟೆಂಬರ್;ಅಕ್ಟೋಬರ್;ನವೆಂಬರ್;ಡಿಸೆಂಬರ್"),
|
|
5121
|
+
mmm: _("ಜನವರಿ;ಫೆಬ್ರವರಿ;ಮಾರ್ಚ್;ಏಪ್ರಿ;ಮೇ;ಜೂನ್;ಜುಲೈ;ಆಗಸ್ಟ್;ಸೆಪ್ಟೆಂ;ಅಕ್ಟೋ;ನವೆಂ;ಡಿಸೆಂ"),
|
|
5122
|
+
dddd: _("ಭಾನು~;ಸೋಮ~;ಮಂಗಳ~;ಬುಧ~;ಗುರು~;ಶುಕ್ರ~;ಶನಿ~", "ವಾರ"),
|
|
5123
|
+
ddd: _("ಭಾನು;ಸೋಮ;ಮಂಗಳ;ಬುಧ;ಗುರು;ಶುಕ್ರ;ಶನಿ"),
|
|
5124
|
+
ampm: _("ಪೂರ್ವಾಹ್ನ;ಅಪರಾಹ್ನ")
|
|
5125
|
+
}, "kn");
|
|
5126
|
+
addLocale({
|
|
5127
|
+
decimal: ",",
|
|
5128
|
+
mmmm: _("sausio;vasario;kovo;balandžio;gegužės;birželio;liepos;rugpjūčio;rugsėjo;spalio;lapkričio;gruodžio"),
|
|
5129
|
+
mmm: _("saus.;vas.;kov.;bal.;geg.;birž.;liep.;rugp.;rugs.;spal.;lapkr.;gruod."),
|
|
5130
|
+
dddd: _("sekmadienis;pirmadienis;antradienis;trečiadienis;ketvirtadienis;penktadienis;šeštadienis"),
|
|
5131
|
+
ddd: _("sk;pr;an;tr;kt;pn;št"),
|
|
5132
|
+
ampm: _("priešpiet;popiet")
|
|
5133
|
+
}, "lt");
|
|
5134
|
+
addLocale({
|
|
5135
|
+
decimal: ",",
|
|
5136
|
+
mmmm: _("janvāris;februāris;marts;aprīlis;maijs;jūnijs;jūlijs;augusts;septembris;oktobris;novembris;decembris"),
|
|
5137
|
+
mmm: _("janv.;febr.;marts;apr.;maijs;jūn.;jūl.;aug.;sept.;okt.;nov.;dec."),
|
|
5138
|
+
dddd: _("svētdiena;pirmdiena;otrdiena;trešdiena;ceturtdiena;piektdiena;sestdiena"),
|
|
5139
|
+
ddd: _("svētd.;pirmd.;otrd.;trešd.;ceturtd.;piektd.;sestd."),
|
|
5140
|
+
ampm: _("priekšpusdienā;pēcpusdienā")
|
|
5141
|
+
}, "lv");
|
|
5142
|
+
addLocale({
|
|
5143
|
+
group: ",",
|
|
5144
|
+
decimal: ".",
|
|
5145
|
+
mmmm: _("ജനുവരി;ഫെബ്രുവരി;മാർച്ച്;ഏപ്രിൽ;മേയ്;ജൂൺ;ജൂലൈ;ഓഗസ്റ്റ്;സെപ്റ്റംബർ;ഒക്ടോബർ;നവംബർ;ഡിസംബർ"),
|
|
5146
|
+
mmm: _("ജനു;ഫെബ്രു;മാർ;ഏപ്രി;മേയ്;ജൂൺ;ജൂലൈ;ഓഗ;സെപ്റ്റം;ഒക്ടോ;നവം;ഡിസം"),
|
|
5147
|
+
dddd: _("ഞായറാഴ്ച;തിങ്കളാഴ്ച;ചൊവ്വാഴ്ച;ബുധനാഴ്ച;വ്യാഴാഴ്ച;വെള്ളിയാഴ്ച;ശനിയാഴ്ച"),
|
|
5148
|
+
ddd: _("ഞായർ;തിങ്കൾ;ചൊവ്വ;ബുധൻ;വ്യാഴം;വെള്ളി;ശനി")
|
|
5149
|
+
}, "ml");
|
|
5150
|
+
addLocale({
|
|
5151
|
+
group: ",",
|
|
5152
|
+
decimal: ".",
|
|
5153
|
+
mmmm: _("нэгдүгээ~;хоёрдугаа~;гуравдугаа~;дөрөвдүгээ~;тавдугаа~;зургаадугаа~;долоодугаа~;наймдугаа~;есдүгээ~;аравдугаа~;арван нэгдүгээ~;арван хоёрдугаа~", "р сар"),
|
|
5154
|
+
mmm: _("1~;2~;3~;4~;5~;6~;7~;8~;9~;10~;11~;12~", "-р сар"),
|
|
5155
|
+
dddd: _("ням;даваа;мягмар;лхагва;пүрэв;баасан;бямба"),
|
|
5156
|
+
ddd: _("Ня;Да;Мя;Лх;Пү;Ба;Бя"),
|
|
5157
|
+
ampm: _("ү.ө.;ү.х.")
|
|
5158
|
+
}, "mn");
|
|
5159
|
+
addLocale({
|
|
5160
|
+
group: ",",
|
|
5161
|
+
decimal: ".",
|
|
5162
|
+
mmmm: _("जानेवारी;फेब्रुवारी;मार्च;एप्रिल;मे;जून;जुलै;ऑगस्ट;सप्टेंबर;ऑक्टोबर;नोव्हेंबर;डिसेंबर"),
|
|
5163
|
+
mmm: _("जाने;फेब्रु;मार्च;एप्रि;मे;जून;जुलै;ऑग;सप्टें;ऑक्टो;नोव्हें;डिसें"),
|
|
5164
|
+
dddd: _("रविवार;सोमवार;मंगळवार;बुधवार;गुरुवार;शुक्रवार;शनिवार"),
|
|
5165
|
+
ddd: _("रवि;सोम;मंगळ;बुध;गुरु;शुक्र;शनि")
|
|
5166
|
+
}, "mr");
|
|
5167
|
+
addLocale(xm({
|
|
5168
|
+
group: ",",
|
|
5169
|
+
decimal: ".",
|
|
5170
|
+
mmmm: _("ဇန်နဝါရီ;ဖေဖော်ဝါရီ;မတ်;ဧပြီ;မေ;ဇွန်;ဇူလိုင်;ဩဂုတ်;စက်တင်ဘာ;အောက်တိုဘာ;နိုဝင်ဘာ;ဒီဇင်ဘာ"),
|
|
5171
|
+
mmm: _("ဇန်;ဖေ;မတ်;ဧ;မေ;ဇွန်;ဇူ;ဩ;စက်;အောက်;နို;ဒီ"),
|
|
5172
|
+
dddd: _("တနင်္ဂနွေ;တနင်္လာ;အင်္ဂါ;ဗုဒ္ဓဟူး;ကြာသပတေး;သောကြာ;စနေ"),
|
|
5173
|
+
ampm: _("နံနက်;ညနေ")
|
|
5174
|
+
}, -1, 0), "my");
|
|
5175
|
+
addLocale({
|
|
5176
|
+
group: ",",
|
|
5177
|
+
decimal: ".",
|
|
5178
|
+
mmmm: _("ਜਨਵਰੀ;ਫ਼ਰਵਰੀ;ਮਾਰਚ;ਅਪ੍ਰੈਲ;ਮਈ;ਜੂਨ;ਜੁਲਾਈ;ਅਗਸਤ;ਸਤੰਬਰ;ਅਕਤੂਬਰ;ਨਵੰਬਰ;ਦਸੰਬਰ"),
|
|
5179
|
+
mmm: _("ਜਨ;ਫ਼ਰ;ਮਾਰਚ;ਅਪ੍ਰੈ;ਮਈ;ਜੂਨ;ਜੁਲਾ;ਅਗ;ਸਤੰ;ਅਕਤੂ;ਨਵੰ;ਦਸੰ"),
|
|
5180
|
+
dddd: _("ਐਤਵਾਰ;ਸੋਮਵਾਰ;ਮੰਗਲਵਾਰ;ਬੁੱਧਵਾਰ;ਵੀਰਵਾਰ;ਸ਼ੁੱਕਰਵਾਰ;ਸ਼ਨਿੱਚਰਵਾਰ"),
|
|
5181
|
+
ddd: _("ਐਤ;ਸੋਮ;ਮੰਗਲ;ਬੁੱਧ;ਵੀਰ;ਸ਼ੁੱਕਰ;ਸ਼ਨਿੱਚਰ"),
|
|
5182
|
+
ampm: _("ਪੂ.ਦੁ.;ਬਾ.ਦੁ.")
|
|
5183
|
+
}, "pa");
|
|
5184
|
+
addLocale({
|
|
5185
|
+
group: ".",
|
|
5186
|
+
decimal: ",",
|
|
5187
|
+
mmmm: _("ianuarie;februarie;martie;aprilie;mai;iunie;iulie;august;septem~;octom~;noiem~;decem~", "brie"),
|
|
5188
|
+
mmm: _("ian.;feb.;mar.;apr.;mai;iun.;iul.;aug.;sept.;oct.;nov.;dec."),
|
|
5189
|
+
dddd: _("duminică;luni;marți;miercuri;joi;vineri;sâmbătă"),
|
|
5190
|
+
ddd: _("dum.;lun.;mar.;mie.;joi;vin.;sâm."),
|
|
5191
|
+
ampm: _("a.m.;p.m.")
|
|
5192
|
+
}, "ro");
|
|
5193
|
+
addLocale(xm({
|
|
5194
|
+
group: ".",
|
|
5195
|
+
decimal: ",",
|
|
5196
|
+
mmmm: _("januar;februar;marec;april;maj;junij;julij;avgust;september;oktober;november;december"),
|
|
5197
|
+
mmm: _("jan.;feb.;mar.;apr.;maj;jun.;jul.;avg.;sep.;okt.;nov.;dec."),
|
|
5198
|
+
dddd: _("nedelja;ponedeljek;torek;sreda;četrtek;petek;sobota"),
|
|
5199
|
+
ampm: _("dop.;pop.")
|
|
5200
|
+
}, -1, 13), "sl");
|
|
5201
|
+
addLocale(xm({
|
|
5202
|
+
group: ".",
|
|
5203
|
+
decimal: ",",
|
|
5204
|
+
mmmm: _("јануар;фебруар;март;април;мај;јун;јул;август;септембар;октобар;новембар;децембар"),
|
|
5205
|
+
dddd: _("недеља;понедељак;уторак;среда;четвртак;петак;субота")
|
|
5206
|
+
}, 3, 3), "sr");
|
|
5207
|
+
addLocale({
|
|
5208
|
+
group: ",",
|
|
5209
|
+
decimal: ".",
|
|
5210
|
+
mmmm: _("ஜனவரி;பிப்ரவரி;மார்ச்;ஏப்ரல்;மே;ஜூன்;ஜூலை;ஆகஸ்ட்;செப்டம்பர்;அக்டோபர்;நவம்பர்;டிசம்பர்"),
|
|
5211
|
+
mmm: _("ஜன.;பிப்.;மார்.;ஏப்.;மே;ஜூன்;ஜூலை;ஆக.;செப்.;அக்.;நவ.;டிச."),
|
|
5212
|
+
dddd: _("ஞாயிறு;திங்கள்;செவ்வாய்;புதன்;வியாழன்;வெள்ளி;சனி"),
|
|
5213
|
+
ddd: _("ஞாயி.;திங்.;செவ்.;புத.;வியா.;வெள்.;சனி")
|
|
5214
|
+
}, "ta");
|
|
5215
|
+
addLocale({
|
|
5216
|
+
group: ",",
|
|
5217
|
+
decimal: ".",
|
|
5218
|
+
mmmm: _("జనవరి;ఫిబ్రవరి;మార్చి;ఏప్రిల్;మే;జూన్;జులై;ఆగస్టు;సెప్టెంబర్;అక్టోబర్;నవంబర్;డిసెంబర్"),
|
|
5219
|
+
mmm: _("జన;ఫిబ్ర;మార్చి;ఏప్రి;మే;జూన్;జులై;ఆగ;సెప్టెం;అక్టో;నవం;డిసెం"),
|
|
5220
|
+
dddd: _("ఆదివారం;సోమవారం;మంగళవారం;బుధవారం;గురువారం;శుక్రవారం;శనివారం"),
|
|
5221
|
+
ddd: _("ఆది;సోమ;మంగళ;బుధ;గురు;శుక్ర;శని")
|
|
5222
|
+
}, "te");
|
|
5223
|
+
addLocale({
|
|
5224
|
+
decimal: ",",
|
|
5225
|
+
mmmm: _("січня;лютого;березня;квітня;травня;червня;липня;серпня;вересня;жовтня;листопада;грудня"),
|
|
5226
|
+
mmm: _("січ.;лют.;бер.;квіт.;трав.;черв.;лип.;серп.;вер.;жовт.;лист.;груд."),
|
|
5227
|
+
dddd: _("неділю;понеділок;вівторок;середу;четвер;пʼятницю;суботу"),
|
|
5228
|
+
ddd: _("нд;пн;вт;ср;чт;пт;сб"),
|
|
5229
|
+
ampm: _("дп;пп")
|
|
5230
|
+
}, "uk");
|
|
5231
|
+
addLocale({
|
|
5232
|
+
group: ".",
|
|
5233
|
+
decimal: ",",
|
|
5234
|
+
mmmm: _("~1;~2;~3;~4;~5;~6;~7;~8;~9;~10;~11;~12", "tháng "),
|
|
5235
|
+
mmm: _("~1;~2;~3;~4;~5;~6;~7;~8;~9;~10;~11;~12", "thg "),
|
|
5236
|
+
dddd: _("Chủ Nhật;Thứ Hai;Thứ Ba;Thứ Tư;Thứ Năm;Thứ Sáu;Thứ Bảy"),
|
|
5237
|
+
ddd: _("CN;Th 2;Th 3;Th 4;Th 5;Th 6;Th 7"),
|
|
5238
|
+
ampm: _("SA;CH")
|
|
5239
|
+
}, "vi");
|
|
5240
|
+
addLocale(xm({
|
|
5241
|
+
group: "٬",
|
|
5242
|
+
decimal: "٫",
|
|
5243
|
+
ampm: _("ص;م"),
|
|
5244
|
+
mmmm: _("يناير;فبراير;مارس;أبريل;مايو;يونيو;يوليو;أغسطس;سبتمبر;أكتوبر;نوفمبر;ديسمبر"),
|
|
5245
|
+
dddd: _("الأحد;الاثنين;الثلاثاء;الأربعاء;الخميس;الجمعة;السبت"),
|
|
5246
|
+
mmmm6: _("رمضان;شوال;ذو القعدة;ذو الحجة;محرم;ربيع الأول;ربيع الآخرة;جمادى الأولى;جمادى الآخرة;رجب;شعبان;رمضان")
|
|
5247
|
+
}, 0, 0), "ar");
|
|
5248
|
+
addLocale({
|
|
5249
|
+
group: ",",
|
|
5250
|
+
decimal: ".",
|
|
5251
|
+
mmmm: _("জানুয়ারী;ফেব্রুয়ারী;মার্চ;এপ্রিল;মে;জুন;জুলাই;আগস্ট;সেপ্টেম্বর;অক্টোবর;নভেম্বর;ডিসেম্বর"),
|
|
5252
|
+
mmm: _("জানু;ফেব;মার্চ;এপ্রি;মে;জুন;জুল;আগ;সেপ্টেঃ;অক্টোঃ;নভেঃ;ডিসেঃ"),
|
|
5253
|
+
dddd: _("রবিবার;সোমবার;মঙ্গলবার;বুধবার;বৃহস্পতিবার;শুক্রবার;শনিবার"),
|
|
5254
|
+
ddd: _("রবি;সোম;মঙ্গল;বুধ;বৃহস্পতি;শুক্র;শনি")
|
|
5255
|
+
}, "bn");
|
|
5256
|
+
addLocale({
|
|
5257
|
+
group: ",",
|
|
5258
|
+
decimal: ".",
|
|
5259
|
+
mmmm: _("जनवरी;फ़रवरी;मार्च;अप्रैल;मई;जून;जुलाई;अगस्त;सितंबर;अक्तूबर;नवंबर;दिसंबर"),
|
|
5260
|
+
mmm: _("जन॰;फ़र॰;मार्च;अप्रैल;मई;जून;जुल॰;अग॰;सित॰;अक्तू॰;नव॰;दिस॰"),
|
|
5261
|
+
dddd: _("रविवार;सोमवार;मंगलवार;बुधवार;गुरुवार;शुक्रवार;शनिवार"),
|
|
5262
|
+
ddd: _("रवि;सोम;मंगल;बुध;गुरु;शुक्र;शनि"),
|
|
5263
|
+
ampm: _("am;pm")
|
|
5264
|
+
}, "hi");
|
|
5265
|
+
|
|
5266
|
+
//#endregion
|
|
5267
|
+
//#region src/shared/numfmt/parse-format-section.ts
|
|
5268
|
+
function getNumberPattern(part, prefix) {
|
|
5269
|
+
switch (prefix) {
|
|
5270
|
+
case "int": return part.int_pattern;
|
|
5271
|
+
case "frac": return part.frac_pattern;
|
|
5272
|
+
case "man": return part.man_pattern;
|
|
5273
|
+
case "den": return part.den_pattern;
|
|
5274
|
+
case "num": return part.num_pattern;
|
|
5275
|
+
}
|
|
5276
|
+
}
|
|
5277
|
+
function minMaxPad(str, part, prefix) {
|
|
5278
|
+
const max = str.length;
|
|
5279
|
+
const min = str.replace(/#/g, "").length;
|
|
5280
|
+
switch (prefix) {
|
|
5281
|
+
case "int":
|
|
5282
|
+
part.int_max = max;
|
|
5283
|
+
part.int_min = min;
|
|
5284
|
+
break;
|
|
5285
|
+
case "frac":
|
|
5286
|
+
part.frac_max = max;
|
|
5287
|
+
part.frac_min = min;
|
|
5288
|
+
break;
|
|
5289
|
+
case "man":
|
|
5290
|
+
part.man_max = max;
|
|
5291
|
+
part.man_min = min;
|
|
5292
|
+
break;
|
|
5293
|
+
case "den":
|
|
5294
|
+
part.den_max = max;
|
|
5295
|
+
part.den_min = min;
|
|
5296
|
+
break;
|
|
5297
|
+
case "num":
|
|
5298
|
+
part.num_max = max;
|
|
5299
|
+
part.num_min = min;
|
|
5300
|
+
break;
|
|
5301
|
+
}
|
|
5302
|
+
return part;
|
|
5303
|
+
}
|
|
5304
|
+
function add(token, tokens) {
|
|
5305
|
+
if (typeof token === "string") tokens.push({
|
|
5306
|
+
type: "string",
|
|
5307
|
+
value: token
|
|
5308
|
+
});
|
|
5309
|
+
else tokens.push(token);
|
|
5310
|
+
}
|
|
5311
|
+
function isNumOp$1(token, activePattern) {
|
|
5312
|
+
const type = token === null || token === void 0 ? void 0 : token.type;
|
|
5313
|
+
return type === "hash" || type === "zero" || type === "qmark" || type === "digit" && activePattern === "den";
|
|
5314
|
+
}
|
|
5315
|
+
function assertNumberChunk(token) {
|
|
5316
|
+
if (token === null) throw new TypeError("Cannot read properties of null (reading 'num')");
|
|
5317
|
+
}
|
|
5318
|
+
function parseFormatSection(inputTokens) {
|
|
5319
|
+
const outputTokens = [];
|
|
5320
|
+
const part = {
|
|
5321
|
+
scale: 1,
|
|
5322
|
+
scaleExponent: 0,
|
|
5323
|
+
percent: false,
|
|
5324
|
+
text: false,
|
|
5325
|
+
date: 0,
|
|
5326
|
+
date_eval: false,
|
|
5327
|
+
date_system: 1,
|
|
5328
|
+
sec_decimals: 0,
|
|
5329
|
+
general: false,
|
|
5330
|
+
clock: 24,
|
|
5331
|
+
int_pattern: [],
|
|
5332
|
+
frac_pattern: [],
|
|
5333
|
+
man_pattern: [],
|
|
5334
|
+
den_pattern: [],
|
|
5335
|
+
num_pattern: [],
|
|
5336
|
+
tokens: outputTokens,
|
|
5337
|
+
tokensUsed: 0,
|
|
5338
|
+
pattern: "",
|
|
5339
|
+
int_max: 0,
|
|
5340
|
+
int_min: 0,
|
|
5341
|
+
frac_max: 0,
|
|
5342
|
+
frac_min: 0,
|
|
5343
|
+
man_max: 0,
|
|
5344
|
+
man_min: 0,
|
|
5345
|
+
num_max: 0,
|
|
5346
|
+
num_min: 0,
|
|
5347
|
+
den_max: 0,
|
|
5348
|
+
den_min: 0,
|
|
5349
|
+
int_p: "",
|
|
5350
|
+
man_p: "",
|
|
5351
|
+
num_p: "",
|
|
5352
|
+
den_p: "",
|
|
5353
|
+
integer: false
|
|
5354
|
+
};
|
|
5355
|
+
let currentPattern = "int";
|
|
5356
|
+
let lastNumberChunk = null;
|
|
5357
|
+
const dateChunks = [];
|
|
5358
|
+
let last;
|
|
5359
|
+
let haveLocale = false;
|
|
5360
|
+
let index = -1;
|
|
5361
|
+
let partOver = false;
|
|
5362
|
+
let patternSource = "";
|
|
5363
|
+
let haveSlash = false;
|
|
5364
|
+
while (++index < inputTokens.length && !partOver) {
|
|
5365
|
+
var _inputTokens;
|
|
5366
|
+
const token = inputTokens[index];
|
|
5367
|
+
const type = token.type || "error";
|
|
5368
|
+
patternSource += token.raw;
|
|
5369
|
+
if (type === "general") {
|
|
5370
|
+
part.general = true;
|
|
5371
|
+
add(token, outputTokens);
|
|
5372
|
+
} else if (isNumOp$1(token, currentPattern)) {
|
|
5373
|
+
const pattern = getNumberPattern(part, currentPattern);
|
|
5374
|
+
if (isNumOp$1(last, currentPattern) || (last === null || last === void 0 ? void 0 : last.type) === "group") {
|
|
5375
|
+
pattern.push((pattern.pop() || "") + token.value);
|
|
5376
|
+
assertNumberChunk(lastNumberChunk);
|
|
5377
|
+
lastNumberChunk.num += token.value;
|
|
5378
|
+
} else {
|
|
5379
|
+
pattern.push(token.value);
|
|
5380
|
+
lastNumberChunk = {
|
|
5381
|
+
type: currentPattern,
|
|
5382
|
+
num: token.value
|
|
5383
|
+
};
|
|
5384
|
+
add(lastNumberChunk, outputTokens);
|
|
5385
|
+
}
|
|
5386
|
+
} else if (type === "paren") {
|
|
5387
|
+
if (token.value === "(") part.parens = true;
|
|
5388
|
+
add(token.value, outputTokens);
|
|
5389
|
+
} else if (type === "digit") add(token.value, outputTokens);
|
|
5390
|
+
else if (type === "slash") {
|
|
5391
|
+
haveSlash = true;
|
|
5392
|
+
const pattern = getNumberPattern(part, currentPattern);
|
|
5393
|
+
if (pattern.length) {
|
|
5394
|
+
if (!lastNumberChunk) throw new SyntaxError("Format pattern is missing a numerator");
|
|
5395
|
+
part.fractions = true;
|
|
5396
|
+
const numerator = pattern.pop();
|
|
5397
|
+
if (numerator === void 0) throw new SyntaxError("Format pattern is missing a numerator");
|
|
5398
|
+
part.num_pattern.push(numerator);
|
|
5399
|
+
lastNumberChunk.type = "num";
|
|
5400
|
+
currentPattern = "den";
|
|
5401
|
+
add({ type: "div" }, outputTokens);
|
|
5402
|
+
} else add(token.value, outputTokens);
|
|
5403
|
+
} else if (type === "comma") add(",", outputTokens);
|
|
5404
|
+
else if (type === "scale") {
|
|
5405
|
+
part.scale = .001 ** token.raw.length;
|
|
5406
|
+
part.scaleExponent = -3 * token.raw.length;
|
|
5407
|
+
} else if (type === "group") {
|
|
5408
|
+
if (currentPattern === "int") part.grouping = true;
|
|
5409
|
+
if (currentPattern === "den") throw new SyntaxError("Cannot group denominator digits");
|
|
5410
|
+
} else if (type === "space") add(token, outputTokens);
|
|
5411
|
+
else if (type === "break") {
|
|
5412
|
+
partOver = true;
|
|
5413
|
+
break;
|
|
5414
|
+
} else if (type === "text") {
|
|
5415
|
+
part.text = true;
|
|
5416
|
+
add(token, outputTokens);
|
|
5417
|
+
} else if (type === "plus" || type === "minus") add(token, outputTokens);
|
|
5418
|
+
else if (type === "duration") {
|
|
5419
|
+
const tokenValue = token.value.toLowerCase();
|
|
5420
|
+
const startsWith = tokenValue[0];
|
|
5421
|
+
const bit = {
|
|
5422
|
+
type: "",
|
|
5423
|
+
size: 0,
|
|
5424
|
+
date: 1,
|
|
5425
|
+
pad: tokenValue.length
|
|
5426
|
+
};
|
|
5427
|
+
if (startsWith === "h") {
|
|
5428
|
+
bit.size = 16;
|
|
5429
|
+
bit.type = "hour-elap";
|
|
5430
|
+
} else if (startsWith === "m") {
|
|
5431
|
+
bit.size = 32;
|
|
5432
|
+
bit.type = "min-elap";
|
|
5433
|
+
} else {
|
|
5434
|
+
bit.size = 64;
|
|
5435
|
+
bit.type = "sec-elap";
|
|
5436
|
+
}
|
|
5437
|
+
part.date = part.date | bit.size;
|
|
5438
|
+
dateChunks.push(bit);
|
|
5439
|
+
add(bit, outputTokens);
|
|
5440
|
+
} else if (part.date && type === "point" && ((_inputTokens = inputTokens[index + 1]) === null || _inputTokens === void 0 ? void 0 : _inputTokens.type) === "zero") {
|
|
5441
|
+
var _inputTokens2, _inputTokens3;
|
|
5442
|
+
let decimals = 1;
|
|
5443
|
+
index++;
|
|
5444
|
+
let raw = "0";
|
|
5445
|
+
if (((_inputTokens2 = inputTokens[index + 1]) === null || _inputTokens2 === void 0 ? void 0 : _inputTokens2.type) === "zero") {
|
|
5446
|
+
raw += "0";
|
|
5447
|
+
decimals = 2;
|
|
5448
|
+
index++;
|
|
5449
|
+
}
|
|
5450
|
+
if (((_inputTokens3 = inputTokens[index + 1]) === null || _inputTokens3 === void 0 ? void 0 : _inputTokens3.type) === "zero") {
|
|
5451
|
+
raw += "0";
|
|
5452
|
+
decimals = 3;
|
|
5453
|
+
index++;
|
|
5454
|
+
}
|
|
5455
|
+
patternSource += raw;
|
|
5456
|
+
const size = [
|
|
5457
|
+
64,
|
|
5458
|
+
128,
|
|
5459
|
+
256,
|
|
5460
|
+
512
|
|
5461
|
+
][decimals];
|
|
5462
|
+
part.date = part.date | size;
|
|
5463
|
+
part.date_eval = true;
|
|
5464
|
+
part.sec_decimals = Math.max(part.sec_decimals, decimals);
|
|
5465
|
+
add({
|
|
5466
|
+
type: "subsec",
|
|
5467
|
+
size,
|
|
5468
|
+
decimals,
|
|
5469
|
+
date: 1
|
|
5470
|
+
}, outputTokens);
|
|
5471
|
+
} else if (type === "calendar") {
|
|
5472
|
+
if (!haveLocale) if (token.value === "B2" || token.value === "b2") part.date_system = 6;
|
|
5473
|
+
else part.date_system = 1;
|
|
5474
|
+
} else if (type === "datetime") {
|
|
5475
|
+
const bit = {
|
|
5476
|
+
type: "",
|
|
5477
|
+
size: 0,
|
|
5478
|
+
date: 1
|
|
5479
|
+
};
|
|
5480
|
+
const value = token.value.toLowerCase();
|
|
5481
|
+
const startsWith = value[0];
|
|
5482
|
+
if (value === "y" || value === "yy") {
|
|
5483
|
+
bit.size = 2;
|
|
5484
|
+
bit.type = "year-short";
|
|
5485
|
+
} else if (startsWith === "y" || startsWith === "e") {
|
|
5486
|
+
bit.size = 2;
|
|
5487
|
+
bit.type = "year";
|
|
5488
|
+
} else if (value === "b" || value === "bb") {
|
|
5489
|
+
bit.size = 2;
|
|
5490
|
+
bit.type = "b-year-short";
|
|
5491
|
+
} else if (startsWith === "b") {
|
|
5492
|
+
bit.size = 2;
|
|
5493
|
+
bit.type = "b-year";
|
|
5494
|
+
} else if (value === "d" || value === "dd") {
|
|
5495
|
+
bit.size = 8;
|
|
5496
|
+
bit.type = "day";
|
|
5497
|
+
bit.pad = /dd/.test(value);
|
|
5498
|
+
} else if (value === "ddd" || value === "aaa") {
|
|
5499
|
+
bit.size = 8;
|
|
5500
|
+
bit.type = "weekday-short";
|
|
5501
|
+
} else if (startsWith === "d" || startsWith === "a") {
|
|
5502
|
+
bit.size = 8;
|
|
5503
|
+
bit.type = "weekday";
|
|
5504
|
+
} else if (startsWith === "h") {
|
|
5505
|
+
bit.size = 16;
|
|
5506
|
+
bit.type = "hour";
|
|
5507
|
+
bit.pad = /hh/i.test(value);
|
|
5508
|
+
} else if (startsWith === "m") {
|
|
5509
|
+
if (value.length === 3) {
|
|
5510
|
+
bit.size = 4;
|
|
5511
|
+
bit.type = "monthname-short";
|
|
5512
|
+
} else if (value.length === 5) {
|
|
5513
|
+
bit.size = 4;
|
|
5514
|
+
bit.type = "monthname-single";
|
|
5515
|
+
} else if (value.length >= 4) {
|
|
5516
|
+
bit.size = 4;
|
|
5517
|
+
bit.type = "monthname";
|
|
5518
|
+
}
|
|
5519
|
+
const lastDateChunk = dateChunks[dateChunks.length - 1];
|
|
5520
|
+
if (!bit.type && lastDateChunk && !lastDateChunk.used && lastDateChunk.size & (16 | 64)) {
|
|
5521
|
+
lastDateChunk.used = true;
|
|
5522
|
+
bit.size = 32;
|
|
5523
|
+
bit.type = "min";
|
|
5524
|
+
bit.pad = /mm/.test(value);
|
|
5525
|
+
}
|
|
5526
|
+
if (!bit.type) {
|
|
5527
|
+
bit.size = 4;
|
|
5528
|
+
bit.type = "month";
|
|
5529
|
+
bit.pad = /mm/.test(value);
|
|
5530
|
+
bit.indeterminate = true;
|
|
5531
|
+
}
|
|
5532
|
+
} else if (startsWith === "s") {
|
|
5533
|
+
bit.size = 64;
|
|
5534
|
+
bit.type = "sec";
|
|
5535
|
+
bit.pad = /ss/.test(value);
|
|
5536
|
+
const lastDateChunk = dateChunks[dateChunks.length - 1];
|
|
5537
|
+
if (lastDateChunk && lastDateChunk.size & 32) bit.used = true;
|
|
5538
|
+
else if (lastDateChunk === null || lastDateChunk === void 0 ? void 0 : lastDateChunk.indeterminate) {
|
|
5539
|
+
delete lastDateChunk.indeterminate;
|
|
5540
|
+
lastDateChunk.size = 32;
|
|
5541
|
+
lastDateChunk.type = "min";
|
|
5542
|
+
bit.used = true;
|
|
5543
|
+
}
|
|
5544
|
+
} else if (startsWith === "g") {}
|
|
5545
|
+
part.date = part.date | bit.size;
|
|
5546
|
+
part.date_eval = true;
|
|
5547
|
+
dateChunks.push(bit);
|
|
5548
|
+
add(bit, outputTokens);
|
|
5549
|
+
} else if (type === "ampm") {
|
|
5550
|
+
part.clock = 12;
|
|
5551
|
+
part.date = part.date | 16;
|
|
5552
|
+
part.date_eval = true;
|
|
5553
|
+
token.short = token.value === "A/P";
|
|
5554
|
+
add(token, outputTokens);
|
|
5555
|
+
} else if (type === "string" || type === "escaped" || type === "char") add(token.value, outputTokens);
|
|
5556
|
+
else if (type === "condition") part.condition = [token.value[0], Number.parseFloat(token.value[1])];
|
|
5557
|
+
else if (type === "locale") {
|
|
5558
|
+
const bits = token.value.split("-");
|
|
5559
|
+
const code = bits.length < 2 ? "" : bits.slice(1).join("-");
|
|
5560
|
+
const currency = bits[0];
|
|
5561
|
+
if (currency) add(currency, outputTokens);
|
|
5562
|
+
const locale = resolveLocale(code);
|
|
5563
|
+
if (locale) part.locale = locale;
|
|
5564
|
+
const windowsCode = Number.parseInt(code, 16);
|
|
5565
|
+
if (Number.isFinite(windowsCode) && windowsCode & 16711680) {
|
|
5566
|
+
if ((windowsCode >> 16 & 255) === 6) part.date_system = 6;
|
|
5567
|
+
}
|
|
5568
|
+
haveLocale = true;
|
|
5569
|
+
} else if (type === "color") {
|
|
5570
|
+
const normalizedColor = token.value.toLowerCase();
|
|
5571
|
+
let color = normalizedColor;
|
|
5572
|
+
const colorMatch = /^color\s*(\d+)$/i.exec(normalizedColor);
|
|
5573
|
+
if (colorMatch) color = Number.parseInt(colorMatch[1], 10);
|
|
5574
|
+
part.color = color;
|
|
5575
|
+
} else if (type === "percent") {
|
|
5576
|
+
part.scale = 100;
|
|
5577
|
+
part.scaleExponent = 2;
|
|
5578
|
+
part.percent = true;
|
|
5579
|
+
add("%", outputTokens);
|
|
5580
|
+
} else if (type === "point") {
|
|
5581
|
+
add(token, outputTokens);
|
|
5582
|
+
if (!part.date) {
|
|
5583
|
+
part.dec_fractions = true;
|
|
5584
|
+
currentPattern = "frac";
|
|
5585
|
+
}
|
|
5586
|
+
} else if (type === "exp") {
|
|
5587
|
+
part.exponential = true;
|
|
5588
|
+
part.exp_plus = token.value.includes("+");
|
|
5589
|
+
currentPattern = "man";
|
|
5590
|
+
add({
|
|
5591
|
+
type: "exp",
|
|
5592
|
+
plus: part.exp_plus
|
|
5593
|
+
}, outputTokens);
|
|
5594
|
+
} else if (type === "skip" || type === "fill") add(token, outputTokens);
|
|
5595
|
+
else if (type === "dbnum" || type === "natnum") {} else if (type === "error") throw new SyntaxError(`Illegal character: ${patternSource}`);
|
|
5596
|
+
else throw new SyntaxError(`Unknown token ${type} in ${patternSource}`);
|
|
5597
|
+
last = token;
|
|
5598
|
+
}
|
|
5599
|
+
part.tokensUsed = index;
|
|
5600
|
+
part.pattern = patternSource;
|
|
5601
|
+
if (/^((?:\[[^\]]+\])+)(;|$)/.test(part.pattern) && !/^\[(?:h+|m+|s+)\]/.test(part.pattern)) add({ type: "text" }, outputTokens);
|
|
5602
|
+
if (part.fractions && part.dec_fractions || part.grouping && !part.int_pattern.length || part.fractions && part.exponential || part.fractions && part.den_pattern.length * part.num_pattern.length === 0 || haveSlash && !part.fractions && !part.date || part.exponential && (part.int_pattern.length || part.frac_pattern.length) * part.man_pattern.length === 0) throw new SyntaxError(`Invalid pattern: ${patternSource}`);
|
|
5603
|
+
const intPattern = part.int_pattern.join("");
|
|
5604
|
+
const manPattern = part.man_pattern.join("");
|
|
5605
|
+
const fracPattern = part.frac_pattern.join("");
|
|
5606
|
+
minMaxPad(intPattern, part, "int");
|
|
5607
|
+
let min = 0;
|
|
5608
|
+
for (let patternIndex = 0; patternIndex < intPattern.length; patternIndex++) {
|
|
5609
|
+
const character = intPattern[intPattern.length - 1 - patternIndex];
|
|
5610
|
+
if (/^[0-9?]/.test(character)) min = patternIndex + 1;
|
|
5611
|
+
}
|
|
5612
|
+
part.int_min = min;
|
|
5613
|
+
minMaxPad(fracPattern, part, "frac");
|
|
5614
|
+
minMaxPad(manPattern, part, "man");
|
|
5615
|
+
let numeratorPattern = part.num_pattern.join("");
|
|
5616
|
+
let denominatorPattern = part.den_pattern[0] || "";
|
|
5617
|
+
if (denominatorPattern.includes("?") || numeratorPattern.includes("?")) {
|
|
5618
|
+
denominatorPattern = denominatorPattern.replace(/\d/g, "?");
|
|
5619
|
+
denominatorPattern = denominatorPattern.replace(/#$/g, "?");
|
|
5620
|
+
minMaxPad(numeratorPattern, part, "num");
|
|
5621
|
+
minMaxPad(denominatorPattern, part, "den");
|
|
5622
|
+
numeratorPattern = numeratorPattern.replace(/#$/g, "?");
|
|
5623
|
+
} else {
|
|
5624
|
+
minMaxPad(numeratorPattern, part, "num");
|
|
5625
|
+
minMaxPad(denominatorPattern, part, "den");
|
|
5626
|
+
}
|
|
5627
|
+
part.int_p = intPattern;
|
|
5628
|
+
part.man_p = manPattern;
|
|
5629
|
+
part.num_p = numeratorPattern;
|
|
5630
|
+
part.den_p = denominatorPattern;
|
|
5631
|
+
if (part.den_pattern.length) part.denominator = Number.parseInt(part.den_pattern.join("").replace(/\D/g, ""), 10);
|
|
5632
|
+
part.integer = !!intPattern.length;
|
|
5633
|
+
if (!part.integer && !part.exponential && fracPattern.length) {
|
|
5634
|
+
const pointIndex = part.tokens.findIndex((token) => token.type === "point");
|
|
5635
|
+
part.tokens.splice(pointIndex, 0, {
|
|
5636
|
+
type: "int",
|
|
5637
|
+
value: "#"
|
|
5638
|
+
});
|
|
5639
|
+
part.integer = true;
|
|
5640
|
+
part.int_pattern = ["#"];
|
|
5641
|
+
part.int_p = "#";
|
|
5642
|
+
}
|
|
5643
|
+
if (part.fractions) for (let tokenIndex = 0; tokenIndex < outputTokens.length - 1; tokenIndex++) {
|
|
5644
|
+
const token = outputTokens[tokenIndex];
|
|
5645
|
+
if (token.type !== "string" && token.type !== "space") continue;
|
|
5646
|
+
const nextType = outputTokens[tokenIndex + 1].type;
|
|
5647
|
+
if (nextType === "num") token.rule = "num+int";
|
|
5648
|
+
else if (nextType === "div") token.rule = "num";
|
|
5649
|
+
else if (nextType === "den") token.rule = "den";
|
|
5650
|
+
}
|
|
5651
|
+
if (part.grouping && part.int_pattern.length > 1) part.grouping = false;
|
|
5652
|
+
return part;
|
|
5653
|
+
}
|
|
5654
|
+
|
|
5655
|
+
//#endregion
|
|
5656
|
+
//#region src/shared/numfmt/clamp.ts
|
|
5657
|
+
/**
|
|
5658
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
5659
|
+
*
|
|
5660
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5661
|
+
* you may not use this file except in compliance with the License.
|
|
5662
|
+
* You may obtain a copy of the License at
|
|
5663
|
+
*
|
|
5664
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5665
|
+
*
|
|
5666
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5667
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5668
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5669
|
+
* See the License for the specific language governing permissions and
|
|
5670
|
+
* limitations under the License.
|
|
5671
|
+
*/
|
|
5672
|
+
function clamp(number) {
|
|
5673
|
+
if (number === 0) return number;
|
|
5674
|
+
const d = Math.ceil(Math.log10(number < 0 ? -number : number));
|
|
5675
|
+
const mag = 10 ** (16 - Math.floor(d));
|
|
5676
|
+
return isFinite(mag) ? Math.round(number * mag) / mag : 0;
|
|
5677
|
+
}
|
|
5678
|
+
|
|
5679
|
+
//#endregion
|
|
5680
|
+
//#region src/shared/numfmt/dec-to-frac.ts
|
|
5681
|
+
/**
|
|
5682
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
5683
|
+
*
|
|
5684
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5685
|
+
* you may not use this file except in compliance with the License.
|
|
5686
|
+
* You may obtain a copy of the License at
|
|
5687
|
+
*
|
|
5688
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5689
|
+
*
|
|
5690
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5691
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5692
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5693
|
+
* See the License for the specific language governing permissions and
|
|
5694
|
+
* limitations under the License.
|
|
5695
|
+
*/
|
|
5696
|
+
const PRECISION = 1e-13;
|
|
5697
|
+
/**
|
|
5698
|
+
* Split a fractional number into a numerator and denominator for display as
|
|
5699
|
+
* vulgar fractions.
|
|
5700
|
+
*
|
|
5701
|
+
* @ignore
|
|
5702
|
+
* @param {number} number The value to split
|
|
5703
|
+
* @param {number} [numeratorMaxDigits] The maxdigits number
|
|
5704
|
+
* @param {number} [denominatorMaxDigits] The maxdigits de
|
|
5705
|
+
* @returns {Array<number>} Array of two numbers, numerator and denominator.
|
|
5706
|
+
*/
|
|
5707
|
+
function dec2frac(number, numeratorMaxDigits = 2, denominatorMaxDigits = 2) {
|
|
5708
|
+
const sign = number < 0 ? -1 : 1;
|
|
5709
|
+
const maxdigits_n = 10 ** (numeratorMaxDigits || 2);
|
|
5710
|
+
const maxdigits_d = 10 ** (denominatorMaxDigits || 2);
|
|
5711
|
+
let z = Math.abs(number);
|
|
5712
|
+
let last_d = 0;
|
|
5713
|
+
let last_n = 0;
|
|
5714
|
+
let curr_n = 0;
|
|
5715
|
+
let curr_d = 1;
|
|
5716
|
+
let tmp;
|
|
5717
|
+
let r;
|
|
5718
|
+
number = z;
|
|
5719
|
+
if (number % 1 === 0) r = [number * sign, 1];
|
|
5720
|
+
else if (number < 1e-19) r = [sign, 0x8ac7230489e80000];
|
|
5721
|
+
else if (number > 0x8ac7230489e80000) r = [0x8ac7230489e80000 * sign, 1];
|
|
5722
|
+
else {
|
|
5723
|
+
do {
|
|
5724
|
+
z = 1 / (z - Math.floor(z));
|
|
5725
|
+
tmp = curr_d;
|
|
5726
|
+
curr_d = curr_d * Math.floor(z) + last_d;
|
|
5727
|
+
last_d = tmp;
|
|
5728
|
+
last_n = curr_n;
|
|
5729
|
+
curr_n = Math.floor(number * curr_d + .5);
|
|
5730
|
+
if (curr_n >= maxdigits_n || curr_d >= maxdigits_d) return [sign * last_n, last_d];
|
|
5731
|
+
} while (Math.abs(number - curr_n / curr_d) >= PRECISION && z !== Math.floor(z));
|
|
5732
|
+
r = [sign * curr_n, curr_d];
|
|
5733
|
+
}
|
|
5734
|
+
return r;
|
|
5735
|
+
}
|
|
5736
|
+
|
|
5737
|
+
//#endregion
|
|
5738
|
+
//#region src/shared/numfmt/num-dec.ts
|
|
5739
|
+
const ZERO_DIGITS = {
|
|
5740
|
+
total: 1,
|
|
5741
|
+
sign: 0,
|
|
5742
|
+
period: 0,
|
|
5743
|
+
int: 1,
|
|
5744
|
+
frac: 0
|
|
5745
|
+
};
|
|
5746
|
+
function numDec(value, includeSign = true) {
|
|
5747
|
+
const decimal = decimalFromNumber(value);
|
|
5748
|
+
if (decimal.digits === "0") return ZERO_DIGITS;
|
|
5749
|
+
const decimalPoint = decimal.exponent + 1;
|
|
5750
|
+
const intSize = Math.max(decimalPoint, 1);
|
|
5751
|
+
const fracSize = Math.max(0, decimal.digits.length - decimalPoint);
|
|
5752
|
+
const signSize = includeSign && decimal.negative ? 1 : 0;
|
|
5753
|
+
const periodSize = fracSize > 0 ? 1 : 0;
|
|
5754
|
+
return {
|
|
5755
|
+
total: signSize + intSize + periodSize + fracSize,
|
|
5756
|
+
digits: Math.max(decimalPoint, 0) + fracSize,
|
|
5757
|
+
sign: signSize,
|
|
5758
|
+
period: periodSize,
|
|
5759
|
+
int: intSize,
|
|
5760
|
+
frac: fracSize
|
|
5761
|
+
};
|
|
5762
|
+
}
|
|
5763
|
+
|
|
5764
|
+
//#endregion
|
|
5765
|
+
//#region src/shared/numfmt/number-props.ts
|
|
5766
|
+
/**
|
|
5767
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
5768
|
+
*
|
|
5769
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5770
|
+
* you may not use this file except in compliance with the License.
|
|
5771
|
+
* You may obtain a copy of the License at
|
|
5772
|
+
*
|
|
5773
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5774
|
+
*
|
|
5775
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5776
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5777
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5778
|
+
* See the License for the specific language governing permissions and
|
|
5779
|
+
* limitations under the License.
|
|
5780
|
+
*/
|
|
5781
|
+
function getExponent(number, intMax = 0) {
|
|
5782
|
+
const exponent = Math.floor(Math.log10(number));
|
|
5783
|
+
return intMax > 1 ? Math.floor(exponent / intMax) * intMax : exponent;
|
|
5784
|
+
}
|
|
5785
|
+
function getSignificand(number, exponent = 1) {
|
|
5786
|
+
if (exponent < -300) return Number.parseFloat(number.toExponential().split("e")[0]);
|
|
5787
|
+
return number * 10 ** -exponent;
|
|
5788
|
+
}
|
|
5789
|
+
|
|
5790
|
+
//#endregion
|
|
5791
|
+
//#region src/shared/numfmt/round.ts
|
|
5792
|
+
/**
|
|
5793
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
5794
|
+
*
|
|
5795
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5796
|
+
* you may not use this file except in compliance with the License.
|
|
5797
|
+
* You may obtain a copy of the License at
|
|
5798
|
+
*
|
|
5799
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5800
|
+
*
|
|
5801
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5802
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5803
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5804
|
+
* See the License for the specific language governing permissions and
|
|
5805
|
+
* limitations under the License.
|
|
5806
|
+
*/
|
|
5807
|
+
function legacyRound$1(number, places = 0) {
|
|
5808
|
+
if (number < 0) return -legacyRound$1(-number, places);
|
|
5809
|
+
if (places) {
|
|
5810
|
+
const power = 10 ** places || 1;
|
|
5811
|
+
return legacyRound$1(number * power, 0) / power;
|
|
5812
|
+
}
|
|
5813
|
+
return Math.round(number);
|
|
5814
|
+
}
|
|
5815
|
+
function round(number, places = 0) {
|
|
5816
|
+
if (typeof number !== "number") return number;
|
|
5817
|
+
if (!Number.isFinite(number) || number === 0) return number === 0 ? 0 : number;
|
|
5818
|
+
if (!Number.isFinite(places)) return legacyRound$1(number, places);
|
|
5819
|
+
const normalizedPlaces = Math.trunc(places);
|
|
5820
|
+
if (Number.isInteger(number) && normalizedPlaces >= 0 || normalizedPlaces > 324) return number;
|
|
5821
|
+
const rounded = decimalPartsToNumber(roundDecimal(decimalFromNumber(number), normalizedPlaces));
|
|
5822
|
+
return Number.isFinite(rounded) ? rounded : number;
|
|
5823
|
+
}
|
|
5824
|
+
|
|
5825
|
+
//#endregion
|
|
5826
|
+
//#region src/shared/numfmt/general.ts
|
|
5827
|
+
function fixLocale(value, locale) {
|
|
5828
|
+
return value.replace(/\./, locale.decimal);
|
|
5829
|
+
}
|
|
5830
|
+
function getAbsoluteDecimal(value) {
|
|
5831
|
+
if (!value) return null;
|
|
5832
|
+
return value.negative ? {
|
|
5833
|
+
...value,
|
|
5834
|
+
negative: false
|
|
5835
|
+
} : value;
|
|
5836
|
+
}
|
|
5837
|
+
function getDecimalExponent(value) {
|
|
5838
|
+
var _value$exponent;
|
|
5839
|
+
return (_value$exponent = value === null || value === void 0 ? void 0 : value.exponent) !== null && _value$exponent !== void 0 ? _value$exponent : 0;
|
|
5840
|
+
}
|
|
5841
|
+
function usesShortestSignificand(value) {
|
|
5842
|
+
return !value || value.exponent < -308;
|
|
5843
|
+
}
|
|
5844
|
+
function getExp(value, locale) {
|
|
5845
|
+
const scientific = roundScientificDecimal(value, 1, true, 5);
|
|
5846
|
+
const exponent = scientific.exponent;
|
|
5847
|
+
const absoluteExponent = Math.abs(exponent);
|
|
5848
|
+
return [
|
|
5849
|
+
fixLocale(decimalPartsToPlainString(scientific.rounded), locale),
|
|
5850
|
+
locale.exponent,
|
|
5851
|
+
exponent < 0 ? locale.negative : locale.positive,
|
|
5852
|
+
absoluteExponent < 10 ? "0" : "",
|
|
5853
|
+
absoluteExponent
|
|
5854
|
+
];
|
|
5855
|
+
}
|
|
5856
|
+
function getShortestExp(number, exponent, locale) {
|
|
5857
|
+
const absoluteExponent = Math.abs(exponent);
|
|
5858
|
+
const mantissa = number === 1 ? number : Math.round(number * 1e5) / 1e5;
|
|
5859
|
+
return [
|
|
5860
|
+
fixLocale(String(mantissa), locale),
|
|
5861
|
+
locale.exponent,
|
|
5862
|
+
exponent < 0 ? locale.negative : locale.positive,
|
|
5863
|
+
absoluteExponent < 10 ? "0" : "",
|
|
5864
|
+
absoluteExponent
|
|
5865
|
+
];
|
|
5866
|
+
}
|
|
5867
|
+
function general(output, part, value, locale, decimalValue = null) {
|
|
5868
|
+
const integer = typeof value === "number" ? value | 0 : 0;
|
|
5869
|
+
if (typeof value === "string") output.push(value);
|
|
5870
|
+
else if (value === integer) output.push(Math.abs(integer));
|
|
5871
|
+
else {
|
|
5872
|
+
const absoluteValue = Math.abs(value);
|
|
5873
|
+
const absoluteDecimal = getAbsoluteDecimal(decimalValue);
|
|
5874
|
+
let exponent = getDecimalExponent(absoluteDecimal);
|
|
5875
|
+
let shortestSignificand = null;
|
|
5876
|
+
if (usesShortestSignificand(absoluteDecimal)) {
|
|
5877
|
+
exponent = getExponent(absoluteValue);
|
|
5878
|
+
shortestSignificand = getSignificand(absoluteValue, exponent);
|
|
5879
|
+
if (shortestSignificand === 10) {
|
|
5880
|
+
shortestSignificand = 1;
|
|
5881
|
+
exponent++;
|
|
5882
|
+
}
|
|
5883
|
+
}
|
|
5884
|
+
const digits = numDec(absoluteValue);
|
|
5885
|
+
if (exponent >= -4 && exponent <= -1) {
|
|
5886
|
+
const formatted = absoluteValue.toPrecision(10 + exponent).replace(/\.?0+$/, "");
|
|
5887
|
+
output.push(fixLocale(formatted, locale));
|
|
5888
|
+
} else if (exponent === 10) {
|
|
5889
|
+
const formatted = absoluteValue.toFixed(10).slice(0, 12).replace(/\.$/, "");
|
|
5890
|
+
output.push(fixLocale(formatted, locale));
|
|
5891
|
+
} else if (Math.abs(exponent) <= 9) if (digits.total <= 11) {
|
|
5892
|
+
const formatted = round(absoluteValue, 9).toFixed(digits.frac);
|
|
5893
|
+
output.push(fixLocale(formatted, locale));
|
|
5894
|
+
} else if (exponent === 9) output.push(Math.floor(absoluteValue));
|
|
5895
|
+
else if (exponent >= 0 && exponent < 9) output.push(fixLocale(String(round(absoluteValue, 9 - exponent)), locale));
|
|
5896
|
+
else output.push(...shortestSignificand === null ? getExp(absoluteDecimal, locale) : getShortestExp(shortestSignificand, exponent, locale));
|
|
5897
|
+
else if (digits.total >= 12) output.push(...shortestSignificand === null ? getExp(absoluteDecimal, locale) : getShortestExp(shortestSignificand, exponent, locale));
|
|
5898
|
+
else output.push(fixLocale(round(absoluteValue, 9).toFixed(digits.frac), locale));
|
|
5899
|
+
}
|
|
5900
|
+
return output;
|
|
5901
|
+
}
|
|
5902
|
+
|
|
5903
|
+
//#endregion
|
|
5904
|
+
//#region src/shared/numfmt/pad.ts
|
|
5905
|
+
/**
|
|
5906
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
5907
|
+
*
|
|
5908
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5909
|
+
* you may not use this file except in compliance with the License.
|
|
5910
|
+
* You may obtain a copy of the License at
|
|
5911
|
+
*
|
|
5912
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5913
|
+
*
|
|
5914
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5915
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5916
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5917
|
+
* See the License for the specific language governing permissions and
|
|
5918
|
+
* limitations under the License.
|
|
5919
|
+
*/
|
|
5920
|
+
/**
|
|
5921
|
+
* @ignore
|
|
5922
|
+
* @param {string} char Instruction character (['#', '?', '0'])
|
|
5923
|
+
* @param {boolean} [nbsp] Use nonbreaking space or not?
|
|
5924
|
+
* @returns {string} Padding character
|
|
5925
|
+
*/
|
|
5926
|
+
function pad$1(char, nbsp = false) {
|
|
5927
|
+
if (char === "0") return "0";
|
|
5928
|
+
else if (char === "?") return nbsp ? "\xA0" : " ";
|
|
5929
|
+
return "";
|
|
5930
|
+
}
|
|
5931
|
+
|
|
5932
|
+
//#endregion
|
|
5933
|
+
//#region src/shared/numfmt/to-ymd.ts
|
|
5934
|
+
const floor$1 = Math.floor;
|
|
5935
|
+
function toYMD1900(serial, leap1900 = true) {
|
|
5936
|
+
if (leap1900 && serial >= 0) {
|
|
5937
|
+
if (serial === 0) return [
|
|
5938
|
+
1900,
|
|
5939
|
+
1,
|
|
5940
|
+
0
|
|
5941
|
+
];
|
|
5942
|
+
if (serial === 60) return [
|
|
5943
|
+
1900,
|
|
5944
|
+
2,
|
|
5945
|
+
29
|
|
5946
|
+
];
|
|
5947
|
+
if (serial < 60) return [
|
|
5948
|
+
1900,
|
|
5949
|
+
serial < 32 ? 1 : 2,
|
|
5950
|
+
(serial - 1) % 31 + 1
|
|
5951
|
+
];
|
|
5952
|
+
}
|
|
5953
|
+
let l = serial + 68569 + 2415019;
|
|
5954
|
+
const n = floor$1(4 * l / 146097);
|
|
5955
|
+
l -= floor$1((146097 * n + 3) / 4);
|
|
5956
|
+
const i = floor$1(4e3 * (l + 1) / 1461001);
|
|
5957
|
+
l = l - floor$1(1461 * i / 4) + 31;
|
|
5958
|
+
const j = floor$1(80 * l / 2447);
|
|
5959
|
+
const nDay = l - floor$1(2447 * j / 80);
|
|
5960
|
+
l = floor$1(j / 11);
|
|
5961
|
+
const nMonth = j + 2 - 12 * l;
|
|
5962
|
+
return [
|
|
5963
|
+
100 * (n - 49) + i + l | 0,
|
|
5964
|
+
nMonth | 0,
|
|
5965
|
+
nDay | 0
|
|
5966
|
+
];
|
|
5967
|
+
}
|
|
5968
|
+
function toYMD1904(serial) {
|
|
5969
|
+
return toYMD1900(serial + 1462);
|
|
5970
|
+
}
|
|
5971
|
+
function toYMD1317(serial) {
|
|
5972
|
+
if (serial === 60) throw new Error("#VALUE!");
|
|
5973
|
+
if (serial <= 1) return [
|
|
5974
|
+
1317,
|
|
5975
|
+
8,
|
|
5976
|
+
29
|
|
5977
|
+
];
|
|
5978
|
+
if (serial < 60) return [
|
|
5979
|
+
1317,
|
|
5980
|
+
serial < 32 ? 9 : 10,
|
|
5981
|
+
1 + (serial - 2) % 30
|
|
5982
|
+
];
|
|
5983
|
+
const y = 10631 / 30;
|
|
5984
|
+
const shift1 = 8.01 / 60;
|
|
5985
|
+
let z = serial + 466935;
|
|
5986
|
+
const cyc = floor$1(z / 10631);
|
|
5987
|
+
z -= 10631 * cyc;
|
|
5988
|
+
const j = floor$1((z - shift1) / y);
|
|
5989
|
+
z -= floor$1(j * y + shift1);
|
|
5990
|
+
const m = floor$1((z + 28.5001) / 29.5);
|
|
5991
|
+
if (m === 13) return [
|
|
5992
|
+
30 * cyc + j,
|
|
5993
|
+
12,
|
|
5994
|
+
30
|
|
5995
|
+
];
|
|
5996
|
+
return [
|
|
5997
|
+
30 * cyc + j,
|
|
5998
|
+
m,
|
|
5999
|
+
z - floor$1(29.5001 * m - 29)
|
|
6000
|
+
];
|
|
6001
|
+
}
|
|
6002
|
+
function toYMD(serial, system = 0, leap1900 = true) {
|
|
6003
|
+
const int = floor$1(serial);
|
|
6004
|
+
if (system === 6) return toYMD1317(int);
|
|
6005
|
+
if (system === -1) return toYMD1904(int);
|
|
6006
|
+
return toYMD1900(int, leap1900);
|
|
6007
|
+
}
|
|
6008
|
+
|
|
6009
|
+
//#endregion
|
|
6010
|
+
//#region src/shared/numfmt/run-part.ts
|
|
6011
|
+
const DAYSIZE$1 = 86400;
|
|
6012
|
+
function dateOverflows(inputValue, roundedValue, bigRange) {
|
|
6013
|
+
if (bigRange) return inputValue < -694324 || roundedValue >= 35830291;
|
|
6014
|
+
return inputValue < 0 || roundedValue >= 2958466;
|
|
6015
|
+
}
|
|
6016
|
+
function legacyRound(number, places = 0) {
|
|
6017
|
+
if (number < 0) return -legacyRound(-number, places);
|
|
6018
|
+
if (places) {
|
|
6019
|
+
const power = 10 ** places || 1;
|
|
6020
|
+
return legacyRound(number * power, 0) / power;
|
|
6021
|
+
}
|
|
6022
|
+
return Math.round(number);
|
|
6023
|
+
}
|
|
6024
|
+
function runPart(value, part, options, locale, decimalValue = null) {
|
|
6025
|
+
var _options$grouping$, _options$grouping$2;
|
|
6026
|
+
const section = part;
|
|
6027
|
+
let renderValue = value;
|
|
6028
|
+
let numericValue = value;
|
|
6029
|
+
let mantissa = "";
|
|
6030
|
+
let mantissaSign = "";
|
|
6031
|
+
let numerator = "";
|
|
6032
|
+
let denominator = "";
|
|
6033
|
+
let fraction = "";
|
|
6034
|
+
let integer = "";
|
|
6035
|
+
let exponent = 0;
|
|
6036
|
+
let roundedNumber = null;
|
|
6037
|
+
let date = 0;
|
|
6038
|
+
if (typeof renderValue === "bigint") {
|
|
6039
|
+
if (renderValue <= Number.MAX_SAFE_INTEGER && renderValue >= Number.MIN_SAFE_INTEGER) {
|
|
6040
|
+
numericValue = Number(renderValue);
|
|
6041
|
+
renderValue = numericValue;
|
|
6042
|
+
} else return options.bigintErrorNumber ? String(renderValue) : options.overflow;
|
|
6043
|
+
date = numericValue;
|
|
6044
|
+
} else date = Math.trunc(numericValue);
|
|
6045
|
+
let time = 0;
|
|
6046
|
+
let year = 0;
|
|
6047
|
+
let month = 1;
|
|
6048
|
+
let day = 0;
|
|
6049
|
+
let weekday = 0;
|
|
6050
|
+
let hour = 0;
|
|
6051
|
+
let minute = 0;
|
|
6052
|
+
let second = 0;
|
|
6053
|
+
let subsec = 0;
|
|
6054
|
+
const l10n = locale || defaultLocale;
|
|
6055
|
+
let decimal = decimalValue;
|
|
6056
|
+
if (!decimal && typeof value === "number" && Number.isFinite(value)) decimal = decimalFromNumber(value);
|
|
6057
|
+
if (decimal && !section.text && section.scaleExponent) decimal = shiftDecimal(decimal, section.scaleExponent);
|
|
6058
|
+
if (!section.text && Number.isFinite(section.scale) && section.scale !== 1) {
|
|
6059
|
+
numericValue = clamp(numericValue * section.scale);
|
|
6060
|
+
renderValue = numericValue;
|
|
6061
|
+
}
|
|
6062
|
+
if (section.exponential && decimal && decimal.exponent >= -308) {
|
|
6063
|
+
const scientific = roundScientificDecimal(decimal, section.int_max, Boolean(section.integer), section.frac_max);
|
|
6064
|
+
exponent = scientific.exponent;
|
|
6065
|
+
roundedNumber = scientific.rounded;
|
|
6066
|
+
mantissa += Math.abs(exponent);
|
|
6067
|
+
} else if (section.exponential) {
|
|
6068
|
+
let significand = Math.abs(numericValue);
|
|
6069
|
+
if (significand) exponent = getExponent(significand, section.int_max);
|
|
6070
|
+
if (numericValue && !section.integer) exponent++;
|
|
6071
|
+
significand = getSignificand(significand, exponent);
|
|
6072
|
+
if (section.int_max === 1 && legacyRound(significand, section.frac_max) === 10) {
|
|
6073
|
+
significand = 1;
|
|
6074
|
+
exponent++;
|
|
6075
|
+
}
|
|
6076
|
+
numericValue = numericValue < 0 ? -significand : significand;
|
|
6077
|
+
renderValue = numericValue;
|
|
6078
|
+
mantissa += Math.abs(exponent);
|
|
6079
|
+
}
|
|
6080
|
+
const requiresDecimalRounding = !Number.isSafeInteger(numericValue) || Boolean(section.scaleExponent);
|
|
6081
|
+
roundedNumber = roundedNumber || (decimal && requiresDecimalRounding && !section.date && !section.fractions && !section.exponential && (section.integer || section.dec_fractions) ? roundDecimal(decimal, section.frac_max) : null);
|
|
6082
|
+
if (section.integer) if (roundedNumber) integer = roundedNumber.integer === "0" ? "" : roundedNumber.integer;
|
|
6083
|
+
else {
|
|
6084
|
+
const places = section.fractions ? 1 : section.frac_max;
|
|
6085
|
+
const roundedInteger = Math.abs(Number.isSafeInteger(numericValue) && places === 0 ? numericValue : legacyRound(numericValue, places));
|
|
6086
|
+
integer += roundedInteger < 1 ? "" : Math.floor(roundedInteger);
|
|
6087
|
+
}
|
|
6088
|
+
const primaryGroup = (_options$grouping$ = options.grouping[0]) !== null && _options$grouping$ !== void 0 ? _options$grouping$ : 3;
|
|
6089
|
+
const secondaryGroup = (_options$grouping$2 = options.grouping[1]) !== null && _options$grouping$2 !== void 0 ? _options$grouping$2 : primaryGroup;
|
|
6090
|
+
if (section.dec_fractions) fraction = roundedNumber ? roundedNumber.fraction : String(legacyRound(numericValue, section.frac_max)).split(".")[1] || "";
|
|
6091
|
+
const fixedSlash = !section.error && (section.num_p.includes("0") || section.den_p.includes("0"));
|
|
6092
|
+
let haveFraction = fixedSlash;
|
|
6093
|
+
if (section.fractions) {
|
|
6094
|
+
haveFraction = fixedSlash || !!(numericValue % 1);
|
|
6095
|
+
const decimal = Math.abs(section.integer ? numericValue % 1 : numericValue);
|
|
6096
|
+
if (decimal) {
|
|
6097
|
+
haveFraction = true;
|
|
6098
|
+
if (section.denominator && Number.isFinite(section.denominator)) {
|
|
6099
|
+
denominator += section.denominator;
|
|
6100
|
+
numerator += legacyRound(decimal * section.denominator);
|
|
6101
|
+
if (numerator === "0") {
|
|
6102
|
+
numerator = "";
|
|
6103
|
+
denominator = "";
|
|
6104
|
+
haveFraction = fixedSlash;
|
|
6105
|
+
}
|
|
6106
|
+
} else {
|
|
6107
|
+
const fractionParts = dec2frac(decimal, Infinity, section.den_max);
|
|
6108
|
+
numerator += fractionParts[0];
|
|
6109
|
+
denominator += fractionParts[1];
|
|
6110
|
+
if (section.integer && numerator === "0") {
|
|
6111
|
+
numerator = "";
|
|
6112
|
+
denominator = "";
|
|
6113
|
+
haveFraction = fixedSlash;
|
|
6114
|
+
}
|
|
6115
|
+
}
|
|
6116
|
+
} else if (!numericValue && !section.integer) {
|
|
6117
|
+
haveFraction = true;
|
|
6118
|
+
numerator = "0";
|
|
6119
|
+
denominator = "1";
|
|
6120
|
+
}
|
|
6121
|
+
if (section.integer && !haveFraction && !Math.trunc(numericValue)) integer = "0";
|
|
6122
|
+
}
|
|
6123
|
+
if (section.date) {
|
|
6124
|
+
date = Math.trunc(numericValue);
|
|
6125
|
+
const rawTime = DAYSIZE$1 * (numericValue - date);
|
|
6126
|
+
time = Math.floor(rawTime);
|
|
6127
|
+
subsec = rawTime - time;
|
|
6128
|
+
if (Math.abs(subsec) < 1e-6) subsec = 0;
|
|
6129
|
+
else if (subsec > .9999) {
|
|
6130
|
+
subsec = 0;
|
|
6131
|
+
time += 1;
|
|
6132
|
+
if (time === DAYSIZE$1) {
|
|
6133
|
+
time = 0;
|
|
6134
|
+
date += 1;
|
|
6135
|
+
}
|
|
6136
|
+
}
|
|
6137
|
+
if (subsec) {
|
|
6138
|
+
const minimumUnit = section.date & 512 || section.date & 256 || section.date & 128;
|
|
6139
|
+
if (minimumUnit === 512 && subsec > .9995 || minimumUnit === 256 && subsec > .995 || minimumUnit === 128 && subsec > .95 || !minimumUnit && subsec >= .5) {
|
|
6140
|
+
time++;
|
|
6141
|
+
subsec = 0;
|
|
6142
|
+
}
|
|
6143
|
+
}
|
|
6144
|
+
if (date || section.date_system) {
|
|
6145
|
+
const dateOutput = toYMD(numericValue, section.date_system, options.leap1900);
|
|
6146
|
+
year = dateOutput[0];
|
|
6147
|
+
month = dateOutput[1];
|
|
6148
|
+
day = dateOutput[2];
|
|
6149
|
+
}
|
|
6150
|
+
if (time) {
|
|
6151
|
+
const normalizedTime = time < 0 ? DAYSIZE$1 + time : time;
|
|
6152
|
+
second = Math.floor(normalizedTime) % 60;
|
|
6153
|
+
minute = Math.floor(normalizedTime / 60) % 60;
|
|
6154
|
+
hour = Math.floor(normalizedTime / 60 / 60) % 60;
|
|
6155
|
+
}
|
|
6156
|
+
weekday = (6 + date) % 7;
|
|
6157
|
+
if (section.date_eval && dateOverflows(numericValue, date + time / DAYSIZE$1, options.dateSpanLarge)) {
|
|
6158
|
+
if (options.dateErrorThrows) throw new Error("Date out of bounds");
|
|
6159
|
+
if (options.dateErrorNumber) return general(numericValue < 0 ? [l10n.negative] : [], {}, numericValue, l10n, decimal).join("");
|
|
6160
|
+
return options.overflow;
|
|
6161
|
+
}
|
|
6162
|
+
}
|
|
6163
|
+
const questionPadding = pad$1("?", options.nbsp);
|
|
6164
|
+
if (exponent < 0) mantissaSign = "-";
|
|
6165
|
+
else if (section.exp_plus) mantissaSign = "+";
|
|
6166
|
+
const output = [];
|
|
6167
|
+
const digitsStart = (numberString, pattern, tokenPattern, offset) => {
|
|
6168
|
+
let normalizedOffset = offset;
|
|
6169
|
+
const length = !normalizedOffset && numberString.length > pattern.length ? tokenPattern.length + numberString.length - pattern.length : tokenPattern.length;
|
|
6170
|
+
if (numberString.length < pattern.length) normalizedOffset += numberString.length - pattern.length;
|
|
6171
|
+
for (let index = 0; index < length; index++) output.push(numberString[index + normalizedOffset] || pad$1(tokenPattern[index], options.nbsp));
|
|
6172
|
+
return length;
|
|
6173
|
+
};
|
|
6174
|
+
let denominatorFixed = false;
|
|
6175
|
+
const counter = {
|
|
6176
|
+
int: 0,
|
|
6177
|
+
frac: 0,
|
|
6178
|
+
man: 0,
|
|
6179
|
+
num: 0,
|
|
6180
|
+
den: 0
|
|
6181
|
+
};
|
|
6182
|
+
for (let tokenIndex = 0, tokenLength = section.tokens.length; tokenIndex < tokenLength; tokenIndex++) {
|
|
6183
|
+
const token = section.tokens[tokenIndex];
|
|
6184
|
+
const tokenType = token.type;
|
|
6185
|
+
const length = token.num ? token.num.length : 0;
|
|
6186
|
+
if (tokenType === "string") {
|
|
6187
|
+
const tokenValue = token.value;
|
|
6188
|
+
if (token.rule) {
|
|
6189
|
+
if (token.rule === "num") {
|
|
6190
|
+
if (haveFraction) output.push(tokenValue.replace(/ /g, questionPadding));
|
|
6191
|
+
else if (section.num_min > 0 || section.den_min > 0) output.push(tokenValue.replace(/./g, questionPadding));
|
|
6192
|
+
} else if (token.rule === "num+int") {
|
|
6193
|
+
if (haveFraction && integer) output.push(tokenValue.replace(/ /g, questionPadding));
|
|
6194
|
+
else if (section.den_min > 0 && (integer || section.num_min)) output.push(tokenValue.replace(/./g, questionPadding));
|
|
6195
|
+
} else if (token.rule === "den") {
|
|
6196
|
+
if (haveFraction) output.push(tokenValue.replace(/ /g, questionPadding));
|
|
6197
|
+
else if (section.den_min > 0) output.push(tokenValue.replace(/./g, questionPadding));
|
|
6198
|
+
}
|
|
6199
|
+
} else output.push(tokenValue.replace(/ /g, questionPadding));
|
|
6200
|
+
} else if (tokenType === "space") if (token.rule === "num+int") {
|
|
6201
|
+
if ((haveFraction || section.num_min || section.den_min) && (integer || section.num_min)) output.push(questionPadding);
|
|
6202
|
+
} else output.push(questionPadding);
|
|
6203
|
+
else if (tokenType === "error") output.push(options.invalid);
|
|
6204
|
+
else if (tokenType === "point") output.push(section.date ? token.value : l10n.decimal);
|
|
6205
|
+
else if (tokenType === "general") general(output, section, renderValue, l10n, decimal);
|
|
6206
|
+
else if (tokenType === "exp") output.push(l10n.exponent);
|
|
6207
|
+
else if (tokenType === "minus") if (token.volatile && section.date) {} else if (token.volatile && roundedNumber) {
|
|
6208
|
+
if (roundedNumber.negative && !roundedNumber.zero) output.push(l10n.negative);
|
|
6209
|
+
} else if (token.volatile && (numericValue >= 0 || typeof renderValue !== "number")) {} else if (token.volatile && !section.fractions && (section.integer || section.dec_fractions)) {
|
|
6210
|
+
if (numericValue < 0 && !!integer && integer !== "0" || fraction) output.push(l10n.negative);
|
|
6211
|
+
} else output.push(l10n.negative);
|
|
6212
|
+
else if (tokenType === "plus") output.push(l10n.positive);
|
|
6213
|
+
else if (tokenType === "text") output.push(renderValue);
|
|
6214
|
+
else if (tokenType === "fill") {
|
|
6215
|
+
if (options.fillChar) output.push(options.fillChar, token.value);
|
|
6216
|
+
} else if (tokenType === "skip") if (options.skipChar) output.push(options.skipChar, token.value);
|
|
6217
|
+
else output.push(options.nbsp ? "\xA0" : " ");
|
|
6218
|
+
else if (tokenType === "div") if (haveFraction) output.push("/");
|
|
6219
|
+
else if (section.num_min > 0 || section.den_min > 0) output.push(questionPadding);
|
|
6220
|
+
else output.push(pad$1("#", options.nbsp));
|
|
6221
|
+
else if (tokenType === "int") if (section.int_pattern.length === 1) {
|
|
6222
|
+
const pattern = section.int_p;
|
|
6223
|
+
const length = Math.max(section.int_min, integer.length);
|
|
6224
|
+
let digits = "";
|
|
6225
|
+
for (let index = length; index > 0; index--) {
|
|
6226
|
+
const digit = integer.charAt(integer.length - index);
|
|
6227
|
+
const patternDigit = digit ? "" : pattern.charAt(pattern.length - index) || pattern[0];
|
|
6228
|
+
let separator = "";
|
|
6229
|
+
if (section.grouping) {
|
|
6230
|
+
const groupIndex = index - 1 - primaryGroup;
|
|
6231
|
+
if (groupIndex >= 0 && !(groupIndex % secondaryGroup)) separator = digit || patternDigit === "0" ? l10n.group : pad$1("?", options.nbsp);
|
|
6232
|
+
}
|
|
6233
|
+
digits += (digit || pad$1(patternDigit, options.nbsp)) + separator;
|
|
6234
|
+
}
|
|
6235
|
+
output.push(digits);
|
|
6236
|
+
} else counter.int += digitsStart(integer, section.int_p, token.num, counter.int);
|
|
6237
|
+
else if (tokenType === "frac") {
|
|
6238
|
+
const offset = counter.frac;
|
|
6239
|
+
for (let index = 0; index < length; index++) output.push(fraction[index + offset] || pad$1(token.num[index], options.nbsp));
|
|
6240
|
+
counter.frac += length;
|
|
6241
|
+
} else if (tokenType === "man") {
|
|
6242
|
+
if (!counter[tokenType] && !counter.man) output.push(mantissaSign);
|
|
6243
|
+
counter.man += digitsStart(mantissa, section.man_p, token.num, counter.man);
|
|
6244
|
+
} else if (tokenType === "num") counter.num += digitsStart(numerator, section.num_p, token.num, counter.num);
|
|
6245
|
+
else if (tokenType === "den") {
|
|
6246
|
+
const offset = counter.den;
|
|
6247
|
+
for (let index = 0; index < length; index++) {
|
|
6248
|
+
let digit = denominator[index + offset];
|
|
6249
|
+
if (!digit) {
|
|
6250
|
+
const char = token.num[index];
|
|
6251
|
+
if ("123456789".includes(char) || denominatorFixed && char === "0") {
|
|
6252
|
+
denominatorFixed = true;
|
|
6253
|
+
digit = options.nbsp ? "\xA0" : " ";
|
|
6254
|
+
} else if (!denominatorFixed && index === length - 1 && char === "0" && !denominator) digit = "1";
|
|
6255
|
+
else digit = pad$1(char, options.nbsp);
|
|
6256
|
+
}
|
|
6257
|
+
output.push(digit);
|
|
6258
|
+
}
|
|
6259
|
+
counter.den += length;
|
|
6260
|
+
} else if (tokenType === "year") {
|
|
6261
|
+
if (year < 0) output.push(l10n.negative);
|
|
6262
|
+
output.push(String(Math.abs(year)).padStart(4, "0"));
|
|
6263
|
+
} else if (tokenType === "year-short") {
|
|
6264
|
+
const shortYear = year % 100;
|
|
6265
|
+
output.push(shortYear < 10 ? "0" : "", shortYear);
|
|
6266
|
+
} else if (tokenType === "month") output.push(token.pad && month < 10 ? "0" : "", month);
|
|
6267
|
+
else if (tokenType === "monthname-single") if (section.date_system === 6) output.push(l10n.mmmm6[month - 1].charAt(0));
|
|
6268
|
+
else output.push(l10n.mmmm[month - 1].charAt(0));
|
|
6269
|
+
else if (tokenType === "monthname-short") if (section.date_system === 6) output.push(l10n.mmm6[month - 1]);
|
|
6270
|
+
else output.push(l10n.mmm[month - 1]);
|
|
6271
|
+
else if (tokenType === "monthname") if (section.date_system === 6) output.push(l10n.mmmm6[month - 1]);
|
|
6272
|
+
else output.push(l10n.mmmm[month - 1]);
|
|
6273
|
+
else if (token.type === "weekday-short") output.push(l10n.ddd[weekday]);
|
|
6274
|
+
else if (tokenType === "weekday") output.push(l10n.dddd[weekday]);
|
|
6275
|
+
else if (tokenType === "day") output.push(token.pad && day < 10 ? "0" : "", day);
|
|
6276
|
+
else if (tokenType === "hour") {
|
|
6277
|
+
const displayHour = hour % section.clock || (section.clock < 24 ? section.clock : 0);
|
|
6278
|
+
output.push(token.pad && displayHour < 10 ? "0" : "", displayHour);
|
|
6279
|
+
} else if (tokenType === "min") output.push(token.pad && minute < 10 ? "0" : "", minute);
|
|
6280
|
+
else if (tokenType === "sec") output.push(token.pad && second < 10 ? "0" : "", second);
|
|
6281
|
+
else if (tokenType === "subsec") {
|
|
6282
|
+
output.push(l10n.decimal);
|
|
6283
|
+
const formattedSubseconds = subsec.toFixed(section.sec_decimals);
|
|
6284
|
+
output.push(formattedSubseconds.slice(2, 2 + token.decimals));
|
|
6285
|
+
} else if (tokenType === "ampm") {
|
|
6286
|
+
const index = hour < 12 ? 0 : 1;
|
|
6287
|
+
if (token.short && !locale) output.push("AP"[index]);
|
|
6288
|
+
else output.push(l10n.ampm[index]);
|
|
6289
|
+
} else if (tokenType === "hour-elap") {
|
|
6290
|
+
if (numericValue < 0) output.push(l10n.negative);
|
|
6291
|
+
const elapsedHours = date * 24 + Math.floor(Math.abs(time) / 3600);
|
|
6292
|
+
output.push(String(Math.abs(elapsedHours)).padStart(token.pad, "0"));
|
|
6293
|
+
} else if (tokenType === "min-elap") {
|
|
6294
|
+
if (numericValue < 0) output.push(l10n.negative);
|
|
6295
|
+
const elapsedMinutes = date * 1440 + Math.floor(Math.abs(time) / 60);
|
|
6296
|
+
output.push(String(Math.abs(elapsedMinutes)).padStart(token.pad, "0"));
|
|
6297
|
+
} else if (tokenType === "sec-elap") {
|
|
6298
|
+
if (numericValue < 0) output.push(l10n.negative);
|
|
6299
|
+
const elapsedSeconds = date * DAYSIZE$1 + Math.abs(time);
|
|
6300
|
+
output.push(String(Math.abs(elapsedSeconds)).padStart(token.pad, "0"));
|
|
6301
|
+
} else if (tokenType === "b-year") output.push(year + 543);
|
|
6302
|
+
else if (tokenType === "b-year-short") {
|
|
6303
|
+
const shortYear = (year + 543) % 100;
|
|
6304
|
+
output.push(shortYear < 10 ? "0" : "", shortYear);
|
|
6305
|
+
}
|
|
6306
|
+
}
|
|
6307
|
+
return output.join("");
|
|
6308
|
+
}
|
|
6309
|
+
|
|
6310
|
+
//#endregion
|
|
6311
|
+
//#region src/shared/numfmt/format-number.ts
|
|
6312
|
+
const defaultText = parseFormatSection([{
|
|
6313
|
+
type: TOKEN_TEXT,
|
|
6314
|
+
value: "@",
|
|
6315
|
+
raw: "@"
|
|
6316
|
+
}]);
|
|
6317
|
+
function isParsedSection(part) {
|
|
6318
|
+
return !!part && "scale" in part;
|
|
6319
|
+
}
|
|
6320
|
+
function getPart(value, parts) {
|
|
6321
|
+
for (let partIndex = 0; partIndex < 3; partIndex++) {
|
|
6322
|
+
const part = parts[partIndex];
|
|
6323
|
+
if (isParsedSection(part)) {
|
|
6324
|
+
let condition;
|
|
6325
|
+
if (part.condition) {
|
|
6326
|
+
const operator = part.condition[0];
|
|
6327
|
+
const operand = part.condition[1];
|
|
6328
|
+
if (operator === "=") condition = value === operand;
|
|
6329
|
+
else if (operator === ">") condition = value > operand;
|
|
6330
|
+
else if (operator === "<") condition = value < operand;
|
|
6331
|
+
else if (operator === ">=") condition = value >= operand;
|
|
6332
|
+
else if (operator === "<=") condition = value <= operand;
|
|
6333
|
+
else if (operator === "<>") condition = value !== operand;
|
|
6334
|
+
} else condition = true;
|
|
6335
|
+
if (condition) return part;
|
|
6336
|
+
} else if (part) return part;
|
|
6337
|
+
}
|
|
6338
|
+
}
|
|
6339
|
+
function formatColor$1(value, pattern, options) {
|
|
6340
|
+
const parts = pattern.partitions;
|
|
6341
|
+
let part = parts[3];
|
|
6342
|
+
let color = null;
|
|
6343
|
+
if ((typeof value === "number" || typeof value === "bigint") && isFinite(value)) part = getPart(value, parts);
|
|
6344
|
+
if (isParsedSection(part) && part.color) color = part.color;
|
|
6345
|
+
if (color && typeof color === "number" && options.indexColors) color = indexColors[color - 1] || "#000";
|
|
6346
|
+
return color;
|
|
6347
|
+
}
|
|
6348
|
+
function formatValue(value, pattern, options) {
|
|
6349
|
+
const parts = pattern.partitions;
|
|
6350
|
+
const locale = getLocale(pattern.locale || options.locale);
|
|
6351
|
+
let renderValue = value;
|
|
6352
|
+
const textPart = parts[3] ? parts[3] : defaultText;
|
|
6353
|
+
if (typeof renderValue === "boolean") renderValue = (locale || defaultLocale).bool[renderValue ? 0 : 1];
|
|
6354
|
+
if (renderValue == null) return "";
|
|
6355
|
+
const isBigInt = typeof renderValue === "bigint";
|
|
6356
|
+
if (typeof renderValue !== "number" && !isBigInt) return runPart(renderValue, textPart, options, locale);
|
|
6357
|
+
if (!isBigInt && !Number.isFinite(renderValue)) {
|
|
6358
|
+
const resolvedLocale = locale || defaultLocale;
|
|
6359
|
+
if (Number.isNaN(renderValue)) return resolvedLocale.nan;
|
|
6360
|
+
return (renderValue < 0 ? resolvedLocale.negative : "") + resolvedLocale.infinity;
|
|
6361
|
+
}
|
|
6362
|
+
const part = getPart(value, parts);
|
|
6363
|
+
const decimalValue = part && typeof value === "number" && Number.isFinite(value) ? decimalFromNumber(value) : null;
|
|
6364
|
+
return part ? runPart(value, part, options, locale, decimalValue) : options.overflow;
|
|
6365
|
+
}
|
|
6366
|
+
|
|
6367
|
+
//#endregion
|
|
6368
|
+
//#region src/shared/numfmt/options.ts
|
|
6369
|
+
const defaultOptions = {
|
|
6370
|
+
overflow: "######",
|
|
6371
|
+
dateErrorThrows: false,
|
|
6372
|
+
dateErrorNumber: true,
|
|
6373
|
+
bigintErrorNumber: false,
|
|
6374
|
+
dateSpanLarge: true,
|
|
6375
|
+
leap1900: true,
|
|
6376
|
+
nbsp: false,
|
|
6377
|
+
throws: true,
|
|
6378
|
+
invalid: "######",
|
|
6379
|
+
locale: "",
|
|
6380
|
+
ignoreTimezone: false,
|
|
6381
|
+
grouping: [3, 3],
|
|
6382
|
+
indexColors: true,
|
|
6383
|
+
skipChar: "",
|
|
6384
|
+
fillChar: ""
|
|
6385
|
+
};
|
|
6386
|
+
|
|
6387
|
+
//#endregion
|
|
6388
|
+
//#region src/shared/numfmt/tokenize.ts
|
|
6389
|
+
const tokenHandlers = [
|
|
6390
|
+
[
|
|
6391
|
+
TOKEN_GENERAL,
|
|
6392
|
+
/^General/i,
|
|
6393
|
+
0
|
|
6394
|
+
],
|
|
6395
|
+
[
|
|
6396
|
+
TOKEN_HASH,
|
|
6397
|
+
/^#/,
|
|
6398
|
+
0
|
|
6399
|
+
],
|
|
6400
|
+
[
|
|
6401
|
+
TOKEN_ZERO,
|
|
6402
|
+
/^0/,
|
|
6403
|
+
0
|
|
6404
|
+
],
|
|
6405
|
+
[
|
|
6406
|
+
TOKEN_QMARK,
|
|
6407
|
+
/^\?/,
|
|
6408
|
+
0
|
|
6409
|
+
],
|
|
6410
|
+
[
|
|
6411
|
+
TOKEN_SLASH,
|
|
6412
|
+
/^\//,
|
|
6413
|
+
0
|
|
6414
|
+
],
|
|
6415
|
+
[
|
|
6416
|
+
TOKEN_BREAK,
|
|
6417
|
+
/^;/,
|
|
6418
|
+
0
|
|
6419
|
+
],
|
|
6420
|
+
[
|
|
6421
|
+
TOKEN_TEXT,
|
|
6422
|
+
/^@/,
|
|
6423
|
+
0
|
|
6424
|
+
],
|
|
6425
|
+
[
|
|
6426
|
+
TOKEN_PLUS,
|
|
6427
|
+
/^\+/,
|
|
6428
|
+
0
|
|
6429
|
+
],
|
|
6430
|
+
[
|
|
6431
|
+
TOKEN_MINUS,
|
|
6432
|
+
/^-/,
|
|
6433
|
+
0
|
|
6434
|
+
],
|
|
6435
|
+
[
|
|
6436
|
+
TOKEN_POINT,
|
|
6437
|
+
/^\./,
|
|
6438
|
+
0
|
|
6439
|
+
],
|
|
6440
|
+
[
|
|
6441
|
+
TOKEN_SPACE,
|
|
6442
|
+
/^ /,
|
|
6443
|
+
0
|
|
6444
|
+
],
|
|
6445
|
+
[
|
|
6446
|
+
TOKEN_PERCENT,
|
|
6447
|
+
/^%/,
|
|
6448
|
+
0
|
|
6449
|
+
],
|
|
6450
|
+
[
|
|
6451
|
+
TOKEN_DIGIT,
|
|
6452
|
+
/^[1-9]/,
|
|
6453
|
+
0
|
|
6454
|
+
],
|
|
6455
|
+
[
|
|
6456
|
+
TOKEN_CALENDAR,
|
|
6457
|
+
/^(?:B[12])/i,
|
|
6458
|
+
0
|
|
6459
|
+
],
|
|
6460
|
+
[
|
|
6461
|
+
TOKEN_ERROR,
|
|
6462
|
+
/^B$/,
|
|
6463
|
+
0
|
|
6464
|
+
],
|
|
6465
|
+
[
|
|
6466
|
+
TOKEN_DATETIME,
|
|
6467
|
+
/^(?:[hH]+|[mM]+|[sS]+|[yY]+|[bB]+|[dD]+|[gG]+|[aA]{3,}|e+)/,
|
|
6468
|
+
0
|
|
6469
|
+
],
|
|
6470
|
+
[
|
|
6471
|
+
TOKEN_DURATION,
|
|
6472
|
+
/^(?:\[(h+|m+|s+)\])/i,
|
|
6473
|
+
1
|
|
6474
|
+
],
|
|
6475
|
+
[
|
|
6476
|
+
TOKEN_CONDITION,
|
|
6477
|
+
/^\[(<[=>]?|>=?|=)\s*(-?[.\d]+)\]/,
|
|
6478
|
+
[1, 2]
|
|
6479
|
+
],
|
|
6480
|
+
[
|
|
6481
|
+
TOKEN_DBNUM,
|
|
6482
|
+
/^\[(DBNum[0-4]?\d)\]/i,
|
|
6483
|
+
1
|
|
6484
|
+
],
|
|
6485
|
+
[
|
|
6486
|
+
TOKEN_NATNUM,
|
|
6487
|
+
/^\[(NatNum[0-4]?\d)\]/i,
|
|
6488
|
+
1
|
|
6489
|
+
],
|
|
6490
|
+
[
|
|
6491
|
+
TOKEN_LOCALE,
|
|
6492
|
+
/^\[\$([^\]]+)\]/,
|
|
6493
|
+
1
|
|
6494
|
+
],
|
|
6495
|
+
[
|
|
6496
|
+
TOKEN_COLOR,
|
|
6497
|
+
/^\[(black|blue|cyan|green|magenta|red|white|yellow|color\s*\d+)\]/i,
|
|
6498
|
+
1
|
|
6499
|
+
],
|
|
6500
|
+
[
|
|
6501
|
+
TOKEN_MODIFIER,
|
|
6502
|
+
/^\[([^\]]+)\]/,
|
|
6503
|
+
1
|
|
6504
|
+
],
|
|
6505
|
+
[
|
|
6506
|
+
TOKEN_AMPM,
|
|
6507
|
+
/^(?:AM\/PM|am\/pm|A\/P)/,
|
|
6508
|
+
0
|
|
6509
|
+
],
|
|
6510
|
+
[
|
|
6511
|
+
TOKEN_ESCAPED,
|
|
6512
|
+
/^\\(.)/,
|
|
6513
|
+
1
|
|
6514
|
+
],
|
|
6515
|
+
[
|
|
6516
|
+
TOKEN_STRING,
|
|
6517
|
+
/^"([^"]*?)"/,
|
|
6518
|
+
1
|
|
6519
|
+
],
|
|
6520
|
+
[
|
|
6521
|
+
TOKEN_SKIP,
|
|
6522
|
+
/^_(\\.|.)/,
|
|
6523
|
+
1
|
|
6524
|
+
],
|
|
6525
|
+
[
|
|
6526
|
+
"exp",
|
|
6527
|
+
/^[Ee]([+-])/,
|
|
6528
|
+
1
|
|
6529
|
+
],
|
|
6530
|
+
[
|
|
6531
|
+
TOKEN_FILL,
|
|
6532
|
+
/^\*(\\.|.)/,
|
|
6533
|
+
1
|
|
6534
|
+
],
|
|
6535
|
+
[
|
|
6536
|
+
TOKEN_PAREN,
|
|
6537
|
+
/^[()]/,
|
|
6538
|
+
0
|
|
6539
|
+
],
|
|
6540
|
+
[
|
|
6541
|
+
TOKEN_ERROR,
|
|
6542
|
+
/^[EÈÉÊËèéêëĒēĔĕĖėĘęĚěȄȅȆȇȨȩNnÑñŃńŅņŇňǸǹ["*/\\_]/,
|
|
6543
|
+
0
|
|
6544
|
+
],
|
|
6545
|
+
[
|
|
6546
|
+
TOKEN_CHAR,
|
|
6547
|
+
/^./,
|
|
6548
|
+
0
|
|
6549
|
+
]
|
|
6550
|
+
];
|
|
6551
|
+
const CODE_QMRK = 63;
|
|
6552
|
+
const CODE_HASH = 35;
|
|
6553
|
+
const CODE_ZERO = 48;
|
|
6554
|
+
const CODE_NINE = 57;
|
|
6555
|
+
const isNumOp = (char) => {
|
|
6556
|
+
const code = (char || "\0").charCodeAt(0);
|
|
6557
|
+
return code === CODE_QMRK || code === CODE_HASH || code >= CODE_ZERO && code <= CODE_NINE;
|
|
6558
|
+
};
|
|
6559
|
+
/**
|
|
6560
|
+
* Breaks a format pattern string into a list of tokens.
|
|
6561
|
+
*/
|
|
6562
|
+
function tokenize(pattern) {
|
|
6563
|
+
let index = 0;
|
|
6564
|
+
const tokens = [];
|
|
6565
|
+
const unresolvedCommas = [];
|
|
6566
|
+
while (index < pattern.length) {
|
|
6567
|
+
const current = pattern.slice(index);
|
|
6568
|
+
let step = 0;
|
|
6569
|
+
const commaMatch = /^(,+)(.)?/.exec(current);
|
|
6570
|
+
if (commaMatch) {
|
|
6571
|
+
const raw = commaMatch[1];
|
|
6572
|
+
step = raw.length;
|
|
6573
|
+
const lookBehind = pattern[index - 1] || "";
|
|
6574
|
+
let maybeGroup = false;
|
|
6575
|
+
let maybeScale = false;
|
|
6576
|
+
if (isNumOp(lookBehind)) {
|
|
6577
|
+
maybeGroup = true;
|
|
6578
|
+
maybeScale = true;
|
|
6579
|
+
} else if (lookBehind === ".") maybeScale = true;
|
|
6580
|
+
const lookAhead = commaMatch[2] || "";
|
|
6581
|
+
if (maybeGroup && (!lookAhead || lookAhead === ";")) maybeGroup = false;
|
|
6582
|
+
if (maybeScale && isNumOp(lookAhead)) maybeScale = false;
|
|
6583
|
+
if (maybeGroup && !maybeScale) tokens.push({
|
|
6584
|
+
type: TOKEN_GROUP,
|
|
6585
|
+
value: ",",
|
|
6586
|
+
raw
|
|
6587
|
+
});
|
|
6588
|
+
else if (!maybeGroup && maybeScale) tokens.push({
|
|
6589
|
+
type: TOKEN_SCALE,
|
|
6590
|
+
value: ",",
|
|
6591
|
+
raw
|
|
6592
|
+
});
|
|
6593
|
+
else if (maybeGroup && maybeScale) {
|
|
6594
|
+
const token = {
|
|
6595
|
+
type: TOKEN_SCALE,
|
|
6596
|
+
value: ",",
|
|
6597
|
+
raw
|
|
6598
|
+
};
|
|
6599
|
+
tokens.push(token);
|
|
6600
|
+
unresolvedCommas.push(token);
|
|
6601
|
+
} else tokens.push({
|
|
6602
|
+
type: TOKEN_COMMA,
|
|
6603
|
+
value: ",",
|
|
6604
|
+
raw
|
|
6605
|
+
});
|
|
6606
|
+
} else {
|
|
6607
|
+
let token;
|
|
6608
|
+
for (const [type, expression, group] of tokenHandlers) {
|
|
6609
|
+
const match = expression.exec(current);
|
|
6610
|
+
if (match) {
|
|
6611
|
+
token = {
|
|
6612
|
+
type,
|
|
6613
|
+
value: typeof group !== "number" ? group.map((matchIndex) => match[matchIndex]) : match[group || 0],
|
|
6614
|
+
raw: match[0]
|
|
6615
|
+
};
|
|
6616
|
+
tokens.push(token);
|
|
6617
|
+
step = match[0].length;
|
|
6618
|
+
break;
|
|
6619
|
+
}
|
|
6620
|
+
}
|
|
6621
|
+
if (unresolvedCommas.length && (token === null || token === void 0 ? void 0 : token.raw) === ";") unresolvedCommas.length = 0;
|
|
6622
|
+
if (unresolvedCommas.length && isNumOp(token === null || token === void 0 ? void 0 : token.raw)) {
|
|
6623
|
+
unresolvedCommas.forEach((unresolved) => unresolved.type = TOKEN_GROUP);
|
|
6624
|
+
unresolvedCommas.length = 0;
|
|
6625
|
+
}
|
|
6626
|
+
}
|
|
6627
|
+
if (!step) {
|
|
6628
|
+
const raw = current[0];
|
|
6629
|
+
step = 1;
|
|
6630
|
+
tokens.push({
|
|
6631
|
+
type: TOKEN_CHAR,
|
|
6632
|
+
value: raw,
|
|
6633
|
+
raw
|
|
6634
|
+
});
|
|
6635
|
+
}
|
|
6636
|
+
index += step;
|
|
6637
|
+
}
|
|
6638
|
+
return tokens;
|
|
6639
|
+
}
|
|
6640
|
+
|
|
6641
|
+
//#endregion
|
|
6642
|
+
//#region src/shared/numfmt/parse-pattern.ts
|
|
6643
|
+
function maybeAddMinus(part) {
|
|
6644
|
+
var _part$condition, _part$condition2;
|
|
6645
|
+
const operator = (_part$condition = part.condition) === null || _part$condition === void 0 ? void 0 : _part$condition[0];
|
|
6646
|
+
const value = (_part$condition2 = part.condition) === null || _part$condition2 === void 0 ? void 0 : _part$condition2[1];
|
|
6647
|
+
if (!(typeof value === "number" && value < 0 && (operator === "<" || operator === "<=" || operator === "=") || value === 0 && operator === "<")) part.tokens.unshift({
|
|
6648
|
+
type: "minus",
|
|
6649
|
+
volatile: true
|
|
6650
|
+
});
|
|
6651
|
+
}
|
|
6652
|
+
function clonePart(part, prefixToken = null) {
|
|
6653
|
+
const result = {
|
|
6654
|
+
...part,
|
|
6655
|
+
int_pattern: [...part.int_pattern],
|
|
6656
|
+
frac_pattern: [...part.frac_pattern],
|
|
6657
|
+
man_pattern: [...part.man_pattern],
|
|
6658
|
+
den_pattern: [...part.den_pattern],
|
|
6659
|
+
num_pattern: [...part.num_pattern],
|
|
6660
|
+
tokens: [...part.tokens]
|
|
6661
|
+
};
|
|
6662
|
+
if (part.condition) result.condition = [...part.condition];
|
|
6663
|
+
if (prefixToken) result.tokens.unshift(prefixToken);
|
|
6664
|
+
result.generated = true;
|
|
6665
|
+
return result;
|
|
6666
|
+
}
|
|
6667
|
+
function parsePattern(pattern) {
|
|
6668
|
+
const partitions = [];
|
|
6669
|
+
let conditional = false;
|
|
6670
|
+
let localeOverride;
|
|
6671
|
+
let textPartition = null;
|
|
6672
|
+
let more = 0;
|
|
6673
|
+
let index = 0;
|
|
6674
|
+
let conditions = 0;
|
|
6675
|
+
let tokens = tokenize(pattern);
|
|
6676
|
+
do {
|
|
6677
|
+
var _tokens$part$tokensUs;
|
|
6678
|
+
const part = parseFormatSection(tokens);
|
|
6679
|
+
if ((part.date || part.general) && (part.int_pattern.length || part.frac_pattern.length || part.scale !== 1 || part.text)) throw new Error("Illegal format");
|
|
6680
|
+
if (part.condition) {
|
|
6681
|
+
conditions++;
|
|
6682
|
+
conditional = true;
|
|
6683
|
+
}
|
|
6684
|
+
if (part.text) {
|
|
6685
|
+
if (textPartition) throw new Error("Unexpected partition");
|
|
6686
|
+
textPartition = part;
|
|
6687
|
+
}
|
|
6688
|
+
if (part.locale) localeOverride = resolveLocale(part.locale);
|
|
6689
|
+
partitions.push(part);
|
|
6690
|
+
more = ((_tokens$part$tokensUs = tokens[part.tokensUsed]) === null || _tokens$part$tokensUs === void 0 ? void 0 : _tokens$part$tokensUs.type) === "break" ? 1 : 0;
|
|
6691
|
+
tokens = tokens.slice(part.tokensUsed + more);
|
|
6692
|
+
index++;
|
|
6693
|
+
} while (more && index < 4 && conditions < 3);
|
|
6694
|
+
if (more) throw new Error("Unexpected partition");
|
|
6695
|
+
if (conditions > 2) throw new Error("Unexpected condition");
|
|
6696
|
+
const fourthPart = partitions[3];
|
|
6697
|
+
if (fourthPart && (fourthPart.int_pattern.length || fourthPart.frac_pattern.length || fourthPart.date)) throw new Error("Unexpected partition");
|
|
6698
|
+
if (conditional) {
|
|
6699
|
+
if (!partitions[0].condition) partitions[0].condition = [">", 0];
|
|
6700
|
+
const numberOfParts = partitions.length;
|
|
6701
|
+
if (numberOfParts === 1) {
|
|
6702
|
+
const fallback = parseFormatSection(tokenize("General"));
|
|
6703
|
+
fallback.generated = true;
|
|
6704
|
+
partitions[1] = fallback;
|
|
6705
|
+
}
|
|
6706
|
+
if (numberOfParts <= 2) {}
|
|
6707
|
+
if (numberOfParts < 3) {
|
|
6708
|
+
const firstPart = partitions[0];
|
|
6709
|
+
const secondPart = partitions[1];
|
|
6710
|
+
maybeAddMinus(firstPart);
|
|
6711
|
+
if (secondPart.condition) maybeAddMinus(secondPart);
|
|
6712
|
+
else {
|
|
6713
|
+
const condition = firstPart.condition;
|
|
6714
|
+
if ((condition === null || condition === void 0 ? void 0 : condition[0]) === "=" || typeof (condition === null || condition === void 0 ? void 0 : condition[1]) === "number" && condition[1] >= 0 && (condition[0] === ">" || condition[0] === ">=")) secondPart.tokens.unshift({
|
|
6715
|
+
type: "minus",
|
|
6716
|
+
volatile: true
|
|
6717
|
+
});
|
|
6718
|
+
}
|
|
6719
|
+
} else partitions.forEach(maybeAddMinus);
|
|
6720
|
+
} else {
|
|
6721
|
+
if (partitions.length < 4 && textPartition) {
|
|
6722
|
+
for (let partitionIndex = 0, length = partitions.length; partitionIndex < length; partitionIndex++) if (partitions[partitionIndex] === textPartition) partitions.splice(partitionIndex, 1);
|
|
6723
|
+
}
|
|
6724
|
+
if (partitions.length < 1 && textPartition) {
|
|
6725
|
+
const positive = parseFormatSection(tokenize("General"));
|
|
6726
|
+
positive.generated = true;
|
|
6727
|
+
partitions[0] = positive;
|
|
6728
|
+
}
|
|
6729
|
+
if (partitions.length < 2) partitions.push(clonePart(partitions[0], {
|
|
6730
|
+
type: "minus",
|
|
6731
|
+
volatile: true
|
|
6732
|
+
}));
|
|
6733
|
+
if (partitions.length < 3) partitions.push(clonePart(partitions[0]));
|
|
6734
|
+
if (partitions.length < 4) if (textPartition) partitions.push(textPartition);
|
|
6735
|
+
else {
|
|
6736
|
+
const text = parseFormatSection(tokenize("@"));
|
|
6737
|
+
text.generated = true;
|
|
6738
|
+
partitions.push(text);
|
|
6739
|
+
}
|
|
6740
|
+
partitions[0].condition = [">", 0];
|
|
6741
|
+
partitions[1].condition = ["<", 0];
|
|
6742
|
+
partitions[2].condition = null;
|
|
6743
|
+
}
|
|
6744
|
+
return {
|
|
6745
|
+
pattern,
|
|
6746
|
+
partitions,
|
|
6747
|
+
locale: localeOverride
|
|
6748
|
+
};
|
|
6749
|
+
}
|
|
6750
|
+
|
|
6751
|
+
//#endregion
|
|
6752
|
+
//#region src/shared/numfmt/serial-date.ts
|
|
6753
|
+
const floor = Math.floor;
|
|
6754
|
+
const DAYSIZE = 86400;
|
|
6755
|
+
const dateUTC = Date.UTC;
|
|
6756
|
+
/**
|
|
6757
|
+
* Convert a native JavaScript Date, or array to a spreadsheet serial date.
|
|
6758
|
+
*
|
|
6759
|
+
* Returns a serial date number if input was a Date object or an array of
|
|
6760
|
+
* numbers, or null.
|
|
6761
|
+
*/
|
|
6762
|
+
function dateToSerial(date, options) {
|
|
6763
|
+
let timestamp = null;
|
|
6764
|
+
if (Array.isArray(date)) {
|
|
6765
|
+
const [year, month, day, hours, minutes, seconds] = date;
|
|
6766
|
+
timestamp = dateUTC(year, month == null ? 0 : month - 1, day !== null && day !== void 0 ? day : 1, hours || 0, minutes || 0, seconds || 0);
|
|
6767
|
+
} else if (date instanceof Date) {
|
|
6768
|
+
timestamp = date.getTime();
|
|
6769
|
+
if (!(options === null || options === void 0 ? void 0 : options.ignoreTimezone)) {
|
|
6770
|
+
const localDate = /* @__PURE__ */ new Date();
|
|
6771
|
+
localDate.setUTCFullYear(date.getFullYear(), date.getMonth(), date.getDate());
|
|
6772
|
+
localDate.setUTCHours(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
|
|
6773
|
+
timestamp = localDate.getTime();
|
|
6774
|
+
}
|
|
6775
|
+
}
|
|
6776
|
+
if (timestamp != null && Number.isFinite(timestamp)) {
|
|
6777
|
+
const days = timestamp / 864e5;
|
|
6778
|
+
return days - (days <= -25509 ? -25568 : -25569);
|
|
6779
|
+
}
|
|
6780
|
+
return null;
|
|
6781
|
+
}
|
|
6782
|
+
/**
|
|
6783
|
+
* Convert a spreadsheet serial date to an array of date parts, accurate to a
|
|
6784
|
+
* second.
|
|
3908
6785
|
*/
|
|
3909
|
-
function
|
|
3910
|
-
let
|
|
3911
|
-
|
|
3912
|
-
let
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
6786
|
+
function dateFromSerial(serial, options) {
|
|
6787
|
+
let date = serial | 0;
|
|
6788
|
+
const fractionalSeconds = DAYSIZE * (serial - date);
|
|
6789
|
+
let time = floor(fractionalSeconds);
|
|
6790
|
+
if (fractionalSeconds - time > .9999) {
|
|
6791
|
+
time += 1;
|
|
6792
|
+
if (time === DAYSIZE) {
|
|
6793
|
+
time = 0;
|
|
6794
|
+
date += 1;
|
|
6795
|
+
}
|
|
6796
|
+
}
|
|
6797
|
+
const normalizedTime = time < 0 ? DAYSIZE + time : time;
|
|
6798
|
+
const [year, month, day] = toYMD(serial, 0, options === null || options === void 0 ? void 0 : options.leap1900);
|
|
6799
|
+
return [
|
|
6800
|
+
year,
|
|
6801
|
+
month,
|
|
6802
|
+
day,
|
|
6803
|
+
floor(normalizedTime / 60 / 60) % 60,
|
|
6804
|
+
floor(normalizedTime / 60) % 60,
|
|
6805
|
+
floor(normalizedTime) % 60
|
|
6806
|
+
];
|
|
6807
|
+
}
|
|
6808
|
+
|
|
6809
|
+
//#endregion
|
|
6810
|
+
//#region src/shared/numfmt/parse-value.ts
|
|
6811
|
+
const okDateFormats = [
|
|
6812
|
+
"!d-m-y",
|
|
6813
|
+
"!d-m-Y",
|
|
6814
|
+
"!j-m-y",
|
|
6815
|
+
"!j-m-Y",
|
|
6816
|
+
"!d-n-y",
|
|
6817
|
+
"!d-n-Y",
|
|
6818
|
+
"!j-n-y",
|
|
6819
|
+
"!j-n-Y",
|
|
6820
|
+
"?m-d-y",
|
|
6821
|
+
"?m-d-Y",
|
|
6822
|
+
"?m-j-y",
|
|
6823
|
+
"?m-j-Y",
|
|
6824
|
+
"?n-d-y",
|
|
6825
|
+
"?n-d-Y",
|
|
6826
|
+
"?n-j-y",
|
|
6827
|
+
"?n-j-Y",
|
|
6828
|
+
"d-M-y",
|
|
6829
|
+
"d-M-Y",
|
|
6830
|
+
"j-M-y",
|
|
6831
|
+
"j-M-Y",
|
|
6832
|
+
"M-d-y",
|
|
6833
|
+
"M-d-Y",
|
|
6834
|
+
"M-j-y",
|
|
6835
|
+
"M-j-Y",
|
|
6836
|
+
"d-F-y",
|
|
6837
|
+
"d-F-Y",
|
|
6838
|
+
"F-d-y",
|
|
6839
|
+
"F-d-Y",
|
|
6840
|
+
"F-j-y",
|
|
6841
|
+
"F-j-Y",
|
|
6842
|
+
"j-F-y",
|
|
6843
|
+
"j-F-Y",
|
|
6844
|
+
"y-F-d",
|
|
6845
|
+
"y-F-j",
|
|
6846
|
+
"y-M-d",
|
|
6847
|
+
"y-M-j",
|
|
6848
|
+
"Y-F-d",
|
|
6849
|
+
"Y-F-j",
|
|
6850
|
+
"Y-M-d",
|
|
6851
|
+
"Y-m-d",
|
|
6852
|
+
"Y-M-j",
|
|
6853
|
+
"Y-m-j",
|
|
6854
|
+
"Y-n-d",
|
|
6855
|
+
"Y-n-j",
|
|
6856
|
+
"j-F",
|
|
6857
|
+
"j-M",
|
|
6858
|
+
"d-F",
|
|
6859
|
+
"d-M",
|
|
6860
|
+
"n-d",
|
|
6861
|
+
"n-j",
|
|
6862
|
+
"n-Y",
|
|
6863
|
+
"m-d",
|
|
6864
|
+
"m-j",
|
|
6865
|
+
"m-Y",
|
|
6866
|
+
"M-Y",
|
|
6867
|
+
"M-y",
|
|
6868
|
+
"F-y",
|
|
6869
|
+
"F-Y",
|
|
6870
|
+
"Y-M",
|
|
6871
|
+
"Y-n",
|
|
6872
|
+
"Y-m",
|
|
6873
|
+
"Y-F",
|
|
6874
|
+
"Y-M"
|
|
6875
|
+
];
|
|
6876
|
+
const tx0 = {
|
|
6877
|
+
j: "d",
|
|
6878
|
+
d: "d",
|
|
6879
|
+
D: "ddd",
|
|
6880
|
+
l: "dddd",
|
|
6881
|
+
n: "m",
|
|
6882
|
+
m: "m",
|
|
6883
|
+
M: "mmm",
|
|
6884
|
+
F: "mmmm",
|
|
6885
|
+
y: "yy",
|
|
6886
|
+
Y: "yyyy"
|
|
6887
|
+
};
|
|
6888
|
+
const tx00 = {
|
|
6889
|
+
j: "dd",
|
|
6890
|
+
d: "dd",
|
|
6891
|
+
D: "ddd",
|
|
6892
|
+
l: "dddd",
|
|
6893
|
+
n: "mm",
|
|
6894
|
+
m: "mm",
|
|
6895
|
+
M: "mmm",
|
|
6896
|
+
F: "mmmm",
|
|
6897
|
+
y: "yy",
|
|
6898
|
+
Y: "yyyy"
|
|
6899
|
+
};
|
|
6900
|
+
const dateTrieDM = {};
|
|
6901
|
+
const dateTrieMD = {};
|
|
6902
|
+
function packDate(format, node, allowType = 1) {
|
|
6903
|
+
if (format) {
|
|
6904
|
+
const char = format[0];
|
|
6905
|
+
const next = format.slice(1);
|
|
6906
|
+
if (char === "!") packDate(next, node, 4);
|
|
6907
|
+
else if (char === "?") packDate(next, node, 2);
|
|
6908
|
+
else {
|
|
6909
|
+
let branch = node[char];
|
|
6910
|
+
if (typeof branch !== "object") {
|
|
6911
|
+
branch = {};
|
|
6912
|
+
node[char] = branch;
|
|
6913
|
+
}
|
|
6914
|
+
packDate(next, branch, allowType);
|
|
6915
|
+
}
|
|
6916
|
+
} else node.$ = allowType;
|
|
6917
|
+
}
|
|
6918
|
+
function addFormatToTrie(format, trie) {
|
|
6919
|
+
packDate(format, trie);
|
|
6920
|
+
packDate(`${format} x`, trie);
|
|
6921
|
+
packDate(`${format} l`, trie);
|
|
6922
|
+
packDate(`${format} l x`, trie);
|
|
6923
|
+
packDate(`l ${format}`, trie);
|
|
6924
|
+
packDate(`l ${format} x`, trie);
|
|
6925
|
+
packDate(`${format} D`, trie);
|
|
6926
|
+
packDate(`${format} D x`, trie);
|
|
6927
|
+
packDate(`D ${format}`, trie);
|
|
6928
|
+
packDate(`D ${format} x`, trie);
|
|
6929
|
+
}
|
|
6930
|
+
okDateFormats.forEach((format) => {
|
|
6931
|
+
if (!format.startsWith("?")) addFormatToTrie(format, dateTrieDM);
|
|
6932
|
+
if (!format.startsWith("!")) addFormatToTrie(format, dateTrieMD);
|
|
6933
|
+
});
|
|
6934
|
+
const currentYear = (/* @__PURE__ */ new Date()).getUTCFullYear();
|
|
6935
|
+
const PT = ".";
|
|
6936
|
+
const CM = ",";
|
|
6937
|
+
const SP = " ";
|
|
6938
|
+
const NS = "\xA0";
|
|
6939
|
+
const NN = " ";
|
|
6940
|
+
const AP = "'";
|
|
6941
|
+
const AG = "٬";
|
|
6942
|
+
const dec2group = {
|
|
6943
|
+
".": [
|
|
6944
|
+
CM,
|
|
6945
|
+
NS,
|
|
6946
|
+
NN,
|
|
6947
|
+
AP,
|
|
6948
|
+
AG
|
|
6949
|
+
],
|
|
6950
|
+
",": [
|
|
6951
|
+
PT,
|
|
6952
|
+
NS,
|
|
6953
|
+
NN,
|
|
6954
|
+
AP,
|
|
6955
|
+
AG
|
|
6956
|
+
],
|
|
6957
|
+
"٫": [
|
|
6958
|
+
PT,
|
|
6959
|
+
NS,
|
|
6960
|
+
NN,
|
|
6961
|
+
AP,
|
|
6962
|
+
AG
|
|
6963
|
+
]
|
|
6964
|
+
};
|
|
6965
|
+
const isDigit = (digit) => (digit === null || digit === void 0 ? void 0 : digit.length) === 1 && digit >= "0" && digit <= "9";
|
|
6966
|
+
/** Parse a numeric string and return its value and inferred format. */
|
|
6967
|
+
function parseNumber(value, options = {}) {
|
|
6968
|
+
const l10n = getLocale(options.locale || "") || defaultLocale;
|
|
6969
|
+
const decimal = l10n.decimal;
|
|
6970
|
+
const groupingChars = [...dec2group[decimal] || [AP, AG]];
|
|
6971
|
+
if (!groupingChars.includes(l10n.group) && l10n.group !== SP && l10n.group !== decimal) groupingChars.push(l10n.group);
|
|
6972
|
+
let number = "";
|
|
6973
|
+
let exponent = "";
|
|
6974
|
+
let sign = 1;
|
|
6975
|
+
let format = "";
|
|
6976
|
+
let minus = false;
|
|
6977
|
+
let openParen = false;
|
|
6978
|
+
let closeParen = false;
|
|
6979
|
+
let percent = false;
|
|
6980
|
+
let currency = false;
|
|
6981
|
+
let currencySymbol = "";
|
|
6982
|
+
let currencyTrailing = false;
|
|
6983
|
+
let index = 0;
|
|
6984
|
+
const prefixChars = [
|
|
6985
|
+
SP,
|
|
6986
|
+
NS,
|
|
6987
|
+
NN,
|
|
6988
|
+
"+",
|
|
6989
|
+
"%",
|
|
6990
|
+
"(",
|
|
6991
|
+
"-"
|
|
6992
|
+
].concat(currencySymbols$1);
|
|
6993
|
+
while (prefixChars.includes(value.charAt(index))) {
|
|
6994
|
+
const char = value.charAt(index);
|
|
6995
|
+
if (char === "-") {
|
|
6996
|
+
if (minus || openParen) return null;
|
|
6997
|
+
minus = true;
|
|
6998
|
+
sign = -1;
|
|
6999
|
+
} else if (reCurrencySymbols.test(char)) {
|
|
7000
|
+
if (currency) return null;
|
|
7001
|
+
currency = true;
|
|
7002
|
+
currencySymbol = char;
|
|
7003
|
+
} else if (char === "(") {
|
|
7004
|
+
if (openParen || minus) return null;
|
|
7005
|
+
openParen = true;
|
|
7006
|
+
sign = -1;
|
|
7007
|
+
} else if (char === "%") {
|
|
7008
|
+
if (percent) return null;
|
|
7009
|
+
percent = true;
|
|
7010
|
+
}
|
|
7011
|
+
index++;
|
|
7012
|
+
}
|
|
7013
|
+
let haveDecimal = false;
|
|
7014
|
+
let grouping;
|
|
7015
|
+
if (value.charAt(index) === decimal || isDigit(value.charAt(index))) while (index < value.length) {
|
|
7016
|
+
const char = value.charAt(index);
|
|
7017
|
+
if (!grouping && groupingChars.includes(char)) grouping = char;
|
|
7018
|
+
else if (grouping && grouping === char) {} else if (char === decimal) {
|
|
7019
|
+
if (haveDecimal) break;
|
|
7020
|
+
number += ".";
|
|
7021
|
+
haveDecimal = true;
|
|
7022
|
+
} else if (isDigit(char)) number += char;
|
|
7023
|
+
else break;
|
|
7024
|
+
index++;
|
|
7025
|
+
}
|
|
7026
|
+
if (value.charAt(index) === "e" || value.charAt(index) === "E") {
|
|
7027
|
+
exponent += value.charAt(index);
|
|
7028
|
+
index++;
|
|
7029
|
+
if (value.charAt(index) === "+" || value.charAt(index) === "-") {
|
|
7030
|
+
exponent += value.charAt(index);
|
|
7031
|
+
index++;
|
|
3935
7032
|
}
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
mergeColumn = startColumnMarge;
|
|
3941
|
-
isMerged = true;
|
|
3942
|
-
break;
|
|
7033
|
+
const exponentStart = index;
|
|
7034
|
+
while (isDigit(value.charAt(index))) {
|
|
7035
|
+
exponent += value.charAt(index);
|
|
7036
|
+
index++;
|
|
3943
7037
|
}
|
|
7038
|
+
if (exponentStart === index) return null;
|
|
7039
|
+
}
|
|
7040
|
+
const suffixChars = [
|
|
7041
|
+
SP,
|
|
7042
|
+
NS,
|
|
7043
|
+
NN,
|
|
7044
|
+
"%",
|
|
7045
|
+
"$",
|
|
7046
|
+
")"
|
|
7047
|
+
].concat(currencySymbols$1);
|
|
7048
|
+
while (suffixChars.includes(value.charAt(index))) {
|
|
7049
|
+
const char = value.charAt(index);
|
|
7050
|
+
if (reCurrencySymbols.test(char)) {
|
|
7051
|
+
if (currency) return null;
|
|
7052
|
+
currency = true;
|
|
7053
|
+
currencySymbol = char;
|
|
7054
|
+
currencyTrailing = true;
|
|
7055
|
+
} else if (char === ")") {
|
|
7056
|
+
if (closeParen || !openParen) return null;
|
|
7057
|
+
closeParen = true;
|
|
7058
|
+
} else if (char === "%") {
|
|
7059
|
+
if (percent) return null;
|
|
7060
|
+
percent = true;
|
|
7061
|
+
}
|
|
7062
|
+
index++;
|
|
7063
|
+
}
|
|
7064
|
+
if (index !== value.length) return null;
|
|
7065
|
+
let numberValue = Number.parseFloat(number + exponent);
|
|
7066
|
+
if (!Number.isFinite(numberValue)) return null;
|
|
7067
|
+
if (exponent) {
|
|
7068
|
+
if (percent || currency) return null;
|
|
7069
|
+
format = "0.00E+00";
|
|
7070
|
+
} else if (percent) {
|
|
7071
|
+
if (currency) return null;
|
|
7072
|
+
format = number.includes(".") ? "0.00%" : "0%";
|
|
7073
|
+
numberValue *= .01;
|
|
7074
|
+
} else if (currency) {
|
|
7075
|
+
const currencyFormat = number.includes(".") ? "#,##0.00" : "#,##0";
|
|
7076
|
+
format = currencyTrailing ? currencyFormat + currencySymbol : currencySymbol + currencyFormat;
|
|
7077
|
+
} else if (grouping) format = number.includes(".") ? "#,##0.00" : "#,##0";
|
|
7078
|
+
const result = { v: numberValue * sign };
|
|
7079
|
+
if (format) result.z = format;
|
|
7080
|
+
return result;
|
|
7081
|
+
}
|
|
7082
|
+
function isValidDate(year, month, day) {
|
|
7083
|
+
if (day < 1) return false;
|
|
7084
|
+
if (month < 1 || month > 12) return false;
|
|
7085
|
+
if (month === 2) {
|
|
7086
|
+
if (day > (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0 || year === 1900 ? 29 : 28)) return false;
|
|
7087
|
+
} else if ((month === 4 || month === 6 || month === 9 || month === 11) && day > 30 || (month === 1 || month === 3 || month === 5 || month === 7 || month === 8 || month === 10 || month === 12) && day > 31) return false;
|
|
7088
|
+
return true;
|
|
7089
|
+
}
|
|
7090
|
+
const matchRec = (string, data, skipPeriod = false) => {
|
|
7091
|
+
for (const item of data) if (string.startsWith(item[0])) {
|
|
7092
|
+
let length = item[0].length;
|
|
7093
|
+
if (skipPeriod && (item[2] === "D" || item[2] === "M") && string[length] === ".") length++;
|
|
7094
|
+
return [string.slice(0, length), item];
|
|
7095
|
+
}
|
|
7096
|
+
return ["", null];
|
|
7097
|
+
};
|
|
7098
|
+
const nextToken = (string, node, data, localeData) => {
|
|
7099
|
+
const path = data.path || "";
|
|
7100
|
+
const matchOrder = Object.keys(node);
|
|
7101
|
+
for (const token of matchOrder) {
|
|
7102
|
+
const branch = node[token];
|
|
7103
|
+
let result;
|
|
7104
|
+
if (!branch) continue;
|
|
7105
|
+
if (token === "$" || token === "€") {
|
|
7106
|
+
if (!string) result = data;
|
|
7107
|
+
} else {
|
|
7108
|
+
if (typeof branch !== "object") continue;
|
|
7109
|
+
if (token === "-") {
|
|
7110
|
+
const match = /^(\s*([./-]|,\s)\s*|\s+)/.exec(string);
|
|
7111
|
+
if (match) {
|
|
7112
|
+
const separator = match[1] === "-" || match[1] === "/" || match[1] === "." ? match[1] : " ";
|
|
7113
|
+
if (!data.sep || data.sep === separator) {
|
|
7114
|
+
const normalizedSeparator = match[0].replace(/\s+/g, " ");
|
|
7115
|
+
result = nextToken(string.slice(match[0].length), branch, {
|
|
7116
|
+
...data,
|
|
7117
|
+
sep: separator,
|
|
7118
|
+
path: path + normalizedSeparator
|
|
7119
|
+
}, localeData);
|
|
7120
|
+
}
|
|
7121
|
+
}
|
|
7122
|
+
} else if (token === " ") {
|
|
7123
|
+
const match = /^[,.]?\s+/.exec(string);
|
|
7124
|
+
if (match) {
|
|
7125
|
+
const normalizedSeparator = match[0].replace(/\s+/g, " ");
|
|
7126
|
+
result = nextToken(string.slice(match[0].length), branch, {
|
|
7127
|
+
...data,
|
|
7128
|
+
path: path + normalizedSeparator
|
|
7129
|
+
}, localeData);
|
|
7130
|
+
}
|
|
7131
|
+
} else if (token === "j" || token === "d") {
|
|
7132
|
+
const match = /^(0?[1-9]|1\d|2\d|3[01])\b/.exec(string);
|
|
7133
|
+
if (match) result = nextToken(string.slice(match[0].length), branch, {
|
|
7134
|
+
...data,
|
|
7135
|
+
day: match[0],
|
|
7136
|
+
path: path + token
|
|
7137
|
+
}, localeData);
|
|
7138
|
+
} else if (token === "n" || token === "m") {
|
|
7139
|
+
const match = /^(0?[1-9]|1[012])\b/.exec(string);
|
|
7140
|
+
if (match) result = nextToken(string.slice(match[0].length), branch, {
|
|
7141
|
+
...data,
|
|
7142
|
+
month: +match[0],
|
|
7143
|
+
_mon: match[0],
|
|
7144
|
+
path: path + token
|
|
7145
|
+
}, localeData);
|
|
7146
|
+
} else if (token === "F" || token === "M") {
|
|
7147
|
+
const [matchedText, match] = matchRec(string, localeData.mon, localeData.mp);
|
|
7148
|
+
if ((match === null || match === void 0 ? void 0 : match[2]) === token) result = nextToken(string.slice(matchedText.length), branch, {
|
|
7149
|
+
...data,
|
|
7150
|
+
month: match[1],
|
|
7151
|
+
_mon: matchedText,
|
|
7152
|
+
path: path + token
|
|
7153
|
+
}, localeData);
|
|
7154
|
+
} else if (token === "l" || token === "D") {
|
|
7155
|
+
const [matchedText, match] = matchRec(string, localeData.day, localeData.dp);
|
|
7156
|
+
if ((match === null || match === void 0 ? void 0 : match[2]) === token) result = nextToken(string.slice(matchedText.length), branch, {
|
|
7157
|
+
...data,
|
|
7158
|
+
path: path + token
|
|
7159
|
+
}, localeData);
|
|
7160
|
+
} else if (token === "y") {
|
|
7161
|
+
const match = /^\d\d\b/.exec(string);
|
|
7162
|
+
if (match) {
|
|
7163
|
+
const year = +match[0] >= 30 ? +match[0] + 1900 : +match[0] + 2e3;
|
|
7164
|
+
result = nextToken(string.slice(match[0].length), branch, {
|
|
7165
|
+
...data,
|
|
7166
|
+
year,
|
|
7167
|
+
path: path + token
|
|
7168
|
+
}, localeData);
|
|
7169
|
+
}
|
|
7170
|
+
} else if (token === "Y") {
|
|
7171
|
+
const match = /^\d\d\d\d\b/.exec(string);
|
|
7172
|
+
if (match) result = nextToken(string.slice(match[0].length), branch, {
|
|
7173
|
+
...data,
|
|
7174
|
+
year: +match[0],
|
|
7175
|
+
path: path + token
|
|
7176
|
+
}, localeData);
|
|
7177
|
+
} else if (token === "x") {
|
|
7178
|
+
const time = parseTime(string, { locale: localeData.locale });
|
|
7179
|
+
if (time) result = nextToken("", branch, {
|
|
7180
|
+
...data,
|
|
7181
|
+
time: time.v,
|
|
7182
|
+
tf: time.z,
|
|
7183
|
+
path: path + token
|
|
7184
|
+
}, localeData);
|
|
7185
|
+
} else throw new Error(`Unknown date token "${token}"`);
|
|
7186
|
+
}
|
|
7187
|
+
if (result && isValidDate(data.year || 1916, data.month || 1, data.day ? +data.day : 1)) return result;
|
|
3944
7188
|
}
|
|
7189
|
+
};
|
|
7190
|
+
const normDateStr = (string) => string.replace(/\s+/g, " ").trim().replace(/’/, "'").replace(/\.$/, "").toLowerCase();
|
|
7191
|
+
const getLookups = (values, symbol) => {
|
|
7192
|
+
const lookups = values.map((value, index) => [
|
|
7193
|
+
normDateStr(value),
|
|
7194
|
+
index + 1,
|
|
7195
|
+
symbol
|
|
7196
|
+
]);
|
|
7197
|
+
lookups.sort((a, b) => b[0].length - a[0].length);
|
|
7198
|
+
return lookups;
|
|
7199
|
+
};
|
|
7200
|
+
/** Parse a date or datetime string and return its serial value and format. */
|
|
7201
|
+
function parseDate(value, options = {}) {
|
|
7202
|
+
var _date$year, _date$day;
|
|
7203
|
+
const l10n = getLocale(options.locale || "") || defaultLocale;
|
|
7204
|
+
const localeData = {
|
|
7205
|
+
mon: getLookups(l10n.mmmm, "F").concat(getLookups(l10n.mmm, "M")),
|
|
7206
|
+
mp: l10n.mmm[0].at(-1) === ".",
|
|
7207
|
+
day: getLookups(l10n.dddd, "l").concat(getLookups(l10n.ddd, "D")),
|
|
7208
|
+
dp: l10n.ddd[0].at(-1) === ".",
|
|
7209
|
+
locale: options.locale
|
|
7210
|
+
};
|
|
7211
|
+
const date = nextToken(normDateStr(value), l10n.preferMDY ? dateTrieMD : dateTrieDM, { path: "" }, localeData);
|
|
7212
|
+
if (!date) return null;
|
|
7213
|
+
if (date.sep === "." && date.path.length === 3) return null;
|
|
7214
|
+
if (date.month == null || date._mon == null) return null;
|
|
7215
|
+
const year = +((_date$year = date.year) !== null && _date$year !== void 0 ? _date$year : currentYear);
|
|
7216
|
+
const day = (_date$day = date.day) !== null && _date$day !== void 0 ? _date$day : "1";
|
|
7217
|
+
let epoch = -Infinity;
|
|
7218
|
+
if (year < 1900) return null;
|
|
7219
|
+
else if (year <= 1900 && date.month <= 2) epoch = 25568;
|
|
7220
|
+
else if (year < 1e4) epoch = 25569;
|
|
7221
|
+
const dateValue = Date.UTC(year, date.month - 1, +day) / 864e5 + epoch + (date.time || 0);
|
|
7222
|
+
if (dateValue < 0 || dateValue > 2958465) return null;
|
|
7223
|
+
const lead0 = date._mon[0] === "0" || day[0] === "0" || date._mon.length === 2 && day.length === 2;
|
|
3945
7224
|
return {
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
endColumn: newEndColumn,
|
|
3952
|
-
startRow: mergeRow,
|
|
3953
|
-
startColumn: mergeColumn
|
|
7225
|
+
v: dateValue,
|
|
7226
|
+
z: date.path.replace(/[jdlDnmMFyYx]/g, (token) => {
|
|
7227
|
+
if (token === "x") return date.tf || "";
|
|
7228
|
+
return (lead0 ? tx00[token] : tx0[token]) || token;
|
|
7229
|
+
})
|
|
3954
7230
|
};
|
|
3955
7231
|
}
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
7232
|
+
const normAMPMStr = (string) => string.replace(/\s+/g, "").trim().replace(/\./g, "").toLowerCase();
|
|
7233
|
+
/** Parse a time string and return its day fraction and inferred format. */
|
|
7234
|
+
function parseTime(value, options = {}) {
|
|
7235
|
+
const l10n = getLocale(options.locale || "") || defaultLocale;
|
|
7236
|
+
const parts = /^\s*([10]?\d|2[0-4])(?::([0-5]\d|\d))?(?::([0-5]\d|\d))?(\.\d{1,10})?(?=\s*[^\s\d]|$)/.exec(value);
|
|
7237
|
+
let ampm = "";
|
|
7238
|
+
if (parts) {
|
|
7239
|
+
const tail = normAMPMStr(value.slice(parts[0].length));
|
|
7240
|
+
if (tail === normAMPMStr(l10n.ampm[0]) || tail === "a" || tail === "am") ampm = "a";
|
|
7241
|
+
else if (tail === normAMPMStr(l10n.ampm[1]) || tail === "p" || tail === "pm") ampm = "p";
|
|
7242
|
+
else if (tail === ":") {
|
|
7243
|
+
if (!parts[3]) parts[3] = "0";
|
|
7244
|
+
if (!parts[2]) parts[2] = "0";
|
|
7245
|
+
} else if (tail) return null;
|
|
7246
|
+
}
|
|
7247
|
+
if (!parts) return null;
|
|
7248
|
+
const [, hoursPart, minutesPart, secondsPart, fractionPart] = parts;
|
|
7249
|
+
if (fractionPart && !secondsPart) return null;
|
|
7250
|
+
if (!ampm && !minutesPart && !secondsPart) return null;
|
|
7251
|
+
let hours = +(hoursPart || 0);
|
|
7252
|
+
if (ampm) {
|
|
7253
|
+
if (hours >= 13) return null;
|
|
7254
|
+
if (ampm === "a") {
|
|
7255
|
+
if (hours === 12) hours = 0;
|
|
7256
|
+
} else if (ampm === "p" && hours !== 12) hours += 12;
|
|
7257
|
+
}
|
|
7258
|
+
const minutes = +(minutesPart || 0);
|
|
7259
|
+
const seconds = +(secondsPart || 0);
|
|
7260
|
+
const milliseconds = +(fractionPart || 0);
|
|
7261
|
+
const hourFormat = hoursPart.length === 2 ? "hh" : "h";
|
|
7262
|
+
const secondsFormat = secondsPart ? ":ss" : "";
|
|
7263
|
+
const ampmFormat = ampm ? " AM/PM" : "";
|
|
7264
|
+
return {
|
|
7265
|
+
v: (hours * 60 * 60 + minutes * 60 + seconds + milliseconds) / (3600 * 24),
|
|
7266
|
+
z: `${hourFormat}:mm${secondsFormat}${ampmFormat}`
|
|
7267
|
+
};
|
|
7268
|
+
}
|
|
7269
|
+
/** Parse a localized or English boolean string. */
|
|
7270
|
+
function parseBool(value, options = {}) {
|
|
7271
|
+
const l10n = getLocale(options.locale || "") || defaultLocale;
|
|
7272
|
+
const normalizedValue = value.trim().toLowerCase();
|
|
7273
|
+
const localizedTrue = l10n.bool[0].toLowerCase();
|
|
7274
|
+
if (normalizedValue === "true" || normalizedValue === localizedTrue) return { v: true };
|
|
7275
|
+
const localizedFalse = l10n.bool[1].toLowerCase();
|
|
7276
|
+
if (normalizedValue === "false" || normalizedValue === localizedFalse) return { v: false };
|
|
7277
|
+
return null;
|
|
7278
|
+
}
|
|
7279
|
+
/** Parse a spreadsheet input as a number, date, time, or boolean. */
|
|
7280
|
+
function parseValue(value, options) {
|
|
7281
|
+
var _ref, _ref2, _parseNumber;
|
|
7282
|
+
return (_ref = (_ref2 = (_parseNumber = parseNumber(value, options)) !== null && _parseNumber !== void 0 ? _parseNumber : parseDate(value, options)) !== null && _ref2 !== void 0 ? _ref2 : parseTime(value, options)) !== null && _ref !== void 0 ? _ref : parseBool(value, options);
|
|
7283
|
+
}
|
|
3962
7284
|
|
|
3963
7285
|
//#endregion
|
|
3964
|
-
//#region src/
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
7286
|
+
//#region src/shared/numfmt/api.ts
|
|
7287
|
+
var api_exports = /* @__PURE__ */ __exportAll({
|
|
7288
|
+
addLocale: () => addLocale,
|
|
7289
|
+
dateFromSerial: () => dateFromSerial,
|
|
7290
|
+
dateToSerial: () => dateToSerial,
|
|
7291
|
+
dec2frac: () => dec2frac,
|
|
7292
|
+
format: () => format,
|
|
7293
|
+
formatColor: () => formatColor,
|
|
7294
|
+
getFormatDateInfo: () => getFormatDateInfo,
|
|
7295
|
+
getFormatInfo: () => getFormatInfo,
|
|
7296
|
+
getLocale: () => getLocale,
|
|
7297
|
+
isDateFormat: () => isDateFormat,
|
|
7298
|
+
isPercentFormat: () => isPercentFormat,
|
|
7299
|
+
isTextFormat: () => isTextFormat$1,
|
|
7300
|
+
isValidFormat: () => isValidFormat,
|
|
7301
|
+
parseBool: () => parseBool,
|
|
7302
|
+
parseDate: () => parseDate,
|
|
7303
|
+
parseLocale: () => parseLocale,
|
|
7304
|
+
parseNumber: () => parseNumber,
|
|
7305
|
+
parseTime: () => parseTime,
|
|
7306
|
+
parseValue: () => parseValue,
|
|
7307
|
+
round: () => round,
|
|
7308
|
+
tokenTypes: () => tokenTypes,
|
|
7309
|
+
tokenize: () => tokenize
|
|
7310
|
+
});
|
|
7311
|
+
const parseDataCache = Object.create({});
|
|
7312
|
+
function prepareFormatterData(pattern, shouldThrow = false) {
|
|
7313
|
+
const normalizedPattern = pattern || "General";
|
|
7314
|
+
let parseData = parseDataCache[normalizedPattern];
|
|
7315
|
+
if (!parseData) try {
|
|
7316
|
+
parseData = parsePattern(normalizedPattern);
|
|
7317
|
+
parseDataCache[normalizedPattern] = parseData;
|
|
7318
|
+
} catch (error) {
|
|
7319
|
+
if (shouldThrow) throw error;
|
|
7320
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
7321
|
+
const errorPart = {
|
|
7322
|
+
tokens: [{ type: "error" }],
|
|
7323
|
+
error: message
|
|
7324
|
+
};
|
|
7325
|
+
parseData = {
|
|
7326
|
+
pattern: normalizedPattern,
|
|
7327
|
+
partitions: [
|
|
7328
|
+
errorPart,
|
|
7329
|
+
errorPart,
|
|
7330
|
+
errorPart,
|
|
7331
|
+
errorPart
|
|
7332
|
+
],
|
|
7333
|
+
error: message,
|
|
7334
|
+
locale: null
|
|
7335
|
+
};
|
|
7336
|
+
}
|
|
7337
|
+
return parseData;
|
|
7338
|
+
}
|
|
7339
|
+
/**
|
|
7340
|
+
* Formats a value as a string and returns the result.
|
|
7341
|
+
*/
|
|
7342
|
+
function format(pattern, value, options = {}) {
|
|
7343
|
+
var _handleDates;
|
|
7344
|
+
const resolvedOptions = Object.assign({}, defaultOptions, options);
|
|
7345
|
+
const data = prepareFormatterData(pattern, resolvedOptions.throws);
|
|
7346
|
+
return formatValue((_handleDates = dateToSerial(value, resolvedOptions)) !== null && _handleDates !== void 0 ? _handleDates : value, data, resolvedOptions);
|
|
7347
|
+
}
|
|
7348
|
+
/**
|
|
7349
|
+
* Find the color appropriate to a value as dictated by a format pattern.
|
|
7350
|
+
*/
|
|
7351
|
+
function formatColor(pattern, value, options) {
|
|
7352
|
+
var _handleDates2;
|
|
7353
|
+
const resolvedOptions = Object.assign({}, defaultOptions, options);
|
|
7354
|
+
const data = prepareFormatterData(pattern, resolvedOptions.throws);
|
|
7355
|
+
return formatColor$1((_handleDates2 = dateToSerial(value, resolvedOptions)) !== null && _handleDates2 !== void 0 ? _handleDates2 : value, data, resolvedOptions);
|
|
7356
|
+
}
|
|
7357
|
+
/** Determine if a given format pattern is a date pattern. */
|
|
7358
|
+
function isDateFormat(pattern) {
|
|
7359
|
+
return isDate(prepareFormatterData(pattern, false).partitions);
|
|
7360
|
+
}
|
|
7361
|
+
/** Determine if a given format pattern is a percentage pattern. */
|
|
7362
|
+
function isPercentFormat(pattern) {
|
|
7363
|
+
return isPercent(prepareFormatterData(pattern, false).partitions);
|
|
7364
|
+
}
|
|
7365
|
+
/** Determine if a given format pattern is a text only pattern. */
|
|
7366
|
+
function isTextFormat$1(pattern) {
|
|
7367
|
+
return isText(prepareFormatterData(pattern, false).partitions);
|
|
7368
|
+
}
|
|
7369
|
+
/** Determine if a given format pattern is valid. */
|
|
7370
|
+
function isValidFormat(pattern) {
|
|
7371
|
+
try {
|
|
7372
|
+
prepareFormatterData(pattern, true);
|
|
7373
|
+
return true;
|
|
7374
|
+
} catch {
|
|
7375
|
+
return false;
|
|
7376
|
+
}
|
|
7377
|
+
}
|
|
7378
|
+
/** Returns metadata describing a parsed format pattern. */
|
|
7379
|
+
function getFormatInfo(pattern, options = {}) {
|
|
7380
|
+
const data = prepareFormatterData(pattern, false);
|
|
7381
|
+
if (!data.info) data.info = info(data.partitions, options === null || options === void 0 ? void 0 : options.currency);
|
|
7382
|
+
return data.info;
|
|
7383
|
+
}
|
|
7384
|
+
/** Gets information about date codes used in a format string. */
|
|
7385
|
+
function getFormatDateInfo(pattern) {
|
|
7386
|
+
const data = prepareFormatterData(pattern, false);
|
|
7387
|
+
if (!data.dateInfo) data.dateInfo = dateInfo(data.partitions);
|
|
7388
|
+
return data.dateInfo;
|
|
7389
|
+
}
|
|
7390
|
+
/** A dictionary of the types used to identify token variants. */
|
|
7391
|
+
const tokenTypes = Object.freeze({
|
|
7392
|
+
AMPM: TOKEN_AMPM,
|
|
7393
|
+
BREAK: TOKEN_BREAK,
|
|
7394
|
+
CALENDAR: TOKEN_CALENDAR,
|
|
7395
|
+
CHAR: TOKEN_CHAR,
|
|
7396
|
+
COLOR: TOKEN_COLOR,
|
|
7397
|
+
COMMA: TOKEN_COMMA,
|
|
7398
|
+
CONDITION: TOKEN_CONDITION,
|
|
7399
|
+
DATETIME: TOKEN_DATETIME,
|
|
7400
|
+
DBNUM: TOKEN_DBNUM,
|
|
7401
|
+
DIGIT: TOKEN_DIGIT,
|
|
7402
|
+
DURATION: TOKEN_DURATION,
|
|
7403
|
+
ERROR: TOKEN_ERROR,
|
|
7404
|
+
ESCAPED: TOKEN_ESCAPED,
|
|
7405
|
+
EXP: "exp",
|
|
7406
|
+
FILL: TOKEN_FILL,
|
|
7407
|
+
GENERAL: TOKEN_GENERAL,
|
|
7408
|
+
GROUP: TOKEN_GROUP,
|
|
7409
|
+
HASH: TOKEN_HASH,
|
|
7410
|
+
LOCALE: TOKEN_LOCALE,
|
|
7411
|
+
MINUS: TOKEN_MINUS,
|
|
7412
|
+
MODIFIER: TOKEN_MODIFIER,
|
|
7413
|
+
NATNUM: TOKEN_NATNUM,
|
|
7414
|
+
PAREN: TOKEN_PAREN,
|
|
7415
|
+
PERCENT: TOKEN_PERCENT,
|
|
7416
|
+
PLUS: TOKEN_PLUS,
|
|
7417
|
+
POINT: TOKEN_POINT,
|
|
7418
|
+
QMARK: TOKEN_QMARK,
|
|
7419
|
+
SCALE: TOKEN_SCALE,
|
|
7420
|
+
SKIP: TOKEN_SKIP,
|
|
7421
|
+
SLASH: TOKEN_SLASH,
|
|
7422
|
+
SPACE: TOKEN_SPACE,
|
|
7423
|
+
STRING: TOKEN_STRING,
|
|
7424
|
+
TEXT: TOKEN_TEXT,
|
|
7425
|
+
ZERO: TOKEN_ZERO
|
|
7426
|
+
});
|
|
3979
7427
|
|
|
3980
7428
|
//#endregion
|
|
3981
7429
|
//#region src/common/regexp/factory.ts
|
|
@@ -4291,22 +7739,7 @@ const regexp = {
|
|
|
4291
7739
|
};
|
|
4292
7740
|
|
|
4293
7741
|
//#endregion
|
|
4294
|
-
//#region src/shared/numfmt.ts
|
|
4295
|
-
/**
|
|
4296
|
-
* Copyright 2023-present DreamNum Co., Ltd.
|
|
4297
|
-
*
|
|
4298
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4299
|
-
* you may not use this file except in compliance with the License.
|
|
4300
|
-
* You may obtain a copy of the License at
|
|
4301
|
-
*
|
|
4302
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4303
|
-
*
|
|
4304
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
4305
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4306
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4307
|
-
* See the License for the specific language governing permissions and
|
|
4308
|
-
* limitations under the License.
|
|
4309
|
-
*/
|
|
7742
|
+
//#region src/shared/numfmt/utils.ts
|
|
4310
7743
|
const DEFAULT_TEXT_FORMAT = "@@@";
|
|
4311
7744
|
const DEFAULT_TEXT_FORMAT_EXCEL = "@";
|
|
4312
7745
|
const DEFAULT_NUMBER_FORMAT = "General";
|
|
@@ -4324,22 +7757,22 @@ function isDefaultFormat(pattern) {
|
|
|
4324
7757
|
const isPatternEqualWithoutDecimal = (patternA, patternB) => {
|
|
4325
7758
|
if (patternA && !patternB || !patternA && patternB) return false;
|
|
4326
7759
|
const getStringWithoutDecimal = (pattern) => {
|
|
4327
|
-
const tokens =
|
|
7760
|
+
const tokens = tokenize(pattern);
|
|
4328
7761
|
let result = "";
|
|
4329
7762
|
let isDecimalPart = false;
|
|
4330
7763
|
let isColorBefore = false;
|
|
4331
7764
|
for (const token of tokens) {
|
|
4332
|
-
if (token.type ===
|
|
7765
|
+
if (token.type === tokenTypes.POINT) {
|
|
4333
7766
|
isDecimalPart = true;
|
|
4334
7767
|
continue;
|
|
4335
7768
|
}
|
|
4336
|
-
if (isColorBefore && token.type ===
|
|
4337
|
-
if (token.type ===
|
|
4338
|
-
if (token.type ===
|
|
7769
|
+
if (isColorBefore && token.type === tokenTypes.MINUS) continue;
|
|
7770
|
+
if (token.type === tokenTypes.SKIP) continue;
|
|
7771
|
+
if (token.type === tokenTypes.COLOR) {
|
|
4339
7772
|
isColorBefore = true;
|
|
4340
7773
|
continue;
|
|
4341
7774
|
} else isColorBefore = false;
|
|
4342
|
-
if (isDecimalPart && token.type ===
|
|
7775
|
+
if (isDecimalPart && token.type === tokenTypes.ZERO) continue;
|
|
4343
7776
|
else isDecimalPart = false;
|
|
4344
7777
|
if (!isDecimalPart) result += token.value || "";
|
|
4345
7778
|
}
|
|
@@ -4389,8 +7822,8 @@ const CURRENCY_SYMBOL_PREFIX_REG = new RegExp(`^${regexp.charset(...Array.from(n
|
|
|
4389
7822
|
* Get the numfmt parse value, and filter out the parse error.
|
|
4390
7823
|
*/
|
|
4391
7824
|
const getNumfmtParseValueFilter = (value) => {
|
|
4392
|
-
var _ref,
|
|
4393
|
-
const parseData = (_ref = (
|
|
7825
|
+
var _ref, _parseDate;
|
|
7826
|
+
const parseData = (_ref = (_parseDate = parseDate(value)) !== null && _parseDate !== void 0 ? _parseDate : parseTime(value)) !== null && _ref !== void 0 ? _ref : parseNumber(value);
|
|
4394
7827
|
if (!parseData) return null;
|
|
4395
7828
|
const { z } = parseData;
|
|
4396
7829
|
if (z) {
|
|
@@ -6840,6 +10273,7 @@ const STYLE_KEYS = defineExactKeys()([
|
|
|
6840
10273
|
"cl",
|
|
6841
10274
|
"va",
|
|
6842
10275
|
"n",
|
|
10276
|
+
"stf",
|
|
6843
10277
|
"tr",
|
|
6844
10278
|
"td",
|
|
6845
10279
|
"ht",
|
|
@@ -14339,6 +17773,7 @@ _defineProperty(BuildTextUtils, "drawing", { add: addDrawing });
|
|
|
14339
17773
|
|
|
14340
17774
|
//#endregion
|
|
14341
17775
|
//#region src/docs/data-model/rich-text-builder.ts
|
|
17776
|
+
const NON_EDITABLE_RICH_TEXT_TOKENS = new Set(Object.values(DataStreamTreeTokenType).filter((token) => token !== "" && token !== " "));
|
|
14342
17777
|
function normalizeBody$1(body) {
|
|
14343
17778
|
if (!body.customRanges) body.customRanges = [];
|
|
14344
17779
|
if (!body.paragraphs) {
|
|
@@ -15948,9 +19383,158 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
|
|
|
15948
19383
|
constructor(data) {
|
|
15949
19384
|
super(data);
|
|
15950
19385
|
_defineProperty(this, "_doc", void 0);
|
|
19386
|
+
_defineProperty(this, "_trackedRanges", /* @__PURE__ */ new Set());
|
|
15951
19387
|
this._doc = new DocumentDataModel(data);
|
|
15952
19388
|
}
|
|
15953
19389
|
/**
|
|
19390
|
+
* Returns editable paragraph handles backed by this detached rich-text builder.
|
|
19391
|
+
*
|
|
19392
|
+
* Paragraph boundaries come from the document model rather than splitting plain text. Each handle stays aligned
|
|
19393
|
+
* when text in this builder grows or shrinks, so callers can safely iterate from the first paragraph to the last.
|
|
19394
|
+
*
|
|
19395
|
+
* @returns Editable paragraphs in document order.
|
|
19396
|
+
* @example
|
|
19397
|
+
* ```ts
|
|
19398
|
+
* const richText = univerAPI.newRichText()
|
|
19399
|
+
* .text('Quarterly Review')
|
|
19400
|
+
* .paragraph()
|
|
19401
|
+
* .text('Revenue increased by 18%.');
|
|
19402
|
+
* for (const paragraph of richText.getParagraphs()) {
|
|
19403
|
+
* console.log(paragraph.getText());
|
|
19404
|
+
* }
|
|
19405
|
+
* ```
|
|
19406
|
+
*/
|
|
19407
|
+
getParagraphs() {
|
|
19408
|
+
var _body$paragraphs;
|
|
19409
|
+
const body = this._data.body;
|
|
19410
|
+
if (!body) return [];
|
|
19411
|
+
const startOffsets = getParagraphContentStartOffsets(body);
|
|
19412
|
+
return ((_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []).map((paragraph) => {
|
|
19413
|
+
var _startOffsets$get;
|
|
19414
|
+
return this._createParagraphBuilder(paragraph.paragraphId, (_startOffsets$get = startOffsets.get(paragraph.startIndex)) !== null && _startOffsets$get !== void 0 ? _startOffsets$get : 0, paragraph.startIndex);
|
|
19415
|
+
});
|
|
19416
|
+
}
|
|
19417
|
+
/**
|
|
19418
|
+
* Returns editable text-run handles for all paragraph text in this builder.
|
|
19419
|
+
*
|
|
19420
|
+
* Unlike the read-only value API, this method also returns unstyled gaps. Paragraph and section markers are never
|
|
19421
|
+
* exposed as text runs. Prefer `getParagraphs()` when paragraph context matters.
|
|
19422
|
+
*
|
|
19423
|
+
* @returns Editable text runs in document order.
|
|
19424
|
+
* @example
|
|
19425
|
+
* ```ts
|
|
19426
|
+
* const richText = univerAPI.newRichText()
|
|
19427
|
+
* .text('Status: ')
|
|
19428
|
+
* .span('Ready', { bold: true, color: '#16a34a' });
|
|
19429
|
+
* for (const run of richText.getTextRuns()) {
|
|
19430
|
+
* console.log(run.getText(), run.getTextStyle()?.getValue());
|
|
19431
|
+
* }
|
|
19432
|
+
* ```
|
|
19433
|
+
*/
|
|
19434
|
+
getTextRuns() {
|
|
19435
|
+
return this.getParagraphs().flatMap((paragraph) => paragraph.getTextRuns());
|
|
19436
|
+
}
|
|
19437
|
+
/** @internal */
|
|
19438
|
+
_createTextRunBuilders(range) {
|
|
19439
|
+
var _body$textRuns, _body$customRanges, _body$customDecoratio;
|
|
19440
|
+
const body = this._data.body;
|
|
19441
|
+
if (!body || range.startOffset >= range.endOffset) return [];
|
|
19442
|
+
const boundaries = /* @__PURE__ */ new Set([range.startOffset, range.endOffset]);
|
|
19443
|
+
const addRangeBoundaries = (startOffset, endOffset) => {
|
|
19444
|
+
const start = Math.max(startOffset, range.startOffset);
|
|
19445
|
+
const end = Math.min(endOffset, range.endOffset);
|
|
19446
|
+
if (start < end) {
|
|
19447
|
+
boundaries.add(start);
|
|
19448
|
+
boundaries.add(end);
|
|
19449
|
+
}
|
|
19450
|
+
};
|
|
19451
|
+
for (const textRun of (_body$textRuns = body.textRuns) !== null && _body$textRuns !== void 0 ? _body$textRuns : []) addRangeBoundaries(textRun.st, textRun.ed);
|
|
19452
|
+
for (const customRange of (_body$customRanges = body.customRanges) !== null && _body$customRanges !== void 0 ? _body$customRanges : []) addRangeBoundaries(customRange.startIndex, customRange.endIndex + 1);
|
|
19453
|
+
for (const decoration of (_body$customDecoratio = body.customDecorations) !== null && _body$customDecoratio !== void 0 ? _body$customDecoratio : []) addRangeBoundaries(decoration.startIndex, decoration.endIndex + 1);
|
|
19454
|
+
for (let offset = range.startOffset; offset < range.endOffset; offset++) if (NON_EDITABLE_RICH_TEXT_TOKENS.has(body.dataStream[offset])) {
|
|
19455
|
+
boundaries.add(offset);
|
|
19456
|
+
boundaries.add(offset + 1);
|
|
19457
|
+
}
|
|
19458
|
+
const offsets = [...boundaries].sort((left, right) => left - right);
|
|
19459
|
+
const runs = [];
|
|
19460
|
+
for (let index = 0; index < offsets.length - 1; index++) {
|
|
19461
|
+
var _body$textRuns2;
|
|
19462
|
+
const startOffset = offsets[index];
|
|
19463
|
+
const endOffset = offsets[index + 1];
|
|
19464
|
+
if (startOffset >= endOffset || endOffset - startOffset === 1 && NON_EDITABLE_RICH_TEXT_TOKENS.has(body.dataStream[startOffset])) continue;
|
|
19465
|
+
const sourceRun = ((_body$textRuns2 = body.textRuns) !== null && _body$textRuns2 !== void 0 ? _body$textRuns2 : []).find((textRun) => textRun.st <= startOffset && textRun.ed >= endOffset);
|
|
19466
|
+
runs.push(new RichTextRunBuilder(this, this._trackRange(startOffset, endOffset), sourceRun === null || sourceRun === void 0 ? void 0 : sourceRun.ts, sourceRun === null || sourceRun === void 0 ? void 0 : sourceRun.sId, Boolean(sourceRun)));
|
|
19467
|
+
}
|
|
19468
|
+
return runs;
|
|
19469
|
+
}
|
|
19470
|
+
/** @internal */
|
|
19471
|
+
_replaceTextRun(range, text, textStyle, styleId, hasExplicitTextStyle) {
|
|
19472
|
+
var _sourceBody$customRan, _sourceBody$customDec;
|
|
19473
|
+
if (text.includes("\r") || text.includes("\n")) throw new RangeError("Rich text run replacement cannot contain paragraph or section breaks.");
|
|
19474
|
+
const body = this._doc.getBody();
|
|
19475
|
+
if (!body) throw new Error("Rich text body is not available.");
|
|
19476
|
+
const { startOffset, endOffset } = range;
|
|
19477
|
+
if (body.dataStream.slice(startOffset, endOffset) === text) return;
|
|
19478
|
+
const sourceBody = getBodySlice(body, startOffset, endOffset);
|
|
19479
|
+
const replacementBody = { dataStream: text };
|
|
19480
|
+
if (text && hasExplicitTextStyle) replacementBody.textRuns = [{
|
|
19481
|
+
st: 0,
|
|
19482
|
+
ed: text.length,
|
|
19483
|
+
sId: styleId,
|
|
19484
|
+
ts: Tools.deepClone(textStyle)
|
|
19485
|
+
}];
|
|
19486
|
+
if (text && ((_sourceBody$customRan = sourceBody.customRanges) === null || _sourceBody$customRan === void 0 ? void 0 : _sourceBody$customRan.length)) replacementBody.customRanges = sourceBody.customRanges.map((customRange) => ({
|
|
19487
|
+
...Tools.deepClone(customRange),
|
|
19488
|
+
startIndex: 0,
|
|
19489
|
+
endIndex: text.length - 1
|
|
19490
|
+
}));
|
|
19491
|
+
if (text && ((_sourceBody$customDec = sourceBody.customDecorations) === null || _sourceBody$customDec === void 0 ? void 0 : _sourceBody$customDec.length)) replacementBody.customDecorations = sourceBody.customDecorations.map((decoration) => ({
|
|
19492
|
+
...Tools.deepClone(decoration),
|
|
19493
|
+
startIndex: 0,
|
|
19494
|
+
endIndex: text.length - 1
|
|
19495
|
+
}));
|
|
19496
|
+
const textX = BuildTextUtils.selection.replace({
|
|
19497
|
+
doc: this._doc,
|
|
19498
|
+
selection: {
|
|
19499
|
+
startOffset,
|
|
19500
|
+
endOffset,
|
|
19501
|
+
collapsed: startOffset === endOffset
|
|
19502
|
+
},
|
|
19503
|
+
body: replacementBody
|
|
19504
|
+
});
|
|
19505
|
+
if (!textX) throw new Error("Replace rich text run failed.");
|
|
19506
|
+
TextX.apply(body, textX.serialize());
|
|
19507
|
+
this._rebaseTrackedRanges(startOffset, endOffset, text.length);
|
|
19508
|
+
}
|
|
19509
|
+
_createParagraphBuilder(paragraphId, startOffset, endOffset) {
|
|
19510
|
+
return new RichTextParagraphBuilder(this, paragraphId, this._trackRange(startOffset, endOffset));
|
|
19511
|
+
}
|
|
19512
|
+
_trackRange(startOffset, endOffset) {
|
|
19513
|
+
const range = {
|
|
19514
|
+
startOffset,
|
|
19515
|
+
endOffset
|
|
19516
|
+
};
|
|
19517
|
+
this._trackedRanges.add(range);
|
|
19518
|
+
return range;
|
|
19519
|
+
}
|
|
19520
|
+
_rebaseTrackedRanges(startOffset, endOffset, replacementLength) {
|
|
19521
|
+
const delta = replacementLength - (endOffset - startOffset);
|
|
19522
|
+
const mapStart = (offset) => {
|
|
19523
|
+
if (offset <= startOffset) return offset;
|
|
19524
|
+
if (offset >= endOffset) return offset + delta;
|
|
19525
|
+
return startOffset;
|
|
19526
|
+
};
|
|
19527
|
+
const mapEnd = (offset) => {
|
|
19528
|
+
if (offset <= startOffset) return offset;
|
|
19529
|
+
if (offset >= endOffset) return offset + delta;
|
|
19530
|
+
return startOffset + replacementLength;
|
|
19531
|
+
};
|
|
19532
|
+
for (const trackedRange of this._trackedRanges) {
|
|
19533
|
+
trackedRange.startOffset = mapStart(trackedRange.startOffset);
|
|
19534
|
+
trackedRange.endOffset = mapEnd(trackedRange.endOffset);
|
|
19535
|
+
}
|
|
19536
|
+
}
|
|
19537
|
+
/**
|
|
15954
19538
|
* Appends plain text to the rich text.
|
|
15955
19539
|
*
|
|
15956
19540
|
* This is an agent-friendly alias of `insertText(text)`. Use it when building rich text from left to right for
|
|
@@ -16005,6 +19589,58 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
|
|
|
16005
19589
|
return this;
|
|
16006
19590
|
}
|
|
16007
19591
|
/**
|
|
19592
|
+
* Sets the column layout for this rich-text document.
|
|
19593
|
+
*
|
|
19594
|
+
* Columns are stored in the rich-text document section layout. This creates text-flow columns, not table columns.
|
|
19595
|
+
* The host renderer must support rich-text columns for the layout to be visible.
|
|
19596
|
+
*
|
|
19597
|
+
* @param options The column layout options.
|
|
19598
|
+
* @param options.count The number of text columns. Must be a positive integer. Use `1` to clear multi-column layout.
|
|
19599
|
+
* @param options.spacing The spacing between columns, in px. Defaults to `0`.
|
|
19600
|
+
* @returns The current builder for chaining.
|
|
19601
|
+
*
|
|
19602
|
+
* @example
|
|
19603
|
+
* ```ts
|
|
19604
|
+
* const presentation = univerAPI.getActivePresentation();
|
|
19605
|
+
* if (!presentation) throw new Error('No active presentation');
|
|
19606
|
+
*
|
|
19607
|
+
* const slide = presentation.getSlideByIndex(0);
|
|
19608
|
+
* if (!slide) throw new Error('The presentation has no slides');
|
|
19609
|
+
* const richText = univerAPI.newRichText()
|
|
19610
|
+
* .columns({ count: 2, spacing: 12 })
|
|
19611
|
+
* .text('Column text');
|
|
19612
|
+
*
|
|
19613
|
+
* const shapeInfo = slide.newShape()
|
|
19614
|
+
* .setRichText(richText)
|
|
19615
|
+
* .setAbsolutePosition(80, 80)
|
|
19616
|
+
* .setSize(360, 160)
|
|
19617
|
+
* .build();
|
|
19618
|
+
*
|
|
19619
|
+
* slide.insertShape(shapeInfo);
|
|
19620
|
+
* ```
|
|
19621
|
+
*/
|
|
19622
|
+
columns(options) {
|
|
19623
|
+
var _this$_data2, _this$_data2$body, _body$sectionBreaks, _options$spacing;
|
|
19624
|
+
if (!Number.isInteger(options.count) || options.count < 1) throw new RangeError("Rich text column count must be a positive integer.");
|
|
19625
|
+
const body = (_this$_data2$body = (_this$_data2 = this._data).body) !== null && _this$_data2$body !== void 0 ? _this$_data2$body : _this$_data2.body = { dataStream: "\r\n" };
|
|
19626
|
+
const sectionBreaks = (_body$sectionBreaks = body.sectionBreaks) !== null && _body$sectionBreaks !== void 0 ? _body$sectionBreaks : body.sectionBreaks = [];
|
|
19627
|
+
if (!sectionBreaks.length) {
|
|
19628
|
+
var _body$dataStream$leng, _body$dataStream;
|
|
19629
|
+
sectionBreaks.push({
|
|
19630
|
+
sectionId: createSectionId(/* @__PURE__ */ new Set()),
|
|
19631
|
+
startIndex: Math.max(0, ((_body$dataStream$leng = (_body$dataStream = body.dataStream) === null || _body$dataStream === void 0 ? void 0 : _body$dataStream.length) !== null && _body$dataStream$leng !== void 0 ? _body$dataStream$leng : 0) - 1)
|
|
19632
|
+
});
|
|
19633
|
+
}
|
|
19634
|
+
const spacing = Math.max(0, (_options$spacing = options.spacing) !== null && _options$spacing !== void 0 ? _options$spacing : 0);
|
|
19635
|
+
const columns = options.count === 1 ? void 0 : Array.from({ length: options.count }, (_, index) => ({
|
|
19636
|
+
width: 0,
|
|
19637
|
+
paddingEnd: index === options.count - 1 ? 0 : spacing
|
|
19638
|
+
}));
|
|
19639
|
+
for (const sectionBreak of sectionBreaks) if (columns) sectionBreak.columnProperties = columns.map((column) => ({ ...column }));
|
|
19640
|
+
else delete sectionBreak.columnProperties;
|
|
19641
|
+
return this;
|
|
19642
|
+
}
|
|
19643
|
+
/**
|
|
16008
19644
|
* Appends one text span with explicit style.
|
|
16009
19645
|
*
|
|
16010
19646
|
* Prefer this method when combining multiple styles, because the style object is local to the inserted text and does
|
|
@@ -16383,6 +20019,174 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
|
|
|
16383
20019
|
return typeof start === "number" ? this.insertRichText(start, rich) : this.insertRichText(rich);
|
|
16384
20020
|
}
|
|
16385
20021
|
};
|
|
20022
|
+
/**
|
|
20023
|
+
* An editable paragraph handle owned by a detached {@link RichTextBuilder}.
|
|
20024
|
+
*
|
|
20025
|
+
* The paragraph is resolved by its persisted paragraph id, while its tracked range is rebased after every run edit.
|
|
20026
|
+
* This keeps paragraph traversal safe when earlier translated text becomes longer or shorter.
|
|
20027
|
+
*/
|
|
20028
|
+
var RichTextParagraphBuilder = class extends RichTextValue {
|
|
20029
|
+
/** @hideconstructor */
|
|
20030
|
+
constructor(_owner, _paragraphId, _range) {
|
|
20031
|
+
super(createParagraphSnapshot(_owner.getData(), _paragraphId, _range));
|
|
20032
|
+
this._owner = _owner;
|
|
20033
|
+
this._paragraphId = _paragraphId;
|
|
20034
|
+
this._range = _range;
|
|
20035
|
+
}
|
|
20036
|
+
/** Returns the persisted paragraph id. */
|
|
20037
|
+
getId() {
|
|
20038
|
+
return this._paragraphId;
|
|
20039
|
+
}
|
|
20040
|
+
/** Returns the current paragraph range without its trailing paragraph marker. */
|
|
20041
|
+
getRange() {
|
|
20042
|
+
return { ...this._range };
|
|
20043
|
+
}
|
|
20044
|
+
/**
|
|
20045
|
+
* Returns the current paragraph text without its trailing paragraph marker.
|
|
20046
|
+
* @example
|
|
20047
|
+
* ```ts
|
|
20048
|
+
* const richText = univerAPI.newRichText().text('Quarterly Review');
|
|
20049
|
+
* const paragraph = richText.getParagraphs()[0];
|
|
20050
|
+
* console.log(paragraph.getText());
|
|
20051
|
+
* ```
|
|
20052
|
+
*/
|
|
20053
|
+
getText() {
|
|
20054
|
+
var _this$_owner$getData$, _this$_owner$getData$2;
|
|
20055
|
+
return ((_this$_owner$getData$ = (_this$_owner$getData$2 = this._owner.getData().body) === null || _this$_owner$getData$2 === void 0 ? void 0 : _this$_owner$getData$2.dataStream) !== null && _this$_owner$getData$ !== void 0 ? _this$_owner$getData$ : "").slice(this._range.startOffset, this._range.endOffset);
|
|
20056
|
+
}
|
|
20057
|
+
toPlainText() {
|
|
20058
|
+
return this.getText();
|
|
20059
|
+
}
|
|
20060
|
+
/**
|
|
20061
|
+
* Returns editable runs that cover all text in this paragraph, including unstyled gaps.
|
|
20062
|
+
* @returns Editable text runs in document order.
|
|
20063
|
+
*/
|
|
20064
|
+
getTextRuns() {
|
|
20065
|
+
return this._owner._createTextRunBuilders(this._range);
|
|
20066
|
+
}
|
|
20067
|
+
getParagraphStyle() {
|
|
20068
|
+
return ParagraphStyleValue.create(this._getParagraph().paragraphStyle);
|
|
20069
|
+
}
|
|
20070
|
+
getParagraphBullet() {
|
|
20071
|
+
return this._getParagraph().bullet;
|
|
20072
|
+
}
|
|
20073
|
+
getLinks() {
|
|
20074
|
+
var _this$getData$body$cu, _this$getData$body;
|
|
20075
|
+
return (_this$getData$body$cu = (_this$getData$body = this.getData().body) === null || _this$getData$body === void 0 || (_this$getData$body = _this$getData$body.customRanges) === null || _this$getData$body === void 0 ? void 0 : _this$getData$body.filter((range) => range.rangeType === 0)) !== null && _this$getData$body$cu !== void 0 ? _this$getData$body$cu : [];
|
|
20076
|
+
}
|
|
20077
|
+
/** Agent-friendly alias of `getParagraphBullet()`. */
|
|
20078
|
+
getBullet() {
|
|
20079
|
+
return this.getParagraphBullet();
|
|
20080
|
+
}
|
|
20081
|
+
getData() {
|
|
20082
|
+
return createParagraphSnapshot(this._owner.getData(), this._paragraphId, this._range);
|
|
20083
|
+
}
|
|
20084
|
+
copy() {
|
|
20085
|
+
return RichTextBuilder.create(Tools.deepClone(this.getData()));
|
|
20086
|
+
}
|
|
20087
|
+
_getParagraph() {
|
|
20088
|
+
var _this$_owner$getData$3;
|
|
20089
|
+
const paragraph = (_this$_owner$getData$3 = this._owner.getData().body) === null || _this$_owner$getData$3 === void 0 || (_this$_owner$getData$3 = _this$_owner$getData$3.paragraphs) === null || _this$_owner$getData$3 === void 0 ? void 0 : _this$_owner$getData$3.find((item) => item.paragraphId === this._paragraphId);
|
|
20090
|
+
if (!paragraph) throw new Error(`Rich text paragraph "${this._paragraphId}" was not found.`);
|
|
20091
|
+
return paragraph;
|
|
20092
|
+
}
|
|
20093
|
+
};
|
|
20094
|
+
/**
|
|
20095
|
+
* An editable text-run handle owned by a detached {@link RichTextBuilder}.
|
|
20096
|
+
*
|
|
20097
|
+
* Calling {@link setText} replaces only the run text. The builder automatically updates this run, every later run,
|
|
20098
|
+
* paragraph indexes, hyperlinks, decorations, and other offset-based document metadata through TextX.
|
|
20099
|
+
*/
|
|
20100
|
+
var RichTextRunBuilder = class {
|
|
20101
|
+
/** @hideconstructor */
|
|
20102
|
+
constructor(_owner, _range, _textStyle, _styleId, _hasExplicitTextStyle) {
|
|
20103
|
+
this._owner = _owner;
|
|
20104
|
+
this._range = _range;
|
|
20105
|
+
this._textStyle = _textStyle;
|
|
20106
|
+
this._styleId = _styleId;
|
|
20107
|
+
this._hasExplicitTextStyle = _hasExplicitTextStyle;
|
|
20108
|
+
_defineProperty(this, "_active", true);
|
|
20109
|
+
}
|
|
20110
|
+
/** Inclusive start offset, kept for compatibility with existing `getTextRuns()` callers. */
|
|
20111
|
+
get st() {
|
|
20112
|
+
return this._range.startOffset;
|
|
20113
|
+
}
|
|
20114
|
+
/** Exclusive end offset, automatically updated after text replacement. */
|
|
20115
|
+
get ed() {
|
|
20116
|
+
return this._range.endOffset;
|
|
20117
|
+
}
|
|
20118
|
+
/** Optional persisted style id. This is not a stable run identity. */
|
|
20119
|
+
get sId() {
|
|
20120
|
+
return this._styleId;
|
|
20121
|
+
}
|
|
20122
|
+
/** Existing text-style value property exposed by `getTextRuns()`. */
|
|
20123
|
+
get ts() {
|
|
20124
|
+
return this._textStyle ? TextStyleValue.create(this._textStyle) : null;
|
|
20125
|
+
}
|
|
20126
|
+
/** Returns the current run range. */
|
|
20127
|
+
getRange() {
|
|
20128
|
+
return { ...this._range };
|
|
20129
|
+
}
|
|
20130
|
+
/** Returns the current run text. */
|
|
20131
|
+
getText() {
|
|
20132
|
+
var _this$_owner$getData$4, _this$_owner$getData$5;
|
|
20133
|
+
return ((_this$_owner$getData$4 = (_this$_owner$getData$5 = this._owner.getData().body) === null || _this$_owner$getData$5 === void 0 ? void 0 : _this$_owner$getData$5.dataStream) !== null && _this$_owner$getData$4 !== void 0 ? _this$_owner$getData$4 : "").slice(this._range.startOffset, this._range.endOffset);
|
|
20134
|
+
}
|
|
20135
|
+
/** Returns this run's explicit text style, or `null` for an unstyled text segment. */
|
|
20136
|
+
getTextStyle() {
|
|
20137
|
+
return this.ts;
|
|
20138
|
+
}
|
|
20139
|
+
/** Returns whether this segment is backed by an explicit document text run. */
|
|
20140
|
+
hasTextStyle() {
|
|
20141
|
+
return this._hasExplicitTextStyle;
|
|
20142
|
+
}
|
|
20143
|
+
/**
|
|
20144
|
+
* Replaces this run's text without changing its style or paragraph structure.
|
|
20145
|
+
*
|
|
20146
|
+
* Replacement text may be longer or shorter than the original. Offsets are updated automatically, so handles
|
|
20147
|
+
* returned in the same `getTextRuns()` call remain safe to use in forward order. Paragraph and section breaks are
|
|
20148
|
+
* rejected because a text run cannot create or remove paragraphs.
|
|
20149
|
+
*
|
|
20150
|
+
* @param text New text for this run.
|
|
20151
|
+
* @returns This run handle for chaining. A handle becomes invalid after it is replaced with an empty string.
|
|
20152
|
+
* @example
|
|
20153
|
+
* ```ts
|
|
20154
|
+
* const richText = univerAPI.newRichText()
|
|
20155
|
+
* .span('标题', { bold: true, fontSize: 24 })
|
|
20156
|
+
* .paragraph()
|
|
20157
|
+
* .text('正文内容');
|
|
20158
|
+
* const replacements = ['Quarterly Review', 'Revenue increased by 18%.'];
|
|
20159
|
+
* let index = 0;
|
|
20160
|
+
* for (const run of richText.getTextRuns()) {
|
|
20161
|
+
* const replacement = replacements[index++];
|
|
20162
|
+
* if (replacement !== undefined) run.setText(replacement);
|
|
20163
|
+
* }
|
|
20164
|
+
* console.log(richText.toPlainText());
|
|
20165
|
+
* ```
|
|
20166
|
+
*/
|
|
20167
|
+
setText(text) {
|
|
20168
|
+
if (!this._active) throw new Error("Rich text run handle is no longer valid.");
|
|
20169
|
+
this._owner._replaceTextRun(this._range, text, this._textStyle, this._styleId, this._hasExplicitTextStyle);
|
|
20170
|
+
if (!text) this._active = false;
|
|
20171
|
+
return this;
|
|
20172
|
+
}
|
|
20173
|
+
};
|
|
20174
|
+
function createParagraphSnapshot(data, paragraphId, range) {
|
|
20175
|
+
var _body$paragraphs2;
|
|
20176
|
+
const { body, ...documentData } = data;
|
|
20177
|
+
if (!body) throw new Error("Rich text body is not available.");
|
|
20178
|
+
const paragraph = (_body$paragraphs2 = body.paragraphs) === null || _body$paragraphs2 === void 0 ? void 0 : _body$paragraphs2.find((item) => item.paragraphId === paragraphId);
|
|
20179
|
+
if (!paragraph) throw new Error(`Rich text paragraph "${paragraphId}" was not found.`);
|
|
20180
|
+
const paragraphBody = getBodySlice(body, range.startOffset, range.endOffset);
|
|
20181
|
+
paragraphBody.paragraphs = [{
|
|
20182
|
+
...Tools.deepClone(paragraph),
|
|
20183
|
+
startIndex: range.endOffset - range.startOffset
|
|
20184
|
+
}];
|
|
20185
|
+
return {
|
|
20186
|
+
...Tools.deepClone(documentData),
|
|
20187
|
+
body: paragraphBody
|
|
20188
|
+
};
|
|
20189
|
+
}
|
|
16386
20190
|
|
|
16387
20191
|
//#endregion
|
|
16388
20192
|
//#region src/docs/data-model/subdocument.ts
|
|
@@ -22982,6 +26786,8 @@ Object.defineProperty(exports, 'ResourceManagerService', {
|
|
|
22982
26786
|
}
|
|
22983
26787
|
});
|
|
22984
26788
|
exports.RichTextBuilder = RichTextBuilder;
|
|
26789
|
+
exports.RichTextParagraphBuilder = RichTextParagraphBuilder;
|
|
26790
|
+
exports.RichTextRunBuilder = RichTextRunBuilder;
|
|
22985
26791
|
exports.RichTextValue = RichTextValue;
|
|
22986
26792
|
exports.RxDisposable = RxDisposable;
|
|
22987
26793
|
exports.SECTION_ID_PREFIX = SECTION_ID_PREFIX;
|
|
@@ -23164,6 +26970,7 @@ exports.getCellValueType = getCellValueType;
|
|
|
23164
26970
|
exports.getCellWithCoordByIndexCore = getCellWithCoordByIndexCore;
|
|
23165
26971
|
exports.getColorStyle = getColorStyle;
|
|
23166
26972
|
exports.getColumnGroupRangeInterval = getColumnGroupRangeInterval;
|
|
26973
|
+
exports.getCustomBlockIdsInSelections = getCustomBlockIdsInSelections;
|
|
23167
26974
|
exports.getCustomBlockInterval = getCustomBlockInterval;
|
|
23168
26975
|
exports.getCustomBlockSlice = getCustomBlockSlice;
|
|
23169
26976
|
exports.getCustomDecorationSlice = getCustomDecorationSlice;
|
|
@@ -23309,7 +27116,7 @@ exports.numberToListABC = numberToListABC;
|
|
|
23309
27116
|
Object.defineProperty(exports, 'numfmt', {
|
|
23310
27117
|
enumerable: true,
|
|
23311
27118
|
get: function () {
|
|
23312
|
-
return
|
|
27119
|
+
return api_exports;
|
|
23313
27120
|
}
|
|
23314
27121
|
});
|
|
23315
27122
|
exports.queryObjectMatrix = queryObjectMatrix;
|