@dcloudio/uni-cli-shared 3.0.0-5020320260806002 → 3.0.0-5020420260811002

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/resolve.d.ts +8 -0
  2. package/dist/resolve.js +78 -2
  3. package/lib/dom2/@intlify/core-base/LICENSE +20 -0
  4. package/lib/dom2/@intlify/core-base/dist/core-base.mjs +1903 -0
  5. package/lib/dom2/@intlify/core-base/package.json +11 -0
  6. package/lib/dom2/@intlify/message-compiler/LICENSE +20 -0
  7. package/lib/dom2/@intlify/message-compiler/dist/message-compiler.mjs +1550 -0
  8. package/lib/dom2/@intlify/message-compiler/package.json +11 -0
  9. package/lib/dom2/@intlify/shared/LICENSE +20 -0
  10. package/lib/dom2/@intlify/shared/dist/shared.mjs +333 -0
  11. package/lib/dom2/@intlify/shared/package.json +11 -0
  12. package/lib/dom2/@vue/devtools-api/LICENSE +21 -0
  13. package/lib/dom2/@vue/devtools-api/dist/index.js +26 -0
  14. package/lib/dom2/@vue/devtools-api/package.json +12 -0
  15. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +71 -68
  16. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +71 -68
  17. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +2 -20
  18. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +53 -29
  19. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +23 -12
  20. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +22 -12
  21. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +80 -30
  22. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +5 -5
  23. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +20 -3
  24. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +369 -317
  25. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +5 -5
  26. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +2032 -5522
  27. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.d.ts +11114 -33
  28. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +2825 -4668
  29. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +905 -2413
  30. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +378 -544
  31. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +998 -2549
  32. package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -1
  33. package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +26 -92
  34. package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +26 -92
  35. package/lib/dom2/app/@vue/shared/dist/shared.d.ts +2 -94
  36. package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +24 -83
  37. package/lib/dom2/pinia/LICENSE +21 -0
  38. package/lib/dom2/pinia/dist/pinia.mjs +1941 -0
  39. package/lib/dom2/pinia/package.json +11 -0
  40. package/lib/dom2/vue-i18n/LICENSE +20 -0
  41. package/lib/dom2/vue-i18n/dist/vue-i18n.esm-bundler.js +1 -0
  42. package/lib/dom2/vue-i18n/dist/vue-i18n.mjs +2501 -0
  43. package/lib/dom2/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js +1 -0
  44. package/lib/dom2/vue-i18n/dist/vue-i18n.runtime.mjs +2501 -0
  45. package/lib/dom2/vue-i18n/package.json +12 -0
  46. package/package.json +5 -5
