@plexui/styles 0.16.6 → 0.16.7
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/dist/es/tokens/index.js +5 -0
- package/dist/es/tokens/index.js.map +1 -0
- package/dist/es/tokens/resolve.js +744 -0
- package/dist/es/tokens/resolve.js.map +1 -0
- package/dist/es/tokens/tokens.generated.js +5818 -0
- package/dist/es/tokens/tokens.generated.js.map +1 -0
- package/dist/types/tokens/index.d.ts +19 -0
- package/dist/types/tokens/resolve.d.ts +143 -0
- package/dist/types/tokens/tokens.generated.d.ts +13 -0
- package/package.json +7 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plex UI design tokens for platforms that do not read CSS (React Native): `@plexui/styles/tokens`.
|
|
3
|
+
*
|
|
4
|
+
* The CSS token files stay the one source of truth; `tokens.generated.ts` is built from them by
|
|
5
|
+
* `scripts/build-tokens.mjs` (`npm run generate:tokens`), and tests/tokens keeps the two in step.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { createTokenResolver, tokenLayers, defaultTokenContext } from "@plexui/styles/tokens"
|
|
9
|
+
*
|
|
10
|
+
* const tokens = createTokenResolver(tokenLayers, defaultTokenContext, { "--color-accent": "#e5484d" })
|
|
11
|
+
* tokens.get("--color-text", "dark") // "#ffffff"
|
|
12
|
+
* tokens.get("--accent-500", "light") // the brand accent, darker by black 20%
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import type { TokenContext } from "./resolve.js";
|
|
16
|
+
export { createTokenResolver, declarationsFor, layerApplies, formatColor, mixColors, resolveValue, type ColorScheme, type LayerCondition, type TokenContext, type TokenLayer, type TokenResolver, type TokenValue, } from "./resolve.js";
|
|
17
|
+
export { resolvedTokens, skippedDeclarations, tokenLayers } from "./tokens.generated.js";
|
|
18
|
+
/** The context `resolvedTokens` was built for: a phone in portrait, high density, motion allowed. */
|
|
19
|
+
export declare const defaultTokenContext: TokenContext;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small evaluator of Plex UI token values, for platforms that do not read CSS (React Native).
|
|
3
|
+
*
|
|
4
|
+
* It resolves a custom property the way a browser does on `:root`: `var()` is substituted as text, then the value is
|
|
5
|
+
* evaluated for one color scheme. It knows the functions the token files use: `light-dark()`, `alpha()` and `spacing()`
|
|
6
|
+
* (the PostCSS functions of @plexui/styles), `color-mix()` in srgb and oklab, `rgb()`/`rgba()`, hex colors, `calc()`,
|
|
7
|
+
* `min()`, `max()`, `clamp()` and `env()`. Lengths come out in px (1rem = 16px; em only with a font size), times in ms.
|
|
8
|
+
* Anything else (a gradient, a curve, a font stack, a shadow list) comes back as text with its parts resolved.
|
|
9
|
+
*
|
|
10
|
+
* This file has no imports and only erasable TypeScript, so Node runs it as is (scripts/build-tokens.mjs).
|
|
11
|
+
*/
|
|
12
|
+
export type ColorScheme = "light" | "dark";
|
|
13
|
+
/** A resolved token: a color as `#rrggbb` or `rgba(r, g, b, a)`, a length in px, a time in ms, a number or text. */
|
|
14
|
+
export type TokenValue = string | number;
|
|
15
|
+
export type Color = {
|
|
16
|
+
r: number;
|
|
17
|
+
g: number;
|
|
18
|
+
b: number;
|
|
19
|
+
a: number;
|
|
20
|
+
};
|
|
21
|
+
export type Value = {
|
|
22
|
+
kind: "color";
|
|
23
|
+
color: Color;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "length";
|
|
26
|
+
px: number;
|
|
27
|
+
} | {
|
|
28
|
+
kind: "em";
|
|
29
|
+
em: number;
|
|
30
|
+
} | {
|
|
31
|
+
kind: "time";
|
|
32
|
+
ms: number;
|
|
33
|
+
} | {
|
|
34
|
+
kind: "number";
|
|
35
|
+
value: number;
|
|
36
|
+
} | {
|
|
37
|
+
kind: "percent";
|
|
38
|
+
value: number;
|
|
39
|
+
} | {
|
|
40
|
+
kind: "text";
|
|
41
|
+
text: string;
|
|
42
|
+
};
|
|
43
|
+
export type ResolveOptions = {
|
|
44
|
+
scheme: ColorScheme;
|
|
45
|
+
/** The font size an `em` is measured against. Without it a value in em stays text. */
|
|
46
|
+
fontSize?: number;
|
|
47
|
+
/** @default 16 */
|
|
48
|
+
rootFontSize?: number;
|
|
49
|
+
};
|
|
50
|
+
export type Node = {
|
|
51
|
+
type: "fn";
|
|
52
|
+
name: string;
|
|
53
|
+
args: Node[][];
|
|
54
|
+
} | {
|
|
55
|
+
type: "dim";
|
|
56
|
+
value: number;
|
|
57
|
+
unit: string;
|
|
58
|
+
} | {
|
|
59
|
+
type: "hash";
|
|
60
|
+
value: string;
|
|
61
|
+
} | {
|
|
62
|
+
type: "ident";
|
|
63
|
+
value: string;
|
|
64
|
+
} | {
|
|
65
|
+
type: "string";
|
|
66
|
+
value: string;
|
|
67
|
+
} | {
|
|
68
|
+
type: "op";
|
|
69
|
+
value: string;
|
|
70
|
+
} | {
|
|
71
|
+
type: "comma";
|
|
72
|
+
} | {
|
|
73
|
+
type: "paren";
|
|
74
|
+
nodes: Node[];
|
|
75
|
+
};
|
|
76
|
+
/** Parses a CSS value into nodes. Whitespace separates nodes; commas and operators are nodes of their own. */
|
|
77
|
+
export declare function parse(text: string): Node[];
|
|
78
|
+
export declare function stringify(nodes: Node[]): string;
|
|
79
|
+
export type Lookup = (name: string) => string | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Substitutes every `var()` in a value with the value of its property, recursively, as the browser does at computed
|
|
82
|
+
* value time. A missing or invalid property takes the fallback; a property in a cycle is invalid and so is every
|
|
83
|
+
* value of the cycle, fallbacks or not (CSS Variables 1, Resolving Dependency Cycles), while a value outside it that
|
|
84
|
+
* refers to it takes its fallback. `alpha()` and `spacing()` are expanded as the PostCSS functions of @plexui/styles
|
|
85
|
+
* expand them. `seen` is the chain of properties being resolved, the last one the property this value belongs to.
|
|
86
|
+
*/
|
|
87
|
+
export declare function substitute(text: string, lookup: Lookup, seen?: ReadonlySet<string>): Node[] | undefined;
|
|
88
|
+
/** sRGB (0-255) to OKLab. */
|
|
89
|
+
export declare function toOklab({ r, g, b }: Color): [number, number, number];
|
|
90
|
+
/** OKLab to sRGB (0-255, unclamped). */
|
|
91
|
+
export declare function fromOklab([L, A, B]: [number, number, number]): [number, number, number];
|
|
92
|
+
/** `color-mix()` after CSS Color 5: normalized percentages, premultiplied alpha, an alpha multiplier below 100%. */
|
|
93
|
+
export declare function mixColors(space: "srgb" | "oklab", c1: Color, p1: number | undefined, c2: Color, p2: number | undefined): Color | undefined;
|
|
94
|
+
export declare function formatColor({ r, g, b, a }: Color): string;
|
|
95
|
+
/** Evaluates a list of nodes (one space-separated component, or a whole value). */
|
|
96
|
+
export declare function evaluateNodes(nodes: Node[], options: ResolveOptions): Value | undefined;
|
|
97
|
+
export declare function serializeValue(value: Value | undefined): TokenValue | undefined;
|
|
98
|
+
/** Resolves one custom property for one scheme; `undefined` when it is invalid at computed value time. */
|
|
99
|
+
export declare function resolveValue(raw: string, lookup: Lookup, options: ResolveOptions, self?: string): TokenValue | undefined;
|
|
100
|
+
/** Where a layer applies: one color scheme, a range of window widths, a high pixel density or reduced motion. */
|
|
101
|
+
export type LayerCondition = {
|
|
102
|
+
scheme?: ColorScheme;
|
|
103
|
+
minWidth?: number;
|
|
104
|
+
maxWidth?: number;
|
|
105
|
+
highDensity?: boolean;
|
|
106
|
+
reducedMotion?: boolean;
|
|
107
|
+
};
|
|
108
|
+
/** Custom properties declared on the root under one condition, raw as written in the CSS. */
|
|
109
|
+
export type TokenLayer = {
|
|
110
|
+
id: string;
|
|
111
|
+
/** The CSS file. */
|
|
112
|
+
source: string;
|
|
113
|
+
/** 0 inside `@layer theme`, 1 unlayered (wins). */
|
|
114
|
+
rank: number;
|
|
115
|
+
specificity: readonly number[];
|
|
116
|
+
/** Source order of the layer's first declaration. */
|
|
117
|
+
order: number;
|
|
118
|
+
when?: LayerCondition;
|
|
119
|
+
tokens: Readonly<Record<string, string>>;
|
|
120
|
+
};
|
|
121
|
+
export type TokenContext = {
|
|
122
|
+
/** Window width in px: the phone layers of the CSS apply up to 767. */
|
|
123
|
+
width: number;
|
|
124
|
+
highDensity: boolean;
|
|
125
|
+
reducedMotion: boolean;
|
|
126
|
+
};
|
|
127
|
+
export declare function layerApplies(layer: TokenLayer, context: TokenContext, scheme: ColorScheme): boolean;
|
|
128
|
+
/** The declarations that win for a context and a scheme, then the overrides (a brand theme: as if set on `:root`). */
|
|
129
|
+
export declare function declarationsFor(layers: readonly TokenLayer[], context: TokenContext, scheme: ColorScheme, overrides?: Readonly<Record<string, string>>): Record<string, string>;
|
|
130
|
+
export type TokenResolver = {
|
|
131
|
+
/** The resolved value of a token (`"--color-text"`, or `"color-text"`), `undefined` when unknown or invalid. */
|
|
132
|
+
get(name: string, scheme: ColorScheme): TokenValue | undefined;
|
|
133
|
+
/** A value resolved at a font size, for tokens in em (the tracking of --font-sans). */
|
|
134
|
+
at(name: string, scheme: ColorScheme, fontSize: number): TokenValue | undefined;
|
|
135
|
+
/** Resolves any CSS value against the tokens (`"alpha(var(--gray-1000), 8%)"`). */
|
|
136
|
+
value(css: string, scheme: ColorScheme, fontSize?: number): TokenValue | undefined;
|
|
137
|
+
/** The raw declaration that wins. */
|
|
138
|
+
raw(name: string, scheme: ColorScheme): string | undefined;
|
|
139
|
+
/** Every token resolved; `null` marks a value invalid at computed value time. */
|
|
140
|
+
all(scheme: ColorScheme): Record<string, TokenValue | null>;
|
|
141
|
+
};
|
|
142
|
+
/** A resolver over the layers for one context. Values are resolved on first use and kept. */
|
|
143
|
+
export declare function createTokenResolver(layers: readonly TokenLayer[], context: TokenContext, overrides?: Readonly<Record<string, string>>): TokenResolver;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TokenLayer, TokenValue } from "./resolve.js";
|
|
2
|
+
/** The token layers in cascade order: later layers win where they apply. */
|
|
3
|
+
export declare const tokenLayers: readonly TokenLayer[];
|
|
4
|
+
/** Custom properties declared on other selectors, which are not tokens (a component's own context). */
|
|
5
|
+
export declare const skippedDeclarations = 122;
|
|
6
|
+
/**
|
|
7
|
+
* Every token resolved for a phone (393px wide, high density, motion allowed), in light and dark.
|
|
8
|
+
* `null` marks a value that is invalid at computed value time. A length is in px, a time in ms.
|
|
9
|
+
*/
|
|
10
|
+
export declare const resolvedTokens: {
|
|
11
|
+
readonly light: Readonly<Record<string, TokenValue | null>>;
|
|
12
|
+
readonly dark: Readonly<Record<string, TokenValue | null>>;
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plexui/styles",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.7",
|
|
4
4
|
"description": "Framework-agnostic CSS for Plex UI: design tokens, globals and component styles",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,6 +45,10 @@
|
|
|
45
45
|
"types": "./dist/types/types.d.ts",
|
|
46
46
|
"default": "./dist/es/types.js"
|
|
47
47
|
},
|
|
48
|
+
"./tokens": {
|
|
49
|
+
"types": "./dist/types/tokens/index.d.ts",
|
|
50
|
+
"default": "./dist/es/tokens/index.js"
|
|
51
|
+
},
|
|
48
52
|
"./postcss": "./postcss.config.mjs"
|
|
49
53
|
},
|
|
50
54
|
"scripts": {
|
|
@@ -55,7 +59,8 @@
|
|
|
55
59
|
"dev:css": "node ./scripts/build-css.mjs --watch",
|
|
56
60
|
"dev": "npm run build:clean && npm run build:js && npm run build:css && (npm run dev:js & npm run dev:css & wait)",
|
|
57
61
|
"build": "npm run build:clean && npm run build:js && npm run build:css",
|
|
58
|
-
"prepublishOnly": "npm run build"
|
|
62
|
+
"prepublishOnly": "npm run build",
|
|
63
|
+
"generate:tokens": "node ./scripts/build-tokens.mjs"
|
|
59
64
|
},
|
|
60
65
|
"peerDependencies": {
|
|
61
66
|
"@tailwindcss/postcss": "^4.0.10",
|