@g9tm/lynxcontrols-foundation 0.0.0-stage → 1.4.0
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 +4 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/collections.d.ts +16 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +40 -0
- package/dist/collections.js.map +1 -0
- package/dist/culture/calendar.d.ts +122 -0
- package/dist/culture/calendar.d.ts.map +1 -0
- package/dist/culture/calendar.js +379 -0
- package/dist/culture/calendar.js.map +1 -0
- package/dist/culture/culture.d.ts +91 -0
- package/dist/culture/culture.d.ts.map +1 -0
- package/dist/culture/culture.js +173 -0
- package/dist/culture/culture.js.map +1 -0
- package/dist/culture/date-format.d.ts +19 -0
- package/dist/culture/date-format.d.ts.map +1 -0
- package/dist/culture/date-format.js +101 -0
- package/dist/culture/date-format.js.map +1 -0
- package/dist/culture/digits.d.ts +29 -0
- package/dist/culture/digits.d.ts.map +1 -0
- package/dist/culture/digits.js +43 -0
- package/dist/culture/digits.js.map +1 -0
- package/dist/culture/duration.d.ts +38 -0
- package/dist/culture/duration.d.ts.map +1 -0
- package/dist/culture/duration.js +41 -0
- package/dist/culture/duration.js.map +1 -0
- package/dist/culture/index.d.ts +9 -0
- package/dist/culture/index.d.ts.map +1 -0
- package/dist/culture/index.js +8 -0
- package/dist/culture/numbers.d.ts +38 -0
- package/dist/culture/numbers.d.ts.map +1 -0
- package/dist/culture/numbers.js +64 -0
- package/dist/culture/numbers.js.map +1 -0
- package/dist/culture/relative-time.d.ts +50 -0
- package/dist/culture/relative-time.d.ts.map +1 -0
- package/dist/culture/relative-time.js +63 -0
- package/dist/culture/relative-time.js.map +1 -0
- package/dist/culture/strings.d.ts +145 -0
- package/dist/culture/strings.d.ts.map +1 -0
- package/dist/culture/strings.js +345 -0
- package/dist/culture/strings.js.map +1 -0
- package/dist/enums/index.d.ts +195 -0
- package/dist/enums/index.d.ts.map +1 -0
- package/dist/enums/index.js +130 -0
- package/dist/enums/index.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/exec/diagnostics.d.ts +74 -0
- package/dist/exec/diagnostics.d.ts.map +1 -0
- package/dist/exec/diagnostics.js +73 -0
- package/dist/exec/diagnostics.js.map +1 -0
- package/dist/exec/index.d.ts +5 -0
- package/dist/exec/index.d.ts.map +1 -0
- package/dist/exec/index.js +4 -0
- package/dist/exec/options.d.ts +75 -0
- package/dist/exec/options.d.ts.map +1 -0
- package/dist/exec/options.js +107 -0
- package/dist/exec/options.js.map +1 -0
- package/dist/exec/safe-executor.d.ts +138 -0
- package/dist/exec/safe-executor.d.ts.map +1 -0
- package/dist/exec/safe-executor.js +401 -0
- package/dist/exec/safe-executor.js.map +1 -0
- package/dist/exec/trace.d.ts +59 -0
- package/dist/exec/trace.d.ts.map +1 -0
- package/dist/exec/trace.js +108 -0
- package/dist/exec/trace.js.map +1 -0
- package/dist/icons/generated/glyph-svg.d.ts +37 -0
- package/dist/icons/generated/glyph-svg.d.ts.map +1 -0
- package/dist/icons/generated/glyph-svg.js +33 -0
- package/dist/icons/generated/glyph-svg.js.map +1 -0
- package/dist/icons/glyph-slots.d.ts +79 -0
- package/dist/icons/glyph-slots.d.ts.map +1 -0
- package/dist/icons/glyph-slots.js +50 -0
- package/dist/icons/glyph-slots.js.map +1 -0
- package/dist/icons/glyph.d.ts +76 -0
- package/dist/icons/glyph.d.ts.map +1 -0
- package/dist/icons/glyph.js +42 -0
- package/dist/icons/glyph.js.map +1 -0
- package/dist/icons/icon-fonts.d.ts +55 -0
- package/dist/icons/icon-fonts.d.ts.map +1 -0
- package/dist/icons/icon-fonts.js +74 -0
- package/dist/icons/icon-fonts.js.map +1 -0
- package/dist/icons/icon.d.ts +102 -0
- package/dist/icons/icon.d.ts.map +1 -0
- package/dist/icons/icon.js +132 -0
- package/dist/icons/icon.js.map +1 -0
- package/dist/icons/index.d.ts +7 -0
- package/dist/icons/index.d.ts.map +1 -0
- package/dist/icons/index.js +6 -0
- package/dist/icons/svg.d.ts +28 -0
- package/dist/icons/svg.d.ts.map +1 -0
- package/dist/icons/svg.js +59 -0
- package/dist/icons/svg.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/services/abort.d.ts +31 -0
- package/dist/services/abort.d.ts.map +1 -0
- package/dist/services/abort.js +47 -0
- package/dist/services/abort.js.map +1 -0
- package/dist/services/clock.d.ts +35 -0
- package/dist/services/clock.d.ts.map +1 -0
- package/dist/services/clock.js +37 -0
- package/dist/services/clock.js.map +1 -0
- package/dist/services/contracts.d.ts +200 -0
- package/dist/services/contracts.d.ts.map +1 -0
- package/dist/services/contracts.js +37 -0
- package/dist/services/contracts.js.map +1 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +4 -0
- package/dist/services/preferences.d.ts +105 -0
- package/dist/services/preferences.d.ts.map +1 -0
- package/dist/services/preferences.js +253 -0
- package/dist/services/preferences.js.map +1 -0
- package/dist/theme/color.d.ts +94 -0
- package/dist/theme/color.d.ts.map +1 -0
- package/dist/theme/color.js +150 -0
- package/dist/theme/color.js.map +1 -0
- package/dist/theme/control-colors.d.ts +46 -0
- package/dist/theme/control-colors.d.ts.map +1 -0
- package/dist/theme/control-colors.js +46 -0
- package/dist/theme/control-colors.js.map +1 -0
- package/dist/theme/index.d.ts +5 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +4 -0
- package/dist/theme/theme.d.ts +88 -0
- package/dist/theme/theme.d.ts.map +1 -0
- package/dist/theme/theme.js +190 -0
- package/dist/theme/theme.js.map +1 -0
- package/dist/theme/variants.d.ts +33 -0
- package/dist/theme/variants.d.ts.map +1 -0
- package/dist/theme/variants.js +53 -0
- package/dist/theme/variants.js.map +1 -0
- package/dist/tokens/css-vars.d.ts +35 -0
- package/dist/tokens/css-vars.d.ts.map +1 -0
- package/dist/tokens/css-vars.js +49 -0
- package/dist/tokens/css-vars.js.map +1 -0
- package/dist/tokens/generated/metrics.d.ts +184 -0
- package/dist/tokens/generated/metrics.d.ts.map +1 -0
- package/dist/tokens/generated/metrics.js +349 -0
- package/dist/tokens/generated/metrics.js.map +1 -0
- package/dist/tokens/generated/palettes.d.ts +113 -0
- package/dist/tokens/generated/palettes.d.ts.map +1 -0
- package/dist/tokens/generated/palettes.js +391 -0
- package/dist/tokens/generated/palettes.js.map +1 -0
- package/dist/tokens/index.d.ts +5 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +4 -0
- package/dist/tokens/layout-metrics.d.ts +120 -0
- package/dist/tokens/layout-metrics.d.ts.map +1 -0
- package/dist/tokens/layout-metrics.js +111 -0
- package/dist/tokens/layout-metrics.js.map +1 -0
- package/docs/api.md +368 -0
- package/docs/foundation.md +369 -0
- package/docs/migration/Core.Controls.Shared.md +475 -0
- package/docs/migration/Core.Helpers.md +132 -0
- package/docs/migration/Core.Icons.md +135 -0
- package/docs/migration/Core.Localization.md +118 -0
- package/docs/migration/Core.Storage.md +54 -0
- package/docs/migration/Core.Theming.md +328 -0
- package/package.json +59 -4
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { G9Error } from "../errors.js";
|
|
2
|
+
import { checkNumberingSystem, normalizeToAscii, toNativeDigits } from "./digits.js";
|
|
3
|
+
const LATIN = Object.freeze({
|
|
4
|
+
decimal: '.',
|
|
5
|
+
group: ',',
|
|
6
|
+
minus: '-'
|
|
7
|
+
});
|
|
8
|
+
const PERSIAN = Object.freeze({
|
|
9
|
+
decimal: '٫',
|
|
10
|
+
group: '٬',
|
|
11
|
+
minus: '−'
|
|
12
|
+
});
|
|
13
|
+
const ARABIC_INDIC = Object.freeze({
|
|
14
|
+
decimal: '٫',
|
|
15
|
+
group: '٬',
|
|
16
|
+
minus: '-'
|
|
17
|
+
});
|
|
18
|
+
function getNumberSymbols(numberingSystem) {
|
|
19
|
+
const system = checkNumberingSystem(numberingSystem);
|
|
20
|
+
return 'latin' === system ? LATIN : 'persian' === system ? PERSIAN : ARABIC_INDIC;
|
|
21
|
+
}
|
|
22
|
+
function fractionDigits(name, value, fallback) {
|
|
23
|
+
if (void 0 === value) return fallback;
|
|
24
|
+
if (!Number.isInteger(value) || value < 0 || value > 20) throw new G9Error('number-invalid-option', `${name} must be an integer 0–20, got ${value}.`);
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
function group(integer, separator) {
|
|
28
|
+
let out = '';
|
|
29
|
+
for(let i = 0; i < integer.length; i++){
|
|
30
|
+
if (i > 0 && (integer.length - i) % 3 === 0) out += separator;
|
|
31
|
+
out += integer.charAt(i);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
function formatNumber(value, options = {}) {
|
|
36
|
+
var _options_numberingSystem, _options_numberingSystem1;
|
|
37
|
+
if (!Number.isFinite(value)) throw new G9Error('number-not-finite', `Cannot format ${value}.`);
|
|
38
|
+
if (Math.abs(value) >= 1e21) throw new G9Error('number-out-of-range', `${value} is too large to format.`);
|
|
39
|
+
const min = fractionDigits('minimumFractionDigits', options.minimumFractionDigits, 0);
|
|
40
|
+
const max = fractionDigits('maximumFractionDigits', options.maximumFractionDigits, Math.max(3, min));
|
|
41
|
+
if (max < min) throw new G9Error('number-invalid-option', `maximumFractionDigits (${max}) is below minimumFractionDigits (${min}).`);
|
|
42
|
+
const symbols = getNumberSymbols(null != (_options_numberingSystem = options.numberingSystem) ? _options_numberingSystem : 'latin');
|
|
43
|
+
const fixed = Math.abs(value).toFixed(max);
|
|
44
|
+
const dot = fixed.indexOf('.');
|
|
45
|
+
const integer = dot < 0 ? fixed : fixed.slice(0, dot);
|
|
46
|
+
let fraction = dot < 0 ? '' : fixed.slice(dot + 1);
|
|
47
|
+
while(fraction.length > min && '0' === fraction.charAt(fraction.length - 1))fraction = fraction.slice(0, -1);
|
|
48
|
+
const negative = value < 0 && /[1-9]/.test(fixed);
|
|
49
|
+
const body = (false === options.useGrouping ? integer : group(integer, symbols.group)) + (fraction ? symbols.decimal + fraction : '');
|
|
50
|
+
return toNativeDigits((negative ? symbols.minus : '') + body, null != (_options_numberingSystem1 = options.numberingSystem) ? _options_numberingSystem1 : 'latin');
|
|
51
|
+
}
|
|
52
|
+
function formatPlainNumber(value, numberingSystem) {
|
|
53
|
+
const symbols = getNumberSymbols(numberingSystem);
|
|
54
|
+
const text = String(value).replace('-', symbols.minus).replace('.', symbols.decimal).replace('Infinity', '∞');
|
|
55
|
+
return toNativeDigits(text, numberingSystem);
|
|
56
|
+
}
|
|
57
|
+
function parseNumber(text) {
|
|
58
|
+
const ascii = normalizeToAscii(text).replace(/[\s]/g, '').replace(/[−]/g, '-').replace(/٫/g, '.').replace(/[,٬]/g, '');
|
|
59
|
+
if (!/^[-+]?(\d+(\.\d*)?|\.\d+)$/.test(ascii)) return null;
|
|
60
|
+
return Number(ascii);
|
|
61
|
+
}
|
|
62
|
+
export { formatNumber, formatPlainNumber, getNumberSymbols, parseNumber };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=numbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"culture/numbers.js","sources":["../../src/culture/numbers.ts"],"sourcesContent":["import { G9Error } from '../errors';\nimport { checkNumberingSystem, type G9NumberingSystem, normalizeToAscii, toNativeDigits } from './digits';\n\n/** The characters a numbering system writes numbers with (CLDR `latn` / `arabext` / `arab` symbols). */\nexport interface G9NumberSymbols {\n readonly decimal: string;\n readonly group: string;\n readonly minus: string;\n}\n\nconst LATIN: G9NumberSymbols = Object.freeze({ decimal: '.', group: ',', minus: '-' });\n// CLDR: Persian and Arabic-Indic digits use the Arabic decimal (U+066B) and thousands (U+066C) separators. The minus\n// carries a bidi mark so it stays in front of the digits inside right-to-left text: LRM + U+2212 for Persian\n// (CLDR fa `arabext`), ALM + hyphen-minus for Arabic-Indic (CLDR ar `arab`).\nconst PERSIAN: G9NumberSymbols = Object.freeze({ decimal: '٫', group: '٬', minus: '−' });\nconst ARABIC_INDIC: G9NumberSymbols = Object.freeze({ decimal: '٫', group: '٬', minus: '-' });\n\n/** Decimal, grouping and minus characters for a numbering system. */\nexport function getNumberSymbols(numberingSystem: G9NumberingSystem): G9NumberSymbols {\n const system = checkNumberingSystem(numberingSystem);\n return system === 'latin' ? LATIN : system === 'persian' ? PERSIAN : ARABIC_INDIC;\n}\n\n/** Options of {@link formatNumber}. */\nexport interface G9NumberFormatOptions {\n /** Digits and separators. Default `'latin'`; pass `culture.numberingSystem` for the active culture. */\n readonly numberingSystem?: G9NumberingSystem;\n /** Fraction digits always written (padded with zeros). Default 0. */\n readonly minimumFractionDigits?: number;\n /** Fraction digits at most; the value is rounded like `Number.prototype.toFixed`. Default 3, at least the minimum. */\n readonly maximumFractionDigits?: number;\n /** Group the integer part by thousands. Default `true`. */\n readonly useGrouping?: boolean;\n}\n\nfunction fractionDigits(name: string, value: number | undefined, fallback: number): number {\n if (value === undefined) return fallback;\n if (!Number.isInteger(value) || value < 0 || value > 20) {\n throw new G9Error('number-invalid-option', `${name} must be an integer 0–20, got ${value}.`);\n }\n return value;\n}\n\nfunction group(integer: string, separator: string): string {\n let out = '';\n for (let i = 0; i < integer.length; i++) {\n if (i > 0 && (integer.length - i) % 3 === 0) out += separator;\n out += integer.charAt(i);\n }\n return out;\n}\n\n/**\n * Formats a number without `Intl` (Lynx has none): thousands grouping, fraction digits and the numbering system's digits\n * and separators. `formatNumber(1234.5, { numberingSystem: 'persian' })` is `'۱٬۲۳۴٫۵'`.\n * @throws {G9Error} `number-not-finite` for NaN/±Infinity, `number-out-of-range` from 1e21 up (where JavaScript\n * switches to exponent notation), `number-invalid-option` for bad fraction digits.\n */\nexport function formatNumber(value: number, options: G9NumberFormatOptions = {}): string {\n if (!Number.isFinite(value)) throw new G9Error('number-not-finite', `Cannot format ${value}.`);\n if (Math.abs(value) >= 1e21) throw new G9Error('number-out-of-range', `${value} is too large to format.`);\n const min = fractionDigits('minimumFractionDigits', options.minimumFractionDigits, 0);\n const max = fractionDigits('maximumFractionDigits', options.maximumFractionDigits, Math.max(3, min));\n if (max < min) {\n throw new G9Error(\n 'number-invalid-option',\n `maximumFractionDigits (${max}) is below minimumFractionDigits (${min}).`,\n );\n }\n const symbols = getNumberSymbols(options.numberingSystem ?? 'latin');\n const fixed = Math.abs(value).toFixed(max);\n const dot = fixed.indexOf('.');\n const integer = dot < 0 ? fixed : fixed.slice(0, dot);\n let fraction = dot < 0 ? '' : fixed.slice(dot + 1);\n while (fraction.length > min && fraction.charAt(fraction.length - 1) === '0') fraction = fraction.slice(0, -1);\n const negative = value < 0 && /[1-9]/.test(fixed);\n const body =\n (options.useGrouping === false ? integer : group(integer, symbols.group)) +\n (fraction ? symbols.decimal + fraction : '');\n return toNativeDigits((negative ? symbols.minus : '') + body, options.numberingSystem ?? 'latin');\n}\n\n/**\n * Writes a number the way .NET's composite formatting (`string.Format(\"{0}\", n)`) does, in shortest round-trip form\n * and without grouping, then in `numberingSystem`'s digits and separators. Used by `G9Strings.format` placeholders.\n */\nexport function formatPlainNumber(value: number, numberingSystem: G9NumberingSystem): string {\n const symbols = getNumberSymbols(numberingSystem);\n const text = String(value).replace('-', symbols.minus).replace('.', symbols.decimal).replace('Infinity', '∞');\n return toNativeDigits(text, numberingSystem);\n}\n\n/**\n * Reads a number typed in any of the three digit sets, with either separator style (`'1,234.5'`, `'۱٬۲۳۴٫۵'`,\n * `'١٬٢٣٤٫٥'`), a leading sign and bidi marks. Returns `null` for anything else (no partial parse).\n */\nexport function parseNumber(text: string | null | undefined): number | null {\n const ascii = normalizeToAscii(text)\n .replace(/[\\s]/g, '')\n .replace(/[−]/g, '-')\n .replace(/٫/g, '.')\n .replace(/[,٬]/g, '');\n if (!/^[-+]?(\\d+(\\.\\d*)?|\\.\\d+)$/.test(ascii)) return null;\n return Number(ascii);\n}\n"],"names":["LATIN","Object","PERSIAN","ARABIC_INDIC","getNumberSymbols","numberingSystem","system","checkNumberingSystem","fractionDigits","name","value","fallback","undefined","Number","G9Error","group","integer","separator","out","i","formatNumber","options","_options_numberingSystem","_options_numberingSystem1","Math","min","max","symbols","fixed","dot","fraction","negative","body","toNativeDigits","formatPlainNumber","text","String","parseNumber","ascii","normalizeToAscii"],"mappings":";;AAUA,MAAMA,QAAyBC,OAAO,MAAM,CAAC;IAAE,SAAS;IAAK,OAAO;IAAK,OAAO;AAAI;AAIpF,MAAMC,UAA2BD,OAAO,MAAM,CAAC;IAAE,SAAS;IAAK,OAAO;IAAK,OAAO;AAAK;AACvF,MAAME,eAAgCF,OAAO,MAAM,CAAC;IAAE,SAAS;IAAK,OAAO;IAAK,OAAO;AAAK;AAGrF,SAASG,iBAAiBC,eAAkC;IACjE,MAAMC,SAASC,qBAAqBF;IACpC,OAAOC,AAAW,YAAXA,SAAqBN,QAAQM,AAAW,cAAXA,SAAuBJ,UAAUC;AACvE;AAcA,SAASK,eAAeC,IAAY,EAAEC,KAAyB,EAAEC,QAAgB;IAC/E,IAAID,AAAUE,WAAVF,OAAqB,OAAOC;IAChC,IAAI,CAACE,OAAO,SAAS,CAACH,UAAUA,QAAQ,KAAKA,QAAQ,IACnD,MAAM,IAAII,QAAQ,yBAAyB,GAAGL,KAAK,8BAA8B,EAAEC,MAAM,CAAC,CAAC;IAE7F,OAAOA;AACT;AAEA,SAASK,MAAMC,OAAe,EAAEC,SAAiB;IAC/C,IAAIC,MAAM;IACV,IAAK,IAAIC,IAAI,GAAGA,IAAIH,QAAQ,MAAM,EAAEG,IAAK;QACvC,IAAIA,IAAI,KAAMH,AAAAA,CAAAA,QAAQ,MAAM,GAAGG,CAAAA,IAAK,MAAM,GAAGD,OAAOD;QACpDC,OAAOF,QAAQ,MAAM,CAACG;IACxB;IACA,OAAOD;AACT;AAQO,SAASE,aAAaV,KAAa,EAAEW,UAAiC,CAAC,CAAC;QAW5CC,0BAU6BC;IApB9D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A,QAAQ,eAAe,AAAD,IAAtBA,4BAA2B;AAC3F;AAMO,SAASW,kBAAkBxB,KAAa,EAAEL,eAAkC;IACjF,MAAMsB,UAAUvB,iBAAiBC;IACjC,MAAM8B,OAAOC,OAAO1B,OAAO,OAAO,CAAC,KAAKiB,QAAQ,KAAK,EAAE,OAAO,CAAC,KAAKA,QAAQ,OAAO,EAAE,OAAO,CAAC,YAAY;IACzG,OAAOM,eAAeE,MAAM9B;AAC9B;AAMO,SAASgC,YAAYF,IAA+B;IACzD,MAAMG,QAAQC,iBAAiBJ,MAC5B,OAAO,CAAC,YAAY,IACpB,OAAO,CAAC,QAAQ,KAChB,OAAO,CAAC,MAAM,KACd,OAAO,CAAC,SAAS;IACpB,IAAI,CAAC,6BAA6B,IAAI,CAACG,QAAQ,OAAO;IACtD,OAAOzB,OAAOyB;AAChB"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type G9Strings } from './strings.js';
|
|
2
|
+
/** A clock (the WP01.4 `G9Clock` contract fits) or a fixed instant, in epoch milliseconds. */
|
|
3
|
+
export type G9Now = number | {
|
|
4
|
+
now(): number;
|
|
5
|
+
};
|
|
6
|
+
/** The unit a relative phrase is written in. */
|
|
7
|
+
export declare const G9RelativeTimeUnit: {
|
|
8
|
+
readonly JustNow: "justNow";
|
|
9
|
+
readonly Minutes: "minutes";
|
|
10
|
+
readonly Hours: "hours";
|
|
11
|
+
readonly Days: "days";
|
|
12
|
+
readonly Weeks: "weeks";
|
|
13
|
+
readonly Months: "months";
|
|
14
|
+
readonly Years: "years";
|
|
15
|
+
};
|
|
16
|
+
export type G9RelativeTimeUnit = (typeof G9RelativeTimeUnit)[keyof typeof G9RelativeTimeUnit];
|
|
17
|
+
/** How long ago an instant was, in the unit the phrase uses. `count` is at least 1 (0 for `'justNow'`). */
|
|
18
|
+
export interface G9RelativeTimeParts {
|
|
19
|
+
readonly unit: G9RelativeTimeUnit;
|
|
20
|
+
readonly count: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Buckets an instant against `now` exactly like MAUI `G9RelativeTimeFormatter.FormatAgo`: under a minute is "just now";
|
|
24
|
+
* then whole minutes (< 60), hours (< 24), days (< 7), weeks (days / 7, < 30 days), months (days / 30, < 365 days),
|
|
25
|
+
* years (days / 365); counts are truncated and at least 1. A future instant counts as now.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getRelativeTimeParts(instantMs: number, now: G9Now): G9RelativeTimeParts;
|
|
28
|
+
/** Inputs of {@link formatAgo}. */
|
|
29
|
+
export interface G9RelativeTimeOptions {
|
|
30
|
+
/** The clock or the current instant. Required: there is no hidden `Date.now()`. */
|
|
31
|
+
readonly now: G9Now;
|
|
32
|
+
/** Strings of the culture to write in (their `culture` supplies the digits). */
|
|
33
|
+
readonly strings: G9Strings;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The relative phrase alone, e.g. `'2 d ago'`, `'۲ روز پیش'` (MAUI `G9RelativeTimeFormatter.FormatAgo`). Takes an
|
|
37
|
+
* absolute instant, so a time zone can no longer shift the result (MAUI subtracted a local `DateTime` from UTC now).
|
|
38
|
+
*/
|
|
39
|
+
export declare function formatAgo(instantMs: number, options: G9RelativeTimeOptions): string;
|
|
40
|
+
/** Inputs of {@link formatAgoWithTime}. */
|
|
41
|
+
export interface G9RelativeTimeWithClockOptions extends G9RelativeTimeOptions {
|
|
42
|
+
/** UTC offset, in minutes, of the wall clock the time is shown in (`210` for Tehran). Required: Lynx has no zones. */
|
|
43
|
+
readonly utcOffsetMinutes: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The phrase joined with the wall-clock time, e.g. `'6 h ago - 14:19'` (MAUI `FormatAgoWithTime`, the history
|
|
47
|
+
* timeline format). The time is `HH:mm` in the culture's digits at `utcOffsetMinutes`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function formatAgoWithTime(instantMs: number, options: G9RelativeTimeWithClockOptions): string;
|
|
50
|
+
//# sourceMappingURL=relative-time.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relative-time.d.ts","sourceRoot":"","sources":["../../src/culture/relative-time.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAExD,8FAA8F;AAC9F,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG;IAAE,GAAG,IAAI,MAAM,CAAA;CAAE,CAAC;AAE/C,gDAAgD;AAChD,eAAO,MAAM,kBAAkB;;;;;;;;CAQrB,CAAC;AACX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC;AAE9F,2GAA2G;AAC3G,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAgBD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,mBAAmB,CAYvF;AAWD,mCAAmC;AACnC,MAAM,WAAW,qBAAqB;IACpC,mFAAmF;IACnF,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;IACpB,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,MAAM,CAKnF;AAED,2CAA2C;AAC3C,MAAM,WAAW,8BAA+B,SAAQ,qBAAqB;IAC3E,sHAAsH;IACtH,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,8BAA8B,GAAG,MAAM,CAKpG"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { G9Error } from "../errors.js";
|
|
2
|
+
import { localDateTimeFromEpochMs } from "./calendar.js";
|
|
3
|
+
import { formatLocalDateTime } from "./date-format.js";
|
|
4
|
+
import { G9StringKey } from "./strings.js";
|
|
5
|
+
const G9RelativeTimeUnit = {
|
|
6
|
+
JustNow: 'justNow',
|
|
7
|
+
Minutes: 'minutes',
|
|
8
|
+
Hours: 'hours',
|
|
9
|
+
Days: 'days',
|
|
10
|
+
Weeks: 'weeks',
|
|
11
|
+
Months: 'months',
|
|
12
|
+
Years: 'years'
|
|
13
|
+
};
|
|
14
|
+
const MINUTE = 60000;
|
|
15
|
+
const HOUR = 60 * MINUTE;
|
|
16
|
+
const DAY = 24 * HOUR;
|
|
17
|
+
function instantOf(name, value) {
|
|
18
|
+
if (!Number.isFinite(value)) throw new G9Error('relative-time-invalid', `${name} must be finite epoch ms, got ${value}.`);
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function readNow(now) {
|
|
22
|
+
return instantOf('now', 'number' == typeof now ? now : now.now());
|
|
23
|
+
}
|
|
24
|
+
function getRelativeTimeParts(instantMs, now) {
|
|
25
|
+
const delta = Math.max(0, readNow(now) - instantOf('instantMs', instantMs));
|
|
26
|
+
const at = (unit, count)=>Object.freeze({
|
|
27
|
+
unit,
|
|
28
|
+
count: Math.max(1, Math.floor(count))
|
|
29
|
+
});
|
|
30
|
+
if (delta < MINUTE) return Object.freeze({
|
|
31
|
+
unit: 'justNow',
|
|
32
|
+
count: 0
|
|
33
|
+
});
|
|
34
|
+
if (delta < HOUR) return at('minutes', delta / MINUTE);
|
|
35
|
+
if (delta < DAY) return at('hours', delta / HOUR);
|
|
36
|
+
const days = delta / DAY;
|
|
37
|
+
if (days < 7) return at('days', days);
|
|
38
|
+
if (days < 30) return at('weeks', days / 7);
|
|
39
|
+
if (days < 365) return at('months', days / 30);
|
|
40
|
+
return at('years', days / 365);
|
|
41
|
+
}
|
|
42
|
+
const KEYS = {
|
|
43
|
+
minutes: G9StringKey.TimeAgoMinutesFormat,
|
|
44
|
+
hours: G9StringKey.TimeAgoHoursFormat,
|
|
45
|
+
days: G9StringKey.TimeAgoDaysFormat,
|
|
46
|
+
weeks: G9StringKey.TimeAgoWeeksFormat,
|
|
47
|
+
months: G9StringKey.TimeAgoMonthsFormat,
|
|
48
|
+
years: G9StringKey.TimeAgoYearsFormat
|
|
49
|
+
};
|
|
50
|
+
function formatAgo(instantMs, options) {
|
|
51
|
+
const parts = getRelativeTimeParts(instantMs, options.now);
|
|
52
|
+
return 'justNow' === parts.unit ? options.strings.get(G9StringKey.TimeAgoJustNow) : options.strings.format(KEYS[parts.unit], parts.count);
|
|
53
|
+
}
|
|
54
|
+
function formatAgoWithTime(instantMs, options) {
|
|
55
|
+
const ago = formatAgo(instantMs, options);
|
|
56
|
+
const local = localDateTimeFromEpochMs(instantMs, options.utcOffsetMinutes);
|
|
57
|
+
return `${ago} - ${formatLocalDateTime(local, 'HH:mm', options.strings.culture, {
|
|
58
|
+
calendar: 'gregorian'
|
|
59
|
+
})}`;
|
|
60
|
+
}
|
|
61
|
+
export { G9RelativeTimeUnit, formatAgo, formatAgoWithTime, getRelativeTimeParts };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=relative-time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"culture/relative-time.js","sources":["../../src/culture/relative-time.ts"],"sourcesContent":["import { G9Error } from '../errors';\nimport { localDateTimeFromEpochMs } from './calendar';\nimport { formatLocalDateTime } from './date-format';\nimport { G9StringKey, type G9Strings } from './strings';\n\n/** A clock (the WP01.4 `G9Clock` contract fits) or a fixed instant, in epoch milliseconds. */\nexport type G9Now = number | { now(): number };\n\n/** The unit a relative phrase is written in. */\nexport const G9RelativeTimeUnit = {\n JustNow: 'justNow',\n Minutes: 'minutes',\n Hours: 'hours',\n Days: 'days',\n Weeks: 'weeks',\n Months: 'months',\n Years: 'years',\n} as const;\nexport type G9RelativeTimeUnit = (typeof G9RelativeTimeUnit)[keyof typeof G9RelativeTimeUnit];\n\n/** How long ago an instant was, in the unit the phrase uses. `count` is at least 1 (0 for `'justNow'`). */\nexport interface G9RelativeTimeParts {\n readonly unit: G9RelativeTimeUnit;\n readonly count: number;\n}\n\nconst MINUTE = 60_000;\nconst HOUR = 60 * MINUTE;\nconst DAY = 24 * HOUR;\n\nfunction instantOf(name: string, value: number): number {\n if (!Number.isFinite(value))\n throw new G9Error('relative-time-invalid', `${name} must be finite epoch ms, got ${value}.`);\n return value;\n}\n\nfunction readNow(now: G9Now): number {\n return instantOf('now', typeof now === 'number' ? now : now.now());\n}\n\n/**\n * Buckets an instant against `now` exactly like MAUI `G9RelativeTimeFormatter.FormatAgo`: under a minute is \"just now\";\n * then whole minutes (< 60), hours (< 24), days (< 7), weeks (days / 7, < 30 days), months (days / 30, < 365 days),\n * years (days / 365); counts are truncated and at least 1. A future instant counts as now.\n */\nexport function getRelativeTimeParts(instantMs: number, now: G9Now): G9RelativeTimeParts {\n const delta = Math.max(0, readNow(now) - instantOf('instantMs', instantMs));\n const at = (unit: G9RelativeTimeUnit, count: number) =>\n Object.freeze({ unit, count: Math.max(1, Math.floor(count)) });\n if (delta < MINUTE) return Object.freeze({ unit: 'justNow', count: 0 });\n if (delta < HOUR) return at('minutes', delta / MINUTE);\n if (delta < DAY) return at('hours', delta / HOUR);\n const days = delta / DAY;\n if (days < 7) return at('days', days);\n if (days < 30) return at('weeks', days / 7);\n if (days < 365) return at('months', days / 30);\n return at('years', days / 365);\n}\n\nconst KEYS: Readonly<Record<Exclude<G9RelativeTimeUnit, 'justNow'>, G9StringKey>> = {\n minutes: G9StringKey.TimeAgoMinutesFormat,\n hours: G9StringKey.TimeAgoHoursFormat,\n days: G9StringKey.TimeAgoDaysFormat,\n weeks: G9StringKey.TimeAgoWeeksFormat,\n months: G9StringKey.TimeAgoMonthsFormat,\n years: G9StringKey.TimeAgoYearsFormat,\n};\n\n/** Inputs of {@link formatAgo}. */\nexport interface G9RelativeTimeOptions {\n /** The clock or the current instant. Required: there is no hidden `Date.now()`. */\n readonly now: G9Now;\n /** Strings of the culture to write in (their `culture` supplies the digits). */\n readonly strings: G9Strings;\n}\n\n/**\n * The relative phrase alone, e.g. `'2 d ago'`, `'۲ روز پیش'` (MAUI `G9RelativeTimeFormatter.FormatAgo`). Takes an\n * absolute instant, so a time zone can no longer shift the result (MAUI subtracted a local `DateTime` from UTC now).\n */\nexport function formatAgo(instantMs: number, options: G9RelativeTimeOptions): string {\n const parts = getRelativeTimeParts(instantMs, options.now);\n return parts.unit === 'justNow'\n ? options.strings.get(G9StringKey.TimeAgoJustNow)\n : options.strings.format(KEYS[parts.unit], parts.count);\n}\n\n/** Inputs of {@link formatAgoWithTime}. */\nexport interface G9RelativeTimeWithClockOptions extends G9RelativeTimeOptions {\n /** UTC offset, in minutes, of the wall clock the time is shown in (`210` for Tehran). Required: Lynx has no zones. */\n readonly utcOffsetMinutes: number;\n}\n\n/**\n * The phrase joined with the wall-clock time, e.g. `'6 h ago - 14:19'` (MAUI `FormatAgoWithTime`, the history\n * timeline format). The time is `HH:mm` in the culture's digits at `utcOffsetMinutes`.\n */\nexport function formatAgoWithTime(instantMs: number, options: G9RelativeTimeWithClockOptions): string {\n const ago = formatAgo(instantMs, options);\n const local = localDateTimeFromEpochMs(instantMs, options.utcOffsetMinutes);\n // Gregorian: only the time is written, and it must not depend on the Persian calendar's range.\n return `${ago} - ${formatLocalDateTime(local, 'HH:mm', options.strings.culture, { calendar: 'gregorian' })}`;\n}\n"],"names":["G9RelativeTimeUnit","MINUTE","HOUR","DAY","instantOf","name","value","Number","G9Error","readNow","now","getRelativeTimeParts","instantMs","delta","Math","at","unit","count","Object","days","KEYS","G9StringKey","formatAgo","options","parts","formatAgoWithTime","ago","local","localDateTimeFromEpochMs","formatLocalDateTime"],"mappings":";;;;AASO,MAAMA,qBAAqB;IAChC,SAAS;IACT,SAAS;IACT,OAAO;IACP,MAAM;IACN,OAAO;IACP,QAAQ;IACR,OAAO;AACT;AASA,MAAMC,SAAS;A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E,MAAMC,QAAQb,qBAAqBC,WAAWW,QAAQ,GAAG;IACzD,OAAOC,AAAe,cAAfA,MAAM,IAAI,GACbD,QAAQ,OAAO,CAAC,GAAG,CAACF,YAAY,cAAc,IAC9CE,QAAQ,OAAO,CAAC,MAAM,CAACH,IAAI,CAACI,MAAM,IAAI,CAAC,EAAEA,MAAM,KAAK;AAC1D;AAYO,SAASC,kBAAkBb,SAAiB,EAAEW,OAAuC;IAC1F,MAAMG,MAAMJ,UAAUV,WAAWW;IACjC,MAAMI,QAAQC,yBAAyBhB,WAAWW,QAAQ,gBAAgB;IAE1E,OAAO,GAAGG,IAAI,GAAG,EAAEG,oBAAoBF,OAAO,SAASJ,QAAQ,OAAO,CAAC,OAAO,EAAE;QAAE,UAAU;IAAY,IAAI;AAC9G"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { G9Culture } from './culture.js';
|
|
2
|
+
/**
|
|
3
|
+
* Every string the controls display on their own initiative (MAUI `G9StringKey`). Values are the camelCase member
|
|
4
|
+
* names; {@link g9StringResourceName} gives the MAUI (PascalCase) name a provider is asked for. Keys ending in
|
|
5
|
+
* `Format` are templates with a `{0}` placeholder: a translation must keep it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const G9StringKey: {
|
|
8
|
+
readonly Ok: "ok";
|
|
9
|
+
readonly Cancel: "cancel";
|
|
10
|
+
readonly Save: "save";
|
|
11
|
+
readonly Confirm: "confirm";
|
|
12
|
+
readonly Close: "close";
|
|
13
|
+
readonly Done: "done";
|
|
14
|
+
readonly Back: "back";
|
|
15
|
+
readonly Retry: "retry";
|
|
16
|
+
readonly Skip: "skip";
|
|
17
|
+
readonly MoreDetails: "moreDetails";
|
|
18
|
+
readonly Clear: "clear";
|
|
19
|
+
readonly Reset: "reset";
|
|
20
|
+
readonly Delete: "delete";
|
|
21
|
+
readonly Search: "search";
|
|
22
|
+
readonly NoResults: "noResults";
|
|
23
|
+
readonly Selected: "selected";
|
|
24
|
+
readonly ComingSoon: "comingSoon";
|
|
25
|
+
readonly Loading: "loading";
|
|
26
|
+
readonly SelectDate: "selectDate";
|
|
27
|
+
readonly SelectTime: "selectTime";
|
|
28
|
+
readonly SelectDateTime: "selectDateTime";
|
|
29
|
+
readonly SelectDuration: "selectDuration";
|
|
30
|
+
readonly Today: "today";
|
|
31
|
+
readonly Tomorrow: "tomorrow";
|
|
32
|
+
readonly Yesterday: "yesterday";
|
|
33
|
+
readonly Now: "now";
|
|
34
|
+
readonly Year: "year";
|
|
35
|
+
readonly Month: "month";
|
|
36
|
+
readonly Day: "day";
|
|
37
|
+
readonly Hour: "hour";
|
|
38
|
+
readonly Minute: "minute";
|
|
39
|
+
readonly TimeSpanYearsFormat: "timeSpanYearsFormat";
|
|
40
|
+
readonly TimeSpanMonthsFormat: "timeSpanMonthsFormat";
|
|
41
|
+
readonly TimeSpanDaysFormat: "timeSpanDaysFormat";
|
|
42
|
+
readonly Information: "information";
|
|
43
|
+
readonly Success: "success";
|
|
44
|
+
readonly Warning: "warning";
|
|
45
|
+
readonly Error: "error";
|
|
46
|
+
readonly RequiredSuffix: "requiredSuffix";
|
|
47
|
+
readonly InvalidEmail: "invalidEmail";
|
|
48
|
+
readonly InvalidUrl: "invalidUrl";
|
|
49
|
+
readonly InvalidValue: "invalidValue";
|
|
50
|
+
readonly Scanning: "scanning";
|
|
51
|
+
readonly MicrophonePermissionDenied: "microphonePermissionDenied";
|
|
52
|
+
readonly SpeechRecognitionPermissionDenied: "speechRecognitionPermissionDenied";
|
|
53
|
+
readonly SpeechRecognitionUnavailable: "speechRecognitionUnavailable";
|
|
54
|
+
readonly VoiceRecognitionFailed: "voiceRecognitionFailed";
|
|
55
|
+
readonly PermissionErrorFormat: "permissionErrorFormat";
|
|
56
|
+
readonly TimeAgoJustNow: "timeAgoJustNow";
|
|
57
|
+
readonly TimeAgoMinutesFormat: "timeAgoMinutesFormat";
|
|
58
|
+
readonly TimeAgoHoursFormat: "timeAgoHoursFormat";
|
|
59
|
+
readonly TimeAgoDaysFormat: "timeAgoDaysFormat";
|
|
60
|
+
readonly TimeAgoWeeksFormat: "timeAgoWeeksFormat";
|
|
61
|
+
readonly TimeAgoMonthsFormat: "timeAgoMonthsFormat";
|
|
62
|
+
readonly TimeAgoYearsFormat: "timeAgoYearsFormat";
|
|
63
|
+
readonly Cancelled: "cancelled";
|
|
64
|
+
readonly CancelFinishingStep: "cancelFinishingStep";
|
|
65
|
+
readonly UnexpectedError: "unexpectedError";
|
|
66
|
+
readonly Checked: "checked";
|
|
67
|
+
readonly NotChecked: "notChecked";
|
|
68
|
+
readonly PartiallyChecked: "partiallyChecked";
|
|
69
|
+
};
|
|
70
|
+
export type G9StringKey = (typeof G9StringKey)[keyof typeof G9StringKey];
|
|
71
|
+
/** Every key in MAUI declaration order. */
|
|
72
|
+
export declare const g9StringKeys: readonly G9StringKey[];
|
|
73
|
+
/** The MAUI member name of a key (`'noResults'` → `'NoResults'`): the name a provider or resource catalogue sees. */
|
|
74
|
+
export declare function g9StringResourceName(key: G9StringKey): string;
|
|
75
|
+
/** A complete string table. */
|
|
76
|
+
export type G9StringTable = {
|
|
77
|
+
readonly [K in G9StringKey]: string;
|
|
78
|
+
};
|
|
79
|
+
/** Some strings of a table (overrides, a partial translation). */
|
|
80
|
+
export type G9PartialStringTable = {
|
|
81
|
+
readonly [K in G9StringKey]?: string | undefined;
|
|
82
|
+
};
|
|
83
|
+
/** The built-in English strings (MAUI `G9Strings` defaults; the golden `strings.json`). */
|
|
84
|
+
export declare const g9EnglishStrings: G9StringTable;
|
|
85
|
+
/**
|
|
86
|
+
* Persian translation of every built-in string. Opt-in (pass it in {@link G9StringsOptions.tables}): MAUI shipped
|
|
87
|
+
* English only, so without it a `fa` culture still shows English, exactly as MAUI did.
|
|
88
|
+
*/
|
|
89
|
+
export declare const g9PersianStrings: G9StringTable;
|
|
90
|
+
/**
|
|
91
|
+
* Arabic translation of every built-in string. Opt-in, like {@link g9PersianStrings}. Count templates use one form;
|
|
92
|
+
* apps that need Arabic plural agreement override those keys or supply a provider.
|
|
93
|
+
*/
|
|
94
|
+
export declare const g9ArabicStrings: G9StringTable;
|
|
95
|
+
/** The bundled translations keyed by language: pass as `tables` to localize `fa` and `ar` without a provider. */
|
|
96
|
+
export declare const g9BuiltInStringTables: Readonly<Record<string, G9PartialStringTable>>;
|
|
97
|
+
/**
|
|
98
|
+
* An app resolver (MAUI `G9Strings.UseProvider` / `UseResources`): receives the resource name (`keyPrefix` + the MAUI
|
|
99
|
+
* member name for built-in keys, the caller's own key for {@link G9Strings.resolve}) and the culture. Return
|
|
100
|
+
* `null`/`undefined`/`''` to fall back.
|
|
101
|
+
*/
|
|
102
|
+
export type G9StringProvider = (name: string, culture: G9Culture) => string | null | undefined;
|
|
103
|
+
/** Inputs of {@link createStrings}. */
|
|
104
|
+
export interface G9StringsOptions {
|
|
105
|
+
/** The culture strings are resolved and numbers formatted for (normally the culture store's snapshot). */
|
|
106
|
+
readonly culture: G9Culture;
|
|
107
|
+
/** App resolver, asked first. */
|
|
108
|
+
readonly provider?: G9StringProvider;
|
|
109
|
+
/** Prepended to built-in key names only, never to `resolve` keys (MAUI `UseResources(…, keyPrefix)`). */
|
|
110
|
+
readonly keyPrefix?: string;
|
|
111
|
+
/** Strings replaced in code (MAUI `G9Strings.Override`); used when the provider has no entry. */
|
|
112
|
+
readonly overrides?: G9PartialStringTable;
|
|
113
|
+
/** Translations by language (`{ fa: g9PersianStrings }`, or {@link g9BuiltInStringTables}). */
|
|
114
|
+
readonly tables?: Readonly<Record<string, G9PartialStringTable>>;
|
|
115
|
+
/**
|
|
116
|
+
* Told when the provider throws. The lookup then falls back (MAUI swallowed it so a broken catalogue cannot take
|
|
117
|
+
* a control down mid-render); this is where the app logs it.
|
|
118
|
+
*/
|
|
119
|
+
readonly onProviderError?: (error: unknown, name: string) => void;
|
|
120
|
+
}
|
|
121
|
+
/** Resolved strings for one culture (MAUI `G9Strings`). Immutable: build a new one when an input changes. */
|
|
122
|
+
export interface G9Strings {
|
|
123
|
+
readonly culture: G9Culture;
|
|
124
|
+
/** Text of a key: provider → overrides → the culture's table → built-in English. */
|
|
125
|
+
get(key: G9StringKey): string;
|
|
126
|
+
/**
|
|
127
|
+
* A `Format` key with its `{n}` placeholders filled; numbers are written in the culture's digits and separators,
|
|
128
|
+
* `null`/`undefined` as `''`, `{{`/`}}` are literal braces.
|
|
129
|
+
* @throws {G9Error} `strings-format` for a malformed template, an alignment/format specifier, or a missing argument.
|
|
130
|
+
*/
|
|
131
|
+
format(key: G9StringKey, ...args: ReadonlyArray<string | number | boolean | null | undefined>): string;
|
|
132
|
+
/** An app key resolved through the provider only (no prefix, no fallback); `null` when there is no entry. */
|
|
133
|
+
resolve(name: string): string | null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Fills a .NET composite-format template (`{0}`, `{{`, `}}`). Specifiers (`{0:N2}`, `{0,5}`) are rejected rather than
|
|
137
|
+
* ignored.
|
|
138
|
+
*/
|
|
139
|
+
export declare function formatTemplate(template: string, args: ReadonlyArray<string | number | boolean | null | undefined>, culture: G9Culture): string;
|
|
140
|
+
/**
|
|
141
|
+
* Creates the strings of one culture. Every input is validated now (unknown keys, non-string texts), so a typo fails
|
|
142
|
+
* at startup rather than rendering a raw key.
|
|
143
|
+
*/
|
|
144
|
+
export declare function createStrings(options: G9StringsOptions): G9Strings;
|
|
145
|
+
//# sourceMappingURL=strings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/culture/strings.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;;;GAIG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Dd,CAAC;AACX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WA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