@huaqiu/dsh-hardware-ui 0.7.18 → 0.7.20

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,320 +1,376 @@
1
1
  /**
2
- * First-run setup wizard.
2
+ * First-run toolchain onboarding, riding DSH's `settings.onboarding` seat.
3
3
  *
4
- * Rendered from the root navigation seat so it can appear before any session
5
- * exists. It only guides the user towards a local KiCad/SolidCraft executable:
6
- * everything on it is skippable, and completion is recorded in the host-backed
7
- * product config (`onboardingComplete`) rather than in browser storage.
4
+ * The seat, not the right panel, owns first run: a blank first session mounts
5
+ * exactly one ordered step, and the step draws its own modal surface because the
6
+ * shell paints no chrome. That is also why the step renders **nothing** until the
7
+ * Host has answered — a mounted-but-deciding step must show and block nothing.
8
8
  *
9
- * It is a full-screen modal, so it must never mount on a guess. Both facts it
10
- * depends on arrive asynchronously — the host's synced config (is onboarding
11
- * recorded?) and one local install probe (is KiCad already usable?) — and
12
- * {@link wizardPhase} refuses to decide until they are known. Deciding on the
13
- * initial `loading`/`undefined` values is what made the wizard flash on first
14
- * launch and on every browser refresh: it mounted, then unmounted a frame later
15
- * when the real answer landed.
9
+ * The modal follows `docs/prototype/huaqiu_eda_hardware_toolchain_ux_prototype.html`
10
+ * line for line: header (H badge, "Welcome to HuaQiu EDA Agent" + a "First-Time
11
+ * Setup" pill, close button), the blue callout, one card per tool, and a footer
12
+ * that says where the settings live with `Skip for Now` / `Save & Get Started`.
13
+ *
14
+ * Two hard-won rules are encoded here:
15
+ * - **Never mark `#root` inert.** The slot renders *inside* `#root`, so inerting
16
+ * the root froze the whole application — including this modal — on every
17
+ * launch and every reload. The backdrop alone is enough to own the pointer.
18
+ * - **Never subscribe to a form snapshot that is rebuilt per call.** The Host
19
+ * form returns a fresh object from `getSnapshot()`, so feeding it straight to
20
+ * `useSyncExternalStore` re-rendered forever. {@link useFormValue} keeps a
21
+ * stable local copy instead.
22
+ *
23
+ * Gating (§4.6) is a pure function so the "must not reopen on every start"
24
+ * promise stays testable: deferred and completed both stop the step from
25
+ * returning. Skipping marks `toolchainSetup = 'deferred'`, not `'complete'` — the
26
+ * setup is still missing, so the sidebar dot and Settings keep saying so; it
27
+ * merely stops interrupting.
28
+ *
29
+ * @module @huaqiu/dsh-hardware-ui/client/wizard
16
30
  */
17
- import {
18
- createElement, useEffect, useMemo, useState, useSyncExternalStore,
19
- type CSSProperties, type ReactNode,
20
- } from 'react'
21
- import type { HardwareInstallationConfig, InstallationsInfo } from './model.js'
22
- import type { HardwareProps } from './components.js'
31
+ import { createElement, useEffect, useRef, useState, useSyncExternalStore, type CSSProperties, type ReactNode } from 'react'
32
+ import { HUAQIU_LOGO_SRC } from './brand.js'
23
33
  import { COPY } from './copy.js'
24
- import { messageOf } from './transport.js'
25
- import { buttonStyle, C, dotStyle, INPUT, MUTED, MONO_TEXT, pillStyle, R } from './theme.js'
34
+ import type { ConfigFormLike, HardwareInstallationConfig } from './model.js'
35
+ import { ToolchainCard, TOOLCHAIN_ICONS } from './toolchain-view.js'
36
+ import {
37
+ jobRunning, setupComplete, type ToolchainController, type ToolchainId, type ToolchainSnapshot, type ToolchainStatus,
38
+ } from './toolchain.js'
39
+ import { buttonStyle, C, disabled, MUTED, R } from './theme.js'
26
40
 
