@g9tm/lynxcontrols-foundation 0.0.0-stage → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +41 -0
- package/dist/tokens/css-vars.d.ts.map +1 -0
- package/dist/tokens/css-vars.js +55 -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 +369 -0
- package/docs/foundation.md +370 -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,173 @@
|
|
|
1
|
+
import { G9Error } from "../errors.js";
|
|
2
|
+
import { checkNumberingSystem } from "./digits.js";
|
|
3
|
+
const G9Direction = {
|
|
4
|
+
Ltr: 'ltr',
|
|
5
|
+
Rtl: 'rtl'
|
|
6
|
+
};
|
|
7
|
+
const G9CalendarSystem = {
|
|
8
|
+
Gregorian: 'gregorian',
|
|
9
|
+
Persian: 'persian'
|
|
10
|
+
};
|
|
11
|
+
const RTL_LANGUAGES = new Set([
|
|
12
|
+
'ar',
|
|
13
|
+
'arc',
|
|
14
|
+
'ckb',
|
|
15
|
+
'dv',
|
|
16
|
+
'fa',
|
|
17
|
+
'he',
|
|
18
|
+
'iw',
|
|
19
|
+
'ks',
|
|
20
|
+
'lrc',
|
|
21
|
+
'mzn',
|
|
22
|
+
'prs',
|
|
23
|
+
'ps',
|
|
24
|
+
'sd',
|
|
25
|
+
'syr',
|
|
26
|
+
'ug',
|
|
27
|
+
'ur',
|
|
28
|
+
'yi'
|
|
29
|
+
]);
|
|
30
|
+
const RTL_SCRIPTS = new Set([
|
|
31
|
+
'arab',
|
|
32
|
+
'hebr',
|
|
33
|
+
'thaa',
|
|
34
|
+
'syrc',
|
|
35
|
+
'nkoo',
|
|
36
|
+
'adlm',
|
|
37
|
+
'mand',
|
|
38
|
+
'samr',
|
|
39
|
+
'rohg'
|
|
40
|
+
]);
|
|
41
|
+
const LOCALE = /^[A-Za-z]{2,8}(-[A-Za-z0-9]{1,8})*$/;
|
|
42
|
+
function parseLocale(locale) {
|
|
43
|
+
if ('' === locale) return {
|
|
44
|
+
language: '',
|
|
45
|
+
script: void 0
|
|
46
|
+
};
|
|
47
|
+
if ('string' != typeof locale || !LOCALE.test(locale)) throw new G9Error('culture-invalid-locale', `"${String(locale)}" is not a BCP 47 locale tag.`);
|
|
48
|
+
const parts = locale.toLowerCase().split('-');
|
|
49
|
+
const script = parts.slice(1).find((part)=>/^[a-z]{4}$/.test(part));
|
|
50
|
+
return {
|
|
51
|
+
language: parts[0],
|
|
52
|
+
script
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const DIRECTIONS = [
|
|
56
|
+
'ltr',
|
|
57
|
+
'rtl'
|
|
58
|
+
];
|
|
59
|
+
const CALENDARS = [
|
|
60
|
+
'gregorian',
|
|
61
|
+
'persian'
|
|
62
|
+
];
|
|
63
|
+
function checkOption(kind, value) {
|
|
64
|
+
if (!('direction' === kind ? DIRECTIONS : CALENDARS).includes(value)) throw new G9Error(`culture-invalid-${kind}`, `"${value}" is not a culture ${kind}.`);
|
|
65
|
+
}
|
|
66
|
+
function checkFont(name, value) {
|
|
67
|
+
if (null != value && 'string' != typeof value) throw new G9Error('culture-invalid-font', `${name} must be a string.`);
|
|
68
|
+
}
|
|
69
|
+
function createCulture(locale, options = {}) {
|
|
70
|
+
var _options_direction, _options_calendar, _options_numberingSystem;
|
|
71
|
+
const { language, script } = parseLocale(locale);
|
|
72
|
+
const rtl = script ? RTL_SCRIPTS.has(script) : RTL_LANGUAGES.has(language);
|
|
73
|
+
const direction = null != (_options_direction = options.direction) ? _options_direction : rtl ? 'rtl' : 'ltr';
|
|
74
|
+
const calendar = null != (_options_calendar = options.calendar) ? _options_calendar : 'fa' === language ? 'persian' : 'gregorian';
|
|
75
|
+
const numberingSystem = null != (_options_numberingSystem = options.numberingSystem) ? _options_numberingSystem : 'fa' === language ? 'persian' : 'ar' === language ? 'arabicIndic' : 'latin';
|
|
76
|
+
checkOption('direction', direction);
|
|
77
|
+
checkOption('calendar', calendar);
|
|
78
|
+
checkNumberingSystem(numberingSystem);
|
|
79
|
+
checkFont('rtlFontFamily', options.rtlFontFamily);
|
|
80
|
+
checkFont('ltrFontFamily', options.ltrFontFamily);
|
|
81
|
+
return Object.freeze({
|
|
82
|
+
locale,
|
|
83
|
+
language,
|
|
84
|
+
direction,
|
|
85
|
+
calendar,
|
|
86
|
+
numberingSystem,
|
|
87
|
+
...'string' == typeof options.rtlFontFamily ? {
|
|
88
|
+
rtlFontFamily: options.rtlFontFamily
|
|
89
|
+
} : {},
|
|
90
|
+
...'string' == typeof options.ltrFontFamily ? {
|
|
91
|
+
ltrFontFamily: options.ltrFontFamily
|
|
92
|
+
} : {}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function withCultureOptions(culture, options) {
|
|
96
|
+
const pick = (key)=>void 0 !== options[key] ? options[key] : culture[key];
|
|
97
|
+
return createCulture(culture.locale, {
|
|
98
|
+
direction: pick('direction'),
|
|
99
|
+
calendar: pick('calendar'),
|
|
100
|
+
numberingSystem: pick('numberingSystem'),
|
|
101
|
+
rtlFontFamily: pick('rtlFontFamily'),
|
|
102
|
+
ltrFontFamily: pick('ltrFontFamily')
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function languageOf(culture) {
|
|
106
|
+
if (null == culture) return '';
|
|
107
|
+
return 'string' == typeof culture ? parseLocale(culture).language : culture.language;
|
|
108
|
+
}
|
|
109
|
+
function isPersianLanguage(culture) {
|
|
110
|
+
return 'fa' === languageOf(culture);
|
|
111
|
+
}
|
|
112
|
+
function isRtl(culture) {
|
|
113
|
+
return 'rtl' === culture.direction;
|
|
114
|
+
}
|
|
115
|
+
function resolveFontFamily(culture, explicitFontFamily) {
|
|
116
|
+
if (null == explicitFontFamily ? void 0 : explicitFontFamily.trim()) return explicitFontFamily;
|
|
117
|
+
return isRtl(culture) ? culture.rtlFontFamily : culture.ltrFontFamily;
|
|
118
|
+
}
|
|
119
|
+
function sameCulture(a, b) {
|
|
120
|
+
return a.locale === b.locale && a.direction === b.direction && a.calendar === b.calendar && a.numberingSystem === b.numberingSystem && a.rtlFontFamily === b.rtlFontFamily && a.ltrFontFamily === b.ltrFontFamily;
|
|
121
|
+
}
|
|
122
|
+
function createCultureStore(initial) {
|
|
123
|
+
const toCulture = (value)=>'string' == typeof value ? createCulture(value) : withCultureOptions(value, {});
|
|
124
|
+
let snapshot = toCulture(initial);
|
|
125
|
+
let notified = snapshot;
|
|
126
|
+
let notifying = false;
|
|
127
|
+
const listeners = new Set();
|
|
128
|
+
function flush() {
|
|
129
|
+
if (notifying) return;
|
|
130
|
+
notifying = true;
|
|
131
|
+
let failed = false;
|
|
132
|
+
let failure;
|
|
133
|
+
try {
|
|
134
|
+
while(notified !== snapshot){
|
|
135
|
+
const current = snapshot;
|
|
136
|
+
notified = current;
|
|
137
|
+
for (const listener of Array.from(listeners))if (listeners.has(listener)) try {
|
|
138
|
+
listener(current);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (!failed) {
|
|
141
|
+
failed = true;
|
|
142
|
+
failure = error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} finally{
|
|
147
|
+
notifying = false;
|
|
148
|
+
}
|
|
149
|
+
if (failed) throw failure;
|
|
150
|
+
}
|
|
151
|
+
function commit(next) {
|
|
152
|
+
if (!sameCulture(next, snapshot)) snapshot = next;
|
|
153
|
+
flush();
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
getSnapshot: ()=>snapshot,
|
|
157
|
+
subscribe (listener) {
|
|
158
|
+
listeners.add(listener);
|
|
159
|
+
return ()=>{
|
|
160
|
+
listeners.delete(listener);
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
setCulture (culture) {
|
|
164
|
+
commit(toCulture(culture));
|
|
165
|
+
},
|
|
166
|
+
update (options) {
|
|
167
|
+
commit(withCultureOptions(snapshot, options));
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
export { G9CalendarSystem, G9Direction, createCulture, createCultureStore, isPersianLanguage, isRtl, languageOf, resolveFontFamily, sameCulture, withCultureOptions };
|
|
172
|
+
|
|
173
|
+
//# sourceMappingURL=culture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"culture/culture.js","sources":["../../src/culture/culture.ts"],"sourcesContent":["import { G9Error } from '../errors';\nimport { checkNumberingSystem, type G9NumberingSystem } from './digits';\n\n/** Reading direction (MAUI `G9Culture.IsRtl`). */\nexport const G9Direction = { Ltr: 'ltr', Rtl: 'rtl' } as const;\nexport type G9Direction = (typeof G9Direction)[keyof typeof G9Direction];\n\n/** Calendar dates are shown in. Only Persian (Jalali) and Gregorian are supported, as in MAUI. */\nexport const G9CalendarSystem = { Gregorian: 'gregorian', Persian: 'persian' } as const;\nexport type G9CalendarSystem = (typeof G9CalendarSystem)[keyof typeof G9CalendarSystem];\n\n/**\n * An immutable culture value: what MAUI read from `CultureInfo` plus the `G9Culture` facade, as independent settings\n * (plan/specs/01-Architecture.md §7). Create with {@link createCulture}; frozen.\n */\nexport interface G9Culture {\n /** BCP 47 tag as given (`'fa-IR'`, `'en-US'`); `''` is the invariant culture. */\n readonly locale: string;\n /** Lower-case language subtag (`'fa'`); `''` for the invariant culture. */\n readonly language: string;\n readonly direction: G9Direction;\n readonly calendar: G9CalendarSystem;\n readonly numberingSystem: G9NumberingSystem;\n /** Font family for right-to-left text (MAUI `G9Culture.RtlFontFamily`); `undefined` lets the platform choose. */\n readonly rtlFontFamily?: string;\n /** Font family for left-to-right text (MAUI `G9Culture.LtrFontFamily`); `undefined` lets the platform choose. */\n readonly ltrFontFamily?: string;\n}\n\n/** Settings that override what the locale implies. `undefined` keeps the locale default. */\nexport interface G9CultureOptions {\n readonly direction?: G9Direction | undefined;\n readonly calendar?: G9CalendarSystem | undefined;\n readonly numberingSystem?: G9NumberingSystem | undefined;\n /** `null` clears the family (platform default). */\n readonly rtlFontFamily?: string | null | undefined;\n /** `null` clears the family (platform default). */\n readonly ltrFontFamily?: string | null | undefined;\n}\n\n// Languages ICU reports as right-to-left (`TextInfo.IsRightToLeft` in MAUI) when no script subtag says otherwise.\nconst RTL_LANGUAGES = new Set([\n 'ar',\n 'arc',\n 'ckb',\n 'dv',\n 'fa',\n 'he',\n 'iw',\n 'ks',\n 'lrc',\n 'mzn',\n 'prs',\n 'ps',\n 'sd',\n 'syr',\n 'ug',\n 'ur',\n 'yi',\n]);\nconst RTL_SCRIPTS = new Set(['arab', 'hebr', 'thaa', 'syrc', 'nkoo', 'adlm', 'mand', 'samr', 'rohg']);\nconst LOCALE = /^[A-Za-z]{2,8}(-[A-Za-z0-9]{1,8})*$/;\n\n/** @throws {G9Error} `culture-invalid-locale` for a tag that is not BCP 47 shaped (`'fa-IR'`, `'zh-Hant-TW'`). */\nfunction parseLocale(locale: string): { language: string; script: string | undefined } {\n if (locale === '') return { language: '', script: undefined };\n if (typeof locale !== 'string' || !LOCALE.test(locale)) {\n throw new G9Error('culture-invalid-locale', `\"${String(locale)}\" is not a BCP 47 locale tag.`);\n }\n const parts = locale.toLowerCase().split('-');\n const script = parts.slice(1).find((part) => /^[a-z]{4}$/.test(part));\n return { language: parts[0] as string, script };\n}\n\nconst DIRECTIONS: readonly string[] = ['ltr', 'rtl'];\nconst CALENDARS: readonly string[] = ['gregorian', 'persian'];\n\nfunction checkOption(kind: 'direction' | 'calendar', value: string): void {\n if (!(kind === 'direction' ? DIRECTIONS : CALENDARS).includes(value)) {\n throw new G9Error(`culture-invalid-${kind}`, `\"${value}\" is not a culture ${kind}.`);\n }\n}\n\nfunction checkFont(name: string, value: string | null | undefined): void {\n if (value !== undefined && value !== null && typeof value !== 'string') {\n throw new G9Error('culture-invalid-font', `${name} must be a string.`);\n }\n}\n\n/**\n * Builds a culture value. Defaults follow the language, never the direction alone: `fa*` → Persian calendar, Persian\n * digits, RTL; `ar*` → Gregorian, Arabic-Indic digits, RTL; other RTL languages (he, ur, …) and scripts (`-Arab`) →\n * RTL with Gregorian and Latin digits; everything else LTR, Gregorian, Latin. `options` override any of these.\n * @throws {G9Error} `culture-invalid-locale` / `-direction` / `-calendar` / `-numbering-system` / `-font`.\n */\nexport function createCulture(locale: string, options: G9CultureOptions = {}): G9Culture {\n const { language, script } = parseLocale(locale);\n const rtl = script ? RTL_SCRIPTS.has(script) : RTL_LANGUAGES.has(language);\n const direction = options.direction ?? (rtl ? 'rtl' : 'ltr');\n const calendar = options.calendar ?? (language === 'fa' ? 'persian' : 'gregorian');\n const numberingSystem =\n options.numberingSystem ?? (language === 'fa' ? 'persian' : language === 'ar' ? 'arabicIndic' : 'latin');\n checkOption('direction', direction);\n checkOption('calendar', calendar);\n checkNumberingSystem(numberingSystem);\n checkFont('rtlFontFamily', options.rtlFontFamily);\n checkFont('ltrFontFamily', options.ltrFontFamily);\n return Object.freeze({\n locale,\n language,\n direction,\n calendar,\n numberingSystem,\n ...(typeof options.rtlFontFamily === 'string' ? { rtlFontFamily: options.rtlFontFamily } : {}),\n ...(typeof options.ltrFontFamily === 'string' ? { ltrFontFamily: options.ltrFontFamily } : {}),\n });\n}\n\n/** The same culture with some settings replaced (`undefined` in `options` keeps the current value). */\nexport function withCultureOptions(culture: G9Culture, options: G9CultureOptions): G9Culture {\n const pick = <K extends keyof G9CultureOptions>(key: K) => (options[key] !== undefined ? options[key] : culture[key]);\n return createCulture(culture.locale, {\n direction: pick('direction'),\n calendar: pick('calendar'),\n numberingSystem: pick('numberingSystem'),\n rtlFontFamily: pick('rtlFontFamily'),\n ltrFontFamily: pick('ltrFontFamily'),\n });\n}\n\n/** Lower-case language subtag of a culture or locale tag; `''` for `null`, `undefined` and the invariant culture. */\nexport function languageOf(culture: G9Culture | string | null | undefined): string {\n if (culture === null || culture === undefined) return '';\n return typeof culture === 'string' ? parseLocale(culture).language : culture.language;\n}\n\n/**\n * `true` when the language is Persian (`fa`, any region), the test MAUI uses to show Jalali dates\n * (`G9Calendar.IsPersianLanguage`). Dari (`prs`), Pashto, Arabic and the invariant culture are `false`.\n */\nexport function isPersianLanguage(culture: G9Culture | string | null | undefined): boolean {\n return languageOf(culture) === 'fa';\n}\n\n/** `true` when the culture reads right-to-left (MAUI `G9Culture.IsRtl`, `G9Visuals.IsRtl`). */\nexport function isRtl(culture: G9Culture): boolean {\n return culture.direction === 'rtl';\n}\n\n/**\n * The font family text should use now (MAUI `G9Culture.ResolveFontFamily`, `G9Visuals.ResolveCulturalFont`): a\n * non-blank `explicitFontFamily` always wins, otherwise the culture's RTL or LTR family. `undefined` means \"platform\n * default\".\n */\nexport function resolveFontFamily(culture: G9Culture, explicitFontFamily?: string | null): string | undefined {\n if (explicitFontFamily?.trim()) return explicitFontFamily;\n return isRtl(culture) ? culture.rtlFontFamily : culture.ltrFontFamily;\n}\n\n/** Field-by-field equality of two culture values. */\nexport function sameCulture(a: G9Culture, b: G9Culture): boolean {\n return (\n a.locale === b.locale &&\n a.direction === b.direction &&\n a.calendar === b.calendar &&\n a.numberingSystem === b.numberingSystem &&\n a.rtlFontFamily === b.rtlFontFamily &&\n a.ltrFontFamily === b.ltrFontFamily\n );\n}\n\n/** Listener of {@link G9CultureStore}: receives the snapshot taken when the change was notified. */\nexport type G9CultureListener = (culture: G9Culture) => void;\n\n/**\n * The app's active culture (MAUI `G9Culture` facade + `CultureChanged`): one frozen snapshot, replaced on each change;\n * listeners are told once per change. Works with `useSyncExternalStore` (`subscribe` / `getSnapshot`). The React\n * provider (WP02) owns one.\n */\nexport interface G9CultureStore {\n /** The current culture (MAUI `CurrentCulture`); the same object until something changes. */\n getSnapshot(): G9Culture;\n /** Adds a listener; returns its unsubscribe function. */\n subscribe(listener: G9CultureListener): () => void;\n /** Switch culture (a value, or a locale tag with its defaults). Notifies only when something changed. */\n setCulture(culture: G9Culture | string): void;\n /** Replace some settings of the current culture (direction, calendar, digits, fonts); notifies once if changed. */\n update(options: G9CultureOptions): void;\n}\n\n/**\n * Creates a {@link G9CultureStore}. Notification follows MAUI `NotifyChanged`: each listener receives the snapshot of\n * the change being reported, even if a listener switches the culture again (that switch is reported afterwards, in a\n * new round, with its own snapshot). Every listener runs even if one throws; the first error is rethrown afterwards.\n * An invalid culture throws before anything changes.\n */\nexport function createCultureStore(initial: G9Culture | string): G9CultureStore {\n // A culture value built by hand (not by createCulture) is validated and normalised the same way.\n const toCulture = (value: G9Culture | string) =>\n typeof value === 'string' ? createCulture(value) : withCultureOptions(value, {});\n let snapshot = toCulture(initial);\n let notified = snapshot;\n let notifying = false;\n const listeners = new Set<G9CultureListener>();\n\n function flush(): void {\n if (notifying) return;\n notifying = true;\n let failed = false;\n let failure: unknown;\n try {\n while (notified !== snapshot) {\n const current = snapshot;\n notified = current;\n for (const listener of Array.from(listeners)) {\n if (!listeners.has(listener)) continue;\n try {\n listener(current);\n } catch (error) {\n if (!failed) {\n failed = true;\n failure = error;\n }\n }\n }\n }\n } finally {\n notifying = false;\n }\n if (failed) throw failure;\n }\n\n function commit(next: G9Culture): void {\n if (!sameCulture(next, snapshot)) snapshot = next;\n flush();\n }\n\n return {\n getSnapshot: () => snapshot,\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n setCulture(culture) {\n commit(toCulture(culture));\n },\n update(options) {\n commit(withCultureOptions(snapshot, options));\n },\n };\n}\n"],"names":["G9Direction","G9CalendarSystem","RTL_LANGUAGES","Set","RTL_SCRIPTS","LOCALE","parseLocale","locale","undefined","G9Error","String","parts","script","part","DIRECTIONS","CALENDARS","checkOption","kind","value","checkFont","name","createCulture","options","_options_direction","_options_calendar","_options_numberingSystem","language","rtl","direction","calendar","numberingSystem","checkNumberingSystem","Object","withCultureOptions","culture","pick","key","languageOf","isPersianLanguage","isRtl","resolveFontFamily","explicitFontFamily","sameCulture","a","b","createCultureStore","initial","toCulture","snapshot","notified","notifying","listeners","flush","failed","failure","current","listener","Array","error","commit","next"],"mappings":";;AAIO,MAAMA,cAAc;IAAE,KAAK;IAAO,KAAK;AAAM;AAI7C,MAAMC,mBAAmB;IAAE,WAAW;IAAa,SAAS;AAAU;AAiC7E,MAAMC,gBAAgB,IAAIC,IAAI;IAC5B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AACD,MAAMC,cAAc,IAAID,IAAI;IAAC;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;CAAO;AACpG,MAAME,SAAS;AAGf,SAASC,YAAYC,MAAc;IACjC,IAAIA,AAAW,OAAXA,QAAe,OAAO;QAAE,UAAU;QAAI,QAAQC;IAAU;IAC5D,IAAI,AAAkB,YAAlB,OAAOD,UAAuB,CAACF,OAAO,IAAI,CAACE,SAC7C,MAAM,IAAIE,QAAQ,0BAA0B,CAAC,CAAC,EAAEC,OAAOH,QAAQ,6BAA6B,CAAC;IAE/F,MAAMI,QAAQJ,OAAO,WAAW,GAAG,KAAK,CAAC;IACzC,MAAMK,SAASD,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,CAACE,OAAS,aAAa,IAAI,CAACA;IAC/D,OAAO;QAAE,UAAUF,KAAK,CAAC,EAAE;QAAYC;IAAO;AAChD;AAEA,MAAME,aAAgC;I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a,IACnCD,EAAE,aAAa,KAAKC,EAAE,aAAa;AAEvC;AA2BO,SAASC,mBAAmBC,OAA2B;IAE5D,MAAMC,YAAY,CAAC7B,QACjB,AAAiB,YAAjB,OAAOA,QAAqBG,cAAcH,SAASe,mBAAmBf,OAAO,CAAC;IAChF,IAAI8B,WAAWD,UAAUD;IACzB,IAAIG,WAAWD;IACf,IAAIE,YAAY;IAChB,MAAMC,YAAY,IAAIhD;IAEtB,SAASiD;QACP,IAAIF,WAAW;QACfA,YAAY;QACZ,IAAIG,SAAS;QACb,IAAIC;QACJ,IAAI;YACF,MAAOL,aAAaD,SAAU;gBAC5B,MAAMO,UAAUP;gBAChBC,WAAWM;gBACX,KAAK,MAAMC,YAAYC,MAAM,IAAI,CAACN,WAChC,IAAKA,UAAU,GAAG,CAACK,WACnB,IAAI;oBACFA,SAASD;gBACX,EAAE,OAAOG,OAAO;oBACd,IAAI,CAACL,QAAQ;wBACXA,SAAS;wBACTC,UAAUI;oBACZ;gBACF;YAEJ;QACF,SAAU;YACRR,YAAY;QACd;QACA,IAAIG,QAAQ,MAAMC;IACpB;IAEA,SAASK,OAAOC,IAAe;QAC7B,IAAI,CAAClB,YAAYkB,MAAMZ,WAAWA,WAAWY;QAC7CR;IACF;IAEA,OAAO;QACL,aAAa,IAAMJ;QACnB,WAAUQ,QAAQ;YAChBL,UAAU,GAAG,CAACK;YACd,OAAO;gBACLL,UAAU,MAAM,CAACK;YACnB;QACF;QACA,YAAWtB,OAAO;YAChByB,OAAOZ,UAAUb;QACnB;QACA,QAAOZ,OAAO;YACZqC,OAAO1B,mBAAmBe,UAAU1B;QACtC;IACF;AACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type G9LocalDate } from './calendar.js';
|
|
2
|
+
import type { G9CalendarSystem, G9Culture } from './culture.js';
|
|
3
|
+
import { type G9NumberingSystem } from './digits.js';
|
|
4
|
+
/** Options of {@link formatLocalDateTime}. */
|
|
5
|
+
export interface G9DateFormatOptions {
|
|
6
|
+
/** Calendar the date is written in. Default `culture.calendar`. Pass `'gregorian'` for MAUI `GetGregorianFormatCulture`. */
|
|
7
|
+
readonly calendar?: G9CalendarSystem;
|
|
8
|
+
/** Digits. Default `culture.numberingSystem`. */
|
|
9
|
+
readonly numberingSystem?: G9NumberingSystem;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Writes a date or date-time with a .NET-style custom pattern, without Intl: `yyyy yy y`, `MMMM MMM MM M`,
|
|
13
|
+
* `dddd ddd dd d`, `HH H hh h`, `mm m`, `ss s`, `fff ff f`, `tt t`; `'quoted'`/`"quoted"` text and `\x` are literal;
|
|
14
|
+
* other non-letters (`/ : . - space`) are written as is. Names and AM/PM come from the culture's language (fa/ar/en);
|
|
15
|
+
* digits from its numbering system. A date without time formats as midnight.
|
|
16
|
+
* @throws {G9Error} `date-format-unsupported` for any other letter (`z`, `K`, `g`, …): quote literal text.
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatLocalDateTime(value: G9LocalDate, pattern: string, culture: G9Culture, options?: G9DateFormatOptions): string;
|
|
19
|
+
//# sourceMappingURL=date-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-format.d.ts","sourceRoot":"","sources":["../../src/culture/date-format.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,WAAW,EAMjB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,KAAK,iBAAiB,EAAkB,MAAM,UAAU,CAAC;AAElE,8CAA8C;AAC9C,MAAM,WAAW,mBAAmB;IAClC,4HAA4H;IAC5H,QAAQ,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IACrC,iDAAiD;IACjD,QAAQ,CAAC,eAAe,CAAC,EAAE,iBAAiB,CAAC;CAC9C;AAUD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,SAAS,EAClB,OAAO,GAAE,mBAAwB,GAChC,MAAM,CA4ER"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { G9Error } from "../errors.js";
|
|
2
|
+
import { dayOfWeek, getMonthName, getWeekdayNames, toCalendarDate, toLocalDate } from "./calendar.js";
|
|
3
|
+
import { toNativeDigits } from "./digits.js";
|
|
4
|
+
const DESIGNATORS = {
|
|
5
|
+
en: [
|
|
6
|
+
'AM',
|
|
7
|
+
'PM'
|
|
8
|
+
],
|
|
9
|
+
fa: [
|
|
10
|
+
'ق.ظ',
|
|
11
|
+
'ب.ظ'
|
|
12
|
+
],
|
|
13
|
+
ar: [
|
|
14
|
+
'ص',
|
|
15
|
+
'م'
|
|
16
|
+
]
|
|
17
|
+
};
|
|
18
|
+
const pad = (value, width)=>String(value).padStart(width, '0');
|
|
19
|
+
function formatLocalDateTime(value, pattern, culture, options = {}) {
|
|
20
|
+
var _options_calendar, _time_hour, _time_minute, _time_second, _time_millisecond, _DESIGNATORS_culture_language;
|
|
21
|
+
const calendar = null != (_options_calendar = options.calendar) ? _options_calendar : culture.calendar;
|
|
22
|
+
const date = toLocalDate(value);
|
|
23
|
+
const view = toCalendarDate(date, calendar);
|
|
24
|
+
const time = value;
|
|
25
|
+
const hour = null != (_time_hour = time.hour) ? _time_hour : 0;
|
|
26
|
+
const minute = null != (_time_minute = time.minute) ? _time_minute : 0;
|
|
27
|
+
const second = null != (_time_second = time.second) ? _time_second : 0;
|
|
28
|
+
const millisecond = null != (_time_millisecond = time.millisecond) ? _time_millisecond : 0;
|
|
29
|
+
const designators = null != (_DESIGNATORS_culture_language = DESIGNATORS[culture.language]) ? _DESIGNATORS_culture_language : DESIGNATORS.en;
|
|
30
|
+
const hour12 = hour % 12 === 0 ? 12 : hour % 12;
|
|
31
|
+
let out = '';
|
|
32
|
+
let i = 0;
|
|
33
|
+
const numeric = (text)=>{
|
|
34
|
+
var _options_numberingSystem;
|
|
35
|
+
out += toNativeDigits(text, null != (_options_numberingSystem = options.numberingSystem) ? _options_numberingSystem : culture.numberingSystem);
|
|
36
|
+
};
|
|
37
|
+
while(i < pattern.length){
|
|
38
|
+
const ch = pattern.charAt(i);
|
|
39
|
+
if ("'" === ch || '"' === ch) {
|
|
40
|
+
const end = pattern.indexOf(ch, i + 1);
|
|
41
|
+
if (end < 0) throw new G9Error('date-format-unsupported', `Unclosed quote in "${pattern}".`);
|
|
42
|
+
out += pattern.slice(i + 1, end);
|
|
43
|
+
i = end + 1;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if ('\\' === ch) {
|
|
47
|
+
out += pattern.charAt(i + 1);
|
|
48
|
+
i += 2;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (!/[A-Za-z]/.test(ch)) {
|
|
52
|
+
out += ch;
|
|
53
|
+
i += 1;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
let n = 1;
|
|
57
|
+
while(pattern.charAt(i + n) === ch)n += 1;
|
|
58
|
+
i += n;
|
|
59
|
+
switch(ch){
|
|
60
|
+
case 'y':
|
|
61
|
+
numeric(1 === n ? String(view.year % 100) : 2 === n ? pad(view.year % 100, 2) : pad(view.year, n));
|
|
62
|
+
break;
|
|
63
|
+
case 'M':
|
|
64
|
+
if (n >= 3) out += getMonthName(calendar, view.month, culture, 3 === n ? 'abbreviated' : 'wide');
|
|
65
|
+
else numeric(pad(view.month, n));
|
|
66
|
+
break;
|
|
67
|
+
case 'd':
|
|
68
|
+
if (n >= 3) out += getWeekdayNames(culture, 3 === n ? 'abbreviated' : 'wide')[dayOfWeek(date)];
|
|
69
|
+
else numeric(pad(view.day, n));
|
|
70
|
+
break;
|
|
71
|
+
case 'H':
|
|
72
|
+
numeric(pad(hour, Math.min(n, 2)));
|
|
73
|
+
break;
|
|
74
|
+
case 'h':
|
|
75
|
+
numeric(pad(hour12, Math.min(n, 2)));
|
|
76
|
+
break;
|
|
77
|
+
case 'm':
|
|
78
|
+
numeric(pad(minute, Math.min(n, 2)));
|
|
79
|
+
break;
|
|
80
|
+
case 's':
|
|
81
|
+
numeric(pad(second, Math.min(n, 2)));
|
|
82
|
+
break;
|
|
83
|
+
case 'f':
|
|
84
|
+
if (n > 3) throw new G9Error('date-format-unsupported', 'Fractions finer than a millisecond are not kept.');
|
|
85
|
+
numeric(pad(millisecond, 3).slice(0, n));
|
|
86
|
+
break;
|
|
87
|
+
case 't':
|
|
88
|
+
{
|
|
89
|
+
const designator = designators[hour < 12 ? 0 : 1];
|
|
90
|
+
out += 1 === n ? designator.charAt(0) : designator;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
default:
|
|
94
|
+
throw new G9Error('date-format-unsupported', `"${ch}" is not a supported pattern letter; quote literal text.`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
export { formatLocalDateTime };
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=date-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"culture/date-format.js","sources":["../../src/culture/date-format.ts"],"sourcesContent":["import { G9Error } from '../errors';\nimport {\n dayOfWeek,\n type G9LocalDate,\n type G9LocalDateTime,\n getMonthName,\n getWeekdayNames,\n toCalendarDate,\n toLocalDate,\n} from './calendar';\nimport type { G9CalendarSystem, G9Culture } from './culture';\nimport { type G9NumberingSystem, toNativeDigits } from './digits';\n\n/** Options of {@link formatLocalDateTime}. */\nexport interface G9DateFormatOptions {\n /** Calendar the date is written in. Default `culture.calendar`. Pass `'gregorian'` for MAUI `GetGregorianFormatCulture`. */\n readonly calendar?: G9CalendarSystem;\n /** Digits. Default `culture.numberingSystem`. */\n readonly numberingSystem?: G9NumberingSystem;\n}\n\nconst DESIGNATORS: Readonly<Record<string, readonly [string, string]>> = {\n en: ['AM', 'PM'],\n fa: ['ق.ظ', 'ب.ظ'],\n ar: ['ص', 'م'],\n};\n\nconst pad = (value: number, width: number) => String(value).padStart(width, '0');\n\n/**\n * Writes a date or date-time with a .NET-style custom pattern, without Intl: `yyyy yy y`, `MMMM MMM MM M`,\n * `dddd ddd dd d`, `HH H hh h`, `mm m`, `ss s`, `fff ff f`, `tt t`; `'quoted'`/`\"quoted\"` text and `\\x` are literal;\n * other non-letters (`/ : . - space`) are written as is. Names and AM/PM come from the culture's language (fa/ar/en);\n * digits from its numbering system. A date without time formats as midnight.\n * @throws {G9Error} `date-format-unsupported` for any other letter (`z`, `K`, `g`, …): quote literal text.\n */\nexport function formatLocalDateTime(\n value: G9LocalDate,\n pattern: string,\n culture: G9Culture,\n options: G9DateFormatOptions = {},\n): string {\n const calendar = options.calendar ?? culture.calendar;\n const date = toLocalDate(value);\n const view = toCalendarDate(date, calendar);\n const time = value as Partial<G9LocalDateTime>;\n const hour = time.hour ?? 0;\n const minute = time.minute ?? 0;\n const second = time.second ?? 0;\n const millisecond = time.millisecond ?? 0;\n const designators = DESIGNATORS[culture.language] ?? (DESIGNATORS.en as readonly [string, string]);\n const hour12 = hour % 12 === 0 ? 12 : hour % 12;\n let out = '';\n let i = 0;\n const numeric = (text: string) => {\n out += toNativeDigits(text, options.numberingSystem ?? culture.numberingSystem);\n };\n while (i < pattern.length) {\n const ch = pattern.charAt(i);\n if (ch === \"'\" || ch === '\"') {\n const end = pattern.indexOf(ch, i + 1);\n if (end < 0) throw new G9Error('date-format-unsupported', `Unclosed quote in \"${pattern}\".`);\n out += pattern.slice(i + 1, end);\n i = end + 1;\n continue;\n }\n if (ch === '\\\\') {\n out += pattern.charAt(i + 1);\n i += 2;\n continue;\n }\n if (!/[A-Za-z]/.test(ch)) {\n out += ch;\n i += 1;\n continue;\n }\n let n = 1;\n while (pattern.charAt(i + n) === ch) n += 1;\n i += n;\n switch (ch) {\n case 'y':\n numeric(n === 1 ? String(view.year % 100) : n === 2 ? pad(view.year % 100, 2) : pad(view.year, n));\n break;\n case 'M':\n if (n >= 3) out += getMonthName(calendar, view.month, culture, n === 3 ? 'abbreviated' : 'wide');\n else numeric(pad(view.month, n));\n break;\n case 'd':\n if (n >= 3) out += getWeekdayNames(culture, n === 3 ? 'abbreviated' : 'wide')[dayOfWeek(date)];\n else numeric(pad(view.day, n));\n break;\n case 'H':\n numeric(pad(hour, Math.min(n, 2)));\n break;\n case 'h':\n numeric(pad(hour12, Math.min(n, 2)));\n break;\n case 'm':\n numeric(pad(minute, Math.min(n, 2)));\n break;\n case 's':\n numeric(pad(second, Math.min(n, 2)));\n break;\n case 'f':\n if (n > 3) throw new G9Error('date-format-unsupported', 'Fractions finer than a millisecond are not kept.');\n numeric(pad(millisecond, 3).slice(0, n));\n break;\n case 't': {\n const designator = designators[hour < 12 ? 0 : 1];\n out += n === 1 ? designator.charAt(0) : designator;\n break;\n }\n default:\n throw new G9Error('date-format-unsupported', `\"${ch}\" is not a supported pattern letter; quote literal text.`);\n }\n }\n return out;\n}\n"],"names":["DESIGNATORS","pad","value","width","String","formatLocalDateTime","pattern","culture","options","_options_calendar","_time_hour","_time_minute","_time_second","_time_millisecond","_DESIGNATORS_culture_language","calendar","date","toLocalDate","view","toCalendarDate","time","hour","minute","second","millisecond","designators","hour12","out","i","numeric","text","_options_numberingSystem","toNativeDigits","ch","end","G9Error","n","getMonthName","getWeekdayNames","dayOfWeek","Math","designator"],"mappings":";;;AAqBA,MAAMA,cAAmE;IACvE,IAAI;QAAC;QAAM;KAAK;IAChB,IAAI;QAAC;QAAO;KAAM;IAClB,IAAI;QAAC;QAAK;KAAI;AAChB;AAEA,MAAMC,MAAM,CAACC,OAAeC,QAAkBC,OAAOF,OAAO,QAAQ,CAACC,OAAO;AASrE,SAASE,oBACdH,KAAkB,EAClBI,OAAe,EACfC,OAAkB,EAClBC,UAA+B,CAAC,CAAC;QAEhBC,mBAIJC,YACEC,cACAC,cACKC,mBACAC;IARpB,MAAMC,WAAW,QAAAN,CAAAA,oBAAAA,QAAQ,QAAQ,AAAD,IAAfA,oBAAoB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AAW,MAAM,CAAC,KAAKA;oBACxC;gBACF;YACA;gBACE,MAAM,IAAIN,QAAQ,2BAA2B,CAAC,CAAC,EAAEF,GAAG,wDAAwD,CAAC;QACjH;IACF;IACA,OAAON;AACT"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which digits numbers are written with. Independent of language and direction (plan/specs/01-Architecture.md §7):
|
|
3
|
+
* `fa*` defaults to `'persian'` (U+06F0–U+06F9), `ar` to `'arabicIndic'` (U+0660–U+0669), everything else `'latin'`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const G9NumberingSystem: {
|
|
6
|
+
readonly Latin: "latin";
|
|
7
|
+
readonly Persian: "persian";
|
|
8
|
+
readonly ArabicIndic: "arabicIndic";
|
|
9
|
+
};
|
|
10
|
+
export type G9NumberingSystem = (typeof G9NumberingSystem)[keyof typeof G9NumberingSystem];
|
|
11
|
+
/** @throws {G9Error} `culture-invalid-numbering-system` for anything that is not a {@link G9NumberingSystem}. */
|
|
12
|
+
export declare function checkNumberingSystem(value: string): G9NumberingSystem;
|
|
13
|
+
/**
|
|
14
|
+
* The value 0–9 of an ASCII, Persian or Arabic-Indic digit, or -1 for any other UTF-16 code unit. This is the digit set
|
|
15
|
+
* MAUI `G9Digits` recognises: a Persian or Arabic keyboard and any paste from a Persian source produce these.
|
|
16
|
+
*/
|
|
17
|
+
export declare function digitValue(codeUnit: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* Replaces every Persian (U+06F0–U+06F9) and Arabic-Indic (U+0660–U+0669) digit with its ASCII counterpart; every
|
|
20
|
+
* other character, separators included, is kept (MAUI `G9Digits.NormalizeToAscii`, both overloads: a one-character
|
|
21
|
+
* string is a `char`). `null`/`undefined` yield `''`. The input string is returned as is when nothing changes.
|
|
22
|
+
*/
|
|
23
|
+
export declare function normalizeToAscii(text: string | null | undefined): string;
|
|
24
|
+
/**
|
|
25
|
+
* Writes every ASCII digit of `text` in `numberingSystem` (the inverse of {@link normalizeToAscii} for one system).
|
|
26
|
+
* Other characters are kept, so separators must already be the culture's (see `formatNumber`).
|
|
27
|
+
*/
|
|
28
|
+
export declare function toNativeDigits(text: string, numberingSystem: G9NumberingSystem): string;
|
|
29
|
+
//# sourceMappingURL=digits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digits.d.ts","sourceRoot":"","sources":["../../src/culture/digits.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;CAA8E,CAAC;AAC7G,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAK3F,iHAAiH;AACjH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAKrE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKnD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAcxE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,iBAAiB,GAAG,MAAM,CAIvF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { G9Error } from "../errors.js";
|
|
2
|
+
const G9NumberingSystem = {
|
|
3
|
+
Latin: 'latin',
|
|
4
|
+
Persian: 'persian',
|
|
5
|
+
ArabicIndic: 'arabicIndic'
|
|
6
|
+
};
|
|
7
|
+
const ZERO = {
|
|
8
|
+
latin: 0x30,
|
|
9
|
+
persian: 0x06f0,
|
|
10
|
+
arabicIndic: 0x0660
|
|
11
|
+
};
|
|
12
|
+
const SYSTEMS = new Set(Object.keys(ZERO));
|
|
13
|
+
function checkNumberingSystem(value) {
|
|
14
|
+
if (!SYSTEMS.has(value)) throw new G9Error('culture-invalid-numbering-system', `"${value}" is not a G9NumberingSystem.`);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
function digitValue(codeUnit) {
|
|
18
|
+
if (codeUnit >= 0x30 && codeUnit <= 0x39) return codeUnit - 0x30;
|
|
19
|
+
if (codeUnit >= 0x06f0 && codeUnit <= 0x06f9) return codeUnit - 0x06f0;
|
|
20
|
+
if (codeUnit >= 0x0660 && codeUnit <= 0x0669) return codeUnit - 0x0660;
|
|
21
|
+
return -1;
|
|
22
|
+
}
|
|
23
|
+
function normalizeToAscii(text) {
|
|
24
|
+
if (!text) return '';
|
|
25
|
+
let out;
|
|
26
|
+
for(let i = 0; i < text.length; i++){
|
|
27
|
+
const code = text.charCodeAt(i);
|
|
28
|
+
const value = code > 0x7f ? digitValue(code) : -1;
|
|
29
|
+
if (value >= 0) {
|
|
30
|
+
if (void 0 === out) out = text.slice(0, i);
|
|
31
|
+
out += String.fromCharCode(0x30 + value);
|
|
32
|
+
} else if (void 0 !== out) out += text.charAt(i);
|
|
33
|
+
}
|
|
34
|
+
return null != out ? out : text;
|
|
35
|
+
}
|
|
36
|
+
function toNativeDigits(text, numberingSystem) {
|
|
37
|
+
const zero = ZERO[checkNumberingSystem(numberingSystem)];
|
|
38
|
+
if (0x30 === zero) return text;
|
|
39
|
+
return text.replace(/[0-9]/g, (d)=>String.fromCharCode(zero + d.charCodeAt(0) - 0x30));
|
|
40
|
+
}
|
|
41
|
+
export { G9NumberingSystem, checkNumberingSystem, digitValue, normalizeToAscii, toNativeDigits };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=digits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"culture/digits.js","sources":["../../src/culture/digits.ts"],"sourcesContent":["import { G9Error } from '../errors';\n\n/**\n * Which digits numbers are written with. Independent of language and direction (plan/specs/01-Architecture.md §7):\n * `fa*` defaults to `'persian'` (U+06F0–U+06F9), `ar` to `'arabicIndic'` (U+0660–U+0669), everything else `'latin'`.\n */\nexport const G9NumberingSystem = { Latin: 'latin', Persian: 'persian', ArabicIndic: 'arabicIndic' } as const;\nexport type G9NumberingSystem = (typeof G9NumberingSystem)[keyof typeof G9NumberingSystem];\n\nconst ZERO: Readonly<Record<G9NumberingSystem, number>> = { latin: 0x30, persian: 0x06f0, arabicIndic: 0x0660 };\nconst SYSTEMS: ReadonlySet<string> = new Set(Object.keys(ZERO));\n\n/** @throws {G9Error} `culture-invalid-numbering-system` for anything that is not a {@link G9NumberingSystem}. */\nexport function checkNumberingSystem(value: string): G9NumberingSystem {\n if (!SYSTEMS.has(value)) {\n throw new G9Error('culture-invalid-numbering-system', `\"${value}\" is not a G9NumberingSystem.`);\n }\n return value as G9NumberingSystem;\n}\n\n/**\n * The value 0–9 of an ASCII, Persian or Arabic-Indic digit, or -1 for any other UTF-16 code unit. This is the digit set\n * MAUI `G9Digits` recognises: a Persian or Arabic keyboard and any paste from a Persian source produce these.\n */\nexport function digitValue(codeUnit: number): number {\n if (codeUnit >= 0x30 && codeUnit <= 0x39) return codeUnit - 0x30;\n if (codeUnit >= 0x06f0 && codeUnit <= 0x06f9) return codeUnit - 0x06f0;\n if (codeUnit >= 0x0660 && codeUnit <= 0x0669) return codeUnit - 0x0660;\n return -1;\n}\n\n/**\n * Replaces every Persian (U+06F0–U+06F9) and Arabic-Indic (U+0660–U+0669) digit with its ASCII counterpart; every\n * other character, separators included, is kept (MAUI `G9Digits.NormalizeToAscii`, both overloads: a one-character\n * string is a `char`). `null`/`undefined` yield `''`. The input string is returned as is when nothing changes.\n */\nexport function normalizeToAscii(text: string | null | undefined): string {\n if (!text) return '';\n let out: string | undefined;\n for (let i = 0; i < text.length; i++) {\n const code = text.charCodeAt(i);\n const value = code > 0x7f ? digitValue(code) : -1;\n if (value >= 0) {\n if (out === undefined) out = text.slice(0, i);\n out += String.fromCharCode(0x30 + value);\n } else if (out !== undefined) {\n out += text.charAt(i);\n }\n }\n return out ?? text;\n}\n\n/**\n * Writes every ASCII digit of `text` in `numberingSystem` (the inverse of {@link normalizeToAscii} for one system).\n * Other characters are kept, so separators must already be the culture's (see `formatNumber`).\n */\nexport function toNativeDigits(text: string, numberingSystem: G9NumberingSystem): string {\n const zero = ZERO[checkNumberingSystem(numberingSystem)];\n if (zero === 0x30) return text;\n return text.replace(/[0-9]/g, (d) => String.fromCharCode(zero + d.charCodeAt(0) - 0x30));\n}\n"],"names":["G9NumberingSystem","ZERO","SYSTEMS","Set","Object","checkNumberingSystem","value","G9Error","digitValue","codeUnit","normalizeToAscii","text","out","i","code","undefined","String","toNativeDigits","numberingSystem","zero","d"],"mappings":";AAMO,MAAMA,oBAAoB;IAAE,OAAO;IAAS,SAAS;IAAW,aAAa;AAAc;AAGlG,MAAMC,OAAoD;IAAE,OAAO;IAAM,SAAS;IAAQ,aAAa;AAAO;AAC9G,MAAMC,UAA+B,IAAIC,IAAIC,OAAO,IAAI,CAACH;AAGlD,SAASI,qBAAqBC,KAAa;IAChD,IAAI,CAACJ,QAAQ,GAAG,CAACI,QACf,MAAM,IAAIC,QAAQ,oCAAoC,CAAC,CAAC,EAAED,MAAM,6BAA6B,CAAC;IAEhG,OAAOA;AACT;AAMO,SAASE,WAAWC,QAAgB;IACzC,IAAIA,YAAY,QAAQA,YAAY,MAAM,OAAOA,WAAW;IAC5D,IAAIA,YAAY,UAAUA,YAAY,QAAQ,OAAOA,WAAW;IAChE,IAAIA,YAAY,UAAUA,YAAY,QAAQ,OAAOA,WAAW;IAChE,OAAO;AACT;AAOO,SAASC,iBAAiBC,IAA+B;IAC9D,IAAI,CAACA,MAAM,OAAO;IAClB,IAAIC;IACJ,IAAK,IAAIC,IAAI,GAAGA,IAAIF,KAAK,MAAM,EAAEE,IAAK;QACpC,MAAMC,OAAOH,KAAK,UAAU,CAACE;QAC7B,MAAMP,QAAQQ,OAAO,OAAON,WAAWM,QAAQ;QAC/C,IAAIR,SAAS,GAAG;YACd,IAAIM,AAAQG,WAARH,KAAmBA,MAAMD,KAAK,KAAK,CAAC,GAAGE;YAC3CD,OAAOI,OAAO,YAAY,CAAC,OAAOV;QACpC,OAAO,IAAIM,AAAQG,WAARH,KACTA,OAAOD,KAAK,MAAM,CAACE;IAEvB;IACA,OAAOD,QAAAA,MAAAA,MAAOD;AAChB;AAMO,SAASM,eAAeN,IAAY,EAAEO,eAAkC;IAC7E,MAAMC,OAAOlB,IAAI,CAACI,qBAAqBa,iBAAiB;IACxD,IAAIC,AAAS,SAATA,MAAe,OAAOR;IAC1B,OAAOA,KAAK,OAAO,CAAC,UAAU,CAACS,IAAMJ,OAAO,YAAY,CAACG,OAAOC,EAAE,UAAU,CAAC,KAAK;AACpF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The picker convention for day-based durations (MAUI `G9TimeSpanMath`): a "year" is 365 days, a "month" 30 days, and
|
|
3
|
+
* the months drum shows 0–11.
|
|
4
|
+
*/
|
|
5
|
+
export declare const G9TimeSpanMath: Readonly<{
|
|
6
|
+
readonly DaysPerYear: 365;
|
|
7
|
+
readonly DaysPerMonth: 30;
|
|
8
|
+
readonly MaxMonths: 11;
|
|
9
|
+
}>;
|
|
10
|
+
/** Years, months and days of a day count (MAUI `(int Years, int Months, int Days)`). */
|
|
11
|
+
export interface G9DayParts {
|
|
12
|
+
readonly years: number;
|
|
13
|
+
readonly months: number;
|
|
14
|
+
readonly days: number;
|
|
15
|
+
}
|
|
16
|
+
/** Milliseconds per day: day-based durations travel as milliseconds (plan/specs/03-API-Conventions.md §2). */
|
|
17
|
+
export declare const MS_PER_DAY = 86400000;
|
|
18
|
+
/**
|
|
19
|
+
* Splits a day count into years, months and days (MAUI `G9TimeSpanMath.Decompose`). Negative input counts as zero.
|
|
20
|
+
* Because 365 is not a multiple of 30, the last five days of a "year" stay in `days` (months is capped at 11, so
|
|
21
|
+
* days can reach 34) instead of producing a month 12 the drum cannot show.
|
|
22
|
+
* @throws {G9Error} `duration-invalid` for a non-integer.
|
|
23
|
+
*/
|
|
24
|
+
export declare function decomposeDays(totalDays: number): G9DayParts;
|
|
25
|
+
/**
|
|
26
|
+
* Joins years, months and days into a day count with the same convention (MAUI `G9TimeSpanMath.Compose`). Negative
|
|
27
|
+
* parts count as zero; the result saturates at 2,147,483,647 (`int.MaxValue`) like MAUI.
|
|
28
|
+
* @throws {G9Error} `duration-invalid` for a non-integer part.
|
|
29
|
+
*/
|
|
30
|
+
export declare function composeDays(years: number, months: number, days: number): number;
|
|
31
|
+
/** A whole-day count as a duration in milliseconds. @throws {G9Error} `duration-invalid` for a non-integer. */
|
|
32
|
+
export declare function daysToMs(days: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* The whole days in a duration in milliseconds, truncated toward zero (.NET `TimeSpan.Days`).
|
|
35
|
+
* @throws {G9Error} `duration-invalid` for NaN or ±Infinity.
|
|
36
|
+
*/
|
|
37
|
+
export declare function msToWholeDays(ms: number): number;
|
|
38
|
+
//# sourceMappingURL=duration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/culture/duration.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,cAAc;;;;EAAgF,CAAC;AAE5G,wFAAwF;AACxF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,8GAA8G;AAC9G,eAAO,MAAM,UAAU,WAAa,CAAC;AAOrC;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAO3D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAS/E;AAED,+GAA+G;AAC/G,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG7C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAGhD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { G9Error } from "../errors.js";
|
|
2
|
+
const G9TimeSpanMath = Object.freeze({
|
|
3
|
+
DaysPerYear: 365,
|
|
4
|
+
DaysPerMonth: 30,
|
|
5
|
+
MaxMonths: 11
|
|
6
|
+
});
|
|
7
|
+
const MS_PER_DAY = 86400000;
|
|
8
|
+
const INT_MAX = 2147483647;
|
|
9
|
+
function checkInteger(name, value) {
|
|
10
|
+
if (!Number.isSafeInteger(value)) throw new G9Error('duration-invalid', `${name} must be an integer, got ${value}.`);
|
|
11
|
+
}
|
|
12
|
+
function decomposeDays(totalDays) {
|
|
13
|
+
checkInteger('totalDays', totalDays);
|
|
14
|
+
const total = Math.max(0, totalDays);
|
|
15
|
+
const years = Math.floor(total / G9TimeSpanMath.DaysPerYear);
|
|
16
|
+
const remainder = total % G9TimeSpanMath.DaysPerYear;
|
|
17
|
+
const months = Math.min(Math.floor(remainder / G9TimeSpanMath.DaysPerMonth), G9TimeSpanMath.MaxMonths);
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
years,
|
|
20
|
+
months,
|
|
21
|
+
days: remainder - months * G9TimeSpanMath.DaysPerMonth
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function composeDays(years, months, days) {
|
|
25
|
+
checkInteger('years', years);
|
|
26
|
+
checkInteger('months', months);
|
|
27
|
+
checkInteger('days', days);
|
|
28
|
+
const total = Math.max(0, years) * G9TimeSpanMath.DaysPerYear + Math.max(0, months) * G9TimeSpanMath.DaysPerMonth + Math.max(0, days);
|
|
29
|
+
return total > INT_MAX ? INT_MAX : total;
|
|
30
|
+
}
|
|
31
|
+
function daysToMs(days) {
|
|
32
|
+
checkInteger('days', days);
|
|
33
|
+
return days * MS_PER_DAY;
|
|
34
|
+
}
|
|
35
|
+
function msToWholeDays(ms) {
|
|
36
|
+
if (!Number.isFinite(ms)) throw new G9Error('duration-invalid', `ms must be finite, got ${ms}.`);
|
|
37
|
+
return Math.trunc(ms / MS_PER_DAY) + 0;
|
|
38
|
+
}
|
|
39
|
+
export { G9TimeSpanMath, MS_PER_DAY, composeDays, daysToMs, decomposeDays, msToWholeDays };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=duration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"culture/duration.js","sources":["../../src/culture/duration.ts"],"sourcesContent":["import { G9Error } from '../errors';\n\n/**\n * The picker convention for day-based durations (MAUI `G9TimeSpanMath`): a \"year\" is 365 days, a \"month\" 30 days, and\n * the months drum shows 0–11.\n */\nexport const G9TimeSpanMath = Object.freeze({ DaysPerYear: 365, DaysPerMonth: 30, MaxMonths: 11 } as const);\n\n/** Years, months and days of a day count (MAUI `(int Years, int Months, int Days)`). */\nexport interface G9DayParts {\n readonly years: number;\n readonly months: number;\n readonly days: number;\n}\n\n/** Milliseconds per day: day-based durations travel as milliseconds (plan/specs/03-API-Conventions.md §2). */\nexport const MS_PER_DAY = 86_400_000;\nconst INT_MAX = 2_147_483_647;\n\nfunction checkInteger(name: string, value: number): void {\n if (!Number.isSafeInteger(value)) throw new G9Error('duration-invalid', `${name} must be an integer, got ${value}.`);\n}\n\n/**\n * Splits a day count into years, months and days (MAUI `G9TimeSpanMath.Decompose`). Negative input counts as zero.\n * Because 365 is not a multiple of 30, the last five days of a \"year\" stay in `days` (months is capped at 11, so\n * days can reach 34) instead of producing a month 12 the drum cannot show.\n * @throws {G9Error} `duration-invalid` for a non-integer.\n */\nexport function decomposeDays(totalDays: number): G9DayParts {\n checkInteger('totalDays', totalDays);\n const total = Math.max(0, totalDays);\n const years = Math.floor(total / G9TimeSpanMath.DaysPerYear);\n const remainder = total % G9TimeSpanMath.DaysPerYear;\n const months = Math.min(Math.floor(remainder / G9TimeSpanMath.DaysPerMonth), G9TimeSpanMath.MaxMonths);\n return Object.freeze({ years, months, days: remainder - months * G9TimeSpanMath.DaysPerMonth });\n}\n\n/**\n * Joins years, months and days into a day count with the same convention (MAUI `G9TimeSpanMath.Compose`). Negative\n * parts count as zero; the result saturates at 2,147,483,647 (`int.MaxValue`) like MAUI.\n * @throws {G9Error} `duration-invalid` for a non-integer part.\n */\nexport function composeDays(years: number, months: number, days: number): number {\n checkInteger('years', years);\n checkInteger('months', months);\n checkInteger('days', days);\n const total =\n Math.max(0, years) * G9TimeSpanMath.DaysPerYear +\n Math.max(0, months) * G9TimeSpanMath.DaysPerMonth +\n Math.max(0, days);\n return total > INT_MAX ? INT_MAX : total;\n}\n\n/** A whole-day count as a duration in milliseconds. @throws {G9Error} `duration-invalid` for a non-integer. */\nexport function daysToMs(days: number): number {\n checkInteger('days', days);\n return days * MS_PER_DAY;\n}\n\n/**\n * The whole days in a duration in milliseconds, truncated toward zero (.NET `TimeSpan.Days`).\n * @throws {G9Error} `duration-invalid` for NaN or ±Infinity.\n */\nexport function msToWholeDays(ms: number): number {\n if (!Number.isFinite(ms)) throw new G9Error('duration-invalid', `ms must be finite, got ${ms}.`);\n return Math.trunc(ms / MS_PER_DAY) + 0;\n}\n"],"names":["G9TimeSpanMath","Object","MS_PER_DAY","INT_MAX","checkInteger","name","value","Number","G9Error","decomposeDays","totalDays","total","Math","years","remainder","months","composeDays","days","daysToMs","msToWholeDays","ms"],"mappings":";AAMO,MAAMA,iBAAiBC,OAAO,MAAM,CAAC;IAAE,aAAa;IAAK,cAAc;IAAI,WAAW;AAAG;AAUzF,MAAMC,aAAa;AAC1B,MAAMC,UAAU;AAEhB,SAASC,aAAaC,IAAY,EAAEC,KAAa;IAC/C,IAAI,CAACC,OAAO,aAAa,CAACD,QAAQ,MAAM,IAAIE,QAAQ,oBAAoB,GAAGH,KAAK,yBAAyB,EAAEC,MAAM,CAAC,CAAC;AACrH;AAQO,SAASG,cAAcC,SAAiB;IAC7CN,aAAa,aAAaM;IAC1B,MAAMC,QAAQC,KAAK,GAAG,CAAC,GAAGF;IAC1B,MAAMG,QAAQD,KAAK,KAAK,CAACD,QAAQX,eAAe,WAAW;IAC3D,MAAMc,YAAYH,QAAQX,eAAe,WAAW;IACpD,MAAMe,SAASH,KAAK,GAAG,CAACA,KAAK,KAAK,CAACE,YAAYd,eAAe,YAAY,GAAGA,eAAe,SAAS;IACrG,OAAOC,OAAO,MAAM,CAAC;QAAEY;QAAOE;QAAQ,MAAMD,YAAYC,SAASf,eAAe,YAAY;IAAC;AAC/F;AAOO,SAASgB,YAAYH,KAAa,EAAEE,MAAc,EAAEE,IAAY;IACrEb,aAAa,SAASS;IACtBT,aAAa,UAAUW;IACvBX,aAAa,QAAQa;IACrB,MAAMN,QACJC,KAAK,GAAG,CAAC,GAAGC,SAASb,eAAe,WAAW,GAC/CY,KAAK,GAAG,CAAC,GAAGG,UAAUf,eAAe,YAAY,GACjDY,KAAK,GAAG,CAAC,GAAGK;IACd,OAAON,QAAQR,UAAUA,UAAUQ;AACrC;AAGO,SAASO,SAASD,IAAY;IACnCb,aAAa,QAAQa;IACrB,OAAOA,OAAOf;AAChB;AAMO,SAASiB,cAAcC,EAAU;IACtC,IAAI,CAACb,OAAO,QAAQ,CAACa,KAAK,MAAM,IAAIZ,QAAQ,oBAAoB,CAAC,uBAAuB,EAAEY,GAAG,CAAC,CAAC;IAC/F,OAAOR,KAAK,KAAK,CAACQ,KAAKlB,cAAc;AACvC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { addDays, clampToPersianRange, combineLocalDateTime, compareLocal, dayOfWeek, daysInGregorianMonth, daysInMonth, formatIsoDate, formatIsoDateTime, fromCalendarDate, fromEpochDays, type G9CalendarDate, type G9LocalDate, type G9LocalDateTime, type G9LocalTime, type G9NameWidth, getMonthName, getMonthNames, getWeekdayNames, isGregorianLeapYear, isLeapYear, isSupportedByPersianCalendar, localDate, localDateTime, localDateTimeFromDate, localDateTimeFromEpochMs, localDateTimeToDate, localDateTimeToEpochMs, localTime, parseIsoDate, parseIsoDateTime, persianMaxSupportedDateTime, persianMinSupportedDateTime, persianNewYear, toCalendarDate, toEpochDays, toLocalDate, } from './calendar.js';
|
|
2
|
+
export { createCulture, createCultureStore, G9CalendarSystem, type G9Culture, type G9CultureListener, type G9CultureOptions, type G9CultureStore, G9Direction, isPersianLanguage, isRtl, languageOf, resolveFontFamily, sameCulture, withCultureOptions, } from './culture.js';
|
|
3
|
+
export { formatLocalDateTime, type G9DateFormatOptions } from './date-format.js';
|
|
4
|
+
export { digitValue, G9NumberingSystem, normalizeToAscii, toNativeDigits } from './digits.js';
|
|
5
|
+
export { composeDays, daysToMs, decomposeDays, type G9DayParts, G9TimeSpanMath, MS_PER_DAY, msToWholeDays, } from './duration.js';
|
|
6
|
+
export { formatNumber, formatPlainNumber, type G9NumberFormatOptions, type G9NumberSymbols, getNumberSymbols, parseNumber, } from './numbers.js';
|
|
7
|
+
export { formatAgo, formatAgoWithTime, type G9Now, type G9RelativeTimeOptions, type G9RelativeTimeParts, G9RelativeTimeUnit, type G9RelativeTimeWithClockOptions, getRelativeTimeParts, } from './relative-time.js';
|
|
8
|
+
export { createStrings, formatTemplate, type G9PartialStringTable, G9StringKey, type G9StringProvider, type G9Strings, type G9StringsOptions, type G9StringTable, g9ArabicStrings, g9BuiltInStringTables, g9EnglishStrings, g9PersianStrings, g9StringKeys, g9StringResourceName, } from './strings.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/culture/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,YAAY,EACZ,aAA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AAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,oBAAoB,GACrB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { addDays, clampToPersianRange, combineLocalDateTime, compareLocal, dayOfWeek, daysInGregorianMonth, daysInMonth, formatIsoDate, formatIsoDateTime, fromCalendarDate, fromEpochDays, getMonthName, getMonthNames, getWeekdayNames, isGregorianLeapYear, isLeapYear, isSupportedByPersianCalendar, localDate, localDateTime, localDateTimeFromDate, localDateTimeFromEpochMs, localDateTimeToDate, localDateTimeToEpochMs, localTime, parseIsoDate, parseIsoDateTime, persianMaxSupportedDateTime, persianMinSupportedDateTime, persianNewYear, toCalendarDate, toEpochDays, toLocalDate } from "./calendar.js";
|
|
2
|
+
export { G9CalendarSystem, G9Direction, createCulture, createCultureStore, isPersianLanguage, isRtl, languageOf, resolveFontFamily, sameCulture, withCultureOptions } from "./culture.js";
|
|
3
|
+
export { formatLocalDateTime } from "./date-format.js";
|
|
4
|
+
export { G9NumberingSystem, digitValue, normalizeToAscii, toNativeDigits } from "./digits.js";
|
|
5
|
+
export { G9TimeSpanMath, MS_PER_DAY, composeDays, daysToMs, decomposeDays, msToWholeDays } from "./duration.js";
|
|
6
|
+
export { formatNumber, formatPlainNumber, getNumberSymbols, parseNumber } from "./numbers.js";
|
|
7
|
+
export { G9RelativeTimeUnit, formatAgo, formatAgoWithTime, getRelativeTimeParts } from "./relative-time.js";
|
|
8
|
+
export { G9StringKey, createStrings, formatTemplate, g9ArabicStrings, g9BuiltInStringTables, g9EnglishStrings, g9PersianStrings, g9StringKeys, g9StringResourceName } from "./strings.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type G9NumberingSystem } from './digits.js';
|
|
2
|
+
/** The characters a numbering system writes numbers with (CLDR `latn` / `arabext` / `arab` symbols). */
|
|
3
|
+
export interface G9NumberSymbols {
|
|
4
|
+
readonly decimal: string;
|
|
5
|
+
readonly group: string;
|
|
6
|
+
readonly minus: string;
|
|
7
|
+
}
|
|
8
|
+
/** Decimal, grouping and minus characters for a numbering system. */
|
|
9
|
+
export declare function getNumberSymbols(numberingSystem: G9NumberingSystem): G9NumberSymbols;
|
|
10
|
+
/** Options of {@link formatNumber}. */
|
|
11
|
+
export interface G9NumberFormatOptions {
|
|
12
|
+
/** Digits and separators. Default `'latin'`; pass `culture.numberingSystem` for the active culture. */
|
|
13
|
+
readonly numberingSystem?: G9NumberingSystem;
|
|
14
|
+
/** Fraction digits always written (padded with zeros). Default 0. */
|
|
15
|
+
readonly minimumFractionDigits?: number;
|
|
16
|
+
/** Fraction digits at most; the value is rounded like `Number.prototype.toFixed`. Default 3, at least the minimum. */
|
|
17
|
+
readonly maximumFractionDigits?: number;
|
|
18
|
+
/** Group the integer part by thousands. Default `true`. */
|
|
19
|
+
readonly useGrouping?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Formats a number without `Intl` (Lynx has none): thousands grouping, fraction digits and the numbering system's digits
|
|
23
|
+
* and separators. `formatNumber(1234.5, { numberingSystem: 'persian' })` is `'۱٬۲۳۴٫۵'`.
|
|
24
|
+
* @throws {G9Error} `number-not-finite` for NaN/±Infinity, `number-out-of-range` from 1e21 up (where JavaScript
|
|
25
|
+
* switches to exponent notation), `number-invalid-option` for bad fraction digits.
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatNumber(value: number, options?: G9NumberFormatOptions): string;
|
|
28
|
+
/**
|
|
29
|
+
* Writes a number the way .NET's composite formatting (`string.Format("{0}", n)`) does, in shortest round-trip form
|
|
30
|
+
* and without grouping, then in `numberingSystem`'s digits and separators. Used by `G9Strings.format` placeholders.
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatPlainNumber(value: number, numberingSystem: G9NumberingSystem): string;
|
|
33
|
+
/**
|
|
34
|
+
* Reads a number typed in any of the three digit sets, with either separator style (`'1,234.5'`, `'۱٬۲۳۴٫۵'`,
|
|
35
|
+
* `'١٬٢٣٤٫٥'`), a leading sign and bidi marks. Returns `null` for anything else (no partial parse).
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseNumber(text: string | null | undefined): number | null;
|
|
38
|
+
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../src/culture/numbers.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,iBAAiB,EAAoC,MAAM,UAAU,CAAC;AAE1G,wGAAwG;AACxG,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AASD,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,eAAe,EAAE,iBAAiB,GAAG,eAAe,CAGpF;AAED,uCAAuC;AACvC,MAAM,WAAW,qBAAqB;IACpC,uGAAuG;IACvG,QAAQ,CAAC,eAAe,CAAC,EAAE,iBAAiB,CAAC;IAC7C,qEAAqE;IACrE,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IACxC,sHAAsH;IACtH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IACxC,2DAA2D;IAC3D,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC;AAmBD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAsBvF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,iBAAiB,GAAG,MAAM,CAI3F;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAQ1E"}
|