@astl/core 0.0.0 → 0.1.1

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 (139) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +202 -0
  3. package/README.md +38 -0
  4. package/dist/answers.d.ts +29 -0
  5. package/dist/answers.d.ts.map +1 -0
  6. package/dist/answers.js +40 -0
  7. package/dist/answers.js.map +1 -0
  8. package/dist/ast.d.ts +25 -0
  9. package/dist/ast.d.ts.map +1 -0
  10. package/dist/ast.js +27 -0
  11. package/dist/ast.js.map +1 -0
  12. package/dist/authoring.d.ts +451 -0
  13. package/dist/authoring.d.ts.map +1 -0
  14. package/dist/authoring.js +2 -0
  15. package/dist/authoring.js.map +1 -0
  16. package/dist/checker.d.ts +78 -0
  17. package/dist/checker.d.ts.map +1 -0
  18. package/dist/checker.js +10 -0
  19. package/dist/checker.js.map +1 -0
  20. package/dist/compiled.d.ts +94 -0
  21. package/dist/compiled.d.ts.map +1 -0
  22. package/dist/compiled.js +16 -0
  23. package/dist/compiled.js.map +1 -0
  24. package/dist/content.d.ts +72 -0
  25. package/dist/content.d.ts.map +1 -0
  26. package/dist/content.js +128 -0
  27. package/dist/content.js.map +1 -0
  28. package/dist/declarations.d.ts +52 -0
  29. package/dist/declarations.d.ts.map +1 -0
  30. package/dist/declarations.js +358 -0
  31. package/dist/declarations.js.map +1 -0
  32. package/dist/definition.d.ts +106 -0
  33. package/dist/definition.d.ts.map +1 -0
  34. package/dist/definition.js +2 -0
  35. package/dist/definition.js.map +1 -0
  36. package/dist/engine.d.ts +95 -0
  37. package/dist/engine.d.ts.map +1 -0
  38. package/dist/engine.js +2 -0
  39. package/dist/engine.js.map +1 -0
  40. package/dist/format.d.ts +29 -0
  41. package/dist/format.d.ts.map +1 -0
  42. package/dist/format.js +55 -0
  43. package/dist/format.js.map +1 -0
  44. package/dist/help.d.ts +38 -0
  45. package/dist/help.d.ts.map +1 -0
  46. package/dist/help.js +22 -0
  47. package/dist/help.js.map +1 -0
  48. package/dist/i18n/check.d.ts +11 -0
  49. package/dist/i18n/check.d.ts.map +1 -0
  50. package/dist/i18n/check.js +64 -0
  51. package/dist/i18n/check.js.map +1 -0
  52. package/dist/i18n/format.d.ts +40 -0
  53. package/dist/i18n/format.d.ts.map +1 -0
  54. package/dist/i18n/format.js +280 -0
  55. package/dist/i18n/format.js.map +1 -0
  56. package/dist/i18n/i18n.d.ts +14 -0
  57. package/dist/i18n/i18n.d.ts.map +1 -0
  58. package/dist/i18n/i18n.js +82 -0
  59. package/dist/i18n/i18n.js.map +1 -0
  60. package/dist/i18n/types.d.ts +31 -0
  61. package/dist/i18n/types.d.ts.map +1 -0
  62. package/dist/i18n/types.js +7 -0
  63. package/dist/i18n/types.js.map +1 -0
  64. package/dist/index.d.ts +45 -0
  65. package/dist/index.d.ts.map +1 -0
  66. package/dist/index.js +21 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/issues.d.ts +98 -0
  69. package/dist/issues.d.ts.map +1 -0
  70. package/dist/issues.js +74 -0
  71. package/dist/issues.js.map +1 -0
  72. package/dist/json.d.ts +7 -0
  73. package/dist/json.d.ts.map +1 -0
  74. package/dist/json.js +2 -0
  75. package/dist/json.js.map +1 -0
  76. package/dist/manifest.d.ts +135 -0
  77. package/dist/manifest.d.ts.map +1 -0
  78. package/dist/manifest.js +63 -0
  79. package/dist/manifest.js.map +1 -0
  80. package/dist/player.d.ts +129 -0
  81. package/dist/player.d.ts.map +1 -0
  82. package/dist/player.js +18 -0
  83. package/dist/player.js.map +1 -0
  84. package/dist/policy.d.ts +53 -0
  85. package/dist/policy.d.ts.map +1 -0
  86. package/dist/policy.js +55 -0
  87. package/dist/policy.js.map +1 -0
  88. package/dist/protocol.d.ts +54 -0
  89. package/dist/protocol.d.ts.map +1 -0
  90. package/dist/protocol.js +51 -0
  91. package/dist/protocol.js.map +1 -0
  92. package/dist/result.d.ts +44 -0
  93. package/dist/result.d.ts.map +1 -0
  94. package/dist/result.js +5 -0
  95. package/dist/result.js.map +1 -0
  96. package/dist/scoring.d.ts +27 -0
  97. package/dist/scoring.d.ts.map +1 -0
  98. package/dist/scoring.js +6 -0
  99. package/dist/scoring.js.map +1 -0
  100. package/dist/slots.d.ts +47 -0
  101. package/dist/slots.d.ts.map +1 -0
  102. package/dist/slots.js +9 -0
  103. package/dist/slots.js.map +1 -0
  104. package/dist/snapshot.d.ts +23 -0
  105. package/dist/snapshot.d.ts.map +1 -0
  106. package/dist/snapshot.js +22 -0
  107. package/dist/snapshot.js.map +1 -0
  108. package/dist/style.d.ts +51 -0
  109. package/dist/style.d.ts.map +1 -0
  110. package/dist/style.js +36 -0
  111. package/dist/style.js.map +1 -0
  112. package/package.json +52 -4
  113. package/src/answers.ts +52 -0
  114. package/src/ast.ts +49 -0
  115. package/src/authoring.ts +475 -0
  116. package/src/checker.ts +91 -0
  117. package/src/compiled.ts +115 -0
  118. package/src/content.ts +156 -0
  119. package/src/declarations.ts +427 -0
  120. package/src/definition.ts +104 -0
  121. package/src/engine.ts +98 -0
  122. package/src/format.ts +67 -0
  123. package/src/help.ts +41 -0
  124. package/src/i18n/check.ts +67 -0
  125. package/src/i18n/format.ts +318 -0
  126. package/src/i18n/i18n.ts +92 -0
  127. package/src/i18n/types.ts +35 -0
  128. package/src/index.ts +201 -0
  129. package/src/issues.ts +107 -0
  130. package/src/json.ts +6 -0
  131. package/src/manifest.ts +193 -0
  132. package/src/player.ts +145 -0
  133. package/src/policy.ts +117 -0
  134. package/src/protocol.ts +65 -0
  135. package/src/result.ts +53 -0
  136. package/src/scoring.ts +31 -0
  137. package/src/slots.ts +57 -0
  138. package/src/snapshot.ts +40 -0
  139. package/src/style.ts +89 -0
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Content format constants and the id grammar.
3
+ *
4
+ * Source: `<astl-doc format="1" lang="pl">` with `<astl-page>` children (or loose content = one implicit page).
5
+ * Source ids are written by authors and editors; opaque ids are written by the compiler into views.
6
+ */
7
+ /** Current content format. Written as `format="1"` on `<astl-doc>` in sources and views. */
8
+ export declare const FORMAT_VERSION = 1;
9
+ export declare const SUPPORTED_FORMATS: readonly number[];
10
+ export declare const DOC_TAG = "astl-doc";
11
+ export declare const PAGE_TAG = "astl-page";
12
+ /** Largest accepted source, in UTF-16 code units. */
13
+ export declare const MAX_SOURCE_LENGTH = 1000000;
14
+ /** Author ids: a letter, then letters, digits, `_` or `-`; at most 64 characters. Unique within one document. */
15
+ export declare const SOURCE_ID_PATTERN: RegExp;
16
+ /** Opaque ids in views: `k` + 16 lowercase base32 characters (80 bits of an HMAC-SHA-256). */
17
+ export declare const OPAQUE_ID_PATTERN: RegExp;
18
+ /** Custom element names that components may use (HTML custom element rules, lowercase ASCII). */
19
+ export declare const ELEMENT_TAG_PATTERN: RegExp;
20
+ /** Prefix reserved for built-in Astrolabe elements. */
21
+ export declare const BUILT_IN_PREFIX = "astl-";
22
+ export declare function isSourceId(value: string): boolean;
23
+ export declare function isOpaqueId(value: string): boolean;
24
+ export type Direction = 'ltr' | 'rtl';
25
+ /** Writing direction for a BCP 47 tag, e.g. `he` -> `rtl`, `pl-PL` -> `ltr`. Script subtags win (`az-Arab`). */
26
+ export declare function directionOf(lang: string): Direction;
27
+ /** Loose BCP 47 check: `pl`, `pl-PL`, `zh-Hant-TW`, `sr-Latn`. */
28
+ export declare const LANGUAGE_TAG_PATTERN: RegExp;
29
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,4FAA4F;AAC5F,eAAO,MAAM,cAAc,IAAI,CAAC;AAChC,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAAQ,CAAC;AAExD,eAAO,MAAM,OAAO,aAAa,CAAC;AAClC,eAAO,MAAM,QAAQ,cAAc,CAAC;AAEpC,qDAAqD;AACrD,eAAO,MAAM,iBAAiB,UAAY,CAAC;AAE3C,iHAAiH;AACjH,eAAO,MAAM,iBAAiB,EAAE,MAAwC,CAAC;AAEzE,8FAA8F;AAC9F,eAAO,MAAM,iBAAiB,EAAE,MAA0B,CAAC;AAE3D,iGAAiG;AACjG,eAAO,MAAM,mBAAmB,EAAE,MAAsC,CAAC;AAEzE,uDAAuD;AACvD,eAAO,MAAM,eAAe,UAAU,CAAC;AAEvC,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,CAAC;AAmBtC,gHAAgH;AAChH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAMnD;AAED,kEAAkE;AAClE,eAAO,MAAM,oBAAoB,EAAE,MAA8C,CAAC"}
package/dist/format.js ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Content format constants and the id grammar.
3
+ *
4
+ * Source: `<astl-doc format="1" lang="pl">` with `<astl-page>` children (or loose content = one implicit page).
5
+ * Source ids are written by authors and editors; opaque ids are written by the compiler into views.
6
+ */
7
+ /** Current content format. Written as `format="1"` on `<astl-doc>` in sources and views. */
8
+ export const FORMAT_VERSION = 1;
9
+ export const SUPPORTED_FORMATS = [1];
10
+ export const DOC_TAG = 'astl-doc';
11
+ export const PAGE_TAG = 'astl-page';
12
+ /** Largest accepted source, in UTF-16 code units. */
13
+ export const MAX_SOURCE_LENGTH = 1_000_000;
14
+ /** Author ids: a letter, then letters, digits, `_` or `-`; at most 64 characters. Unique within one document. */
15
+ export const SOURCE_ID_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
16
+ /** Opaque ids in views: `k` + 16 lowercase base32 characters (80 bits of an HMAC-SHA-256). */
17
+ export const OPAQUE_ID_PATTERN = /^k[a-z2-7]{16}$/;
18
+ /** Custom element names that components may use (HTML custom element rules, lowercase ASCII). */
19
+ export const ELEMENT_TAG_PATTERN = /^[a-z][a-z0-9]*-[a-z0-9-]*$/;
20
+ /** Prefix reserved for built-in Astrolabe elements. */
21
+ export const BUILT_IN_PREFIX = 'astl-';
22
+ export function isSourceId(value) {
23
+ return SOURCE_ID_PATTERN.test(value);
24
+ }
25
+ export function isOpaqueId(value) {
26
+ return OPAQUE_ID_PATTERN.test(value);
27
+ }
28
+ /** Scripts written right to left, by BCP 47 primary language subtag (enough for the markets we target). */
29
+ const RTL_LANGUAGES = new Set([
30
+ 'ar',
31
+ 'arc',
32
+ 'ckb',
33
+ 'dv',
34
+ 'fa',
35
+ 'he',
36
+ 'ks',
37
+ 'ku',
38
+ 'ps',
39
+ 'sd',
40
+ 'ug',
41
+ 'ur',
42
+ 'yi',
43
+ ]);
44
+ /** Writing direction for a BCP 47 tag, e.g. `he` -> `rtl`, `pl-PL` -> `ltr`. Script subtags win (`az-Arab`). */
45
+ export function directionOf(lang) {
46
+ const parts = lang.toLowerCase().split('-');
47
+ if (parts.includes('arab') || parts.includes('hebr') || parts.includes('thaa') || parts.includes('syrc'))
48
+ return 'rtl';
49
+ if (parts.includes('latn') || parts.includes('cyrl'))
50
+ return 'ltr';
51
+ return RTL_LANGUAGES.has(parts[0] ?? '') ? 'rtl' : 'ltr';
52
+ }
53
+ /** Loose BCP 47 check: `pl`, `pl-PL`, `zh-Hant-TW`, `sr-Latn`. */
54
+ export const LANGUAGE_TAG_PATTERN = /^[a-zA-Z]{2,3}(-[a-zA-Z0-9]{2,8})*$/;
55
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,4FAA4F;AAC5F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAChC,MAAM,CAAC,MAAM,iBAAiB,GAAsB,CAAC,CAAC,CAAC,CAAC;AAExD,MAAM,CAAC,MAAM,OAAO,GAAG,UAA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CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IACnE,OAAO,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AAC3D,CAAC;AAED,kEAAkE;AAClE,MAAM,CAAC,MAAM,oBAAoB,GAAW,qCAAqC,CAAC"}
package/dist/help.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Help for students (content format 1, additive): hints, an explanation and feedback texts. Inside a graded component
3
+ * they belong to that interaction; directly on a page, to the page. They usually give the answer away, so they are
4
+ * key-side data: compile moves their content into the answer key (`AnswerKey.help`), and the view keeps only what a
5
+ * player needs to offer them (`ElementHelp`, written as the attributes `HELP_ATTRIBUTES`).
6
+ */
7
+ /** One hint, rich content; hints come in source order. `cost`: the fraction 0..1 of the points it takes off. */
8
+ export declare const HINT_TAG = "astl-hint";
9
+ /** Why the answer is what it is; at most one per interaction or page. */
10
+ export declare const EXPLANATION_TAG = "astl-explanation";
11
+ /** The text for one verdict, picked by `when`; at most one per `when`. */
12
+ export declare const FEEDBACK_TAG = "astl-feedback";
13
+ export declare const HELP_TAGS: ReadonlySet<string>;
14
+ /** The `when` of a feedback text: one per group verdict, `omitted` for `empty`. */
15
+ export type FeedbackVariant = 'correct' | 'incorrect' | 'partial' | 'omitted';
16
+ export declare const FEEDBACK_VARIANTS: readonly FeedbackVariant[];
17
+ /** What a view says about the help of an interaction or a page, so a player can offer it: never its text. */
18
+ export interface ElementHelp {
19
+ /** The cost of each hint, in order (0: free). */
20
+ readonly hints: readonly number[];
21
+ readonly explanation: boolean;
22
+ /** The variants with a text, in `FEEDBACK_VARIANTS` order. */
23
+ readonly feedback: readonly FeedbackVariant[];
24
+ }
25
+ /**
26
+ * The view attributes of `ElementHelp`, on a graded component or a page: `hints="0 0.25"` (the costs, space
27
+ * separated), `explanation` (present when there is one) and `feedback="correct incorrect"` (the variants with a text,
28
+ * in `FEEDBACK_VARIANTS` order). Only those with something to say are written; sources never carry them. The engine
29
+ * writes them (compile), the player reads them.
30
+ */
31
+ export declare const HELP_ATTRIBUTES: readonly string[];
32
+ /** A feedback text as a student gets it: the variant of the verdict and the author's text (HTML of format 1). */
33
+ export interface Feedback {
34
+ /** The verdict's variant; its text is the `incorrect` one when a partial verdict has none of its own. */
35
+ readonly variant: FeedbackVariant;
36
+ readonly html: string;
37
+ }
38
+ //# sourceMappingURL=help.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,gHAAgH;AAChH,eAAO,MAAM,QAAQ,cAAc,CAAC;AACpC,yEAAyE;AACzE,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,0EAA0E;AAC1E,eAAO,MAAM,YAAY,kBAAkB,CAAC;AAC5C,eAAO,MAAM,SAAS,EAAE,WAAW,CAAC,MAAM,CAAsD,CAAC;AAEjG,mFAAmF;AACnF,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,CAAC;AAC9E,eAAO,MAAM,iBAAiB,EAAE,SAAS,eAAe,EAAmD,CAAC;AAE5G,6GAA6G;AAC7G,MAAM,WAAW,WAAW;IAC1B,iDAAiD;IACjD,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,CAAC;CAC/C;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAAyC,CAAC;AAEvF,iHAAiH;AACjH,MAAM,WAAW,QAAQ;IACvB,yGAAyG;IACzG,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
package/dist/help.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Help for students (content format 1, additive): hints, an explanation and feedback texts. Inside a graded component
3
+ * they belong to that interaction; directly on a page, to the page. They usually give the answer away, so they are
4
+ * key-side data: compile moves their content into the answer key (`AnswerKey.help`), and the view keeps only what a
5
+ * player needs to offer them (`ElementHelp`, written as the attributes `HELP_ATTRIBUTES`).
6
+ */
7
+ /** One hint, rich content; hints come in source order. `cost`: the fraction 0..1 of the points it takes off. */
8
+ export const HINT_TAG = 'astl-hint';
9
+ /** Why the answer is what it is; at most one per interaction or page. */
10
+ export const EXPLANATION_TAG = 'astl-explanation';
11
+ /** The text for one verdict, picked by `when`; at most one per `when`. */
12
+ export const FEEDBACK_TAG = 'astl-feedback';
13
+ export const HELP_TAGS = new Set([HINT_TAG, EXPLANATION_TAG, FEEDBACK_TAG]);
14
+ export const FEEDBACK_VARIANTS = ['correct', 'incorrect', 'partial', 'omitted'];
15
+ /**
16
+ * The view attributes of `ElementHelp`, on a graded component or a page: `hints="0 0.25"` (the costs, space
17
+ * separated), `explanation` (present when there is one) and `feedback="correct incorrect"` (the variants with a text,
18
+ * in `FEEDBACK_VARIANTS` order). Only those with something to say are written; sources never carry them. The engine
19
+ * writes them (compile), the player reads them.
20
+ */
21
+ export const HELP_ATTRIBUTES = ['hints', 'explanation', 'feedback'];
22
+ //# sourceMappingURL=help.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.js","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,gHAAgH;AAChH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;AACpC,yEAAyE;AACzE,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAClD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,YAAY,GAAG,eAAe,CAAC;AAC5C,MAAM,CAAC,MAAM,SAAS,GAAwB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC,CAAC;AAIjG,MAAM,CAAC,MAAM,iBAAiB,GAA+B,CAAC,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAW5G;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAsB,CAAC,OAAO,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { MessageCatalog } from './types.js';
2
+ export interface CatalogProblem {
3
+ readonly key: string;
4
+ readonly kind: 'missing' | 'extra' | 'syntax' | 'params' | 'plural';
5
+ readonly detail: string;
6
+ }
7
+ /** Problems of `catalog` alone (syntax and plural coverage). */
8
+ export declare function checkCatalog(catalog: MessageCatalog): CatalogProblem[];
9
+ /** Problems of a translation compared with its source catalog (same namespace). */
10
+ export declare function compareCatalogs(source: MessageCatalog, translation: MessageCatalog): CatalogProblem[];
11
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/i18n/check.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACpE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAkBD,gEAAgE;AAChE,wBAAgB,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,CAYtE;AAED,mFAAmF;AACnF,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,GAAG,cAAc,EAAE,CAqBrG"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Catalog checks for CI: every translation has the same keys and parameters as the source catalog, parses, and
3
+ * covers every plural category its locale needs (Polish: one, few, many, other).
4
+ */
5
+ import { messageParams, parseMessage, pluralCategories } from './format.js';
6
+ function pluralProblems(parts, locale) {
7
+ const out = [];
8
+ const walk = (list) => {
9
+ for (const p of list) {
10
+ if (p.type === 'plural') {
11
+ const needed = pluralCategories(locale, p.ordinal);
12
+ const missing = needed.filter((c) => !Object.hasOwn(p.options, c));
13
+ if (missing.length > 0)
14
+ out.push(`{${p.name}} lacks ${missing.join(', ')}`);
15
+ }
16
+ if (p.type === 'plural' || p.type === 'select')
17
+ for (const sub of Object.values(p.options))
18
+ walk(sub);
19
+ }
20
+ };
21
+ walk(parts);
22
+ return out;
23
+ }
24
+ /** Problems of `catalog` alone (syntax and plural coverage). */
25
+ export function checkCatalog(catalog) {
26
+ const problems = [];
27
+ for (const [key, message] of Object.entries(catalog.messages)) {
28
+ try {
29
+ const parts = parseMessage(message);
30
+ for (const detail of pluralProblems(parts, catalog.locale))
31
+ problems.push({ key, kind: 'plural', detail });
32
+ }
33
+ catch (e) {
34
+ problems.push({ key, kind: 'syntax', detail: e.message });
35
+ }
36
+ }
37
+ return problems;
38
+ }
39
+ /** Problems of a translation compared with its source catalog (same namespace). */
40
+ export function compareCatalogs(source, translation) {
41
+ const problems = checkCatalog(translation);
42
+ for (const [key, message] of Object.entries(source.messages)) {
43
+ const other = Object.hasOwn(translation.messages, key) ? translation.messages[key] : undefined;
44
+ if (other === undefined) {
45
+ problems.push({ key, kind: 'missing', detail: `missing in ${translation.locale}` });
46
+ continue;
47
+ }
48
+ try {
49
+ const want = [...messageParams(parseMessage(message))].sort().join(',');
50
+ const got = [...messageParams(parseMessage(other))].sort().join(',');
51
+ if (want !== got)
52
+ problems.push({ key, kind: 'params', detail: `expected {${want}}, got {${got}}` });
53
+ }
54
+ catch {
55
+ // Syntax problems are already reported by checkCatalog.
56
+ }
57
+ }
58
+ for (const key of Object.keys(translation.messages)) {
59
+ if (!Object.hasOwn(source.messages, key))
60
+ problems.push({ key, kind: 'extra', detail: `not in ${source.locale}` });
61
+ }
62
+ return problems;
63
+ }
64
+ //# sourceMappingURL=check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/i18n/check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAoB,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAS9F,SAAS,cAAc,CAAC,KAA6B,EAAE,MAAc;IACnE,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,MAAM,IAAI,GAAG,CAAC,IAA4B,EAAE,EAAE;QAC5C,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;YACrB,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACxB,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;gBACnD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;gBACnE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;oBAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,WAAW,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC9E,CAAC;YACD,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ;gBAAE,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;oBAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACxG,CAAC;IACH,CAAC,CAAC;IACF,IAAI,CAAC,KAAK,CAAC,CAAC;IACZ,OAAO,GAAG,CAAC;AACb,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,YAAY,CAAC,OAAuB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AC;QACD,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACxE,MAAM,GAAG,GAAG,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACrE,IAAI,IAAI,KAAK,GAAG;gBAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,IAAI,WAAW,GAAG,GAAG,EAAE,CAAC,CAAC;QACvG,CAAC;QAAC,MAAM,CAAC;YACP,wDAAwD;QAC1D,CAAC;IACH,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC;YACtC,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * A dependency-free ICU MessageFormat 1 subset: `{name}`, `{name, number[, integer|percent]}`,
3
+ * `{name, plural|selectordinal, [offset:n] =0 {..} one {..} few {..} many {..} other {..}}` with `#`,
4
+ * and `{name, select, a {..} other {..}}`, nested to any depth. Apostrophe quoting as in ICU
5
+ * (`''` is a literal apostrophe, `'{'` quotes syntax characters). Dates and times are not supported on purpose:
6
+ * hosts format them and pass strings.
7
+ */
8
+ import type { MessageFormatter } from './types.js';
9
+ export type MessagePart = {
10
+ readonly type: 'text';
11
+ readonly value: string;
12
+ } | {
13
+ readonly type: 'arg';
14
+ readonly name: string;
15
+ readonly style: 'plain' | 'number' | 'integer' | 'percent';
16
+ } | {
17
+ readonly type: 'plural';
18
+ readonly name: string;
19
+ readonly ordinal: boolean;
20
+ readonly offset: number;
21
+ readonly options: Readonly<Record<string, readonly MessagePart[]>>;
22
+ } | {
23
+ readonly type: 'select';
24
+ readonly name: string;
25
+ readonly options: Readonly<Record<string, readonly MessagePart[]>>;
26
+ } | {
27
+ readonly type: 'pound';
28
+ };
29
+ export declare class MessageSyntaxError extends Error {
30
+ readonly offset: number;
31
+ constructor(message: string, offset: number);
32
+ }
33
+ export declare function parseMessage(message: string): MessagePart[];
34
+ /** Names of all arguments a message uses, including plural and select selectors. */
35
+ export declare function messageParams(parts: readonly MessagePart[]): Set<string>;
36
+ /** Plural categories a locale needs, e.g. `pl` -> one, few, many, other. */
37
+ export declare function pluralCategories(locale: string, ordinal?: boolean): readonly string[];
38
+ /** The default MessageFormatter. A message with a syntax error renders as its raw text instead of throwing. */
39
+ export declare const icuFormatter: MessageFormatter;
40
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/i18n/format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,YAAY,CAAC;AAElE,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjD;IACE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;CAC5D,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC,CAAC,CAAC;CACpE,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC,CAAC,CAAC;CACpE,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAE/B,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAI1C;CACF;AAgKD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE,CAE3D;AAED,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAaxE;AAgFD,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,SAAS,MAAM,EAAE,CAEnF;AAID,+GAA+G;AAC/G,eAAO,MAAM,YAAY,EAAE,gBAa1B,CAAC"}
@@ -0,0 +1,280 @@
1
+ export class MessageSyntaxError extends Error {
2
+ offset;
3
+ constructor(message, offset) {
4
+ super(`${message} at offset ${offset}`);
5
+ this.name = 'MessageSyntaxError';
6
+ this.offset = offset;
7
+ }
8
+ }
9
+ const PLURAL_KEYWORDS = new Set(['zero', 'one', 'two', 'few', 'many', 'other']);
10
+ class Parser {
11
+ src;
12
+ pos = 0;
13
+ constructor(src) {
14
+ this.src = src;
15
+ }
16
+ parse() {
17
+ const parts = this.message(false);
18
+ if (this.pos < this.src.length)
19
+ throw new MessageSyntaxError('Unexpected "}"', this.pos);
20
+ return parts;
21
+ }
22
+ /** Parses until an unmatched `}` (not consumed) or the end. */
23
+ message(inPlural) {
24
+ const parts = [];
25
+ let buf = '';
26
+ const flush = () => {
27
+ if (buf !== '')
28
+ parts.push({ type: 'text', value: buf });
29
+ buf = '';
30
+ };
31
+ while (this.pos < this.src.length) {
32
+ const ch = this.src[this.pos];
33
+ if (ch === "'") {
34
+ buf += this.apostrophe(inPlural);
35
+ }
36
+ else if (ch === '{') {
37
+ flush();
38
+ parts.push(this.argument());
39
+ }
40
+ else if (ch === '}') {
41
+ break;
42
+ }
43
+ else if (ch === '#' && inPlural) {
44
+ flush();
45
+ parts.push({ type: 'pound' });
46
+ this.pos++;
47
+ }
48
+ else {
49
+ buf += ch;
50
+ this.pos++;
51
+ }
52
+ }
53
+ flush();
54
+ return parts;
55
+ }
56
+ apostrophe(inPlural) {
57
+ const next = this.src[this.pos + 1];
58
+ if (next === "'") {
59
+ this.pos += 2;
60
+ return "'";
61
+ }
62
+ if (next === '{' || next === '}' || (inPlural && next === '#')) {
63
+ // Quoted literal until the next lone apostrophe.
64
+ this.pos++;
65
+ let out = '';
66
+ while (this.pos < this.src.length) {
67
+ const ch = this.src[this.pos];
68
+ if (ch === "'") {
69
+ if (this.src[this.pos + 1] === "'") {
70
+ out += "'";
71
+ this.pos += 2;
72
+ continue;
73
+ }
74
+ this.pos++;
75
+ return out;
76
+ }
77
+ out += ch;
78
+ this.pos++;
79
+ }
80
+ return out;
81
+ }
82
+ this.pos++;
83
+ return "'";
84
+ }
85
+ argument() {
86
+ const start = this.pos;
87
+ this.pos++; // {
88
+ const name = this.word();
89
+ if (name === '')
90
+ throw new MessageSyntaxError('Missing argument name', this.pos);
91
+ this.space();
92
+ if (this.eat('}'))
93
+ return { type: 'arg', name, style: 'plain' };
94
+ if (!this.eat(','))
95
+ throw new MessageSyntaxError('Expected "," or "}"', this.pos);
96
+ this.space();
97
+ const kind = this.word();
98
+ this.space();
99
+ if (kind === 'number') {
100
+ let style = 'number';
101
+ if (this.eat(',')) {
102
+ this.space();
103
+ const s = this.word();
104
+ if (s !== 'integer' && s !== 'percent')
105
+ throw new MessageSyntaxError(`Unsupported number style "${s}"`, this.pos);
106
+ style = s;
107
+ this.space();
108
+ }
109
+ this.expect('}');
110
+ return { type: 'arg', name, style };
111
+ }
112
+ if (kind === 'plural' || kind === 'selectordinal' || kind === 'select') {
113
+ this.expect(',');
114
+ this.space();
115
+ let offset = 0;
116
+ if (kind !== 'select' && this.src.startsWith('offset:', this.pos)) {
117
+ this.pos += 'offset:'.length;
118
+ this.space();
119
+ const n = this.word();
120
+ offset = Number(n);
121
+ if (!Number.isInteger(offset) || offset < 0)
122
+ throw new MessageSyntaxError(`Invalid offset "${n}"`, this.pos);
123
+ this.space();
124
+ }
125
+ // Null prototype: option keys like `__proto__` or `constructor` stay plain data.
126
+ const options = Object.create(null);
127
+ while (!this.eat('}')) {
128
+ if (this.pos >= this.src.length)
129
+ throw new MessageSyntaxError('Unclosed argument', start);
130
+ const key = this.word();
131
+ if (key === '')
132
+ throw new MessageSyntaxError('Expected an option key', this.pos);
133
+ if (kind !== 'select' && !PLURAL_KEYWORDS.has(key) && !/^=\d+$/.test(key)) {
134
+ throw new MessageSyntaxError(`Invalid plural key "${key}"`, this.pos);
135
+ }
136
+ if (Object.hasOwn(options, key))
137
+ throw new MessageSyntaxError(`Duplicate option "${key}"`, this.pos);
138
+ this.space();
139
+ this.expect('{');
140
+ options[key] = this.message(kind !== 'select');
141
+ this.expect('}');
142
+ this.space();
143
+ }
144
+ if (!Object.hasOwn(options, 'other'))
145
+ throw new MessageSyntaxError('Missing "other" option', start);
146
+ return kind === 'select'
147
+ ? { type: 'select', name, options }
148
+ : { type: 'plural', name, ordinal: kind === 'selectordinal', offset, options };
149
+ }
150
+ throw new MessageSyntaxError(`Unsupported argument type "${kind}"`, this.pos);
151
+ }
152
+ word() {
153
+ const m = /^[^\s{}#,'"]+/u.exec(this.src.slice(this.pos));
154
+ if (!m)
155
+ return '';
156
+ this.pos += m[0].length;
157
+ return m[0];
158
+ }
159
+ space() {
160
+ while (this.pos < this.src.length && /\s/u.test(this.src[this.pos]))
161
+ this.pos++;
162
+ }
163
+ eat(ch) {
164
+ if (this.src[this.pos] === ch) {
165
+ this.pos++;
166
+ return true;
167
+ }
168
+ return false;
169
+ }
170
+ expect(ch) {
171
+ if (!this.eat(ch))
172
+ throw new MessageSyntaxError(`Expected "${ch}"`, this.pos);
173
+ }
174
+ }
175
+ export function parseMessage(message) {
176
+ return new Parser(message).parse();
177
+ }
178
+ /** Names of all arguments a message uses, including plural and select selectors. */
179
+ export function messageParams(parts) {
180
+ const names = new Set();
181
+ const walk = (list) => {
182
+ for (const p of list) {
183
+ if (p.type === 'arg')
184
+ names.add(p.name);
185
+ if (p.type === 'plural' || p.type === 'select') {
186
+ names.add(p.name);
187
+ for (const sub of Object.values(p.options))
188
+ walk(sub);
189
+ }
190
+ }
191
+ };
192
+ walk(parts);
193
+ return names;
194
+ }
195
+ /** Own-property lookup: option keys such as `constructor` must never resolve to Object.prototype members. */
196
+ function option(options, key) {
197
+ return Object.hasOwn(options, key) ? options[key] : undefined;
198
+ }
199
+ function render(parts, params, locale, pound) {
200
+ let out = '';
201
+ for (const p of parts) {
202
+ switch (p.type) {
203
+ case 'text':
204
+ out += p.value;
205
+ break;
206
+ case 'pound':
207
+ out += pound ?? '#';
208
+ break;
209
+ case 'arg': {
210
+ const v = params[p.name];
211
+ if (v === undefined)
212
+ out += `{${p.name}}`;
213
+ else if (typeof v === 'number' || p.style !== 'plain')
214
+ out += formatNumber(Number(v), p.style, locale);
215
+ else
216
+ out += v;
217
+ break;
218
+ }
219
+ case 'select': {
220
+ const v = params[p.name];
221
+ const branch = (v !== undefined ? option(p.options, String(v)) : undefined) ?? option(p.options, 'other') ?? [];
222
+ out += render(branch, params, locale, pound);
223
+ break;
224
+ }
225
+ case 'plural': {
226
+ const n = Number(params[p.name]);
227
+ if (Number.isNaN(n)) {
228
+ out += render(option(p.options, 'other') ?? [], params, locale, `{${p.name}}`);
229
+ break;
230
+ }
231
+ const exact = option(p.options, `=${n}`);
232
+ const value = n - p.offset;
233
+ const category = pluralRules(locale, p.ordinal).select(value);
234
+ const branch = exact ?? option(p.options, category) ?? option(p.options, 'other') ?? [];
235
+ out += render(branch, params, locale, formatNumber(value, 'number', locale));
236
+ break;
237
+ }
238
+ }
239
+ }
240
+ return out;
241
+ }
242
+ const pluralCache = new Map();
243
+ function pluralRules(locale, ordinal) {
244
+ const id = `${locale}|${ordinal ? 'o' : 'c'}`;
245
+ let rules = pluralCache.get(id);
246
+ if (!rules) {
247
+ rules = new Intl.PluralRules(locale, { type: ordinal ? 'ordinal' : 'cardinal' });
248
+ pluralCache.set(id, rules);
249
+ }
250
+ return rules;
251
+ }
252
+ function formatNumber(value, style, locale) {
253
+ if (style === 'integer')
254
+ return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(value);
255
+ if (style === 'percent')
256
+ return new Intl.NumberFormat(locale, { style: 'percent' }).format(value);
257
+ return new Intl.NumberFormat(locale, { maximumFractionDigits: 2 }).format(value);
258
+ }
259
+ /** Plural categories a locale needs, e.g. `pl` -> one, few, many, other. */
260
+ export function pluralCategories(locale, ordinal = false) {
261
+ return pluralRules(locale, ordinal).resolvedOptions().pluralCategories;
262
+ }
263
+ const parsedCache = new Map();
264
+ /** The default MessageFormatter. A message with a syntax error renders as its raw text instead of throwing. */
265
+ export const icuFormatter = {
266
+ format(message, params, locale) {
267
+ let parts = parsedCache.get(message);
268
+ if (parts === undefined) {
269
+ try {
270
+ parts = parseMessage(message);
271
+ }
272
+ catch {
273
+ parts = null;
274
+ }
275
+ parsedCache.set(message, parts);
276
+ }
277
+ return parts === null ? message : render(parts, params, locale, null);
278
+ },
279
+ };
280
+ //# sourceMappingURL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EAAE,CAAC;YACxB,IAAI,CAAC;gBACH,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;YAChC,CAAC;YAAC,MAAM,CAAC;gBACP,KAAK,GAAG,IAAI,CAAC;YACf,CAAC;YACD,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAClC,CAAC;QACD,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACxE,CAAC;CACF,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { I18n, MessageCatalog, MessageFormatter } from './types.js';
2
+ /**
3
+ * BCP 47 lookup (RFC 4647 section 3.4, extended): for each requested tag try the tag, then shorter prefixes
4
+ * (`pl-PL` -> `pl`), then any available tag with the same language (`pt` -> `pt-BR`). Case-insensitive.
5
+ */
6
+ export declare function negotiateLocale(requested: readonly string[], available: readonly string[], fallback: string): string;
7
+ export interface CreateI18nOptions {
8
+ readonly catalogs: readonly MessageCatalog[];
9
+ /** Default `en`. */
10
+ readonly fallbackLocale?: string;
11
+ readonly formatter?: MessageFormatter;
12
+ }
13
+ export declare function createI18n(options: CreateI18nOptions): I18n;
14
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../src/i18n/i18n.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,gBAAgB,EAA4B,MAAM,YAAY,CAAC;AAEnG;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,QAAQ,EAAE,MAAM,GACf,MAAM,CAaR;AAUD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;IAC7C,oBAAoB;IACpB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;CACvC;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAkD3D"}