@cameronsjo/artificer 0.28.0 → 0.29.1

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.
@@ -0,0 +1,210 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Interactive React wrappers wired to Artificer's pure keyboard state machines
4
+ * (ArtificerTabs.nextIndex, ArtificerOptions.nextOption/matchOption,
5
+ * ArtificerTree.nextVisible/treeAction). React owns the DOM; the vanilla
6
+ * modules own the WAI-ARIA APG keyboard math (with inline fallback when the
7
+ * module script hasn't attached to window yet).
8
+ */
9
+ import * as React from 'react';
10
+ import { cx } from './primitives.js';
11
+ export function Tabs({ items, selectedId, defaultSelectedId, onSelect, orientation = 'horizontal', label, className = '', }) {
12
+ const baseId = React.useId();
13
+ const [uncontrolled, setUncontrolled] = React.useState(() => defaultSelectedId ?? items[0]?.id ?? '');
14
+ const activeId = selectedId ?? uncontrolled;
15
+ const activeIndex = Math.max(0, items.findIndex((t) => t.id === activeId));
16
+ const tabRefs = React.useRef([]);
17
+ const selectIndex = (idx) => {
18
+ const item = items[idx];
19
+ if (!item || item.disabled)
20
+ return;
21
+ if (selectedId === undefined)
22
+ setUncontrolled(item.id);
23
+ onSelect?.(item.id);
24
+ tabRefs.current[idx]?.focus();
25
+ };
26
+ const onKeyDown = (e) => {
27
+ const next = window.ArtificerTabs?.nextIndex(e.key, activeIndex, items.length, { orientation })
28
+ ?? fallbackNextIndex(e.key, activeIndex, items.length, orientation);
29
+ if (next == null)
30
+ return;
31
+ e.preventDefault();
32
+ selectIndex(next);
33
+ };
34
+ return (_jsxs("div", { className: className || undefined, children: [_jsx("div", { className: "tabs", role: "tablist", "aria-label": label, "aria-orientation": orientation, onKeyDown: onKeyDown, children: items.map((item, i) => {
35
+ const selected = i === activeIndex;
36
+ const tabId = `${baseId}-tab-${item.id}`;
37
+ const panelId = `${baseId}-panel-${item.id}`;
38
+ return (_jsx("button", { ref: (el) => { tabRefs.current[i] = el; }, id: tabId, type: "button", role: "tab", "aria-selected": selected, "aria-controls": panelId, tabIndex: selected ? 0 : -1, disabled: item.disabled, onClick: () => selectIndex(i), children: item.label }, item.id));
39
+ }) }), items.map((item, i) => {
40
+ const selected = i === activeIndex;
41
+ const tabId = `${baseId}-tab-${item.id}`;
42
+ const panelId = `${baseId}-panel-${item.id}`;
43
+ return (_jsx("div", { id: panelId, role: "tabpanel", "aria-labelledby": tabId, hidden: !selected, children: item.content }, item.id));
44
+ })] }));
45
+ }
46
+ function fallbackNextIndex(key, current, count, orientation) {
47
+ if (count <= 0)
48
+ return null;
49
+ const prevKey = orientation === 'vertical' ? 'ArrowUp' : 'ArrowLeft';
50
+ const nextKey = orientation === 'vertical' ? 'ArrowDown' : 'ArrowRight';
51
+ if (key === nextKey)
52
+ return (current + 1) % count;
53
+ if (key === prevKey)
54
+ return (current - 1 + count) % count;
55
+ if (key === 'Home')
56
+ return 0;
57
+ if (key === 'End')
58
+ return count - 1;
59
+ return null;
60
+ }
61
+ export function Listbox({ items, selectedId, onSelect, variant = 'listbox', label, className = '', }) {
62
+ const isMenu = variant === 'menu';
63
+ const [cursor, setCursor] = React.useState(() => Math.max(0, items.findIndex((it) => it.id === selectedId)));
64
+ const refs = React.useRef([]);
65
+ const bufferRef = React.useRef('');
66
+ const timerRef = React.useRef(null);
67
+ const move = (idx) => {
68
+ setCursor(idx);
69
+ refs.current[idx]?.focus();
70
+ };
71
+ const onKeyDown = (e) => {
72
+ const next = window.ArtificerOptions?.nextOption(e.key, cursor, items.length, { wrap: isMenu })
73
+ ?? fallbackNextOption(e.key, cursor, items.length, isMenu);
74
+ if (next != null) {
75
+ e.preventDefault();
76
+ move(next);
77
+ return;
78
+ }
79
+ if (e.key === 'Enter' || e.key === ' ') {
80
+ const item = items[cursor];
81
+ if (item && !item.disabled) {
82
+ e.preventDefault();
83
+ onSelect?.(item);
84
+ }
85
+ return;
86
+ }
87
+ if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
88
+ bufferRef.current += e.key;
89
+ if (timerRef.current)
90
+ clearTimeout(timerRef.current);
91
+ timerRef.current = setTimeout(() => { bufferRef.current = ''; }, 500);
92
+ const hit = window.ArtificerOptions?.matchOption(items.map((it) => it.label), bufferRef.current, cursor);
93
+ if (hit != null && hit >= 0) {
94
+ e.preventDefault();
95
+ move(hit);
96
+ }
97
+ }
98
+ };
99
+ const optCls = isMenu ? 'menu__option' : 'listbox__option';
100
+ return (_jsx("div", { role: isMenu ? 'menu' : 'listbox', "aria-label": label, className: cx(isMenu ? 'menu' : 'listbox', className), onKeyDown: onKeyDown, children: items.map((item, i) => (_jsx("button", { ref: (el) => { refs.current[i] = el; }, type: "button", role: isMenu ? 'menuitem' : 'option', "aria-selected": isMenu ? undefined : item.id === selectedId, "aria-disabled": item.disabled || undefined, tabIndex: i === cursor ? 0 : -1, className: cx(optCls, item.danger && isMenu && 'menu__option--danger'), onClick: () => {
101
+ setCursor(i);
102
+ if (!item.disabled)
103
+ onSelect?.(item);
104
+ }, children: item.label }, item.id))) }));
105
+ }
106
+ export function Menu(props) {
107
+ return _jsx(Listbox, { ...props, variant: "menu" });
108
+ }
109
+ function fallbackNextOption(key, current, count, wrap) {
110
+ if (count <= 0)
111
+ return null;
112
+ if (key === 'ArrowDown')
113
+ return wrap ? (current + 1) % count : Math.min(count - 1, current + 1);
114
+ if (key === 'ArrowUp')
115
+ return wrap ? (current - 1 + count) % count : Math.max(0, current - 1);
116
+ if (key === 'Home')
117
+ return 0;
118
+ if (key === 'End')
119
+ return count - 1;
120
+ return null;
121
+ }
122
+ export function Tree({ nodes, selectedId, defaultExpandedIds = [], onSelect, label, className = '', }) {
123
+ const [expanded, setExpanded] = React.useState(() => new Set(defaultExpandedIds));
124
+ const [focusedId, setFocusedId] = React.useState(() => selectedId ?? nodes[0]?.id ?? '');
125
+ const refs = React.useRef(new Map());
126
+ const visible = [];
127
+ const walk = (list, parentId) => {
128
+ for (const node of list) {
129
+ visible.push({ node, parentId });
130
+ if (node.children?.length && expanded.has(node.id))
131
+ walk(node.children, node.id);
132
+ }
133
+ };
134
+ walk(nodes, null);
135
+ const focusNode = (id) => {
136
+ setFocusedId(id);
137
+ refs.current.get(id)?.focus();
138
+ };
139
+ const toggleNode = (id) => {
140
+ setExpanded((prev) => {
141
+ const next = new Set(prev);
142
+ if (next.has(id))
143
+ next.delete(id);
144
+ else
145
+ next.add(id);
146
+ return next;
147
+ });
148
+ };
149
+ const onKeyDown = (e) => {
150
+ const idx = Math.max(0, visible.findIndex((v) => v.node.id === focusedId));
151
+ const entry = visible[idx];
152
+ if (!entry)
153
+ return;
154
+ const isParent = Boolean(entry.node.children?.length);
155
+ const isExpanded = expanded.has(entry.node.id);
156
+ const moved = window.ArtificerTree?.nextVisible(e.key, idx, visible.length)
157
+ ?? fallbackNextOption(e.key, idx, visible.length, false);
158
+ if (moved != null) {
159
+ const target = visible[moved];
160
+ if (target) {
161
+ e.preventDefault();
162
+ focusNode(target.node.id);
163
+ }
164
+ return;
165
+ }
166
+ const action = window.ArtificerTree?.treeAction(e.key, { expanded: isExpanded, isParent })
167
+ ?? fallbackTreeAction(e.key, isExpanded, isParent);
168
+ if (!action)
169
+ return;
170
+ e.preventDefault();
171
+ const firstChild = entry.node.children?.[0];
172
+ if (action === 'expand' && isParent && !isExpanded)
173
+ toggleNode(entry.node.id);
174
+ else if (action === 'collapse' && isParent && isExpanded)
175
+ toggleNode(entry.node.id);
176
+ else if (action === 'first-child' && firstChild)
177
+ focusNode(firstChild.id);
178
+ else if (action === 'parent' && entry.parentId)
179
+ focusNode(entry.parentId);
180
+ else if (action === 'activate') {
181
+ if (isParent)
182
+ toggleNode(entry.node.id);
183
+ else
184
+ onSelect?.(entry.node);
185
+ }
186
+ };
187
+ const renderNodes = (list) => list.map((node) => {
188
+ const isParent = Boolean(node.children?.length);
189
+ const isExpanded = expanded.has(node.id);
190
+ const isFocused = node.id === focusedId;
191
+ return (_jsxs("li", { ref: (el) => { refs.current.set(node.id, el); }, role: "treeitem", "aria-expanded": isParent ? isExpanded : undefined, "aria-selected": node.id === selectedId, tabIndex: isFocused ? 0 : -1, onClick: (e) => {
192
+ e.stopPropagation();
193
+ focusNode(node.id);
194
+ if (isParent)
195
+ toggleNode(node.id);
196
+ else
197
+ onSelect?.(node);
198
+ }, children: [_jsxs("span", { className: "tree__row", children: [isParent && _jsx("span", { className: "tree__twisty", "aria-hidden": "true" }), _jsx("span", { children: node.label })] }), isParent && isExpanded && (_jsx("ul", { role: "group", children: renderNodes(node.children) }))] }, node.id));
199
+ });
200
+ return (_jsx("ul", { role: "tree", "aria-label": label, className: cx('tree', className), onKeyDown: onKeyDown, children: renderNodes(nodes) }));
201
+ }
202
+ function fallbackTreeAction(key, expanded, isParent) {
203
+ if (key === 'ArrowRight')
204
+ return isParent ? (expanded ? 'first-child' : 'expand') : null;
205
+ if (key === 'ArrowLeft')
206
+ return isParent && expanded ? 'collapse' : 'parent';
207
+ if (key === 'Enter' || key === ' ')
208
+ return 'activate';
209
+ return null;
210
+ }
@@ -40,10 +40,10 @@ export declare function GridAuto({ min, className, style, ...rest }: React.HTMLA
40
40
  min?: number;
41
41
  }): React.JSX.Element;
