@stapel/tokens-antd 0.1.0 → 0.3.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/index.d.ts.map +1 -1
- package/dist/index.js +42 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +43 -3
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAaxC,6EAA6E;AAC7E,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AA8CzC,yEAAyE;AACzE,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;AAE/D;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,cAAc,CAoB3D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,CAM9D"}
|
package/dist/index.js
CHANGED
|
@@ -21,10 +21,49 @@
|
|
|
21
21
|
* and spread it directly: `<ConfigProvider theme={toAntdThemeConfig(mode)}>`.
|
|
22
22
|
*/
|
|
23
23
|
import { theme as antdTheme } from "antd";
|
|
24
|
-
import { bridgeColorRoles, bridgeFontSizeRole, bridgeRadiusRole, colors, fontFamily, fontSize, radii, } from "@stapel/tokens";
|
|
25
|
-
/**
|
|
24
|
+
import { bridgeColorRoles, bridgeFontSizeRole, bridgeRadiusRole, colors, cssVar, fontFamily, fontSize, radii, } from "@stapel/tokens";
|
|
25
|
+
/**
|
|
26
|
+
* Resolve a neutral colour role to a real hex for `mode` (owner audit
|
|
27
|
+
* 2026-07-17, §54 theme-bridge root cause): a host that customizes its OWN
|
|
28
|
+
* brand colour does so exactly as `@stapel/tokens`' README prescribes — copy
|
|
29
|
+
* `theme.default.json` to `stapel.theme.json`, edit the `ramps`, run
|
|
30
|
+
* `pnpm gen:tokens` — which regenerates THAT HOST's `tokens.css` custom
|
|
31
|
+
* properties (`--stapel-color-<role>`). It does NOT and CANNOT change this
|
|
32
|
+
* published package's own compiled-in `colors` object — that snapshot is
|
|
33
|
+
* frozen at `@stapel/tokens`' OWN publish time to `@stapel/tokens`' OWN
|
|
34
|
+
* default theme, forever, regardless of what any host does. Feeding `colors`
|
|
35
|
+
* straight into antd's `ConfigProvider` (the previous implementation) is why
|
|
36
|
+
* every default skin rendered Stapel's stock brand colour instead of the
|
|
37
|
+
* host's, no matter how correctly the host had customized its tokens: the
|
|
38
|
+
* bridge was never wired to read them.
|
|
39
|
+
*
|
|
40
|
+
* The fix reads the LIVE `--stapel-color-<role>` custom property off
|
|
41
|
+
* `document.documentElement` at call time — the exact value the host's own
|
|
42
|
+
* (re)generated `tokens.css` sets, already resolved through whichever
|
|
43
|
+
* `data-theme` is active — and falls back to the static default only where
|
|
44
|
+
* there is no DOM to read (SSR, tests, a host that never loaded
|
|
45
|
+
* `tokens.css`). This is the one change that makes "the skin takes its theme
|
|
46
|
+
* from the bridge automatically" (the doc comment on every default skin)
|
|
47
|
+
* literally true for a host's brand colour, not just its light/dark mode.
|
|
48
|
+
*/
|
|
49
|
+
function readLiveCssVar(name, fallback) {
|
|
50
|
+
if (typeof document === "undefined")
|
|
51
|
+
return fallback;
|
|
52
|
+
// `getPropertyValue` wants the BARE custom-property name (`--stapel-color-x`);
|
|
53
|
+
// `cssVar()` deliberately returns the `var(--stapel-color-x)` wrapper for
|
|
54
|
+
// embedding in a CSS value, which `getPropertyValue` would never match —
|
|
55
|
+
// stripped back off here rather than duplicating the `--stapel-` prefix.
|
|
56
|
+
const propertyName = cssVar(`color-${name}`).slice("var(".length, -1);
|
|
57
|
+
const value = getComputedStyle(document.documentElement)
|
|
58
|
+
.getPropertyValue(propertyName)
|
|
59
|
+
.trim();
|
|
60
|
+
return value.length > 0 ? value : fallback;
|
|
61
|
+
}
|
|
62
|
+
/** Resolve a neutral colour role to its hex for `mode` via the shared table,
|
|
63
|
+
* preferring the host's live CSS custom property over the compiled-in default. */
|
|
26
64
|
function role(name, mode) {
|
|
27
|
-
|
|
65
|
+
const token = bridgeColorRoles[name];
|
|
66
|
+
return readLiveCssVar(token, colors[token][mode]);
|
|
28
67
|
}
|
|
29
68
|
/**
|
|
30
69
|
* `@stapel/tokens` L2 → antd `theme.token` (frontend-guidelines §2.4 table).
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,MAAM,EACN,UAAU,EACV,QAAQ,EACR,KAAK,GACN,MAAM,gBAAgB,CAAC;AAMxB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,UAAU,EACV,QAAQ,EACR,KAAK,GACN,MAAM,gBAAgB,CAAC;AAMxB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAS,cAAc,CAAC,IAAmB,EAAE,QAAgB;IAC3D,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO,QAAQ,CAAC;IAC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I,CAAC;QAC3C,aAAa,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC;QACrC,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC;QAC1C,WAAW,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC;QACjC,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC;QACnD,YAAY,EAAE,KAAK,CAAC,gBAAgB,CAAC;QACrC,QAAQ,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC,QAAQ;QAC/C,UAAU,EAAE,UAAU,CAAC,IAAI;KAC5B,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAe;IAC/C,OAAO;QACL,SAAS,EACP,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,gBAAgB;QACxE,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC;KACzB,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stapel/tokens-antd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Token bridge (frontend-guidelines §2.4, §38 T3): projects @stapel/tokens L2 core tokens onto an Ant Design ConfigProvider theme. `toAntdTheme(mode)` → theme.token; `toAntdThemeConfig(mode)` → the full ThemeConfig (algorithm + token). Pure functions, one mapping table shared with @stapel/tokens-mui. Not components.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"antd": ">=5.20.0 <7"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@stapel/tokens": "^0.
|
|
38
|
+
"@stapel/tokens": "^0.4.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@size-limit/preset-small-lib": "^11.2.0",
|
package/src/index.ts
CHANGED
|
@@ -27,18 +27,58 @@ import {
|
|
|
27
27
|
bridgeFontSizeRole,
|
|
28
28
|
bridgeRadiusRole,
|
|
29
29
|
colors,
|
|
30
|
+
cssVar,
|
|
30
31
|
fontFamily,
|
|
31
32
|
fontSize,
|
|
32
33
|
radii,
|
|
33
34
|
} from "@stapel/tokens";
|
|
34
|
-
import type { BridgeColorRole } from "@stapel/tokens";
|
|
35
|
+
import type { BridgeColorRole, CoreTokenName } from "@stapel/tokens";
|
|
35
36
|
|
|
36
37
|
/** Light or dark — the half of every L2 core token's `{light,dark}` pair. */
|
|
37
38
|
export type ThemeMode = "light" | "dark";
|
|
38
39
|
|
|
39
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Resolve a neutral colour role to a real hex for `mode` (owner audit
|
|
42
|
+
* 2026-07-17, §54 theme-bridge root cause): a host that customizes its OWN
|
|
43
|
+
* brand colour does so exactly as `@stapel/tokens`' README prescribes — copy
|
|
44
|
+
* `theme.default.json` to `stapel.theme.json`, edit the `ramps`, run
|
|
45
|
+
* `pnpm gen:tokens` — which regenerates THAT HOST's `tokens.css` custom
|
|
46
|
+
* properties (`--stapel-color-<role>`). It does NOT and CANNOT change this
|
|
47
|
+
* published package's own compiled-in `colors` object — that snapshot is
|
|
48
|
+
* frozen at `@stapel/tokens`' OWN publish time to `@stapel/tokens`' OWN
|
|
49
|
+
* default theme, forever, regardless of what any host does. Feeding `colors`
|
|
50
|
+
* straight into antd's `ConfigProvider` (the previous implementation) is why
|
|
51
|
+
* every default skin rendered Stapel's stock brand colour instead of the
|
|
52
|
+
* host's, no matter how correctly the host had customized its tokens: the
|
|
53
|
+
* bridge was never wired to read them.
|
|
54
|
+
*
|
|
55
|
+
* The fix reads the LIVE `--stapel-color-<role>` custom property off
|
|
56
|
+
* `document.documentElement` at call time — the exact value the host's own
|
|
57
|
+
* (re)generated `tokens.css` sets, already resolved through whichever
|
|
58
|
+
* `data-theme` is active — and falls back to the static default only where
|
|
59
|
+
* there is no DOM to read (SSR, tests, a host that never loaded
|
|
60
|
+
* `tokens.css`). This is the one change that makes "the skin takes its theme
|
|
61
|
+
* from the bridge automatically" (the doc comment on every default skin)
|
|
62
|
+
* literally true for a host's brand colour, not just its light/dark mode.
|
|
63
|
+
*/
|
|
64
|
+
function readLiveCssVar(name: CoreTokenName, fallback: string): string {
|
|
65
|
+
if (typeof document === "undefined") return fallback;
|
|
66
|
+
// `getPropertyValue` wants the BARE custom-property name (`--stapel-color-x`);
|
|
67
|
+
// `cssVar()` deliberately returns the `var(--stapel-color-x)` wrapper for
|
|
68
|
+
// embedding in a CSS value, which `getPropertyValue` would never match —
|
|
69
|
+
// stripped back off here rather than duplicating the `--stapel-` prefix.
|
|
70
|
+
const propertyName = cssVar(`color-${name}`).slice("var(".length, -1);
|
|
71
|
+
const value = getComputedStyle(document.documentElement)
|
|
72
|
+
.getPropertyValue(propertyName)
|
|
73
|
+
.trim();
|
|
74
|
+
return value.length > 0 ? value : fallback;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Resolve a neutral colour role to its hex for `mode` via the shared table,
|
|
78
|
+
* preferring the host's live CSS custom property over the compiled-in default. */
|
|
40
79
|
function role(name: BridgeColorRole, mode: ThemeMode): string {
|
|
41
|
-
|
|
80
|
+
const token = bridgeColorRoles[name];
|
|
81
|
+
return readLiveCssVar(token, colors[token][mode]);
|
|
42
82
|
}
|
|
43
83
|
|
|
44
84
|
/** The flat antd token map (`ThemeConfig["token"]`), never undefined. */
|