unicode-input-toolconverter 0.2.0 → 0.2.3

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 (143) hide show
  1. package/.nyc_output/out.json +8980 -1849
  2. package/CHANGES.md +15 -1
  3. package/README.md +6 -11
  4. package/_locales/en-US/messages.json +153 -6
  5. package/_locales/hu-HU/messages.json +153 -6
  6. package/_locales/pt-BR/messages.json +153 -6
  7. package/_locales/sv-SE/messages.json +153 -6
  8. package/babel.config.json +0 -1
  9. package/browser_action/characterSelection.js +18 -11
  10. package/browser_action/charrefConverters.js +286 -79
  11. package/browser_action/chartBuild.js +97 -27
  12. package/browser_action/encodingBehaviors.js +10 -7
  13. package/browser_action/entityBehaviors.js +42 -16
  14. package/browser_action/index-es.html +13 -1
  15. package/browser_action/index-instrumented.html +13 -1
  16. package/browser_action/index-pages.html +13 -1
  17. package/browser_action/index.html +13 -1
  18. package/browser_action/index.iife.min.js +9 -1
  19. package/browser_action/index.iife.min.js.map +1 -1
  20. package/browser_action/index.instrumented.iife.min.js +1 -1
  21. package/browser_action/index.instrumented.iife.min.js.map +1 -1
  22. package/browser_action/index.js +5 -5
  23. package/browser_action/preferences/prefDefaults.js +12 -3
  24. package/browser_action/service-worker/sw-activateCallback.js +1 -2
  25. package/browser_action/service-worker/sw-resources.json +6 -4
  26. package/browser_action/templateUtils/elements.js +12 -1
  27. package/browser_action/templateUtils/fill.js +6 -0
  28. package/browser_action/templateUtils/validation.js +4 -1
  29. package/browser_action/templates/chartBuild.js +167 -102
  30. package/browser_action/templates/index.js +227 -53
  31. package/browser_action/templatesElementCustomization/widgets.js +40 -15
  32. package/browser_action/unicode/UnicodeConverter.js +99 -73
  33. package/browser_action/unicode/charrefunicodeDb.js +100 -50
  34. package/browser_action/unicode/getScriptInfoForCodePoint.js +13 -4
  35. package/browser_action/unicode/hangul.js +27 -20
  36. package/browser_action/unicode/lastScriptNames.json +1 -1
  37. package/browser_action/unicode/parseUnihanFromTextFileStrings.js +44 -25
  38. package/browser_action/unicode/unicodeFieldInfo.js +112 -90
  39. package/browser_action/unicode/unicodeScripts.js +409 -35
  40. package/browser_action/unicode/unihan.js +4 -3
  41. package/browser_action/unicode/unihanDbPopulate.js +7 -2
  42. package/browser_action/unicode/unihanFields.js +34 -0
  43. package/browser_action/unicodecharref.js +353 -190
  44. package/browser_action/utils/DOMUtils.js +95 -34
  45. package/browser_action/utils/FetchUtils.js +7 -6
  46. package/browser_action/utils/TextUtils.js +4 -4
  47. package/browser_action/utils/TypedArrayUtils.js +9 -5
  48. package/browser_action/utils/semicolonSeparatedToArray.js +3 -3
  49. package/browser_action/utils/setupServiceWorker.js +2 -2
  50. package/eslint.config.js +11 -0
  51. package/icons/openWindow16.png +0 -0
  52. package/icons/openWindow24.png +0 -0
  53. package/lib/background.html +7 -0
  54. package/lib/background.js +2 -2
  55. package/package.json +80 -70
  56. package/pnpm-workspace.yaml +8 -0
  57. package/server.js +66 -51
  58. package/sw.js +97 -56
  59. package/tools/entities-import.js +4 -1
  60. package/tools/findEsResources.js +33 -10
  61. package/tools/fix-sw-resources-vendor-paths.js +60 -0
  62. package/tools/list-locales.js +2 -2
  63. package/tools/parseUnicodeCharts.js +126 -60
  64. package/tools/ucd-import.js +1 -10
  65. package/tools/unicode-charts.html +49 -20
  66. package/tools/unihan-import.js +45 -15
  67. package/tools/write-sw-version.js +16 -0
  68. package/tsconfig.json +23 -0
  69. package/typings/__coverage__.d.ts +5 -0
  70. package/typings/apple-system-profiler.d.ts +17 -0
  71. package/typings/commands.d.ts +19 -0
  72. package/typings/json-6.d.ts +4 -0
  73. package/typings/rollup-plugin-istanbul.d.ts +3 -0
  74. package/vendor/camelcase/index.d.ts +154 -0
  75. package/vendor/camelcase/index.js +137 -23
  76. package/vendor/fflate/esm/browser.d.ts +1539 -0
  77. package/vendor/fflate/esm/browser.js +82 -55
  78. package/vendor/intl-dom/dist/Formatter.d.ts +120 -0
  79. package/vendor/intl-dom/dist/Formatter.d.ts.map +1 -0
  80. package/vendor/intl-dom/dist/collation.d.ts +42 -0
  81. package/vendor/intl-dom/dist/collation.d.ts.map +1 -0
  82. package/vendor/intl-dom/dist/defaultAllSubstitutions.d.ts +52 -0
  83. package/vendor/intl-dom/dist/defaultAllSubstitutions.d.ts.map +1 -0
  84. package/vendor/intl-dom/dist/defaultInsertNodes.d.ts +96 -0
  85. package/vendor/intl-dom/dist/defaultInsertNodes.d.ts.map +1 -0
  86. package/vendor/intl-dom/dist/defaultKeyCheckerConverter.d.ts +17 -0
  87. package/vendor/intl-dom/dist/defaultKeyCheckerConverter.d.ts.map +1 -0
  88. package/vendor/intl-dom/dist/defaultLocaleResolver.d.ts +285 -0
  89. package/vendor/intl-dom/dist/defaultLocaleResolver.d.ts.map +1 -0
  90. package/vendor/intl-dom/dist/findLocaleStrings.d.ts +88 -0
  91. package/vendor/intl-dom/dist/findLocaleStrings.d.ts.map +1 -0
  92. package/vendor/intl-dom/dist/getDOMForLocaleString.d.ts +67 -0
  93. package/vendor/intl-dom/dist/getDOMForLocaleString.d.ts.map +1 -0
  94. package/vendor/intl-dom/dist/getMessageForKeyByStyle.d.ts +73 -0
  95. package/vendor/intl-dom/dist/getMessageForKeyByStyle.d.ts.map +1 -0
  96. package/vendor/intl-dom/dist/getStringFromMessageAndDefaults.d.ts +26 -0
  97. package/vendor/intl-dom/dist/getStringFromMessageAndDefaults.d.ts.map +1 -0
  98. package/vendor/intl-dom/dist/i18n.d.ts +113 -0
  99. package/vendor/intl-dom/dist/i18n.d.ts.map +1 -0
  100. package/vendor/intl-dom/dist/index.d.ts +92 -0
  101. package/vendor/intl-dom/dist/index.d.ts.map +1 -0
  102. package/vendor/intl-dom/dist/index.esm.d.ts +34 -0
  103. package/vendor/intl-dom/dist/index.esm.js +854 -896
  104. package/vendor/intl-dom/dist/index.esm.min.js +4 -0
  105. package/vendor/intl-dom/dist/index.esm.min.js.map +1 -0
  106. package/vendor/intl-dom/dist/index.umd.js +2953 -0
  107. package/vendor/intl-dom/dist/index.umd.min.js +4 -0
  108. package/vendor/intl-dom/dist/index.umd.min.js.map +1 -0
  109. package/vendor/intl-dom/dist/promiseChainForValues.d.ts +34 -0
  110. package/vendor/intl-dom/dist/promiseChainForValues.d.ts.map +1 -0
  111. package/vendor/intl-dom/dist/shared.d.ts +20 -0
  112. package/vendor/intl-dom/dist/shared.d.ts.map +1 -0
  113. package/vendor/intl-dom/dist/utils.d.ts +53 -0
  114. package/vendor/intl-dom/dist/utils.d.ts.map +1 -0
  115. package/vendor/jamilih/dist/jml.d.mts +468 -0
  116. package/vendor/jamilih/dist/{jml-es.js → jml.mjs} +1489 -343
  117. package/vendor/jquery/dist/jquery.js +1677 -2713
  118. package/vendor/json-6/dist/index.mjs +2 -0
  119. package/vendor/miller-columns/CHANGES.md +185 -0
  120. package/vendor/miller-columns/LICENSE-MIT.txt +21 -0
  121. package/vendor/miller-columns/README.md +249 -0
  122. package/vendor/miller-columns/demos/index.html +69 -0
  123. package/vendor/miller-columns/demos/index.js +72 -0
  124. package/vendor/miller-columns/dist/index-es.js +748 -0
  125. package/vendor/miller-columns/dist/index-es.min.d.ts +25 -0
  126. package/vendor/miller-columns/dist/index-es.min.js +7 -1
  127. package/vendor/miller-columns/dist/index-umd.js +757 -0
  128. package/vendor/miller-columns/dist/index-umd.min.js +7 -0
  129. package/vendor/miller-columns/dist/index.d.ts +25 -0
  130. package/vendor/miller-columns/dist/millerColumns.d.ts +10 -0
  131. package/vendor/miller-columns/eslint.config.js +46 -0
  132. package/vendor/miller-columns/fix-declarations.js +18 -0
  133. package/vendor/miller-columns/miller-columns.css +24 -1
  134. package/vendor/miller-columns/package.json +73 -0
  135. package/vendor/miller-columns/pnpm-workspace.yaml +2 -0
  136. package/vendor/miller-columns/src/index.js +642 -0
  137. package/vendor/miller-columns/src/millerColumns.ts +12 -0
  138. package/vendor/miller-columns/tsconfig-prod.json +23 -0
  139. package/vendor/miller-columns/tsconfig.json +21 -0
  140. package/vendor/simple-prefs/dist/index.esm.d.ts +1 -0
  141. package/vendor/simple-prefs/dist/index.esm.js +164 -216
  142. package/vendor/simple-prefs/dist/simple-prefs.d.ts +117 -0
  143. package/lgtm.yml +0 -5
