@khanacademy/wonder-blocks-tokens 16.3.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @khanacademy/wonder-blocks-tokens@16.3.0 build:css /home/runner/work/wonder-blocks/wonder-blocks/packages/wonder-blocks-tokens
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,18 @@
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
+
3
16
  ## 16.3.0
4
17
 
5
18
  ### Minor Changes
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;
@@ -1,6 +1,11 @@
1
1
  /**
2
- * NOTE: These tokens are going to be deprecated in favor of the new `sizing`
3
- * tokens.
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;
@@ -1,3 +1,4 @@
1
1
  import { mix, fade } from "./color-utils";
2
2
  import { pxToRem, remToPx } from "./sizing-utils";
3
- export { mix, fade, pxToRem, remToPx };
3
+ import { tokenValue } from "./token-value";
4
+ export { mix, fade, pxToRem, remToPx, tokenValue };
@@ -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.3.0",
6
+ "version": "16.4.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },