@animus-ui/system 0.1.1 → 0.1.3
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 +125 -4
- package/dist/Animus.d.ts +2 -3
- package/dist/Animus.d.ts.map +1 -1
- package/dist/AnimusExtended.d.ts +2 -3
- package/dist/AnimusExtended.d.ts.map +1 -1
- package/dist/SystemBuilder.d.ts +55 -8
- package/dist/SystemBuilder.d.ts.map +1 -1
- package/dist/appearance/index.d.ts +75 -0
- package/dist/appearance/index.d.ts.map +1 -0
- package/dist/appearance/index.js +179 -0
- package/dist/bootstrap/createAppearanceBootstrap.d.ts +71 -0
- package/dist/bootstrap/createAppearanceBootstrap.d.ts.map +1 -0
- package/dist/bootstrap/index.d.ts +2 -0
- package/dist/bootstrap/index.d.ts.map +1 -0
- package/dist/bootstrap/index.js +98 -0
- package/dist/composeWithContext.d.ts.map +1 -1
- package/dist/composeWithContext.js +43 -22
- package/dist/conditions.d.ts +163 -0
- package/dist/conditions.d.ts.map +1 -0
- package/dist/{createComposedFamily-DSE2ZuRE.js → createComposedFamily-DJ2aqfqN.js} +141 -67
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +648 -25
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/resolveClasses.d.ts.map +1 -1
- package/dist/runtime-entry.js +1 -1
- package/dist/selectors.d.ts +22 -0
- package/dist/selectors.d.ts.map +1 -1
- package/dist/theme/createTheme.d.ts +47 -4
- package/dist/theme/createTheme.d.ts.map +1 -1
- package/dist/types/component.d.ts +27 -10
- package/dist/types/component.d.ts.map +1 -1
- package/dist/types/config.d.ts +124 -11
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/props.d.ts +0 -4
- package/dist/types/props.d.ts.map +1 -1
- package/dist/types/theme.d.ts +132 -0
- package/dist/types/theme.d.ts.map +1 -1
- package/dist/utils/deepMerge.d.ts +0 -3
- package/dist/utils/deepMerge.d.ts.map +1 -1
- package/package.json +12 -4
package/README.md
CHANGED
|
@@ -136,12 +136,133 @@ ds.styles() → @layer base
|
|
|
136
136
|
|
|
137
137
|
The type system prevents calling methods out of order. `.variant()` after `.states()` is a type error.
|
|
138
138
|
|
|
139
|
+
## Color Modes
|
|
140
|
+
|
|
141
|
+
`addColorModes(initialMode, modeConfig)` emits a `[data-color-mode="…"]` block
|
|
142
|
+
per mode. An optional third argument opts the theme into OS participation:
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
const tokens = createTheme()
|
|
146
|
+
.addColors({ gray: { 100: '#f0f0f0', 800: '#1a1a1a' } })
|
|
147
|
+
.addColorModes(
|
|
148
|
+
'dark',
|
|
149
|
+
{
|
|
150
|
+
dark: { bg: 'gray.800', text: 'gray.100' },
|
|
151
|
+
light: { bg: 'gray.100', text: 'gray.800' },
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
// OS preference → declared mode name.
|
|
155
|
+
systemPreference: { light: 'light', dark: 'dark' },
|
|
156
|
+
// CSS `color-scheme` per mode. The two mapped modes default to
|
|
157
|
+
// 'light'/'dark' (the mapping forces them), so `{}` is the whole
|
|
158
|
+
// opt-in here; classify any ADDITIONAL modes explicitly.
|
|
159
|
+
browserColorScheme: {},
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
.build();
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**`systemPreference`** enables guarded fallback emission:
|
|
166
|
+
|
|
167
|
+
```css
|
|
168
|
+
@media (prefers-color-scheme: dark) {
|
|
169
|
+
:root:not([data-color-mode]) {
|
|
170
|
+
/* the dark mode's declarations */
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The `:not([data-color-mode])` guard is what makes an explicit attribute win — in
|
|
176
|
+
CSS alone, with no script. Both values must name declared modes.
|
|
177
|
+
|
|
178
|
+
**`browserColorScheme`** adds the CSS `color-scheme` property so native
|
|
179
|
+
scrollbars, form controls, and UA styling track the active mode. When supplied it
|
|
180
|
+
must classify _every_ declared mode, otherwise a mode would silently inherit the
|
|
181
|
+
previous one's native scheme — with one carve-out: the two modes named by
|
|
182
|
+
`systemPreference` are forced to `light`/`dark` by validation anyway, so they
|
|
183
|
+
default and may be omitted. An explicit entry on a mapped mode is honored and
|
|
184
|
+
still conflict-checked.
|
|
185
|
+
|
|
186
|
+
A theme that opts into neither emits exactly the bytes it emitted before.
|
|
187
|
+
|
|
188
|
+
### "System" is the absence of the attribute
|
|
189
|
+
|
|
190
|
+
There is no `data-color-mode="system"` — the OS-following state is the attribute
|
|
191
|
+
being **absent**, which is the only value the media guard above can fall through.
|
|
192
|
+
`system` is a reserved mode name and is rejected.
|
|
193
|
+
|
|
194
|
+
### The appearance record
|
|
195
|
+
|
|
196
|
+
Persisted appearance lives under one versioned key, `animus:appearance`:
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
{ "v": 1, "mode": "system" | "<mode name>", "theme": "default" }
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
The `theme` axis is reserved and currently ignored — a writer that owns only the
|
|
203
|
+
mode axis must preserve the fields it does not own. The package ships that
|
|
204
|
+
write discipline so you don't hand-roll it: `@animus-ui/system/appearance` is a
|
|
205
|
+
tiny, storage-only runtime subpath (no React, no listeners, no DOM — applying
|
|
206
|
+
`data-color-mode` stays yours):
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import {
|
|
210
|
+
SYSTEM_MODE,
|
|
211
|
+
migrateLegacyModeKey,
|
|
212
|
+
persistColorMode,
|
|
213
|
+
} from '@animus-ui/system/appearance';
|
|
214
|
+
|
|
215
|
+
persistColorMode('midnight'); // read-modify-write; unowned fields survive
|
|
216
|
+
persistColorMode(SYSTEM_MODE); // "follow the OS" — bootstrap restores absence
|
|
217
|
+
|
|
218
|
+
// One-shot: move YOUR app's old key into the record, then delete it.
|
|
219
|
+
migrateLegacyModeKey('my-app-color-mode', ['midnight', 'paper']);
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
It refuses to downgrade a record written by a newer version, and refuses to
|
|
223
|
+
migrate the shared `color-mode` key (that one may belong to another app on your
|
|
224
|
+
origin; the bootstrap already reads it, read-only).
|
|
225
|
+
|
|
226
|
+
To restore it before first paint, generate an inline snippet from the **built**
|
|
227
|
+
theme:
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
import { createAppearanceBootstrap } from '@animus-ui/system/bootstrap';
|
|
231
|
+
|
|
232
|
+
const { code, cspHash } = createAppearanceBootstrap(tokens, {
|
|
233
|
+
storageKey: 'animus:appearance', // default
|
|
234
|
+
});
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
`code` is a dependency-free IIFE for the document head: it reads the record,
|
|
238
|
+
validates `mode` against the theme's declared names, sets `data-color-mode` for a
|
|
239
|
+
valid explicit mode, and **removes** the attribute for `"system"`, a missing
|
|
240
|
+
record, or an unrecognized value — handing control back to the media query. It
|
|
241
|
+
never writes storage and never calls `matchMedia` (materializing the OS answer
|
|
242
|
+
into the attribute would freeze it against later OS changes). The pre-record
|
|
243
|
+
plain-string `color-mode` key is read once, only when the record is absent, and
|
|
244
|
+
is never written.
|
|
245
|
+
|
|
246
|
+
`cspHash` authorizes that exact script. Derive the header from the artifact at
|
|
247
|
+
build time and **single-quote** the value — `script-src 'sha256-…'`. Unquoted it
|
|
248
|
+
parses as a host source and silently blocks the script; hand-copied, it goes
|
|
249
|
+
stale the moment a mode is renamed.
|
|
250
|
+
|
|
251
|
+
This subpath is build tooling. It is never imported by the component or runtime
|
|
252
|
+
entries, so it cannot reach an extracted application bundle — generate the
|
|
253
|
+
artifact in your bundler config and hand it to the plugin
|
|
254
|
+
([`@animus-ui/vite-plugin`](https://github.com/codecaaron/animus/tree/main/packages/vite-plugin)
|
|
255
|
+
accepts `appearanceBootstrap`; in Next.js the application places `code` itself,
|
|
256
|
+
so it can control CSP nonce and ordering).
|
|
257
|
+
|
|
139
258
|
## Exports
|
|
140
259
|
|
|
141
|
-
| Path
|
|
142
|
-
|
|
|
143
|
-
| `@animus-ui/system`
|
|
144
|
-
| `@animus-ui/system/groups`
|
|
260
|
+
| Path | What's in it |
|
|
261
|
+
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
262
|
+
| `@animus-ui/system` | Full API — builder, theme, runtime, types |
|
|
263
|
+
| `@animus-ui/system/groups` | Pre-built prop groups: `space`, `color`, `typography`, `layout`, `flex`, `grid`, `border`, `shadows`, `background`, `positioning`, `transitions` |
|
|
264
|
+
| `@animus-ui/system/bootstrap` | `createAppearanceBootstrap` — build-time only, never imported by application code |
|
|
265
|
+
| `@animus-ui/system/appearance` | `persistColorMode`, `migrateLegacyModeKey`, `SYSTEM_MODE` — storage-only appearance record write path (runtime, client-safe) |
|
|
145
266
|
|
|
146
267
|
## License
|
|
147
268
|
|
package/dist/Animus.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
1
2
|
import { AnimusExtended } from './AnimusExtended';
|
|
2
3
|
import { AbstractParser, CompoundEntry, CSSPropMap, CSSProps, CustomPropConfig, Prop, SystemProps, ThemedCSSPropMap, ThemedCSSProps, VariantConfig } from './types/config';
|
|
3
4
|
import { AbstractProps } from './types/props';
|
|
@@ -14,9 +15,7 @@ export declare class AnimusWithAll<PropRegistry extends Record<string, Prop>, Gr
|
|
|
14
15
|
constructor(props: PropRegistry, groups: GroupRegistry, base: BaseStyles, variants: Variants, states: States, activeGroups: ActiveGroups, custom: CustomProps, compounds?: CompoundEntry[]);
|
|
15
16
|
extend(): AnimusExtended<PropRegistry, GroupRegistry, BaseStyles, Variants, States, ActiveGroups, CustomProps>;
|
|
16
17
|
asElement<El extends keyof JSX.IntrinsicElements>(component: El): AnimusComponent<El, PropRegistry, GroupRegistry, BaseStyles, Variants, States, ActiveGroups, CustomProps>;
|
|
17
|
-
asComponent<C extends (
|
|
18
|
-
className?: string;
|
|
19
|
-
}) => any>(AsComponent: C): AnimusWrappedComponent<PropRegistry, GroupRegistry, BaseStyles, Variants, States, ActiveGroups, CustomProps>;
|
|
18
|
+
asComponent<C extends ComponentType<any>>(AsComponent: C): AnimusWrappedComponent<C, PropRegistry, GroupRegistry, BaseStyles, Variants, States, ActiveGroups, CustomProps>;
|
|
20
19
|
asClass(): (props?: Record<string, unknown>) => string;
|
|
21
20
|
_buildComponentConfig(): {
|
|
22
21
|
variants: Record<string, {
|
package/dist/Animus.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Animus.d.ts","sourceRoot":"","sources":["../src/Animus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EACL,cAAc,EACd,aAAa,EACb,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,IAAI,EACJ,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,aAAa,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG9C,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAE3B,qBAAa,aAAa,CACxB,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EACzC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,YAAY,CAAC,EAAE,CAAC,EAC5D,UAAU,SAAS,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC,EACvE,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC9C,MAAM,SAAS,UAAU,CAAC,aAAa,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC,EACrE,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EACzC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;IAExC,YAAY,EAAS,YA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AM,KAAK,EAAE,MAAM,CAAC;eACtC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC;kBAC/B,gBAAgB,CAAC,KAAK,EAAE,YAAY,CAAC;QAiBhD;CACF;AAED,qBAAa,MAAM,CACjB,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EACzC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,YAAY,CAAC,EAAE,CAAC,CAC5D,SAAQ,cAAc,CAAC,YAAY,EAAE,aAAa,EAAE,EAAE,CAAC;IACvD,YAAY,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAErD;IACD,MAAM,CAAC,KAAK,SAAS,aAAa,EAChC,MAAM,EAAE,cAAc,CAAC,KAAK,EAAE,YAAY,CAAC,oFAO5C;CACF"}
|
package/dist/AnimusExtended.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
1
2
|
import { AbstractParser, CompoundEntry, CSSPropMap, CSSProps, CustomPropConfig, Prop, SystemProps, ThemedCSSPropMap, ThemedCSSProps, VariantConfig } from './types/config';
|
|
2
3
|
import { AbstractProps } from './types/props';
|
|
3
4
|
import type { AnimusComponent, AnimusWrappedComponent } from './types/component';
|
|
@@ -13,9 +14,7 @@ export declare class AnimusExtendedWithAll<PropRegistry extends Record<string, P
|
|
|
13
14
|
constructor(props: PropRegistry, groups: GroupRegistry, base: BaseStyles, variants: Variants, states: States, activeGroups: ActiveGroups, custom: CustomProps, compounds?: CompoundEntry[]);
|
|
14
15
|
extend(): AnimusExtended<PropRegistry, GroupRegistry, BaseStyles, Variants, States, ActiveGroups, CustomProps>;
|
|
15
16
|
asElement<El extends keyof JSX.IntrinsicElements>(component: El): AnimusComponent<El, PropRegistry, GroupRegistry, BaseStyles, Variants, States, ActiveGroups, CustomProps>;
|
|
16
|
-
asComponent<C extends (
|
|
17
|
-
className?: string;
|
|
18
|
-
}) => any>(AsComponent: C): AnimusWrappedComponent<PropRegistry, GroupRegistry, BaseStyles, Variants, States, ActiveGroups, CustomProps>;
|
|
17
|
+
asComponent<C extends ComponentType<any>>(AsComponent: C): AnimusWrappedComponent<C, PropRegistry, GroupRegistry, BaseStyles, Variants, States, ActiveGroups, CustomProps>;
|
|
19
18
|
asClass(): (props?: Record<string, unknown>) => string;
|
|
20
19
|
_buildComponentConfig(): {
|
|
21
20
|
variants: Record<string, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimusExtended.d.ts","sourceRoot":"","sources":["../src/AnimusExtended.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AnimusExtended.d.ts","sourceRoot":"","sources":["../src/AnimusExtended.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI3C,OAAO,EACL,cAAc,EACd,aAAa,EACb,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,IAAI,EACJ,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,aAAa,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG9C,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAE3B,qBAAa,qBAAqB,CAChC,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EACzC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,YAAY,CAAC,EAAE,CAAC,EAC5D,UAAU,SAAS,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC,EACvE,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC9C,MAAM,SAAS,UAAU,CAAC,aAAa,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC,EACrE,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EACzC,WAAW,SAAS,MAAM,CAA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CAAC;kBAC/B,gBAAgB,CAAC,KAAK,EAAE,YAAY,CAAC;2CAsBhD;CACF;AAED,qBAAa,cAAc,CACzB,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EACzC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,YAAY,CAAC,EAAE,CAAC,EAC5D,UAAU,SAAS,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC,EACvE,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC9C,MAAM,SAAS,UAAU,CAAC,aAAa,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC,EACrE,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EACzC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CACxC,SAAQ,sBAAsB,CAC9B,YAAY,EACZ,aAAa,EACb,UAAU,EACV,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,WAAW,CACZ;IACC,MAAM,CAAC,KAAK,SAAS,aAAa,EAChC,MAAM,EAAE,cAAc,CAAC,KAAK,EAAE,YAAY,CAAC,sJAoB5C;CACF"}
|
package/dist/SystemBuilder.d.ts
CHANGED
|
@@ -1,16 +1,45 @@
|
|
|
1
1
|
import { Animus } from './Animus';
|
|
2
|
+
import { type ConditionAliasMap, type RegistryBrand } from './conditions';
|
|
2
3
|
import { type KeyframeFrameMap, type Keyframes } from './keyframes';
|
|
3
4
|
import { type SelectorAliasMap } from './selectors';
|
|
4
5
|
import { NamedTransform } from './transforms/createTransform';
|
|
5
6
|
import { Prop, ThemedCSSProps } from './types/config';
|
|
6
7
|
import { AbstractProps } from './types/props';
|
|
7
8
|
export type GlobalStyleMap = Record<string, Record<string, any>>;
|
|
9
|
+
/** One `src` descriptor of a font-face resource. */
|
|
10
|
+
export interface FontFaceSrc {
|
|
11
|
+
/**
|
|
12
|
+
* Emitted byte-exact as authored — asset resolution and rewriting belong
|
|
13
|
+
* to the host bundler's CSS asset pipeline, not to extraction.
|
|
14
|
+
*/
|
|
15
|
+
url: string;
|
|
16
|
+
/** Format hint (`woff2`, `woff`, …), rendered as `format('…')`. */
|
|
17
|
+
format?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A typed `@font-face` descriptor (global-styles-system). `family` may use a
|
|
21
|
+
* font-scale token reference (`{fonts.body}`); other descriptors take CSS
|
|
22
|
+
* literals only.
|
|
23
|
+
*/
|
|
24
|
+
export interface FontFace {
|
|
25
|
+
family: string;
|
|
26
|
+
src: FontFaceSrc[];
|
|
27
|
+
weight?: string;
|
|
28
|
+
style?: string;
|
|
29
|
+
display?: string;
|
|
30
|
+
unicodeRange?: string;
|
|
31
|
+
stretch?: string;
|
|
32
|
+
}
|
|
8
33
|
export interface GlobalStyleBlock {
|
|
9
34
|
__brand: 'GlobalStyleBlock';
|
|
10
35
|
styles: GlobalStyleMap;
|
|
36
|
+
/** Rendered ahead of the block's selector rules in `@layer anm-global`. */
|
|
37
|
+
fontFaces?: FontFace[];
|
|
11
38
|
}
|
|
12
39
|
export type GlobalStylesFactory<PropReg extends Record<string, Prop> = Record<string, Prop>> = <Map extends Record<string, AbstractProps>>(styles: {
|
|
13
40
|
readonly [K in keyof Map]: ThemedCSSProps<Map[K], PropReg>;
|
|
41
|
+
}, options?: {
|
|
42
|
+
fontFaces?: readonly FontFace[];
|
|
14
43
|
}) => GlobalStyleBlock;
|
|
15
44
|
export type CreateKeyframesFactory<PropReg extends Record<string, Prop> = Record<string, Prop>> = <Frames extends Record<string, Record<string, AbstractProps>>>(frames: {
|
|
16
45
|
readonly [N in keyof Frames]: {
|
|
@@ -25,26 +54,44 @@ type IncludableSystem = {
|
|
|
25
54
|
export interface CreateSystemConfig {
|
|
26
55
|
includes?: readonly IncludableSystem[];
|
|
27
56
|
}
|
|
28
|
-
export declare class SystemBuilder<PropReg extends Record<string, Prop> = {}, GroupReg extends Record<string, (keyof PropReg)[]> = {}> {
|
|
57
|
+
export declare class SystemBuilder<PropReg extends Record<string, Prop> = {}, GroupReg extends Record<string, (keyof PropReg)[]> = {}, Conds extends string = never, Sels extends string = never> {
|
|
29
58
|
#private;
|
|
30
|
-
constructor(propRegistry?: PropReg, groupRegistry?: GroupReg, selectorRegistry?: SelectorAliasMap, includesRegistry?: readonly IncludableSystem[]);
|
|
31
|
-
addSelectors
|
|
32
|
-
|
|
33
|
-
|
|
59
|
+
constructor(propRegistry?: PropReg, groupRegistry?: GroupReg, selectorRegistry?: SelectorAliasMap, includesRegistry?: readonly IncludableSystem[], conditionRegistry?: ConditionAliasMap);
|
|
60
|
+
addSelectors<S extends Record<`_${string}`, string>>(selectors: S): SystemBuilder<PropReg, GroupReg, Conds, Sels | Extract<keyof S, string>>;
|
|
61
|
+
/**
|
|
62
|
+
* Register condition aliases (`_motionReduce`, `_cardSm`, …) → at-rule
|
|
63
|
+
* condition strings (`@media …` / `@container …` / `@supports …`).
|
|
64
|
+
* Recognized as block keys in style objects; user aliases override built-ins
|
|
65
|
+
* of the same name (design D3). Keys are constrained to `_`-prefixed aliases
|
|
66
|
+
* and values to `@`-prefixed at-rule strings — a value that does not begin
|
|
67
|
+
* with an at-rule name is a compile-time type error (design D9; the runtime
|
|
68
|
+
* `inferConditionKind` throw is defense-in-depth). The registered keys are
|
|
69
|
+
* accumulated into the phantom `Conds` union and surfaced on `build()`.
|
|
70
|
+
*/
|
|
71
|
+
addConditions<C extends Record<`_${string}`, `@media${string}` | `@container${string}` | `@supports${string}`>>(conditions: C): SystemBuilder<PropReg, GroupReg, Conds | Extract<keyof C, string>, Sels>;
|
|
72
|
+
addGroup<Name extends string, Conf extends Record<string, Prop>>(name: Name extends keyof PropReg ? never : Name, config: Conf): SystemBuilder<PropReg & Conf, GroupReg & Record<Name, (keyof Conf)[]>, Conds, Sels>;
|
|
73
|
+
addProps<Conf extends Record<string, Prop> & Partial<Record<Extract<keyof GroupReg, string>, never>>>(config: Conf): SystemBuilder<PropReg & Conf, GroupReg, Conds, Sels>;
|
|
34
74
|
build(): {
|
|
35
|
-
system: SystemInstance<PropReg, GroupReg>;
|
|
75
|
+
system: SystemInstance<PropReg, GroupReg, Conds, Sels>;
|
|
36
76
|
createGlobalStyles: GlobalStylesFactory<PropReg>;
|
|
37
77
|
createKeyframes: CreateKeyframesFactory<PropReg>;
|
|
38
78
|
};
|
|
39
79
|
}
|
|
40
|
-
export type SystemInstance<PropReg extends Record<string, Prop>, GroupReg extends Record<string, (keyof PropReg)[]
|
|
80
|
+
export type SystemInstance<PropReg extends Record<string, Prop>, GroupReg extends Record<string, (keyof PropReg)[]>, Conds extends string = never, Sels extends string = never> = Animus<PropReg, GroupReg> & {
|
|
41
81
|
toConfig(): SerializedConfig;
|
|
42
|
-
}
|
|
82
|
+
} & RegistryBrand<Conds, Sels>;
|
|
43
83
|
export interface SerializedConfig {
|
|
44
84
|
propConfig: string;
|
|
45
85
|
groupRegistry: string;
|
|
46
86
|
transforms: Record<string, NamedTransform>;
|
|
47
87
|
selectorAliases: string;
|
|
88
|
+
/**
|
|
89
|
+
* Condition alias map JSON (inc 03 — NEW field): `alias → { value, order,
|
|
90
|
+
* kind }`. `"{}"` when the system registers no conditions (built-ins are
|
|
91
|
+
* empty this increment). Distinct from `selectorAliases`, which stays
|
|
92
|
+
* byte-for-byte unchanged.
|
|
93
|
+
*/
|
|
94
|
+
conditionAliases: string;
|
|
48
95
|
}
|
|
49
96
|
export declare function createSystem(config?: CreateSystemConfig): SystemBuilder;
|
|
50
97
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SystemBuilder.d.ts","sourceRoot":"","sources":["../src/SystemBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,SAAS,EAEf,MAAM,aAAa,CAAC;AACrB,OAAO,EAGL,KAAK,gBAAgB,EAEtB,MAAM,aAAa,CA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AAQ,IAAI,gBAAgB,CAAC;CAC9B,GAAG,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAE/B,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC3C,eAAe,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AA4DD,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,aAAa,CAOvE"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Appearance record write path — the CLIENT half of the contract the generated
|
|
3
|
+
* bootstrap reads (openspec: color-mode-bootstrap, "Appearance record
|
|
4
|
+
* contract").
|
|
5
|
+
*
|
|
6
|
+
* This module is runtime application code: it ships in client bundles and owns
|
|
7
|
+
* only the record WRITE path. It deliberately imports nothing from
|
|
8
|
+
* `@animus-ui/system/bootstrap` — that subpath is build tooling, reaches
|
|
9
|
+
* `node:crypto`, and must never enter an application bundle — so the two
|
|
10
|
+
* modules re-state the key and shape they agree on, and the round-trip tests
|
|
11
|
+
* pin the agreement (a record written here is restored by the generated
|
|
12
|
+
* snippet).
|
|
13
|
+
*
|
|
14
|
+
* Record: `animus:appearance` → `{"v":1,"mode":…,"theme":…}`.
|
|
15
|
+
*
|
|
16
|
+
* Two axes share one record. A writer that changes ONE axis reads, modifies
|
|
17
|
+
* and writes back, so fields it does not own (`theme`, plus anything a future
|
|
18
|
+
* version adds) survive untouched.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Mode value meaning "follow the OS". It is never a declared mode and never
|
|
22
|
+
* reaches `data-color-mode` — the OS is followed by the attribute's ABSENCE,
|
|
23
|
+
* which the generated bootstrap restores when it reads this value.
|
|
24
|
+
*/
|
|
25
|
+
export declare const SYSTEM_MODE = "system";
|
|
26
|
+
export interface AppearanceStorageOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Overrides the record key. MUST match the `storageKey` the bootstrap
|
|
29
|
+
* artifact was generated with, or the snippet restores from a key this
|
|
30
|
+
* module never writes. Defaults to `animus:appearance`.
|
|
31
|
+
*/
|
|
32
|
+
storageKey?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Persists the mode axis, preserving every field this call does not own
|
|
36
|
+
* (`v`, `theme`, and any additional keys already in the record).
|
|
37
|
+
*
|
|
38
|
+
* Pass {@link SYSTEM_MODE} to persist "follow the OS" — the generated
|
|
39
|
+
* bootstrap restores it as attribute absence. Applying the mode to the
|
|
40
|
+
* document (setting or removing `data-color-mode`) stays the caller's job:
|
|
41
|
+
* this module is storage-only and never touches the DOM.
|
|
42
|
+
*
|
|
43
|
+
* REFUSAL RULE: when the stored record carries a version this code does not
|
|
44
|
+
* understand, NOTHING is written. Downgrading it to a v1 shape would drop
|
|
45
|
+
* whatever fields the newer writer keeps there, and this axis is not worth
|
|
46
|
+
* that. A caller that has already updated the attribute keeps the user's
|
|
47
|
+
* choice for the session — only its persistence is skipped.
|
|
48
|
+
*
|
|
49
|
+
* Storage failures are likewise swallowed: persistence is a convenience, and
|
|
50
|
+
* the attribute write that accompanies it has already taken effect.
|
|
51
|
+
*/
|
|
52
|
+
export declare function persistColorMode(mode: string, options?: AppearanceStorageOptions): void;
|
|
53
|
+
/**
|
|
54
|
+
* One-shot migration of an application's OWN historical mode key into the
|
|
55
|
+
* record.
|
|
56
|
+
*
|
|
57
|
+
* The generated bootstrap only knows the record and the contract's `color-mode`
|
|
58
|
+
* key — an app that persisted under its own key before adopting the record
|
|
59
|
+
* would silently drop every returning visitor's mode without this. Run it
|
|
60
|
+
* post-paint from the app entry: the visit on which it migrates still paints
|
|
61
|
+
* in the OS-resolved mode before correcting itself — one accepted flash, once
|
|
62
|
+
* — and every later load restores pre-paint through the bootstrap.
|
|
63
|
+
*
|
|
64
|
+
* It writes only when there is nothing to lose (no record) and something worth
|
|
65
|
+
* keeping (a value in `declaredModes`), then DELETES the old key so the
|
|
66
|
+
* migration cannot run twice or resurrect a stale value. Deleting is
|
|
67
|
+
* legitimate precisely because the key is the application's own; the
|
|
68
|
+
* contract's `color-mode` key may belong to another app on this origin and is
|
|
69
|
+
* refused, as is the record key itself.
|
|
70
|
+
*
|
|
71
|
+
* @returns the migrated mode name, so the caller can apply it to the document
|
|
72
|
+
* for this one visit, or `null` when nothing was migrated.
|
|
73
|
+
*/
|
|
74
|
+
export declare function migrateLegacyModeKey(legacyKey: string, declaredModes: readonly string[], options?: AppearanceStorageOptions): string | null;
|
|
75
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/appearance/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAgBH;;;;GAIG;AACH,eAAO,MAAM,WAAW,WAAW,CAAC;AASpC,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAkFD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,wBAAwB,GACjC,IAAI,CAWN;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,OAAO,CAAC,EAAE,wBAAwB,GACjC,MAAM,GAAG,IAAI,CAmDf"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
//#region src/appearance/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Appearance record write path — the CLIENT half of the contract the generated
|
|
4
|
+
* bootstrap reads (openspec: color-mode-bootstrap, "Appearance record
|
|
5
|
+
* contract").
|
|
6
|
+
*
|
|
7
|
+
* This module is runtime application code: it ships in client bundles and owns
|
|
8
|
+
* only the record WRITE path. It deliberately imports nothing from
|
|
9
|
+
* `@animus-ui/system/bootstrap` — that subpath is build tooling, reaches
|
|
10
|
+
* `node:crypto`, and must never enter an application bundle — so the two
|
|
11
|
+
* modules re-state the key and shape they agree on, and the round-trip tests
|
|
12
|
+
* pin the agreement (a record written here is restored by the generated
|
|
13
|
+
* snippet).
|
|
14
|
+
*
|
|
15
|
+
* Record: `animus:appearance` → `{"v":1,"mode":…,"theme":…}`.
|
|
16
|
+
*
|
|
17
|
+
* Two axes share one record. A writer that changes ONE axis reads, modifies
|
|
18
|
+
* and writes back, so fields it does not own (`theme`, plus anything a future
|
|
19
|
+
* version adds) survive untouched.
|
|
20
|
+
*/
|
|
21
|
+
/** The single versioned appearance record key. */
|
|
22
|
+
const DEFAULT_STORAGE_KEY = "animus:appearance";
|
|
23
|
+
/**
|
|
24
|
+
* The CONTRACT's pre-record key. The generated bootstrap reads it once, only
|
|
25
|
+
* when the record is absent, and never writes it — it may belong to another
|
|
26
|
+
* app on this origin, so this module refuses to migrate (and therefore
|
|
27
|
+
* delete) it. See {@link migrateLegacyModeKey}.
|
|
28
|
+
*/
|
|
29
|
+
const CONTRACT_LEGACY_KEY = "color-mode";
|
|
30
|
+
/** The only appearance-record version this module writes or read-modify-writes. */
|
|
31
|
+
const RECORD_VERSION = 1;
|
|
32
|
+
/**
|
|
33
|
+
* Mode value meaning "follow the OS". It is never a declared mode and never
|
|
34
|
+
* reaches `data-color-mode` — the OS is followed by the attribute's ABSENCE,
|
|
35
|
+
* which the generated bootstrap restores when it reads this value.
|
|
36
|
+
*/
|
|
37
|
+
const SYSTEM_MODE = "system";
|
|
38
|
+
/** Applied when nothing is stored: OS-driven mode, default theme. */
|
|
39
|
+
const DEFAULT_RECORD = {
|
|
40
|
+
v: RECORD_VERSION,
|
|
41
|
+
mode: SYSTEM_MODE,
|
|
42
|
+
theme: "default"
|
|
43
|
+
};
|
|
44
|
+
function storageOf() {
|
|
45
|
+
return globalThis.localStorage;
|
|
46
|
+
}
|
|
47
|
+
function keyOf(options) {
|
|
48
|
+
const key = options?.storageKey ?? DEFAULT_STORAGE_KEY;
|
|
49
|
+
if (typeof key !== "string" || key === "") throw new Error("appearance: storageKey must be a non-empty string.");
|
|
50
|
+
return key;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Reads the stored record.
|
|
54
|
+
*
|
|
55
|
+
* READ FAILURE vs. ABSENT: a `getItem` that THROWS (blocked or partitioned
|
|
56
|
+
* storage) — or no storage object at all — is reported as `absent`, not
|
|
57
|
+
* `foreign`, deliberately. "Absent" here means "this code has no knowledge of
|
|
58
|
+
* a stored record", and a store we cannot read at all is indistinguishable
|
|
59
|
+
* from an empty one. The asymmetry is safe because the accompanying write is
|
|
60
|
+
* wrapped in its own try/catch: a store that throws on read throws on write
|
|
61
|
+
* too, so the `absent` classification can never actually clobber anything.
|
|
62
|
+
* Only a store we CAN read and whose content we cannot interpret yields
|
|
63
|
+
* `foreign`.
|
|
64
|
+
*
|
|
65
|
+
* A present-but-corrupt value (not JSON, not an object) is `absent`: it is
|
|
66
|
+
* nobody's live state, so replacing it with a clean record is a repair. A
|
|
67
|
+
* present record carrying an unrecognized `v` is `foreign`: that is a future
|
|
68
|
+
* writer's data, and v1-shaped fields written over it would destroy fields
|
|
69
|
+
* this version does not know exist.
|
|
70
|
+
*/
|
|
71
|
+
function readRecord(storageKey) {
|
|
72
|
+
let raw = null;
|
|
73
|
+
try {
|
|
74
|
+
raw = storageOf()?.getItem(storageKey) ?? null;
|
|
75
|
+
} catch {
|
|
76
|
+
return { kind: "absent" };
|
|
77
|
+
}
|
|
78
|
+
if (typeof raw !== "string" || raw === "") return { kind: "absent" };
|
|
79
|
+
let parsed;
|
|
80
|
+
try {
|
|
81
|
+
parsed = JSON.parse(raw);
|
|
82
|
+
} catch {
|
|
83
|
+
return { kind: "absent" };
|
|
84
|
+
}
|
|
85
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return { kind: "absent" };
|
|
86
|
+
const record = parsed;
|
|
87
|
+
if (record.v !== RECORD_VERSION) return { kind: "foreign" };
|
|
88
|
+
return {
|
|
89
|
+
kind: "record",
|
|
90
|
+
record
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Persists the mode axis, preserving every field this call does not own
|
|
95
|
+
* (`v`, `theme`, and any additional keys already in the record).
|
|
96
|
+
*
|
|
97
|
+
* Pass {@link SYSTEM_MODE} to persist "follow the OS" — the generated
|
|
98
|
+
* bootstrap restores it as attribute absence. Applying the mode to the
|
|
99
|
+
* document (setting or removing `data-color-mode`) stays the caller's job:
|
|
100
|
+
* this module is storage-only and never touches the DOM.
|
|
101
|
+
*
|
|
102
|
+
* REFUSAL RULE: when the stored record carries a version this code does not
|
|
103
|
+
* understand, NOTHING is written. Downgrading it to a v1 shape would drop
|
|
104
|
+
* whatever fields the newer writer keeps there, and this axis is not worth
|
|
105
|
+
* that. A caller that has already updated the attribute keeps the user's
|
|
106
|
+
* choice for the session — only its persistence is skipped.
|
|
107
|
+
*
|
|
108
|
+
* Storage failures are likewise swallowed: persistence is a convenience, and
|
|
109
|
+
* the attribute write that accompanies it has already taken effect.
|
|
110
|
+
*/
|
|
111
|
+
function persistColorMode(mode, options) {
|
|
112
|
+
const storageKey = keyOf(options);
|
|
113
|
+
const outcome = readRecord(storageKey);
|
|
114
|
+
if (outcome.kind === "foreign") return;
|
|
115
|
+
const base = outcome.kind === "record" ? outcome.record : DEFAULT_RECORD;
|
|
116
|
+
try {
|
|
117
|
+
storageOf()?.setItem(storageKey, JSON.stringify({
|
|
118
|
+
...base,
|
|
119
|
+
mode
|
|
120
|
+
}));
|
|
121
|
+
} catch {}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* One-shot migration of an application's OWN historical mode key into the
|
|
125
|
+
* record.
|
|
126
|
+
*
|
|
127
|
+
* The generated bootstrap only knows the record and the contract's `color-mode`
|
|
128
|
+
* key — an app that persisted under its own key before adopting the record
|
|
129
|
+
* would silently drop every returning visitor's mode without this. Run it
|
|
130
|
+
* post-paint from the app entry: the visit on which it migrates still paints
|
|
131
|
+
* in the OS-resolved mode before correcting itself — one accepted flash, once
|
|
132
|
+
* — and every later load restores pre-paint through the bootstrap.
|
|
133
|
+
*
|
|
134
|
+
* It writes only when there is nothing to lose (no record) and something worth
|
|
135
|
+
* keeping (a value in `declaredModes`), then DELETES the old key so the
|
|
136
|
+
* migration cannot run twice or resurrect a stale value. Deleting is
|
|
137
|
+
* legitimate precisely because the key is the application's own; the
|
|
138
|
+
* contract's `color-mode` key may belong to another app on this origin and is
|
|
139
|
+
* refused, as is the record key itself.
|
|
140
|
+
*
|
|
141
|
+
* @returns the migrated mode name, so the caller can apply it to the document
|
|
142
|
+
* for this one visit, or `null` when nothing was migrated.
|
|
143
|
+
*/
|
|
144
|
+
function migrateLegacyModeKey(legacyKey, declaredModes, options) {
|
|
145
|
+
const storageKey = keyOf(options);
|
|
146
|
+
if (legacyKey === CONTRACT_LEGACY_KEY) throw new Error(`appearance: '${CONTRACT_LEGACY_KEY}' is the contract's shared legacy key — the generated bootstrap reads it read-only and it may belong to another app on this origin. Migrate only keys your application owns.`);
|
|
147
|
+
if (legacyKey === storageKey) throw new Error(`appearance: legacyKey '${legacyKey}' is the record key itself — nothing to migrate.`);
|
|
148
|
+
const forget = () => {
|
|
149
|
+
try {
|
|
150
|
+
storageOf()?.removeItem(legacyKey);
|
|
151
|
+
} catch {}
|
|
152
|
+
};
|
|
153
|
+
if (readRecord(storageKey).kind !== "absent") {
|
|
154
|
+
forget();
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
let legacy = null;
|
|
158
|
+
try {
|
|
159
|
+
legacy = storageOf()?.getItem(legacyKey) ?? null;
|
|
160
|
+
} catch {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
if (typeof legacy !== "string" || !declaredModes.includes(legacy)) {
|
|
164
|
+
if (legacy !== null) forget();
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
storageOf()?.setItem(storageKey, JSON.stringify({
|
|
169
|
+
...DEFAULT_RECORD,
|
|
170
|
+
mode: legacy
|
|
171
|
+
}));
|
|
172
|
+
} catch {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
forget();
|
|
176
|
+
return legacy;
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
export { SYSTEM_MODE, migrateLegacyModeKey, persistColorMode };
|