@@ -0,0 +1,1903 @@
1
+ /*!
2
+ * core-base v11.4.6
3
+ * (c) 2026 kazuya kawaguchi
4
+ * Released under the MIT License.
5
+ */
6
+ import { getGlobalThis, isObject, hasOwn, isNumber, create, isString, isBoolean, warn, format as format$1, isArray, isPlainObject, isFunction, isPromise, assign, isRegExp, warnOnce, isDate, isEmptyObject, toDisplayString, join, sanitizeTranslatedHtml, escapeHtml, inBrowser, mark, measure, generateFormatCacheKey, generateCodeFrame } from '@intlify/shared';
7
+ import { detectHtmlTag, defaultOnError, baseCompile as baseCompile$1, COMPILE_ERROR_CODES_EXTEND_POINT, createCompileError } from '@intlify/message-compiler';
8
+ export { CompileErrorCodes, createCompileError } from '@intlify/message-compiler';
9
+
10
+ /**
11
+ * This is only called in esm-bundler builds.
12
+ * istanbul-ignore-next
13
+ */
14
+ function initFeatureFlags() {
15
+ if (typeof __INTLIFY_PROD_DEVTOOLS__ !== 'boolean') {
16
+ getGlobalThis().__INTLIFY_PROD_DEVTOOLS__ = false;
17
+ }
18
+ if (typeof __INTLIFY_DROP_MESSAGE_COMPILER__ !== 'boolean') {
19
+ getGlobalThis().__INTLIFY_DROP_MESSAGE_COMPILER__ = false;
20
+ }
21
+ }
22
+
23
+ function isMessageAST(val) {
24
+ return (isObject(val) &&
25
+ resolveType(val) === 0 &&
26
+ (hasOwn(val, 'b') || hasOwn(val, 'body')));
27
+ }
28
+ const PROPS_BODY = ['b', 'body'];
29
+ function resolveBody(node) {
30
+ return resolveProps(node, PROPS_BODY);
31
+ }
32
+ const PROPS_CASES = ['c', 'cases'];
33
+ function resolveCases(node) {
34
+ return resolveProps(node, PROPS_CASES, []);
35
+ }
36
+ const PROPS_STATIC = ['s', 'static'];
37
+ function resolveStatic(node) {
38
+ return resolveProps(node, PROPS_STATIC);
39
+ }
40
+ const PROPS_ITEMS = ['i', 'items'];
41
+ function resolveItems(node) {
42
+ return resolveProps(node, PROPS_ITEMS, []);
43
+ }
44
+ const PROPS_TYPE = ['t', 'type'];
45
+ function resolveType(node) {
46
+ return resolveProps(node, PROPS_TYPE);
47
+ }
48
+ const PROPS_VALUE = ['v', 'value'];
49
+ function resolveValue$1(node, type) {
50
+ const resolved = resolveProps(node, PROPS_VALUE);
51
+ if (resolved != null) {
52
+ return resolved;
53
+ }
54
+ else {
55
+ throw createUnhandleNodeError(type);
56
+ }
57
+ }
58
+ const PROPS_MODIFIER = ['m', 'modifier'];
59
+ function resolveLinkedModifier(node) {
60
+ return resolveProps(node, PROPS_MODIFIER);
61
+ }
62
+ const PROPS_KEY = ['k', 'key'];
63
+ function resolveLinkedKey(node) {
64
+ const resolved = resolveProps(node, PROPS_KEY);
65
+ if (resolved) {
66
+ return resolved;
67
+ }
68
+ else {
69
+ throw createUnhandleNodeError(6 /* NodeTypes.Linked */);
70
+ }
71
+ }
72
+ function resolveProps(node, props, defaultValue) {
73
+ for (let i = 0; i < props.length; i++) {
74
+ const prop = props[i];
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ if (hasOwn(node, prop) && node[prop] != null) {
77
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
+ return node[prop];
79
+ }
80
+ }
81
+ return defaultValue;
82
+ }
83
+ const AST_NODE_PROPS_KEYS = [
84
+ ...PROPS_BODY,
85
+ ...PROPS_CASES,
86
+ ...PROPS_STATIC,
87
+ ...PROPS_ITEMS,
88
+ ...PROPS_KEY,
89
+ ...PROPS_MODIFIER,
90
+ ...PROPS_VALUE,
91
+ ...PROPS_TYPE
92
+ ];
93
+ function createUnhandleNodeError(type) {
94
+ return new Error(`unhandled node type: ${type}`);
95
+ }
96
+
97
+ function format(ast) {
98
+ const msg = (ctx) => formatParts(ctx, ast);
99
+ return msg;
100
+ }
101
+ function formatParts(ctx, ast) {
102
+ const body = resolveBody(ast);
103
+ if (body == null) {
104
+ throw createUnhandleNodeError(0 /* NodeTypes.Resource */);
105
+ }
106
+ const type = resolveType(body);
107
+ if (type === 1 /* NodeTypes.Plural */) {
108
+ const plural = body;
109
+ const cases = resolveCases(plural);
110
+ return ctx.plural(cases.reduce((messages, c) => [
111
+ ...messages,
112
+ formatMessageParts(ctx, c)
113
+ ], []));
114
+ }
115
+ else {
116
+ return formatMessageParts(ctx, body);
117
+ }
118
+ }
119
+ function formatMessageParts(ctx, node) {
120
+ const static_ = resolveStatic(node);
121
+ if (static_ != null) {
122
+ return ctx.type === 'text'
123
+ ? static_
124
+ : ctx.normalize([static_]);
125
+ }
126
+ else {
127
+ const messages = resolveItems(node).reduce((acm, c) => [...acm, formatMessagePart(ctx, c)], []);
128
+ return ctx.normalize(messages);
129
+ }
130
+ }
131
+ function formatMessagePart(ctx, node) {
132
+ const type = resolveType(node);
133
+ switch (type) {
134
+ case 3 /* NodeTypes.Text */: {
135
+ return resolveValue$1(node, type);
136
+ }
137
+ case 9 /* NodeTypes.Literal */: {
138
+ return resolveValue$1(node, type);
139
+ }
140
+ case 4 /* NodeTypes.Named */: {
141
+ const named = node;
142
+ if (hasOwn(named, 'k') && named.k) {
143
+ return ctx.interpolate(ctx.named(named.k));
144
+ }
145
+ if (hasOwn(named, 'key') && named.key) {
146
+ return ctx.interpolate(ctx.named(named.key));
147
+ }
148
+ throw createUnhandleNodeError(type);
149
+ }
150
+ case 5 /* NodeTypes.List */: {
151
+ const list = node;
152
+ if (hasOwn(list, 'i') && isNumber(list.i)) {
153
+ return ctx.interpolate(ctx.list(list.i));
154
+ }
155
+ if (hasOwn(list, 'index') && isNumber(list.index)) {
156
+ return ctx.interpolate(ctx.list(list.index));
157
+ }
158
+ throw createUnhandleNodeError(type);
159
+ }
160
+ case 6 /* NodeTypes.Linked */: {
161
+ const linked = node;
162
+ const modifier = resolveLinkedModifier(linked);
163
+ const key = resolveLinkedKey(linked);
164
+ return ctx.linked(formatMessagePart(ctx, key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
165
+ }
166
+ case 7 /* NodeTypes.LinkedKey */: {
167
+ return resolveValue$1(node, type);
168
+ }
169
+ case 8 /* NodeTypes.LinkedModifier */: {
170
+ return resolveValue$1(node, type);
171
+ }
172
+ default:
173
+ throw new Error(`unhandled node on format message part: ${type}`);
174
+ }
175
+ }
176
+
177
+ const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
178
+ function checkHtmlMessage(source, warnHtmlMessage) {
179
+ if (warnHtmlMessage && detectHtmlTag(source)) {
180
+ warn(format$1(WARN_MESSAGE, { source }));
181
+ }
182
+ }
183
+ const defaultOnCacheKey = (message) => message;
184
+ let compileCache = create();
185
+ function clearCompileCache() {
186
+ compileCache = create();
187
+ }
188
+ function baseCompile(message, options = {}) {
189
+ // error detecting on compile
190
+ let detectError = false;
191
+ const onError = options.onError || defaultOnError;
192
+ options.onError = (err) => {
193
+ detectError = true;
194
+ onError(err);
195
+ };
196
+ // compile with mesasge-compiler
197
+ return { ...baseCompile$1(message, options), detectError };
198
+ }
199
+ /* #__NO_SIDE_EFFECTS__ */
200
+ function compile(message, context) {
201
+ if ((!__INTLIFY_DROP_MESSAGE_COMPILER__) &&
202
+ isString(message)) {
203
+ // check HTML message
204
+ const warnHtmlMessage = isBoolean(context.warnHtmlMessage)
205
+ ? context.warnHtmlMessage
206
+ : true;
207
+ (process.env.NODE_ENV !== 'production') && checkHtmlMessage(message, warnHtmlMessage);
208
+ // check caches
209
+ const onCacheKey = context.onCacheKey || defaultOnCacheKey;
210
+ const cacheKey = onCacheKey(message);
211
+ const cached = compileCache[cacheKey];
212
+ if (cached) {
213
+ return cached;
214
+ }
215
+ // compile with JIT mode
216
+ const { ast, detectError } = baseCompile(message, {
217
+ ...context,
218
+ location: (process.env.NODE_ENV !== 'production'),
219
+ jit: true
220
+ });
221
+ // compose message function from AST
222
+ const msg = format(ast);
223
+ // if occurred compile error, don't cache
224
+ return !detectError
225
+ ? (compileCache[cacheKey] = msg)
226
+ : msg;
227
+ }
228
+ else {
229
+ if ((process.env.NODE_ENV !== 'production') && !isMessageAST(message)) {
230
+ warn(`the message that is resolve with key '${context.key}' is not supported for jit compilation`);
231
+ return (() => message);
232
+ }
233
+ // AST case (passed from bundler)
234
+ const cacheKey = message.cacheKey;
235
+ if (cacheKey) {
236
+ const cached = compileCache[cacheKey];
237
+ if (cached) {
238
+ return cached;
239
+ }
240
+ // compose message function from message (AST)
241
+ return (compileCache[cacheKey] =
242
+ format(message));
243
+ }
244
+ else {
245
+ return format(message);
246
+ }
247
+ }
248
+ }
249
+
250
+ let devtools = null;
251
+ function setDevToolsHook(hook) {
252
+ devtools = hook;
253
+ }
254
+ function getDevToolsHook() {
255
+ return devtools;
256
+ }
257
+ function initI18nDevTools(i18n, version, meta) {
258
+ // TODO: queue if devtools is undefined
259
+ devtools &&
260
+ devtools.emit('i18n:init', {
261
+ timestamp: Date.now(),
262
+ i18n,
263
+ version,
264
+ meta
265
+ });
266
+ }
267
+ const translateDevTools =
268
+ /* #__PURE__*/ createDevToolsHook('function:translate');
269
+ function createDevToolsHook(hook) {
270
+ return (payloads) => devtools && devtools.emit(hook, payloads);
271
+ }
272
+
273
+ const CoreErrorCodes = {
274
+ INVALID_ARGUMENT: COMPILE_ERROR_CODES_EXTEND_POINT, // 17
275
+ INVALID_DATE_ARGUMENT: 18,
276
+ INVALID_ISO_DATE_ARGUMENT: 19,
277
+ NOT_SUPPORT_NON_STRING_MESSAGE: 20,
278
+ NOT_SUPPORT_LOCALE_PROMISE_VALUE: 21,
279
+ NOT_SUPPORT_LOCALE_ASYNC_FUNCTION: 22,
280
+ NOT_SUPPORT_LOCALE_TYPE: 23
281
+ };
282
+ const CORE_ERROR_CODES_EXTEND_POINT = 24;
283
+ function createCoreError(code) {
284
+ return createCompileError(code, null, (process.env.NODE_ENV !== 'production') ? { messages: errorMessages } : undefined);
285
+ }
286
+ /** @internal */
287
+ const errorMessages = {
288
+ [CoreErrorCodes.INVALID_ARGUMENT]: 'Invalid arguments',
289
+ [CoreErrorCodes.INVALID_DATE_ARGUMENT]: 'The date provided is an invalid Date object.' +
290
+ 'Make sure your Date represents a valid date.',
291
+ [CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: 'The argument provided is not a valid ISO date string',
292
+ [CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE]: 'Not support non-string message',
293
+ [CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE]: 'cannot support promise value',
294
+ [CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION]: 'cannot support async function',
295
+ [CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE]: 'cannot support locale type'
296
+ };
297
+
298
+ /** @internal */
299
+ function getLocale(context, options) {
300
+ return options.locale != null
301
+ ? resolveLocale(options.locale)
302
+ : resolveLocale(context.locale);
303
+ }
304
+ let _resolveLocale;
305
+ /** @internal */
306
+ function resolveLocale(locale) {
307
+ if (isString(locale)) {
308
+ return locale;
309
+ }
310
+ else {
311
+ if (isFunction(locale)) {
312
+ if (locale.resolvedOnce && _resolveLocale != null) {
313
+ return _resolveLocale;
314
+ }
315
+ else if (locale.constructor.name === 'Function') {
316
+ const resolve = locale();
317
+ if (isPromise(resolve)) {
318
+ throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE);
319
+ }
320
+ return (_resolveLocale = resolve);
321
+ }
322
+ else {
323
+ throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION);
324
+ }
325
+ }
326
+ else {
327
+ throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE);
328
+ }
329
+ }
330
+ }
331
+ /**
332
+ * Fallback with simple implemenation
333
+ *
334
+ * @remarks
335
+ * A fallback locale function implemented with a simple fallback algorithm.
336
+ *
337
+ * Basically, it returns the value as specified in the `fallbackLocale` props, and is processed with the fallback inside intlify.
338
+ *
339
+ * @param ctx - A {@link CoreContext | context}
340
+ * @param fallback - A {@link FallbackLocale | fallback locale}
341
+ * @param start - A starting {@link Locale | locale}
342
+ *
343
+ * @returns Fallback locales
344
+ *
345
+ * @VueI18nGeneral
346
+ */
347
+ function fallbackWithSimple(ctx, fallback, start) {
348
+ // prettier-ignore
349
+ return [...new Set([
350
+ start,
351
+ ...(isArray(fallback)
352
+ ? fallback
353
+ : isObject(fallback)
354
+ ? Object.keys(fallback)
355
+ : isString(fallback)
356
+ ? [fallback]
357
+ : [start])
358
+ ])];
359
+ }
360
+ /**
361
+ * Fallback with locale chain
362
+ *
363
+ * @remarks
364
+ * A fallback locale function implemented with a fallback chain algorithm. It's used in VueI18n as default.
365
+ *
366
+ * @param ctx - A {@link CoreContext | context}
367
+ * @param fallback - A {@link FallbackLocale | fallback locale}
368
+ * @param start - A starting {@link Locale | locale}
369
+ *
370
+ * @returns Fallback locales
371
+ *
372
+ * @VueI18nSee [Fallbacking](../guide/essentials/fallback)
373
+ *
374
+ * @VueI18nGeneral
375
+ */
376
+ function fallbackWithLocaleChain(ctx, fallback, start) {
377
+ const startLocale = isString(start) ? start : DEFAULT_LOCALE;
378
+ const context = ctx;
379
+ if (!context.__localeChainCache) {
380
+ context.__localeChainCache = new Map();
381
+ }
382
+ let chain = context.__localeChainCache.get(startLocale);
383
+ if (!chain) {
384
+ chain = [];
385
+ // first block defined by start
386
+ let block = [start];
387
+ // while any intervening block found
388
+ while (isArray(block)) {
389
+ block = appendBlockToChain(chain, block, fallback);
390
+ }
391
+ // prettier-ignore
392
+ // last block defined by default
393
+ const defaults = isArray(fallback) || !isPlainObject(fallback)
394
+ ? fallback
395
+ : fallback['default']
396
+ ? fallback['default']
397
+ : null;
398
+ // convert defaults to array
399
+ block = isString(defaults) ? [defaults] : defaults;
400
+ if (isArray(block)) {
401
+ appendBlockToChain(chain, block, false);
402
+ }
403
+ context.__localeChainCache.set(startLocale, chain);
404
+ }
405
+ return chain;
406
+ }
407
+ function appendBlockToChain(chain, block, blocks) {
408
+ let follow = true;
409
+ for (let i = 0; i < block.length && isBoolean(follow); i++) {
410
+ const locale = block[i];
411
+ if (isString(locale)) {
412
+ follow = appendLocaleToChain(chain, block[i], blocks);
413
+ }
414
+ }
415
+ return follow;
416
+ }
417
+ function appendLocaleToChain(chain, locale, blocks) {
418
+ let follow;
419
+ const tokens = locale.split('-');
420
+ do {
421
+ const target = tokens.join('-');
422
+ follow = appendItemToChain(chain, target, blocks);
423
+ tokens.splice(-1, 1);
424
+ } while (tokens.length && follow === true);
425
+ return follow;
426
+ }
427
+ function appendItemToChain(chain, target, blocks) {
428
+ let follow = false;
429
+ if (!chain.includes(target)) {
430
+ follow = true;
431
+ if (target) {
432
+ follow = target[target.length - 1] !== '!';
433
+ const locale = target.replace(/!/g, '');
434
+ chain.push(locale);
435
+ if ((isArray(blocks) || isPlainObject(blocks)) &&
436
+ blocks[locale] // eslint-disable-line @typescript-eslint/no-explicit-any
437
+ ) {
438
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
439
+ follow = blocks[locale];
440
+ }
441
+ }
442
+ }
443
+ return follow;
444
+ }
445
+
446
+ const pathStateMachine = [];
447
+ pathStateMachine[0 /* States.BEFORE_PATH */] = {
448
+ ["w" /* PathCharTypes.WORKSPACE */]: [0 /* States.BEFORE_PATH */],
449
+ ["i" /* PathCharTypes.IDENT */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
450
+ ["[" /* PathCharTypes.LEFT_BRACKET */]: [4 /* States.IN_SUB_PATH */],
451
+ ["o" /* PathCharTypes.END_OF_FAIL */]: [7 /* States.AFTER_PATH */]
452
+ };
453
+ pathStateMachine[1 /* States.IN_PATH */] = {
454
+ ["w" /* PathCharTypes.WORKSPACE */]: [1 /* States.IN_PATH */],
455
+ ["." /* PathCharTypes.DOT */]: [2 /* States.BEFORE_IDENT */],
456
+ ["[" /* PathCharTypes.LEFT_BRACKET */]: [4 /* States.IN_SUB_PATH */],
457
+ ["o" /* PathCharTypes.END_OF_FAIL */]: [7 /* States.AFTER_PATH */]
458
+ };
459
+ pathStateMachine[2 /* States.BEFORE_IDENT */] = {
460
+ ["w" /* PathCharTypes.WORKSPACE */]: [2 /* States.BEFORE_IDENT */],
461
+ ["i" /* PathCharTypes.IDENT */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
462
+ ["0" /* PathCharTypes.ZERO */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */]
463
+ };
464
+ pathStateMachine[3 /* States.IN_IDENT */] = {
465
+ ["i" /* PathCharTypes.IDENT */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
466
+ ["0" /* PathCharTypes.ZERO */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
467
+ ["w" /* PathCharTypes.WORKSPACE */]: [1 /* States.IN_PATH */, 1 /* Actions.PUSH */],
468
+ ["." /* PathCharTypes.DOT */]: [2 /* States.BEFORE_IDENT */, 1 /* Actions.PUSH */],
469
+ ["[" /* PathCharTypes.LEFT_BRACKET */]: [4 /* States.IN_SUB_PATH */, 1 /* Actions.PUSH */],
470
+ ["o" /* PathCharTypes.END_OF_FAIL */]: [7 /* States.AFTER_PATH */, 1 /* Actions.PUSH */]
471
+ };
472
+ pathStateMachine[4 /* States.IN_SUB_PATH */] = {
473
+ ["'" /* PathCharTypes.SINGLE_QUOTE */]: [5 /* States.IN_SINGLE_QUOTE */, 0 /* Actions.APPEND */],
474
+ ["\"" /* PathCharTypes.DOUBLE_QUOTE */]: [6 /* States.IN_DOUBLE_QUOTE */, 0 /* Actions.APPEND */],
475
+ ["[" /* PathCharTypes.LEFT_BRACKET */]: [
476
+ 4 /* States.IN_SUB_PATH */,
477
+ 2 /* Actions.INC_SUB_PATH_DEPTH */
478
+ ],
479
+ ["]" /* PathCharTypes.RIGHT_BRACKET */]: [1 /* States.IN_PATH */, 3 /* Actions.PUSH_SUB_PATH */],
480
+ ["o" /* PathCharTypes.END_OF_FAIL */]: 8 /* States.ERROR */,
481
+ ["l" /* PathCharTypes.ELSE */]: [4 /* States.IN_SUB_PATH */, 0 /* Actions.APPEND */]
482
+ };
483
+ pathStateMachine[5 /* States.IN_SINGLE_QUOTE */] = {
484
+ ["'" /* PathCharTypes.SINGLE_QUOTE */]: [4 /* States.IN_SUB_PATH */, 0 /* Actions.APPEND */],
485
+ ["o" /* PathCharTypes.END_OF_FAIL */]: 8 /* States.ERROR */,
486
+ ["l" /* PathCharTypes.ELSE */]: [5 /* States.IN_SINGLE_QUOTE */, 0 /* Actions.APPEND */]
487
+ };
488
+ pathStateMachine[6 /* States.IN_DOUBLE_QUOTE */] = {
489
+ ["\"" /* PathCharTypes.DOUBLE_QUOTE */]: [4 /* States.IN_SUB_PATH */, 0 /* Actions.APPEND */],
490
+ ["o" /* PathCharTypes.END_OF_FAIL */]: 8 /* States.ERROR */,
491
+ ["l" /* PathCharTypes.ELSE */]: [6 /* States.IN_DOUBLE_QUOTE */, 0 /* Actions.APPEND */]
492
+ };
493
+ /**
494
+ * Check if an expression is a literal value.
495
+ */
496
+ const literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;
497
+ function isLiteral(exp) {
498
+ return literalValueRE.test(exp);
499
+ }
500
+ /**
501
+ * Strip quotes from a string
502
+ */
503
+ function stripQuotes(str) {
504
+ const a = str.charCodeAt(0);
505
+ const b = str.charCodeAt(str.length - 1);
506
+ return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
507
+ }
508
+ /**
509
+ * Determine the type of a character in a keypath.
510
+ */
511
+ function getPathCharType(ch) {
512
+ if (ch === undefined || ch === null) {
513
+ return "o" /* PathCharTypes.END_OF_FAIL */;
514
+ }
515
+ const code = ch.charCodeAt(0);
516
+ switch (code) {
517
+ case 0x5b: // [
518
+ case 0x5d: // ]
519
+ case 0x2e: // .
520
+ case 0x22: // "
521
+ case 0x27: // '
522
+ return ch;
523
+ case 0x5f: // _
524
+ case 0x24: // $
525
+ case 0x2d: // -
526
+ return "i" /* PathCharTypes.IDENT */;
527
+ case 0x09: // Tab (HT)
528
+ case 0x0a: // Newline (LF)
529
+ case 0x0d: // Return (CR)
530
+ case 0xa0: // No-break space (NBSP)
531
+ case 0xfeff: // Byte Order Mark (BOM)
532
+ case 0x2028: // Line Separator (LS)
533
+ case 0x2029: // Paragraph Separator (PS)
534
+ return "w" /* PathCharTypes.WORKSPACE */;
535
+ }
536
+ return "i" /* PathCharTypes.IDENT */;
537
+ }
538
+ /**
539
+ * Format a subPath, return its plain form if it is
540
+ * a literal string or number. Otherwise prepend the
541
+ * dynamic indicator (*).
542
+ */
543
+ function formatSubPath(path) {
544
+ const trimmed = path.trim();
545
+ // invalid leading 0
546
+ if (path.charAt(0) === '0' && isNaN(parseInt(path))) {
547
+ return false;
548
+ }
549
+ return isLiteral(trimmed)
550
+ ? stripQuotes(trimmed)
551
+ : "*" /* PathCharTypes.ASTARISK */ + trimmed;
552
+ }
553
+ /**
554
+ * Parse a string path into an array of segments
555
+ */
556
+ function parse(path) {
557
+ const keys = [];
558
+ let index = -1;
559
+ let mode = 0 /* States.BEFORE_PATH */;
560
+ let subPathDepth = 0;
561
+ let c;
562
+ let key; // eslint-disable-line
563
+ let newChar;
564
+ let type;
565
+ let transition;
566
+ let action;
567
+ let typeMap;
568
+ const actions = [];
569
+ actions[0 /* Actions.APPEND */] = () => {
570
+ if (key === undefined) {
571
+ key = newChar;
572
+ }
573
+ else {
574
+ key += newChar;
575
+ }
576
+ };
577
+ actions[1 /* Actions.PUSH */] = () => {
578
+ if (key !== undefined) {
579
+ keys.push(key);
580
+ key = undefined;
581
+ }
582
+ };
583
+ actions[2 /* Actions.INC_SUB_PATH_DEPTH */] = () => {
584
+ actions[0 /* Actions.APPEND */]();
585
+ subPathDepth++;
586
+ };
587
+ actions[3 /* Actions.PUSH_SUB_PATH */] = () => {
588
+ if (subPathDepth > 0) {
589
+ subPathDepth--;
590
+ mode = 4 /* States.IN_SUB_PATH */;
591
+ actions[0 /* Actions.APPEND */]();
592
+ }
593
+ else {
594
+ subPathDepth = 0;
595
+ if (key === undefined) {
596
+ return false;
597
+ }
598
+ key = formatSubPath(key);
599
+ if (key === false) {
600
+ return false;
601
+ }
602
+ else {
603
+ actions[1 /* Actions.PUSH */]();
604
+ }
605
+ }
606
+ };
607
+ function maybeUnescapeQuote() {
608
+ const nextChar = path[index + 1];
609
+ if ((mode === 5 /* States.IN_SINGLE_QUOTE */ &&
610
+ nextChar === "'" /* PathCharTypes.SINGLE_QUOTE */) ||
611
+ (mode === 6 /* States.IN_DOUBLE_QUOTE */ &&
612
+ nextChar === "\"" /* PathCharTypes.DOUBLE_QUOTE */)) {
613
+ index++;
614
+ newChar = '\\' + nextChar;
615
+ actions[0 /* Actions.APPEND */]();
616
+ return true;
617
+ }
618
+ }
619
+ while (mode !== null) {
620
+ index++;
621
+ c = path[index];
622
+ if (c === '\\' && maybeUnescapeQuote()) {
623
+ continue;
624
+ }
625
+ type = getPathCharType(c);
626
+ typeMap = pathStateMachine[mode];
627
+ transition = typeMap[type] || typeMap["l" /* PathCharTypes.ELSE */] || 8 /* States.ERROR */;
628
+ // check parse error
629
+ if (transition === 8 /* States.ERROR */) {
630
+ return;
631
+ }
632
+ mode = transition[0];
633
+ if (transition[1] !== undefined) {
634
+ action = actions[transition[1]];
635
+ if (action) {
636
+ newChar = c;
637
+ if (action() === false) {
638
+ return;
639
+ }
640
+ }
641
+ }
642
+ // check parse finish
643
+ if (mode === 7 /* States.AFTER_PATH */) {
644
+ return keys;
645
+ }
646
+ }
647
+ }
648
+ // path token cache
649
+ const cache = new Map();
650
+ /**
651
+ * key-value message resolver
652
+ *
653
+ * @remarks
654
+ * Resolves messages with the key-value structure. Note that messages with a hierarchical structure such as objects cannot be resolved
655
+ *
656
+ * @param obj - A target object to be resolved with path
657
+ * @param path - A {@link Path | path} to resolve the value of message
658
+ *
659
+ * @returns A resolved {@link PathValue | path value}
660
+ *
661
+ * @VueI18nGeneral
662
+ */
663
+ function resolveWithKeyValue(obj, path) {
664
+ return isObject(obj) ? obj[path] : null;
665
+ }
666
+ /**
667
+ * message resolver
668
+ *
669
+ * @remarks
670
+ * Resolves messages. messages with a hierarchical structure such as objects can be resolved. This resolver is used in VueI18n as default.
671
+ *
672
+ * @param obj - A target object to be resolved with path
673
+ * @param path - A {@link Path | path} to resolve the value of message
674
+ *
675
+ * @returns A resolved {@link PathValue | path value}
676
+ *
677
+ * @VueI18nGeneral
678
+ */
679
+ function resolveValue(obj, path) {
680
+ // check object
681
+ if (!isObject(obj)) {
682
+ return null;
683
+ }
684
+ // parse path
685
+ let hit = cache.get(path);
686
+ if (!hit) {
687
+ hit = parse(path);
688
+ if (hit) {
689
+ cache.set(path, hit);
690
+ }
691
+ }
692
+ // check hit
693
+ if (!hit) {
694
+ return null;
695
+ }
696
+ // resolve path value
697
+ const len = hit.length;
698
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- for generic object
699
+ let last = obj;
700
+ let i = 0;
701
+ while (i < len) {
702
+ const key = hit[i];
703
+ /**
704
+ * NOTE:
705
+ * if `key` is intlify message format AST node key and `last` is intlify message format AST, skip it.
706
+ * because the AST node is not a key-value structure.
707
+ */
708
+ if (AST_NODE_PROPS_KEYS.includes(key) && isMessageAST(last)) {
709
+ return null;
710
+ }
711
+ if (!isObject(last)) {
712
+ return null;
713
+ }
714
+ if (!hasOwn(last, key)) {
715
+ return null;
716
+ }
717
+ const val = last[key];
718
+ if (val === undefined) {
719
+ return null;
720
+ }
721
+ if (isFunction(last)) {
722
+ return null;
723
+ }
724
+ last = val;
725
+ i++;
726
+ }
727
+ return last;
728
+ }
729
+
730
+ const CoreWarnCodes = {
731
+ NOT_FOUND_KEY: 1,
732
+ FALLBACK_TO_TRANSLATE: 2,
733
+ CANNOT_FORMAT_NUMBER: 3,
734
+ FALLBACK_TO_NUMBER_FORMAT: 4,
735
+ CANNOT_FORMAT_DATE: 5,
736
+ FALLBACK_TO_DATE_FORMAT: 6,
737
+ EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: 7,
738
+ INVALID_NUMBER_ARGUMENT: 8,
739
+ INVALID_DATE_ARGUMENT: 9
740
+ };
741
+ const CORE_WARN_CODES_EXTEND_POINT = 10;
742
+ /** @internal */
743
+ const warnMessages = {
744
+ [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
745
+ [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
746
+ [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
747
+ [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
748
+ [CoreWarnCodes.CANNOT_FORMAT_DATE]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
749
+ [CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`,
750
+ [CoreWarnCodes.EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER]: `This project is using Custom Message Compiler, which is an experimental feature. It may receive breaking changes or be removed in the future.`,
751
+ [CoreWarnCodes.INVALID_NUMBER_ARGUMENT]: `Invalid argument for number formatting: expected a number but received '{value}'.`,
752
+ [CoreWarnCodes.INVALID_DATE_ARGUMENT]: `Invalid argument for datetime formatting: expected a Date, number, or ISO string but received '{value}'.`
753
+ };
754
+ function getWarnMessage(code, ...args) {
755
+ return format$1(warnMessages[code], ...args);
756
+ }
757
+
758
+ /* eslint-disable @typescript-eslint/no-explicit-any */
759
+ /**
760
+ * Intlify core-base version
761
+ * @internal
762
+ */
763
+ const VERSION = '11.4.6';
764
+ const NOT_REOSLVED = -1;
765
+ const DEFAULT_LOCALE = 'en-US';
766
+ const MISSING_RESOLVE_VALUE = '';
767
+ const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
768
+ function getDefaultLinkedModifiers() {
769
+ return {
770
+ upper: (val, type) => {
771
+ // prettier-ignore
772
+ return type === 'text' && isString(val)
773
+ ? val.toUpperCase()
774
+ : type === 'vnode' && isObject(val) && '__v_isVNode' in val
775
+ ? val.children.toUpperCase()
776
+ : val;
777
+ },
778
+ lower: (val, type) => {
779
+ // prettier-ignore
780
+ return type === 'text' && isString(val)
781
+ ? val.toLowerCase()
782
+ : type === 'vnode' && isObject(val) && '__v_isVNode' in val
783
+ ? val.children.toLowerCase()
784
+ : val;
785
+ },
786
+ capitalize: (val, type) => {
787
+ // prettier-ignore
788
+ return (type === 'text' && isString(val)
789
+ ? capitalize(val)
790
+ : type === 'vnode' && isObject(val) && '__v_isVNode' in val
791
+ ? capitalize(val.children)
792
+ : val);
793
+ }
794
+ };
795
+ }
796
+ let _compiler;
797
+ function registerMessageCompiler(compiler) {
798
+ _compiler = compiler;
799
+ }
800
+ let _resolver;
801
+ /**
802
+ * Register the message resolver
803
+ *
804
+ * @param resolver - A {@link MessageResolver} function
805
+ *
806
+ * @VueI18nGeneral
807
+ */
808
+ function registerMessageResolver(resolver) {
809
+ _resolver = resolver;
810
+ }
811
+ let _fallbacker;
812
+ /**
813
+ * Register the locale fallbacker
814
+ *
815
+ * @param fallbacker - A {@link LocaleFallbacker} function
816
+ *
817
+ * @VueI18nGeneral
818
+ */
819
+ function registerLocaleFallbacker(fallbacker) {
820
+ _fallbacker = fallbacker;
821
+ }
822
+ // Additional Meta for Intlify DevTools
823
+ let _additionalMeta = null;
824
+ /* #__NO_SIDE_EFFECTS__ */
825
+ const setAdditionalMeta = (meta) => {
826
+ _additionalMeta = meta;
827
+ };
828
+ /* #__NO_SIDE_EFFECTS__ */
829
+ const getAdditionalMeta = () => _additionalMeta;
830
+ let _fallbackContext = null;
831
+ const setFallbackContext = (context) => {
832
+ _fallbackContext = context;
833
+ };
834
+ const getFallbackContext = () => _fallbackContext;
835
+ // ID for CoreContext
836
+ let _cid = 0;
837
+ function createCoreContext(options = {}) {
838
+ // setup options
839
+ const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
840
+ const version = isString(options.version) ? options.version : VERSION;
841
+ const locale = isString(options.locale) || isFunction(options.locale)
842
+ ? options.locale
843
+ : DEFAULT_LOCALE;
844
+ const _locale = isFunction(locale) ? DEFAULT_LOCALE : locale;
845
+ const fallbackLocale = isArray(options.fallbackLocale) ||
846
+ isPlainObject(options.fallbackLocale) ||
847
+ isString(options.fallbackLocale) ||
848
+ options.fallbackLocale === false
849
+ ? options.fallbackLocale
850
+ : _locale;
851
+ const messages = isPlainObject(options.messages)
852
+ ? options.messages
853
+ : createResources(_locale);
854
+ const datetimeFormats = isPlainObject(options.datetimeFormats)
855
+ ? options.datetimeFormats
856
+ : createResources(_locale)
857
+ ;
858
+ const numberFormats = isPlainObject(options.numberFormats)
859
+ ? options.numberFormats
860
+ : createResources(_locale)
861
+ ;
862
+ const modifiers = assign(create(), options.modifiers, getDefaultLinkedModifiers());
863
+ const pluralRules = options.pluralRules || create();
864
+ const missing = isFunction(options.missing) ? options.missing : null;
865
+ const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
866
+ ? options.missingWarn
867
+ : true;
868
+ const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
869
+ ? options.fallbackWarn
870
+ : true;
871
+ const fallbackFormat = !!options.fallbackFormat;
872
+ const unresolving = !!options.unresolving;
873
+ const postTranslation = isFunction(options.postTranslation)
874
+ ? options.postTranslation
875
+ : null;
876
+ const processor = isPlainObject(options.processor) ? options.processor : null;
877
+ const warnHtmlMessage = isBoolean(options.warnHtmlMessage)
878
+ ? options.warnHtmlMessage
879
+ : true;
880
+ const escapeParameter = !!options.escapeParameter;
881
+ const messageCompiler = isFunction(options.messageCompiler)
882
+ ? options.messageCompiler
883
+ : _compiler;
884
+ if ((process.env.NODE_ENV !== 'production') &&
885
+ true &&
886
+ true &&
887
+ isFunction(options.messageCompiler)) {
888
+ warnOnce(getWarnMessage(CoreWarnCodes.EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER));
889
+ }
890
+ const messageResolver = isFunction(options.messageResolver)
891
+ ? options.messageResolver
892
+ : _resolver || resolveWithKeyValue;
893
+ const localeFallbacker = isFunction(options.localeFallbacker)
894
+ ? options.localeFallbacker
895
+ : _fallbacker || fallbackWithSimple;
896
+ const fallbackContext = isObject(options.fallbackContext)
897
+ ? options.fallbackContext
898
+ : undefined;
899
+ // setup internal options
900
+ const internalOptions = options;
901
+ const __datetimeFormatters = isObject(internalOptions.__datetimeFormatters)
902
+ ? internalOptions.__datetimeFormatters
903
+ : new Map()
904
+ ;
905
+ const __numberFormatters = isObject(internalOptions.__numberFormatters)
906
+ ? internalOptions.__numberFormatters
907
+ : new Map()
908
+ ;
909
+ const __meta = isObject(internalOptions.__meta) ? internalOptions.__meta : {};
910
+ _cid++;
911
+ const context = {
912
+ version,
913
+ cid: _cid,
914
+ locale,
915
+ fallbackLocale,
916
+ messages,
917
+ modifiers,
918
+ pluralRules,
919
+ missing,
920
+ missingWarn,
921
+ fallbackWarn,
922
+ fallbackFormat,
923
+ unresolving,
924
+ postTranslation,
925
+ processor,
926
+ warnHtmlMessage,
927
+ escapeParameter,
928
+ messageCompiler,
929
+ messageResolver,
930
+ localeFallbacker,
931
+ fallbackContext,
932
+ onWarn,
933
+ __meta
934
+ };
935
+ {
936
+ context.datetimeFormats = datetimeFormats;
937
+ context.numberFormats = numberFormats;
938
+ context.__datetimeFormatters = __datetimeFormatters;
939
+ context.__numberFormatters = __numberFormatters;
940
+ }
941
+ // for vue-devtools timeline event
942
+ if ((process.env.NODE_ENV !== 'production')) {
943
+ context.__v_emitter =
944
+ internalOptions.__v_emitter != null
945
+ ? internalOptions.__v_emitter
946
+ : undefined;
947
+ }
948
+ // NOTE: experimental !!
949
+ if ((process.env.NODE_ENV !== 'production') || __INTLIFY_PROD_DEVTOOLS__) {
950
+ initI18nDevTools(context, version, __meta);
951
+ }
952
+ return context;
953
+ }
954
+ const createResources = (locale) => ({ [locale]: create() });
955
+ /** @internal */
956
+ function isTranslateFallbackWarn(fallback, key) {
957
+ return fallback instanceof RegExp ? fallback.test(key) : fallback;
958
+ }
959
+ /** @internal */
960
+ function isTranslateMissingWarn(missing, key) {
961
+ return missing instanceof RegExp ? missing.test(key) : missing;
962
+ }
963
+ /** @internal */
964
+ function handleMissing(context, key, locale, missingWarn, type) {
965
+ const { missing, onWarn } = context;
966
+ // for vue-devtools timeline event
967
+ if ((process.env.NODE_ENV !== 'production')) {
968
+ const emitter = context.__v_emitter;
969
+ if (emitter) {
970
+ emitter.emit('missing', {
971
+ locale,
972
+ key,
973
+ type,
974
+ groupId: `${type}:${key}`
975
+ });
976
+ }
977
+ }
978
+ if (missing !== null) {
979
+ const ret = missing(context, locale, key, type);
980
+ return isString(ret) ? ret : key;
981
+ }
982
+ else {
983
+ if ((process.env.NODE_ENV !== 'production') && isTranslateMissingWarn(missingWarn, key)) {
984
+ onWarn(getWarnMessage(CoreWarnCodes.NOT_FOUND_KEY, { key, locale }));
985
+ }
986
+ return key;
987
+ }
988
+ }
989
+ /** @internal */
990
+ function updateFallbackLocale(ctx, locale, fallback) {
991
+ const context = ctx;
992
+ context.__localeChainCache = new Map();
993
+ ctx.localeFallbacker(ctx, fallback, locale);
994
+ }
995
+ /** @internal */
996
+ function isAlmostSameLocale(locale, compareLocale) {
997
+ if (locale === compareLocale)
998
+ return false;
999
+ return locale.split('-')[0] === compareLocale.split('-')[0];
1000
+ }
1001
+ /** @internal */
1002
+ function isImplicitFallback(targetLocale, locales) {
1003
+ const index = locales.indexOf(targetLocale);
1004
+ if (index === -1) {
1005
+ return false;
1006
+ }
1007
+ for (let i = index + 1; i < locales.length; i++) {
1008
+ if (isAlmostSameLocale(targetLocale, locales[i])) {
1009
+ return true;
1010
+ }
1011
+ }
1012
+ return false;
1013
+ }
1014
+ /* eslint-enable @typescript-eslint/no-explicit-any */
1015
+
1016
+ const intlDefined = typeof Intl !== 'undefined';
1017
+ const Availabilities = {
1018
+ dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
1019
+ numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined'
1020
+ };
1021
+
1022
+ // implementation of `datetime` function
1023
+ function datetime(context, ...args) {
1024
+ const { datetimeFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1025
+ const { __datetimeFormatters } = context;
1026
+ if ((process.env.NODE_ENV !== 'production') && !Availabilities.dateTimeFormat) {
1027
+ onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
1028
+ return MISSING_RESOLVE_VALUE;
1029
+ }
1030
+ if (!isString(args[0]) && !isDate(args[0]) && !isNumber(args[0])) {
1031
+ if ((process.env.NODE_ENV !== 'production')) {
1032
+ onWarn(getWarnMessage(CoreWarnCodes.INVALID_DATE_ARGUMENT, {
1033
+ value: String(args[0])
1034
+ }));
1035
+ }
1036
+ return MISSING_RESOLVE_VALUE;
1037
+ }
1038
+ const [key, value, options, overrides] = parseDateTimeArgs(...args);
1039
+ const missingWarn = isBoolean(options.missingWarn)
1040
+ ? options.missingWarn
1041
+ : context.missingWarn;
1042
+ const fallbackWarn = isBoolean(options.fallbackWarn)
1043
+ ? options.fallbackWarn
1044
+ : context.fallbackWarn;
1045
+ const part = !!options.part;
1046
+ const locale = getLocale(context, options);
1047
+ const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1048
+ fallbackLocale, locale);
1049
+ if (!isString(key) || key === '') {
1050
+ const formatter = new Intl.DateTimeFormat(locale.replace(/!/g, ''), overrides);
1051
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
1052
+ }
1053
+ // resolve format
1054
+ let datetimeFormat = {};
1055
+ let targetLocale;
1056
+ let format = null;
1057
+ let from = locale;
1058
+ let to = null;
1059
+ const type = 'datetime format';
1060
+ for (let i = 0; i < locales.length; i++) {
1061
+ targetLocale = to = locales[i];
1062
+ if ((process.env.NODE_ENV !== 'production') &&
1063
+ locale !== targetLocale &&
1064
+ isTranslateFallbackWarn(fallbackWarn, key)) {
1065
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
1066
+ key,
1067
+ target: targetLocale
1068
+ }));
1069
+ }
1070
+ // for vue-devtools timeline event
1071
+ if ((process.env.NODE_ENV !== 'production') && locale !== targetLocale) {
1072
+ const emitter = context.__v_emitter;
1073
+ if (emitter) {
1074
+ emitter.emit('fallback', {
1075
+ type,
1076
+ key,
1077
+ from,
1078
+ to,
1079
+ groupId: `${type}:${key}`
1080
+ });
1081
+ }
1082
+ }
1083
+ datetimeFormat =
1084
+ datetimeFormats[targetLocale] || {};
1085
+ format = datetimeFormat[key];
1086
+ if (isPlainObject(format))
1087
+ break;
1088
+ handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1089
+ from = to;
1090
+ }
1091
+ // checking format and target locale
1092
+ if (!isPlainObject(format) || !isString(targetLocale)) {
1093
+ return unresolving ? NOT_REOSLVED : key;
1094
+ }
1095
+ let id = `${targetLocale}__${key}`;
1096
+ if (!isEmptyObject(overrides)) {
1097
+ id = `${id}__${JSON.stringify(overrides)}`;
1098
+ }
1099
+ let formatter = __datetimeFormatters.get(id);
1100
+ if (!formatter) {
1101
+ formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
1102
+ __datetimeFormatters.set(id, formatter);
1103
+ }
1104
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
1105
+ }
1106
+ /** @internal */
1107
+ const DATETIME_FORMAT_OPTIONS_KEYS = [
1108
+ 'localeMatcher',
1109
+ 'weekday',
1110
+ 'era',
1111
+ 'year',
1112
+ 'month',
1113
+ 'day',
1114
+ 'hour',
1115
+ 'minute',
1116
+ 'second',
1117
+ 'timeZoneName',
1118
+ 'formatMatcher',
1119
+ 'hour12',
1120
+ 'timeZone',
1121
+ 'dateStyle',
1122
+ 'timeStyle',
1123
+ 'calendar',
1124
+ 'dayPeriod',
1125
+ 'numberingSystem',
1126
+ 'hourCycle',
1127
+ 'fractionalSecondDigits'
1128
+ ];
1129
+ /** @internal */
1130
+ function parseDateTimeArgs(...args) {
1131
+ const [arg1, arg2, arg3, arg4] = args;
1132
+ const options = create();
1133
+ let overrides = create();
1134
+ let value;
1135
+ if (isString(arg1)) {
1136
+ // Only allow ISO strings - other date formats are often supported,
1137
+ // but may cause different results in different browsers.
1138
+ const matches = arg1.match(/(\d{4}-\d{2}-\d{2})(T|\s)?(.*)/);
1139
+ if (!matches) {
1140
+ throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1141
+ }
1142
+ // Some browsers can not parse the iso datetime separated by space,
1143
+ // this is a compromise solution by replace the 'T'/' ' with 'T'
1144
+ const dateTime = matches[3]
1145
+ ? matches[3].trim().startsWith('T')
1146
+ ? `${matches[1].trim()}${matches[3].trim()}`
1147
+ : `${matches[1].trim()}T${matches[3].trim()}`
1148
+ : matches[1].trim();
1149
+ value = new Date(dateTime);
1150
+ try {
1151
+ // This will fail if the date is not valid
1152
+ value.toISOString();
1153
+ }
1154
+ catch {
1155
+ throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1156
+ }
1157
+ }
1158
+ else if (isDate(arg1)) {
1159
+ if (isNaN(arg1.getTime())) {
1160
+ throw createCoreError(CoreErrorCodes.INVALID_DATE_ARGUMENT);
1161
+ }
1162
+ value = arg1;
1163
+ }
1164
+ else if (isNumber(arg1)) {
1165
+ value = arg1;
1166
+ }
1167
+ else {
1168
+ throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1169
+ }
1170
+ if (isString(arg2)) {
1171
+ options.key = arg2;
1172
+ }
1173
+ else if (isPlainObject(arg2)) {
1174
+ Object.keys(arg2).forEach(key => {
1175
+ if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
1176
+ overrides[key] = arg2[key];
1177
+ }
1178
+ else {
1179
+ options[key] = arg2[key];
1180
+ }
1181
+ });
1182
+ }
1183
+ if (isString(arg3)) {
1184
+ options.locale = arg3;
1185
+ }
1186
+ else if (isPlainObject(arg3)) {
1187
+ overrides = arg3;
1188
+ }
1189
+ if (isPlainObject(arg4)) {
1190
+ overrides = arg4;
1191
+ }
1192
+ return [options.key || '', value, options, overrides];
1193
+ }
1194
+ /** @internal */
1195
+ function clearDateTimeFormat(ctx, locale, format) {
1196
+ const context = ctx;
1197
+ for (const key in format) {
1198
+ const id = `${locale}__${key}`;
1199
+ if (!context.__datetimeFormatters.has(id)) {
1200
+ continue;
1201
+ }
1202
+ context.__datetimeFormatters.delete(id);
1203
+ }
1204
+ }
1205
+
1206
+ // implementation of `number` function
1207
+ function number(context, ...args) {
1208
+ const { numberFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1209
+ const { __numberFormatters } = context;
1210
+ if ((process.env.NODE_ENV !== 'production') && !Availabilities.numberFormat) {
1211
+ onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
1212
+ return MISSING_RESOLVE_VALUE;
1213
+ }
1214
+ if (!isNumber(args[0])) {
1215
+ if ((process.env.NODE_ENV !== 'production')) {
1216
+ onWarn(getWarnMessage(CoreWarnCodes.INVALID_NUMBER_ARGUMENT, {
1217
+ value: String(args[0])
1218
+ }));
1219
+ }
1220
+ return MISSING_RESOLVE_VALUE;
1221
+ }
1222
+ const [key, value, options, overrides] = parseNumberArgs(...args);
1223
+ const missingWarn = isBoolean(options.missingWarn)
1224
+ ? options.missingWarn
1225
+ : context.missingWarn;
1226
+ const fallbackWarn = isBoolean(options.fallbackWarn)
1227
+ ? options.fallbackWarn
1228
+ : context.fallbackWarn;
1229
+ const part = !!options.part;
1230
+ const locale = getLocale(context, options);
1231
+ const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1232
+ fallbackLocale, locale);
1233
+ if (!isString(key) || key === '') {
1234
+ const formatter = new Intl.NumberFormat(locale.replace(/!/g, ''), overrides);
1235
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
1236
+ }
1237
+ // resolve format
1238
+ let numberFormat = {};
1239
+ let targetLocale;
1240
+ let format = null;
1241
+ let from = locale;
1242
+ let to = null;
1243
+ const type = 'number format';
1244
+ for (let i = 0; i < locales.length; i++) {
1245
+ targetLocale = to = locales[i];
1246
+ if ((process.env.NODE_ENV !== 'production') &&
1247
+ locale !== targetLocale &&
1248
+ isTranslateFallbackWarn(fallbackWarn, key)) {
1249
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
1250
+ key,
1251
+ target: targetLocale
1252
+ }));
1253
+ }
1254
+ // for vue-devtools timeline event
1255
+ if ((process.env.NODE_ENV !== 'production') && locale !== targetLocale) {
1256
+ const emitter = context.__v_emitter;
1257
+ if (emitter) {
1258
+ emitter.emit('fallback', {
1259
+ type,
1260
+ key,
1261
+ from,
1262
+ to,
1263
+ groupId: `${type}:${key}`
1264
+ });
1265
+ }
1266
+ }
1267
+ numberFormat =
1268
+ numberFormats[targetLocale] || {};
1269
+ format = numberFormat[key];
1270
+ if (isPlainObject(format))
1271
+ break;
1272
+ handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1273
+ from = to;
1274
+ }
1275
+ // checking format and target locale
1276
+ if (!isPlainObject(format) || !isString(targetLocale)) {
1277
+ return unresolving ? NOT_REOSLVED : key;
1278
+ }
1279
+ let id = `${targetLocale}__${key}`;
1280
+ if (!isEmptyObject(overrides)) {
1281
+ id = `${id}__${JSON.stringify(overrides)}`;
1282
+ }
1283
+ let formatter = __numberFormatters.get(id);
1284
+ if (!formatter) {
1285
+ formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
1286
+ __numberFormatters.set(id, formatter);
1287
+ }
1288
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
1289
+ }
1290
+ /** @internal */
1291
+ const NUMBER_FORMAT_OPTIONS_KEYS = [
1292
+ 'localeMatcher',
1293
+ 'style',
1294
+ 'currency',
1295
+ 'currencyDisplay',
1296
+ 'currencySign',
1297
+ 'useGrouping',
1298
+ 'minimumIntegerDigits',
1299
+ 'minimumFractionDigits',
1300
+ 'maximumFractionDigits',
1301
+ 'minimumSignificantDigits',
1302
+ 'maximumSignificantDigits',
1303
+ 'compactDisplay',
1304
+ 'notation',
1305
+ 'signDisplay',
1306
+ 'unit',
1307
+ 'unitDisplay',
1308
+ 'roundingMode',
1309
+ 'roundingPriority',
1310
+ 'roundingIncrement',
1311
+ 'trailingZeroDisplay'
1312
+ ];
1313
+ /** @internal */
1314
+ function parseNumberArgs(...args) {
1315
+ const [arg1, arg2, arg3, arg4] = args;
1316
+ const options = create();
1317
+ let overrides = create();
1318
+ if (!isNumber(arg1)) {
1319
+ throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1320
+ }
1321
+ const value = arg1;
1322
+ if (isString(arg2)) {
1323
+ options.key = arg2;
1324
+ }
1325
+ else if (isPlainObject(arg2)) {
1326
+ Object.keys(arg2).forEach(key => {
1327
+ if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
1328
+ overrides[key] = arg2[key];
1329
+ }
1330
+ else {
1331
+ options[key] = arg2[key];
1332
+ }
1333
+ });
1334
+ }
1335
+ if (isString(arg3)) {
1336
+ options.locale = arg3;
1337
+ }
1338
+ else if (isPlainObject(arg3)) {
1339
+ overrides = arg3;
1340
+ }
1341
+ if (isPlainObject(arg4)) {
1342
+ overrides = arg4;
1343
+ }
1344
+ return [options.key || '', value, options, overrides];
1345
+ }
1346
+ /** @internal */
1347
+ function clearNumberFormat(ctx, locale, format) {
1348
+ const context = ctx;
1349
+ for (const key in format) {
1350
+ const id = `${locale}__${key}`;
1351
+ if (!context.__numberFormatters.has(id)) {
1352
+ continue;
1353
+ }
1354
+ context.__numberFormatters.delete(id);
1355
+ }
1356
+ }
1357
+
1358
+ const DEFAULT_MODIFIER = (str) => str;
1359
+ const DEFAULT_MESSAGE = (ctx) => ''; // eslint-disable-line
1360
+ const DEFAULT_MESSAGE_DATA_TYPE = 'text';
1361
+ const DEFAULT_NORMALIZE = (values) => values.length === 0 ? '' : join(values);
1362
+ const DEFAULT_INTERPOLATE = toDisplayString;
1363
+ function pluralDefault(choice, choicesLength) {
1364
+ choice = Math.abs(choice);
1365
+ // singular (0) | plural (1)
1366
+ if (choicesLength === 2) {
1367
+ // prettier-ignore
1368
+ return choice === 1
1369
+ ? 0
1370
+ : 1;
1371
+ }
1372
+ // zero (0) | singular (1) | plural (2)
1373
+ return Math.min(choice, 2);
1374
+ }
1375
+ function getPluralIndex(options) {
1376
+ // prettier-ignore
1377
+ const index = isNumber(options.pluralIndex)
1378
+ ? options.pluralIndex
1379
+ : -1;
1380
+ return isNumber(options.named?.count)
1381
+ ? options.named.count
1382
+ : isNumber(options.named?.n)
1383
+ ? options.named.n
1384
+ : index;
1385
+ }
1386
+ function createMessageContext(options = {}) {
1387
+ const locale = options.locale;
1388
+ const pluralIndex = getPluralIndex(options);
1389
+ const pluralRule = isString(locale) && isFunction(options.pluralRules?.[locale])
1390
+ ? options.pluralRules[locale]
1391
+ : pluralDefault;
1392
+ const orgPluralRule = pluralRule === pluralDefault ? undefined : pluralDefault;
1393
+ const plural = (messages) => messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
1394
+ const _list = options.list || [];
1395
+ const list = (index) => _list[index];
1396
+ const _named = options.named || create(); // eslint-disable-line @typescript-eslint/no-explicit-any
1397
+ // normalize named
1398
+ if (isNumber(options.pluralIndex)) {
1399
+ _named.count ||= options.pluralIndex;
1400
+ _named.n ||= options.pluralIndex;
1401
+ }
1402
+ const named = (key) => _named[key];
1403
+ function message(key, useLinked) {
1404
+ // prettier-ignore
1405
+ const msg = isFunction(options.messages)
1406
+ ? options.messages(key, !!useLinked)
1407
+ : isObject(options.messages)
1408
+ ? options.messages[key]
1409
+ : false;
1410
+ return !msg
1411
+ ? options.parent
1412
+ ? options.parent.message(key) // resolve from parent messages
1413
+ : DEFAULT_MESSAGE
1414
+ : msg;
1415
+ }
1416
+ const _modifier = (name) => options.modifiers
1417
+ ? options.modifiers[name]
1418
+ : DEFAULT_MODIFIER;
1419
+ const normalize = isFunction(options.processor?.normalize)
1420
+ ? options.processor.normalize
1421
+ : DEFAULT_NORMALIZE;
1422
+ const interpolate = isFunction(options.processor?.interpolate)
1423
+ ? options.processor.interpolate
1424
+ : DEFAULT_INTERPOLATE;
1425
+ const type = isString(options.processor?.type)
1426
+ ? options.processor.type
1427
+ : DEFAULT_MESSAGE_DATA_TYPE;
1428
+ const linked = (key, ...args) => {
1429
+ const [arg1, arg2] = args;
1430
+ let type = 'text';
1431
+ let modifier = '';
1432
+ if (args.length === 1) {
1433
+ if (isObject(arg1)) {
1434
+ modifier = arg1.modifier || modifier;
1435
+ type = arg1.type || type;
1436
+ }
1437
+ else if (isString(arg1)) {
1438
+ modifier = arg1 || modifier;
1439
+ }
1440
+ }
1441
+ else if (args.length === 2) {
1442
+ if (isString(arg1)) {
1443
+ modifier = arg1 || modifier;
1444
+ }
1445
+ if (isString(arg2)) {
1446
+ type = arg2 || type;
1447
+ }
1448
+ }
1449
+ const ret = message(key, true)(ctx);
1450
+ // If the linked message is not resolved (empty string), fall back to the key itself
1451
+ const resolved = ret === '' || ret === undefined ? key : ret;
1452
+ const msg =
1453
+ // The message in vnode resolved with linked are returned as an array by processor.nomalize
1454
+ type === 'vnode' && isArray(resolved) && modifier
1455
+ ? resolved[0]
1456
+ : resolved;
1457
+ return modifier ? _modifier(modifier)(msg, type) : msg;
1458
+ };
1459
+ const ctx = {
1460
+ ["list" /* HelperNameMap.LIST */]: list,
1461
+ ["named" /* HelperNameMap.NAMED */]: named,
1462
+ ["plural" /* HelperNameMap.PLURAL */]: plural,
1463
+ ["linked" /* HelperNameMap.LINKED */]: linked,
1464
+ ["message" /* HelperNameMap.MESSAGE */]: message,
1465
+ ["type" /* HelperNameMap.TYPE */]: type,
1466
+ ["interpolate" /* HelperNameMap.INTERPOLATE */]: interpolate,
1467
+ ["normalize" /* HelperNameMap.NORMALIZE */]: normalize,
1468
+ ["values" /* HelperNameMap.VALUES */]: assign(create(), _list, _named)
1469
+ };
1470
+ return ctx;
1471
+ }
1472
+
1473
+ const NOOP_MESSAGE_FUNCTION = () => '';
1474
+ const isMessageFunction = (val) => isFunction(val);
1475
+ // implementation of `translate` function
1476
+ function translate(context, ...args) {
1477
+ const { fallbackFormat, postTranslation, unresolving, messageCompiler, fallbackLocale, messages } = context;
1478
+ const [key, options] = parseTranslateArgs(...args);
1479
+ const missingWarn = isBoolean(options.missingWarn)
1480
+ ? options.missingWarn
1481
+ : context.missingWarn;
1482
+ const fallbackWarn = isBoolean(options.fallbackWarn)
1483
+ ? options.fallbackWarn
1484
+ : context.fallbackWarn;
1485
+ const escapeParameter = isBoolean(options.escapeParameter)
1486
+ ? options.escapeParameter
1487
+ : context.escapeParameter;
1488
+ const resolvedMessage = !!options.resolvedMessage;
1489
+ // prettier-ignore
1490
+ const defaultMsgOrKey = isString(options.default) || isBoolean(options.default) // default by function option
1491
+ ? !isBoolean(options.default)
1492
+ ? options.default
1493
+ : (!messageCompiler ? () => key : key)
1494
+ : fallbackFormat // default by `fallbackFormat` option
1495
+ ? (!messageCompiler ? () => key : key)
1496
+ : null;
1497
+ const enableDefaultMsg = fallbackFormat ||
1498
+ (defaultMsgOrKey != null &&
1499
+ (isString(defaultMsgOrKey) || isFunction(defaultMsgOrKey)));
1500
+ const locale = getLocale(context, options);
1501
+ // escape params
1502
+ escapeParameter && escapeParams(options);
1503
+ // resolve message format
1504
+ // eslint-disable-next-line prefer-const
1505
+ let [formatScope, targetLocale, message] = !resolvedMessage
1506
+ ? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
1507
+ : [
1508
+ key,
1509
+ locale,
1510
+ messages[locale] || create()
1511
+ ];
1512
+ // NOTE:
1513
+ // Fix to work around `ssrTransfrom` bug in Vite.
1514
+ // https://github.com/vitejs/vite/issues/4306
1515
+ // To get around this, use temporary variables.
1516
+ // https://github.com/nuxt/framework/issues/1461#issuecomment-954606243
1517
+ let format = formatScope;
1518
+ // if you use default message, set it as message format!
1519
+ let cacheBaseKey = key;
1520
+ if (!resolvedMessage &&
1521
+ !(isString(format) ||
1522
+ isMessageAST(format) ||
1523
+ isMessageFunction(format))) {
1524
+ if (enableDefaultMsg) {
1525
+ format = defaultMsgOrKey;
1526
+ cacheBaseKey = format;
1527
+ }
1528
+ }
1529
+ // checking message format and target locale
1530
+ if (!resolvedMessage &&
1531
+ (!(isString(format) ||
1532
+ isMessageAST(format) ||
1533
+ isMessageFunction(format)) ||
1534
+ !isString(targetLocale))) {
1535
+ return unresolving ? NOT_REOSLVED : key;
1536
+ }
1537
+ // TODO: refactor
1538
+ if ((process.env.NODE_ENV !== 'production') && isString(format) && context.messageCompiler == null) {
1539
+ warn(`The message format compilation is not supported in this build. ` +
1540
+ `Because message compiler isn't included. ` +
1541
+ `You need to pre-compilation all message format. ` +
1542
+ `So translate function return '${key}'.`);
1543
+ return key;
1544
+ }
1545
+ // setup compile error detecting
1546
+ let occurred = false;
1547
+ const onError = () => {
1548
+ occurred = true;
1549
+ };
1550
+ // compile message format
1551
+ const msg = !isMessageFunction(format)
1552
+ ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError)
1553
+ : format;
1554
+ // if occurred compile error, return the message format
1555
+ if (occurred) {
1556
+ return format;
1557
+ }
1558
+ // evaluate message with context
1559
+ const ctxOptions = getMessageContextOptions(context, targetLocale, message, options);
1560
+ const msgContext = createMessageContext(ctxOptions);
1561
+ const messaged = evaluateMessage(context, msg, msgContext);
1562
+ // if use post translation option, proceed it with handler
1563
+ let ret = postTranslation
1564
+ ? postTranslation(messaged, key)
1565
+ : messaged;
1566
+ // apply HTML sanitization for security
1567
+ if (escapeParameter && isString(ret)) {
1568
+ ret = sanitizeTranslatedHtml(ret);
1569
+ }
1570
+ // NOTE: experimental !!
1571
+ if ((process.env.NODE_ENV !== 'production') || __INTLIFY_PROD_DEVTOOLS__) {
1572
+ // prettier-ignore
1573
+ const payloads = {
1574
+ timestamp: Date.now(),
1575
+ key: isString(key)
1576
+ ? key
1577
+ : isMessageFunction(format)
1578
+ ? format.key
1579
+ : '',
1580
+ locale: targetLocale || (isMessageFunction(format)
1581
+ ? format.locale
1582
+ : ''),
1583
+ format: isString(format)
1584
+ ? format
1585
+ : isMessageFunction(format)
1586
+ ? format.source
1587
+ : '',
1588
+ message: ret
1589
+ };
1590
+ payloads.meta = assign({}, context.__meta, getAdditionalMeta() || {});
1591
+ translateDevTools(payloads);
1592
+ }
1593
+ return ret;
1594
+ }
1595
+ function escapeParams(options) {
1596
+ if (isArray(options.list)) {
1597
+ options.list = options.list.map(item => isString(item) ? escapeHtml(item) : item);
1598
+ }
1599
+ else if (isObject(options.named)) {
1600
+ Object.keys(options.named).forEach(key => {
1601
+ if (isString(options.named[key])) {
1602
+ options.named[key] = escapeHtml(options.named[key]);
1603
+ }
1604
+ });
1605
+ }
1606
+ }
1607
+ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
1608
+ const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
1609
+ const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
1610
+ let message = create();
1611
+ let targetLocale;
1612
+ let format = null;
1613
+ let from = locale;
1614
+ let to = null;
1615
+ const type = 'translate';
1616
+ for (let i = 0; i < locales.length; i++) {
1617
+ targetLocale = to = locales[i];
1618
+ if ((process.env.NODE_ENV !== 'production') &&
1619
+ locale !== targetLocale &&
1620
+ !isAlmostSameLocale(locale, targetLocale) &&
1621
+ isTranslateFallbackWarn(fallbackWarn, key)) {
1622
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_TRANSLATE, {
1623
+ key,
1624
+ target: targetLocale
1625
+ }));
1626
+ }
1627
+ const emitter = (process.env.NODE_ENV !== 'production')
1628
+ ? context.__v_emitter
1629
+ : undefined;
1630
+ // for vue-devtools timeline event
1631
+ if ((process.env.NODE_ENV !== 'production') && locale !== targetLocale) {
1632
+ if (emitter) {
1633
+ emitter.emit('fallback', {
1634
+ type,
1635
+ key,
1636
+ from,
1637
+ to,
1638
+ groupId: `${type}:${key}`
1639
+ });
1640
+ }
1641
+ }
1642
+ message =
1643
+ messages[targetLocale] || create();
1644
+ // for vue-devtools timeline event
1645
+ let start = null;
1646
+ let startTag;
1647
+ let endTag;
1648
+ if ((process.env.NODE_ENV !== 'production') && inBrowser && emitter) {
1649
+ start = window.performance.now();
1650
+ startTag = 'intlify-message-resolve-start';
1651
+ endTag = 'intlify-message-resolve-end';
1652
+ mark && mark(startTag);
1653
+ }
1654
+ if ((format = resolveValue(message, key)) === null) {
1655
+ // if null, resolve with object key path
1656
+ format = message[key]; // eslint-disable-line @typescript-eslint/no-explicit-any
1657
+ }
1658
+ // for vue-devtools timeline event
1659
+ if ((process.env.NODE_ENV !== 'production') && inBrowser && emitter) {
1660
+ const end = window.performance.now();
1661
+ if (emitter && start && format) {
1662
+ emitter.emit('message-resolve', {
1663
+ type: 'message-resolve',
1664
+ key,
1665
+ message: format,
1666
+ time: end - start,
1667
+ groupId: `${type}:${key}`
1668
+ });
1669
+ }
1670
+ if (startTag && endTag && mark && measure) {
1671
+ mark(endTag);
1672
+ measure('intlify message resolve', startTag, endTag);
1673
+ }
1674
+ }
1675
+ if (isString(format) || isMessageAST(format) || isMessageFunction(format)) {
1676
+ break;
1677
+ }
1678
+ if (!isImplicitFallback(targetLocale, locales)) {
1679
+ const missingRet = handleMissing(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1680
+ key, targetLocale, missingWarn, type);
1681
+ if (missingRet !== key) {
1682
+ format = missingRet;
1683
+ }
1684
+ }
1685
+ from = to;
1686
+ }
1687
+ return [format, targetLocale, message];
1688
+ }
1689
+ function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) {
1690
+ const { messageCompiler, warnHtmlMessage } = context;
1691
+ if (isMessageFunction(format)) {
1692
+ const msg = format;
1693
+ msg.locale = msg.locale || targetLocale;
1694
+ msg.key = msg.key || key;
1695
+ return msg;
1696
+ }
1697
+ if (messageCompiler == null) {
1698
+ const msg = (() => format);
1699
+ msg.locale = targetLocale;
1700
+ msg.key = key;
1701
+ return msg;
1702
+ }
1703
+ // for vue-devtools timeline event
1704
+ const emitter = (process.env.NODE_ENV !== 'production')
1705
+ ? context.__v_emitter
1706
+ : undefined;
1707
+ let start = null;
1708
+ let startTag;
1709
+ let endTag;
1710
+ if ((process.env.NODE_ENV !== 'production') && inBrowser && emitter) {
1711
+ start = window.performance.now();
1712
+ startTag = 'intlify-message-compilation-start';
1713
+ endTag = 'intlify-message-compilation-end';
1714
+ mark && mark(startTag);
1715
+ }
1716
+ const msg = messageCompiler(format, getCompileContext(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, onError));
1717
+ // for vue-devtools timeline event
1718
+ if ((process.env.NODE_ENV !== 'production') && inBrowser && emitter) {
1719
+ const end = window.performance.now();
1720
+ if (emitter && start) {
1721
+ emitter.emit('message-compilation', {
1722
+ type: 'message-compilation',
1723
+ message: format,
1724
+ time: end - start,
1725
+ groupId: `${'translate'}:${key}`
1726
+ });
1727
+ }
1728
+ if (startTag && endTag && mark && measure) {
1729
+ mark(endTag);
1730
+ measure('intlify message compilation', startTag, endTag);
1731
+ }
1732
+ }
1733
+ msg.locale = targetLocale;
1734
+ msg.key = key;
1735
+ msg.source = format;
1736
+ return msg;
1737
+ }
1738
+ function evaluateMessage(context, msg, msgCtx) {
1739
+ // for vue-devtools timeline event
1740
+ const emitter = (process.env.NODE_ENV !== 'production')
1741
+ ? context.__v_emitter
1742
+ : undefined;
1743
+ let start = null;
1744
+ let startTag;
1745
+ let endTag;
1746
+ if ((process.env.NODE_ENV !== 'production') && inBrowser && emitter) {
1747
+ start = window.performance.now();
1748
+ startTag = 'intlify-message-evaluation-start';
1749
+ endTag = 'intlify-message-evaluation-end';
1750
+ mark && mark(startTag);
1751
+ }
1752
+ const messaged = msg(msgCtx);
1753
+ // for vue-devtools timeline event
1754
+ if ((process.env.NODE_ENV !== 'production') && inBrowser && emitter) {
1755
+ const end = window.performance.now();
1756
+ if (emitter && start) {
1757
+ emitter.emit('message-evaluation', {
1758
+ type: 'message-evaluation',
1759
+ value: messaged,
1760
+ time: end - start,
1761
+ groupId: `${'translate'}:${msg.key}`
1762
+ });
1763
+ }
1764
+ if (startTag && endTag && mark && measure) {
1765
+ mark(endTag);
1766
+ measure('intlify message evaluation', startTag, endTag);
1767
+ }
1768
+ }
1769
+ return messaged;
1770
+ }
1771
+ /** @internal */
1772
+ function parseTranslateArgs(...args) {
1773
+ const [arg1, arg2, arg3] = args;
1774
+ const options = create();
1775
+ if (!isString(arg1) &&
1776
+ !isNumber(arg1) &&
1777
+ !isMessageFunction(arg1) &&
1778
+ !isMessageAST(arg1)) {
1779
+ throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1780
+ }
1781
+ // prettier-ignore
1782
+ const key = isNumber(arg1)
1783
+ ? String(arg1)
1784
+ : isMessageFunction(arg1)
1785
+ ? arg1
1786
+ : arg1;
1787
+ if (isNumber(arg2)) {
1788
+ options.plural = arg2;
1789
+ }
1790
+ else if (isString(arg2)) {
1791
+ options.default = arg2;
1792
+ }
1793
+ else if (isPlainObject(arg2) && !isEmptyObject(arg2)) {
1794
+ options.named = arg2;
1795
+ }
1796
+ else if (isArray(arg2)) {
1797
+ options.list = arg2;
1798
+ }
1799
+ if (isNumber(arg3)) {
1800
+ options.plural = arg3;
1801
+ }
1802
+ else if (isString(arg3)) {
1803
+ options.default = arg3;
1804
+ }
1805
+ else if (isPlainObject(arg3)) {
1806
+ assign(options, arg3);
1807
+ }
1808
+ return [key, options];
1809
+ }
1810
+ function getCompileContext(context, locale, key, source, warnHtmlMessage, onError) {
1811
+ return {
1812
+ locale,
1813
+ key,
1814
+ warnHtmlMessage,
1815
+ onError: (err) => {
1816
+ onError && onError(err);
1817
+ if ((process.env.NODE_ENV !== 'production')) {
1818
+ const _source = getSourceForCodeFrame(source);
1819
+ const codeFrame = err.location &&
1820
+ _source &&
1821
+ generateCodeFrame(_source, err.location.start.offset, err.location.end.offset);
1822
+ const emitter = context.__v_emitter;
1823
+ if (emitter && _source) {
1824
+ emitter.emit('compile-error', {
1825
+ message: _source,
1826
+ error: err.message,
1827
+ start: err.location && err.location.start.offset,
1828
+ end: err.location && err.location.end.offset,
1829
+ groupId: `${'translate'}:${key}`
1830
+ });
1831
+ }
1832
+ const message = `Message compilation error: ${err.message}`;
1833
+ throw new SyntaxError(codeFrame ? `${message}\n${codeFrame}` : message);
1834
+ }
1835
+ throw err;
1836
+ },
1837
+ onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
1838
+ };
1839
+ }
1840
+ function getSourceForCodeFrame(source) {
1841
+ if (isString(source)) {
1842
+ return source;
1843
+ }
1844
+ else {
1845
+ if (source.loc && source.loc.source) {
1846
+ return source.loc.source;
1847
+ }
1848
+ }
1849
+ }
1850
+ function getMessageContextOptions(context, locale, message, options) {
1851
+ const { modifiers, pluralRules, messageResolver: resolveValue, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
1852
+ const resolveMessage = (key, useLinked) => {
1853
+ let val = resolveValue(message, key);
1854
+ // fallback
1855
+ if (val == null && (fallbackContext || useLinked)) {
1856
+ const [format, , message] = resolveMessageFormat(fallbackContext || context, // NOTE: if has fallbackContext, fallback to root, else if use linked, fallback to local context
1857
+ key, locale, fallbackLocale, fallbackWarn, missingWarn);
1858
+ val = format ?? resolveValue(message, key);
1859
+ }
1860
+ if (isString(val) || isMessageAST(val)) {
1861
+ let occurred = false;
1862
+ const onError = () => {
1863
+ occurred = true;
1864
+ };
1865
+ const msg = compileMessageFormat(context, key, locale, val, key, onError);
1866
+ return !occurred
1867
+ ? msg
1868
+ : NOOP_MESSAGE_FUNCTION;
1869
+ }
1870
+ else if (isMessageFunction(val)) {
1871
+ return val;
1872
+ }
1873
+ else {
1874
+ // TODO: should be implemented warning message
1875
+ return NOOP_MESSAGE_FUNCTION;
1876
+ }
1877
+ };
1878
+ const ctxOptions = {
1879
+ locale,
1880
+ modifiers,
1881
+ pluralRules,
1882
+ messages: resolveMessage
1883
+ };
1884
+ if (context.processor) {
1885
+ ctxOptions.processor = context.processor;
1886
+ }
1887
+ if (options.list) {
1888
+ ctxOptions.list = options.list;
1889
+ }
1890
+ if (options.named) {
1891
+ ctxOptions.named = options.named;
1892
+ }
1893
+ if (isNumber(options.plural)) {
1894
+ ctxOptions.pluralIndex = options.plural;
1895
+ }
1896
+ return ctxOptions;
1897
+ }
1898
+
1899
+ {
1900
+ initFeatureFlags();
1901
+ }
1902
+
1903
+ export { AST_NODE_PROPS_KEYS, CORE_ERROR_CODES_EXTEND_POINT, CORE_WARN_CODES_EXTEND_POINT, CoreErrorCodes, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_REOSLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compile, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getAdditionalMeta, getDevToolsHook, getFallbackContext, getLocale, getWarnMessage, handleMissing, initI18nDevTools, isAlmostSameLocale, isImplicitFallback, isMessageAST, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveLocale, resolveValue, resolveWithKeyValue, setAdditionalMeta, setDevToolsHook, setFallbackContext, translate, translateDevTools, updateFallbackLocale };