@huaqiu/dsh-engineering-workbench 0.7.27 → 0.7.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -108362,6 +108362,822 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
108362
108362
  ]
108363
108363
  });
108364
108364
  }
108365
+ const MODES = [
108366
+ "design",
108367
+ "mechanical",
108368
+ "review",
108369
+ "manufacture"
108370
+ ];
108371
+ function validRequest(value) {
108372
+ return !!value && MODES.includes(value.view) && (value.designTool === void 0 || value.view === "design" && [
108373
+ "schematic",
108374
+ "pcb",
108375
+ "3d"
108376
+ ].includes(value.designTool)) && (value.action === void 0 || ["open", "suggest"].includes(value.action)) && [
108377
+ value.path,
108378
+ value.project,
108379
+ value.reference
108380
+ ].every((s) => s === void 0 || typeof s === "string" && s.trim() && s.length <= 4096) && (value.path === void 0 || /\.kicad_(pcb|sch)$/i.test(value.path)) && (value.project === void 0 || /\.kicad_pro$/i.test(value.project));
108381
+ }
108382
+ function requestsIn(nodes) {
108383
+ const requests = /* @__PURE__ */ new Map();
108384
+ const visit = (node) => {
108385
+ if (!node || typeof node !== "object") return;
108386
+ if (node.kind === "tool-result" && node.call?.name === "hardware_open_workbench" && Array.isArray(node.content)) for (const block of node.content) {
108387
+ if (block.type !== "text") continue;
108388
+ try {
108389
+ const value = JSON.parse(block.text);
108390
+ if (validRequest(value) && typeof value.requestId === "string" && Number.isFinite(value.issuedAt)) requests.set(value.requestId, value);
108391
+ } catch {}
108392
+ }
108393
+ for (const key of [
108394
+ "children",
108395
+ "nodes",
108396
+ "subCalls"
108397
+ ]) if (Array.isArray(node[key])) node[key].forEach(visit);
108398
+ };
108399
+ nodes.forEach(visit);
108400
+ return [...requests.values()];
108401
+ }
108402
+ //#endregion
108403
+ //#region src/styles.ts
108404
+ const styles = `
108405
+ .ew-model{margin:0 6px 6px;min-height:180px}.ew-model-info{overflow-wrap:anywhere}.ew-model-picker{position:relative;cursor:pointer;padding:4px 8px;border:1px solid var(--dsw-alias-border-l2,#abbcac);border-radius:4px}.ew-model-picker input{position:absolute;inset:0;width:100%;height:100%;opacity:0;cursor:pointer}.ew-model-picker:focus-within{outline:2px solid #bf845d;outline-offset:1px}
108406
+ .ew-file-control{display:inline-flex;flex-wrap:wrap;align-items:center;gap:4px;max-width:100%}.ew-files .ew-preview-toggle{padding:3px 6px;font-size:12px}
108407
+ .ew .ew-content[data-preview=false]{min-height:0}.ew .ew-content[data-preview=false] .ew-inspect{flex:1;width:auto;max-height:none}.ew .ew-content[data-preview=false] .ew-main{min-height:0}
108408
+ .ew-content{display:flex;flex:1;flex-direction:column;min-height:260px}.ew-content .ew-main{min-width:0}
108409
+ @container(min-width:800px){.ew-content{flex-direction:row}.ew-content .ew-inspect{width:230px;max-height:100%;border-left:1px solid var(--dsw-alias-border-l2,#c4cabb)}}
108410
+ .ew{container-type:inline-size;box-sizing:border-box;height:100%;min-height:0;display:flex;flex-direction:column;overflow:auto;background:var(--dsw-alias-bg-layer-1,#f7f4ed);color:var(--dsw-alias-label-primary,#213b30);font-size:13px;line-height:1.5;font-family:inherit}
108411
+ .ew-main{display:flex;flex:1;min-height:220px}.ew-main[data-manufacture=true] .ew-drawings{order:2;flex:1;min-width:0}.ew-manufacture{min-width:0}.ew *{box-sizing:border-box}.ew p{margin:12px}.ew button,.ew select,.ew input{font:inherit;color:inherit}
108412
+ .ew button,.ew select,.ew input:not([type=checkbox]){background:var(--dsw-alias-bg-layer-1,#faf8f1);border:1px solid var(--dsw-alias-border-l2,#abbcac);border-radius:4px;padding:4px 8px}
108413
+ .ew button{cursor:pointer}.ew button:disabled{opacity:.45;cursor:default}.ew :focus-visible{outline:2px solid #bf845d;outline-offset:1px}
108414
+ .ew-head,.ew-tools,.ew-files,.ew-inspect header,.ew-manufacture header,.ew-manufacture footer{display:flex;align-items:center;gap:8px;padding:8px 12px;flex-wrap:wrap}
108415
+ .ew-head{min-height:32px;padding-block:3px;padding-right:76px;background:#153f35;color:#faf3df;flex:none}
108416
+ .ew-head span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:40%}.ew-head select,.ew-head button{background:#204d40;border-color:#739181;color:#fff5e2}.ew-head select{max-width:48%}
108417
+ .ew button[aria-pressed=true]{background:#235642;color:#fff8e9;border-color:#386c53}
108418
+ .ew-tools,.ew-files{font-size:12px;padding-block:5px}.ew-files label{max-width:100%}.ew-files select{max-width:min(240px,70cqw)}.ew-drawings{display:flex;flex:1 0 200px;min-height:200px;padding:6px;gap:5px}.ew-pane{display:flex;flex-direction:column;flex:1;min-width:0;background:var(--dsw-alias-bg-base);border:1px solid var(--dsw-alias-border-l2,#bac8bc);border-radius:5px;overflow:hidden}.ew [hidden]{display:none!important}
108419
+ .ew-stage{position:relative;flex:1;min-height:140px}.ew-surface{position:absolute;inset:0;overflow:hidden}.ew-message{position:absolute;inset:15px;display:grid;place-content:center;text-align:center;pointer-events:none}.ew-pane small,.ew-inspect small{padding:3px 8px}
108420
+ .ew-inspect{padding:0 0 8px;border-top:1px solid var(--dsw-alias-border-l2,#c4cabb);max-height:32%;overflow:auto;flex:none}.ew-inspect input:not([type=checkbox]){width:130px}.ew-details,.ew-inspect>label{padding:2px 12px}.ew-details details span{display:inline-block;margin:2px 10px 2px 0}
108421
+ .ew-manufacture{display:flex;flex:1;min-height:180px;flex-direction:column}.ew-manufacture header{justify-content:space-between}.ew-table-wrap{overflow:auto;flex:1}
108422
+ .ew table{border-collapse:collapse;width:100%;text-align:left;font-size:12px}.ew th,.ew td{padding:6px 10px;border-bottom:1px solid var(--dsw-alias-border-l2,#c9d0c5)}.ew th{position:sticky;top:0;background:var(--dsw-alias-bg-layer-2,#e4e9de)}.ew tr[data-selected=true]{box-shadow:inset 3px 0 #ca906a;background:var(--dsw-alias-button-primary-dimmed)}
108423
+ @container(max-width:580px){.ew-main[data-manufacture=true]{flex-direction:column-reverse;min-height:440px}.ew-drawings[data-review=true]{flex-direction:column;min-height:310px}.ew-head{padding-right:68px}.ew-tools,.ew-files{gap:4px}}
108424
+ .ew[data-view=manufacture] .ew-main{flex-direction:column;min-height:0}
108425
+ .ew[data-view=manufacture] .ew-drawings{flex:0 1 26%;min-height:140px}
108426
+ .ew-manufacture{flex:1 1 300px;min-height:220px;overflow:auto}
108427
+ .ew-pricing input{width:6em}.ew-manufacture .ew-pricing{justify-content:flex-start}
108428
+ .ew-prices{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;padding:8px 12px;margin:0;border-block:1px solid var(--dsw-alias-border-l2,#bac8bc)}
108429
+ .ew-prices dt,.ew-manufacture td small{font-size:12px}.ew-prices dd{margin:2px 0;font-weight:600;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}
108430
+ .ew-manufacture td{vertical-align:top}.ew-manufacture td small{display:block;margin-top:3px}.ew-manufacture td select{max-width:18em}
108431
+ .ew-fab-file{display:flex;flex:1;min-height:160px;flex-direction:column}.ew-fab-file select{max-width:65cqw}
108432
+ .ew-fab-file header{justify-content:flex-start}.ew-gerber{display:grid;flex:1;min-height:160px;place-items:center;background:#15332c}.ew-gerber img{width:100%;height:100%;max-height:65vh;min-height:140px;object-fit:contain}
108433
+ .ew-coordinates{overflow:auto;flex:1;margin:0;padding:12px;white-space:pre;font:12px/1.6 ui-monospace,monospace}
108434
+
108435
+ .ew-manufacture[data-manufacturing-tab=BOM] {
108436
+ --bom-line: var(--dsw-alias-border-l2,#bac8bc);
108437
+ --bom-surface: var(--dsw-alias-bg-layer-1,#faf8f2);
108438
+ --bom-head: var(--dsw-alias-bg-layer-2,#e7ece5);
108439
+ --bom-accent: var(--dsw-alias-label-primary,currentColor);
108440
+ }
108441
+ .ew-manufacture[data-manufacturing-tab=BOM] .ew-prices {gap:0;padding:5px 0}
108442
+ .ew-manufacture[data-manufacturing-tab=BOM] .ew-prices div {padding:1px 12px}
108443
+ .ew-manufacture[data-manufacturing-tab=BOM] .ew-prices div+div {border-inline-start:1px solid var(--bom-line)}
108444
+ .ew-bom-grid {min-width:0;min-height:155px;flex:1;display:flex;flex-direction:column}
108445
+ .ew-bom-bar {display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:6px 10px;border-bottom:1px solid var(--bom-line)}
108446
+ .ew-bom-bar>span {font-size:11px;font-variant-numeric:tabular-nums;opacity:.78}
108447
+ .ew-bom-bar input {margin-inline-start:auto;width:min(15em,46cqw);min-width:8em}
108448
+ .ew-bom-bar input,.ew-bom-bar button {font-size:12px}
108449
+ .ew-bom-scroll {min-width:0;min-height:80px;flex:1;overflow:auto;overscroll-behavior:contain}
108450
+ .ew .ew-bom-table {border-collapse:separate;border-spacing:0;table-layout:fixed;font-size:12px;line-height:1.35}
108451
+ .ew-bom-table thead {position:sticky;top:0;z-index:2}
108452
+ .ew .ew-bom-table th,.ew .ew-bom-table td {padding:0 8px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border-inline-end:1px solid var(--bom-line);border-bottom:1px solid var(--bom-line);vertical-align:middle}
108453
+ .ew .ew-bom-table th {position:relative;top:auto;background:var(--bom-head);font-weight:600;text-align:start;user-select:none}
108454
+ .ew .ew-bom-groups th {height:21px;font-size:11px;background:var(--bom-surface);color:var(--bom-accent);box-shadow:inset 0 2px #588572}
108455
+ .ew .ew-bom-groups th[data-group=采购方案] {box-shadow:inset 0 2px #b8855b}
108456
+ .ew .ew-bom-table th[scope=col] {height:27px;padding:0}
108457
+ .ew-bom-heading {display:block;overflow:hidden;text-overflow:ellipsis;padding:5px 8px;cursor:grab}
108458
+ .ew-bom-heading:active {cursor:grabbing}
108459
+ .ew-bom-resize {position:absolute;top:0;bottom:0;right:0;width:9px;touch-action:none;cursor:col-resize}
108460
+ .ew-bom-resize::after {content:'';position:absolute;right:0;top:20%;bottom:20%;width:2px;background:var(--bom-line)}
108461
+ .ew-bom-resize:is(:hover,:focus-visible,:active)::after,.ew-bom-table th[data-drop]::before {background:#c98e5d}
108462
+ .ew-bom-table th[data-drop]::before {content:'';position:absolute;inset:0 auto 0 0;width:3px}
108463
+ .ew-bom-table th[data-drop=after]::before {left:auto;right:0}
108464
+ .ew .ew-bom-table td {height:27px;font-variant-numeric:tabular-nums}
108465
+ .ew-bom-table tbody tr:nth-child(even) {background:color-mix(in srgb,currentColor 3%,transparent)}
108466
+ .ew-bom-table tbody tr:hover {background:color-mix(in srgb,currentColor 8%,transparent)}
108467
+ .ew .ew-bom-table tbody tr[data-selected=true] {background:color-mix(in srgb,#769f87 26%,var(--bom-surface));box-shadow:none}
108468
+ .ew-bom-table tr[data-selected=true] td:first-child {box-shadow:inset 3px 0 #c58c60}
108469
+ .ew-bom-table td:is([data-col=qty],[data-col=stock],[data-col=moq],[data-col=unit],[data-col=batch]) {text-align:end}
108470
+ .ew .ew-bom-table button.ew-bom-ref,.ew .ew-bom-table td select {display:block;width:100%;font:inherit;text-align:start;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border:0;border-radius:0;padding:2px 0;background:transparent}
108471
+ .ew .ew-bom-table td select option {background:var(--bom-surface);color:var(--bom-accent)}
108472
+ .ew-bom-ref:hover {text-decoration:underline}
108473
+ .ew-bom-empty {opacity:.45}
108474
+ .ew-bom-status::before {content:'';display:inline-block;vertical-align:1px;margin-right:5px;width:5px;height:5px;border-radius:50%;background:currentColor;opacity:.5}
108475
+ .ew-bom-status[data-state=已匹配]::before {background:#4da478;opacity:1}
108476
+ .ew-bom-status:is([data-state=待确认],[data-state=未报价],[data-state=查询失败])::before {background:#c48c48;opacity:1}
108477
+
108478
+ `;
108479
+ //#endregion
108480
+ //#region src/pages.ts
108481
+ const baseId = "@huaqiu/dsh-engineering-workbench";
108482
+ const baseKind = "huaqiu-engineering-workbench";
108483
+ const pages = {
108484
+ design: {
108485
+ title: "电路设计",
108486
+ id: baseId,
108487
+ kind: baseKind
108488
+ },
108489
+ mechanical: {
108490
+ title: "结构设计",
108491
+ id: baseId + "/mechanical",
108492
+ kind: baseKind + "-mechanical"
108493
+ },
108494
+ review: {
108495
+ title: "评审",
108496
+ id: baseId + "/review",
108497
+ kind: baseKind + "-review"
108498
+ },
108499
+ manufacture: {
108500
+ title: "制造",
108501
+ id: baseId + "/manufacture",
108502
+ kind: baseKind + "-manufacture"
108503
+ }
108504
+ };
108505
+ const views = Object.keys(pages);
108506
+ //#endregion
108507
+ //#region src/Workbench.tsx
108508
+ const drawingNames = {
108509
+ pcb: "PCB",
108510
+ schematic: "原理图"
108511
+ };
108512
+ function Workbench(props) {
108513
+ const cwd = props.useSessions((s) => s.byId[props.sessionId]?.cwd);
108514
+ const nav = props.useTabInfo().tab.navigation;
108515
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Workspace, {
108516
+ cwd: cwd ?? "",
108517
+ session: props.sessionId,
108518
+ view: props.view,
108519
+ selection: props.selectionFor(props.sessionId),
108520
+ nav: nav.params,
108521
+ open: props.open,
108522
+ draft: props.draft
108523
+ }, props.sessionId + (cwd ?? ""));
108524
+ }
108525
+ function Workspace({ cwd, session, view, selection, nav, open, draft }) {
108526
+ const [data, setData] = (0, react.useState)();
108527
+ const [reload, setReload] = (0, react.useState)(0);
108528
+ const [error, setError] = (0, react.useState)("");
108529
+ const [projectPath, setProjectPath] = (0, react.useState)(selection.project ?? "");
108530
+ const [request, setRequest] = (0, react.useState)();
108531
+ const lastNav = (0, react.useRef)("");
108532
+ (0, react.useEffect)(() => {
108533
+ let live = true;
108534
+ setError("");
108535
+ loadProjects(cwd, void 0, session).then((result) => {
108536
+ if (live) setData(result);
108537
+ }).catch((e) => {
108538
+ if (live) {
108539
+ setData(void 0);
108540
+ setError(messageOf(e));
108541
+ }
108542
+ });
108543
+ return () => {
108544
+ live = false;
108545
+ };
108546
+ }, [
108547
+ cwd,
108548
+ session,
108549
+ reload
108550
+ ]);
108551
+ const projects = data?.projects ?? [];
108552
+ const active = projects.find((p) => p.path === projectPath) ?? data?.selected ?? (projects.length === 1 ? projects[0] : void 0);
108553
+ (0, react.useEffect)(() => {
108554
+ if (!data || !nav || nav.view !== view || !validRequest(nav) || !nav.requestId || lastNav.current === nav.requestId) return;
108555
+ lastNav.current = nav.requestId;
108556
+ let candidates = data.projects ?? [];
108557
+ if (nav.project) candidates = candidates.filter((p) => matches(p.path, nav.project));
108558
+ if (nav.path) candidates = candidates.filter((p) => {
108559
+ const files = filesOf(p);
108560
+ return [...files.boards, ...files.sheets].some((f) => matches(f.path, nav.path));
108561
+ });
108562
+ if (nav.path || nav.project) {
108563
+ if (candidates.length !== 1) {
108564
+ setError(candidates.length ? "多个工程匹配,请指定完整路径。" : "当前工作区未找到指定文件或工程。");
108565
+ return;
108566
+ }
108567
+ setProjectPath(candidates[0].path);
108568
+ }
108569
+ setError("");
108570
+ setRequest(nav);
108571
+ }, [
108572
+ data,
108573
+ nav,
108574
+ view
108575
+ ]);
108576
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
108577
+ className: "ew",
108578
+ "aria-label": pages[view].title,
108579
+ "data-view": view,
108580
+ children: [
108581
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: styles }),
108582
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
108583
+ className: "ew-head",
108584
+ children: [projects.length > 1 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
108585
+ "aria-label": "当前工程",
108586
+ value: active?.path ?? "",
108587
+ onChange: (e) => {
108588
+ if (active || !request?.designTool) setRequest(void 0);
108589
+ setError("");
108590
+ setProjectPath(e.target.value);
108591
+ Object.assign(selection, {
108592
+ project: e.target.value,
108593
+ board: void 0,
108594
+ sheet: void 0,
108595
+ reference: void 0,
108596
+ kind: void 0
108597
+ });
108598
+ },
108599
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
108600
+ value: "",
108601
+ disabled: true,
108602
+ children: "选择工程"
108603
+ }), projects.map((p) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("option", {
108604
+ value: p.path,
108605
+ children: [
108606
+ p.name,
108607
+ " · ",
108608
+ p.path
108609
+ ]
108610
+ }, p.path))]
108611
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
108612
+ title: active?.path,
108613
+ children: active?.name ?? basename(cwd)
108614
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
108615
+ onClick: () => setReload((n) => n + 1),
108616
+ children: "刷新"
108617
+ })]
108618
+ }),
108619
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
108620
+ role: "alert",
108621
+ children: error
108622
+ }),
108623
+ active ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Project, {
108624
+ view,
108625
+ selection,
108626
+ project: active,
108627
+ cwd: data?.cwd || cwd,
108628
+ session,
108629
+ request,
108630
+ open,
108631
+ draft
108632
+ }, active.path) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
108633
+ role: "status",
108634
+ children: !data && !error ? "正在查找 KiCad 工程…" : projects.length ? "请选择要查看的工程。" : "当前工作区没有可用的 KiCad 工程。"
108635
+ })
108636
+ ]
108637
+ });
108638
+ }
108639
+ function Project({ project, cwd, session, view, selection, request, open, draft }) {
108640
+ const { boards, sheets } = filesOf(project);
108641
+ const seed = selection.project === project.path ? selection : {};
108642
+ const preferSchematic = view === "design" && sheets.length > 0 || boards.length === 0;
108643
+ const [kind, setKind] = (0, react.useState)(seed.kind ?? (preferSchematic ? "schematic" : "pcb"));
108644
+ const [awaiting3d, setAwaiting3d] = (0, react.useState)(false);
108645
+ const [manufacturingTab, setManufacturingTab] = (0, react.useState)("BOM");
108646
+ const [boardPath, setBoard] = (0, react.useState)(boards.find((f) => f.path === seed.board)?.path || project.defaultBoard || (boards.length === 1 ? boards[0].path : ""));
108647
+ const [sheetPath, setSheet] = (0, react.useState)(sheets.find((f) => f.path === seed.sheet)?.path || project.rootSheet?.path || project.schematic?.path || sheets[0]?.path || "");
108648
+ const [reference, setReference] = (0, react.useState)(seed.reference ?? "");
108649
+ const [parsedBoard, setParsedBoard] = (0, react.useState)();
108650
+ const [message, setMessage] = (0, react.useState)("");
108651
+ const [visited, setVisited] = (0, react.useState)({});
108652
+ const [closed, setClosed] = (0, react.useState)({
108653
+ pcb: false,
108654
+ schematic: false
108655
+ });
108656
+ const [records, setRecords] = (0, react.useState)([]);
108657
+ const seen = (0, react.useRef)("");
108658
+ const board = boards.find((f) => f.path === boardPath);
108659
+ const sheet = sheets.find((f) => f.path === sheetPath);
108660
+ const boardKey = boardPath + "@" + (board?.revision ?? "");
108661
+ const parts = parsedBoard?.key === boardKey ? parsedBoard.parts : [];
108662
+ const rememberParts = (0, react.useCallback)((parts) => setParsedBoard({
108663
+ key: boardKey,
108664
+ parts
108665
+ }), [boardKey]);
108666
+ (0, react.useEffect)(() => {
108667
+ if (!request?.requestId || seen.current === request.requestId) return;
108668
+ seen.current = request.requestId;
108669
+ const next = {
108670
+ project: project.path,
108671
+ board: boardPath,
108672
+ sheet: sheetPath,
108673
+ reference,
108674
+ kind
108675
+ };
108676
+ setAwaiting3d(false);
108677
+ if (request.path) {
108678
+ const targets = [...boards, ...sheets].filter((f) => matches(f.path, request.path));
108679
+ if (targets.length !== 1) {
108680
+ setMessage("文件路径不唯一或已移除,请手动选择。");
108681
+ return;
108682
+ }
108683
+ const target = targets[0];
108684
+ const targetKind = boards.includes(target) ? "pcb" : "schematic";
108685
+ setClosed((prev) => ({
108686
+ ...prev,
108687
+ [targetKind]: false
108688
+ }));
108689
+ if (boards.includes(target)) {
108690
+ if (target.path !== boardPath) {
108691
+ setReference("");
108692
+ next.reference = "";
108693
+ }
108694
+ setBoard(target.path);
108695
+ setKind("pcb");
108696
+ next.board = target.path;
108697
+ next.kind = "pcb";
108698
+ } else {
108699
+ setSheet(target.path);
108700
+ setKind("schematic");
108701
+ next.sheet = target.path;
108702
+ next.kind = "schematic";
108703
+ }
108704
+ }
108705
+ setMessage("");
108706
+ if (view === "design" && request.designTool) {
108707
+ const tool = request.designTool;
108708
+ const drawing = tool === "3d" ? "pcb" : tool;
108709
+ next.kind = drawing;
108710
+ setKind(drawing);
108711
+ setClosed((prev) => ({
108712
+ ...prev,
108713
+ [drawing]: false
108714
+ }));
108715
+ if (tool === "3d" && boards.some((b) => b.path === next.board)) open(session, "hardware-engineering", {
108716
+ destination: "3d",
108717
+ path: next.board,
108718
+ projectPath: project.path
108719
+ });
108720
+ else if (tool === "3d" && boards.length) {
108721
+ setAwaiting3d(true);
108722
+ setMessage("请选择要在 3D 中查看的板文件。");
108723
+ } else if (!(drawing === "pcb" ? boards : sheets).length) setMessage(drawing === "pcb" ? "当前工程没有板文件。" : "当前工程没有原理图文件。");
108724
+ }
108725
+ if (request.reference) {
108726
+ next.reference = request.reference.trim().toUpperCase();
108727
+ setReference(next.reference);
108728
+ }
108729
+ Object.assign(selection, next);
108730
+ }, [
108731
+ request,
108732
+ boards,
108733
+ sheets
108734
+ ]);
108735
+ const showPcb = !!board && !closed.pcb && (view !== "design" || kind === "pcb") && (view !== "manufacture" || manufacturingTab === "BOM");
108736
+ const showSch = !!sheet && !closed.schematic && (view === "review" || view === "design" && kind === "schematic");
108737
+ const hasPreview = showPcb || showSch;
108738
+ (0, react.useEffect)(() => {
108739
+ setVisited((prev) => ({
108740
+ ...prev,
108741
+ pcb: prev.pcb || showPcb,
108742
+ schematic: prev.schematic || showSch
108743
+ }));
108744
+ }, [showPcb, showSch]);
108745
+ const selected = parts.find((p) => p.ref.toUpperCase() === reference.toUpperCase());
108746
+ const inspectPath = (kind === "pcb" ? board : sheet)?.path;
108747
+ const ask = () => {
108748
+ try {
108749
+ draft(session, "请结合当前工程回答:" + project.name + "\n文件:" + (view === "manufacture" ? sheetPath : inspectPath || project.path) + (reference ? "\n位号:" + reference : "") + "\n");
108750
+ setMessage("已加入左侧对话草稿。");
108751
+ } catch (e) {
108752
+ setMessage(messageOf(e));
108753
+ }
108754
+ };
108755
+ function nativeOpen() {
108756
+ if (inspectPath) openArtifact({
108757
+ application: "kicad",
108758
+ artifactPath: inspectPath,
108759
+ projectPath: project.path,
108760
+ kind,
108761
+ session
108762
+ }).catch((e) => setMessage(messageOf(e)));
108763
+ }
108764
+ function remember(updates) {
108765
+ Object.assign(selection, {
108766
+ project: project.path,
108767
+ board: boardPath,
108768
+ sheet: sheetPath,
108769
+ kind,
108770
+ reference
108771
+ }, updates);
108772
+ }
108773
+ function chooseReference(value) {
108774
+ setReference(value);
108775
+ remember({ reference: value });
108776
+ }
108777
+ function chooseKind(value) {
108778
+ setAwaiting3d(false);
108779
+ setMessage("");
108780
+ setKind(value);
108781
+ remember({ kind: value });
108782
+ setClosed((prev) => ({
108783
+ ...prev,
108784
+ [value]: false
108785
+ }));
108786
+ }
108787
+ const selectFile = (type, path) => {
108788
+ setClosed((prev) => ({
108789
+ ...prev,
108790
+ [type]: false
108791
+ }));
108792
+ if (type === "pcb") {
108793
+ setBoard(path);
108794
+ setReference("");
108795
+ } else setSheet(path);
108796
+ setKind(type);
108797
+ setMessage("");
108798
+ remember(type === "pcb" ? {
108799
+ board: path,
108800
+ reference: "",
108801
+ kind: type
108802
+ } : {
108803
+ sheet: path,
108804
+ kind: type
108805
+ });
108806
+ if (type === "pcb" && awaiting3d) {
108807
+ setAwaiting3d(false);
108808
+ open(session, "hardware-engineering", {
108809
+ destination: "3d",
108810
+ path,
108811
+ projectPath: project.path
108812
+ });
108813
+ }
108814
+ };
108815
+ const order = () => {
108816
+ if (!board) {
108817
+ setMessage("请先选择要下单的板文件。");
108818
+ return;
108819
+ }
108820
+ open(session, "hardware-engineering", {
108821
+ destination: "order",
108822
+ path: board.path,
108823
+ projectPath: project.path,
108824
+ schematicPath: project.rootSheet?.path || project.schematic?.path
108825
+ });
108826
+ };
108827
+ const recordKey = [
108828
+ boardPath,
108829
+ board?.revision,
108830
+ sheetPath,
108831
+ sheet?.revision,
108832
+ reference.trim().toUpperCase()
108833
+ ].join(" · ");
108834
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
108835
+ view === "design" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
108836
+ className: "ew-tools",
108837
+ children: [
108838
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
108839
+ "aria-pressed": kind === "schematic",
108840
+ onClick: () => chooseKind("schematic"),
108841
+ children: "原理图"
108842
+ }),
108843
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
108844
+ "aria-pressed": kind === "pcb",
108845
+ onClick: () => chooseKind("pcb"),
108846
+ children: "PCB"
108847
+ }),
108848
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
108849
+ disabled: !board,
108850
+ onClick: () => open(session, "hardware-engineering", {
108851
+ destination: "3d",
108852
+ path: boardPath,
108853
+ projectPath: project.path
108854
+ }),
108855
+ children: "板级 3D ↗"
108856
+ }),
108857
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
108858
+ disabled: !inspectPath,
108859
+ onClick: nativeOpen,
108860
+ children: "在 KiCad 中打开 ↗"
108861
+ })
108862
+ ]
108863
+ }),
108864
+ view === "manufacture" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
108865
+ className: "ew-tools",
108866
+ "aria-label": "制造文件",
108867
+ children: manufacturingTabs.map((tab) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
108868
+ "aria-pressed": tab === manufacturingTab,
108869
+ onClick: () => setManufacturingTab(tab),
108870
+ children: tab
108871
+ }, tab))
108872
+ }),
108873
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
108874
+ className: "ew-files",
108875
+ children: ["schematic", "pcb"].filter((type) => (view !== "design" || kind === type) && (view !== "manufacture" || manufacturingTab === "BOM" || type === "pcb")).map((type) => {
108876
+ const files = type === "pcb" ? boards : sheets;
108877
+ const file = type === "pcb" ? board : sheet;
108878
+ const action = closed[type] ? "打开" : "关闭";
108879
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
108880
+ className: "ew-file-control",
108881
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [
108882
+ type === "pcb" ? "板文件" : "原理图",
108883
+ " ",
108884
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
108885
+ value: file?.path || "",
108886
+ onChange: (e) => selectFile(type, e.target.value),
108887
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
108888
+ value: "",
108889
+ disabled: true,
108890
+ children: "选择文件"
108891
+ }), files.map((f) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
108892
+ value: f.path,
108893
+ children: basename(f.path)
108894
+ }, f.path))]
108895
+ })
108896
+ ] }), file && (view !== "manufacture" || type === "pcb" && manufacturingTab === "BOM") && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
108897
+ type: "button",
108898
+ className: "ew-preview-toggle",
108899
+ "aria-label": action + drawingNames[type] + "预览",
108900
+ title: action + drawingNames[type] + "预览",
108901
+ onClick: () => setClosed((prev) => ({
108902
+ ...prev,
108903
+ [type]: !prev[type]
108904
+ })),
108905
+ children: [action, "预览"]
108906
+ })]
108907
+ }, type);
108908
+ })
108909
+ }),
108910
+ message && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
108911
+ role: "status",
108912
+ children: message
108913
+ }),
108914
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
108915
+ className: "ew-content",
108916
+ "data-preview": hasPreview,
108917
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
108918
+ className: "ew-main",
108919
+ "data-manufacture": view === "manufacture",
108920
+ hidden: !hasPreview && view !== "manufacture",
108921
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
108922
+ className: "ew-drawings",
108923
+ hidden: !hasPreview,
108924
+ "data-review": showPcb && showSch,
108925
+ children: ["schematic", "pcb"].map((type) => {
108926
+ const visible = type === "pcb" ? showPcb : showSch;
108927
+ const file = type === "pcb" ? board : sheet;
108928
+ if (!file || closed[type] || !visible && !visited[type]) return null;
108929
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
108930
+ className: "ew-pane",
108931
+ hidden: !visible,
108932
+ children: [view === "review" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: type === "pcb" ? "PCB" : "原理图" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Drawing, {
108933
+ kind: type,
108934
+ path: file.path,
108935
+ session,
108936
+ cwd,
108937
+ onParts: type === "pcb" ? rememberParts : void 0
108938
+ }, file.path + "@" + (file.revision ?? ""))]
108939
+ }, type);
108940
+ })
108941
+ }), view === "manufacture" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Manufacture, {
108942
+ tab: manufacturingTab,
108943
+ path: sheet?.path || "",
108944
+ board: board?.path || "",
108945
+ cwd,
108946
+ session,
108947
+ reference,
108948
+ location: selected?.location,
108949
+ select: chooseReference,
108950
+ ask,
108951
+ order
108952
+ }, JSON.stringify([
108953
+ sheet?.path,
108954
+ sheet?.revision,
108955
+ boardKey
108956
+ ]))]
108957
+ }), view !== "manufacture" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
108958
+ className: "ew-inspect",
108959
+ children: [
108960
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", { children: [
108961
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: view === "review" ? "评审记录" : "对象属性" }),
108962
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
108963
+ list: "ew-refs-" + view + "-" + session,
108964
+ "aria-label": "位号",
108965
+ placeholder: "输入位号,如 J1",
108966
+ value: reference,
108967
+ onChange: (e) => chooseReference(e.target.value)
108968
+ }),
108969
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("datalist", {
108970
+ id: "ew-refs-" + view + "-" + session,
108971
+ children: parts.map((p, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", { value: p.ref }, i))
108972
+ }),
108973
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
108974
+ onClick: ask,
108975
+ children: "询问助手"
108976
+ })
108977
+ ] }),
108978
+ selected && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
108979
+ className: "ew-details",
108980
+ children: [
108981
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: selected.ref }),
108982
+ " ",
108983
+ selected.value,
108984
+ " · ",
108985
+ selected.footprint,
108986
+ selected.location && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: selected.location }),
108987
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", { children: [
108988
+ "焊盘与网络(",
108989
+ selected.pins.length,
108990
+ ")"
108991
+ ] }), selected.pins.map((p, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
108992
+ p.number,
108993
+ " ",
108994
+ p.net
108995
+ ] }, i))] })
108996
+ ]
108997
+ }),
108998
+ reference && !selected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: "当前已读 PCB 中未找到此位号。" }),
108999
+ view === "review" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [
109000
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
109001
+ type: "checkbox",
109002
+ disabled: !board || !sheet || !reference,
109003
+ checked: records.includes(recordKey),
109004
+ onChange: (e) => setRecords((prev) => e.target.checked ? [...prev, recordKey] : prev.filter((k) => k !== recordKey))
109005
+ }),
109006
+ " 当前文件对 · ",
109007
+ reference || "选定位号",
109008
+ " 已复核"
109009
+ ] })
109010
+ ]
109011
+ })]
109012
+ })
109013
+ ] });
109014
+ }
109015
+ //#endregion
109016
+ //#region src/caption-menu.ts
109017
+ /** The Windows caption is created by the desktop preload, sometimes after the plugins. */
109018
+ function installCaptionMenu(mounted, activate) {
109019
+ let bar;
109020
+ let menu;
109021
+ function closeMenu(restoreFocus = false) {
109022
+ if (!menu) return;
109023
+ const popup = menu;
109024
+ menu = void 0;
109025
+ popup.remove();
109026
+ buttons[0].setAttribute("aria-expanded", "false");
109027
+ if (restoreFocus) buttons[0].focus();
109028
+ }
109029
+ function showMenu(focusLast = false) {
109030
+ const trigger = buttons[0];
109031
+ if (!bar || trigger.disabled) return;
109032
+ closeMenu();
109033
+ const popup = document.createElement("div");
109034
+ popup.id = "engineering-design-menu";
109035
+ popup.setAttribute("role", "menu");
109036
+ popup.setAttribute("aria-label", "设计");
109037
+ const rect = trigger.getBoundingClientRect();
109038
+ Object.assign(popup.style, {
109039
+ position: "fixed",
109040
+ top: rect.bottom + "px",
109041
+ left: rect.left + "px",
109042
+ minWidth: "124px",
109043
+ display: "grid",
109044
+ padding: "4px",
109045
+ border: "1px solid var(--dsw-alias-border-l2)",
109046
+ borderRadius: "6px",
109047
+ background: "var(--dsw-alias-bg-layer-1)",
109048
+ boxShadow: "0 4px 14px #0002"
109049
+ });
109050
+ for (const view of ["design", "mechanical"]) {
109051
+ const item = document.createElement("button");
109052
+ item.type = "button";
109053
+ item.tabIndex = -1;
109054
+ item.setAttribute("role", "menuitem");
109055
+ item.textContent = pages[view].title;
109056
+ item.style.textAlign = "start";
109057
+ item.onclick = () => {
109058
+ closeMenu(true);
109059
+ const session = mounted.getSnapshot();
109060
+ if (session !== void 0) activate(session, view);
109061
+ };
109062
+ popup.append(item);
109063
+ }
109064
+ popup.onkeydown = (e) => {
109065
+ const items = Array.from(popup.querySelectorAll("button"));
109066
+ if (e.key === "Escape") closeMenu(true);
109067
+ else if ([
109068
+ "ArrowDown",
109069
+ "ArrowUp",
109070
+ "Home",
109071
+ "End"
109072
+ ].includes(e.key)) {
109073
+ const index = items.indexOf(e.target);
109074
+ items[e.key === "Home" ? 0 : e.key === "End" ? 1 : 1 - index]?.focus();
109075
+ } else return;
109076
+ e.preventDefault();
109077
+ e.stopPropagation();
109078
+ };
109079
+ popup.addEventListener("focusout", (e) => {
109080
+ if (!popup.contains(e.relatedTarget)) closeMenu();
109081
+ });
109082
+ bar.after(popup);
109083
+ menu = popup;
109084
+ trigger.setAttribute("aria-expanded", "true");
109085
+ popup.querySelector(focusLast ? "button:last-child" : "button")?.focus();
109086
+ }
109087
+ const buttons = [
109088
+ "design",
109089
+ "review",
109090
+ "manufacture"
109091
+ ].map((view) => {
109092
+ const button = document.createElement("button");
109093
+ button.type = "button";
109094
+ button.setAttribute("role", "menuitem");
109095
+ button.tabIndex = -1;
109096
+ button.textContent = view === "design" ? "设计" : pages[view].title;
109097
+ if (view === "design") {
109098
+ button.setAttribute("aria-haspopup", "menu");
109099
+ button.setAttribute("aria-controls", "engineering-design-menu");
109100
+ button.setAttribute("aria-expanded", "false");
109101
+ button.onkeydown = (e) => {
109102
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
109103
+ e.preventDefault();
109104
+ e.stopPropagation();
109105
+ showMenu(e.key === "ArrowUp");
109106
+ }
109107
+ };
109108
+ }
109109
+ button.onpointerdown = button.onmousedown = (event) => event.preventDefault();
109110
+ button.onclick = () => {
109111
+ if (view === "design") {
109112
+ if (menu) closeMenu(true);
109113
+ else showMenu();
109114
+ return;
109115
+ }
109116
+ closeMenu();
109117
+ const session = mounted.getSnapshot();
109118
+ if (session !== void 0) activate(session, view);
109119
+ };
109120
+ return button;
109121
+ });
109122
+ const update = () => {
109123
+ closeMenu();
109124
+ const disabled = mounted.getSnapshot() === void 0;
109125
+ for (const button of buttons) {
109126
+ button.disabled = disabled;
109127
+ button.title = disabled ? "请先打开会话" : "打开" + button.textContent + "页面";
109128
+ }
109129
+ };
109130
+ const move = (event) => {
109131
+ if (event.key !== "ArrowRight" && event.key !== "ArrowLeft") return;
109132
+ const items = Array.from(bar.querySelectorAll("button[role=menuitem]:enabled"));
109133
+ const index = items.indexOf(event.target);
109134
+ if (index < 0) return;
109135
+ const next = items[(index + (event.key === "ArrowRight" ? 1 : -1) + items.length) % items.length];
109136
+ if (!buttons.includes(items[index]) && !buttons.includes(next)) return;
109137
+ event.preventDefault();
109138
+ event.stopPropagation();
109139
+ for (const item of items) item.tabIndex = item === next ? 0 : -1;
109140
+ next.focus();
109141
+ };
109142
+ const detach = () => {
109143
+ closeMenu();
109144
+ bar?.removeEventListener("keydown", move, true);
109145
+ if (bar && buttons.some((b) => b.tabIndex === 0)) {
109146
+ const first = bar.querySelector("button[aria-haspopup=menu]");
109147
+ if (first) first.tabIndex = 0;
109148
+ }
109149
+ for (const button of buttons) {
109150
+ button.remove();
109151
+ button.tabIndex = -1;
109152
+ }
109153
+ bar = void 0;
109154
+ };
109155
+ const mount = () => {
109156
+ const next = (document.querySelector("[data-windows-menu]")?.shadowRoot)?.querySelector("[role=menubar]");
109157
+ if (next === bar) return;
109158
+ detach();
109159
+ const anchor = next?.querySelector("button[data-place-order]");
109160
+ if (!next || !anchor) return;
109161
+ bar = next;
109162
+ for (const button of buttons) next.insertBefore(button, anchor);
109163
+ next.addEventListener("keydown", move, true);
109164
+ update();
109165
+ };
109166
+ const observer = new MutationObserver(mount);
109167
+ const dismiss = (e) => {
109168
+ if (menu && !e.composedPath().includes(menu) && !e.composedPath().includes(buttons[0])) closeMenu();
109169
+ };
109170
+ document.addEventListener("pointerdown", dismiss, true);
109171
+ observer.observe(document.body, { childList: true });
109172
+ const unsubscribe = mounted.subscribe(update);
109173
+ mount();
109174
+ return () => {
109175
+ document.removeEventListener("pointerdown", dismiss, true);
109176
+ observer.disconnect();
109177
+ unsubscribe();
109178
+ detach();
109179
+ };
109180
+ }
108365
109181
  /**
108366
109182
  * @license
108367
109183
  * Copyright 2010-2026 Three.js Authors
@@ -140733,897 +141549,372 @@ void main() {
140733
141549
  color.setRGB(r, g, b, SRGBColorSpace);
140734
141550
  colors[componentIdx] = color.r;
140735
141551
  colors[componentIdx + 1] = color.g;
140736
- colors[componentIdx + 2] = color.b;
140737
- }
140738
- }
140739
- }
140740
- geometry.setAttribute("position", new BufferAttribute(vertices, 3));
140741
- geometry.setAttribute("normal", new BufferAttribute(normals, 3));
140742
- if (hasColors) {
140743
- geometry.setAttribute("color", new BufferAttribute(colors, 3));
140744
- geometry.hasColors = true;
140745
- geometry.alpha = alpha;
140746
- }
140747
- return geometry;
140748
- }
140749
- function parseASCII(data) {
140750
- const geometry = new BufferGeometry();
140751
- const patternSolid = /solid([\s\S]*?)endsolid/g;
140752
- const patternFace = /facet([\s\S]*?)endfacet/g;
140753
- const patternName = /solid\s(.+)/;
140754
- let faceCounter = 0;
140755
- const patternFloat = /[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source;
140756
- const patternVertex = new RegExp("vertex" + patternFloat + patternFloat + patternFloat, "g");
140757
- const patternNormal = new RegExp("normal" + patternFloat + patternFloat + patternFloat, "g");
140758
- const vertices = [];
140759
- const normals = [];
140760
- const groupNames = [];
140761
- const normal = new Vector3();
140762
- let result;
140763
- let groupCount = 0;
140764
- let startVertex = 0;
140765
- let endVertex = 0;
140766
- while ((result = patternSolid.exec(data)) !== null) {
140767
- startVertex = endVertex;
140768
- const solid = result[0];
140769
- const name = (result = patternName.exec(solid)) !== null ? result[1] : "";
140770
- groupNames.push(name);
140771
- while ((result = patternFace.exec(solid)) !== null) {
140772
- let vertexCountPerFace = 0;
140773
- let normalCountPerFace = 0;
140774
- const text = result[0];
140775
- while ((result = patternNormal.exec(text)) !== null) {
140776
- normal.x = parseFloat(result[1]);
140777
- normal.y = parseFloat(result[2]);
140778
- normal.z = parseFloat(result[3]);
140779
- normalCountPerFace++;
140780
- }
140781
- while ((result = patternVertex.exec(text)) !== null) {
140782
- vertices.push(parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3]));
140783
- normals.push(normal.x, normal.y, normal.z);
140784
- vertexCountPerFace++;
140785
- endVertex++;
140786
- }
140787
- if (normalCountPerFace !== 1) console.error("THREE.STLLoader: Something isn't right with the normal of face number " + faceCounter);
140788
- if (vertexCountPerFace !== 3) console.error("THREE.STLLoader: Something isn't right with the vertices of face number " + faceCounter);
140789
- faceCounter++;
140790
- }
140791
- const start = startVertex;
140792
- const count = endVertex - startVertex;
140793
- geometry.userData.groupNames = groupNames;
140794
- geometry.addGroup(start, count, groupCount);
140795
- groupCount++;
140796
- }
140797
- geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
140798
- geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
140799
- return geometry;
140800
- }
140801
- function ensureString(buffer) {
140802
- if (typeof buffer !== "string") return new TextDecoder().decode(buffer);
140803
- return buffer;
140804
- }
140805
- function ensureBinary(buffer) {
140806
- if (typeof buffer === "string") {
140807
- const array_buffer = new Uint8Array(buffer.length);
140808
- for (let i = 0; i < buffer.length; i++) array_buffer[i] = buffer.charCodeAt(i) & 255;
140809
- return array_buffer.buffer || array_buffer;
140810
- } else return buffer;
140811
- }
140812
- const binData = ensureBinary(data);
140813
- return isBinary(binData) ? parseBinary(binData) : parseASCII(ensureString(data));
140814
- }
140815
- };
140816
- //#endregion
140817
- //#region ../dsh-hardware-ui/src/client/mesh-file.ts
140818
- const meshFileTypes = ".stl,.obj";
140819
- function parseMeshFile(name, bytes) {
140820
- if (/\.obj$/i.test(name)) return new OBJLoader().parse(new TextDecoder().decode(bytes));
140821
- if (!/\.stl$/i.test(name)) throw new Error("请选择 STL 或 OBJ 文件。");
140822
- const header = new TextDecoder("ascii").decode(bytes.slice(0, 9));
140823
- const binary = bytes.byteLength >= 84 && 84 + new DataView(bytes).getUint32(80, true) * 50 === bytes.byteLength;
140824
- if (bytes.byteLength < 84 || !binary && !header.includes("solid")) throw new Error("STL 文件不完整或格式无效。");
140825
- const geometry = new STLLoader().parse(bytes);
140826
- if (!geometry.getAttribute("normal") || !binary) geometry.computeVertexNormals();
140827
- return new Mesh(geometry, new MeshStandardMaterial({
140828
- side: 2,
140829
- vertexColors: geometry.hasAttribute("color")
140830
- }));
140831
- }
140832
- //#endregion
140833
- //#region src/Mechanical.tsx
140834
- function Mechanical({ file, onFile }) {
140835
- const host = (0, react.useRef)(null);
140836
- const [status, setStatus] = (0, react.useState)("");
140837
- (0, react.useEffect)(() => {
140838
- if (!file) return;
140839
- const controller = new AbortController();
140840
- let preview;
140841
- async function load(modelFile) {
140842
- if (modelFile.size > 33554432) throw new Error("请选择不超过 32 MiB 的模型文件。");
140843
- const bytes = await modelFile.arrayBuffer();
140844
- if (controller.signal.aborted) return;
140845
- preview = mountModel(parseMeshFile(modelFile.name, bytes), host.current, { signal: controller.signal });
140846
- setStatus("");
140847
- }
140848
- setStatus("正在读取模型…");
140849
- load(file).catch((error) => {
140850
- if (!controller.signal.aborted) setStatus("无法预览模型。" + (error instanceof Error ? error.message : String(error)));
140851
- });
140852
- return () => {
140853
- controller.abort();
140854
- preview?.dispose();
140855
- };
140856
- }, [file]);
140857
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
140858
- className: "ew-files",
140859
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
140860
- className: "ew-model-picker",
140861
- children: ["选择模型", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
140862
- type: "file",
140863
- accept: meshFileTypes,
140864
- onChange: (event) => {
140865
- const selected = event.target.files?.[0];
140866
- if (selected) onFile(selected);
140867
- event.target.value = "";
140868
- }
140869
- })]
140870
- }), file && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
140871
- className: "ew-model-info",
140872
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: file.name }), !status && " · 拖动旋转,滚轮缩放"]
140873
- })]
140874
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
140875
- className: "ew-pane ew-model",
140876
- "aria-label": "结构件预览",
140877
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
140878
- className: "ew-stage",
140879
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
140880
- className: "ew-surface",
140881
- ref: host
140882
- }), (!file || status) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
140883
- className: "ew-message",
140884
- role: "status",
140885
- children: status || "选择 STL 或 OBJ 文件,预览外壳或结构件。"
140886
- })]
140887
- })
140888
- })] });
140889
- }
140890
- const MODES = [
140891
- "design",
140892
- "review",
140893
- "manufacture"
140894
- ];
140895
- function validRequest(value) {
140896
- return !!value && MODES.includes(value.view) && (value.designTool === void 0 || value.view === "design" && [
140897
- "schematic",
140898
- "pcb",
140899
- "3d",
140900
- "mechanical"
140901
- ].includes(value.designTool)) && (value.action === void 0 || ["open", "suggest"].includes(value.action)) && [
140902
- value.path,
140903
- value.project,
140904
- value.reference
140905
- ].every((s) => s === void 0 || typeof s === "string" && s.trim() && s.length <= 4096) && (value.path === void 0 || /\.kicad_(pcb|sch)$/i.test(value.path)) && (value.project === void 0 || /\.kicad_pro$/i.test(value.project));
140906
- }
140907
- function requestsIn(nodes) {
140908
- const requests = /* @__PURE__ */ new Map();
140909
- const visit = (node) => {
140910
- if (!node || typeof node !== "object") return;
140911
- if (node.kind === "tool-result" && node.call?.name === "hardware_open_workbench" && Array.isArray(node.content)) for (const block of node.content) {
140912
- if (block.type !== "text") continue;
140913
- try {
140914
- const value = JSON.parse(block.text);
140915
- if (validRequest(value) && typeof value.requestId === "string" && Number.isFinite(value.issuedAt)) requests.set(value.requestId, value);
140916
- } catch {}
140917
- }
140918
- for (const key of [
140919
- "children",
140920
- "nodes",
140921
- "subCalls"
140922
- ]) if (Array.isArray(node[key])) node[key].forEach(visit);
140923
- };
140924
- nodes.forEach(visit);
140925
- return [...requests.values()];
140926
- }
140927
- //#endregion
140928
- //#region src/styles.ts
140929
- const styles = `
140930
- .ew-model{margin:0 6px 6px;min-height:180px}.ew-model-info{overflow-wrap:anywhere}.ew-model-picker{position:relative;cursor:pointer;padding:4px 8px;border:1px solid var(--dsw-alias-border-l2,#abbcac);border-radius:4px}.ew-model-picker input{position:absolute;inset:0;width:100%;height:100%;opacity:0;cursor:pointer}.ew-model-picker:focus-within{outline:2px solid #bf845d;outline-offset:1px}
140931
- .ew-file-control{display:inline-flex;flex-wrap:wrap;align-items:center;gap:4px;max-width:100%}.ew-files .ew-preview-toggle{padding:3px 6px;font-size:12px}
140932
- .ew .ew-content[data-preview=false]{min-height:0}.ew .ew-content[data-preview=false] .ew-inspect{flex:1;width:auto;max-height:none}.ew .ew-content[data-preview=false] .ew-main{min-height:0}
140933
- .ew-content{display:flex;flex:1;flex-direction:column;min-height:260px}.ew-content .ew-main{min-width:0}
140934
- @container(min-width:800px){.ew-content{flex-direction:row}.ew-content .ew-inspect{width:230px;max-height:100%;border-left:1px solid var(--dsw-alias-border-l2,#c4cabb)}}
140935
- .ew{container-type:inline-size;box-sizing:border-box;height:100%;min-height:0;display:flex;flex-direction:column;overflow:auto;background:var(--dsw-alias-bg-layer-1,#f7f4ed);color:var(--dsw-alias-label-primary,#213b30);font-size:13px;line-height:1.5;font-family:inherit}
140936
- .ew-main{display:flex;flex:1;min-height:220px}.ew-main[data-manufacture=true] .ew-drawings{order:2;flex:1;min-width:0}.ew-manufacture{min-width:0}.ew *{box-sizing:border-box}.ew p{margin:12px}.ew button,.ew select,.ew input{font:inherit;color:inherit}
140937
- .ew button,.ew select,.ew input:not([type=checkbox]){background:var(--dsw-alias-bg-layer-1,#faf8f1);border:1px solid var(--dsw-alias-border-l2,#abbcac);border-radius:4px;padding:4px 8px}
140938
- .ew button{cursor:pointer}.ew button:disabled{opacity:.45;cursor:default}.ew :focus-visible{outline:2px solid #bf845d;outline-offset:1px}
140939
- .ew-head,.ew-tools,.ew-files,.ew-inspect header,.ew-manufacture header,.ew-manufacture footer{display:flex;align-items:center;gap:8px;padding:8px 12px;flex-wrap:wrap}
140940
- .ew-head{min-height:32px;padding-block:3px;padding-right:76px;background:#153f35;color:#faf3df;flex:none}
140941
- .ew-head span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:40%}.ew-head select,.ew-head button{background:#204d40;border-color:#739181;color:#fff5e2}.ew-head select{max-width:48%}
140942
- .ew button[aria-pressed=true]{background:#235642;color:#fff8e9;border-color:#386c53}
140943
- .ew-tools,.ew-files{font-size:12px;padding-block:5px}.ew-files label{max-width:100%}.ew-files select{max-width:min(240px,70cqw)}.ew-drawings{display:flex;flex:1 0 200px;min-height:200px;padding:6px;gap:5px}.ew-pane{display:flex;flex-direction:column;flex:1;min-width:0;background:var(--dsw-alias-bg-base);border:1px solid var(--dsw-alias-border-l2,#bac8bc);border-radius:5px;overflow:hidden}.ew [hidden]{display:none!important}
140944
- .ew-stage{position:relative;flex:1;min-height:140px}.ew-surface{position:absolute;inset:0;overflow:hidden}.ew-message{position:absolute;inset:15px;display:grid;place-content:center;text-align:center;pointer-events:none}.ew-pane small,.ew-inspect small{padding:3px 8px}
140945
- .ew-inspect{padding:0 0 8px;border-top:1px solid var(--dsw-alias-border-l2,#c4cabb);max-height:32%;overflow:auto;flex:none}.ew-inspect input:not([type=checkbox]){width:130px}.ew-details,.ew-inspect>label{padding:2px 12px}.ew-details details span{display:inline-block;margin:2px 10px 2px 0}
140946
- .ew-manufacture{display:flex;flex:1;min-height:180px;flex-direction:column}.ew-manufacture header{justify-content:space-between}.ew-table-wrap{overflow:auto;flex:1}
140947
- .ew table{border-collapse:collapse;width:100%;text-align:left;font-size:12px}.ew th,.ew td{padding:6px 10px;border-bottom:1px solid var(--dsw-alias-border-l2,#c9d0c5)}.ew th{position:sticky;top:0;background:var(--dsw-alias-bg-layer-2,#e4e9de)}.ew tr[data-selected=true]{box-shadow:inset 3px 0 #ca906a;background:var(--dsw-alias-button-primary-dimmed)}
140948
- @container(max-width:580px){.ew-main[data-manufacture=true]{flex-direction:column-reverse;min-height:440px}.ew-drawings[data-review=true]{flex-direction:column;min-height:310px}.ew-head{padding-right:68px}.ew-tools,.ew-files{gap:4px}}
140949
- .ew[data-view=manufacture] .ew-main{flex-direction:column;min-height:0}
140950
- .ew[data-view=manufacture] .ew-drawings{flex:0 1 26%;min-height:140px}
140951
- .ew-manufacture{flex:1 1 300px;min-height:220px;overflow:auto}
140952
- .ew-pricing input{width:6em}.ew-manufacture .ew-pricing{justify-content:flex-start}
140953
- .ew-prices{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;padding:8px 12px;margin:0;border-block:1px solid var(--dsw-alias-border-l2,#bac8bc)}
140954
- .ew-prices dt,.ew-manufacture td small{font-size:12px}.ew-prices dd{margin:2px 0;font-weight:600;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}
140955
- .ew-manufacture td{vertical-align:top}.ew-manufacture td small{display:block;margin-top:3px}.ew-manufacture td select{max-width:18em}
140956
- .ew-fab-file{display:flex;flex:1;min-height:160px;flex-direction:column}.ew-fab-file select{max-width:65cqw}
140957
- .ew-fab-file header{justify-content:flex-start}.ew-gerber{display:grid;flex:1;min-height:160px;place-items:center;background:#15332c}.ew-gerber img{width:100%;height:100%;max-height:65vh;min-height:140px;object-fit:contain}
140958
- .ew-coordinates{overflow:auto;flex:1;margin:0;padding:12px;white-space:pre;font:12px/1.6 ui-monospace,monospace}
140959
-
140960
- .ew-manufacture[data-manufacturing-tab=BOM] {
140961
- --bom-line: var(--dsw-alias-border-l2,#bac8bc);
140962
- --bom-surface: var(--dsw-alias-bg-layer-1,#faf8f2);
140963
- --bom-head: var(--dsw-alias-bg-layer-2,#e7ece5);
140964
- --bom-accent: var(--dsw-alias-label-primary,currentColor);
140965
- }
140966
- .ew-manufacture[data-manufacturing-tab=BOM] .ew-prices {gap:0;padding:5px 0}
140967
- .ew-manufacture[data-manufacturing-tab=BOM] .ew-prices div {padding:1px 12px}
140968
- .ew-manufacture[data-manufacturing-tab=BOM] .ew-prices div+div {border-inline-start:1px solid var(--bom-line)}
140969
- .ew-bom-grid {min-width:0;min-height:155px;flex:1;display:flex;flex-direction:column}
140970
- .ew-bom-bar {display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:6px 10px;border-bottom:1px solid var(--bom-line)}
140971
- .ew-bom-bar>span {font-size:11px;font-variant-numeric:tabular-nums;opacity:.78}
140972
- .ew-bom-bar input {margin-inline-start:auto;width:min(15em,46cqw);min-width:8em}
140973
- .ew-bom-bar input,.ew-bom-bar button {font-size:12px}
140974
- .ew-bom-scroll {min-width:0;min-height:80px;flex:1;overflow:auto;overscroll-behavior:contain}
140975
- .ew .ew-bom-table {border-collapse:separate;border-spacing:0;table-layout:fixed;font-size:12px;line-height:1.35}
140976
- .ew-bom-table thead {position:sticky;top:0;z-index:2}
140977
- .ew .ew-bom-table th,.ew .ew-bom-table td {padding:0 8px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border-inline-end:1px solid var(--bom-line);border-bottom:1px solid var(--bom-line);vertical-align:middle}
140978
- .ew .ew-bom-table th {position:relative;top:auto;background:var(--bom-head);font-weight:600;text-align:start;user-select:none}
140979
- .ew .ew-bom-groups th {height:21px;font-size:11px;background:var(--bom-surface);color:var(--bom-accent);box-shadow:inset 0 2px #588572}
140980
- .ew .ew-bom-groups th[data-group=采购方案] {box-shadow:inset 0 2px #b8855b}
140981
- .ew .ew-bom-table th[scope=col] {height:27px;padding:0}
140982
- .ew-bom-heading {display:block;overflow:hidden;text-overflow:ellipsis;padding:5px 8px;cursor:grab}
140983
- .ew-bom-heading:active {cursor:grabbing}
140984
- .ew-bom-resize {position:absolute;top:0;bottom:0;right:0;width:9px;touch-action:none;cursor:col-resize}
140985
- .ew-bom-resize::after {content:'';position:absolute;right:0;top:20%;bottom:20%;width:2px;background:var(--bom-line)}
140986
- .ew-bom-resize:is(:hover,:focus-visible,:active)::after,.ew-bom-table th[data-drop]::before {background:#c98e5d}
140987
- .ew-bom-table th[data-drop]::before {content:'';position:absolute;inset:0 auto 0 0;width:3px}
140988
- .ew-bom-table th[data-drop=after]::before {left:auto;right:0}
140989
- .ew .ew-bom-table td {height:27px;font-variant-numeric:tabular-nums}
140990
- .ew-bom-table tbody tr:nth-child(even) {background:color-mix(in srgb,currentColor 3%,transparent)}
140991
- .ew-bom-table tbody tr:hover {background:color-mix(in srgb,currentColor 8%,transparent)}
140992
- .ew .ew-bom-table tbody tr[data-selected=true] {background:color-mix(in srgb,#769f87 26%,var(--bom-surface));box-shadow:none}
140993
- .ew-bom-table tr[data-selected=true] td:first-child {box-shadow:inset 3px 0 #c58c60}
140994
- .ew-bom-table td:is([data-col=qty],[data-col=stock],[data-col=moq],[data-col=unit],[data-col=batch]) {text-align:end}
140995
- .ew .ew-bom-table button.ew-bom-ref,.ew .ew-bom-table td select {display:block;width:100%;font:inherit;text-align:start;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border:0;border-radius:0;padding:2px 0;background:transparent}
140996
- .ew .ew-bom-table td select option {background:var(--bom-surface);color:var(--bom-accent)}
140997
- .ew-bom-ref:hover {text-decoration:underline}
140998
- .ew-bom-empty {opacity:.45}
140999
- .ew-bom-status::before {content:'';display:inline-block;vertical-align:1px;margin-right:5px;width:5px;height:5px;border-radius:50%;background:currentColor;opacity:.5}
141000
- .ew-bom-status[data-state=已匹配]::before {background:#4da478;opacity:1}
141001
- .ew-bom-status:is([data-state=待确认],[data-state=未报价],[data-state=查询失败])::before {background:#c48c48;opacity:1}
141002
-
141003
- `;
141004
- //#endregion
141005
- //#region src/pages.ts
141006
- const baseId = "@huaqiu/dsh-engineering-workbench";
141007
- const baseKind = "huaqiu-engineering-workbench";
141008
- const pages = {
141009
- design: {
141010
- title: "设计",
141011
- id: baseId,
141012
- kind: baseKind
141013
- },
141014
- review: {
141015
- title: "评审",
141016
- id: baseId + "/review",
141017
- kind: baseKind + "-review"
141018
- },
141019
- manufacture: {
141020
- title: "制造",
141021
- id: baseId + "/manufacture",
141022
- kind: baseKind + "-manufacture"
141023
- }
141024
- };
141025
- const views = Object.keys(pages);
141026
- //#endregion
141027
- //#region src/Workbench.tsx
141028
- const drawingNames = {
141029
- pcb: "PCB",
141030
- schematic: "原理图"
141031
- };
141032
- function Workbench(props) {
141033
- const cwd = props.useSessions((s) => s.byId[props.sessionId]?.cwd);
141034
- const nav = props.useTabInfo().tab.navigation;
141035
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Workspace, {
141036
- cwd: cwd ?? "",
141037
- session: props.sessionId,
141038
- view: props.view,
141039
- selection: props.selectionFor(props.sessionId),
141040
- nav: nav.params,
141041
- open: props.open,
141042
- draft: props.draft
141043
- }, props.sessionId + (cwd ?? ""));
141044
- }
141045
- function Workspace({ cwd, session, view, selection, nav, open, draft }) {
141046
- const [data, setData] = (0, react.useState)();
141047
- const [reload, setReload] = (0, react.useState)(0);
141048
- const [error, setError] = (0, react.useState)("");
141049
- const [projectPath, setProjectPath] = (0, react.useState)(selection.project ?? "");
141050
- const [request, setRequest] = (0, react.useState)();
141051
- const lastNav = (0, react.useRef)("");
141052
- (0, react.useEffect)(() => {
141053
- let live = true;
141054
- setError("");
141055
- loadProjects(cwd, void 0, session).then((result) => {
141056
- if (live) setData(result);
141057
- }).catch((e) => {
141058
- if (live) {
141059
- setData(void 0);
141060
- setError(messageOf(e));
141061
- }
141062
- });
141063
- return () => {
141064
- live = false;
141065
- };
141066
- }, [
141067
- cwd,
141068
- session,
141069
- reload
141070
- ]);
141071
- const projects = data?.projects ?? [];
141072
- const active = projects.find((p) => p.path === projectPath) ?? data?.selected ?? (projects.length === 1 ? projects[0] : void 0);
141073
- (0, react.useEffect)(() => {
141074
- if (!data || !nav || nav.view !== view || !validRequest(nav) || !nav.requestId || lastNav.current === nav.requestId) return;
141075
- lastNav.current = nav.requestId;
141076
- let candidates = data.projects ?? [];
141077
- if (nav.project) candidates = candidates.filter((p) => matches(p.path, nav.project));
141078
- if (nav.path) candidates = candidates.filter((p) => {
141079
- const files = filesOf(p);
141080
- return [...files.boards, ...files.sheets].some((f) => matches(f.path, nav.path));
141081
- });
141082
- if (nav.path || nav.project) {
141083
- if (candidates.length !== 1) {
141084
- setError(candidates.length ? "多个工程匹配,请指定完整路径。" : "当前工作区未找到指定文件或工程。");
141085
- return;
141086
- }
141087
- setProjectPath(candidates[0].path);
141088
- }
141089
- setError("");
141090
- setRequest(nav);
141091
- }, [
141092
- data,
141093
- nav,
141094
- view
141095
- ]);
141096
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
141097
- className: "ew",
141098
- "aria-label": pages[view].title,
141099
- "data-view": view,
141100
- children: [
141101
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: styles }),
141102
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
141103
- className: "ew-head",
141104
- children: [projects.length > 1 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
141105
- "aria-label": "当前工程",
141106
- value: active?.path ?? "",
141107
- onChange: (e) => {
141108
- if (active || !request?.designTool) setRequest(void 0);
141109
- setError("");
141110
- setProjectPath(e.target.value);
141111
- Object.assign(selection, {
141112
- project: e.target.value,
141113
- board: void 0,
141114
- sheet: void 0,
141115
- reference: void 0,
141116
- kind: void 0
141117
- });
141118
- },
141119
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
141120
- value: "",
141121
- disabled: true,
141122
- children: "选择工程"
141123
- }), projects.map((p) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("option", {
141124
- value: p.path,
141125
- children: [
141126
- p.name,
141127
- " · ",
141128
- p.path
141129
- ]
141130
- }, p.path))]
141131
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
141132
- title: active?.path,
141133
- children: active?.name ?? basename(cwd)
141134
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
141135
- onClick: () => setReload((n) => n + 1),
141136
- children: "刷新"
141137
- })]
141138
- }),
141139
- error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
141140
- role: "alert",
141141
- children: error
141142
- }),
141143
- active ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Project, {
141144
- view,
141145
- selection,
141146
- project: active,
141147
- cwd: data?.cwd || cwd,
141148
- session,
141149
- request,
141150
- open,
141151
- draft
141152
- }, active.path) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
141153
- role: "status",
141154
- children: !data && !error ? "正在查找 KiCad 工程…" : projects.length ? "请选择要查看的工程。" : "当前工作区没有可用的 KiCad 工程。"
141155
- })
141156
- ]
141157
- });
141158
- }
141159
- function Project({ project, cwd, session, view, selection, request, open, draft }) {
141160
- const { boards, sheets } = filesOf(project);
141161
- const seed = selection.project === project.path ? selection : {};
141162
- const preferSchematic = view === "design" && sheets.length > 0 || boards.length === 0;
141163
- const [kind, setKind] = (0, react.useState)(seed.kind ?? (preferSchematic ? "schematic" : "pcb"));
141164
- const [mechanical, setMechanical] = (0, react.useState)(false);
141165
- const [awaiting3d, setAwaiting3d] = (0, react.useState)(false);
141166
- const [modelFile, setModelFile] = (0, react.useState)();
141167
- const [manufacturingTab, setManufacturingTab] = (0, react.useState)("BOM");
141168
- const showMechanical = view === "design" && mechanical;
141169
- const [boardPath, setBoard] = (0, react.useState)(boards.find((f) => f.path === seed.board)?.path || project.defaultBoard || (boards.length === 1 ? boards[0].path : ""));
141170
- const [sheetPath, setSheet] = (0, react.useState)(sheets.find((f) => f.path === seed.sheet)?.path || project.rootSheet?.path || project.schematic?.path || sheets[0]?.path || "");
141171
- const [reference, setReference] = (0, react.useState)(seed.reference ?? "");
141172
- const [parsedBoard, setParsedBoard] = (0, react.useState)();
141173
- const [message, setMessage] = (0, react.useState)("");
141174
- const [visited, setVisited] = (0, react.useState)({});
141175
- const [closed, setClosed] = (0, react.useState)({
141176
- pcb: false,
141177
- schematic: false
141178
- });
141179
- const [records, setRecords] = (0, react.useState)([]);
141180
- const seen = (0, react.useRef)("");
141181
- const board = boards.find((f) => f.path === boardPath);
141182
- const sheet = sheets.find((f) => f.path === sheetPath);
141183
- const boardKey = boardPath + "@" + (board?.revision ?? "");
141184
- const parts = parsedBoard?.key === boardKey ? parsedBoard.parts : [];
141185
- const rememberParts = (0, react.useCallback)((parts) => setParsedBoard({
141186
- key: boardKey,
141187
- parts
141188
- }), [boardKey]);
141189
- (0, react.useEffect)(() => {
141190
- if (!request?.requestId || seen.current === request.requestId) return;
141191
- seen.current = request.requestId;
141192
- const next = {
141193
- project: project.path,
141194
- board: boardPath,
141195
- sheet: sheetPath,
141196
- reference,
141197
- kind
141198
- };
141199
- setAwaiting3d(false);
141200
- if (request.path) {
141201
- const targets = [...boards, ...sheets].filter((f) => matches(f.path, request.path));
141202
- if (targets.length !== 1) {
141203
- setMessage("文件路径不唯一或已移除,请手动选择。");
141204
- return;
141205
- }
141206
- const target = targets[0];
141207
- setMechanical(false);
141208
- const targetKind = boards.includes(target) ? "pcb" : "schematic";
141209
- setClosed((prev) => ({
141210
- ...prev,
141211
- [targetKind]: false
141212
- }));
141213
- if (boards.includes(target)) {
141214
- if (target.path !== boardPath) {
141215
- setReference("");
141216
- next.reference = "";
141217
- }
141218
- setBoard(target.path);
141219
- setKind("pcb");
141220
- next.board = target.path;
141221
- next.kind = "pcb";
141222
- } else {
141223
- setSheet(target.path);
141224
- setKind("schematic");
141225
- next.sheet = target.path;
141226
- next.kind = "schematic";
141552
+ colors[componentIdx + 2] = color.b;
141553
+ }
141554
+ }
141555
+ }
141556
+ geometry.setAttribute("position", new BufferAttribute(vertices, 3));
141557
+ geometry.setAttribute("normal", new BufferAttribute(normals, 3));
141558
+ if (hasColors) {
141559
+ geometry.setAttribute("color", new BufferAttribute(colors, 3));
141560
+ geometry.hasColors = true;
141561
+ geometry.alpha = alpha;
141227
141562
  }
141563
+ return geometry;
141228
141564
  }
141229
- setMessage("");
141230
- if (view === "design" && request.designTool) {
141231
- const tool = request.designTool;
141232
- setMechanical(tool === "mechanical");
141233
- if (tool !== "mechanical") {
141234
- const drawing = tool === "3d" ? "pcb" : tool;
141235
- next.kind = drawing;
141236
- setKind(drawing);
141237
- setClosed((prev) => ({
141238
- ...prev,
141239
- [drawing]: false
141240
- }));
141241
- if (tool === "3d" && boards.some((b) => b.path === next.board)) open(session, "hardware-engineering", {
141242
- destination: "3d",
141243
- path: next.board,
141244
- projectPath: project.path
141245
- });
141246
- else if (tool === "3d" && boards.length) {
141247
- setAwaiting3d(true);
141248
- setMessage("请选择要在 3D 中查看的板文件。");
141249
- } else if (!(drawing === "pcb" ? boards : sheets).length) setMessage(drawing === "pcb" ? "当前工程没有板文件。" : "当前工程没有原理图文件。");
141565
+ function parseASCII(data) {
141566
+ const geometry = new BufferGeometry();
141567
+ const patternSolid = /solid([\s\S]*?)endsolid/g;
141568
+ const patternFace = /facet([\s\S]*?)endfacet/g;
141569
+ const patternName = /solid\s(.+)/;
141570
+ let faceCounter = 0;
141571
+ const patternFloat = /[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source;
141572
+ const patternVertex = new RegExp("vertex" + patternFloat + patternFloat + patternFloat, "g");
141573
+ const patternNormal = new RegExp("normal" + patternFloat + patternFloat + patternFloat, "g");
141574
+ const vertices = [];
141575
+ const normals = [];
141576
+ const groupNames = [];
141577
+ const normal = new Vector3();
141578
+ let result;
141579
+ let groupCount = 0;
141580
+ let startVertex = 0;
141581
+ let endVertex = 0;
141582
+ while ((result = patternSolid.exec(data)) !== null) {
141583
+ startVertex = endVertex;
141584
+ const solid = result[0];
141585
+ const name = (result = patternName.exec(solid)) !== null ? result[1] : "";
141586
+ groupNames.push(name);
141587
+ while ((result = patternFace.exec(solid)) !== null) {
141588
+ let vertexCountPerFace = 0;
141589
+ let normalCountPerFace = 0;
141590
+ const text = result[0];
141591
+ while ((result = patternNormal.exec(text)) !== null) {
141592
+ normal.x = parseFloat(result[1]);
141593
+ normal.y = parseFloat(result[2]);
141594
+ normal.z = parseFloat(result[3]);
141595
+ normalCountPerFace++;
141596
+ }
141597
+ while ((result = patternVertex.exec(text)) !== null) {
141598
+ vertices.push(parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3]));
141599
+ normals.push(normal.x, normal.y, normal.z);
141600
+ vertexCountPerFace++;
141601
+ endVertex++;
141602
+ }
141603
+ if (normalCountPerFace !== 1) console.error("THREE.STLLoader: Something isn't right with the normal of face number " + faceCounter);
141604
+ if (vertexCountPerFace !== 3) console.error("THREE.STLLoader: Something isn't right with the vertices of face number " + faceCounter);
141605
+ faceCounter++;
141606
+ }
141607
+ const start = startVertex;
141608
+ const count = endVertex - startVertex;
141609
+ geometry.userData.groupNames = groupNames;
141610
+ geometry.addGroup(start, count, groupCount);
141611
+ groupCount++;
141250
141612
  }
141613
+ geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
141614
+ geometry.setAttribute("normal", new Float32BufferAttribute(normals, 3));
141615
+ return geometry;
141251
141616
  }
141252
- if (request.reference) {
141253
- next.reference = request.reference.trim().toUpperCase();
141254
- setReference(next.reference);
141617
+ function ensureString(buffer) {
141618
+ if (typeof buffer !== "string") return new TextDecoder().decode(buffer);
141619
+ return buffer;
141255
141620
  }
141256
- Object.assign(selection, next);
141257
- }, [
141258
- request,
141259
- boards,
141260
- sheets
141261
- ]);
141262
- const showPcb = !showMechanical && !!board && !closed.pcb && (view !== "design" || kind === "pcb") && (view !== "manufacture" || manufacturingTab === "BOM");
141263
- const showSch = !showMechanical && !!sheet && !closed.schematic && (view === "review" || view === "design" && kind === "schematic");
141264
- const hasPreview = showPcb || showSch;
141265
- (0, react.useEffect)(() => {
141266
- setVisited((prev) => ({
141267
- ...prev,
141268
- pcb: prev.pcb || showPcb,
141269
- schematic: prev.schematic || showSch
141270
- }));
141271
- }, [showPcb, showSch]);
141272
- const selected = parts.find((p) => p.ref.toUpperCase() === reference.toUpperCase());
141273
- const inspectPath = (kind === "pcb" ? board : sheet)?.path;
141274
- const ask = () => {
141275
- try {
141276
- draft(session, "请结合当前工程回答:" + project.name + "\n文件:" + (view === "manufacture" ? sheetPath : inspectPath || project.path) + (reference ? "\n位号:" + reference : "") + "\n");
141277
- setMessage("已加入左侧对话草稿。");
141278
- } catch (e) {
141279
- setMessage(messageOf(e));
141621
+ function ensureBinary(buffer) {
141622
+ if (typeof buffer === "string") {
141623
+ const array_buffer = new Uint8Array(buffer.length);
141624
+ for (let i = 0; i < buffer.length; i++) array_buffer[i] = buffer.charCodeAt(i) & 255;
141625
+ return array_buffer.buffer || array_buffer;
141626
+ } else return buffer;
141280
141627
  }
141281
- };
141282
- function nativeOpen() {
141283
- if (inspectPath) openArtifact({
141284
- application: "kicad",
141285
- artifactPath: inspectPath,
141286
- projectPath: project.path,
141287
- kind,
141288
- session
141289
- }).catch((e) => setMessage(messageOf(e)));
141290
- }
141291
- function remember(updates) {
141292
- Object.assign(selection, {
141293
- project: project.path,
141294
- board: boardPath,
141295
- sheet: sheetPath,
141296
- kind,
141297
- reference
141298
- }, updates);
141299
- }
141300
- function chooseReference(value) {
141301
- setReference(value);
141302
- remember({ reference: value });
141628
+ const binData = ensureBinary(data);
141629
+ return isBinary(binData) ? parseBinary(binData) : parseASCII(ensureString(data));
141303
141630
  }
141304
- function chooseKind(value) {
141305
- setAwaiting3d(false);
141306
- setMessage("");
141307
- setMechanical(false);
141308
- setKind(value);
141309
- remember({ kind: value });
141310
- setClosed((prev) => ({
141311
- ...prev,
141312
- [value]: false
141631
+ };
141632
+ //#endregion
141633
+ //#region ../dsh-hardware-ui/src/client/mesh-file.ts
141634
+ function parseMeshFile(name, bytes) {
141635
+ if (/\.obj$/i.test(name)) return new OBJLoader().parse(new TextDecoder().decode(bytes));
141636
+ if (!/\.stl$/i.test(name)) throw new Error("请选择 STL 或 OBJ 文件。");
141637
+ const header = new TextDecoder("ascii").decode(bytes.slice(0, 9));
141638
+ const binary = bytes.byteLength >= 84 && 84 + new DataView(bytes).getUint32(80, true) * 50 === bytes.byteLength;
141639
+ if (bytes.byteLength < 84 || !binary && !header.includes("solid")) throw new Error("STL 文件不完整或格式无效。");
141640
+ const geometry = new STLLoader().parse(bytes);
141641
+ if (!geometry.getAttribute("normal") || !binary) geometry.computeVertexNormals();
141642
+ return new Mesh(geometry, new MeshStandardMaterial({
141643
+ side: 2,
141644
+ vertexColors: geometry.hasAttribute("color")
141645
+ }));
141646
+ }
141647
+ //#endregion
141648
+ //#region src/Mechanical.tsx
141649
+ const supported = (name) => /\.(stl|obj)$/i.test(name);
141650
+ const sortModels = (models) => models.sort((a, b) => a.name.localeCompare(b.name, void 0, { numeric: true }));
141651
+ async function scan(files, session, folder, signal) {
141652
+ const groups = /* @__PURE__ */ new Map();
141653
+ const named = /* @__PURE__ */ new Set();
141654
+ const pending = [{
141655
+ path: folder ?? ".",
141656
+ prefix: "",
141657
+ group: folder
141658
+ }];
141659
+ let incomplete = false;
141660
+ while (pending.length) {
141661
+ signal.throwIfAborted();
141662
+ await Promise.all(pending.splice(-4).map(async ({ path, prefix, group }) => {
141663
+ const result = await files.list(session, path, signal);
141664
+ if (!result.ok) {
141665
+ if (path !== (folder ?? ".")) {
141666
+ incomplete = true;
141667
+ return;
141668
+ }
141669
+ throw new Error(result.error.code === "workspace-file/not-found" ? "找不到该文件夹,请切换目录。" : result.error.message || "无法读取文件夹。");
141670
+ }
141671
+ incomplete ||= result.value.truncated;
141672
+ for (const entry of result.value.entries) {
141673
+ const child = path === "." ? entry.name : path.replace(/[/\\]+$/, "") + "/" + entry.name;
141674
+ if (entry.type === "directory") {
141675
+ if (!folder && [".git", "node_modules"].includes(entry.name)) continue;
141676
+ const startsGroup = !group && /^(mechanical|mechnical)$/i.test(entry.name);
141677
+ if (startsGroup) named.add(child);
141678
+ pending.push({
141679
+ path: child,
141680
+ prefix: startsGroup ? "" : prefix + entry.name + "/",
141681
+ group: startsGroup ? child : group
141682
+ });
141683
+ } else if (entry.type === "file" && supported(entry.name)) {
141684
+ const key = group ?? path;
141685
+ const models = groups.get(key) ?? [];
141686
+ models.push({
141687
+ name: group ? prefix + entry.name : entry.name,
141688
+ path: child,
141689
+ size: entry.size
141690
+ });
141691
+ groups.set(key, models);
141692
+ }
141693
+ }
141313
141694
  }));
141314
141695
  }
141315
- const selectFile = (type, path) => {
141316
- setClosed((prev) => ({
141317
- ...prev,
141318
- [type]: false
141319
- }));
141320
- if (type === "pcb") {
141321
- setBoard(path);
141322
- setReference("");
141323
- } else setSheet(path);
141324
- setKind(type);
141325
- setMessage("");
141326
- remember(type === "pcb" ? {
141327
- board: path,
141328
- reference: "",
141329
- kind: type
141330
- } : {
141331
- sheet: path,
141332
- kind: type
141333
- });
141334
- if (type === "pcb" && awaiting3d) {
141335
- setAwaiting3d(false);
141336
- open(session, "hardware-engineering", {
141337
- destination: "3d",
141338
- path,
141339
- projectPath: project.path
141340
- });
141341
- }
141696
+ const priority = (dir) => named.has(dir) ? 0 : groups.get(dir)?.some((m) => /\.stl$/i.test(m.name)) ? 1 : 2;
141697
+ const folders = Array.from(/* @__PURE__ */ new Set([...groups.keys(), ...named])).sort((a, b) => Number(!groups.has(a)) - Number(!groups.has(b)) || priority(a) - priority(b) || a.split("/").length - b.split("/").length || a.localeCompare(b, void 0, { numeric: true }));
141698
+ const resolved = folder ?? folders[0];
141699
+ return {
141700
+ folder: resolved,
141701
+ folders,
141702
+ models: sortModels(groups.get(resolved ?? "") ?? []),
141703
+ notice: incomplete ? "部分目录未能完整列出,可直接切换到对应子目录。" : void 0
141342
141704
  };
141343
- const order = () => {
141344
- if (!board) {
141345
- setMessage("请先选择要下单的板文件。");
141346
- return;
141705
+ }
141706
+ function ModelPreview({ model, files, session }) {
141707
+ const host = (0, react.useRef)(null);
141708
+ const [status, setStatus] = (0, react.useState)("正在读取模型…");
141709
+ (0, react.useEffect)(() => {
141710
+ const controller = new AbortController();
141711
+ const { signal } = controller;
141712
+ let preview;
141713
+ async function load() {
141714
+ if ((model.size ?? 0) > 33554432) throw new Error("模型超过 32 MiB。");
141715
+ let buffer;
141716
+ if (model.file) buffer = await model.file.arrayBuffer();
141717
+ else {
141718
+ if (!files) throw new Error("当前会话无法读取模型。");
141719
+ const result = await files.readBytes(session, model.path, {}, signal);
141720
+ if (!result.ok) throw new Error(result.error.message || "无法读取文件。");
141721
+ const { data, eof } = result.value;
141722
+ if (!eof || data.byteLength > 33554432) throw new Error("模型超过预览上限或文件不完整。");
141723
+ buffer = data.slice().buffer;
141724
+ }
141725
+ signal.throwIfAborted();
141726
+ preview = mountModel(parseMeshFile(model.name, buffer), host.current, { signal });
141727
+ setStatus("");
141347
141728
  }
141348
- open(session, "hardware-engineering", {
141349
- destination: "order",
141350
- path: board.path,
141351
- projectPath: project.path,
141352
- schematicPath: project.rootSheet?.path || project.schematic?.path
141729
+ setStatus("正在读取模型…");
141730
+ load().catch((e) => {
141731
+ if (!signal.aborted) setStatus("无法预览模型。" + String(e.message || e));
141353
141732
  });
141354
- };
141355
- const recordKey = [
141356
- boardPath,
141357
- board?.revision,
141358
- sheetPath,
141359
- sheet?.revision,
141360
- reference.trim().toUpperCase()
141361
- ].join(" · ");
141362
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
141363
- view === "design" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
141364
- className: "ew-tools",
141365
- children: [
141366
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
141367
- "aria-pressed": !mechanical && kind === "schematic",
141368
- onClick: () => chooseKind("schematic"),
141369
- children: "原理图"
141370
- }),
141371
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
141372
- "aria-pressed": !mechanical && kind === "pcb",
141373
- onClick: () => chooseKind("pcb"),
141374
- children: "PCB"
141375
- }),
141376
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
141377
- disabled: !board,
141378
- onClick: () => open(session, "hardware-engineering", {
141379
- destination: "3d",
141380
- path: boardPath,
141381
- projectPath: project.path
141382
- }),
141383
- children: "板级 3D ↗"
141384
- }),
141385
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
141386
- "aria-pressed": mechanical,
141387
- onClick: () => {
141388
- setAwaiting3d(false);
141389
- setMessage("");
141390
- setMechanical(true);
141391
- },
141392
- children: "结构件"
141393
- }),
141394
- !mechanical && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
141395
- disabled: !inspectPath,
141396
- onClick: nativeOpen,
141397
- children: "在 KiCad 中打开 ↗"
141398
- })
141399
- ]
141400
- }),
141401
- showMechanical && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Mechanical, {
141402
- file: modelFile,
141403
- onFile: setModelFile
141404
- }),
141405
- view === "manufacture" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
141406
- className: "ew-tools",
141407
- "aria-label": "制造文件",
141408
- children: manufacturingTabs.map((tab) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
141409
- "aria-pressed": tab === manufacturingTab,
141410
- onClick: () => setManufacturingTab(tab),
141411
- children: tab
141412
- }, tab))
141413
- }),
141414
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
141415
- className: "ew-files",
141416
- hidden: showMechanical,
141417
- children: ["schematic", "pcb"].filter((type) => (view !== "design" || kind === type) && (view !== "manufacture" || manufacturingTab === "BOM" || type === "pcb")).map((type) => {
141418
- const files = type === "pcb" ? boards : sheets;
141419
- const file = type === "pcb" ? board : sheet;
141420
- const action = closed[type] ? "打开" : "关闭";
141421
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
141422
- className: "ew-file-control",
141423
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [
141424
- type === "pcb" ? "板文件" : "原理图",
141425
- " ",
141426
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
141427
- value: file?.path || "",
141428
- onChange: (e) => selectFile(type, e.target.value),
141429
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
141430
- value: "",
141431
- disabled: true,
141432
- children: "选择文件"
141433
- }), files.map((f) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
141434
- value: f.path,
141435
- children: basename(f.path)
141436
- }, f.path))]
141437
- })
141438
- ] }), file && (view !== "manufacture" || type === "pcb" && manufacturingTab === "BOM") && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
141439
- type: "button",
141440
- className: "ew-preview-toggle",
141441
- "aria-label": action + drawingNames[type] + "预览",
141442
- title: action + drawingNames[type] + "预览",
141443
- onClick: () => setClosed((prev) => ({
141444
- ...prev,
141445
- [type]: !prev[type]
141446
- })),
141447
- children: [action, "预览"]
141448
- })]
141449
- }, type);
141450
- })
141451
- }),
141452
- message && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
141733
+ return () => {
141734
+ controller.abort();
141735
+ preview?.dispose();
141736
+ };
141737
+ }, [
141738
+ model,
141739
+ files,
141740
+ session
141741
+ ]);
141742
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
141743
+ className: "ew-stage",
141744
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
141745
+ className: "ew-surface",
141746
+ ref: host
141747
+ }), status && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
141748
+ className: "ew-message",
141453
141749
  role: "status",
