@huaqiu/dsh-hardware-ui 0.7.14 → 0.7.16

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.
@@ -8,8 +8,9 @@
8
8
  */
9
9
  import { createElement, useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from 'react'
10
10
  import { isAbortError } from './ecad.js'
11
+ import { COPY } from './copy.js'
11
12
  import {
12
- loadOrderConfig, openOrderUrl, placeOrder, prepareFabrication,
13
+ loadOrderConfig, messageOf, openOrderUrl, placeOrder, prepareFabrication,
13
14
  type FabricationProjection, type OrderConfigInfo, type PlacedOrder,
14
15
  } from './transport.js'
15
16
  import {
@@ -38,18 +39,14 @@ function formatBytes(bytes: number): string {
38
39
  return `${(bytes / (1024 * 1024)).toFixed(2)} MB`
39
40
  }
40
41
 
41
- function describe(error: unknown): string {
42
- return error instanceof Error ? error.message : String(error)
43
- }
44
-
45
42
  function specRows(facts: FabricationProjection['facts']): { label: string; value: string }[] {
46
43
  return [
47
- { label: 'Layers', value: `${String(facts.layers)} Cu` },
48
- { label: 'Outline', value: `${facts.widthMm.toFixed(1)} × ${facts.heightMm.toFixed(1)} mm` },
49
- { label: 'Thickness', value: `${facts.thicknessMm.toFixed(2)} mm` },
50
- { label: 'Min trace', value: facts.minTrackMm === undefined ? 'default' : `${facts.minTrackMm.toFixed(2)} mm` },
51
- { label: 'Min drill', value: facts.minViaDrillMm === undefined ? 'default' : `${facts.minViaDrillMm.toFixed(2)} mm` },
52
- { label: 'Outer Cu', value: `${String(facts.outerOz ?? 1)} oz` },
44
+ { label: COPY.order.layers, value: COPY.order.layersValue(facts.layers) },
45
+ { label: COPY.order.outline, value: `${facts.widthMm.toFixed(1)} × ${facts.heightMm.toFixed(1)} mm` },
46
+ { label: COPY.order.thickness, value: `${facts.thicknessMm.toFixed(2)} mm` },
47
+ { label: COPY.order.minTrace, value: facts.minTrackMm === undefined ? COPY.order.defaultValue : `${facts.minTrackMm.toFixed(2)} mm` },
48
+ { label: COPY.order.minDrill, value: facts.minViaDrillMm === undefined ? COPY.order.defaultValue : `${facts.minViaDrillMm.toFixed(2)} mm` },
49
+ { label: COPY.order.outerCopper, value: COPY.order.copperValue(facts.outerOz ?? 1) },
53
50
  ]
54
51
  }
55
52
 
@@ -126,7 +123,7 @@ function workflowCard(input: {
126
123
  'data-hardware-order-action': input.tag.toLowerCase(),
127
124
  onClick: input.onAction,
128
125
  },
129
- input.busy ? 'Submitting…' : input.action,
126
+ input.busy ? COPY.order.submitting : input.action,
130
127
  ),
131
128
  )
132
129
  }
@@ -154,7 +151,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
154
151
  useEffect(() => {
155
152
  loadOrderConfig()
156
153
  .then((value) => { if (live.current) setConfig(value) })
157
- .catch((error: unknown) => { if (live.current) setMessage(describe(error)) })
154
+ .catch((error: unknown) => { if (live.current) setMessage(messageOf(error)) })
158
155
  }, [])
159
156
 
160
157
  // Preparing the package is local: gerbers, drill files and CSVs come from the
@@ -172,7 +169,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
172
169
  .then((value) => { if (!controller.signal.aborted) setPrepared(value) })
173
170
  .catch((error: unknown) => {
174
171
  if (controller.signal.aborted || isAbortError(error)) return
175
- setMessage(describe(error))
172
+ setMessage(messageOf(error))
176
173
  })
177
174
  .finally(() => { if (!controller.signal.aborted) setPreparing(false) })
178
175
  return () => { controller.abort() }
@@ -197,7 +194,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
197
194
  setConfirming(undefined)
198
195
  setAcknowledged(false)
199
196
  } catch (error) {
200
- setMessage(describe(error))
197
+ setMessage(messageOf(error))
201
198
  } finally {
202
199
  setPlacing(undefined)
203
200
  }
@@ -222,7 +219,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
222
219
  await openOrderUrl(placed.orderUrl)
223
220
  setPlaced({ ...placed, launched: true, status: 'launched' })
