@fctc/sme-widget-ui 4.1.10-beta.0 → 4.1.10-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.js ADDED
@@ -0,0 +1,3611 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // node_modules/void-elements/index.js
34
+ var require_void_elements = __commonJS({
35
+ "node_modules/void-elements/index.js"(exports2, module2) {
36
+ "use strict";
37
+ module2.exports = {
38
+ "area": true,
39
+ "base": true,
40
+ "br": true,
41
+ "col": true,
42
+ "embed": true,
43
+ "hr": true,
44
+ "img": true,
45
+ "input": true,
46
+ "link": true,
47
+ "meta": true,
48
+ "param": true,
49
+ "source": true,
50
+ "track": true,
51
+ "wbr": true
52
+ };
53
+ }
54
+ });
55
+
56
+ // src/utils.ts
57
+ var utils_exports = {};
58
+ __export(utils_exports, {
59
+ ACCEPT_TYPES: () => ACCEPT_TYPES,
60
+ ALLOWED_EXTS: () => ALLOWED_EXTS,
61
+ ALLOWED_MIME_TYPES: () => ALLOWED_MIME_TYPES,
62
+ COLORS: () => COLORS,
63
+ DOTS: () => DOTS,
64
+ SearchType: () => SearchType,
65
+ checkIsImageLink: () => checkIsImageLink,
66
+ convertFloatToTime: () => convertFloatToTime,
67
+ convertTimeToFloat: () => convertTimeToFloat,
68
+ formatFileSize: () => formatFileSize,
69
+ formatFloatNumber: () => formatFloatNumber,
70
+ formatNumberOnly: () => formatNumberOnly,
71
+ generateTagColors: () => generateTagColors,
72
+ getFileLabel: () => getFileLabel,
73
+ getPasswordMessage: () => getPasswordMessage,
74
+ isBase64Image: () => isBase64Image,
75
+ parseFormattedNumber: () => parseFormattedNumber,
76
+ range: () => range,
77
+ uppercaseFirstLetter: () => uppercaseFirstLetter,
78
+ useFormatDate: () => useFormatDate,
79
+ validateAndParseDate: () => validateAndParseDate,
80
+ validateInput: () => validateInput
81
+ });
82
+ module.exports = __toCommonJS(utils_exports);
83
+
84
+ // src/utils/file.ts
85
+ var isBase64Image = (str) => {
86
+ const base64Regex = /^data:image\/(png|jpeg|jpg|gif|webp);base64,/;
87
+ if (!base64Regex.test(str)) {
88
+ return false;
89
+ }
90
+ try {
91
+ const base64Data = str.split(",")[1];
92
+ return !!base64Data && atob(base64Data).length > 0;
93
+ } catch (error) {
94
+ return false;
95
+ }
96
+ };
97
+ var checkIsImageLink = (url) => {
98
+ const imageExtensions = /\.(jpg|jpeg|png|gif|bmp|webp|svg|tiff|ico)$/i;
99
+ return imageExtensions.test(url) || isBase64Image(url);
100
+ };
101
+ var formatFileSize = (size) => {
102
+ if (size < 1024) return `${size} B`;
103
+ const i = Math.floor(Math.log(size) / Math.log(1024));
104
+ const sizes = ["B", "KB", "MB", "GB", "TB"];
105
+ return `${(size / Math.pow(1024, i)).toFixed(2)} ${sizes[i]}`;
106
+ };
107
+ var getFileLabel = (name) => {
108
+ const ext = (name?.split(".").pop() || "").toLowerCase();
109
+ if (ext === "pdf") return "PDF";
110
+ if (ext === "json") return "JSON";
111
+ if (ext === "zip") return "ZIP";
112
+ if (ext === "mp4") return "MP4";
113
+ if (ext === "xls" || ext === "xlsx") return "XLS";
114
+ if (ext === "png" || ext === "jpg" || ext === "jpeg") return "IMG";
115
+ return "FILE";
116
+ };
117
+ var ALLOWED_MIME_TYPES = /* @__PURE__ */ new Set([
118
+ "image/jpeg",
119
+ "image/png",
120
+ "application/pdf",
121
+ "video/mp4",
122
+ "application/zip",
123
+ "application/x-zip-compressed",
124
+ "application/vnd.ms-excel",
125
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
126
+ "application/json"
127
+ ]);
128
+ var ALLOWED_EXTS = [
129
+ ".pdf",
130
+ ".json",
131
+ ".mp4",
132
+ ".zip",
133
+ ".xls",
134
+ ".xlsx",
135
+ ".jpeg",
136
+ ".jpg",
137
+ ".png"
138
+ ];
139
+ var ACCEPT_TYPES = [
140
+ ...ALLOWED_EXTS,
141
+ ...Array.from(ALLOWED_MIME_TYPES)
142
+ ].join(",");
143
+
144
+ // src/utils/number.ts
145
+ var formatNumberOnly = (num) => {
146
+ if (isNaN(num)) return "";
147
+ return num?.toString()?.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
148
+ };
149
+ var parseFormattedNumber = (val) => {
150
+ if (!val) return "0";
151
+ const raw = val.replace(/[^\d]/g, "");
152
+ return raw ? parseFloat(raw) : "";
153
+ };
154
+ var convertFloatToTime = (floatValue) => {
155
+ const hours = Math.floor(floatValue);
156
+ const minutes = Math.round((floatValue - hours) * 60);
157
+ const formattedHours = String(hours).padStart(2, "0");
158
+ const formattedMinutes = String(minutes).padStart(2, "0");
159
+ return `${formattedHours}:${formattedMinutes}`;
160
+ };
161
+ var convertTimeToFloat = (timeString) => {
162
+ const [hours, minutes] = timeString.split(":").map(Number);
163
+ return hours + minutes / 60;
164
+ };
165
+ var formatFloatNumber = (value) => {
166
+ if (value === void 0 || value === null || value === "") return "";
167
+ const numValue = typeof value === "string" ? parseFloat(value.replace(/,/g, "")) : value;
168
+ if (isNaN(numValue)) return "";
169
+ return numValue.toLocaleString("en-US", {
170
+ minimumFractionDigits: numValue % 1 === 0 ? 0 : 1,
171
+ maximumFractionDigits: 20
172
+ });
173
+ };
174
+
175
+ // src/utils/string.ts
176
+ function validateInput(value, type) {
177
+ if (type === "text") {
178
+ return /^[\p{L}\s]+$/u.test(value);
179
+ }
180
+ if (type === "number") {
181
+ return /^[0-9]+$/.test(value);
182
+ }
183
+ if (type === "email") {
184
+ return /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
185
+ }
186
+ if (type === "phone") {
187
+ return /^(0|\+?84)[0-9]{9}$/.test(value);
188
+ }
189
+ return false;
190
+ }
191
+ function getPasswordMessage(min, max, upcase, digit, special) {
192
+ let message = `M?t kh?u ph?i c\uFFFD t? ${min} d?n ${max} k\uFFFD t?`;
193
+ if (upcase || upcase === "0") {
194
+ message += `, ${upcase} ch? in hoa`;
195
+ }
196
+ if (digit || digit === "0") {
197
+ message += `, ${digit} s?`;
198
+ }
199
+ if (special || special === "0") {
200
+ message += `, ${special} k\uFFFD t? d?c bi?t`;
201
+ }
202
+ return message;
203
+ }
204
+ var uppercaseFirstLetter = (str) => {
205
+ const strLowerCase = str?.toLowerCase();
206
+ return strLowerCase.charAt(0).toUpperCase() + strLowerCase.slice(1);
207
+ };
208
+
209
+ // src/utils/array.ts
210
+ var range = (start, end) => {
211
+ let length = end - start + 1;
212
+ return Array.from({ length }, (_, idx) => idx + start);
213
+ };
214
+
215
+ // src/utils/date.ts
216
+ var import_moment = __toESM(require("moment"));
217
+
218
+ // src/provider/index.tsx
219
+ var import_react9 = require("react");
220
+
221
+ // node_modules/react-i18next/dist/es/Trans.js
222
+ var import_react3 = require("react");
223
+
224
+ // node_modules/react-i18next/dist/es/TransWithoutContext.js
225
+ var import_react = require("react");
226
+
227
+ // node_modules/html-parse-stringify/dist/html-parse-stringify.module.js
228
+ var import_void_elements = __toESM(require_void_elements());
229
+
230
+ // node_modules/react-i18next/dist/es/unescape.js
231
+ var matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
232
+ var htmlEntities = {
233
+ "&amp;": "&",
234
+ "&#38;": "&",
235
+ "&lt;": "<",
236
+ "&#60;": "<",
237
+ "&gt;": ">",
238
+ "&#62;": ">",
239
+ "&apos;": "'",
240
+ "&#39;": "'",
241
+ "&quot;": '"',
242
+ "&#34;": '"',
243
+ "&nbsp;": " ",
244
+ "&#160;": " ",
245
+ "&copy;": "\xA9",
246
+ "&#169;": "\xA9",
247
+ "&reg;": "\xAE",
248
+ "&#174;": "\xAE",
249
+ "&hellip;": "\u2026",
250
+ "&#8230;": "\u2026",
251
+ "&#x2F;": "/",
252
+ "&#47;": "/"
253
+ };
254
+ var unescapeHtmlEntity = (m) => htmlEntities[m];
255
+ var unescape = (text) => text.replace(matchHtmlEntity, unescapeHtmlEntity);
256
+
257
+ // node_modules/react-i18next/dist/es/defaults.js
258
+ var defaultOptions = {
259
+ bindI18n: "languageChanged",
260
+ bindI18nStore: "",
261
+ transEmptyNodeValue: "",
262
+ transSupportBasicHtmlNodes: true,
263
+ transWrapTextNodes: "",
264
+ transKeepBasicHtmlNodesFor: ["br", "strong", "i", "p"],
265
+ useSuspense: true,
266
+ unescape
267
+ };
268
+ var setDefaults = (options = {}) => {
269
+ defaultOptions = {
270
+ ...defaultOptions,
271
+ ...options
272
+ };
273
+ };
274
+
275
+ // node_modules/react-i18next/dist/es/i18nInstance.js
276
+ var i18nInstance;
277
+ var setI18n = (instance2) => {
278
+ i18nInstance = instance2;
279
+ };
280
+
281
+ // node_modules/react-i18next/dist/es/context.js
282
+ var import_react2 = require("react");
283
+
284
+ // node_modules/react-i18next/dist/es/initReactI18next.js
285
+ var initReactI18next = {
286
+ type: "3rdParty",
287
+ init(instance2) {
288
+ setDefaults(instance2.options.react);
289
+ setI18n(instance2);
290
+ }
291
+ };
292
+
293
+ // node_modules/react-i18next/dist/es/context.js
294
+ var I18nContext = (0, import_react2.createContext)();
295
+
296
+ // node_modules/react-i18next/dist/es/useTranslation.js
297
+ var import_react4 = require("react");
298
+
299
+ // node_modules/react-i18next/dist/es/withTranslation.js
300
+ var import_react5 = require("react");
301
+
302
+ // node_modules/react-i18next/dist/es/I18nextProvider.js
303
+ var import_react6 = require("react");
304
+
305
+ // node_modules/react-i18next/dist/es/withSSR.js
306
+ var import_react8 = require("react");
307
+
308
+ // node_modules/react-i18next/dist/es/useSSR.js
309
+ var import_react7 = require("react");
310
+
311
+ // node_modules/i18next/dist/esm/i18next.js
312
+ var isString2 = (obj) => typeof obj === "string";
313
+ var defer = () => {
314
+ let res;
315
+ let rej;
316
+ const promise = new Promise((resolve, reject) => {
317
+ res = resolve;
318
+ rej = reject;
319
+ });
320
+ promise.resolve = res;
321
+ promise.reject = rej;
322
+ return promise;
323
+ };
324
+ var makeString = (object) => {
325
+ if (object == null) return "";
326
+ return "" + object;
327
+ };
328
+ var copy = (a, s, t2) => {
329
+ a.forEach((m) => {
330
+ if (s[m]) t2[m] = s[m];
331
+ });
332
+ };
333
+ var lastOfPathSeparatorRegExp = /###/g;
334
+ var cleanKey = (key) => key && key.indexOf("###") > -1 ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
335
+ var canNotTraverseDeeper = (object) => !object || isString2(object);
336
+ var getLastOfPath = (object, path2, Empty) => {
337
+ const stack = !isString2(path2) ? path2 : path2.split(".");
338
+ let stackIndex = 0;
339
+ while (stackIndex < stack.length - 1) {
340
+ if (canNotTraverseDeeper(object)) return {};
341
+ const key = cleanKey(stack[stackIndex]);
342
+ if (!object[key] && Empty) object[key] = new Empty();
343
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
344
+ object = object[key];
345
+ } else {
346
+ object = {};
347
+ }
348
+ ++stackIndex;
349
+ }
350
+ if (canNotTraverseDeeper(object)) return {};
351
+ return {
352
+ obj: object,
353
+ k: cleanKey(stack[stackIndex])
354
+ };
355
+ };
356
+ var setPath = (object, path2, newValue) => {
357
+ const {
358
+ obj,
359
+ k
360
+ } = getLastOfPath(object, path2, Object);
361
+ if (obj !== void 0 || path2.length === 1) {
362
+ obj[k] = newValue;
363
+ return;
364
+ }
365
+ let e2 = path2[path2.length - 1];
366
+ let p = path2.slice(0, path2.length - 1);
367
+ let last = getLastOfPath(object, p, Object);
368
+ while (last.obj === void 0 && p.length) {
369
+ e2 = `${p[p.length - 1]}.${e2}`;
370
+ p = p.slice(0, p.length - 1);
371
+ last = getLastOfPath(object, p, Object);
372
+ if (last?.obj && typeof last.obj[`${last.k}.${e2}`] !== "undefined") {
373
+ last.obj = void 0;
374
+ }
375
+ }
376
+ last.obj[`${last.k}.${e2}`] = newValue;
377
+ };
378
+ var pushPath = (object, path2, newValue, concat) => {
379
+ const {
380
+ obj,
381
+ k
382
+ } = getLastOfPath(object, path2, Object);
383
+ obj[k] = obj[k] || [];
384
+ obj[k].push(newValue);
385
+ };
386
+ var getPath = (object, path2) => {
387
+ const {
388
+ obj,
389
+ k
390
+ } = getLastOfPath(object, path2);
391
+ if (!obj) return void 0;
392
+ if (!Object.prototype.hasOwnProperty.call(obj, k)) return void 0;
393
+ return obj[k];
394
+ };
395
+ var getPathWithDefaults = (data, defaultData, key) => {
396
+ const value = getPath(data, key);
397
+ if (value !== void 0) {
398
+ return value;
399
+ }
400
+ return getPath(defaultData, key);
401
+ };
402
+ var deepExtend = (target, source, overwrite) => {
403
+ for (const prop in source) {
404
+ if (prop !== "__proto__" && prop !== "constructor") {
405
+ if (prop in target) {
406
+ if (isString2(target[prop]) || target[prop] instanceof String || isString2(source[prop]) || source[prop] instanceof String) {
407
+ if (overwrite) target[prop] = source[prop];
408
+ } else {
409
+ deepExtend(target[prop], source[prop], overwrite);
410
+ }
411
+ } else {
412
+ target[prop] = source[prop];
413
+ }
414
+ }
415
+ }
416
+ return target;
417
+ };
418
+ var regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
419
+ var _entityMap = {
420
+ "&": "&amp;",
421
+ "<": "&lt;",
422
+ ">": "&gt;",
423
+ '"': "&quot;",
424
+ "'": "&#39;",
425
+ "/": "&#x2F;"
426
+ };
427
+ var escape = (data) => {
428
+ if (isString2(data)) {
429
+ return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
430
+ }
431
+ return data;
432
+ };
433
+ var RegExpCache = class {
434
+ constructor(capacity) {
435
+ this.capacity = capacity;
436
+ this.regExpMap = /* @__PURE__ */ new Map();
437
+ this.regExpQueue = [];
438
+ }
439
+ getRegExp(pattern) {
440
+ const regExpFromCache = this.regExpMap.get(pattern);
441
+ if (regExpFromCache !== void 0) {
442
+ return regExpFromCache;
443
+ }
444
+ const regExpNew = new RegExp(pattern);
445
+ if (this.regExpQueue.length === this.capacity) {
446
+ this.regExpMap.delete(this.regExpQueue.shift());
447
+ }
448
+ this.regExpMap.set(pattern, regExpNew);
449
+ this.regExpQueue.push(pattern);
450
+ return regExpNew;
451
+ }
452
+ };
453
+ var chars = [" ", ",", "?", "!", ";"];
454
+ var looksLikeObjectPathRegExpCache = new RegExpCache(20);
455
+ var looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
456
+ nsSeparator = nsSeparator || "";
457
+ keySeparator = keySeparator || "";
458
+ const possibleChars = chars.filter((c) => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
459
+ if (possibleChars.length === 0) return true;
460
+ const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
461
+ let matched = !r.test(key);
462
+ if (!matched) {
463
+ const ki = key.indexOf(keySeparator);
464
+ if (ki > 0 && !r.test(key.substring(0, ki))) {
465
+ matched = true;
466
+ }
467
+ }
468
+ return matched;
469
+ };
470
+ var deepFind = function(obj, path2) {
471
+ let keySeparator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ".";
472
+ if (!obj) return void 0;
473
+ if (obj[path2]) {
474
+ if (!Object.prototype.hasOwnProperty.call(obj, path2)) return void 0;
475
+ return obj[path2];
476
+ }
477
+ const tokens = path2.split(keySeparator);
478
+ let current = obj;
479
+ for (let i = 0; i < tokens.length; ) {
480
+ if (!current || typeof current !== "object") {
481
+ return void 0;
482
+ }
483
+ let next;
484
+ let nextPath = "";
485
+ for (let j = i; j < tokens.length; ++j) {
486
+ if (j !== i) {
487
+ nextPath += keySeparator;
488
+ }
489
+ nextPath += tokens[j];
490
+ next = current[nextPath];
491
+ if (next !== void 0) {
492
+ if (["string", "number", "boolean"].indexOf(typeof next) > -1 && j < tokens.length - 1) {
493
+ continue;
494
+ }
495
+ i += j - i + 1;
496
+ break;
497
+ }
498
+ }
499
+ current = next;
500
+ }
501
+ return current;
502
+ };
503
+ var getCleanedCode = (code) => code?.replace("_", "-");
504
+ var consoleLogger = {
505
+ type: "logger",
506
+ log(args) {
507
+ this.output("log", args);
508
+ },
509
+ warn(args) {
510
+ this.output("warn", args);
511
+ },
512
+ error(args) {
513
+ this.output("error", args);
514
+ },
515
+ output(type, args) {
516
+ console?.[type]?.apply?.(console, args);
517
+ }
518
+ };
519
+ var Logger = class _Logger {
520
+ constructor(concreteLogger) {
521
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
522
+ this.init(concreteLogger, options);
523
+ }
524
+ init(concreteLogger) {
525
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
526
+ this.prefix = options.prefix || "i18next:";
527
+ this.logger = concreteLogger || consoleLogger;
528
+ this.options = options;
529
+ this.debug = options.debug;
530
+ }
531
+ log() {
532
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
533
+ args[_key] = arguments[_key];
534
+ }
535
+ return this.forward(args, "log", "", true);
536
+ }
537
+ warn() {
538
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
539
+ args[_key2] = arguments[_key2];
540
+ }
541
+ return this.forward(args, "warn", "", true);
542
+ }
543
+ error() {
544
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
545
+ args[_key3] = arguments[_key3];
546
+ }
547
+ return this.forward(args, "error", "");
548
+ }
549
+ deprecate() {
550
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
551
+ args[_key4] = arguments[_key4];
552
+ }
553
+ return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
554
+ }
555
+ forward(args, lvl, prefix, debugOnly) {
556
+ if (debugOnly && !this.debug) return null;
557
+ if (isString2(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
558
+ return this.logger[lvl](args);
559
+ }
560
+ create(moduleName) {
561
+ return new _Logger(this.logger, {
562
+ ...{
563
+ prefix: `${this.prefix}:${moduleName}:`
564
+ },
565
+ ...this.options
566
+ });
567
+ }
568
+ clone(options) {
569
+ options = options || this.options;
570
+ options.prefix = options.prefix || this.prefix;
571
+ return new _Logger(this.logger, options);
572
+ }
573
+ };
574
+ var baseLogger = new Logger();
575
+ var EventEmitter = class {
576
+ constructor() {
577
+ this.observers = {};
578
+ }
579
+ on(events, listener) {
580
+ events.split(" ").forEach((event) => {
581
+ if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
582
+ const numListeners = this.observers[event].get(listener) || 0;
583
+ this.observers[event].set(listener, numListeners + 1);
584
+ });
585
+ return this;
586
+ }
587
+ off(event, listener) {
588
+ if (!this.observers[event]) return;
589
+ if (!listener) {
590
+ delete this.observers[event];
591
+ return;
592
+ }
593
+ this.observers[event].delete(listener);
594
+ }
595
+ emit(event) {
596
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
597
+ args[_key - 1] = arguments[_key];
598
+ }
599
+ if (this.observers[event]) {
600
+ const cloned = Array.from(this.observers[event].entries());
601
+ cloned.forEach((_ref) => {
602
+ let [observer, numTimesAdded] = _ref;
603
+ for (let i = 0; i < numTimesAdded; i++) {
604
+ observer(...args);
605
+ }
606
+ });
607
+ }
608
+ if (this.observers["*"]) {
609
+ const cloned = Array.from(this.observers["*"].entries());
610
+ cloned.forEach((_ref2) => {
611
+ let [observer, numTimesAdded] = _ref2;
612
+ for (let i = 0; i < numTimesAdded; i++) {
613
+ observer.apply(observer, [event, ...args]);
614
+ }
615
+ });
616
+ }
617
+ }
618
+ };
619
+ var ResourceStore = class extends EventEmitter {
620
+ constructor(data) {
621
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
622
+ ns: ["translation"],
623
+ defaultNS: "translation"
624
+ };
625
+ super();
626
+ this.data = data || {};
627
+ this.options = options;
628
+ if (this.options.keySeparator === void 0) {
629
+ this.options.keySeparator = ".";
630
+ }
631
+ if (this.options.ignoreJSONStructure === void 0) {
632
+ this.options.ignoreJSONStructure = true;
633
+ }
634
+ }
635
+ addNamespaces(ns) {
636
+ if (this.options.ns.indexOf(ns) < 0) {
637
+ this.options.ns.push(ns);
638
+ }
639
+ }
640
+ removeNamespaces(ns) {
641
+ const index = this.options.ns.indexOf(ns);
642
+ if (index > -1) {
643
+ this.options.ns.splice(index, 1);
644
+ }
645
+ }
646
+ getResource(lng, ns, key) {
647
+ let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
648
+ const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
649
+ const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
650
+ let path2;
651
+ if (lng.indexOf(".") > -1) {
652
+ path2 = lng.split(".");
653
+ } else {
654
+ path2 = [lng, ns];
655
+ if (key) {
656
+ if (Array.isArray(key)) {
657
+ path2.push(...key);
658
+ } else if (isString2(key) && keySeparator) {
659
+ path2.push(...key.split(keySeparator));
660
+ } else {
661
+ path2.push(key);
662
+ }
663
+ }
664
+ }
665
+ const result = getPath(this.data, path2);
666
+ if (!result && !ns && !key && lng.indexOf(".") > -1) {
667
+ lng = path2[0];
668
+ ns = path2[1];
669
+ key = path2.slice(2).join(".");
670
+ }
671
+ if (result || !ignoreJSONStructure || !isString2(key)) return result;
672
+ return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
673
+ }
674
+ addResource(lng, ns, key, value) {
675
+ let options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
676
+ silent: false
677
+ };
678
+ const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
679
+ let path2 = [lng, ns];
680
+ if (key) path2 = path2.concat(keySeparator ? key.split(keySeparator) : key);
681
+ if (lng.indexOf(".") > -1) {
682
+ path2 = lng.split(".");
683
+ value = ns;
684
+ ns = path2[1];
685
+ }
686
+ this.addNamespaces(ns);
687
+ setPath(this.data, path2, value);
688
+ if (!options.silent) this.emit("added", lng, ns, key, value);
689
+ }
690
+ addResources(lng, ns, resources) {
691
+ let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {
692
+ silent: false
693
+ };
694
+ for (const m in resources) {
695
+ if (isString2(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
696
+ silent: true
697
+ });
698
+ }
699
+ if (!options.silent) this.emit("added", lng, ns, resources);
700
+ }
701
+ addResourceBundle(lng, ns, resources, deep, overwrite) {
702
+ let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {
703
+ silent: false,
704
+ skipCopy: false
705
+ };
706
+ let path2 = [lng, ns];
707
+ if (lng.indexOf(".") > -1) {
708
+ path2 = lng.split(".");
709
+ deep = resources;
710
+ resources = ns;
711
+ ns = path2[1];
712
+ }
713
+ this.addNamespaces(ns);
714
+ let pack = getPath(this.data, path2) || {};
715
+ if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
716
+ if (deep) {
717
+ deepExtend(pack, resources, overwrite);
718
+ } else {
719
+ pack = {
720
+ ...pack,
721
+ ...resources
722
+ };
723
+ }
724
+ setPath(this.data, path2, pack);
725
+ if (!options.silent) this.emit("added", lng, ns, resources);
726
+ }
727
+ removeResourceBundle(lng, ns) {
728
+ if (this.hasResourceBundle(lng, ns)) {
729
+ delete this.data[lng][ns];
730
+ }
731
+ this.removeNamespaces(ns);
732
+ this.emit("removed", lng, ns);
733
+ }
734
+ hasResourceBundle(lng, ns) {
735
+ return this.getResource(lng, ns) !== void 0;
736
+ }
737
+ getResourceBundle(lng, ns) {
738
+ if (!ns) ns = this.options.defaultNS;
739
+ return this.getResource(lng, ns);
740
+ }
741
+ getDataByLanguage(lng) {
742
+ return this.data[lng];
743
+ }
744
+ hasLanguageSomeTranslations(lng) {
745
+ const data = this.getDataByLanguage(lng);
746
+ const n = data && Object.keys(data) || [];
747
+ return !!n.find((v) => data[v] && Object.keys(data[v]).length > 0);
748
+ }
749
+ toJSON() {
750
+ return this.data;
751
+ }
752
+ };
753
+ var postProcessor = {
754
+ processors: {},
755
+ addPostProcessor(module2) {
756
+ this.processors[module2.name] = module2;
757
+ },
758
+ handle(processors, value, key, options, translator) {
759
+ processors.forEach((processor) => {
760
+ value = this.processors[processor]?.process(value, key, options, translator) ?? value;
761
+ });
762
+ return value;
763
+ }
764
+ };
765
+ var checkedLoadedFor = {};
766
+ var shouldHandleAsObject = (res) => !isString2(res) && typeof res !== "boolean" && typeof res !== "number";
767
+ var Translator = class _Translator extends EventEmitter {
768
+ constructor(services) {
769
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
770
+ super();
771
+ copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
772
+ this.options = options;
773
+ if (this.options.keySeparator === void 0) {
774
+ this.options.keySeparator = ".";
775
+ }
776
+ this.logger = baseLogger.create("translator");
777
+ }
778
+ changeLanguage(lng) {
779
+ if (lng) this.language = lng;
780
+ }
781
+ exists(key) {
782
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
783
+ interpolation: {}
784
+ };
785
+ if (key == null) {
786
+ return false;
787
+ }
788
+ const resolved = this.resolve(key, options);
789
+ return resolved?.res !== void 0;
790
+ }
791
+ extractFromKey(key, options) {
792
+ let nsSeparator = options.nsSeparator !== void 0 ? options.nsSeparator : this.options.nsSeparator;
793
+ if (nsSeparator === void 0) nsSeparator = ":";
794
+ const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
795
+ let namespaces = options.ns || this.options.defaultNS || [];
796
+ const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
797
+ const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
798
+ if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
799
+ const m = key.match(this.interpolator.nestingRegexp);
800
+ if (m && m.length > 0) {
801
+ return {
802
+ key,
803
+ namespaces: isString2(namespaces) ? [namespaces] : namespaces
804
+ };
805
+ }
806
+ const parts = key.split(nsSeparator);
807
+ if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
808
+ key = parts.join(keySeparator);
809
+ }
810
+ return {
811
+ key,
812
+ namespaces: isString2(namespaces) ? [namespaces] : namespaces
813
+ };
814
+ }
815
+ translate(keys, options, lastKey) {
816
+ if (typeof options !== "object" && this.options.overloadTranslationOptionHandler) {
817
+ options = this.options.overloadTranslationOptionHandler(arguments);
818
+ }
819
+ if (typeof options === "object") options = {
820
+ ...options
821
+ };
822
+ if (!options) options = {};
823
+ if (keys == null) return "";
824
+ if (!Array.isArray(keys)) keys = [String(keys)];
825
+ const returnDetails = options.returnDetails !== void 0 ? options.returnDetails : this.options.returnDetails;
826
+ const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
827
+ const {
828
+ key,
829
+ namespaces
830
+ } = this.extractFromKey(keys[keys.length - 1], options);
831
+ const namespace = namespaces[namespaces.length - 1];
832
+ const lng = options.lng || this.language;
833
+ const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
834
+ if (lng?.toLowerCase() === "cimode") {
835
+ if (appendNamespaceToCIMode) {
836
+ const nsSeparator = options.nsSeparator || this.options.nsSeparator;
837
+ if (returnDetails) {
838
+ return {
839
+ res: `${namespace}${nsSeparator}${key}`,
840
+ usedKey: key,
841
+ exactUsedKey: key,
842
+ usedLng: lng,
843
+ usedNS: namespace,
844
+ usedParams: this.getUsedParamsDetails(options)
845
+ };
846
+ }
847
+ return `${namespace}${nsSeparator}${key}`;
848
+ }
849
+ if (returnDetails) {
850
+ return {
851
+ res: key,
852
+ usedKey: key,
853
+ exactUsedKey: key,
854
+ usedLng: lng,
855
+ usedNS: namespace,
856
+ usedParams: this.getUsedParamsDetails(options)
857
+ };
858
+ }
859
+ return key;
860
+ }
861
+ const resolved = this.resolve(keys, options);
862
+ let res = resolved?.res;
863
+ const resUsedKey = resolved?.usedKey || key;
864
+ const resExactUsedKey = resolved?.exactUsedKey || key;
865
+ const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
866
+ const joinArrays = options.joinArrays !== void 0 ? options.joinArrays : this.options.joinArrays;
867
+ const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
868
+ const needsPluralHandling = options.count !== void 0 && !isString2(options.count);
869
+ const hasDefaultValue = _Translator.hasDefaultValue(options);
870
+ const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : "";
871
+ const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
872
+ ordinal: false
873
+ }) : "";
874
+ const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0;
875
+ const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
876
+ let resForObjHndl = res;
877
+ if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
878
+ resForObjHndl = defaultValue;
879
+ }
880
+ const handleAsObject = shouldHandleAsObject(resForObjHndl);
881
+ const resType = Object.prototype.toString.apply(resForObjHndl);
882
+ if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString2(joinArrays) && Array.isArray(resForObjHndl))) {
883
+ if (!options.returnObjects && !this.options.returnObjects) {
884
+ if (!this.options.returnedObjectHandler) {
885
+ this.logger.warn("accessing an object - but returnObjects options is not enabled!");
886
+ }
887
+ const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
888
+ ...options,
889
+ ns: namespaces
890
+ }) : `key '${key} (${this.language})' returned an object instead of string.`;
891
+ if (returnDetails) {
892
+ resolved.res = r;
893
+ resolved.usedParams = this.getUsedParamsDetails(options);
894
+ return resolved;
895
+ }
896
+ return r;
897
+ }
898
+ if (keySeparator) {
899
+ const resTypeIsArray = Array.isArray(resForObjHndl);
900
+ const copy2 = resTypeIsArray ? [] : {};
901
+ const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
902
+ for (const m in resForObjHndl) {
903
+ if (Object.prototype.hasOwnProperty.call(resForObjHndl, m)) {
904
+ const deepKey = `${newKeyToUse}${keySeparator}${m}`;
905
+ if (hasDefaultValue && !res) {
906
+ copy2[m] = this.translate(deepKey, {
907
+ ...options,
908
+ defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : void 0,
909
+ ...{
910
+ joinArrays: false,
911
+ ns: namespaces
912
+ }
913
+ });
914
+ } else {
915
+ copy2[m] = this.translate(deepKey, {
916
+ ...options,
917
+ ...{
918
+ joinArrays: false,
919
+ ns: namespaces
920
+ }
921
+ });
922
+ }
923
+ if (copy2[m] === deepKey) copy2[m] = resForObjHndl[m];
924
+ }
925
+ }
926
+ res = copy2;
927
+ }
928
+ } else if (handleAsObjectInI18nFormat && isString2(joinArrays) && Array.isArray(res)) {
929
+ res = res.join(joinArrays);
930
+ if (res) res = this.extendTranslation(res, keys, options, lastKey);
931
+ } else {
932
+ let usedDefault = false;
933
+ let usedKey = false;
934
+ if (!this.isValidLookup(res) && hasDefaultValue) {
935
+ usedDefault = true;
936
+ res = defaultValue;
937
+ }
938
+ if (!this.isValidLookup(res)) {
939
+ usedKey = true;
940
+ res = key;
941
+ }
942
+ const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
943
+ const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
944
+ const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
945
+ if (usedKey || usedDefault || updateMissing) {
946
+ this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
947
+ if (keySeparator) {
948
+ const fk = this.resolve(key, {
949
+ ...options,
950
+ keySeparator: false
951
+ });
952
+ if (fk && fk.res) this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
953
+ }
954
+ let lngs = [];
955
+ const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
956
+ if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
957
+ for (let i = 0; i < fallbackLngs.length; i++) {
958
+ lngs.push(fallbackLngs[i]);
959
+ }
960
+ } else if (this.options.saveMissingTo === "all") {
961
+ lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
962
+ } else {
963
+ lngs.push(options.lng || this.language);
964
+ }
965
+ const send = (l, k, specificDefaultValue) => {
966
+ const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
967
+ if (this.options.missingKeyHandler) {
968
+ this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
969
+ } else if (this.backendConnector?.saveMissing) {
970
+ this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
971
+ }
972
+ this.emit("missingKey", l, namespace, k, res);
973
+ };
974
+ if (this.options.saveMissing) {
975
+ if (this.options.saveMissingPlurals && needsPluralHandling) {
976
+ lngs.forEach((language) => {
977
+ const suffixes = this.pluralResolver.getSuffixes(language, options);
978
+ if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
979
+ suffixes.push(`${this.options.pluralSeparator}zero`);
980
+ }
981
+ suffixes.forEach((suffix) => {
982
+ send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
983
+ });
984
+ });
985
+ } else {
986
+ send(lngs, key, defaultValue);
987
+ }
988
+ }
989
+ }
990
+ res = this.extendTranslation(res, keys, options, resolved, lastKey);
991
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
992
+ if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
993
+ res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : void 0);
994
+ }
995
+ }
996
+ if (returnDetails) {
997
+ resolved.res = res;
998
+ resolved.usedParams = this.getUsedParamsDetails(options);
999
+ return resolved;
1000
+ }
1001
+ return res;
1002
+ }
1003
+ extendTranslation(res, key, options, resolved, lastKey) {
1004
+ var _this = this;
1005
+ if (this.i18nFormat?.parse) {
1006
+ res = this.i18nFormat.parse(res, {
1007
+ ...this.options.interpolation.defaultVariables,
1008
+ ...options
1009
+ }, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
1010
+ resolved
1011
+ });
1012
+ } else if (!options.skipInterpolation) {
1013
+ if (options.interpolation) this.interpolator.init({
1014
+ ...options,
1015
+ ...{
1016
+ interpolation: {
1017
+ ...this.options.interpolation,
1018
+ ...options.interpolation
1019
+ }
1020
+ }
1021
+ });
1022
+ const skipOnVariables = isString2(res) && (options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
1023
+ let nestBef;
1024
+ if (skipOnVariables) {
1025
+ const nb = res.match(this.interpolator.nestingRegexp);
1026
+ nestBef = nb && nb.length;
1027
+ }
1028
+ let data = options.replace && !isString2(options.replace) ? options.replace : options;
1029
+ if (this.options.interpolation.defaultVariables) data = {
1030
+ ...this.options.interpolation.defaultVariables,
1031
+ ...data
1032
+ };
1033
+ res = this.interpolator.interpolate(res, data, options.lng || this.language || resolved.usedLng, options);
1034
+ if (skipOnVariables) {
1035
+ const na = res.match(this.interpolator.nestingRegexp);
1036
+ const nestAft = na && na.length;
1037
+ if (nestBef < nestAft) options.nest = false;
1038
+ }
1039
+ if (!options.lng && resolved && resolved.res) options.lng = this.language || resolved.usedLng;
1040
+ if (options.nest !== false) res = this.interpolator.nest(res, function() {
1041
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1042
+ args[_key] = arguments[_key];
1043
+ }
1044
+ if (lastKey?.[0] === args[0] && !options.context) {
1045
+ _this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
1046
+ return null;
1047
+ }
1048
+ return _this.translate(...args, key);
1049
+ }, options);
1050
+ if (options.interpolation) this.interpolator.reset();
1051
+ }
1052
+ const postProcess = options.postProcess || this.options.postProcess;
1053
+ const postProcessorNames = isString2(postProcess) ? [postProcess] : postProcess;
1054
+ if (res != null && postProcessorNames?.length && options.applyPostProcessor !== false) {
1055
+ res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
1056
+ i18nResolved: {
1057
+ ...resolved,
1058
+ usedParams: this.getUsedParamsDetails(options)
1059
+ },
1060
+ ...options
1061
+ } : options, this);
1062
+ }
1063
+ return res;
1064
+ }
1065
+ resolve(keys) {
1066
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1067
+ let found;
1068
+ let usedKey;
1069
+ let exactUsedKey;
1070
+ let usedLng;
1071
+ let usedNS;
1072
+ if (isString2(keys)) keys = [keys];
1073
+ keys.forEach((k) => {
1074
+ if (this.isValidLookup(found)) return;
1075
+ const extracted = this.extractFromKey(k, options);
1076
+ const key = extracted.key;
1077
+ usedKey = key;
1078
+ let namespaces = extracted.namespaces;
1079
+ if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
1080
+ const needsPluralHandling = options.count !== void 0 && !isString2(options.count);
1081
+ const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0;
1082
+ const needsContextHandling = options.context !== void 0 && (isString2(options.context) || typeof options.context === "number") && options.context !== "";
1083
+ const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
1084
+ namespaces.forEach((ns) => {
1085
+ if (this.isValidLookup(found)) return;
1086
+ usedNS = ns;
1087
+ if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
1088
+ checkedLoadedFor[`${codes[0]}-${ns}`] = true;
1089
+ this.logger.warn(`key "${usedKey}" for languages "${codes.join(", ")}" won't get resolved as namespace "${usedNS}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
1090
+ }
1091
+ codes.forEach((code) => {
1092
+ if (this.isValidLookup(found)) return;
1093
+ usedLng = code;
1094
+ const finalKeys = [key];
1095
+ if (this.i18nFormat?.addLookupKeys) {
1096
+ this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
1097
+ } else {
1098
+ let pluralSuffix;
1099
+ if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
1100
+ const zeroSuffix = `${this.options.pluralSeparator}zero`;
1101
+ const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
1102
+ if (needsPluralHandling) {
1103
+ finalKeys.push(key + pluralSuffix);
1104
+ if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
1105
+ finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
1106
+ }
1107
+ if (needsZeroSuffixLookup) {
1108
+ finalKeys.push(key + zeroSuffix);
1109
+ }
1110
+ }
1111
+ if (needsContextHandling) {
1112
+ const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
1113
+ finalKeys.push(contextKey);
1114
+ if (needsPluralHandling) {
1115
+ finalKeys.push(contextKey + pluralSuffix);
1116
+ if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
1117
+ finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
1118
+ }
1119
+ if (needsZeroSuffixLookup) {
1120
+ finalKeys.push(contextKey + zeroSuffix);
1121
+ }
1122
+ }
1123
+ }
1124
+ }
1125
+ let possibleKey;
1126
+ while (possibleKey = finalKeys.pop()) {
1127
+ if (!this.isValidLookup(found)) {
1128
+ exactUsedKey = possibleKey;
1129
+ found = this.getResource(code, ns, possibleKey, options);
1130
+ }
1131
+ }
1132
+ });
1133
+ });
1134
+ });
1135
+ return {
1136
+ res: found,
1137
+ usedKey,
1138
+ exactUsedKey,
1139
+ usedLng,
1140
+ usedNS
1141
+ };
1142
+ }
1143
+ isValidLookup(res) {
1144
+ return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
1145
+ }
1146
+ getResource(code, ns, key) {
1147
+ let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
1148
+ if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
1149
+ return this.resourceStore.getResource(code, ns, key, options);
1150
+ }
1151
+ getUsedParamsDetails() {
1152
+ let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1153
+ const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
1154
+ const useOptionsReplaceForData = options.replace && !isString2(options.replace);
1155
+ let data = useOptionsReplaceForData ? options.replace : options;
1156
+ if (useOptionsReplaceForData && typeof options.count !== "undefined") {
1157
+ data.count = options.count;
1158
+ }
1159
+ if (this.options.interpolation.defaultVariables) {
1160
+ data = {
1161
+ ...this.options.interpolation.defaultVariables,
1162
+ ...data
1163
+ };
1164
+ }
1165
+ if (!useOptionsReplaceForData) {
1166
+ data = {
1167
+ ...data
1168
+ };
1169
+ for (const key of optionsKeys) {
1170
+ delete data[key];
1171
+ }
1172
+ }
1173
+ return data;
1174
+ }
1175
+ static hasDefaultValue(options) {
1176
+ const prefix = "defaultValue";
1177
+ for (const option in options) {
1178
+ if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && void 0 !== options[option]) {
1179
+ return true;
1180
+ }
1181
+ }
1182
+ return false;
1183
+ }
1184
+ };
1185
+ var LanguageUtil = class {
1186
+ constructor(options) {
1187
+ this.options = options;
1188
+ this.supportedLngs = this.options.supportedLngs || false;
1189
+ this.logger = baseLogger.create("languageUtils");
1190
+ }
1191
+ getScriptPartFromCode(code) {
1192
+ code = getCleanedCode(code);
1193
+ if (!code || code.indexOf("-") < 0) return null;
1194
+ const p = code.split("-");
1195
+ if (p.length === 2) return null;
1196
+ p.pop();
1197
+ if (p[p.length - 1].toLowerCase() === "x") return null;
1198
+ return this.formatLanguageCode(p.join("-"));
1199
+ }
1200
+ getLanguagePartFromCode(code) {
1201
+ code = getCleanedCode(code);
1202
+ if (!code || code.indexOf("-") < 0) return code;
1203
+ const p = code.split("-");
1204
+ return this.formatLanguageCode(p[0]);
1205
+ }
1206
+ formatLanguageCode(code) {
1207
+ if (isString2(code) && code.indexOf("-") > -1) {
1208
+ let formattedCode;
1209
+ try {
1210
+ formattedCode = Intl.getCanonicalLocales(code)[0];
1211
+ } catch (e2) {
1212
+ }
1213
+ if (formattedCode && this.options.lowerCaseLng) {
1214
+ formattedCode = formattedCode.toLowerCase();
1215
+ }
1216
+ if (formattedCode) return formattedCode;
1217
+ if (this.options.lowerCaseLng) {
1218
+ return code.toLowerCase();
1219
+ }
1220
+ return code;
1221
+ }
1222
+ return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
1223
+ }
1224
+ isSupportedCode(code) {
1225
+ if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
1226
+ code = this.getLanguagePartFromCode(code);
1227
+ }
1228
+ return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
1229
+ }
1230
+ getBestMatchFromCodes(codes) {
1231
+ if (!codes) return null;
1232
+ let found;
1233
+ codes.forEach((code) => {
1234
+ if (found) return;
1235
+ const cleanedLng = this.formatLanguageCode(code);
1236
+ if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
1237
+ });
1238
+ if (!found && this.options.supportedLngs) {
1239
+ codes.forEach((code) => {
1240
+ if (found) return;
1241
+ const lngOnly = this.getLanguagePartFromCode(code);
1242
+ if (this.isSupportedCode(lngOnly)) return found = lngOnly;
1243
+ found = this.options.supportedLngs.find((supportedLng) => {
1244
+ if (supportedLng === lngOnly) return supportedLng;
1245
+ if (supportedLng.indexOf("-") < 0 && lngOnly.indexOf("-") < 0) return;
1246
+ if (supportedLng.indexOf("-") > 0 && lngOnly.indexOf("-") < 0 && supportedLng.substring(0, supportedLng.indexOf("-")) === lngOnly) return supportedLng;
1247
+ if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
1248
+ });
1249
+ });
1250
+ }
1251
+ if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
1252
+ return found;
1253
+ }
1254
+ getFallbackCodes(fallbacks, code) {
1255
+ if (!fallbacks) return [];
1256
+ if (typeof fallbacks === "function") fallbacks = fallbacks(code);
1257
+ if (isString2(fallbacks)) fallbacks = [fallbacks];
1258
+ if (Array.isArray(fallbacks)) return fallbacks;
1259
+ if (!code) return fallbacks.default || [];
1260
+ let found = fallbacks[code];
1261
+ if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
1262
+ if (!found) found = fallbacks[this.formatLanguageCode(code)];
1263
+ if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
1264
+ if (!found) found = fallbacks.default;
1265
+ return found || [];
1266
+ }
1267
+ toResolveHierarchy(code, fallbackCode) {
1268
+ const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
1269
+ const codes = [];
1270
+ const addCode = (c) => {
1271
+ if (!c) return;
1272
+ if (this.isSupportedCode(c)) {
1273
+ codes.push(c);
1274
+ } else {
1275
+ this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
1276
+ }
1277
+ };
1278
+ if (isString2(code) && (code.indexOf("-") > -1 || code.indexOf("_") > -1)) {
1279
+ if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
1280
+ if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
1281
+ if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
1282
+ } else if (isString2(code)) {
1283
+ addCode(this.formatLanguageCode(code));
1284
+ }
1285
+ fallbackCodes.forEach((fc) => {
1286
+ if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
1287
+ });
1288
+ return codes;
1289
+ }
1290
+ };
1291
+ var suffixesOrder = {
1292
+ zero: 0,
1293
+ one: 1,
1294
+ two: 2,
1295
+ few: 3,
1296
+ many: 4,
1297
+ other: 5
1298
+ };
1299
+ var dummyRule = {
1300
+ select: (count) => count === 1 ? "one" : "other",
1301
+ resolvedOptions: () => ({
1302
+ pluralCategories: ["one", "other"]
1303
+ })
1304
+ };
1305
+ var PluralResolver = class {
1306
+ constructor(languageUtils) {
1307
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1308
+ this.languageUtils = languageUtils;
1309
+ this.options = options;
1310
+ this.logger = baseLogger.create("pluralResolver");
1311
+ this.pluralRulesCache = {};
1312
+ }
1313
+ addRule(lng, obj) {
1314
+ this.rules[lng] = obj;
1315
+ }
1316
+ clearCache() {
1317
+ this.pluralRulesCache = {};
1318
+ }
1319
+ getRule(code) {
1320
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1321
+ const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
1322
+ const type = options.ordinal ? "ordinal" : "cardinal";
1323
+ const cacheKey = JSON.stringify({
1324
+ cleanedCode,
1325
+ type
1326
+ });
1327
+ if (cacheKey in this.pluralRulesCache) {
1328
+ return this.pluralRulesCache[cacheKey];
1329
+ }
1330
+ let rule;
1331
+ try {
1332
+ rule = new Intl.PluralRules(cleanedCode, {
1333
+ type
1334
+ });
1335
+ } catch (err) {
1336
+ if (!Intl) {
1337
+ this.logger.error("No Intl support, please use an Intl polyfill!");
1338
+ return dummyRule;
1339
+ }
1340
+ if (!code.match(/-|_/)) return dummyRule;
1341
+ const lngPart = this.languageUtils.getLanguagePartFromCode(code);
1342
+ rule = this.getRule(lngPart, options);
1343
+ }
1344
+ this.pluralRulesCache[cacheKey] = rule;
1345
+ return rule;
1346
+ }
1347
+ needsPlural(code) {
1348
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1349
+ let rule = this.getRule(code, options);
1350
+ if (!rule) rule = this.getRule("dev", options);
1351
+ return rule?.resolvedOptions().pluralCategories.length > 1;
1352
+ }
1353
+ getPluralFormsOfKey(code, key) {
1354
+ let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1355
+ return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
1356
+ }
1357
+ getSuffixes(code) {
1358
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1359
+ let rule = this.getRule(code, options);
1360
+ if (!rule) rule = this.getRule("dev", options);
1361
+ if (!rule) return [];
1362
+ return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
1363
+ }
1364
+ getSuffix(code, count) {
1365
+ let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1366
+ const rule = this.getRule(code, options);
1367
+ if (rule) {
1368
+ return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
1369
+ }
1370
+ this.logger.warn(`no plural rule found for: ${code}`);
1371
+ return this.getSuffix("dev", count, options);
1372
+ }
1373
+ };
1374
+ var deepFindWithDefaults = function(data, defaultData, key) {
1375
+ let keySeparator = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : ".";
1376
+ let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
1377
+ let path2 = getPathWithDefaults(data, defaultData, key);
1378
+ if (!path2 && ignoreJSONStructure && isString2(key)) {
1379
+ path2 = deepFind(data, key, keySeparator);
1380
+ if (path2 === void 0) path2 = deepFind(defaultData, key, keySeparator);
1381
+ }
1382
+ return path2;
1383
+ };
1384
+ var regexSafe = (val) => val.replace(/\$/g, "$$$$");
1385
+ var Interpolator = class {
1386
+ constructor() {
1387
+ let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1388
+ this.logger = baseLogger.create("interpolator");
1389
+ this.options = options;
1390
+ this.format = options?.interpolation?.format || ((value) => value);
1391
+ this.init(options);
1392
+ }
1393
+ init() {
1394
+ let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1395
+ if (!options.interpolation) options.interpolation = {
1396
+ escapeValue: true
1397
+ };
1398
+ const {
1399
+ escape: escape$1,
1400
+ escapeValue,
1401
+ useRawValueToEscape,
1402
+ prefix,
1403
+ prefixEscaped,
1404
+ suffix,
1405
+ suffixEscaped,
1406
+ formatSeparator,
1407
+ unescapeSuffix,
1408
+ unescapePrefix,
1409
+ nestingPrefix,
1410
+ nestingPrefixEscaped,
1411
+ nestingSuffix,
1412
+ nestingSuffixEscaped,
1413
+ nestingOptionsSeparator,
1414
+ maxReplaces,
1415
+ alwaysFormat
1416
+ } = options.interpolation;
1417
+ this.escape = escape$1 !== void 0 ? escape$1 : escape;
1418
+ this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
1419
+ this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
1420
+ this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
1421
+ this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
1422
+ this.formatSeparator = formatSeparator || ",";
1423
+ this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix || "-";
1424
+ this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix || "";
1425
+ this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
1426
+ this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
1427
+ this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
1428
+ this.maxReplaces = maxReplaces || 1e3;
1429
+ this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
1430
+ this.resetRegExp();
1431
+ }
1432
+ reset() {
1433
+ if (this.options) this.init(this.options);
1434
+ }
1435
+ resetRegExp() {
1436
+ const getOrResetRegExp = (existingRegExp, pattern) => {
1437
+ if (existingRegExp?.source === pattern) {
1438
+ existingRegExp.lastIndex = 0;
1439
+ return existingRegExp;
1440
+ }
1441
+ return new RegExp(pattern, "g");
1442
+ };
1443
+ this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
1444
+ this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
1445
+ this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
1446
+ }
1447
+ interpolate(str, data, lng, options) {
1448
+ let match;
1449
+ let value;
1450
+ let replaces;
1451
+ const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
1452
+ const handleFormat = (key) => {
1453
+ if (key.indexOf(this.formatSeparator) < 0) {
1454
+ const path2 = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
1455
+ return this.alwaysFormat ? this.format(path2, void 0, lng, {
1456
+ ...options,
1457
+ ...data,
1458
+ interpolationkey: key
1459
+ }) : path2;
1460
+ }
1461
+ const p = key.split(this.formatSeparator);
1462
+ const k = p.shift().trim();
1463
+ const f = p.join(this.formatSeparator).trim();
1464
+ return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
1465
+ ...options,
1466
+ ...data,
1467
+ interpolationkey: k
1468
+ });
1469
+ };
1470
+ this.resetRegExp();
1471
+ const missingInterpolationHandler = options?.missingInterpolationHandler || this.options.missingInterpolationHandler;
1472
+ const skipOnVariables = options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
1473
+ const todos = [{
1474
+ regex: this.regexpUnescape,
1475
+ safeValue: (val) => regexSafe(val)
1476
+ }, {
1477
+ regex: this.regexp,
1478
+ safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
1479
+ }];
1480
+ todos.forEach((todo) => {
1481
+ replaces = 0;
1482
+ while (match = todo.regex.exec(str)) {
1483
+ const matchedVar = match[1].trim();
1484
+ value = handleFormat(matchedVar);
1485
+ if (value === void 0) {
1486
+ if (typeof missingInterpolationHandler === "function") {
1487
+ const temp = missingInterpolationHandler(str, match, options);
1488
+ value = isString2(temp) ? temp : "";
1489
+ } else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
1490
+ value = "";
1491
+ } else if (skipOnVariables) {
1492
+ value = match[0];
1493
+ continue;
1494
+ } else {
1495
+ this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
1496
+ value = "";
1497
+ }
1498
+ } else if (!isString2(value) && !this.useRawValueToEscape) {
1499
+ value = makeString(value);
1500
+ }
1501
+ const safeValue = todo.safeValue(value);
1502
+ str = str.replace(match[0], safeValue);
1503
+ if (skipOnVariables) {
1504
+ todo.regex.lastIndex += value.length;
1505
+ todo.regex.lastIndex -= match[0].length;
1506
+ } else {
1507
+ todo.regex.lastIndex = 0;
1508
+ }
1509
+ replaces++;
1510
+ if (replaces >= this.maxReplaces) {
1511
+ break;
1512
+ }
1513
+ }
1514
+ });
1515
+ return str;
1516
+ }
1517
+ nest(str, fc) {
1518
+ let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1519
+ let match;
1520
+ let value;
1521
+ let clonedOptions;
1522
+ const handleHasOptions = (key, inheritedOptions) => {
1523
+ const sep = this.nestingOptionsSeparator;
1524
+ if (key.indexOf(sep) < 0) return key;
1525
+ const c = key.split(new RegExp(`${sep}[ ]*{`));
1526
+ let optionsString = `{${c[1]}`;
1527
+ key = c[0];
1528
+ optionsString = this.interpolate(optionsString, clonedOptions);
1529
+ const matchedSingleQuotes = optionsString.match(/'/g);
1530
+ const matchedDoubleQuotes = optionsString.match(/"/g);
1531
+ if ((matchedSingleQuotes?.length ?? 0) % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
1532
+ optionsString = optionsString.replace(/'/g, '"');
1533
+ }
1534
+ try {
1535
+ clonedOptions = JSON.parse(optionsString);
1536
+ if (inheritedOptions) clonedOptions = {
1537
+ ...inheritedOptions,
1538
+ ...clonedOptions
1539
+ };
1540
+ } catch (e2) {
1541
+ this.logger.warn(`failed parsing options string in nesting for key ${key}`, e2);
1542
+ return `${key}${sep}${optionsString}`;
1543
+ }
1544
+ if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
1545
+ return key;
1546
+ };
1547
+ while (match = this.nestingRegexp.exec(str)) {
1548
+ let formatters = [];
1549
+ clonedOptions = {
1550
+ ...options
1551
+ };
1552
+ clonedOptions = clonedOptions.replace && !isString2(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
1553
+ clonedOptions.applyPostProcessor = false;
1554
+ delete clonedOptions.defaultValue;
1555
+ let doReduce = false;
1556
+ if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
1557
+ const r = match[1].split(this.formatSeparator).map((elem) => elem.trim());
1558
+ match[1] = r.shift();
1559
+ formatters = r;
1560
+ doReduce = true;
1561
+ }
1562
+ value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
1563
+ if (value && match[0] === str && !isString2(value)) return value;
1564
+ if (!isString2(value)) value = makeString(value);
1565
+ if (!value) {
1566
+ this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
1567
+ value = "";
1568
+ }
1569
+ if (doReduce) {
1570
+ value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
1571
+ ...options,
1572
+ interpolationkey: match[1].trim()
1573
+ }), value.trim());
1574
+ }
1575
+ str = str.replace(match[0], value);
1576
+ this.regexp.lastIndex = 0;
1577
+ }
1578
+ return str;
1579
+ }
1580
+ };
1581
+ var parseFormatStr = (formatStr) => {
1582
+ let formatName = formatStr.toLowerCase().trim();
1583
+ const formatOptions = {};
1584
+ if (formatStr.indexOf("(") > -1) {
1585
+ const p = formatStr.split("(");
1586
+ formatName = p[0].toLowerCase().trim();
1587
+ const optStr = p[1].substring(0, p[1].length - 1);
1588
+ if (formatName === "currency" && optStr.indexOf(":") < 0) {
1589
+ if (!formatOptions.currency) formatOptions.currency = optStr.trim();
1590
+ } else if (formatName === "relativetime" && optStr.indexOf(":") < 0) {
1591
+ if (!formatOptions.range) formatOptions.range = optStr.trim();
1592
+ } else {
1593
+ const opts = optStr.split(";");
1594
+ opts.forEach((opt) => {
1595
+ if (opt) {
1596
+ const [key, ...rest] = opt.split(":");
1597
+ const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
1598
+ const trimmedKey = key.trim();
1599
+ if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
1600
+ if (val === "false") formatOptions[trimmedKey] = false;
1601
+ if (val === "true") formatOptions[trimmedKey] = true;
1602
+ if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
1603
+ }
1604
+ });
1605
+ }
1606
+ }
1607
+ return {
1608
+ formatName,
1609
+ formatOptions
1610
+ };
1611
+ };
1612
+ var createCachedFormatter = (fn) => {
1613
+ const cache = {};
1614
+ return (val, lng, options) => {
1615
+ let optForCache = options;
1616
+ if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
1617
+ optForCache = {
1618
+ ...optForCache,
1619
+ [options.interpolationkey]: void 0
1620
+ };
1621
+ }
1622
+ const key = lng + JSON.stringify(optForCache);
1623
+ let formatter = cache[key];
1624
+ if (!formatter) {
1625
+ formatter = fn(getCleanedCode(lng), options);
1626
+ cache[key] = formatter;
1627
+ }
1628
+ return formatter(val);
1629
+ };
1630
+ };
1631
+ var Formatter = class {
1632
+ constructor() {
1633
+ let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1634
+ this.logger = baseLogger.create("formatter");
1635
+ this.options = options;
1636
+ this.formats = {
1637
+ number: createCachedFormatter((lng, opt) => {
1638
+ const formatter = new Intl.NumberFormat(lng, {
1639
+ ...opt
1640
+ });
1641
+ return (val) => formatter.format(val);
1642
+ }),
1643
+ currency: createCachedFormatter((lng, opt) => {
1644
+ const formatter = new Intl.NumberFormat(lng, {
1645
+ ...opt,
1646
+ style: "currency"
1647
+ });
1648
+ return (val) => formatter.format(val);
1649
+ }),
1650
+ datetime: createCachedFormatter((lng, opt) => {
1651
+ const formatter = new Intl.DateTimeFormat(lng, {
1652
+ ...opt
1653
+ });
1654
+ return (val) => formatter.format(val);
1655
+ }),
1656
+ relativetime: createCachedFormatter((lng, opt) => {
1657
+ const formatter = new Intl.RelativeTimeFormat(lng, {
1658
+ ...opt
1659
+ });
1660
+ return (val) => formatter.format(val, opt.range || "day");
1661
+ }),
1662
+ list: createCachedFormatter((lng, opt) => {
1663
+ const formatter = new Intl.ListFormat(lng, {
1664
+ ...opt
1665
+ });
1666
+ return (val) => formatter.format(val);
1667
+ })
1668
+ };
1669
+ this.init(options);
1670
+ }
1671
+ init(services) {
1672
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
1673
+ interpolation: {}
1674
+ };
1675
+ this.formatSeparator = options.interpolation.formatSeparator || ",";
1676
+ }
1677
+ add(name, fc) {
1678
+ this.formats[name.toLowerCase().trim()] = fc;
1679
+ }
1680
+ addCached(name, fc) {
1681
+ this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
1682
+ }
1683
+ format(value, format, lng) {
1684
+ let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
1685
+ const formats = format.split(this.formatSeparator);
1686
+ if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f) => f.indexOf(")") > -1)) {
1687
+ const lastIndex = formats.findIndex((f) => f.indexOf(")") > -1);
1688
+ formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
1689
+ }
1690
+ const result = formats.reduce((mem, f) => {
1691
+ const {
1692
+ formatName,
1693
+ formatOptions
1694
+ } = parseFormatStr(f);
1695
+ if (this.formats[formatName]) {
1696
+ let formatted = mem;
1697
+ try {
1698
+ const valOptions = options?.formatParams?.[options.interpolationkey] || {};
1699
+ const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
1700
+ formatted = this.formats[formatName](mem, l, {
1701
+ ...formatOptions,
1702
+ ...options,
1703
+ ...valOptions
1704
+ });
1705
+ } catch (error) {
1706
+ this.logger.warn(error);
1707
+ }
1708
+ return formatted;
1709
+ } else {
1710
+ this.logger.warn(`there was no format function for ${formatName}`);
1711
+ }
1712
+ return mem;
1713
+ }, value);
1714
+ return result;
1715
+ }
1716
+ };
1717
+ var removePending = (q, name) => {
1718
+ if (q.pending[name] !== void 0) {
1719
+ delete q.pending[name];
1720
+ q.pendingCount--;
1721
+ }
1722
+ };
1723
+ var Connector = class extends EventEmitter {
1724
+ constructor(backend, store, services) {
1725
+ let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
1726
+ super();
1727
+ this.backend = backend;
1728
+ this.store = store;
1729
+ this.services = services;
1730
+ this.languageUtils = services.languageUtils;
1731
+ this.options = options;
1732
+ this.logger = baseLogger.create("backendConnector");
1733
+ this.waitingReads = [];
1734
+ this.maxParallelReads = options.maxParallelReads || 10;
1735
+ this.readingCalls = 0;
1736
+ this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
1737
+ this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
1738
+ this.state = {};
1739
+ this.queue = [];
1740
+ this.backend?.init?.(services, options.backend, options);
1741
+ }
1742
+ queueLoad(languages, namespaces, options, callback) {
1743
+ const toLoad = {};
1744
+ const pending = {};
1745
+ const toLoadLanguages = {};
1746
+ const toLoadNamespaces = {};
1747
+ languages.forEach((lng) => {
1748
+ let hasAllNamespaces = true;
1749
+ namespaces.forEach((ns) => {
1750
+ const name = `${lng}|${ns}`;
1751
+ if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
1752
+ this.state[name] = 2;
1753
+ } else if (this.state[name] < 0) ;
1754
+ else if (this.state[name] === 1) {
1755
+ if (pending[name] === void 0) pending[name] = true;
1756
+ } else {
1757
+ this.state[name] = 1;
1758
+ hasAllNamespaces = false;
1759
+ if (pending[name] === void 0) pending[name] = true;
1760
+ if (toLoad[name] === void 0) toLoad[name] = true;
1761
+ if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
1762
+ }
1763
+ });
1764
+ if (!hasAllNamespaces) toLoadLanguages[lng] = true;
1765
+ });
1766
+ if (Object.keys(toLoad).length || Object.keys(pending).length) {
1767
+ this.queue.push({
1768
+ pending,
1769
+ pendingCount: Object.keys(pending).length,
1770
+ loaded: {},
1771
+ errors: [],
1772
+ callback
1773
+ });
1774
+ }
1775
+ return {
1776
+ toLoad: Object.keys(toLoad),
1777
+ pending: Object.keys(pending),
1778
+ toLoadLanguages: Object.keys(toLoadLanguages),
1779
+ toLoadNamespaces: Object.keys(toLoadNamespaces)
1780
+ };
1781
+ }
1782
+ loaded(name, err, data) {
1783
+ const s = name.split("|");
1784
+ const lng = s[0];
1785
+ const ns = s[1];
1786
+ if (err) this.emit("failedLoading", lng, ns, err);
1787
+ if (!err && data) {
1788
+ this.store.addResourceBundle(lng, ns, data, void 0, void 0, {
1789
+ skipCopy: true
1790
+ });
1791
+ }
1792
+ this.state[name] = err ? -1 : 2;
1793
+ if (err && data) this.state[name] = 0;
1794
+ const loaded = {};
1795
+ this.queue.forEach((q) => {
1796
+ pushPath(q.loaded, [lng], ns);
1797
+ removePending(q, name);
1798
+ if (err) q.errors.push(err);
1799
+ if (q.pendingCount === 0 && !q.done) {
1800
+ Object.keys(q.loaded).forEach((l) => {
1801
+ if (!loaded[l]) loaded[l] = {};
1802
+ const loadedKeys = q.loaded[l];
1803
+ if (loadedKeys.length) {
1804
+ loadedKeys.forEach((n) => {
1805
+ if (loaded[l][n] === void 0) loaded[l][n] = true;
1806
+ });
1807
+ }
1808
+ });
1809
+ q.done = true;
1810
+ if (q.errors.length) {
1811
+ q.callback(q.errors);
1812
+ } else {
1813
+ q.callback();
1814
+ }
1815
+ }
1816
+ });
1817
+ this.emit("loaded", loaded);
1818
+ this.queue = this.queue.filter((q) => !q.done);
1819
+ }
1820
+ read(lng, ns, fcName) {
1821
+ let tried = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
1822
+ let wait = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : this.retryTimeout;
1823
+ let callback = arguments.length > 5 ? arguments[5] : void 0;
1824
+ if (!lng.length) return callback(null, {});
1825
+ if (this.readingCalls >= this.maxParallelReads) {
1826
+ this.waitingReads.push({
1827
+ lng,
1828
+ ns,
1829
+ fcName,
1830
+ tried,
1831
+ wait,
1832
+ callback
1833
+ });
1834
+ return;
1835
+ }
1836
+ this.readingCalls++;
1837
+ const resolver = (err, data) => {
1838
+ this.readingCalls--;
1839
+ if (this.waitingReads.length > 0) {
1840
+ const next = this.waitingReads.shift();
1841
+ this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
1842
+ }
1843
+ if (err && data && tried < this.maxRetries) {
1844
+ setTimeout(() => {
1845
+ this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
1846
+ }, wait);
1847
+ return;
1848
+ }
1849
+ callback(err, data);
1850
+ };
1851
+ const fc = this.backend[fcName].bind(this.backend);
1852
+ if (fc.length === 2) {
1853
+ try {
1854
+ const r = fc(lng, ns);
1855
+ if (r && typeof r.then === "function") {
1856
+ r.then((data) => resolver(null, data)).catch(resolver);
1857
+ } else {
1858
+ resolver(null, r);
1859
+ }
1860
+ } catch (err) {
1861
+ resolver(err);
1862
+ }
1863
+ return;
1864
+ }
1865
+ return fc(lng, ns, resolver);
1866
+ }
1867
+ prepareLoading(languages, namespaces) {
1868
+ let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1869
+ let callback = arguments.length > 3 ? arguments[3] : void 0;
1870
+ if (!this.backend) {
1871
+ this.logger.warn("No backend was added via i18next.use. Will not load resources.");
1872
+ return callback && callback();
1873
+ }
1874
+ if (isString2(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
1875
+ if (isString2(namespaces)) namespaces = [namespaces];
1876
+ const toLoad = this.queueLoad(languages, namespaces, options, callback);
1877
+ if (!toLoad.toLoad.length) {
1878
+ if (!toLoad.pending.length) callback();
1879
+ return null;
1880
+ }
1881
+ toLoad.toLoad.forEach((name) => {
1882
+ this.loadOne(name);
1883
+ });
1884
+ }
1885
+ load(languages, namespaces, callback) {
1886
+ this.prepareLoading(languages, namespaces, {}, callback);
1887
+ }
1888
+ reload(languages, namespaces, callback) {
1889
+ this.prepareLoading(languages, namespaces, {
1890
+ reload: true
1891
+ }, callback);
1892
+ }
1893
+ loadOne(name) {
1894
+ let prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
1895
+ const s = name.split("|");
1896
+ const lng = s[0];
1897
+ const ns = s[1];
1898
+ this.read(lng, ns, "read", void 0, void 0, (err, data) => {
1899
+ if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
1900
+ if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
1901
+ this.loaded(name, err, data);
1902
+ });
1903
+ }
1904
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
1905
+ let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {};
1906
+ let clb = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : () => {
1907
+ };
1908
+ if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
1909
+ this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
1910
+ return;
1911
+ }
1912
+ if (key === void 0 || key === null || key === "") return;
1913
+ if (this.backend?.create) {
1914
+ const opts = {
1915
+ ...options,
1916
+ isUpdate
1917
+ };
1918
+ const fc = this.backend.create.bind(this.backend);
1919
+ if (fc.length < 6) {
1920
+ try {
1921
+ let r;
1922
+ if (fc.length === 5) {
1923
+ r = fc(languages, namespace, key, fallbackValue, opts);
1924
+ } else {
1925
+ r = fc(languages, namespace, key, fallbackValue);
1926
+ }
1927
+ if (r && typeof r.then === "function") {
1928
+ r.then((data) => clb(null, data)).catch(clb);
1929
+ } else {
1930
+ clb(null, r);
1931
+ }
1932
+ } catch (err) {
1933
+ clb(err);
1934
+ }
1935
+ } else {
1936
+ fc(languages, namespace, key, fallbackValue, clb, opts);
1937
+ }
1938
+ }
1939
+ if (!languages || !languages[0]) return;
1940
+ this.store.addResource(languages[0], namespace, key, fallbackValue);
1941
+ }
1942
+ };
1943
+ var get = () => ({
1944
+ debug: false,
1945
+ initAsync: true,
1946
+ ns: ["translation"],
1947
+ defaultNS: ["translation"],
1948
+ fallbackLng: ["dev"],
1949
+ fallbackNS: false,
1950
+ supportedLngs: false,
1951
+ nonExplicitSupportedLngs: false,
1952
+ load: "all",
1953
+ preload: false,
1954
+ simplifyPluralSuffix: true,
1955
+ keySeparator: ".",
1956
+ nsSeparator: ":",
1957
+ pluralSeparator: "_",
1958
+ contextSeparator: "_",
1959
+ partialBundledLanguages: false,
1960
+ saveMissing: false,
1961
+ updateMissing: false,
1962
+ saveMissingTo: "fallback",
1963
+ saveMissingPlurals: true,
1964
+ missingKeyHandler: false,
1965
+ missingInterpolationHandler: false,
1966
+ postProcess: false,
1967
+ postProcessPassResolved: false,
1968
+ returnNull: false,
1969
+ returnEmptyString: true,
1970
+ returnObjects: false,
1971
+ joinArrays: false,
1972
+ returnedObjectHandler: false,
1973
+ parseMissingKeyHandler: false,
1974
+ appendNamespaceToMissingKey: false,
1975
+ appendNamespaceToCIMode: false,
1976
+ overloadTranslationOptionHandler: (args) => {
1977
+ let ret = {};
1978
+ if (typeof args[1] === "object") ret = args[1];
1979
+ if (isString2(args[1])) ret.defaultValue = args[1];
1980
+ if (isString2(args[2])) ret.tDescription = args[2];
1981
+ if (typeof args[2] === "object" || typeof args[3] === "object") {
1982
+ const options = args[3] || args[2];
1983
+ Object.keys(options).forEach((key) => {
1984
+ ret[key] = options[key];
1985
+ });
1986
+ }
1987
+ return ret;
1988
+ },
1989
+ interpolation: {
1990
+ escapeValue: true,
1991
+ format: (value) => value,
1992
+ prefix: "{{",
1993
+ suffix: "}}",
1994
+ formatSeparator: ",",
1995
+ unescapePrefix: "-",
1996
+ nestingPrefix: "$t(",
1997
+ nestingSuffix: ")",
1998
+ nestingOptionsSeparator: ",",
1999
+ maxReplaces: 1e3,
2000
+ skipOnVariables: true
2001
+ }
2002
+ });
2003
+ var transformOptions = (options) => {
2004
+ if (isString2(options.ns)) options.ns = [options.ns];
2005
+ if (isString2(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
2006
+ if (isString2(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
2007
+ if (options.supportedLngs?.indexOf?.("cimode") < 0) {
2008
+ options.supportedLngs = options.supportedLngs.concat(["cimode"]);
2009
+ }
2010
+ if (typeof options.initImmediate === "boolean") options.initAsync = options.initImmediate;
2011
+ return options;
2012
+ };
2013
+ var noop = () => {
2014
+ };
2015
+ var bindMemberFunctions = (inst) => {
2016
+ const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
2017
+ mems.forEach((mem) => {
2018
+ if (typeof inst[mem] === "function") {
2019
+ inst[mem] = inst[mem].bind(inst);
2020
+ }
2021
+ });
2022
+ };
2023
+ var I18n = class _I18n extends EventEmitter {
2024
+ constructor() {
2025
+ let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
2026
+ let callback = arguments.length > 1 ? arguments[1] : void 0;
2027
+ super();
2028
+ this.options = transformOptions(options);
2029
+ this.services = {};
2030
+ this.logger = baseLogger;
2031
+ this.modules = {
2032
+ external: []
2033
+ };
2034
+ bindMemberFunctions(this);
2035
+ if (callback && !this.isInitialized && !options.isClone) {
2036
+ if (!this.options.initAsync) {
2037
+ this.init(options, callback);
2038
+ return this;
2039
+ }
2040
+ setTimeout(() => {
2041
+ this.init(options, callback);
2042
+ }, 0);
2043
+ }
2044
+ }
2045
+ init() {
2046
+ var _this = this;
2047
+ let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
2048
+ let callback = arguments.length > 1 ? arguments[1] : void 0;
2049
+ this.isInitializing = true;
2050
+ if (typeof options === "function") {
2051
+ callback = options;
2052
+ options = {};
2053
+ }
2054
+ if (options.defaultNS == null && options.ns) {
2055
+ if (isString2(options.ns)) {
2056
+ options.defaultNS = options.ns;
2057
+ } else if (options.ns.indexOf("translation") < 0) {
2058
+ options.defaultNS = options.ns[0];
2059
+ }
2060
+ }
2061
+ const defOpts = get();
2062
+ this.options = {
2063
+ ...defOpts,
2064
+ ...this.options,
2065
+ ...transformOptions(options)
2066
+ };
2067
+ this.options.interpolation = {
2068
+ ...defOpts.interpolation,
2069
+ ...this.options.interpolation
2070
+ };
2071
+ if (options.keySeparator !== void 0) {
2072
+ this.options.userDefinedKeySeparator = options.keySeparator;
2073
+ }
2074
+ if (options.nsSeparator !== void 0) {
2075
+ this.options.userDefinedNsSeparator = options.nsSeparator;
2076
+ }
2077
+ const createClassOnDemand = (ClassOrObject) => {
2078
+ if (!ClassOrObject) return null;
2079
+ if (typeof ClassOrObject === "function") return new ClassOrObject();
2080
+ return ClassOrObject;
2081
+ };
2082
+ if (!this.options.isClone) {
2083
+ if (this.modules.logger) {
2084
+ baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
2085
+ } else {
2086
+ baseLogger.init(null, this.options);
2087
+ }
2088
+ let formatter;
2089
+ if (this.modules.formatter) {
2090
+ formatter = this.modules.formatter;
2091
+ } else {
2092
+ formatter = Formatter;
2093
+ }
2094
+ const lu = new LanguageUtil(this.options);
2095
+ this.store = new ResourceStore(this.options.resources, this.options);
2096
+ const s = this.services;
2097
+ s.logger = baseLogger;
2098
+ s.resourceStore = this.store;
2099
+ s.languageUtils = lu;
2100
+ s.pluralResolver = new PluralResolver(lu, {
2101
+ prepend: this.options.pluralSeparator,
2102
+ simplifyPluralSuffix: this.options.simplifyPluralSuffix
2103
+ });
2104
+ if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
2105
+ s.formatter = createClassOnDemand(formatter);
2106
+ s.formatter.init(s, this.options);
2107
+ this.options.interpolation.format = s.formatter.format.bind(s.formatter);
2108
+ }
2109
+ s.interpolator = new Interpolator(this.options);
2110
+ s.utils = {
2111
+ hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
2112
+ };
2113
+ s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
2114
+ s.backendConnector.on("*", function(event) {
2115
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2116
+ args[_key - 1] = arguments[_key];
2117
+ }
2118
+ _this.emit(event, ...args);
2119
+ });
2120
+ if (this.modules.languageDetector) {
2121
+ s.languageDetector = createClassOnDemand(this.modules.languageDetector);
2122
+ if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
2123
+ }
2124
+ if (this.modules.i18nFormat) {
2125
+ s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
2126
+ if (s.i18nFormat.init) s.i18nFormat.init(this);
2127
+ }
2128
+ this.translator = new Translator(this.services, this.options);
2129
+ this.translator.on("*", function(event) {
2130
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
2131
+ args[_key2 - 1] = arguments[_key2];
2132
+ }
2133
+ _this.emit(event, ...args);
2134
+ });
2135
+ this.modules.external.forEach((m) => {
2136
+ if (m.init) m.init(this);
2137
+ });
2138
+ }
2139
+ this.format = this.options.interpolation.format;
2140
+ if (!callback) callback = noop;
2141
+ if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
2142
+ const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
2143
+ if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
2144
+ }
2145
+ if (!this.services.languageDetector && !this.options.lng) {
2146
+ this.logger.warn("init: no languageDetector is used and no lng is defined");
2147
+ }
2148
+ const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
2149
+ storeApi.forEach((fcName) => {
2150
+ this[fcName] = function() {
2151
+ return _this.store[fcName](...arguments);
2152
+ };
2153
+ });
2154
+ const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
2155
+ storeApiChained.forEach((fcName) => {
2156
+ this[fcName] = function() {
2157
+ _this.store[fcName](...arguments);
2158
+ return _this;
2159
+ };
2160
+ });
2161
+ const deferred = defer();
2162
+ const load = () => {
2163
+ const finish = (err, t2) => {
2164
+ this.isInitializing = false;
2165
+ if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
2166
+ this.isInitialized = true;
2167
+ if (!this.options.isClone) this.logger.log("initialized", this.options);
2168
+ this.emit("initialized", this.options);
2169
+ deferred.resolve(t2);
2170
+ callback(err, t2);
2171
+ };
2172
+ if (this.languages && !this.isInitialized) return finish(null, this.t.bind(this));
2173
+ this.changeLanguage(this.options.lng, finish);
2174
+ };
2175
+ if (this.options.resources || !this.options.initAsync) {
2176
+ load();
2177
+ } else {
2178
+ setTimeout(load, 0);
2179
+ }
2180
+ return deferred;
2181
+ }
2182
+ loadResources(language) {
2183
+ let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
2184
+ let usedCallback = callback;
2185
+ const usedLng = isString2(language) ? language : this.language;
2186
+ if (typeof language === "function") usedCallback = language;
2187
+ if (!this.options.resources || this.options.partialBundledLanguages) {
2188
+ if (usedLng?.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
2189
+ const toLoad = [];
2190
+ const append = (lng) => {
2191
+ if (!lng) return;
2192
+ if (lng === "cimode") return;
2193
+ const lngs = this.services.languageUtils.toResolveHierarchy(lng);
2194
+ lngs.forEach((l) => {
2195
+ if (l === "cimode") return;
2196
+ if (toLoad.indexOf(l) < 0) toLoad.push(l);
2197
+ });
2198
+ };
2199
+ if (!usedLng) {
2200
+ const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
2201
+ fallbacks.forEach((l) => append(l));
2202
+ } else {
2203
+ append(usedLng);
2204
+ }
2205
+ this.options.preload?.forEach?.((l) => append(l));
2206
+ this.services.backendConnector.load(toLoad, this.options.ns, (e2) => {
2207
+ if (!e2 && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
2208
+ usedCallback(e2);
2209
+ });
2210
+ } else {
2211
+ usedCallback(null);
2212
+ }
2213
+ }
2214
+ reloadResources(lngs, ns, callback) {
2215
+ const deferred = defer();
2216
+ if (typeof lngs === "function") {
2217
+ callback = lngs;
2218
+ lngs = void 0;
2219
+ }
2220
+ if (typeof ns === "function") {
2221
+ callback = ns;
2222
+ ns = void 0;
2223
+ }
2224
+ if (!lngs) lngs = this.languages;
2225
+ if (!ns) ns = this.options.ns;
2226
+ if (!callback) callback = noop;
2227
+ this.services.backendConnector.reload(lngs, ns, (err) => {
2228
+ deferred.resolve();
2229
+ callback(err);
2230
+ });
2231
+ return deferred;
2232
+ }
2233
+ use(module2) {
2234
+ if (!module2) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
2235
+ if (!module2.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
2236
+ if (module2.type === "backend") {
2237
+ this.modules.backend = module2;
2238
+ }
2239
+ if (module2.type === "logger" || module2.log && module2.warn && module2.error) {
2240
+ this.modules.logger = module2;
2241
+ }
2242
+ if (module2.type === "languageDetector") {
2243
+ this.modules.languageDetector = module2;
2244
+ }
2245
+ if (module2.type === "i18nFormat") {
2246
+ this.modules.i18nFormat = module2;
2247
+ }
2248
+ if (module2.type === "postProcessor") {
2249
+ postProcessor.addPostProcessor(module2);
2250
+ }
2251
+ if (module2.type === "formatter") {
2252
+ this.modules.formatter = module2;
2253
+ }
2254
+ if (module2.type === "3rdParty") {
2255
+ this.modules.external.push(module2);
2256
+ }
2257
+ return this;
2258
+ }
2259
+ setResolvedLanguage(l) {
2260
+ if (!l || !this.languages) return;
2261
+ if (["cimode", "dev"].indexOf(l) > -1) return;
2262
+ for (let li = 0; li < this.languages.length; li++) {
2263
+ const lngInLngs = this.languages[li];
2264
+ if (["cimode", "dev"].indexOf(lngInLngs) > -1) continue;
2265
+ if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
2266
+ this.resolvedLanguage = lngInLngs;
2267
+ break;
2268
+ }
2269
+ }
2270
+ }
2271
+ changeLanguage(lng, callback) {
2272
+ var _this2 = this;
2273
+ this.isLanguageChangingTo = lng;
2274
+ const deferred = defer();
2275
+ this.emit("languageChanging", lng);
2276
+ const setLngProps = (l) => {
2277
+ this.language = l;
2278
+ this.languages = this.services.languageUtils.toResolveHierarchy(l);
2279
+ this.resolvedLanguage = void 0;
2280
+ this.setResolvedLanguage(l);
2281
+ };
2282
+ const done = (err, l) => {
2283
+ if (l) {
2284
+ setLngProps(l);
2285
+ this.translator.changeLanguage(l);
2286
+ this.isLanguageChangingTo = void 0;
2287
+ this.emit("languageChanged", l);
2288
+ this.logger.log("languageChanged", l);
2289
+ } else {
2290
+ this.isLanguageChangingTo = void 0;
2291
+ }
2292
+ deferred.resolve(function() {
2293
+ return _this2.t(...arguments);
2294
+ });
2295
+ if (callback) callback(err, function() {
2296
+ return _this2.t(...arguments);
2297
+ });
2298
+ };
2299
+ const setLng = (lngs) => {
2300
+ if (!lng && !lngs && this.services.languageDetector) lngs = [];
2301
+ const l = isString2(lngs) ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
2302
+ if (l) {
2303
+ if (!this.language) {
2304
+ setLngProps(l);
2305
+ }
2306
+ if (!this.translator.language) this.translator.changeLanguage(l);
2307
+ this.services.languageDetector?.cacheUserLanguage?.(l);
2308
+ }
2309
+ this.loadResources(l, (err) => {
2310
+ done(err, l);
2311
+ });
2312
+ };
2313
+ if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
2314
+ setLng(this.services.languageDetector.detect());
2315
+ } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
2316
+ if (this.services.languageDetector.detect.length === 0) {
2317
+ this.services.languageDetector.detect().then(setLng);
2318
+ } else {
2319
+ this.services.languageDetector.detect(setLng);
2320
+ }
2321
+ } else {
2322
+ setLng(lng);
2323
+ }
2324
+ return deferred;
2325
+ }
2326
+ getFixedT(lng, ns, keyPrefix) {
2327
+ var _this3 = this;
2328
+ const fixedT = function(key, opts) {
2329
+ let options;
2330
+ if (typeof opts !== "object") {
2331
+ for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
2332
+ rest[_key3 - 2] = arguments[_key3];
2333
+ }
2334
+ options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
2335
+ } else {
2336
+ options = {
2337
+ ...opts
2338
+ };
2339
+ }
2340
+ options.lng = options.lng || fixedT.lng;
2341
+ options.lngs = options.lngs || fixedT.lngs;
2342
+ options.ns = options.ns || fixedT.ns;
2343
+ if (options.keyPrefix !== "") options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
2344
+ const keySeparator = _this3.options.keySeparator || ".";
2345
+ let resultKey;
2346
+ if (options.keyPrefix && Array.isArray(key)) {
2347
+ resultKey = key.map((k) => `${options.keyPrefix}${keySeparator}${k}`);
2348
+ } else {
2349
+ resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
2350
+ }
2351
+ return _this3.t(resultKey, options);
2352
+ };
2353
+ if (isString2(lng)) {
2354
+ fixedT.lng = lng;
2355
+ } else {
2356
+ fixedT.lngs = lng;
2357
+ }
2358
+ fixedT.ns = ns;
2359
+ fixedT.keyPrefix = keyPrefix;
2360
+ return fixedT;
2361
+ }
2362
+ t() {
2363
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2364
+ args[_key4] = arguments[_key4];
2365
+ }
2366
+ return this.translator?.translate(...args);
2367
+ }
2368
+ exists() {
2369
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
2370
+ args[_key5] = arguments[_key5];
2371
+ }
2372
+ return this.translator?.exists(...args);
2373
+ }
2374
+ setDefaultNamespace(ns) {
2375
+ this.options.defaultNS = ns;
2376
+ }
2377
+ hasLoadedNamespace(ns) {
2378
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
2379
+ if (!this.isInitialized) {
2380
+ this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
2381
+ return false;
2382
+ }
2383
+ if (!this.languages || !this.languages.length) {
2384
+ this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
2385
+ return false;
2386
+ }
2387
+ const lng = options.lng || this.resolvedLanguage || this.languages[0];
2388
+ const fallbackLng = this.options ? this.options.fallbackLng : false;
2389
+ const lastLng = this.languages[this.languages.length - 1];
2390
+ if (lng.toLowerCase() === "cimode") return true;
2391
+ const loadNotPending = (l, n) => {
2392
+ const loadState = this.services.backendConnector.state[`${l}|${n}`];
2393
+ return loadState === -1 || loadState === 0 || loadState === 2;
2394
+ };
2395
+ if (options.precheck) {
2396
+ const preResult = options.precheck(this, loadNotPending);
2397
+ if (preResult !== void 0) return preResult;
2398
+ }
2399
+ if (this.hasResourceBundle(lng, ns)) return true;
2400
+ if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
2401
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
2402
+ return false;
2403
+ }
2404
+ loadNamespaces(ns, callback) {
2405
+ const deferred = defer();
2406
+ if (!this.options.ns) {
2407
+ if (callback) callback();
2408
+ return Promise.resolve();
2409
+ }
2410
+ if (isString2(ns)) ns = [ns];
2411
+ ns.forEach((n) => {
2412
+ if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
2413
+ });
2414
+ this.loadResources((err) => {
2415
+ deferred.resolve();
2416
+ if (callback) callback(err);
2417
+ });
2418
+ return deferred;
2419
+ }
2420
+ loadLanguages(lngs, callback) {
2421
+ const deferred = defer();
2422
+ if (isString2(lngs)) lngs = [lngs];
2423
+ const preloaded = this.options.preload || [];
2424
+ const newLngs = lngs.filter((lng) => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
2425
+ if (!newLngs.length) {
2426
+ if (callback) callback();
2427
+ return Promise.resolve();
2428
+ }
2429
+ this.options.preload = preloaded.concat(newLngs);
2430
+ this.loadResources((err) => {
2431
+ deferred.resolve();
2432
+ if (callback) callback(err);
2433
+ });
2434
+ return deferred;
2435
+ }
2436
+ dir(lng) {
2437
+ if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
2438
+ if (!lng) return "rtl";
2439
+ const rtlLngs = ["ar", "shu", "sqr", "ssh", "xaa", "yhd", "yud", "aao", "abh", "abv", "acm", "acq", "acw", "acx", "acy", "adf", "ads", "aeb", "aec", "afb", "ajp", "apc", "apd", "arb", "arq", "ars", "ary", "arz", "auz", "avl", "ayh", "ayl", "ayn", "ayp", "bbz", "pga", "he", "iw", "ps", "pbt", "pbu", "pst", "prp", "prd", "ug", "ur", "ydd", "yds", "yih", "ji", "yi", "hbo", "men", "xmn", "fa", "jpr", "peo", "pes", "prs", "dv", "sam", "ckb"];
2440
+ const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
2441
+ return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
2442
+ }
2443
+ static createInstance() {
2444
+ let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
2445
+ let callback = arguments.length > 1 ? arguments[1] : void 0;
2446
+ return new _I18n(options, callback);
2447
+ }
2448
+ cloneInstance() {
2449
+ let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
2450
+ let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
2451
+ const forkResourceStore = options.forkResourceStore;
2452
+ if (forkResourceStore) delete options.forkResourceStore;
2453
+ const mergedOptions = {
2454
+ ...this.options,
2455
+ ...options,
2456
+ ...{
2457
+ isClone: true
2458
+ }
2459
+ };
2460
+ const clone = new _I18n(mergedOptions);
2461
+ if (options.debug !== void 0 || options.prefix !== void 0) {
2462
+ clone.logger = clone.logger.clone(options);
2463
+ }
2464
+ const membersToCopy = ["store", "services", "language"];
2465
+ membersToCopy.forEach((m) => {
2466
+ clone[m] = this[m];
2467
+ });
2468
+ clone.services = {
2469
+ ...this.services
2470
+ };
2471
+ clone.services.utils = {
2472
+ hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
2473
+ };
2474
+ if (forkResourceStore) {
2475
+ const clonedData = Object.keys(this.store.data).reduce((prev, l) => {
2476
+ prev[l] = {
2477
+ ...this.store.data[l]
2478
+ };
2479
+ return Object.keys(prev[l]).reduce((acc, n) => {
2480
+ acc[n] = {
2481
+ ...prev[l][n]
2482
+ };
2483
+ return acc;
2484
+ }, {});
2485
+ }, {});
2486
+ clone.store = new ResourceStore(clonedData, mergedOptions);
2487
+ clone.services.resourceStore = clone.store;
2488
+ }
2489
+ clone.translator = new Translator(clone.services, mergedOptions);
2490
+ clone.translator.on("*", function(event) {
2491
+ for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
2492
+ args[_key6 - 1] = arguments[_key6];
2493
+ }
2494
+ clone.emit(event, ...args);
2495
+ });
2496
+ clone.init(mergedOptions, callback);
2497
+ clone.translator.options = mergedOptions;
2498
+ clone.translator.backendConnector.services.utils = {
2499
+ hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
2500
+ };
2501
+ return clone;
2502
+ }
2503
+ toJSON() {
2504
+ return {
2505
+ options: this.options,
2506
+ store: this.store,
2507
+ language: this.language,
2508
+ languages: this.languages,
2509
+ resolvedLanguage: this.resolvedLanguage
2510
+ };
2511
+ }
2512
+ };
2513
+ var instance = I18n.createInstance();
2514
+ instance.createInstance = I18n.createInstance;
2515
+ var createInstance = instance.createInstance;
2516
+ var dir = instance.dir;
2517
+ var init = instance.init;
2518
+ var loadResources = instance.loadResources;
2519
+ var reloadResources = instance.reloadResources;
2520
+ var use = instance.use;
2521
+ var changeLanguage = instance.changeLanguage;
2522
+ var getFixedT = instance.getFixedT;
2523
+ var t = instance.t;
2524
+ var exists = instance.exists;
2525
+ var setDefaultNamespace = instance.setDefaultNamespace;
2526
+ var hasLoadedNamespace2 = instance.hasLoadedNamespace;
2527
+ var loadNamespaces2 = instance.loadNamespaces;
2528
+ var loadLanguages2 = instance.loadLanguages;
2529
+
2530
+ // node_modules/i18next-browser-languagedetector/dist/esm/i18nextBrowserLanguageDetector.js
2531
+ var {
2532
+ slice,
2533
+ forEach
2534
+ } = [];
2535
+ function defaults(obj) {
2536
+ forEach.call(slice.call(arguments, 1), (source) => {
2537
+ if (source) {
2538
+ for (const prop in source) {
2539
+ if (obj[prop] === void 0) obj[prop] = source[prop];
2540
+ }
2541
+ }
2542
+ });
2543
+ return obj;
2544
+ }
2545
+ function hasXSS(input) {
2546
+ if (typeof input !== "string") return false;
2547
+ const xssPatterns = [/<\s*script.*?>/i, /<\s*\/\s*script\s*>/i, /<\s*img.*?on\w+\s*=/i, /<\s*\w+\s*on\w+\s*=.*?>/i, /javascript\s*:/i, /vbscript\s*:/i, /expression\s*\(/i, /eval\s*\(/i, /alert\s*\(/i, /document\.cookie/i, /document\.write\s*\(/i, /window\.location/i, /innerHTML/i];
2548
+ return xssPatterns.some((pattern) => pattern.test(input));
2549
+ }
2550
+ var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
2551
+ var serializeCookie = function(name, val) {
2552
+ let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
2553
+ path: "/"
2554
+ };
2555
+ const opt = options;
2556
+ const value = encodeURIComponent(val);
2557
+ let str = `${name}=${value}`;
2558
+ if (opt.maxAge > 0) {
2559
+ const maxAge = opt.maxAge - 0;
2560
+ if (Number.isNaN(maxAge)) throw new Error("maxAge should be a Number");
2561
+ str += `; Max-Age=${Math.floor(maxAge)}`;
2562
+ }
2563
+ if (opt.domain) {
2564
+ if (!fieldContentRegExp.test(opt.domain)) {
2565
+ throw new TypeError("option domain is invalid");
2566
+ }
2567
+ str += `; Domain=${opt.domain}`;
2568
+ }
2569
+ if (opt.path) {
2570
+ if (!fieldContentRegExp.test(opt.path)) {
2571
+ throw new TypeError("option path is invalid");
2572
+ }
2573
+ str += `; Path=${opt.path}`;
2574
+ }
2575
+ if (opt.expires) {
2576
+ if (typeof opt.expires.toUTCString !== "function") {
2577
+ throw new TypeError("option expires is invalid");
2578
+ }
2579
+ str += `; Expires=${opt.expires.toUTCString()}`;
2580
+ }
2581
+ if (opt.httpOnly) str += "; HttpOnly";
2582
+ if (opt.secure) str += "; Secure";
2583
+ if (opt.sameSite) {
2584
+ const sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite;
2585
+ switch (sameSite) {
2586
+ case true:
2587
+ str += "; SameSite=Strict";
2588
+ break;
2589
+ case "lax":
2590
+ str += "; SameSite=Lax";
2591
+ break;
2592
+ case "strict":
2593
+ str += "; SameSite=Strict";
2594
+ break;
2595
+ case "none":
2596
+ str += "; SameSite=None";
2597
+ break;
2598
+ default:
2599
+ throw new TypeError("option sameSite is invalid");
2600
+ }
2601
+ }
2602
+ if (opt.partitioned) str += "; Partitioned";
2603
+ return str;
2604
+ };
2605
+ var cookie = {
2606
+ create(name, value, minutes, domain) {
2607
+ let cookieOptions = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
2608
+ path: "/",
2609
+ sameSite: "strict"
2610
+ };
2611
+ if (minutes) {
2612
+ cookieOptions.expires = /* @__PURE__ */ new Date();
2613
+ cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1e3);
2614
+ }
2615
+ if (domain) cookieOptions.domain = domain;
2616
+ document.cookie = serializeCookie(name, value, cookieOptions);
2617
+ },
2618
+ read(name) {
2619
+ const nameEQ = `${name}=`;
2620
+ const ca = document.cookie.split(";");
2621
+ for (let i = 0; i < ca.length; i++) {
2622
+ let c = ca[i];
2623
+ while (c.charAt(0) === " ") c = c.substring(1, c.length);
2624
+ if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
2625
+ }
2626
+ return null;
2627
+ },
2628
+ remove(name, domain) {
2629
+ this.create(name, "", -1, domain);
2630
+ }
2631
+ };
2632
+ var cookie$1 = {
2633
+ name: "cookie",
2634
+ // Deconstruct the options object and extract the lookupCookie property
2635
+ lookup(_ref) {
2636
+ let {
2637
+ lookupCookie
2638
+ } = _ref;
2639
+ if (lookupCookie && typeof document !== "undefined") {
2640
+ return cookie.read(lookupCookie) || void 0;
2641
+ }
2642
+ return void 0;
2643
+ },
2644
+ // Deconstruct the options object and extract the lookupCookie, cookieMinutes, cookieDomain, and cookieOptions properties
2645
+ cacheUserLanguage(lng, _ref2) {
2646
+ let {
2647
+ lookupCookie,
2648
+ cookieMinutes,
2649
+ cookieDomain,
2650
+ cookieOptions
2651
+ } = _ref2;
2652
+ if (lookupCookie && typeof document !== "undefined") {
2653
+ cookie.create(lookupCookie, lng, cookieMinutes, cookieDomain, cookieOptions);
2654
+ }
2655
+ }
2656
+ };
2657
+ var querystring = {
2658
+ name: "querystring",
2659
+ // Deconstruct the options object and extract the lookupQuerystring property
2660
+ lookup(_ref) {
2661
+ let {
2662
+ lookupQuerystring
2663
+ } = _ref;
2664
+ let found;
2665
+ if (typeof window !== "undefined") {
2666
+ let {
2667
+ search
2668
+ } = window.location;
2669
+ if (!window.location.search && window.location.hash?.indexOf("?") > -1) {
2670
+ search = window.location.hash.substring(window.location.hash.indexOf("?"));
2671
+ }
2672
+ const query = search.substring(1);
2673
+ const params = query.split("&");
2674
+ for (let i = 0; i < params.length; i++) {
2675
+ const pos = params[i].indexOf("=");
2676
+ if (pos > 0) {
2677
+ const key = params[i].substring(0, pos);
2678
+ if (key === lookupQuerystring) {
2679
+ found = params[i].substring(pos + 1);
2680
+ }
2681
+ }
2682
+ }
2683
+ }
2684
+ return found;
2685
+ }
2686
+ };
2687
+ var hash = {
2688
+ name: "hash",
2689
+ // Deconstruct the options object and extract the lookupHash property and the lookupFromHashIndex property
2690
+ lookup(_ref) {
2691
+ let {
2692
+ lookupHash,
2693
+ lookupFromHashIndex
2694
+ } = _ref;
2695
+ let found;
2696
+ if (typeof window !== "undefined") {
2697
+ const {
2698
+ hash: hash2
2699
+ } = window.location;
2700
+ if (hash2 && hash2.length > 2) {
2701
+ const query = hash2.substring(1);
2702
+ if (lookupHash) {
2703
+ const params = query.split("&");
2704
+ for (let i = 0; i < params.length; i++) {
2705
+ const pos = params[i].indexOf("=");
2706
+ if (pos > 0) {
2707
+ const key = params[i].substring(0, pos);
2708
+ if (key === lookupHash) {
2709
+ found = params[i].substring(pos + 1);
2710
+ }
2711
+ }
2712
+ }
2713
+ }
2714
+ if (found) return found;
2715
+ if (!found && lookupFromHashIndex > -1) {
2716
+ const language = hash2.match(/\/([a-zA-Z-]*)/g);
2717
+ if (!Array.isArray(language)) return void 0;
2718
+ const index = typeof lookupFromHashIndex === "number" ? lookupFromHashIndex : 0;
2719
+ return language[index]?.replace("/", "");
2720
+ }
2721
+ }
2722
+ }
2723
+ return found;
2724
+ }
2725
+ };
2726
+ var hasLocalStorageSupport = null;
2727
+ var localStorageAvailable = () => {
2728
+ if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
2729
+ try {
2730
+ hasLocalStorageSupport = typeof window !== "undefined" && window.localStorage !== null;
2731
+ if (!hasLocalStorageSupport) {
2732
+ return false;
2733
+ }
2734
+ const testKey = "i18next.translate.boo";
2735
+ window.localStorage.setItem(testKey, "foo");
2736
+ window.localStorage.removeItem(testKey);
2737
+ } catch (e2) {
2738
+ hasLocalStorageSupport = false;
2739
+ }
2740
+ return hasLocalStorageSupport;
2741
+ };
2742
+ var localStorage = {
2743
+ name: "localStorage",
2744
+ // Deconstruct the options object and extract the lookupLocalStorage property
2745
+ lookup(_ref) {
2746
+ let {
2747
+ lookupLocalStorage
2748
+ } = _ref;
2749
+ if (lookupLocalStorage && localStorageAvailable()) {
2750
+ return window.localStorage.getItem(lookupLocalStorage) || void 0;
2751
+ }
2752
+ return void 0;
2753
+ },
2754
+ // Deconstruct the options object and extract the lookupLocalStorage property
2755
+ cacheUserLanguage(lng, _ref2) {
2756
+ let {
2757
+ lookupLocalStorage
2758
+ } = _ref2;
2759
+ if (lookupLocalStorage && localStorageAvailable()) {
2760
+ window.localStorage.setItem(lookupLocalStorage, lng);
2761
+ }
2762
+ }
2763
+ };
2764
+ var hasSessionStorageSupport = null;
2765
+ var sessionStorageAvailable = () => {
2766
+ if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
2767
+ try {
2768
+ hasSessionStorageSupport = typeof window !== "undefined" && window.sessionStorage !== null;
2769
+ if (!hasSessionStorageSupport) {
2770
+ return false;
2771
+ }
2772
+ const testKey = "i18next.translate.boo";
2773
+ window.sessionStorage.setItem(testKey, "foo");
2774
+ window.sessionStorage.removeItem(testKey);
2775
+ } catch (e2) {
2776
+ hasSessionStorageSupport = false;
2777
+ }
2778
+ return hasSessionStorageSupport;
2779
+ };
2780
+ var sessionStorage = {
2781
+ name: "sessionStorage",
2782
+ lookup(_ref) {
2783
+ let {
2784
+ lookupSessionStorage
2785
+ } = _ref;
2786
+ if (lookupSessionStorage && sessionStorageAvailable()) {
2787
+ return window.sessionStorage.getItem(lookupSessionStorage) || void 0;
2788
+ }
2789
+ return void 0;
2790
+ },
2791
+ cacheUserLanguage(lng, _ref2) {
2792
+ let {
2793
+ lookupSessionStorage
2794
+ } = _ref2;
2795
+ if (lookupSessionStorage && sessionStorageAvailable()) {
2796
+ window.sessionStorage.setItem(lookupSessionStorage, lng);
2797
+ }
2798
+ }
2799
+ };
2800
+ var navigator$1 = {
2801
+ name: "navigator",
2802
+ lookup(options) {
2803
+ const found = [];
2804
+ if (typeof navigator !== "undefined") {
2805
+ const {
2806
+ languages,
2807
+ userLanguage,
2808
+ language
2809
+ } = navigator;
2810
+ if (languages) {
2811
+ for (let i = 0; i < languages.length; i++) {
2812
+ found.push(languages[i]);
2813
+ }
2814
+ }
2815
+ if (userLanguage) {
2816
+ found.push(userLanguage);
2817
+ }
2818
+ if (language) {
2819
+ found.push(language);
2820
+ }
2821
+ }
2822
+ return found.length > 0 ? found : void 0;
2823
+ }
2824
+ };
2825
+ var htmlTag = {
2826
+ name: "htmlTag",
2827
+ // Deconstruct the options object and extract the htmlTag property
2828
+ lookup(_ref) {
2829
+ let {
2830
+ htmlTag: htmlTag2
2831
+ } = _ref;
2832
+ let found;
2833
+ const internalHtmlTag = htmlTag2 || (typeof document !== "undefined" ? document.documentElement : null);
2834
+ if (internalHtmlTag && typeof internalHtmlTag.getAttribute === "function") {
2835
+ found = internalHtmlTag.getAttribute("lang");
2836
+ }
2837
+ return found;
2838
+ }
2839
+ };
2840
+ var path = {
2841
+ name: "path",
2842
+ // Deconstruct the options object and extract the lookupFromPathIndex property
2843
+ lookup(_ref) {
2844
+ let {
2845
+ lookupFromPathIndex
2846
+ } = _ref;
2847
+ if (typeof window === "undefined") return void 0;
2848
+ const language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
2849
+ if (!Array.isArray(language)) return void 0;
2850
+ const index = typeof lookupFromPathIndex === "number" ? lookupFromPathIndex : 0;
2851
+ return language[index]?.replace("/", "");
2852
+ }
2853
+ };
2854
+ var subdomain = {
2855
+ name: "subdomain",
2856
+ lookup(_ref) {
2857
+ let {
2858
+ lookupFromSubdomainIndex
2859
+ } = _ref;
2860
+ const internalLookupFromSubdomainIndex = typeof lookupFromSubdomainIndex === "number" ? lookupFromSubdomainIndex + 1 : 1;
2861
+ const language = typeof window !== "undefined" && window.location?.hostname?.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i);
2862
+ if (!language) return void 0;
2863
+ return language[internalLookupFromSubdomainIndex];
2864
+ }
2865
+ };
2866
+ var canCookies = false;
2867
+ try {
2868
+ document.cookie;
2869
+ canCookies = true;
2870
+ } catch (e2) {
2871
+ }
2872
+ var order = ["querystring", "cookie", "localStorage", "sessionStorage", "navigator", "htmlTag"];
2873
+ if (!canCookies) order.splice(1, 1);
2874
+ var getDefaults2 = () => ({
2875
+ order,
2876
+ lookupQuerystring: "lng",
2877
+ lookupCookie: "i18next",
2878
+ lookupLocalStorage: "i18nextLng",
2879
+ lookupSessionStorage: "i18nextLng",
2880
+ // cache user language
2881
+ caches: ["localStorage"],
2882
+ excludeCacheFor: ["cimode"],
2883
+ // cookieMinutes: 10,
2884
+ // cookieDomain: 'myDomain'
2885
+ convertDetectedLanguage: (l) => l
2886
+ });
2887
+ var Browser = class {
2888
+ constructor(services) {
2889
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
2890
+ this.type = "languageDetector";
2891
+ this.detectors = {};
2892
+ this.init(services, options);
2893
+ }
2894
+ init() {
2895
+ let services = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
2896
+ languageUtils: {}
2897
+ };
2898
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
2899
+ let i18nOptions = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
2900
+ this.services = services;
2901
+ this.options = defaults(options, this.options || {}, getDefaults2());
2902
+ if (typeof this.options.convertDetectedLanguage === "string" && this.options.convertDetectedLanguage.indexOf("15897") > -1) {
2903
+ this.options.convertDetectedLanguage = (l) => l.replace("-", "_");
2904
+ }
2905
+ if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
2906
+ this.i18nOptions = i18nOptions;
2907
+ this.addDetector(cookie$1);
2908
+ this.addDetector(querystring);
2909
+ this.addDetector(localStorage);
2910
+ this.addDetector(sessionStorage);
2911
+ this.addDetector(navigator$1);
2912
+ this.addDetector(htmlTag);
2913
+ this.addDetector(path);
2914
+ this.addDetector(subdomain);
2915
+ this.addDetector(hash);
2916
+ }
2917
+ addDetector(detector) {
2918
+ this.detectors[detector.name] = detector;
2919
+ return this;
2920
+ }
2921
+ detect() {
2922
+ let detectionOrder = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.options.order;
2923
+ let detected = [];
2924
+ detectionOrder.forEach((detectorName) => {
2925
+ if (this.detectors[detectorName]) {
2926
+ let lookup = this.detectors[detectorName].lookup(this.options);
2927
+ if (lookup && typeof lookup === "string") lookup = [lookup];
2928
+ if (lookup) detected = detected.concat(lookup);
2929
+ }
2930
+ });
2931
+ detected = detected.filter((d) => d !== void 0 && d !== null && !hasXSS(d)).map((d) => this.options.convertDetectedLanguage(d));
2932
+ if (this.services && this.services.languageUtils && this.services.languageUtils.getBestMatchFromCodes) return detected;
2933
+ return detected.length > 0 ? detected[0] : null;
2934
+ }
2935
+ cacheUserLanguage(lng) {
2936
+ let caches = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : this.options.caches;
2937
+ if (!caches) return;
2938
+ if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1) return;
2939
+ caches.forEach((cacheName) => {
2940
+ if (this.detectors[cacheName]) this.detectors[cacheName].cacheUserLanguage(lng, this.options);
2941
+ });
2942
+ }
2943
+ };
2944
+ Browser.type = "languageDetector";
2945
+
2946
+ // src/locales/vi.json
2947
+ var vi_default = {
2948
+ "search...": "T\xECm ki\u1EBFm...",
2949
+ search: "T\xECm ki\u1EBFm",
2950
+ search_more: "T\xECm ki\u1EBFm th\xEAm",
2951
+ for: "cho",
2952
+ cancel: "H\u1EE7y",
2953
+ empty_data: "D\u1EEF li\u1EC7u tr\u1ED1ng",
2954
+ detail_button: "Chi ti\u1EBFt",
2955
+ cancel_button: "H\u1EE7y",
2956
+ choose: "Ch\u1ECDn",
2957
+ total: "T\u1ED5ng ti\u1EC1n",
2958
+ no: "Kh\xF4ng",
2959
+ loading: "\u0110ang t\u1EA3i",
2960
+ active: "Ho\u1EA1t \u0111\u1ED9ng",
2961
+ in_active: "Ng\u01B0ng ho\u1EA1t \u0111\u1ED9ng",
2962
+ new: "M\u1EDBi",
2963
+ add_line: "Th\xEAm d\xF2ng",
2964
+ choose_place: "Vui l\xF2ng ch\u1ECDn",
2965
+ filter_by: "B\u1ED9 l\u1ECDc",
2966
+ group_by: "Nh\xF3m theo",
2967
+ or: "ho\u1EB7c",
2968
+ second_ago: "gi\xE2y tr\u01B0\u1EDBc",
2969
+ minute_ago: "ph\xFAt tr\u01B0\u1EDBc",
2970
+ hour_ago: "gi\u1EDD tr\u01B0\u1EDBc",
2971
+ day_ago: "ng\xE0y tr\u01B0\u1EDBc",
2972
+ month_ago: "th\xE1ng tr\u01B0\u1EDBc",
2973
+ year_ago: "n\u0103m tr\u01B0\u1EDBc",
2974
+ second_future: "gi\xE2y n\u1EEFa",
2975
+ minute_future: "ph\xFAt n\u1EEFa",
2976
+ hour_future: "gi\u1EDD n\u1EEFa",
2977
+ day_future: "ng\xE0y n\u1EEFa",
2978
+ month_future: "th\xE1ng n\u1EEFa",
2979
+ year_future: "n\u0103m n\u1EEFa",
2980
+ now: "B\xE2y gi\u1EDD",
2981
+ download_file: "T\u1EA3i xu\u1ED1ng t\u1EC7p n\xE0y",
2982
+ upload_success: "T\u1EA3i t\u1EC7p l\xEAn th\xE0nh c\xF4ng",
2983
+ upload_failure: "T\u1EA3i t\u1EC7p l\xEAn th\u1EA5t b\u1EA1i",
2984
+ file_accept_single: "Ch\u1EC9 ch\u1EA5p nh\u1EADn c\xE1c \u0111\u1ECBnh d\u1EA1ng JPEG, PNG, PDF, MP4, XLS, XLXS, ZIP v\xE0 m\u1ED7i t\u1EC7p c\xF3 dung l\u01B0\u1EE3ng t\u1ED1i \u0111a l\xE0 10MB.",
2985
+ file_accept_total: "Ch\u1EC9 ch\u1EA5p nh\u1EADn c\xE1c \u0111\u1ECBnh d\u1EA1ng JPEG, PNG, PDF, MP4, XLS, XLXS, ZIP v\xE0 t\u1ED5ng dung l\u01B0\u1EE3ng t\u1ED1i \u0111a l\xE0 50MB.",
2986
+ must_required: "l\xE0 b\u1EAFt bu\u1ED9c.",
2987
+ "none-validated": "Gi\xE1 tr\u1ECB kh\xF4ng h\u1EE3p l\u1EC7",
2988
+ invalid_number: "\u0110\u1ECBnh d\u1EA1ng s\u1ED1 kh\xF4ng h\u1EE3p l\u1EC7",
2989
+ upload_file_placeholder: "T\u1EA3i t\u1EC7p c\u1EE7a b\u1EA1n",
2990
+ "no-available": "Kh\xF4ng c\xF3 l\u1EF1a ch\u1ECDn n\xE0o",
2991
+ paid_amount: "S\u1ED1 ti\u1EC1n \u0111\xE3 tr\u1EA3",
2992
+ remanining_amount: "S\u1ED1 ti\u1EC1n c\xF2n l\u1EA1i",
2993
+ only_image_accept: "Ch\u1EC9 \u0111\u01B0\u1EE3c t\u1EA3i l\xEAn h\xECnh \u1EA3nh",
2994
+ "text-only": "Ch\u1EC9 \u0111\u01B0\u1EE3c nh\u1EADp ch\u1EEF (kh\xF4ng ch\u1EE9a s\u1ED1 v\xE0 k\xFD t\u1EF1 \u0111\u1EB7c bi\u1EC7t)",
2995
+ "number-only": "Ch\u1EC9 \u0111\u01B0\u1EE3c nh\u1EADp s\u1ED1 (kh\xF4ng ch\u1EE9a ch\u1EEF v\xE0 k\xFD t\u1EF1 \u0111\u1EB7c bi\u1EC7t)",
2996
+ "email-only": "Email kh\xF4ng h\u1EE3p l\u1EC7",
2997
+ "phone-only": "S\u1ED1 \u0111i\u1EC7n tho\u1EA1i kh\xF4ng h\u1EE3p l\u1EC7",
2998
+ message: "M\u1EADt kh\u1EA9u ph\u1EA3i c\xF3 t\u1EEB {{min}} \u0111\u1EBFn {{max}} k\xFD t\u1EF1",
2999
+ "message-text-error": " kh\xF4ng \u0111\u01B0\u1EE3c v\u01B0\u1EE3t qu\xE1 {{max}} k\xFD t\u1EF1",
3000
+ upcase: ", {{count}} ch\u1EEF in hoa",
3001
+ digit: ", {{count}} s\u1ED1",
3002
+ special: ", {{count}} k\xFD t\u1EF1 \u0111\u1EB7c bi\u1EC7t",
3003
+ upload_files_accept: "Ch\u1EC9 ch\u1EA5p nh\u1EADn c\xE1c \u0111\u1ECBnh d\u1EA1ng JPEG, PNG, PDF, MP4, XLS, XLXS, ZIP",
3004
+ show_all: "Xem t\u1EA5t c\u1EA3",
3005
+ upload_max_files: "B\u1EA1n ch\u1EC9 \u0111\u01B0\u1EE3c t\u1EA3i l\xEAn t\u1ED1i \u0111a 5 t\u1EADp tin v\xE0 5 \u1EA3nh",
3006
+ file_too_large: " M\u1ED7i file ho\u1EB7c h\xECnh \u1EA3nh dung l\u01B0\u1EE3ng t\u1ED1i \u0111a 10MB",
3007
+ remove_all: "X\xF3a t\u1EA5t c\u1EA3",
3008
+ download: "T\u1EA3i xu\u1ED1ng",
3009
+ please_enter: "Vui l\xF2ng nh\u1EADp"
3010
+ };
3011
+
3012
+ // src/locales/en.json
3013
+ var en_default = {
3014
+ "none-validated": "Invalid value",
3015
+ "search...": "Search...",
3016
+ search: "Search",
3017
+ search_more: "Search more",
3018
+ for: "for",
3019
+ cancel: "Cancel",
3020
+ choose: "Choose",
3021
+ total: "Total",
3022
+ no: "No",
3023
+ loading: "Loading",
3024
+ detail_button: "Detail",
3025
+ cancel_button: "Cancel",
3026
+ empty_data: "No data",
3027
+ new: "New",
3028
+ add_line: "Add a line",
3029
+ choose_place: "Please choose",
3030
+ filter_by: "Filter",
3031
+ group_by: "Group By",
3032
+ or: "or",
3033
+ now: "Now",
3034
+ second_ago: "seconds ago",
3035
+ minute_ago: "minutes ago",
3036
+ hour_ago: "hours ago",
3037
+ day_ago: "days ago",
3038
+ month_ago: "months ago",
3039
+ year_ago: "years ago",
3040
+ second_future: "seconds",
3041
+ minute_future: "minutes",
3042
+ hour_future: "hours",
3043
+ day_future: "days",
3044
+ month_future: "months",
3045
+ year_future: "years",
3046
+ download_file: "Download this file",
3047
+ upload_success: "Upload file success",
3048
+ upload_failure: "Upload file failure",
3049
+ file_accept_single: "Only JPEG, PNG, PDF, MP4, XLS, XLXS, ZIP, JSON formats are allowed, and each file should be up to 10MB.",
3050
+ file_accept_total: "Only JPEG, PNG, PDF, MP4, XLS, XLXS, ZIP, JSON formats are allowed, and total should be up to 50MB.",
3051
+ must_required: "is required",
3052
+ invalid_number: "Invalid number",
3053
+ active: "Active",
3054
+ in_active: "Inactive",
3055
+ upload_file_placeholder: "Upload your file",
3056
+ "no-available": "No options available",
3057
+ paid_amount: "Amount Paid",
3058
+ remanining_amount: "Amount Remaining",
3059
+ only_image_accept: "Only accept image",
3060
+ "text-only": "Only letters (no numbers or special characters)",
3061
+ "number-only": "Only enter numbers (no letters or special characters)",
3062
+ "email-only": "Invalid email address",
3063
+ "phone-only": "Invalid phone number",
3064
+ message: "Password must be between {{min}} and {{max}} characters",
3065
+ "message-text-error": " must not exceed {{max}} characters",
3066
+ upcase: ", {{count}} uppercase letter",
3067
+ digit: ", {{count}} digit",
3068
+ special: ", {{count}} special character",
3069
+ upload_files_accept: "Only JPEG, PNG, PDF, MP4, XLS, XLXS, ZIP, JSON formats are allowed",
3070
+ show_all: "Show all",
3071
+ upload_max_files: "You can only upload a maximum of 5 files and 5 images",
3072
+ file_too_large: "Image/file size exceeds the 10MB limit",
3073
+ remove_all: "Remove all",
3074
+ download: "Download",
3075
+ please_enter: "Please enter"
3076
+ };
3077
+
3078
+ // src/utils/i18n.ts
3079
+ instance.use(Browser).use(initReactI18next).init({
3080
+ resources: {
3081
+ vi: { translation: vi_default },
3082
+ en: { translation: en_default }
3083
+ },
3084
+ fallbackLng: "vi",
3085
+ lng: "vi_VN",
3086
+ debug: false,
3087
+ nonExplicitSupportedLngs: true,
3088
+ interpolation: {
3089
+ escapeValue: false
3090
+ },
3091
+ detection: {
3092
+ caches: ["cookie"]
3093
+ }
3094
+ });
3095
+
3096
+ // src/provider/index.tsx
3097
+ var import_jsx_runtime = require("react/jsx-runtime");
3098
+ var I18nContext2 = (0, import_react9.createContext)(null);
3099
+ var useI18n = () => {
3100
+ const context = (0, import_react9.useContext)(I18nContext2);
3101
+ if (!context) {
3102
+ throw new Error("useI18n must be used within I18nProvider");
3103
+ }
3104
+ return context;
3105
+ };
3106
+
3107
+ // src/utils/date.ts
3108
+ var useFormatDate = () => {
3109
+ const { t: t2 } = useI18n();
3110
+ const getRelativeTime = (dateString) => {
3111
+ const units = [
3112
+ {
3113
+ unit: "year",
3114
+ seconds: 365 * 24 * 60 * 60,
3115
+ keyPast: "year_ago",
3116
+ keyFuture: "year_future"
3117
+ },
3118
+ {
3119
+ unit: "month",
3120
+ seconds: 30 * 24 * 60 * 60,
3121
+ keyPast: "month_ago",
3122
+ keyFuture: "month_future"
3123
+ },
3124
+ {
3125
+ unit: "day",
3126
+ seconds: 24 * 60 * 60,
3127
+ keyPast: "day_ago",
3128
+ keyFuture: "day_future"
3129
+ },
3130
+ {
3131
+ unit: "hour",
3132
+ seconds: 60 * 60,
3133
+ keyPast: "hour_ago",
3134
+ keyFuture: "hour_future"
3135
+ },
3136
+ {
3137
+ unit: "minute",
3138
+ seconds: 60,
3139
+ keyPast: "minute_ago",
3140
+ keyFuture: "minute_future"
3141
+ },
3142
+ {
3143
+ unit: "second",
3144
+ seconds: 1,
3145
+ keyPast: "second_ago",
3146
+ keyFuture: "second_future"
3147
+ }
3148
+ ];
3149
+ const currentDate = /* @__PURE__ */ new Date();
3150
+ let year, month, day, hours = 0, minutes = 0, seconds = 0;
3151
+ const parts = dateString.split(/[- :]/).map(Number);
3152
+ if (parts[0] > 31) {
3153
+ ;
3154
+ [year, month, day] = parts;
3155
+ } else {
3156
+ ;
3157
+ [day, month, year] = parts;
3158
+ }
3159
+ if (parts.length > 3) [hours, minutes, seconds] = parts.slice(3);
3160
+ const givenDate = new Date(year, month - 1, day, hours, minutes, seconds);
3161
+ if (hours === 0 && minutes === 0 && seconds === 0) {
3162
+ givenDate.setHours(23, 59, 59);
3163
+ }
3164
+ const timeDifferenceInSeconds = Math.floor(
3165
+ (givenDate.getTime() - currentDate.getTime()) / 1e3
3166
+ );
3167
+ const isFuture = timeDifferenceInSeconds > 0;
3168
+ const absoluteDiff = Math.abs(timeDifferenceInSeconds);
3169
+ for (const { seconds: seconds2, keyPast, keyFuture } of units) {
3170
+ let diff = absoluteDiff / seconds2;
3171
+ if (diff >= 1) {
3172
+ diff = isFuture ? Math.ceil(diff) : Math.floor(diff);
3173
+ return isFuture ? `${diff} ${t2(keyFuture, { count: diff })}` : `${diff} ${t2(keyPast, { count: diff })}`;
3174
+ }
3175
+ }
3176
+ return t2("now");
3177
+ };
3178
+ return { getRelativeTime };
3179
+ };
3180
+ var validateAndParseDate = (input, isDateTime = false) => {
3181
+ if (!input || typeof input !== "string") return null;
3182
+ const cleanInput = input.replace(/[^0-9-\/:\s]/g, "");
3183
+ const dateFormat = "YYYY-MM-DD";
3184
+ const dateTimeFormat = "YYYY-MM-DD HH:mm:ss";
3185
+ const currentDay = (0, import_moment.default)().format("DD");
3186
+ const currentMonth = (0, import_moment.default)().format("MM");
3187
+ const currentYear = (0, import_moment.default)().format("YYYY");
3188
+ const defaultTime = "00:00:00";
3189
+ const maxYear = parseInt(currentYear) + 10;
3190
+ const isValidDate = (day, month, year) => {
3191
+ const date = (0, import_moment.default)(`${day}-${month}-${year}`, "DD-MM-YYYY", true);
3192
+ return date.isValid();
3193
+ };
3194
+ const isValidTime = (hour, minute = "00", second = "00") => {
3195
+ const h = parseInt(hour, 10);
3196
+ const m = parseInt(minute, 10);
3197
+ const s = parseInt(second, 10);
3198
+ return h >= 0 && h <= 23 && m >= 0 && m <= 59 && s >= 0 && s <= 59;
3199
+ };
3200
+ const formatOutput = (day, month, year, time = defaultTime) => {
3201
+ let result = (0, import_moment.default)(
3202
+ `${day}-${month}-${year} ${time}`,
3203
+ "DD-MM-YYYY HH:mm:ss"
3204
+ );
3205
+ if (!result.isValid()) return null;
3206
+ if (isDateTime) {
3207
+ result = result.subtract(7, "hours");
3208
+ return result.format(dateTimeFormat);
3209
+ }
3210
+ return result.format(dateFormat);
3211
+ };
3212
+ if (isDateTime && input.match(
3213
+ /^\d{1,2}[\/-]\d{1,2}[\/-]\d{2,4}\s+\d{1,2}(:\d{1,2}(:\d{1,2})?)?$/
3214
+ )) {
3215
+ const [datePart, timePart] = input.split(/\s+/);
3216
+ const dateParts = datePart.split(/[\/-]/);
3217
+ const timeParts = timePart.split(":");
3218
+ const day = dateParts[0].padStart(2, "0");
3219
+ const month = dateParts[1].padStart(2, "0");
3220
+ const year = dateParts[2].length <= 2 ? `20${dateParts[2].padStart(2, "0")}` : dateParts[2].padStart(4, "0");
3221
+ const hour = timeParts[0].padStart(2, "0");
3222
+ const minute = timeParts[1] ? timeParts[1].padStart(2, "0") : "00";
3223
+ const second = timeParts[2] ? timeParts[2].padStart(2, "0") : "00";
3224
+ if (isValidDate(day, month, year) && isValidTime(hour, minute, second)) {
3225
+ let result = (0, import_moment.default)(
3226
+ `${day}-${month}-${year} ${hour}:${minute}:${second}`,
3227
+ "DD-MM-YYYY HH:mm:ss"
3228
+ );
3229
+ if (!result.isValid()) return null;
3230
+ result = result.subtract(7, "hours");
3231
+ return result.format(dateTimeFormat);
3232
+ }
3233
+ return null;
3234
+ }
3235
+ if (cleanInput.match(/^\d{4}-\d{2}-\d{2}$/)) {
3236
+ const [year, month, day] = cleanInput.split("-");
3237
+ if (isValidDate(day, month, year)) {
3238
+ return formatOutput(day, month, year);
3239
+ }
3240
+ return null;
3241
+ }
3242
+ if (cleanInput.match(/^\d{1,2}\/\d{1,2}\/\d{2,4}$/)) {
3243
+ const [day, month, year] = cleanInput.split("/");
3244
+ const paddedDay = day.padStart(2, "0");
3245
+ const paddedMonth = month.padStart(2, "0");
3246
+ const fullYear = year.length <= 2 ? `20${year.padStart(2, "0")}` : year.padStart(4, "0");
3247
+ if (isValidDate(paddedDay, paddedMonth, fullYear)) {
3248
+ return formatOutput(paddedDay, paddedMonth, fullYear);
3249
+ }
3250
+ return null;
3251
+ }
3252
+ if (cleanInput.match(/^\d{1,2}-\d{1,2}-\d{2,4}$/)) {
3253
+ const [day, month, year] = cleanInput.split("-");
3254
+ const paddedDay = day.padStart(2, "0");
3255
+ const paddedMonth = month.padStart(2, "0");
3256
+ const fullYear = year.length <= 2 ? `20${year.padStart(2, "0")}` : year.padStart(4, "0");
3257
+ if (isValidDate(paddedDay, paddedMonth, fullYear)) {
3258
+ return formatOutput(paddedDay, paddedMonth, fullYear);
3259
+ }
3260
+ return null;
3261
+ }
3262
+ if (cleanInput.match(/^\d{1,2}[\/-]\d{1,2}$/)) {
3263
+ const [day, month] = cleanInput.split(/[\/-]/);
3264
+ const paddedDay = day.padStart(2, "0");
3265
+ const paddedMonth = month.padStart(2, "0");
3266
+ if (isValidDate(paddedDay, paddedMonth, currentYear)) {
3267
+ return formatOutput(paddedDay, paddedMonth, currentYear);
3268
+ }
3269
+ return null;
3270
+ }
3271
+ if (cleanInput.match(/^\d{4}$/)) {
3272
+ const num = parseInt(cleanInput, 10);
3273
+ if (num >= 2e3 && num <= maxYear) {
3274
+ if (isValidDate(currentDay, currentMonth, num.toString())) {
3275
+ return formatOutput(currentDay, currentMonth, num.toString());
3276
+ }
3277
+ return null;
3278
+ }
3279
+ const day = cleanInput.slice(0, 2);
3280
+ const month = cleanInput.slice(2, 4);
3281
+ if (isValidDate(day, month, currentYear)) {
3282
+ return formatOutput(day, month, currentYear);
3283
+ }
3284
+ return null;
3285
+ }
3286
+ if (cleanInput.startsWith("-") && /^\-\d+$/.test(cleanInput)) {
3287
+ const daysToSubtract = Math.abs(parseInt(cleanInput, 10));
3288
+ let result = (0, import_moment.default)().subtract(daysToSubtract, "days");
3289
+ if (isDateTime) {
3290
+ result = result.subtract(7, "hours");
3291
+ }
3292
+ if (result.isValid()) {
3293
+ return isDateTime ? result.format(dateTimeFormat) : result.format(dateFormat);
3294
+ }
3295
+ return null;
3296
+ }
3297
+ if (input.match(/^\d{1,2}[^0-9-\/]+\d{1,2}[^0-9-\/]+\d{2,4}.*$/)) {
3298
+ const parts = input.split(/[^0-9-\/]+/).filter(Boolean);
3299
+ const day = parts[0].padStart(2, "0");
3300
+ const month = parts[1].padStart(2, "0");
3301
+ let year = parts[2];
3302
+ year = year.length === 2 ? `20${year}` : year.padStart(4, "0");
3303
+ if (isValidDate(day, month, year)) {
3304
+ return formatOutput(day, month, year);
3305
+ }
3306
+ return null;
3307
+ }
3308
+ if (isDateTime) {
3309
+ if (cleanInput.length === 9) {
3310
+ const day = cleanInput.slice(0, 2);
3311
+ const month = cleanInput.slice(2, 4);
3312
+ const year = cleanInput.slice(4, 8);
3313
+ const hour = cleanInput.slice(8, 9).padStart(2, "0");
3314
+ if (isValidDate(day, month, year) && isValidTime(hour)) {
3315
+ let result = (0, import_moment.default)(
3316
+ `${day}-${month}-${year} ${hour}:00:00`,
3317
+ "DD-MM-YYYY HH:mm:ss"
3318
+ );
3319
+ if (!result.isValid()) return null;
3320
+ result = result.subtract(7, "hours");
3321
+ return result.format(dateTimeFormat);
3322
+ }
3323
+ return null;
3324
+ }
3325
+ if (cleanInput.length === 10) {
3326
+ const day = cleanInput.slice(0, 2);
3327
+ const month = cleanInput.slice(2, 4);
3328
+ const year = cleanInput.slice(4, 8);
3329
+ const hour = cleanInput.slice(8, 10);
3330
+ if (isValidDate(day, month, year) && isValidTime(hour)) {
3331
+ let result = (0, import_moment.default)(
3332
+ `${day}-${month}-${year} ${hour}:00:00`,
3333
+ "DD-MM-YYYY HH:mm:ss"
3334
+ );
3335
+ if (!result.isValid()) return null;
3336
+ result = result.subtract(7, "hours");
3337
+ return result.format(dateTimeFormat);
3338
+ }
3339
+ return null;
3340
+ }
3341
+ if (cleanInput.length === 11) {
3342
+ const day = cleanInput.slice(0, 2);
3343
+ const month = cleanInput.slice(2, 4);
3344
+ const year = cleanInput.slice(4, 8);
3345
+ const hour = cleanInput.slice(8, 10);
3346
+ const minute = cleanInput.slice(10, 11).padStart(2, "0");
3347
+ if (isValidDate(day, month, year) && isValidTime(hour, minute)) {
3348
+ let result = (0, import_moment.default)(
3349
+ `${day}-${month}-${year} ${hour}:${minute}:00`,
3350
+ "DD-MM-YYYY HH:mm:ss"
3351
+ );
3352
+ if (!result.isValid()) return null;
3353
+ result = result.subtract(7, "hours");
3354
+ return result.format(dateTimeFormat);
3355
+ }
3356
+ return null;
3357
+ }
3358
+ if (cleanInput.length === 12) {
3359
+ const day = cleanInput.slice(0, 2);
3360
+ const month = cleanInput.slice(2, 4);
3361
+ const year = cleanInput.slice(4, 8);
3362
+ const hour = cleanInput.slice(8, 10);
3363
+ const minute = cleanInput.slice(10, 12);
3364
+ if (isValidDate(day, month, year) && isValidTime(hour, minute)) {
3365
+ let result = (0, import_moment.default)(
3366
+ `${day}-${month}-${year} ${hour}:${minute}:00`,
3367
+ "DD-MM-YYYY HH:mm:ss"
3368
+ );
3369
+ if (!result.isValid()) return null;
3370
+ result = result.subtract(7, "hours");
3371
+ return result.format(dateTimeFormat);
3372
+ }
3373
+ return null;
3374
+ }
3375
+ if (cleanInput.length === 13) {
3376
+ const day = cleanInput.slice(0, 2);
3377
+ const month = cleanInput.slice(2, 4);
3378
+ const year = cleanInput.slice(4, 8);
3379
+ const hour = cleanInput.slice(8, 10);
3380
+ const minute = cleanInput.slice(10, 12);
3381
+ const second = cleanInput.slice(12, 13).padStart(2, "0");
3382
+ if (isValidDate(day, month, year) && isValidTime(hour, minute, second)) {
3383
+ let result = (0, import_moment.default)(
3384
+ `${day}-${month}-${year} ${hour}:${minute}:${second}`,
3385
+ "DD-MM-YYYY HH:mm:ss"
3386
+ );
3387
+ if (!result.isValid()) return null;
3388
+ result = result.subtract(7, "hours");
3389
+ return result.format(dateTimeFormat);
3390
+ }
3391
+ return null;
3392
+ }
3393
+ if (cleanInput.length === 14) {
3394
+ const day = cleanInput.slice(0, 2);
3395
+ const month = cleanInput.slice(2, 4);
3396
+ const year = cleanInput.slice(4, 8);
3397
+ const hour = cleanInput.slice(8, 10);
3398
+ const minute = cleanInput.slice(10, 12);
3399
+ const second = cleanInput.slice(12, 14);
3400
+ if (isValidDate(day, month, year) && isValidTime(hour, minute, second)) {
3401
+ let result = (0, import_moment.default)(
3402
+ `${day}-${month}-${year} ${hour}:${minute}:${second}`,
3403
+ "DD-MM-YYYY HH:mm:ss"
3404
+ );
3405
+ if (!result.isValid()) return null;
3406
+ result = result.subtract(7, "hours");
3407
+ return result.format(dateTimeFormat);
3408
+ }
3409
+ return null;
3410
+ }
3411
+ }
3412
+ const len = cleanInput.length;
3413
+ if (len === 1 || len === 2) {
3414
+ const paddedDay = cleanInput.padStart(2, "0");
3415
+ if (isValidDate(paddedDay, currentMonth, currentYear)) {
3416
+ return formatOutput(paddedDay, currentMonth, currentYear);
3417
+ }
3418
+ return null;
3419
+ }
3420
+ if (len === 3) {
3421
+ const day = cleanInput.slice(0, 2);
3422
+ const month = cleanInput.slice(2, 3).padStart(2, "0");
3423
+ if (isValidDate(day, month, currentYear)) {
3424
+ return formatOutput(day, month, currentYear);
3425
+ }
3426
+ return null;
3427
+ }
3428
+ if (len === 6) {
3429
+ const day = cleanInput.slice(0, 2);
3430
+ const month = cleanInput.slice(2, 4);
3431
+ let year = cleanInput.slice(4, 6);
3432
+ year = `20${year}`;
3433
+ if (parseInt(month) > 12) {
3434
+ if (isValidDate(day, currentMonth, currentYear)) {
3435
+ return formatOutput(day, currentMonth, currentYear);
3436
+ }
3437
+ return null;
3438
+ }
3439
+ if (isValidDate(day, month, year)) {
3440
+ return formatOutput(day, month, year);
3441
+ }
3442
+ return null;
3443
+ }
3444
+ if (len === 7) {
3445
+ return null;
3446
+ }
3447
+ if (len === 8) {
3448
+ const day = cleanInput.slice(0, 2);
3449
+ const month = cleanInput.slice(2, 4);
3450
+ const year = cleanInput.slice(4, 8);
3451
+ if (isValidDate(day, month, year)) {
3452
+ return formatOutput(day, month, year);
3453
+ }
3454
+ return null;
3455
+ }
3456
+ if (len > 8 && !isDateTime) {
3457
+ return null;
3458
+ }
3459
+ return null;
3460
+ };
3461
+
3462
+ // src/utils/color.ts
3463
+ var generateTagColors = (name, id) => {
3464
+ const combined = name + id / 2;
3465
+ let hash2 = 0;
3466
+ for (let i = 0; i < combined.length; i++) {
3467
+ hash2 = combined.charCodeAt(i) + ((hash2 << 5) - hash2);
3468
+ }
3469
+ const r = hash2 >> 16 & 255;
3470
+ const g = hash2 >> 8 & 255;
3471
+ const b = hash2 & 255;
3472
+ const rNorm = r / 255;
3473
+ const gNorm = g / 255;
3474
+ const bNorm = b / 255;
3475
+ const max = Math.max(rNorm, gNorm, bNorm);
3476
+ const min = Math.min(rNorm, gNorm, bNorm);
3477
+ const delta = max - min;
3478
+ let h = 0;
3479
+ if (delta !== 0) {
3480
+ if (max === rNorm) h = (gNorm - bNorm) / delta % 6;
3481
+ else if (max === gNorm) h = (bNorm - rNorm) / delta + 2;
3482
+ else h = (rNorm - gNorm) / delta + 4;
3483
+ }
3484
+ h = Math.round(h * 60);
3485
+ if (h < 0) h += 360;
3486
+ const bgS = 0.35;
3487
+ const bgL = 0.92;
3488
+ const borderS = 0.45;
3489
+ const borderL = 0.78;
3490
+ const textS = 0.55;
3491
+ const textL = 0.32;
3492
+ const hslToRgb = (h2, s, l) => {
3493
+ const c = (1 - Math.abs(2 * l - 1)) * s;
3494
+ const x = c * (1 - Math.abs(h2 / 60 % 2 - 1));
3495
+ const m = l - c / 2;
3496
+ let r2 = 0, g2 = 0, b2 = 0;
3497
+ if (0 <= h2 && h2 < 60) [r2, g2, b2] = [c, x, 0];
3498
+ else if (60 <= h2 && h2 < 120) [r2, g2, b2] = [x, c, 0];
3499
+ else if (120 <= h2 && h2 < 180) [r2, g2, b2] = [0, c, x];
3500
+ else if (180 <= h2 && h2 < 240) [r2, g2, b2] = [0, x, c];
3501
+ else if (240 <= h2 && h2 < 300) [r2, g2, b2] = [x, 0, c];
3502
+ else [r2, g2, b2] = [c, 0, x];
3503
+ return `rgb(${Math.round((r2 + m) * 255)}, ${Math.round(
3504
+ (g2 + m) * 255
3505
+ )}, ${Math.round((b2 + m) * 255)})`;
3506
+ };
3507
+ return {
3508
+ background: hslToRgb(h, bgS, bgL),
3509
+ // nh?t nh?t
3510
+ border: hslToRgb(h, borderS, borderL),
3511
+ // d?m hon background
3512
+ textColor: hslToRgb(h, textS, textL)
3513
+ // d?m nh?t
3514
+ };
3515
+ };
3516
+
3517
+ // src/utils/constants.ts
3518
+ var COLORS = [
3519
+ {
3520
+ name: "no_color",
3521
+ color: "RGBA(230.1375,221.3625,221.3625,1)",
3522
+ id: 0
3523
+ },
3524
+ {
3525
+ name: "red",
3526
+ color: "rgba(255,155.5,155.5,1)",
3527
+ id: 1
3528
+ },
3529
+ {
3530
+ name: "orange",
3531
+ color: "RGBA(247.0375,198.06116071,152.4625,1)",
3532
+ id: 2
3533
+ },
3534
+ {
3535
+ name: "yellow",
3536
+ color: "RGBA(252.88960843, 226.89175248, 135.61039157,1)",
3537
+ id: 3
3538
+ },
3539
+ {
3540
+ name: "cyan",
3541
+ color: "RGBA(187.45210396, 215.03675558, 248.04789604,1)",
3542
+ id: 4
3543
+ },
3544
+ {
3545
+ name: "purple",
3546
+ color: "RGBA(216.79194664, 167.70805336, 203.91748283,1)",
3547
+ id: 5
3548
+ },
3549
+ {
3550
+ name: "almond",
3551
+ color: "RGBA(247.84539474, 213.9484835, 199.65460526,1)",
3552
+ id: 6
3553
+ },
3554
+ {
3555
+ name: "teal",
3556
+ color: "RGBA(136.6125, 224.8875, 218.94591346,1)",
3557
+ id: 7
3558
+ },
3559
+ {
3560
+ name: "blue",
3561
+ color: "RGBA(150.60535714, 165.68382711, 248.89464286,1)",
3562
+ id: 8
3563
+ },
3564
+ {
3565
+ name: "raspberry",
3566
+ color: "RGBA(254.94583333, 157.55416667, 203.95543194,1)",
3567
+ id: 9
3568
+ },
3569
+ {
3570
+ name: "green",
3571
+ color: "RGBA(182.62075688, 236.87924312, 189.81831118,1)",
3572
+ id: 10
3573
+ },
3574
+ {
3575
+ name: "violet",
3576
+ color: "RGBA(230.11575613, 219.41069277, 252.08930723,1)",
3577
+ id: 11
3578
+ }
3579
+ ];
3580
+ var DOTS = "...";
3581
+ var SearchType = {
3582
+ FILTER: "filter_by",
3583
+ SEARCH: "search_by",
3584
+ GROUP: "group_by"
3585
+ };
3586
+ var MAX_FILE_SIZE = 10 * 1024 * 1024;
3587
+ // Annotate the CommonJS export names for ESM import in node:
3588
+ 0 && (module.exports = {
3589
+ ACCEPT_TYPES,
3590
+ ALLOWED_EXTS,
3591
+ ALLOWED_MIME_TYPES,
3592
+ COLORS,
3593
+ DOTS,
3594
+ SearchType,
3595
+ checkIsImageLink,
3596
+ convertFloatToTime,
3597
+ convertTimeToFloat,
3598
+ formatFileSize,
3599
+ formatFloatNumber,
3600
+ formatNumberOnly,
3601
+ generateTagColors,
3602
+ getFileLabel,
3603
+ getPasswordMessage,
3604
+ isBase64Image,
3605
+ parseFormattedNumber,
3606
+ range,
3607
+ uppercaseFirstLetter,
3608
+ useFormatDate,
3609
+ validateAndParseDate,
3610
+ validateInput
3611
+ });