@huaqiu/component-gen-app 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ /**
2
+ * `@huaqiu/component-gen-app` — localized dimension-key labels.
3
+ *
4
+ * Ported from `dsh-tool-symbol-footprint` (parse.ts fieldLabel + i18n.ts
5
+ * FIELD_LABEL_KEY). `humanizeKey()` alone always produced English labels in a
6
+ * Chinese UI, so keys resolve through the copy pack's `field.*` section first
7
+ * and only fall back to `humanizeKey()` for names the agent invented.
8
+ */
9
+ import type { Translate } from '../copy/index.js'
10
+
11
+ /** Humanize a camelCase / snake_case key for display. */
12
+ export function humanizeKey(key: string): string {
13
+ return String(key)
14
+ .replace(/[_-]+/g, ' ')
15
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
16
+ .replace(/^\w/, (c) => c.toUpperCase())
17
+ }
18
+
19
+ /** canonical (lowercased, separators stripped) dimension key → copy key. */
20
+ export const FIELD_LABEL_KEY: Record<string, string> = {
21
+ w: 'field.width',
22
+ width: 'field.width',
23
+ h: 'field.height',
24
+ height: 'field.height',
25
+ l: 'field.length',
26
+ length: 'field.length',
27
+ d: 'field.depth',
28
+ depth: 'field.depth',
29
+ e: 'field.span',
30
+ span: 'field.span',
31
+ bodywidth: 'field.bodyWidth',
32
+ bodylength: 'field.bodyLength',
33
+ bodyheight: 'field.bodyHeight',
34
+ boardwidth: 'field.boardWidth',
35
+ boardheight: 'field.boardHeight',
36
+ overallwidth: 'field.overallWidth',
37
+ overalllength: 'field.overallLength',
38
+ overallheight: 'field.overallHeight',
39
+ pitch: 'field.pitch',
40
+ pitchx: 'field.pitchX',
41
+ pitchy: 'field.pitchY',
42
+ pitchd: 'field.pitch',
43
+ pitche: 'field.pitch',
44
+ leadpitch: 'field.leadPitch',
45
+ padwidth: 'field.padWidth',
46
+ padlength: 'field.padLength',
47
+ padheight: 'field.padHeight',
48
+ leadwidth: 'field.leadWidth',
49
+ leadlength: 'field.leadLength',
50
+ leadspan: 'field.leadSpan',
51
+ pincount: 'field.pinCount',
52
+ pins: 'field.pinCount',
53
+ totalpins: 'field.pinCount',
54
+ n: 'field.pinCount',
55
+ nmax: 'field.pinCount',
56
+ rows: 'field.rows',
57
+ row: 'field.rows',
58
+ columns: 'field.columns',
59
+ column: 'field.columns',
60
+ col: 'field.columns',
61
+ cols: 'field.columns',
62
+ standoff: 'field.standoff',
63
+ }
64
+
65
+ /** Localized label for a dimension key (`w`/`width` → 宽度, …). */
66
+ export function fieldLabel(key: string, t: Translate): string {
67
+ const raw = String(key)
68
+ const bounds = /^(.*?)_(max|min)$/i.exec(raw)
69
+ if (bounds) {
70
+ const base = fieldLabel(bounds[1]!, t)
71
+ return t(bounds[2]!.toLowerCase() === 'max' ? 'field.maxOf' : 'field.minOf', { field: base })
72
+ }
73
+ const canonical = raw.toLowerCase().replace(/[\s_-]+/g, '')
74
+ const copyKey = FIELD_LABEL_KEY[canonical]
75
+ return copyKey ? t(copyKey) : humanizeKey(raw)
76
+ }