224
221
  } catch (error) {
225
- setMessage(describe(error))
222
+ setMessage(messageOf(error))
226
223
  } finally {
227
224
  setReopening(false)
228
225
  }
@@ -242,13 +239,13 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
242
239
  'h3',
243
240
  { style: { margin: 0, fontSize: 13, fontWeight: 600, color: C.text, display: 'flex', alignItems: 'center', gap: 6 } },
244
241
  createElement('span', { style: dotStyle(C.accent) }),
245
- 'Fabrication & assembly',
242
+ COPY.order.title,
246
243
  ),
247
244
  preparing
248
- ? createElement('span', { style: pillStyle('info') }, 'packaging…')
245
+ ? createElement('span', { style: pillStyle('info') }, COPY.order.packaging)
249
246
  : prepared !== undefined
250
- ? createElement('span', { style: pillStyle('ok') }, 'package ready')
251
- : createElement('span', { style: pillStyle(configured ? 'muted' : 'warn') }, configured ? 'not prepared' : 'KiCad missing'),
247
+ ? createElement('span', { style: pillStyle('ok') }, COPY.order.packageReady)
248
+ : createElement('span', { style: pillStyle(configured ? 'muted' : 'warn') }, configured ? COPY.order.packagePending : COPY.viewer.kicadMissing),
252
249
  ),
253
250
  createElement('p', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10.5 } }, boardTitle),
254
251
  )
@@ -257,14 +254,14 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
257
254
  'div',
258
255
  { style: cardStyle() },
259
256
  createElement('div', { style: SPREAD },
260
- createElement('span', { style: SECTION_TITLE }, 'Fabrication package'),
257
+ createElement('span', { style: SECTION_TITLE }, COPY.order.packageCard),
261
258
  prepared === undefined
262
259
  ? null
263
- : createElement('span', { style: pillStyle('muted') }, `${String(prepared.archive.files.length)} files · ${zipSize}`),
260
+ : createElement('span', { style: pillStyle('muted') }, COPY.order.packageFiles(prepared.archive.files.length, zipSize ?? '')),
264
261
  ),
265
262
  prepared === undefined
266
263
  ? createElement('p', { style: MUTED },
267
- preparing ? 'Running kicad-cli pcb export gerbers and drill…' : 'Not prepared yet.')
264
+ preparing ? COPY.order.packageRunning : COPY.order.packageNotPrepared)
268
265
  : createElement(
269
266
  'div',
270
267
  {
@@ -284,47 +281,47 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
284
281
  const pcbCard = workflowCard({
285
282
  tag: 'PCB',
286
283
  tagColor: C.ok,
287
- title: 'Bare board fabrication',
284
+ title: COPY.order.pcbTitle,
288
285
  subtitle: prepared === undefined
289
- ? 'Quotes and orders the selected board through the Huaqiu fabrication service.'
290
- : `${prepared.archive.zipName} · ${String(prepared.archive.files.length)} gerber/drill files · ${zipSize}`,
286
+ ? COPY.order.pcbSubtitle
287
+ : COPY.order.pcbSummary(prepared.archive.zipName, prepared.archive.files.length, zipSize ?? ''),
291
288
  details: specs.length === 0
292
- ? [{ label: 'Board', value: boardTitle }]
289
+ ? [{ label: COPY.order.boardFile, value: boardTitle }]
293
290
  : specs,
294
- action: 'Submit PCB order',
291
+ action: COPY.order.pcbAction,
295
292
  onAction: () => { setAcknowledged(false); setConfirming('pcb') },
296
293
  busy: placing === 'pcb',
297
294
  ...(configured && prepared !== undefined
298
- ? tokenReady ? {} : { blocked: 'Sign in to Huaqiu to place an order — the order page opens under your account.' }
299
- : { blocked: configured ? 'Waiting for the fabrication package.' : 'Configure KiCad to package the board files.' }),
295
+ ? tokenReady ? {} : { blocked: COPY.order.signInToOrder }
296
+ : { blocked: configured ? COPY.order.waitingForPackage : COPY.order.configureToPackage }),
300
297
  })
301
298
 
302
299
  const smtCard = workflowCard({
303
300
  tag: 'PCBA',
304
301
  tagColor: C.info,
305
- title: 'Turnkey assembly',
302
+ title: COPY.order.smtTitle,
306
303
  subtitle: assembly === undefined
307
- ? 'Needs the project root schematic for the BOM and component positions.'
308
- : `${String(assembly.positions)} placements · ${String(assembly.bomLines)} BOM lines · ${formatBytes(assembly.bomBytes + assembly.positionsBytes)}`,
304
+ ? COPY.order.smtSubtitle
305
+ : COPY.order.smtSummary(assembly.positions, assembly.bomLines, formatBytes(assembly.bomBytes + assembly.positionsBytes)),
309
306
  details: [
310
- { label: 'Placements', value: assembly === undefined ? '—' : String(assembly.positions) },
311
- { label: 'BOM lines', value: assembly === undefined ? '—' : String(assembly.bomLines) },
312
- { label: 'Token', value: tokenReady ? 'Huaqiu login' : 'signed out' },
307
+ { label: COPY.order.placements, value: assembly === undefined ? '—' : String(assembly.positions) },
308
+ { label: COPY.order.bomLines, value: assembly === undefined ? '—' : String(assembly.bomLines) },
309
+ { label: COPY.order.credential, value: tokenReady ? COPY.order.signedIn : COPY.order.signedOut },
313
310
  ],
314
- action: 'Submit assembly order',
311
+ action: COPY.order.smtAction,
315
312
  onAction: () => { setAcknowledged(false); setConfirming('smt') },
316
313
  busy: placing === 'smt',
317
314
  ...(assembly === undefined
318
- ? { blocked: 'Select a root schematic so the BOM and positions can be built.' }
315
+ ? { blocked: COPY.order.selectRootSchematic }
319
316
  : tokenReady
320
317
  ? {}
321
- : { blocked: 'Sign in to Huaqiu to order assembly — the page opens under your account.' }),
318
+ : { blocked: COPY.order.signInToOrderSmt }),
322
319
  })
