traceforge-pcb 1.0.0__py3-none-any.whl
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.
- traceforge/__init__.py +3 -0
- traceforge/__main__.py +3 -0
- traceforge/acp_server.py +570 -0
- traceforge/agent.py +680 -0
- traceforge/altium/__init__.py +6 -0
- traceforge/altium/cfb.py +70 -0
- traceforge/altium/cli.py +60 -0
- traceforge/altium/model.py +163 -0
- traceforge/altium/outputs.py +24 -0
- traceforge/altium/pcb.py +301 -0
- traceforge/altium/project.py +328 -0
- traceforge/altium/schematic.py +400 -0
- traceforge/altium/tools.py +166 -0
- traceforge/approval.py +219 -0
- traceforge/attachments.py +346 -0
- traceforge/background.py +253 -0
- traceforge/bench/__init__.py +5 -0
- traceforge/bench/adapters.py +337 -0
- traceforge/bench/checks.py +410 -0
- traceforge/bench/cli.py +121 -0
- traceforge/bench/design.py +439 -0
- traceforge/bench/kicad.py +99 -0
- traceforge/bench/partscheck.py +159 -0
- traceforge/bench/review.py +100 -0
- traceforge/bench/runner.py +226 -0
- traceforge/bench/score.py +204 -0
- traceforge/bench/tasks.py +102 -0
- traceforge/chat.py +1185 -0
- traceforge/checks.py +328 -0
- traceforge/checks_sides.py +118 -0
- traceforge/cli.py +2224 -0
- traceforge/clipboard.py +107 -0
- traceforge/config.py +299 -0
- traceforge/context.py +276 -0
- traceforge/design/__init__.py +1 -0
- traceforge/design/constraints.py +397 -0
- traceforge/design/generate.py +1789 -0
- traceforge/design/outline.py +905 -0
- traceforge/design/schematic_layout.py +932 -0
- traceforge/design/schematic_lint.py +329 -0
- traceforge/design/schematic_route.py +207 -0
- traceforge/design/sheets.py +854 -0
- traceforge/design/sides.py +328 -0
- traceforge/design/spec.py +462 -0
- traceforge/design/specsheet.py +2351 -0
- traceforge/design/specsheet_render.py +183 -0
- traceforge/desktop/__init__.py +109 -0
- traceforge/desktop/keys.py +90 -0
- traceforge/desktop/project.py +443 -0
- traceforge/desktop/review.py +20 -0
- traceforge/desktop/server.py +1277 -0
- traceforge/desktop/static/app.css +223 -0
- traceforge/desktop/static/app.js +683 -0
- traceforge/desktop/static/highlight.js +77 -0
- traceforge/desktop/static/index.html +89 -0
- traceforge/desktop/static/md.js +90 -0
- traceforge/desktop/static/viewer.js +213 -0
- traceforge/desktop/symbols.py +212 -0
- traceforge/desktop/update.py +65 -0
- traceforge/diagnostics.py +67 -0
- traceforge/errata.py +219 -0
- traceforge/fab.py +108 -0
- traceforge/fab_layers.py +44 -0
- traceforge/features/__init__.py +6 -0
- traceforge/features/candidates.py +117 -0
- traceforge/features/cli.py +200 -0
- traceforge/features/package.py +433 -0
- traceforge/features/revdiff.py +224 -0
- traceforge/features/sarif.py +145 -0
- traceforge/features/viewer.py +265 -0
- traceforge/firmware/__init__.py +3 -0
- traceforge/firmware/cli.py +174 -0
- traceforge/firmware/drivers.py +372 -0
- traceforge/firmware/drivers_data.py +256 -0
- traceforge/firmware/mcus.py +177 -0
- traceforge/firmware/netlist.py +55 -0
- traceforge/firmware/pinmap.py +296 -0
- traceforge/firmware/scaffold.py +466 -0
- traceforge/firmware/toolchain.py +262 -0
- traceforge/hooks.py +237 -0
- traceforge/kicad/__init__.py +0 -0
- traceforge/kicad/cli.py +519 -0
- traceforge/kicad/diffpair.py +174 -0
- traceforge/kicad/edgegeom.py +191 -0
- traceforge/kicad/edit.py +405 -0
- traceforge/kicad/escape.py +1410 -0
- traceforge/kicad/formats.py +1073 -0
- traceforge/kicad/impedance.py +320 -0
- traceforge/kicad/install.py +75 -0
- traceforge/kicad/libraries.py +490 -0
- traceforge/kicad/models3d.py +942 -0
- traceforge/kicad/outputs.py +81 -0
- traceforge/kicad/pcb.py +787 -0
- traceforge/kicad/planes.py +1242 -0
- traceforge/kicad/project.py +136 -0
- traceforge/kicad/route.py +2698 -0
- traceforge/kicad/routegeom.py +164 -0
- traceforge/kicad/schematic.py +268 -0
- traceforge/kicad/sides.py +34 -0
- traceforge/kicad/stackup.py +424 -0
- traceforge/kicad_plugin/__init__.py +12 -0
- traceforge/kicad_plugin/actions.py +92 -0
- traceforge/kicad_plugin/cli.py +66 -0
- traceforge/kicad_plugin/client.py +86 -0
- traceforge/kicad_plugin/context.py +257 -0
- traceforge/kicad_plugin/discovery.py +81 -0
- traceforge/kicad_plugin/install.py +203 -0
- traceforge/kicad_plugin/overlay.py +60 -0
- traceforge/kicad_plugin/payload/action_plugin.py +65 -0
- traceforge/kicad_plugin/payload/ipc_main.py +42 -0
- traceforge/kicad_plugin/payload/plugin.json +90 -0
- traceforge/kicad_plugin/payload/requirements.txt +1 -0
- traceforge/kicad_plugin/views.py +202 -0
- traceforge/langchain.py +57 -0
- traceforge/local.py +580 -0
- traceforge/mcp_server.py +304 -0
- traceforge/models.py +310 -0
- traceforge/next_steps.py +110 -0
- traceforge/parts/__init__.py +52 -0
- traceforge/parts/alternates.py +488 -0
- traceforge/parts/bom.py +423 -0
- traceforge/parts/brief.py +705 -0
- traceforge/parts/catalog.py +297 -0
- traceforge/parts/cli_sourcing.py +156 -0
- traceforge/parts/data/duty_rates.yaml +37 -0
- traceforge/parts/data/hs_codes.yaml +103 -0
- traceforge/parts/datasheet.py +278 -0
- traceforge/parts/fx.py +100 -0
- traceforge/parts/model.py +185 -0
- traceforge/parts/net.py +187 -0
- traceforge/parts/offers.py +46 -0
- traceforge/parts/packages.py +397 -0
- traceforge/parts/pinout.py +714 -0
- traceforge/parts/providers/__init__.py +17 -0
- traceforge/parts/providers/base.py +100 -0
- traceforge/parts/providers/jlc.py +364 -0
- traceforge/parts/providers/keyed.py +661 -0
- traceforge/parts/report.py +508 -0
- traceforge/parts/supply.py +330 -0
- traceforge/parts/verify.py +455 -0
- traceforge/parts/web.py +575 -0
- traceforge/plans.py +70 -0
- traceforge/preferences.py +127 -0
- traceforge/prices.py +130 -0
- traceforge/prices.yaml +28 -0
- traceforge/prompts/__init__.py +54 -0
- traceforge/prompts/system.md +103 -0
- traceforge/providers.py +764 -0
- traceforge/remote/__init__.py +33 -0
- traceforge/remote/client.py +422 -0
- traceforge/remote/oidc.py +240 -0
- traceforge/remote/orgs.py +510 -0
- traceforge/remote/server.py +690 -0
- traceforge/remote/store.py +100 -0
- traceforge/review_changes.py +187 -0
- traceforge/routing.py +99 -0
- traceforge/runtime.py +435 -0
- traceforge/sessions.py +324 -0
- traceforge/sexpr.py +279 -0
- traceforge/sim/__init__.py +17 -0
- traceforge/sim/acmath.py +234 -0
- traceforge/sim/circuit.py +499 -0
- traceforge/sim/cli.py +162 -0
- traceforge/sim/engine.py +172 -0
- traceforge/sim/ltspice.py +175 -0
- traceforge/sim/measure.py +123 -0
- traceforge/sim/models.py +76 -0
- traceforge/sim/project.py +218 -0
- traceforge/sim/rawfile.py +123 -0
- traceforge/sim/results.py +298 -0
- traceforge/sim/tune.py +172 -0
- traceforge/skill_commands.py +165 -0
- traceforge/skill_library/circuit-simulation/SKILL.md +30 -0
- traceforge/skill_library/compliance-review/SKILL.md +51 -0
- traceforge/skill_library/design-review/SKILL.md +47 -0
- traceforge/skill_library/errata-hunt/SKILL.md +30 -0
- traceforge/skill_library/firmware/SKILL.md +26 -0
- traceforge/skill_library/power-budget/SKILL.md +27 -0
- traceforge/skill_library/release-package/SKILL.md +29 -0
- traceforge/skill_library/sourcing-brief/SKILL.md +24 -0
- traceforge/skill_library/thermal-review/SKILL.md +15 -0
- traceforge/skills.py +131 -0
- traceforge/thermal.py +557 -0
- traceforge/tools/__init__.py +48 -0
- traceforge/tools/agent_tools.py +213 -0
- traceforge/tools/base.py +303 -0
- traceforge/tools/batch.py +155 -0
- traceforge/tools/connections.py +245 -0
- traceforge/tools/files.py +777 -0
- traceforge/tools/firmware_tools.py +218 -0
- traceforge/tools/kicad_tools.py +1072 -0
- traceforge/tools/models3d_tools.py +141 -0
- traceforge/tools/parts_tools.py +473 -0
- traceforge/tools/processes.py +246 -0
- traceforge/tools/review_tools.py +178 -0
- traceforge/tools/sim_tools.py +230 -0
- traceforge/tui.py +620 -0
- traceforge/updates.py +124 -0
- traceforge/validate/__init__.py +77 -0
- traceforge/validate/builtins.py +1091 -0
- traceforge/validate/circuits.py +1240 -0
- traceforge/validate/config.py +410 -0
- traceforge/validate/default.yaml +113 -0
- traceforge/validate/design.py +191 -0
- traceforge/validate/explain.py +112 -0
- traceforge/validate/grounding.py +169 -0
- traceforge/validate/ipc2221.py +350 -0
- traceforge/validate/multilayer.py +805 -0
- traceforge/validate/netmodel.py +261 -0
- traceforge/validate/partcheck.py +472 -0
- traceforge/validate/report.py +280 -0
- traceforge/validate/review.py +322 -0
- traceforge/validate/runner.py +662 -0
- traceforge/workspace.py +171 -0
- traceforge_pcb-1.0.0.dist-info/METADATA +463 -0
- traceforge_pcb-1.0.0.dist-info/RECORD +219 -0
- traceforge_pcb-1.0.0.dist-info/WHEEL +4 -0
- traceforge_pcb-1.0.0.dist-info/entry_points.txt +2 -0
- traceforge_pcb-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* A small syntax highlighter for the editor: YAML, Python, KiCad S-expressions, JSON, C and shell-style
|
|
2
|
+
files. No dependencies, no network. highlight(text, lang) returns escaped HTML made of <span class="tk-*">. */
|
|
3
|
+
(function () {
|
|
4
|
+
const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
5
|
+
|
|
6
|
+
// each rule: [class, regex]; the first rule whose regex matches at the cursor wins (sticky matching)
|
|
7
|
+
const PY_KW = "False|None|True|and|as|assert|async|await|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|raise|return|try|while|with|yield|match|case|self";
|
|
8
|
+
const C_KW = "auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while|bool|true|false|uint8_t|uint16_t|uint32_t|int8_t|int16_t|int32_t|NULL|class|namespace|template|public|private|using|new|delete";
|
|
9
|
+
const LANGS = {
|
|
10
|
+
python: [
|
|
11
|
+
["c", /#[^\n]*/y], ["s", /(?:[rbfRBF]{0,2})(?:"""[\s\S]*?(?:"""|$)|'''[\s\S]*?(?:'''|$)|"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?)/y],
|
|
12
|
+
["k", new RegExp("(?:" + PY_KW + ")\\b", "y")], ["f", /@[A-Za-z_][\w.]*/y], ["n", /\b(?:0[xX][\da-fA-F_]+|\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?)\b/y], ["w", /[A-Za-z_]\w*/y],
|
|
13
|
+
],
|
|
14
|
+
yaml: [
|
|
15
|
+
["c", /#[^\n]*/y], ["a", /[ \t]*(?:-[ \t]+)*(?:"[^"\n]*"|'[^'\n]*'|[^\s:#'"{}\[\],-][^:#\n]*?)(?=[ \t]*:(?:[ \t\r\n]|$))/y],
|
|
16
|
+
["s", /"(?:[^"\\\n]|\\.)*"?|'(?:[^'\n]|'')*'?/y], ["k", /\b(?:true|false|null|yes|no|on|off)\b|~/y],
|
|
17
|
+
["n", /-?\b\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?\b/y], ["p", /[-:\[\]{},|>&*!]/y], ["w", /[^\s:#'"\[\]{},|>&*!-]+/y],
|
|
18
|
+
],
|
|
19
|
+
sexp: [
|
|
20
|
+
["s", /"(?:[^"\\]|\\[\s\S])*"?/y], ["p", /[()]/y], ["n", /-?\d+\.?\d*(?:e[+-]?\d+)?(?![\w.:\/-])/y],
|
|
21
|
+
["k", /(?<=\()[A-Za-z_][\w.-]*/y], ["v", /\b(?:yes|no|true|false|hide|none)\b/y], ["w", /[^\s()"]+/y],
|
|
22
|
+
],
|
|
23
|
+
json: [
|
|
24
|
+
["a", /"(?:[^"\\\n]|\\.)*"(?=\s*:)/y], ["s", /"(?:[^"\\\n]|\\.)*"?/y], ["k", /\b(?:true|false|null)\b/y],
|
|
25
|
+
["n", /-?\d+\.?\d*(?:[eE][+-]?\d+)?/y], ["p", /[{}\[\],:]/y],
|
|
26
|
+
],
|
|
27
|
+
c: [
|
|
28
|
+
["c", /\/\/[^\n]*|\/\*[\s\S]*?(?:\*\/|$)/y], ["f", /^[ \t]*#[ \t]*\w+/my], ["s", /"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/y],
|
|
29
|
+
["k", new RegExp("(?:" + C_KW + ")\\b", "y")], ["n", /\b(?:0[xX][\da-fA-F]+|0[bB][01]+|\d+\.?\d*(?:[eE][+-]?\d+)?)[uUlLfF]*\b/y], ["w", /[A-Za-z_]\w*/y],
|
|
30
|
+
],
|
|
31
|
+
shell: [
|
|
32
|
+
["c", /#[^\n]*/y], ["s", /"(?:[^"\\]|\\[\s\S])*"?|'[^']*'?/y], ["k", /\b(?:if|then|else|elif|fi|for|do|done|while|case|esac|function|return|export|in)\b/y],
|
|
33
|
+
["f", /\$\{?\w+\}?/y], ["w", /[A-Za-z_][\w-]*/y],
|
|
34
|
+
],
|
|
35
|
+
toml: [
|
|
36
|
+
["c", /#[^\n]*/y], ["a", /^[ \t]*[\w."-]+(?=[ \t]*=)/my], ["f", /^[ \t]*\[[^\]\n]*\]/my], ["s", /"(?:[^"\\\n]|\\.)*"?|'[^'\n]*'?/y],
|
|
37
|
+
["k", /\b(?:true|false)\b/y], ["n", /-?\d[\d_]*\.?\d*/y],
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
const BY_EXT = { py: "python", pyw: "python", yaml: "yaml", yml: "yaml", json: "json", c: "c", h: "c", cpp: "c", hpp: "c", cc: "c", ino: "c", ts: "c", js: "c", sh: "shell", bash: "shell", toml: "toml", kicad_pcb: "sexp", kicad_sch: "sexp", kicad_sym: "sexp", kicad_mod: "sexp", kicad_pro: "json", kicad_dru: "sexp", kicad_wks: "sexp", net: "sexp", sexp: "sexp" };
|
|
41
|
+
|
|
42
|
+
function langFor(path) {
|
|
43
|
+
const name = (path || "").split("/").pop().toLowerCase();
|
|
44
|
+
if (name === "makefile" || name === "dockerfile") return "shell";
|
|
45
|
+
const m = name.match(/\.([a-z0-9_]+)$/);
|
|
46
|
+
return (m && BY_EXT[m[1]]) || null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function highlight(text, lang) {
|
|
50
|
+
const rules = LANGS[lang];
|
|
51
|
+
if (!rules) return esc(text);
|
|
52
|
+
let out = "", i = 0, plain = "";
|
|
53
|
+
const flush = () => { if (plain) { out += esc(plain); plain = ""; } };
|
|
54
|
+
const n = text.length;
|
|
55
|
+
while (i < n) {
|
|
56
|
+
let hit = null;
|
|
57
|
+
for (const [cls, re] of rules) {
|
|
58
|
+
re.lastIndex = i;
|
|
59
|
+
const m = re.exec(text);
|
|
60
|
+
if (m && m.index === i && m[0].length) { hit = [cls, m[0]]; break; }
|
|
61
|
+
}
|
|
62
|
+
if (!hit) { plain += text[i++]; continue; }
|
|
63
|
+
if (hit[0] === "w") { plain += hit[1]; i += hit[1].length; continue; }
|
|
64
|
+
flush();
|
|
65
|
+
// YAML keys: keep list dashes and indentation uncoloured
|
|
66
|
+
if (hit[0] === "a" && lang === "yaml") {
|
|
67
|
+
const lead = hit[1].match(/^[ \t]*(?:-[ \t]+)*/)[0];
|
|
68
|
+
out += esc(lead) + `<span class="tk-a">${esc(hit[1].slice(lead.length))}</span>`;
|
|
69
|
+
} else out += `<span class="tk-${hit[0]}">${esc(hit[1])}</span>`;
|
|
70
|
+
i += hit[1].length;
|
|
71
|
+
}
|
|
72
|
+
flush();
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
window.TFhl = { highlight, langFor, LANGS: Object.keys(LANGS) };
|
|
77
|
+
})();
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en" data-theme="dark">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Traceforge</title>
|
|
7
|
+
<link rel="stylesheet" href="/static/app.css?token=__TOKEN__">
|
|
8
|
+
<script>
|
|
9
|
+
window.TF_TOKEN = "__TOKEN__";
|
|
10
|
+
try { document.documentElement.dataset.theme = localStorage.getItem("tf-theme") || "dark"; } catch (e) {}
|
|
11
|
+
</script>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div id="app" data-view="center" data-left="1">
|
|
15
|
+
<header id="top">
|
|
16
|
+
<div class="brand"><span class="logo" aria-hidden="true"></span><span>Traceforge</span></div>
|
|
17
|
+
<button id="project-btn" class="chip-btn" title="Open a project folder"><i data-i="folder"></i><span id="project-name">Open project</span></button>
|
|
18
|
+
<div class="spacer"></div>
|
|
19
|
+
<button id="palette-btn" class="ghost" title="Component actions (Ctrl/Cmd+K)"><i data-i="command"></i><span class="hide-sm">Actions</span><kbd>K</kbd></button>
|
|
20
|
+
<button id="quick-btn" class="ghost" title="Quick chat (Ctrl/Cmd+Shift+Space)"><i data-i="zap"></i><span class="hide-sm">Quick chat</span></button>
|
|
21
|
+
<button id="theme-btn" class="icon" title="Toggle theme"><i data-i="sun"></i></button>
|
|
22
|
+
<button id="settings-btn" class="icon" title="Settings"><i data-i="settings"></i></button>
|
|
23
|
+
</header>
|
|
24
|
+
|
|
25
|
+
<aside id="left">
|
|
26
|
+
<div class="seg" id="left-seg">
|
|
27
|
+
<button data-p="files" class="on">Files</button><button data-p="git">Git</button><button data-p="history">Chats</button>
|
|
28
|
+
</div>
|
|
29
|
+
<div class="panel-body" id="left-body"></div>
|
|
30
|
+
</aside>
|
|
31
|
+
|
|
32
|
+
<main id="center">
|
|
33
|
+
<div id="tabbar"><div id="tabs"></div><button id="newtab" class="icon" title="New chat (Ctrl/Cmd+T)"><i data-i="plus"></i></button></div>
|
|
34
|
+
<div id="chats"></div>
|
|
35
|
+
<div id="suggest"></div>
|
|
36
|
+
<div id="reviewbar" hidden></div>
|
|
37
|
+
<div id="composer">
|
|
38
|
+
<div id="chips"></div>
|
|
39
|
+
<div class="box">
|
|
40
|
+
<textarea id="input" rows="1" placeholder="Ask about the design, or type @ to mention a component" spellcheck="true"></textarea>
|
|
41
|
+
<button id="attach" class="icon" title="Attach screenshot, datasheet or file"><i data-i="paperclip"></i></button>
|
|
42
|
+
<button id="send" class="primary" title="Send (Enter)"><i data-i="send"></i></button>
|
|
43
|
+
<input type="file" id="file" multiple hidden>
|
|
44
|
+
</div>
|
|
45
|
+
<div id="picker" hidden></div>
|
|
46
|
+
<div class="controls">
|
|
47
|
+
<select id="mode" title="Mode"></select>
|
|
48
|
+
<select id="model" title="Model"></select>
|
|
49
|
+
<select id="effort" title="Reasoning effort"></select>
|
|
50
|
+
<select id="approval" title="Approvals"></select>
|
|
51
|
+
<span class="spacer"></span>
|
|
52
|
+
<span id="usage" title="Tokens this chat"></span>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
</main>
|
|
56
|
+
|
|
57
|
+
<section id="right">
|
|
58
|
+
<div class="seg" id="right-seg">
|
|
59
|
+
<button data-p="pcb" class="on">Board</button><button data-p="sch">Schematic</button><button data-p="changes">Changes<b id="changes-n" hidden></b></button><button data-p="checks">Checks</button><button data-p="editor">Editor</button>
|
|
60
|
+
</div>
|
|
61
|
+
<div class="panel-body" id="right-body">
|
|
62
|
+
<div class="pane" data-p="pcb"></div>
|
|
63
|
+
<div class="pane" data-p="sch" hidden></div>
|
|
64
|
+
<div class="pane" data-p="changes" hidden></div>
|
|
65
|
+
<div class="pane" data-p="checks" hidden></div>
|
|
66
|
+
<div class="pane" data-p="editor" hidden></div>
|
|
67
|
+
</div>
|
|
68
|
+
</section>
|
|
69
|
+
|
|
70
|
+
<nav id="bottomnav">
|
|
71
|
+
<button data-v="left">Project</button><button data-v="center" class="on">Chat</button><button data-v="right">Viewer</button>
|
|
72
|
+
</nav>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
<div id="quick" hidden>
|
|
76
|
+
<div class="qhead"><i data-i="zap"></i><b>Quick chat</b><span class="spacer"></span><button class="icon" id="quick-expand" title="Open as a full tab"><i data-i="expand"></i></button><button class="icon" id="quick-close" title="Close (Esc)"><i data-i="x"></i></button></div>
|
|
77
|
+
<div id="qchat"></div>
|
|
78
|
+
<div class="qbox"><textarea id="qinput" rows="1" placeholder="Quick question about this design"></textarea><button class="icon" id="qshot" title="Attach the current viewer as an image"><i data-i="image"></i></button><button class="primary" id="qsend"><i data-i="send"></i></button></div>
|
|
79
|
+
<div id="qchips"></div>
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
<div id="modal" hidden><div class="sheet" id="sheet"></div></div>
|
|
83
|
+
<div id="toasts"></div>
|
|
84
|
+
<script src="/static/md.js?token=__TOKEN__"></script>
|
|
85
|
+
<script src="/static/highlight.js?token=__TOKEN__"></script>
|
|
86
|
+
<script src="/static/viewer.js?token=__TOKEN__"></script>
|
|
87
|
+
<script src="/static/app.js?token=__TOKEN__"></script>
|
|
88
|
+
</body>
|
|
89
|
+
</html>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/* Small Markdown renderer (headings, lists, tables, fences, quotes, inline) and icon set. No dependencies. */
|
|
2
|
+
(function () {
|
|
3
|
+
const esc = (s) => String(s).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
4
|
+
|
|
5
|
+
function inline(text, refs) {
|
|
6
|
+
const codes = [];
|
|
7
|
+
let t = text.replace(/`([^`\n]+)`/g, (_, c) => { codes.push(c); return "\u0000" + (codes.length - 1) + "\u0000"; });
|
|
8
|
+
t = esc(t);
|
|
9
|
+
t = t.replace(/\*\*([^*\n]+)\*\*/g, "<strong>$1</strong>").replace(/(^|[^\w*])\*([^*\n]+)\*(?!\w)/g, "$1<em>$2</em>").replace(/~~([^~\n]+)~~/g, "<del>$1</del>");
|
|
10
|
+
t = t.replace(/\[([^\]\n]+)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>');
|
|
11
|
+
t = t.replace(/(^|[\s(])(https?:\/\/[^\s<)]+)/g, '$1<a href="$2" target="_blank" rel="noopener noreferrer">$2</a>');
|
|
12
|
+
if (refs) t = t.replace(/(^|[^\w`])@([A-Za-z]{1,4}\d{1,4}[A-Za-z]?)\b/g, (m, a, r) => refs.has(r) ? `${a}<span class="mention" data-ref="${r}">@${r}</span>` : m);
|
|
13
|
+
return t.replace(/\u0000(\d+)\u0000/g, (_, i) => "<code>" + esc(codes[+i]) + "</code>");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function render(src, refs) {
|
|
17
|
+
const lines = String(src).replace(/\r/g, "").split("\n");
|
|
18
|
+
const out = [];
|
|
19
|
+
let i = 0;
|
|
20
|
+
const isTable = (k) => k + 1 < lines.length && /^\s*\|.*\|\s*$/.test(lines[k]) && /^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(lines[k + 1]);
|
|
21
|
+
while (i < lines.length) {
|
|
22
|
+
const line = lines[i];
|
|
23
|
+
let m;
|
|
24
|
+
if ((m = line.match(/^\s*(```|~~~)\s*([\w+-]*)/))) {
|
|
25
|
+
const fence = m[1], buf = [];
|
|
26
|
+
i++;
|
|
27
|
+
while (i < lines.length && !lines[i].trim().startsWith(fence)) buf.push(lines[i++]);
|
|
28
|
+
i++;
|
|
29
|
+
out.push(`<pre data-lang="${esc(m[2])}"><button class="btn cp" type="button">Copy</button><code>${esc(buf.join("\n"))}</code></pre>`);
|
|
30
|
+
} else if (!line.trim()) { i++; }
|
|
31
|
+
else if ((m = line.match(/^(#{1,4})\s+(.*)$/))) { out.push(`<h${m[1].length}>${inline(m[2], refs)}</h${m[1].length}>`); i++; }
|
|
32
|
+
else if (/^\s*([-*_])(\s*\1){2,}\s*$/.test(line)) { out.push("<hr>"); i++; }
|
|
33
|
+
else if (isTable(i)) {
|
|
34
|
+
const cells = (l) => l.trim().replace(/^\||\|$/g, "").split("|").map((c) => c.trim());
|
|
35
|
+
const head = cells(lines[i]); i += 2;
|
|
36
|
+
const rows = [];
|
|
37
|
+
while (i < lines.length && /^\s*\|.*\|\s*$/.test(lines[i])) rows.push(cells(lines[i++]));
|
|
38
|
+
out.push("<table><thead><tr>" + head.map((c) => `<th>${inline(c, refs)}</th>`).join("") + "</tr></thead><tbody>" + rows.map((r) => "<tr>" + r.map((c) => `<td>${inline(c, refs)}</td>`).join("") + "</tr>").join("") + "</tbody></table>");
|
|
39
|
+
} else if (/^\s*>/.test(line)) {
|
|
40
|
+
const buf = [];
|
|
41
|
+
while (i < lines.length && /^\s*>/.test(lines[i])) buf.push(lines[i++].replace(/^\s*>\s?/, ""));
|
|
42
|
+
out.push("<blockquote>" + render(buf.join("\n"), refs) + "</blockquote>");
|
|
43
|
+
} else if (/^\s*([-*+]|\d+[.)])\s+/.test(line)) {
|
|
44
|
+
const ordered = /^\s*\d/.test(line), items = [];
|
|
45
|
+
while (i < lines.length && (/^\s*([-*+]|\d+[.)])\s+/.test(lines[i]) || (/^\s{2,}\S/.test(lines[i]) && items.length))) {
|
|
46
|
+
const mm = lines[i].match(/^(\s*)([-*+]|\d+[.)])\s+(.*)$/);
|
|
47
|
+
if (mm && mm[1].length < 2) items.push(mm[3]);
|
|
48
|
+
else if (mm) items[items.length - 1] += "\n" + " " + mm[3];
|
|
49
|
+
else items[items.length - 1] += " " + lines[i].trim();
|
|
50
|
+
i++;
|
|
51
|
+
}
|
|
52
|
+
const tag = ordered ? "ol" : "ul";
|
|
53
|
+
out.push(`<${tag}>` + items.map((t) => `<li>${inline(t, refs).replace(/\n/g, "<br>")}</li>`).join("") + `</${tag}>`);
|
|
54
|
+
} else {
|
|
55
|
+
const buf = [];
|
|
56
|
+
while (i < lines.length && lines[i].trim() && !/^\s*(```|~~~|#{1,4}\s|>|([-*+]|\d+[.)])\s)/.test(lines[i]) && !isTable(i)) buf.push(lines[i++]);
|
|
57
|
+
if (!buf.length) { buf.push(lines[i++]); }
|
|
58
|
+
out.push(`<p>${inline(buf.join("\n"), refs).replace(/\n/g, "<br>")}</p>`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return out.join("\n");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function diffHtml(text) {
|
|
65
|
+
if (!text) return '<div class="m">No textual changes.</div>';
|
|
66
|
+
return text.split("\n").map((l) => {
|
|
67
|
+
const c = l.startsWith("+++") || l.startsWith("---") ? "m" : l.startsWith("@@") ? "h" : l.startsWith("+") ? "a" : l.startsWith("-") ? "d" : l.startsWith("diff ") || l.startsWith("index ") ? "m" : "";
|
|
68
|
+
return `<div class="${c}">${esc(l) || " "}</div>`;
|
|
69
|
+
}).join("");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const P = {
|
|
73
|
+
folder: "M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",
|
|
74
|
+
file: "M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8zM14 3v5h5",
|
|
75
|
+
plus: "M12 5v14M5 12h14", x: "M6 6l12 12M18 6L6 18", send: "M5 12l14-7-5 14-2-6z",
|
|
76
|
+
stop: "M7 7h10v10H7z", paperclip: "M20 11l-8.5 8.5a5 5 0 0 1-7-7L13 4a3.5 3.5 0 0 1 5 5l-8.5 8.5a2 2 0 0 1-3-3L14 7",
|
|
77
|
+
command: "M9 6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3z",
|
|
78
|
+
zap: "M13 3L5 14h6l-1 7 8-11h-6z", sun: "M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8zM12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4",
|
|
79
|
+
moon: "M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z", settings: "M12 9a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM19 12l2-1-2-4-2 .5a7 7 0 0 0-1.5-1L15 4h-4l-.5 2.5a7 7 0 0 0-1.5 1L7 7l-2 4 2 1a7 7 0 0 0 0 2l-2 1 2 4 2-.5a7 7 0 0 0 1.5 1L11 22h4l.5-2.5a7 7 0 0 0 1.5-1l2 .5 2-4-2-1a7 7 0 0 0 0-2z",
|
|
80
|
+
check: "M5 12.5l4.5 4.5L19 7", undo: "M9 14L4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3", pencil: "M4 20l4-1L19 8a2.1 2.1 0 0 0-3-3L5 16zM14 7l3 3",
|
|
81
|
+
branch: "M6 4v12M18 8a3 3 0 1 0 0-.01M6 20a2 2 0 1 0 0-.01M18 11c0 4-6 3-12 7", search: "M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM21 21l-4.5-4.5",
|
|
82
|
+
chev: "M9 6l6 6-6 6", tool: "M14.7 6.3a4 4 0 0 0-5.4 5.4L3 18l3 3 6.3-6.3a4 4 0 0 0 5.4-5.4L15 12l-3-3z",
|
|
83
|
+
expand: "M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7", image: "M4 5h16v14H4zM4 16l5-5 4 4 3-3 4 4M9 9.5a1 1 0 1 0 0-.01", copy: "M9 9h10v11H9zM5 15V4h10",
|
|
84
|
+
chip: "M7 7h10v10H7zM9 3v4M15 3v4M9 17v4M15 17v4M3 9h4M3 15h4M17 9h4M17 15h4", refresh: "M20 11a8 8 0 1 0-2 6M20 4v7h-7", chat: "M4 5h16v11H9l-5 4z", plus2: "M12 8v8M8 12h8", minus: "M5 12h14", fit: "M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5",
|
|
85
|
+
};
|
|
86
|
+
function icon(name) { return `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${P[name] || P.file}"/></svg>`; }
|
|
87
|
+
function hydrateIcons(root) { (root || document).querySelectorAll("i[data-i]:not([data-done])").forEach((el) => { el.innerHTML = icon(el.dataset.i); el.dataset.done = 1; }); }
|
|
88
|
+
|
|
89
|
+
window.TFmd = { render, esc, diffHtml, icon, hydrateIcons };
|
|
90
|
+
})();
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/* Pan/zoom board and schematic viewer with clickable components, plus the before/after diff view. */
|
|
2
|
+
(function () {
|
|
3
|
+
const NS = "http://www.w3.org/2000/svg";
|
|
4
|
+
|
|
5
|
+
class PanZoom {
|
|
6
|
+
constructor(ports, vb) {
|
|
7
|
+
this.ports = ports; this.vb = vb.slice(); this.home = vb.slice(); this.drag = null; this.moved = false;
|
|
8
|
+
ports.forEach((p) => this.bind(p));
|
|
9
|
+
this.ro = new ResizeObserver(() => this.apply());
|
|
10
|
+
ports.forEach((p) => this.ro.observe(p));
|
|
11
|
+
}
|
|
12
|
+
svg(p) { return p.querySelector("svg.board"); }
|
|
13
|
+
rect() { return this.ports[0].getBoundingClientRect(); }
|
|
14
|
+
fit() { this.vb = this.home.slice(); this.apply(); }
|
|
15
|
+
apply() {
|
|
16
|
+
const r = this.rect(); if (!r.width || !r.height) return;
|
|
17
|
+
const [x, y, w, h] = this.vb, want = r.height / r.width;
|
|
18
|
+
// keep the viewBox the same shape as the port so panning maths stays linear
|
|
19
|
+
const cx = x + w / 2, cy = y + h / 2; let nw = w, nh = w * want;
|
|
20
|
+
if (nh < h) { nh = h; nw = h / want; }
|
|
21
|
+
this.vb = [cx - nw / 2, cy - nh / 2, nw, nh];
|
|
22
|
+
this.ports.forEach((p) => { const s = this.svg(p); if (s) s.setAttribute("viewBox", this.vb.join(" ")); });
|
|
23
|
+
}
|
|
24
|
+
zoom(f, px, py) {
|
|
25
|
+
const r = this.rect(); const [x, y, w, h] = this.vb;
|
|
26
|
+
const fx = px == null ? 0.5 : (px - r.left) / r.width, fy = py == null ? 0.5 : (py - r.top) / r.height;
|
|
27
|
+
const nw = Math.min(Math.max(w * f, this.home[2] / 80), this.home[2] * 12), k = nw / w;
|
|
28
|
+
this.vb = [x + (w - nw) * fx, y + (h - h * k) * fy, nw, h * k]; this.apply();
|
|
29
|
+
}
|
|
30
|
+
bind(p) {
|
|
31
|
+
p.addEventListener("wheel", (e) => { e.preventDefault(); this.zoom(e.deltaY > 0 ? 1.15 : 1 / 1.15, e.clientX, e.clientY); }, { passive: false });
|
|
32
|
+
p.addEventListener("pointerdown", (e) => { if (e.button !== 0) return; this.drag = { x: e.clientX, y: e.clientY, vb: this.vb.slice() }; this.moved = false; p.setPointerCapture(e.pointerId); });
|
|
33
|
+
p.addEventListener("pointermove", (e) => {
|
|
34
|
+
if (!this.drag) return;
|
|
35
|
+
const dx = e.clientX - this.drag.x, dy = e.clientY - this.drag.y;
|
|
36
|
+
if (Math.abs(dx) + Math.abs(dy) > 4) this.moved = true;
|
|
37
|
+
if (!this.moved) return;
|
|
38
|
+
const k = this.drag.vb[2] / this.rect().width;
|
|
39
|
+
this.vb = [this.drag.vb[0] - dx * k, this.drag.vb[1] - dy * k, this.drag.vb[2], this.drag.vb[3]]; this.apply();
|
|
40
|
+
});
|
|
41
|
+
const end = () => { this.drag = null; };
|
|
42
|
+
p.addEventListener("pointerup", end); p.addEventListener("pointercancel", end);
|
|
43
|
+
p.addEventListener("dblclick", (e) => { if (!e.target.classList.contains("hit")) this.fit(); });
|
|
44
|
+
}
|
|
45
|
+
destroy() { this.ro.disconnect(); }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function mountSvg(port, svgText, cls) {
|
|
49
|
+
port.querySelectorAll("svg.board").forEach((n) => n.remove());
|
|
50
|
+
const doc = new DOMParser().parseFromString(svgText, "image/svg+xml");
|
|
51
|
+
const svg = document.importNode(doc.documentElement, true);
|
|
52
|
+
["width", "height"].forEach((a) => svg.removeAttribute(a));
|
|
53
|
+
svg.classList.add("board"); if (cls) svg.classList.add(cls);
|
|
54
|
+
svg.setAttribute("preserveAspectRatio", "xMidYMid meet");
|
|
55
|
+
port.prepend(svg);
|
|
56
|
+
return svg;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function sheetBox(kind, geo) {
|
|
60
|
+
if (geo && geo.viewBox) return geo.viewBox;
|
|
61
|
+
const it = (geo && geo.items) || [];
|
|
62
|
+
if (kind === "sch" && it.length) {
|
|
63
|
+
const x0 = Math.min(...it.map((i) => i.x)) - 25, y0 = Math.min(...it.map((i) => i.y)) - 25;
|
|
64
|
+
const x1 = Math.max(...it.map((i) => i.x + i.w)) + 25, y1 = Math.max(...it.map((i) => i.y + i.h)) + 25;
|
|
65
|
+
return [x0, y0, x1 - x0, y1 - y0];
|
|
66
|
+
}
|
|
67
|
+
return [0, 0, kind === "pcb" ? 297 : 420, kind === "pcb" ? 210 : 297];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
class Viewer {
|
|
71
|
+
constructor(el, kind, app) {
|
|
72
|
+
this.el = el; this.kind = kind; this.app = app; this.data = null; this.rects = new Map();
|
|
73
|
+
el.innerHTML = `<div class="vbar"><b class="src">${kind === "pcb" ? "Board" : "Schematic"}</b><span class="muted small hint">Click a part to select · scroll to zoom</span><span class="spacer"></span><button class="btn" data-a="fit"><i data-i="fit"></i>Fit</button><button class="btn" data-a="src" title="Edit the KiCad file as text">Source</button><button class="btn" data-a="refresh"><i data-i="refresh"></i>Refresh</button></div><div class="vport ${kind}"><div class="vmsg">Loading...</div><div class="vzoom"><button data-z="in" title="Zoom in">+</button><button data-z="out" title="Zoom out">-</button></div><div class="vinfo" hidden></div></div>`;
|
|
74
|
+
TFmd.hydrateIcons(el);
|
|
75
|
+
this.port = el.querySelector(".vport"); this.info = el.querySelector(".vinfo");
|
|
76
|
+
el.querySelector('[data-a="fit"]').onclick = () => this.pz && this.pz.fit();
|
|
77
|
+
el.querySelector('[data-a="src"]').onclick = () => this.data && this.data.source && this.app.edit(this.data.source);
|
|
78
|
+
el.querySelector('[data-a="refresh"]').onclick = () => this.load(true);
|
|
79
|
+
el.querySelector('[data-z="in"]').onclick = () => this.pz && this.pz.zoom(1 / 1.3);
|
|
80
|
+
el.querySelector('[data-z="out"]').onclick = () => this.pz && this.pz.zoom(1.3);
|
|
81
|
+
this.mtime = null;
|
|
82
|
+
}
|
|
83
|
+
msg(text) { this.port.querySelectorAll("svg.board").forEach((n) => n.remove()); const m = this.port.querySelector(".vmsg") || this.port.insertAdjacentElement("afterbegin", Object.assign(document.createElement("div"), { className: "vmsg" })); m.hidden = false; m.textContent = text; }
|
|
84
|
+
async load(force) {
|
|
85
|
+
let d;
|
|
86
|
+
try { d = await this.app.api("/api/board?kind=" + this.kind); } catch (e) { this.msg(e.message); return; }
|
|
87
|
+
if (!force && this.data && d.mtime === this.mtime) return;
|
|
88
|
+
this.data = d; this.mtime = d.mtime;
|
|
89
|
+
if (!d.available || !d.sheets.length) { this.pz && this.pz.destroy(); this.pz = null; this.msg(d.message || "Nothing to show."); return; }
|
|
90
|
+
this.el.querySelector(".src").textContent = d.source;
|
|
91
|
+
const keep = this.pz ? this.pz.vb.slice() : null;
|
|
92
|
+
this.pz && this.pz.destroy();
|
|
93
|
+
const layers = this.kind === "pcb" && d.layers && d.layers.length ? d.layers : null;
|
|
94
|
+
const svg = mountSvg(this.port, layers ? layers[0].svg : d.sheets[0].svg);
|
|
95
|
+
if (layers) this.layerStack(svg, layers); else this.layerBar(null);
|
|
96
|
+
this.port.querySelector(".vmsg").hidden = true;
|
|
97
|
+
const geo = d.geometry || {}; const box = sheetBox(this.kind, geo);
|
|
98
|
+
this.el.querySelector(".hint").textContent = (geo.note ? geo.note + " · " : "") + "Click a part to select · scroll to zoom";
|
|
99
|
+
this.rects.clear();
|
|
100
|
+
const g = document.createElementNS(NS, "g"); g.setAttribute("class", "overlay");
|
|
101
|
+
[...(geo.items || [])].sort((a, b) => b.w * b.h - a.w * a.h).forEach((it) => {
|
|
102
|
+
const r = document.createElementNS(NS, "rect");
|
|
103
|
+
r.setAttribute("x", it.x); r.setAttribute("y", it.y); r.setAttribute("width", Math.max(it.w, .6)); r.setAttribute("height", Math.max(it.h, .6)); r.setAttribute("rx", .3);
|
|
104
|
+
r.setAttribute("class", it.estimated ? "hit est" : "hit"); r.dataset.ref = it.ref;
|
|
105
|
+
const t = document.createElementNS(NS, "title"); t.textContent = it.ref + (it.value ? " " + it.value : ""); r.append(t);
|
|
106
|
+
r.addEventListener("pointerenter", () => { this.app.hovered = it.ref; });
|
|
107
|
+
r.addEventListener("pointerleave", () => { if (this.app.hovered === it.ref) this.app.hovered = null; });
|
|
108
|
+
r.addEventListener("click", (e) => { if (this.pz && this.pz.moved) return; e.stopPropagation(); this.app.select(it.ref); });
|
|
109
|
+
g.append(r); this.rects.set(it.ref, r);
|
|
110
|
+
});
|
|
111
|
+
svg.append(g);
|
|
112
|
+
this.pz = new PanZoom([this.port], keep && this.data && force !== true ? keep : box); this.pz.home = box.slice(); this.pz.apply();
|
|
113
|
+
this.port.onclick = (e) => { if (!e.target.classList.contains("hit") && !this.pz.moved) this.app.select(null); };
|
|
114
|
+
this.mark(this.app.selected);
|
|
115
|
+
}
|
|
116
|
+
// Multi-layer boards: one group per copper layer (plus the outline) and a chip per layer to show or hide it.
|
|
117
|
+
layerStack(svg, layers) {
|
|
118
|
+
const hidden = this.hiddenLayers || (this.hiddenLayers = new Set());
|
|
119
|
+
const wrap = (name, nodes) => {
|
|
120
|
+
const g = document.createElementNS(NS, "g"); g.setAttribute("class", "lyr"); g.dataset.layer = name;
|
|
121
|
+
nodes.forEach((n) => g.append(n)); return g;
|
|
122
|
+
};
|
|
123
|
+
const keep = (root) => [...root.childNodes].filter((n) => n.nodeType === 1 && !["title", "desc"].includes(n.localName));
|
|
124
|
+
const groups = layers.map((l, i) => {
|
|
125
|
+
if (i === 0) return wrap(l.name, keep(svg));
|
|
126
|
+
const doc = new DOMParser().parseFromString(l.svg, "image/svg+xml");
|
|
127
|
+
return wrap(l.name, keep(doc.documentElement).map((n) => document.importNode(n, true)));
|
|
128
|
+
});
|
|
129
|
+
// bottom layers first so the top layer is painted last; the outline always on top
|
|
130
|
+
[...groups].reverse().forEach((g) => svg.append(g));
|
|
131
|
+
const out = groups.find((g) => g.dataset.layer === "Outline"); if (out) svg.append(out);
|
|
132
|
+
groups.forEach((g) => { g.style.display = hidden.has(g.dataset.layer) ? "none" : ""; });
|
|
133
|
+
this.layerBar(layers, (name, on) => {
|
|
134
|
+
on ? hidden.delete(name) : hidden.add(name);
|
|
135
|
+
svg.querySelectorAll(".lyr").forEach((g) => { if (g.dataset.layer === name) g.style.display = on ? "" : "none"; });
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
layerBar(layers, toggle) {
|
|
139
|
+
let bar = this.port.querySelector(".vlayers");
|
|
140
|
+
if (!layers) { bar && bar.remove(); return; }
|
|
141
|
+
if (!bar) { bar = document.createElement("div"); bar.className = "vlayers"; this.port.append(bar); bar.addEventListener("pointerdown", (e) => e.stopPropagation()); }
|
|
142
|
+
const hidden = this.hiddenLayers || new Set();
|
|
143
|
+
bar.innerHTML = layers.map((l) => `<button class="lchip${hidden.has(l.name) ? " off" : ""}" data-l="${TFmd.esc(l.name)}" title="Show or hide ${TFmd.esc(l.name)}"><i style="background:${TFmd.esc(l.color)}"></i>${TFmd.esc(l.name)}</button>`).join("");
|
|
144
|
+
bar.querySelectorAll(".lchip").forEach((b) => { b.onclick = (e) => { e.stopPropagation(); const on = b.classList.contains("off"); b.classList.toggle("off", !on); toggle(b.dataset.l, on); }; });
|
|
145
|
+
}
|
|
146
|
+
mark(ref) {
|
|
147
|
+
this.rects.forEach((r, k) => r.classList.toggle("sel", k === ref));
|
|
148
|
+
if (!ref) { this.info.hidden = true; return; }
|
|
149
|
+
const c = this.app.compMap.get(ref);
|
|
150
|
+
this.info.hidden = false;
|
|
151
|
+
this.info.innerHTML = `<span class="ref">${TFmd.esc(ref)}</span><span class="meta">${TFmd.esc(c ? [c.value, c.footprint && c.footprint.split(":").pop()].filter(Boolean).join(" · ") : "")}</span><button class="btn" data-a="m">@ Mention</button><button class="btn accent" data-a="k">Actions <kbd>K</kbd></button>`;
|
|
152
|
+
this.info.querySelector('[data-a="m"]').onclick = () => this.app.mention(ref);
|
|
153
|
+
this.info.querySelector('[data-a="k"]').onclick = () => this.app.openPalette();
|
|
154
|
+
if (this.pz && this.rects.has(ref)) this.reveal(ref);
|
|
155
|
+
}
|
|
156
|
+
reveal(ref) {
|
|
157
|
+
const r = this.rects.get(ref); const b = this.pz.vb;
|
|
158
|
+
const x = +r.getAttribute("x"), y = +r.getAttribute("y"), w = +r.getAttribute("width"), h = +r.getAttribute("height");
|
|
159
|
+
if (x < b[0] || y < b[1] || x + w > b[0] + b[2] || y + h > b[1] + b[3]) { this.pz.vb = [x + w / 2 - b[2] / 2, y + h / 2 - b[3] / 2, b[2], b[3]]; this.pz.apply(); }
|
|
160
|
+
}
|
|
161
|
+
// a PNG of what is on screen, for "attach the current view"
|
|
162
|
+
async png() {
|
|
163
|
+
const svg = this.port.querySelector("svg.board"); if (!svg) return null;
|
|
164
|
+
const clone = svg.cloneNode(true); clone.querySelector(".overlay")?.remove();
|
|
165
|
+
const r = this.port.getBoundingClientRect(); const W = Math.min(1600, Math.max(600, r.width * 2)), H = Math.round(W * r.height / r.width);
|
|
166
|
+
clone.setAttribute("width", W); clone.setAttribute("height", H); clone.setAttribute("xmlns", NS);
|
|
167
|
+
const url = URL.createObjectURL(new Blob([new XMLSerializer().serializeToString(clone)], { type: "image/svg+xml" }));
|
|
168
|
+
const img = new Image(); await new Promise((ok, no) => { img.onload = ok; img.onerror = no; img.src = url; });
|
|
169
|
+
const cv = document.createElement("canvas"); cv.width = W; cv.height = H; const cx = cv.getContext("2d");
|
|
170
|
+
cx.fillStyle = this.kind === "pcb" ? "#0b0e13" : "#f4f1e8"; cx.fillRect(0, 0, W, H); cx.drawImage(img, 0, 0, W, H); URL.revokeObjectURL(url);
|
|
171
|
+
return new Promise((ok) => cv.toBlob(ok, "image/png"));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// before / after view with changed items highlighted
|
|
176
|
+
function visualDiff(host, v) {
|
|
177
|
+
host.innerHTML = "";
|
|
178
|
+
if (!v || !v.available || (!v.before && !v.after)) { host.innerHTML = `<div class="empty">${TFmd.esc((v && v.message) || "No visual comparison available.")}</div>`; return null; }
|
|
179
|
+
const ch = v.changes || { items: [], tracks: [] };
|
|
180
|
+
const sum = ch.summary || {};
|
|
181
|
+
const legend = document.createElement("div"); legend.className = "legend";
|
|
182
|
+
const n = (s) => ch.items.filter((i) => i.status === s).length;
|
|
183
|
+
legend.innerHTML = `<span><i style="background:#3fb67f"></i>${n("added")} added</span><span><i style="background:#d8a542"></i>${n("changed")} changed</span><span><i style="background:#ec5f58"></i>${n("removed")} removed</span>` + (sum.tracks_added != null ? `<span>${sum.tracks_added} track segments added, ${sum.tracks_removed} removed</span>` : "");
|
|
184
|
+
const pair = document.createElement("div"); pair.className = "pair";
|
|
185
|
+
const mk = (label, svgText, geo, side) => {
|
|
186
|
+
const port = document.createElement("div"); port.className = "vport " + (v.kind || "");
|
|
187
|
+
port.innerHTML = `<span class="lab">${label}</span>`;
|
|
188
|
+
if (!svgText) { port.insertAdjacentHTML("beforeend", `<div class="vmsg">${side === "after" ? "File deleted" : "New file"}</div>`); return port; }
|
|
189
|
+
const svg = mountSvg(port, svgText); const g = document.createElementNS(NS, "g");
|
|
190
|
+
const byRef = new Map(((geo && geo.items) || []).map((i) => [i.ref, i]));
|
|
191
|
+
ch.items.forEach((c) => {
|
|
192
|
+
if (side === "before" && c.status === "added") return; if (side === "after" && c.status === "removed") return;
|
|
193
|
+
const it = byRef.get(c.ref); if (!it) return;
|
|
194
|
+
const r = document.createElementNS(NS, "rect"); r.setAttribute("x", it.x); r.setAttribute("y", it.y); r.setAttribute("width", Math.max(it.w, .8)); r.setAttribute("height", Math.max(it.h, .8)); r.setAttribute("rx", .3); r.setAttribute("class", "hl-" + c.status);
|
|
195
|
+
const t = document.createElementNS(NS, "title"); t.textContent = c.ref + " " + c.status; r.append(t); g.append(r);
|
|
196
|
+
});
|
|
197
|
+
ch.tracks.forEach((t) => {
|
|
198
|
+
if ((side === "before") !== (t.status === "removed")) return;
|
|
199
|
+
const l = document.createElementNS(NS, "line"); ["x1", "y1", "x2", "y2"].forEach((k) => l.setAttribute(k, t[k])); l.setAttribute("class", "seg-tr-" + t.status); l.setAttribute("stroke-width", .45); l.setAttribute("stroke-linecap", "round"); g.append(l);
|
|
200
|
+
});
|
|
201
|
+
svg.append(g); return port;
|
|
202
|
+
};
|
|
203
|
+
v.kind = v.kind || "";
|
|
204
|
+
const geo = v.geometry || {}; const box = sheetBox(geo && geo.items && geo.items.length && !geo.viewBox ? "sch" : "pcb", geo);
|
|
205
|
+
const a = mk("Before", v.before, v.geometry_before || geo, "before"), b = mk("After", v.after, geo, "after");
|
|
206
|
+
pair.append(a, b); host.append(legend, pair);
|
|
207
|
+
const ports = [a, b].filter((p) => p.querySelector("svg.board"));
|
|
208
|
+
if (!ports.length) return null;
|
|
209
|
+
const pz = new PanZoom(ports, box); pz.apply(); return pz;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
window.TFview = { Viewer, visualDiff, PanZoom };
|
|
213
|
+
})();
|