| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038 |
- import {
- connectorPinGroups,
- findCandidates,
- generateAdcSnippet,
- sameNetPins,
- searchBoard,
- } from "./board-logic.mjs";
- const SVG_NS = "http://www.w3.org/2000/svg";
- const state = {
- data: null,
- runtime: {status: "loading", recommendationsEnabled: false, adcCopyEnabled: false, staleSources: []},
- categories: new Set(["CON", "J", "PL", "TP"]),
- selectedTouchpoint: null,
- selectedPin: null,
- baseViewBox: null,
- viewBox: null,
- dragging: null,
- activeTab: "detail",
- searchResults: [],
- activeSearchIndex: -1,
- };
- const dom = Object.fromEntries(
- [
- "app",
- "app-status",
- "board-summary",
- "board-search",
- "search-results",
- "stale-banner",
- "category-filters",
- "layer-controls",
- "zoom-in",
- "zoom-out",
- "reset-view",
- "board-viewport",
- "board-svg",
- "board-loading",
- "board-tooltip",
- "hotspot-layer",
- "pin-layer",
- "net-layer",
- "selection-layer",
- "layer-mask",
- "layer-silk",
- "layer-copper",
- "layer-photo",
- "photo-control",
- "photo-layer",
- "photo-label",
- "visible-count",
- "zoom-readout",
- "selection-readout",
- "detail-panel",
- "detail-tab",
- "candidate-tab",
- "detail-content",
- "candidate-content",
- "candidate-list",
- "capability-select",
- "drawer-toggle",
- ].map((id) => [id, document.getElementById(id)]),
- );
- function svgElement(name, attributes = {}) {
- const node = document.createElementNS(SVG_NS, name);
- for (const [key, value] of Object.entries(attributes)) node.setAttribute(key, String(value));
- return node;
- }
- function element(name, className = "", content = null) {
- const node = document.createElement(name);
- if (className) node.className = className;
- if (content != null) node.textContent = String(content);
- return node;
- }
- function formatNumber(value, digits = 3) {
- const number = Number(value);
- return Number.isFinite(number) ? number.toFixed(digits).replace(/\.0+$|(?<=\.[0-9]*?)0+$/g, "") : "未知";
- }
- function evidenceLabel(tier) {
- return {
- board_database: "板数据库原始值",
- cross_verified: "已交叉验证",
- name_inferred: "名称推断",
- unknown: "未知",
- }[tier] ?? "未知";
- }
- function directionLabel(direction) {
- return {
- input: "输入",
- output: "输出",
- bidirectional: "双向",
- passive: "无源",
- unknown: "未知",
- }[direction] ?? direction ?? "未知";
- }
- function activeLevelLabel(level) {
- return {
- high: "高电平有效",
- low: "低电平有效",
- rising_edge: "上升沿计步脉冲",
- state: "状态选择(非有效电平)",
- unknown: "未注明",
- }[level] ?? level ?? "未注明";
- }
- function categoryLabel(category) {
- return {CON: "连接器", J: "J 类对象", PL: "PL 器件", TP: "测试点"}[category] ?? category;
- }
- function touchpointKindLabel(touchpoint) {
- if (touchpoint?.connector) return touchpoint.category === "CON" ? "连接器" : "调试接口";
- if (touchpoint?.category === "PL") return "电源器件";
- if (touchpoint?.category === "J") {
- const pins = Array.isArray(touchpoint.pins) ? touchpoint.pins : [];
- if (pins.length && pins.every((pin) => pin.mechanical === true)) return "安装孔";
- if (pins.some((pin) => pin.function_category === "manufacturing_mark")) return "制造标记";
- }
- return categoryLabel(touchpoint?.category);
- }
- function padRoleLabel(role) {
- return {
- contact: "接触针",
- shield: "屏蔽固定焊盘",
- mechanical: "机械孔",
- unknown: "未分类焊盘",
- }[role] ?? "未分类焊盘";
- }
- function touchpointPinSummary(touchpoint) {
- if (touchpoint.connector) {
- return `${touchpoint.connector.contact_count} 接触针 · ${touchpoint.connector.auxiliary_pad_count} 辅助焊盘`;
- }
- return `${touchpoint.pins.length} 针`;
- }
- function setStatus(kind, text) {
- dom["app-status"].className = `status-badge status-${kind}`;
- dom["app-status"].textContent = text;
- }
- function applyRuntimeStatus() {
- const runtime = state.runtime;
- if (runtime.status === "pass") {
- setStatus("pass", "数据已校验");
- dom["stale-banner"].hidden = true;
- } else if (runtime.status === "stale_sources") {
- setStatus("stale", "来源已变化");
- dom["stale-banner"].hidden = false;
- dom["stale-banner"].textContent = `源文件与生成时不一致:${(runtime.staleSources ?? []).join(",")}。选脚推荐与 ADC 复制已关闭。`;
- } else {
- setStatus("error", "资产不可用");
- dom["stale-banner"].hidden = false;
- dom["stale-banner"].textContent = runtime.message || "生成资产未通过完整性校验。";
- }
- }
- async function loadApplication() {
- try {
- const [dataResponse, statusResponse] = await Promise.all([
- fetch("/generated/board-data.json", {cache: "no-store"}),
- fetch("/api/status", {cache: "no-store"}),
- ]);
- if (!dataResponse.ok) throw new Error(`板数据 HTTP ${dataResponse.status}`);
- if (!statusResponse.ok) throw new Error(`状态 HTTP ${statusResponse.status}`);
- state.data = await dataResponse.json();
- state.runtime = await statusResponse.json();
- initializeBoard();
- applyRuntimeStatus();
- } catch (error) {
- state.runtime = {
- status: "error",
- recommendationsEnabled: false,
- adcCopyEnabled: false,
- staleSources: [],
- message: error instanceof Error ? error.message : String(error),
- };
- applyRuntimeStatus();
- dom["board-loading"].textContent = "板数据载入失败";
- renderEmptyDetail("板数据不可用", state.runtime.message);
- }
- }
- function initializeBoard() {
- const {board, counts} = state.data;
- const width = Number(board.view_box.width);
- const height = Number(board.view_box.height);
- const padding = Math.max(height * 0.08, 1.2);
- state.baseViewBox = {x: -padding, y: -padding, width: width + padding * 2, height: height + padding * 2};
- state.viewBox = {...state.baseViewBox};
- for (const image of [dom["layer-mask"], dom["layer-silk"], dom["layer-copper"], dom["layer-photo"]]) {
- image.setAttribute("x", "0");
- image.setAttribute("y", "0");
- image.setAttribute("width", String(width));
- image.setAttribute("height", String(height));
- }
- dom["board-summary"].textContent = `${board.name} · ${counts.touchpoints} 座子 · ${counts.connector_contacts} 个 CON 接触针`;
- dom["board-loading"].hidden = true;
- updateViewBox();
- renderBoardMarkers();
- configurePhotoOverlay();
- renderEmptyDetail("未选择座子", `${counts.touchpoints} 个座子 · ${counts.connector_contacts} 个 CON 接触针 · ${counts.connector_auxiliary_pads} 个 CON 辅助焊盘`);
- renderCandidates();
- }
- function configurePhotoOverlay() {
- const overlay = state.data?.photo_overlay;
- if (!overlay) return;
- const matrix = Array.isArray(overlay.matrix) ? overlay.matrix : [];
- if (matrix.length !== 6 || !matrix.every(Number.isFinite)) return;
- const source = `/generated/${overlay.asset}`;
- const image = new Image();
- image.addEventListener("load", () => {
- dom["layer-photo"].setAttribute("href", source);
- dom["layer-photo"].setAttribute("width", String(image.naturalWidth));
- dom["layer-photo"].setAttribute("height", String(image.naturalHeight));
- dom["layer-photo"].setAttribute("transform", `matrix(${matrix.join(" ")})`);
- dom["photo-layer"].disabled = false;
- dom["photo-control"].classList.remove("disabled-control");
- dom["photo-control"].title = `已校准 ${overlay.control_point_count} 个控制点`;
- dom["photo-label"].textContent = "照片";
- });
- image.addEventListener("error", () => {
- dom["photo-control"].title = "照片资产载入失败";
- dom["photo-label"].textContent = "照片不可用";
- });
- image.src = source;
- }
- function updateViewBox() {
- if (!state.viewBox) return;
- const {x, y, width, height} = state.viewBox;
- dom["board-svg"].setAttribute("viewBox", `${x} ${y} ${width} ${height}`);
- const ratio = state.baseViewBox.width / width;
- const pinsInteractive = ratio >= 1.8;
- dom["board-svg"].classList.toggle("pins-interactive", pinsInteractive);
- for (const group of dom["pin-layer"].querySelectorAll(".pin-group")) {
- group.setAttribute("tabindex", pinsInteractive ? "0" : "-1");
- }
- dom["zoom-readout"].textContent = `${Math.round(ratio * 100)}%`;
- }
- function effectiveBounds(bounds, minimum = 3.2) {
- const width = Math.max(Number(bounds.width), minimum);
- const height = Math.max(Number(bounds.height), minimum);
- return {
- x: Number(bounds.x) - (width - Number(bounds.width)) / 2,
- y: Number(bounds.y) - (height - Number(bounds.height)) / 2,
- width,
- height,
- };
- }
- function renderBoardMarkers() {
- dom["hotspot-layer"].replaceChildren();
- dom["pin-layer"].replaceChildren();
- if (!state.data) return;
- let visible = 0;
- for (const touchpoint of state.data.touchpoints) {
- if (!state.categories.has(touchpoint.category)) continue;
- visible += 1;
- const bounds = effectiveBounds(touchpoint.view_bounds);
- const hotspot = svgElement("rect", {
- x: bounds.x,
- y: bounds.y,
- width: bounds.width,
- height: bounds.height,
- rx: 0.45,
- class: `hotspot${state.selectedTouchpoint?.reference === touchpoint.reference ? " is-selected" : ""}`,
- tabindex: 0,
- role: "button",
- "aria-label": `${touchpoint.reference} ${touchpointKindLabel(touchpoint)} ${touchpointPinSummary(touchpoint)}`,
- "data-reference": touchpoint.reference,
- });
- hotspot.addEventListener("pointerenter", (event) => showTouchpointTooltip(event, touchpoint));
- hotspot.addEventListener("pointermove", positionTooltip);
- hotspot.addEventListener("pointerleave", hideTooltip);
- hotspot.addEventListener("focus", () => showTouchpointTooltip(null, touchpoint));
- hotspot.addEventListener("blur", hideTooltip);
- hotspot.addEventListener("click", (event) => {
- event.stopPropagation();
- selectTouchpoint(touchpoint, null, true);
- });
- hotspot.addEventListener("keydown", (event) => {
- if (event.key === "Enter" || event.key === " ") {
- event.preventDefault();
- selectTouchpoint(touchpoint, null, true);
- }
- });
- dom["hotspot-layer"].append(hotspot);
- for (const pin of touchpoint.pins) {
- const group = svgElement("g", {
- class: `pin-group role-${pin.pad_role}${state.selectedTouchpoint?.reference === touchpoint.reference && state.selectedPin?.id === pin.id ? " is-selected" : ""}`,
- tabindex: dom["board-svg"].classList.contains("pins-interactive") ? 0 : -1,
- role: "button",
- "aria-label": `${touchpoint.reference}.${pin.number || "机械"} ${pin.net || "无网络"}`,
- "data-reference": touchpoint.reference,
- "data-pin": pin.number,
- "data-pin-id": pin.id,
- "data-pad-role": pin.pad_role,
- });
- const width = Math.max(Number(pin.size.width), Number(pin.size.drill_width), 0.65);
- const height = Math.max(Number(pin.size.height), Number(pin.size.drill_height), 0.65);
- const radius = Math.max(Math.min(width, height) / 2, 0.42);
- const hitRadius = Math.max(Math.min(width, height) / 2 + 0.15, 0.58);
- group.append(
- svgElement("circle", {cx: pin.view_position.x, cy: pin.view_position.y, r: hitRadius, class: "pin-hit"}),
- svgElement("circle", {cx: pin.view_position.x, cy: pin.view_position.y, r: radius, class: "pin-dot"}),
- );
- group.addEventListener("pointerenter", (event) => showPinTooltip(event, touchpoint, pin));
- group.addEventListener("pointermove", positionTooltip);
- group.addEventListener("pointerleave", hideTooltip);
- group.addEventListener("focus", () => showPinTooltip(null, touchpoint, pin));
- group.addEventListener("blur", hideTooltip);
- group.addEventListener("click", (event) => {
- event.stopPropagation();
- selectTouchpoint(touchpoint, pin, true);
- });
- group.addEventListener("keydown", (event) => {
- if (event.key === "Enter" || event.key === " ") {
- event.preventDefault();
- selectTouchpoint(touchpoint, pin, true);
- }
- });
- dom["pin-layer"].append(group);
- }
- }
- dom["visible-count"].textContent = `${visible} 个座子`;
- renderSelectionOverlay();
- }
- function showTouchpointTooltip(event, touchpoint) {
- dom["board-tooltip"].replaceChildren();
- const key = element("div", "tooltip-key", touchpoint.reference);
- const detail = element("div", "", `${touchpointKindLabel(touchpoint)} · ${touchpointPinSummary(touchpoint)}`);
- const summary = element("div", "", touchpoint.summary);
- dom["board-tooltip"].append(key, detail, summary);
- dom["board-tooltip"].hidden = false;
- if (event) positionTooltip(event);
- else positionTooltipForTouchpoint(touchpoint);
- }
- function showPinTooltip(event, touchpoint, pin) {
- dom["board-tooltip"].replaceChildren();
- dom["board-tooltip"].append(
- element("div", "tooltip-key", `${touchpoint.reference}.${pin.number || "机械孔"}`),
- element("div", "tooltip-role", padRoleLabel(pin.pad_role)),
- element("div", "", pin.net || "无命名网络"),
- element("div", "", pin.summary || evidenceLabel(pin.evidence_tier)),
- );
- dom["board-tooltip"].hidden = false;
- if (event) positionTooltip(event);
- else positionTooltipForTouchpoint(touchpoint);
- }
- function positionTooltip(event) {
- if (!event || dom["board-tooltip"].hidden) return;
- const viewport = dom["board-viewport"].getBoundingClientRect();
- const tooltip = dom["board-tooltip"];
- const left = Math.min(event.clientX - viewport.left + 12, viewport.width - tooltip.offsetWidth - 12);
- const top = Math.min(event.clientY - viewport.top + 12, viewport.height - tooltip.offsetHeight - 12);
- tooltip.style.left = `${Math.max(8, left)}px`;
- tooltip.style.top = `${Math.max(8, top)}px`;
- }
- function positionTooltipForTouchpoint(touchpoint) {
- const point = dom["board-svg"].createSVGPoint();
- point.x = touchpoint.view_position.x;
- point.y = touchpoint.view_position.y;
- const screen = point.matrixTransform(dom["board-svg"].getScreenCTM());
- positionTooltip({clientX: screen.x, clientY: screen.y});
- }
- function hideTooltip() {
- dom["board-tooltip"].hidden = true;
- }
- function renderSelectionOverlay() {
- dom["selection-layer"].replaceChildren();
- dom["net-layer"].replaceChildren();
- if (!state.selectedTouchpoint) return;
- const bounds = effectiveBounds(state.selectedTouchpoint.view_bounds, 4.2);
- const pad = 0.8;
- const x = bounds.x - pad;
- const y = bounds.y - pad;
- const width = bounds.width + pad * 2;
- const height = bounds.height + pad * 2;
- dom["selection-layer"].append(
- svgElement("rect", {x, y, width, height, rx: 0.55, class: "selection-reticle"}),
- svgElement("line", {x1: x - 1.4, y1: y + height / 2, x2: x + 1.1, y2: y + height / 2, class: "selection-cross"}),
- svgElement("line", {x1: x + width - 1.1, y1: y + height / 2, x2: x + width + 1.4, y2: y + height / 2, class: "selection-cross"}),
- svgElement("line", {x1: x + width / 2, y1: y - 1.4, x2: x + width / 2, y2: y + 1.1, class: "selection-cross"}),
- svgElement("line", {x1: x + width / 2, y1: y + height - 1.1, x2: x + width / 2, y2: y + height + 1.4, class: "selection-cross"}),
- );
- if (!state.selectedPin?.net) return;
- for (const item of sameNetPins(state.data, state.selectedPin.net)) {
- dom["net-layer"].append(
- svgElement("circle", {
- cx: item.pin.view_position.x,
- cy: item.pin.view_position.y,
- r: Math.max(Number(item.pin.size.width), Number(item.pin.size.height), 1.3),
- class: "net-highlight",
- }),
- );
- }
- }
- function selectTouchpoint(touchpoint, pin = null, openDrawer = false) {
- state.selectedTouchpoint = touchpoint;
- state.selectedPin = pin;
- dom["selection-readout"].textContent = pin
- ? `${touchpoint.reference}.${pin.number || "机械孔"} · ${padRoleLabel(pin.pad_role)} · ${pin.net || "无网络"}`
- : `${touchpoint.reference} · ${touchpointPinSummary(touchpoint)}`;
- if (openDrawer) setDrawerCollapsed(false);
- renderBoardMarkers();
- renderDetail();
- }
- function renderEmptyDetail(title, subtitle) {
- dom["detail-content"].replaceChildren();
- const wrapper = element("div", "empty-panel");
- wrapper.append(element("strong", "", title), element("span", "empty-stats", subtitle));
- dom["detail-content"].append(wrapper);
- }
- function fact(label, value) {
- const wrapper = element("div", "fact");
- wrapper.append(element("span", "fact-label", label), element("span", "fact-value", value));
- return wrapper;
- }
- function renderConnectorLayout(touchpoint, groups) {
- const connector = touchpoint.connector;
- const section = element("section", "connector-layout");
- const header = element("div", "connector-layout-header");
- header.append(
- element("h3", "section-title connector-layout-title", "板正面接触针排列"),
- element("span", `evidence-tag${connector.review_status === "cross_verified" ? " verified" : ""}`, evidenceLabel(connector.review_status)),
- );
- section.append(header);
- if (!groups.contactRows.length) {
- section.append(element("div", "risk-note", "该连接器尚无经过复核的接触针顺序。"));
- return section;
- }
- const orientation = element("div", "connector-orientation");
- orientation.append(element("span", "connector-axis connector-axis-top", "上"));
- const middle = element("div", "connector-axis-row");
- middle.append(element("span", "connector-axis", "左"));
- const grid = element("div", "connector-grid");
- const columns = Math.max(...groups.contactRows.map((row) => row.length), 1);
- for (const pins of groups.contactRows) {
- const row = element("div", "connector-grid-row");
- row.style.setProperty("--connector-columns", String(columns));
- for (const pin of pins) {
- const button = element("button", `connector-contact${state.selectedPin?.id === pin.id ? " is-selected" : ""}`, pin.number);
- button.type = "button";
- button.dataset.pinId = pin.id;
- button.setAttribute("aria-label", `${touchpoint.reference}.${pin.number},板正面第 ${pin.board_order} 位`);
- button.addEventListener("click", () => selectTouchpoint(touchpoint, pin, true));
- row.append(button);
- }
- grid.append(row);
- }
- middle.append(grid, element("span", "connector-axis", "右"));
- orientation.append(middle, element("span", "connector-axis connector-axis-bottom", "下"));
- section.append(orientation);
- section.append(
- element(
- "div",
- "connector-layout-meta",
- `${connector.profile} · ${connector.contact_count} 接触针 · ${connector.auxiliary_pad_count} 辅助焊盘`,
- ),
- element(
- "div",
- "connector-perspective-note",
- "板正面俯视:按页面上/下/左/右读取;线缆端或对接面可能是镜像。",
- ),
- );
- return section;
- }
- function renderPinRow(touchpoint, pin) {
- const row = element("button", `pin-row${state.selectedPin?.id === pin.id ? " is-selected" : ""}`);
- row.type = "button";
- row.dataset.pin = pin.number;
- row.dataset.pinId = pin.id;
- row.dataset.padRole = pin.pad_role;
- const primary = element("span", "pin-primary");
- primary.append(
- element("span", "pin-summary", pin.summary),
- element("span", "pin-net", `原始网络:${pin.net || "无命名网络"}`),
- );
- row.append(
- element("span", "pin-number", pin.number || "孔"),
- primary,
- element("span", "pin-direction", pin.pad_role === "contact" ? directionLabel(pin.direction) : padRoleLabel(pin.pad_role)),
- );
- row.addEventListener("click", () => selectTouchpoint(touchpoint, pin, true));
- return row;
- }
- function appendPinSection(container, touchpoint, title, pins) {
- if (!pins.length) return;
- container.append(element("h3", "section-title", title));
- const pinList = element("div", "pin-list");
- for (const pin of pins) pinList.append(renderPinRow(touchpoint, pin));
- container.append(pinList);
- }
- function renderDetail() {
- const touchpoint = state.selectedTouchpoint;
- if (!touchpoint) {
- const counts = state.data?.counts;
- renderEmptyDetail(
- "未选择座子",
- counts ? `${counts.touchpoints} 个座子 · ${counts.connector_contacts} 个 CON 接触针 · ${counts.connector_auxiliary_pads} 个 CON 辅助焊盘` : "",
- );
- return;
- }
- dom["detail-content"].replaceChildren();
- const heading = element("div", "detail-heading");
- const headingText = element("div");
- headingText.append(element("h2", "detail-reference", touchpoint.reference), element("p", "detail-summary", touchpoint.summary));
- heading.append(headingText, element("span", "category-tag", touchpointKindLabel(touchpoint)));
- const facts = element("div", "detail-facts");
- if (touchpoint.connector) {
- facts.append(
- fact("接触针", touchpoint.connector.contact_count),
- fact("辅助焊盘", touchpoint.connector.auxiliary_pad_count),
- fact("总焊盘", touchpoint.pins.length),
- fact("板面", touchpoint.side === "front" ? "正面" : "背面"),
- fact("坐标", `${formatNumber(touchpoint.position.x)} / ${formatNumber(touchpoint.position.y)} mm`),
- fact("旋转", `${formatNumber(touchpoint.rotation, 1)}°`),
- );
- } else {
- facts.append(
- fact("针脚数量", touchpoint.pins.length),
- fact("板面", touchpoint.side === "front" ? "正面" : "背面"),
- fact("坐标", `${formatNumber(touchpoint.position.x)} / ${formatNumber(touchpoint.position.y)} mm`),
- fact("旋转", `${formatNumber(touchpoint.rotation, 1)}°`),
- );
- }
- dom["detail-content"].append(heading, facts);
- if (touchpoint.connector) {
- const groups = connectorPinGroups(touchpoint);
- dom["detail-content"].append(renderConnectorLayout(touchpoint, groups));
- appendPinSection(dom["detail-content"], touchpoint, "接触针(板正面顺序)", groups.contacts);
- appendPinSection(dom["detail-content"], touchpoint, "屏蔽与机械焊盘", groups.auxiliary);
- } else {
- appendPinSection(dom["detail-content"], touchpoint, "针脚", touchpoint.pins);
- }
- if (state.selectedPin) dom["detail-content"].append(renderPinDetail(touchpoint, state.selectedPin));
- }
- function renderPinDetail(touchpoint, pin) {
- const wrapper = element("section", "pin-detail");
- const header = element("div", "pin-detail-header");
- header.append(
- element("h3", "", `${touchpoint.reference}.${pin.number || "机械孔"}`),
- element("span", `evidence-tag${pin.evidence_tier === "cross_verified" ? " verified" : ""}`, evidenceLabel(pin.evidence_tier)),
- );
- wrapper.append(header);
- const programmingGuide = renderProgrammingGuide(pin);
- if (programmingGuide) wrapper.append(programmingGuide);
- wrapper.append(element("h4", "section-title", "物理与电气事实"));
- const facts = element("div", "detail-facts");
- const programmableTarget = pin.fpga
- ? "FPGA U3"
- : pin.mcu
- ? `${pin.mcu.family} ${pin.mcu.device}`
- : "无直接可编程映射";
- const devicePin = pin.fpga?.ball
- ? `FPGA ${pin.fpga.ball}`
- : pin.mcu
- ? `${pin.mcu.device}.${pin.mcu.pin} (${pin.mcu.signal})`
- : "无已验证映射";
- const boardPosition = pin.board_order == null
- ? "不属于外部接触针"
- : `第 ${pin.board_order} 位 · 第 ${pin.row} 行 / 第 ${pin.column} 列`;
- facts.append(
- fact("焊盘角色", padRoleLabel(pin.pad_role)),
- fact("板正面位置", boardPosition),
- fact("原始网络", pin.net || "无命名网络"),
- fact("逻辑方向", directionLabel(pin.direction)),
- fact("外部电平", pin.external_level || "未知"),
- fact("可编程目标", programmableTarget),
- fact("器件引脚", devicePin),
- fact("I/O 标准", pin.fpga?.io_standard || "未知"),
- fact("板上 pull", pin.board_pull || "未注明"),
- fact("有效电平", activeLevelLabel(pin.active_level)),
- fact("极性", pin.polarity && pin.polarity !== "unknown" ? pin.polarity : "未注明"),
- );
- wrapper.append(facts);
- if (pin.external_components?.length) {
- wrapper.append(element("h4", "section-title", "相关板上器件"));
- const components = element("ul", "component-list");
- for (const item of pin.external_components) components.append(element("li", "", item));
- wrapper.append(components);
- }
- if (pin.path?.length) {
- wrapper.append(element("h4", "section-title", "已验证板内路径"));
- const path = element("ol", "path-list");
- for (const item of pin.path) path.append(element("li", "", item));
- wrapper.append(path);
- }
- wrapper.append(element("h4", "section-title", "证据来源"));
- const sources = element("ul", "source-list");
- for (const source of pin.evidence_sources ?? []) sources.append(element("li", "", source));
- wrapper.append(sources);
- if (pin.net) {
- const netMatches = sameNetPins(state.data, pin.net);
- wrapper.append(element("div", "info-note", `同网焊盘 ${netMatches.length} 个,板图已同步高亮。`));
- }
- const blockers = pin.recommendation?.reasons ?? [];
- if (!pin.recommendation?.eligible) {
- wrapper.append(element("div", "risk-note", `不可用于自动候选或 ADC:${blockers.join("、") || "证据条件不足"}。`));
- }
- const dedicatedConfigurationPin = String(pin.function_category || "").startsWith("jtag_");
- if (!pin.fpga || dedicatedConfigurationPin) {
- wrapper.append(
- element(
- "div",
- "info-note",
- dedicatedConfigurationPin
- ? "专用配置脚不使用用户 ADC 约束"
- : "此针不对应可生成 ADC 的 FPGA 用户 I/O。",
- ),
- );
- return wrapper;
- }
- wrapper.append(element("h4", "section-title", "ADC 片段"));
- const adc = element("div", "adc-controls");
- const input = element("input");
- input.type = "text";
- input.placeholder = "RTL 端口名";
- input.setAttribute("aria-label", "RTL 端口名");
- input.disabled = !pin.recommendation?.eligible || state.runtime.adcCopyEnabled !== true;
- const copy = element("button", "copy-button", "⧉");
- copy.type = "button";
- copy.title = "复制 ADC 片段";
- copy.setAttribute("aria-label", "复制 ADC 片段");
- copy.disabled = input.disabled;
- const status = element("div", "copy-status");
- copy.addEventListener("click", async () => {
- try {
- const snippet = generateAdcSnippet(pin, input.value.trim(), state.runtime);
- await copyText(snippet);
- status.textContent = "ADC 片段已复制";
- } catch (error) {
- status.textContent = error instanceof Error ? error.message : String(error);
- }
- });
- adc.append(input, copy);
- wrapper.append(adc, status, element("div", "risk-note", "这里只证明物理可用性,仍需检查当前工程约束冲突。"));
- return wrapper;
- }
- function appendGuidanceList(container, title, items, className = "guidance-list") {
- if (!Array.isArray(items) || !items.length) return;
- container.append(element("h4", "section-title", title));
- const list = element("ul", className);
- for (const item of items) list.append(element("li", "", item));
- container.append(list);
- }
- function renderProgrammingGuide(pin) {
- const programming = pin.programming;
- if (!programming) return null;
- const section = element("section", `programming-guide status-${programming.status || "unknown"}`);
- const heading = element("div", "programming-guide-heading");
- heading.append(
- element("h4", "section-title programming-title", "编程结论"),
- element(
- "span",
- `evidence-tag${programming.evidence_tier === "cross_verified" ? " verified" : ""}`,
- evidenceLabel(programming.evidence_tier),
- ),
- );
- section.append(heading, element("p", "programming-conclusion", programming.conclusion));
- section.append(element("h4", "section-title", "板内网络解释"));
- section.append(element("p", "programming-copy", programming.network_explanation));
- appendGuidanceList(section, "怎么接", programming.connection_guidance);
- section.append(
- element(
- "h4",
- "section-title",
- programming.status === "verified_mcu" ? "MCU 固件用法" : "HDL 用法",
- ),
- );
- section.append(element("p", "programming-copy", programming.hdl_guidance));
- appendGuidanceList(section, "约束要求", programming.constraints, "guidance-list constraint-list");
- appendGuidanceList(section, "风险与未知", programming.risks, "guidance-list risk-list");
- return section;
- }
- async function copyText(value) {
- if (navigator.clipboard?.writeText) return navigator.clipboard.writeText(value);
- const textarea = element("textarea");
- textarea.value = value;
- textarea.style.position = "fixed";
- textarea.style.opacity = "0";
- document.body.append(textarea);
- textarea.select();
- document.execCommand("copy");
- textarea.remove();
- }
- function renderCandidates() {
- if (!state.data) return;
- dom["candidate-list"].replaceChildren();
- if (state.runtime.recommendationsEnabled !== true) {
- dom["candidate-list"].append(element("div", "risk-note", "源文件状态不是当前值,选脚推荐已关闭。"));
- return;
- }
- const capability = dom["capability-select"].value;
- const candidates = findCandidates(state.data, capability);
- if (!candidates.length) {
- const empty = element("div", "empty-panel");
- empty.append(
- element("strong", "", "没有满足全部证据条件的候选"),
- element("span", "empty-stats", "未知、推断、保留、电源、地、机械焊盘和固定负载冲突均已排除"),
- );
- dom["candidate-list"].append(empty);
- return;
- }
- for (const candidate of candidates) {
- const row = element("button", "candidate-row");
- row.type = "button";
- row.append(
- element("span", "candidate-key", `${candidate.reference}.${candidate.pin.number} · ${candidate.pin.fpga.ball}`),
- element("span", "candidate-reason", candidate.reason),
- element("span", "candidate-warning", candidate.warning),
- );
- row.addEventListener("click", () => {
- switchTab("detail");
- selectTouchpoint(candidate.touchpoint, candidate.pin, true);
- focusOnTouchpoint(candidate.touchpoint);
- });
- dom["candidate-list"].append(row);
- }
- }
- function switchTab(tab) {
- state.activeTab = tab;
- const detail = tab === "detail";
- dom["detail-tab"].setAttribute("aria-selected", String(detail));
- dom["candidate-tab"].setAttribute("aria-selected", String(!detail));
- dom["detail-content"].hidden = !detail;
- dom["candidate-content"].hidden = detail;
- if (!detail) renderCandidates();
- }
- function renderSearchResults(query) {
- state.searchResults = searchBoard(state.data, query).slice(0, 24);
- state.activeSearchIndex = -1;
- dom["search-results"].replaceChildren();
- if (!query.trim()) {
- dom["search-results"].hidden = true;
- return;
- }
- dom["search-results"].hidden = false;
- if (!state.searchResults.length) {
- dom["search-results"].append(element("div", "empty-search", "没有匹配的座子或针脚"));
- return;
- }
- state.searchResults.forEach((result, index) => {
- const button = element("button", "search-result");
- button.type = "button";
- button.role = "option";
- button.dataset.index = String(index);
- button.setAttribute("aria-selected", "false");
- const key = result.type === "pin" ? `${result.reference}.${result.pinNumber}` : result.reference;
- const detail = result.type === "pin"
- ? `${result.pin.net || "无网络"} · ${result.pin.fpga?.ball || evidenceLabel(result.pin.evidence_tier)}`
- : `${touchpointKindLabel(result.touchpoint)} · ${result.touchpoint.summary}`;
- button.append(element("span", "result-key", key), element("span", "result-detail", detail));
- button.addEventListener("click", () => activateSearchResult(index));
- dom["search-results"].append(button);
- });
- }
- function activateSearchResult(index) {
- const result = state.searchResults[index];
- if (!result) return;
- state.categories.add(result.touchpoint.category);
- const checkbox = dom["category-filters"].querySelector(`input[value="${result.touchpoint.category}"]`);
- if (checkbox) checkbox.checked = true;
- selectTouchpoint(result.touchpoint, result.pin, true);
- focusOnTouchpoint(result.touchpoint);
- dom["board-search"].value = result.type === "pin" ? `${result.reference}.${result.pinNumber}` : result.reference;
- dom["search-results"].hidden = true;
- dom["board-svg"].focus();
- }
- function updateSearchSelection(nextIndex) {
- const options = [...dom["search-results"].querySelectorAll(".search-result")];
- if (!options.length) return;
- state.activeSearchIndex = (nextIndex + options.length) % options.length;
- options.forEach((option, index) => option.setAttribute("aria-selected", String(index === state.activeSearchIndex)));
- options[state.activeSearchIndex].scrollIntoView({block: "nearest"});
- }
- function focusOnTouchpoint(touchpoint) {
- const bounds = effectiveBounds(touchpoint.view_bounds, 8);
- const viewport = dom["board-svg"].getBoundingClientRect();
- const aspect = Math.max(viewport.width / Math.max(viewport.height, 1), 1);
- let width = Math.max(bounds.width * 3.4, state.baseViewBox.width / 12);
- let height = width / aspect;
- if (height < bounds.height * 3.4) {
- height = bounds.height * 3.4;
- width = height * aspect;
- }
- state.viewBox = {
- x: bounds.x + bounds.width / 2 - width / 2,
- y: bounds.y + bounds.height / 2 - height / 2,
- width,
- height,
- };
- clampViewBox();
- updateViewBox();
- }
- function clampViewBox() {
- if (!state.viewBox || !state.baseViewBox) return;
- const marginX = state.baseViewBox.width * 0.25;
- const marginY = state.baseViewBox.height * 0.4;
- const minX = state.baseViewBox.x - marginX;
- const maxX = state.baseViewBox.x + state.baseViewBox.width + marginX - state.viewBox.width;
- const minY = state.baseViewBox.y - marginY;
- const maxY = state.baseViewBox.y + state.baseViewBox.height + marginY - state.viewBox.height;
- state.viewBox.x = Math.min(Math.max(state.viewBox.x, minX), Math.max(minX, maxX));
- state.viewBox.y = Math.min(Math.max(state.viewBox.y, minY), Math.max(minY, maxY));
- }
- function zoomAt(factor, clientX = null, clientY = null) {
- if (!state.viewBox || !state.baseViewBox) return;
- const minimumWidth = state.baseViewBox.width / 35;
- const maximumWidth = state.baseViewBox.width * 1.25;
- const newWidth = Math.min(Math.max(state.viewBox.width * factor, minimumWidth), maximumWidth);
- const ratio = newWidth / state.viewBox.width;
- const anchor = clientX == null ? {
- x: state.viewBox.x + state.viewBox.width / 2,
- y: state.viewBox.y + state.viewBox.height / 2,
- } : clientToSvg(clientX, clientY);
- state.viewBox = {
- x: anchor.x - (anchor.x - state.viewBox.x) * ratio,
- y: anchor.y - (anchor.y - state.viewBox.y) * ratio,
- width: newWidth,
- height: state.viewBox.height * ratio,
- };
- clampViewBox();
- updateViewBox();
- }
- function clientToSvg(clientX, clientY) {
- const point = dom["board-svg"].createSVGPoint();
- point.x = clientX;
- point.y = clientY;
- return point.matrixTransform(dom["board-svg"].getScreenCTM().inverse());
- }
- function resetView() {
- state.viewBox = {...state.baseViewBox};
- updateViewBox();
- }
- function setDrawerCollapsed(collapsed) {
- dom.app.classList.toggle("detail-collapsed", collapsed);
- dom["drawer-toggle"].setAttribute("aria-expanded", String(!collapsed));
- dom["drawer-toggle"].title = collapsed ? "展开详情" : "收起详情";
- dom["drawer-toggle"].setAttribute("aria-label", collapsed ? "展开详情" : "收起详情");
- }
- dom["category-filters"].addEventListener("change", (event) => {
- const input = event.target;
- if (!(input instanceof HTMLInputElement)) return;
- if (input.checked) state.categories.add(input.value);
- else state.categories.delete(input.value);
- renderBoardMarkers();
- });
- dom["layer-controls"].addEventListener("change", (event) => {
- const input = event.target;
- if (!(input instanceof HTMLInputElement)) return;
- const layer = dom[`layer-${input.value}`];
- if (layer) layer.hidden = !input.checked;
- });
- dom["zoom-in"].addEventListener("click", () => zoomAt(0.8));
- dom["zoom-out"].addEventListener("click", () => zoomAt(1.25));
- dom["reset-view"].addEventListener("click", resetView);
- dom["detail-tab"].addEventListener("click", () => switchTab("detail"));
- dom["candidate-tab"].addEventListener("click", () => switchTab("candidate"));
- dom["capability-select"].addEventListener("change", renderCandidates);
- dom["drawer-toggle"].addEventListener("click", () => setDrawerCollapsed(!dom.app.classList.contains("detail-collapsed")));
- dom["board-search"].addEventListener("input", (event) => {
- if (state.data) renderSearchResults(event.target.value);
- });
- dom["board-search"].addEventListener("keydown", (event) => {
- if (event.key === "ArrowDown") {
- event.preventDefault();
- updateSearchSelection(state.activeSearchIndex + 1);
- } else if (event.key === "ArrowUp") {
- event.preventDefault();
- updateSearchSelection(state.activeSearchIndex - 1);
- } else if (event.key === "Enter" && state.activeSearchIndex >= 0) {
- event.preventDefault();
- activateSearchResult(state.activeSearchIndex);
- } else if (event.key === "Escape") {
- dom["search-results"].hidden = true;
- }
- });
- document.addEventListener("pointerdown", (event) => {
- if (!dom["search-results"].contains(event.target) && event.target !== dom["board-search"]) {
- dom["search-results"].hidden = true;
- }
- });
- dom["board-svg"].addEventListener("wheel", (event) => {
- event.preventDefault();
- zoomAt(event.deltaY < 0 ? 0.82 : 1.22, event.clientX, event.clientY);
- }, {passive: false});
- dom["board-svg"].addEventListener("pointerdown", (event) => {
- if (event.target.closest?.(".hotspot, .pin-group")) return;
- dom["board-svg"].setPointerCapture(event.pointerId);
- dom["board-svg"].classList.add("is-panning");
- state.dragging = {pointerId: event.pointerId, x: event.clientX, y: event.clientY, viewBox: {...state.viewBox}};
- });
- dom["board-svg"].addEventListener("pointermove", (event) => {
- if (!state.dragging || state.dragging.pointerId !== event.pointerId) return;
- const bounds = dom["board-svg"].getBoundingClientRect();
- state.viewBox = {
- ...state.dragging.viewBox,
- x: state.dragging.viewBox.x - (event.clientX - state.dragging.x) * state.dragging.viewBox.width / bounds.width,
- y: state.dragging.viewBox.y - (event.clientY - state.dragging.y) * state.dragging.viewBox.height / bounds.height,
- };
- clampViewBox();
- updateViewBox();
- });
- function endPan(event) {
- if (!state.dragging || state.dragging.pointerId !== event.pointerId) return;
- state.dragging = null;
- dom["board-svg"].classList.remove("is-panning");
- }
- dom["board-svg"].addEventListener("pointerup", endPan);
- dom["board-svg"].addEventListener("pointercancel", endPan);
- dom["board-svg"].addEventListener("keydown", (event) => {
- const stepX = state.viewBox.width * 0.06;
- const stepY = state.viewBox.height * 0.08;
- if (event.key === "+" || event.key === "=") zoomAt(0.8);
- else if (event.key === "-") zoomAt(1.25);
- else if (event.key === "0") resetView();
- else if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.key)) {
- if (event.key === "ArrowLeft") state.viewBox.x -= stepX;
- if (event.key === "ArrowRight") state.viewBox.x += stepX;
- if (event.key === "ArrowUp") state.viewBox.y -= stepY;
- if (event.key === "ArrowDown") state.viewBox.y += stepY;
- clampViewBox();
- updateViewBox();
- } else return;
- event.preventDefault();
- });
- window.addEventListener("resize", () => {
- hideTooltip();
- if (window.innerWidth > 860) setDrawerCollapsed(false);
- });
- setDrawerCollapsed(window.innerWidth <= 860);
- loadApplication();
|