323
320
 
324
321
  const agentHint = createElement(
325
322
  'div',
326
323
  { style: { ...ROW, gap: 4, paddingTop: 2 } },
327
- createElement('span', { style: { fontSize: 10, color: C.text3 } }, 'Agent entry points'),
324
+ createElement('span', { style: { fontSize: 10, color: C.text3 } }, COPY.order.agentEntryPoints),
328
325
  ...['quote_pcb', 'place_pcb_order', 'quote_smt', 'place_smt_order'].map(name => createElement(
329
326
  'span', { key: name, style: { ...pillStyle('muted'), fontSize: 9.5 } }, name,
330
327
  )),
@@ -334,17 +331,23 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
334
331
  'div',
335
332
  { style: cardStyle({ borderColor: 'rgba(52,211,153,0.4)' }), 'data-hardware-order-result': placed.kind },
336
333
  createElement('div', { style: SPREAD },
337
- createElement('span', { style: SECTION_TITLE }, `${placed.kind === 'pcb' ? 'PCB' : 'Assembly'} order created`),
334
+ createElement('span', { style: SECTION_TITLE },
335
+ placed.kind === 'pcb' ? COPY.order.resultTitlePcb : COPY.order.resultTitleSmt),
338
336
  createElement('span', { style: pillStyle(placed.launched ? 'ok' : 'muted') },
339
- placed.launched ? 'opened in browser' : 'ready to open'),
337
+ placed.launched ? COPY.order.resultLaunched : COPY.order.resultReady),
340
338
  ),
341
- createElement('p', { style: MUTED }, placed.message),
339
+ // The host sends its own English sentence in `placed.message`; the visible
340
+ // copy is derived here so the panel speaks one language. The host string is
341
+ // kept on the object for tooling, not rendered.
342
+ createElement('p', { style: MUTED },
343
+ placed.launched
344
+ ? COPY.order.resultLaunchedMessage(placed.kind === 'pcb' ? 'PCB' : '贴片')
345
+ : COPY.order.resultReadyMessage(placed.kind === 'pcb' ? 'PCB' : '贴片')),
342
346
  createElement('a', {
343
347
  style: LINK, href: placed.orderUrl, target: '_blank', rel: 'noreferrer noopener',
344
348
  'data-hardware-order-url': true,
345
349
  }, placed.orderUrl),
346
- createElement('p', { style: { ...MUTED, fontSize: 10 } },
347
- 'Same page KiCad shows in its order webview, opened in your default browser.'),
350
+ createElement('p', { style: { ...MUTED, fontSize: 10 } }, COPY.order.resultNote),
348
351
  createElement('div', { style: ROW },
349
352
  createElement('button', {
350
353
  type: 'button',
@@ -352,9 +355,9 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
352
355
  disabled: reopening,
353
356
  'data-hardware-order-reopen': true,
354
357
  onClick: () => { void reopen() },
355
- }, reopening ? 'Opening…' : 'Open in browser'),
358
+ }, reopening ? COPY.order.opening : COPY.order.openInBrowser),
356
359
  createElement('button', { type: 'button', style: buttonStyle('secondary'), onClick: () => { void copy() } },
357
- copied ? 'Copied' : 'Copy URL'),
360
+ copied ? COPY.order.copied : COPY.order.copyUrl),
358
361
  createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10 } },