141454
- children: message
141455
- }),
141456
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
141457
- className: "ew-content",
141458
- hidden: showMechanical,
141459
- "data-preview": hasPreview,
141460
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
141461
- className: "ew-main",
141462
- "data-manufacture": view === "manufacture",
141463
- hidden: !hasPreview && view !== "manufacture",
141464
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
141465
- className: "ew-drawings",
141466
- hidden: !hasPreview,
141467
- "data-review": showPcb && showSch,
141468
- children: ["schematic", "pcb"].map((type) => {
141469
- const visible = type === "pcb" ? showPcb : showSch;
141470
- const file = type === "pcb" ? board : sheet;
141471
- if (!file || closed[type] || !visible && !visited[type]) return null;
141472
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
141473
- className: "ew-pane",
141474
- hidden: !visible,
141475
- children: [view === "review" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: type === "pcb" ? "PCB" : "原理图" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Drawing, {
141476
- kind: type,
141477
- path: file.path,
141478
- session,
141479
- cwd,
141480
- onParts: type === "pcb" ? rememberParts : void 0
141481
- }, file.path + "@" + (file.revision ?? ""))]
141482
- }, type);
141483
- })
141484
- }), view === "manufacture" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Manufacture, {
141485
- tab: manufacturingTab,
141486
- path: sheet?.path || "",
141487
- board: board?.path || "",
141488
- cwd,
141489
- session,
141490
- reference,
141491
- location: selected?.location,
141492
- select: chooseReference,
141493
- ask,
141494
- order
141495
- }, JSON.stringify([
141496
- sheet?.path,
141497
- sheet?.revision,
141498
- boardKey
141499
- ]))]
141500
- }), view !== "manufacture" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
141501
- className: "ew-inspect",
141750
+ children: status
141751
+ })]
141752
+ });
141753
+ }
141754
+ function Mechanical({ files, sessionId }) {
141755
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelBrowser, {
141756
+ files,
141757
+ session: sessionId
141758
+ }, sessionId);
141759
+ }
141760
+ function ModelBrowser({ files, session }) {
141761
+ const [source, setSource] = (0, react.useState)({});
141762
+ const [draft, setDraft] = (0, react.useState)();
141763
+ const [folders, setFolders] = (0, react.useState)([]);
141764
+ const [loaded, setLoaded] = (0, react.useState)();
141765
+ const [selected, setSelected] = (0, react.useState)("");
141766
+ const picker = (0, react.useRef)(null);
141767
+ const catalog = source.local ?? (loaded?.source === source ? loaded.catalog : void 0);
141768
+ const input = draft ?? source.folder ?? catalog?.folder ?? "";
141769
+ const currentFolder = source.folder ?? catalog?.folder ?? "";
141770
+ const model = catalog?.models.find((item) => item.name === selected) ?? catalog?.models[0];
141771
+ (0, react.useEffect)(() => {
141772
+ if (source.local) return;
141773
+ const controller = new AbortController();
141774
+ (files ? scan(files, session, source.folder, controller.signal) : Promise.reject(/* @__PURE__ */ new Error("工作区目录不可用,请使用「浏览文件夹」。"))).then((catalog) => {
141775
+ if (!controller.signal.aborted) {
141776
+ if (!source.folder) setFolders(catalog.folders ?? []);
141777
+ setLoaded({
141778
+ source,
141779
+ catalog
141780
+ });
141781
+ }
141782
+ }).catch((e) => {
141783
+ if (!controller.signal.aborted) setLoaded({
141784
+ source,
141785
+ catalog: {
141786
+ models: [],
141787
+ notice: String(e.message || e)
141788
+ }
141789
+ });
141790
+ });
141791
+ return () => controller.abort();
141792
+ }, [
141793
+ source,
141794
+ files,
141795
+ session
141796
+ ]);
141797
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
141798
+ className: "ew",
141799
+ "aria-label": "结构设计",
141800
+ "data-view": "mechanical",
141801
+ children: [
141802
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: styles }),
141803
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
141804
+ className: "ew-files ew-model-folder",
141805
+ onSubmit: (e) => {
141806
+ e.preventDefault();
141807
+ if (input.trim()) setSource({ folder: input.trim() });
141808
+ },
141502
141809
  children: [
141503
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", { children: [
141504
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: view === "review" ? "评审记录" : "对象属性" }),
141505
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
141506
- list: "ew-refs-" + view + "-" + session,
141507
- "aria-label": "位号",
141508
- placeholder: "输入位号,如 J1",
141509
- value: reference,
141510
- onChange: (e) => chooseReference(e.target.value)
141511
- }),
141512
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("datalist", {
141513
- id: "ew-refs-" + view + "-" + session,
141514
- children: parts.map((p, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", { value: p.ref }, i))
141515
- }),
141516
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
141517
- onClick: ask,
141518
- children: "询问助手"
141519
- })
141520
- ] }),
141521
- selected && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
141522
- className: "ew-details",
141523
- children: [
141524
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: selected.ref }),
141525
- " ",
141526
- selected.value,
141527
- " · ",
141528
- selected.footprint,
141529
- selected.location && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: selected.location }),
141530
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", { children: [
141531
- "焊盘与网络(",
141532
- selected.pins.length,
141533
- ")"
141534
- ] }), selected.pins.map((p, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
141535
- p.number,
141536
- " ",
141537
- p.net
141538
- ] }, i))] })
141539
- ]
141810
+ folders.length > 1 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: ["已定位目录 ", /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
141811
+ value: !source.local && folders.includes(currentFolder) ? currentFolder : "",
141812
+ onChange: (e) => {
141813
+ setDraft(void 0);
141814
+ setSelected("");
141815
+ setSource({ folder: e.target.value });
141816
+ },
141817
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
141818
+ value: "",
141819
+ disabled: true,
141820
+ children: "选择目录"
141821
+ }), folders.map((dir) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
141822
+ value: dir,
141823
+ children: dir
141824
+ }, dir))]
141825
+ })] }),
141826
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: ["文件夹 ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
141827
+ value: input,
141828
+ title: input,
141829
+ onChange: (e) => setDraft(e.target.value),
141830
+ placeholder: "工作区模型目录"
141831
+ })] }),
141832
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
141833
+ type: "submit",
141834
+ disabled: !input.trim(),
141835
+ children: "打开目录"
141540
141836
  }),
141541
- reference && !selected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: "当前已读 PCB 中未找到此位号。" }),
141542
- view === "review" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [
141543
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
141544
- type: "checkbox",
141545
- disabled: !board || !sheet || !reference,
141546
- checked: records.includes(recordKey),
141547
- onChange: (e) => setRecords((prev) => e.target.checked ? [...prev, recordKey] : prev.filter((k) => k !== recordKey))
141548
- }),
141549
- " 当前文件对 · ",
141550
- reference || "选定位号",
141551
- " 已复核"
141552
- ] })
141837
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
141838
+ type: "button",
141839
+ onClick: () => {
141840
+ setSource({});
141841
+ setSelected("");
141842
+ setDraft(void 0);
141843
+ },
141844
+ children: "自动定位"
141845
+ }),
141846
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
141847
+ type: "button",
141848
+ onClick: () => picker.current?.click(),
141849
+ children: "浏览文件夹"
141850
+ }),
141851
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
141852
+ type: "file",
141853
+ hidden: true,
141854
+ multiple: true,
141855
+ ref: (el) => {
141856
+ picker.current = el;
141857
+ el?.setAttribute("webkitdirectory", "");
141858
+ },
141859
+ "aria-label": "选择本机文件夹",
141860
+ onChange: (e) => {
141861
+ const entries = Array.from(e.target.files ?? []);
141862
+ e.target.value = "";
141863
+ if (!entries.length) return;
141864
+ const folder = entries[0].webkitRelativePath.split("/")[0];
141865
+ const models = entries.filter((f) => supported(f.name)).map((file) => ({
141866
+ file,
141867
+ path: file.webkitRelativePath,
141868
+ name: file.webkitRelativePath.slice(folder.length + 1),
141869
+ size: file.size
141870
+ }));
141871
+ setDraft(void 0);
141872
+ setSource({
141873
+ folder,
141874
+ local: { models: sortModels(models) }
141875
+ });
141876
+ setSelected("");
141877
+ }
141878
+ })
141553
141879
  ]
