@wayrisignals/kicad-webview
Version:
Interactive KiCad schematic, PCB and 3D viewer for the web, with Gerber, Excellon, linked views and offline HTML exports
3 lines (2 loc) • 5.03 kB
JavaScript
/*! KiCad WebView 1.2.1 | Copyright (c) 2026 wayri | SPDX-License-Identifier: MPL-2.0 | Source: https://github.com/wayri/kicad-webview/tree/v1.2.1 | Keep LICENSE and THIRD-PARTY-NOTICES.md; bundled dependencies retain their licenses. */
import{c as S,d as $,e as g}from"./chunk-MUROJAPA.js";import"./chunk-ISOTB6CX.js";import"./chunk-TZWR7E27.js";function D(a,s){let y=a.host.ownerDocument,w="http://www.w3.org/2000/svg",t=(e,n)=>{let r=y.createElement(e);return n&&(r.textContent=n),r},i=y.createElementNS(w,"svg"),m=y.createElementNS(w,"g");i.append(m),i.setAttribute("aria-hidden","true"),i.style.cssText="position:absolute;inset:0;width:100%;height:100%;pointer-events:none;z-index:2";let h=t("section");h.setAttribute("aria-label","Imported analysis results"),h.style.cssText="position:absolute;left:10px;bottom:10px;z-index:4;max-width:min(340px,calc(100% - 20px));max-height:55%;overflow:auto;padding:10px;border:1px solid var(--viewer-border);border-radius:10px;background:var(--viewer-bar);color:var(--viewer-ink);box-shadow:var(--viewer-shadow);font:12px/1.5 system-ui";let L=t("strong",s.provenance.kind==="illustrative"?"ILLUSTRATIVE \xB7 NOT SOLVER RESULTS":"IMPORTED "+s.provenance.kind.toUpperCase()+" RESULTS");L.style.cssText="display:block;color:var(--viewer-accent);font-size:10px;letter-spacing:.06em";let c=t("select");c.setAttribute("aria-label","Analysis field"),c.style.cssText="display:block;width:100%;margin:6px 0;padding:6px;background:var(--viewer-bg);color:var(--viewer-ink);border:1px solid var(--viewer-border);border-radius:5px";for(let e of s.fields){let n=t("option",e.name+" ["+e.unit+"]");n.value=e.id,c.append(n)}let O=t("div");O.style.cssText="height:8px;border-radius:4px;background:linear-gradient(90deg,"+[0,1/3,2/3,1].map(e=>S(e,[0,1])).join(",")+")";let A=t("div");A.style.cssText="display:flex;justify-content:space-between;font-variant-numeric:tabular-nums";let R=t("span"),z=t("span");A.append(R,z);let d=t("div","Move over the board to probe a cell.");d.setAttribute("role","status");let F=t("label"),p=t("input");p.type="checkbox",p.checked=!0,p.setAttribute("aria-label","Show analysis overlay"),F.append(p,t("span"," Show overlay"));let l=t("input");l.type="range",l.min="0",l.max="100",l.value="65",l.setAttribute("aria-label","Analysis opacity"),l.style.width="100%";let N=t("details"),B=t("summary","Run details & assumptions"),I=t("div",s.provenance.tool+" \xB7 "+s.provenance.runId+(s.provenance.generatedAt?" \xB7 "+s.provenance.generatedAt:""));I.style.overflowWrap="anywhere";let M=t("ul");for(let e of s.provenance.assumptions)M.append(t("li",e));N.append(B,I,M,t("p","Fixed color scale; values outside the scale clamp to endpoint colors. Overlapping cells use the last supplied cell. This viewer does not calculate or validate engineering results.")),h.append(L,c,O,A,d,F,l,N);let o=s.fields[0],x=null,f=null,k=null,C=!1,b=!1;function E(e){let n=s.fields.find(r=>r.id===e);if(!n)throw new TypeError("Choose an imported analysis field.");o=n,c.value=e,m.replaceChildren();for(let r of o.samples){let v=y.createElementNS(w,"rect");for(let _ of["x","y","width","height"])v.setAttribute(_,String(r[_]));v.setAttribute("fill",S(r.value,o.range)),m.append(v)}R.textContent=g(o.range[0])+" "+o.unit,z.textContent=g(o.range[1])+" "+o.unit,d.textContent="Move over the board to probe a cell.",u()}function T(){return a.view==="pcb"&&a.renderer?.viewport?.camera}function u(){if(C)return;let e=T(),n=!o.layer||a.renderer?.visibleLayers?.has(o.layer);if(i.hidden=!e||!p.checked||!n,i.style.display=i.hidden?"none":"",m.setAttribute("opacity",String(Number(l.value)/100)),!e){b=!0,d.textContent="Overlay paused \xB7 switch to PCB layout.";return}if(!n){b=!0,d.textContent="Overlay paused \xB7 "+o.layer+" is hidden.";return}if(!p.checked){b=!0,d.textContent="Overlay hidden.";return}b&&(b=!1,d.textContent="Move over the board to probe a cell.");let r=e.world_to_screen({x:0,y:0});i.setAttribute("viewBox","0 0 "+e.width+" "+e.height),m.setAttribute("transform",`translate(${r.x} ${r.y}) scale(${e.flipped?-e.zoom:e.zoom} ${e.zoom})`)}let U=e=>{if(!T()||e.target!==a.renderer.canvas||i.hidden)return;let n=a.renderer.canvas.getBoundingClientRect();k={x:e.clientX-n.left,y:e.clientY-n.top},f===null&&(f=requestAnimationFrame(()=>{if(f=null,C||!T()||i.hidden||!k)return;let r=a.renderer.viewport.camera.screen_to_world(k),v=$(o,r);d.textContent=v?g(v.value)+" "+o.unit+" \xB7 "+r.x.toFixed(2)+", "+r.y.toFixed(2)+" mm":"No supplied result at this position."}))};a.stage.addEventListener("pointermove",U);function V(){x?.removeEventListener?.("kicad:viewframe",u),x=a.renderer,x?.addEventListener?.("kicad:viewframe",u),a.stage.append(i,h),u()}return c.onchange=()=>E(c.value),p.onchange=u,l.oninput=u,E(o.id),V(),{data:s,attach:V,sync:u,setField:E,dispose(){C=!0,x?.removeEventListener?.("kicad:viewframe",u),a.stage.removeEventListener("pointermove",U),f!==null&&cancelAnimationFrame(f),c.onchange=p.onchange=l.oninput=null,i.remove(),h.remove()}}}export{D as createAnalysisLayer};