359
362
  `${placed.archive.zipName} · ${formatBytes(placed.archive.zipBytes)}`),
360
363
  ),
@@ -362,7 +365,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
362
365
 
363
366
  const dialog = confirming === undefined ? null : createElement(
364
367
  'div',
365
- { style: DIALOG_BACKDROP, role: 'dialog', 'aria-modal': true, 'aria-label': 'Confirm order upload', 'data-hardware-order-confirm': confirming },
368
+ { style: DIALOG_BACKDROP, role: 'dialog', 'aria-modal': true, 'aria-label': COPY.order.confirmAria, 'data-hardware-order-confirm': confirming },
366
369
  createElement(
367
370
  'div',
368
371
  { style: DIALOG },
@@ -370,21 +373,20 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
370
373
  'div',
371
374
  { style: { display: 'flex', flexDirection: 'column', gap: 3 } },
372
375
  createElement('h4', { style: { margin: 0, fontSize: 13, fontWeight: 600 } },
373
- confirming === 'pcb' ? 'Upload board files and create the PCB order?' : 'Upload the assembly package?'),
374
- createElement('p', { style: MUTED },
375
- 'This sends the files below to the Huaqiu order service. The order is created there and its page opens in your default browser; payment still happens on that page.'),
376
+ confirming === 'pcb' ? COPY.order.confirmTitlePcb : COPY.order.confirmTitleSmt),
377
+ createElement('p', { style: MUTED }, COPY.order.confirmBody),
376
378
  ),
377
379
  createElement(
378
380
  'ul',
379
381
  { style: { margin: 0, paddingLeft: 16, fontSize: 11, color: C.text2, lineHeight: 1.7 } },
380
- createElement('li', null, `${prepared?.archive.zipName ?? 'board.zip'} — gerbers and drill files (${zipSize ?? '—'})`),
382
+ createElement('li', null, COPY.order.confirmZip(prepared?.archive.zipName ?? 'board.zip', zipSize ?? '—')),
381
383
  ...(confirming === 'smt'
382
384
  ? [
383
- createElement('li', { key: 'pos' }, `Component positions (${assembly === undefined ? '—' : formatBytes(assembly.positionsBytes)})`),
384
- createElement('li', { key: 'bom' }, `Assembly BOM (${assembly === undefined ? '—' : formatBytes(assembly.bomBytes)})`),
385
+ createElement('li', { key: 'pos' }, COPY.order.confirmPositions(assembly === undefined ? '—' : formatBytes(assembly.positionsBytes))),
386
+ createElement('li', { key: 'bom' }, COPY.order.confirmBom(assembly === undefined ? '—' : formatBytes(assembly.bomBytes))),
385
387
  ]
386
388
  : []),
387
- createElement('li', { key: 'host' }, createElement('span', { style: MONO_TEXT }, config?.baseUrl ?? 'the configured order service')),
389
+ createElement('li', { key: 'host' }, createElement('span', { style: MONO_TEXT }, COPY.order.confirmHost(config?.baseUrl))),
388
390
  ),
389
391
  createElement(
390
392
  'label',
@@ -395,7 +397,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
395
397
  onChange: (event: { currentTarget: HTMLInputElement }) => { setAcknowledged(event.currentTarget.checked) },
396
398
  'data-hardware-order-ack': true,
397
399
  }),
398
- 'I understand these board files leave this machine.',
400
+ COPY.order.confirmAck,
399
401
  ),
400
402
  createElement(
401
403
  'div',
@@ -403,14 +405,14 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
403
405
  createElement('button', {
404
406
  type: 'button', style: buttonStyle('quiet'),
405
407
  onClick: () => { setConfirming(undefined); setAcknowledged(false) },
406
- }, 'Cancel'),
408
+ }, COPY.order.cancel),
407
409
  createElement('button', {
408
410
  type: 'button',
409
411
  style: { ...buttonStyle('primary'), ...disabled(!acknowledged || placing !== undefined) },
410
412
  disabled: !acknowledged || placing !== undefined,
411
413
  'data-hardware-order-confirm-submit': true,
412
414
  onClick: () => { void submit(confirming) },
413
- }, placing === undefined ? 'Upload and open order page' : 'Uploading…'),
415
+ }, placing === undefined ? COPY.order.uploadAndOpen : COPY.order.uploading),
414
416
  ),