27
- const BACKDROP: CSSProperties = {
28
- position: 'fixed', inset: 0, zIndex: 60, display: 'flex', alignItems: 'center', justifyContent: 'center',
29
- padding: 16, background: 'rgba(0,0,0,0.6)', backdropFilter: 'blur(3px)',
30
- }
31
- const PANEL: CSSProperties = {
32
- width: 'min(520px, 100%)', maxHeight: '85vh', overflow: 'auto', borderRadius: R.lg, padding: 16,
33
- display: 'flex', flexDirection: 'column', gap: 12,
34
- color: C.text,
35
- background: C.panel,
36
- border: `1px solid ${C.border}`,
37
- boxShadow: '0 28px 70px rgba(0,0,0,0.55)',
38
- fontSize: 12, lineHeight: 1.5,
39
- }
40
- const TITLE: CSSProperties = { margin: 0, fontSize: 15, fontWeight: 600, letterSpacing: 0.1 }
41
- const LEAD: CSSProperties = { margin: 0, fontSize: 11.5, lineHeight: 1.6, color: C.text2 }
42
- const ROW: CSSProperties = { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }
43
- const SPREAD: CSSProperties = { ...ROW, justifyContent: 'space-between' }
44
- const STEP_LABEL: CSSProperties = { fontSize: 10, color: C.text3 }
45
- const BRAND_MARK: CSSProperties = {
46
- width: 26, height: 26, borderRadius: R.sm, display: 'flex', alignItems: 'center', justifyContent: 'center',
47
- fontSize: 11, fontWeight: 700, color: '#fff', background: C.accent,
48
- boxShadow: '0 4px 14px rgba(225,27,27,0.35)', flex: '0 0 auto',
49
- }
50
- const FIELD_CARD: CSSProperties = {
51
- border: `1px solid ${C.borderSoft}`, borderRadius: R.md, background: C.base, padding: 10,
52
- display: 'flex', flexDirection: 'column', gap: 6,
41
+ /** Step id claimed on `settings.onboarding`; also the launcher's `openOnboarding(id)`. */
42
+ export const TOOLCHAIN_ONBOARDING_STEP = 'hardware-engineering-toolchain'
43
+
44
+ /** Both cards, in prototype order. */
45
+ const TOOLCHAIN_IDS: readonly ToolchainId[] = ['kicad', 'solidcraft']
46
+
47
+ /** What the seat's registrant receives: the shell's own props plus our face. */
48
+ export interface OnboardingProps {
49
+ /** Shell: the step currently selected by the coordinator. */
50
+ readonly stepId?: string
51
+ /** Shell: reopened explicitly from the launcher (not first run). */
52
+ readonly explicit?: boolean
53
+ /** Shell: hand ownership back to the next entry. */
54
+ readonly complete?: () => void
55
+ readonly toolchain?: ToolchainController
56
+ /** The Host-backed config form, used to persist the skip flag. */
57
+ readonly configForm?: () => ConfigFormLike<HardwareInstallationConfig> | undefined
53
58
  }
54
59
 
55
- /** Step titles, in order (also the dot-strip tooltips and the counter label). */
56
- const STEPS = COPY.wizard.steps
60
+ /** How the step resolves for one render. */
61
+ export type OnboardingPhase =
62
+ /** No controller (a Host without the capability) — nothing may paint. */
63
+ | 'no-controller'
64
+ /** The Host has not answered yet: render null, decide nothing. */
65
+ | 'waiting'
66
+ /** Show the modal. */
67
+ | 'open'
68
+ /** Both tools already validate: complete silently, no modal. */
69
+ | 'configured'
70
+ /** Previously completed or skipped: stay away. */
71
+ | 'dismissed'
57
72
 
58
73
  /**
59
- * Dismissal remembered for the life of this client bundle, not one mount.
74
+ * Decide whether the step may mount, without guessing.
60
75
  *
61
- * The navigation seat is remounted by the framework (a conversation switch, a
62
- * slot refresh), so component state alone lets a just-closed wizard come back
63
- * for a frame while the host config write is still in flight. A browser refresh
64
- * reloads the bundle, so the host config stays the only cross-session source of
65
- * truth and this cannot outlive the tab.
76
+ * The regression this guards is the flash: the previous panel-mounted wizard
77
+ * decided on initial `loading`/`undefined` values and appeared before the status
78
+ * was known. Here `waiting` renders null, and only a definite "incomplete"
79
+ * answer yields `open`.
66
80
  */
67
- let dismissedInClient = false
81
+ export function onboardingPhase(input: {
82
+ readonly hasController: boolean
83
+ readonly status?: ToolchainStatus
84
+ readonly loading: boolean
85
+ readonly setup?: string
86
+ }): OnboardingPhase {
87
+ if (!input.hasController) return 'no-controller'
88
+ // `toolchainSetup` is the only record of what the first-run step was told:
89
+ // `complete` and `deferred` both mean "never interrupt again". The old
90
+ // `onboardingComplete` boolean is deliberately not honoured — this product is
91
+ // still in internal test, and one source of truth is worth more than the
92
+ // compatibility. A profile that only carries the legacy flag is treated as
93
+ // unanswered.
94
+ if (input.setup === 'complete' || input.setup === 'deferred') return 'dismissed'
95
+ if (input.status === undefined || input.loading) return 'waiting'
96
+ if (setupComplete(input.status)) return 'configured'
97
+ return 'open'
98
+ }
68
99
 
69
100
  /**
70
- * How the wizard resolves for one render.
101
+ * May the footer's primary button submit?
71
102
  *
72
- * `waiting` and `no-form` render nothing, exactly like `completed`; they exist
73
- * so the reason a modal is absent is testable instead of being implicit in an
74
- * `if` chain.
103
+ * Two gates, both asked for after the first-run walk:
104
+ * - **No run in flight.** While a toolchain is downloading or extracting, the
105
+ * step must not hand itself back: the install owns the profile, and
106
+ * "Get Started" would dismiss the modal out from under the bar it shows.
107
+ * - **Something usable.** At least one tool is already configured, or the text
108
+ * in an input has been verified against the Host (`checks`). A merely
109
+ * non-empty input is not enough: the button used to be pressed with garbage
110
+ * paths and then reported the Host's rejection, which is a worse first run
111
+ * than a disabled button that lights up the moment a path checks out.
75
112
  */
76
- export type WizardPhase =
77
- /** No host config form: there is nowhere to record completion. */
78
- | 'no-form'
79
- /** Config sync or the install probe has not answered yet. */
80
- | 'waiting'
81
- /** The host already recorded completion or a skip. */
82
- | 'completed'
83
- /** KiCad validates now, so first-run setup has nothing left to ask. */
84
- | 'configured'
85
- /** Closed in this browser session. */
86
- | 'dismissed'
87
- /** Render it. */
88
- | 'open'
113
+ export function saveReady(snapshot: ToolchainSnapshot): boolean {
114
+ if (snapshot.saving !== undefined) return false
115
+ if (TOOLCHAIN_IDS.some(id => jobRunning(snapshot.jobs[id]))) return false
116
+ if (TOOLCHAIN_IDS.some(id => snapshot.status?.[id].state === 'configured')) return true
117
+ return TOOLCHAIN_IDS.some(id => snapshot.checks[id]?.state === 'valid')
118
+ }
119
+
120
+ /** Fields of the stored configuration this step reacts to. */function sameConfig(left: HardwareInstallationConfig | undefined, right: HardwareInstallationConfig | undefined): boolean {
121
+ if (left === right) return true
122
+ if (left === undefined || right === undefined) return false
123
+ return left.kicadRoot === right.kicadRoot
124
+ && left.solidcraftRoot === right.solidcraftRoot
125
+ && left.toolchainSetup === right.toolchainSetup
126
+ }
89
127
 
90
128
  /**
91
- * Decide whether the wizard may mount, without guessing.
129
+ * The form's value, read through a *stable* snapshot.
92
130
  *
93
- * Order matters: a completed onboarding needs no probe, so it must not wait on
94
- * one; a `loading` config must not fall through to "not completed", which is the
95
- * flash this function exists to prevent.
131
+ * `form.getSnapshot()` allocates a new object on every call; handing that straight
132
+ * to `useSyncExternalStore` makes React see a changed store on every render and
133
+ * spin. Keeping the last value in local state, and replacing it only when a
134
+ * relevant field actually moved, is what makes this safe.
96
135
  */
97
- export function wizardPhase(input: {
98
- readonly hasForm: boolean
99
- /** `ConfigFormSnapshot.status`; `loading` until the host answered once. */
100
- readonly status?: string
101
- readonly onboardingComplete: boolean
102
- /** KiCad readiness; `undefined` while the probe is still in flight. */
103
- readonly kicadConfigured?: boolean | undefined
104
- readonly dismissed: boolean
105
- }): WizardPhase {
106
- if (!input.hasForm) return 'no-form'
107
- if (input.dismissed) return 'dismissed'
108
- if (input.status === 'loading') return 'waiting'
109
- if (input.onboardingComplete) return 'completed'
110
- if (input.kicadConfigured === undefined) return 'waiting'
111
- return input.kicadConfigured ? 'configured' : 'open'
136
+ function useFormValue(form: ConfigFormLike<HardwareInstallationConfig> | undefined): HardwareInstallationConfig | undefined {
137
+ const [value, setValue] = useState<HardwareInstallationConfig | undefined>(() => form?.getSnapshot().value)
138
+ useEffect(() => {
139
+ if (form === undefined) {
140
+ setValue(undefined)
141
+ return
142
+ }
143
+ const read = (): void => {
144
+ const next = form.getSnapshot().value
145
+ setValue(previous => (sameConfig(previous, next) ? previous : next))
146
+ }
147
+ read()
148
+ return form.subscribe(read)
149
+ }, [form])
150
+ return value
112
151
  }
113
152
 
114
- export function OnboardingWizard(props: HardwareProps): ReactNode {
115
- const { actions, configForm, saveInstallation, installations, useStore } = props
116
- const installed = useStore(state => state.installations)
117
- const form = configForm()
118
- const empty = useMemo<{ value?: HardwareInstallationConfig; status?: string }>(() => ({}), [])
119
- const snapshot = useSyncExternalStore<{ value?: HardwareInstallationConfig; status?: string }>(
120
- form === undefined ? () => () => {} : listener => form.subscribe(listener),
121
- form === undefined ? () => empty : () => form.getSnapshot(),
122
- form === undefined ? () => empty : () => form.getSnapshot(),
123
- )
153
+ const BACKDROP: CSSProperties = {
154
+ position: 'fixed', inset: 0, zIndex: 2000, display: 'flex', alignItems: 'center',
155
+ justifyContent: 'center', padding: 16, background: 'rgba(0,0,0,0.75)', backdropFilter: 'blur(2px)',
156
+ }
124
157
 
125
- const [step, setStep] = useState(0)
126
- const [closed, setClosed] = useState(dismissedInClient)
127
- const [kicadRoot, setKicadRoot] = useState('')
128
- const [solidcraftRoot, setSolidcraftRoot] = useState('')
129
- const [message, setMessage] = useState('')
130
- const [busy, setBusy] = useState(false)
131
- /**
132
- * This seat's own install probe: `undefined` while in flight, `null` when it
133
- * failed (the wizard stays usable, paths can be typed). A result another seat
134
- * already wrote to the store counts too, so a mounted viewer does not make the
135
- * navigation row probe twice before deciding.
136
- */
137
- const [probe, setProbe] = useState<InstallationsInfo | null>()
158
+ const HEADER: CSSProperties = {
159
+ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 16,
160
+ padding: '20px 22px 14px', borderBottom: `1px solid ${C.borderSoft}`,
161
+ background: 'linear-gradient(90deg, #241B1C 0%, #1C1C1E 100%)', borderRadius: `${R.lg}px ${R.lg}px 0 0`,
162
+ }
138
163
 
139
- useEffect(() => {
140
- let live = true
141
- installations()
142
- .then((result) => {
143
- if (!live) return
144
- setProbe(result)
145
- actions.setInstallations(result)
146
- })
147
- .catch(() => { if (live) setProbe(null) })
148
- return () => { live = false }
149
- }, [actions, installations])
164
+ const CALLOUT: CSSProperties = {
165
+ display: 'flex', alignItems: 'flex-start', gap: 10, padding: 12, borderRadius: R.md,
166
+ background: 'rgba(59,130,246,0.10)', border: '1px solid rgba(59,130,246,0.22)',
167
+ color: '#BFDBFE', fontSize: 11, lineHeight: 1.6,
168
+ }
150
169
 
151
- const facts = probe ?? installed
152
- const phase = wizardPhase({
153
- hasForm: form !== undefined,
154
- status: snapshot.status,
155
- onboardingComplete: snapshot.value?.onboardingComplete === true,
156
- kicadConfigured: probe === undefined && installed === undefined
157
- ? undefined
158
- : facts?.kicad?.configured === true,
159
- dismissed: closed,
160
- })
170
+ const FOOTER: CSSProperties = {
171
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12, flexWrap: 'wrap',
172
+ padding: '14px 22px', borderTop: `1px solid ${C.borderSoft}`, background: '#161618',
173
+ borderRadius: `0 0 ${R.lg}px ${R.lg}px`,
174
+ }
161
175
 
162
- useEffect(() => {
163
- if (kicadRoot !== '' || facts?.kicad?.root === undefined) return
164
- setKicadRoot(facts.kicad.root)
165
- }, [facts?.kicad?.root, kicadRoot])
176
+ /** Small line icon, same drawing rules as the cards. */
177
+ function Glyph(props: { readonly path: string; readonly size?: number; readonly color?: string; readonly extra?: string }): ReactNode {
178
+ return createElement(
179
+ 'svg',
180
+ {
181
+ viewBox: '0 0 24 24', width: props.size ?? 14, height: props.size ?? 14, 'aria-hidden': true,
182
+ style: { flex: '0 0 auto', color: props.color ?? 'inherit' },
183
+ },
184
+ createElement('path', {
185
+ d: props.path, fill: 'none', stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round',
186
+ }),
187
+ ...(props.extra === undefined
188
+ ? []
189
+ : [createElement('path', {
190
+ d: props.extra, fill: 'none', stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round',
191
+ })]),
192
+ )
193
+ }
194
+
195
+ /** Stable empty snapshot for the no-controller case (identity must not churn). */
196
+ const EMPTY: ToolchainSnapshot = {
197
+ loading: true, jobs: {}, drafts: { kicad: '', solidcraft: '' }, checks: {}, confirmed: {}, toasts: [],
198
+ }
199
+ const emptySnapshot = (): ToolchainSnapshot => EMPTY
166
200
 
167
- // `form === undefined` is already `no-form`; repeating it here is what lets
168
- // TypeScript narrow it for the handlers below.
169
- if (form === undefined || phase !== 'open') return null
201
+ /**
202
+ * The step itself.
203
+ *
204
+ * `complete()` is the shell's own hand-back; the plugin additionally records
205
+ * `toolchainSetup` so a later launch knows the difference between "configured"
206
+ * and "the user said not now".
207
+ */
208
+ export function ToolchainOnboarding(props: OnboardingProps): ReactNode {
209
+ const controller = props.toolchain
210
+ const form = props.configForm?.()
211
+ const value = useFormValue(form)
212
+ const snapshot = useSyncExternalStore<ToolchainSnapshot>(
213
+ controller === undefined ? (): (() => void) => () => {} : controller.subscribe,
214
+ controller === undefined ? emptySnapshot : controller.getSnapshot,
215
+ controller === undefined ? emptySnapshot : controller.getSnapshot,
216
+ )
217
+ const autoCompleted = useRef(false)
218
+ const phase = onboardingPhase({
219
+ hasController: controller !== undefined,
220
+ ...(snapshot.status === undefined ? {} : { status: snapshot.status }),
221
+ loading: snapshot.loading,
222
+ ...(value?.toolchainSetup === undefined ? {} : { setup: value.toolchainSetup }),
223
+ })
170
224
 
171
- const complete = async (): Promise<void> => {
172
- // Close first: the write is a host round-trip, and the user's click must
173
- // dismiss the modal whether or not the host accepts it.
174
- dismissedInClient = true
175
- setClosed(true)
176
- try {
177
- await form.set('onboardingComplete', true)
178
- } catch {
179
- // A refused host write must not trap the user in the wizard.
225
+ const persist = async (patch: Partial<HardwareInstallationConfig>): Promise<void> => {
226
+ for (const [field, entry] of Object.entries(patch)) {
227
+ await form?.set(field, entry)
180
228
  }
181
229
  }
182
230
 
183
- const finish = async (): Promise<void> => {
184
- setBusy(true)
185
- try {
186
- if (kicadRoot !== '') await saveInstallation('kicad', kicadRoot)
187
- if (solidcraftRoot !== '') await saveInstallation('solidcraft', solidcraftRoot)
188
- } catch (error) {
189
- setMessage(messageOf(error))
190
- setBusy(false)
191
- return
192
- }
193
- // Record completion before the probe refresh: a valid KiCad root makes this
194
- // wizard unmount on the next render, and a write issued after that would
195
- // rely on an unmounted component finishing its async tail.
196
- await complete()
197
- try {
198
- actions.setInstallations(await installations())
199
- } catch {
200
- // The viewer re-probes on its own; nothing here depends on the answer.
201
- }
231
+ // §4.7: both tools configured means the step has nothing left to ask, so it
232
+ // completes itself the moment the Host confirms — the user never sees a
233
+ // redundant "Save & Get Started".
234
+ const complete = props.complete
235
+ useEffect(() => {
236
+ if (phase !== 'configured' || autoCompleted.current) return
237
+ autoCompleted.current = true
238
+ void persist({ toolchainSetup: 'complete' }).then(() => complete?.())
239
+ // eslint-disable-next-line react-hooks/exhaustive-deps
240
+ }, [phase])
241
+
242
+ if (phase !== 'open' || controller === undefined) return null
243
+
244
+ const skip = async (): Promise<void> => {
245
+ await persist({ toolchainSetup: 'deferred' })
246
+ controller.toast('info', COPY.toolchain.toastSkipped)
247
+ props.complete?.()
202
248
  }
203
249
 
204
- const next = async (): Promise<void> => {
205
- if (step < STEPS.length - 1) {
206
- setStep(step + 1)
207
- return
250
+ const save = async (): Promise<void> => {
251
+ // The footer's primary button is this step's only save affordance (the
252
+ // prototype has no per-card validate), so it must persist what is typed:
253
+ // each path is validated and written through the Host first, and a rejected
254
+ // path leaves the modal open with the Host's reason already toasted.
255
+ for (const id of TOOLCHAIN_IDS) {
256
+ const path = (snapshot.drafts[id] ?? '').trim()
257
+ if (path === '') continue
258
+ const outcome = await controller.save(id, path)
259
+ if (!outcome.ok) return
208
260
  }
209
- await finish()
261
+ await persist({ toolchainSetup: 'complete' })
262
+ props.complete?.()
210
263
  }
211
264
 
212
- const stepBody = (): ReactNode => {
213
- if (step === 0) {
214
- return createElement(
265
+ // Ready means "there is something worth saving": a typed path, or a tool that
266
+ // is already configured (so pressing the button simply ends the step). It is
267
+ // *not* "everything is configured" — SolidCraft is optional, and a disabled
268
+ // primary button with no other way to submit was a dead end.
269
+ const ready = saveReady(snapshot)
270
+
271
+ return createElement(
272
+ 'div',
273
+ {
274
+ style: BACKDROP,
275
+ role: 'dialog',
276
+ 'aria-modal': true,
277
+ 'aria-label': COPY.toolchain.onboardingAria,
278
+ 'data-hardware-toolchain-onboarding': true,
279
+ },
280
+ createElement(
281
+ 'div',
282
+ {
283
+ style: {
284
+ display: 'flex', flexDirection: 'column', width: 672, maxWidth: '100%', maxHeight: '92vh',
285
+ background: '#1C1C1E', border: '1px solid rgba(255,255,255,0.15)', borderRadius: R.lg,
286
+ boxShadow: '0 24px 64px rgba(0,0,0,0.5)', overflow: 'hidden',
287
+ },
288
+ },
289
+ // Header: the HuaQiu mark (`assets/huaqiu.svg`, inlined in `brand.ts`), title,
290
+ // First-Time Setup pill, close.
291
+ createElement(
215
292
  'div',
216
- { style: { display: 'flex', flexDirection: 'column', gap: 10 } },
293
+ { style: HEADER },
217
294
  createElement(
218
295
  'div',
219
- { style: { ...ROW, gap: 10 } },
220
- createElement('span', { style: BRAND_MARK }, 'H!'),
296
+ { style: { display: 'flex', alignItems: 'center', gap: 12, minWidth: 0 } },
297
+ createElement('img', {
298
+ src: HUAQIU_LOGO_SRC,
299
+ alt: '',
300
+ 'aria-hidden': true,
301
+ width: 40,
302
+ height: 40,
303
+ // The vendor file draws its own rounded frame; the tile adds no colour of
304
+ // its own so the shipped mark is what the user sees.
305
+ style: { width: 40, height: 40, flex: '0 0 auto', display: 'block' },
306
+ }),
221
307
  createElement(
222
308
  'div',
223
- { style: { display: 'flex', flexDirection: 'column', gap: 1 } },
224
- createElement('h2', { style: TITLE }, COPY.wizard.welcomeTitle),
225
- createElement('span', { style: STEP_LABEL }, COPY.wizard.welcomeKicker),
309
+ { style: { display: 'flex', flexDirection: 'column', gap: 3, minWidth: 0 } },
310
+ createElement(
311
+ 'div',
312
+ { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
313
+ createElement('h2', { style: { margin: 0, fontSize: 15, fontWeight: 600, color: C.text } }, COPY.wizard.title),
314
+ createElement('span', {
315
+ style: {
316
+ fontSize: 10, fontWeight: 500, letterSpacing: '0.06em', textTransform: 'uppercase',
317
+ padding: '2px 8px', borderRadius: 999, color: C.accent,
318
+ background: 'rgba(198,58,62,0.20)', border: `1px solid rgba(198,58,62,0.35)`,
319
+ },
320
+ }, COPY.wizard.badge),
321
+ ),
322
+ createElement('p', { style: { ...MUTED, margin: 0, lineHeight: 1.5 } }, COPY.wizard.lead),
226
323
  ),
227
324
  ),
228
- createElement('p', { style: LEAD }, COPY.wizard.welcomeLead),
229
- createElement('div',
230
- { style: FIELD_CARD },
231
- createElement('span', { style: { fontSize: 11, fontWeight: 600 } }, COPY.wizard.welcomeUsesTitle),
232
- createElement('p', { style: { ...MUTED, color: C.text3 } }, COPY.wizard.welcomeUses),
233
- ),
234
- createElement('p', { style: { ...MUTED, color: C.text3 } }, COPY.wizard.welcomeLocal),
235
- )
236
- }
237
- if (step === 1) {
238
- return createElement(
325
+ createElement('button', {
326
+ type: 'button',
327
+ title: COPY.wizard.skip,
328
+ 'aria-label': COPY.wizard.skip,
329
+ onClick: () => { void skip() },
330
+ style: { ...buttonStyle('quiet', { padding: 6 }), flex: '0 0 auto' },
331
+ }, createElement(Glyph, { path: TOOLCHAIN_ICONS.close, size: 16 })),
332
+ ),
333
+
334
+ // Body: callout + one card per tool.
335
+ createElement(
239
336
  'div',
240
- { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
337
+ { style: { display: 'flex', flexDirection: 'column', gap: 14, padding: 22, overflowY: 'auto' } },
241
338
  createElement(
242
339
  'div',
243
- { style: SPREAD },
244
- createElement('h2', { style: TITLE }, COPY.wizard.kicadTitle),
245
- createElement('span', { style: facts?.kicad?.configured === true ? pillStyle('ok') : pillStyle('muted') },
246
- facts?.kicad?.configured === true ? `v${facts.kicad.version ?? '?'}` : COPY.wizard.kicadOptional),
340
+ { style: CALLOUT },
341
+ createElement(Glyph, {
342
+ path: TOOLCHAIN_ICONS.info, size: 16, color: '#60A5FA', extra: 'M12 3a9 9 0 1018 0 9 9 0 00-18 0z',
343
+ }),
344
+ createElement('div', { style: { minWidth: 0 } }, COPY.wizard.callout),
247
345
  ),
248
- createElement('p', { style: LEAD }, COPY.wizard.kicadLead),
249
- createElement('input', {
250
- style: INPUT, value: kicadRoot, autoFocus: true, spellCheck: false,
251
- placeholder: COPY.wizard.kicadPlaceholder,
252
- onChange: event => setKicadRoot(event.currentTarget.value),
253
- }),
254
- createElement('p', { style: { ...MUTED, color: C.text3 } }, COPY.wizard.kicadSkipHint),
255
- )
256
- }
257
- return createElement(
258
- 'div',
259
- { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
260
- createElement(
261
- 'div',
262
- { style: SPREAD },
263
- createElement('h2', { style: TITLE }, COPY.wizard.solidcraftTitle),
264
- createElement('span', { style: pillStyle('muted') }, COPY.wizard.kicadOptional),
346
+ createElement(ToolchainCard, { tool: 'kicad', controller, snapshot, variant: 'wizard' }),
347
+ createElement(ToolchainCard, { tool: 'solidcraft', controller, snapshot, variant: 'wizard' }),
265
348
  ),
266
- createElement('p', { style: LEAD }, COPY.wizard.solidcraftLead),
267
- createElement('input', {
268
- style: INPUT, value: solidcraftRoot, autoFocus: true, spellCheck: false,
269
- placeholder: COPY.wizard.solidcraftPlaceholder,
270
- onChange: event => setSolidcraftRoot(event.currentTarget.value),
271
- }),
272
- )
273
- }
274
349
 
275
- return createElement(
276
- 'div',
277
- { style: BACKDROP, role: 'dialog', 'aria-modal': true, 'aria-label': COPY.wizard.aria, 'data-hardware-wizard': true },
278
- createElement(
279
- 'div',
280
- { style: PANEL },
350
+ // Footer: where the settings live, then Skip / Save & Get Started.
281
351
  createElement(
282
352
  'div',
283
- { style: SPREAD },
353
+ { style: FOOTER },
284
354
  createElement(
285
355
  'div',
286
- { style: { ...ROW, gap: 6 } },
287
- ...STEPS.map((label, index) => createElement('span', {
288
- key: label,
289
- style: { ...dotStyle(index === step ? C.accent : index < step ? C.ok : C.text3, 6) },
290
- title: label,
291
- })),
292
- createElement('span', { style: { ...STEP_LABEL, ...MONO_TEXT } }, COPY.wizard.stepCounter(step + 1, STEPS.length, STEPS[step] ?? '')),
356
+ { style: { display: 'flex', alignItems: 'center', gap: 8, ...MUTED, minWidth: 0 } },
357
+ createElement(Glyph, { path: TOOLCHAIN_ICONS.gear, color: C.text3 }),
358
+ createElement('span', { style: { minWidth: 0 } }, COPY.wizard.footer),
293
359
  ),
294
- createElement('button', {
295
- type: 'button', style: buttonStyle('quiet', { fontSize: 10.5 }),
296
- onClick: () => { void complete() },
297
- }, COPY.wizard.skip),
298
- ),
299
- stepBody(),
300
- ...(message === '' ? [] : [createElement('p', { key: 'msg', style: { ...MUTED, color: C.text2 }, role: 'status' }, message)]),
301
- createElement(
302
- 'div',
303
- { style: { ...SPREAD, paddingTop: 6, borderTop: `1px solid ${C.borderSoft}` } },
304
- createElement('span', { style: { ...MUTED, color: C.text3, fontSize: 10 } }, COPY.wizard.footerNote),
305
360
  createElement(
306
- 'span',
307
- { style: ROW },
308
- step > 0
309
- ? createElement('button', {
310
- type: 'button', style: buttonStyle('secondary'),
311
- onClick: () => { setStep(step - 1) },
312
- }, COPY.wizard.back)
313
- : null,
361
+ 'div',
362
+ { style: { display: 'flex', alignItems: 'center', gap: 10, flex: '0 0 auto' } },
363
+ createElement('button', {
364
+ type: 'button',
365
+ style: buttonStyle('quiet'),
366
+ onClick: () => { void skip() },
367
+ }, COPY.wizard.skip),
314
368
  createElement('button', {
315
- type: 'button', style: buttonStyle('primary'), disabled: busy,
316
- onClick: () => { void next() },
317
- }, busy ? COPY.wizard.saving : step === STEPS.length - 1 ? COPY.wizard.finish : COPY.wizard.next),
369
+ type: 'button',
370
+ style: { ...buttonStyle('primary', { padding: '8px 16px', fontSize: 12, fontWeight: 600 }), ...disabled(!ready) },
371
+ disabled: !ready,
372
+ onClick: () => { void save() },
373
+ }, COPY.wizard.save),
318
374
  ),
319
375
  ),
320
376
  ),