@menapo/vi18n 0.1.1 → 0.1.2

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 (118) hide show
  1. package/dist/{apply-Bre-lY9J.js → apply-FAHl1R6T.js} +69 -89
  2. package/dist/{captured-Bj8bO6vd.js → captured-CTjjDF5o.js} +196 -217
  3. package/dist/{check-BIKEuu6B.js → check-DwFwOB1d.js} +66 -84
  4. package/dist/cli.js +2 -3
  5. package/dist/{collect-Cx4_SKOe.js → collect-CYATDjdo.js} +1 -2
  6. package/dist/collisions-uMTuq36M.js +215 -0
  7. package/dist/compile-CEvH-6sY.js +240 -0
  8. package/dist/{compile-Cc97JaW2.js → compile-DqkofbiO.js} +376 -331
  9. package/dist/concurrency-BCY_4zcr.js +1 -0
  10. package/dist/concurrency-Dy2ny50V.js +107 -0
  11. package/dist/config.d.ts +1 -5
  12. package/dist/config.js +4 -5
  13. package/dist/{types-D3QGM8XO.js → diagnostics-1onDF6Ua.js} +26 -26
  14. package/dist/{dir-zw6bGMKQ.js → dir-TGLYuOZb.js} +34 -37
  15. package/dist/{duplicates-yuRljQ6h.js → duplicates-CsUXRX2J.js} +10 -27
  16. package/dist/engine-Bf7nVigL.js +556 -0
  17. package/dist/engine.d.ts +1 -5
  18. package/dist/engine.js +297 -168
  19. package/dist/exchange-DYG9RZoT.js +41 -0
  20. package/dist/{exclude-Du-Zd_qI.js → exclude-vMnm3lqU.js} +2 -3
  21. package/dist/{export-C9Sy6UWv.js → export-BYq0gfLd.js} +17 -38
  22. package/dist/{extract-C3S8btx0.js → extract-CYtuEo8u.js} +114 -82
  23. package/dist/{formats-9unqj_fZ.js → formats-ChV1LVH_.js} +352 -276
  24. package/dist/fs-ezCMZeDV.js +52 -0
  25. package/dist/i18next-1waHziMy.js +1 -0
  26. package/dist/i18next-D66Icz3L.js +1907 -0
  27. package/dist/{import-nANvQutw.js → import-BApbQlmm.js} +81 -75
  28. package/dist/index.d.ts +1 -13
  29. package/dist/index.js +14 -16
  30. package/dist/{init-C2ScuW6a.js → init-J7AwwA5e.js} +466 -501
  31. package/dist/{library-D5CWvTQs.js → library-BfSOBeBd.js} +975 -451
  32. package/dist/lingui-Ee2farVo.js +902 -0
  33. package/dist/lint.d.ts +0 -4
  34. package/dist/lint.js +68 -81
  35. package/dist/{load-gW-oJt1Q.js → load-BFLLqY8x.js} +272 -147
  36. package/dist/{load-CQRz4PpM.js → load-CMwhukZ4.js} +1211 -1115
  37. package/dist/{locales-DX4MOBFE.js → locales-DxLDrx-h.js} +271 -237
  38. package/dist/{lsp-RMMMc88P.js → lsp-BC7xDGON.js} +4 -5
  39. package/dist/{match-BGr8EXB3.js → match-BLDcj610.js} +11 -4
  40. package/dist/{mcp-CHVwBoRP.js → mcp-Cka8ywDF.js} +4 -5
  41. package/dist/{merge-driver-BTX87aVm.js → merge-driver-B04Apm29.js} +138 -122
  42. package/dist/migrate-D7TNl6SD.js +2169 -0
  43. package/dist/migrate-khCY8TE0.js +1 -0
  44. package/dist/{openai-CTaMDcl-.js → openai-RWw0YlAx.js} +128 -87
  45. package/dist/{output-DWE3SIUA.js → output-CF9uvk_-.js} +15 -9
  46. package/dist/parse.d.ts +1 -3
  47. package/dist/parse.js +7 -8
  48. package/dist/{pipeline-DbX6rlo5.js → pipeline-B30irGMD.js} +1 -1
  49. package/dist/{pipeline-C9Dbotkh.js → pipeline-sgl_q_op.js} +387 -359
  50. package/dist/project-DSzWKU3C.js +544 -0
  51. package/dist/{pseudo-DRv30iN5.js → pseudo-DNbNNVGP.js} +125 -3
  52. package/dist/{raw-C4Y6vyGY.js → raw-YsYZMS9n.js} +52 -29
  53. package/dist/react-intl-tzGIk6G3.js +634 -0
  54. package/dist/restore-BG_zMpSj.js +199 -0
  55. package/dist/rewrite-hAcRJwiZ.js +415 -0
  56. package/dist/{rich-DCUKl5HM.js → rich-ApY1Dm4S.js} +35 -28
  57. package/dist/rolldown-runtime-C1I3wEg2.js +43 -0
  58. package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
  59. package/dist/run-CFzR3V93.js +647 -0
  60. package/dist/scan-worker.d.ts +2 -4
  61. package/dist/scan-worker.js +1 -1
  62. package/dist/{scoped-BMYpSthj.js → scoped-h3KE8XWW.js} +3 -4
  63. package/dist/{server-deBOq2vq.js → server-WlxZH0oX.js} +275 -330
  64. package/dist/{server-Da1Ot9IN.js → server-ceuzzkal.js} +292 -386
  65. package/dist/server.d.ts +1 -17
  66. package/dist/server.js +415 -381
  67. package/dist/{sitemap-DJXzKoza.js → sitemap-796jJKUT.js} +21 -33
  68. package/dist/{sources-D19czDSA.js → sources-DuOdM02f.js} +712 -373
  69. package/dist/{status-zr4jY59Y.js → status-CTH3qI-0.js} +30 -30
  70. package/dist/{stdio-FPOKQAgu.js → stdio-D9kTzyqB.js} +2 -4
  71. package/dist/{stdio-CVaJfxA7.js → stdio-FWIVU3P4.js} +1 -2
  72. package/dist/sync-CpL0Qsgw.js +1352 -0
  73. package/dist/{t-DC-c9zE5.js → t-gvEXx25s.js} +76 -53
  74. package/dist/test.d.ts +5 -16
  75. package/dist/test.js +77 -48
  76. package/dist/translate-BrfVRkjl.js +336 -0
  77. package/dist/{ts-BaU5yOf0.js → ts-BX6kwig5.js} +25 -14
  78. package/dist/{types-DtvQ7UdD.js → types-3kwyaCAm.js} +1 -2
  79. package/dist/{types-DsdWBG0b.d.ts → types-BaG1LboH.d.ts} +2 -6
  80. package/dist/{types-CgUCkFU1.d.ts → types-Cy2bPdSg.d.ts} +14 -20
  81. package/dist/types-Ds_vebja.js +41 -0
  82. package/dist/{units-CQ5Q99RC.js → units-VVLgQ7x7.js} +7 -16
  83. package/dist/{url-CRfCOhUI.js → url-Bpc6wLea.js} +24 -11
  84. package/dist/{url-CsBkRaJy.js → url-D2_VlEeH.js} +25 -12
  85. package/dist/{validate-D6DJepZv.js → validate-PGgMsasz.js} +3 -5
  86. package/dist/{validate-BxpupdAf.js → validate-zv4-IZyZ.js} +690 -377
  87. package/dist/{version-Byqi2guX.js → version-BFs370Ce.js} +3 -5
  88. package/dist/{vite-scan-CT_vsp4g.js → vite-scan-DFKSGVE9.js} +87 -92
  89. package/dist/vite.d.ts +2 -6
  90. package/dist/vite.js +6482 -6018
  91. package/dist/vue-i18n-CBmZqHbG.js +806 -0
  92. package/dist/{which-BOemZ5Q8.js → which-BpyJyBkX.js} +44 -37
  93. package/dist/{worker-84U6uYB3.js → worker-BjzVqJVO.js} +454 -608
  94. package/package.json +5 -5
  95. package/dist/check-HsmmpJZg.js +0 -1
  96. package/dist/codec-DuvU2VQy.js +0 -207
  97. package/dist/collisions-CfpZU8e4.js +0 -217
  98. package/dist/compile-BaDh0cHG.js +0 -245
  99. package/dist/concurrency-C9UUWuDC.js +0 -96
  100. package/dist/concurrency-DONL7t4V.js +0 -1
  101. package/dist/engine-C2ENBRJe.js +0 -531
  102. package/dist/i18next-9HAoxwUI.js +0 -1
  103. package/dist/i18next-BEJgv_S8.js +0 -1596
  104. package/dist/lingui-zUiCl9Um.js +0 -833
  105. package/dist/messages-BfjIExyB.js +0 -166
  106. package/dist/migrate-IpLDMXmq.js +0 -1484
  107. package/dist/migrate-rCQuOGsf.js +0 -1
  108. package/dist/project-Bw9UPIdx.js +0 -1046
  109. package/dist/project-C4GpaN-n.js +0 -381
  110. package/dist/react-intl-BP0u-D5m.js +0 -519
  111. package/dist/restore-CiYv-jxS.js +0 -175
  112. package/dist/rewrite-EsIw_lsq.js +0 -803
  113. package/dist/run-BEcnBbu-.js +0 -694
  114. package/dist/runtime-DTMmliT1.js +0 -64
  115. package/dist/sync-B9V2KFwb.js +0 -658
  116. package/dist/translate-CQnJfLjO.js +0 -299
  117. package/dist/types-wSh9fCBY.js +0 -11
  118. package/dist/vue-i18n-g0iGy6CZ.js +0 -651