@@ -0,0 +1,2953 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.IntlDom = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ function _arrayLikeToArray(r, a) {
8
+ (null == a || a > r.length) && (a = r.length);
9
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
10
+ return n;
11
+ }
12
+ function _arrayWithHoles(r) {
13
+ if (Array.isArray(r)) return r;
14
+ }
15
+ function _arrayWithoutHoles(r) {
16
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
17
+ }
18
+ function _assertThisInitialized(e) {
19
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
20
+ return e;
21
+ }
22
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
23
+ try {
24
+ var i = n[a](c),
25
+ u = i.value;
26
+ } catch (n) {
27
+ return void e(n);
28
+ }
29
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
30
+ }
31
+ function _asyncToGenerator(n) {
32
+ return function () {
33
+ var t = this,
34
+ e = arguments;
35
+ return new Promise(function (r, o) {
36
+ var a = n.apply(t, e);
37
+ function _next(n) {
38
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
39
+ }
40
+ function _throw(n) {
41
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
42
+ }
43
+ _next(void 0);
44
+ });
45
+ };
46
+ }
47
+ function _callSuper(t, o, e) {
48
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, [], _getPrototypeOf(t).constructor) : o.apply(t, e));
49
+ }
50
+ function _classCallCheck(a, n) {
51
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
52
+ }
53
+ function _defineProperties(e, r) {
54
+ for (var t = 0; t < r.length; t++) {
55
+ var o = r[t];
56
+ o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
57
+ }
58
+ }
59
+ function _createClass(e, r, t) {
60
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
61
+ writable: false
62
+ }), e;
63
+ }
64
+ function _defineProperty(e, r, t) {
65
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
66
+ value: t,
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true
70
+ }) : e[r] = t, e;
71
+ }
72
+ function _getPrototypeOf(t) {
73
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
74
+ return t.__proto__ || Object.getPrototypeOf(t);
75
+ }, _getPrototypeOf(t);
76
+ }
77
+ function _inherits(t, e) {
78
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
79
+ t.prototype = Object.create(e && e.prototype, {
80
+ constructor: {
81
+ value: t,
82
+ writable: true,
83
+ configurable: true
84
+ }
85
+ }), Object.defineProperty(t, "prototype", {
86
+ writable: false
87
+ }), e && _setPrototypeOf(t, e);
88
+ }
89
+ function _isNativeReflectConstruct() {
90
+ try {
91
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
92
+ } catch (t) {}
93
+ return (_isNativeReflectConstruct = function () {
94
+ return !!t;
95
+ })();
96
+ }
97
+ function _iterableToArray(r) {
98
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
99
+ }
100
+ function _iterableToArrayLimit(r, l) {
101
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
102
+ if (null != t) {
103
+ var e,
104
+ n,
105
+ i,
106
+ u,
107
+ a = [],
108
+ f = true,
109
+ o = false;
110
+ try {
111
+ if (i = (t = t.call(r)).next, 0 === l) {
112
+ if (Object(t) !== t) return;
113
+ f = !1;
114
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
115
+ } catch (r) {
116
+ o = true, n = r;
117
+ } finally {
118
+ try {
119
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
120
+ } finally {
121
+ if (o) throw n;
122
+ }
123
+ }
124
+ return a;
125
+ }
126
+ }
127
+ function _nonIterableRest() {
128
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
129
+ }
130
+ function _nonIterableSpread() {
131
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
132
+ }
133
+ function ownKeys(e, r) {
134
+ var t = Object.keys(e);
135
+ if (Object.getOwnPropertySymbols) {
136
+ var o = Object.getOwnPropertySymbols(e);
137
+ r && (o = o.filter(function (r) {
138
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
139
+ })), t.push.apply(t, o);
140
+ }
141
+ return t;
142
+ }
143
+ function _objectSpread2(e) {
144
+ for (var r = 1; r < arguments.length; r++) {
145
+ var t = null != arguments[r] ? arguments[r] : {};
146
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
147
+ _defineProperty(e, r, t[r]);
148
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
149
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
150
+ });
151
+ }
152
+ return e;
153
+ }
154
+ function _possibleConstructorReturn(t, e) {
155
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
156
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
157
+ return _assertThisInitialized(t);
158
+ }
159
+ function _regenerator() {
160
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
161
+ var e,
162
+ t,
163
+ r = "function" == typeof Symbol ? Symbol : {},
164
+ n = r.iterator || "@@iterator",
165
+ o = r.toStringTag || "@@toStringTag";
166
+ function i(r, n, o, i) {
167
+ var c = n && n.prototype instanceof Generator ? n : Generator,
168
+ u = Object.create(c.prototype);
169
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
170
+ var i,
171
+ c,
172
+ u,
173
+ f = 0,
174
+ p = o || [],
175
+ y = false,
176
+ G = {
177
+ p: 0,
178
+ n: 0,
179
+ v: e,
180
+ a: d,
181
+ f: d.bind(e, 4),
182
+ d: function (t, r) {
183
+ return i = t, c = 0, u = e, G.n = r, a;
184
+ }
185
+ };
186
+ function d(r, n) {
187
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
188
+ var o,
189
+ i = p[t],
190
+ d = G.p,
191
+ l = i[2];
192
+ r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
193
+ }
194
+ if (o || r > 1) return a;
195
+ throw y = true, n;
196
+ }
197
+ return function (o, p, l) {
198
+ if (f > 1) throw TypeError("Generator is already running");
199
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
200
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
201
+ try {
202
+ if (f = 2, i) {
203
+ if (c || (o = "next"), t = i[o]) {
204
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
205
+ if (!t.done) return t;
206
+ u = t.value, c < 2 && (c = 0);
207
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
208
+ i = e;
209
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
210
+ } catch (t) {
211
+ i = e, c = 1, u = t;
212
+ } finally {
213
+ f = 1;
214
+ }
215
+ }
216
+ return {
217
+ value: t,
218
+ done: y
219
+ };
220
+ };
221
+ }(r, o, i), true), u;
222
+ }
223
+ var a = {};
224
+ function Generator() {}
225
+ function GeneratorFunction() {}
226
+ function GeneratorFunctionPrototype() {}
227
+ t = Object.getPrototypeOf;
228
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
229
+ return this;
230
+ }), t),
231
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
232
+ function f(e) {
233
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
234
+ }
235
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
236
+ return this;
237
+ }), _regeneratorDefine(u, "toString", function () {
238
+ return "[object Generator]";
239
+ }), (_regenerator = function () {
240
+ return {
241
+ w: i,
242
+ m: f
243
+ };
244
+ })();
245
+ }
246
+ function _regeneratorDefine(e, r, n, t) {
247
+ var i = Object.defineProperty;
248
+ try {
249
+ i({}, "", {});
250
+ } catch (e) {
251
+ i = 0;
252
+ }
253
+ _regeneratorDefine = function (e, r, n, t) {
254
+ function o(r, n) {
255
+ _regeneratorDefine(e, r, function (e) {
256
+ return this._invoke(r, n, e);
257
+ });
258
+ }
259
+ r ? i ? i(e, r, {
260
+ value: n,
261
+ enumerable: !t,
262
+ configurable: !t,
263
+ writable: !t
264
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
265
+ }, _regeneratorDefine(e, r, n, t);
266
+ }
267
+ function _setPrototypeOf(t, e) {
268
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
269
+ return t.__proto__ = e, t;
270
+ }, _setPrototypeOf(t, e);
271
+ }
272
+ function _slicedToArray(r, e) {
273
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
274
+ }
275
+ function _taggedTemplateLiteral(e, t) {
276
+ return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, {
277
+ raw: {
278
+ value: Object.freeze(t)
279
+ }
280
+ }));
281
+ }
282
+ function _toConsumableArray(r) {
283
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
284
+ }
285
+ function _toPrimitive(t, r) {
286
+ if ("object" != typeof t || !t) return t;
287
+ var e = t[Symbol.toPrimitive];
288
+ if (void 0 !== e) {
289
+ var i = e.call(t, r);
290
+ if ("object" != typeof i) return i;
291
+ throw new TypeError("@@toPrimitive must return a primitive value.");
292
+ }
293
+ return ("string" === r ? String : Number)(t);
294
+ }
295
+ function _toPropertyKey(t) {
296
+ var i = _toPrimitive(t, "string");
297
+ return "symbol" == typeof i ? i : i + "";
298
+ }
299
+ function _typeof(o) {
300
+ "@babel/helpers - typeof";
301
+
302
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
303
+ return typeof o;
304
+ } : function (o) {
305
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
306
+ }, _typeof(o);
307
+ }
308
+ function _unsupportedIterableToArray(r, a) {
309
+ if (r) {
310
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
311
+ var t = {}.toString.call(r).slice(8, -1);
312
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
313
+ }
314
+ }
315
+ function _wrapRegExp() {
316
+ _wrapRegExp = function (e, r) {
317
+ return new BabelRegExp(e, void 0, r);
318
+ };
319
+ var e = RegExp.prototype,
320
+ r = new WeakMap();
321
+ function BabelRegExp(e, t, p) {
322
+ var o = RegExp(e, t);
323
+ return r.set(o, p || r.get(e)), _setPrototypeOf(o, BabelRegExp.prototype);
324
+ }
325
+ function buildGroups(e, t) {
326
+ var p = r.get(t);
327
+ return Object.keys(p).reduce(function (r, t) {
328
+ var o = p[t];
329
+ if ("number" == typeof o) r[t] = e[o];else {
330
+ for (var i = 0; void 0 === e[o[i]] && i + 1 < o.length;) i++;
331
+ r[t] = e[o[i]];
332
+ }
333
+ return r;
334
+ }, Object.create(null));
335
+ }
336
+ return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (r) {
337
+ var t = e.exec.call(this, r);
338
+ if (t) {
339
+ t.groups = buildGroups(t, this);
340
+ var p = t.indices;
341
+ p && (p.groups = buildGroups(p, this));
342
+ }
343
+ return t;
344
+ }, BabelRegExp.prototype[Symbol.replace] = function (t, p) {
345
+ if ("string" == typeof p) {
346
+ var o = r.get(this);
347
+ return e[Symbol.replace].call(this, t, p.replace(/\$<([^>]+)(>|$)/g, function (e, r, t) {
348
+ if ("" === t) return e;
349
+ var p = o[r];
350
+ return Array.isArray(p) ? "$" + p.join("$") : "number" == typeof p ? "$" + p : "";
351
+ }));
352
+ }
353
+ if ("function" == typeof p) {
354
+ var i = this;
355
+ return e[Symbol.replace].call(this, t, function () {
356
+ var e = arguments;
357
+ return "object" != typeof e[e.length - 1] && (e = [].slice.call(e)).push(buildGroups(e, i)), p.apply(this, e);
358
+ });
359
+ }
360
+ return e[Symbol.replace].call(this, t, p);
361
+ }, _wrapRegExp.apply(this, arguments);
362
+ }
363
+
364
+ /* eslint-disable unicorn/no-top-level-assignment-in-function -- Temporary */
365
+ // We want it to work in the browser, so commenting out
366
+ // import jsonExtra from 'json5';
367
+ // import jsonExtra from 'json-6';
368
+
369
+ /* eslint-disable jsdoc/reject-any-type -- Ok */
370
+ /**
371
+ * @typedef {any} JSON6
372
+ */
373
+ /**
374
+ * @typedef {any} AnyValue
375
+ */
376
+ /* eslint-enable jsdoc/reject-any-type -- Ok */
377
+
378
+ // Don't use ts-expect-error here, as result differs by tsconfig
379
+ // @ts-ignore Need typing for JSON6
380
+ var _jsonExtra = globalThis.jsonExtra;
381
+
382
+ /**
383
+ * @param {JSON6} __jsonExtra
384
+ */
385
+ var setJSONExtra = function setJSONExtra(__jsonExtra) {
386
+ _jsonExtra = __jsonExtra;
387
+ };
388
+
389
+ /**
390
+ * @param {string} str
391
+ * @returns {string}
392
+ */
393
+ var unescapeBackslashes = function unescapeBackslashes(str) {
394
+ return str.replaceAll(/\\+/g, function (esc) {
395
+ return esc.slice(0, esc.length / 2);
396
+ });
397
+ };
398
+
399
+ /**
400
+ * @param {string} args
401
+ * @returns {AnyValue}
402
+ */
403
+ var parseJSONExtra = function parseJSONExtra(args) {
404
+ return _jsonExtra.parse(
405
+ // Doesn't actually currently allow explicit brackets,
406
+ // but in case we change our regex to allow inner brackets
407
+ '{' + (args || '').replace(/^\{/, '').replace(/\}$/, '') + '}');
408
+ };
409
+
410
+ // Todo: Extract to own library (RegExtras?)
411
+
412
+ /**
413
+ * @callback BetweenMatches
414
+ * @param {string} str
415
+ * @returns {void}
416
+ */
417
+
418
+ /**
419
+ * @callback AfterMatch
420
+ * @param {string} str
421
+ * @returns {void}
422
+ */
423
+
424
+ /**
425
+ * @callback EscapeAtOne
426
+ * @param {string} str
427
+ * @returns {void}
428
+ */
429
+
430
+ /**
431
+ * @param {RegExp} regex
432
+ * @param {string} str
433
+ * @param {{
434
+ * onMatch: (...arg0: string[]) => void,
435
+ * extra?: BetweenMatches|AfterMatch|EscapeAtOne
436
+ * betweenMatches?: BetweenMatches,
437
+ * afterMatch?: AfterMatch,
438
+ * escapeAtOne?: EscapeAtOne
439
+ * }} cfg
440
+ */
441
+ var processRegex = function processRegex(regex, str, _ref) {
442
+ var onMatch = _ref.onMatch,
443
+ extra = _ref.extra,
444
+ betweenMatches = _ref.betweenMatches,
445
+ afterMatch = _ref.afterMatch,
446
+ escapeAtOne = _ref.escapeAtOne;
447
+ if (extra) {
448
+ betweenMatches = extra;
449
+ afterMatch = extra;
450
+ escapeAtOne = extra;
451
+ }
452
+ if (!betweenMatches || !afterMatch) {
453
+ throw new Error('You must have `extra` or `betweenMatches` and `afterMatch` arguments.');
454
+ }
455
+ var match;
456
+ var previousIndex = 0;
457
+ while ((match = regex.exec(str)) !== null) {
458
+ var _match = match,
459
+ _match2 = _slicedToArray(_match, 2),
460
+ _ = _match2[0],
461
+ esc = _match2[1];
462
+ var lastIndex = regex.lastIndex;
463
+ var startMatchPos = lastIndex - _.length;
464
+ if (startMatchPos > previousIndex) {
465
+ betweenMatches(str.slice(previousIndex, startMatchPos));
466
+ }
467
+ if (escapeAtOne && esc.length % 2) {
468
+ previousIndex = lastIndex;
469
+ escapeAtOne(_);
470
+ continue;
471
+ }
472
+ onMatch.apply(void 0, _toConsumableArray(match));
473
+ previousIndex = lastIndex;
474
+ }
475
+ if (previousIndex !== str.length) {
476
+ // Get text at end
477
+ afterMatch(str.slice(previousIndex));
478
+ }
479
+ };
480
+
481
+ /* globals document -- Polyglot variable */
482
+ /* eslint-disable unicorn/no-top-level-assignment-in-function -- Necessary */
483
+ /**
484
+ * @typedef {(
485
+ * input: RequestInfo|URL, init?: RequestInit
486
+ * ) => Promise<Response>} Fetch
487
+ */
488
+ /**
489
+ * @type {null|Fetch}
490
+ */
491
+ var _fetch = typeof fetch !== 'undefined' ? fetch
492
+ /* c8 ignore next -- Available in Node now too */ : null;
493
+
494
+ /**
495
+ * @param {Fetch} f
496
+ * @returns {void}
497
+ */
498
+ var setFetch = function setFetch(f) {
499
+ _fetch = f;
500
+ };
501
+
502
+ /**
503
+ * @returns {Fetch|null}
504
+ */
505
+ var getFetch = function getFetch() {
506
+ return _fetch;
507
+ };
508
+
509
+ /** @type {Document|null} */
510
+ var _doc = typeof document !== 'undefined'
511
+ /* c8 ignore next -- Not available by default in Node */ ? document : null;
512
+
513
+ /**
514
+ * @param {Document} doc
515
+ * @returns {void}
516
+ */
517
+ var setDocument = function setDocument(doc) {
518
+ _doc = doc;
519
+ };
520
+
521
+ /**
522
+ * @returns {Document|null}
523
+ */
524
+ var getDocument = function getDocument() {
525
+ return _doc;
526
+ };
527
+
528
+ var _templateObject$2;
529
+
530
+ /**
531
+ *
532
+ * @returns {string}
533
+ */
534
+ function generateUUID() {
535
+ // Adapted from original: public domain/MIT: https://stackoverflow.com/a/8809472/271577
536
+ var d = Date.now();
537
+ /* c8 ignore next 5 -- Available in Node */
538
+ if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
539
+ d += performance.now(); // use high-precision timer if available
540
+ }
541
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replaceAll(/[xy]/g, function (c) {
542
+ /* eslint-disable no-bitwise, sonarjs/pseudo-random -- Convenient */
543
+ var r = Math.trunc((d + Math.random() * 16) % 16);
544
+ d = Math.floor(d / 16);
545
+ return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
546
+ /* eslint-enable no-bitwise, sonarjs/pseudo-random -- Convenient */
547
+ });
548
+ }
549
+
550
+ /**
551
+ *
552
+ * @param {string} locale
553
+ * @param {string[]} arrayOfItems
554
+ * @param {Intl.CollatorOptions|undefined} options
555
+ * @returns {string[]}
556
+ */
557
+ var sort = function sort(locale, arrayOfItems, options) {
558
+ // eslint-disable-next-line unicorn/no-array-sort -- Modifies
559
+ return arrayOfItems.sort(new Intl.Collator(locale, options).compare);
560
+ };
561
+
562
+ /**
563
+ *
564
+ * @param {string} locale
565
+ * @param {string[]} arrayOfItems
566
+ * @param {Intl.ListFormatOptions|undefined} [options]
567
+ * @returns {string}
568
+ */
569
+ var list = function list(locale, arrayOfItems, options) {
570
+ return new Intl.ListFormat(locale, options).format(arrayOfItems);
571
+ };
572
+
573
+ /**
574
+ *
575
+ * @param {string} locale
576
+ * @param {string[]} arrayOfItems
577
+ * @param {Intl.ListFormatOptions|undefined} [listOptions]
578
+ * @param {Intl.CollatorOptions|undefined} [collationOptions]
579
+ * @returns {string}
580
+ */
581
+ var sortListSimple = function sortListSimple(locale, arrayOfItems, listOptions, collationOptions) {
582
+ sort(locale, arrayOfItems, collationOptions);
583
+ return list(locale, arrayOfItems, listOptions);
584
+ };
585
+
586
+ /**
587
+ * @typedef {number} Integer
588
+ */
589
+
590
+ /**
591
+ *
592
+ * @param {string} locale
593
+ * @param {string[]} arrayOfItems
594
+ * @param {import('./index.js').SortListMapper|
595
+ * Intl.ListFormatOptions|undefined} map
596
+ * @param {Intl.ListFormatOptions|undefined} [listOptions]
597
+ * @param {Intl.CollatorOptions|undefined} [collationOptions]
598
+ * @returns {DocumentFragment|string}
599
+ */
600
+ var sortList = function sortList(locale, arrayOfItems, map, listOptions, collationOptions) {
601
+ if (typeof map !== 'function') {
602
+ return sortListSimple(locale, /** @type {string[]} */arrayOfItems, map, listOptions);
603
+ }
604
+ sort(locale, arrayOfItems, collationOptions);
605
+ var randomId = generateUUID();
606
+ var placeholderArray = _toConsumableArray(arrayOfItems).map(function (_, i) {
607
+ return "<<".concat(randomId).concat(i, ">>");
608
+ });
609
+
610
+ /** @type {(string|Node)[]} */
611
+ var nodes = [];
612
+
613
+ /**
614
+ * @param {string} arg
615
+ * @returns {void}
616
+ */
617
+ var push = function push(arg) {
618
+ nodes.push(arg);
619
+ };
620
+ processRegex(
621
+ // // eslint-disable-next-line prefer-named-capture-group
622
+ new RegExp(String.raw(_templateObject$2 || (_templateObject$2 = _taggedTemplateLiteral(["<<", "(d)>>"], ["<<", "(\\d)>>"])), randomId), 'gv'), list(locale, placeholderArray, listOptions), {
623
+ betweenMatches: push,
624
+ afterMatch: push,
625
+ onMatch: function onMatch(_, idx) {
626
+ push(map(arrayOfItems[Number(idx)], Number(idx)));
627
+ }
628
+ });
629
+ var _doc = /** @type {Document} */getDocument();
630
+ var container = _doc.createDocumentFragment();
631
+ container.append.apply(container, nodes);
632
+ return container;
633
+ };
634
+
635
+ /**
636
+ * @typedef {number} Integer
637
+ */
638
+
639
+ /**
640
+ * @param {{
641
+ * object: import('./defaultLocaleResolver.js').DateRangeValueArray|
642
+ * import('./defaultLocaleResolver.js').ListValueArray|
643
+ * import('./defaultLocaleResolver.js').RelativeValueArray|
644
+ * import('./defaultLocaleResolver.js').ValueArray
645
+ * }} cfg
646
+ * @returns {{
647
+ * value: number|string|string[]|Date,
648
+ * options?: Intl.NumberFormatOptions|Intl.PluralRulesOptions|
649
+ * string|Date|number,
650
+ * extraOpts?: object,
651
+ * callback?: (item: string, i: Integer) => Element
652
+ * }}
653
+ */
654
+ var getFormatterInfo = function getFormatterInfo(_ref) {
655
+ var object = _ref.object;
656
+ if (Array.isArray(object)) {
657
+ if (typeof object[1] === 'function') {
658
+ var _object = _slicedToArray(
659
+ /**
660
+ * @type {[
661
+ * string[], (item: string, i: Integer) => Element, object, object
662
+ * ]}
663
+ */
664
+ object, 4),
665
+ _value = _object[0],
666
+ callback = _object[1],
667
+ _options = _object[2],
668
+ _extraOpts = _object[3];
669
+ return {
670
+ value: _value,
671
+ callback: callback,
672
+ options: _options,
673
+ extraOpts: _extraOpts
674
+ };
675
+ }
676
+ var _object2 = _slicedToArray(object, 3),
677
+ value = _object2[0],
678
+ options = _object2[1],
679
+ extraOpts = _object2[2];
680
+ return {
681
+ value: value,
682
+ options: options,
683
+ extraOpts: extraOpts
684
+ };
685
+ }
686
+ return {
687
+ value: object
688
+ };
689
+ };
690
+
691
+ /**
692
+ * Callback to give replacement text based on a substitution value.
693
+ *
694
+ * `value` - contains the value returned by the individual substitution.
695
+ * `arg` - See `cfg.arg` of {@link SubstitutionCallback}.
696
+ * `key` - The substitution key Not currently in use
697
+ * `locale` - The locale.
698
+ * @typedef {(info: {
699
+ * value: import('./defaultLocaleResolver.js').SubstitutionObjectValue
700
+ * arg?: string,
701
+ * key?: string,
702
+ * locale?: string
703
+ * }) => string|Node} AllSubstitutionCallback
704
+ */
705
+
706
+ /**
707
+ * @type {AllSubstitutionCallback}
708
+ */
709
+ var defaultAllSubstitutions = function defaultAllSubstitutions(_ref2) {
710
+ var value = _ref2.value,
711
+ arg = _ref2.arg,
712
+ locale = _ref2.locale;
713
+ // Strings or DOM Nodes
714
+ if (typeof value === 'string' || value && _typeof(value) === 'object' && 'nodeType' in value) {
715
+ return value;
716
+ }
717
+
718
+ /** @type {object|string|Date|number|undefined} */
719
+ var opts;
720
+
721
+ /**
722
+ * @param {{
723
+ * type: string,
724
+ * options?: object,
725
+ * checkArgOptions?: boolean;
726
+ * }} cfg
727
+ * @returns {object|undefined}
728
+ */
729
+ var applyArgs = function applyArgs(_ref3) {
730
+ var type = _ref3.type,
731
+ _ref3$options = _ref3.options,
732
+ options = _ref3$options === void 0 ? (/** @type {object|undefined} */
733
+ opts) : _ref3$options,
734
+ _ref3$checkArgOptions = _ref3.checkArgOptions,
735
+ checkArgOptions = _ref3$checkArgOptions === void 0 ? false : _ref3$checkArgOptions;
736
+ if (typeof arg === 'string') {
737
+ // eslint-disable-next-line prefer-const -- Convenient
738
+ var _arg$split = arg.split('|', 3),
739
+ _arg$split2 = _slicedToArray(_arg$split, 3),
740
+ userType = _arg$split2[0],
741
+ extraArgs = _arg$split2[1],
742
+ argOptions = _arg$split2[2];
743
+ // Alias
744
+ if (userType === 'DATE') {
745
+ userType = 'DATETIME';
746
+ }
747
+ if (userType === type) {
748
+ if (!extraArgs) {
749
+ options = {};
750
+ } else if (!checkArgOptions || argOptions) {
751
+ // Todo: Allow escaping and restoring of pipe symbol
752
+ options = _objectSpread2(_objectSpread2({}, options), parseJSONExtra(checkArgOptions && argOptions ? argOptions : extraArgs));
753
+ }
754
+ }
755
+ }
756
+ return options;
757
+ };
758
+ var expectsDatetime = false;
759
+ if (value && _typeof(value) === 'object' && !Array.isArray(value)) {
760
+ var singleKey = Object.keys(value)[0];
761
+ /**
762
+ * @typedef {"number"|"date"|"datetime"|"dateRange"|
763
+ * "datetimeRange"|"relative"|"region"|"language"|
764
+ * "script"|"currency"|"list"|"plural"} SpecialFormat
765
+ */
766
+ if (['number', 'date', 'datetime', 'dateRange', 'datetimeRange', 'relative', 'region', 'language', 'script', 'currency', 'list', 'plural'].includes(singleKey)) {
767
+ var extraOpts, callback;
768
+ var obj = /** @type {unknown} */
769
+ /** @type {Record<string, keyof SpecialFormat>} */
770
+ value[(
771
+ /**
772
+ * @type {SpecialFormat}
773
+ */
774
+ singleKey)];
775
+ var _getFormatterInfo = getFormatterInfo({
776
+ object: (
777
+ /**
778
+ * @type {import('./defaultLocaleResolver.js').DateRangeValueArray|
779
+ * import('./defaultLocaleResolver.js').ListValueArray|
780
+ * import('./defaultLocaleResolver.js').RelativeValueArray|
781
+ * import('./defaultLocaleResolver.js').ValueArray
782
+ * }
783
+ */
784
+ obj)
785
+ });
786
+ value = _getFormatterInfo.value;
787
+ opts = _getFormatterInfo.options;
788
+ extraOpts = _getFormatterInfo.extraOpts;
789
+ callback = _getFormatterInfo.callback;
790
+ switch (singleKey) {
791
+ case 'date':
792
+ case 'datetime':
793
+ expectsDatetime = true;
794
+ break;
795
+ case 'dateRange':
796
+ case 'datetimeRange':
797
+ {
798
+ var dtf = new Intl.DateTimeFormat(locale, applyArgs({
799
+ type: 'DATERANGE',
800
+ options: extraOpts
801
+ }));
802
+ return dtf.formatRange.apply(dtf, _toConsumableArray(/** @type {[Date, Date]} */
803
+ [(/** @type {number|Date} */
804
+ value), (/** @type {Date} */
805
+ opts)].map(function (val) {
806
+ return typeof val === 'number' ? new Date(val) : val;
807
+ })));
808
+ }
809
+ case 'region':
810
+ case 'language':
811
+ case 'script':
812
+ case 'currency':
813
+ return /** @type {string} */new Intl.DisplayNames(locale, _objectSpread2(_objectSpread2({}, applyArgs({
814
+ type: singleKey.toUpperCase()
815
+ })), {}, {
816
+ type: singleKey
817
+ })).of(/** @type {string} */value);
818
+ case 'relative':
819
+ // The second argument actually contains the primary options, so swap
820
+ // eslint-disable-next-line @stylistic/max-len -- Long
821
+ var _ref4 = /** @type {[Intl.RelativeTimeFormatUnit, object?]} */
822
+ [opts, extraOpts];
823
+ extraOpts = _ref4[0];
824
+ opts = _ref4[1];
825
+ return new Intl.RelativeTimeFormat(locale, applyArgs({
826
+ type: 'RELATIVE'
827
+ })).format(/** @type {number} */value, extraOpts);
828
+
829
+ // ListFormat (with Collator)
830
+ case 'list':
831
+ if (callback) {
832
+ return sortList(/** @type {string} */locale, /** @type {string[]} */
833
+ value, callback, applyArgs({
834
+ type: 'LIST'
835
+ }), applyArgs({
836
+ type: 'LIST',
837
+ options: extraOpts,
838
+ checkArgOptions: true
839
+ }));
840
+ }
841
+ return sortList(/** @type {string} */locale, /** @type {string[]} */
842
+ value, applyArgs({
843
+ type: 'LIST'
844
+ }), applyArgs({
845
+ type: 'LIST',
846
+ options: extraOpts,
847
+ checkArgOptions: true
848
+ }));
849
+ }
850
+ }
851
+ }
852
+
853
+ // Dates
854
+ if (value) {
855
+ if (typeof value === 'number' && (expectsDatetime || /^DATE(?:TIME)(?:\||$)/.test(/** @type {string} */arg))) {
856
+ value = new Date(value);
857
+ }
858
+ if (_typeof(value) === 'object' && 'getTime' in value && typeof value.getTime === 'function') {
859
+ return new Intl.DateTimeFormat(locale, applyArgs({
860
+ type: 'DATETIME'
861
+ })).format(value);
862
+ }
863
+ }
864
+
865
+ // Date range
866
+ if (Array.isArray(value)) {
867
+ var _Intl$DateTimeFormat;
868
+ var _extraOpts2 = /** @type {Intl.DateTimeFormatOptions|undefined} */
869
+ value[2];
870
+ return (_Intl$DateTimeFormat = new Intl.DateTimeFormat(locale, applyArgs({
871
+ type: 'DATERANGE',
872
+ options: _extraOpts2
873
+ }))).formatRange.apply(_Intl$DateTimeFormat, _toConsumableArray(/** @type {[Date, Date]} */
874
+ value.slice(0, 2).map(function (val) {
875
+ return typeof val === 'number' ? new Date(val) : val;
876
+ })));
877
+ }
878
+
879
+ // Numbers
880
+ if (typeof value === 'number') {
881
+ return new Intl.NumberFormat(locale, applyArgs({
882
+ type: 'NUMBER'
883
+ })).format(value);
884
+ }
885
+
886
+ // console.log('value', value);
887
+ throw new TypeError('Unknown formatter');
888
+ };
889
+
890
+ var _templateObject$1, _templateObject2$1;
891
+
892
+ /**
893
+ * Base class for formatting.
894
+ */
895
+ var Formatter = /*#__PURE__*/_createClass(function Formatter() {
896
+ _classCallCheck(this, Formatter);
897
+ });
898
+
899
+ /**
900
+ * @param {object} cfg
901
+ * @param {string} cfg.key
902
+ * @param {import('./getMessageForKeyByStyle.js').LocaleBody} cfg.body
903
+ * @param {string} cfg.type
904
+ * @param {"richNested"|"rich"|"plain"|
905
+ * "plainNested"|import('./getMessageForKeyByStyle.js').
906
+ * MessageStyleCallback} [cfg.messageStyle]
907
+ * @returns {string}
908
+ */
909
+ var _getSubstitution = function getSubstitution(_ref) {
910
+ var key = _ref.key,
911
+ body = _ref.body,
912
+ type = _ref.type,
913
+ _ref$messageStyle = _ref.messageStyle,
914
+ messageStyle = _ref$messageStyle === void 0 ? 'richNested' : _ref$messageStyle;
915
+ var messageForKey = getMessageForKeyByStyle({
916
+ messageStyle: messageStyle
917
+ });
918
+ var substitution = messageForKey({
919
+ body: body
920
+ }, key);
921
+ if (!substitution) {
922
+ throw new Error("Key value not found for ".concat(type, " key: (").concat(key, ")"));
923
+ }
924
+ // We don't allow a substitution function here or below as comes
925
+ // from locale and locale content should not pose security concerns
926
+ return substitution.value;
927
+ };
928
+
929
+ /**
930
+ * Formatter for local variables.
931
+ */
932
+ var LocalFormatter = /*#__PURE__*/function (_Formatter) {
933
+ /**
934
+ * @param {import('./getMessageForKeyByStyle.js').LocalObject} locals
935
+ */
936
+ function LocalFormatter(locals) {
937
+ var _this;
938
+ _classCallCheck(this, LocalFormatter);
939
+ _this = _callSuper(this, LocalFormatter);
940
+ _this.locals = locals;
941
+ return _this;
942
+ }
943
+ /**
944
+ * @param {string} key
945
+ * @returns {string|Element}
946
+ */
947
+ _inherits(LocalFormatter, _Formatter);
948
+ return _createClass(LocalFormatter, [{
949
+ key: "getSubstitution",
950
+ value: function getSubstitution(key) {
951
+ return _getSubstitution({
952
+ key: key.slice(1),
953
+ body: this.locals,
954
+ type: 'local'
955
+ });
956
+ }
957
+ /**
958
+ * @param {string} key
959
+ * @returns {boolean}
960
+ */
961
+ }, {
962
+ key: "isMatch",
963
+ value: function isMatch(key) {
964
+ var components = key.slice(1).split('.');
965
+ /** @type {import('./getMessageForKeyByStyle.js').LocaleBody} */
966
+ var parent = this.locals;
967
+ return /** @type {typeof LocalFormatter} */this.constructor.isMatchingKey(key) && components.every(function (cmpt) {
968
+ var result = Object.hasOwn(parent, cmpt);
969
+ parent =
970
+ /**
971
+ * @type {import('./defaultLocaleResolver.js').
972
+ * RichNestedLocaleStringBodyObject|
973
+ * import('./defaultLocaleResolver.js').
974
+ * PlainNestedLocaleStringBodyObject|
975
+ * import('./defaultLocaleResolver.js').RichLocaleStringSubObject
976
+ * }
977
+ */
978
+ /**
979
+ * @type {import('./defaultLocaleResolver.js').
980
+ * RichNestedLocaleStringBodyObject|
981
+ * import('./defaultLocaleResolver.js').
982
+ * PlainNestedLocaleStringBodyObject
983
+ * }
984
+ */
985
+ parent[cmpt];
986
+ return result;
987
+ });
988
+ }
989
+ }], [{
990
+ key: "isMatchingKey",
991
+ value:
992
+ /**
993
+ * @param {string} key
994
+ * @returns {boolean}
995
+ */
996
+ function isMatchingKey(key) {
997
+ return key.startsWith('-');
998
+ }
999
+ }]);
1000
+ }(Formatter);
1001
+
1002
+ /**
1003
+ * Formatter for regular variables.
1004
+ */
1005
+ var RegularFormatter = /*#__PURE__*/function (_Formatter2) {
1006
+ /**
1007
+ * @param {import('./defaultLocaleResolver.js').SubstitutionObject
1008
+ * } substitutions
1009
+ */
1010
+ function RegularFormatter(substitutions) {
1011
+ var _this2;
1012
+ _classCallCheck(this, RegularFormatter);
1013
+ _this2 = _callSuper(this, RegularFormatter);
1014
+ _this2.substitutions = substitutions;
1015
+ return _this2;
1016
+ }
1017
+ /**
1018
+ * @param {string} key
1019
+ * @returns {boolean}
1020
+ */
1021
+ _inherits(RegularFormatter, _Formatter2);
1022
+ return _createClass(RegularFormatter, [{
1023
+ key: "isMatch",
1024
+ value: function isMatch(key) {
1025
+ return /** @type {typeof RegularFormatter} */this.constructor.isMatchingKey(key) && Object.hasOwn(this.substitutions, key);
1026
+ }
1027
+ }], [{
1028
+ key: "isMatchingKey",
1029
+ value:
1030
+ /**
1031
+ * @param {string} key
1032
+ * @returns {boolean}
1033
+ */
1034
+ function isMatchingKey(key) {
1035
+ return /^[0-9A-Z_a-z]/.test(key);
1036
+ }
1037
+ }]);
1038
+ }(Formatter);
1039
+
1040
+ /**
1041
+ * Formatter for switch variables.
1042
+ */
1043
+ var SwitchFormatter = /*#__PURE__*/function (_Formatter3) {
1044
+ /**
1045
+ * @param {import('./defaultLocaleResolver.js').Switches} switches
1046
+ * @param {object} cfg
1047
+ * @param {import('./defaultLocaleResolver.js').
1048
+ * SubstitutionObject} cfg.substitutions
1049
+ */
1050
+ function SwitchFormatter(switches, _ref2) {
1051
+ var _this3;
1052
+ var substitutions = _ref2.substitutions;
1053
+ _classCallCheck(this, SwitchFormatter);
1054
+ _this3 = _callSuper(this, SwitchFormatter);
1055
+ _this3.switches = switches;
1056
+ _this3.substitutions = substitutions;
1057
+ return _this3;
1058
+ }
1059
+
1060
+ /**
1061
+ * @param {string} key
1062
+ * @param {object} cfg
1063
+ * @param {string} cfg.locale
1064
+ * @param {(string|undefined)[]} cfg.usedKeys
1065
+ * @param {string} cfg.arg
1066
+ * @param {import('./getDOMForLocaleString.js').
1067
+ * MissingSuppliedFormattersCallback} cfg.missingSuppliedFormatters
1068
+ * @returns {string}
1069
+ */
1070
+ _inherits(SwitchFormatter, _Formatter3);
1071
+ return _createClass(SwitchFormatter, [{
1072
+ key: "getSubstitution",
1073
+ value: function getSubstitution(key, _ref3) {
1074
+ var locale = _ref3.locale,
1075
+ usedKeys = _ref3.usedKeys,
1076
+ arg = _ref3.arg,
1077
+ missingSuppliedFormatters = _ref3.missingSuppliedFormatters;
1078
+ var ky = /** @type {typeof SwitchFormatter} */this.constructor.getKey(key).slice(1);
1079
+ // Expression might not actually use formatter, e.g., for singular,
1080
+ // the conditional might just write out "one"
1081
+
1082
+ var _this$getMatch = this.getMatch(ky),
1083
+ _this$getMatch2 = _slicedToArray(_this$getMatch, 3),
1084
+ objKey = _this$getMatch2[0],
1085
+ body = _this$getMatch2[1],
1086
+ keySegment = _this$getMatch2[2];
1087
+ usedKeys.push(keySegment);
1088
+ var type;
1089
+ /** @type {string} */
1090
+ var opts;
1091
+ if (objKey && objKey.includes('|')) {
1092
+ var _objKey$split = objKey.split('|', 3);
1093
+ var _objKey$split2 = _slicedToArray(_objKey$split, 3);
1094
+ type = _objKey$split2[1];
1095
+ opts = _objKey$split2[2];
1096
+ }
1097
+ if (!body) {
1098
+ missingSuppliedFormatters({
1099
+ key: key,
1100
+ formatter: this
1101
+ });
1102
+ return String.raw(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral(["{"], ["\\{"]))) + key + '}';
1103
+ }
1104
+
1105
+ /*
1106
+ if (!(ky in this.substitutions)) {
1107
+ throw new Error(`Switch expecting formatter: ${ky}`);
1108
+ }
1109
+ */
1110
+
1111
+ /**
1112
+ * @param {number} value
1113
+ * @param {Intl.NumberFormatOptions|undefined} [defaultOptions]
1114
+ * @returns {string}
1115
+ */
1116
+ var getNumberFormat = function getNumberFormat(value, defaultOptions) {
1117
+ var numberOpts = parseJSONExtra(opts);
1118
+ return new Intl.NumberFormat(locale, _objectSpread2(_objectSpread2({}, defaultOptions), numberOpts)).format(value);
1119
+ };
1120
+
1121
+ /**
1122
+ * @param {number} value
1123
+ * @param {Intl.PluralRulesOptions|undefined} [defaultOptions]
1124
+ * @returns {Intl.LDMLPluralRule}
1125
+ */
1126
+ var getPluralFormat = function getPluralFormat(value, defaultOptions) {
1127
+ var pluralOpts = parseJSONExtra(opts);
1128
+ return new Intl.PluralRules(locale, _objectSpread2(_objectSpread2({}, defaultOptions), pluralOpts)).select(value);
1129
+ };
1130
+ var formatterValue = this.substitutions[(/** @type {string} */keySegment)];
1131
+ var match = formatterValue;
1132
+ if (typeof formatterValue === 'number') {
1133
+ switch (type) {
1134
+ case 'NUMBER':
1135
+ match = getNumberFormat(formatterValue);
1136
+ break;
1137
+ case 'PLURAL':
1138
+ match = getPluralFormat(formatterValue);
1139
+ break;
1140
+ default:
1141
+ match = new Intl.PluralRules(locale).select(formatterValue);
1142
+ break;
1143
+ }
1144
+ } else if (formatterValue && _typeof(formatterValue) === 'object') {
1145
+ var singleKey = Object.keys(formatterValue)[0];
1146
+ if (['number', 'plural'].includes(singleKey)) {
1147
+ var _getFormatterInfo = getFormatterInfo({
1148
+ object:
1149
+ /**
1150
+ * @type {import('./defaultLocaleResolver.js').NumberInfo|
1151
+ * import('./defaultLocaleResolver.js').PluralInfo}
1152
+ */
1153
+ // @ts-expect-error Ok
1154
+ formatterValue[(/** @type {"number"|"plural"} */singleKey)]
1155
+ }),
1156
+ value = _getFormatterInfo.value,
1157
+ options = _getFormatterInfo.options;
1158
+ if (!type) {
1159
+ type = singleKey.toUpperCase();
1160
+ }
1161
+ var typeMatches = singleKey.toUpperCase() === type;
1162
+ if (!typeMatches) {
1163
+ throw new TypeError("Expecting type \"".concat(type.toLowerCase(), "\"; instead found \"").concat(singleKey, "\"."));
1164
+ }
1165
+ // eslint-disable-next-line default-case -- Just two cases
1166
+ switch (type) {
1167
+ case 'NUMBER':
1168
+ match = getNumberFormat(/** @type {number} */value, /** @type {Intl.NumberFormatOptions} */
1169
+ options);
1170
+ break;
1171
+ case 'PLURAL':
1172
+ match = getPluralFormat(/** @type {number} */value, /** @type {Intl.PluralRulesOptions} */
1173
+ options);
1174
+ break;
1175
+ }
1176
+ }
1177
+ }
1178
+
1179
+ // We do not want the default `richNested` here as that will split
1180
+ // up the likes of `0.0`
1181
+ var messageStyle = 'richNested';
1182
+
1183
+ /**
1184
+ * @param {string} s
1185
+ * @returns {string}
1186
+ */
1187
+ var preventNesting = function preventNesting(s) {
1188
+ return s.replaceAll('\\', '\\\\').replaceAll('.', String.raw(_templateObject2$1 || (_templateObject2$1 = _taggedTemplateLiteral(["."], ["\\."]))));
1189
+ };
1190
+ try {
1191
+ return _getSubstitution({
1192
+ messageStyle: messageStyle,
1193
+ key: match ? preventNesting(/** @type {string} */match) : arg,
1194
+ body: body,
1195
+ type: 'switch'
1196
+ });
1197
+ } catch (err) {
1198
+ try {
1199
+ return _getSubstitution({
1200
+ messageStyle: messageStyle,
1201
+ key: '*' + preventNesting(/** @type {string} */match),
1202
+ body: body,
1203
+ type: 'switch'
1204
+ });
1205
+ } catch (error) {
1206
+ var k = Object.keys(body).find(function (switchKey) {
1207
+ return switchKey.startsWith('*');
1208
+ });
1209
+ if (!k) {
1210
+ throw new Error("No defaults found for switch ".concat(ky), {
1211
+ cause: error
1212
+ });
1213
+ }
1214
+ return _getSubstitution({
1215
+ messageStyle: messageStyle,
1216
+ key: preventNesting(k),
1217
+ body: body,
1218
+ type: 'switch'
1219
+ });
1220
+ }
1221
+ }
1222
+ }
1223
+
1224
+ /**
1225
+ * @param {string} key
1226
+ * @returns {boolean}
1227
+ */
1228
+ }, {
1229
+ key: "isMatch",
1230
+ value: function isMatch(key) {
1231
+ return Boolean(key && /** @type {typeof SwitchFormatter} */this.constructor.isMatchingKey(key) && this.getMatch(key.slice(1)).length);
1232
+ }
1233
+
1234
+ /**
1235
+ * @typedef {[
1236
+ * objKey?: string,
1237
+ * body?: import('./getMessageForKeyByStyle.js').LocaleBody,
1238
+ * keySegment?: string
1239
+ * ]} SwitchMatch
1240
+ */
1241
+
1242
+ /**
1243
+ * @typedef {number} Integer
1244
+ */
1245
+
1246
+ /**
1247
+ * @param {string} ky
1248
+ * @returns {SwitchMatch}
1249
+ */
1250
+ }, {
1251
+ key: "getMatch",
1252
+ value: function getMatch(ky) {
1253
+ var _this4 = this;
1254
+ var ks = ky.split('.');
1255
+ var returnValue = /** @type {unknown} */ks.reduce(
1256
+ /**
1257
+ * @param {import('./defaultLocaleResolver.js').SwitchArrays|
1258
+ * import('./defaultLocaleResolver.js').SwitchArray|
1259
+ * import('./defaultLocaleResolver.js').SwitchCaseArray|SwitchMatch} obj
1260
+ * @param {string} k
1261
+ * @param {Integer} i
1262
+ * @throws {Error}
1263
+ * @returns {import('./defaultLocaleResolver.js').SwitchArrays|
1264
+ * import('./defaultLocaleResolver.js').SwitchArray|
1265
+ * import('./defaultLocaleResolver.js').SwitchCaseArray|
1266
+ * SwitchMatch}
1267
+ */
1268
+ function (obj, k, i) {
1269
+ if (Array.isArray(obj)) {
1270
+ return obj;
1271
+ }
1272
+ if (i < ks.length - 1) {
1273
+ if (!Object.hasOwn(obj, k)) {
1274
+ throw new Error("Switch key \"".concat(k, "\" not found (from \"~").concat(ky, "\")"));
1275
+ }
1276
+ return obj[k];
1277
+ }
1278
+ // Todo: Should throw on encountering duplicate fundamental keys (even
1279
+ // if there are different arguments, that should not be allowed)
1280
+ var ret = Object.entries(obj).find(function (_ref4) {
1281
+ var _ref5 = _slicedToArray(_ref4, 1),
1282
+ switchKey = _ref5[0];
1283
+ return k === /** @type {typeof SwitchFormatter} */_this4.constructor.getKey(switchKey);
1284
+ });
1285
+ return ret ? [].concat(_toConsumableArray(ret), [k]) : [];
1286
+ },
1287
+ /**
1288
+ * @type {import('./defaultLocaleResolver.js').SwitchArrays|
1289
+ * import('./defaultLocaleResolver.js').SwitchArray|
1290
+ * import('./defaultLocaleResolver.js').SwitchCaseArray|SwitchMatch}
1291
+ */ /** @type {unknown} */
1292
+ this.switches);
1293
+ return /** @type {SwitchMatch} */returnValue;
1294
+ }
1295
+ }], [{
1296
+ key: "isMatchingKey",
1297
+ value:
1298
+ /**
1299
+ * @param {string} key
1300
+ * @returns {boolean}
1301
+ */
1302
+ function isMatchingKey(key) {
1303
+ return key.startsWith('~');
1304
+ }
1305
+ /**
1306
+ * @param {string} key
1307
+ * @returns {string}
1308
+ */
1309
+ }, {
1310
+ key: "getKey",
1311
+ value: function getKey(key) {
1312
+ var match = key.match(/^(?:[\0-\{\}-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*/);
1313
+ return /** @type {string} */match && match[0];
1314
+ }
1315
+ }]);
1316
+ }(Formatter);
1317
+
1318
+ /* eslint-disable jsdoc/reject-any-type -- Generic API */
1319
+ /**
1320
+ * @typedef {(value: any) => Promise<any>|any} PromiseChainErrback
1321
+ */
1322
+
1323
+ /**
1324
+ * The given array will have its items processed in series; if the supplied
1325
+ * `errBack` (which is guaranteed to run at least once), when passed the
1326
+ * current item, returns a `Promise` or value that resolves, that value will
1327
+ * be used for the return result of this function and no other items in
1328
+ * the array will continue to be processed; if it rejects, however, the
1329
+ * next item will be processed with `errBack`.
1330
+ * Accept an array of values to pass to an errback which should return
1331
+ * a promise (or final result value) which resolves to a result or which
1332
+ * rejects so that the next item in the array can be checked in series.
1333
+ * @param {Array<any>} values Array of values
1334
+ * @param {PromiseChainErrback} errBack Accepts an item of the array as its
1335
+ * single argument
1336
+ * @param {string} [errorMessage]
1337
+ * @returns {Promise<any>} Either resolves to a value derived from an item in
1338
+ * the array or rejects if all items reject
1339
+ * @example
1340
+ promiseChainForValues(['a', 'b', 'c'], (val) => {
1341
+ return new Promise(function (resolve, reject) {
1342
+ if (val === 'a') {
1343
+ reject(new Error('missing'));
1344
+ }
1345
+ setTimeout(() => {
1346
+ resolve(val);
1347
+ }, 100);
1348
+ });
1349
+ });
1350
+ */
1351
+ var promiseChainForValues = function promiseChainForValues(values, errBack) {
1352
+ var errorMessage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Reached end of values array.';
1353
+ if (!Array.isArray(values)) {
1354
+ throw new TypeError('The `values` argument to `promiseChainForValues` must be an array.');
1355
+ }
1356
+ if (typeof errBack !== 'function') {
1357
+ throw new TypeError('The `errBack` argument to `promiseChainForValues` must be a function.');
1358
+ }
1359
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
1360
+ var ret, p, breaking, value, _t;
1361
+ return _regenerator().w(function (_context) {
1362
+ while (1) switch (_context.p = _context.n) {
1363
+ case 0:
1364
+ p = Promise.reject(new Error('Intentionally reject so as to begin checking chain'));
1365
+ case 1:
1366
+ value = values.shift();
1367
+ _context.p = 2;
1368
+ _context.n = 3;
1369
+ return p;
1370
+ case 3:
1371
+ ret = _context.v;
1372
+ return _context.a(3, 7);
1373
+ case 4:
1374
+ _context.p = 4;
1375
+ _t = _context.v;
1376
+ if (!breaking) {
1377
+ _context.n = 5;
1378
+ break;
1379
+ }
1380
+ throw new Error(errorMessage, {
1381
+ cause: _t
1382
+ });
1383
+ case 5:
1384
+ // We allow one more try
1385
+ if (!values.length) {
1386
+ breaking = true;
1387
+ }
1388
+ // // eslint-disable-next-line no-await-in-loop
1389
+ p = errBack(value);
1390
+ case 6:
1391
+ _context.n = 1;
1392
+ break;
1393
+ case 7:
1394
+ return _context.a(2, ret);
1395
+ }
1396
+ }, _callee, null, [[2, 4]]);
1397
+ }))();
1398
+ };
1399
+
1400
+ /**
1401
+ * `arg` - By default, accepts the third portion of the
1402
+ * `formattingRegex` within `insertNodes`, i.e., to allow the locale to
1403
+ * supply arguments back to the calling script.
1404
+ * `key` - The substitution key.
1405
+ * @callback SubstitutionCallback
1406
+ * @param {{
1407
+ * arg: string,
1408
+ * key: string
1409
+ * }} cfg
1410
+ * @returns {string|Element} The replacement text or element
1411
+ */
1412
+
1413
+ /**
1414
+ * May have additional properties if supplying options to an underlying
1415
+ * formatter.
1416
+ * The first value is the main value.
1417
+ * The second are the options related to the main value.
1418
+ * The third are any additional options.
1419
+ * @typedef {[string|number|Date, object?, object?]} ValueArray
1420
+ */
1421
+
1422
+ /**
1423
+ * @typedef {number} Integer
1424
+ */
1425
+
1426
+ /**
1427
+ * @typedef {[
1428
+ * string[],
1429
+ * (((item: string, i: Integer) => Element)|object)?,
1430
+ * object?,
1431
+ * object?
1432
+ * ]} ListValueArray
1433
+ */
1434
+
1435
+ /**
1436
+ * @typedef {[
1437
+ * Date|number, Date|number, Intl.DateTimeFormatOptions|undefined
1438
+ * ]} DateRangeValueArray
1439
+ */
1440
+
1441
+ /**
1442
+ * @typedef {[number, Intl.RelativeTimeFormatUnit, object?]} RelativeValueArray
1443
+ */
1444
+
1445
+ /**
1446
+ * @typedef {object} RelativeTimeInfo
1447
+ * @property {RelativeValueArray} relative
1448
+ */
1449
+
1450
+ /**
1451
+ * @typedef {object} ListInfo
1452
+ * @property {ListValueArray} list
1453
+ */
1454
+
1455
+ /**
1456
+ * @typedef {object} NumberInfo
1457
+ * @property {ValueArray|number} number
1458
+ */
1459
+
1460
+ /**
1461
+ * @typedef {object} DateInfo
1462
+ * @property {ValueArray} date
1463
+ */
1464
+
1465
+ /**
1466
+ * @typedef {object} DateTimeInfo
1467
+ * @property {ValueArray} datetime
1468
+ */
1469
+
1470
+ /**
1471
+ * @typedef {object} DateRangeInfo
1472
+ * @property {DateRangeValueArray} dateRange
1473
+ */
1474
+
1475
+ /**
1476
+ * @typedef {object} DatetimeRangeInfo
1477
+ * @property {DateRangeValueArray} datetimeRange
1478
+ */
1479
+
1480
+ /**
1481
+ * @typedef {object} RegionInfo
1482
+ * @property {ValueArray} region
1483
+ */
1484
+
1485
+ /**
1486
+ * @typedef {object} LanguageInfo
1487
+ * @property {ValueArray} language
1488
+ */
1489
+
1490
+ /**
1491
+ * @typedef {object} ScriptInfo
1492
+ * @property {ValueArray} script
1493
+ */
1494
+
1495
+ /**
1496
+ * @typedef {object} CurrencyInfo
1497
+ * @property {ValueArray} currency
1498
+ */
1499
+
1500
+ /**
1501
+ * @typedef {object} PluralInfo
1502
+ * @property {ValueArray} plural
1503
+ */
1504
+
1505
+ /**
1506
+ * @typedef {{[key: string]: string}} PlainLocaleStringBodyObject
1507
+ */
1508
+
1509
+ /**
1510
+ * @typedef {{
1511
+ * [key: string]: string|PlainNestedLocaleStringBodyObject
1512
+ * }} PlainNestedLocaleStringBodyObject
1513
+ */
1514
+
1515
+ /**
1516
+ * @typedef {object} SwitchCaseInfo
1517
+ * @property {boolean} [default=false] Whether this conditional is the default
1518
+ */
1519
+
1520
+ /**
1521
+ * Contains the type, the message, and optional info about the switch case.
1522
+ * @typedef {[string, string, SwitchCaseInfo?]} SwitchCaseArray
1523
+ */
1524
+
1525
+ /**
1526
+ * @typedef {Record<string, SwitchCaseArray>} SwitchArray
1527
+ */
1528
+
1529
+ /**
1530
+ * @typedef {Record<string, SwitchArray>} SwitchArrays
1531
+ */
1532
+
1533
+ /**
1534
+ * @typedef {object} SwitchCase
1535
+ * @property {string} message The locale message with any formatting
1536
+ * place-holders; defaults to use of any single conditional
1537
+ * @property {string} [description] A description to add for translators
1538
+ */
1539
+
1540
+ /**
1541
+ * @typedef {Record<string, SwitchCase>} SwitchGroup
1542
+ */
1543
+
1544
+ /**
1545
+ * @typedef {Record<string, SwitchCase|SwitchGroup>} Switch
1546
+ */
1547
+
1548
+ /**
1549
+ * @typedef {Record<string, Switch>} Switches
1550
+ */
1551
+
1552
+ /**
1553
+ * @typedef {object} RichLocaleStringSubObject
1554
+ * @property {string} message The locale message with any formatting
1555
+ * place-holders; defaults to use of any single conditional
1556
+ * @property {string} [description] A description to add for translators
1557
+ * @property {Switches} [switches] Conditionals
1558
+ */
1559
+
1560
+ /**
1561
+ * @typedef {{
1562
+ * [key: string]: RichLocaleStringSubObject
1563
+ * }} RichLocaleStringBodyObject
1564
+ */
1565
+
1566
+ /**
1567
+ * @typedef {{
1568
+ * [key: string]: RichLocaleStringSubObject|RichNestedLocaleStringBodyObject
1569
+ * }} RichNestedLocaleStringBodyObject
1570
+ */
1571
+
1572
+ /**
1573
+ * Takes a base path and locale and gives a URL.
1574
+ * @callback LocaleResolver
1575
+ * @param {string} localesBasePath (Trailing slash optional)
1576
+ * @param {string} locale BCP-47 language string
1577
+ * @returns {string|false} URL of the locale file to be fetched
1578
+ */
1579
+
1580
+ /**
1581
+ * @typedef {[
1582
+ * Date|number, Date|number, (Intl.DateTimeFormatOptions|undefined)?
1583
+ * ]} DateRange
1584
+ */
1585
+
1586
+ /**
1587
+ * @typedef {string|string[]|number|Date|DateRange|
1588
+ * Element|Node|SubstitutionCallback|
1589
+ * NumberInfo|PluralInfo|CurrencyInfo|LanguageInfo|ScriptInfo|
1590
+ * DatetimeRangeInfo|DateRangeInfo|RegionInfo|DateTimeInfo|DateInfo|
1591
+ * ListInfo|RelativeTimeInfo
1592
+ * } SubstitutionObjectValue
1593
+ */
1594
+
1595
+ /**
1596
+ * @typedef {{
1597
+ * [key: string]: SubstitutionObjectValue
1598
+ * }} SubstitutionObject
1599
+ */
1600
+
1601
+ /**
1602
+ * @type {LocaleResolver}
1603
+ */
1604
+ var defaultLocaleResolver = function defaultLocaleResolver(localesBasePath, locale) {
1605
+ if (typeof localesBasePath !== 'string') {
1606
+ throw new TypeError('`defaultLocaleResolver` expects a string `localesBasePath`.');
1607
+ }
1608
+ if (typeof locale !== 'string') {
1609
+ throw new TypeError('`defaultLocaleResolver` expects a string `locale`.');
1610
+ }
1611
+ if (/[\.\/\\]/.test(locale)) {
1612
+ throw new TypeError('Locales cannot use file-reserved characters, `.`, `/` or `\\`');
1613
+ }
1614
+ return "".concat(localesBasePath.replace(/\/$/, ''), "/_locales/").concat(locale, "/messages.json");
1615
+ };
1616
+
1617
+ /**
1618
+ * @typedef {number} Integer
1619
+ */
1620
+
1621
+ /**
1622
+ * @callback Replace
1623
+ * @param {{
1624
+ * str: string,
1625
+ * substs?: import('./defaultLocaleResolver.js').SubstitutionObject,
1626
+ * formatter?: import('./Formatter.js').RegularFormatter|
1627
+ * import('./Formatter.js').LocalFormatter|
1628
+ * import('./Formatter.js').SwitchFormatter
1629
+ * }} cfg
1630
+ * @returns {string}
1631
+ */
1632
+
1633
+ /**
1634
+ * @callback ProcessSubstitutions
1635
+ * @param {{
1636
+ * str: string,
1637
+ * substs?: import('./defaultLocaleResolver.js').SubstitutionObject,
1638
+ * formatter?: import('./Formatter.js').RegularFormatter|
1639
+ * import('./Formatter.js').LocalFormatter|
1640
+ * import('./Formatter.js').SwitchFormatter
1641
+ * }} cfg
1642
+ * @returns {(string|Node)[]}
1643
+ */
1644
+
1645
+ /**
1646
+ * Callback to return a string or array of nodes and strings based on
1647
+ * a localized string, substitutions object, and other metadata.
1648
+ *
1649
+ * `string` - The localized string.
1650
+ * `dom` - If substitutions known to contain DOM, can be set
1651
+ * to `true` to optimize.
1652
+ * `usedKeys` - Array for tracking which keys have been used. Defaults
1653
+ * to empty array.
1654
+ * `substitutions` - The formatting substitutions object.
1655
+ * `allSubstitutions` - The
1656
+ * callback or array composed thereof for applying to each substitution.
1657
+ * `locale` - The successfully resolved locale
1658
+ * `locals` - The local section.
1659
+ * `switches` - The switch section.
1660
+ * `maximumLocalNestingDepth` - Depth of local variable resolution to
1661
+ * check before reporting a recursion error. Defaults to 3.
1662
+ * `missingSuppliedFormatters` - Callback
1663
+ * supplied key to throw if the supplied key is present (if
1664
+ * `throwOnMissingSuppliedFormatters` is enabled). Defaults to no-op.
1665
+ * `checkExtraSuppliedFormatters` - No
1666
+ * argument callback to check if any formatters are not present in `string`
1667
+ * (if `throwOnExtraSuppliedFormatters` is enabled). Defaults to no-op.
1668
+ * @typedef {(cfg: {
1669
+ * string: string,
1670
+ * dom?: boolean,
1671
+ * usedKeys: string[],
1672
+ * substitutions: import('./defaultLocaleResolver.js').SubstitutionObject,
1673
+ * allSubstitutions?: ?(
1674
+ * import('./defaultAllSubstitutions.js').AllSubstitutionCallback|
1675
+ * import('./defaultAllSubstitutions.js').AllSubstitutionCallback[]
1676
+ * )
1677
+ * locale: string|undefined,
1678
+ * locals?: import('./getMessageForKeyByStyle.js').LocalObject|undefined,
1679
+ * switches: import('./defaultLocaleResolver.js').Switches|undefined,
1680
+ * maximumLocalNestingDepth?: Integer,
1681
+ * missingSuppliedFormatters: import('./getDOMForLocaleString.js').
1682
+ * MissingSuppliedFormattersCallback,
1683
+ * checkExtraSuppliedFormatters: import('./getDOMForLocaleString.js').
1684
+ * CheckExtraSuppliedFormattersCallback
1685
+ * }) => string|(Node|string)[]} InsertNodesCallback
1686
+ */
1687
+
1688
+ /**
1689
+ * @type {InsertNodesCallback}
1690
+ */
1691
+ var defaultInsertNodes = function defaultInsertNodes(_ref) {
1692
+ var string = _ref.string,
1693
+ dom = _ref.dom,
1694
+ usedKeys = _ref.usedKeys,
1695
+ substitutions = _ref.substitutions,
1696
+ allSubstitutions = _ref.allSubstitutions,
1697
+ locale = _ref.locale,
1698
+ locals = _ref.locals,
1699
+ switches = _ref.switches,
1700
+ _ref$maximumLocalNest = _ref.maximumLocalNestingDepth,
1701
+ maximumLocalNestingDepth = _ref$maximumLocalNest === void 0 ? 3 : _ref$maximumLocalNest,
1702
+ missingSuppliedFormatters = _ref.missingSuppliedFormatters,
1703
+ checkExtraSuppliedFormatters = _ref.checkExtraSuppliedFormatters;
1704
+ if (typeof maximumLocalNestingDepth !== 'number') {
1705
+ throw new TypeError('`maximumLocalNestingDepth` must be a number.');
1706
+ }
1707
+ var addFunctionKeys = function addFunctionKeys() {
1708
+ Object.entries(substitutions).forEach(function (_ref2) {
1709
+ var _ref3 = _slicedToArray(_ref2, 2),
1710
+ key = _ref3[0],
1711
+ value = _ref3[1];
1712
+ if (typeof value === 'function') {
1713
+ usedKeys.push(key);
1714
+ }
1715
+ });
1716
+ };
1717
+ addFunctionKeys();
1718
+ var localFormatter = new LocalFormatter(/** @type {import('./getMessageForKeyByStyle.js').LocalObject} */locals);
1719
+ var regularFormatter = new RegularFormatter(substitutions);
1720
+ var switchFormatter = new SwitchFormatter(/** @type {import('./defaultLocaleResolver.js').Switches} */
1721
+ switches, {
1722
+ substitutions: substitutions
1723
+ });
1724
+
1725
+ // eslint-disable-next-line prefer-named-capture-group -- Convenient for now
1726
+ var formattingRegex = /(\\*)\{((?:(?:[\0-\|~-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])|\\\})*?)(?:(\|)((?:[\0-\|~-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*))?\}/g;
1727
+ if (allSubstitutions) {
1728
+ allSubstitutions = Array.isArray(allSubstitutions) ? allSubstitutions : [allSubstitutions];
1729
+ }
1730
+
1731
+ /**
1732
+ * @param {{
1733
+ * key: string,
1734
+ * arg: string,
1735
+ * substs: import('./defaultLocaleResolver.js').SubstitutionObject
1736
+ * }} cfg
1737
+ * @returns {string|Node}
1738
+ */
1739
+ var getSubstitution = function getSubstitution(_ref4) {
1740
+ var key = _ref4.key,
1741
+ arg = _ref4.arg,
1742
+ substs = _ref4.substs;
1743
+ /** @type {import('./defaultLocaleResolver.js').SubstitutionObjectValue} */
1744
+ var substitution;
1745
+ var isLocalKey =
1746
+ /**
1747
+ * @type {typeof import('./Formatter.js').LocalFormatter}
1748
+ */
1749
+ localFormatter.constructor.isMatchingKey(key);
1750
+ if (isLocalKey) {
1751
+ substitution = localFormatter.getSubstitution(key);
1752
+ } else if (
1753
+ /**
1754
+ * @type {typeof import('./Formatter.js').SwitchFormatter}
1755
+ */
1756
+ switchFormatter.constructor.isMatchingKey(key)) {
1757
+ substitution = switchFormatter.getSubstitution(key, {
1758
+ locale: (/** @type {string} */locale),
1759
+ usedKeys: usedKeys,
1760
+ arg: arg,
1761
+ missingSuppliedFormatters: missingSuppliedFormatters
1762
+ });
1763
+ } else {
1764
+ substitution = substs[key];
1765
+ if (typeof substitution === 'function') {
1766
+ substitution = substitution({
1767
+ arg: arg,
1768
+ key: key
1769
+ });
1770
+ }
1771
+ }
1772
+ // Todo: Could support resolving locals within arguments
1773
+ // Todo: Even for `null` `allSubstitutions`, we could have
1774
+ // a mode to throw for non-string/non-DOM (non-numbers?),
1775
+ // or whatever is not likely intended as a target for `toString()`.
1776
+ if (allSubstitutions) {
1777
+ substitution = /** @type {string|Node} */
1778
+ /**
1779
+ * @type {import('./defaultAllSubstitutions.js').
1780
+ * AllSubstitutionCallback[]
1781
+ * }
1782
+ */allSubstitutions.reduce(
1783
+ /**
1784
+ * @param {import('./defaultLocaleResolver.js').
1785
+ * SubstitutionObjectValue} subst
1786
+ * @param {import('./defaultAllSubstitutions.js').
1787
+ * AllSubstitutionCallback} allSubst
1788
+ * @returns {string|Node}
1789
+ */
1790
+ function (subst, allSubst) {
1791
+ return allSubst({
1792
+ value: subst,
1793
+ arg: arg,
1794
+ key: key,
1795
+ locale: locale
1796
+ });
1797
+ }, substitution);
1798
+ } else if (arg && /^(?:NUMBER|DATE(?:TIME|RANGE|TIMERANGE)?|REGION|LANGUAGE|SCRIPT|CURRENCY|RELATIVE|LIST)(?:\||$)/.test(arg)) {
1799
+ substitution = defaultAllSubstitutions({
1800
+ value: substitution,
1801
+ arg: arg,
1802
+ locale: locale
1803
+ });
1804
+ }
1805
+
1806
+ // Change this and return type if other substitutions possible
1807
+ return /** @type {string|Node} */substitution;
1808
+ };
1809
+ var recursiveLocalCount = 1;
1810
+ /**
1811
+ * @param {{
1812
+ * substitution: string|Node,
1813
+ * ky: string,
1814
+ * arg: string,
1815
+ * processSubsts: Replace|ProcessSubstitutions
1816
+ * }} cfg
1817
+ * @returns {number|string|Node|(string|Node)[]}
1818
+ */
1819
+ var checkLocalVars = function checkLocalVars(_ref5) {
1820
+ var substitution = _ref5.substitution,
1821
+ ky = _ref5.ky,
1822
+ arg = _ref5.arg,
1823
+ processSubsts = _ref5.processSubsts;
1824
+ /** @type {number|string|Node|(string|Node)[]} */
1825
+ var subst = substitution;
1826
+ if (typeof substitution === 'string' && substitution.includes('{')) {
1827
+ if (recursiveLocalCount++ > maximumLocalNestingDepth) {
1828
+ throw new TypeError('Too much recursion in local variables.');
1829
+ }
1830
+ if (/** @type {typeof import('./Formatter.js').LocalFormatter} */localFormatter.constructor.isMatchingKey(ky)) {
1831
+ var extraSubsts = substitutions;
1832
+ var localFormatters;
1833
+ if (arg) {
1834
+ localFormatters = parseJSONExtra(arg);
1835
+ extraSubsts = _objectSpread2(_objectSpread2({}, substitutions), localFormatters);
1836
+ }
1837
+ subst = processSubsts({
1838
+ str: substitution,
1839
+ substs: extraSubsts,
1840
+ formatter: localFormatter
1841
+ });
1842
+ if (localFormatters) {
1843
+ checkExtraSuppliedFormatters({
1844
+ substitutions: localFormatters
1845
+ });
1846
+ }
1847
+ } else if (/** @type {typeof import('./Formatter.js').SwitchFormatter} */
1848
+ switchFormatter.constructor.isMatchingKey(ky)) {
1849
+ subst = processSubsts({
1850
+ str: substitution
1851
+ });
1852
+ }
1853
+ }
1854
+ return subst;
1855
+ };
1856
+
1857
+ // Give chance to avoid this block when known to contain DOM
1858
+ if (!dom) {
1859
+ // Run this block to optimize non-DOM substitutions
1860
+ var returnsDOM = false;
1861
+
1862
+ /** @type {Replace} */
1863
+ var _replace = function replace(_ref6) {
1864
+ var str = _ref6.str,
1865
+ _ref6$substs = _ref6.substs,
1866
+ substs = _ref6$substs === void 0 ? substitutions : _ref6$substs,
1867
+ _ref6$formatter = _ref6.formatter,
1868
+ formatter = _ref6$formatter === void 0 ? regularFormatter : _ref6$formatter;
1869
+ return str.replaceAll(formattingRegex,
1870
+ /**
1871
+ * @param {string} _
1872
+ * @param {string} esc
1873
+ * @param {string} ky
1874
+ * @param {string} pipe
1875
+ * @param {string} arg
1876
+ * @returns {string}
1877
+ */
1878
+ function (_, esc, ky, pipe, arg) {
1879
+ if (esc.length % 2) {
1880
+ return _;
1881
+ }
1882
+ if (missingSuppliedFormatters({
1883
+ key: ky,
1884
+ formatter: formatter
1885
+ })) {
1886
+ return _;
1887
+ }
1888
+ /** @type {string|number|Node|(string|Node)[]} */
1889
+ var substitution = getSubstitution({
1890
+ key: ky,
1891
+ arg: arg,
1892
+ substs: substs
1893
+ });
1894
+ substitution = checkLocalVars({
1895
+ substitution: substitution,
1896
+ ky: ky,
1897
+ arg: arg,
1898
+ processSubsts: _replace
1899
+ });
1900
+ returnsDOM || (returnsDOM = substitution !== null && _typeof(substitution) === 'object' && 'nodeType' in substitution);
1901
+ usedKeys.push(ky);
1902
+ return esc + substitution;
1903
+ });
1904
+ };
1905
+ var ret = _replace({
1906
+ str: string
1907
+ });
1908
+ if (!returnsDOM) {
1909
+ checkExtraSuppliedFormatters({
1910
+ substitutions: substitutions
1911
+ });
1912
+ usedKeys.length = 0;
1913
+ addFunctionKeys();
1914
+ return unescapeBackslashes(ret);
1915
+ }
1916
+ usedKeys.length = 0;
1917
+ addFunctionKeys();
1918
+ }
1919
+ recursiveLocalCount = 1;
1920
+
1921
+ /** @type {ProcessSubstitutions} */
1922
+ var _processSubstitutions = function processSubstitutions(_ref7) {
1923
+ var str = _ref7.str,
1924
+ _ref7$substs = _ref7.substs,
1925
+ substs = _ref7$substs === void 0 ? substitutions : _ref7$substs,
1926
+ _ref7$formatter = _ref7.formatter,
1927
+ formatter = _ref7$formatter === void 0 ? regularFormatter : _ref7$formatter;
1928
+ /** @type {(string|Node)[]} */
1929
+ var nodes = [];
1930
+
1931
+ // Copy to ensure we are resetting index on each instance (manually
1932
+ // resetting on `formattingRegex` is problematic with recursion that
1933
+ // uses the same regex copy)
1934
+ var regex = new RegExp(formattingRegex, 'gv');
1935
+
1936
+ /**
1937
+ * @param {...(string|Node)} args
1938
+ */
1939
+ var push = function push() {
1940
+ nodes.push.apply(nodes, arguments);
1941
+ };
1942
+ processRegex(regex, str, {
1943
+ extra: push,
1944
+ onMatch: function onMatch(_, esc, ky, pipe, arg) {
1945
+ if (missingSuppliedFormatters({
1946
+ key: ky,
1947
+ formatter: formatter
1948
+ })) {
1949
+ push(_);
1950
+ } else {
1951
+ if (esc.length) {
1952
+ push(esc);
1953
+ }
1954
+
1955
+ /** @type {string|number|Node|(string|Node)[]} */
1956
+ var substitution = getSubstitution({
1957
+ key: ky,
1958
+ arg: arg,
1959
+ substs: substs
1960
+ });
1961
+ substitution = checkLocalVars({
1962
+ substitution: substitution,
1963
+ ky: ky,
1964
+ arg: arg,
1965
+ processSubsts: _processSubstitutions
1966
+ });
1967
+ if (Array.isArray(substitution)) {
1968
+ push.apply(void 0, _toConsumableArray(substitution));
1969
+ } else if (
1970
+ // Clone so that multiple instances may be added (and no
1971
+ // side effects to user code)
1972
+ substitution && _typeof(substitution) === 'object' && 'nodeType' in substitution) {
1973
+ push(substitution.cloneNode(true));
1974
+ } else {
1975
+ // Why no number here?
1976
+ push(/** @type {string} */substitution);
1977
+ }
1978
+ }
1979
+ usedKeys.push(ky);
1980
+ }
1981
+ });
1982
+ return nodes;
1983
+ };
1984
+ var nodes = _processSubstitutions({
1985
+ str: string
1986
+ });
1987
+ checkExtraSuppliedFormatters({
1988
+ substitutions: substitutions
1989
+ });
1990
+ usedKeys.length = 0;
1991
+ return nodes.map(function (node) {
1992
+ if (typeof node === 'string') {
1993
+ return unescapeBackslashes(node);
1994
+ }
1995
+ return node;
1996
+ });
1997
+ };
1998
+
1999
+ var _templateObject, _templateObject2;
2000
+ /**
2001
+ * @callback KeyCheckerConverterCallback
2002
+ * @param {string|string[]} key By default may be an array (if the type ends
2003
+ * with "Nested") or a string, but a non-default validator may do otherwise.
2004
+ * @param {"plain"|"plainNested"|"rich"|
2005
+ * "richNested"|
2006
+ * import('./getMessageForKeyByStyle.js').MessageStyleCallback
2007
+ * } messageStyle
2008
+ * @throws {TypeError}
2009
+ * @returns {string} The converted (or unconverted) key
2010
+ */
2011
+
2012
+ /**
2013
+ * @type {KeyCheckerConverterCallback}
2014
+ */
2015
+ var defaultKeyCheckerConverter = function defaultKeyCheckerConverter(key, messageStyle) {
2016
+ if (typeof messageStyle === 'string' && Array.isArray(key) && key.every(function (k) {
2017
+ return typeof k === 'string';
2018
+ }) && messageStyle.endsWith('Nested')) {
2019
+ return key.map(function (k) {
2020
+ return k.replaceAll(/*#__PURE__*/_wrapRegExp(/(\\+)/g, {
2021
+ backslashes: 1
2022
+ }), String.raw(_templateObject || (_templateObject = _taggedTemplateLiteral(["$<backslashes>"], ["\\$<backslashes>"])))).replaceAll('.', String.raw(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["."], ["\\."]))));
2023
+ }).join('.');
2024
+ }
2025
+ if (typeof key !== 'string') {
2026
+ throw new TypeError('`key` is expected to be a string (or array of strings for nested style)');
2027
+ }
2028
+ return key;
2029
+ };
2030
+
2031
+ /**
2032
+ * @typedef {LocaleBody} LocalObject
2033
+ */
2034
+
2035
+ /**
2036
+ * May also contain language code and direction, translator name and
2037
+ * contact, etc., but no defaults currently apply besides reserving `locals`
2038
+ * @typedef {object} LocaleHead
2039
+ * @property {LocalObject} [locals]
2040
+ * @property {import('./defaultLocaleResolver.js').Switches} [switches]
2041
+ */
2042
+
2043
+ /**
2044
+ * @typedef {import('./defaultLocaleResolver.js').
2045
+ * RichNestedLocaleStringBodyObject|
2046
+ * import('./defaultLocaleResolver.js').RichLocaleStringBodyObject|
2047
+ * import('./defaultLocaleResolver.js').PlainLocaleStringBodyObject|
2048
+ * import('./defaultLocaleResolver.js').PlainNestedLocaleStringBodyObject|
2049
+ * object
2050
+ * } LocaleBody
2051
+ */
2052
+
2053
+ /**
2054
+ * @typedef {object} LocaleObject
2055
+ * @property {LocaleHead} [head]
2056
+ * @property {LocaleBody} body
2057
+ */
2058
+
2059
+ /**
2060
+ * @typedef {object} MessageStyleCallbackResult
2061
+ * @property {string} value Regardless of message style, will contain
2062
+ * the string result
2063
+ * @property {import(
2064
+ * './defaultLocaleResolver.js'
2065
+ * ).RichLocaleStringSubObject} [info] Full info on the localized item
2066
+ * (for rich message styles only)
2067
+ */
2068
+
2069
+ /**
2070
+ * @callback MessageStyleCallback
2071
+ * @param {LocaleObject} obj The exact
2072
+ * format depends on the `cfg.defaults` of `i18n`
2073
+ * @param {string} key
2074
+ * @returns {false|MessageStyleCallbackResult} If `false`, will resort to
2075
+ * default
2076
+ */
2077
+
2078
+ /* eslint-disable @stylistic/max-len -- Long */
2079
+ /**
2080
+ * @param {object} [cfg]
2081
+ * @param {"richNested"|"rich"|"plain"|"plainNested"|MessageStyleCallback} [cfg.messageStyle]
2082
+ * @returns {MessageStyleCallback}
2083
+ */
2084
+ var getMessageForKeyByStyle = function getMessageForKeyByStyle() {
2085
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
2086
+ _ref$messageStyle = _ref.messageStyle,
2087
+ messageStyle = _ref$messageStyle === void 0 ? 'richNested' : _ref$messageStyle;
2088
+ return typeof messageStyle === 'function' ? messageStyle : messageStyle === 'richNested' ? function (mainObj, key) {
2089
+ var obj =
2090
+ /**
2091
+ * @type {import('./defaultLocaleResolver.js').
2092
+ * RichNestedLocaleStringBodyObject
2093
+ * }
2094
+ */
2095
+ mainObj && _typeof(mainObj) === 'object' && mainObj.body;
2096
+
2097
+ /**
2098
+ * @type {string[]}
2099
+ */
2100
+ var keys = [];
2101
+ // eslint-disable-next-line @stylistic/max-len -- Long
2102
+ // eslint-disable-next-line prefer-named-capture-group -- Convenient for now
2103
+ var possiblyEscapedCharPattern = /(\\*)\./g;
2104
+
2105
+ /**
2106
+ * @param {string} val
2107
+ * @returns {void}
2108
+ */
2109
+ var mergeWithPreviousOrStart = function mergeWithPreviousOrStart(val) {
2110
+ if (!keys.length) {
2111
+ keys[0] = '';
2112
+ }
2113
+ keys[keys.length - 1] += val;
2114
+ };
2115
+ processRegex(possiblyEscapedCharPattern, key, {
2116
+ // If odd, this is just an escaped dot, so merge content with
2117
+ // any previous
2118
+ extra: mergeWithPreviousOrStart,
2119
+ onMatch: function onMatch(_, esc) {
2120
+ // If even, there are no backslashes, or they are just escaped
2121
+ // backslashes and not an escaped dot, so start anew, though
2122
+ // first merge any backslashes
2123
+ mergeWithPreviousOrStart(esc);
2124
+ keys.push('');
2125
+ }
2126
+ });
2127
+ var keysUnescaped = keys.map(function (ky) {
2128
+ return unescapeBackslashes(ky);
2129
+ });
2130
+
2131
+ /**
2132
+ * @type {false|{
2133
+ * value: string|undefined,
2134
+ * info: import('./defaultLocaleResolver.js').
2135
+ * RichLocaleStringSubObject
2136
+ * }}
2137
+ */
2138
+ var ret = false;
2139
+ var currObj = obj;
2140
+
2141
+ // eslint-disable-next-line @stylistic/max-len -- Long
2142
+ // eslint-disable-next-line unicorn/no-unused-array-method-return -- Shortcircuiting
2143
+ keysUnescaped.some(function (ky, i, kys) {
2144
+ if (!currObj || _typeof(currObj) !== 'object') {
2145
+ return true;
2146
+ }
2147
+ if (
2148
+ // If specified key is too deep, we should fail
2149
+ i === kys.length - 1 && Object.hasOwn(currObj, ky) && currObj[ky] !== null && _typeof(currObj[ky]) === 'object' && 'message' in currObj[ky] &&
2150
+ // NECESSARY FOR SECURITY ON UNTRUSTED LOCALES
2151
+ typeof currObj[ky].message === 'string') {
2152
+ ret = {
2153
+ value: (/** @type {string} */currObj[ky].message),
2154
+ info: (
2155
+ /**
2156
+ * @type {import('./defaultLocaleResolver.js').
2157
+ * RichLocaleStringSubObject}
2158
+ */
2159
+ currObj[ky])
2160
+ };
2161
+ }
2162
+ currObj =
2163
+ /**
2164
+ * @type {import('./defaultLocaleResolver.js').
2165
+ * RichNestedLocaleStringBodyObject
2166
+ * }
2167
+ */
2168
+ currObj[ky];
2169
+ return false;
2170
+ });
2171
+ return ret;
2172
+ } : messageStyle === 'rich' ? function (mainObj, key) {
2173
+ var obj =
2174
+ /**
2175
+ * @type {import('./defaultLocaleResolver.js').
2176
+ * RichLocaleStringBodyObject
2177
+ * }
2178
+ */
2179
+ mainObj && _typeof(mainObj) === 'object' && mainObj.body;
2180
+ if (obj && _typeof(obj) === 'object' && Object.hasOwn(obj, key) && obj[key] !== null && _typeof(obj[key]) === 'object' && 'message' in obj[key] &&
2181
+ // NECESSARY FOR SECURITY ON UNTRUSTED LOCALES
2182
+ typeof obj[key].message === 'string') {
2183
+ return {
2184
+ value: obj[key].message,
2185
+ info: obj[key]
2186
+ };
2187
+ }
2188
+ return false;
2189
+ } : messageStyle === 'plain' ? function (mainObj, key) {
2190
+ var obj =
2191
+ /**
2192
+ * @type {import('./defaultLocaleResolver.js').
2193
+ * PlainLocaleStringBodyObject
2194
+ * }
2195
+ */
2196
+ mainObj && _typeof(mainObj) === 'object' && mainObj.body;
2197
+ if (obj && _typeof(obj) === 'object' && Object.hasOwn(obj, key) && obj[key] !== null && typeof obj[key] === 'string') {
2198
+ return {
2199
+ value: obj[key]
2200
+ };
2201
+ }
2202
+ return false;
2203
+ } : messageStyle === 'plainNested' ? function (mainObj, key) {
2204
+ var obj =
2205
+ /**
2206
+ * @type {import('./defaultLocaleResolver.js').
2207
+ * PlainNestedLocaleStringBodyObject
2208
+ * }
2209
+ */
2210
+ mainObj && _typeof(mainObj) === 'object' && mainObj.body;
2211
+ if (obj && _typeof(obj) === 'object') {
2212
+ // Should really be counting that it is an odd number
2213
+ // of backslashes only
2214
+ var keys = key.split(/(?<!\\)\./);
2215
+ var value = keys.reduce(
2216
+ /**
2217
+ * @param {null|string|import('./defaultLocaleResolver.js').
2218
+ * PlainNestedLocaleStringBodyObject} o
2219
+ * @param {string} k
2220
+ * @returns {null|string|import('./defaultLocaleResolver.js').
2221
+ * PlainNestedLocaleStringBodyObject}
2222
+ */
2223
+ function (o, k) {
2224
+ // eslint-disable-next-line @stylistic/max-len -- Long
2225
+ // eslint-disable-next-line unicorn/no-computed-property-existence-check -- Ok
2226
+ if (o && _typeof(o) === 'object' && o[k]) {
2227
+ return o[k];
2228
+ }
2229
+ return null;
2230
+ }, obj);
2231
+ if (value && typeof value === 'string') {
2232
+ return {
2233
+ value: value
2234
+ };
2235
+ }
2236
+ }
2237
+ return false;
2238
+ } : function () {
2239
+ throw new TypeError("Unknown `messageStyle` ".concat(messageStyle));
2240
+ }();
2241
+ };
2242
+
2243
+ /**
2244
+ * @param {object} cfg
2245
+ * @param {string|false} [cfg.message] If present, this string will be
2246
+ * the return value.
2247
+ * @param {false|null|undefined|
2248
+ * import('./getMessageForKeyByStyle.js').LocaleObject
2249
+ * } [cfg.defaults]
2250
+ * @param {"richNested"|"rich"|"plain"|"plainNested"|
2251
+ * import('./getMessageForKeyByStyle.js').MessageStyleCallback
2252
+ * } [cfg.messageStyle]
2253
+ * @param {import('./getMessageForKeyByStyle.js').
2254
+ * MessageStyleCallback
2255
+ * } [cfg.messageForKey] Defaults to getting `MessageStyleCallback` based
2256
+ * on `messageStyle`
2257
+ * @param {string} cfg.key Key to check against object of strings;
2258
+ * used to find a default if no string `message` is provided.
2259
+ * @returns {string}
2260
+ */
2261
+ var getStringFromMessageAndDefaults = function getStringFromMessageAndDefaults(_ref) {
2262
+ var message = _ref.message,
2263
+ defaults = _ref.defaults,
2264
+ messageStyle = _ref.messageStyle,
2265
+ _ref$messageForKey = _ref.messageForKey,
2266
+ messageForKey = _ref$messageForKey === void 0 ? getMessageForKeyByStyle({
2267
+ messageStyle: messageStyle
2268
+ }) : _ref$messageForKey,
2269
+ key = _ref.key;
2270
+ // NECESSARY CHECK FOR SECURITY ON UNTRUSTED LOCALES
2271
+ /** @type {string|false} */
2272
+ var str;
2273
+ if (typeof message === 'string') {
2274
+ str = message;
2275
+ } else if (
2276
+ // eslint-disable-next-line @stylistic/max-len -- Long
2277
+ // eslint-disable-next-line unicorn/prefer-includes-over-repeated-comparisons -- TS
2278
+ defaults === false || defaults === undefined || defaults === null) {
2279
+ str = false;
2280
+ } else if (defaults && _typeof(defaults) === 'object') {
2281
+ var msg = messageForKey(defaults, key);
2282
+ str = msg ? msg.value : msg;
2283
+ } else {
2284
+ throw new TypeError("Default locale strings must resolve to `false`, " + "nullish, or an object!");
2285
+ }
2286
+ if (str === false) {
2287
+ throw new Error("Key value not found for key: (".concat(key, ")"));
2288
+ }
2289
+ return str;
2290
+ };
2291
+
2292
+ /**
2293
+ * @typedef {number} Integer
2294
+ */
2295
+
2296
+ /**
2297
+ * @callback CheckExtraSuppliedFormattersCallback
2298
+ * @param {import('./defaultLocaleResolver.js').SubstitutionObject|{
2299
+ * substitutions: import('./defaultLocaleResolver.js').SubstitutionObject
2300
+ * }} substs (Why is an arg. of `substitutions` being passed in?)
2301
+ * @throws {Error} Upon an extra formatting key being found
2302
+ * @returns {void}
2303
+ */
2304
+
2305
+ /**
2306
+ * @typedef {(
2307
+ * cfg: {
2308
+ * key: string,
2309
+ * formatter: import('./Formatter.js').LocalFormatter|
2310
+ * import('./Formatter.js').RegularFormatter|
2311
+ * import('./Formatter.js').SwitchFormatter
2312
+ * }
2313
+ * ) => boolean} MissingSuppliedFormattersCallback
2314
+ */
2315
+
2316
+ /**
2317
+ *
2318
+ * @param {object} cfg
2319
+ * @param {string} cfg.string
2320
+ * @param {string} [cfg.locale] The (possibly already resolved) locale
2321
+ * for use by configuring formatters
2322
+ * @param {import('./getMessageForKeyByStyle.js').LocalObject} [cfg.locals]
2323
+ * @param {import('./defaultLocaleResolver.js').Switches} [cfg.switches]
2324
+ * @param {Integer} [cfg.maximumLocalNestingDepth]
2325
+ * @param {?(import('./defaultAllSubstitutions.js').AllSubstitutionCallback|
2326
+ * import('./defaultAllSubstitutions.js').AllSubstitutionCallback[])
2327
+ * } [cfg.allSubstitutions]
2328
+ * @param {import('./defaultInsertNodes.js').InsertNodesCallback
2329
+ * } [cfg.insertNodes]
2330
+ * @param {false|import('./defaultLocaleResolver.js').SubstitutionObject
2331
+ * } [cfg.substitutions]
2332
+ * @param {boolean} [cfg.dom]
2333
+ * @param {boolean} [cfg.forceNodeReturn]
2334
+ * @param {boolean} [cfg.throwOnMissingSuppliedFormatters]
2335
+ * @param {boolean} [cfg.throwOnExtraSuppliedFormatters]
2336
+ * @returns {string|Text|DocumentFragment}
2337
+ */
2338
+ var getDOMForLocaleString = function getDOMForLocaleString(_ref) {
2339
+ var string = _ref.string,
2340
+ locale = _ref.locale,
2341
+ locals = _ref.locals,
2342
+ switches = _ref.switches;
2343
+ _ref.maximumLocalNestingDepth;
2344
+ var _ref$allSubstitutions = _ref.allSubstitutions,
2345
+ allSubstitutions = _ref$allSubstitutions === void 0 ? [defaultAllSubstitutions] : _ref$allSubstitutions,
2346
+ _ref$insertNodes = _ref.insertNodes,
2347
+ insertNodes = _ref$insertNodes === void 0 ? defaultInsertNodes : _ref$insertNodes,
2348
+ _ref$substitutions = _ref.substitutions,
2349
+ substitutions = _ref$substitutions === void 0 ? false : _ref$substitutions,
2350
+ _ref$dom = _ref.dom,
2351
+ dom = _ref$dom === void 0 ? false : _ref$dom,
2352
+ _ref$forceNodeReturn = _ref.forceNodeReturn,
2353
+ forceNodeReturn = _ref$forceNodeReturn === void 0 ? false : _ref$forceNodeReturn,
2354
+ _ref$throwOnMissingSu = _ref.throwOnMissingSuppliedFormatters,
2355
+ throwOnMissingSuppliedFormatters = _ref$throwOnMissingSu === void 0 ? true : _ref$throwOnMissingSu,
2356
+ _ref$throwOnExtraSupp = _ref.throwOnExtraSuppliedFormatters,
2357
+ throwOnExtraSuppliedFormatters = _ref$throwOnExtraSupp === void 0 ? true : _ref$throwOnExtraSupp;
2358
+ if (typeof string !== 'string') {
2359
+ throw new TypeError('An options object with a `string` property set to a string must ' + 'be provided for `getDOMForLocaleString`.');
2360
+ }
2361
+
2362
+ /**
2363
+ * @param {string} str
2364
+ * @returns {Text|string}
2365
+ */
2366
+ var stringOrTextNode = function stringOrTextNode(str) {
2367
+ var _doc = getDocument();
2368
+ return forceNodeReturn ? /** @type {Document} */_doc.createTextNode(str) : str;
2369
+ };
2370
+ if (!substitutions && !allSubstitutions && !throwOnMissingSuppliedFormatters) {
2371
+ return stringOrTextNode(string);
2372
+ }
2373
+ if (!substitutions) {
2374
+ substitutions = {};
2375
+ }
2376
+
2377
+ /** @type {string[]} */
2378
+ var usedKeys = [];
2379
+
2380
+ /**
2381
+ * @type {CheckExtraSuppliedFormattersCallback}
2382
+ */
2383
+ var checkExtraSuppliedFormatters = function checkExtraSuppliedFormatters(_ref2) {
2384
+ var substs = _ref2.substitutions;
2385
+ if (throwOnExtraSuppliedFormatters) {
2386
+ Object.keys(substs).forEach(function (key) {
2387
+ if (!usedKeys.includes(key)) {
2388
+ throw new Error("Extra formatting key: ".concat(key));
2389
+ }
2390
+ });
2391
+ }
2392
+ };
2393
+
2394
+ /**
2395
+ * @type {MissingSuppliedFormattersCallback}
2396
+ */
2397
+ var missingSuppliedFormatters = function missingSuppliedFormatters(_ref3) {
2398
+ var key = _ref3.key,
2399
+ formatter = _ref3.formatter;
2400
+ var matching = formatter.isMatch(key);
2401
+ if (!matching &&
2402
+ /**
2403
+ * @type {typeof import('./Formatter.js').LocalFormatter|
2404
+ * typeof import('./Formatter.js').RegularFormatter|
2405
+ * typeof import('./Formatter.js').SwitchFormatter}
2406
+ */
2407
+ formatter.constructor.isMatchingKey(key)) {
2408
+ if (throwOnMissingSuppliedFormatters) {
2409
+ throw new Error("Missing formatting key: ".concat(key));
2410
+ }
2411
+ return true;
2412
+ }
2413
+ return false;
2414
+ };
2415
+ var nodes = insertNodes({
2416
+ string: string,
2417
+ dom: dom,
2418
+ usedKeys: usedKeys,
2419
+ substitutions: substitutions,
2420
+ allSubstitutions: allSubstitutions,
2421
+ locale: locale,
2422
+ locals: locals,
2423
+ switches: switches,
2424
+ missingSuppliedFormatters: missingSuppliedFormatters,
2425
+ checkExtraSuppliedFormatters: checkExtraSuppliedFormatters
2426
+ });
2427
+ if (typeof nodes === 'string') {
2428
+ return stringOrTextNode(nodes);
2429
+ }
2430
+ var _doc = getDocument();
2431
+ var container = /** @type {Document} */_doc.createDocumentFragment();
2432
+ container.append.apply(container, _toConsumableArray(nodes));
2433
+ return container;
2434
+ };
2435
+
2436
+ /**
2437
+ * Takes a locale and returns a new locale to check.
2438
+ * @callback LocaleMatcher
2439
+ * @param {string} locale The failed locale
2440
+ * @throws {Error} If there are no further hyphens left to check
2441
+ * @returns {string|Promise<string>} The new locale to check
2442
+ */
2443
+
2444
+ /**
2445
+ * @type {LocaleMatcher}
2446
+ */
2447
+ var defaultLocaleMatcher = function defaultLocaleMatcher(locale) {
2448
+ if (!locale.includes('-')) {
2449
+ throw new Error('Locale not available');
2450
+ }
2451
+ // Try without hyphen, i.e., the "lookup" algorithm:
2452
+ // See https://tools.ietf.org/html/rfc4647#section-3.4 and
2453
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl
2454
+ return locale.replace(/-(?:[\0-,\.-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*$/, '');
2455
+ };
2456
+
2457
+ /**
2458
+ * @param {object} cfg
2459
+ * @param {string} cfg.locale
2460
+ * @param {string[]} cfg.locales
2461
+ * @param {LocaleMatcher} [cfg.localeMatcher]
2462
+ * @returns {string|false}
2463
+ */
2464
+ var getMatchingLocale = function getMatchingLocale(_ref) {
2465
+ var locale = _ref.locale,
2466
+ locales = _ref.locales,
2467
+ _ref$localeMatcher = _ref.localeMatcher,
2468
+ localeMatcher = _ref$localeMatcher === void 0 ? defaultLocaleMatcher : _ref$localeMatcher;
2469
+ try {
2470
+ while (!locales.includes(locale)) {
2471
+ // Catch as `defaultLocaleMatcher` will throw if no hyphen found
2472
+ locale = localeMatcher(locale);
2473
+ }
2474
+ } catch (err) {
2475
+ return false;
2476
+ }
2477
+ return locale;
2478
+ };
2479
+
2480
+ /**
2481
+ * @typedef {object} LocaleObjectInfo
2482
+ * @property {import('./getMessageForKeyByStyle.js').
2483
+ * LocaleObject} strings The successfully retrieved locale strings
2484
+ * @property {string} locale The successfully resolved locale
2485
+ */
2486
+
2487
+ /**
2488
+ * @typedef {{
2489
+ * locales?: string[],
2490
+ * defaultLocales?: string[],
2491
+ * localesBasePath?: string,
2492
+ * localeResolver?: import('./defaultLocaleResolver.js').LocaleResolver,
2493
+ * localeMatcher?: "lookup"|LocaleMatcher
2494
+ * }} LocaleStringArgs
2495
+ */
2496
+
2497
+ /**
2498
+ * `locales` - BCP-47 language strings. Defaults to `navigator.languages`.
2499
+ * `defaultLocales` - Defaults to ["en-US"].
2500
+ * `localesBasePath` - Defaults to `.`.
2501
+ * `localeResolver` - Defaults to `defaultLocaleResolver`.
2502
+ * @typedef {(
2503
+ * cfg?: LocaleStringArgs
2504
+ * ) => Promise<LocaleObjectInfo>} LocaleStringFinder
2505
+ */
2506
+
2507
+ /**
2508
+ *
2509
+ * @type {LocaleStringFinder}
2510
+ */
2511
+ var findLocaleStrings = function findLocaleStrings() {
2512
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
2513
+ locales = _ref2.locales,
2514
+ defaultLocales = _ref2.defaultLocales,
2515
+ localeResolver = _ref2.localeResolver,
2516
+ localesBasePath = _ref2.localesBasePath,
2517
+ localeMatcher = _ref2.localeMatcher;
2518
+ return /** @type {Promise<LocaleObjectInfo>} */_findLocale({
2519
+ locales: locales,
2520
+ defaultLocales: defaultLocales,
2521
+ localeResolver: localeResolver,
2522
+ localesBasePath: localesBasePath,
2523
+ localeMatcher: localeMatcher
2524
+ });
2525
+ };
2526
+
2527
+ /**
2528
+ * Resolves to the successfully resolved locale.
2529
+ * `locales` - BCP-47 language strings. Defaults to `navigator.languages`.
2530
+ * `defaultLocales` - Defaults to ["en-US"].
2531
+ * `localesBasePath` - Defaults to `.`.
2532
+ * `localeResolver` - Defaults to `defaultLocaleResolver`.
2533
+ * `localeMatcher`.
2534
+ * @typedef {(cfg?: LocaleStringArgs) => Promise<string>} LocaleFinder
2535
+ */
2536
+
2537
+ /**
2538
+ *
2539
+ * @type {LocaleFinder}
2540
+ */
2541
+ var findLocale = function findLocale() {
2542
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
2543
+ locales = _ref3.locales,
2544
+ defaultLocales = _ref3.defaultLocales,
2545
+ localeResolver = _ref3.localeResolver,
2546
+ localesBasePath = _ref3.localesBasePath,
2547
+ localeMatcher = _ref3.localeMatcher;
2548
+ return /** @type {Promise<string>} */_findLocale({
2549
+ locales: locales,
2550
+ defaultLocales: defaultLocales,
2551
+ localeResolver: localeResolver,
2552
+ localesBasePath: localesBasePath,
2553
+ localeMatcher: localeMatcher,
2554
+ headOnly: true
2555
+ });
2556
+ };
2557
+
2558
+ /**
2559
+ * @type {(
2560
+ * cfg: LocaleStringArgs & {
2561
+ * headOnly?: boolean
2562
+ * }
2563
+ * ) => Promise<string|LocaleObjectInfo>} Also has a `headOnly` boolean
2564
+ * property to determine whether to make a simple HEAD and resolve to
2565
+ * the locale rather than locale and contents
2566
+ */
2567
+ var _findLocale = /*#__PURE__*/function () {
2568
+ var _findLocale2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref4) {
2569
+ var _ref4$locales, locales, _ref4$defaultLocales, defaultLocales, _ref4$localeResolver, localeResolver, _ref4$localesBasePath, localesBasePath, _ref4$localeMatcher, localeMatcher, _ref4$headOnly, headOnly, getLocale, _getLocale;
2570
+ return _regenerator().w(function (_context2) {
2571
+ while (1) switch (_context2.n) {
2572
+ case 0:
2573
+ _getLocale = function _getLocale3() {
2574
+ _getLocale = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(locale) {
2575
+ var url, _fetch, resp, strings, newLocale, _t;
2576
+ return _regenerator().w(function (_context) {
2577
+ while (1) switch (_context.p = _context.n) {
2578
+ case 0:
2579
+ if (!(typeof locale !== 'string')) {
2580
+ _context.n = 1;
2581
+ break;
2582
+ }
2583
+ throw new TypeError('Non-string locale type');
2584
+ case 1:
2585
+ url = localeResolver(localesBasePath, locale);
2586
+ if (!(typeof url !== 'string')) {
2587
+ _context.n = 2;
2588
+ break;
2589
+ }
2590
+ throw new TypeError('`localeResolver` expected to resolve to (URL) string.');
2591
+ case 2:
2592
+ _context.p = 2;
2593
+ _fetch = /** @type {import('./shared.js').Fetch} */getFetch();
2594
+ _context.n = 3;
2595
+ return headOnly ? _fetch(url, {
2596
+ method: 'HEAD'
2597
+ }) : _fetch(url);
2598
+ case 3:
2599
+ resp = _context.v;
2600
+ if (!(resp.status === 404)) {
2601
+ _context.n = 4;
2602
+ break;
2603
+ }
2604
+ throw new Error('Trying again');
2605
+ case 4:
2606
+ if (!headOnly) {
2607
+ _context.n = 5;
2608
+ break;
2609
+ }
2610
+ return _context.a(2, locale);
2611
+ case 5:
2612
+ _context.n = 6;
2613
+ return resp.json();
2614
+ case 6:
2615
+ strings = _context.v;
2616
+ return _context.a(2, {
2617
+ locale: locale,
2618
+ strings: strings
2619
+ });
2620
+ case 7:
2621
+ _context.p = 7;
2622
+ _t = _context.v;
2623
+ if (!(/** @type {Error} */_t.name === 'SyntaxError')) {
2624
+ _context.n = 8;
2625
+ break;
2626
+ }
2627
+ throw _t;
2628
+ case 8:
2629
+ _context.n = 9;
2630
+ return /** @type {LocaleMatcher} */localeMatcher(locale);
2631
+ case 9:
2632
+ newLocale = _context.v;
2633
+ return _context.a(2, getLocale(newLocale));
2634
+ }
2635
+ }, _callee, null, [[2, 7]]);
2636
+ }));
2637
+ return _getLocale.apply(this, arguments);
2638
+ };
2639
+ getLocale = function _getLocale2(_x2) {
2640
+ return _getLocale.apply(this, arguments);
2641
+ };
2642
+ _ref4$locales = _ref4.locales, locales = _ref4$locales === void 0 ? typeof intlDomLocale !== 'undefined' ? [intlDomLocale] : typeof navigator === 'undefined' ? [] : navigator.languages : _ref4$locales, _ref4$defaultLocales = _ref4.defaultLocales, defaultLocales = _ref4$defaultLocales === void 0 ? ['en-US'] : _ref4$defaultLocales, _ref4$localeResolver = _ref4.localeResolver, localeResolver = _ref4$localeResolver === void 0 ? defaultLocaleResolver : _ref4$localeResolver, _ref4$localesBasePath = _ref4.localesBasePath, localesBasePath = _ref4$localesBasePath === void 0 ? '.' : _ref4$localesBasePath, _ref4$localeMatcher = _ref4.localeMatcher, localeMatcher = _ref4$localeMatcher === void 0 ? 'lookup' : _ref4$localeMatcher, _ref4$headOnly = _ref4.headOnly, headOnly = _ref4$headOnly === void 0 ? false : _ref4$headOnly;
2643
+ /**
2644
+ * @callback getLocale
2645
+ * @throws {SyntaxError|TypeError|Error}
2646
+ * @param {string} locale
2647
+ * @returns {Promise<LocaleObjectInfo|string>}
2648
+ */
2649
+ if (!(localeMatcher === 'lookup')) {
2650
+ _context2.n = 1;
2651
+ break;
2652
+ }
2653
+ localeMatcher = defaultLocaleMatcher;
2654
+ _context2.n = 2;
2655
+ break;
2656
+ case 1:
2657
+ if (!(typeof localeMatcher !== 'function')) {
2658
+ _context2.n = 2;
2659
+ break;
2660
+ }
2661
+ throw new TypeError('`localeMatcher` must be "lookup" or a function!');
2662
+ case 2:
2663
+ _context2.n = 3;
2664
+ return promiseChainForValues([].concat(_toConsumableArray(locales), _toConsumableArray(defaultLocales)), getLocale, 'No matching locale found for ' + [].concat(_toConsumableArray(locales), _toConsumableArray(defaultLocales)).join(', '));
2665
+ case 3:
2666
+ return _context2.a(2, _context2.v);
2667
+ }
2668
+ }, _callee2);
2669
+ }));
2670
+ function _findLocale(_x) {
2671
+ return _findLocale2.apply(this, arguments);
2672
+ }
2673
+ return _findLocale;
2674
+ }();
2675
+
2676
+ /**
2677
+ * @typedef {import('./index.js').Sort} Sort
2678
+ */
2679
+ /**
2680
+ * @typedef {import('./index.js').SortList} SortList
2681
+ */
2682
+ /**
2683
+ * @typedef {import('./index.js').List} List
2684
+ */
2685
+
2686
+ /**
2687
+ * @typedef {import('./index.js').I18NCallback} I18NCallback
2688
+ */
2689
+
2690
+ /**
2691
+ * @param {object} cfg
2692
+ * @param {import('./getMessageForKeyByStyle.js').LocaleObject} cfg.strings
2693
+ * @param {string} cfg.resolvedLocale
2694
+ * @param {"richNested"|"rich"|"plain"|"plainNested"|
2695
+ * import('./getMessageForKeyByStyle.js').
2696
+ * MessageStyleCallback} [cfg.messageStyle]
2697
+ * @param {?import('./defaultAllSubstitutions.js').AllSubstitutionCallback|
2698
+ * import('./defaultAllSubstitutions.js').
2699
+ * AllSubstitutionCallback[]} [cfg.allSubstitutions]
2700
+ * @param {import('./defaultInsertNodes.js').
2701
+ * InsertNodesCallback} [cfg.insertNodes]
2702
+ * @param {import('./defaultKeyCheckerConverter.js').
2703
+ * KeyCheckerConverterCallback} [cfg.keyCheckerConverter]
2704
+ * @param {false|null|undefined|
2705
+ * import('./getMessageForKeyByStyle.js').LocaleObject} [cfg.defaults]
2706
+ * @param {false|import('./defaultLocaleResolver.js').
2707
+ * SubstitutionObject} [cfg.substitutions]
2708
+ * @param {Integer} [cfg.maximumLocalNestingDepth]
2709
+ * @param {boolean} [cfg.dom]
2710
+ * @param {boolean} [cfg.forceNodeReturn]
2711
+ * @param {boolean} [cfg.throwOnMissingSuppliedFormatters]
2712
+ * @param {boolean} [cfg.throwOnExtraSuppliedFormatters]
2713
+ * @returns {I18NCallback} Rejects if no suitable locale is found.
2714
+ */
2715
+ var i18nServer = function i18nServer(_ref) {
2716
+ var strings = _ref.strings,
2717
+ resolvedLocale = _ref.resolvedLocale,
2718
+ _ref$messageStyle = _ref.messageStyle,
2719
+ messageStyle = _ref$messageStyle === void 0 ? 'richNested' : _ref$messageStyle,
2720
+ defaultAllSubstitutionsValue = _ref.allSubstitutions,
2721
+ insertNodes = _ref.insertNodes,
2722
+ _ref$keyCheckerConver = _ref.keyCheckerConverter,
2723
+ keyCheckerConverter = _ref$keyCheckerConver === void 0 ? defaultKeyCheckerConverter : _ref$keyCheckerConver,
2724
+ defaultDefaults = _ref.defaults,
2725
+ defaultSubstitutions = _ref.substitutions,
2726
+ maximumLocalNestingDepth = _ref.maximumLocalNestingDepth,
2727
+ _ref$dom = _ref.dom,
2728
+ domDefaults = _ref$dom === void 0 ? false : _ref$dom,
2729
+ _ref$forceNodeReturn = _ref.forceNodeReturn,
2730
+ forceNodeReturnDefault = _ref$forceNodeReturn === void 0 ? false : _ref$forceNodeReturn,
2731
+ _ref$throwOnMissingSu = _ref.throwOnMissingSuppliedFormatters,
2732
+ throwOnMissingSuppliedFormattersDefault = _ref$throwOnMissingSu === void 0 ? true : _ref$throwOnMissingSu,
2733
+ _ref$throwOnExtraSupp = _ref.throwOnExtraSuppliedFormatters,
2734
+ throwOnExtraSuppliedFormattersDefault = _ref$throwOnExtraSupp === void 0 ? true : _ref$throwOnExtraSupp;
2735
+ if (!strings || _typeof(strings) !== 'object') {
2736
+ throw new TypeError("Locale strings must be an object!");
2737
+ }
2738
+ var messageForKey = getMessageForKeyByStyle({
2739
+ messageStyle: messageStyle
2740
+ });
2741
+
2742
+ /**
2743
+ * @type {I18NCallback}
2744
+ */
2745
+ var formatter = function formatter(key, substitutions) {
2746
+ var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
2747
+ _ref2$allSubstitution = _ref2.allSubstitutions,
2748
+ allSubstitutions = _ref2$allSubstitution === void 0 ? defaultAllSubstitutionsValue : _ref2$allSubstitution,
2749
+ _ref2$defaults = _ref2.defaults,
2750
+ defaults = _ref2$defaults === void 0 ? defaultDefaults : _ref2$defaults,
2751
+ _ref2$dom = _ref2.dom,
2752
+ dom = _ref2$dom === void 0 ? domDefaults : _ref2$dom,
2753
+ _ref2$forceNodeReturn = _ref2.forceNodeReturn,
2754
+ forceNodeReturn = _ref2$forceNodeReturn === void 0 ? forceNodeReturnDefault : _ref2$forceNodeReturn,
2755
+ _ref2$throwOnMissingS = _ref2.throwOnMissingSuppliedFormatters,
2756
+ throwOnMissingSuppliedFormatters = _ref2$throwOnMissingS === void 0 ? throwOnMissingSuppliedFormattersDefault : _ref2$throwOnMissingS,
2757
+ _ref2$throwOnExtraSup = _ref2.throwOnExtraSuppliedFormatters,
2758
+ throwOnExtraSuppliedFormatters = _ref2$throwOnExtraSup === void 0 ? throwOnExtraSuppliedFormattersDefault : _ref2$throwOnExtraSup;
2759
+ key = /** @type {string} */keyCheckerConverter(key, messageStyle);
2760
+ var message = messageForKey(strings, key);
2761
+ var string = getStringFromMessageAndDefaults({
2762
+ message: message && typeof message.value === 'string' ? message.value : false,
2763
+ defaults: defaults,
2764
+ messageForKey: messageForKey,
2765
+ key: key
2766
+ });
2767
+ return getDOMForLocaleString({
2768
+ string: string,
2769
+ locals: strings.head && strings.head.locals,
2770
+ switches: strings.head && strings.head.switches,
2771
+ locale: resolvedLocale,
2772
+ maximumLocalNestingDepth: maximumLocalNestingDepth,
2773
+ allSubstitutions: allSubstitutions,
2774
+ insertNodes: insertNodes,
2775
+ substitutions: _objectSpread2(_objectSpread2({}, defaultSubstitutions), substitutions),
2776
+ dom: dom,
2777
+ forceNodeReturn: forceNodeReturn,
2778
+ throwOnMissingSuppliedFormatters: throwOnMissingSuppliedFormatters,
2779
+ throwOnExtraSuppliedFormatters: throwOnExtraSuppliedFormatters
2780
+ });
2781
+ };
2782
+ formatter.resolvedLocale = resolvedLocale;
2783
+ formatter.strings = strings;
2784
+
2785
+ /** @type {Sort} */
2786
+ formatter.sort = function (arrayOfItems, options) {
2787
+ return sort(resolvedLocale, arrayOfItems, options);
2788
+ };
2789
+
2790
+ /** @type {SortList} */
2791
+ formatter.sortList = function (arrayOfItems, map, listOptions, collationOptions) {
2792
+ return sortList(resolvedLocale, arrayOfItems, map, listOptions, collationOptions);
2793
+ };
2794
+
2795
+ /** @type {List} */
2796
+ formatter.list = function (arrayOfItems, options) {
2797
+ return list(resolvedLocale, arrayOfItems, options);
2798
+ };
2799
+ return formatter;
2800
+ };
2801
+
2802
+ /**
2803
+ * @typedef {number} Integer
2804
+ */
2805
+
2806
+ /**
2807
+ * @param {object} [cfg]
2808
+ * @param {string[]} [cfg.locales] BCP-47 language strings
2809
+ * @param {string[]} [cfg.defaultLocales]
2810
+ * @param {import('./findLocaleStrings.js').
2811
+ * LocaleStringFinder} [cfg.localeStringFinder]
2812
+ * @param {string} [cfg.localesBasePath]
2813
+ * @param {import('./defaultLocaleResolver.js').
2814
+ * LocaleResolver} [cfg.localeResolver]
2815
+ * @param {"lookup"|import('./findLocaleStrings.js').
2816
+ * LocaleMatcher} [cfg.localeMatcher]
2817
+ * @param {"richNested"|"rich"|"plain"|"plainNested"|
2818
+ * import('./getMessageForKeyByStyle.js').
2819
+ * MessageStyleCallback} [cfg.messageStyle]
2820
+ * @param {?(import('./defaultAllSubstitutions.js').AllSubstitutionCallback|
2821
+ * import('./defaultAllSubstitutions.js').
2822
+ * AllSubstitutionCallback[])} [cfg.allSubstitutions]
2823
+ * @param {import('./defaultInsertNodes.js').
2824
+ * InsertNodesCallback} [cfg.insertNodes]
2825
+ * @param {import('./defaultKeyCheckerConverter.js').
2826
+ * KeyCheckerConverterCallback} [cfg.keyCheckerConverter]
2827
+ * @param {false|null|undefined|
2828
+ * import('./getMessageForKeyByStyle.js').LocaleObject} [cfg.defaults]
2829
+ * @param {false|
2830
+ * import('./defaultLocaleResolver.js').
2831
+ * SubstitutionObject} [cfg.substitutions]
2832
+ * @param {Integer} [cfg.maximumLocalNestingDepth]
2833
+ * @param {boolean} [cfg.dom]
2834
+ * @param {boolean} [cfg.forceNodeReturn]
2835
+ * @param {boolean} [cfg.throwOnMissingSuppliedFormatters]
2836
+ * @param {boolean} [cfg.throwOnExtraSuppliedFormatters]
2837
+ * @returns {Promise<I18NCallback>} Rejects if no suitable locale is found.
2838
+ */
2839
+ var i18n = /*#__PURE__*/function () {
2840
+ var _i18n = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
2841
+ var _ref3,
2842
+ locales,
2843
+ defaultLocales,
2844
+ _ref3$localeStringFin,
2845
+ localeStringFinder,
2846
+ localesBasePath,
2847
+ localeResolver,
2848
+ localeMatcher,
2849
+ messageStyle,
2850
+ allSubstitutions,
2851
+ insertNodes,
2852
+ keyCheckerConverter,
2853
+ defaults,
2854
+ substitutions,
2855
+ maximumLocalNestingDepth,
2856
+ dom,
2857
+ forceNodeReturn,
2858
+ throwOnMissingSuppliedFormatters,
2859
+ throwOnExtraSuppliedFormatters,
2860
+ _yield$localeStringFi,
2861
+ strings,
2862
+ resolvedLocale,
2863
+ defaultLocale,
2864
+ _yield$localeStringFi2,
2865
+ _args = arguments;
2866
+ return _regenerator().w(function (_context) {
2867
+ while (1) switch (_context.n) {
2868
+ case 0:
2869
+ _ref3 = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, locales = _ref3.locales, defaultLocales = _ref3.defaultLocales, _ref3$localeStringFin = _ref3.localeStringFinder, localeStringFinder = _ref3$localeStringFin === void 0 ? findLocaleStrings : _ref3$localeStringFin, localesBasePath = _ref3.localesBasePath, localeResolver = _ref3.localeResolver, localeMatcher = _ref3.localeMatcher, messageStyle = _ref3.messageStyle, allSubstitutions = _ref3.allSubstitutions, insertNodes = _ref3.insertNodes, keyCheckerConverter = _ref3.keyCheckerConverter, defaults = _ref3.defaults, substitutions = _ref3.substitutions, maximumLocalNestingDepth = _ref3.maximumLocalNestingDepth, dom = _ref3.dom, forceNodeReturn = _ref3.forceNodeReturn, throwOnMissingSuppliedFormatters = _ref3.throwOnMissingSuppliedFormatters, throwOnExtraSuppliedFormatters = _ref3.throwOnExtraSuppliedFormatters;
2870
+ _context.n = 1;
2871
+ return localeStringFinder({
2872
+ locales: locales,
2873
+ defaultLocales: defaultLocales,
2874
+ localeResolver: localeResolver,
2875
+ localesBasePath: localesBasePath,
2876
+ localeMatcher: localeMatcher
2877
+ });
2878
+ case 1:
2879
+ _yield$localeStringFi = _context.v;
2880
+ strings = _yield$localeStringFi.strings;
2881
+ resolvedLocale = _yield$localeStringFi.locale;
2882
+ if (!(!defaults && defaultLocales)) {
2883
+ _context.n = 3;
2884
+ break;
2885
+ }
2886
+ _context.n = 2;
2887
+ return localeStringFinder({
2888
+ locales: defaultLocales,
2889
+ defaultLocales: [],
2890
+ localeResolver: localeResolver,
2891
+ localesBasePath: localesBasePath,
2892
+ localeMatcher: localeMatcher
2893
+ });
2894
+ case 2:
2895
+ _yield$localeStringFi2 = _context.v;
2896
+ defaults = _yield$localeStringFi2.strings;
2897
+ defaultLocale = _yield$localeStringFi2.locale;
2898
+ if (defaultLocale === resolvedLocale) {
2899
+ defaults = null; // No need to fall back
2900
+ }
2901
+ case 3:
2902
+ return _context.a(2, i18nServer({
2903
+ strings: strings,
2904
+ resolvedLocale: resolvedLocale,
2905
+ messageStyle: messageStyle,
2906
+ allSubstitutions: allSubstitutions,
2907
+ insertNodes: insertNodes,
2908
+ keyCheckerConverter: keyCheckerConverter,
2909
+ defaults: defaults,
2910
+ substitutions: substitutions,
2911
+ maximumLocalNestingDepth: maximumLocalNestingDepth,
2912
+ dom: dom,
2913
+ forceNodeReturn: forceNodeReturn,
2914
+ throwOnMissingSuppliedFormatters: throwOnMissingSuppliedFormatters,
2915
+ throwOnExtraSuppliedFormatters: throwOnExtraSuppliedFormatters
2916
+ }));
2917
+ }
2918
+ }, _callee);
2919
+ }));
2920
+ function i18n() {
2921
+ return _i18n.apply(this, arguments);
2922
+ }
2923
+ return i18n;
2924
+ }();
2925
+
2926
+ exports.Formatter = Formatter;
2927
+ exports.LocalFormatter = LocalFormatter;
2928
+ exports.RegularFormatter = RegularFormatter;
2929
+ exports.SwitchFormatter = SwitchFormatter;
2930
+ exports.defaultAllSubstitutions = defaultAllSubstitutions;
2931
+ exports.defaultInsertNodes = defaultInsertNodes;
2932
+ exports.defaultKeyCheckerConverter = defaultKeyCheckerConverter;
2933
+ exports.defaultLocaleMatcher = defaultLocaleMatcher;
2934
+ exports.defaultLocaleResolver = defaultLocaleResolver;
2935
+ exports.findLocale = findLocale;
2936
+ exports.findLocaleStrings = findLocaleStrings;
2937
+ exports.getDOMForLocaleString = getDOMForLocaleString;
2938
+ exports.getDocument = getDocument;
2939
+ exports.getFetch = getFetch;
2940
+ exports.getMatchingLocale = getMatchingLocale;
2941
+ exports.getMessageForKeyByStyle = getMessageForKeyByStyle;
2942
+ exports.getStringFromMessageAndDefaults = getStringFromMessageAndDefaults;
2943
+ exports.i18n = i18n;
2944
+ exports.i18nServer = i18nServer;
2945
+ exports.parseJSONExtra = parseJSONExtra;
2946
+ exports.processRegex = processRegex;
2947
+ exports.promiseChainForValues = promiseChainForValues;
2948
+ exports.setDocument = setDocument;
2949
+ exports.setFetch = setFetch;
2950
+ exports.setJSONExtra = setJSONExtra;
2951
+ exports.unescapeBackslashes = unescapeBackslashes;
2952
+
2953
+ }));