@nexub/tokens 1.9.0 → 2.1.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/dist/js/generated/native.d.ts +854 -0
- package/dist/js/generated/native.js +886 -0
- package/dist/js/native.d.ts +6 -0
- package/dist/js/native.js +3 -0
- package/dist/js/seed.d.ts +11 -0
- package/dist/js/seed.js +20 -4
- package/package.json +6 -2
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { native } from './generated/native.js';
|
|
2
|
+
import type { native } from './generated/native.js';
|
|
3
|
+
export type NativeTokens = typeof native;
|
|
4
|
+
export type NativeRoles = NativeTokens['color']['roles']['standard']['light'];
|
|
5
|
+
export type NativeRole = keyof NativeRoles;
|
|
6
|
+
export type NativeTypeRole = keyof NativeTokens['type'];
|
package/dist/js/seed.d.ts
CHANGED
|
@@ -8,6 +8,17 @@
|
|
|
8
8
|
* @returns {Record<string, string>} e.g. `createSeedTheme('#4099f1')['--color-primary'] === 'light-dark(#0061a6, #a0c9ff)'`
|
|
9
9
|
*/
|
|
10
10
|
export function createSeedTheme(seed: string, { contrast, target }?: SeedThemeOptions): Record<string, string>;
|
|
11
|
+
/**
|
|
12
|
+
* The same accent family as plain hex per scheme, for React Native
|
|
13
|
+
* (`@nexub/react-native` merges it over the built-in roles).
|
|
14
|
+
* @param {string} seed Hex colour, `#rgb` or `#rrggbb`.
|
|
15
|
+
* @param {SeedThemeOptions} [options]
|
|
16
|
+
* @returns {{ light: Record<string, string>, dark: Record<string, string> }}
|
|
17
|
+
*/
|
|
18
|
+
export function createSeedRoles(seed: string, { contrast, target }?: SeedThemeOptions): {
|
|
19
|
+
light: Record<string, string>;
|
|
20
|
+
dark: Record<string, string>;
|
|
21
|
+
};
|
|
11
22
|
/**
|
|
12
23
|
* The same theme as a CSS rule, for SSR / static stylesheets (no flash, no JS):
|
|
13
24
|
* `:root {\n --color-primary: light-dark(…);\n …\n}\n`.
|
package/dist/js/seed.js
CHANGED
|
@@ -20,6 +20,21 @@ const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
|
20
20
|
* @returns {Record<string, string>} e.g. `createSeedTheme('#4099f1')['--color-primary'] === 'light-dark(#0061a6, #a0c9ff)'`
|
|
21
21
|
*/
|
|
22
22
|
export function createSeedTheme(seed, { contrast = 'standard', target = 'primary' } = {}) {
|
|
23
|
+
const { light, dark } = createSeedRoles(seed, { contrast, target });
|
|
24
|
+
/** @type {Record<string, string>} */
|
|
25
|
+
const vars = {};
|
|
26
|
+
for (const role of Object.keys(light))
|
|
27
|
+
vars[`--color-${role}`] = `light-dark(${light[role]}, ${dark[role]})`;
|
|
28
|
+
return vars;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The same accent family as plain hex per scheme, for React Native
|
|
32
|
+
* (`@nexub/react-native` merges it over the built-in roles).
|
|
33
|
+
* @param {string} seed Hex colour, `#rgb` or `#rrggbb`.
|
|
34
|
+
* @param {SeedThemeOptions} [options]
|
|
35
|
+
* @returns {{ light: Record<string, string>, dark: Record<string, string> }}
|
|
36
|
+
*/
|
|
37
|
+
export function createSeedRoles(seed, { contrast = 'standard', target = 'primary' } = {}) {
|
|
23
38
|
if (typeof seed !== 'string' || !HEX.test(seed))
|
|
24
39
|
throw new TypeError(`@nexub/tokens/seed: seed must be a hex colour (#rgb or #rrggbb), got ${JSON.stringify(seed)}`);
|
|
25
40
|
if (!LEVELS.includes(contrast))
|
|
@@ -30,13 +45,14 @@ export function createSeedTheme(seed, { contrast = 'standard', target = 'primary
|
|
|
30
45
|
const roles = { ...accent(target) };
|
|
31
46
|
if (target === 'primary' && ROLES['inverse-primary'])
|
|
32
47
|
roles['inverse-primary'] = ROLES['inverse-primary'];
|
|
33
|
-
/** @type {Record<string, string>} */
|
|
34
|
-
const
|
|
48
|
+
/** @type {{ light: Record<string, string>, dark: Record<string, string> }} */
|
|
49
|
+
const out = { light: {}, dark: {} };
|
|
35
50
|
for (const [role, entry] of Object.entries(roles)) {
|
|
36
51
|
const [, l, d] = tonesAt(entry, contrast);
|
|
37
|
-
|
|
52
|
+
out.light[role] = toneHex(pal, l);
|
|
53
|
+
out.dark[role] = toneHex(pal, d);
|
|
38
54
|
}
|
|
39
|
-
return
|
|
55
|
+
return out;
|
|
40
56
|
}
|
|
41
57
|
/**
|
|
42
58
|
* The same theme as a CSS rule, for SSR / static stylesheets (no flash, no JS):
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexub/tokens",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Design tokens for Nexub Design System — colours, typography, spacing, radii, shadows, and motion as CSS variables and
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Design tokens for Nexub Design System — colours, typography, spacing, radii, shadows, and motion as CSS variables, Tailwind presets and React Native objects.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/Nexub-AI/nexub-ds#readme",
|
|
@@ -42,6 +42,10 @@
|
|
|
42
42
|
"types": "./dist/js/seed.d.ts",
|
|
43
43
|
"default": "./dist/js/seed.js"
|
|
44
44
|
},
|
|
45
|
+
"./native": {
|
|
46
|
+
"types": "./dist/js/native.d.ts",
|
|
47
|
+
"default": "./dist/js/native.js"
|
|
48
|
+
},
|
|
45
49
|
"./tailwind": {
|
|
46
50
|
"types": "./dist/tailwind/preset.d.ts",
|
|
47
51
|
"default": "./dist/tailwind/preset.js"
|