@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.
Files changed (164) hide show
  1. package/README.md +4 -2
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/collections.d.ts +16 -0
  4. package/dist/collections.d.ts.map +1 -0
  5. package/dist/collections.js +40 -0
  6. package/dist/collections.js.map +1 -0
  7. package/dist/culture/calendar.d.ts +122 -0
  8. package/dist/culture/calendar.d.ts.map +1 -0
  9. package/dist/culture/calendar.js +379 -0
  10. package/dist/culture/calendar.js.map +1 -0
  11. package/dist/culture/culture.d.ts +91 -0
  12. package/dist/culture/culture.d.ts.map +1 -0
  13. package/dist/culture/culture.js +173 -0
  14. package/dist/culture/culture.js.map +1 -0
  15. package/dist/culture/date-format.d.ts +19 -0
  16. package/dist/culture/date-format.d.ts.map +1 -0
  17. package/dist/culture/date-format.js +101 -0
  18. package/dist/culture/date-format.js.map +1 -0
  19. package/dist/culture/digits.d.ts +29 -0
  20. package/dist/culture/digits.d.ts.map +1 -0
  21. package/dist/culture/digits.js +43 -0
  22. package/dist/culture/digits.js.map +1 -0
  23. package/dist/culture/duration.d.ts +38 -0
  24. package/dist/culture/duration.d.ts.map +1 -0
  25. package/dist/culture/duration.js +41 -0
  26. package/dist/culture/duration.js.map +1 -0
  27. package/dist/culture/index.d.ts +9 -0
  28. package/dist/culture/index.d.ts.map +1 -0
  29. package/dist/culture/index.js +8 -0
  30. package/dist/culture/numbers.d.ts +38 -0
  31. package/dist/culture/numbers.d.ts.map +1 -0
  32. package/dist/culture/numbers.js +64 -0
  33. package/dist/culture/numbers.js.map +1 -0
  34. package/dist/culture/relative-time.d.ts +50 -0
  35. package/dist/culture/relative-time.d.ts.map +1 -0
  36. package/dist/culture/relative-time.js +63 -0
  37. package/dist/culture/relative-time.js.map +1 -0
  38. package/dist/culture/strings.d.ts +145 -0
  39. package/dist/culture/strings.d.ts.map +1 -0
  40. package/dist/culture/strings.js +345 -0
  41. package/dist/culture/strings.js.map +1 -0
  42. package/dist/enums/index.d.ts +195 -0
  43. package/dist/enums/index.d.ts.map +1 -0
  44. package/dist/enums/index.js +130 -0
  45. package/dist/enums/index.js.map +1 -0
  46. package/dist/errors.d.ts +10 -0
  47. package/dist/errors.d.ts.map +1 -0
  48. package/dist/errors.js +21 -0
  49. package/dist/errors.js.map +1 -0
  50. package/dist/exec/diagnostics.d.ts +74 -0
  51. package/dist/exec/diagnostics.d.ts.map +1 -0
  52. package/dist/exec/diagnostics.js +73 -0
  53. package/dist/exec/diagnostics.js.map +1 -0
  54. package/dist/exec/index.d.ts +5 -0
  55. package/dist/exec/index.d.ts.map +1 -0
  56. package/dist/exec/index.js +4 -0
  57. package/dist/exec/options.d.ts +75 -0
  58. package/dist/exec/options.d.ts.map +1 -0
  59. package/dist/exec/options.js +107 -0
  60. package/dist/exec/options.js.map +1 -0
  61. package/dist/exec/safe-executor.d.ts +138 -0
  62. package/dist/exec/safe-executor.d.ts.map +1 -0
  63. package/dist/exec/safe-executor.js +401 -0
  64. package/dist/exec/safe-executor.js.map +1 -0
  65. package/dist/exec/trace.d.ts +59 -0
  66. package/dist/exec/trace.d.ts.map +1 -0
  67. package/dist/exec/trace.js +108 -0
  68. package/dist/exec/trace.js.map +1 -0
  69. package/dist/icons/generated/glyph-svg.d.ts +37 -0
  70. package/dist/icons/generated/glyph-svg.d.ts.map +1 -0
  71. package/dist/icons/generated/glyph-svg.js +33 -0
  72. package/dist/icons/generated/glyph-svg.js.map +1 -0
  73. package/dist/icons/glyph-slots.d.ts +79 -0
  74. package/dist/icons/glyph-slots.d.ts.map +1 -0
  75. package/dist/icons/glyph-slots.js +50 -0
  76. package/dist/icons/glyph-slots.js.map +1 -0
  77. package/dist/icons/glyph.d.ts +76 -0
  78. package/dist/icons/glyph.d.ts.map +1 -0
  79. package/dist/icons/glyph.js +42 -0
  80. package/dist/icons/glyph.js.map +1 -0
  81. package/dist/icons/icon-fonts.d.ts +55 -0
  82. package/dist/icons/icon-fonts.d.ts.map +1 -0
  83. package/dist/icons/icon-fonts.js +74 -0
  84. package/dist/icons/icon-fonts.js.map +1 -0
  85. package/dist/icons/icon.d.ts +102 -0
  86. package/dist/icons/icon.d.ts.map +1 -0
  87. package/dist/icons/icon.js +132 -0
  88. package/dist/icons/icon.js.map +1 -0
  89. package/dist/icons/index.d.ts +7 -0
  90. package/dist/icons/index.d.ts.map +1 -0
  91. package/dist/icons/index.js +6 -0
  92. package/dist/icons/svg.d.ts +28 -0
  93. package/dist/icons/svg.d.ts.map +1 -0
  94. package/dist/icons/svg.js +59 -0
  95. package/dist/icons/svg.js.map +1 -0
  96. package/dist/index.d.ts +10 -0
  97. package/dist/index.d.ts.map +1 -0
  98. package/dist/index.js +9 -0
  99. package/dist/services/abort.d.ts +31 -0
  100. package/dist/services/abort.d.ts.map +1 -0
  101. package/dist/services/abort.js +47 -0
  102. package/dist/services/abort.js.map +1 -0
  103. package/dist/services/clock.d.ts +35 -0
  104. package/dist/services/clock.d.ts.map +1 -0
  105. package/dist/services/clock.js +37 -0
  106. package/dist/services/clock.js.map +1 -0
  107. package/dist/services/contracts.d.ts +200 -0
  108. package/dist/services/contracts.d.ts.map +1 -0
  109. package/dist/services/contracts.js +37 -0
  110. package/dist/services/contracts.js.map +1 -0
  111. package/dist/services/index.d.ts +5 -0
  112. package/dist/services/index.d.ts.map +1 -0
  113. package/dist/services/index.js +4 -0
  114. package/dist/services/preferences.d.ts +105 -0
  115. package/dist/services/preferences.d.ts.map +1 -0
  116. package/dist/services/preferences.js +253 -0
  117. package/dist/services/preferences.js.map +1 -0
  118. package/dist/theme/color.d.ts +94 -0
  119. package/dist/theme/color.d.ts.map +1 -0
  120. package/dist/theme/color.js +150 -0
  121. package/dist/theme/color.js.map +1 -0
  122. package/dist/theme/control-colors.d.ts +46 -0
  123. package/dist/theme/control-colors.d.ts.map +1 -0
  124. package/dist/theme/control-colors.js +46 -0
  125. package/dist/theme/control-colors.js.map +1 -0
  126. package/dist/theme/index.d.ts +5 -0
  127. package/dist/theme/index.d.ts.map +1 -0
  128. package/dist/theme/index.js +4 -0
  129. package/dist/theme/theme.d.ts +88 -0
  130. package/dist/theme/theme.d.ts.map +1 -0
  131. package/dist/theme/theme.js +190 -0
  132. package/dist/theme/theme.js.map +1 -0
  133. package/dist/theme/variants.d.ts +33 -0
  134. package/dist/theme/variants.d.ts.map +1 -0
  135. package/dist/theme/variants.js +53 -0
  136. package/dist/theme/variants.js.map +1 -0
  137. package/dist/tokens/css-vars.d.ts +41 -0
  138. package/dist/tokens/css-vars.d.ts.map +1 -0
  139. package/dist/tokens/css-vars.js +55 -0
  140. package/dist/tokens/css-vars.js.map +1 -0
  141. package/dist/tokens/generated/metrics.d.ts +184 -0
  142. package/dist/tokens/generated/metrics.d.ts.map +1 -0
  143. package/dist/tokens/generated/metrics.js +349 -0
  144. package/dist/tokens/generated/metrics.js.map +1 -0
  145. package/dist/tokens/generated/palettes.d.ts +113 -0
  146. package/dist/tokens/generated/palettes.d.ts.map +1 -0
  147. package/dist/tokens/generated/palettes.js +391 -0
  148. package/dist/tokens/generated/palettes.js.map +1 -0
  149. package/dist/tokens/index.d.ts +5 -0
  150. package/dist/tokens/index.d.ts.map +1 -0
  151. package/dist/tokens/index.js +4 -0
  152. package/dist/tokens/layout-metrics.d.ts +120 -0
  153. package/dist/tokens/layout-metrics.d.ts.map +1 -0
  154. package/dist/tokens/layout-metrics.js +111 -0
  155. package/dist/tokens/layout-metrics.js.map +1 -0
  156. package/docs/api.md +369 -0
  157. package/docs/foundation.md +370 -0
  158. package/docs/migration/Core.Controls.Shared.md +475 -0
  159. package/docs/migration/Core.Helpers.md +132 -0
  160. package/docs/migration/Core.Icons.md +135 -0
  161. package/docs/migration/Core.Localization.md +118 -0
  162. package/docs/migration/Core.Storage.md +54 -0
  163. package/docs/migration/Core.Theming.md +328 -0
  164. package/package.json +59 -4
