oltc-selector 2.2.0 → 2.3.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +49 -45
  3. package/bin/oltc.js +2861 -441
  4. package/package.json +5 -5
package/bin/oltc.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // lib/appVersion.ts
4
- var APP_VERSION = "2.2.0";
4
+ var APP_VERSION = "2.3.0";
5
5
 
6
6
  // lib/decimal.ts
7
7
  var GROUPED = /^\d{1,3}([,,]\d{3})+$/;
@@ -19,6 +19,35 @@ function parseDecimal(raw) {
19
19
 
20
20
  // lib/tapCode.ts
21
21
  var PITCHES = [10, 12, 14, 16, 18];
22
+ function parseTapRange(raw) {
23
+ let s = raw.trim().replace(/\s+/g, "");
24
+ if (!s) return null;
25
+ s = s.replace(/[×✕✖]/g, "x").replace(/%/g, "%").replace(/,/g, ",");
26
+ s = s.replace(/,/g, ".");
27
+ let stepPercent = null;
28
+ const pct = s.match(/x(\d+(?:\.\d+)?)%$/i);
29
+ if (pct && pct.index != null) {
30
+ const p = Number(pct[1]) / 100;
31
+ if (p > 0 && p < 0.2) stepPercent = p;
32
+ s = s.slice(0, pct.index);
33
+ }
34
+ const patterns = [
35
+ /^[±](\d+)[//](\d+)$/,
36
+ /^[±](\d+)-(\d+)$/,
37
+ /^\+(\d+)\/-(\d+)$/,
38
+ /^\+(\d+)-(\d+)$/,
39
+ /^(\d+)[//](\d+)$/
40
+ ];
41
+ for (const re of patterns) {
42
+ const m = s.match(re);
43
+ if (!m) continue;
44
+ const plus = Number(m[1]);
45
+ const minus = Number(m[2]);
46
+ if (!(plus > 0) || !(minus > 0) || plus > 30 || minus > 30) return null;
47
+ return { plus, minus, positions: plus + minus + 1, stepPercent };
48
+ }
49
+ return null;
50
+ }
22
51
  var W_DIAGRAMS = [
23
52
  // mid=1, small pitch ladder
24
53
  { plusMinus: 4, pitch: 10, positions: 9, mid: 1 },
@@ -130,6 +159,23 @@ var PM_STEP_OPTIONS_W = [
130
159
  16,
131
160
  17
132
161
  ];
162
+ var PM_STEP_OPTIONS_G = [
163
+ 8,
164
+ 9,
165
+ 10,
166
+ 11,
167
+ 12,
168
+ 13,
169
+ 14,
170
+ 15,
171
+ 16,
172
+ 17
173
+ ];
174
+ function pmStepOptionsFor(regulation) {
175
+ if (regulation === "coarse_fine") return PM_STEP_OPTIONS_G;
176
+ if (regulation === "reversing") return PM_STEP_OPTIONS_W;
177
+ return [];
178
+ }
133
179
  var PM_TAP_MAP = Object.fromEntries(
134
180
  PM_STEP_OPTIONS_W.map((n) => {
135
181
  const mid = preferredMid(n, "reversing");
@@ -214,12 +260,23 @@ function resolveTapFields(input) {
214
260
  mid: mid2,
215
261
  tapCode: buildTapCode({ pitch: pitch2, positions: positions2, mid: mid2, regulation: reg }),
216
262
  changeOver: "0",
217
- standard: true
263
+ // 2–4 linear positions are not a brochure diagram (r2 ORDERS-9).
264
+ standard: positions2 >= 5
218
265
  };
219
266
  }
220
267
  if (input.plusMinusSteps != null && input.plusMinusSteps > 0) {
221
268
  const n = input.plusMinusSteps;
222
269
  const allowed = midOptionsFor(n, reg);
270
+ if (reg === "coarse_fine" && n === 7 && !allowed.length) {
271
+ return {
272
+ positions: 17,
273
+ pitch: 10,
274
+ mid: 3,
275
+ tapCode: buildTapCode({ pitch: 10, positions: 17, mid: 3, regulation: reg }),
276
+ changeOver: changeOverOf(reg),
277
+ standard: false
278
+ };
279
+ }
223
280
  let mid2;
224
281
  if (input.midPositions === 1 || input.midPositions === 3) {
225
282
  mid2 = allowed.includes(input.midPositions) ? input.midPositions : preferredMid(n, reg);
@@ -238,8 +295,8 @@ function resolveTapFields(input) {
238
295
  standard: row != null && isStandard(positions2, mid2, pitch2)
239
296
  };
240
297
  }
241
- let positions = input.positions ?? 19;
242
- let mid = input.midPositions === 1 || input.midPositions === 3 ? input.midPositions : defaultMid(positions, reg);
298
+ const positions = input.positions ?? 19;
299
+ const mid = input.midPositions === 1 || input.midPositions === 3 ? input.midPositions : defaultMid(positions, reg);
243
300
  const pitch = input.pitch ?? (mid === 1 || mid === 3 ? (() => {
244
301
  const n = plusMinusFromPositions(positions, reg);
245
302
  if (n != null) {
@@ -385,8 +442,10 @@ var SELECTOR_SIZES_BY_UM = {
385
442
  126: ["B", "C", "D", "DE"],
386
443
  145: ["C", "D", "DE"],
387
444
  170: ["B", "C", "D", "DE"],
388
- 252: ["C", "D", "DE"],
389
- 300: ["DE"],
445
+ // 252 B and 300 D: sold (3× 252B, e.g. CM2III-500Y/252B on E-CM2250216;
446
+ // 3xSHZVI-1200/300D on E-SHZV260102). The Um default stays the auto floor.
447
+ 252: ["B", "C", "D", "DE"],
448
+ 300: ["D", "DE"],
390
449
  363: ["DE"]
391
450
  };
392
451
  var SIZE_ORDER = ["B", "C", "D", "DE"];
@@ -399,6 +458,29 @@ var INTERNAL_INSULATION = {
399
458
  DE: { a_li: 550, a_pf: 120, b_li: 550, b_pf: 160 },
400
459
  E: { a_li: 0, a_pf: 0, b_li: 0, b_pf: 0 }
401
460
  };
461
+ var INTERNAL_INSULATION_BY_FAMILY = {
462
+ cm2: { C: { a_li: 350, a_pf: 82, b_li: 350, b_pf: 82 } },
463
+ cm: { C: { a_li: 350, a_pf: 82, b_li: 350, b_pf: 82 } },
464
+ cmd: { D: { a_li: 490, a_pf: 105, b_li: 490, b_pf: 146 } }
465
+ };
466
+ function internalInsulation(seriesId, size) {
467
+ const own = seriesId ? INTERNAL_INSULATION_BY_FAMILY[seriesId]?.[size] : void 0;
468
+ return own ?? INTERNAL_INSULATION[size];
469
+ }
470
+ function atPitch(table, pitch) {
471
+ const pitches = Object.keys(table).map(Number).sort((a, b) => a - b);
472
+ const at = pitches.find((p) => p >= pitch) ?? pitches[pitches.length - 1];
473
+ return at != null ? table[at] : void 0;
474
+ }
475
+ function stepCapacityKva(s, current, pitch, dutyA) {
476
+ const byPitch = s.stepCapacityByPitch?.[current];
477
+ const rated = (byPitch ? atPitch(byPitch, pitch) : void 0) ?? s.stepCapacityByCurrent?.[current] ?? null;
478
+ const reduced = s.stepCapacityReduced ? atPitch(s.stepCapacityReduced, pitch) : void 0;
479
+ if (rated != null && reduced && dutyA != null && dutyA <= reduced.currentA + 0.01) {
480
+ return Math.max(rated, reduced.kva);
481
+ }
482
+ return rated;
483
+ }
402
484
  function iiiTypeAllowsConnection(s, phases, conn) {
403
485
  if (phases !== "III") return true;
404
486
  const allowed = s.iiiConnections ?? s.connections;
@@ -421,7 +503,11 @@ var FAMILY_MIN_RANK = {
421
503
  // only wins on on-tank path
422
504
  cvt: 12,
423
505
  cz: 14,
424
- wsg: 6,
506
+ // 2026-11-04: WDG/WLG are the drum OCTC sold (45 OS rows, none WSG), so
507
+ // they rank before WSG; WSG stays for the D quote QS2607203.
508
+ wsg: 7,
509
+ wdg: 5.9,
510
+ wlg: 5.9,
425
511
  hwdk: 80,
426
512
  wsl: 5,
427
513
  // OCTC-only list (never mixed into CV2→CM2→SHZV)
@@ -644,6 +730,8 @@ var SERIES = [
644
730
  umKv: [72.5, 126, 170, 252],
645
731
  usesSelectorSize: true,
646
732
  maxStepVoltageV: 4e3,
733
+ // TD-CMD Table 1: 3300 V at 400/600 A, 4000 V from 1000 A.
734
+ maxStepVoltageByCurrent: { 400: 3300, 600: 3300 },
647
735
  stepCapacityByCurrent: {
648
736
  400: 1320,
649
737
  600: 1600,
@@ -676,6 +764,8 @@ var SERIES = [
676
764
  },
677
765
  umKv: [40.5, 72.5, 126, 145],
678
766
  usesSelectorSize: false,
767
+ pitches: [10, 12],
768
+ // CV2 Table 1: 10 and 12 contacts
679
769
  maxStepVoltageV: 2e3,
680
770
  stepCapacityByCurrent: {
681
771
  350: 700,
@@ -704,11 +794,18 @@ var SERIES = [
704
794
  },
705
795
  umKv: [40.5, 72.5],
706
796
  usesSelectorSize: false,
797
+ pitches: [10, 12, 14],
798
+ // CV&SV Table 1: 10/12/14
707
799
  maxStepVoltageV: 1500,
708
800
  stepCapacityByCurrent: {
709
801
  350: 525,
710
802
  700: 660
711
803
  },
804
+ // TD-CV&SV (HM0.154.001) Table 1 row 7, by contacts 10 / 12 / 14.
805
+ stepCapacityByPitch: {
806
+ 350: { 10: 525, 12: 420, 14: 350 },
807
+ 700: { 10: 660, 12: 520, 14: 450 }
808
+ },
712
809
  connections: ["Y", "D"],
713
810
  maxPositionsLinear: 14,
714
811
  maxPositionsWithChangeOver: 27,
@@ -731,9 +828,22 @@ var SERIES = [
731
828
  },
732
829
  umKv: [40.5, 72.5],
733
830
  usesSelectorSize: false,
831
+ pitches: [10, 12],
832
+ // CV&SV Table 1: SV has no 14
734
833
  maxStepVoltageV: 1500,
735
834
  stepCapacityByCurrent: {
736
- 500: 525
835
+ 500: 400
836
+ },
837
+ // TD-CV&SV Table 1 gives SV "400~525* / 325~420*" (10 / 12 contacts, no 14).
838
+ // Footnote *: 525 / 420 kVA only with through-current cut to 350 / 300 A.
839
+ // Conservative reading: 400 / 325 kVA at any duty above 350 / 300 A
840
+ // (no interpolation between the two brochure points).
841
+ stepCapacityByPitch: {
842
+ 500: { 10: 400, 12: 325 }
843
+ },
844
+ stepCapacityReduced: {
845
+ 10: { currentA: 350, kva: 525 },
846
+ 12: { currentA: 300, kva: 420 }
737
847
  },
738
848
  connections: ["Y", "D"],
739
849
  maxPositionsLinear: 12,
@@ -764,8 +874,8 @@ var SERIES = [
764
874
  200: 80
765
875
  },
766
876
  connections: ["Y", "D", "any"],
767
- maxPositionsLinear: 10,
768
- maxPositionsWithChangeOver: 10,
877
+ maxPositionsLinear: 9,
878
+ maxPositionsWithChangeOver: 9,
769
879
  defaultMdu: "CMA7",
770
880
  notesEn: "Dry-type CVTIII-160/200 / 12 kV.",
771
881
  notesZh: "\u5E72\u5F0F CVTIII-160/200\uFF0C12 kV\u3002",
@@ -811,7 +921,9 @@ var SERIES = [
811
921
  I: [1500, 2e3, 2500],
812
922
  III: [1500, 2e3, 2500]
813
923
  },
814
- umKv: [35, 40.5, 69],
924
+ // 2026-11-04: Um classes of HWDK Un 35 / 69 kV. The type carries Um
925
+ // (sold HWDKI-1500/40.5-17), not Un.
926
+ umKv: [40.5, 72.5],
815
927
  usesSelectorSize: false,
816
928
  maxStepVoltageV: 6e3,
817
929
  connections: ["Y", "D", "any"],
@@ -868,12 +980,61 @@ var SERIES = [
868
980
  usesSelectorSize: false,
869
981
  maxStepVoltageV: 1e4,
870
982
  connections: ["Y", "D"],
871
- maxPositionsLinear: 12,
872
- maxPositionsWithChangeOver: 12,
983
+ // 2026-11-04: contacts are 4x5 / 6x5 only. 12 let a 6x5 stand for 7–12
984
+ // positions; no WSG string was ever sold.
985
+ maxPositionsLinear: 6,
986
+ maxPositionsWithChangeOver: 6,
873
987
  defaultMdu: "CMA7",
874
988
  notesEn: "Drum OCTC (WG sheet). dutyKind=octc only. Wiring roman follows octcSeries (form default IV). Auto D \u2192 WSGII (Anthony WSG II-800D/40.5-4x5A).",
875
989
  notesZh: "\u9F13\u5F0F\u65E0\u8F7D\uFF08WG \u4EF7\u76EE\u8868\uFF09\u3002\u4EC5 dutyKind=octc\u3002\u63A5\u7EBF\u65B9\u5F0F\u8DDF octcSeries\uFF08\u9875\u9762\u9ED8\u8BA4 IV\uFF09\u3002\u672A\u6307\u5B9A\u65F6 D \u2192 WSGII\u3002",
876
- rank: 6
990
+ rank: 7
991
+ },
992
+ // 2026-11-04: the drum OCTC the maker actually sells. Single-phase, one per
993
+ // phase (3xWDGIV-800/40.5-5x5A). Existence is the sold-row list in
994
+ // lib/listIndex.ts; every sold row is Y or blank, so no D.
995
+ {
996
+ id: "wdg",
997
+ code: "WDG",
998
+ nameEn: "WDG single-phase drum off-circuit tap changer (OCTC)",
999
+ nameZh: "WDG \u5355\u76F8\u9F13\u5F0F\u65E0\u8F7D\u5206\u63A5\u5F00\u5173\uFF08OCTC\uFF09",
1000
+ mounting: ["in_tank"],
1001
+ medium: "oil",
1002
+ structure: "drum",
1003
+ vacuum: false,
1004
+ dutyKind: "octc",
1005
+ currents: { I: [300, 400, 800, 1250] },
1006
+ umKv: [40.5, 72.5],
1007
+ usesSelectorSize: false,
1008
+ maxStepVoltageV: 1e4,
1009
+ connections: ["Y"],
1010
+ maxPositionsLinear: 6,
1011
+ maxPositionsWithChangeOver: 6,
1012
+ defaultMdu: "CMA7",
1013
+ notesEn: "Single-phase drum OCTC, one unit per phase. IV 5x5 up to 5 positions; V 6x5 up to 6 when V is asked.",
1014
+ notesZh: "\u5355\u76F8\u9F13\u5F0F\u65E0\u8F7D\uFF0C\u6BCF\u76F8\u4E00\u53F0\u3002IV 5x5 \u81F3 5 \u6863\uFF1B\u6307\u5B9A V \u65F6 6x5 \u81F3 6 \u6863\u3002",
1015
+ rank: 5.9
1016
+ },
1017
+ {
1018
+ id: "wlg",
1019
+ code: "WLG",
1020
+ nameEn: "WLG single-phase drum off-circuit tap changer (OCTC)",
1021
+ nameZh: "WLG \u5355\u76F8\u9F13\u5F0F\u65E0\u8F7D\u5206\u63A5\u5F00\u5173\uFF08OCTC\uFF09",
1022
+ mounting: ["in_tank"],
1023
+ medium: "oil",
1024
+ structure: "drum",
1025
+ vacuum: false,
1026
+ dutyKind: "octc",
1027
+ currents: { I: [800] },
1028
+ umKv: [40.5],
1029
+ usesSelectorSize: false,
1030
+ maxStepVoltageV: 1e4,
1031
+ connections: ["Y"],
1032
+ maxPositionsLinear: 5,
1033
+ maxPositionsWithChangeOver: 5,
1034
+ defaultMdu: "CMA7",
1035
+ notesEn: "Single-phase drum OCTC, series-parallel VIII 4x2 only (one sale).",
1036
+ notesZh: "\u5355\u76F8\u9F13\u5F0F\u65E0\u8F7D\uFF0C\u53EA\u6709\u4E32\u5E76\u8054 VIII 4x2\uFF08\u4E00\u5355\uFF09\u3002",
1037
+ rank: 5.9
877
1038
  }
878
1039
  ];
879
1040
  function nearestUm(wanted, allowed) {
@@ -892,11 +1053,7 @@ function coveringUms(wanted, allowed) {
892
1053
  function nearestCurrent(wanted, allowed) {
893
1054
  if (!allowed?.length) return null;
894
1055
  const sorted = [...allowed].sort((a, b) => a - b);
895
- const ge = sorted.find((c) => c >= wanted - 0.01);
896
- if (ge != null) return ge;
897
- const max = sorted[sorted.length - 1];
898
- if (wanted <= max * 1.01 + 0.5) return max;
899
- return null;
1056
+ return sorted.find((c) => c >= wanted - 0.01) ?? null;
900
1057
  }
901
1058
  function phaseToken(p) {
902
1059
  return p;
@@ -914,24 +1071,31 @@ function firstAllowedAtOrAbove(min, allowed) {
914
1071
  }
915
1072
  return allowed[allowed.length - 1] ?? "B";
916
1073
  }
917
- function coversAcrossTap(size, needALi, needAPf) {
918
- const ins = INTERNAL_INSULATION[size];
1074
+ function coversAcrossTap(size, needALi, needAPf, seriesId) {
1075
+ const ins = internalInsulation(seriesId, size);
919
1076
  return ins.a_li + 0.5 >= needALi && ins.a_pf + 0.5 >= needAPf;
920
1077
  }
921
- function resolveSelectorSize(um, requested, acrossTapBilKv, acrossTapPfKv) {
1078
+ function resolveSelectorSize(um, requested, acrossTapBilKv, acrossTapPfKv, seriesId, statedFloor = false, minSize) {
922
1079
  const allowed = SELECTOR_SIZES_BY_UM[um] ?? ["B", "C", "D", "DE"];
923
1080
  const needALi = acrossTapBilKv ?? 0;
924
1081
  const needAPf = acrossTapPfKv ?? 0;
925
1082
  const typed = requested && requested !== "auto" ? requested : null;
1083
+ const stated = statedFloor && needALi > 0 && needAPf > 0;
1084
+ const umDefault = defaultSelectorSizeForUm(um);
1085
+ const untyped = minSize && SIZE_ORDER.indexOf(minSize) > SIZE_ORDER.indexOf(umDefault) ? minSize : umDefault;
926
1086
  const floor = firstAllowedAtOrAbove(
927
- typed ?? defaultSelectorSizeForUm(um),
1087
+ typed ?? (stated ? allowed[0] : untyped),
928
1088
  allowed
929
1089
  );
930
1090
  for (let i = SIZE_ORDER.indexOf(floor); i < SIZE_ORDER.length; i++) {
931
1091
  const cand = SIZE_ORDER[i];
932
1092
  if (!allowed.includes(cand)) continue;
933
- if (!coversAcrossTap(cand, needALi, needAPf)) continue;
934
- return typed && cand !== typed ? { size: cand, raisedFrom: typed } : { size: cand };
1093
+ if (!coversAcrossTap(cand, needALi, needAPf, seriesId)) continue;
1094
+ if (typed && cand !== typed) return { size: cand, raisedFrom: typed };
1095
+ if (!typed && SIZE_ORDER.indexOf(cand) < SIZE_ORDER.indexOf(umDefault)) {
1096
+ return { size: cand, loweredFrom: umDefault };
1097
+ }
1098
+ return { size: cand };
935
1099
  }
936
1100
  return { size: null };
937
1101
  }
@@ -952,7 +1116,7 @@ var listIndex_data_default = { source: "QS/a. Base Price List 2025.xlsx (WSL/WDL
952
1116
 
953
1117
  // lib/parseType.ts
954
1118
  function normalizeType(raw) {
955
- let t = raw.replace(/[×*]/g, "x").replace(/[–—-]/g, "-").replace(/,/g, ".").replace(/(/g, "(").replace(/)/g, ")").replace(/\s+/g, "").replace(/(\d)_(\d)/g, "$1x$2").replace(/(III|II|I)(\d)/, "$1-$2").replace(/(WSL|WDL|WSG)(VIII|VII|IV|VI|IX|V)(\d)/i, "$1$2-$3");
1119
+ let t = raw.replace(/[×*]/g, "x").replace(/[–—-]/g, "-").replace(/,/g, ".").replace(/(/g, "(").replace(/)/g, ")").replace(/\s+/g, "").replace(/(\d)_(\d)/g, "$1x$2").replace(/(III|II|I)(\d)/, "$1-$2").replace(/(WSL|WDL|WSG|WDG|WLG)(VIII|VII|IV|VI|IX|V)(\d)/i, "$1$2-$3");
956
1120
  if (!t.includes("/")) {
957
1121
  t = t.replace(/([YD])(\d+(?:\.\d+)?)-/i, "$1/$2-");
958
1122
  }
@@ -962,7 +1126,7 @@ function normalizeType(raw) {
962
1126
  );
963
1127
  return t;
964
1128
  }
965
- var OCTC_TYPE_RE = /^(?:(\d+)x)?(WSL|WDL|WSG)(VIII|VII|III|II|IV|VI|IX|V|I)-(\d+)([YD])?[/-](\d+(?:\.\d+)?)-(\d+)x(\d+)(?:\((\d+)x(\d+)\))?(?:\(([A-E])\)|([A-E]))?$/i;
1129
+ var OCTC_TYPE_RE = /^(?:(\d+)x)?(WSL|WDL|WSG|WDG|WLG)(VIII|VII|III|II|IV|VI|IX|V|I)-(\d+)([YD])?[/-](\d+(?:\.\d+)?)-(\d+)x(\d+)(?:\((\d+)x(\d+)\))?(?:\(([A-E])\)|([A-E]))?$/i;
966
1130
  function parseTypeString(raw) {
967
1131
  const t = normalizeType(raw);
968
1132
  const octc = t.match(OCTC_TYPE_RE);
@@ -1024,10 +1188,27 @@ function octcSig(row) {
1024
1188
  ].join("|");
1025
1189
  }
1026
1190
  var octcIndex = null;
1191
+ var DRUM_SOLD_ROWS = [
1192
+ "WDGIV-300/40.5-5x5A",
1193
+ "WDGIV-400/40.5-5x5A",
1194
+ "WDGIV-800/40.5-5x5A",
1195
+ "WDGIV-300/72.5-5x5B",
1196
+ "WDGIV-400/72.5-5x5A",
1197
+ "WDGIV-800/72.5-5x5A",
1198
+ "WDGIV-1250/72.5-5x5A",
1199
+ "WDGV-800/40.5-6x5B",
1200
+ "WDGV-800/72.5-6x5B",
1201
+ "WLGVIII-800/40.5-4x2A"
1202
+ ];
1203
+ var DRUM_FAMILIES = /* @__PURE__ */ new Set(["WDG", "WLG"]);
1027
1204
  function getOctcIndex() {
1028
1205
  if (octcIndex) return octcIndex;
1029
1206
  const bySig = /* @__PURE__ */ new Map();
1030
- for (const row of file.octc) {
1207
+ const drumRows = DRUM_SOLD_ROWS.flatMap((listKey) => {
1208
+ const p = parseTypeString(listKey);
1209
+ return p ? [{ ...p, listKey }] : [];
1210
+ });
1211
+ for (const row of [...file.octc, ...drumRows]) {
1031
1212
  const k = octcSig(row);
1032
1213
  const bucket = bySig.get(k);
1033
1214
  if (bucket) bucket.push(row);
@@ -1058,14 +1239,23 @@ function listRowExists(model) {
1058
1239
  if (KEYS.has(compact)) return true;
1059
1240
  const parsed = parseTypeString(compact);
1060
1241
  if (!parsed) return false;
1061
- if (parsed.family !== "WSL" && parsed.family !== "WDL") return false;
1242
+ if (parsed.family !== "WSL" && parsed.family !== "WDL" && !DRUM_FAMILIES.has(parsed.family)) {
1243
+ return false;
1244
+ }
1062
1245
  return Boolean(lookupOctcRows(parsed)?.length);
1063
1246
  }
1064
1247
  function resolveOctcListKey(model) {
1065
1248
  const parsed = parseTypeString(model);
1066
1249
  if (!parsed) return null;
1067
1250
  if (parsed.family === "WSG") return model;
1068
- if (parsed.family !== "WSL" && parsed.family !== "WDL") return null;
1251
+ const unit = model.match(/^(\d+)x/i);
1252
+ if (unit) {
1253
+ const one = resolveOctcListKey(model.slice(unit[0].length));
1254
+ return one ? `${unit[1]}x${one}` : null;
1255
+ }
1256
+ if (parsed.family !== "WSL" && parsed.family !== "WDL" && !DRUM_FAMILIES.has(parsed.family)) {
1257
+ return null;
1258
+ }
1069
1259
  const candidates = /* @__PURE__ */ new Set();
1070
1260
  const add = (m) => {
1071
1261
  if (m) candidates.add(m);
@@ -1084,6 +1274,10 @@ function resolveOctcListKey(model) {
1084
1274
  add(stripped.replace(new RegExp(`${sizeNow}$`), sz));
1085
1275
  }
1086
1276
  }
1277
+ if (sizeNow) {
1278
+ add(model.replace(new RegExp(`${sizeNow}$`), ""));
1279
+ add(stripped.replace(new RegExp(`${sizeNow}$`), ""));
1280
+ }
1087
1281
  for (const c of candidates) {
1088
1282
  if (listRowExists(c)) {
1089
1283
  const hits2 = lookupOctcRows(parseTypeString(c) ?? parsed);
@@ -1107,8 +1301,10 @@ function commercialTypeExists(model, series) {
1107
1301
  if (s.dutyKind === "octc") {
1108
1302
  if (s.id === "wsg") {
1109
1303
  const i = s.currents.III?.includes(parsed.currentA) || s.currents.II?.includes(parsed.currentA) || s.currents.I?.includes(parsed.currentA);
1304
+ const roman = ["II", "IV", "V"].includes(parsed.phases);
1305
+ const contact = parsed.tapCode === "4x5" || parsed.tapCode === "6x5";
1110
1306
  return Boolean(
1111
- i && s.umKv.some((u) => Math.abs(u - parsed.umKv) < 0.05)
1307
+ i && roman && contact && s.umKv.some((u) => Math.abs(u - parsed.umKv) < 0.05)
1112
1308
  );
1113
1309
  }
1114
1310
  return listRowExists(model);
@@ -1155,24 +1351,105 @@ function connectionLetterOnPhase(s, phases, connection) {
1155
1351
  return connection;
1156
1352
  }
1157
1353
 
1354
+ // lib/deriveUm.ts
1355
+ var SNAP_UN = [33, 35, 66, 69, 110, 115, 132, 138, 150, 220, 230, 330];
1356
+ var IEC_UM = [
1357
+ 3.6,
1358
+ 7.2,
1359
+ 12,
1360
+ 17.5,
1361
+ 24,
1362
+ 36,
1363
+ 40.5,
1364
+ 52,
1365
+ 72.5,
1366
+ 100,
1367
+ 123,
1368
+ 145,
1369
+ 170,
1370
+ 245,
1371
+ 300,
1372
+ 362,
1373
+ 420,
1374
+ 550,
1375
+ 800
1376
+ ];
1377
+ var CATALOGUE_UM = [12, 17.5, 40.5, 72.5, 126, 145, 170, 252, 300, 363];
1378
+ function nominalSystemKv(ratedKv) {
1379
+ let best = ratedKv;
1380
+ for (const u of [...SNAP_UN, 400, 500]) {
1381
+ const win = u >= 400 ? 0.05 : 0.12;
1382
+ if (u <= ratedKv && (ratedKv - u) / ratedKv <= win) best = u;
1383
+ }
1384
+ return best;
1385
+ }
1386
+ function iecUmFromRatedKv(ratedKv) {
1387
+ if (!(ratedKv > 0)) return NaN;
1388
+ const un = nominalSystemKv(ratedKv);
1389
+ return IEC_UM.find((u) => u >= un * 1.04) ?? NaN;
1390
+ }
1391
+ function catalogueUmFromRatedKv(ratedKv) {
1392
+ const um = iecUmFromRatedKv(ratedKv);
1393
+ if (!Number.isFinite(um)) return NaN;
1394
+ return CATALOGUE_UM.find((c) => c >= um - 1e-9) ?? um;
1395
+ }
1396
+ function maxThroughCurrent(ratedA, minusSteps, stepPercent) {
1397
+ if (!(ratedA > 0)) return NaN;
1398
+ if (!(minusSteps > 0) || !(stepPercent > 0)) return ratedA;
1399
+ const drop = minusSteps * stepPercent;
1400
+ if (drop <= 0) return ratedA;
1401
+ if (drop >= 1) return NaN;
1402
+ return ratedA / (1 - drop);
1403
+ }
1404
+
1158
1405
  // lib/engine.ts
1159
1406
  function normOctcContact(raw) {
1160
- const t = (raw ?? "").replace(/\s+/g, "").toLowerCase();
1161
- const m = t.match(/^(\d+)x(\d+)$/);
1407
+ const t = (raw ?? "").replace(/\s+/g, "").replace(/[×*✕]/g, "x").toLowerCase();
1408
+ const m = t.match(/^(\d+)x(\d+)[a-e]?$/);
1162
1409
  if (!m) return "";
1163
1410
  return `${Number(m[1])}x${Number(m[2])}`;
1164
1411
  }
1412
+ function octcContactPositions(contact) {
1413
+ const c = normOctcContact(contact);
1414
+ if (c === "4x5" || c === "5x5" || c === "4x2" || c === "5x2") return 5;
1415
+ return Number(c.split("x")[0]) || 0;
1416
+ }
1417
+ function octcPositionsAsked(input) {
1418
+ if (input.plusMinusSteps != null && input.plusMinusSteps > 0) return 2 * input.plusMinusSteps + 1;
1419
+ return input.positions;
1420
+ }
1165
1421
  function octcContactCode(input, seriesId) {
1166
1422
  const hinted = normOctcContact(input.octcContact);
1167
- if (hinted) return hinted;
1168
1423
  let pos = input.positions;
1169
1424
  if (input.plusMinusSteps != null && input.plusMinusSteps > 0) {
1170
1425
  pos = 2 * input.plusMinusSteps + 1;
1171
1426
  }
1172
1427
  if (seriesId === "wsg") {
1428
+ if (pos != null && pos > 6) return "";
1429
+ if (hinted === "4x5") return pos == null || pos <= 5 ? hinted : "";
1430
+ if (hinted === "6x5") return hinted;
1431
+ if (hinted) return "";
1173
1432
  if (pos == null || pos <= 5) return "4x5";
1174
1433
  return "6x5";
1175
1434
  }
1435
+ if (seriesId === "wdg" || seriesId === "wlg") {
1436
+ const roman = input.octcSeries ?? "auto";
1437
+ const hintRoman = roman === "auto" && hinted === "6x5" && seriesId === "wdg";
1438
+ let drum = "";
1439
+ if (seriesId === "wlg") {
1440
+ if ((roman === "VIII" || roman === "auto" && hinted === "4x2") && (pos == null || pos <= 5)) {
1441
+ drum = "4x2";
1442
+ }
1443
+ } else if (roman === "V" || hintRoman) {
1444
+ if (pos == null || pos <= 6) drum = "6x5";
1445
+ } else if (roman === "auto" || roman === "IV") {
1446
+ if (pos == null || pos <= 5) drum = "5x5";
1447
+ }
1448
+ return hinted && hinted !== drum ? "" : drum;
1449
+ }
1450
+ if (hinted && pos != null && octcContactPositions(hinted) < pos) return "";
1451
+ if (hinted) return hinted;
1452
+ if (input.octcSeries === "VIII" && (pos == null || pos <= 5)) return "5x2";
1176
1453
  if (pos == null || pos <= 6) return "6x5";
1177
1454
  if (pos <= 7) return "7x6";
1178
1455
  if (pos <= 8) return "8x7";
@@ -1182,7 +1459,7 @@ function octcContactCode(input, seriesId) {
1182
1459
  if (pos <= 16) return "16x15";
1183
1460
  return "18x17";
1184
1461
  }
1185
- function octcSizeLetter(um, contact, requested) {
1462
+ function octcSizeLetter(um, contact, requested, acrossTapGiven = false) {
1186
1463
  if (requested && requested !== "auto") {
1187
1464
  if (requested === "DE") return "E";
1188
1465
  return requested;
@@ -1190,25 +1467,33 @@ function octcSizeLetter(um, contact, requested) {
1190
1467
  const c = contact.toLowerCase();
1191
1468
  if (c === "18x17" || c === "16x15") return "E";
1192
1469
  if (c === "12x11" || c === "10x9" || c === "12x12") return "D";
1193
- if (um <= 72.5 + 0.1 && ["6x5", "4x5", "5x4", "5x2", "4x3", "3x2", "7x6"].includes(c)) {
1470
+ if (um <= (acrossTapGiven ? 72.5 : 145) + 0.1 && ["6x5", "4x5", "5x4", "5x2", "4x3", "3x2", "7x6"].includes(c)) {
1194
1471
  return "A";
1195
1472
  }
1196
1473
  return "B";
1197
1474
  }
1198
1475
  function octcRoman(connection, contact, series, familyCode) {
1199
1476
  if (series && series !== "auto") return series;
1200
- const c = (contact ?? "").toLowerCase();
1477
+ const c = normOctcContact(contact);
1201
1478
  if (c === "5x2" || c === "12x2") return "VIII";
1202
1479
  if (c === "3x2" || c === "6x2") return "VI";
1203
1480
  if (c === "5x4" || c === "4x3") return "V";
1204
1481
  if (c === "12x12") return "VII";
1482
+ if (familyCode === "WDG" && c === "6x5") return "V";
1483
+ if (familyCode === "WLG" && c === "4x2") return "VIII";
1205
1484
  if (familyCode === "WSG" && connection === "D") return "II";
1206
1485
  return "IV";
1207
1486
  }
1208
1487
  function isOctcSeries(s) {
1209
1488
  return s.dutyKind === "octc";
1210
1489
  }
1211
- function maxStepVoltageForSeries(s, pitch) {
1490
+ var DRUM_SINGLE = /* @__PURE__ */ new Set(["wdg", "wlg"]);
1491
+ function rankUnits(seriesId, unitCount) {
1492
+ return DRUM_SINGLE.has(seriesId) ? 1 : unitCount;
1493
+ }
1494
+ function maxStepVoltageForSeries(s, pitch, current) {
1495
+ const byCurrent = current != null ? s.maxStepVoltageByCurrent?.[current] : void 0;
1496
+ if (byCurrent != null) return byCurrent;
1212
1497
  if (s.id === "cv2" || s.id === "cv" || s.id === "sv") {
1213
1498
  if (pitch <= 10) return s.id === "cv2" ? 2e3 : 1500;
1214
1499
  if (pitch <= 12) return s.id === "cv2" ? 1500 : 1400;
@@ -1216,17 +1501,25 @@ function maxStepVoltageForSeries(s, pitch) {
1216
1501
  }
1217
1502
  return s.maxStepVoltageV;
1218
1503
  }
1504
+ function seriesTap(s, tap, reg) {
1505
+ if (!s.pitches || reg === "linear" || s.pitches.includes(tap.pitch)) return tap;
1506
+ const pitch = s.pitches.find((p) => tap.positions <= 2 * (p - 1) + 1);
1507
+ if (pitch == null) return null;
1508
+ const tapCode = buildTapCode({ pitch, positions: tap.positions, mid: tap.mid, regulation: reg });
1509
+ const guideRow = pitch === 10 && tap.mid === 1 && reg === "reversing" && (tap.positions === 13 || tap.positions === 15 || tap.positions === 17 || tap.positions === 19);
1510
+ return { ...tap, pitch, tapCode, standard: guideRow };
1511
+ }
1219
1512
  function compoundCoversAcrossTap(s, input) {
1220
1513
  if (s.structure !== "compound") return true;
1221
1514
  const needBil = input.acrossTapBilKv ?? 0;
1222
1515
  const needPf = input.acrossTapPfKv ?? 0;
1223
1516
  if (needBil <= 0 && needPf <= 0) return true;
1224
- const aLi = s.id === "cv2" ? 200 : 200;
1225
- const aPf = s.id === "cv2" ? 50 : 50;
1517
+ const aLi = 200;
1518
+ const aPf = 50;
1226
1519
  return aLi + 0.5 >= needBil && aPf + 0.5 >= needPf;
1227
1520
  }
1228
1521
  function formatUmToken(um, size, usesSelectorSize) {
1229
- const umStr = Number.isInteger(um) ? String(um) : String(um);
1522
+ const umStr = String(um);
1230
1523
  if (!usesSelectorSize || !size) return umStr;
1231
1524
  return `${umStr}${size}`;
1232
1525
  }
@@ -1241,7 +1534,8 @@ function buildModelString(series, phases, current, connection, umToken, tapCode,
1241
1534
  octcSeries,
1242
1535
  series.code
1243
1536
  );
1244
- core = `${series.code}${roman}-${current}${yd}/${umToken}-${tapCode}`;
1537
+ const ydToken = DRUM_SINGLE.has(series.id) ? "" : yd;
1538
+ core = `${series.code}${roman}-${current}${ydToken}/${umToken}-${tapCode}`;
1245
1539
  } else if (series.code === "HWDK") {
1246
1540
  core = `${series.code}${phases}-${current}/${umToken}`;
1247
1541
  if (tapCode && /^\d+$/.test(tapCode)) core += `-${tapCode}`;
@@ -1271,7 +1565,7 @@ function seriesMatchesMedium(s, input) {
1271
1565
  if (input.medium === "oil") return s.medium === "oil" && !s.vacuum;
1272
1566
  return true;
1273
1567
  }
1274
- function adequacyScore(s, input, current, um, unitCount) {
1568
+ function adequacyScore(s, input, current, um, unitCount, pitch) {
1275
1569
  let score = 1e4;
1276
1570
  const fam = FAMILY_MIN_RANK[s.id] ?? s.rank;
1277
1571
  score -= fam * 100;
@@ -1283,6 +1577,14 @@ function adequacyScore(s, input, current, um, unitCount) {
1283
1577
  score += 2500;
1284
1578
  }
1285
1579
  if (input.mounting === "in_tank" && s.id === "hwv") score -= 4e3;
1580
+ if ((s.id === "cv" || s.id === "sv") && input.stepVoltageV > STEP_VOLTAGE_LINE * maxStepVoltageForSeries(s, pitch)) {
1581
+ score -= 3500;
1582
+ }
1583
+ if (input.phases === "I" && s.id === "cv2") score -= 3500;
1584
+ const windUm = input.tapWindingKv ? catalogueUmFromRatedKv(input.tapWindingKv) : 0;
1585
+ if (s.id === "shzv" && (windUm >= 420 || unitCount === 1 && input.phases === "III" && windUm >= 252 && input.throughCurrentA > 430)) {
1586
+ score += 1700;
1587
+ }
1286
1588
  if (unitCount > 1) {
1287
1589
  score -= 8e3;
1288
1590
  score -= current * 0.05;
@@ -1291,7 +1593,7 @@ function adequacyScore(s, input, current, um, unitCount) {
1291
1593
  score -= overshootI * 0.25;
1292
1594
  const overshootUm = um - input.umKv;
1293
1595
  score -= overshootUm * 3;
1294
- const psin = s.stepCapacityByCurrent?.[current];
1596
+ const psin = stepCapacityKva(s, current, pitch, input.throughCurrentA);
1295
1597
  if (psin && input.stepVoltageV > 0) {
1296
1598
  const need = input.throughCurrentA * input.stepVoltageV / 1e3;
1297
1599
  if (need > 0 && psin >= need) {
@@ -1301,17 +1603,31 @@ function adequacyScore(s, input, current, um, unitCount) {
1301
1603
  return score;
1302
1604
  }
1303
1605
  function ratingCoversDuty(wanted, rating) {
1304
- if (wanted <= rating + 0.01) return true;
1305
- return wanted <= rating * 1.01 + 0.5;
1606
+ return wanted <= rating + 0.01;
1306
1607
  }
1307
- function buildAttempts(s, input) {
1608
+ function buildAttempts(s, input, octcWide = false) {
1308
1609
  const out = [];
1309
1610
  const covering = coveringUms(input.umKv, s.umKv).filter(
1310
1611
  (u) => u >= input.umKv - 0.1
1311
1612
  );
1312
1613
  if (!covering.length) return out;
1313
1614
  const um0 = covering[0];
1314
- const ums = !isOctcSeries(s) && (FAMILY_MIN_RANK[s.id] ?? s.rank) < 40 ? covering : [um0];
1615
+ const ums = !isOctcSeries(s) && (FAMILY_MIN_RANK[s.id] ?? s.rank) < 40 ? covering : s.id === "wsl" && (input.preferStructure === "cage" || octcWide) ? covering : [um0];
1616
+ if (DRUM_SINGLE.has(s.id)) {
1617
+ const curI = nearestCurrent(input.throughCurrentA, s.currents.I ?? []);
1618
+ if (curI != null && ratingCoversDuty(input.throughCurrentA, curI)) {
1619
+ for (const um of input.preferStructure === "drum" || octcWide ? covering : [um0]) {
1620
+ out.push({
1621
+ series: s,
1622
+ phases: "I",
1623
+ current: curI,
1624
+ um,
1625
+ unitCount: input.phases === "I" ? 1 : input.phases === "II" ? 2 : 3
1626
+ });
1627
+ }
1628
+ }
1629
+ return out;
1630
+ }
1315
1631
  if (s.id === "cz") {
1316
1632
  const curI = nearestCurrent(input.throughCurrentA, s.currents.I ?? []);
1317
1633
  if (curI != null && ratingCoversDuty(input.throughCurrentA, curI)) {
@@ -1320,7 +1636,8 @@ function buildAttempts(s, input) {
1320
1636
  phases: "I",
1321
1637
  current: curI,
1322
1638
  um: um0,
1323
- unitCount: 3
1639
+ // 2026-11-07: one CZI per phase; a single-phase job was quoted 3×CZI.
1640
+ unitCount: input.phases === "I" ? 1 : input.phases === "II" ? 2 : 3
1324
1641
  });
1325
1642
  }
1326
1643
  return out;
@@ -1347,7 +1664,8 @@ function buildAttempts(s, input) {
1347
1664
  }
1348
1665
  }
1349
1666
  if (isOctcSeries(s)) return out;
1350
- if (s.currents.I?.length && (input.phases === "III" || connIllegal)) {
1667
+ if (s.currents.I?.length && // 2026-11-07: one I-unit per phase; a two-phase (II) delta job was quoted 3×.
1668
+ (input.phases === "III" || connIllegal && input.phases === "II")) {
1351
1669
  const curI = nearestCurrent(input.throughCurrentA, s.currents.I);
1352
1670
  if (curI != null) {
1353
1671
  out.push({
@@ -1355,7 +1673,7 @@ function buildAttempts(s, input) {
1355
1673
  phases: "I",
1356
1674
  current: curI,
1357
1675
  um: um0,
1358
- unitCount: 3,
1676
+ unitCount: input.phases === "II" ? 2 : 3,
1359
1677
  deltaForced: connIllegal
1360
1678
  });
1361
1679
  }
@@ -1390,6 +1708,196 @@ function diversifyResults(ranked) {
1390
1708
  }
1391
1709
  return [primary, ...rest];
1392
1710
  }
1711
+ var LIMIT_AXES = ["um", "current", "positions", "ust", "kva"];
1712
+ function limitScope(input) {
1713
+ if (input.dutyKind === "octc") return { en: "OCTC", zh: "\u65E0\u8F7D" };
1714
+ if (input.mounting === "dry_type") return { en: "dry-type", zh: "\u5E72\u5F0F" };
1715
+ if (input.mounting === "reactor") return { en: "reactor", zh: "\u7535\u6297\u5F0F" };
1716
+ const on = input.mounting === "on_tank" || input.mounting === "external_compartment";
1717
+ const vac = input.preferVacuum || input.medium === "oil_vacuum";
1718
+ const oil = !vac && input.medium === "oil";
1719
+ return {
1720
+ en: `${on ? "on-tank" : "in-tank"}${vac ? " vacuum" : oil ? " oil" : ""}`,
1721
+ zh: `${on ? "\u7BB1\u5916" : "\u7BB1\u5185"}${vac ? "\u771F\u7A7A" : oil ? "\u6CB9\u6D78" : ""}`
1722
+ };
1723
+ }
1724
+ function familyMiss(s, input, tap) {
1725
+ const octc = isOctcSeries(s);
1726
+ const ratings = [];
1727
+ if (s.id === "cz") {
1728
+ const n = input.phases === "I" ? 1 : input.phases === "II" ? 2 : 3;
1729
+ for (const c of s.currents.I ?? []) ratings.push({ current: c, label: `${n > 1 ? `${n}\xD7` : ""}${s.code}I-${c}` });
1730
+ } else if (s.id === "wdg" || s.id === "wlg") {
1731
+ const n = input.phases === "I" ? 1 : input.phases === "II" ? 2 : 3;
1732
+ for (const c of s.currents.I ?? []) {
1733
+ const row = DRUM_SOLD_ROWS.filter((r) => r.startsWith(s.code) && r.includes(`-${c}/`)).pop();
1734
+ const name = row ? row.replace(/-[^-]+$/, "") : `${s.code}-${c}`;
1735
+ ratings.push({ current: c, label: `${n > 1 ? `${n}\xD7` : ""}${name}` });
1736
+ }
1737
+ } else {
1738
+ const legal = phaseConnectionLegal(s, input.phases, input.connection);
1739
+ if (legal) {
1740
+ for (const c of s.currents[input.phases] ?? []) {
1741
+ ratings.push({ current: c, label: `${s.code}${input.phases}-${c}` });
1742
+ }
1743
+ }
1744
+ if (!octc && (input.phases === "III" || !legal)) {
1745
+ for (const c of s.currents.I ?? []) ratings.push({ current: c, label: `3\xD7${s.code}I-${c}` });
1746
+ }
1747
+ }
1748
+ if (!ratings.length) return null;
1749
+ const blocks = [];
1750
+ if (!s.umKv.some((u) => u >= input.umKv - 0.1)) {
1751
+ blocks.push({ axis: "um", need: input.umKv, limit: Math.max(...s.umKv), label: s.code });
1752
+ }
1753
+ const top = ratings.reduce((a, b) => b.current > a.current ? b : a);
1754
+ const covering = ratings.filter((r) => ratingCoversDuty(input.throughCurrentA, r.current));
1755
+ if (!covering.length) {
1756
+ blocks.push({ axis: "current", need: input.throughCurrentA, limit: top.current, label: top.label });
1757
+ }
1758
+ const pool = covering.length ? covering : [top];
1759
+ if (octc) {
1760
+ let pos = input.positions;
1761
+ if (input.plusMinusSteps != null && input.plusMinusSteps > 0) pos = 2 * input.plusMinusSteps + 1;
1762
+ if (pos != null && pos > s.maxPositionsLinear) {
1763
+ blocks.push({ axis: "positions", need: pos, limit: s.maxPositionsLinear, label: s.code });
1764
+ }
1765
+ } else {
1766
+ const maxPos = input.regulation === "linear" ? s.maxPositionsLinear : s.maxPositionsWithChangeOver;
1767
+ if (tap.positions > maxPos) {
1768
+ blocks.push({ axis: "positions", need: tap.positions, limit: maxPos, label: s.code });
1769
+ }
1770
+ if (input.stepVoltageV > 0) {
1771
+ const ust = Math.max(
1772
+ ...pool.map((r) => maxStepVoltageForSeries(s, tap.pitch, r.current))
1773
+ );
1774
+ if (input.stepVoltageV > ust + 0.5) {
1775
+ blocks.push({ axis: "ust", need: input.stepVoltageV, limit: ust, label: s.code });
1776
+ }
1777
+ const caps = pool.map((r) => ({
1778
+ r,
1779
+ kva: stepCapacityKva(s, r.current, tap.pitch, input.throughCurrentA)
1780
+ }));
1781
+ const needKva = input.throughCurrentA * input.stepVoltageV / 1e3;
1782
+ if (caps.every((c) => c.kva != null)) {
1783
+ const best = caps.reduce((a, b) => (b.kva ?? 0) > (a.kva ?? 0) ? b : a);
1784
+ if (needKva > (best.kva ?? 0) + 0.5) {
1785
+ blocks.push({ axis: "kva", need: needKva, limit: best.kva ?? 0, label: best.r.label });
1786
+ }
1787
+ }
1788
+ }
1789
+ }
1790
+ const worst = Math.max(0, ...blocks.map((b) => b.limit > 0 ? b.need / b.limit : Infinity));
1791
+ return { s, blocks, worst };
1792
+ }
1793
+ function fmtNeed(axis, v) {
1794
+ if (axis === "um") return String(v);
1795
+ if (axis === "current" && v < 100) return String(Math.round(v * 10) / 10);
1796
+ return String(Math.round(v));
1797
+ }
1798
+ function everyFamilyLine(b, scope, pitch) {
1799
+ const n = fmtNeed(b.axis, b.need);
1800
+ const max = fmtNeed(b.axis, b.limit);
1801
+ switch (b.axis) {
1802
+ case "um":
1803
+ return {
1804
+ en: `Um ${n} kV is above the highest ${scope.en} class (${max} kV, ${b.label}).`,
1805
+ zh: `Um ${n} kV \u8D85\u51FA${scope.zh}\u6700\u9AD8\u7B49\u7EA7\uFF08${max} kV\uFF0C${b.label}\uFF09\u3002`
1806
+ };
1807
+ case "current":
1808
+ return {
1809
+ en: `Through-current ${n} A is above the largest ${scope.en} rating (${max} A, ${b.label}).`,
1810
+ zh: `\u901A\u8FC7\u7535\u6D41 ${n} A \u8D85\u51FA${scope.zh}\u6700\u5927\u989D\u5B9A\uFF08${max} A\uFF0C${b.label}\uFF09\u3002`
1811
+ };
1812
+ case "positions":
1813
+ return {
1814
+ en: `${n} positions are above every ${scope.en} family (max ${max}, ${b.label}).`,
1815
+ zh: `${n} \u4E2A\u5DE5\u4F5C\u4F4D\u7F6E\u8D85\u51FA${scope.zh}\u6240\u6709\u7CFB\u5217\uFF08\u6700\u591A ${max}\uFF0C${b.label}\uFF09\u3002`
1816
+ };
1817
+ case "ust":
1818
+ return {
1819
+ en: `Step voltage ${n} V is above every ${scope.en} family at pitch ${pitch} (max ${max} V, ${b.label}).`,
1820
+ zh: `\u7EA7\u7535\u538B ${n} V \u8D85\u51FA\u8282\u8DDD ${pitch} \u4E0B${scope.zh}\u6240\u6709\u7CFB\u5217\uFF08\u6700\u9AD8 ${max} V\uFF0C${b.label}\uFF09\u3002`
1821
+ };
1822
+ case "kva":
1823
+ return {
1824
+ en: `Step capacity ${n} kVA is above every ${scope.en} family at pitch ${pitch} (max ${max} kVA, ${b.label}).`,
1825
+ zh: `\u7EA7\u5BB9\u91CF ${n} kVA \u8D85\u51FA\u8282\u8DDD ${pitch} \u4E0B${scope.zh}\u6240\u6709\u7CFB\u5217\uFF08\u6700\u5927 ${max} kVA\uFF0C${b.label}\uFF09\u3002`
1826
+ };
1827
+ }
1828
+ }
1829
+ function familyLine(code2, b, pitch) {
1830
+ const n = fmtNeed(b.axis, b.need);
1831
+ const max = fmtNeed(b.axis, b.limit);
1832
+ switch (b.axis) {
1833
+ case "um":
1834
+ return {
1835
+ en: `${code2}: Um ${n} kV is above its ${max} kV.`,
1836
+ zh: `${code2}\uFF1AUm ${n} kV \u8D85\u51FA\u5176 ${max} kV\u3002`
1837
+ };
1838
+ case "current":
1839
+ return {
1840
+ en: `${code2}: through-current ${n} A is above its ${max} A.`,
1841
+ zh: `${code2}\uFF1A\u901A\u8FC7\u7535\u6D41 ${n} A \u8D85\u51FA\u5176 ${max} A\u3002`
1842
+ };
1843
+ case "positions":
1844
+ return {
1845
+ en: `${code2}: ${n} positions are above its ${max}.`,
1846
+ zh: `${code2}\uFF1A${n} \u4E2A\u5DE5\u4F5C\u4F4D\u7F6E\u8D85\u51FA\u5176 ${max}\u3002`
1847
+ };
1848
+ case "ust":
1849
+ return {
1850
+ en: `${code2}: step voltage ${n} V is above its ${max} V at pitch ${pitch}.`,
1851
+ zh: `${code2}\uFF1A\u7EA7\u7535\u538B ${n} V \u8D85\u51FA\u5176\u8282\u8DDD ${pitch} \u4E0B\u7684 ${max} V\u3002`
1852
+ };
1853
+ case "kva":
1854
+ return {
1855
+ en: `${code2}: step capacity ${n} kVA is above its ${max} kVA at pitch ${pitch}.`,
1856
+ zh: `${code2}\uFF1A\u7EA7\u5BB9\u91CF ${n} kVA \u8D85\u51FA\u5176\u8282\u8DDD ${pitch} \u4E0B\u7684 ${max} kVA\u3002`
1857
+ };
1858
+ }
1859
+ }
1860
+ function noFitReasons(families, input, tap) {
1861
+ const misses = families.map((s) => familyMiss(s, input, tap)).filter((m) => m != null);
1862
+ if (!misses.length || misses.some((m) => !m.blocks.length)) return null;
1863
+ const pitch = tap.pitch;
1864
+ const en = [];
1865
+ const zh = [];
1866
+ const everywhere = LIMIT_AXES.filter(
1867
+ (ax) => misses.every((m) => m.blocks.some((b) => b.axis === ax))
1868
+ ).filter((ax, _, all) => !(ax === "kva" && all.includes("current")));
1869
+ if (everywhere.length) {
1870
+ const scope = limitScope(input);
1871
+ for (const ax of everywhere.slice(0, 2)) {
1872
+ const blocks = misses.map((m) => ({ m, b: m.blocks.find((b) => b.axis === ax) })).sort((x, y) => y.b.limit - x.b.limit || x.m.s.rank - y.m.s.rank);
1873
+ const ceiling = blocks[0].b;
1874
+ const label = ax === "current" || ax === "kva" ? ceiling.label : [...new Set(blocks.filter((x) => x.b.limit === ceiling.limit).map((x) => x.m.s.code))].slice(0, 3).join("/");
1875
+ const line = everyFamilyLine({ ...ceiling, label }, scope, pitch);
1876
+ en.push(line.en);
1877
+ zh.push(line.zh);
1878
+ }
1879
+ return { en, zh };
1880
+ }
1881
+ const ranked = [...misses].sort(
1882
+ (a, b) => a.blocks.length - b.blocks.length || a.worst - b.worst || a.s.rank - b.s.rank
1883
+ );
1884
+ const ratio = (b) => b.limit > 0 ? b.need / b.limit : Infinity;
1885
+ const worstBlock = (m) => m.blocks.reduce((a, b) => ratio(b) > ratio(a) ? b : a);
1886
+ const closest = ranked[0];
1887
+ const bind = worstBlock(closest);
1888
+ const first = familyLine(closest.s.code, bind, pitch);
1889
+ en.push(first.en);
1890
+ zh.push(first.zh);
1891
+ const clears = ranked.find(
1892
+ (m) => m !== closest && !m.blocks.some((b) => b.axis === bind.axis)
1893
+ );
1894
+ if (clears) {
1895
+ const second = familyLine(clears.s.code, worstBlock(clears), pitch);
1896
+ en.push(second.en);
1897
+ zh.push(second.zh);
1898
+ }
1899
+ return { en, zh };
1900
+ }
1393
1901
  function selectOltc(input) {
1394
1902
  const errorsEn = [];
1395
1903
  const errorsZh = [];
@@ -1405,9 +1913,36 @@ function selectOltc(input) {
1405
1913
  errorsEn.push("Step voltage must be a number \u2265 0 (0 = not given).");
1406
1914
  errorsZh.push("\u7EA7\u7535\u538B\u987B\u4E3A \u2265 0 \u7684\u6570\u5B57\uFF080 \u8868\u793A\u672A\u7ED9\uFF09\u3002");
1407
1915
  }
1916
+ if (input.positions != null && !(Number.isInteger(input.positions) && input.positions >= 2)) {
1917
+ errorsEn.push("Positions must be a whole number of at least 2.");
1918
+ errorsZh.push("\u6863\u4F4D\u6570\u987B\u4E3A\u4E0D\u5C0F\u4E8E 2 \u7684\u6574\u6570\u3002");
1919
+ }
1920
+ for (const [name, v] of [
1921
+ ["Across-tap LI", input.acrossTapBilKv],
1922
+ ["Across-tap AC", input.acrossTapPfKv],
1923
+ ["Earth LI", input.bilKv],
1924
+ ["Earth AC", input.pfKv]
1925
+ ]) {
1926
+ if (v != null && !(Number.isFinite(v) && v >= 0)) {
1927
+ errorsEn.push(`${name} must be a number \u2265 0 (kV).`);
1928
+ errorsZh.push(`${name} \u987B\u4E3A \u2265 0 \u7684\u6570\u5B57\uFF08kV\uFF09\u3002`);
1929
+ }
1930
+ }
1931
+ if (input.plusMinusSteps != null && !(Number.isInteger(input.plusMinusSteps) && input.plusMinusSteps >= 1)) {
1932
+ errorsEn.push("\xB1 steps must be a whole number of at least 1.");
1933
+ errorsZh.push("\xB1 \u7EA7\u6570\u987B\u4E3A\u4E0D\u5C0F\u4E8E 1 \u7684\u6574\u6570\u3002");
1934
+ }
1408
1935
  if (errorsEn.length) {
1409
1936
  return { ok: false, results: [], errorsEn, errorsZh };
1410
1937
  }
1938
+ if (input.dutyKind === "octc" || input.mounting === "reactor") {
1939
+ input = {
1940
+ ...input,
1941
+ medium: "oil",
1942
+ preferVacuum: false,
1943
+ ...input.dutyKind === "octc" ? { octcSeries: input.octcSeries ?? "auto" } : {}
1944
+ };
1945
+ }
1411
1946
  if ((input.bilKv ?? 0) > 0 || (input.pfKv ?? 0) > 0) {
1412
1947
  const earthUm = umForEarthInsulation(input.umKv, input.bilKv, input.pfKv);
1413
1948
  if (earthUm == null) {
@@ -1424,7 +1959,7 @@ function selectOltc(input) {
1424
1959
  }
1425
1960
  if (earthUm > input.umKv + 0.01) input = { ...input, umKv: earthUm };
1426
1961
  }
1427
- const tap = resolveTapFields({
1962
+ const baseTap = resolveTapFields({
1428
1963
  regulation: input.regulation,
1429
1964
  positions: input.positions,
1430
1965
  plusMinusSteps: input.plusMinusSteps,
@@ -1440,17 +1975,21 @@ function selectOltc(input) {
1440
1975
  if (input.connection === "any") return true;
1441
1976
  return s.connections.includes(input.connection) || s.connections.includes("any");
1442
1977
  });
1978
+ candidates = candidates.filter(
1979
+ (s) => s.id !== "wsg" || ["auto", "II", "IV", "V"].includes(input.octcSeries ?? "auto")
1980
+ );
1443
1981
  const wantStruct = input.preferStructure;
1444
- if (input.transformerKind === "auto" && !wantOctc) {
1982
+ const autoKind = input.transformerKind === "auto";
1983
+ if ((autoKind || input.combinedOnly) && !wantOctc) {
1445
1984
  if (wantStruct === "compound") {
1446
1985
  return {
1447
1986
  ok: false,
1448
1987
  results: [],
1449
1988
  errorsEn: [
1450
- "Autotransformers take combined types only: compound types (CV/CV2/SV) stop at 200 kV across the tap winding."
1989
+ autoKind ? "Autotransformers take combined types only: compound types (CV/CV2/SV) stop at 200 kV across the tap winding." : "Tapped windings of 220 kV class and above take combined types only: compound types (CV/CV2/SV) stop at 200 kV across the tap winding."
1451
1990
  ],
1452
1991
  errorsZh: [
1453
- "\u81EA\u8026\u53D8\u53EA\u7528\u7EC4\u5408\u5F0F\uFF1A\u590D\u5408\u5F0F\uFF08CV/CV2/SV\uFF09\u8DE8\u8C03\u538B\u7ED5\u7EC4\u51B2\u51FB\u4E0A\u9650 200 kV\u3002"
1992
+ autoKind ? "\u81EA\u8026\u53D8\u53EA\u7528\u7EC4\u5408\u5F0F\uFF1A\u590D\u5408\u5F0F\uFF08CV/CV2/SV\uFF09\u8DE8\u8C03\u538B\u7ED5\u7EC4\u51B2\u51FB\u4E0A\u9650 200 kV\u3002" : "220 kV \u7EA7\u53CA\u4EE5\u4E0A\u8C03\u538B\u7ED5\u7EC4\u53EA\u7528\u7EC4\u5408\u5F0F\uFF1A\u590D\u5408\u5F0F\uFF08CV/CV2/SV\uFF09\u8DE8\u8C03\u538B\u7ED5\u7EC4\u51B2\u51FB\u4E0A\u9650 200 kV\u3002"
1454
1993
  ]
1455
1994
  };
1456
1995
  }
@@ -1474,287 +2013,429 @@ function selectOltc(input) {
1474
2013
  const results = [];
1475
2014
  const seen = /* @__PURE__ */ new Set();
1476
2015
  let acrossTapShort = false;
1477
- for (const s of candidates) {
1478
- if (!compoundCoversAcrossTap(s, input)) {
1479
- acrossTapShort = true;
1480
- continue;
1481
- }
1482
- if (!isOctcSeries(s)) {
1483
- const pitchMaxUst = maxStepVoltageForSeries(s, tap.pitch);
1484
- if (input.stepVoltageV > pitchMaxUst + 0.5) continue;
1485
- const maxPos = input.regulation === "linear" ? s.maxPositionsLinear : s.maxPositionsWithChangeOver;
1486
- if (tap.positions > maxPos) continue;
1487
- } else {
1488
- let octcPos = input.positions;
1489
- if (input.plusMinusSteps != null && input.plusMinusSteps > 0) {
1490
- octcPos = 2 * input.plusMinusSteps + 1;
1491
- }
1492
- if (octcPos != null && octcPos > s.maxPositionsLinear) continue;
1493
- }
1494
- for (const att of buildAttempts(s, input)) {
1495
- const phaseCurrents = s.currents[att.phases] ?? s.currents.I ?? [];
1496
- const need = input.stepVoltageV > 0 ? input.throughCurrentA * input.stepVoltageV / 1e3 : 0;
1497
- const capacityOk = (c) => {
1498
- const psin = s.stepCapacityByCurrent?.[c];
1499
- if (psin != null && need > psin + 0.5) return false;
1500
- return true;
1501
- };
1502
- const covering = phaseCurrents.filter(
1503
- (c) => ratingCoversDuty(input.throughCurrentA, c) && capacityOk(c)
1504
- );
1505
- if (!covering.length) continue;
1506
- const currentsToEmit = covering.slice(0, 2);
1507
- const topEmitted = Math.max(...currentsToEmit);
1508
- const stepUpCurrent = [...phaseCurrents].sort((a, b) => a - b).find(
1509
- (c) => c > topEmitted + 0.5 && ratingCoversDuty(input.throughCurrentA, c) && capacityOk(c)
1510
- );
1511
- if (stepUpCurrent != null && !currentsToEmit.includes(stepUpCurrent)) {
1512
- currentsToEmit.push(stepUpCurrent);
2016
+ const trRaised = /* @__PURE__ */ new Map();
2017
+ const octcWidePass = wantOctc && (wantStruct ?? "auto") === "auto";
2018
+ const passes = !wantOctc ? [{ wide: false, all: false }] : octcWidePass ? [
2019
+ { wide: false, all: false },
2020
+ { wide: true, all: false },
2021
+ { wide: false, all: true },
2022
+ { wide: true, all: true }
2023
+ ] : [
2024
+ { wide: false, all: false },
2025
+ { wide: false, all: true }
2026
+ ];
2027
+ for (const { wide, all } of passes) {
2028
+ if ((wide || all) && results.length) break;
2029
+ for (const s of candidates) {
2030
+ const tap = isOctcSeries(s) ? baseTap : seriesTap(s, baseTap, input.regulation);
2031
+ if (!tap) continue;
2032
+ if (!compoundCoversAcrossTap(s, input)) {
2033
+ acrossTapShort = true;
2034
+ continue;
1513
2035
  }
1514
- for (const current of currentsToEmit) {
1515
- const octc = isOctcSeries(s);
1516
- const contact = octc ? octcContactCode(input, s.id) : "";
1517
- const gradePick = !octc && s.usesSelectorSize ? resolveSelectorSize(
1518
- att.um,
1519
- input.selectorSize ?? "auto",
1520
- input.acrossTapBilKv,
1521
- input.acrossTapPfKv
1522
- ) : null;
1523
- if (gradePick && gradePick.size == null) {
1524
- acrossTapShort = true;
1525
- continue;
1526
- }
1527
- const selectorSize = octc ? octcSizeLetter(att.um, contact, input.selectorSize ?? "auto") : gradePick?.size ?? "";
1528
- const tapCode = octc ? contact : tap.tapCode;
1529
- const modelTap = octc ? `${contact}${selectorSize}` : s.id === "cz" || s.id === "hwdk" ? String(tap.positions) : tap.tapCode;
1530
- const umToken = formatUmToken(att.um, selectorSize, s.usesSelectorSize);
1531
- const phases = phaseToken(att.phases);
1532
- const conn = input.connection === "any" ? s.connections.includes("Y") ? "Y" : s.connections[0] : input.connection;
1533
- let mduStr = "";
1534
- const mduPref = input.mdu ?? "none";
1535
- if (mduPref && mduPref !== "none" && mduPref !== "auto") {
1536
- mduStr = mduPref;
1537
- } else if (mduPref === "auto") {
1538
- mduStr = s.defaultMdu;
1539
- }
1540
- const modelConn = connectionLetterOnPhase(
1541
- s,
1542
- att.phases,
1543
- conn
1544
- );
1545
- let finalModel = buildModelString(
1546
- s,
1547
- phases,
1548
- current,
1549
- modelConn,
1550
- umToken,
1551
- modelTap,
1552
- att.unitCount,
1553
- input.octcSeries
1554
- );
1555
- if (att.phases === "I") {
1556
- finalModel = finalModel.replace(
1557
- new RegExp(`(${s.code}I-\\d+)[YD]/`),
1558
- "$1/"
1559
- );
1560
- } else if (att.phases === "II" && modelConn === "any") {
1561
- finalModel = finalModel.replace(
1562
- new RegExp(`(${s.code}II-\\d+)[YD]/`),
1563
- "$1/"
1564
- );
1565
- }
1566
- if (octc) {
1567
- const listed = resolveOctcListModel(finalModel);
1568
- if (!listed) continue;
1569
- finalModel = listed;
1570
- } else if (!commercialTypeExists(finalModel, s)) {
1571
- continue;
1572
- }
1573
- if (seen.has(finalModel)) continue;
1574
- seen.add(finalModel);
1575
- const modelWithMdu = mduStr ? `${finalModel}+${mduStr}` : finalModel;
1576
- const score = adequacyScore(s, input, current, att.um, att.unitCount);
1577
- const reasonsEn = [];
1578
- const reasonsZh = [];
1579
- const warningsEn = [];
1580
- const warningsZh = [];
1581
- const cautionsEn = [];
1582
- const cautionsZh = [];
1583
- if (input.throughCurrentA > current + 0.01) {
1584
- const pct = ((input.throughCurrentA / current - 1) * 100).toFixed(1);
1585
- cautionsEn.push(
1586
- `Duty ${input.throughCurrentA.toFixed(1)} A is ${pct}% above the ${current} A rating (1% commercial tolerance). Confirm with engineering.`
1587
- );
1588
- cautionsZh.push(
1589
- `\u9700\u6C42 ${input.throughCurrentA.toFixed(1)} A \u8D85\u51FA\u989D\u5B9A ${current} A \u7684 ${pct}%\uFF08\u6309 1% \u5546\u52A1\u5BB9\u5DEE\u653E\u884C\uFF09\uFF0C\u987B\u5DE5\u7A0B\u786E\u8BA4\u3002`
1590
- );
1591
- }
1592
- if (!octc && !(input.stepVoltageV > 0)) {
1593
- cautionsEn.push(
1594
- "Step voltage not given: step-voltage and step-capacity limits were not checked."
1595
- );
1596
- cautionsZh.push("\u672A\u7ED9\u7EA7\u7535\u538B\uFF1A\u7EA7\u7535\u538B\u548C\u7EA7\u5BB9\u91CF\u90FD\u6CA1\u6709\u6821\u9A8C\u3002");
1597
- }
1598
- if (!octc && !tap.standard) {
1599
- cautionsEn.push(
1600
- `Tap code ${tap.tapCode} is not a brochure Fig. 3-3 diagram. Engineering must confirm the connection.`
1601
- );
1602
- cautionsZh.push(
1603
- `\u5206\u63A5\u4EE3\u7801 ${tap.tapCode} \u4E0D\u5728\u6837\u672C\u56FE 3-3 \u6807\u51C6\u63A5\u7EBF\u5185\uFF0C\u987B\u5DE5\u7A0B\u786E\u8BA4\u63A5\u7EBF\u3002`
1604
- );
1605
- }
1606
- if (gradePick?.raisedFrom) {
1607
- cautionsEn.push(
1608
- `Selector grade raised from ${gradePick.raisedFrom} to ${selectorSize} (Um ${att.um} kV / across-tap stress).`
1609
- );
1610
- cautionsZh.push(
1611
- `\u9009\u62E9\u5668\u7B49\u7EA7\u5DF2\u7531 ${gradePick.raisedFrom} \u5347\u4E3A ${selectorSize}\uFF08Um ${att.um} kV \u6216\u8C03\u538B\u7ED5\u7EC4\u95F4\u7EDD\u7F18\u8981\u6C42\uFF09\u3002`
1612
- );
1613
- }
1614
- if (!octc && !s.usesSelectorSize && s.structure !== "compound" && ((input.acrossTapBilKv ?? 0) > 0 || (input.acrossTapPfKv ?? 0) > 0)) {
1615
- cautionsEn.push(
1616
- `${s.code} across-tap withstand is not in the catalogue data: across-tap stress not checked.`
1617
- );
1618
- cautionsZh.push(
1619
- `${s.code} \u8C03\u538B\u7ED5\u7EC4\u95F4\u8010\u53D7\u4E0D\u5728\u76EE\u5F55\u6570\u636E\u91CC\uFF1A\u8C03\u538B\u7ED5\u7EC4\u95F4\u7EDD\u7F18\u672A\u6821\u9A8C\u3002`
1620
- );
2036
+ if (!isOctcSeries(s)) {
2037
+ const pitchMaxUst = maxStepVoltageForSeries(s, tap.pitch);
2038
+ if (input.stepVoltageV > pitchMaxUst + 0.5) continue;
2039
+ const maxPos = input.regulation === "linear" ? s.maxPositionsLinear : s.maxPositionsWithChangeOver;
2040
+ if (tap.positions > maxPos) continue;
2041
+ } else {
2042
+ let octcPos = input.positions;
2043
+ if (input.plusMinusSteps != null && input.plusMinusSteps > 0) {
2044
+ octcPos = 2 * input.plusMinusSteps + 1;
1621
2045
  }
1622
- const dutyA = input.throughCurrentA >= 100 ? String(Math.round(input.throughCurrentA)) : String(Math.round(input.throughCurrentA * 10) / 10);
1623
- reasonsEn.push(
1624
- `Minimum-adequate path: ${s.nameEn}, Ium ${current} A \u2265 ${dutyA} A, Um ${att.um} kV.`
2046
+ if (octcPos != null && octcPos > s.maxPositionsLinear) continue;
2047
+ }
2048
+ for (const att of buildAttempts(s, input, wide)) {
2049
+ const phaseCurrents = s.currents[att.phases] ?? s.currents.I ?? [];
2050
+ const need = input.stepVoltageV > 0 ? input.throughCurrentA * input.stepVoltageV / 1e3 : 0;
2051
+ const capacityOk = (c) => {
2052
+ const psin = stepCapacityKva(s, c, tap.pitch, input.throughCurrentA);
2053
+ if (psin != null && need > psin + 0.5) return false;
2054
+ if (input.stepVoltageV > maxStepVoltageForSeries(s, tap.pitch, c) + 0.5) return false;
2055
+ return true;
2056
+ };
2057
+ const covering = phaseCurrents.filter(
2058
+ (c) => ratingCoversDuty(input.throughCurrentA, c) && capacityOk(c)
1625
2059
  );
1626
- reasonsZh.push(
1627
- `\u6700\u4F4E\u6EE1\u8DB3\u8DEF\u5F84\uFF1A${s.nameZh}\uFF0CIum ${current} A \u2265 \u9700\u6C42 ${dutyA} A\uFF0CUm ${att.um} kV\u3002`
2060
+ if (!covering.length) continue;
2061
+ const listGated = isOctcSeries(s) && all;
2062
+ let listRowsEmitted = 0;
2063
+ const currentsToEmit = listGated ? [...covering] : covering.slice(0, 2);
2064
+ const topEmitted = Math.max(...currentsToEmit);
2065
+ const stepUpCurrent = [...phaseCurrents].sort((a, b) => a - b).find(
2066
+ (c) => c > topEmitted + 0.5 && ratingCoversDuty(input.throughCurrentA, c) && capacityOk(c)
1628
2067
  );
1629
- if (s.structure === "compound" && !octc) {
1630
- reasonsEn.push(
1631
- "Compound type fits duty \u2014 preferred over larger combined types when eligible."
1632
- );
1633
- reasonsZh.push(
1634
- "\u590D\u5408\u5F0F\u6EE1\u8DB3\u5DE5\u51B5\u65F6\u4F18\u5148\u4E8E\u66F4\u5927\u7684\u7EC4\u5408\u5F0F\uFF08\u975E\u9ED8\u8BA4 SHZV\uFF09\u3002"
1635
- );
1636
- }
1637
- if (s.usesSelectorSize) {
1638
- reasonsEn.push(
1639
- `Tap selector grade ${selectorSize} (smallest covering Um` + (input.acrossTapBilKv ? ` + across-tap BIL ${input.acrossTapBilKv} kV` : "") + ")."
1640
- );
1641
- reasonsZh.push(
1642
- `\u5206\u63A5\u9009\u62E9\u5668\u7B49\u7EA7 ${selectorSize}\uFF08\u6EE1\u8DB3 Um` + (input.acrossTapBilKv ? ` \u4E0E\u8C03\u538B\u7ED5\u7EC4\u95F4 BIL ${input.acrossTapBilKv} kV` : "") + " \u7684\u6700\u5C0F\u89C4\u683C\uFF09\u3002"
1643
- );
2068
+ if (stepUpCurrent != null && !currentsToEmit.includes(stepUpCurrent)) {
2069
+ currentsToEmit.push(stepUpCurrent);
1644
2070
  }
1645
- if (octc) {
1646
- const roman = octcRoman(conn, contact, input.octcSeries, s.code);
1647
- reasonsEn.push(
1648
- `OCTC contact ${contact}${selectorSize} (${s.code}${roman}).`
1649
- );
1650
- reasonsZh.push(
1651
- `\u65E0\u8F7D\u89E6\u5934 ${contact}${selectorSize}\uFF08${s.code}${roman}\uFF09\u3002`
2071
+ for (const current of currentsToEmit) {
2072
+ if (listGated && listRowsEmitted >= 3) break;
2073
+ const octc = isOctcSeries(s);
2074
+ const contact = octc ? octcContactCode(input, s.id) : "";
2075
+ if (octc && !contact) continue;
2076
+ const umDefault = defaultSelectorSizeForUm(att.um);
2077
+ const classBump = !octc && s.usesSelectorSize && input.transformerKind !== "auto" && (input.tapWindingKv ?? 0) >= 330 && att.um <= 126 + 0.1 && // One stated value alone does not settle the grade (ENGINE-1).
2078
+ !((input.acrossTapBilKv ?? 0) > 0 && (input.acrossTapPfKv ?? 0) > 0) ? SIZE_ORDER[SIZE_ORDER.indexOf(umDefault) + 1] : void 0;
2079
+ const trBump = !octc && !classBump && s.usesSelectorSize && (input.market ?? "").trim().toUpperCase() === "TR" && input.connection === "Y" && input.transformerKind !== "auto" && (input.tapWindingKv ?? 0) >= 110 && att.um <= 72.5 + 0.1 && !((input.acrossTapBilKv ?? 0) > 0 && (input.acrossTapPfKv ?? 0) > 0) && // 2026-11-04 final ENGINE-11: one stated value above what B withstands
2080
+ // (LI 350 > 265) sets C from the stress, not from practice: no
2081
+ // "B also fits" caution and no B copy.
2082
+ coversAcrossTap(umDefault, input.acrossTapBilKv ?? 0, input.acrossTapPfKv ?? 0, s.id) ? SIZE_ORDER[SIZE_ORDER.indexOf(umDefault) + 1] : void 0;
2083
+ const gradePick = !octc && s.usesSelectorSize ? resolveSelectorSize(
2084
+ att.um,
2085
+ input.selectorSize ?? "auto",
2086
+ input.acrossTapBilKv,
2087
+ input.acrossTapPfKv,
2088
+ s.id,
2089
+ // Only a, not b, is checked: the stated stress may lower the
2090
+ // grade where no phase-to-phase gap matters (2026-11-04 GRADE-2).
2091
+ att.phases === "I" || att.phases === "III" && input.connection === "Y",
2092
+ classBump ?? trBump
2093
+ ) : null;
2094
+ if (gradePick && gradePick.size == null) {
2095
+ acrossTapShort = true;
2096
+ continue;
2097
+ }
2098
+ let selectorSize = octc ? octcSizeLetter(
2099
+ att.um,
2100
+ contact,
2101
+ input.selectorSize ?? "auto",
2102
+ (input.acrossTapBilKv ?? 0) > 0 || (input.acrossTapPfKv ?? 0) > 0
2103
+ ) : gradePick?.size ?? "";
2104
+ const tapCode = octc ? contact : tap.tapCode;
2105
+ const modelTap = octc ? `${contact}${selectorSize}` : s.id === "cz" ? String(tap.positions) : s.id === "hwdk" ? String(
2106
+ input.plusMinusSteps != null && input.plusMinusSteps > 0 ? 2 * input.plusMinusSteps + 1 : tap.positions
2107
+ ) : s.id === "cvt" ? `09${String(tap.positions).padStart(2, "0")}` : tap.tapCode;
2108
+ const umToken = formatUmToken(att.um, selectorSize, s.usesSelectorSize);
2109
+ const phases = phaseToken(att.phases);
2110
+ const conn = input.connection === "any" ? s.connections.includes("Y") ? "Y" : s.connections[0] : input.connection;
2111
+ let mduStr = "";
2112
+ const mduPref = input.mdu ?? "none";
2113
+ if (mduPref && mduPref !== "none" && mduPref !== "auto") {
2114
+ mduStr = mduPref;
2115
+ } else if (mduPref === "auto") {
2116
+ mduStr = s.defaultMdu;
2117
+ }
2118
+ const modelConn = connectionLetterOnPhase(
2119
+ s,
2120
+ att.phases,
2121
+ conn
1652
2122
  );
1653
- } else {
1654
- reasonsEn.push(
1655
- `Tap code ${tap.tapCode}: pitch ${tap.pitch}, ${tap.positions} pos, mid ${tap.mid}, ${input.regulation}.`
2123
+ let finalModel = buildModelString(
2124
+ s,
2125
+ phases,
2126
+ current,
2127
+ modelConn,
2128
+ umToken,
2129
+ modelTap,
2130
+ att.unitCount,
2131
+ input.octcSeries
1656
2132
  );
1657
- reasonsZh.push(
1658
- `\u5206\u63A5\u4EE3\u7801 ${tap.tapCode}\uFF1A\u8282\u8DDD ${tap.pitch}\uFF0C${tap.positions} \u4F4D\uFF0C\u4E2D\u95F4\u4F4D ${tap.mid}\u3002`
2133
+ if (att.phases === "I") {
2134
+ finalModel = finalModel.replace(
2135
+ new RegExp(`(${s.code}I-\\d+)[YD]/`),
2136
+ "$1/"
2137
+ );
2138
+ } else if (att.phases === "II" && modelConn === "any") {
2139
+ finalModel = finalModel.replace(
2140
+ new RegExp(`(${s.code}II-\\d+)[YD]/`),
2141
+ "$1/"
2142
+ );
2143
+ }
2144
+ if (octc) {
2145
+ const listed = resolveOctcListModel(finalModel);
2146
+ if (!listed) continue;
2147
+ finalModel = listed;
2148
+ const listedSize = parseTypeString(listed)?.selectorSize;
2149
+ if (listedSize) selectorSize = listedSize;
2150
+ } else if (!commercialTypeExists(finalModel, s)) {
2151
+ continue;
2152
+ }
2153
+ if (seen.has(finalModel)) continue;
2154
+ seen.add(finalModel);
2155
+ listRowsEmitted += 1;
2156
+ const modelWithMdu = mduStr ? `${finalModel}+${mduStr}` : finalModel;
2157
+ const score = adequacyScore(
2158
+ s,
2159
+ input,
2160
+ current,
2161
+ att.um,
2162
+ rankUnits(s.id, att.unitCount),
2163
+ tap.pitch
1659
2164
  );
1660
- }
1661
- if (att.unitCount > 1) {
1662
- if (att.deltaForced) {
1663
- reasonsEn.push(
1664
- `${att.unitCount}\xD7 single-phase \u2014 no brochure III type for this connection (e.g. CM2III-\u2026D does not exist).`
2165
+ const reasonsEn = [];
2166
+ const reasonsZh = [];
2167
+ const warningsEn = [];
2168
+ const warningsZh = [];
2169
+ const cautionsEn = [];
2170
+ const cautionsZh = [];
2171
+ if (!octc && !(input.stepVoltageV > 0)) {
2172
+ cautionsEn.push(
2173
+ "Step voltage not given: step-voltage and step-capacity limits were not checked."
1665
2174
  );
1666
- reasonsZh.push(
1667
- `${att.unitCount} \u53F0\u5355\u76F8 \u2014 \u6837\u672C\u6CA1\u6709\u8FD9\u4E2A\u8FDE\u63A5\u7684\u4E09\u76F8\u578B\u53F7\uFF08\u6CA1\u6709 CM2III-\u2026D\uFF09\u3002`
2175
+ cautionsZh.push("\u672A\u7ED9\u7EA7\u7535\u538B\uFF1A\u7EA7\u7535\u538B\u548C\u7EA7\u5BB9\u91CF\u90FD\u6CA1\u6709\u6821\u9A8C\u3002");
2176
+ }
2177
+ if (!octc && !tap.standard) {
2178
+ cautionsEn.push(
2179
+ `Tap code ${tap.tapCode} is not a brochure Fig. 3-3 diagram. Engineering must confirm the connection.`
1668
2180
  );
1669
- } else {
1670
- reasonsEn.push(
1671
- `${att.unitCount}\xD7 single-phase \u2014 no single III unit covers this I\u1D64 (prefer one SHZV/SHZVG when it fits; 3\xD7 costs more).`
2181
+ cautionsZh.push(
2182
+ `\u5206\u63A5\u4EE3\u7801 ${tap.tapCode} \u4E0D\u5728\u6837\u672C\u56FE 3-3 \u6807\u51C6\u63A5\u7EBF\u5185\uFF0C\u987B\u5DE5\u7A0B\u786E\u8BA4\u63A5\u7EBF\u3002`
1672
2183
  );
1673
- reasonsZh.push(
1674
- `${att.unitCount} \u53F0\u5355\u76F8 \u2014 \u65E0\u4E09\u76F8\u6574\u673A\u53EF\u8986\u76D6\u6B64\u7535\u6D41\uFF08\u6709 SHZV/SHZVG \u6574\u673A\u65F6\u4F18\u5148\uFF1B3\xD7 \u66F4\u8D35\uFF09\u3002`
2184
+ }
2185
+ if (s.id === "cvt" && input.regulation !== "linear") {
2186
+ cautionsEn.push("CVT is a linear-regulation type (brochure). Engineering must confirm it for this range.");
2187
+ cautionsZh.push("CVT \u6837\u672C\u53EA\u6709\u7EBF\u6027\u8C03\uFF0C\u6B64\u8C03\u538B\u8303\u56F4\u8BF7\u5DE5\u7A0B\u786E\u8BA4\u3002");
2188
+ }
2189
+ if (!octc) {
2190
+ const review = [];
2191
+ const reviewZh = [];
2192
+ if (s.id === "cm2" && input.stepVoltageV > 2500 + 0.5) {
2193
+ review.push("CM2 step voltage above 2500 V");
2194
+ reviewZh.push("CM2 \u7EA7\u7535\u538B\u8D85\u8FC7 2500 V");
2195
+ }
2196
+ if (s.id === "shzv" && input.stepVoltageV > 3300 + 0.5) {
2197
+ review.push("SHZV step voltage above 3300 V");
2198
+ reviewZh.push("SHZV \u7EA7\u7535\u538B\u8D85\u8FC7 3300 V");
2199
+ }
2200
+ if (selectorSize === "DE" || selectorSize === "E") {
2201
+ review.push(`selector grade ${selectorSize}`);
2202
+ reviewZh.push(`\u9009\u62E9\u5668 ${selectorSize} \u7EA7`);
2203
+ }
2204
+ if (att.um >= 300) {
2205
+ review.push(`Um ${att.um} kV`);
2206
+ reviewZh.push(`Um ${att.um} kV`);
2207
+ }
2208
+ if (review.length) {
2209
+ cautionsEn.push(`Needs the maker's technical review: ${review.join(", ")}.`);
2210
+ cautionsZh.push(`\u987B\u5382\u5BB6\u6280\u672F\u7279\u522B\u8BC4\u5BA1\uFF1A${reviewZh.join("\uFF0C")}\u3002`);
2211
+ }
2212
+ if (tap.changeOver !== "0" && input.transformerKind !== "auto" && (input.tapWindingKv ?? 0) > 121) {
2213
+ cautionsEn.push(
2214
+ "Change-over selector above 110 kV: check the recovery voltage and quote the tie-in resistor as an option (maker's Cw/Ce needed)."
2215
+ );
2216
+ cautionsZh.push("110 kV \u4EE5\u4E0A\u7684\u6B63\u53CD\u8C03/\u7C97\u7EC6\u8C03\uFF1A\u8981\u6838\u6062\u590D\u7535\u538B\uFF0C\u53EF\u80FD\u8981\u52A0\u7535\u4F4D\u7535\u963B\u3002\u8BF7\u53D8\u538B\u5668\u5382\u63D0\u4F9B Cw\u3001Ce\uFF0C\u62A5\u4EF7\u65F6\u628A\u7535\u4F4D\u7535\u963B\u5217\u4E3A\u53EF\u9009\u9879\u3002");
2217
+ }
2218
+ }
2219
+ if (wide) {
2220
+ const from = nearestUm(input.umKv, s.umKv);
2221
+ if (from != null && att.um > from + 0.1) {
2222
+ cautionsEn.push(`No ${from} kV list row covers this duty: next class ${att.um} kV.`);
2223
+ cautionsZh.push(`${from} kV \u4EF7\u76EE\u8868\u6CA1\u6709\u6EE1\u8DB3\u6B64\u5DE5\u51B5\u7684\u578B\u53F7\uFF1A\u4E0A\u9760\u81F3 ${att.um} kV\u3002`);
2224
+ }
2225
+ }
2226
+ if (gradePick?.raisedFrom) {
2227
+ cautionsEn.push(
2228
+ `Selector grade raised from ${gradePick.raisedFrom} to ${selectorSize} (Um ${att.um} kV / across-tap stress).`
2229
+ );
2230
+ cautionsZh.push(
2231
+ `\u9009\u62E9\u5668\u7B49\u7EA7\u5DF2\u7531 ${gradePick.raisedFrom} \u5347\u4E3A ${selectorSize}\uFF08Um ${att.um} kV \u6216\u8C03\u538B\u7ED5\u7EC4\u95F4\u7EDD\u7F18\u8981\u6C42\uFF09\u3002`
1675
2232
  );
1676
2233
  }
1677
- }
1678
- const earth = EARTH_INSULATION[att.um];
1679
- if (earth) {
1680
- reasonsEn.push(
1681
- `Earth insulation (catalogue): PF ${earth.pf} / LI ${earth.bil} kV.`
1682
- );
1683
- reasonsZh.push(
1684
- `\u5BF9\u5730\u7EDD\u7F18\uFF08\u6837\u672C\uFF09\uFF1A\u5DE5\u9891 ${earth.pf} / \u96F7\u7535 ${earth.bil} kV\u3002`
1685
- );
1686
- }
1687
- if (current > input.throughCurrentA + 0.5) {
1688
- warningsEn.push(`Through-current rounded up to ${current} A.`);
1689
- warningsZh.push(`\u901A\u8FC7\u7535\u6D41\u5DF2\u4E0A\u9760\u81F3 ${current} A\u3002`);
1690
- }
1691
- const coveringUm = nearestUm(input.umKv, s.umKv);
1692
- const extraUm = coveringUm != null && att.um > coveringUm + 0.1;
1693
- if (extraUm) {
2234
+ const gradeAuto = !gradePick?.raisedFrom && (input.selectorSize ?? "auto") === "auto";
2235
+ if (gradeAuto && classBump && selectorSize === classBump) {
2236
+ cautionsEn.push(
2237
+ `Selector grade raised one step to ${selectorSize}: winding of 330 kV class or above.`
2238
+ );
2239
+ cautionsZh.push(`\u9009\u62E9\u5668\u7B49\u7EA7\u4E0A\u8C03\u4E00\u7EA7\u4E3A ${selectorSize}\uFF1A330 kV \u7EA7\u53CA\u4EE5\u4E0A\u7ED5\u7EC4\u3002`);
2240
+ } else if (gradeAuto && classBump && ((input.acrossTapBilKv ?? 0) > 0 || (input.acrossTapPfKv ?? 0) > 0) && SIZE_ORDER.indexOf(selectorSize) > SIZE_ORDER.indexOf(classBump)) {
2241
+ const li = input.acrossTapBilKv ?? 0;
2242
+ const ac = input.acrossTapPfKv ?? 0;
2243
+ const en = [li > 0 ? `LI ${li}` : "", ac > 0 ? `AC ${ac}` : ""].filter(Boolean).join(" / ");
2244
+ const zh = [li > 0 ? `\u96F7\u7535 ${li}` : "", ac > 0 ? `\u5DE5\u9891 ${ac}` : ""].filter(Boolean).join(" / ");
2245
+ cautionsEn.push(
2246
+ `Selector grade ${selectorSize} from the stated across-tap ${en} kV (330 kV-class step gives ${classBump}).`
2247
+ );
2248
+ cautionsZh.push(`\u9009\u62E9\u5668\u7B49\u7EA7 ${selectorSize} \u4F9D\u636E\u7ED9\u5B9A\u7684\u8C03\u538B\u7ED5\u7EC4\u95F4 ${zh} kV\uFF08330 kV \u7EA7\u4E0A\u8C03\u4E3A ${classBump}\uFF09\u3002`);
2249
+ }
2250
+ const trRaise = gradeAuto && trBump != null && selectorSize === trBump;
2251
+ if (trRaise) {
2252
+ cautionsEn.push(
2253
+ `Selector grade raised to ${selectorSize}: ${selectorSize} is usual on Turkish 110 kV-class neutrals (${umDefault} also fits).`
2254
+ );
2255
+ cautionsZh.push(
2256
+ `\u9009\u62E9\u5668\u7B49\u7EA7\u4E0A\u8C03\u4E3A ${selectorSize}\uFF1A\u571F\u8033\u5176 110 kV \u7EA7\u4E2D\u6027\u70B9\u901A\u5E38\u53D6 ${selectorSize}\uFF08${umDefault} \u4E5F\u6EE1\u8DB3\uFF09\u3002`
2257
+ );
2258
+ }
2259
+ if (gradePick?.loweredFrom) {
2260
+ cautionsEn.push(
2261
+ `Selector grade ${selectorSize} is below the Um ${att.um} kV default ${gradePick.loweredFrom}, from the stated across-tap LI ${input.acrossTapBilKv} / AC ${input.acrossTapPfKv} kV.`
2262
+ );
2263
+ cautionsZh.push(
2264
+ `\u9009\u62E9\u5668\u7B49\u7EA7 ${selectorSize} \u4F4E\u4E8E Um ${att.um} kV \u7684\u9ED8\u8BA4 ${gradePick.loweredFrom}\uFF0C\u4F9D\u636E\u7ED9\u5B9A\u7684\u8C03\u538B\u7ED5\u7EC4\u95F4 \u96F7\u7535 ${input.acrossTapBilKv} / \u5DE5\u9891 ${input.acrossTapPfKv} kV\u3002`
2265
+ );
2266
+ }
2267
+ if (!octc && !s.usesSelectorSize && s.structure !== "compound" && ((input.acrossTapBilKv ?? 0) > 0 || (input.acrossTapPfKv ?? 0) > 0)) {
2268
+ cautionsEn.push(
2269
+ `${s.code} across-tap withstand is not in the catalogue data: across-tap stress not checked.`
2270
+ );
2271
+ cautionsZh.push(
2272
+ `${s.code} \u8C03\u538B\u7ED5\u7EC4\u95F4\u8010\u53D7\u4E0D\u5728\u76EE\u5F55\u6570\u636E\u91CC\uFF1A\u8C03\u538B\u7ED5\u7EC4\u95F4\u7EDD\u7F18\u672A\u6821\u9A8C\u3002`
2273
+ );
2274
+ }
2275
+ const dutyA = input.throughCurrentA >= 100 ? String(Math.round(input.throughCurrentA)) : String(Math.round(input.throughCurrentA * 10) / 10);
1694
2276
  reasonsEn.push(
1695
- `Next catalogue Um ${att.um} kV (list twin of ${coveringUm} kV).`
2277
+ `Minimum-adequate path: ${s.nameEn}, Ium ${current} A \u2265 ${dutyA} A, Um ${att.um} kV.`
1696
2278
  );
1697
2279
  reasonsZh.push(
1698
- `\u76EE\u5F55\u4E0B\u4E00\u6863 Um ${att.um} kV\uFF08${coveringUm} kV \u7684\u4EF7\u76EE\u8868\u914D\u5BF9\uFF09\u3002`
2280
+ `\u6700\u4F4E\u6EE1\u8DB3\u8DEF\u5F84\uFF1A${s.nameZh}\uFF0CIum ${current} A \u2265 \u9700\u6C42 ${dutyA} A\uFF0CUm ${att.um} kV\u3002`
1699
2281
  );
1700
- } else if (att.um > input.umKv + 0.1) {
1701
- warningsEn.push(`Um rounded up to ${att.um} kV.`);
1702
- warningsZh.push(`Um \u5DF2\u4E0A\u9760\u81F3 ${att.um} kV\u3002`);
2282
+ if (s.structure === "compound" && !octc) {
2283
+ reasonsEn.push(
2284
+ "Compound type fits duty \u2014 preferred over larger combined types when eligible."
2285
+ );
2286
+ reasonsZh.push(
2287
+ "\u590D\u5408\u5F0F\u6EE1\u8DB3\u5DE5\u51B5\u65F6\u4F18\u5148\u4E8E\u66F4\u5927\u7684\u7EC4\u5408\u5F0F\uFF08\u975E\u9ED8\u8BA4 SHZV\uFF09\u3002"
2288
+ );
2289
+ }
2290
+ if (s.usesSelectorSize) {
2291
+ reasonsEn.push(
2292
+ `Tap selector grade ${selectorSize} (smallest covering Um` + (input.acrossTapBilKv ? ` + across-tap BIL ${input.acrossTapBilKv} kV` : "") + ")."
2293
+ );
2294
+ reasonsZh.push(
2295
+ `\u5206\u63A5\u9009\u62E9\u5668\u7B49\u7EA7 ${selectorSize}\uFF08\u6EE1\u8DB3 Um` + (input.acrossTapBilKv ? ` \u4E0E\u8C03\u538B\u7ED5\u7EC4\u95F4 BIL ${input.acrossTapBilKv} kV` : "") + " \u7684\u6700\u5C0F\u89C4\u683C\uFF09\u3002"
2296
+ );
2297
+ }
2298
+ if (octc) {
2299
+ const roman = octcRoman(conn, contact, input.octcSeries, s.code);
2300
+ reasonsEn.push(
2301
+ `OCTC contact ${contact}${selectorSize} (${s.code}${roman}).`
2302
+ );
2303
+ reasonsZh.push(
2304
+ `\u65E0\u8F7D\u89E6\u5934 ${contact}${selectorSize}\uFF08${s.code}${roman}\uFF09\u3002`
2305
+ );
2306
+ } else {
2307
+ reasonsEn.push(
2308
+ `Tap code ${tap.tapCode}: pitch ${tap.pitch}, ${tap.positions} pos, mid ${tap.mid}, ${input.regulation}.`
2309
+ );
2310
+ reasonsZh.push(
2311
+ `\u5206\u63A5\u4EE3\u7801 ${tap.tapCode}\uFF1A\u8282\u8DDD ${tap.pitch}\uFF0C${tap.positions} \u4F4D\uFF0C\u4E2D\u95F4\u4F4D ${tap.mid}\u3002`
2312
+ );
2313
+ }
2314
+ if (rankUnits(s.id, att.unitCount) > 1) {
2315
+ if (att.deltaForced) {
2316
+ reasonsEn.push(
2317
+ `${att.unitCount}\xD7 single-phase \u2014 no brochure III type for this connection (e.g. CM2III-\u2026D does not exist).`
2318
+ );
2319
+ reasonsZh.push(
2320
+ `${att.unitCount} \u53F0\u5355\u76F8 \u2014 \u6837\u672C\u6CA1\u6709\u8FD9\u4E2A\u8FDE\u63A5\u7684\u4E09\u76F8\u578B\u53F7\uFF08\u6CA1\u6709 CM2III-\u2026D\uFF09\u3002`
2321
+ );
2322
+ } else {
2323
+ reasonsEn.push(
2324
+ `${att.unitCount}\xD7 single-phase \u2014 no single III unit covers this I\u1D64 (prefer one SHZV/SHZVG when it fits; 3\xD7 costs more).`
2325
+ );
2326
+ reasonsZh.push(
2327
+ `${att.unitCount} \u53F0\u5355\u76F8 \u2014 \u65E0\u4E09\u76F8\u6574\u673A\u53EF\u8986\u76D6\u6B64\u7535\u6D41\uFF08\u6709 SHZV/SHZVG \u6574\u673A\u65F6\u4F18\u5148\uFF1B3\xD7 \u66F4\u8D35\uFF09\u3002`
2328
+ );
2329
+ }
2330
+ }
2331
+ const earth = EARTH_INSULATION[att.um];
2332
+ if (earth) {
2333
+ reasonsEn.push(
2334
+ `Earth insulation (catalogue): PF ${earth.pf} / LI ${earth.bil} kV.`
2335
+ );
2336
+ reasonsZh.push(
2337
+ `\u5BF9\u5730\u7EDD\u7F18\uFF08\u6837\u672C\uFF09\uFF1A\u5DE5\u9891 ${earth.pf} / \u96F7\u7535 ${earth.bil} kV\u3002`
2338
+ );
2339
+ }
2340
+ if (current > input.throughCurrentA + 0.5) {
2341
+ warningsEn.push(`Through-current rounded up to ${current} A.`);
2342
+ warningsZh.push(`\u901A\u8FC7\u7535\u6D41\u5DF2\u4E0A\u9760\u81F3 ${current} A\u3002`);
2343
+ }
2344
+ const coveringUm = nearestUm(input.umKv, s.umKv);
2345
+ const extraUm = coveringUm != null && att.um > coveringUm + 0.1;
2346
+ if (extraUm) {
2347
+ reasonsEn.push(
2348
+ `Next catalogue Um ${att.um} kV (list twin of ${coveringUm} kV).`
2349
+ );
2350
+ reasonsZh.push(
2351
+ `\u76EE\u5F55\u4E0B\u4E00\u6863 Um ${att.um} kV\uFF08${coveringUm} kV \u7684\u4EF7\u76EE\u8868\u914D\u5BF9\uFF09\u3002`
2352
+ );
2353
+ } else if (att.um > input.umKv + 0.1) {
2354
+ warningsEn.push(`Um rounded up to ${att.um} kV.`);
2355
+ warningsZh.push(`Um \u5DF2\u4E0A\u9760\u81F3 ${att.um} kV\u3002`);
2356
+ }
2357
+ warningsEn.push(
2358
+ "Indicative selection from published technical data. Final OS requires engineering confirmation."
2359
+ );
2360
+ warningsZh.push(
2361
+ "\u4F9D\u636E\u516C\u5F00\u6280\u672F\u6837\u672C\u7684\u9009\u578B\u5EFA\u8BAE\u3002\u6700\u7EC8 OS \u987B\u5DE5\u7A0B\u786E\u8BA4\u3002"
2362
+ );
2363
+ const maxStepVoltageV = octc ? null : maxStepVoltageForSeries(s, tap.pitch, current);
2364
+ const stepCapacity = stepCapacityKva(s, current, tap.pitch, input.throughCurrentA);
2365
+ let confidence = 0.88;
2366
+ if (rankUnits(s.id, att.unitCount) > 1) confidence -= 0.08;
2367
+ confidence -= 0.05 * cautionsEn.length;
2368
+ if (warningsEn.length > 2) confidence -= 0.03;
2369
+ confidence = Math.max(0.45, Math.min(0.96, confidence));
2370
+ results.push({
2371
+ seriesId: s.id,
2372
+ seriesCode: s.code,
2373
+ model: finalModel,
2374
+ modelWithMdu,
2375
+ phases: att.phases,
2376
+ currentA: current,
2377
+ connection: conn,
2378
+ umKv: att.um,
2379
+ selectorSize,
2380
+ umToken,
2381
+ tapCode,
2382
+ regulation: input.regulation,
2383
+ changeOver: octc ? "0" : tap.changeOver,
2384
+ pitch: octc ? 0 : tap.pitch,
2385
+ positions: octc ? input.positions ?? (input.plusMinusSteps != null && input.plusMinusSteps > 0 ? 2 * input.plusMinusSteps + 1 : 5) : tap.positions,
2386
+ mid: octc ? 0 : tap.mid,
2387
+ mdu: mduStr,
2388
+ unitCount: att.unitCount,
2389
+ maxStepVoltageV,
2390
+ stepCapacityKva: stepCapacity,
2391
+ earthPfKv: earth?.pf ?? null,
2392
+ earthBilKv: earth?.bil ?? null,
2393
+ reasonsEn,
2394
+ reasonsZh,
2395
+ warningsEn,
2396
+ warningsZh,
2397
+ cautionsEn,
2398
+ cautionsZh,
2399
+ confidence,
2400
+ adequacyScore: score
2401
+ });
2402
+ if (trRaise) trRaised.set(results[results.length - 1], umDefault);
1703
2403
  }
1704
- warningsEn.push(
1705
- "Indicative selection from published technical data. Final OS requires engineering confirmation."
1706
- );
1707
- warningsZh.push(
1708
- "\u4F9D\u636E\u516C\u5F00\u6280\u672F\u6837\u672C\u7684\u9009\u578B\u5EFA\u8BAE\u3002\u6700\u7EC8 OS \u987B\u5DE5\u7A0B\u786E\u8BA4\u3002"
1709
- );
1710
- const maxStepVoltageV = octc ? null : maxStepVoltageForSeries(s, tap.pitch);
1711
- const stepCapacityKva = s.stepCapacityByCurrent?.[current] ?? null;
1712
- let confidence = 0.88;
1713
- if (att.unitCount > 1) confidence -= 0.08;
1714
- confidence -= 0.05 * cautionsEn.length;
1715
- if (warningsEn.length > 2) confidence -= 0.03;
1716
- confidence = Math.max(0.45, Math.min(0.96, confidence));
1717
- results.push({
1718
- seriesId: s.id,
1719
- seriesCode: s.code,
1720
- model: finalModel,
1721
- modelWithMdu,
1722
- phases: att.phases,
1723
- currentA: current,
1724
- connection: conn,
1725
- umKv: att.um,
1726
- selectorSize,
1727
- umToken,
1728
- tapCode,
1729
- regulation: input.regulation,
1730
- changeOver: octc ? "0" : tap.changeOver,
1731
- pitch: octc ? 0 : tap.pitch,
1732
- positions: octc ? input.positions ?? (input.plusMinusSteps != null && input.plusMinusSteps > 0 ? 2 * input.plusMinusSteps + 1 : 5) : tap.positions,
1733
- mid: octc ? 0 : tap.mid,
1734
- mdu: mduStr,
1735
- unitCount: att.unitCount,
1736
- maxStepVoltageV,
1737
- stepCapacityKva,
1738
- earthPfKv: earth?.pf ?? null,
1739
- earthBilKv: earth?.bil ?? null,
1740
- reasonsEn,
1741
- reasonsZh,
1742
- warningsEn,
1743
- warningsZh,
1744
- cautionsEn,
1745
- cautionsZh,
1746
- confidence,
1747
- adequacyScore: score
1748
- });
1749
2404
  }
1750
2405
  }
1751
2406
  }
2407
+ for (const [r, from] of trRaised) {
2408
+ const s = SERIES.find((x) => x.id === r.seriesId);
2409
+ if (!s) continue;
2410
+ const umToken = formatUmToken(r.umKv, from, true);
2411
+ const model = r.model.replace(`/${r.umToken}-`, `/${umToken}-`);
2412
+ if (model === r.model || seen.has(model) || !commercialTypeExists(model, s)) continue;
2413
+ if (!coversAcrossTap(from, input.acrossTapBilKv ?? 0, input.acrossTapPfKv ?? 0, r.seriesId)) continue;
2414
+ seen.add(model);
2415
+ const keep = r.cautionsEn.map((c) => !c.startsWith("Selector grade raised to "));
2416
+ results.push({
2417
+ ...r,
2418
+ model,
2419
+ modelWithMdu: r.mdu ? `${model}+${r.mdu}` : model,
2420
+ selectorSize: from,
2421
+ umToken,
2422
+ reasonsEn: r.reasonsEn.map((x) => x.replace(`grade ${r.selectorSize} (`, `grade ${from} (`)),
2423
+ reasonsZh: r.reasonsZh.map((x) => x.replace(`\u7B49\u7EA7 ${r.selectorSize}\uFF08`, `\u7B49\u7EA7 ${from}\uFF08`)),
2424
+ cautionsEn: r.cautionsEn.filter((_, i) => keep[i]),
2425
+ cautionsZh: r.cautionsZh.filter((_, i) => keep[i]),
2426
+ confidence: Math.min(0.96, r.confidence + 0.05),
2427
+ adequacyScore: r.adequacyScore - 1e-6
2428
+ });
2429
+ }
1752
2430
  let final = results;
1753
2431
  if (wantOctc) {
1754
2432
  final = results.filter((r) => {
1755
2433
  const s = SERIES.find((x) => x.id === r.seriesId);
1756
2434
  return s != null && s.medium === "oil" && !s.vacuum;
1757
2435
  });
2436
+ if (wantStruct === "drum" && final.some((r) => DRUM_SINGLE.has(r.seriesId))) {
2437
+ final = final.filter((r) => r.seriesId !== "wsg");
2438
+ }
1758
2439
  } else if (input.preferVacuum) {
1759
2440
  final = results.filter(
1760
2441
  (r) => SERIES.find((s) => s.id === r.seriesId)?.vacuum
@@ -1765,12 +2446,63 @@ function selectOltc(input) {
1765
2446
  );
1766
2447
  }
1767
2448
  final.sort((a, b) => {
1768
- if (a.unitCount !== b.unitCount) return a.unitCount - b.unitCount;
2449
+ const ua = rankUnits(a.seriesId, a.unitCount);
2450
+ const ub = rankUnits(b.seriesId, b.unitCount);
2451
+ if (ua !== ub) return ua - ub;
1769
2452
  if (b.adequacyScore !== a.adequacyScore)
1770
2453
  return b.adequacyScore - a.adequacyScore;
1771
2454
  return b.confidence - a.confidence;
1772
2455
  });
1773
2456
  if (!final.length) {
2457
+ const locked = candidates.filter(
2458
+ (s) => wantOctc ? s.medium === "oil" && !s.vacuum : input.preferVacuum ? s.vacuum : input.medium === "oil" ? !s.vacuum : true
2459
+ );
2460
+ const why = noFitReasons(locked, input, baseTap);
2461
+ const hinted = normOctcContact(input.octcContact);
2462
+ const asked = octcPositionsAsked(input);
2463
+ if (wantOctc && hinted && asked != null && octcContactPositions(hinted) < asked) {
2464
+ const cov = octcContactPositions(hinted);
2465
+ return {
2466
+ ok: false,
2467
+ results: [],
2468
+ errorsEn: [`Contact ${hinted} covers ${cov} positions; ${asked} were asked.`, ...why?.en ?? []],
2469
+ errorsZh: [`\u89E6\u5934 ${hinted} \u53EA\u8986\u76D6 ${cov} \u4E2A\u5DE5\u4F5C\u4F4D\u7F6E\uFF0C\u8981\u6C42 ${asked} \u4E2A\u3002`, ...why?.zh ?? []]
2470
+ };
2471
+ }
2472
+ if (wantOctc && input.connection === "D") {
2473
+ const conn = input.connection;
2474
+ const dropped = SERIES.filter(
2475
+ (s) => isOctcSeries(s) && s.medium === "oil" && !s.vacuum && seriesMatchesMounting(s, input) && seriesMatchesMedium(s, input) && !s.connections.includes(conn) && !s.connections.includes("any") && (!wantStruct || wantStruct === "auto" || s.structure === wantStruct)
2476
+ );
2477
+ const onY = dropped.length ? selectOltc({ ...input, connection: "Y" }) : null;
2478
+ const fitY = dropped.filter((s) => onY?.ok && onY.results.some((r) => r.seriesId === s.id));
2479
+ if (fitY.length) {
2480
+ const codes = fitY.map((s) => s.code).join("/");
2481
+ if (selectOltc({ ...input, preferStructure: "cage" }).ok) {
2482
+ return {
2483
+ ok: false,
2484
+ results: [],
2485
+ errorsEn: [`${codes} drum OCTC is sold for star (Y) points only; for delta (D) use a cage type.`],
2486
+ errorsZh: [`${codes} \u9F13\u5F0F\u65E0\u8F7D\u53EA\u7528\u4E8E\u661F\u70B9\uFF08Y\uFF09\uFF1B\u89D2\u63A5\uFF08D\uFF09\u8BF7\u7528\u7B3C\u5F0F\u3002`]
2487
+ };
2488
+ }
2489
+ return {
2490
+ ok: false,
2491
+ results: [],
2492
+ errorsEn: [
2493
+ `${codes} drum OCTC is sold for star (Y) points only.`,
2494
+ ...why?.en ?? ["Parameters out of catalogue range (current, Um, step voltage, or positions)."]
2495
+ ],
2496
+ errorsZh: [
2497
+ `${codes} \u9F13\u5F0F\u65E0\u8F7D\u53EA\u7528\u4E8E\u661F\u70B9\uFF08Y\uFF09\u3002`,
2498
+ ...why?.zh ?? ["\u53C2\u6570\u8D85\u51FA\u76EE\u5F55\u8303\u56F4\uFF08\u7535\u6D41\u3001Um\u3001\u7EA7\u7535\u538B\u6216\u6863\u4F4D\u6570\uFF09\u3002"]
2499
+ ]
2500
+ };
2501
+ }
2502
+ }
2503
+ if (why) {
2504
+ return { ok: false, results: [], errorsEn: why.en, errorsZh: why.zh };
2505
+ }
1774
2506
  return {
1775
2507
  ok: false,
1776
2508
  results: [],
@@ -1838,7 +2570,7 @@ function insulationUse(row, need) {
1838
2570
  aLi = 200;
1839
2571
  aPf = 50;
1840
2572
  } else if (row.selectorSize) {
1841
- const ins = INTERNAL_INSULATION[row.selectorSize];
2573
+ const ins = internalInsulation(row.seriesId, row.selectorSize);
1842
2574
  aLi = ins?.a_li ?? 0;
1843
2575
  aPf = ins?.a_pf ?? 0;
1844
2576
  }
@@ -1929,72 +2661,6 @@ function optionsWithInsurance(results, dutyA, stepVoltageV, n = 3, need) {
1929
2661
  return step ? [step].slice(0, n) : [];
1930
2662
  }
1931
2663
 
1932
- // lib/deriveUm.ts
1933
- var RATED_TO_WINDING_UM = {
1934
- 33: 40.5,
1935
- 35: 40.5,
1936
- 66: 72.5,
1937
- 69: 72.5,
1938
- 110: 126,
1939
- 115: 126,
1940
- 132: 145,
1941
- 138: 145,
1942
- 150: 170,
1943
- 220: 252,
1944
- 230: 252,
1945
- 330: 363
1946
- };
1947
- var SNAP_UN = Object.keys(RATED_TO_WINDING_UM).map(Number).sort(
1948
- (a, b) => a - b
1949
- );
1950
- var IEC_UM = [
1951
- 3.6,
1952
- 7.2,
1953
- 12,
1954
- 17.5,
1955
- 24,
1956
- 36,
1957
- 40.5,
1958
- 52,
1959
- 72.5,
1960
- 100,
1961
- 123,
1962
- 145,
1963
- 170,
1964
- 245,
1965
- 300,
1966
- 362,
1967
- 420,
1968
- 550,
1969
- 800
1970
- ];
1971
- var CATALOGUE_UM = [12, 17.5, 40.5, 72.5, 126, 145, 170, 252, 300, 363];
1972
- function nominalSystemKv(ratedKv) {
1973
- let best = ratedKv;
1974
- for (const u of SNAP_UN) {
1975
- if (u <= ratedKv && (ratedKv - u) / ratedKv <= 0.12) best = u;
1976
- }
1977
- return best;
1978
- }
1979
- function iecUmFromRatedKv(ratedKv) {
1980
- if (!(ratedKv > 0)) return NaN;
1981
- const un = nominalSystemKv(ratedKv);
1982
- return IEC_UM.find((u) => u >= un * 1.04) ?? NaN;
1983
- }
1984
- function catalogueUmFromRatedKv(ratedKv) {
1985
- const um = iecUmFromRatedKv(ratedKv);
1986
- if (!Number.isFinite(um)) return NaN;
1987
- return CATALOGUE_UM.find((c) => c >= um - 1e-9) ?? um;
1988
- }
1989
- function maxThroughCurrent(ratedA, minusSteps, stepPercent) {
1990
- if (!(ratedA > 0)) return NaN;
1991
- if (!(minusSteps > 0) || !(stepPercent > 0)) return ratedA;
1992
- const drop = minusSteps * stepPercent;
1993
- if (drop <= 0) return ratedA;
1994
- const denom = 1 - Math.min(drop, 0.45);
1995
- return ratedA / denom;
1996
- }
1997
-
1998
2664
  // lib/transformer.ts
1999
2665
  var TAP_POINTS_FOR = {
2000
2666
  two_winding: ["neutral", "line_end"],
@@ -2013,6 +2679,7 @@ var fail = (zh, en) => ({
2013
2679
  umAssumed: false,
2014
2680
  ratedA: NaN,
2015
2681
  maxA: NaN,
2682
+ maxRule: "full_range",
2016
2683
  dutyA: NaN,
2017
2684
  currentKv: NaN,
2018
2685
  currentDivisor: "sqrt3",
@@ -2022,6 +2689,7 @@ var fail = (zh, en) => ({
2022
2689
  cautionsEn: []
2023
2690
  });
2024
2691
  var NEUTRAL_DEFAULT_UM = 72.5;
2692
+ var NEUTRAL_400KV_UM = 126;
2025
2693
  function deriveDuty(spec) {
2026
2694
  const cautionsZh = [];
2027
2695
  const cautionsEn = [];
@@ -2067,17 +2735,82 @@ function deriveDuty(spec) {
2067
2735
  stepBaseV = spec.tapKv * 1e3 / SQRT3;
2068
2736
  }
2069
2737
  const ratedA = spec.mva > 0 ? spec.mva * 1e3 / ((currentDivisor === "three" ? 3 : SQRT3) * currentKv) : NaN;
2070
- const maxA = spec.stepFraction != null && spec.stepFraction > 0 ? maxThroughCurrent(ratedA, spec.minusSteps, spec.stepFraction) : ratedA;
2738
+ const minusDrop = spec.stepFraction != null && spec.stepFraction > 0 && spec.minusSteps > 0 ? spec.minusSteps * spec.stepFraction : 0;
2739
+ if (minusDrop >= 1) {
2740
+ return fail("\u8D1F\u5206\u63A5\u8303\u56F4 \u2265 100%\u3002", "Minus range \u2265 100%.");
2741
+ }
2742
+ const derivedMaxA = spec.stepFraction != null && spec.stepFraction > 0 ? maxThroughCurrent(ratedA, spec.minusSteps, spec.stepFraction) : ratedA;
2743
+ if (minusDrop > 0.45 && Number.isFinite(derivedMaxA)) {
2744
+ const pct = String(Math.round(minusDrop * 1e3) / 10);
2745
+ cautionsZh.push(`\u8D1F\u5206\u63A5\u8303\u56F4 ${pct}% \u5F02\u5E38\u5927\uFF1A\u6700\u4F4E\u6863\u7535\u6D41 ${fmtA(derivedMaxA)} A\uFF0C\u8BF7\u6838\u5BF9 OS\u3002`);
2746
+ cautionsEn.push(`Minus range ${pct}% is unusually large: lowest-tap current ${fmtA(derivedMaxA)} A, check the OS.`);
2747
+ }
2748
+ let maxA = derivedMaxA;
2749
+ let maxRule = "full_range";
2750
+ const statedMaxA = spec.statedMaxA ?? 0;
2751
+ if (statedMaxA > 0) {
2752
+ maxA = statedMaxA;
2753
+ maxRule = "stated";
2754
+ if (Number.isFinite(ratedA) && statedMaxA < ratedA - 0.05) {
2755
+ maxA = derivedMaxA;
2756
+ maxRule = "full_range";
2757
+ cautionsZh.push(`OS Imax ${fmtA(statedMaxA)} A \u4F4E\u4E8E\u989D\u5B9A ${fmtA(ratedA)} A\uFF1A\u4E0D\u91C7\u7528\uFF0C\u6309\u5168\u8303\u56F4 ${fmtA(derivedMaxA)} A \u9009\uFF0C\u8BF7\u6838\u5BF9 OS\u3002`);
2758
+ cautionsEn.push(`OS Imax ${fmtA(statedMaxA)} A is below the rated ${fmtA(ratedA)} A: not used, sized on the full-range ${fmtA(derivedMaxA)} A. Check the OS.`);
2759
+ } else if (Number.isFinite(derivedMaxA) && statedMaxA < 0.97 * derivedMaxA) {
2760
+ const capPct = ((1 - ratedA / statedMaxA) * 100).toFixed(1);
2761
+ cautionsZh.push(`OS Imax ${fmtA(statedMaxA)} A \u4F4E\u4E8E\u5168\u8303\u56F4 ${fmtA(derivedMaxA)} A\uFF1A\u5382\u5BB6\u5728 \u2212${capPct}% \u4EE5\u4E0B\u9650\u7535\u6D41\uFF08\u6700\u5927\u7535\u6D41\u5206\u63A5\uFF09\u3002\u6309 OS \u503C\u9009\u3002`);
2762
+ cautionsEn.push(`OS Imax ${fmtA(statedMaxA)} A is below the full-range ${fmtA(derivedMaxA)} A: the maker caps the current below \u2212${capPct}% (maximum-current tapping). Sized on the OS figure.`);
2763
+ } else if (Number.isFinite(derivedMaxA) && statedMaxA > 1.25 * derivedMaxA) {
2764
+ cautionsZh.push(`OS Imax ${fmtA(statedMaxA)} A \u8FDC\u9AD8\u4E8E\u5168\u8303\u56F4 ${fmtA(derivedMaxA)} A\uFF1A\u662F\u7EBF\u7535\u6D41\u8FD8\u662F\u6570\u636E\u9519\u8BEF\uFF1F\u6309 OS \u503C\u9009\u3002`);
2765
+ cautionsEn.push(`OS Imax ${fmtA(statedMaxA)} A is far above the full-range ${fmtA(derivedMaxA)} A: line current or a data error? Sized on the OS figure.`);
2766
+ }
2767
+ }
2071
2768
  const k = spec.safetyK > 0 ? spec.safetyK : 1;
2072
- const stepV = spec.stepFraction != null && spec.stepFraction > 0 ? stepBaseV * spec.stepFraction : null;
2769
+ const derivedStepV = spec.stepFraction != null && spec.stepFraction > 0 ? stepBaseV * spec.stepFraction : null;
2770
+ let stepV = derivedStepV;
2771
+ const statedStepV = spec.statedStepV ?? 0;
2772
+ if (statedStepV > 0) {
2773
+ stepV = derivedStepV != null ? Math.max(derivedStepV, statedStepV) : statedStepV;
2774
+ const ratio = derivedStepV != null && derivedStepV > 0 ? statedStepV / derivedStepV : 0;
2775
+ if ((auto || spec.winding === "star") && ratio >= 1.7 && ratio <= 1.76) {
2776
+ cautionsZh.push(`OS Ust ${Math.round(statedStepV)} V \u50CF\u7EBF\u7535\u538B\u503C\uFF1B\u5B9E\u9645\u7EA7\u7535\u538B ${Math.round(derivedStepV)} V\u3002\u6309 OS \u503C\u9009\u3002`);
2777
+ cautionsEn.push(`OS Ust ${Math.round(statedStepV)} V looks like a line value; the physical step is ${Math.round(derivedStepV)} V. Sized on the OS figure.`);
2778
+ } else if (derivedStepV != null && statedStepV < derivedStepV * 0.97) {
2779
+ cautionsZh.push(`OS Ust ${Math.round(statedStepV)} V \u4F4E\u4E8E\u6309\u5BB9\u91CF\u548C\u6863\u8DDD\u7B97\u7684 ${Math.round(derivedStepV)} V\uFF0C\u6309 ${Math.round(derivedStepV)} V \u9009\u3002`);
2780
+ cautionsEn.push(`OS Ust ${Math.round(statedStepV)} V is below the ${Math.round(derivedStepV)} V from the rating and step. Sized on ${Math.round(derivedStepV)} V.`);
2781
+ } else if (
2782
+ // 2026-11-04 final ENGINE-12: --ust 1588 on 110 kV with no step % is
2783
+ // 2.5 % per step, but the lowest tap was sized on the 1.25 % default
2784
+ // (333.3 A on a 350 A switch; 375 A at 2.5 %). A stated Imax decides
2785
+ // the current itself; an auto's extreme tap sits above nominal (D5).
2786
+ derivedStepV != null && statedMaxA <= 0 && ratio > 1.03 && Number.isFinite(ratedA) && !(auto && spec.stepFractionStated)
2787
+ ) {
2788
+ const implied = statedStepV / stepBaseV;
2789
+ const pct = (x) => String(Math.round(x * 1e4) / 100);
2790
+ const ust = Math.round(statedStepV);
2791
+ if (!spec.stepFractionStated && spec.minusSteps * implied < 1) {
2792
+ maxA = Math.max(maxA, maxThroughCurrent(ratedA, spec.minusSteps, implied));
2793
+ cautionsZh.push(`OS Ust ${ust} V \u5373\u6BCF\u7EA7 ${pct(implied)}%\uFF0C\u4E0D\u662F\u9ED8\u8BA4\u7684 ${pct(spec.stepFraction)}%\uFF1A\u6700\u4F4E\u6863\u7535\u6D41\u6309 ${pct(implied)}% \u7B97\u3002`);
2794
+ cautionsEn.push(`OS Ust ${ust} V is ${pct(implied)} % per step, not the ${pct(spec.stepFraction)} % default; lowest tap sized on ${pct(implied)} %.`);
2795
+ } else if (spec.stepFractionStated) {
2796
+ cautionsZh.push(`OS Ust ${ust} V \u5373\u6BCF\u7EA7 ${pct(implied)}%\uFF0C\u4E0E\u7ED9\u5B9A\u7684 ${pct(spec.stepFraction)}% \u4E0D\u7B26\uFF1A\u6700\u4F4E\u6863\u7535\u6D41\u6309 ${pct(spec.stepFraction)}% \u7B97\uFF0C\u8BF7\u6838\u5BF9 OS\u3002`);
2797
+ cautionsEn.push(`OS Ust ${ust} V is ${pct(implied)} % per step, not the stated ${pct(spec.stepFraction)} %; lowest tap sized on ${pct(spec.stepFraction)} %. Check the OS.`);
2798
+ }
2799
+ }
2800
+ }
2073
2801
  let umSystemKv;
2074
2802
  let umKv;
2075
2803
  let umRule;
2076
2804
  let umAssumed = false;
2805
+ let neutralMarket = null;
2077
2806
  if (auto) {
2078
2807
  umSystemKv = spec.hvKv;
2079
2808
  umKv = catalogueUmFromRatedKv(spec.hvKv);
2080
2809
  umRule = "auto_hv";
2810
+ if (spec.tapPoint === "auto_mv_line") {
2811
+ umKv = Math.min(umKv, Math.max(catalogueUmFromRatedKv(spec.mvKv), 170));
2812
+ }
2813
+ umAssumed = true;
2081
2814
  } else if (spec.tapPoint === "neutral") {
2082
2815
  umSystemKv = spec.tapKv;
2083
2816
  const lineClass = catalogueUmFromRatedKv(spec.tapKv);
@@ -2086,20 +2819,49 @@ function deriveDuty(spec) {
2086
2819
  umRule = "neutral_full";
2087
2820
  if (lineClass === 40.5) umAssumed = true;
2088
2821
  } else {
2089
- umKv = NEUTRAL_DEFAULT_UM;
2822
+ umKv = lineClass > 363 ? NEUTRAL_400KV_UM : NEUTRAL_DEFAULT_UM;
2090
2823
  umRule = "neutral_assumed";
2091
2824
  umAssumed = true;
2825
+ const market = (spec.market ?? "").trim().toUpperCase();
2826
+ if (market === "IT" && lineClass <= 252) {
2827
+ umKv = lineClass === 145 ? 170 : lineClass;
2828
+ neutralMarket = "IT";
2829
+ } else if (market === "TR" && lineClass >= 252 && lineClass <= 363) {
2830
+ umKv = 126;
2831
+ neutralMarket = "TR";
2832
+ }
2092
2833
  }
2093
2834
  } else {
2094
2835
  umSystemKv = spec.tapKv;
2095
2836
  umKv = catalogueUmFromRatedKv(spec.tapKv);
2096
2837
  umRule = "line";
2097
2838
  }
2839
+ let ruleUmKv;
2098
2840
  if (spec.earthUmKv != null && spec.earthUmKv > 0) {
2841
+ const floor = umRule === "line" ? umKv : auto ? catalogueUmFromRatedKv(spec.mvKv) : 0;
2842
+ if (spec.earthUmKv < floor - 0.01) {
2843
+ cautionsZh.push(`\u6307\u5B9A Um ${spec.earthUmKv} kV \u4F4E\u4E8E\u8BE5\u70B9\u7CFB\u7EDF Um ${floor} kV\uFF0C\u8BF7\u6838\u5BF9 OS\u3002`);
2844
+ cautionsEn.push(`Stated Um ${spec.earthUmKv} kV is below the system class Um ${floor} kV at this point. Check the OS.`);
2845
+ }
2846
+ ruleUmKv = umKv;
2099
2847
  umKv = spec.earthUmKv;
2100
2848
  umRule = "explicit";
2101
2849
  umAssumed = false;
2102
2850
  }
2851
+ if (auto && spec.tapPoint === "auto_junction" && umRule === "auto_hv" && umKv > 363) {
2852
+ const mvClass = catalogueUmFromRatedKv(spec.mvKv);
2853
+ const open = [72.5, 126, 170, 252, 300, 363].filter((u) => u >= mvClass - 0.01);
2854
+ if (!open.length) {
2855
+ return fail(
2856
+ `\u81EA\u8026\u53D8\u9AD8\u538B Um ${umKv} kV\u3001\u4E2D\u538B Um ${mvClass} kV \u90FD\u8D85\u51FA\u76EE\u5F55\uFF08\u6700\u9AD8 363 kV\uFF09\u3002\u8BF7\u8054\u7CFB\u5DE5\u7A0B\u3002`,
2857
+ `Autotransformer HV class Um ${umKv} kV and MV class Um ${mvClass} kV are both above the catalogue (top 363 kV). Contact engineering.`
2858
+ );
2859
+ }
2860
+ return fail(
2861
+ `\u81EA\u8026\u53D8\u9AD8\u538B Um ${umKv} kV \u8D85\u51FA\u76EE\u5F55\uFF08\u6700\u9AD8 363 kV\uFF09\u3002\u8BF7\u6309 OS \u586B\u5F00\u5173\u5BF9\u5730\u7EDD\u7F18\uFF08CLI\uFF1A--earth-um\uFF09\uFF0C\u53EF\u9009 ${open.join("\u3001")} kV\u3002`,
2862
+ `Autotransformer HV class Um ${umKv} kV is above the catalogue (top 363 kV). Give the switch's insulation to earth from the OS (CLI: --earth-um): ${open.join(", ")} kV.`
2863
+ );
2864
+ }
2103
2865
  if (!Number.isFinite(umKv) || umKv > 363) {
2104
2866
  return fail(
2105
2867
  "\u7535\u538B\u8D85\u51FA\u76EE\u5F55\uFF1A\u5F00\u5173\u6700\u9AD8 Um 363 kV\u3002",
@@ -2107,23 +2869,50 @@ function deriveDuty(spec) {
2107
2869
  );
2108
2870
  }
2109
2871
  if (umRule === "neutral_full" && umAssumed) {
2110
- cautionsZh.push("35 kV \u7EA7\u4E2D\u6027\u70B9\u5148\u6309 Um 40.5 \u9009\uFF1B\u4E0D\u5C11\u8BA2\u5355\uFF08\u4FC4\u7F57\u65AF\u3001\u571F\u8033\u5176\uFF09\u6309 72.5 \u4E70\uFF0C\u4EE5 OS \u4E3A\u51C6\u3002");
2111
- cautionsEn.push("35 kV-class neutral sized at Um 40.5; many orders (Russia, Turkey) bought 72.5. The OS decides.");
2872
+ cautionsZh.push("35 kV \u7EA7\u4E2D\u6027\u70B9\u5148\u6309 Um 40.5 kV \u9009\uFF1B\u4E0D\u5C11\u9879\u76EE\u8981\u6C42 72.5\uFF0C\u4EE5\u8BA2\u8D27\u89C4\u8303\uFF08OS\uFF09\u4E3A\u51C6\u3002CM/CM2/SHZV \u6700\u4F4E\u5C31\u662F 72.5\u3002");
2873
+ cautionsEn.push("35 kV-class neutral sized at Um 40.5 kV; many projects specify 72.5; the order specification (OS) decides. CM/CM2/SHZV start at 72.5.");
2112
2874
  }
2113
2875
  if (umRule === "neutral_assumed") {
2114
- cautionsZh.push(`\u4E2D\u6027\u70B9\u7EDD\u7F18\u672A\u7ED9\uFF0C\u5148\u6309 Um ${NEUTRAL_DEFAULT_UM} \u9009\uFF0C\u4EE5 OS \u4E3A\u51C6\u3002`);
2115
- cautionsEn.push(`Neutral insulation not given: sized at Um ${NEUTRAL_DEFAULT_UM}; the OS decides.`);
2876
+ if (neutralMarket === "IT") {
2877
+ cautionsZh.push(`\u610F\u5927\u5229\u4E2D\u6027\u70B9\u5148\u6309\u7EBF\u7AEF\u7B49\u7EA7 Um ${umKv} kV \u9009\uFF08\u90E8\u5206\u9879\u76EE\u7528 72.5\uFF09\uFF0C\u4EE5\u8BA2\u8D27\u89C4\u8303\uFF08OS\uFF09\u4E3A\u51C6\u3002`);
2878
+ cautionsEn.push(`Italy: neutral sized at the line class, Um ${umKv} kV (some projects use 72.5); the order specification (OS) decides.`);
2879
+ } else if (neutralMarket === "TR") {
2880
+ cautionsZh.push(`\u571F\u8033\u5176 220 kV \u7EA7\u53CA\u4EE5\u4E0A\u4E2D\u6027\u70B9\u5148\u6309 Um ${umKv} kV \u9009\uFF08\u901A\u5E38 126 \u6216 170\uFF0C\u4E0D\u7528 72.5\uFF09\uFF0C\u4EE5\u8BA2\u8D27\u89C4\u8303\uFF08OS\uFF09\u4E3A\u51C6\u3002`);
2881
+ cautionsEn.push(`Turkey: 220 kV-class and above neutral sized at Um ${umKv} kV (126 or 170 is usual, not 72.5); the order specification (OS) decides.`);
2882
+ } else if (umKv === NEUTRAL_400KV_UM) {
2883
+ cautionsZh.push(`400 kV \u7EA7\u7ED5\u7EC4\u4E2D\u6027\u70B9\u5148\u6309 Um ${umKv} kV \u9009\uFF08\u571F\u8033\u5176\u3001\u8461\u8404\u7259\u5E38\u7528 126\uFF1B\u5DF4\u897F 440/500 kV \u5E38\u7528 72.5\uFF09\uFF0C\u4EE5\u8BA2\u8D27\u89C4\u8303\uFF08OS\uFF09\u4E3A\u51C6\u3002`);
2884
+ cautionsEn.push(`Neutral of a 400 kV-class winding sized at Um ${umKv} kV (126 is usual in Turkey and Portugal; 72.5 in Brazil at 440/500 kV); the order specification (OS) decides.`);
2885
+ } else {
2886
+ cautionsZh.push(`\u4E2D\u6027\u70B9\u7EDD\u7F18\u672A\u7ED9\uFF0C\u5148\u6309 Um ${umKv} kV \u9009\uFF0C\u4EE5\u8BA2\u8D27\u89C4\u8303\uFF08OS\uFF09\u4E3A\u51C6\u3002`);
2887
+ cautionsEn.push(`Neutral insulation not given: sized at Um ${umKv} kV; the order specification (OS) decides.`);
2888
+ }
2889
+ }
2890
+ const highWinding = !auto && catalogueUmFromRatedKv(spec.tapKv) >= 252;
2891
+ if (highWinding) {
2892
+ cautionsZh.push("220 kV \u7EA7\u53CA\u4EE5\u4E0A\u8C03\u538B\u7ED5\u7EC4\u53EA\u7528\u7EC4\u5408\u5F0F\u3002");
2893
+ cautionsEn.push("220 kV-class tapped winding: combined types only.");
2116
2894
  }
2117
2895
  if (auto) {
2118
2896
  if (spec.tapPoint === "auto_mv_line" && umRule === "auto_hv") {
2119
- cautionsZh.push("HMR 230/121 kV \u5148\u4F8B\u6309\u5382\u5BB6\u6570\u636E\u7528 Um 170\u3002");
2120
- cautionsEn.push("HMR 230/121 kV orders used Um 170 on the maker's data.");
2121
- } else if (spec.tapPoint === "auto_junction" && umKv === 252 && umRule === "auto_hv") {
2122
- cautionsZh.push("\u5148\u4F8B\uFF1A125 MVA 225/115/35 kV \xB18\xD71.25% \u2192 3\xD7SHZVI-600/252D-10193W\uFF082026-10-27\uFF09\u3002");
2123
- cautionsEn.push("Precedent: 125 MVA 225/115/35 kV \xB18\xD71.25% \u2192 3\xD7SHZVI-600/252D-10193W (27 Oct 2026).");
2897
+ if (umKv === 170) {
2898
+ cautionsZh.push("230/121 kV \u81EA\u8026\u53D8\u4E2D\u538B\u51FA\u7EBF\u901A\u5E38\u7528 Um 170 kV\uFF0C\u8BF7\u6309\u5382\u5BB6\u6570\u636E\u6838\u5BF9\u3002");
2899
+ cautionsEn.push("230/121 kV autotransformer MV line lead: Um 170 kV is usual; check the maker's data.");
2900
+ } else {
2901
+ cautionsZh.push(`\u4E2D\u538B\u51FA\u7EBF\u5148\u6309\u4E2D\u538B\u7B49\u7EA7 Um ${umKv} kV \u9009\uFF0C\u4EE5\u8BA2\u8D27\u89C4\u8303\uFF08OS\uFF09\u4E3A\u51C6\u3002`);
2902
+ cautionsEn.push(`MV line lead sized at the MV class, Um ${umKv} kV; the order specification (OS) decides.`);
2903
+ }
2904
+ } else if (spec.tapPoint === "auto_junction" && umRule === "auto_hv") {
2905
+ cautionsZh.push(`\u81EA\u8026\u53D8\u4E32\u8054-\u516C\u5171\u8FDE\u63A5\u70B9\u5148\u6309\u9AD8\u538B\u7B49\u7EA7 Um ${umKv} kV \u9009\uFF0C\u4EE5\u8BA2\u8D27\u89C4\u8303\uFF08OS\uFF09\u4E3A\u51C6\u3002`);
2906
+ cautionsEn.push(`Autotransformer junction sized at the HV class, Um ${umKv} kV; the order specification (OS) decides.`);
2124
2907
  }
2125
- cautionsZh.push("\u672A\u6838\uFF1A\u8DE8\u8C03\u538B\u7ED5\u7EC4\u51B2\u51FB\uFF08a \u503C\uFF09\u3001\u675F\u7F1A\u7535\u963B\u3002");
2908
+ cautionsZh.push("\u81EA\u8026\u53D8\u53EA\u7528\u7EC4\u5408\u5F0F\uFF08\u590D\u5408\u5F0F\u8DE8\u8C03\u538B\u7ED5\u7EC4\u51B2\u51FB\u4E0A\u9650 200 kV\uFF09\u3002");
2909
+ cautionsEn.push("Autotransformer: combined types only (compound types stop at 200 kV across the tap winding).");
2910
+ cautionsZh.push("\u8FD8\u6CA1\u6838\uFF1A\u8C03\u538B\u7ED5\u7EC4\u4E24\u7AEF\u7684\u51B2\u51FB\u7535\u538B\uFF08a \u503C\uFF09\uFF0C\u4EE5\u53CA\u8981\u4E0D\u8981\u52A0\u7535\u4F4D\u7535\u963B\u3002");
2126
2911
  cautionsEn.push("Not checked: impulse across the tap winding (a), tie-in resistor.");
2912
+ if (!(statedStepV > 0 && statedStepV >= (derivedStepV ?? 0) - 0.5)) {
2913
+ cautionsZh.push("\u53D8\u78C1\u901A\uFF1A\u5404\u6863 Ust \u548C\u7535\u6D41\u4E0D\u540C\uFF0C\u6781\u9650\u6863 Ust \u672A\u6821\u9A8C\u3002\u8BF7\u5411\u5382\u5BB6\u8981\u5206\u63A5\u8868\u3002");
2914
+ cautionsEn.push("Variable flux: Ust and current differ per tap; Ust at the extreme tap is not checked. Get the maker's per-tap table.");
2915
+ }
2127
2916
  }
2128
2917
  return {
2129
2918
  ok: true,
@@ -2132,18 +2921,1003 @@ function deriveDuty(spec) {
2132
2921
  actualUmKv: iecUmFromRatedKv(umSystemKv),
2133
2922
  umKv,
2134
2923
  umRule,
2924
+ ...ruleUmKv != null ? { ruleUmKv } : {},
2135
2925
  umAssumed,
2136
2926
  ratedA,
2137
2927
  maxA,
2928
+ maxRule,
2138
2929
  dutyA: maxA * k,
2139
2930
  currentKv,
2140
2931
  currentDivisor,
2141
2932
  stepV,
2142
- combinedOnly: auto,
2933
+ combinedOnly: auto || highWinding,
2143
2934
  cautionsZh,
2144
2935
  cautionsEn
2145
2936
  };
2146
2937
  }
2938
+ function umChoices(d, spec) {
2939
+ if (!d.ok || d.umRule === "explicit") return [];
2940
+ const ladder = [40.5, 72.5, 126, 170, 252, 300, 363];
2941
+ if (d.umRule === "neutral_assumed" || d.umRule === "neutral_full" && d.umAssumed) {
2942
+ const top = Math.max(catalogueUmFromRatedKv(spec.tapKv), NEUTRAL_DEFAULT_UM);
2943
+ const low = Math.min(d.umKv, NEUTRAL_DEFAULT_UM);
2944
+ return ladder.filter((u) => u >= low - 0.01 && u <= top + 0.01);
2945
+ }
2946
+ if (d.umRule === "auto_hv") {
2947
+ if (spec.tapPoint === "auto_mv_line") {
2948
+ const hv = catalogueUmFromRatedKv(spec.hvKv);
2949
+ const mv = catalogueUmFromRatedKv(spec.mvKv);
2950
+ return ladder.filter((u) => u >= mv - 0.01 && u <= Math.min(hv, 363) + 0.01);
2951
+ }
2952
+ const floor = catalogueUmFromRatedKv(spec.mvKv);
2953
+ return ladder.filter((u) => u >= floor - 0.01 && u <= d.umKv + 0.01);
2954
+ }
2955
+ return [];
2956
+ }
2957
+ function fmtA(a) {
2958
+ return (Math.round(a * 10) / 10).toFixed(1);
2959
+ }
2960
+
2961
+ // lib/nameplate.ts
2962
+ var NOTE_EN = {
2963
+ auto_needs_mv: "autotransformer needs HV and MV kV",
2964
+ auto_tertiary: "range is on the tertiary of an autotransformer",
2965
+ zigzag: "zigzag tapped winding: confirm the tap point",
2966
+ tiny_mva: "power reads {mva} MVA: check the figure",
2967
+ single_phase: "single-phase: {mva} MVA read as one unit, sized as 3 \xD7 {mva} MVA on a single-phase switch",
2968
+ tap_ladder: "{chain} kV read as tap voltages; rated {kv} kV",
2969
+ auto_vg: "text says autotransformer but vector group {vg} has HV and MV in different connections",
2970
+ delta_text: "text mentions delta: confirm which winding is tapped",
2971
+ percent: "{pct} read as +{plus}/\u2212{minus} \xD7 {step} %",
2972
+ percent_positions: "{pos} positions do not match +{plus}/\u2212{minus}",
2973
+ percent_small: "{pct} gives no step count: range not read",
2974
+ zero_range: "range \xB10 ignored",
2975
+ second_range: "{kv} kV {range} is a second tapped winding: used for off-circuit duty",
2976
+ largest_mva: "several ratings: sized on the largest, {mva} MVA",
2977
+ mid_winding: "tap in the middle of the winding: sized as line end; take the insulation to earth from the OS",
2978
+ quantity: "3 \xD7 {mva} MVA read as three three-phase units of {mva} MVA: confirm it is not a single-phase bank",
2979
+ earth_li: "insulation to earth LI {li} kV is not used: set the Um to earth from it",
2980
+ off_circuit_line: "the line names only an off-circuit tap changer: sized as off-circuit (OCTC)"
2981
+ };
2982
+ function lineNoteEn(n) {
2983
+ let s = NOTE_EN[n.key];
2984
+ for (const [k, v] of Object.entries(n.vars ?? {})) s = s.replaceAll(`{${k}}`, String(v));
2985
+ return s;
2986
+ }
2987
+ var NUM = String.raw`\d+(?:\.\d+)?`;
2988
+ function normalizeTenderText(raw) {
2989
+ return raw.replace(
2990
+ /[\uFF01-\uFF5E]/g,
2991
+ (c) => "\uFF0C\uFF1A\uFF1B".includes(c) ? c : String.fromCharCode(c.charCodeAt(0) - 65248)
2992
+ ).replace(/\u3000/g, " ").replace(
2993
+ /\+\s*(\d{1,2})\s*[x×*]\s*(\d+(?:[.,]\d+)?)\s*%\s*[-−–]\s*(\d{1,2})\s*[x×*]\s*\2\s*%/g,
2994
+ (_m, a, st, b) => a === b ? `\xB1${a}x${st}%` : `+${a}/-${b}x${st}%`
2995
+ ).replace(
2996
+ /(?<![\d./])([1-9])\s*\/\s*([2-9]|1[0-6])\s*%/g,
2997
+ (_m, a, b) => `${Math.round(Number(a) / Number(b) * 1e4) / 1e4}%`
2998
+ ).replace(/(?<![А-Яа-яЁё])[мМ][вВ][аА](?![А-Яа-яЁё])/g, "MVA").replace(/(?<![А-Яа-яЁё])[кК][вВ][аА](?![А-Яа-яЁё])/g, "kVA").replace(/(?<![А-Яа-яЁё])[кК][вВ](?![А-Яа-яЁё])/g, "kV").replace(
2999
+ new RegExp("(?<![\\p{L}\\d])[\u0423Y\u0414]\u041D?(?:\\s*\\/\\s*[\u0423Y\u0414]\u041D?)+(?:\\s*-\\s*[\u0414\u0423Y\u041D\\d]{1,2})*(?!\\p{L})", "gu"),
3000
+ (m) => m.replace(/У/g, "Y").replace(/Д/g, "D").replace(/Н/g, "N")
3001
+ ).replace(/[×✕✖*]/g, "x").replace(/(?<=\d\s*)[хХ](?=\s*\d)/g, "x").replace(/(\d)\s*X\s*(?=\d)/g, "$1 x ").replace(
3002
+ /\b[1-9]\d{0,2}(?:\.\d{3})+(?=\s*(?:\/\s*[1-9]\d{0,2}(?:\.\d{3})+\s*)*kVA)/gi,
3003
+ (m) => m.replace(/\./g, "")
3004
+ ).replace(
3005
+ /(\b(?:rated|power|rating|capacity|S[rn])\b[^\d;]{0,20}kVA\s*\)?\s*[:=,]?\s*)(\d{1,3}(?:[,   '’]\d{3})+)(?!\d)/gi,
3006
+ (_m, lead, n) => lead + n.replace(/[,   '’]/g, "")
3007
+ ).replace(
3008
+ /\b\d{1,3}(?:[, \u00A0\u202F'’]\d{3})+(?=\s*(?:\/\s*\d{1,3}(?:[, \u00A0\u202F'’]\d{3})+\s*)*kVA)/gi,
3009
+ (m, offset, s) => {
3010
+ const before = s.slice(Math.max(0, offset - 12), offset);
3011
+ const list = /\d[, \u00A0\u202F'’]\d{3}\s*\/\s*$/.test(before);
3012
+ if (!list && /\d[/.]?\s?$/.test(before) && !/[A-Za-z]\d{1,2}\s$/.test(before)) return m;
3013
+ return m.replace(/[, \u00A0\u202F'’]/g, "");
3014
+ }
3015
+ ).replace(
3016
+ /\b(\d{1,3})[, \u00A0\u202F](\d{3})(?![\d.,])(?=\s*(?:±\s*\d{1,2}(?:\s*x\s*[\d.,]+\s*%)?)?(?:\s*\/\s*\d[\d, \u00A0\u202F.]*?\s*(?:±\s*\d{1,2}(?:\s*x\s*[\d.,]+\s*%)?)?)*\s*V\b)/g,
3017
+ "$1$2"
3018
+ ).replace(/(?<![DdYyNnaZz]\d{0,2})(\d),(\d)/g, "$1.$2").replace(/,/g, ",").replace(/%/g, "%").replace(/[–—-−]/g, "-").replace(/(\d+(?:\.\d+)?)-\1(?=\s*(?:kV|\/))/gi, "$1").replace(
3019
+ /(?<![\w.])(\d+(?:\.\d+)?)\s*[:\-]\s*(\d+(?:\.\d+)?)(?=\s*kV)/gi,
3020
+ (m, a, b) => Number(a) / Number(b) >= 1.5 ? `${a}/${b}` : m
3021
+ ).replace(/\+\s*\/\s*-|\+\s*-(?=\s*\d+(?:\.\d+)?\s*(?:x|steps?\b|taps?\b|positions?\b|%))/g, "\xB1").replace(new RegExp(String.raw`([+\-±])\s*%\s*(${NUM})`, "g"), "$1$2%").replace(new RegExp(String.raw`x\s*%\s*(${NUM})`, "gi"), "x $1%").replace(new RegExp(String.raw`\+\s*(${NUM})\s*%\s*(?:,|\band\b|&)\s*-\s*(${NUM})\s*%`, "gi"), "+$1%/-$2%").replace(new RegExp(String.raw`\bplus\s*(${NUM})\s*%\s*,?\s*(?:and\s+)?minus\s*(${NUM})\s*%`, "gi"), "+$1%/-$2%").replace(
3022
+ new RegExp(String.raw`(?<![\w.%/])-\s*(${NUM})\s*(%?)\s*(?:\/|\bto\b|\.\.\.|…)\s*\+\s*(${NUM})\s*(%?)`, "gi"),
3023
+ // "-5/+10%": a % on either side makes both percent.
3024
+ (m, minus, p1, plus, p2, offset, s) => {
3025
+ const pct = p1 || p2;
3026
+ if (!pct && !/^\s*x\s*\d/i.test(s.slice(offset + m.length, offset + m.length + 12))) return m;
3027
+ return `+${plus}${pct}/-${minus}${pct}`;
3028
+ }
3029
+ ).replace(new RegExp(String.raw`\+\s*(${NUM})\s*%\s*to\s*-`, "gi"), "+$1%/-").replace(
3030
+ new RegExp(String.raw`\+\s*(\d{1,2})\s*x\s*(${NUM})\s*%\s*\/\s*-\s*(\d{1,2})\s*x\s*\2\s*%`, "g"),
3031
+ "+$1/-$3 x $2%"
3032
+ ).replace(
3033
+ new RegExp(String.raw`(?<![\d.+\-±])0(?![\d.])\s*%?\s*(?:\bto\b|\/)\s*-\s*(${NUM})\s*%`, "gi"),
3034
+ "+0%/-$1%"
3035
+ ).replace(new RegExp(String.raw`(?<![\w.%/])-\s*(${NUM})\s*%\s*(?:\bto\b|\/)\s*\+?\s*0(?![\d.])\s*%?`, "gi"), "+0%/-$1%").replace(
3036
+ new RegExp(String.raw`(?<![\w.%/])-\s*(\d{1,2})\s*x\s*(${NUM})\s*%\s*\/\s*\+\s*(\d{1,2})\s*x\s*\2\s*%`, "g"),
3037
+ "+$3/-$1 x $2%"
3038
+ ).replace(
3039
+ new RegExp(String.raw`\+\s*(\d{1,2})\s*x\s*(${NUM})\s*%\s*\/\s*-\s*0(?![\d.])(?:\s*x\s*\2\s*%)?`, "g"),
3040
+ "+$1/-0 x $2%"
3041
+ ).replace(
3042
+ new RegExp(String.raw`\+\s*0(?![\d.])(?:\s*x\s*${NUM}\s*%)?\s*\/\s*-\s*(\d{1,2})\s*x\s*(${NUM})\s*%`, "g"),
3043
+ "+0/-$1 x $2%"
3044
+ ).replace(/\(\s*([±+][^()]{1,30}%)\s*\)/g, " $1 ").replace(/\(\s*(\d+(?:\.\d+)?\s*±[^()]*%)\s*\)/g, "$1").replace(/\s*\/\s*(?:√|sqrt\s*|v)\s*3\b/gi, "").replace(/\s+/g, " ").trim();
3045
+ }
3046
+ function parseVectorGroup(raw) {
3047
+ const text = raw.replace(
3048
+ /\b(?:YN|Yn|Y|D|ZN|Z)(?:(?:yn|y|d|zn|z|a)[0-9Oo]{0,2}){1,3}(?![A-Za-z0-9])/g,
3049
+ (g) => g.replace(/(?<=(?:yn|y|d|zn|z|a)\d?)[Oo]/g, "0")
3050
+ ).replace(/(?<![A-Za-z])Y[oO0](?![A-Za-z0-9])/g, "YN").replace(/[Δ△]/g, "D").replace(/\b(YN|Yn|Y|D|ZN|Z)\s*-\s*(?=(?:yn|y|d|zn|z|YN|Yn|Y|D)\s*\d)/g, "$1").replace(
3051
+ /\b(YN|Y|D|ZN|Z)\s*\/\s*(YN|Y|D|ZN|Z)(?:\s*-\s*(\d{1,2}))?\b/g,
3052
+ (m2, h, l, c) => h + l.toLowerCase() + (c ?? "")
3053
+ ).replace(/\bYn(?=(?:yn|y|d|zn|z|a)\d)/g, "YN").replace(/\b(YN|Y|D|ZN|Z)[,\s/]+(?=(?:yn|y|d|zn|z|a)\d)/g, "$1").replace(/((?:YN|Y|D|ZN|Z)(?:(?:yn|y|d|zn|z|a)\d{1,2})+)[,/]\s*(?=(?:yn|y|d|zn|z|a)\d)/g, "$1").replace(/\b(YN|D|Y|ZN|Z)((?:YN|Yn|Y|D|ZN|Zn|Z|A)\s?\d{1,2})+\b/g, (m2, h) => h + m2.slice(h.length).toLowerCase());
3054
+ const all = [...text.matchAll(/(?:^|[^A-Za-z])((?:YN|Y|D|ZN|Z)(?:(?:yn|y|d|zn|z|a|auto)\d{0,2}){1,3})(?![A-Za-z])/g)];
3055
+ const m = all.find((x) => /\d|n/i.test(x[1].slice(1))) ?? all.find((x) => !/a/.test(x[1].slice(1)));
3056
+ if (!m) {
3057
+ const one = text.match(/(?<![A-Za-z])I([ai])(\d{1,2})(?:i\d{1,2})?(?![A-Za-z\d])/);
3058
+ if (!one) return null;
3059
+ return { group: one[0], windings: one[1] === "a" ? ["a"] : [] };
3060
+ }
3061
+ const group = m[1];
3062
+ const windings = [];
3063
+ const re = /(YN|Y|D|ZN|Z|yn|y|d|zn|z|auto|a)\d{0,2}/g;
3064
+ let t;
3065
+ while (t = re.exec(group)) {
3066
+ const w = t[1].toLowerCase();
3067
+ windings.push(w.startsWith("a") ? "a" : w.startsWith("y") ? "Y" : w.startsWith("d") ? "D" : "Z");
3068
+ }
3069
+ return { group, windings };
3070
+ }
3071
+ var THREE_PHASE = /\bthree[\s-]?phase|\b3[\s-]?ph(?:ase)?\b(?!\s*\d+\s*V\b)|三相/i;
3072
+ var CN_MODEL = /\b(O?[SD][A-Z]*Z[A-Z0-9]*)-(\d{3,7})\/(\d{2,3})\b/;
3073
+ var RU_MODEL = /(?<![А-Яа-яЁёA-Za-z])(А?[ОТ][А-ЯЁ]*)-(\d{3,6})\/(\d{2,3})(?!\d)/u;
3074
+ var THREE_X = new RegExp(String.raw`\b3\s*x\s*(${NUM})\s*MVA`, "i");
3075
+ function parseMva(text, threeUnit = true) {
3076
+ const none = { differ: false, unit: false, bank: false };
3077
+ const grouped = /(?<![\d.])[1-9]\d{0,2}\.\d{3}(?![\d.])(?=\s*kVA)/gi;
3078
+ let misread = false;
3079
+ if (grouped.test(text)) {
3080
+ text = text.replace(grouped, (m) => m.replace(".", ""));
3081
+ misread = true;
3082
+ }
3083
+ const unit = text.match(THREE_X);
3084
+ if (threeUnit && unit && !THREE_PHASE.test(text)) return { ...none, mva: Number(unit[1]), unit: true };
3085
+ const notRating = (i) => {
3086
+ const head = text.slice(Math.max(0, i - 30), i);
3087
+ if (/(?:fault|short[\s-]?circuit|\bs?s\.?c\b)[^;,]{0,30}$/i.test(head)) return true;
3088
+ if (/(?:tertiary|stabili\w*|earthing|auxiliary|\baux\b\.?|station\s+service|feeder|losses?\s+at|\bbase)[^;,]{0,25}$/i.test(head)) {
3089
+ return true;
3090
+ }
3091
+ const g = head.match(/(?:network|system|grid)([^;,\d]{0,30})$/i);
3092
+ return g != null && !/transformer|trafo|\bunit\b/i.test(g[1]);
3093
+ };
3094
+ const read = (unitRe, scale) => [...text.matchAll(new RegExp(String.raw`(${NUM})(?:\s*/\s*${NUM})*\s*${unitRe}`, "gi"))].filter((m) => !notRating(m.index ?? 0)).map((m) => (m[0].match(/\d+(?:\.\d+)?/g) ?? []).map((x) => Number(x) / scale)).filter((g) => g.length && g.every((n) => Number.isFinite(n) && n > 0));
3095
+ const first = [
3096
+ ...text.matchAll(
3097
+ new RegExp(
3098
+ String.raw`\b(?:rated(?:\s+(?:power|rating|capacity))?|power(?:\s+rating)?|rating|capacity|S[rn])\s*(?:\(\s*([Mk])VA\s*\)|,?\s*([Mk])VA)\s*[:=,]?\s*(${NUM}(?:\s*/\s*${NUM})*)(?![\d.])(?!\s*(?:kV|[±+/]\s*\d|±))`,
3099
+ "gi"
3100
+ )
3101
+ )
3102
+ ].map((m) => m[3].split("/").map((x) => Number(x) / (/k/i.test(m[1] ?? m[2] ?? "") ? 1e3 : 1))).filter((g) => g.every((n) => Number.isFinite(n) && n > 0));
3103
+ let all = [...first, ...read(String.raw`MVA(?![a-z])(?!\s*base)`, 1)];
3104
+ if (!all.length) all = read(String.raw`kVA(?![a-z])`, 1e3);
3105
+ if (all.length) {
3106
+ const figs = all.flat();
3107
+ return {
3108
+ mva: Math.max(...figs),
3109
+ differ: new Set(figs).size > 1,
3110
+ unit: false,
3111
+ bank: new RegExp(String.raw`${NUM}\s*[Mk]VA\s*\(?\s*bank\b`, "i").test(text),
3112
+ ...misread ? { misread } : {}
3113
+ };
3114
+ }
3115
+ const cn = text.match(CN_MODEL) ?? text.match(RU_MODEL);
3116
+ if (cn) return { ...none, mva: Number(cn[2]) / 1e3 };
3117
+ return { ...none, mva: null };
3118
+ }
3119
+ var POSITIONS = /(?<![±\d.]\s?)(\d{1,2})\s*(?:positions|pos\b|taps|tappings|kademe|posisi)/i;
3120
+ function nearTolerance(text, index) {
3121
+ return /(?:\bu[kz]\b|\bimpedance|\btoler|偏差|阻抗)/i.test(text.slice(Math.max(0, index - 30), index));
3122
+ }
3123
+ function splitPercentRange(plusPct, minusPct, total) {
3124
+ const a = Math.round(plusPct * 1e3);
3125
+ const b = Math.round(minusPct * 1e3);
3126
+ const span = a + b;
3127
+ if (!(span > 0)) return null;
3128
+ const tries = total ? [total] : Array.from({ length: 19 }, (_, i) => 16 + i);
3129
+ for (const n of tries) {
3130
+ if (span % n) continue;
3131
+ const s = span / n;
3132
+ if (a % s || b % s) continue;
3133
+ return { plus: a / s, minus: b / s, stepPct: s / 1e3 };
3134
+ }
3135
+ return null;
3136
+ }
3137
+ function percentRange(text, pmCount) {
3138
+ const tapWord = (i) => /(?:tapp\w*|OLTC|regulat\w*|range|tap[\s-]?changer|on[\s-]?load)\W{0,4}(?:range\W{0,3})?$/i.test(
3139
+ text.slice(Math.max(0, i - 20), i)
3140
+ );
3141
+ const otherFigure = (i) => nearTolerance(text, i) || /(?:Hz|frequency|variation|\bu[kz]r?\b|%\s*Z\b|\bZ\b|impedance|toler)[^,;]{0,15}$/i.test(text.slice(Math.max(0, i - 15), i));
3142
+ const hits = [
3143
+ ...[...text.matchAll(new RegExp(String.raw`\+\s*(${NUM})\s*%?\s*/?\s*-\s*(${NUM})\s*%`, "g"))].map(
3144
+ (m) => ({ m, plusPct: Number(m[1]), minusPct: Number(m[2]) })
3145
+ ),
3146
+ ...[...text.matchAll(new RegExp(String.raw`±\s*(${NUM})\s*%`, "g"))].map((m) => ({
3147
+ m,
3148
+ plusPct: Number(m[1]),
3149
+ minusPct: Number(m[1])
3150
+ }))
3151
+ ].map((h) => ({ ...h, tap: tapWord(h.m.index ?? 0) })).filter((h) => h.tap || !otherFigure(h.m.index ?? 0)).filter((h) => h.plusPct + h.minusPct > 0 && h.plusPct <= 50 && h.minusPct <= 50).sort((x, y) => Number(y.tap) - Number(x.tap) || (x.m.index ?? 0) - (y.m.index ?? 0));
3152
+ for (let i = 0; i < hits.length; i++) {
3153
+ const r = percentHit(text, hits[i], pmCount);
3154
+ if (r?.unread && i < hits.length - 1) continue;
3155
+ if (r) return r;
3156
+ }
3157
+ return null;
3158
+ }
3159
+ function percentHit(text, h, pmCount) {
3160
+ const { plusPct, minusPct } = h;
3161
+ const index = h.m.index ?? 0;
3162
+ const end = index + h.m[0].length;
3163
+ const pctText = h.m[0].trim();
3164
+ const span = plusPct + minusPct;
3165
+ const nx = text.match(new RegExp(String.raw`(?<![±+\-\d.])(\d{1,2})\s*x\s*(${NUM})\s*%`));
3166
+ const xs = text.match(new RegExp(String.raw`x\s*(${NUM})\s*%`));
3167
+ const stepWord = statedStep(text);
3168
+ const posM = text.match(POSITIONS);
3169
+ const countM = text.slice(end, end + 40).match(/^\s*[,(]?\s*(?:(?:linear|coarse\W*fine|reversing)\s+)?(?:in\s*)?(\d{1,2})\s*(?:steps|级|档)/i);
3170
+ const positions = posM ? Number(posM[1]) : null;
3171
+ let step = null;
3172
+ let total;
3173
+ if (nx) {
3174
+ step = Number(nx[2]);
3175
+ total = Number(nx[1]);
3176
+ } else if (xs) step = Number(xs[1]);
3177
+ else if (stepWord != null) step = stepWord;
3178
+ else if (pmCount && pmCount >= 2 && h.plusPct === h.minusPct && minusPct <= 3 && COMMON_STEPS.some((c) => Math.abs(minusPct - c) <= c * 0.01)) {
3179
+ return { plus: pmCount, minus: pmCount, stepPct: minusPct, index, end, pct: { text: pctText, stated: true } };
3180
+ } else if (pmCount) step = (h.plusPct === h.minusPct ? minusPct : span / 2) / pmCount;
3181
+ else if (positions != null && positions > 2) step = span / (positions - 1);
3182
+ else if (countM) total = Number(countM[1]);
3183
+ let plus;
3184
+ let minus;
3185
+ let stepPct;
3186
+ let stated = true;
3187
+ if (step != null && step > 0 && step <= 10) {
3188
+ plus = Math.round(plusPct / step);
3189
+ minus = Math.round(minusPct / step);
3190
+ stepPct = Math.round(step * 1e4) / 1e4;
3191
+ } else {
3192
+ const split = total ? splitPercentRange(plusPct, minusPct, total) : null;
3193
+ if (split) ({ plus, minus, stepPct } = split);
3194
+ else {
3195
+ if (span <= 10) return { plus: 0, minus: 0, stepPct: null, index, end, unread: pctText };
3196
+ stated = false;
3197
+ const auto = splitPercentRange(plusPct, minusPct);
3198
+ if (auto) ({ plus, minus, stepPct } = auto);
3199
+ else {
3200
+ plus = Math.round(plusPct / 1.25);
3201
+ minus = Math.round(minusPct / 1.25);
3202
+ stepPct = 1.25;
3203
+ }
3204
+ }
3205
+ }
3206
+ if (plus + minus === 0) return null;
3207
+ return { plus, minus, stepPct, index, end, pct: { text: pctText, stated } };
3208
+ }
3209
+ function statedStep(text) {
3210
+ const res = [
3211
+ String.raw`(${NUM})\s*%\s*(?:per\s*step|\/\s*step|each\s+step|steps?)\b`,
3212
+ String.raw`\bsteps?\s+of\s+(${NUM})\s*%`,
3213
+ String.raw`\bstep(?:\s+voltage)?\s*[:=]?\s*(${NUM})\s*%`,
3214
+ String.raw`\bU\s?st\b[^;%]{0,25}?(?:=|\()\s*(${NUM})\s*%`
3215
+ ];
3216
+ for (const re of res) {
3217
+ const m = text.match(new RegExp(re, "i"));
3218
+ const s = m ? Number(m[1]) : NaN;
3219
+ if (s > 0 && s <= 10) return s;
3220
+ }
3221
+ return null;
3222
+ }
3223
+ function countRange(text) {
3224
+ const pos = text.match(/(?<![±+\-\d.]\s?)\b(\d{1,2})\s*(?:positions|tap\s+positions|pos\b|kademe|posisi)/i) ?? text.match(/\bpositions?\s*(?:of\s+)?[:=]?\s*(\d{1,2})\b(?!\s*%)/i) ?? text.match(/\b(?:OLTC|tap\w*|positions?)\s*:?\s*1\s*(?:-|~|…|to)\s*(\d{1,2})\b(?![\d.]*\s*(?:%|kV))/i);
3225
+ const steps = text.match(/(?<![±+\-\d.x]\s?)\b(\d{1,2})\s*steps\b/i);
3226
+ let n = null;
3227
+ let m = null;
3228
+ if (pos && Number(pos[1]) >= 3 && (Number(pos[1]) - 1) % 2 === 0) {
3229
+ n = (Number(pos[1]) - 1) / 2;
3230
+ m = pos;
3231
+ } else if (steps && Number(steps[1]) >= 2 && Number(steps[1]) % 2 === 0) {
3232
+ n = Number(steps[1]) / 2;
3233
+ m = steps;
3234
+ }
3235
+ if (n == null || m == null) return null;
3236
+ const index = m.index ?? 0;
3237
+ return { plus: n, minus: n, stepPct: statedStep(text), index, end: index + m[0].length, guessed: true };
3238
+ }
3239
+ var COMMON_STEPS = [0.625, 0.833, 1, 1.25, 1.5, 1.67, 1.78, 2, 2.5, 3];
3240
+ var STEP_AFTER = new RegExp(
3241
+ String.raw`^\s*(?:(?:steps?|taps?|positions?)\s*)?(of|x|@)?\s*(\()?\s*(${NUM})\s*%\s*(per\s*step|each|steps?\b)?`,
3242
+ "i"
3243
+ );
3244
+ function stepHits(text) {
3245
+ const sym = new RegExp(String.raw`±\s*(\d{1,2})(?![\d.]*\s*%)\s*(?:x\s*(${NUM})\s*%)?`, "g");
3246
+ const asym = new RegExp(
3247
+ String.raw`\+\s*(\d{1,2})(?![\d.]*\s*%)\s*/?\s*-\s*(\d{1,2})(?![\d.]*\s*%)\s*(?:x\s*(${NUM})\s*%)?`,
3248
+ "g"
3249
+ );
3250
+ return [
3251
+ ...[...text.matchAll(sym)].map((m) => ({ m, plus: Number(m[1]), minus: Number(m[1]), step: m[2] })),
3252
+ ...[...text.matchAll(asym)].map((m) => ({ m, plus: Number(m[1]), minus: Number(m[2]), step: m[3] }))
3253
+ ].map((h) => {
3254
+ const index = h.m.index ?? 0;
3255
+ let end = index + h.m[0].length;
3256
+ let stepPct = h.step ? Number(h.step) : null;
3257
+ const a = stepPct == null ? text.slice(end, end + 30).match(STEP_AFTER) : null;
3258
+ if (a) {
3259
+ const s = Number(a[3]);
3260
+ const n = Math.max(h.plus, h.minus);
3261
+ const total = n >= 2 && COMMON_STEPS.some((c) => Math.abs(s / n - c) <= c * 0.01);
3262
+ if (s > 0 && s <= 10 && (a[1] != null || a[4] != null || s <= 5 && !total)) {
3263
+ stepPct = s;
3264
+ end += a[0].length;
3265
+ }
3266
+ }
3267
+ return { plus: h.plus, minus: h.minus, stepPct, index, end };
3268
+ }).filter((h) => h.stepPct != null || !nearTolerance(text, h.index)).sort((x, y) => x.index - y.index);
3269
+ }
3270
+ function findRange(text) {
3271
+ const steps = stepHits(text);
3272
+ const s = steps.find((h) => h.plus + h.minus > 0);
3273
+ if (s && s.stepPct != null) return s;
3274
+ const p = percentRange(text, s && s.plus === s.minus ? s.plus : null);
3275
+ if (p) return p;
3276
+ if (s) return { ...s, stepPct: statedStep(text) };
3277
+ if (!steps.length) return countRange(text);
3278
+ const z = steps[0];
3279
+ return z ? { ...z, stepPct: z.stepPct, zero: true } : null;
3280
+ }
3281
+ var OLTC_WORD = /\bOLTC|on[\s-]?load|有载/gi;
3282
+ var OCTC_WORD = /\bDETC|\bOCTC|\bNLTC|off[\s-]?circuit|de-?energi[sz]ed|无载|无励磁/gi;
3283
+ var ON_LOAD_ANY = /\bOLTC\b|\bon[\s-]?load\b|有载|bajo\s+carga|\bcó\s+tải|\bberbeban\b|yük\s+altında/i;
3284
+ var DRY_TYPE = /\bdry[\s-]?type\b|\bcast[\s-]?resin\b|\bresin[\s-]?(?:cast|encapsulated|insulated)\b|干式|\btransformador(?:es)?\s+(?:tipo\s+)?seco|\bkuru\s+tip|\bmáy\s+biến\s+(?:áp|thế)\s+khô|\btrafo\s+kering|\btransformator\s+kering/i;
3285
+ var OFF_CIRCUIT_TAP = new RegExp(
3286
+ [
3287
+ String.raw`\b(?:DETC|OCTC|NLTC)\b`,
3288
+ String.raw`\b(?:off[\s-]?(?:circuit|load)|no[\s-]?load|de-?energi[sz]ed)\s+tap`,
3289
+ String.raw`\btap[\s-]?chang\w*\s*[(:,-]?\s*(?:off[\s-]?(?:circuit|load)|no[\s-]?load|de-?energi[sz]ed)`,
3290
+ String.raw`(?:conmutador|cambiador)[^,;.]{0,30}(?:sin\s+carga|desenergizad)`,
3291
+ String.raw`(?:chuyển|đổi)\s+nấc[^,;.]{0,20}không\s+tải`,
3292
+ String.raw`(?:pengubah|perubah)\s+tap[^,;.]{0,20}tanpa\s+beban`,
3293
+ String.raw`yüksüz\s+kademe`,
3294
+ "\u65E0\u8F7D",
3295
+ "\u65E0\u52B1\u78C1"
3296
+ ].join("|"),
3297
+ "i"
3298
+ );
3299
+ function dutyTag(text, hits, i) {
3300
+ const h = hits[i];
3301
+ const prevEnd = i > 0 ? hits[i - 1].end : 0;
3302
+ const nextStart = i + 1 < hits.length ? hits[i + 1].index : text.length;
3303
+ const head = text.slice(prevEnd, h.index);
3304
+ const cut = Math.max(head.lastIndexOf(","), head.lastIndexOf(";"), head.lastIndexOf(")"), head.lastIndexOf("("));
3305
+ const before = head.slice(cut + 1);
3306
+ const tailAll = text.slice(h.end, nextStart);
3307
+ const stop = tailAll.search(/[,;)]/);
3308
+ const after = stop < 0 ? tailAll : tailAll.slice(0, stop + 1);
3309
+ let best = null;
3310
+ for (const [re, d] of [[OLTC_WORD, "oltc"], [OCTC_WORD, "octc"]]) {
3311
+ for (const m2 of before.matchAll(re)) {
3312
+ const dist = before.length - ((m2.index ?? 0) + m2[0].length);
3313
+ if (!best || dist < best.dist) best = { d, dist };
3314
+ }
3315
+ const m = after.match(new RegExp(re.source, "i"));
3316
+ if (m && (!best || (m.index ?? 0) < best.dist)) best = { d, dist: m.index ?? 0 };
3317
+ }
3318
+ return best?.d ?? null;
3319
+ }
3320
+ var SIDE = String.raw`(LV|MV|HV|low[\s-]voltage|high[\s-]voltage|secondary)`;
3321
+ function sideIndex(side, n, auto) {
3322
+ const s = side.toLowerCase();
3323
+ if (/^(?:lv|low|secondary)/.test(s)) return n - 1;
3324
+ if (/^mv/.test(s)) return n === 3 || auto ? 1 : null;
3325
+ if (/^(?:hv|high)/.test(s)) return 0;
3326
+ return null;
3327
+ }
3328
+ function sideAfter(text, end) {
3329
+ const tail = text.slice(end, end + 30);
3330
+ const m = tail.match(new RegExp(String.raw`^\s*\(?\s*(?:(?:on|in|at)\s+(?:the\s+)?${SIDE}\b|${SIDE}\s+tapping)`, "i"));
3331
+ if (m) return { side: m[1] ?? m[2] };
3332
+ const k = tail.match(new RegExp(String.raw`^\s*\(?\s*on\s+(?:the\s+)?(${NUM})\s*kV(?![A-Za-z])(?:\s+(?:side|winding))?`, "i"));
3333
+ return k ? { kv: Number(k[1]) } : null;
3334
+ }
3335
+ function sideBefore(text, index) {
3336
+ const head = text.slice(Math.max(0, index - 40), index);
3337
+ const m = head.match(
3338
+ // "HV/LV ±8" names both sides; the trailing LV is not the tapped one.
3339
+ // 2026-11-04 R4: "MV OCTC ±2x2.5%", "MV DETC ±…", "MV off-circuit taps ±…": up to two
3340
+ // duty or tap words between the side and the range (the range went on the HV, 65 % low).
3341
+ new RegExp(
3342
+ String.raw`(?<!\/\s*)\b${SIDE}\s*(?:side\s*)?(?:(?:OLTC|OCTC|DETC|NLTC|off[\s-]?(?:circuit|load)|on[\s-]?load|tap[\s-]?changer|taps?|tapp\w*|regulat\w*|winding)\s*){0,2}[:\-]?\s*$`,
3343
+ "i"
3344
+ )
3345
+ );
3346
+ return m ? { side: m[1] } : null;
3347
+ }
3348
+ function tapWindingFromWords(text, range, kv, auto) {
3349
+ if (kv.length < 2) return null;
3350
+ const at = (w2) => {
3351
+ if (!w2) return null;
3352
+ if (w2.kv != null) return kv.indexOf(w2.kv) >= 0 ? kv.indexOf(w2.kv) : null;
3353
+ return w2.side ? sideIndex(w2.side, kv.length, auto) : null;
3354
+ };
3355
+ const own = range ? at(sideAfter(text, range.end)) ?? at(sideBefore(text, range.index)) : null;
3356
+ if (own != null) return own;
3357
+ const lead = String.raw`(?:OLTC|tapp\w*|regulat\w*|tap[\s-]?changer|on[\s-]?load)[^;.,]{0,25}?`;
3358
+ const m = text.match(
3359
+ new RegExp(
3360
+ String.raw`${lead}\b(?:on|in|at)\s+(?:the\s+)?${SIDE}\b|\((LV|MV) tapping\)|${lead}\b(?:on|in|at)\s+(?:the\s+)?(${NUM})\s*kV(?![A-Za-z])|\btapped\s+winding\s*[:=]?\s*${SIDE}\b|\b(?:OLTC|regulat\w*)\s+(${NUM})\s*kV\s*(?=±|\+)`,
3361
+ "i"
3362
+ )
3363
+ );
3364
+ if (m) {
3365
+ const k = m[3] ?? m[5];
3366
+ return at(k != null ? { kv: Number(k) } : { side: m[1] ?? m[2] ?? m[4] });
3367
+ }
3368
+ const site = text.match(
3369
+ new RegExp(
3370
+ String.raw`\b(?:on|at|in)\s+(?:the\s+)?(${NUM})\s*kV\s+(?:line[\s-]?end|side|terminals?)\b(?!\s*(?:LI|BIL|AC|insulation|[:=]?\s*\d))` + String.raw`|\bfor\s+(${NUM})\s*kV\s+(?:voltage\s+)?variation` + String.raw`|\b(IV|intermediate[\s-]voltage)\s+(?:line[\s-]?end|side|terminals?)\b` + String.raw`|\b(?:at|on)\s+(?:the\s+)?(LV|low[\s-]voltage)\s+(?:transformer\s+)?terminals?\b`,
3371
+ "i"
3372
+ )
3373
+ );
3374
+ if (site) {
3375
+ const k = site[1] ?? site[2];
3376
+ if (k != null) return at({ kv: Number(k) });
3377
+ return at({ side: site[3] ? "MV" : "LV" });
3378
+ }
3379
+ const cn = text.match(/([低中高])压侧(?:有载)?(?:调压|分接)|(?:调压|分接)[^,;,;]{0,6}?([低中高])压侧/);
3380
+ if (!cn) return null;
3381
+ const w = cn[1] ?? cn[2];
3382
+ return w === "\u4F4E" ? kv.length - 1 : w === "\u9AD8" ? 0 : kv.length === 3 || auto ? 1 : null;
3383
+ }
3384
+ var DUTY_TAG = String.raw`(?:\s*\(\s*(OLTC|OCTC|DETC|NLTC|on[\s-]?load|off[\s-]?circuit)\s*\))?`;
3385
+ var RANGE_AT_START = new RegExp(
3386
+ String.raw`^\s*(?:±\s*(\d{1,2})|\+\s*(\d{1,2})\s*/?\s*-\s*(\d{1,2}))(?![\d.]*\s*%)\s*(?:x\s*(${NUM})\s*%)?`
3387
+ );
3388
+ var NOT_WINDING = /\b(?:BIL|LIWL|LI|SIL|AC|Um|insulation|withstand|impulse|lightning|switching|power[\s-]?frequency|test|applied|induced|highest|max(?:imum)?\.?(?:\s+system)?|equipment)\b[^\d]{0,20}$/i;
3389
+ var AFTER_LABEL = /^\s*(?:kV\s*)?(?:BIL|LIWL|LI|SIL|Um|impulse|lightning|power[\s-]?frequency|withstand|test)\b(?![^,;\d]{0,30}\d)/i;
3390
+ var UN_UM = { 11: 12, 33: 36, 66: 72.5, 110: 123, 132: 145, 150: 170, 220: 245, 230: 245 };
3391
+ function clauseBefore(text, at) {
3392
+ return text.slice(Math.max(0, at - 30), at).split(/[,;]|\)(?=\s*[A-Za-z])/).pop() ?? "";
3393
+ }
3394
+ function inInsulationList(text, at) {
3395
+ const clauses = text.slice(0, at).split(/[,;]/);
3396
+ for (let i = clauses.length - 1; i >= 0; i--) {
3397
+ const c = clauses[i];
3398
+ if (i === clauses.length - 1 && /^\s*(?:HV|MV|LV)\s*\/\s*(?:MV|LV)\b/i.test(c)) return false;
3399
+ if (/^\s*(?:insulation|LI\b|LIWL|BIL|AC\b|test|withstand|impulse|lightning)/i.test(c)) return true;
3400
+ if (!/^\s*(?:HV|MV|LV|HVN|N|neutral|tertiary|line[\s-]?end)\b/i.test(c)) return false;
3401
+ }
3402
+ return false;
3403
+ }
3404
+ function findVoltages(text, range, lone) {
3405
+ if (range) {
3406
+ const before = text.slice(0, range.index);
3407
+ const after = text.slice(range.end);
3408
+ const continues = new RegExp(String.raw`^${DUTY_TAG}\s*(?:kV)?\s*/\s*${NUM}`, "i").test(after);
3409
+ const own = before.match(
3410
+ new RegExp(continues ? String.raw`(${NUM})\s*(?:kV)?\s*$` : String.raw`(${NUM})\s*$`, "i")
3411
+ );
3412
+ if (own) {
3413
+ const left = [];
3414
+ let head = before.slice(0, own.index);
3415
+ for (; ; ) {
3416
+ const m = head.match(new RegExp(String.raw`(${NUM})\s*(?:kV)?\s*/\s*$`, "i"));
3417
+ if (!m) break;
3418
+ left.unshift(Number(m[1]));
3419
+ head = head.slice(0, m.index);
3420
+ }
3421
+ const right = [];
3422
+ const extra = [];
3423
+ let tail = after;
3424
+ for (; ; ) {
3425
+ const m = tail.match(new RegExp(String.raw`^${DUTY_TAG}\s*(?:kV)?\s*/\s*(${NUM})`, "i"));
3426
+ if (!m) break;
3427
+ right.push(Number(m[2]));
3428
+ tail = tail.slice(m[0].length);
3429
+ const r = tail.match(RANGE_AT_START);
3430
+ if (r) {
3431
+ const plus = Number(r[1] ?? r[2]);
3432
+ const minus = Number(r[1] ?? r[3]);
3433
+ tail = tail.slice(r[0].length);
3434
+ const tag = tail.match(new RegExp(String.raw`^${DUTY_TAG}`, "i"))?.[1];
3435
+ if (plus + minus > 0) {
3436
+ extra.push({
3437
+ at: left.length + right.length,
3438
+ plus,
3439
+ minus,
3440
+ stepPct: r[4] ? Number(r[4]) : null,
3441
+ ...tag && new RegExp(OCTC_WORD.source, "i").test(tag) ? { offCircuit: true } : {}
3442
+ });
3443
+ }
3444
+ }
3445
+ }
3446
+ let kv2 = [...left, Number(own[1]), ...right];
3447
+ if (/^\s*V\b/.test(tail) && kv2.some((n) => n > 1200)) kv2 = kv2.map((n) => n / 1e3);
3448
+ else if (/^\s*V\b/.test(tail) && /kV/i.test(own[0]) && right.length) {
3449
+ kv2 = [...left, Number(own[1]), ...right.map((n) => n / 1e3)];
3450
+ }
3451
+ const standalone = !continues && left.length > 0 && /\s$/.test(own[0]);
3452
+ if (kv2.length >= 2) return { kv: kv2, tapIndex: standalone ? null : left.length, extra };
3453
+ }
3454
+ }
3455
+ const chains = [
3456
+ ...text.matchAll(new RegExp(String.raw`(${NUM}(?:\s*(?:kV)?\s*/\s*${NUM}){1,2})\s*kV(?![Ap])`, "gi"))
3457
+ ].filter((m) => !/[%x]\s*$/i.test(text.slice(Math.max(0, (m.index ?? 0) - 2), m.index ?? 0))).map((m) => {
3458
+ const head = text.slice(Math.max(0, (m.index ?? 0) - 30), m.index ?? 0);
3459
+ const at = m.index ?? 0;
3460
+ const end = at + m[0].length;
3461
+ const c = m[1].split("/").map((x) => Number(x.replace(/kV/i, "").trim()));
3462
+ const unUm = c.length === 2 && (UN_UM[c[0]] === c[1] || /^\s*\(?\s*(?:U[nr]\s*\/\s*)?Um\b(?!\s*[:=]?\s*\d)/i.test(text.slice(end, end + 12)));
3463
+ return {
3464
+ c: unUm ? [c[0]] : c,
3465
+ at,
3466
+ end,
3467
+ unUm,
3468
+ // A ratio word before it, or the range right beside it, names the ratio.
3469
+ // 2026-11-04 R4: "voltage 132/33 kV" after an insulation list is the ratio too.
3470
+ ratio: /(?:ratio|rated\s+voltage|nominal|\bU[rn]\b|(?<!(?:test|impulse|highest|max\w*|system)\s+)\bvoltages?\b)[^\d]{0,20}$/i.test(head),
3471
+ near: range != null && (/^\s*$/.test(text.slice(end, range.index)) || /^\s*$/.test(text.slice(range.end, at)))
3472
+ };
3473
+ }).filter(
3474
+ (x) => x.unUm || !NOT_WINDING.test(clauseBefore(text, x.at)) && !AFTER_LABEL.test(text.slice(x.end, x.end + 50)) && !inInsulationList(text, x.at)
3475
+ ).filter((x) => x.c.every((n) => n > 0.2 && n < 1200));
3476
+ if (chains.length) {
3477
+ chains.sort(
3478
+ (a, b) => Number(b.ratio) - Number(a.ratio) || Number(b.near) - Number(a.near) || b.c.length - a.c.length || a.at - b.at
3479
+ );
3480
+ return { kv: chains[0].c, tapIndex: null, extra: [] };
3481
+ }
3482
+ const cn = text.match(CN_MODEL) ?? text.match(RU_MODEL);
3483
+ if (cn) return { kv: [Number(cn[3])], tapIndex: null, extra: [] };
3484
+ if (!lone) return { kv: [], tapIndex: null, extra: [] };
3485
+ const hits = [...text.matchAll(new RegExp(String.raw`(?<![A-Za-z/\d.])(${NUM})\s*(?:±[^,;/]{0,25}?%\s*)?kV(?![Ap])`, "gi"))].map((m) => ({ kv: Number(m[1]), index: m.index ?? 0, end: (m.index ?? 0) + m[0].length })).filter((h) => h.kv > 0.2 && h.kv < 1200).filter((h) => {
3486
+ const head = clauseBefore(text, h.index);
3487
+ return !NOT_WINDING.test(head) && !/\bneutral\b[^\d]{0,20}$/i.test(head) && !AFTER_LABEL.test(text.slice(h.end, h.end + 50));
3488
+ });
3489
+ const kv = [...new Set(hits.map((h) => h.kv))].sort((a, b) => b - a);
3490
+ if (!kv.length || kv.length > 3) return { kv: [], tapIndex: null, extra: [] };
3491
+ const direct = range ? hits.find(
3492
+ (h, i) => (
3493
+ // "132±10x1.25% kV": the range inside the figure is its own.
3494
+ h.index < range.index && h.end >= range.end || h.end <= range.index && /^\s*$/.test(text.slice(h.end, range.index)) && !(i > 0 && /^\s*\/\s*$/.test(text.slice(hits[i - 1].end, h.index)))
3495
+ )
3496
+ ) : void 0;
3497
+ const written = [...new Set(hits.map((h) => h.kv))];
3498
+ const reordered = written.some((k, i) => kv[i] !== k);
3499
+ return { kv, tapIndex: direct ? kv.indexOf(direct.kv) : null, extra: [], ...reordered ? { reordered } : {} };
3500
+ }
3501
+ function autoText(text) {
3502
+ if (/\bauto[\s-]?(?:transformers?|trafo|TR)\b|\bautotrafo|自耦/i.test(text) || // 2026-11-04 R3: Spanish, French, German, Russian, Vietnamese and Turkish words.
3503
+ /\bautotransforma(?:dor|teur|tor)\w*|автотрансформатор|\btự\s*ngẫu|\boto[\s-]?(?:trafo|transformat)\w*/i.test(text) || /\bauto\b(?!\s*[/)]|[\s-]*(?:control|mode|operation|start|reclos|tap|voltage|changeover|transfer|reset|cooling|fan|pump|manual|AVR))(?<!(?:manual|hand|\(|AVR)\s*\/?\s*auto)/i.test(text) || // 2026-11-04 R2: PLN "IBT" and the Rosseti АТДЦТН / АОДЦТН models were two-winding.
3504
+ /\bIBT\b|\b[Ii]nter[\s-]?bus\s+transformer/.test(text) || /(?<![А-ЯЁа-яё])А[ОТ]Д[А-ЯЁ]*-\d/u.test(text) || /\bA[OT]D[A-Z]*-\d|\bO[SD][A-Z]*Z[A-Z0-9]*-\d/.test(text)) {
3505
+ return "word";
3506
+ }
3507
+ return /\bAT-?\d{1,2}\b|\bAT\s+\d+(?:\.\d+)?\s*MVA/.test(text) ? "at" : null;
3508
+ }
3509
+ var DELTA_TAP = /(?:regulat\w*|tapp\w*|OLTC)\b(?:(?!\b(?:LV|MV|secondary|tertiary|low[\s-]voltage)\b)[^;.]){0,40}\bdelta\b|\bHV\b[\s:]*(?:winding\s*)?(?:is\s*)?delta\b|\bHV\b\s*[:=]\s*D\b|\bdelta[\s-]connected\s+HV\b|\bdelta[\s/-]*star\b|(?<!\b(?:LV|MV|secondary|tertiary)\b[\s:]*)\bD[\s-]?connection\b|三角形调压|角接调压/i;
3510
+ var DELTA_OTHER = /\b(?:LV|MV|tertiary|secondary|stabili[sz]ing|low[\s-]voltage)\b(?:(?!\bHV\b|\bstar\b)[^;.,]){0,25}\b(?:delta|D[\s-]?connect)|\bdelta\s+(?:tertiary|stabili)|star\s*\/\s*delta/i;
3511
+ var STAR_TAP = /(?:regulat\w*|tapp\w*|OLTC|tap[\s-]?changer)[^;.,]{0,40}?(?<!\b(?:LV|MV|secondary|tertiary|kV)\s+)(?<!\bnot\s+(?:in|at)?\s*(?:the\s+)?)\b(?:star[\s-]?point|neutral)\b(?![\s-]*(?:point\s+)?(?:is\s+)?(?:solidly\s+)?(?:earthed|grounded))|(?<!\b(?:LV|MV|secondary|tertiary|kV)\s+)\bstar neutral\b(?![\s-]*(?:point\s+)?(?:is\s+)?(?:solidly\s+)?(?:earthed|grounded))|\bneutral[\s-]end\s+(?:tapp\w*|regulat\w*|OLTC)|(?<!\bnot\s+)\bin neutral\b|中性点调压/i;
3512
+ var MID_WINDING = /(?:middle|(?:electrical\s+)?cent(?:re|er))\s+of\s+(?:the\s+)?(?:(?:HV|higher|high[\s-]voltage|primary)\s+)?winding|mid[\s-]winding/i;
3513
+ function lineEndTap(text) {
3514
+ for (const m of text.matchAll(/line[\s-]?end|线端/gi)) {
3515
+ const at = m.index ?? 0;
3516
+ const head = text.slice(Math.max(0, at - 25), at);
3517
+ const clause = head.slice(Math.max(head.lastIndexOf(","), head.lastIndexOf(";")) + 1);
3518
+ const after = text.slice(at + m[0].length, at + m[0].length + 12);
3519
+ if (/\b(?:LI|BIL|LIWL|SIL|AC)\b|insulation|withstand|绝缘/i.test(clause)) continue;
3520
+ if (/^\s*(?:\/|\d|LI\b|BIL\b|AC\b|:)/i.test(after)) continue;
3521
+ return true;
3522
+ }
3523
+ return false;
3524
+ }
3525
+ function parseTenderLine(raw) {
3526
+ const text = normalizeTenderText(raw);
3527
+ if (!text) return null;
3528
+ const vg = parseVectorGroup(text);
3529
+ const windings = vg?.windings ?? [];
3530
+ const notes = [];
3531
+ const autoWord = autoText(text);
3532
+ const contradicts = vg != null && windings.length >= 2 && windings[0] !== windings[1];
3533
+ const auto = windings.includes("a") || autoWord != null && !contradicts;
3534
+ if (autoWord != null && contradicts && !windings.includes("a")) {
3535
+ notes.push({ key: "auto_vg", vars: { vg: vg.group } });
3536
+ }
3537
+ let range = findRange(text);
3538
+ let found = findVoltages(text, range?.guessed ? null : range, !auto);
3539
+ const apart = [];
3540
+ const stated = stepHits(text).filter((h) => h.plus + h.minus > 0 && h.stepPct != null).filter((h, i, a) => a.findIndex((o) => o.plus === h.plus && o.minus === h.minus && o.stepPct === h.stepPct) === i);
3541
+ if (!found.extra.length && stated.length >= 2 && range && range.stepPct != null && !range.pct) {
3542
+ const tags = stated.map((_, i) => dutyTag(text, stated, i));
3543
+ const on = stated.filter((_, i) => tags[i] === "oltc");
3544
+ const notOff = stated.filter((_, i) => tags[i] !== "octc");
3545
+ const pool = on.length ? on : notOff.length ? notOff : stated;
3546
+ const main2 = pool.reduce((x, y) => y.plus + y.minus > x.plus + x.minus ? y : x);
3547
+ const siteOf = (h) => {
3548
+ const head = text.slice(0, h.index);
3549
+ const k = head.match(new RegExp(String.raw`(?<![A-Za-z/\d.])(${NUM})(?:\s*kV)?\s*$`, "i"));
3550
+ if (k && !/\/\s*$/.test(head.slice(0, k.index))) return { kv: Number(k[1]) };
3551
+ const zh = head.match(/([高中低])压侧?(?:有载|无载)?(?:调压)?\s*$/);
3552
+ if (zh) return { side: zh[1] === "\u9AD8" ? "HV" : zh[1] === "\u4E2D" ? "MV" : "LV" };
3553
+ return sideAfter(text, h.end) ?? sideBefore(text, h.index);
3554
+ };
3555
+ stated.forEach((h, i) => {
3556
+ if (h !== main2) apart.push({ hit: h, offCircuit: tags[i] === "octc", site: siteOf(h) });
3557
+ });
3558
+ if (main2.index !== range.index) {
3559
+ range = main2;
3560
+ found = findVoltages(text, range, !auto);
3561
+ }
3562
+ }
3563
+ let kv = found.kv;
3564
+ const rangeIndex = found.tapIndex;
3565
+ const singleWord = [
3566
+ ...text.matchAll(
3567
+ new RegExp(
3568
+ String.raw`single[\s-]?phase|single[\s-]?ph\b|\b1[\s-]?ph(?:ase)?\b|\b1\s*pha\b|\b(?:1|satu)\s*fasa\b|monof[aá]sic[a-z]*|monophas[a-zéè]*|einphas[a-z]*|однофазн[а-яё]*|\b1\s*[ØΦφ]|(?<=[MkМк][VВ][AА]\s*)per\s+phase\b(?!\s+(?:impedance|reactance|resistance|loss))|单相(?!电源|供电|交流)|\bbank of 3\b`,
3569
+ "gi"
3570
+ )
3571
+ )
3572
+ ].some((m) => {
3573
+ const i = m.index ?? 0;
3574
+ const after = text.slice(i + m[0].length, i + m[0].length + 14);
3575
+ const before = text.slice(Math.max(0, i - 25), i);
3576
+ if (/^\W{0,3}(?:\d+\s*V\b|supply|aux|control|motor|fault|short|earth|to\b|auto[\s-]?reclos|reclos|trip)/i.test(after)) {
3577
+ return false;
3578
+ }
3579
+ if (/(?:aux\w*|supply|control|motor|heater|fault|short[\s-]?circuit|\d+\s*V)\W*$/i.test(before)) return false;
3580
+ return !/^bank/i.test(m[0]) || !THREE_PHASE.test(text);
3581
+ });
3582
+ const singleModel = /\bO?D[A-Z]*Z[A-Z0-9]*-\d{3,7}\/\d/.test(text) || /(?<![А-ЯЁа-яё])АО[А-ЯЁ]*-\d/u.test(text) || /(?<![А-ЯЁа-яё])О(?!ПН)[А-ЯЁ]*-\d{3,6}\/\d/u.test(text) || /\bAOD[A-Z]*-\d/.test(text);
3583
+ const rootThree = /\/\s*(?:√|sqrt\s*|v)\s*3\b/i.test(raw) && !THREE_PHASE.test(text);
3584
+ const singleGroup = vg != null && /^I/.test(vg.group);
3585
+ const singleSign = singleWord || singleModel || rootThree || singleGroup;
3586
+ const threeUnit = singleSign || /\bbank\b/i.test(text) || kv.length > 0 && Math.max(...kv) >= 220;
3587
+ const mvaRead = parseMva(text, threeUnit);
3588
+ let mva = mvaRead.mva;
3589
+ if (!kv.length && mva == null && !range && !vg) return null;
3590
+ const assumed = [];
3591
+ if (!vg && autoWord !== "word") assumed.push("kind");
3592
+ const mvaSign = /\d\s*[Mk]VA|[Mk]VA\W{0,6}\d/i.test(text) || CN_MODEL.test(text) || RU_MODEL.test(text);
3593
+ if (mva == null || mvaRead.misread || !mvaSign) assumed.push("mva");
3594
+ if (mvaRead.differ && mva != null) notes.push({ key: "largest_mva", vars: { mva } });
3595
+ const threeX = text.match(THREE_X);
3596
+ if (!threeUnit && threeX && !THREE_PHASE.test(text) && mva != null) notes.push({ key: "quantity", vars: { mva } });
3597
+ const real = range && !range.zero && !range.unread ? range : null;
3598
+ if (!real || real.pct && !real.pct.stated || real.guessed) assumed.push("range");
3599
+ if (range?.zero) notes.push({ key: "zero_range" });
3600
+ if (range?.unread) notes.push({ key: "percent_small", vars: { pct: range.unread } });
3601
+ if (real?.pct) {
3602
+ if (!real.pct.stated) {
3603
+ notes.push({
3604
+ key: "percent",
3605
+ vars: { pct: real.pct.text, plus: real.plus, minus: real.minus, step: real.stepPct ?? 1.25 }
3606
+ });
3607
+ }
3608
+ const pos = text.match(POSITIONS);
3609
+ if (pos && Number(pos[1]) !== real.plus + real.minus + 1) {
3610
+ notes.push({ key: "percent_positions", vars: { pos: pos[1], plus: real.plus, minus: real.minus } });
3611
+ }
3612
+ }
3613
+ if (!auto && kv.length === 3 && real && rangeIndex == null) {
3614
+ const sorted = [...kv].sort((a, b) => b - a);
3615
+ if (sorted[0] / sorted[2] <= 1.35) {
3616
+ notes.push({ key: "tap_ladder", vars: { chain: kv.join("/"), kv: sorted[1] } });
3617
+ kv = [sorted[1]];
3618
+ }
3619
+ }
3620
+ const flipped = kv.length > 1 && kv[0] < kv[kv.length - 1];
3621
+ const voltagesKv = flipped ? [...kv].reverse() : kv;
3622
+ const at = (i) => flipped ? kv.length - 1 - i : i;
3623
+ let tapIndex = rangeIndex != null ? at(rangeIndex) : null;
3624
+ if (tapIndex != null && range?.pct && voltagesKv.length > 1) {
3625
+ const named = tapWindingFromWords(text, range, voltagesKv, auto);
3626
+ if (named != null) tapIndex = named;
3627
+ }
3628
+ if (tapIndex == null && voltagesKv.length) {
3629
+ tapIndex = tapWindingFromWords(text, range, voltagesKv, auto);
3630
+ if (tapIndex == null) {
3631
+ tapIndex = 0;
3632
+ assumed.push("tap_winding");
3633
+ }
3634
+ }
3635
+ let main = real && tapIndex != null ? { tapIndex, plus: real.plus, minus: real.minus, stepPct: real.stepPct } : null;
3636
+ const others = found.extra.filter((e) => e.at < kv.length).map((e) => ({
3637
+ tapIndex: at(e.at),
3638
+ plus: e.plus,
3639
+ minus: e.minus,
3640
+ stepPct: e.stepPct,
3641
+ ...e.offCircuit ? { offCircuit: true } : {}
3642
+ }));
3643
+ if (main && others.length) {
3644
+ const all = [main, ...others];
3645
+ const big = all.reduce((x, y) => y.plus + y.minus > x.plus + x.minus ? y : x);
3646
+ main = big;
3647
+ others.splice(0, others.length, ...all.filter((r) => r !== big));
3648
+ tapIndex = big.tapIndex;
3649
+ }
3650
+ if (main) {
3651
+ for (const a of apart) {
3652
+ let ti = null;
3653
+ if (a.site?.kv != null) ti = voltagesKv.indexOf(a.site.kv) >= 0 ? voltagesKv.indexOf(a.site.kv) : null;
3654
+ else if (a.site?.side) ti = sideIndex(a.site.side, voltagesKv.length, auto);
3655
+ others.push({
3656
+ tapIndex: ti ?? main.tapIndex,
3657
+ plus: a.hit.plus,
3658
+ minus: a.hit.minus,
3659
+ stepPct: a.hit.stepPct,
3660
+ offCircuit: a.offCircuit,
3661
+ kvAssumed: ti == null
3662
+ });
3663
+ }
3664
+ }
3665
+ const starTap = STAR_TAP.test(text);
3666
+ const lineEnd = !starTap && lineEndTap(text);
3667
+ const midWinding = !starTap && !lineEnd && MID_WINDING.test(text);
3668
+ const orderGuess = flipped || found.reordered === true;
3669
+ const pointAt = (i) => {
3670
+ let letter = i != null ? windings[i] : void 0;
3671
+ let winding = "star";
3672
+ let tapPoint = "neutral";
3673
+ let windingAssumed = false;
3674
+ let tapPointAssumed = false;
3675
+ let deltaText = false;
3676
+ let mid = false;
3677
+ if (letter == null) {
3678
+ if (DELTA_TAP.test(text) && !DELTA_OTHER.test(text)) letter = "D";
3679
+ else if (starTap) letter = "Y";
3680
+ else if (/\bdelta\b|三角形|角接/i.test(text)) deltaText = true;
3681
+ }
3682
+ if (letter === "D") {
3683
+ winding = "delta";
3684
+ tapPoint = "line_end";
3685
+ } else if (letter === "Y" || letter == null && (lineEnd || midWinding)) {
3686
+ if (letter == null) windingAssumed = true;
3687
+ if (lineEnd || midWinding) {
3688
+ tapPoint = "line_end";
3689
+ mid = midWinding;
3690
+ } else if (!starTap) tapPointAssumed = true;
3691
+ } else {
3692
+ windingAssumed = true;
3693
+ tapPointAssumed = true;
3694
+ }
3695
+ if (i != null && windings[i] != null && orderGuess) {
3696
+ windingAssumed = true;
3697
+ if (!starTap && !lineEnd && !midWinding) tapPointAssumed = true;
3698
+ }
3699
+ return { winding, tapPoint, windingAssumed, tapPointAssumed, zigzag: letter === "Z", deltaText, mid };
3700
+ };
3701
+ const otherRanges = auto ? [] : others.map((r) => {
3702
+ const p2 = pointAt(r.tapIndex);
3703
+ return {
3704
+ ...r,
3705
+ kv: voltagesKv[r.tapIndex],
3706
+ winding: p2.winding,
3707
+ tapPoint: p2.tapPoint,
3708
+ windingAssumed: p2.windingAssumed,
3709
+ tapPointAssumed: p2.tapPointAssumed
3710
+ };
3711
+ });
3712
+ for (const r of otherRanges) {
3713
+ const pm = r.plus === r.minus ? `\xB1${r.plus}` : `+${r.plus}/\u2212${r.minus}`;
3714
+ notes.push({ key: "second_range", vars: { kv: r.kv, range: `${pm}${r.stepPct ? ` \xD7 ${r.stepPct} %` : ""}` } });
3715
+ }
3716
+ const phases = mvaRead.unit || singleSign ? "I" : null;
3717
+ if (phases && mvaRead.bank && mva != null) mva = Math.round(mva / 3 * 1e3) / 1e3;
3718
+ if (phases && mva != null) notes.push({ key: "single_phase", vars: { mva } });
3719
+ const topKv = voltagesKv.length ? Math.max(...voltagesKv) : 0;
3720
+ if (mva != null && (mva < 0.2 || mva < 1 && topKv >= 33)) notes.push({ key: "tiny_mva", vars: { mva } });
3721
+ const neutralBilKv = parseNeutralBil(text);
3722
+ const earthLi = text.match(/\bto\s+(?:earth|ground)\b[^;]{0,25}?\b(?:LI|BIL|LIWL)\s*[:=]?\s*(\d{2,4})/i);
3723
+ if (earthLi && neutralBilKv == null) notes.push({ key: "earth_li", vars: { li: Number(earthLi[1]) } });
3724
+ const regulation = /coarse[\s/-]*fine|粗细调/i.test(text) ? "coarse_fine" : /(?<!non[\s-]?)\blinear\b|线性调/i.test(text) ? "linear" : /\brevers|正反调/i.test(text) ? "reversing" : null;
3725
+ const allTags = stated.map((_, i) => dutyTag(text, stated, i));
3726
+ const offCircuitOnly = OFF_CIRCUIT_TAP.test(text) && !ON_LOAD_ANY.test(text) && (stated.length < 2 || allTags.every((d) => d === "octc"));
3727
+ if (offCircuitOnly) notes.push({ key: "off_circuit_line" });
3728
+ const dryType = DRY_TYPE.test(text);
3729
+ const base = {
3730
+ mva,
3731
+ voltagesKv,
3732
+ tapIndex,
3733
+ plus: main?.plus ?? null,
3734
+ minus: main?.minus ?? null,
3735
+ stepPct: main?.stepPct ?? null,
3736
+ vectorGroup: vg?.group ?? null,
3737
+ windings,
3738
+ neutralBilKv,
3739
+ phases,
3740
+ regulation,
3741
+ otherRanges,
3742
+ ...offCircuitOnly ? { offCircuitOnly: true } : {},
3743
+ ...dryType ? { dryType: true } : {},
3744
+ assumed,
3745
+ notes
3746
+ };
3747
+ if (auto) {
3748
+ const hvKv = voltagesKv[0] ?? null;
3749
+ const mvKv = voltagesKv[1] ?? null;
3750
+ if (hvKv == null || mvKv == null) notes.push({ key: "auto_needs_mv" });
3751
+ const tapPoint = tapIndex === 1 ? "auto_mv_line" : "auto_junction";
3752
+ assumed.push("tap_point");
3753
+ if (tapIndex != null && tapIndex > 1) notes.push({ key: "auto_tertiary" });
3754
+ return {
3755
+ ...base,
3756
+ kind: "auto",
3757
+ tapPoint,
3758
+ winding: "star",
3759
+ tapKv: null,
3760
+ hvKv,
3761
+ mvKv,
3762
+ warnings: notes.map(lineNoteEn)
3763
+ };
3764
+ }
3765
+ const tapKv = tapIndex != null ? voltagesKv[tapIndex] ?? null : null;
3766
+ const p = pointAt(tapIndex);
3767
+ if (p.zigzag) notes.push({ key: "zigzag" });
3768
+ if (p.deltaText) notes.push({ key: "delta_text" });
3769
+ if (p.mid) notes.push({ key: "mid_winding" });
3770
+ if (p.windingAssumed) assumed.push("winding");
3771
+ if (p.tapPointAssumed) assumed.push("tap_point");
3772
+ return {
3773
+ ...base,
3774
+ kind: "two_winding",
3775
+ tapPoint: p.tapPoint,
3776
+ winding: p.winding,
3777
+ tapKv,
3778
+ hvKv: null,
3779
+ mvKv: null,
3780
+ warnings: notes.map(lineNoteEn)
3781
+ };
3782
+ }
3783
+ function parseNeutralBil(text) {
3784
+ const re = /(?:neutral|中性点)([^;.]{0,30}?)(?:BIL|LI|LIWL)\s*[:=]?\s*(\d{2,4})((?:\s*\/\s*\d{2,4})*)/gi;
3785
+ for (const m of text.matchAll(re)) {
3786
+ const at = m.index ?? 0;
3787
+ if (/\b(?:LV|MV|tertiary|secondary)\s*$/i.test(text.slice(Math.max(0, at - 12), at))) continue;
3788
+ if (/\b(?:LV|MV|HV|tertiary|line[\s-]?end)\b|\//i.test(m[1])) continue;
3789
+ const names = text.slice(Math.max(0, at - 30), at).match(/((?:[A-Za-z][A-Za-z\s-]{0,12}\/\s*)+)$/);
3790
+ if (names) {
3791
+ const k = (names[1].match(/\//g) ?? []).length;
3792
+ const figs = [m[2], ...m[3].match(/\d{2,4}/g) ?? []];
3793
+ if (figs[k] == null) continue;
3794
+ return Number(figs[k]);
3795
+ }
3796
+ return Number(m[2]);
3797
+ }
3798
+ const named = /\b(?:HV\s+)?neutr(?:al|e|o)\s*[:=]?\s*(?:BIL|LI)?\s*(\d{2,4})\s*kVp?\b/gi;
3799
+ for (const m of text.matchAll(named)) {
3800
+ const at = m.index ?? 0;
3801
+ if (Number(m[1]) < 95) continue;
3802
+ const clause = text.slice(Math.max(0, at - 40), at).split(/[,;]/).pop() ?? "";
3803
+ if (/\b(?:LV|MV|tertiary|secondary|low[\s-]?voltage|\d+(?:\.\d+)?\s*kV)\b/i.test(clause)) continue;
3804
+ const after = text.slice(at + m[0].length, at + m[0].length + 8);
3805
+ const marked = /BIL|LI|kVp/i.test(m[0]) || /^\s*(?:BIL|LI|LIWL)\b/i.test(after);
3806
+ if (!marked && Number(m[1]) < 250) continue;
3807
+ return Number(m[1]);
3808
+ }
3809
+ const hvn = text.match(/\bHVN\b\s*[:=]?\s*(\d{2,4})((?:\s*\/\s*\d{2,4})*)/);
3810
+ if (hvn) return Math.max(Number(hvn[1]), ...(hvn[2].match(/\d{2,4}/g) ?? []).map(Number));
3811
+ return neutralFromList(text);
3812
+ }
3813
+ function neutralFromList(text) {
3814
+ const LBL = String.raw`(?:HV[\s-]?N|HVN|HV|MV|LV|N|neutral|line(?:[\s-]?end)?)`;
3815
+ const NAMES = String.raw`${LBL}(?:\s*\/\s*${LBL}){1,3}`;
3816
+ const FIGS = String.raw`(\d{2,4}(?:\s*\/\s*\d{2,4}){1,3})`;
3817
+ const list = new RegExp(
3818
+ String.raw`(?:\b(?:BIL|LIWL|LI|insulation)\b[^;\d]{0,12}?\(?\s*(${NAMES})\s*\)?|\b(${NAMES})\s*(?:BIL|LIWL|LI)\b)\s*[:=]?\s*${FIGS}`,
3819
+ "gi"
3820
+ );
3821
+ const isN = (n) => /^(?:HV[\s-]?N|HVN|N|neutral)$/i.test(n.trim());
3822
+ for (const m of text.matchAll(list)) {
3823
+ const names = (m[1] ?? m[2]).split("/").map((n) => n.trim());
3824
+ const figs = m[3].split("/").map((f) => Number(f.trim()));
3825
+ const k = names.findIndex(isN);
3826
+ if (k < 0 || figs[k] == null || figs[k] < 95) continue;
3827
+ if (/^N$/i.test(names[k]) && !(k > 0 && /^HV$/i.test(names[k - 1]))) continue;
3828
+ if (!/^HV[\s-]?N$|^HVN$/i.test(names[k]) && !names.some((n) => /^(?:HV|line)/i.test(n))) continue;
3829
+ return figs[k];
3830
+ }
3831
+ for (const m of text.matchAll(/[,;]\s*(HV[\s-]?N|HVN|N)\s*[:=]?\s*(\d{2,4})\b(?!\s*\/)/gi)) {
3832
+ const at = m.index ?? 0;
3833
+ const seg = text.slice(0, at).split(";").pop() ?? "";
3834
+ if (!/\b(?:BIL|LIWL|LI|insulation)\b[^;]*\bHV\s*[:=]?\s*\d/i.test(seg)) continue;
3835
+ if (Number(m[2]) >= 95) return Number(m[2]);
3836
+ }
3837
+ const pair = text.match(/\bneutr(?:al|e|o)\s+(BIL|LIWL|LI|AC)\s*\/\s*(BIL|LIWL|LI|AC)\s*[:=]?\s*(\d{2,4})\s*\/\s*(\d{2,4})/i);
3838
+ if (pair) return Number(/^AC$/i.test(pair[1]) ? pair[4] : pair[3]);
3839
+ const ins = text.match(/\bneutr(?:al|e|o)\s+insulation\s*[:=]?\s*(\d{2,4})\s*kV\s*(?:LI|BIL|LIWL)\b/i);
3840
+ return ins ? Number(ins[1]) : null;
3841
+ }
3842
+ var asPitch = (p) => p;
3843
+ function geometryForRange(plus, minus, reg) {
3844
+ const S = plus + minus;
3845
+ if (reg === "linear") return { positions: S + 1, mid: 0, pitch: asPitch(defaultPitch(S + 1, "linear")) };
3846
+ const opts = pmStepOptionsFor(reg);
3847
+ const want = plus === minus ? plus : Math.ceil(S / 2);
3848
+ const own = opts.includes(want) || plus === minus && reg === "coarse_fine" && want === 7;
3849
+ const n = own ? want : opts.find((o) => o >= want) ?? want;
3850
+ const mid = preferredMid(n, reg);
3851
+ const row = lookupDiagram(n, mid, reg);
3852
+ if (plus !== minus && row && S % 2 === 1 && n === want && row.pitch === 10) {
3853
+ return { positions: S + mid, mid, pitch: 10 };
3854
+ }
3855
+ return {
3856
+ positions: row?.positions ?? 2 * n + mid,
3857
+ mid,
3858
+ pitch: asPitch(row?.pitch ?? pitchFor(n, mid)),
3859
+ plusMinusSteps: n
3860
+ };
3861
+ }
3862
+ function defaultRegulationForRange(plus, minus) {
3863
+ return plus !== minus && plus + minus <= 9 ? "linear" : null;
3864
+ }
3865
+ function tenderLineSettings(tl, opts = {}) {
3866
+ if (tl.mva == null || !tl.voltagesKv.length) return { ok: false, reason: "no_mva_kv" };
3867
+ if (tl.kind === "auto" && (tl.hvKv == null || tl.mvKv == null)) return { ok: false, reason: "auto_needs_mv" };
3868
+ let tapKv = tl.tapKv;
3869
+ let tapKvStated = !tl.assumed.includes("tap_winding");
3870
+ let winding = tl.winding;
3871
+ let tapPoint = tl.tapPoint;
3872
+ let windingStated = !tl.assumed.includes("winding");
3873
+ let tapPointStated = !tl.assumed.includes("tap_point");
3874
+ let plus = tl.plus;
3875
+ let minus = tl.minus;
3876
+ let stepPct = tl.stepPct;
3877
+ let octcWinding = false;
3878
+ if (opts.octc && tl.kind === "two_winding" && tl.otherRanges.length) {
3879
+ const off = tl.otherRanges.find((x) => x.offCircuit);
3880
+ const r = off ?? tl.otherRanges.reduce((x, y) => y.plus + y.minus <= x.plus + x.minus ? y : x);
3881
+ if (off || plus == null || minus == null || r.plus + r.minus <= plus + minus) {
3882
+ plus = r.plus;
3883
+ minus = r.minus;
3884
+ stepPct = r.stepPct;
3885
+ winding = r.winding;
3886
+ tapPoint = r.tapPoint;
3887
+ tapKv = r.kv;
3888
+ tapKvStated = !r.kvAssumed;
3889
+ windingStated = !r.windingAssumed;
3890
+ tapPointStated = !r.tapPointAssumed;
3891
+ octcWinding = true;
3892
+ }
3893
+ }
3894
+ const uneven = plus != null && minus != null ? defaultRegulationForRange(plus, minus) : null;
3895
+ const earthUm = tl.neutralBilKv != null && tapPoint === "neutral" ? umForEarthInsulation(0, tl.neutralBilKv) : null;
3896
+ return {
3897
+ ok: true,
3898
+ s: {
3899
+ kind: tl.kind,
3900
+ kindStated: !tl.assumed.includes("kind"),
3901
+ mva: tl.phases === "I" ? 3 * tl.mva : tl.mva,
3902
+ phases: tl.phases,
3903
+ hvKv: tl.hvKv,
3904
+ mvKv: tl.mvKv,
3905
+ tapKv,
3906
+ tapKvStated,
3907
+ winding,
3908
+ windingStated,
3909
+ tapPoint,
3910
+ tapPointStated,
3911
+ plus,
3912
+ minus,
3913
+ stepPct,
3914
+ regulation: tl.regulation ?? uneven,
3915
+ regulationStated: tl.regulation != null,
3916
+ earthUm: earthUm ?? null,
3917
+ octcWinding
3918
+ }
3919
+ };
3920
+ }
2147
3921
 
2148
3922
  // lib/cli.ts
2149
3923
  var CliError = class extends Error {
@@ -2152,9 +3926,22 @@ var CliError = class extends Error {
2152
3926
  this.name = "CliError";
2153
3927
  }
2154
3928
  };
2155
- function num(raw, flag) {
3929
+ function num(raw, flag, bound = "positive") {
3930
+ if (bound !== "any" && /^\s*-\s*[\d.]/.test(raw)) {
3931
+ throw new CliError(
3932
+ bound === "positive" ? `${flag} must be greater than 0 (got ${raw})` : `${flag} must not be negative (got ${raw})`
3933
+ );
3934
+ }
2156
3935
  const p = parseDecimal(raw);
2157
- if (p.ok) return p.value;
3936
+ if (p.ok) {
3937
+ if (bound === "positive" && !(p.value > 0)) {
3938
+ throw new CliError(`${flag} must be greater than 0 (got ${raw})`);
3939
+ }
3940
+ if (bound === "nonNegative" && p.value < 0) {
3941
+ throw new CliError(`${flag} must not be negative (got ${raw})`);
3942
+ }
3943
+ return p.value;
3944
+ }
2158
3945
  if (p.reason === "ambiguous") {
2159
3946
  throw new CliError(
2160
3947
  `Ambiguous number for ${flag}: ${raw}. Write 1200 or 1.2 (no thousands separator).`
@@ -2162,8 +3949,112 @@ function num(raw, flag) {
2162
3949
  }
2163
3950
  throw new CliError(`Invalid number for ${flag}: ${raw}`);
2164
3951
  }
2165
- function parseCliArgs(argv2) {
3952
+ var KNOWN_FLAGS = [
3953
+ "--help",
3954
+ "--version",
3955
+ "--json",
3956
+ "--lang",
3957
+ "--no-update-check",
3958
+ "--octc",
3959
+ "--oil",
3960
+ "--vacuum",
3961
+ "--iu",
3962
+ "--imax",
3963
+ "--os-imax",
3964
+ "--market",
3965
+ "--across-li",
3966
+ "--across-ac",
3967
+ "--mva",
3968
+ "--kv",
3969
+ "--um",
3970
+ "--ust",
3971
+ "--step-pct",
3972
+ "--k",
3973
+ "--conn",
3974
+ "--connection",
3975
+ "--kind",
3976
+ "--auto",
3977
+ "--tap",
3978
+ "--winding",
3979
+ "--hv",
3980
+ "--mv",
3981
+ "--earth-um",
3982
+ "--reg",
3983
+ "--pm",
3984
+ "--positions",
3985
+ "--pos",
3986
+ "--structure",
3987
+ "--series",
3988
+ "--mount",
3989
+ "--contact",
3990
+ "--phases",
3991
+ "--line",
3992
+ "--nameplate",
3993
+ "--minus",
3994
+ "--range",
3995
+ "--mid",
3996
+ "--duty"
3997
+ ];
3998
+ var SWITCH_FLAGS = /* @__PURE__ */ new Set([
3999
+ "--help",
4000
+ "-h",
4001
+ "--version",
4002
+ "-v",
4003
+ "-V",
4004
+ "--json",
4005
+ "--no-update-check",
4006
+ "--octc",
4007
+ "--oil",
4008
+ "--vacuum",
4009
+ "--auto"
4010
+ ]);
4011
+ var FLAG_ALIAS = {
4012
+ "--connection": "--conn",
4013
+ "--positions": "--pos",
4014
+ "--nameplate": "--line"
4015
+ };
4016
+ function editDistance(a, b) {
4017
+ const d = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
4018
+ for (let j = 1; j <= b.length; j++) d[0][j] = j;
4019
+ for (let i = 1; i <= a.length; i++) {
4020
+ for (let j = 1; j <= b.length; j++) {
4021
+ d[i][j] = Math.min(
4022
+ d[i - 1][j] + 1,
4023
+ d[i][j - 1] + 1,
4024
+ d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)
4025
+ );
4026
+ }
4027
+ }
4028
+ return d[a.length][b.length];
4029
+ }
4030
+ function unknownFlag(a) {
4031
+ const name = a.replace(/=.*$/s, "");
4032
+ const best = KNOWN_FLAGS.map((f) => [f, editDistance(name, f)]).sort((x, y) => x[1] - y[1])[0];
4033
+ const hint = best && best[1] <= 2 ? ` Did you mean ${best[0]}?` : "";
4034
+ return new CliError(`Unknown flag: ${name}.${hint} Run oltc --help for the list.`);
4035
+ }
4036
+ function splitEquals(argv2) {
4037
+ const out = [];
4038
+ for (let i = 0; i < argv2.length; i++) {
4039
+ const a = argv2[i];
4040
+ const prev = argv2[i - 1];
4041
+ const m = /^(--[a-z][a-z-]*)=(.*)$/s.exec(a);
4042
+ if (m && SWITCH_FLAGS.has(m[1]) && prev !== "--line" && prev !== "--nameplate") {
4043
+ throw new CliError(`${m[1]} takes no value`);
4044
+ }
4045
+ if (prev === "--line" || prev === "--nameplate" || !m || /^--(line|nameplate|lang)$/.test(m[1])) {
4046
+ out.push(a);
4047
+ } else {
4048
+ out.push(m[1], m[2]);
4049
+ }
4050
+ }
4051
+ return out;
4052
+ }
4053
+ function parseCliArgs(rawArgv) {
4054
+ const argv2 = splitEquals(rawArgv);
4055
+ const envLang = typeof process !== "undefined" ? process.env?.OLTC_LANG?.toLowerCase() : void 0;
2166
4056
  const out = {
4057
+ ...envLang === "en" ? { lang: "en" } : {},
2167
4058
  conn: "Y",
2168
4059
  kind: "two_winding",
2169
4060
  reg: "reversing",
@@ -2180,21 +4071,47 @@ function parseCliArgs(argv2) {
2180
4071
  };
2181
4072
  const take = (i, flag) => {
2182
4073
  const v = argv2[i + 1];
2183
- if (v == null || v.startsWith("-")) {
4074
+ if (v == null || v.startsWith("-") && !/^-[\d.]/.test(v)) {
2184
4075
  throw new CliError(`Missing value for ${flag}`);
2185
4076
  }
2186
4077
  return [v, i + 1];
2187
4078
  };
4079
+ const seenFlags = /* @__PURE__ */ new Set();
4080
+ let lineRaw = null;
4081
+ let rangeRaw = null;
2188
4082
  for (let i = 0; i < argv2.length; i++) {
2189
4083
  const a = argv2[i];
4084
+ if (a.startsWith("--") && !SWITCH_FLAGS.has(a)) {
4085
+ const name = a.replace(/=.*$/s, "");
4086
+ const key = FLAG_ALIAS[name] ?? name;
4087
+ if (seenFlags.has(key)) throw new CliError(`${key} is given twice`);
4088
+ seenFlags.add(key);
4089
+ }
4090
+ const eq = a.match(/^--(line|nameplate)=(.*)$/s);
4091
+ if (eq) {
4092
+ out.given.add("line");
4093
+ lineRaw = eq[2];
4094
+ continue;
4095
+ }
2190
4096
  if (a === "-h" || a === "--help") {
2191
4097
  out.help = true;
2192
4098
  continue;
2193
4099
  }
4100
+ if (a === "--version" || a === "-v" || a === "-V") {
4101
+ out.version = true;
4102
+ continue;
4103
+ }
2194
4104
  if (a === "--json") {
2195
4105
  out.json = true;
2196
4106
  continue;
2197
4107
  }
4108
+ if (a === "--lang" || a.startsWith("--lang=")) {
4109
+ const v = a.includes("=") ? a.slice(7) : argv2[++i];
4110
+ const l = (v ?? "").toLowerCase();
4111
+ if (l !== "en" && l !== "zh") throw new CliError("--lang must be en or zh");
4112
+ out.lang = l;
4113
+ continue;
4114
+ }
2198
4115
  if (a === "--no-update-check") {
2199
4116
  continue;
2200
4117
  }
@@ -2216,12 +4133,40 @@ function parseCliArgs(argv2) {
2216
4133
  continue;
2217
4134
  }
2218
4135
  if (a === "--iu" || a === "--imax") {
4136
+ if (out.given.has(a === "--iu" ? "imaxFlag" : "iuFlag")) {
4137
+ throw new CliError("Give --iu or --imax, not both");
4138
+ }
4139
+ if (a === "--iu") out.given.add("iuFlag");
2219
4140
  out.given.add("iu");
4141
+ if (a === "--imax") out.given.add("imaxFlag");
2220
4142
  const [v, n] = take(i, a);
2221
4143
  out.iu = num(v, a);
2222
4144
  i = n;
2223
4145
  continue;
2224
4146
  }
4147
+ if (a === "--os-imax") {
4148
+ out.given.add("osImax");
4149
+ const [v, n] = take(i, a);
4150
+ out.osImax = num(v, a);
4151
+ i = n;
4152
+ continue;
4153
+ }
4154
+ if (a === "--market") {
4155
+ out.given.add("market");
4156
+ const [v, n] = take(i, a);
4157
+ if (!/^[A-Za-z]{2}$/.test(v)) throw new CliError(`--market must be a 2-letter country code (IT, TR, RU\u2026)`);
4158
+ out.market = v.toUpperCase();
4159
+ i = n;
4160
+ continue;
4161
+ }
4162
+ if (a === "--across-li" || a === "--across-ac") {
4163
+ const key = a === "--across-li" ? "acrossLi" : "acrossAc";
4164
+ out.given.add(key);
4165
+ const [v, n] = take(i, a);
4166
+ out[key] = num(v, a, "nonNegative");
4167
+ i = n;
4168
+ continue;
4169
+ }
2225
4170
  if (a === "--mva") {
2226
4171
  out.given.add("mva");
2227
4172
  const [v, n] = take(i, a);
@@ -2246,7 +4191,7 @@ function parseCliArgs(argv2) {
2246
4191
  if (a === "--ust") {
2247
4192
  out.given.add("ust");
2248
4193
  const [v, n] = take(i, a);
2249
- out.ust = num(v, a);
4194
+ out.ust = num(v, a, "nonNegative");
2250
4195
  i = n;
2251
4196
  continue;
2252
4197
  }
@@ -2339,13 +4284,19 @@ function parseCliArgs(argv2) {
2339
4284
  out.given.add("pm");
2340
4285
  const [v, n] = take(i, a);
2341
4286
  out.pm = num(v, a);
4287
+ if (!Number.isInteger(out.pm) || out.pm < 1) {
4288
+ throw new CliError("--pm must be a whole number of at least 1");
4289
+ }
2342
4290
  i = n;
2343
4291
  continue;
2344
4292
  }
2345
4293
  if (a === "--positions" || a === "--pos") {
2346
4294
  out.given.add("positions");
2347
4295
  const [v, n] = take(i, a);
2348
- out.positions = num(v, a);
4296
+ out.positions = num(v, a, "nonNegative");
4297
+ if (!Number.isInteger(out.positions) || out.positions < 2) {
4298
+ throw new CliError(`${a} must be a whole number of at least 2`);
4299
+ }
2349
4300
  i = n;
2350
4301
  continue;
2351
4302
  }
@@ -2392,13 +4343,17 @@ function parseCliArgs(argv2) {
2392
4343
  if (m === "in-tank" || m === "intank") out.mount = "in_tank";
2393
4344
  else if (m === "on-tank" || m === "ontank") out.mount = "on_tank";
2394
4345
  else if (m === "dry" || m === "dry-type") out.mount = "dry_type";
2395
- else throw new CliError(`--mount must be in-tank|on-tank|dry`);
4346
+ else if (m === "reactor") out.mount = "reactor";
4347
+ else throw new CliError(`--mount must be in-tank|on-tank|dry|reactor`);
2396
4348
  i = n;
2397
4349
  continue;
2398
4350
  }
2399
4351
  if (a === "--contact") {
2400
4352
  out.given.add("contact");
2401
4353
  const [v, n] = take(i, a);
4354
+ if (!/^\d+\s*[xX×*✕]\s*\d+[A-Ea-e]?$/.test(v.trim())) {
4355
+ throw new CliError("--contact must look like 6x5 or 12x11D");
4356
+ }
2402
4357
  out.contact = v;
2403
4358
  i = n;
2404
4359
  continue;
@@ -2414,6 +4369,37 @@ function parseCliArgs(argv2) {
2414
4369
  i = n;
2415
4370
  continue;
2416
4371
  }
4372
+ if (a === "--line" || a === "--nameplate") {
4373
+ out.given.add("line");
4374
+ const v = argv2[i + 1];
4375
+ if (v == null) throw new CliError(`Missing value for ${a}`);
4376
+ lineRaw = v;
4377
+ i += 1;
4378
+ continue;
4379
+ }
4380
+ if (a === "--minus") {
4381
+ out.given.add("minus");
4382
+ const [v, n] = take(i, a);
4383
+ const m = num(v, a, "nonNegative");
4384
+ if (!(m >= 0) || !Number.isInteger(m)) throw new CliError(`--minus must be a whole number of steps`);
4385
+ out.minus = m;
4386
+ i = n;
4387
+ continue;
4388
+ }
4389
+ if (a === "--range") {
4390
+ const [v, n] = take(i, a);
4391
+ rangeRaw = v;
4392
+ i = n;
4393
+ continue;
4394
+ }
4395
+ if (a === "--mid") {
4396
+ out.given.add("mid");
4397
+ const [v, n] = take(i, a);
4398
+ if (v !== "1" && v !== "3") throw new CliError(`--mid must be 1 or 3`);
4399
+ out.mid = v === "1" ? 1 : 3;
4400
+ i = n;
4401
+ continue;
4402
+ }
2417
4403
  if (a === "--duty") {
2418
4404
  out.given.add("octc");
2419
4405
  const [v, n] = take(i, a);
@@ -2424,10 +4410,106 @@ function parseCliArgs(argv2) {
2424
4410
  i = n;
2425
4411
  continue;
2426
4412
  }
2427
- throw new CliError(`Unknown flag: ${a}`);
4413
+ throw unknownFlag(a);
4414
+ }
4415
+ out.typed = seenFlags;
4416
+ if (rangeRaw != null) {
4417
+ const r = parseTapRange(rangeRaw);
4418
+ if (!r) throw new CliError(`--range must look like +4/-12 or +4/-12x1.25%`);
4419
+ if (r.stepPercent != null && !out.given.has("stepPct")) {
4420
+ out.stepPct = Math.round(r.stepPercent * 1e6) / 1e4;
4421
+ out.given.add("stepPct");
4422
+ }
4423
+ applyRange(out, r.plus, r.minus);
4424
+ }
4425
+ if (lineRaw != null) applyTenderLine(out, lineRaw);
4426
+ if (out.given.has("imaxFlag") && out.mva != null && out.osImax == null) {
4427
+ out.osImax = out.iu;
4428
+ out.iu = void 0;
4429
+ out.given.delete("iu");
4430
+ out.given.add("osImax");
2428
4431
  }
2429
4432
  return out;
2430
4433
  }
4434
+ function applyRange(out, plus, minus) {
4435
+ if (out.given.has("range")) return;
4436
+ out.given.add("range");
4437
+ out.range = { plus, minus };
4438
+ if (plus !== minus && !out.given.has("minus")) out.minus = minus;
4439
+ if (!out.given.has("reg") && defaultRegulationForRange(plus, minus)) out.reg = "linear";
4440
+ if (out.given.has("pm") || out.given.has("positions")) return;
4441
+ if (plus === minus) {
4442
+ out.pm = plus;
4443
+ out.given.add("pm");
4444
+ return;
4445
+ }
4446
+ if (out.octc || out.reg === "linear") {
4447
+ out.positions = plus + minus + 1;
4448
+ out.given.add("positions");
4449
+ return;
4450
+ }
4451
+ const g = geometryForRange(plus, minus, out.reg);
4452
+ if (g.plusMinusSteps != null) {
4453
+ out.pm = g.plusMinusSteps;
4454
+ out.given.add("pm");
4455
+ } else {
4456
+ out.positions = g.positions;
4457
+ out.given.add("positions");
4458
+ }
4459
+ if (out.mid != null && (g.mid === 1 || g.mid === 3) && out.mid !== g.mid) {
4460
+ throw new CliError(
4461
+ `--mid ${out.mid} does not fit +${plus}/-${minus}: the Fig. 3-3 row has mid ${g.mid}.`
4462
+ );
4463
+ }
4464
+ if (out.mid == null && (g.mid === 1 || g.mid === 3)) out.mid = g.mid;
4465
+ }
4466
+ function applyTenderLine(out, raw) {
4467
+ const t = parseTenderLine(raw);
4468
+ if (t?.offCircuitOnly && !out.given.has("octc")) out.octc = true;
4469
+ if (t?.dryType && !out.given.has("mount")) out.mount = "dry_type";
4470
+ const r = t ? tenderLineSettings(t, { octc: out.octc }) : null;
4471
+ if (r && !r.ok && r.reason === "auto_needs_mv") {
4472
+ throw new CliError(
4473
+ `--line reads an autotransformer without both HV and MV kV: ${raw}. Give --hv and --mv.`
4474
+ );
4475
+ }
4476
+ if (!t || !r || !r.ok) {
4477
+ const text = normalizeTenderText(raw);
4478
+ const hasMva = /\d\s*(?:MVA|kVA)/i.test(text);
4479
+ const hasKv = /\d\s*kV(?!A)/i.test(text);
4480
+ const what = !hasMva && !hasKv ? "MVA and kV" : !hasMva ? "the MVA rating" : !hasKv ? "the kV ratio" : "the kV ratio and range";
4481
+ throw new CliError(
4482
+ `Could not read ${what} from --line: ${raw}. Write it like "25MVA 110\xB18x1.25%/10.5kV YNd11", or give --mva/--kv (or --hv/--mv) instead.`
4483
+ );
4484
+ }
4485
+ const s = r.s;
4486
+ out.line = t;
4487
+ const fill = (key, apply, sure = true) => {
4488
+ if (out.given.has(key)) return;
4489
+ apply();
4490
+ if (sure) out.given.add(key);
4491
+ };
4492
+ fill("kind", () => out.kind = s.kind, s.kindStated);
4493
+ fill("mva", () => out.mva = s.mva, !t.assumed.includes("mva"));
4494
+ if (s.phases) fill("phases", () => out.phases = s.phases);
4495
+ if (s.kind === "auto") {
4496
+ if (s.hvKv != null) fill("hv", () => out.hv = s.hvKv);
4497
+ if (s.mvKv != null) fill("mv", () => out.mv = s.mvKv);
4498
+ } else if (s.tapKv != null) {
4499
+ fill("kv", () => out.kv = s.tapKv, s.tapKvStated);
4500
+ fill("winding", () => out.winding = s.winding, s.windingStated);
4501
+ }
4502
+ fill("tap", () => out.tap = s.tapPoint, s.tapPointStated);
4503
+ if (s.octcWinding && s.tapKv != null) out.lineOctcKv = s.tapKv;
4504
+ if (s.regulation) fill("reg", () => out.reg = s.regulation, s.regulationStated);
4505
+ if (s.plus != null && s.minus != null) {
4506
+ const typed = out.given.has("range") || out.given.has("pm") || out.given.has("positions");
4507
+ applyRange(out, s.plus, s.minus);
4508
+ if (!typed && !s.octcWinding && t.assumed.includes("range")) out.lineRangeAssumed = true;
4509
+ }
4510
+ if (s.stepPct != null) fill("stepPct", () => out.stepPct = s.stepPct);
4511
+ if (s.earthUm != null) fill("earthUm", () => out.earthUm = s.earthUm, false);
4512
+ }
2431
4513
  var CLI_HELP = `oltc \u2014 OLTC/OCTC type selection (package: oltc-selector, no prices)
2432
4514
 
2433
4515
  Usage:
@@ -2435,12 +4517,24 @@ Usage:
2435
4517
  oltc --mva 25 --kv 110 --tap neutral --reg W --pm 8
2436
4518
  oltc --mva 16 --kv 22 --tap line --winding star
2437
4519
  oltc --mva 125 --kind auto --hv 225 --mv 115 --tap junction
4520
+ oltc --line "125MVA 225\xB18x1,25%/115/35kV YNa0d11"
2438
4521
  oltc --octc --iu 800 --um 72.5 --conn D --series II --contact 6x5
2439
4522
  oltc --iu 600 --um 72.5 --conn Y --reg W --pm 8 --structure combined
2440
4523
 
2441
4524
  Flags:
2442
4525
  --iu, --imax A Max through-current (Imax). No safety factor.
4526
+ Beside --mva, --imax means --os-imax.
4527
+ --os-imax A Capacity path: the OS / maker Imax at the lowest tap.
4528
+ Replaces the full-range current, floored at rated I.
4529
+ --line "text" (also --nameplate) Tender line: MVA, kV ratio with \xB1N\xD7x%, vector group.
4530
+ Reads autotransformer from YNa0 / auto / OSFPSZ, delta
4531
+ line end from D, star neutral from Y (asked in \u5047\u5B9A).
4532
+ Percent ranges (+0/-30%), single-phase, coarse/fine and
4533
+ linear words are read. Flags given beside it win.
4534
+ --line="\u2026" keeps a line that starts with a dash.
2443
4535
  --mva MVA --kv kV Capacity path: Imax from rated I, minus steps, --step-pct, --k
4536
+ With --iu, --kv alone gives the winding voltage (220 kV
4537
+ combined-only, 330 kV grade, --market) and Um if omitted.
2444
4538
  --kind two|auto Transformer kind (--auto = --kind auto). Default two-winding.
2445
4539
  --tap P Where the OLTC sits: neutral|line (two-winding),
2446
4540
  junction|mv-line (autotransformer, series/common junction
@@ -2451,27 +4545,46 @@ Flags:
2451
4545
  --earth-um kV OLTC insulation to earth from the OS or maker (catalogue
2452
4546
  class). Overrides the rule: line end = winding system,
2453
4547
  neutral \u226472.5 full else 72.5 assumed, autotransformer = HV.
2454
- --um kV Equipment Um (OLTC). With --mva/--kv, derived if omitted.
2455
- --ust V Step voltage. With --mva/--kv/--step-pct, derived if omitted.
4548
+ --market CC Buyer's country for a neutral's assumed Um: IT (line
4549
+ class up to 252), TR (126 on 220 kV class and above).
4550
+ Needs --kv (or --mva/--kv).
4551
+ --um kV Equipment Um (OLTC). With --kv, derived if omitted.
4552
+ --ust V Step voltage. With --mva/--kv/--step-pct, derived if omitted;
4553
+ given, it is the OS figure and a floor (never lowers Ust).
4554
+ --across-li kV --across-ac kV
4555
+ Stated across-tap-winding LI / AC withstand: sets the
4556
+ selector grade (B/C/D/DE).
2456
4557
  --step-pct % Step as percent (1.25 means 1.25%). Capacity path only.
2457
4558
  --k n Safety factor on capacity path only (default 1.0, same as the web app).
2458
4559
  --conn Y|D Switch connection (star point / line end). Default Y.
2459
4560
  On the capacity path, legacy: Y = star neutral, D = delta line end.
2460
4561
  --reg W|G|0 Reversing / coarse-fine / linear. Default W.
2461
4562
  --pm N \xB1 steps. Default 8.
4563
+ --range +a/-b[xs%] Uneven range, e.g. +4/-12x1.25%. W/G takes the Fig. 3-3
4564
+ row the maker sells (+4/-12 \u2192 10193W); the lowest tap uses \u2212b.
4565
+ --minus N Minus steps for the lowest-tap current (beside --pm/--pos).
4566
+ --mid 1|3 Mid positions of the W/G diagram, when Fig. 3-3 has the pair.
2462
4567
  --pos, --positions Linear / OCTC positions.
2463
- --octc Off-circuit (\u65E0\u8F7D). Default on-load.
4568
+ --octc Off-circuit (\u65E0\u8F7D). Default on-load. (--duty octc|oltc is the same.)
2464
4569
  --structure auto|combined|compound|cage|drum (\u7EC4\u5408\u5F0F/\u590D\u5408\u5F0F/\u7B3C\u5F0F/\u9F13\u5F0F)
2465
4570
  --series II|IV|V|VI|VII|VIII OCTC wiring. Default auto is linear IV (Y and D).
2466
- --mount in-tank|on-tank|dry. Default in-tank.
4571
+ --mount in-tank|on-tank|dry|reactor. Default in-tank. Reactor is oil (HWDK).
2467
4572
  --oil / --vacuum Switching medium. Default vacuum (on-load).
2468
4573
  --contact OCTC contact e.g. 6x5.
2469
4574
  --phases I|II|III. Default III.
2470
- --json Machine-readable result (still no prices).
4575
+ --json Machine-readable result (still no prices). Keys: ok, version,
4576
+ model, why, alts, cautions, resolved (the duty as numbers),
4577
+ line, basis, umChoices, assumptions, errors. Errors are JSON too.
4578
+ --lang en|zh Output language (default zh; OLTC_LANG=en also works).
4579
+ --version, -v Print the version.
2471
4580
  --no-update-check Skip the daily check for a newer version. The check only
2472
4581
  prints a notice on stderr; it never installs anything.
2473
4582
  OLTC_NO_UPDATE_CHECK=1 or CI=1 also turn it off.
2474
- -h, --help This text.
4583
+ -h, --help This text. Also shown when no flag is given.
4584
+
4585
+ Every flag with a value also takes --flag=value. A flag that cannot take effect (--series
4586
+ without --octc, --conn D with --tap neutral, a flag given twice) is an error.
4587
+ Exit code: 0 a type was found, 1 no type or bad input.
2475
4588
 
2476
4589
  Defaults match the web first paint: on-load, in-tank vacuum, structure auto,
2477
4590
  \xB18 mid-3 reversing. Omitting --octc and --structure auto is minimum-adequate.
@@ -2490,17 +4603,20 @@ function cliConnection(args) {
2490
4603
  }
2491
4604
  var pmGiven = (args) => args.given.has("pm") && args.pm != null && args.pm > 0;
2492
4605
  function cliPlusMinus(args) {
2493
- if (pmGiven(args)) return { n: args.pm, mid: 3 };
4606
+ if (pmGiven(args)) return { n: args.pm, mid: args.mid ?? 3 };
2494
4607
  if (args.positions != null) {
4608
+ const own = args.mid ? lookupByPositions(args.positions, args.mid, args.reg) : null;
4609
+ if (own) return { n: own.plusMinus, mid: args.mid };
2495
4610
  const n = plusMinusFromPositions(args.positions, args.reg);
2496
4611
  if (n == null) return null;
2497
4612
  const mid = lookupByPositions(args.positions, 3, args.reg) ? 3 : 1;
2498
4613
  return { n, mid };
2499
4614
  }
2500
4615
  if (args.given.has("pm")) return null;
2501
- return args.pm != null && args.pm > 0 ? { n: args.pm, mid: 3 } : null;
4616
+ return args.pm != null && args.pm > 0 ? { n: args.pm, mid: args.mid ?? 3 } : null;
2502
4617
  }
2503
4618
  function cliMinusSteps(args) {
4619
+ if (args.minus != null && args.minus >= 0) return args.minus;
2504
4620
  const fromPositions = args.positions != null && args.positions > 1 ? Math.ceil((args.positions - 1) / 2) : null;
2505
4621
  if (args.octc || args.reg === "linear") {
2506
4622
  if (fromPositions != null) return fromPositions;
@@ -2516,8 +4632,22 @@ function cliLinearPositions(args) {
2516
4632
  if (pmGiven(args)) return Math.round(2 * args.pm + 1);
2517
4633
  return void 0;
2518
4634
  }
4635
+ function iuHasVoltage(args) {
4636
+ if (args.mva != null) return false;
4637
+ if (args.kind === "auto") {
4638
+ return args.hv != null && args.hv > 0 && args.mv != null && args.mv > 0;
4639
+ }
4640
+ return args.kv != null && args.kv > 0;
4641
+ }
4642
+ var dutyCache = /* @__PURE__ */ new WeakMap();
2519
4643
  function cliDuty(args) {
2520
- if (args.mva == null) return null;
4644
+ if (dutyCache.has(args)) return dutyCache.get(args);
4645
+ const d = computeCliDuty(args);
4646
+ dutyCache.set(args, d);
4647
+ return d;
4648
+ }
4649
+ function computeCliDuty(args) {
4650
+ if (args.mva == null && !iuHasVoltage(args)) return null;
2521
4651
  const auto = args.kind === "auto";
2522
4652
  if (auto) {
2523
4653
  if (!(args.hv != null && args.hv > 0 && args.mv != null && args.mv > 0)) {
@@ -2534,26 +4664,77 @@ function cliDuty(args) {
2534
4664
  kind: args.kind,
2535
4665
  tapPoint: tap,
2536
4666
  winding,
2537
- mva: args.mva,
4667
+ mva: args.mva ?? 0,
2538
4668
  tapKv: args.kv ?? 0,
2539
4669
  hvKv: args.hv ?? 0,
2540
4670
  mvKv: args.mv ?? 0,
2541
4671
  minusSteps: cliMinusSteps(args),
2542
4672
  stepFraction: pct,
4673
+ // 2026-11-04 final ENGINE-12: a defaulted 1.25 % yields to the step --ust implies.
4674
+ stepFractionStated: args.given.has("stepPct"),
2543
4675
  // 与网页版首屏一致:容量路径默认不额外加安全系数
2544
4676
  safetyK: args.k != null && args.k > 0 ? args.k : 1,
2545
- ...earth != null ? { earthUmKv: earth } : {}
4677
+ ...earth != null ? { earthUmKv: earth } : {},
4678
+ ...args.osImax != null && args.osImax > 0 ? { statedMaxA: args.osImax } : {},
4679
+ // --ust used to replace Ust after deriveDuty: basis.stepV disagreed (D3).
4680
+ ...args.ust != null && args.ust > 0 ? { statedStepV: args.ust } : {},
4681
+ ...args.market ? { market: args.market } : {}
2546
4682
  });
2547
4683
  }
4684
+ function checkConflicts(args) {
4685
+ const g = (k) => args.given.has(k);
4686
+ if (!args.octc) {
4687
+ if (g("series")) throw new CliError("--series is off-circuit wiring: add --octc");
4688
+ if (g("contact")) throw new CliError("--contact is an off-circuit contact: add --octc");
4689
+ if (args.structure === "cage" || args.structure === "drum") {
4690
+ throw new CliError(
4691
+ `--structure ${args.structure} is off-circuit: add --octc (on-load takes combined or compound)`
4692
+ );
4693
+ }
4694
+ } else {
4695
+ if (args.structure === "combined" || args.structure === "compound") {
4696
+ throw new CliError(
4697
+ `--structure ${args.structure} is on-load only: with --octc use cage or drum`
4698
+ );
4699
+ }
4700
+ if (g("medium") && args.vacuum) {
4701
+ throw new CliError("--vacuum does not apply with --octc (off-circuit switches do not break current)");
4702
+ }
4703
+ }
4704
+ if (g("medium") && args.oil && args.mount === "dry_type") {
4705
+ throw new CliError("--oil does not apply with --mount dry");
4706
+ }
4707
+ if (g("medium") && args.vacuum && args.mount === "reactor") {
4708
+ throw new CliError("--vacuum does not apply with --mount reactor (the reactor switch is oil)");
4709
+ }
4710
+ if (args.typed?.has("--conn") && args.typed.has("--tap") && args.conn === "D" && args.tap === "neutral") {
4711
+ throw new CliError("--conn D conflicts with --tap neutral: a neutral tap point is star (Y). Drop one.");
4712
+ }
4713
+ if (g("pm") && g("positions") && args.pm != null && args.positions != null) {
4714
+ const wg = () => plusMinusFromPositions(args.positions, args.reg) === args.pm || [1, 3].some(
4715
+ (mid) => resolveTapFields({ regulation: args.reg, plusMinusSteps: args.pm, midPositions: mid }).positions === args.positions
4716
+ );
4717
+ const fromPm = args.octc || args.reg === "linear" ? args.positions === 2 * args.pm + 1 : wg();
4718
+ if (!fromPm) {
4719
+ throw new CliError(
4720
+ `--pm ${args.pm} and --pos ${args.positions} disagree. Give one of them.`
4721
+ );
4722
+ }
4723
+ }
4724
+ }
2548
4725
  function cliToSelectInput(args) {
4726
+ checkConflicts(args);
2549
4727
  const dutyKind = args.octc ? "octc" : "oltc";
2550
- const oil = args.octc || args.oil || !args.vacuum;
4728
+ const oil = args.octc || args.oil || !args.vacuum || args.mount === "reactor";
2551
4729
  const medium = args.mount === "dry_type" ? "dry" : oil ? "oil" : "oil_vacuum";
2552
4730
  let iu = args.iu;
2553
4731
  let um = args.um;
2554
4732
  let ust = args.ust ?? 0;
2555
4733
  if (args.iu != null && args.mva != null) {
2556
- throw new CliError("Give --iu or --mva/--kv, not both");
4734
+ throw new CliError("Give --iu or --mva/--kv, not both (the OS Imax beside --mva is --os-imax)");
4735
+ }
4736
+ if (args.osImax != null && args.mva == null) {
4737
+ throw new CliError("--os-imax needs --mva/--kv; on the --iu path give the current as --iu");
2557
4738
  }
2558
4739
  if (args.k != null && args.mva == null) {
2559
4740
  throw new CliError("--k applies only on the --mva path (--iu has no safety factor)");
@@ -2564,16 +4745,27 @@ function cliToSelectInput(args) {
2564
4745
  if (args.stepPct != null && args.mva == null) {
2565
4746
  throw new CliError("--step-pct needs --mva/--kv; give --ust on the --iu path");
2566
4747
  }
4748
+ if (args.market && args.mva == null && !iuHasVoltage(args)) {
4749
+ throw new CliError("--market needs the winding voltage: add --kv (or --mva/--kv)");
4750
+ }
2567
4751
  const duty = cliDuty(args);
2568
4752
  let conn = args.conn;
2569
- if (duty) {
2570
- if (!duty.ok) throw new CliError(duty.errorZh ?? duty.errorEn ?? "Bad transformer data");
4753
+ if (duty && args.mva != null) {
4754
+ if (!duty.ok) throw new CliError((args.lang === "en" ? duty.errorEn : duty.errorZh) ?? duty.errorEn ?? "Bad transformer data");
2571
4755
  iu = duty.dutyA;
2572
4756
  if (um == null || !(um > 0)) um = duty.umKv;
2573
- if (!(ust > 0) && duty.stepV != null) ust = duty.stepV;
4757
+ if (duty.stepV != null) ust = duty.stepV;
2574
4758
  conn = duty.connection;
2575
4759
  } else {
4760
+ if (duty && !duty.ok) throw new CliError((args.lang === "en" ? duty.errorEn : duty.errorZh) ?? duty.errorEn ?? "Bad transformer data");
4761
+ if (duty && (um == null || !(um > 0))) um = duty.umKv;
2576
4762
  conn = cliConnection(args);
4763
+ if (!duty && args.earthUm != null && args.earthUm > 0) {
4764
+ if (um != null && um > 0 && Math.abs(um - args.earthUm) > 0.01) {
4765
+ throw new CliError("Give --um or --earth-um, not both, when no winding voltage (--kv) is given");
4766
+ }
4767
+ um = args.earthUm;
4768
+ }
2577
4769
  }
2578
4770
  if (iu == null || !(iu > 0)) {
2579
4771
  throw new CliError("Need --iu (Imax) or --mva plus --kv");
@@ -2589,11 +4781,17 @@ function cliToSelectInput(args) {
2589
4781
  phases: args.phases,
2590
4782
  connection: conn,
2591
4783
  ...args.kind === "auto" ? { transformerKind: "auto" } : {},
4784
+ ...duty?.combinedOnly ? { combinedOnly: true } : {},
4785
+ ...duty?.ok && args.kind !== "auto" ? { tapWindingKv: duty.umSystemKv } : {},
4786
+ // 2026-11-04 r3 ORDERS-11: buyer practice on the grade (TR 72.5C neutrals).
4787
+ ...args.market ? { market: args.market } : {},
2592
4788
  throughCurrentA: iu,
2593
4789
  umKv: um,
2594
4790
  stepVoltageV: ust,
2595
4791
  regulation: args.octc ? "linear" : args.reg,
2596
4792
  selectorSize: "auto",
4793
+ ...args.acrossLi != null && args.acrossLi > 0 ? { acrossTapBilKv: args.acrossLi } : {},
4794
+ ...args.acrossAc != null && args.acrossAc > 0 ? { acrossTapPfKv: args.acrossAc } : {},
2597
4795
  preferStructure: args.structure,
2598
4796
  mdu: "none"
2599
4797
  };
@@ -2614,6 +4812,7 @@ function cliToSelectInput(args) {
2614
4812
  input.midPositions = pm.mid;
2615
4813
  }
2616
4814
  if (args.positions != null) input.positions = args.positions;
4815
+ if (args.mid && input.plusMinusSteps == null) input.midPositions = args.mid;
2617
4816
  }
2618
4817
  return input;
2619
4818
  }
@@ -2621,7 +4820,7 @@ var MOUNT_ZH = {
2621
4820
  in_tank: "\u7BB1\u5185",
2622
4821
  on_tank: "\u7BB1\u9876",
2623
4822
  dry_type: "\u5E72\u5F0F",
2624
- // CLI 不会接收这两种,列上只为 Record 完整性
4823
+ // CLI 不接收外置隔室,列上只为 Record 完整性
2625
4824
  external_compartment: "\u5916\u7F6E\u9694\u5BA4",
2626
4825
  reactor: "\u7535\u6297\u5668"
2627
4826
  };
@@ -2634,17 +4833,23 @@ function assumptionsFromArgs(args, family) {
2634
4833
  auto_junction: "\u4E32\u8054/\u516C\u5171\u7ED5\u7EC4\u8FDE\u63A5\u70B9",
2635
4834
  auto_mv_line: "\u4E2D\u538B\u51FA\u7EBF"
2636
4835
  };
2637
- const tapGiven = args.given.has("tap") || args.given.has("conn") || args.winding === "delta";
4836
+ const tapGiven = args.given.has("tap") || args.given.has("conn") || args.winding === "delta" && (args.line == null || args.given.has("winding"));
2638
4837
  if (args.mva != null) {
2639
4838
  const duty = cliDuty(args);
2640
4839
  const tap = cliTapPoint(args);
2641
4840
  items.push(`${args.kind === "auto" ? "\u81EA\u8026\u53D8" : "\u53CC\u7ED5\u7EC4"}${mark("kind")}`);
4841
+ if (!args.given.has("mva")) items.push(`\u5BB9\u91CF ${args.mva} MVA\uFF08\u9ED8\u8BA4\uFF09`);
2642
4842
  items.push(`\u5F00\u5173\u5728${tapZh[tap]}${tapGiven ? "" : "\uFF08\u9ED8\u8BA4\uFF09"}`);
2643
4843
  if (args.kind !== "auto") {
2644
4844
  const w = args.winding ?? (tap === "neutral" || args.conn === "Y" ? "star" : "delta");
2645
4845
  items.push(`${w === "star" ? "\u661F\u5F62" : "\u89D2\u5F62"}\u7ED5\u7EC4${args.given.has("winding") ? "" : "\uFF08\u9ED8\u8BA4\uFF09"}`);
4846
+ if (args.kv != null && !args.given.has("kv")) items.push(`\u8C03\u538B\u7ED5\u7EC4 ${args.kv} kV\uFF08\u9ED8\u8BA4\uFF09`);
4847
+ }
4848
+ if (args.earthUm != null && !args.given.has("earthUm") && args.line?.neutralBilKv != null) {
4849
+ items.push(`\u5BF9\u5730 Um ${args.earthUm}\uFF08\u62DB\u6807\u884C\u4E2D\u6027\u70B9 BIL ${args.line.neutralBilKv} kV\uFF09`);
2646
4850
  }
2647
4851
  if (duty?.umAssumed) items.push(`\u5BF9\u5730 Um ${duty.umKv}\uFF08\u672A\u6307\u5B9A\uFF09`);
4852
+ if (args.market) items.push(`\u5E02\u573A=${args.market}`);
2648
4853
  } else {
2649
4854
  const conn = cliConnection(args);
2650
4855
  const derived = tapSetsConnection(args);
@@ -2663,6 +4868,23 @@ function assumptionsFromArgs(args, family) {
2663
4868
  items.push(
2664
4869
  args.given.has("stepPct") ? `step=${args.stepPct}%` : "step=1.25%\uFF08\u9ED8\u8BA4\uFF09"
2665
4870
  );
4871
+ if (!args.given.has("minus") && !args.given.has("range")) {
4872
+ items.push(`\u6700\u4F4E\u6863\u6309 \u2212${cliMinusSteps(args)} \u7B97\uFF08\u2212\u6863\u672A\u6307\u5B9A\uFF0C+a/\u2212b \u7528 --range \u6216 --minus\uFF09`);
4873
+ }
4874
+ if (args.lineRangeAssumed && args.range) {
4875
+ const { plus, minus } = args.range;
4876
+ items.push(`\u8C03\u538B\u8303\u56F4 ${plus === minus ? `\xB1${plus}` : `+${plus}/\u2212${minus}`}\uFF08\u9ED8\u8BA4\uFF0C\u62DB\u6807\u884C\u672A\u5199\u5168\uFF09`);
4877
+ }
4878
+ if (args.lineOctcKv != null) {
4879
+ const guess = args.given.has("kv") ? "" : "\u9ED8\u8BA4\uFF0C";
4880
+ items.push(`\u65E0\u8F7D\u5F00\u5173\u53D6 ${args.lineOctcKv} kV \u7ED5\u7EC4\u7684\u8303\u56F4\uFF08${guess}\u62DB\u6807\u884C\u6709\u4E24\u4E2A\u8C03\u538B\u8303\u56F4\uFF09`);
4881
+ }
4882
+ }
4883
+ if (args.given.has("acrossLi") || args.given.has("acrossAc")) {
4884
+ const li = args.acrossLi != null && args.acrossLi > 0 ? `LI ${args.acrossLi}` : "LI \u672A\u6307\u5B9A";
4885
+ const ac = args.acrossAc != null && args.acrossAc > 0 ? `AC ${args.acrossAc}` : "AC \u672A\u6307\u5B9A";
4886
+ const half = li.includes("\u672A\u6307\u5B9A") !== ac.includes("\u672A\u6307\u5B9A");
4887
+ items.push(`\u8C03\u538B\u7ED5\u7EC4\u95F4 ${li} / ${ac} kV${half ? "\uFF08\u53EA\u7ED9\u4E00\u9879\uFF1A\u7B49\u7EA7\u4E0D\u4F4E\u4E8E Um \u9ED8\u8BA4\uFF09" : ""}`);
2666
4888
  }
2667
4889
  const phases = `\u76F8\u6570=${args.phases}${mark("phases")}`;
2668
4890
  if (args.octc) {
@@ -2684,9 +4906,15 @@ function assumptionsFromArgs(args, family) {
2684
4906
  items.push(
2685
4907
  `reg=${args.reg === "reversing" ? "W \u6B63\u53CD\u8C03" : args.reg === "coarse_fine" ? "G \u7C97\u7EC6\u8C03" : "0 \u7EBF\u6027\u8C03"}${mark("reg")}`
2686
4908
  );
4909
+ const uneven = args.range && args.range.plus !== args.range.minus ? `+${args.range.plus}/\u2212${args.range.minus}` : null;
2687
4910
  if (args.reg === "linear") {
2688
4911
  items.push(
2689
- args.positions != null ? `${args.positions} \u6863${mark("positions")}` : pmGiven(args) ? `${cliLinearPositions(args)} \u6863\uFF08\u7531 \xB1${args.pm} \u63A8\uFF09` : "\u6863\u6570\u672A\u6307\u5B9A"
4912
+ args.positions != null ? `${args.positions} \u6863${uneven ? `\uFF08${uneven}\uFF09` : mark("positions")}` : pmGiven(args) ? `${cliLinearPositions(args)} \u6863\uFF08\u7531 \xB1${args.pm} \u63A8\uFF09` : "\u6863\u6570\u672A\u6307\u5B9A"
4913
+ );
4914
+ } else if (uneven) {
4915
+ const pm = cliPlusMinus(args);
4916
+ items.push(
4917
+ `${uneven} \u6863 \u2192 ${args.positions != null && !pmGiven(args) ? `${args.positions} \u6863` : `\xB1${pm?.n ?? args.pm}`}\uFF08\u6700\u4F4E\u6863\u6309 \u2212${cliMinusSteps(args)}\uFF09`
2690
4918
  );
2691
4919
  } else if (args.positions != null && !args.given.has("pm")) {
2692
4920
  const pm = cliPlusMinus(args);
@@ -2697,7 +4925,9 @@ function assumptionsFromArgs(args, family) {
2697
4925
  if (!args.given.has("ust") && args.mva == null) {
2698
4926
  items.push("Ust \u672A\u6307\u5B9A\uFF08\u7EA7\u7535\u538B\u3001\u7EA7\u5BB9\u91CF\u672A\u6821\u9A8C\uFF09");
2699
4927
  }
2700
- items.push(`${args.oil || !args.vacuum ? "\u6CB9\u6D78" : "\u771F\u7A7A"}${mark("medium")}`);
4928
+ items.push(
4929
+ `${args.oil || !args.vacuum || args.mount === "reactor" ? "\u6CB9\u6D78" : "\u771F\u7A7A"}${mark("medium")}`
4930
+ );
2701
4931
  items.push(`${MOUNT_ZH[args.mount]}${mark("mount")}`);
2702
4932
  items.push(phases);
2703
4933
  return items;
@@ -2710,16 +4940,121 @@ function assumptionsLine(args, family) {
2710
4940
  return `\u5047\u5B9A\uFF1A${items.join(" \xB7 ")}`;
2711
4941
  }
2712
4942
  var round1 = (n) => Math.round(n * 10) / 10;
4943
+ var ASSUMPTION_EN = [
4944
+ ["\uFF08\u9ED8\u8BA4\uFF0C\u62DB\u6807\u884C\u672A\u5199\u5168\uFF09", " (default; the line does not give it all)"],
4945
+ ["\uFF08\u9ED8\u8BA4\uFF09", " (default)"],
4946
+ ["\uFF08\u672A\u6307\u5B9A\uFF09", " (not stated)"],
4947
+ ["\uFF08\u5F85 OS \u6838\u5BF9\uFF09", " (check the OS)"],
4948
+ [/(只给一项:等级不低于 Um 默认)/, " (one value only: grade not below the Um default)"],
4949
+ [/^最低档按 −(\d+) 算(−档未指定,\+a\/−b 用 --range 或 --minus)$/, "lowest tap at \u2212$1 (minus not stated; give +a/\u2212b with --range or --minus)"],
4950
+ [/^无载开关取 ([\d.]+) kV 绕组的范围((默认,)?招标行有两个调压范围)$/, "off-circuit range from the $1 kV winding (two ranges on the line)"],
4951
+ [/^对地 Um ([\d.]+)(招标行中性点 BIL ([\d.]+) kV)$/, "Um to earth $1 (line neutral BIL $2 kV)"],
4952
+ ["Ust \u672A\u6307\u5B9A\uFF08\u7EA7\u7535\u538B\u3001\u7EA7\u5BB9\u91CF\u672A\u6821\u9A8C\uFF09", "Ust not stated (step voltage and capacity not checked)"],
4953
+ ["\u4E32\u8054/\u516C\u5171\u7ED5\u7EC4\u8FDE\u63A5\u70B9", "series/common junction"],
4954
+ ["\u4E2D\u538B\u51FA\u7EBF", "MV line lead"],
4955
+ ["\u5F00\u5173\u5728\u4E2D\u6027\u70B9", "tap at neutral"],
4956
+ ["\u5F00\u5173\u5728\u7EBF\u7AEF", "tap at line end"],
4957
+ ["\u5F00\u5173\u5728", "tap at "],
4958
+ ["\u81EA\u8026\u53D8", "autotransformer"],
4959
+ ["\u53CC\u7ED5\u7EC4", "two-winding"],
4960
+ [/^容量 /, "power "],
4961
+ ["\u661F\u5F62\u7ED5\u7EC4", "star winding"],
4962
+ ["\u89D2\u5F62\u7ED5\u7EC4", "delta winding"],
4963
+ [/^调压绕组间 /, "across tap winding "],
4964
+ [/^调压绕组 /, "tapped winding "],
4965
+ [/^调压范围 /, "range "],
4966
+ ["\u5BF9\u5730 Um", "Um to earth"],
4967
+ ["\u5E02\u573A=", "market="],
4968
+ ["\u661F\u70B9", "star point"],
4969
+ ["\u7EBF\u7AEF", "line end"],
4970
+ ["\u4E2D\u6027\u70B9", "neutral"],
4971
+ ["\u76F8\u6570=", "phases="],
4972
+ ["\u63A5\u7EBF=\u81EA\u52A8", "wiring=auto"],
4973
+ ["\u63A5\u7EBF=", "wiring="],
4974
+ [/(由 ±([\d.]+) 推)/, " (from \xB1$1)"],
4975
+ [/(最低档按 −(\d+))/, " (lowest tap at \u2212$1)"],
4976
+ ["\u6863\u6570\u672A\u6307\u5B9A", "positions not stated"],
4977
+ [/^±([\d.]+) 档/, "\xB1$1 steps"],
4978
+ [/ 档/g, " positions"],
4979
+ ["W \u6B63\u53CD\u8C03", "W reversing"],
4980
+ ["G \u7C97\u7EC6\u8C03", "G coarse/fine"],
4981
+ ["0 \u7EBF\u6027\u8C03", "0 linear"],
4982
+ ["\u6CB9\u6D78", "oil"],
4983
+ ["\u771F\u7A7A", "vacuum"],
4984
+ ["\u7BB1\u5185", "in tank"],
4985
+ ["\u7BB1\u9876", "on tank"],
4986
+ ["\u5E72\u5F0F", "dry-type"],
4987
+ ["\u5916\u7F6E\u9694\u5BA4", "external compartment"],
4988
+ ["\u7535\u6297\u5668", "reactor"],
4989
+ ["\u672A\u6307\u5B9A", "not stated"],
4990
+ ["\uFF08", " ("],
4991
+ ["\uFF09", ")"],
4992
+ ["\uFF0C", ", "]
4993
+ ];
4994
+ function assumptionEn(item) {
4995
+ let s = item;
4996
+ for (const [from, to] of ASSUMPTION_EN) s = typeof from === "string" ? s.split(from).join(to) : s.replace(from, to);
4997
+ return s;
4998
+ }
4999
+ function basisLineEn(d) {
5000
+ const div = d.currentDivisor === "three" ? "3" : "\u221A3";
5001
+ const um = d.umRule === "explicit" ? `Um to earth ${d.umKv} (stated)` : d.umRule === "neutral_assumed" || d.umRule === "neutral_full" ? `neutral Um ${d.umKv}${d.umAssumed ? " (check the OS)" : ""}` : `${d.umSystemKv} kV system Um ${d.actualUmKv} \u2192 class ${d.umKv}`;
5002
+ const ust = d.stepV == null ? "" : ` \xB7 Ust ${round1(d.stepV)} V`;
5003
+ const max = d.maxRule === "stated" ? "OS Imax" : "lowest tap";
5004
+ if (!(d.ratedA > 0)) return `Imax as given \xB7 ${um}`;
5005
+ return `I = S/(${div}\xD7${d.currentKv} kV) = ${round1(d.ratedA)} A, ${max} ${round1(d.maxA)} A${ust} \xB7 ${um}`;
5006
+ }
2713
5007
  function basisLineZh(d) {
2714
5008
  const div = d.currentDivisor === "three" ? "3" : "\u221A3";
2715
5009
  const um = d.umRule === "explicit" ? `\u5BF9\u5730 Um ${d.umKv}\uFF08\u6307\u5B9A\uFF09` : d.umRule === "neutral_assumed" || d.umRule === "neutral_full" ? `\u4E2D\u6027\u70B9 Um ${d.umKv}${d.umAssumed ? "\uFF08\u5F85 OS \u6838\u5BF9\uFF09" : ""}` : `${d.umSystemKv} kV \u7CFB\u7EDF Um ${d.actualUmKv} \u2192 ${d.umKv} \u7EA7`;
2716
5010
  const ust = d.stepV == null ? "" : ` \xB7 Ust ${round1(d.stepV)} V`;
2717
- return `I = S/(${div}\xD7${d.currentKv} kV) = ${round1(d.ratedA)} A\uFF0C\u6700\u4F4E\u6863 ${round1(d.maxA)} A${ust} \xB7 ${um}`;
5011
+ const max = d.maxRule === "stated" ? "OS Imax" : "\u6700\u4F4E\u6863";
5012
+ if (!(d.ratedA > 0)) return `Imax \u6309\u7ED9\u5B9A\u503C \xB7 ${um}`;
5013
+ return `I = S/(${div}\xD7${d.currentKv} kV) = ${round1(d.ratedA)} A\uFF0C${max} ${round1(d.maxA)} A${ust} \xB7 ${um}`;
5014
+ }
5015
+ function cliNotes(args, input, primaryUmKv, en, engineNotes = []) {
5016
+ if (!args) return [];
5017
+ const notes = [];
5018
+ const duty = cliDuty(args);
5019
+ if (duty?.ok && duty.ruleUmKv != null && duty.umKv < duty.ruleUmKv - 0.01) {
5020
+ const already = duty.cautionsEn.some((c) => c.startsWith("Stated Um"));
5021
+ if (!already) {
5022
+ notes.push(
5023
+ en ? `Stated insulation to earth, Um ${duty.umKv} kV, is below the ${duty.ruleUmKv} kV the winding voltage gives. Check the order specification (OS).` : `\u6307\u5B9A\u5BF9\u5730\u7EDD\u7F18 Um ${duty.umKv} kV \u4F4E\u4E8E\u6309\u7ED5\u7EC4\u7535\u538B\u5F97\u51FA\u7684 ${duty.ruleUmKv} kV\uFF0C\u8BF7\u6838\u5BF9\u8BA2\u8D27\u89C4\u8303\uFF08OS\uFF09\u3002`
5024
+ );
5025
+ }
5026
+ }
5027
+ const classSaid = engineNotes.some((c) => /next class|上一级|下一级/.test(c));
5028
+ if (primaryUmKv != null && primaryUmKv > input.umKv + 0.01 && !classSaid) {
5029
+ notes.push(
5030
+ en ? `Um ${input.umKv} kV is not a class of this type: sized at Um ${primaryUmKv} kV.` : `Um ${input.umKv} kV \u4E0D\u662F\u8BE5\u578B\u53F7\u7684\u7535\u538B\u7B49\u7EA7\uFF0C\u6309 Um ${primaryUmKv} kV \u9009\u3002`
5031
+ );
5032
+ }
5033
+ if (args.market && args.market !== "IT" && args.market !== "TR") {
5034
+ notes.push(
5035
+ en ? `--market ${args.market} has no rule (IT and TR only): not used.` : `--market ${args.market} \u6CA1\u6709\u5BF9\u5E94\u89C4\u5219\uFF08\u53EA\u6709 IT\u3001TR\uFF09\uFF0C\u672A\u4F7F\u7528\u3002`
5036
+ );
5037
+ }
5038
+ return notes;
5039
+ }
5040
+ function lineKindLabel(t, en) {
5041
+ if (t.kind === "auto") return en ? "autotransformer" : "\u81EA\u8026\u53D8";
5042
+ if (t.voltagesKv.length >= 3) return en ? "three-winding" : "\u4E09\u7ED5\u7EC4";
5043
+ return en ? "two-winding" : "\u53CC\u7ED5\u7EC4";
5044
+ }
5045
+ function noTypeHint(args, en) {
5046
+ if (!args) return null;
5047
+ if (args.mount === "dry_type" && !args.octc && args.reg !== "linear" && !args.given.has("mid")) {
5048
+ return en ? "Dry-type switches stop at 17 positions: try --mid 1 (\xB18 \u2192 17 positions) or fewer steps." : "\u5E72\u5F0F\u5F00\u5173\u6700\u591A 17 \u6863\uFF1A\u8BD5 --mid 1\uFF08\xB18 \u4E3A 17 \u6863\uFF09\u6216\u51CF\u5C11\u7EA7\u6570\u3002";
5049
+ }
5050
+ return null;
2718
5051
  }
2719
5052
  function formatCliText(input, args) {
2720
5053
  const out = selectOltc(input);
5054
+ const en = args?.lang === "en";
2721
5055
  if (!out.ok || !out.results.length) {
2722
- const err = [...out.errorsZh, ...out.errorsEn].join("\n") || "No type found.";
5056
+ const hint = noTypeHint(args, en);
5057
+ const err = [...en ? out.errorsEn : [...out.errorsZh, ...out.errorsEn], ...hint ? [hint] : []].join("\n") || "No type found.";
2723
5058
  throw new CliError(err);
2724
5059
  }
2725
5060
  const primary = out.results[0];
@@ -2738,22 +5073,40 @@ function formatCliText(input, args) {
2738
5073
  );
2739
5074
  const lines = [
2740
5075
  primary.model,
2741
- primary.reasonsZh[0] || primary.reasonsEn[0] || "\u6700\u4F4E\u6EE1\u8DB3"
5076
+ en ? primary.reasonsEn[0] || "Lowest type that meets the duty" : primary.reasonsZh[0] || primary.reasonsEn[0] || "\u6700\u4F4E\u6EE1\u8DB3"
2742
5077
  ];
2743
5078
  const duty = args ? cliDuty(args) : null;
2744
- if (duty?.ok) lines.push(`\u4F9D\u636E\uFF1A${basisLineZh(duty)}`);
2745
- for (const c of primary.cautionsZh) lines.push(`\u6CE8\u610F\uFF1A${c}`);
2746
- for (const c of duty?.cautionsZh ?? []) lines.push(`\u6CE8\u610F\uFF1A${c}`);
5079
+ const note = en ? "Note: " : "\u6CE8\u610F\uFF1A";
5080
+ if (duty?.ok) lines.push(en ? `Basis: ${basisLineEn(duty)}` : `\u4F9D\u636E\uFF1A${basisLineZh(duty)}`);
5081
+ for (const c of en ? primary.cautionsEn : primary.cautionsZh) lines.push(`${note}${c}`);
5082
+ for (const c of (en ? duty?.cautionsEn : duty?.cautionsZh) ?? []) lines.push(`${note}${c}`);
5083
+ for (const c of cliNotes(args, input, primary.umKv, en, [...primary.cautionsEn, ...primary.cautionsZh])) {
5084
+ lines.push(`${note}${c}`);
5085
+ }
5086
+ const choices = args && duty?.ok ? umChoicesFor(args, input) : [];
5087
+ if (choices.length > 1) {
5088
+ const list = choices.map((c) => `Um ${c.um} \u2192 ${c.model ?? (en ? "none" : "\u65E0")}`).join(" \xB7 ");
5089
+ lines.push(
5090
+ en ? `Insulation to earth open: ${list} (take it from the tender's neutral / tap-winding insulation; use --earth-um)` : `\u5BF9\u5730\u7EDD\u7F18\u672A\u5B9A\uFF1A${list}\uFF08\u6309\u62DB\u6807\u7684\u4E2D\u6027\u70B9/\u8C03\u538B\u7ED5\u7EC4\u7EDD\u7F18\u53D6\uFF0C\u7528 --earth-um\uFF09`
5091
+ );
5092
+ }
5093
+ if (args?.line) {
5094
+ const t = args.line;
5095
+ const kind = lineKindLabel(t, en);
5096
+ const vg = t.vectorGroup ? ` \xB7 ${t.vectorGroup}` : en ? " \xB7 no vector group" : " \xB7 \u65E0\u8054\u7ED3\u7EC4";
5097
+ lines.push(`${en ? "Line: " : "\u62DB\u6807\u884C\uFF1A"}${kind} \xB7 ${t.mva} MVA \xB7 ${t.voltagesKv.join("/")} kV${vg}`);
5098
+ for (const w of t.warnings) lines.push(en ? `Note: line ${w}` : `\u6CE8\u610F\uFF1A\u62DB\u6807\u884C ${w}`);
5099
+ }
2747
5100
  if (alts.length) {
2748
5101
  lines.push("");
2749
- lines.push("\u5176\u4ED6");
5102
+ lines.push(en ? "Other" : "\u5176\u4ED6");
2750
5103
  for (const a of alts) lines.push(a.model);
2751
5104
  }
2752
5105
  if (args) {
2753
5106
  const assumed = assumptionsLine(args, primary.seriesCode);
2754
5107
  if (assumed) {
2755
5108
  lines.push("");
2756
- lines.push(assumed);
5109
+ lines.push(en ? `Assumed: ${assumptionsFromArgs(args, primary.seriesCode).map(assumptionEn).join(" \xB7 ")}` : assumed);
2757
5110
  }
2758
5111
  }
2759
5112
  return lines.join("\n") + "\n";
@@ -2774,21 +5127,44 @@ function formatCliJson(input, args) {
2774
5127
  acrossTapPfKv: input.acrossTapPfKv
2775
5128
  }
2776
5129
  ).map((r) => r.model);
5130
+ const en = args?.lang === "en";
5131
+ const dutyJ = args ? cliDuty(args) : null;
5132
+ const hint = out.ok ? null : noTypeHint(args, en);
2777
5133
  const payload = {
2778
- ok: out.ok,
5134
+ ok: out.ok && primary != null,
5135
+ version: APP_VERSION,
2779
5136
  model: primary?.model ?? null,
2780
- why: primary?.reasonsZh[0] ?? primary?.reasonsEn[0] ?? null,
5137
+ why: en ? primary?.reasonsEn[0] ?? null : primary?.reasonsZh[0] ?? primary?.reasonsEn[0] ?? null,
2781
5138
  alts,
2782
- cautions: [
2783
- ...primary?.cautionsZh ?? [],
2784
- ...(args ? cliDuty(args) : null)?.cautionsZh ?? []
2785
- ],
5139
+ cautions: en ? [...primary?.cautionsEn ?? [], ...dutyJ?.cautionsEn ?? [], ...cliNotes(args, input, primary?.umKv ?? null, true, primary?.cautionsEn)] : [...primary?.cautionsZh ?? [], ...dutyJ?.cautionsZh ?? [], ...cliNotes(args, input, primary?.umKv ?? null, false, primary?.cautionsZh)],
5140
+ // What the engine was asked, as numbers: no prose to parse.
5141
+ resolved: {
5142
+ dutyKind: input.dutyKind,
5143
+ throughCurrentA: round1(input.throughCurrentA),
5144
+ umKv: input.umKv,
5145
+ stepVoltageV: round1(input.stepVoltageV),
5146
+ connection: input.connection,
5147
+ phases: input.phases,
5148
+ regulation: input.regulation,
5149
+ plusMinusSteps: input.plusMinusSteps ?? null,
5150
+ positions: input.positions ?? null,
5151
+ mounting: input.mounting,
5152
+ medium: input.medium
5153
+ },
5154
+ line: args?.line ? {
5155
+ kind: lineKindLabel(args.line, true),
5156
+ mva: args.line.mva,
5157
+ voltagesKv: args.line.voltagesKv,
5158
+ vectorGroup: args.line.vectorGroup ?? null,
5159
+ warnings: args.line.warnings
5160
+ } : null,
2786
5161
  basis: (() => {
2787
- const d = args ? cliDuty(args) : null;
5162
+ const d = dutyJ;
2788
5163
  return d?.ok ? {
2789
5164
  connection: d.connection,
2790
- ratedA: round1(d.ratedA),
2791
- maxA: round1(d.maxA),
5165
+ ratedA: d.ratedA > 0 ? round1(d.ratedA) : null,
5166
+ maxA: d.maxA > 0 ? round1(d.maxA) : null,
5167
+ maxRule: d.maxRule,
2792
5168
  stepV: d.stepV == null ? null : round1(d.stepV),
2793
5169
  umSystemKv: d.umSystemKv,
2794
5170
  actualUmKv: d.actualUmKv,
@@ -2797,26 +5173,68 @@ function formatCliJson(input, args) {
2797
5173
  umAssumed: d.umAssumed
2798
5174
  } : null;
2799
5175
  })(),
2800
- assumptions: args ? assumptionsFromArgs(args, primary?.seriesCode) : [],
2801
- errors: out.errorsZh.length ? out.errorsZh : out.errorsEn
5176
+ umChoices: args ? umChoicesFor(args, input) : [],
5177
+ assumptions: args ? assumptionsFromArgs(args, primary?.seriesCode).map((a) => en ? assumptionEn(a) : a) : [],
5178
+ errors: [...en ? out.errorsEn : out.errorsZh.length ? out.errorsZh : out.errorsEn, ...hint ? [hint] : []]
2802
5179
  };
2803
5180
  return JSON.stringify(payload, null, 2) + "\n";
2804
5181
  }
5182
+ function umChoicesFor(args, input) {
5183
+ const d = cliDuty(args);
5184
+ if (!d?.ok) return [];
5185
+ const tap = cliTapPoint(args);
5186
+ const spec = {
5187
+ kind: args.kind,
5188
+ tapPoint: tap,
5189
+ winding: args.winding ?? (tap === "neutral" ? "star" : "delta"),
5190
+ mva: args.mva ?? 0,
5191
+ tapKv: args.kv ?? 0,
5192
+ hvKv: args.hv ?? 0,
5193
+ mvKv: args.mv ?? 0,
5194
+ minusSteps: 0,
5195
+ stepFraction: null,
5196
+ safetyK: 1
5197
+ };
5198
+ return umChoices(d, spec).map((um) => ({
5199
+ um,
5200
+ model: selectOltc({ ...input, umKv: um }).results[0]?.model ?? null
5201
+ }));
5202
+ }
2805
5203
  function runCli(argv2, io = {
2806
5204
  stdout: (s) => process.stdout.write(s),
2807
5205
  stderr: (s) => process.stderr.write(s)
2808
5206
  }) {
5207
+ const asksHelp = argv2.some(
5208
+ (a, i) => (a === "-h" || a === "--help") && argv2[i - 1] !== "--line" && argv2[i - 1] !== "--nameplate"
5209
+ );
5210
+ const selecting = argv2.filter((a) => a !== "--no-update-check");
5211
+ if (asksHelp || selecting.length === 0) {
5212
+ io.stdout(CLI_HELP);
5213
+ return 0;
5214
+ }
5215
+ const wantsJson = argv2.includes("--json");
2809
5216
  try {
2810
5217
  const args = parseCliArgs(argv2);
2811
- if (args.help) {
2812
- io.stdout(CLI_HELP);
5218
+ if (args.version) {
5219
+ io.stdout(`oltc-selector ${APP_VERSION}
5220
+ `);
2813
5221
  return 0;
2814
5222
  }
2815
5223
  const input = cliToSelectInput(args);
2816
- io.stdout(args.json ? formatCliJson(input, args) : formatCliText(input, args));
5224
+ if (args.json) {
5225
+ const text = formatCliJson(input, args);
5226
+ io.stdout(text);
5227
+ return JSON.parse(text).ok ? 0 : 1;
5228
+ }
5229
+ io.stdout(formatCliText(input, args));
2817
5230
  return 0;
2818
5231
  } catch (err) {
2819
5232
  const msg = err instanceof Error ? err.message : String(err);
5233
+ if (wantsJson) {
5234
+ io.stdout(
5235
+ JSON.stringify({ ok: false, version: APP_VERSION, model: null, errors: msg.split("\n") }, null, 2) + "\n"
5236
+ );
5237
+ }
2820
5238
  io.stderr(msg.endsWith("\n") ? msg : msg + "\n");
2821
5239
  return 1;
2822
5240
  }
@@ -2845,6 +5263,8 @@ function updateNotice(latest, current) {
2845
5263
  return `
2846
5264
  \u6709\u65B0\u7248\u672C oltc-selector ${latest}\uFF08\u5F53\u524D ${current}\uFF09\uFF0C\u4E0D\u4F1A\u81EA\u52A8\u66F4\u65B0\u3002
2847
5265
  \u9700\u8981\u65F6\u8FD0\u884C\uFF1Anpm i -g oltc-selector@latest\uFF0C\u6216\u7528 npx -y oltc-selector@latest\u3002
5266
+ New version oltc-selector ${latest} (you have ${current}). Nothing is installed for you.
5267
+ To update: npm i -g oltc-selector@latest, or run npx -y oltc-selector@latest.
2848
5268
  `;
2849
5269
  }
2850
5270
  function updateCheckEnabled(argv2, env) {