141554
- })]
141555
- })
141556
- ] });
141557
- }
141558
- //#endregion
141559
- //#region src/caption-menu.ts
141560
- /** The Windows caption is created by the desktop preload, sometimes after the plugins. */
141561
- function installCaptionMenu(mounted, activate) {
141562
- let bar;
141563
- const buttons = views.map((view) => {
141564
- const button = document.createElement("button");
141565
- button.type = "button";
141566
- button.setAttribute("role", "menuitem");
141567
- button.tabIndex = -1;
141568
- button.textContent = pages[view].title;
141569
- button.onpointerdown = button.onmousedown = (event) => event.preventDefault();
141570
- button.onclick = () => {
141571
- const session = mounted.getSnapshot();
141572
- if (session !== void 0) activate(session, view);
141573
- };
141574
- return button;
141880
+ }),
141881
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
141882
+ className: "ew-files",
141883
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: ["结构件 ", /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
141884
+ value: model?.name ?? "",
141885
+ disabled: !model,
141886
+ onChange: (e) => setSelected(e.target.value),
141887
+ children: [!model && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
141888
+ value: "",
141889
+ children: "选择模型"
141890
+ }), catalog?.models.map((m) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
141891
+ value: m.name,
141892
+ children: m.name
141893
+ }, m.name))]
141894
+ })] }), model && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "拖动旋转,滚轮缩放" })]
141895
+ }),
141896
+ catalog?.notice && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
141897
+ role: "status",
141898
+ children: catalog.notice
141899
+ }),
141900
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
141901
+ className: "ew-pane ew-model",
141902
+ "aria-label": "结构件预览",
141903
+ children: model ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelPreview, {
141904
+ model,
141905
+ files,
141906
+ session
141907
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
141908
+ className: "ew-stage",
141909
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
141910
+ className: "ew-message",
141911
+ role: "status",
141912
+ children: !catalog ? "正在查找结构件…" : catalog.notice ? "请选择其他模型目录。" : source.folder ? "此文件夹及其子目录中没有 STL 或 OBJ 模型。" : "当前工作区中没有找到 STL 或 OBJ 模型。"
141913
+ })
141914
+ })
141915
+ })
141916
+ ]
141575
141917
  });