42
42
  type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'destructive';
43
- export declare function Button({ variant, size, className, ...rest }: React.ButtonHTMLAttributes<HTMLButtonElement> & {
43
+ export declare const Button: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes<HTMLButtonElement> & {
44
44
  variant?: ButtonVariant;
45
45
  size?: 'sm';
46
- }): React.JSX.Element;
46
+ } & React.RefAttributes<HTMLButtonElement>>;
47
47
  interface FieldControlProps {
48
48
  id?: string;
49
49
  'aria-invalid'?: 'true';
@@ -57,9 +57,9 @@ export declare function Field({ label, hint, error, id, className, children, }:
57
57
  className?: string;
58
58
  children: React.ReactElement<FieldControlProps>;
59
59
  }): React.JSX.Element;
60
- export declare const Input: (p: React.InputHTMLAttributes<HTMLInputElement>) => React.JSX.Element;
61
- export declare const Textarea: (p: React.TextareaHTMLAttributes<HTMLTextAreaElement>) => React.JSX.Element;
62
- export declare const Select: (p: React.SelectHTMLAttributes<HTMLSelectElement>) => React.JSX.Element;
60
+ export declare const Input: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & React.RefAttributes<HTMLInputElement>>;
61
+ export declare const Textarea: React.ForwardRefExoticComponent<React.TextareaHTMLAttributes<HTMLTextAreaElement> & React.RefAttributes<HTMLTextAreaElement>>;
62
+ export declare const Select: React.ForwardRefExoticComponent<React.SelectHTMLAttributes<HTMLSelectElement> & React.RefAttributes<HTMLSelectElement>>;
63
63
  type NotifTier = 'urgent' | 'attention' | 'info' | 'background';
