@atscript/ui 0.1.163 → 0.1.164

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 (156) hide show
  1. package/dist/client-factory.cjs +27 -0
  2. package/dist/client-factory.d.cts +53 -0
  3. package/dist/client-factory.d.mts +53 -0
  4. package/dist/client-factory.mjs +25 -0
  5. package/dist/form/apply.cjs +38 -0
  6. package/dist/form/apply.d.cts +36 -0
  7. package/dist/form/apply.d.mts +36 -0
  8. package/dist/form/apply.mjs +38 -0
  9. package/dist/form/clone.cjs +30 -0
  10. package/dist/form/clone.d.cts +23 -0
  11. package/dist/form/clone.d.mts +23 -0
  12. package/dist/form/clone.mjs +30 -0
  13. package/dist/form/create-form-def.cjs +440 -0
  14. package/dist/form/create-form-def.d.cts +67 -0
  15. package/dist/form/create-form-def.d.mts +67 -0
  16. package/dist/form/create-form-def.mjs +438 -0
  17. package/dist/form/decimal-format.cjs +324 -0
  18. package/dist/form/decimal-format.d.cts +86 -0
  19. package/dist/form/decimal-format.d.mts +86 -0
  20. package/dist/form/decimal-format.mjs +315 -0
  21. package/dist/form/diff.cjs +458 -0
  22. package/dist/form/diff.d.cts +80 -0
  23. package/dist/form/diff.d.mts +80 -0
  24. package/dist/form/diff.mjs +457 -0
  25. package/dist/form/dirty.cjs +65 -0
  26. package/dist/form/dirty.d.cts +47 -0
  27. package/dist/form/dirty.d.mts +47 -0
  28. package/dist/form/dirty.mjs +64 -0
  29. package/dist/form/error-utils.cjs +97 -0
  30. package/dist/form/error-utils.d.cts +58 -0
  31. package/dist/form/error-utils.d.mts +58 -0
  32. package/dist/form/error-utils.mjs +92 -0
  33. package/dist/form/form-actions.cjs +30 -0
  34. package/dist/form/form-actions.d.cts +17 -0
  35. package/dist/form/form-actions.d.mts +17 -0
  36. package/dist/form/form-actions.mjs +30 -0
  37. package/dist/form/grid.cjs +69 -0
  38. package/dist/form/grid.d.cts +49 -0
  39. package/dist/form/grid.d.mts +49 -0
  40. package/dist/form/grid.mjs +64 -0
  41. package/dist/form/labels.cjs +10 -0
  42. package/dist/form/labels.d.cts +7 -0
  43. package/dist/form/labels.d.mts +7 -0
  44. package/dist/form/labels.mjs +10 -0
  45. package/dist/form/measurement.cjs +20 -0
  46. package/dist/form/measurement.d.cts +29 -0
  47. package/dist/form/measurement.d.mts +29 -0
  48. package/dist/form/measurement.mjs +20 -0
  49. package/dist/form/path-utils.cjs +182 -0
  50. package/dist/form/path-utils.d.cts +47 -0
  51. package/dist/form/path-utils.d.mts +47 -0
  52. package/dist/form/path-utils.mjs +175 -0
  53. package/dist/form/rebase.cjs +89 -0
  54. package/dist/form/rebase.d.cts +61 -0
  55. package/dist/form/rebase.d.mts +61 -0
  56. package/dist/form/rebase.mjs +89 -0
  57. package/dist/form/skipped-nav.cjs +100 -0
  58. package/dist/form/skipped-nav.d.cts +13 -0
  59. package/dist/form/skipped-nav.d.mts +13 -0
  60. package/dist/form/skipped-nav.mjs +98 -0
  61. package/dist/form/types.cjs +40 -0
  62. package/dist/form/types.d.cts +133 -0
  63. package/dist/form/types.d.mts +133 -0
  64. package/dist/form/types.mjs +36 -0
  65. package/dist/form/union-detect.cjs +46 -0
  66. package/dist/form/union-detect.d.cts +22 -0
  67. package/dist/form/union-detect.d.mts +22 -0
  68. package/dist/form/union-detect.mjs +46 -0
  69. package/dist/form/validate.cjs +150 -0
  70. package/dist/form/validate.d.cts +50 -0
  71. package/dist/form/validate.d.mts +50 -0
  72. package/dist/form/validate.mjs +147 -0
  73. package/dist/index.cjs +217 -3360
  74. package/dist/index.d.cts +38 -1693
  75. package/dist/index.d.mts +38 -1693
  76. package/dist/index.mjs +35 -3179
  77. package/dist/nav/model-routes.cjs +59 -0
  78. package/dist/nav/model-routes.d.cts +33 -0
  79. package/dist/nav/model-routes.d.mts +33 -0
  80. package/dist/nav/model-routes.mjs +59 -0
  81. package/dist/plugin/annotations.cjs +577 -0
  82. package/dist/plugin/annotations.mjs +577 -0
  83. package/dist/plugin/primitives.cjs +30 -0
  84. package/dist/plugin/primitives.mjs +30 -0
  85. package/dist/plugin/value-help-validation.cjs +419 -0
  86. package/dist/plugin/value-help-validation.mjs +413 -0
  87. package/dist/plugin.cjs +4 -1001
  88. package/dist/plugin.mjs +2 -999
  89. package/dist/shared/annotation-keys.cjs +189 -0
  90. package/dist/shared/annotation-keys.d.cts +82 -0
  91. package/dist/shared/annotation-keys.d.mts +82 -0
  92. package/dist/shared/annotation-keys.mjs +97 -0
  93. package/dist/shared/field-resolver.cjs +123 -0
  94. package/dist/shared/field-resolver.d.cts +77 -0
  95. package/dist/shared/field-resolver.d.mts +77 -0
  96. package/dist/shared/field-resolver.mjs +110 -0
  97. package/dist/shared/meta-cache.cjs +244 -0
  98. package/dist/shared/meta-cache.d.cts +110 -0
  99. package/dist/shared/meta-cache.d.mts +110 -0
  100. package/dist/shared/meta-cache.mjs +237 -0
  101. package/dist/shared/str.cjs +19 -0
  102. package/dist/shared/str.d.cts +7 -0
  103. package/dist/shared/str.d.mts +7 -0
  104. package/dist/shared/str.mjs +17 -0
  105. package/dist/table/column-resolver.cjs +17 -0
  106. package/dist/table/column-resolver.d.cts +11 -0
  107. package/dist/table/column-resolver.d.mts +11 -0
  108. package/dist/table/column-resolver.mjs +15 -0
  109. package/dist/table/create-table-def.cjs +233 -0
  110. package/dist/table/create-table-def.d.cts +15 -0
  111. package/dist/table/create-table-def.d.mts +15 -0
  112. package/dist/table/create-table-def.mjs +233 -0
  113. package/dist/table/navigate-href.cjs +45 -0
  114. package/dist/table/navigate-href.d.cts +31 -0
  115. package/dist/table/navigate-href.d.mts +31 -0
  116. package/dist/table/navigate-href.mjs +45 -0
  117. package/dist/table/types.d.cts +287 -0
  118. package/dist/table/types.d.mts +287 -0
  119. package/dist/table/value-kind.cjs +20 -0
  120. package/dist/table/value-kind.d.cts +15 -0
  121. package/dist/table/value-kind.d.mts +15 -0
  122. package/dist/table/value-kind.mjs +19 -0
  123. package/dist/value-help/dict-paths.cjs +17 -0
  124. package/dist/value-help/dict-paths.d.cts +11 -0
  125. package/dist/value-help/dict-paths.d.mts +11 -0
  126. package/dist/value-help/dict-paths.mjs +17 -0
  127. package/dist/value-help/distinct-client.cjs +51 -0
  128. package/dist/value-help/distinct-client.d.cts +40 -0
  129. package/dist/value-help/distinct-client.d.mts +40 -0
  130. package/dist/value-help/distinct-client.mjs +50 -0
  131. package/dist/value-help/extract-literals.cjs +76 -0
  132. package/dist/value-help/extract-literals.d.cts +32 -0
  133. package/dist/value-help/extract-literals.d.mts +32 -0
  134. package/dist/value-help/extract-literals.mjs +74 -0
  135. package/dist/value-help/extract-ref.cjs +100 -0
  136. package/dist/value-help/extract-ref.d.cts +37 -0
  137. package/dist/value-help/extract-ref.d.mts +37 -0
  138. package/dist/value-help/extract-ref.mjs +100 -0
  139. package/dist/value-help/filter-tree.cjs +45 -0
  140. package/dist/value-help/filter-tree.mjs +45 -0
  141. package/dist/value-help/index.d.mts +8 -0
  142. package/dist/value-help/resolve-options.cjs +64 -0
  143. package/dist/value-help/resolve-options.d.cts +35 -0
  144. package/dist/value-help/resolve-options.d.mts +35 -0
  145. package/dist/value-help/resolve-options.mjs +60 -0
  146. package/dist/value-help/resolve.cjs +62 -0
  147. package/dist/value-help/resolve.d.cts +31 -0
  148. package/dist/value-help/resolve.d.mts +31 -0
  149. package/dist/value-help/resolve.mjs +61 -0
  150. package/dist/value-help/types.d.cts +36 -0
  151. package/dist/value-help/types.d.mts +36 -0
  152. package/dist/value-help/value-help-client.cjs +136 -0
  153. package/dist/value-help/value-help-client.d.cts +67 -0
  154. package/dist/value-help/value-help-client.d.mts +67 -0
  155. package/dist/value-help/value-help-client.mjs +134 -0
  156. package/package.json +10 -10