141576
- const update = () => {
141577
- const disabled = mounted.getSnapshot() === void 0;
141578
- for (const button of buttons) {
141579
- button.disabled = disabled;
141580
- button.title = disabled ? "请先打开会话" : "打开" + button.textContent + "页面";
141581
- }
141582
- };
141583
- const move = (event) => {
141584
- if (event.key !== "ArrowRight" && event.key !== "ArrowLeft") return;
141585
- const items = Array.from(bar.querySelectorAll("button[role=menuitem]:enabled"));
141586
- const index = items.indexOf(event.target);
141587
- if (index < 0) return;
141588
- const next = items[(index + (event.key === "ArrowRight" ? 1 : -1) + items.length) % items.length];
141589
- if (!buttons.includes(items[index]) && !buttons.includes(next)) return;
141590
- event.preventDefault();
141591
- event.stopPropagation();
141592
- for (const item of items) item.tabIndex = item === next ? 0 : -1;
141593
- next.focus();
141594
- };
141595
- const detach = () => {
141596
- bar?.removeEventListener("keydown", move, true);
141597
- if (bar && buttons.some((b) => b.tabIndex === 0)) {
141598
- const first = bar.querySelector("button[aria-haspopup=menu]");
141599
- if (first) first.tabIndex = 0;
141600
- }
141601
- for (const button of buttons) {
141602
- button.remove();
141603
- button.tabIndex = -1;
141604
- }
141605
- bar = void 0;
141606
- };
141607
- const mount = () => {
141608
- const next = (document.querySelector("[data-windows-menu]")?.shadowRoot)?.querySelector("[role=menubar]");
141609
- if (next === bar) return;
141610
- detach();
141611
- const anchor = next?.querySelector("button[data-place-order]");
141612
- if (!next || !anchor) return;
141613
- bar = next;
141614
- for (const button of buttons) next.insertBefore(button, anchor);
141615
- next.addEventListener("keydown", move, true);
141616
- update();
141617
- };
141618
- const observer = new MutationObserver(mount);
141619
- observer.observe(document.body, { childList: true });
141620
- const unsubscribe = mounted.subscribe(update);
141621
- mount();
141622
- return () => {
141623
- observer.disconnect();
141624
- unsubscribe();
141625
- detach();
141626
- };
141627
141918
  }