415
417
  ),
416
418
  )
@@ -431,7 +433,7 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
431
433
  createElement(
432
434
  'div',
433
435
  { style: { ...SPREAD, ...cardStyle({ flexDirection: 'row', alignItems: 'center' }) } },
434
- createElement('span', { style: { fontSize: 11, color: C.text2 } }, 'Production batch'),
436
+ createElement('span', { style: { fontSize: 11, color: C.text2 } }, COPY.order.batch),
435
437
  createElement(
436
438
  'select',
437
439
  {
@@ -439,9 +441,9 @@ export function OrderPanel(props: OrderPanelProps): ReactNode {
439
441
  'data-hardware-order-quantity': true,
440
442
  onChange: (event: { currentTarget: HTMLSelectElement }) => { setQuantity(Number(event.currentTarget.value)) },
441
443
  },
442
- ...QUANTITIES.map(count => createElement('option', { key: count, value: count }, `${String(count)} units`)),
444
+ ...QUANTITIES.map(count => createElement('option', { key: count, value: count }, COPY.order.batchUnits(count))),
443
445
  ),
444
- createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10 } }, `quote basis · ${String(quantity)} pcs`),
446
+ createElement('span', { style: { ...MUTED, ...MONO_TEXT, fontSize: 10 } }, COPY.order.quoteBasis(quantity)),
445
447
  ),
446
448
  packageCard,
447
449
  resultCard,
@@ -9,8 +9,9 @@
9
9
  import { createElement, useEffect, useRef, useState, type CSSProperties, type ReactNode } from 'react'
10
10
  import { isAbortError, mountEcad } from './ecad.js'
11
11
  import { mountGlb } from './glb.js'
12
- import { loadBom, prepareBoardGlb, type BomProjection } from './transport.js'
12
+ import { loadBom, messageOf, prepareBoardGlb, type BomProjection } from './transport.js'
13
13
  import { OrderPanel } from './order.js'
14
+ import { COPY } from './copy.js'
14
15
  import {
15
16
  C, cardStyle, dotStyle, MONO, MONO_TEXT, pillStyle, R, SECTION_TITLE,
16
17
  } from './theme.js'
@@ -32,6 +33,9 @@ const TOP_RIGHT: CSSProperties = {
32
33
  }
33
34
  const CENTER: CSSProperties = {
34
35
  display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
36
+ // `flex` as well as `height`: the BOM stage wraps this in a row box, and a
37
+ // height-only child there shrank to its text instead of filling the stage.
38
+ flex: '1 1 auto', width: '100%', boxSizing: 'border-box',
35
39
  height: '100%', gap: 6, padding: 20, textAlign: 'center',
36
40
  }
37
41
  const CENTER_TEXT: CSSProperties = { margin: 0, fontSize: 11, color: C.text3, maxWidth: 340, lineHeight: 1.6 }
@@ -51,16 +55,28 @@ const SCRIPT: CSSProperties = {
51
55
 
52
56
  type Status = 'loading' | 'ready' | 'error'
53
57
 
54
- function describe(error: unknown): string {
55
- return error instanceof Error ? error.message : String(error)
56
- }
57
-
58
58
  function shortRevision(revision: string | undefined): string {
59
59
  return revision === undefined ? '' : revision.slice(0, 10)
60
60
  }
61
61
 
62
- function statusLine(status: Status, message?: string, hint?: string): ReactNode {
63
- const text = message ?? (status === 'loading' ? 'Loading saved artifact…' : '')
62
+ /**
63
+ * The stage's placeholder: what is missing, why, and what to do about it.
64
+ *
65
+ * Every variant is one centred column, so an empty schematic, an empty BOM and a
66
+ * failed export sit in the same place. A placeholder never stops at "not
67
+ * available": the last line always says how the artifact can exist — normally by
68
+ * asking the agent to create it.
69
+ */
70
+ function statusLine(status: Status, input: {
71
+ /** What the stage is missing, in the user's words ("暂无原理图"). */
72
+ readonly title: string
73
+ readonly message?: string
74
+ /** The technical next step, when there is one (configure KiCad, saved-file preview only). */
75
+ readonly hint?: string
76
+ /** How to obtain the artifact. Omitted when the blocker is a setting, not a missing file. */
77
+ readonly guidance?: string
78
+ }): ReactNode {
79
+ const text = input.message ?? (status === 'loading' ? COPY.preview.loading : '')
64
80
  return createElement(
65
81
  'div',
66
82
  { style: CENTER, role: 'status', 'data-hardware-stage': status },
@@ -71,9 +87,16 @@ function statusLine(status: Status, message?: string, hint?: string): ReactNode
71
87
  borderTopColor: C.info, animation: 'dsh-hw-spin 900ms linear infinite',
72
88
  },
73
89
  })
74
- : createElement('span', { style: { ...pillStyle('warn'), fontFamily: MONO } }, 'unavailable'),
75
- createElement('p', { style: CENTER_TEXT }, text),
76
- hint === undefined ? null : createElement('p', { style: { ...CENTER_TEXT, fontSize: 10, color: C.text3 } }, hint),
90
+ : createElement('span', { style: { ...pillStyle('warn'), fontFamily: MONO } }, input.title),
91
+ text === '' ? null : createElement('p', { style: CENTER_TEXT }, text),
92
+ input.hint === undefined
93
+ ? null
94
+ : createElement('p', { style: { ...CENTER_TEXT, fontSize: 10 } }, input.hint),
95
+ input.guidance === undefined
96
+ ? null
97
+ : createElement('p', {
98
+ style: { ...CENTER_TEXT, fontSize: 10.5, color: C.text2 }, 'data-hardware-guidance': true,
99
+ }, input.guidance),
77
100
  )
