pkhex 25.10.26-a

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.
Files changed (69) hide show
  1. package/README.md +73 -0
  2. package/dist/PKHeX.Core.dll +0 -0
  3. package/dist/PKHeX.deps.json +361 -0
  4. package/dist/PKHeX.dll +0 -0
  5. package/dist/PKHeX.runtimeconfig.json +38 -0
  6. package/dist/System.Collections.Concurrent.dll +0 -0
  7. package/dist/System.Collections.dll +0 -0
  8. package/dist/System.ComponentModel.Annotations.dll +0 -0
  9. package/dist/System.ComponentModel.Primitives.dll +0 -0
  10. package/dist/System.ComponentModel.TypeConverter.dll +0 -0
  11. package/dist/System.Console.dll +0 -0
  12. package/dist/System.Diagnostics.DiagnosticSource.dll +0 -0
  13. package/dist/System.Diagnostics.TraceSource.dll +0 -0
  14. package/dist/System.IO.Compression.ZipFile.dll +0 -0
  15. package/dist/System.IO.Compression.dll +0 -0
  16. package/dist/System.IO.Pipelines.dll +0 -0
  17. package/dist/System.Linq.dll +0 -0
  18. package/dist/System.Memory.dll +0 -0
  19. package/dist/System.Net.Http.dll +0 -0
  20. package/dist/System.Net.Primitives.dll +0 -0
  21. package/dist/System.Numerics.Vectors.dll +0 -0
  22. package/dist/System.ObjectModel.dll +0 -0
  23. package/dist/System.Private.CoreLib.dll +0 -0
  24. package/dist/System.Private.Uri.dll +0 -0
  25. package/dist/System.Runtime.InteropServices.JavaScript.dll +0 -0
  26. package/dist/System.Runtime.InteropServices.dll +0 -0
  27. package/dist/System.Runtime.Numerics.dll +0 -0
  28. package/dist/System.Runtime.dll +0 -0
  29. package/dist/System.Security.Cryptography.dll +0 -0
  30. package/dist/System.Text.Encodings.Web.dll +0 -0
  31. package/dist/System.Text.Json.dll +0 -0
  32. package/dist/System.Text.RegularExpressions.dll +0 -0
  33. package/dist/System.Threading.Tasks.Parallel.dll +0 -0
  34. package/dist/System.Threading.dll +0 -0
  35. package/dist/api-wrapper.d.ts +114 -0
  36. package/dist/api-wrapper.js +154 -0
  37. package/dist/blazor.boot.json +47 -0
  38. package/dist/corebindings.c +315 -0
  39. package/dist/dotnet.d.ts +698 -0
  40. package/dist/dotnet.es6.extpost.js +2 -0
  41. package/dist/dotnet.es6.lib.js +149 -0
  42. package/dist/dotnet.es6.pre.js +3 -0
  43. package/dist/dotnet.globalization.js +1015 -0
  44. package/dist/dotnet.js +4 -0
  45. package/dist/dotnet.js.map +1 -0
  46. package/dist/dotnet.native.js +16 -0
  47. package/dist/dotnet.native.js.symbols +8687 -0
  48. package/dist/dotnet.native.wasm +0 -0
  49. package/dist/dotnet.runtime.js +4 -0
  50. package/dist/dotnet.runtime.js.map +1 -0
  51. package/dist/driver.c +573 -0
  52. package/dist/emcc-default.rsp +0 -0
  53. package/dist/emcc-link.rsp +17 -0
  54. package/dist/gc-common.h +73 -0
  55. package/dist/helpers.d.ts +5 -0
  56. package/dist/helpers.js +15 -0
  57. package/dist/index.d.ts +43 -0
  58. package/dist/index.js +54 -0
  59. package/dist/package.json +44 -0
  60. package/dist/pinvoke.c +62 -0
  61. package/dist/pinvoke.h +50 -0
  62. package/dist/runtime.c +386 -0
  63. package/dist/runtime.h +25 -0
  64. package/dist/segmentation-rules.json +83 -0
  65. package/dist/wasm-config.h +13 -0
  66. package/dist/wasm-props.json +21 -0
  67. package/package.json +58 -0
  68. package/src/helpers.ts +20 -0
  69. package/src/index.d.ts +919 -0
