@tangible/ui 0.2.20 → 0.2.21

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.
@@ -25,6 +25,13 @@ export type ColorFieldLabels = ColorPickerLabels & {
25
25
  /** Strings for the embedded GradientPicker (gradient mode only). */
26
26
  gradientPicker?: GradientPickerLabels;
27
27
  };
28
+ /**
29
+ * Trigger chrome. `field` is the default bordered pill; `bare` drops the field
30
+ * box (border, background, padding) so the swatch itself is the control —
31
+ * sized like an IconButton of the same `size`, for colour-ladder strips and
32
+ * swatch grids.
33
+ */
34
+ export type ColorFieldVariant = 'field' | 'bare';
28
35
  export type ColorFieldProps = {
29
36
  /**
30
37
  * Controlled value — a CSS colour, a `var(--x[, fallback])` reference, or
@@ -58,6 +65,23 @@ export type ColorFieldProps = {
58
65
  label?: React.ReactNode;
59
66
  /** Show the label text beside the swatch. @default true */
60
67
  showLabel?: boolean;
68
+ /**
69
+ * Show the icon-swatch before the label. Opt out for a text-only trigger
70
+ * (a dense settings row where the value text is the affordance). Hiding the
71
+ * swatch also hides the `dynamic` bolt and any `icon` — the accessible name
72
+ * still carries the dynamic state. With both this and `showLabel` off the
73
+ * trigger would be empty, so the label is kept and a dev warning fires.
74
+ * @default true
75
+ */
76
+ showSwatch?: boolean;
77
+ /**
78
+ * Trigger chrome. `bare` removes the field box and sizes the swatch to the
79
+ * control height (an IconButton-shaped tile), keeping the focus ring and the
80
+ * swatch's own edge. Composes with `showLabel={false}` for a swatch-only
81
+ * tile, or with a label for a chrome-less swatch + text row.
82
+ * @default 'field'
83
+ */
84
+ variant?: ColorFieldVariant;
61
85
  /**
62
86
  * Dynamic-data treatment — a neutral swatch with a bolt icon, for values
63
87
  * bound to dynamic sources rather than a fixed colour.
@@ -85,4 +109,4 @@ export type ColorFieldProps = {
85
109
  * and a label that opens a {@link ColorPicker} in a dialog popover. This is the
86
110
  * reusable field-level control for colour inputs; the picker itself is the panel.
87
111
  */
88
- export declare function ColorField({ value: controlledValue, defaultValue, onValueChange, format: controlledFormat, defaultFormat, onFormatChange, formats, alpha, gradient, disabled, label, showLabel, dynamic, icon, size, side, align, open, defaultOpen, onOpenChange, labels, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, className, id, ...rest }: ColorFieldProps): import("react/jsx-runtime").JSX.Element;
112
+ export declare function ColorField({ value: controlledValue, defaultValue, onValueChange, format: controlledFormat, defaultFormat, onFormatChange, formats, alpha, gradient, disabled, label, showLabel, showSwatch, variant, dynamic, icon, size, side, align, open, defaultOpen, onOpenChange, labels, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, className, id, ...rest }: ColorFieldProps): import("react/jsx-runtime").JSX.Element;
@@ -67,7 +67,7 @@ function nodeToText(node) {
67
67
  * and a label that opens a {@link ColorPicker} in a dialog popover. This is the
68
68
  * reusable field-level control for colour inputs; the picker itself is the panel.
69
69
  */
70
- export function ColorField({ value: controlledValue, defaultValue = '#000000', onValueChange, format: controlledFormat, defaultFormat = 'hex', onFormatChange, formats, alpha = true, gradient = false, disabled, label, showLabel = true, dynamic = false, icon, size = 'md', side = 'bottom', align = 'start', open, defaultOpen, onOpenChange, labels, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, className, id, ...rest }) {
70
+ export function ColorField({ value: controlledValue, defaultValue = '#000000', onValueChange, format: controlledFormat, defaultFormat = 'hex', onFormatChange, formats, alpha = true, gradient = false, disabled, label, showLabel = true, showSwatch = true, variant = 'field', dynamic = false, icon, size = 'md', side = 'bottom', align = 'start', open, defaultOpen, onOpenChange, labels, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, className, id, ...rest }) {
71
71
  const triggerRef = useRef(null);
72
72
  const isValueControlled = useRef(controlledValue !== undefined).current;
73
73
  const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
@@ -142,6 +142,12 @@ export function ColorField({ value: controlledValue, defaultValue = '#000000', o
142
142
  !ariaLabelledby) {
143
143
  console.warn('[ColorField] `label` is a node with no derivable text — pass `aria-label` so the control has an accessible name.');
144
144
  }
145
+ // An empty trigger is never right: with both content slots opted out, keep
146
+ // the label — the value text is the least a colour control must show.
147
+ const hasLabel = showLabel || !showSwatch;
148
+ if (isDev() && !showLabel && !showSwatch) {
149
+ console.warn('[ColorField] `showLabel={false}` and `showSwatch={false}` together would render an empty trigger — the label is kept.');
150
+ }
145
151
  // Name context includes the value/label and the dynamic state, so both the
146
152
  // trigger and the (focus-trapped) popover dialog identify which field this is.
147
153
  const nameContext = (labelText ? `${triggerBase}: ${labelText}` : triggerBase) +
@@ -155,7 +161,7 @@ export function ColorField({ value: controlledValue, defaultValue = '#000000', o
155
161
  if (!next)
156
162
  lastGradientRef.current = null;
157
163
  onOpenChange?.(next);
158
- }, children: [_jsx(Popover.Trigger, { asChild: true, children: _jsxs("button", { ref: triggerRef, type: "button", id: id, className: cx('tui-color-field', size !== 'md' && `is-size-${size}`, !showLabel && 'is-swatch-only', disabled && 'is-disabled', className), disabled: disabled, "aria-label": computedAriaLabel, "aria-labelledby": ariaLabelledby, ...rest, children: [_jsx("span", { className: "tui-color-field__swatch", "aria-hidden": "true", style: {
164
+ }, children: [_jsx(Popover.Trigger, { asChild: true, children: _jsxs("button", { ref: triggerRef, type: "button", id: id, className: cx('tui-color-field', size !== 'md' && `is-size-${size}`, variant !== 'field' && `is-variant-${variant}`, showSwatch && !hasLabel && 'is-swatch-only', !showSwatch && 'is-label-only', disabled && 'is-disabled', className), disabled: disabled, "aria-label": computedAriaLabel, "aria-labelledby": ariaLabelledby, ...rest, children: [showSwatch && (_jsx("span", { className: "tui-color-field__swatch", "aria-hidden": "true", style: {
159
165
  '--_swatch': swatchBg,
160
166
  '--_swatch-icon': iconColor,
161
167
  // A gradient paints the whole swatch; solid values keep the
@@ -165,7 +171,7 @@ export function ColorField({ value: controlledValue, defaultValue = '#000000', o
165
171
  ...(isGradient && !dynamic
166
172
  ? { '--_swatch-image': formatGradient(parsedGradient.gradient) }
167
173
  : null),
168
- }, children: _jsx(Icon, { name: swatchIcon, className: "tui-color-field__swatch-icon" }) }), showLabel && _jsx("span", { className: "tui-color-field__label", children: labelNode })] }) }), _jsx(Popover.Content, { side: side, align: align, modal: true, "aria-label": popoverLabel, className: "tui-color-field__popover", children: gradient ? (_jsxs(Tabs
174
+ }, children: _jsx(Icon, { name: swatchIcon, className: "tui-color-field__swatch-icon" }) })), hasLabel && _jsx("span", { className: "tui-color-field__label", children: labelNode })] }) }), _jsx(Popover.Content, { side: side, align: align, modal: true, "aria-label": popoverLabel, className: "tui-color-field__popover", children: gradient ? (_jsxs(Tabs
169
175
  // The tab derives from the value; switching CONVERTS the value
170
176
  // (matching the reference design): solid → a two-stop gradient of
171
177
  // itself, gradient → its first stop's colour. Because switching is
@@ -1,7 +1,7 @@
1
1
  export { ColorPicker } from './ColorPicker';
2
2
  export type { ColorPickerProps } from './ColorPicker';
3
3
  export { ColorField } from './ColorField';
4
- export type { ColorFieldProps, ColorFieldLabels } from './ColorField';
4
+ export type { ColorFieldProps, ColorFieldLabels, ColorFieldVariant } from './ColorField';
5
5
  export type { Side as ColorFieldSide, Align as ColorFieldAlign } from '../Popover';
6
6
  export { defaultColorPickerLabels } from './labels';
7
7
  export type { ColorPickerLabels } from './labels';
@@ -30,6 +30,13 @@ export type ToastProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'title' | 'c
30
30
  announce?: ToastAnnounce;
31
31
  /** Renders a dismiss (×) button. Default true. */
32
32
  dismissible?: boolean;
33
+ /**
34
+ * Makes the toast root programmatically focusable (tabIndex -1, with a
35
+ * focus ring) — Notice's `focusable`, forwarded. ToastProvider sets it on
36
+ * every queued toast: the root is the focus target when a same-id
37
+ * replacement unmounts an instance that held focus.
38
+ */
39
+ focusable?: boolean;
33
40
  /** Called after the exit animation completes (× button path). */
34
41
  onDismiss?: () => void;
35
42
  /** Accessible label for the dismiss button. Default 'Dismiss'. */
@@ -80,6 +87,13 @@ export declare const Toast: React.ForwardRefExoticComponent<Omit<React.HTMLAttri
80
87
  announce?: ToastAnnounce;
81
88
  /** Renders a dismiss (×) button. Default true. */
82
89
  dismissible?: boolean;
90
+ /**
91
+ * Makes the toast root programmatically focusable (tabIndex -1, with a
92
+ * focus ring) — Notice's `focusable`, forwarded. ToastProvider sets it on
93
+ * every queued toast: the root is the focus target when a same-id
94
+ * replacement unmounts an instance that held focus.
95
+ */
96
+ focusable?: boolean;
83
97
  /** Called after the exit animation completes (× button path). */
84
98
  onDismiss?: () => void;
85
99
  /** Accessible label for the dismiss button. Default 'Dismiss'. */
@@ -28,19 +28,15 @@ const EXIT_FALLBACK_MS = 1000;
28
28
  * component API tokens (`--tui-notice-bg`, `--tui-notice-padding`, …) can be
29
29
  * re-pointed per toast context: `.tui-toast { --tui-notice-bg: …; }`.
30
30
  */
31
- export const Toast = forwardRef(function Toast({ theme = 'neutral', size = 'sm', icon, title, announce, dismissible = true, onDismiss, dismissLabel, actions, className, children, ...rest }, ref) {
31
+ export const Toast = forwardRef(function Toast({ theme = 'neutral', size = 'sm', icon, title, announce, dismissible = true, focusable, onDismiss, dismissLabel, actions, className, children, ...rest }, ref) {
32
32
  const resolvedAnnounce = announce ?? (theme === 'danger' ? 'assertive' : 'polite');
33
- return (_jsxs(Notice, { as: "div", ref: ref, className: cx('tui-toast', 'tui-interface', className), "data-theme": "dark", theme: theme, size: size, inline: true, announce: resolvedAnnounce, dismissible: dismissible, onDismiss: onDismiss, dismissLabel: dismissLabel, exitAnimation: "fade", ...rest, children: [icon && _jsx(Notice.Head, { icon: icon }), (title || children != null) && (_jsxs(Notice.Body, { children: [title && _jsx("div", { className: "tui-toast__title", children: title }), children != null && _jsx("div", { className: "tui-toast__description", children: children })] })), actions && _jsx(Notice.Foot, { children: actions })] }));
33
+ return (_jsxs(Notice, { as: "div", ref: ref, className: cx('tui-toast', 'tui-interface', className), "data-theme": "dark", theme: theme, size: size, inline: true, announce: resolvedAnnounce, dismissible: dismissible, focusable: focusable, onDismiss: onDismiss, dismissLabel: dismissLabel, exitAnimation: "fade", ...rest, children: [icon && _jsx(Notice.Head, { icon: icon }), (title || children != null) && (_jsxs(Notice.Body, { children: [title && _jsx("div", { className: "tui-toast__title", children: title }), children != null && _jsx("div", { className: "tui-toast__description", children: children })] })), actions && _jsx(Notice.Foot, { children: actions })] }));
34
34
  });
35
35
  let toastCounter = 0;
36
36
  export function ToastProvider({ children, placement = 'bottom-end', duration = 5000, regionLabel = 'Notifications', max = 5, container, }) {
37
37
  const [toasts, setToasts] = useState([]);
38
38
  const anchorRef = useRef(null);
39
39
  const [mount, setMount] = useState(null);
40
- // Once the region has appeared it stays mounted (empty when idle): a live
41
- // region that already exists announces inserted toasts far more reliably
42
- // than one created in the same commit as its first content.
43
- const [everShown, setEverShown] = useState(false);
44
40
  const autoMountRef = useRef(null);
45
41
  const warnedEmptyRef = useRef(false);
46
42
  const warnedUndismissableRef = useRef(false);
@@ -60,7 +56,6 @@ export function ToastProvider({ children, placement = 'bottom-end', duration = 5
60
56
  'dismiss(id), or the toast can never be removed.');
61
57
  }
62
58
  const id = options.id ?? `tui-toast-${++toastCounter}`;
63
- setEverShown(true);
64
59
  setToasts((prev) => {
65
60
  const existing = prev.find((t) => t.id === id);
66
61
  const record = {
@@ -97,9 +92,13 @@ export function ToastProvider({ children, placement = 'bottom-end', duration = 5
97
92
  const api = useMemo(() => ({ toast, dismiss, dismissAll }), [toast, dismiss, dismissAll]);
98
93
  // Resolve the portal mount from the provider's own position in the tree
99
94
  // (the anchor span), never from document.activeElement — see the Modal
100
- // portal gotcha in CLAUDE.md.
95
+ // portal gotcha in CLAUDE.md. Runs at provider mount, not first toast:
96
+ // the region and its announcers are PRE-WARMED so the page's very first
97
+ // toast lands in live regions AT has already registered — insertion into
98
+ // an existing region is the reliable announcement path; a live region
99
+ // born in the same commit as its first content is the unreliable one.
101
100
  useLayoutEffect(() => {
102
- if (!isBrowser || !everShown)
101
+ if (!isBrowser)
103
102
  return;
104
103
  if (container) {
105
104
  setMount((current) => (current === container ? current : container));
@@ -113,8 +112,8 @@ export function ToastProvider({ children, placement = 'bottom-end', duration = 5
113
112
  const resolved = getPortalRootFor(anchorRef.current);
114
113
  autoMountRef.current = resolved;
115
114
  setMount(resolved);
116
- }, [everShown, container]);
117
- return (_jsxs(ToastContext.Provider, { value: api, children: [children, _jsx("span", { hidden: true, ref: anchorRef }), isBrowser && mount && everShown &&
115
+ }, [container]);
116
+ return (_jsxs(ToastContext.Provider, { value: api, children: [children, _jsx("span", { hidden: true, ref: anchorRef }), isBrowser && mount &&
118
117
  createPortal(_jsx(ToastRegion, { placement: placement, label: regionLabel, toasts: toasts, defaultDuration: duration, onRemove: remove }), mount)] }));
119
118
  }
120
119
  function ToastRegion({ placement, label, toasts, defaultDuration, onRemove }) {
@@ -123,17 +122,52 @@ function ToastRegion({ placement, label, toasts, defaultDuration, onRemove }) {
123
122
  const [focused, setFocused] = useState(false);
124
123
  const [pressed, setPressed] = useState(false);
125
124
  const paused = hovered || focused || pressed;
126
- return (_jsx("div", { ref: regionRef, className: cx('tui-toast-region', `is-placement-${placement}`), role: "region", "aria-label": label, tabIndex: -1, onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), onPointerDown: () => setPressed(true), onPointerUp: () => setPressed(false), onPointerCancel: () => setPressed(false), onFocusCapture: () => setFocused(true), onBlurCapture: (event) => {
125
+ // Pre-warmed announcers: one polite, one assertive, mounted (empty) with
126
+ // the region. Toast roots carry aria-live="off" — announcements happen
127
+ // exclusively by MUTATING these already-registered live regions, never by
128
+ // inserting fresh role="status"/"alert" subtrees (unreliable across AT,
129
+ // and double-fire when both mechanisms work).
130
+ const [announcement, setAnnouncement] = useState(null);
131
+ const announceSeqRef = useRef(0);
132
+ const announceClearRef = useRef(null);
133
+ // Focus hand-off across a same-id replacement: the outgoing instance
134
+ // records its id here at unmount if it held focus; the incoming instance
135
+ // claims it on mount.
136
+ const focusHandoffRef = useRef(null);
137
+ const announce = useCallback((politeness, text) => {
138
+ if (!text)
139
+ return;
140
+ announceSeqRef.current += 1;
141
+ // Alternating trailing NBSP guarantees a DOM mutation even when the
142
+ // same message repeats back-to-back — identical text is no mutation,
143
+ // and no mutation is no announcement.
144
+ setAnnouncement({
145
+ politeness,
146
+ text: text + (announceSeqRef.current % 2 ? ' ' : ''),
147
+ });
148
+ if (announceClearRef.current)
149
+ clearTimeout(announceClearRef.current);
150
+ // Clear after AT has had time to speak, so browse mode can't stumble
151
+ // over stale text in the hidden node.
152
+ announceClearRef.current = setTimeout(() => setAnnouncement(null), 3000);
153
+ }, []);
154
+ useEffect(() => {
155
+ return () => {
156
+ if (announceClearRef.current)
157
+ clearTimeout(announceClearRef.current);
158
+ };
159
+ }, []);
160
+ return (_jsxs("div", { ref: regionRef, className: cx('tui-toast-region', `is-placement-${placement}`), role: "region", "aria-label": label, tabIndex: -1, onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), onPointerDown: () => setPressed(true), onPointerUp: () => setPressed(false), onPointerCancel: () => setPressed(false), onFocusCapture: () => setFocused(true), onBlurCapture: (event) => {
127
161
  if (!event.currentTarget.contains(event.relatedTarget)) {
128
162
  setFocused(false);
129
163
  }
130
- }, children: toasts.map((record) => (_jsx(ToastItem
131
- // Keyed on revision too: a re-toast of the same id REMOUNTS the
132
- // item, resetting Notice's exit state — updating in place could
133
- // land new content inside an element already faded to nothing.
134
- , { record: record, paused: paused, defaultDuration: defaultDuration, regionRef: regionRef, onRemove: onRemove }, `${record.id}:${record.revision}`))) }));
164
+ }, children: [_jsx("div", { className: "tui-toast-region__announcer", "aria-live": "polite", "aria-atomic": "true", children: announcement?.politeness === 'polite' ? announcement.text : '' }), _jsx("div", { className: "tui-toast-region__announcer", "aria-live": "assertive", "aria-atomic": "true", children: announcement?.politeness === 'assertive' ? announcement.text : '' }), toasts.map((record) => (_jsx(ToastItem
165
+ // Keyed on revision too: a re-toast of the same id REMOUNTS the
166
+ // item, resetting Notice's exit state — updating in place could
167
+ // land new content inside an element already faded to nothing.
168
+ , { record: record, paused: paused, defaultDuration: defaultDuration, regionRef: regionRef, focusHandoffRef: focusHandoffRef, announce: announce, onRemove: onRemove }, `${record.id}:${record.revision}`)))] }));
135
169
  }
136
- function ToastItem({ record, paused, defaultDuration, regionRef, onRemove }) {
170
+ function ToastItem({ record, paused, defaultDuration, regionRef, focusHandoffRef, announce, onRemove, }) {
137
171
  const handleRef = useRef(null);
138
172
  const firedRef = useRef(false);
139
173
  const unmountedRef = useRef(false);
@@ -142,6 +176,35 @@ function ToastItem({ record, paused, defaultDuration, regionRef, onRemove }) {
142
176
  unmountedRef.current = true;
143
177
  };
144
178
  }, []);
179
+ const politeness = record.announce ?? (record.theme === 'danger' ? 'assertive' : 'polite');
180
+ // Once per instance (a same-id re-toast REMOUNTS, so updates re-enter
181
+ // here): announce the toast's text via the region's pre-warmed live
182
+ // regions, and settle focus across a replacement. useLayoutEffect so the
183
+ // unmount cleanup still sees the DOM attached — it must know whether this
184
+ // instance held focus at the moment it was replaced.
185
+ useLayoutEffect(() => {
186
+ const element = handleRef.current?.element;
187
+ // Title + description only — the dismiss label and action buttons are
188
+ // controls, not message.
189
+ const text = ['.tui-toast__title', '.tui-toast__description']
190
+ .map((selector) => element?.querySelector(selector)?.textContent?.trim())
191
+ .filter(Boolean)
192
+ .join('. ');
193
+ announce(politeness, text);
194
+ // Claim a pending hand-off: the instance this one replaced held focus.
195
+ if (focusHandoffRef.current === record.id) {
196
+ focusHandoffRef.current = null;
197
+ element?.focus();
198
+ }
199
+ return () => {
200
+ // Replaced (or otherwise unmounted) while holding focus: record the
201
+ // hand-off for the incoming instance. Normal removals never get here
202
+ // with focus inside — finalize has already moved it to the region.
203
+ if (element && element.contains(document.activeElement)) {
204
+ focusHandoffRef.current = record.id;
205
+ }
206
+ };
207
+ }, [announce, politeness, record.id, focusHandoffRef]);
145
208
  // Single exit point: onDismiss fires once no matter which path removed the
146
209
  // toast (timer, dismiss(), or the × button). If the removed toast held
147
210
  // focus, hand it to the region — unmounting the focused element would
@@ -189,7 +252,10 @@ function ToastItem({ record, paused, defaultDuration, regionRef, onRemove }) {
189
252
  if (record.dismissed)
190
253
  void dismissNow();
191
254
  }, [record.dismissed, dismissNow]);
192
- return (_jsx(Toast, { ref: handleRef, theme: record.theme, size: record.size, icon: record.icon, title: record.title, actions: record.actions, announce: record.announce, dismissible: record.dismissible, dismissLabel: record.dismissLabel, className: record.className, style: record.style, "data-testid": record['data-testid'], onDismiss: finalize, children: record.description }));
255
+ return (_jsx(Toast, { ref: handleRef, theme: record.theme, size: record.size, icon: record.icon, title: record.title, actions: record.actions, announce: record.announce, dismissible: record.dismissible, dismissLabel: record.dismissLabel, className: record.className, style: record.style, "data-testid": record['data-testid'], onDismiss: finalize, "aria-live": "off",
256
+ // tabIndex -1: the root is the focus target for same-id replacement
257
+ // hand-off (the Notice `focusable` prop, built for exactly this).
258
+ focusable: true, children: record.description }));
193
259
  }
194
260
  /**
195
261
  * Countdown that survives pauses: while `paused`, the remaining time is
@@ -54,7 +54,7 @@ export type { CheckboxProps } from './Checkbox';
54
54
  export type { ChipProps } from './Chip';
55
55
  export type { ChipGroupProps, ChipGroupSingleProps, ChipGroupMultipleProps } from './ChipGroup';
56
56
  export type { ChipsProps, ChipOption } from './Chips';
57
- export type { ColorPickerProps, ColorPickerLabels, ColorFieldProps, ColorFieldLabels, ColorAreaProps, ColorSliderProps } from './ColorPicker';
57
+ export type { ColorPickerProps, ColorPickerLabels, ColorFieldProps, ColorFieldLabels, ColorFieldVariant, ColorAreaProps, ColorSliderProps } from './ColorPicker';
58
58
  export type { ColorFormat, Hsva as ColorHsva } from './ColorPicker';
59
59
  export type { GradientPickerProps, GradientPickerLabels, GradientBarProps, GradientBarLabels, Gradient, GradientType, GradientStop, } from './GradientPicker';
60
60
  export type { ContentIndicatorProps } from './ContentIndicator';
package/figma-tokens.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
- "version": "0.2.20",
2
+ "version": "0.2.21",
3
3
  "source": "publish/styles/all.expanded.css",
4
4
  "prefix": "tui-",
5
- "note": "Layer 1 primitives only. Component API tokens (--tui-{component}-*) are never defined in CSS — they exist only as fallback reads — so they have no Figma representation.",
5
+ "note": "Layer 1 primitives only. Component API tokens (--tui-{component}-*) are never defined in CSS — they exist only as fallback reads — so they have no Figma representation. CONTRACT: consumers read TUI defaults from this file at build time (variables[].cssVar, the \"Light\"/\"Dark\" mode names, and alias chains into TUI/Primitives). Renaming a cssVar or a mode is a breaking change to those consumers even when the CSS value is unchanged — a rename silently becomes an undefined default downstream — so treat it as at least a minor bump and call it out in the CHANGELOG.",
6
6
  "collections": [
7
7
  {
8
8
  "name": "TUI/Primitives",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangible/ui",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "Tangible Design System",
5
5
  "type": "module",
6
6
  "main": "./components/index.js",
@@ -41,6 +41,14 @@
41
41
  "import": "./utils/color/contrast.js",
42
42
  "types": "./utils/color/contrast.d.ts"
43
43
  },
44
+ "./utils/color": {
45
+ "import": "./utils/color/color.js",
46
+ "types": "./utils/color/color.d.ts"
47
+ },
48
+ "./utils/color/gradient": {
49
+ "import": "./utils/color/gradient.js",
50
+ "types": "./utils/color/gradient.d.ts"
51
+ },
44
52
  "./icons": {
45
53
  "import": "./icons/registry.js",
46
54
  "types": "./icons/registry.d.ts"
@@ -212,6 +212,19 @@ Tokens, not class overrides. Four layers, and you only touch two:
212
212
  `--_*` is component-private and `$_*` compiles away; neither is yours to set. Names come from
213
213
  `tui-manifest.json` → `cssTokens`.
214
214
 
215
+ Every layer-1 primitive — colour roles **and** the scale (spacing, radius, type sizes, weights,
216
+ shadows) — is emitted at `:where(.tui-interface)`, specificity (0,0,0). A site theme written at
217
+ `:where()` after TUI's sheet therefore overrides all of them uniformly; before 0.2.21 the scale
218
+ block sat at bare `.tui-interface` and such a theme won the colours but silently lost the layout
219
+ tokens.
220
+
221
+ Colour maths ships as public utils: `@tangible/ui/utils/color` (`parseColor`, `formatColor`,
222
+ `rgbToOklch`/`oklchToRgb`, `rgbToHsl`, `hexToRgba`, …), `@tangible/ui/utils/color/gradient`
223
+ (`parseGradient`/`formatGradient`), and `@tangible/ui/utils/color/contrast` (`getContrastTone`,
224
+ `getContrastForeground`, `contrastRatio(hexA, hexB)` — WCAG ratio 1–21, `NaN` on bad input so a
225
+ `>= 4.5` check fails closed). Use them for user-selected colours and theme tooling (deriving or
226
+ validating a ladder), not to pick a component's own theming at runtime.
227
+
215
228
  Useful primitives:
216
229
 
217
230
  - Surfaces / text: `--tui-color-bg`, `-bg-surface`, `-bg-elevated`, `-bg-muted`, `-bg-inverted`,