@@ -0,0 +1,370 @@
1
+ # `@g9tm/lynxcontrols-foundation` guide
2
+
3
+ Pure TypeScript: no React, no lynx-ui, no native modules, no `Intl`. Runs on the Lynx background thread and in Node
4
+ tests. This guide covers all of WP01: **slice 1.1: tokens, theme and colours**, **slice 1.2: culture**, **slice 1.3:
5
+ icons** and **slice 1.4: safe execution, diagnostics, preferences, service contracts and the shared enums**.
6
+
7
+ Imports: `@g9tm/lynxcontrols-foundation` (everything) or the subpaths `@g9tm/lynxcontrols-foundation/tokens`, `/theme`, `/culture`, `/icons`,
8
+ `/enums`, `/exec`, `/services`.
9
+ Migration tables: [`migration/Core.Theming.md`](migration/Core.Theming.md),
10
+ [`migration/Core.Localization.md`](migration/Core.Localization.md) (`G9Culture`, `G9Strings`, `G9StringKey`),
11
+ [`migration/Core.Icons.md`](migration/Core.Icons.md) (`G9Glyph`, `G9Glyphs`, `G9IconSource`, `G9IconFonts`),
12
+ [`migration/Core.Helpers.md`](migration/Core.Helpers.md) (`G9ColorHelper`, `G9RelativeTimeFormatter`, `G9SafeCommand`,
13
+ `G9SafeCommandOptions`, `G9Diagnostics`, `G9DiagnosticsReport`, `G9OperationTrace`, `G9ObservableRangeCollection`),
14
+ [`migration/Core.Storage.md`](migration/Core.Storage.md) (`G9Preferences`, `IG9PreferenceStore` and the two stores),
15
+ [`migration/Core.Controls.Shared.md`](migration/Core.Controls.Shared.md) (`G9Colors`, `G9Visuals`, `G9Metrics`,
16
+ `G9Calendar`, `G9Digits`, `G9TimeSpanMath`, every shared enum, `G9InputType`, …).
17
+
18
+ ## Theme and tokens
19
+
20
+ The example below is `src/guide.example.test.ts`; it compiles and runs in `npm test`.
21
+
22
+ ```ts
23
+ import {
24
+ createThemeStore, darken, formatColor, g9Token, resolveButtonVariant, resolveLayoutMetrics,
25
+ toCssVariables, toLayoutCssVariables, toMetricCssVariables, withAlpha,
26
+ } from '@g9tm/lynxcontrols-foundation';
27
+
28
+ // 1. One store per app (the WP02 provider owns it). Brand colour as an override on every scheme.
29
+ const theme = createThemeStore({ mode: 'system', systemScheme: 'light', overrides: { Primary: '#1E88E5' } });
30
+
31
+ // 2. Everything a stylesheet needs, as CSS variables for the root element.
32
+ const vars = {
33
+ ...toCssVariables(theme.getSnapshot()), // --g9-primary, --g9-on-primary, … (95)
34
+ ...toMetricCssVariables(), // --g9-metric-radius-md: 12px, … (171)
35
+ ...toLayoutCssVariables(resolveLayoutMetrics({ EdgeSpacing: 12 })), // --g9-layout-edge-spacing: 12px, …
36
+ };
37
+ theme.subscribe((next) => { /* re-apply toCssVariables(next) to the root */ });
38
+
39
+ // 3. Components reference tokens; derived colours are computed from the snapshot when props change, never per frame.
40
+ const background = g9Token('Surface'); // 'var(--g9-surface)'
41
+ const { palette } = theme.getSnapshot();
42
+ const pressed = formatColor(darken(palette.Primary, 0.2)); // '#186DB7'
43
+ const halo = formatColor(withAlpha(palette.Primary, 0.14)); // 'rgba(30, 136, 229, 0.14)'
44
+ const primaryButton = resolveButtonVariant('primary', palette); // { background, text, stroke, usesGradient }
45
+
46
+ // 4. The platform reports a scheme; the user's choice wins once made.
47
+ theme.setSystemScheme('dark');
48
+ theme.setMode('light');
49
+ ```
50
+
51
+ ### Tokens
52
+
53
+ - `G9ColorToken`: the 95 MAUI colour tokens, valued by their MAUI names (`G9ColorToken.Primary === 'Primary'`), in
54
+ declaration order (`g9ColorTokens`). CSS variable: `cssVariableName('OnPrimary')` → `--g9-on-primary`;
55
+ `g9Token('OnPrimary')` → `var(--g9-on-primary)`; `resolveThemeColor('var(--g9-surface)', palette)` → the palette's
56
+ literal (for a value that must not be a `var()`, such as another custom property).
57
+ - `g9LightPalette`, `g9DarkPalette`: the stock palettes (`G9PaletteValues`, CSS colour strings).
58
+ - `G9Metrics`: the 171 control metrics; `g9MetricUnits` says which are `px`, `ms` or unitless.
59
+ - `g9LayoutMetrics` / `resolveLayoutMetrics(overrides)`: spacing, sizes, insets (`{ top, end, bottom, start }`) and
60
+ corner radii. Overrides replace MAUI's app-resource retuning; derived members (sheet footer, map bottom bar) follow
61
+ their sources. An unknown key or a wrongly shaped value throws `G9Error` (`layout-metric-unknown` /
62
+ `layout-metric-invalid`).
63
+ - `resolveFullScreenSheetTopPadding({ safeAreaInset, useTopSafeAreaPadding, additionalTopSafeAreaPadding,
64
+ topSafeAreaPaddingOverride })`: the status-bar band above a full-screen sheet.
65
+
66
+ **Generated files.** `src/tokens/generated/palettes.ts` and `metrics.ts` are written by `npm run gen:tokens`
67
+ (`scripts/gen-tokens.mjs`) from `plan/golden/theme-palettes.json` and `metrics.json`, the outputs of the original C#.
68
+ Do not edit them; `tokens.test.ts` runs the generator in `--check` mode and fails on drift.
69
+
70
+ ### Theme
71
+
72
+ - `resolveTheme({ mode, systemScheme, palettes, overrides })` → frozen `G9ResolvedTheme` `{ mode, systemScheme,
73
+ scheme, palette }`. Layers: stock palette of the painted scheme, then `palettes[scheme]`, then `overrides`. Mode
74
+ `'system'` follows `systemScheme`; `'light'`/`'dark'` pin it. Defaults: `'system'`, `'light'`. Every value is
75
+ validated (unknown token → `G9Error('theme-unknown-token')`, unreadable colour → `G9ColorFormatError`), including
76
+ the palette of the scheme not currently painted.
77
+ - `createThemeStore(options)` → `G9ThemeStore` with `getSnapshot` / `subscribe` (fits `useSyncExternalStore`),
78
+ `setMode` (MAUI `ChangeTheme`), `setSystemScheme` (platform change; repaints only in `'system'` mode),
79
+ `setPalettes`, `setOverrides`, `apply(completePalette)` (MAUI `G9Palette.Apply`; kept until the next mode/scheme
80
+ change re-resolves the theme) and nested `beginBatch` / `endBatch`.
81
+ - Listeners get the snapshot taken at notify time, once per change, and nothing when nothing visible changed.
82
+ - Inside a batch nothing is notified; the outermost `endBatch` notifies once.
83
+ - A change a listener makes during a notification is delivered after the current round.
84
+ - An invalid input throws and leaves the store unchanged. A throwing listener does not stop the others; the
85
+ first error is rethrown to the caller after all listeners ran.
86
+ - **Persistence is the caller's job**: MAUI stored the choice under preference key `theme`. Subscribe and save
87
+ `snapshot.mode` (the WP02 provider does this with the preferences service).
88
+
89
+ ### Colours
90
+
91
+ `G9Color` is a CSS colour string. Arithmetic runs on `G9Rgba` (channels `0..1` stored at float32, like MAUI `Color`)
92
+ so results match the MAUI helpers exactly; `formatColor` returns CSS.
93
+
94
+ | Function | Behaviour |
95
+ | --- | --- |
96
+ | `parseColor(css)` / `tryParseColor` | `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa` (alpha last), `rgb()`, `rgba()`, `transparent`; otherwise `G9ColorFormatError` (`code: 'color-format'`). Named colours are not accepted. |
97
+ | `parseMauiColor(hex)` | MAUI order: `#argb`, `#aarrggbb` (alpha first). |
98
+ | `formatColor(c)` | `#RRGGBB` when opaque, else `rgba(R, G, B, A)`; bytes rounded, alpha the shortest decimal that reads back as the same float32. |
99
+ | `toHex(c)` | MAUI `ToHex`: `#RRGGBB`, alpha dropped, channels truncated after float32 × 255. |
100
+ | `withAlpha`, `withOpacity`, `applyAlpha` | set alpha; `withOpacity` also takes invariant numeric strings (`'0.5'`), unreadable → 1. |
101
+ | `darken`, `lighten`, `mix`, `createBorderColor` (15 %), `createHoverColor` (8 %), `createPressedColor` (20 %) | MAUI recipes, percentages clamped to `0..1`. |
102
+ | `getLuminance`, `getContrastRatio`, `getContrastingTextColor`, `meetsWcagAA` (4.5), `meetsWcagAAA` (7) | WCAG formulas as in MAUI. |
103
+
104
+ ### Variants and control colours
105
+
106
+ - `resolveButtonVariant(variant, palette)` → `G9VariantColors` `{ background, text, stroke, usesGradient }` for every
107
+ `G9ButtonVariant` (`'primary'`, `'tonal'`, …, `'errorTonal'`, `'text'`). `G9ButtonVisualResult` is the same shape for
108
+ a button's final colours after its own escape hatches (WP04).
109
+ - `resolveProgressColor(type, palette)`, `hasSwatch(first, second)`.
110
+ - `G9Colors` alpha constants; `switchOffTrack(theme)`, `switchOnTrack`, `switchThumbOff`, `switchThumbOn`,
111
+ `checkBoxMark` take the resolved theme because they depend on the painted scheme.
112
+ - `buildSolidOrGradient(base, useGradient)` → `G9Fill`; `fillToCss(fill)` → a colour or
113
+ `linear-gradient(to bottom, …)`. No shadows anywhere (specs/01 §6).
114
+
115
+ ### Platform notes
116
+
117
+ Nothing in this slice touches the UI thread, a native module or `Intl`; `no-intl.test.ts` runs the public API with
118
+ `Intl` removed, and `npm run test:nointl` runs the whole suite that way. Applying the variables to a Lynx element
119
+ (`setProperty` on the provider root) is WP02.
120
+
121
+ ## Culture
122
+
123
+ Everything is table-driven: Lynx has no `Intl`, so nothing here calls `Intl`, `toLocale*` or the Intl-dependent parts
124
+ of `@internationalized/date` (lint bans them). The example below is the second test in `src/guide.example.test.ts`.
125
+
126
+ ```ts
127
+ import {
128
+ createCultureStore, createStrings, decomposeDays, formatAgo, formatLocalDateTime, formatNumber, G9StringKey,
129
+ g9BuiltInStringTables, localDateTimeFromEpochMs, normalizeToAscii, parseNumber,
130
+ } from '@g9tm/lynxcontrols-foundation';
131
+
132
+ // 1. One culture store per app (the WP02 provider owns it). No Intl: the host passes the device locale.
133
+ const culture = createCultureStore('fa-IR'); // RTL, Persian calendar, Persian digits
134
+ let strings = createStrings({ culture: culture.getSnapshot(), tables: g9BuiltInStringTables });
135
+ culture.subscribe((next) => { strings = createStrings({ culture: next, tables: g9BuiltInStringTables }); });
136
+
137
+ // 2. Strings, numbers and digits.
138
+ strings.get(G9StringKey.Done); // 'انجام شد'
139
+ formatNumber(1234.5, { numberingSystem: culture.getSnapshot().numberingSystem }); // '۱٬۲۳۴٫۵'
140
+ parseNumber('۱٬۲۳۴٫۵'); // 1234.5
141
+ normalizeToAscii('۰۹۱۲-۱۲۳-۴۵۶۷'); // '0912-123-4567'
142
+
143
+ // 3. Dates: instants are epoch ms; wall-clock values come from an explicit UTC offset (Tehran +03:30).
144
+ const now = Date.UTC(2024, 2, 20, 12, 0);
145
+ formatLocalDateTime(localDateTimeFromEpochMs(now, 210), 'dddd d MMMM yyyy', culture.getSnapshot());
146
+ // 'چهارشنبه ۱ فروردین ۱۴۰۳'
147
+ formatAgo(now - 2 * 86_400_000, { now, strings }); // '۲ روز پیش' (the clock is explicit too)
148
+ decomposeDays(400); // { years: 1, months: 1, days: 5 }
149
+
150
+ // 4. Switching language notifies once with the new snapshot.
151
+ culture.setCulture('en-US');
152
+ ```
153
+
154
+ ### Culture values and the store
155
+
156
+ - `createCulture(locale, options?)` → frozen `G9Culture` `{ locale, language, direction, calendar, numberingSystem,
157
+ rtlFontFamily?, ltrFontFamily? }`. Defaults follow the language, never the direction alone: `fa*` → Persian
158
+ calendar, Persian digits, RTL; `ar*` → Gregorian, Arabic-Indic digits, RTL; other RTL languages or scripts → RTL,
159
+ Gregorian, Latin; the rest LTR. Every setting is an independent override; invalid input throws a `G9Error`.
160
+ - `createCultureStore(culture | locale)`: `getSnapshot`, `subscribe`, `setCulture`, `update(options)` (`null` clears a
161
+ font). Listeners run once per actual change with the snapshot of that change, also when a listener switches again
162
+ (that switch is reported next, with its own snapshot); all listeners run, then the first error is rethrown.
163
+ - `isRtl`, `isPersianLanguage`, `resolveFontFamily(culture, explicit?)`, `withCultureOptions`, `sameCulture`.
164
+
165
+ ### Strings
166
+
167
+ `createStrings({ culture, provider?, keyPrefix?, overrides?, tables?, onProviderError? })` → `{ get, format, resolve }`.
168
+ Lookup order: provider (asked with `keyPrefix` + the MAUI member name, e.g. `G9NoResults`) → `overrides` →
169
+ `tables[culture.language]` → built-in English. Without `tables` every culture shows English, exactly like MAUI;
170
+ `g9BuiltInStringTables` adds the bundled Persian and Arabic translations. `format` fills `{0}` with numbers in the
171
+ culture's digits and rejects specifiers such as `{0:N2}`. `resolve(name)` is provider-only (app keys).
172
+
173
+ ### Digits, numbers, calendars, durations, relative time
174
+
175
+ - `normalizeToAscii`, `toNativeDigits`, `digitValue`; `formatNumber` (grouping, fraction digits, `,`/`.` for Latin,
176
+ `٬`/`٫` for Persian and Arabic-Indic), `parseNumber` (any digit set, either separator style).
177
+ - `G9LocalDate` / `G9LocalTime` / `G9LocalDateTime`: frozen values built with `localDate`, `localTime`, `localDateTime`;
178
+ epoch-ms converters take an explicit UTC offset; ISO and `Date` converters; `compareLocal`, `addDays`, `dayOfWeek`.
179
+ - `toCalendarDate(date, 'persian')`, `fromCalendarDate`, `persianNewYear`, `isLeapYear`, `daysInMonth`; month and
180
+ weekday names for fa/ar/en. Persian dates equal .NET's exactly for 1200–1501 AP; later years and the range edges
181
+ follow `@internationalized/date` (see the `G9Calendar` section of the Core.Controls.Shared migration table).
182
+ - `formatLocalDateTime(value, pattern, culture, { calendar?, numberingSystem? })`: .NET-style patterns.
183
+ - `decomposeDays` / `composeDays` (365-day years, 30-day months), `daysToMs`, `msToWholeDays`.
184
+ - `formatAgo(instantMs, { now, strings })`, `formatAgoWithTime(…, utcOffsetMinutes)`, `getRelativeTimeParts`.
185
+
186
+ ### Culture platform notes
187
+
188
+ No `Intl`, no device time-zone database: the host supplies the locale and, where a wall clock is shown, the UTC
189
+ offset. `no-intl.test.ts` runs this slice's public API with `Intl` removed, and `npm run test:nointl` runs every
190
+ suite that way.
191
+
192
+ ## Icons
193
+
194
+ Built-in glyphs are SVG, not a font (MAUI ADR-0003): they cannot render as tofu and need no asset. Other icons come
195
+ from the app's own icon font, an SVG or an image. The example below is the third test in `src/guide.example.test.ts`.
196
+
197
+ ```ts
198
+ import { createIconFontRegistry, glyphIcon, resolveGlyphSlots, svgForGlyph } from '@g9tm/lynxcontrols-foundation';
199
+
200
+ // 1. Built-in glyphs need no font: SVG for Lynx <svg content> (WP02 renders it), coloured and weighted.
201
+ const chevron = svgForGlyph('chevronDown', '#1E88E5'); // golden drawing, stroke="#1E88E5"
202
+ const boldPlus = svgForGlyph('plus', 'currentColor', 1.5); // stroke-width="3"
203
+
204
+ // 2. One icon-font registry per app (the WP02 provider owns it). Raw names keep look-alike glyphs apart.
205
+ const fonts = createIconFontRegistry();
206
+ const myIcons = fonts.register('MyIcons', { Valve: 0xe801, HourGlass: 0xeae7, Hourglass: 0xe88b });
207
+ fonts.registerName('hour-glass', myIcons.HourGlass);
208
+ fonts.registerName('hourglass', myIcons.Hourglass);
209
+ const fromServer = fonts.resolve('hour-glass', glyphIcon('info')); // MyIcons U+EAE7
210
+ const builtIn = fonts.resolve('Search'); // { glyph: 'search' }
211
+
212
+ // 3. Replace the controls' own icons (passed as G9Provider settings.glyphs in WP02).
213
+ const glyphs = resolveGlyphSlots({ chevron: myIcons.Valve });
214
+ ```
215
+
216
+ ### The icon model
217
+
218
+ - `G9Glyph`: the 27 built-in glyphs plus `'none'` (camelCase MAUI names); `g9Glyphs[n]` is MAUI enum number `n`.
219
+ - `G9Icon` = `{ glyph }` | `{ font, codepoint }` | `{ font, text }` | `{ svg }` | `{ image: { uri } | { asset } | { svg } }`.
220
+ No icon is `null`/`undefined`; `{ glyph: 'none' }` is empty too. Build with `glyphIcon`, `codePointIcon`,
221
+ `fontIcon` or `defineIconFont(font, { Member: text or codepoint })` (MAUI icon-font enums); all validate and throw a
222
+ `G9Error` (`icon-glyph`, `icon-font`, `icon-codepoint`, `icon-shape`). Helpers: `isGlyphIcon`, `isFontIcon`,
223
+ `isSvgIcon`, `isImageIcon`, `isIconEmpty`, `builtInGlyph`, `fontIconText`, `iconEquals` (code point equals its
224
+ text), `iconSignature` (stable identity for "rebuild only if changed"), `toIcon`, `assertG9Icon`.
225
+
226
+ ### Glyph slots
227
+
228
+ `g9DefaultGlyphSlots` is MAUI `G9Glyphs`: 27 slots such as `chevron`, `clear`, `eyeOpen`, `info`/`success`/
229
+ `warning`/`error`, each defaulting to a built-in glyph. `resolveGlyphSlots(overrides)` returns a frozen set with your
230
+ replacements; an unknown slot or malformed icon throws. A control that has a slot draws every icon of that kind from
231
+ it (MAUI ADR-0021), so an override applies everywhere or nowhere.
232
+
233
+ ### Icon fonts
234
+
235
+ `createIconFontRegistry()` → `{ register, registerName, resolve, parse, reset, defaultFontAlias }`. Names compare
236
+ ordinal-ignore-case. `resolve(name, fallback?)` tries registered raw names first (every `registerName` entry, every
237
+ `Font.Member`, and every member name, first registered font first), then built-in glyph names (`'Search'`,
238
+ `'chevronDown'`, or the MAUI number). `parse(name)` is the strict form for configuration text: blank is no icon, an
239
+ unknown name throws `icon-unknown`. Register the font's own exported names with `registerName` whenever they differ from
240
+ member names: `hour-glass` and `hourglass` are different glyphs in several fonts, and member names that differ only by
241
+ case collide.
242
+
243
+ ### SVG rendering
244
+
245
+ `svgForGlyph(glyph, color = 'currentColor', weightScale = 1)` returns the golden document with the colour written in
246
+ (normalised by `formatColor`; `currentColor` is kept) and the stroke width set to 2 × `weightScale` design units;
247
+ filled dots keep their recorded radius. `'none'` returns `''`. Results come from a shared LRU cache of
248
+ `g9GlyphSvgCacheDefaultSize` (256) documents; `createGlyphSvgCache(maxEntries)` makes a private one with `size`, `has`
249
+ and `clear`.
250
+
251
+ ### Icon platform notes
252
+
253
+ No `Intl`: name folding is simple per-code-point upper-casing (`iconNameKey`), never locale rules. `no-intl.test.ts`
254
+ runs this slice with `Intl` removed. Rendering the SVG (`<svg content>`), font glyphs (`<text>` with the font family)
255
+ and images is WP02; nothing here has been drawn on a device yet.
256
+
257
+ ## Execution and services
258
+
259
+ One guarded-execution state machine for every safe button, tap and command (MAUI `G9SafeCommand`, specs/03 §4), the
260
+ observation seam, the preference model and the contracts the app supplies. The example below is the fourth test in
261
+ `src/guide.example.test.ts`.
262
+
263
+ ```ts
264
+ import {
265
+ createDiagnostics, createMemoryPreferenceStore, createPreferences, createSafeExecutor, createSystemClock,
266
+ hasCapability, requireCapability,
267
+ } from '@g9tm/lynxcontrols-foundation';
268
+
269
+ // 1. One diagnostics hub, clock and preferences per app (the WP02 provider owns them).
270
+ const diagnostics = createDiagnostics();
271
+ diagnostics.onOperationStarted((source, key) => inFlight.add(`${source}/${key}`));
272
+ diagnostics.onOperationCompleted((source, key) => inFlight.delete(`${source}/${key}`));
273
+ const clock = createSystemClock();
274
+ const prefs = createPreferences({ store: createMemoryPreferenceStore({ 'g9controls.theme': 'dark' }) });
275
+ await prefs.hydrate(); // before the first render
276
+ const sheetHeights = prefs.namespace('sheets');
277
+
278
+ // 2. One executor per control or screen; the provider passes its popup presenter as showError.
279
+ const executor = createSafeExecutor({ clock, diagnostics, showError: (request) => popups.show(request) });
280
+
281
+ // 3. Guarded work: double taps are throttled, overlapping runs of the same key are skipped.
282
+ const saved = await executor.run(
283
+ async ({ trace, signal }) => {
284
+ trace.step('validated');
285
+ if (signal.aborted) return null;
286
+ await sheetHeights.setInt('login', 320);
287
+ return 'saved';
288
+ },
289
+ { source: 'LoginScreen', throttleKey: 'save', timeoutMs: 10_000 },
290
+ ); // { status: 'completed', value: 'saved' }
291
+ executor.dispose(); // on unmount: in-flight runs settle as cancelled, busy resets
292
+
293
+ // 4. Optional services hide their feature; required ones fail loudly.
294
+ const showMic = hasCapability(services, 'speech');
295
+ const host = requireCapability(services, 'host'); // throws G9CapabilityMissingError('host') when absent
296
+ ```
297
+
298
+ ### The safe executor
299
+
300
+ `createSafeExecutor({ clock, diagnostics, strings, showError, diagnosticsHandler, diagnosticsAvailable, defaults,
301
+ timers })` → `{ run, runSafe, showOperationError, tryThrottle, resetThrottle, isRunning, getSnapshot, subscribe,
302
+ dispose }`.
303
+
304
+ - **A run**: disposed? caller `signal` aborted? throttled (same key within `throttleIntervalMs`, default 369 ms, by
305
+ monotonic time)? same key in flight (`preventConcurrentExecution`, default on)? Each of these settles the run
306
+ without calling the action. Then the optional delay (`delayBeforeExecutionMs`, else `busyDelayMs`; the guards are
307
+ held), `setBusy(true)`, `operationStarted`, the action with `{ signal, trace, key, source }`. A synchronous action
308
+ runs inside `run()` itself when there is no delay.
309
+ - **Every exit** (value, throw, `timeoutMs`, caller abort, `dispose()`) emits `operationCompleted` once, calls
310
+ `setBusy(false)` and frees the key before anything waits on the user.
311
+ - **Failures** (a throw, a timeout: `G9Error` `safe-timeout`, or `trace.fail(message)`) then go to
312
+ `onOperationFailed` → `onError` (not for `trace.fail`) → the popup (`showErrorPopup`, default on; title `Error`,
313
+ message `errorMessage` or `UnexpectedError`, OK, and "More details" when a `diagnosticsHandler` is configured and
314
+ `diagnosticsAvailable()` allows it) → rethrow when `rethrow` is set. An `AbortError` thrown by the action is a quiet
315
+ cancellation.
316
+ - **Results**: `{ status: 'completed', value }`, `{ status: 'skipped', reason: 'throttled' | 'concurrent' |
317
+ 'disposed' }`, `{ status: 'cancelled', reason: 'aborted' | 'disposed' }`, `{ status: 'failed', reason: 'error' |
318
+ 'timeout' | 'reported', error, report }`. The promise settles exactly once; it rejects only for invalid options
319
+ (`G9Error` `safe-options`) or with `rethrow`.
320
+ - **After timeout, abort or dispose** the action's signal is aborted and its eventual result is ignored: no second
321
+ report, no busy flicker, no unhandled rejection.
322
+ - Option presets: `createUiOperationOptions`, `createSilentOperationOptions`, `createFireAndForgetOperationOptions`.
323
+ `getSnapshot()` → `{ state: 'idle' | 'busy' | 'disposed', running }` for spinners.
324
+
325
+ ### Diagnostics and traces
326
+
327
+ `createDiagnostics({ onListenerError })` is the host's observation seam: `onOperationStarted`, `onOperationCompleted`
328
+ (exactly once per started run, so in-flight counts never leak), `onActivityChanged` (with `activity(name)` scopes whose
329
+ `dispose()` is idempotent), `onOperationFailed` (`G9DiagnosticsReport` `{ source, userMessage, diagnosticsText,
330
+ exceptions }`) and `onLog`. A throwing listener never breaks what it observes. `createOperationTrace(key, source, {
331
+ clock, log })` records `step`/`warning`/`error`/`fail` with elapsed times and builds the MAUI "More details" report.
332
+
333
+ ### Preferences
334
+
335
+ `createPreferences({ store, keyPrefix = 'g9controls.', onStoreError })` hydrates the namespace once (`hydrate()`; a
336
+ synchronous store is hydrated before it returns), then reads synchronously from an immutable snapshot (`getInt`,
337
+ `getString`, `getSnapshot`, `subscribe`). Writes (`setInt` 32-bit integers, `setString`, `null` or `remove` deletes)
338
+ update the snapshot first and then the store; a write made before hydration finishes wins. Store failures never reach
339
+ the caller: they go to `onStoreError` and reads keep their defaults. `namespace('sheets')` scopes keys to
340
+ `g9controls.sheets.`; `intKey`/`stringKey` are typed handles. `createMemoryPreferenceStore(initial)` is the in-memory
341
+ store for tests and opt-out; platform stores come from the host adapters (WP12–WP14).
342
+
343
+ ### Clock, cancellation and capabilities
344
+
345
+ - `G9Clock` = `{ now(), monotonicNow() }`; `createSystemClock()` (monotonic time survives device-clock corrections),
346
+ `createManualClock()` for tests and previews.
347
+ - `G9AbortSignal` is satisfied by a web `AbortSignal`; `createAbortController()` uses the runtime's controller and
348
+ falls back to a portable one (the Lynx typings do not declare `AbortController`).
349
+ - Contracts only (implementations come from the app and later packages): `G9SpeechToText` (`isAvailable`,
350
+ `requestPermission`, `listen` → `recognized` / `cancelled` / `no-match` / `denied`), `G9Scanner` (`scan` →
351
+ `scanned` / `cancelled` / `denied`), `G9MediaProvider` (images and video on every target), `G9HostServices` (exit,
352
+ `hideKeyboard`, safe insets, optional Android `setSoftInputMode`; the system back press arrives as a global event
353
+ that the WP02 provider dispatches). `G9Capabilities` lists them; `g9RequiredCapabilities` is `clock`,
354
+ `preferences`, `host`; `requireCapability` / `assertRequiredCapabilities` throw `G9CapabilityMissingError` (code
355
+ `capability-missing`, `capability` names it).
356
+
357
+ ### Enums
358
+
359
+ Every shared MAUI enum is a frozen const object plus a string union with camelCase values (specs/03 §1):
360
+ `G9ButtonVariant`, `G9ProgressType`, `G9ControlSize`, `G9TextInputDirection`, `G9FilledValueHighlight`,
361
+ `G9KeyboardType`, `G9DateTimePickerMode`, `G9DateTimeDisplayFormat`, `G9RangeSliderMode`, `G9PinEntryType`,
362
+ `G9ChipGroupSelectionMode`, `G9ChipGroupLayoutMode`, `G9ProgressLabelPlacement`, `G9SeparatorTitleAlignment`,
363
+ `G9TabMode`, `G9TabStyle`, `G9CascadeDirection`, `G9CascadeTransition`, `G9TabBarPosition` and `G9InputType` (the
364
+ filter and validation policy behind it ships with the fields in WP03).
365
+
366
+ ### Execution platform notes
367
+
368
+ No `Intl` anywhere; `no-intl.test.ts` runs this slice with `Intl` removed. Timers default to the runtime's
369
+ `setTimeout`; `performance.now` and `AbortController` are used when present and replaced otherwise, which has not
370
+ been checked on a PrimJS device yet. The actions run on the background thread; nothing here touches the main thread.