78
101
  }
79
102
 
@@ -133,7 +156,7 @@ function EcadStage({ kind, path, revision, session, cwd }: {
133
156
  .catch((error: unknown) => {
134
157
  if (!live || isAbortError(error)) return
135
158
  setStatus('error')
136
- setMessage(describe(error))
159
+ setMessage(messageOf(error))
137
160
  })
138
161
  return () => {
139
162
  live = false
@@ -150,15 +173,15 @@ function EcadStage({ kind, path, revision, session, cwd }: {
150
173
  attrs: { 'data-hardware-ecad': kind },
151
174
  topRight: status === 'ready'
152
175
  ? [
153
- createElement('span', { key: 'kind', style: { ...pillStyle('muted'), fontSize: 9.5 } }, kind === 'schematic' ? 'sheet' : 'board'),
176
+ createElement('span', { key: 'kind', style: { ...pillStyle('muted'), fontSize: 9.5 } }, kind === 'schematic' ? COPY.preview.kindSchematic : COPY.preview.kindBoard),
154
177
  sourceRevision === undefined
155
178
  ? null
156
- : createElement('span', { key: 'rev', style: { ...pillStyle('muted'), fontSize: 9.5 } }, `rev ${shortRevision(sourceRevision)}`),
179
+ : createElement('span', { key: 'rev', style: { ...pillStyle('muted'), fontSize: 9.5 } }, COPY.preview.revision(shortRevision(sourceRevision))),
157
180
  ]
158
181
  : undefined,
159
182
  overlay: status === 'ready'
160
183
  ? [createElement('span', { key: 'dot', style: dotStyle(kind === 'schematic' ? C.info : C.ok, 6) }),
161
- 'saved file · scroll to zoom, drag to pan']
184
+ COPY.preview.ecadOverlay]
162
185
  : undefined,
163
186
  },
164
187
  createElement(
@@ -166,7 +189,13 @@ function EcadStage({ kind, path, revision, session, cwd }: {
166
189
  { style: { position: 'relative', flex: '1 1 0', minHeight: 160 } },
167
190
  ...(status === 'ready'
168
191
  ? []
169
- : [statusLine(status, message, status === 'error' ? 'Saved-file preview only; the file must exist and parse.' : undefined)]),
192
+ : [statusLine(status, {
193
+ title: COPY.placeholder.title[kind],
194
+ ...(message === undefined ? {} : { message }),
195
+ ...(status === 'error'
196
+ ? { hint: COPY.preview.ecadHint, guidance: COPY.placeholder.guide[kind] }
197
+ : {}),
198
+ })]),
170
199
  createElement('div', { key: 'canvas', ref: container, style: { position: 'absolute', inset: 0 } }),
171
200
  ),
172
201
  )
@@ -190,21 +219,21 @@ function GlbStage({ boardPath, cwd, session, configured }: {
190
219
  if (element === null) return
191
220
  if (!configured) {
192
221
  setStatus('error')
193
- setMessage('KiCad is not configured.')
222
+ setMessage(COPY.preview.kicadNotConfigured)
194
223
  return
195
224
  }
196
225
  const controller = new AbortController()
197
226
  let live = true
198
227
  let mounted: { dispose(): void } | undefined
199
228
  setStatus('loading')
200
- setMessage('Exporting the PCB to GLB with kicad-cli…')
229
+ setMessage(COPY.preview.glbExporting)
201
230
  element.replaceChildren()
202
231
  const run = async (): Promise<void> => {
203
232
  const glb = await prepareBoardGlb(boardPath, cwd, controller.signal, session)
204
233
  if (!live) return
205
234
  setRevision(glb.revision)
206
235
  setCached(glb.cached)
207
- setMessage('Loading the 3D model…')
236
+ setMessage(COPY.preview.glbLoading)
208
237
  mounted = await mountGlb(glb.url, element, { signal: controller.signal })
209
238
  if (!live) {
210
239
  mounted.dispose()
@@ -216,7 +245,7 @@ function GlbStage({ boardPath, cwd, session, configured }: {
216
245
  run().catch((error: unknown) => {
217
246
  if (!live || isAbortError(error)) return
218
247
  setStatus('error')
219
- setMessage(describe(error))
248
+ setMessage(messageOf(error))
220
249
  })
221
250
  return () => {
222
251
  live = false
@@ -233,16 +262,24 @@ function GlbStage({ boardPath, cwd, session, configured }: {
233
262
  attrs: { 'data-hardware-glb': true },
234
263
  topRight: status === 'ready'
235
264
  ? [
236
- createElement('span', { key: 'mode', style: pillStyle('muted', { fontSize: 9.5 }) }, cached ? 'cached' : 'generated'),
237
- createElement('span', { key: 'rev', style: pillStyle('muted', { fontSize: 9.5 }) }, `rev ${shortRevision(revision)}`),
265
+ createElement('span', { key: 'mode', style: pillStyle('muted', { fontSize: 9.5 }) }, cached ? COPY.preview.glbCached : COPY.preview.glbGenerated),
266
+ createElement('span', { key: 'rev', style: pillStyle('muted', { fontSize: 9.5 }) }, COPY.preview.revision(shortRevision(revision))),
238
267
  ]
239
268
  : undefined,
240
- overlay: status === 'ready' ? 'drag to orbit · wheel to zoom' : 'kicad-cli pcb export glb',
269
+ overlay: status === 'ready' ? COPY.preview.glbOverlay : 'kicad-cli pcb export glb',
241
270
  },
242
271
  createElement(
243
272
  'div',
244
273
  { style: { position: 'relative', flex: '1 1 0', minHeight: 160 } },
245
- ...(status === 'ready' ? [] : [statusLine(status, message)]),
274
+ ...(status === 'ready'
275
+ ? []
276
+ : [statusLine(status, {
277
+ title: COPY.placeholder.title['3d'],
278
+ ...(message === undefined ? {} : { message }),
279
+ // A missing installation is a setting to fix, not an artifact to
280
+ // create, so the agent guidance would point the wrong way.
281
+ ...(status === 'error' && configured ? { guidance: COPY.placeholder.guide['3d'] } : {}),
282
+ })]),
246
283
  createElement('div', { key: 'canvas', ref: container, style: { position: 'absolute', inset: 0 } }),
247
284
  ),
248
285
  )
@@ -268,7 +305,7 @@ function BomStage({ schematicPath, session, cwd, configured }: {
268
305
  useEffect(() => {
269
306
  if (!configured) {
270
307
  setStatus('error')
271
- setMessage('KiCad is not configured.')
308
+ setMessage(COPY.preview.kicadNotConfigured)
272
309
  return
273
310
  }
274
311
  const controller = new AbortController()
@@ -287,7 +324,7 @@ function BomStage({ schematicPath, session, cwd, configured }: {
287
324
  .catch((error: unknown) => {
288
325
  if (!live || isAbortError(error)) return
289
326
  setStatus('error')
290
- setMessage(describe(error))
327
+ setMessage(messageOf(error))
291
328
  })
292
329
  return () => { live = false; controller.abort() }
293
330
  }, [schematicPath, session, cwd, configured])
@@ -296,13 +333,19 @@ function BomStage({ schematicPath, session, cwd, configured }: {
296
333
  return createElement(
297
334
  Stage,
298
335
  { label: 'bom', attrs: { 'data-hardware-bom': true }, overlay: 'kicad-cli sch export bom' },
299
- createElement('div', { style: { flex: '1 1 0', display: 'flex' } }, statusLine(
300
- status,
301
- message,
302
- status === 'error' && !configured
303
- ? 'BOM rows come from kicad-cli sch export bom. Configure KiCad in Settings → Hardware Engineering.'
304
- : undefined,
305
- )),
336
+ // The wrapper is a row box so the placeholder can claim its full width;
337
+ // without that the BOM placeholder sat at the stage's left edge while
338
+ // every other destination centred.
339
+ createElement(
340
+ 'div',
341
+ { style: { flex: '1 1 0', minWidth: 0, display: 'flex' } },
342
+ statusLine(status, {
343
+ title: COPY.placeholder.title.bom,
344
+ ...(message === undefined ? {} : { message }),
345
+ ...(status === 'error' && !configured ? { hint: COPY.preview.bomHint } : {}),
346
+ ...(status === 'error' && configured ? { guidance: COPY.placeholder.guide.bom } : {}),
347
+ }),
348
+ ),
306
349
  )
307
350
  }
308
351
 
@@ -316,10 +359,10 @@ function BomStage({ schematicPath, session, cwd, configured }: {
316
359
  createElement(
317
360
  'div',
318
361
  { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, padding: '8px 10px', borderBottom: `1px solid ${C.border}` } },
319
- createElement('span', { style: SECTION_TITLE }, `Bill of materials · ${String(bom.rows.length)} lines`),
362
+ createElement('span', { style: SECTION_TITLE }, COPY.preview.bomTitle(bom.rows.length)),
320
363
  createElement('div', { style: { display: 'flex', gap: 4, alignItems: 'center' } },
321
- createElement('span', { style: pillStyle('muted') }, `${String(total)} placements`),
322
- createElement('span', { style: pillStyle('muted') }, `rev ${shortRevision(bom.revision)}`),
364
+ createElement('span', { style: pillStyle('muted') }, COPY.preview.bomPlacements(total)),
365
+ createElement('span', { style: pillStyle('muted') }, COPY.preview.revision(shortRevision(bom.revision))),
323
366
  ),
324
367
  ),
325
368
  createElement(
@@ -329,7 +372,7 @@ function BomStage({ schematicPath, session, cwd, configured }: {
329
372
  'table',
330
373
  { style: TABLE },
331
374
  createElement('thead', {}, createElement('tr', {},
332
- ...['Refs', 'Qty', 'Value', 'Footprint', 'Notes'].map(label =>
375
+ ...COPY.preview.bomColumns.map(label =>
333
376
  createElement('th', { key: label, style: TH }, label)))),
334
377
  createElement('tbody', {},
335
378
  ...bom.rows.map((row, index) => createElement('tr', {
@@ -1,4 +1,5 @@
1
1
  /** Same-origin calls to the `@huaqiu/hardware-artifacts` Host routes. */
2
+ import { describeHostError } from './copy.js'
2
3
  import type {
3
4
  DiscoveryInfo, HardwareProjectInfo, InstallationsInfo, NativeApplication,
4
5
  } from './model.js'
@@ -12,16 +13,37 @@ interface Envelope<T> {
12
13
  readonly [key: string]: unknown
13
14
  }
14
15
 
16
+ /**
17
+ * One failed call → one `Error` whose message is already user-facing zh_CN.
18
+ *
19
+ * The route envelope carries a stable `code`, so the sentence is chosen here
20
+ * instead of at every render site (the panel, the stages and the settings
21
+ * section all show `error.message`). The code stays on the error object for
22
+ * callers that branch on it. Host detail survives inside the message only when
23
+ * {@link describeHostError} judges it technical rather than prose.
24
+ */
15
25
  async function request<T>(path: string, init?: RequestInit): Promise<T> {
16
26
  const response = await fetch(`${PREFIX}${path}`, init)
17
27
  const body = await response.json().catch(() => undefined) as Envelope<T> | undefined
18
28
  if (!response.ok || body?.ok === false) {
29
+ const code = body?.error?.code
19
30
  const detail = body?.error?.message ?? `HTTP ${response.status}`
20
- throw new Error(body?.error?.code === undefined ? detail : `${body.error.code}: ${detail}`)
31
+ const error = new Error(describeHostError(code, detail))
32
+ throw code === undefined ? error : Object.assign(error, { code })
21
33
  }
22
34
  return body as T
23
35
  }
24
36
 
37
+ /**
38
+ * Readable text of a thrown value.
39
+ *
40
+ * `String(new Error('x'))` is `"Error: x"`, which is why every message the UI
41
+ * renders goes through here instead of `String(error)`.
42
+ */
43
+ export function messageOf(error: unknown): string {
44
+ return error instanceof Error ? error.message : String(error)
45
+ }
46
+
25
47
  function query(cwd: string | undefined, project?: string, session?: string): string {
26
48
  const params = new URLSearchParams()
27
49
  if (cwd !== undefined && cwd !== '') params.set('cwd', cwd)