@@ -0,0 +1,1015 @@
1
+ //! Licensed to the .NET Foundation under one or more agreements.
2
+ //! The .NET Foundation licenses this file to you under the MIT license.
3
+
4
+ // Licensed to the .NET Foundation under one or more agreements.
5
+ // The .NET Foundation licenses this file to you under the MIT license.
6
+ const VoidPtrNull = 0;
7
+
8
+ // Licensed to the .NET Foundation under one or more agreements.
9
+ // The .NET Foundation licenses this file to you under the MIT license.
10
+ const SURROGATE_HIGHER_START = "\uD800";
11
+ const SURROGATE_HIGHER_END = "\uDBFF";
12
+ const SURROGATE_LOWER_START = "\uDC00";
13
+ const SURROGATE_LOWER_END = "\uDFFF";
14
+ const OUTER_SEPARATOR = "##";
15
+ const INNER_SEPARATOR = "||";
16
+ function normalizeLocale(locale) {
17
+ if (!locale)
18
+ return undefined;
19
+ try {
20
+ locale = locale.toLocaleLowerCase();
21
+ if (locale.includes("zh")) {
22
+ // browser does not recognize "zh-chs" and "zh-cht" as equivalents of "zh-HANS" "zh-HANT", we are helping, otherwise
23
+ // it would throw on getCanonicalLocales with "RangeError: Incorrect locale information provided"
24
+ locale = locale.replace("chs", "HANS").replace("cht", "HANT");
25
+ }
26
+ const canonicalLocales = Intl.getCanonicalLocales(locale.replace("_", "-"));
27
+ return canonicalLocales.length > 0 ? canonicalLocales[0] : undefined;
28
+ }
29
+ catch (_a) {
30
+ return undefined;
31
+ }
32
+ }
33
+ function isSurrogate(str, startIdx) {
34
+ return SURROGATE_HIGHER_START <= str[startIdx] &&
35
+ str[startIdx] <= SURROGATE_HIGHER_END &&
36
+ startIdx + 1 < str.length &&
37
+ SURROGATE_LOWER_START <= str[startIdx + 1] &&
38
+ str[startIdx + 1] <= SURROGATE_LOWER_END;
39
+ }
40
+
41
+ // Licensed to the .NET Foundation under one or more agreements.
42
+ // The .NET Foundation licenses this file to you under the MIT license.
43
+ /* eslint-disable no-inner-declarations */
44
+ const MONTH_CODE = "MMMM";
45
+ const YEAR_CODE = "yyyy";
46
+ const DAY_CODE = "d";
47
+ const WEEKDAY_CODE = "dddd";
48
+ const keyWords$1 = [MONTH_CODE, YEAR_CODE, DAY_CODE, WEEKDAY_CODE];
49
+ // this function joins all calendar info with OUTER_SEPARATOR into one string and returns it back to managed code
50
+ function mono_wasm_get_calendar_info(culture, cultureLength, calendarId, dst, dstMaxLength, dstLength) {
51
+ try {
52
+ const cultureName = runtimeHelpers.utf16ToString(culture, (culture + 2 * cultureLength));
53
+ const locale = cultureName ? cultureName : undefined;
54
+ const calendarInfo = {
55
+ EnglishName: "",
56
+ YearMonth: "",
57
+ MonthDay: "",
58
+ LongDates: "",
59
+ ShortDates: "",
60
+ EraNames: "",
61
+ AbbreviatedEraNames: "",
62
+ DayNames: "",
63
+ AbbreviatedDayNames: "",
64
+ ShortestDayNames: "",
65
+ MonthNames: "",
66
+ AbbreviatedMonthNames: "",
67
+ MonthGenitiveNames: "",
68
+ AbbrevMonthGenitiveNames: "",
69
+ };
70
+ const date = new Date(999, 10, 22); // Fri Nov 22 0999 00:00:00 GMT+0124 (Central European Standard Time)
71
+ calendarInfo.EnglishName = getCalendarName(locale);
72
+ const dayNames = getDayNames(locale);
73
+ calendarInfo.DayNames = dayNames.long.join(INNER_SEPARATOR);
74
+ calendarInfo.AbbreviatedDayNames = dayNames.abbreviated.join(INNER_SEPARATOR);
75
+ calendarInfo.ShortestDayNames = dayNames.shortest.join(INNER_SEPARATOR);
76
+ const monthNames = getMonthNames(locale);
77
+ calendarInfo.MonthNames = monthNames.long.join(INNER_SEPARATOR);
78
+ calendarInfo.AbbreviatedMonthNames = monthNames.abbreviated.join(INNER_SEPARATOR);
79
+ calendarInfo.MonthGenitiveNames = monthNames.longGenitive.join(INNER_SEPARATOR);
80
+ calendarInfo.AbbrevMonthGenitiveNames = monthNames.abbreviatedGenitive.join(INNER_SEPARATOR);
81
+ calendarInfo.YearMonth = getMonthYearPattern(locale, date);
82
+ calendarInfo.MonthDay = getMonthDayPattern(locale, date);
83
+ calendarInfo.ShortDates = getShortDatePattern(locale);
84
+ calendarInfo.LongDates = getLongDatePattern(locale, date);
85
+ const eraNames = getEraNames(date, locale, calendarId);
86
+ calendarInfo.EraNames = eraNames.eraNames;
87
+ calendarInfo.AbbreviatedEraNames = eraNames.abbreviatedEraNames;
88
+ const result = Object.values(calendarInfo).join(OUTER_SEPARATOR);
89
+ if (result.length > dstMaxLength) {
90
+ throw new Error(`Calendar info exceeds length of ${dstMaxLength}.`);
91
+ }
92
+ runtimeHelpers.stringToUTF16(dst, dst + 2 * result.length, result);
93
+ runtimeHelpers.setI32(dstLength, result.length);
94
+ return VoidPtrNull;
95
+ }
96
+ catch (ex) {
97
+ return runtimeHelpers.stringToUTF16Ptr(ex.toString());
98
+ }
99
+ }
100
+ function getCalendarName(locale) {
101
+ const calendars = getCalendarInfo(locale);
102
+ if (!calendars || calendars.length == 0)
103
+ return "";
104
+ return calendars[0];
105
+ }
106
+ function getCalendarInfo(locale) {
107
+ try {
108
+ // most tools have it implemented as a property
109
+ return new Intl.Locale(locale).calendars;
110
+ }
111
+ catch (_a) {
112
+ try {
113
+ // but a few use methods, which is the preferred way
114
+ return new Intl.Locale(locale).getCalendars();
115
+ }
116
+ catch (_b) {
117
+ return undefined;
118
+ }
119
+ }
120
+ }
121
+ function getMonthYearPattern(locale, date) {
122
+ let pattern = date.toLocaleDateString(locale, { year: "numeric", month: "long" }).toLowerCase();
123
+ // pattern has month name as string or as number
124
+ const monthName = date.toLocaleString(locale, { month: "long" }).toLowerCase().trim();
125
+ if (monthName.charAt(monthName.length - 1) == "\u6708") {
126
+ // Chineese-like patterns:
127
+ return "yyyy\u5e74M\u6708";
128
+ }
129
+ pattern = pattern.replace(monthName, MONTH_CODE);
130
+ pattern = pattern.replace("999", YEAR_CODE);
131
+ // sometimes the number is localized and the above does not have an effect
132
+ const yearStr = date.toLocaleDateString(locale, { year: "numeric" });
133
+ return pattern.replace(yearStr, YEAR_CODE);
134
+ }
135
+ function getMonthDayPattern(locale, date) {
136
+ let pattern = date.toLocaleDateString(locale, { month: "long", day: "numeric" }).toLowerCase();
137
+ // pattern has month name as string or as number
138
+ const monthName = date.toLocaleString(locale, { month: "long" }).toLowerCase().trim();
139
+ if (monthName.charAt(monthName.length - 1) == "\u6708") {
140
+ // Chineese-like patterns:
141
+ return "M\u6708d\u65e5";
142
+ }
143
+ const formatWithoutMonthName = new Intl.DateTimeFormat(locale, { day: "numeric" });
144
+ const replacedMonthName = getGenitiveForName(date, pattern, monthName, formatWithoutMonthName);
145
+ pattern = pattern.replace(replacedMonthName, MONTH_CODE);
146
+ pattern = pattern.replace("22", DAY_CODE);
147
+ const dayStr = formatWithoutMonthName.format(date);
148
+ return pattern.replace(dayStr, DAY_CODE);
149
+ }
150
+ function getShortDatePattern(locale) {
151
+ if ((locale === null || locale === void 0 ? void 0 : locale.substring(0, 2)) == "fa") {
152
+ // persian calendar is shifted and it has no lapping dates with
153
+ // arabic and gregorian calendars, so that both day and month would be < 10
154
+ return "yyyy/M/d";
155
+ }
156
+ const year = 2014;
157
+ const month = 1;
158
+ const day = 2;
159
+ const date = new Date(year, month - 1, day); // arabic: 1/3/1435
160
+ const longYearStr = "2014";
161
+ const shortYearStr = "14";
162
+ const longMonthStr = "01";
163
+ const shortMonthStr = "1";
164
+ const longDayStr = "02";
165
+ const shortDayStr = "2";
166
+ let pattern = date.toLocaleDateString(locale, { dateStyle: "short" });
167
+ // each date part might be in localized numbers or standard arabic numbers
168
+ // toLocaleDateString returns not compatible data,
169
+ // e.g. { dateStyle: "short" } sometimes contains localized year number
170
+ // while { year: "numeric" } contains non-localized year number and vice versa
171
+ if (pattern.includes(shortYearStr)) {
172
+ pattern = pattern.replace(longYearStr, YEAR_CODE);
173
+ pattern = pattern.replace(shortYearStr, YEAR_CODE);
174
+ }
175
+ else {
176
+ const yearStr = date.toLocaleDateString(locale, { year: "numeric" });
177
+ const yearStrShort = yearStr.substring(yearStr.length - 2, yearStr.length);
178
+ pattern = pattern.replace(yearStr, YEAR_CODE);
179
+ if (yearStrShort)
180
+ pattern = pattern.replace(yearStrShort, YEAR_CODE);
181
+ }
182
+ if (pattern.includes(shortMonthStr)) {
183
+ pattern = pattern.replace(longMonthStr, "MM");
184
+ pattern = pattern.replace(shortMonthStr, "M");
185
+ }
186
+ else {
187
+ const monthStr = date.toLocaleDateString(locale, { month: "numeric" });
188
+ const localizedMonthCode = monthStr.length == 1 ? "M" : "MM";
189
+ pattern = pattern.replace(monthStr, localizedMonthCode);
190
+ }
191
+ if (pattern.includes(shortDayStr)) {
192
+ pattern = pattern.replace(longDayStr, "dd");
193
+ pattern = pattern.replace(shortDayStr, "d");
194
+ }
195
+ else {
196
+ const dayStr = date.toLocaleDateString(locale, { day: "numeric" });
197
+ const localizedDayCode = dayStr.length == 1 ? "d" : "dd";
198
+ pattern = pattern.replace(dayStr, localizedDayCode);
199
+ }
200
+ return pattern;
201
+ }
202
+ function getLongDatePattern(locale, date) {
203
+ if (locale == "th-TH") {
204
+ // cannot be caught with regexes
205
+ return "ddddที่ d MMMM g yyyy";
206
+ }
207
+ let pattern = new Intl.DateTimeFormat(locale, { weekday: "long", year: "numeric", month: "long", day: "numeric" }).format(date).toLowerCase();
208
+ const monthName = date.toLocaleString(locale, { month: "long" }).trim().toLowerCase();
209
+ // pattern has month name as string or as number
210
+ const monthSuffix = monthName.charAt(monthName.length - 1);
211
+ if (monthSuffix == "\u6708" || monthSuffix == "\uc6d4") {
212
+ // Asian-like patterns:
213
+ const shortMonthName = date.toLocaleString(locale, { month: "short" });
214
+ pattern = pattern.replace(shortMonthName, `M${monthSuffix}`);
215
+ }
216
+ else {
217
+ const replacedMonthName = getGenitiveForName(date, pattern, monthName, new Intl.DateTimeFormat(locale, { weekday: "long", year: "numeric", day: "numeric" }));
218
+ pattern = pattern.replace(replacedMonthName, MONTH_CODE);
219
+ }
220
+ pattern = pattern.replace("999", YEAR_CODE);
221
+ // sometimes the number is localized and the above does not have an effect,
222
+ // so additionally, we need to do:
223
+ const yearStr = date.toLocaleDateString(locale, { year: "numeric" });
224
+ pattern = pattern.replace(yearStr, YEAR_CODE);
225
+ const weekday = date.toLocaleDateString(locale, { weekday: "long" }).toLowerCase();
226
+ const replacedWeekday = getGenitiveForName(date, pattern, weekday, new Intl.DateTimeFormat(locale, { year: "numeric", month: "long", day: "numeric" }));
227
+ pattern = pattern.replace(replacedWeekday, WEEKDAY_CODE);
228
+ pattern = pattern.replace("22", DAY_CODE);
229
+ const dayStr = date.toLocaleDateString(locale, { day: "numeric" }); // should we replace it for localized digits?
230
+ pattern = pattern.replace(dayStr, DAY_CODE);
231
+ return wrapSubstrings$1(pattern, locale);
232
+ }
233
+ function getGenitiveForName(date, pattern, name, formatWithoutName) {
234
+ let genitiveName = name;
235
+ const nameStart = pattern.indexOf(name);
236
+ if (nameStart == -1 ||
237
+ // genitive month name can include monthName and monthName can include spaces, e.g. "tháng 11":, so we cannot use pattern.includes() or pattern.split(" ").includes()
238
+ (nameStart != -1 && pattern.length > nameStart + name.length && pattern[nameStart + name.length] != " " && pattern[nameStart + name.length] != "," && pattern[nameStart + name.length] != "\u060c")) {
239
+ // needs to be in Genitive form to be useful
240
+ // e.g.
241
+ // pattern = '999 m. lapkričio 22 d., šeštadienis',
242
+ // patternWithoutName = '999 2, šeštadienis',
243
+ // name = 'lapkritis'
244
+ // genitiveName = 'lapkričio'
245
+ const patternWithoutName = formatWithoutName.format(date).toLowerCase();
246
+ genitiveName = pattern.split(/,| /).filter(x => !patternWithoutName.split(/,| /).includes(x) && x[0] == name[0])[0];
247
+ }
248
+ return genitiveName;
249
+ }
250
+ function getDayNames(locale) {
251
+ const weekDay = new Date(2023, 5, 25); // Sunday
252
+ const dayNames = [];
253
+ const dayNamesAbb = [];
254
+ const dayNamesSS = [];
255
+ for (let i = 0; i < 7; i++) {
256
+ dayNames[i] = weekDay.toLocaleDateString(locale, { weekday: "long" });
257
+ dayNamesAbb[i] = weekDay.toLocaleDateString(locale, { weekday: "short" });
258
+ dayNamesSS[i] = weekDay.toLocaleDateString(locale, { weekday: "narrow" });
259
+ weekDay.setDate(weekDay.getDate() + 1);
260
+ }
261
+ return { long: dayNames, abbreviated: dayNamesAbb, shortest: dayNamesSS };
262
+ }
263
+ function getMonthNames(locale) {
264
+ // some calendars have the first month on non-0 index in JS
265
+ // first month: Muharram ("ar") or Farwardin ("fa") or January
266
+ const localeLang = locale ? locale.split("-")[0] : "";
267
+ const firstMonthShift = localeLang == "ar" ? 8 : localeLang == "fa" ? 3 : 0;
268
+ const date = new Date(2021, firstMonthShift, 1);
269
+ const months = [];
270
+ const monthsAbb = [];
271
+ const monthsGen = [];
272
+ const monthsAbbGen = [];
273
+ let isChineeseStyle, isShortFormBroken;
274
+ for (let i = firstMonthShift; i < 12 + firstMonthShift; i++) {
275
+ const monthCnt = i % 12;
276
+ date.setMonth(monthCnt);
277
+ const monthNameLong = date.toLocaleDateString(locale, { month: "long" });
278
+ const monthNameShort = date.toLocaleDateString(locale, { month: "short" });
279
+ months[i - firstMonthShift] = monthNameLong;
280
+ monthsAbb[i - firstMonthShift] = monthNameShort;
281
+ // for Genitive forms:
282
+ isChineeseStyle = isChineeseStyle !== null && isChineeseStyle !== void 0 ? isChineeseStyle : monthNameLong.charAt(monthNameLong.length - 1) == "\u6708";
283
+ if (isChineeseStyle) {
284
+ // for Chinese-like calendar's Genitive = Nominative
285
+ monthsGen[i - firstMonthShift] = monthNameLong;
286
+ monthsAbbGen[i - firstMonthShift] = monthNameShort;
287
+ continue;
288
+ }
289
+ const formatWithoutMonthName = new Intl.DateTimeFormat(locale, { day: "numeric" });
290
+ const monthWithDayLong = date.toLocaleDateString(locale, { month: "long", day: "numeric" });
291
+ monthsGen[i - firstMonthShift] = getGenitiveForName(date, monthWithDayLong, monthNameLong, formatWithoutMonthName);
292
+ isShortFormBroken = isShortFormBroken !== null && isShortFormBroken !== void 0 ? isShortFormBroken : /^\d+$/.test(monthNameShort);
293
+ if (isShortFormBroken) {
294
+ // for buggy locales e.g. lt-LT, short month contains only number instead of string
295
+ // we leave Genitive = Nominative
296
+ monthsAbbGen[i - firstMonthShift] = monthNameShort;
297
+ continue;
298
+ }
299
+ const monthWithDayShort = date.toLocaleDateString(locale, { month: "short", day: "numeric" });
300
+ monthsAbbGen[i - firstMonthShift] = getGenitiveForName(date, monthWithDayShort, monthNameShort, formatWithoutMonthName);
301
+ }
302
+ return { long: months, abbreviated: monthsAbb, longGenitive: monthsGen, abbreviatedGenitive: monthsAbbGen };
303
+ }
304
+ // .NET expects that only the Japanese calendars have more than 1 era.
305
+ // So for other calendars, only return the latest era.
306
+ function getEraNames(date, locale, calendarId) {
307
+ if (shouldBePopulatedByManagedCode(calendarId)) {
308
+ // managed code already handles these calendars,
309
+ // so empty strings will get overwritten in
310
+ // InitializeEraNames/InitializeAbbreviatedEraNames
311
+ return {
312
+ eraNames: "",
313
+ abbreviatedEraNames: ""
314
+ };
315
+ }
316
+ const yearStr = date.toLocaleDateString(locale, { year: "numeric" });
317
+ const dayStr = date.toLocaleDateString(locale, { day: "numeric" });
318
+ const eraDate = date.toLocaleDateString(locale, { era: "short" });
319
+ const shortEraDate = date.toLocaleDateString(locale, { era: "narrow" });
320
+ const eraDateParts = eraDate.includes(yearStr) ?
321
+ getEraDateParts(yearStr) :
322
+ getEraDateParts(date.getFullYear().toString());
323
+ return {
324
+ eraNames: getEraFromDateParts(eraDateParts.eraDateParts, eraDateParts.ignoredPart),
325
+ abbreviatedEraNames: getEraFromDateParts(eraDateParts.abbrEraDateParts, eraDateParts.ignoredPart)
326
+ };
327
+ function shouldBePopulatedByManagedCode(calendarId) {
328
+ return (calendarId > 1 && calendarId < 15) || calendarId == 22 || calendarId == 23;
329
+ }
330
+ function getEraFromDateParts(dateParts, ignoredPart) {
331
+ const regex = new RegExp(`^((?!${ignoredPart}|[0-9]).)*$`);
332
+ const filteredEra = dateParts.filter(part => regex.test(part));
333
+ if (filteredEra.length == 0)
334
+ throw new Error(`Internal error, era for locale ${locale} was in non-standard format.`);
335
+ return filteredEra[0].trim();
336
+ }
337
+ function getEraDateParts(yearStr) {
338
+ if (eraDate.startsWith(yearStr) || eraDate.endsWith(yearStr)) {
339
+ return {
340
+ eraDateParts: eraDate.split(dayStr),
341
+ abbrEraDateParts: shortEraDate.split(dayStr),
342
+ ignoredPart: yearStr,
343
+ };
344
+ }
345
+ return {
346
+ eraDateParts: eraDate.split(yearStr),
347
+ abbrEraDateParts: shortEraDate.split(yearStr),
348
+ ignoredPart: dayStr,
349
+ };
350
+ }
351
+ }
352
+ // wraps all substrings in the format in quotes, except for key words
353
+ // transform e.g. "dddd, d MMMM yyyy г." into "dddd, d MMMM yyyy 'г'."
354
+ function wrapSubstrings$1(str, locale) {
355
+ const words = str.split(/\s+/);
356
+ // locales that write date nearly without spaces should not have format parts quoted - "ja", "zh"
357
+ // "ko" format parts should not be quoted but processing it would overcomplicate the logic
358
+ if (words.length <= 2 || (locale === null || locale === void 0 ? void 0 : locale.startsWith("ko"))) {
359
+ return str;
360
+ }
361
+ for (let i = 0; i < words.length; i++) {
362
+ if (!keyWords$1.includes(words[i].replace(",", "")) &&
363
+ !keyWords$1.includes(words[i].replace(".", "")) &&
364
+ !keyWords$1.includes(words[i].replace("\u060c", "")) &&
365
+ !keyWords$1.includes(words[i].replace("\u05d1", ""))) {
366
+ if (words[i].endsWith(".,")) {
367
+ // if the "word" appears twice, then the occurence with punctuation is not a code but fixed part of the format
368
+ // see: "hu-HU" vs "lt-LT" format
369
+ const wordNoPuctuation = words[i].slice(0, -2);
370
+ if (words.filter(x => x == wordNoPuctuation).length == 1)
371
+ words[i] = `'${words[i].slice(0, -2)}'.,`;
372
+ }
373
+ else if (words[i].endsWith(".")) {
374
+ words[i] = `'${words[i].slice(0, -1)}'.`;
375
+ }
376
+ else if (words[i].endsWith(",")) {
377
+ words[i] = `'${words[i].slice(0, -1)}',`;
378
+ }
379
+ else {
380
+ words[i] = `'${words[i]}'`;
381
+ }
382
+ }
383
+ }
384
+ return words.join(" ");
385
+ }
386
+
387
+ // Licensed to the .NET Foundation under one or more agreements.
388
+ // The .NET Foundation licenses this file to you under the MIT license.
389
+ function mono_wasm_change_case(culture, cultureLength, src, srcLength, dst, dstLength, toUpper) {
390
+ try {
391
+ const cultureName = runtimeHelpers.utf16ToString(culture, (culture + 2 * cultureLength));
392
+ if (!cultureName)
393
+ throw new Error("Cannot change case, the culture name is null.");
394
+ const input = runtimeHelpers.utf16ToStringLoop(src, src + 2 * srcLength);
395
+ const result = toUpper ? input.toLocaleUpperCase(cultureName) : input.toLocaleLowerCase(cultureName);
396
+ if (result.length <= input.length) {
397
+ runtimeHelpers.stringToUTF16(dst, dst + 2 * dstLength, result);
398
+ return VoidPtrNull;
399
+ }
400
+ // workaround to maintain the ICU-like behavior
401
+ const heapI16 = runtimeHelpers.localHeapViewU16();
402
+ let jump = 1;
403
+ if (toUpper) {
404
+ for (let i = 0; i < input.length; i += jump) {
405
+ // surrogate parts have to enter ToUpper/ToLower together to give correct output
406
+ if (isSurrogate(input, i)) {
407
+ jump = 2;
408
+ const surrogate = input.substring(i, i + 2);
409
+ const upperSurrogate = surrogate.toLocaleUpperCase(cultureName);
410
+ const appendedSurrogate = upperSurrogate.length > 2 ? surrogate : upperSurrogate;
411
+ appendSurrogateToMemory(heapI16, dst, appendedSurrogate, i);
412
+ }
413
+ else {
414
+ jump = 1;
415
+ const upperChar = input[i].toLocaleUpperCase(cultureName);
416
+ const appendedChar = upperChar.length > 1 ? input[i] : upperChar;
417
+ runtimeHelpers.setU16_local(heapI16, dst + i * 2, appendedChar.charCodeAt(0));
418
+ }
419
+ }
420
+ }
421
+ else {
422
+ for (let i = 0; i < input.length; i += jump) {
423
+ // surrogate parts have to enter ToUpper/ToLower together to give correct output
424
+ if (isSurrogate(input, i)) {
425
+ jump = 2;
426
+ const surrogate = input.substring(i, i + 2);
427
+ const upperSurrogate = surrogate.toLocaleLowerCase(cultureName);
428
+ const appendedSurrogate = upperSurrogate.length > 2 ? surrogate : upperSurrogate;
429
+ appendSurrogateToMemory(heapI16, dst, appendedSurrogate, i);
430
+ }
431
+ else {
432
+ jump = 1;
433
+ const lowerChar = input[i].toLocaleLowerCase(cultureName);
434
+ const appendedChar = lowerChar.length > 1 ? input[i] : lowerChar;
435
+ runtimeHelpers.setU16_local(heapI16, dst + i * 2, appendedChar.charCodeAt(0));
436
+ }
437
+ }
438
+ }
439
+ return VoidPtrNull;
440
+ }
441
+ catch (ex) {
442
+ return runtimeHelpers.stringToUTF16Ptr(ex.toString());
443
+ }
444
+ }
445
+ function appendSurrogateToMemory(heapI16, dst, surrogate, idx) {
446
+ runtimeHelpers.setU16_local(heapI16, dst + idx * 2, surrogate.charCodeAt(0));
447
+ runtimeHelpers.setU16_local(heapI16, dst + (idx + 1) * 2, surrogate.charCodeAt(1));
448
+ }
449
+
450
+ // Licensed to the .NET Foundation under one or more agreements.
451
+ // The .NET Foundation licenses this file to you under the MIT license.
452
+ /**
453
+ * This file is partially using code from FormatJS Intl.Segmenter implementation, reference:
454
+ * https://github.com/formatjs/formatjs/blob/58d6a7b398d776ca3d2726d72ae1573b65cc3bef/packages/intl-segmenter/src/segmenter.ts
455
+ * https://github.com/formatjs/formatjs/blob/58d6a7b398d776ca3d2726d72ae1573b65cc3bef/packages/intl-segmenter/src/segmentation-utils.ts
456
+ */
457
+ let segmentationRules;
458
+ function replaceVariables(variables, input) {
459
+ const findVarRegex = /\$[A-Za-z0-9_]+/gm;
460
+ return input.replaceAll(findVarRegex, match => {
461
+ if (!(match in variables)) {
462
+ throw new Error(`No such variable ${match}`);
463
+ }
464
+ return variables[match];
465
+ });
466
+ }
467
+ function generateRegexRule(rule, variables, after) {
468
+ return new RegExp(`${after ? "^" : ""}${replaceVariables(variables, rule)}${after ? "" : "$"}`);
469
+ }
470
+ function isSegmentationTypeRaw(obj) {
471
+ return obj.variables != null && obj.rules != null;
472
+ }
473
+ function setSegmentationRulesFromJson(json) {
474
+ if (!isSegmentationTypeRaw(json))
475
+ throw new Error("Provided grapheme segmentation rules are not valid");
476
+ segmentationRules = GraphemeSegmenter.prepareSegmentationRules(json);
477
+ }
478
+ class GraphemeSegmenter {
479
+ constructor() {
480
+ this.rules = segmentationRules;
481
+ this.ruleSortedKeys = Object.keys(this.rules).sort((a, b) => Number(a) - Number(b));
482
+ }
483
+ /**
484
+ * Returns the next grapheme in the given string starting from the specified index.
485
+ * @param str - The input string.
486
+ * @param startIndex - The starting index.
487
+ * @returns The next grapheme.
488
+ */
489
+ nextGrapheme(str, startIndex) {
490
+ const breakIdx = this.nextGraphemeBreak(str, startIndex);
491
+ return str.substring(startIndex, breakIdx);
492
+ }
493
+ /**
494
+ * Finds the index of the next grapheme break in a given string starting from a specified index.
495
+ *
496
+ * @param str - The input string.
497
+ * @param startIndex - The index to start searching from.
498
+ * @returns The index of the next grapheme break.
499
+ */
500
+ nextGraphemeBreak(str, startIndex) {
501
+ if (startIndex < 0)
502
+ return 0;
503
+ if (startIndex >= str.length - 1)
504
+ return str.length;
505
+ let prev = String.fromCodePoint(str.codePointAt(startIndex));
506
+ for (let i = startIndex + 1; i < str.length; i++) {
507
+ // Don't break surrogate pairs
508
+ if (isSurrogate(str, i)) {
509
+ continue;
510
+ }
511
+ const curr = String.fromCodePoint(str.codePointAt(i));
512
+ if (this.isGraphemeBreak(prev, curr))
513
+ return i;
514
+ prev = curr;
515
+ }
516
+ return str.length;
517
+ }
518
+ isGraphemeBreak(previous, current) {
519
+ for (const key of this.ruleSortedKeys) {
520
+ const { before, after, breaks } = this.rules[key];
521
+ // match before and after rules
522
+ if (before && !before.test(previous)) {
523
+ continue;
524
+ }
525
+ if (after && !after.test(current)) {
526
+ continue;
527
+ }
528
+ return breaks;
529
+ }
530
+ // GB999: Any ÷ Any
531
+ return true;
532
+ }
533
+ static prepareSegmentationRules(segmentationRules) {
534
+ const preparedRules = {};
535
+ for (const key of Object.keys(segmentationRules.rules)) {
536
+ const ruleValue = segmentationRules.rules[key];
537
+ const preparedRule = { breaks: ruleValue.breaks, };
538
+ if ("before" in ruleValue && ruleValue.before) {
539
+ preparedRule.before = generateRegexRule(ruleValue.before, segmentationRules.variables, false);
540
+ }
541
+ if ("after" in ruleValue && ruleValue.after) {
542
+ preparedRule.after = generateRegexRule(ruleValue.after, segmentationRules.variables, true);
543
+ }
544
+ preparedRules[key] = preparedRule;
545
+ }
546
+ return preparedRules;
547
+ }
548
+ }
549
+
550
+ // Licensed to the .NET Foundation under one or more agreements.
551
+ // The .NET Foundation licenses this file to you under the MIT license.
552
+ const COMPARISON_ERROR = -2;
553
+ const INDEXING_ERROR = -1;
554
+ let graphemeSegmenterCached;
555
+ function mono_wasm_compare_string(culture, cultureLength, str1, str1Length, str2, str2Length, options, resultPtr) {
556
+ try {
557
+ const cultureName = runtimeHelpers.utf16ToString(culture, (culture + 2 * cultureLength));
558
+ const string1 = runtimeHelpers.utf16ToString(str1, (str1 + 2 * str1Length));
559
+ const string2 = runtimeHelpers.utf16ToString(str2, (str2 + 2 * str2Length));
560
+ const casePicker = (options & 0x1f);
561
+ const locale = cultureName ? cultureName : undefined;
562
+ const result = compareStrings(string1, string2, locale, casePicker);
563
+ runtimeHelpers.setI32(resultPtr, result);
564
+ return VoidPtrNull;
565
+ }
566
+ catch (ex) {
567
+ runtimeHelpers.setI32(resultPtr, COMPARISON_ERROR);
568
+ return runtimeHelpers.stringToUTF16Ptr(ex.toString());
569
+ }
570
+ }
571
+ function mono_wasm_starts_with(culture, cultureLength, str1, str1Length, str2, str2Length, options, resultPtr) {
572
+ try {
573
+ const cultureName = runtimeHelpers.utf16ToString(culture, (culture + 2 * cultureLength));
574
+ const prefix = decodeToCleanString(str2, str2Length);
575
+ // no need to look for an empty string
576
+ if (prefix.length == 0) {
577
+ runtimeHelpers.setI32(resultPtr, 1); // true
578
+ return VoidPtrNull;
579
+ }
580
+ const source = decodeToCleanString(str1, str1Length);
581
+ if (source.length < prefix.length) {
582
+ runtimeHelpers.setI32(resultPtr, 0); // false
583
+ return VoidPtrNull;
584
+ }
585
+ const sourceOfPrefixLength = source.slice(0, prefix.length);
586
+ const casePicker = (options & 0x1f);
587
+ const locale = cultureName ? cultureName : undefined;
588
+ const cmpResult = compareStrings(sourceOfPrefixLength, prefix, locale, casePicker);
589
+ const result = cmpResult === 0 ? 1 : 0; // equals ? true : false
590
+ runtimeHelpers.setI32(resultPtr, result);
591
+ return VoidPtrNull;
592
+ }
593
+ catch (ex) {
594
+ runtimeHelpers.setI32(resultPtr, INDEXING_ERROR);
595
+ return runtimeHelpers.stringToUTF16Ptr(ex.toString());
596
+ }
597
+ }
598
+ function mono_wasm_ends_with(culture, cultureLength, str1, str1Length, str2, str2Length, options, resultPtr) {
599
+ try {
600
+ const cultureName = runtimeHelpers.utf16ToString(culture, (culture + 2 * cultureLength));
601
+ const suffix = decodeToCleanString(str2, str2Length);
602
+ if (suffix.length == 0) {
603
+ runtimeHelpers.setI32(resultPtr, 1); // true
604
+ return VoidPtrNull;
605
+ }
606
+ const source = decodeToCleanString(str1, str1Length);
607
+ const diff = source.length - suffix.length;
608
+ if (diff < 0) {
609
+ runtimeHelpers.setI32(resultPtr, 0); // false
610
+ return VoidPtrNull;
611
+ }
612
+ const sourceOfSuffixLength = source.slice(diff, source.length);
613
+ const casePicker = (options & 0x1f);
614
+ const locale = cultureName ? cultureName : undefined;
615
+ const cmpResult = compareStrings(sourceOfSuffixLength, suffix, locale, casePicker);
616
+ const result = cmpResult === 0 ? 1 : 0; // equals ? true : false
617
+ runtimeHelpers.setI32(resultPtr, result);
618
+ return VoidPtrNull;
619
+ }
620
+ catch (ex) {
621
+ runtimeHelpers.setI32(resultPtr, INDEXING_ERROR);
622
+ return runtimeHelpers.stringToUTF16Ptr(ex.toString());
623
+ }
624
+ }
625
+ function mono_wasm_index_of(culture, cultureLength, needlePtr, needleLength, srcPtr, srcLength, options, fromBeginning, resultPtr) {
626
+ try {
627
+ const needle = runtimeHelpers.utf16ToString(needlePtr, (needlePtr + 2 * needleLength));
628
+ // no need to look for an empty string
629
+ if (cleanString(needle).length == 0) {
630
+ runtimeHelpers.setI32(resultPtr, fromBeginning ? 0 : srcLength);
631
+ return VoidPtrNull;
632
+ }
633
+ const source = runtimeHelpers.utf16ToString(srcPtr, (srcPtr + 2 * srcLength));
634
+ // no need to look in an empty string
635
+ if (cleanString(source).length == 0) {
636
+ runtimeHelpers.setI32(resultPtr, fromBeginning ? 0 : srcLength);
637
+ return VoidPtrNull;
638
+ }
639
+ const cultureName = runtimeHelpers.utf16ToString(culture, (culture + 2 * cultureLength));
640
+ const locale = cultureName ? cultureName : undefined;
641
+ const casePicker = (options & 0x1f);
642
+ let result = -1;
643
+ const graphemeSegmenter = graphemeSegmenterCached || (graphemeSegmenterCached = new GraphemeSegmenter());
644
+ const needleSegments = [];
645
+ let needleIdx = 0;
646
+ // Grapheme segmentation of needle string
647
+ while (needleIdx < needle.length) {
648
+ const needleGrapheme = graphemeSegmenter.nextGrapheme(needle, needleIdx);
649
+ needleSegments.push(needleGrapheme);
650
+ needleIdx += needleGrapheme.length;
651
+ }
652
+ let srcIdx = 0;
653
+ while (srcIdx < source.length) {
654
+ const srcGrapheme = graphemeSegmenter.nextGrapheme(source, srcIdx);
655
+ srcIdx += srcGrapheme.length;
656
+ if (!checkMatchFound(srcGrapheme, needleSegments[0], locale, casePicker)) {
657
+ continue;
658
+ }
659
+ let j;
660
+ let srcNextIdx = srcIdx;
661
+ for (j = 1; j < needleSegments.length; j++) {
662
+ const srcGrapheme = graphemeSegmenter.nextGrapheme(source, srcNextIdx);
663
+ if (!checkMatchFound(srcGrapheme, needleSegments[j], locale, casePicker)) {
664
+ break;
665
+ }
666
+ srcNextIdx += srcGrapheme.length;
667
+ }
668
+ if (j === needleSegments.length) {
669
+ result = srcIdx - srcGrapheme.length;
670
+ if (fromBeginning)
671
+ break;
672
+ }
673
+ }
674
+ runtimeHelpers.setI32(resultPtr, result);
675
+ return VoidPtrNull;
676
+ }
677
+ catch (ex) {
678
+ runtimeHelpers.setI32(resultPtr, INDEXING_ERROR);
679
+ return runtimeHelpers.stringToUTF16Ptr(ex.toString());
680
+ }
681
+ function checkMatchFound(str1, str2, locale, casePicker) {
682
+ return compareStrings(str1, str2, locale, casePicker) === 0;
683
+ }
684
+ }
685
+ function compareStrings(string1, string2, locale, casePicker) {
686
+ switch (casePicker) {
687
+ case 0:
688
+ // 0: None - default algorithm for the platform OR
689
+ // StringSort - for ICU it gives the same result as None, see: https://github.com/dotnet/dotnet-api-docs/issues
690
+ // does not work for "ja"
691
+ if (locale && locale.split("-")[0] === "ja")
692
+ return COMPARISON_ERROR;
693
+ return string1.localeCompare(string2, locale); // a ≠ b, a ≠ á, a ≠ A
694
+ case 8:
695
+ // 8: IgnoreKanaType works only for "ja"
696
+ if (locale && locale.split("-")[0] !== "ja")
697
+ return COMPARISON_ERROR;
698
+ return string1.localeCompare(string2, locale); // a ≠ b, a ≠ á, a ≠ A
699
+ case 1:
700
+ // 1: IgnoreCase
701
+ string1 = string1.toLocaleLowerCase(locale);
702
+ string2 = string2.toLocaleLowerCase(locale);
703
+ return string1.localeCompare(string2, locale); // a ≠ b, a ≠ á, a ≠ A
704
+ case 4:
705
+ case 12:
706
+ // 4: IgnoreSymbols
707
+ // 12: IgnoreKanaType | IgnoreSymbols
708
+ return string1.localeCompare(string2, locale, { ignorePunctuation: true }); // by default ignorePunctuation: false
709
+ case 5:
710
+ // 5: IgnoreSymbols | IgnoreCase
711
+ string1 = string1.toLocaleLowerCase(locale);
712
+ string2 = string2.toLocaleLowerCase(locale);
713
+ return string1.localeCompare(string2, locale, { ignorePunctuation: true }); // a ≠ b, a ≠ á, a ≠ A
714
+ case 9:
715
+ // 9: IgnoreKanaType | IgnoreCase
716
+ return string1.localeCompare(string2, locale, { sensitivity: "accent" }); // a ≠ b, a ≠ á, a = A
717
+ case 10:
718
+ // 10: IgnoreKanaType | IgnoreNonSpace
719
+ return string1.localeCompare(string2, locale, { sensitivity: "case" }); // a ≠ b, a = á, a ≠ A
720
+ case 11:
721
+ // 11: IgnoreKanaType | IgnoreNonSpace | IgnoreCase
722
+ return string1.localeCompare(string2, locale, { sensitivity: "base" }); // a ≠ b, a = á, a = A
723
+ case 13:
724
+ // 13: IgnoreKanaType | IgnoreCase | IgnoreSymbols
725
+ return string1.localeCompare(string2, locale, { sensitivity: "accent", ignorePunctuation: true }); // a ≠ b, a ≠ á, a = A
726
+ case 14:
727
+ // 14: IgnoreKanaType | IgnoreSymbols | IgnoreNonSpace
728
+ return string1.localeCompare(string2, locale, { sensitivity: "case", ignorePunctuation: true }); // a ≠ b, a = á, a ≠ A
729
+ case 15:
730
+ // 15: IgnoreKanaType | IgnoreSymbols | IgnoreNonSpace | IgnoreCase
731
+ return string1.localeCompare(string2, locale, { sensitivity: "base", ignorePunctuation: true }); // a ≠ b, a = á, a = A
732
+ case 2:
733
+ case 3:
734
+ case 6:
735
+ case 7:
736
+ case 16:
737
+ case 17:
738
+ case 18:
739
+ case 19:
740
+ case 20:
741
+ case 21:
742
+ case 22:
743
+ case 23:
744
+ case 24:
745
+ case 25:
746
+ case 26:
747
+ case 27:
748
+ case 28:
749
+ case 29:
750
+ case 30:
751
+ case 31:
752
+ default:
753
+ // 2: IgnoreNonSpace
754
+ // 3: IgnoreNonSpace | IgnoreCase
755
+ // 6: IgnoreSymbols | IgnoreNonSpace
756
+ // 7: IgnoreSymbols | IgnoreNonSpace | IgnoreCase
757
+ // 16: IgnoreWidth
758
+ // 17: IgnoreWidth | IgnoreCase
759
+ // 18: IgnoreWidth | IgnoreNonSpace
760
+ // 19: IgnoreWidth | IgnoreNonSpace | IgnoreCase
761
+ // 20: IgnoreWidth | IgnoreSymbols
762
+ // 21: IgnoreWidth | IgnoreSymbols | IgnoreCase
763
+ // 22: IgnoreWidth | IgnoreSymbols | IgnoreNonSpace
764
+ // 23: IgnoreWidth | IgnoreSymbols | IgnoreNonSpace | IgnoreCase
765
+ // 24: IgnoreKanaType | IgnoreWidth
766
+ // 25: IgnoreKanaType | IgnoreWidth | IgnoreCase
767
+ // 26: IgnoreKanaType | IgnoreWidth | IgnoreNonSpace
768
+ // 27: IgnoreKanaType | IgnoreWidth | IgnoreNonSpace | IgnoreCase
769
+ // 28: IgnoreKanaType | IgnoreWidth | IgnoreSymbols
770
+ // 29: IgnoreKanaType | IgnoreWidth | IgnoreSymbols | IgnoreCase
771
+ // 30: IgnoreKanaType | IgnoreWidth | IgnoreSymbols | IgnoreNonSpace
772
+ // 31: IgnoreKanaType | IgnoreWidth | IgnoreSymbols | IgnoreNonSpace | IgnoreCase
773
+ throw new Error(`Invalid comparison option. Option=${casePicker}`);
774
+ }
775
+ }
776
+ function decodeToCleanString(strPtr, strLen) {
777
+ const str = runtimeHelpers.utf16ToString(strPtr, (strPtr + 2 * strLen));
778
+ return cleanString(str);
779
+ }
780
+ function cleanString(str) {
781
+ const nStr = str.normalize();
782
+ return nStr.replace(/[\u200B-\u200D\uFEFF\0]/g, "");
783
+ }
784
+
785
+ // Licensed to the .NET Foundation under one or more agreements.
786
+ // The .NET Foundation licenses this file to you under the MIT license.
787
+ const NO_PREFIX_24H = "H";
788
+ const PREFIX_24H = "HH";
789
+ const NO_PREFIX_12H = "h";
790
+ const PREFIX_12H = "hh";
791
+ const SECONDS_CODE = "ss";
792
+ const MINUTES_CODE = "mm";
793
+ const DESIGNATOR_CODE = "tt";
794
+ // Note: wrapSubstrings
795
+ // The character "h" can be ambiguous as it might represent an hour code hour code and a fixed (quoted) part of the format.
796
+ // Special Case for "fr-CA": Always recognize "HH" as a keyword and do not quote it, to avoid formatting issues.
797
+ const keyWords = [SECONDS_CODE, MINUTES_CODE, DESIGNATOR_CODE, PREFIX_24H];
798
+ function mono_wasm_get_culture_info(culture, cultureLength, dst, dstMaxLength, dstLength) {
799
+ try {
800
+ const cultureName = runtimeHelpers.utf16ToString(culture, (culture + 2 * cultureLength));
801
+ const cultureInfo = {
802
+ AmDesignator: "",
803
+ PmDesignator: "",
804
+ LongTimePattern: "",
805
+ ShortTimePattern: ""
806
+ };
807
+ const canonicalLocale = normalizeLocale(cultureName);
808
+ const designators = getAmPmDesignators(canonicalLocale);
809
+ cultureInfo.AmDesignator = designators.am;
810
+ cultureInfo.PmDesignator = designators.pm;
811
+ cultureInfo.LongTimePattern = getLongTimePattern(canonicalLocale, designators);
812
+ cultureInfo.ShortTimePattern = getShortTimePattern(cultureInfo.LongTimePattern);
813
+ const result = Object.values(cultureInfo).join(OUTER_SEPARATOR);
814
+ if (result.length > dstMaxLength) {
815
+ throw new Error(`Culture info exceeds length of ${dstMaxLength}.`);
816
+ }
817
+ runtimeHelpers.stringToUTF16(dst, dst + 2 * result.length, result);
818
+ runtimeHelpers.setI32(dstLength, result.length);
819
+ return VoidPtrNull;
820
+ }
821
+ catch (ex) {
822
+ runtimeHelpers.setI32(dstLength, -1);
823
+ return runtimeHelpers.stringToUTF16Ptr(ex.toString());
824
+ }
825
+ }
826
+ function getAmPmDesignators(locale) {
827
+ const pmTime = new Date("August 19, 1975 12:15:33"); // do not change, some PM hours result in hour digits change, e.g. 13 -> 01 or 1
828
+ const amTime = new Date("August 19, 1975 11:15:33"); // do not change, some AM hours result in hour digits change, e.g. 9 -> 09
829
+ const pmDesignator = getDesignator(pmTime, locale);
830
+ const amDesignator = getDesignator(amTime, locale);
831
+ return {
832
+ am: amDesignator,
833
+ pm: pmDesignator
834
+ };
835
+ }
836
+ function getDesignator(time, locale) {
837
+ let withDesignator = time.toLocaleTimeString(locale, { hourCycle: "h12" });
838
+ const localizedZero = (0).toLocaleString(locale);
839
+ if (withDesignator.includes(localizedZero)) {
840
+ // in v8>=11.8 "12" changes to "0" for ja-JP
841
+ const localizedTwelve = (12).toLocaleString(locale);
842
+ withDesignator = withDesignator.replace(localizedZero, localizedTwelve);
843
+ }
844
+ const withoutDesignator = time.toLocaleTimeString(locale, { hourCycle: "h24" });
845
+ const designator = withDesignator.replace(withoutDesignator, "").trim();
846
+ if (new RegExp("[0-9]$").test(designator)) {
847
+ const designatorParts = withDesignator.split(" ").filter(part => new RegExp("^((?![0-9]).)*$").test(part));
848
+ if (!designatorParts || designatorParts.length == 0)
849
+ return "";
850
+ return designatorParts.join(" ");
851
+ }
852
+ return designator;
853
+ }
854
+ function getLongTimePattern(locale, designators) {
855
+ const hourIn24Format = 18; // later hours than 18 have night designators in some locales (instead of AM designator)
856
+ const hourIn12Format = 6;
857
+ const localizedHour24 = (hourIn24Format).toLocaleString(locale); // not all locales use arabic numbers
858
+ const localizedHour12 = (hourIn12Format).toLocaleString(locale);
859
+ const pmTime = new Date(`August 19, 1975 ${hourIn24Format}:15:30`); // in the comments, en-US locale is used:
860
+ const shortTime = new Intl.DateTimeFormat(locale, { timeStyle: "medium" });
861
+ const shortPmStyle = shortTime.format(pmTime); // 12:15:30 PM
862
+ const minutes = pmTime.toLocaleTimeString(locale, { minute: "numeric" }); // 15
863
+ const seconds = pmTime.toLocaleTimeString(locale, { second: "numeric" }); // 30
864
+ let pattern = shortPmStyle.replace(designators.pm, DESIGNATOR_CODE).replace(minutes, MINUTES_CODE).replace(seconds, SECONDS_CODE); // 12:mm:ss tt
865
+ const isISOStyle = pattern.includes(localizedHour24); // 24h or 12h pattern?
866
+ const localized0 = (0).toLocaleString(locale);
867
+ const hour12WithPrefix = `${localized0}${localizedHour12}`; // 06
868
+ const amTime = new Date(`August 19, 1975 ${hourIn12Format}:15:30`);
869
+ const h12Style = shortTime.format(amTime);
870
+ let hourPattern;
871
+ if (isISOStyle) { // 24h
872
+ const hasPrefix = h12Style.includes(hour12WithPrefix);
873
+ hourPattern = hasPrefix ? PREFIX_24H : NO_PREFIX_24H;
874
+ pattern = pattern.replace(localizedHour24, hourPattern);
875
+ }
876
+ else { // 12h
877
+ const hasPrefix = h12Style.includes(hour12WithPrefix);
878
+ hourPattern = hasPrefix ? PREFIX_12H : NO_PREFIX_12H;
879
+ pattern = pattern.replace(hasPrefix ? hour12WithPrefix : localizedHour12, hourPattern);
880
+ }
881
+ return wrapSubstrings(pattern);
882
+ }
883
+ function getShortTimePattern(pattern) {
884
+ // remove seconds:
885
+ // short dotnet pattern does not contain seconds while JS's pattern always contains them
886
+ const secondsIdx = pattern.indexOf(SECONDS_CODE);
887
+ if (secondsIdx > 0) {
888
+ const secondsWithSeparator = `${pattern[secondsIdx - 1]}${SECONDS_CODE}`;
889
+ // en-US: 12:mm:ss tt -> 12:mm tt;
890
+ // fr-CA: 12 h mm min ss s -> 12 h mm min s
891
+ const shortPatternNoSecondsDigits = pattern.replace(secondsWithSeparator, "");
892
+ if (shortPatternNoSecondsDigits.length > secondsIdx && shortPatternNoSecondsDigits[shortPatternNoSecondsDigits.length - 1] != "t") {
893
+ pattern = pattern.split(secondsWithSeparator)[0];
894
+ }
895
+ else {
896
+ pattern = shortPatternNoSecondsDigits;
897
+ }
898
+ }
899
+ return pattern;
900
+ }
901
+ // wraps all substrings in the format in quotes, except for key words
902
+ // transform e.g. "HH h mm min ss s" into "HH 'h' mm 'min' ss 's'"
903
+ function wrapSubstrings(str) {
904
+ const words = str.split(/\s+/);
905
+ for (let i = 0; i < words.length; i++) {
906
+ if (!words[i].includes(":") && !words[i].includes(".") && !keyWords.includes(words[i])) {
907
+ words[i] = `'${words[i]}'`;
908
+ }
909
+ }
910
+ return words.join(" ");
911
+ }
912
+
913
+ // Licensed to the .NET Foundation under one or more agreements.
914
+ // The .NET Foundation licenses this file to you under the MIT license.
915
+ function mono_wasm_get_first_day_of_week(culture, cultureLength, resultPtr) {
916
+ try {
917
+ const cultureName = runtimeHelpers.utf16ToString(culture, (culture + 2 * cultureLength));
918
+ const canonicalLocale = normalizeLocale(cultureName);
919
+ const result = getFirstDayOfWeek(canonicalLocale);
920
+ runtimeHelpers.setI32(resultPtr, result);
921
+ return VoidPtrNull;
922
+ }
923
+ catch (ex) {
924
+ runtimeHelpers.setI32(resultPtr, -1);
925
+ return runtimeHelpers.stringToUTF16Ptr(ex.toString());
926
+ }
927
+ }
928
+ function mono_wasm_get_first_week_of_year(culture, cultureLength, resultPtr) {
929
+ try {
930
+ const cultureName = runtimeHelpers.utf16ToString(culture, (culture + 2 * cultureLength));
931
+ const canonicalLocale = normalizeLocale(cultureName);
932
+ const result = getFirstWeekOfYear(canonicalLocale);
933
+ runtimeHelpers.setI32(resultPtr, result);
934
+ return VoidPtrNull;
935
+ }
936
+ catch (ex) {
937
+ runtimeHelpers.setI32(resultPtr, -1);
938
+ return runtimeHelpers.stringToUTF16Ptr(ex.toString());
939
+ }
940
+ }
941
+ function getFirstDayOfWeek(locale) {
942
+ const weekInfo = getWeekInfo(locale);
943
+ if (weekInfo) {
944
+ // JS's Sunday == 7 while dotnet's Sunday == 0
945
+ return weekInfo.firstDay == 7 ? 0 : weekInfo.firstDay;
946
+ }
947
+ // Firefox does not support it rn but we can make a temporary workaround for it,
948
+ // that should be removed when it starts being supported:
949
+ const saturdayLocales = ["en-AE", "en-SD", "fa-IR"];
950
+ if (saturdayLocales.includes(locale)) {
951
+ return 6;
952
+ }
953
+ const sundayLanguages = ["th", "pt", "mr", "ml", "ko", "kn", "ja", "id", "hi", "he", "gu", "fil", "bn", "am", "ar", "te"];
954
+ const sundayLocales = ["ta-SG", "ta-IN", "sw-KE", "ms-SG", "fr-CA", "es-MX", "en-US", "en-ZW", "en-ZA", "en-WS", "en-VI", "en-UM", "en-TT", "en-SG", "en-PR", "en-PK", "en-PH", "en-MT", "en-MO", "en-MH", "en-KE", "en-JM", "en-IN", "en-IL", "en-HK", "en-GU", "en-DM", "en-CA", "en-BZ", "en-BW", "en-BS", "en-AS", "en-AG", "zh-Hans-HK", "zh-SG", "zh-HK", "zh-TW"]; // "en-AU" is Monday in chrome, so firefox should be in line
955
+ const localeLang = locale.split("-")[0];
956
+ if (sundayLanguages.includes(localeLang) || sundayLocales.includes(locale)) {
957
+ return 0;
958
+ }
959
+ return 1;
960
+ }
961
+ function getFirstWeekOfYear(locale) {
962
+ const weekInfo = getWeekInfo(locale);
963
+ if (weekInfo) {
964
+ // enum CalendarWeekRule
965
+ // FirstDay = 0, // when minimalDays < 4
966
+ // FirstFullWeek = 1, // when miminalDays == 7
967
+ // FirstFourDayWeek = 2 // when miminalDays >= 4
968
+ return weekInfo.minimalDays == 7 ? 1 :
969
+ weekInfo.minimalDays < 4 ? 0 : 2;
970
+ }
971
+ // Firefox does not support it rn but we can make a temporary workaround for it,
972
+ // that should be removed when it starts being supported:
973
+ const firstFourDayWeekLocales = ["pt-PT", "fr-CH", "fr-FR", "fr-BE", "es-ES", "en-SE", "en-NL", "en-JE", "en-IM", "en-IE", "en-GI", "en-GG", "en-GB", "en-FJ", "en-FI", "en-DK", "en-DE", "en-CH", "en-BE", "en-AT", "el-GR", "nl-BE", "nl-NL"];
974
+ const firstFourDayWeekLanguages = ["sv", "sk", "ru", "pl", "no", "nb", "lt", "it", "hu", "fi", "et", "de", "da", "cs", "ca", "bg"];
975
+ const localeLang = locale.split("-")[0];
976
+ if (firstFourDayWeekLocales.includes(locale) || firstFourDayWeekLanguages.includes(localeLang)) {
977
+ return 2;
978
+ }
979
+ return 0;
980
+ }
981
+ function getWeekInfo(locale) {
982
+ try {
983
+ // most tools have it implemented as property
984
+ return new Intl.Locale(locale).weekInfo;
985
+ }
986
+ catch (_a) {
987
+ try {
988
+ // but a few use methods, which is the preferred way
989
+ return new Intl.Locale(locale).getWeekInfo();
990
+ }
991
+ catch (_b) {
992
+ return undefined;
993
+ }
994
+ }
995
+ }
996
+
997
+ let globalizationHelpers;
998
+ let runtimeHelpers;
999
+ function initHybrid(gh, rh) {
1000
+ gh.mono_wasm_change_case = mono_wasm_change_case;
1001
+ gh.mono_wasm_compare_string = mono_wasm_compare_string;
1002
+ gh.mono_wasm_starts_with = mono_wasm_starts_with;
1003
+ gh.mono_wasm_ends_with = mono_wasm_ends_with;
1004
+ gh.mono_wasm_index_of = mono_wasm_index_of;
1005
+ gh.mono_wasm_get_calendar_info = mono_wasm_get_calendar_info;
1006
+ gh.mono_wasm_get_culture_info = mono_wasm_get_culture_info;
1007
+ gh.mono_wasm_get_first_day_of_week = mono_wasm_get_first_day_of_week;
1008
+ gh.mono_wasm_get_first_week_of_year = mono_wasm_get_first_week_of_year;
1009
+ gh.setSegmentationRulesFromJson = setSegmentationRulesFromJson;
1010
+ globalizationHelpers = gh;
1011
+ runtimeHelpers = rh;
1012
+ }
1013
+
1014
+ export { globalizationHelpers, initHybrid, runtimeHelpers };
1015
+ //# sourceMappingURL=dotnet.globalization.js.map