@@ -1,5 +1,5 @@
1
- import { m as OP } from "./dir-zw6bGMKQ.js";
2
- //#region src/core/diagnostics.ts
1
+ import { p as OP } from "./dir-TGLYuOZb.js";
2
+ // src/core/diagnostics.ts
3
3
  /**
4
4
  * The only way core code creates a throwable diagnostic, so every error that
5
5
  * crosses a module boundary can be reported without knowing who threw it.
@@ -21,8 +21,7 @@ function isDiagnosticError(error) {
21
21
  const diagnostic = error.diagnostic;
22
22
  return typeof diagnostic === "object" && diagnostic !== null && typeof diagnostic.code === "string";
23
23
  }
24
- //#endregion
25
- //#region src/core/icu/skeleton.ts
24
+ // src/core/icu/skeleton.ts
26
25
  const fail = (code, message) => ({
27
26
  ok: false,
28
27
  code,
@@ -233,22 +232,13 @@ function applyNumberStem(stem, parts, token, options) {
233
232
  case "currency": {
234
233
  const code = parts[1];
235
234
  if (optionCount !== 1 || code === void 0) return fail("icu-unknown-currency", `${token} needs one currency code: write ::currency/EUR (with the code you need)`);
236
- if (!supportedCurrencies().has(code)) return fail("icu-unknown-currency", `Unknown currency code "${code}": use an ISO 4217 code such as EUR`);
235
+ if (!isSupportedCurrency(code)) return fail("icu-unknown-currency", `Unknown currency code "${code}": use an ISO 4217 code such as EUR`);
237
236
  options.style = "currency";
238
237
  options.currency = code;
239
238
  return null;
240
239
  }
241
240
  case "measure-unit":
242
- case "unit": {
243
- const written = parts[1];
244
- if (optionCount !== 1 || written === void 0) return fail("icu-unknown-unit", `${token} needs one unit: write ::unit/kilometer or ::measure-unit/length-meter`);
245
- const unit = written.replace(/^(.*?)-/, "");
246
- if (stem === "unit" && unit !== written) return fail("icu-unknown-unit", isSupportedUnit(unit) && !isSupportedUnit(written) ? `${token} has a unit type: write ::unit/${unit} or ::measure-unit/${written}` : `${token} names a hyphenated unit, which ::unit/ cannot express: write ::measure-unit/<type>-${written}, as in ::measure-unit/volume-fluid-ounce or ::measure-unit/speed-kilometer-per-hour`);
247
- if (!isSupportedUnit(unit)) return fail("icu-unknown-unit", `Unknown unit "${written}": use a unit Intl.NumberFormat supports, such as kilometer`);
248
- options.style = "unit";
249
- options.unit = unit;
250
- return null;
251
- }
241
+ case "unit": return unitStem(stem, parts, token, options);
252
242
  case "scientific":
253
243
  case "engineering":
254
244
  options.notation = stem;
@@ -267,6 +257,22 @@ function applyNumberStem(stem, parts, token, options) {
267
257
  case "scale":
268
258
  case "%x100": return unknownStem(token, "scaling is not supported: scale the value before formatting it");
269
259
  }
260
+ return applyShapedStem(stem, parts, token, options);
261
+ }
262
+ /** `unit/…` and `measure-unit/…`. */
263
+ function unitStem(stem, parts, token, options) {
264
+ const written = parts[1];
265
+ if (parts.length !== 2 || written === void 0) return fail("icu-unknown-unit", `${token} needs one unit: write ::unit/kilometer or ::measure-unit/length-meter`);
266
+ const unit = written.replace(/^(.*?)-/, "");
267
+ if (stem === "unit" && unit !== written) return fail("icu-unknown-unit", isSupportedUnit(unit) && !isSupportedUnit(written) ? `${token} has a unit type: write ::unit/${unit} or ::measure-unit/${written}` : `${token} names a hyphenated unit, which ::unit/ cannot express: write ::measure-unit/<type>-${written}, as in ::measure-unit/volume-fluid-ounce or ::measure-unit/speed-kilometer-per-hour`);
268
+ if (!isSupportedUnit(unit)) return fail("icu-unknown-unit", `Unknown unit "${written}": use a unit Intl.NumberFormat supports, such as kilometer`);
269
+ options.style = "unit";
270
+ options.unit = unit;
271
+ return null;
272
+ }
273
+ /** Stems recognised by their shape: concise integer width, precision, sign, concise notation. */
274
+ function applyShapedStem(stem, parts, token, options) {
275
+ const optionCount = parts.length - 1;
270
276
  if (CONCISE_INTEGER_WIDTH.test(stem)) {
271
277
  if (optionCount > 0) return unknownStem(token, `${stem} takes no option`);
272
278
  options.minimumIntegerDigits = stem.length;
@@ -275,16 +281,7 @@ function applyNumberStem(stem, parts, token, options) {
275
281
  const fraction = FRACTION_PRECISION.exec(stem);
276
282
  if (fraction !== null) {
277
283
  if (optionCount > 1) return unknownStem(token, "fraction precision takes at most one option");
278
- const [, zeros, star, hashes, minZeros, maxHashes] = fraction;
279
- if (star === "*") options.minimumFractionDigits = zeros.length;
280
- else if (hashes !== void 0) options.maximumFractionDigits = hashes.length;
281
- else if (minZeros !== void 0 && maxHashes !== void 0) {
282
- options.minimumFractionDigits = minZeros.length;
283
- options.maximumFractionDigits = minZeros.length + maxHashes.length;
284
- } else {
285
- options.minimumFractionDigits = zeros.length;
286
- options.maximumFractionDigits = zeros.length;
287
- }
284
+ applyFraction(fraction, options);
288
285
  const option = parts[1];
289
286
  if (option === "w") options.trailingZeroDisplay = "stripIfInteger";
290
287
  else if (option !== void 0 && !applySignificant(option, options)) return unknownStem(token, `"${option}" is neither w nor a significant-digits option such as @@#`);
@@ -311,11 +308,24 @@ function applyNumberStem(stem, parts, token, options) {
311
308
  }
312
309
  return unknownStem(token, "not a number skeleton stem vi18n supports");
313
310
  }
311
+ /** A fraction precision stem's digit counts (`.00`, `.0*`, `.##`, `.0#`). */
312
+ function applyFraction(fraction, options) {
313
+ const [, zeros, star, hashes, minZeros, maxHashes] = fraction;
314
+ if (star === "*") options.minimumFractionDigits = zeros.length;
315
+ else if (hashes !== void 0) options.maximumFractionDigits = hashes.length;
316
+ else if (minZeros !== void 0 && maxHashes !== void 0) {
317
+ options.minimumFractionDigits = minZeros.length;
318
+ options.maximumFractionDigits = minZeros.length + maxHashes.length;
319
+ } else {
320
+ options.minimumFractionDigits = zeros.length;
321
+ options.maximumFractionDigits = zeros.length;
322
+ }
323
+ }
314
324
  /** FormatJS `parseSignificantPrecision`, restricted to inputs it does not crash on. */
315
325
  function applySignificant(text, options) {
316
326
  const match = SIGNIFICANT_PRECISION.exec(text);
317
327
  if (match === null) return false;
318
- const [, ats, extra, priority] = match;
328
+ const [, ats = "", extra, priority] = match;
319
329
  if (priority === "r") options.roundingPriority = "morePrecision";
320
330
  else if (priority === "s") options.roundingPriority = "lessPrecision";
321
331
  if (extra === void 0) {
@@ -425,6 +435,15 @@ function dateSkeleton(skeleton) {
425
435
  options: nonEmpty(options)
426
436
  };
427
437
  }
438
+ /** The width of a text field (era, weekday) by its length: 4 long, 5 narrow, else short. */
439
+ const TEXT_WIDTHS = [
440
+ "short",
441
+ "short",
442
+ "short",
443
+ "long",
444
+ "narrow",
445
+ "short"
446
+ ];
428
447
  function applyDateField(run, options) {
429
448
  const symbol = run[0];
430
449
  const length = run.length;
@@ -435,12 +454,12 @@ function applyDateField(run, options) {
435
454
  return null;
436
455
  };
437
456
  switch (symbol) {
438
- case "G": return set("era", length === 4 ? "long" : length === 5 ? "narrow" : "short");
457
+ case "G": return set("era", TEXT_WIDTHS[length - 1]);
439
458
  case "y": return set("year", length === 2 ? "2-digit" : "numeric");
440
459
  case "M":
441
460
  case "L": return set("month", MONTH_WIDTHS[length - 1]);
442
461
  case "d": return set("day", NUMERIC_2DIGIT[length - 1]);
443
- case "E": return set("weekday", length === 4 ? "long" : length === 5 ? "narrow" : "short");
462
+ case "E": return set("weekday", TEXT_WIDTHS[length - 1]);
444
463
  case "e":
445
464
  case "c":
446
465
  if (length < 4) return unknownDate(run, "numeric weekdays are not supported; use EEE or EEEE");
@@ -484,9 +503,6 @@ function nonEmpty(options) {
484
503
  }
485
504
  let currencies;
486
505
  let units;
487
- function supportedCurrencies() {
488
- return currencies ??= new Set(Intl.supportedValuesOf("currency"));
489
- }
490
506
  /** A sanctioned unit, or `<unit>-per-<unit>` of two (what Intl.NumberFormat accepts). */
491
507
  function isSupportedUnit(unit) {
492
508
  units ??= new Set(Intl.supportedValuesOf("unit"));
@@ -494,8 +510,11 @@ function isSupportedUnit(unit) {
494
510
  const per = unit.indexOf("-per-");
495
511
  return per > 0 && units.has(unit.slice(0, per)) && units.has(unit.slice(per + 5));
496
512
  }
497
- //#endregion
498
- //#region src/core/icu/parse.ts
513
+ function isSupportedCurrency(code) {
514
+ currencies ??= new Set(Intl.supportedValuesOf("currency"));
515
+ return currencies.has(code);
516
+ }
517
+ // src/core/icu/parse.ts
499
518
  /**
500
519
  * ICU MessageFormat 1 in FormatJS's dialect (INTERNALS §2.1), written as one
501
520
  * recursive-descent pass over UTF-16 code units: every syntax character is
@@ -572,6 +591,18 @@ function positionAt(source, offset) {
572
591
  column: end - lineStart + 1
573
592
  };
574
593
  }
594
+ /** An apostrophe before `next` opens a quoted section (ICU's ApostropheMode DOUBLE_OPTIONAL). */
595
+ function opensQuote(next, poundSensitive) {
596
+ return next === LBRACE$2 || next === RBRACE$2 || next === LT$1 || next === GT$1 || next === HASH$2 && poundSensitive;
597
+ }
598
+ /** The apostrophe closing a quoted section whose text starts before `from` (`''` is one apostrophe in it), or the end. */
599
+ function closingQuote(src, from) {
600
+ let pos = from;
601
+ while (pos < src.length) if (src.charCodeAt(pos) !== APOS$1) pos++;
602
+ else if (src.charCodeAt(pos + 1) === APOS$1) pos += 2;
603
+ else return pos;
604
+ return src.length;
605
+ }
575
606
  var Parser$1 = class {
576
607
  src;
577
608
  locations;
@@ -602,13 +633,7 @@ var Parser$1 = class {
602
633
  else if (c === HASH$2 && poundSensitive) {
603
634
  if (!pluralParent) throw this.error("icu-pound-nested", "# is ambiguous inside a select nested in a plural: write the plural's argument (as in {count}) for the number, or '#' for a literal #", this.pos);
604
635
  const start = this.pos++;
605
- nodes.push(this.locations ? {
606
- type: "pound",
607
- loc: {
608
- start,
609
- end: this.pos
610
- }
611
- } : { type: "pound" });
636
+ nodes.push(this.located({ type: "pound" }, start));
612
637
  } else if (c === LT$1 && src.charCodeAt(this.pos + 1) === SLASH$2) {
613
638
  if (inTag) break;
614
639
  throw this.error("icu-syntax", "Closing tag without a matching opening tag", this.pos);
@@ -616,17 +641,10 @@ var Parser$1 = class {
616
641
  else {
617
642
  const start = this.pos;
618
643
  const value = this.parseLiteral(depth, poundSensitive);
619
- nodes.push(this.locations ? {
620
- type: "literal",
621
- value,
622
- loc: {
623
- start,
624
- end: this.pos
625
- }
626
- } : {
644
+ nodes.push(this.located({
627
645
  type: "literal",
628
646
  value
629
- });
647
+ }, start));
630
648
  }
631
649
  }
632
650
  return nodes;
@@ -646,35 +664,13 @@ var Parser$1 = class {
646
664
  value += src.slice(run, pos + 1);
647
665
  pos += 2;
648
666
  run = pos;
649
- continue;
650
- }
651
- if (next === LBRACE$2 || next === RBRACE$2 || next === LT$1 || next === GT$1 || next === HASH$2 && poundSensitive) {
667
+ } else if (opensQuote(next, poundSensitive)) {
652
668
  this.quotes?.push(pos);
653
- value += src.slice(run, pos);
654
- let quoted = pos + 1;
655
- pos += 2;
656
- for (;;) {
657
- if (pos >= length) {
658
- value += src.slice(quoted, pos);
659
- break;
660
- }
661
- if (src.charCodeAt(pos) === APOS$1) {
662
- if (src.charCodeAt(pos + 1) === APOS$1) {
663
- value += src.slice(quoted, pos + 1);
664
- pos += 2;
665
- quoted = pos;
666
- continue;
667
- }
668
- value += src.slice(quoted, pos);
669
- pos++;
670
- break;
671
- }
672
- pos++;
673
- }
669
+ const close = closingQuote(src, pos + 2);
670
+ value += src.slice(run, pos) + src.slice(pos + 1, close).replaceAll("''", "'");
671
+ pos = close < length ? close + 1 : close;
674
672
  run = pos;
675
- continue;
676
- }
677
- pos++;
673
+ } else pos++;
678
674
  continue;
679
675
  }
680
676
  if (c === LBRACE$2) break;
@@ -694,19 +690,11 @@ var Parser$1 = class {
694
690
  this.skipSpace();
695
691
  if (this.src.startsWith("/>", this.pos)) {
696
692
  this.pos += 2;
697
- return this.locations ? {
698
- type: "tag",
699
- name,
700
- children: null,
701
- loc: {
702
- start,
703
- end: this.pos
704
- }
705
- } : {
693
+ return this.located({
706
694
  type: "tag",
707
695
  name,
708
696
  children: null
709
- };
697
+ }, start);
710
698
  }
711
699
  if (this.src.charCodeAt(this.pos) !== GT$1) throw this.error("icu-syntax", `Malformed tag <${name}: tags have no attributes`, start);
712
700
  this.pos++;
@@ -720,19 +708,11 @@ var Parser$1 = class {
720
708
  this.skipSpace();
721
709
  if (this.src.charCodeAt(this.pos) !== GT$1) throw this.error("icu-syntax", `Malformed closing tag for <${name}>`, closeStart);
722
710
  this.pos++;
723
- return this.locations ? {
724
- type: "tag",
725
- name,
726
- children,
727
- loc: {
728
- start,
729
- end: this.pos
730
- }
731
- } : {
711
+ return this.located({
732
712
  type: "tag",
733
713
  name,
734
714
  children
735
- };
715
+ }, start);
736
716
  }
737
717
  /** Assumes the current character is an ASCII letter (checked by the caller). */
738
718
  parseTagName() {
@@ -758,17 +738,10 @@ var Parser$1 = class {
758
738
  const c = src.charCodeAt(this.pos);
759
739
  if (c === RBRACE$2) {
760
740
  this.pos++;
761
- return this.locations ? {
762
- type: "argument",
763
- name,
764
- loc: {
765
- start: open,
766
- end: this.pos
767
- }
768
- } : {
741
+ return this.located({
769
742
  type: "argument",
770
743
  name
771
- };
744
+ }, open);
772
745
  }
773
746
  if (c !== COMMA) throw this.malformed(open);
774
747
  this.pos++;
@@ -782,7 +755,11 @@ var Parser$1 = class {
782
755
  case "time": return this.parseFormatted(type, name, open);
783
756
  case "select":
784
757
  case "plural":
785
- case "selectordinal": return this.parseChoice(type, name, open, depth, poundSensitive, inTag);
758
+ case "selectordinal": return this.parseChoice({
759
+ type,
760
+ name,
761
+ open
762
+ }, depth, poundSensitive, inTag);
786
763
  case "": throw this.error("icu-syntax", `Expected an argument type after {${name},`, typeStart);
787
764
  default:
788
765
  if (UNSUPPORTED_TYPES.has(type)) throw this.error("icu-unsupported-type", type === "choice" ? "{…, choice} is not supported: use {…, plural} or {…, select}" : `{…, ${type}} is not supported because Intl cannot render it: use {…, number}, {…, plural} or {…, selectordinal}`, typeStart);
@@ -811,11 +788,7 @@ var Parser$1 = class {
811
788
  style: resolved.style,
812
789
  options: resolved.options
813
790
  };
814
- if (this.locations) node.loc = {
815
- start: open,
816
- end: this.pos
817
- };
818
- return node;
791
+ return this.located(node, open);
819
792
  }
820
793
  /** ICU `MessagePattern` simple style: up to the unbalanced `}`, quotes kept. */
821
794
  simpleStyle() {
@@ -839,7 +812,7 @@ var Parser$1 = class {
839
812
  }
840
813
  return src.slice(start, this.pos);
841
814
  }
842
- parseChoice(type, name, open, depth, poundSensitive, inTag) {
815
+ parseChoice({ type, name, open }, depth, poundSensitive, inTag) {
843
816
  const src = this.src;
844
817
  this.skipSpace();
845
818
  if (src.charCodeAt(this.pos) !== COMMA) throw this.error("icu-syntax", `Expected options after {${name}, ${type}`, this.pos);
@@ -876,17 +849,10 @@ var Parser$1 = class {
876
849
  const value = this.parseMessage(depth + 1, plural, childPoundSensitive, inTag);
877
850
  if (src.charCodeAt(this.pos) !== RBRACE$2) throw this.unclosed(valueOpen);
878
851
  this.pos++;
879
- options.push(this.locations ? {
880
- key,
881
- value,
882
- loc: {
883
- start: keyStart,
884
- end: this.pos
885
- }
886
- } : {
852
+ options.push(this.located({
887
853
  key,
888
854
  value
889
- });
855
+ }, keyStart));
890
856
  this.skipSpace();
891
857
  keyStart = this.pos;
892
858
  selector = this.identifier();
@@ -895,28 +861,24 @@ var Parser$1 = class {
895
861
  if (!keys.has("other")) throw this.error("icu-missing-other", `{${name}, ${type}} needs an other {…} option`, open);
896
862
  if (src.charCodeAt(this.pos) !== RBRACE$2) throw this.unclosed(open);
897
863
  this.pos++;
898
- if (type === "select") return this.locations ? {
899
- type: "select",
900
- name,
901
- options,
902
- loc: {
903
- start: open,
904
- end: this.pos
905
- }
906
- } : {
864
+ if (type === "select") return this.located({
907
865
  type: "select",
908
866
  name,
909
867
  options
910
- };
911
- const node = {
868
+ }, open);
869
+ const pluralType = type === "plural" ? "cardinal" : "ordinal";
870
+ return this.located({
912
871
  type: "plural",
913
- pluralType: type === "plural" ? "cardinal" : "ordinal",
872
+ pluralType,
914
873
  name,
915
874
  offset,
916
875
  options
917
- };
876
+ }, open);
877
+ }
878
+ /** `node` with its source range, from `start` to here, when locations are on. */
879
+ located(node, start) {
918
880
  if (this.locations) node.loc = {
919
- start: open,
881
+ start,
920
882
  end: this.pos
921
883
  };
922
884
  return node;
@@ -980,12 +942,46 @@ var Parser$1 = class {
980
942
  function isAsciiLetter(c) {
981
943
  return c >= 65 && c <= 90 || c >= 97 && c <= 122;
982
944
  }
945
+ /** Whether code point `c` falls in one of `ranges`, a flat list of inclusive `[low, high]` pairs. */
946
+ function inRanges(c, ranges) {
947
+ for (let i = 0; i < ranges.length; i += 2) if (c >= ranges[i] && c <= ranges[i + 1]) return true;
948
+ return false;
949
+ }
950
+ /** XML's NameChar beyond ASCII, as inclusive code point pairs. */
951
+ const TAG_NAME_RANGES = [
952
+ 183,
953
+ 183,
954
+ 192,
955
+ 214,
956
+ 216,
957
+ 246,
958
+ 248,
959
+ 893,
960
+ 895,
961
+ 8191,
962
+ 8204,
963
+ 8205,
964
+ 8255,
965
+ 8256,
966
+ 8304,
967
+ 8591,
968
+ 11264,
969
+ 12271,
970
+ 12289,
971
+ 55295,
972
+ 63744,
973
+ 64975,
974
+ 65008,
975
+ 65533,
976
+ 65536,
977
+ 983039
978
+ ];
983
979
  /** FormatJS `_isPotentialElementNameChar` (custom-element name characters); MF2 markup names are checked with it too. */
984
980
  function isTagNameChar(c) {
985
- return c === 45 || c === 46 || c >= 48 && c <= 57 || c === 95 || c >= 97 && c <= 122 || c >= 65 && c <= 90 || c === 183 || c >= 192 && c <= 214 || c >= 216 && c <= 246 || c >= 248 && c <= 893 || c >= 895 && c <= 8191 || c >= 8204 && c <= 8205 || c >= 8255 && c <= 8256 || c >= 8304 && c <= 8591 || c >= 11264 && c <= 12271 || c >= 12289 && c <= 55295 || c >= 63744 && c <= 64975 || c >= 65008 && c <= 65533 || c >= 65536 && c <= 983039;
981
+ if (c < 128) return c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 45 || c === 46 || c === 95;
982
+ return inRanges(c, TAG_NAME_RANGES);
986
983
  }
987
- //#endregion
988
- //#region src/core/mf2/syntax.ts
984
+ // src/core/mf2/syntax.ts
989
985
  /**
990
986
  * MessageFormat 2 syntax (Unicode LDML part 9, `message.abnf`) read into its
991
987
  * data model, with the spec's data-model errors (PLAN §4.2, INTERNALS §2.1.4).
@@ -1020,10 +1016,37 @@ const IDEOGRAPHIC_SPACE = 12288;
1020
1016
  const isWs = (c) => c === SPACE || c === TAB || c === LF || c === CR$1 || c === IDEOGRAPHIC_SPACE;
1021
1017
  /** `bidi`: ALM, LRM, RLM and the four isolates. */
1022
1018
  const isBidi = (c) => c === 1564 || c === 8206 || c === 8207 || c >= 8294 && c <= 8297;
1019
+ /** `name-start` beyond U+00A0, as inclusive code point pairs. */
1020
+ const NAME_START_RANGES = [
1021
+ 161,
1022
+ 1563,
1023
+ 1565,
1024
+ 5759,
1025
+ 5761,
1026
+ 8191,
1027
+ 8203,
1028
+ 8205,
1029
+ 8208,
1030
+ 8231,
1031
+ 8240,
1032
+ 8286,
1033
+ 8288,
1034
+ 8293,
1035
+ 8298,
1036
+ 12287,
1037
+ 12289,
1038
+ 55295,
1039
+ 57344,
1040
+ 64975,
1041
+ 65008,
1042
+ 65533,
1043
+ 65536,
1044
+ 1114109
1045
+ ];
1023
1046
  /** `name-start`, by code point. */
1024
1047
  function isNameStart(c) {
1025
1048
  if (c < 161) return c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === PLUS || c === UNDERSCORE;
1026
- return (c <= 1563 || c >= 1565 && c <= 5759 || c >= 5761 && c <= 8191 || c >= 8203 && c <= 8205 || c >= 8208 && c <= 8231 || c >= 8240 && c <= 8286 || c >= 8288 && c <= 8293 || c >= 8298 && c <= 12287 || c >= 12289 && c <= 55295 || c >= 57344 && c <= 64975 || c >= 65008 && c <= 65533 || c >= 65536 && c <= 1114109) && (c & 65534) !== 65534;
1049
+ return inRanges(c, NAME_START_RANGES) && (c & 65534) !== 65534;
1027
1050
  }
1028
1051
  const isNameChar = (c) => isNameStart(c) || c >= 48 && c <= 57 || c === MINUS || c === DOT;
1029
1052
  /**
@@ -1474,8 +1497,7 @@ function annotated(name, declared, visiting) {
1474
1497
  visiting.add(name);
1475
1498
  return operand?.type === "variable" && declaration.kind === "local" ? annotated(operand.name, declared, visiting) : false;
1476
1499
  }
1477
- //#endregion
1478
- //#region src/core/mf2/lower.ts
1500
+ // src/core/mf2/lower.ts
1479
1501
  /**
1480
1502
  * MF2 data model → the ICU AST (INTERNALS §2.1.4): the IR, ids, catalogs,
1481
1503
  * validation and pseudo-locales read MF2 messages exactly as they read ICU
@@ -1511,6 +1533,22 @@ const NUMERIC = /* @__PURE__ */ new Set([
1511
1533
  "percent",
1512
1534
  "currency"
1513
1535
  ]);
1536
+ function isKnownFn(name) {
1537
+ return KNOWN.has(name);
1538
+ }
1539
+ function isNumeric(name) {
1540
+ return NUMERIC.has(name);
1541
+ }
1542
+ /** The `select` modes of `:number` and `:integer`. */
1543
+ const SELECT_MODES = /* @__PURE__ */ new Set([
1544
+ "plural",
1545
+ "ordinal",
1546
+ "exact"
1547
+ ]);
1548
+ function isSelectMode(select) {
1549
+ return SELECT_MODES.has(select);
1550
+ }
1551
+ const selectError = (select) => `select=${select}: use plural, ordinal or exact`;
1514
1552
  /** `[^\p{White_Space}\p{Pattern_Syntax}]+`: ICU argument names and select keys. */
1515
1553
  const ICU_IDENTIFIER = /^[^\p{White_Space}\p{Pattern_Syntax}]+$/u;
1516
1554
  /** MF2's `number-literal`. */
@@ -1575,9 +1613,13 @@ var Lowering = class {
1575
1613
  }
1576
1614
  resolve(expression) {
1577
1615
  const { operand, fn, at } = expression;
1578
- if (fn !== null && !KNOWN.has(fn.name)) throw this.fail(fn.name === "offset" || fn.name === "math" ? `:${fn.name} is not supported: pass the adjusted number as a value` : `unknown function :${fn.name}: use :string, :number, :integer, :percent, :currency, :date, :time or :datetime`, at, fn.name === "offset" || fn.name === "math" ? "icu-unsupported-type" : "icu-syntax");
1616
+ const name = fn === null ? null : fn.name;
1617
+ if (name !== null && !isKnownFn(name)) {
1618
+ const removed = name === "offset" || name === "math";
1619
+ throw this.fail(removed ? `:${name} is not supported: pass the adjusted number as a value` : `unknown function :${name}: use :string, :number, :integer, :percent, :currency, :date, :time or :datetime`, at, removed ? "icu-unsupported-type" : "icu-syntax");
1620
+ }
1579
1621
  let base;
1580
- if (operand === null) throw this.fail(`{:${fn?.name}} has no operand: write {$name :${fn?.name}}`, at);
1622
+ if (operand === null) throw this.fail(`{:${name}} has no operand: write {$name :${name}}`, at);
1581
1623
  else if (operand.type === "literal") base = {
1582
1624
  kind: "text",
1583
1625
  text: operand.value
@@ -1587,8 +1629,7 @@ var Lowering = class {
1587
1629
  name: operand.name,
1588
1630
  fn: null
1589
1631
  };
1590
- if (fn === null) return base;
1591
- const name = fn.name;
1632
+ if (fn === null || name === null) return base;
1592
1633
  const own = this.options(name, fn.options, at);
1593
1634
  if (name === "string") {
1594
1635
  if (base.kind === "arg") return {
@@ -1601,29 +1642,7 @@ var Lowering = class {
1601
1642
  text: base.text
1602
1643
  };
1603
1644
  }
1604
- if (NUMERIC.has(name)) {
1605
- const merged = inherit(name, base.kind === "text" ? null : base.fn, own);
1606
- if (name === "currency" && !merged.options.has("currency")) throw this.fail(":currency needs currency=EUR (the ISO 4217 code)", at);
1607
- this.style(merged, at);
1608
- if (base.kind === "text") {
1609
- if (!NUMBER_LITERAL.test(base.text)) throw this.fail(`${JSON.stringify(base.text)} is not a number for :${name}`, at);
1610
- return {
1611
- kind: "number",
1612
- text: base.text,
1613
- fn: merged
1614
- };
1615
- }
1616
- if (base.kind === "number") return {
1617
- kind: "number",
1618
- text: base.text,
1619
- fn: merged
1620
- };
1621
- return {
1622
- kind: "arg",
1623
- name: base.name,
1624
- fn: merged
1625
- };
1626
- }
1645
+ if (isNumeric(name)) return this.numeric(name, base, own, at);
1627
1646
  if (base.kind !== "arg") throw this.fail(`formatting a literal date depends on the time zone: pass the date as a value`, at, "icu-unsupported-type");
1628
1647
  const fnDate = annotation(name, own);
1629
1648
  this.style(fnDate, at);
@@ -1633,6 +1652,23 @@ var Lowering = class {
1633
1652
  fn: fnDate
1634
1653
  };
1635
1654
  }
1655
+ /** A numeric annotation on `base`, over the options `base` already has. */
1656
+ numeric(name, base, own, at) {
1657
+ const merged = inherit(name, base.kind === "text" ? null : base.fn, own);
1658
+ if (name === "currency" && !merged.options.has("currency")) throw this.fail(":currency needs currency=EUR (the ISO 4217 code)", at);
1659
+ this.style(merged, at);
1660
+ if (base.kind === "arg") return {
1661
+ kind: "arg",
1662
+ name: base.name,
1663
+ fn: merged
1664
+ };
1665
+ if (base.kind === "text" && !NUMBER_LITERAL.test(base.text)) throw this.fail(`${JSON.stringify(base.text)} is not a number for :${name}`, at);
1666
+ return {
1667
+ kind: "number",
1668
+ text: base.text,
1669
+ fn: merged
1670
+ };
1671
+ }
1636
1672
  /** Literal option values; a variable must name a constant declared earlier. */
1637
1673
  options(fn, options, at) {
1638
1674
  const out = /* @__PURE__ */ new Map();
@@ -1712,7 +1748,7 @@ var Lowering = class {
1712
1748
  let type = "number";
1713
1749
  let style;
1714
1750
  try {
1715
- if (NUMERIC.has(fn.name)) style = numberStyle(fn);
1751
+ if (isNumeric(fn.name)) style = numberStyle(fn.name, fn.options);
1716
1752
  else [type, style] = dateStyle(fn);
1717
1753
  } catch (error) {
1718
1754
  if (error instanceof Unsupported) throw this.fail(error.message, at, error.code);
@@ -1748,7 +1784,7 @@ var Lowering = class {
1748
1784
  if (fn.name === "number" || fn.name === "integer") {
1749
1785
  if (fn.inheritedSelect) throw this.fail(`$${name} takes select from the value it is declared from: set select on its own annotation`, at);
1750
1786
  const select = fn.options.get("select") ?? "plural";
1751
- if (select !== "plural" && select !== "ordinal" && select !== "exact") throw this.fail(`select=${select}: use plural, ordinal or exact`, at);
1787
+ if (!isSelectMode(select)) throw this.fail(selectError(select), at);
1752
1788
  if (value.kind === "number") return {
1753
1789
  kind: "constant-number",
1754
1790
  text: value.text,
@@ -1778,32 +1814,14 @@ var Lowering = class {
1778
1814
  }
1779
1815
  const selector = selectors[i];
1780
1816
  const keys = [];
1781
- for (const group of live) for (const variant of group) {
1817
+ for (const variant of live.flat()) {
1782
1818
  const key = variant.keys[i];
1783
1819
  if (key !== null && !keys.includes(key)) keys.push(key);
1784
1820
  }
1785
1821
  const only = (key) => (group) => group.filter((variant) => variant.keys[i] === key);
1786
1822
  const next = (...picks) => this.expand(selectors, i + 1, live.flatMap((group) => picks.map((pick) => pick(group))));
1787
1823
  if (selector.kind === "constant") return next(only(selector.text), only(null));
1788
- if (selector.kind === "string") {
1789
- for (const key of keys) if (!ICU_IDENTIFIER.test(key)) throw this.fail(`the key ${JSON.stringify(key)} cannot be an ICU select key (no spaces or punctuation)`, this.message.matchAt, "icu-unsupported-type");
1790
- const options = keys.map((key) => ({
1791
- key,
1792
- value: next(only(key), only(null))
1793
- }));
1794
- const fallback = next(only(null));
1795
- const other = options.find((option) => option.key === "other");
1796
- if (other === void 0) options.push({
1797
- key: "other",
1798
- value: fallback
1799
- });
1800
- else if (!same(other.value, fallback)) throw this.fail(`a :string key "other" cannot be told apart from * in vi18n's IR: rename the value or merge the two variants`, this.message.matchAt, "icu-unsupported-type");
1801
- return this.choice({
1802
- type: "select",
1803
- name: selector.name,
1804
- options
1805
- });
1806
- }
1824
+ if (selector.kind === "string") return this.stringSelect(selector.name, keys, only, next);
1807
1825
  const exact = [];
1808
1826
  const categories = [];
1809
1827
  for (const key of keys) if (NUMBER_LITERAL.test(key)) {
@@ -1817,26 +1835,6 @@ var Lowering = class {
1817
1835
  if (categories.length > 0 && !selector.exact) throw this.fail(`the plural category of the literal ${selector.text} depends on the locale: select on a value`, this.message.matchAt, "icu-unsupported-type");
1818
1836
  return next(only(String(Number(selector.text))), only(null));
1819
1837
  }
1820
- const byCategory = (prefix) => {
1821
- const first = prefix === null ? [] : [only(prefix)];
1822
- const options = categories.map((category) => ({
1823
- key: category,
1824
- value: next(...first, only(category), only(null))
1825
- }));
1826
- const fallback = next(...first, only(null));
1827
- const other = options.find((option) => option.key === "other");
1828
- if (other === void 0) options.push({
1829
- key: "other",
1830
- value: fallback
1831
- });
1832
- else if (!same(other.value, fallback)) {
1833
- for (const category of CATEGORIES) if (!categories.includes(category)) options.push({
1834
- key: category,
1835
- value: fallback
1836
- });
1837
- }
1838
- return options;
1839
- };
1840
1838
  const plural = (options) => this.choice({
1841
1839
  type: "plural",
1842
1840
  pluralType: selector.kind === "ordinal" ? "ordinal" : "cardinal",
@@ -1846,11 +1844,31 @@ var Lowering = class {
1846
1844
  });
1847
1845
  const options = exact.map((key) => ({
1848
1846
  key: "=" + String(Number(key)),
1849
- value: plural(byCategory(key))
1847
+ value: plural(byCategory(only, next, categories, key))
1850
1848
  }));
1851
- options.push(...byCategory(null));
1849
+ options.push(...byCategory(only, next, categories, null));
1852
1850
  return plural(options);
1853
1851
  }
1852
+ /** A `:string` selector's select, one case per key and `other` for `*`. */
1853
+ stringSelect(name, keys, only, next) {
1854
+ for (const key of keys) if (!ICU_IDENTIFIER.test(key)) throw this.fail(`the key ${JSON.stringify(key)} cannot be an ICU select key (no spaces or punctuation)`, this.message.matchAt, "icu-unsupported-type");
1855
+ const options = keys.map((key) => ({
1856
+ key,
1857
+ value: next(only(key), only(null))
1858
+ }));
1859
+ const fallback = next(only(null));
1860
+ const other = options.find((option) => option.key === "other");
1861
+ if (other === void 0) options.push({
1862
+ key: "other",
1863
+ value: fallback
1864
+ });
1865
+ else if (!same(other.value, fallback)) throw this.fail(`a :string key "other" cannot be told apart from * in vi18n's IR: rename the value or merge the two variants`, this.message.matchAt, "icu-unsupported-type");
1866
+ return this.choice({
1867
+ type: "select",
1868
+ name,
1869
+ options
1870
+ });
1871
+ }
1854
1872
  /** A select or plural, or its one value when every case renders the same. */
1855
1873
  choice(node) {
1856
1874
  const [first, ...rest] = node.options;
@@ -1861,6 +1879,27 @@ var Lowering = class {
1861
1879
  return mf2Error(this.source, message, offset, code);
1862
1880
  }
1863
1881
  };
1882
+ /** The cases after an exact key `prefix` (or none): categories, then `*`. */
1883
+ function byCategory(only, next, categories, prefix) {
1884
+ const first = prefix === null ? [] : [only(prefix)];
1885
+ const options = categories.map((category) => ({
1886
+ key: category,
1887
+ value: next(...first, only(category), only(null))
1888
+ }));
1889
+ const fallback = next(...first, only(null));
1890
+ const other = options.find((option) => option.key === "other");
1891
+ if (other === void 0) options.push({
1892
+ key: "other",
1893
+ value: fallback
1894
+ });
1895
+ else if (!same(other.value, fallback)) {
1896
+ for (const category of CATEGORIES) if (!categories.includes(category)) options.push({
1897
+ key: category,
1898
+ value: fallback
1899
+ });
1900
+ }
1901
+ return options;
1902
+ }
1864
1903
  function annotation(name, options) {
1865
1904
  return {
1866
1905
  name,
@@ -1868,6 +1907,19 @@ function annotation(name, options) {
1868
1907
  inheritedSelect: false
1869
1908
  };
1870
1909
  }
1910
+ /** The options of the value an annotation is declared from that it does not take over. */
1911
+ const DROPPED = {
1912
+ integer: [
1913
+ "minimumFractionDigits",
1914
+ "maximumFractionDigits",
1915
+ "minimumSignificantDigits"
1916
+ ],
1917
+ percent: [
1918
+ "minimumIntegerDigits",
1919
+ "roundingIncrement",
1920
+ "select"
1921
+ ]
1922
+ };
1871
1923
  /**
1872
1924
  * MF2 option inheritance: a numeric annotation on a numeric value keeps the
1873
1925
  * value's options it has itself, its own winning; `:integer` drops fraction
@@ -1875,17 +1927,9 @@ function annotation(name, options) {
1875
1927
  * `select`.
1876
1928
  */
1877
1929
  function inherit(name, prev, own) {
1878
- if (prev === null || !NUMERIC.has(prev.name)) return annotation(name, own);
1930
+ if (prev === null || !isNumeric(prev.name)) return annotation(name, own);
1879
1931
  const known = OPTIONS[name];
1880
- const dropped = name === "integer" ? [
1881
- "minimumFractionDigits",
1882
- "maximumFractionDigits",
1883
- "minimumSignificantDigits"
1884
- ] : name === "percent" ? [
1885
- "minimumIntegerDigits",
1886
- "roundingIncrement",
1887
- "select"
1888
- ] : [];
1932
+ const dropped = DROPPED[name] ?? [];
1889
1933
  const options = /* @__PURE__ */ new Map();
1890
1934
  for (const [key, value] of prev.options) if (known.includes(key) && !dropped.includes(key)) options.set(key, value);
1891
1935
  const inheritedSelect = options.has("select") && !own.has("select");
@@ -1991,109 +2035,119 @@ const OPTIONS = {
1991
2035
  * options match what MF2's `Intl.NumberFormat`-named options mean). Keyword
1992
2036
  * styles where one says the same: `integer`, `percent`.
1993
2037
  */
1994
- function numberStyle(fn) {
1995
- const o = fn.options;
1996
- for (const key of o.keys()) if (!OPTIONS[fn.name].includes(key)) throw invalid(`:${fn.name} has no option ${key}`);
1997
- const digits = (key) => {
1998
- const value = o.get(key);
1999
- if (value === void 0) return null;
2000
- if (!DIGIT_SIZE.test(value)) throw invalid(`${key}=${value} is not a digit count`);
2001
- return Number(value);
2002
- };
2038
+ function numberStyle(name, o) {
2039
+ for (const key of o.keys()) if (!OPTIONS[name].includes(key)) throw invalid(`:${name} has no option ${key}`);
2003
2040
  const tokens = [];
2004
- if (fn.name === "integer") tokens.push(".");
2005
- if (fn.name === "percent") tokens.push("percent");
2006
- if (fn.name === "currency") tokens.push("currency/" + o.get("currency").toUpperCase());
2007
- const minInt = digits("minimumIntegerDigits");
2008
- const minFrac = digits("minimumFractionDigits");
2009
- const maxFrac = digits("maximumFractionDigits");
2010
- const minSig = digits("minimumSignificantDigits");
2011
- const maxSig = digits("maximumSignificantDigits");
2041
+ if (name === "integer") tokens.push(".");
2042
+ if (name === "percent") tokens.push("percent");
2043
+ if (name === "currency") tokens.push("currency/" + o.get("currency").toUpperCase());
2044
+ const minInt = digits(o, "minimumIntegerDigits");
2045
+ const minFrac = digits(o, "minimumFractionDigits");
2046
+ const maxFrac = digits(o, "maximumFractionDigits");
2047
+ const minSig = digits(o, "minimumSignificantDigits");
2048
+ const maxSig = digits(o, "maximumSignificantDigits");
2012
2049
  if (minInt !== null) tokens.push("integer-width/*" + "0".repeat(minInt));
2013
- let fraction = null;
2014
- if (fn.name === "currency") {
2015
- const value = o.get("fractionDigits");
2016
- if (value !== void 0 && value !== "auto") {
2017
- if (!DIGIT_SIZE.test(value)) throw invalid(`fractionDigits=${value} is not a digit count`);
2018
- fraction = "." + "0".repeat(Number(value));
2019
- }
2020
- } else if (minFrac !== null || maxFrac !== null) {
2021
- const min = minFrac ?? 0;
2022
- if (maxFrac === null) fraction = min === 0 ? null : "." + "0".repeat(min) + "*";
2023
- else if (maxFrac < min) throw invalid("maximumFractionDigits is below minimumFractionDigits");
2024
- else fraction = "." + "0".repeat(min) + "#".repeat(maxFrac - min);
2025
- }
2026
- const strip = o.get("trailingZeroDisplay");
2027
- if (strip === "stripIfInteger") {
2028
- if (fraction === null || fraction.endsWith("*")) throw new Unsupported("trailingZeroDisplay=stripIfInteger needs both fraction digit counts");
2029
- if (fraction !== ".") fraction += "/w";
2030
- } else if (strip !== void 0 && strip !== "auto") throw new Unsupported(`trailingZeroDisplay=${strip} is not supported`);
2050
+ const fraction = stripped(name === "currency" ? currencyFraction(o) : fractionDigits(minFrac, maxFrac), o.get("trailingZeroDisplay"));
2031
2051
  if (fraction !== null) tokens.push(fraction);
2032
- let significant = null;
2033
- if (minSig !== null || maxSig !== null) {
2034
- const min = minSig ?? 1;
2035
- if (min < 1) throw invalid("minimumSignificantDigits must be at least 1");
2036
- if (maxSig === null) significant = "@".repeat(min) + "+";
2037
- else if (maxSig < min) throw invalid("maximumSignificantDigits is below minimumSignificantDigits");
2038
- else significant = "@".repeat(min) + "#".repeat(maxSig - min);
2039
- }
2040
- const priority = o.get("roundingPriority");
2041
- if (priority !== void 0 && priority !== "auto") {
2042
- if (significant === null || priority !== "morePrecision" && priority !== "lessPrecision") throw new Unsupported(`roundingPriority=${priority} needs significant digits set here`);
2043
- significant += priority === "morePrecision" ? "r" : "s";
2044
- }
2052
+ const significant = prioritised(significantDigits(minSig, maxSig), o.get("roundingPriority"));
2045
2053
  if (significant !== null) tokens.push(significant);
2054
+ tokens.push(...optionStems(o));
2055
+ const select = o.get("select");
2056
+ if (select !== void 0 && !isSelectMode(select)) throw invalid(selectError(select));
2057
+ if (tokens.length === 0) return null;
2058
+ if (tokens.length === 1 && tokens[0] === ".") return "integer";
2059
+ if (tokens.length === 1 && tokens[0] === "percent") return "percent";
2060
+ return "::" + tokens.join(" ");
2061
+ }
2062
+ /** A digit-count option, checked; null when not set. */
2063
+ function digits(o, key) {
2064
+ const value = o.get(key);
2065
+ if (value === void 0) return null;
2066
+ if (!DIGIT_SIZE.test(value)) throw invalid(`${key}=${value} is not a digit count`);
2067
+ return Number(value);
2068
+ }
2069
+ /** `:currency`'s `fractionDigits` as a precision stem. */
2070
+ function currencyFraction(o) {
2071
+ const value = o.get("fractionDigits");
2072
+ if (value === void 0 || value === "auto") return null;
2073
+ if (!DIGIT_SIZE.test(value)) throw invalid(`fractionDigits=${value} is not a digit count`);
2074
+ return "." + "0".repeat(Number(value));
2075
+ }
2076
+ /** Minimum and maximum fraction digits as a precision stem (`.00#`, `.0*`). */
2077
+ function fractionDigits(minFrac, maxFrac) {
2078
+ if (minFrac === null && maxFrac === null) return null;
2079
+ const min = minFrac ?? 0;
2080
+ if (maxFrac === null) return min === 0 ? null : "." + "0".repeat(min) + "*";
2081
+ if (maxFrac < min) throw invalid("maximumFractionDigits is below minimumFractionDigits");
2082
+ return "." + "0".repeat(min) + "#".repeat(maxFrac - min);
2083
+ }
2084
+ /** The precision stem with `trailingZeroDisplay` applied (`/w`). */
2085
+ function stripped(fraction, strip) {
2086
+ if (strip === void 0 || strip === "auto") return fraction;
2087
+ if (strip !== "stripIfInteger") throw new Unsupported(`trailingZeroDisplay=${strip} is not supported`);
2088
+ if (fraction === null || fraction.endsWith("*")) throw new Unsupported("trailingZeroDisplay=stripIfInteger needs both fraction digit counts");
2089
+ return fraction === "." ? fraction : fraction + "/w";
2090
+ }
2091
+ /** Minimum and maximum significant digits as a stem (`@@#`, `@+`). */
2092
+ function significantDigits(minSig, maxSig) {
2093
+ if (minSig === null && maxSig === null) return null;
2094
+ const min = minSig ?? 1;
2095
+ if (min < 1) throw invalid("minimumSignificantDigits must be at least 1");
2096
+ if (maxSig === null) return "@".repeat(min) + "+";
2097
+ if (maxSig < min) throw invalid("maximumSignificantDigits is below minimumSignificantDigits");
2098
+ return "@".repeat(min) + "#".repeat(maxSig - min);
2099
+ }
2100
+ /** The significant-digits stem with `roundingPriority` applied (`r`, `s`). */
2101
+ function prioritised(significant, priority) {
2102
+ if (priority === void 0 || priority === "auto") return significant;
2103
+ if (significant === null || priority !== "morePrecision" && priority !== "lessPrecision") throw new Unsupported(`roundingPriority=${priority} needs significant digits set here`);
2104
+ return significant + (priority === "morePrecision" ? "r" : "s");
2105
+ }
2106
+ /** Stems for the sign, grouping, currency display and rounding options. */
2107
+ function optionStems(o) {
2108
+ const stems = [];
2046
2109
  const currencySign = o.get("currencySign");
2047
- if (currencySign === "accounting") tokens.push("sign-accounting");
2110
+ if (currencySign === "accounting") stems.push("sign-accounting");
2048
2111
  else if (currencySign !== void 0 && currencySign !== "standard") throw new Unsupported(`currencySign=${currencySign} is not supported`);
2049
- const sign = o.get("signDisplay");
2050
- if (sign !== void 0 && sign !== "auto") {
2051
- const stem = Object.hasOwn(SIGN, sign) ? SIGN[sign] : void 0;
2052
- if (stem === void 0) throw new Unsupported(`signDisplay=${sign} is not supported`);
2053
- tokens.push(stem);
2054
- }
2112
+ const sign = tableStem(SIGN, o, "signDisplay", "auto");
2113
+ if (sign !== null) stems.push(sign);
2055
2114
  const grouping = o.get("useGrouping");
2056
- if (grouping === "never" || grouping === "false") tokens.push("group-off");
2115
+ if (grouping === "never" || grouping === "false") stems.push("group-off");
2057
2116
  else if (grouping !== void 0 && grouping !== "auto") throw new Unsupported(`useGrouping=${grouping} is not supported`);
2058
- const display = o.get("currencyDisplay");
2059
- if (display !== void 0 && display !== "symbol") {
2060
- const stem = Object.hasOwn(CURRENCY_DISPLAY, display) ? CURRENCY_DISPLAY[display] : void 0;
2061
- if (stem === void 0) throw new Unsupported(`currencyDisplay=${display} is not supported`);
2062
- tokens.push(stem);
2063
- }
2117
+ const display = tableStem(CURRENCY_DISPLAY, o, "currencyDisplay", "symbol");
2118
+ if (display !== null) stems.push(display);
2064
2119
  const increment = o.get("roundingIncrement");
2065
2120
  if (increment !== void 0 && increment !== "1") throw new Unsupported(`roundingIncrement=${increment} is not supported`);
2066
- const mode = o.get("roundingMode");
2067
- if (mode !== void 0 && mode !== "halfExpand") {
2068
- const stem = Object.hasOwn(ROUNDING, mode) ? ROUNDING[mode] : void 0;
2069
- if (stem === void 0) throw new Unsupported(`roundingMode=${mode} is not supported`);
2070
- tokens.push(stem);
2071
- }
2072
- const select = o.get("select");
2073
- if (select !== void 0 && select !== "plural" && select !== "ordinal" && select !== "exact") throw invalid(`select=${select}: use plural, ordinal or exact`);
2074
- if (tokens.length === 0) return null;
2075
- if (tokens.length === 1 && (tokens[0] === "." || tokens[0] === "percent")) return tokens[0] === "." ? "integer" : "percent";
2076
- return "::" + tokens.join(" ");
2121
+ const mode = tableStem(ROUNDING, o, "roundingMode", "halfExpand");
2122
+ if (mode !== null) stems.push(mode);
2123
+ return stems;
2124
+ }
2125
+ /** The stem `table` gives option `key`'s value; null for its default. */
2126
+ function tableStem(table, o, key, fallback) {
2127
+ const value = o.get(key);
2128
+ if (value === void 0 || value === fallback) return null;
2129
+ const stem = Object.hasOwn(table, value) ? table[value] : void 0;
2130
+ if (stem === void 0) throw new Unsupported(`${key}=${value} is not supported`);
2131
+ return stem;
2077
2132
  }
2133
+ /** The skeleton fields of each `fields` value, one symbol each: `M` and `E` take their width from `length`. */
2078
2134
  const DATE_FIELDS = {
2079
- weekday: ["E"],
2080
- "day-weekday": ["d", "E"],
2081
- "month-day": ["M", "d"],
2082
- "month-day-weekday": [
2083
- "M",
2084
- "d",
2085
- "E"
2086
- ],
2087
- "year-month-day": [
2088
- "y",
2089
- "M",
2090
- "d"
2091
- ],
2092
- "year-month-day-weekday": [
2093
- "y",
2094
- "M",
2095
- "d",
2096
- "E"
2135
+ weekday: "E",
2136
+ "day-weekday": "dE",
2137
+ "month-day": "Md",
2138
+ "month-day-weekday": "MdE",
2139
+ "year-month-day": "yMd",
2140
+ "year-month-day-weekday": "yMdE"
2141
+ };
2142
+ /** The options of `:date`, `:time` and `:datetime` vi18n supports. */
2143
+ const DATE_OPTIONS = {
2144
+ date: ["fields", "length"],
2145
+ time: ["precision", "timeZoneStyle"],
2146
+ datetime: [
2147
+ "dateFields",
2148
+ "dateLength",
2149
+ "timePrecision",
2150
+ "timeZoneStyle"
2097
2151
  ]
2098
2152
  };
2099
2153
  const MONTH = {
@@ -2117,12 +2171,7 @@ const ZONE = {
2117
2171
  */
2118
2172
  function dateStyle(fn) {
2119
2173
  const o = fn.options;
2120
- const known = fn.name === "date" ? ["fields", "length"] : fn.name === "time" ? ["precision", "timeZoneStyle"] : [
2121
- "dateFields",
2122
- "dateLength",
2123
- "timePrecision",
2124
- "timeZoneStyle"
2125
- ];
2174
+ const known = DATE_OPTIONS[fn.name] ?? [];
2126
2175
  for (const key of o.keys()) if (!known.includes(key)) throw new Unsupported(`:${fn.name} has no option ${key} vi18n supports (Draft options and overrides are not)`);
2127
2176
  const pick = (table, key, value) => {
2128
2177
  if (!Object.hasOwn(table, value)) throw invalid(`${key}=${value} is not a value of ${key}`);
@@ -2133,7 +2182,8 @@ function dateStyle(fn) {
2133
2182
  const length = o.get(lengthKey) ?? "medium";
2134
2183
  const month = pick(MONTH, lengthKey, length);
2135
2184
  if (!Object.hasOwn(DATE_FIELDS, fields)) throw invalid(`${fieldsKey}=${fields} is not a value of ${fieldsKey}`);
2136
- return DATE_FIELDS[fields].map((field) => field === "M" ? month : field === "E" ? length === "long" ? "EEEE" : "EEE" : field).join("");
2185
+ const weekday = length === "long" ? "EEEE" : "EEE";
2186
+ return DATE_FIELDS[fields].replace("M", month).replace("E", weekday);
2137
2187
  };
2138
2188
  const time = (precisionKey) => {
2139
2189
  const zone = o.get("timeZoneStyle");
@@ -2143,8 +2193,7 @@ function dateStyle(fn) {
2143
2193
  if (fn.name === "time") return ["time", "::" + time("precision")];
2144
2194
  return ["date", "::" + date("dateFields", "dateLength") + time("timePrecision")];
2145
2195
  }
2146
- //#endregion
2147
- //#region src/core/mf2/index.ts
2196
+ // src/core/mf2/index.ts
2148
2197
  /**
2149
2198
  * The message front ends (PLAN §4.2, INTERNALS §2.1.4): ICU MessageFormat 1,
2150
2199
  * and MessageFormat 2 lowered into the same ICU AST. `parseSource` is what
@@ -2174,7 +2223,7 @@ function bodyStart(source) {
2174
2223
  let i = 0;
2175
2224
  for (; i < source.length; i++) {
2176
2225
  const c = source.charCodeAt(i);
2177
- if (!(c === 32 || c === 9 || c === 10 || c === 13 || c === 12288) && !(c === 1564 || c === 8206 || c === 8207 || c >= 8294 && c <= 8297)) break;
2226
+ if (!isWs(c) && !isBidi(c)) break;
2178
2227
  }
2179
2228
  return i;
2180
2229
  }
@@ -2207,8 +2256,7 @@ function hinted(error, hint) {
2207
2256
  message: `${diagnostic.message} (${hint})`
2208
2257
  });
2209
2258
  }
2210
- //#endregion
2211
- //#region src/core/icu/print.ts
2259
+ // src/core/icu/print.ts
2212
2260
  const HASH = 35;
2213
2261
  const APOS = 39;
2214
2262
  const SLASH = 47;
@@ -2334,8 +2382,7 @@ function isSpecial(value, i, c, poundSensitive) {
2334
2382
  }
2335
2383
  return false;
2336
2384
  }
2337
- //#endregion
2338
- //#region src/core/icu/canonical.ts
2385
+ // src/core/icu/canonical.ts
2339
2386
  /**
2340
2387
  * Source normalisation and the canonical form (INTERNALS §2.2.1): the text
2341
2388
  * that ids hash, catalogs store and translators read.
@@ -2368,8 +2415,7 @@ function isPlainText(text) {
2368
2415
  }
2369
2416
  return true;
2370
2417
  }
2371
- //#endregion
2372
- //#region src/core/ir/compile.ts
2418
+ // src/core/ir/compile.ts
2373
2419
  /**
2374
2420
  * Compiles a parsed ICU message to the JSON IR the runtime interprets
2375
2421
  * (INTERNALS §2.3, PLAN §5.9).
@@ -2418,7 +2464,7 @@ function compileNode(node) {
2418
2464
  case "number":
2419
2465
  case "date":
2420
2466
  case "time": {
2421
- const op = node.type === "number" ? OP.number : node.type === "date" ? OP.date : OP.time;
2467
+ const op = OP[node.type];
2422
2468
  const options = copyOptions(node.options);
2423
2469
  return options === null ? [node.name, op] : [
2424
2470
  node.name,
@@ -2498,5 +2544,4 @@ function copyOptions(options) {
2498
2544
  }
2499
2545
  return copy;
2500
2546
  }
2501
- //#endregion
2502
2547
  export { printICU as a, parseICU as c, diagnosticError as d, isDiagnosticError as f, normalizeSource as i, positionAt as l, canonicalize as n, isMF2Form as o, isPlainText as r, parseSource as s, compileMessage as t, quoteStarts as u };