@wirecore/wirelayer-tokens 0.4.0 → 0.5.1
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 +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/resolve.d.ts +13 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +58 -0
- package/dist/resolve.js.map +1 -0
- package/dist/theme.css +6 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/resolve.ts +59 -0
package/README.md
CHANGED
|
@@ -8,8 +8,13 @@ Design tokens of WireLayer – colors, radii, typography, size grid, local fonts
|
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
+
With npm, pnpm, Yarn or Bun:
|
|
12
|
+
|
|
11
13
|
```sh
|
|
14
|
+
npm install @wirecore/wirelayer-tokens
|
|
12
15
|
pnpm add @wirecore/wirelayer-tokens
|
|
16
|
+
yarn add @wirecore/wirelayer-tokens
|
|
17
|
+
bun add @wirecore/wirelayer-tokens
|
|
13
18
|
```
|
|
14
19
|
|
|
15
20
|
## Usage
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { checkTheme, contrastPairs, suggestThemeFixes, type ContrastFix, type Co
|
|
|
3
3
|
export { colorDeclarations, themeToCss } from './css.js';
|
|
4
4
|
export { nativeExtraThemes, nativeFonts, nativeThemeName, themeToNativeCss } from './native.js';
|
|
5
5
|
export { contrast, inGamut, luminance, oklchToRgb, over, parse, rgbToOklch, toHex, type Rgba } from './color.js';
|
|
6
|
+
export { resolveTokens, watchTokens } from './resolve.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAC;AAC5B,OAAO,EACH,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,kBAAkB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAC;AAC5B,OAAO,EACH,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,kBAAkB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AACjH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,4 +4,5 @@ export { checkTheme, contrastPairs, suggestThemeFixes, } from './contrast.js';
|
|
|
4
4
|
export { colorDeclarations, themeToCss } from './css.js';
|
|
5
5
|
export { nativeExtraThemes, nativeFonts, nativeThemeName, themeToNativeCss } from './native.js';
|
|
6
6
|
export { contrast, inGamut, luminance, oklchToRgb, over, parse, rgbToOklch, toHex } from './color.js';
|
|
7
|
+
export { resolveTokens, watchTokens } from './resolve.js';
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAC7G,cAAc,aAAa,CAAC;AAC5B,OAAO,EACH,UAAU,EACV,aAAa,EACb,iBAAiB,GAIpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAa,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAC7G,cAAc,aAAa,CAAC;AAC5B,OAAO,EACH,UAAU,EACV,aAAa,EACb,iBAAiB,GAIpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAa,MAAM,YAAY,CAAC;AACjH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ColorSet } from './tokens.js';
|
|
2
|
+
/**
|
|
3
|
+
* The colours of the tokens as they apply to `element` right now (mode, theme and own overrides included): hex,
|
|
4
|
+
* `#rrggbbaa` for translucent ones (line, glow). A value the browser cannot paint stays as written.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveTokens(element?: Element): ColorSet;
|
|
7
|
+
/**
|
|
8
|
+
* Calls `onChange` whenever the token colours may have changed: another mode or theme on the page (`data-mode`,
|
|
9
|
+
* `data-theme`, `class`, `style` of <html> and <body>) or another system colour scheme. Returns the function that
|
|
10
|
+
* stops it. Browser only.
|
|
11
|
+
*/
|
|
12
|
+
export declare function watchTokens(onChange: () => void): () => void;
|
|
13
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEzD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,OAAkC,GAAG,QAAQ,CAKnF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAW5D"}
|
package/dist/resolve.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// The colour tokens as fixed values at runtime – for canvas libraries (xterm.js, charts) that cannot read CSS
|
|
2
|
+
// variables. Browser only.
|
|
3
|
+
import { parse, toHex } from './color.js';
|
|
4
|
+
import { colorTokens } from './tokens.js';
|
|
5
|
+
/**
|
|
6
|
+
* The colours of the tokens as they apply to `element` right now (mode, theme and own overrides included): hex,
|
|
7
|
+
* `#rrggbbaa` for translucent ones (line, glow). A value the browser cannot paint stays as written.
|
|
8
|
+
*/
|
|
9
|
+
export function resolveTokens(element = document.documentElement) {
|
|
10
|
+
const style = getComputedStyle(element);
|
|
11
|
+
return Object.fromEntries(colorTokens.map((token) => [token, toFixedColor(style.getPropertyValue(`--wc-${token}`).trim())]));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Calls `onChange` whenever the token colours may have changed: another mode or theme on the page (`data-mode`,
|
|
15
|
+
* `data-theme`, `class`, `style` of <html> and <body>) or another system colour scheme. Returns the function that
|
|
16
|
+
* stops it. Browser only.
|
|
17
|
+
*/
|
|
18
|
+
export function watchTokens(onChange) {
|
|
19
|
+
const observer = new MutationObserver(onChange);
|
|
20
|
+
const attributeFilter = ['data-mode', 'data-theme', 'class', 'style'];
|
|
21
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter });
|
|
22
|
+
if (document.body)
|
|
23
|
+
observer.observe(document.body, { attributes: true, attributeFilter });
|
|
24
|
+
const scheme = typeof matchMedia === 'function' ? matchMedia('(prefers-color-scheme: dark)') : undefined;
|
|
25
|
+
scheme?.addEventListener?.('change', onChange);
|
|
26
|
+
return () => {
|
|
27
|
+
observer.disconnect();
|
|
28
|
+
scheme?.removeEventListener?.('change', onChange);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function toFixedColor(value) {
|
|
32
|
+
if (!value)
|
|
33
|
+
return value;
|
|
34
|
+
try {
|
|
35
|
+
const color = parse(value);
|
|
36
|
+
const alpha = Math.round(color.a * 255);
|
|
37
|
+
return alpha < 255 ? `${toHex(color)}${alpha.toString(16).padStart(2, '0')}` : toHex(color);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return paintedColor(value) ?? value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
let canvas;
|
|
44
|
+
/** Other notations (hsl, color-mix …): painted onto a pixel and read back */
|
|
45
|
+
function paintedColor(value) {
|
|
46
|
+
if (typeof CSS === 'undefined' || !CSS.supports?.('color', value))
|
|
47
|
+
return undefined;
|
|
48
|
+
canvas ??= document.createElement('canvas').getContext('2d', { willReadFrequently: true });
|
|
49
|
+
if (!canvas)
|
|
50
|
+
return undefined;
|
|
51
|
+
canvas.clearRect(0, 0, 1, 1);
|
|
52
|
+
canvas.fillStyle = value;
|
|
53
|
+
canvas.fillRect(0, 0, 1, 1);
|
|
54
|
+
const [r = 0, g = 0, b = 0, a = 0] = canvas.getImageData(0, 0, 1, 1).data;
|
|
55
|
+
const hex = (channel) => channel.toString(16).padStart(2, '0');
|
|
56
|
+
return `#${hex(r)}${hex(g)}${hex(b)}${a < 255 ? hex(a) : ''}`;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,2BAA2B;AAC3B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAiB,MAAM,aAAa,CAAC;AAEzD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,UAAmB,QAAQ,CAAC,eAAe;IACrE,MAAM,KAAK,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACxC,OAAO,MAAM,CAAC,WAAW,CACrB,WAAW,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,gBAAgB,CAAC,QAAQ,KAAK,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CACxF,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,QAAoB;IAC5C,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACtE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,CAAC;IAClF,IAAI,QAAQ,C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AS,CAAC;IACpF,MAAM,KAAK,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3F,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7B,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5B,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1E,MAAM,GAAG,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACvE,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAClE,CAAC"}
|
package/dist/theme.css
CHANGED
|
@@ -329,4 +329,10 @@
|
|
|
329
329
|
-webkit-font-smoothing: antialiased;
|
|
330
330
|
-moz-osx-font-smoothing: grayscale;
|
|
331
331
|
}
|
|
332
|
+
/* Popups positioned by Ark (Select, Menu, Popover …): Ark copies the z-index of the content to the positioner as
|
|
333
|
+
an inline style – Vue removes it again when it patches the positioner's style, which drops a list behind a
|
|
334
|
+
dialog. In the base layer, so a z-index utility on a positioner still wins */
|
|
335
|
+
[data-scope][data-part='positioner'] {
|
|
336
|
+
z-index: var(--z-index);
|
|
337
|
+
}
|
|
332
338
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -11,3 +11,4 @@ export {
|
|
|
11
11
|
export { colorDeclarations, themeToCss } from './css.js';
|
|
12
12
|
export { nativeExtraThemes, nativeFonts, nativeThemeName, themeToNativeCss } from './native.js';
|
|
13
13
|
export { contrast, inGamut, luminance, oklchToRgb, over, parse, rgbToOklch, toHex, type Rgba } from './color.js';
|
|
14
|
+
export { resolveTokens, watchTokens } from './resolve.js';
|
package/src/resolve.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The colour tokens as fixed values at runtime – for canvas libraries (xterm.js, charts) that cannot read CSS
|
|
2
|
+
// variables. Browser only.
|
|
3
|
+
import { parse, toHex } from './color.js';
|
|
4
|
+
import { colorTokens, type ColorSet } from './tokens.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The colours of the tokens as they apply to `element` right now (mode, theme and own overrides included): hex,
|
|
8
|
+
* `#rrggbbaa` for translucent ones (line, glow). A value the browser cannot paint stays as written.
|
|
9
|
+
*/
|
|
10
|
+
export function resolveTokens(element: Element = document.documentElement): ColorSet {
|
|
11
|
+
const style = getComputedStyle(element);
|
|
12
|
+
return Object.fromEntries(
|
|
13
|
+
colorTokens.map((token) => [token, toFixedColor(style.getPropertyValue(`--wc-${token}`).trim())])
|
|
14
|
+
) as ColorSet;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Calls `onChange` whenever the token colours may have changed: another mode or theme on the page (`data-mode`,
|
|
19
|
+
* `data-theme`, `class`, `style` of <html> and <body>) or another system colour scheme. Returns the function that
|
|
20
|
+
* stops it. Browser only.
|
|
21
|
+
*/
|
|
22
|
+
export function watchTokens(onChange: () => void): () => void {
|
|
23
|
+
const observer = new MutationObserver(onChange);
|
|
24
|
+
const attributeFilter = ['data-mode', 'data-theme', 'class', 'style'];
|
|
25
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter });
|
|
26
|
+
if (document.body) observer.observe(document.body, { attributes: true, attributeFilter });
|
|
27
|
+
const scheme = typeof matchMedia === 'function' ? matchMedia('(prefers-color-scheme: dark)') : undefined;
|
|
28
|
+
scheme?.addEventListener?.('change', onChange);
|
|
29
|
+
return () => {
|
|
30
|
+
observer.disconnect();
|
|
31
|
+
scheme?.removeEventListener?.('change', onChange);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function toFixedColor(value: string): string {
|
|
36
|
+
if (!value) return value;
|
|
37
|
+
try {
|
|
38
|
+
const color = parse(value);
|
|
39
|
+
const alpha = Math.round(color.a * 255);
|
|
40
|
+
return alpha < 255 ? `${toHex(color)}${alpha.toString(16).padStart(2, '0')}` : toHex(color);
|
|
41
|
+
} catch {
|
|
42
|
+
return paintedColor(value) ?? value;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let canvas: CanvasRenderingContext2D | null | undefined;
|
|
47
|
+
|
|
48
|
+
/** Other notations (hsl, color-mix …): painted onto a pixel and read back */
|
|
49
|
+
function paintedColor(value: string): string | undefined {
|
|
50
|
+
if (typeof CSS === 'undefined' || !CSS.supports?.('color', value)) return undefined;
|
|
51
|
+
canvas ??= document.createElement('canvas').getContext('2d', { willReadFrequently: true });
|
|
52
|
+
if (!canvas) return undefined;
|
|
53
|
+
canvas.clearRect(0, 0, 1, 1);
|
|
54
|
+
canvas.fillStyle = value;
|
|
55
|
+
canvas.fillRect(0, 0, 1, 1);
|
|
56
|
+
const [r = 0, g = 0, b = 0, a = 0] = canvas.getImageData(0, 0, 1, 1).data;
|
|
57
|
+
const hex = (channel: number) => channel.toString(16).padStart(2, '0');
|
|
58
|
+
return `#${hex(r)}${hex(g)}${hex(b)}${a < 255 ? hex(a) : ''}`;
|
|
59
|
+
}
|