141628
141919
  //#endregion
141629
141920
  //#region src/ToolRail.tsx
@@ -141725,7 +142016,9 @@ void main() {
141725
142016
  "sidebarRight",
141726
142017
  "sidebarRightTabs",
141727
142018
  "sessions",
141728
- "conversation"
142019
+ "conversation",
142020
+ "remote",
142021
+ "remote.workspaceFiles"
141729
142022
  ];
141730
142023
  const EMPTY = [];
141731
142024
  function ConversationNavigation({ sessionId, useChat, useSession, open }) {
@@ -141801,7 +142094,7 @@ void main() {
141801
142094
  }
141802
142095
  function activateTool(session, tool) {
141803
142096
  const selected = selectionFor(session);
141804
- const view = tool === "review" || tool === "manufacture" ? tool : "design";
142097
+ const view = tool === "review" || tool === "manufacture" || tool === "mechanical" ? tool : "design";
141805
142098
  const path = tool === "schematic" ? selected.sheet : tool === "mechanical" ? void 0 : selected.board;
141806
142099
  open(session, pages[view].kind, {
141807
142100
  view,
@@ -141840,13 +142133,13 @@ void main() {
141840
142133
  ctx.effect(() => ctx.slots.inject("sidebar.right.pane.tab", () => ctx.slots.register({
141841
142134
  name: "sidebar.right.pane.tab",
141842
142135
  key: id,
141843
- inject: () => ({
142136
+ inject: () => view === "mechanical" ? { files: ctx.remote?.workspaceFiles } : {
141844
142137
  open,
141845
142138
  draft,
141846
142139
  view,
141847
142140
  selectionFor
141848
- })
141849
- }, Workbench)), "engineering page: " + view);
142141
+ }
142142
+ }, view === "mechanical" ? Mechanical : Workbench)), "engineering page: " + view);
141850
142143
  }
141851
142144
  ctx.effect(() => installCaptionMenu(ctx.sidebarRight.mounted, (session, view) => {
141852
142145
  open(session, pages[view].kind);