64
64
  export declare function Notification({ tier, title, children, action, }: {
65
65
  tier?: NotifTier;
@@ -83,5 +83,20 @@ export declare function Icon({ name, ...rest }: {
83
83
  } & React.HTMLAttributes<HTMLElement>): React.JSX.Element;
84
84
  export declare function useIcons(ref?: React.RefObject<HTMLElement | null>): void;
85
85
  export declare function useWhimsy(ref?: React.RefObject<HTMLElement | null>): void;
86
+ export type AlertTier = 'urgent' | 'attention' | 'info' | 'success';
87
+ export declare function Alert({ tier, title, children, className, ...rest }: React.HTMLAttributes<HTMLDivElement> & {
88
+ tier?: AlertTier;
89
+ title: string;
90
+ }): React.JSX.Element;
91
+ export declare function ButtonGroup({ label, className, ...rest }: React.HTMLAttributes<HTMLDivElement> & {
92
+ label?: string;
93
+ }): React.JSX.Element;
94
+ export declare function ListGroup({ as: As, className, ...rest }: React.HTMLAttributes<HTMLElement> & {
95
+ as?: React.ElementType;
96
+ }): React.JSX.Element;
97
+ export declare function ListGroupItem({ active, as: As, className, ...rest }: React.HTMLAttributes<HTMLElement> & {
98
+ active?: boolean;
99
+ as?: React.ElementType;
100
+ }): React.JSX.Element;
86
101
  export {};
87
102
  //# sourceMappingURL=primitives.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../framework-adap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CAAA;CAAE,qBAE3D;AAED,wBAAgB,SAAS,CAAC,EACxB,EAAE,EAAE,EAAU,EACd,SAAc,EACd,GAAG,IAAI,EACR,EAAE,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG;IAAE,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;CAAE,qBAEhE;AAED,wBAAgB,aAAa,CAAC,EAC5B,MAAc,EACd,EAAE,EAAE,EAAU,EACd,SAAc,EACd,GAAG,IAAI,EACR,EAAE,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;CAAE,qBAElF"}
@@ -51,9 +51,9 @@ export function GridAuto({ min = 240, className = '', style, ...rest }) {
51
51
  const vars = { '--min': `${min}px` };
52
52
  return _jsx("div", { ...rest, style: { ...vars, ...style }, className: cx('grid-auto', className) });
53
53
  }
54
- export function Button({ variant = 'secondary', size, className = '', ...rest }) {
55
- return _jsx("button", { ...rest, className: cx('btn', `btn--${variant}`, size && `btn--${size}`, className) });
56
- }
54
+ export const Button = React.forwardRef(function Button({ variant = 'secondary', size, className = '', ...rest }, ref) {
55
+ return _jsx("button", { ref: ref, ...rest, className: cx('btn', `btn--${variant}`, size && `btn--${size}`, className) });
56
+ });
57
57
  export function Field({ label, hint, error, id, className = '', children, }) {
58
58
  const errId = error ? `${id}-err` : undefined;
59
59
  const hintId = !error && hint ? `${id}-hint` : undefined;
@@ -65,9 +65,15 @@ export function Field({ label, hint, error, id, className = '', children, }) {
65
65
  extra['aria-describedby'] = describedBy;
66
66
  return (_jsxs("div", { className: cx('field', error && 'field--invalid', className), children: [_jsx("label", { className: "field__label", htmlFor: id, children: label }), React.cloneElement(children, extra), error && (_jsx("p", { className: "field__error", id: errId, children: error })), !error && hint && (_jsx("p", { className: "field__hint", id: hintId, children: hint }))] }));
67
67
  }
68
- export const Input = (p) => (_jsx("input", { ...p, className: cx('input', p.className) }));
69
- export const Textarea = (p) => (_jsx("textarea", { ...p, className: cx('textarea', p.className) }));
70
- export const Select = (p) => (_jsx("select", { ...p, className: cx('select', p.className) }));
68
+ export const Input = React.forwardRef(function Input(p, ref) {
69
+ return _jsx("input", { ref: ref, ...p, className: cx('input', p.className) });
70
+ });
71
+ export const Textarea = React.forwardRef(function Textarea(p, ref) {
72
+ return _jsx("textarea", { ref: ref, ...p, className: cx('textarea', p.className) });
73
+ });
74
+ export const Select = React.forwardRef(function Select(p, ref) {
75
+ return _jsx("select", { ref: ref, ...p, className: cx('select', p.className) });
76
+ });
71
77
  export function Notification({ tier = 'info', title, children, action, }) {
72
78
  // Live-region contract: urgent → alert (assertive) · attention/info →
73
79
  // status (polite) · background → NO role — a silent badge, never announced.
@@ -81,10 +87,19 @@ export function Modal({ open, onClose, title, children, footer, labelledBy, }) {
81
87
  const autoId = React.useId();
82
88
  const titleId = labelledBy ?? autoId;
83
89
  React.useEffect(() => {
84
- if (!open || !ref.current || !window.ArtificerFocus)
90
+ if (!open || !ref.current)
85
91
  return;
86
- const trap = window.ArtificerFocus.trap(ref.current, { onEscape: onClose });
87
- return () => trap.release();
92
+ if (window.ArtificerFocus) {
93
+ const trap = window.ArtificerFocus.trap(ref.current, { onEscape: onClose });
94
+ return () => trap.release();
95
+ }
96
+ // Fallback when artificer-focus.js is not loaded (#582): Escape still closes.
97
+ const onKeyDown = (e) => {
98
+ if (e.key === 'Escape')
99
+ onClose();
100
+ };
101
+ document.addEventListener('keydown', onKeyDown);
102
+ return () => document.removeEventListener('keydown', onKeyDown);
88
103
  }, [open, onClose]);
89
104
  if (!open)
90
105
  return null;
@@ -119,3 +134,16 @@ export function useWhimsy(ref) {
119
134
  w.Whimsy?.greeting?.(scope);
120
135
  });
121
136
  }
137
+ export function Alert({ tier = 'info', title, children, className = '', ...rest }) {
138
+ const role = tier === 'urgent' ? 'alert' : 'status';
139
+ return (_jsx("div", { ...rest, role: rest.role ?? role, className: cx('alert', `alert--${tier}`, className), children: _jsxs("div", { className: "alert__body", children: [_jsx("p", { className: "alert__title", children: title }), children && _jsx("div", { className: "alert__msg", children: children })] }) }));
140
+ }
141
+ export function ButtonGroup({ label, className = '', ...rest }) {
142
+ return _jsx("div", { ...rest, role: rest.role ?? 'group', "aria-label": label ?? rest['aria-label'], className: cx('btn-group', className) });
143
+ }
144
+ export function ListGroup({ as: As = 'div', className = '', ...rest }) {
145
+ return _jsx(As, { ...rest, className: cx('list-group', className) });
146
+ }
147
+ export function ListGroupItem({ active = false, as: As = 'div', className = '', ...rest }) {
148
+ return _jsx(As, { ...rest, className: cx('list-group__item', active && 'list-group__item--active', className) });
149
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cameronsjo/artificer",
3
- "version": "0.28.0",
3
+ "version": "0.29.1",
4
4
  "description": "Cameron's personal design system — AuDHD-friendly, dark-first, for tools and dashboards. Apache-2.0 but Cameron-first: published for my own reuse, unsupported, no stability guarantees implied.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Cameron Sjo",
@@ -22,6 +22,7 @@
22
22
  "./whimsy.css": "./src/artificer-whimsy.css",
23
23
  "./texture.css": "./src/artificer-texture.css",
24
24
  "./editorial.css": "./src/artificer-editorial.css",
25
+ "./tailwind.css": "./src/artificer-tailwind.css",
25
26
  "./print.css": "./src/print.css",
26
27
  "./theme.js": {
27
28
  "types": "./types/theme.d.ts",
@@ -3,7 +3,7 @@ name: Artificer
3
3
  description: Cameron's personal design system. AuDHD-optimized, Ghostty-rooted, dark-first with a paper-stock light mode and a Jazz Age Deco palette (burnished gold + royal purple). Use for tools, dashboards, agent UIs, terminals, settings panels — anything that must stay calm until something demands action. Do NOT use for marketing sites, kid-facing UI, or anywhere the goal is delight-via-stimulation.
4
4
  ---
5
5
 
6
- # Artificer · v0.28.0
6
+ # Artificer · v0.29.1
7
7
 
8
8
  A neurodivergent-first design system for Cameron. Every token and rule here exists to reduce cognitive load for an AuDHD brain that **scans instead of reads** and holds **3–4 items** in working memory.
9
9
 
@@ -152,6 +152,9 @@ If you have **no file system** (chat-only artifact), inline the contents of `art
152
152
  | Eyebrow / overline label | `.eyebrow` (+ `.eyebrow--accent`) — uppercase label over a heading, block, or demo — `typography.html#doc-chrome` |
153
153
  | Doc-page subsection header | `<h3 class="subsection-title">` — mono 700 body-md; sibling under `.section-title` — `typography.html#doc-chrome` |
154
154
  | Callout / standing note | `.callout` + `.callout__title` (+ `--steel`/`--attention`/`--urgent`) — an inset tier rule inside a bordered raised box (never a `border-left` on a rounded box); the title names the tier in text — `typography.html#doc-chrome` |
155
+ | Inline static alert inside a card or form | `.alert` + `.alert__body`/`.alert__title`/`.alert__msg` (+ `--urgent`/`--attention`/`--info`/`--success`); React: `Alert` |
156
+ | Joined/segmented button row | `.btn-group` wrapping `.btn` siblings; React: `ButtonGroup` |
157
+ | Bordered vertical stack of rows | `.list-group` + `.list-group__item` (+ `--active`); React: `ListGroup`/`ListGroupItem` |
155
158
  | Doc-page section header | `<h2 class="section-title">` — mono 500, mixed case, `--fg`, border-bottom rule; doc/spec chrome (uppercase tracking is for small labels only) — `data-display.html` |
156
159
  | Live-spec / doc-page example container | `<figure class="figure">` + `<figcaption class="meta">…</figcaption>` — `.figure--frame`/`--flush` modifiers — `data-display.html` |
157
160
  | Make it fun / playful / celebratory / rainbow | The sanctioned `.whimsy` layer, opt-in, one per view; never on chrome/status/data/errors. Palettes: spectrum (default), `.whimsy--brand`, `.whimsy--signature` (gold + purple), `.whimsy--silver`, `.whimsy--gold`. Pick by the "Which one?" table — `whimsy.html` |
@@ -268,7 +268,7 @@
268
268
  setActive(target);
269
269
  return;
270
270
  }
271
- if (e.key === 'Enter') {
271
+ if (e.key === 'Enter' && !e.isComposing && e.keyCode !== 229) {
272
272
  if (current < 0) return;
273
273
  e.preventDefault();
274
274
  select(current);
@@ -219,7 +219,7 @@
219
219
  el.setAttribute('data-sploot-auto-label', '');
220
220
  }
221
221
  }
222
- while (el.firstChild) el.removeChild(el.firstChild);
222
+ el.replaceChildren();
223
223
  layers(p, opts).forEach(function (l) {
224
224
  var span = document.createElement('span');
225
225
  span.className = 'sploot__layer ' + l.cls;
@@ -0,0 +1,92 @@
1
+ /* ═══════════════════════════════════════════════════════════════════════════
2
+ ARTIFICER · Tailwind v4 @theme adapter
3
+ Import AFTER @import "tailwindcss"; (artificer.css may be imported either
4
+ before or after Tailwind — both declare @layer theme, base, components,
5
+ utilities and place Artificer in @layer components).
6
+
7
+ @import "tailwindcss";
8
+ @import "@cameronsjo/artificer/artificer.css";
9
+ @import "@cameronsjo/artificer/tailwind.css";
10
+
11
+ Static tokens live in `@theme`. Runtime CSS custom property references live
12
+ in `@theme inline` so Tailwind inlines `var(--...)` directly into utilities
13
+ without emitting duplicate or self-referential `:root` declarations.
14
+ Spacing tokens use the `s-*` prefix (`p-s-md`, `gap-s-lg`) so they never
15
+ collide with Tailwind v4's container widths (`max-w-xs`..`max-w-3xl`).
16
+ ═══════════════════════════════════════════════════════════════════════════ */
17
+
18
+ @theme {
19
+ /* Typography — bound to Artificer's bundled variable faces (ADR 0046) */
20
+ --font-mono: 'JetBrains Mono', 'Berkeley Mono', ui-monospace, 'SF Mono', Menlo, monospace;
21
+ --font-body: 'Bricolage Grotesque', 'Source Sans 3', system-ui, -apple-system, sans-serif;
22
+ --font-interface: 'Recursive', 'Source Sans 3', system-ui, -apple-system, sans-serif;
23
+ --font-sans: 'Bricolage Grotesque', 'Source Sans 3', system-ui, -apple-system, sans-serif;
24
+
25
+ /* Radius */
26
+ --radius-sm: 4px;
27
+ --radius-md: 8px;
28
+ --radius-lg: 12px;
29
+ --radius-pill: 999px;
30
+
31
+ /* Motion */
32
+ --ease-artificer: cubic-bezier(0.2, 0.7, 0.3, 1);
33
+
34
+ /* Breakpoints */
35
+ --breakpoint-mobile: 640px;
36
+ --breakpoint-tablet: 800px;
37
+ --breakpoint-wide: 1200px;
38
+ }
39
+
40
+ @theme inline {
41
+ /* Surfaces */
42
+ --color-bg: var(--bg);
43
+ --color-bg-raised: var(--bg-raised);
44
+ --color-bg-overlay: var(--bg-overlay);
45
+ --color-bg-inactive: var(--bg-inactive);
46
+
47
+ /* Foreground & borders */
48
+ --color-fg: var(--fg);
49
+ --color-fg-secondary: var(--fg-secondary);
50
+ --color-fg-muted: var(--fg-muted);
51
+ --color-fg-disabled: var(--fg-disabled);
52
+ --color-border: var(--border);
53
+ --color-border-lifted: var(--border-lifted);
54
+
55
+ /* Semantic */
56
+ --color-accent: var(--accent);
57
+ --color-accent-bright: var(--accent-bright);
58
+ --color-accent-fill: var(--accent-fill);
59
+ --color-on-accent: var(--on-accent);
60
+ --color-attention: var(--attention);
61
+ --color-attention-fill: var(--attention-fill);
62
+ --color-on-attention: var(--on-attention);
63
+ --color-urgent: var(--urgent);
64
+ --color-urgent-fill: var(--urgent-fill);
65
+ --color-urgent-text: var(--urgent-text);
66
+ --color-on-urgent: var(--on-urgent);
67
+ --color-success: var(--success);
68
+ --color-success-fill: var(--success-fill);
69
+ --color-on-success: var(--on-success);
70
+ --color-steel: var(--steel);
71
+ --color-steel-fill: var(--steel-fill);
72
+ --color-diff-add-bg: var(--diff-add-bg);
73
+ --color-diff-del-bg: var(--diff-del-bg);
74
+
75
+ /* Brand */
76
+ --color-brand-purple: var(--brand-purple);
77
+ --color-brand-purple-bright: var(--brand-purple-bright);
78
+ --color-brand-purple-fill: var(--brand-purple-fill);
79
+
80
+ /* Spacing (8px grid — s-* prefix avoids clobbering Tailwind's max-w-xs..3xl) */
81
+ --spacing-s-xs: var(--s-xs);
82
+ --spacing-s-sm: var(--s-sm);
83
+ --spacing-s-md: var(--s-md);
84
+ --spacing-s-lg: var(--s-lg);
85
+ --spacing-s-xl: var(--s-xl);
86
+ --spacing-s-2xl: var(--s-2xl);
87
+ --spacing-s-3xl: var(--s-3xl);
88
+
89
+ /* Shadows (art-* prefix avoids self-referential --shadow-overlay cycles) */
90
+ --shadow-art-overlay: var(--shadow-overlay);
91
+ --shadow-art-popover: var(--shadow-popover);
92
+ }
@@ -29,12 +29,18 @@
29
29
  return mode === 'auto' ? systemTheme() : mode;
30
30
  }
31
31
 
32
- // Paint the mode everywhere: the html attribute, plus state narration on
33
- // every toggle (data-theme-mode for styling hooks, aria-label/title for
34
- // people, the legacy label span if present).
32
+ function syncColorSchemeMeta(mode, theme) {
33
+ var meta = document.querySelector && document.querySelector('meta[name="color-scheme"]');
34
+ if (meta) meta.setAttribute('content', mode === 'auto' ? 'light dark' : theme);
35
+ }
36
+
37
+ // Paint the mode everywhere: the html attribute, <meta name="color-scheme">,
38
+ // plus state narration on every toggle (data-theme-mode for styling hooks,
39
+ // aria-label/title for people, the legacy label span if present).
35
40
  function reflect(mode) {
36
41
  var theme = resolvedTheme(mode);
37
42
  document.documentElement.setAttribute('data-theme', theme);
43
+ syncColorSchemeMeta(mode, theme);
38
44
  var next = MODES[(MODES.indexOf(mode) + 1) % MODES.length];
39
45
  var state = mode === 'auto' ? 'auto (' + theme + ')' : mode;
40
46
  document.querySelectorAll('[data-theme-toggle]').forEach(function (b) {
@@ -141,9 +147,14 @@
141
147
  // the same autoInit shape as artificer-icons.js. observe() calls bind()
142
148
  // internally, so static pages see no double-scan; SPA-mounted
143
149
  // [data-theme-toggle] buttons now bind without manual observe() arming.
150
+ var disconnectBodyObserver = null;
144
151
  function autoInit() {
152
+ if (disconnectBodyObserver) {
153
+ disconnectBodyObserver();
154
+ disconnectBodyObserver = null;
155
+ }
145
156
  if (typeof MutationObserver !== 'undefined') {
146
- observe(document.body);
157
+ disconnectBodyObserver = observe(document.body);
147
158
  } else {
148
159
  bind();
149
160
  }
@@ -153,4 +164,20 @@
153
164
  } else {
154
165
  autoInit();
155
166
  }
167
+
168
+ // Astro View Transitions (#530): swaps replace <html> attributes and <body>.
169
+ // Carry data-theme + <meta name="color-scheme"> onto the incoming document
170
+ // before swap so there is no flash, then re-bind/re-observe after swap.
171
+ if (document.addEventListener) {
172
+ document.addEventListener('astro:before-swap', function (ev) {
173
+ var doc = ev && ev.newDocument;
174
+ if (!doc || !doc.documentElement) return;
175
+ var mode = storedMode();
176
+ var theme = resolvedTheme(mode);
177
+ doc.documentElement.setAttribute('data-theme', theme);
178
+ var meta = doc.querySelector && doc.querySelector('meta[name="color-scheme"]');
179
+ if (meta) meta.setAttribute('content', mode === 'auto' ? 'light dark' : theme);
180
+ });
181
+ document.addEventListener('astro:page-load', autoInit);
182
+ }
156
183
  })();
@@ -1,5 +1,5 @@
1
1
  /* ═══════════════════════════════════════════════════════════════════════════
2
- ARTIFICER · Whimsy helper · v0.28.0
2
+ ARTIFICER · Whimsy helper · v0.29.1
3
3
  ─────────────────────────────────────────────────────────────────────────
4
4
  Tiny, dependency-free. Pairs with artificer-whimsy.css. Exposes window.Whimsy.
5
5