@khanacademy/wonder-blocks-tokens 16.2.0 → 16.4.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/.turbo/turbo-build$colon$css.log +1 -1
- package/CHANGELOG.md +19 -0
- package/dist/build/generate-token-docs.d.ts +41 -0
- package/dist/css/index.css +1 -1
- package/dist/css/vars.css +1 -1
- package/dist/es/index.js +3 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.js +3 -0
- package/dist/tokens/spacing.d.ts +25 -2
- package/dist/util/index.d.ts +2 -1
- package/dist/util/token-value.d.ts +28 -0
- package/package.json +2 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @khanacademy/wonder-blocks-tokens@16.
|
|
2
|
+
> @khanacademy/wonder-blocks-tokens@16.4.0 build:css /home/runner/work/wonder-blocks/wonder-blocks/packages/wonder-blocks-tokens
|
|
3
3
|
> node -r @swc-node/register ./src/build/generate-css-variables.ts
|
|
4
4
|
|
|
5
5
|
CSS variables generated successfully in: /home/runner/work/wonder-blocks/wonder-blocks/packages/wonder-blocks-tokens/dist/css
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-tokens
|
|
2
2
|
|
|
3
|
+
## 16.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c1c74df: Soft-deprecate the `spacing` primitive token in favor of `sizing`. Editors
|
|
8
|
+
will now show deprecation warnings on `spacing`, `VALID_PRIMARY_SPACING`,
|
|
9
|
+
`VALID_SECONDARY_SPACING`, and `VALID_SPACING`. No runtime or visual changes
|
|
10
|
+
— each `spacing.<name>` value still maps 1:1 to a `sizing.size_<n>` token. A
|
|
11
|
+
codemod is available at `wb-codemod/transforms/migrate-spacing-to-sizing.ts`
|
|
12
|
+
to help migrate consumers; run it with
|
|
13
|
+
`npx @khanacademy/wb-codemod -t migrate-spacing-to-sizing <paths>`.
|
|
14
|
+
- 72c5272: Add `tokenValue()` helper to resolve the raw value of a semantic token at runtime. Useful for interoperating with third-party libraries that expect raw color values instead of CSS `var(...)` references.
|
|
15
|
+
|
|
16
|
+
## 16.3.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- 40f217b: Add Noto as fallback font for Thunderblocks in tokens.fontFamily
|
|
21
|
+
|
|
3
22
|
## 16.2.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env -S node -r @swc-node/register
|
|
2
|
+
import themeDefault from "../theme/default";
|
|
3
|
+
type ThemeObject = typeof themeDefault;
|
|
4
|
+
export declare function flattenToMap(obj: unknown, prefix?: string, map?: Map<string, string | number>): Map<string, string | number>;
|
|
5
|
+
export declare function toCssVar(tokenGroup: string, dotPath: string): string;
|
|
6
|
+
type Group = {
|
|
7
|
+
/** Slug used for the output filename. */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Storybook title path. */
|
|
10
|
+
title: string;
|
|
11
|
+
/** H1 rendered in the MDX page. */
|
|
12
|
+
heading: string;
|
|
13
|
+
/** Variable name used in code examples (e.g. `sizing`). */
|
|
14
|
+
tokenPrefix: string;
|
|
15
|
+
/** Short blurb shown above the table, rendered as markdown. */
|
|
16
|
+
description: string;
|
|
17
|
+
/** Whether to emit a CSS Variable column. */
|
|
18
|
+
includeCssVar: boolean;
|
|
19
|
+
} & ({
|
|
20
|
+
/**
|
|
21
|
+
* Returns the token subtree for a given theme. One value column is
|
|
22
|
+
* emitted per theme.
|
|
23
|
+
*/
|
|
24
|
+
getTokens: (theme: ThemeObject) => unknown;
|
|
25
|
+
} | {
|
|
26
|
+
/**
|
|
27
|
+
* For tokens that aren't themed (e.g. media query breakpoints). A
|
|
28
|
+
* single Value column is emitted.
|
|
29
|
+
*/
|
|
30
|
+
tokens: unknown;
|
|
31
|
+
});
|
|
32
|
+
export declare const groups: ReadonlyArray<Group>;
|
|
33
|
+
export declare function renderThemedTable(group: Group & {
|
|
34
|
+
getTokens: (theme: ThemeObject) => unknown;
|
|
35
|
+
}): string;
|
|
36
|
+
export declare function renderSimpleTable(group: Group & {
|
|
37
|
+
tokens: unknown;
|
|
38
|
+
}): string;
|
|
39
|
+
export declare function renderMdx(group: Group): string;
|
|
40
|
+
export declare function generateTokenDocs(outputDir: string): void;
|
|
41
|
+
export {};
|
package/dist/css/index.css
CHANGED
|
@@ -856,7 +856,7 @@
|
|
|
856
856
|
--wb-boxShadow-low: 0 2px 2px 0 color-mix(in srgb, #252368 20%, transparent);
|
|
857
857
|
--wb-boxShadow-mid: 0 4px 8px 0 color-mix(in srgb, #252368 20%, transparent);
|
|
858
858
|
--wb-boxShadow-high: 0 8px 16px 0 color-mix(in srgb, #252368 20%, transparent);
|
|
859
|
-
--wb-font-family-sans: Plus Jakarta Sans, serif;
|
|
859
|
+
--wb-font-family-sans: Plus Jakarta Sans, "Noto Sans", sans-serif;
|
|
860
860
|
--wb-font-family-serif: "Noto Serif", serif;
|
|
861
861
|
--wb-font-family-mono: Inconsolata, monospace;
|
|
862
862
|
--wb-font-size-xxxLarge: 3.6rem;
|
package/dist/css/vars.css
CHANGED
|
@@ -490,7 +490,7 @@
|
|
|
490
490
|
--wb-boxShadow-low: 0 2px 2px 0 color-mix(in srgb, #252368 20%, transparent);
|
|
491
491
|
--wb-boxShadow-mid: 0 4px 8px 0 color-mix(in srgb, #252368 20%, transparent);
|
|
492
492
|
--wb-boxShadow-high: 0 8px 16px 0 color-mix(in srgb, #252368 20%, transparent);
|
|
493
|
-
--wb-font-family-sans: Plus Jakarta Sans, serif;
|
|
493
|
+
--wb-font-family-sans: Plus Jakarta Sans, "Noto Sans", sans-serif;
|
|
494
494
|
--wb-font-family-serif: "Noto Serif", serif;
|
|
495
495
|
--wb-font-family-mono: Inconsolata, monospace;
|
|
496
496
|
--wb-font-size-xxxLarge: 3.6rem;
|
package/dist/es/index.js
CHANGED
|
@@ -8,6 +8,8 @@ const width={xsMax:567,smMin:568,smMax:681,mdMin:682,mdMax:1023,lgMin:1024};cons
|
|
|
8
8
|
|
|
9
9
|
const BASELINE_VALUE=10;function remToPx(value,baseline=BASELINE_VALUE){const num=parseFloat(value);const result=Math.round(num*baseline);return `${result}px`}function pxToRem(value,baseline=BASELINE_VALUE){return `${value/baseline}rem`}
|
|
10
10
|
|
|
11
|
+
const cssVarRegex=/^\s*var\(\s*(--[^,)\s]+)/;function tokenValue(token,element){const rootElement=element||document.querySelector("[data-wb-theme]")||document.documentElement;const match=token.match(cssVarRegex);if(!match){return token}return getComputedStyle(rootElement).getPropertyValue(match[1]).trim()}
|
|
12
|
+
|
|
11
13
|
function mapValuesToCssVars(obj,prefix="--wb-"){const cssVars={};for(const key in obj){if(typeof obj[key]==="object"){cssVars[key]=mapValuesToCssVars(obj[key],`${prefix}${key}-`);}else {cssVars[key]=`var(${prefix}${key})`;}}return cssVars}
|
|
12
14
|
|
|
13
15
|
const CSS_VAR_PREFIX="--wb-";
|
|
@@ -30,4 +32,4 @@ var theme = mapValuesToCssVars(themeDefault,CSS_VAR_PREFIX);
|
|
|
30
32
|
|
|
31
33
|
const {border,boxShadow,semanticColor,sizing,font}=theme;
|
|
32
34
|
|
|
33
|
-
export { border, boxShadow, breakpoint, color$1 as color, fade, font, mapValuesToCssVars, mix, pxToRem, remToPx, semanticColor, sizing, spacing };
|
|
35
|
+
export { border, boxShadow, breakpoint, color$1 as color, fade, font, mapValuesToCssVars, mix, pxToRem, remToPx, semanticColor, sizing, spacing, tokenValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { color } from "./tokens/color";
|
|
2
2
|
import { spacing } from "./tokens/spacing";
|
|
3
3
|
import { breakpoint } from "./tokens/media-queries";
|
|
4
|
-
import { mix, fade, pxToRem, remToPx } from "./util";
|
|
4
|
+
import { mix, fade, pxToRem, remToPx, tokenValue } from "./util";
|
|
5
5
|
import { mapValuesToCssVars } from "./internal/map-values-to-css-vars";
|
|
6
6
|
declare const border: {
|
|
7
7
|
radius: {
|
|
@@ -882,4 +882,9 @@ mix, fade,
|
|
|
882
882
|
/**
|
|
883
883
|
* Allows converting regular JS tokens to CSS variables.
|
|
884
884
|
*/
|
|
885
|
-
mapValuesToCssVars,
|
|
885
|
+
mapValuesToCssVars,
|
|
886
|
+
/**
|
|
887
|
+
* Resolves the raw value of a Wonder Blocks token at runtime by reading
|
|
888
|
+
* the computed value of its underlying CSS custom property.
|
|
889
|
+
*/
|
|
890
|
+
tokenValue, };
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,8 @@ const width={xsMax:567,smMin:568,smMax:681,mdMin:682,mdMax:1023,lgMin:1024};cons
|
|
|
12
12
|
|
|
13
13
|
const BASELINE_VALUE=10;function remToPx(value,baseline=BASELINE_VALUE){const num=parseFloat(value);const result=Math.round(num*baseline);return `${result}px`}function pxToRem(value,baseline=BASELINE_VALUE){return `${value/baseline}rem`}
|
|
14
14
|
|
|
15
|
+
const cssVarRegex=/^\s*var\(\s*(--[^,)\s]+)/;function tokenValue(token,element){const rootElement=element||document.querySelector("[data-wb-theme]")||document.documentElement;const match=token.match(cssVarRegex);if(!match){return token}return getComputedStyle(rootElement).getPropertyValue(match[1]).trim()}
|
|
16
|
+
|
|
15
17
|
function mapValuesToCssVars(obj,prefix="--wb-"){const cssVars={};for(const key in obj){if(typeof obj[key]==="object"){cssVars[key]=mapValuesToCssVars(obj[key],`${prefix}${key}-`);}else {cssVars[key]=`var(${prefix}${key})`;}}return cssVars}
|
|
16
18
|
|
|
17
19
|
const CSS_VAR_PREFIX="--wb-";
|
|
@@ -47,3 +49,4 @@ exports.remToPx = remToPx;
|
|
|
47
49
|
exports.semanticColor = semanticColor;
|
|
48
50
|
exports.sizing = sizing;
|
|
49
51
|
exports.spacing = spacing;
|
|
52
|
+
exports.tokenValue = tokenValue;
|
package/dist/tokens/spacing.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Primitive tokens for dimensional values (margin, padding, gaps, sizes).
|
|
3
|
+
*
|
|
4
|
+
* @deprecated Use `sizing` from `@khanacademy/wonder-blocks-tokens` instead.
|
|
5
|
+
* Each `spacing.<name>` value has an equivalent `sizing.size_<n>` token (e.g.
|
|
6
|
+
* `spacing.medium_16` → `sizing.size_160`). A codemod is available at
|
|
7
|
+
* `wb-codemod/transforms/migrate-spacing-to-sizing.ts` to help migrate
|
|
8
|
+
* consumers.
|
|
4
9
|
*/
|
|
5
10
|
export declare const spacing: {
|
|
6
11
|
readonly xxxxSmall_2: 2;
|
|
@@ -14,6 +19,24 @@ export declare const spacing: {
|
|
|
14
19
|
readonly xxLarge_48: 48;
|
|
15
20
|
readonly xxxLarge_64: 64;
|
|
16
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated The `spacing` token is deprecated; use `sizing` from
|
|
24
|
+
* `@khanacademy/wonder-blocks-tokens` instead. For APIs that need to constrain
|
|
25
|
+
* to a numeric set, prefer `number` (or `number | string` to also accept rem
|
|
26
|
+
* strings from `sizing`).
|
|
27
|
+
*/
|
|
17
28
|
export type VALID_PRIMARY_SPACING = 4 | 8 | 16 | 32 | 64;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated The `spacing` token is deprecated; use `sizing` from
|
|
31
|
+
* `@khanacademy/wonder-blocks-tokens` instead. For APIs that need to constrain
|
|
32
|
+
* to a numeric set, prefer `number` (or `number | string` to also accept rem
|
|
33
|
+
* strings from `sizing`).
|
|
34
|
+
*/
|
|
18
35
|
export type VALID_SECONDARY_SPACING = 6 | 12 | 24 | 48;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated The `spacing` token is deprecated; use `sizing` from
|
|
38
|
+
* `@khanacademy/wonder-blocks-tokens` instead. For APIs that need to constrain
|
|
39
|
+
* to a numeric set, prefer `number` (or `number | string` to also accept rem
|
|
40
|
+
* strings from `sizing`).
|
|
41
|
+
*/
|
|
19
42
|
export type VALID_SPACING = VALID_PRIMARY_SPACING | VALID_SECONDARY_SPACING;
|
package/dist/util/index.d.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves the raw value of a Wonder Blocks token at runtime.
|
|
3
|
+
*
|
|
4
|
+
* Semantic tokens are exported as `var(--...)` strings so that theming works
|
|
5
|
+
* through the CSS cascade. This helper reads the computed value of that custom
|
|
6
|
+
* property, returning the concrete string (e.g. a hex or `rgba()` value) that
|
|
7
|
+
* third-party libraries expecting raw color values can consume.
|
|
8
|
+
*
|
|
9
|
+
* If `token` is not a `var(...)` expression, it is returned unchanged.
|
|
10
|
+
*
|
|
11
|
+
* @param token A token string — typically a `var(--...)` reference exported
|
|
12
|
+
* from this package, but a raw value is accepted and returned as-is.
|
|
13
|
+
* @param element The element whose computed style should be read. Defaults to
|
|
14
|
+
* the first `[data-wb-theme]` element in the current document, falling back to
|
|
15
|
+
* `document.documentElement`. Pass a descendant of a `[data-wb-theme]` element
|
|
16
|
+
* to resolve the value for that theme scope.
|
|
17
|
+
* @returns The resolved raw value, trimmed. Returns an empty string when the
|
|
18
|
+
* custom property is not defined on the given element.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import {semanticColor, tokenValue} from "@khanacademy/wonder-blocks-tokens";
|
|
23
|
+
*
|
|
24
|
+
* tokenValue(semanticColor.core.foreground.instructive.default);
|
|
25
|
+
* // => "#1865f2"
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function tokenValue(token: string, element?: Element): string;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Core primitive design tokens for Web Wonder Blocks",
|
|
4
4
|
"author": "Khan Academy",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "16.
|
|
6
|
+
"version": "16.4.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"bin": "./bin/cli.js",
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build:css": "node -r @swc-node/register ./src/build/generate-css-variables.ts",
|
|
38
|
+
"build:token-docs": "node -r @swc-node/register ./src/build/generate-token-docs.ts",
|
|
38
39
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
39
40
|
}
|
|
40
41
|
}
|