@cameronsjo/artificer 0.18.1 → 0.21.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/README.md +65 -6
- package/bin/artificer.mjs +655 -0
- package/bin/lint-core.mjs +151 -0
- package/package.json +11 -3
- package/reference/SKILL.md +407 -0
- package/src/artificer-editorial.css +40 -0
- package/src/artificer-icons.js +122 -45
- package/src/artificer-theme.js +115 -25
- package/src/artificer-whimsy.css +15 -1
- package/src/artificer-whimsy.js +155 -12
- package/src/artificer.css +85 -8
- package/src/primitives.json +1084 -0
- package/src/theme-bootstrap.html +6 -3
- package/src/tokens.json +7 -4
package/src/artificer-icons.js
CHANGED
|
@@ -10,60 +10,106 @@
|
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
12
|
// 16×16 paths. Stroke-only (no fills) so they read on any surface.
|
|
13
|
-
// Sourced from Lucide (lucide.dev, ISC license)
|
|
13
|
+
// Sourced from Lucide (lucide.dev, ISC license), hand-redrawn onto the
|
|
14
|
+
// 16-grid (24-grid × ⅔, then tuned) — never pasted. Keys are the
|
|
15
|
+
// canonical Lucide names; legacy names live in ALIASES below.
|
|
14
16
|
const PATHS = {
|
|
15
17
|
// Navigation / chrome
|
|
16
|
-
'menu':
|
|
17
|
-
'
|
|
18
|
-
'chevron-
|
|
19
|
-
'chevron-
|
|
20
|
-
'chevron-
|
|
21
|
-
'
|
|
22
|
-
'arrow-
|
|
23
|
-
'
|
|
24
|
-
'external': 'M10 3h3v3M13 3l-6 6M11 9v3H4V5h3',
|
|
18
|
+
'menu': 'M3 4h10M3 8h10M3 12h10', // bars span the box (Lucide 6/12/18 × ⅔) — reads standing alone at 16px (#114)
|
|
19
|
+
'chevron-right': 'M6 4l4 4-4 4',
|
|
20
|
+
'chevron-left': 'M10 4l-4 4 4 4',
|
|
21
|
+
'chevron-down': 'M4 6l4 4 4-4',
|
|
22
|
+
'chevron-up': 'M4 10l4-4 4 4',
|
|
23
|
+
'arrow-right': 'M3 8h10M9 4l4 4-4 4',
|
|
24
|
+
'arrow-left': 'M13 8H3M7 4L3 8l4 4',
|
|
25
|
+
'external-link': 'M10 3h3v3M13 3l-6 6M11 9v3H4V5h3',
|
|
25
26
|
|
|
26
27
|
// Status / semantic
|
|
27
|
-
'check':
|
|
28
|
-
'x':
|
|
29
|
-
'alert':
|
|
30
|
-
'info':
|
|
31
|
-
'circle-dot':
|
|
32
|
-
'
|
|
28
|
+
'check': 'M3 8l3 3 7-7',
|
|
29
|
+
'x': 'M4 4l8 8M12 4l-8 8',
|
|
30
|
+
'triangle-alert': 'M8 2L1.5 13h13L8 2zM8 6v3M8 11.5v.01',
|
|
31
|
+
'info': 'M8 1a7 7 0 100 14A7 7 0 008 1zM8 7v4M8 4.5v.01',
|
|
32
|
+
'circle-dot': 'M8 1a7 7 0 100 14A7 7 0 008 1zM8 6a2 2 0 100 4 2 2 0 000-4z',
|
|
33
|
+
'loader': 'M8 1.5v2.5M8 12v2.5M3.4 3.4l1.8 1.8M10.8 10.8l1.8 1.8M1.5 8H4M12 8h2.5M3.4 12.6l1.8-1.8M10.8 5.2l1.8-1.8',
|
|
33
34
|
|
|
34
35
|
// Actions
|
|
35
|
-
'plus':
|
|
36
|
-
'minus':
|
|
37
|
-
'search':
|
|
38
|
-
'
|
|
39
|
-
'trash':
|
|
40
|
-
'copy':
|
|
41
|
-
'download':
|
|
42
|
-
'upload':
|
|
43
|
-
'send':
|
|
44
|
-
'refresh':
|
|
36
|
+
'plus': 'M8 3v10M3 8h10',
|
|
37
|
+
'minus': 'M3 8h10',
|
|
38
|
+
'search': 'M11.5 11.5L14 14M2.5 7a4.5 4.5 0 109 0 4.5 4.5 0 00-9 0z',
|
|
39
|
+
'pencil': 'M11 2l3 3-8 8H3v-3l8-8zM10 3l3 3',
|
|
40
|
+
'trash-2': 'M3 4h10M5.5 4V2.5h5V4M4.5 4l.5 9.5h6L11.5 4M6.5 7v4M9.5 7v4',
|
|
41
|
+
'copy': 'M5 5V3a1 1 0 011-1h7a1 1 0 011 1v7a1 1 0 01-1 1h-2M3 5h7a1 1 0 011 1v7a1 1 0 01-1 1H3a1 1 0 01-1-1V6a1 1 0 011-1z',
|
|
42
|
+
'download': 'M8 2v8M4 7l4 4 4-4M2 13h12',
|
|
43
|
+
'upload': 'M8 11V3M4 6l4-4 4 4M2 13h12',
|
|
44
|
+
'send': 'M14 2L1 8l5 2 8-8zM14 2l-6 12-2-5',
|
|
45
|
+
'refresh-cw': 'M14 4v3.5h-3.5M2 12V8.5h3.5M3 6a5.5 5.5 0 0110.5-1M13 10a5.5 5.5 0 01-10.5 1',
|
|
45
46
|
|
|
46
47
|
// Files & system
|
|
47
|
-
'file':
|
|
48
|
-
'folder':
|
|
49
|
-
'terminal':
|
|
50
|
-
'code':
|
|
51
|
-
'settings':
|
|
52
|
-
'theme':
|
|
48
|
+
'file': 'M4 1h6l3 3v10a1 1 0 01-1 1H4a1 1 0 01-1-1V2a1 1 0 011-1zM10 1v3h3',
|
|
49
|
+
'folder': 'M2 4a1 1 0 011-1h3l1.5 1.5H13a1 1 0 011 1V13a1 1 0 01-1 1H3a1 1 0 01-1-1V4z',
|
|
50
|
+
'square-terminal': 'M2 3h12a1 1 0 011 1v8a1 1 0 01-1 1H2a1 1 0 01-1-1V4a1 1 0 011-1zM4 6l2 2-2 2M8 10h4',
|
|
51
|
+
'code': 'M5 4L1 8l4 4M11 4l4 4-4 4',
|
|
52
|
+
'settings': 'M8 5.5a2.5 2.5 0 100 5 2.5 2.5 0 000-5zM8 1v1.5M8 13.5V15M2.5 8H1M15 8h-1.5M3.5 3.5l1 1M11.5 11.5l1 1M3.5 12.5l1-1M11.5 4.5l1-1',
|
|
53
|
+
'theme': 'M8 1a7 7 0 100 14V1z', // Artificer-custom — no Lucide counterpart
|
|
53
54
|
|
|
54
55
|
// Person
|
|
55
|
-
'user':
|
|
56
|
-
'
|
|
56
|
+
'user': 'M8 8a3 3 0 100-6 3 3 0 000 6zM2 14c.5-3 3-5 6-5s5.5 2 6 5',
|
|
57
|
+
'log-out': 'M10 4V3a1 1 0 00-1-1H3a1 1 0 00-1 1v10a1 1 0 001 1h6a1 1 0 001-1v-1M7 8h7M11 5l3 3-3 3',
|
|
58
|
+
|
|
59
|
+
// Common objects
|
|
60
|
+
'lock': 'M4 7.5h8a1 1 0 011 1v4a1 1 0 01-1 1H4a1 1 0 01-1-1v-4a1 1 0 011-1zM5.5 7.5V5a2.5 2.5 0 015 0v2.5',
|
|
61
|
+
'lock-open': 'M4 7.5h8a1 1 0 011 1v4a1 1 0 01-1 1H4a1 1 0 01-1-1v-4a1 1 0 011-1zM5.5 7.5V5a2.5 2.5 0 014.9-.6',
|
|
62
|
+
'layers': 'M8 2L2 5l6 3 6-3-6-3zM2 8l6 3 6-3M2 11l6 3 6-3',
|
|
63
|
+
'droplet': 'M8 1.5c2 3 4.5 5.5 4.5 8.5a4.5 4.5 0 01-9 0c0-3 2.5-5.5 4.5-8.5z',
|
|
64
|
+
'eye': 'M1.5 8s2.5-4.5 6.5-4.5S14.5 8 14.5 8s-2.5 4.5-6.5 4.5S1.5 8 1.5 8zM8 6.5a1.5 1.5 0 100 3 1.5 1.5 0 000-3z',
|
|
65
|
+
'eye-off': 'M1.5 8s2.5-4.5 6.5-4.5S14.5 8 14.5 8s-2.5 4.5-6.5 4.5S1.5 8 1.5 8zM3 3l10 10',
|
|
66
|
+
'clock': 'M8 1a7 7 0 100 14A7 7 0 008 1zM8 4v4l2.5 1.5',
|
|
67
|
+
|
|
68
|
+
// Observability & app-nav (#228 — 8 curated additions, hand-tuned 16-grid)
|
|
69
|
+
'activity': 'M1 8h3l2 5 3-10 2 5h4', // Metrics — ECG pulse
|
|
70
|
+
'bell': 'M8 2a4 4 0 00-4 4c0 4-1.5 5-1.5 5h11s-1.5-1-1.5-5a4 4 0 00-4-4zM6.5 13.5a1.5 1.5 0 003 0', // Alerts
|
|
71
|
+
'git-branch': 'M4 2v8M4 10a2 2 0 100 4 2 2 0 000-4zM12 2a2 2 0 100 4 2 2 0 000-4zM12 6a6 6 0 01-6 6', // Traces
|
|
72
|
+
'users': 'M6 3a2.5 2.5 0 100 5 2.5 2.5 0 000-5zM1.5 14c0-2.8 2-4.3 4.5-4.3s4.5 1.5 4.5 4.3M11 3.2a2.5 2.5 0 010 4.6M11.8 9.8c1.6.5 2.7 2 2.7 4.2', // Team
|
|
73
|
+
'box': 'M8 1.5l6 3v7l-6 3-6-3v-7l6-3zM2 4.5l6 3 6-3M8 7.5v7', // Environments — cube
|
|
74
|
+
'credit-card': 'M2.5 4h11a1 1 0 011 1v6a1 1 0 01-1 1h-11a1 1 0 01-1-1V5a1 1 0 011-1zM1.5 7h13M4 10h3', // Billing
|
|
75
|
+
'list': 'M6 4h8M6 8h8M6 12h8M3 4h.01M3 8h.01M3 12h.01', // Logs — dotted rows
|
|
76
|
+
'layout': 'M3.5 2h9a1.5 1.5 0 011.5 1.5v9a1.5 1.5 0 01-1.5 1.5h-9A1.5 1.5 0 012 12.5v-9A1.5 1.5 0 013.5 2zM2 6h12M6 6v8', // Dashboards — header + sidebar
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Legacy names → canonical Lucide keys. Markup written against the old
|
|
80
|
+
// set keeps working; list() reports canonical names only. close/x were
|
|
81
|
+
// byte-identical entries — close folds in here.
|
|
82
|
+
const ALIASES = {
|
|
83
|
+
'close': 'x',
|
|
84
|
+
'chevron-r': 'chevron-right',
|
|
85
|
+
'chevron-l': 'chevron-left',
|
|
86
|
+
'chevron-d': 'chevron-down',
|
|
87
|
+
'chevron-u': 'chevron-up',
|
|
88
|
+
'arrow-r': 'arrow-right',
|
|
89
|
+
'arrow-l': 'arrow-left',
|
|
90
|
+
'external': 'external-link',
|
|
91
|
+
'alert': 'triangle-alert',
|
|
92
|
+
'spinner': 'loader',
|
|
93
|
+
'edit': 'pencil',
|
|
94
|
+
'trash': 'trash-2',
|
|
95
|
+
'refresh': 'refresh-cw',
|
|
96
|
+
'terminal': 'square-terminal',
|
|
97
|
+
'logout': 'log-out',
|
|
57
98
|
};
|
|
58
99
|
|
|
59
100
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
101
|
+
const hasOwn = Object.prototype.hasOwnProperty;
|
|
60
102
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
103
|
+
// Own-property lookups only — DOM-sourced names like "constructor" must
|
|
104
|
+
// miss cleanly instead of reaching the Object prototype (which made
|
|
105
|
+
// build() throw mid-hydrate).
|
|
106
|
+
function resolve(name) {
|
|
107
|
+
if (hasOwn.call(PATHS, name)) return name;
|
|
108
|
+
if (hasOwn.call(ALIASES, name)) return ALIASES[name];
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function baseSvg(opts) {
|
|
67
113
|
const svg = document.createElementNS(SVG_NS, 'svg');
|
|
68
114
|
const size = (opts && opts.size) || 16;
|
|
69
115
|
svg.setAttribute('viewBox', '0 0 16 16');
|
|
@@ -77,13 +123,23 @@
|
|
|
77
123
|
svg.setAttribute('aria-hidden', 'true');
|
|
78
124
|
svg.setAttribute('focusable', 'false');
|
|
79
125
|
svg.classList.add('icon');
|
|
126
|
+
return svg;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function build(name, opts) {
|
|
130
|
+
const key = resolve(name);
|
|
131
|
+
if (!key) {
|
|
132
|
+
console.warn('[artificer/icons] Unknown icon: ' + name);
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
const svg = baseSvg(opts);
|
|
80
136
|
if (opts && opts.className) {
|
|
81
137
|
svg.classList.add(...opts.className.split(/\s+/).filter(Boolean));
|
|
82
138
|
}
|
|
83
139
|
|
|
84
140
|
// Split path data on M commands so each subpath is its own <path>;
|
|
85
141
|
// keeps stroke joins clean across disconnected strokes.
|
|
86
|
-
const subpaths =
|
|
142
|
+
const subpaths = PATHS[key].split(/(?=M)/g).filter(Boolean);
|
|
87
143
|
subpaths.forEach(p => {
|
|
88
144
|
const path = document.createElementNS(SVG_NS, 'path');
|
|
89
145
|
path.setAttribute('d', p.trim());
|
|
@@ -92,18 +148,39 @@
|
|
|
92
148
|
return svg;
|
|
93
149
|
}
|
|
94
150
|
|
|
151
|
+
// Dashed-box stand-in for an unknown name. A blank <i> was a silent
|
|
152
|
+
// failure only the console knew about (#170) — the box makes the miss
|
|
153
|
+
// visible in the page itself. DOM hydration only; build() keeps its
|
|
154
|
+
// returns-null contract for programmatic callers.
|
|
155
|
+
function buildMissing(opts) {
|
|
156
|
+
const svg = baseSvg(opts);
|
|
157
|
+
svg.classList.add('icon--missing');
|
|
158
|
+
const rect = document.createElementNS(SVG_NS, 'rect');
|
|
159
|
+
rect.setAttribute('x', '2.5');
|
|
160
|
+
rect.setAttribute('y', '2.5');
|
|
161
|
+
rect.setAttribute('width', '11');
|
|
162
|
+
rect.setAttribute('height', '11');
|
|
163
|
+
rect.setAttribute('rx', '1');
|
|
164
|
+
rect.setAttribute('stroke-dasharray', '2 2');
|
|
165
|
+
svg.appendChild(rect);
|
|
166
|
+
return svg;
|
|
167
|
+
}
|
|
168
|
+
|
|
95
169
|
// Replace <i data-icon="name"></i> placeholders in the DOM
|
|
96
170
|
function hydrate(root) {
|
|
97
171
|
const scope = root || document;
|
|
98
172
|
scope.querySelectorAll('[data-icon]').forEach(el => {
|
|
99
173
|
if (el.dataset.iconHydrated === '1') return;
|
|
100
174
|
const name = el.getAttribute('data-icon');
|
|
101
|
-
const
|
|
175
|
+
const opts = {
|
|
102
176
|
size: el.getAttribute('data-icon-size') || 16,
|
|
103
177
|
strokeWidth: el.getAttribute('data-icon-stroke') || 1.5,
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
178
|
+
};
|
|
179
|
+
// Marking unknown names hydrated stops the warn-per-mutation-batch
|
|
180
|
+
// loop; an attribute change clears the lock, so fixing data-icon
|
|
181
|
+
// still rebuilds.
|
|
182
|
+
const svg = build(name, opts) || buildMissing(opts);
|
|
183
|
+
el.textContent = '';
|
|
107
184
|
el.appendChild(svg);
|
|
108
185
|
el.dataset.iconHydrated = '1';
|
|
109
186
|
});
|
package/src/artificer-theme.js
CHANGED
|
@@ -1,42 +1,117 @@
|
|
|
1
1
|
// Artificer · theme handling (persisted in localStorage, shared across pages)
|
|
2
|
+
//
|
|
3
|
+
// Three modes, one key: 'dark' | 'light' | 'auto'. Explicit modes pin the
|
|
4
|
+
// theme; 'auto' (or nothing stored) follows prefers-color-scheme live. The
|
|
5
|
+
// toggle cycles dark → light → auto. The canonical control is an EMPTY
|
|
6
|
+
// <button class="theme-toggle" data-theme-toggle aria-label="Toggle theme">
|
|
7
|
+
// — bind() injects the half-circle `theme` glyph itself (no dependency on
|
|
8
|
+
// artificer-icons.js) and keeps aria-label/title narrating state + next
|
|
9
|
+
// action. Legacy markup (.dot + [data-theme-label]) keeps working; the
|
|
10
|
+
// label reads Dark / Light / Auto.
|
|
2
11
|
(function () {
|
|
3
12
|
var KEY = 'artificer.theme';
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
var MODES = ['dark', 'light', 'auto'];
|
|
14
|
+
var SVG_NS = 'http://www.w3.org/2000/svg';
|
|
15
|
+
var GLYPH = 'M8 1a7 7 0 100 14V1z'; // the Artificer-custom `theme` mark
|
|
16
|
+
|
|
17
|
+
function systemTheme() {
|
|
18
|
+
return window.matchMedia &&
|
|
19
|
+
window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
|
8
20
|
}
|
|
9
21
|
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
try { localStorage.
|
|
22
|
+
function storedMode() {
|
|
23
|
+
var s = null;
|
|
24
|
+
try { s = localStorage.getItem(KEY); } catch (e) {}
|
|
25
|
+
return MODES.indexOf(s) > -1 ? s : 'auto';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function resolvedTheme(mode) {
|
|
29
|
+
return mode === 'auto' ? systemTheme() : mode;
|
|
30
|
+
}
|
|
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).
|
|
35
|
+
function reflect(mode) {
|
|
36
|
+
var theme = resolvedTheme(mode);
|
|
37
|
+
document.documentElement.setAttribute('data-theme', theme);
|
|
38
|
+
var next = MODES[(MODES.indexOf(mode) + 1) % MODES.length];
|
|
39
|
+
var state = mode === 'auto' ? 'auto (' + theme + ')' : mode;
|
|
13
40
|
document.querySelectorAll('[data-theme-toggle]').forEach(function (b) {
|
|
41
|
+
b.setAttribute('data-theme-mode', mode);
|
|
42
|
+
b.setAttribute('aria-label', 'Theme: ' + state + '. Switch to ' + next + '.');
|
|
43
|
+
b.setAttribute('title', 'Theme: ' + state);
|
|
14
44
|
var label = b.querySelector('[data-theme-label]');
|
|
15
|
-
if (label)
|
|
45
|
+
if (label) {
|
|
46
|
+
label.textContent = mode === 'auto' ? 'Auto'
|
|
47
|
+
: theme === 'light' ? 'Light' : 'Dark';
|
|
48
|
+
}
|
|
16
49
|
});
|
|
17
50
|
}
|
|
18
51
|
|
|
52
|
+
function apply(next) {
|
|
53
|
+
if (MODES.indexOf(next) === -1) {
|
|
54
|
+
console.warn('[artificer/theme] Unknown mode: ' + next);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
try { localStorage.setItem(KEY, next); } catch (e) {}
|
|
58
|
+
reflect(next);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function toggle() {
|
|
62
|
+
apply(MODES[(MODES.indexOf(storedMode()) + 1) % MODES.length]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The canonical empty button gets the glyph injected; buttons that ship
|
|
66
|
+
// their own children (legacy dot + label, or a consumer's custom icon)
|
|
67
|
+
// are left untouched.
|
|
68
|
+
function ensureIcon(b) {
|
|
69
|
+
if (b.firstElementChild) return;
|
|
70
|
+
var svg = document.createElementNS(SVG_NS, 'svg');
|
|
71
|
+
svg.setAttribute('viewBox', '0 0 16 16');
|
|
72
|
+
svg.setAttribute('width', 16);
|
|
73
|
+
svg.setAttribute('height', 16);
|
|
74
|
+
svg.setAttribute('fill', 'none');
|
|
75
|
+
svg.setAttribute('stroke', 'currentColor');
|
|
76
|
+
svg.setAttribute('stroke-width', 1.5);
|
|
77
|
+
svg.setAttribute('stroke-linecap', 'round');
|
|
78
|
+
svg.setAttribute('stroke-linejoin', 'round');
|
|
79
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
80
|
+
svg.setAttribute('focusable', 'false');
|
|
81
|
+
svg.classList.add('icon');
|
|
82
|
+
var path = document.createElementNS(SVG_NS, 'path');
|
|
83
|
+
path.setAttribute('d', GLYPH);
|
|
84
|
+
svg.appendChild(path);
|
|
85
|
+
b.appendChild(svg);
|
|
86
|
+
b.classList.add('theme-toggle--icon');
|
|
87
|
+
}
|
|
88
|
+
|
|
19
89
|
function bind() {
|
|
20
|
-
var
|
|
21
|
-
(window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark');
|
|
90
|
+
var fresh = false;
|
|
22
91
|
document.querySelectorAll('[data-theme-toggle]').forEach(function (b) {
|
|
23
92
|
if (b.dataset.themeBound === '1') return;
|
|
24
93
|
b.dataset.themeBound = '1';
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
b.addEventListener('click',
|
|
28
|
-
var cur = document.documentElement.getAttribute('data-theme') ||
|
|
29
|
-
(window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark');
|
|
30
|
-
apply(cur === 'light' ? 'dark' : 'light');
|
|
31
|
-
});
|
|
94
|
+
fresh = true;
|
|
95
|
+
ensureIcon(b);
|
|
96
|
+
b.addEventListener('click', toggle);
|
|
32
97
|
});
|
|
98
|
+
if (fresh) reflect(storedMode());
|
|
33
99
|
}
|
|
34
100
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
101
|
+
// In auto, track the OS preference live. Pinned modes ignore the event.
|
|
102
|
+
if (window.matchMedia) {
|
|
103
|
+
var mq = window.matchMedia('(prefers-color-scheme: light)');
|
|
104
|
+
var onChange = function () { if (storedMode() === 'auto') reflect('auto'); };
|
|
105
|
+
if (mq.addEventListener) mq.addEventListener('change', onChange);
|
|
106
|
+
else if (mq.addListener) mq.addListener(onChange);
|
|
39
107
|
}
|
|
108
|
+
|
|
109
|
+
// Early paint: an explicit stored mode applies before bind so pages
|
|
110
|
+
// without the pre-paint bootstrap still land on the pinned theme fast.
|
|
111
|
+
if (storedMode() !== 'auto') {
|
|
112
|
+
document.documentElement.setAttribute('data-theme', storedMode());
|
|
113
|
+
}
|
|
114
|
+
|
|
40
115
|
// SPA lifecycle — auto-hydrate nodes inserted after first paint. Returns a
|
|
41
116
|
// disconnect fn. Idempotent guards make the re-scan cheap (done nodes skip).
|
|
42
117
|
function observe(root) {
|
|
@@ -55,12 +130,27 @@
|
|
|
55
130
|
mo.observe(root, { childList: true, subtree: true });
|
|
56
131
|
return function () { mo.disconnect(); };
|
|
57
132
|
}
|
|
58
|
-
|
|
133
|
+
// KEY is exposed as the ONE canonical definition of the persistence key
|
|
134
|
+
// (#36 item 1): framework adapters read window.ArtificerTheme.KEY instead of
|
|
135
|
+
// re-hardcoding the 'artificer.theme' literal, so the dot/hyphen split can't
|
|
136
|
+
// reopen. This is a classic <script> (not an ESM), so the key ships on the
|
|
137
|
+
// runtime object rather than as an `export`.
|
|
138
|
+
window.ArtificerTheme = { apply: apply, toggle: toggle, bind: bind, observe: observe, KEY: KEY };
|
|
59
139
|
|
|
60
|
-
//
|
|
140
|
+
// Auto-bind on DOM ready, then arm the MutationObserver for SPA use —
|
|
141
|
+
// the same autoInit shape as artificer-icons.js. observe() calls bind()
|
|
142
|
+
// internally, so static pages see no double-scan; SPA-mounted
|
|
143
|
+
// [data-theme-toggle] buttons now bind without manual observe() arming.
|
|
144
|
+
function autoInit() {
|
|
145
|
+
if (typeof MutationObserver !== 'undefined') {
|
|
146
|
+
observe(document.body);
|
|
147
|
+
} else {
|
|
148
|
+
bind();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
61
151
|
if (document.readyState === 'loading') {
|
|
62
|
-
document.addEventListener('DOMContentLoaded',
|
|
152
|
+
document.addEventListener('DOMContentLoaded', autoInit);
|
|
63
153
|
} else {
|
|
64
|
-
|
|
154
|
+
autoInit();
|
|
65
155
|
}
|
|
66
156
|
})();
|
package/src/artificer-whimsy.css
CHANGED
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
--whimsy-bob: 2.6s; /* sine-wave bob period (wave variant) */
|
|
40
40
|
--whimsy-rise: 0.16em; /* sine-wave bob amplitude */
|
|
41
41
|
--whimsy-settle-speed: 150s; /* glacial rest cycle — ~2.5min, sub-perceptual */
|
|
42
|
+
--whimsy-dissolve-hold: 800ms; /* graceful exit: fully-lit before receding */
|
|
43
|
+
--whimsy-dissolve-fade: 2000ms; /* graceful exit: opacity fade-out duration */
|
|
42
44
|
|
|
43
45
|
/* Burnished spectrum — hue stops walk Artificer's own brand hues and loop
|
|
44
46
|
(first == last so the flow is seamless). Built lazily from the knobs,
|
|
@@ -304,6 +306,18 @@
|
|
|
304
306
|
.whimsy--wave > .whimsy-char { transform: none !important; }
|
|
305
307
|
}
|
|
306
308
|
|
|
309
|
+
/* ─── Dissolve — the graceful one-shot exit (Whimsy.dissolve / .celebrate) ──
|
|
310
|
+
The gradient is clipped to text (color:transparent), so it can't transition
|
|
311
|
+
to a solid — opacity is the only animatable handle. Fade the whole element
|
|
312
|
+
out (flow keeps shimmering as it recedes), then JS clears it. */
|
|
313
|
+
.whimsy--dissolving {
|
|
314
|
+
transition: opacity var(--whimsy-dissolve-fade) var(--ease);
|
|
315
|
+
opacity: 0;
|
|
316
|
+
}
|
|
317
|
+
@media (prefers-reduced-motion: reduce) {
|
|
318
|
+
.whimsy--dissolving { transition: none; } /* JS also collapses to instant clear */
|
|
319
|
+
}
|
|
320
|
+
|
|
307
321
|
|
|
308
322
|
/* ─── Whimsy focus ring (opt-in · explicit request only) ───────────────────
|
|
309
323
|
A burnished ring that circles a focused control — delight layered OVER
|
|
@@ -379,7 +393,7 @@
|
|
|
379
393
|
travels; reveals L→R. Put it on the text element (made inline-block) so it
|
|
380
394
|
shares the mark's exact width + gradient. The sanctioned replacement for a
|
|
381
395
|
flat link underline on a .whimsy wordmark — see CLAUDE.md § Whimsy + § Brand. */
|
|
382
|
-
.whimsy-underline { position: relative; display: inline-block; }
|
|
396
|
+
.whimsy-underline { position: relative; display: inline-block; width: fit-content; }
|
|
383
397
|
.whimsy-underline::after {
|
|
384
398
|
content: ""; position: absolute; left: 0; right: 0; bottom: -0.3em; height: 10px;
|
|
385
399
|
background-image: var(--whimsy-gradient); background-size: 200% 100%;
|
package/src/artificer-whimsy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
-
ARTIFICER · Whimsy helper · v0.
|
|
2
|
+
ARTIFICER · Whimsy helper · v0.21.0
|
|
3
3
|
─────────────────────────────────────────────────────────────────────────
|
|
4
4
|
Tiny, dependency-free. Pairs with artificer-whimsy.css. Exposes window.Whimsy.
|
|
5
5
|
|
|
@@ -9,9 +9,21 @@
|
|
|
9
9
|
typed — the "ultrathink" gesture.
|
|
10
10
|
opts = { triggers:[…], target?, onIgnite?,
|
|
11
11
|
onClear?, loops?, settle? }
|
|
12
|
-
Whimsy.celebrate(el, ms?) one-shot: light el up for ms (default
|
|
13
|
-
then
|
|
14
|
-
|
|
12
|
+
Whimsy.celebrate(el, ms?) one-shot: light el up, hold for ms (default
|
|
13
|
+
2600), then dissolve out with a graceful
|
|
14
|
+
opacity fade (celebrate(el, {dissolve:false})
|
|
15
|
+
for the old hard clear). For whimsical
|
|
16
|
+
operations (deploy succeeded, streak hit).
|
|
17
|
+
Whimsy.dissolve(el, opts?) graceful exit: hold (flowing) → opacity
|
|
18
|
+
fade-out → clear. Reduced-motion collapses
|
|
19
|
+
to an instant clear. opts = { hold?, fade? }
|
|
20
|
+
— omitted values read the element's live
|
|
21
|
+
--whimsy-dissolve-hold/-fade. Returns
|
|
22
|
+
cancel() — aborts the exit, leaving the
|
|
23
|
+
element lit (does not remove "whimsy").
|
|
24
|
+
Whimsy.parseMs(v) PURE — parse a CSS <time> ("800ms" |
|
|
25
|
+
"1.5s") into ms; NaN if unparseable.
|
|
26
|
+
Internal utility, exposed for testing.
|
|
15
27
|
Whimsy.greeting(root?) swap [data-whimsy-greeting] elements to the
|
|
16
28
|
seasonal footer line — June → "happy pride"
|
|
17
29
|
+ vivid flow; off-season → the inline text
|
|
@@ -36,7 +48,34 @@
|
|
|
36
48
|
"use strict";
|
|
37
49
|
|
|
38
50
|
function igniteEl(el) { if (el) el.classList.add("whimsy"); }
|
|
39
|
-
|
|
51
|
+
|
|
52
|
+
/* ── Dissolve bookkeeping ── el → in-flight { t1, t2 } timers ──────────────
|
|
53
|
+
One entry per element currently mid-exit. cancelDissolve() is the single
|
|
54
|
+
full-cleanup path: cancels both timers, drops the dissolving class and
|
|
55
|
+
any inline fade override, forgets the entry. Called by clearEl() (so an
|
|
56
|
+
external hard clear can never orphan a dissolve chain mid-fade) and by
|
|
57
|
+
dissolve()/celebrate() (both to implement the returned cancel(), and to
|
|
58
|
+
cancel any PRIOR chain before arming a new one — element reuse, e.g. a
|
|
59
|
+
double-celebrate, must not let an old timer clear the new run out from
|
|
60
|
+
under it). */
|
|
61
|
+
var dissolveTimers = new WeakMap();
|
|
62
|
+
function cancelDissolve(el) {
|
|
63
|
+
if (!el) return;
|
|
64
|
+
var timers = dissolveTimers.get(el);
|
|
65
|
+
if (timers) {
|
|
66
|
+
window.clearTimeout(timers.t1);
|
|
67
|
+
window.clearTimeout(timers.t2);
|
|
68
|
+
dissolveTimers.delete(el);
|
|
69
|
+
}
|
|
70
|
+
el.classList.remove("whimsy--dissolving");
|
|
71
|
+
el.style.removeProperty("--whimsy-dissolve-fade");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function clearEl(el) {
|
|
75
|
+
if (!el) return;
|
|
76
|
+
cancelDissolve(el);
|
|
77
|
+
el.classList.remove("whimsy");
|
|
78
|
+
}
|
|
40
79
|
|
|
41
80
|
/* ── Settle ── flow for N hue-cycles, then come to rest ────────────────── */
|
|
42
81
|
|
|
@@ -147,12 +186,113 @@
|
|
|
147
186
|
return function off() { input.removeEventListener("input", check); };
|
|
148
187
|
}
|
|
149
188
|
|
|
150
|
-
/*
|
|
151
|
-
function
|
|
152
|
-
|
|
189
|
+
/* prefers-reduced-motion probe — safe in Node (no matchMedia → false). */
|
|
190
|
+
function prefersReducedMotion() {
|
|
191
|
+
return typeof window !== "undefined" && window.matchMedia
|
|
192
|
+
? window.matchMedia("(prefers-reduced-motion: reduce)").matches : false;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* PURE — parse a CSS <time> value ("800ms" | "1.5s") into ms. NaN if
|
|
196
|
+
unparseable (caller supplies a fallback). Unit-tested. */
|
|
197
|
+
function parseMs(v) {
|
|
198
|
+
if (v == null) return NaN;
|
|
199
|
+
var s = String(v).trim();
|
|
200
|
+
var n = parseFloat(s);
|
|
201
|
+
if (isNaN(n)) return NaN;
|
|
202
|
+
if (/ms$/i.test(s)) return n;
|
|
203
|
+
return /s$/i.test(s) ? n * 1000 : n;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/* PURE — dissolve phase timeline in ms. reducedMotion collapses to instant.
|
|
207
|
+
opts = { hold?, fade? }. Unit-tested. */
|
|
208
|
+
function dissolveTimeline(opts, reducedMotion) {
|
|
209
|
+
opts = opts || {};
|
|
210
|
+
if (reducedMotion) return { hold: 0, fade: 0, total: 0 };
|
|
211
|
+
var hold = opts.hold != null ? opts.hold : 800;
|
|
212
|
+
var fade = opts.fade != null ? opts.fade : 2000;
|
|
213
|
+
return { hold: hold, fade: fade, total: hold + fade };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/* Graceful exit: hold (flowing) → opacity fade-out → clear. Reduced-motion
|
|
217
|
+
collapses to an instant clear. opts = { hold?, fade? } — an omitted value
|
|
218
|
+
reads the element's LIVE --whimsy-dissolve-hold / -fade (so a CSS-only
|
|
219
|
+
override on an ancestor scope works with no JS opts object), falling
|
|
220
|
+
back to dissolveTimeline's 800/2000 if that doesn't resolve either.
|
|
221
|
+
|
|
222
|
+
An explicit opts.fade pins an INLINE override so the CSS transition-
|
|
223
|
+
duration can never drift from what JS times the clear to. Any in-flight
|
|
224
|
+
chain on `el` is cancelled first (cancelDissolve — drops a stale inline
|
|
225
|
+
override along with the old timers), so a stale override from an
|
|
226
|
+
earlier explicit call can't survive into a later default-fade call and
|
|
227
|
+
let JS clear on 2000ms while CSS is still mid a 5000ms fade — a one-
|
|
228
|
+
frame snap back to solid (the original #85 defect, reintroduced on
|
|
229
|
+
element reuse).
|
|
230
|
+
|
|
231
|
+
Returns a cancel() fn. Cancelling ABORTS the exit — timers stop, the
|
|
232
|
+
dissolving class and inline override drop — but does NOT remove
|
|
233
|
+
"whimsy": the element stays/returns to fully lit, it just stops
|
|
234
|
+
counting down.
|
|
235
|
+
|
|
236
|
+
Reduced-motion is re-checked when the hold elapses, not just at call
|
|
237
|
+
time — the OS preference can flip mid-hold. Flipping to reduce clears
|
|
238
|
+
immediately instead of still waiting out the fade duration invisible
|
|
239
|
+
(opacity:0) but present in the DOM/a11y tree/layout. */
|
|
240
|
+
function dissolve(el, opts) {
|
|
241
|
+
if (!el) return function () {};
|
|
242
|
+
opts = opts || {};
|
|
243
|
+
cancelDissolve(el);
|
|
244
|
+
if (prefersReducedMotion()) { clearEl(el); return function () {}; }
|
|
245
|
+
|
|
246
|
+
var cs = getComputedStyle(el);
|
|
247
|
+
var fadeMs = opts.fade;
|
|
248
|
+
if (fadeMs != null) {
|
|
249
|
+
el.style.setProperty("--whimsy-dissolve-fade", fadeMs + "ms");
|
|
250
|
+
} else {
|
|
251
|
+
var parsedFade = parseMs(cs.getPropertyValue("--whimsy-dissolve-fade"));
|
|
252
|
+
fadeMs = isNaN(parsedFade) ? null : parsedFade;
|
|
253
|
+
}
|
|
254
|
+
var holdMs = opts.hold;
|
|
255
|
+
if (holdMs == null) {
|
|
256
|
+
var parsedHold = parseMs(cs.getPropertyValue("--whimsy-dissolve-hold"));
|
|
257
|
+
holdMs = isNaN(parsedHold) ? null : parsedHold;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
var t = dissolveTimeline({ hold: holdMs, fade: fadeMs }, false);
|
|
261
|
+
var timers = { t1: null, t2: null };
|
|
262
|
+
dissolveTimers.set(el, timers);
|
|
263
|
+
timers.t1 = window.setTimeout(function () {
|
|
264
|
+
// Re-check: the OS preference can flip DURING the hold. If it's now
|
|
265
|
+
// reduce, the CSS media query already kills .whimsy--dissolving's
|
|
266
|
+
// transition (no motion plays either way) — but without this check
|
|
267
|
+
// t2 would still wait the FULL fade before clearing, leaving the
|
|
268
|
+
// element opacity:0 yet present (DOM/a11y tree/layout) for up to
|
|
269
|
+
// --whimsy-dissolve-fade. Clear immediately instead, matching what
|
|
270
|
+
// reduced-motion means everywhere else in this module: instant.
|
|
271
|
+
if (prefersReducedMotion()) { clearEl(el); return; }
|
|
272
|
+
el.classList.add("whimsy--dissolving");
|
|
273
|
+
timers.t2 = window.setTimeout(function () {
|
|
274
|
+
clearEl(el);
|
|
275
|
+
}, t.fade);
|
|
276
|
+
}, t.hold);
|
|
277
|
+
|
|
278
|
+
return function cancel() { cancelDissolve(el); };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/* One-shot whimsy for an operation that just succeeded — dissolves by default.
|
|
282
|
+
celebrate(el, ms) — back-compat: number = fully-lit hold, then a graceful fade.
|
|
283
|
+
celebrate(el, { hold?, fade?, dissolve? }) — dissolve:false = the old hard clear. */
|
|
284
|
+
function celebrate(el, opts) {
|
|
285
|
+
if (!el) return function () {};
|
|
286
|
+
cancelDissolve(el); // starting fresh — any prior chain on this el is done
|
|
153
287
|
igniteEl(el);
|
|
154
|
-
|
|
155
|
-
|
|
288
|
+
if (typeof opts === "number") opts = { hold: opts };
|
|
289
|
+
opts = opts || {};
|
|
290
|
+
var hold = opts.hold != null ? opts.hold : 2600;
|
|
291
|
+
if (opts.dissolve === false) {
|
|
292
|
+
var id = window.setTimeout(function () { clearEl(el); }, hold);
|
|
293
|
+
return function () { window.clearTimeout(id); };
|
|
294
|
+
}
|
|
295
|
+
return dissolve(el, { hold: hold, fade: opts.fade });
|
|
156
296
|
}
|
|
157
297
|
|
|
158
298
|
/* ── Seasonal greeting ── pure spec + DOM application ──────────────────── */
|
|
@@ -181,11 +321,11 @@
|
|
|
181
321
|
}
|
|
182
322
|
// Off-season fallback. The line is the consumer's to set — via the
|
|
183
323
|
// element's inline text or opts.default. Lines that fit the calm glacial
|
|
184
|
-
// drift: "kindness is
|
|
324
|
+
// drift: "kindness is a choice" (default) or "abide no hatred".
|
|
185
325
|
// (Future idea: rotate one per day/month via a modulus on the date; for
|
|
186
326
|
// now it's a deliberately stable per-surface choice, not a slot machine.)
|
|
187
327
|
return { season: "default",
|
|
188
|
-
text: opts.default || "kindness is
|
|
328
|
+
text: opts.default || "kindness is a choice",
|
|
189
329
|
classes: ["whimsy", opts.defaultClass || "whimsy--glacial"] };
|
|
190
330
|
}
|
|
191
331
|
|
|
@@ -238,6 +378,9 @@
|
|
|
238
378
|
observe: observe,
|
|
239
379
|
watch: watch,
|
|
240
380
|
celebrate: celebrate,
|
|
381
|
+
dissolve: dissolve,
|
|
382
|
+
dissolveTimeline: dissolveTimeline,
|
|
383
|
+
parseMs: parseMs,
|
|
241
384
|
greeting: greeting,
|
|
242
385
|
greetingFor: greetingFor,
|
|
243
386
|
run: run,
|