@pie-element/shared-controller-utils 0.1.5-next.20261110065815 → 0.1.5-next.20261110132055

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,7 +37,7 @@ const matches =
37
37
  normalizeResponse(authored, { language, ignoreCase: true });
38
38
  ```
39
39
 
40
- `ignoreCase` folds with `toLocaleLowerCase` in Turkish and Azerbaijani, so İ/ı fold correctly, and with `toLowerCase()` in every other language. A tag the runtime has no locale data for keeps `.` and `,`. `foldLetterVariants` folds Arabic hamza and madda alef forms, tashkeel, ة and ى; it changes what counts as correct spelling, so it stays an authoring choice per response. Math controllers call `normalizeResponse` without a language, so `٫` becomes the `.` math-validation computes on.
40
+ `ignoreCase` folds with `toLocaleLowerCase` in Turkish and Azerbaijani, so İ/ı fold correctly, and with `toLowerCase()` in every other language. A tag the runtime has no locale data for keeps `.` and `,`. `foldLetterVariants` folds Arabic hamza and madda alef forms, tashkeel, ة and ى; it changes what counts as correct spelling, so it stays an authoring choice per response. Math controllers pass `latexNumbers`, which writes numbers with the marks math-validation computes on: `٫` becomes `.` and `٬` becomes `,` in every language. Where the tag names a region that writes a decimal comma (`es-ES`, `de-DE`), a number's one `,` or `{,}` also becomes `.`, and `;` becomes `, ` between list items. A `.` stays a decimal point, a number with two marks such as `1.000,5` stays as typed, and a tag without a region keeps the point, because US Spanish content declares `es`. Which regions write a decimal comma comes from a fixed CLDR 48 table, so every runtime scores alike. Math controllers take the language from `mathContentLanguage`, which reads an underscore code such as `es_ES` as its language alone, because the authoring dropdown and the Learnosity transform write it for Spanish of any region. `contentLanguage` keeps its region. Both pass over a code that names no language, `und` or `zxx` among them, to `env.locale`.
41
41
 
42
42
  ## Development
43
43
 
@@ -0,0 +1,27 @@
1
+ This build contains code from the packages below, each followed by the license text and notices it ships.
2
+
3
+ ================================================================================
4
+ @pie-players/pie-language-tags@1.0.0-beta.9
5
+ License: MIT
6
+ --------------------------------------------------------------------------------
7
+ MIT License
8
+
9
+ Copyright (c) 2026 PIE Framework contributors
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -6,5 +6,5 @@
6
6
  */
7
7
  export { lockChoices, getShuffledChoices } from './persistence.js';
8
8
  export * as partialScoring from './partial-scoring.js';
9
- export { contentLanguage, foldCase, foldDigits, normalizeResponse } from './response-normalizer.js';
9
+ export { contentLanguage, foldCase, foldDigits, mathContentLanguage, normalizeResponse, } from './response-normalizer.js';
10
10
  export type { NormalizeOptions } from './response-normalizer.js';
package/dist/index.js CHANGED
@@ -47,22 +47,55 @@ var s = /* @__PURE__ */ t({ enabled: () => c });
47
47
  function c(e, t, n) {
48
48
  return e?.partialScoring === !1 || t?.partialScoring === !1 ? !1 : typeof n != "boolean" || n;
49
49
  }
50
+ // ../../../node_modules/.bun/@pie-players+pie-language-tags@1.0.0-beta.9/node_modules/@pie-players/pie-language-tags/dist/index.js
51
+ function l(e) {
52
+ return e ? e.trim().replace(/_/g, "-") : "";
53
+ }
54
+ function u(e) {
55
+ let t = l(e).split(/[.@]/)[0];
56
+ if (/^[a-z]{2,3}(-|$)/i.test(t)) try {
57
+ return Intl.getCanonicalLocales(t)[0];
58
+ } catch {
59
+ return;
60
+ }
61
+ }
50
62
  // src/response-normalizer.ts
51
- var l = /[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069\u0640]/g, u = /[\uFB50-\uFDFF\uFE70-\uFEFC]+/g, d = /\p{Nd}/u, f = /(?![0-9])\p{Nd}/gu, p = /\u066B/g, m = /\u066C/g, h = /[\u0622\u0623\u0625\u0671]/g, g = /[\u064B-\u065F\u0670]/g, _ = /* @__PURE__ */ new Map(), v = (e) => {
52
- let t = _.get(e);
63
+ var d = /[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069\u0640]/g, f = /[\uFB50-\uFDFF\uFE70-\uFEFC]+/g, p = /\p{Nd}/u, m = /(?![0-9])\p{Nd}/gu, h = /\u066B/g, g = /\u066C/g, _ = /[0-9]+(?:(?:[.,]|\{,\})[0-9]+)*(?:(?:,|\{,\})(?=\\overline))?/g, v = /[.,]|\{,\}/g, y = /(?<!\\|&(?:[a-zA-Z][a-zA-Z0-9]*|#[0-9]+|#[xX][0-9a-fA-F]+));/g, b = (e) => {
64
+ let t = e.match(v) ?? [];
65
+ return t.length === 1 && t[0] !== "." ? e.replace(v, ".") : e;
66
+ }, x = new Set("af az be bg br bs ca cs cv da de el eo es et eu ff fi fo fr fy gl hr hu hy ia id ie is it jv ka kk kl ku ky lb ln lo lt lu lv mk nb nl nn no oc os pl ps pt rm rn ro ru rw sc se sg sk sl sq sr su sv tg tk tr tt uk uz vi wo".split(" ")), S = {
67
+ ar: [
68
+ "DZ",
69
+ "LB",
70
+ "LY",
71
+ "MA",
72
+ "MR",
73
+ "TN"
74
+ ],
75
+ de: ["CH", "LI"],
76
+ en: "AT BE CZ DE DK EE ES FI FR GE HU ID IT LT LV NL NO PL PT RO SE SI SK UA ZA".split(" "),
77
+ es: "419 BR BZ CU DO GT HN MX NI PA PE PR SV US".split(" "),
78
+ it: ["CH"],
79
+ kk: ["CN"],
80
+ ku: ["IQ"],
81
+ ms: ["BN", "ID"],
82
+ qu: ["BO"],
83
+ sw: ["CD"]
84
+ }, C = /[\u0622\u0623\u0625\u0671]/g, w = /[\u064B-\u065F\u0670]/g, T = /* @__PURE__ */ new Map(), E = (e) => {
85
+ let t = T.get(e);
53
86
  if (t !== void 0) return t;
54
87
  let n = 0;
55
- for (; d.test(String.fromCodePoint(e - n - 1));) n++;
88
+ for (; p.test(String.fromCodePoint(e - n - 1));) n++;
56
89
  let r = n % 10;
57
- return _.set(e, r), r;
58
- }, y = (e) => e.replace(f, (e) => String(v(e.codePointAt(0)))), b = {
90
+ return T.set(e, r), r;
91
+ }, D = (e) => e.replace(m, (e) => String(E(e.codePointAt(0)))), O = {
59
92
  decimal: ".",
60
93
  group: ","
61
- }, x = /* @__PURE__ */ new Map(), S = (e) => {
62
- if (!e) return b;
63
- let t = x.get(e);
94
+ }, k = /* @__PURE__ */ new Map(), A = (e) => {
95
+ if (!e) return O;
96
+ let t = k.get(e);
64
97
  if (t) return t;
65
- let n = b;
98
+ let n = O;
66
99
  try {
67
100
  if (Intl.NumberFormat.supportedLocalesOf(e).length > 0) {
68
101
  let t = new Intl.NumberFormat(e, { numberingSystem: "latn" }).formatToParts(12345.6);
@@ -72,19 +105,38 @@ var l = /[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069\u0640]/g, u = /[\uFB50-\u
72
105
  };
73
106
  }
74
107
  } catch {}
75
- return x.set(e, n), n;
76
- }, C = (e, t) => {
77
- let n = [e?.language, t?.locale];
78
- for (let e of n) if (typeof e == "string" && e.trim()) return e.trim().replace(/_/g, "-");
79
- }, w = /^(tr|az)(-|$)/i, T = (e, t) => {
80
- if (!t || !w.test(t)) return e.toLowerCase();
108
+ return k.set(e, n), n;
109
+ }, j = (e) => {
110
+ if (!e) return !1;
111
+ try {
112
+ let { language: t, region: n } = new Intl.Locale(e);
113
+ return n ? x.has(t) !== (S[t]?.includes(n) ?? !1) : !1;
114
+ } catch {
115
+ return !1;
116
+ }
117
+ }, M = /* @__PURE__ */ new Set([
118
+ "und",
119
+ "zxx",
120
+ "mul",
121
+ "mis"
122
+ ]), N = (e) => {
123
+ let t = u(e);
124
+ return t && !M.has(t.split("-")[0]) ? t : void 0;
125
+ }, P = (e, t, n) => {
126
+ let r = [e?.language, t?.locale];
127
+ for (let e of r) {
128
+ let t = typeof e == "string" ? n(e) : void 0;
129
+ if (t) return t;
130
+ }
131
+ }, F = (e, t) => P(e, t, N), I = (e, t) => P(e, t, (e) => N(e.includes("_") ? e.slice(0, e.indexOf("_")) : e)), L = /^(tr|az)(-|$)/i, R = (e, t) => {
132
+ if (!t || !L.test(t)) return e.toLowerCase();
81
133
  try {
82
134
  return e.toLocaleLowerCase(t);
83
135
  } catch {
84
136
  return e.toLowerCase();
85
137
  }
86
- }, E = (e, t = {}) => {
87
- let n = S(t.language), r = (t.ignoreCase ? T(e, t.language) : e).replace(l, "").replace(u, (e) => e.normalize("NFKC")).normalize("NFC");
88
- return r = y(r).replace(p, n.decimal).replace(m, n.group), t.foldLetterVariants && (r = r.replace(g, "").replace(h, "ا").replace(/\u0629/g, "ه").replace(/\u0649/g, "ي")), t.ignoreAccents && (r = r.normalize("NFD").replace(/[\u0300-\u036F]/g, "").normalize("NFC")), t.collapseWhitespace && (r = r.replace(/\s+/g, " ").trim()), t.ignoreSlashSpacing && (r = r.replace(/\s*\/\s*/g, "/")), r;
138
+ }, z = (e, t = {}) => {
139
+ let n = t.latexNumbers ? O : A(t.language), r = (t.ignoreCase ? R(e, t.language) : e).replace(d, "").replace(f, (e) => e.normalize("NFKC")).normalize("NFC");
140
+ return r = D(r), t.latexNumbers && j(t.language) && (r = r.replace(_, b).replace(y, ", ")), r = r.replace(h, n.decimal).replace(g, n.group), t.foldLetterVariants && (r = r.replace(w, "").replace(C, "ا").replace(/\u0629/g, "ه").replace(/\u0649/g, "ي")), t.ignoreAccents && (r = r.normalize("NFD").replace(/[\u0300-\u036F]/g, "").normalize("NFC")), t.collapseWhitespace && (r = r.replace(/\s+/g, " ").trim()), t.ignoreSlashSpacing && (r = r.replace(/\s*\/\s*/g, "/")), r;
89
141
  };
90
- export { C as contentLanguage, T as foldCase, y as foldDigits, a as getShuffledChoices, o as lockChoices, E as normalizeResponse, s as partialScoring };
142
+ export { F as contentLanguage, R as foldCase, D as foldDigits, a as getShuffledChoices, o as lockChoices, I as mathContentLanguage, z as normalizeResponse, s as partialScoring };
@@ -30,15 +30,33 @@ export interface NormalizeOptions {
30
30
  ignoreSlashSpacing?: boolean;
31
31
  /** Remove the combining diacritics U+0300–U+036F, so `é` compares equal to `e`. */
32
32
  ignoreAccents?: boolean;
33
+ /**
34
+ * Write numbers in the form math-validation computes on. `٫` becomes `.` and `٬` becomes `,`
35
+ * whatever the language. Where the language's region writes a decimal comma (`es-ES`, `de-DE`),
36
+ * a number's one `,` or `{,}`, also before a repeating `\overline`, becomes `.`, and `;` becomes
37
+ * `, ` between list items, spaced so that math-validation does not read `(2;500)` as 2500. A `.`
38
+ * stays a decimal point, and a number with two marks (`1.000,5`) stays as typed. A tag without
39
+ * a region keeps the point, because US Spanish content declares `es`, which CLDR gives a decimal
40
+ * comma. The option reads text written in the language's convention, so a second pass over its
41
+ * output would read a list comma as a decimal.
42
+ */
43
+ latexNumbers?: boolean;
33
44
  }
34
45
  /** Every Unicode decimal digit (`\p{Nd}`) replaced by its ASCII digit. */
35
46
  export declare const foldDigits: (value: string) => string;
36
47
  /**
37
48
  * The language a comparison runs in: the element's `model.language`, then the
38
- * item's `env.locale`. The translator's underscore form (`tr_TR`) becomes a
39
- * BCP 47 tag.
49
+ * item's `env.locale`. A value that names no language passes to the next.
40
50
  */
41
51
  export declare const contentLanguage: (model?: object | null, env?: object | null) => string | undefined;
52
+ /**
53
+ * The language math scoring reads numbers in, to pass with `latexNumbers`: as `contentLanguage`
54
+ * finds it, except that an underscore code (`es_ES`, `tr_TR`) yields its language alone. Its
55
+ * producers, the authoring dropdown and the Learnosity transform, write `es_ES` for Spanish of any
56
+ * region, and content tagged `es_ES` mostly uses US number conventions, so a decimal comma comes
57
+ * only from a hyphenated tag.
58
+ */
59
+ export declare const mathContentLanguage: (model?: object | null, env?: object | null) => string | undefined;
42
60
  /**
43
61
  * Lower case for comparison: `toLocaleLowerCase` in Turkish and Azerbaijani,
44
62
  * so dotted and dotless i fold correctly, and `toLowerCase()` otherwise.
@@ -49,7 +67,7 @@ export declare const foldCase: (value: string, language?: string) => string;
49
67
  * when the options ask for it; bidi controls and tatweel removed; Arabic
50
68
  * presentation forms folded to base letters; NFC; every decimal digit folded
51
69
  * to 0–9; `٫` and `٬` replaced by the content language's decimal and group
52
- * marks. Arabic letter variants, accents, whitespace runs and the spacing
70
+ * marks, or with `latexNumbers` by the marks math-validation computes on. Arabic letter variants, accents, whitespace runs and the spacing
53
71
  * around `/` fold only when the options ask for it.
54
72
  */
55
73
  export declare const normalizeResponse: (value: string, options?: NormalizeOptions) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/shared-controller-utils",
3
- "version": "0.1.5-next.20261110065815",
3
+ "version": "0.1.5-next.20261110132055",
4
4
  "description": "Controller utility functions for PIE elements",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,7 +21,8 @@
21
21
  "clean": "rm -rf dist"
22
22
  },
23
23
  "dependencies": {
24
- "@pie-element/shared-types": "0.2.4-next.20261110065815"
24
+ "@pie-element/shared-types": "0.2.4-next.20261110072702",
25
+ "@pie-players/pie-language-tags": "1.0.0-beta.9"
25
26
  },
26
27
  "publishConfig": {
27
28
  "access": "public"