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