@@ -0,0 +1,324 @@
1
+ //#region src/form/decimal-format.ts
2
+ const WHITESPACE_GROUP_RE = /[   ]/g;
3
+ const numberFormatCache = /* @__PURE__ */ new Map();
4
+ function getNumberFormat(locale, opts) {
5
+ const key = `${locale ?? ""}|${opts.style ?? ""}|${opts.currency ?? ""}|${opts.currencyDisplay ?? ""}|${opts.useGrouping ?? ""}|${opts.minimumFractionDigits ?? ""}|${opts.maximumFractionDigits ?? ""}`;
6
+ let f = numberFormatCache.get(key);
7
+ if (!f) {
8
+ f = new Intl.NumberFormat(locale, opts);
9
+ numberFormatCache.set(key, f);
10
+ }
11
+ return f;
12
+ }
13
+ const decimalSeparatorCache = /* @__PURE__ */ new Map();
14
+ const thousandsSeparatorCache = /* @__PURE__ */ new Map();
15
+ const currencyDisplayCache = /* @__PURE__ */ new Map();
16
+ const currencyDecimalsCache = /* @__PURE__ */ new Map();
17
+ /** "." in en-US, "," in fr-FR. Returns "." when locale is undefined. */
18
+ function getDecimalSeparator(locale) {
19
+ const key = locale ?? "";
20
+ const cached = decimalSeparatorCache.get(key);
21
+ if (cached !== void 0) return cached;
22
+ let out = ".";
23
+ try {
24
+ out = getNumberFormat(locale, { useGrouping: false }).formatToParts(1.1).find((p) => p.type === "decimal")?.value ?? ".";
25
+ } catch {}
26
+ decimalSeparatorCache.set(key, out);
27
+ return out;
28
+ }
29
+ /**
30
+ * "," in en-US, NNBSP (U+202F) in fr-FR. Returns "" when no grouping is
31
+ * applied (or when Intl rejects the locale).
32
+ */
33
+ function getThousandsSeparator(locale) {
34
+ const key = locale ?? "";
35
+ const cached = thousandsSeparatorCache.get(key);
36
+ if (cached !== void 0) return cached;
37
+ let out = "";
38
+ try {
39
+ out = getNumberFormat(locale, { useGrouping: true }).formatToParts(1e6).find((p) => p.type === "group")?.value ?? "";
40
+ } catch {}
41
+ thousandsSeparatorCache.set(key, out);
42
+ return out;
43
+ }
44
+ function getCurrencyDisplayParts(code, locale) {
45
+ const key = `${locale ?? ""}|${code}`;
46
+ const cached = currencyDisplayCache.get(key);
47
+ if (cached) return cached;
48
+ let out = {
49
+ symbol: code,
50
+ position: "prefix"
51
+ };
52
+ try {
53
+ const parts = getNumberFormat(locale, {
54
+ style: "currency",
55
+ currency: code,
56
+ currencyDisplay: "narrowSymbol"
57
+ }).formatToParts(0);
58
+ const idxCur = parts.findIndex((p) => p.type === "currency");
59
+ const idxInt = parts.findIndex((p) => p.type === "integer");
60
+ out = {
61
+ symbol: parts[idxCur]?.value ?? code,
62
+ position: idxInt === -1 || idxCur < idxInt ? "prefix" : "suffix"
63
+ };
64
+ } catch {}
65
+ currencyDisplayCache.set(key, out);
66
+ return out;
67
+ }
68
+ /**
69
+ * Currency's natural decimal count via Intl. JPY=0, USD/EUR=2, BHD/KWD=3.
70
+ * Returns `undefined` for codes Intl doesn't know — caller falls back to
71
+ * `dbPrecisionScale`.
72
+ */
73
+ function getCurrencyDecimals(code, locale) {
74
+ if (!code) return void 0;
75
+ const key = `${locale ?? ""}|${code}`;
76
+ if (currencyDecimalsCache.has(key)) return currencyDecimalsCache.get(key);
77
+ let out;
78
+ try {
79
+ const max = getNumberFormat(locale, {
80
+ style: "currency",
81
+ currency: code
82
+ }).resolvedOptions().maximumFractionDigits;
83
+ out = typeof max === "number" ? max : void 0;
84
+ } catch {
85
+ out = void 0;
86
+ }
87
+ currencyDecimalsCache.set(key, out);
88
+ return out;
89
+ }
90
+ /**
91
+ * Parse a user-typed decimal string. Returns the canonical decimal
92
+ * (no thousands separator, "." as decimal separator) or `null` if invalid.
93
+ * Accepts both "." and "," as the decimal separator (locale-aware).
94
+ * Strips the locale thousands separator. Preserves sign. Does NOT
95
+ * enforce scale.
96
+ */
97
+ function parseDecimalInput(raw, locale) {
98
+ if (typeof raw !== "string") return null;
99
+ const trimmed = raw.trim();
100
+ if (trimmed === "") return null;
101
+ const decSep = getDecimalSeparator(locale);
102
+ const thouSep = getThousandsSeparator(locale);
103
+ let sign = "";
104
+ let body = trimmed;
105
+ if (body.startsWith("-")) {
106
+ sign = "-";
107
+ body = body.slice(1);
108
+ } else if (body.startsWith("+")) body = body.slice(1);
109
+ if (body.length === 0) return null;
110
+ if (body.includes("-") || body.includes("+")) return null;
111
+ if (thouSep && body.includes(thouSep)) {
112
+ const decIdx = body.indexOf(decSep);
113
+ const headRaw = decIdx === -1 ? body : body.slice(0, decIdx);
114
+ const tail = decIdx === -1 ? "" : body.slice(decIdx);
115
+ if (tail.includes(thouSep)) return null;
116
+ if (headRaw.includes(thouSep)) {
117
+ const groups = headRaw.split(thouSep);
118
+ const first = groups[0];
119
+ if (first.length < 1 || first.length > 3 || !/^\d+$/.test(first)) return null;
120
+ for (let i = 1; i < groups.length; i += 1) if (!/^\d{3}$/.test(groups[i])) return null;
121
+ }
122
+ body = `${headRaw.split(thouSep).join("")}${tail}`;
123
+ }
124
+ body = body.replace(WHITESPACE_GROUP_RE, "");
125
+ if (decSep !== ".") {
126
+ if ((body.match(/,/g)?.length ?? 0) > 1) return null;
127
+ if (body.includes(".") && body.includes(",")) return null;
128
+ if (body.includes(",")) body = body.replace(",", ".");
129
+ } else if (body.includes(",")) {
130
+ if (body.includes(".")) return null;
131
+ if ((body.match(/,/g)?.length ?? 0) > 1) return null;
132
+ body = body.replace(",", ".");
133
+ }
134
+ if (!/^\d*\.?\d*$/.test(body)) return null;
135
+ if (body === "" || body === ".") return null;
136
+ if (body.endsWith(".")) body = body.slice(0, -1);
137
+ if (body.startsWith(".")) body = `0${body}`;
138
+ const dot = body.indexOf(".");
139
+ if (dot === -1) body = body.replace(/^0+(\d)/, "$1");
140
+ else {
141
+ const head = body.slice(0, dot);
142
+ const tail = body.slice(dot);
143
+ body = `${head.replace(/^0+(\d)/, "$1")}${tail}`;
144
+ }
145
+ if (sign === "-" && /^0+(\.0+)?$/.test(body)) sign = "";
146
+ return `${sign}${body}`;
147
+ }
148
+ /**
149
+ * Enforce a fractional-digit count by truncating or padding. String-only —
150
+ * no float arithmetic. Default behaviour truncates (no rounding) so digits
151
+ * the user typed can't silently shift. Pass `roundHalfUp: true` to round.
152
+ *
153
+ * enforceScale("12.345", 2) → "12.34" (truncate)
154
+ * enforceScale("12.3", 4) → "12.3000" (pad)
155
+ * enforceScale("12", 0) → "12"
156
+ * enforceScale("12.99", 0) → "12" (no rounding)
157
+ */
158
+ function enforceScale(s, scale, opts) {
159
+ if (typeof s !== "string" || s === "") return s;
160
+ if (scale === void 0 || scale < 0) return s;
161
+ const parts = splitDecimalString(s);
162
+ if (scale === 0) {
163
+ if (opts?.roundHalfUp && parts.decimal.length > 0 && parts.decimal[0] >= "5") {
164
+ const bumped = addOne(parts.integer);
165
+ return joinDecimalString({
166
+ sign: parts.sign,
167
+ integer: bumped,
168
+ decimal: ""
169
+ });
170
+ }
171
+ return joinDecimalString({
172
+ sign: parts.sign,
173
+ integer: parts.integer,
174
+ decimal: ""
175
+ });
176
+ }
177
+ if (parts.decimal.length === scale) return joinDecimalString(parts);
178
+ if (parts.decimal.length < scale) return joinDecimalString({
179
+ sign: parts.sign,
180
+ integer: parts.integer,
181
+ decimal: parts.decimal.padEnd(scale, "0")
182
+ });
183
+ let head = parts.decimal.slice(0, scale);
184
+ const dropped = parts.decimal.slice(scale);
185
+ let integer = parts.integer;
186
+ if (opts?.roundHalfUp && dropped.length > 0 && dropped[0] >= "5") {
187
+ const bumpedFrac = addOne(head);
188
+ if (bumpedFrac.length > head.length) {
189
+ integer = addOne(integer);
190
+ head = "0".repeat(scale);
191
+ } else head = bumpedFrac;
192
+ }
193
+ return joinDecimalString({
194
+ sign: parts.sign,
195
+ integer,
196
+ decimal: head
197
+ });
198
+ }
199
+ function addOne(digits) {
200
+ if (digits === "") return "1";
201
+ const out = digits.split("");
202
+ let i = out.length - 1;
203
+ let carry = 1;
204
+ while (i >= 0 && carry > 0) {
205
+ const d = out[i].charCodeAt(0) - 48 + carry | 0;
206
+ if (d >= 10) {
207
+ out[i] = "0";
208
+ carry = 1;
209
+ } else {
210
+ out[i] = String.fromCharCode(d + 48);
211
+ carry = 0;
212
+ }
213
+ i -= 1;
214
+ }
215
+ if (carry > 0) out.unshift("1");
216
+ return out.join("");
217
+ }
218
+ function splitDecimalString(s) {
219
+ if (typeof s !== "string" || s === "") return {
220
+ sign: "",
221
+ integer: "0",
222
+ decimal: ""
223
+ };
224
+ let sign = "";
225
+ let body = s;
226
+ if (body.startsWith("-")) {
227
+ sign = "-";
228
+ body = body.slice(1);
229
+ } else if (body.startsWith("+")) body = body.slice(1);
230
+ if (body === "") return {
231
+ sign: "",
232
+ integer: "0",
233
+ decimal: ""
234
+ };
235
+ const dot = body.indexOf(".");
236
+ let integer;
237
+ let decimal;
238
+ if (dot === -1) {
239
+ integer = body;
240
+ decimal = "";
241
+ } else {
242
+ integer = body.slice(0, dot);
243
+ decimal = body.slice(dot + 1);
244
+ }
245
+ if (integer === "") integer = "0";
246
+ integer = integer.replace(/^0+(\d)/, "$1");
247
+ if (sign === "-" && integer === "0" && !decimal.replace(/0/g, "")) sign = "";
248
+ return {
249
+ sign,
250
+ integer,
251
+ decimal
252
+ };
253
+ }
254
+ function joinDecimalString(parts) {
255
+ const integer = parts.integer === "" ? "0" : parts.integer;
256
+ const decimal = parts.decimal;
257
+ const body = decimal === "" ? integer : `${integer}.${decimal}`;
258
+ return `${parts.sign}${body}`;
259
+ }
260
+ function formatDecimalForDisplay(opts) {
261
+ const { value, scale, locale, currency, unit, useGrouping = currency !== void 0 || unit !== void 0 || scale !== void 0 } = opts;
262
+ if (value === null || value === void 0 || value === "") return "";
263
+ let canonical;
264
+ if (typeof value === "number") {
265
+ if (!Number.isFinite(value)) return "";
266
+ canonical = String(value);
267
+ } else canonical = value;
268
+ if (!/^[+-]?\d*(\.\d*)?$/.test(canonical) || canonical === "." || canonical === "-") return canonical;
269
+ if (scale !== void 0 && scale >= 0) canonical = enforceScale(canonical, scale);
270
+ const parts = splitDecimalString(canonical);
271
+ const asNumber = Number(canonical);
272
+ const intlSafe = Number.isFinite(asNumber);
273
+ if (currency) {
274
+ try {
275
+ const fmt = getNumberFormat(locale, {
276
+ style: "currency",
277
+ currency,
278
+ currencyDisplay: "narrowSymbol",
279
+ minimumFractionDigits: scale,
280
+ maximumFractionDigits: scale,
281
+ useGrouping
282
+ });
283
+ if (intlSafe) return fmt.format(asNumber);
284
+ } catch {}
285
+ return `${currency} ${formatPlain(parts, scale, locale, useGrouping)}`;
286
+ }
287
+ const base = formatPlain(parts, scale, locale, useGrouping);
288
+ return unit ? `${base} ${unit}` : base;
289
+ }
290
+ function formatPlain(parts, scale, locale, useGrouping) {
291
+ const intStr = useGrouping ? groupInteger(parts.integer, locale) : parts.integer;
292
+ const decStr = scale !== void 0 && scale >= 0 ? parts.decimal.padEnd(scale, "0").slice(0, scale) : parts.decimal;
293
+ const decSep = getDecimalSeparator(locale);
294
+ const body = decStr.length > 0 ? `${intStr}${decSep}${decStr}` : intStr;
295
+ return `${parts.sign}${body}`;
296
+ }
297
+ /**
298
+ * Insert the locale's thousands separator into a plain integer string.
299
+ * Pure string-based — no float math, handles arbitrary length.
300
+ */
301
+ function groupInteger(integer, locale) {
302
+ const sep = getThousandsSeparator(locale);
303
+ if (!sep) return integer;
304
+ if (integer.length <= 3) return integer;
305
+ const out = [];
306
+ let i = integer.length;
307
+ while (i > 3) {
308
+ out.unshift(integer.slice(i - 3, i));
309
+ i -= 3;
310
+ }
311
+ out.unshift(integer.slice(0, i));
312
+ return out.join(sep);
313
+ }
314
+ //#endregion
315
+ exports.enforceScale = enforceScale;
316
+ exports.formatDecimalForDisplay = formatDecimalForDisplay;
317
+ exports.getCurrencyDecimals = getCurrencyDecimals;
318
+ exports.getCurrencyDisplayParts = getCurrencyDisplayParts;
319
+ exports.getDecimalSeparator = getDecimalSeparator;
320
+ exports.getThousandsSeparator = getThousandsSeparator;
321
+ exports.groupInteger = groupInteger;
322
+ exports.joinDecimalString = joinDecimalString;
323
+ exports.parseDecimalInput = parseDecimalInput;
324
+ exports.splitDecimalString = splitDecimalString;
@@ -0,0 +1,86 @@
1
+ //#region src/form/decimal-format.d.ts
2
+ /**
3
+ * Framework-agnostic decimal formatting + parsing helpers shared by
4
+ * `@atscript/vue-table` (read-only cell display) and `@atscript/vue-form`
5
+ * (editable amount/measure inputs). Symmetric output is the contract —
6
+ * a value rendered in a cell must read identically when displayed in
7
+ * the form composables, modulo currency / unit adornment.
8
+ *
9
+ * The functions here are intentionally pure (no `Number()` round-trips
10
+ * in the storage value path) — decimal-as-string correctness depends on
11
+ * not bouncing through floats.
12
+ */
13
+ interface CurrencyDisplay {
14
+ /** Narrow symbol: "$" / "€" / "US$" depending on locale. Falls back to code on Intl failure. */
15
+ symbol: string;
16
+ /** Whether the symbol typically sits left or right of the amount. */
17
+ position: "prefix" | "suffix";
18
+ }
19
+ interface DecimalParts {
20
+ sign: "" | "-";
21
+ /** Integer part, no thousands separator, no leading zeros beyond "0". */
22
+ integer: string;
23
+ /** Decimal part as captured, no separator. Empty string if absent. */
24
+ decimal: string;
25
+ }
26
+ interface FormatDecimalOptions {
27
+ value: string | number | null | undefined;
28
+ /** Scale used for display (typically the effective scale, not DB scale). Trailing zeros pad. */
29
+ scale?: number;
30
+ locale?: string;
31
+ /** When set → Intl.NumberFormat with style:currency. Symbol/grouping handled by Intl. */
32
+ currency?: string;
33
+ /** When set (and no currency) → "<formatted> <unit>". */
34
+ unit?: string;
35
+ /**
36
+ * Whether to group thousands. Grouping is reserved for measured values, so
37
+ * the default is derived: true when `currency`, `unit`, or `scale` is set,
38
+ * false for plain numbers. Pass explicitly to override.
39
+ */
40
+ useGrouping?: boolean;
41
+ }
42
+ /** "." in en-US, "," in fr-FR. Returns "." when locale is undefined. */
43
+ declare function getDecimalSeparator(locale?: string): string;
44
+ /**
45
+ * "," in en-US, NNBSP (U+202F) in fr-FR. Returns "" when no grouping is
46
+ * applied (or when Intl rejects the locale).
47
+ */
48
+ declare function getThousandsSeparator(locale?: string): string;
49
+ declare function getCurrencyDisplayParts(code: string, locale?: string): CurrencyDisplay;
50
+ /**
51
+ * Currency's natural decimal count via Intl. JPY=0, USD/EUR=2, BHD/KWD=3.
52
+ * Returns `undefined` for codes Intl doesn't know — caller falls back to
53
+ * `dbPrecisionScale`.
54
+ */
55
+ declare function getCurrencyDecimals(code: string, locale?: string): number | undefined;
56
+ /**
57
+ * Parse a user-typed decimal string. Returns the canonical decimal
58
+ * (no thousands separator, "." as decimal separator) or `null` if invalid.
59
+ * Accepts both "." and "," as the decimal separator (locale-aware).
60
+ * Strips the locale thousands separator. Preserves sign. Does NOT
61
+ * enforce scale.
62
+ */
63
+ declare function parseDecimalInput(raw: string, locale?: string): string | null;
64
+ /**
65
+ * Enforce a fractional-digit count by truncating or padding. String-only —
66
+ * no float arithmetic. Default behaviour truncates (no rounding) so digits
67
+ * the user typed can't silently shift. Pass `roundHalfUp: true` to round.
68
+ *
69
+ * enforceScale("12.345", 2) → "12.34" (truncate)
70
+ * enforceScale("12.3", 4) → "12.3000" (pad)
71
+ * enforceScale("12", 0) → "12"
72
+ * enforceScale("12.99", 0) → "12" (no rounding)
73
+ */
74
+ declare function enforceScale(s: string, scale: number | undefined, opts?: {
75
+ roundHalfUp?: boolean;
76
+ }): string;
77
+ declare function splitDecimalString(s: string): DecimalParts;
78
+ declare function joinDecimalString(parts: DecimalParts): string;
79
+ declare function formatDecimalForDisplay(opts: FormatDecimalOptions): string;
80
+ /**
81
+ * Insert the locale's thousands separator into a plain integer string.
82
+ * Pure string-based — no float math, handles arbitrary length.
83
+ */
84
+ declare function groupInteger(integer: string, locale?: string): string;
85
+ //#endregion
86
+ export { CurrencyDisplay, DecimalParts, FormatDecimalOptions, enforceScale, formatDecimalForDisplay, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getThousandsSeparator, groupInteger, joinDecimalString, parseDecimalInput, splitDecimalString };
@@ -0,0 +1,86 @@
1
+ //#region src/form/decimal-format.d.ts
2
+ /**
3
+ * Framework-agnostic decimal formatting + parsing helpers shared by
4
+ * `@atscript/vue-table` (read-only cell display) and `@atscript/vue-form`
5
+ * (editable amount/measure inputs). Symmetric output is the contract —
6
+ * a value rendered in a cell must read identically when displayed in
7
+ * the form composables, modulo currency / unit adornment.
8
+ *
9
+ * The functions here are intentionally pure (no `Number()` round-trips
10
+ * in the storage value path) — decimal-as-string correctness depends on
11
+ * not bouncing through floats.
12
+ */
13
+ interface CurrencyDisplay {
14
+ /** Narrow symbol: "$" / "€" / "US$" depending on locale. Falls back to code on Intl failure. */
15
+ symbol: string;
16
+ /** Whether the symbol typically sits left or right of the amount. */
17
+ position: "prefix" | "suffix";
18
+ }
19
+ interface DecimalParts {
20
+ sign: "" | "-";
21
+ /** Integer part, no thousands separator, no leading zeros beyond "0". */
22
+ integer: string;
23
+ /** Decimal part as captured, no separator. Empty string if absent. */
24
+ decimal: string;
25
+ }
26
+ interface FormatDecimalOptions {
27
+ value: string | number | null | undefined;
28
+ /** Scale used for display (typically the effective scale, not DB scale). Trailing zeros pad. */
29
+ scale?: number;
30
+ locale?: string;
31
+ /** When set → Intl.NumberFormat with style:currency. Symbol/grouping handled by Intl. */
32
+ currency?: string;
33
+ /** When set (and no currency) → "<formatted> <unit>". */
34
+ unit?: string;
35
+ /**
36
+ * Whether to group thousands. Grouping is reserved for measured values, so
37
+ * the default is derived: true when `currency`, `unit`, or `scale` is set,
38
+ * false for plain numbers. Pass explicitly to override.
39
+ */
40
+ useGrouping?: boolean;
41
+ }
42
+ /** "." in en-US, "," in fr-FR. Returns "." when locale is undefined. */
43
+ declare function getDecimalSeparator(locale?: string): string;
44
+ /**
45
+ * "," in en-US, NNBSP (U+202F) in fr-FR. Returns "" when no grouping is
46
+ * applied (or when Intl rejects the locale).
47
+ */
48
+ declare function getThousandsSeparator(locale?: string): string;
49
+ declare function getCurrencyDisplayParts(code: string, locale?: string): CurrencyDisplay;
50
+ /**
51
+ * Currency's natural decimal count via Intl. JPY=0, USD/EUR=2, BHD/KWD=3.
52
+ * Returns `undefined` for codes Intl doesn't know — caller falls back to
53
+ * `dbPrecisionScale`.
54
+ */
55
+ declare function getCurrencyDecimals(code: string, locale?: string): number | undefined;
56
+ /**
57
+ * Parse a user-typed decimal string. Returns the canonical decimal
58
+ * (no thousands separator, "." as decimal separator) or `null` if invalid.
59
+ * Accepts both "." and "," as the decimal separator (locale-aware).
60
+ * Strips the locale thousands separator. Preserves sign. Does NOT
61
+ * enforce scale.
62
+ */
63
+ declare function parseDecimalInput(raw: string, locale?: string): string | null;
64
+ /**
65
+ * Enforce a fractional-digit count by truncating or padding. String-only —
66
+ * no float arithmetic. Default behaviour truncates (no rounding) so digits
67
+ * the user typed can't silently shift. Pass `roundHalfUp: true` to round.
68
+ *
69
+ * enforceScale("12.345", 2) → "12.34" (truncate)
70
+ * enforceScale("12.3", 4) → "12.3000" (pad)
71
+ * enforceScale("12", 0) → "12"
72
+ * enforceScale("12.99", 0) → "12" (no rounding)
73
+ */
74
+ declare function enforceScale(s: string, scale: number | undefined, opts?: {
75
+ roundHalfUp?: boolean;
76
+ }): string;
77
+ declare function splitDecimalString(s: string): DecimalParts;
78
+ declare function joinDecimalString(parts: DecimalParts): string;
79
+ declare function formatDecimalForDisplay(opts: FormatDecimalOptions): string;
80
+ /**
81
+ * Insert the locale's thousands separator into a plain integer string.
82
+ * Pure string-based — no float math, handles arbitrary length.
83
+ */
84
+ declare function groupInteger(integer: string, locale?: string): string;
85
+ //#endregion
86
+ export { CurrencyDisplay, DecimalParts, FormatDecimalOptions, enforceScale, formatDecimalForDisplay, getCurrencyDecimals, getCurrencyDisplayParts, getDecimalSeparator, getThousandsSeparator, groupInteger, joinDecimalString, parseDecimalInput, splitDecimalString };